@arcote.tech/arc-adapter-db-postgres 0.7.32 → 0.8.1
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/dist/index.js +19 -7
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1364,11 +1364,18 @@ function notifyTokenChange(scope) {
|
|
|
1364
1364
|
|
|
1365
1365
|
class AuthAdapter {
|
|
1366
1366
|
scopes = new Map;
|
|
1367
|
+
namespace;
|
|
1368
|
+
constructor(options) {
|
|
1369
|
+
this.namespace = options?.storageNamespace || undefined;
|
|
1370
|
+
}
|
|
1371
|
+
storageKey(scope) {
|
|
1372
|
+
return this.namespace ? `${TOKEN_PREFIX}${this.namespace}:${scope}` : TOKEN_PREFIX + scope;
|
|
1373
|
+
}
|
|
1367
1374
|
setToken(token, scope = "default") {
|
|
1368
1375
|
if (!token) {
|
|
1369
1376
|
this.scopes.delete(scope);
|
|
1370
1377
|
if (hasLocalStorage()) {
|
|
1371
|
-
localStorage.removeItem(
|
|
1378
|
+
localStorage.removeItem(this.storageKey(scope));
|
|
1372
1379
|
notifyTokenChange(scope);
|
|
1373
1380
|
}
|
|
1374
1381
|
return;
|
|
@@ -1378,7 +1385,7 @@ class AuthAdapter {
|
|
|
1378
1385
|
if (parts.length !== 3) {
|
|
1379
1386
|
this.scopes.delete(scope);
|
|
1380
1387
|
if (hasLocalStorage())
|
|
1381
|
-
localStorage.removeItem(
|
|
1388
|
+
localStorage.removeItem(this.storageKey(scope));
|
|
1382
1389
|
return;
|
|
1383
1390
|
}
|
|
1384
1391
|
const payload = JSON.parse(atob(parts[1]));
|
|
@@ -1392,13 +1399,13 @@ class AuthAdapter {
|
|
|
1392
1399
|
}
|
|
1393
1400
|
});
|
|
1394
1401
|
if (hasLocalStorage()) {
|
|
1395
|
-
localStorage.setItem(
|
|
1402
|
+
localStorage.setItem(this.storageKey(scope), token);
|
|
1396
1403
|
notifyTokenChange(scope);
|
|
1397
1404
|
}
|
|
1398
1405
|
} catch {
|
|
1399
1406
|
this.scopes.delete(scope);
|
|
1400
1407
|
if (hasLocalStorage())
|
|
1401
|
-
localStorage.removeItem(
|
|
1408
|
+
localStorage.removeItem(this.storageKey(scope));
|
|
1402
1409
|
}
|
|
1403
1410
|
}
|
|
1404
1411
|
setDecoded(decoded, scope = "default") {
|
|
@@ -1407,10 +1414,13 @@ class AuthAdapter {
|
|
|
1407
1414
|
loadPersisted() {
|
|
1408
1415
|
if (!hasLocalStorage())
|
|
1409
1416
|
return;
|
|
1417
|
+
const prefix = this.namespace ? `${TOKEN_PREFIX}${this.namespace}:` : TOKEN_PREFIX;
|
|
1410
1418
|
for (let i = 0;i < localStorage.length; i++) {
|
|
1411
1419
|
const key = localStorage.key(i);
|
|
1412
|
-
if (key?.startsWith(
|
|
1413
|
-
const scope = key.slice(
|
|
1420
|
+
if (key?.startsWith(prefix)) {
|
|
1421
|
+
const scope = key.slice(prefix.length);
|
|
1422
|
+
if (!this.namespace && scope.includes(":"))
|
|
1423
|
+
continue;
|
|
1414
1424
|
const raw = localStorage.getItem(key);
|
|
1415
1425
|
if (raw) {
|
|
1416
1426
|
try {
|
|
@@ -1464,7 +1474,7 @@ class AuthAdapter {
|
|
|
1464
1474
|
clear() {
|
|
1465
1475
|
if (hasLocalStorage()) {
|
|
1466
1476
|
for (const scope of this.scopes.keys()) {
|
|
1467
|
-
localStorage.removeItem(
|
|
1477
|
+
localStorage.removeItem(this.storageKey(scope));
|
|
1468
1478
|
}
|
|
1469
1479
|
}
|
|
1470
1480
|
this.scopes.clear();
|
|
@@ -3304,6 +3314,8 @@ class ArcFunction {
|
|
|
3304
3314
|
if (!tokenInstance) {
|
|
3305
3315
|
return false;
|
|
3306
3316
|
}
|
|
3317
|
+
if (!protection.check)
|
|
3318
|
+
continue;
|
|
3307
3319
|
const result = await protection.check(tokenInstance);
|
|
3308
3320
|
if (result === false) {
|
|
3309
3321
|
return false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcote.tech/arc-adapter-db-postgres",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"postgres": "^3.4.4"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"@arcote.tech/arc": "^0.
|
|
26
|
+
"@arcote.tech/arc": "^0.8.1"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/pg": "^8.11.0",
|