@nestia/fetcher 10.0.1 → 11.0.0-dev.20260305

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.
Files changed (59) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +93 -93
  3. package/package.json +20 -13
  4. package/src/AesPkcs5.ts +41 -49
  5. package/src/EncryptedFetcher.ts +176 -176
  6. package/src/FormDataInput.ts +80 -80
  7. package/src/HttpError.ts +1 -1
  8. package/src/IConnection.ts +241 -241
  9. package/src/IEncryptionPassword.ts +44 -44
  10. package/src/IFetchEvent.ts +31 -31
  11. package/src/IFetchRoute.ts +60 -60
  12. package/src/IPropagation.ts +99 -99
  13. package/src/NestiaSimulator.ts +82 -82
  14. package/src/PlainFetcher.ts +105 -105
  15. package/src/index.ts +12 -7
  16. package/src/internal/FetcherBase.ts +235 -235
  17. package/lib/AesPkcs5.d.ts +0 -30
  18. package/lib/AesPkcs5.js +0 -49
  19. package/lib/AesPkcs5.js.map +0 -1
  20. package/lib/EncryptedFetcher.d.ts +0 -47
  21. package/lib/EncryptedFetcher.js +0 -139
  22. package/lib/EncryptedFetcher.js.map +0 -1
  23. package/lib/FormDataInput.d.ts +0 -70
  24. package/lib/FormDataInput.js +0 -3
  25. package/lib/FormDataInput.js.map +0 -1
  26. package/lib/HttpError.d.ts +0 -1
  27. package/lib/HttpError.js +0 -6
  28. package/lib/HttpError.js.map +0 -1
  29. package/lib/IConnection.d.ts +0 -165
  30. package/lib/IConnection.js +0 -3
  31. package/lib/IConnection.js.map +0 -1
  32. package/lib/IEncryptionPassword.d.ts +0 -41
  33. package/lib/IEncryptionPassword.js +0 -3
  34. package/lib/IEncryptionPassword.js.map +0 -1
  35. package/lib/IFetchEvent.d.ts +0 -11
  36. package/lib/IFetchEvent.js +0 -21
  37. package/lib/IFetchEvent.js.map +0 -1
  38. package/lib/IFetchRoute.d.ts +0 -46
  39. package/lib/IFetchRoute.js +0 -3
  40. package/lib/IFetchRoute.js.map +0 -1
  41. package/lib/IPropagation.d.ts +0 -69
  42. package/lib/IPropagation.js +0 -3
  43. package/lib/IPropagation.js.map +0 -1
  44. package/lib/MigrateFetcher.d.ts +0 -19
  45. package/lib/MigrateFetcher.js +0 -179
  46. package/lib/MigrateFetcher.js.map +0 -1
  47. package/lib/NestiaSimulator.d.ts +0 -13
  48. package/lib/NestiaSimulator.js +0 -62
  49. package/lib/NestiaSimulator.js.map +0 -1
  50. package/lib/PlainFetcher.d.ts +0 -46
  51. package/lib/PlainFetcher.js +0 -89
  52. package/lib/PlainFetcher.js.map +0 -1
  53. package/lib/index.d.ts +0 -7
  54. package/lib/index.js +0 -24
  55. package/lib/index.js.map +0 -1
  56. package/lib/internal/FetcherBase.d.ts +0 -1
  57. package/lib/internal/FetcherBase.js +0 -348
  58. package/lib/internal/FetcherBase.js.map +0 -1
  59. package/src/MigrateFetcher.ts +0 -118
@@ -1,139 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- 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;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.EncryptedFetcher = void 0;
40
- var AesPkcs5_1 = require("./AesPkcs5");
41
- var FetcherBase_1 = require("./internal/FetcherBase");
42
- /**
43
- * Utility class for `fetch` functions used in `@nestia/sdk` with encryption.
44
- *
45
- * `EncryptedFetcher` is a utility class designed for SDK functions generated by
46
- * [`@nestia/sdk`](https://nestia.io/docs/sdk/sdk), interacting with the remote
47
- * HTTP API encrypted by AES-PKCS algorithm. In other words, this is a
48
- * collection of dedicated `fetch()` functions for `@nestia/sdk` with
49
- * encryption.
50
- *
51
- * For reference, `EncryptedFetcher` class being used only when target
52
- * controller method is encrypting body data by `@EncryptedRoute` or
53
- * `@EncryptedBody` decorators. If those decorators are not used,
54
- * {@link PlainFetcher} class would be used instead.
55
- *
56
- * @author Jeongho Nam - https://github.com/samchon
57
- */
58
- var EncryptedFetcher;
59
- (function (EncryptedFetcher) {
60
- function fetch(connection, route, input, stringify) {
61
- return __awaiter(this, void 0, void 0, function () {
62
- var closure;
63
- var _a, _b, _c, _d;
64
- return __generator(this, function (_e) {
65
- if ((((_a = route.request) === null || _a === void 0 ? void 0 : _a.encrypted) === true || ((_b = route.response) === null || _b === void 0 ? void 0 : _b.encrypted)) &&
66
- connection.encryption === undefined)
67
- throw new Error("Error on EncryptedFetcher.fetch(): the encryption password has not been configured.");
68
- closure = typeof connection.encryption === "function"
69
- ? function (direction) {
70
- return function (headers, body) {
71
- return connection.encryption({
72
- headers: headers,
73
- body: body,
74
- direction: direction,
75
- });
76
- };
77
- }
78
- : function () { return function () { return connection.encryption; }; };
79
- return [2 /*return*/, FetcherBase_1.FetcherBase.request({
80
- className: "EncryptedFetcher",
81
- encode: ((_c = route.request) === null || _c === void 0 ? void 0 : _c.encrypted) === true
82
- ? function (input, headers) {
83
- var p = closure("encode")(headers, input);
84
- return AesPkcs5_1.AesPkcs5.encrypt((stringify !== null && stringify !== void 0 ? stringify : JSON.stringify)(input), p.key, p.iv);
85
- }
86
- : function (input) { return input; },
87
- decode: ((_d = route.response) === null || _d === void 0 ? void 0 : _d.encrypted) === true
88
- ? function (input, headers) {
89
- var p = closure("decode")(headers, input);
90
- var s = AesPkcs5_1.AesPkcs5.decrypt(input, p.key, p.iv);
91
- return s.length ? JSON.parse(s) : s;
92
- }
93
- : function (input) { return input; },
94
- })(connection, route, input, stringify)];
95
- });
96
- });
97
- }
98
- EncryptedFetcher.fetch = fetch;
99
- function propagate(connection, route, input, stringify) {
100
- return __awaiter(this, void 0, void 0, function () {
101
- var closure;
102
- var _a, _b, _c, _d;
103
- return __generator(this, function (_e) {
104
- if ((((_a = route.request) === null || _a === void 0 ? void 0 : _a.encrypted) === true || ((_b = route.response) === null || _b === void 0 ? void 0 : _b.encrypted)) &&
105
- connection.encryption === undefined)
106
- throw new Error("Error on EncryptedFetcher.propagate(): the encryption password has not been configured.");
107
- closure = typeof connection.encryption === "function"
108
- ? function (direction) {
109
- return function (headers, body) {
110
- return connection.encryption({
111
- headers: headers,
112
- body: body,
113
- direction: direction,
114
- });
115
- };
116
- }
117
- : function () { return function () { return connection.encryption; }; };
118
- return [2 /*return*/, FetcherBase_1.FetcherBase.propagate({
119
- className: "EncryptedFetcher",
120
- encode: ((_c = route.request) === null || _c === void 0 ? void 0 : _c.encrypted) === true
121
- ? function (input, headers) {
122
- var p = closure("encode")(headers, input);
123
- return AesPkcs5_1.AesPkcs5.encrypt((stringify !== null && stringify !== void 0 ? stringify : JSON.stringify)(input), p.key, p.iv);
124
- }
125
- : function (input) { return input; },
126
- decode: ((_d = route.response) === null || _d === void 0 ? void 0 : _d.encrypted) === true
127
- ? function (input, headers) {
128
- var p = closure("decode")(headers, input);
129
- var s = AesPkcs5_1.AesPkcs5.decrypt(input, p.key, p.iv);
130
- return s.length ? JSON.parse(s) : s;
131
- }
132
- : function (input) { return input; },
133
- })(connection, route, input, stringify)];
134
- });
135
- });
136
- }
137
- EncryptedFetcher.propagate = propagate;
138
- })(EncryptedFetcher || (exports.EncryptedFetcher = EncryptedFetcher = {}));
139
- //# sourceMappingURL=EncryptedFetcher.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"EncryptedFetcher.js","sourceRoot":"","sources":["../src/EncryptedFetcher.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAsC;AAKtC,sDAAqD;AAErD;;;;;;;;;;;;;;;GAeG;AACH,IAAiB,gBAAgB,CAwJhC;AAxJD,WAAiB,gBAAgB;IAuC/B,SAAsB,KAAK,CACzB,UAAuB,EACvB,KAAwE,EACxE,KAAa,EACb,SAAoC;;;;;gBAEpC,IACE,CAAC,CAAA,MAAA,KAAK,CAAC,OAAO,0CAAE,SAAS,MAAK,IAAI,KAAI,MAAA,KAAK,CAAC,QAAQ,0C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O;gCACb,IAAM,CAAC,GAAwB,OAAO,CAAC,QAAQ,CAAC,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;gCACjE,OAAO,mBAAQ,CAAC,OAAO,CACrB,CAAC,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,IAAI,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,EACpC,CAAC,CAAC,GAAG,EACL,CAAC,CAAC,EAAE,CACL,CAAC;4BACJ,CAAC;4BACH,CAAC,CAAC,UAAC,KAAK,IAAK,OAAA,KAAK,EAAL,CAAK;wBACtB,MAAM,EACJ,CAAA,MAAA,KAAK,CAAC,QAAQ,0CAAE,SAAS,MAAK,IAAI;4BAChC,CAAC,CAAC,UAAC,KAAK,EAAE,OAAO;gCACb,IAAM,CAAC,GAAwB,OAAO,CAAC,QAAQ,CAAC,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;gCACjE,IAAM,CAAC,GAAW,mBAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;gCACvD,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;4BACtC,CAAC;4BACH,CAAC,CAAC,UAAC,KAAK,IAAK,OAAA,KAAK,EAAL,CAAK;qBACvB,CAAC,CAAC,UAAU,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,CAAoB,EAAC;;;KAC5D;IAjDqB,0BAAS,YAiD9B,CAAA;AACH,CAAC,EAxJgB,gBAAgB,gCAAhB,gBAAgB,QAwJhC"}
@@ -1,70 +0,0 @@
1
- /**
2
- * FormData input type.
3
- *
4
- * `FormDataInput<T>` is a type for the input of the `FormData` request, casting
5
- * `File` property value type as an union of `File` and
6
- * {@link FormDataInput.IFileProps}, especially for the React Native
7
- * environment.
8
- *
9
- * You know what? In the React Native environment, `File` class is not
10
- * supported. Therefore, when composing a `FormData` request, you have to put
11
- * the URI address of the local filesystem with file name and content type that
12
- * is represented by the {@link FormDataInput.IFileProps} type.
13
- *
14
- * This `FormDataInput<T>` type is designed for that purpose. If the property
15
- * value type is a `File` class, it converts it to an union type of `File` and
16
- * {@link FormDataInput.IFileProps} type. Also, if the property value type is an
17
- * array of `File` class, it converts it to an array of union type of `File` and
18
- * {@link FormDataInput.IFileProps} type too.
19
- *
20
- * Before | After ----------|------------------------ `boolean` | `boolean`
21
- * `bigint` | `bigint` `number` | `number` `string` | `string` `File` | `File \|
22
- * IFileProps`
23
- *
24
- * @author Jeongho Nam - https://github.com/samchon
25
- * @template T Target object type.
26
- */
27
- export type FormDataInput<T extends object> = T extends Array<any> ? never : T extends Function ? never : {
28
- [P in keyof T]: T[P] extends Array<infer U> ? FormDataInput.Value<U>[] : FormDataInput.Value<T[P]>;
29
- };
30
- export declare namespace FormDataInput {
31
- /**
32
- * Value type of the `FormDataInput`.
33
- *
34
- * `Value<T>` is a type for the property value defined in the `FormDataInput`.
35
- *
36
- * If the original value type is a `File` class, `Value<T>` converts it to an
37
- * union type of `File` and {@link IFileProps} type which is a structured data
38
- * for the URI file location in the React Native environment.
39
- */
40
- type Value<T> = T extends File ? T | IFileProps : T;
41
- /**
42
- * Properties of a file.
43
- *
44
- * In the React Native, this `IFileProps` structured data can replace the
45
- * `File` class instance in the `FormData` request.
46
- *
47
- * Just put the {@link uri URI address} of the local file system with the
48
- * file's {@link name} and {@link type}. It would be casted to the `File` class
49
- * instance automatically in the `FormData` request.
50
- *
51
- * Note that, this `IFileProps` type works only in the React Native
52
- * environment. If you are developing a Web or NodeJS application, you have to
53
- * utilize the `File` class instance directly.
54
- */
55
- interface IFileProps {
56
- /**
57
- * URI address of the file.
58
- *
59
- * In the React Native, the URI address in the local file system can replace
60
- * the `File` class instance. If
61
- *
62
- * @format uri
63
- */
64
- uri: string;
65
- /** Name of the file. */
66
- name: string;
67
- /** Content type of the file. */
68
- type: string;
69
- }
70
- }
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=FormDataInput.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FormDataInput.js","sourceRoot":"","sources":["../src/FormDataInput.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- export { HttpError } from "@samchon/openapi";
package/lib/HttpError.js DELETED
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HttpError = void 0;
4
- var openapi_1 = require("@samchon/openapi");
5
- Object.defineProperty(exports, "HttpError", { enumerable: true, get: function () { return openapi_1.HttpError; } });
6
- //# sourceMappingURL=HttpError.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"HttpError.js","sourceRoot":"","sources":["../src/HttpError.ts"],"names":[],"mappings":";;;AAAA,4CAA6C;AAApC,oGAAA,SAAS,OAAA"}
@@ -1,165 +0,0 @@
1
- import { IEncryptionPassword } from "./IEncryptionPassword";
2
- import { IFetchEvent } from "./IFetchEvent";
3
- /**
4
- * Connection information.
5
- *
6
- * `IConnection` is an interface ttype who represents connection information of
7
- * the remote HTTP server. You can target the remote HTTP server by wring the
8
- * {@link IConnection.host} variable down. Also, you can configure special header
9
- * values by specializing the {@link IConnection.headers} variable.
10
- *
11
- * If the remote HTTP server encrypts or decrypts its body data through the
12
- * AES-128/256 algorithm, specify the {@link IConnection.encryption} with
13
- * {@link IEncryptionPassword} or {@link IEncryptionPassword.Closure} variable.
14
- *
15
- * @author Jenogho Nam - https://github.com/samchon
16
- * @author Seungjun We - https://github.com/SeungjunWe
17
- */
18
- export interface IConnection<Headers extends object | undefined = object | undefined> {
19
- /** Host address of the remote HTTP server. */
20
- host: string;
21
- /** Header values delivered to the remote HTTP server. */
22
- headers?: Record<string, IConnection.HeaderValue> & IConnection.Headerify<Headers>;
23
- /**
24
- * Use simulation mode.
25
- *
26
- * If you configure this property to be `true`, your SDK library does not send
27
- * any request to remote backend server, but just returns random data
28
- * generated by `typia.random<T>()` function with request data validation.
29
- *
30
- * By the way, to utilize this simulation mode, SDK library must be generated
31
- * with {@link INestiaConfig.simulate} option, too. Open `nestia.config.ts`
32
- * file, and configure {@link INestiaConfig.simulate} property to be `true`.
33
- * Them, newly generated SDK library would have a built-in mock-up data
34
- * generator.
35
- *
36
- * @default false
37
- */
38
- simulate?: boolean;
39
- /**
40
- * Logger function.
41
- *
42
- * This function is called when the fetch event is completed.
43
- *
44
- * @param event Event information of the fetch event.
45
- */
46
- logger?: (event: IFetchEvent) => Promise<void>;
47
- /**
48
- * Encryption password of its closure function.
49
- *
50
- * Define it only when target backend server is encrypting body data through
51
- * `@EncryptedRoute` or `@EncryptedBody` decorators of `@nestia/core` for
52
- * security reason.
53
- */
54
- encryption?: IEncryptionPassword | IEncryptionPassword.Closure;
55
- /** Additional options for the `fetch` function. */
56
- options?: IConnection.IOptions;
57
- /**
58
- * Custom fetch function.
59
- *
60
- * If you want to use custom `fetch` function instead of built-in, assign your
61
- * custom `fetch` function into this property.
62
- *
63
- * For reference, the `fetch` function has started to be supported since
64
- * version 20 of NodeJS. Therefore, if you are using NodeJS version 19 or
65
- * lower, you have to assign the `node-fetch` module into this property.
66
- */
67
- fetch?: typeof fetch;
68
- }
69
- export declare namespace IConnection {
70
- /**
71
- * Additional options for the `fetch` function.
72
- *
73
- * Almost same with {@link RequestInit} type of the {@link fetch} function, but
74
- * `body`, `headers` and `method` properties are omitted.
75
- *
76
- * The reason why defining duplicated definition of {@link RequestInit} is for
77
- * legacy NodeJS environments, which does not have the {@link fetch} function
78
- * type.
79
- */
80
- interface IOptions {
81
- /**
82
- * A string indicating how the request will interact with the browser's
83
- * cache to set request's cache.
84
- */
85
- cache?: "default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload";
86
- /**
87
- * A string indicating whether credentials will be sent with the request
88
- * always, never, or only when sent to a same-origin URL. Sets request's
89
- * credentials.
90
- */
91
- credentials?: "omit" | "same-origin" | "include";
92
- /**
93
- * A cryptographic hash of the resource to be fetched by request.
94
- *
95
- * Sets request's integrity.
96
- */
97
- integrity?: string;
98
- /** A boolean to set request's keepalive. */
99
- keepalive?: boolean;
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
- * A string indicating whether request follows redirects, results in an
109
- * error upon encountering a redirect, or returns the redirect (in an opaque
110
- * fashion).
111
- *
112
- * Sets request's redirect.
113
- */
114
- redirect?: "error" | "follow" | "manual";
115
- /**
116
- * A string whose value is a same-origin URL, "about:client", or the empty
117
- * string, to set request's referrer.
118
- */
119
- referrer?: string;
120
- /** A referrer policy to set request's referrerPolicy. */
121
- referrerPolicy?: "" | "no-referrer" | "no-referrer-when-downgrade" | "origin" | "origin-when-cross-origin" | "same-origin" | "strict-origin" | "strict-origin-when-cross-origin" | "unsafe-url";
122
- /** An AbortSignal to set request's signal. */
123
- signal?: AbortSignal | null;
124
- }
125
- /**
126
- * Type of allowed header values.
127
- *
128
- * Only atomic or array of atomic values are allowed.
129
- */
130
- type HeaderValue = string | boolean | number | bigint | string | Array<boolean> | Array<number> | Array<bigint> | Array<number> | Array<string>;
131
- /**
132
- * Type of headers
133
- *
134
- * `Headerify` removes every properties that are not allowed in the HTTP
135
- * headers type.
136
- *
137
- * Below are list of prohibited in HTTP headers.
138
- *
139
- * 1. Value type one of {@link HeaderValue}
140
- * 2. Key is "set-cookie", but value is not an Array type
141
- * 3. Key is one of them, but value is Array type
142
- *
143
- * - "age"
144
- * - "authorization"
145
- * - "content-length"
146
- * - "content-type"
147
- * - "etag"
148
- * - "expires"
149
- * - "from"
150
- * - "host"
151
- * - "if-modified-since"
152
- * - "if-unmodified-since"
153
- * - "last-modified"
154
- * - "location"
155
- * - "max-forwards"
156
- * - "proxy-authorization"
157
- * - "referer"
158
- * - "retry-after"
159
- * - "server"
160
- * - "user-agent"
161
- */
162
- type Headerify<T extends object | undefined> = {
163
- [P in keyof T]?: T[P] extends HeaderValue | undefined ? P extends string ? Lowercase<P> extends "set-cookie" ? T[P] extends Array<HeaderValue> ? T[P] | undefined : never : Lowercase<P> extends "age" | "authorization" | "content-length" | "content-type" | "etag" | "expires" | "from" | "host" | "if-modified-since" | "if-unmodified-since" | "last-modified" | "location" | "max-forwards" | "proxy-authorization" | "referer" | "retry-after" | "server" | "user-agent" ? T[P] extends Array<HeaderValue> ? never : T[P] | undefined : T[P] | undefined : never : never;
164
- };
165
- }
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=IConnection.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IConnection.js","sourceRoot":"","sources":["../src/IConnection.ts"],"names":[],"mappings":""}
@@ -1,41 +0,0 @@
1
- import { IConnection } from "./IConnection";
2
- /**
3
- * Encryption password.
4
- *
5
- * `IEncryptionPassword` is a type of interface who represents encryption
6
- * password used by the {@link Fetcher} with AES-128/256 algorithm. If your
7
- * encryption password is not fixed but changes according to the input content,
8
- * you can utilize the {@link IEncryptionPassword.Closure} function type.
9
- *
10
- * @author Jeongho Nam - https://github.com/samchon
11
- */
12
- export interface IEncryptionPassword {
13
- /** Secret key. */
14
- key: string;
15
- /** Initialization Vector. */
16
- iv: string;
17
- }
18
- export declare namespace IEncryptionPassword {
19
- /**
20
- * Type of a closure function returning the {@link IEncryptionPassword} object.
21
- *
22
- * `IEncryptionPassword.Closure` is a type of closure function who are
23
- * returning the {@link IEncryptionPassword} object. It would be used when your
24
- * encryption password be changed according to the input content.
25
- */
26
- interface Closure {
27
- /**
28
- * Encryption password getter.
29
- *
30
- * @param props Properties for predication
31
- * @returns Encryption password
32
- */
33
- (props: IProps): IEncryptionPassword;
34
- }
35
- /** Properties for the closure. */
36
- interface IProps {
37
- headers: Record<string, IConnection.HeaderValue | undefined>;
38
- body: string;
39
- direction: "encode" | "decode";
40
- }
41
- }
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=IEncryptionPassword.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IEncryptionPassword.js","sourceRoot":"","sources":["../src/IEncryptionPassword.ts"],"names":[],"mappings":""}
@@ -1,11 +0,0 @@
1
- import { IFetchRoute } from "./IFetchRoute";
2
- export interface IFetchEvent {
3
- route: IFetchRoute<"DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT">;
4
- path: string;
5
- status: number | null;
6
- input: any;
7
- output: any;
8
- started_at: Date;
9
- respond_at: Date | null;
10
- completed_at: Date;
11
- }
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- // export namespace IFetchEvent {
4
- // export interface IFunction {
5
- // (connection: IConnection, ...args: any[]): Promise<any>;
6
- // METADATA: {
7
- // method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS";
8
- // path: string;
9
- // request: null | {
10
- // type: string;
11
- // encrypted: boolean;
12
- // };
13
- // response: null | {
14
- // type: string;
15
- // encrypted: boolean;
16
- // };
17
- // };
18
- // status: null | number;
19
- // }
20
- // }
21
- //# sourceMappingURL=IFetchEvent.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IFetchEvent.js","sourceRoot":"","sources":["../src/IFetchEvent.ts"],"names":[],"mappings":";;AAaA,iCAAiC;AACjC,iCAAiC;AACjC,+DAA+D;AAC/D,kBAAkB;AAClB,kFAAkF;AAClF,sBAAsB;AACtB,0BAA0B;AAC1B,wBAAwB;AACxB,8BAA8B;AAC9B,WAAW;AACX,2BAA2B;AAC3B,wBAAwB;AACxB,8BAA8B;AAC9B,WAAW;AACX,SAAS;AACT,6BAA6B;AAC7B,MAAM;AACN,IAAI"}
@@ -1,46 +0,0 @@
1
- /**
2
- * Properties of remote API route.
3
- *
4
- * @author Jeongho Nam - https://github.com/samchon
5
- */
6
- export interface IFetchRoute<Method extends "HEAD" | "GET" | "POST" | "PUT" | "PATCH" | "DELETE"> {
7
- /** Method of the HTTP request. */
8
- method: Method;
9
- /** Path of the HTTP request. */
10
- path: string;
11
- /**
12
- * Path template.
13
- *
14
- * Filled since 3.2.2 version.
15
- */
16
- template?: string;
17
- /** Request body data info. */
18
- request: Method extends "DELETE" | "POST" | "PUT" | "PATCH" ? IFetchRoute.IBody | null : null;
19
- /** Response body data info. */
20
- response: Method extends "HEAD" ? null : IFetchRoute.IBody;
21
- /** When special status code being used. */
22
- status: number | null;
23
- /**
24
- * Parser of the query string.
25
- *
26
- * If content type of response body is `application/x-www-form-urlencoded`,
27
- * then this `parseQuery` function would be called.
28
- *
29
- * If you've forgotten to configuring this `parseQuery` property about the
30
- * `application/x-www-form-urlencoded` typed response body data, then only the
31
- * `URLSearchParams` typed instance would be returned instead.
32
- */
33
- parseQuery?(input: URLSearchParams): any;
34
- }
35
- export declare namespace IFetchRoute {
36
- /**
37
- * Metadata of body.
38
- *
39
- * Describes how content-type being used in body, and whether encrypted or
40
- * not.
41
- */
42
- interface IBody {
43
- type: "application/json" | "application/x-www-form-urlencoded" | "multipart/form-data" | "text/plain";
44
- encrypted?: boolean;
45
- }
46
- }
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=IFetchRoute.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IFetchRoute.js","sourceRoot":"","sources":["../src/IFetchRoute.ts"],"names":[],"mappings":""}
@@ -1,69 +0,0 @@
1
- /**
2
- * Propagation type.
3
- *
4
- * `IPropagation` is a type gathering all possible status codes and their body
5
- * data types as a discriminated union type. You can specify the status code and
6
- * its body data type just by using conditional statement like below.
7
- *
8
- * ```typescript
9
- * type Output = IPropagation<{
10
- * 200: ISeller.IAuthorized;
11
- * 400: TypeGuardError.IProps;
12
- * >};
13
- *
14
- * const output: Output = await sdk.sellers.authenticate.join(input);
15
- * if (output.success) {
16
- * // automatically casted to "ISeller.IAuthorized" type
17
- * const authorized: ISeller.IAuthorized = output.data;
18
- * } else if (output.status === 400) {
19
- * // automatically casted to "TypeGuardError.IProps" type
20
- * const error: TypeGuardError.IProps = output.data;
21
- * } else {
22
- * // unknown type when out of pre-defined status codes
23
- * const result: unknown = output.data;
24
- * }
25
- * ```
26
- *
27
- * For reference, this `IPropagation` type is utilized by SDK library generated
28
- * by `@nestia/sdk`, when you've configured {@link INestiaConfig.propagate} to be
29
- * `true`. In that case, SDK functions generated by `@nestia/sdk` no more
30
- * returns response DTO typed data directly, but returns this `IPropagation`
31
- * typed object instead.
32
- *
33
- * @author Jeongho Nam - https://github.com/samchon
34
- * @template StatusMap Map of status code and its body data type.
35
- * @template Success Default success status code.
36
- */
37
- export type IPropagation<StatusMap extends {
38
- [P in IPropagation.Status]?: any;
39
- }, Success extends number = 200 | 201> = {
40
- [P in keyof StatusMap]: IPropagation.IBranch<P extends Success ? true : false, P, StatusMap[P]>;
41
- }[keyof StatusMap] | IPropagation.IBranch<false, unknown, unknown>;
42
- export declare namespace IPropagation {
43
- /**
44
- * Type of configurable status codes.
45
- *
46
- * The special characters like `2XX`, `3XX`, `4XX`, `5XX` are meaning the
47
- * range of status codes. If `5XX` is specified, it means the status code is
48
- * in the range of `500` to `599`.
49
- */
50
- export type Status = number | "2XX" | "3XX" | "4XX" | "5XX";
51
- /**
52
- * Branch type of propagation.
53
- *
54
- * `IPropagation.IBranch` is a branch type composing `IPropagation` type,
55
- * which is gathering all possible status codes and their body data types as a
56
- * union type.
57
- */
58
- export interface IBranch<Success extends boolean, StatusValue, BodyData> {
59
- success: Success;
60
- status: StatusValue extends "2XX" | "3XX" | "4XX" | "5XX" ? StatusRange<StatusValue> : StatusValue extends number ? StatusValue : never;
61
- data: BodyData;
62
- headers: Record<string, string | string[]>;
63
- }
64
- /** Range of status codes by the first digit. */
65
- export type StatusRange<T extends "2XX" | "3XX" | "4XX" | "5XX"> = T extends 0 ? IntRange<200, 299> : T extends 3 ? IntRange<300, 399> : T extends 4 ? IntRange<400, 499> : IntRange<500, 599>;
66
- type IntRange<F extends number, T extends number> = Exclude<Enumerate<T>, Enumerate<F>>;
67
- type Enumerate<N extends number, Acc extends number[] = []> = Acc["length"] extends N ? Acc[number] : Enumerate<N, [...Acc, Acc["length"]]>;
68
- export {};
69
- }
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=IPropagation.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IPropagation.js","sourceRoot":"","sources":["../src/IPropagation.ts"],"names":[],"mappings":""}