@yaks/inbox 0.0.0-stage → 0.2.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/LICENSE +202 -0
  2. package/Person.tsx +275 -0
  3. package/Project.tsx +83 -0
  4. package/README.md +311 -2
  5. package/_dist/actions-browser.d.ts +8 -0
  6. package/_dist/actions-browser.d.ts.map +1 -0
  7. package/_dist/actions.d.ts +22 -0
  8. package/_dist/actions.d.ts.map +1 -0
  9. package/_dist/asks.d.ts +15 -0
  10. package/_dist/asks.d.ts.map +1 -0
  11. package/_dist/graph.d.ts +12 -0
  12. package/_dist/graph.d.ts.map +1 -0
  13. package/_dist/letters.d.ts +24 -0
  14. package/_dist/letters.d.ts.map +1 -0
  15. package/_dist/mail.d.ts +4 -0
  16. package/_dist/mail.d.ts.map +1 -0
  17. package/_dist/mod.d.ts +7 -0
  18. package/_dist/mod.d.ts.map +1 -0
  19. package/_dist/options.d.ts +18 -0
  20. package/_dist/options.d.ts.map +1 -0
  21. package/_dist/queries.d.ts +23 -0
  22. package/_dist/queries.d.ts.map +1 -0
  23. package/_dist/read.d.ts +18 -0
  24. package/_dist/read.d.ts.map +1 -0
  25. package/_dist/reader.d.ts +25 -0
  26. package/_dist/reader.d.ts.map +1 -0
  27. package/_dist/service.d.ts +8 -0
  28. package/_dist/service.d.ts.map +1 -0
  29. package/_dist/threads.d.ts +33 -0
  30. package/_dist/threads.d.ts.map +1 -0
  31. package/_dist/tools.d.ts +12 -0
  32. package/_dist/tools.d.ts.map +1 -0
  33. package/_dist/vocab.d.ts +5 -0
  34. package/_dist/vocab.d.ts.map +1 -0
  35. package/actions-browser.js +165 -0
  36. package/actions-browser.js.map +1 -0
  37. package/actions-browser.ts +158 -0
  38. package/actions.js +34 -0
  39. package/actions.js.map +1 -0
  40. package/actions.ts +53 -0
  41. package/asks.js +76 -0
  42. package/asks.js.map +1 -0
  43. package/asks.ts +94 -0
  44. package/deno.json +1 -0
  45. package/front.js +41 -0
  46. package/front.js.map +1 -0
  47. package/front.json +68 -0
  48. package/front.ts +38 -0
  49. package/graph.js +176 -0
  50. package/graph.js.map +1 -0
  51. package/graph.ts +182 -0
  52. package/inspect.tsx +22 -0
  53. package/letters.js +233 -0
  54. package/letters.js.map +1 -0
  55. package/letters.ts +325 -0
  56. package/mail.js +122 -0
  57. package/mail.js.map +1 -0
  58. package/mail.ts +148 -0
  59. package/mod.js +11 -0
  60. package/mod.js.map +1 -0
  61. package/mod.ts +24 -0
  62. package/options.js +15 -0
  63. package/options.js.map +1 -0
  64. package/options.ts +42 -0
  65. package/package.json +76 -4
  66. package/queries.js +240 -0
  67. package/queries.js.map +1 -0
  68. package/queries.ts +302 -0
  69. package/read.js +453 -0
  70. package/read.js.map +1 -0
  71. package/read.ts +476 -0
  72. package/reader.js +105 -0
  73. package/reader.js.map +1 -0
  74. package/reader.ts +147 -0
  75. package/service.js +29 -0
  76. package/service.js.map +1 -0
  77. package/service.ts +45 -0
  78. package/threads.js +182 -0
  79. package/threads.js.map +1 -0
  80. package/threads.ts +276 -0
  81. package/tools.js +101 -0
  82. package/tools.js.map +1 -0
  83. package/tools.ts +103 -0
  84. package/views.tsx +30 -0
  85. package/vocab.js +12 -0
  86. package/vocab.js.map +1 -0
  87. package/vocab.json +242 -0
  88. package/vocab.ts +11 -0
package/mail.js ADDED
@@ -0,0 +1,122 @@
1
+ // The `./mail` facet: what the inbox's email door makes of a letter that
2
+ // arrived. @yaks/mail records the letter and asks each configured package's
3
+ // reading (@yaks/mail `Reading`); this is the inbox's, and it answers only
4
+ // where the config opened a door (./options.ts `person`).
5
+ //
6
+ // Two things a letter can mean here. A verified letter from the person to the
7
+ // inbox address, answering nothing, is a new conversation: the received
8
+ // entity keeps its envelope and gains `conversation{}`, with their words as its
9
+ // doc. A verified reply from whom a thread letter was sent to, or from the
10
+ // person to a thread's own address, is a comment in that thread, and a number
11
+ // or words answering its open decision answer it.
12
+ //
13
+ // Provenance is checked first, independently of the person: a sender that is a
14
+ // session, effect, call, output or transcript entry, the inbox address itself, or `Auto-Submitted` other than `no` is kept as mail only. DKIM
15
+ // authenticates a sending domain, not whether a person or an automation typed
16
+ // the words.
17
+ import { line } from "@yaks/query";
18
+ import { answer } from "@yaks/task";
19
+ let comp = (b, name)=>b?.[name] ?? {};
20
+ let str = (v)=>String(v ?? '');
21
+ /** The new words, without the quoted conversation or a conventional signature. */ let unquoted = (body)=>body.split(/\r?\n(?:On .+wrote:|>.*|--\s*$)/m)[0].trim();
22
+ /** The number shown in the letter, or a custom answer. Out-of-range numbers
23
+ * remain comments rather than silently becoming custom decision answers. */ let choice = (body, decision)=>{
24
+ let text = unquoted(body);
25
+ return /^\d+$/.test(text) ? decision.choices[Number(text) - 1]?.label ?? '' : text;
26
+ };
27
+ /** Keep the received envelope even when its author cannot act on the thread.
28
+ * DKIM is the receiving edge's verdict, never an assertion in the body. */ let replied = async (graph, letter, parent, by, owner)=>{
29
+ if (!parent?.mail_notice && !owner) return [
30
+ letter
31
+ ];
32
+ let mail = comp(letter, 'mail');
33
+ let prior = comp(parent, 'mail');
34
+ if (parent?.mail_notice && !prior.target) return [
35
+ letter
36
+ ];
37
+ let target = parent?.conversation ? parent.entity.eid : str(prior.target || mail.target);
38
+ if (!by || mail.verified != true || !target) return [
39
+ letter
40
+ ];
41
+ let recipient = str(comp(parent, 'deliver').to);
42
+ // A stored outgoing envelope proves whom we asked. Without it, only an
43
+ // explicitly enabled inbox recipient can act via a thread's email address.
44
+ if (parent?.deliver ? recipient != by : owner != by) return [
45
+ letter
46
+ ];
47
+ let addressed = (await graph.read(line`.entity.eid=${target}`))[0];
48
+ let ancestor = str(comp(addressed, 'comment').target);
49
+ let root = ancestor ? (await graph.read(line`.entity.eid=${ancestor}`))[0] : addressed;
50
+ if (ancestor) target = ancestor;
51
+ if (!root || root.mail && !root.conversation || !(root.task || root.design || root.session || root.bug || root.project || root.doc)) return [
52
+ letter
53
+ ];
54
+ let replyTo = (parent?.comment ? parent.entity.eid : str(comp(parent, 'mail_notice').comment)) || (ancestor ? addressed.entity.eid : '');
55
+ let out = {
56
+ ...letter,
57
+ mail: {
58
+ ...mail,
59
+ target
60
+ },
61
+ comment: {
62
+ target,
63
+ ...replyTo ? {
64
+ reply_to: replyTo
65
+ } : {}
66
+ }
67
+ };
68
+ let decision = root.decision;
69
+ let picked = decision ? choice(str(comp(letter, 'doc').body), decision) : '';
70
+ let assigned = str(comp(root, 'filed').assignee);
71
+ let canAnswer = !assigned || assigned == by;
72
+ return [
73
+ out,
74
+ ...picked && canAnswer && !root.decided && !root.cancelled && !root.completed ? answer(target, picked).map((b)=>({
75
+ ...b,
76
+ $actor: {
77
+ by
78
+ }
79
+ })) : []
80
+ ];
81
+ };
82
+ let one = async (graph, eid)=>(await graph.read(line`.entity.eid=${eid}`))[0];
83
+ /** Whether a letter is a person's own words from outside: not a known
84
+ * session, effect, call, output or transcript entry, not the inbox address
85
+ * writing to itself, and not a letter that says it was automatic. */ let external = async ({ graph, message, letter, by, canonical }, from)=>{
86
+ let writer = by ? await one(graph, by) : undefined;
87
+ let automatic = message.headers.get('auto-submitted')?.trim().toLowerCase();
88
+ return !(writer?.session || writer?.effect || writer?.call || writer?.output || writer?.entry || automatic && automatic != 'no' || from && canonical(str(comp(letter, 'mail').from)) == canonical(from));
89
+ };
90
+ /** The inbox's reading of an arrival, where the options open a door. */ export let reading = (options = {})=>{
91
+ let { person, from } = options;
92
+ if (!person) return;
93
+ return async (read)=>{
94
+ let { graph, message, arrival, letter, reply, by, canonical } = read;
95
+ if (!await external(read, from)) return;
96
+ // A reply whose parent is unknown is still a reply, never a fresh request.
97
+ // External provenance was checked first; the person filter and the
98
+ // verification fail closed before a conversation mark is added. The
99
+ // envelope stays on the conversation itself, so Message-ID deduplication
100
+ // and later email replies use the same root.
101
+ let mail = letter.mail;
102
+ let text = arrival.text ?? '';
103
+ if (from && by == person && mail.verified == true && canonical(message.to) == canonical(from) && !arrival.target && !reply && !message.headers.get('in-reply-to') && !message.headers.get('references') && text.trim()) {
104
+ let { target: _target, ...envelope } = mail;
105
+ return [
106
+ {
107
+ ...letter,
108
+ mail: envelope,
109
+ conversation: {},
110
+ doc: {
111
+ title: text.split(/\r?\n/, 1)[0],
112
+ body: text
113
+ }
114
+ }
115
+ ];
116
+ }
117
+ let parent = reply ? await one(graph, reply) : undefined;
118
+ let said = await replied(graph, letter, parent, by, person);
119
+ return said.length == 1 && said[0] == letter ? undefined : said;
120
+ };
121
+ };
122
+ //# sourceMappingURL=mail.js.map
package/mail.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mail.js","sources":["./mail.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,4EAA4E;AAC5E,2EAA2E;AAC3E,0DAA0D;AAC1D,EAAE;AACF,8EAA8E;AAC9E,wEAAwE;AACxE,gFAAgF;AAChF,2EAA2E;AAC3E,8EAA8E;AAC9E,kDAAkD;AAClD,EAAE;AACF,+EAA+E;AAC/E,8IAA8I;AAC9I,8EAA8E;AAC9E,aAAa;AAGb,SAAS,IAAI,2BAAgC;AAE7C,SAAS,MAAM,0BAA8C;AAG7D,IAAI,OAAO,CAAC,GAAuB,OACjC,GAAG,CAAC,KAAK,IAAY,CAAC;AACxB,IAAI,MAAM,CAAC,IAAe,OAAO,KAAK;AAEtC,gFAAgF,GAChF,IAAI,WAAW,CAAC,OACd,KAAK,KAAK,CAAC,mCAAmC,CAAC,EAAE,CAAC,IAAI;AAExD;0EAC0E,GAC1E,IAAI,SAAS,CAAC,MAAc;EAC1B,IAAI,OAAO,SAAS;EACpB,OAAO,QAAQ,IAAI,CAAC,QAChB,SAAS,OAAO,CAAC,OAAO,QAAQ,EAAE,EAAE,SAAS,KAC7C;AACN;AAEA;yEACyE,GACzE,IAAI,UAAU,OACZ,OACA,QACA,QACA,IACA;EAEA,IAAI,CAAC,QAAQ,eAAe,CAAC,OAAO,OAAO;IAAC;GAAO;EACnD,IAAI,OAAO,KAAK,QAAQ;EACx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,GAAG;IAChE,IAAI,CAAC,MAAM,SAAS,MAAM,OAAO;IACjC,2EAA2E;IAC3E,mEAAmE;IACnE,oEAAoE;IACpE,yEAAyE;IACzE,6CAA6C;IAC7C,IAAI,OAAO,OAAO,IAAI;IACtB,IAAI,OAAO,QAAQ,IAAI,IAAI;IAC3B,IACE,QAAQ,MAAM,UAAU,KAAK,QAAQ,IAAI,QACzC,UAAU,QAAQ,EAAE,KAAK,UAAU,SACnC,CAAC,QAAQ,MAAM,IAAI,CAAC,SAAS,CAAC,QAAQ,OAAO,CAAC,GAAG,CAAC,kBAClD,CAAC,QAAQ,OAAO,CAAC,GAAG,CAAC,iBAAiB,KAAK,IAAI,IAC/C;MACA,IAAI,EAAE,QAAQ,OAAO,EAAE,GAAG,UAAU,GAAG;MACvC,OAAO;QAAC;UACN,GAAG,MAAM;UACT,MAAM;UACN,cAAc,CAAC;UACf,KAAK;YAAE,OAAO,KAAK,KAAK,CAAC,SAAS,EAAE,CAAC,EAAE;YAAE,MAAM;UAAK;QACtD;OAAE;IACJ;IACA,IAAI,SAAS,QAAQ,MAAM,IAAI,OAAO,SAAS;IAC/C,IAAI,OAAO,MAAM,QAAQ,OAAO,QAAQ,QAAQ,IAAI;IACpD,OAAO,KAAK,MAAM,IAAI,KAAK,IAAI,CAAC,EAAE,IAAI,SAAS,YAAY;EAC7D;AACF,EAAC"}
package/mail.ts ADDED
@@ -0,0 +1,148 @@
1
+ // The `./mail` facet: what the inbox's email door makes of a letter that
2
+ // arrived. @yaks/mail records the letter and asks each configured package's
3
+ // reading (@yaks/mail `Reading`); this is the inbox's, and it answers only
4
+ // where the config opened a door (./options.ts `person`).
5
+ //
6
+ // Two things a letter can mean here. A verified letter from the person to the
7
+ // inbox address, answering nothing, is a new conversation: the received
8
+ // entity keeps its envelope and gains `conversation{}`, with their words as its
9
+ // doc. A verified reply from whom a thread letter was sent to, or from the
10
+ // person to a thread's own address, is a comment in that thread, and a number
11
+ // or words answering its open decision answer it.
12
+ //
13
+ // Provenance is checked first, independently of the person: a sender that is a
14
+ // session, effect, call, output or transcript entry, the inbox address itself, or `Auto-Submitted` other than `no` is kept as mail only. DKIM
15
+ // authenticates a sending domain, not whether a person or an automation typed
16
+ // the words.
17
+
18
+ import type { Bundle, Comp, Eid } from 'jsr:@yaks/graph@0.2.36'
19
+ import { line } from '@yaks/query'
20
+ import type { Book, Read, Reading } from 'jsr:@yaks/mail@0.2.36'
21
+ import { answer, type Decision } from '@yaks/task'
22
+ import type { Options } from './options.ts'
23
+
24
+ let comp = (b: Bundle | undefined, name: string): Comp =>
25
+ b?.[name] as Comp ?? {}
26
+ let str = (v: unknown) => String(v ?? '')
27
+
28
+ /** The new words, without the quoted conversation or a conventional signature. */
29
+ let unquoted = (body: string): string =>
30
+ body.split(/\r?\n(?:On .+wrote:|>.*|--\s*$)/m)[0].trim()
31
+
32
+ /** The number shown in the letter, or a custom answer. Out-of-range numbers
33
+ * remain comments rather than silently becoming custom decision answers. */
34
+ let choice = (body: string, decision: Decision): string => {
35
+ let text = unquoted(body)
36
+ return /^\d+$/.test(text)
37
+ ? decision.choices[Number(text) - 1]?.label ?? ''
38
+ : text
39
+ }
40
+
41
+ /** Keep the received envelope even when its author cannot act on the thread.
42
+ * DKIM is the receiving edge's verdict, never an assertion in the body. */
43
+ let replied = async (
44
+ graph: Book,
45
+ letter: Bundle,
46
+ parent: Bundle | undefined,
47
+ by: string | null,
48
+ owner?: string,
49
+ ): Promise<Bundle[]> => {
50
+ if (!parent?.mail_notice && !owner) return [letter]
51
+ let mail = comp(letter, 'mail')
52
+ let prior = comp(parent, 'mail')
53
+ if (parent?.mail_notice && !prior.target) return [letter]
54
+ let target = parent?.conversation
55
+ ? parent.entity.eid
56
+ : str(prior.target || mail.target)
57
+ if (!by || mail.verified != true || !target) return [letter]
58
+ let recipient = str(comp(parent, 'deliver').to)
59
+ // A stored outgoing envelope proves whom we asked. Without it, only an
60
+ // explicitly enabled inbox recipient can act via a thread's email address.
61
+ if (parent?.deliver ? recipient != by : owner != by) return [letter]
62
+ let addressed = (await graph.read(line`.entity.eid=${target}`))[0]
63
+ let ancestor = str(comp(addressed, 'comment').target)
64
+ let root = ancestor
65
+ ? (await graph.read(line`.entity.eid=${ancestor}`))[0]
66
+ : addressed
67
+ if (ancestor) target = ancestor
68
+ if (
69
+ !root || (root.mail && !root.conversation) ||
70
+ !(root.task || root.design || root.session ||
71
+ root.bug || root.project || root.doc)
72
+ ) return [letter]
73
+ let replyTo =
74
+ (parent?.comment
75
+ ? parent.entity.eid
76
+ : str(comp(parent, 'mail_notice').comment)) ||
77
+ (ancestor ? addressed!.entity.eid : '')
78
+ let out: Bundle = {
79
+ ...letter,
80
+ mail: { ...mail, target },
81
+ comment: { target, ...(replyTo ? { reply_to: replyTo } : {}) },
82
+ }
83
+ let decision = root.decision as Decision | undefined
84
+ let picked = decision ? choice(str(comp(letter, 'doc').body), decision) : ''
85
+ let assigned = str(comp(root, 'filed').assignee)
86
+ let canAnswer = !assigned || assigned == by
87
+ return [
88
+ out,
89
+ ...(picked && canAnswer && !root.decided && !root.cancelled &&
90
+ !root.completed
91
+ ? answer(target, picked).map((b) => ({ ...b, $actor: { by } }))
92
+ : []),
93
+ ]
94
+ }
95
+
96
+ let one = async (graph: Book, eid: Eid): Promise<Bundle | undefined> =>
97
+ (await graph.read(line`.entity.eid=${eid}`))[0]
98
+
99
+ /** Whether a letter is a person's own words from outside: not a known
100
+ * session, effect, call, output or transcript entry, not the inbox address
101
+ * writing to itself, and not a letter that says it was automatic. */
102
+ let external = async (
103
+ { graph, message, letter, by, canonical }: Read,
104
+ from?: string,
105
+ ): Promise<boolean> => {
106
+ let writer = by ? await one(graph, by) : undefined
107
+ let automatic = message.headers.get('auto-submitted')?.trim().toLowerCase()
108
+ return !(
109
+ writer?.session || writer?.effect || writer?.call || writer?.output ||
110
+ writer?.entry ||
111
+ (automatic && automatic != 'no') ||
112
+ (from && canonical(str(comp(letter, 'mail').from)) == canonical(from))
113
+ )
114
+ }
115
+
116
+ /** The inbox's reading of an arrival, where the options open a door. */
117
+ export let reading = (options: Options = {}): Reading | undefined => {
118
+ let { person, from } = options
119
+ if (!person) return
120
+ return async (read) => {
121
+ let { graph, message, arrival, letter, reply, by, canonical } = read
122
+ if (!await external(read, from)) return
123
+ // A reply whose parent is unknown is still a reply, never a fresh request.
124
+ // External provenance was checked first; the person filter and the
125
+ // verification fail closed before a conversation mark is added. The
126
+ // envelope stays on the conversation itself, so Message-ID deduplication
127
+ // and later email replies use the same root.
128
+ let mail = letter.mail as Record<string, unknown>
129
+ let text = arrival.text ?? ''
130
+ if (
131
+ from && by == person && mail.verified == true &&
132
+ canonical(message.to) == canonical(from) &&
133
+ !arrival.target && !reply && !message.headers.get('in-reply-to') &&
134
+ !message.headers.get('references') && text.trim()
135
+ ) {
136
+ let { target: _target, ...envelope } = mail
137
+ return [{
138
+ ...letter,
139
+ mail: envelope,
140
+ conversation: {},
141
+ doc: { title: text.split(/\r?\n/, 1)[0], body: text },
142
+ }]
143
+ }
144
+ let parent = reply ? await one(graph, reply) : undefined
145
+ let said = await replied(graph, letter, parent, by, person)
146
+ return said.length == 1 && said[0] == letter ? undefined : said
147
+ }
148
+ }
package/mod.js ADDED
@@ -0,0 +1,11 @@
1
+ /** Pure person and thread attention policy. No I/O or sends. */ import { threadOf } from "@yaks/notify";
2
+ import { activityAt } from "./threads.js";
3
+ export * from "./reader.js";
4
+ export { inboxDoc } from "./vocab.js";
5
+ export { activityAt, attention, lanes, messageAt, saidBy, stateAt, threadOf, threads } from "./threads.js";
6
+ // Single-row views read the person's subscription too; no root mark is personal.
7
+ export let isUnread = (r, who)=>{
8
+ let opened = who.attention?.get(threadOf(r, who))?.comps.opened;
9
+ return activityAt(r) > String(opened?.at ?? '');
10
+ };
11
+ //# sourceMappingURL=mod.js.map
package/mod.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.js","sources":["./mod.ts"],"names":[],"mappings":"AAAA,8DAA8D,GAE9D,SAAS,QAAQ,4BAAiC;AAClD,SAAS,UAAU,uBAAsB;AACzC,4BAA2B;AAC3B,SAAS,QAAQ,qBAAoB;AAErC,SACE,UAAU,EACV,SAAS,EACT,KAAK,EACL,SAAS,EACT,MAAM,EACN,OAAO,EACP,QAAQ,EACR,OAAO,uBACY;AAGrB,iFAAiF;AACjF,OAAO,IAAI,WAAW,CAAC,GAAQ;EAC7B,IAAI,SAAS,IAAI,SAAS,EAAE,IAAI,SAAS,GAAG,OAAO,MAAM;EACzD,OAAO,WAAW,KAAK,OAAO,QAAQ,MAAM;AAC9C,EAAC"}
package/mod.ts ADDED
@@ -0,0 +1,24 @@
1
+ /** Pure person and thread attention policy. No I/O or sends. */
2
+ import { type Reader, type Row } from './reader.js'
3
+ import { threadOf } from '@yaks/notify'
4
+ import { activityAt } from './threads.js'
5
+ export * from './reader.js'
6
+ export { inboxDoc } from './vocab.js'
7
+
8
+ export {
9
+ activityAt,
10
+ attention,
11
+ lanes,
12
+ messageAt,
13
+ saidBy,
14
+ stateAt,
15
+ threadOf,
16
+ threads,
17
+ } from './threads.js'
18
+ export type { Direction, Lane, Search, Thread } from './threads.js'
19
+
20
+ // Single-row views read the person's subscription too; no root mark is personal.
21
+ export let isUnread = (r: Row, who: Reader): boolean => {
22
+ let opened = who.attention?.get(threadOf(r, who))?.comps.opened
23
+ return activityAt(r) > String(opened?.at ?? '')
24
+ }
package/options.js ADDED
@@ -0,0 +1,15 @@
1
+ // What a config passes to @yaks/inbox: its email door, all of it optional.
2
+ //
3
+ // ```json
4
+ // { "use": "@yaks/inbox",
5
+ // "with": { "person": "<person eid>",
6
+ // "from": "inbox@books.example",
7
+ // "base": "https://books.example",
8
+ // "hour": 9 } }
9
+ // ```
10
+ //
11
+ // `./service` reads all of it to queue letters, and `./mail` reads `person`
12
+ // and `from` to read the letters that come back. A config that names no
13
+ // person opens no door: the inbox is then only what its views and tools show.
14
+ /** The door the options open, or none. */ export let door = (options = {})=>options.person && options.from && options.base ? options : undefined;
15
+ //# sourceMappingURL=options.js.map
package/options.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.js","sources":["./options.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,EAAE;AACF,UAAU;AACV,0BAA0B;AAC1B,wCAAwC;AACxC,6CAA6C;AAC7C,+CAA+C;AAC/C,4BAA4B;AAC5B,MAAM;AACN,EAAE;AACF,4EAA4E;AAC5E,wEAAwE;AACxE,8EAA8E;AA2B9E,wCAAwC,GACxC,OAAO,IAAI,OAAO,CAAC,UAAmB,CAAC,CAAC,GACtC,QAAQ,MAAM,IAAI,QAAQ,IAAI,IAAI,QAAQ,IAAI,GAAG,UAAkB,UAAS"}
package/options.ts ADDED
@@ -0,0 +1,42 @@
1
+ // What a config passes to @yaks/inbox: its email door, all of it optional.
2
+ //
3
+ // ```json
4
+ // { "use": "@yaks/inbox",
5
+ // "with": { "person": "<person eid>",
6
+ // "from": "inbox@books.example",
7
+ // "base": "https://books.example",
8
+ // "hour": 9 } }
9
+ // ```
10
+ //
11
+ // `./service` reads all of it to queue letters, and `./mail` reads `person`
12
+ // and `from` to read the letters that come back. A config that names no
13
+ // person opens no door: the inbox is then only what its views and tools show.
14
+
15
+ import type { Eid } from 'jsr:@yaks/graph@0.2.36'
16
+
17
+ /** What a config passes to @yaks/inbox. */
18
+ export type Options = {
19
+ /** whose inbox reaches a mail client; letters from them may answer it */
20
+ person?: Eid
21
+ /** the inbox address: letters go out from it, and a verified letter from
22
+ * `person` to it starts a conversation */
23
+ from?: string
24
+ /** where a letter's thread links point: this graph's web address */
25
+ base?: string
26
+ /** the UTC hour after which the day's one digest is queued (default 9) */
27
+ hour?: number
28
+ /** email alerts too; they are never sent unless asked for */
29
+ alerts?: boolean
30
+ /** email updates too; they are never sent unless asked for */
31
+ updates?: boolean
32
+ /** how long the service waits between passes, in milliseconds (default ten
33
+ * seconds) */
34
+ every?: number
35
+ }
36
+
37
+ /** An email door that can send: a person, an address and a link base. */
38
+ export type Door = Options & { person: Eid; from: string; base: string }
39
+
40
+ /** The door the options open, or none. */
41
+ export let door = (options: Options = {}): Door | undefined =>
42
+ options.person && options.from && options.base ? options as Door : undefined
package/package.json CHANGED
@@ -1,6 +1,78 @@
1
1
  {
2
2
  "name": "@yaks/inbox",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.36",
4
+ "homepage": "https://jsr.io/@yaks/inbox",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./_dist/mod.d.ts",
9
+ "default": "./mod.js"
10
+ },
11
+ "./queries": {
12
+ "types": "./_dist/queries.d.ts",
13
+ "default": "./queries.js"
14
+ },
15
+ "./vocab": {
16
+ "types": "./_dist/vocab.d.ts",
17
+ "default": "./vocab.js"
18
+ },
19
+ "./tools": {
20
+ "types": "./_dist/tools.d.ts",
21
+ "default": "./tools.js"
22
+ },
23
+ "./graph": {
24
+ "types": "./_dist/graph.d.ts",
25
+ "default": "./graph.js"
26
+ },
27
+ "./read": {
28
+ "types": "./_dist/read.d.ts",
29
+ "default": "./read.js"
30
+ },
31
+ "./service": {
32
+ "types": "./_dist/service.d.ts",
33
+ "default": "./service.js"
34
+ },
35
+ "./letters": {
36
+ "types": "./_dist/letters.d.ts",
37
+ "default": "./letters.js"
38
+ },
39
+ "./mail": {
40
+ "types": "./_dist/mail.d.ts",
41
+ "default": "./mail.js"
42
+ },
43
+ "./actions": {
44
+ "types": "./_dist/actions.d.ts",
45
+ "default": "./actions.js"
46
+ },
47
+ "./actions-browser": {
48
+ "types": "./_dist/actions-browser.d.ts",
49
+ "default": "./actions-browser.js"
50
+ },
51
+ "./views": {
52
+ "default": "./views.tsx"
53
+ }
54
+ },
55
+ "license": "Apache-2.0",
56
+ "dependencies": {
57
+ "@yaks/archetype": "0.2.36",
58
+ "@yaks/client": "0.2.36",
59
+ "@yaks/draft": "0.2.36",
60
+ "@yaks/fp": "0.2.36",
61
+ "@yaks/graph": "0.2.36",
62
+ "@yaks/inspect": "0.2.36",
63
+ "@yaks/kernel": "0.2.36",
64
+ "@yaks/mail": "0.2.36",
65
+ "@yaks/notify": "0.2.36",
66
+ "@yaks/query": "0.2.36",
67
+ "@yaks/task": "0.2.36",
68
+ "@yaks/tools": "0.2.36",
69
+ "@yaks/ui": "0.2.36",
70
+ "@yaks/ux": "0.2.36",
71
+ "@yaks/vocab": "0.2.36",
72
+ "@types/react": "19.3.0",
73
+ "lucide": "1.31.0",
74
+ "react": "19.3.0"
75
+ },
76
+ "description": "Exact person and thread attention policy, with server-owned summaries and lazy conversation reads shared by inbox doors.",
77
+ "repository": "https://github.com/yak-sh/yak.git"
78
+ }