@common.js/node-fetch 3.3.2
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/@types/index.d.ts +219 -0
- package/LICENSE.md +22 -0
- package/README.md +5 -0
- package/package.json +117 -0
- package/src/body.js +902 -0
- package/src/errors/abort-error.js +93 -0
- package/src/errors/base.js +181 -0
- package/src/errors/fetch-error.js +100 -0
- package/src/headers.js +737 -0
- package/src/index.js +602 -0
- package/src/request.js +434 -0
- package/src/response.js +382 -0
- package/src/utils/get-search.js +18 -0
- package/src/utils/is-redirect.js +20 -0
- package/src/utils/is.js +51 -0
- package/src/utils/multipart-parser.js +661 -0
- package/src/utils/referrer.js +272 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "AbortError", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return AbortError;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
var _baseJs = require("./base.js");
|
|
12
|
+
function _assertThisInitialized(self) {
|
|
13
|
+
if (self === void 0) {
|
|
14
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
15
|
+
}
|
|
16
|
+
return self;
|
|
17
|
+
}
|
|
18
|
+
function _classCallCheck(instance, Constructor) {
|
|
19
|
+
if (!(instance instanceof Constructor)) {
|
|
20
|
+
throw new TypeError("Cannot call a class as a function");
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function _getPrototypeOf(o) {
|
|
24
|
+
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
|
|
25
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
26
|
+
};
|
|
27
|
+
return _getPrototypeOf(o);
|
|
28
|
+
}
|
|
29
|
+
function _inherits(subClass, superClass) {
|
|
30
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
31
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
32
|
+
}
|
|
33
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
34
|
+
constructor: {
|
|
35
|
+
value: subClass,
|
|
36
|
+
writable: true,
|
|
37
|
+
configurable: true
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
if (superClass) _setPrototypeOf(subClass, superClass);
|
|
41
|
+
}
|
|
42
|
+
function _possibleConstructorReturn(self, call) {
|
|
43
|
+
if (call && (_typeof(call) === "object" || typeof call === "function")) {
|
|
44
|
+
return call;
|
|
45
|
+
}
|
|
46
|
+
return _assertThisInitialized(self);
|
|
47
|
+
}
|
|
48
|
+
function _setPrototypeOf(o, p) {
|
|
49
|
+
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
|
|
50
|
+
o.__proto__ = p;
|
|
51
|
+
return o;
|
|
52
|
+
};
|
|
53
|
+
return _setPrototypeOf(o, p);
|
|
54
|
+
}
|
|
55
|
+
var _typeof = function(obj) {
|
|
56
|
+
"@swc/helpers - typeof";
|
|
57
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
58
|
+
};
|
|
59
|
+
function _isNativeReflectConstruct() {
|
|
60
|
+
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
61
|
+
if (Reflect.construct.sham) return false;
|
|
62
|
+
if (typeof Proxy === "function") return true;
|
|
63
|
+
try {
|
|
64
|
+
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
65
|
+
return true;
|
|
66
|
+
} catch (e) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function _createSuper(Derived) {
|
|
71
|
+
var hasNativeReflectConstruct = _isNativeReflectConstruct();
|
|
72
|
+
return function _createSuperInternal() {
|
|
73
|
+
var Super = _getPrototypeOf(Derived), result;
|
|
74
|
+
if (hasNativeReflectConstruct) {
|
|
75
|
+
var NewTarget = _getPrototypeOf(this).constructor;
|
|
76
|
+
result = Reflect.construct(Super, arguments, NewTarget);
|
|
77
|
+
} else {
|
|
78
|
+
result = Super.apply(this, arguments);
|
|
79
|
+
}
|
|
80
|
+
return _possibleConstructorReturn(this, result);
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
var AbortError = /*#__PURE__*/ function(FetchBaseError) {
|
|
84
|
+
"use strict";
|
|
85
|
+
_inherits(AbortError, FetchBaseError);
|
|
86
|
+
var _super = _createSuper(AbortError);
|
|
87
|
+
function AbortError(message) {
|
|
88
|
+
var type = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "aborted";
|
|
89
|
+
_classCallCheck(this, AbortError);
|
|
90
|
+
return _super.call(this, message, type);
|
|
91
|
+
}
|
|
92
|
+
return AbortError;
|
|
93
|
+
}(_baseJs.FetchBaseError);
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "FetchBaseError", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return FetchBaseError;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
function _assertThisInitialized(self) {
|
|
12
|
+
if (self === void 0) {
|
|
13
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
14
|
+
}
|
|
15
|
+
return self;
|
|
16
|
+
}
|
|
17
|
+
function _classCallCheck(instance, Constructor) {
|
|
18
|
+
if (!(instance instanceof Constructor)) {
|
|
19
|
+
throw new TypeError("Cannot call a class as a function");
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function isNativeReflectConstruct() {
|
|
23
|
+
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
24
|
+
if (Reflect.construct.sham) return false;
|
|
25
|
+
if (typeof Proxy === "function") return true;
|
|
26
|
+
try {
|
|
27
|
+
Date.prototype.toString.call(Reflect.construct(Date, [], function() {}));
|
|
28
|
+
return true;
|
|
29
|
+
} catch (e) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function _construct(Parent, args, Class) {
|
|
34
|
+
if (isNativeReflectConstruct()) {
|
|
35
|
+
_construct = Reflect.construct;
|
|
36
|
+
} else {
|
|
37
|
+
_construct = function _construct(Parent, args, Class) {
|
|
38
|
+
var a = [
|
|
39
|
+
null
|
|
40
|
+
];
|
|
41
|
+
a.push.apply(a, args);
|
|
42
|
+
var Constructor = Function.bind.apply(Parent, a);
|
|
43
|
+
var instance = new Constructor();
|
|
44
|
+
if (Class) _setPrototypeOf(instance, Class.prototype);
|
|
45
|
+
return instance;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return _construct.apply(null, arguments);
|
|
49
|
+
}
|
|
50
|
+
function _defineProperties(target, props) {
|
|
51
|
+
for(var i = 0; i < props.length; i++){
|
|
52
|
+
var descriptor = props[i];
|
|
53
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
54
|
+
descriptor.configurable = true;
|
|
55
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
56
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
60
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
61
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
62
|
+
return Constructor;
|
|
63
|
+
}
|
|
64
|
+
function _getPrototypeOf(o) {
|
|
65
|
+
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
|
|
66
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
67
|
+
};
|
|
68
|
+
return _getPrototypeOf(o);
|
|
69
|
+
}
|
|
70
|
+
function _inherits(subClass, superClass) {
|
|
71
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
72
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
73
|
+
}
|
|
74
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
75
|
+
constructor: {
|
|
76
|
+
value: subClass,
|
|
77
|
+
writable: true,
|
|
78
|
+
configurable: true
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
if (superClass) _setPrototypeOf(subClass, superClass);
|
|
82
|
+
}
|
|
83
|
+
function _isNativeFunction(fn) {
|
|
84
|
+
return Function.toString.call(fn).indexOf("[native code]") !== -1;
|
|
85
|
+
}
|
|
86
|
+
function _possibleConstructorReturn(self, call) {
|
|
87
|
+
if (call && (_typeof(call) === "object" || typeof call === "function")) {
|
|
88
|
+
return call;
|
|
89
|
+
}
|
|
90
|
+
return _assertThisInitialized(self);
|
|
91
|
+
}
|
|
92
|
+
function _setPrototypeOf(o, p) {
|
|
93
|
+
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
|
|
94
|
+
o.__proto__ = p;
|
|
95
|
+
return o;
|
|
96
|
+
};
|
|
97
|
+
return _setPrototypeOf(o, p);
|
|
98
|
+
}
|
|
99
|
+
var _typeof = function(obj) {
|
|
100
|
+
"@swc/helpers - typeof";
|
|
101
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
102
|
+
};
|
|
103
|
+
function _wrapNativeSuper(Class) {
|
|
104
|
+
var _cache = typeof Map === "function" ? new Map() : undefined;
|
|
105
|
+
_wrapNativeSuper = function _wrapNativeSuper(Class) {
|
|
106
|
+
if (Class === null || !_isNativeFunction(Class)) return Class;
|
|
107
|
+
if (typeof Class !== "function") {
|
|
108
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
109
|
+
}
|
|
110
|
+
if (typeof _cache !== "undefined") {
|
|
111
|
+
if (_cache.has(Class)) return _cache.get(Class);
|
|
112
|
+
_cache.set(Class, Wrapper);
|
|
113
|
+
}
|
|
114
|
+
function Wrapper() {
|
|
115
|
+
return _construct(Class, arguments, _getPrototypeOf(this).constructor);
|
|
116
|
+
}
|
|
117
|
+
Wrapper.prototype = Object.create(Class.prototype, {
|
|
118
|
+
constructor: {
|
|
119
|
+
value: Wrapper,
|
|
120
|
+
enumerable: false,
|
|
121
|
+
writable: true,
|
|
122
|
+
configurable: true
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
return _setPrototypeOf(Wrapper, Class);
|
|
126
|
+
};
|
|
127
|
+
return _wrapNativeSuper(Class);
|
|
128
|
+
}
|
|
129
|
+
function _isNativeReflectConstruct() {
|
|
130
|
+
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
131
|
+
if (Reflect.construct.sham) return false;
|
|
132
|
+
if (typeof Proxy === "function") return true;
|
|
133
|
+
try {
|
|
134
|
+
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
135
|
+
return true;
|
|
136
|
+
} catch (e) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function _createSuper(Derived) {
|
|
141
|
+
var hasNativeReflectConstruct = _isNativeReflectConstruct();
|
|
142
|
+
return function _createSuperInternal() {
|
|
143
|
+
var Super = _getPrototypeOf(Derived), result;
|
|
144
|
+
if (hasNativeReflectConstruct) {
|
|
145
|
+
var NewTarget = _getPrototypeOf(this).constructor;
|
|
146
|
+
result = Reflect.construct(Super, arguments, NewTarget);
|
|
147
|
+
} else {
|
|
148
|
+
result = Super.apply(this, arguments);
|
|
149
|
+
}
|
|
150
|
+
return _possibleConstructorReturn(this, result);
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
var FetchBaseError = /*#__PURE__*/ function(Error1) {
|
|
154
|
+
"use strict";
|
|
155
|
+
_inherits(FetchBaseError, Error1);
|
|
156
|
+
var _super = _createSuper(FetchBaseError);
|
|
157
|
+
function FetchBaseError(message, type) {
|
|
158
|
+
_classCallCheck(this, FetchBaseError);
|
|
159
|
+
var _this;
|
|
160
|
+
_this = _super.call(this, message);
|
|
161
|
+
// Hide custom error implementation details from end-users
|
|
162
|
+
Error.captureStackTrace(_assertThisInitialized(_this), _this.constructor);
|
|
163
|
+
_this.type = type;
|
|
164
|
+
return _this;
|
|
165
|
+
}
|
|
166
|
+
_createClass(FetchBaseError, [
|
|
167
|
+
{
|
|
168
|
+
key: "name",
|
|
169
|
+
get: function get() {
|
|
170
|
+
return this.constructor.name;
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
key: Symbol.toStringTag,
|
|
175
|
+
get: function get() {
|
|
176
|
+
return this.constructor.name;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
]);
|
|
180
|
+
return FetchBaseError;
|
|
181
|
+
}(_wrapNativeSuper(Error));
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "FetchError", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return FetchError;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
var _baseJs = require("./base.js");
|
|
12
|
+
function _assertThisInitialized(self) {
|
|
13
|
+
if (self === void 0) {
|
|
14
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
15
|
+
}
|
|
16
|
+
return self;
|
|
17
|
+
}
|
|
18
|
+
function _classCallCheck(instance, Constructor) {
|
|
19
|
+
if (!(instance instanceof Constructor)) {
|
|
20
|
+
throw new TypeError("Cannot call a class as a function");
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function _getPrototypeOf(o) {
|
|
24
|
+
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
|
|
25
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
26
|
+
};
|
|
27
|
+
return _getPrototypeOf(o);
|
|
28
|
+
}
|
|
29
|
+
function _inherits(subClass, superClass) {
|
|
30
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
31
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
32
|
+
}
|
|
33
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
34
|
+
constructor: {
|
|
35
|
+
value: subClass,
|
|
36
|
+
writable: true,
|
|
37
|
+
configurable: true
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
if (superClass) _setPrototypeOf(subClass, superClass);
|
|
41
|
+
}
|
|
42
|
+
function _possibleConstructorReturn(self, call) {
|
|
43
|
+
if (call && (_typeof(call) === "object" || typeof call === "function")) {
|
|
44
|
+
return call;
|
|
45
|
+
}
|
|
46
|
+
return _assertThisInitialized(self);
|
|
47
|
+
}
|
|
48
|
+
function _setPrototypeOf(o, p) {
|
|
49
|
+
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
|
|
50
|
+
o.__proto__ = p;
|
|
51
|
+
return o;
|
|
52
|
+
};
|
|
53
|
+
return _setPrototypeOf(o, p);
|
|
54
|
+
}
|
|
55
|
+
var _typeof = function(obj) {
|
|
56
|
+
"@swc/helpers - typeof";
|
|
57
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
58
|
+
};
|
|
59
|
+
function _isNativeReflectConstruct() {
|
|
60
|
+
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
61
|
+
if (Reflect.construct.sham) return false;
|
|
62
|
+
if (typeof Proxy === "function") return true;
|
|
63
|
+
try {
|
|
64
|
+
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
65
|
+
return true;
|
|
66
|
+
} catch (e) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function _createSuper(Derived) {
|
|
71
|
+
var hasNativeReflectConstruct = _isNativeReflectConstruct();
|
|
72
|
+
return function _createSuperInternal() {
|
|
73
|
+
var Super = _getPrototypeOf(Derived), result;
|
|
74
|
+
if (hasNativeReflectConstruct) {
|
|
75
|
+
var NewTarget = _getPrototypeOf(this).constructor;
|
|
76
|
+
result = Reflect.construct(Super, arguments, NewTarget);
|
|
77
|
+
} else {
|
|
78
|
+
result = Super.apply(this, arguments);
|
|
79
|
+
}
|
|
80
|
+
return _possibleConstructorReturn(this, result);
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
var FetchError = /*#__PURE__*/ function(FetchBaseError) {
|
|
84
|
+
"use strict";
|
|
85
|
+
_inherits(FetchError, FetchBaseError);
|
|
86
|
+
var _super = _createSuper(FetchError);
|
|
87
|
+
function FetchError(message, type, systemError) {
|
|
88
|
+
_classCallCheck(this, FetchError);
|
|
89
|
+
var _this;
|
|
90
|
+
_this = _super.call(this, message, type);
|
|
91
|
+
// When err.type is `system`, err.erroredSysCall contains system error and err.code contains system error code
|
|
92
|
+
if (systemError) {
|
|
93
|
+
// eslint-disable-next-line no-multi-assign
|
|
94
|
+
_this.code = _this.errno = systemError.code;
|
|
95
|
+
_this.erroredSysCall = systemError.syscall;
|
|
96
|
+
}
|
|
97
|
+
return _this;
|
|
98
|
+
}
|
|
99
|
+
return FetchError;
|
|
100
|
+
}(_baseJs.FetchBaseError);
|