@automattic/request-promise-native 2.1.1 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- var core = require('../'),
1
+ var core = require('../lib/plumbing'),
2
2
  isArray = require('lodash/isArray'),
3
3
  isFunction = require('lodash/isFunction'),
4
4
  isObjectLike = require('lodash/isObjectLike');
package/errors.js CHANGED
@@ -1 +1 @@
1
- module.exports = require('request-promise-core/errors');
1
+ module.exports = require('./deps/promise-core/errors.js');
@@ -0,0 +1,393 @@
1
+ // See https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/request/index.d.ts
2
+
3
+ import caseless from "caseless";
4
+ import { Stream, Readable } from "node:stream";
5
+ import http from "node:http";
6
+ import https from "node:https";
7
+ import FormData from "form-data";
8
+ import net from "node:net";
9
+ import ToughCookie from "tough-cookie";
10
+ import { Url } from "node:url";
11
+
12
+ declare namespace request {
13
+ interface RequestAPI<TRequest extends Request, TOptions extends CoreOptions, TUriUrlOptions> {
14
+ defaults(options: TOptions): RequestAPI<TRequest, TOptions, RequiredUriUrl>;
15
+ defaults(options: RequiredUriUrl & TOptions): DefaultUriUrlRequestApi<TRequest, TOptions, OptionalUriUrl>;
16
+
17
+ (uri: string, options?: TOptions, callback?: RequestCallback): TRequest;
18
+ (uri: string, callback?: RequestCallback): TRequest;
19
+ (options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest;
20
+
21
+ get(uri: string, options?: TOptions, callback?: RequestCallback): TRequest;
22
+ get(uri: string, callback?: RequestCallback): TRequest;
23
+ get(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest;
24
+
25
+ post(uri: string, options?: TOptions, callback?: RequestCallback): TRequest;
26
+ post(uri: string, callback?: RequestCallback): TRequest;
27
+ post(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest;
28
+
29
+ put(uri: string, options?: TOptions, callback?: RequestCallback): TRequest;
30
+ put(uri: string, callback?: RequestCallback): TRequest;
31
+ put(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest;
32
+
33
+ head(uri: string, options?: TOptions, callback?: RequestCallback): TRequest;
34
+ head(uri: string, callback?: RequestCallback): TRequest;
35
+ head(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest;
36
+
37
+ patch(uri: string, options?: TOptions, callback?: RequestCallback): TRequest;
38
+ patch(uri: string, callback?: RequestCallback): TRequest;
39
+ patch(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest;
40
+
41
+ del(uri: string, options?: TOptions, callback?: RequestCallback): TRequest;
42
+ del(uri: string, callback?: RequestCallback): TRequest;
43
+ del(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest;
44
+
45
+ delete(uri: string, options?: TOptions, callback?: RequestCallback): TRequest;
46
+ delete(uri: string, callback?: RequestCallback): TRequest;
47
+ delete(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest;
48
+
49
+ initParams(uri: string, options?: TOptions, callback?: RequestCallback): RequiredUriUrl & TOptions;
50
+ initParams(
51
+ uriOrOpts: string | RequiredUriUrl & TOptions,
52
+ callback?: RequestCallback,
53
+ ): RequiredUriUrl & TOptions;
54
+
55
+ forever(agentOptions: any, optionsArg: any): TRequest;
56
+ jar(store?: any): CookieJar;
57
+ cookie(str: string): Cookie | undefined;
58
+
59
+ debug: boolean;
60
+ }
61
+
62
+ interface DefaultUriUrlRequestApi<TRequest extends Request, TOptions extends CoreOptions, TUriUrlOptions>
63
+ extends RequestAPI<TRequest, TOptions, TUriUrlOptions>
64
+ {
65
+ defaults(options: TOptions): DefaultUriUrlRequestApi<TRequest, TOptions, OptionalUriUrl>;
66
+ (callback?: RequestCallback): TRequest;
67
+
68
+ get(uri: string, options?: TOptions, callback?: RequestCallback): TRequest;
69
+ get(uri: string, callback?: RequestCallback): TRequest;
70
+ get(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest;
71
+ get(callback?: RequestCallback): TRequest;
72
+
73
+ post(uri: string, options?: TOptions, callback?: RequestCallback): TRequest;
74
+ post(uri: string, callback?: RequestCallback): TRequest;
75
+ post(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest;
76
+ post(callback?: RequestCallback): TRequest;
77
+
78
+ put(uri: string, options?: TOptions, callback?: RequestCallback): TRequest;
79
+ put(uri: string, callback?: RequestCallback): TRequest;
80
+ put(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest;
81
+ put(callback?: RequestCallback): TRequest;
82
+
83
+ head(uri: string, options?: TOptions, callback?: RequestCallback): TRequest;
84
+ head(uri: string, callback?: RequestCallback): TRequest;
85
+ head(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest;
86
+ head(callback?: RequestCallback): TRequest;
87
+
88
+ patch(uri: string, options?: TOptions, callback?: RequestCallback): TRequest;
89
+ patch(uri: string, callback?: RequestCallback): TRequest;
90
+ patch(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest;
91
+ patch(callback?: RequestCallback): TRequest;
92
+
93
+ del(uri: string, options?: TOptions, callback?: RequestCallback): TRequest;
94
+ del(uri: string, callback?: RequestCallback): TRequest;
95
+ del(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest;
96
+ del(callback?: RequestCallback): TRequest;
97
+
98
+ delete(uri: string, options?: TOptions, callback?: RequestCallback): TRequest;
99
+ delete(uri: string, callback?: RequestCallback): TRequest;
100
+ delete(options: TUriUrlOptions & TOptions, callback?: RequestCallback): TRequest;
101
+ delete(callback?: RequestCallback): TRequest;
102
+ }
103
+
104
+ interface CoreOptions {
105
+ baseUrl?: string | undefined;
106
+ callback?: RequestCallback | undefined;
107
+ jar?: CookieJar | boolean | undefined;
108
+ formData?: { [key: string]: any } | undefined;
109
+ form?: { [key: string]: any } | string | undefined;
110
+ auth?: AuthOptions | undefined;
111
+ oauth?: OAuthOptions | undefined;
112
+ aws?: AWSOptions | undefined;
113
+ hawk?: HawkOptions | undefined;
114
+ qs?: any;
115
+ qsStringifyOptions?: any;
116
+ qsParseOptions?: any;
117
+ json?: any;
118
+ jsonReviver?: ((key: string, value: any) => any) | undefined;
119
+ jsonReplacer?: ((key: string, value: any) => any) | undefined;
120
+ multipart?: RequestPart[] | Multipart | undefined;
121
+ agent?: http.Agent | https.Agent | undefined;
122
+ agentOptions?: http.AgentOptions | https.AgentOptions | undefined;
123
+ agentClass?: any;
124
+ forever?: any;
125
+ host?: string | undefined;
126
+ port?: number | undefined;
127
+ method?: string | undefined;
128
+ headers?: Headers | undefined;
129
+ body?: any;
130
+ family?: 4 | 6 | undefined;
131
+ followRedirect?: boolean | ((response: http.IncomingMessage) => boolean) | undefined;
132
+ followAllRedirects?: boolean | undefined;
133
+ followOriginalHttpMethod?: boolean | undefined;
134
+ maxRedirects?: number | undefined;
135
+ removeRefererHeader?: boolean | undefined;
136
+ encoding?: string | null | undefined;
137
+ pool?: PoolOptions | undefined;
138
+ timeout?: number | undefined;
139
+ localAddress?: string | undefined;
140
+ proxy?: any;
141
+ tunnel?: boolean | undefined;
142
+ strictSSL?: boolean | undefined;
143
+ rejectUnauthorized?: boolean | undefined;
144
+ time?: boolean | undefined;
145
+ gzip?: boolean | undefined;
146
+ preambleCRLF?: boolean | undefined;
147
+ postambleCRLF?: boolean | undefined;
148
+ withCredentials?: boolean | undefined;
149
+ key?: Buffer | undefined;
150
+ cert?: Buffer | undefined;
151
+ passphrase?: string | undefined;
152
+ ca?: string | Buffer | string[] | Buffer[] | undefined;
153
+ har?: HttpArchiveRequest | undefined;
154
+ useQuerystring?: boolean | undefined;
155
+ }
156
+
157
+ interface UriOptions {
158
+ uri: string | Url;
159
+ }
160
+ interface UrlOptions {
161
+ url: string | Url;
162
+ }
163
+ type RequiredUriUrl = UriOptions | UrlOptions;
164
+
165
+ type OptionalUriUrl = RequiredUriUrl | {};
166
+
167
+ type OptionsWithUri = UriOptions & CoreOptions;
168
+ type OptionsWithUrl = UrlOptions & CoreOptions;
169
+ type Options = OptionsWithUri | OptionsWithUrl;
170
+
171
+ type MultipartBody = string | Buffer | ArrayBuffer | Uint8Array;
172
+
173
+ type RequestCallback = (error: any, response: Response, body: any) => void;
174
+
175
+ interface HttpArchiveRequest {
176
+ url?: string | undefined;
177
+ method?: string | undefined;
178
+ headers?: NameValuePair[] | undefined;
179
+ postData?: {
180
+ mimeType?: string | undefined;
181
+ params?: NameValuePair[] | undefined;
182
+ } | undefined;
183
+ }
184
+
185
+ interface ExtraPoolOptions {
186
+ maxSockets?: number | undefined;
187
+ }
188
+
189
+ type PoolOptions = false | { [key: string]: http.Agent | https.Agent } & ExtraPoolOptions | ExtraPoolOptions;
190
+
191
+ interface NameValuePair {
192
+ name: string;
193
+ value: string;
194
+ }
195
+
196
+ interface Multipart {
197
+ chunked?: boolean | undefined;
198
+ data?:
199
+ | Array<{
200
+ "content-type"?: string | undefined;
201
+ body: MultipartBody;
202
+ }>
203
+ | undefined;
204
+ }
205
+
206
+ interface RequestPart {
207
+ headers?: Headers | undefined;
208
+ body: any;
209
+ }
210
+
211
+ interface Request extends caseless.Httpified, Stream {
212
+ readable: boolean;
213
+ writable: boolean;
214
+ explicitMethod?: true | undefined;
215
+
216
+ debug(...args: any[]): void;
217
+ pipeDest(dest: any): void;
218
+ qs(q: object, clobber?: boolean): Request;
219
+ form(): FormData;
220
+ form(form: any): Request;
221
+ multipart(multipart: RequestPart[]): Request;
222
+ json(val: any): Request;
223
+ aws(opts: AWSOptions, now?: boolean): Request;
224
+ hawk(opts: HawkOptions): void;
225
+ auth(username: string, password: string, sendImmediately?: boolean, bearer?: string): Request;
226
+ oauth(oauth: OAuthOptions): Request;
227
+ jar(jar: CookieJar): Request;
228
+
229
+ on(event: string, listener: (...args: any[]) => void): this;
230
+ on(event: "request", listener: (req: http.ClientRequest) => void): this;
231
+ on(event: "response", listener: (resp: Response) => void): this;
232
+ on(event: "data", listener: (data: Buffer | string) => void): this;
233
+ on(event: "error", listener: (e: Error) => void): this;
234
+ on(event: "complete", listener: (resp: Response, body?: string | Buffer) => void): this;
235
+ on(event: "pipe", listener: (src: Readable) => void): this;
236
+ on(event: "socket", listener: (src: net.Socket) => void): this;
237
+
238
+ write(buffer: Buffer | string, cb?: (err?: Error) => void): boolean;
239
+ write(str: string, encoding?: string, cb?: (err?: Error) => void): boolean;
240
+ end(cb?: () => void): any;
241
+ end(chunk: string | Buffer, cb?: () => void): any;
242
+ end(str: string, encoding?: string, cb?: () => void): any;
243
+
244
+ pause(): void;
245
+ resume(): void;
246
+ abort(): void;
247
+ destroy(): void;
248
+ toJSON(): RequestAsJSON;
249
+
250
+ // several of the CoreOptions are copied onto the request instance
251
+ host?: string | undefined;
252
+ port?: number | undefined;
253
+ followAllRedirects?: boolean | undefined;
254
+ followOriginalHttpMethod?: boolean | undefined;
255
+ maxRedirects?: number | undefined;
256
+ removeRefererHeader?: boolean | undefined;
257
+ encoding?: string | null | undefined;
258
+ timeout?: number | undefined;
259
+ localAddress?: string | undefined;
260
+ strictSSL?: boolean | undefined;
261
+ rejectUnauthorized?: boolean | undefined;
262
+ time?: boolean | undefined;
263
+ gzip?: boolean | undefined;
264
+ preambleCRLF?: boolean | undefined;
265
+ postambleCRLF?: boolean | undefined;
266
+ withCredentials?: boolean | undefined;
267
+ key?: Buffer | undefined;
268
+ cert?: Buffer | undefined;
269
+ passphrase?: string | undefined;
270
+ ca?: string | Buffer | string[] | Buffer[] | undefined;
271
+ har?: HttpArchiveRequest | undefined;
272
+
273
+ // set in `Request.prototype.init`
274
+ headers: Headers;
275
+ method: string;
276
+ pool: PoolOptions;
277
+ dests: Readable[];
278
+ callback?: RequestCallback | undefined;
279
+ uri: Url & { href: string; pathname: string };
280
+ proxy: null | string | Url;
281
+ tunnel: boolean;
282
+ setHost: boolean;
283
+ path: string;
284
+ agent: false | http.Agent | https.Agent;
285
+ body: Buffer | Buffer[] | string | string[] | Readable;
286
+ timing?: boolean | undefined;
287
+ src?: Readable | undefined;
288
+
289
+ // set in `Request.prototype.start`
290
+ href: string;
291
+ startTime?: number | undefined;
292
+ startTimeNow?: number | undefined;
293
+ timings?: {
294
+ socket: number;
295
+ lookup: number;
296
+ connect: number;
297
+ response: number;
298
+ end: number;
299
+ } | undefined;
300
+
301
+ // set in `Request.prototype.onRequestResponse`
302
+ elapsedTime?: number | undefined;
303
+ response?: Response | undefined;
304
+ }
305
+
306
+ interface Response extends http.IncomingMessage {
307
+ statusCode: number;
308
+ statusMessage: string;
309
+ request: Request;
310
+ body: any; // Buffer, string, stream.Readable, or a plain object if `json` was truthy
311
+ caseless: caseless.Caseless; // case-insensitive access to headers
312
+ toJSON(): ResponseAsJSON;
313
+
314
+ timingStart?: number | undefined;
315
+ elapsedTime?: number | undefined;
316
+ timings?: {
317
+ socket: number;
318
+ lookup: number;
319
+ connect: number;
320
+ response: number;
321
+ end: number;
322
+ } | undefined;
323
+ timingPhases?: {
324
+ wait: number;
325
+ dns: number;
326
+ tcp: number;
327
+ firstByte: number;
328
+ download: number;
329
+ total: number;
330
+ } | undefined;
331
+ }
332
+
333
+ // aliases for backwards compatibility
334
+ type ResponseRequest = Request;
335
+ type RequestResponse = Response;
336
+
337
+ interface Headers {
338
+ [key: string]: any;
339
+ }
340
+
341
+ interface AuthOptions {
342
+ user?: string | undefined;
343
+ username?: string | undefined;
344
+ pass?: string | undefined;
345
+ password?: string | undefined;
346
+ sendImmediately?: boolean | undefined;
347
+ bearer?: string | (() => string) | undefined;
348
+ }
349
+
350
+ interface OAuthOptions {
351
+ callback?: string | undefined;
352
+ consumer_key?: string | undefined;
353
+ consumer_secret?: string | undefined;
354
+ token?: string | undefined;
355
+ token_secret?: string | undefined;
356
+ transport_method?: "body" | "header" | "query" | undefined;
357
+ verifier?: string | undefined;
358
+ body_hash?: true | string | undefined;
359
+ }
360
+
361
+ interface HawkOptions {
362
+ credentials: any;
363
+ }
364
+
365
+ interface AWSOptions {
366
+ secret: string;
367
+ bucket?: string | undefined;
368
+ }
369
+
370
+ interface RequestAsJSON {
371
+ uri: Url;
372
+ method: string;
373
+ headers: Headers;
374
+ }
375
+
376
+ interface ResponseAsJSON {
377
+ statusCode: number;
378
+ body: any;
379
+ headers: Headers;
380
+ request: RequestAsJSON;
381
+ }
382
+
383
+ type Cookie = ToughCookie.Cookie;
384
+
385
+ interface CookieJar {
386
+ setCookie(cookieOrStr: Cookie | string, uri: string | Url, options?: ToughCookie.SetCookieOptions): void;
387
+ getCookieString(uri: string | Url): string;
388
+ getCookies(uri: string | Url): Cookie[];
389
+ }
390
+ }
391
+
392
+ declare var request: request.RequestAPI<request.Request, request.CoreOptions, request.RequiredUriUrl>;
393
+ export = request;
package/lib/rp.js CHANGED
@@ -1,4 +1,4 @@
1
- var configure = require('request-promise-core/configure/request2'),
1
+ var configure = require('../deps/promise-core/configure/request2'),
2
2
  stealthyRequire = require('stealthy-require');
3
3
 
4
4
  // Load Request freshly - so that users can require an unaltered request instance!
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/request-promise-native",
3
- "version": "2.1.1",
3
+ "version": "2.3.0",
4
4
  "description": "The simplified HTTP request client 'request' with Promise support. Powered by native ES6 promises.",
5
5
  "keywords": [
6
6
  "xhr",
@@ -13,11 +13,13 @@
13
13
  "native"
14
14
  ],
15
15
  "main": "./lib/rp.js",
16
+ "types": "./lib/request.d.ts",
16
17
  "scripts": {
17
18
  "lint": "eslint .",
18
19
  "lint:fix": "eslint --fix .",
19
- "test": "mocha test/spec",
20
- "check-dependencies": "npx depcheck@1.4.7"
20
+ "test": "mocha test/spec && mocha deps/promise-core/test/spec",
21
+ "check-dependencies": "npx depcheck@1.4.7",
22
+ "check-dts": "npx check-dts lib/*.d.ts"
21
23
  },
22
24
  "repository": {
23
25
  "type": "git",
@@ -33,14 +35,19 @@
33
35
  "node": ">=18.x"
34
36
  },
35
37
  "dependencies": {
38
+ "lodash": "^4.17.19",
36
39
  "request": "npm:@cypress/request@^3.0.7",
37
- "request-promise-core": "file:deps/promise-core",
38
40
  "stealthy-require": "^1.1.1"
39
41
  },
40
42
  "devDependencies": {
43
+ "@types/caseless": "^0.12.5",
44
+ "@types/node": "^22.13.1",
45
+ "bluebird": "^3.7.2",
41
46
  "body-parser": "~1.20.3",
42
47
  "chai": "^4.5.0",
43
48
  "eslint": "^9.19.0",
44
- "mocha": "^11.1.0"
49
+ "globals": "^15.14.0",
50
+ "mocha": "^11.1.0",
51
+ "tough-cookie": "^5.1.1"
45
52
  }
46
53
  }