@lbstack/accessx 0.3.0 → 0.3.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/src/core/engine.js +22 -4
- package/package.json +1 -1
package/dist/src/core/engine.js
CHANGED
|
@@ -27,6 +27,11 @@ export function createEngine(config) {
|
|
|
27
27
|
interval: interval,
|
|
28
28
|
condition: condition,
|
|
29
29
|
};
|
|
30
|
+
const updatePermissions = (list) => {
|
|
31
|
+
assignment.permissions.clear();
|
|
32
|
+
list.forEach((p) => assignment.permissions.set(p, assignment.condition || (() => true)));
|
|
33
|
+
notify();
|
|
34
|
+
};
|
|
30
35
|
const updateFn = async (newKey) => {
|
|
31
36
|
let list = [];
|
|
32
37
|
if (typeof perms === "function") {
|
|
@@ -38,8 +43,7 @@ export function createEngine(config) {
|
|
|
38
43
|
else {
|
|
39
44
|
list = Array.isArray(perms) ? perms : [perms];
|
|
40
45
|
}
|
|
41
|
-
|
|
42
|
-
list.forEach((p) => assignment.permissions.set(p, assignment.condition || (() => true)));
|
|
46
|
+
updatePermissions(list);
|
|
43
47
|
if (newKey !== undefined) {
|
|
44
48
|
assignment.lastInvalidateKey = newKey;
|
|
45
49
|
}
|
|
@@ -49,12 +53,26 @@ export function createEngine(config) {
|
|
|
49
53
|
? await assignment.invalidateKeyFetcher()
|
|
50
54
|
: assignment.invalidateKeyFetcher;
|
|
51
55
|
}
|
|
52
|
-
notify();
|
|
53
56
|
};
|
|
54
|
-
|
|
57
|
+
// Immediate application for synchronous perms
|
|
58
|
+
if (typeof perms !== "function") {
|
|
59
|
+
const list = Array.isArray(perms) ? perms : [perms];
|
|
60
|
+
updatePermissions(list);
|
|
61
|
+
// Handle literal key synchronously
|
|
62
|
+
if (invalidateKey && typeof invalidateKey !== "function") {
|
|
63
|
+
assignment.lastInvalidateKey = invalidateKey;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
55
66
|
if (!roleAssignments.has(role))
|
|
56
67
|
roleAssignments.set(role, []);
|
|
57
68
|
roleAssignments.get(role).push(assignment);
|
|
69
|
+
// Still call updateFn to handle potential async invalidateKeyFetcher
|
|
70
|
+
// and initial perms fetch if it's a function.
|
|
71
|
+
const initialUpdate = updateFn();
|
|
72
|
+
if (typeof perms === "function" ||
|
|
73
|
+
typeof invalidateKey === "function") {
|
|
74
|
+
await initialUpdate;
|
|
75
|
+
}
|
|
58
76
|
if (interval && interval > 0) {
|
|
59
77
|
assignment.timer = setInterval(async () => {
|
|
60
78
|
const currentKey = assignment.invalidateKeyFetcher
|