@arcote.tech/arc-adapter-db-sqlite 0.7.31 → 0.8.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.
Files changed (2) hide show
  1. package/dist/index.js +19 -7
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1367,11 +1367,18 @@ function notifyTokenChange(scope) {
1367
1367
 
1368
1368
  class AuthAdapter {
1369
1369
  scopes = new Map;
1370
+ namespace;
1371
+ constructor(options) {
1372
+ this.namespace = options?.storageNamespace || undefined;
1373
+ }
1374
+ storageKey(scope) {
1375
+ return this.namespace ? `${TOKEN_PREFIX}${this.namespace}:${scope}` : TOKEN_PREFIX + scope;
1376
+ }
1370
1377
  setToken(token, scope = "default") {
1371
1378
  if (!token) {
1372
1379
  this.scopes.delete(scope);
1373
1380
  if (hasLocalStorage()) {
1374
- localStorage.removeItem(TOKEN_PREFIX + scope);
1381
+ localStorage.removeItem(this.storageKey(scope));
1375
1382
  notifyTokenChange(scope);
1376
1383
  }
1377
1384
  return;
@@ -1381,7 +1388,7 @@ class AuthAdapter {
1381
1388
  if (parts.length !== 3) {
1382
1389
  this.scopes.delete(scope);
1383
1390
  if (hasLocalStorage())
1384
- localStorage.removeItem(TOKEN_PREFIX + scope);
1391
+ localStorage.removeItem(this.storageKey(scope));
1385
1392
  return;
1386
1393
  }
1387
1394
  const payload = JSON.parse(atob(parts[1]));
@@ -1395,13 +1402,13 @@ class AuthAdapter {
1395
1402
  }
1396
1403
  });
1397
1404
  if (hasLocalStorage()) {
1398
- localStorage.setItem(TOKEN_PREFIX + scope, token);
1405
+ localStorage.setItem(this.storageKey(scope), token);
1399
1406
  notifyTokenChange(scope);
1400
1407
  }
1401
1408
  } catch {
1402
1409
  this.scopes.delete(scope);
1403
1410
  if (hasLocalStorage())
1404
- localStorage.removeItem(TOKEN_PREFIX + scope);
1411
+ localStorage.removeItem(this.storageKey(scope));
1405
1412
  }
1406
1413
  }
1407
1414
  setDecoded(decoded, scope = "default") {
@@ -1410,10 +1417,13 @@ class AuthAdapter {
1410
1417
  loadPersisted() {
1411
1418
  if (!hasLocalStorage())
1412
1419
  return;
1420
+ const prefix = this.namespace ? `${TOKEN_PREFIX}${this.namespace}:` : TOKEN_PREFIX;
1413
1421
  for (let i = 0;i < localStorage.length; i++) {
1414
1422
  const key = localStorage.key(i);
1415
- if (key?.startsWith(TOKEN_PREFIX)) {
1416
- const scope = key.slice(TOKEN_PREFIX.length);
1423
+ if (key?.startsWith(prefix)) {
1424
+ const scope = key.slice(prefix.length);
1425
+ if (!this.namespace && scope.includes(":"))
1426
+ continue;
1417
1427
  const raw = localStorage.getItem(key);
1418
1428
  if (raw) {
1419
1429
  try {
@@ -1467,7 +1477,7 @@ class AuthAdapter {
1467
1477
  clear() {
1468
1478
  if (hasLocalStorage()) {
1469
1479
  for (const scope of this.scopes.keys()) {
1470
- localStorage.removeItem(TOKEN_PREFIX + scope);
1480
+ localStorage.removeItem(this.storageKey(scope));
1471
1481
  }
1472
1482
  }
1473
1483
  this.scopes.clear();
@@ -3307,6 +3317,8 @@ class ArcFunction {
3307
3317
  if (!tokenInstance) {
3308
3318
  return false;
3309
3319
  }
3320
+ if (!protection.check)
3321
+ continue;
3310
3322
  const result = await protection.check(tokenInstance);
3311
3323
  if (result === false) {
3312
3324
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcote.tech/arc-adapter-db-sqlite",
3
- "version": "0.7.31",
3
+ "version": "0.8.0",
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.7.31"
23
+ "@arcote.tech/arc": "^0.8.0"
24
24
  },
25
25
  "devDependencies": {
26
26
  "typescript": "^5.0.0"