@arcote.tech/arc-adapter-db-sqlite 0.4.7 → 0.4.9

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.
Files changed (2) hide show
  1. package/dist/index.js +13 -2
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1357,14 +1357,23 @@ var TOKEN_PREFIX = "arc:token:";
1357
1357
  function hasLocalStorage() {
1358
1358
  return typeof localStorage !== "undefined";
1359
1359
  }
1360
+ function notifyTokenChange(scope) {
1361
+ if (typeof window !== "undefined") {
1362
+ queueMicrotask(() => {
1363
+ window.dispatchEvent(new CustomEvent("arc:token-change", { detail: { scope } }));
1364
+ });
1365
+ }
1366
+ }
1360
1367
 
1361
1368
  class AuthAdapter {
1362
1369
  scopes = new Map;
1363
1370
  setToken(token, scope = "default") {
1364
1371
  if (!token) {
1365
1372
  this.scopes.delete(scope);
1366
- if (hasLocalStorage())
1373
+ if (hasLocalStorage()) {
1367
1374
  localStorage.removeItem(TOKEN_PREFIX + scope);
1375
+ notifyTokenChange(scope);
1376
+ }
1368
1377
  return;
1369
1378
  }
1370
1379
  try {
@@ -1385,8 +1394,10 @@ class AuthAdapter {
1385
1394
  exp: payload.exp
1386
1395
  }
1387
1396
  });
1388
- if (hasLocalStorage())
1397
+ if (hasLocalStorage()) {
1389
1398
  localStorage.setItem(TOKEN_PREFIX + scope, token);
1399
+ notifyTokenChange(scope);
1400
+ }
1390
1401
  } catch {
1391
1402
  this.scopes.delete(scope);
1392
1403
  if (hasLocalStorage())
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcote.tech/arc-adapter-db-sqlite",
3
- "version": "0.4.7",
3
+ "version": "0.4.9",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -20,7 +20,7 @@
20
20
  "test": "bun test"
21
21
  },
22
22
  "peerDependencies": {
23
- "@arcote.tech/arc": "^0.4.7"
23
+ "@arcote.tech/arc": "^0.4.9"
24
24
  },
25
25
  "devDependencies": {
26
26
  "typescript": "^5.0.0"