@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/md.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"md.js","sources":["./md.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,8EAA8E;AAC9E,EAAE;AACF,+EAA+E;AAC/E,gHAAgH;AAChH,8EAA8E;AAC9E,4EAA4E;AAC5E,8CAA8C;AAC9C,EAAE;AACF,+EAA+E;AAC/E,SAAS;AACT,EAAE;AACF,wEAAwE;AACxE,2EAA2E;AAC3E,+EAA+E;AAC/E,EAAE;AACF,8EAA8E;AAC9E,8EAA8E;AAC9E,6EAA6E;AAC7E,8EAA8E;AAC9E,6EAA6E;AAC7E,8EAA8E;AAC9E,mDAAmD;AACnD,EAAE;AACF,2EAA2E;AAC3E,+EAA+E;AAC/E,+EAA+E;AAC/E,6EAA6E;AAC7E,sBAAsB;AAEtB,0EAA0E,GAkB1E,IAAI,MAAM;AAEV,4EAA4E;AAC5E,+EAA+E;AAC/E,0EAA0E;AAC1E,+EAA+E;AAC/E,wEAAwE;AACxE,sCAAsC;AACtC,IAAI,SACF;AAEF,6DAA6D,GAC7D,OAAO,IAAI,SAAS,CAAC;EACnB,IAAI,MAAe,EAAE;EACrB,IAAI,KAAK;EACT,KAAK,IAAI,KAAK,KAAK,QAAQ,CAAC,QAAS;IACnC,IAAI,EAAE,KAAK,GAAG,IAAI,IAAI,IAAI,CAAC;MAAE,MAAM;MAAQ,MAAM,KAAK,KAAK,CAAC,IAAI,EAAE,KAAK;IAAE;IACzE,IAAI,CAAC,CAAC,EAAE,IAAI,MAAM,IAAI,IA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QAEF,IAAI,CAAC;EACT,GAAG,IAAI,CAAC,QAAO"}
|
package/md.ts
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
// A letter's body is markdown, and it goes out twice: once as the plain text
|
|
2
|
+
// part and once as HTML. This file is both renderings, from one small reader.
|
|
3
|
+
//
|
|
4
|
+
// It is deliberately minimal — paragraphs, headings, bullets, tables, an image
|
|
5
|
+
// on a line of its own, links, bold, italic, code — because a mail client renders a small subset of HTML anyway
|
|
6
|
+
// and because a markdown library is a dependency this package would otherwise
|
|
7
|
+
// not need. If you already have a renderer you trust, hand its output in as
|
|
8
|
+
// the message's `html` and none of this runs.
|
|
9
|
+
//
|
|
10
|
+
// Two rules are not negotiable, and they are why this is not `escape()` plus a
|
|
11
|
+
// regex:
|
|
12
|
+
//
|
|
13
|
+
// Markup A body wrote is text, never markup. Every character a letter
|
|
14
|
+
// carries is escaped; the only tags in the output are the ones this file
|
|
15
|
+
// generates. A letter from a stranger cannot ship a <script> to your reader.
|
|
16
|
+
//
|
|
17
|
+
// An href is tested by its shape, never by A list of bad schemes. A browser
|
|
18
|
+
// decodes entities inside an attribute, so `javascript:alert(1)` is a
|
|
19
|
+
// scheme by the time it parses one and no denylist sees it coming. Only an
|
|
20
|
+
// absolute http, https, mailto or tel link becomes an anchor; anything else
|
|
21
|
+
// renders as its own text. Relative links are rejected too — a mail client
|
|
22
|
+
// has no base document to resolve `/potluck` against, so it would reach the
|
|
23
|
+
// reader as a broken address rather than a link.
|
|
24
|
+
//
|
|
25
|
+
// A body a graph stores holds the eid of each entity it names (@yaks/graph
|
|
26
|
+
// `Prose`), and a reader never reads a whole uuid: given what the sender calls
|
|
27
|
+
// each one ({@link Names}), an eid written bare reads as its id, linked to its
|
|
28
|
+
// page, and a link written to one goes to that page. A uuid it does not name
|
|
29
|
+
// is left as written.
|
|
30
|
+
|
|
31
|
+
/** One piece of a body: a run of words, or the markup that decorates it. */
|
|
32
|
+
export type Token = {
|
|
33
|
+
/** what it is */
|
|
34
|
+
kind: 'text' | 'link' | 'code' | 'strong' | 'em' | 'ref'
|
|
35
|
+
/** the words it carries */
|
|
36
|
+
text: string
|
|
37
|
+
/** where a link points */
|
|
38
|
+
href?: string
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** What a letter calls an entity its body holds the eid of: its id, and the
|
|
42
|
+
* page a reader opens it at, where it has one. */
|
|
43
|
+
export type Named = { id: string; href?: string }
|
|
44
|
+
|
|
45
|
+
/** What the sender calls each eid a body holds, or nothing for one it does not
|
|
46
|
+
* know, which then stays as written. */
|
|
47
|
+
export type Names = (eid: string) => Named | undefined
|
|
48
|
+
|
|
49
|
+
let EID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
|
|
50
|
+
|
|
51
|
+
// Links first (their text may hold anything), then code (which consumes its
|
|
52
|
+
// content whole), then the two emphases, then an eid standing as a word of its
|
|
53
|
+
// own, then an address written bare. An underscore inside a word is never
|
|
54
|
+
// emphasis, so `session_token=nango_connect` keeps its underscores, and a bare
|
|
55
|
+
// address is one run of text, so a token in it keeps every character (a
|
|
56
|
+
// base64url `-_x_-` is not emphasis).
|
|
57
|
+
let INLINE =
|
|
58
|
+
/\[([^\]]*)\]\(([^)\s]+)\)|`([^`]+)`|\*\*([^*]+)\*\*|\*([^*\n]+)\*|(?<![\p{L}\p{N}_])_([^_\n]+)_(?![\p{L}\p{N}_])|(?<![\w#\/-])([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})(?![\w-])|(https?:\/\/\S+)/giu
|
|
59
|
+
|
|
60
|
+
/** A line of markdown → the tokens it is made of, in order. */
|
|
61
|
+
export let tokens = (line: string): Token[] => {
|
|
62
|
+
let out: Token[] = []
|
|
63
|
+
let at = 0
|
|
64
|
+
for (let m of line.matchAll(INLINE)) {
|
|
65
|
+
if (m.index > at) out.push({ kind: 'text', text: line.slice(at, m.index) })
|
|
66
|
+
if (m[2] != null) out.push({ kind: 'link', text: m[1], href: m[2] })
|
|
67
|
+
else if (m[3] != null) out.push({ kind: 'code', text: m[3] })
|
|
68
|
+
else if (m[4] != null) out.push({ kind: 'strong', text: m[4] })
|
|
69
|
+
else if (m[7] != null) out.push({ kind: 'ref', text: m[7] })
|
|
70
|
+
else if (m[8] != null) out.push({ kind: 'text', text: m[8] })
|
|
71
|
+
else out.push({ kind: 'em', text: m[5] ?? m[6] })
|
|
72
|
+
at = m.index + m[0].length
|
|
73
|
+
}
|
|
74
|
+
if (at < line.length) out.push({ kind: 'text', text: line.slice(at) })
|
|
75
|
+
return out
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** The eids a body names, written bare or as a link's target, once each and
|
|
79
|
+
* in lower case: what the sender is asked to name. Code keeps its ids literal,
|
|
80
|
+
* so none in it is listed. */
|
|
81
|
+
export let eids = (body: string): string[] => [
|
|
82
|
+
...new Set(
|
|
83
|
+
body.split('\n').flatMap(tokens).flatMap((t) =>
|
|
84
|
+
t.kind == 'ref'
|
|
85
|
+
? [t.text.toLowerCase()]
|
|
86
|
+
: t.kind == 'link' && EID.test(t.href!.trim())
|
|
87
|
+
? [t.href!.trim().toLowerCase()]
|
|
88
|
+
: []
|
|
89
|
+
),
|
|
90
|
+
),
|
|
91
|
+
]
|
|
92
|
+
|
|
93
|
+
// A line's tokens with each eid the sender names as its reader reads it: a
|
|
94
|
+
// bare one is its id, a link where it has a page; a link to one goes to that
|
|
95
|
+
// page, or is its words. An eid it does not name is a uuid like any other.
|
|
96
|
+
let drawn = (line: string, names?: Names): Token[] =>
|
|
97
|
+
tokens(line).map((t) => {
|
|
98
|
+
let eid = t.kind == 'ref'
|
|
99
|
+
? t.text
|
|
100
|
+
: t.kind == 'link' && EID.test(t.href!.trim())
|
|
101
|
+
? t.href!.trim()
|
|
102
|
+
: undefined
|
|
103
|
+
let named = eid ? names?.(eid.toLowerCase()) : undefined
|
|
104
|
+
if (t.kind == 'ref') {
|
|
105
|
+
return named?.href
|
|
106
|
+
? { kind: 'link', text: named.id, href: named.href }
|
|
107
|
+
: { kind: 'text', text: named?.id ?? t.text }
|
|
108
|
+
}
|
|
109
|
+
return named ? { ...t, href: named.href ?? '' } : t
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
/** Whether an href may become an anchor: absolute, and one of four schemes. */
|
|
113
|
+
export let linkable = (href: string): boolean =>
|
|
114
|
+
/^(?:https?:\/\/|mailto:|tel:)\S+$/i.test(href.trim())
|
|
115
|
+
|
|
116
|
+
/** `&` first, or the escapes escape. */
|
|
117
|
+
export let escape = (s: string): string =>
|
|
118
|
+
s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
|
|
119
|
+
.replace(/"/g, '"')
|
|
120
|
+
|
|
121
|
+
let inline = (line: string, names?: Names): string =>
|
|
122
|
+
drawn(line, names).map((t) =>
|
|
123
|
+
t.kind == 'link' && linkable(t.href!)
|
|
124
|
+
? `<a href="${escape(t.href!.trim())}">${escape(t.text)}</a>`
|
|
125
|
+
: t.kind == 'code'
|
|
126
|
+
? `<code>${escape(t.text)}</code>`
|
|
127
|
+
: t.kind == 'strong'
|
|
128
|
+
? `<strong>${escape(t.text)}</strong>`
|
|
129
|
+
: t.kind == 'em'
|
|
130
|
+
? `<em>${escape(t.text)}</em>`
|
|
131
|
+
: escape(t.text)
|
|
132
|
+
).join('')
|
|
133
|
+
|
|
134
|
+
let flat = (line: string, names?: Names): string =>
|
|
135
|
+
drawn(line, names).map((t) =>
|
|
136
|
+
t.kind == 'link' && linkable(t.href!) && t.text.trim() != t.href!.trim()
|
|
137
|
+
? `${t.text} (${t.href!.trim()})`
|
|
138
|
+
: t.text
|
|
139
|
+
).join('')
|
|
140
|
+
|
|
141
|
+
// An image stands on a line of its own, at an absolute http(s) address: a mail
|
|
142
|
+
// client fetches it from there, and has no other way to show one.
|
|
143
|
+
let IMAGE = /^!\[([^\]]*)\]\((https?:\/\/[^)\s]+)\)$/i
|
|
144
|
+
|
|
145
|
+
// A table is a run of lines that start with a pipe; a row of dashes under the
|
|
146
|
+
// first makes it the head. A cell holds a pipe written `\|`.
|
|
147
|
+
let ROW = /^\s*\|/
|
|
148
|
+
let RULE = /^\s*\|?(\s*:?-+:?\s*\|)+\s*:?-*:?\s*$/
|
|
149
|
+
let cells = (line: string): string[] =>
|
|
150
|
+
line.trim().replace(/^\|/, '').replace(/(?<!\\)\|$/, '')
|
|
151
|
+
.split(/(?<!\\)\|/).map((c) => c.trim().replace(/\\\|/g, '|'))
|
|
152
|
+
let table = (lines: string[]) => {
|
|
153
|
+
let ruled = lines.length > 1 && RULE.test(lines[1])
|
|
154
|
+
return {
|
|
155
|
+
head: ruled ? cells(lines[0]) : undefined,
|
|
156
|
+
rows: lines.slice(ruled ? 2 : 0).map(cells),
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Mail clients drop a stylesheet, so a table's few rules ride on its cells.
|
|
161
|
+
let CELL = 'padding:2px 10px 2px 0;text-align:left;vertical-align:top'
|
|
162
|
+
|
|
163
|
+
// Quoted correspondence carries the sender's text verbatim, including markup.
|
|
164
|
+
let quotation = (lines: string[]) =>
|
|
165
|
+
lines.every((line) => line.startsWith('> '))
|
|
166
|
+
|
|
167
|
+
// A block is a run of lines between blank ones. Its first line determines what
|
|
168
|
+
// kind of block it is.
|
|
169
|
+
let block = (lines: string[], names?: Names): string => {
|
|
170
|
+
if (quotation(lines)) {
|
|
171
|
+
return '<blockquote style="white-space:pre-wrap">' +
|
|
172
|
+
escape(lines.map((line) => line.slice(2)).join('\n')) +
|
|
173
|
+
'</blockquote>'
|
|
174
|
+
}
|
|
175
|
+
let head = /^(#{1,6})\s+(.*)$/.exec(lines[0])
|
|
176
|
+
if (head) {
|
|
177
|
+
let n = head[1].length
|
|
178
|
+
return `<h${n}>${inline(head[2], names)}</h${n}>`
|
|
179
|
+
}
|
|
180
|
+
let image = lines.length == 1 && IMAGE.exec(lines[0].trim())
|
|
181
|
+
if (image) {
|
|
182
|
+
return `<p><img src="${escape(image[2])}" alt="${
|
|
183
|
+
escape(image[1])
|
|
184
|
+
}" style="max-width:100%"></p>`
|
|
185
|
+
}
|
|
186
|
+
if (lines.every((l) => ROW.test(l))) {
|
|
187
|
+
let t = table(lines)
|
|
188
|
+
let row = (cs: string[], tag: string) =>
|
|
189
|
+
`<tr>${
|
|
190
|
+
cs.map((c) => `<${tag} style="${CELL}">${inline(c, names)}</${tag}>`)
|
|
191
|
+
.join('')
|
|
192
|
+
}</tr>`
|
|
193
|
+
return `<table style="border-collapse:collapse">${
|
|
194
|
+
t.head ? `<thead>${row(t.head, 'th')}</thead>` : ''
|
|
195
|
+
}<tbody>${t.rows.map((r) => row(r, 'td')).join('')}</tbody></table>`
|
|
196
|
+
}
|
|
197
|
+
if (lines.every((l) => /^\s*[-*]\s+/.test(l))) {
|
|
198
|
+
let items = lines.map((l) =>
|
|
199
|
+
`<li>${inline(l.replace(/^\s*[-*]\s+/, ''), names)}</li>`
|
|
200
|
+
)
|
|
201
|
+
return `<ul>${items.join('')}</ul>`
|
|
202
|
+
}
|
|
203
|
+
return `<p>${lines.map((l) => inline(l, names)).join('<br>')}</p>`
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
let blocks = (body: string): string[][] =>
|
|
207
|
+
body.replace(/\r\n?/g, '\n').split(/\n\s*\n/)
|
|
208
|
+
.map((b) => b.split('\n').filter((l) => l.trim()))
|
|
209
|
+
.filter((b) => b.length)
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* A markdown body → safe HTML for the message's HTML part. Everything the body
|
|
213
|
+
* wrote is escaped; the only markup in the result is this file's own.
|
|
214
|
+
*
|
|
215
|
+
* ```ts
|
|
216
|
+
* import { html } from '@yaks/mail'
|
|
217
|
+
* html('Potluck **Friday** — [sign up](https://books.example/potluck)')
|
|
218
|
+
* // '<p>Potluck <strong>Friday</strong> — <a href="…">sign up</a></p>'
|
|
219
|
+
* ```
|
|
220
|
+
*/
|
|
221
|
+
export let html = (body: string, names?: Names): string =>
|
|
222
|
+
blocks(body).map((lines) => block(lines, names)).join('\n')
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* The same body as plain text, for the message's text part: the markup goes,
|
|
226
|
+
* the words stay, and a link keeps its address in parentheses so a reader with
|
|
227
|
+
* no HTML can still follow it.
|
|
228
|
+
*/
|
|
229
|
+
export let text = (body: string, names?: Names): string =>
|
|
230
|
+
blocks(body).map((lines) => {
|
|
231
|
+
if (quotation(lines)) return lines.join('\n')
|
|
232
|
+
let image = lines.length == 1 && IMAGE.exec(lines[0].trim())
|
|
233
|
+
if (image) return `${image[1]} (${image[2]})`
|
|
234
|
+
if (lines.every((l) => ROW.test(l))) {
|
|
235
|
+
let t = table(lines)
|
|
236
|
+
return [...t.head ? [t.head] : [], ...t.rows]
|
|
237
|
+
.map((r) => r.map((c) => flat(c, names)).join(' · ')).join('\n')
|
|
238
|
+
}
|
|
239
|
+
return lines.map((l) =>
|
|
240
|
+
flat(
|
|
241
|
+
l.replace(/^(#{1,6})\s+/, '').replace(/^\s*[-*]\s+/, '- '),
|
|
242
|
+
names,
|
|
243
|
+
)
|
|
244
|
+
).join('\n')
|
|
245
|
+
}).join('\n\n')
|
package/mod.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @yaks/mail — letters, in the graph: the mail components for a
|
|
3
|
+
* {@link https://jsr.io/@yaks/graph | @yaks/graph}.
|
|
4
|
+
*
|
|
5
|
+
* Say a book club runs on a graph. It has people, a reading list, a potluck
|
|
6
|
+
* sign-up. Sooner or later it has to write to somebody — an invitation, a
|
|
7
|
+
* reminder, an answer to a question that arrived by email — and that is this
|
|
8
|
+
* package: a letter is an entity like everything else, so it is queryable,
|
|
9
|
+
* attributable, and hangs off the thing it is about.
|
|
10
|
+
*
|
|
11
|
+
* ## A letter is an entity
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { mailDoc } from '@yaks/mail'
|
|
14
|
+
* // { entity: { eid: 'e1' },
|
|
15
|
+
* // doc: { title: 'Potluck Friday', body: 'Bring a dish.' },
|
|
16
|
+
* // mail: { from: 'hello@books.example', target: potluck },
|
|
17
|
+
* // deliver: { to: ana } }
|
|
18
|
+
* ```
|
|
19
|
+
* `mail` is the envelope, `deliver` is the request to send it, and `target` is
|
|
20
|
+
* what it is about — any entity at all. Because the recipient is an entity
|
|
21
|
+
* rather than a string, the address it goes to is whatever their
|
|
22
|
+
* {@link mailDoc | `email`} component holds at the moment it leaves.
|
|
23
|
+
*
|
|
24
|
+
* ## The subject and the body are a `doc` They are `doc{title, body}`, from
|
|
25
|
+
* {@link https://jsr.io/@yaks/doc | @yaks/doc}, which this package depends on.
|
|
26
|
+
* The words a person reads belong in the one component every readable thing
|
|
27
|
+
* has, so a letter is searched, rendered and edited by whatever already handles
|
|
28
|
+
* a `doc` — instead of by a second copy of the same two properties.
|
|
29
|
+
*
|
|
30
|
+
* Compose `docs()` beside {@link mailbox}, never inside it: a vocabulary
|
|
31
|
+
* rejects a component declared twice, so an application that already declares
|
|
32
|
+
* `doc` is not fought over it.
|
|
33
|
+
*
|
|
34
|
+
* ## Sending is an effect, not a write
|
|
35
|
+
* Nothing in `apply()` talks to a mail server. {@link sending} is a
|
|
36
|
+
* `created(mail)` handler on {@link https://jsr.io/@yaks/effects | @yaks/effects}:
|
|
37
|
+
* it runs after the transaction commits, hands the letter to the
|
|
38
|
+
* {@link Sender} the caller supplied, and writes back what happened —
|
|
39
|
+
* `delivered{at}` or `bounced{at, reason}`. So the write cannot fail
|
|
40
|
+
* because a mail server is down, and "what became of that letter?" is a query.
|
|
41
|
+
*
|
|
42
|
+
* {@link post} selects a sender by name from those the host lends: a
|
|
43
|
+
* provider's, lent by its own plugin (@yaks/resend, @yaks/cloudflare-mail),
|
|
44
|
+
* or the host's own. {@link stash} is built in, for tests and development.
|
|
45
|
+
*
|
|
46
|
+
* ## Receiving is a pure function {@link inbound} turns a message as an Email
|
|
47
|
+
* Worker receives it into the bundles that record it. It queries the graph for
|
|
48
|
+
* nothing, so it can be tested without one. The two properties that are lookups
|
|
49
|
+
* — whom the letter is about, which letter it answers — are answered by {@link
|
|
50
|
+
* arrived} one file over, where there is a graph to query, and
|
|
51
|
+
* `@yaks/mail/routes` exports the HTTP route a mail edge posts a letter on.
|
|
52
|
+
*
|
|
53
|
+
* ## The worked example
|
|
54
|
+
* {@link invited} fills the `created(member)` handler slot
|
|
55
|
+
* {@link https://jsr.io/@yaks/member | @yaks/member} documents and leaves
|
|
56
|
+
* empty: somebody joins the club, and an invitation is written — the sending
|
|
57
|
+
* effect carries it like any other letter.
|
|
58
|
+
*
|
|
59
|
+
* ```ts
|
|
60
|
+
* import { graph } from '@yaks/graph'
|
|
61
|
+
* import { effects } from '@yaks/effects'
|
|
62
|
+
* import { ram } from '@yaks/ram'
|
|
63
|
+
* import { loadVocab } from '@yaks/vocab'
|
|
64
|
+
* import { docDoc, docs } from '@yaks/doc'
|
|
65
|
+
* import { memberDoc } from '@yaks/member'
|
|
66
|
+
* import { invited, mailbox, mailDoc, stash } from '@yaks/mail'
|
|
67
|
+
*
|
|
68
|
+
* let vocab = loadVocab([docDoc, mailDoc, memberDoc])
|
|
69
|
+
* let fx = effects(vocab, { write: (b) => g.apply(b, { trusted: true }) })
|
|
70
|
+
* let post = stash()
|
|
71
|
+
* let box = mailbox({ domain: 'books.example', sender: post, effects: fx })
|
|
72
|
+
* let g = graph({ storage: ram(vocab), vocab, plugins: [fx, docs(), box] })
|
|
73
|
+
*
|
|
74
|
+
* fx.created('member', invited({
|
|
75
|
+
* apply: (bundles) => g.apply(bundles),
|
|
76
|
+
* welcome: () => ({
|
|
77
|
+
* from: 'hello@books.example',
|
|
78
|
+
* subject: 'You are in the book club',
|
|
79
|
+
* body: 'Welcome. We meet Thursdays.',
|
|
80
|
+
* }),
|
|
81
|
+
* }))
|
|
82
|
+
* ```
|
|
83
|
+
*
|
|
84
|
+
* ## What is deliberately not here
|
|
85
|
+
* MIME parsing (pass {@link inbound} the text — a parser is a parser's job),
|
|
86
|
+
* queues and retries (a bounced letter is data; writing a fresh one is the
|
|
87
|
+
* retry), and any credential of any kind.
|
|
88
|
+
*
|
|
89
|
+
* The core — the vocabulary, {@link canon}, {@link inbound}, {@link sending} —
|
|
90
|
+
* imports no platform API, so it runs on a server, in a Worker, and in a
|
|
91
|
+
* browser tab. No mail provider lives here.
|
|
92
|
+
*
|
|
93
|
+
* @module
|
|
94
|
+
*/ export * from "./comp.js";
|
|
95
|
+
export * from "./addr.js";
|
|
96
|
+
export * from "./md.js";
|
|
97
|
+
export * from "./send.js";
|
|
98
|
+
export * from "./stash.js";
|
|
99
|
+
export * from "./transport.js";
|
|
100
|
+
export * from "./inbound.js";
|
|
101
|
+
export * from "./arrive.js";
|
|
102
|
+
export * from "./invite.js";
|
|
103
|
+
export * from "./plugin.js";
|
|
104
|
+
export * from "./recipient.js";
|
|
105
|
+
export * from "./options.js";
|
|
106
|
+
export * from "./pull.js";
|
|
107
|
+
export * from "./capture.js";
|
|
108
|
+
export { deliveryField, receipted } from "./receipts.js";
|
|
109
|
+
//# sourceMappingURL=mod.js.map
|
package/mod.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.js","sources":["./mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6FC,GAED,0BAAyB;AACzB,0BAAyB;AACzB,wBAAuB;AACvB,0BAAyB;AACzB,2BAA0B;AAC1B,+BAA8B;AAC9B,6BAA4B;AAC5B,4BAA2B;AAC3B,4BAA2B;AAC3B,4BAA2B;AAC3B,+BAA8B;AAC9B,6BAA4B;AAC5B,0BAAyB;AACzB,6BAA4B;AAE5B,SAAS,aAAa,EAAE,SAAS,wBAAuB"}
|
package/mod.ts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @yaks/mail — letters, in the graph: the mail components for a
|
|
3
|
+
* {@link https://jsr.io/@yaks/graph | @yaks/graph}.
|
|
4
|
+
*
|
|
5
|
+
* Say a book club runs on a graph. It has people, a reading list, a potluck
|
|
6
|
+
* sign-up. Sooner or later it has to write to somebody — an invitation, a
|
|
7
|
+
* reminder, an answer to a question that arrived by email — and that is this
|
|
8
|
+
* package: a letter is an entity like everything else, so it is queryable,
|
|
9
|
+
* attributable, and hangs off the thing it is about.
|
|
10
|
+
*
|
|
11
|
+
* ## A letter is an entity
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { mailDoc } from '@yaks/mail'
|
|
14
|
+
* // { entity: { eid: 'e1' },
|
|
15
|
+
* // doc: { title: 'Potluck Friday', body: 'Bring a dish.' },
|
|
16
|
+
* // mail: { from: 'hello@books.example', target: potluck },
|
|
17
|
+
* // deliver: { to: ana } }
|
|
18
|
+
* ```
|
|
19
|
+
* `mail` is the envelope, `deliver` is the request to send it, and `target` is
|
|
20
|
+
* what it is about — any entity at all. Because the recipient is an entity
|
|
21
|
+
* rather than a string, the address it goes to is whatever their
|
|
22
|
+
* {@link mailDoc | `email`} component holds at the moment it leaves.
|
|
23
|
+
*
|
|
24
|
+
* ## The subject and the body are a `doc` They are `doc{title, body}`, from
|
|
25
|
+
* {@link https://jsr.io/@yaks/doc | @yaks/doc}, which this package depends on.
|
|
26
|
+
* The words a person reads belong in the one component every readable thing
|
|
27
|
+
* has, so a letter is searched, rendered and edited by whatever already handles
|
|
28
|
+
* a `doc` — instead of by a second copy of the same two properties.
|
|
29
|
+
*
|
|
30
|
+
* Compose `docs()` beside {@link mailbox}, never inside it: a vocabulary
|
|
31
|
+
* rejects a component declared twice, so an application that already declares
|
|
32
|
+
* `doc` is not fought over it.
|
|
33
|
+
*
|
|
34
|
+
* ## Sending is an effect, not a write
|
|
35
|
+
* Nothing in `apply()` talks to a mail server. {@link sending} is a
|
|
36
|
+
* `created(mail)` handler on {@link https://jsr.io/@yaks/effects | @yaks/effects}:
|
|
37
|
+
* it runs after the transaction commits, hands the letter to the
|
|
38
|
+
* {@link Sender} the caller supplied, and writes back what happened —
|
|
39
|
+
* `delivered{at}` or `bounced{at, reason}`. So the write cannot fail
|
|
40
|
+
* because a mail server is down, and "what became of that letter?" is a query.
|
|
41
|
+
*
|
|
42
|
+
* {@link post} selects a sender by name from those the host lends: a
|
|
43
|
+
* provider's, lent by its own plugin (@yaks/resend, @yaks/cloudflare-mail),
|
|
44
|
+
* or the host's own. {@link stash} is built in, for tests and development.
|
|
45
|
+
*
|
|
46
|
+
* ## Receiving is a pure function {@link inbound} turns a message as an Email
|
|
47
|
+
* Worker receives it into the bundles that record it. It queries the graph for
|
|
48
|
+
* nothing, so it can be tested without one. The two properties that are lookups
|
|
49
|
+
* — whom the letter is about, which letter it answers — are answered by {@link
|
|
50
|
+
* arrived} one file over, where there is a graph to query, and
|
|
51
|
+
* `@yaks/mail/routes` exports the HTTP route a mail edge posts a letter on.
|
|
52
|
+
*
|
|
53
|
+
* ## The worked example
|
|
54
|
+
* {@link invited} fills the `created(member)` handler slot
|
|
55
|
+
* {@link https://jsr.io/@yaks/member | @yaks/member} documents and leaves
|
|
56
|
+
* empty: somebody joins the club, and an invitation is written — the sending
|
|
57
|
+
* effect carries it like any other letter.
|
|
58
|
+
*
|
|
59
|
+
* ```ts
|
|
60
|
+
* import { graph } from '@yaks/graph'
|
|
61
|
+
* import { effects } from '@yaks/effects'
|
|
62
|
+
* import { ram } from '@yaks/ram'
|
|
63
|
+
* import { loadVocab } from '@yaks/vocab'
|
|
64
|
+
* import { docDoc, docs } from '@yaks/doc'
|
|
65
|
+
* import { memberDoc } from '@yaks/member'
|
|
66
|
+
* import { invited, mailbox, mailDoc, stash } from '@yaks/mail'
|
|
67
|
+
*
|
|
68
|
+
* let vocab = loadVocab([docDoc, mailDoc, memberDoc])
|
|
69
|
+
* let fx = effects(vocab, { write: (b) => g.apply(b, { trusted: true }) })
|
|
70
|
+
* let post = stash()
|
|
71
|
+
* let box = mailbox({ domain: 'books.example', sender: post, effects: fx })
|
|
72
|
+
* let g = graph({ storage: ram(vocab), vocab, plugins: [fx, docs(), box] })
|
|
73
|
+
*
|
|
74
|
+
* fx.created('member', invited({
|
|
75
|
+
* apply: (bundles) => g.apply(bundles),
|
|
76
|
+
* welcome: () => ({
|
|
77
|
+
* from: 'hello@books.example',
|
|
78
|
+
* subject: 'You are in the book club',
|
|
79
|
+
* body: 'Welcome. We meet Thursdays.',
|
|
80
|
+
* }),
|
|
81
|
+
* }))
|
|
82
|
+
* ```
|
|
83
|
+
*
|
|
84
|
+
* ## What is deliberately not here
|
|
85
|
+
* MIME parsing (pass {@link inbound} the text — a parser is a parser's job),
|
|
86
|
+
* queues and retries (a bounced letter is data; writing a fresh one is the
|
|
87
|
+
* retry), and any credential of any kind.
|
|
88
|
+
*
|
|
89
|
+
* The core — the vocabulary, {@link canon}, {@link inbound}, {@link sending} —
|
|
90
|
+
* imports no platform API, so it runs on a server, in a Worker, and in a
|
|
91
|
+
* browser tab. No mail provider lives here.
|
|
92
|
+
*
|
|
93
|
+
* @module
|
|
94
|
+
*/
|
|
95
|
+
|
|
96
|
+
export * from './comp.js'
|
|
97
|
+
export * from './addr.js'
|
|
98
|
+
export * from './md.js'
|
|
99
|
+
export * from './send.js'
|
|
100
|
+
export * from './stash.js'
|
|
101
|
+
export * from './transport.js'
|
|
102
|
+
export * from './inbound.js'
|
|
103
|
+
export * from './arrive.js'
|
|
104
|
+
export * from './invite.js'
|
|
105
|
+
export * from './plugin.js'
|
|
106
|
+
export * from './recipient.js'
|
|
107
|
+
export * from './options.js'
|
|
108
|
+
export * from './pull.js'
|
|
109
|
+
export * from './capture.js'
|
|
110
|
+
|
|
111
|
+
export { deliveryField, receipted } from './receipts.js'
|
package/options.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// What a config passes to this plugin, in one place, because all four of its
|
|
2
|
+
// entry points read it: `./graph` reads the domain, `./effects` reads the
|
|
3
|
+
// transport, `./routes` reads the HTTP route settings, `./service` reads the
|
|
4
|
+
// edge it pulls from. One options type, one file — putting the type in one of
|
|
5
|
+
// those modules would give it fields it never reads.
|
|
6
|
+
//
|
|
7
|
+
// ```json
|
|
8
|
+
// { "use": "@yaks/mail",
|
|
9
|
+
// "with": { "domain": "books.example",
|
|
10
|
+
// "triage": "…",
|
|
11
|
+
// "sender": { "via": "cloudflare" },
|
|
12
|
+
// "door": { "secret": { "secret": "MAIL_DOOR_SECRET" } },
|
|
13
|
+
// "pull": { "url": "https://edge.books.example",
|
|
14
|
+
// "token": { "secret": "EDGE_TOKEN" } } } }
|
|
15
|
+
// ```
|
|
16
|
+
//
|
|
17
|
+
// The sender is lent by the plugin listed beside it, which holds its
|
|
18
|
+
// credentials: `{ "use": "@yaks/cloudflare-mail", "with": { "account": "…",
|
|
19
|
+
// "token": { "secret": "CF_EMAIL_TOKEN" } } }`.
|
|
20
|
+
//
|
|
21
|
+
// Nothing here holds a secret: `{"secret": "NAME"}` anywhere in the object is
|
|
22
|
+
// that secret's value at the moment it is read (@yaks/cli, @yaks/secrets), so
|
|
23
|
+
// the file is committable and the token is not in it.
|
|
24
|
+
//# sourceMappingURL=options.js.map
|
package/options.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","sources":["./options.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,0EAA0E;AAC1E,6EAA6E;AAC7E,8EAA8E;AAC9E,qDAAqD;AACrD,EAAE;AACF,UAAU;AACV,yBAAyB;AACzB,yCAAyC;AACzC,6BAA6B;AAC7B,iDAAiD;AACjD,sEAAsE;AACtE,6DAA6D;AAC7D,kEAAkE;AAClE,MAAM;AACN,EAAE;AACF,qEAAqE;AACrE,4EAA4E;AAC5E,gDAAgD;AAChD,EAAE;AACF,8EAA8E;AAC9E,8EAA8E;AAC9E,sDAAsD"}
|
package/options.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// What a config passes to this plugin, in one place, because all four of its
|
|
2
|
+
// entry points read it: `./graph` reads the domain, `./effects` reads the
|
|
3
|
+
// transport, `./routes` reads the HTTP route settings, `./service` reads the
|
|
4
|
+
// edge it pulls from. One options type, one file — putting the type in one of
|
|
5
|
+
// those modules would give it fields it never reads.
|
|
6
|
+
//
|
|
7
|
+
// ```json
|
|
8
|
+
// { "use": "@yaks/mail",
|
|
9
|
+
// "with": { "domain": "books.example",
|
|
10
|
+
// "triage": "…",
|
|
11
|
+
// "sender": { "via": "cloudflare" },
|
|
12
|
+
// "door": { "secret": { "secret": "MAIL_DOOR_SECRET" } },
|
|
13
|
+
// "pull": { "url": "https://edge.books.example",
|
|
14
|
+
// "token": { "secret": "EDGE_TOKEN" } } } }
|
|
15
|
+
// ```
|
|
16
|
+
//
|
|
17
|
+
// The sender is lent by the plugin listed beside it, which holds its
|
|
18
|
+
// credentials: `{ "use": "@yaks/cloudflare-mail", "with": { "account": "…",
|
|
19
|
+
// "token": { "secret": "CF_EMAIL_TOKEN" } } }`.
|
|
20
|
+
//
|
|
21
|
+
// Nothing here holds a secret: `{"secret": "NAME"}` anywhere in the object is
|
|
22
|
+
// that secret's value at the moment it is read (@yaks/cli, @yaks/secrets), so
|
|
23
|
+
// the file is committable and the token is not in it.
|
|
24
|
+
|
|
25
|
+
import type { Eid } from 'jsr:@yaks/graph@0.2.36'
|
|
26
|
+
|
|
27
|
+
/** What a config passes to @yaks/mail. */
|
|
28
|
+
export type Options = {
|
|
29
|
+
/** the sender address a host supplies for an app's own mailbox */
|
|
30
|
+
from?: () => string | null
|
|
31
|
+
/** your own mail domain — the addresses this graph canonicalizes on write */
|
|
32
|
+
domain?: string
|
|
33
|
+
/** whether `domain` belongs to this graph rather than to a mail server: a
|
|
34
|
+
* letter to an address there is delivered by writing it, never handed to the
|
|
35
|
+
* transport. True where the addresses at your domain are entities here (an
|
|
36
|
+
* agent, a project); false where somebody reads them in a mail client. */
|
|
37
|
+
local?: boolean
|
|
38
|
+
/** where a letter addressed to nobody this graph knows lands — the triage
|
|
39
|
+
* entity, for letters posted to the door and letters pulled from an edge
|
|
40
|
+
* alike. With none, such a letter is recorded with no target. */
|
|
41
|
+
triage?: Eid
|
|
42
|
+
/** where an entity a letter names opens: an address with `{id}` where its
|
|
43
|
+
* id goes (`https://tasks.yak.sh/{id}`). Each entity a body names then reads
|
|
44
|
+
* as its id linked there; with none, as its id alone. */
|
|
45
|
+
mentions?: string
|
|
46
|
+
/** the transport outbound letters go through; with none, none are sent */
|
|
47
|
+
sender?: Transport
|
|
48
|
+
/** where letters arrive, and who may post one to this graph */
|
|
49
|
+
door?: Door
|
|
50
|
+
/** the edge this graph pulls arrivals from, where the edge cannot reach the
|
|
51
|
+
* graph to post them; with none, nothing is pulled */
|
|
52
|
+
pull?: Pull
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The sender outbound letters go through, by the name the host lends it
|
|
56
|
+
* under: a provider plugin's (`resend`, `cloudflare`), the host's own, or the
|
|
57
|
+
* built-in `stash`. */
|
|
58
|
+
export type Transport = {
|
|
59
|
+
/** a name in Host.senders, or `stash` */
|
|
60
|
+
via: string
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** The arrival endpoint: where a mail edge posts a letter, and what it must
|
|
64
|
+
* present. */
|
|
65
|
+
export type Door = {
|
|
66
|
+
/** the path it answers on (default `/mail/inbound`) */
|
|
67
|
+
path?: string
|
|
68
|
+
/** the bearer token the mail edge presents. Set none and the endpoint
|
|
69
|
+
* takes no letter. */
|
|
70
|
+
secret?: string
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** The edge arrivals are pulled from (./pull.ts): the letters that came to
|
|
74
|
+
* your domain, and the requests posted to its hook paths, held until this
|
|
75
|
+
* graph takes them. */
|
|
76
|
+
export type Pull = {
|
|
77
|
+
/** the edge's API root */
|
|
78
|
+
url: string
|
|
79
|
+
/** the bearer token it asks for — `{"secret": "…"}` in the config */
|
|
80
|
+
token: string
|
|
81
|
+
/** how long to wait between pulls, in milliseconds (default ten seconds) */
|
|
82
|
+
every?: number
|
|
83
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,68 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yaks/mail",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.36",
|
|
4
|
+
"homepage": "https://jsr.io/@yaks/mail",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./_dist/mod.d.ts",
|
|
9
|
+
"default": "./mod.js"
|
|
10
|
+
},
|
|
11
|
+
"./addr": {
|
|
12
|
+
"types": "./_dist/addr.d.ts",
|
|
13
|
+
"default": "./addr.js"
|
|
14
|
+
},
|
|
15
|
+
"./vocab": {
|
|
16
|
+
"types": "./_dist/vocab.d.ts",
|
|
17
|
+
"default": "./vocab.js"
|
|
18
|
+
},
|
|
19
|
+
"./answers": {
|
|
20
|
+
"types": "./_dist/answers.d.ts",
|
|
21
|
+
"default": "./answers.js"
|
|
22
|
+
},
|
|
23
|
+
"./graph": {
|
|
24
|
+
"types": "./_dist/graph.d.ts",
|
|
25
|
+
"default": "./graph.js"
|
|
26
|
+
},
|
|
27
|
+
"./tools": {
|
|
28
|
+
"types": "./_dist/tools.d.ts",
|
|
29
|
+
"default": "./tools.js"
|
|
30
|
+
},
|
|
31
|
+
"./effects": {
|
|
32
|
+
"types": "./_dist/effects.d.ts",
|
|
33
|
+
"default": "./effects.js"
|
|
34
|
+
},
|
|
35
|
+
"./routes": {
|
|
36
|
+
"types": "./_dist/routes.d.ts",
|
|
37
|
+
"default": "./routes.js"
|
|
38
|
+
},
|
|
39
|
+
"./service": {
|
|
40
|
+
"types": "./_dist/service.d.ts",
|
|
41
|
+
"default": "./service.js"
|
|
42
|
+
},
|
|
43
|
+
"./gmail": {
|
|
44
|
+
"types": "./_dist/gmail.d.ts",
|
|
45
|
+
"default": "./gmail.js"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"license": "Apache-2.0",
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@yaks/api": "0.2.36",
|
|
51
|
+
"@yaks/cli": "0.2.36",
|
|
52
|
+
"@yaks/doc": "0.2.36",
|
|
53
|
+
"@yaks/edge": "0.2.36",
|
|
54
|
+
"@yaks/effects": "0.2.36",
|
|
55
|
+
"@yaks/fp": "0.2.36",
|
|
56
|
+
"@yaks/graph": "0.2.36",
|
|
57
|
+
"@yaks/hook": "0.2.36",
|
|
58
|
+
"@yaks/host": "0.2.36",
|
|
59
|
+
"@yaks/id": "0.2.36",
|
|
60
|
+
"@yaks/notify": "0.2.36",
|
|
61
|
+
"@yaks/query": "0.2.36",
|
|
62
|
+
"@yaks/tools": "0.2.36",
|
|
63
|
+
"@yaks/vocab": "0.2.36",
|
|
64
|
+
"postal-mime": "3.0.0"
|
|
65
|
+
},
|
|
66
|
+
"description": "Represents letters and their delivery outcomes as graph components, sends them through a sender the caller supplies, and converts arrivals to bundles.",
|
|
67
|
+
"repository": "https://github.com/yak-sh/yak.git"
|
|
68
|
+
}
|