@aooth/arbac-moost 0.2.2 → 0.2.3
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/atscript/index.mjs +2 -2
- package/dist/index.d.mts +39 -0
- package/dist/index.mjs +17 -0
- package/package.json +18 -18
package/dist/atscript/index.mjs
CHANGED
|
@@ -475,7 +475,7 @@ var AoothArbacUserCredentials = class {
|
|
|
475
475
|
throwFeatureDisabled("JSON Schema", "jsonSchema", "emit.jsonSchema");
|
|
476
476
|
}
|
|
477
477
|
};
|
|
478
|
-
$ak("db.index.fulltext", "db.index.plain", "db.index.unique", "db.view.joins", "expect.pattern");
|
|
479
|
-
$nr("aooth.auth.metadata", "aooth.user.email", "aooth.user.phone", "arbac.attenuate.attr", "arbac.attenuate.role", "arbac.attribute", "arbac.role", "arbac.userId", "db.agg.avg", "db.agg.count", "db.agg.countDistinct", "db.agg.max", "db.agg.min", "db.agg.sum", "db.alias", "db.amount.currency.ref", "db.column", "db.column.collate", "db.column.derived", "db.column.dimension", "db.column.filterable", "db.column.measure", "db.column.precision", "db.column.renamed", "db.column.searchable", "db.column.sortable", "db.column.version", "db.column.version.exempt", "db.compute", "db.default", "db.default.increment", "db.default.now", "db.default.uuid", "db.depth.limit", "db.encrypted", "db.http.path", "db.ignore", "db.index.fulltext", "db.index.geo", "db.index.plain", "db.index.unique", "db.json", "db.onUpdate.inc", "db.onUpdate.now", "db.patch.strategy", "db.rel.FK", "db.rel.filter", "db.rel.filterable", "db.rel.from", "db.rel.onDelete", "db.rel.onUpdate", "db.rel.to", "db.rel.via", "db.schema", "db.search.filter", "db.search.vector", "db.search.vector.threshold", "db.sort.nulls", "db.space", "db.sync.method", "db.table", "db.table.filterable", "db.table.preferredId.uniqueIndex", "db.table.renamed", "db.table.sortable", "db.unit.ref", "db.view", "db.view.filter", "db.view.for", "db.view.having", "db.view.joins", "db.view.materialized", "db.view.renamed", "db.writeOnly", "meta.default", "meta.id", "meta.readonly", "meta.required");
|
|
478
|
+
$ak("db.index.fulltext", "db.index.fulltext.language", "db.index.fulltext.match", "db.index.plain", "db.index.unique", "db.view.joins", "expect.pattern");
|
|
479
|
+
$nr("aooth.auth.metadata", "aooth.user.email", "aooth.user.phone", "arbac.attenuate.attr", "arbac.attenuate.role", "arbac.attribute", "arbac.role", "arbac.userId", "db.agg.avg", "db.agg.count", "db.agg.countDistinct", "db.agg.max", "db.agg.min", "db.agg.sum", "db.alias", "db.amount.currency.ref", "db.column", "db.column.collate", "db.column.derived", "db.column.dimension", "db.column.filterable", "db.column.measure", "db.column.precision", "db.column.renamed", "db.column.searchable", "db.column.sortable", "db.column.version", "db.column.version.exempt", "db.compute", "db.default", "db.default.increment", "db.default.now", "db.default.uuid", "db.depth.limit", "db.encrypted", "db.http.path", "db.ignore", "db.index.fulltext", "db.index.fulltext.language", "db.index.fulltext.match", "db.index.geo", "db.index.plain", "db.index.unique", "db.json", "db.onUpdate.inc", "db.onUpdate.now", "db.patch.strategy", "db.rel.FK", "db.rel.filter", "db.rel.filterable", "db.rel.from", "db.rel.onDelete", "db.rel.onUpdate", "db.rel.to", "db.rel.via", "db.schema", "db.search.filter", "db.search.vector", "db.search.vector.threshold", "db.sort.nulls", "db.space", "db.sync.method", "db.table", "db.table.filterable", "db.table.preferredId.uniqueIndex", "db.table.renamed", "db.table.sortable", "db.unit.ref", "db.view", "db.view.filter", "db.view.for", "db.view.having", "db.view.joins", "db.view.materialized", "db.view.renamed", "db.writeOnly", "meta.default", "meta.id", "meta.readonly", "meta.required");
|
|
480
480
|
defineAnnotatedType("object", AoothArbacUserCredentials).prop("id", $f(AoothUserCredentials, "id")).prop("username", $f(AoothUserCredentials, "username")).prop("version", $f(AoothUserCredentials, "version")).prop("password", $f(AoothUserCredentials, "password")).prop("account", $f(AoothUserCredentials, "account")).prop("mfa", $f(AoothUserCredentials, "mfa")).prop("trustedDevices", $f(AoothUserCredentials, "trustedDevices")).prop("seenDevices", $f(AoothUserCredentials, "seenDevices")).prop("roles", defineAnnotatedType("array").of(defineAnnotatedType().designType("string").tags("string").$type).annotate("arbac.role", true).$type);
|
|
481
481
|
export { AoothArbacUserCredentials, ArbacUserRecordCache, AtscriptArbacUserProvider, extractAttenuation, getAoothUserHandleSpec, getArbacAttenuationSpec, validateAttenuationTargets };
|
package/dist/index.d.mts
CHANGED
|
@@ -224,6 +224,37 @@ export interface ArbacEvaluateOptions {
|
|
|
224
224
|
*/
|
|
225
225
|
table?: VisibilityTableSource;
|
|
226
226
|
}
|
|
227
|
+
/** The current user as ARBAC sees it — what `useArbac().principal()` returns. */
|
|
228
|
+
export interface ArbacPrincipal<TUserAttrs extends object = object> {
|
|
229
|
+
/** The user id the `ArbacUserProvider` resolved for this event. */
|
|
230
|
+
userId: string;
|
|
231
|
+
/**
|
|
232
|
+
* The roles the user HOLDS (`ArbacUserProvider.getRoles`), before
|
|
233
|
+
* credential attenuation. Don't authorize on it — an attenuated credential
|
|
234
|
+
* may act with fewer roles; use {@link effectiveRoles} or `evaluate()`.
|
|
235
|
+
*/
|
|
236
|
+
roles: string[];
|
|
237
|
+
/**
|
|
238
|
+
* The roles this request acts with: {@link roles} narrowed by the
|
|
239
|
+
* credential's attenuation (`roles ∩ attenuation.roles`; all held roles when
|
|
240
|
+
* the attenuation names none). A claimed role the user does not hold is
|
|
241
|
+
* never included, even with `allowUnheldRoles` — that "view as" mode only
|
|
242
|
+
* ever narrows through `evaluate()`. Use this for role checks in app code.
|
|
243
|
+
*/
|
|
244
|
+
effectiveRoles: string[];
|
|
245
|
+
/** The user's attributes (`ArbacUserProvider.getAttrs`), loaded on the first call. */
|
|
246
|
+
attrs: () => Promise<TUserAttrs>;
|
|
247
|
+
/**
|
|
248
|
+
* The credential's restrict-only attenuation
|
|
249
|
+
* (`ArbacUserProvider.getAttenuation`), when it narrows the user's
|
|
250
|
+
* authority; absent otherwise.
|
|
251
|
+
*/
|
|
252
|
+
attenuation?: {
|
|
253
|
+
roles?: string[];
|
|
254
|
+
attrs?: Record<string, unknown>;
|
|
255
|
+
allowUnheldRoles?: boolean;
|
|
256
|
+
};
|
|
257
|
+
}
|
|
227
258
|
interface ArbacBindings {
|
|
228
259
|
getScopes: <TScope extends object>() => TScope[] | undefined;
|
|
229
260
|
setScopes: <TScope extends object>(scope: TScope[] | undefined) => void;
|
|
@@ -246,6 +277,14 @@ interface ArbacBindings {
|
|
|
246
277
|
scopes?: TScope[];
|
|
247
278
|
userId: string;
|
|
248
279
|
}>;
|
|
280
|
+
/**
|
|
281
|
+
* The current principal — user id, held and effective roles, lazy
|
|
282
|
+
* attributes and credential attenuation — read through the
|
|
283
|
+
* `ArbacUserProvider`, the same source `evaluate()` uses. Loaded fresh on
|
|
284
|
+
* every call (like `evaluate()`), so a role change applies immediately.
|
|
285
|
+
* Decide on `effectiveRoles` (or `evaluate()`), never on `roles`.
|
|
286
|
+
*/
|
|
287
|
+
principal: <TUserAttrs extends object = object>() => Promise<ArbacPrincipal<TUserAttrs>>;
|
|
249
288
|
resource: string;
|
|
250
289
|
action: string;
|
|
251
290
|
isPublic: boolean;
|
package/dist/index.mjs
CHANGED
|
@@ -871,6 +871,11 @@ async function loadPrincipal(user) {
|
|
|
871
871
|
};
|
|
872
872
|
}
|
|
873
873
|
const arbacDeps = cachedBy((_controller, ctx) => Promise.all([useControllerContext(ctx).instantiate(ArbacUserProviderToken), useControllerContext(ctx).instantiate(MoostArbac)]));
|
|
874
|
+
/** Load the current principal through the controller's user provider (fresh, no memo). */
|
|
875
|
+
async function loadCurrentPrincipal(ctx) {
|
|
876
|
+
const [user] = await arbacDeps(useControllerContext(ctx).getController(), ctx);
|
|
877
|
+
return loadPrincipal(user);
|
|
878
|
+
}
|
|
874
879
|
const principalKey = key("arbac.principal");
|
|
875
880
|
function isHttpEvent(ctx) {
|
|
876
881
|
return ctx.has(eventTypeKey) && ctx.get(eventTypeKey) === "http";
|
|
@@ -1044,11 +1049,23 @@ const useArbac = (_ctx) => {
|
|
|
1044
1049
|
allowed: true
|
|
1045
1050
|
};
|
|
1046
1051
|
};
|
|
1052
|
+
const principal = async () => {
|
|
1053
|
+
const p = await loadCurrentPrincipal(ctx);
|
|
1054
|
+
const claimed = p.attenuate?.roles;
|
|
1055
|
+
return {
|
|
1056
|
+
userId: p.userId,
|
|
1057
|
+
roles: p.roles,
|
|
1058
|
+
effectiveRoles: claimed ? p.roles.filter((r) => claimed.includes(r)) : p.roles,
|
|
1059
|
+
attrs: () => p.attrs(p.userId),
|
|
1060
|
+
...p.attenuate && { attenuation: p.attenuate }
|
|
1061
|
+
};
|
|
1062
|
+
};
|
|
1047
1063
|
return {
|
|
1048
1064
|
getScopes,
|
|
1049
1065
|
setScopes,
|
|
1050
1066
|
evaluate,
|
|
1051
1067
|
evaluateOrThrow,
|
|
1068
|
+
principal,
|
|
1052
1069
|
resource,
|
|
1053
1070
|
action,
|
|
1054
1071
|
isPublic
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aooth/arbac-moost",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Moost RBAC integration for aoothjs (migrated from @moostjs/arbac)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"abac",
|
|
@@ -60,30 +60,30 @@
|
|
|
60
60
|
"access": "public"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@uniqu/core": "^0.
|
|
64
|
-
"@aooth/arbac": "0.2.
|
|
65
|
-
"@aooth/user": "0.2.
|
|
66
|
-
"@aooth/arbac-core": "0.2.
|
|
63
|
+
"@uniqu/core": "^0.2.0",
|
|
64
|
+
"@aooth/arbac": "0.2.3",
|
|
65
|
+
"@aooth/user": "0.2.3",
|
|
66
|
+
"@aooth/arbac-core": "0.2.3"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"@atscript/core": "^0.2.
|
|
70
|
-
"@atscript/db": "^0.1.
|
|
71
|
-
"@atscript/db-sql-tools": "^0.1.
|
|
72
|
-
"@atscript/db-sqlite": "^0.1.
|
|
73
|
-
"@atscript/moost-db": "^0.1.
|
|
74
|
-
"@atscript/typescript": "^0.2.
|
|
75
|
-
"@moostjs/event-http": "^0.7.
|
|
69
|
+
"@atscript/core": "^0.2.4",
|
|
70
|
+
"@atscript/db": "^0.1.168",
|
|
71
|
+
"@atscript/db-sql-tools": "^0.1.168",
|
|
72
|
+
"@atscript/db-sqlite": "^0.1.168",
|
|
73
|
+
"@atscript/moost-db": "^0.1.168",
|
|
74
|
+
"@atscript/typescript": "^0.2.4",
|
|
75
|
+
"@moostjs/event-http": "^0.7.2",
|
|
76
76
|
"@types/better-sqlite3": "^7.6.13",
|
|
77
77
|
"better-sqlite3": "^12.6.2",
|
|
78
|
-
"unplugin-atscript": "^0.2.
|
|
78
|
+
"unplugin-atscript": "^0.2.4"
|
|
79
79
|
},
|
|
80
80
|
"peerDependencies": {
|
|
81
|
-
"@atscript/db": "^0.1.
|
|
82
|
-
"@atscript/moost-db": "^0.1.
|
|
83
|
-
"@atscript/typescript": "^0.2.
|
|
84
|
-
"@moostjs/event-http": "^0.7.
|
|
81
|
+
"@atscript/db": "^0.1.168",
|
|
82
|
+
"@atscript/moost-db": "^0.1.168",
|
|
83
|
+
"@atscript/typescript": "^0.2.4",
|
|
84
|
+
"@moostjs/event-http": "^0.7.2",
|
|
85
85
|
"@wooksjs/event-core": "^0.8.0",
|
|
86
|
-
"moost": "^0.7.
|
|
86
|
+
"moost": "^0.7.2"
|
|
87
87
|
},
|
|
88
88
|
"peerDependenciesMeta": {
|
|
89
89
|
"@atscript/db": {
|