@aooth/arbac-moost 0.2.1 → 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.d.mts +9 -17
- package/dist/atscript/index.mjs +16 -19
- package/dist/{decorateMetadata-CU_mqYGT.mjs → decorateMetadata-BqEexuhv.mjs} +3 -6
- package/dist/index.d.mts +81 -66
- package/dist/index.mjs +48 -48
- package/dist/plugin.d.mts +1 -4
- package/dist/plugin.mjs +1 -2
- package/dist/{user.provider-SisapkME.d.mts → user.provider-BbYgv9RC.d.mts} +0 -14
- package/package.json +18 -18
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { r as AoothArbacClaims, t as ArbacUserProvider } from "../user.provider-
|
|
1
|
+
import { r as AoothArbacClaims, t as ArbacUserProvider } from "../user.provider-BbYgv9RC.mjs";
|
|
2
2
|
import { TAtscriptAnnotatedType, TAtscriptTypeObject, TMetadataMap, TValidatorOptions, Validator } from "@atscript/typescript/utils";
|
|
3
3
|
import { AoothUserCredentials } from "@aooth/user/atscript-db/model.as";
|
|
4
|
-
//#region src/atscript/auto-provider.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* Minimal atscript-db readable surface used to fetch the user record.
|
|
7
6
|
* Structurally compatible with `AtscriptDbTable<T>.findOne` so the runtime
|
|
@@ -74,7 +73,7 @@ interface ArbacUserRecordCacheOptions {
|
|
|
74
73
|
*
|
|
75
74
|
* @since 0.1.78
|
|
76
75
|
*/
|
|
77
|
-
declare class ArbacUserRecordCache {
|
|
76
|
+
export declare class ArbacUserRecordCache {
|
|
78
77
|
private readonly ttlMs;
|
|
79
78
|
private readonly max;
|
|
80
79
|
private readonly now;
|
|
@@ -103,7 +102,7 @@ declare class ArbacUserRecordCache {
|
|
|
103
102
|
* `extraSelect` (third constructor argument) to have the fetch include the
|
|
104
103
|
* extra fields they read.
|
|
105
104
|
*/
|
|
106
|
-
declare abstract class AtscriptArbacUserProvider<T extends object = object> extends ArbacUserProvider {
|
|
105
|
+
export declare abstract class AtscriptArbacUserProvider<T extends object = object> extends ArbacUserProvider {
|
|
107
106
|
protected readonly userType: TAtscriptAnnotatedType;
|
|
108
107
|
protected readonly table: ArbacUserTable<T>;
|
|
109
108
|
private readonly spec;
|
|
@@ -142,8 +141,6 @@ declare abstract class AtscriptArbacUserProvider<T extends object = object> exte
|
|
|
142
141
|
*/
|
|
143
142
|
private fetchRecord;
|
|
144
143
|
}
|
|
145
|
-
//#endregion
|
|
146
|
-
//#region src/atscript/attenuation-extract.d.ts
|
|
147
144
|
/**
|
|
148
145
|
* Spec computed once per credential `TAtscriptAnnotatedType` — which typed root
|
|
149
146
|
* fields carry the restrict-only ARBAC attenuation:
|
|
@@ -165,7 +162,7 @@ interface ArbacAttenuationSpec {
|
|
|
165
162
|
* {@link ArbacAttenuationSpec}. Mirrors the user-side `getArbacExtractSpec`:
|
|
166
163
|
* structural, computed once, fail-loud on an ambiguous (multiple) role field.
|
|
167
164
|
*/
|
|
168
|
-
declare function getArbacAttenuationSpec(credType: TAtscriptAnnotatedType): ArbacAttenuationSpec;
|
|
165
|
+
export declare function getArbacAttenuationSpec(credType: TAtscriptAnnotatedType): ArbacAttenuationSpec;
|
|
169
166
|
/**
|
|
170
167
|
* Boot-time cross-model check: every `@arbac.attenuate.attr "userAttr"` target
|
|
171
168
|
* must name a real key in the user model's `@arbac.attribute` keyspace
|
|
@@ -174,7 +171,7 @@ declare function getArbacAttenuationSpec(credType: TAtscriptAnnotatedType): Arba
|
|
|
174
171
|
* cached). Soundness does NOT depend on this — the scope conjunction clips
|
|
175
172
|
* regardless — but it turns a silent misconfig into a loud boot failure.
|
|
176
173
|
*/
|
|
177
|
-
declare function validateAttenuationTargets(credType: TAtscriptAnnotatedType, validUserAttrs: Iterable<string>): void;
|
|
174
|
+
export declare function validateAttenuationTargets(credType: TAtscriptAnnotatedType, validUserAttrs: Iterable<string>): void;
|
|
178
175
|
/**
|
|
179
176
|
* Build the restrict-only {@link AoothArbacClaims} for a credential `record`
|
|
180
177
|
* (its typed root fields — e.g. the auth context, which carries the credential
|
|
@@ -194,9 +191,7 @@ declare function validateAttenuationTargets(credType: TAtscriptAnnotatedType, va
|
|
|
194
191
|
* are omitted (attrs-only narrowing), which is the distinct "no role narrowing"
|
|
195
192
|
* case, not a malformed one.
|
|
196
193
|
*/
|
|
197
|
-
declare function extractAttenuation(credType: TAtscriptAnnotatedType, record: object | null | undefined): AoothArbacClaims | undefined;
|
|
198
|
-
//#endregion
|
|
199
|
-
//#region src/atscript/handle-spec.d.ts
|
|
194
|
+
export declare function extractAttenuation(credType: TAtscriptAnnotatedType, record: object | null | undefined): AoothArbacClaims | undefined;
|
|
200
195
|
/**
|
|
201
196
|
* Resolved login/recovery HANDLE fields for a user credential model, discovered
|
|
202
197
|
* from the `@aooth.user.*` annotations (registered by `arbacPlugin`). Computed
|
|
@@ -233,14 +228,12 @@ interface AoothUserHandleSpec {
|
|
|
233
228
|
* `@aooth.user.*` field resolves to all-`undefined` handles (email/phone login
|
|
234
229
|
* is simply unavailable — graceful degradation, not an error).
|
|
235
230
|
*/
|
|
236
|
-
declare function getAoothUserHandleSpec(userType: TAtscriptAnnotatedType): AoothUserHandleSpec;
|
|
237
|
-
//#endregion
|
|
238
|
-
//#region src/atscript/models/user.as.d.ts
|
|
231
|
+
export declare function getAoothUserHandleSpec(userType: TAtscriptAnnotatedType): AoothUserHandleSpec;
|
|
239
232
|
/**
|
|
240
233
|
* Atscript interface **AoothArbacUserCredentials**
|
|
241
234
|
* @see {@link ./user.as:7:18}
|
|
242
235
|
*/
|
|
243
|
-
declare class AoothArbacUserCredentials extends AoothUserCredentials {
|
|
236
|
+
export declare class AoothArbacUserCredentials extends AoothUserCredentials {
|
|
244
237
|
roles: string[];
|
|
245
238
|
static __is_atscript_annotated_type: true;
|
|
246
239
|
static type: TAtscriptTypeObject<keyof AoothArbacUserCredentials, AoothArbacUserCredentials>;
|
|
@@ -252,5 +245,4 @@ declare class AoothArbacUserCredentials extends AoothUserCredentials {
|
|
|
252
245
|
static toExampleData?: () => any;
|
|
253
246
|
}
|
|
254
247
|
// prettier-ignore-end
|
|
255
|
-
|
|
256
|
-
export { AoothArbacUserCredentials, type AoothUserHandleSpec, type ArbacAttenuationSpec, ArbacUserRecordCache, type ArbacUserRecordCacheOptions, type ArbacUserTable, AtscriptArbacUserProvider, type AtscriptArbacUserProviderOptions, extractAttenuation, getAoothUserHandleSpec, getArbacAttenuationSpec, validateAttenuationTargets };
|
|
248
|
+
export type { AoothUserHandleSpec, ArbacAttenuationSpec, ArbacUserRecordCacheOptions, ArbacUserTable, AtscriptArbacUserProviderOptions };
|
package/dist/atscript/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { i as __decorate, n as ArbacUserProvider, t as __decorateMetadata } from "../decorateMetadata-
|
|
1
|
+
import { i as __decorate, n as ArbacUserProvider, t as __decorateMetadata } from "../decorateMetadata-BqEexuhv.mjs";
|
|
2
2
|
import { defineWook, key } from "@wooksjs/event-core";
|
|
3
3
|
import { Injectable } from "moost";
|
|
4
4
|
import { $ak, $f, $nr, defineAnnotatedType, throwFeatureDisabled } from "@atscript/typescript/utils";
|
|
5
5
|
import { AoothUserCredentials } from "@aooth/user/atscript-db/model.as";
|
|
6
|
-
|
|
6
|
+
// src/atscript/role-list.ts
|
|
7
7
|
/**
|
|
8
8
|
* Collect unique, non-empty strings from an iterable of unknown values,
|
|
9
9
|
* preserving first-seen order and dropping anything that is not a non-empty
|
|
@@ -21,8 +21,7 @@ function uniqueStrings(values) {
|
|
|
21
21
|
}
|
|
22
22
|
return out;
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
//#region src/atscript/auto-provider.ts
|
|
24
|
+
// src/atscript/auto-provider.ts
|
|
26
25
|
const specCache$2 = /* @__PURE__ */ new WeakMap();
|
|
27
26
|
/**
|
|
28
27
|
* Resolve the identifier field on an object type using the three-step chain
|
|
@@ -52,12 +51,14 @@ function resolveIdentifierField(type) {
|
|
|
52
51
|
}
|
|
53
52
|
if (explicit) return explicit;
|
|
54
53
|
const preferred = type.metadata.get("db.table.preferredId.uniqueIndex");
|
|
55
|
-
if (preferred !== void 0)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
54
|
+
if (preferred !== void 0) {
|
|
55
|
+
if (typeof preferred === "string") {
|
|
56
|
+
const fields = uniqueIndexFields.get(preferred);
|
|
57
|
+
if (fields && fields.length === 1) return fields[0];
|
|
58
|
+
} else {
|
|
59
|
+
for (const fields of uniqueIndexFields.values()) if (fields.length === 1) return fields[0];
|
|
60
|
+
if (anyUniqueField.length > 0) return anyUniqueField[0];
|
|
61
|
+
}
|
|
61
62
|
}
|
|
62
63
|
return metaId;
|
|
63
64
|
}
|
|
@@ -308,8 +309,7 @@ AtscriptArbacUserProvider = __decorate([Injectable(), __decorateMetadata("design
|
|
|
308
309
|
Object,
|
|
309
310
|
Object
|
|
310
311
|
])], AtscriptArbacUserProvider);
|
|
311
|
-
|
|
312
|
-
//#region src/atscript/attenuation-extract.ts
|
|
312
|
+
// src/atscript/attenuation-extract.ts
|
|
313
313
|
const specCache$1 = /* @__PURE__ */ new WeakMap();
|
|
314
314
|
/**
|
|
315
315
|
* Walk a credential model's `@arbac.attenuate.*` annotations into a cached
|
|
@@ -403,8 +403,7 @@ function extractAttenuation(credType, record) {
|
|
|
403
403
|
if (attrs !== void 0) out.attrs = attrs;
|
|
404
404
|
return out;
|
|
405
405
|
}
|
|
406
|
-
|
|
407
|
-
//#region src/atscript/handle-spec.ts
|
|
406
|
+
// src/atscript/handle-spec.ts
|
|
408
407
|
const specCache = /* @__PURE__ */ new WeakMap();
|
|
409
408
|
/** A `@db.index.unique` annotation is a non-empty `(string | true)[]`. */
|
|
410
409
|
function hasUniqueIndex(md) {
|
|
@@ -466,8 +465,7 @@ function getAoothUserHandleSpec(userType) {
|
|
|
466
465
|
specCache.set(userType, spec);
|
|
467
466
|
return spec;
|
|
468
467
|
}
|
|
469
|
-
|
|
470
|
-
//#region src/atscript/models/user.as
|
|
468
|
+
// src/atscript/models/user.as
|
|
471
469
|
var AoothArbacUserCredentials = class {
|
|
472
470
|
static __is_atscript_annotated_type = true;
|
|
473
471
|
static type = {};
|
|
@@ -477,8 +475,7 @@ var AoothArbacUserCredentials = class {
|
|
|
477
475
|
throwFeatureDisabled("JSON Schema", "jsonSchema", "emit.jsonSchema");
|
|
478
476
|
}
|
|
479
477
|
};
|
|
480
|
-
$ak("db.index.fulltext", "db.index.plain", "db.index.unique", "db.view.joins", "expect.pattern");
|
|
481
|
-
$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");
|
|
482
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);
|
|
483
|
-
//#endregion
|
|
484
481
|
export { AoothArbacUserCredentials, ArbacUserRecordCache, AtscriptArbacUserProvider, extractAttenuation, getAoothUserHandleSpec, getArbacAttenuationSpec, validateAttenuationTargets };
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
// \0@oxc-project+runtime@0.155.0/helpers/esm/decorate.js
|
|
2
2
|
function __decorate(decorators, target, key, desc) {
|
|
3
3
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
4
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
5
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
//#region src/user.provider.ts
|
|
8
|
+
// src/user.provider.ts
|
|
10
9
|
/**
|
|
11
10
|
* Abstract base class for providing user data required for ARBAC evaluations.
|
|
12
11
|
*
|
|
@@ -27,10 +26,8 @@ var ArbacUserProvider = class {};
|
|
|
27
26
|
* etc. Runtime resolves to the concrete subclass registered via DI.
|
|
28
27
|
*/
|
|
29
28
|
const ArbacUserProviderToken = ArbacUserProvider;
|
|
30
|
-
|
|
31
|
-
//#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorateMetadata.js
|
|
29
|
+
// \0@oxc-project+runtime@0.155.0/helpers/esm/decorateMetadata.js
|
|
32
30
|
function __decorateMetadata(k, v) {
|
|
33
31
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
34
32
|
}
|
|
35
|
-
//#endregion
|
|
36
33
|
export { __decorate as i, ArbacUserProvider as n, ArbacUserProviderToken as r, __decorateMetadata as t };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as ProjectionOf, a as conjoinArbacDbScopes, b as TArbacMeta, c as ArbacDbScope, d as extractUsedControlValues, f as applyAllowedFieldsAndSet, g as OwnFieldKey, h as NavTarget, i as ConjoinArbacDbScopesOptions, l as AsArbacDbController, m as NavRelationKey, n as ArbacUserProviderToken, o as RefForeignKey, p as ControlsOf, r as AoothArbacClaims, s as RefTableSource, t as ArbacUserProvider, u as enforceControlsPolicy, v as ARBAC_DELEGATED_AUTH, x as getArbacMate, y as ArbacDelegatedAuth } from "./user.provider-
|
|
1
|
+
import { _ as ProjectionOf, a as conjoinArbacDbScopes, b as TArbacMeta, c as ArbacDbScope, d as extractUsedControlValues, f as applyAllowedFieldsAndSet, g as OwnFieldKey, h as NavTarget, i as ConjoinArbacDbScopesOptions, l as AsArbacDbController, m as NavRelationKey, n as ArbacUserProviderToken, o as RefForeignKey, p as ControlsOf, r as AoothArbacClaims, s as RefTableSource, t as ArbacUserProvider, u as enforceControlsPolicy, v as ARBAC_DELEGATED_AUTH, x as getArbacMate, y as ArbacDelegatedAuth } from "./user.provider-BbYgv9RC.mjs";
|
|
2
2
|
import { Arbac, Arbac as Arbac$1, TArbacCompiledRule, TArbacEvalResult, TArbacEvalResult as TArbacEvalResult$1, TArbacRole, TArbacRoleForResource, TArbacRule, arbacPatternToRegex } from "@aooth/arbac-core";
|
|
3
3
|
import { ControlGate, ControlGate as ControlGate$1, TProjection, TScopeFieldRules, TScopeFilter, conjoinScopeFilters } from "@aooth/arbac";
|
|
4
4
|
import { TAuthGuardDef } from "@moostjs/event-http";
|
|
@@ -6,7 +6,6 @@ import { EventContext } from "@wooksjs/event-core";
|
|
|
6
6
|
import { FilterExpr, TDbRemoveGuardContext, TDbWriteCheckContext, TDbWriteGuardContext, TDeleteOptions, TMetaResponse, TRowResolveOptions, TWriteOptions, UniqueryControls } from "@atscript/db";
|
|
7
7
|
import { AsDbReadableController, AsJsonValueHelpController, AsValueHelpController, TDbActionScopeContext, TDbControlsType, TDbIndexFieldPaths, TDbRequestContext, ValueHelpSelect } from "@atscript/moost-db";
|
|
8
8
|
import { TAtscriptAnnotatedType, TAtscriptDataType, TSerializedAnnotatedType } from "@atscript/typescript/utils";
|
|
9
|
-
//#region src/db/visibility.d.ts
|
|
10
9
|
/**
|
|
11
10
|
* The slice of an atscript-db readable (table / view) the visibility walk
|
|
12
11
|
* reads — a moost-db controller's `this.readable` satisfies it: identifiers
|
|
@@ -136,20 +135,20 @@ interface MetaVisibility {
|
|
|
136
135
|
* scopes at all, or any scope without a `projection` (a universal grant makes
|
|
137
136
|
* `unionProjections` collapse to the universe `{}`).
|
|
138
137
|
*/
|
|
139
|
-
declare function unionScopeProjection(scopes: ArbacDbScope[]): TProjection | undefined;
|
|
138
|
+
export declare function unionScopeProjection(scopes: ArbacDbScope[]): TProjection | undefined;
|
|
140
139
|
/**
|
|
141
140
|
* Relation names any scope explicitly declares via `with.<name>` — those
|
|
142
141
|
* relations are governed by the declared sub-scopes alone (parent authority),
|
|
143
142
|
* and the declaration implies the relation EXISTS for this principal even
|
|
144
143
|
* when the projection union does not name it (see {@link ArbacDbScope.with}).
|
|
145
144
|
*/
|
|
146
|
-
declare function collectWithGrantNames(scopes: ArbacDbScope[]): ReadonlySet<string>;
|
|
145
|
+
export declare function collectWithGrantNames(scopes: ArbacDbScope[]): ReadonlySet<string>;
|
|
147
146
|
/**
|
|
148
147
|
* Union of write-scope `allowedFields`; `"all"` for field-unrestricted write
|
|
149
148
|
* access. The whitelist exists only when at least one scope carries an
|
|
150
149
|
* `allowedFields` array — scoped-but-unlisted writes are field-unrestricted.
|
|
151
150
|
*/
|
|
152
|
-
declare function collectWritableFields(scopes: ArbacDbScope[], unrestricted: boolean): ReadonlySet<string> | "all" | undefined;
|
|
151
|
+
export declare function collectWritableFields(scopes: ArbacDbScope[], unrestricted: boolean): ReadonlySet<string> | "all" | undefined;
|
|
153
152
|
/**
|
|
154
153
|
* Whether a flattened dot-path field exists for this principal.
|
|
155
154
|
*
|
|
@@ -164,13 +163,13 @@ declare function collectWritableFields(scopes: ArbacDbScope[], unrestricted: boo
|
|
|
164
163
|
* So a field a joined table hides is as unknown in a `$with` sub-query as a
|
|
165
164
|
* top-level hidden column is in the main query (no filter/sort value oracle).
|
|
166
165
|
*/
|
|
167
|
-
declare function isMetaFieldVisible(path: string, vis: MetaVisibility): boolean;
|
|
166
|
+
export declare function isMetaFieldVisible(path: string, vis: MetaVisibility): boolean;
|
|
168
167
|
/**
|
|
169
168
|
* PK + `preferredId` for a controller's table/readable — the
|
|
170
169
|
* {@link MetaVisibility.alwaysVisible} set. Kept for compatibility: the
|
|
171
170
|
* controllers now pass `this.readable` and it is derived there.
|
|
172
171
|
*/
|
|
173
|
-
declare function metaAlwaysVisibleFields(_controller: object, source: {
|
|
172
|
+
export declare function metaAlwaysVisibleFields(_controller: object, source: {
|
|
174
173
|
primaryKeys: readonly string[];
|
|
175
174
|
preferredId: readonly string[];
|
|
176
175
|
}): ReadonlySet<string>;
|
|
@@ -199,9 +198,7 @@ interface ScopeVisibilityOptions {
|
|
|
199
198
|
* @param opts - {@link ScopeVisibilityOptions}; a bare identifier set is the
|
|
200
199
|
* 0.1.71 `alwaysVisible` argument
|
|
201
200
|
*/
|
|
202
|
-
declare function buildScopeVisibility(scopes: ArbacDbScope[], table: VisibilityTableSource | undefined, opts?: ScopeVisibilityOptions | ReadonlySet<string>): MetaVisibility;
|
|
203
|
-
//#endregion
|
|
204
|
-
//#region src/arbac.composables.d.ts
|
|
201
|
+
export declare function buildScopeVisibility(scopes: ArbacDbScope[], table: VisibilityTableSource | undefined, opts?: ScopeVisibilityOptions | ReadonlySet<string>): MetaVisibility;
|
|
205
202
|
/**
|
|
206
203
|
* The scopes cached for the current event (`undefined` before the authorize
|
|
207
204
|
* interceptor / `setScopes` ran). A direct slot read — no controller
|
|
@@ -210,9 +207,9 @@ declare function buildScopeVisibility(scopes: ArbacDbScope[], table: VisibilityT
|
|
|
210
207
|
*
|
|
211
208
|
* `TScope` is a caller-side type witness (see `evaluate` below).
|
|
212
209
|
*/
|
|
213
|
-
declare function getArbacScopes<TScope extends object>(ctx?: EventContext): TScope[] | undefined;
|
|
210
|
+
export declare function getArbacScopes<TScope extends object>(ctx?: EventContext): TScope[] | undefined;
|
|
214
211
|
/** Options of `useArbac().evaluate()` / `evaluateOrThrow()`. */
|
|
215
|
-
interface ArbacEvaluateOptions {
|
|
212
|
+
export interface ArbacEvaluateOptions {
|
|
216
213
|
/** Resource to evaluate; defaults to the current handler's. */
|
|
217
214
|
resource?: string;
|
|
218
215
|
/** Action to evaluate; defaults to the current handler's. */
|
|
@@ -227,6 +224,37 @@ interface ArbacEvaluateOptions {
|
|
|
227
224
|
*/
|
|
228
225
|
table?: VisibilityTableSource;
|
|
229
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
|
+
}
|
|
230
258
|
interface ArbacBindings {
|
|
231
259
|
getScopes: <TScope extends object>() => TScope[] | undefined;
|
|
232
260
|
setScopes: <TScope extends object>(scope: TScope[] | undefined) => void;
|
|
@@ -249,6 +277,14 @@ interface ArbacBindings {
|
|
|
249
277
|
scopes?: TScope[];
|
|
250
278
|
userId: string;
|
|
251
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>>;
|
|
252
288
|
resource: string;
|
|
253
289
|
action: string;
|
|
254
290
|
isPublic: boolean;
|
|
@@ -268,9 +304,7 @@ interface ArbacBindings {
|
|
|
268
304
|
* step handlers. Scope read/write goes through `arbacScopesKey` directly
|
|
269
305
|
* so it still lives on the per-event slot.
|
|
270
306
|
*/
|
|
271
|
-
declare const useArbac: (_ctx?: EventContext) => ArbacBindings;
|
|
272
|
-
//#endregion
|
|
273
|
-
//#region src/arbac.decorator.d.ts
|
|
307
|
+
export declare const useArbac: (_ctx?: EventContext) => ArbacBindings;
|
|
274
308
|
/**
|
|
275
309
|
* ARBAC checks authorization, not authentication, so the transport
|
|
276
310
|
* declaration is empty — pair with an upstream auth guard (e.g. JWT
|
|
@@ -281,21 +315,19 @@ declare const useArbac: (_ctx?: EventContext) => ArbacBindings;
|
|
|
281
315
|
* apply it to controllers/handlers that should remain reachable without an
|
|
282
316
|
* evaluated rule (e.g. login/recovery workflows, health probes).
|
|
283
317
|
*/
|
|
284
|
-
declare const arbacAuthorizeInterceptor: TAuthGuardDef;
|
|
318
|
+
export declare const arbacAuthorizeInterceptor: TAuthGuardDef;
|
|
285
319
|
/** Wrapped via `Authenticate` so `@moostjs/swagger` picks up the auth-guard metadata. */
|
|
286
|
-
declare const ArbacAuthorize: () => ClassDecorator & MethodDecorator;
|
|
320
|
+
export declare const ArbacAuthorize: () => ClassDecorator & MethodDecorator;
|
|
287
321
|
/**
|
|
288
322
|
* Decorator to specify a resource id for ARBAC evaluation. Apply to a
|
|
289
323
|
* controller class or a handler method.
|
|
290
324
|
*/
|
|
291
|
-
declare const ArbacResource: (name: string) => MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
|
|
325
|
+
export declare const ArbacResource: (name: string) => MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
|
|
292
326
|
/**
|
|
293
327
|
* Decorator to specify an action id for ARBAC evaluation. Typically applied
|
|
294
328
|
* at the method level.
|
|
295
329
|
*/
|
|
296
|
-
declare const ArbacAction: (name: string) => MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
|
|
297
|
-
//#endregion
|
|
298
|
-
//#region src/db/as-arbac-db-readable-controller.d.ts
|
|
330
|
+
export declare const ArbacAction: (name: string) => MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
|
|
299
331
|
type TSelect = UniqueryControls["$select"];
|
|
300
332
|
/**
|
|
301
333
|
* Read-only mirror of {@link AsArbacDbController} for view-style controllers
|
|
@@ -303,7 +335,7 @@ type TSelect = UniqueryControls["$select"];
|
|
|
303
335
|
* Applies the same fail-closed `prepareRequest` and filter / projection /
|
|
304
336
|
* controls overlays — no write-side hooks because the parent exposes none.
|
|
305
337
|
*/
|
|
306
|
-
declare class AsArbacDbReadableController<T extends TAtscriptAnnotatedType = TAtscriptAnnotatedType> extends AsDbReadableController<T> {
|
|
338
|
+
export declare class AsArbacDbReadableController<T extends TAtscriptAnnotatedType = TAtscriptAnnotatedType> extends AsDbReadableController<T> {
|
|
307
339
|
/** Makes this controller the `$with` policy source for its table's ARBAC resource. */
|
|
308
340
|
protected readonly _arbacRelationTarget: true;
|
|
309
341
|
/** Same contract as {@link AsArbacDbController.prepareRequest}. */
|
|
@@ -335,8 +367,6 @@ declare class AsArbacDbReadableController<T extends TAtscriptAnnotatedType = TAt
|
|
|
335
367
|
/** Same contract as {@link AsArbacDbController.hasField}. */
|
|
336
368
|
protected hasField(path: string): boolean;
|
|
337
369
|
}
|
|
338
|
-
//#endregion
|
|
339
|
-
//#region src/db/as-arbac-value-help-controller.d.ts
|
|
340
370
|
/**
|
|
341
371
|
* ARBAC-scoped mirror of `@atscript/moost-db`'s {@link AsValueHelpController}
|
|
342
372
|
* (bring your own backing source): the same scope contract as
|
|
@@ -370,7 +400,7 @@ declare class AsArbacDbReadableController<T extends TAtscriptAnnotatedType = TAt
|
|
|
370
400
|
*
|
|
371
401
|
* @since 0.1.72
|
|
372
402
|
*/
|
|
373
|
-
declare abstract class AsArbacValueHelpController<T extends TAtscriptAnnotatedType = TAtscriptAnnotatedType, DataType = TAtscriptDataType<T>> extends AsValueHelpController<T, DataType> {
|
|
403
|
+
export declare abstract class AsArbacValueHelpController<T extends TAtscriptAnnotatedType = TAtscriptAnnotatedType, DataType = TAtscriptDataType<T>> extends AsValueHelpController<T, DataType> {
|
|
374
404
|
private _arbacHost?;
|
|
375
405
|
/** Makes this controller the binding / `ref` policy source for its bound type's ARBAC resource. */
|
|
376
406
|
protected readonly _arbacValueHelpTarget: true;
|
|
@@ -405,7 +435,7 @@ declare abstract class AsArbacValueHelpController<T extends TAtscriptAnnotatedTy
|
|
|
405
435
|
*
|
|
406
436
|
* @since 0.1.72
|
|
407
437
|
*/
|
|
408
|
-
declare class AsArbacJsonValueHelpController<T extends TAtscriptAnnotatedType = TAtscriptAnnotatedType, DataType = TAtscriptDataType<T>> extends AsJsonValueHelpController<T, DataType> {
|
|
438
|
+
export declare class AsArbacJsonValueHelpController<T extends TAtscriptAnnotatedType = TAtscriptAnnotatedType, DataType = TAtscriptDataType<T>> extends AsJsonValueHelpController<T, DataType> {
|
|
409
439
|
private _arbacHost?;
|
|
410
440
|
/** Makes this controller the binding / `ref` policy source for its bound type's ARBAC resource. */
|
|
411
441
|
protected readonly _arbacValueHelpTarget: true;
|
|
@@ -422,8 +452,6 @@ declare class AsArbacJsonValueHelpController<T extends TAtscriptAnnotatedType =
|
|
|
422
452
|
runGetOne(id: string): ReturnType<AsJsonValueHelpController<T, DataType>["runGetOne"]>;
|
|
423
453
|
runGetOneComposite(query: Record<string, string>): ReturnType<AsJsonValueHelpController<T, DataType>["runGetOneComposite"]>;
|
|
424
454
|
}
|
|
425
|
-
//#endregion
|
|
426
|
-
//#region src/db/relation-policy.d.ts
|
|
427
455
|
/**
|
|
428
456
|
* Register an ARBAC DB controller as an owner of its readable's ARBAC
|
|
429
457
|
* resource, so a `$with` from another controller can evaluate the caller's
|
|
@@ -435,7 +463,7 @@ declare class AsArbacJsonValueHelpController<T extends TAtscriptAnnotatedType =
|
|
|
435
463
|
* @returns `true` (so it can initialize a field)
|
|
436
464
|
* @since 0.1.72
|
|
437
465
|
*/
|
|
438
|
-
declare function registerArbacDbTarget(controller: object): true;
|
|
466
|
+
export declare function registerArbacDbTarget(controller: object): true;
|
|
439
467
|
/**
|
|
440
468
|
* The ARBAC resource + action a controller's handler is authorized as — the
|
|
441
469
|
* precedence `useArbac()` applies while that handler serves a request.
|
|
@@ -445,12 +473,10 @@ declare function registerArbacDbTarget(controller: object): true;
|
|
|
445
473
|
*
|
|
446
474
|
* @since 0.1.72
|
|
447
475
|
*/
|
|
448
|
-
declare function resolveHandlerArbacIds(instance: object, methodName: string): {
|
|
476
|
+
export declare function resolveHandlerArbacIds(instance: object, methodName: string): {
|
|
449
477
|
resource: string;
|
|
450
478
|
action: string;
|
|
451
479
|
};
|
|
452
|
-
//#endregion
|
|
453
|
-
//#region src/db/meta-projection.d.ts
|
|
454
480
|
/**
|
|
455
481
|
* Foreign `ref` targets for `/meta` pruning: annotated type → the caller's
|
|
456
482
|
* visibility on it, or `null` when the caller cannot read it.
|
|
@@ -475,7 +501,7 @@ type MetaRefTargets = ReadonlyMap<object, MetaVisibility | null>;
|
|
|
475
501
|
* NEVER mutates the input — the base controller caches the static envelope
|
|
476
502
|
* (`applyMetaOverlay` contract); every pruned branch is a fresh object.
|
|
477
503
|
*/
|
|
478
|
-
declare function pruneMetaByVisibility(meta: TMetaResponse, vis: MetaVisibility, refTargets?: MetaRefTargets): TMetaResponse;
|
|
504
|
+
export declare function pruneMetaByVisibility(meta: TMetaResponse, vis: MetaVisibility, refTargets?: MetaRefTargets): TMetaResponse;
|
|
479
505
|
/**
|
|
480
506
|
* The full ARBAC `/meta` overlay, shared by the ARBAC DB and value-help
|
|
481
507
|
* controllers.
|
|
@@ -511,7 +537,7 @@ declare function pruneMetaByVisibility(meta: TMetaResponse, vis: MetaVisibility,
|
|
|
511
537
|
* signature) still works, without them
|
|
512
538
|
* @param _indexes - @deprecated ignored since 0.1.74 (moost-db prunes the search surface)
|
|
513
539
|
*/
|
|
514
|
-
declare function applyArbacMetaOverlay(meta: TMetaResponse, source: VisibilityTableSource | ReadonlySet<string>, _indexes?: readonly TDbIndexFieldPaths[]): Promise<TMetaResponse>;
|
|
540
|
+
export declare function applyArbacMetaOverlay(meta: TMetaResponse, source: VisibilityTableSource | ReadonlySet<string>, _indexes?: readonly TDbIndexFieldPaths[]): Promise<TMetaResponse>;
|
|
515
541
|
/**
|
|
516
542
|
* Test-friendly internal helper — exported for unit tests and helper
|
|
517
543
|
* composition; regular consumers should not call this directly.
|
|
@@ -524,16 +550,14 @@ declare function applyArbacMetaOverlay(meta: TMetaResponse, source: VisibilityTa
|
|
|
524
550
|
* properties are skipped entirely (a getter-valued property is not a method
|
|
525
551
|
* and can never carry `@DbAction` metadata).
|
|
526
552
|
*/
|
|
527
|
-
declare function collectMethodNames(instance: object): string[];
|
|
528
|
-
//#endregion
|
|
529
|
-
//#region src/db/request-scopes.d.ts
|
|
553
|
+
export declare function collectMethodNames(instance: object): string[];
|
|
530
554
|
/**
|
|
531
555
|
* The scopes resolved for the current event, or `undefined` before
|
|
532
556
|
* {@link resolveRequestScopes} ran.
|
|
533
557
|
*
|
|
534
558
|
* @since 0.1.72
|
|
535
559
|
*/
|
|
536
|
-
declare function cachedRequestScopes(): ArbacDbScope[] | undefined;
|
|
560
|
+
export declare function cachedRequestScopes(): ArbacDbScope[] | undefined;
|
|
537
561
|
/**
|
|
538
562
|
* Resolve the current event's scopes once: the ones the authorize
|
|
539
563
|
* interceptor cached, else an ARBAC evaluation of the handler's
|
|
@@ -544,7 +568,7 @@ declare function cachedRequestScopes(): ArbacDbScope[] | undefined;
|
|
|
544
568
|
*
|
|
545
569
|
* @since 0.1.72
|
|
546
570
|
*/
|
|
547
|
-
declare function resolveRequestScopes(): Promise<ArbacDbScope[]>;
|
|
571
|
+
export declare function resolveRequestScopes(): Promise<ArbacDbScope[]>;
|
|
548
572
|
/**
|
|
549
573
|
* The resolved scopes, synchronously — for the hooks that run after the
|
|
550
574
|
* entry point (`validateControls`, `transformFilter`, the write guards …).
|
|
@@ -552,7 +576,7 @@ declare function resolveRequestScopes(): Promise<ArbacDbScope[]>;
|
|
|
552
576
|
*
|
|
553
577
|
* @since 0.1.72
|
|
554
578
|
*/
|
|
555
|
-
declare function requireRequestScopes(): ArbacDbScope[];
|
|
579
|
+
export declare function requireRequestScopes(): ArbacDbScope[];
|
|
556
580
|
/**
|
|
557
581
|
* Shared body of the ARBAC controllers' `hasField` overrides: a field
|
|
558
582
|
* outside the read-scope visibility — hidden by the projection union, a
|
|
@@ -563,7 +587,7 @@ declare function requireRequestScopes(): ArbacDbScope[];
|
|
|
563
587
|
*
|
|
564
588
|
* @since 0.1.72
|
|
565
589
|
*/
|
|
566
|
-
declare function requestFieldVisible(path: string, source: VisibilityTableSource | ReadonlySet<string>): boolean;
|
|
590
|
+
export declare function requestFieldVisible(path: string, source: VisibilityTableSource | ReadonlySet<string>): boolean;
|
|
567
591
|
/**
|
|
568
592
|
* Whether `path` is visible to `scopes` over `source` (see
|
|
569
593
|
* {@link requestFieldVisible}, which reads the request's scopes).
|
|
@@ -571,7 +595,7 @@ declare function requestFieldVisible(path: string, source: VisibilityTableSource
|
|
|
571
595
|
* @param source - the controller's `this.readable`; an identifier set (the
|
|
572
596
|
* 0.1.67 signature) still works, without relation / schema rules
|
|
573
597
|
*/
|
|
574
|
-
declare function isScopedFieldVisible(scopes: ArbacDbScope[], path: string, source: VisibilityTableSource | ReadonlySet<string>): boolean;
|
|
598
|
+
export declare function isScopedFieldVisible(scopes: ArbacDbScope[], path: string, source: VisibilityTableSource | ReadonlySet<string>): boolean;
|
|
575
599
|
/**
|
|
576
600
|
* Body of the ARBAC DB / value-help controllers' `prepareRequest` — every
|
|
577
601
|
* endpoint, `@DbAction` handlers included (`endpoint: "action"`, before any
|
|
@@ -593,7 +617,7 @@ declare function isScopedFieldVisible(scopes: ArbacDbScope[], path: string, sour
|
|
|
593
617
|
*
|
|
594
618
|
* @since 0.1.72
|
|
595
619
|
*/
|
|
596
|
-
declare function prepareArbacRequest(ctx: TDbRequestContext, readable?: VisibilityTableSource): Promise<void>;
|
|
620
|
+
export declare function prepareArbacRequest(ctx: TDbRequestContext, readable?: VisibilityTableSource): Promise<void>;
|
|
597
621
|
/**
|
|
598
622
|
* `authorizeForm` for the ARBAC DB controllers: a form is served iff the
|
|
599
623
|
* caller may run at least one of the actions that take it as input — each
|
|
@@ -601,7 +625,7 @@ declare function prepareArbacRequest(ctx: TDbRequestContext, readable?: Visibili
|
|
|
601
625
|
*
|
|
602
626
|
* @since 0.1.72
|
|
603
627
|
*/
|
|
604
|
-
declare function authorizeArbacForm(actionNames: readonly string[]): Promise<boolean>;
|
|
628
|
+
export declare function authorizeArbacForm(actionNames: readonly string[]): Promise<boolean>;
|
|
605
629
|
/**
|
|
606
630
|
* Body of the ARBAC DB controllers' `allowedActions`: the action `names` the
|
|
607
631
|
* caller holds a grant on — each evaluated as {@link actionArbacIds} names
|
|
@@ -610,7 +634,7 @@ declare function authorizeArbacForm(actionNames: readonly string[]): Promise<boo
|
|
|
610
634
|
*
|
|
611
635
|
* @since 0.1.72
|
|
612
636
|
*/
|
|
613
|
-
declare function arbacAllowedActions(names: readonly string[]): Promise<string[]>;
|
|
637
|
+
export declare function arbacAllowedActions(names: readonly string[]): Promise<string[]>;
|
|
614
638
|
/**
|
|
615
639
|
* Body of the ARBAC DB controllers' `actionRowScope`: the rows the
|
|
616
640
|
* `@DbAction` `name` may run on — the filter of the caller's grant on the
|
|
@@ -629,7 +653,7 @@ declare function arbacAllowedActions(names: readonly string[]): Promise<string[]
|
|
|
629
653
|
*
|
|
630
654
|
* @since 0.1.72
|
|
631
655
|
*/
|
|
632
|
-
declare function arbacActionRowScope(name: string): Promise<Record<string, unknown> | undefined>;
|
|
656
|
+
export declare function arbacActionRowScope(name: string): Promise<Record<string, unknown> | undefined>;
|
|
633
657
|
/**
|
|
634
658
|
* Body of the ARBAC controllers' `transformFilter` (and so of the row
|
|
635
659
|
* overlay `/one`, `DELETE` and `@DbAction` ids use): the user filter
|
|
@@ -637,7 +661,7 @@ declare function arbacActionRowScope(name: string): Promise<Record<string, unkno
|
|
|
637
661
|
*
|
|
638
662
|
* @since 0.1.72
|
|
639
663
|
*/
|
|
640
|
-
declare function arbacRowFilter(filter: Record<string, unknown> | undefined): Record<string, unknown>;
|
|
664
|
+
export declare function arbacRowFilter(filter: Record<string, unknown> | undefined): Record<string, unknown>;
|
|
641
665
|
/**
|
|
642
666
|
* Body of the ARBAC DB controllers' `transformRelationFilter` (since 0.1.74):
|
|
643
667
|
* the operand of a CLIENT relational predicate at `path` (`ticket`,
|
|
@@ -651,9 +675,7 @@ declare function arbacRowFilter(filter: Record<string, unknown> | undefined): Re
|
|
|
651
675
|
*
|
|
652
676
|
* @since 0.1.74
|
|
653
677
|
*/
|
|
654
|
-
declare function arbacRelationFilter(path: string, filter: FilterExpr, readable: VisibilityTableSource): FilterExpr;
|
|
655
|
-
//#endregion
|
|
656
|
-
//#region src/db/shared-read-helpers.d.ts
|
|
678
|
+
export declare function arbacRelationFilter(path: string, filter: FilterExpr, readable: VisibilityTableSource): FilterExpr;
|
|
657
679
|
/**
|
|
658
680
|
* Restrict the user-supplied `$select` to the scopes' projection union.
|
|
659
681
|
* Returns the original projection untouched when no scope declares a
|
|
@@ -677,14 +699,14 @@ declare function arbacRelationFilter(path: string, filter: FilterExpr, readable:
|
|
|
677
699
|
*
|
|
678
700
|
* @since 0.1.72
|
|
679
701
|
*/
|
|
680
|
-
declare function applyArbacProjection(projection: unknown, scopes: ArbacDbScope[], readable?: VisibilityTableSource): TProjection | undefined;
|
|
702
|
+
export declare function applyArbacProjection(projection: unknown, scopes: ArbacDbScope[], readable?: VisibilityTableSource): TProjection | undefined;
|
|
681
703
|
/**
|
|
682
704
|
* Enforce the union of per-scope `controls` gates against the parsed
|
|
683
705
|
* Uniquery controls. Throws `HttpError(403)` on the first violation.
|
|
684
706
|
*
|
|
685
707
|
* @since 0.1.72
|
|
686
708
|
*/
|
|
687
|
-
declare function applyArbacControls(controls: Record<string, unknown>, scopes: ArbacDbScope[]): void;
|
|
709
|
+
export declare function applyArbacControls(controls: Record<string, unknown>, scopes: ArbacDbScope[]): void;
|
|
688
710
|
/**
|
|
689
711
|
* Walk the user-supplied `$with` items in `controls` and overlay each joined
|
|
690
712
|
* relation with the policy of its rows (the `$with` inherit-target policy):
|
|
@@ -701,9 +723,7 @@ declare function applyArbacControls(controls: Record<string, unknown>, scopes: A
|
|
|
701
723
|
*
|
|
702
724
|
* @since 0.1.72
|
|
703
725
|
*/
|
|
704
|
-
declare function applyArbacRelationScopes(controls: Record<string, unknown>, scopes: ArbacDbScope[], readable?: VisibilityTableSource): void;
|
|
705
|
-
//#endregion
|
|
706
|
-
//#region src/db/write-policy.d.ts
|
|
726
|
+
export declare function applyArbacRelationScopes(controls: Record<string, unknown>, scopes: ArbacDbScope[], readable?: VisibilityTableSource): void;
|
|
707
727
|
/** The table surface the write guards need (`AtscriptDbTable` satisfies it). */
|
|
708
728
|
interface ArbacWriteTable {
|
|
709
729
|
count(query: {
|
|
@@ -732,17 +752,15 @@ interface ArbacWriteTable {
|
|
|
732
752
|
* 0.1.75) — and, with `ignoreConflicts` (`?$onConflict=ignore`), refused
|
|
733
753
|
* whenever it cannot, since the post-write check never sees skipped rows.
|
|
734
754
|
*/
|
|
735
|
-
declare function guardArbacWrite(ctx: TDbWriteGuardContext, scopes: readonly ArbacDbScope[], table: ArbacWriteTable, refs: RefTableSource, ignoreConflicts?: boolean): Promise<void>;
|
|
755
|
+
export declare function guardArbacWrite(ctx: TDbWriteGuardContext, scopes: readonly ArbacDbScope[], table: ArbacWriteTable, refs: RefTableSource, ignoreConflicts?: boolean): Promise<void>;
|
|
736
756
|
/**
|
|
737
757
|
* WITH CHECK after the write, inside its transaction: every written row must
|
|
738
758
|
* match the scopes' `check` (default `filter`) — else 403 and the write rolls
|
|
739
759
|
* back. Non-transactional adapters were checked in {@link guardArbacWrite}.
|
|
740
760
|
*/
|
|
741
|
-
declare function checkArbacWrite(ctx: TDbWriteCheckContext, scopes: readonly ArbacDbScope[]): Promise<void>;
|
|
761
|
+
export declare function checkArbacWrite(ctx: TDbWriteCheckContext, scopes: readonly ArbacDbScope[]): Promise<void>;
|
|
742
762
|
/** USING for deletes: the exact row the delete targets must match the scope filter (else 404). */
|
|
743
|
-
declare function guardArbacRemove(ctx: TDbRemoveGuardContext, scopes: readonly ArbacDbScope[], table: Pick<ArbacWriteTable, "count">): Promise<void>;
|
|
744
|
-
//#endregion
|
|
745
|
-
//#region src/db/use-arbac-db-scope.d.ts
|
|
763
|
+
export declare function guardArbacRemove(ctx: TDbRemoveGuardContext, scopes: readonly ArbacDbScope[], table: Pick<ArbacWriteTable, "count">): Promise<void>;
|
|
746
764
|
/**
|
|
747
765
|
* The slice of an atscript-db table {@link ArbacDbScopeHelpers.assertRowsInScope}
|
|
748
766
|
* needs — satisfied by `AtscriptDbTable` / a controller's `this.table`.
|
|
@@ -835,9 +853,7 @@ interface ArbacDbScopeHelpers<T = unknown> {
|
|
|
835
853
|
* await this.table.insertOne({ ...row, ...scope.set() }, scope.writeOptions(this.table));
|
|
836
854
|
* ```
|
|
837
855
|
*/
|
|
838
|
-
declare function useArbacDbScope<T = unknown>(): Promise<ArbacDbScopeHelpers<T>>;
|
|
839
|
-
//#endregion
|
|
840
|
-
//#region src/moost-arbac.d.ts
|
|
856
|
+
export declare function useArbacDbScope<T = unknown>(): Promise<ArbacDbScopeHelpers<T>>;
|
|
841
857
|
/**
|
|
842
858
|
* A DI-enabled extension of the `Arbac` class for use within Moost.
|
|
843
859
|
*
|
|
@@ -849,7 +865,7 @@ declare function useArbacDbScope<T = unknown>(): Promise<ArbacDbScopeHelpers<T>>
|
|
|
849
865
|
* @template TUserAttrs - The type representing user attributes relevant to access control.
|
|
850
866
|
* @template TScope - The type representing access control scopes.
|
|
851
867
|
*/
|
|
852
|
-
declare class MoostArbac<TUserAttrs extends object, TScope extends object> extends Arbac$1<TUserAttrs, TScope> {
|
|
868
|
+
export declare class MoostArbac<TUserAttrs extends object, TScope extends object> extends Arbac$1<TUserAttrs, TScope> {
|
|
853
869
|
private scopeFieldRules;
|
|
854
870
|
/**
|
|
855
871
|
* Register the conjunction rule of custom (declaration-merged) scope
|
|
@@ -916,5 +932,4 @@ declare class MoostArbac<TUserAttrs extends object, TScope extends object> exten
|
|
|
916
932
|
/** The registered custom scope field rules. @since 0.1.72 */
|
|
917
933
|
getScopeFields(): TScopeFieldRules<TScope>;
|
|
918
934
|
}
|
|
919
|
-
|
|
920
|
-
export { ARBAC_DELEGATED_AUTH, type AoothArbacClaims, Arbac, ArbacAction, ArbacAuthorize, ArbacDbScope, type ArbacDbScopeHelpers, ArbacDelegatedAuth, ArbacEvaluateOptions, type ArbacGuardedTable, type ArbacRelationResolution, ArbacResource, type ArbacScopedTable, ArbacUserProvider, ArbacUserProviderToken, type ArbacWriteTable, AsArbacDbController, AsArbacDbReadableController, AsArbacJsonValueHelpController, AsArbacValueHelpController, type ConjoinArbacDbScopesOptions, type ControlGate, type ControlsOf, type MetaVisibility, MoostArbac, type NavRelationKey, type NavTarget, type OwnFieldKey, type ProjectionOf, type RefForeignKey, type RefTableSource, type ScopeVisibilityOptions, type TArbacCompiledRule, type TArbacEvalResult, TArbacMeta, type TArbacRole, type TArbacRoleForResource, type TArbacRule, type VisibilityTableSource, applyAllowedFieldsAndSet, applyArbacControls, applyArbacMetaOverlay, applyArbacProjection, applyArbacRelationScopes, arbacActionRowScope, arbacAllowedActions, arbacAuthorizeInterceptor, arbacPatternToRegex, arbacRelationFilter, arbacRowFilter, authorizeArbacForm, buildScopeVisibility, cachedRequestScopes, checkArbacWrite, collectMethodNames, collectWithGrantNames, collectWritableFields, conjoinArbacDbScopes, conjoinScopeFilters, enforceControlsPolicy, extractUsedControlValues, getArbacMate, getArbacScopes, guardArbacRemove, guardArbacWrite, isMetaFieldVisible, isScopedFieldVisible, metaAlwaysVisibleFields, prepareArbacRequest, pruneMetaByVisibility, registerArbacDbTarget, requestFieldVisible, requireRequestScopes, resolveHandlerArbacIds, resolveRequestScopes, unionScopeProjection, useArbac, useArbacDbScope };
|
|
935
|
+
export { ARBAC_DELEGATED_AUTH, type AoothArbacClaims, Arbac, ArbacDbScope, type ArbacDbScopeHelpers, ArbacDelegatedAuth, type ArbacGuardedTable, type ArbacRelationResolution, type ArbacScopedTable, ArbacUserProvider, ArbacUserProviderToken, type ArbacWriteTable, AsArbacDbController, type ConjoinArbacDbScopesOptions, type ControlGate, type ControlsOf, type MetaVisibility, type NavRelationKey, type NavTarget, type OwnFieldKey, type ProjectionOf, type RefForeignKey, type RefTableSource, type ScopeVisibilityOptions, type TArbacCompiledRule, type TArbacEvalResult, TArbacMeta, type TArbacRole, type TArbacRoleForResource, type TArbacRule, type VisibilityTableSource, applyAllowedFieldsAndSet, arbacPatternToRegex, conjoinArbacDbScopes, conjoinScopeFilters, enforceControlsPolicy, extractUsedControlValues, getArbacMate };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as __decorate, n as ArbacUserProvider, r as ArbacUserProviderToken, t as __decorateMetadata } from "./decorateMetadata-
|
|
1
|
+
import { i as __decorate, n as ArbacUserProvider, r as ArbacUserProviderToken, t as __decorateMetadata } from "./decorateMetadata-BqEexuhv.mjs";
|
|
2
2
|
import { Arbac, Arbac as Arbac$1, arbacPatternToRegex } from "@aooth/arbac-core";
|
|
3
3
|
import { DB_SCOPE_KEYS, DENY_FILTER, ScopeFieldConfigError, applyScopeFieldFilters, conjoinScopeFilters, conjoinScopeFilters as conjoinScopeFilters$1, conjoinScopes, effectiveScope, expandExcludeToLeaves, getProjectionMode, intersectEnabled, isFieldAllowed, needsInheritedConjunction, normalizeScopes, restrictProjection, stableKey, unionOutcomes } from "@aooth/arbac";
|
|
4
4
|
import { Authenticate, HttpError } from "@moostjs/event-http";
|
|
@@ -7,7 +7,7 @@ import { Inherit, Injectable, TInterceptorPriority, defineBeforeInterceptor, get
|
|
|
7
7
|
import { computeInsights, containsRelationFilter, findAncestorInSet, getPath, hasRelationOp, isPlainObject, isRelationOp, translateQueryTree } from "@atscript/db";
|
|
8
8
|
import { AsDbController, AsDbReadableController, AsJsonValueHelpController, AsValueHelpController, DB_CRUD_HANDLERS, VALUE_HELP_CRUD_HANDLERS, badRequest, discoverRowLevelActions, getControllerFormType, getDbEndpoint, hasActionDelegations, resolveTerminalRef, stableMeta } from "@atscript/moost-db";
|
|
9
9
|
import { groupByFields, walkFilter } from "@uniqu/core";
|
|
10
|
-
|
|
10
|
+
// src/db/helpers.ts
|
|
11
11
|
/** `map.get(key)`, created with `create()` and stored on a miss. */
|
|
12
12
|
function getOrCreate(map, key, create) {
|
|
13
13
|
let value = map.get(key);
|
|
@@ -44,8 +44,7 @@ const navFieldsCache = /* @__PURE__ */ new WeakMap();
|
|
|
44
44
|
function navFieldsOf(table) {
|
|
45
45
|
return table.navFields ?? getOrCreate(navFieldsCache, table, () => new Set(table.relations?.keys()));
|
|
46
46
|
}
|
|
47
|
-
|
|
48
|
-
//#region src/db/visibility.ts
|
|
47
|
+
// src/db/visibility.ts
|
|
49
48
|
/**
|
|
50
49
|
* Union the per-scope `projection` whitelists into the single access-control
|
|
51
50
|
* projection used for FIELD-EXISTENCE decisions (`hasField` parity + `/meta`
|
|
@@ -289,8 +288,7 @@ function isIdentifierSet(source) {
|
|
|
289
288
|
function scopeVisibility(scopes, source = NO_TABLE) {
|
|
290
289
|
return getOrCreate(getOrCreate(scopeVisibilityCache, scopes, () => /* @__PURE__ */ new WeakMap()), source, () => isIdentifierSet(source) ? buildScopeVisibility(scopes, void 0, source) : buildScopeVisibility(scopes, source === NO_TABLE ? void 0 : source));
|
|
291
290
|
}
|
|
292
|
-
|
|
293
|
-
//#region src/db/relation-policy.ts
|
|
291
|
+
// src/db/relation-policy.ts
|
|
294
292
|
/** Registry bucket for controllers without an `app`. */
|
|
295
293
|
const NO_APP = {};
|
|
296
294
|
const registry = /* @__PURE__ */ new WeakMap();
|
|
@@ -504,8 +502,7 @@ function requestRelations(readable) {
|
|
|
504
502
|
const stored = ctx.has(requestRelationsKey) ? ctx.get(requestRelationsKey) : void 0;
|
|
505
503
|
return stored && stored.readable === readable ? stored.relations : void 0;
|
|
506
504
|
}
|
|
507
|
-
|
|
508
|
-
//#region src/db/write-refs.ts
|
|
505
|
+
// src/db/write-refs.ts
|
|
509
506
|
/**
|
|
510
507
|
* The FK a `checkRefs` entry designates: one of its local fields, or the TO
|
|
511
508
|
* relation it backs (`readable.foreignKeyOf`). A name that is neither is a
|
|
@@ -664,8 +661,7 @@ function prefetchRefTargets(scopes, table) {
|
|
|
664
661
|
}
|
|
665
662
|
for (const type of types) evaluateTypeRead(type).catch(() => {});
|
|
666
663
|
}
|
|
667
|
-
|
|
668
|
-
//#region src/attenuation.ts
|
|
664
|
+
// src/attenuation.ts
|
|
669
665
|
/**
|
|
670
666
|
* Conjoin the full-authority scopes (`userScopes`, the ceiling) and the
|
|
671
667
|
* credential's narrowed scopes (`credScopes`) into ONE composite
|
|
@@ -708,8 +704,7 @@ function conjoinArbacDbScopes(userScopes, credScopes, opts) {
|
|
|
708
704
|
fields
|
|
709
705
|
})];
|
|
710
706
|
}
|
|
711
|
-
|
|
712
|
-
//#region src/db/field-children.ts
|
|
707
|
+
// src/db/field-children.ts
|
|
713
708
|
const fieldChildrenCache = /* @__PURE__ */ new WeakMap();
|
|
714
709
|
const NONE = /* @__PURE__ */ new Set();
|
|
715
710
|
/**
|
|
@@ -735,8 +730,7 @@ function fieldChildrenOf(table) {
|
|
|
735
730
|
return (path) => byParent.get(path) ?? [];
|
|
736
731
|
});
|
|
737
732
|
}
|
|
738
|
-
|
|
739
|
-
//#region src/moost-arbac.ts
|
|
733
|
+
// src/moost-arbac.ts
|
|
740
734
|
/** Default number of memoized `/meta` projections per envelope. */
|
|
741
735
|
const DEFAULT_META_MEMO_MAX = 64;
|
|
742
736
|
let MoostArbac = class MoostArbac extends Arbac$1 {
|
|
@@ -830,8 +824,7 @@ let MoostArbac = class MoostArbac extends Arbac$1 {
|
|
|
830
824
|
}
|
|
831
825
|
};
|
|
832
826
|
MoostArbac = __decorate([Injectable()], MoostArbac);
|
|
833
|
-
|
|
834
|
-
//#region src/arbac.evaluate.ts
|
|
827
|
+
// src/arbac.evaluate.ts
|
|
835
828
|
/**
|
|
836
829
|
* The ARBAC resource + action a handler is authorized as. Resource: method
|
|
837
830
|
* `@ArbacResource` → class `@ArbacResource` → controller id → class name.
|
|
@@ -878,6 +871,11 @@ async function loadPrincipal(user) {
|
|
|
878
871
|
};
|
|
879
872
|
}
|
|
880
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
|
+
}
|
|
881
879
|
const principalKey = key("arbac.principal");
|
|
882
880
|
function isHttpEvent(ctx) {
|
|
883
881
|
return ctx.has(eventTypeKey) && ctx.get(eventTypeKey) === "http";
|
|
@@ -980,8 +978,7 @@ function evaluateArbacCached(resource, action, table) {
|
|
|
980
978
|
table: normalized
|
|
981
979
|
}, true);
|
|
982
980
|
}
|
|
983
|
-
|
|
984
|
-
//#region src/arbac.composables.ts
|
|
981
|
+
// src/arbac.composables.ts
|
|
985
982
|
/**
|
|
986
983
|
* Writable slot holding the evaluated scopes for the current event.
|
|
987
984
|
*
|
|
@@ -1042,24 +1039,39 @@ const useArbac = (_ctx) => {
|
|
|
1042
1039
|
};
|
|
1043
1040
|
const evaluateOrThrow = async (opts) => {
|
|
1044
1041
|
const result = await evaluate(opts);
|
|
1045
|
-
if (!result.allowed)
|
|
1042
|
+
if (!result.allowed) {
|
|
1043
|
+
const r = opts?.resource || resource;
|
|
1044
|
+
const a = opts?.action || action;
|
|
1045
|
+
throw new HttpError(403, `Forbidden: ${r}/${a}`);
|
|
1046
|
+
}
|
|
1046
1047
|
return {
|
|
1047
1048
|
...result,
|
|
1048
1049
|
allowed: true
|
|
1049
1050
|
};
|
|
1050
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
|
+
};
|
|
1051
1063
|
return {
|
|
1052
1064
|
getScopes,
|
|
1053
1065
|
setScopes,
|
|
1054
1066
|
evaluate,
|
|
1055
1067
|
evaluateOrThrow,
|
|
1068
|
+
principal,
|
|
1056
1069
|
resource,
|
|
1057
1070
|
action,
|
|
1058
1071
|
isPublic
|
|
1059
1072
|
};
|
|
1060
1073
|
};
|
|
1061
|
-
|
|
1062
|
-
//#region src/arbac.mate.ts
|
|
1074
|
+
// src/arbac.mate.ts
|
|
1063
1075
|
/**
|
|
1064
1076
|
* Returns the shared `Mate` instance typed with ARBAC metadata fields.
|
|
1065
1077
|
*
|
|
@@ -1081,8 +1093,7 @@ function getArbacMate() {
|
|
|
1081
1093
|
* @since 0.1.72
|
|
1082
1094
|
*/
|
|
1083
1095
|
const ARBAC_DELEGATED_AUTH = Symbol.for("aooth.arbac.delegatedAuth");
|
|
1084
|
-
|
|
1085
|
-
//#region src/arbac.decorator.ts
|
|
1096
|
+
// src/arbac.decorator.ts
|
|
1086
1097
|
/**
|
|
1087
1098
|
* ARBAC checks authorization, not authentication, so the transport
|
|
1088
1099
|
* declaration is empty — pair with an upstream auth guard (e.g. JWT
|
|
@@ -1129,8 +1140,7 @@ const ArbacResource = (name) => getArbacMate().decorate("arbacResourceId", name)
|
|
|
1129
1140
|
* at the method level.
|
|
1130
1141
|
*/
|
|
1131
1142
|
const ArbacAction = (name) => getArbacMate().decorate("arbacActionId", name);
|
|
1132
|
-
|
|
1133
|
-
//#region src/db/meta-memo.ts
|
|
1143
|
+
// src/db/meta-memo.ts
|
|
1134
1144
|
/** Deepest relation nesting the decision record follows; deeper → not memoized. */
|
|
1135
1145
|
const MAX_RECORD_DEPTH = 16;
|
|
1136
1146
|
var Unkeyable = class extends Error {};
|
|
@@ -1307,8 +1317,7 @@ function memoMetaProjection(envelope, key, max, compute) {
|
|
|
1307
1317
|
function shareMeta(obj) {
|
|
1308
1318
|
return stableMeta(obj);
|
|
1309
1319
|
}
|
|
1310
|
-
|
|
1311
|
-
//#region src/db/meta-projection.ts
|
|
1320
|
+
// src/db/meta-projection.ts
|
|
1312
1321
|
/**
|
|
1313
1322
|
* Exact-or-ancestor membership in the write whitelist: `credit.credentials.user`
|
|
1314
1323
|
* matches a `credit.credentials` grant. A path through a nav relation is
|
|
@@ -2037,7 +2046,7 @@ function formChildren(runtime, node) {
|
|
|
2037
2046
|
/** Nested-relation walk bound — serialized nav bodies are finite, this only guards pathological input. */
|
|
2038
2047
|
const MAX_NAV_DEPTH = 8;
|
|
2039
2048
|
/** The form walk bound; past it every `ref` / binding is stripped (fail closed). */
|
|
2040
|
-
const MAX_FORM_DEPTH =
|
|
2049
|
+
const MAX_FORM_DEPTH = 16;
|
|
2041
2050
|
function serializedChildren(node) {
|
|
2042
2051
|
const def = node.type;
|
|
2043
2052
|
return [
|
|
@@ -2421,8 +2430,7 @@ function collectMethodNames(instance) {
|
|
|
2421
2430
|
}
|
|
2422
2431
|
return [...names];
|
|
2423
2432
|
}
|
|
2424
|
-
|
|
2425
|
-
//#region src/db/shared-read-helpers.ts
|
|
2433
|
+
// src/db/shared-read-helpers.ts
|
|
2426
2434
|
/**
|
|
2427
2435
|
* Restrict the user-supplied `$select` to the scopes' projection union.
|
|
2428
2436
|
* Returns the original projection untouched when no scope declares a
|
|
@@ -2453,7 +2461,8 @@ function applyArbacProjection(projection, scopes, readable) {
|
|
|
2453
2461
|
function restrictSelect(projection, vis) {
|
|
2454
2462
|
if (Object.keys(vis.allowed).length === 0) return projection;
|
|
2455
2463
|
const childrenOf = fieldChildrenOf(vis.table);
|
|
2456
|
-
|
|
2464
|
+
const result = restrictProjection(normalizeSelect(projection) ?? {}, vis.allowed, childrenOf);
|
|
2465
|
+
return expandExcludeToLeaves(result, childrenOf);
|
|
2457
2466
|
}
|
|
2458
2467
|
/**
|
|
2459
2468
|
* Enforce the union of per-scope `controls` gates against the parsed
|
|
@@ -2539,8 +2548,7 @@ function normalizeSelect(value) {
|
|
|
2539
2548
|
}
|
|
2540
2549
|
if (typeof value === "object") return value;
|
|
2541
2550
|
}
|
|
2542
|
-
|
|
2543
|
-
//#region src/db/request-scopes.ts
|
|
2551
|
+
// src/db/request-scopes.ts
|
|
2544
2552
|
/** Endpoints whose `prepareRequest` carries parsed Uniquery controls. */
|
|
2545
2553
|
const READ_ENDPOINTS = /* @__PURE__ */ new Set([
|
|
2546
2554
|
"query",
|
|
@@ -2829,8 +2837,7 @@ function arbacRelationFilter(path, filter, readable) {
|
|
|
2829
2837
|
if (!level?.scopes) throw badRequest(path, `Unknown field "${path}"`);
|
|
2830
2838
|
return conjoinScopeFilters$1(effectiveScope(level.scopes).filter, filter) ?? filter;
|
|
2831
2839
|
}
|
|
2832
|
-
|
|
2833
|
-
//#region src/db/write-fields.ts
|
|
2840
|
+
// src/db/write-fields.ts
|
|
2834
2841
|
/**
|
|
2835
2842
|
* Test-friendly internal helper — exported for unit tests and helper
|
|
2836
2843
|
* composition; regular consumers should not call this directly.
|
|
@@ -2947,8 +2954,7 @@ function applyPreparedOverlay(data, prepared) {
|
|
|
2947
2954
|
if (prepared.setOverrides) for (const [path, value] of prepared.setOverrides) setPath$1(merged, path, value, prepared.isMergePatch);
|
|
2948
2955
|
return merged;
|
|
2949
2956
|
}
|
|
2950
|
-
|
|
2951
|
-
//#region src/db/write-check.ts
|
|
2957
|
+
// src/db/write-check.ts
|
|
2952
2958
|
/** Thrown by {@link compileScopeCheck} for an operator the evaluator does not model. */
|
|
2953
2959
|
var UnsupportedCheckError = class extends Error {};
|
|
2954
2960
|
/**
|
|
@@ -3071,8 +3077,7 @@ function setPath(target, path, value) {
|
|
|
3071
3077
|
}
|
|
3072
3078
|
node[segs.at(-1)] = value;
|
|
3073
3079
|
}
|
|
3074
|
-
|
|
3075
|
-
//#region src/db/write-policy.ts
|
|
3080
|
+
// src/db/write-policy.ts
|
|
3076
3081
|
const OUT_OF_SCOPE = "Row outside your write scope";
|
|
3077
3082
|
/**
|
|
3078
3083
|
* Nested writes through nav props are denied unless a write scope opts the
|
|
@@ -3185,8 +3190,7 @@ async function guardArbacRemove(ctx, scopes, table) {
|
|
|
3185
3190
|
controls: {}
|
|
3186
3191
|
}) === 0) throw new HttpError(404, "Not found");
|
|
3187
3192
|
}
|
|
3188
|
-
|
|
3189
|
-
//#region src/db/as-arbac-db-controller.ts
|
|
3193
|
+
// src/db/as-arbac-db-controller.ts
|
|
3190
3194
|
let AsArbacDbController = class AsArbacDbController extends AsDbController {
|
|
3191
3195
|
/** Makes this controller the `$with` policy source for its table's ARBAC resource. */
|
|
3192
3196
|
_arbacRelationTarget = registerArbacDbTarget(this);
|
|
@@ -3488,8 +3492,7 @@ function remapUniquUrlSyntaxError(err) {
|
|
|
3488
3492
|
if (!/at (?:pos )?\d+/.test(msg)) return err;
|
|
3489
3493
|
return new HttpError(400, `Invalid query string: ${msg}`);
|
|
3490
3494
|
}
|
|
3491
|
-
|
|
3492
|
-
//#region src/db/as-arbac-db-readable-controller.ts
|
|
3495
|
+
// src/db/as-arbac-db-readable-controller.ts
|
|
3493
3496
|
let AsArbacDbReadableController = class AsArbacDbReadableController extends AsDbReadableController {
|
|
3494
3497
|
/** Makes this controller the `$with` policy source for its table's ARBAC resource. */
|
|
3495
3498
|
_arbacRelationTarget = registerArbacDbTarget(this);
|
|
@@ -3551,8 +3554,7 @@ let AsArbacDbReadableController = class AsArbacDbReadableController extends AsDb
|
|
|
3551
3554
|
}
|
|
3552
3555
|
};
|
|
3553
3556
|
AsArbacDbReadableController = __decorate([Inherit()], AsArbacDbReadableController);
|
|
3554
|
-
|
|
3555
|
-
//#region src/db/as-arbac-value-help-controller.ts
|
|
3557
|
+
// src/db/as-arbac-value-help-controller.ts
|
|
3556
3558
|
function valueHelpHost(boundType, primaryKey, searchableFields) {
|
|
3557
3559
|
const ids = primaryKey ? [primaryKey] : [];
|
|
3558
3560
|
return {
|
|
@@ -3749,8 +3751,7 @@ __decorate([
|
|
|
3749
3751
|
__decorateMetadata("design:returntype", typeof ReturnType === "undefined" ? Object : ReturnType)
|
|
3750
3752
|
], AsArbacJsonValueHelpController.prototype, "runGetOneComposite", null);
|
|
3751
3753
|
AsArbacJsonValueHelpController = __decorate([Inherit()], AsArbacJsonValueHelpController);
|
|
3752
|
-
|
|
3753
|
-
//#region src/db/use-arbac-db-scope.ts
|
|
3754
|
+
// src/db/use-arbac-db-scope.ts
|
|
3754
3755
|
/**
|
|
3755
3756
|
* The current event's merged ARBAC DB scope, for custom routes and
|
|
3756
3757
|
* `@DbAction` handlers that query the table directly. Resolves the event's
|
|
@@ -3812,5 +3813,4 @@ async function useArbacDbScope() {
|
|
|
3812
3813
|
})
|
|
3813
3814
|
};
|
|
3814
3815
|
}
|
|
3815
|
-
//#endregion
|
|
3816
3816
|
export { ARBAC_DELEGATED_AUTH, Arbac, ArbacAction, ArbacAuthorize, ArbacResource, ArbacUserProvider, ArbacUserProviderToken, AsArbacDbController, AsArbacDbReadableController, AsArbacJsonValueHelpController, AsArbacValueHelpController, MoostArbac, applyAllowedFieldsAndSet, applyArbacControls, applyArbacMetaOverlay, applyArbacProjection, applyArbacRelationScopes, arbacActionRowScope, arbacAllowedActions, arbacAuthorizeInterceptor, arbacPatternToRegex, arbacRelationFilter, arbacRowFilter, authorizeArbacForm, buildScopeVisibility, cachedRequestScopes, checkArbacWrite, collectMethodNames, collectWithGrantNames, collectWritableFields, conjoinArbacDbScopes, conjoinScopeFilters, enforceControlsPolicy, extractUsedControlValues, getArbacMate, getArbacScopes, guardArbacRemove, guardArbacWrite, isMetaFieldVisible, isScopedFieldVisible, metaAlwaysVisibleFields, prepareArbacRequest, pruneMetaByVisibility, registerArbacDbTarget, requestFieldVisible, requireRequestScopes, resolveHandlerArbacIds, resolveRequestScopes, unionScopeProjection, useArbac, useArbacDbScope };
|
package/dist/plugin.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { TAtscriptPlugin } from "@atscript/core";
|
|
2
|
-
//#region src/plugin.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* Registers the `@arbac.*` annotation namespace for `@aooth/arbac-moost`:
|
|
5
4
|
*
|
|
@@ -45,6 +44,4 @@ import { TAtscriptPlugin } from "@atscript/core";
|
|
|
45
44
|
* export default { plugins: [arbacPlugin()] }
|
|
46
45
|
* ```
|
|
47
46
|
*/
|
|
48
|
-
|
|
49
|
-
//#endregion
|
|
50
|
-
export { arbacPlugin as default };
|
|
47
|
+
export default function arbacPlugin(): TAtscriptPlugin;
|
package/dist/plugin.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AnnotationSpec } from "@atscript/core";
|
|
2
|
-
|
|
2
|
+
// src/plugin.ts
|
|
3
3
|
/**
|
|
4
4
|
* Registers the `@arbac.*` annotation namespace for `@aooth/arbac-moost`:
|
|
5
5
|
*
|
|
@@ -115,5 +115,4 @@ function arbacPlugin() {
|
|
|
115
115
|
}
|
|
116
116
|
};
|
|
117
117
|
}
|
|
118
|
-
//#endregion
|
|
119
118
|
export { arbacPlugin as default };
|
|
@@ -3,7 +3,6 @@ import { Mate, TClassConstructor, TMateParamMeta, TMoostMetadata } from "moost";
|
|
|
3
3
|
import { FilterExpr, TDbRemoveGuardContext, TDbWriteAction, TDbWriteCheckContext, TDbWriteGuardContext, TMetaResponse, UniqueryControls } from "@atscript/db";
|
|
4
4
|
import { AsDbController, TDbActionScopeContext, TDbControlsType, TDbRequestContext } from "@atscript/moost-db";
|
|
5
5
|
import { NavPropsOf, OwnPropsOf, TAtscriptAnnotatedType, TAtscriptDataType, TSerializedAnnotatedType } from "@atscript/typescript/utils";
|
|
6
|
-
//#region src/arbac.mate.d.ts
|
|
7
6
|
/**
|
|
8
7
|
* ARBAC metadata fields attached to classes and methods by ARBAC decorators.
|
|
9
8
|
*
|
|
@@ -47,8 +46,6 @@ declare const ARBAC_DELEGATED_AUTH: unique symbol;
|
|
|
47
46
|
interface ArbacDelegatedAuth {
|
|
48
47
|
[ARBAC_DELEGATED_AUTH](method: string): boolean;
|
|
49
48
|
}
|
|
50
|
-
//#endregion
|
|
51
|
-
//#region src/db/scope-types.d.ts
|
|
52
49
|
/**
|
|
53
50
|
* Unwrap a `NavPropsOf<T>[K]` value to its target model type:
|
|
54
51
|
* `Comment[]` → `Comment`, `Task` → `Task`. Used to recurse `with.<K>` into
|
|
@@ -99,8 +96,6 @@ type ControlsOf<T> = IsUnknown<T> extends true ? Record<string, ControlGate> : {
|
|
|
99
96
|
$with?: ReadonlyArray<NavRelationKey<T>> | boolean;
|
|
100
97
|
$groupBy?: ReadonlyArray<OwnFieldKey<T>> | boolean;
|
|
101
98
|
} & Partial<Record<BooleanControl, boolean>>;
|
|
102
|
-
//#endregion
|
|
103
|
-
//#region src/db/write-fields.d.ts
|
|
104
99
|
/**
|
|
105
100
|
* Test-friendly internal helper — exported for unit tests and helper
|
|
106
101
|
* composition; regular consumers should not call this directly.
|
|
@@ -123,8 +118,6 @@ type ControlsOf<T> = IsUnknown<T> extends true ? Record<string, ControlGate> : {
|
|
|
123
118
|
* does not carry is skipped (adding the block would clear its other leaves).
|
|
124
119
|
*/
|
|
125
120
|
declare function applyAllowedFieldsAndSet(data: unknown, scopes: ArbacDbScope[], preserveFields?: readonly string[], isMergePatch?: (objectPath: string) => boolean): unknown;
|
|
126
|
-
//#endregion
|
|
127
|
-
//#region src/db/as-arbac-db-controller.d.ts
|
|
128
121
|
type TSelect = UniqueryControls["$select"];
|
|
129
122
|
/**
|
|
130
123
|
* Contract returned by an ARBAC role's scope predicate on a DB-backed resource.
|
|
@@ -442,8 +435,6 @@ declare function enforceControlsPolicy(policy: Record<string, ControlGate>, cont
|
|
|
442
435
|
* gate, which throws if a non-whitelistable control receives a string[]).
|
|
443
436
|
*/
|
|
444
437
|
declare function extractUsedControlValues(key: string, value: unknown, controls?: Record<string, unknown>): string[];
|
|
445
|
-
//#endregion
|
|
446
|
-
//#region src/db/write-refs.d.ts
|
|
447
438
|
/** A `@db.rel.FK` entry as atscript-db's readable exposes it. */
|
|
448
439
|
interface RefForeignKey {
|
|
449
440
|
readonly fields: readonly string[];
|
|
@@ -458,8 +449,6 @@ interface RefTableSource {
|
|
|
458
449
|
/** The FK a TO relation is backed by (atscript-db's `readable.foreignKeyOf`). @since 0.1.72 */
|
|
459
450
|
foreignKeyOf?(relationName: string): RefForeignKey | undefined;
|
|
460
451
|
}
|
|
461
|
-
//#endregion
|
|
462
|
-
//#region src/attenuation.d.ts
|
|
463
452
|
/**
|
|
464
453
|
* The restrict-only ARBAC attenuation carried by a credential — its assumed
|
|
465
454
|
* role SUBSET and narrowing attribute overrides. Sourced into evaluation via
|
|
@@ -535,8 +524,6 @@ interface ConjoinArbacDbScopesOptions {
|
|
|
535
524
|
*/
|
|
536
525
|
fields?: TScopeFieldRules<ArbacDbScope>;
|
|
537
526
|
}
|
|
538
|
-
//#endregion
|
|
539
|
-
//#region src/user.provider.d.ts
|
|
540
527
|
/**
|
|
541
528
|
* Abstract base class for providing user data required for ARBAC evaluations.
|
|
542
529
|
*
|
|
@@ -591,5 +578,4 @@ declare abstract class ArbacUserProvider<TUserAttrs extends object = object> {
|
|
|
591
578
|
* etc. Runtime resolves to the concrete subclass registered via DI.
|
|
592
579
|
*/
|
|
593
580
|
declare const ArbacUserProviderToken: TClassConstructor<ArbacUserProvider>;
|
|
594
|
-
//#endregion
|
|
595
581
|
export { ProjectionOf as _, conjoinArbacDbScopes as a, TArbacMeta as b, ArbacDbScope as c, extractUsedControlValues as d, applyAllowedFieldsAndSet as f, OwnFieldKey as g, NavTarget as h, ConjoinArbacDbScopesOptions as i, AsArbacDbController as l, NavRelationKey as m, ArbacUserProviderToken as n, RefForeignKey as o, ControlsOf as p, AoothArbacClaims as r, RefTableSource as s, ArbacUserProvider as t, enforceControlsPolicy as u, ARBAC_DELEGATED_AUTH as v, getArbacMate as x, ArbacDelegatedAuth as y };
|
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/
|
|
66
|
-
"@aooth/
|
|
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": {
|