spitch 0.0.1-alpha.1 → 1.16.1
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.
- package/CHANGELOG.md +4 -5
- package/LICENSE +1 -1
- package/README.md +61 -27
- package/_shims/index.d.ts +2 -0
- package/_shims/index.js +5 -1
- package/_shims/index.mjs +5 -1
- package/_shims/web-runtime.js +1 -1
- package/_shims/web-runtime.js.map +1 -1
- package/_shims/web-runtime.mjs +1 -1
- package/_shims/web-runtime.mjs.map +1 -1
- package/core.d.ts +22 -9
- package/core.d.ts.map +1 -1
- package/core.js +50 -29
- package/core.js.map +1 -1
- package/core.mjs +51 -30
- package/core.mjs.map +1 -1
- package/error.d.ts +18 -24
- package/error.d.ts.map +1 -1
- package/error.js +1 -31
- package/error.js.map +1 -1
- package/error.mjs +1 -31
- package/error.mjs.map +1 -1
- package/index.d.mts +15 -18
- package/index.d.ts +15 -18
- package/index.d.ts.map +1 -1
- package/index.js +29 -11
- package/index.js.map +1 -1
- package/index.mjs +13 -10
- package/index.mjs.map +1 -1
- package/package.json +4 -4
- package/resource.d.ts +1 -1
- package/resource.d.ts.map +1 -1
- package/resource.js.map +1 -1
- package/resource.mjs.map +1 -1
- package/resources/index.d.ts +2 -2
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js.map +1 -1
- package/resources/index.mjs +2 -2
- package/resources/index.mjs.map +1 -1
- package/resources/speech.d.ts +24 -13
- package/resources/speech.d.ts.map +1 -1
- package/resources/speech.js +8 -4
- package/resources/speech.js.map +1 -1
- package/resources/speech.mjs +8 -4
- package/resources/speech.mjs.map +1 -1
- package/resources/text.d.ts +20 -6
- package/resources/text.d.ts.map +1 -1
- package/resources/text.js +6 -2
- package/resources/text.js.map +1 -1
- package/resources/text.mjs +6 -2
- package/resources/text.mjs.map +1 -1
- package/resources.d.ts +2 -0
- package/resources.d.ts.map +1 -0
- package/resources.js +18 -0
- package/resources.js.map +1 -0
- package/resources.mjs +2 -0
- package/resources.mjs.map +1 -0
- package/src/_shims/index.d.ts +2 -0
- package/src/_shims/index.js +5 -1
- package/src/_shims/index.mjs +5 -1
- package/src/_shims/web-runtime.ts +1 -1
- package/src/core.ts +81 -37
- package/src/error.ts +25 -41
- package/src/index.ts +52 -25
- package/src/resource.ts +1 -1
- package/src/resources/index.ts +13 -2
- package/src/resources/speech.ts +69 -15
- package/src/resources/text.ts +38 -7
- package/src/resources.ts +1 -0
- package/src/version.ts +1 -1
- package/version.d.ts +1 -1
- package/version.d.ts.map +1 -1
- package/version.js +1 -1
- package/version.js.map +1 -1
- package/version.mjs +1 -1
- package/version.mjs.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 1.16.1 (2025-06-17)
|
|
4
4
|
|
|
5
|
-
Full Changelog: [
|
|
5
|
+
Full Changelog: [v1.16.0...v1.16.1](https://github.com/spi-tch/node/compare/v1.16.0...v1.16.1)
|
|
6
6
|
|
|
7
7
|
### Chores
|
|
8
8
|
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* go live ([#1](https://github.com/spi-tch/spitch-node/issues/1)) ([0ef989d](https://github.com/spi-tch/spitch-node/commit/0ef989d934571aca2926db0b1c1d0c4ff11497b1))
|
|
9
|
+
* sync repo ([c537b43](https://github.com/spi-tch/node/commit/c537b434b5dc7709e3141ee647aa2fa7d36a47e1))
|
|
10
|
+
* update SDK settings ([3014122](https://github.com/spi-tch/node/commit/3014122f88736cc800e509bb0f3abc323941b699))
|
package/LICENSE
CHANGED
|
@@ -186,7 +186,7 @@
|
|
|
186
186
|
same "printed page" as the copyright notice for easier
|
|
187
187
|
identification within third-party archives.
|
|
188
188
|
|
|
189
|
-
Copyright
|
|
189
|
+
Copyright 2025 Spitch
|
|
190
190
|
|
|
191
191
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
192
|
you may not use this file except in compliance with the License.
|
package/README.md
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
This library provides convenient access to the Spitch REST API from server-side TypeScript or JavaScript.
|
|
6
6
|
|
|
7
|
-
The REST API documentation can be found on [docs.
|
|
7
|
+
The REST API documentation can be found on [docs.spitch.app](https://docs.spitch.app). The full API of this library can be found in [api.md](api.md).
|
|
8
8
|
|
|
9
|
-
It is generated with [Stainless](https://www.
|
|
9
|
+
It is generated with [Stainless](https://www.stainless.com/).
|
|
10
10
|
|
|
11
11
|
## Installation
|
|
12
12
|
|
|
@@ -26,11 +26,10 @@ const client = new Spitch({
|
|
|
26
26
|
apiKey: process.env['SPITCH_API_KEY'], // This is the default and can be omitted
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
const response = await client.speech.transcibe({ language: 'yo' });
|
|
31
|
-
}
|
|
29
|
+
const response = await client.speech.generate({ language: 'yo', text: 'text', voice: 'sade' });
|
|
32
30
|
|
|
33
|
-
|
|
31
|
+
const content = await response.blob();
|
|
32
|
+
console.log(content);
|
|
34
33
|
```
|
|
35
34
|
|
|
36
35
|
### Request & Response types
|
|
@@ -45,16 +44,42 @@ const client = new Spitch({
|
|
|
45
44
|
apiKey: process.env['SPITCH_API_KEY'], // This is the default and can be omitted
|
|
46
45
|
});
|
|
47
46
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const response: unknown = await client.speech.transcibe(params);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
main();
|
|
47
|
+
const params: Spitch.SpeechGenerateParams = { language: 'yo', text: 'text', voice: 'sade' };
|
|
48
|
+
const response: Response = await client.speech.generate(params);
|
|
54
49
|
```
|
|
55
50
|
|
|
56
51
|
Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.
|
|
57
52
|
|
|
53
|
+
## File uploads
|
|
54
|
+
|
|
55
|
+
Request parameters that correspond to file uploads can be passed in many different forms:
|
|
56
|
+
|
|
57
|
+
- `File` (or an object with the same structure)
|
|
58
|
+
- a `fetch` `Response` (or an object with the same structure)
|
|
59
|
+
- an `fs.ReadStream`
|
|
60
|
+
- the return value of our `toFile` helper
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
import fs from 'fs';
|
|
64
|
+
import fetch from 'node-fetch';
|
|
65
|
+
import Spitch, { toFile } from 'spitch';
|
|
66
|
+
|
|
67
|
+
const client = new Spitch();
|
|
68
|
+
|
|
69
|
+
// If you have access to Node `fs` we recommend using `fs.createReadStream()`:
|
|
70
|
+
await client.speech.transcribe({ language: 'yo', content: fs.createReadStream('/path/to/file') });
|
|
71
|
+
|
|
72
|
+
// Or if you have the web `File` API you can pass a `File` instance:
|
|
73
|
+
await client.speech.transcribe({ language: 'yo', content: new File(['my bytes'], 'file') });
|
|
74
|
+
|
|
75
|
+
// You can also pass a `fetch` `Response`:
|
|
76
|
+
await client.speech.transcribe({ language: 'yo', content: await fetch('https://somesite/file') });
|
|
77
|
+
|
|
78
|
+
// Finally, if none of the above are convenient, you can use our `toFile` helper:
|
|
79
|
+
await client.speech.transcribe({ language: 'yo', content: await toFile(Buffer.from('my bytes'), 'file') });
|
|
80
|
+
await client.speech.transcribe({ language: 'yo', content: await toFile(new Uint8Array([0, 1, 2]), 'file') });
|
|
81
|
+
```
|
|
82
|
+
|
|
58
83
|
## Handling errors
|
|
59
84
|
|
|
60
85
|
When the library is unable to connect to the API,
|
|
@@ -63,8 +88,9 @@ a subclass of `APIError` will be thrown:
|
|
|
63
88
|
|
|
64
89
|
<!-- prettier-ignore -->
|
|
65
90
|
```ts
|
|
66
|
-
|
|
67
|
-
|
|
91
|
+
const response = await client.speech
|
|
92
|
+
.generate({ language: 'yo', text: 'text', voice: 'sade' })
|
|
93
|
+
.catch(async (err) => {
|
|
68
94
|
if (err instanceof Spitch.APIError) {
|
|
69
95
|
console.log(err.status); // 400
|
|
70
96
|
console.log(err.name); // BadRequestError
|
|
@@ -73,12 +99,9 @@ async function main() {
|
|
|
73
99
|
throw err;
|
|
74
100
|
}
|
|
75
101
|
});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
main();
|
|
79
102
|
```
|
|
80
103
|
|
|
81
|
-
Error codes are as
|
|
104
|
+
Error codes are as follows:
|
|
82
105
|
|
|
83
106
|
| Status Code | Error Type |
|
|
84
107
|
| ----------- | -------------------------- |
|
|
@@ -107,7 +130,7 @@ const client = new Spitch({
|
|
|
107
130
|
});
|
|
108
131
|
|
|
109
132
|
// Or, configure per-request:
|
|
110
|
-
await client.speech.
|
|
133
|
+
await client.speech.generate({ language: 'yo', text: 'text', voice: 'sade' }, {
|
|
111
134
|
maxRetries: 5,
|
|
112
135
|
});
|
|
113
136
|
```
|
|
@@ -124,7 +147,7 @@ const client = new Spitch({
|
|
|
124
147
|
});
|
|
125
148
|
|
|
126
149
|
// Override per-request:
|
|
127
|
-
await client.speech.
|
|
150
|
+
await client.speech.generate({ language: 'yo', text: 'text', voice: 'sade' }, {
|
|
128
151
|
timeout: 5 * 1000,
|
|
129
152
|
});
|
|
130
153
|
```
|
|
@@ -145,11 +168,13 @@ You can also use the `.withResponse()` method to get the raw `Response` along wi
|
|
|
145
168
|
```ts
|
|
146
169
|
const client = new Spitch();
|
|
147
170
|
|
|
148
|
-
const response = await client.speech.
|
|
171
|
+
const response = await client.speech.generate({ language: 'yo', text: 'text', voice: 'sade' }).asResponse();
|
|
149
172
|
console.log(response.headers.get('X-My-Header'));
|
|
150
173
|
console.log(response.statusText); // access the underlying Response object
|
|
151
174
|
|
|
152
|
-
const { data: response, response: raw } = await client.speech
|
|
175
|
+
const { data: response, response: raw } = await client.speech
|
|
176
|
+
.generate({ language: 'yo', text: 'text', voice: 'sade' })
|
|
177
|
+
.withResponse();
|
|
153
178
|
console.log(raw.headers.get('X-My-Header'));
|
|
154
179
|
console.log(response);
|
|
155
180
|
```
|
|
@@ -214,7 +239,7 @@ import Spitch from 'spitch';
|
|
|
214
239
|
```
|
|
215
240
|
|
|
216
241
|
To do the inverse, add `import "spitch/shims/node"` (which does import polyfills).
|
|
217
|
-
This can also be useful if you are getting the wrong TypeScript types for `Response` ([more details](https://github.com/spi-tch/
|
|
242
|
+
This can also be useful if you are getting the wrong TypeScript types for `Response` ([more details](https://github.com/spi-tch/node/tree/main/src/_shims#readme)).
|
|
218
243
|
|
|
219
244
|
### Logging and middleware
|
|
220
245
|
|
|
@@ -255,8 +280,8 @@ const client = new Spitch({
|
|
|
255
280
|
});
|
|
256
281
|
|
|
257
282
|
// Override per-request:
|
|
258
|
-
await client.speech.
|
|
259
|
-
{ language: 'yo' },
|
|
283
|
+
await client.speech.generate(
|
|
284
|
+
{ language: 'yo', text: 'text', voice: 'sade' },
|
|
260
285
|
{
|
|
261
286
|
httpAgent: new http.Agent({ keepAlive: false }),
|
|
262
287
|
},
|
|
@@ -268,12 +293,12 @@ await client.speech.transcibe(
|
|
|
268
293
|
This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:
|
|
269
294
|
|
|
270
295
|
1. Changes that only affect static types, without breaking runtime behavior.
|
|
271
|
-
2. Changes to library internals which are technically public but not intended or documented for external use. _(Please open a GitHub issue to let us know if you are relying on such internals)_
|
|
296
|
+
2. Changes to library internals which are technically public but not intended or documented for external use. _(Please open a GitHub issue to let us know if you are relying on such internals.)_
|
|
272
297
|
3. Changes that we do not expect to impact the vast majority of users in practice.
|
|
273
298
|
|
|
274
299
|
We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.
|
|
275
300
|
|
|
276
|
-
We are keen for your feedback; please open an [issue](https://www.github.com/spi-tch/
|
|
301
|
+
We are keen for your feedback; please open an [issue](https://www.github.com/spi-tch/node/issues) with questions, bugs, or suggestions.
|
|
277
302
|
|
|
278
303
|
## Requirements
|
|
279
304
|
|
|
@@ -281,6 +306,15 @@ TypeScript >= 4.5 is supported.
|
|
|
281
306
|
|
|
282
307
|
The following runtimes are supported:
|
|
283
308
|
|
|
309
|
+
- Web browsers (Up-to-date Chrome, Firefox, Safari, Edge, and more)
|
|
310
|
+
- Node.js 18 LTS or later ([non-EOL](https://endoflife.date/nodejs)) versions.
|
|
311
|
+
- Deno v1.28.0 or higher.
|
|
312
|
+
- Bun 1.0 or later.
|
|
313
|
+
- Cloudflare Workers.
|
|
314
|
+
- Vercel Edge Runtime.
|
|
315
|
+
- Jest 28 or greater with the `"node"` environment (`"jsdom"` is not supported at this time).
|
|
316
|
+
- Nitro v2.6 or greater.
|
|
317
|
+
|
|
284
318
|
Note that React Native is not supported at this time.
|
|
285
319
|
|
|
286
320
|
If you are interested in other runtime environments, please open or upvote an issue on GitHub.
|
package/_shims/index.d.ts
CHANGED
|
@@ -79,3 +79,5 @@ export function fileFromPath(path: string, options?: FileFromPathOptions): Promi
|
|
|
79
79
|
export function fileFromPath(path: string, filename?: string, options?: FileFromPathOptions): Promise<File>;
|
|
80
80
|
|
|
81
81
|
export function isFsReadStream(value: any): value is FsReadStream;
|
|
82
|
+
|
|
83
|
+
export const init: () => void;
|
package/_shims/index.js
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*/
|
|
4
4
|
const shims = require('./registry');
|
|
5
5
|
const auto = require('spitch/_shims/auto/runtime');
|
|
6
|
-
|
|
6
|
+
exports.init = () => {
|
|
7
|
+
if (!shims.kind) shims.setShims(auto.getRuntime(), { auto: true });
|
|
8
|
+
};
|
|
7
9
|
for (const property of Object.keys(shims)) {
|
|
8
10
|
Object.defineProperty(exports, property, {
|
|
9
11
|
get() {
|
|
@@ -11,3 +13,5 @@ for (const property of Object.keys(shims)) {
|
|
|
11
13
|
},
|
|
12
14
|
});
|
|
13
15
|
}
|
|
16
|
+
|
|
17
|
+
exports.init();
|
package/_shims/index.mjs
CHANGED
|
@@ -3,5 +3,9 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import * as shims from './registry.mjs';
|
|
5
5
|
import * as auto from 'spitch/_shims/auto/runtime';
|
|
6
|
-
|
|
6
|
+
export const init = () => {
|
|
7
|
+
if (!shims.kind) shims.setShims(auto.getRuntime(), { auto: true });
|
|
8
|
+
};
|
|
7
9
|
export * from './registry.mjs';
|
|
10
|
+
|
|
11
|
+
init();
|
package/_shims/web-runtime.js
CHANGED
|
@@ -69,7 +69,7 @@ function getRuntime({ manuallyImported } = {}) {
|
|
|
69
69
|
}),
|
|
70
70
|
getDefaultAgent: (url) => undefined,
|
|
71
71
|
fileFromPath: () => {
|
|
72
|
-
throw new Error('The `fileFromPath` function is only supported in Node. See the README for more details: https://www.github.com/spi-tch/
|
|
72
|
+
throw new Error('The `fileFromPath` function is only supported in Node. See the README for more details: https://www.github.com/spi-tch/node#file-uploads');
|
|
73
73
|
},
|
|
74
74
|
isFsReadStream: (value) => false,
|
|
75
75
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-runtime.js","sourceRoot":"","sources":["../src/_shims/web-runtime.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,sDAAgD;AAIhD,SAAgB,UAAU,CAAC,EAAE,gBAAgB,KAAqC,EAAE;IAClF,MAAM,cAAc,GAClB,gBAAgB,CAAC,CAAC;QAChB,+BAA+B;QACjC,CAAC,CAAC;;;CAGL,CAAC;IAEA,IAAI,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,CAAC;IAC1C,IAAI;QACF,aAAa;QACb,MAAM,GAAG,KAAK,CAAC;QACf,aAAa;QACb,QAAQ,GAAG,OAAO,CAAC;QACnB,aAAa;QACb,SAAS,GAAG,QAAQ,CAAC;QACrB,aAAa;QACb,QAAQ,GAAG,OAAO,CAAC;KACpB;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,KAAK,CACb,iEACG,KAAa,CAAC,OACjB,KAAK,cAAc,EAAE,CACtB,CAAC;KACH;IAED,OAAO;QACL,IAAI,EAAE,KAAK;QACX,KAAK,EAAE,MAAM;QACb,OAAO,EAAE,QAAQ;QACjB,QAAQ,EAAE,SAAS;QACnB,OAAO,EAAE,QAAQ;QACjB,QAAQ;QACN,aAAa;QACb,OAAO,QAAQ,KAAK,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAC3C,MAAM,QAAQ;YACZ,aAAa;YACb;gBACE,MAAM,IAAI,KAAK,CACb,qFAAqF,cAAc,EAAE,CACtG,CAAC;YACJ,CAAC;SACF,CACF;QACH,IAAI,EACF,OAAO,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CACnC,MAAM,IAAI;YACR;gBACE,MAAM,IAAI,KAAK,CACb,iFAAiF,cAAc,EAAE,CAClG,CAAC;YACJ,CAAC;SACF,CACF;QACH,IAAI;QACF,aAAa;QACb,OAAO,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CACnC,MAAM,IAAI;YACR,aAAa;YACb;gBACE,MAAM,IAAI,KAAK,CACb,iFAAiF,cAAc,EAAE,CAClG,CAAC;YACJ,CAAC;SACF,CACF;QACH,cAAc;QACZ,aAAa;QACb,OAAO,cAAc,KAAK,WAAW,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,CACvD,MAAM,cAAc;YAClB,aAAa;YACb;gBACE,MAAM,IAAI,KAAK,CACb,uFAAuF,cAAc,EAAE,CACxG,CAAC;YACJ,CAAC;SACF,CACF;QACH,0BAA0B,EAAE,KAAK;QAC/B,aAAa;QACb,IAAc,EACd,IAAuB,EACK,EAAE,CAAC,CAAC;YAChC,GAAG,IAAI;YACP,IAAI,EAAE,IAAI,6BAAa,CAAC,IAAI,CAAQ;SACrC,CAAC;QACF,eAAe,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,SAAS;QAC3C,YAAY,EAAE,GAAG,EAAE;YACjB,MAAM,IAAI,KAAK,CACb,
|
|
1
|
+
{"version":3,"file":"web-runtime.js","sourceRoot":"","sources":["../src/_shims/web-runtime.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,sDAAgD;AAIhD,SAAgB,UAAU,CAAC,EAA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Z,aAAa;QACb,OAAO,cAAc,KAAK,WAAW,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,CACvD,MAAM,cAAc;YAClB,aAAa;YACb;gBACE,MAAM,IAAI,KAAK,CACb,uFAAuF,cAAc,EAAE,CACxG,CAAC;YACJ,CAAC;SACF,CACF;QACH,0BAA0B,EAAE,KAAK;QAC/B,aAAa;QACb,IAAc,EACd,IAAuB,EACK,EAAE,CAAC,CAAC;YAChC,GAAG,IAAI;YACP,IAAI,EAAE,IAAI,6BAAa,CAAC,IAAI,CAAQ;SACrC,CAAC;QACF,eAAe,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,SAAS;QAC3C,YAAY,EAAE,GAAG,EAAE;YACjB,MAAM,IAAI,KAAK,CACb,0IAA0I,CAC3I,CAAC;QACJ,CAAC;QACD,cAAc,EAAE,CAAC,KAAU,EAAE,EAAE,CAAC,KAAK;KACtC,CAAC;AACJ,CAAC;AA/FD,gCA+FC"}
|
package/_shims/web-runtime.mjs
CHANGED
|
@@ -63,7 +63,7 @@ export function getRuntime({ manuallyImported } = {}) {
|
|
|
63
63
|
}),
|
|
64
64
|
getDefaultAgent: (url) => undefined,
|
|
65
65
|
fileFromPath: () => {
|
|
66
|
-
throw new Error('The `fileFromPath` function is only supported in Node. See the README for more details: https://www.github.com/spi-tch/
|
|
66
|
+
throw new Error('The `fileFromPath` function is only supported in Node. See the README for more details: https://www.github.com/spi-tch/node#file-uploads');
|
|
67
67
|
},
|
|
68
68
|
isFsReadStream: (value) => false,
|
|
69
69
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-runtime.mjs","sourceRoot":"","sources":["../src/_shims/web-runtime.ts"],"names":[],"mappings":"OAGO,EAAE,aAAa,EAAE;AAIxB,MAAM,UAAU,UAAU,CAAC,EAAE,gBAAgB,KAAqC,EAAE;IAClF,MAAM,cAAc,GAClB,gBAAgB,CAAC,CAAC;QAChB,+BAA+B;QACjC,CAAC,CAAC;;;C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AQ;YACZ,aAAa;YACb;gBACE,MAAM,IAAI,KAAK,CACb,qFAAqF,cAAc,EAAE,CACtG,CAAC;YACJ,CAAC;SACF,CACF;QACH,IAAI,EACF,OAAO,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CACnC,MAAM,IAAI;YACR;gBACE,MAAM,IAAI,KAAK,CACb,iFAAiF,cAAc,EAAE,CAClG,CAAC;YACJ,CAAC;SACF,CACF;QACH,IAAI;QACF,aAAa;QACb,OAAO,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CACnC,MAAM,IAAI;YACR,aAAa;YACb;gBACE,MAAM,IAAI,KAAK,CACb,iFAAiF,cAAc,EAAE,CAClG,CAAC;YACJ,CAAC;SACF,CACF;QACH,cAAc;QACZ,aAAa;QACb,OAAO,cAAc,KAAK,WAAW,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,CACvD,MAAM,cAAc;YAClB,aAAa;YACb;gBACE,MAAM,IAAI,KAAK,CACb,uFAAuF,cAAc,EAAE,CACxG,CAAC;YACJ,CAAC;SACF,CACF;QACH,0BAA0B,EAAE,KAAK;QAC/B,aAAa;QACb,IAAc,EACd,IAAuB,EACK,EAAE,CAAC,CAAC;YAChC,GAAG,IAAI;YACP,IAAI,EAAE,IAAI,aAAa,CAAC,IAAI,CAAQ;SACrC,CAAC;QACF,eAAe,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,SAAS;QAC3C,YAAY,EAAE,GAAG,EAAE;YACjB,MAAM,IAAI,KAAK,CACb,0IAA0I,CAC3I,CAAC;QACJ,CAAC;QACD,cAAc,EAAE,CAAC,KAAU,EAAE,EAAE,CAAC,KAAK;KACtC,CAAC;AACJ,CAAC"}
|
package/core.d.ts
CHANGED
|
@@ -6,6 +6,17 @@ export { type Response };
|
|
|
6
6
|
import { BlobLike } from "./uploads.js";
|
|
7
7
|
export { maybeMultipartFormRequestOptions, multipartFormRequestOptions, createForm, type Uploadable, } from "./uploads.js";
|
|
8
8
|
export type Fetch = (url: RequestInfo, init?: RequestInit) => Promise<Response>;
|
|
9
|
+
/**
|
|
10
|
+
* An alias to the builtin `Array` type so we can
|
|
11
|
+
* easily alias it in import statements if there are name clashes.
|
|
12
|
+
*/
|
|
13
|
+
type _Array<T> = Array<T>;
|
|
14
|
+
/**
|
|
15
|
+
* An alias to the builtin `Record` type so we can
|
|
16
|
+
* easily alias it in import statements if there are name clashes.
|
|
17
|
+
*/
|
|
18
|
+
type _Record<K extends keyof any, T> = Record<K, T>;
|
|
19
|
+
export type { _Array as Array, _Record as Record };
|
|
9
20
|
type PromiseOrValue<T> = T | Promise<T>;
|
|
10
21
|
type APIResponseProps = {
|
|
11
22
|
response: Response;
|
|
@@ -21,7 +32,7 @@ export declare class APIPromise<T> extends Promise<T> {
|
|
|
21
32
|
private parseResponse;
|
|
22
33
|
private parsedPromise;
|
|
23
34
|
constructor(responsePromise: Promise<APIResponseProps>, parseResponse?: (props: APIResponseProps) => PromiseOrValue<T>);
|
|
24
|
-
_thenUnwrap<U>(transform: (data: T) => U): APIPromise<U>;
|
|
35
|
+
_thenUnwrap<U>(transform: (data: T, props: APIResponseProps) => U): APIPromise<U>;
|
|
25
36
|
/**
|
|
26
37
|
* Gets the raw `Response` instance instead of parsing the response
|
|
27
38
|
* data.
|
|
@@ -59,15 +70,17 @@ export declare class APIPromise<T> extends Promise<T> {
|
|
|
59
70
|
finally(onfinally?: (() => void) | undefined | null): Promise<T>;
|
|
60
71
|
}
|
|
61
72
|
export declare abstract class APIClient {
|
|
73
|
+
#private;
|
|
62
74
|
baseURL: string;
|
|
63
75
|
maxRetries: number;
|
|
64
76
|
timeout: number;
|
|
65
77
|
httpAgent: Agent | undefined;
|
|
66
78
|
private fetch;
|
|
67
79
|
protected idempotencyHeader?: string;
|
|
68
|
-
constructor({ baseURL, maxRetries, timeout, // 1 minute
|
|
69
|
-
httpAgent, fetch:
|
|
80
|
+
constructor({ baseURL, baseURLOverridden, maxRetries, timeout, // 1 minute
|
|
81
|
+
httpAgent, fetch: overriddenFetch, }: {
|
|
70
82
|
baseURL: string;
|
|
83
|
+
baseURLOverridden: boolean;
|
|
71
84
|
maxRetries?: number | undefined;
|
|
72
85
|
timeout: number | undefined;
|
|
73
86
|
httpAgent: Agent | undefined;
|
|
@@ -97,7 +110,7 @@ export declare abstract class APIClient {
|
|
|
97
110
|
private methodRequest;
|
|
98
111
|
getAPIList<Item, PageClass extends AbstractPage<Item> = AbstractPage<Item>>(path: string, Page: new (...args: any[]) => PageClass, opts?: RequestOptions<any>): PagePromise<PageClass, Item>;
|
|
99
112
|
private calculateContentLength;
|
|
100
|
-
buildRequest<Req>(
|
|
113
|
+
buildRequest<Req>(inputOptions: FinalRequestOptions<Req>, { retryCount }?: {
|
|
101
114
|
retryCount?: number;
|
|
102
115
|
}): {
|
|
103
116
|
req: RequestInit;
|
|
@@ -124,10 +137,9 @@ export declare abstract class APIClient {
|
|
|
124
137
|
request<Req, Rsp>(options: PromiseOrValue<FinalRequestOptions<Req>>, remainingRetries?: number | null): APIPromise<Rsp>;
|
|
125
138
|
private makeRequest;
|
|
126
139
|
requestAPIList<Item = unknown, PageClass extends AbstractPage<Item> = AbstractPage<Item>>(Page: new (...args: ConstructorParameters<typeof AbstractPage>) => PageClass, options: FinalRequestOptions): PagePromise<PageClass, Item>;
|
|
127
|
-
buildURL<Req>(path: string, query: Req | null | undefined): string;
|
|
140
|
+
buildURL<Req>(path: string, query: Req | null | undefined, defaultBaseURL?: string | undefined): string;
|
|
128
141
|
protected stringifyQuery(query: Record<string, unknown>): string;
|
|
129
142
|
fetchWithTimeout(url: RequestInfo, init: RequestInit | undefined, ms: number, controller: AbortController): Promise<Response>;
|
|
130
|
-
protected getRequestClient(): RequestClient;
|
|
131
143
|
private shouldRetry;
|
|
132
144
|
private retryRequest;
|
|
133
145
|
private calculateDefaultRetryTimeoutMillis;
|
|
@@ -152,8 +164,8 @@ export declare abstract class AbstractPage<Item> implements AsyncIterable<Item>
|
|
|
152
164
|
abstract getPaginatedItems(): Item[];
|
|
153
165
|
hasNextPage(): boolean;
|
|
154
166
|
getNextPage(): Promise<this>;
|
|
155
|
-
iterPages(): AsyncGenerator<
|
|
156
|
-
[Symbol.asyncIterator](): AsyncGenerator<
|
|
167
|
+
iterPages(): AsyncGenerator<this>;
|
|
168
|
+
[Symbol.asyncIterator](): AsyncGenerator<Item>;
|
|
157
169
|
}
|
|
158
170
|
/**
|
|
159
171
|
* This subclass of Promise will resolve to an instantiated Page once the request completes.
|
|
@@ -173,7 +185,7 @@ export declare class PagePromise<PageClass extends AbstractPage<Item>, Item = Re
|
|
|
173
185
|
* console.log(item)
|
|
174
186
|
* }
|
|
175
187
|
*/
|
|
176
|
-
[Symbol.asyncIterator](): AsyncGenerator<
|
|
188
|
+
[Symbol.asyncIterator](): AsyncGenerator<Item>;
|
|
177
189
|
}
|
|
178
190
|
export declare const createResponseHeaders: (headers: Awaited<ReturnType<Fetch>>['headers']) => Record<string, string>;
|
|
179
191
|
type HTTPMethod = 'get' | 'post' | 'put' | 'patch' | 'delete';
|
|
@@ -191,6 +203,7 @@ export type RequestOptions<Req = unknown | Record<string, unknown> | Readable |
|
|
|
191
203
|
query?: Req | undefined;
|
|
192
204
|
body?: Req | null | undefined;
|
|
193
205
|
headers?: Headers | undefined;
|
|
206
|
+
defaultBaseURL?: string | undefined;
|
|
194
207
|
maxRetries?: number;
|
|
195
208
|
stream?: boolean | undefined;
|
|
196
209
|
timeout?: number;
|
package/core.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["src/core.ts"],"names":[],"mappings":";;AACA,OAAO,EAEL,QAAQ,EAIT,MAAM,SAAS,CAAC;AACjB,OAAO,EAEL,KAAK,QAAQ,EAEb,KAAK,KAAK,EAEV,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,WAAW,
|
|
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eAAO,MAAM,kBAAkB,UAAW,OAAO,KAAG,OAAO,GAAG,SAK7D,CAAC;AAGF,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAIlE;AAGD,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAExD;AAwBD,wBAAgB,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,QAInD;AAaD,eAAO,MAAM,kBAAkB,eAS9B,CAAC;AAEF,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;CACpD;AACD,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,GAAG,eAAe,CAAC;AAE1F,eAAO,MAAM,iBAAiB,YAAa,GAAG,+BAE7C,CAAC;AAEF,eAAO,MAAM,iBAAiB,YAAa,WAAW,GAAG,OAAO,UAAU,MAAM,KAAG,MAMlF,CAAC;AAEF,eAAO,MAAM,SAAS,YAAa,WAAW,GAAG,OAAO,UAAU,MAAM,KAAG,MAAM,GAAG,SA2BnF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,QAAQ,QAAS,MAAM,GAAG,IAAI,GAAG,SAAS,KAAG,MAWzD,CAAC;AAEF,wBAAgB,KAAK,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAElE"}
|
package/core.js
CHANGED
|
@@ -10,12 +10,14 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var _AbstractPage_client;
|
|
13
|
+
var _APIClient_baseURLOverridden, _AbstractPage_client;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.isObj = exports.toBase64 = exports.getHeader = exports.getRequiredHeader = exports.isHeadersProtocol = exports.isRunningInBrowser = exports.debug = exports.hasOwn = exports.isEmptyObj = exports.maybeCoerceBoolean = exports.maybeCoerceFloat = exports.maybeCoerceInteger = exports.coerceBoolean = exports.coerceFloat = exports.coerceInteger = exports.readEnv = exports.ensurePresent = exports.castToError = exports.sleep = exports.safeJSON = exports.isRequestOptions = exports.createResponseHeaders = exports.PagePromise = exports.AbstractPage = exports.APIClient = exports.APIPromise = exports.createForm = exports.multipartFormRequestOptions = exports.maybeMultipartFormRequestOptions = void 0;
|
|
16
16
|
const version_1 = require("./version.js");
|
|
17
17
|
const error_1 = require("./error.js");
|
|
18
18
|
const index_1 = require("./_shims/index.js");
|
|
19
|
+
// try running side effects outside of _shims/index to workaround https://github.com/vercel/next.js/issues/76881
|
|
20
|
+
(0, index_1.init)();
|
|
19
21
|
const uploads_1 = require("./uploads.js");
|
|
20
22
|
var uploads_2 = require("./uploads.js");
|
|
21
23
|
Object.defineProperty(exports, "maybeMultipartFormRequestOptions", { enumerable: true, get: function () { return uploads_2.maybeMultipartFormRequestOptions; } });
|
|
@@ -31,7 +33,8 @@ async function defaultParseResponse(props) {
|
|
|
31
33
|
return response;
|
|
32
34
|
}
|
|
33
35
|
const contentType = response.headers.get('content-type');
|
|
34
|
-
const
|
|
36
|
+
const mediaType = contentType?.split(';')[0]?.trim();
|
|
37
|
+
const isJSON = mediaType?.includes('application/json') || mediaType?.endsWith('+json');
|
|
35
38
|
if (isJSON) {
|
|
36
39
|
const json = await response.json();
|
|
37
40
|
debug('response', response.status, response.url, response.headers, json);
|
|
@@ -58,7 +61,7 @@ class APIPromise extends Promise {
|
|
|
58
61
|
this.parseResponse = parseResponse;
|
|
59
62
|
}
|
|
60
63
|
_thenUnwrap(transform) {
|
|
61
|
-
return new APIPromise(this.responsePromise, async (props) => transform(await this.parseResponse(props)));
|
|
64
|
+
return new APIPromise(this.responsePromise, async (props) => transform(await this.parseResponse(props), props));
|
|
62
65
|
}
|
|
63
66
|
/**
|
|
64
67
|
* Gets the raw `Response` instance instead of parsing the response
|
|
@@ -111,13 +114,15 @@ class APIPromise extends Promise {
|
|
|
111
114
|
}
|
|
112
115
|
exports.APIPromise = APIPromise;
|
|
113
116
|
class APIClient {
|
|
114
|
-
constructor({ baseURL, maxRetries = 2, timeout = 60000, // 1 minute
|
|
115
|
-
httpAgent, fetch:
|
|
117
|
+
constructor({ baseURL, baseURLOverridden, maxRetries = 2, timeout = 60000, // 1 minute
|
|
118
|
+
httpAgent, fetch: overriddenFetch, }) {
|
|
119
|
+
_APIClient_baseURLOverridden.set(this, void 0);
|
|
116
120
|
this.baseURL = baseURL;
|
|
121
|
+
__classPrivateFieldSet(this, _APIClient_baseURLOverridden, baseURLOverridden, "f");
|
|
117
122
|
this.maxRetries = validatePositiveInteger('maxRetries', maxRetries);
|
|
118
123
|
this.timeout = validatePositiveInteger('timeout', timeout);
|
|
119
124
|
this.httpAgent = httpAgent;
|
|
120
|
-
this.fetch =
|
|
125
|
+
this.fetch = overriddenFetch ?? index_1.fetch;
|
|
121
126
|
}
|
|
122
127
|
authHeaders(opts) {
|
|
123
128
|
return {};
|
|
@@ -190,20 +195,21 @@ class APIClient {
|
|
|
190
195
|
}
|
|
191
196
|
return null;
|
|
192
197
|
}
|
|
193
|
-
buildRequest(
|
|
194
|
-
const
|
|
198
|
+
buildRequest(inputOptions, { retryCount = 0 } = {}) {
|
|
199
|
+
const options = { ...inputOptions };
|
|
200
|
+
const { method, path, query, defaultBaseURL, headers: headers = {} } = options;
|
|
195
201
|
const body = ArrayBuffer.isView(options.body) || (options.__binaryRequest && typeof options.body === 'string') ?
|
|
196
202
|
options.body
|
|
197
203
|
: (0, uploads_1.isMultipartBody)(options.body) ? options.body.body
|
|
198
204
|
: options.body ? JSON.stringify(options.body, null, 2)
|
|
199
205
|
: null;
|
|
200
206
|
const contentLength = this.calculateContentLength(body);
|
|
201
|
-
const url = this.buildURL(path, query);
|
|
207
|
+
const url = this.buildURL(path, query, defaultBaseURL);
|
|
202
208
|
if ('timeout' in options)
|
|
203
209
|
validatePositiveInteger('timeout', options.timeout);
|
|
204
|
-
|
|
210
|
+
options.timeout = options.timeout ?? this.timeout;
|
|
205
211
|
const httpAgent = options.httpAgent ?? this.httpAgent ?? (0, index_1.getDefaultAgent)(url);
|
|
206
|
-
const minAgentTimeout = timeout + 1000;
|
|
212
|
+
const minAgentTimeout = options.timeout + 1000;
|
|
207
213
|
if (typeof httpAgent?.options?.timeout === 'number' &&
|
|
208
214
|
minAgentTimeout > (httpAgent.options.timeout ?? 0)) {
|
|
209
215
|
// Allow any given request to bump our agent active socket timeout.
|
|
@@ -213,9 +219,9 @@ class APIClient {
|
|
|
213
219
|
httpAgent.options.timeout = minAgentTimeout;
|
|
214
220
|
}
|
|
215
221
|
if (this.idempotencyHeader && method !== 'get') {
|
|
216
|
-
if (!
|
|
217
|
-
|
|
218
|
-
headers[this.idempotencyHeader] =
|
|
222
|
+
if (!inputOptions.idempotencyKey)
|
|
223
|
+
inputOptions.idempotencyKey = this.defaultIdempotencyKey();
|
|
224
|
+
headers[this.idempotencyHeader] = inputOptions.idempotencyKey;
|
|
219
225
|
}
|
|
220
226
|
const reqHeaders = this.buildHeaders({ options, headers, contentLength, retryCount });
|
|
221
227
|
const req = {
|
|
@@ -227,7 +233,7 @@ class APIClient {
|
|
|
227
233
|
// not compatible with standard web types
|
|
228
234
|
signal: options.signal ?? null,
|
|
229
235
|
};
|
|
230
|
-
return { req, url, timeout };
|
|
236
|
+
return { req, url, timeout: options.timeout };
|
|
231
237
|
}
|
|
232
238
|
buildHeaders({ options, headers, contentLength, retryCount, }) {
|
|
233
239
|
const reqHeaders = {};
|
|
@@ -241,11 +247,18 @@ class APIClient {
|
|
|
241
247
|
if ((0, uploads_1.isMultipartBody)(options.body) && index_1.kind !== 'node') {
|
|
242
248
|
delete reqHeaders['content-type'];
|
|
243
249
|
}
|
|
244
|
-
// Don't set
|
|
245
|
-
// which can contain nulls, instead of `reqHeaders` to account
|
|
246
|
-
|
|
250
|
+
// Don't set theses headers if they were already set or removed through default headers or by the caller.
|
|
251
|
+
// We check `defaultHeaders` and `headers`, which can contain nulls, instead of `reqHeaders` to account
|
|
252
|
+
// for the removal case.
|
|
253
|
+
if ((0, exports.getHeader)(defaultHeaders, 'x-stainless-retry-count') === undefined &&
|
|
254
|
+
(0, exports.getHeader)(headers, 'x-stainless-retry-count') === undefined) {
|
|
247
255
|
reqHeaders['x-stainless-retry-count'] = String(retryCount);
|
|
248
256
|
}
|
|
257
|
+
if ((0, exports.getHeader)(defaultHeaders, 'x-stainless-timeout') === undefined &&
|
|
258
|
+
(0, exports.getHeader)(headers, 'x-stainless-timeout') === undefined &&
|
|
259
|
+
options.timeout) {
|
|
260
|
+
reqHeaders['x-stainless-timeout'] = String(Math.trunc(options.timeout / 1000));
|
|
261
|
+
}
|
|
249
262
|
this.validateHeaders(reqHeaders, headers);
|
|
250
263
|
return reqHeaders;
|
|
251
264
|
}
|
|
@@ -320,10 +333,11 @@ class APIClient {
|
|
|
320
333
|
const request = this.makeRequest(options, null);
|
|
321
334
|
return new PagePromise(this, request, Page);
|
|
322
335
|
}
|
|
323
|
-
buildURL(path, query) {
|
|
336
|
+
buildURL(path, query, defaultBaseURL) {
|
|
337
|
+
const baseURL = (!__classPrivateFieldGet(this, _APIClient_baseURLOverridden, "f") && defaultBaseURL) || this.baseURL;
|
|
324
338
|
const url = isAbsoluteURL(path) ?
|
|
325
339
|
new URL(path)
|
|
326
|
-
: new URL(
|
|
340
|
+
: new URL(baseURL + (baseURL.endsWith('/') && path.startsWith('/') ? path.slice(1) : path));
|
|
327
341
|
const defaultQuery = this.defaultQuery();
|
|
328
342
|
if (!isEmptyObj(defaultQuery)) {
|
|
329
343
|
query = { ...defaultQuery, ...query };
|
|
@@ -352,16 +366,21 @@ class APIClient {
|
|
|
352
366
|
if (signal)
|
|
353
367
|
signal.addEventListener('abort', () => controller.abort());
|
|
354
368
|
const timeout = setTimeout(() => controller.abort(), ms);
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
369
|
+
const fetchOptions = {
|
|
370
|
+
signal: controller.signal,
|
|
371
|
+
...options,
|
|
372
|
+
};
|
|
373
|
+
if (fetchOptions.method) {
|
|
374
|
+
// Custom methods like 'patch' need to be uppercased
|
|
375
|
+
// See https://github.com/nodejs/undici/issues/2294
|
|
376
|
+
fetchOptions.method = fetchOptions.method.toUpperCase();
|
|
377
|
+
}
|
|
378
|
+
return (
|
|
379
|
+
// use undefined this binding; fetch errors if bound to something else in browser/cloudflare
|
|
380
|
+
this.fetch.call(undefined, url, fetchOptions).finally(() => {
|
|
359
381
|
clearTimeout(timeout);
|
|
360
382
|
}));
|
|
361
383
|
}
|
|
362
|
-
getRequestClient() {
|
|
363
|
-
return { fetch: this.fetch };
|
|
364
|
-
}
|
|
365
384
|
shouldRetry(response) {
|
|
366
385
|
// Note this is not a standard header.
|
|
367
386
|
const shouldRetryHeader = response.headers.get('x-should-retry');
|
|
@@ -429,6 +448,7 @@ class APIClient {
|
|
|
429
448
|
}
|
|
430
449
|
}
|
|
431
450
|
exports.APIClient = APIClient;
|
|
451
|
+
_APIClient_baseURLOverridden = new WeakMap();
|
|
432
452
|
class AbstractPage {
|
|
433
453
|
constructor(client, response, body, options) {
|
|
434
454
|
_AbstractPage_client.set(this, void 0);
|
|
@@ -528,6 +548,7 @@ const requestOptionsKeys = {
|
|
|
528
548
|
query: true,
|
|
529
549
|
body: true,
|
|
530
550
|
headers: true,
|
|
551
|
+
defaultBaseURL: true,
|
|
531
552
|
maxRetries: true,
|
|
532
553
|
stream: true,
|
|
533
554
|
timeout: true,
|
|
@@ -682,8 +703,8 @@ const safeJSON = (text) => {
|
|
|
682
703
|
}
|
|
683
704
|
};
|
|
684
705
|
exports.safeJSON = safeJSON;
|
|
685
|
-
// https://
|
|
686
|
-
const startsWithSchemeRegexp =
|
|
706
|
+
// https://url.spec.whatwg.org/#url-scheme-string
|
|
707
|
+
const startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i;
|
|
687
708
|
const isAbsoluteURL = (url) => {
|
|
688
709
|
return startsWithSchemeRegexp.test(url);
|
|
689
710
|
};
|