From 679a0f92eab8bb43a6d69d28955be68f37369870 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Fri, 13 Oct 2023 09:34:21 -0700 Subject: [PATCH] Add named unions for all polymophic types --- .../resources/generated_examples_test.spec.js | 86 ++++++++++++------- types/Accounts.d.ts | 2 +- types/AccountsResource.d.ts | 22 ++--- types/BalanceTransactionSources.d.ts | 24 ++++++ types/BalanceTransactions.d.ts | 21 +---- types/CustomerSources.d.ts | 9 ++ types/CustomersResource.d.ts | 16 +--- types/ExternalAccounts.d.ts | 9 ++ types/PaymentIntents.d.ts | 3 +- types/Payouts.d.ts | 6 +- types/index.d.ts | 3 + types/shared.d.ts | 8 +- 12 files changed, 121 insertions(+), 88 deletions(-) create mode 100644 types/BalanceTransactionSources.d.ts create mode 100644 types/CustomerSources.d.ts create mode 100644 types/ExternalAccounts.d.ts diff --git a/test/resources/generated_examples_test.spec.js b/test/resources/generated_examples_test.spec.js index 5680f0fc27..545f8bd4f2 100644 --- a/test/resources/generated_examples_test.spec.js +++ b/test/resources/generated_examples_test.spec.js @@ -8,13 +8,13 @@ const expect = require('chai').expect; describe('Accounts', function() { it('listExternalAccounts method', async function() { - const externalAccount = await stripe.accounts.listExternalAccounts( + const externalAccounts = await stripe.accounts.listExternalAccounts( 'acct_xxxxxxxxxxxxx', { limit: 3, } ); - expect(externalAccount).not.to.be.null; + expect(externalAccounts).not.to.be.null; }); it('list method', async function() { @@ -93,6 +93,28 @@ describe('Accounts', function() { expect(capability).not.to.be.null; }); + it('listExternalAccounts method', async function() { + const externalAccounts = await stripe.accounts.listExternalAccounts( + 'acct_xxxxxxxxxxxxx', + { + object: 'bank_account', + limit: 3, + } + ); + expect(externalAccounts).not.to.be.null; + }); + + it('listExternalAccounts method', async function() { + const externalAccounts = await stripe.accounts.listExternalAccounts( + 'acct_xxxxxxxxxxxxx', + { + object: 'card', + limit: 3, + } + ); + expect(externalAccounts).not.to.be.null; + }); + it('createExternalAccount method', async function() { const externalAccount = await stripe.accounts.createExternalAccount( 'acct_xxxxxxxxxxxxx', @@ -114,19 +136,19 @@ describe('Accounts', function() { }); it('deleteExternalAccount method', async function() { - const deletedExternalAccount = await stripe.accounts.deleteExternalAccount( + const deleted = await stripe.accounts.deleteExternalAccount( 'acct_xxxxxxxxxxxxx', 'ba_xxxxxxxxxxxxx' ); - expect(deletedExternalAccount).not.to.be.null; + expect(deleted).not.to.be.null; }); it('deleteExternalAccount method', async function() { - const deletedExternalAccount = await stripe.accounts.deleteExternalAccount( + const deleted = await stripe.accounts.deleteExternalAccount( 'acct_xxxxxxxxxxxxx', 'card_xxxxxxxxxxxxx' ); - expect(deletedExternalAccount).not.to.be.null; + expect(deleted).not.to.be.null; }); it('retrieveExternalAccount method', async function() { @@ -417,10 +439,14 @@ describe('Customers', function() { }); it('updateSource method', async function() { - const card = await stripe.customers.updateSource('cus_123', 'card_123', { - account_holder_name: 'Kamil', - }); - expect(card).not.to.be.null; + const customerSource = await stripe.customers.updateSource( + 'cus_123', + 'card_123', + { + account_holder_name: 'Kamil', + } + ); + expect(customerSource).not.to.be.null; }); it('list method', async function() { @@ -517,81 +543,81 @@ describe('Customers', function() { }); it('listSources method', async function() { - const paymentSource = await stripe.customers.listSources( + const customerSources = await stripe.customers.listSources( 'cus_xxxxxxxxxxxxx', { object: 'bank_account', limit: 3, } ); - expect(paymentSource).not.to.be.null; + expect(customerSources).not.to.be.null; }); it('listSources method', async function() { - const paymentSource = await stripe.customers.listSources( + const customerSources = await stripe.customers.listSources( 'cus_xxxxxxxxxxxxx', { object: 'card', limit: 3, } ); - expect(paymentSource).not.to.be.null; + expect(customerSources).not.to.be.null; }); it('createSource method', async function() { - const paymentSource = await stripe.customers.createSource( + const customerSource = await stripe.customers.createSource( 'cus_xxxxxxxxxxxxx', { source: 'btok_xxxxxxxxxxxxx', } ); - expect(paymentSource).not.to.be.null; + expect(customerSource).not.to.be.null; }); it('createSource method', async function() { - const paymentSource = await stripe.customers.createSource( + const customerSource = await stripe.customers.createSource( 'cus_xxxxxxxxxxxxx', { source: 'tok_xxxx', } ); - expect(paymentSource).not.to.be.null; + expect(customerSource).not.to.be.null; }); it('deleteSource method', async function() { - const paymentSource = await stripe.customers.deleteSource( + const customerSource = await stripe.customers.deleteSource( 'cus_xxxxxxxxxxxxx', 'ba_xxxxxxxxxxxxx' ); - expect(paymentSource).not.to.be.null; + expect(customerSource).not.to.be.null; }); it('deleteSource method', async function() { - const paymentSource = await stripe.customers.deleteSource( + const customerSource = await stripe.customers.deleteSource( 'cus_xxxxxxxxxxxxx', 'card_xxxxxxxxxxxxx' ); - expect(paymentSource).not.to.be.null; + expect(customerSource).not.to.be.null; }); it('retrieveSource method', async function() { - const paymentSource = await stripe.customers.retrieveSource( + const customerSource = await stripe.customers.retrieveSource( 'cus_xxxxxxxxxxxxx', 'ba_xxxxxxxxxxxxx' ); - expect(paymentSource).not.to.be.null; + expect(customerSource).not.to.be.null; }); it('retrieveSource method', async function() { - const paymentSource = await stripe.customers.retrieveSource( + const customerSource = await stripe.customers.retrieveSource( 'cus_xxxxxxxxxxxxx', 'card_xxxxxxxxxxxxx' ); - expect(paymentSource).not.to.be.null; + expect(customerSource).not.to.be.null; }); it('updateSource method', async function() { - const card = await stripe.customers.updateSource( + const customerSource = await stripe.customers.updateSource( 'cus_xxxxxxxxxxxxx', 'ba_xxxxxxxxxxxxx', { @@ -600,18 +626,18 @@ describe('Customers', function() { }, } ); - expect(card).not.to.be.null; + expect(customerSource).not.to.be.null; }); it('updateSource method', async function() { - const card = await stripe.customers.updateSource( + const customerSource = await stripe.customers.updateSource( 'cus_xxxxxxxxxxxxx', 'card_xxxxxxxxxxxxx', { name: 'Jenny Rosen', } ); - expect(card).not.to.be.null; + expect(customerSource).not.to.be.null; }); it('verifySource method', async function() { diff --git a/types/Accounts.d.ts b/types/Accounts.d.ts index e1c30b17fd..ff4a6bde74 100644 --- a/types/Accounts.d.ts +++ b/types/Accounts.d.ts @@ -77,7 +77,7 @@ declare module 'stripe' { /** * External accounts (bank accounts and debit cards) currently attached to this account */ - external_accounts?: ApiList; + external_accounts?: ApiList; future_requirements?: Account.FutureRequirements; diff --git a/types/AccountsResource.d.ts b/types/AccountsResource.d.ts index 2b77605d0f..58b8978ef3 100644 --- a/types/AccountsResource.d.ts +++ b/types/AccountsResource.d.ts @@ -3410,7 +3410,7 @@ declare module 'stripe' { id: string, params: ExternalAccountCreateParams, options?: RequestOptions - ): Promise>; + ): Promise>; /** * Creates a single-use login link for an Express account to access their Stripe dashboard. @@ -3448,16 +3448,12 @@ declare module 'stripe' { id: string, params?: ExternalAccountDeleteParams, options?: RequestOptions - ): Promise< - Stripe.Response - >; + ): Promise>; deleteExternalAccount( accountId: string, id: string, options?: RequestOptions - ): Promise< - Stripe.Response - >; + ): Promise>; /** * Deletes an existing person's relationship to the account's legal entity. Any person with a relationship for an account can be deleted through the API, except if the person is the account_opener. If your integration is using the executive parameter, you cannot delete the only verified executive on file. @@ -3494,11 +3490,11 @@ declare module 'stripe' { id: string, params?: ExternalAccountListParams, options?: RequestOptions - ): ApiListPromise; + ): ApiListPromise; listExternalAccounts( id: string, options?: RequestOptions - ): ApiListPromise; + ): ApiListPromise; /** * Returns a list of people associated with the account's legal entity. The people are returned sorted by creation date, with the most recent people appearing first. @@ -3547,12 +3543,12 @@ declare module 'stripe' { id: string, params?: ExternalAccountRetrieveParams, options?: RequestOptions - ): Promise>; + ): Promise>; retrieveExternalAccount( accountId: string, id: string, options?: RequestOptions - ): Promise>; + ): Promise>; /** * Retrieves an existing person. @@ -3594,12 +3590,12 @@ declare module 'stripe' { id: string, params?: ExternalAccountUpdateParams, options?: RequestOptions - ): Promise>; + ): Promise>; updateExternalAccount( accountId: string, id: string, options?: RequestOptions - ): Promise>; + ): Promise>; /** * Updates an existing person. diff --git a/types/BalanceTransactionSources.d.ts b/types/BalanceTransactionSources.d.ts new file mode 100644 index 0000000000..afa1da163a --- /dev/null +++ b/types/BalanceTransactionSources.d.ts @@ -0,0 +1,24 @@ +// File generated from our OpenAPI spec + +declare module 'stripe' { + namespace Stripe { + type BalanceTransactionSource = + | ApplicationFee + | Charge + | ConnectCollectionTransfer + | CustomerCashBalanceTransaction + | Dispute + | FeeRefund + | Issuing.Authorization + | Issuing.Dispute + | Issuing.Transaction + | Payout + | PlatformTaxFee + | Refund + | ReserveTransaction + | TaxDeductedAtSource + | Topup + | Transfer + | TransferReversal; + } +} diff --git a/types/BalanceTransactions.d.ts b/types/BalanceTransactions.d.ts index 26345b7981..8aa8e57e6b 100644 --- a/types/BalanceTransactions.d.ts +++ b/types/BalanceTransactions.d.ts @@ -72,26 +72,7 @@ declare module 'stripe' { /** * This transaction relates to the Stripe object. */ - source: - | string - | Stripe.ApplicationFee - | Stripe.Charge - | Stripe.ConnectCollectionTransfer - | Stripe.CustomerCashBalanceTransaction - | Stripe.Dispute - | Stripe.FeeRefund - | Stripe.Issuing.Authorization - | Stripe.Issuing.Dispute - | Stripe.Issuing.Transaction - | Stripe.Payout - | Stripe.PlatformTaxFee - | Stripe.Refund - | Stripe.ReserveTransaction - | Stripe.TaxDeductedAtSource - | Stripe.Topup - | Stripe.Transfer - | Stripe.TransferReversal - | null; + source: string | Stripe.BalanceTransactionSource | null; /** * The transaction's net funds status in the Stripe balance, which are either `available` or `pending`. diff --git a/types/CustomerSources.d.ts b/types/CustomerSources.d.ts new file mode 100644 index 0000000000..74f455bdd8 --- /dev/null +++ b/types/CustomerSources.d.ts @@ -0,0 +1,9 @@ +// File generated from our OpenAPI spec + +declare module 'stripe' { + namespace Stripe { + type CustomerSource = Account | BankAccount | Card | Source; + + type DeletedCustomerSource = DeletedBankAccount | DeletedCard; + } +} diff --git a/types/CustomersResource.d.ts b/types/CustomersResource.d.ts index 0e3540e66e..dd83e3885b 100644 --- a/types/CustomersResource.d.ts +++ b/types/CustomersResource.d.ts @@ -1136,18 +1136,14 @@ declare module 'stripe' { params?: CustomerSourceDeleteParams, options?: RequestOptions ): Promise< - Stripe.Response< - Stripe.CustomerSource | Stripe.DeletedBankAccount | Stripe.DeletedCard - > + Stripe.Response >; deleteSource( customerId: string, id: string, options?: RequestOptions ): Promise< - Stripe.Response< - Stripe.CustomerSource | Stripe.DeletedBankAccount | Stripe.DeletedCard - > + Stripe.Response >; /** @@ -1365,16 +1361,12 @@ declare module 'stripe' { id: string, params?: CustomerSourceUpdateParams, options?: RequestOptions - ): Promise< - Stripe.Response - >; + ): Promise>; updateSource( customerId: string, id: string, options?: RequestOptions - ): Promise< - Stripe.Response - >; + ): Promise>; /** * Verify a specified bank account for a given customer. diff --git a/types/ExternalAccounts.d.ts b/types/ExternalAccounts.d.ts new file mode 100644 index 0000000000..3413e996d3 --- /dev/null +++ b/types/ExternalAccounts.d.ts @@ -0,0 +1,9 @@ +// File generated from our OpenAPI spec + +declare module 'stripe' { + namespace Stripe { + type DeletedExternalAccount = DeletedBankAccount | DeletedCard; + + type ExternalAccount = BankAccount | Card; + } +} diff --git a/types/PaymentIntents.d.ts b/types/PaymentIntents.d.ts index 8c1d7237ea..28c39ae276 100644 --- a/types/PaymentIntents.d.ts +++ b/types/PaymentIntents.d.ts @@ -198,8 +198,7 @@ declare module 'stripe' { source: | string | Stripe.CustomerSource - | Stripe.DeletedBankAccount - | Stripe.DeletedCard + | Stripe.DeletedCustomerSource | null; /** diff --git a/types/Payouts.d.ts b/types/Payouts.d.ts index 51ad8e84bc..ebcdc7b6c4 100644 --- a/types/Payouts.d.ts +++ b/types/Payouts.d.ts @@ -63,10 +63,8 @@ declare module 'stripe' { */ destination: | string - | Stripe.BankAccount - | Stripe.DeletedBankAccount - | Stripe.Card - | Stripe.DeletedCard + | Stripe.ExternalAccount + | Stripe.DeletedExternalAccount | null; /** diff --git a/types/index.d.ts b/types/index.d.ts index 999c2e54ad..0babf7ccc5 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -112,6 +112,7 @@ /// /// /// +/// /// /// /// @@ -128,12 +129,14 @@ /// /// /// +/// /// /// /// /// /// /// +/// /// /// /// diff --git a/types/shared.d.ts b/types/shared.d.ts index 2863f08495..f44c783dc9 100644 --- a/types/shared.d.ts +++ b/types/shared.d.ts @@ -135,13 +135,9 @@ declare module 'stripe' { /** * The resulting source of [a Connect platform debiting a connected account](https://stripe.com/docs/connect/account-debits#charging-a-connected-account). + * @deprecated prefer Stripe.Account */ - type AccountDebitSource = { - id: string; - object: 'account'; - }; - - type CustomerSource = AccountDebitSource | BankAccount | Card | Source; + type AccountDebitSource = Account; interface RangeQueryParam { /**