@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.
- package/LICENSE +202 -0
- package/README.md +676 -2
- package/_dist/addr.d.ts +40 -0
- package/_dist/addr.d.ts.map +1 -0
- package/_dist/answers.d.ts +18 -0
- package/_dist/answers.d.ts.map +1 -0
- package/_dist/arrive.d.ts +64 -0
- package/_dist/arrive.d.ts.map +1 -0
- package/_dist/capture.d.ts +22 -0
- package/_dist/capture.d.ts.map +1 -0
- package/_dist/comp.d.ts +27 -0
- package/_dist/comp.d.ts.map +1 -0
- package/_dist/effects.d.ts +9 -0
- package/_dist/effects.d.ts.map +1 -0
- package/_dist/gmail.d.ts +16 -0
- package/_dist/gmail.d.ts.map +1 -0
- package/_dist/graph.d.ts +9 -0
- package/_dist/graph.d.ts.map +1 -0
- package/_dist/inbound.d.ts +105 -0
- package/_dist/inbound.d.ts.map +1 -0
- package/_dist/invite.d.ts +69 -0
- package/_dist/invite.d.ts.map +1 -0
- package/_dist/md.d.ts +34 -0
- package/_dist/md.d.ts.map +1 -0
- package/_dist/mod.d.ts +109 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/options.d.ts +38 -0
- package/_dist/options.d.ts.map +1 -0
- package/_dist/plugin.d.ts +38 -0
- package/_dist/plugin.d.ts.map +1 -0
- package/_dist/pull.d.ts +99 -0
- package/_dist/pull.d.ts.map +1 -0
- package/_dist/receipts.d.ts +8 -0
- package/_dist/receipts.d.ts.map +1 -0
- package/_dist/recipient.d.ts +24 -0
- package/_dist/recipient.d.ts.map +1 -0
- package/_dist/routes.d.ts +19 -0
- package/_dist/routes.d.ts.map +1 -0
- package/_dist/send.d.ts +80 -0
- package/_dist/send.d.ts.map +1 -0
- package/_dist/service.d.ts +14 -0
- package/_dist/service.d.ts.map +1 -0
- package/_dist/stash.d.ts +23 -0
- package/_dist/stash.d.ts.map +1 -0
- package/_dist/tools.d.ts +27 -0
- package/_dist/tools.d.ts.map +1 -0
- package/_dist/transport.d.ts +6 -0
- package/_dist/transport.d.ts.map +1 -0
- package/_dist/vocab.d.ts +7 -0
- package/_dist/vocab.d.ts.map +1 -0
- package/addr.js +92 -0
- package/addr.js.map +1 -0
- package/addr.ts +106 -0
- package/answers.js +71 -0
- package/answers.js.map +1 -0
- package/answers.ts +95 -0
- package/arrive.js +122 -0
- package/arrive.js.map +1 -0
- package/arrive.ts +198 -0
- package/capture.js +21 -0
- package/capture.js.map +1 -0
- package/capture.ts +43 -0
- package/comp.js +76 -0
- package/comp.js.map +1 -0
- package/comp.ts +91 -0
- package/deno.json +1 -0
- package/effects.js +90 -0
- package/effects.js.map +1 -0
- package/effects.ts +90 -0
- package/gmail.js +262 -0
- package/gmail.js.map +1 -0
- package/gmail.ts +314 -0
- package/graph.js +26 -0
- package/graph.js.map +1 -0
- package/graph.ts +30 -0
- package/inbound.js +206 -0
- package/inbound.js.map +1 -0
- package/inbound.ts +238 -0
- package/invite.js +102 -0
- package/invite.js.map +1 -0
- package/invite.ts +143 -0
- package/md.js +188 -0
- package/md.js.map +1 -0
- package/md.ts +245 -0
- package/mod.js +109 -0
- package/mod.js.map +1 -0
- package/mod.ts +111 -0
- package/options.js +24 -0
- package/options.js.map +1 -0
- package/options.ts +83 -0
- package/package.json +66 -4
- package/plugin.js +97 -0
- package/plugin.js.map +1 -0
- package/plugin.ts +88 -0
- package/pull.js +344 -0
- package/pull.js.map +1 -0
- package/pull.ts +443 -0
- package/readings.js +24 -0
- package/readings.js.map +1 -0
- package/readings.ts +34 -0
- package/receipts.js +45 -0
- package/receipts.js.map +1 -0
- package/receipts.ts +45 -0
- package/recipient.js +92 -0
- package/recipient.js.map +1 -0
- package/recipient.ts +89 -0
- package/routes.js +103 -0
- package/routes.js.map +1 -0
- package/routes.ts +125 -0
- package/send.js +284 -0
- package/send.js.map +1 -0
- package/send.ts +325 -0
- package/service.js +64 -0
- package/service.js.map +1 -0
- package/service.ts +75 -0
- package/stash.js +29 -0
- package/stash.js.map +1 -0
- package/stash.ts +49 -0
- package/tools.js +343 -0
- package/tools.js.map +1 -0
- package/tools.ts +416 -0
- package/transport.js +23 -0
- package/transport.js.map +1 -0
- package/transport.ts +24 -0
- package/vocab.js +14 -0
- package/vocab.js.map +1 -0
- package/vocab.json +415 -0
- package/vocab.ts +16 -0
- package/work.js +121 -0
- package/work.js.map +1 -0
- package/work.ts +134 -0
package/work.ts
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
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
|
+
|
|
31
|
+
import { line } from '@yaks/query'
|
|
32
|
+
import type { Bundle, Comp, Eid, ReadTx } from 'jsr:@yaks/graph@0.2.36'
|
|
33
|
+
import type { Handlers } from 'jsr:@yaks/effects@0.2.36'
|
|
34
|
+
import type { Vocab } from 'jsr:@yaks/vocab@0.2.36'
|
|
35
|
+
import { identityEid } from '@yaks/graph/identity'
|
|
36
|
+
import { link } from '@yaks/edge'
|
|
37
|
+
import { DELIVER, DELIVERED, EMAIL, MAIL } from './comp.js'
|
|
38
|
+
import { answering } from './answers.js'
|
|
39
|
+
|
|
40
|
+
/** The task a letter filed: derived from the letter, so it is found again. */
|
|
41
|
+
export let taskEid = (letter: Eid): Eid => identityEid('mail_task', [letter])
|
|
42
|
+
|
|
43
|
+
let comp = (b: Bundle | undefined, name: string): Comp =>
|
|
44
|
+
(b?.[name] ?? {}) as Comp
|
|
45
|
+
let str = (v: unknown): string => typeof v == 'string' ? v : ''
|
|
46
|
+
let one = async (tx: ReadTx, eid: string): Promise<Bundle | undefined> =>
|
|
47
|
+
eid ? (await tx.get([eid]))[0] : undefined
|
|
48
|
+
|
|
49
|
+
/** The project a letter reached: its target when that is a project, or the
|
|
50
|
+
* project the target's address is filed under. */
|
|
51
|
+
let projectOf = async (tx: ReadTx, target: string): Promise<string> => {
|
|
52
|
+
let to = await one(tx, target)
|
|
53
|
+
if (!to) return ''
|
|
54
|
+
if (to.project) return target
|
|
55
|
+
return to[EMAIL] ? str(comp(to, 'filed').project) : ''
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The task a letter files, for an agent to answer it. */
|
|
59
|
+
let filing = (letter: Bundle, project: Eid): Bundle[] => {
|
|
60
|
+
let eid = letter.entity.eid
|
|
61
|
+
let mail = comp(letter, MAIL)
|
|
62
|
+
let from = str(mail.reply_address) || str(mail.from)
|
|
63
|
+
let subject = str(comp(letter, 'doc').title).split('\n')[0] || '(no subject)'
|
|
64
|
+
return [{
|
|
65
|
+
entity: { eid: taskEid(eid) },
|
|
66
|
+
task: {},
|
|
67
|
+
doc: {
|
|
68
|
+
title: `Letter from ${from || 'someone'}: ${
|
|
69
|
+
subject.length > 160 ? `${subject.slice(0, 160)}…` : subject
|
|
70
|
+
}`,
|
|
71
|
+
body: `A letter${from ? ` from ${from}` : ''} reached this project. ` +
|
|
72
|
+
`Read it with \`yak mail show ${eid}\`. A reply (\`yak mail ` +
|
|
73
|
+
'reply`) or a letter sent `--about` it completes this task. An ' +
|
|
74
|
+
'answer given where the letter asks for one instead, such as a ' +
|
|
75
|
+
'support thread it names, does not, so complete the task once it is ' +
|
|
76
|
+
'given. When the letter needs no answer, cancel this task: that ' +
|
|
77
|
+
'archives the letter.',
|
|
78
|
+
},
|
|
79
|
+
filed: { project, priority: 1 },
|
|
80
|
+
}]
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** `mail_task`, `mail_answered` and `mail_dismissed`, for a graph whose vocabulary has tasks
|
|
84
|
+
* filed under projects; under any other, neither does anything. */
|
|
85
|
+
export let work = (vocab?: Vocab): Handlers => ({
|
|
86
|
+
mail_task: async (event, tx, write) => {
|
|
87
|
+
if (!vocab?.comp('task') || !vocab.prop('filed', 'project')) return
|
|
88
|
+
let letter = await one(tx, event.entity.eid)
|
|
89
|
+
if (!letter?.[MAIL] || letter[DELIVER]) return
|
|
90
|
+
let project = await projectOf(tx, str(comp(letter, MAIL).target))
|
|
91
|
+
if (!project || await one(tx, taskEid(letter.entity.eid))) return
|
|
92
|
+
let linked = vocab.comp('edge') && vocab.comp('about')
|
|
93
|
+
await write([
|
|
94
|
+
...filing(letter, project),
|
|
95
|
+
...linked
|
|
96
|
+
? [link(taskEid(letter.entity.eid), 'about', event.entity.eid)]
|
|
97
|
+
: [],
|
|
98
|
+
])
|
|
99
|
+
},
|
|
100
|
+
mail_answered: async (event, tx, write) => {
|
|
101
|
+
let reply = await one(tx, event.entity.eid)
|
|
102
|
+
if (!reply?.[DELIVER] || !reply[DELIVERED]) return
|
|
103
|
+
let tasks = await Promise.all(
|
|
104
|
+
answering(reply).map((letter) => one(tx, taskEid(letter))),
|
|
105
|
+
)
|
|
106
|
+
let open = tasks.filter((t) => t?.task && !t.completed && !t.cancelled)
|
|
107
|
+
if (open.length) {
|
|
108
|
+
await write(open.map((t) => ({ entity: t!.entity, completed: {} })))
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
mail_dismissed: async (event, tx, write) => {
|
|
112
|
+
if (!vocab?.comp('archived') || !vocab.comp('about')) return
|
|
113
|
+
let task = await one(tx, event.entity.eid)
|
|
114
|
+
let cancelled = task?.cancelled as Comp | undefined
|
|
115
|
+
if (!cancelled) return
|
|
116
|
+
let links = await tx.read(
|
|
117
|
+
line`.about&.edge.from=${task!.entity.eid}`,
|
|
118
|
+
)
|
|
119
|
+
let letters = await tx.get(
|
|
120
|
+
links.map((l) => str(comp(l, 'edge').to))
|
|
121
|
+
.filter((to) => taskEid(to) == task!.entity.eid),
|
|
122
|
+
)
|
|
123
|
+
let waiting = letters.filter((l) => l?.[MAIL] && !l.archived)
|
|
124
|
+
if (waiting.length) {
|
|
125
|
+
let { at, by, via } = cancelled
|
|
126
|
+
await write(waiting.map((l) => ({
|
|
127
|
+
entity: l!.entity,
|
|
128
|
+
archived: Object.fromEntries(
|
|
129
|
+
Object.entries({ at, by, via }).filter(([, v]) => v != undefined),
|
|
130
|
+
),
|
|
131
|
+
})))
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
})
|