@nestia/fetcher 0.1.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/README.md +120 -0
- package/lib/AesPkcs5.d.ts +30 -0
- package/lib/AesPkcs5.js +49 -0
- package/lib/AesPkcs5.js.map +1 -0
- package/lib/Fetcher.d.ts +68 -0
- package/lib/Fetcher.js +190 -0
- package/lib/Fetcher.js.map +1 -0
- package/lib/HttpError.d.ts +21 -0
- package/lib/HttpError.js +53 -0
- package/lib/HttpError.js.map +1 -0
- package/lib/IConnection.d.ts +29 -0
- package/lib/IConnection.js +3 -0
- package/lib/IConnection.js.map +1 -0
- package/lib/IEncryptionPassword.d.ts +56 -0
- package/lib/IEncryptionPassword.js +3 -0
- package/lib/IEncryptionPassword.js.map +1 -0
- package/lib/Primitive.d.ts +45 -0
- package/lib/Primitive.js +3 -0
- package/lib/Primitive.js.map +1 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +23 -0
- package/lib/index.js.map +1 -0
- package/lib/internal/Singleton.d.ts +1 -0
- package/lib/internal/Singleton.js +24 -0
- package/lib/internal/Singleton.js.map +1 -0
- package/package.json +48 -0
- package/src/AesPkcs5.ts +51 -0
- package/src/Fetcher.ts +241 -0
- package/src/HttpError.ts +30 -0
- package/src/IConnection.ts +32 -0
- package/src/IEncryptionPassword.ts +64 -0
- package/src/Primitive.ts +85 -0
- package/src/index.ts +7 -0
- package/src/internal/Singleton.ts +20 -0
package/README.md
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# Nestia Fetcher
|
|
2
|
+
## Outline
|
|
3
|
+
[](https://github.com/samchon/@nestia/fetcher/blob/master/LICENSE)
|
|
4
|
+
[](https://www.npmjs.com/package/@nestia/fetcher)
|
|
5
|
+
[](https://www.npmjs.com/package/@nestia/fetcher)
|
|
6
|
+
[](https://github.com/samchon/@nestia/fetcher/actions?query=workflow%3Abuild)
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install --save @nestia/fetcher
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
`@nestia/fetcher` is a fetcher library of [**Nestia**](https://github.com/samchon/nestia) SDK.
|
|
13
|
+
|
|
14
|
+
When you build an SDK (Software Development Kit) library interacting with remote HTTP server through the [**Nestia**](https://github.com/samchon/nestia), the SDK library would be dependent on this `@nestia/fetcher`. Therefore, if you publish the SDK library on the NPM module, you have to add this `@nestia/fetcher` in the `dependencies` field of the `package.json`.
|
|
15
|
+
|
|
16
|
+
Also, if you're a client developer who've installed an SDK library which has been generated by the [**Nestia**](https://github.com/samchon/nestia), you also need to install this `@nestia/fetcher` module. With the `IConnection` and `HttpError` instances provided this `@nestia/fetcher`, you can enjoy the SDK library much conveniently.
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## Example
|
|
22
|
+
### `package.json`
|
|
23
|
+
When you build an SDK library who've been generated by the [**Nestia**](https://github.com/samchon/nestia), you have to add this `@nestia/fetcher` in the `dependencies` field of the `package.json`. If your project had installed the [**Nestia**](https://github.com/samchon/nestia), you can write the `dependencies`' property by writing the `npx nestia dependencies` command on your console.
|
|
24
|
+
|
|
25
|
+
```json
|
|
26
|
+
{
|
|
27
|
+
"name": "payments-server-api",
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@nestia/fetcher": "^1.0.0"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### SDK Library
|
|
35
|
+
Opening the SDK library source file who've been generated by the [**Nestia**](https://github.com/samchon/nestia), you can find the SDK library is importing this `@nestia/fetcher` module in every `functional` files. Therefore, I repeat that you have to put this `@nestia/fetcher` down into the `dependencies` field of the `package.json`.
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import { Fetcher, IConnection, Primitive } from "@nestia/fetcher";
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 결제 내역 발행하기.
|
|
42
|
+
*
|
|
43
|
+
* @param connection connection information
|
|
44
|
+
* @param input 결제 내역 입력 정보
|
|
45
|
+
* @returns 결제 내역
|
|
46
|
+
*
|
|
47
|
+
* @nestia Generated by Nestia - https://github.com/samchon/nestia
|
|
48
|
+
* @controller PaymentHistoriesController.store()
|
|
49
|
+
* @path POST /histories
|
|
50
|
+
*/
|
|
51
|
+
export function store
|
|
52
|
+
(
|
|
53
|
+
connection: IConnection,
|
|
54
|
+
input: Primitive<store.Input>
|
|
55
|
+
): Promise<store.Output>
|
|
56
|
+
{
|
|
57
|
+
return Fetcher.fetch
|
|
58
|
+
(
|
|
59
|
+
connection,
|
|
60
|
+
store.CONFIG,
|
|
61
|
+
store.METHOD,
|
|
62
|
+
store.path(),
|
|
63
|
+
input
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
export namespace store
|
|
67
|
+
{
|
|
68
|
+
export type Input = Primitive<IPaymentHistory.IStore>;
|
|
69
|
+
export type Output = Primitive<IPaymentHistory>;
|
|
70
|
+
|
|
71
|
+
export const METHOD = "POST" as const;
|
|
72
|
+
export const PATH: string = "/histories";
|
|
73
|
+
export const CONFIG: IConnection.IEncrypted = {
|
|
74
|
+
input_encrypted: true,
|
|
75
|
+
output_encrypted: true,
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export function path(): string
|
|
79
|
+
{
|
|
80
|
+
return `/histories`;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Utilization Code
|
|
86
|
+
After you've published the SDK library and let client developers to install the SDK library, the client developers would import this `@nestia/fetcher` module, too. They would utilize the `IConnection` and `HttpError` instances like below.
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
import payments from "payments-server-api";
|
|
90
|
+
import { IPaymentHistory } from "payments-server-api/lib/structures/IPaymentHistory";
|
|
91
|
+
import { IConnection, HttpError } from "@nestia/fetcher";
|
|
92
|
+
|
|
93
|
+
export async function main(): Promise<void>
|
|
94
|
+
{
|
|
95
|
+
// CONNECTION INFO OF THE REMOTE HTTP SERVER
|
|
96
|
+
const connection: IConnection = {
|
|
97
|
+
host: "http://payments.somewhere.com",
|
|
98
|
+
encryption: {
|
|
99
|
+
key: "SqwHmmXm1fZteI3URPtoyBWFJDMQ7FBQ",
|
|
100
|
+
iv: "9eSfjygAClnE1JJs"
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
try
|
|
105
|
+
{
|
|
106
|
+
const input: IPaymentHistory.IStore = { ...SOME_DATA };
|
|
107
|
+
const history: IPaymentHistory = await payments.functional.histories.store
|
|
108
|
+
(
|
|
109
|
+
connection,
|
|
110
|
+
input
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
catch (exp)
|
|
114
|
+
{
|
|
115
|
+
// HTTP-ERRROR
|
|
116
|
+
if (exp instanceof HttpError)
|
|
117
|
+
console.log(exp);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
```
|
|
@@ -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
|
+
* @return 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
|
+
* @return Decrypted data.
|
|
28
|
+
*/
|
|
29
|
+
function decrypt(data: string, key: string, iv: string): string;
|
|
30
|
+
}
|
package/lib/AesPkcs5.js
ADDED
|
@@ -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
|
+
var 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
|
+
* @return Encrypted data
|
|
27
|
+
*/
|
|
28
|
+
function encrypt(data, key, iv) {
|
|
29
|
+
var bytes = key.length * 8;
|
|
30
|
+
var cipher = crypto_1.default.createCipheriv("AES-".concat(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
|
+
* @return Decrypted data.
|
|
41
|
+
*/
|
|
42
|
+
function decrypt(data, key, iv) {
|
|
43
|
+
var bytes = key.length * 8;
|
|
44
|
+
var decipher = crypto_1.default.createDecipheriv("AES-".concat(bytes, "-CBC"), key, iv);
|
|
45
|
+
return decipher.update(data, "base64", "utf8") + decipher.final("utf8");
|
|
46
|
+
}
|
|
47
|
+
AesPkcs5.decrypt = decrypt;
|
|
48
|
+
})(AesPkcs5 = exports.AesPkcs5 || (exports.AesPkcs5 = {}));
|
|
49
|
+
//# sourceMappingURL=AesPkcs5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AesPkcs5.js","sourceRoot":"","sources":["../src/AesPkcs5.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA4B;AAE5B;;;;;;;;;GASG;AACH,IAAiB,QAAQ,CAsCxB;AAtCD,WAAiB,QAAQ;IACrB;;;;;;;OAOG;IACH,SAAgB,OAAO,CAAC,IAAY,EAAE,GAAW,EAAE,EAAU;QACzD,IAAM,KAAK,GAAW,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC;QACrC,IAAM,MAAM,GAAkB,gBAAM,CAAC,cAAc,CAC/C,cAAO,KAAK,SAAM,EAClB,GAAG,EACH,EAAE,CACL,CAAC;QAEF,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC1E,CAAC;IATe,gBAAO,UAStB,CAAA;IAED;;;;;;;OAOG;IACH,SAAgB,OAAO,CAAC,IAAY,EAAE,GAAW,EAAE,EAAU;QACzD,IAAM,KAAK,GAAW,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC;QACrC,IAAM,QAAQ,GAAoB,gBAAM,CAAC,gBAAgB,CACrD,cAAO,KAAK,SAAM,EAClB,GAAG,EACH,EAAE,CACL,CAAC;QAEF,OAAO,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAC5E,CAAC;IATe,gBAAO,UAStB,CAAA;AACL,CAAC,EAtCgB,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAsCxB"}
|
package/lib/Fetcher.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { IConnection } from "./IConnection";
|
|
2
|
+
import { Primitive } from "./Primitive";
|
|
3
|
+
/**
|
|
4
|
+
* Fetcher, utility class for the [**Nestia**](https://github.com/samchon/nestia) fetch.
|
|
5
|
+
*
|
|
6
|
+
* `Fetcher` is a utility class providing the {@link Fetcher.fetch} functions who're being
|
|
7
|
+
* used by all of the SDK libraries, interacting with the remote HTTP servers, who are
|
|
8
|
+
* generated by the [**Nestia**](https://github.com/samchon/nestia).
|
|
9
|
+
*
|
|
10
|
+
* As this `Fetcher` be used only by the [**Nestia**](https://github.com/samchon/nestia)
|
|
11
|
+
* generated SDK libraries, you don't need to handle this class directly. It may only be
|
|
12
|
+
* appeared in the source codes of the [**Nestia**](https://github.com/samchon/nestia)
|
|
13
|
+
* generated SDK libraries.
|
|
14
|
+
*
|
|
15
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
16
|
+
*/
|
|
17
|
+
export declare class Fetcher {
|
|
18
|
+
/**
|
|
19
|
+
* Fetch function for the `GET` or `DELETE` methods.
|
|
20
|
+
*
|
|
21
|
+
* @param connection Connection information for the remote HTTP server
|
|
22
|
+
* @param encrypted Whether the request/response body be encrypted or not
|
|
23
|
+
* @param method Method of the HTTP request
|
|
24
|
+
* @param path Path of the HTTP request
|
|
25
|
+
* @return Response body data from the remote HTTP server
|
|
26
|
+
*/
|
|
27
|
+
static fetch<Output>(connection: IConnection, encrypted: Fetcher.IEncrypted, method: "GET" | "DELETE", path: string): Promise<Primitive<Output>>;
|
|
28
|
+
/**
|
|
29
|
+
* Fetch function for the `POST`, `PUT` and `PATCH` methods.
|
|
30
|
+
*
|
|
31
|
+
* @param connection Connection information for the remote HTTP server
|
|
32
|
+
* @param encrypted Whether the request/response body be encrypted or not
|
|
33
|
+
* @param method Method of the HTTP request
|
|
34
|
+
* @param path Path of the HTTP request
|
|
35
|
+
* @param input Request body data for the HTTP request
|
|
36
|
+
* @param stringify JSON string conversion function, default is the `JSON.stringify`
|
|
37
|
+
* @return Response body data from the remote HTTP server
|
|
38
|
+
*/
|
|
39
|
+
static fetch<Input, Output>(connection: IConnection, encrypted: Fetcher.IEncrypted, method: "POST" | "PUT" | "PATCH", path: string, input: Input, stringify?: (input: Input) => string): Promise<Primitive<Output>>;
|
|
40
|
+
}
|
|
41
|
+
export declare namespace Fetcher {
|
|
42
|
+
/**
|
|
43
|
+
* Whether be encrypted or not.
|
|
44
|
+
*
|
|
45
|
+
* `Fetcher.IEncrypted` is a type of interface who represents whether the HTTP request
|
|
46
|
+
* and response body must be encrypted or not.
|
|
47
|
+
*
|
|
48
|
+
* Like the {@link Fetcher} who are being used by all of the SDK libraries that are
|
|
49
|
+
* generated by the [Nestia](https://github.com/samchon/nestia), this `IEncrypted`
|
|
50
|
+
* interface would be used by the [Nestia](https://github.com/samchon/nestia) generated
|
|
51
|
+
* SDK libaries.
|
|
52
|
+
*
|
|
53
|
+
* As this `Fetcher` be used only by the [**Nestia**](https://github.com/samchon/nestia)
|
|
54
|
+
* generated SDK libraries, you don't need to handle this class directly. It may only be
|
|
55
|
+
* appeared in the source codes of the [**Nestia**](https://github.com/samchon/nestia)
|
|
56
|
+
* generated SDK libraries.
|
|
57
|
+
*/
|
|
58
|
+
interface IEncrypted {
|
|
59
|
+
/**
|
|
60
|
+
* Whether the request body be encrypted or not.
|
|
61
|
+
*/
|
|
62
|
+
request?: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Whether the response body be encrypted or not.
|
|
65
|
+
*/
|
|
66
|
+
response: boolean;
|
|
67
|
+
}
|
|
68
|
+
}
|
package/lib/Fetcher.js
ADDED
|
@@ -0,0 +1,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 (_) 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
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
77
|
+
var init, body_1, headers, password, url, response, body, headers, password, ret;
|
|
78
|
+
return __generator(this, function (_a) {
|
|
79
|
+
switch (_a.label) {
|
|
80
|
+
case 0:
|
|
81
|
+
if (encrypted.request === true || encrypted.response === true)
|
|
82
|
+
if (connection.encryption === undefined)
|
|
83
|
+
throw new Error("Error on nestia.Fetcher.encrypt(): the encryption password has not been configured.");
|
|
84
|
+
init = {
|
|
85
|
+
method: method,
|
|
86
|
+
headers: encrypted.request === false &&
|
|
87
|
+
input !== undefined &&
|
|
88
|
+
typeof input === "object"
|
|
89
|
+
? __assign(__assign({}, connection.headers), { "Content-Type": "application/json" }) : connection.headers,
|
|
90
|
+
};
|
|
91
|
+
// REQUEST BODY (WITH ENCRYPTION)
|
|
92
|
+
if (input !== undefined) {
|
|
93
|
+
body_1 = (stringify || JSON.stringify)(input);
|
|
94
|
+
if (encrypted.request === true) {
|
|
95
|
+
headers = new Singleton_1.Singleton(function () { return init.headers; });
|
|
96
|
+
password = connection.encryption instanceof Function
|
|
97
|
+
? connection.encryption({ headers: headers.get(), body: body_1 }, true)
|
|
98
|
+
: connection.encryption;
|
|
99
|
+
if (is_disabled(password, headers, body_1, true) === false)
|
|
100
|
+
body_1 = AesPkcs5_1.AesPkcs5.encrypt(body_1, password.key, password.iv);
|
|
101
|
+
}
|
|
102
|
+
init.body = body_1;
|
|
103
|
+
}
|
|
104
|
+
//----
|
|
105
|
+
// RESPONSE MESSAGE
|
|
106
|
+
//----
|
|
107
|
+
// URL SPECIFICATION
|
|
108
|
+
if (connection.host[connection.host.length - 1] !== "/" &&
|
|
109
|
+
path[0] !== "/")
|
|
110
|
+
path = "/" + path;
|
|
111
|
+
url = new URL("".concat(connection.host).concat(path));
|
|
112
|
+
return [4 /*yield*/, polyfill.get()];
|
|
113
|
+
case 1: return [4 /*yield*/, (_a.sent())(url.href, init)];
|
|
114
|
+
case 2:
|
|
115
|
+
response = _a.sent();
|
|
116
|
+
return [4 /*yield*/, response.text()];
|
|
117
|
+
case 3:
|
|
118
|
+
body = _a.sent();
|
|
119
|
+
if (!body)
|
|
120
|
+
return [2 /*return*/, undefined];
|
|
121
|
+
// CHECK THE STATUS CODE
|
|
122
|
+
if (response.status !== 200 && response.status !== 201)
|
|
123
|
+
throw new HttpError_1.HttpError(method, path, response.status, body);
|
|
124
|
+
// FINALIZATION (WITH DECODING)
|
|
125
|
+
if (encrypted.response === true) {
|
|
126
|
+
headers = new Singleton_1.Singleton(function () { return headers_to_object(response.headers); });
|
|
127
|
+
password = connection.encryption instanceof Function
|
|
128
|
+
? connection.encryption({ headers: headers.get(), body: body }, false)
|
|
129
|
+
: connection.encryption;
|
|
130
|
+
if (is_disabled(password, headers, body, false) === false)
|
|
131
|
+
body = AesPkcs5_1.AesPkcs5.decrypt(body, password.key, password.iv);
|
|
132
|
+
}
|
|
133
|
+
ret = body;
|
|
134
|
+
try {
|
|
135
|
+
// PARSE RESPONSE BODY
|
|
136
|
+
ret = JSON.parse(ret);
|
|
137
|
+
// FIND __SET_HEADERS__ FIELD
|
|
138
|
+
if (ret.__set_headers__ !== undefined &&
|
|
139
|
+
typeof ret.__set_headers__ === "object") {
|
|
140
|
+
if (connection.headers === undefined)
|
|
141
|
+
connection.headers = {};
|
|
142
|
+
Object.assign(connection.headers, ret.__set_headers__);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
catch (_b) { }
|
|
146
|
+
// RETURNS
|
|
147
|
+
return [2 /*return*/, ret];
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
return Fetcher;
|
|
153
|
+
}());
|
|
154
|
+
exports.Fetcher = Fetcher;
|
|
155
|
+
var polyfill = new Singleton_1.Singleton(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
156
|
+
var _a;
|
|
157
|
+
return __generator(this, function (_b) {
|
|
158
|
+
switch (_b.label) {
|
|
159
|
+
case 0:
|
|
160
|
+
if (!(typeof global === "object" &&
|
|
161
|
+
typeof global.process === "object" &&
|
|
162
|
+
typeof global.process.versions === "object" &&
|
|
163
|
+
typeof global.process.versions.node !== undefined)) return [3 /*break*/, 3];
|
|
164
|
+
if (!(global.fetch === undefined)) return [3 /*break*/, 2];
|
|
165
|
+
_a = global;
|
|
166
|
+
return [4 /*yield*/, (0, import2_1.default)("node-fetch")];
|
|
167
|
+
case 1:
|
|
168
|
+
_a.fetch = (_b.sent()).default;
|
|
169
|
+
_b.label = 2;
|
|
170
|
+
case 2: return [2 /*return*/, global.fetch];
|
|
171
|
+
case 3: return [2 /*return*/, window.fetch];
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
}); });
|
|
175
|
+
function is_disabled(password, headers, body, encoded) {
|
|
176
|
+
if (password.disabled === undefined)
|
|
177
|
+
return false;
|
|
178
|
+
if (typeof password.disabled === "function")
|
|
179
|
+
return password.disabled({
|
|
180
|
+
headers: headers.get(),
|
|
181
|
+
body: body,
|
|
182
|
+
}, encoded);
|
|
183
|
+
return password.disabled;
|
|
184
|
+
}
|
|
185
|
+
function headers_to_object(headers) {
|
|
186
|
+
var output = {};
|
|
187
|
+
headers.forEach(function (value, key) { return (output[key] = value); });
|
|
188
|
+
return output;
|
|
189
|
+
}
|
|
190
|
+
//# sourceMappingURL=Fetcher.js.map
|
|
@@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
+
*/
|
|
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
|
+
}
|
package/lib/HttpError.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
// INHERITANCE POLYFILL
|
|
43
|
+
var proto = _newTarget.prototype;
|
|
44
|
+
if (Object.setPrototypeOf)
|
|
45
|
+
Object.setPrototypeOf(_this, proto);
|
|
46
|
+
else
|
|
47
|
+
_this.__proto__ = proto;
|
|
48
|
+
return _this;
|
|
49
|
+
}
|
|
50
|
+
return HttpError;
|
|
51
|
+
}(Error));
|
|
52
|
+
exports.HttpError = HttpError;
|
|
53
|
+
//# sourceMappingURL=HttpError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpError.js","sourceRoot":"","sources":["../src/HttpError.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;GAMG;AACH;IAA+B,6BAAK;IAChC;;;;;;;OAOG;IACH,mBACoB,MAAmD,EACnD,IAAY,EACZ,MAAc,EAC9B,OAAe;;QAJnB,YAMI,kBAAM,OAAO,CAAC,SAMjB;QAXmB,YAAM,GAAN,MAAM,CAA6C;QACnD,UAAI,GAAJ,IAAI,CAAQ;QACZ,YAAM,GAAN,MAAM,CAAQ;QAK9B,uBAAuB;QACvB,IAAM,KAAK,GAAc,WAAW,SAAS,CAAC;QAC9C,IAAI,MAAM,CAAC,cAAc;YAAE,MAAM,CAAC,cAAc,CAAC,KAAI,EAAE,KAAK,CAAC,CAAC;;YACxD,KAAY,CAAC,SAAS,GAAG,KAAK,CAAC;;IACzC,CAAC;IACL,gBAAC;AAAD,CAAC,AAtBD,CAA+B,KAAK,GAsBnC;AAtBY,8BAAS"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { IEncryptionPassword } from "./IEncryptionPassword";
|
|
2
|
+
/**
|
|
3
|
+
* Connection information.
|
|
4
|
+
*
|
|
5
|
+
* `IConnection` is a type of interface who represents connection information of the remote
|
|
6
|
+
* HTTP server. You can target the remote HTTP server by wring the {@link IConnection.host}
|
|
7
|
+
* variable down. Also, you can configure special header values by specializing the
|
|
8
|
+
* {@link IConnection.headers} variable.
|
|
9
|
+
*
|
|
10
|
+
* If the remote HTTP server encrypts or decrypts its body data through the AES-128/256
|
|
11
|
+
* algorithm, specify the {@link IConnection.encryption} with {@link IEncryptionPassword}
|
|
12
|
+
* or {@link IEncryptionPassword.Closure} variable.
|
|
13
|
+
*
|
|
14
|
+
* @author Jenogho Nam - https://github.com/samchon
|
|
15
|
+
*/
|
|
16
|
+
export interface IConnection {
|
|
17
|
+
/**
|
|
18
|
+
* Host address of the remote HTTP server.
|
|
19
|
+
*/
|
|
20
|
+
host: string;
|
|
21
|
+
/**
|
|
22
|
+
* Header values delivered to the remote HTTP server.
|
|
23
|
+
*/
|
|
24
|
+
headers?: Record<string, string>;
|
|
25
|
+
/**
|
|
26
|
+
* Encryption password of its closure function.
|
|
27
|
+
*/
|
|
28
|
+
encryption?: IEncryptionPassword | IEncryptionPassword.Closure;
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IConnection.js","sourceRoot":"","sources":["../src/IConnection.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encryption password.
|
|
3
|
+
*
|
|
4
|
+
* `IEncryptionPassword` is a type of interface who represents encryption password used by
|
|
5
|
+
* the {@link Fetcher} with AES-128/256 algorithm. If your encryption password is not fixed
|
|
6
|
+
* but changes according to the input content, you can utilize the
|
|
7
|
+
* {@link IEncryptionPassword.Closure} function type.
|
|
8
|
+
*
|
|
9
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
10
|
+
*/
|
|
11
|
+
export interface IEncryptionPassword {
|
|
12
|
+
/**
|
|
13
|
+
* Secret key.
|
|
14
|
+
*/
|
|
15
|
+
key: string;
|
|
16
|
+
/**
|
|
17
|
+
* Initialization vector.
|
|
18
|
+
*/
|
|
19
|
+
iv: string;
|
|
20
|
+
/**
|
|
21
|
+
* Disable encryption to let content as plain.
|
|
22
|
+
*
|
|
23
|
+
* When you configure this `disabled` variable to be `false`, encryption and decryption
|
|
24
|
+
* algorithm would be disabled. Therefore, content like request or response body
|
|
25
|
+
* would be considered as a plain text instead.
|
|
26
|
+
*
|
|
27
|
+
* Default is `false`.
|
|
28
|
+
*/
|
|
29
|
+
disabled?: boolean | ((param: IEncryptionPassword.IParameter, encoded: boolean) => boolean);
|
|
30
|
+
}
|
|
31
|
+
export declare namespace IEncryptionPassword {
|
|
32
|
+
/**
|
|
33
|
+
* Type of a closure function returning the {@link IEncryptionPassword} object.
|
|
34
|
+
*
|
|
35
|
+
* `IEncryptionPassword.Closure` is a type of closure function who are returning the
|
|
36
|
+
* {@link IEncryptionPassword} object. It would be used when your encryption password
|
|
37
|
+
* be changed according to the input content.
|
|
38
|
+
*/
|
|
39
|
+
interface Closure {
|
|
40
|
+
/**
|
|
41
|
+
* Encryption password getter.
|
|
42
|
+
*
|
|
43
|
+
* @param param Request or response headers and body content
|
|
44
|
+
* @param encoded Be encoded or to be decoded
|
|
45
|
+
* @returns Encryption password
|
|
46
|
+
*/
|
|
47
|
+
(param: IParameter, encoded: boolean): IEncryptionPassword;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Parameter for the closure.
|
|
51
|
+
*/
|
|
52
|
+
interface IParameter {
|
|
53
|
+
headers: Record<string, string>;
|
|
54
|
+
body: string;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IEncryptionPassword.js","sourceRoot":"","sources":["../src/IEncryptionPassword.ts"],"names":[],"mappings":""}
|