@ojolowoblue/lamba 1.0.5 → 1.0.7
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 +58 -4
- package/dist/index.d.mts +73 -1
- package/dist/index.d.ts +73 -1
- package/dist/index.js +130 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +127 -18
- package/dist/index.mjs.map +1 -1
- package/dist/integrations/react.js +124 -18
- package/dist/integrations/react.js.map +1 -1
- package/dist/integrations/react.mjs +124 -18
- package/dist/integrations/react.mjs.map +1 -1
- package/dist/integrations/vue.js +124 -18
- package/dist/integrations/vue.js.map +1 -1
- package/dist/integrations/vue.mjs +124 -18
- package/dist/integrations/vue.mjs.map +1 -1
- package/dist/lamba.min.js +8 -8
- package/package.json +1 -1
package/dist/integrations/vue.js
CHANGED
|
@@ -29,34 +29,33 @@ var import_vue = require("vue");
|
|
|
29
29
|
var STORAGE_PRESETS_KEY = "__lamba_presets__";
|
|
30
30
|
var STORAGE_ACTIVE_PRESET_KEY = "__lamba_active_preset__";
|
|
31
31
|
var PresetManager = class {
|
|
32
|
-
constructor() {
|
|
32
|
+
constructor(storage) {
|
|
33
33
|
this.presets = [];
|
|
34
34
|
this.activePresetId = null;
|
|
35
|
+
this.storage = storage;
|
|
35
36
|
this.loadFromStorage();
|
|
36
37
|
}
|
|
37
38
|
loadFromStorage() {
|
|
38
|
-
if (typeof localStorage === "undefined") return;
|
|
39
39
|
try {
|
|
40
|
-
const rawPresets =
|
|
40
|
+
const rawPresets = this.storage.getItem(STORAGE_PRESETS_KEY);
|
|
41
41
|
if (rawPresets) {
|
|
42
42
|
this.presets = JSON.parse(rawPresets);
|
|
43
43
|
}
|
|
44
|
-
this.activePresetId =
|
|
44
|
+
this.activePresetId = this.storage.getItem(STORAGE_ACTIVE_PRESET_KEY);
|
|
45
45
|
} catch (e) {
|
|
46
|
-
console.warn("[lamba] Failed to parse presets from
|
|
46
|
+
console.warn("[lamba] Failed to parse presets from storage", e);
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
saveToStorage() {
|
|
50
|
-
if (typeof localStorage === "undefined") return;
|
|
51
50
|
try {
|
|
52
|
-
|
|
51
|
+
this.storage.setItem(STORAGE_PRESETS_KEY, JSON.stringify(this.presets));
|
|
53
52
|
if (this.activePresetId) {
|
|
54
|
-
|
|
53
|
+
this.storage.setItem(STORAGE_ACTIVE_PRESET_KEY, this.activePresetId);
|
|
55
54
|
} else {
|
|
56
|
-
|
|
55
|
+
this.storage.removeItem(STORAGE_ACTIVE_PRESET_KEY);
|
|
57
56
|
}
|
|
58
57
|
} catch (e) {
|
|
59
|
-
console.warn("[lamba] Failed to save presets to
|
|
58
|
+
console.warn("[lamba] Failed to save presets to storage", e);
|
|
60
59
|
}
|
|
61
60
|
}
|
|
62
61
|
getPresets() {
|
|
@@ -208,6 +207,99 @@ async function tryFetchRootEnvFile() {
|
|
|
208
207
|
return {};
|
|
209
208
|
}
|
|
210
209
|
|
|
210
|
+
// src/core/storage.ts
|
|
211
|
+
var LocalStorageAdapter = class {
|
|
212
|
+
getItem(key) {
|
|
213
|
+
try {
|
|
214
|
+
return typeof localStorage !== "undefined" ? localStorage.getItem(key) : null;
|
|
215
|
+
} catch {
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
setItem(key, value) {
|
|
220
|
+
try {
|
|
221
|
+
if (typeof localStorage !== "undefined") localStorage.setItem(key, value);
|
|
222
|
+
} catch {
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
removeItem(key) {
|
|
226
|
+
try {
|
|
227
|
+
if (typeof localStorage !== "undefined") localStorage.removeItem(key);
|
|
228
|
+
} catch {
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
clear() {
|
|
232
|
+
try {
|
|
233
|
+
if (typeof localStorage !== "undefined") {
|
|
234
|
+
localStorage.removeItem("__lamba_overrides__");
|
|
235
|
+
localStorage.removeItem("__lamba_presets__");
|
|
236
|
+
localStorage.removeItem("__lamba_active_preset__");
|
|
237
|
+
}
|
|
238
|
+
} catch {
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
var SessionStorageAdapter = class {
|
|
243
|
+
getItem(key) {
|
|
244
|
+
try {
|
|
245
|
+
return typeof sessionStorage !== "undefined" ? sessionStorage.getItem(key) : null;
|
|
246
|
+
} catch {
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
setItem(key, value) {
|
|
251
|
+
try {
|
|
252
|
+
if (typeof sessionStorage !== "undefined") sessionStorage.setItem(key, value);
|
|
253
|
+
} catch {
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
removeItem(key) {
|
|
257
|
+
try {
|
|
258
|
+
if (typeof sessionStorage !== "undefined") sessionStorage.removeItem(key);
|
|
259
|
+
} catch {
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
clear() {
|
|
263
|
+
try {
|
|
264
|
+
if (typeof sessionStorage !== "undefined") {
|
|
265
|
+
sessionStorage.removeItem("__lamba_overrides__");
|
|
266
|
+
sessionStorage.removeItem("__lamba_presets__");
|
|
267
|
+
sessionStorage.removeItem("__lamba_active_preset__");
|
|
268
|
+
}
|
|
269
|
+
} catch {
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
var MemoryStorageAdapter = class {
|
|
274
|
+
constructor() {
|
|
275
|
+
this.store = /* @__PURE__ */ new Map();
|
|
276
|
+
}
|
|
277
|
+
getItem(key) {
|
|
278
|
+
return this.store.get(key) ?? null;
|
|
279
|
+
}
|
|
280
|
+
setItem(key, value) {
|
|
281
|
+
this.store.set(key, value);
|
|
282
|
+
}
|
|
283
|
+
removeItem(key) {
|
|
284
|
+
this.store.delete(key);
|
|
285
|
+
}
|
|
286
|
+
clear() {
|
|
287
|
+
this.store.clear();
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
function createStorageAdapter(strategy = "local", custom) {
|
|
291
|
+
if (custom) return custom;
|
|
292
|
+
switch (strategy) {
|
|
293
|
+
case "session":
|
|
294
|
+
return new SessionStorageAdapter();
|
|
295
|
+
case "memory":
|
|
296
|
+
return new MemoryStorageAdapter();
|
|
297
|
+
case "local":
|
|
298
|
+
default:
|
|
299
|
+
return new LocalStorageAdapter();
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
211
303
|
// src/core/store.ts
|
|
212
304
|
var STORAGE_OVERRIDES_KEY = "__lamba_overrides__";
|
|
213
305
|
var DEFAULT_SECRET_PATTERN = /(KEY|SECRET|TOKEN|PASSWORD|AUTH|PRIVATE|CREDENTIAL|SIGNATURE)/i;
|
|
@@ -219,7 +311,8 @@ var EnvStore = class {
|
|
|
219
311
|
this.storeChangeListeners = /* @__PURE__ */ new Set();
|
|
220
312
|
this.secretPattern = options.secretKeysPattern || DEFAULT_SECRET_PATTERN;
|
|
221
313
|
this.allowedPrefixes = options.allowedPrefixes;
|
|
222
|
-
this.
|
|
314
|
+
this.storage = createStorageAdapter(options.storageStrategy ?? "local", options.storage);
|
|
315
|
+
this.presetManager = new PresetManager(this.storage);
|
|
223
316
|
this.loadOverridesFromStorage();
|
|
224
317
|
if (options.env) {
|
|
225
318
|
this.mergeDefaults(options.env);
|
|
@@ -236,22 +329,20 @@ var EnvStore = class {
|
|
|
236
329
|
this.patchProcessEnv();
|
|
237
330
|
}
|
|
238
331
|
loadOverridesFromStorage() {
|
|
239
|
-
if (typeof localStorage === "undefined") return;
|
|
240
332
|
try {
|
|
241
|
-
const stored =
|
|
333
|
+
const stored = this.storage.getItem(STORAGE_OVERRIDES_KEY);
|
|
242
334
|
if (stored) {
|
|
243
335
|
this.overrides = JSON.parse(stored);
|
|
244
336
|
}
|
|
245
337
|
} catch (e) {
|
|
246
|
-
console.warn("[lamba] Failed to parse overrides from
|
|
338
|
+
console.warn("[lamba] Failed to parse overrides from storage", e);
|
|
247
339
|
}
|
|
248
340
|
}
|
|
249
341
|
saveOverridesToStorage() {
|
|
250
|
-
if (typeof localStorage === "undefined") return;
|
|
251
342
|
try {
|
|
252
|
-
|
|
343
|
+
this.storage.setItem(STORAGE_OVERRIDES_KEY, JSON.stringify(this.overrides));
|
|
253
344
|
} catch (e) {
|
|
254
|
-
console.warn("[lamba] Failed to save overrides to
|
|
345
|
+
console.warn("[lamba] Failed to save overrides to storage", e);
|
|
255
346
|
}
|
|
256
347
|
}
|
|
257
348
|
/**
|
|
@@ -1472,7 +1563,10 @@ var LambaManager = class {
|
|
|
1472
1563
|
interceptNetworkRequests: true,
|
|
1473
1564
|
...options
|
|
1474
1565
|
};
|
|
1475
|
-
if (this.options.enabled === false)
|
|
1566
|
+
if (this.options.enabled === false) {
|
|
1567
|
+
this.purge(options);
|
|
1568
|
+
return this;
|
|
1569
|
+
}
|
|
1476
1570
|
this.store = new EnvStore(this.options);
|
|
1477
1571
|
if (this.options.interceptNetworkRequests !== false) {
|
|
1478
1572
|
this.networkInterceptor = new NetworkInterceptor(this.store);
|
|
@@ -1529,6 +1623,18 @@ var LambaManager = class {
|
|
|
1529
1623
|
reset() {
|
|
1530
1624
|
this.store?.resetAllOverrides();
|
|
1531
1625
|
}
|
|
1626
|
+
/**
|
|
1627
|
+
* Removes ALL lamba data from storage (overrides, presets, active preset).
|
|
1628
|
+
* Safe to call even when lamba has not been initialized.
|
|
1629
|
+
* Useful when disabling lamba to ensure no stale data remains in the browser.
|
|
1630
|
+
*
|
|
1631
|
+
* @param options - Optionally pass storage options to target the correct adapter.
|
|
1632
|
+
* Defaults to 'local' (localStorage) to cover the common case.
|
|
1633
|
+
*/
|
|
1634
|
+
purge(options) {
|
|
1635
|
+
const adapter = this.store?.storage ?? createStorageAdapter(options?.storageStrategy ?? "local", options?.storage);
|
|
1636
|
+
adapter.clear();
|
|
1637
|
+
}
|
|
1532
1638
|
/**
|
|
1533
1639
|
* Subscribes to environment variable changes.
|
|
1534
1640
|
*/
|