@terreno/comms 57.20.0 → 57.21.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.
package/CHANGELOG.md CHANGED
@@ -20,6 +20,56 @@ Upgrade notes for consumer action live in [`mcp-server/src/docs/upgrades/`](mcp-
20
20
 
21
21
  Unreleased changes live in [`changelog/unreleased/`](changelog/unreleased/). Add one Markdown file per feature (see that directory's README) instead of editing this section.
22
22
 
23
+ ## [57.21.0] - 2026-11-01
24
+
25
+ Upgrade note: [`mcp-server/src/docs/upgrades/57.21.0.md`](mcp-server/src/docs/upgrades/57.21.0.md).
26
+
27
+ ### Breaking
28
+
29
+ - The `terreno-scan` plugin is now `terreno-loop`, and its skills are renamed from `terreno-scan-*` to `terreno-loop-*`. The resident loop `terreno-scan-loop` is now `terreno-loop-run`: `/terreno-loop:run` in Claude Code, `/terreno-loop-run` in Cursor, `$terreno-loop-run` in Codex. Claude Code moves existing installs over through the marketplace `renames` entry. In Cursor and Codex, uninstall `terreno-scan` and install `terreno-loop`. Campaign state stays at `.terreno/scan/<goal>.json`, so campaigns already in progress resume.
30
+
31
+ ### Added
32
+
33
+ - `@terreno/admin-spa` serves an MCP OAuth consent screen at `/console/oauth/consent`, so a backend with no product frontend can set `mcpOAuth.consentUrl` to `${issuer}/console/oauth/consent`. Any signed-in user can approve or deny a request with their Better Auth session; signed-out users sign in and return through the login screen's new `returnTo` parameter, which accepts only in-app paths.
34
+ - Claude Code plugins now publish to npm with every release, as `@terreno/agent-plugin` and `@terreno/agent-plugin-loop`. A new `terreno-releases` marketplace installs them at the latest stable release. To pin one release, add `TerrenoLabs/terreno#<version>` instead. See [Install agent skills](docs/how-to/install-agent-skills.md#pick-a-channel).
35
+ - The generated Claude plugin manifest no longer pins `version`. Before this change, plugins installed from the `TerrenoLabs/terreno` marketplace stayed on the `2.12.0` copy, because their version never changed. They now update on every commit. Run `/plugin update terreno@terreno-plugins` once to leave `2.12.0`.
36
+ - The `terreno-planning` lifecycle plugin (2.13.0) plans e2e tests and manual regression cases in every IP:
37
+
38
+ - Grow requires `## E2E tests` and `## Regression cases` sections (either may be `None — <reason>`), read from the e2e guide at `docs/testing/e2e.md` or a `## Testing conventions` override in AGENTS.md or CLAUDE.md.
39
+ - Regression cases stay minimal: most features add none. A case is only for what a developer or QA must check by hand, such as push notifications, and Roast fails one that repeats an existing case.
40
+ - Pick writes each planned spec in the task that delivers it, and Roast runs it; a missing or failing row is `FAIL`.
41
+ - Brew gates on every planned spec and merges regression cases into `docs/regression/<area>.md` with the next free ID.
42
+ - Taste re-checks both sections after behaviour-changing fixes and renumbers regression ID collisions with `master`.
43
+ - `bun run check:lifecycle-skills` enforces these phrases in every stage.
44
+ - New `backfill-regression` skill proposes manual regression cases one area at a time and writes only the sets the human approves.
45
+ - A consumer opts out of manual regression suites with `Regression suites | none` in its `## Testing conventions` table.
46
+ - The `terreno-planning` lifecycle plugin (2.14.0) grows an end-user guide with every feature:
47
+
48
+ - Every IP has a `## User guide` section listing the guide pages it adds, updates, or retires, or `None — <reason>`. Pages live in `docs/user-guide/<area>/<feature>.md`, one feature per page, with `title`, `audience`, `platforms`, and `questions` frontmatter that chat agents use to answer "how do I…" questions.
49
+ - Pick writes each page in the task that ships the feature, Roast checks it against the shipped screens, Brew gates on it and the index, and Taste keeps it current after fixes.
50
+ - A repo opts out with `| User guide | none — <reason> |` in a `## User guide conventions` table in AGENTS.md or CLAUDE.md.
51
+ - New `backfill-user-guide` skill drafts pages for features that shipped without one, one area at a time, and writes only the pages the human approves.
52
+ - `bun run check:user-guide` validates the pages and index (CI `repo-policies`); `--uncovered <app dir>` lists screens no page names.
53
+ - Terreno's own guide covers the example app's main features.
54
+ - `@terreno/api`: opt-in `mcpRequestLog` on `TerrenoApp` records one metadata-only `McpRequestLog` row per MCP tool call (tool, user, credential, service token or OAuth client, duration, outcome, error class; never arguments, results, or error text), expiring after `retentionDays` (default 30).
55
+ - `@terreno/api`: opt-in `mcpToolSettings` on `TerrenoApp` registers every MCP tool in `McpToolSetting` at startup; tools an admin switches off are hidden from `tools/list` and rejected by `tools/call`.
56
+ - `@terreno/api`: deleting an `McpOAuthToken` row revokes its whole connection (token family) and keeps the rows. New `McpOAuthToken.revokeAllForUser` and `McpServiceToken.revokeAllForUser`.
57
+ - `@terreno/admin-backend`: `mcpAdminModels()` adds MCP admin screens (service tokens, OAuth clients, OAuth connections, request log, tool switches), `mcpAdminStatements` for RBAC, and `mcpAdminScripts()` adds `mcp-sign-out-everywhere`. See [Manage MCP from the admin panel](docs/how-to/manage-mcp-in-admin.md).
58
+ - Docs: [Expose an MCP server safely](docs/how-to/expose-mcp-server-safely.md) (OAuth, service tokens, Cloudflare Tunnel, Access) and the `bootstrap-mcp-server` skill for a single-binary MCP server with the admin console embedded.
59
+ - Every workspace package has a real-process smoke test and an e2e page:
60
+
61
+ - Each package's `e2e/smoke.ts` (or `smoke.spec.ts` for browser packages) runs its built output through its public entry: a server on a real port, the compiled binary, or a page in Chromium. `bun run --cwd <package> smoke` runs one; `bun run smoke` runs them all and prints each package's time. The CircleCI `smoke` job runs them on every package change.
62
+ - `@terreno/test` adds the smoke helpers `smokeMongoUri()`, `spawnUntilReady()`, `spawnExampleBackend()`, `runBin()`, and `freePort()`.
63
+ - The [E2E testing guide](docs/testing/e2e.md) explains the test tiers and links one page per package under `docs/testing/e2e/`.
64
+ - Manual regression cases live in `docs/regression/<area>.md`, one file per area, and `bun run check:regression-suites` validates them.
65
+ - example-frontend's smoke serves a web export that `bun run --cwd example-frontend export:smoke` builds once with a placeholder API URL; the smoke swaps in a `freePort()` API URL as it serves the bundle, so the 30 s smoke no longer rebuilds the export. `spawnUntilReady()` takes `stopGraceMs`, and `spawnExampleBackend()` stops example-backend after 0.5 s instead of 5 s.
66
+ - Every workspace package has a `typecheck` script that runs `tsc` over source and test files through a new `tsconfig.typecheck.json`. Root `bun run lint` ends with `bun run typecheck`, and CircleCI runs it in a new `typecheck` job. Test files that had type errors were fixed.
67
+
68
+ ### Changed
69
+
70
+ - `@terreno/api`: deleting an `McpOAuthToken` row with document or query `deleteOne` now revokes that row's whole token family (the connection) and keeps the rows instead of removing one pair. `deleteMany` is unchanged.
71
+ - `@terreno/ui`: new `theme.field` tokens (`background`, `backgroundDisabled`, `border`, `borderFocus`, `borderError`, `borderDisabled`) style form inputs. `TextField`, `SelectField`, `DateTimeField`, `HeightField`, and `OtpField` read them instead of `surface.base` and `border.dark`. Defaults equal the old colors, but overriding `surface` or `border` no longer recolors those fields; use `setTheme({field: ...})`.
72
+
23
73
  ## [57.20.0] - 2026-10-30
24
74
 
25
75
  Upgrade note: [`mcp-server/src/docs/upgrades/57.20.0.md`](mcp-server/src/docs/upgrades/57.20.0.md).
package/biome.jsonc CHANGED
@@ -5,6 +5,7 @@
5
5
  "includes": [
6
6
  "package.json",
7
7
  "src/**/*.ts",
8
+ "e2e/**/*.ts",
8
9
  "!!**/node_modules",
9
10
  "!!node_modules",
10
11
  "!!**/dist",
package/e2e/smoke.ts ADDED
@@ -0,0 +1,287 @@
1
+ /**
2
+ * Real-process smoke for @terreno/comms. Run `bun e2e/smoke.ts` after `bun run compile`.
3
+ *
4
+ * The smoke re-runs this file with `serve` as a child process: a TerrenoApp built from the compiled
5
+ * packages with `CommsApp` and `WebhooksApp`, on a free port, against `smokeMongoUri()`. Mail goes
6
+ * through `SendGridMailProvider` with an in-memory client, so nothing leaves the machine. The
7
+ * parent then checks over real HTTP that an admin can send a message, that the comms dashboard
8
+ * records it as sent, and that a signed SendGrid `delivered` event marks it delivered. Exits
9
+ * non-zero on the first failed check.
10
+ */
11
+ import crypto from "node:crypto";
12
+ import {
13
+ freePort,
14
+ type SpawnedProcess,
15
+ smokeMongoUri,
16
+ spawnUntilReady,
17
+ stopSmokeMongo,
18
+ } from "@terreno/test";
19
+ import type express from "express";
20
+ import {DateTime} from "luxon";
21
+
22
+ const SERVE_ARG = "serve";
23
+ const ADMIN_PASSWORD = "comms-smoke-password-1";
24
+ const FROM_EMAIL = "comms-smoke@example.com";
25
+ const SUBJECT = "Comms smoke";
26
+
27
+ /**
28
+ * Unique per run, so the smoke can rerun against a persistent `TERRENO_TEST_MONGODB_URI` without
29
+ * colliding with an earlier run's admin user or SendGrid message id.
30
+ */
31
+ const runId = (): string => process.env.COMMS_SMOKE_RUN_ID as string;
32
+ const adminEmail = (): string => `comms-smoke-admin-${runId()}@example.com`;
33
+ const providerMessageIdFor = (count: number): string => `comms-smoke-${runId()}-${count}`;
34
+
35
+ interface SmokeSendResult {
36
+ accepted: boolean;
37
+ loggedMessageId?: string;
38
+ providerMessageId?: string;
39
+ }
40
+
41
+ interface SmokeCommsMessage {
42
+ channel: string;
43
+ provider: string;
44
+ status: string;
45
+ }
46
+
47
+ /**
48
+ * Child: the compiled API with an admin user, CommsApp on an in-memory SendGrid client, and one
49
+ * smoke action that sends mail the way app code does. The packages are imported here, not at the
50
+ * top, so the parent process never loads them.
51
+ */
52
+ const serve = async (): Promise<void> => {
53
+ const {logger, modelRouter, Permissions, TerrenoApp, WebhooksApp, z} = await import(
54
+ "@terreno/api"
55
+ );
56
+ const {UserModel} = await import("@terreno/api/testing");
57
+ const {CommsApp, CommsMessage, getCommsService} = await import("@terreno/comms");
58
+ const {SendGridMailProvider} = await import("@terreno/comms/adapters/sendgrid");
59
+ const {default: mongoose} = await import("mongoose");
60
+
61
+ let sentCount = 0;
62
+ const mail = new SendGridMailProvider({
63
+ apiKey: "comms-smoke-key",
64
+ // Stands in for `@sendgrid/mail`; SendGrid's 202 carries the message id in `x-message-id`.
65
+ client: {
66
+ send: async (): Promise<
67
+ [{headers: Record<string, string>; statusCode: number}, Record<string, unknown>]
68
+ > => {
69
+ sentCount += 1;
70
+ return [{headers: {"x-message-id": providerMessageIdFor(sentCount)}, statusCode: 202}, {}];
71
+ },
72
+ },
73
+ fromEmail: FROM_EMAIL,
74
+ webhookVerificationKey: process.env.SENDGRID_WEBHOOK_VERIFICATION_KEY,
75
+ });
76
+ const webhooks = new WebhooksApp({idempotency: {store: "memory"}});
77
+ const comms = new CommsApp({mail, webhooks});
78
+
79
+ const smokeRouter = modelRouter("/commsSmoke", CommsMessage, {
80
+ collectionActions: {
81
+ sendMail: {
82
+ body: z.object({text: z.string()}).strict(),
83
+ handler: async ({body, user}) => {
84
+ const sender = user as unknown as {_id: unknown; email: string};
85
+ return getCommsService().sendMail(
86
+ {subject: SUBJECT, text: (body as {text: string}).text, to: sender.email},
87
+ {userId: String(sender._id)}
88
+ );
89
+ },
90
+ method: "POST",
91
+ permissions: [Permissions.IsAdmin],
92
+ },
93
+ },
94
+ permissions: {create: [], delete: [], list: [], read: [], update: []},
95
+ });
96
+
97
+ const healthPlugin = {
98
+ register: (app: express.Application): void => {
99
+ app.get("/health", (_req, res) => {
100
+ res.json({healthy: mongoose.connection.readyState === 1});
101
+ });
102
+ },
103
+ };
104
+
105
+ // The admin is seeded, not signed up: signup never grants `admin`, and the dashboard needs it.
106
+ // `register` comes from the model's passport-local-mongoose plugin, which its type omits.
107
+ const registrableUsers = UserModel as unknown as {
108
+ register: (user: unknown, password: string) => Promise<unknown>;
109
+ };
110
+ await mongoose.connect(process.env.MONGO_URI as string);
111
+ await registrableUsers.register(
112
+ new UserModel({admin: true, email: adminEmail()}),
113
+ ADMIN_PASSWORD
114
+ );
115
+ const app = new TerrenoApp({
116
+ loggingOptions: {logRequests: false},
117
+ userModel: UserModel as unknown as ConstructorParameters<typeof TerrenoApp>[0]["userModel"],
118
+ })
119
+ .register(comms)
120
+ .register(webhooks)
121
+ .register(smokeRouter)
122
+ .register(healthPlugin);
123
+ app.start();
124
+ await app.whenReady();
125
+ logger.info(`[commsSmoke] serving on port ${process.env.PORT}`);
126
+ };
127
+
128
+ const expectStatus = async (res: Response, status: number, step: string): Promise<unknown> => {
129
+ const body = await res.text();
130
+ if (res.status !== status) {
131
+ throw new Error(`${step}: expected ${status}, got ${res.status}: ${body}`);
132
+ }
133
+ return body ? JSON.parse(body) : undefined;
134
+ };
135
+
136
+ const expectMessageStatus = async ({
137
+ baseUrl,
138
+ headers,
139
+ messageId,
140
+ status,
141
+ }: {
142
+ baseUrl: string;
143
+ headers: Record<string, string>;
144
+ messageId: string;
145
+ status: string;
146
+ }): Promise<void> => {
147
+ const step = `GET /comms/messages/${messageId}`;
148
+ const read = (await expectStatus(
149
+ await fetch(`${baseUrl}/comms/messages/${messageId}`, {headers}),
150
+ 200,
151
+ step
152
+ )) as {data: SmokeCommsMessage};
153
+ const {channel, provider} = read.data;
154
+ if (read.data.status !== status || channel !== "mail" || provider !== "sendgrid") {
155
+ throw new Error(`${step}: expected a sendgrid mail row ${status}, got ${JSON.stringify(read)}`);
156
+ }
157
+ };
158
+
159
+ /** Signs a SendGrid Event Webhook body the way SendGrid does: ECDSA P-256 over timestamp + body. */
160
+ const signSendGridEvents = ({
161
+ payload,
162
+ privateKey,
163
+ }: {
164
+ payload: string;
165
+ privateKey: crypto.KeyObject;
166
+ }): Record<string, string> => {
167
+ const timestamp = String(DateTime.utc().toUnixInteger());
168
+ const signer = crypto.createSign("SHA256");
169
+ signer.update(timestamp);
170
+ signer.update(payload);
171
+ signer.end();
172
+ return {
173
+ "Content-Type": "application/json",
174
+ "X-Twilio-Email-Event-Webhook-Signature": signer.sign(privateKey, "base64"),
175
+ "X-Twilio-Email-Event-Webhook-Timestamp": timestamp,
176
+ };
177
+ };
178
+
179
+ /** Parent: boots the child and walks send → sent → delivered over HTTP. */
180
+ const run = async (): Promise<void> => {
181
+ const startedAt = DateTime.now();
182
+ process.env.COMMS_SMOKE_RUN_ID = String(startedAt.toMillis());
183
+ const port = await freePort();
184
+ const baseUrl = `http://127.0.0.1:${port}`;
185
+ const keyPair = crypto.generateKeyPairSync("ec", {namedCurve: "prime256v1"});
186
+ let server: SpawnedProcess | undefined;
187
+
188
+ try {
189
+ server = await spawnUntilReady({
190
+ cmd: [process.execPath, __filename, SERVE_ARG],
191
+ env: {
192
+ COMMS_SMOKE_RUN_ID: runId(),
193
+ MONGO_URI: await smokeMongoUri({databaseName: "commsSmoke"}),
194
+ PORT: String(port),
195
+ REFRESH_TOKEN_SECRET: "comms-smoke-refresh-secret",
196
+ SENDGRID_WEBHOOK_VERIFICATION_KEY: keyPair.publicKey
197
+ .export({format: "pem", type: "spki"})
198
+ .toString(),
199
+ SESSION_SECRET: "comms-smoke-session-secret",
200
+ TOKEN_ISSUER: "comms-smoke",
201
+ TOKEN_SECRET: "comms-smoke-token-secret",
202
+ },
203
+ timeoutMs: 20000,
204
+ url: `${baseUrl}/health`,
205
+ });
206
+
207
+ const login = (await expectStatus(
208
+ await fetch(`${baseUrl}/auth/login`, {
209
+ body: JSON.stringify({email: adminEmail(), password: ADMIN_PASSWORD}),
210
+ headers: {"Content-Type": "application/json"},
211
+ method: "POST",
212
+ }),
213
+ 200,
214
+ "POST /auth/login"
215
+ )) as {data: {token: string}};
216
+ const headers = {
217
+ Authorization: `Bearer ${login.data.token}`,
218
+ "Content-Type": "application/json",
219
+ };
220
+ console.info("✅ POST /auth/login signs the admin in");
221
+
222
+ const sent = (await expectStatus(
223
+ await fetch(`${baseUrl}/commsSmoke/sendMail`, {
224
+ body: JSON.stringify({text: "Sent by the comms smoke"}),
225
+ headers,
226
+ method: "POST",
227
+ }),
228
+ 200,
229
+ "POST /commsSmoke/sendMail"
230
+ )) as {data: SmokeSendResult};
231
+ const {accepted, loggedMessageId, providerMessageId} = sent.data;
232
+ if (!accepted || !loggedMessageId || providerMessageId !== providerMessageIdFor(1)) {
233
+ throw new Error(
234
+ `POST /commsSmoke/sendMail: expected an accepted, logged send through the in-memory client, got ${JSON.stringify(sent)}`
235
+ );
236
+ }
237
+ console.info("✅ POST /commsSmoke/sendMail sends through the in-memory SendGrid client");
238
+
239
+ await expectMessageStatus({baseUrl, headers, messageId: loggedMessageId, status: "sent"});
240
+ console.info("✅ GET /comms/messages/:id records the message as sent");
241
+
242
+ const payload = JSON.stringify([
243
+ {
244
+ email: adminEmail(),
245
+ event: "delivered",
246
+ sg_event_id: `comms-smoke-event-${runId()}`,
247
+ sg_message_id: `${providerMessageId}.filter0001.1.1`,
248
+ },
249
+ ]);
250
+ await expectStatus(
251
+ await fetch(`${baseUrl}/comms/webhooks/sendgrid`, {
252
+ body: payload,
253
+ headers: signSendGridEvents({payload, privateKey: keyPair.privateKey}),
254
+ method: "POST",
255
+ }),
256
+ 200,
257
+ "POST /comms/webhooks/sendgrid"
258
+ );
259
+ console.info("✅ POST /comms/webhooks/sendgrid accepts a signed delivered event");
260
+
261
+ await expectMessageStatus({baseUrl, headers, messageId: loggedMessageId, status: "delivered"});
262
+ console.info("✅ GET /comms/messages/:id records the message as delivered");
263
+ } catch (error: unknown) {
264
+ if (server) {
265
+ console.error(`--- server output ---\n${server.output()}`);
266
+ }
267
+ throw error;
268
+ } finally {
269
+ await server?.stop();
270
+ await stopSmokeMongo();
271
+ }
272
+
273
+ console.info(`comms smoke passed in ${DateTime.now().diff(startedAt).toMillis()} ms`);
274
+ };
275
+
276
+ const main = process.argv[2] === SERVE_ARG ? serve : run;
277
+ main().then(
278
+ () => {
279
+ if (main === run) {
280
+ process.exit(0);
281
+ }
282
+ },
283
+ (error: unknown) => {
284
+ console.error(`❌ ${error instanceof Error ? error.message : String(error)}`);
285
+ process.exit(1);
286
+ }
287
+ );
package/package.json CHANGED
@@ -4,14 +4,14 @@
4
4
  "url": "https://github.com/TerrenoLabs/terreno/issues"
5
5
  },
6
6
  "dependencies": {
7
- "@terreno/api": "57.20.0",
7
+ "@terreno/api": "57.21.0",
8
8
  "libphonenumber-js": "^1.13.8",
9
9
  "luxon": "^3.7.2"
10
10
  },
11
11
  "description": "Pluggable mail, SMS, push, and verification providers — part of Terreno, the batteries-included TypeScript framework for universal apps.",
12
12
  "devDependencies": {
13
13
  "@biomejs/biome": "^2.3.6",
14
- "@terreno/test": "57.20.0",
14
+ "@terreno/test": "57.21.0",
15
15
  "@types/bun": "^1.4.0",
16
16
  "@types/express": "^5.0.6",
17
17
  "@types/luxon": "^3.7.1",
@@ -81,13 +81,15 @@
81
81
  "compile": "bun tsc",
82
82
  "compile:watch": "bun tsc -w",
83
83
  "dev": "bun tsc -w",
84
- "lint": "biome check ./src",
85
- "lint:fix": "biome check --write ./src",
84
+ "lint": "biome check ./src ./e2e",
85
+ "lint:fix": "biome check --write ./src ./e2e",
86
+ "smoke": "bun e2e/smoke.ts",
86
87
  "test": "bun test",
87
88
  "test:agent": "AGENT=1 bun test --only-failures",
88
89
  "test:ci": "bun test",
89
- "test:coverage": "bun run ../scripts/check-coverage.ts"
90
+ "test:coverage": "bun run ../scripts/check-coverage.ts",
91
+ "typecheck": "tsc -p tsconfig.typecheck.json"
90
92
  },
91
93
  "types": "dist/index.d.ts",
92
- "version": "57.20.0"
94
+ "version": "57.21.0"
93
95
  }
@@ -8,8 +8,10 @@ import {CommsService} from "./commsService";
8
8
  import {CommsMessage} from "./models/commsMessage";
9
9
  import {PushToken} from "./models/pushToken";
10
10
  import type {
11
+ BeforeSendResult,
11
12
  CheckVerificationOptions,
12
13
  CommsHookContext,
14
+ DeliveryEvent,
13
15
  MailMessage,
14
16
  MailProvider,
15
17
  PushMessage,
@@ -18,6 +20,7 @@ import type {
18
20
  SmsProvider,
19
21
  StartVerificationOptions,
20
22
  VerificationProvider,
23
+ VerificationResult,
21
24
  } from "./types";
22
25
 
23
26
  const captureError = async (operation: () => Promise<unknown>): Promise<unknown> => {
@@ -71,7 +74,7 @@ describe("CommsService", () => {
71
74
  })),
72
75
  };
73
76
  const verification: VerificationProvider = {
74
- checkVerification: async (): Promise<{valid: boolean}> => ({valid: true}),
77
+ checkVerification: async (): Promise<VerificationResult> => ({valid: true}),
75
78
  id: "memory-verification",
76
79
  startVerification: async (): Promise<SendResult> => ({
77
80
  accepted: true,
@@ -656,7 +659,7 @@ describe("CommsService", () => {
656
659
  sendSms: async (): Promise<SendResult> => ({accepted: true}),
657
660
  },
658
661
  verification: {
659
- checkVerification: async (): Promise<{valid: boolean}> => ({error: "bad", valid: false}),
662
+ checkVerification: async (): Promise<VerificationResult> => ({error: "bad", valid: false}),
660
663
  id: "hook-verification",
661
664
  startVerification: async (): Promise<SendResult> => ({accepted: true}),
662
665
  },
@@ -1002,7 +1005,7 @@ describe("CommsService", () => {
1002
1005
  const errorSpy = spyOn(logger, "error");
1003
1006
  try {
1004
1007
  const service = new CommsService({
1005
- beforeSend: async (): Promise<void> => {
1008
+ beforeSend: async (): Promise<BeforeSendResult | undefined> => {
1006
1009
  throw new Error("beforeSend boom for person@example.com key=sg.secret");
1007
1010
  },
1008
1011
  mail: {
@@ -1313,7 +1316,7 @@ describe("CommsService", () => {
1313
1316
  sendSms: async (): Promise<SendResult> => ({accepted: true}),
1314
1317
  },
1315
1318
  verification: {
1316
- checkVerification: async (): Promise<{valid: boolean}> => ({valid: true}),
1319
+ checkVerification: async (): Promise<VerificationResult> => ({valid: true}),
1317
1320
  id: "shape-verification",
1318
1321
  startVerification: async (): Promise<SendResult> => ({accepted: true}),
1319
1322
  },
@@ -1436,7 +1439,7 @@ describe("CommsService", () => {
1436
1439
  let checkCalls = 0;
1437
1440
  const service = new CommsService({
1438
1441
  verification: {
1439
- checkVerification: async (): Promise<{valid: boolean}> => {
1442
+ checkVerification: async (): Promise<VerificationResult> => {
1440
1443
  checkCalls += 1;
1441
1444
  return {error: "bad", valid: false};
1442
1445
  },
@@ -1489,7 +1492,7 @@ describe("CommsService", () => {
1489
1492
  },
1490
1493
  },
1491
1494
  verification: {
1492
- checkVerification: async (): Promise<{valid: boolean}> => ({valid: true}),
1495
+ checkVerification: async (): Promise<VerificationResult> => ({valid: true}),
1493
1496
  id: "cancel-verification",
1494
1497
  startVerification: async (): Promise<SendResult> => {
1495
1498
  providerCalls += 1;
@@ -1548,7 +1551,7 @@ describe("CommsService", () => {
1548
1551
 
1549
1552
  it("reports each channel as configured only with a provider in production", (): void => {
1550
1553
  const verification: VerificationProvider = {
1551
- checkVerification: async (): Promise<{valid: boolean}> => ({valid: true}),
1554
+ checkVerification: async (): Promise<VerificationResult> => ({valid: true}),
1552
1555
  id: "configured-verification",
1553
1556
  startVerification: async (): Promise<SendResult> => ({accepted: true}),
1554
1557
  };
@@ -1756,7 +1759,8 @@ describe("CommsService", () => {
1756
1759
  to: "person@example.com",
1757
1760
  });
1758
1761
 
1759
- await service.recordDeliveryEvent({channel: "mail", status: "delivered"});
1762
+ // Providers can post events without a message id; the service must tolerate them.
1763
+ await service.recordDeliveryEvent({channel: "mail", status: "delivered"} as DeliveryEvent);
1760
1764
 
1761
1765
  assert.deepEqual(events, ["delivered"]);
1762
1766
  const unchanged = await CommsMessage.findExactlyOne({_id: row._id});
@@ -67,7 +67,7 @@ const buildSendGridCommsApp = ({
67
67
  } = {}): {
68
68
  app: Application;
69
69
  comms: CommsApp;
70
- keyPair: crypto.KeyPairKeyObjectResult;
70
+ keyPair: {privateKey: crypto.KeyObject; publicKey: crypto.KeyObject};
71
71
  } => {
72
72
  const keyPair = crypto.generateKeyPairSync("ec", {namedCurve: "prime256v1"});
73
73
  const publicKey = keyPair.publicKey.export({format: "pem", type: "spki"}).toString();
@@ -0,0 +1,18 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "noEmit": true,
5
+ "composite": false,
6
+ "incremental": false,
7
+ "declaration": false,
8
+ "declarationMap": false,
9
+ "types": [
10
+ "node",
11
+ "bun"
12
+ ]
13
+ },
14
+ "exclude": [
15
+ "node_modules",
16
+ "dist"
17
+ ]
18
+ }