@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/words.ts
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
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
|
+
|
|
15
|
+
/** What a `member` row records. An `owner` runs the space and holds `owner`
|
|
16
|
+
* permission on every app in it; a `member` belongs, and holds only what a
|
|
17
|
+
* grant gives them. */
|
|
18
|
+
export type Role = 'owner' | 'member'
|
|
19
|
+
|
|
20
|
+
/** What a `grant` gives one principal on one app: `owner` shares and deletes
|
|
21
|
+
* it, `editor` writes it, `viewer` reads it. */
|
|
22
|
+
export type Level = 'owner' | 'editor' | 'viewer'
|
|
23
|
+
|
|
24
|
+
/** What an app allows everyone with no grant on it:
|
|
25
|
+
*
|
|
26
|
+
* - `public` — anyone with the link reads it; only the granted write.
|
|
27
|
+
* - `open` — anyone with the link reads it and writes it, signed in or not.
|
|
28
|
+
* - `private` — only principals holding a permission see it at all.
|
|
29
|
+
* - `friends` — confirmed friends of a space owner may also read it.
|
|
30
|
+
*/
|
|
31
|
+
export type Mode = typeof MODES[number]
|
|
32
|
+
|
|
33
|
+
/** The roles, least to most. */
|
|
34
|
+
export let ROLES: Role[] = ['member', 'owner']
|
|
35
|
+
|
|
36
|
+
/** The levels a grant confers, least to most. */
|
|
37
|
+
export let LEVELS: Level[] = ['viewer', 'editor', 'owner']
|
|
38
|
+
|
|
39
|
+
/** The modes an app can be in. */
|
|
40
|
+
export let MODES = ['public', 'open', 'private', 'friends'] as const
|
|
41
|
+
|
|
42
|
+
/** Read a stored `member.role`: an unset one is a plain `member`. */
|
|
43
|
+
export let role = (v: unknown): Role => v == 'owner' ? 'owner' : 'member'
|
|
44
|
+
|
|
45
|
+
/** Read a stored `grant.access`: an unset one is a `viewer` — the least a grant
|
|
46
|
+
* can mean, never the most. */
|
|
47
|
+
export let level = (v: unknown): Level =>
|
|
48
|
+
v == 'owner' ? 'owner' : v == 'editor' ? 'editor' : 'viewer'
|
|
49
|
+
|
|
50
|
+
/** Read a stored `access.mode`. An app whose mode cannot be read, because its
|
|
51
|
+
* `access` is missing or says something else, is `private`: a lost row locks
|
|
52
|
+
* the app, never opens it. Every app is born with an explicit mode, so report
|
|
53
|
+
* a missing mode as a failure. */
|
|
54
|
+
export let mode = (v: unknown): Mode =>
|
|
55
|
+
MODES.includes(v as Mode) ? v as Mode : 'private'
|
|
56
|
+
|
|
57
|
+
/** May a principal holding this level write? An `owner` and an `editor` write;
|
|
58
|
+
* a `viewer`, and a principal holding nothing, do not. */
|
|
59
|
+
export let writes = (l: Level | null): boolean => l == 'owner' || l == 'editor'
|
|
60
|
+
|
|
61
|
+
/** Does this level reach that one? Holding nothing reaches nothing. */
|
|
62
|
+
export let reaches = (l: Level | null, floor: Level): boolean =>
|
|
63
|
+
l != null && LEVELS.indexOf(l) >= LEVELS.indexOf(floor)
|
|
64
|
+
|
|
65
|
+
/** The least a component asks of whoever writes it, whatever the app's mode:
|
|
66
|
+
* a level, or `person` — anyone signed in, level or none. */
|
|
67
|
+
export type Floor = 'person' | Level
|
|
68
|
+
|
|
69
|
+
/** The floor each component asks of whoever writes it, by name. */
|
|
70
|
+
export type Floors = Record<string, Floor>
|
|
71
|
+
|
|
72
|
+
/** The floors, least to most. */
|
|
73
|
+
export let FLOORS: Floor[] = ['person', ...LEVELS]
|
|
74
|
+
|
|
75
|
+
/** Is this a floor? */
|
|
76
|
+
export let isFloor = (v: unknown): v is Floor => FLOORS.includes(v as Floor)
|
|
77
|
+
|
|
78
|
+
/** Read a declared floor: one this package does not know asks the most. */
|
|
79
|
+
export let floor = (v: unknown): Floor => isFloor(v) ? v : 'owner'
|
|
80
|
+
|
|
81
|
+
/** Does a principal holding this level stand on that floor? Anyone signed in
|
|
82
|
+
* stands on `person`, and nobody stands on any.
|
|
83
|
+
*
|
|
84
|
+
* ```ts
|
|
85
|
+
* import { assertEquals } from '@std/assert'
|
|
86
|
+
* import { stands } from '@yaks/member'
|
|
87
|
+
* assertEquals(stands('kim', null, 'person'), true)
|
|
88
|
+
* assertEquals(stands(null, null, 'person'), false)
|
|
89
|
+
* assertEquals(stands('kim', 'viewer', 'editor'), false)
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export let stands = (
|
|
93
|
+
who: string | null,
|
|
94
|
+
l: Level | null,
|
|
95
|
+
f: Floor,
|
|
96
|
+
): boolean => f == 'person' ? who != null : reaches(l, f)
|
|
97
|
+
|
|
98
|
+
// The rules, stated once. Everything else in this package — the `policy`
|
|
99
|
+
// helpers the HTTP layer calls, the `precondition` hook a transaction passes —
|
|
100
|
+
// reads a mode and a level out of storage and then calls `reads` or `edits`,
|
|
101
|
+
// and the egress (@yaks/egress) calls `callsOut`. A service that already knows
|
|
102
|
+
// both (one that authenticated the caller at its edge and keeps modes in a
|
|
103
|
+
// directory) calls them directly, with no storage at all, and so cannot drift
|
|
104
|
+
// from the graph that enforces them.
|
|
105
|
+
|
|
106
|
+
/** May this principal read the app? Friendship is a read permission on its
|
|
107
|
+
* own, independent of membership or a grant. */
|
|
108
|
+
export let reads = (m: Mode, l: Level | null, friend = false): boolean =>
|
|
109
|
+
l != null || m == 'public' || m == 'open' || m == 'friends' && friend
|
|
110
|
+
|
|
111
|
+
/** May a principal holding this level write an app in this mode? An `open` app
|
|
112
|
+
* is written by anyone, signed in or not; anything else requires owner or
|
|
113
|
+
* editor. */
|
|
114
|
+
export let edits = (m: Mode, l: Level | null): boolean =>
|
|
115
|
+
m == 'open' || writes(l)
|
|
116
|
+
|
|
117
|
+
/** May a principal holding this level call out through a credential an app
|
|
118
|
+
* uses (egress-use)? Whoever holds any level on the app may; anyone else only
|
|
119
|
+
* through one the app opened to `anyone`, as a public widget's is. The app's
|
|
120
|
+
* mode does not enter into it: the sentinel a caller presents points at a
|
|
121
|
+
* credential and is not one, so it is never enough on its own. */
|
|
122
|
+
export let callsOut = (anyone: boolean, l: Level | null): boolean =>
|
|
123
|
+
anyone || l != null
|