diff --git a/types/2020-08-27/index.d.ts b/types/2020-08-27/index.d.ts index 36185d555c..a4cc146e83 100644 --- a/types/2020-08-27/index.d.ts +++ b/types/2020-08-27/index.d.ts @@ -105,6 +105,8 @@ declare module 'stripe' { setAppInfo(info: Stripe.AppInfo): void; + StripeResource: Stripe.StripeResource; + /** * Top Level Resources */ diff --git a/types/lib.d.ts b/types/lib.d.ts index 78c00f2974..4dd672a781 100644 --- a/types/lib.d.ts +++ b/types/lib.d.ts @@ -5,6 +5,43 @@ import {Agent} from 'http'; declare module 'stripe' { namespace Stripe { + export class StripeResource { + static extend< + // eslint-disable-next-line @typescript-eslint/no-explicit-any + T extends {[prop: string]: any} & { + includeBasic?: Array< + 'create' | 'retrieve' | 'update' | 'list' | 'del' + >; + } + >(spec: T): StripeResource & T; + static method(spec: { + method: string; + path: string; + methodType?: 'list'; + }): (...args: any[]) => object; //eslint-disable-line @typescript-eslint/no-explicit-any + static BASIC_METHODS: { + create( + params: CouponCreateParams, + options?: RequestOptions + ): Promise; + retrieve( + id: string, + params?: CouponRetrieveParams, + options?: RequestOptions + ): Promise; + update( + id: string, + params?: CouponUpdateParams, + options?: RequestOptions + ): Promise; + list( + params?: CouponListParams, + options?: RequestOptions + ): ApiListPromise; + del(id: string, options?: RequestOptions): Promise; + }; + static MAX_BUFFERED_REQUEST_METRICS: number; + } export type LatestApiVersion = '2020-08-27'; export type HttpAgent = Agent; diff --git a/types/test/typescriptTest.ts b/types/test/typescriptTest.ts index b9503ee38a..8d4d294956 100644 --- a/types/test/typescriptTest.ts +++ b/types/test/typescriptTest.ts @@ -168,3 +168,14 @@ const stripeCardError: Stripe.StripeCardError = Stripe.errors.generate({ code: 'card_declined', charge: 'ch_123', }); + +Stripe.StripeResource.extend({ + includeBasic: ['retrieve'], + foo: Stripe.StripeResource.method({ + method: 'create', + path: 'foo', + }), +}); + +const maxBufferedRequestMetrics: number = + Stripe.StripeResource.MAX_BUFFERED_REQUEST_METRICS;