@aooth/arbac-moost 0.1.64 → 0.1.66

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.
@@ -1,4 +1,4 @@
1
- import { r as AoothArbacClaims, t as ArbacUserProvider } from "../user.provider-abwC0SjM.mjs";
1
+ import { r as AoothArbacClaims, t as ArbacUserProvider } from "../user.provider-B1f6ZI45.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
4
  //#region src/atscript/auto-provider.d.ts
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as ArbacDbScope, c as enforceControlsPolicy, d as NavRelationKey, f as NavTarget, i as conjoinArbacDbScopes, l as extractUsedControlValues, m as ProjectionOf, n as ArbacUserProviderToken, o as AsArbacDbController, p as OwnFieldKey, r as AoothArbacClaims, s as applyAllowedFieldsAndSet, t as ArbacUserProvider, u as ControlsOf } from "./user.provider-abwC0SjM.mjs";
1
+ import { a as ArbacDbScope, c as enforceControlsPolicy, d as NavRelationKey, f as NavTarget, i as conjoinArbacDbScopes, l as extractUsedControlValues, m as ProjectionOf, n as ArbacUserProviderToken, o as AsArbacDbController, p as OwnFieldKey, r as AoothArbacClaims, s as applyAllowedFieldsAndSet, t as ArbacUserProvider, u as ControlsOf } from "./user.provider-B1f6ZI45.mjs";
2
2
  import { Arbac, Arbac as Arbac$1, TArbacCompiledRule, TArbacEvalResult, TArbacRole, TArbacRoleForResource, TArbacRule, arbacPatternToRegex } from "@aooth/arbac-core";
3
3
  import { TAuthGuardDef } from "@moostjs/event-http";
4
4
  import { EventContext } from "@wooksjs/event-core";
package/dist/index.mjs CHANGED
@@ -5,6 +5,7 @@ import { current, key } from "@wooksjs/event-core";
5
5
  import { Inherit, Injectable, TInterceptorPriority, defineBeforeInterceptor, getConstructor, getMoostMate, useControllerContext, useLogger } from "moost";
6
6
  import { conjoinScopeFilters, intersectControlsPolicy, isFieldAllowed, mergeScopeFilters, restrictProjection, unionControlsPolicy, unionProjections } from "@aooth/arbac";
7
7
  import { AsDbController, AsDbReadableController } from "@atscript/moost-db";
8
+ import { groupByFields } from "@uniqu/core";
8
9
  //#region src/attenuation.ts
9
10
  /**
10
11
  * Conjoin the full-authority scopes (`userScopes`, the ceiling) and the
@@ -808,7 +809,7 @@ function enforceControlsPolicy(policy, controls) {
808
809
  if (Array.isArray(used) && used.length === 0) continue;
809
810
  if (gate === false) throw new HttpError(403, `Control "${key}" is not allowed for your role`);
810
811
  if (Array.isArray(gate)) {
811
- const usedValues = extractUsedControlValues(key, used);
812
+ const usedValues = extractUsedControlValues(key, used, controls);
812
813
  for (const v of usedValues) if (!gate.includes(v)) throw new HttpError(403, `Control "${key}=${v}" is not allowed for your role`);
813
814
  }
814
815
  }
@@ -824,13 +825,16 @@ function enforceControlsPolicy(policy, controls) {
824
825
  * - `$with` — array of `{ name, … }` objects (per `TypedWithRelation`,
825
826
  * see `@uniqu/core` parser at `parseWithSegment`); we extract `name`.
826
827
  * Bare strings are tolerated for forward compatibility.
827
- * - `$groupBy` — array of column names (strings). Returned as-is.
828
+ * - `$groupBy` — array of column names (strings). With `controls` given,
829
+ * a calendar-bucket alias (`$select: [{ $bucket, $field, $as }]`) is
830
+ * mapped to its source `$field` (`groupByFields` from `@uniqu/core`),
831
+ * so the whitelist is checked against the column actually grouped on.
828
832
  *
829
833
  * For unknown controls we return an empty array; the caller then enforces
830
834
  * `false`-only semantics (controlled by `unionControlsPolicy`'s whitelist
831
835
  * gate, which throws if a non-whitelistable control receives a string[]).
832
836
  */
833
- function extractUsedControlValues(key, value) {
837
+ function extractUsedControlValues(key, value, controls) {
834
838
  if (!Array.isArray(value)) return [];
835
839
  if (key === "$with") {
836
840
  const out = [];
@@ -838,7 +842,10 @@ function extractUsedControlValues(key, value) {
838
842
  else if (typeof entry?.name === "string") out.push(entry.name);
839
843
  return out;
840
844
  }
841
- if (key === "$groupBy") return value.filter((x) => typeof x === "string");
845
+ if (key === "$groupBy") return controls ? groupByFields({
846
+ $select: controls.$select,
847
+ $groupBy: value
848
+ }) : value.filter((x) => typeof x === "string");
842
849
  return [];
843
850
  }
844
851
  /**
@@ -212,13 +212,16 @@ declare function enforceControlsPolicy(policy: Record<string, ControlGate>, cont
212
212
  * - `$with` — array of `{ name, … }` objects (per `TypedWithRelation`,
213
213
  * see `@uniqu/core` parser at `parseWithSegment`); we extract `name`.
214
214
  * Bare strings are tolerated for forward compatibility.
215
- * - `$groupBy` — array of column names (strings). Returned as-is.
215
+ * - `$groupBy` — array of column names (strings). With `controls` given,
216
+ * a calendar-bucket alias (`$select: [{ $bucket, $field, $as }]`) is
217
+ * mapped to its source `$field` (`groupByFields` from `@uniqu/core`),
218
+ * so the whitelist is checked against the column actually grouped on.
216
219
  *
217
220
  * For unknown controls we return an empty array; the caller then enforces
218
221
  * `false`-only semantics (controlled by `unionControlsPolicy`'s whitelist
219
222
  * gate, which throws if a non-whitelistable control receives a string[]).
220
223
  */
221
- declare function extractUsedControlValues(key: string, value: unknown): string[];
224
+ declare function extractUsedControlValues(key: string, value: unknown, controls?: Record<string, unknown>): string[];
222
225
  /**
223
226
  * Test-friendly internal helper — exported for unit tests and helper
224
227
  * composition; regular consumers should not call this directly.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aooth/arbac-moost",
3
- "version": "0.1.64",
3
+ "version": "0.1.66",
4
4
  "description": "Moost RBAC integration for aoothjs (migrated from @moostjs/arbac)",
5
5
  "keywords": [
6
6
  "abac",
@@ -60,26 +60,26 @@
60
60
  "access": "public"
61
61
  },
62
62
  "dependencies": {
63
- "@aooth/arbac": "0.1.64",
64
- "@aooth/user": "0.1.64",
65
- "@aooth/arbac-core": "0.1.64"
63
+ "@uniqu/core": "^0.1.9",
64
+ "@aooth/arbac": "0.1.66",
65
+ "@aooth/user": "0.1.66",
66
+ "@aooth/arbac-core": "0.1.66"
66
67
  },
67
68
  "devDependencies": {
68
69
  "@atscript/core": "^0.1.93",
69
- "@atscript/db": "^0.1.130",
70
- "@atscript/db-sql-tools": "^0.1.130",
71
- "@atscript/db-sqlite": "^0.1.130",
72
- "@atscript/moost-db": "^0.1.130",
70
+ "@atscript/db": "^0.1.132",
71
+ "@atscript/db-sql-tools": "^0.1.132",
72
+ "@atscript/db-sqlite": "^0.1.132",
73
+ "@atscript/moost-db": "^0.1.132",
73
74
  "@atscript/typescript": "^0.1.93",
74
75
  "@moostjs/event-http": "^0.6.37",
75
76
  "@types/better-sqlite3": "^7.6.13",
76
- "@uniqu/core": "^0.1.8",
77
77
  "better-sqlite3": "^12.6.2",
78
78
  "unplugin-atscript": "^0.1.93"
79
79
  },
80
80
  "peerDependencies": {
81
- "@atscript/db": "^0.1.130",
82
- "@atscript/moost-db": "^0.1.130",
81
+ "@atscript/db": "^0.1.132",
82
+ "@atscript/moost-db": "^0.1.132",
83
83
  "@atscript/typescript": "^0.1.93",
84
84
  "@moostjs/event-http": "^0.6.37",
85
85
  "@wooksjs/event-core": "^0.7.23",