@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.
Files changed (86) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +471 -2
  3. package/_dist/asking.d.ts +4 -0
  4. package/_dist/asking.d.ts.map +1 -0
  5. package/_dist/comp.d.ts +14 -0
  6. package/_dist/comp.d.ts.map +1 -0
  7. package/_dist/deny.d.ts +19 -0
  8. package/_dist/deny.d.ts.map +1 -0
  9. package/_dist/graph.d.ts +4 -0
  10. package/_dist/graph.d.ts.map +1 -0
  11. package/_dist/guard.d.ts +45 -0
  12. package/_dist/guard.d.ts.map +1 -0
  13. package/_dist/keywords.d.ts +80 -0
  14. package/_dist/keywords.d.ts.map +1 -0
  15. package/_dist/mod.d.ts +112 -0
  16. package/_dist/mod.d.ts.map +1 -0
  17. package/_dist/owns.d.ts +18 -0
  18. package/_dist/owns.d.ts.map +1 -0
  19. package/_dist/pace.d.ts +48 -0
  20. package/_dist/pace.d.ts.map +1 -0
  21. package/_dist/personal.d.ts +46 -0
  22. package/_dist/personal.d.ts.map +1 -0
  23. package/_dist/plugin.d.ts +32 -0
  24. package/_dist/plugin.d.ts.map +1 -0
  25. package/_dist/policy.d.ts +35 -0
  26. package/_dist/policy.d.ts.map +1 -0
  27. package/_dist/privacy.d.ts +55 -0
  28. package/_dist/privacy.d.ts.map +1 -0
  29. package/_dist/roles.d.ts +20 -0
  30. package/_dist/roles.d.ts.map +1 -0
  31. package/_dist/vocab.d.ts +10 -0
  32. package/_dist/vocab.d.ts.map +1 -0
  33. package/_dist/words.d.ts +53 -0
  34. package/_dist/words.d.ts.map +1 -0
  35. package/asking.js +65 -0
  36. package/asking.js.map +1 -0
  37. package/asking.ts +77 -0
  38. package/comp.js +43 -0
  39. package/comp.js.map +1 -0
  40. package/comp.ts +52 -0
  41. package/deno.json +1 -0
  42. package/deny.js +31 -0
  43. package/deny.js.map +1 -0
  44. package/deny.ts +45 -0
  45. package/graph.js +6 -0
  46. package/graph.js.map +1 -0
  47. package/graph.ts +16 -0
  48. package/guard.js +265 -0
  49. package/guard.js.map +1 -0
  50. package/guard.ts +327 -0
  51. package/keywords.js +170 -0
  52. package/keywords.js.map +1 -0
  53. package/keywords.ts +190 -0
  54. package/meta/member.vocab.json +70 -0
  55. package/mod.js +112 -0
  56. package/mod.js.map +1 -0
  57. package/mod.ts +113 -0
  58. package/owns.js +12 -0
  59. package/owns.js.map +1 -0
  60. package/owns.ts +23 -0
  61. package/pace.js +189 -0
  62. package/pace.js.map +1 -0
  63. package/pace.ts +195 -0
  64. package/package.json +33 -4
  65. package/personal.js +448 -0
  66. package/personal.js.map +1 -0
  67. package/personal.ts +550 -0
  68. package/plugin.js +63 -0
  69. package/plugin.js.map +1 -0
  70. package/plugin.ts +62 -0
  71. package/policy.js +115 -0
  72. package/policy.js.map +1 -0
  73. package/policy.ts +176 -0
  74. package/privacy.js +293 -0
  75. package/privacy.js.map +1 -0
  76. package/privacy.ts +379 -0
  77. package/roles.js +164 -0
  78. package/roles.js.map +1 -0
  79. package/roles.ts +245 -0
  80. package/vocab.js +19 -0
  81. package/vocab.js.map +1 -0
  82. package/vocab.json +272 -0
  83. package/vocab.ts +20 -0
  84. package/words.js +75 -0
  85. package/words.js.map +1 -0
  86. package/words.ts +123 -0
package/README.md CHANGED
@@ -1,3 +1,472 @@
1
- # Temporary Holding Version
1
+ # @yaks/member
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Access control for [@yaks/graph](../graph). The package stores space
4
+ memberships, permission grants and access modes as graph components. It checks
5
+ writes inside `apply()`, provides app-level admission checks, and scopes
6
+ person-owned data inside graph reads and transactions.
7
+
8
+ It does not authenticate callers or open storage. The caller supplies verified
9
+ identity at the graph boundary.
10
+
11
+ ## Install
12
+
13
+ ```sh
14
+ deno add jsr:@yaks/member
15
+ # or: npx jsr add @yaks/member
16
+ ```
17
+
18
+ The complete example below also uses `@yaks/graph`, `@yaks/vocab`, `@yaks/ram`
19
+ and `@yaks/doc`.
20
+
21
+ ## Terms
22
+
23
+ A **principal** is the entity making a request: usually a person, or a grant
24
+ entity representing a share link. An **app** is the entity whose access rules
25
+ apply to the graph. A **space** groups memberships; its owners receive owner
26
+ permission when a policy or guard is configured with that space's id.
27
+
28
+ The application supplies app, space and principal entity ids. This package does
29
+ not declare their components or infer an app's space from its contents.
30
+
31
+ ## The three components
32
+
33
+ These components are stored by the graph's storage adapter, alongside the
34
+ application's other data:
35
+
36
+ | Component | Purpose |
37
+ | ----------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
38
+ | `member{space, person, role}` | Associates a person with a space. `role` defaults to `member`; `owner` supplies owner permission to policies configured for that space. |
39
+ | `grant{app, person, token, access}` | Gives a principal permission on an app. `access` defaults to `viewer`, with `editor` and `owner` also supported. A share link uses `token` instead of `person`. |
40
+ | `access{mode}` | Sets an app's access mode. A missing or unreadable mode reads as `private`. |
41
+
42
+ Memberships and grants are separate entities. The `access` component is stored
43
+ on the app entity. References from `member` and `grant` use `death: cascade`, so
44
+ deleting a referenced person, space or app removes the dependent entities. Use
45
+ qualified query names such as `.grant.person=dana` and `.grant.access=editor`
46
+ for properties whose short names are disabled.
47
+
48
+ The modes determine access:
49
+
50
+ | Mode | Read | Write ordinary data |
51
+ | --------- | ------------------------------------- | --------------------------------------------------------------------------- |
52
+ | `public` | Anyone | Owner or editor |
53
+ | `open` | Anyone | Anyone adds rows; a principal holding no writing level changes only its own |
54
+ | `private` | Any principal with a permission level | Owner or editor |
55
+
56
+ ## Membership is not permission
57
+
58
+ An ordinary membership supplies no permission. A grant can authorize a person
59
+ who has no membership at all. Removing a membership removes any owner permission
60
+ derived from that membership, but **does not revoke explicit grants**. Remove
61
+ the grants separately when revoking those permissions.
62
+
63
+ Permission resolution checks these cases in order:
64
+
65
+ 1. An anonymous principal has no permission level.
66
+ 2. If the principal entity itself carries a grant for this app, use that grant's
67
+ access level. This supports share links.
68
+ 3. If the principal is an owner in the configured space, use `owner`.
69
+ 4. Otherwise, use the first matching grant naming that person and app, or no
70
+ level if none exists.
71
+
72
+ Space-owner permission is computed from membership, without storing a grant for
73
+ every app. Omitting `space` from the policy or guard disables this source of
74
+ permission. The package does not combine multiple grants by taking their highest
75
+ level; avoid conflicting duplicate grants for a person and app.
76
+
77
+ ## The three checks
78
+
79
+ `reads(mode, level)` allows reads when the mode is not `private` or the
80
+ principal has any level. `edits(mode, level)` allows writes when the mode is
81
+ `open` or the level is `owner` or `editor`. `callsOut(anyone, level)` is
82
+ egress-use: it allows calling out through a credential an app uses when the app
83
+ opened that credential to anyone, or the principal has any level, whatever the
84
+ mode. [@yaks/egress](../egress) asks it before it swaps a sentinel.
85
+
86
+ These exported functions require no storage. A viewer can write an `open` app;
87
+ on `public` and `private` apps a viewer can only read. `writes(level)` checks
88
+ the level alone and returns true for `owner` and `editor`.
89
+
90
+ ## Where each check runs
91
+
92
+ This complete example uses in-memory storage, creates an initial owner, then
93
+ installs the write guard:
94
+
95
+ ```ts
96
+ import { loadVocab } from '@yaks/vocab'
97
+ import { graph } from '@yaks/graph'
98
+ import { ram } from '@yaks/ram'
99
+ import { docDoc } from '@yaks/doc'
100
+ import { memberDoc, members, policy } from '@yaks/member'
101
+
102
+ let vocab = loadVocab([memberDoc, docDoc])
103
+ let storage = ram(vocab)
104
+ let g = graph({ storage, vocab })
105
+
106
+ await g.apply([
107
+ { entity: { eid: 'club' }, doc: { title: 'Book club' } },
108
+ { entity: { eid: 'dana' }, doc: { title: 'Dana' } },
109
+ {
110
+ entity: { eid: 'notes' },
111
+ doc: { title: 'Club notes' },
112
+ access: { mode: 'private' },
113
+ },
114
+ {
115
+ entity: { eid: 'membership' },
116
+ member: { space: 'club', person: 'dana', role: 'owner' },
117
+ },
118
+ ])
119
+ g.use(members({ app: 'notes', space: 'club', vocab }))
120
+
121
+ await g.apply([{
122
+ entity: { eid: 'notes' },
123
+ doc: { body: 'Next meeting: Thursday' },
124
+ $actor: { by: 'dana' },
125
+ }])
126
+
127
+ let may = policy(storage, { space: 'club' })
128
+ console.log(await may.canRead('dana', 'notes')) // true
129
+ console.log(await may.canRead(null, 'notes')) // false
130
+ ```
131
+
132
+ A **bundle** is one entity's components as a JSON object. A **batch** is a list
133
+ of bundles applied in one transaction. The guard selects the first nonempty
134
+ `$actor.by` in the batch as its principal, and uses the configured app's access
135
+ rules for the entire batch. It is not a per-entity filter for a graph containing
136
+ several independently protected apps.
137
+
138
+ `members()` registers a `precondition` hook. It reads permissions inside the
139
+ transaction before applying bundles; throwing `Denied` or `Paced` rolls back
140
+ that transaction. It is handed the vocabulary the graph was loaded with, whose
141
+ components may declare who writes them and how often (below). Batches without an
142
+ actor are anonymous, so ordinary writes are allowed only when the app is `open`.
143
+
144
+ A host migrating instrument identities may supply `instrument`, a pure function
145
+ from an instrument id to its canonical eid. Ownership, companion permission and
146
+ pacing compare both the vouched writer and stored instrument through that same
147
+ function. Without it, instrument eids compare exactly.
148
+
149
+ The code receiving a request must authenticate the caller and replace any
150
+ client-supplied actor before applying bundles. [@yaks/api](../api) uses
151
+ `signed()` for that replacement. This package trusts the actor it receives.
152
+
153
+ Reads do not pass through `apply()`. Call `policy(storage, { space }).canRead`
154
+ before returning results. `policy()` also exposes `modeOf`, `levelOf` and
155
+ `canWrite`. These methods return values for synchronous storage and promises for
156
+ asynchronous storage; `await` works with either.
157
+
158
+ ## Only an owner edits the access rows
159
+
160
+ Batches that write or remove `member`, `grant` or `access` components require
161
+ owner permission on the configured app. An editor can change ordinary data but
162
+ cannot write these access-control components. This additional check also runs
163
+ for an `open` app.
164
+
165
+ ## A component says who writes it, and how often
166
+
167
+ A component may declare a `floor`: the least its writer holds, whatever the
168
+ app's mode. `person` is anyone signed in; `viewer`, `editor` and `owner` are
169
+ that level on the app, or more. The keyword is this package's, so load the
170
+ vocabulary with `memberKeywords` for the loader to keep it; `floorsIn(vocab)`
171
+ reads the floors back, and `floored(doc)` lists a document's floors that are not
172
+ one.
173
+
174
+ ```json
175
+ {
176
+ "$defs": {
177
+ "line": {
178
+ "component": true,
179
+ "type": "object",
180
+ "floor": "person",
181
+ "pace": "1s",
182
+ "properties": { "text": { "type": "string" } }
183
+ }
184
+ }
185
+ }
186
+ ```
187
+
188
+ A batch that writes or removes a floored component is refused for anyone below
189
+ the floor, with a `Denied` naming the component (`need` is the floor, `comp` the
190
+ component). A program installing the guard names floors for words it did not
191
+ declare with `floors`, which win over declared ones:
192
+ `members({ app: 'shop', space: 'club', vocab, floors: { product: 'editor' } })`.
193
+ The access rows ask `owner` whatever either says.
194
+
195
+ ## A component says who reads it
196
+
197
+ `readers` takes the same values as `floor` and asks them of whoever reads the
198
+ component, whatever the app's mode: an entity wearing it is seen only by a
199
+ reader standing on that floor. Form sign-ups declare `"readers": "editor"`, so
200
+ anyone reads a `public` form and only the app's editors and owners read the
201
+ sign-ups. `readersIn(vocab)` reads the declarations back, and `floored(doc)`
202
+ reports a `readers` that is not a floor too.
203
+
204
+ `readers` can also map floors to queries on the component's own properties,
205
+ `{ "editor": ".individual.status&.individual.status!=member,attender" }`: an
206
+ entity asks the highest floor whose query its own bundle matches (run in memory
207
+ by @yaks/match, where `_privacy` is reckoned), and nothing when it matches none.
208
+ `!=` matches an absent property, so the example names `.individual.status` first
209
+ to leave an entity with no status to every reader. The conditions are part of
210
+ the declarations' `hash`, so changing one has every entity re-reckoned and a
211
+ string-only declaration hashes as it always has. `floored(doc)` refuses a key
212
+ that is no floor and a query that does not parse or tests another component,
213
+ `conditioned(vocab)` one naming a property the vocabulary lacks, and
214
+ `personal(vocab)` refuses conditions in a vocabulary that keeps no `_privacy`.
215
+
216
+ `shown` takes the same values and keeps only its own component: a reader below
217
+ the floor reads an entity wearing it without that component, and a query on it
218
+ finds nothing, while the entity's other components read as they otherwise would.
219
+ A directory keeps what a person ticked on a sign-up form to its editors by
220
+ declaring `interests` `"shown": "editor"` beside a members' `individual`.
221
+ `shownIn(vocab)` reads the declarations back, and `floored(doc)` reports a
222
+ `shown` that is not a floor.
223
+
224
+ The [person-owned data](#person-owned-data) plugin enforces both, at the same
225
+ reads and with the same bypasses. Each external read supplies `ReadOpts.level`
226
+ beside `ReadOpts.person`: the level the host verified the person holds on the
227
+ app, or none. A guest, a stranger signed in and a level this package does not
228
+ know stand below every level. It keeps rows from readers only; writes keep their
229
+ floor and mode.
230
+
231
+ ## The owner of a referenced row may answer with a mark
232
+
233
+ A component may declare `permit`: companion mark names mapped to local reference
234
+ properties. On an existing row, the owner of the stored reference's target may
235
+ add or remove the named mark. The target belongs to its `created.by`, or, when
236
+ it has no byline, to its `created.via`. The app must still admit the writer; the
237
+ mark's floor and pace apply too.
238
+
239
+ ```json
240
+ {
241
+ "$defs": {
242
+ "request": {
243
+ "component": true,
244
+ "type": "object",
245
+ "floor": "owner",
246
+ "permit": { "completed": "target" },
247
+ "properties": {
248
+ "target": { "type": "string", "ref": "entity", "death": "keep" },
249
+ "text": { "type": "string" }
250
+ }
251
+ }
252
+ }
253
+ }
254
+ ```
255
+
256
+ Here an app owner writes `request{target, text}`. The referenced row's owner
257
+ answers on that request with `completed{}`; the graph fills the mark's `at`,
258
+ `by` and `via`. Repeating the mark preserves its history. Writing
259
+ `completed: null` removes it under the same referenced ownership.
260
+
261
+ Load declarations with `memberKeywords`. `permitted(vocab)` reports malformed
262
+ maps, undeclared companions, companions with writable properties, and properties
263
+ that are not stored references. Companions must be marks containing only stamped
264
+ properties; `created`, `updated` and `tombstone` cannot be companions.
265
+ `permitsIn(vocab)` reads valid declarations and throws on invalid ones.
266
+
267
+ This permission changes only the named mark. It grants no request edits,
268
+ rebinding, request component removal or entity deletion, including changes split
269
+ across several bundles in one batch. A missing or deleted target grants nothing,
270
+ and a newly created request cannot supply its own permission. Owners and editors
271
+ retain their ordinary rights; floors and access-control words remain protected.
272
+
273
+ ## A row kept within a row of one's own
274
+
275
+ A program installing the guard may name components a principal holding no
276
+ writing level writes only inside a row of its own, each with the reference
277
+ property naming that row: `within: { entry: 'session' }` lets an `open` app's
278
+ visitor add lines only to transcripts they started. The parent belongs to its
279
+ `created.by`, or, with no byline, to its `created.via`; a parent created in the
280
+ same batch is the writer's. Owners and editors write anywhere.
281
+
282
+ ## How often a component may be written
283
+
284
+ `pace` is @yaks/vocab's keyword: how often one instrument may write one entity's
285
+ component. On a stored component this guard holds it by the bundle's
286
+ `$actor.via`, for guests and signed-in writers alike. Writers with no `via`
287
+ share a clock on each entity's component, even when their `by` differs. Another
288
+ entity, component or `via` keeps its own clock, so one batch may write many
289
+ entities. Owners keep the pace too.
290
+
291
+ A write inside its clock's interval is refused with `Paced`, carrying `actor`
292
+ (the `via`, or null), `entity`, `comp`, `pace` and `wait` (milliseconds until
293
+ the writer may try again). Writing the same values is a retry and starts no
294
+ clock. Clearing a component goes at once and preserves its clock; deleting the
295
+ entity removes its clocks with it. `pacesIn(vocab)` reads the stored paces back.
296
+ The guard's `now` is the time its clocks are kept by (default `Date.now`).
297
+
298
+ The package also declares `_pace{writes}`, a server-owned component on each
299
+ paced entity. Its JSON ledger keeps independent component/via clocks; changing
300
+ another component or alternating instruments cannot erase one. Accepted clock
301
+ patches commit with their values, and expired clocks are removed on that
302
+ entity's next paced write. Clients cannot write or clear the ledger, and its
303
+ `sync: none` keeps it off transports in either direction. An existing row
304
+ without a ledger conservatively initializes each worn component from its recent
305
+ `created` and `updated` instruments. Its first accepted paced write persists
306
+ these clocks; after that, entity stamps no longer influence pacing. This online
307
+ transition keeps a recent legacy write paced without rewriting stores at boot.
308
+
309
+ `pacing(paces, tx, bundles, now?)` returns the accepted bundles with clock
310
+ patches, and derives each entity's writer from the bundles as the graph does.
311
+ The hook supplied by `guarding()` therefore needs `memberDoc` in the graph's
312
+ vocabulary when any component declares a stored pace.
313
+
314
+ ## A visitor to an open app adds, and changes only its own rows
315
+
316
+ A principal that an `open` app admits and no level does (an anonymous caller, a
317
+ viewer, a stranger signed in) may create entities, and may change or delete an
318
+ existing entity when its `created.by` names that principal, or when the entity
319
+ is the principal itself. A row without `created.by` belongs only to the caller
320
+ whose `$actor.via` matches its `created.via`; a guest with only `via` may change
321
+ and delete those rows. A matching `via` grants no permission on a row carrying
322
+ someone else's `created.by`, and supplies no signed-in identity or permission
323
+ level. A caller with neither `by` nor `via` owns nothing, so it only adds. A
324
+ batch that leaves every property it names as it was is admitted on any row, so a
325
+ retried write of the same values is not refused. Owners and editors are not
326
+ affected.
327
+
328
+ Create the first owner membership before installing `members()`, as in the
329
+ example. With the guard installed, writing the first owner membership requires
330
+ an owner that does not yet exist. Thereafter an authorized owner can maintain
331
+ memberships and grants through the guarded graph.
332
+
333
+ ## Person-owned data
334
+
335
+ A component's `personal` declaration names who owns its data. A local reference
336
+ property, such as `"personal": "by"`, makes the entire entity private to the
337
+ person that property names. `"personal": "entity"` makes just the component
338
+ private on the person's entity; its public name and other public components
339
+ remain visible.
340
+
341
+ Register `memberKeywords` when loading these declarations. `personal(vocab)`
342
+ protects them as a graph plugin; `personalsIn(vocab)` reads them, refusing the
343
+ vocabulary while `unowned(vocab)` finds any that names no owner, each as a
344
+ sentence saying what to write instead. A host refuses a deploy by the same rule.
345
+ The `@yaks/member/graph` facet composes this plugin through `@yaks/host`. Hosts
346
+ can also supply a component-to-owner map in the facet's `personal` option. The
347
+ shared draft vocabulary declares its own `by` policy.
348
+
349
+ Every external read supplies `ReadOpts.person`: the verified person eid, or
350
+ `null` for a guest. Reads with no person are internal. Visibility applies before
351
+ filters, projections, references, aggregates and subscription membership, even
352
+ for native reads. Guests cannot read a private entity whose owner is missing.
353
+ Whole-entity ownership also protects every component and the entity's deletion.
354
+ Private entity ownership is chosen at creation; an ordinary write cannot make an
355
+ existing public entity private. Creation binds an omitted owner to the writer,
356
+ and nobody can transfer that owner or remove its ownership component. Removing
357
+ the entity is the owner's act. Private components on a person's entity are
358
+ writable only by that person. Rules and reference cascades pass through the same
359
+ transaction checks.
360
+
361
+ App editors and space owners gain no authority over another person's private
362
+ data. Explicit `ReadOpts.administrative` grants administrative reads only when
363
+ the host has verified that authority. Ordinary administrative writes still
364
+ respect ownership; trusted server transactions are the explicit repair boundary.
365
+ In yaks.app the kernel vouches administrative reads and strips caller-supplied
366
+ administrative headers.
367
+
368
+ ## Share links
369
+
370
+ A grant can identify a link token instead of a person:
371
+
372
+ ```json
373
+ {
374
+ "entity": { "eid": "share" },
375
+ "grant": { "app": "notes", "token": "a-secret-token", "access": "viewer" }
376
+ }
377
+ ```
378
+
379
+ The authentication layer validates the token and identifies the caller as
380
+ `share`, the grant entity's id. Permission lookup then reads that entity's own
381
+ grant. Deleting the grant revokes its permission. Its permission applies only to
382
+ the named app; that app's mode still applies, including unrestricted ordinary
383
+ writes when the mode is `open`.
384
+
385
+ This package does not generate tokens, validate incoming tokens, or implement an
386
+ HTTP route for opening a link.
387
+
388
+ ## Invitations belong to another package
389
+
390
+ [@yaks/mail](../mail) supplies invitation handling through
391
+ [@yaks/effects](../effects). A `created('member')` handler runs after commit, so
392
+ a delivery failure does not roll back the membership write: an application
393
+ registers `fx.created('member', run)` on its effects registry `fx`, where `run`
394
+ reads `event.comp?.person` and `event.comp?.space`. This package registers no
395
+ invitation handler.
396
+
397
+ ## Exports
398
+
399
+ | Import path | Exports |
400
+ | -------------------- | ------------------------------------------------------------------------------------------ |
401
+ | `@yaks/member` | Component definitions, access helpers, policy, write guard, plugin and error listed below. |
402
+ | `@yaks/member/vocab` | `memberDoc` and `docs`, the array of vocabulary documents. |
403
+ | `@yaks/member/words` | `role`, `level`, `mode` and the access rules over them, without the rest of the package. |
404
+
405
+ The main export includes:
406
+
407
+ | Exports | Purpose |
408
+ | ------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
409
+ | `memberDoc` | Vocabulary document containing access components and pacing metadata. |
410
+ | `MEMBER`, `GRANT`, `ACCESS`, `GOVERNED` | Component names and the list requiring owner permission. |
411
+ | `Role`, `Level`, `Mode`; `ROLES`, `LEVELS`, `MODES` | Value types and their supported values. |
412
+ | `role`, `level`, `mode` | Read a value with its default: member, viewer or private. |
413
+ | `reads`, `edits`, `callsOut`, `writes`, `reaches` | Pure permission checks. |
414
+ | `members(guard)` | Graph plugin with the vocabulary, permission-read requirements and write hook. |
415
+ | `guarding(guard)`, `wanting(guard)`, `actorOf`, `asks` | Write hook and supporting helpers. |
416
+ | `policy(storage, where)` | Read and write checks bound to storage. |
417
+ | `modeOn`, `levelOn`, `readsOn`, `writesOn` | Checks using an existing graph transaction. |
418
+ | `Guard`, `Floors`, `Viewer`, `Where`, `Policy` | Configuration and policy types. |
419
+ | `Denied` | Error with `actor`, `app`, `need` and `act` fields. |
420
+ | `owns(owner, who)`, `Owner` | Match verified `{by, via}` against a row's recorded owner; a bound person takes precedence over its instrument. |
421
+ | `memberKeywords`, `floorsIn`, `readersIn`, `shownIn`, `floored`, `conditioned`, `permitsIn`, `permitted`; `Permits` | Permission declarations, their validation and loaded forms. |
422
+ | `personal`, `personalsIn`, `unowned`; `Personal` | Person-owned policy, its validated declarations and their refusals. |
423
+ | `privacy`, `declarationsOf`, `kept`, `PRIVACY`; `Declared`, `Privacy` | Each entity's kept privacy: how it is reckoned, written, found stale and read. |
424
+
425
+ ## What is deliberately not here
426
+
427
+ Authentication belongs to the caller. App permissions, component floors and
428
+ person ownership are separate checks; this package supplies no per-grant query
429
+ filters. It supports exactly the `viewer`, `editor` and `owner` levels.
430
+
431
+ ## Integration
432
+
433
+ `members()` is a graph plugin. It uses the same storage and hook interfaces as
434
+ application plugins. [@yaks/api](../api) maps `Denied` errors to HTTP 403; a
435
+ caller can choose its own response policy.
436
+
437
+ ## Compatibility
438
+
439
+ Pure TypeScript with no platform API imports. It runs on Deno, Node, browsers
440
+ and Cloudflare Workers with suitable storage and package resolution.
441
+
442
+ ## Derived rows and source visibility
443
+
444
+ A server-generated row can inherit its source's personal visibility. Pass
445
+ `through: { page: 'source' }` to the plugin, where `page.source` references the
446
+ source entity, or call `personal(vocab, owners, { page: 'source' })` directly.
447
+ Reads, counts, reference traversal and relayed patches then follow the source's
448
+ current owner; changing that owner changes the derived row's visibility too.
449
+ This controls disclosure. It does not give a client permission to edit the
450
+ source or the derived row.
451
+
452
+ ## Each entity's privacy, kept
453
+
454
+ A vocabulary that loads this package's document keeps, on every entity wearing a
455
+ `personal`, inherited or `readers` component, what those declarations make of
456
+ it: `_privacy{person, shut, signed, floor, hash}` (./privacy.ts). `person` is
457
+ the one person it is kept to, `shut` says it is kept to nobody (it names more
458
+ than one person, or a page names no source), `signed` that a component asks its
459
+ readers to be signed in, `floor` the highest level one asks, and `hash` the
460
+ declarations it was reckoned under. The plugin writes it in the transaction that
461
+ changes what it is read from, and rewrites the entities that inherit from one
462
+ whose own part moved; a `_privacy` written by anyone else is put back.
463
+
464
+ A person's read is then screened by that one component, which @yaks/sql asks of
465
+ each row's owner in place: a derived property that reads many relations pays for
466
+ one join a relation, not for every declaration through every reference. A store
467
+ is read this way once it holds no entity whose privacy is missing or reckoned
468
+ under other declarations (`privacy(...).current`), and by the declarations
469
+ themselves until then, so a store written before it kept privacy, or one whose
470
+ declarations a deploy changed, is never read by a privacy it lacks. A pass over
471
+ `privacy(...).stale`, with `reckon`, brings it up to date; yaks.app runs one
472
+ from each app store's mover (workers/yak/ privacy-move.ts).
@@ -0,0 +1,4 @@
1
+ import { type Floor } from "./words.js";
2
+ /** What a component asks of its readers: a floor, or a query for each floor
3
+ * an entity wearing it asks when its bundle matches. */ export type Asked = Floor | Partial<Record<Floor, string>>;
4
+ //# sourceMappingURL=asking.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asking.d.ts","sources":["../asking.ts"],"names":[],"mappings":"AASA,SAAS,KAAK,KAAK,qBAA4C;AAE/D;sDACsD,GACtD,YAAY,QAAQ,QAAQ,QAAQ,OAAO,OAAO,MAAM"}
@@ -0,0 +1,14 @@
1
+ import type { VocabDoc } from "@yaks/vocab";
2
+ /** The name of the component recording one person's place on a space's
3
+ * roster. */ export declare let MEMBER: string;
4
+ /** The name of the component recording one principal's permission on one
5
+ * app. */ export declare let GRANT: string;
6
+ /** The name of the component carrying an app's access mode. */ export declare let ACCESS: string;
7
+ /** The components this package governs: only an owner may write one. */ export declare let GOVERNED: string[];
8
+ /**
9
+ * The membership vocabulary, to load beside your own:
10
+ * `loadVocab([memberDoc, ...mine])`. It declares nothing about what a space or
11
+ * an app is — both are plain entities in your own vocabulary — only who belongs
12
+ * to one and who may reach the other.
13
+ */ export declare let memberDoc: VocabDoc;
14
+ //# sourceMappingURL=comp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"comp.d.ts","sources":["../comp.ts"],"names":[],"mappings":"AAsBA,cAAc,QAAQ,2BAAgC;AAGtD;WACW,GACX,OAAO,YAAI,eAAiB;AAE5B;QACQ,GACR,OAAO,YAAI,cAAe;AAE1B,6DAA6D,GAC7D,OAAO,YAAI,eAAiB;AAE5B,sEAAsE,GACtE,OAAO,YAAI,UAAU,MAAM,GAM1B;AAED;;;;;CAKC,GACD,OAAO,YAAI,WAAW,SAAc"}
@@ -0,0 +1,19 @@
1
+ import type { Eid } from "@yaks/graph";
2
+ import type { Floor } from "./words.js";
3
+ /** An act the principal is not allowed to perform. The HTTP status is 403 when
4
+ * somebody is signed in and 401 when nobody is — which the HTTP layer knows and
5
+ * this error does not, so it carries the facts and leaves that choice there. */ export declare class Denied extends Error {
6
+ actor: Eid | null;
7
+ app: Eid;
8
+ need: Floor;
9
+ act: 'read' | 'write';
10
+ comp?: string;
11
+ /**
12
+ * @param actor who was acting, or `null` for an anonymous request
13
+ * @param app the app whose access rules refused it
14
+ * @param need the least that would have been enough: a level, or `person`
15
+ * @param act which of the two rules refused it (default: `write`)
16
+ * @param comp the component whose floor refused it, when one did
17
+ */ constructor(actor: Eid | null, app: Eid, need: Floor, act?: 'read' | 'write', comp?: string);
18
+ }
19
+ //# sourceMappingURL=deny.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deny.d.ts","sources":["../deny.ts"],"names":[],"mappings":"AAYA,cAAc,GAAG,2BAAgC;AACjD,cAAc,KAAK,qBAAoB;AAEvC;;8EAE8E,GAC9E,OAAO,cAAM,eAAe;EASjB,OAAO,MAAM,IAAI;EACjB,KAAK;EACL,MAAM;EACN,KAAK,SAAS;EACd,OAAO,MAAM;EAZtB;;;;;;GAMC,GACD,YACE,AAAO,OAAO,MAAM,IAAI,EACxB,AAAO,KAAK,GAAG,EACf,AAAO,MAAM,KAAK,EAClB,AAAO,MAAK,SAAS,OAAiB,EACtC,AAAO,OAAO,MAAM;AAaxB"}
@@ -0,0 +1,4 @@
1
+ import type { Host, Options } from "@yaks/host";
2
+ import type { Plugin } from "@yaks/graph";
3
+ /** Hosts choose protected components; apps can also declare personal aspects. */ export declare let plugins: (host: Pick<Host, 'vocab'>, options: Options) => Plugin[];
4
+ //# sourceMappingURL=graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.d.ts","sources":["../graph.ts"],"names":[],"mappings":"AACA,cAAc,IAAI,EAAE,OAAO,0BAA+B;AAC1D,cAAc,MAAM,2BAAgC;AAGpD,+EAA+E,GAC/E,OAAO,YAAI,UACT,MAAM,KAAK,MAAM,UACjB,SAAS,YACR,SAMF"}
@@ -0,0 +1,45 @@
1
+ import type { Actor, Ask, Bundle, Eid, Hook } from "@yaks/graph";
2
+ import type { Vocab } from "@yaks/vocab";
3
+ import { type Viewer, type Where } from "./policy.js";
4
+ import { type Instrument } from "./pace.js";
5
+ import { type Floors, type Level } from "./words.js";
6
+ /** Which app a guard decides for, and whose roster governs it. */ export type Guard = Where & {
7
+ /** the app this graph holds — its `access` mode decides a write by a
8
+ * principal that holds no level */ app: Eid;
9
+ /** the vocabulary the graph was loaded with, whose components' declared
10
+ * `floor` and `permit` (registered with `memberKeywords`) and `pace` hold here */ vocab: Vocab;
11
+ /** components that ask a floor of their own besides the ones the vocabulary
12
+ * declares — `{ product: 'editor' }` keeps a shop's prices its editors' on
13
+ * an `open` app, and wins over a declared one. The access rows ask `owner`
14
+ * whatever either says. */ floors?: Floors;
15
+ /** components a principal holding no writing level writes only inside a row
16
+ * of its own, each named with the reference to that row: `{ entry:
17
+ * 'session' }` keeps an `open` app's visitor writing lines in their own
18
+ * transcripts, where a line in someone else's would ask for a model's turn
19
+ * at the account's expense. A row created in the same batch is the
20
+ * principal's own. */ within?: Record<string, string>;
21
+ /** Current standing vouched by the receiving boundary. Null is an
22
+ * authoritative absence; undefined asks the stored roster. */ level?: (who: Viewer, writer: Actor) => Level | null | undefined;
23
+ /** Canonical identity of a vouched instrument, including stored identities
24
+ * retained while a host migrates its attribution. Defaults to exact eids. */ instrument?: Instrument;
25
+ /** the time pace is kept by, in ms (default: `Date.now`) */ now?: () => number;
26
+ };
27
+ /** The principal a signed transaction acts as: every bundle in it was signed by
28
+ * the same HTTP layer, so the first one carrying an `$actor` settles it for all
29
+ * of them. */ export declare let actorOf: (bundles: Bundle[]) => Viewer;
30
+ /**
31
+ * Everything the permission check is about to read, declared before it reads
32
+ * any of it: the app (its mode decides for a principal with no level), the
33
+ * principal's own entity (a share link's bearer is a grant), everything filed
34
+ * about the principal — their membership rows, their grants — and the rows the
35
+ * bundles name, whose byline says whose they are. @yaks/graph fetches these in
36
+ * one gather; companion permissions then read the stored reference targets in
37
+ * one additional batch.
38
+ */ export declare let wanting: (where: Guard) => any;
39
+ /**
40
+ * The `precondition` hook: refuse bundles this principal may not write.
41
+ * Registered by {@link https://jsr.io/@yaks/member/doc/~/members | members};
42
+ * exported on its own for a graph that wants the check without this package's
43
+ * components.
44
+ */ export declare let guarding: (where: Guard) => Hook;
45
+ //# sourceMappingURL=guard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guard.d.ts","sources":["../guard.ts"],"names":[],"mappings":"AA4CA,cAAc,KAAK,EAAE,GAAG,EAAE,MAAM,EAAQ,GAAG,EAAE,IAAI,2BAAoC;AAIrF,cAAc,KAAK,2BAAgC;AAGnD,SAA0B,KAAK,MAAM,EAAE,KAAK,KAAK,sBAAqB;AAGtE,SAAS,KAAK,UAAU,oBAAoC;AAC5D,SAAgB,KAAK,MAAM,EAAE,KAAK,KAAK,qBAAoC;AAE3E,gEAAgE,GAChE,YAAY,QAAQ;EAClB;mCACiC,GACjC,KAAK;EACL;kFACgF,GAChF,OAAO;EACP;;;2BAGyB,GACzB,SAAS;EACT;;;;;sBAKoB,GACpB,SAAS,OAAO,MAAM,EAAE,MAAM;EAC9B;8DAC4D,GAC5D,SAAS,KAAK,QAAQ,QAAQ,UAAU,QAAQ,IAAI,GAAG,SAAS;EAChE;6EAC2E,GAC3E,aAAa;EACb,0DAA0D,GAC1D,YAAY,MAAM;;AAGpB;;YAEY,GACZ,OAAO,YAAI,UAAW,SAAS,aAAW,OAMzC;AA6ID;;;;;;;;CAQC,GACD,OAAO,YAAI,UAAW,OAAO,cAU5B;AAED;;;;;CAKC,GACD,OAAO,YAAI,WAAY,OAAO,UAAQ,KA8DrC"}