fetch-har 8.1.2 → 8.1.4
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 +60 -0
- package/dist/index.d.ts +2 -3
- package/dist/index.js +44 -31
- package/package.json +11 -11
- package/src/index.ts +65 -49
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,63 @@
|
|
|
1
|
+
## <small>8.1.4 (2023-01-03)</small>
|
|
2
|
+
|
|
3
|
+
* chore(deps-dev): bump @readme/eslint-config from 10.1.0 to 10.1.1 (#331) ([75de615](https://github.com/readmeio/fetch-har/commit/75de615)), closes [#331](https://github.com/readmeio/fetch-har/issues/331)
|
|
4
|
+
* chore(deps-dev): bump @readme/eslint-config from 10.1.1 to 10.2.0 (#345) ([b791ce3](https://github.com/readmeio/fetch-har/commit/b791ce3)), closes [#345](https://github.com/readmeio/fetch-har/issues/345)
|
|
5
|
+
* chore(deps-dev): bump @readme/eslint-config from 9.0.0 to 10.1.0 (#312) ([27b53b8](https://github.com/readmeio/fetch-har/commit/27b53b8)), closes [#312](https://github.com/readmeio/fetch-har/issues/312)
|
|
6
|
+
* chore(deps-dev): bump @types/chai from 4.3.1 to 4.3.3 (#313) ([cfc65d0](https://github.com/readmeio/fetch-har/commit/cfc65d0)), closes [#313](https://github.com/readmeio/fetch-har/issues/313)
|
|
7
|
+
* chore(deps-dev): bump @types/express from 4.17.13 to 4.17.14 (#323) ([1fec46d](https://github.com/readmeio/fetch-har/commit/1fec46d)), closes [#323](https://github.com/readmeio/fetch-har/issues/323)
|
|
8
|
+
* chore(deps-dev): bump @types/mocha from 10.0.0 to 10.0.1 (#344) ([75d4db7](https://github.com/readmeio/fetch-har/commit/75d4db7)), closes [#344](https://github.com/readmeio/fetch-har/issues/344)
|
|
9
|
+
* chore(deps-dev): bump @types/mocha from 9.1.1 to 10.0.0 (#326) ([36c4b00](https://github.com/readmeio/fetch-har/commit/36c4b00)), closes [#326](https://github.com/readmeio/fetch-har/issues/326)
|
|
10
|
+
* chore(deps-dev): bump @types/node from 18.11.8 to 18.11.10 (#349) ([6479fbf](https://github.com/readmeio/fetch-har/commit/6479fbf)), closes [#349](https://github.com/readmeio/fetch-har/issues/349)
|
|
11
|
+
* chore(deps-dev): bump @types/node from 18.6.1 to 18.6.3 (#309) ([4cce975](https://github.com/readmeio/fetch-har/commit/4cce975)), closes [#309](https://github.com/readmeio/fetch-har/issues/309)
|
|
12
|
+
* chore(deps-dev): bump @types/node from 18.6.3 to 18.7.14 (#315) ([69679ac](https://github.com/readmeio/fetch-har/commit/69679ac)), closes [#315](https://github.com/readmeio/fetch-har/issues/315)
|
|
13
|
+
* chore(deps-dev): bump @types/node from 18.7.14 to 18.7.23 (#324) ([8c0c037](https://github.com/readmeio/fetch-har/commit/8c0c037)), closes [#324](https://github.com/readmeio/fetch-har/issues/324)
|
|
14
|
+
* chore(deps-dev): bump @types/node from 18.7.23 to 18.8.0 (#330) ([0174e1d](https://github.com/readmeio/fetch-har/commit/0174e1d)), closes [#330](https://github.com/readmeio/fetch-har/issues/330)
|
|
15
|
+
* chore(deps-dev): bump @types/node from 18.8.0 to 18.11.8 (#335) ([5a602b3](https://github.com/readmeio/fetch-har/commit/5a602b3)), closes [#335](https://github.com/readmeio/fetch-har/issues/335)
|
|
16
|
+
* chore(deps-dev): bump chai from 4.3.6 to 4.3.7 (#348) ([b427f19](https://github.com/readmeio/fetch-har/commit/b427f19)), closes [#348](https://github.com/readmeio/fetch-har/issues/348)
|
|
17
|
+
* chore(deps-dev): bump eslint from 8.20.0 to 8.23.0 (#318) ([5d6293b](https://github.com/readmeio/fetch-har/commit/5d6293b)), closes [#318](https://github.com/readmeio/fetch-har/issues/318)
|
|
18
|
+
* chore(deps-dev): bump eslint from 8.23.0 to 8.24.0 (#325) ([033eeec](https://github.com/readmeio/fetch-har/commit/033eeec)), closes [#325](https://github.com/readmeio/fetch-har/issues/325)
|
|
19
|
+
* chore(deps-dev): bump eslint from 8.24.0 to 8.26.0 (#339) ([8806ab8](https://github.com/readmeio/fetch-har/commit/8806ab8)), closes [#339](https://github.com/readmeio/fetch-har/issues/339)
|
|
20
|
+
* chore(deps-dev): bump eslint from 8.26.0 to 8.28.0 (#350) ([3440e1c](https://github.com/readmeio/fetch-har/commit/3440e1c)), closes [#350](https://github.com/readmeio/fetch-har/issues/350)
|
|
21
|
+
* chore(deps-dev): bump express from 4.18.1 to 4.18.2 (#338) ([acdc8ac](https://github.com/readmeio/fetch-har/commit/acdc8ac)), closes [#338](https://github.com/readmeio/fetch-har/issues/338)
|
|
22
|
+
* chore(deps-dev): bump mocha from 10.0.0 to 10.1.0 (#336) ([9e91790](https://github.com/readmeio/fetch-har/commit/9e91790)), closes [#336](https://github.com/readmeio/fetch-har/issues/336)
|
|
23
|
+
* chore(deps-dev): bump prettier from 2.7.1 to 2.8.0 (#347) ([22ce3c9](https://github.com/readmeio/fetch-har/commit/22ce3c9)), closes [#347](https://github.com/readmeio/fetch-har/issues/347)
|
|
24
|
+
* chore(deps-dev): bump typescript from 4.7.4 to 4.8.2 (#316) ([a5819c1](https://github.com/readmeio/fetch-har/commit/a5819c1)), closes [#316](https://github.com/readmeio/fetch-har/issues/316)
|
|
25
|
+
* chore(deps-dev): bump typescript from 4.8.2 to 4.8.4 (#327) ([2e1fdf1](https://github.com/readmeio/fetch-har/commit/2e1fdf1)), closes [#327](https://github.com/readmeio/fetch-har/issues/327)
|
|
26
|
+
* chore(deps-dev): bump typescript from 4.8.4 to 4.9.3 (#346) ([afa6122](https://github.com/readmeio/fetch-har/commit/afa6122)), closes [#346](https://github.com/readmeio/fetch-har/issues/346)
|
|
27
|
+
* chore(deps-dev): bump undici from 5.10.0 to 5.11.0 (#332) ([a020b27](https://github.com/readmeio/fetch-har/commit/a020b27)), closes [#332](https://github.com/readmeio/fetch-har/issues/332)
|
|
28
|
+
* chore(deps-dev): bump undici from 5.11.0 to 5.12.0 (#337) ([e4e3daf](https://github.com/readmeio/fetch-har/commit/e4e3daf)), closes [#337](https://github.com/readmeio/fetch-har/issues/337)
|
|
29
|
+
* chore(deps-dev): bump undici from 5.12.0 to 5.13.0 (#351) ([2f1da07](https://github.com/readmeio/fetch-har/commit/2f1da07)), closes [#351](https://github.com/readmeio/fetch-har/issues/351)
|
|
30
|
+
* chore(deps-dev): bump undici from 5.8.0 to 5.8.2 (#310) ([09a5241](https://github.com/readmeio/fetch-har/commit/09a5241)), closes [#310](https://github.com/readmeio/fetch-har/issues/310)
|
|
31
|
+
* chore(deps-dev): bump undici from 5.8.2 to 5.10.0 (#314) ([ad16183](https://github.com/readmeio/fetch-har/commit/ad16183)), closes [#314](https://github.com/readmeio/fetch-har/issues/314)
|
|
32
|
+
* chore(deps): bump @types/har-format from 1.2.8 to 1.2.9 (#322) ([4746a42](https://github.com/readmeio/fetch-har/commit/4746a42)), closes [#322](https://github.com/readmeio/fetch-har/issues/322)
|
|
33
|
+
* chore(deps): bump @types/har-format from 1.2.9 to 1.2.10 (#352) ([df4506a](https://github.com/readmeio/fetch-har/commit/df4506a)), closes [#352](https://github.com/readmeio/fetch-har/issues/352)
|
|
34
|
+
* chore(deps): bump actions/cache from 3.0.10 to 3.0.11 (#334) ([b4b9a7c](https://github.com/readmeio/fetch-har/commit/b4b9a7c)), closes [#334](https://github.com/readmeio/fetch-har/issues/334)
|
|
35
|
+
* chore(deps): bump actions/cache from 3.0.5 to 3.0.8 (#311) ([011f9d4](https://github.com/readmeio/fetch-har/commit/011f9d4)), closes [#311](https://github.com/readmeio/fetch-har/issues/311)
|
|
36
|
+
* chore(deps): bump actions/cache from 3.0.8 to 3.0.9 (#320) ([441c2a6](https://github.com/readmeio/fetch-har/commit/441c2a6)), closes [#320](https://github.com/readmeio/fetch-har/issues/320)
|
|
37
|
+
* chore(deps): bump actions/cache from 3.0.9 to 3.0.10 (#329) ([0d9bc07](https://github.com/readmeio/fetch-har/commit/0d9bc07)), closes [#329](https://github.com/readmeio/fetch-har/issues/329)
|
|
38
|
+
* chore(deps): bump decode-uri-component from 0.2.0 to 0.2.2 (#353) ([b987538](https://github.com/readmeio/fetch-har/commit/b987538)), closes [#353](https://github.com/readmeio/fetch-har/issues/353)
|
|
39
|
+
* chore(deps): bump engine.io and socket.io (#343) ([5e0451a](https://github.com/readmeio/fetch-har/commit/5e0451a)), closes [#343](https://github.com/readmeio/fetch-har/issues/343)
|
|
40
|
+
* chore(deps): bump formdata-node from 4.3.3 to 4.4.1 (#319) ([31ab620](https://github.com/readmeio/fetch-har/commit/31ab620)), closes [#319](https://github.com/readmeio/fetch-har/issues/319)
|
|
41
|
+
* chore(deps): bump loader-utils from 1.4.0 to 1.4.1 (#340) ([e90b650](https://github.com/readmeio/fetch-har/commit/e90b650)), closes [#340](https://github.com/readmeio/fetch-har/issues/340)
|
|
42
|
+
* chore(deps): bump loader-utils from 1.4.1 to 1.4.2 (#342) ([ca2e6d2](https://github.com/readmeio/fetch-har/commit/ca2e6d2)), closes [#342](https://github.com/readmeio/fetch-har/issues/342)
|
|
43
|
+
* chore(deps): bump socket.io-parser from 4.0.4 to 4.0.5 (#341) ([97cbd5b](https://github.com/readmeio/fetch-har/commit/97cbd5b)), closes [#341](https://github.com/readmeio/fetch-har/issues/341)
|
|
44
|
+
* chore(deps): bumping deps ([6636acd](https://github.com/readmeio/fetch-har/commit/6636acd))
|
|
45
|
+
* ci: formdata-node is esm only now so we cant use it ([b9b0b47](https://github.com/readmeio/fetch-har/commit/b9b0b47))
|
|
46
|
+
* ci: running unit tests on node 19 (#333) ([6f936da](https://github.com/readmeio/fetch-har/commit/6f936da)), closes [#333](https://github.com/readmeio/fetch-har/issues/333)
|
|
47
|
+
* ci: simplifying ci dep caching ([78a5f34](https://github.com/readmeio/fetch-har/commit/78a5f34))
|
|
48
|
+
* ci: stop testing on node 19 until it hits LTS ([864a10b](https://github.com/readmeio/fetch-har/commit/864a10b))
|
|
49
|
+
* ci: temp-dir is esm-only now ([15e96a0](https://github.com/readmeio/fetch-har/commit/15e96a0))
|
|
50
|
+
* ci: timing out browser tests at 5mins ([c53c161](https://github.com/readmeio/fetch-har/commit/c53c161))
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
## <small>8.1.3 (2022-07-29)</small>
|
|
55
|
+
|
|
56
|
+
* chore: clenaing up some lengthy test comments ([7f797af](https://github.com/readmeio/fetch-har/commit/7f797af))
|
|
57
|
+
* fix: postData filenames may be encoded so we should look for them in `opts.files` too (#308) ([f938ee3](https://github.com/readmeio/fetch-har/commit/f938ee3)), closes [#308](https://github.com/readmeio/fetch-har/issues/308)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
1
61
|
## <small>8.1.2 (2022-07-27)</small>
|
|
2
62
|
|
|
3
63
|
* fix: updating the data-urls package to fix a problem with file case sensititivity ([42cadff](https://github.com/readmeio/fetch-har/commit/42cadff))
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { Har } from 'har-format';
|
|
3
|
-
|
|
3
|
+
export interface FetchHAROptions {
|
|
4
4
|
userAgent?: string;
|
|
5
5
|
files?: Record<string, Blob | Buffer>;
|
|
6
6
|
multipartEncoder?: any;
|
|
7
7
|
init?: RequestInit;
|
|
8
|
-
}
|
|
8
|
+
}
|
|
9
9
|
export default function fetchHAR(har: Har, opts?: FetchHAROptions): Promise<Response>;
|
|
10
|
-
export {};
|
package/dist/index.js
CHANGED
|
@@ -11,8 +11,8 @@ var __assign = (this && this.__assign) || function () {
|
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
13
|
exports.__esModule = true;
|
|
14
|
-
var readable_stream_1 = require("readable-stream");
|
|
15
14
|
var data_urls_1 = require("@readme/data-urls");
|
|
15
|
+
var readable_stream_1 = require("readable-stream");
|
|
16
16
|
if (!globalThis.Blob) {
|
|
17
17
|
try {
|
|
18
18
|
// eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-extraneous-dependencies
|
|
@@ -82,6 +82,15 @@ function isFormData(value) {
|
|
|
82
82
|
isFunction(value.entries) &&
|
|
83
83
|
isFunction(value[Symbol.iterator]));
|
|
84
84
|
}
|
|
85
|
+
function getFileFromSuppliedFiles(filename, files) {
|
|
86
|
+
if (filename in files) {
|
|
87
|
+
return files[filename];
|
|
88
|
+
}
|
|
89
|
+
else if (decodeURIComponent(filename) in files) {
|
|
90
|
+
return files[decodeURIComponent(filename)];
|
|
91
|
+
}
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
85
94
|
function fetchHAR(har, opts) {
|
|
86
95
|
var _a;
|
|
87
96
|
if (opts === void 0) { opts = {}; }
|
|
@@ -199,23 +208,25 @@ function fetchHAR(har, opts) {
|
|
|
199
208
|
}
|
|
200
209
|
request.postData.params.forEach(function (param) {
|
|
201
210
|
if ('fileName' in param) {
|
|
202
|
-
if (opts.files
|
|
203
|
-
var fileContents = opts.files
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
211
|
+
if (opts.files) {
|
|
212
|
+
var fileContents = getFileFromSuppliedFiles(param.fileName, opts.files);
|
|
213
|
+
if (fileContents) {
|
|
214
|
+
// If the file we've got available to us is a Buffer then we need to convert it so
|
|
215
|
+
// that the FormData API can use it.
|
|
216
|
+
if (isBuffer(fileContents)) {
|
|
217
|
+
form_1.append(param.name, new File([fileContents], param.fileName, {
|
|
218
|
+
type: param.contentType || null
|
|
219
|
+
}), param.fileName);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
else if (isFile(fileContents)) {
|
|
223
|
+
form_1.append(param.name, fileContents, param.fileName);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
throw new TypeError('An unknown object has been supplied into the `files` config for use. We only support instances of the File API and Node Buffer objects.');
|
|
215
227
|
}
|
|
216
|
-
throw new TypeError('An unknown object has been supplied into the `files` config for use. We only support instances of the File API and Node Buffer objects.');
|
|
217
228
|
}
|
|
218
|
-
|
|
229
|
+
if ('value' in param) {
|
|
219
230
|
var paramBlob = void 0;
|
|
220
231
|
var parsed = (0, data_urls_1.parse)(param.value);
|
|
221
232
|
if (parsed) {
|
|
@@ -275,23 +286,25 @@ function fetchHAR(har, opts) {
|
|
|
275
286
|
var parsed = (0, data_urls_1.parse)(request.postData.text);
|
|
276
287
|
if (parsed) {
|
|
277
288
|
if ((parsed === null || parsed === void 0 ? void 0 : parsed.name) && parsed.name in opts.files) {
|
|
278
|
-
var fileContents = opts.files
|
|
279
|
-
if (
|
|
280
|
-
|
|
281
|
-
}
|
|
282
|
-
else if (isFile(fileContents)) {
|
|
283
|
-
// `Readable.from` isn't available in browsers but the browser `Request` object can
|
|
284
|
-
// handle `File` objects just fine without us having to mold it into shape.
|
|
285
|
-
if (isBrowser()) {
|
|
289
|
+
var fileContents = getFileFromSuppliedFiles(parsed.name, opts.files);
|
|
290
|
+
if (fileContents) {
|
|
291
|
+
if (isBuffer(fileContents)) {
|
|
286
292
|
options.body = fileContents;
|
|
287
293
|
}
|
|
288
|
-
else {
|
|
289
|
-
//
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
294
|
+
else if (isFile(fileContents)) {
|
|
295
|
+
// `Readable.from` isn't available in browsers but the browser `Request` object can
|
|
296
|
+
// handle `File` objects just fine without us having to mold it into shape.
|
|
297
|
+
if (isBrowser()) {
|
|
298
|
+
options.body = fileContents;
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
// @ts-expect-error "Property 'from' does not exist on type 'typeof Readable'." but it does!
|
|
302
|
+
options.body = readable_stream_1.Readable.from(fileContents.stream());
|
|
303
|
+
// Supplying a polyfilled `File` stream into `Request.body` doesn't automatically
|
|
304
|
+
// add `Content-Length`.
|
|
305
|
+
if (!headers.has('content-length')) {
|
|
306
|
+
headers.set('content-length', String(fileContents.size));
|
|
307
|
+
}
|
|
295
308
|
}
|
|
296
309
|
}
|
|
297
310
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fetch-har",
|
|
3
|
-
"version": "8.1.
|
|
3
|
+
"version": "8.1.4",
|
|
4
4
|
"description": "Make a fetch request from a HAR definition",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -40,16 +40,16 @@
|
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@jsdevtools/host-environment": "^2.1.2",
|
|
42
42
|
"@jsdevtools/karma-config": "^3.1.7",
|
|
43
|
-
"@readme/eslint-config": "^
|
|
43
|
+
"@readme/eslint-config": "^10.3.2",
|
|
44
44
|
"@types/chai": "^4.3.1",
|
|
45
|
-
"@types/express": "^4.17.
|
|
46
|
-
"@types/mocha": "^
|
|
45
|
+
"@types/express": "^4.17.15",
|
|
46
|
+
"@types/mocha": "^10.0.0",
|
|
47
47
|
"@types/multer": "^1.4.7",
|
|
48
|
-
"@types/node": "^18.
|
|
49
|
-
"@types/readable-stream": "^2.3.
|
|
48
|
+
"@types/node": "^18.11.18",
|
|
49
|
+
"@types/readable-stream": "^2.3.15",
|
|
50
50
|
"chai": "^4.3.4",
|
|
51
51
|
"datauri": "^4.1.0",
|
|
52
|
-
"eslint": "^8.
|
|
52
|
+
"eslint": "^8.31.0",
|
|
53
53
|
"express": "^4.18.1",
|
|
54
54
|
"fetch-mock": "^9.11.0",
|
|
55
55
|
"form-data": "^4.0.0",
|
|
@@ -57,17 +57,17 @@
|
|
|
57
57
|
"formdata-node": "^4.3.2",
|
|
58
58
|
"har-examples": "^3.1.1",
|
|
59
59
|
"isomorphic-fetch": "^3.0.0",
|
|
60
|
-
"mocha": "^10.
|
|
60
|
+
"mocha": "^10.2.0",
|
|
61
61
|
"multer": "^1.4.5-lts.1",
|
|
62
62
|
"nock": "^13.2.4",
|
|
63
63
|
"node-fetch": "^2.6.0",
|
|
64
64
|
"nyc": "^15.1.0",
|
|
65
|
-
"prettier": "^2.
|
|
65
|
+
"prettier": "^2.8.1",
|
|
66
66
|
"temp-dir": "^2.0.0",
|
|
67
67
|
"ts-loader": "^8.4.0",
|
|
68
68
|
"ts-node": "^10.7.0",
|
|
69
|
-
"typescript": "^4.
|
|
70
|
-
"undici": "^5.
|
|
69
|
+
"typescript": "^4.9.4",
|
|
70
|
+
"undici": "^5.14.0",
|
|
71
71
|
"webpack": "^4.46.0"
|
|
72
72
|
},
|
|
73
73
|
"browserslist": [
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type { Har } from 'har-format';
|
|
2
1
|
import type { DataURL as npmDataURL } from '@readme/data-urls';
|
|
3
|
-
import {
|
|
2
|
+
import type { Har } from 'har-format';
|
|
3
|
+
|
|
4
4
|
import { parse as parseDataUrl } from '@readme/data-urls';
|
|
5
|
+
import { Readable } from 'readable-stream';
|
|
5
6
|
|
|
6
7
|
if (!globalThis.Blob) {
|
|
7
8
|
try {
|
|
@@ -36,6 +37,19 @@ if (!globalThis.FormData) {
|
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
|
|
40
|
+
export interface FetchHAROptions {
|
|
41
|
+
userAgent?: string;
|
|
42
|
+
files?: Record<string, Blob | Buffer>;
|
|
43
|
+
multipartEncoder?: any; // form-data-encoder
|
|
44
|
+
init?: RequestInit;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
type DataURL = npmDataURL & {
|
|
48
|
+
// `parse-data-url` doesn't explicitly support `name` in data URLs but if it's there it'll be
|
|
49
|
+
// returned back to us.
|
|
50
|
+
name?: string;
|
|
51
|
+
};
|
|
52
|
+
|
|
39
53
|
function isBrowser() {
|
|
40
54
|
return typeof window !== 'undefined' && typeof document !== 'undefined';
|
|
41
55
|
}
|
|
@@ -86,18 +100,15 @@ function isFormData(value: any) {
|
|
|
86
100
|
);
|
|
87
101
|
}
|
|
88
102
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
103
|
+
function getFileFromSuppliedFiles(filename: string, files: FetchHAROptions['files']) {
|
|
104
|
+
if (filename in files) {
|
|
105
|
+
return files[filename];
|
|
106
|
+
} else if (decodeURIComponent(filename) in files) {
|
|
107
|
+
return files[decodeURIComponent(filename)];
|
|
108
|
+
}
|
|
95
109
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
// returned back to us.
|
|
99
|
-
name?: string;
|
|
100
|
-
};
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
101
112
|
|
|
102
113
|
export default function fetchHAR(har: Har, opts: FetchHAROptions = {}) {
|
|
103
114
|
if (!har) throw new Error('Missing HAR definition');
|
|
@@ -232,30 +243,33 @@ export default function fetchHAR(har: Har, opts: FetchHAROptions = {}) {
|
|
|
232
243
|
|
|
233
244
|
request.postData.params.forEach(param => {
|
|
234
245
|
if ('fileName' in param) {
|
|
235
|
-
if (opts.files
|
|
236
|
-
const fileContents = opts.files
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
246
|
+
if (opts.files) {
|
|
247
|
+
const fileContents = getFileFromSuppliedFiles(param.fileName, opts.files);
|
|
248
|
+
if (fileContents) {
|
|
249
|
+
// If the file we've got available to us is a Buffer then we need to convert it so
|
|
250
|
+
// that the FormData API can use it.
|
|
251
|
+
if (isBuffer(fileContents)) {
|
|
252
|
+
form.append(
|
|
253
|
+
param.name,
|
|
254
|
+
new File([fileContents], param.fileName, {
|
|
255
|
+
type: param.contentType || null,
|
|
256
|
+
}),
|
|
257
|
+
param.fileName
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
return;
|
|
261
|
+
} else if (isFile(fileContents)) {
|
|
262
|
+
form.append(param.name, fileContents as Blob, param.fileName);
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
throw new TypeError(
|
|
267
|
+
'An unknown object has been supplied into the `files` config for use. We only support instances of the File API and Node Buffer objects.'
|
|
247
268
|
);
|
|
248
|
-
|
|
249
|
-
return;
|
|
250
|
-
} else if (isFile(fileContents)) {
|
|
251
|
-
form.append(param.name, fileContents as Blob, param.fileName);
|
|
252
|
-
return;
|
|
253
269
|
}
|
|
270
|
+
}
|
|
254
271
|
|
|
255
|
-
|
|
256
|
-
'An unknown object has been supplied into the `files` config for use. We only support instances of the File API and Node Buffer objects.'
|
|
257
|
-
);
|
|
258
|
-
} else if ('value' in param) {
|
|
272
|
+
if ('value' in param) {
|
|
259
273
|
let paramBlob;
|
|
260
274
|
const parsed = parseDataUrl(param.value);
|
|
261
275
|
if (parsed) {
|
|
@@ -321,22 +335,24 @@ export default function fetchHAR(har: Har, opts: FetchHAROptions = {}) {
|
|
|
321
335
|
const parsed = parseDataUrl(request.postData.text) as DataURL;
|
|
322
336
|
if (parsed) {
|
|
323
337
|
if (parsed?.name && parsed.name in opts.files) {
|
|
324
|
-
const fileContents = opts.files
|
|
325
|
-
if (
|
|
326
|
-
|
|
327
|
-
} else if (isFile(fileContents)) {
|
|
328
|
-
// `Readable.from` isn't available in browsers but the browser `Request` object can
|
|
329
|
-
// handle `File` objects just fine without us having to mold it into shape.
|
|
330
|
-
if (isBrowser()) {
|
|
338
|
+
const fileContents = getFileFromSuppliedFiles(parsed.name, opts.files);
|
|
339
|
+
if (fileContents) {
|
|
340
|
+
if (isBuffer(fileContents)) {
|
|
331
341
|
options.body = fileContents;
|
|
332
|
-
} else {
|
|
333
|
-
//
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
342
|
+
} else if (isFile(fileContents)) {
|
|
343
|
+
// `Readable.from` isn't available in browsers but the browser `Request` object can
|
|
344
|
+
// handle `File` objects just fine without us having to mold it into shape.
|
|
345
|
+
if (isBrowser()) {
|
|
346
|
+
options.body = fileContents;
|
|
347
|
+
} else {
|
|
348
|
+
// @ts-expect-error "Property 'from' does not exist on type 'typeof Readable'." but it does!
|
|
349
|
+
options.body = Readable.from((fileContents as File).stream());
|
|
350
|
+
|
|
351
|
+
// Supplying a polyfilled `File` stream into `Request.body` doesn't automatically
|
|
352
|
+
// add `Content-Length`.
|
|
353
|
+
if (!headers.has('content-length')) {
|
|
354
|
+
headers.set('content-length', String((fileContents as File).size));
|
|
355
|
+
}
|
|
340
356
|
}
|
|
341
357
|
}
|
|
342
358
|
}
|