From 7f31c018a0acf9a598bd05c54f43e849fefaceca Mon Sep 17 00:00:00 2001 From: Oleg Vaskevich Date: Wed, 3 Jul 2019 09:36:02 -0700 Subject: [PATCH] Add support for auto pagination in Stripe (#36495) --- types/stripe/index.d.ts | 286 ++++++++++++++++++----------------- types/stripe/stripe-tests.ts | 18 +++ types/stripe/tsconfig.json | 3 +- 3 files changed, 166 insertions(+), 141 deletions(-) diff --git a/types/stripe/index.d.ts b/types/stripe/index.d.ts index bd4c3170dd..8e218a7e44 100644 --- a/types/stripe/index.d.ts +++ b/types/stripe/index.d.ts @@ -24,8 +24,9 @@ // Christopher Eck // Joshua Feltimo // Josiah +// Oleg Vaskevich // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.2 +// TypeScript Version: 2.3 /// @@ -6991,6 +6992,11 @@ declare namespace Stripe { constructor(stripe: Stripe, urlData: any); } + interface IListPromise extends Promise>, AsyncIterableIterator { + autoPagingEach(handler: (item: T) => Promise): void; + autoPagingToArray(opts: {limit: number}): Promise; + } + namespace resources { class UsageRecords extends StripeResource { /** @@ -7059,10 +7065,10 @@ declare namespace Stripe { /** * Returns a list of accounts connected to your platform via Connect. If you’re not a platform, the list will be empty. */ - list(data: IListOptions, options: HeaderOptions, response?: IResponseFn>): Promise>; - list(data: IListOptions, response?: IResponseFn>): Promise>; - list(options: HeaderOptions, response?: IResponseFn>): Promise>; - list(response?: IResponseFn>): Promise>; + list(data: IListOptions, options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(data: IListOptions, response?: IResponseFn>): IListPromise; + list(options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(response?: IResponseFn>): IListPromise; /** * When you create a new bank account or credit card, you must specify a managed account to create it on. @@ -7122,16 +7128,16 @@ declare namespace Stripe { * available by default on the corresponding Stripe object. If you need more than those 10, you can use this API method and the limit * and starting_after parameters to page through additional bank accounts. */ - listExternalAccounts(accId: string, data: accounts.IBankAccountListOptions, options: HeaderOptions, response?: IResponseFn>): Promise>; - listExternalAccounts(accId: string, data: accounts.IBankAccountListOptions, response?: IResponseFn>): Promise>; + listExternalAccounts(accId: string, data: accounts.IBankAccountListOptions, options: HeaderOptions, response?: IResponseFn>): IListPromise; + listExternalAccounts(accId: string, data: accounts.IBankAccountListOptions, response?: IResponseFn>): IListPromise; /** * You can see a list of the cards belonging to a managed account. Note that the 10 most recent external accounts are available on the * account object. If you need more than those 10, you can use this API method and the limit and starting_after parameters to page * through additional cards. */ - listExternalAccounts(accId: string, data: accounts.ICardListOptions, options: HeaderOptions, response?: IResponseFn>): Promise>; - listExternalAccounts(accId: string, data: accounts.ICardListOptions, response?: IResponseFn>): Promise>; + listExternalAccounts(accId: string, data: accounts.ICardListOptions, options: HeaderOptions, response?: IResponseFn>): IListPromise; + listExternalAccounts(accId: string, data: accounts.ICardListOptions, response?: IResponseFn>): IListPromise; /** * Creates a single-use login link for an Express account to access their Stripe dashboard. @@ -7156,10 +7162,10 @@ declare namespace Stripe { * Returns a list of application fees you’ve previously collected. The application fees are returned in sorted order, with the most * recent fees appearing first. */ - list(data: applicationFees.IApplicationFeeListOptions, options: HeaderOptions, response?: IResponseFn>): Promise>; - list(data: applicationFees.IApplicationFeeListOptions, response?: IResponseFn>): Promise>; - list(options: HeaderOptions, response?: IResponseFn>): Promise>; - list(response?: IResponseFn>): Promise>; + list(data: applicationFees.IApplicationFeeListOptions, options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(data: applicationFees.IApplicationFeeListOptions, response?: IResponseFn>): IListPromise; + list(options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(response?: IResponseFn>): IListPromise; /** * Refunds an application fee that has previously been collected but not yet refunded. Funds will be refunded to the Stripe account that @@ -7210,10 +7216,10 @@ declare namespace Stripe { * by default on the application fee object. If you need more than those 10, you can use this API method and the limit and starting_after * parameters to page through additional refunds. */ - listRefunds(feeId: string, data: IListOptions, options: HeaderOptions, response?: IResponseFn>): Promise>; - listRefunds(feeId: string, data: IListOptions, response?: IResponseFn>): Promise>; - listRefunds(feeId: string, options: HeaderOptions, response?: IResponseFn>): Promise>; - listRefunds(feeId: string, response?: IResponseFn>): Promise>; + listRefunds(feeId: string, data: IListOptions, options: HeaderOptions, response?: IResponseFn>): IListPromise; + listRefunds(feeId: string, data: IListOptions, response?: IResponseFn>): IListPromise; + listRefunds(feeId: string, options: HeaderOptions, response?: IResponseFn>): IListPromise; + listRefunds(feeId: string, response?: IResponseFn>): IListPromise; } class ApplicationFeeRefunds extends StripeResource { @@ -7254,10 +7260,10 @@ declare namespace Stripe { * by default on the application fee object. If you need more than those 10, you can use this API method and the limit and starting_after * parameters to page through additional refunds. */ - list(data: IListOptions, options: HeaderOptions, response?: IResponseFn>): Promise>; - list(data: IListOptions, response?: IResponseFn>): Promise>; - list(options: HeaderOptions, response?: IResponseFn>): Promise>; - list(response?: IResponseFn>): Promise>; + list(data: IListOptions, options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(data: IListOptions, response?: IResponseFn>): IListPromise; + list(options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(response?: IResponseFn>): IListPromise; } class Balance extends StripeResource { @@ -7267,10 +7273,10 @@ declare namespace Stripe { retrieveTransaction(id: string, options: HeaderOptions, response?: IResponseFn): Promise; retrieveTransaction(id: string, response?: IResponseFn): Promise; - listTransactions(data: balance.IBalanceListOptions, options: HeaderOptions, response?: IResponseFn): Promise>; - listTransactions(data: balance.IBalanceListOptions, response?: IResponseFn): Promise>; - listTransactions(options: HeaderOptions, response?: IResponseFn): Promise>; - listTransactions(response?: IResponseFn): Promise>; + listTransactions(data: balance.IBalanceListOptions, options: HeaderOptions, response?: IResponseFn): IListPromise; + listTransactions(data: balance.IBalanceListOptions, response?: IResponseFn): IListPromise; + listTransactions(options: HeaderOptions, response?: IResponseFn): IListPromise; + listTransactions(response?: IResponseFn): IListPromise; } class BitcoinReceivers extends StripeResource { @@ -7292,8 +7298,8 @@ declare namespace Stripe { /** * Returns a list of your receivers. Receivers are returned sorted by creation date, with the most recently created receivers appearing first. */ - list(data: bitcoinReceivers.IBitcoinReceiverListOptions, options: HeaderOptions, response?: IResponseFn>): Promise>; - list(data: bitcoinReceivers.IBitcoinReceiverListOptions, response?: IResponseFn>): Promise>; + list(data: bitcoinReceivers.IBitcoinReceiverListOptions, options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(data: bitcoinReceivers.IBitcoinReceiverListOptions, response?: IResponseFn>): IListPromise; // update(id: string): void; // This does seem to be a method in the library (https://github.com/stripe/stripe-node/blob/master/lib/resources/BitcoinReceivers.js#L12), but isn't in the API documentation. @@ -7368,10 +7374,10 @@ declare namespace Stripe { * * @param data Filtering options for the returned items. */ - list(data: charges.IChargeListOptions, options: HeaderOptions, response?: IResponseFn>): Promise>; - list(data: charges.IChargeListOptions, response?: IResponseFn>): Promise>; - list(options: HeaderOptions, response?: IResponseFn>): Promise>; - list(response?: IResponseFn>): Promise>; + list(data: charges.IChargeListOptions, options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(data: charges.IChargeListOptions, response?: IResponseFn>): IListPromise; + list(options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(response?: IResponseFn>): IListPromise; /** * When you create a new refund, you must specify a charge to create it on. @@ -7438,10 +7444,10 @@ declare namespace Stripe { * @param chargeId The ID of the charge refunded * @param data Used to filter the refunds returned */ - listRefunds(chargeId: string, data: IListOptions, options: HeaderOptions, response?: IResponseFn>): Promise>; - listRefunds(chargeId: string, data: IListOptions, response?: IResponseFn>): Promise>; - listRefunds(chargeId: string, options: HeaderOptions, response?: IResponseFn>): Promise>; - listRefunds(chargeId: string, response?: IResponseFn>): Promise>; + listRefunds(chargeId: string, data: IListOptions, options: HeaderOptions, response?: IResponseFn>): IListPromise; + listRefunds(chargeId: string, data: IListOptions, response?: IResponseFn>): IListPromise; + listRefunds(chargeId: string, options: HeaderOptions, response?: IResponseFn>): IListPromise; + listRefunds(chargeId: string, response?: IResponseFn>): IListPromise; markAsSafe(chargeId: string, response?: IResponseFn): Promise; markAsFraudulent(chargeId: string, response?: IResponseFn): Promise; @@ -7488,10 +7494,10 @@ declare namespace Stripe { * with the most recent refunds appearing first. * For convenience, the 10 most recent refunds are always available by default on the charge object. */ - list?(data: refunds.IRefundListOptions, options: HeaderOptions, response?: IResponseFn>): Promise>; - list?(data: refunds.IRefundListOptions, response?: IResponseFn>): Promise>; - list?(options: HeaderOptions, response?: IResponseFn>): Promise>; - list?(response?: IResponseFn>): Promise>; + list?(data: refunds.IRefundListOptions, options: HeaderOptions, response?: IResponseFn>): IListPromise; + list?(data: refunds.IRefundListOptions, response?: IResponseFn>): IListPromise; + list?(options: HeaderOptions, response?: IResponseFn>): IListPromise; + list?(response?: IResponseFn>): IListPromise; } class Coupons extends StripeResource { @@ -7556,10 +7562,10 @@ declare namespace Stripe { * * @param data Filtering options for the list. */ - list(data: IListOptionsCreated, options: HeaderOptions, response?: IResponseFn>): Promise>; - list(data: IListOptionsCreated, response?: IResponseFn>): Promise>; - list(options: HeaderOptions, response?: IResponseFn>): Promise>; - list(response?: IResponseFn>): Promise>; + list(data: IListOptionsCreated, options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(data: IListOptionsCreated, response?: IResponseFn>): IListPromise; + list(options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(response?: IResponseFn>): IListPromise; } class CustomerCards extends StripeResource { @@ -7588,10 +7594,10 @@ declare namespace Stripe { * specify include[]=total_count in your request. * @param data Filtering options */ - list(data: IListOptions, options: HeaderOptions, response?: IResponseFn>): Promise>; - list(data: IListOptions, response?: IResponseFn>): Promise>; - list(options: HeaderOptions, response?: IResponseFn>): Promise>; - list(response?: IResponseFn>): Promise>; + list(data: IListOptions, options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(data: IListOptions, response?: IResponseFn>): IListPromise; + list(options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(response?: IResponseFn>): IListPromise; /** * If you need to update only some card details, like the billing address or expiration date, you can do so without having to re-enter the @@ -7660,10 +7666,10 @@ declare namespace Stripe { * * @param data Allows you to filter the customers you want. */ - list(data: customers.ICustomerListOptions, options: HeaderOptions, response?: IResponseFn>): Promise>; - list(data: customers.ICustomerListOptions, response?: IResponseFn>): Promise>; - list(options: HeaderOptions, response?: IResponseFn>): Promise>; - list(response?: IResponseFn>): Promise>; + list(data: customers.ICustomerListOptions, options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(data: customers.ICustomerListOptions, response?: IResponseFn>): IListPromise; + list(options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(response?: IResponseFn>): IListPromise; /** * Updates the specified customer by setting the values of the parameters passed. Any parameters not provided will be left unchanged. @@ -7782,10 +7788,10 @@ declare namespace Stripe { * @param customerId The ID of the customer whose cards will be retrieved * @param data Filtering options */ - listCards(customerId: string, data: IListOptions, options: HeaderOptions, response?: IResponseFn>): Promise>; - listCards(customerId: string, data: IListOptions, response?: IResponseFn>): Promise>; - listCards(customerId: string, options: HeaderOptions, response?: IResponseFn>): Promise>; - listCards(customerId: string, response?: IResponseFn>): Promise>; + listCards(customerId: string, data: IListOptions, options: HeaderOptions, response?: IResponseFn>): IListPromise; + listCards(customerId: string, data: IListOptions, response?: IResponseFn>): IListPromise; + listCards(customerId: string, options: HeaderOptions, response?: IResponseFn>): IListPromise; + listCards(customerId: string, response?: IResponseFn>): IListPromise; /** * When adding a card to a customer, the parameter name is source. When @@ -7827,8 +7833,8 @@ declare namespace Stripe { * @param customerId The ID of the customer whose cards will be retrieved * @param data Filtering options */ - listSources(customerId: string, data: customers.ICardSourceListOptions, options: HeaderOptions, response?: IResponseFn>): Promise>; - listSources(customerId: string, data: customers.ICardSourceListOptions, response?: IResponseFn>): Promise>; + listSources(customerId: string, data: customers.ICardSourceListOptions, options: HeaderOptions, response?: IResponseFn>): IListPromise; + listSources(customerId: string, data: customers.ICardSourceListOptions, response?: IResponseFn>): IListPromise; /** * You can see a list of the bank accounts belonging to a customer or recipient. Note that the 10 most recent * bank accounts are always available by default on the customer or recipient object. If you need more than @@ -7842,11 +7848,11 @@ declare namespace Stripe { * @param customerId The ID of the customer whose cards will be retrieved * @param data Filtering options */ - listSources(customerId: string, data: customers.IBankAccountSourceListOptions, options: HeaderOptions, response?: IResponseFn>): Promise>; - listSources(customerId: string, data: customers.IBankAccountSourceListOptions, response?: IResponseFn>): Promise>; + listSources(customerId: string, data: customers.IBankAccountSourceListOptions, options: HeaderOptions, response?: IResponseFn>): IListPromise; + listSources(customerId: string, data: customers.IBankAccountSourceListOptions, response?: IResponseFn>): IListPromise; - listSources(customerId: string, data: customers.ISourceListOptions, options: HeaderOptions, response?: IResponseFn>): Promise>; - listSources(customerId: string, data: customers.ISourceListOptions, response?: IResponseFn>): Promise>; + listSources(customerId: string, data: customers.ISourceListOptions, options: HeaderOptions, response?: IResponseFn>): IListPromise; + listSources(customerId: string, data: customers.ISourceListOptions, response?: IResponseFn>): IListPromise; /** * By default, you can see the 10 most recent cards/bank accounts stored on a customer or recipient directly on the customer or recipient object, but @@ -8003,10 +8009,10 @@ declare namespace Stripe { * @param customerId The ID of the customer whose subscriptions will be retrieved * @param data Filtering options */ - listSubscriptions(customerId: string, data: IListOptions, options: HeaderOptions, response?: IResponseFn>): Promise>; - listSubscriptions(customerId: string, data: IListOptions, response?: IResponseFn>): Promise>; - listSubscriptions(customerId: string, options: HeaderOptions, response?: IResponseFn>): Promise>; - listSubscriptions(customerId: string, response?: IResponseFn>): Promise>; + listSubscriptions(customerId: string, data: IListOptions, options: HeaderOptions, response?: IResponseFn>): IListPromise; + listSubscriptions(customerId: string, data: IListOptions, response?: IResponseFn>): IListPromise; + listSubscriptions(customerId: string, options: HeaderOptions, response?: IResponseFn>): IListPromise; + listSubscriptions(customerId: string, response?: IResponseFn>): IListPromise; /** * Removes the currently applied discount on a customer. @@ -8104,10 +8110,10 @@ declare namespace Stripe { * * @param data Filtering options */ - list(data: subscriptions.ISubscriptionListOptions, options: HeaderOptions, response?: IResponseFn>): Promise>; - list(data: subscriptions.ISubscriptionListOptions, response?: IResponseFn>): Promise>; - list(options: HeaderOptions, response?: IResponseFn>): Promise>; - list(response?: IResponseFn>): Promise>; + list(data: subscriptions.ISubscriptionListOptions, options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(data: subscriptions.ISubscriptionListOptions, response?: IResponseFn>): IListPromise; + list(options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(response?: IResponseFn>): IListPromise; /** * Removes the currently applied discount on a subscription. @@ -8199,8 +8205,8 @@ declare namespace Stripe { * * @param data Filtering options */ - list(data: subscriptionItems.ISubscriptionItemListOptions, options: HeaderOptions, response?: IResponseFn>): Promise>; - list(data: subscriptionItems.ISubscriptionItemListOptions, response?: IResponseFn>): Promise>; + list(data: subscriptionItems.ISubscriptionItemListOptions, options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(data: subscriptionItems.ISubscriptionItemListOptions, response?: IResponseFn>): IListPromise; } class Disputes extends StripeResource { @@ -8238,10 +8244,10 @@ declare namespace Stripe { /** * Returns a list of your disputes. */ - list(data: IListOptionsCreated, options: HeaderOptions, response?: IResponseFn>): Promise>; - list(data: IListOptionsCreated, response?: IResponseFn>): Promise>; - list(options: HeaderOptions, response?: IResponseFn>): Promise>; - list(response?: IResponseFn>): Promise>; + list(data: IListOptionsCreated, options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(data: IListOptionsCreated, response?: IResponseFn>): IListPromise; + list(options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(response?: IResponseFn>): IListPromise; setMetadata(): void; // TODO: Implement placeholder method getMetadata(): void; // TODO: Implement placeholder method @@ -8260,10 +8266,10 @@ declare namespace Stripe { /** * List events, going back up to 30 days. */ - list(data: events.IEventListOptions, options: HeaderOptions, response?: IResponseFn>): Promise>; - list(data: events.IEventListOptions, response?: IResponseFn>): Promise>; - list(options: HeaderOptions, response?: IResponseFn>): Promise>; - list(response?: IResponseFn>): Promise>; + list(data: events.IEventListOptions, options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(data: events.IEventListOptions, response?: IResponseFn>): IListPromise; + list(options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(response?: IResponseFn>): IListPromise; } class FileUploads extends StripeResource { @@ -8289,10 +8295,10 @@ declare namespace Stripe { * Returns a list of the files that you have uploaded to Stripe. * The file uploads are returned sorted by creation date, with the most recently created file uploads appearing first. */ - list(data: fileUploads.IFileUploadListOptions, options: HeaderOptions, response?: IResponseFn>): Promise>; - list(data: fileUploads.IFileUploadListOptions, response?: IResponseFn>): Promise>; - list(options: HeaderOptions, response?: IResponseFn>): Promise>; - list(response?: IResponseFn>): Promise>; + list(data: fileUploads.IFileUploadListOptions, options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(data: fileUploads.IFileUploadListOptions, response?: IResponseFn>): IListPromise; + list(options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(response?: IResponseFn>): IListPromise; } class Invoices extends StripeResource { @@ -8342,10 +8348,10 @@ declare namespace Stripe { * @param id The id of the invoice containing the lines to be retrieved * @param data Filtering options */ - retrieveLines(id: string, data: invoices.IInvoiceLineItemRetrievalOptions, options: HeaderOptions, response?: IResponseFn>): Promise>; - retrieveLines(id: string, data: invoices.IInvoiceLineItemRetrievalOptions, response?: IResponseFn>): Promise>; - retrieveLines(id: string, options: HeaderOptions, response?: IResponseFn>): Promise>; - retrieveLines(id: string, response?: IResponseFn>): Promise>; + retrieveLines(id: string, data: invoices.IInvoiceLineItemRetrievalOptions, options: HeaderOptions, response?: IResponseFn>): IListPromise; + retrieveLines(id: string, data: invoices.IInvoiceLineItemRetrievalOptions, response?: IResponseFn>): IListPromise; + retrieveLines(id: string, options: HeaderOptions, response?: IResponseFn>): IListPromise; + retrieveLines(id: string, response?: IResponseFn>): IListPromise; /** * At any time, you can preview the upcoming invoice for a customer. This will show you all the charges that are pending, @@ -8403,9 +8409,9 @@ declare namespace Stripe { * * @param data Filtering options */ - list(data: invoices.IInvoiceListOptions, options: HeaderOptions, response?: IResponseFn>): Promise>; - list(data: invoices.IInvoiceListOptions, response?: IResponseFn>): Promise>; - list(response?: IResponseFn>): Promise>; + list(data: invoices.IInvoiceListOptions, options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(data: invoices.IInvoiceListOptions, response?: IResponseFn>): IListPromise; + list(response?: IResponseFn>): IListPromise; } class InvoiceItems extends StripeResource { @@ -8432,10 +8438,10 @@ declare namespace Stripe { * Returns a list of your invoice items. Invoice items are returned sorted by creation date, with the most recently created invoice * items appearing first. */ - list(data: invoiceItems.InvoiceItemListOptions, options: HeaderOptions, response?: IResponseFn>): Promise>; - list(data: invoiceItems.InvoiceItemListOptions, response?: IResponseFn>): Promise>; - list(options: HeaderOptions, response?: IResponseFn>): Promise>; - list(response?: IResponseFn>): Promise>; + list(data: invoiceItems.InvoiceItemListOptions, options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(data: invoiceItems.InvoiceItemListOptions, response?: IResponseFn>): IListPromise; + list(options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(response?: IResponseFn>): IListPromise; /** * Removes an invoice item from the upcoming invoice. Removing an invoice item is only possible before the invoice it's attached @@ -8468,18 +8474,18 @@ declare namespace Stripe { data: paymentIntents.IPaymentIntentListOptions, options: HeaderOptions, response?: IResponseFn>, - ): Promise>; + ): IListPromise; list( data: paymentIntents.IPaymentIntentListOptions, response?: IResponseFn>, - ): Promise>; + ): IListPromise; list( options: HeaderOptions, response?: IResponseFn>, - ): Promise>; + ): IListPromise; list( response?: IResponseFn>, - ): Promise>; + ): IListPromise; /** * Updates a PaymentIntent object. @@ -8637,10 +8643,10 @@ declare namespace Stripe { /** * Returns a list of existing payouts sent to third-party bank accounts or that Stripe has sent you. The payouts are returned in sorted order, with the most recently created payouts appearing first. */ - list(data: payouts.IPayoutListOptions, options: HeaderOptions, response?: IResponseFn>): Promise>; - list(data: payouts.IPayoutListOptions, response?: IResponseFn>): Promise>; - list(options: HeaderOptions, response?: IResponseFn>): Promise>; - list(response?: IResponseFn>): Promise>; + list(data: payouts.IPayoutListOptions, options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(data: payouts.IPayoutListOptions, response?: IResponseFn>): IListPromise; + list(options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(response?: IResponseFn>): IListPromise; /** * A previously created payout can be canceled if it has not yet been paid out. Funds will be refunded to your available balance, and the fees you were originally charged on the payout will be refunded. @@ -8703,10 +8709,10 @@ declare namespace Stripe { * request should never throw an error. You can optionally request that the response include the total count of all plans. To * do so, specify include[]=total_count in your request. */ - list(data: IPlanListOptions, options: HeaderOptions, response?: IResponseFn>): Promise>; - list(data: IPlanListOptions, response?: IResponseFn>): Promise>; - list(options: HeaderOptions, response?: IResponseFn>): Promise>; - list(response?: IResponseFn>): Promise>; + list(data: IPlanListOptions, options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(data: IPlanListOptions, response?: IResponseFn>): IListPromise; + list(options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(response?: IResponseFn>): IListPromise; } interface IPlanListOptions extends IListOptionsCreated { @@ -8814,10 +8820,10 @@ declare namespace Stripe { * with the most recent refunds appearing first. * For convenience, the 10 most recent refunds are always available by default on the charge object. */ - list(data: refunds.IRefundListOptions, options: HeaderOptions, response?: IResponseFn>): Promise>; - list(data: refunds.IRefundListOptions, response?: IResponseFn>): Promise>; - list(options: HeaderOptions, response?: IResponseFn>): Promise>; - list(response?: IResponseFn>): Promise>; + list(data: refunds.IRefundListOptions, options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(data: refunds.IRefundListOptions, response?: IResponseFn>): IListPromise; + list(options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(response?: IResponseFn>): IListPromise; } class Sources extends StripeResource { @@ -8904,16 +8910,16 @@ declare namespace Stripe { * Returns a list of existing transfers sent to third-party bank accounts or that Stripe has sent you. The transfers are * returned in sorted order, with the most recently created transfers appearing first. */ - list(data: transfers.ITransferListOptions, options: HeaderOptions, response?: IResponseFn>): Promise>; - list(data: transfers.ITransferListOptions, response?: IResponseFn>): Promise>; - list(options: HeaderOptions, response?: IResponseFn>): Promise>; - list(response?: IResponseFn>): Promise>; + list(data: transfers.ITransferListOptions, options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(data: transfers.ITransferListOptions, response?: IResponseFn>): IListPromise; + list(options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(response?: IResponseFn>): IListPromise; cancel(id: string, options: HeaderOptions, response?: IResponseFn): Promise; cancel(id: string, response?: IResponseFn): Promise; - listTransactions(options: HeaderOptions, response?: IResponseFn>): Promise>; // TODO: Not sure if this should be a list of balance transactions or charges. - listTransactions(response?: IResponseFn>): Promise>; // TODO: Not sure if this should be a list of balance transactions or charges. + listTransactions(options: HeaderOptions, response?: IResponseFn>): IListPromise; // TODO: Not sure if this should be a list of balance transactions or charges. + listTransactions(response?: IResponseFn>): IListPromise; // TODO: Not sure if this should be a list of balance transactions or charges. /** * When you create a new reversal, you must specify a transfer to create it on. @@ -8967,10 +8973,10 @@ declare namespace Stripe { * default on the transfer object. If you need more than those 10, you can use this API method and the limit and starting_after * parameters to page through additional reversals. */ - listReversals(transferId: string, data: IListOptions, options: HeaderOptions, response?: IResponseFn>): Promise>; - listReversals(transferId: string, data: IListOptions, response?: IResponseFn>): Promise>; - listReversals(transferId: string, options: HeaderOptions, response?: IResponseFn>): Promise>; - listReversals(transferId: string, response?: IResponseFn>): Promise>; + listReversals(transferId: string, data: IListOptions, options: HeaderOptions, response?: IResponseFn>): IListPromise; + listReversals(transferId: string, data: IListOptions, response?: IResponseFn>): IListPromise; + listReversals(transferId: string, options: HeaderOptions, response?: IResponseFn>): IListPromise; + listReversals(transferId: string, response?: IResponseFn>): IListPromise; setMetadata(): void; // TODO: Implement placeholder method getMetadata(): void; // TODO: Implement placeholder method @@ -9015,20 +9021,20 @@ declare namespace Stripe { * default on the transfer object. If you need more than those 10, you can use this API method and the limit and starting_after * parameters to page through additional reversals. */ - list(data: IListOptions, options: HeaderOptions, response?: IResponseFn>): Promise>; - list(data: IListOptions, response?: IResponseFn>): Promise>; - list(options: HeaderOptions, response?: IResponseFn>): Promise>; - list(response?: IResponseFn>): Promise>; + list(data: IListOptions, options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(data: IListOptions, response?: IResponseFn>): IListPromise; + list(options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(response?: IResponseFn>): IListPromise; } class CountrySpecs extends StripeResource { /** * Lists all Country Spec objects available in the API. */ - list(data: IListOptions, options: HeaderOptions, response?: IResponseFn>): Promise>; - list(data: IListOptions, response?: IResponseFn>): Promise>; - list(options: HeaderOptions, response?: IResponseFn>): Promise>; - list(response?: IResponseFn>): Promise>; + list(data: IListOptions, options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(data: IListOptions, response?: IResponseFn>): IListPromise; + list(options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(response?: IResponseFn>): IListPromise; /** * Returns a Country Spec for a given Country code. @@ -9073,10 +9079,10 @@ declare namespace Stripe { /** * Returns a list of your orders. The orders are returned sorted by creation date, with the most recently created orders appearing first. */ - list(data: orders.IOrderListOptions, options: HeaderOptions, response?: IResponseFn>): Promise>; - list(data: orders.IOrderListOptions, response?: IResponseFn>): Promise>; - list(options: HeaderOptions, response?: IResponseFn>): Promise>; - list(response?: IResponseFn>): Promise>; + list(data: orders.IOrderListOptions, options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(data: orders.IOrderListOptions, response?: IResponseFn>): IListPromise; + list(options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(response?: IResponseFn>): IListPromise; } class Products { @@ -9107,10 +9113,10 @@ declare namespace Stripe { /** * Returns a list of your products. The products are returned sorted by creation date, with the most recently created products appearing first. */ - list(data: products.IProductListOptions, options: HeaderOptions, response?: IResponseFn>): Promise>; - list(data: products.IProductListOptions, response?: IResponseFn>): Promise>; - list(options: HeaderOptions, response?: IResponseFn>): Promise>; - list(response?: IResponseFn>): Promise>; + list(data: products.IProductListOptions, options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(data: products.IProductListOptions, response?: IResponseFn>): IListPromise; + list(options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(response?: IResponseFn>): IListPromise; /** * Delete a product. Deleting a product is only possible if it has no SKUs associated with it. @@ -9147,10 +9153,10 @@ declare namespace Stripe { /** * Returns a list of your SKUs. The SKUs are returned sorted by creation date, with the most recently created SKUs appearing first. */ - list(data: skus.ISkuListOptions, options: HeaderOptions, response?: IResponseFn>): Promise>; - list(data: skus.ISkuListOptions, response?: IResponseFn>): Promise>; - list(options: HeaderOptions, response?: IResponseFn>): Promise>; - list(response?: IResponseFn>): Promise>; + list(data: skus.ISkuListOptions, options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(data: skus.ISkuListOptions, response?: IResponseFn>): IListPromise; + list(options: HeaderOptions, response?: IResponseFn>): IListPromise; + list(response?: IResponseFn>): IListPromise; /** * Delete a SKU. Deleting a SKU is only possible until it has been used in an order. diff --git a/types/stripe/stripe-tests.ts b/types/stripe/stripe-tests.ts index 6b31a443a7..67d7f78d1a 100644 --- a/types/stripe/stripe-tests.ts +++ b/types/stripe/stripe-tests.ts @@ -5,6 +5,24 @@ const stripe = new Stripe("sk_test_BF573NobVn98OiIsPAv7A04K"); stripe.setApiVersion('2019-05-16'); +// generic list tests +// ################################################################################## +stripe.balance.listTransactions().then(items => { + items; // $ExpectType IList +}); +stripe.balance.listTransactions().autoPagingEach(async item => { + item; // $ExpectType IBalanceTransaction +}); +stripe.balance.listTransactions().autoPagingToArray({}); // $ExpectError +stripe.balance.listTransactions().autoPagingToArray({limit: 1}).then(items => { + items; // $ExpectType IBalanceTransaction[] +}); +async function testAutoPaging() { + for await (const item of stripe.balance.listTransactions()) { + item; // $ExpectType IBalanceTransaction + } +} + //#region Balance tests // ################################################################################## diff --git a/types/stripe/tsconfig.json b/types/stripe/tsconfig.json index 46d4cf5ff6..532dc20865 100644 --- a/types/stripe/tsconfig.json +++ b/types/stripe/tsconfig.json @@ -2,7 +2,8 @@ "compilerOptions": { "module": "commonjs", "lib": [ - "es6" + "es6", + "esnext.asynciterable" ], "noImplicitAny": true, "noImplicitThis": true,