@yaks/mail 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 (131) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +676 -2
  3. package/_dist/addr.d.ts +40 -0
  4. package/_dist/addr.d.ts.map +1 -0
  5. package/_dist/answers.d.ts +18 -0
  6. package/_dist/answers.d.ts.map +1 -0
  7. package/_dist/arrive.d.ts +64 -0
  8. package/_dist/arrive.d.ts.map +1 -0
  9. package/_dist/capture.d.ts +22 -0
  10. package/_dist/capture.d.ts.map +1 -0
  11. package/_dist/comp.d.ts +27 -0
  12. package/_dist/comp.d.ts.map +1 -0
  13. package/_dist/effects.d.ts +9 -0
  14. package/_dist/effects.d.ts.map +1 -0
  15. package/_dist/gmail.d.ts +16 -0
  16. package/_dist/gmail.d.ts.map +1 -0
  17. package/_dist/graph.d.ts +9 -0
  18. package/_dist/graph.d.ts.map +1 -0
  19. package/_dist/inbound.d.ts +105 -0
  20. package/_dist/inbound.d.ts.map +1 -0
  21. package/_dist/invite.d.ts +69 -0
  22. package/_dist/invite.d.ts.map +1 -0
  23. package/_dist/md.d.ts +34 -0
  24. package/_dist/md.d.ts.map +1 -0
  25. package/_dist/mod.d.ts +109 -0
  26. package/_dist/mod.d.ts.map +1 -0
  27. package/_dist/options.d.ts +38 -0
  28. package/_dist/options.d.ts.map +1 -0
  29. package/_dist/plugin.d.ts +38 -0
  30. package/_dist/plugin.d.ts.map +1 -0
  31. package/_dist/pull.d.ts +99 -0
  32. package/_dist/pull.d.ts.map +1 -0
  33. package/_dist/receipts.d.ts +8 -0
  34. package/_dist/receipts.d.ts.map +1 -0
  35. package/_dist/recipient.d.ts +24 -0
  36. package/_dist/recipient.d.ts.map +1 -0
  37. package/_dist/routes.d.ts +19 -0
  38. package/_dist/routes.d.ts.map +1 -0
  39. package/_dist/send.d.ts +80 -0
  40. package/_dist/send.d.ts.map +1 -0
  41. package/_dist/service.d.ts +14 -0
  42. package/_dist/service.d.ts.map +1 -0
  43. package/_dist/stash.d.ts +23 -0
  44. package/_dist/stash.d.ts.map +1 -0
  45. package/_dist/tools.d.ts +27 -0
  46. package/_dist/tools.d.ts.map +1 -0
  47. package/_dist/transport.d.ts +6 -0
  48. package/_dist/transport.d.ts.map +1 -0
  49. package/_dist/vocab.d.ts +7 -0
  50. package/_dist/vocab.d.ts.map +1 -0
  51. package/addr.js +92 -0
  52. package/addr.js.map +1 -0
  53. package/addr.ts +106 -0
  54. package/answers.js +71 -0
  55. package/answers.js.map +1 -0
  56. package/answers.ts +95 -0
  57. package/arrive.js +122 -0
  58. package/arrive.js.map +1 -0
  59. package/arrive.ts +198 -0
  60. package/capture.js +21 -0
  61. package/capture.js.map +1 -0
  62. package/capture.ts +43 -0
  63. package/comp.js +76 -0
  64. package/comp.js.map +1 -0
  65. package/comp.ts +91 -0
  66. package/deno.json +1 -0
  67. package/effects.js +90 -0
  68. package/effects.js.map +1 -0
  69. package/effects.ts +90 -0
  70. package/gmail.js +262 -0
  71. package/gmail.js.map +1 -0
  72. package/gmail.ts +314 -0
  73. package/graph.js +26 -0
  74. package/graph.js.map +1 -0
  75. package/graph.ts +30 -0
  76. package/inbound.js +206 -0
  77. package/inbound.js.map +1 -0
  78. package/inbound.ts +238 -0
  79. package/invite.js +102 -0
  80. package/invite.js.map +1 -0
  81. package/invite.ts +143 -0
  82. package/md.js +188 -0
  83. package/md.js.map +1 -0
  84. package/md.ts +245 -0
  85. package/mod.js +109 -0
  86. package/mod.js.map +1 -0
  87. package/mod.ts +111 -0
  88. package/options.js +24 -0
  89. package/options.js.map +1 -0
  90. package/options.ts +83 -0
  91. package/package.json +66 -4
  92. package/plugin.js +97 -0
  93. package/plugin.js.map +1 -0
  94. package/plugin.ts +88 -0
  95. package/pull.js +344 -0
  96. package/pull.js.map +1 -0
  97. package/pull.ts +443 -0
  98. package/readings.js +24 -0
  99. package/readings.js.map +1 -0
  100. package/readings.ts +34 -0
  101. package/receipts.js +45 -0
  102. package/receipts.js.map +1 -0
  103. package/receipts.ts +45 -0
  104. package/recipient.js +92 -0
  105. package/recipient.js.map +1 -0
  106. package/recipient.ts +89 -0
  107. package/routes.js +103 -0
  108. package/routes.js.map +1 -0
  109. package/routes.ts +125 -0
  110. package/send.js +284 -0
  111. package/send.js.map +1 -0
  112. package/send.ts +325 -0
  113. package/service.js +64 -0
  114. package/service.js.map +1 -0
  115. package/service.ts +75 -0
  116. package/stash.js +29 -0
  117. package/stash.js.map +1 -0
  118. package/stash.ts +49 -0
  119. package/tools.js +343 -0
  120. package/tools.js.map +1 -0
  121. package/tools.ts +416 -0
  122. package/transport.js +23 -0
  123. package/transport.js.map +1 -0
  124. package/transport.ts +24 -0
  125. package/vocab.js +14 -0
  126. package/vocab.js.map +1 -0
  127. package/vocab.json +415 -0
  128. package/vocab.ts +16 -0
  129. package/work.js +121 -0
  130. package/work.js.map +1 -0
  131. package/work.ts +134 -0
package/vocab.json ADDED
@@ -0,0 +1,415 @@
1
+ {
2
+ "$id": "urn:uuid:9943b3f1-54f6-408b-808b-ea7e402a6aa1",
3
+ "title": "mail",
4
+ "$defs": {
5
+ "mail": {
6
+ "$id": "urn:uuid:ea7b9af6-9fd2-4d87-a0ab-ae7d635d1e4f",
7
+ "component": true,
8
+ "type": "object",
9
+ "description": "one letter's envelope, sent or received; in an app, read only by its owners and editors, whatever the app's access",
10
+ "readers": "editor",
11
+ "properties": {
12
+ "from": {
13
+ "$id": "urn:uuid:b695e16e-a49b-4879-911d-86b39e4412ce",
14
+ "type": "string",
15
+ "description": "the address it came from",
16
+ "examples": [
17
+ "ann@example.com"
18
+ ]
19
+ },
20
+ "connection": {
21
+ "$id": "urn:uuid:fa5dd0b5-540b-4073-a821-c5490a087928",
22
+ "type": "string",
23
+ "stamped": true,
24
+ "description": "The space connection that sends or receives this letter, stamped by the host."
25
+ },
26
+ "name": {
27
+ "$id": "urn:uuid:7c56e771-49d8-459a-ae95-fadbf306c232",
28
+ "type": "string",
29
+ "description": "the name it is from, as the reader's mail shows it beside the address",
30
+ "examples": [
31
+ "Ann at the Book Club"
32
+ ]
33
+ },
34
+ "to": {
35
+ "$id": "urn:uuid:7ec2ee9f-14ca-4b3c-b041-affe7cab95d7",
36
+ "type": "string",
37
+ "description": "the address it is written to — absent when `deliver.to` names the recipient as an entity instead",
38
+ "examples": [
39
+ "bob@example.com"
40
+ ]
41
+ },
42
+ "cc": {
43
+ "$id": "urn:uuid:cc6156c4-79d4-40ad-872a-83cd584b10c2",
44
+ "type": "string",
45
+ "description": "the address copied on it",
46
+ "examples": [
47
+ "ann@example.com"
48
+ ]
49
+ },
50
+ "at": {
51
+ "$id": "urn:uuid:2b6c05d4-df97-4018-8fc1-6fa9e6f6a81b",
52
+ "type": "string",
53
+ "format": "date-time",
54
+ "description": "when it was written, or when it arrived"
55
+ },
56
+ "target": {
57
+ "$id": "urn:uuid:fbc22496-2d05-4369-9415-ba287a54b423",
58
+ "type": "string",
59
+ "ref": "entity",
60
+ "death": "keep",
61
+ "description": "the entity this letter is about — any entity at all, so correspondence hangs off the thing it concerns"
62
+ },
63
+ "reply_to": {
64
+ "$id": "urn:uuid:6dcf9533-fe48-4778-9e4a-070a0209c64b",
65
+ "type": "string",
66
+ "ref": "mail",
67
+ "death": "keep",
68
+ "description": "the letter this one answers"
69
+ },
70
+ "message_id": {
71
+ "$id": "urn:uuid:cf9c5728-970c-46fe-83d4-046ef7cb730a",
72
+ "type": "string",
73
+ "description": "the Message-ID other mail systems know this letter by — read from a letter that arrived, or returned by the sender for one that left — and what a reply threads on"
74
+ },
75
+ "verified": {
76
+ "$id": "urn:uuid:3ca7f8ed-7d3f-4bc1-bb57-2fea67939e3a",
77
+ "type": "boolean",
78
+ "description": "whether the sending domain signed for this letter (DKIM) — false is recorded, never dropped: a letter nobody signed for is still a letter, and the reader is the one who decides what to trust"
79
+ },
80
+ "in_reply_to": {
81
+ "$id": "urn:uuid:463d981f-1429-4310-a3f0-dbf6f4bc2ea4",
82
+ "type": "string",
83
+ "description": "the Message-ID this letter answers, exactly as the header wrote it — what arrives before `reply_to` can name an entity, and all a reply to a letter nobody kept ever has"
84
+ },
85
+ "reply_address": {
86
+ "$id": "urn:uuid:13a515d3-c9ef-4e1e-8447-d6e121b545cc",
87
+ "type": "string",
88
+ "description": "where an answer to this letter goes: for one that arrived, its `Reply-To:` header; for one we send, the `Reply-To:` it leaves with. Absent, an answer goes to `from`",
89
+ "examples": [
90
+ "ana@example.com"
91
+ ]
92
+ }
93
+ }
94
+ },
95
+ "email": {
96
+ "$id": "urn:uuid:2bce8bee-e883-4f1e-a594-1490172c29ba",
97
+ "component": true,
98
+ "type": "object",
99
+ "description": "an address, as an entity — what a person is reachable at",
100
+ "properties": {
101
+ "address": {
102
+ "$id": "urn:uuid:5d5f9bd6-6b15-400f-8c26-76d5c88148ba",
103
+ "type": "string",
104
+ "description": "the address itself, canonical (see canon)",
105
+ "index": true
106
+ }
107
+ }
108
+ },
109
+ "recipient": {
110
+ "$id": "urn:uuid:370fb148-e602-40d9-90f5-d8422a8f098a",
111
+ "component": true,
112
+ "type": "object",
113
+ "description": "this address is on file only because a letter is for it, and nothing else about it is; in an app, read only by its owners and editors, whatever the app's access — the platform writes it when a letter's `deliver.to` names such an address, as a letter is kept by `mail`",
114
+ "readers": "editor"
115
+ },
116
+ "deliver": {
117
+ "$id": "urn:uuid:715e5e0e-a87e-4471-b619-ed940c71f7a3",
118
+ "component": true,
119
+ "type": "object",
120
+ "description": "who a letter is for, as an entity in your graph",
121
+ "properties": {
122
+ "to": {
123
+ "$id": "urn:uuid:5e1dd3aa-6fad-4da4-844e-fb9850a47660",
124
+ "type": "string",
125
+ "ref": "entity",
126
+ "death": "keep",
127
+ "description": "the recipient — their address is looked up when the letter goes out"
128
+ },
129
+ "waiting": {
130
+ "$id": "urn:uuid:6880c202-c715-4b46-b7d9-dd155e357c00",
131
+ "type": "string",
132
+ "stamped": true,
133
+ "description": "why an outbound letter cannot reach a sender yet; cleared before it is handed over"
134
+ },
135
+ "tried": {
136
+ "$id": "urn:uuid:ca94c1b1-b5f7-4c27-8956-baa61fcd3b08",
137
+ "type": "string",
138
+ "format": "date-time",
139
+ "stamped": true,
140
+ "description": "when the letter was handed to the sender — one with this and no outcome may have left, so it is never handed over again"
141
+ }
142
+ }
143
+ },
144
+ "delivered": {
145
+ "$id": "urn:uuid:e99b7661-ed9e-4ab4-b839-8e7e882a925c",
146
+ "component": true,
147
+ "journal": false,
148
+ "type": "object",
149
+ "description": "the letter left: half of the outcome pair",
150
+ "properties": {
151
+ "at": {
152
+ "$id": "urn:uuid:e222c090-615a-4c81-aaed-381aeb26f2da",
153
+ "type": "string",
154
+ "format": "date-time",
155
+ "stamped": true,
156
+ "description": "when it went"
157
+ },
158
+ "channel": {
159
+ "$id": "urn:uuid:816bd91c-2607-4b85-a5d8-79f60c3ff76a",
160
+ "type": "string",
161
+ "description": "the delivery channel, when delivery can take more than one route"
162
+ }
163
+ }
164
+ },
165
+ "bounced": {
166
+ "$id": "urn:uuid:a7e30c56-36c1-4a63-a962-b8f3af1c0112",
167
+ "component": true,
168
+ "journal": false,
169
+ "type": "object",
170
+ "description": "the letter did not leave: the other half",
171
+ "properties": {
172
+ "at": {
173
+ "$id": "urn:uuid:dac2a8aa-1dec-47e9-8d30-9871eb34258d",
174
+ "type": "string",
175
+ "format": "date-time",
176
+ "stamped": true,
177
+ "description": "when the attempt failed"
178
+ },
179
+ "reason": {
180
+ "$id": "urn:uuid:3eb6a446-a0c2-4988-bf5c-6925991e7d2a",
181
+ "type": "string",
182
+ "stamped": true,
183
+ "description": "what went wrong, as the sender reported it"
184
+ },
185
+ "refused": {
186
+ "$id": "urn:uuid:33356c11-9352-4de1-8679-70509c02205f",
187
+ "type": "boolean",
188
+ "stamped": true,
189
+ "description": "the provider refused an address on the letter: the address is the writer's to fix, and nothing failed"
190
+ }
191
+ }
192
+ },
193
+ "notified": {
194
+ "$id": "urn:uuid:6c8a44d7-a3e3-47a9-974a-5635589ce1a1",
195
+ "component": true,
196
+ "journal": false,
197
+ "type": "object",
198
+ "description": "a recipient was told about something",
199
+ "properties": {
200
+ "at": {
201
+ "$id": "urn:uuid:d7d75429-759c-4fe6-acd2-5a998562bf98",
202
+ "type": "string",
203
+ "format": "date-time",
204
+ "stamped": true,
205
+ "description": "when they were told"
206
+ },
207
+ "by": {
208
+ "$id": "urn:uuid:4b9d8cb3-d8f2-412e-8148-8cbb6eea176a",
209
+ "type": "string",
210
+ "ref": "entity",
211
+ "death": "keep",
212
+ "stamped": true,
213
+ "description": "who told them"
214
+ },
215
+ "via": {
216
+ "$id": "urn:uuid:58aaebc3-9d98-4ed0-8195-fa092e7b8481",
217
+ "type": "string",
218
+ "ref": "entity",
219
+ "death": "keep",
220
+ "stamped": true,
221
+ "description": "what carried it"
222
+ }
223
+ }
224
+ },
225
+ "mail_show": {
226
+ "tool": true,
227
+ "page": true,
228
+ "destructive": false,
229
+ "noun": "mail",
230
+ "verb": "show",
231
+ "title": "Read a mail message",
232
+ "step": {
233
+ "doing": "Reading an email…",
234
+ "done": "Read an email"
235
+ },
236
+ "description": "Return one mail message in full: its headers, its body, and one-line summaries of the rest of its thread, with this message marked. The text is returned in content.body alongside the opened mark. Reading marks the caller's subscription to the thread opened, which is why this tool writes where graph_show only reads.",
237
+ "input": {
238
+ "letter": {
239
+ "type": "string",
240
+ "ref": "mail",
241
+ "description": "the message to read; pass its id or registered name"
242
+ }
243
+ },
244
+ "required": [
245
+ "letter"
246
+ ],
247
+ "idempotent": true,
248
+ "positional": [
249
+ "letter"
250
+ ]
251
+ },
252
+ "mail_reply": {
253
+ "tool": true,
254
+ "noun": "mail",
255
+ "verb": "reply",
256
+ "title": "Reply to a mail message",
257
+ "step": {
258
+ "doing": "Replying to an email…",
259
+ "done": "Replied to an email"
260
+ },
261
+ "description": "Write a reply threaded on one message and request that it be sent. It is addressed to the other side of the original (the sender of a received message, or the recipient of one you sent) from the address the original used, with the subject prefixed `Re:`. Replying to a received message archives the caller's subscription to its thread: a thread you have answered is not waiting on you. The configured sender delivers it; a graph with no sender configured records the reply and never sends it. Returns the applied bundles: JSON objects with entity ids and the components (named groups of fields) written or removed. Confirm the recipient and message before requesting delivery; a sent email cannot be recalled.",
262
+ "input": {
263
+ "letter": {
264
+ "type": "string",
265
+ "ref": "mail",
266
+ "description": "the message being replied to; pass its id or registered name"
267
+ },
268
+ "body": {
269
+ "type": "string",
270
+ "description": "the text of the reply",
271
+ "short": "b"
272
+ }
273
+ },
274
+ "required": [
275
+ "letter",
276
+ "body"
277
+ ],
278
+ "openWorld": true,
279
+ "positional": [
280
+ "letter",
281
+ "body"
282
+ ]
283
+ },
284
+ "mail_send": {
285
+ "tool": true,
286
+ "noun": "mail",
287
+ "verb": "send",
288
+ "title": "Send a mail message",
289
+ "step": {
290
+ "doing": "Sending an email…",
291
+ "done": "Sent an email"
292
+ },
293
+ "description": "Create a mail message and request that it be sent. It sends from an address this graph holds, through the graph’s own sender, and never from a person’s own mail account: asked to email someone with nothing here named, use whatever mail tool the person has connected. `to` is an email address or the id of an entity in this graph; an address nobody in the graph has becomes a new `email` entity, so the address book grows as mail is sent. `from` defaults to the email address of the entity it is `about`, such as a project’s own, so the answer comes back to that entity; otherwise to the caller’s own email address. Without a configured sender, the message is recorded but not sent. A configured sender delivers it asynchronously and writes `delivered` or `bounced` onto the message. Returns the applied bundles: JSON objects with entity ids and the components (named groups of fields) written or removed. Confirm the recipient and message before requesting delivery; a sent email cannot be recalled. The initial result is not a delivery receipt; read the message again to check its outcome.",
294
+ "input": {
295
+ "to": {
296
+ "type": "string",
297
+ "description": "an email address, or the id of the entity it is for"
298
+ },
299
+ "subject": {
300
+ "type": "string",
301
+ "description": "the subject line"
302
+ },
303
+ "body": {
304
+ "type": "string",
305
+ "description": "the text of the message",
306
+ "short": "b"
307
+ },
308
+ "from": {
309
+ "type": "string",
310
+ "description": "the address it is sent from (default: the address of what it is about, else the caller’s own)"
311
+ },
312
+ "about": {
313
+ "type": "string",
314
+ "ref": "entity",
315
+ "description": "the entity this message is about, so the correspondence is attached to it; pass its id or registered name"
316
+ }
317
+ },
318
+ "required": [
319
+ "to",
320
+ "subject",
321
+ "body"
322
+ ],
323
+ "openWorld": true,
324
+ "positional": [
325
+ "to",
326
+ "subject"
327
+ ]
328
+ },
329
+ "mail_check": {
330
+ "tool": true,
331
+ "noun": "mail",
332
+ "verb": "check",
333
+ "title": "Check the mail",
334
+ "step": {
335
+ "doing": "Checking for new email…",
336
+ "done": "Checked for new email"
337
+ },
338
+ "description": "Check that every received mail message has a sender. Also reports incomplete configuration for a sender this server has configured. A message with a Message-ID but no `from` can never be answered, since a reply has no address to go to. Takes no arguments. Returns a report in content.body, with warning or failure findings when present; it does not repair the records or configuration.",
339
+ "input": {},
340
+ "readOnly": true
341
+ },
342
+ "mail_post": {
343
+ "effect": true,
344
+ "created": [
345
+ "mail",
346
+ "deliver"
347
+ ],
348
+ "tries": 6,
349
+ "description": "Hand an outbound letter to the sender and record its outcome. A send the sender knows never left is tried again; an unavailable configured sender defers its recorded run."
350
+ },
351
+ "mail_task": {
352
+ "effect": true,
353
+ "created": [
354
+ "mail"
355
+ ],
356
+ "target": ".mail !deliver",
357
+ "option": "local",
358
+ "description": "File a letter that arrived for a project, or for an address filed under one, as a task in that project, linked to the letter by an about edge, so it waits on the board until it is answered."
359
+ },
360
+ "mail_answered": {
361
+ "effect": true,
362
+ "created": [
363
+ "delivered"
364
+ ],
365
+ "target": ".mail.reply_to | .mail.target",
366
+ "option": "local",
367
+ "description": "Complete the task a letter filed once this graph has delivered a letter answering it: its reply, or one sent about it."
368
+ },
369
+ "mail_dismissed": {
370
+ "effect": true,
371
+ "created": [
372
+ "cancelled"
373
+ ],
374
+ "target": ".task",
375
+ "option": "local",
376
+ "description": "Archive the letter whose task was cancelled, with the cancel's time and actor: cancelling a letter's task says it needs no answer, so it leaves the unanswered list."
377
+ }
378
+ },
379
+ "kinds": {
380
+ "mail": {
381
+ "$id": "urn:uuid:ea7b9af6-9fd2-4d87-a0ab-ae7d635d1e4f",
382
+ "description": "one letter's envelope, sent or received; in an app, read only by its owners and editors, whatever the app's access",
383
+ "with": {
384
+ "doc": true
385
+ },
386
+ "prefix": "E",
387
+ "examples": [
388
+ {
389
+ "mail": {
390
+ "from": "ada@example.com"
391
+ },
392
+ "doc": {
393
+ "title": "Lunch on Friday",
394
+ "body": "Noon at the usual place?"
395
+ },
396
+ "deliver": {
397
+ "to": "bea@example.com"
398
+ }
399
+ }
400
+ ]
401
+ },
402
+ "email": {
403
+ "$id": "urn:uuid:2bce8bee-e883-4f1e-a594-1490172c29ba",
404
+ "description": "an address, as an entity — what a person is reachable at",
405
+ "prefix": "A",
406
+ "examples": [
407
+ {
408
+ "email": {
409
+ "address": "ada@example.com"
410
+ }
411
+ }
412
+ ]
413
+ }
414
+ }
415
+ }
package/vocab.ts ADDED
@@ -0,0 +1,16 @@
1
+ // The mail components, and only those: the `@yaks/mail/vocab` entry point. It
2
+ // imports no storage, no SQL and no runtime, so a browser tab that loads this
3
+ // vocabulary loads nothing else.
4
+
5
+ import type { VocabDoc } from 'jsr:@yaks/vocab@0.2.36'
6
+ import { mailDoc } from './comp.js'
7
+ import manifest from './package.json' with { type: 'json' }
8
+
9
+ export { mailDoc }
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 document this plugin declares. */
16
+ export let docs: VocabDoc[] = [mailDoc]
package/work.js ADDED
@@ -0,0 +1,121 @@
1
+ // A letter that reaches a project is work for it, the way a bug the tracker
2
+ // opens is (@yaks/heal files a task for each). Hearing it is not enough: a
3
+ // session of the project hears an arrival once on its bus (@yaks/session) and
4
+ // marks it `notified`, and a session that heard it and went on with other work
5
+ // left nothing behind that says a person is still waiting. So the arrival
6
+ // files a task in the project, which stays open on its board until an answer
7
+ // goes out or an agent closes it.
8
+ //
9
+ // mail_task an arrival to a project, or to an address filed under one
10
+ // (hello@yaks.app under yaks.app), files `task{}` +
11
+ // `doc{title, body}` + `filed{project, priority}`, linked to
12
+ // the letter by an `about` edge
13
+ // mail_answered a letter this graph delivered about it (./answers.ts
14
+ // `answering`: its reply, or one sent about it) completes
15
+ // the task the letter filed
16
+ // mail_dismissed the letter's task cancelled says the letter needs no
17
+ // answer, so the letter is archived (`archived{at, by, via}`
18
+ // copied from the cancel), which takes it off the unanswered
19
+ // list (`yak admin errors`)
20
+ //
21
+ // All three are declared under the `local` option: a graph whose addresses are
22
+ // entities that read it (an agent, a project) is one where a letter is work
23
+ // for whoever works here; where a person reads the mail in a mail client, the
24
+ // mailbox is the destination and files nothing.
25
+ //
26
+ // The task's eid derives from the letter, so a run interrupted and run again
27
+ // finds the task it wrote, and the reply finds the task to complete without a
28
+ // search. Every word is the vocabulary's to declare: a graph without tasks,
29
+ // projects or edges files nothing, or files without the link.
30
+ import { line } from "@yaks/query";
31
+ import { identityEid } from "@yaks/graph/identity";
32
+ import { link } from "@yaks/edge";
33
+ import { DELIVER, DELIVERED, EMAIL, MAIL } from "./comp.js";
34
+ import { answering } from "./answers.js";
35
+ /** The task a letter filed: derived from the letter, so it is found again. */ export let taskEid = (letter)=>identityEid('mail_task', [
36
+ letter
37
+ ]);
38
+ let comp = (b, name)=>b?.[name] ?? {};
39
+ let str = (v)=>typeof v == 'string' ? v : '';
40
+ let one = async (tx, eid)=>eid ? (await tx.get([
41
+ eid
42
+ ]))[0] : undefined;
43
+ /** The project a letter reached: its target when that is a project, or the
44
+ * project the target's address is filed under. */ let projectOf = async (tx, target)=>{
45
+ let to = await one(tx, target);
46
+ if (!to) return '';
47
+ if (to.project) return target;
48
+ return to[EMAIL] ? str(comp(to, 'filed').project) : '';
49
+ };
50
+ /** The task a letter files, for an agent to answer it. */ let filing = (letter, project)=>{
51
+ let eid = letter.entity.eid;
52
+ let mail = comp(letter, MAIL);
53
+ let from = str(mail.reply_address) || str(mail.from);
54
+ let subject = str(comp(letter, 'doc').title).split('\n')[0] || '(no subject)';
55
+ return [
56
+ {
57
+ entity: {
58
+ eid: taskEid(eid)
59
+ },
60
+ task: {},
61
+ doc: {
62
+ title: `Letter from ${from || 'someone'}: ${subject.length > 160 ? `${subject.slice(0, 160)}…` : subject}`,
63
+ body: `A letter${from ? ` from ${from}` : ''} reached this project. ` + `Read it with \`yak mail show ${eid}\`. A reply (\`yak mail ` + 'reply`) or a letter sent `--about` it completes this task. An ' + 'answer given where the letter asks for one instead, such as a ' + 'support thread it names, does not, so complete the task once it is ' + 'given. When the letter needs no answer, cancel this task: that ' + 'archives the letter.'
64
+ },
65
+ filed: {
66
+ project,
67
+ priority: 1
68
+ }
69
+ }
70
+ ];
71
+ };
72
+ /** `mail_task`, `mail_answered` and `mail_dismissed`, for a graph whose vocabulary has tasks
73
+ * filed under projects; under any other, neither does anything. */ export let work = (vocab)=>({
74
+ mail_task: async (event, tx, write)=>{
75
+ if (!vocab?.comp('task') || !vocab.prop('filed', 'project')) return;
76
+ let letter = await one(tx, event.entity.eid);
77
+ if (!letter?.[MAIL] || letter[DELIVER]) return;
78
+ let project = await projectOf(tx, str(comp(letter, MAIL).target));
79
+ if (!project || await one(tx, taskEid(letter.entity.eid))) return;
80
+ let linked = vocab.comp('edge') && vocab.comp('about');
81
+ await write([
82
+ ...filing(letter, project),
83
+ ...linked ? [
84
+ link(taskEid(letter.entity.eid), 'about', event.entity.eid)
85
+ ] : []
86
+ ]);
87
+ },
88
+ mail_answered: async (event, tx, write)=>{
89
+ let reply = await one(tx, event.entity.eid);
90
+ if (!reply?.[DELIVER] || !reply[DELIVERED]) return;
91
+ let tasks = await Promise.all(answering(reply).map((letter)=>one(tx, taskEid(letter))));
92
+ let open = tasks.filter((t)=>t?.task && !t.completed && !t.cancelled);
93
+ if (open.length) {
94
+ await write(open.map((t)=>({
95
+ entity: t.entity,
96
+ completed: {}
97
+ })));
98
+ }
99
+ },
100
+ mail_dismissed: async (event, tx, write)=>{
101
+ if (!vocab?.comp('archived') || !vocab.comp('about')) return;
102
+ let task = await one(tx, event.entity.eid);
103
+ let cancelled = task?.cancelled;
104
+ if (!cancelled) return;
105
+ let links = await tx.read(line`.about&.edge.from=${task.entity.eid}`);
106
+ let letters = await tx.get(links.map((l)=>str(comp(l, 'edge').to)).filter((to)=>taskEid(to) == task.entity.eid));
107
+ let waiting = letters.filter((l)=>l?.[MAIL] && !l.archived);
108
+ if (waiting.length) {
109
+ let { at, by, via } = cancelled;
110
+ await write(waiting.map((l)=>({
111
+ entity: l.entity,
112
+ archived: Object.fromEntries(Object.entries({
113
+ at,
114
+ by,
115
+ via
116
+ }).filter(([, v])=>v != undefined))
117
+ })));
118
+ }
119
+ }
120
+ });
121
+ //# sourceMappingURL=work.js.map
package/work.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"work.js","sources":["./work.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,2EAA2E;AAC3E,8EAA8E;AAC9E,+EAA+E;AAC/E,0EAA0E;AAC1E,6EAA6E;AAC7E,kCAAkC;AAClC,EAAE;AACF,6EAA6E;AAC7E,qEAAqE;AACrE,8EAA8E;AAC9E,iDAAiD;AACjD,wEAAwE;AACxE,2EAA2E;AAC3E,6CAA6C;AAC7C,wEAAwE;AACxE,8EAA8E;AAC9E,8EAA8E;AAC9E,6CAA6C;AAC7C,EAAE;AACF,+EAA+E;AAC/E,4EAA4E;AAC5E,8EAA8E;AAC9E,gDAAgD;AAChD,EAAE;AACF,6EAA6E;AAC7E,8EAA8E;AAC9E,4EAA4E;AAC5E,8DAA8D;AAE9D,SAAS,IAAI,2BAAgC;AAI7C,SAAS,WAAW,oCAAyC;AAC7D,SAAS,IAAI,0BAA+B;AAC5C,SAAS,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,oBAAmB;AAC3D,SAAS,SAAS,uBAAsB;AAExC,4EAA4E,GAC5E,OAAO,IAAI,UAAU,CAAC,SAAqB,YAAY,aAAa;IAAC;GAAO,EAAC;AAE7E,IAAI,OAAO,CAAC,GAAuB,OAChC,GA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