@naturalcycles/nodejs-lib 12.85.4 → 12.86.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.
|
@@ -24,11 +24,8 @@ export declare function loadSecretsFromEncryptedJsonFile(filePath: string, secre
|
|
|
24
24
|
* For whole-file encryption - use `loadSecretsFromEncryptedJsonFile`
|
|
25
25
|
*/
|
|
26
26
|
export declare function loadSecretsFromEncryptedJsonFileValues(filePath: string, secretEncryptionKey?: Base64String): void;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
*/
|
|
30
|
-
export declare function secret<T = string>(k: string, json?: boolean): T;
|
|
31
|
-
export declare function secretOptional<T = string>(k: string, json?: boolean): T | undefined;
|
|
27
|
+
export declare function secret<T = string>(k: string, parseJson?: boolean): T;
|
|
28
|
+
export declare function secretOptional<T = string>(k: string, parseJson?: boolean): T | undefined;
|
|
32
29
|
export declare function getSecretMap(): StringMap;
|
|
33
30
|
/**
|
|
34
31
|
* REPLACES secretMap with new map.
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.setSecretMap = exports.getSecretMap = exports.secretOptional = exports.secret = exports.loadSecretsFromEncryptedJsonFileValues = exports.loadSecretsFromEncryptedJsonFile = exports.removeSecretsFromEnv = exports.loadSecretsFromEnv = void 0;
|
|
4
4
|
const fs = require("node:fs");
|
|
5
5
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
6
|
-
const __1 = require("..");
|
|
7
6
|
const crypto_util_1 = require("./crypto.util");
|
|
8
7
|
let loaded = false;
|
|
9
8
|
const secretMap = {};
|
|
@@ -44,7 +43,6 @@ exports.removeSecretsFromEnv = removeSecretsFromEnv;
|
|
|
44
43
|
* Whole file is encrypted.
|
|
45
44
|
* For "json-values encrypted" style - use `loadSecretsFromEncryptedJsonFileValues`
|
|
46
45
|
*/
|
|
47
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
48
46
|
function loadSecretsFromEncryptedJsonFile(filePath, secretEncryptionKey) {
|
|
49
47
|
(0, js_lib_1._assert)(fs.existsSync(filePath), `loadSecretsFromEncryptedJsonFile() cannot load from path: ${filePath}`);
|
|
50
48
|
let secrets;
|
|
@@ -80,21 +78,23 @@ function loadSecretsFromEncryptedJsonFileValues(filePath, secretEncryptionKey) {
|
|
|
80
78
|
.join(', ')}`);
|
|
81
79
|
}
|
|
82
80
|
exports.loadSecretsFromEncryptedJsonFileValues = loadSecretsFromEncryptedJsonFileValues;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
*/
|
|
86
|
-
function secret(k, json = false) {
|
|
87
|
-
const v = secretOptional(k, json);
|
|
81
|
+
function secret(k, parseJson = false) {
|
|
82
|
+
const v = secretOptional(k, parseJson);
|
|
88
83
|
if (!v) {
|
|
89
84
|
throw new Error(`secret(${k.toUpperCase()}) not found!`);
|
|
90
85
|
}
|
|
91
86
|
return v;
|
|
92
87
|
}
|
|
93
88
|
exports.secret = secret;
|
|
94
|
-
function secretOptional(k,
|
|
89
|
+
function secretOptional(k, parseJson = false) {
|
|
95
90
|
requireLoaded();
|
|
96
|
-
|
|
97
|
-
|
|
91
|
+
let v = secretMap[k.toUpperCase()];
|
|
92
|
+
if (!v)
|
|
93
|
+
return;
|
|
94
|
+
if (parseJson) {
|
|
95
|
+
v = (0, js_lib_1._jsonParseIfPossible)(v);
|
|
96
|
+
}
|
|
97
|
+
return v;
|
|
98
98
|
}
|
|
99
99
|
exports.secretOptional = secretOptional;
|
|
100
100
|
function getSecretMap() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as fs from 'node:fs'
|
|
2
|
-
import { _assert, Base64String, StringMap } from '@naturalcycles/js-lib'
|
|
3
|
-
import { base64ToString } from '..'
|
|
2
|
+
import { _assert, _jsonParseIfPossible, Base64String, StringMap } from '@naturalcycles/js-lib'
|
|
4
3
|
import { decryptObject, decryptRandomIVBuffer } from './crypto.util'
|
|
5
4
|
|
|
6
5
|
let loaded = false
|
|
@@ -50,7 +49,6 @@ export function removeSecretsFromEnv(): void {
|
|
|
50
49
|
* Whole file is encrypted.
|
|
51
50
|
* For "json-values encrypted" style - use `loadSecretsFromEncryptedJsonFileValues`
|
|
52
51
|
*/
|
|
53
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
54
52
|
export function loadSecretsFromEncryptedJsonFile(
|
|
55
53
|
filePath: string,
|
|
56
54
|
secretEncryptionKey?: Base64String,
|
|
@@ -109,11 +107,8 @@ export function loadSecretsFromEncryptedJsonFileValues(
|
|
|
109
107
|
)
|
|
110
108
|
}
|
|
111
109
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
*/
|
|
115
|
-
export function secret<T = string>(k: string, json = false): T {
|
|
116
|
-
const v = secretOptional(k, json)
|
|
110
|
+
export function secret<T = string>(k: string, parseJson = false): T {
|
|
111
|
+
const v = secretOptional(k, parseJson)
|
|
117
112
|
if (!v) {
|
|
118
113
|
throw new Error(`secret(${k.toUpperCase()}) not found!`)
|
|
119
114
|
}
|
|
@@ -121,10 +116,16 @@ export function secret<T = string>(k: string, json = false): T {
|
|
|
121
116
|
return v as any
|
|
122
117
|
}
|
|
123
118
|
|
|
124
|
-
export function secretOptional<T = string>(k: string,
|
|
119
|
+
export function secretOptional<T = string>(k: string, parseJson = false): T | undefined {
|
|
125
120
|
requireLoaded()
|
|
126
|
-
|
|
127
|
-
|
|
121
|
+
let v = secretMap[k.toUpperCase()]
|
|
122
|
+
if (!v) return
|
|
123
|
+
|
|
124
|
+
if (parseJson) {
|
|
125
|
+
v = _jsonParseIfPossible(v)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return v as T
|
|
128
129
|
}
|
|
129
130
|
|
|
130
131
|
export function getSecretMap(): StringMap {
|