Skip to content

Commit

Permalink
chore: update typings exports
Browse files Browse the repository at this point in the history
  • Loading branch information
tianyingchun committed May 16, 2024
1 parent afcd481 commit 50b95f5
Show file tree
Hide file tree
Showing 20 changed files with 45 additions and 119 deletions.
5 changes: 5 additions & 0 deletions .changeset/lemon-wasps-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hyperse-io/paypal-node-sdk": patch
---

update typings exports
7 changes: 4 additions & 3 deletions src/core/PayPalHttpClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readFileSync } from 'fs';
import paypalhttp, { type HttpRequest } from '@paypal/paypalhttp';
import packageJson from '../../package.json' with { type: 'json' };
import { AccessToken } from './AccessToken.js';
import { AccessTokenRequest } from './AccessTokenRequest.js';
import { type HttpRequestBase } from './HttpRequestBase.js';
Expand All @@ -15,8 +15,8 @@ import { TokenCache } from './TokenCache.js';

export class PayPalHttpClient extends paypalhttp.HttpClient {
private _cache: TokenCache;

public refreshToken?: string;
private package: { version: string };

/**
* @param environment - The environment for this client
Expand All @@ -27,6 +27,7 @@ export class PayPalHttpClient extends paypalhttp.HttpClient {
this._cache = TokenCache.cacheForEnvironment(environment, refreshToken);
this.refreshToken = refreshToken;
this.addInjector(this.authInjector);
this.package = JSON.parse(readFileSync('../../package.json', 'utf8'));
this.addInjector(function (req) {
req.headers['Accept-Encoding'] = 'gzip';
req.headers['sdk_name'] = 'Checkout SDK';
Expand Down Expand Up @@ -65,7 +66,7 @@ export class PayPalHttpClient extends paypalhttp.HttpClient {
getUserAgent() {
return (
'PayPalSDK/PayPal-node-SDK ' +
packageJson.version +
this.package.version +
' (node ' +
process.version +
'-' +
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * as orders from './orders/index.js';
export * as payments from './payments/index.js';
export * as customers from './customers/index.js';
export * as webhook from './webhook/index.js';
export * from './types/index.js';
6 changes: 0 additions & 6 deletions src/orders/ordersAuthorizeRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { HttpRequestBase } from '../core/HttpRequestBase.js';
import {
type PaymentSource,
type BaseOrderHeaders,
type Order,
} from '../types/type-order.js';

export type OrdersAuthorizeRequestBody = {
Expand Down Expand Up @@ -59,8 +58,3 @@ export class OrdersAuthorizeRequest extends HttpRequestBase<
return this;
}
}

/**
* The response body contains the authorization details.
*/
export type OrdersAuthorizeRequestResult = Order;
6 changes: 0 additions & 6 deletions src/orders/ordersCaptureRequest.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import querystring from 'querystring';
import { HttpRequestBase } from '../core/HttpRequestBase.js';
import {
type Order,
type BaseOrderHeaders,
type PaymentSource,
} from '../types/type-order.js';
Expand Down Expand Up @@ -60,8 +59,3 @@ export class OrdersCaptureRequest extends HttpRequestBase<
return this;
}
}

/**
* The response from capturing a payment for an order.
*/
export type OrdersCaptureRequestResult = Order;
6 changes: 0 additions & 6 deletions src/orders/ordersCreateRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
type Payer,
type PurchaseUnitRequest,
type OrderApplicationContext,
type Order,
} from '../types/type-order.js';

export type OrdersCreateRequestBody = {
Expand Down Expand Up @@ -57,8 +56,3 @@ export class OrdersCreateRequest extends HttpRequestBase<
return this;
}
}

/**
* The response body of the OrdersCreateRequest.
*/
export type OrdersCreateRequestResult = Order;
7 changes: 1 addition & 6 deletions src/orders/ordersGetRequest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import querystring from 'querystring';
import { HttpRequestBase } from '../core/HttpRequestBase.js';
import { type Order, type BaseOrderHeaders } from '../types/type-order.js';
import { type BaseOrderHeaders } from '../types/type-order.js';

/**
* Shows details for an order, by ID.
Expand All @@ -17,8 +17,3 @@ export class OrdersGetRequest extends HttpRequestBase<BaseOrderHeaders> {
};
}
}

/**
* The response body of the OrdersGetRequest.
*/
export type OrdersGetRequestResult = Order;
11 changes: 1 addition & 10 deletions src/orders/ordersPatchRequest.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import querystring from 'querystring';
import { HttpRequestBase } from '../core/HttpRequestBase.js';
import {
type Order,
type BaseOrderHeaders,
type Patch,
} from '../types/type-order.js';
import { type BaseOrderHeaders, type Patch } from '../types/type-order.js';

type OrderPatchRequestBody = Patch[];

Expand Down Expand Up @@ -32,8 +28,3 @@ export class OrdersPatchRequest extends HttpRequestBase<
return this;
}
}

/**
* The response body of the OrdersPatchRequest.
*/
export type OrdersPatchRequestResult = Order;
6 changes: 0 additions & 6 deletions src/payments/authorizationsCaptureRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
type PaymentInstruction,
type Money,
type BasePaymentHeaders,
type Capture,
} from '../types/type-payment.js';

type AuthorizationsCaptureRequestBody = {
Expand Down Expand Up @@ -61,8 +60,3 @@ export class AuthorizationsCaptureRequest extends HttpRequestBase<
return this;
}
}

/**
* The response body of the AuthorizationsCaptureRequest.
*/
export type AuthorizationsCaptureRequestResult = Capture;
10 changes: 1 addition & 9 deletions src/payments/authorizationsGetRequest.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import querystring from 'querystring';
import { HttpRequestBase } from '../core/HttpRequestBase.js';
import {
type Capture,
type BasePaymentHeaders,
} from '../types/type-payment.js';
import { type BasePaymentHeaders } from '../types/type-payment.js';

/**
* Shows details for an authorized payment, by ID.
Expand All @@ -23,8 +20,3 @@ export class AuthorizationsGetRequest extends HttpRequestBase<BasePaymentHeaders
};
}
}

/**
* The response body of the AuthorizationsGetRequest.
*/
export type AuthorizationsGetRequestResult = Capture;
11 changes: 1 addition & 10 deletions src/payments/authorizationsReauthorizeRequest.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import querystring from 'querystring';
import { HttpRequestBase } from '../core/HttpRequestBase.js';
import {
type Money,
type BasePaymentHeaders,
type Capture,
} from '../types/type-payment.js';
import { type Money, type BasePaymentHeaders } from '../types/type-payment.js';

type AuthorizationsReauthorizeRequestBody = {
amount: Money;
Expand Down Expand Up @@ -56,8 +52,3 @@ export class AuthorizationsReauthorizeRequest extends HttpRequestBase<
return this;
}
}

/**
* The response for reauthorizing a payment, by ID.
*/
export type AuthorizationsReauthorizeRequestResult = Capture;
10 changes: 1 addition & 9 deletions src/payments/authorizationsVoidRequest.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import querystring from 'querystring';
import { HttpRequestBase } from '../core/HttpRequestBase.js';
import {
type Capture,
type BasePaymentHeaders,
} from '../types/type-payment.js';
import { type BasePaymentHeaders } from '../types/type-payment.js';

interface AuthorizationsVoidRequestHeaders extends BasePaymentHeaders {
'PayPal-Auth-Assertion'?: string;
Expand All @@ -27,8 +24,3 @@ export class AuthorizationsVoidRequest extends HttpRequestBase<AuthorizationsVoi
};
}
}

/**
* The response for voiding an authorized payment, by ID.
*/
export type AuthorizationsVoidRequestResult = Capture;
10 changes: 1 addition & 9 deletions src/payments/capturesGetRequest.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import querystring from 'querystring';
import { HttpRequestBase } from '../core/HttpRequestBase.js';
import {
type Capture,
type BasePaymentHeaders,
} from '../types/type-payment.js';
import { type BasePaymentHeaders } from '../types/type-payment.js';

/**
* Captures Get
Expand All @@ -24,8 +21,3 @@ export class CapturesGetRequest extends HttpRequestBase<BasePaymentHeaders> {
};
}
}

/**
* The response body of the CapturesGetRequest.
*/
export type CapturesGetRequestResult = Capture;
13 changes: 2 additions & 11 deletions src/payments/capturesRefundRequest.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import querystring from 'querystring';
import { HttpRequestBase } from '../core/HttpRequestBase.js';
import {
type Money,
type BasePaymentHeaders,
type Capture,
} from '../types/type-payment.js';
import { type Money, type BasePaymentHeaders } from '../types/type-payment.js';

type CapturesRefundRequestBody = {
amount: Money;
Expand All @@ -26,7 +22,7 @@ export class CapturesRefundRequest extends HttpRequestBase<
CapturesRefundRequestHeaders,
CapturesRefundRequestBody
> {
constructor(captureId) {
constructor(captureId: string) {
super();
this.path = '/v2/payments/captures/{capture_id}/refund?';
this.path = this.path.replace(
Expand Down Expand Up @@ -63,8 +59,3 @@ export class CapturesRefundRequest extends HttpRequestBase<
return this;
}
}

/**
* The response body of the CapturesRefundRequest.
*/
export type CapturesRefundRequestResult = Capture;
10 changes: 1 addition & 9 deletions src/payments/refundsGetRequest.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import querystring from 'querystring';
import { HttpRequestBase } from '../core/HttpRequestBase.js';
import {
type Capture,
type BasePaymentHeaders,
} from '../types/type-payment.js';
import { type BasePaymentHeaders } from '../types/type-payment.js';

/**
* Shows details for a refund, by ID.
Expand All @@ -20,8 +17,3 @@ export class RefundsGetRequest extends HttpRequestBase<BasePaymentHeaders> {
};
}
}

/**
* The response body of the RefundsGetRequest.
*/
export type RefundsGetRequestResult = Capture;
4 changes: 4 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './type-customer.js';
export * from './type-order.js';
export * from './type-payment.js';
export * from './type-webhook.js';
5 changes: 5 additions & 0 deletions src/types/type-order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,11 @@ export interface PurchaseUnit {
// https://developer.paypal.com/docs/api/orders/v2/#definition-purchase_unit_request
export interface PurchaseUnitRequest {
amount: AmountWithBreakdown;
/**
* [ 1 .. 127 ] characters
* The API caller-provided external ID. Used to reconcile client transactions with PayPal transactions.
* Appears in transaction and settlement reports but is not visible to the payer.
*/
custom_id?: string;
description?: string;
invoice_id?: string;
Expand Down
11 changes: 11 additions & 0 deletions src/types/type-webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,14 @@ export interface WebhookEvent {
export interface BaseWebhookHeaders extends BaseHeaders {
'Content-Type': 'application/json';
}

/**
* The response body of the VerifyWebhookSignature.
*/
export type VerifyWebhookSignatureResult = {
/**
* The status of the signature verification.
* Enum: "SUCCESS" "FAILURE"
*/
verification_status: 'SUCCESS' | 'FAILURE';
};
5 changes: 4 additions & 1 deletion src/webhook/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export { VerifyWebhookSignature } from './verifyWebhookSignature.js';
export {
VerifyWebhookSignature,
type VerifyWebhookSignatureBody,
} from './verifyWebhookSignature.js';
20 changes: 2 additions & 18 deletions src/webhook/verifyWebhookSignature.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import querystring from 'querystring';
import { HttpRequestBase } from '../core/HttpRequestBase.js';
import {
type WebhookEvent,
type BaseWebhookHeaders,
} from '../types/type-webhook.js';

type VerifyWebhookSignatureBody = {
export type VerifyWebhookSignatureBody = {
/**
* The ID of the HTTP transmission. Contained in the PAYPAL-TRANSMISSION-ID header of the notification message.
* '69cd13f0-d67a-11e5-baa3-778b53f4ae55';
Expand Down Expand Up @@ -49,13 +48,9 @@ export class VerifyWebhookSignature extends HttpRequestBase<
BaseWebhookHeaders,
VerifyWebhookSignatureBody
> {
constructor(authorizationId) {
constructor() {
super();
this.path = '/v1/notifications/verify-webhook-signature?';
this.path = this.path.replace(
'{authorization_id}',
querystring.escape(authorizationId)
);
this.verb = 'POST';
this.headers = {
'Content-Type': 'application/json',
Expand All @@ -81,14 +76,3 @@ export class VerifyWebhookSignature extends HttpRequestBase<
return this;
}
}

/**
* The response body of the VerifyWebhookSignature.
*/
export type VerifyWebhookSignatureResult = {
/**
* The status of the signature verification.
* Enum: "SUCCESS" "FAILURE"
*/
verification_status: 'SUCCESS' | 'FAILURE';
};

0 comments on commit 50b95f5

Please sign in to comment.