@friggframework/core 2.0.0--canary.625.0de0db4.0 → 2.0.0--canary.625.eaeb79b.0
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/core/parameters-to-env.js +26 -0
- package/core/ssm-preload.mjs +4 -17
- package/package.json +5 -5
|
@@ -216,6 +216,31 @@ const adoptPreloadedKeys = (keys) => {
|
|
|
216
216
|
ttlSeconds === 0 ? Infinity : Date.now() + ttlSeconds * 1000;
|
|
217
217
|
};
|
|
218
218
|
|
|
219
|
+
/**
|
|
220
|
+
* INIT-phase preload used by ssm-preload.mjs: fetch offloaded parameters and
|
|
221
|
+
* set them into process.env, then adopt the keys it set so the handler-time
|
|
222
|
+
* loader refreshes them on TTL. Real env wins — a key already present is never
|
|
223
|
+
* fetched or overwritten, so a console override keeps working even if that
|
|
224
|
+
* key's parameter is absent from SSM (fetching it would fail INIT). Returns the
|
|
225
|
+
* keys actually set (empty when every key was already in real env). Throws,
|
|
226
|
+
* listing the names, only for a genuinely-needed parameter that is missing.
|
|
227
|
+
*/
|
|
228
|
+
const preloadOffloadedParameters = async (prefix, keys, options = {}) => {
|
|
229
|
+
const keysToFetch = keys.filter((key) => process.env[key] === undefined);
|
|
230
|
+
if (keysToFetch.length === 0) {
|
|
231
|
+
return [];
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const values = await fetchOffloadedParameters(prefix, keysToFetch, options);
|
|
235
|
+
const setKeys = [];
|
|
236
|
+
for (const [key, value] of Object.entries(values)) {
|
|
237
|
+
process.env[key] = value;
|
|
238
|
+
setKeys.push(key);
|
|
239
|
+
}
|
|
240
|
+
adoptPreloadedKeys(setKeys);
|
|
241
|
+
return setKeys;
|
|
242
|
+
};
|
|
243
|
+
|
|
219
244
|
const _resetCache = () => {
|
|
220
245
|
client = null;
|
|
221
246
|
cacheExpiresAt = null;
|
|
@@ -226,6 +251,7 @@ const _resetCache = () => {
|
|
|
226
251
|
module.exports = {
|
|
227
252
|
parametersToEnv,
|
|
228
253
|
fetchOffloadedParameters,
|
|
254
|
+
preloadOffloadedParameters,
|
|
229
255
|
adoptPreloadedKeys,
|
|
230
256
|
_resetCache,
|
|
231
257
|
};
|
package/core/ssm-preload.mjs
CHANGED
|
@@ -25,23 +25,10 @@ if (prefix && rawKeys) {
|
|
|
25
25
|
.filter(Boolean);
|
|
26
26
|
|
|
27
27
|
if (keys.length > 0) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const values = await fetchOffloadedParameters(prefix, keys);
|
|
33
|
-
|
|
34
|
-
// Real env vars win over SSM (console-override debugging escape hatch).
|
|
35
|
-
const setKeys = [];
|
|
36
|
-
for (const [key, value] of Object.entries(values)) {
|
|
37
|
-
if (process.env[key] === undefined) {
|
|
38
|
-
process.env[key] = value;
|
|
39
|
-
setKeys.push(key);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
// Hand the keys we set to the handler-time loader (same in-process
|
|
43
|
-
// module singleton) so its TTL-refresh path re-fetches them.
|
|
44
|
-
adoptPreloadedKeys(setKeys);
|
|
28
|
+
// The fetch/real-env-wins/adopt logic lives in the CJS module (tested
|
|
29
|
+
// there); this preload is a thin INIT-phase shim over it.
|
|
30
|
+
const { preloadOffloadedParameters } = require('./parameters-to-env');
|
|
31
|
+
const setKeys = await preloadOffloadedParameters(prefix, keys);
|
|
45
32
|
console.log(`frigg-ssm-preload: loaded ${setKeys.length} parameter(s) at INIT under ${prefix}`);
|
|
46
33
|
}
|
|
47
34
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@friggframework/core",
|
|
3
3
|
"prettier": "@friggframework/prettier-config",
|
|
4
|
-
"version": "2.0.0--canary.625.
|
|
4
|
+
"version": "2.0.0--canary.625.eaeb79b.0",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@aws-sdk/client-apigatewaymanagementapi": "^3.588.0",
|
|
7
7
|
"@aws-sdk/client-kms": "^3.588.0",
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
}
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@friggframework/eslint-config": "2.0.0--canary.625.
|
|
43
|
-
"@friggframework/prettier-config": "2.0.0--canary.625.
|
|
44
|
-
"@friggframework/test": "2.0.0--canary.625.
|
|
42
|
+
"@friggframework/eslint-config": "2.0.0--canary.625.eaeb79b.0",
|
|
43
|
+
"@friggframework/prettier-config": "2.0.0--canary.625.eaeb79b.0",
|
|
44
|
+
"@friggframework/test": "2.0.0--canary.625.eaeb79b.0",
|
|
45
45
|
"@prisma/client": "^6.19.3",
|
|
46
46
|
"@types/lodash": "4.17.15",
|
|
47
47
|
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
@@ -81,5 +81,5 @@
|
|
|
81
81
|
"publishConfig": {
|
|
82
82
|
"access": "public"
|
|
83
83
|
},
|
|
84
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "eaeb79b0e8f8bbe466ac40f389d603e86bd806b7"
|
|
85
85
|
}
|