From 40e95e20cfbfa8fff7f0c68fe0d2c5bcffafe694 Mon Sep 17 00:00:00 2001 From: Richard Marmorstein Date: Tue, 4 Apr 2023 10:37:51 -0700 Subject: [PATCH 1/3] Set the latest API version as the default --- README.md | 5 ++--- src/stripe.core.ts | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0738c971b0..df18080044 100644 --- a/README.md +++ b/README.md @@ -97,8 +97,7 @@ We therefore encourage [upgrading your API version][api-version-upgrading] if you would like to take advantage of Stripe's TypeScript definitions. If you are on an older API version (e.g., `2019-10-17`) and not able to upgrade, -you may pass another version or `apiVersion: null` to use your account's default API version, -and use a comment like `// @ts-ignore stripe-version-2019-10-17` to silence type errors here +you may pass another version and use a comment like `// @ts-ignore stripe-version-2019-10-17` to silence type errors here and anywhere the types differ between your API version and the latest. When you upgrade, you should remove these comments. @@ -176,7 +175,7 @@ const stripe = Stripe('sk_test_...', { | Option | Default | Description | | ------------------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `apiVersion` | `null` | Stripe API version to be used. If not set the account's default version will be used. | +| `apiVersion` | `null` | Stripe API version to be used. If not set, stripe-node will use the latest version at the time of release. | | `maxNetworkRetries` | 0 | The amount of times a request should be [retried](#network-retries). | | `httpAgent` | `null` | [Proxy](#configuring-a-proxy) agent to be used by the library. | | `timeout` | 80000 | [Maximum time each request can take in ms.](#configuring-timeout) | diff --git a/src/stripe.core.ts b/src/stripe.core.ts index 5ba8f324a8..18bfab4ce3 100644 --- a/src/stripe.core.ts +++ b/src/stripe.core.ts @@ -1,4 +1,5 @@ import * as _Error from './Error.js'; +import * as apiVersion from './apiVersion.js'; import * as resources from './resources.js'; import {HttpClient, HttpClientResponse} from './net/HttpClient.js'; import { @@ -16,7 +17,7 @@ import {StripeObject, AppInfo, UserProvidedConfig} from './Types.js'; const DEFAULT_HOST = 'api.stripe.com'; const DEFAULT_PORT = '443'; const DEFAULT_BASE_PATH = '/v1/'; -const DEFAULT_API_VERSION = (null as unknown) as string; +const DEFAULT_API_VERSION = apiVersion.ApiVersion; const DEFAULT_TIMEOUT = 80000; From 4fe45af3f26983a5cc06a368c12de78d0708b717 Mon Sep 17 00:00:00 2001 From: Richard Marmorstein Date: Tue, 4 Apr 2023 16:55:53 -0700 Subject: [PATCH 2/3] Fix test --- test/stripe.spec.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/stripe.spec.ts b/test/stripe.spec.ts index efdbb235f9..f7ee86b382 100644 --- a/test/stripe.spec.ts +++ b/test/stripe.spec.ts @@ -6,6 +6,7 @@ import {FetchHttpClient} from '../cjs/net/FetchHttpClient.js'; import {NodeHttpClient} from '../cjs/net/NodeHttpClient.js'; import {createStripe} from '../cjs/stripe.core.js'; import {getMockPlatformFunctions} from './testUtils.js'; +import {ApiVersion} from '../cjs/apiVersion.js'; const testUtils = require('./testUtils.js'); const Stripe = require('../cjs/stripe.cjs.node.js'); @@ -119,7 +120,7 @@ describe('Stripe Module', function() { cases.forEach((item) => { const newStripe = Stripe(testUtils.getUserStripeKey(), item); - expect(newStripe.getApiField('version')).to.equal(null); + expect(newStripe.getApiField('version')).to.equal(ApiVersion); }); }); From 4a905645bb863fee1bd04cc3d509a054b2b24107 Mon Sep 17 00:00:00 2001 From: Annie Li Date: Tue, 4 Apr 2023 18:40:31 -0700 Subject: [PATCH 3/3] Remove circular reference in Stripe object --- src/stripe.core.ts | 5 ----- testProjects/mjs/index.js | 3 --- 2 files changed, 8 deletions(-) diff --git a/src/stripe.core.ts b/src/stripe.core.ts index 5ba8f324a8..97c45dfbd8 100644 --- a/src/stripe.core.ts +++ b/src/stripe.core.ts @@ -63,11 +63,6 @@ export function createStripe( Stripe.HttpClientResponse = HttpClientResponse; Stripe.CryptoProvider = CryptoProvider; - // For backwards compatibiblity after moving to separate CJS and ESM entrypoints. - // To be removed in the next major version. - Stripe.Stripe = Stripe; - Stripe.default = Stripe; - function Stripe( this: StripeObject, key: string, diff --git a/testProjects/mjs/index.js b/testProjects/mjs/index.js index fd3bb046c1..6572b9dfda 100644 --- a/testProjects/mjs/index.js +++ b/testProjects/mjs/index.js @@ -41,9 +41,6 @@ assert(Stripe.StripeResource.MAX_BUFFERED_REQUEST_METRICS); assert(Stripe.webhooks); assert(Stripe.resources); -assert(Stripe.Stripe); -assert(Stripe.default); - const stripe = new Stripe(process.argv[2]); const defaultStripe = new DefaultStripe(process.argv[2]);