Skip to content

Commit 1b5ff05

Browse files
Revert "Add raw_request (#2185)" (#2188)
This reverts commit 6d3cef2.
1 parent 6d3cef2 commit 1b5ff05

File tree

8 files changed

+7
-387
lines changed

8 files changed

+7
-387
lines changed

README.md

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -517,40 +517,6 @@ const stripe = new Stripe('sk_test_...', {
517517
});
518518
```
519519

520-
### Custom requests
521-
522-
If you would like to send a request to an undocumented API (for example you are in a private beta), or if you prefer to bypass the method definitions in the library and specify your request details directly, you can use the `rawRequest` method on the StripeClient object.
523-
524-
```javascript
525-
const client = new Stripe('sk_test_...');
526-
527-
client.rawRequest(
528-
'POST',
529-
'/v1/beta_endpoint',
530-
{ param: 123 },
531-
{ apiVersion: '2022-11-15; feature_beta=v3' }
532-
)
533-
.then((response) => /* handle response */ )
534-
.catch((error) => console.error(error));
535-
```
536-
537-
Or using ES modules and `async`/`await`:
538-
539-
```javascript
540-
import Stripe from 'stripe';
541-
const stripe = new Stripe('sk_test_...');
542-
543-
const response = await stripe.rawRequest(
544-
'POST',
545-
'/v1/beta_endpoint',
546-
{ param: 123 },
547-
{ apiVersion: '2022-11-15; feature_beta=v3' }
548-
);
549-
550-
// handle response
551-
```
552-
553-
554520
## Support
555521

556522
New features and bug fixes are released on the latest major version of the `stripe` package. If you are on an older major version, we recommend that you upgrade to the latest in order to use the new features and bug fixes including those for security vulnerabilities. Older major versions of the package will continue to be available for use, but will not be receiving any updates.

src/RequestSender.ts

Lines changed: 1 addition & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import {
1111
normalizeHeaders,
1212
removeNullish,
1313
stringifyRequestData,
14-
getDataFromArgs,
15-
getOptionsFromArgs,
1614
} from './utils.js';
1715
import {HttpClient, HttpClientResponseInterface} from './net/HttpClient.js';
1816
import {
@@ -26,8 +24,6 @@ import {
2624
RequestData,
2725
RequestOptions,
2826
RequestDataProcessor,
29-
RequestOpts,
30-
RequestArgs,
3127
} from './Types.js';
3228

3329
export type HttpClientResponseError = {code: string};
@@ -426,84 +422,11 @@ export class RequestSender {
426422
}
427423
}
428424

429-
_rawRequest(
430-
method: string,
431-
path: string,
432-
params?: RequestData,
433-
options?: RequestOptions
434-
): Promise<any> {
435-
const requestPromise = new Promise<any>((resolve, reject) => {
436-
let opts: RequestOpts;
437-
try {
438-
const requestMethod = method.toUpperCase();
439-
if (
440-
requestMethod !== 'POST' &&
441-
params &&
442-
Object.keys(params).length !== 0
443-
) {
444-
throw new Error(
445-
'rawRequest only supports params on POST requests. Please pass null and add your parameters to path.'
446-
);
447-
}
448-
const args: RequestArgs = [].slice.call([params, options]);
449-
450-
// Pull request data and options (headers, auth) from args.
451-
const dataFromArgs = getDataFromArgs(args);
452-
const data = Object.assign({}, dataFromArgs);
453-
const calculatedOptions = getOptionsFromArgs(args);
454-
455-
const headers = calculatedOptions.headers;
456-
457-
opts = {
458-
requestMethod,
459-
requestPath: path,
460-
bodyData: data,
461-
queryData: {},
462-
auth: calculatedOptions.auth,
463-
headers,
464-
host: null,
465-
streaming: false,
466-
settings: {},
467-
usage: ['raw_request'],
468-
};
469-
} catch (err) {
470-
reject(err);
471-
return;
472-
}
473-
474-
function requestCallback(
475-
err: any,
476-
response: HttpClientResponseInterface
477-
): void {
478-
if (err) {
479-
reject(err);
480-
} else {
481-
resolve(response);
482-
}
483-
}
484-
485-
const {headers, settings} = opts;
486-
487-
this._request(
488-
opts.requestMethod,
489-
opts.host,
490-
path,
491-
opts.bodyData,
492-
opts.auth,
493-
{headers, settings, streaming: opts.streaming},
494-
opts.usage,
495-
requestCallback
496-
);
497-
});
498-
499-
return requestPromise;
500-
}
501-
502425
_request(
503426
method: string,
504427
host: string | null,
505428
path: string,
506-
data: RequestData | null,
429+
data: RequestData,
507430
auth: string | null,
508431
options: RequestOptions = {},
509432
usage: Array<string> = [],

src/Types.d.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -149,20 +149,8 @@ export type StripeObject = {
149149
_getPropsFromConfig: (config: Record<string, unknown>) => UserProvidedConfig;
150150
_clientId?: string;
151151
_platformFunctions: PlatformFunctions;
152-
rawRequest: (
153-
method: string,
154-
path: string,
155-
data: RequestData,
156-
options: RequestOptions
157-
) => Promise<any>;
158152
};
159153
export type RequestSender = {
160-
_rawRequest(
161-
method: string,
162-
path: string,
163-
params?: RequestData,
164-
options?: RequestOptions
165-
): Promise<any>;
166154
_request(
167155
method: string,
168156
host: string | null,
@@ -223,7 +211,7 @@ export type StripeResourceObject = {
223211
};
224212
export type RequestDataProcessor = (
225213
method: string,
226-
data: RequestData | null,
214+
data: RequestData,
227215
headers: RequestHeaders | undefined,
228216
prepareAndMakeRequest: (error: Error | null, data: string) => void
229217
) => void;

src/stripe.core.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import * as _Error from './Error.js';
22
import {RequestSender} from './RequestSender.js';
33
import {StripeResource} from './StripeResource.js';
4-
import {
5-
AppInfo,
6-
StripeObject,
7-
RequestData,
8-
RequestOptions,
9-
UserProvidedConfig,
10-
} from './Types.js';
4+
import {AppInfo, StripeObject, UserProvidedConfig} from './Types.js';
115
import {WebhookObject, createWebhooks} from './Webhooks.js';
126
import * as apiVersion from './apiVersion.js';
137
import {CryptoProvider} from './crypto/CryptoProvider.js';
@@ -214,15 +208,6 @@ export function createStripe(
214208
_requestSender: null!,
215209
_platformFunctions: null!,
216210

217-
rawRequest(
218-
method: string,
219-
path: string,
220-
params?: RequestData,
221-
options?: RequestOptions
222-
): Promise<any> {
223-
return this._requestSender._rawRequest(method, path, params, options);
224-
},
225-
226211
/**
227212
* @private
228213
*/

src/utils.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ const OPTIONS_KEYS = [
1616
'maxNetworkRetries',
1717
'timeout',
1818
'host',
19-
'additionalHeaders',
2019
];
2120

2221
type Settings = {
@@ -29,7 +28,7 @@ type Options = {
2928
host: string | null;
3029
settings: Settings;
3130
streaming?: boolean;
32-
headers: RequestHeaders;
31+
headers: Record<string, unknown>;
3332
};
3433

3534
export function isOptionsHash(o: unknown): boolean | unknown {
@@ -159,13 +158,13 @@ export function getOptionsFromArgs(args: RequestArgs): Options {
159158
opts.auth = params.apiKey as string;
160159
}
161160
if (params.idempotencyKey) {
162-
opts.headers['Idempotency-Key'] = params.idempotencyKey as string;
161+
opts.headers['Idempotency-Key'] = params.idempotencyKey;
163162
}
164163
if (params.stripeAccount) {
165-
opts.headers['Stripe-Account'] = params.stripeAccount as string;
164+
opts.headers['Stripe-Account'] = params.stripeAccount;
166165
}
167166
if (params.apiVersion) {
168-
opts.headers['Stripe-Version'] = params.apiVersion as string;
167+
opts.headers['Stripe-Version'] = params.apiVersion;
169168
}
170169
if (Number.isInteger(params.maxNetworkRetries)) {
171170
opts.settings.maxNetworkRetries = params.maxNetworkRetries as number;
@@ -176,11 +175,6 @@ export function getOptionsFromArgs(args: RequestArgs): Options {
176175
if (params.host) {
177176
opts.host = params.host as string;
178177
}
179-
if (params.additionalHeaders) {
180-
opts.headers = params.additionalHeaders as {
181-
[headerName: string]: string;
182-
};
183-
}
184178
}
185179
}
186180
return opts;

0 commit comments

Comments
 (0)