@nestia/fetcher 1.3.4 → 1.4.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/lib/Fetcher.js +9 -12
- package/lib/Fetcher.js.map +1 -1
- package/lib/IConnection.d.ts +64 -0
- package/package.json +1 -1
- package/src/Fetcher.ts +1 -0
- package/src/IConnection.ts +87 -0
package/lib/Fetcher.js
CHANGED
|
@@ -73,22 +73,19 @@ var Fetcher = /** @class */ (function () {
|
|
|
73
73
|
function Fetcher() {
|
|
74
74
|
}
|
|
75
75
|
Fetcher.fetch = function (connection, encrypted, method, path, input, stringify) {
|
|
76
|
-
var _a;
|
|
76
|
+
var _a, _b;
|
|
77
77
|
return __awaiter(this, void 0, void 0, function () {
|
|
78
78
|
var init, url, response, text, content, ret;
|
|
79
|
-
return __generator(this, function (
|
|
80
|
-
switch (
|
|
79
|
+
return __generator(this, function (_c) {
|
|
80
|
+
switch (_c.label) {
|
|
81
81
|
case 0:
|
|
82
82
|
if (encrypted.request === true || encrypted.response === true)
|
|
83
83
|
if (connection.encryption === undefined)
|
|
84
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 &&
|
|
85
|
+
init = __assign(__assign({}, ((_a = connection.options) !== null && _a !== void 0 ? _a : {})), { method: method, headers: encrypted.request === false &&
|
|
88
86
|
input !== undefined &&
|
|
89
87
|
typeof input === "object"
|
|
90
|
-
? __assign(__assign({}, connection.headers), { "Content-Type": "application/json" }) : (
|
|
91
|
-
};
|
|
88
|
+
? __assign(__assign({}, connection.headers), { "Content-Type": "application/json" }) : (_b = connection.headers) !== null && _b !== void 0 ? _b : {} });
|
|
92
89
|
if (encrypted.request || typeof input === "string")
|
|
93
90
|
init.headers["Content-Type"] =
|
|
94
91
|
"text/plain";
|
|
@@ -115,12 +112,12 @@ var Fetcher = /** @class */ (function () {
|
|
|
115
112
|
path = "/" + path;
|
|
116
113
|
url = new URL("".concat(connection.host).concat(path));
|
|
117
114
|
return [4 /*yield*/, polyfill.get()];
|
|
118
|
-
case 1: return [4 /*yield*/, (
|
|
115
|
+
case 1: return [4 /*yield*/, (_c.sent())(url.href, init)];
|
|
119
116
|
case 2:
|
|
120
|
-
response =
|
|
117
|
+
response = _c.sent();
|
|
121
118
|
return [4 /*yield*/, response.text()];
|
|
122
119
|
case 3:
|
|
123
|
-
text =
|
|
120
|
+
text = _c.sent();
|
|
124
121
|
if (!text)
|
|
125
122
|
return [2 /*return*/, undefined];
|
|
126
123
|
// CHECK THE STATUS CODE
|
|
@@ -153,7 +150,7 @@ var Fetcher = /** @class */ (function () {
|
|
|
153
150
|
Object.assign(connection.headers, ret.__set_headers__);
|
|
154
151
|
}
|
|
155
152
|
}
|
|
156
|
-
catch (
|
|
153
|
+
catch (_d) { }
|
|
157
154
|
// RETURNS
|
|
158
155
|
return [2 /*return*/, ret];
|
|
159
156
|
}
|
package/lib/Fetcher.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Fetcher.js","sourceRoot":"","sources":["../src/Fetcher.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAA8B;AAM9B,uCAAsC;AACtC,yCAAwC;AACxC,kDAAiD;AAEjD;;;;;;;;;;;;;GAaG;AACH;IAAA;
|
|
1
|
+
{"version":3,"file":"Fetcher.js","sourceRoot":"","sources":["../src/Fetcher.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAA8B;AAM9B,uCAAsC;AACtC,yCAAwC;AACxC,kDAAiD;AAEjD;;;;;;;;;;;;;GAaG;AACH;IAAA;IAqKA,CAAC;IAhIuB,aAAK,GAAzB,UACI,UAAuB,EACvB,SAA6B,EAC7B,MAAmD,EACnD,IAAY,EAC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A;;gBAA5C,GAAO,KAAK,GAAI,CAAC,SAA2B,CAAS,CAAC,OAAO,CAAC;;oBAClE,sBAAQ,MAAc,CAAC,KAAK,EAAC;oBAEjC,sBAAO,MAAM,CAAC,KAAK,EAAC;;;KACvB,CAAC,CAAC;AAEH,SAAS,iBAAiB,CAAC,OAAgB;IACvC,IAAM,MAAM,GAA2B,EAAE,CAAC;IAC1C,OAAO,CAAC,OAAO,CAAC,UAAC,KAAK,EAAE,GAAG,IAAK,OAAA,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,EAArB,CAAqB,CAAC,CAAC;IACvD,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
package/lib/IConnection.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { IRandomGenerator } from "./IRandomGenerator";
|
|
|
13
13
|
* or {@link IEncryptionPassword.Closure} variable.
|
|
14
14
|
*
|
|
15
15
|
* @author Jenogho Nam - https://github.com/samchon
|
|
16
|
+
* @author Seungjun We - https://github.com/SeungjunWe
|
|
16
17
|
*/
|
|
17
18
|
export interface IConnection {
|
|
18
19
|
/**
|
|
@@ -43,4 +44,67 @@ export interface IConnection {
|
|
|
43
44
|
* @default false
|
|
44
45
|
*/
|
|
45
46
|
simulate?: boolean | Partial<IRandomGenerator>;
|
|
47
|
+
/**
|
|
48
|
+
* Additional options for the `fetch` function.
|
|
49
|
+
*/
|
|
50
|
+
options?: IConnection.IOptions;
|
|
51
|
+
}
|
|
52
|
+
export declare namespace IConnection {
|
|
53
|
+
/**
|
|
54
|
+
* Addiotional options for the `fetch` function.
|
|
55
|
+
*
|
|
56
|
+
* Almost same with {@link RequestInit} type of the {@link fetch} function,
|
|
57
|
+
* but `body`, `headers` and `method` properties are omitted.
|
|
58
|
+
*
|
|
59
|
+
* The reason why defining duplicated definition of {@link RequestInit}
|
|
60
|
+
* is for legacy NodeJS environments, which does not have the {@link fetch}
|
|
61
|
+
* function type.
|
|
62
|
+
*/
|
|
63
|
+
interface IOptions {
|
|
64
|
+
/**
|
|
65
|
+
* A string indicating how the request will interact with the browser's
|
|
66
|
+
* cache to set request's cache.
|
|
67
|
+
*/
|
|
68
|
+
cache?: "default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload";
|
|
69
|
+
/**
|
|
70
|
+
* A string indicating whether credentials will be sent with the request
|
|
71
|
+
* always, never, or only when sent to a same-origin URL. Sets request's
|
|
72
|
+
* credentials.
|
|
73
|
+
*/
|
|
74
|
+
credentials?: "omit" | "same-origin" | "include";
|
|
75
|
+
/**
|
|
76
|
+
* A cryptographic hash of the resource to be fetched by request.
|
|
77
|
+
*
|
|
78
|
+
* Sets request's integrity.
|
|
79
|
+
*/
|
|
80
|
+
integrity?: string;
|
|
81
|
+
/**
|
|
82
|
+
* A boolean to set request's keepalive.
|
|
83
|
+
*/
|
|
84
|
+
keepalive?: boolean;
|
|
85
|
+
/**
|
|
86
|
+
* A string to indicate whether the request will use CORS, or will be
|
|
87
|
+
* restricted to same-origin URLs.
|
|
88
|
+
*
|
|
89
|
+
* Sets request's mode.
|
|
90
|
+
*/
|
|
91
|
+
mode?: "cors" | "navigate" | "no-cors" | "same-origin";
|
|
92
|
+
/**
|
|
93
|
+
* A string indicating whether request follows redirects, results in
|
|
94
|
+
* an error upon encountering a redirect, or returns the redirect
|
|
95
|
+
* (in an opaque fashion).
|
|
96
|
+
*
|
|
97
|
+
* Sets request's redirect.
|
|
98
|
+
*/
|
|
99
|
+
redirect?: "error" | "follow" | "manual";
|
|
100
|
+
/**
|
|
101
|
+
* A string whose value is a same-origin URL, "about:client", or the
|
|
102
|
+
* empty string, to set request's referrer.
|
|
103
|
+
*/
|
|
104
|
+
referrer?: string;
|
|
105
|
+
/**
|
|
106
|
+
* A referrer policy to set request's referrerPolicy.
|
|
107
|
+
*/
|
|
108
|
+
referrerPolicy?: "" | "no-referrer" | "no-referrer-when-downgrade" | "origin" | "origin-when-cross-origin" | "same-origin" | "strict-origin" | "strict-origin-when-cross-origin" | "unsafe-url";
|
|
109
|
+
}
|
|
46
110
|
}
|
package/package.json
CHANGED
package/src/Fetcher.ts
CHANGED
package/src/IConnection.ts
CHANGED
|
@@ -14,6 +14,7 @@ import { IRandomGenerator } from "./IRandomGenerator";
|
|
|
14
14
|
* or {@link IEncryptionPassword.Closure} variable.
|
|
15
15
|
*
|
|
16
16
|
* @author Jenogho Nam - https://github.com/samchon
|
|
17
|
+
* @author Seungjun We - https://github.com/SeungjunWe
|
|
17
18
|
*/
|
|
18
19
|
export interface IConnection {
|
|
19
20
|
/**
|
|
@@ -47,4 +48,90 @@ export interface IConnection {
|
|
|
47
48
|
* @default false
|
|
48
49
|
*/
|
|
49
50
|
simulate?: boolean | Partial<IRandomGenerator>;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Additional options for the `fetch` function.
|
|
54
|
+
*/
|
|
55
|
+
options?: IConnection.IOptions;
|
|
56
|
+
}
|
|
57
|
+
export namespace IConnection {
|
|
58
|
+
/**
|
|
59
|
+
* Addiotional options for the `fetch` function.
|
|
60
|
+
*
|
|
61
|
+
* Almost same with {@link RequestInit} type of the {@link fetch} function,
|
|
62
|
+
* but `body`, `headers` and `method` properties are omitted.
|
|
63
|
+
*
|
|
64
|
+
* The reason why defining duplicated definition of {@link RequestInit}
|
|
65
|
+
* is for legacy NodeJS environments, which does not have the {@link fetch}
|
|
66
|
+
* function type.
|
|
67
|
+
*/
|
|
68
|
+
export interface IOptions {
|
|
69
|
+
/**
|
|
70
|
+
* A string indicating how the request will interact with the browser's
|
|
71
|
+
* cache to set request's cache.
|
|
72
|
+
*/
|
|
73
|
+
cache?:
|
|
74
|
+
| "default"
|
|
75
|
+
| "force-cache"
|
|
76
|
+
| "no-cache"
|
|
77
|
+
| "no-store"
|
|
78
|
+
| "only-if-cached"
|
|
79
|
+
| "reload";
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* A string indicating whether credentials will be sent with the request
|
|
83
|
+
* always, never, or only when sent to a same-origin URL. Sets request's
|
|
84
|
+
* credentials.
|
|
85
|
+
*/
|
|
86
|
+
credentials?: "omit" | "same-origin" | "include";
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* A cryptographic hash of the resource to be fetched by request.
|
|
90
|
+
*
|
|
91
|
+
* Sets request's integrity.
|
|
92
|
+
*/
|
|
93
|
+
integrity?: string;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* A boolean to set request's keepalive.
|
|
97
|
+
*/
|
|
98
|
+
keepalive?: boolean;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* A string to indicate whether the request will use CORS, or will be
|
|
102
|
+
* restricted to same-origin URLs.
|
|
103
|
+
*
|
|
104
|
+
* Sets request's mode.
|
|
105
|
+
*/
|
|
106
|
+
mode?: "cors" | "navigate" | "no-cors" | "same-origin";
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* A string indicating whether request follows redirects, results in
|
|
110
|
+
* an error upon encountering a redirect, or returns the redirect
|
|
111
|
+
* (in an opaque fashion).
|
|
112
|
+
*
|
|
113
|
+
* Sets request's redirect.
|
|
114
|
+
*/
|
|
115
|
+
redirect?: "error" | "follow" | "manual";
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* A string whose value is a same-origin URL, "about:client", or the
|
|
119
|
+
* empty string, to set request's referrer.
|
|
120
|
+
*/
|
|
121
|
+
referrer?: string;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* A referrer policy to set request's referrerPolicy.
|
|
125
|
+
*/
|
|
126
|
+
referrerPolicy?:
|
|
127
|
+
| ""
|
|
128
|
+
| "no-referrer"
|
|
129
|
+
| "no-referrer-when-downgrade"
|
|
130
|
+
| "origin"
|
|
131
|
+
| "origin-when-cross-origin"
|
|
132
|
+
| "same-origin"
|
|
133
|
+
| "strict-origin"
|
|
134
|
+
| "strict-origin-when-cross-origin"
|
|
135
|
+
| "unsafe-url";
|
|
136
|
+
}
|
|
50
137
|
}
|