@naturalcycles/nodejs-lib 12.86.0 → 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,8 +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
|
-
export declare function secret<T = string>(k: string): T;
|
|
28
|
-
export declare function secretOptional<T = string>(k: string): 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;
|
|
29
29
|
export declare function getSecretMap(): StringMap;
|
|
30
30
|
/**
|
|
31
31
|
* REPLACES secretMap with new map.
|
|
@@ -78,17 +78,23 @@ function loadSecretsFromEncryptedJsonFileValues(filePath, secretEncryptionKey) {
|
|
|
78
78
|
.join(', ')}`);
|
|
79
79
|
}
|
|
80
80
|
exports.loadSecretsFromEncryptedJsonFileValues = loadSecretsFromEncryptedJsonFileValues;
|
|
81
|
-
function secret(k) {
|
|
82
|
-
const v = secretOptional(k);
|
|
81
|
+
function secret(k, parseJson = false) {
|
|
82
|
+
const v = secretOptional(k, parseJson);
|
|
83
83
|
if (!v) {
|
|
84
84
|
throw new Error(`secret(${k.toUpperCase()}) not found!`);
|
|
85
85
|
}
|
|
86
86
|
return v;
|
|
87
87
|
}
|
|
88
88
|
exports.secret = secret;
|
|
89
|
-
function secretOptional(k) {
|
|
89
|
+
function secretOptional(k, parseJson = false) {
|
|
90
90
|
requireLoaded();
|
|
91
|
-
|
|
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;
|
|
92
98
|
}
|
|
93
99
|
exports.secretOptional = secretOptional;
|
|
94
100
|
function getSecretMap() {
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as fs from 'node:fs'
|
|
2
|
-
import { _assert, Base64String, StringMap } from '@naturalcycles/js-lib'
|
|
2
|
+
import { _assert, _jsonParseIfPossible, Base64String, StringMap } from '@naturalcycles/js-lib'
|
|
3
3
|
import { decryptObject, decryptRandomIVBuffer } from './crypto.util'
|
|
4
4
|
|
|
5
5
|
let loaded = false
|
|
@@ -107,8 +107,8 @@ export function loadSecretsFromEncryptedJsonFileValues(
|
|
|
107
107
|
)
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
export function secret<T = string>(k: string): T {
|
|
111
|
-
const v = secretOptional(k)
|
|
110
|
+
export function secret<T = string>(k: string, parseJson = false): T {
|
|
111
|
+
const v = secretOptional(k, parseJson)
|
|
112
112
|
if (!v) {
|
|
113
113
|
throw new Error(`secret(${k.toUpperCase()}) not found!`)
|
|
114
114
|
}
|
|
@@ -116,9 +116,16 @@ export function secret<T = string>(k: string): T {
|
|
|
116
116
|
return v as any
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
export function secretOptional<T = string>(k: string): T | undefined {
|
|
119
|
+
export function secretOptional<T = string>(k: string, parseJson = false): T | undefined {
|
|
120
120
|
requireLoaded()
|
|
121
|
-
|
|
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
|
|
122
129
|
}
|
|
123
130
|
|
|
124
131
|
export function getSecretMap(): StringMap {
|