@nestia/fetcher 11.0.0-dev.20260305 → 11.0.0-dev.20260312

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 (50) hide show
  1. package/lib/AesPkcs5.d.ts +30 -0
  2. package/lib/AesPkcs5.js +49 -0
  3. package/lib/AesPkcs5.js.map +1 -0
  4. package/lib/EncryptedFetcher.d.ts +47 -0
  5. package/lib/EncryptedFetcher.js +98 -0
  6. package/lib/EncryptedFetcher.js.map +1 -0
  7. package/lib/FormDataInput.d.ts +70 -0
  8. package/lib/FormDataInput.js +3 -0
  9. package/lib/FormDataInput.js.map +1 -0
  10. package/lib/HttpError.d.ts +1 -0
  11. package/lib/HttpError.js +6 -0
  12. package/lib/HttpError.js.map +1 -0
  13. package/lib/IConnection.d.ts +165 -0
  14. package/lib/IConnection.js +3 -0
  15. package/lib/IConnection.js.map +1 -0
  16. package/lib/IEncryptionPassword.d.ts +41 -0
  17. package/lib/IEncryptionPassword.js +3 -0
  18. package/lib/IEncryptionPassword.js.map +1 -0
  19. package/lib/IFetchEvent.d.ts +11 -0
  20. package/lib/IFetchEvent.js +21 -0
  21. package/lib/IFetchEvent.js.map +1 -0
  22. package/lib/IFetchRoute.d.ts +46 -0
  23. package/lib/IFetchRoute.js +3 -0
  24. package/lib/IFetchRoute.js.map +1 -0
  25. package/lib/IPropagation.d.ts +69 -0
  26. package/lib/IPropagation.js +3 -0
  27. package/lib/IPropagation.js.map +1 -0
  28. package/lib/NestiaSimulator.d.ts +13 -0
  29. package/lib/NestiaSimulator.js +44 -0
  30. package/lib/NestiaSimulator.js.map +1 -0
  31. package/lib/PlainFetcher.d.ts +46 -0
  32. package/lib/PlainFetcher.js +58 -0
  33. package/lib/PlainFetcher.js.map +1 -0
  34. package/lib/index.d.ts +11 -0
  35. package/lib/index.js +28 -0
  36. package/lib/index.js.map +1 -0
  37. package/lib/internal/FetcherBase.d.ts +1 -0
  38. package/lib/internal/FetcherBase.js +185 -0
  39. package/lib/internal/FetcherBase.js.map +1 -0
  40. package/package.json +3 -3
  41. package/src/EncryptedFetcher.ts +176 -176
  42. package/src/FormDataInput.ts +80 -80
  43. package/src/IConnection.ts +241 -241
  44. package/src/IEncryptionPassword.ts +44 -44
  45. package/src/IFetchEvent.ts +31 -31
  46. package/src/IFetchRoute.ts +60 -60
  47. package/src/IPropagation.ts +99 -99
  48. package/src/NestiaSimulator.ts +82 -82
  49. package/src/PlainFetcher.ts +105 -105
  50. package/src/internal/FetcherBase.ts +235 -235
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Utility class for the AES-128/256 encryption.
3
+ *
4
+ * - AES-128/256
5
+ * - CBC mode
6
+ * - PKCS#5 Padding
7
+ * - Base64 Encoding
8
+ *
9
+ * @author Jeongho Nam - https://github.com/samchon
10
+ */
11
+ export declare namespace AesPkcs5 {
12
+ /**
13
+ * Encrypt data
14
+ *
15
+ * @param data Target data
16
+ * @param key Key value of the encryption.
17
+ * @param iv Initializer Vector for the encryption
18
+ * @returns Encrypted data
19
+ */
20
+ function encrypt(data: string, key: string, iv: string): string;
21
+ /**
22
+ * Decrypt data.
23
+ *
24
+ * @param data Target data
25
+ * @param key Key value of the decryption.
26
+ * @param iv Initializer Vector for the decryption
27
+ * @returns Decrypted data.
28
+ */
29
+ function decrypt(data: string, key: string, iv: string): string;
30
+ }
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.AesPkcs5 = void 0;
7
+ const crypto_1 = __importDefault(require("crypto"));
8
+ /**
9
+ * Utility class for the AES-128/256 encryption.
10
+ *
11
+ * - AES-128/256
12
+ * - CBC mode
13
+ * - PKCS#5 Padding
14
+ * - Base64 Encoding
15
+ *
16
+ * @author Jeongho Nam - https://github.com/samchon
17
+ */
18
+ var AesPkcs5;
19
+ (function (AesPkcs5) {
20
+ /**
21
+ * Encrypt data
22
+ *
23
+ * @param data Target data
24
+ * @param key Key value of the encryption.
25
+ * @param iv Initializer Vector for the encryption
26
+ * @returns Encrypted data
27
+ */
28
+ function encrypt(data, key, iv) {
29
+ const bytes = key.length * 8;
30
+ const cipher = crypto_1.default.createCipheriv(`AES-${bytes}-CBC`, key, iv);
31
+ return cipher.update(data, "utf8", "base64") + cipher.final("base64");
32
+ }
33
+ AesPkcs5.encrypt = encrypt;
34
+ /**
35
+ * Decrypt data.
36
+ *
37
+ * @param data Target data
38
+ * @param key Key value of the decryption.
39
+ * @param iv Initializer Vector for the decryption
40
+ * @returns Decrypted data.
41
+ */
42
+ function decrypt(data, key, iv) {
43
+ const bytes = key.length * 8;
44
+ const decipher = crypto_1.default.createDecipheriv(`AES-${bytes}-CBC`, key, iv);
45
+ return decipher.update(data, "base64", "utf8") + decipher.final("utf8");
46
+ }
47
+ AesPkcs5.decrypt = decrypt;
48
+ })(AesPkcs5 || (exports.AesPkcs5 = AesPkcs5 = {}));
49
+ //# sourceMappingURL=AesPkcs5.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AesPkcs5.js","sourceRoot":"","sources":["../src/AesPkcs5.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAE5B;;;;;;;;;GASG;AACH,IAAiB,QAAQ,CA4BxB;AA5BD,WAAiB,QAAQ;IACvB;;;;;;;OAOG;IACH,SAAgB,OAAO,CAAC,IAAY,EAAE,GAAW,EAAE,EAAU;QAC3D,MAAM,KAAK,GAAW,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC;QACrC,MAAM,MAAM,GAAG,gBAAM,CAAC,cAAc,CAAC,OAAO,KAAK,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;QAClE,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACxE,CAAC;IAJe,gBAAO,UAItB,CAAA;IAED;;;;;;;OAOG;IACH,SAAgB,OAAO,CAAC,IAAY,EAAE,GAAW,EAAE,EAAU;QAC3D,MAAM,KAAK,GAAW,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC;QACrC,MAAM,QAAQ,GAAG,gBAAM,CAAC,gBAAgB,CAAC,OAAO,KAAK,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;QACtE,OAAO,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAC1E,CAAC;IAJe,gBAAO,UAItB,CAAA;AACH,CAAC,EA5BgB,QAAQ,wBAAR,QAAQ,QA4BxB"}
@@ -0,0 +1,47 @@
1
+ import { IConnection } from "./IConnection";
2
+ import { IFetchRoute } from "./IFetchRoute";
3
+ import { IPropagation } from "./IPropagation";
4
+ /**
5
+ * Utility class for `fetch` functions used in `@nestia/sdk` with encryption.
6
+ *
7
+ * `EncryptedFetcher` is a utility class designed for SDK functions generated by
8
+ * [`@nestia/sdk`](https://nestia.io/docs/sdk/sdk), interacting with the remote
9
+ * HTTP API encrypted by AES-PKCS algorithm. In other words, this is a
10
+ * collection of dedicated `fetch()` functions for `@nestia/sdk` with
11
+ * encryption.
12
+ *
13
+ * For reference, `EncryptedFetcher` class being used only when target
14
+ * controller method is encrypting body data by `@EncryptedRoute` or
15
+ * `@EncryptedBody` decorators. If those decorators are not used,
16
+ * {@link PlainFetcher} class would be used instead.
17
+ *
18
+ * @author Jeongho Nam - https://github.com/samchon
19
+ */
20
+ export declare namespace EncryptedFetcher {
21
+ /**
22
+ * Fetch function only for `HEAD` method.
23
+ *
24
+ * @param connection Connection information for the remote HTTP server
25
+ * @param route Route information about the target API
26
+ * @returns Nothing because of `HEAD` method
27
+ */
28
+ function fetch(connection: IConnection, route: IFetchRoute<"HEAD">): Promise<void>;
29
+ /**
30
+ * Fetch function only for `GET` method.
31
+ *
32
+ * @param connection Connection information for the remote HTTP server
33
+ * @param route Route information about the target API
34
+ * @returns Response body data from the remote API
35
+ */
36
+ function fetch<Output>(connection: IConnection, route: IFetchRoute<"GET">): Promise<Output>;
37
+ /**
38
+ * Fetch function for the `POST`, `PUT`, `PATCH` and `DELETE` methods.
39
+ *
40
+ * @param connection Connection information for the remote HTTP server
41
+ * @param route Route information about the target API
42
+ * @returns Response body data from the remote API
43
+ */
44
+ function fetch<Input, Output>(connection: IConnection, route: IFetchRoute<"POST" | "PUT" | "PATCH" | "DELETE">, input?: Input, stringify?: (input: Input) => string): Promise<Output>;
45
+ function propagate<Output extends IPropagation<any, any>>(connection: IConnection, route: IFetchRoute<"GET" | "HEAD">): Promise<Output>;
46
+ function propagate<Input, Output extends IPropagation<any, any>>(connection: IConnection, route: IFetchRoute<"DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT">, input?: Input, stringify?: (input: Input) => string): Promise<Output>;
47
+ }
@@ -0,0 +1,98 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.EncryptedFetcher = void 0;
13
+ const AesPkcs5_1 = require("./AesPkcs5");
14
+ const FetcherBase_1 = require("./internal/FetcherBase");
15
+ /**
16
+ * Utility class for `fetch` functions used in `@nestia/sdk` with encryption.
17
+ *
18
+ * `EncryptedFetcher` is a utility class designed for SDK functions generated by
19
+ * [`@nestia/sdk`](https://nestia.io/docs/sdk/sdk), interacting with the remote
20
+ * HTTP API encrypted by AES-PKCS algorithm. In other words, this is a
21
+ * collection of dedicated `fetch()` functions for `@nestia/sdk` with
22
+ * encryption.
23
+ *
24
+ * For reference, `EncryptedFetcher` class being used only when target
25
+ * controller method is encrypting body data by `@EncryptedRoute` or
26
+ * `@EncryptedBody` decorators. If those decorators are not used,
27
+ * {@link PlainFetcher} class would be used instead.
28
+ *
29
+ * @author Jeongho Nam - https://github.com/samchon
30
+ */
31
+ var EncryptedFetcher;
32
+ (function (EncryptedFetcher) {
33
+ function fetch(connection, route, input, stringify) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ var _a, _b, _c, _d;
36
+ if ((((_a = route.request) === null || _a === void 0 ? void 0 : _a.encrypted) === true || ((_b = route.response) === null || _b === void 0 ? void 0 : _b.encrypted)) &&
37
+ connection.encryption === undefined)
38
+ throw new Error("Error on EncryptedFetcher.fetch(): the encryption password has not been configured.");
39
+ const closure = typeof connection.encryption === "function"
40
+ ? (direction) => (headers, body) => connection.encryption({
41
+ headers,
42
+ body,
43
+ direction,
44
+ })
45
+ : () => () => connection.encryption;
46
+ return FetcherBase_1.FetcherBase.request({
47
+ className: "EncryptedFetcher",
48
+ encode: ((_c = route.request) === null || _c === void 0 ? void 0 : _c.encrypted) === true
49
+ ? (input, headers) => {
50
+ const p = closure("encode")(headers, input);
51
+ return AesPkcs5_1.AesPkcs5.encrypt((stringify !== null && stringify !== void 0 ? stringify : JSON.stringify)(input), p.key, p.iv);
52
+ }
53
+ : (input) => input,
54
+ decode: ((_d = route.response) === null || _d === void 0 ? void 0 : _d.encrypted) === true
55
+ ? (input, headers) => {
56
+ const p = closure("decode")(headers, input);
57
+ const s = AesPkcs5_1.AesPkcs5.decrypt(input, p.key, p.iv);
58
+ return s.length ? JSON.parse(s) : s;
59
+ }
60
+ : (input) => input,
61
+ })(connection, route, input, stringify);
62
+ });
63
+ }
64
+ EncryptedFetcher.fetch = fetch;
65
+ function propagate(connection, route, input, stringify) {
66
+ return __awaiter(this, void 0, void 0, function* () {
67
+ var _a, _b, _c, _d;
68
+ if ((((_a = route.request) === null || _a === void 0 ? void 0 : _a.encrypted) === true || ((_b = route.response) === null || _b === void 0 ? void 0 : _b.encrypted)) &&
69
+ connection.encryption === undefined)
70
+ throw new Error("Error on EncryptedFetcher.propagate(): the encryption password has not been configured.");
71
+ const closure = typeof connection.encryption === "function"
72
+ ? (direction) => (headers, body) => connection.encryption({
73
+ headers,
74
+ body,
75
+ direction,
76
+ })
77
+ : () => () => connection.encryption;
78
+ return FetcherBase_1.FetcherBase.propagate({
79
+ className: "EncryptedFetcher",
80
+ encode: ((_c = route.request) === null || _c === void 0 ? void 0 : _c.encrypted) === true
81
+ ? (input, headers) => {
82
+ const p = closure("encode")(headers, input);
83
+ return AesPkcs5_1.AesPkcs5.encrypt((stringify !== null && stringify !== void 0 ? stringify : JSON.stringify)(input), p.key, p.iv);
84
+ }
85
+ : (input) => input,
86
+ decode: ((_d = route.response) === null || _d === void 0 ? void 0 : _d.encrypted) === true
87
+ ? (input, headers) => {
88
+ const p = closure("decode")(headers, input);
89
+ const s = AesPkcs5_1.AesPkcs5.decrypt(input, p.key, p.iv);
90
+ return s.length ? JSON.parse(s) : s;
91
+ }
92
+ : (input) => input,
93
+ })(connection, route, input, stringify);
94
+ });
95
+ }
96
+ EncryptedFetcher.propagate = propagate;
97
+ })(EncryptedFetcher || (exports.EncryptedFetcher = EncryptedFetcher = {}));
98
+ //# sourceMappingURL=EncryptedFetcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EncryptedFetcher.js","sourceRoot":"","sources":["../src/EncryptedFetcher.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAsC;AAKtC,wDAAqD;AAErD;;;;;;;;;;;;;;;GAeG;AACH,IAAiB,gBAAgB,CAwJhC;AAxJD,WAAiB,gBAAgB;IAuC/B,SAAsB,KAAK,CACzB,UAAuB,EACvB,KAAwE,EACxE,KAAa,EACb,SA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AC,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;wBACjB,MAAM,CAAC,GAAwB,OAAO,CAAC,QAAQ,CAAC,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;wBACjE,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;oBACJ,CAAC;oBACH,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK;gBACtB,MAAM,EACJ,CAAA,MAAA,KAAK,CAAC,QAAQ,0CAAE,SAAS,MAAK,IAAI;oBAChC,CAAC,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;wBACjB,MAAM,CAAC,GAAwB,OAAO,CAAC,QAAQ,CAAC,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;wBACjE,MAAM,CAAC,GAAW,mBAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;wBACvD,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;oBACtC,CAAC;oBACH,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK;aACvB,CAAC,CAAC,UAAU,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,CAAoB,CAAC;QAC7D,CAAC;KAAA;IAjDqB,0BAAS,YAiD9B,CAAA;AACH,CAAC,EAxJgB,gBAAgB,gCAAhB,gBAAgB,QAwJhC"}
@@ -0,0 +1,70 @@
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
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=FormDataInput.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FormDataInput.js","sourceRoot":"","sources":["../src/FormDataInput.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ export { HttpError } from "@typia/utils";
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpError = void 0;
4
+ var utils_1 = require("@typia/utils");
5
+ Object.defineProperty(exports, "HttpError", { enumerable: true, get: function () { return utils_1.HttpError; } });
6
+ //# sourceMappingURL=HttpError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HttpError.js","sourceRoot":"","sources":["../src/HttpError.ts"],"names":[],"mappings":";;;AAAA,sCAAyC;AAAhC,kGAAA,SAAS,OAAA"}
@@ -0,0 +1,165 @@
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
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=IConnection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IConnection.js","sourceRoot":"","sources":["../src/IConnection.ts"],"names":[],"mappings":""}
@@ -0,0 +1,41 @@
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
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=IEncryptionPassword.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IEncryptionPassword.js","sourceRoot":"","sources":["../src/IEncryptionPassword.ts"],"names":[],"mappings":""}
@@ -0,0 +1,11 @@
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
+ }
@@ -0,0 +1,21 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,46 @@
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
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=IFetchRoute.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IFetchRoute.js","sourceRoot":"","sources":["../src/IFetchRoute.ts"],"names":[],"mappings":""}