@yaks/member 0.0.0-stage → 0.2.36
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/LICENSE +202 -0
- package/README.md +471 -2
- package/_dist/asking.d.ts +4 -0
- package/_dist/asking.d.ts.map +1 -0
- package/_dist/comp.d.ts +14 -0
- package/_dist/comp.d.ts.map +1 -0
- package/_dist/deny.d.ts +19 -0
- package/_dist/deny.d.ts.map +1 -0
- package/_dist/graph.d.ts +4 -0
- package/_dist/graph.d.ts.map +1 -0
- package/_dist/guard.d.ts +45 -0
- package/_dist/guard.d.ts.map +1 -0
- package/_dist/keywords.d.ts +80 -0
- package/_dist/keywords.d.ts.map +1 -0
- package/_dist/mod.d.ts +112 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/owns.d.ts +18 -0
- package/_dist/owns.d.ts.map +1 -0
- package/_dist/pace.d.ts +48 -0
- package/_dist/pace.d.ts.map +1 -0
- package/_dist/personal.d.ts +46 -0
- package/_dist/personal.d.ts.map +1 -0
- package/_dist/plugin.d.ts +32 -0
- package/_dist/plugin.d.ts.map +1 -0
- package/_dist/policy.d.ts +35 -0
- package/_dist/policy.d.ts.map +1 -0
- package/_dist/privacy.d.ts +55 -0
- package/_dist/privacy.d.ts.map +1 -0
- package/_dist/roles.d.ts +20 -0
- package/_dist/roles.d.ts.map +1 -0
- package/_dist/vocab.d.ts +10 -0
- package/_dist/vocab.d.ts.map +1 -0
- package/_dist/words.d.ts +53 -0
- package/_dist/words.d.ts.map +1 -0
- package/asking.js +65 -0
- package/asking.js.map +1 -0
- package/asking.ts +77 -0
- package/comp.js +43 -0
- package/comp.js.map +1 -0
- package/comp.ts +52 -0
- package/deno.json +1 -0
- package/deny.js +31 -0
- package/deny.js.map +1 -0
- package/deny.ts +45 -0
- package/graph.js +6 -0
- package/graph.js.map +1 -0
- package/graph.ts +16 -0
- package/guard.js +265 -0
- package/guard.js.map +1 -0
- package/guard.ts +327 -0
- package/keywords.js +170 -0
- package/keywords.js.map +1 -0
- package/keywords.ts +190 -0
- package/meta/member.vocab.json +70 -0
- package/mod.js +112 -0
- package/mod.js.map +1 -0
- package/mod.ts +113 -0
- package/owns.js +12 -0
- package/owns.js.map +1 -0
- package/owns.ts +23 -0
- package/pace.js +189 -0
- package/pace.js.map +1 -0
- package/pace.ts +195 -0
- package/package.json +33 -4
- package/personal.js +448 -0
- package/personal.js.map +1 -0
- package/personal.ts +550 -0
- package/plugin.js +63 -0
- package/plugin.js.map +1 -0
- package/plugin.ts +62 -0
- package/policy.js +115 -0
- package/policy.js.map +1 -0
- package/policy.ts +176 -0
- package/privacy.js +293 -0
- package/privacy.js.map +1 -0
- package/privacy.ts +379 -0
- package/roles.js +164 -0
- package/roles.js.map +1 -0
- package/roles.ts +245 -0
- package/vocab.js +19 -0
- package/vocab.js.map +1 -0
- package/vocab.json +272 -0
- package/vocab.ts +20 -0
- package/words.js +75 -0
- package/words.js.map +1 -0
- package/words.ts +123 -0
package/asking.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// What a `readers` declaration asks of a reader, for the entity wearing it.
|
|
2
|
+
// A floor asks it of every such entity; an object maps floors to queries, and
|
|
3
|
+
// an entity asks the highest floor whose query its own bundle matches, or
|
|
4
|
+
// nothing when it matches none: `{"editor": ".individual.status!=member"}`.
|
|
5
|
+
import { filter } from '@yaks/match'
|
|
6
|
+
import { parse } from '@yaks/query'
|
|
7
|
+
import type { Clause } from '@yaks/query'
|
|
8
|
+
import type { Bundle } from 'jsr:@yaks/graph@0.2.36'
|
|
9
|
+
import type { Vocab } from 'jsr:@yaks/vocab@0.2.36'
|
|
10
|
+
import { type Floor, floor, FLOORS, isFloor } from './words.js'
|
|
11
|
+
|
|
12
|
+
/** What a component asks of its readers: a floor, or a query for each floor
|
|
13
|
+
* an entity wearing it asks when its bundle matches. */
|
|
14
|
+
export type Asked = Floor | Partial<Record<Floor, string>>
|
|
15
|
+
|
|
16
|
+
/** The floor an entity wearing the component asks, or none. */
|
|
17
|
+
export type Ask = (b: Bundle) => Floor | null
|
|
18
|
+
|
|
19
|
+
let conditional = (v: unknown): v is Record<string, unknown> =>
|
|
20
|
+
!!v && typeof v == 'object' && !Array.isArray(v)
|
|
21
|
+
|
|
22
|
+
/** A declared `readers` as {@link Asked}: a floor this package does not know
|
|
23
|
+
* asks the most. */
|
|
24
|
+
export let askedOf = (said: unknown): Asked =>
|
|
25
|
+
conditional(said)
|
|
26
|
+
? Object.fromEntries(
|
|
27
|
+
Object.entries(said).map(([f, q]) => [floor(f), String(q)]),
|
|
28
|
+
)
|
|
29
|
+
: floor(said)
|
|
30
|
+
|
|
31
|
+
/** The conditions of an {@link Asked}, lowest floor first: `[floor, query]`.
|
|
32
|
+
* A floor alone is one without a query. */
|
|
33
|
+
export let conditions = (asked: Asked): [Floor, string | null][] =>
|
|
34
|
+
typeof asked == 'string'
|
|
35
|
+
? [[asked, null]]
|
|
36
|
+
: FLOORS.flatMap((f) => asked[f] === undefined ? [] : [[f, asked[f]!]])
|
|
37
|
+
|
|
38
|
+
/** The highest floor `asked` can ask of a reader. */
|
|
39
|
+
export let top = (asked: Asked): Floor =>
|
|
40
|
+
conditions(asked).at(-1)?.[0] ?? 'owner'
|
|
41
|
+
|
|
42
|
+
/** What `asked` asks of the entity whose bundle is given, its queries run in
|
|
43
|
+
* memory against it. */
|
|
44
|
+
export let asking = (asked: Asked, vocab: Vocab | undefined): Ask => {
|
|
45
|
+
if (typeof asked == 'string') return () => asked
|
|
46
|
+
if (!vocab) throw new Error('a readers condition is matched against a vocab')
|
|
47
|
+
let tests = conditions(asked).map(([f, q]) => [f, filter(q!, vocab)] as const)
|
|
48
|
+
return (b) => tests.findLast(([, test]) => test(b))?.[0] ?? null
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Whether a clause tests only `name`'s own properties.
|
|
52
|
+
let within = (name: string, c: Clause): boolean =>
|
|
53
|
+
c.kind == 'and' || c.kind == 'or'
|
|
54
|
+
? c.clauses.every((k) => within(name, k))
|
|
55
|
+
: c.kind == 'pred' && c.path[0] == name && !c.where
|
|
56
|
+
|
|
57
|
+
/** The reasons a component's `readers` is no declaration: a key that is not a
|
|
58
|
+
* floor, a query that does not parse, or one that tests anything but the
|
|
59
|
+
* component's own properties (an entity's bundle is all that is matched). */
|
|
60
|
+
export let askedErrors = (name: string, said: unknown): string[] => {
|
|
61
|
+
let is = `${name} is read by`
|
|
62
|
+
let floors = 'readers is person, viewer, editor or owner'
|
|
63
|
+
if (!conditional(said)) {
|
|
64
|
+
return isFloor(said) ? [] : [`${is} "${said}" — ${floors}`]
|
|
65
|
+
}
|
|
66
|
+
return Object.entries(said).flatMap(([f, q]) => {
|
|
67
|
+
if (!isFloor(f)) return [`${is} "${f}" — ${floors}`]
|
|
68
|
+
try {
|
|
69
|
+
if (typeof q == 'string' && within(name, parse(q))) return []
|
|
70
|
+
} catch (e) {
|
|
71
|
+
return [`${is} ${f}s where "${q}" — it does not parse: ${e}`]
|
|
72
|
+
}
|
|
73
|
+
return [
|
|
74
|
+
`${is} ${f}s where "${q}" — it may test only ${name}'s own properties`,
|
|
75
|
+
]
|
|
76
|
+
})
|
|
77
|
+
}
|
package/comp.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// The three components this package defines, as one vocabulary document to
|
|
2
|
+
// load beside your own.
|
|
3
|
+
//
|
|
4
|
+
// member{space, person, role} the roster: who belongs to a space
|
|
5
|
+
// grant{app, person, token, access} the permission: what one principal may
|
|
6
|
+
// do with one app
|
|
7
|
+
// access{mode} what the app allows everyone else
|
|
8
|
+
//
|
|
9
|
+
// Two layers, because they answer different questions. The roster is who you
|
|
10
|
+
// would remove — delete one row and they are gone from everything. A grant is
|
|
11
|
+
// what they may touch while they are here. Keeping them apart means a club can
|
|
12
|
+
// add a member without deciding, in the same breath, what that member may edit.
|
|
13
|
+
//
|
|
14
|
+
// Every reference is deleted with what it points at (`death: cascade`). A
|
|
15
|
+
// roster row about a deleted person is not a fact about anybody; a grant on a
|
|
16
|
+
// deleted app grants nothing. There is no orphan sweep to run because there are
|
|
17
|
+
// no orphans.
|
|
18
|
+
//
|
|
19
|
+
// The document itself is `./vocab.json` — plain JSON Schema, readable by
|
|
20
|
+
// anything that reads JSON. This file re-exports it under the name callers
|
|
21
|
+
// import, and keeps the prose about why it is shaped this way.
|
|
22
|
+
import doc from './vocab.json' with {
|
|
23
|
+
type: 'json'
|
|
24
|
+
};
|
|
25
|
+
/** The name of the component recording one person's place on a space's
|
|
26
|
+
* roster. */ export let MEMBER = 'member';
|
|
27
|
+
/** The name of the component recording one principal's permission on one
|
|
28
|
+
* app. */ export let GRANT = 'grant';
|
|
29
|
+
/** The name of the component carrying an app's access mode. */ export let ACCESS = 'access';
|
|
30
|
+
/** The components this package governs: only an owner may write one. */ export let GOVERNED = [
|
|
31
|
+
MEMBER,
|
|
32
|
+
GRANT,
|
|
33
|
+
ACCESS,
|
|
34
|
+
'app_role',
|
|
35
|
+
'app_ability'
|
|
36
|
+
];
|
|
37
|
+
/**
|
|
38
|
+
* The membership vocabulary, to load beside your own:
|
|
39
|
+
* `loadVocab([memberDoc, ...mine])`. It declares nothing about what a space or
|
|
40
|
+
* an app is — both are plain entities in your own vocabulary — only who belongs
|
|
41
|
+
* to one and who may reach the other.
|
|
42
|
+
*/ export let memberDoc = doc;
|
|
43
|
+
//# sourceMappingURL=comp.js.map
|
package/comp.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comp.js","sources":["./comp.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,wBAAwB;AACxB,EAAE;AACF,0EAA0E;AAC1E,8EAA8E;AAC9E,uDAAuD;AACvD,yEAAyE;AACzE,EAAE;AACF,6EAA6E;AAC7E,8EAA8E;AAC9E,+EAA+E;AAC/E,gFAAgF;AAChF,EAAE;AACF,0EAA0E;AAC1E,8EAA8E;AAC9E,gFAAgF;AAChF,cAAc;AACd,EAAE;AACF,yEAAyE;AACzE,2EAA2E;AAC3E,+DAA+D;AAG/D,OAAO,SAAS,oBAAoB;EAAE,MAAM;AAAO,EAAC;AAEpD;WACW,GACX,OAAO,IAAI,SAAS,SAAQ;AAE5B;QACQ,GACR,OAAO,IAAI,QAAQ,QAAO;AAE1B,6DAA6D,GAC7D,OAAO,IAAI,SAAS,SAAQ;AAE5B,sEAAsE,GACtE,OAAO,IAAI,WAAqB;EAC9B;EACA;EACA;EACA;EACA;CACD,CAAA;AAED;;;;;CAKC,GACD,OAAO,IAAI,YAAsB,IAAG"}
|
package/comp.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// The three components this package defines, as one vocabulary document to
|
|
2
|
+
// load beside your own.
|
|
3
|
+
//
|
|
4
|
+
// member{space, person, role} the roster: who belongs to a space
|
|
5
|
+
// grant{app, person, token, access} the permission: what one principal may
|
|
6
|
+
// do with one app
|
|
7
|
+
// access{mode} what the app allows everyone else
|
|
8
|
+
//
|
|
9
|
+
// Two layers, because they answer different questions. The roster is who you
|
|
10
|
+
// would remove — delete one row and they are gone from everything. A grant is
|
|
11
|
+
// what they may touch while they are here. Keeping them apart means a club can
|
|
12
|
+
// add a member without deciding, in the same breath, what that member may edit.
|
|
13
|
+
//
|
|
14
|
+
// Every reference is deleted with what it points at (`death: cascade`). A
|
|
15
|
+
// roster row about a deleted person is not a fact about anybody; a grant on a
|
|
16
|
+
// deleted app grants nothing. There is no orphan sweep to run because there are
|
|
17
|
+
// no orphans.
|
|
18
|
+
//
|
|
19
|
+
// The document itself is `./vocab.json` — plain JSON Schema, readable by
|
|
20
|
+
// anything that reads JSON. This file re-exports it under the name callers
|
|
21
|
+
// import, and keeps the prose about why it is shaped this way.
|
|
22
|
+
|
|
23
|
+
import type { VocabDoc } from 'jsr:@yaks/vocab@0.2.36'
|
|
24
|
+
import doc from './vocab.json' with { type: 'json' }
|
|
25
|
+
|
|
26
|
+
/** The name of the component recording one person's place on a space's
|
|
27
|
+
* roster. */
|
|
28
|
+
export let MEMBER = 'member'
|
|
29
|
+
|
|
30
|
+
/** The name of the component recording one principal's permission on one
|
|
31
|
+
* app. */
|
|
32
|
+
export let GRANT = 'grant'
|
|
33
|
+
|
|
34
|
+
/** The name of the component carrying an app's access mode. */
|
|
35
|
+
export let ACCESS = 'access'
|
|
36
|
+
|
|
37
|
+
/** The components this package governs: only an owner may write one. */
|
|
38
|
+
export let GOVERNED: string[] = [
|
|
39
|
+
MEMBER,
|
|
40
|
+
GRANT,
|
|
41
|
+
ACCESS,
|
|
42
|
+
'app_role',
|
|
43
|
+
'app_ability',
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The membership vocabulary, to load beside your own:
|
|
48
|
+
* `loadVocab([memberDoc, ...mine])`. It declares nothing about what a space or
|
|
49
|
+
* an app is — both are plain entities in your own vocabulary — only who belongs
|
|
50
|
+
* to one and who may reach the other.
|
|
51
|
+
*/
|
|
52
|
+
export let memberDoc: VocabDoc = doc
|
package/deno.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"publish":{"exclude":["**/*_test.ts","./testing.ts"]},"name":"@yaks/member","version":"0.2.36","license":"Apache-2.0","description":"Access control for a graph: space membership, per-app permission grants, and access modes, with the checks that enforce them on reads and writes.","exports":{".":"./mod.ts","./vocab":"./vocab.ts","./graph":"./graph.ts","./words":"./words.ts"},"imports":{"@yaks/member":"./mod.ts","@yaks/member/vocab":"./vocab.ts","@yaks/member/graph":"./graph.ts","@yaks/member/words":"./words.ts"}}
|
package/deny.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// The denial. It is shaped like every other error a graph throws — an Error
|
|
2
|
+
// with a name, a message, and the facts as fields — so it reaches a client
|
|
3
|
+
// through @yaks/api's `refusal()` intact and a caller reads the facts rather
|
|
4
|
+
// than a translated summary of them.
|
|
5
|
+
//
|
|
6
|
+
// What it reports is deliberately the same to a stranger and to a member who is
|
|
7
|
+
// merely not allowed: which act, which app, and which level would have been
|
|
8
|
+
// enough. What it does not report is whether the app exists, or who else may
|
|
9
|
+
// reach it — a private app is its owner's to disclose. A caller that would
|
|
10
|
+
// rather tell a stranger nothing at all still can: this carries the facts, and
|
|
11
|
+
// what to put in the response is the caller's decision.
|
|
12
|
+
/** An act the principal is not allowed to perform. The HTTP status is 403 when
|
|
13
|
+
* somebody is signed in and 401 when nobody is — which the HTTP layer knows and
|
|
14
|
+
* this error does not, so it carries the facts and leaves that choice there. */ export class Denied extends Error {
|
|
15
|
+
actor;
|
|
16
|
+
app;
|
|
17
|
+
need;
|
|
18
|
+
act;
|
|
19
|
+
comp;
|
|
20
|
+
/**
|
|
21
|
+
* @param actor who was acting, or `null` for an anonymous request
|
|
22
|
+
* @param app the app whose access rules refused it
|
|
23
|
+
* @param need the least that would have been enough: a level, or `person`
|
|
24
|
+
* @param act which of the two rules refused it (default: `write`)
|
|
25
|
+
* @param comp the component whose floor refused it, when one did
|
|
26
|
+
*/ constructor(actor, app, need, act = 'write', comp){
|
|
27
|
+
super(`${actor ?? 'someone signed out'} may not ${act} ` + `${comp ? `${comp} in ` : ''}${app} — ${need == 'person' ? 'only someone signed in may: sign in first' : `${need} is the least that may: a grant of ${need} on the ` + `app, which an owner of the app or of its space gives`}`), this.actor = actor, this.app = app, this.need = need, this.act = act, this.comp = comp;
|
|
28
|
+
this.name = 'Denied';
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=deny.js.map
|
package/deny.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deny.js","sources":["./deny.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,2EAA2E;AAC3E,6EAA6E;AAC7E,qCAAqC;AACrC,EAAE;AACF,gFAAgF;AAChF,4EAA4E;AAC5E,6EAA6E;AAC7E,2EAA2E;AAC3E,+EAA+E;AAC/E,wDAAwD;AAKxD;;8EAE8E,GAC9E,OAAO,MAAM,eAAe;;;;;;EAC1B;;;;;;GAMC,GACD,YACE,AAAO,KAAiB,EACxB,AAAO,GAAQ,EACf,AAAO,IAAW,EAClB,AAAO,MAAwB,OAAO,EACtC,AAAO,IAAa,CACpB;IACA,KAAK,CACH,GAAG,SAAS,qBAAqB,SAAS,EAAE,IAAI,CAAC,CAAC,GAChD,GAAG,OAAO,GAAG,KAAK,IAAI,CAAC,GAAG,KAAK,IAAI,GAAG,EACpC,QAAQ,WACJ,8CACA,GAAG,KAAK,mCAAmC,EAAE,KAAK,QAAQ,CAAC,GAC3D,CAAC,oDAAoD,CAAC,EAC1D,QAbC,QAAA,YACA,MAAA,UACA,OAAA,WACA,MAAA,UACA,OAAA;IAWP,IAAI,CAAC,IAAI,GAAG;EACd;AACF"}
|
package/deny.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// The denial. It is shaped like every other error a graph throws — an Error
|
|
2
|
+
// with a name, a message, and the facts as fields — so it reaches a client
|
|
3
|
+
// through @yaks/api's `refusal()` intact and a caller reads the facts rather
|
|
4
|
+
// than a translated summary of them.
|
|
5
|
+
//
|
|
6
|
+
// What it reports is deliberately the same to a stranger and to a member who is
|
|
7
|
+
// merely not allowed: which act, which app, and which level would have been
|
|
8
|
+
// enough. What it does not report is whether the app exists, or who else may
|
|
9
|
+
// reach it — a private app is its owner's to disclose. A caller that would
|
|
10
|
+
// rather tell a stranger nothing at all still can: this carries the facts, and
|
|
11
|
+
// what to put in the response is the caller's decision.
|
|
12
|
+
|
|
13
|
+
import type { Eid } from 'jsr:@yaks/graph@0.2.36'
|
|
14
|
+
import type { Floor } from './words.ts'
|
|
15
|
+
|
|
16
|
+
/** An act the principal is not allowed to perform. The HTTP status is 403 when
|
|
17
|
+
* somebody is signed in and 401 when nobody is — which the HTTP layer knows and
|
|
18
|
+
* this error does not, so it carries the facts and leaves that choice there. */
|
|
19
|
+
export class Denied extends Error {
|
|
20
|
+
/**
|
|
21
|
+
* @param actor who was acting, or `null` for an anonymous request
|
|
22
|
+
* @param app the app whose access rules refused it
|
|
23
|
+
* @param need the least that would have been enough: a level, or `person`
|
|
24
|
+
* @param act which of the two rules refused it (default: `write`)
|
|
25
|
+
* @param comp the component whose floor refused it, when one did
|
|
26
|
+
*/
|
|
27
|
+
constructor(
|
|
28
|
+
public actor: Eid | null,
|
|
29
|
+
public app: Eid,
|
|
30
|
+
public need: Floor,
|
|
31
|
+
public act: 'read' | 'write' = 'write',
|
|
32
|
+
public comp?: string,
|
|
33
|
+
) {
|
|
34
|
+
super(
|
|
35
|
+
`${actor ?? 'someone signed out'} may not ${act} ` +
|
|
36
|
+
`${comp ? `${comp} in ` : ''}${app} — ${
|
|
37
|
+
need == 'person'
|
|
38
|
+
? 'only someone signed in may: sign in first'
|
|
39
|
+
: `${need} is the least that may: a grant of ${need} on the ` +
|
|
40
|
+
`app, which an owner of the app or of its space gives`
|
|
41
|
+
}`,
|
|
42
|
+
)
|
|
43
|
+
this.name = 'Denied'
|
|
44
|
+
}
|
|
45
|
+
}
|
package/graph.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Composed person-owned policy, independent of the host's app-level guard.
|
|
2
|
+
import { personal } from "./personal.js";
|
|
3
|
+
/** Hosts choose protected components; apps can also declare personal aspects. */ export let plugins = (host, options)=>[
|
|
4
|
+
personal(host.vocab, options.personal, options.through)
|
|
5
|
+
];
|
|
6
|
+
//# sourceMappingURL=graph.js.map
|
package/graph.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph.js","sources":["./graph.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAG3E,SAAwB,QAAQ,wBAAuB;AAEvD,+EAA+E,GAC/E,OAAO,IAAI,UAAU,CACnB,MACA,UACa;IACb,SACE,KAAK,KAAK,EACV,QAAQ,QAAQ,EAChB,QAAQ,OAAO;GAElB,CAAA"}
|
package/graph.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Composed person-owned policy, independent of the host's app-level guard.
|
|
2
|
+
import type { Host, Options } from 'jsr:@yaks/host@0.2.36'
|
|
3
|
+
import type { Plugin } from 'jsr:@yaks/graph@0.2.36'
|
|
4
|
+
import { type Personal, personal } from './personal.js'
|
|
5
|
+
|
|
6
|
+
/** Hosts choose protected components; apps can also declare personal aspects. */
|
|
7
|
+
export let plugins = (
|
|
8
|
+
host: Pick<Host, 'vocab'>,
|
|
9
|
+
options: Options,
|
|
10
|
+
): Plugin[] => [
|
|
11
|
+
personal(
|
|
12
|
+
host.vocab,
|
|
13
|
+
options.personal as Personal | undefined,
|
|
14
|
+
options.through as Personal | undefined,
|
|
15
|
+
),
|
|
16
|
+
]
|
package/guard.js
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
// The write check, as a @yaks/graph hook.
|
|
2
|
+
//
|
|
3
|
+
// It runs at `precondition` — inside the transaction, before a single row has
|
|
4
|
+
// moved — for the same reason the `$was` guard does: a check that reads after
|
|
5
|
+
// the write is checking its own work. Throwing here rolls the whole transaction
|
|
6
|
+
// back, so a batch is admitted entirely or not at all, and there is
|
|
7
|
+
// no half-written state for the caller to reconcile.
|
|
8
|
+
//
|
|
9
|
+
// It asks four questions, in this order:
|
|
10
|
+
//
|
|
11
|
+
// 1. May this principal write this app at all? (`open` mode, or owner/editor)
|
|
12
|
+
// 2. Do the bundles touch a component that asks a floor of its own? The
|
|
13
|
+
// access rows ask owner, always; the vocabulary declares the rest
|
|
14
|
+
// (`floor`, keywords.ts), and so may the program installing the guard
|
|
15
|
+
// (`floors`).
|
|
16
|
+
// 3. Is the principal in only because the app is `open`? Then it adds rows,
|
|
17
|
+
// changes the rows it wrote, answers a stored reference's request with a
|
|
18
|
+
// declared companion mark (`permit`), and puts a row the program keeps
|
|
19
|
+
// `within` its parent only inside a parent of its own.
|
|
20
|
+
// 4. Does a bundle write a component sooner than its `pace` lets this writer
|
|
21
|
+
// (pace.ts)?
|
|
22
|
+
//
|
|
23
|
+
// None of them is a new level. They are the rules that an editor writes the
|
|
24
|
+
// app's data and does not hand out permissions, that a shop's prices are its
|
|
25
|
+
// editors' however open its guest book is, that a chat takes lines only from
|
|
26
|
+
// people signed in, that a visitor signs the guest book without erasing it, and
|
|
27
|
+
// that nobody fills it faster than the rest can read. They matter most on an
|
|
28
|
+
// `open` app, where the first question admits everybody: without them, a
|
|
29
|
+
// visitor invited to sign could rewrite the roster and lock the owner out, set
|
|
30
|
+
// the price of everything to a cent, delete every entry but their own, or push
|
|
31
|
+
// everyone else's out of sight.
|
|
32
|
+
//
|
|
33
|
+
// A row is the principal's own when its `created.by` names them, or when it is
|
|
34
|
+
// them. Without a `created.by`, a row belongs to the `created.via` that made
|
|
35
|
+
// it. A caller with neither identity owns nothing, so it only adds. A bundle
|
|
36
|
+
// that changes nothing — every property it names already holds that value —
|
|
37
|
+
// is nobody's business, which lets the same bytes be uploaded twice.
|
|
38
|
+
//
|
|
39
|
+
// The principal is whatever `$actor` the bundles carry. An HTTP layer replaces
|
|
40
|
+
// that field with the identity it authenticated before calling `apply()`
|
|
41
|
+
// (@yaks/api `signed`). Bundles with no `$actor` act as nobody — allowed on an
|
|
42
|
+
// `open` app, refused everywhere else — which is what an anonymous visitor
|
|
43
|
+
// should get.
|
|
44
|
+
import { after } from "@yaks/fp";
|
|
45
|
+
import { actorOf as writerOf } from "@yaks/graph/provenance";
|
|
46
|
+
import { comps, dead } from "@yaks/graph/bundle";
|
|
47
|
+
import { GOVERNED, GRANT, MEMBER } from "./comp.js";
|
|
48
|
+
import { owns } from "./owns.js";
|
|
49
|
+
import { levelOn, modeOn } from "./policy.js";
|
|
50
|
+
import { Denied } from "./deny.js";
|
|
51
|
+
import { floorsIn, permitsIn } from "./keywords.js";
|
|
52
|
+
import { pacesIn, pacing } from "./pace.js";
|
|
53
|
+
import { edits, stands, writes } from "./words.js";
|
|
54
|
+
/** The principal a signed transaction acts as: every bundle in it was signed by
|
|
55
|
+
* the same HTTP layer, so the first one carrying an `$actor` settles it for all
|
|
56
|
+
* of them. */ export let actorOf = (bundles)=>{
|
|
57
|
+
for (let b of bundles){
|
|
58
|
+
let by = b.$actor?.by;
|
|
59
|
+
if (by) return by;
|
|
60
|
+
}
|
|
61
|
+
return null;
|
|
62
|
+
};
|
|
63
|
+
let OWNED = Object.fromEntries(GOVERNED.map((c)=>[
|
|
64
|
+
c,
|
|
65
|
+
'owner'
|
|
66
|
+
]));
|
|
67
|
+
// Every floor a guard holds: the vocabulary's, the program's over them, and
|
|
68
|
+
// the access rows' over both.
|
|
69
|
+
let held = (where)=>({
|
|
70
|
+
...floorsIn(where.vocab),
|
|
71
|
+
...where.floors,
|
|
72
|
+
...OWNED
|
|
73
|
+
});
|
|
74
|
+
// The first component these bundles touch whose floor this principal, holding
|
|
75
|
+
// this level, does not stand on.
|
|
76
|
+
let short = (floors, who, level, bundles)=>{
|
|
77
|
+
for (let b of bundles){
|
|
78
|
+
for (let [name] of comps(b)){
|
|
79
|
+
let f = floors[name];
|
|
80
|
+
if (f && !stands(who, level, f)) return name;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
// Theirs: the person owns their entity and bylined rows; an unbylined row
|
|
85
|
+
// belongs only to the instrument that made it.
|
|
86
|
+
let mine = (row, who, via, instrument)=>{
|
|
87
|
+
let created = row.created;
|
|
88
|
+
return !!who && row.entity.eid == who || owns({
|
|
89
|
+
by: typeof created?.by == 'string' ? created.by : null,
|
|
90
|
+
via: typeof created?.via == 'string' ? instrument(created.via) : null
|
|
91
|
+
}, {
|
|
92
|
+
by: who,
|
|
93
|
+
via: via ? instrument(via) : null
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
// Nothing this bundle says differs from the row it names.
|
|
97
|
+
let idle = (b, row)=>dead(b) ? dead(row) : comps(b).every(([name, comp])=>{
|
|
98
|
+
let held = row[name];
|
|
99
|
+
if (!comp) return held == null;
|
|
100
|
+
return !!held && Object.entries(comp).every(([prop, v])=>held[prop] == v);
|
|
101
|
+
});
|
|
102
|
+
// The parents the bundles put a kept row in, as their patches or stored rows
|
|
103
|
+
// name them, must be the principal's own; one not stored yet is being made here.
|
|
104
|
+
let inside = (tx, who, app, bundles, via, within, instrument)=>{
|
|
105
|
+
let kept = bundles.filter((b)=>!dead(b) && Object.keys(within).some((c)=>b[c] !== undefined));
|
|
106
|
+
if (!kept.length) return bundles;
|
|
107
|
+
return after(tx.get([
|
|
108
|
+
...new Set(kept.map((b)=>b.entity.eid))
|
|
109
|
+
]), (rows)=>{
|
|
110
|
+
let held = new Map(rows.map((r)=>[
|
|
111
|
+
r.entity.eid,
|
|
112
|
+
r
|
|
113
|
+
]));
|
|
114
|
+
let parents = new Set(kept.flatMap((b)=>Object.entries(within).flatMap(([c, prop])=>{
|
|
115
|
+
if (b[c] === null) return [];
|
|
116
|
+
let ref = b[c]?.[prop] ?? held.get(b.entity.eid)?.[c]?.[prop];
|
|
117
|
+
return typeof ref == 'string' ? [
|
|
118
|
+
ref
|
|
119
|
+
] : [];
|
|
120
|
+
})));
|
|
121
|
+
return after(parents.size ? tx.get([
|
|
122
|
+
...parents
|
|
123
|
+
]) : [], (rows)=>{
|
|
124
|
+
if (rows.some((r)=>!mine(r, who, via, instrument))) {
|
|
125
|
+
throw new Denied(who, app, 'editor');
|
|
126
|
+
}
|
|
127
|
+
return bundles;
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
// A principal the mode admits and no level does: new rows, and its own.
|
|
132
|
+
let adding = (tx, who, app, bundles, via, permits, instrument)=>after(tx.get([
|
|
133
|
+
...new Set(bundles.map((b)=>b.entity.eid))
|
|
134
|
+
]), (rows)=>{
|
|
135
|
+
let held = new Map(rows.map((r)=>[
|
|
136
|
+
r.entity.eid,
|
|
137
|
+
r
|
|
138
|
+
]));
|
|
139
|
+
let foreign = bundles.filter((b)=>{
|
|
140
|
+
let row = held.get(b.entity.eid);
|
|
141
|
+
if (!row || mine(row, who, via, instrument) || idle(b, row)) return false;
|
|
142
|
+
if (dead(b) || dead(row)) throw new Denied(who, app, 'editor');
|
|
143
|
+
return true;
|
|
144
|
+
});
|
|
145
|
+
if (!foreign.length) return bundles;
|
|
146
|
+
// Read referenced owners once, from stored requests rather than incoming
|
|
147
|
+
// patches. Every bundle is still checked, so a second patch cannot rebind
|
|
148
|
+
// or delete a request beside its permitted mark.
|
|
149
|
+
let targets = new Set();
|
|
150
|
+
let refs = (row, mark)=>Object.entries(permits).flatMap(([comp, marks])=>{
|
|
151
|
+
let ref = row[comp]?.[marks[mark]];
|
|
152
|
+
return typeof ref == 'string' ? [
|
|
153
|
+
ref
|
|
154
|
+
] : [];
|
|
155
|
+
});
|
|
156
|
+
for (let b of foreign){
|
|
157
|
+
let row = held.get(b.entity.eid);
|
|
158
|
+
for (let [name] of comps(b)){
|
|
159
|
+
for (let eid of refs(row, name))targets.add(eid);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return after(targets.size ? tx.get([
|
|
163
|
+
...targets
|
|
164
|
+
]) : [], (rows)=>{
|
|
165
|
+
let owners = new Map(rows.map((r)=>[
|
|
166
|
+
r.entity.eid,
|
|
167
|
+
r
|
|
168
|
+
]));
|
|
169
|
+
for (let b of foreign){
|
|
170
|
+
let row = held.get(b.entity.eid);
|
|
171
|
+
let allowed = comps(b).every(([name, patch])=>refs(row, name).some((eid)=>{
|
|
172
|
+
let target = owners.get(eid);
|
|
173
|
+
return !!target && !dead(target) && mine(target, who, via, instrument) && (patch === null || !row[name] || idle({
|
|
174
|
+
entity: b.entity,
|
|
175
|
+
[name]: patch
|
|
176
|
+
}, row));
|
|
177
|
+
}));
|
|
178
|
+
if (!allowed) throw new Denied(who, app, 'editor');
|
|
179
|
+
}
|
|
180
|
+
return bundles;
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
/**
|
|
184
|
+
* Everything the permission check is about to read, declared before it reads
|
|
185
|
+
* any of it: the app (its mode decides for a principal with no level), the
|
|
186
|
+
* principal's own entity (a share link's bearer is a grant), everything filed
|
|
187
|
+
* about the principal — their membership rows, their grants — and the rows the
|
|
188
|
+
* bundles name, whose byline says whose they are. @yaks/graph fetches these in
|
|
189
|
+
* one gather; companion permissions then read the stored reference targets in
|
|
190
|
+
* one additional batch.
|
|
191
|
+
*/ export let wanting = (where)=>(bundles)=>{
|
|
192
|
+
if (!bundles.length) return [];
|
|
193
|
+
let who = actorOf(bundles);
|
|
194
|
+
let level = where.level?.(who, writerOf(bundles));
|
|
195
|
+
let eids = bundles.map((b)=>b.entity.eid);
|
|
196
|
+
if (!writes(level ?? null)) eids.push(where.app);
|
|
197
|
+
if (level !== undefined) return [
|
|
198
|
+
{
|
|
199
|
+
eids
|
|
200
|
+
}
|
|
201
|
+
];
|
|
202
|
+
return who ? [
|
|
203
|
+
{
|
|
204
|
+
eids: [
|
|
205
|
+
...eids,
|
|
206
|
+
who
|
|
207
|
+
]
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
about: [
|
|
211
|
+
who
|
|
212
|
+
],
|
|
213
|
+
comps: [
|
|
214
|
+
GRANT,
|
|
215
|
+
MEMBER
|
|
216
|
+
]
|
|
217
|
+
}
|
|
218
|
+
] : [
|
|
219
|
+
{
|
|
220
|
+
eids
|
|
221
|
+
}
|
|
222
|
+
];
|
|
223
|
+
};
|
|
224
|
+
/**
|
|
225
|
+
* The `precondition` hook: refuse bundles this principal may not write.
|
|
226
|
+
* Registered by {@link https://jsr.io/@yaks/member/doc/~/members | members};
|
|
227
|
+
* exported on its own for a graph that wants the check without this package's
|
|
228
|
+
* components.
|
|
229
|
+
*/ export let guarding = (where)=>{
|
|
230
|
+
let floors = held(where);
|
|
231
|
+
let floored = Object.keys(floors).filter((name)=>where.vocab.comp(name));
|
|
232
|
+
let permits = permitsIn(where.vocab);
|
|
233
|
+
let paces = pacesIn(where.vocab);
|
|
234
|
+
let instrument = where.instrument ?? ((via)=>via);
|
|
235
|
+
let within = where.within ?? {};
|
|
236
|
+
let now = where.now ?? Date.now;
|
|
237
|
+
if (Object.keys(paces).length && !where.vocab.comp('_pace')) {
|
|
238
|
+
throw new Error('stored pacing needs memberDoc in the graph vocabulary');
|
|
239
|
+
}
|
|
240
|
+
return (bundles, tx)=>{
|
|
241
|
+
if (!bundles.length) return bundles;
|
|
242
|
+
let who = actorOf(bundles);
|
|
243
|
+
let vouched = where.level?.(who, writerOf(bundles));
|
|
244
|
+
return after(vouched === undefined ? levelOn(tx, who, where.app, where) : vouched, (level)=>after(writes(level) ? null : modeOn(tx, where.app), (mode)=>{
|
|
245
|
+
if (!writes(level) && !edits(mode, level)) {
|
|
246
|
+
throw new Denied(who, where.app, 'editor');
|
|
247
|
+
}
|
|
248
|
+
let comp = short(floors, who, level, bundles);
|
|
249
|
+
if (comp) {
|
|
250
|
+
throw new Denied(who, where.app, floors[comp], 'write', comp);
|
|
251
|
+
}
|
|
252
|
+
let via = writerOf(bundles).via;
|
|
253
|
+
let deleted = bundles.filter(dead).map((b)=>b.entity.eid);
|
|
254
|
+
let protectedComps = deleted.length ? floored.filter((name)=>!stands(who, level, floors[name])) : [];
|
|
255
|
+
return after(protectedComps.length ? tx.get(deleted, protectedComps) : [], (rows)=>{
|
|
256
|
+
let comp = short(floors, who, level, rows);
|
|
257
|
+
if (comp) {
|
|
258
|
+
throw new Denied(who, where.app, floors[comp], 'write', comp);
|
|
259
|
+
}
|
|
260
|
+
return after(writes(level) ? bundles : after(inside(tx, who, where.app, bundles, via, within, instrument), (b)=>adding(tx, who, where.app, b, via, permits, instrument)), (b)=>pacing(paces, tx, b, now(), where.instrument));
|
|
261
|
+
});
|
|
262
|
+
}));
|
|
263
|
+
};
|
|
264
|
+
};
|
|
265
|
+
//# sourceMappingURL=guard.js.map
|
package/guard.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guard.js","sources":["./guard.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,EAAE;AACF,8EAA8E;AAC9E,8EAA8E;AAC9E,gFAAgF;AAChF,oEAAoE;AACpE,qDAAqD;AACrD,EAAE;AACF,yCAAyC;AACzC,EAAE;AACF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