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

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.26",
3
+ "version": "0.9.0-dev.27",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,3 +1,4 @@
1
+ import type { KeyGrant } from './rpc'
1
2
  import type { PermissionEntry, Scope } from './types'
2
3
 
3
4
  /**
@@ -122,3 +123,28 @@ export function isActionAllowed(pattern: string, catalog: readonly string[]): bo
122
123
  }
123
124
  return false
124
125
  }
126
+
127
+ /**
128
+ * Intersect live permissions with a ceiling: an OAuth scope's grants, or a terminal's patterns for an application. The
129
+ * ceiling never adds anything: each result is the narrower action and the narrower scope of one held entry and one
130
+ * ceiling entry that overlap, so a held `*` under a ceiling `a.read` yields `a.read`.
131
+ */
132
+ export function narrowPermissions(live: readonly PermissionEntry[], ceiling: readonly KeyGrant[]): PermissionEntry[] {
133
+ const result: PermissionEntry[] = []
134
+ for (const held of live) {
135
+ for (const limit of ceiling) {
136
+ const action = matchAction(limit.action, held.action) ? held.action : matchAction(held.action, limit.action) ? limit.action : null
137
+ const scope = narrowerScope(held.scope, limit.scope ?? null)
138
+ if (action === null || scope === undefined) continue
139
+ result.push({ action, scope, source: held.source })
140
+ }
141
+ }
142
+ return uniquePermissions(result)
143
+ }
144
+
145
+ /** `null` is global; `undefined` means the two scopes do not overlap. */
146
+ function narrowerScope(held: Scope | null, limit: Scope | null): Scope | null | undefined {
147
+ if (held === null) return limit
148
+ if (limit === null) return held
149
+ return held.type === limit.type && held.value === limit.value ? held : undefined
150
+ }
@@ -1,3 +1,4 @@
1
+ import type { KeyGrant } from './rpc';
1
2
  import type { PermissionEntry, Scope } from './types';
2
3
  /**
3
4
  * Wildcard action matching. The pattern is one of:
@@ -53,3 +54,9 @@ export declare function scopedValues(entries: PermissionEntry[], action: string,
53
54
  * - otherwise → invalid.
54
55
  */
55
56
  export declare function isActionAllowed(pattern: string, catalog: readonly string[]): boolean;
57
+ /**
58
+ * Intersect live permissions with a ceiling: an OAuth scope's grants, or a terminal's patterns for an application. The
59
+ * ceiling never adds anything: each result is the narrower action and the narrower scope of one held entry and one
60
+ * ceiling entry that overlap, so a held `*` under a ceiling `a.read` yields `a.read`.
61
+ */
62
+ export declare function narrowPermissions(live: readonly PermissionEntry[], ceiling: readonly KeyGrant[]): PermissionEntry[];