@crvouga/mockingbird-notifications 0.1.0 → 0.2.1
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/README.md +96 -17
- package/dist/{chunk-QE3TRUI6.js → chunk-3HF2NSFV.js} +280 -10
- package/dist/chunk-3HF2NSFV.js.map +7 -0
- package/dist/{chunk-LM7R7AR7.js → chunk-FBJ2DRHH.js} +58 -6
- package/dist/chunk-FBJ2DRHH.js.map +7 -0
- package/dist/chunk-GHIEYY5B.js +1177 -0
- package/dist/chunk-GHIEYY5B.js.map +7 -0
- package/dist/chunk-SNOESDNW.js +400 -0
- package/dist/chunk-SNOESDNW.js.map +7 -0
- package/dist/cli.js +12 -4
- package/dist/cli.js.map +2 -2
- package/dist/index.d.ts +6 -361
- package/dist/index.js +9 -6
- package/dist/index.js.map +2 -2
- package/dist/server.d.ts +19 -153
- package/dist/server.js +7 -3
- package/dist/types-C4yF6DQp.d.ts +244 -0
- package/dist/types-CU0LKNyA.d.ts +238 -0
- package/dist/ui.d.ts +96 -316
- package/dist/ui.js +808 -133
- package/dist/ui.js.map +4 -4
- package/package.json +14 -10
- package/dist/chunk-GRGR3QZM.js +0 -1066
- package/dist/chunk-GRGR3QZM.js.map +0 -7
- package/dist/chunk-JQ6KPT2C.js +0 -202
- package/dist/chunk-JQ6KPT2C.js.map +0 -7
- package/dist/chunk-LM7R7AR7.js.map +0 -7
- package/dist/chunk-QE3TRUI6.js.map +0 -7
|
@@ -0,0 +1,238 @@
|
|
|
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[];
|
|
5
|
+
/** Emulators the harness knows how to read. */
|
|
6
|
+
type ServiceKind = "twilio" | "resend" | "fcm" | "ses" | "sns" | "customerio" | "mailosaur" | "slack";
|
|
7
|
+
declare const SERVICE_KINDS: readonly ServiceKind[];
|
|
8
|
+
declare const SERVICE_LABELS: Record<ServiceKind, string>;
|
|
9
|
+
type Address = {
|
|
10
|
+
name: string | null;
|
|
11
|
+
address: string;
|
|
12
|
+
};
|
|
13
|
+
type SmsContent = {
|
|
14
|
+
body: string;
|
|
15
|
+
/** One-time code the sender included (Twilio Verify), when known. */
|
|
16
|
+
code: string | null;
|
|
17
|
+
media: string[];
|
|
18
|
+
/** `whatsapp` when the message went to a `whatsapp:` address; plain text messages omit it. */
|
|
19
|
+
via?: "sms" | "whatsapp";
|
|
20
|
+
};
|
|
21
|
+
type EmailAttachment = {
|
|
22
|
+
filename: string;
|
|
23
|
+
contentType: string | null;
|
|
24
|
+
size: number | null;
|
|
25
|
+
};
|
|
26
|
+
type EmailContent = {
|
|
27
|
+
subject: string;
|
|
28
|
+
html: string | null;
|
|
29
|
+
text: string | null;
|
|
30
|
+
cc: string[];
|
|
31
|
+
bcc: string[];
|
|
32
|
+
replyTo: string[];
|
|
33
|
+
attachments: EmailAttachment[];
|
|
34
|
+
headers: Record<string, string>;
|
|
35
|
+
};
|
|
36
|
+
type PushPlatform = "android" | "ios" | "web" | "unknown";
|
|
37
|
+
type PushContent = {
|
|
38
|
+
title: string | null;
|
|
39
|
+
body: string | null;
|
|
40
|
+
imageUrl: string | null;
|
|
41
|
+
/** The app the notification belongs to (the FCM project, for example). */
|
|
42
|
+
app: string;
|
|
43
|
+
platform: PushPlatform;
|
|
44
|
+
data: Record<string, string>;
|
|
45
|
+
badge: number | null;
|
|
46
|
+
sound: string | null;
|
|
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
|
+
};
|
|
73
|
+
/** One message as a recipient would receive it, normalized across emulators. */
|
|
74
|
+
type Notification = {
|
|
75
|
+
/** Stable across polls: `<service entry>:<namespace>:<provider id>`. */
|
|
76
|
+
id: string;
|
|
77
|
+
/** The provider's own id (Twilio SID, Resend id, FCM message name, …). */
|
|
78
|
+
providerId: string;
|
|
79
|
+
channel: Channel;
|
|
80
|
+
/** The fleet entry name (`twilio`, or an alias such as `push`). */
|
|
81
|
+
source: string;
|
|
82
|
+
service: ServiceKind;
|
|
83
|
+
namespace: string;
|
|
84
|
+
/** Phone number, email address, push registration token, or chat channel (`#alerts`). */
|
|
85
|
+
to: string;
|
|
86
|
+
from: Address;
|
|
87
|
+
/** ISO-8601, on the emulator's clock. */
|
|
88
|
+
createdAt: string;
|
|
89
|
+
/** Short plain-text preview. */
|
|
90
|
+
preview: string;
|
|
91
|
+
/** Provider delivery state when it reports one (`queued`, `delivered`, `suppressed`, …). */
|
|
92
|
+
status: string | null;
|
|
93
|
+
sms: SmsContent | null;
|
|
94
|
+
email: EmailContent | null;
|
|
95
|
+
push: PushContent | null;
|
|
96
|
+
/** Set on `chat` notifications; absent or null on every other channel. */
|
|
97
|
+
chat?: ChatContent | null;
|
|
98
|
+
/** The record exactly as the emulator reported it. */
|
|
99
|
+
raw: unknown;
|
|
100
|
+
};
|
|
101
|
+
type NotificationFilter = {
|
|
102
|
+
channel?: Channel | undefined;
|
|
103
|
+
service?: ServiceKind | undefined;
|
|
104
|
+
source?: string | undefined;
|
|
105
|
+
namespace?: string | undefined;
|
|
106
|
+
/** Exact recipient (case-insensitive for email). */
|
|
107
|
+
to?: string | undefined;
|
|
108
|
+
/** Case-insensitive text search across sender, subject, title and body. */
|
|
109
|
+
contains?: string | undefined;
|
|
110
|
+
/** Only notifications created at or after this instant (ISO-8601 or epoch ms). */
|
|
111
|
+
since?: string | number | undefined;
|
|
112
|
+
};
|
|
113
|
+
type SourceStatus = {
|
|
114
|
+
name: string;
|
|
115
|
+
service: ServiceKind | null;
|
|
116
|
+
url: string;
|
|
117
|
+
ok: boolean;
|
|
118
|
+
error: string | null;
|
|
119
|
+
count: number;
|
|
120
|
+
lastSyncAt: string | null;
|
|
121
|
+
};
|
|
122
|
+
declare const matches: (n: Notification, filter: NotificationFilter) => boolean;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Where the emulators are. The harness reads the same fleet the application uses: the live fleet
|
|
126
|
+
* controller (`adminBase`), the fleet's ready manifest, or explicit URLs and in-process runtimes.
|
|
127
|
+
*/
|
|
128
|
+
|
|
129
|
+
type FetchLike = (request: Request) => Response | Promise<Response>;
|
|
130
|
+
/** A service emulator: its base URL, an `{ url, adminUrl?, service? }` entry, or an in-process runtime. */
|
|
131
|
+
type ServiceInput = string | {
|
|
132
|
+
url: string;
|
|
133
|
+
adminUrl?: string;
|
|
134
|
+
service?: ServiceKind;
|
|
135
|
+
} | {
|
|
136
|
+
fetch: FetchLike;
|
|
137
|
+
service?: ServiceKind;
|
|
138
|
+
adminPrefix?: string;
|
|
139
|
+
};
|
|
140
|
+
/** The subset of a fleet ready manifest (`--ready-file`) the harness reads. */
|
|
141
|
+
type FleetManifest = {
|
|
142
|
+
adminBase?: string;
|
|
143
|
+
services: Record<string, {
|
|
144
|
+
protocol?: string;
|
|
145
|
+
url?: string;
|
|
146
|
+
adminUrl?: string;
|
|
147
|
+
target?: string;
|
|
148
|
+
} | undefined>;
|
|
149
|
+
};
|
|
150
|
+
type Endpoint = {
|
|
151
|
+
/** The fleet entry name, e.g. `twilio`, or an alias such as `push`. */
|
|
152
|
+
name: string;
|
|
153
|
+
/** Null until the emulator's health route has told us what it is. */
|
|
154
|
+
service: ServiceKind | null;
|
|
155
|
+
/** Absolute admin prefix, e.g. `http://127.0.0.1:8798/__admin`. */
|
|
156
|
+
adminUrl: string;
|
|
157
|
+
fetch: FetchLike;
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* An emulator whose admin API the dashboard fronts. Unlike {@link Endpoint} this is every HTTP
|
|
161
|
+
* emulator, messaging or not (stripe, cognito, …).
|
|
162
|
+
*/
|
|
163
|
+
type AdminTarget = {
|
|
164
|
+
/** The fleet entry name, e.g. `stripe`, or an alias such as `push`. */
|
|
165
|
+
name: string;
|
|
166
|
+
/** The emulator it runs, e.g. `fcm` for the alias `push`. The name when nobody said. */
|
|
167
|
+
target: string;
|
|
168
|
+
/** Absolute admin prefix, e.g. `http://127.0.0.1:8798/__admin`. */
|
|
169
|
+
adminUrl: string;
|
|
170
|
+
fetch: FetchLike;
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
type HarnessOptions = {
|
|
174
|
+
/** A running fleet controller's `adminBase` (`http://127.0.0.1:9000/__admin/fleet`). */
|
|
175
|
+
fleet?: string;
|
|
176
|
+
/** A fleet ready manifest, or a function that reads the current one (re-read on every sync). */
|
|
177
|
+
manifest?: FleetManifest | (() => FleetManifest | Promise<FleetManifest>);
|
|
178
|
+
/** Explicit emulators by name: base URLs, `{ url, adminUrl }`, or in-process runtimes. */
|
|
179
|
+
services?: Record<string, ServiceInput>;
|
|
180
|
+
/**
|
|
181
|
+
* Namespaces to watch in the background. `"all"` follows the fleet's namespace list.
|
|
182
|
+
* Any namespace an API call or the UI asks for is watched from then on. Default `["default"]`,
|
|
183
|
+
* or `"all"` with `fleet`.
|
|
184
|
+
*/
|
|
185
|
+
namespaces?: "all" | string[];
|
|
186
|
+
/** Background polling interval. `0` turns it off; reads still sync on demand. Default 750 ms. */
|
|
187
|
+
pollIntervalMs?: number;
|
|
188
|
+
/** Sent as `x-mockingbird-admin-key` to the fleet and every emulator. */
|
|
189
|
+
adminKey?: string;
|
|
190
|
+
/** Admin keys by emulator name, for emulators whose key is not `adminKey`. */
|
|
191
|
+
adminKeys?: Record<string, string>;
|
|
192
|
+
/**
|
|
193
|
+
* Front every emulator's admin API on this origin, so the page shows an Emulators tab next to
|
|
194
|
+
* Notifications. `createServer` (the `./server` entry) turns it on; pass `adminGateway()` from
|
|
195
|
+
* that entry to turn it on for a harness you serve yourself.
|
|
196
|
+
*/
|
|
197
|
+
admin?: AdminGatewayFactory | false;
|
|
198
|
+
/** The tab the page opens on when it has both. Default `notifications`. */
|
|
199
|
+
defaultTab?: "emulators" | "notifications";
|
|
200
|
+
/** Transport for URL endpoints. Default: global `fetch`. */
|
|
201
|
+
fetch?: FetchLike;
|
|
202
|
+
/** Page title. */
|
|
203
|
+
title?: string;
|
|
204
|
+
};
|
|
205
|
+
type AdminGatewayContext = {
|
|
206
|
+
/** Every HTTP emulator the harness knows, messaging or not, after a fresh discovery. */
|
|
207
|
+
targets(): Promise<AdminTarget[]>;
|
|
208
|
+
/** The admin key header for one emulator: empty when the harness has no key for it. */
|
|
209
|
+
headers(name: string): Record<string, string>;
|
|
210
|
+
title: string;
|
|
211
|
+
};
|
|
212
|
+
type AdminGateway = {
|
|
213
|
+
/** The admin UI's mount config for the current emulators; null when there are none. */
|
|
214
|
+
config(): Promise<Record<string, unknown> | null>;
|
|
215
|
+
/** Everything under `/admin/`: the admin UI script and each emulator's admin API. */
|
|
216
|
+
fetch(request: Request): Promise<Response>;
|
|
217
|
+
};
|
|
218
|
+
type AdminGatewayFactory = (context: AdminGatewayContext) => AdminGateway;
|
|
219
|
+
type WaitOptions = {
|
|
220
|
+
timeoutMs?: number;
|
|
221
|
+
count?: number;
|
|
222
|
+
};
|
|
223
|
+
type NotificationHarness = {
|
|
224
|
+
/** The harness UI and JSON API as a Fetch handler. */
|
|
225
|
+
fetch(request: Request): Promise<Response>;
|
|
226
|
+
/** Read every emulator now. Resolves after a read that started after this call. */
|
|
227
|
+
sync(namespace?: string): Promise<void>;
|
|
228
|
+
/** Notifications matching `filter`, oldest first, after a fresh sync. */
|
|
229
|
+
list(filter?: NotificationFilter): Promise<Notification[]>;
|
|
230
|
+
/** Resolve once at least `count` (default 1) notifications match; reject after `timeoutMs`. */
|
|
231
|
+
waitFor(filter: NotificationFilter, options?: WaitOptions): Promise<Notification[]>;
|
|
232
|
+
sources(): SourceStatus[];
|
|
233
|
+
close(): void;
|
|
234
|
+
};
|
|
235
|
+
declare const createNotificationHarness: (options?: HarnessOptions) => NotificationHarness;
|
|
236
|
+
|
|
237
|
+
export { CHANNELS as f, SERVICE_KINDS as n, SERVICE_LABELS as o, createNotificationHarness as s, matches as t };
|
|
238
|
+
export type { Address as A, Channel as C, EmailAttachment as E, FetchLike as F, HarnessOptions as H, NotificationFilter as N, PushContent as P, SourceStatus as S, WaitOptions as W, Notification as a, AdminGateway as b, AdminGatewayContext as c, AdminGatewayFactory as d, AdminTarget as e, ChatContent as g, ChatReaction as h, EmailContent as i, Endpoint as j, FleetManifest as k, NotificationHarness as l, PushPlatform as m, ServiceInput as p, ServiceKind as q, SmsContent as r };
|