@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/answers.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// Who a letter that arrived is from, and the reply that first answered it. An
|
|
2
|
+
// answer is a letter we sent about it, delivered: one whose `reply_to` names
|
|
3
|
+
// it, as `mail_reply` writes, or whose `target` does, as `mail_send` writes
|
|
4
|
+
// with `about`. Any other letter that later left for the same address (a
|
|
5
|
+
// notice, a code, a letter about something else) answers nothing. Computed
|
|
6
|
+
// from the letters, never stored.
|
|
7
|
+
import { line } from "@yaks/query";
|
|
8
|
+
let comp = (b, name)=>b[name] ?? {};
|
|
9
|
+
let lower = (v)=>typeof v == 'string' ? v.trim().toLowerCase() : '';
|
|
10
|
+
let time = (v)=>Date.parse(typeof v == 'string' ? v : '');
|
|
11
|
+
/// sender({ entity: { eid: 'l' },
|
|
12
|
+
/// mail: { from: 'hello@bot.example', reply_address: 'Ann@Example.com' } })
|
|
13
|
+
/// -> 'ann@example.com'
|
|
14
|
+
/// sender({ entity: { eid: 'l' }, mail: { from: 'bob@example.com' } })
|
|
15
|
+
/// -> 'bob@example.com'
|
|
16
|
+
/** Where an answer to a letter that arrived goes, lowercased. */ export let sender = (letter)=>lower(comp(letter, 'mail').reply_address) || lower(comp(letter, 'mail').from);
|
|
17
|
+
/// automated('noreply@notify.cloudflare.com') -> true
|
|
18
|
+
/// automated('no-reply@accounts.example') -> true
|
|
19
|
+
/// automated('mailer-daemon@mx.example') -> true
|
|
20
|
+
/// automated('0100019f-a1b2@bounce.example') -> true
|
|
21
|
+
/// automated('ann@example.com') -> false
|
|
22
|
+
/** Whether an address is a machine's: a no-reply, a bounce or a notifier,
|
|
23
|
+
* which nobody reads an answer at. */ export let automated = (address)=>/^(?:no-?reply|do-?not-?reply|notifications?|mailer-daemon|postmaster|bounces?)@/i.test(address) || /@(?:[\w-]+\.)*(?:bounce|notify|envelope)\./i.test(address);
|
|
24
|
+
/** When a letter that left was delivered; NaN while it has not. */ export let left = (sent)=>time(comp(sent, 'delivered').at);
|
|
25
|
+
/** When a letter arrived. */ export let arrived = (letter)=>time(comp(letter, 'mail').at);
|
|
26
|
+
/// answering({ entity: { eid: 's' }, mail: { reply_to: 'a' } }) -> ['a']
|
|
27
|
+
/// answering({ entity: { eid: 's' }, mail: { target: 'b' } }) -> ['b']
|
|
28
|
+
/// answering({ entity: { eid: 's' }, mail: { reply_to: 'a', target: 'a' } })
|
|
29
|
+
/// -> ['a']
|
|
30
|
+
/** The letters a letter we sent answers: the one it replies to and the one it
|
|
31
|
+
* is about. The one definition of an answer, for whatever reads them. */ export let answering = (sent)=>{
|
|
32
|
+
let mail = comp(sent, 'mail');
|
|
33
|
+
return [
|
|
34
|
+
...new Set([
|
|
35
|
+
mail.reply_to,
|
|
36
|
+
mail.target
|
|
37
|
+
])
|
|
38
|
+
].filter((v)=>typeof v == 'string' && v != '');
|
|
39
|
+
};
|
|
40
|
+
/** The query for letters we sent that may answer one, delivered since
|
|
41
|
+
* `from`: every letter {@link answering} reads something from. */ export let answersSince = (from)=>line`.delivered.at>=${from} (.mail.reply_to | .mail.target) ?mail ?delivered`;
|
|
42
|
+
/// let got = (eid, at) => ({ entity: { eid }, mail: { from: 'a@x.com', at } })
|
|
43
|
+
/// let reply = (eid, to, at) => ({ entity: { eid }, mail: { reply_to: to },
|
|
44
|
+
/// ...(at ? { delivered: { at } } : {}) })
|
|
45
|
+
/// let [a, b] = answers(
|
|
46
|
+
/// [got('a', '2026-10-12T10:00:00Z'), got('b', '2026-10-12T10:00:00Z')],
|
|
47
|
+
/// [reply('r2', 'a', '2026-10-12T12:00:00Z'),
|
|
48
|
+
/// reply('r1', 'a', '2026-10-12T11:00:00Z'), reply('rb', 'b')],
|
|
49
|
+
/// )
|
|
50
|
+
/// [a.answer?.entity.eid, a.ms, b.answer] -> ['r1', 3_600_000, undefined]
|
|
51
|
+
/// let about = { entity: { eid: 'n' }, mail: { target: 'a' },
|
|
52
|
+
/// delivered: { at: '2026-10-12T10:30:00Z' } }
|
|
53
|
+
/// answers([got('a', '2026-10-12T10:00:00Z')], [about])[0].answer?.entity.eid
|
|
54
|
+
/// -> 'n'
|
|
55
|
+
/** Each letter with the first delivered reply to it. */ export let answers = (letters, sent)=>{
|
|
56
|
+
let first = new Map();
|
|
57
|
+
for (let b of sent.filter((b)=>!Number.isNaN(left(b))).sort((a, b)=>left(a) - left(b))){
|
|
58
|
+
for (let to of answering(b))if (!first.has(to)) first.set(to, b);
|
|
59
|
+
}
|
|
60
|
+
return letters.map((letter)=>{
|
|
61
|
+
let answer = first.get(letter.entity.eid);
|
|
62
|
+
return answer ? {
|
|
63
|
+
letter,
|
|
64
|
+
answer,
|
|
65
|
+
ms: left(answer) - arrived(letter)
|
|
66
|
+
} : {
|
|
67
|
+
letter
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
//# sourceMappingURL=answers.js.map
|
package/answers.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"answers.js","sources":["./answers.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,6EAA6E;AAC7E,4EAA4E;AAC5E,yEAAyE;AACzE,2EAA2E;AAC3E,kCAAkC;AAGlC,SAAqB,IAAI,2BAAgC;AAEzD,IAAI,OAAO,CAAC,GAAW,OAAkB,CAAC,CAAC,KAAK,IAAI,CAAC;AACrD,IAAI,QAAQ,CAAC,IAAe,OAAO,KAAK,WAAW,EAAE,IAAI,GAAG,WAAW,KAAK;AAC5E,IAAI,OAAO,CAAC,IAAe,KAAK,KAAK,CAAC,OAAO,KAAK,WAAW,IAAI;AAEjE,k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,CAAC,CAAC,IAAM,CAAC,OAAO,KAAK,CAAC,KAAK,KAC5C,IAAI,CAAC,CAAC,GAAG,IAAM,KAAK,KAAK,KAAK,IACjC;IACA,KAAK,IAAI,MAAM,UAAU,GAAI,IAAI,CAAC,MAAM,GAAG,CAAC,KAAK,MAAM,GAAG,CAAC,IAAI;EACjE;EACA,OAAO,QAAQ,GAAG,CAAC,CAAC;IAClB,IAAI,SAAS,MAAM,GAAG,CAAC,OAAO,MAAM,CAAC,GAAG;IACxC,OAAO,SACH;MAAE;MAAQ;MAAQ,IAAI,KAAK,UAAU,QAAQ;IAAQ,IACrD;MAAE;IAAO;EACf;AACF,EAAC"}
|
package/answers.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// Who a letter that arrived is from, and the reply that first answered it. An
|
|
2
|
+
// answer is a letter we sent about it, delivered: one whose `reply_to` names
|
|
3
|
+
// it, as `mail_reply` writes, or whose `target` does, as `mail_send` writes
|
|
4
|
+
// with `about`. Any other letter that later left for the same address (a
|
|
5
|
+
// notice, a code, a letter about something else) answers nothing. Computed
|
|
6
|
+
// from the letters, never stored.
|
|
7
|
+
|
|
8
|
+
import type { Bundle, Comp } from 'jsr:@yaks/graph@0.2.36'
|
|
9
|
+
import { type Built, line } from '@yaks/query'
|
|
10
|
+
|
|
11
|
+
let comp = (b: Bundle, name: string) => (b[name] ?? {}) as Comp
|
|
12
|
+
let lower = (v: unknown) => typeof v == 'string' ? v.trim().toLowerCase() : ''
|
|
13
|
+
let time = (v: unknown) => Date.parse(typeof v == 'string' ? v : '')
|
|
14
|
+
|
|
15
|
+
/// sender({ entity: { eid: 'l' },
|
|
16
|
+
/// mail: { from: 'hello@bot.example', reply_address: 'Ann@Example.com' } })
|
|
17
|
+
/// -> 'ann@example.com'
|
|
18
|
+
/// sender({ entity: { eid: 'l' }, mail: { from: 'bob@example.com' } })
|
|
19
|
+
/// -> 'bob@example.com'
|
|
20
|
+
/** Where an answer to a letter that arrived goes, lowercased. */
|
|
21
|
+
export let sender = (letter: Bundle): string =>
|
|
22
|
+
lower(comp(letter, 'mail').reply_address) || lower(comp(letter, 'mail').from)
|
|
23
|
+
|
|
24
|
+
/// automated('noreply@notify.cloudflare.com') -> true
|
|
25
|
+
/// automated('no-reply@accounts.example') -> true
|
|
26
|
+
/// automated('mailer-daemon@mx.example') -> true
|
|
27
|
+
/// automated('0100019f-a1b2@bounce.example') -> true
|
|
28
|
+
/// automated('ann@example.com') -> false
|
|
29
|
+
/** Whether an address is a machine's: a no-reply, a bounce or a notifier,
|
|
30
|
+
* which nobody reads an answer at. */
|
|
31
|
+
export let automated = (address: string): boolean =>
|
|
32
|
+
/^(?:no-?reply|do-?not-?reply|notifications?|mailer-daemon|postmaster|bounces?)@/i
|
|
33
|
+
.test(address) ||
|
|
34
|
+
/@(?:[\w-]+\.)*(?:bounce|notify|envelope)\./i.test(address)
|
|
35
|
+
|
|
36
|
+
/** When a letter that left was delivered; NaN while it has not. */
|
|
37
|
+
export let left = (sent: Bundle): number => time(comp(sent, 'delivered').at)
|
|
38
|
+
|
|
39
|
+
/** When a letter arrived. */
|
|
40
|
+
export let arrived = (letter: Bundle): number => time(comp(letter, 'mail').at)
|
|
41
|
+
|
|
42
|
+
/// answering({ entity: { eid: 's' }, mail: { reply_to: 'a' } }) -> ['a']
|
|
43
|
+
/// answering({ entity: { eid: 's' }, mail: { target: 'b' } }) -> ['b']
|
|
44
|
+
/// answering({ entity: { eid: 's' }, mail: { reply_to: 'a', target: 'a' } })
|
|
45
|
+
/// -> ['a']
|
|
46
|
+
/** The letters a letter we sent answers: the one it replies to and the one it
|
|
47
|
+
* is about. The one definition of an answer, for whatever reads them. */
|
|
48
|
+
export let answering = (sent: Bundle): string[] => {
|
|
49
|
+
let mail = comp(sent, 'mail')
|
|
50
|
+
return [...new Set([mail.reply_to, mail.target])]
|
|
51
|
+
.filter((v): v is string => typeof v == 'string' && v != '')
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** The query for letters we sent that may answer one, delivered since
|
|
55
|
+
* `from`: every letter {@link answering} reads something from. */
|
|
56
|
+
export let answersSince = (from: string): Built =>
|
|
57
|
+
line`.delivered.at>=${from} (.mail.reply_to | .mail.target) ?mail ?delivered`
|
|
58
|
+
|
|
59
|
+
export type Answered = {
|
|
60
|
+
letter: Bundle
|
|
61
|
+
/** the first delivered reply to it, if one has left */
|
|
62
|
+
answer?: Bundle
|
|
63
|
+
/** from its arrival to that answer's delivery */
|
|
64
|
+
ms?: number
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/// let got = (eid, at) => ({ entity: { eid }, mail: { from: 'a@x.com', at } })
|
|
68
|
+
/// let reply = (eid, to, at) => ({ entity: { eid }, mail: { reply_to: to },
|
|
69
|
+
/// ...(at ? { delivered: { at } } : {}) })
|
|
70
|
+
/// let [a, b] = answers(
|
|
71
|
+
/// [got('a', '2026-10-12T10:00:00Z'), got('b', '2026-10-12T10:00:00Z')],
|
|
72
|
+
/// [reply('r2', 'a', '2026-10-12T12:00:00Z'),
|
|
73
|
+
/// reply('r1', 'a', '2026-10-12T11:00:00Z'), reply('rb', 'b')],
|
|
74
|
+
/// )
|
|
75
|
+
/// [a.answer?.entity.eid, a.ms, b.answer] -> ['r1', 3_600_000, undefined]
|
|
76
|
+
/// let about = { entity: { eid: 'n' }, mail: { target: 'a' },
|
|
77
|
+
/// delivered: { at: '2026-10-12T10:30:00Z' } }
|
|
78
|
+
/// answers([got('a', '2026-10-12T10:00:00Z')], [about])[0].answer?.entity.eid
|
|
79
|
+
/// -> 'n'
|
|
80
|
+
/** Each letter with the first delivered reply to it. */
|
|
81
|
+
export let answers = (letters: Bundle[], sent: Bundle[]): Answered[] => {
|
|
82
|
+
let first = new Map<string, Bundle>()
|
|
83
|
+
for (
|
|
84
|
+
let b of sent.filter((b) => !Number.isNaN(left(b)))
|
|
85
|
+
.sort((a, b) => left(a) - left(b))
|
|
86
|
+
) {
|
|
87
|
+
for (let to of answering(b)) if (!first.has(to)) first.set(to, b)
|
|
88
|
+
}
|
|
89
|
+
return letters.map((letter) => {
|
|
90
|
+
let answer = first.get(letter.entity.eid)
|
|
91
|
+
return answer
|
|
92
|
+
? { letter, answer, ms: left(answer) - arrived(letter) }
|
|
93
|
+
: { letter }
|
|
94
|
+
})
|
|
95
|
+
}
|
package/arrive.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// Receiving, with a graph: the questions ./inbound.ts deliberately does not
|
|
2
|
+
// ask. That file is pure — a message in, bundles out — and stays that way,
|
|
3
|
+
// because a letter's other two properties are lookups: whom it is about
|
|
4
|
+
// (`mail.target`), and which earlier letter it answers (`mail.reply_to`).
|
|
5
|
+
// Both are questions for the address book and the letters already stored, so
|
|
6
|
+
// they live in this file instead.
|
|
7
|
+
//
|
|
8
|
+
// The address book is read in one direction here: which entity has this
|
|
9
|
+
// address. Both ends of a letter are found the same way (`routed`), and the
|
|
10
|
+
// one it came from is who wrote it. A sender nobody here knows resolves to
|
|
11
|
+
// nobody — never to whatever a routing fallback would have picked — and the
|
|
12
|
+
// letter says so with an empty `$actor`. Saying nothing is not the same: a
|
|
13
|
+
// batch that names no writer is signed by the graph's owner (@yaks/graph
|
|
14
|
+
// `Options.actor`), and a stranger's letter would join the journal as the
|
|
15
|
+
// words of whoever runs the mailbox.
|
|
16
|
+
//
|
|
17
|
+
// The id grammar is the address grammar: an address whose local part is an id
|
|
18
|
+
// this graph knows names that entity, resolved by the same call that resolves
|
|
19
|
+
// an id a person typed (`graph.address`). Derived, never stored — an
|
|
20
|
+
// address-book row per short-lived entity is bookkeeping nobody would keep
|
|
21
|
+
// accurate, and writing to an agent should not require creating one.
|
|
22
|
+
//
|
|
23
|
+
// The Message-ID is what makes an arrival idempotent. An endpoint posted the
|
|
24
|
+
// same letter twice, or a sweep that pulls a message it already pulled,
|
|
25
|
+
// records it once: the second call returns no bundles at all.
|
|
26
|
+
import { Refused } from "@yaks/graph/errors";
|
|
27
|
+
import { and, eq, limit } from "@yaks/query";
|
|
28
|
+
import { canon, local as localOf } from "./addr.js";
|
|
29
|
+
import { EMAIL, MAIL } from "./comp.js";
|
|
30
|
+
import { author, inbound, messageId, verdict } from "./inbound.js";
|
|
31
|
+
// One entity, or none. Everything this file asks is a single-row question, so
|
|
32
|
+
// the shape is written once.
|
|
33
|
+
let one = async (graph, clause)=>(await graph.read(and(clause, limit(1))))[0]?.entity.eid ?? null;
|
|
34
|
+
/**
|
|
35
|
+
* Which entity has this address, or nobody.
|
|
36
|
+
*
|
|
37
|
+
* Case and punctuation are the address book's own: the canonicalizer in the
|
|
38
|
+
* `normalize` phase (./plugin.ts) means a stored address is already in one
|
|
39
|
+
* form, so a lookup canonicalizes the same way before it queries.
|
|
40
|
+
*/ export let wearer = (graph, address, domain)=>one(graph, eq(`${EMAIL}.address`, domain ? canon(domain)(address) : address));
|
|
41
|
+
/** The entity an id-shaped address at `domain` names, or none: `S-31@yours`
|
|
42
|
+
* is S-31. Only your own domain — everywhere else, a local part is a mailbox
|
|
43
|
+
* name and reading it as an id would misdeliver. */ export let named = async (graph, address, domain)=>{
|
|
44
|
+
let id = localOf(domain)(address);
|
|
45
|
+
if (!id) return null;
|
|
46
|
+
try {
|
|
47
|
+
return (await graph.address([
|
|
48
|
+
id
|
|
49
|
+
])).get(id) ?? null;
|
|
50
|
+
} catch (e) {
|
|
51
|
+
// `S-99@yours` when there is no S-99 is a letter for nobody here, which
|
|
52
|
+
// triage takes — the address door refusing the id is that answer, not a
|
|
53
|
+
// reason to refuse the letter.
|
|
54
|
+
if (e instanceof Refused) return null;
|
|
55
|
+
throw e;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
let nobody = Promise.resolve(null);
|
|
59
|
+
/** The letter other mail systems know by this Message-ID, or none — what
|
|
60
|
+
* threading resolves against, and what makes an arrival idempotent. */ export let known = (graph, id)=>id ? one(graph, eq(`${MAIL}.message_id`, id)) : nobody;
|
|
61
|
+
/** Whom a letter to this address is for: whoever has that address, else the
|
|
62
|
+
* entity its id names, else nobody. */ export let routed = async (graph, address, domain)=>await wearer(graph, address, domain) ?? (domain ? await named(graph, address, domain) : null);
|
|
63
|
+
/**
|
|
64
|
+
* A received message → the bundles that record it, with the two lookups
|
|
65
|
+
* answered: whom it is for and which letter it answers. `receive` is
|
|
66
|
+
* `arrived({ graph, domain, triage })`, and `graph.apply(await receive(message,
|
|
67
|
+
* { text }))` records the letter; the README shows it whole.
|
|
68
|
+
*
|
|
69
|
+
* An empty array of bundles means the letter is already here: the Message-ID
|
|
70
|
+
* is the one identity a letter carries between mail systems, so recording it
|
|
71
|
+
* twice would be the error, not the second delivery.
|
|
72
|
+
*
|
|
73
|
+
* The letter is written by its author, found as a recipient is (`routed`),
|
|
74
|
+
* where the edge vouched for its From address (`Arrival.vouched`), and by
|
|
75
|
+
* nobody where it did not or nobody here has that address: its `$actor` is then
|
|
76
|
+
* empty, so the graph does not sign it as its owner's. An unattributed write
|
|
77
|
+
* is the truth about a stranger's letter, and far better than the mailbox's
|
|
78
|
+
* owner appearing to have written it.
|
|
79
|
+
*
|
|
80
|
+
* What else a letter means is not mail's to say: each of `readings` is asked
|
|
81
|
+
* in turn, and the first that answers says what is recorded instead.
|
|
82
|
+
*/ export let arrived = ({ graph, domain, triage, readings = [] })=>async (m, arrival = {})=>{
|
|
83
|
+
let id = messageId(m);
|
|
84
|
+
if (id && await known(graph, id)) return [];
|
|
85
|
+
let target = arrival.target ?? await routed(graph, m.to, domain) ?? triage;
|
|
86
|
+
let answers = m.headers.get('in-reply-to');
|
|
87
|
+
let reply = arrival.reply ?? (answers ? await known(graph, answers.replace(/[<>]/g, '').trim()) : null);
|
|
88
|
+
let by = arrival.vouched ? await routed(graph, author(m), domain) : null;
|
|
89
|
+
let bundles = inbound(m, {
|
|
90
|
+
...arrival,
|
|
91
|
+
verified: arrival.verified ?? verdict(m.headers) ?? undefined,
|
|
92
|
+
...target ? {
|
|
93
|
+
target
|
|
94
|
+
} : {},
|
|
95
|
+
...reply ? {
|
|
96
|
+
reply
|
|
97
|
+
} : {}
|
|
98
|
+
});
|
|
99
|
+
let letter = {
|
|
100
|
+
...bundles[0],
|
|
101
|
+
$actor: by ? {
|
|
102
|
+
by
|
|
103
|
+
} : {}
|
|
104
|
+
};
|
|
105
|
+
let canonical = domain ? canon(domain) : (address)=>address;
|
|
106
|
+
for (let read of readings){
|
|
107
|
+
let said = await read({
|
|
108
|
+
graph,
|
|
109
|
+
message: m,
|
|
110
|
+
arrival,
|
|
111
|
+
letter,
|
|
112
|
+
reply,
|
|
113
|
+
by,
|
|
114
|
+
canonical
|
|
115
|
+
});
|
|
116
|
+
if (said) return said;
|
|
117
|
+
}
|
|
118
|
+
return [
|
|
119
|
+
letter
|
|
120
|
+
];
|
|
121
|
+
};
|
|
122
|
+
//# sourceMappingURL=arrive.js.map
|
package/arrive.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arrive.js","sources":["./arrive.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,2EAA2E;AAC3E,wEAAwE;AACxE,0EAA0E;AAC1E,6EAA6E;AAC7E,kCAAkC;AAClC,EAAE;AACF,wEAAwE;AACxE,4EAA4E;AAC5E,2EAA2E;AAC3E,4EAA4E;AAC5E,2EAA2E;AAC3E,yEAAyE;AACzE,0EAA0E;AAC1E,qCAAqC;AACrC,EAAE;AACF,8EAA8E;AAC9E,8EAA8E;AAC9E,qEAAqE;AACrE,2EAA2E;AAC3E,qEAAqE;AACrE,EAAE;AACF,6EAA6E;AAC7E,wEAAwE;AACxE,8DAA8D;AAG9D,SAAS,OAAO,kCAAuC;AACvD,SAAS,GAAG,EAAe,EAAE,EAAE,KAAK,2BAAgC;AACpE,SAAS,KAAK,EAAE,SAAS,OAAO,oBAAmB;AACnD,SAAS,KAAK,EAAE,IAAI,oBAAmB;AACvC,SAEE,MAAM,EACN,OAAO,EACP,SAAS,EAET,OAAO,uBACY;AAOrB,8EAA8E;AAC9E,6BAA6B;AAC7B,IAAI,MAAM,O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I,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC;IAC5B,IAAI,QAAQ,QAAQ,KAAK,IACvB,CAAC,UAAU,MAAM,MAAM,OAAO,QAAQ,OAAO,CAAC,SAAS,IAAI,IAAI,MAAM,IAAI;IAC3E,IAAI,KAAK,QAAQ,OAAO,GAAG,MAAM,OAAO,OAAO,OAAO,IAAI,UAAU;IACpE,IAAI,UAAU,QAAQ,GAAG;MACvB,GAAG,OAAO;MACV,UAAU,QAAQ,QAAQ,IAAI,QAAQ,EAAE,OAAO,KAAK;MACpD,GAAI,SAAS;QAAE;MAAO,IAAI,CAAC,CAAC;MAC5B,GAAI,QAAQ;QAAE;MAAM,IAAI,CAAC,CAAC;IAC5B;IACA,IAAI,SAAiB;MAAE,GAAG,OAAO,CAAC,EAAE;MAAE,QAAQ,KAAK;QAAE;MAAG,IAAI,CAAC;IAAE;IAC/D,IAAI,YAAY,SAAS,MAAM,UAAU,CAAC,UAAoB;IAC9D,KAAK,IAAI,QAAQ,SAAU;MACzB,IAAI,OAAO,MAAM,KAAK;QACpB;QACA,SAAS;QACT;QACA;QACA;QACA;QACA;MACF;MACA,IAAI,MAAM,OAAO;IACnB;IACA,OAAO;MAAC;KAAO;EACjB,EAAC"}
|
package/arrive.ts
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
// Receiving, with a graph: the questions ./inbound.ts deliberately does not
|
|
2
|
+
// ask. That file is pure — a message in, bundles out — and stays that way,
|
|
3
|
+
// because a letter's other two properties are lookups: whom it is about
|
|
4
|
+
// (`mail.target`), and which earlier letter it answers (`mail.reply_to`).
|
|
5
|
+
// Both are questions for the address book and the letters already stored, so
|
|
6
|
+
// they live in this file instead.
|
|
7
|
+
//
|
|
8
|
+
// The address book is read in one direction here: which entity has this
|
|
9
|
+
// address. Both ends of a letter are found the same way (`routed`), and the
|
|
10
|
+
// one it came from is who wrote it. A sender nobody here knows resolves to
|
|
11
|
+
// nobody — never to whatever a routing fallback would have picked — and the
|
|
12
|
+
// letter says so with an empty `$actor`. Saying nothing is not the same: a
|
|
13
|
+
// batch that names no writer is signed by the graph's owner (@yaks/graph
|
|
14
|
+
// `Options.actor`), and a stranger's letter would join the journal as the
|
|
15
|
+
// words of whoever runs the mailbox.
|
|
16
|
+
//
|
|
17
|
+
// The id grammar is the address grammar: an address whose local part is an id
|
|
18
|
+
// this graph knows names that entity, resolved by the same call that resolves
|
|
19
|
+
// an id a person typed (`graph.address`). Derived, never stored — an
|
|
20
|
+
// address-book row per short-lived entity is bookkeeping nobody would keep
|
|
21
|
+
// accurate, and writing to an agent should not require creating one.
|
|
22
|
+
//
|
|
23
|
+
// The Message-ID is what makes an arrival idempotent. An endpoint posted the
|
|
24
|
+
// same letter twice, or a sweep that pulls a message it already pulled,
|
|
25
|
+
// records it once: the second call returns no bundles at all.
|
|
26
|
+
|
|
27
|
+
import type { Bundle, Eid, Graph } from 'jsr:@yaks/graph@0.2.36'
|
|
28
|
+
import { Refused } from '@yaks/graph/errors'
|
|
29
|
+
import { and, type Clause, eq, limit } from '@yaks/query'
|
|
30
|
+
import { canon, local as localOf } from './addr.js'
|
|
31
|
+
import { EMAIL, MAIL } from './comp.js'
|
|
32
|
+
import {
|
|
33
|
+
type Arrival,
|
|
34
|
+
author,
|
|
35
|
+
inbound,
|
|
36
|
+
messageId,
|
|
37
|
+
type Received,
|
|
38
|
+
verdict,
|
|
39
|
+
} from './inbound.js'
|
|
40
|
+
|
|
41
|
+
/** A graph as this file uses one: a read, and the call that resolves an id a
|
|
42
|
+
* caller typed. Nothing here writes — the bundles are returned to the
|
|
43
|
+
* caller. */
|
|
44
|
+
export type Book = Pick<Graph, 'read' | 'address'>
|
|
45
|
+
|
|
46
|
+
// One entity, or none. Everything this file asks is a single-row question, so
|
|
47
|
+
// the shape is written once.
|
|
48
|
+
let one = async (graph: Book, clause: Clause): Promise<Eid | null> =>
|
|
49
|
+
(await graph.read(and(clause, limit(1))))[0]?.entity.eid ?? null
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Which entity has this address, or nobody.
|
|
53
|
+
*
|
|
54
|
+
* Case and punctuation are the address book's own: the canonicalizer in the
|
|
55
|
+
* `normalize` phase (./plugin.ts) means a stored address is already in one
|
|
56
|
+
* form, so a lookup canonicalizes the same way before it queries.
|
|
57
|
+
*/
|
|
58
|
+
export let wearer = (
|
|
59
|
+
graph: Book,
|
|
60
|
+
address: string,
|
|
61
|
+
domain?: string,
|
|
62
|
+
): Promise<Eid | null> =>
|
|
63
|
+
one(graph, eq(`${EMAIL}.address`, domain ? canon(domain)(address) : address))
|
|
64
|
+
|
|
65
|
+
/** The entity an id-shaped address at `domain` names, or none: `S-31@yours`
|
|
66
|
+
* is S-31. Only your own domain — everywhere else, a local part is a mailbox
|
|
67
|
+
* name and reading it as an id would misdeliver. */
|
|
68
|
+
export let named = async (
|
|
69
|
+
graph: Book,
|
|
70
|
+
address: string,
|
|
71
|
+
domain: string,
|
|
72
|
+
): Promise<Eid | null> => {
|
|
73
|
+
let id = localOf(domain)(address)
|
|
74
|
+
if (!id) return null
|
|
75
|
+
try {
|
|
76
|
+
return (await graph.address([id])).get(id) ?? null
|
|
77
|
+
} catch (e) {
|
|
78
|
+
// `S-99@yours` when there is no S-99 is a letter for nobody here, which
|
|
79
|
+
// triage takes — the address door refusing the id is that answer, not a
|
|
80
|
+
// reason to refuse the letter.
|
|
81
|
+
if (e instanceof Refused) return null
|
|
82
|
+
throw e
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
let nobody: Promise<Eid | null> = Promise.resolve(null)
|
|
87
|
+
|
|
88
|
+
/** The letter other mail systems know by this Message-ID, or none — what
|
|
89
|
+
* threading resolves against, and what makes an arrival idempotent. */
|
|
90
|
+
export let known = (graph: Book, id: string): Promise<Eid | null> =>
|
|
91
|
+
id ? one(graph, eq(`${MAIL}.message_id`, id)) : nobody
|
|
92
|
+
|
|
93
|
+
/** Whom a letter to this address is for: whoever has that address, else the
|
|
94
|
+
* entity its id names, else nobody. */
|
|
95
|
+
export let routed = async (
|
|
96
|
+
graph: Book,
|
|
97
|
+
address: string,
|
|
98
|
+
domain?: string,
|
|
99
|
+
): Promise<Eid | null> =>
|
|
100
|
+
await wearer(graph, address, domain) ??
|
|
101
|
+
(domain ? await named(graph, address, domain) : null)
|
|
102
|
+
|
|
103
|
+
/** One arrival, as another package reads it: the message whole (its headers
|
|
104
|
+
* are only here), the letter as mail records it, and the lookups mail
|
|
105
|
+
* answered. */
|
|
106
|
+
export type Read = {
|
|
107
|
+
/** the graph to query */
|
|
108
|
+
graph: Book
|
|
109
|
+
/** the message as it arrived */
|
|
110
|
+
message: Received
|
|
111
|
+
/** what the caller knew beside it: the parsed text, a target it named */
|
|
112
|
+
arrival: Arrival
|
|
113
|
+
/** the letter as mail records it, its `$actor` included */
|
|
114
|
+
letter: Bundle
|
|
115
|
+
/** the letter it answers, where this graph has it */
|
|
116
|
+
reply: Eid | null
|
|
117
|
+
/** who wrote it, where the address book knows them */
|
|
118
|
+
by: Eid | null
|
|
119
|
+
/** an address in the form this graph stores addresses in */
|
|
120
|
+
canonical: (address: string) => string
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** What a package makes of an arrival: the bundles to record in place of the
|
|
124
|
+
* letter alone (the letter, perhaps with more on it, and whatever else it
|
|
125
|
+
* means), or nothing to leave it a letter. A package offers one from its
|
|
126
|
+
* `./mail` facet (./readings.ts). */
|
|
127
|
+
export type Reading = (
|
|
128
|
+
read: Read,
|
|
129
|
+
) => Bundle[] | undefined | Promise<Bundle[] | undefined>
|
|
130
|
+
|
|
131
|
+
/** What the receiving half needs, besides the message. */
|
|
132
|
+
export type Arrivals = {
|
|
133
|
+
/** the graph to query */
|
|
134
|
+
graph: Book
|
|
135
|
+
/** your own mail domain: the one whose addresses this graph can resolve.
|
|
136
|
+
* Without it, every address belongs to somebody else and a letter is
|
|
137
|
+
* recorded against whatever the address book already knows. */
|
|
138
|
+
domain?: string
|
|
139
|
+
/** where a letter addressed to nobody here lands — the triage entity */
|
|
140
|
+
triage?: Eid
|
|
141
|
+
/** what other packages make of an arrival, asked in order; the first that
|
|
142
|
+
* answers decides what is recorded */
|
|
143
|
+
readings?: Reading[]
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* A received message → the bundles that record it, with the two lookups
|
|
148
|
+
* answered: whom it is for and which letter it answers. `receive` is
|
|
149
|
+
* `arrived({ graph, domain, triage })`, and `graph.apply(await receive(message,
|
|
150
|
+
* { text }))` records the letter; the README shows it whole.
|
|
151
|
+
*
|
|
152
|
+
* An empty array of bundles means the letter is already here: the Message-ID
|
|
153
|
+
* is the one identity a letter carries between mail systems, so recording it
|
|
154
|
+
* twice would be the error, not the second delivery.
|
|
155
|
+
*
|
|
156
|
+
* The letter is written by its author, found as a recipient is (`routed`),
|
|
157
|
+
* where the edge vouched for its From address (`Arrival.vouched`), and by
|
|
158
|
+
* nobody where it did not or nobody here has that address: its `$actor` is then
|
|
159
|
+
* empty, so the graph does not sign it as its owner's. An unattributed write
|
|
160
|
+
* is the truth about a stranger's letter, and far better than the mailbox's
|
|
161
|
+
* owner appearing to have written it.
|
|
162
|
+
*
|
|
163
|
+
* What else a letter means is not mail's to say: each of `readings` is asked
|
|
164
|
+
* in turn, and the first that answers says what is recorded instead.
|
|
165
|
+
*/
|
|
166
|
+
export let arrived = (
|
|
167
|
+
{ graph, domain, triage, readings = [] }: Arrivals,
|
|
168
|
+
): (m: Received, arrival?: Arrival) => Promise<Bundle[]> =>
|
|
169
|
+
async (m, arrival = {}) => {
|
|
170
|
+
let id = messageId(m)
|
|
171
|
+
if (id && await known(graph, id)) return []
|
|
172
|
+
let target = arrival.target ?? await routed(graph, m.to, domain) ?? triage
|
|
173
|
+
let answers = m.headers.get('in-reply-to')
|
|
174
|
+
let reply = arrival.reply ??
|
|
175
|
+
(answers ? await known(graph, answers.replace(/[<>]/g, '').trim()) : null)
|
|
176
|
+
let by = arrival.vouched ? await routed(graph, author(m), domain) : null
|
|
177
|
+
let bundles = inbound(m, {
|
|
178
|
+
...arrival,
|
|
179
|
+
verified: arrival.verified ?? verdict(m.headers) ?? undefined,
|
|
180
|
+
...(target ? { target } : {}),
|
|
181
|
+
...(reply ? { reply } : {}),
|
|
182
|
+
})
|
|
183
|
+
let letter: Bundle = { ...bundles[0], $actor: by ? { by } : {} }
|
|
184
|
+
let canonical = domain ? canon(domain) : (address: string) => address
|
|
185
|
+
for (let read of readings) {
|
|
186
|
+
let said = await read({
|
|
187
|
+
graph,
|
|
188
|
+
message: m,
|
|
189
|
+
arrival,
|
|
190
|
+
letter,
|
|
191
|
+
reply,
|
|
192
|
+
by,
|
|
193
|
+
canonical,
|
|
194
|
+
})
|
|
195
|
+
if (said) return said
|
|
196
|
+
}
|
|
197
|
+
return [letter]
|
|
198
|
+
}
|
package/capture.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// A delivery's recoverable source, independent of its parsed graph projection.
|
|
2
|
+
// Bytes are base64 in the JSON capture so any private byte store can keep it.
|
|
3
|
+
import { fromBase64, toBase64 } from "@yaks/fp";
|
|
4
|
+
let part = ({ bytes, ...file })=>({
|
|
5
|
+
...file,
|
|
6
|
+
base64: toBase64(bytes)
|
|
7
|
+
});
|
|
8
|
+
/** Describe a delivery with its files encoded by the caller, such as private byte references. */ export let capturing = ({ headers, attachments, sources, ...mail }, file)=>({
|
|
9
|
+
...mail,
|
|
10
|
+
headers: [
|
|
11
|
+
...headers.entries?.() ?? []
|
|
12
|
+
],
|
|
13
|
+
attachments: attachments.map(file),
|
|
14
|
+
sources: (sources ?? []).map(file)
|
|
15
|
+
});
|
|
16
|
+
/** Keep all bytes before projecting a delivery into a letter or an upload. */ export let capture = (mail)=>capturing(mail, part);
|
|
17
|
+
/** Read original files from a capture, including ones an app could not take. */ export let captured = (parts)=>parts.map(({ base64, ...file })=>({
|
|
18
|
+
...file,
|
|
19
|
+
bytes: fromBase64(base64)
|
|
20
|
+
}));
|
|
21
|
+
//# sourceMappingURL=capture.js.map
|
package/capture.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capture.js","sources":["./capture.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,8EAA8E;AAC9E,SAAS,UAAU,EAAE,QAAQ,wBAA6B;AAmB1D,IAAI,OAAO,CAAC,EAAE,KAAK,EAAE,GAAG,MAAkB,GAAW,CAAC;IACpD,GAAG,IAAI;IACP,QAAQ,SAAS;EACnB,CAAC;AAED,+FAA+F,GAC/F,OAAO,IAAI,YAAY,CACrB,EAAE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,MAAgB,EACpD,OACkB,CAAC;IACnB,GAAG,IAAI;IACP,SAAS;SAAI,QAAQ,OAAO,QAAQ,EAAE;KAAC;IACvC,aAAa,YAAY,GAAG,CAAC;IAC7B,SAAS,CAAC,WAAW,EAAE,EAAE,GAAG,CAAC;EAC/B,CAAC,EAAC;AAEF,4EAA4E,GAC5E,OAAO,IAAI,UAAU,CAAC,OAA4B,UAAU,MAAM,MAAK;AAEvE,8EAA8E,GAC9E,OAAO,IAAI,WAAW,CAAC,QACrB,MAAM,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,GAAK,CAAC;MAAE,GAAG,IAAI;MAAE,OAAO,WAAW;IAAQ,CAAC,GAAE"}
|
package/capture.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// A delivery's recoverable source, independent of its parsed graph projection.
|
|
2
|
+
// Bytes are base64 in the JSON capture so any private byte store can keep it.
|
|
3
|
+
import { fromBase64, toBase64 } from '@yaks/fp'
|
|
4
|
+
import type { Incoming, MailSource } from 'jsr:@yaks/host@0.2.36/senders'
|
|
5
|
+
|
|
6
|
+
type Part = { name: string; type: string; base64: string }
|
|
7
|
+
|
|
8
|
+
/** A complete delivery: the neutral envelope and original provider bytes. */
|
|
9
|
+
export type Capture<File = Part> = {
|
|
10
|
+
from: string
|
|
11
|
+
to: string
|
|
12
|
+
name?: string
|
|
13
|
+
headers: [string, string][]
|
|
14
|
+
text: string
|
|
15
|
+
html?: string
|
|
16
|
+
verified?: boolean
|
|
17
|
+
vouched?: boolean
|
|
18
|
+
attachments: File[]
|
|
19
|
+
sources: File[]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let part = ({ bytes, ...file }: MailSource): Part => ({
|
|
23
|
+
...file,
|
|
24
|
+
base64: toBase64(bytes),
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
/** Describe a delivery with its files encoded by the caller, such as private byte references. */
|
|
28
|
+
export let capturing = <File>(
|
|
29
|
+
{ headers, attachments, sources, ...mail }: Incoming,
|
|
30
|
+
file: (source: MailSource) => File,
|
|
31
|
+
): Capture<File> => ({
|
|
32
|
+
...mail,
|
|
33
|
+
headers: [...headers.entries?.() ?? []],
|
|
34
|
+
attachments: attachments.map(file),
|
|
35
|
+
sources: (sources ?? []).map(file),
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
/** Keep all bytes before projecting a delivery into a letter or an upload. */
|
|
39
|
+
export let capture = (mail: Incoming): Capture => capturing(mail, part)
|
|
40
|
+
|
|
41
|
+
/** Read original files from a capture, including ones an app could not take. */
|
|
42
|
+
export let captured = (parts: Part[]): MailSource[] =>
|
|
43
|
+
parts.map(({ base64, ...file }) => ({ ...file, bytes: fromBase64(base64) }))
|
package/comp.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// The components this package declares, as one vocabulary document to load
|
|
2
|
+
// beside your own.
|
|
3
|
+
//
|
|
4
|
+
// mail{from, name, to, at, target, reply_to, message_id, verified,
|
|
5
|
+
// in_reply_to, reply_address} one letter's envelope
|
|
6
|
+
// email{address} an address, as an entity
|
|
7
|
+
// deliver{to} who it is for, as an entity
|
|
8
|
+
// delivered{at} it left
|
|
9
|
+
// bounced{at, reason, refused} it did not
|
|
10
|
+
// notified{at, by, via} they were told
|
|
11
|
+
//
|
|
12
|
+
// The subject and the body are not here. They are `doc{title, body}`, from
|
|
13
|
+
// {@link https://jsr.io/@yaks/doc | @yaks/doc}, which this package depends on
|
|
14
|
+
// (Jeff, 2026-09-05: "the mail package can't require the package that installs
|
|
15
|
+
// doc?"). A letter is an entity like any other, and the words a person reads
|
|
16
|
+
// belong in the one component every readable thing has — so a letter is
|
|
17
|
+
// searched, rendered and edited by whatever already handles a `doc`, instead of
|
|
18
|
+
// by a second copy of the same two properties. What is left on `mail` is the
|
|
19
|
+
// envelope: who it is from, where it went, when, what it is about, what it
|
|
20
|
+
// answers.
|
|
21
|
+
//
|
|
22
|
+
// `mail` does not declare `doc` — a vocabulary rejects a component declared
|
|
23
|
+
// twice, so composing it is the application's choice: `loadVocab([docDoc,
|
|
24
|
+
// mailDoc, ...mine])`, `plugins: [docs(), mailbox({...})]`. `target` is what
|
|
25
|
+
// makes this a graph's mail — the entity the letter is about, which may be any
|
|
26
|
+
// entity at all, so a reply about the potluck hangs off the potluck.
|
|
27
|
+
//
|
|
28
|
+
// Two ways to record who it is for, on purpose. `mail.to` is the To: line — an
|
|
29
|
+
// address, written by whoever composed the letter. `deliver.to` is a
|
|
30
|
+
// recipient: an entity in your graph, whose address is looked up when the
|
|
31
|
+
// letter goes out. Addressing a person rather than a string is what lets them
|
|
32
|
+
// change their address without rewriting the mail that has not left yet.
|
|
33
|
+
//
|
|
34
|
+
// `verified` is the receiving side's verdict on an arrival: whether the sending
|
|
35
|
+
// domain signed for the letter (DKIM). It is a property and not a gate — a
|
|
36
|
+
// letter nobody signed for is recorded with `verified: false` rather than
|
|
37
|
+
// dropped, because dropping it is silence and the reader is the one who decides
|
|
38
|
+
// what an unsigned letter is worth.
|
|
39
|
+
//
|
|
40
|
+
// `delivered` and `bounced` are the two ends of one outcome, and exactly one of
|
|
41
|
+
// them lands on a letter. Both are stamped: they are the sender's report of
|
|
42
|
+
// what happened, written by the effect, never by a client claiming its own mail
|
|
43
|
+
// arrived.
|
|
44
|
+
//
|
|
45
|
+
// The document itself is `./vocab.json` — plain JSON Schema, readable by
|
|
46
|
+
// anything that reads JSON. This file re-exports it under the name callers
|
|
47
|
+
// import and keeps the prose about why it is shaped the way it is.
|
|
48
|
+
import doc from './vocab.json' with {
|
|
49
|
+
type: 'json'
|
|
50
|
+
};
|
|
51
|
+
/** The component naming one letter. */ export let MAIL = 'mail';
|
|
52
|
+
/** The component naming an address as an entity of its own. */ export let EMAIL = 'email';
|
|
53
|
+
/** The component keeping an address only a letter names to those who may read
|
|
54
|
+
* the letters. */ export let RECIPIENT = 'recipient';
|
|
55
|
+
/** The component naming who a letter is for, as an entity. */ export let DELIVER = 'deliver';
|
|
56
|
+
/** The component stamped on a letter that left. */ export let DELIVERED = 'delivered';
|
|
57
|
+
/** The component stamped on a letter that did not. */ export let BOUNCED = 'bounced';
|
|
58
|
+
/** The component stamped when a recipient was told. */ export let NOTIFIED = 'notified';
|
|
59
|
+
/**
|
|
60
|
+
* The mail vocabulary document, to load beside
|
|
61
|
+
* {@link https://jsr.io/@yaks/doc | @yaks/doc}'s and your own:
|
|
62
|
+
* `loadVocab([docDoc, mailDoc, ...mine])`. It declares nothing about what a
|
|
63
|
+
* person or a club is — those are plain entities in your own vocabulary — only
|
|
64
|
+
* the envelope of a letter, who it is for, and what became of it. The subject
|
|
65
|
+
* and the body are `doc.title` and `doc.body`.
|
|
66
|
+
*
|
|
67
|
+
* The `prefix` keywords are {@link https://jsr.io/@yaks/id | @yaks/id}'s: load
|
|
68
|
+
* that package's keywords and a letter reads back as `E-7`, an address as
|
|
69
|
+
* `A-3`. A loader that never registers them simply drops both.
|
|
70
|
+
*
|
|
71
|
+
* `mail` declares `before: ['doc']` — an entity carrying both is a letter,
|
|
72
|
+
* not the `doc` it also carries, so `mail` sorts first. The component it sorts
|
|
73
|
+
* against is @yaks/doc's, which is why this document is never loaded without
|
|
74
|
+
* it.
|
|
75
|
+
*/ export let mailDoc = doc;
|
|
76
|
+
//# sourceMappingURL=comp.js.map
|
package/comp.js.map
ADDED
|
@@ -0,0 +1 @@
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