@crvouga/mockingbird-notifications 0.1.0 → 0.2.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/dist/cli.js CHANGED
@@ -2,9 +2,9 @@
2
2
  import {
3
3
  DEFAULT_PORT,
4
4
  createServer
5
- } from "./chunk-JQ6KPT2C.js";
6
- import "./chunk-GRGR3QZM.js";
7
- import "./chunk-QE3TRUI6.js";
5
+ } from "./chunk-4QVURMVP.js";
6
+ import "./chunk-GHIEYY5B.js";
7
+ import "./chunk-3HF2NSFV.js";
8
8
 
9
9
  // src/cli.ts
10
10
  import { parseArgs } from "node:util";
@@ -25,6 +25,8 @@ Options:
25
25
  or every fleet namespace with --fleet)
26
26
  --poll <ms> Background poll interval (default 750; 0 reads only on demand)
27
27
  --admin-key-env <V> Environment variable holding the admin key (default MOCKINGBIRD_ADMIN_KEY)
28
+ --tab <name> Tab the page opens on: notifications (default) or emulators
29
+ --no-emulators Serve the notifications UI alone, without the Emulators tab
28
30
  --ready-json Print {"url": \u2026} as one JSON line once listening
29
31
  -h, --help Show this help
30
32
  `;
@@ -41,6 +43,8 @@ var main = async (argv) => {
41
43
  namespace: { type: "string", multiple: true },
42
44
  poll: { type: "string" },
43
45
  "admin-key-env": { type: "string" },
46
+ tab: { type: "string" },
47
+ "no-emulators": { type: "boolean" },
44
48
  "ready-json": { type: "boolean" },
45
49
  help: { type: "boolean", short: "h" }
46
50
  }
@@ -66,6 +70,8 @@ var main = async (argv) => {
66
70
  const poll = values.poll === void 0 ? void 0 : Number(values.poll);
67
71
  if (poll !== void 0 && (!Number.isFinite(poll) || poll < 0))
68
72
  throw new Error("--poll: expected milliseconds");
73
+ if (values.tab !== void 0 && values.tab !== "emulators" && values.tab !== "notifications")
74
+ throw new Error("--tab: expected emulators or notifications");
69
75
  const adminKey = process.env[values["admin-key-env"] ?? "MOCKINGBIRD_ADMIN_KEY"];
70
76
  const server = await createServer({
71
77
  port,
@@ -75,7 +81,9 @@ var main = async (argv) => {
75
81
  ...Object.keys(services).length ? { services } : {},
76
82
  ...values.namespace?.length ? { namespaces: values.namespace } : {},
77
83
  ...poll !== void 0 ? { pollIntervalMs: poll } : {},
78
- ...adminKey ? { adminKey } : {}
84
+ ...adminKey ? { adminKey } : {},
85
+ ...values.tab ? { defaultTab: values.tab } : {},
86
+ ...values["no-emulators"] ? { admin: false } : {}
79
87
  });
80
88
  if (values["ready-json"]) process.stdout.write(`${JSON.stringify({ url: server.url })}
81
89
  `);
package/dist/cli.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/cli.ts"],
4
- "sourcesContent": ["#!/usr/bin/env node\n/// <reference types=\"node\" />\nimport { parseArgs } from \"node:util\"\nimport type { ServiceInput } from \"./discovery.js\"\nimport { createServer, DEFAULT_PORT } from \"./server.js\"\n\nconst HELP = `mockingbird-notifications \u2014 see every SMS, email and push your app sends through Mockingbird\n\nUsage:\n mockingbird-notifications serve [options]\n\nWhere the emulators are (pick one or combine):\n --fleet <url> Running fleet controller adminBase, e.g. http://127.0.0.1:9000/__admin/fleet\n --manifest <file> The fleet's --ready-file (re-read on every sync, so restarts are followed)\n --service <n=url> An emulator by name, e.g. --service twilio=http://127.0.0.1:8798 (repeatable)\n\nOptions:\n --port <n> Listen port (default ${DEFAULT_PORT}; 0 picks a free one)\n --host <host> Listen host (default 127.0.0.1)\n --namespace <name> Namespace to watch in the background (repeatable; default \"default\",\n or every fleet namespace with --fleet)\n --poll <ms> Background poll interval (default 750; 0 reads only on demand)\n --admin-key-env <V> Environment variable holding the admin key (default MOCKINGBIRD_ADMIN_KEY)\n --ready-json Print {\"url\": \u2026} as one JSON line once listening\n -h, --help Show this help\n`\n\nconst main = async (argv: string[]): Promise<number> => {\n const { values, positionals } = parseArgs({\n args: argv,\n allowPositionals: true,\n options: {\n fleet: { type: \"string\" },\n manifest: { type: \"string\" },\n service: { type: \"string\", multiple: true },\n port: { type: \"string\" },\n host: { type: \"string\" },\n namespace: { type: \"string\", multiple: true },\n poll: { type: \"string\" },\n \"admin-key-env\": { type: \"string\" },\n \"ready-json\": { type: \"boolean\" },\n help: { type: \"boolean\", short: \"h\" },\n },\n })\n if (values.help || positionals[0] !== \"serve\") {\n process.stdout.write(HELP)\n return values.help ? 0 : 2\n }\n const services: Record<string, ServiceInput> = {}\n for (const entry of values.service ?? []) {\n const eq = entry.indexOf(\"=\")\n if (eq <= 0) throw new Error(`--service ${entry}: expected name=url`)\n services[entry.slice(0, eq)] = entry.slice(eq + 1)\n }\n if (!values.fleet && !values.manifest && Object.keys(services).length === 0) {\n process.stderr.write(\"mockingbird-notifications: pass --fleet, --manifest or --service\\n\\n\")\n process.stderr.write(HELP)\n return 2\n }\n const port = values.port === undefined ? DEFAULT_PORT : Number(values.port)\n if (!Number.isInteger(port) || port < 0 || port > 65535)\n throw new Error(\"--port: expected 0\u201365535\")\n const poll = values.poll === undefined ? undefined : Number(values.poll)\n if (poll !== undefined && (!Number.isFinite(poll) || poll < 0))\n throw new Error(\"--poll: expected milliseconds\")\n const adminKey = process.env[values[\"admin-key-env\"] ?? \"MOCKINGBIRD_ADMIN_KEY\"]\n const server = await createServer({\n port,\n ...(values.host ? { host: values.host } : {}),\n ...(values.fleet ? { fleet: values.fleet } : {}),\n ...(values.manifest ? { manifest: values.manifest } : {}),\n ...(Object.keys(services).length ? { services } : {}),\n ...(values.namespace?.length ? { namespaces: values.namespace } : {}),\n ...(poll !== undefined ? { pollIntervalMs: poll } : {}),\n ...(adminKey ? { adminKey } : {}),\n })\n if (values[\"ready-json\"]) process.stdout.write(`${JSON.stringify({ url: server.url })}\\n`)\n else process.stdout.write(`Notifications harness: ${server.url}\\n`)\n await new Promise<void>((resolve) => {\n const stop = () => resolve()\n process.once(\"SIGINT\", stop)\n process.once(\"SIGTERM\", stop)\n })\n await server.close()\n return 0\n}\n\nmain(process.argv.slice(2)).then(\n (code) => {\n if (code !== 0) process.exitCode = code\n },\n (error: unknown) => {\n process.stderr.write(\n `mockingbird-notifications: ${error instanceof Error ? error.message : String(error)}\\n`,\n )\n process.exitCode = 1\n },\n)\n"],
5
- "mappings": ";;;;;;;;;AAEA,SAAS,iBAAiB;AAI1B,IAAM,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8CAWiC,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAU1D,IAAM,OAAO,OAAO,SAAoC;AACtD,QAAM,EAAE,QAAQ,YAAY,IAAI,UAAU;AAAA,IACxC,MAAM;AAAA,IACN,kBAAkB;AAAA,IAClB,SAAS;AAAA,MACP,OAAO,EAAE,MAAM,SAAS;AAAA,MACxB,UAAU,EAAE,MAAM,SAAS;AAAA,MAC3B,SAAS,EAAE,MAAM,UAAU,UAAU,KAAK;AAAA,MAC1C,MAAM,EAAE,MAAM,SAAS;AAAA,MACvB,MAAM,EAAE,MAAM,SAAS;AAAA,MACvB,WAAW,EAAE,MAAM,UAAU,UAAU,KAAK;AAAA,MAC5C,MAAM,EAAE,MAAM,SAAS;AAAA,MACvB,iBAAiB,EAAE,MAAM,SAAS;AAAA,MAClC,cAAc,EAAE,MAAM,UAAU;AAAA,MAChC,MAAM,EAAE,MAAM,WAAW,OAAO,IAAI;AAAA,IACtC;AAAA,EACF,CAAC;AACD,MAAI,OAAO,QAAQ,YAAY,CAAC,MAAM,SAAS;AAC7C,YAAQ,OAAO,MAAM,IAAI;AACzB,WAAO,OAAO,OAAO,IAAI;AAAA,EAC3B;AACA,QAAM,WAAyC,CAAC;AAChD,aAAW,SAAS,OAAO,WAAW,CAAC,GAAG;AACxC,UAAM,KAAK,MAAM,QAAQ,GAAG;AAC5B,QAAI,MAAM,EAAG,OAAM,IAAI,MAAM,aAAa,KAAK,qBAAqB;AACpE,aAAS,MAAM,MAAM,GAAG,EAAE,CAAC,IAAI,MAAM,MAAM,KAAK,CAAC;AAAA,EACnD;AACA,MAAI,CA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AM,IAAI,QAAc,CAAC,YAAY;AACnC,UAAM,OAAO,MAAM,QAAQ;AAC3B,YAAQ,KAAK,UAAU,IAAI;AAC3B,YAAQ,KAAK,WAAW,IAAI;AAAA,EAC9B,CAAC;AACD,QAAM,OAAO,MAAM;AACnB,SAAO;AACT;AAEA,KAAK,QAAQ,KAAK,MAAM,CAAC,CAAC,EAAE;AAAA,EAC1B,CAAC,SAAS;AACR,QAAI,SAAS,EAAG,SAAQ,WAAW;AAAA,EACrC;AAAA,EACA,CAAC,UAAmB;AAClB,YAAQ,OAAO;AAAA,MACb,8BAA8B,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;AAAA;AAAA,IACtF;AACA,YAAQ,WAAW;AAAA,EACrB;AACF;",
4
+ "sourcesContent": ["#!/usr/bin/env node\n/// <reference types=\"node\" />\nimport { parseArgs } from \"node:util\"\nimport type { ServiceInput } from \"./discovery.js\"\nimport { createServer, DEFAULT_PORT } from \"./server.js\"\n\nconst HELP = `mockingbird-notifications \u2014 see every SMS, email and push your app sends through Mockingbird\n\nUsage:\n mockingbird-notifications serve [options]\n\nWhere the emulators are (pick one or combine):\n --fleet <url> Running fleet controller adminBase, e.g. http://127.0.0.1:9000/__admin/fleet\n --manifest <file> The fleet's --ready-file (re-read on every sync, so restarts are followed)\n --service <n=url> An emulator by name, e.g. --service twilio=http://127.0.0.1:8798 (repeatable)\n\nOptions:\n --port <n> Listen port (default ${DEFAULT_PORT}; 0 picks a free one)\n --host <host> Listen host (default 127.0.0.1)\n --namespace <name> Namespace to watch in the background (repeatable; default \"default\",\n or every fleet namespace with --fleet)\n --poll <ms> Background poll interval (default 750; 0 reads only on demand)\n --admin-key-env <V> Environment variable holding the admin key (default MOCKINGBIRD_ADMIN_KEY)\n --tab <name> Tab the page opens on: notifications (default) or emulators\n --no-emulators Serve the notifications UI alone, without the Emulators tab\n --ready-json Print {\"url\": \u2026} as one JSON line once listening\n -h, --help Show this help\n`\n\nconst main = async (argv: string[]): Promise<number> => {\n const { values, positionals } = parseArgs({\n args: argv,\n allowPositionals: true,\n options: {\n fleet: { type: \"string\" },\n manifest: { type: \"string\" },\n service: { type: \"string\", multiple: true },\n port: { type: \"string\" },\n host: { type: \"string\" },\n namespace: { type: \"string\", multiple: true },\n poll: { type: \"string\" },\n \"admin-key-env\": { type: \"string\" },\n tab: { type: \"string\" },\n \"no-emulators\": { type: \"boolean\" },\n \"ready-json\": { type: \"boolean\" },\n help: { type: \"boolean\", short: \"h\" },\n },\n })\n if (values.help || positionals[0] !== \"serve\") {\n process.stdout.write(HELP)\n return values.help ? 0 : 2\n }\n const services: Record<string, ServiceInput> = {}\n for (const entry of values.service ?? []) {\n const eq = entry.indexOf(\"=\")\n if (eq <= 0) throw new Error(`--service ${entry}: expected name=url`)\n services[entry.slice(0, eq)] = entry.slice(eq + 1)\n }\n if (!values.fleet && !values.manifest && Object.keys(services).length === 0) {\n process.stderr.write(\"mockingbird-notifications: pass --fleet, --manifest or --service\\n\\n\")\n process.stderr.write(HELP)\n return 2\n }\n const port = values.port === undefined ? DEFAULT_PORT : Number(values.port)\n if (!Number.isInteger(port) || port < 0 || port > 65535)\n throw new Error(\"--port: expected 0\u201365535\")\n const poll = values.poll === undefined ? undefined : Number(values.poll)\n if (poll !== undefined && (!Number.isFinite(poll) || poll < 0))\n throw new Error(\"--poll: expected milliseconds\")\n if (values.tab !== undefined && values.tab !== \"emulators\" && values.tab !== \"notifications\")\n throw new Error(\"--tab: expected emulators or notifications\")\n const adminKey = process.env[values[\"admin-key-env\"] ?? \"MOCKINGBIRD_ADMIN_KEY\"]\n const server = await createServer({\n port,\n ...(values.host ? { host: values.host } : {}),\n ...(values.fleet ? { fleet: values.fleet } : {}),\n ...(values.manifest ? { manifest: values.manifest } : {}),\n ...(Object.keys(services).length ? { services } : {}),\n ...(values.namespace?.length ? { namespaces: values.namespace } : {}),\n ...(poll !== undefined ? { pollIntervalMs: poll } : {}),\n ...(adminKey ? { adminKey } : {}),\n ...(values.tab ? { defaultTab: values.tab } : {}),\n ...(values[\"no-emulators\"] ? { admin: false as const } : {}),\n })\n if (values[\"ready-json\"]) process.stdout.write(`${JSON.stringify({ url: server.url })}\\n`)\n else process.stdout.write(`Notifications harness: ${server.url}\\n`)\n await new Promise<void>((resolve) => {\n const stop = () => resolve()\n process.once(\"SIGINT\", stop)\n process.once(\"SIGTERM\", stop)\n })\n await server.close()\n return 0\n}\n\nmain(process.argv.slice(2)).then(\n (code) => {\n if (code !== 0) process.exitCode = code\n },\n (error: unknown) => {\n process.stderr.write(\n `mockingbird-notifications: ${error instanceof Error ? error.message : String(error)}\\n`,\n )\n process.exitCode = 1\n },\n)\n"],
5
+ "mappings": ";;;;;;;;;AAEA,SAAS,iBAAiB;AAI1B,IAAM,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8CAWiC,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAY1D,IAAM,OAAO,OAAO,SAAoC;AACtD,QAAM,EAAE,QAAQ,YAAY,IAAI,UAAU;AAAA,IACxC,MAAM;AAAA,IACN,kBAAkB;AAAA,IAClB,SAAS;AAAA,MACP,OAAO,EAAE,MAAM,SAAS;AAAA,MACxB,UAAU,EAAE,MAAM,SAAS;AAAA,MAC3B,SAAS,EAAE,MAAM,UAAU,UAAU,KAAK;AAAA,MAC1C,MAAM,EAAE,MAAM,SAAS;AAAA,MACvB,MAAM,EAAE,MAAM,SAAS;AAAA,MACvB,WAAW,EAAE,MAAM,UAAU,UAAU,KAAK;AAAA,MAC5C,MAAM,EAAE,MAAM,SAAS;AAAA,MACvB,iBAAiB,EAAE,MAAM,SAAS;AAAA,MAClC,KAAK,EAAE,MAAM,SAAS;AAAA,MACtB,gBAAgB,EAAE,MAAM,UAAU;AAAA,MAClC,cAAc,EAAE,MAAM,UAAU;AAAA,MAChC,MAAM,EAAE,MAAM,WAAW,OAAO,IAAI;AAAA,IAC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AAO,WAAW,EAAE,UAAU,OAAO,SAAS,IAAI,CAAC;AAAA,IACvD,GAAI,OAAO,KAAK,QAAQ,EAAE,SAAS,EAAE,SAAS,IAAI,CAAC;AAAA,IACnD,GAAI,OAAO,WAAW,SAAS,EAAE,YAAY,OAAO,UAAU,IAAI,CAAC;AAAA,IACnE,GAAI,SAAS,SAAY,EAAE,gBAAgB,KAAK,IAAI,CAAC;AAAA,IACrD,GAAI,WAAW,EAAE,SAAS,IAAI,CAAC;AAAA,IAC/B,GAAI,OAAO,MAAM,EAAE,YAAY,OAAO,IAAI,IAAI,CAAC;AAAA,IAC/C,GAAI,OAAO,cAAc,IAAI,EAAE,OAAO,MAAe,IAAI,CAAC;AAAA,EAC5D,CAAC;AACD,MAAI,OAAO,YAAY,EAAG,SAAQ,OAAO,MAAM,GAAG,KAAK,UAAU,EAAE,KAAK,OAAO,IAAI,CAAC,CAAC;AAAA,CAAI;AAAA,MACpF,SAAQ,OAAO,MAAM,0BAA0B,OAAO,GAAG;AAAA,CAAI;AAClE,QAAM,IAAI,QAAc,CAAC,YAAY;AACnC,UAAM,OAAO,MAAM,QAAQ;AAC3B,YAAQ,KAAK,UAAU,IAAI;AAC3B,YAAQ,KAAK,WAAW,IAAI;AAAA,EAC9B,CAAC;AACD,QAAM,OAAO,MAAM;AACnB,SAAO;AACT;AAEA,KAAK,QAAQ,KAAK,MAAM,CAAC,CAAC,EAAE;AAAA,EAC1B,CAAC,SAAS;AACR,QAAI,SAAS,EAAG,SAAQ,WAAW;AAAA,EACrC;AAAA,EACA,CAAC,UAAmB;AAClB,YAAQ,OAAO;AAAA,MACb,8BAA8B,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;AAAA;AAAA,IACtF;AACA,YAAQ,WAAW;AAAA,EACrB;AACF;",
6
6
  "names": []
7
7
  }
package/dist/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
- /** The three kinds of device a notification lands on. */
2
- type Channel = "sms" | "email" | "push";
1
+ /** The kinds of device a notification lands on. */
2
+ type Channel = "sms" | "email" | "push" | "chat";
3
+ /** Every channel, in the order the devices are laid out. */
4
+ declare const CHANNELS: readonly Channel[];
3
5
  /** Emulators the harness knows how to read. */
4
- type ServiceKind = "twilio" | "resend" | "fcm" | "ses" | "sns" | "customerio" | "mailosaur";
6
+ type ServiceKind = "twilio" | "resend" | "fcm" | "ses" | "sns" | "customerio" | "mailosaur" | "slack";
5
7
  declare const SERVICE_KINDS: readonly ServiceKind[];
6
8
  declare const SERVICE_LABELS: Record<ServiceKind, string>;
7
9
  type Address = {
@@ -13,6 +15,8 @@ type SmsContent = {
13
15
  /** One-time code the sender included (Twilio Verify), when known. */
14
16
  code: string | null;
15
17
  media: string[];
18
+ /** `whatsapp` when the message went to a `whatsapp:` address; plain text messages omit it. */
19
+ via?: "sms" | "whatsapp";
16
20
  };
17
21
  type EmailAttachment = {
18
22
  filename: string;
@@ -41,6 +45,31 @@ type PushContent = {
41
45
  badge: number | null;
42
46
  sound: string | null;
43
47
  };
48
+ type ChatReaction = {
49
+ name: string;
50
+ count: number;
51
+ };
52
+ /** A message posted into a team chat channel (Slack). */
53
+ type ChatContent = {
54
+ /** The message text, in the provider's own markup (Slack mrkdwn). */
55
+ text: string;
56
+ /** Workspace the message was posted in. */
57
+ workspace: string | null;
58
+ /** How it arrived: `chat.postMessage`, `chat.postEphemeral` or `incoming-webhook`. */
59
+ method: string;
60
+ /** Block Kit blocks, exactly as sent. */
61
+ blocks: unknown[];
62
+ /** Legacy attachments, exactly as sent. */
63
+ attachments: unknown[];
64
+ /** Parent message timestamp when this is a threaded reply. */
65
+ threadTs: string | null;
66
+ /** Shown to one member only. */
67
+ ephemeral: boolean;
68
+ edited: boolean;
69
+ reactions: ChatReaction[];
70
+ /** Display names of the users and channels the message mentions by id (`U…` → `ada`). */
71
+ names?: Record<string, string>;
72
+ };
44
73
  /** One message as a recipient would receive it, normalized across emulators. */
45
74
  type Notification = {
46
75
  /** Stable across polls: `<service entry>:<namespace>:<provider id>`. */
@@ -52,7 +81,7 @@ type Notification = {
52
81
  source: string;
53
82
  service: ServiceKind;
54
83
  namespace: string;
55
- /** Phone number, email address, or push registration token. */
84
+ /** Phone number, email address, push registration token, or chat channel (`#alerts`). */
56
85
  to: string;
57
86
  from: Address;
58
87
  /** ISO-8601, on the emulator's clock. */
@@ -64,6 +93,8 @@ type Notification = {
64
93
  sms: SmsContent | null;
65
94
  email: EmailContent | null;
66
95
  push: PushContent | null;
96
+ /** Set on `chat` notifications; absent or null on every other channel. */
97
+ chat?: ChatContent | null;
67
98
  /** The record exactly as the emulator reported it. */
68
99
  raw: unknown;
69
100
  };
@@ -116,7 +147,7 @@ declare class NotificationClient {
116
147
  sources(): Promise<SourceStatus[]>;
117
148
  /** A UI link that opens one device (or one notification) for a screenshot. */
118
149
  link(view?: {
119
- channel?: "sms" | "email" | "push";
150
+ channel?: Channel;
120
151
  to?: string;
121
152
  id?: string;
122
153
  }): string;
@@ -157,6 +188,19 @@ type Endpoint = {
157
188
  adminUrl: string;
158
189
  fetch: FetchLike;
159
190
  };
191
+ /**
192
+ * An emulator whose admin API the dashboard fronts. Unlike {@link Endpoint} this is every HTTP
193
+ * emulator, messaging or not (stripe, cognito, …).
194
+ */
195
+ type AdminTarget = {
196
+ /** The fleet entry name, e.g. `stripe`, or an alias such as `push`. */
197
+ name: string;
198
+ /** The emulator it runs, e.g. `fcm` for the alias `push`. The name when nobody said. */
199
+ target: string;
200
+ /** Absolute admin prefix, e.g. `http://127.0.0.1:8798/__admin`. */
201
+ adminUrl: string;
202
+ fetch: FetchLike;
203
+ };
160
204
 
161
205
  type HarnessOptions = {
162
206
  /** A running fleet controller's `adminBase` (`http://127.0.0.1:9000/__admin/fleet`). */
@@ -175,11 +219,35 @@ type HarnessOptions = {
175
219
  pollIntervalMs?: number;
176
220
  /** Sent as `x-mockingbird-admin-key` to the fleet and every emulator. */
177
221
  adminKey?: string;
222
+ /** Admin keys by emulator name, for emulators whose key is not `adminKey`. */
223
+ adminKeys?: Record<string, string>;
224
+ /**
225
+ * Front every emulator's admin API on this origin, so the page shows an Emulators tab next to
226
+ * Notifications. `createServer` (the `./server` entry) turns it on; pass `adminGateway()` from
227
+ * that entry to turn it on for a harness you serve yourself.
228
+ */
229
+ admin?: AdminGatewayFactory | false;
230
+ /** The tab the page opens on when it has both. Default `notifications`. */
231
+ defaultTab?: "emulators" | "notifications";
178
232
  /** Transport for URL endpoints. Default: global `fetch`. */
179
233
  fetch?: FetchLike;
180
234
  /** Page title. */
181
235
  title?: string;
182
236
  };
237
+ type AdminGatewayContext = {
238
+ /** Every HTTP emulator the harness knows, messaging or not, after a fresh discovery. */
239
+ targets(): Promise<AdminTarget[]>;
240
+ /** The admin key header for one emulator: empty when the harness has no key for it. */
241
+ headers(name: string): Record<string, string>;
242
+ title: string;
243
+ };
244
+ type AdminGateway = {
245
+ /** The admin UI's mount config for the current emulators; null when there are none. */
246
+ config(): Promise<Record<string, unknown> | null>;
247
+ /** Everything under `/admin/`: the admin UI script and each emulator's admin API. */
248
+ fetch(request: Request): Promise<Response>;
249
+ };
250
+ type AdminGatewayFactory = (context: AdminGatewayContext) => AdminGateway;
183
251
  type WaitOptions = {
184
252
  timeoutMs?: number;
185
253
  count?: number;
@@ -224,10 +292,12 @@ declare const parseMime: (raw: string) => ParsedMime;
224
292
  *
225
293
  * data-notification-id data-channel data-service data-source data-to data-from
226
294
  * data-status data-created-at data-unread ("true" | "false")
295
+ * data-via ("whatsapp", only on WhatsApp messages)
227
296
  *
228
297
  * The UI root (`TEST_IDS.app`) reports its state the same way: `data-ready` ("true" once the first
229
298
  * read finished), `data-view`, `data-namespace`, `data-count`, `data-version`, `data-connected`,
230
- * `data-sound` and `data-motion`.
299
+ * `data-sound`, `data-motion`, `data-layout` ("grid" = devices side by side, "tabs" = one device at
300
+ * a time) and `data-tab` (the selected channel tab: "all", "sms", "push", "email" or "chat").
231
301
  *
232
302
  * This module has no dependencies, so Playwright, Cypress or WebdriverIO specs can import it.
233
303
  */
@@ -255,18 +325,26 @@ declare const TEST_IDS: {
255
325
  /** Bottom-left message after an action, e.g. "Conversation archived." */
256
326
  readonly toast: "toast";
257
327
  readonly toastUndo: "toast-undo";
258
- /** The phone; `data-screen="threads" | "conversation"`, `data-recipient`, `data-thread`. */
328
+ /** The `role="tablist"` that switches between devices; `data-layout="grid" | "tabs"`. */
329
+ readonly channelTabs: "channel-tabs";
330
+ /** One `role="tab"`; `data-value="all" | "sms" | "push" | "email" | "chat"`, `aria-selected`, `data-unread` (a count). */
331
+ readonly channelTab: "channel-tab";
332
+ /** Unread badge on a tab whose device is not showing its newest arrivals (absent when 0). */
333
+ readonly channelTabUnread: "channel-tab-unread";
334
+ /** The phone; `data-screen="threads" | "conversation"`, `data-recipient`, `data-thread`, and `data-via="whatsapp"` while a WhatsApp chat is open. */
259
335
  readonly smsDevice: "sms-device";
260
336
  /** Phone number `<select>`; option values are E.164 numbers. */
261
337
  readonly smsRecipient: "sms-recipient";
262
338
  /** Unread SMS badge next to the column title (absent when 0). */
263
339
  readonly smsUnreadCount: "sms-unread-count";
264
- /** One conversation in the list; `data-from` (the sender address), `data-unread`, `data-pinned`, `data-muted`. */
340
+ /** One conversation in the list; `data-from` (the sender address), `data-unread`, `data-pinned`, `data-muted`, `data-via`. */
265
341
  readonly smsThread: "sms-thread";
266
342
  readonly smsThreadName: "sms-thread-name";
267
343
  readonly smsThreadPreview: "sms-thread-preview";
268
344
  readonly smsThreadTime: "sms-thread-time";
269
345
  readonly smsThreadUnread: "sms-thread-unread";
346
+ /** "WhatsApp" label on a WhatsApp conversation in the list. */
347
+ readonly smsThreadVia: "sms-thread-via";
270
348
  /** Swipe actions behind a thread (also reachable with the keyboard: focus the thread, press Delete). */
271
349
  readonly smsThreadDelete: "sms-thread-delete";
272
350
  readonly smsThreadMute: "sms-thread-mute";
@@ -274,7 +352,7 @@ declare const TEST_IDS: {
274
352
  readonly smsThreadToggleUnread: "sms-thread-toggle-unread";
275
353
  /** Shown when the phone has no messages. */
276
354
  readonly smsEmpty: "sms-empty";
277
- /** An open conversation; `data-from`. */
355
+ /** An open conversation; `data-from`, `data-via="sms" | "whatsapp"`. */
278
356
  readonly smsConversation: "sms-conversation";
279
357
  readonly smsConversationTitle: "sms-conversation-title";
280
358
  readonly smsBack: "sms-back";
@@ -369,6 +447,29 @@ declare const TEST_IDS: {
369
447
  readonly emailAttachments: "email-attachments";
370
448
  /** One attachment; `data-filename`, `data-content-type`, `data-size`. */
371
449
  readonly emailAttachment: "email-attachment";
450
+ /** The chat window; `data-recipient` (the open channel), `data-workspace`. */
451
+ readonly chatDevice: "chat-device";
452
+ /** Channel `<select>`; option values are channel names (`#alerts`) or webhook paths. */
453
+ readonly chatRecipient: "chat-recipient";
454
+ readonly chatUnreadCount: "chat-unread-count";
455
+ readonly chatWorkspace: "chat-workspace";
456
+ /** One channel in the sidebar; `data-to`, `data-unread` (a count), `aria-current`. */
457
+ readonly chatChannel: "chat-channel";
458
+ /** The open channel's name in the header. */
459
+ readonly chatTitle: "chat-title";
460
+ /** One message; notification attributes plus `data-method`, `data-ephemeral`, `data-thread`. */
461
+ readonly chatMessage: "chat-message";
462
+ readonly chatMessageAuthor: "chat-message-author";
463
+ readonly chatMessageTime: "chat-message-time";
464
+ /** The message text, with mrkdwn formatting applied. */
465
+ readonly chatMessageText: "chat-message-text";
466
+ /** Block Kit blocks; each block inside carries `data-block="<type>"`. */
467
+ readonly chatMessageBlocks: "chat-message-blocks";
468
+ /** Legacy attachments; each one inside carries `data-color`. */
469
+ readonly chatMessageAttachments: "chat-message-attachments";
470
+ /** One reaction; `data-name`, `data-count`. */
471
+ readonly chatMessageReaction: "chat-message-reaction";
472
+ readonly chatEmpty: "chat-empty";
372
473
  readonly timeline: "timeline";
373
474
  /** One row; notification attributes. Click it to inspect. */
374
475
  readonly timelineRow: "timeline-row";
@@ -382,6 +483,14 @@ declare const TEST_IDS: {
382
483
  readonly inspectorField: "inspector-field";
383
484
  /** The full record, normalized fields plus `raw`, as JSON text. */
384
485
  readonly inspectorJson: "inspector-json";
486
+ /** The dashboard root; `data-tab` is the open tab's id. */
487
+ readonly dashboard: "dashboard";
488
+ /** One tab button; `data-tab` (`emulators`, `notifications`, or an embedder's id), `aria-selected`. */
489
+ readonly dashboardTab: "dashboard-tab";
490
+ /** One tab's panel; `data-tab`. Hidden unless its tab is open. */
491
+ readonly dashboardPanel: "dashboard-panel";
492
+ /** Notifications that arrived while another tab was open; `data-count`. Hidden at 0. */
493
+ readonly dashboardBadge: "dashboard-badge";
385
494
  };
386
495
  type TestId = (typeof TEST_IDS)[keyof typeof TEST_IDS];
387
496
  /** CSS selectors for the harness UI. Each one works with `page.locator()` or `querySelector`. */
@@ -399,13 +508,23 @@ declare const selectors: {
399
508
  }) => string;
400
509
  /** A conversation in the Messages list. */
401
510
  smsThread: (from: string) => string;
511
+ /** A channel tab: `"all"`, `"sms"`, `"push"`, `"email"` or `"chat"`. */
512
+ channelTab: (value: "all" | "sms" | "push" | "email" | "chat") => string;
513
+ /** A chat message, optionally by id. */
514
+ chatMessage: (id?: string) => string;
515
+ /** A channel in the chat sidebar. */
516
+ chatChannel: (to: string) => string;
402
517
  /** A push notification card, optionally by id. */
403
518
  pushNotification: (id?: string) => string;
404
519
  /** An inbox row, optionally by id. */
405
520
  emailRow: (id?: string) => string;
406
521
  /** A timeline row, optionally by id. */
407
522
  timelineRow: (id?: string) => string;
523
+ /** A dashboard tab button by tab id (`emulators`, `notifications`, …). */
524
+ dashboardTab: (id: string) => string;
525
+ /** A dashboard tab's panel by tab id. */
526
+ dashboardPanel: (id: string) => string;
408
527
  };
409
528
 
410
- export { NotificationClient, SERVICE_KINDS, SERVICE_LABELS, TEST_IDS, createNotificationHarness, matches, parseMime, selectors };
411
- export type { Address, Channel, EmailAttachment, EmailContent, Endpoint, FetchLike, FleetManifest, HarnessOptions, Notification, NotificationClientOptions, NotificationFilter, NotificationHarness, PushContent, PushPlatform, ServiceInput, ServiceKind, SmsContent, SourceStatus, TestId, WaitOptions };
529
+ export { CHANNELS, NotificationClient, SERVICE_KINDS, SERVICE_LABELS, TEST_IDS, createNotificationHarness, matches, parseMime, selectors };
530
+ export type { Address, AdminGateway, AdminGatewayContext, AdminGatewayFactory, AdminTarget, Channel, ChatContent, ChatReaction, EmailAttachment, EmailContent, Endpoint, FetchLike, FleetManifest, HarnessOptions, Notification, NotificationClientOptions, NotificationFilter, NotificationHarness, PushContent, PushPlatform, ServiceInput, ServiceKind, SmsContent, SourceStatus, TestId, WaitOptions };
package/dist/index.js CHANGED
@@ -1,16 +1,18 @@
1
1
  import {
2
2
  TEST_IDS,
3
3
  selectors
4
- } from "./chunk-LM7R7AR7.js";
4
+ } from "./chunk-FBJ2DRHH.js";
5
5
  import {
6
+ createNotificationHarness,
7
+ parseMime
8
+ } from "./chunk-GHIEYY5B.js";
9
+ import {
10
+ CHANNELS,
6
11
  SERVICE_KINDS,
7
12
  SERVICE_LABELS,
8
- createNotificationHarness,
9
13
  filterToSearch,
10
- matches,
11
- parseMime
12
- } from "./chunk-GRGR3QZM.js";
13
- import "./chunk-QE3TRUI6.js";
14
+ matches
15
+ } from "./chunk-3HF2NSFV.js";
14
16
 
15
17
  // src/client.ts
16
18
  var NotificationClient = class {
@@ -83,6 +85,7 @@ var NotificationClient = class {
83
85
  }
84
86
  };
85
87
  export {
88
+ CHANNELS,
86
89
  NotificationClient,
87
90
  SERVICE_KINDS,
88
91
  SERVICE_LABELS,
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/client.ts"],
4
- "sourcesContent": ["import {\n filterToSearch,\n type Notification,\n type NotificationFilter,\n type SourceStatus,\n} from \"./model.js\"\n\nexport type NotificationClientOptions = {\n /** Default namespace for every call that does not name one. */\n namespace?: string\n fetch?: (request: Request) => Response | Promise<Response>\n}\n\n/** Talks to a running harness over HTTP, for tests that run in another process. */\nexport class NotificationClient {\n readonly baseUrl: string\n private readonly namespace: string | undefined\n private readonly fetchImpl: (request: Request) => Response | Promise<Response>\n\n constructor(baseUrl: string, options: NotificationClientOptions = {}) {\n this.baseUrl = baseUrl.replace(/\\/+$/, \"\")\n this.namespace = options.namespace\n this.fetchImpl = options.fetch ?? ((request) => fetch(request))\n }\n\n private async get<T>(\n path: string,\n filter: NotificationFilter = {},\n extra: Record<string, string> = {},\n ) {\n const params = filterToSearch({ namespace: this.namespace, ...filter })\n for (const [k, v] of Object.entries(extra)) params.set(k, v)\n const query = params.toString()\n const response = await this.fetchImpl(\n new Request(`${this.baseUrl}${path}${query ? `?${query}` : \"\"}`),\n )\n const body = (await response.json()) as T & { error?: { message?: string } }\n if (!response.ok) {\n const error = new Error(body.error?.message ?? `HTTP ${response.status}`)\n Object.assign(error, { status: response.status, body })\n throw error\n }\n return body\n }\n\n /** Every matching notification, oldest first. */\n async list(filter: NotificationFilter = {}): Promise<Notification[]> {\n return (await this.get<{ notifications: Notification[] }>(\"/api/notifications\", filter))\n .notifications\n }\n\n /** The newest match, or `null`. */\n async latest(filter: NotificationFilter = {}): Promise<Notification | null> {\n try {\n return await this.get<Notification>(\"/api/notifications/latest\", filter)\n } catch (error) {\n if ((error as { status?: number }).status === 404) return null\n throw error\n }\n }\n\n /** Wait until `count` (default 1) notifications match and return them; throws on timeout. */\n async waitFor(\n filter: NotificationFilter,\n options: { timeoutMs?: number; count?: number } = {},\n ): Promise<Notification[]> {\n const extra: Record<string, string> = {}\n if (options.timeoutMs !== undefined) extra.timeoutMs = String(options.timeoutMs)\n if (options.count !== undefined) extra.count = String(options.count)\n return (await this.get<{ notifications: Notification[] }>(\"/api/wait\", filter, extra))\n .notifications\n }\n\n /** Wait for the next SMS to `to` and return its one-time code (Twilio Verify) or first 4\u20138 digit run. */\n async waitForCode(\n to: string,\n filter: NotificationFilter = {},\n timeoutMs?: number,\n ): Promise<string> {\n const found = await this.waitFor(\n { channel: \"sms\", to, ...filter },\n timeoutMs === undefined ? {} : { timeoutMs },\n )\n const last = found.at(-1)\n const code = last?.sms?.code ?? /\\b(\\d{4,8})\\b/.exec(last?.sms?.body ?? \"\")?.[1]\n if (!code) throw new Error(`no code in the latest SMS to ${to}`)\n return code\n }\n\n async sources(): Promise<SourceStatus[]> {\n return (await this.get<{ sources: SourceStatus[] }>(\"/api/sources\")).sources\n }\n\n /** A UI link that opens one device (or one notification) for a screenshot. */\n link(view: { channel?: \"sms\" | \"email\" | \"push\"; to?: string; id?: string } = {}): string {\n const params = new URLSearchParams()\n if (this.namespace) params.set(\"namespace\", this.namespace)\n if (view.channel) params.set(\"view\", view.channel)\n if (view.to) params.set(\"to\", view.to)\n if (view.id) params.set(\"id\", view.id)\n const query = params.toString()\n return `${this.baseUrl}/${query ? `?${query}` : \"\"}`\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;AAcO,IAAM,qBAAN,MAAyB;AAAA,EACrB;AAAA,EACQ;AAAA,EACA;AAAA,EAEjB,YAAY,SAAiB,UAAqC,CAAC,GAAG;AACpE,SAAK,UAAU,QAAQ,QAAQ,QAAQ,EAAE;AACzC,SAAK,YAAY,QAAQ;AACzB,SAAK,YAAY,QAAQ,UAAU,CAAC,YAAY,MAAM,OAAO;AAAA,EAC/D;AAAA,EAEA,MAAc,IACZ,MACA,SAA6B,CAAC,GAC9B,QAAgC,CAAC,GACjC;AACA,UAAM,SAAS,eAAe,EAAE,WAAW,KAAK,WAAW,GAAG,OAAO,CAAC;AACtE,eAAW,CAAC,GAAG,CAAC,KAAK,OAAO,QAAQ,KAAK,EAAG,QAAO,IAAI,GAAG,CAAC;AAC3D,UAAM,QAAQ,OAAO,SAAS;AAC9B,UAAM,WAAW,MAAM,KAAK;AAAA,MAC1B,IAAI,QAAQ,GAAG,KAAK,OAAO,GAAG,IAAI,GAAG,QAAQ,IAAI,KAAK,KAAK,EAAE,EAAE;AAAA,IACjE;AACA,UAAM,OAAQ,MAAM,SAAS,KAAK;AAClC,QAAI,CAAC,SAAS,IAAI;AAChB,YAAM,QAAQ,IAAI,MAAM,KAAK,OAA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AAA;AAAA,EAGA,KAAK,OAAyE,CAAC,GAAW;AACxF,UAAM,SAAS,IAAI,gBAAgB;AACnC,QAAI,KAAK,UAAW,QAAO,IAAI,aAAa,KAAK,SAAS;AAC1D,QAAI,KAAK,QAAS,QAAO,IAAI,QAAQ,KAAK,OAAO;AACjD,QAAI,KAAK,GAAI,QAAO,IAAI,MAAM,KAAK,EAAE;AACrC,QAAI,KAAK,GAAI,QAAO,IAAI,MAAM,KAAK,EAAE;AACrC,UAAM,QAAQ,OAAO,SAAS;AAC9B,WAAO,GAAG,KAAK,OAAO,IAAI,QAAQ,IAAI,KAAK,KAAK,EAAE;AAAA,EACpD;AACF;",
4
+ "sourcesContent": ["import {\n type Channel,\n filterToSearch,\n type Notification,\n type NotificationFilter,\n type SourceStatus,\n} from \"./model.js\"\n\nexport type NotificationClientOptions = {\n /** Default namespace for every call that does not name one. */\n namespace?: string\n fetch?: (request: Request) => Response | Promise<Response>\n}\n\n/** Talks to a running harness over HTTP, for tests that run in another process. */\nexport class NotificationClient {\n readonly baseUrl: string\n private readonly namespace: string | undefined\n private readonly fetchImpl: (request: Request) => Response | Promise<Response>\n\n constructor(baseUrl: string, options: NotificationClientOptions = {}) {\n this.baseUrl = baseUrl.replace(/\\/+$/, \"\")\n this.namespace = options.namespace\n this.fetchImpl = options.fetch ?? ((request) => fetch(request))\n }\n\n private async get<T>(\n path: string,\n filter: NotificationFilter = {},\n extra: Record<string, string> = {},\n ) {\n const params = filterToSearch({ namespace: this.namespace, ...filter })\n for (const [k, v] of Object.entries(extra)) params.set(k, v)\n const query = params.toString()\n const response = await this.fetchImpl(\n new Request(`${this.baseUrl}${path}${query ? `?${query}` : \"\"}`),\n )\n const body = (await response.json()) as T & { error?: { message?: string } }\n if (!response.ok) {\n const error = new Error(body.error?.message ?? `HTTP ${response.status}`)\n Object.assign(error, { status: response.status, body })\n throw error\n }\n return body\n }\n\n /** Every matching notification, oldest first. */\n async list(filter: NotificationFilter = {}): Promise<Notification[]> {\n return (await this.get<{ notifications: Notification[] }>(\"/api/notifications\", filter))\n .notifications\n }\n\n /** The newest match, or `null`. */\n async latest(filter: NotificationFilter = {}): Promise<Notification | null> {\n try {\n return await this.get<Notification>(\"/api/notifications/latest\", filter)\n } catch (error) {\n if ((error as { status?: number }).status === 404) return null\n throw error\n }\n }\n\n /** Wait until `count` (default 1) notifications match and return them; throws on timeout. */\n async waitFor(\n filter: NotificationFilter,\n options: { timeoutMs?: number; count?: number } = {},\n ): Promise<Notification[]> {\n const extra: Record<string, string> = {}\n if (options.timeoutMs !== undefined) extra.timeoutMs = String(options.timeoutMs)\n if (options.count !== undefined) extra.count = String(options.count)\n return (await this.get<{ notifications: Notification[] }>(\"/api/wait\", filter, extra))\n .notifications\n }\n\n /** Wait for the next SMS to `to` and return its one-time code (Twilio Verify) or first 4\u20138 digit run. */\n async waitForCode(\n to: string,\n filter: NotificationFilter = {},\n timeoutMs?: number,\n ): Promise<string> {\n const found = await this.waitFor(\n { channel: \"sms\", to, ...filter },\n timeoutMs === undefined ? {} : { timeoutMs },\n )\n const last = found.at(-1)\n const code = last?.sms?.code ?? /\\b(\\d{4,8})\\b/.exec(last?.sms?.body ?? \"\")?.[1]\n if (!code) throw new Error(`no code in the latest SMS to ${to}`)\n return code\n }\n\n async sources(): Promise<SourceStatus[]> {\n return (await this.get<{ sources: SourceStatus[] }>(\"/api/sources\")).sources\n }\n\n /** A UI link that opens one device (or one notification) for a screenshot. */\n link(view: { channel?: Channel; to?: string; id?: string } = {}): string {\n const params = new URLSearchParams()\n if (this.namespace) params.set(\"namespace\", this.namespace)\n if (view.channel) params.set(\"view\", view.channel)\n if (view.to) params.set(\"to\", view.to)\n if (view.id) params.set(\"id\", view.id)\n const query = params.toString()\n return `${this.baseUrl}/${query ? `?${query}` : \"\"}`\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAeO,IAAM,qBAAN,MAAyB;AAAA,EACrB;AAAA,EACQ;AAAA,EACA;AAAA,EAEjB,YAAY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,OAAW,OAAM,YAAY,OAAO,QAAQ,SAAS;AAC/E,QAAI,QAAQ,UAAU,OAAW,OAAM,QAAQ,OAAO,QAAQ,KAAK;AACnE,YAAQ,MAAM,KAAK,IAAuC,aAAa,QAAQ,KAAK,GACjF;AAAA,EACL;AAAA;AAAA,EAGA,MAAM,YACJ,IACA,SAA6B,CAAC,GAC9B,WACiB;AACjB,UAAM,QAAQ,MAAM,KAAK;AAAA,MACvB,EAAE,SAAS,OAAO,IAAI,GAAG,OAAO;AAAA,MAChC,cAAc,SAAY,CAAC,IAAI,EAAE,UAAU;AAAA,IAC7C;AACA,UAAM,OAAO,MAAM,GAAG,EAAE;AACxB,UAAM,OAAO,MAAM,KAAK,QAAQ,gBAAgB,KAAK,MAAM,KAAK,QAAQ,EAAE,IAAI,CAAC;AAC/E,QAAI,CAAC,KAAM,OAAM,IAAI,MAAM,gCAAgC,EAAE,EAAE;AAC/D,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,UAAmC;AACvC,YAAQ,MAAM,KAAK,IAAiC,cAAc,GAAG;AAAA,EACvE;AAAA;AAAA,EAGA,KAAK,OAAwD,CAAC,GAAW;AACvE,UAAM,SAAS,IAAI,gBAAgB;AACnC,QAAI,KAAK,UAAW,QAAO,IAAI,aAAa,KAAK,SAAS;AAC1D,QAAI,KAAK,QAAS,QAAO,IAAI,QAAQ,KAAK,OAAO;AACjD,QAAI,KAAK,GAAI,QAAO,IAAI,MAAM,KAAK,EAAE;AACrC,QAAI,KAAK,GAAI,QAAO,IAAI,MAAM,KAAK,EAAE;AACrC,UAAM,QAAQ,OAAO,SAAS;AAC9B,WAAO,GAAG,KAAK,OAAO,IAAI,QAAQ,IAAI,KAAK,KAAK,EAAE;AAAA,EACpD;AACF;",
6
6
  "names": []
7
7
  }
package/dist/server.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- /** The three kinds of device a notification lands on. */
2
- type Channel = "sms" | "email" | "push";
1
+ /** The kinds of device a notification lands on. */
2
+ type Channel = "sms" | "email" | "push" | "chat";
3
3
  /** Emulators the harness knows how to read. */
4
- type ServiceKind = "twilio" | "resend" | "fcm" | "ses" | "sns" | "customerio" | "mailosaur";
4
+ type ServiceKind = "twilio" | "resend" | "fcm" | "ses" | "sns" | "customerio" | "mailosaur" | "slack";
5
5
  type Address = {
6
6
  name: string | null;
7
7
  address: string;
@@ -11,6 +11,8 @@ type SmsContent = {
11
11
  /** One-time code the sender included (Twilio Verify), when known. */
12
12
  code: string | null;
13
13
  media: string[];
14
+ /** `whatsapp` when the message went to a `whatsapp:` address; plain text messages omit it. */
15
+ via?: "sms" | "whatsapp";
14
16
  };
15
17
  type EmailAttachment = {
16
18
  filename: string;
@@ -39,6 +41,31 @@ type PushContent = {
39
41
  badge: number | null;
40
42
  sound: string | null;
41
43
  };
44
+ type ChatReaction = {
45
+ name: string;
46
+ count: number;
47
+ };
48
+ /** A message posted into a team chat channel (Slack). */
49
+ type ChatContent = {
50
+ /** The message text, in the provider's own markup (Slack mrkdwn). */
51
+ text: string;
52
+ /** Workspace the message was posted in. */
53
+ workspace: string | null;
54
+ /** How it arrived: `chat.postMessage`, `chat.postEphemeral` or `incoming-webhook`. */
55
+ method: string;
56
+ /** Block Kit blocks, exactly as sent. */
57
+ blocks: unknown[];
58
+ /** Legacy attachments, exactly as sent. */
59
+ attachments: unknown[];
60
+ /** Parent message timestamp when this is a threaded reply. */
61
+ threadTs: string | null;
62
+ /** Shown to one member only. */
63
+ ephemeral: boolean;
64
+ edited: boolean;
65
+ reactions: ChatReaction[];
66
+ /** Display names of the users and channels the message mentions by id (`U…` → `ada`). */
67
+ names?: Record<string, string>;
68
+ };
42
69
  /** One message as a recipient would receive it, normalized across emulators. */
43
70
  type Notification = {
44
71
  /** Stable across polls: `<service entry>:<namespace>:<provider id>`. */
@@ -50,7 +77,7 @@ type Notification = {
50
77
  source: string;
51
78
  service: ServiceKind;
52
79
  namespace: string;
53
- /** Phone number, email address, or push registration token. */
80
+ /** Phone number, email address, push registration token, or chat channel (`#alerts`). */
54
81
  to: string;
55
82
  from: Address;
56
83
  /** ISO-8601, on the emulator's clock. */
@@ -62,6 +89,8 @@ type Notification = {
62
89
  sms: SmsContent | null;
63
90
  email: EmailContent | null;
64
91
  push: PushContent | null;
92
+ /** Set on `chat` notifications; absent or null on every other channel. */
93
+ chat?: ChatContent | null;
65
94
  /** The record exactly as the emulator reported it. */
66
95
  raw: unknown;
67
96
  };
@@ -113,6 +142,19 @@ type FleetManifest = {
113
142
  target?: string;
114
143
  } | undefined>;
115
144
  };
145
+ /**
146
+ * An emulator whose admin API the dashboard fronts. Unlike {@link Endpoint} this is every HTTP
147
+ * emulator, messaging or not (stripe, cognito, …).
148
+ */
149
+ type AdminTarget = {
150
+ /** The fleet entry name, e.g. `stripe`, or an alias such as `push`. */
151
+ name: string;
152
+ /** The emulator it runs, e.g. `fcm` for the alias `push`. The name when nobody said. */
153
+ target: string;
154
+ /** Absolute admin prefix, e.g. `http://127.0.0.1:8798/__admin`. */
155
+ adminUrl: string;
156
+ fetch: FetchLike;
157
+ };
116
158
 
117
159
  type HarnessOptions = {
118
160
  /** A running fleet controller's `adminBase` (`http://127.0.0.1:9000/__admin/fleet`). */
@@ -131,11 +173,35 @@ type HarnessOptions = {
131
173
  pollIntervalMs?: number;
132
174
  /** Sent as `x-mockingbird-admin-key` to the fleet and every emulator. */
133
175
  adminKey?: string;
176
+ /** Admin keys by emulator name, for emulators whose key is not `adminKey`. */
177
+ adminKeys?: Record<string, string>;
178
+ /**
179
+ * Front every emulator's admin API on this origin, so the page shows an Emulators tab next to
180
+ * Notifications. `createServer` (the `./server` entry) turns it on; pass `adminGateway()` from
181
+ * that entry to turn it on for a harness you serve yourself.
182
+ */
183
+ admin?: AdminGatewayFactory | false;
184
+ /** The tab the page opens on when it has both. Default `notifications`. */
185
+ defaultTab?: "emulators" | "notifications";
134
186
  /** Transport for URL endpoints. Default: global `fetch`. */
135
187
  fetch?: FetchLike;
136
188
  /** Page title. */
137
189
  title?: string;
138
190
  };
191
+ type AdminGatewayContext = {
192
+ /** Every HTTP emulator the harness knows, messaging or not, after a fresh discovery. */
193
+ targets(): Promise<AdminTarget[]>;
194
+ /** The admin key header for one emulator: empty when the harness has no key for it. */
195
+ headers(name: string): Record<string, string>;
196
+ title: string;
197
+ };
198
+ type AdminGateway = {
199
+ /** The admin UI's mount config for the current emulators; null when there are none. */
200
+ config(): Promise<Record<string, unknown> | null>;
201
+ /** Everything under `/admin/`: the admin UI script and each emulator's admin API. */
202
+ fetch(request: Request): Promise<Response>;
203
+ };
204
+ type AdminGatewayFactory = (context: AdminGatewayContext) => AdminGateway;
139
205
  type WaitOptions = {
140
206
  timeoutMs?: number;
141
207
  count?: number;
@@ -153,8 +219,27 @@ type NotificationHarness = {
153
219
  close(): void;
154
220
  };
155
221
 
222
+ /** Where the admin UI reads each vendor's logo and links from, as every emulator's own admin does. */
223
+ declare const ADMIN_BRANDS_URL = "https://mockingbird.chrisvouga.dev/brands.json";
224
+ type AdminGatewayOptions = {
225
+ /** Default {@link ADMIN_BRANDS_URL}. */
226
+ brandsUrl?: string;
227
+ };
228
+ /**
229
+ * Pass the result as the harness's `admin` option. `createServer` does so by default.
230
+ *
231
+ * A request that carries no admin key gets the harness's own (`adminKey` / `adminKeys`), so the
232
+ * page works against a locked fleet without the viewer typing the key. Anyone who can reach the
233
+ * harness can then change emulator state: keep it on a loopback or otherwise private address.
234
+ */
235
+ declare const adminGateway: (options?: AdminGatewayOptions) => AdminGatewayFactory;
236
+
156
237
  /** Port `mockingbird-notifications serve` listens on when none is given. */
157
238
  declare const DEFAULT_PORT = 8790;
239
+ /**
240
+ * `admin` defaults to `adminGateway()` here: the page gets an Emulators tab with every emulator's
241
+ * admin dashboard. Pass `admin: false` for the notifications UI alone.
242
+ */
158
243
  type NotificationServerOptions = Omit<HarnessOptions, "manifest"> & {
159
244
  /** A fleet ready manifest object, or the path of the fleet's `--ready-file` (re-read every sync). */
160
245
  manifest?: HarnessOptions["manifest"] | string;
@@ -173,5 +258,5 @@ type NotificationServer = {
173
258
  declare const manifestFile: (path: string) => () => Promise<FleetManifest>;
174
259
  declare const createServer: (options?: NotificationServerOptions) => Promise<NotificationServer>;
175
260
 
176
- export { DEFAULT_PORT, createServer, manifestFile };
177
- export type { NotificationServer, NotificationServerOptions };
261
+ export { ADMIN_BRANDS_URL, DEFAULT_PORT, adminGateway, createServer, manifestFile };
262
+ export type { AdminGatewayOptions, NotificationServer, NotificationServerOptions };
package/dist/server.js CHANGED
@@ -1,12 +1,16 @@
1
1
  import {
2
+ ADMIN_BRANDS_URL,
2
3
  DEFAULT_PORT,
4
+ adminGateway,
3
5
  createServer,
4
6
  manifestFile
5
- } from "./chunk-JQ6KPT2C.js";
6
- import "./chunk-GRGR3QZM.js";
7
- import "./chunk-QE3TRUI6.js";
7
+ } from "./chunk-4QVURMVP.js";
8
+ import "./chunk-GHIEYY5B.js";
9
+ import "./chunk-3HF2NSFV.js";
8
10
  export {
11
+ ADMIN_BRANDS_URL,
9
12
  DEFAULT_PORT,
13
+ adminGateway,
10
14
  createServer,
11
15
  manifestFile
12
16
  };