Skip to content

Commit

Permalink
Merge dcaadd2 into cb1e1ce
Browse files Browse the repository at this point in the history
  • Loading branch information
richardm-stripe committed Jan 12, 2023
2 parents cb1e1ce + dcaadd2 commit 54e5fad
Show file tree
Hide file tree
Showing 29 changed files with 570 additions and 131 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Add support for `mark_stale_quote` method on resource `Quote`
* Add support for `duration` and `line_ends_at` on `QuoteCreateParams.subscription_data.bill_on_acceptance.bill_until`, `QuoteCreateParams.subscription_data_overrides[].bill_on_acceptance.bill_until`, `QuoteUpdateParams.subscription_data.bill_on_acceptance.bill_until`, and `QuoteUpdateParams.subscription_data_overrides[].bill_on_acceptance.bill_until`
* Remove support for `line_starts_at` on `QuoteCreateParams.subscription_data.bill_on_acceptance.bill_until`, `QuoteCreateParams.subscription_data_overrides[].bill_on_acceptance.bill_until`, `QuoteUpdateParams.subscription_data.bill_on_acceptance.bill_until`, and `QuoteUpdateParams.subscription_data_overrides[].bill_on_acceptance.bill_until`
* Add support for `metadata` on `Terminal.Reader.action.refund_payment` and `TerminalReaderRefundPaymentParams`
* Add support for `metadata` on `Terminal.Reader.action.refund_payment` and `TerminalReaderRefundPaymentParams`

## 11.6.0 - 2023-01-05
* [#1646](https://github.com/stripe/stripe-node/pull/1646) API Updates
Expand Down
2 changes: 1 addition & 1 deletion OPENAPI_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v217
v218
27 changes: 17 additions & 10 deletions lib/Webhooks.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 10 additions & 7 deletions lib/multipart.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/resources.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/resources/Quotes.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions lib/resources/Tax/Registrations.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 23 additions & 5 deletions lib/utils.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions src/Error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,14 @@ class StripeConnectionError extends StripeError {}
* webhook fails
*/
class StripeSignatureVerificationError extends StripeError {
header: string;
payload: string;

constructor(header: string, payload: string, raw: StripeRawError = {}) {
header: string | Uint8Array;
payload: string | Uint8Array;

constructor(
header: string | Uint8Array,
payload: string | Uint8Array,
raw: StripeRawError = {}
) {
super(raw);
this.header = header;
this.payload = payload;
Expand Down
2 changes: 1 addition & 1 deletion src/Types.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable camelcase */
type AppInfo = {name?: string} & Record<string, unknown>;
type BufferedFile = {name: string; type: string; file: {data: Buffer}};
type BufferedFile = {name: string; type: string; file: {data: Uint8Array}};
type HttpClientResponseError = {code: number};
type HttpHeaderValue = string | number | string[];
type MethodSpec = {
Expand Down
39 changes: 23 additions & 16 deletions src/Webhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import utils = require('./utils');
import _Error = require('./Error');
const {StripeError, StripeSignatureVerificationError} = _Error;

type WebhookHeader = string | Buffer;
type WebhookHeader = string | Uint8Array;
type WebhookParsedHeader = {
signatures: Array<string>;
timestamp: number;
};
type WebhookParsedEvent = {
details: WebhookParsedHeader;
decodedPayload: string;
decodedHeader: string;
decodedPayload: WebhookHeader;
decodedHeader: WebhookPayload;
};
type WebhookTestHeaderOptions = {
timestamp: number;
Expand All @@ -22,7 +22,7 @@ type WebhookTestHeaderOptions = {
};

type WebhookEvent = Record<string, unknown>;
type WebhookPayload = string | Buffer;
type WebhookPayload = string | Uint8Array;
type WebhookSignatureObject = {
verifyHeader: (
encodedPayload: WebhookPayload,
Expand Down Expand Up @@ -78,8 +78,10 @@ const Webhook: WebhookObject = {
cryptoProvider
);

// @ts-ignore
const jsonPayload = JSON.parse(payload);
const jsonPayload =
payload instanceof Uint8Array
? JSON.parse(new TextDecoder('utf8').decode(payload))
: JSON.parse(payload);
return jsonPayload;
},

Expand All @@ -98,8 +100,10 @@ const Webhook: WebhookObject = {
cryptoProvider
);

// @ts-ignore
const jsonPayload = JSON.parse(payload);
const jsonPayload =
payload instanceof Uint8Array
? JSON.parse(new TextDecoder('utf8').decode(payload))
: JSON.parse(payload);
return jsonPayload;
},

Expand Down Expand Up @@ -218,9 +222,11 @@ function parseEventDetails(
encodedHeader: WebhookHeader,
expectedScheme: string
): WebhookParsedEvent {
const decodedPayload = Buffer.isBuffer(encodedPayload)
? encodedPayload.toString('utf8')
: encodedPayload;
const textDecoder = new TextDecoder('utf8');
const decodedPayload =
encodedPayload instanceof Uint8Array
? textDecoder.decode(encodedPayload)
: encodedPayload;

// Express's type for `Request#headers` is `string | []string`
// which is because the `set-cookie` header is an array,
Expand All @@ -232,9 +238,10 @@ function parseEventDetails(
);
}

const decodedHeader = Buffer.isBuffer(encodedHeader)
? encodedHeader.toString('utf8')
: encodedHeader;
const decodedHeader =
encodedHeader instanceof Uint8Array
? textDecoder.decode(encodedHeader)
: encodedHeader;

const details = parseHeader(decodedHeader, expectedScheme);

Expand All @@ -259,7 +266,7 @@ function parseEventDetails(

function validateComputedSignature(
payload: WebhookPayload,
header: string,
header: WebhookHeader,
details: WebhookParsedHeader,
expectedSignature: string,
tolerance: number
Expand Down Expand Up @@ -292,7 +299,7 @@ function validateComputedSignature(
}

function parseHeader(
header: string,
header: WebhookHeader,
scheme: string
): WebhookParsedHeader | null {
if (typeof header !== 'string') {
Expand Down
Loading

0 comments on commit 54e5fad

Please sign in to comment.