fetch-har 6.0.2 → 6.1.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.
- package/CHANGELOG.md +6 -0
- package/README.md +6 -11
- package/example.js +4 -8
- package/index.js +11 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
## 6.1.0 (2022-01-27)
|
|
2
|
+
|
|
3
|
+
* feat: automatically polyfilling FormData with formdata-node if present (#241) ([da94dfc](https://github.com/readmeio/fetch-har/commit/da94dfc)), closes [#241](https://github.com/readmeio/fetch-har/issues/241)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
1
7
|
## <small>6.0.2 (2022-01-27)</small>
|
|
2
8
|
|
|
3
9
|
* fix: typo in the optional formdata-node package ([d05bcda](https://github.com/readmeio/fetch-har/commit/d05bcda))
|
package/README.md
CHANGED
|
@@ -14,16 +14,11 @@ npm install --save fetch-har
|
|
|
14
14
|
## Usage
|
|
15
15
|
```js
|
|
16
16
|
require('isomorphic-fetch');
|
|
17
|
-
const fetchHar = require('.');
|
|
18
17
|
|
|
19
|
-
// If executing from an environment that dodoesn't normally provide fetch()
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
|
|
23
|
-
globalThis.Blob = require('formdata-node').Blob;
|
|
24
|
-
globalThis.File = require('formdata-node').File;
|
|
25
|
-
globalThis.FormData = require('formdata-node').FormData;
|
|
26
|
-
}
|
|
18
|
+
// If executing from an environment that dodoesn't normally provide `fetch()`
|
|
19
|
+
// we'll automatically polyfill in the `Blob`, `File`, and `FormData` APIs
|
|
20
|
+
// with the optional `formdata-node` package (provided you've installed it).
|
|
21
|
+
const fetchHar = require('.');
|
|
27
22
|
|
|
28
23
|
const har = {
|
|
29
24
|
log: {
|
|
@@ -66,7 +61,7 @@ If you are executing `fetch-har` in a browser environment that supports the [For
|
|
|
66
61
|
|
|
67
62
|
Unfortunately the most popular NPM package [form-data](https://npm.im/form-data) ships with a [non-spec compliant API](https://github.com/form-data/form-data/issues/124), and for this we don't recommend you use it, as if you use `fetch-har` to upload files it may not work.
|
|
68
63
|
|
|
69
|
-
|
|
64
|
+
Though we recommend either [formdata-node](https://npm.im/formdata-node) or [formdata-polyfill](https://npm.im/formdata-polyfill) we prefer [formdata-node](https://npm.im/formdata-node) right now as it's CJS-compatible.
|
|
70
65
|
|
|
71
66
|
#### Options
|
|
72
67
|
##### userAgent
|
|
@@ -89,7 +84,7 @@ await fetchHar(har, { files: {
|
|
|
89
84
|
If you don't supply this option `fetch-har` will fallback to the data URL present within the supplied HAR. If no `files` option is present, and no data URL (via `param.value`) is present in the HAR, a fatal exception will be thrown.
|
|
90
85
|
|
|
91
86
|
##### multipartEncoder
|
|
92
|
-
> ❗ If you are using `fetch-har` in Node you may need this option!
|
|
87
|
+
> ❗ If you are using `fetch-har` in Node you may need this option to execute `multipart/form-data` requests!
|
|
93
88
|
|
|
94
89
|
If you are running `fetch-har` within a Node environment and you're using `node-fetch@2`, or another `fetch` polyfill that does not support a spec-compliant `FormData` API, you will need to specify an encoder that will transform your `FormData` object into something that can be used with [Request.body](https://developer.mozilla.org/en-US/docs/Web/API/Request/body).
|
|
95
90
|
|
package/example.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
/* eslint-disable import/no-extraneous-dependencies, no-console */
|
|
2
2
|
require('isomorphic-fetch');
|
|
3
|
-
const fetchHar = require('.');
|
|
4
3
|
|
|
5
|
-
// If executing from an environment that dodoesn't normally provide fetch()
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
globalThis.File = require('formdata-node').File;
|
|
10
|
-
globalThis.FormData = require('formdata-node').FormData;
|
|
11
|
-
}
|
|
4
|
+
// If executing from an environment that dodoesn't normally provide `fetch()`
|
|
5
|
+
// we'll automatically polyfill in the `Blob`, `File`, and `FormData` APIs
|
|
6
|
+
// with the optional `formdata-node` package (provided you've installed it).
|
|
7
|
+
const fetchHar = require('.');
|
|
12
8
|
|
|
13
9
|
const har = {
|
|
14
10
|
log: {
|
package/index.js
CHANGED
|
@@ -23,6 +23,17 @@ if (!globalThis.File) {
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
if (!globalThis.FormData) {
|
|
27
|
+
try {
|
|
28
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
29
|
+
globalThis.FormData = require('formdata-node').FormData;
|
|
30
|
+
} catch (e) {
|
|
31
|
+
throw new Error(
|
|
32
|
+
'Since you do not have the FormData API available in this environment you must install the optional `formdata-node` dependency.'
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
26
37
|
function isBrowser() {
|
|
27
38
|
return typeof window !== 'undefined' && typeof document !== 'undefined';
|
|
28
39
|
}
|