Skip to content

Commit

Permalink
Add types for extra request options (#1448)
Browse files Browse the repository at this point in the history
* Add types for extra request options

* tests and fewer props

Co-authored-by: Pavel Krymets <pakrym@stripe.com>
  • Loading branch information
remi-stripe and pakrym-stripe committed Jun 9, 2022
1 parent 5416318 commit 5135ab0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/StripeResource.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,24 @@ describe('StripeResource', () => {
}
);
});

it('allows overriding host', (done) => {
const scope = nock('https://myhost')
.get('/v1/accounts/acct_123')
.reply(200, '{}');

realStripe.accounts.retrieve(
'acct_123',
{},
{
host: 'myhost',
},
(err, response) => {
done(err);
scope.done();
}
);
});
});
});

Expand Down
14 changes: 14 additions & 0 deletions types/lib.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,19 @@ declare module 'stripe' {
*/
timeout?: number;

/**
* Specify the host to use for API Requests.
*/
host?: string;

/**
* Specify the port to use for API Requests.
*/
port?: string | number;

/**
* Specify the HTTP protool to use for API Requests.
*/
protocol?: HttpProtocol;

/**
Expand Down Expand Up @@ -170,6 +179,11 @@ declare module 'stripe' {
* Specify a timeout for this request in milliseconds.
*/
timeout?: number;

/**
* Specify the host for this request.
*/
host?: string;
}

export type Response<T> = T & {
Expand Down
4 changes: 4 additions & 0 deletions types/test/typescriptTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,7 @@ Stripe.StripeError.generate({
Stripe.errors.StripeError.generate({
type: 'card_error',
});

stripe.accounts.retrieve('123', {
host: 'my_host',
});

0 comments on commit 5135ab0

Please sign in to comment.