joshlei-cookies 2.8.0 → 3.0.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/index.js +1 -73
- package/package.json +2 -5
package/index.js
CHANGED
|
@@ -207,72 +207,6 @@ const CookieManager = {
|
|
|
207
207
|
},
|
|
208
208
|
};
|
|
209
209
|
|
|
210
|
-
const _managedCookieNames = new Set();
|
|
211
|
-
|
|
212
|
-
const _ensureSyncing = (() => {
|
|
213
|
-
let initialized = false;
|
|
214
|
-
let poller = null;
|
|
215
|
-
|
|
216
|
-
return () => {
|
|
217
|
-
if (!isBrowser || initialized) return;
|
|
218
|
-
initialized = true;
|
|
219
|
-
|
|
220
|
-
try {
|
|
221
|
-
const ss = window.sessionStorage;
|
|
222
|
-
const originalRemoveItem = ss.removeItem.bind(ss);
|
|
223
|
-
const originalSetItem = ss.setItem.bind(ss);
|
|
224
|
-
|
|
225
|
-
ss.removeItem = function (key) {
|
|
226
|
-
originalRemoveItem(key);
|
|
227
|
-
try {
|
|
228
|
-
if (typeof key === 'string' && key.indexOf('jstudio_token_') === 0) {
|
|
229
|
-
const cookieName = key.slice('jstudio_token_'.length);
|
|
230
|
-
try { CookieManager.remove(cookieName); } catch (e) {}
|
|
231
|
-
_managedCookieNames.delete(cookieName);
|
|
232
|
-
}
|
|
233
|
-
} catch (e) {}
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
ss.setItem = function (key, value) {
|
|
237
|
-
originalSetItem(key, value);
|
|
238
|
-
try {
|
|
239
|
-
if (typeof key === 'string' && key.indexOf('jstudio_token_') === 0) {
|
|
240
|
-
const cookieName = key.slice('jstudio_token_'.length);
|
|
241
|
-
_managedCookieNames.add(cookieName);
|
|
242
|
-
}
|
|
243
|
-
} catch (e) {}
|
|
244
|
-
};
|
|
245
|
-
} catch (e) {}
|
|
246
|
-
|
|
247
|
-
try {
|
|
248
|
-
window.addEventListener('storage', (ev) => {
|
|
249
|
-
try {
|
|
250
|
-
if (!ev.key) return;
|
|
251
|
-
if (ev.key.indexOf('jstudio_token_') === 0 && ev.newValue === null) {
|
|
252
|
-
const cookieName = ev.key.slice('jstudio_token_'.length);
|
|
253
|
-
try { CookieManager.remove(cookieName); } catch (e) {}
|
|
254
|
-
_managedCookieNames.delete(cookieName);
|
|
255
|
-
}
|
|
256
|
-
} catch (e) {}
|
|
257
|
-
});
|
|
258
|
-
} catch (e) {}
|
|
259
|
-
|
|
260
|
-
poller = setInterval(() => {
|
|
261
|
-
try {
|
|
262
|
-
for (const name of Array.from(_managedCookieNames)) {
|
|
263
|
-
try {
|
|
264
|
-
const val = CookieManager.get(name);
|
|
265
|
-
if (val === null) {
|
|
266
|
-
try { sessionStorage.removeItem(`jstudio_token_${name}`); } catch (e) {}
|
|
267
|
-
_managedCookieNames.delete(name);
|
|
268
|
-
}
|
|
269
|
-
} catch (e) {}
|
|
270
|
-
}
|
|
271
|
-
} catch (e) {}
|
|
272
|
-
}, 2000);
|
|
273
|
-
};
|
|
274
|
-
})();
|
|
275
|
-
|
|
276
210
|
const importKey = async (rawKey) => {
|
|
277
211
|
try {
|
|
278
212
|
const crypto = await initCrypto();
|
|
@@ -393,7 +327,6 @@ export const SetJSCookie = async (name, data, options = {}) => {
|
|
|
393
327
|
|
|
394
328
|
const encryptedData = await CryptoManager.encrypt(JSON.stringify(dataToStore), hashedKey);
|
|
395
329
|
CookieManager.set(name, encryptedData, options);
|
|
396
|
-
try { _managedCookieNames.add(name); _ensureSyncing(); } catch (e) {}
|
|
397
330
|
} catch (error) {
|
|
398
331
|
throw new Error(`Failed to set cookie: ${error.message}`);
|
|
399
332
|
}
|
|
@@ -450,12 +383,7 @@ export const RemoveJSCookie = (name, options = {}) => {
|
|
|
450
383
|
if (isBrowser) sessionStorage.removeItem(`jstudio_token_${name}`);
|
|
451
384
|
} catch (e) {}
|
|
452
385
|
CookieManager.remove(name, options);
|
|
453
|
-
try { _managedCookieNames.delete(name); } catch (e) {}
|
|
454
|
-
try { _ensureSyncing(); } catch (e) {}
|
|
455
386
|
} catch (error) {
|
|
456
387
|
throw new Error(`Failed to remove cookie: ${error.message}`);
|
|
457
388
|
}
|
|
458
|
-
};
|
|
459
|
-
|
|
460
|
-
// Start syncing when module is loaded in browser
|
|
461
|
-
try { if (isBrowser) _ensureSyncing(); } catch (e) {}
|
|
389
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "joshlei-cookies",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "A secure cookie management library with built-in AES encryption for browser environments",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -32,10 +32,7 @@
|
|
|
32
32
|
"exports": {
|
|
33
33
|
".": {
|
|
34
34
|
"import": "./index.js",
|
|
35
|
-
"
|
|
35
|
+
"default": "./index.js"
|
|
36
36
|
}
|
|
37
|
-
},
|
|
38
|
-
"dependencies": {
|
|
39
|
-
"joshlei-cookies": "^1.0.0"
|
|
40
37
|
}
|
|
41
38
|
}
|