@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/index.mjs
CHANGED
|
@@ -2,34 +2,33 @@
|
|
|
2
2
|
var STORAGE_PRESETS_KEY = "__lamba_presets__";
|
|
3
3
|
var STORAGE_ACTIVE_PRESET_KEY = "__lamba_active_preset__";
|
|
4
4
|
var PresetManager = class {
|
|
5
|
-
constructor() {
|
|
5
|
+
constructor(storage) {
|
|
6
6
|
this.presets = [];
|
|
7
7
|
this.activePresetId = null;
|
|
8
|
+
this.storage = storage;
|
|
8
9
|
this.loadFromStorage();
|
|
9
10
|
}
|
|
10
11
|
loadFromStorage() {
|
|
11
|
-
if (typeof localStorage === "undefined") return;
|
|
12
12
|
try {
|
|
13
|
-
const rawPresets =
|
|
13
|
+
const rawPresets = this.storage.getItem(STORAGE_PRESETS_KEY);
|
|
14
14
|
if (rawPresets) {
|
|
15
15
|
this.presets = JSON.parse(rawPresets);
|
|
16
16
|
}
|
|
17
|
-
this.activePresetId =
|
|
17
|
+
this.activePresetId = this.storage.getItem(STORAGE_ACTIVE_PRESET_KEY);
|
|
18
18
|
} catch (e) {
|
|
19
|
-
console.warn("[lamba] Failed to parse presets from
|
|
19
|
+
console.warn("[lamba] Failed to parse presets from storage", e);
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
saveToStorage() {
|
|
23
|
-
if (typeof localStorage === "undefined") return;
|
|
24
23
|
try {
|
|
25
|
-
|
|
24
|
+
this.storage.setItem(STORAGE_PRESETS_KEY, JSON.stringify(this.presets));
|
|
26
25
|
if (this.activePresetId) {
|
|
27
|
-
|
|
26
|
+
this.storage.setItem(STORAGE_ACTIVE_PRESET_KEY, this.activePresetId);
|
|
28
27
|
} else {
|
|
29
|
-
|
|
28
|
+
this.storage.removeItem(STORAGE_ACTIVE_PRESET_KEY);
|
|
30
29
|
}
|
|
31
30
|
} catch (e) {
|
|
32
|
-
console.warn("[lamba] Failed to save presets to
|
|
31
|
+
console.warn("[lamba] Failed to save presets to storage", e);
|
|
33
32
|
}
|
|
34
33
|
}
|
|
35
34
|
getPresets() {
|
|
@@ -181,6 +180,99 @@ async function tryFetchRootEnvFile() {
|
|
|
181
180
|
return {};
|
|
182
181
|
}
|
|
183
182
|
|
|
183
|
+
// src/core/storage.ts
|
|
184
|
+
var LocalStorageAdapter = class {
|
|
185
|
+
getItem(key) {
|
|
186
|
+
try {
|
|
187
|
+
return typeof localStorage !== "undefined" ? localStorage.getItem(key) : null;
|
|
188
|
+
} catch {
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
setItem(key, value) {
|
|
193
|
+
try {
|
|
194
|
+
if (typeof localStorage !== "undefined") localStorage.setItem(key, value);
|
|
195
|
+
} catch {
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
removeItem(key) {
|
|
199
|
+
try {
|
|
200
|
+
if (typeof localStorage !== "undefined") localStorage.removeItem(key);
|
|
201
|
+
} catch {
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
clear() {
|
|
205
|
+
try {
|
|
206
|
+
if (typeof localStorage !== "undefined") {
|
|
207
|
+
localStorage.removeItem("__lamba_overrides__");
|
|
208
|
+
localStorage.removeItem("__lamba_presets__");
|
|
209
|
+
localStorage.removeItem("__lamba_active_preset__");
|
|
210
|
+
}
|
|
211
|
+
} catch {
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
var SessionStorageAdapter = class {
|
|
216
|
+
getItem(key) {
|
|
217
|
+
try {
|
|
218
|
+
return typeof sessionStorage !== "undefined" ? sessionStorage.getItem(key) : null;
|
|
219
|
+
} catch {
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
setItem(key, value) {
|
|
224
|
+
try {
|
|
225
|
+
if (typeof sessionStorage !== "undefined") sessionStorage.setItem(key, value);
|
|
226
|
+
} catch {
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
removeItem(key) {
|
|
230
|
+
try {
|
|
231
|
+
if (typeof sessionStorage !== "undefined") sessionStorage.removeItem(key);
|
|
232
|
+
} catch {
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
clear() {
|
|
236
|
+
try {
|
|
237
|
+
if (typeof sessionStorage !== "undefined") {
|
|
238
|
+
sessionStorage.removeItem("__lamba_overrides__");
|
|
239
|
+
sessionStorage.removeItem("__lamba_presets__");
|
|
240
|
+
sessionStorage.removeItem("__lamba_active_preset__");
|
|
241
|
+
}
|
|
242
|
+
} catch {
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
var MemoryStorageAdapter = class {
|
|
247
|
+
constructor() {
|
|
248
|
+
this.store = /* @__PURE__ */ new Map();
|
|
249
|
+
}
|
|
250
|
+
getItem(key) {
|
|
251
|
+
return this.store.get(key) ?? null;
|
|
252
|
+
}
|
|
253
|
+
setItem(key, value) {
|
|
254
|
+
this.store.set(key, value);
|
|
255
|
+
}
|
|
256
|
+
removeItem(key) {
|
|
257
|
+
this.store.delete(key);
|
|
258
|
+
}
|
|
259
|
+
clear() {
|
|
260
|
+
this.store.clear();
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
function createStorageAdapter(strategy = "local", custom) {
|
|
264
|
+
if (custom) return custom;
|
|
265
|
+
switch (strategy) {
|
|
266
|
+
case "session":
|
|
267
|
+
return new SessionStorageAdapter();
|
|
268
|
+
case "memory":
|
|
269
|
+
return new MemoryStorageAdapter();
|
|
270
|
+
case "local":
|
|
271
|
+
default:
|
|
272
|
+
return new LocalStorageAdapter();
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
184
276
|
// src/core/store.ts
|
|
185
277
|
var STORAGE_OVERRIDES_KEY = "__lamba_overrides__";
|
|
186
278
|
var DEFAULT_SECRET_PATTERN = /(KEY|SECRET|TOKEN|PASSWORD|AUTH|PRIVATE|CREDENTIAL|SIGNATURE)/i;
|
|
@@ -192,7 +284,8 @@ var EnvStore = class {
|
|
|
192
284
|
this.storeChangeListeners = /* @__PURE__ */ new Set();
|
|
193
285
|
this.secretPattern = options.secretKeysPattern || DEFAULT_SECRET_PATTERN;
|
|
194
286
|
this.allowedPrefixes = options.allowedPrefixes;
|
|
195
|
-
this.
|
|
287
|
+
this.storage = createStorageAdapter(options.storageStrategy ?? "local", options.storage);
|
|
288
|
+
this.presetManager = new PresetManager(this.storage);
|
|
196
289
|
this.loadOverridesFromStorage();
|
|
197
290
|
if (options.env) {
|
|
198
291
|
this.mergeDefaults(options.env);
|
|
@@ -209,22 +302,20 @@ var EnvStore = class {
|
|
|
209
302
|
this.patchProcessEnv();
|
|
210
303
|
}
|
|
211
304
|
loadOverridesFromStorage() {
|
|
212
|
-
if (typeof localStorage === "undefined") return;
|
|
213
305
|
try {
|
|
214
|
-
const stored =
|
|
306
|
+
const stored = this.storage.getItem(STORAGE_OVERRIDES_KEY);
|
|
215
307
|
if (stored) {
|
|
216
308
|
this.overrides = JSON.parse(stored);
|
|
217
309
|
}
|
|
218
310
|
} catch (e) {
|
|
219
|
-
console.warn("[lamba] Failed to parse overrides from
|
|
311
|
+
console.warn("[lamba] Failed to parse overrides from storage", e);
|
|
220
312
|
}
|
|
221
313
|
}
|
|
222
314
|
saveOverridesToStorage() {
|
|
223
|
-
if (typeof localStorage === "undefined") return;
|
|
224
315
|
try {
|
|
225
|
-
|
|
316
|
+
this.storage.setItem(STORAGE_OVERRIDES_KEY, JSON.stringify(this.overrides));
|
|
226
317
|
} catch (e) {
|
|
227
|
-
console.warn("[lamba] Failed to save overrides to
|
|
318
|
+
console.warn("[lamba] Failed to save overrides to storage", e);
|
|
228
319
|
}
|
|
229
320
|
}
|
|
230
321
|
/**
|
|
@@ -1445,7 +1536,10 @@ var LambaManager = class {
|
|
|
1445
1536
|
interceptNetworkRequests: true,
|
|
1446
1537
|
...options
|
|
1447
1538
|
};
|
|
1448
|
-
if (this.options.enabled === false)
|
|
1539
|
+
if (this.options.enabled === false) {
|
|
1540
|
+
this.purge(options);
|
|
1541
|
+
return this;
|
|
1542
|
+
}
|
|
1449
1543
|
this.store = new EnvStore(this.options);
|
|
1450
1544
|
if (this.options.interceptNetworkRequests !== false) {
|
|
1451
1545
|
this.networkInterceptor = new NetworkInterceptor(this.store);
|
|
@@ -1502,6 +1596,18 @@ var LambaManager = class {
|
|
|
1502
1596
|
reset() {
|
|
1503
1597
|
this.store?.resetAllOverrides();
|
|
1504
1598
|
}
|
|
1599
|
+
/**
|
|
1600
|
+
* Removes ALL lamba data from storage (overrides, presets, active preset).
|
|
1601
|
+
* Safe to call even when lamba has not been initialized.
|
|
1602
|
+
* Useful when disabling lamba to ensure no stale data remains in the browser.
|
|
1603
|
+
*
|
|
1604
|
+
* @param options - Optionally pass storage options to target the correct adapter.
|
|
1605
|
+
* Defaults to 'local' (localStorage) to cover the common case.
|
|
1606
|
+
*/
|
|
1607
|
+
purge(options) {
|
|
1608
|
+
const adapter = this.store?.storage ?? createStorageAdapter(options?.storageStrategy ?? "local", options?.storage);
|
|
1609
|
+
adapter.clear();
|
|
1610
|
+
}
|
|
1505
1611
|
/**
|
|
1506
1612
|
* Subscribes to environment variable changes.
|
|
1507
1613
|
*/
|
|
@@ -1540,6 +1646,9 @@ if (typeof window !== "undefined") {
|
|
|
1540
1646
|
var index_default = lamba;
|
|
1541
1647
|
export {
|
|
1542
1648
|
LambaManager,
|
|
1649
|
+
LocalStorageAdapter,
|
|
1650
|
+
MemoryStorageAdapter,
|
|
1651
|
+
SessionStorageAdapter,
|
|
1543
1652
|
index_default as default,
|
|
1544
1653
|
lamba,
|
|
1545
1654
|
parseEnvString,
|