pipework 0.69.0 → 0.71.0

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 (59) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/REFERENCE.md +74 -5
  3. package/dist/REFERENCE.md +124 -2
  4. package/dist/core/config/schema.js +2 -2
  5. package/dist/core/config/schema.js.map +1 -1
  6. package/dist/data/migrate/internal-definitions.d.ts.map +1 -1
  7. package/dist/data/migrate/internal-definitions.js +4 -2
  8. package/dist/data/migrate/internal-definitions.js.map +1 -1
  9. package/dist/infra/access-links/index.d.ts +1 -0
  10. package/dist/infra/access-links/index.d.ts.map +1 -1
  11. package/dist/infra/access-links/namespace.d.ts +24 -0
  12. package/dist/infra/access-links/namespace.d.ts.map +1 -1
  13. package/dist/infra/access-links/namespace.js +23 -0
  14. package/dist/infra/access-links/namespace.js.map +1 -1
  15. package/dist/infra/access-links/person-check.d.ts +45 -0
  16. package/dist/infra/access-links/person-check.d.ts.map +1 -0
  17. package/dist/infra/access-links/person-check.js +128 -0
  18. package/dist/infra/access-links/person-check.js.map +1 -0
  19. package/dist/infra/access-links/schema.d.ts +8 -0
  20. package/dist/infra/access-links/schema.d.ts.map +1 -1
  21. package/dist/infra/access-links/schema.js +7 -1
  22. package/dist/infra/access-links/schema.js.map +1 -1
  23. package/dist/infra/email/audit.d.ts +2 -2
  24. package/dist/infra/email/audit.d.ts.map +1 -1
  25. package/dist/infra/email/audit.js +3 -3
  26. package/dist/infra/email/audit.js.map +1 -1
  27. package/dist/infra/email/inbound.d.ts +199 -0
  28. package/dist/infra/email/inbound.d.ts.map +1 -0
  29. package/dist/infra/email/inbound.js +451 -0
  30. package/dist/infra/email/inbound.js.map +1 -0
  31. package/dist/infra/email/index.d.ts +1 -0
  32. package/dist/infra/email/index.d.ts.map +1 -1
  33. package/dist/infra/email/index.js +1 -0
  34. package/dist/infra/email/index.js.map +1 -1
  35. package/dist/infra/email/mail.d.ts +14 -1
  36. package/dist/infra/email/mail.d.ts.map +1 -1
  37. package/dist/infra/email/mail.js +39 -3
  38. package/dist/infra/email/mail.js.map +1 -1
  39. package/dist/infra/email/mime.d.ts +38 -0
  40. package/dist/infra/email/mime.d.ts.map +1 -0
  41. package/dist/infra/email/mime.js +474 -0
  42. package/dist/infra/email/mime.js.map +1 -0
  43. package/dist/infra/email/namespace.d.ts +8 -1
  44. package/dist/infra/email/namespace.d.ts.map +1 -1
  45. package/dist/infra/email/namespace.js +8 -1
  46. package/dist/infra/email/namespace.js.map +1 -1
  47. package/dist/infra/email/providers.d.ts +3 -1
  48. package/dist/infra/email/providers.d.ts.map +1 -1
  49. package/dist/infra/email/providers.js +8 -3
  50. package/dist/infra/email/providers.js.map +1 -1
  51. package/dist/infra/email/schema.d.ts +109 -0
  52. package/dist/infra/email/schema.d.ts.map +1 -1
  53. package/dist/infra/email/schema.js +39 -1
  54. package/dist/infra/email/schema.js.map +1 -1
  55. package/dist/infra/email/sns.d.ts +14 -0
  56. package/dist/infra/email/sns.d.ts.map +1 -1
  57. package/dist/infra/email/sns.js +37 -23
  58. package/dist/infra/email/sns.js.map +1 -1
  59. package/package.json +1 -1
@@ -0,0 +1,128 @@
1
+ import { createHash, createHmac, randomBytes, timingSafeEqual } from 'node:crypto';
2
+ import { sql } from '../../data/db/sql.js';
3
+ import { pipeSystem } from '../../data/db/db.js';
4
+ const ALGORITHM = 'SHA-256';
5
+ const MIN_SECRET_BYTES = 32;
6
+ const MAX_NUMBER_LIMIT = 10_000_000;
7
+ const PRUNE_BATCH = 100;
8
+ function sha256Hex(data) {
9
+ return createHash('sha256').update(data).digest('hex');
10
+ }
11
+ function sameBytes(a, b) {
12
+ return a.length === b.length && a.length > 0 && timingSafeEqual(a, b);
13
+ }
14
+ function sameHex(a, b) {
15
+ return sameBytes(Buffer.from(a, 'hex'), Buffer.from(b, 'hex'));
16
+ }
17
+ function positive(name, value) {
18
+ if (!Number.isFinite(value) || value <= 0)
19
+ throw new Error(`personCheck: ${name} must be a positive number`);
20
+ return value;
21
+ }
22
+ function createPersonCheck(config) {
23
+ const secret = typeof config.secret === 'string' ? Buffer.from(config.secret, 'utf8') : config.secret;
24
+ if (!Buffer.isBuffer(secret) || secret.length < MIN_SECRET_BYTES) {
25
+ throw new Error(`personCheck: secret must be ${String(MIN_SECRET_BYTES)} bytes or more, the same in every process (no random fallback: a per-process secret breaks passes across processes)`);
26
+ }
27
+ const maxNumber = config.maxNumber ?? 100_000;
28
+ if (!Number.isInteger(maxNumber) || maxNumber < 1 || maxNumber > MAX_NUMBER_LIMIT) {
29
+ throw new Error(`personCheck: maxNumber must be an integer from 1 to ${String(MAX_NUMBER_LIMIT)}`);
30
+ }
31
+ const challengeMs = positive('challengeMs', config.challengeMs ?? 600_000);
32
+ const passMs = positive('passMs', config.passMs ?? 1_800_000);
33
+ const database = config.database;
34
+ const key = (purpose) => createHmac('sha256', secret).update(`pipework access links person check: ${purpose}`).digest();
35
+ const challengeKey = key('challenge');
36
+ const passKey = key('pass');
37
+ function challenge(code) {
38
+ const expires = Math.floor((Date.now() + challengeMs) / 1000);
39
+ const salt = `${randomBytes(12).toString('hex')}?expires=${String(expires)}&link=${encodeURIComponent(code)}`;
40
+ const secretNumber = randomBytes(4).readUInt32BE() % (maxNumber + 1);
41
+ const digest = sha256Hex(salt + String(secretNumber));
42
+ const signature = createHmac('sha256', challengeKey).update(digest).digest('hex');
43
+ return { algorithm: ALGORITHM, challenge: digest, maxnumber: maxNumber, salt, signature };
44
+ }
45
+ function issuePass(code) {
46
+ const exp = Date.now() + passMs;
47
+ const body = Buffer.from(JSON.stringify({ code, exp })).toString('base64url');
48
+ const mac = createHmac('sha256', passKey).update(body).digest('base64url');
49
+ return { pass: `${body}.${mac}`, expiresAt: new Date(exp) };
50
+ }
51
+ // The challenge's expiry in ms when `solution` solves a live challenge made for `code`; otherwise null.
52
+ function solvedUntil(code, solution) {
53
+ if (typeof solution !== 'string')
54
+ return null;
55
+ let payload;
56
+ try {
57
+ payload = JSON.parse(Buffer.from(solution, 'base64').toString('utf8'));
58
+ }
59
+ catch {
60
+ return null;
61
+ }
62
+ if (typeof payload !== 'object' || payload === null || Array.isArray(payload))
63
+ return null;
64
+ const { algorithm, challenge: id, number, salt, signature } = payload;
65
+ if (algorithm !== ALGORITHM || typeof id !== 'string' || typeof salt !== 'string' || typeof signature !== 'string')
66
+ return null;
67
+ if (typeof number !== 'number' || !Number.isSafeInteger(number) || number < 0)
68
+ return null;
69
+ const params = new URLSearchParams(salt.split('?')[1] ?? '');
70
+ const expires = Number(params.get('expires'));
71
+ if (!Number.isFinite(expires) || expires * 1000 <= Date.now() || params.get('link') !== code)
72
+ return null;
73
+ const expected = createHmac('sha256', challengeKey).update(id).digest('hex');
74
+ if (!sameHex(expected, signature))
75
+ return null;
76
+ if (!sameHex(sha256Hex(salt + String(number)), id))
77
+ return null;
78
+ return { id, untilMs: expires * 1000 };
79
+ }
80
+ async function verify(code, solution) {
81
+ const solved = solvedUntil(code, solution);
82
+ if (solved === null)
83
+ return null;
84
+ const db = pipeSystem(database);
85
+ const spent = await db.execute(sql `
86
+ INSERT INTO access_link_check_spent (challenge, expires_at)
87
+ VALUES (${solved.id}, ${new Date(solved.untilMs).toISOString()})
88
+ ON CONFLICT DO NOTHING RETURNING 1 AS spent`);
89
+ if (spent.length === 0)
90
+ return null;
91
+ // Kept an hour past expiry so clock skew between processes and the database never reopens a solution.
92
+ await db.execute(sql `
93
+ DELETE FROM access_link_check_spent WHERE ctid IN (
94
+ SELECT ctid FROM access_link_check_spent WHERE expires_at < now() - interval '1 hour' LIMIT ${PRUNE_BATCH})`);
95
+ return issuePass(code);
96
+ }
97
+ const check = ({ link, proof }) => {
98
+ if (typeof proof !== 'string')
99
+ return Promise.resolve(false);
100
+ const parts = proof.split('.');
101
+ const [body, mac] = parts;
102
+ if (parts.length !== 2 || body === undefined || mac === undefined)
103
+ return Promise.resolve(false);
104
+ const expected = createHmac('sha256', passKey).update(body).digest();
105
+ if (!sameBytes(Buffer.from(mac, 'base64url'), expected))
106
+ return Promise.resolve(false);
107
+ try {
108
+ const claims = JSON.parse(Buffer.from(body, 'base64url').toString('utf8'));
109
+ return Promise.resolve(typeof claims.exp === 'number' && claims.exp > Date.now() && claims.code === link.code);
110
+ }
111
+ catch {
112
+ return Promise.resolve(false);
113
+ }
114
+ };
115
+ return { challenge, verify, check };
116
+ }
117
+ /** Solves a challenge the way the widget does and returns its base64 payload. For tests: it does the work the browser would. */
118
+ function solvePersonChallenge(c) {
119
+ for (let n = 0; n <= c.maxnumber; n++) {
120
+ if (sha256Hex(c.salt + String(n)) === c.challenge) {
121
+ const payload = { algorithm: c.algorithm, challenge: c.challenge, number: n, salt: c.salt, signature: c.signature, took: 0 };
122
+ return Buffer.from(JSON.stringify(payload)).toString('base64');
123
+ }
124
+ }
125
+ throw new Error('personCheck.solve: challenge has no solution');
126
+ }
127
+ export const personCheck = Object.assign(createPersonCheck, { solve: solvePersonChallenge });
128
+ //# sourceMappingURL=person-check.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"person-check.js","sourceRoot":"","sources":["../../../src/infra/access-links/person-check.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAClF,OAAO,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAA;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAGhD,MAAM,SAAS,GAAG,SAAS,CAAA;AAC3B,MAAM,gBAAgB,GAAG,EAAE,CAAA;AAC3B,MAAM,gBAAgB,GAAG,UAAU,CAAA;AACnC,MAAM,WAAW,GAAG,GAAG,CAAA;AA0CvB,SAAS,SAAS,CAAC,IAAY;IAC7B,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AACxD,CAAC;AAED,SAAS,SAAS,CAAC,CAAS,E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AK,EAAE,oBAAoB,EAAE,CAAC,CAAA"}
@@ -124,4 +124,12 @@ export declare const accessLinkUse: import("../../data/domain/types.js").Defined
124
124
  nullable: true;
125
125
  }>;
126
126
  }, "access_link_use">;
127
+ export declare const accessLinkCheckSpent: import("../../data/domain/types.js").DefinedTable<{
128
+ challenge: import("../../data/domain/types.js").FieldDescriptor<string, {
129
+ primaryKey: true;
130
+ }> & import("../../data/domain/field.js").FieldModifiers<string, {
131
+ primaryKey: true;
132
+ }>;
133
+ expiresAt: import("../../data/domain/types.js").FieldDescriptor<Date, {}> & import("../../data/domain/field.js").FieldModifiers<Date, {}>;
134
+ }, "access_link_check_spent">;
127
135
  //# sourceMappingURL=schema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/infra/access-links/schema.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,wBAAwB,gDAAiD,CAAA;AAEtF,eAAO,MAAM,cAAc;;;;;;;;;;;;;sBAKzB,CAAA;AAEF,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAgBrB,CAAA;AAEF,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAiBxB,CAAA"}
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/infra/access-links/schema.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,wBAAwB,gDAAiD,CAAA;AAEtF,eAAO,MAAM,cAAc;;;;;;;;;;;;;sBAKzB,CAAA;AAEF,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAgBrB,CAAA;AAEF,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAiBxB,CAAA;AAIF,eAAO,MAAM,oBAAoB;;;;;;;6BAG/B,CAAA"}
@@ -1,4 +1,4 @@
1
- // The three tables behind access links. `access_link_code` is deliberately NOT
1
+ // The four tables behind access links. `access_link_code` is deliberately NOT
2
2
  // tenant-scoped: it maps a code to its tenant so a request with no tenant can
3
3
  // find where to look, and holds nothing else. `access_link` and
4
4
  // `access_link_use` carry a `.tenant()` key, so generated migrations put them
@@ -49,4 +49,10 @@ export const accessLinkUse = define('access_link_use', {
49
49
  byLink: index('idx_access_link_use_link').on(t['linkId'], t['status']),
50
50
  }),
51
51
  });
52
+ // Person-check solutions already accepted, kept until the challenge has expired:
53
+ // one solved challenge makes one pass, across processes. Not tenant-scoped.
54
+ export const accessLinkCheckSpent = define('access_link_check_spent', {
55
+ challenge: field.text().primaryKey(),
56
+ expiresAt: field.timestamp(),
57
+ });
52
58
  //# sourceMappingURL=schema.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/infra/access-links/schema.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,8EAA8E;AAC9E,gEAAgE;AAChE,8EAA8E;AAC9E,mCAAmC;AAEnC,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAA;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAA;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAA;AAElD,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,SAAS,EAAE,WAAW,EAAE,WAAW,CAAU,CAAA;AAEtF,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,kBAAkB,EAAE;IACvD,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,UAAU,EAAE;IAC/B,QAAQ,EAAE,KAAK,CAAC,IAAI,EAAE;IACtB,MAAM,EAAE,KAAK,CAAC,IAAI,EAAE;IACpB,SAAS,EAAE,KAAK,CA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AE,EAAE,CAAC,CAAC;QACf,MAAM,EAAE,KAAK,CAAC,0BAA0B,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC;KACvE,CAAC;CACH,CAAC,CAAA;AAEF,iFAAiF;AACjF,4EAA4E;AAC5E,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC,yBAAyB,EAAE;IACpE,SAAS,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,UAAU,EAAE;IACpC,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE;CAC7B,CAAC,CAAA"}
@@ -1,3 +1,3 @@
1
- /** Writes an `Email` audit record under the Flow's open trace step; does nothing when no step is open. */
2
- export declare function auditEmail(verb: string, entityId: string | null, details: Record<string, unknown>): Promise<void>;
1
+ /** Writes an audit record (entity `Email` unless given) under the Flow's open trace step; does nothing when no step is open. */
2
+ export declare function auditEmail(verb: string, entityId: string | null, details: Record<string, unknown>, entity?: string): Promise<void>;
3
3
  //# sourceMappingURL=audit.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../../../src/infra/email/audit.ts"],"names":[],"mappings":"AAMA,0GAA0G;AAC1G,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAevH"}
1
+ {"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../../../src/infra/email/audit.ts"],"names":[],"mappings":"AAMA,gIAAgI;AAChI,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,SAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAezI"}
@@ -3,8 +3,8 @@ import { pipeSystem } from '../../data/db/db.js';
3
3
  import { getContext } from '../../request/context/store.js';
4
4
  import { resolveActorId } from '../../data/write/audit/actor.js';
5
5
  import { getBaseLogger } from '../../core/logging/index.js';
6
- /** Writes an `Email` audit record under the Flow's open trace step; does nothing when no step is open. */
7
- export async function auditEmail(verb, entityId, details) {
6
+ /** Writes an audit record (entity `Email` unless given) under the Flow's open trace step; does nothing when no step is open. */
7
+ export async function auditEmail(verb, entityId, details, entity = 'Email') {
8
8
  const flow = getContext();
9
9
  const trace = flow?.trace;
10
10
  const stepId = trace?.buffer.openStepId ?? null;
@@ -15,7 +15,7 @@ export async function auditEmail(verb, entityId, details) {
15
15
  INSERT INTO audit_record
16
16
  (trace_day, trace_id, trace_step_id, tenant_id, actor_id, entity, verb, entity_id, after, occurred_at)
17
17
  VALUES (${trace.openedDay}, ${trace.id}, ${stepId}, ${flow.tenant}, ${resolveActorId(flow)},
18
- 'Email', ${verb}, ${entityId}, ${JSON.stringify(details)}::jsonb, now())
18
+ ${entity}, ${verb}, ${entityId}, ${JSON.stringify(details)}::jsonb, now())
19
19
  `);
20
20
  }
21
21
  catch (err) {
@@ -1 +1 @@
1
- {"version":3,"file":"audit.js","sourceRoot":"","sources":["../../../src/infra/email/audit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAA;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAA;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAA;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAE3D,0GAA0G;AAC1G,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,IAAY,EAAE,QAAuB,EAAE,OAAgC;IACtG,MAAM,IAAI,GAAG,UAAU,EAAE,CAAA;IACzB,MAAM,KAAK,GAAG,IAAI,EAAE,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AAK,EAAE,MAAM,CAAC,UAAU,IAAI,IAAI,CAAA;IAC/C,IAAI,IAAI,KAAK,SAAS,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,IAAI,MAAM,KAAK,IAAI;QAAE,OAAM;IAC1F,IAAI,CAAC;QACH,MAAM,UAAU,EAAE,CAAC,OAAO,CAAC,GAAG,CAAA;;;gBAGlB,KAAK,CAAC,SAAS,KAAK,KAAK,CAAC,EAAE,KAAK,MAAM,KAAK,IAAI,CAAC,MAAM,KAAK,cAAc,CAAC,IAAI,CAAC;UACtF,MAAM,KAAK,IAAI,KAAK,QAAQ,KAAK,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;KAC7D,CAAC,CAAA;IACJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,aAAa,EAAE,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,EAAE,EAAE,6BAA6B,IAAI,eAAe,CAAC,CAAA;IACrG,CAAC;AACH,CAAC"}
@@ -0,0 +1,199 @@
1
+ import type { Queue } from '../../async/jobs/queue.js';
2
+ import type { Handler } from '../../request/di/types.js';
3
+ import type { StorageBackend } from '../storage/backend.js';
4
+ import type { Storage, StoredFile } from '../storage/handle.js';
5
+ export declare const RECEIVE_JOB = "pipework.email.receive";
6
+ export interface EmailAddress {
7
+ readonly address: string;
8
+ readonly name: string;
9
+ }
10
+ export interface ReceivedAttachment {
11
+ readonly filename: string | null;
12
+ readonly mediaType: string;
13
+ readonly size: number;
14
+ /** Lowercase hex SHA-256 of the decoded content. */
15
+ readonly sha256: string;
16
+ /** The `Content-ID` without angle brackets, for `cid:` references from the HTML. */
17
+ readonly contentId: string | null;
18
+ readonly inline: boolean;
19
+ /** The stored file, or `null` when no tenant was resolved or no `storage` was given. */
20
+ readonly file: StoredFile | null;
21
+ }
22
+ /** What SES concluded about a received message: each of `PASS`, `FAIL`, `GRAY` or `PROCESSING_FAILED`. */
23
+ export interface EmailVerdicts {
24
+ readonly spam: string | null;
25
+ readonly virus: string | null;
26
+ readonly spf: string | null;
27
+ readonly dkim: string | null;
28
+ readonly dmarc: string | null;
29
+ }
30
+ /** What is known about a message before it is threaded: everything but its conversation and tenant. Handed to `resolveTenant`. */
31
+ export type UnthreadedEmail = Omit<ReceivedEmail, 'conversationId' | 'isNewConversation' | 'tenantId'>;
32
+ /** A received, parsed and threaded message, as handed to `onMessage`. */
33
+ export interface ReceivedEmail {
34
+ /** The `pipework_email_inbound` row id; pass it as `inReplyTo` to `mail.send` to answer. */
35
+ readonly id: string;
36
+ readonly conversationId: string;
37
+ /** True when no earlier received or sent message matched this one's `In-Reply-To`/`References`. */
38
+ readonly isNewConversation: boolean;
39
+ readonly tenantId: string | null;
40
+ /** The `Message-ID` without angle brackets, or `null`. */
41
+ readonly messageId: string | null;
42
+ readonly inReplyTo: string | null;
43
+ readonly references: readonly string[];
44
+ /** An empty address and name when the message has no readable From. */
45
+ readonly from: EmailAddress;
46
+ readonly to: readonly EmailAddress[];
47
+ readonly cc: readonly EmailAddress[];
48
+ readonly replyTo: readonly EmailAddress[];
49
+ readonly subject: string;
50
+ readonly date: Date | null;
51
+ readonly text: string | null;
52
+ readonly html: string | null;
53
+ readonly attachments: readonly ReceivedAttachment[];
54
+ /** `null` for a message from the folder stand-in. */
55
+ readonly verdicts: EmailVerdicts | null;
56
+ /** The envelope recipients SES accepted the message for; for the stand-in, the To and Cc addresses. */
57
+ readonly recipients: readonly string[];
58
+ }
59
+ /** A received message's row, without bodies. */
60
+ export interface InboundRecord {
61
+ readonly id: string;
62
+ readonly source: 'ses' | 'folder';
63
+ readonly status: 'received' | 'processed' | 'failed';
64
+ readonly error: string | null;
65
+ readonly messageId: string | null;
66
+ readonly conversationId: string | null;
67
+ readonly tenantId: string | null;
68
+ readonly subject: string | null;
69
+ readonly fromAddress: string | null;
70
+ readonly verdicts: EmailVerdicts | null;
71
+ readonly receivedAt: Date;
72
+ readonly processedAt: Date | null;
73
+ readonly rawExpiresAt: Date;
74
+ readonly rawDeletedAt: Date | null;
75
+ }
76
+ export interface InboundSweepResult {
77
+ /** Raw copies deleted. */
78
+ readonly deleted: number;
79
+ /** Raw copies that could not be deleted (left for the next sweep). */
80
+ readonly failed: number;
81
+ }
82
+ export interface InboundScanResult {
83
+ /** Files taken in. */
84
+ readonly received: number;
85
+ /** Files already taken in earlier (same bytes); moved to `received/` without a new row. */
86
+ readonly duplicates: number;
87
+ }
88
+ type RawLocation = Record<string, unknown>;
89
+ /** Where received mail comes from. Made by `mail.sesReceipt` or `mail.inboundFolder`. */
90
+ export interface InboundSource {
91
+ readonly kind: 'ses' | 'folder';
92
+ /** Reads the raw message; throws `RawTooLargeError` past `maxBytes` and `RawNotFoundError` when it definitely does not exist. */
93
+ read(location: RawLocation, maxBytes: number): Promise<Buffer>;
94
+ remove(location: RawLocation): Promise<void>;
95
+ readonly ses?: SesReceiptConfig;
96
+ readonly folder?: {
97
+ readonly dir: string;
98
+ };
99
+ }
100
+ export declare class RawNotFoundError extends Error {
101
+ constructor(detail: string);
102
+ }
103
+ export declare class RawTooLargeError extends Error {
104
+ readonly maxBytes: number;
105
+ constructor(maxBytes: number);
106
+ }
107
+ export interface SesReceiptConfig {
108
+ /** A storage backend over the SES receipt bucket with no prefix (`storage.s3({ bucket, region, credentials })`); keys are the S3 action's object keys. */
109
+ readonly bucket: StorageBackend;
110
+ /** The SNS topics SES publishes receipt notifications to. */
111
+ readonly topicArns: readonly string[];
112
+ readonly region?: string;
113
+ readonly fetchCert?: (url: string) => Promise<string>;
114
+ readonly confirm?: (url: string) => Promise<void>;
115
+ }
116
+ /**
117
+ * The SES receipt source. SES stores each raw message in S3 (receipt rule action "S3" with an SNS topic)
118
+ * and notifies the topic; `inbound.webhook` verifies the notification and records it, and the receive job
119
+ * reads the object from `bucket`. A notification whose action is not S3 (for example the SNS action,
120
+ * which carries the message inline), or whose type is not `Received`, is answered 200 and ignored.
121
+ */
122
+ export declare function sesReceipt(config: SesReceiptConfig): InboundSource;
123
+ /**
124
+ * The development source: `.eml` files dropped in `dir` are received by `inbound.scan()`, which copies each
125
+ * to `<dir>/received/` (where the raw copy stays until `sweep`) and removes the original. Refused when the
126
+ * environment is `production`.
127
+ */
128
+ export declare function inboundFolder(config: {
129
+ readonly dir: string;
130
+ }): InboundSource;
131
+ export interface InboundConfig {
132
+ readonly source: InboundSource;
133
+ /** The app's job queue; its worker surface must run `inbound.jobs`. */
134
+ readonly queue: Queue;
135
+ /**
136
+ * Called in the receive job with each parsed, threaded message. A throw makes the queue retry the job.
137
+ * It is called at least once per message: a retry after a handler error, or a job re-run after a crash,
138
+ * calls it again with the same `id`. Make it idempotent on `id`.
139
+ */
140
+ readonly onMessage: (email: ReceivedEmail) => Promise<void> | void;
141
+ /** Stores attachments (as the resolved tenant's files). Without it, or without a tenant, attachments have `file: null`. */
142
+ readonly storage?: Storage;
143
+ /**
144
+ * Names the tenant a message belongs to (`null` for none), e.g. by its recipient address. It runs before
145
+ * threading, so it gets the message without a conversation: a message is only joined to a conversation of
146
+ * the same tenant (or of a message with no tenant).
147
+ */
148
+ readonly resolveTenant?: (email: UnthreadedEmail) => Promise<string | null>;
149
+ /** Days the raw copy is kept before `sweep` deletes it. Default 30. */
150
+ readonly rawRetentionDays?: number;
151
+ /** Raw messages larger than this are marked `failed` and not handled. Default 40 MiB. */
152
+ readonly maxRawBytes?: number;
153
+ /** The app's environment; `inboundFolder` is refused when this is `production`. */
154
+ readonly environment?: string;
155
+ }
156
+ export interface Inbound {
157
+ /** The public POST endpoint SNS delivers SES receipt notifications to (SES source only). */
158
+ webhook(config: {
159
+ readonly path: string;
160
+ }): Handler<Record<string, unknown>, unknown>;
161
+ /** Job handlers for the receive job; spread into the worker surface's `jobs`. */
162
+ readonly jobs: readonly Handler<Record<string, unknown>, unknown>[];
163
+ /** Folder source only: receives every `.eml` file in the folder. Needs a Flow (a job or schedule run). */
164
+ scan(): Promise<InboundScanResult>;
165
+ /** Deletes raw copies past their retention. Needs a Flow (a job or schedule run). */
166
+ sweep(options?: {
167
+ readonly limit?: number;
168
+ }): Promise<InboundSweepResult>;
169
+ /** The row of a received message, or `null`. Needs a Flow (a job, request or test context). */
170
+ get(id: string): Promise<InboundRecord | null>;
171
+ }
172
+ /**
173
+ * Receiving email. `inbound.webhook` (SES) or `inbound.scan` (folder) records each message in
174
+ * `pipework_email_inbound` and enqueues the `pipework.email.receive` job, once per message. The job
175
+ * reads the raw message, parses it, assigns a conversation, resolves the tenant, stores the attachments
176
+ * as that tenant's files and calls `onMessage` with a `ReceivedEmail`.
177
+ *
178
+ * Needs blueprint `email: {}` (table `pipework_email_inbound`; `pipework_email_messages` gains `conversation_id`).
179
+ * The row is not tenant-scoped (it exists before a tenant is known) and holds no bodies: the raw message
180
+ * is the copy and `sweep` deletes it after `rawRetentionDays`.
181
+ *
182
+ * Threading: the ids in In-Reply-To then References are matched to an earlier received message's
183
+ * Message-ID, or, for an id `<X@region.amazonses.com>`, to a sent message whose `provider_message_id` is `X`
184
+ * (set the sent message's conversation with `mail.send({ conversationId })` or `inReplyTo`). The first match
185
+ * decides the conversation; with none the message starts one (`isNewConversation: true`). Ids are matched exactly.
186
+ * A received message is matched only when its tenant equals the tenant `resolveTenant` named for this message or
187
+ * either is null; a sent message's conversation is refused when it holds a received message of another tenant.
188
+ *
189
+ * Threading is not authentication: Message-IDs are not secret and From is forgeable. Before attaching a message to
190
+ * a conversation's participants, the app checks `from` against them and the DKIM and DMARC verdicts.
191
+ *
192
+ * The receive job is a trace step `pipework/email:receive` with an `EmailInbound:received` audit record on success.
193
+ * A handler error (or a failure reading the raw message) rethrows so the queue retries; attachments stored by
194
+ * an earlier attempt are reused. Set `maxAttempts` on the queue. A raw message over `maxRawBytes` is marked
195
+ * `failed` and not retried. Message bodies are never logged.
196
+ */
197
+ export declare function createInbound(config: InboundConfig): Inbound;
198
+ export {};
199
+ //# sourceMappingURL=inbound.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inbound.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