abbot-http-client 0.0.58 → 0.0.60
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/dist/index.cjs +69 -49
- package/dist/index.d.cts +10 -11
- package/dist/index.d.ts +10 -11
- package/dist/index.js +69 -49
- package/package.json +1 -2
package/dist/index.cjs
CHANGED
|
@@ -113,7 +113,71 @@ var AxiosBase = class {
|
|
|
113
113
|
};
|
|
114
114
|
|
|
115
115
|
// src/encryption/cryp.ts
|
|
116
|
-
var
|
|
116
|
+
var crypto = __toESM(require("crypto"), 1);
|
|
117
|
+
var Cryp = class _Cryp {
|
|
118
|
+
static TAG_SIZE = 16;
|
|
119
|
+
// bytes
|
|
120
|
+
static NONCE_SIZE = 12;
|
|
121
|
+
// bytes
|
|
122
|
+
static CHAR = "0123456789";
|
|
123
|
+
static ALGO = "aes-256-gcm";
|
|
124
|
+
key;
|
|
125
|
+
iv;
|
|
126
|
+
constructor(key, iv) {
|
|
127
|
+
this.key = key;
|
|
128
|
+
this.iv = iv ?? _Cryp.genIv();
|
|
129
|
+
}
|
|
130
|
+
encrypt(text) {
|
|
131
|
+
if (!text) return "";
|
|
132
|
+
const keyBuf = Buffer.from(this.key, "utf8");
|
|
133
|
+
const ivBuf = Buffer.from(this.iv, "utf8");
|
|
134
|
+
const cipher = crypto.createCipheriv(_Cryp.ALGO, keyBuf, ivBuf);
|
|
135
|
+
const encrypted = Buffer.concat([
|
|
136
|
+
cipher.update(text, "utf8"),
|
|
137
|
+
cipher.final()
|
|
138
|
+
]);
|
|
139
|
+
const tag = cipher.getAuthTag();
|
|
140
|
+
return Buffer.concat([encrypted, tag]).toString("base64");
|
|
141
|
+
}
|
|
142
|
+
decryptText(text) {
|
|
143
|
+
if (!text) return "";
|
|
144
|
+
const data = Buffer.from(text, "base64");
|
|
145
|
+
const ciphertext = data.subarray(0, data.length - _Cryp.TAG_SIZE);
|
|
146
|
+
const tag = data.subarray(data.length - _Cryp.TAG_SIZE);
|
|
147
|
+
const keyBuf = Buffer.from(this.key, "utf8");
|
|
148
|
+
const ivBuf = Buffer.from(this.iv, "utf8");
|
|
149
|
+
const decipher = crypto.createDecipheriv(_Cryp.ALGO, keyBuf, ivBuf);
|
|
150
|
+
decipher.setAuthTag(tag);
|
|
151
|
+
const decrypted = Buffer.concat([
|
|
152
|
+
decipher.update(ciphertext),
|
|
153
|
+
decipher.final()
|
|
154
|
+
]);
|
|
155
|
+
return decrypted.toString("utf8");
|
|
156
|
+
}
|
|
157
|
+
decrypt(text) {
|
|
158
|
+
if (!text) return null;
|
|
159
|
+
const data = Buffer.from(text, "base64");
|
|
160
|
+
const ciphertext = data.subarray(0, data.length - _Cryp.TAG_SIZE);
|
|
161
|
+
const tag = data.subarray(data.length - _Cryp.TAG_SIZE);
|
|
162
|
+
const keyBuf = Buffer.from(this.key, "utf8");
|
|
163
|
+
const ivBuf = Buffer.from(this.iv, "utf8");
|
|
164
|
+
const decipher = crypto.createDecipheriv(_Cryp.ALGO, keyBuf, ivBuf);
|
|
165
|
+
decipher.setAuthTag(tag);
|
|
166
|
+
const decrypted = Buffer.concat([
|
|
167
|
+
decipher.update(ciphertext),
|
|
168
|
+
decipher.final()
|
|
169
|
+
]).toString("utf8");
|
|
170
|
+
return JSON.parse(decrypted);
|
|
171
|
+
}
|
|
172
|
+
static genIv() {
|
|
173
|
+
let result = "";
|
|
174
|
+
for (let i = 0; i < _Cryp.NONCE_SIZE; i++) {
|
|
175
|
+
const index = Math.floor(Math.random() * _Cryp.CHAR.length);
|
|
176
|
+
result += _Cryp.CHAR[index];
|
|
177
|
+
}
|
|
178
|
+
return result;
|
|
179
|
+
}
|
|
180
|
+
};
|
|
117
181
|
|
|
118
182
|
// src/encryption/es.ts
|
|
119
183
|
var ES = class {
|
|
@@ -139,44 +203,6 @@ var ES = class {
|
|
|
139
203
|
}
|
|
140
204
|
};
|
|
141
205
|
|
|
142
|
-
// src/encryption/cryp.ts
|
|
143
|
-
var Cryp = class {
|
|
144
|
-
ivText;
|
|
145
|
-
key;
|
|
146
|
-
keyBuffer;
|
|
147
|
-
iv;
|
|
148
|
-
algConfig;
|
|
149
|
-
constructor(cryptProps, apiKey) {
|
|
150
|
-
this.ivText = cryptProps.iv;
|
|
151
|
-
this.key = cryptProps.keyValue ? cryptProps.keyValue : ES.d(ES.b2a(apiKey));
|
|
152
|
-
this.keyBuffer = import_crypto_ts.enc.Utf8.parse(this.key);
|
|
153
|
-
this.iv = import_crypto_ts.enc.Utf8.parse(this.ivText);
|
|
154
|
-
this.algConfig = { mode: import_crypto_ts.mode.CBC, padding: import_crypto_ts.pad.PKCS7, iv: this.iv };
|
|
155
|
-
}
|
|
156
|
-
encrypt(textValue) {
|
|
157
|
-
if (!textValue) return "";
|
|
158
|
-
if (!textValue.length) return textValue;
|
|
159
|
-
const cipher = import_crypto_ts.AES.encrypt(textValue, this.keyBuffer, this.algConfig);
|
|
160
|
-
return cipher.toString();
|
|
161
|
-
}
|
|
162
|
-
decrypt(encryptedValue) {
|
|
163
|
-
try {
|
|
164
|
-
if (!encryptedValue || !encryptedValue.length) return null;
|
|
165
|
-
const decryptValue = import_crypto_ts.AES.decrypt(
|
|
166
|
-
encryptedValue,
|
|
167
|
-
this.keyBuffer,
|
|
168
|
-
this.algConfig
|
|
169
|
-
);
|
|
170
|
-
const decryptData = decryptValue.toString(import_crypto_ts.enc.Utf8);
|
|
171
|
-
const jsonData = JSON.parse(decryptData);
|
|
172
|
-
return jsonData;
|
|
173
|
-
} catch (err) {
|
|
174
|
-
console.error(err);
|
|
175
|
-
return null;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
|
|
180
206
|
// src/encryption/secure.ts
|
|
181
207
|
var Secure = class {
|
|
182
208
|
static keySize = 16;
|
|
@@ -213,7 +239,7 @@ var AbbLog = class {
|
|
|
213
239
|
log = [];
|
|
214
240
|
constructor(cryp) {
|
|
215
241
|
this.cryp = cryp;
|
|
216
|
-
this.log.push(`[${(0, import_console_log_colors.blueBright)(cryp.
|
|
242
|
+
this.log.push(`[${(0, import_console_log_colors.blueBright)(cryp.iv)}]`);
|
|
217
243
|
this.log.push(`[${(0, import_console_log_colors.blueBright)(cryp.key)}]`);
|
|
218
244
|
}
|
|
219
245
|
logRequest(path, req) {
|
|
@@ -252,7 +278,7 @@ var AbbotHttp = class extends AxiosBase {
|
|
|
252
278
|
}
|
|
253
279
|
createAxiosInstance(option) {
|
|
254
280
|
const axios2 = this.axiosInstance();
|
|
255
|
-
const { cryp, iv } = this.prepareRequestConfig(
|
|
281
|
+
const { cryp, iv } = this.prepareRequestConfig();
|
|
256
282
|
axios2.cryp = cryp;
|
|
257
283
|
axios2.log = new AbbLog(cryp);
|
|
258
284
|
axios2.interceptors.request.use(
|
|
@@ -321,15 +347,9 @@ var AbbotHttp = class extends AxiosBase {
|
|
|
321
347
|
);
|
|
322
348
|
return axios2;
|
|
323
349
|
}
|
|
324
|
-
prepareRequestConfig(
|
|
350
|
+
prepareRequestConfig() {
|
|
325
351
|
const iv = Secure.createId();
|
|
326
|
-
const cryp = new Cryp(
|
|
327
|
-
{
|
|
328
|
-
iv,
|
|
329
|
-
keyValue: option?.isInit ? null : this.config.app.encKey
|
|
330
|
-
},
|
|
331
|
-
this.config.app.apiKey
|
|
332
|
-
);
|
|
352
|
+
const cryp = new Cryp(this.config.app.apiKey, iv);
|
|
333
353
|
const form = new URLSearchParams();
|
|
334
354
|
return { cryp, iv, form };
|
|
335
355
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -31,21 +31,20 @@ type DeepPartial<T> = T extends object ? {
|
|
|
31
31
|
declare function deepMerge<T>(target: T, source: DeepPartial<T>): T;
|
|
32
32
|
|
|
33
33
|
declare class Cryp {
|
|
34
|
-
|
|
34
|
+
private static readonly TAG_SIZE;
|
|
35
|
+
private static readonly NONCE_SIZE;
|
|
36
|
+
private static readonly CHAR;
|
|
37
|
+
private static readonly ALGO;
|
|
35
38
|
key: string;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}, apiKey: string);
|
|
43
|
-
encrypt(textValue?: string): string;
|
|
44
|
-
decrypt<T>(encryptedValue?: string): T | null;
|
|
39
|
+
iv: string;
|
|
40
|
+
constructor(key: string, iv?: string);
|
|
41
|
+
encrypt(text?: string): string;
|
|
42
|
+
decryptText(text?: string): string;
|
|
43
|
+
decrypt<T = any>(text?: string): T | null;
|
|
44
|
+
static genIv(): string;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
interface MethodOption {
|
|
48
|
-
isInit: boolean;
|
|
49
48
|
contentType: string;
|
|
50
49
|
responseType: ResponseType;
|
|
51
50
|
isDownload: boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -31,21 +31,20 @@ type DeepPartial<T> = T extends object ? {
|
|
|
31
31
|
declare function deepMerge<T>(target: T, source: DeepPartial<T>): T;
|
|
32
32
|
|
|
33
33
|
declare class Cryp {
|
|
34
|
-
|
|
34
|
+
private static readonly TAG_SIZE;
|
|
35
|
+
private static readonly NONCE_SIZE;
|
|
36
|
+
private static readonly CHAR;
|
|
37
|
+
private static readonly ALGO;
|
|
35
38
|
key: string;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}, apiKey: string);
|
|
43
|
-
encrypt(textValue?: string): string;
|
|
44
|
-
decrypt<T>(encryptedValue?: string): T | null;
|
|
39
|
+
iv: string;
|
|
40
|
+
constructor(key: string, iv?: string);
|
|
41
|
+
encrypt(text?: string): string;
|
|
42
|
+
decryptText(text?: string): string;
|
|
43
|
+
decrypt<T = any>(text?: string): T | null;
|
|
44
|
+
static genIv(): string;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
interface MethodOption {
|
|
48
|
-
isInit: boolean;
|
|
49
48
|
contentType: string;
|
|
50
49
|
responseType: ResponseType;
|
|
51
50
|
isDownload: boolean;
|
package/dist/index.js
CHANGED
|
@@ -66,7 +66,71 @@ var AxiosBase = class {
|
|
|
66
66
|
};
|
|
67
67
|
|
|
68
68
|
// src/encryption/cryp.ts
|
|
69
|
-
import
|
|
69
|
+
import * as crypto from "crypto";
|
|
70
|
+
var Cryp = class _Cryp {
|
|
71
|
+
static TAG_SIZE = 16;
|
|
72
|
+
// bytes
|
|
73
|
+
static NONCE_SIZE = 12;
|
|
74
|
+
// bytes
|
|
75
|
+
static CHAR = "0123456789";
|
|
76
|
+
static ALGO = "aes-256-gcm";
|
|
77
|
+
key;
|
|
78
|
+
iv;
|
|
79
|
+
constructor(key, iv) {
|
|
80
|
+
this.key = key;
|
|
81
|
+
this.iv = iv ?? _Cryp.genIv();
|
|
82
|
+
}
|
|
83
|
+
encrypt(text) {
|
|
84
|
+
if (!text) return "";
|
|
85
|
+
const keyBuf = Buffer.from(this.key, "utf8");
|
|
86
|
+
const ivBuf = Buffer.from(this.iv, "utf8");
|
|
87
|
+
const cipher = crypto.createCipheriv(_Cryp.ALGO, keyBuf, ivBuf);
|
|
88
|
+
const encrypted = Buffer.concat([
|
|
89
|
+
cipher.update(text, "utf8"),
|
|
90
|
+
cipher.final()
|
|
91
|
+
]);
|
|
92
|
+
const tag = cipher.getAuthTag();
|
|
93
|
+
return Buffer.concat([encrypted, tag]).toString("base64");
|
|
94
|
+
}
|
|
95
|
+
decryptText(text) {
|
|
96
|
+
if (!text) return "";
|
|
97
|
+
const data = Buffer.from(text, "base64");
|
|
98
|
+
const ciphertext = data.subarray(0, data.length - _Cryp.TAG_SIZE);
|
|
99
|
+
const tag = data.subarray(data.length - _Cryp.TAG_SIZE);
|
|
100
|
+
const keyBuf = Buffer.from(this.key, "utf8");
|
|
101
|
+
const ivBuf = Buffer.from(this.iv, "utf8");
|
|
102
|
+
const decipher = crypto.createDecipheriv(_Cryp.ALGO, keyBuf, ivBuf);
|
|
103
|
+
decipher.setAuthTag(tag);
|
|
104
|
+
const decrypted = Buffer.concat([
|
|
105
|
+
decipher.update(ciphertext),
|
|
106
|
+
decipher.final()
|
|
107
|
+
]);
|
|
108
|
+
return decrypted.toString("utf8");
|
|
109
|
+
}
|
|
110
|
+
decrypt(text) {
|
|
111
|
+
if (!text) return null;
|
|
112
|
+
const data = Buffer.from(text, "base64");
|
|
113
|
+
const ciphertext = data.subarray(0, data.length - _Cryp.TAG_SIZE);
|
|
114
|
+
const tag = data.subarray(data.length - _Cryp.TAG_SIZE);
|
|
115
|
+
const keyBuf = Buffer.from(this.key, "utf8");
|
|
116
|
+
const ivBuf = Buffer.from(this.iv, "utf8");
|
|
117
|
+
const decipher = crypto.createDecipheriv(_Cryp.ALGO, keyBuf, ivBuf);
|
|
118
|
+
decipher.setAuthTag(tag);
|
|
119
|
+
const decrypted = Buffer.concat([
|
|
120
|
+
decipher.update(ciphertext),
|
|
121
|
+
decipher.final()
|
|
122
|
+
]).toString("utf8");
|
|
123
|
+
return JSON.parse(decrypted);
|
|
124
|
+
}
|
|
125
|
+
static genIv() {
|
|
126
|
+
let result = "";
|
|
127
|
+
for (let i = 0; i < _Cryp.NONCE_SIZE; i++) {
|
|
128
|
+
const index = Math.floor(Math.random() * _Cryp.CHAR.length);
|
|
129
|
+
result += _Cryp.CHAR[index];
|
|
130
|
+
}
|
|
131
|
+
return result;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
70
134
|
|
|
71
135
|
// src/encryption/es.ts
|
|
72
136
|
var ES = class {
|
|
@@ -92,44 +156,6 @@ var ES = class {
|
|
|
92
156
|
}
|
|
93
157
|
};
|
|
94
158
|
|
|
95
|
-
// src/encryption/cryp.ts
|
|
96
|
-
var Cryp = class {
|
|
97
|
-
ivText;
|
|
98
|
-
key;
|
|
99
|
-
keyBuffer;
|
|
100
|
-
iv;
|
|
101
|
-
algConfig;
|
|
102
|
-
constructor(cryptProps, apiKey) {
|
|
103
|
-
this.ivText = cryptProps.iv;
|
|
104
|
-
this.key = cryptProps.keyValue ? cryptProps.keyValue : ES.d(ES.b2a(apiKey));
|
|
105
|
-
this.keyBuffer = enc.Utf8.parse(this.key);
|
|
106
|
-
this.iv = enc.Utf8.parse(this.ivText);
|
|
107
|
-
this.algConfig = { mode: mode.CBC, padding: pad.PKCS7, iv: this.iv };
|
|
108
|
-
}
|
|
109
|
-
encrypt(textValue) {
|
|
110
|
-
if (!textValue) return "";
|
|
111
|
-
if (!textValue.length) return textValue;
|
|
112
|
-
const cipher = AES.encrypt(textValue, this.keyBuffer, this.algConfig);
|
|
113
|
-
return cipher.toString();
|
|
114
|
-
}
|
|
115
|
-
decrypt(encryptedValue) {
|
|
116
|
-
try {
|
|
117
|
-
if (!encryptedValue || !encryptedValue.length) return null;
|
|
118
|
-
const decryptValue = AES.decrypt(
|
|
119
|
-
encryptedValue,
|
|
120
|
-
this.keyBuffer,
|
|
121
|
-
this.algConfig
|
|
122
|
-
);
|
|
123
|
-
const decryptData = decryptValue.toString(enc.Utf8);
|
|
124
|
-
const jsonData = JSON.parse(decryptData);
|
|
125
|
-
return jsonData;
|
|
126
|
-
} catch (err) {
|
|
127
|
-
console.error(err);
|
|
128
|
-
return null;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
|
|
133
159
|
// src/encryption/secure.ts
|
|
134
160
|
var Secure = class {
|
|
135
161
|
static keySize = 16;
|
|
@@ -166,7 +192,7 @@ var AbbLog = class {
|
|
|
166
192
|
log = [];
|
|
167
193
|
constructor(cryp) {
|
|
168
194
|
this.cryp = cryp;
|
|
169
|
-
this.log.push(`[${blueBright(cryp.
|
|
195
|
+
this.log.push(`[${blueBright(cryp.iv)}]`);
|
|
170
196
|
this.log.push(`[${blueBright(cryp.key)}]`);
|
|
171
197
|
}
|
|
172
198
|
logRequest(path, req) {
|
|
@@ -205,7 +231,7 @@ var AbbotHttp = class extends AxiosBase {
|
|
|
205
231
|
}
|
|
206
232
|
createAxiosInstance(option) {
|
|
207
233
|
const axios2 = this.axiosInstance();
|
|
208
|
-
const { cryp, iv } = this.prepareRequestConfig(
|
|
234
|
+
const { cryp, iv } = this.prepareRequestConfig();
|
|
209
235
|
axios2.cryp = cryp;
|
|
210
236
|
axios2.log = new AbbLog(cryp);
|
|
211
237
|
axios2.interceptors.request.use(
|
|
@@ -274,15 +300,9 @@ var AbbotHttp = class extends AxiosBase {
|
|
|
274
300
|
);
|
|
275
301
|
return axios2;
|
|
276
302
|
}
|
|
277
|
-
prepareRequestConfig(
|
|
303
|
+
prepareRequestConfig() {
|
|
278
304
|
const iv = Secure.createId();
|
|
279
|
-
const cryp = new Cryp(
|
|
280
|
-
{
|
|
281
|
-
iv,
|
|
282
|
-
keyValue: option?.isInit ? null : this.config.app.encKey
|
|
283
|
-
},
|
|
284
|
-
this.config.app.apiKey
|
|
285
|
-
);
|
|
305
|
+
const cryp = new Cryp(this.config.app.apiKey, iv);
|
|
286
306
|
const form = new URLSearchParams();
|
|
287
307
|
return { cryp, iv, form };
|
|
288
308
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "abbot-http-client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.60",
|
|
4
4
|
"description": "This package helps Abbot team to handle all the axios requests.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -20,7 +20,6 @@
|
|
|
20
20
|
"@types/node": "^24.0.14",
|
|
21
21
|
"axios": "^1.10.0",
|
|
22
22
|
"console-log-colors": "^0.5.0",
|
|
23
|
-
"crypto-ts": "^1.0.2",
|
|
24
23
|
"ts-node": "^10.9.2",
|
|
25
24
|
"typescript": "^5.8.3"
|
|
26
25
|
},
|