@koralabs/kora-labs-common 6.4.18 → 6.4.19
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/aws/index.d.ts +2 -0
- package/aws/index.js +6 -0
- package/aws/kmsEnvironment.d.ts +9 -0
- package/aws/kmsEnvironment.js +33 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +2 -1
package/aws/index.d.ts
ADDED
package/aws/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hydrateKmsEnvironment = exports.decryptKmsCiphertext = void 0;
|
|
4
|
+
var kmsEnvironment_1 = require("./kmsEnvironment");
|
|
5
|
+
Object.defineProperty(exports, "decryptKmsCiphertext", { enumerable: true, get: function () { return kmsEnvironment_1.decryptKmsCiphertext; } });
|
|
6
|
+
Object.defineProperty(exports, "hydrateKmsEnvironment", { enumerable: true, get: function () { return kmsEnvironment_1.hydrateKmsEnvironment; } });
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { KMSClient } from '@aws-sdk/client-kms';
|
|
3
|
+
export type KmsClientLike = Pick<KMSClient, 'send'>;
|
|
4
|
+
export declare function decryptKmsCiphertext(ciphertext: string, client?: KmsClientLike): Promise<string>;
|
|
5
|
+
export declare function hydrateKmsEnvironment({ env, client, keys }?: {
|
|
6
|
+
env?: NodeJS.ProcessEnv;
|
|
7
|
+
client?: KmsClientLike;
|
|
8
|
+
keys?: string[];
|
|
9
|
+
}): Promise<string[]>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hydrateKmsEnvironment = exports.decryptKmsCiphertext = void 0;
|
|
4
|
+
const client_kms_1 = require("@aws-sdk/client-kms");
|
|
5
|
+
async function decryptKmsCiphertext(ciphertext, client = new client_kms_1.KMSClient({})) {
|
|
6
|
+
const response = await client.send(new client_kms_1.DecryptCommand({
|
|
7
|
+
CiphertextBlob: Buffer.from(ciphertext, 'base64')
|
|
8
|
+
}));
|
|
9
|
+
if (!response.Plaintext) {
|
|
10
|
+
throw new Error('KMS decrypt returned empty plaintext');
|
|
11
|
+
}
|
|
12
|
+
return Buffer.from(response.Plaintext).toString('utf8');
|
|
13
|
+
}
|
|
14
|
+
exports.decryptKmsCiphertext = decryptKmsCiphertext;
|
|
15
|
+
async function hydrateKmsEnvironment({ env = process.env, client = new client_kms_1.KMSClient({}), keys } = {}) {
|
|
16
|
+
const candidateKeys = (keys !== null && keys !== void 0 ? keys : Object.keys(env)
|
|
17
|
+
.filter((key) => key.endsWith('_ENC'))
|
|
18
|
+
.map((key) => key.slice(0, -4))).sort();
|
|
19
|
+
const hydratedKeys = [];
|
|
20
|
+
for (const key of candidateKeys) {
|
|
21
|
+
if (env[key]) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const ciphertext = env[`${key}_ENC`];
|
|
25
|
+
if (!ciphertext) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
env[key] = await decryptKmsCiphertext(ciphertext, client);
|
|
29
|
+
hydratedKeys.push(key);
|
|
30
|
+
}
|
|
31
|
+
return hydratedKeys;
|
|
32
|
+
}
|
|
33
|
+
exports.hydrateKmsEnvironment = hydrateKmsEnvironment;
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.ProtectedWords = exports.Logger = exports.LogCategory = exports.Environment = exports.ComputeEnvironment = void 0;
|
|
18
18
|
__exportStar(require("./constants"), exports);
|
|
19
|
+
__exportStar(require("./aws"), exports);
|
|
19
20
|
var environment_1 = require("./environment");
|
|
20
21
|
Object.defineProperty(exports, "ComputeEnvironment", { enumerable: true, get: function () { return environment_1.ComputeEnvironment; } });
|
|
21
22
|
Object.defineProperty(exports, "Environment", { enumerable: true, get: function () { return environment_1.Environment; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koralabs/kora-labs-common",
|
|
3
|
-
"version": "6.4.
|
|
3
|
+
"version": "6.4.19",
|
|
4
4
|
"description": "Kora Labs Common Utilities",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"typescript": "^4.7.3"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
+
"@aws-sdk/client-kms": "^3.1003.0",
|
|
42
43
|
"bech32": "^2.0.0",
|
|
43
44
|
"blakejs": "^1.2.1",
|
|
44
45
|
"boolean": "^3.2.0",
|