swagger-client 3.13.5 → 3.14.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/README.md +1 -1
- package/dist/swagger-client.browser.js +1645 -2287
- package/dist/swagger-client.browser.min.js +1 -1
- package/dist/swagger-client.browser.min.js.map +1 -1
- package/es/execute/index.js +2 -1
- package/es/http/fold-formdata-to-request.browser.js +5 -0
- package/es/http/fold-formdata-to-request.node.js +26 -0
- package/es/{http.js → http/index.js} +10 -8
- package/es/index.js +2 -1
- package/lib/execute/index.js +3 -1
- package/lib/http/fold-formdata-to-request.browser.js +11 -0
- package/lib/http/fold-formdata-to-request.node.js +40 -0
- package/lib/{http.js → http/index.js} +12 -9
- package/lib/index.js +2 -1
- package/package.json +27 -21
- package/es/internal/form-data-monkey-patch.js +0 -104
- package/lib/internal/form-data-monkey-patch.js +0 -73
package/es/execute/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime-corejs3/helpers/slicedToArray";
|
|
2
2
|
import _objectSpread from "@babel/runtime-corejs3/helpers/objectSpread2";
|
|
3
3
|
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/objectWithoutProperties";
|
|
4
|
+
var _excluded = ["http", "fetch", "spec", "operationId", "pathName", "method", "parameters", "securities"];
|
|
4
5
|
import _Object$assign from "@babel/runtime-corejs3/core-js-stable/object/assign";
|
|
5
6
|
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
|
6
7
|
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
|
@@ -73,7 +74,7 @@ export function execute(_ref) {
|
|
|
73
74
|
method = _ref.method,
|
|
74
75
|
parameters = _ref.parameters,
|
|
75
76
|
securities = _ref.securities,
|
|
76
|
-
extras = _objectWithoutProperties(_ref,
|
|
77
|
+
extras = _objectWithoutProperties(_ref, _excluded);
|
|
77
78
|
|
|
78
79
|
// Provide default fetch implementation
|
|
79
80
|
var http = userHttp || fetch || stockHttp; // Default to _our_ http
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime-corejs3/helpers/objectSpread2";
|
|
2
|
+
import { Readable } from 'stream';
|
|
3
|
+
import { Encoder } from 'form-data-encoder';
|
|
4
|
+
/**
|
|
5
|
+
* formdata-node works in node-fetch@2.x via form-data-encoder only.
|
|
6
|
+
* FormData instance is converted to Encoder instance which gets converted
|
|
7
|
+
* to Readable Stream.
|
|
8
|
+
*
|
|
9
|
+
* TODO(vladimir.gorej@gmail.com): this can be removed when migrated to node-fetch@3.x
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
var foldFormDataToRequest = function foldFormDataToRequest(formdata, request) {
|
|
13
|
+
var encoder = new Encoder(formdata);
|
|
14
|
+
var readableStream = Readable.from(encoder); // get rid of previous headers
|
|
15
|
+
|
|
16
|
+
delete request.headers['content-type'];
|
|
17
|
+
delete request.headers['Content-Type']; // set computed headers
|
|
18
|
+
|
|
19
|
+
request.headers = _objectSpread(_objectSpread({}, request.headers), encoder.headers); // set FormData instance to request for debugging purposes
|
|
20
|
+
|
|
21
|
+
request.formdata = formdata; // assign readable stream as request body
|
|
22
|
+
|
|
23
|
+
request.body = readableStream;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export default foldFormDataToRequest;
|
|
@@ -20,8 +20,9 @@ import jsYaml from 'js-yaml';
|
|
|
20
20
|
import pick from 'lodash/pick';
|
|
21
21
|
import isFunction from 'lodash/isFunction';
|
|
22
22
|
import { Buffer } from 'buffer';
|
|
23
|
-
import FormData from '
|
|
24
|
-
import { encodeDisallowedCharacters } from '
|
|
23
|
+
import { FormData } from 'formdata-node';
|
|
24
|
+
import { encodeDisallowedCharacters } from '../execute/oas3/style-serializer';
|
|
25
|
+
import foldFormDataToRequest from './fold-formdata-to-request.node'; // For testing
|
|
25
26
|
|
|
26
27
|
export var self = {
|
|
27
28
|
serializeRes: serializeRes,
|
|
@@ -97,10 +98,10 @@ function _http() {
|
|
|
97
98
|
|
|
98
99
|
case 12:
|
|
99
100
|
// for content-type=multipart\/form-data remove content-type from request before fetch
|
|
100
|
-
// so that correct one with `boundary` is set
|
|
101
|
-
contentType = request.headers['content-type'] || request.headers['Content-Type'];
|
|
101
|
+
// so that correct one with `boundary` is set when request body is different than boundary encoded string
|
|
102
|
+
contentType = request.headers['content-type'] || request.headers['Content-Type']; // TODO(vladimir.gorej@gmail.com): assertion of FormData instance can be removed when migrated to node-fetch@2.x
|
|
102
103
|
|
|
103
|
-
if (/multipart\/form-data/i.test(contentType)) {
|
|
104
|
+
if (/multipart\/form-data/i.test(contentType) && request.body instanceof FormData) {
|
|
104
105
|
delete request.headers['content-type'];
|
|
105
106
|
delete request.headers['Content-Type'];
|
|
106
107
|
} // eslint-disable-next-line no-undef
|
|
@@ -155,7 +156,7 @@ function _http() {
|
|
|
155
156
|
throw _context6.t2;
|
|
156
157
|
|
|
157
158
|
case 34:
|
|
158
|
-
error = new Error(res.statusText);
|
|
159
|
+
error = new Error(res.statusText || "response status is ".concat(res.status));
|
|
159
160
|
error.status = res.status;
|
|
160
161
|
error.statusCode = res.status;
|
|
161
162
|
error.responseError = _context6.t2;
|
|
@@ -167,7 +168,7 @@ function _http() {
|
|
|
167
168
|
break;
|
|
168
169
|
}
|
|
169
170
|
|
|
170
|
-
_error = new Error(res.statusText);
|
|
171
|
+
_error = new Error(res.statusText || "response status is ".concat(res.status));
|
|
171
172
|
_error.status = res.status;
|
|
172
173
|
_error.statusCode = res.status;
|
|
173
174
|
_error.response = res;
|
|
@@ -577,7 +578,8 @@ export function mergeInQueryOrForm() {
|
|
|
577
578
|
var contentType = req.headers['content-type'] || req.headers['Content-Type'];
|
|
578
579
|
|
|
579
580
|
if (hasFile || /multipart\/form-data/i.test(contentType)) {
|
|
580
|
-
|
|
581
|
+
var formdata = buildFormData(req.form);
|
|
582
|
+
foldFormDataToRequest(formdata, req);
|
|
581
583
|
} else {
|
|
582
584
|
req.body = encodeFormOrQuery(form);
|
|
583
585
|
}
|
package/es/index.js
CHANGED
|
@@ -78,7 +78,8 @@ Swagger.prototype = {
|
|
|
78
78
|
allowMetaPatches: this.allowMetaPatches,
|
|
79
79
|
useCircularStructures: this.useCircularStructures,
|
|
80
80
|
requestInterceptor: this.requestInterceptor || null,
|
|
81
|
-
responseInterceptor: this.responseInterceptor || null
|
|
81
|
+
responseInterceptor: this.responseInterceptor || null,
|
|
82
|
+
skipNormalization: this.skipNormalization || false
|
|
82
83
|
}, options)).then(function (obj) {
|
|
83
84
|
_this2.originalSpec = _this2.spec;
|
|
84
85
|
_this2.spec = obj.spec;
|
package/lib/execute/index.js
CHANGED
|
@@ -30,6 +30,8 @@ var _buildRequest2 = _interopRequireDefault(require("./swagger2/build-request"))
|
|
|
30
30
|
|
|
31
31
|
var _helpers = require("../helpers");
|
|
32
32
|
|
|
33
|
+
const _excluded = ["http", "fetch", "spec", "operationId", "pathName", "method", "parameters", "securities"];
|
|
34
|
+
|
|
33
35
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
34
36
|
|
|
35
37
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
@@ -94,7 +96,7 @@ function execute(_ref) {
|
|
|
94
96
|
parameters,
|
|
95
97
|
securities
|
|
96
98
|
} = _ref,
|
|
97
|
-
extras = _objectWithoutProperties(_ref,
|
|
99
|
+
extras = _objectWithoutProperties(_ref, _excluded);
|
|
98
100
|
|
|
99
101
|
// Provide default fetch implementation
|
|
100
102
|
const http = userHttp || fetch || _http.default; // Default to _our_ http
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = void 0;
|
|
5
|
+
|
|
6
|
+
var _stream = require("stream");
|
|
7
|
+
|
|
8
|
+
var _formDataEncoder = require("form-data-encoder");
|
|
9
|
+
|
|
10
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
11
|
+
|
|
12
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
13
|
+
|
|
14
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* formdata-node works in node-fetch@2.x via form-data-encoder only.
|
|
18
|
+
* FormData instance is converted to Encoder instance which gets converted
|
|
19
|
+
* to Readable Stream.
|
|
20
|
+
*
|
|
21
|
+
* TODO(vladimir.gorej@gmail.com): this can be removed when migrated to node-fetch@3.x
|
|
22
|
+
*/
|
|
23
|
+
const foldFormDataToRequest = (formdata, request) => {
|
|
24
|
+
const encoder = new _formDataEncoder.Encoder(formdata);
|
|
25
|
+
|
|
26
|
+
const readableStream = _stream.Readable.from(encoder); // get rid of previous headers
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
delete request.headers['content-type'];
|
|
30
|
+
delete request.headers['Content-Type']; // set computed headers
|
|
31
|
+
|
|
32
|
+
request.headers = _objectSpread(_objectSpread({}, request.headers), encoder.headers); // set FormData instance to request for debugging purposes
|
|
33
|
+
|
|
34
|
+
request.formdata = formdata; // assign readable stream as request body
|
|
35
|
+
|
|
36
|
+
request.body = readableStream;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
var _default = foldFormDataToRequest;
|
|
40
|
+
exports.default = _default;
|
|
@@ -22,9 +22,11 @@ var _isFunction = _interopRequireDefault(require("lodash/isFunction"));
|
|
|
22
22
|
|
|
23
23
|
var _buffer = require("buffer");
|
|
24
24
|
|
|
25
|
-
var
|
|
25
|
+
var _formdataNode = require("formdata-node");
|
|
26
26
|
|
|
27
|
-
var _styleSerializer = require("
|
|
27
|
+
var _styleSerializer = require("../execute/oas3/style-serializer");
|
|
28
|
+
|
|
29
|
+
var _foldFormdataToRequest = _interopRequireDefault(require("./fold-formdata-to-request.node"));
|
|
28
30
|
|
|
29
31
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
30
32
|
|
|
@@ -68,12 +70,12 @@ async function http(url, request = {}) {
|
|
|
68
70
|
if (request.requestInterceptor) {
|
|
69
71
|
request = (await request.requestInterceptor(request)) || request;
|
|
70
72
|
} // for content-type=multipart\/form-data remove content-type from request before fetch
|
|
71
|
-
// so that correct one with `boundary` is set
|
|
73
|
+
// so that correct one with `boundary` is set when request body is different than boundary encoded string
|
|
72
74
|
|
|
73
75
|
|
|
74
|
-
const contentType = request.headers['content-type'] || request.headers['Content-Type'];
|
|
76
|
+
const contentType = request.headers['content-type'] || request.headers['Content-Type']; // TODO(vladimir.gorej@gmail.com): assertion of FormData instance can be removed when migrated to node-fetch@2.x
|
|
75
77
|
|
|
76
|
-
if (/multipart\/form-data/i.test(contentType)) {
|
|
78
|
+
if (/multipart\/form-data/i.test(contentType) && request.body instanceof _formdataNode.FormData) {
|
|
77
79
|
delete request.headers['content-type'];
|
|
78
80
|
delete request.headers['Content-Type'];
|
|
79
81
|
} // eslint-disable-next-line no-undef
|
|
@@ -95,7 +97,7 @@ async function http(url, request = {}) {
|
|
|
95
97
|
throw resError;
|
|
96
98
|
}
|
|
97
99
|
|
|
98
|
-
const error = new Error(res.statusText);
|
|
100
|
+
const error = new Error(res.statusText || `response status is ${res.status}`);
|
|
99
101
|
error.status = res.status;
|
|
100
102
|
error.statusCode = res.status;
|
|
101
103
|
error.responseError = resError;
|
|
@@ -103,7 +105,7 @@ async function http(url, request = {}) {
|
|
|
103
105
|
}
|
|
104
106
|
|
|
105
107
|
if (!res.ok) {
|
|
106
|
-
const error = new Error(res.statusText);
|
|
108
|
+
const error = new Error(res.statusText || `response status is ${res.status}`);
|
|
107
109
|
error.status = res.status;
|
|
108
110
|
error.statusCode = res.status;
|
|
109
111
|
error.response = res;
|
|
@@ -370,7 +372,7 @@ function buildFormData(reqForm) {
|
|
|
370
372
|
}
|
|
371
373
|
|
|
372
374
|
return formData;
|
|
373
|
-
}, new
|
|
375
|
+
}, new _formdataNode.FormData());
|
|
374
376
|
} // Encodes an object using appropriate serializer.
|
|
375
377
|
|
|
376
378
|
|
|
@@ -420,7 +422,8 @@ function mergeInQueryOrForm(req = {}) {
|
|
|
420
422
|
const contentType = req.headers['content-type'] || req.headers['Content-Type'];
|
|
421
423
|
|
|
422
424
|
if (hasFile || /multipart\/form-data/i.test(contentType)) {
|
|
423
|
-
|
|
425
|
+
const formdata = buildFormData(req.form);
|
|
426
|
+
(0, _foldFormdataToRequest.default)(formdata, req);
|
|
424
427
|
} else {
|
|
425
428
|
req.body = encodeFormOrQuery(form);
|
|
426
429
|
}
|
package/lib/index.js
CHANGED
|
@@ -98,7 +98,8 @@ Swagger.prototype = {
|
|
|
98
98
|
allowMetaPatches: this.allowMetaPatches,
|
|
99
99
|
useCircularStructures: this.useCircularStructures,
|
|
100
100
|
requestInterceptor: this.requestInterceptor || null,
|
|
101
|
-
responseInterceptor: this.responseInterceptor || null
|
|
101
|
+
responseInterceptor: this.responseInterceptor || null,
|
|
102
|
+
skipNormalization: this.skipNormalization || false
|
|
102
103
|
}, options)).then(obj => {
|
|
103
104
|
this.originalSpec = this.spec;
|
|
104
105
|
this.spec = obj.spec;
|
package/package.json
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "swagger-client",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.14.1",
|
|
4
4
|
"description": "SwaggerJS - a collection of interfaces for OAI specs",
|
|
5
|
+
"browser": {
|
|
6
|
+
"./src/http/fold-formdata-to-request.node.js": "./src/http/fold-formdata-to-request.browser.js",
|
|
7
|
+
"./lib/http/fold-formdata-to-request.node.js": "./lib/http/fold-formdata-to-request.browser.js",
|
|
8
|
+
"./es/http/fold-formdata-to-request.node.js": "./es/http/fold-formdata-to-request.browser.js"
|
|
9
|
+
},
|
|
5
10
|
"main": "lib/commonjs.js",
|
|
6
11
|
"module": "es/index.js",
|
|
7
12
|
"jsnext:main": "es/index.js",
|
|
@@ -41,7 +46,7 @@
|
|
|
41
46
|
"test:unit:coverage": "cross-env BABEL_ENV=commonjs jest --runInBand --config ./config/jest/jest.unit.coverage.config.js",
|
|
42
47
|
"test:unit:watch": "cross-env BABEL_ENV=commonjs jest --runInBand --watch --config ./config/jest/jest.unit.config.js",
|
|
43
48
|
"test:artifact": "run-s test:artifact:umd:browser test:artifact:es test:artifact:commonjs",
|
|
44
|
-
"test:artifact:umd:browser": "npm run build:umd:browser && cross-env BABEL_ENV=
|
|
49
|
+
"test:artifact:umd:browser": "npm run build:umd:browser && cross-env BABEL_ENV=browser jest --config ./config/jest/jest.artifact-umd-browser.config.js",
|
|
45
50
|
"test:artifact:es": "npm run build:es && cross-env BABEL_ENV=commonjs jest --config ./config/jest/jest.artifact-es.config.js",
|
|
46
51
|
"test:artifact:commonjs": "npm run build:commonjs && cross-env BABEL_ENV=commonjs jest --config ./config/jest/jest.artifact-commonjs.config.js",
|
|
47
52
|
"deps:license": "license-checker --production --csv --out $npm_package_config_deps_check_dir/licenses.csv && license-checker --development --csv --out $npm_package_config_deps_check_dir/licenses-dev.csv",
|
|
@@ -60,44 +65,44 @@
|
|
|
60
65
|
],
|
|
61
66
|
"license": "Apache-2.0",
|
|
62
67
|
"devDependencies": {
|
|
63
|
-
"@babel/cli": "=7.14.
|
|
64
|
-
"@babel/core": "=7.14.
|
|
65
|
-
"@babel/plugin-proposal-class-properties": "=7.
|
|
66
|
-
"@babel/plugin-proposal-object-rest-spread": "=7.14.
|
|
67
|
-
"@babel/plugin-transform-runtime": "=7.14.
|
|
68
|
-
"@babel/preset-env": "=7.14.
|
|
69
|
-
"@babel/register": "=7.
|
|
68
|
+
"@babel/cli": "=7.14.8",
|
|
69
|
+
"@babel/core": "=7.14.8",
|
|
70
|
+
"@babel/plugin-proposal-class-properties": "=7.14.5",
|
|
71
|
+
"@babel/plugin-proposal-object-rest-spread": "=7.14.7",
|
|
72
|
+
"@babel/plugin-transform-runtime": "=7.14.5",
|
|
73
|
+
"@babel/preset-env": "=7.14.8",
|
|
74
|
+
"@babel/register": "=7.14.5",
|
|
70
75
|
"@char0n/npm-audit": "gist:2964395223d7943c10396f59df9a8ea0",
|
|
71
76
|
"@commitlint/cli": "^12.0.0",
|
|
72
|
-
"@commitlint/config-conventional": "^
|
|
77
|
+
"@commitlint/config-conventional": "^13.1.0",
|
|
73
78
|
"babel-loader": "=8.2.2",
|
|
74
79
|
"babel-plugin-lodash": "=3.3.4",
|
|
75
80
|
"cross-env": "=7.0.3",
|
|
76
|
-
"eslint": "=7.
|
|
81
|
+
"eslint": "=7.31.0",
|
|
77
82
|
"eslint-config-airbnb-base": "=14.2.1",
|
|
78
83
|
"eslint-config-prettier": "=8.3.0",
|
|
79
|
-
"eslint-plugin-import": "=2.23.
|
|
84
|
+
"eslint-plugin-import": "=2.23.4",
|
|
80
85
|
"eslint-plugin-prettier": "=3.4.0",
|
|
81
|
-
"expect": "=
|
|
86
|
+
"expect": "=27.0.6",
|
|
82
87
|
"fetch-mock": "=9.11.0",
|
|
83
88
|
"glob": "=7.1.7",
|
|
84
|
-
"husky": "
|
|
89
|
+
"husky": "^7.0.1",
|
|
85
90
|
"inspectpack": "=4.7.1",
|
|
86
91
|
"install": "=0.13.0",
|
|
87
|
-
"jest": "
|
|
92
|
+
"jest": "^27.0.1",
|
|
88
93
|
"json-loader": "=0.5.7",
|
|
89
94
|
"license-checker": "=25.0.1",
|
|
90
|
-
"lint-staged": "=11.
|
|
95
|
+
"lint-staged": "=11.1.1",
|
|
91
96
|
"lodash-webpack-plugin": "=0.11.6",
|
|
92
|
-
"nock": "=13.
|
|
97
|
+
"nock": "=13.1.1",
|
|
93
98
|
"node-fetch": "=2.6.1",
|
|
94
99
|
"npm-run-all": "=4.1.5",
|
|
95
100
|
"prettier": "^2.3.0",
|
|
96
101
|
"rimraf": "=3.0.2",
|
|
97
102
|
"terser-webpack-plugin": "^5.0.3",
|
|
98
|
-
"webpack": "=5.
|
|
103
|
+
"webpack": "=5.46.0",
|
|
99
104
|
"webpack-bundle-size-analyzer": "=3.1.0",
|
|
100
|
-
"webpack-cli": "=4.7.
|
|
105
|
+
"webpack-cli": "=4.7.2",
|
|
101
106
|
"webpack-stats-plugin": "=1.0.3",
|
|
102
107
|
"xmock": "=0.3.0"
|
|
103
108
|
},
|
|
@@ -106,10 +111,11 @@
|
|
|
106
111
|
"btoa": "^1.2.1",
|
|
107
112
|
"buffer": "^6.0.3",
|
|
108
113
|
"cookie": "~0.4.1",
|
|
109
|
-
"cross-fetch": "^3.
|
|
114
|
+
"cross-fetch": "^3.1.4",
|
|
110
115
|
"deep-extend": "~0.6.0",
|
|
111
116
|
"fast-json-patch": "^3.0.0-1",
|
|
112
|
-
"
|
|
117
|
+
"form-data-encoder": "^1.0.1",
|
|
118
|
+
"formdata-node": "^3.6.2",
|
|
113
119
|
"js-yaml": "^3.14.0",
|
|
114
120
|
"lodash": "^4.17.19",
|
|
115
121
|
"qs": "^6.9.4",
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import _classCallCheck from "@babel/runtime-corejs3/helpers/classCallCheck";
|
|
2
|
-
import _createClass from "@babel/runtime-corejs3/helpers/createClass";
|
|
3
|
-
import _get from "@babel/runtime-corejs3/helpers/get";
|
|
4
|
-
import _getPrototypeOf from "@babel/runtime-corejs3/helpers/getPrototypeOf";
|
|
5
|
-
import _inherits from "@babel/runtime-corejs3/helpers/inherits";
|
|
6
|
-
import _createSuper from "@babel/runtime-corejs3/helpers/createSuper";
|
|
7
|
-
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
|
8
|
-
import _findInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find";
|
|
9
|
-
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
|
10
|
-
import isFunction from 'lodash/isFunction';
|
|
11
|
-
import IsomorphicFormData from 'isomorphic-form-data'; // patches FormData type by mutating it.
|
|
12
|
-
// patch :: FormData -> PatchedFormData
|
|
13
|
-
|
|
14
|
-
export var patch = function patch(FormData) {
|
|
15
|
-
var createEntry = function createEntry(field, value) {
|
|
16
|
-
return {
|
|
17
|
-
name: field,
|
|
18
|
-
value: value
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
/** We return original type if prototype already contains one of methods we're trying to patch.
|
|
22
|
-
* Reasoning: if one of the methods already exists, it would access data in other
|
|
23
|
-
* property than our `_entryList`. That could potentially create nasty
|
|
24
|
-
* hardly detectable bugs if `form-data` library implements only couple of
|
|
25
|
-
* methods that it misses, instead of implementing all of them.
|
|
26
|
-
* Current solution will fail the tests to let us know that form-data library
|
|
27
|
-
* already implements some of the methods that we try to monkey-patch, and our
|
|
28
|
-
* monkey-patch code should then compensate the library changes easily.
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (isFunction(FormData.prototype.set) || isFunction(FormData.prototype.get) || isFunction(FormData.prototype.getAll) || isFunction(FormData.prototype.has)) {
|
|
33
|
-
return FormData;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
var PatchedFormData = /*#__PURE__*/function (_FormData) {
|
|
37
|
-
_inherits(PatchedFormData, _FormData);
|
|
38
|
-
|
|
39
|
-
var _super = _createSuper(PatchedFormData);
|
|
40
|
-
|
|
41
|
-
function PatchedFormData(form) {
|
|
42
|
-
var _this;
|
|
43
|
-
|
|
44
|
-
_classCallCheck(this, PatchedFormData);
|
|
45
|
-
|
|
46
|
-
_this = _super.call(this, form);
|
|
47
|
-
_this.entryList = [];
|
|
48
|
-
return _this;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
_createClass(PatchedFormData, [{
|
|
52
|
-
key: "append",
|
|
53
|
-
value: function append(field, value, options) {
|
|
54
|
-
this.entryList.push(createEntry(field, value));
|
|
55
|
-
return _get(_getPrototypeOf(PatchedFormData.prototype), "append", this).call(this, field, value, options);
|
|
56
|
-
}
|
|
57
|
-
}, {
|
|
58
|
-
key: "set",
|
|
59
|
-
value: function set(field, value) {
|
|
60
|
-
var _context;
|
|
61
|
-
|
|
62
|
-
var newEntry = createEntry(field, value);
|
|
63
|
-
this.entryList = _filterInstanceProperty(_context = this.entryList).call(_context, function (entry) {
|
|
64
|
-
return entry.name !== field;
|
|
65
|
-
});
|
|
66
|
-
this.entryList.push(newEntry);
|
|
67
|
-
}
|
|
68
|
-
}, {
|
|
69
|
-
key: "get",
|
|
70
|
-
value: function get(field) {
|
|
71
|
-
var _context2;
|
|
72
|
-
|
|
73
|
-
var foundEntry = _findInstanceProperty(_context2 = this.entryList).call(_context2, function (entry) {
|
|
74
|
-
return entry.name === field;
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
return foundEntry === undefined ? null : foundEntry;
|
|
78
|
-
}
|
|
79
|
-
}, {
|
|
80
|
-
key: "getAll",
|
|
81
|
-
value: function getAll(field) {
|
|
82
|
-
var _context3, _context4;
|
|
83
|
-
|
|
84
|
-
return _mapInstanceProperty(_context3 = _filterInstanceProperty(_context4 = this.entryList).call(_context4, function (entry) {
|
|
85
|
-
return entry.name === field;
|
|
86
|
-
})).call(_context3, function (entry) {
|
|
87
|
-
return entry.value;
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
}, {
|
|
91
|
-
key: "has",
|
|
92
|
-
value: function has(field) {
|
|
93
|
-
return this.entryList.some(function (entry) {
|
|
94
|
-
return entry.name === field;
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
}]);
|
|
98
|
-
|
|
99
|
-
return PatchedFormData;
|
|
100
|
-
}(FormData);
|
|
101
|
-
|
|
102
|
-
return PatchedFormData;
|
|
103
|
-
};
|
|
104
|
-
export default patch(IsomorphicFormData);
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.__esModule = true;
|
|
4
|
-
exports.default = exports.patch = void 0;
|
|
5
|
-
|
|
6
|
-
var _isFunction = _interopRequireDefault(require("lodash/isFunction"));
|
|
7
|
-
|
|
8
|
-
var _isomorphicFormData = _interopRequireDefault(require("isomorphic-form-data"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
// patches FormData type by mutating it.
|
|
13
|
-
// patch :: FormData -> PatchedFormData
|
|
14
|
-
const patch = FormData => {
|
|
15
|
-
const createEntry = (field, value) => ({
|
|
16
|
-
name: field,
|
|
17
|
-
value
|
|
18
|
-
});
|
|
19
|
-
/** We return original type if prototype already contains one of methods we're trying to patch.
|
|
20
|
-
* Reasoning: if one of the methods already exists, it would access data in other
|
|
21
|
-
* property than our `_entryList`. That could potentially create nasty
|
|
22
|
-
* hardly detectable bugs if `form-data` library implements only couple of
|
|
23
|
-
* methods that it misses, instead of implementing all of them.
|
|
24
|
-
* Current solution will fail the tests to let us know that form-data library
|
|
25
|
-
* already implements some of the methods that we try to monkey-patch, and our
|
|
26
|
-
* monkey-patch code should then compensate the library changes easily.
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if ((0, _isFunction.default)(FormData.prototype.set) || (0, _isFunction.default)(FormData.prototype.get) || (0, _isFunction.default)(FormData.prototype.getAll) || (0, _isFunction.default)(FormData.prototype.has)) {
|
|
31
|
-
return FormData;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
class PatchedFormData extends FormData {
|
|
35
|
-
constructor(form) {
|
|
36
|
-
super(form);
|
|
37
|
-
this.entryList = [];
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
append(field, value, options) {
|
|
41
|
-
this.entryList.push(createEntry(field, value));
|
|
42
|
-
return super.append(field, value, options);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
set(field, value) {
|
|
46
|
-
const newEntry = createEntry(field, value);
|
|
47
|
-
this.entryList = this.entryList.filter(entry => entry.name !== field);
|
|
48
|
-
this.entryList.push(newEntry);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
get(field) {
|
|
52
|
-
const foundEntry = this.entryList.find(entry => entry.name === field);
|
|
53
|
-
return foundEntry === undefined ? null : foundEntry;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
getAll(field) {
|
|
57
|
-
return this.entryList.filter(entry => entry.name === field).map(entry => entry.value);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
has(field) {
|
|
61
|
-
return this.entryList.some(entry => entry.name === field);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return PatchedFormData;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
exports.patch = patch;
|
|
70
|
-
|
|
71
|
-
var _default = patch(_isomorphicFormData.default);
|
|
72
|
-
|
|
73
|
-
exports.default = _default;
|