@nestia/fetcher 1.3.3 → 1.3.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/lib/AesPkcs5.d.ts +30 -30
- package/lib/AesPkcs5.js +48 -48
- package/lib/AesPkcs5.js.map +1 -1
- package/lib/Fetcher.d.ts +72 -72
- package/lib/Fetcher.js +190 -190
- package/lib/HttpError.d.ts +46 -46
- package/lib/HttpError.js +80 -80
- package/lib/IConnection.d.ts +46 -54
- package/lib/IConnection.js +2 -2
- package/lib/IEncryptionPassword.d.ts +46 -46
- package/lib/IEncryptionPassword.js +2 -2
- package/lib/IRandomGenerator.d.ts +32 -32
- package/lib/IRandomGenerator.js +2 -2
- package/lib/Primitive.d.ts +54 -54
- package/lib/Primitive.js +2 -2
- package/lib/index.d.ts +6 -6
- package/lib/index.js +22 -22
- package/lib/internal/Singleton.d.ts +1 -1
- package/lib/internal/Singleton.js +23 -23
- package/package.json +2 -2
- package/src/IConnection.ts +0 -9
package/lib/Fetcher.js
CHANGED
|
@@ -1,191 +1,191 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
-
};
|
|
52
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
-
exports.Fetcher = void 0;
|
|
54
|
-
var import2_1 = __importDefault(require("import2"));
|
|
55
|
-
var AesPkcs5_1 = require("./AesPkcs5");
|
|
56
|
-
var HttpError_1 = require("./HttpError");
|
|
57
|
-
var Singleton_1 = require("./internal/Singleton");
|
|
58
|
-
/**
|
|
59
|
-
* Fetcher, utility class for the [**Nestia**](https://github.com/samchon/nestia) fetch.
|
|
60
|
-
*
|
|
61
|
-
* `Fetcher` is a utility class providing the {@link Fetcher.fetch} functions who're being
|
|
62
|
-
* used by all of the SDK libraries, interacting with the remote HTTP servers, who are
|
|
63
|
-
* generated by the [**Nestia**](https://github.com/samchon/nestia).
|
|
64
|
-
*
|
|
65
|
-
* As this `Fetcher` be used only by the [**Nestia**](https://github.com/samchon/nestia)
|
|
66
|
-
* generated SDK libraries, you don't need to handle this class directly. It may only be
|
|
67
|
-
* appeared in the source codes of the [**Nestia**](https://github.com/samchon/nestia)
|
|
68
|
-
* generated SDK libraries.
|
|
69
|
-
*
|
|
70
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
71
|
-
*/
|
|
72
|
-
var Fetcher = /** @class */ (function () {
|
|
73
|
-
function Fetcher() {
|
|
74
|
-
}
|
|
75
|
-
Fetcher.fetch = function (connection, encrypted, method, path, input, stringify) {
|
|
76
|
-
var _a;
|
|
77
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
78
|
-
var init, url, response, text, content, ret;
|
|
79
|
-
return __generator(this, function (_b) {
|
|
80
|
-
switch (_b.label) {
|
|
81
|
-
case 0:
|
|
82
|
-
if (encrypted.request === true || encrypted.response === true)
|
|
83
|
-
if (connection.encryption === undefined)
|
|
84
|
-
throw new Error("Error on nestia.Fetcher.encrypt(): the encryption password has not been configured.");
|
|
85
|
-
init = {
|
|
86
|
-
method: method,
|
|
87
|
-
headers: encrypted.request === false &&
|
|
88
|
-
input !== undefined &&
|
|
89
|
-
typeof input === "object"
|
|
90
|
-
? __assign(__assign({}, connection.headers), { "Content-Type": "application/json" }) : (_a = connection.headers) !== null && _a !== void 0 ? _a : {},
|
|
91
|
-
};
|
|
92
|
-
if (encrypted.request || typeof input === "string")
|
|
93
|
-
init.headers["Content-Type"] =
|
|
94
|
-
"text/plain";
|
|
95
|
-
// REQUEST BODY (WITH ENCRYPTION)
|
|
96
|
-
if (input !== undefined)
|
|
97
|
-
init.body = (function () {
|
|
98
|
-
var json = (stringify !== null && stringify !== void 0 ? stringify : JSON.stringify)(input);
|
|
99
|
-
if (!encrypted.request)
|
|
100
|
-
return json;
|
|
101
|
-
var password = connection.encryption instanceof Function
|
|
102
|
-
? connection.encryption({
|
|
103
|
-
headers: init.headers,
|
|
104
|
-
body: json,
|
|
105
|
-
}, true)
|
|
106
|
-
: connection.encryption;
|
|
107
|
-
return AesPkcs5_1.AesPkcs5.encrypt(json, password.key, password.iv);
|
|
108
|
-
})();
|
|
109
|
-
//----
|
|
110
|
-
// RESPONSE MESSAGE
|
|
111
|
-
//----
|
|
112
|
-
// URL SPECIFICATION
|
|
113
|
-
if (connection.host[connection.host.length - 1] !== "/" &&
|
|
114
|
-
path[0] !== "/")
|
|
115
|
-
path = "/" + path;
|
|
116
|
-
url = new URL("".concat(connection.host).concat(path));
|
|
117
|
-
return [4 /*yield*/, polyfill.get()];
|
|
118
|
-
case 1: return [4 /*yield*/, (_b.sent())(url.href, init)];
|
|
119
|
-
case 2:
|
|
120
|
-
response = _b.sent();
|
|
121
|
-
return [4 /*yield*/, response.text()];
|
|
122
|
-
case 3:
|
|
123
|
-
text = _b.sent();
|
|
124
|
-
if (!text)
|
|
125
|
-
return [2 /*return*/, undefined];
|
|
126
|
-
// CHECK THE STATUS CODE
|
|
127
|
-
if ((encrypted.status !== undefined &&
|
|
128
|
-
response.status !== encrypted.status) ||
|
|
129
|
-
(encrypted.status === undefined &&
|
|
130
|
-
response.status !== 200 &&
|
|
131
|
-
response.status !== 201))
|
|
132
|
-
throw new HttpError_1.HttpError(method, path, response.status, text);
|
|
133
|
-
content = !encrypted.response
|
|
134
|
-
? text
|
|
135
|
-
: (function () {
|
|
136
|
-
var password = connection.encryption instanceof Function
|
|
137
|
-
? connection.encryption({
|
|
138
|
-
headers: headers_to_object(response.headers),
|
|
139
|
-
body: text,
|
|
140
|
-
}, false)
|
|
141
|
-
: connection.encryption;
|
|
142
|
-
return AesPkcs5_1.AesPkcs5.decrypt(text, password.key, password.iv);
|
|
143
|
-
})();
|
|
144
|
-
ret = content;
|
|
145
|
-
try {
|
|
146
|
-
// PARSE RESPONSE BODY
|
|
147
|
-
ret = JSON.parse(ret);
|
|
148
|
-
// FIND __SET_HEADERS__ FIELD
|
|
149
|
-
if (ret.__set_headers__ !== undefined &&
|
|
150
|
-
typeof ret.__set_headers__ === "object") {
|
|
151
|
-
if (connection.headers === undefined)
|
|
152
|
-
connection.headers = {};
|
|
153
|
-
Object.assign(connection.headers, ret.__set_headers__);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
catch (_c) { }
|
|
157
|
-
// RETURNS
|
|
158
|
-
return [2 /*return*/, ret];
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
};
|
|
163
|
-
return Fetcher;
|
|
164
|
-
}());
|
|
165
|
-
exports.Fetcher = Fetcher;
|
|
166
|
-
var polyfill = new Singleton_1.Singleton(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
167
|
-
var _a;
|
|
168
|
-
return __generator(this, function (_b) {
|
|
169
|
-
switch (_b.label) {
|
|
170
|
-
case 0:
|
|
171
|
-
if (!(typeof global === "object" &&
|
|
172
|
-
typeof global.process === "object" &&
|
|
173
|
-
typeof global.process.versions === "object" &&
|
|
174
|
-
typeof global.process.versions.node !== undefined)) return [3 /*break*/, 3];
|
|
175
|
-
if (!(global.fetch === undefined)) return [3 /*break*/, 2];
|
|
176
|
-
_a = global;
|
|
177
|
-
return [4 /*yield*/, (0, import2_1.default)("node-fetch")];
|
|
178
|
-
case 1:
|
|
179
|
-
_a.fetch = (_b.sent()).default;
|
|
180
|
-
_b.label = 2;
|
|
181
|
-
case 2: return [2 /*return*/, global.fetch];
|
|
182
|
-
case 3: return [2 /*return*/, window.fetch];
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
}); });
|
|
186
|
-
function headers_to_object(headers) {
|
|
187
|
-
var output = {};
|
|
188
|
-
headers.forEach(function (value, key) { return (output[key] = value); });
|
|
189
|
-
return output;
|
|
190
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
+
};
|
|
52
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
+
exports.Fetcher = void 0;
|
|
54
|
+
var import2_1 = __importDefault(require("import2"));
|
|
55
|
+
var AesPkcs5_1 = require("./AesPkcs5");
|
|
56
|
+
var HttpError_1 = require("./HttpError");
|
|
57
|
+
var Singleton_1 = require("./internal/Singleton");
|
|
58
|
+
/**
|
|
59
|
+
* Fetcher, utility class for the [**Nestia**](https://github.com/samchon/nestia) fetch.
|
|
60
|
+
*
|
|
61
|
+
* `Fetcher` is a utility class providing the {@link Fetcher.fetch} functions who're being
|
|
62
|
+
* used by all of the SDK libraries, interacting with the remote HTTP servers, who are
|
|
63
|
+
* generated by the [**Nestia**](https://github.com/samchon/nestia).
|
|
64
|
+
*
|
|
65
|
+
* As this `Fetcher` be used only by the [**Nestia**](https://github.com/samchon/nestia)
|
|
66
|
+
* generated SDK libraries, you don't need to handle this class directly. It may only be
|
|
67
|
+
* appeared in the source codes of the [**Nestia**](https://github.com/samchon/nestia)
|
|
68
|
+
* generated SDK libraries.
|
|
69
|
+
*
|
|
70
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
71
|
+
*/
|
|
72
|
+
var Fetcher = /** @class */ (function () {
|
|
73
|
+
function Fetcher() {
|
|
74
|
+
}
|
|
75
|
+
Fetcher.fetch = function (connection, encrypted, method, path, input, stringify) {
|
|
76
|
+
var _a;
|
|
77
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
78
|
+
var init, url, response, text, content, ret;
|
|
79
|
+
return __generator(this, function (_b) {
|
|
80
|
+
switch (_b.label) {
|
|
81
|
+
case 0:
|
|
82
|
+
if (encrypted.request === true || encrypted.response === true)
|
|
83
|
+
if (connection.encryption === undefined)
|
|
84
|
+
throw new Error("Error on nestia.Fetcher.encrypt(): the encryption password has not been configured.");
|
|
85
|
+
init = {
|
|
86
|
+
method: method,
|
|
87
|
+
headers: encrypted.request === false &&
|
|
88
|
+
input !== undefined &&
|
|
89
|
+
typeof input === "object"
|
|
90
|
+
? __assign(__assign({}, connection.headers), { "Content-Type": "application/json" }) : (_a = connection.headers) !== null && _a !== void 0 ? _a : {},
|
|
91
|
+
};
|
|
92
|
+
if (encrypted.request || typeof input === "string")
|
|
93
|
+
init.headers["Content-Type"] =
|
|
94
|
+
"text/plain";
|
|
95
|
+
// REQUEST BODY (WITH ENCRYPTION)
|
|
96
|
+
if (input !== undefined)
|
|
97
|
+
init.body = (function () {
|
|
98
|
+
var json = (stringify !== null && stringify !== void 0 ? stringify : JSON.stringify)(input);
|
|
99
|
+
if (!encrypted.request)
|
|
100
|
+
return json;
|
|
101
|
+
var password = connection.encryption instanceof Function
|
|
102
|
+
? connection.encryption({
|
|
103
|
+
headers: init.headers,
|
|
104
|
+
body: json,
|
|
105
|
+
}, true)
|
|
106
|
+
: connection.encryption;
|
|
107
|
+
return AesPkcs5_1.AesPkcs5.encrypt(json, password.key, password.iv);
|
|
108
|
+
})();
|
|
109
|
+
//----
|
|
110
|
+
// RESPONSE MESSAGE
|
|
111
|
+
//----
|
|
112
|
+
// URL SPECIFICATION
|
|
113
|
+
if (connection.host[connection.host.length - 1] !== "/" &&
|
|
114
|
+
path[0] !== "/")
|
|
115
|
+
path = "/" + path;
|
|
116
|
+
url = new URL("".concat(connection.host).concat(path));
|
|
117
|
+
return [4 /*yield*/, polyfill.get()];
|
|
118
|
+
case 1: return [4 /*yield*/, (_b.sent())(url.href, init)];
|
|
119
|
+
case 2:
|
|
120
|
+
response = _b.sent();
|
|
121
|
+
return [4 /*yield*/, response.text()];
|
|
122
|
+
case 3:
|
|
123
|
+
text = _b.sent();
|
|
124
|
+
if (!text)
|
|
125
|
+
return [2 /*return*/, undefined];
|
|
126
|
+
// CHECK THE STATUS CODE
|
|
127
|
+
if ((encrypted.status !== undefined &&
|
|
128
|
+
response.status !== encrypted.status) ||
|
|
129
|
+
(encrypted.status === undefined &&
|
|
130
|
+
response.status !== 200 &&
|
|
131
|
+
response.status !== 201))
|
|
132
|
+
throw new HttpError_1.HttpError(method, path, response.status, text);
|
|
133
|
+
content = !encrypted.response
|
|
134
|
+
? text
|
|
135
|
+
: (function () {
|
|
136
|
+
var password = connection.encryption instanceof Function
|
|
137
|
+
? connection.encryption({
|
|
138
|
+
headers: headers_to_object(response.headers),
|
|
139
|
+
body: text,
|
|
140
|
+
}, false)
|
|
141
|
+
: connection.encryption;
|
|
142
|
+
return AesPkcs5_1.AesPkcs5.decrypt(text, password.key, password.iv);
|
|
143
|
+
})();
|
|
144
|
+
ret = content;
|
|
145
|
+
try {
|
|
146
|
+
// PARSE RESPONSE BODY
|
|
147
|
+
ret = JSON.parse(ret);
|
|
148
|
+
// FIND __SET_HEADERS__ FIELD
|
|
149
|
+
if (ret.__set_headers__ !== undefined &&
|
|
150
|
+
typeof ret.__set_headers__ === "object") {
|
|
151
|
+
if (connection.headers === undefined)
|
|
152
|
+
connection.headers = {};
|
|
153
|
+
Object.assign(connection.headers, ret.__set_headers__);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
catch (_c) { }
|
|
157
|
+
// RETURNS
|
|
158
|
+
return [2 /*return*/, ret];
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
return Fetcher;
|
|
164
|
+
}());
|
|
165
|
+
exports.Fetcher = Fetcher;
|
|
166
|
+
var polyfill = new Singleton_1.Singleton(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
167
|
+
var _a;
|
|
168
|
+
return __generator(this, function (_b) {
|
|
169
|
+
switch (_b.label) {
|
|
170
|
+
case 0:
|
|
171
|
+
if (!(typeof global === "object" &&
|
|
172
|
+
typeof global.process === "object" &&
|
|
173
|
+
typeof global.process.versions === "object" &&
|
|
174
|
+
typeof global.process.versions.node !== undefined)) return [3 /*break*/, 3];
|
|
175
|
+
if (!(global.fetch === undefined)) return [3 /*break*/, 2];
|
|
176
|
+
_a = global;
|
|
177
|
+
return [4 /*yield*/, (0, import2_1.default)("node-fetch")];
|
|
178
|
+
case 1:
|
|
179
|
+
_a.fetch = (_b.sent()).default;
|
|
180
|
+
_b.label = 2;
|
|
181
|
+
case 2: return [2 /*return*/, global.fetch];
|
|
182
|
+
case 3: return [2 /*return*/, window.fetch];
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
}); });
|
|
186
|
+
function headers_to_object(headers) {
|
|
187
|
+
var output = {};
|
|
188
|
+
headers.forEach(function (value, key) { return (output[key] = value); });
|
|
189
|
+
return output;
|
|
190
|
+
}
|
|
191
191
|
//# sourceMappingURL=Fetcher.js.map
|
package/lib/HttpError.d.ts
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HTTP Error.
|
|
3
|
-
*
|
|
4
|
-
* `HttpError` is a type of error class who've been thrown by the remote HTTP server.
|
|
5
|
-
*
|
|
6
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
7
|
-
*/
|
|
8
|
-
export declare class HttpError extends Error {
|
|
9
|
-
readonly method: "GET" | "DELETE" | "POST" | "PUT" | "PATCH";
|
|
10
|
-
readonly path: string;
|
|
11
|
-
readonly status: number;
|
|
12
|
-
/**
|
|
13
|
-
* Initializer Constructor.
|
|
14
|
-
*
|
|
15
|
-
* @param method Method of the HTTP request.
|
|
16
|
-
* @param path Path of the HTTP request.
|
|
17
|
-
* @param status Status code from the remote HTTP server.
|
|
18
|
-
* @param message Error message from the remote HTTP server.
|
|
19
|
-
*/
|
|
20
|
-
constructor(method: "GET" | "DELETE" | "POST" | "PUT" | "PATCH", path: string, status: number, message: string);
|
|
21
|
-
/**
|
|
22
|
-
* `HttpError` to JSON.
|
|
23
|
-
*
|
|
24
|
-
* When you call `JSON.stringify()` function on current `HttpError` instance,
|
|
25
|
-
* this `HttpError.toJSON()` method would be automatically called.
|
|
26
|
-
*
|
|
27
|
-
* Also, if response body from the remote HTTP server forms a JSON object,
|
|
28
|
-
* this `HttpError.toJSON()` method would be useful because it returns the
|
|
29
|
-
* parsed JSON object about the {@link message} property.
|
|
30
|
-
*
|
|
31
|
-
* @template T Expected type of the response body.
|
|
32
|
-
* @returns JSON object of the `HttpError`.
|
|
33
|
-
*/
|
|
34
|
-
toJSON<T>(): HttpError.IProps<T>;
|
|
35
|
-
}
|
|
36
|
-
export declare namespace HttpError {
|
|
37
|
-
/**
|
|
38
|
-
* Returned type of {@link HttpError.toJSON} method.
|
|
39
|
-
*/
|
|
40
|
-
interface IProps<T> {
|
|
41
|
-
method: "GET" | "DELETE" | "POST" | "PUT" | "PATCH";
|
|
42
|
-
path: string;
|
|
43
|
-
status: number;
|
|
44
|
-
message: T;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* HTTP Error.
|
|
3
|
+
*
|
|
4
|
+
* `HttpError` is a type of error class who've been thrown by the remote HTTP server.
|
|
5
|
+
*
|
|
6
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
7
|
+
*/
|
|
8
|
+
export declare class HttpError extends Error {
|
|
9
|
+
readonly method: "GET" | "DELETE" | "POST" | "PUT" | "PATCH";
|
|
10
|
+
readonly path: string;
|
|
11
|
+
readonly status: number;
|
|
12
|
+
/**
|
|
13
|
+
* Initializer Constructor.
|
|
14
|
+
*
|
|
15
|
+
* @param method Method of the HTTP request.
|
|
16
|
+
* @param path Path of the HTTP request.
|
|
17
|
+
* @param status Status code from the remote HTTP server.
|
|
18
|
+
* @param message Error message from the remote HTTP server.
|
|
19
|
+
*/
|
|
20
|
+
constructor(method: "GET" | "DELETE" | "POST" | "PUT" | "PATCH", path: string, status: number, message: string);
|
|
21
|
+
/**
|
|
22
|
+
* `HttpError` to JSON.
|
|
23
|
+
*
|
|
24
|
+
* When you call `JSON.stringify()` function on current `HttpError` instance,
|
|
25
|
+
* this `HttpError.toJSON()` method would be automatically called.
|
|
26
|
+
*
|
|
27
|
+
* Also, if response body from the remote HTTP server forms a JSON object,
|
|
28
|
+
* this `HttpError.toJSON()` method would be useful because it returns the
|
|
29
|
+
* parsed JSON object about the {@link message} property.
|
|
30
|
+
*
|
|
31
|
+
* @template T Expected type of the response body.
|
|
32
|
+
* @returns JSON object of the `HttpError`.
|
|
33
|
+
*/
|
|
34
|
+
toJSON<T>(): HttpError.IProps<T>;
|
|
35
|
+
}
|
|
36
|
+
export declare namespace HttpError {
|
|
37
|
+
/**
|
|
38
|
+
* Returned type of {@link HttpError.toJSON} method.
|
|
39
|
+
*/
|
|
40
|
+
interface IProps<T> {
|
|
41
|
+
method: "GET" | "DELETE" | "POST" | "PUT" | "PATCH";
|
|
42
|
+
path: string;
|
|
43
|
+
status: number;
|
|
44
|
+
message: T;
|
|
45
|
+
}
|
|
46
|
+
}
|
package/lib/HttpError.js
CHANGED
|
@@ -1,81 +1,81 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.HttpError = void 0;
|
|
19
|
-
/**
|
|
20
|
-
* HTTP Error.
|
|
21
|
-
*
|
|
22
|
-
* `HttpError` is a type of error class who've been thrown by the remote HTTP server.
|
|
23
|
-
*
|
|
24
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
25
|
-
*/
|
|
26
|
-
var HttpError = /** @class */ (function (_super) {
|
|
27
|
-
__extends(HttpError, _super);
|
|
28
|
-
/**
|
|
29
|
-
* Initializer Constructor.
|
|
30
|
-
*
|
|
31
|
-
* @param method Method of the HTTP request.
|
|
32
|
-
* @param path Path of the HTTP request.
|
|
33
|
-
* @param status Status code from the remote HTTP server.
|
|
34
|
-
* @param message Error message from the remote HTTP server.
|
|
35
|
-
*/
|
|
36
|
-
function HttpError(method, path, status, message) {
|
|
37
|
-
var _newTarget = this.constructor;
|
|
38
|
-
var _this = _super.call(this, message) || this;
|
|
39
|
-
_this.method = method;
|
|
40
|
-
_this.path = path;
|
|
41
|
-
_this.status = status;
|
|
42
|
-
/**
|
|
43
|
-
* @internal
|
|
44
|
-
*/
|
|
45
|
-
_this.body_ = NOT_YET;
|
|
46
|
-
// INHERITANCE POLYFILL
|
|
47
|
-
var proto = _newTarget.prototype;
|
|
48
|
-
if (Object.setPrototypeOf)
|
|
49
|
-
Object.setPrototypeOf(_this, proto);
|
|
50
|
-
else
|
|
51
|
-
_this.__proto__ = proto;
|
|
52
|
-
return _this;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* `HttpError` to JSON.
|
|
56
|
-
*
|
|
57
|
-
* When you call `JSON.stringify()` function on current `HttpError` instance,
|
|
58
|
-
* this `HttpError.toJSON()` method would be automatically called.
|
|
59
|
-
*
|
|
60
|
-
* Also, if response body from the remote HTTP server forms a JSON object,
|
|
61
|
-
* this `HttpError.toJSON()` method would be useful because it returns the
|
|
62
|
-
* parsed JSON object about the {@link message} property.
|
|
63
|
-
*
|
|
64
|
-
* @template T Expected type of the response body.
|
|
65
|
-
* @returns JSON object of the `HttpError`.
|
|
66
|
-
*/
|
|
67
|
-
HttpError.prototype.toJSON = function () {
|
|
68
|
-
if (this.body_ === NOT_YET)
|
|
69
|
-
this.body_ = JSON.parse(this.message);
|
|
70
|
-
return {
|
|
71
|
-
method: this.method,
|
|
72
|
-
path: this.path,
|
|
73
|
-
status: this.status,
|
|
74
|
-
message: this.body_,
|
|
75
|
-
};
|
|
76
|
-
};
|
|
77
|
-
return HttpError;
|
|
78
|
-
}(Error));
|
|
79
|
-
exports.HttpError = HttpError;
|
|
80
|
-
var NOT_YET = {};
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.HttpError = void 0;
|
|
19
|
+
/**
|
|
20
|
+
* HTTP Error.
|
|
21
|
+
*
|
|
22
|
+
* `HttpError` is a type of error class who've been thrown by the remote HTTP server.
|
|
23
|
+
*
|
|
24
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
25
|
+
*/
|
|
26
|
+
var HttpError = /** @class */ (function (_super) {
|
|
27
|
+
__extends(HttpError, _super);
|
|
28
|
+
/**
|
|
29
|
+
* Initializer Constructor.
|
|
30
|
+
*
|
|
31
|
+
* @param method Method of the HTTP request.
|
|
32
|
+
* @param path Path of the HTTP request.
|
|
33
|
+
* @param status Status code from the remote HTTP server.
|
|
34
|
+
* @param message Error message from the remote HTTP server.
|
|
35
|
+
*/
|
|
36
|
+
function HttpError(method, path, status, message) {
|
|
37
|
+
var _newTarget = this.constructor;
|
|
38
|
+
var _this = _super.call(this, message) || this;
|
|
39
|
+
_this.method = method;
|
|
40
|
+
_this.path = path;
|
|
41
|
+
_this.status = status;
|
|
42
|
+
/**
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
_this.body_ = NOT_YET;
|
|
46
|
+
// INHERITANCE POLYFILL
|
|
47
|
+
var proto = _newTarget.prototype;
|
|
48
|
+
if (Object.setPrototypeOf)
|
|
49
|
+
Object.setPrototypeOf(_this, proto);
|
|
50
|
+
else
|
|
51
|
+
_this.__proto__ = proto;
|
|
52
|
+
return _this;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* `HttpError` to JSON.
|
|
56
|
+
*
|
|
57
|
+
* When you call `JSON.stringify()` function on current `HttpError` instance,
|
|
58
|
+
* this `HttpError.toJSON()` method would be automatically called.
|
|
59
|
+
*
|
|
60
|
+
* Also, if response body from the remote HTTP server forms a JSON object,
|
|
61
|
+
* this `HttpError.toJSON()` method would be useful because it returns the
|
|
62
|
+
* parsed JSON object about the {@link message} property.
|
|
63
|
+
*
|
|
64
|
+
* @template T Expected type of the response body.
|
|
65
|
+
* @returns JSON object of the `HttpError`.
|
|
66
|
+
*/
|
|
67
|
+
HttpError.prototype.toJSON = function () {
|
|
68
|
+
if (this.body_ === NOT_YET)
|
|
69
|
+
this.body_ = JSON.parse(this.message);
|
|
70
|
+
return {
|
|
71
|
+
method: this.method,
|
|
72
|
+
path: this.path,
|
|
73
|
+
status: this.status,
|
|
74
|
+
message: this.body_,
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
return HttpError;
|
|
78
|
+
}(Error));
|
|
79
|
+
exports.HttpError = HttpError;
|
|
80
|
+
var NOT_YET = {};
|
|
81
81
|
//# sourceMappingURL=HttpError.js.map
|