@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/roles.ts
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
// App role definitions are read from the same store as the rows they select.
|
|
2
|
+
import { after } from '@yaks/fp'
|
|
3
|
+
import {
|
|
4
|
+
type Actor,
|
|
5
|
+
type Bundle,
|
|
6
|
+
type Comp,
|
|
7
|
+
dead,
|
|
8
|
+
deathPlan,
|
|
9
|
+
type Hook,
|
|
10
|
+
type Plugin,
|
|
11
|
+
type ReadTx,
|
|
12
|
+
type Tx,
|
|
13
|
+
withPerson,
|
|
14
|
+
} from '@yaks/graph'
|
|
15
|
+
import { actorOf } from '@yaks/graph/provenance'
|
|
16
|
+
import {
|
|
17
|
+
absent,
|
|
18
|
+
and,
|
|
19
|
+
bare,
|
|
20
|
+
kinded,
|
|
21
|
+
map,
|
|
22
|
+
or,
|
|
23
|
+
parse,
|
|
24
|
+
type Query,
|
|
25
|
+
} from '@yaks/query'
|
|
26
|
+
import type { Vocab } from 'jsr:@yaks/vocab@0.2.36'
|
|
27
|
+
import { Denied } from './deny.js'
|
|
28
|
+
import { modeOn } from './policy.js'
|
|
29
|
+
import { type Level, LEVELS, writes } from './words.js'
|
|
30
|
+
|
|
31
|
+
/** The rows shared by a published app and its installed copies. */
|
|
32
|
+
export let ROLE_DEFINITIONS = ['app_role', 'app_ability']
|
|
33
|
+
|
|
34
|
+
export let builtIn = (name: string): name is Level =>
|
|
35
|
+
LEVELS.includes(name as Level)
|
|
36
|
+
|
|
37
|
+
export let roleRows = (
|
|
38
|
+
tx: Pick<ReadTx, 'read'>,
|
|
39
|
+
): Bundle[] | Promise<Bundle[]> =>
|
|
40
|
+
tx.read('.app_role|.app_ability', {}, ROLE_DEFINITIONS.concat('doc'))
|
|
41
|
+
|
|
42
|
+
/** The highest level among the roles the app recognizes. */
|
|
43
|
+
export let roleLevel = (
|
|
44
|
+
names: readonly string[],
|
|
45
|
+
rows: Bundle[] = [],
|
|
46
|
+
): Level | null => {
|
|
47
|
+
let levels = new Set(names.filter(builtIn))
|
|
48
|
+
for (let row of rows) {
|
|
49
|
+
let role = row.app_role as Comp | undefined
|
|
50
|
+
if (
|
|
51
|
+
role && names.includes(String(role.name)) && !builtIn(String(role.name))
|
|
52
|
+
) {
|
|
53
|
+
let level = role.level
|
|
54
|
+
if (level === 'editor' || level === 'viewer') levels.add(level)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return LEVELS.findLast((level) => levels.has(level)) ?? null
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** An ability selects entities using the same predicates as a graph query. */
|
|
61
|
+
export let abilityQuery = (vocab: Vocab, query: string): Query => {
|
|
62
|
+
let ast = kinded(vocab, parse(query)) as Query
|
|
63
|
+
map(ast, (clause) => {
|
|
64
|
+
if (clause.kind == 'pred') {
|
|
65
|
+
vocab.aim(clause.path.join('.'), bare(clause))
|
|
66
|
+
} else if (!['and', 'or', 'refs', 'walk'].includes(clause.kind)) {
|
|
67
|
+
throw new Error(
|
|
68
|
+
'An ability query must select entities without shaping the answer',
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
return clause
|
|
72
|
+
})
|
|
73
|
+
return ast
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
let none = and(absent('entity.eid'))
|
|
77
|
+
let fits = (
|
|
78
|
+
vocab: Vocab,
|
|
79
|
+
person: string,
|
|
80
|
+
names: readonly string[],
|
|
81
|
+
rows: Bundle[],
|
|
82
|
+
act: 'read' | 'write',
|
|
83
|
+
): Query | undefined => {
|
|
84
|
+
if (names.some((name) => builtIn(name) && (act == 'read' || writes(name)))) {
|
|
85
|
+
return undefined
|
|
86
|
+
}
|
|
87
|
+
let held = new Set(
|
|
88
|
+
rows.filter((row) => {
|
|
89
|
+
let role = row.app_role as Comp | undefined
|
|
90
|
+
return role && !builtIn(String(role.name)) &&
|
|
91
|
+
names.includes(String(role.name)) &&
|
|
92
|
+
(role.level == 'editor' || act == 'read' && role.level == 'viewer')
|
|
93
|
+
}).map((row) => row.entity.eid),
|
|
94
|
+
)
|
|
95
|
+
let arms: Query[] = []
|
|
96
|
+
for (let row of rows) {
|
|
97
|
+
let ability = row.app_ability as Comp | undefined
|
|
98
|
+
if (!ability || ability.act != act || !held.has(String(ability.role))) {
|
|
99
|
+
continue
|
|
100
|
+
}
|
|
101
|
+
let query = ability.query
|
|
102
|
+
if (query == null || query === '') return undefined
|
|
103
|
+
if (typeof query != 'string') continue
|
|
104
|
+
try {
|
|
105
|
+
arms.push(withPerson(vocab, abilityQuery(vocab, query), person))
|
|
106
|
+
} catch {
|
|
107
|
+
// A release can retire a component a stored ability used to select.
|
|
108
|
+
// That ability then selects nothing until the app's policy is updated.
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return arms.length ? and(or(...arms)) : none
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
type Holder = { person: string; roles: readonly string[] }
|
|
115
|
+
type AppRoles = {
|
|
116
|
+
app: string
|
|
117
|
+
vocab: Vocab
|
|
118
|
+
holder: (actor: Actor) => Holder | undefined
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
let denied = (holder: Holder, app: string) =>
|
|
122
|
+
new Denied(holder.person, app, 'editor', 'write')
|
|
123
|
+
|
|
124
|
+
let permits = (
|
|
125
|
+
tx: ReadTx,
|
|
126
|
+
ids: string[],
|
|
127
|
+
query: Query,
|
|
128
|
+
refuse: () => Error,
|
|
129
|
+
) => {
|
|
130
|
+
if (!ids.length) return undefined
|
|
131
|
+
return after(
|
|
132
|
+
tx.read(query, { eids: ids, unordered: true }, ['entity']),
|
|
133
|
+
(rows) => {
|
|
134
|
+
if (rows.length != ids.length) throw refuse()
|
|
135
|
+
},
|
|
136
|
+
)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Scope private reads and check writes in both transaction states. */
|
|
140
|
+
export let appRoles = ({ app, vocab, holder }: AppRoles): Plugin => {
|
|
141
|
+
let checking = (tx: Tx, found: Holder, bundles: Bundle[], before: boolean) =>
|
|
142
|
+
after(roleRows(tx), (definitions) => {
|
|
143
|
+
let query = fits(vocab, found.person, found.roles, definitions, 'write')
|
|
144
|
+
if (!query) return bundles
|
|
145
|
+
let ids = [
|
|
146
|
+
...new Set(
|
|
147
|
+
bundles.filter((b) => b.entity.eid).map((b) => b.entity.eid),
|
|
148
|
+
),
|
|
149
|
+
]
|
|
150
|
+
let refuse = () => denied(found, app)
|
|
151
|
+
if (!before) {
|
|
152
|
+
let removed = new Set(bundles.filter(dead).map((b) => b.entity.eid))
|
|
153
|
+
return after(
|
|
154
|
+
permits(tx, ids.filter((eid) => !removed.has(eid)), query, refuse),
|
|
155
|
+
() => bundles,
|
|
156
|
+
)
|
|
157
|
+
}
|
|
158
|
+
return after(
|
|
159
|
+
tx.get(ids, ['entity']),
|
|
160
|
+
(rows) =>
|
|
161
|
+
after(
|
|
162
|
+
permits(
|
|
163
|
+
tx,
|
|
164
|
+
rows.filter((b) => !dead(b)).map((b) => b.entity.eid),
|
|
165
|
+
query,
|
|
166
|
+
refuse,
|
|
167
|
+
),
|
|
168
|
+
() => bundles,
|
|
169
|
+
),
|
|
170
|
+
)
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
let held = (bundles: Bundle[]) => {
|
|
174
|
+
let found = holder(actorOf(bundles) ?? {})
|
|
175
|
+
return found?.roles.some((role) => !builtIn(role)) &&
|
|
176
|
+
!found.roles.some((role) => role == 'owner' || role == 'editor')
|
|
177
|
+
? found
|
|
178
|
+
: undefined
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
let authorize: Hook = (bundles, tx, _error, context) => {
|
|
182
|
+
let found = context?.trusted ? undefined : held(bundles)
|
|
183
|
+
return found ? checking(tx, found, bundles, true) : bundles
|
|
184
|
+
}
|
|
185
|
+
let scope: NonNullable<Plugin['scope']> = ({ tx, opts }) => {
|
|
186
|
+
if (!opts.person || !opts.roles?.some((name) => !builtIn(name))) return
|
|
187
|
+
let mode = modeOn(tx, app)
|
|
188
|
+
if (mode == 'public' || mode == 'open') return
|
|
189
|
+
let rows = roleRows(tx)
|
|
190
|
+
return {
|
|
191
|
+
entity: Array.isArray(rows)
|
|
192
|
+
? fits(vocab, opts.person, opts.roles, rows, 'read')
|
|
193
|
+
: none,
|
|
194
|
+
dependencies: ROLE_DEFINITIONS,
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return {
|
|
198
|
+
name: '@yaks/member/roles',
|
|
199
|
+
scope,
|
|
200
|
+
reads: (opts) => !!opts.roles?.some((name) => !builtIn(name)),
|
|
201
|
+
answer: ({ tx, opts, screened }, rows) => {
|
|
202
|
+
if (screened || !rows.length) return rows
|
|
203
|
+
let visibility = scope({ tx, opts })
|
|
204
|
+
if (!visibility?.entity) return rows
|
|
205
|
+
return after(
|
|
206
|
+
tx.get(rows.map((b) => b.entity.eid), ['entity'], {
|
|
207
|
+
visibility,
|
|
208
|
+
graves: true,
|
|
209
|
+
}),
|
|
210
|
+
(found) => {
|
|
211
|
+
let seen = new Set(found.map((b) => b.entity.eid))
|
|
212
|
+
return rows.filter((b) => seen.has(b.entity.eid))
|
|
213
|
+
},
|
|
214
|
+
)
|
|
215
|
+
},
|
|
216
|
+
authorize,
|
|
217
|
+
hooks: {
|
|
218
|
+
rules: (rows, tx, _error, context) => {
|
|
219
|
+
let found = context?.trusted
|
|
220
|
+
? undefined
|
|
221
|
+
: held(context?.bundles ?? rows)
|
|
222
|
+
if (!found) return rows
|
|
223
|
+
let killed = rows.filter(dead).map((b) => b.entity.eid)
|
|
224
|
+
return after(
|
|
225
|
+
killed.length ? deathPlan(tx, vocab, killed) : undefined,
|
|
226
|
+
(plan) =>
|
|
227
|
+
after(
|
|
228
|
+
checking(tx, found, [
|
|
229
|
+
...rows,
|
|
230
|
+
...plan?.gone.map(({ eid }) => ({ entity: { eid } })) ?? [],
|
|
231
|
+
...plan?.loose.map(({ eid }) => ({ entity: { eid } })) ?? [],
|
|
232
|
+
], true),
|
|
233
|
+
() => rows,
|
|
234
|
+
),
|
|
235
|
+
)
|
|
236
|
+
},
|
|
237
|
+
cascade: (bundles, tx, _error, context) => {
|
|
238
|
+
let found = context?.trusted
|
|
239
|
+
? undefined
|
|
240
|
+
: held(context?.bundles ?? bundles)
|
|
241
|
+
return found ? checking(tx, found, bundles, false) : bundles
|
|
242
|
+
},
|
|
243
|
+
},
|
|
244
|
+
}
|
|
245
|
+
}
|
package/vocab.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// The component definitions and nothing else, exported as
|
|
2
|
+
// `@yaks/member/vocab`. It imports no storage, no SQL and no runtime code, so a
|
|
3
|
+
// browser tab that loads this vocabulary loads nothing else with it.
|
|
4
|
+
import { memberDoc } from "./comp.js";
|
|
5
|
+
import manifest from './package.json' with {
|
|
6
|
+
type: 'json'
|
|
7
|
+
};
|
|
8
|
+
export { memberDoc };
|
|
9
|
+
/** What this package is: its manifest's description, the one place it is
|
|
10
|
+
* written, which a host stamps on each document here. */ export let description = manifest.description;
|
|
11
|
+
/** Every vocabulary document this plugin contributes. */ export let docs = [
|
|
12
|
+
memberDoc
|
|
13
|
+
];
|
|
14
|
+
export { memberKeywords } from "./keywords.js";
|
|
15
|
+
import { memberKeywords } from "./keywords.js";
|
|
16
|
+
export let keywords = [
|
|
17
|
+
memberKeywords
|
|
18
|
+
];
|
|
19
|
+
//# sourceMappingURL=vocab.js.map
|
package/vocab.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vocab.js","sources":["./vocab.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,gFAAgF;AAChF,qEAAqE;AAGrE,SAAS,SAAS,oBAAmB;AACrC,OAAO,cAAc,sBAAsB;EAAE,MAAM;AAAO,EAAC;AAE3D,SAAS,SAAS,GAAE;AAEpB;uDACuD,GACvD,OAAO,IAAI,cAAsB,SAAS,WAAW,CAAA;AAErD,uDAAuD,GACvD,OAAO,IAAI,OAAmB;EAAC;CAAU,CAAA;AAEzC,SAAS,cAAc,wBAAuB;AAC9C,SAAS,cAAc,wBAAuB;AAC9C,OAAO,IAAI,WAAW;EAAC;CAAe,CAAA"}
|
package/vocab.json
ADDED
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$id": "urn:uuid:d96549f8-2df5-4d85-ad20-ee391da61abd",
|
|
3
|
+
"title": "member",
|
|
4
|
+
"$defs": {
|
|
5
|
+
"member": {
|
|
6
|
+
"$id": "urn:uuid:873d2e5d-3061-49ad-99b9-883b2eda9a8e",
|
|
7
|
+
"component": true,
|
|
8
|
+
"type": "object",
|
|
9
|
+
"description": "one person's membership in a space",
|
|
10
|
+
"properties": {
|
|
11
|
+
"space": {
|
|
12
|
+
"$id": "urn:uuid:50d285c2-4085-4198-baad-952006691a62",
|
|
13
|
+
"type": "string",
|
|
14
|
+
"ref": "entity",
|
|
15
|
+
"death": "cascade",
|
|
16
|
+
"description": "the space they belong to"
|
|
17
|
+
},
|
|
18
|
+
"person": {
|
|
19
|
+
"$id": "urn:uuid:a86a552f-daf8-46dc-97dc-3e240db430c1",
|
|
20
|
+
"type": "string",
|
|
21
|
+
"ref": "entity",
|
|
22
|
+
"death": "cascade",
|
|
23
|
+
"description": "the person the membership is for"
|
|
24
|
+
},
|
|
25
|
+
"role": {
|
|
26
|
+
"$id": "urn:uuid:1aa8d814-5d6c-48e1-a222-9f9f25771ffb",
|
|
27
|
+
"type": "string",
|
|
28
|
+
"enum": [
|
|
29
|
+
"owner",
|
|
30
|
+
"member"
|
|
31
|
+
],
|
|
32
|
+
"default": "member",
|
|
33
|
+
"description": "owner runs the space and holds owner permission on every app in it; member belongs and holds only what a grant gives them"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"grant": {
|
|
38
|
+
"$id": "urn:uuid:41ca19bb-146e-4566-9cac-5b52dd230e87",
|
|
39
|
+
"component": true,
|
|
40
|
+
"type": "object",
|
|
41
|
+
"description": "what one principal is permitted to do with one app",
|
|
42
|
+
"properties": {
|
|
43
|
+
"app": {
|
|
44
|
+
"$id": "urn:uuid:77456970-ffa7-4570-bcb8-092043b27b2f",
|
|
45
|
+
"type": "string",
|
|
46
|
+
"ref": "entity",
|
|
47
|
+
"death": "cascade",
|
|
48
|
+
"description": "the app the grant is on"
|
|
49
|
+
},
|
|
50
|
+
"person": {
|
|
51
|
+
"$id": "urn:uuid:d366217e-32a8-4c49-bb05-3ee63df89612",
|
|
52
|
+
"type": "string",
|
|
53
|
+
"ref": "entity",
|
|
54
|
+
"death": "cascade",
|
|
55
|
+
"description": "the person it is for \u2014 absent on a share link, which names a token instead"
|
|
56
|
+
},
|
|
57
|
+
"token": {
|
|
58
|
+
"$id": "urn:uuid:10192a2d-ae35-4d55-9626-218bbdac248d",
|
|
59
|
+
"type": "string",
|
|
60
|
+
"description": "an unguessable secret standing in for a person: whoever opens the link acts as this grant"
|
|
61
|
+
},
|
|
62
|
+
"access": {
|
|
63
|
+
"$id": "urn:uuid:0a183e71-c610-4e49-a212-9ae5ccb88c1f",
|
|
64
|
+
"type": "string",
|
|
65
|
+
"enum": [
|
|
66
|
+
"owner",
|
|
67
|
+
"editor",
|
|
68
|
+
"viewer"
|
|
69
|
+
],
|
|
70
|
+
"default": "viewer",
|
|
71
|
+
"description": "owner shares and deletes, editor writes, viewer reads"
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
"access": {
|
|
76
|
+
"$id": "urn:uuid:4f268033-1919-4e0f-8a9d-5a4a44e0df42",
|
|
77
|
+
"component": true,
|
|
78
|
+
"type": "object",
|
|
79
|
+
"description": "what an app allows everyone who has no grant on it",
|
|
80
|
+
"properties": {
|
|
81
|
+
"mode": {
|
|
82
|
+
"$id": "urn:uuid:7845b925-f945-4adc-a659-61657f9291c3",
|
|
83
|
+
"type": "string",
|
|
84
|
+
"enum": [
|
|
85
|
+
"public",
|
|
86
|
+
"open",
|
|
87
|
+
"private",
|
|
88
|
+
"friends"
|
|
89
|
+
],
|
|
90
|
+
"default": "public",
|
|
91
|
+
"description": "public: anyone reads. open: anyone reads and writes. private: only those with a permission see it. friends: as private, and confirmed friends of a space owner also read."
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
"_privacy": {
|
|
96
|
+
"$id": "urn:uuid:66962ebf-4fa2-424d-9720-ced973401362",
|
|
97
|
+
"component": true,
|
|
98
|
+
"journal": false,
|
|
99
|
+
"type": "object",
|
|
100
|
+
"wire": false,
|
|
101
|
+
"sync": "none",
|
|
102
|
+
"description": "Who may read this entity, as the personal, inherited and readers declarations say of its components and of what it inherits from; kept by @yaks/member's personal rule in the transaction that changes them, and screening a person's read where every entity's is current. An entity wearing none of those components keeps none.",
|
|
103
|
+
"properties": {
|
|
104
|
+
"person": {
|
|
105
|
+
"$id": "urn:uuid:ae217ba3-b867-42eb-898c-552c5281c941",
|
|
106
|
+
"type": "string",
|
|
107
|
+
"ref": "entity",
|
|
108
|
+
"death": "keep",
|
|
109
|
+
"stamped": true,
|
|
110
|
+
"description": "The one person it is kept to; none where it is kept to no one in particular."
|
|
111
|
+
},
|
|
112
|
+
"shut": {
|
|
113
|
+
"$id": "urn:uuid:abe1cba3-486a-49bf-abf9-4d7fb61da6d0",
|
|
114
|
+
"type": "boolean",
|
|
115
|
+
"stamped": true,
|
|
116
|
+
"description": "True where it is kept to nobody: it names more than one person, or names nobody where a person was asked."
|
|
117
|
+
},
|
|
118
|
+
"signed": {
|
|
119
|
+
"$id": "urn:uuid:81ffc817-ba5a-4080-b44e-491e82d193d3",
|
|
120
|
+
"type": "boolean",
|
|
121
|
+
"stamped": true,
|
|
122
|
+
"description": "True where a component asks its readers to be signed in."
|
|
123
|
+
},
|
|
124
|
+
"floor": {
|
|
125
|
+
"$id": "urn:uuid:9c71cd97-b0d8-4b35-b607-b3b01770efa4",
|
|
126
|
+
"type": "string",
|
|
127
|
+
"enum": [
|
|
128
|
+
"viewer",
|
|
129
|
+
"editor",
|
|
130
|
+
"owner"
|
|
131
|
+
],
|
|
132
|
+
"stamped": true,
|
|
133
|
+
"description": "The highest level a component asks its readers to hold."
|
|
134
|
+
},
|
|
135
|
+
"hash": {
|
|
136
|
+
"$id": "urn:uuid:53a2399d-9b3f-4664-b37a-721dd0c92aaf",
|
|
137
|
+
"type": "string",
|
|
138
|
+
"index": true,
|
|
139
|
+
"stamped": true,
|
|
140
|
+
"description": "The declarations it was reckoned under, as their hash: one other than the store's is stale."
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
"_pace": {
|
|
145
|
+
"$id": "urn:uuid:a8582232-6757-4bbf-8cf7-dcb83e115b41",
|
|
146
|
+
"component": true,
|
|
147
|
+
"journal": false,
|
|
148
|
+
"type": "object",
|
|
149
|
+
"wire": false,
|
|
150
|
+
"sync": "none",
|
|
151
|
+
"description": "The last accepted write of each paced component through each instrument on this entity; maintained by the write guard in the value's transaction.",
|
|
152
|
+
"properties": {
|
|
153
|
+
"writes": {
|
|
154
|
+
"$id": "urn:uuid:bab448b6-3f93-4620-9fcd-3a3fb911a89d",
|
|
155
|
+
"type": "array",
|
|
156
|
+
"stamped": true,
|
|
157
|
+
"description": "Independent component and via clocks, read whole; a null via pools writers carrying no instrument.",
|
|
158
|
+
"items": {
|
|
159
|
+
"type": "object",
|
|
160
|
+
"required": [
|
|
161
|
+
"comp",
|
|
162
|
+
"via",
|
|
163
|
+
"at"
|
|
164
|
+
],
|
|
165
|
+
"properties": {
|
|
166
|
+
"comp": {
|
|
167
|
+
"type": "string"
|
|
168
|
+
},
|
|
169
|
+
"via": {
|
|
170
|
+
"type": [
|
|
171
|
+
"string",
|
|
172
|
+
"null"
|
|
173
|
+
]
|
|
174
|
+
},
|
|
175
|
+
"at": {
|
|
176
|
+
"type": "number"
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
"app_role": {
|
|
184
|
+
"$id": "urn:uuid:6677ebb7-fc2a-42f6-86c6-03a2ced1a3cc",
|
|
185
|
+
"component": true,
|
|
186
|
+
"type": "object",
|
|
187
|
+
"description": "A named role in this app.",
|
|
188
|
+
"unique": [
|
|
189
|
+
[
|
|
190
|
+
"name"
|
|
191
|
+
]
|
|
192
|
+
],
|
|
193
|
+
"required": [
|
|
194
|
+
"name",
|
|
195
|
+
"level"
|
|
196
|
+
],
|
|
197
|
+
"properties": {
|
|
198
|
+
"name": {
|
|
199
|
+
"$id": "urn:uuid:fcc85a3e-9694-4f2d-abdd-81f9ca328974",
|
|
200
|
+
"type": "string",
|
|
201
|
+
"pattern": "^[a-z][a-z0-9_-]*$"
|
|
202
|
+
},
|
|
203
|
+
"level": {
|
|
204
|
+
"$id": "urn:uuid:1e4d2b78-3336-4926-b0db-ab24cbd36851",
|
|
205
|
+
"type": "string",
|
|
206
|
+
"enum": [
|
|
207
|
+
"editor",
|
|
208
|
+
"viewer"
|
|
209
|
+
]
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
"app_ability": {
|
|
214
|
+
"$id": "urn:uuid:bddce680-1040-445f-ab19-ba1d942c2288",
|
|
215
|
+
"component": true,
|
|
216
|
+
"type": "object",
|
|
217
|
+
"description": "An app role's permission to read or write the rows selected by a query.",
|
|
218
|
+
"required": [
|
|
219
|
+
"role",
|
|
220
|
+
"act"
|
|
221
|
+
],
|
|
222
|
+
"properties": {
|
|
223
|
+
"role": {
|
|
224
|
+
"$id": "urn:uuid:e4d9abdf-f146-4f5d-9fb2-21f65a8c76cd",
|
|
225
|
+
"type": "string",
|
|
226
|
+
"ref": "app_role",
|
|
227
|
+
"death": "cascade"
|
|
228
|
+
},
|
|
229
|
+
"act": {
|
|
230
|
+
"$id": "urn:uuid:a81a3cb7-72f7-44cc-bcd8-8229c7a30f2d",
|
|
231
|
+
"type": "string",
|
|
232
|
+
"enum": [
|
|
233
|
+
"read",
|
|
234
|
+
"write"
|
|
235
|
+
]
|
|
236
|
+
},
|
|
237
|
+
"query": {
|
|
238
|
+
"$id": "urn:uuid:484e5102-eb6f-45fc-b1ad-f8fa306963bc",
|
|
239
|
+
"type": "string"
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
"kinds": {
|
|
245
|
+
"member": {
|
|
246
|
+
"$id": "urn:uuid:873d2e5d-3061-49ad-99b9-883b2eda9a8e",
|
|
247
|
+
"description": "one person's membership in a space",
|
|
248
|
+
"examples": [
|
|
249
|
+
{
|
|
250
|
+
"member": {
|
|
251
|
+
"space": "b2d4e6f8-1a3c-4e5f-8a7b-9c0d1e2f3a4b",
|
|
252
|
+
"person": "e5f6a7b8-c9d0-4e1f-a2b3-c4d5e6f7a8b9",
|
|
253
|
+
"role": "member"
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
]
|
|
257
|
+
},
|
|
258
|
+
"grant": {
|
|
259
|
+
"$id": "urn:uuid:41ca19bb-146e-4566-9cac-5b52dd230e87",
|
|
260
|
+
"description": "what one principal is permitted to do with one app",
|
|
261
|
+
"examples": [
|
|
262
|
+
{
|
|
263
|
+
"grant": {
|
|
264
|
+
"app": "1a2b3c4d-5e6f-4a7b-8c9d-0e1f2a3b4c5d",
|
|
265
|
+
"person": "e5f6a7b8-c9d0-4e1f-a2b3-c4d5e6f7a8b9",
|
|
266
|
+
"access": "viewer"
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
]
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
package/vocab.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// The component definitions and nothing else, exported as
|
|
2
|
+
// `@yaks/member/vocab`. It imports no storage, no SQL and no runtime code, so a
|
|
3
|
+
// browser tab that loads this vocabulary loads nothing else with it.
|
|
4
|
+
|
|
5
|
+
import type { VocabDoc } from 'jsr:@yaks/vocab@0.2.36'
|
|
6
|
+
import { memberDoc } from './comp.js'
|
|
7
|
+
import manifest from './package.json' with { type: 'json' }
|
|
8
|
+
|
|
9
|
+
export { memberDoc }
|
|
10
|
+
|
|
11
|
+
/** What this package is: its manifest's description, the one place it is
|
|
12
|
+
* written, which a host stamps on each document here. */
|
|
13
|
+
export let description: string = manifest.description
|
|
14
|
+
|
|
15
|
+
/** Every vocabulary document this plugin contributes. */
|
|
16
|
+
export let docs: VocabDoc[] = [memberDoc]
|
|
17
|
+
|
|
18
|
+
export { memberKeywords } from './keywords.js'
|
|
19
|
+
import { memberKeywords } from './keywords.js'
|
|
20
|
+
export let keywords = [memberKeywords]
|
package/words.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// The three enumerated values this package defines, the helpers that read one
|
|
2
|
+
// out of storage, and the three access rules stated once.
|
|
3
|
+
//
|
|
4
|
+
// A role is what a `member` row records: you are a space's owner, or one of its
|
|
5
|
+
// members. A level is what a `grant` gives one principal on one app: owner,
|
|
6
|
+
// editor, viewer. A mode is what an app allows everyone else — the people with
|
|
7
|
+
// no membership and no grant at all.
|
|
8
|
+
//
|
|
9
|
+
// Roles and levels are kept apart on purpose. `owner` and `member` record
|
|
10
|
+
// whether you belong to the space; `owner`, `editor` and `viewer` record what
|
|
11
|
+
// you may do with one app in it. Membership is not permission: a member with no
|
|
12
|
+
// grant reaches an app exactly as far as a stranger does, which is what makes a
|
|
13
|
+
// roster safe to be generous with.
|
|
14
|
+
/** What a `member` row records. An `owner` runs the space and holds `owner`
|
|
15
|
+
* permission on every app in it; a `member` belongs, and holds only what a
|
|
16
|
+
* grant gives them. */ /** The roles, least to most. */ export let ROLES = [
|
|
17
|
+
'member',
|
|
18
|
+
'owner'
|
|
19
|
+
];
|
|
20
|
+
/** The levels a grant confers, least to most. */ export let LEVELS = [
|
|
21
|
+
'viewer',
|
|
22
|
+
'editor',
|
|
23
|
+
'owner'
|
|
24
|
+
];
|
|
25
|
+
/** The modes an app can be in. */ export let MODES = [
|
|
26
|
+
'public',
|
|
27
|
+
'open',
|
|
28
|
+
'private',
|
|
29
|
+
'friends'
|
|
30
|
+
];
|
|
31
|
+
/** Read a stored `member.role`: an unset one is a plain `member`. */ export let role = (v)=>v == 'owner' ? 'owner' : 'member';
|
|
32
|
+
/** Read a stored `grant.access`: an unset one is a `viewer` — the least a grant
|
|
33
|
+
* can mean, never the most. */ export let level = (v)=>v == 'owner' ? 'owner' : v == 'editor' ? 'editor' : 'viewer';
|
|
34
|
+
/** Read a stored `access.mode`. An app whose mode cannot be read, because its
|
|
35
|
+
* `access` is missing or says something else, is `private`: a lost row locks
|
|
36
|
+
* the app, never opens it. Every app is born with an explicit mode, so report
|
|
37
|
+
* a missing mode as a failure. */ export let mode = (v)=>MODES.includes(v) ? v : 'private';
|
|
38
|
+
/** May a principal holding this level write? An `owner` and an `editor` write;
|
|
39
|
+
* a `viewer`, and a principal holding nothing, do not. */ export let writes = (l)=>l == 'owner' || l == 'editor';
|
|
40
|
+
/** Does this level reach that one? Holding nothing reaches nothing. */ export let reaches = (l, floor)=>l != null && LEVELS.indexOf(l) >= LEVELS.indexOf(floor);
|
|
41
|
+
/** The floors, least to most. */ export let FLOORS = [
|
|
42
|
+
'person',
|
|
43
|
+
...LEVELS
|
|
44
|
+
];
|
|
45
|
+
/** Is this a floor? */ export let isFloor = (v)=>FLOORS.includes(v);
|
|
46
|
+
/** Read a declared floor: one this package does not know asks the most. */ export let floor = (v)=>isFloor(v) ? v : 'owner';
|
|
47
|
+
/** Does a principal holding this level stand on that floor? Anyone signed in
|
|
48
|
+
* stands on `person`, and nobody stands on any.
|
|
49
|
+
*
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { assertEquals } from '@std/assert'
|
|
52
|
+
* import { stands } from '@yaks/member'
|
|
53
|
+
* assertEquals(stands('kim', null, 'person'), true)
|
|
54
|
+
* assertEquals(stands(null, null, 'person'), false)
|
|
55
|
+
* assertEquals(stands('kim', 'viewer', 'editor'), false)
|
|
56
|
+
* ```
|
|
57
|
+
*/ export let stands = (who, l, f)=>f == 'person' ? who != null : reaches(l, f);
|
|
58
|
+
// The rules, stated once. Everything else in this package — the `policy`
|
|
59
|
+
// helpers the HTTP layer calls, the `precondition` hook a transaction passes —
|
|
60
|
+
// reads a mode and a level out of storage and then calls `reads` or `edits`,
|
|
61
|
+
// and the egress (@yaks/egress) calls `callsOut`. A service that already knows
|
|
62
|
+
// both (one that authenticated the caller at its edge and keeps modes in a
|
|
63
|
+
// directory) calls them directly, with no storage at all, and so cannot drift
|
|
64
|
+
// from the graph that enforces them.
|
|
65
|
+
/** May this principal read the app? Friendship is a read permission on its
|
|
66
|
+
* own, independent of membership or a grant. */ export let reads = (m, l, friend = false)=>l != null || m == 'public' || m == 'open' || m == 'friends' && friend;
|
|
67
|
+
/** May a principal holding this level write an app in this mode? An `open` app
|
|
68
|
+
* is written by anyone, signed in or not; anything else requires owner or
|
|
69
|
+
* editor. */ export let edits = (m, l)=>m == 'open' || writes(l);
|
|
70
|
+
/** May a principal holding this level call out through a credential an app
|
|
71
|
+
* uses (egress-use)? Whoever holds any level on the app may; anyone else only
|
|
72
|
+
* through one the app opened to `anyone`, as a public widget's is. The app's
|
|
73
|
+
* mode does not enter into it: the sentinel a caller presents points at a
|
|
74
|
+
* credential and is not one, so it is never enough on its own. */ export let callsOut = (anyone, l)=>anyone || l != null;
|
|
75
|
+
//# sourceMappingURL=words.js.map
|
package/words.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"words.js","sources":["./words.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,0DAA0D;AAC1D,EAAE;AACF,gFAAgF;AAChF,4EAA4E;AAC5E,+EAA+E;AAC/E,qCAAqC;AACrC,EAAE;AACF,0EAA0E;AAC1E,8EAA8E;AAC9E,gFAAgF;AAChF,gFAAgF;AAChF,mCAAmC;AAEnC;;qBAEqB,GAgBrB,8BAA8B,GAC9B,OAAO,IAAI,QAAgB;EAAC;EAAU;CAAQ,CAAA;AAE9C,+CAA+C,GAC/C,OAAO,IAAI,SAAkB;EAAC;EAAU;EAAU;CAAQ,CAAA;AAE1D,gCAAgC,GAChC,OAAO,IAAI,QAAQ;EAAC;EAAU;EAAQ;EAAW;CAAU,CAAS;AAEpE,mEAAmE,GACnE,OAAO,IAAI,OAAO,CAAC,IAAqB,KAAK,UAAU,UAAU,SAAQ;AAEzE;6BAC6B,GAC7B,OAAO,IAAI,QAAQ,CAAC,IAClB,KAAK,UAAU,UAAU,KAAK,WAAW,WAAW,SAAQ;AAE9D;;;gCAGgC,GAChC,OAAO,IAAI,OAAO,CAAC,IACjB,MAAM,QAAQ,CAAC,KAAa,IAAY,UAAS;AAEnD;wDACwD,GACxD,OAAO,IAAI,SAAS,CAAC,IAA6B,KAAK,WAAW,KAAK,SAAQ;AAE/E,qEAAqE,GACrE,OAAO,IAAI,UAAU,CAAC,GAAiB,QACrC,KAAK,QAAQ,OAAO,OAAO,CAAC,MAAM,OAAO,OAAO,CAAC,OAAM;AASzD,+BAA+B,GAC/B,OAAO,IAAI,SAAkB;EAAC;KAAa;CAAO,CAAA;AAElD,qBAAqB,GACrB,OAAO,IAAI,UAAU,CAAC,IAA2B,OAAO,QAAQ,CAAC,GAAW;AAE5E,yEAAyE,GACzE,OAAO,IAAI,QAAQ,CAAC,IAAsB,QAAQ,KAAK,IAAI,QAAO;AAElE;;;;;;;;;;CAUC,GACD,OAAO,IAAI,SAAS,CAClB,KACA,GACA,IACY,KAAK,WAAW,OAAO,OAAO,QAAQ,GAAG,GAAE;AAEzD,yEAAyE;AACzE,+EAA+E;AAC/E,6EAA6E;AAC7E,+EAA+E;AAC/E,2EAA2E;AAC3E,8EAA8E;AAC9E,qCAAqC;AAErC;8CAC8C,GAC9C,OAAO,IAAI,QAAQ,CAAC,GAAS,GAAiB,SAAS,KAAK,GAC1D,KAAK,QAAQ,KAAK,YAAY,KAAK,UAAU,KAAK,aAAa,OAAM;AAEvE;;WAEW,GACX,OAAO,IAAI,QAAQ,CAAC,GAAS,IAC3B,KAAK,UAAU,OAAO,GAAE;AAE1B;;;;gEAIgE,GAChE,OAAO,IAAI,WAAW,CAAC,QAAiB,IACtC,UAAU,KAAK,KAAI"}
|