@pithy-sh/email 0.10.1 → 0.10.3

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.
@@ -16,7 +16,7 @@ function extractAddress(value) {
16
16
  function originalMessageId(raw) {
17
17
  const explicit = field(raw, "Original-Message-ID");
18
18
  if (explicit) return explicit.replace(/^<|>$/g, "");
19
- const ids = [...raw.matchAll(/^Message-ID:\s*<([^>]+)>/gim)].map((m) => m[1]);
19
+ const ids = [...raw.matchAll(/^Message-ID:[ \t]*<([^>\r\n]+)>/gim)].map((m) => m[1]);
20
20
  return ids.length > 0 ? ids[ids.length - 1] : void 0;
21
21
  }
22
22
  /** Classify an inbound message. */
@@ -41,6 +41,13 @@ export interface InboundSkip {
41
41
  * suppression database skips the suppression, and each skip is reported in `skipped` rather than thrown.
42
42
  */
43
43
  export declare function applyInbound(db: EmailDatabase | undefined, suppressionDb: EmailSuppressionDatabase | undefined, c: InboundClassification, now: Date, environment?: string): Promise<InboundOutcome>;
44
+ /**
45
+ * The largest inbound message the bounce handler reads, by its declared size. What comes back here is
46
+ * a DSN or a feedback report about a templated send with no attachments, so even a report that returns
47
+ * the whole original runs to tens of kilobytes; 2 MiB, support's default bound, leaves that a wide
48
+ * margin and refuses anything else before a byte of it is buffered.
49
+ */
50
+ export declare const MAX_BOUNCE_RAW_BYTES: number;
44
51
  /**
45
52
  * Build the inbound-email handler for the `Capability.email` seam. Reads `DB` + `EMAIL_SUPPRESSIONS` from env.
46
53
  *
@@ -1 +1 @@
1
- {"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../src/bounce/handler.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,0CAA0C,CAAC;AAIvF,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,wBAAwB,EAG9B,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAmB,KAAK,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEzE;;;;;;G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K,CAAC,EAAE,MAAM,CAAC;IACf,6DAA6D;IAC7D,UAAU,EAAE,OAAO,CAAC;IACpB,6GAA6G;IAC7G,OAAO,EAAE,WAAW,EAAE,CAAC;CACxB;AAED,yFAAyF;AACzF,MAAM,WAAW,WAAW;IAC1B,8GAA8G;IAC9G,IAAI,EAAE,KAAK,GAAG,aAAa,CAAC;IAC5B,mDAAmD;IACnD,OAAO,EAAE,IAAI,GAAG,oBAAoB,CAAC;CACtC;AAED;;;;;;;;;GASG;AACH,wBAAsB,YAAY,CAChC,EAAE,EAAE,aAAa,GAAG,SAAS,EAC7B,aAAa,EAAE,wBAAwB,GAAG,SAAS,EACnD,CAAC,EAAE,qBAAqB,EACxB,GAAG,EAAE,IAAI,EACT,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,cAAc,CAAC,CAiEzB;AAED;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,QAAkB,CAAC;AAEpD;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,IAAI,sBAAsB,CAmD5D"}
@@ -78,6 +78,13 @@ async function applyInbound(db, suppressionDb, c, now, environment) {
78
78
  };
79
79
  }
80
80
  /**
81
+ * The largest inbound message the bounce handler reads, by its declared size. What comes back here is
82
+ * a DSN or a feedback report about a templated send with no attachments, so even a report that returns
83
+ * the whole original runs to tens of kilobytes; 2 MiB, support's default bound, leaves that a wide
84
+ * margin and refuses anything else before a byte of it is buffered.
85
+ */
86
+ const MAX_BOUNCE_RAW_BYTES = 2097152;
87
+ /**
81
88
  * Build the inbound-email handler for the `Capability.email` seam. Reads `DB` + `EMAIL_SUPPRESSIONS` from env.
82
89
  *
83
90
  * It never throws. `createEntrypoint` runs every capability's handler in turn, so a throw here would stop the ones
@@ -94,6 +101,15 @@ function createBounceHandler() {
94
101
  fields: { env: environment ?? "unknown" }
95
102
  });
96
103
  try {
104
+ const declared = message.rawSize;
105
+ if (typeof declared === "number" && declared > 2097152) {
106
+ log.warn("email inbound message refused before parsing", {
107
+ reason: "too_large",
108
+ rawSize: declared,
109
+ maxRawBytes: MAX_BOUNCE_RAW_BYTES
110
+ });
111
+ return;
112
+ }
97
113
  const raw = await new Response(message.raw).text();
98
114
  const parsed = await PostalMime.parse(raw);
99
115
  const headers = {};
@@ -123,4 +139,4 @@ function isD1(binding) {
123
139
  return typeof binding === "object" && binding !== null;
124
140
  }
125
141
  //#endregion
126
- export { applyInbound, createBounceHandler };
142
+ export { MAX_BOUNCE_RAW_BYTES, applyInbound, createBounceHandler };
@@ -32,7 +32,7 @@ export declare const emailWorkflowRegistry: WorkflowRegistry;
32
32
  /**
33
33
  * The Workflows one environment's email worker is deployed with — `<project>-<env>-email-send` and
34
34
  * `<project>-<env>-email-schedule`. Derived by the call {@link resolveEmailConfig} deploys with, so teardown
35
- * deletes the names provision created and no others (#789). Deleting a Worker does not delete the Workflows
35
+ * deletes the names provision created and no others. Deleting a Worker does not delete the Workflows
36
36
  * registered against it.
37
37
  */
38
38
  export declare function emailWorkflowNames(project: string, env: ManagedEnvironment): string[];
@@ -83,18 +83,23 @@ export interface EmailConfigParams {
83
83
  */
84
84
  env: ManagedEnvironment | "dev";
85
85
  /**
86
- * **The feature this host serves, when it serves one (#643).** A feature gets its own email host, as a
86
+ * **The feature this host serves, when it serves one.** A feature gets its own email host, as a
87
87
  * declared environment does, and everything the host is called or reads takes the feature's names: the
88
88
  * Worker and its Workflows (`<project>-f<issue>-<slug>-email[-<job>]`), the feature's own master key and
89
89
  * link-signing key entries, and the feature's own suppression database. `env` is then `feature`, which is
90
90
  * what the host's `ENVIRONMENT` var says.
91
91
  */
92
92
  feature?: FeatureIdentity;
93
+ /**
94
+ * The `apps/<owner>` Worker whose own host this is, when it owns a binding the host binds. The Worker and its
95
+ * Workflows then carry `<owner>---<capability>`, so it never takes the shared host's names.
96
+ */
97
+ owner?: string;
93
98
  /** The app database id for this environment — where jobs/events live. */
94
99
  appDatabaseId: string;
95
100
  /** The shared suppression database id (same in every environment). */
96
101
  suppressionDatabaseId: string;
97
- /** This environment's secrets database id (`<project>-<env>-secrets`). The signing key is not in it (#596). */
102
+ /** This environment's secrets database id (`<project>-<env>-secrets`). The signing key is not in it. */
98
103
  secretsDatabaseId: string;
99
104
  /** The CF Secrets Store id holding the per-env master key and the per-env link-signing key. */
100
105
  storeId: string;
@@ -1 +1 @@
1
- {"version":3,"file":"resolveEmailConfig.d.ts","sourceRoot":"","sources":["../../src/provision/resolveEmailConfig.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAEzE,OAAO,KAAK,EACV,aAAa,EACb,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,kCAAkC,CAAC;AAG1C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAGzE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAGtE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,EAAE,KAAK,eAAe,EAAuB,MAAM,eAAe,CAAC;AAG1E;;;;;;GAMG;AACH,MAAM,WAAW,2BAA4B,SAAQ,oBAAoB;IACvE,kBAAkB,EAAE,MAAM,CAAC;IAC3B,mBAAmB,EAAE,MAAM,EAAE,CAAC;IAC9B,WAAW,EAAE,OAAO,CAAC;IACrB,YAAY,EAAE,aAAa,EAAE,CAAC;IAC9B,UAAU,EAAE,oBAAoB,EAAE,CAAC;IACnC,qBAAqB,EAAE,uBAAuB,EAAE,CAAC;IACjD,SAAS,EAAE,mBAAmB,EAAE,CAAC;IACjC,QAAQ,EAAE;QAAE,KAAK,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;IAC9B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B;AA4BD,2GAA2G;AAC3G,eAAO,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FAA4F;AAC5F,MAAM,WAAW,iBAAiB;IAChC;;;;;OAKG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,GAAG,EAAE,kBAAkB,GAAG,KAAK,CAAC;IAChC;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,yEAAyE;IACzE,aAAa,EAAE,MAAM,CAAC;IACtB,sEAAsE;IACtE,qBAAqB,EAAE,MAAM,CAAC;IAC9B,wGAAwG;IACxG,iBAAiB,EAAE,MAAM,CAAC;IAC1B,+FAA+F;IAC/F,OAAO,EAAE,MAAM,CAAC;IAChB,mGAAmG;IACnG,OAAO,EAAE,MAAM,CAAC;IAChB,iFAAiF;IACjF,KAAK,EAAE,UAAU,CAAC;IAClB;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B;;;OAGG;IACH,WAAW,CAAC,EAAE,eAAe,CAAC;CAK/B;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,2BAA2B,EACrC,MAAM,EAAE,iBAAiB,GACxB,2BAA2B,CA2D7B"}
@@ -36,7 +36,7 @@ const emailWorkflowRegistry = Object.fromEntries(Object.entries({
36
36
  /**
37
37
  * The Workflows one environment's email worker is deployed with — `<project>-<env>-email-send` and
38
38
  * `<project>-<env>-email-schedule`. Derived by the call {@link resolveEmailConfig} deploys with, so teardown
39
- * deletes the names provision created and no others (#789). Deleting a Worker does not delete the Workflows
39
+ * deletes the names provision created and no others. Deleting a Worker does not delete the Workflows
40
40
  * registered against it.
41
41
  */
42
42
  function emailWorkflowNames(project, env) {
@@ -114,12 +114,14 @@ function emailMessagesVars(messages) {
114
114
  function resolveEmailConfig(template, params) {
115
115
  const { project, env, appDatabaseId, suppressionDatabaseId, secretsDatabaseId, storeId, baseUrl, theme } = params;
116
116
  const feature = params.feature;
117
+ const owner = params.owner;
117
118
  const scope = feature ? featureScope(feature) : environmentScope(project, env);
118
119
  return resolveWorkflowHost(template, {
119
120
  project,
120
121
  capability: EMAIL_CAPABILITY,
121
122
  env,
122
123
  ...feature ? { feature } : {},
124
+ ...owner !== void 0 ? { owner } : {},
123
125
  databaseIds: {
124
126
  DB: appDatabaseId,
125
127
  EMAIL_SUPPRESSIONS: suppressionDatabaseId,
@@ -139,7 +141,8 @@ function resolveEmailConfig(template, params) {
139
141
  project,
140
142
  capability: EMAIL_CAPABILITY,
141
143
  env,
142
- ...feature ? { feature } : {}
144
+ ...feature ? { feature } : {},
145
+ ...owner !== void 0 ? { owner } : {}
143
146
  }).workflows
144
147
  });
145
148
  }
@@ -3,5 +3,5 @@
3
3
  /** This package's npm name — the join key against a release feed. */
4
4
  export declare const PACKAGE_NAME = "@pithy-sh/email";
5
5
  /** This package's version, stamped from its own package.json at generation time. */
6
- export declare const PACKAGE_VERSION = "0.10.1";
6
+ export declare const PACKAGE_VERSION = "0.10.3";
7
7
  //# sourceMappingURL=version.generated.d.ts.map
@@ -4,6 +4,6 @@
4
4
  /** This package's npm name — the join key against a release feed. */
5
5
  const PACKAGE_NAME = "@pithy-sh/email";
6
6
  /** This package's version, stamped from its own package.json at generation time. */
7
- const PACKAGE_VERSION = "0.10.1";
7
+ const PACKAGE_VERSION = "0.10.3";
8
8
  //#endregion
9
9
  export { PACKAGE_NAME, PACKAGE_VERSION };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pithy-sh/email",
3
- "version": "0.10.1",
3
+ "version": "0.10.3",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -39,11 +39,11 @@
39
39
  "@cloudflare/workers-types": "^5.20260729.1",
40
40
  "@hono/zod-validator": "^0.9.0",
41
41
  "handlebars": "^4.7.9",
42
- "postal-mime": "^3.0.0"
42
+ "postal-mime": "^4.0.8"
43
43
  },
44
44
  "peerDependencies": {
45
- "@pithy-sh/core": "^0.19.0",
46
- "@pithy-sh/secrets": "^0.6.7",
45
+ "@pithy-sh/core": "^0.20.1",
46
+ "@pithy-sh/secrets": "^0.6.8",
47
47
  "hono": "^4.13.2",
48
48
  "kysely": "^0.29.0",
49
49
  "zod": "^4.4.0"
@@ -47,7 +47,7 @@ function extractAddress(value: string | undefined): string | undefined {
47
47
  function originalMessageId(raw: string): string | undefined {
48
48
  const explicit = field(raw, "Original-Message-ID");
49
49
  if (explicit) return explicit.replace(/^<|>$/g, "");
50
- const ids = [...raw.matchAll(/^Message-ID:\s*<([^>]+)>/gim)].map((m) => m[1]);
50
+ const ids = [...raw.matchAll(/^Message-ID:[ \t]*<([^>\r\n]+)>/gim)].map((m) => m[1]);
51
51
  return ids.length > 0 ? ids[ids.length - 1] : undefined;
52
52
  }
53
53
 
@@ -130,6 +130,14 @@ export async function applyInbound(
130
130
  return { acted: suppressed || Boolean(job), type: c.type, jobId: job?.id, suppressed, skipped };
131
131
  }
132
132
 
133
+ /**
134
+ * The largest inbound message the bounce handler reads, by its declared size. What comes back here is
135
+ * a DSN or a feedback report about a templated send with no attachments, so even a report that returns
136
+ * the whole original runs to tens of kilobytes; 2 MiB, support's default bound, leaves that a wide
137
+ * margin and refuses anything else before a byte of it is buffered.
138
+ */
139
+ export const MAX_BOUNCE_RAW_BYTES = 2 * 1024 * 1024;
140
+
133
141
  /**
134
142
  * Build the inbound-email handler for the `Capability.email` seam. Reads `DB` + `EMAIL_SUPPRESSIONS` from env.
135
143
  *
@@ -144,6 +152,16 @@ export function createBounceHandler(): CapabilityEmailHandler {
144
152
  const environment = typeof env.ENVIRONMENT === "string" ? env.ENVIRONMENT : undefined;
145
153
  const log = createWorkerLogger({ name: "email", fields: { env: environment ?? "unknown" } });
146
154
  try {
155
+ const declared = message.rawSize;
156
+ if (typeof declared === "number" && declared > MAX_BOUNCE_RAW_BYTES) {
157
+ log.warn("email inbound message refused before parsing", {
158
+ reason: "too_large",
159
+ rawSize: declared,
160
+ maxRawBytes: MAX_BOUNCE_RAW_BYTES,
161
+ });
162
+ return;
163
+ }
164
+
147
165
  const raw = await new Response(message.raw).text();
148
166
  const parsed = await PostalMime.parse(raw);
149
167
  const headers: Record<string, string> = {};
@@ -54,8 +54,7 @@ export interface EmailWorkerWranglerTemplate extends WorkflowHostTemplate {
54
54
  * jobs are mirrored here, and `resolveEmailConfig.test.ts` asserts the bindings and class names match
55
55
  * the committed template byte for byte.
56
56
  *
57
- * **`params` is no longer a placeholder** (pithy-sh/pithy#410). The host mounts the shared dispatch
58
- * route, and that route validates an arriving loopback payload against the declaring spec's own
57
+ * **`params` is a request contract.** The host mounts the shared dispatch route, and that route validates an arriving loopback payload against the declaring spec's own
59
58
  * schema before it starts anything — so the registry's `params` is the request contract of a real
60
59
  * HTTP surface. Both sides therefore read the one schema out of `workflows/params.ts`; a `z.unknown()`
61
60
  * here would let a malformed dispatch through to fail inside a durable instance instead.
@@ -81,7 +80,7 @@ export const emailWorkflowRegistry: WorkflowRegistry = Object.fromEntries(
81
80
  /**
82
81
  * The Workflows one environment's email worker is deployed with — `<project>-<env>-email-send` and
83
82
  * `<project>-<env>-email-schedule`. Derived by the call {@link resolveEmailConfig} deploys with, so teardown
84
- * deletes the names provision created and no others (#789). Deleting a Worker does not delete the Workflows
83
+ * deletes the names provision created and no others. Deleting a Worker does not delete the Workflows
85
84
  * registered against it.
86
85
  */
87
86
  export function emailWorkflowNames(project: string, env: ManagedEnvironment): string[] {
@@ -156,18 +155,23 @@ export interface EmailConfigParams {
156
155
  */
157
156
  env: ManagedEnvironment | "dev";
158
157
  /**
159
- * **The feature this host serves, when it serves one (#643).** A feature gets its own email host, as a
158
+ * **The feature this host serves, when it serves one.** A feature gets its own email host, as a
160
159
  * declared environment does, and everything the host is called or reads takes the feature's names: the
161
160
  * Worker and its Workflows (`<project>-f<issue>-<slug>-email[-<job>]`), the feature's own master key and
162
161
  * link-signing key entries, and the feature's own suppression database. `env` is then `feature`, which is
163
162
  * what the host's `ENVIRONMENT` var says.
164
163
  */
165
164
  feature?: FeatureIdentity;
165
+ /**
166
+ * The `apps/<owner>` Worker whose own host this is, when it owns a binding the host binds. The Worker and its
167
+ * Workflows then carry `<owner>---<capability>`, so it never takes the shared host's names.
168
+ */
169
+ owner?: string;
166
170
  /** The app database id for this environment — where jobs/events live. */
167
171
  appDatabaseId: string;
168
172
  /** The shared suppression database id (same in every environment). */
169
173
  suppressionDatabaseId: string;
170
- /** This environment's secrets database id (`<project>-<env>-secrets`). The signing key is not in it (#596). */
174
+ /** This environment's secrets database id (`<project>-<env>-secrets`). The signing key is not in it. */
171
175
  secretsDatabaseId: string;
172
176
  /** The CF Secrets Store id holding the per-env master key and the per-env link-signing key. */
173
177
  storeId: string;
@@ -220,6 +224,7 @@ export function resolveEmailConfig(
220
224
  ): EmailWorkerWranglerTemplate {
221
225
  const { project, env, appDatabaseId, suppressionDatabaseId, secretsDatabaseId, storeId, baseUrl, theme } = params;
222
226
  const feature = params.feature;
227
+ const owner = params.owner;
223
228
  // One scope for every name below, so a feature's host can never bind a declared environment's key or list.
224
229
  const scope = feature ? featureScope(feature) : environmentScope(project, env);
225
230
  const resolved = resolveWorkflowHost(template, {
@@ -227,6 +232,7 @@ export function resolveEmailConfig(
227
232
  capability: EMAIL_CAPABILITY,
228
233
  env,
229
234
  ...(feature ? { feature } : {}),
235
+ ...(owner !== undefined ? { owner } : {}),
230
236
  databaseIds: {
231
237
  DB: appDatabaseId,
232
238
  EMAIL_SUPPRESSIONS: suppressionDatabaseId,
@@ -247,7 +253,7 @@ export function resolveEmailConfig(
247
253
  // The link-signing key, at the entry `pithy secrets provision` created and bound the app Worker to —
248
254
  // composed by the same `environmentScope(...).secretEntry` call, from the declaration's own scope, so
249
255
  // the Worker that signs a link and the Worker that verifies it cannot be handed two different keys.
250
- // Keyed by the binding the template declares; the entry keeps the registry key's name (#603).
256
+ // Keyed by the binding the template declares; the entry keeps the registry key's name.
251
257
  secretNames: {
252
258
  [EMAIL_LINK_SIGNING_KEY_BINDING]: scope.secretEntry(
253
259
  EMAIL_LINK_SIGNING_KEY,
@@ -268,6 +274,7 @@ export function resolveEmailConfig(
268
274
  capability: EMAIL_CAPABILITY,
269
275
  env,
270
276
  ...(feature ? { feature } : {}),
277
+ ...(owner !== undefined ? { owner } : {}),
271
278
  }).workflows,
272
279
  });
273
280
  // The resolver fills fields; it never drops one. So every field this template narrows to required
@@ -13,4 +13,4 @@
13
13
  export const PACKAGE_NAME = "@pithy-sh/email";
14
14
 
15
15
  /** This package's version, stamped from its own package.json at generation time. */
16
- export const PACKAGE_VERSION = "0.10.1";
16
+ export const PACKAGE_VERSION = "0.10.3";