@fabrika/auth-core 0.9.0-dev.23 → 0.9.0-dev.26

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabrika/auth-core",
3
- "version": "0.9.0-dev.23",
3
+ "version": "0.9.0-dev.26",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -4,6 +4,7 @@
4
4
  import type {
5
5
  BodyAdmission,
6
6
  Caller,
7
+ ColumnPolicyArtifact,
7
8
  ColumnTestArtifact,
8
9
  ConditionArtifact,
9
10
  ConditionLiteralArtifact,
@@ -160,6 +161,7 @@ function canonicalTable(table: TablePolicyArtifact): TablePolicyArtifact {
160
161
  scope: table.scope.mode === 'child' ? { ...table.scope, inherit: sorted(table.scope.inherit) } : table.scope,
161
162
  insert: sorted(table.insert),
162
163
  update: sorted(table.update),
164
+ columns: mapValues(table.columns, canonicalColumn),
163
165
  ...(table.when === undefined ? {} : { when: mapValues(table.when, canonicalCondition) }),
164
166
  ...(table.relationWhen === undefined
165
167
  ? {}
@@ -170,6 +172,11 @@ function canonicalTable(table: TablePolicyArtifact): TablePolicyArtifact {
170
172
  }
171
173
  }
172
174
 
175
+ /** A column's list of read actions sorted; one action, and a column without its own read, as they are. */
176
+ function canonicalColumn(column: ColumnPolicyArtifact): ColumnPolicyArtifact {
177
+ return column.read === undefined || typeof column.read === 'string' ? column : { ...column, read: sorted(column.read) }
178
+ }
179
+
173
180
  function canonicalConfers(confers: ConfersArtifact): ConfersArtifact {
174
181
  return confers.when === undefined ? confers : { ...confers, when: canonicalCondition(confers.when) }
175
182
  }
package/src/contract.ts CHANGED
@@ -1020,9 +1020,9 @@ export interface ColumnTestArtifact {
1020
1020
  readonly gte?: ConditionLiteralArtifact | { readonly now: true }
1021
1021
  }
1022
1022
 
1023
- /** A column's own read action, its own write action, or both; an absent one is left out. */
1023
+ /** A column's own read actions (one as its text, several as a list), its own write action, or both; an absent one is left out. */
1024
1024
  export interface ColumnPolicyArtifact {
1025
- readonly read?: string
1025
+ readonly read?: TableActionArtifact
1026
1026
  readonly write?: string
1027
1027
  }
1028
1028
 
@@ -29,6 +29,22 @@ export function matchAction(pattern: string, action: string): boolean {
29
29
  return pattern === action
30
30
  }
31
31
 
32
+ /**
33
+ * `entries` with each identical action, scope and source once, the first kept in order: how IAM resolves a principal's
34
+ * permissions, so two roles granting one action at one scope put one entry into the token.
35
+ */
36
+ export function uniquePermissions(entries: readonly PermissionEntry[]): PermissionEntry[] {
37
+ const seen = new Set<string>()
38
+ return entries.filter((entry) => {
39
+ const key = JSON.stringify([entry.action, entry.scope?.type ?? null, entry.scope?.value ?? null, entry.source])
40
+ if (seen.has(key)) {
41
+ return false
42
+ }
43
+ seen.add(key)
44
+ return true
45
+ })
46
+ }
47
+
32
48
  /**
33
49
  * Does `entries` grant `action` at the given scope? Mirrors `can()` semantics exactly:
34
50
  * - scope === undefined → scope-less: ONLY entries with scope === null satisfy (global perms only).
@@ -937,9 +937,9 @@ export interface ColumnTestArtifact {
937
937
  readonly now: true;
938
938
  };
939
939
  }
940
- /** A column's own read action, its own write action, or both; an absent one is left out. */
940
+ /** A column's own read actions (one as its text, several as a list), its own write action, or both; an absent one is left out. */
941
941
  export interface ColumnPolicyArtifact {
942
- readonly read?: string;
942
+ readonly read?: TableActionArtifact;
943
943
  readonly write?: string;
944
944
  }
945
945
  export type TableScope = {
@@ -16,6 +16,11 @@ import type { PermissionEntry, Scope } from './types';
16
16
  * matchAction('project.*', 'projects.read') === false
17
17
  */
18
18
  export declare function matchAction(pattern: string, action: string): boolean;
19
+ /**
20
+ * `entries` with each identical action, scope and source once, the first kept in order: how IAM resolves a principal's
21
+ * permissions, so two roles granting one action at one scope put one entry into the token.
22
+ */
23
+ export declare function uniquePermissions(entries: readonly PermissionEntry[]): PermissionEntry[];
19
24
  /**
20
25
  * Does `entries` grant `action` at the given scope? Mirrors `can()` semantics exactly:
21
26
  * - scope === undefined → scope-less: ONLY entries with scope === null satisfy (global perms only).