drapcode-utility 2.1.4 → 2.2.1
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/build/encryption/KMS.d.ts +3 -6
- package/build/encryption/KMS.js +24 -16
- package/build/encryption/crypt.d.ts +4 -4
- package/build/encryption/crypt.js +80 -42
- package/build/encryption/file.js +4 -9
- package/build/encryption/index.d.ts +1 -37
- package/build/encryption/index.js +6 -74
- package/build/encryption/model.d.ts +6 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +1 -0
- package/build/utils/s3-util.d.ts +0 -4
- package/build/utils/s3-util.js +0 -17
- package/build/utils/util.js +4 -4
- package/package.json +3 -3
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import { AwsConfig } from "./model";
|
|
2
|
-
export declare const
|
|
3
|
-
|
|
4
|
-
data: string;
|
|
5
|
-
message: string;
|
|
6
|
-
}>;
|
|
1
|
+
import { AwsConfig, DecryptResponse, Encryption } from "./model";
|
|
2
|
+
export declare const processKey: (encryption: Encryption, encryptionType: string) => Promise<Encryption>;
|
|
3
|
+
export declare const processKMSDecryption: (config: AwsConfig, cipherText: string, context: any) => Promise<DecryptResponse>;
|
|
7
4
|
export declare const processKMSGenerateDataKey: (config: AwsConfig, arn: string) => Promise<{
|
|
8
5
|
status: string;
|
|
9
6
|
dataKey: string;
|
package/build/encryption/KMS.js
CHANGED
|
@@ -1,36 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.processKMSGenerateDataKey = exports.
|
|
3
|
+
exports.processKMSGenerateDataKey = exports.processKMSDecryption = exports.processKey = void 0;
|
|
4
4
|
const client_kms_1 = require("@aws-sdk/client-kms");
|
|
5
|
-
const
|
|
5
|
+
const processKey = async (encryption, encryptionType) => {
|
|
6
|
+
if (encryptionType !== "KMS") {
|
|
7
|
+
return encryption;
|
|
8
|
+
}
|
|
9
|
+
const plainTextData = await (0, exports.processKMSDecryption)(encryption.awsConfig, encryption.dataKey, {});
|
|
10
|
+
if (plainTextData.status === "SUCCESS") {
|
|
11
|
+
return { ...encryption, dataKey: plainTextData.data };
|
|
12
|
+
}
|
|
13
|
+
return encryption;
|
|
14
|
+
};
|
|
15
|
+
exports.processKey = processKey;
|
|
16
|
+
const processKMSDecryption = async (config, cipherText, context) => {
|
|
6
17
|
try {
|
|
7
18
|
const { accessKeyId, secretAccessKey, region } = config;
|
|
8
19
|
const client = new client_kms_1.KMSClient({
|
|
9
20
|
region,
|
|
10
21
|
credentials: { accessKeyId, secretAccessKey },
|
|
22
|
+
maxAttempts: 3,
|
|
11
23
|
});
|
|
24
|
+
const dCipherText = Buffer.from(cipherText, "base64");
|
|
12
25
|
const input = {
|
|
13
|
-
|
|
14
|
-
Plaintext: Buffer.from(plainText),
|
|
26
|
+
CiphertextBlob: dCipherText,
|
|
15
27
|
EncryptionContext: context,
|
|
16
28
|
};
|
|
17
|
-
const command = new client_kms_1.
|
|
29
|
+
const command = new client_kms_1.DecryptCommand(input);
|
|
18
30
|
const response = await client.send(command);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
return { status: "SUCCESS", data:
|
|
31
|
+
if (!response.Plaintext) {
|
|
32
|
+
throw new Error("Missing plaintext in KMS response.");
|
|
33
|
+
}
|
|
34
|
+
const plainText = Buffer.from(response.Plaintext).toString("base64");
|
|
35
|
+
return { status: "SUCCESS", data: plainText, message: "" };
|
|
24
36
|
}
|
|
25
37
|
catch (error) {
|
|
26
|
-
return {
|
|
27
|
-
status: "FAILED",
|
|
28
|
-
data: "",
|
|
29
|
-
message: error.message,
|
|
30
|
-
};
|
|
38
|
+
return { status: "FAILED", data: "", message: error.message };
|
|
31
39
|
}
|
|
32
40
|
};
|
|
33
|
-
exports.
|
|
41
|
+
exports.processKMSDecryption = processKMSDecryption;
|
|
34
42
|
const processKMSGenerateDataKey = async (config, arn) => {
|
|
35
43
|
try {
|
|
36
44
|
const { accessKeyId, secretAccessKey, region } = config;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const encryptData: (data: string, key: string) => string;
|
|
2
|
-
export declare const decryptData: (data: string, key: string) => string;
|
|
3
|
-
export declare const encryptFile: (filePath: string, key: string) => Promise<string>;
|
|
4
|
-
export declare const decryptFile: (encryptedFilePath: string, key: string) => Promise<string>;
|
|
1
|
+
export declare const encryptData: (data: string, key: string, iv?: string) => string;
|
|
2
|
+
export declare const decryptData: (data: string, key: string, iv?: string) => string;
|
|
3
|
+
export declare const encryptFile: (filePath: string, key: string, iv: string) => Promise<string>;
|
|
4
|
+
export declare const decryptFile: (encryptedFilePath: string, key: string, iv: string) => Promise<string>;
|
|
@@ -7,14 +7,19 @@ exports.decryptFile = exports.encryptFile = exports.decryptData = exports.encryp
|
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
8
|
const crypto_1 = __importDefault(require("crypto"));
|
|
9
9
|
const defaultAlgorithm = "aes-256-cbc";
|
|
10
|
-
const fixedIv =
|
|
11
|
-
const
|
|
10
|
+
const fixedIv = "i4mboZDwaNEC38YCzi77lw==";
|
|
11
|
+
const toBuffer = (base64) => Buffer.from(base64, "base64");
|
|
12
|
+
const createCipher = (key, iv) => crypto_1.default.createCipheriv(defaultAlgorithm, toBuffer(key), toBuffer(iv));
|
|
13
|
+
const createDecipher = (key, iv) => crypto_1.default.createDecipheriv(defaultAlgorithm, toBuffer(key), toBuffer(iv));
|
|
14
|
+
const encryptData = (data, key, iv) => {
|
|
12
15
|
try {
|
|
13
|
-
|
|
14
|
-
|
|
16
|
+
console.log("encryptData: key :>> ", key);
|
|
17
|
+
console.log("encryptData: iv :>> ", iv);
|
|
18
|
+
if (!iv)
|
|
19
|
+
iv = fixedIv;
|
|
20
|
+
const cipher = createCipher(key, iv);
|
|
15
21
|
const encrypted = Buffer.concat([cipher.update(`${data}`), cipher.final()]);
|
|
16
|
-
|
|
17
|
-
return handleExtraString(base64Encrypted, true);
|
|
22
|
+
return handleExtraString(encrypted.toString("base64"), true);
|
|
18
23
|
}
|
|
19
24
|
catch (error) {
|
|
20
25
|
console.error("\n Error: ", error);
|
|
@@ -22,12 +27,15 @@ const encryptData = (data, key) => {
|
|
|
22
27
|
}
|
|
23
28
|
};
|
|
24
29
|
exports.encryptData = encryptData;
|
|
25
|
-
const decryptData = (data, key) => {
|
|
30
|
+
const decryptData = (data, key, iv) => {
|
|
26
31
|
try {
|
|
32
|
+
console.log("decryptData: key :>> ", key);
|
|
33
|
+
console.log("decryptData: iv :>> ", iv);
|
|
27
34
|
const cleaned = handleExtraString(data, false);
|
|
28
|
-
const encryptedData =
|
|
29
|
-
|
|
30
|
-
|
|
35
|
+
const encryptedData = toBuffer(cleaned);
|
|
36
|
+
if (!iv)
|
|
37
|
+
iv = fixedIv;
|
|
38
|
+
const decipher = createDecipher(key, iv);
|
|
31
39
|
const decrypted = Buffer.concat([
|
|
32
40
|
decipher.update(encryptedData),
|
|
33
41
|
decipher.final(),
|
|
@@ -40,40 +48,70 @@ const decryptData = (data, key) => {
|
|
|
40
48
|
}
|
|
41
49
|
};
|
|
42
50
|
exports.decryptData = decryptData;
|
|
43
|
-
const encryptFile = async (filePath, key) => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
51
|
+
const encryptFile = async (filePath, key, iv) => {
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
try {
|
|
54
|
+
console.log("encryptFile: key :>> ", key);
|
|
55
|
+
console.log("encryptFile: iv :>> ", iv);
|
|
56
|
+
if (!iv)
|
|
57
|
+
iv = fixedIv;
|
|
58
|
+
const cipher = createCipher(key, iv);
|
|
59
|
+
const encryptedFilePath = filePath.endsWith(".enc")
|
|
60
|
+
? filePath
|
|
61
|
+
: `${filePath}.enc`;
|
|
62
|
+
const readStream = fs_1.default.createReadStream(filePath);
|
|
63
|
+
const writeStream = fs_1.default.createWriteStream(encryptedFilePath);
|
|
64
|
+
readStream
|
|
65
|
+
.pipe(cipher)
|
|
66
|
+
.pipe(writeStream)
|
|
67
|
+
.on("finish", () => {
|
|
68
|
+
console.log("File encrypted successfully (stream).");
|
|
69
|
+
resolve(encryptedFilePath);
|
|
70
|
+
})
|
|
71
|
+
.on("error", (err) => {
|
|
72
|
+
console.error("encryptFileStream error:", err);
|
|
73
|
+
reject(err);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
console.error("\n Error: ", error);
|
|
78
|
+
reject(error);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
59
81
|
};
|
|
60
82
|
exports.encryptFile = encryptFile;
|
|
61
|
-
const decryptFile = async (encryptedFilePath, key) => {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
83
|
+
const decryptFile = async (encryptedFilePath, key, iv) => {
|
|
84
|
+
return new Promise((resolve, reject) => {
|
|
85
|
+
try {
|
|
86
|
+
console.log("decryptFile: key :>> ", key);
|
|
87
|
+
console.log("decryptFile: iv :>> ", iv);
|
|
88
|
+
if (!iv)
|
|
89
|
+
iv = fixedIv;
|
|
90
|
+
const decipher = createDecipher(key, iv);
|
|
91
|
+
const readStream = fs_1.default.createReadStream(encryptedFilePath);
|
|
92
|
+
const decryptedFilePath = encryptedFilePath.endsWith(".enc")
|
|
93
|
+
? `${encryptedFilePath.slice(0, -4)}.dec`
|
|
94
|
+
: `${encryptedFilePath}.dec`;
|
|
95
|
+
const writeStream = fs_1.default.createWriteStream(decryptedFilePath);
|
|
96
|
+
readStream
|
|
97
|
+
.pipe(decipher)
|
|
98
|
+
.pipe(writeStream)
|
|
99
|
+
.on("finish", () => {
|
|
100
|
+
console.log("File decrypted successfully (stream).");
|
|
101
|
+
resolve(decryptedFilePath);
|
|
102
|
+
})
|
|
103
|
+
.on("error", (err) => {
|
|
104
|
+
console.error("decryptFileStream error:", err);
|
|
105
|
+
reject(err);
|
|
106
|
+
});
|
|
107
|
+
console.log("File decrypted successfully.");
|
|
108
|
+
return decryptedFilePath;
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
console.error("Error:", error);
|
|
112
|
+
reject(error);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
77
115
|
};
|
|
78
116
|
exports.decryptFile = decryptFile;
|
|
79
117
|
const handleExtraString = (key, append = true) => {
|
package/build/encryption/file.js
CHANGED
|
@@ -3,16 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.processFileEncryptionDecryption = void 0;
|
|
4
4
|
const crypt_1 = require("./crypt");
|
|
5
5
|
const processFileEncryptionDecryption = async (data, encryption, decrypt) => {
|
|
6
|
-
const {
|
|
6
|
+
const { dataKey, iv } = encryption;
|
|
7
7
|
if (!data)
|
|
8
8
|
return data;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
? await (0, crypt_1.decryptFile)(data, dataKey)
|
|
13
|
-
: await (0, crypt_1.encryptFile)(data, dataKey);
|
|
14
|
-
default:
|
|
15
|
-
return data;
|
|
16
|
-
}
|
|
9
|
+
return decrypt
|
|
10
|
+
? await (0, crypt_1.decryptFile)(data, dataKey, iv)
|
|
11
|
+
: await (0, crypt_1.encryptFile)(data, dataKey, iv);
|
|
17
12
|
};
|
|
18
13
|
exports.processFileEncryptionDecryption = processFileEncryptionDecryption;
|
|
@@ -14,41 +14,5 @@ export declare const createKMSDataKey: (config: AwsConfig, arn: string) => Promi
|
|
|
14
14
|
dataKey: string;
|
|
15
15
|
message: string;
|
|
16
16
|
}>;
|
|
17
|
-
|
|
18
|
-
* This method is used to encrypt plaintext upto 4KB
|
|
19
|
-
* It requires KMS config and ARN
|
|
20
|
-
* @param config AWS Config
|
|
21
|
-
* @param arn KMS Key
|
|
22
|
-
* @param plainText Text to be encrypted
|
|
23
|
-
* @param context Extra setting for extra security
|
|
24
|
-
* @returns {status: string, message: string, cipherText: string}
|
|
25
|
-
*/
|
|
26
|
-
export declare const encryptDataWithKMS: (config: AwsConfig, arn: string, plainText: string, context: any) => Promise<{
|
|
27
|
-
status: string;
|
|
28
|
-
data: string;
|
|
29
|
-
message: string;
|
|
30
|
-
}>;
|
|
31
|
-
/**
|
|
32
|
-
* This method is used to decrypt secure text
|
|
33
|
-
* It requires KMS config
|
|
34
|
-
* @param config AWS Config
|
|
35
|
-
* @param cipherText Encrypted Text
|
|
36
|
-
* @param context Extra setting which given for extra security
|
|
37
|
-
* @returns {status: string, message: string, plainText: string}
|
|
38
|
-
*/
|
|
39
|
-
export declare const decryptDataWithKMS: (config: AwsConfig, cipherText: string, context: any) => Promise<{
|
|
40
|
-
status: string;
|
|
41
|
-
data: string;
|
|
42
|
-
message: string;
|
|
43
|
-
}>;
|
|
44
|
-
export declare const drapcodeEncryptDecrypt: (data: string, encrypt: boolean) => Promise<{
|
|
45
|
-
status: string;
|
|
46
|
-
data: string;
|
|
47
|
-
message: string;
|
|
48
|
-
}>;
|
|
17
|
+
export declare const drapcodeEncryptDecrypt: (data: string, encrypt: boolean) => Promise<import("./model").DecryptResponse>;
|
|
49
18
|
export declare const cryptFile: (filePath: any, encryption: Encryption, decrypt: boolean) => Promise<string>;
|
|
50
|
-
export declare const processKMSDecryption: (config: AwsConfig, cipherText: string, context: any) => Promise<{
|
|
51
|
-
status: string;
|
|
52
|
-
data: string;
|
|
53
|
-
message: string;
|
|
54
|
-
}>;
|
|
@@ -1,25 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const client_kms_1 = require("@aws-sdk/client-kms");
|
|
3
|
+
exports.cryptFile = exports.drapcodeEncryptDecrypt = exports.createKMSDataKey = exports.processDataEncryptionDecryption = exports.processItemEncryptDecrypt = exports.crypt = void 0;
|
|
5
4
|
const drapcode_constant_1 = require("drapcode-constant");
|
|
6
5
|
const crypt_1 = require("./crypt");
|
|
7
6
|
const file_1 = require("./file");
|
|
8
7
|
const KMS_1 = require("./KMS");
|
|
9
8
|
const crypt = async (data, fields, encryption, decrypt, encryptedRefCollections = []) => {
|
|
10
|
-
if (encryption.encryptionType === "KMS") {
|
|
11
|
-
const { accessKeyId, secretAccessKey, region } = encryption.awsConfig;
|
|
12
|
-
const config = {
|
|
13
|
-
region,
|
|
14
|
-
accessKeyId,
|
|
15
|
-
secretAccessKey,
|
|
16
|
-
};
|
|
17
|
-
const plainTextData = await (0, exports.processKMSDecryption)(config, encryption.dataKey, {});
|
|
18
|
-
if (plainTextData.status === "FAILED") {
|
|
19
|
-
return plainTextData;
|
|
20
|
-
}
|
|
21
|
-
encryption.dataKey = plainTextData.data;
|
|
22
|
-
}
|
|
23
9
|
if (Array.isArray(data)) {
|
|
24
10
|
const promises = data.map((item) => (0, exports.processItemEncryptDecrypt)(item, fields, encryption, decrypt, encryptedRefCollections));
|
|
25
11
|
data = await Promise.all(promises);
|
|
@@ -63,15 +49,12 @@ const processItemEncryptDecrypt = async (item, fields, encryption, decrypt, encr
|
|
|
63
49
|
};
|
|
64
50
|
exports.processItemEncryptDecrypt = processItemEncryptDecrypt;
|
|
65
51
|
const processDataEncryptionDecryption = async (data, encryption, decrypt) => {
|
|
66
|
-
const { encryptionType, dataKey } = encryption;
|
|
67
52
|
if (!data)
|
|
68
53
|
return data;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return data;
|
|
74
|
-
}
|
|
54
|
+
const { dataKey, iv } = encryption;
|
|
55
|
+
return decrypt
|
|
56
|
+
? (0, crypt_1.decryptData)(data, dataKey, iv)
|
|
57
|
+
: (0, crypt_1.encryptData)(data, dataKey, iv);
|
|
75
58
|
};
|
|
76
59
|
exports.processDataEncryptionDecryption = processDataEncryptionDecryption;
|
|
77
60
|
const processReferenceItemDecrypt = async (data, encryption, decrypt, refField, encryptedRefCollections) => {
|
|
@@ -104,33 +87,6 @@ const createKMSDataKey = async (config, arn) => {
|
|
|
104
87
|
return dataKeyRes;
|
|
105
88
|
};
|
|
106
89
|
exports.createKMSDataKey = createKMSDataKey;
|
|
107
|
-
/**
|
|
108
|
-
* This method is used to encrypt plaintext upto 4KB
|
|
109
|
-
* It requires KMS config and ARN
|
|
110
|
-
* @param config AWS Config
|
|
111
|
-
* @param arn KMS Key
|
|
112
|
-
* @param plainText Text to be encrypted
|
|
113
|
-
* @param context Extra setting for extra security
|
|
114
|
-
* @returns {status: string, message: string, cipherText: string}
|
|
115
|
-
*/
|
|
116
|
-
const encryptDataWithKMS = async (config, arn, plainText, context) => {
|
|
117
|
-
const cryptData = await (0, KMS_1.processKMSEncryption)(config, arn, plainText, context);
|
|
118
|
-
return cryptData;
|
|
119
|
-
};
|
|
120
|
-
exports.encryptDataWithKMS = encryptDataWithKMS;
|
|
121
|
-
/**
|
|
122
|
-
* This method is used to decrypt secure text
|
|
123
|
-
* It requires KMS config
|
|
124
|
-
* @param config AWS Config
|
|
125
|
-
* @param cipherText Encrypted Text
|
|
126
|
-
* @param context Extra setting which given for extra security
|
|
127
|
-
* @returns {status: string, message: string, plainText: string}
|
|
128
|
-
*/
|
|
129
|
-
const decryptDataWithKMS = async (config, cipherText, context) => {
|
|
130
|
-
const plainTextData = await (0, exports.processKMSDecryption)(config, cipherText, context);
|
|
131
|
-
return plainTextData;
|
|
132
|
-
};
|
|
133
|
-
exports.decryptDataWithKMS = decryptDataWithKMS;
|
|
134
90
|
const drapcodeEncryptDecrypt = async (data, encrypt) => {
|
|
135
91
|
const region = process.env.AWS_KMS_REGION;
|
|
136
92
|
const accessKey = process.env.AWS_KMS_ACCESS_KEY;
|
|
@@ -158,7 +114,7 @@ const drapcodeEncryptDecrypt = async (data, encrypt) => {
|
|
|
158
114
|
secretAccessKey: secretKey,
|
|
159
115
|
};
|
|
160
116
|
//Generate Public Key from
|
|
161
|
-
const plainTextData = await (0,
|
|
117
|
+
const plainTextData = await (0, KMS_1.processKMSDecryption)(config, privateDataKey, {});
|
|
162
118
|
if (plainTextData.status === "FAILED") {
|
|
163
119
|
return plainTextData;
|
|
164
120
|
}
|
|
@@ -180,27 +136,3 @@ const cryptFile = async (filePath, encryption, decrypt) => {
|
|
|
180
136
|
return data;
|
|
181
137
|
};
|
|
182
138
|
exports.cryptFile = cryptFile;
|
|
183
|
-
const processKMSDecryption = async (config, cipherText, context) => {
|
|
184
|
-
try {
|
|
185
|
-
const { accessKeyId, secretAccessKey, region } = config;
|
|
186
|
-
const client = new client_kms_1.KMSClient({
|
|
187
|
-
region,
|
|
188
|
-
credentials: { accessKeyId, secretAccessKey },
|
|
189
|
-
maxAttempts: 3,
|
|
190
|
-
});
|
|
191
|
-
const dCipherText = Buffer.from(cipherText, "base64");
|
|
192
|
-
const input = {
|
|
193
|
-
CiphertextBlob: dCipherText,
|
|
194
|
-
EncryptionContext: context,
|
|
195
|
-
};
|
|
196
|
-
const command = new client_kms_1.DecryptCommand(input);
|
|
197
|
-
const response = await client.send(command);
|
|
198
|
-
//@ts-ignore it is important else it will throw error
|
|
199
|
-
const plainText = Buffer.from(response.Plaintext).toString("base64");
|
|
200
|
-
return { status: "SUCCESS", data: plainText, message: "" };
|
|
201
|
-
}
|
|
202
|
-
catch (error) {
|
|
203
|
-
return { status: "FAILED", data: "", message: error.message };
|
|
204
|
-
}
|
|
205
|
-
};
|
|
206
|
-
exports.processKMSDecryption = processKMSDecryption;
|
package/build/index.d.ts
CHANGED
|
@@ -16,5 +16,6 @@ export * from "./utils/common-util";
|
|
|
16
16
|
export * from "./utils/rest-client";
|
|
17
17
|
export * from "./encryption/index";
|
|
18
18
|
export * from "./encryption/utility";
|
|
19
|
+
export * from "./encryption/KMS";
|
|
19
20
|
export * from "./format-fields/index";
|
|
20
21
|
export * from "./utils/token";
|
package/build/index.js
CHANGED
|
@@ -32,5 +32,6 @@ __exportStar(require("./utils/common-util"), exports);
|
|
|
32
32
|
__exportStar(require("./utils/rest-client"), exports);
|
|
33
33
|
__exportStar(require("./encryption/index"), exports);
|
|
34
34
|
__exportStar(require("./encryption/utility"), exports);
|
|
35
|
+
__exportStar(require("./encryption/KMS"), exports);
|
|
35
36
|
__exportStar(require("./format-fields/index"), exports);
|
|
36
37
|
__exportStar(require("./utils/token"), exports);
|
package/build/utils/s3-util.d.ts
CHANGED
|
@@ -13,10 +13,6 @@ interface S3Config {
|
|
|
13
13
|
}
|
|
14
14
|
export declare const createS3Client: (awsConfig: AWSConfig) => S3Client | null;
|
|
15
15
|
export declare const fileUploadToS3: (files: any, s3Client: S3Client, s3Config: S3Config, publicS3Client: S3Client, publicS3Config: S3Config, isGenerateIcons: boolean, encryption: Encryption, options?: {}) => Promise<{
|
|
16
|
-
status: string;
|
|
17
|
-
data: string;
|
|
18
|
-
message: string;
|
|
19
|
-
} | {
|
|
20
16
|
originalname: any;
|
|
21
17
|
mimetype: any;
|
|
22
18
|
size: any;
|
package/build/utils/s3-util.js
CHANGED
|
@@ -10,7 +10,6 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
10
10
|
const mime_types_1 = __importDefault(require("mime-types"));
|
|
11
11
|
const lib_storage_1 = require("@aws-sdk/lib-storage");
|
|
12
12
|
const encryption_1 = require("../encryption");
|
|
13
|
-
const encryption_2 = require("../encryption");
|
|
14
13
|
const uuid_1 = require("uuid");
|
|
15
14
|
const gm_1 = __importDefault(require("gm"));
|
|
16
15
|
const svgo_1 = require("svgo");
|
|
@@ -33,22 +32,6 @@ const createS3Client = (awsConfig) => {
|
|
|
33
32
|
};
|
|
34
33
|
exports.createS3Client = createS3Client;
|
|
35
34
|
const fileUploadToS3 = async (files, s3Client, s3Config, publicS3Client, publicS3Config, isGenerateIcons, encryption, options = {}) => {
|
|
36
|
-
if (encryption) {
|
|
37
|
-
const { awsConfig, encryptionType, dataKey } = encryption;
|
|
38
|
-
if (encryptionType === "KMS") {
|
|
39
|
-
const { accessKeyId, secretAccessKey, region } = awsConfig;
|
|
40
|
-
const config = {
|
|
41
|
-
region,
|
|
42
|
-
accessKeyId,
|
|
43
|
-
secretAccessKey,
|
|
44
|
-
};
|
|
45
|
-
const plainTextData = await (0, encryption_2.processKMSDecryption)(config, dataKey, {});
|
|
46
|
-
if (plainTextData.status === "FAILED") {
|
|
47
|
-
return plainTextData;
|
|
48
|
-
}
|
|
49
|
-
encryption.dataKey = plainTextData.data;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
35
|
if (Array.isArray(files)) {
|
|
53
36
|
const fileOptions = [];
|
|
54
37
|
const s3Key = s3Config.key;
|
package/build/utils/util.js
CHANGED
|
@@ -890,7 +890,7 @@ const addition = function (formatType, { numbers }) {
|
|
|
890
890
|
}
|
|
891
891
|
numbers = numbers.map((number) => (isNaN(number) ? 0 : number));
|
|
892
892
|
const allNumbers = (0, exports.validateNumbers)(numbers);
|
|
893
|
-
return (0, numeral_1.default)(mathjs_1.default.
|
|
893
|
+
return (0, numeral_1.default)(mathjs_1.default.sum(allNumbers)).format(formatType ? formatType : "00.00");
|
|
894
894
|
}
|
|
895
895
|
catch (err) {
|
|
896
896
|
console.log("🚀 ~ file: util.js:89 ~ addition ~ error:", err);
|
|
@@ -901,10 +901,10 @@ exports.addition = addition;
|
|
|
901
901
|
const substraction = function (formatType, { numbers1, numbers2 }) {
|
|
902
902
|
try {
|
|
903
903
|
const actNumber1 = Array.isArray(numbers1)
|
|
904
|
-
? mathjs_1.default.
|
|
904
|
+
? mathjs_1.default.sum(...numbers1)
|
|
905
905
|
: numbers1;
|
|
906
906
|
const actNumber2 = Array.isArray(numbers2)
|
|
907
|
-
? mathjs_1.default.
|
|
907
|
+
? mathjs_1.default.sum(...numbers2)
|
|
908
908
|
: numbers2;
|
|
909
909
|
return (0, numeral_1.default)(mathjs_1.default.subtract(actNumber1, actNumber2)).format(formatType ? formatType : "00.00");
|
|
910
910
|
}
|
|
@@ -936,7 +936,7 @@ const multiply = function (formatType, { numbers }) {
|
|
|
936
936
|
}
|
|
937
937
|
numbers = numbers.map((number) => (isNaN(number) ? 1 : number));
|
|
938
938
|
const allNumbers = (0, exports.validateNumbers)(numbers);
|
|
939
|
-
return (0, numeral_1.default)(mathjs_1.default.
|
|
939
|
+
return (0, numeral_1.default)(mathjs_1.default.prod(...allNumbers)).format(formatType ? formatType : "00.00");
|
|
940
940
|
}
|
|
941
941
|
catch (err) {
|
|
942
942
|
console.log("🚀 ~ file: util.js:106 ~ multiply ~ error:", err);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drapcode-utility",
|
|
3
|
-
"version": "2.1
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
"axios": "^1.1.2",
|
|
43
43
|
"date-fns": "^4.1.0",
|
|
44
44
|
"dompurify": "^3.1.7",
|
|
45
|
-
"drapcode-constant": "^1.
|
|
45
|
+
"drapcode-constant": "^1.9.1",
|
|
46
46
|
"drapcode-logger": "^1.3.5",
|
|
47
|
-
"drapcode-redis": "^1.3.
|
|
47
|
+
"drapcode-redis": "^1.3.6",
|
|
48
48
|
"exiftool-vendored": "^28.2.1",
|
|
49
49
|
"express": "^4.17.1",
|
|
50
50
|
"gm": "^1.25.0",
|