@fabrika/auth-core 0.9.0-dev.19 → 0.9.0-dev.20
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 +1 -1
- package/src/contract.ts +25 -1
- package/src/requirement.ts +5 -2
- package/types/src/contract.d.ts +21 -1
- package/types/src/requirement.d.ts +2 -2
package/package.json
CHANGED
package/src/contract.ts
CHANGED
|
@@ -264,7 +264,7 @@ export interface BodyAdmission {
|
|
|
264
264
|
* `action` is that action in some scope, global included, and only globally under the `app` form. The access form is
|
|
265
265
|
* what the framework then resolves.
|
|
266
266
|
*/
|
|
267
|
-
export type EndpointRequirement = MemberRequirement | ActionRequirement | CapabilitiesRequirement
|
|
267
|
+
export type EndpointRequirement = MemberRequirement | ActionRequirement | AnyOfRequirement | CapabilitiesRequirement
|
|
268
268
|
|
|
269
269
|
export interface MemberRequirement {
|
|
270
270
|
readonly kind: 'member'
|
|
@@ -276,6 +276,24 @@ export interface ActionRequirement {
|
|
|
276
276
|
readonly access: AccessForm
|
|
277
277
|
}
|
|
278
278
|
|
|
279
|
+
/**
|
|
280
|
+
* Any one of several actions (`access: { anyOf, app: true }`), each held as a global grant, the `app` form's rule: two to
|
|
281
|
+
* `MAX_ANY_OF` distinct actions, sorted, so the order in the source does not change the digest.
|
|
282
|
+
*/
|
|
283
|
+
export interface AnyOfRequirement {
|
|
284
|
+
readonly kind: 'anyOf'
|
|
285
|
+
readonly actions: readonly [string, string, ...string[]]
|
|
286
|
+
readonly access: { readonly form: 'app' }
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/** The most actions an `anyOf` requirement lists. */
|
|
290
|
+
export const MAX_ANY_OF = 16
|
|
291
|
+
|
|
292
|
+
/** Whether `actions` is an `anyOf` list as a row carries it: two to `MAX_ANY_OF` actions, strictly ascending. */
|
|
293
|
+
export function isAnyOfList(actions: readonly string[]): boolean {
|
|
294
|
+
return actions.length >= 2 && actions.length <= MAX_ANY_OF && actions.every((action, index) => index === 0 || (actions[index - 1] ?? '') < action)
|
|
295
|
+
}
|
|
296
|
+
|
|
279
297
|
/**
|
|
280
298
|
* Several capabilities (`access: { capabilities }`), by the name the handler reads each under (`ctx.capabilities.<name>`):
|
|
281
299
|
* the token must carry every action, and the access form of each narrows it as it narrows a single one. At least two.
|
|
@@ -849,6 +867,12 @@ export interface CspSource {
|
|
|
849
867
|
*/
|
|
850
868
|
export type TableActionArtifact = string | readonly string[]
|
|
851
869
|
|
|
870
|
+
/**
|
|
871
|
+
* An application table's `actions.read` that every `app` endpoint, job and webhook reads with, whatever its action; never
|
|
872
|
+
* a public procedure, a scoped site, a link or an export. No vocabulary may declare an action of this name.
|
|
873
|
+
*/
|
|
874
|
+
export const READ_ANY = 'any'
|
|
875
|
+
|
|
852
876
|
export interface TablePolicyArtifact {
|
|
853
877
|
readonly scope: TableScope
|
|
854
878
|
/** An inbox's read action is `read`; it has no write action, because only its form appends. */
|
package/src/requirement.ts
CHANGED
|
@@ -8,8 +8,8 @@ import type { PermissionEntry } from './types'
|
|
|
8
8
|
* Whether a token's permissions meet an endpoint's requirement. This is authorization, not a gate: it reads only the
|
|
9
9
|
* token. `member` is any permission of this application; an action is that action in some scope, global included.
|
|
10
10
|
* The access form narrows it to one scope afterwards, against the application's own data. The `app` form is the
|
|
11
|
-
* action held as a global grant, so an entry scoped to any value does not meet it
|
|
12
|
-
* one of their actions. `authenticated`, which only an installation row carries, needs no permission.
|
|
11
|
+
* action held as a global grant, so an entry scoped to any value does not meet it; `anyOf` is one of its actions held so.
|
|
12
|
+
* Several capabilities need every one of their actions. `authenticated`, which only an installation row carries, needs no permission.
|
|
13
13
|
*/
|
|
14
14
|
export function satisfies(requirement: EndpointRequirement | AuthenticatedRequirement, perms: readonly PermissionEntry[]): boolean {
|
|
15
15
|
if (requirement.kind === 'authenticated') {
|
|
@@ -18,6 +18,9 @@ export function satisfies(requirement: EndpointRequirement | AuthenticatedRequir
|
|
|
18
18
|
if (requirement.kind === 'member') {
|
|
19
19
|
return perms.length > 0
|
|
20
20
|
}
|
|
21
|
+
if (requirement.kind === 'anyOf') {
|
|
22
|
+
return requirement.actions.some((action) => perms.some((entry) => permits([entry], action)))
|
|
23
|
+
}
|
|
21
24
|
if (requirement.kind === 'capabilities') {
|
|
22
25
|
return Object.values(requirement.capabilities).every((capability) => holdsAction(capability, perms))
|
|
23
26
|
}
|
package/types/src/contract.d.ts
CHANGED
|
@@ -239,7 +239,7 @@ export interface BodyAdmission {
|
|
|
239
239
|
* `action` is that action in some scope, global included, and only globally under the `app` form. The access form is
|
|
240
240
|
* what the framework then resolves.
|
|
241
241
|
*/
|
|
242
|
-
export type EndpointRequirement = MemberRequirement | ActionRequirement | CapabilitiesRequirement;
|
|
242
|
+
export type EndpointRequirement = MemberRequirement | ActionRequirement | AnyOfRequirement | CapabilitiesRequirement;
|
|
243
243
|
export interface MemberRequirement {
|
|
244
244
|
readonly kind: 'member';
|
|
245
245
|
}
|
|
@@ -248,6 +248,21 @@ export interface ActionRequirement {
|
|
|
248
248
|
readonly action: string;
|
|
249
249
|
readonly access: AccessForm;
|
|
250
250
|
}
|
|
251
|
+
/**
|
|
252
|
+
* Any one of several actions (`access: { anyOf, app: true }`), each held as a global grant, the `app` form's rule: two to
|
|
253
|
+
* `MAX_ANY_OF` distinct actions, sorted, so the order in the source does not change the digest.
|
|
254
|
+
*/
|
|
255
|
+
export interface AnyOfRequirement {
|
|
256
|
+
readonly kind: 'anyOf';
|
|
257
|
+
readonly actions: readonly [string, string, ...string[]];
|
|
258
|
+
readonly access: {
|
|
259
|
+
readonly form: 'app';
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
/** The most actions an `anyOf` requirement lists. */
|
|
263
|
+
export declare const MAX_ANY_OF = 16;
|
|
264
|
+
/** Whether `actions` is an `anyOf` list as a row carries it: two to `MAX_ANY_OF` actions, strictly ascending. */
|
|
265
|
+
export declare function isAnyOfList(actions: readonly string[]): boolean;
|
|
251
266
|
/**
|
|
252
267
|
* Several capabilities (`access: { capabilities }`), by the name the handler reads each under (`ctx.capabilities.<name>`):
|
|
253
268
|
* the token must carry every action, and the access form of each narrows it as it narrows a single one. At least two.
|
|
@@ -759,6 +774,11 @@ export interface CspSource {
|
|
|
759
774
|
* two. A single action stays text, so the artifact of a policy that names one keeps its shape and digest.
|
|
760
775
|
*/
|
|
761
776
|
export type TableActionArtifact = string | readonly string[];
|
|
777
|
+
/**
|
|
778
|
+
* An application table's `actions.read` that every `app` endpoint, job and webhook reads with, whatever its action; never
|
|
779
|
+
* a public procedure, a scoped site, a link or an export. No vocabulary may declare an action of this name.
|
|
780
|
+
*/
|
|
781
|
+
export declare const READ_ANY = "any";
|
|
762
782
|
export interface TablePolicyArtifact {
|
|
763
783
|
readonly scope: TableScope;
|
|
764
784
|
/** An inbox's read action is `read`; it has no write action, because only its form appends. */
|
|
@@ -6,8 +6,8 @@ import type { PermissionEntry } from './types';
|
|
|
6
6
|
* Whether a token's permissions meet an endpoint's requirement. This is authorization, not a gate: it reads only the
|
|
7
7
|
* token. `member` is any permission of this application; an action is that action in some scope, global included.
|
|
8
8
|
* The access form narrows it to one scope afterwards, against the application's own data. The `app` form is the
|
|
9
|
-
* action held as a global grant, so an entry scoped to any value does not meet it
|
|
10
|
-
* one of their actions. `authenticated`, which only an installation row carries, needs no permission.
|
|
9
|
+
* action held as a global grant, so an entry scoped to any value does not meet it; `anyOf` is one of its actions held so.
|
|
10
|
+
* Several capabilities need every one of their actions. `authenticated`, which only an installation row carries, needs no permission.
|
|
11
11
|
*/
|
|
12
12
|
export declare function satisfies(requirement: EndpointRequirement | AuthenticatedRequirement, perms: readonly PermissionEntry[]): boolean;
|
|
13
13
|
/**
|