@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/service.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.js","sources":["./service.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,6EAA6E;AAC7E,EAAE;AACF,yEAAyE;AACzE,4EAA4E;AAC5E,2EAA2E;AAC3E,8EAA8E;AAC9E,6EAA6E;AAC7E,EAAE;AACF,wEAAwE;AACxE,yDAAyD;AAIzD,SAAS,KAAK,6BAAkC;AAEhD,SAA+B,IAAI,EAAE,IAAI,oBAAgC;AACzE,SAAS,QAAQ,wBAAuB;AAExC,oEAAoE,GACpE,OAAO,IAAI,QAAQ,OAAM;AAIzB;;uEAEuE,GACvE,IAAI,UAAU,OACZ,MACA,MACA,UAAmB,CAAC,CAAC,EACrB,SAAsB,YAAY,KAAK,EAAE;EAEzC,IAAI,KAAK;IACP,OAAO,KAAK,KAAK;IACjB,GAAI,KAAK,MAAM,GAAG;MAAE,QAAQ,KAAK,MAAM;IAAC,IAAI,CAAC,CAAC;IAC9C,GAAI,KAAK,GAAG,GAAG;MAAE,KAAK,KAAK,GAAG;IAAC,IAAI,CAAC,CAAC;IACrC,GAAI,QAAQ,MAAM,GAAG;MAAE,QAAQ,QAAQ,MAAM;IAAC,IAAI,CAAC,CAAC;IACpD,GAAI,QAAQ,MAAM,GAAG;MAAE,QAAQ,QAAQ,MAAM;IAAC,IAAI,CAAC,CAAC;IACpD,GAAI,OAAO,OAAO,GAAG,CAAC,IAAI;MAAE,MAAM,IAAI;IAAc,CAAC;IACrD,UAAU,MAAM,SAAS,KAAK,MAAM,EAAE;EACxC;EACA,IAAI;EACJ,OAAS;IACP,IAAI,QAAQ,KAAK,GAAG;IACpB,MAAM,KAAK,SAAS,OAAO,KAAK;MAAE,GAAG,EAAE;MAAE;IAAM,GAAG;IAClD,QAAQ;IACR,IAAI,OAAO,OAAO,EAAE;IACpB,MAAM,MAAM,QAAQ,IAAI,EAAE,SAAS,OAAO;IAC1C,IAAI,OAAO,OAAO,EAAE;EACtB;AACF;AAIA,IAAI,OAAa,CAAC,SAAS,OAAS,KAAK,SAAS,OAAO;AAEzD,+DAA+D,GAC/D,OAAO,IAAI,UAAU,CACnB,MACA,UAAmB,CAAC,CAAC,EACrB,SAAsB,YAAY,KAAK,EAAE,EACzC,OAAa,IAAI;EAEjB,IAAI,CAAC,QAAQ,IAAI,EAAE;IACjB,IAAI,OAAO,OAAO,EAAE,OAAO,QAAQ,OAAO;IAC1C,OAAO,CAAC;MACN,MAAO,CAAC,OAAO,OAAO,CAAE,MAAM,MAAM,OAAO;IAC7C,CAAC;EACH;EACA,wEAAwE;EACxE,yEAAyE;EACzE,IAAI,OAAO,OAAO,OAAO,GAAG,YAAY;EACxC,OAAO,QAAQ,MAAM,KAAK,QAAQ,IAAI,EAAE,OAAO,SAAS;AAC1D,EAAC"}
|
package/service.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// The pull, as a duty: the module a server imports at `@yaks/mail/service` to
|
|
2
|
+
// take what arrived at the edge for as long as the server is up (./pull.ts).
|
|
3
|
+
//
|
|
4
|
+
// It is a loop rather than an effect because nothing is committed when a
|
|
5
|
+
// letter reaches the edge; the graph has to ask. It is a duty rather than a
|
|
6
|
+
// timer every process starts because the edge hands each letter to whoever
|
|
7
|
+
// asks first — the host holds it under a lease, so one process over the graph
|
|
8
|
+
// pulls at a time. An explicit one-pass host pulls once when nobody else is.
|
|
9
|
+
//
|
|
10
|
+
// A config that names no `pull` has nothing to take, but holds the duty
|
|
11
|
+
// until shutdown, like a configured poll between passes.
|
|
12
|
+
|
|
13
|
+
import type { Graph } from 'jsr:@yaks/graph@0.2.36'
|
|
14
|
+
import type { Config } from 'jsr:@yaks/host@0.2.36'
|
|
15
|
+
import { sleep } from '@yaks/effects'
|
|
16
|
+
import type { Options, Pull } from './options.ts'
|
|
17
|
+
import { type Down, type Edge, edge, pull, type Report } from './pull.js'
|
|
18
|
+
import { readings } from './readings.js'
|
|
19
|
+
|
|
20
|
+
/** How long a pull waits for the next one, unless the config says. */
|
|
21
|
+
export let EVERY = 10_000
|
|
22
|
+
|
|
23
|
+
type Host = { graph: Graph; config?: Config; report?: Report; log?: Report }
|
|
24
|
+
|
|
25
|
+
/** Pull from one edge, then again every `pull.every`, until the signal aborts.
|
|
26
|
+
* An already-aborted signal is one pull, so a tray it cannot take is said at
|
|
27
|
+
* once; a loop logs transient outages and reports letters they delay. */
|
|
28
|
+
let polling = async (
|
|
29
|
+
host: Host,
|
|
30
|
+
from: Edge,
|
|
31
|
+
options: Options = {},
|
|
32
|
+
signal: AbortSignal = AbortSignal.abort(),
|
|
33
|
+
): Promise<void> => {
|
|
34
|
+
let at = {
|
|
35
|
+
graph: host.graph,
|
|
36
|
+
...(host.report ? { report: host.report } : {}),
|
|
37
|
+
...(host.log ? { log: host.log } : {}),
|
|
38
|
+
...(options.domain ? { domain: options.domain } : {}),
|
|
39
|
+
...(options.triage ? { triage: options.triage } : {}),
|
|
40
|
+
...(signal.aborted ? {} : { down: new Map() as Down }),
|
|
41
|
+
readings: await readings(host.config?.plugins),
|
|
42
|
+
}
|
|
43
|
+
let since: number | undefined
|
|
44
|
+
for (;;) {
|
|
45
|
+
let began = Date.now()
|
|
46
|
+
await pull(since == null ? at : { ...at, since }, from)
|
|
47
|
+
since = began
|
|
48
|
+
if (signal.aborted) return
|
|
49
|
+
await sleep(options.pull?.every ?? EVERY, signal)
|
|
50
|
+
if (signal.aborted) return
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
type Open = (options: Pull, stop?: AbortSignal) => Edge
|
|
55
|
+
|
|
56
|
+
let open: Open = (options, stop) => edge(options, fetch, stop)
|
|
57
|
+
|
|
58
|
+
/** Pull what arrived, then keep polling until the host stops. */
|
|
59
|
+
export let service = (
|
|
60
|
+
host: Host,
|
|
61
|
+
options: Options = {},
|
|
62
|
+
signal: AbortSignal = AbortSignal.abort(),
|
|
63
|
+
make: Open = open,
|
|
64
|
+
): Promise<void> => {
|
|
65
|
+
if (!options.pull) {
|
|
66
|
+
if (signal.aborted) return Promise.resolve()
|
|
67
|
+
return (async () => {
|
|
68
|
+
while (!signal.aborted) await sleep(EVERY, signal)
|
|
69
|
+
})()
|
|
70
|
+
}
|
|
71
|
+
// Already aborted means one pass. A live signal also stops an in-flight
|
|
72
|
+
// edge request, so shutdown and a lost lease do not wait on the network.
|
|
73
|
+
let stop = signal.aborted ? undefined : signal
|
|
74
|
+
return polling(host, make(options.pull, stop), options, signal)
|
|
75
|
+
}
|
package/stash.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// The sender that sends nothing: it keeps the messages in an array.
|
|
2
|
+
//
|
|
3
|
+
// This is what a test uses, and it is also what a development environment
|
|
4
|
+
// wants — a club's whole invitation flow runs end to end, and the letters pile
|
|
5
|
+
// up somewhere you can read them instead of in somebody's inbox.
|
|
6
|
+
/**
|
|
7
|
+
* A sender that keeps messages in memory.
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { stash } from '@yaks/mail'
|
|
11
|
+
*
|
|
12
|
+
* let post = stash()
|
|
13
|
+
* // … send a letter …
|
|
14
|
+
* post.last()?.subject // 'You are invited'
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* Receipts are `stash-1`, `stash-2`, … so a test can assert on the
|
|
18
|
+
* `mail.message_id` the letter was given.
|
|
19
|
+
*/ export let stash = ({ refuse } = {})=>{
|
|
20
|
+
let sent = [];
|
|
21
|
+
return {
|
|
22
|
+
sent,
|
|
23
|
+
last: ()=>sent[sent.length - 1],
|
|
24
|
+
send: (message)=>refuse ? Promise.reject(new Error(refuse)) : Promise.resolve(sent.push(message)).then((n)=>({
|
|
25
|
+
id: `stash-${n}`
|
|
26
|
+
}))
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=stash.js.map
|
package/stash.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stash.js","sources":["./stash.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,EAAE;AACF,0EAA0E;AAC1E,+EAA+E;AAC/E,iEAAiE;AAkBjE;;;;;;;;;;;;;CAaC,GACD,OAAO,IAAI,QAAQ,CAAC,EAAE,MAAM,EAAQ,GAAG,CAAC,CAAC;EACvC,IAAI,OAAkB,EAAE;EACxB,OAAO;IACL;IACA,MAAM,IAAM,IAAI,CAAC,KAAK,MAAM,GAAG,EAAE;IACjC,MAAM,CAAC,UACL,SACI,QAAQ,MAAM,CAAC,IAAI,MAAM,WACzB,QAAQ,OAAO,CAAC,KAAK,IAAI,CAAC,UAAU,IAAI,CAAC,CAAC,IAAM,CAAC;UACjD,IAAI,CAAC,MAAM,EAAE,GAAG;QAClB,CAAC;EACP;AACF,EAAC"}
|
package/stash.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// The sender that sends nothing: it keeps the messages in an array.
|
|
2
|
+
//
|
|
3
|
+
// This is what a test uses, and it is also what a development environment
|
|
4
|
+
// wants — a club's whole invitation flow runs end to end, and the letters pile
|
|
5
|
+
// up somewhere you can read them instead of in somebody's inbox.
|
|
6
|
+
|
|
7
|
+
import type { Message, Receipt, Sender } from './send.ts'
|
|
8
|
+
|
|
9
|
+
/** A {@link Sender} that keeps what it was given. */
|
|
10
|
+
export type Stash = Sender & {
|
|
11
|
+
/** every message handed over, in order */
|
|
12
|
+
sent: Message[]
|
|
13
|
+
/** the last one, for the common assertion */
|
|
14
|
+
last: () => Message | undefined
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** How a stash behaves. */
|
|
18
|
+
export type Kept = {
|
|
19
|
+
/** reject every message with this reason, to exercise the bounce path */
|
|
20
|
+
refuse?: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* A sender that keeps messages in memory.
|
|
25
|
+
*
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { stash } from '@yaks/mail'
|
|
28
|
+
*
|
|
29
|
+
* let post = stash()
|
|
30
|
+
* // … send a letter …
|
|
31
|
+
* post.last()?.subject // 'You are invited'
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* Receipts are `stash-1`, `stash-2`, … so a test can assert on the
|
|
35
|
+
* `mail.message_id` the letter was given.
|
|
36
|
+
*/
|
|
37
|
+
export let stash = ({ refuse }: Kept = {}): Stash => {
|
|
38
|
+
let sent: Message[] = []
|
|
39
|
+
return {
|
|
40
|
+
sent,
|
|
41
|
+
last: () => sent[sent.length - 1],
|
|
42
|
+
send: (message: Message): Promise<Receipt> =>
|
|
43
|
+
refuse
|
|
44
|
+
? Promise.reject(new Error(refuse))
|
|
45
|
+
: Promise.resolve(sent.push(message)).then((n) => ({
|
|
46
|
+
id: `stash-${n}`,
|
|
47
|
+
})),
|
|
48
|
+
}
|
|
49
|
+
}
|
package/tools.js
ADDED
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
// What an agent may ask for here: the `@yaks/mail/tools` entry point — the
|
|
2
|
+
// implementations behind the `tool: true` declarations in ./vocab.json. Three
|
|
3
|
+
// commands a person runs all day, and one check.
|
|
4
|
+
//
|
|
5
|
+
// Reading and answering belong to the caller's attention. The shared
|
|
6
|
+
// subscription row keeps the thread's `opened` and `archived` marks apart from
|
|
7
|
+
// the letter's own state, and the inbox uses the same thread identity.
|
|
8
|
+
// Marks are refreshed atomically, so repeated actions receive a fresh time.
|
|
9
|
+
// A graph using these tools composes @yaks/notify and @yaks/kernel vocabulary.
|
|
10
|
+
//
|
|
11
|
+
// The sender is not this file's business. `mail send` and `mail reply` create
|
|
12
|
+
// a letter that asks to be sent (`deliver`), and ./effects.ts — built from the
|
|
13
|
+
// `sender` the config names beside this plugin — is what hands it to a
|
|
14
|
+
// transport and writes `delivered` or `bounced` back onto it. So a tool that
|
|
15
|
+
// writes mail never talks to a mail server, and a test replaces the whole of
|
|
16
|
+
// it with `{"via": "stash"}`.
|
|
17
|
+
//
|
|
18
|
+
// What is not checked in `mail check`, deliberately: whether each address this
|
|
19
|
+
// graph can create is deliverable at the MTA — the fleet's doctor read
|
|
20
|
+
// Cloudflare Email Routing's live rule set to determine that. That is a
|
|
21
|
+
// question about a zone somebody deployed, answered using a credential the
|
|
22
|
+
// server holds, and its answer is the same whatever graph is running; a
|
|
23
|
+
// package's check reads the graph its own components describe. A deployment
|
|
24
|
+
// that wants that check asks its provider, in its own deployment's check, and
|
|
25
|
+
// this package's `bounced{reason}` is what records the answer arriving the
|
|
26
|
+
// hard way.
|
|
27
|
+
import { addressed, argsOf, who } from "@yaks/graph/call";
|
|
28
|
+
import { BODY, DOC, TITLE } from "@yaks/doc";
|
|
29
|
+
import { human } from "@yaks/id";
|
|
30
|
+
import { threadOf as attentionTarget } from "@yaks/notify";
|
|
31
|
+
import { ancestry, markAttention } from "@yaks/notify/attention";
|
|
32
|
+
import { absent, and, eq, every, list, present } from "@yaks/query";
|
|
33
|
+
import { CallError } from "@yaks/tools/errors";
|
|
34
|
+
import { checked } from "@yaks/tools/check";
|
|
35
|
+
import { said } from "@yaks/tools/result";
|
|
36
|
+
import { wearer } from "./arrive.js";
|
|
37
|
+
import { post } from "./effects.js";
|
|
38
|
+
import { DELIVER, EMAIL, MAIL } from "./comp.js";
|
|
39
|
+
let str = (v)=>v == null ? '' : String(v);
|
|
40
|
+
let comp = (b, name)=>b?.[name];
|
|
41
|
+
let prop = (c, k)=>str(c?.[k]);
|
|
42
|
+
// One entity whole, by eid. Everything here works from the letter as it
|
|
43
|
+
// stands rather than from a patch, the way ./send.ts does.
|
|
44
|
+
let one = async (graph, eid)=>(await graph.get([
|
|
45
|
+
eid
|
|
46
|
+
]))[0];
|
|
47
|
+
// The eid a recipient argument names, whatever form a person typed it in:
|
|
48
|
+
// `to` takes an address or an id, so it is not a declared reference the
|
|
49
|
+
// runner resolves the way it resolves `who`, `item`, `letter` and `about`
|
|
50
|
+
// (@yaks/tools).
|
|
51
|
+
let at = async (graph, said)=>(await addressed(graph, [
|
|
52
|
+
str(said)
|
|
53
|
+
]))[0];
|
|
54
|
+
// The letter an argument names, rejected unless it carries `mail`.
|
|
55
|
+
let letterIn = async (graph, said)=>{
|
|
56
|
+
let found = await one(graph, str(said));
|
|
57
|
+
if (!comp(found, MAIL)) {
|
|
58
|
+
throw new CallError('letter', `not a letter: ${str(said)}`);
|
|
59
|
+
}
|
|
60
|
+
return found;
|
|
61
|
+
};
|
|
62
|
+
/** `Re:` derivation — shed however many `Re:`/`Fwd:` layers already piled up,
|
|
63
|
+
* so a long thread does not grow a subject line. */ export let reSubject = (said)=>`Re: ${said.replace(/^(\s*(re|fwd?):\s*)+/i, '').trim()}`;
|
|
64
|
+
/** A letter's two sides as a reply to it sees them. An arrival — a letter
|
|
65
|
+
* with a Message-ID that never asked to be sent; one of ours carries
|
|
66
|
+
* `deliver`, and has a Message-ID too once the transport gave it one — is
|
|
67
|
+
* answered at whom it says to answer, its Reply-To, else its author, and from
|
|
68
|
+
* the address it was delivered to. Our own letter is answered to its
|
|
69
|
+
* recipient, from the address it went out from. */ export let sides = (letter)=>{
|
|
70
|
+
let mail = comp(letter, MAIL);
|
|
71
|
+
let deliver = comp(letter, DELIVER);
|
|
72
|
+
let arrived = !!prop(mail, 'message_id') && !deliver;
|
|
73
|
+
return arrived ? {
|
|
74
|
+
arrived,
|
|
75
|
+
far: prop(mail, 'reply_address') || prop(mail, 'from'),
|
|
76
|
+
from: prop(mail, 'to')
|
|
77
|
+
} : {
|
|
78
|
+
arrived,
|
|
79
|
+
far: prop(deliver, 'to'),
|
|
80
|
+
from: prop(mail, 'from')
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
// The far side's address as an entity, since `deliver.to` names a recipient
|
|
84
|
+
// rather than a string: whoever already has that address, else a new `email`
|
|
85
|
+
// row for it. That is what makes the address book grow by use instead of by
|
|
86
|
+
// bookkeeping — and why writing to a stranger needs no step before it. An
|
|
87
|
+
// empty address resolves to nobody, never to a blank row: an `email` entity
|
|
88
|
+
// with no address is a recipient a letter can be aimed at and never reach.
|
|
89
|
+
let recipientOf = async (graph, address, domain)=>{
|
|
90
|
+
if (!address) return {
|
|
91
|
+
to: '',
|
|
92
|
+
made: []
|
|
93
|
+
};
|
|
94
|
+
let known = await wearer(graph, address, domain);
|
|
95
|
+
return known ? {
|
|
96
|
+
to: known,
|
|
97
|
+
made: []
|
|
98
|
+
} : {
|
|
99
|
+
to: '$to',
|
|
100
|
+
made: [
|
|
101
|
+
{
|
|
102
|
+
entity: {
|
|
103
|
+
eid: '$to'
|
|
104
|
+
},
|
|
105
|
+
[EMAIL]: {
|
|
106
|
+
address
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
]
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
// Whom an argument means: a string with an `@` is an address, anything else is
|
|
113
|
+
// an id.
|
|
114
|
+
let aimedAt = async (graph, said, domain)=>said.includes('@') ? await recipientOf(graph, said, domain) : {
|
|
115
|
+
to: await at(graph, said),
|
|
116
|
+
made: []
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* A letter's thread: up its one-parent `reply_to` chain, then down over
|
|
120
|
+
* whatever answers anything already found. Each read is keyed by the letters
|
|
121
|
+
* in hand, so a thread costs its own rows rather than every letter ever sent.
|
|
122
|
+
*/ export let threadOf = async (graph, letter)=>{
|
|
123
|
+
let found = await ancestry(graph, letter);
|
|
124
|
+
let seen = new Set(found.map((b)=>b.entity.eid));
|
|
125
|
+
let refs = (rows)=>[
|
|
126
|
+
...new Set(rows.flatMap((b)=>[
|
|
127
|
+
b.entity.eid,
|
|
128
|
+
prop(comp(b, MAIL), 'message_id'),
|
|
129
|
+
prop(comp(b, 'notified'), 'message_id')
|
|
130
|
+
]).filter(Boolean))
|
|
131
|
+
];
|
|
132
|
+
for(let front = refs(found); front.length;){
|
|
133
|
+
let down = (await graph.read(and(eq(`${MAIL}.reply_to`, list(...front)), every()), {
|
|
134
|
+
native: true
|
|
135
|
+
})).filter((b)=>!seen.has(b.entity.eid));
|
|
136
|
+
for (let b of down)seen.add(b.entity.eid), found.push(b);
|
|
137
|
+
front = refs(down);
|
|
138
|
+
}
|
|
139
|
+
// Chronological where the letters record a time, insertion order where they
|
|
140
|
+
// do not — a sort that is stable either way rather than one that invents a
|
|
141
|
+
// time.
|
|
142
|
+
return found.sort((a, b)=>prop(comp(a, MAIL), 'at').localeCompare(prop(comp(b, MAIL), 'at')));
|
|
143
|
+
};
|
|
144
|
+
// Resolve the caller and thread through the shared policy before touching
|
|
145
|
+
// attention. A mail target aimed at the caller is an address, not a thread.
|
|
146
|
+
let attentionOf = async (graph, call, thread, letter)=>{
|
|
147
|
+
let actor = str(who(call)?.by);
|
|
148
|
+
if (!actor) {
|
|
149
|
+
throw new CallError('who', 'nobody is asking — mail attention needs a caller');
|
|
150
|
+
}
|
|
151
|
+
let [person] = await graph.get([
|
|
152
|
+
actor
|
|
153
|
+
]);
|
|
154
|
+
let rows = thread.map((b)=>({
|
|
155
|
+
eid: b.entity.eid,
|
|
156
|
+
comps: b
|
|
157
|
+
}));
|
|
158
|
+
let byId = new Map(rows.map((r)=>[
|
|
159
|
+
r.eid,
|
|
160
|
+
r
|
|
161
|
+
]));
|
|
162
|
+
for (let r of rows){
|
|
163
|
+
for (let id of [
|
|
164
|
+
r.comps.mail?.message_id,
|
|
165
|
+
r.comps.notified?.message_id
|
|
166
|
+
]){
|
|
167
|
+
if (id) byId.set(str(id), r);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
let target = attentionTarget({
|
|
171
|
+
eid: letter.entity.eid,
|
|
172
|
+
comps: letter
|
|
173
|
+
}, {
|
|
174
|
+
actor,
|
|
175
|
+
scope: person?.project ? actor : undefined,
|
|
176
|
+
session: person?.session ? actor : undefined
|
|
177
|
+
}, byId);
|
|
178
|
+
let [subscription] = await graph.read(and(eq('subscription.actor', actor), eq('subscription.target', target), every()));
|
|
179
|
+
return {
|
|
180
|
+
actor,
|
|
181
|
+
target,
|
|
182
|
+
subscription
|
|
183
|
+
};
|
|
184
|
+
};
|
|
185
|
+
// One letter as a line: who it is from, what it is about, and whether it has
|
|
186
|
+
// been read — `●` unread, `·` read, `×` archived, the way a mail client does.
|
|
187
|
+
let line = (id, attention)=>(b)=>{
|
|
188
|
+
let mail = comp(b, MAIL);
|
|
189
|
+
let at = prop(mail, 'at') || prop(comp(b, 'created'), 'at');
|
|
190
|
+
let marked = (name)=>{
|
|
191
|
+
let mark = comp(attention, name);
|
|
192
|
+
return !!mark && (!mark.at || str(mark.at) >= at);
|
|
193
|
+
};
|
|
194
|
+
let dot = marked('archived') ? '×' : marked('opened') ? '·' : '●';
|
|
195
|
+
let who = prop(mail, 'from');
|
|
196
|
+
return `${dot} ${id(b)}${who ? ` ${who}` : ''} — ${prop(comp(b, DOC), TITLE) || '(no subject)'}`;
|
|
197
|
+
};
|
|
198
|
+
// One letter whole: the envelope a person reads, then the words, then the rest
|
|
199
|
+
// of the thread with this one marked.
|
|
200
|
+
let page = (id, letter, thread, attention)=>{
|
|
201
|
+
let mail = comp(letter, MAIL);
|
|
202
|
+
let doc = comp(letter, DOC);
|
|
203
|
+
let said = [
|
|
204
|
+
`# ${prop(doc, TITLE) || '(no subject)'}`,
|
|
205
|
+
[
|
|
206
|
+
prop(mail, 'from') && `from ${prop(mail, 'from')}`,
|
|
207
|
+
prop(mail, 'to') && `to ${prop(mail, 'to')}`,
|
|
208
|
+
prop(mail, 'at'),
|
|
209
|
+
mail?.verified === false && 'UNSIGNED'
|
|
210
|
+
].filter(Boolean).join(' · '),
|
|
211
|
+
'',
|
|
212
|
+
prop(doc, BODY)
|
|
213
|
+
];
|
|
214
|
+
if (thread.length > 1) {
|
|
215
|
+
said.push('', '## Thread', ...thread.map((t)=>`${t.entity.eid == letter.entity.eid ? '▶' : ' '} ${line(id, attention)(t)}`));
|
|
216
|
+
}
|
|
217
|
+
return said.join('\n');
|
|
218
|
+
};
|
|
219
|
+
/** The implementations of the tools ./vocab.json declares. A factory, like
|
|
220
|
+
* every other entry point in these packages: the domain is what an address a
|
|
221
|
+
* person typed is canonicalized against before the address book is queried,
|
|
222
|
+
* into the same form the canonicalizer stored it in (./plugin.ts). Everything
|
|
223
|
+
* else a handler needs arrives on the call it is handed. */ export let runs = (host, options = {})=>({
|
|
224
|
+
// Reading is the mark, so this writes. The prose is the result; the `opened`
|
|
225
|
+
// patch is what keeps a second call from reporting it as unread.
|
|
226
|
+
mail_show: async (call, graph)=>{
|
|
227
|
+
let args = argsOf(call);
|
|
228
|
+
let letter = await letterIn(graph, args.letter);
|
|
229
|
+
let thread = await threadOf(graph, letter);
|
|
230
|
+
let attention = await attentionOf(graph, call, thread, letter);
|
|
231
|
+
return [
|
|
232
|
+
...await markAttention(graph, attention.actor, attention.target, 'opened'),
|
|
233
|
+
said(call, page(human(graph.vocab), letter, thread, attention.subscription))
|
|
234
|
+
];
|
|
235
|
+
},
|
|
236
|
+
// The reply goes to the far side ({@link sides}) and never to a fallback
|
|
237
|
+
// between an arrival's and ours: the wrong choice here is this graph's own
|
|
238
|
+
// address, so a reply that quietly went there would look sent without
|
|
239
|
+
// being sent.
|
|
240
|
+
mail_reply: async (call, graph)=>{
|
|
241
|
+
let args = argsOf(call);
|
|
242
|
+
let letter = await letterIn(graph, args.letter);
|
|
243
|
+
let { arrived, far: answered, from } = sides(letter);
|
|
244
|
+
let far = arrived ? await recipientOf(graph, answered, options.domain) : {
|
|
245
|
+
to: answered,
|
|
246
|
+
made: []
|
|
247
|
+
};
|
|
248
|
+
if (!far.to) {
|
|
249
|
+
throw new CallError('reply', 'cannot reply: that letter names nobody to answer — send a fresh mail');
|
|
250
|
+
}
|
|
251
|
+
let attention = arrived ? await attentionOf(graph, call, await threadOf(graph, letter), letter) : undefined;
|
|
252
|
+
return [
|
|
253
|
+
...far.made,
|
|
254
|
+
{
|
|
255
|
+
entity: {
|
|
256
|
+
eid: '$reply'
|
|
257
|
+
},
|
|
258
|
+
[DOC]: {
|
|
259
|
+
[TITLE]: reSubject(prop(comp(letter, DOC), TITLE)),
|
|
260
|
+
[BODY]: str(args.body)
|
|
261
|
+
},
|
|
262
|
+
// No `target`: on an arrival that property holds whom the letter was
|
|
263
|
+
// routed to (./arrive.ts), which is this side of the thread — carrying
|
|
264
|
+
// it forward would file our own answer as one more letter to us.
|
|
265
|
+
// `reply_to` is what threads a reply, and it is enough.
|
|
266
|
+
[MAIL]: {
|
|
267
|
+
...from ? {
|
|
268
|
+
from
|
|
269
|
+
} : {},
|
|
270
|
+
reply_to: letter.entity.eid
|
|
271
|
+
},
|
|
272
|
+
[DELIVER]: {
|
|
273
|
+
to: far.to
|
|
274
|
+
}
|
|
275
|
+
},
|
|
276
|
+
// Answering an arrival puts its thread away: a thread you have replied
|
|
277
|
+
// to is not one waiting on you. Only an arrival — following up on your
|
|
278
|
+
// own letter left nothing waiting, so there is nothing to put away.
|
|
279
|
+
...attention ? await markAttention(graph, attention.actor, attention.target, 'archived') : []
|
|
280
|
+
];
|
|
281
|
+
},
|
|
282
|
+
// A letter goes out from the address of what it is about, so the answer
|
|
283
|
+
// comes back to that: a project's letter from the project's address. Where
|
|
284
|
+
// that has none, from whoever is asking.
|
|
285
|
+
mail_send: async (call, graph)=>{
|
|
286
|
+
let args = argsOf(call);
|
|
287
|
+
let far = await aimedAt(graph, str(args.to), options.domain);
|
|
288
|
+
if (!far.to) {
|
|
289
|
+
throw new CallError('to', 'a letter needs somebody to go to — say --to');
|
|
290
|
+
}
|
|
291
|
+
let target = str(args.about);
|
|
292
|
+
let address = async (eid)=>eid ? prop(comp(await one(graph, eid), EMAIL), 'address') : '';
|
|
293
|
+
let from = args.from != null ? str(args.from) : options.from?.() || await address(target) || await address(str(who(call)?.by));
|
|
294
|
+
if (!from) {
|
|
295
|
+
throw new CallError('from', 'a letter needs a from address — say --from, or send it about ' + 'something with an `email.address`, or give whoever is asking one');
|
|
296
|
+
}
|
|
297
|
+
return [
|
|
298
|
+
...far.made,
|
|
299
|
+
{
|
|
300
|
+
entity: {
|
|
301
|
+
eid: '$letter'
|
|
302
|
+
},
|
|
303
|
+
[DOC]: {
|
|
304
|
+
[TITLE]: str(args.subject),
|
|
305
|
+
[BODY]: str(args.body)
|
|
306
|
+
},
|
|
307
|
+
[MAIL]: {
|
|
308
|
+
from,
|
|
309
|
+
...target ? {
|
|
310
|
+
target
|
|
311
|
+
} : {}
|
|
312
|
+
},
|
|
313
|
+
[DELIVER]: {
|
|
314
|
+
to: far.to
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
];
|
|
318
|
+
},
|
|
319
|
+
mail_check: async (call, graph)=>{
|
|
320
|
+
// An arrival is a letter with a Message-ID that never asked to be sent
|
|
321
|
+
// (see `sides`), and one with no sender has nobody to answer.
|
|
322
|
+
let orphans = await graph.read(and(present(`${MAIL}.message_id`), absent(DELIVER), absent(`${MAIL}.from`), every()));
|
|
323
|
+
let id = human(graph.vocab);
|
|
324
|
+
let found = orphans.map((b)=>({
|
|
325
|
+
level: 'fail',
|
|
326
|
+
text: `${id(b)} arrived with no sender — a reply has nowhere to go`
|
|
327
|
+
}));
|
|
328
|
+
// And the other direction: a transport this server could not build leaves
|
|
329
|
+
// outbound letters sitting in the graph. Missing config never stops the
|
|
330
|
+
// server from starting (./effects.ts), so this is where it is reported.
|
|
331
|
+
let { waiting } = options.sender ? post(options.sender, host) : {
|
|
332
|
+
waiting: undefined
|
|
333
|
+
};
|
|
334
|
+
if (waiting) {
|
|
335
|
+
found.push({
|
|
336
|
+
level: 'warn',
|
|
337
|
+
text: `nothing is being sent — ${waiting}. What is written meanwhile ` + `waits in the graph`
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
return checked(call.entity.eid, 'every letter that arrived carries a sender, and this server can send', found);
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
//# sourceMappingURL=tools.js.map
|
package/tools.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sources":["./tools.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,8EAA8E;AAC9E,iDAAiD;AACjD,EAAE;AACF,qEAAqE;AACrE,+EAA+E;AAC/E,uEAAuE;AACvE,4EAA4E;AAC5E,+EAA+E;AAC/E,EAAE;AACF,8EAA8E;AAC9E,+EAA+E;AAC/E,uEAAuE;AACvE,6EAA6E;AAC7E,6EAA6E;AAC7E,8BAA8B;AAC9B,EAAE;AACF,+EAA+E;AAC/E,uEAAuE;AACvE,wEAAwE;AACxE,2EAA2E;AAC3E,wEAAwE;AACxE,4EAA4E;AAC5E,8EAA8E;AAC9E,2EAA2E;AAC3E,YAAY;AAGZ,SAAS,SAAS,EAAE,MAAM,EAAE,GAAG,gCAAqC;AACpE,SAAS,IAAI,EAAE,GAAG,EAAE,KAAK,yBAA8B;AACvD,SAAS,KAAK,wBAA6B;AAC3C,SAAS,YAAY,eAAe,4BAAiC;AACrE,SAAS,QAAQ,EAAE,aAAa,sCAA2C;AAC3E,SAAS,MAAM,EAAE,GAAG,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,2BAAgC;AAE9E,SAAS,SAAS,kCAAuC;AACzD,SAAS,OAAO,iCAAsC;AACtD,SAAS,IAAI,kCAAuC;AAEpD,SAAS,MAAM,sBAAqB;AACpC,SAAS,IAAI,uBAAsB;AACnC,SAAS,OAAO,EAAE,KAAK,EAAE,IAAI,oBAAmB;AAIhD,IAAI,MAAM,CAAC,IAAuB,KAAK,OAAO,KAAK,OAAO;AAE1D,IAAI,OAAO,CAAC,GAAuB,OACjC,GAAG,CAAC,KAAK;AAEX,IAAI,OAAO,CAAC,GAAqB,IAAsB,IAAI,GAAG,CA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