@ojolowoblue/lamba 1.0.4 → 1.0.6
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/README.md +74 -20
- package/dist/index.d.mts +73 -10
- package/dist/index.d.ts +73 -10
- package/dist/index.js +144 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +141 -26
- package/dist/index.mjs.map +1 -1
- package/dist/integrations/react.d.mts +1 -1
- package/dist/integrations/react.d.ts +1 -1
- package/dist/integrations/react.js +139 -27
- package/dist/integrations/react.js.map +1 -1
- package/dist/integrations/react.mjs +139 -27
- package/dist/integrations/react.mjs.map +1 -1
- package/dist/integrations/vue.d.mts +1 -1
- package/dist/integrations/vue.d.ts +1 -1
- package/dist/integrations/vue.js +139 -27
- package/dist/integrations/vue.js.map +1 -1
- package/dist/integrations/vue.mjs +139 -27
- package/dist/integrations/vue.mjs.map +1 -1
- package/dist/lamba.min.js +10 -10
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -21,6 +21,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
LambaManager: () => LambaManager,
|
|
24
|
+
LocalStorageAdapter: () => LocalStorageAdapter,
|
|
25
|
+
MemoryStorageAdapter: () => MemoryStorageAdapter,
|
|
26
|
+
SessionStorageAdapter: () => SessionStorageAdapter,
|
|
24
27
|
default: () => index_default,
|
|
25
28
|
lamba: () => lamba,
|
|
26
29
|
parseEnvString: () => parseEnvString,
|
|
@@ -32,34 +35,33 @@ module.exports = __toCommonJS(index_exports);
|
|
|
32
35
|
var STORAGE_PRESETS_KEY = "__lamba_presets__";
|
|
33
36
|
var STORAGE_ACTIVE_PRESET_KEY = "__lamba_active_preset__";
|
|
34
37
|
var PresetManager = class {
|
|
35
|
-
constructor() {
|
|
38
|
+
constructor(storage) {
|
|
36
39
|
this.presets = [];
|
|
37
40
|
this.activePresetId = null;
|
|
41
|
+
this.storage = storage;
|
|
38
42
|
this.loadFromStorage();
|
|
39
43
|
}
|
|
40
44
|
loadFromStorage() {
|
|
41
|
-
if (typeof localStorage === "undefined") return;
|
|
42
45
|
try {
|
|
43
|
-
const rawPresets =
|
|
46
|
+
const rawPresets = this.storage.getItem(STORAGE_PRESETS_KEY);
|
|
44
47
|
if (rawPresets) {
|
|
45
48
|
this.presets = JSON.parse(rawPresets);
|
|
46
49
|
}
|
|
47
|
-
this.activePresetId =
|
|
50
|
+
this.activePresetId = this.storage.getItem(STORAGE_ACTIVE_PRESET_KEY);
|
|
48
51
|
} catch (e) {
|
|
49
|
-
console.warn("[lamba] Failed to parse presets from
|
|
52
|
+
console.warn("[lamba] Failed to parse presets from storage", e);
|
|
50
53
|
}
|
|
51
54
|
}
|
|
52
55
|
saveToStorage() {
|
|
53
|
-
if (typeof localStorage === "undefined") return;
|
|
54
56
|
try {
|
|
55
|
-
|
|
57
|
+
this.storage.setItem(STORAGE_PRESETS_KEY, JSON.stringify(this.presets));
|
|
56
58
|
if (this.activePresetId) {
|
|
57
|
-
|
|
59
|
+
this.storage.setItem(STORAGE_ACTIVE_PRESET_KEY, this.activePresetId);
|
|
58
60
|
} else {
|
|
59
|
-
|
|
61
|
+
this.storage.removeItem(STORAGE_ACTIVE_PRESET_KEY);
|
|
60
62
|
}
|
|
61
63
|
} catch (e) {
|
|
62
|
-
console.warn("[lamba] Failed to save presets to
|
|
64
|
+
console.warn("[lamba] Failed to save presets to storage", e);
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
67
|
getPresets() {
|
|
@@ -211,6 +213,99 @@ async function tryFetchRootEnvFile() {
|
|
|
211
213
|
return {};
|
|
212
214
|
}
|
|
213
215
|
|
|
216
|
+
// src/core/storage.ts
|
|
217
|
+
var LocalStorageAdapter = class {
|
|
218
|
+
getItem(key) {
|
|
219
|
+
try {
|
|
220
|
+
return typeof localStorage !== "undefined" ? localStorage.getItem(key) : null;
|
|
221
|
+
} catch {
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
setItem(key, value) {
|
|
226
|
+
try {
|
|
227
|
+
if (typeof localStorage !== "undefined") localStorage.setItem(key, value);
|
|
228
|
+
} catch {
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
removeItem(key) {
|
|
232
|
+
try {
|
|
233
|
+
if (typeof localStorage !== "undefined") localStorage.removeItem(key);
|
|
234
|
+
} catch {
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
clear() {
|
|
238
|
+
try {
|
|
239
|
+
if (typeof localStorage !== "undefined") {
|
|
240
|
+
localStorage.removeItem("__lamba_overrides__");
|
|
241
|
+
localStorage.removeItem("__lamba_presets__");
|
|
242
|
+
localStorage.removeItem("__lamba_active_preset__");
|
|
243
|
+
}
|
|
244
|
+
} catch {
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
var SessionStorageAdapter = class {
|
|
249
|
+
getItem(key) {
|
|
250
|
+
try {
|
|
251
|
+
return typeof sessionStorage !== "undefined" ? sessionStorage.getItem(key) : null;
|
|
252
|
+
} catch {
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
setItem(key, value) {
|
|
257
|
+
try {
|
|
258
|
+
if (typeof sessionStorage !== "undefined") sessionStorage.setItem(key, value);
|
|
259
|
+
} catch {
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
removeItem(key) {
|
|
263
|
+
try {
|
|
264
|
+
if (typeof sessionStorage !== "undefined") sessionStorage.removeItem(key);
|
|
265
|
+
} catch {
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
clear() {
|
|
269
|
+
try {
|
|
270
|
+
if (typeof sessionStorage !== "undefined") {
|
|
271
|
+
sessionStorage.removeItem("__lamba_overrides__");
|
|
272
|
+
sessionStorage.removeItem("__lamba_presets__");
|
|
273
|
+
sessionStorage.removeItem("__lamba_active_preset__");
|
|
274
|
+
}
|
|
275
|
+
} catch {
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
var MemoryStorageAdapter = class {
|
|
280
|
+
constructor() {
|
|
281
|
+
this.store = /* @__PURE__ */ new Map();
|
|
282
|
+
}
|
|
283
|
+
getItem(key) {
|
|
284
|
+
return this.store.get(key) ?? null;
|
|
285
|
+
}
|
|
286
|
+
setItem(key, value) {
|
|
287
|
+
this.store.set(key, value);
|
|
288
|
+
}
|
|
289
|
+
removeItem(key) {
|
|
290
|
+
this.store.delete(key);
|
|
291
|
+
}
|
|
292
|
+
clear() {
|
|
293
|
+
this.store.clear();
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
function createStorageAdapter(strategy = "local", custom) {
|
|
297
|
+
if (custom) return custom;
|
|
298
|
+
switch (strategy) {
|
|
299
|
+
case "session":
|
|
300
|
+
return new SessionStorageAdapter();
|
|
301
|
+
case "memory":
|
|
302
|
+
return new MemoryStorageAdapter();
|
|
303
|
+
case "local":
|
|
304
|
+
default:
|
|
305
|
+
return new LocalStorageAdapter();
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
214
309
|
// src/core/store.ts
|
|
215
310
|
var STORAGE_OVERRIDES_KEY = "__lamba_overrides__";
|
|
216
311
|
var DEFAULT_SECRET_PATTERN = /(KEY|SECRET|TOKEN|PASSWORD|AUTH|PRIVATE|CREDENTIAL|SIGNATURE)/i;
|
|
@@ -222,7 +317,8 @@ var EnvStore = class {
|
|
|
222
317
|
this.storeChangeListeners = /* @__PURE__ */ new Set();
|
|
223
318
|
this.secretPattern = options.secretKeysPattern || DEFAULT_SECRET_PATTERN;
|
|
224
319
|
this.allowedPrefixes = options.allowedPrefixes;
|
|
225
|
-
this.
|
|
320
|
+
this.storage = createStorageAdapter(options.storageStrategy ?? "local", options.storage);
|
|
321
|
+
this.presetManager = new PresetManager(this.storage);
|
|
226
322
|
this.loadOverridesFromStorage();
|
|
227
323
|
if (options.env) {
|
|
228
324
|
this.mergeDefaults(options.env);
|
|
@@ -239,22 +335,20 @@ var EnvStore = class {
|
|
|
239
335
|
this.patchProcessEnv();
|
|
240
336
|
}
|
|
241
337
|
loadOverridesFromStorage() {
|
|
242
|
-
if (typeof localStorage === "undefined") return;
|
|
243
338
|
try {
|
|
244
|
-
const stored =
|
|
339
|
+
const stored = this.storage.getItem(STORAGE_OVERRIDES_KEY);
|
|
245
340
|
if (stored) {
|
|
246
341
|
this.overrides = JSON.parse(stored);
|
|
247
342
|
}
|
|
248
343
|
} catch (e) {
|
|
249
|
-
console.warn("[lamba] Failed to parse overrides from
|
|
344
|
+
console.warn("[lamba] Failed to parse overrides from storage", e);
|
|
250
345
|
}
|
|
251
346
|
}
|
|
252
347
|
saveOverridesToStorage() {
|
|
253
|
-
if (typeof localStorage === "undefined") return;
|
|
254
348
|
try {
|
|
255
|
-
|
|
349
|
+
this.storage.setItem(STORAGE_OVERRIDES_KEY, JSON.stringify(this.overrides));
|
|
256
350
|
} catch (e) {
|
|
257
|
-
console.warn("[lamba] Failed to save overrides to
|
|
351
|
+
console.warn("[lamba] Failed to save overrides to storage", e);
|
|
258
352
|
}
|
|
259
353
|
}
|
|
260
354
|
/**
|
|
@@ -307,9 +401,9 @@ var EnvStore = class {
|
|
|
307
401
|
let changed = false;
|
|
308
402
|
for (const [key, rawDefault] of Object.entries(env)) {
|
|
309
403
|
if (!this.isAllowedKey(key)) continue;
|
|
310
|
-
const defaultValue = rawDefault
|
|
404
|
+
const defaultValue = rawDefault;
|
|
311
405
|
const isOverridden = key in this.overrides;
|
|
312
|
-
const currentValue = isOverridden ?
|
|
406
|
+
const currentValue = isOverridden ? this.overrides[key] : defaultValue;
|
|
313
407
|
const isSecret = this.secretPattern.test(key);
|
|
314
408
|
const existing = this.variables.get(key);
|
|
315
409
|
if (!existing) {
|
|
@@ -1363,7 +1457,15 @@ var ModalUI = class {
|
|
|
1363
1457
|
`;
|
|
1364
1458
|
const inputEl = card.querySelector(".var-input");
|
|
1365
1459
|
inputEl.addEventListener("change", () => {
|
|
1366
|
-
|
|
1460
|
+
let val = inputEl.value;
|
|
1461
|
+
if (typeof varItem.defaultValue === "boolean") {
|
|
1462
|
+
if (val === "true") val = true;
|
|
1463
|
+
else if (val === "false") val = false;
|
|
1464
|
+
} else if (typeof varItem.defaultValue === "number") {
|
|
1465
|
+
const num = Number(val);
|
|
1466
|
+
if (!isNaN(num) && val.trim() !== "") val = num;
|
|
1467
|
+
}
|
|
1468
|
+
this.store.setOverride(varItem.key, val);
|
|
1367
1469
|
});
|
|
1368
1470
|
card.querySelector(".toggle-secret-btn")?.addEventListener("click", () => {
|
|
1369
1471
|
this.secretVisibilityMap.set(varItem.key, !isVisible);
|
|
@@ -1376,7 +1478,8 @@ var ModalUI = class {
|
|
|
1376
1478
|
}
|
|
1377
1479
|
escapeHtml(str) {
|
|
1378
1480
|
if (str === null || str === void 0) return "";
|
|
1379
|
-
|
|
1481
|
+
const text = typeof str === "object" ? JSON.stringify(str) : String(str);
|
|
1482
|
+
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
1380
1483
|
}
|
|
1381
1484
|
};
|
|
1382
1485
|
|
|
@@ -1399,7 +1502,7 @@ var LambaManager = class {
|
|
|
1399
1502
|
},
|
|
1400
1503
|
set(_target, prop, value) {
|
|
1401
1504
|
if (typeof prop === "string") {
|
|
1402
|
-
self.set(prop,
|
|
1505
|
+
self.set(prop, value);
|
|
1403
1506
|
return true;
|
|
1404
1507
|
}
|
|
1405
1508
|
return false;
|
|
@@ -1418,9 +1521,7 @@ var LambaManager = class {
|
|
|
1418
1521
|
try {
|
|
1419
1522
|
const defaultObj = {};
|
|
1420
1523
|
for (const [k, v] of Object.entries(targetEnv)) {
|
|
1421
|
-
|
|
1422
|
-
defaultObj[k] = String(v);
|
|
1423
|
-
}
|
|
1524
|
+
defaultObj[k] = v;
|
|
1424
1525
|
}
|
|
1425
1526
|
if (Object.keys(defaultObj).length > 0) {
|
|
1426
1527
|
this.store.mergeDefaults(defaultObj);
|
|
@@ -1434,10 +1535,24 @@ var LambaManager = class {
|
|
|
1434
1535
|
if (typeof prop === "string") {
|
|
1435
1536
|
const overrideVal = self.get(prop);
|
|
1436
1537
|
if (overrideVal !== void 0 && overrideVal !== "") {
|
|
1538
|
+
const targetVal = Reflect.get(target, prop);
|
|
1539
|
+
if (typeof targetVal === "boolean") {
|
|
1540
|
+
if (overrideVal === "true" || overrideVal === true) return true;
|
|
1541
|
+
if (overrideVal === "false" || overrideVal === false) return false;
|
|
1542
|
+
} else if (typeof targetVal === "number" && typeof overrideVal === "string") {
|
|
1543
|
+
const num = Number(overrideVal);
|
|
1544
|
+
if (!isNaN(num)) return num;
|
|
1545
|
+
}
|
|
1437
1546
|
return overrideVal;
|
|
1438
1547
|
}
|
|
1439
1548
|
}
|
|
1440
1549
|
return Reflect.get(target, prop);
|
|
1550
|
+
},
|
|
1551
|
+
set(target, prop, value) {
|
|
1552
|
+
if (typeof prop === "string") {
|
|
1553
|
+
self.set(prop, value);
|
|
1554
|
+
}
|
|
1555
|
+
return Reflect.set(target, prop, value);
|
|
1441
1556
|
}
|
|
1442
1557
|
});
|
|
1443
1558
|
}
|
|
@@ -1490,7 +1605,7 @@ var LambaManager = class {
|
|
|
1490
1605
|
if (!this.store) {
|
|
1491
1606
|
this.init();
|
|
1492
1607
|
}
|
|
1493
|
-
return this.store?.get(key, fallback) ?? fallback
|
|
1608
|
+
return this.store?.get(key, fallback) ?? fallback;
|
|
1494
1609
|
}
|
|
1495
1610
|
/**
|
|
1496
1611
|
* Overrides an environment variable live at runtime.
|
|
@@ -1550,6 +1665,9 @@ var index_default = lamba;
|
|
|
1550
1665
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1551
1666
|
0 && (module.exports = {
|
|
1552
1667
|
LambaManager,
|
|
1668
|
+
LocalStorageAdapter,
|
|
1669
|
+
MemoryStorageAdapter,
|
|
1670
|
+
SessionStorageAdapter,
|
|
1553
1671
|
lamba,
|
|
1554
1672
|
parseEnvString,
|
|
1555
1673
|
stringifyEnv
|