namirasoft-core 1.4.93 → 1.4.95
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/BaseServer.js +12 -9
- package/dist/BaseServer.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/BaseServer.ts +12 -9
- package/src/index.ts +0 -1
- package/dist/EncryptionOperation.d.ts +0 -6
- package/dist/EncryptionOperation.js +0 -71
- package/dist/EncryptionOperation.js.map +0 -1
- package/src/EncryptionOperation.ts +0 -41
package/dist/BaseServer.js
CHANGED
|
@@ -51,11 +51,15 @@ class BaseServer {
|
|
|
51
51
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
52
52
|
let url = URLOperation_1.URLOperation.getLink(this.base_url, sub, query);
|
|
53
53
|
if (!config)
|
|
54
|
-
config = {
|
|
55
|
-
if (
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
config = {};
|
|
55
|
+
if (!config.headers)
|
|
56
|
+
config.headers = {};
|
|
57
|
+
if (config.withCredentials == null)
|
|
58
|
+
config.withCredentials = true;
|
|
59
|
+
if (config.sign)
|
|
60
|
+
if ((_a = config.sign) === null || _a === void 0 ? void 0 : _a.header)
|
|
61
|
+
if ((_b = config.sign) === null || _b === void 0 ? void 0 : _b.key)
|
|
62
|
+
if (data)
|
|
59
63
|
config.headers[config.sign.header] = HashOperation_1.HashOperation.SHA256Secret(config.sign.key, data);
|
|
60
64
|
try {
|
|
61
65
|
(_c = config.onBeforeRequest) === null || _c === void 0 ? void 0 : _c.call(config, url, config);
|
|
@@ -74,11 +78,10 @@ class BaseServer {
|
|
|
74
78
|
let error_verbose = (_f = config.error_verbose) !== null && _f !== void 0 ? _f : this.error_verbose;
|
|
75
79
|
let error_suppress = (_g = config.error_suppress) !== null && _g !== void 0 ? _g : this.error_suppress;
|
|
76
80
|
if (error instanceof Error) {
|
|
77
|
-
if (
|
|
78
|
-
|
|
79
|
-
|
|
81
|
+
if (error_verbose)
|
|
82
|
+
error.message = `Error calling url '${url}' ` + error.message;
|
|
83
|
+
if (onError)
|
|
80
84
|
onError(error);
|
|
81
|
-
}
|
|
82
85
|
else {
|
|
83
86
|
ConsoleOperation_1.ConsoleOperation.warning("onError function has not been properly set.");
|
|
84
87
|
ConsoleOperation_1.ConsoleOperation.error(error === null || error === void 0 ? void 0 : error.message);
|
package/dist/BaseServer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseServer.js","sourceRoot":"","sources":["../src/BaseServer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAAiE;AACjE,mDAAgD;AAChD,iDAA8C;AAC9C,qDAAkD;AAElD,yDAAsD;AACtD,6CAA0C;AAC1C,2CAAwC;AAcxC,MAAsB,UAAU;IAErB,MAAM,CAAC,WAAW,CAAC,CAAM,EAAE,IAAY;;QAE1C,IAAI,eAAK,CAAC,YAAY,CAAC,CAAC,CAAC;YACrB,IAAI,CAAC,CAAC,QAAQ;gBACV,IAAI,CAAA,MAAA,CAAC,CAAC,QAAQ,0CAAE,MAAM,MAAK,IAAI;oBAC3B,OAAO,IAAI,CAAC;QACxB,IAAI,CAAC,YAAY,qBAAS;YACtB,IAAI,CAAC,CAAC,IAAI,KAAK,IAAI;gBACf,OAAO,IAAI,CAAC;QACpB,OAAO,KAAK,CAAA;IAChB,CAAC;IASD,YAAY,QAAgB;QANpB,qBAAgB,GAA2D,EAAE,CAAC;QAC9E,oBAAe,GAAkD,EAAE,CAAC;QAErE,mBAAc,GAAa,KAAK,CAAC;QACjC,kBAAa,GAAa,KAAK,CAAC;QAInC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,aAAa,GAAG,IAAI,uBAAU,CAAC,0BAA0B,EAAE,KAAK,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IAC7F,CAAC;IACM,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AE;gBAEhG,OAAO,MAAM,eAAK,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;YAC9C,CAAC,CAAA,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QACjC,CAAC;KAAA;IACY,MAAM,CAA+B,GAAW,EAAE,KAA2C,EAAE,IAAc,EAAE,MAAkC;;YAE1J,OAAO,MAAM,IAAI,CAAC,QAAQ,CAAC,CAAO,GAAW,EAAE,IAAa,EAAE,MAAkC,EAAE,EAAE;gBAEhG,OAAO,MAAM,eAAK,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;YAChD,CAAC,CAAA,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QACjC,CAAC;KAAA;IACY,OAAO,CAA+B,GAAW,EAAE,KAA2C,EAAE,MAAkC;;YAE3I,OAAO,MAAM,IAAI,CAAC,QAAQ,CAAC,CAAO,GAAW,EAAE,CAAO,EAAE,MAAkC,EAAE,EAAE;gBAE1F,OAAO,MAAM,eAAK,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;YAC3C,CAAC,CAAA,EAAE,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;QACtC,CAAC;KAAA;CACJ;AAjID,gCAiIC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -13,7 +13,6 @@ export * from "./ConvertService";
|
|
|
13
13
|
export * from "./Country";
|
|
14
14
|
export * from "./CountryOperation";
|
|
15
15
|
export * from "./EncodingOperation";
|
|
16
|
-
export * from "./EncryptionOperation";
|
|
17
16
|
export * from "./EnvService";
|
|
18
17
|
export * from "./ErrorOperation";
|
|
19
18
|
export * from "./FileOperation";
|
package/dist/index.js
CHANGED
|
@@ -29,7 +29,6 @@ __exportStar(require("./ConvertService"), exports);
|
|
|
29
29
|
__exportStar(require("./Country"), exports);
|
|
30
30
|
__exportStar(require("./CountryOperation"), exports);
|
|
31
31
|
__exportStar(require("./EncodingOperation"), exports);
|
|
32
|
-
__exportStar(require("./EncryptionOperation"), exports);
|
|
33
32
|
__exportStar(require("./EnvService"), exports);
|
|
34
33
|
__exportStar(require("./ErrorOperation"), exports);
|
|
35
34
|
__exportStar(require("./FileOperation"), exports);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,mDAAiC;AACjC,qDAAmC;AACnC,kDAAgC;AAChC,+CAA6B;AAC7B,6CAA2B;AAC3B,kDAAgC;AAChC,iDAA+B;AAC/B,qDAAmC;AACnC,kDAAgC;AAChC,8CAA4B;AAC5B,mDAAiC;AACjC,4CAA0B;AAC1B,qDAAmC;AACnC,sDAAoC;AACpC
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,mDAAiC;AACjC,qDAAmC;AACnC,kDAAgC;AAChC,+CAA6B;AAC7B,6CAA2B;AAC3B,kDAAgC;AAChC,iDAA+B;AAC/B,qDAAmC;AACnC,kDAAgC;AAChC,8CAA4B;AAC5B,mDAAiC;AACjC,4CAA0B;AAC1B,qDAAmC;AACnC,sDAAoC;AACpC,+CAA6B;AAC7B,mDAAiC;AACjC,kDAAgC;AAChC,+CAA6B;AAC7B,yDAAuC;AACvC,uDAAqC;AACrC,iDAA+B;AAC/B,kDAAgC;AAChC,8CAA4B;AAC5B,+CAA6B;AAC7B,6CAA2B;AAC3B,mDAAiC;AACjC,qDAAmC;AACnC,kDAAgC;AAChC,4DAA0C;AAC1C,yDAAuC;AACvC,oDAAkC;AAClC,qDAAmC;AACnC,kDAAgC;AAChC,mDAAiC;AACjC,oDAAkC;AAClC,sDAAoC;AACpC,mDAAiC;AACjC,mDAAiC;AACjC,oDAAkC;AAClC,6CAA2B;AAC3B,oDAAkC;AAClC,kDAAgC;AAChC,sDAAoC;AACpC,qDAAmC;AACnC,iDAA+B;AAC/B,qDAAmC"}
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"framework": "npm",
|
|
9
9
|
"application": "package",
|
|
10
10
|
"private": false,
|
|
11
|
-
"version": "1.4.
|
|
11
|
+
"version": "1.4.95",
|
|
12
12
|
"author": "Amir Abolhasani",
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"main": "./dist/index.js",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"build": ""
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@types/node": "^24.
|
|
20
|
+
"@types/node": "^24.7.0",
|
|
21
21
|
"async-mutex": "^0.5.0",
|
|
22
22
|
"axios": "^1.12.2",
|
|
23
23
|
"buffer": "^6.0.3",
|
package/src/BaseServer.ts
CHANGED
|
@@ -57,11 +57,16 @@ export abstract class BaseServer
|
|
|
57
57
|
{
|
|
58
58
|
let url: string = URLOperation.getLink(this.base_url, sub, query);
|
|
59
59
|
if (!config)
|
|
60
|
-
config = {
|
|
61
|
-
if (config.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
config = {};
|
|
61
|
+
if (!config.headers)
|
|
62
|
+
config.headers = {};
|
|
63
|
+
if (config.withCredentials == null)
|
|
64
|
+
config.withCredentials = true;
|
|
65
|
+
|
|
66
|
+
if (config.sign)
|
|
67
|
+
if (config.sign?.header)
|
|
68
|
+
if (config.sign?.key)
|
|
69
|
+
if (data)
|
|
65
70
|
config.headers[config.sign.header] = HashOperation.SHA256Secret(config.sign.key, data);
|
|
66
71
|
try
|
|
67
72
|
{
|
|
@@ -84,12 +89,10 @@ export abstract class BaseServer
|
|
|
84
89
|
let error_suppress = config.error_suppress ?? this.error_suppress;
|
|
85
90
|
if (error instanceof Error)
|
|
86
91
|
{
|
|
92
|
+
if (error_verbose)
|
|
93
|
+
error.message = `Error calling url '${url}' ` + error.message;
|
|
87
94
|
if (onError)
|
|
88
|
-
{
|
|
89
|
-
if (error_verbose)
|
|
90
|
-
error.message = `Error calling url '${url}' ` + error.message;
|
|
91
95
|
onError(error);
|
|
92
|
-
}
|
|
93
96
|
else
|
|
94
97
|
{
|
|
95
98
|
ConsoleOperation.warning("onError function has not been properly set.");
|
package/src/index.ts
CHANGED
|
@@ -13,7 +13,6 @@ export * from "./ConvertService";
|
|
|
13
13
|
export * from "./Country";
|
|
14
14
|
export * from "./CountryOperation";
|
|
15
15
|
export * from "./EncodingOperation";
|
|
16
|
-
export * from "./EncryptionOperation";
|
|
17
16
|
export * from "./EnvService";
|
|
18
17
|
export * from "./ErrorOperation";
|
|
19
18
|
export * from "./FileOperation";
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.EncryptionOperation = void 0;
|
|
37
|
-
const crypto = __importStar(require("node:crypto"));
|
|
38
|
-
class EncryptionOperation {
|
|
39
|
-
static encrypt(algorithm, secret, message) {
|
|
40
|
-
if (secret.length != 32)
|
|
41
|
-
throw new Error("Secret length must be exactly 32");
|
|
42
|
-
const secretBytes = Buffer.from(secret);
|
|
43
|
-
const iv = crypto.randomBytes(16);
|
|
44
|
-
const cipher = crypto.createCipheriv(algorithm, secretBytes, iv);
|
|
45
|
-
const encrypted = Buffer.concat([cipher.update(JSON.stringify(message), 'utf8'), cipher.final()]);
|
|
46
|
-
const authTag = cipher.getAuthTag();
|
|
47
|
-
const ivHex = iv.toString('hex');
|
|
48
|
-
const authTagHex = authTag.toString('hex');
|
|
49
|
-
const encryptedHex = encrypted.toString('hex');
|
|
50
|
-
return [ivHex, authTagHex, encryptedHex].join(";");
|
|
51
|
-
}
|
|
52
|
-
static decrypt(algorithm, secret, message) {
|
|
53
|
-
const [ivHex, authTagHex, encryptedHex] = message.split(';');
|
|
54
|
-
const iv = Buffer.from(ivHex, 'hex');
|
|
55
|
-
const authTag = Buffer.from(authTagHex, 'hex');
|
|
56
|
-
const encrypte = Buffer.from(encryptedHex, 'hex');
|
|
57
|
-
const decipher = crypto.createDecipheriv(algorithm, secret, iv);
|
|
58
|
-
decipher.setAuthTag(authTag);
|
|
59
|
-
let decrypted = decipher.update(encrypte);
|
|
60
|
-
decrypted = Buffer.concat([decrypted, decipher.final()]);
|
|
61
|
-
return JSON.parse(decrypted.toString());
|
|
62
|
-
}
|
|
63
|
-
static AES256GCMEncrypt(secret, message) {
|
|
64
|
-
return EncryptionOperation.encrypt("aes-256-gcm", secret, message);
|
|
65
|
-
}
|
|
66
|
-
static AES256GCMDecrypt(secret, message) {
|
|
67
|
-
return EncryptionOperation.decrypt("aes-256-gcm", secret, message);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
exports.EncryptionOperation = EncryptionOperation;
|
|
71
|
-
//# sourceMappingURL=EncryptionOperation.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EncryptionOperation.js","sourceRoot":"","sources":["../src/EncryptionOperation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAsC;AAEtC,MAAa,mBAAmB;IAEpB,MAAM,CAAC,OAAO,CAAI,SAAiB,EAAE,MAAc,EAAE,OAAU;QAEnE,IAAI,MAAM,CAAC,MAAM,IAAI,EAAE;YACnB,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;QACxD,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACxC,MAAM,EAAE,GAAG,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;QAClC,MAAM,MAAM,GAAG,MAAM,CAAC,cAAc,CAAC,SAAS,EAAE,WAAW,EAAE,EAAE,CAAC,CAAC;QACjE,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAClG,MAAM,OAAO,GAAI,MAAc,CAAC,UAAU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M,EAAE,OAAO,CAAC,CAAC;IACvE,CAAC;IACD,MAAM,CAAC,gBAAgB,CAAI,MAAc,EAAE,OAAe;QAEtD,OAAO,mBAAmB,CAAC,OAAO,CAAC,aAAa,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACvE,CAAC;CACJ;AAtCD,kDAsCC"}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import * as crypto from 'node:crypto';
|
|
2
|
-
|
|
3
|
-
export class EncryptionOperation
|
|
4
|
-
{
|
|
5
|
-
private static encrypt<T>(algorithm: string, secret: string, message: T): string
|
|
6
|
-
{
|
|
7
|
-
if (secret.length != 32)
|
|
8
|
-
throw new Error("Secret length must be exactly 32");
|
|
9
|
-
const secretBytes = Buffer.from(secret);
|
|
10
|
-
const iv = crypto.randomBytes(16);
|
|
11
|
-
const cipher = crypto.createCipheriv(algorithm, secretBytes, iv);
|
|
12
|
-
const encrypted = Buffer.concat([cipher.update(JSON.stringify(message), 'utf8'), cipher.final()]);
|
|
13
|
-
const authTag = (cipher as any).getAuthTag();
|
|
14
|
-
const ivHex = iv.toString('hex');
|
|
15
|
-
const authTagHex = authTag.toString('hex');
|
|
16
|
-
const encryptedHex = encrypted.toString('hex');
|
|
17
|
-
return [ivHex, authTagHex, encryptedHex].join(";");
|
|
18
|
-
}
|
|
19
|
-
private static decrypt<T>(algorithm: string, secret: string, message: string): T
|
|
20
|
-
{
|
|
21
|
-
const [ivHex, authTagHex, encryptedHex] = message.split(';');
|
|
22
|
-
const iv = Buffer.from(ivHex, 'hex');
|
|
23
|
-
const authTag = Buffer.from(authTagHex, 'hex');
|
|
24
|
-
const encrypte = Buffer.from(encryptedHex, 'hex');
|
|
25
|
-
|
|
26
|
-
const decipher = crypto.createDecipheriv(algorithm, secret, iv);
|
|
27
|
-
(decipher as any).setAuthTag(authTag);
|
|
28
|
-
|
|
29
|
-
let decrypted = decipher.update(encrypte);
|
|
30
|
-
decrypted = Buffer.concat([decrypted, decipher.final()]);
|
|
31
|
-
return JSON.parse(decrypted.toString());
|
|
32
|
-
}
|
|
33
|
-
static AES256GCMEncrypt<T>(secret: string, message: T): string
|
|
34
|
-
{
|
|
35
|
-
return EncryptionOperation.encrypt("aes-256-gcm", secret, message);
|
|
36
|
-
}
|
|
37
|
-
static AES256GCMDecrypt<T>(secret: string, message: string): T
|
|
38
|
-
{
|
|
39
|
-
return EncryptionOperation.decrypt("aes-256-gcm", secret, message);
|
|
40
|
-
}
|
|
41
|
-
}
|