Skip to content

Commit

Permalink
API Updates for beta branch (#1572)
Browse files Browse the repository at this point in the history
* Migrate other Stripe infrastructure to TS

* Reviewer comments

* Update TypeScript

* Reviewer comments

* Remove 'use strict' from migrated files

* Turn on alwaysStrict in tsconfig

* Update src/net/NodeHttpClient.ts

Co-authored-by: Kamil Pajdzik <[email protected]>

* Update src/crypto/SubtleCryptoProvider.ts

Co-authored-by: Kamil Pajdzik <[email protected]>

* Update src/crypto/SubtleCryptoProvider.ts

Co-authored-by: Kamil Pajdzik <[email protected]>

* Remove hasOwn alias, undo suggested commits

* Update src/net/FetchHttpClient.ts

Co-authored-by: Kamil Pajdzik <[email protected]>

* Add more types to HTTP clients

* API Updates (#1564)

Codegen for openapi v197

* Bump version to 10.12.0

* Fix release tag calculation (#1567)

* Upgrade dev dependencies (#1568)

* Upgrade @types/node

* Upgrade @typescript-eslint/eslint-plugin

* Upgrade @typescript-eslint/parser

* Upgrade eslint

* Lint

* Add ESLint congif for TS tests

* Add Node configuration to ESLint configuration

* Remove 'Function' declaration

* Downgrade lint packages and suppress lint errors

* Upgrade ansi-regex

* Downgrade @typescript-eslint/parser

* Reset angi-regex

* Yarn.lock

* Upgrade chai

* Upgrade mocha

* Downgrade mocha

* Add ^

* Upgrade eslint-config-prettier

* Upgrade eslint-plugin-chai-friendly

* Upgrade eslint-plugin-prettier

* Downgrade eslint-plugin-prettier

* Remove ansi-regex

* Upgrade typescript

* Upgrade mocha-junit-reporter

* Upgrade qs

* Upgrade prettier

* Upgrade nock

* Formatting

* Downgrade prettier

* Lint

* Upgrade nanoid

* Revert nanoid

* Upgrade node-fetch

* Downgrade node-fetch

* Revert types/node change

* Revert fetch type

* Update node-fetch to 2.6.7 (#1570)

* Update node-fetch to 2.6.7

* Yarn.lock

* Formatting

* Lint

* API Updates (#1571)

Codegen for openapi v201

* Bump version to 10.13.0

* Set version to 10.13.0 to simplify merge

* Reset version to 10.12.0-beta.1

* Codegen for openapi v201

Co-authored-by: Annie Li <[email protected]>
Co-authored-by: anniel-stripe <[email protected]>
Co-authored-by: yejia-stripe <[email protected]>
Co-authored-by: Yejia Chen <[email protected]>
Co-authored-by: pakrym-stripe <[email protected]>
  • Loading branch information
6 people authored Oct 6, 2022
1 parent 440f2cb commit 93432ee
Show file tree
Hide file tree
Showing 50 changed files with 861 additions and 640 deletions.
4 changes: 2 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ module.exports = {
extends: ['plugin:prettier/recommended'],
overrides: [
{
files: ["**/*.ts"],
parser: "@typescript-eslint/parser",
files: ['**/*.ts'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'prettier'],
extends: [
'eslint:recommended',
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ jobs:
npm config set //registry.npmjs.org/:_authToken $NPM_AUTH_TOKEN
# print the NPM user name for validation
npm whoami
VERSION=$(npm -s run env echo '$npm_package_version')
VERSION=$(node -p "require('./package.json').version" )
# Only publish stable versions to the latest tag
if [[ "$VERSION" =~ ^[^-]+$ ]]; then
NPM_TAG="latest"
Expand Down
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# Changelog

## 10.13.0 - 2022-10-06
* [#1571](https://github.com/stripe/stripe-node/pull/1571) API Updates
* Add support for new value `invalid_dob_age_under_18` on enums `Account.future_requirements.errors[].code`, `Account.requirements.errors[].code`, `Capability.future_requirements.errors[].code`, `Capability.requirements.errors[].code`, `Person.future_requirements.errors[].code`, and `Person.requirements.errors[].code`
* Add support for new value `bank_of_china` on enums `Charge.payment_method_details.fpx.bank`, `PaymentIntentConfirmParams.payment_method_data.fpx.bank`, `PaymentIntentCreateParams.payment_method_data.fpx.bank`, `PaymentIntentUpdateParams.payment_method_data.fpx.bank`, `PaymentMethod.fpx.bank`, `PaymentMethodCreateParams.fpx.bank`, `SetupIntentConfirmParams.payment_method_data.fpx.bank`, `SetupIntentCreateParams.payment_method_data.fpx.bank`, and `SetupIntentUpdateParams.payment_method_data.fpx.bank`
* Add support for new values `America/Nuuk`, `Europe/Kyiv`, and `Pacific/Kanton` on enum `ReportingReportRunCreateParams.parameters.timezone`
* Add support for `klarna` on `SetupAttempt.payment_method_details`
* [#1570](https://github.com/stripe/stripe-node/pull/1570) Update node-fetch to 2.6.7
* [#1568](https://github.com/stripe/stripe-node/pull/1568) Upgrade dependencies
* [#1567](https://github.com/stripe/stripe-node/pull/1567) Fix release tag calculation

## 10.12.0 - 2022-09-29
* [#1564](https://github.com/stripe/stripe-node/pull/1564) API Updates
* Change type of `Charge.payment_method_details.card_present.incremental_authorization_supported` and `Charge.payment_method_details.card_present.overcapture_supported` from `boolean | null` to `boolean`
* Add support for `created` on `Checkout.Session`
* Add support for `setup_future_usage` on `PaymentIntent.payment_method_options.pix`, `PaymentIntentConfirmParams.payment_method_options.pix`, `PaymentIntentCreateParams.payment_method_options.pix`, and `PaymentIntentUpdateParams.payment_method_options.pix`
* Deprecate `CheckoutSessionCreateParams.subscription_data.items` (use the `line_items` param instead). This will be removed in the next major version.
* [#1563](https://github.com/stripe/stripe-node/pull/1563) Migrate other Stripe infrastructure to TS
* [#1562](https://github.com/stripe/stripe-node/pull/1562) Restore lib after generating
* [#1551](https://github.com/stripe/stripe-node/pull/1551) Re-introduce Typescript changes

## 10.12.0-beta.1 - 2022-09-26
* [#1561](https://github.com/stripe/stripe-node/pull/1561) API Updates for beta branch
* Updated stable APIs to the latest version
Expand Down
2 changes: 1 addition & 1 deletion OPENAPI_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v196
v201
3 changes: 3 additions & 0 deletions examples/webhook-signing/typescript-node-express/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
module.exports = {
env: {
node: true,
},
root: true,
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'prettier'],
Expand Down
10 changes: 8 additions & 2 deletions lib/Webhooks.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/apiVersion.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/crypto/SubtleCryptoProvider.js

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

9 changes: 6 additions & 3 deletions lib/multipart.js

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

3 changes: 2 additions & 1 deletion lib/net/FetchHttpClient.js

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

3 changes: 2 additions & 1 deletion lib/net/NodeHttpClient.js

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

24 changes: 16 additions & 8 deletions lib/utils.js

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

31 changes: 15 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,30 @@
"main": "lib/stripe.js",
"types": "types/2022-08-01/index.d.ts",
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^2.13.0",
"@typescript-eslint/parser": "^2.13.0",
"chai": "~4.2.0",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"chai": "^4.3.6",
"chai-as-promised": "~7.1.1",
"coveralls": "^3.1.1",
"eslint": "^6.8.0",
"eslint-config-prettier": "^4.1.0",
"eslint-plugin-chai-friendly": "^0.4.0",
"eslint-plugin-prettier": "^3.0.1",
"mocha": "^8.3.2",
"mocha-junit-reporter": "^1.23.1",
"nock": "^13.1.1",
"node-fetch": "^2.6.2",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-chai-friendly": "^0.7.2",
"eslint-plugin-prettier": "^3.4.1",
"mocha": "^8.4.0",
"mocha-junit-reporter": "^2.1.0",
"nock": "^13.2.9",
"node-fetch": "^2.6.7",
"nyc": "^15.1.0",
"prettier": "^1.16.4",
"typescript": "^3.7.2"
"typescript": "^4.8.4"
},
"resolutions": {
"ansi-regex": "5.0.1",
"minimist": "1.2.6",
"nanoid": "3.2.0"
"nanoid": "^3.2.0"
},
"dependencies": {
"@types/node": ">=8.1.0",
"qs": "^6.10.3"
"qs": "^6.11.0"
},
"license": "MIT",
"scripts": {
Expand All @@ -68,5 +67,5 @@
"report": "nyc -r text -r lcov report",
"coveralls": "cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
"prettier-format": "prettier --config .prettierrc 'lib/**/*.js' --write"
}
}
}
1 change: 1 addition & 0 deletions src/Error.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable camelcase */
type RawErrorType =
| 'card_error'
| 'invalid_request_error'
Expand Down
2 changes: 0 additions & 2 deletions src/ResourceNamespace.js → src/ResourceNamespace.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

// ResourceNamespace allows you to create nested resources, i.e. `stripe.issuing.cards`.
// It also works recursively, so you could do i.e. `stripe.billing.invoicing.pay`.

Expand Down
16 changes: 10 additions & 6 deletions src/Webhooks.js → src/Webhooks.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict';

const utils = require('./utils');
const {StripeError, StripeSignatureVerificationError} = require('./Error');
import utils = require('./utils');
import _Error = require('./Error');
const {StripeError, StripeSignatureVerificationError} = _Error;

const Webhook = {
DEFAULT_TOLERANCE: 300, // 5 minutes
signature: null,

constructEvent(payload, header, secret, tolerance, cryptoProvider) {
this.signature.verifyHeader(
Expand Down Expand Up @@ -169,6 +169,7 @@ function parseEventDetails(encodedPayload, encodedHeader, expectedScheme) {
if (!details || details.timestamp === -1) {
throw new StripeSignatureVerificationError({
message: 'Unable to extract timestamp and signatures from header',
// @ts-expect-error Type '{ decodedHeader: any; decodedPayload: any; }' is not assignable to type 'string'.
detail: {
decodedHeader,
decodedPayload,
Expand All @@ -179,6 +180,7 @@ function parseEventDetails(encodedPayload, encodedHeader, expectedScheme) {
if (!details.signatures.length) {
throw new StripeSignatureVerificationError({
message: 'No signatures found with expected scheme',
// @ts-expect-error Type '{ decodedHeader: any; decodedPayload: any; }' is not assignable to type 'string'.
detail: {
decodedHeader,
decodedPayload,
Expand Down Expand Up @@ -210,6 +212,7 @@ function validateComputedSignature(
'No signatures found matching the expected signature for payload.' +
' Are you passing the raw request body you received from Stripe?' +
' https://github.com/stripe/stripe-node#webhook-signing',
// @ts-expect-error Type '{ header: any; payload: any; }' is not assignable to type 'string'.
detail: {
header,
payload,
Expand All @@ -222,6 +225,7 @@ function validateComputedSignature(
if (tolerance > 0 && timestampAge > tolerance) {
throw new StripeSignatureVerificationError({
message: 'Timestamp outside the tolerance zone',
// @ts-expect-error Type '{ header: any; payload: any; }' is not assignable to type 'string'.
detail: {
header,
payload,
Expand All @@ -242,7 +246,7 @@ function parseHeader(header, scheme) {
const kv = item.split('=');

if (kv[0] === 't') {
accum.timestamp = kv[1];
accum.timestamp = parseInt(kv[1], 10);
}

if (kv[0] === scheme) {
Expand Down Expand Up @@ -274,4 +278,4 @@ function getNodeCryptoProvider() {

Webhook.signature = signature;

module.exports = Webhook;
export = Webhook;
8 changes: 3 additions & 5 deletions src/crypto/CryptoProvider.js → src/crypto/CryptoProvider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

/**
* Interface encapsulating the various crypto computations used by the library,
* allowing pluggable underlying crypto implementations.
Expand All @@ -13,7 +11,7 @@ class CryptoProvider {
* - computeHMACSignature('', 'test_secret') => 'f7f9bd47fb987337b5796fdc1fdb9ba221d0d5396814bfcaf9521f43fd8927fd'
* - computeHMACSignature('\ud83d\ude00', 'test_secret') => '837da296d05c4fe31f61d5d7ead035099d9585a5bcde87de952012a78f0b0c43
*/
computeHMACSignature(payload, secret) {
computeHMACSignature(payload: string, secret: string): string {
throw new Error('computeHMACSignature not implemented.');
}

Expand All @@ -28,9 +26,9 @@ class CryptoProvider {
* - computeHMACSignature('', 'test_secret') => 'f7f9bd47fb987337b5796fdc1fdb9ba221d0d5396814bfcaf9521f43fd8927fd'
* - computeHMACSignature('\ud83d\ude00', 'test_secret') => '837da296d05c4fe31f61d5d7ead035099d9585a5bcde87de952012a78f0b0c43
*/
computeHMACSignatureAsync(payload, secret) {
computeHMACSignatureAsync(payload: string, secret: string): Promise<string> {
throw new Error('computeHMACSignatureAsync not implemented.');
}
}

module.exports = CryptoProvider;
export = CryptoProvider;
Loading

0 comments on commit 93432ee

Please sign in to comment.