@cardonjs/notify 0.0.0-stage → 0.1.10

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Matias Terradas
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,227 @@
1
- # Temporary Holding Version
1
+ # @cardonjs/notify
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The notifications interface of Cardón: the `NotificationChannel` type every notification
4
+ adapter returns (one message to one target), the message checks every channel runs before any
5
+ I/O, typed templates, a development channel that only logs, the shared contract suite adapters
6
+ must pass (`@cardonjs/notify/contract`) and a test-only in-memory channel
7
+ (`@cardonjs/notify/testing`). Adapters such as `@cardonjs/notify-webpush` build the channel;
8
+ business logic receives it through the context and never touches a provider SDK. Standard web
9
+ APIs only (Workers, Node, Bun, Deno); it does not depend on `hono`.
10
+
11
+ Peer dependencies: `@cardonjs/core` (`Logger`). `@cardonjs/testing` is an optional peer, only
12
+ needed by `@cardonjs/notify/contract` (in adapter tests).
13
+
14
+ For coding agents: `llms.txt`, shipped next to this README in the package, is a compact usage guide (public API, a minimal example, common mistakes).
15
+
16
+ ## The model
17
+
18
+ - **A channel sends one message to one target.** A target is whatever the provider addresses:
19
+ a push subscription, an email address. Who the targets of a user are (their stored push
20
+ subscriptions, their verified email) is your data, not the channel's.
21
+ - **`send` resolves a `SendResult`**: `sent`; `gone` (the target no longer exists: delete it);
22
+ or `failed` with `retryable` (try again later, or give up). It never rejects for anything the
23
+ provider answers or for a network failure. It throws a `TypeError` only for an invalid message
24
+ or target, which is a bug in the server; the error message never echoes the value.
25
+ - **No retries, no outbox, no preferences.** A channel sends once. Retrying `failed` results
26
+ comes with background jobs.
27
+
28
+ ## Messages
29
+
30
+ ```ts
31
+ interface NotificationMessage {
32
+ title: string; // 1..120 characters, not blank
33
+ body: string; // 0..500 characters
34
+ url?: string; // opened on click: an https URL, http on localhost, or a path starting with "/"
35
+ tag?: string; // 1..64 of [A-Za-z0-9_-:.]; replaces a shown notification with the same tag
36
+ data?: Record<string, string | number | boolean | null>; // flat, at most 20 keys
37
+ }
38
+ ```
39
+
40
+ `validMessage(message)` returns a frozen, normalised copy of the message, or throws a
41
+ `TypeError` unless it follows these rules and its JSON (`{ title, body, url, tag, data }`) is at
42
+ most 3000 UTF-8 bytes. Characters are counted as Unicode code points, and strings must be
43
+ well-formed (no lone surrogates), so what arrives is exactly what was sent. Only the five fields
44
+ are allowed (a blank title is not). The copy has only the fields that are present, `data` is
45
+ copied and frozen, and each property is read exactly once, so a getter or a Proxy cannot hand a
46
+ channel something other than what was checked: **send the copy**. `assertValidMessage(message)`
47
+ is the same check as a TypeScript type guard. The limits are exported as `MAX_TITLE_LENGTH`,
48
+ `MAX_BODY_LENGTH`, `MAX_URL_LENGTH`, `MAX_DATA_KEYS` and `MAX_MESSAGE_BYTES`.
49
+
50
+ `url` is opened by the user's device, so it is strict: `https:` without credentials, or a path
51
+ starting with a single `/` (not `//host` nor `/\host`, which browsers read as another host);
52
+ no control characters; at most 2000 characters. Never `javascript:`, `data:` or `http:` on any
53
+ other host. Build it from your own routes, never from client input.
54
+
55
+ `http:` is accepted only for a loopback origin written canonically: `isLocalHttpUrl(value)`
56
+ (from `@cardonjs/core`, re-exported here) requires the raw string to start with exactly
57
+ `http://localhost`, `http://127.0.0.1` or `http://[::1]` (lowercase), then an optional port of
58
+ digits and the end or `/`, `?`, `#`, in printable ASCII without a backslash, and the URL parser
59
+ to read the same host without credentials. The string you send is the string that was checked,
60
+ so it cannot name another host for another parser: `http://localhost\@evil.example/`,
61
+ fullwidth or zero-width characters, `localhos%74`, and also `HTTP://LOCALHOST/`, `127.1`,
62
+ `2130706433`, `0x7f.1` and `[0:0:0:0:0:0:0:1]` are refused although they are loopback for a
63
+ browser; so are `*.localhost`, a trailing dot, `0.0.0.0`, other `127.x` and IPv4-mapped
64
+ addresses. `https:` URLs are unchanged.
65
+
66
+ It is accepted in every environment, not behind a flag, so that an app can run on plain http
67
+ locally (`@cardonjs/users` emails link to the web app); the package does not know the environment,
68
+ so an app must refuse loopback origins outside development itself (the starter's config does).
69
+ What it means: the link, with whatever it carries (a token), travels like any other link through
70
+ the email provider, gateways and link scanners or rewriters; only following it stays on the
71
+ recipient's machine, and only if that machine resolves `localhost` to loopback, as browsers do.
72
+ Every `NotificationChannel` must accept such a URL: the contract checks it, so an adapter cannot
73
+ be stricter than the interface here.
74
+
75
+ Never put secrets in `title`, `body`, `tag` or `data`: they are shown on a lock screen, stored
76
+ by the provider or logged. Send an id and let the app load the details. The one exception is a
77
+ single-use link in `url` (an email verification or password reset) on a channel that delivers
78
+ privately to one person, such as email.
79
+
80
+ ## Templates
81
+
82
+ Templates are typed functions, not a template engine. Another language is another function.
83
+
84
+ ```ts
85
+ import { defineTemplates } from "@cardonjs/notify";
86
+
87
+ export const templates = defineTemplates({
88
+ orderReady: (data: { orderId: string; store: string }) => ({
89
+ title: "Your order is ready",
90
+ body: `Pick it up at ${data.store}.`,
91
+ url: `/orders/${data.orderId}`,
92
+ tag: `order-${data.orderId}`,
93
+ }),
94
+ orderReadyEs: (data: { orderId: string; store: string }) => ({
95
+ title: "Tu pedido está listo",
96
+ body: `Retiralo en ${data.store}.`,
97
+ url: `/orders/${data.orderId}`,
98
+ tag: `order-${data.orderId}`,
99
+ }),
100
+ });
101
+
102
+ // Typed: the name must exist and the data must match it.
103
+ const message = templates.render("orderReady", { orderId: "1001", store: "Centro" });
104
+ ```
105
+
106
+ `render` returns the frozen copy from `validMessage`; an unknown name throws a `TypeError`
107
+ (without echoing it).
108
+
109
+ ## Sending
110
+
111
+ A channel comes from an adapter in the adapters factory. Send to each target and delete the
112
+ gone ones; the result says what happened, nothing is thrown for a provider answer.
113
+
114
+ ```ts
115
+ import type { NotificationChannel, NotificationMessage } from "@cardonjs/notify";
116
+
117
+ /** Sends to every target; deletes the gone ones. Returns how many were sent. */
118
+ export async function sendToAll<Target>(
119
+ channel: NotificationChannel<Target>,
120
+ targets: readonly Target[],
121
+ message: NotificationMessage,
122
+ removeGone: (target: Target) => Promise<void>,
123
+ ): Promise<{ sent: number; failed: number }> {
124
+ let sent = 0;
125
+ let failed = 0;
126
+ for (const target of targets) {
127
+ const result = await channel.send(target, message);
128
+ if (result.status === "sent") sent++;
129
+ else if (result.status === "gone") await removeGone(target);
130
+ else failed++;
131
+ }
132
+ return { sent, failed };
133
+ }
134
+ ```
135
+
136
+ `@cardonjs/notify-webpush` shows the full flow for Web Push: the subscriptions table, the
137
+ subscribe route and a service worker.
138
+
139
+ ## Development: `logChannel`
140
+
141
+ ```ts
142
+ import { createLogger } from "@cardonjs/core";
143
+ import { logChannel } from "@cardonjs/notify";
144
+
145
+ const channel = logChannel(createLogger());
146
+ await channel.send("anyone", templates.render("orderReady", { orderId: "1001", store: "Centro" }));
147
+ // {"level":"info","msg":"notification sent","channel":"log","titleLength":19,"tag":"order-1001",...}
148
+ ```
149
+
150
+ It validates the message, logs the title length and the tag only (never the title, body, url,
151
+ data or target) and answers `sent`. Use it where there are no provider keys yet.
152
+
153
+ ## Testing
154
+
155
+ `memoryChannel<Target>()` from `@cardonjs/notify/testing` records what it delivers:
156
+
157
+ ```ts
158
+ import { memoryChannel } from "@cardonjs/notify/testing";
159
+
160
+ const channel = memoryChannel<string>();
161
+ await channel.send("user-1", { title: "Hi", body: "" });
162
+ channel.sent(); // [{ target: "user-1", message: { title: "Hi", body: "" } }]
163
+ channel.markGone("user-2"); // sends to "user-2" answer { status: "gone" }
164
+ channel.failNext(true); // the next send answers { status: "failed", retryable: true }
165
+ channel.attempts(); // sends that reached the "provider" (valid ones): 1 so far
166
+ ```
167
+
168
+ `undefined` and `null` targets are a `TypeError`. `markGone` matches targets like `Set` keys
169
+ (the same object or primitive); pass `memoryChannel({ key: (s) => s.endpoint })` so a row
170
+ reloaded from storage matches the one marked gone. Test-only: never use it in production.
171
+
172
+ ## Writing an adapter
173
+
174
+ An adapter returns a `NotificationChannel<Target>`, calls `validMessage` first and uses only the
175
+ copy, checks its target before any I/O, makes exactly one provider request per valid send (no
176
+ internal retries), and maps every provider answer and network failure to a `SendResult`.
177
+ It must pass the shared contract, run with the adapter's own test runner:
178
+
179
+ ```ts
180
+ import { type ChannelContractHarness, channelContract } from "@cardonjs/notify/contract";
181
+ import { describe, it } from "vitest";
182
+
183
+ function harness(): ChannelContractHarness<MyTarget> {
184
+ return {
185
+ create: () => myChannel({ fetch: stub.fetch }),
186
+ liveTarget: async () => ({ target: stub.liveTarget(), received: stub.received }),
187
+ goneTarget: async () => stub.goneTarget(),
188
+ failingTargets: async () => [
189
+ { target: stub.failing(503), retryable: true },
190
+ { target: stub.failing(400), retryable: false },
191
+ ],
192
+ invalidTargets: async () => [undefined, { address: "not valid" }],
193
+ attempts: async () => stub.requests.length, // every request the provider received
194
+ };
195
+ }
196
+
197
+ describe("channelContract", () => {
198
+ it.each(channelContract.map((c) => [c.name, c] as const))("%s", async (_, c) => {
199
+ await c.run(harness());
200
+ });
201
+ });
202
+ ```
203
+
204
+ The cases: a valid message arrives exactly once with every field intact (unicode and emoji
205
+ included); two sends arrive in order as two messages; a message with an `http:` URL on
206
+ `localhost` arrives intact; a gone target is `gone` (nothing to check
207
+ when `goneTarget` is `null`); each failing
208
+ target is `failed` with the expected `retryable`, never a rejection; invalid messages (empty
209
+ title, too long, `javascript:`/`http:` (on a public host or a look-alike of localhost)/`//host`
210
+ URLs, nested data, over 3000 bytes, ...) are a
211
+ `TypeError` and nothing is sent; invalid targets are a `TypeError` that does not echo them and
212
+ nothing is sent; results are not cached across targets (live then gone, or live then failing
213
+ when `goneTarget` is `null`). Every case also reads `attempts()`
214
+ before and after each send: a valid send (sent, gone or failed) is exactly one provider attempt,
215
+ an invalid message or target is none.
216
+
217
+ Two harness fields describe a provider that cannot do everything a push service does:
218
+
219
+ - `goneTarget: null`: the provider never reports a target as gone while sending (an email API
220
+ accepts a suppressed address and reports the bounce later, through a webhook). The gone case
221
+ then has nothing to check and says so in its name (exported as `GONE_CASE`, so the adapter's
222
+ runner can report it as skipped: `it.skip(GONE_CASE, ...)`), and the caching case uses the
223
+ first failing target, which must fail on every send.
224
+ - `undelivered: ["data"]` (any of `"url"`, `"tag"`, `"data"`): optional fields the channel
225
+ does not deliver by design (an email has no `data`). The cases compare what arrived without
226
+ them; a declared field that arrives anyway still fails, and any other value in `undelivered`
227
+ fails every case.
@@ -0,0 +1,57 @@
1
+ /**
2
+ * The shared contract every `NotificationChannel` adapter must pass. Import it from
3
+ * `@cardonjs/notify/contract` in the adapter's tests (it needs `@cardonjs/testing`) and run each case
4
+ * with the adapter's own runner against a harness over the channel (or a faithful stub of its
5
+ * provider).
6
+ */
7
+ import { type ContractCase } from "@cardonjs/testing";
8
+ import type { NotificationChannel, NotificationMessage } from "./notify.js";
9
+ export interface ChannelContractHarness<Target> {
10
+ /** The channel under test. Called once per case. */
11
+ create(): NotificationChannel<Target> | Promise<NotificationChannel<Target>>;
12
+ /** A target the provider accepts, and how to read what it received (decoded messages). */
13
+ liveTarget(): Promise<{
14
+ target: Target;
15
+ received(): Promise<NotificationMessage[]>;
16
+ }>;
17
+ /**
18
+ * A target the provider reports as gone, or `null` when the provider never reports one while
19
+ * sending (an email API accepts a suppressed address and reports the bounce later, through a
20
+ * webhook). With `null`, the gone case has nothing to check and passes without checking
21
+ * anything (its name says so; report it as skipped), and the caching case uses the first
22
+ * failing target instead, which must then fail on every send.
23
+ */
24
+ goneTarget: (() => Promise<Target>) | null;
25
+ /**
26
+ * Optional fields the channel does not deliver by design, left out when comparing what
27
+ * arrived (an email has no `data`). Only `"url"`, `"tag"` and `"data"`: anything else fails
28
+ * every case. Default: none; `title` and `body` always arrive.
29
+ */
30
+ readonly undelivered?: readonly UndeliveredField[];
31
+ /**
32
+ * Targets whose provider fails: `retryable` says what the channel must report. Not empty.
33
+ * The case sends to each once, in order.
34
+ */
35
+ failingTargets(): Promise<{
36
+ target: Target;
37
+ retryable: boolean;
38
+ }[]>;
39
+ /** Targets that must be rejected with TypeError before any I/O. Not empty. */
40
+ invalidTargets(): Promise<unknown[]>;
41
+ /**
42
+ * How many requests the provider has received so far, for all targets (e.g. the requests a
43
+ * stub served). The cases compare it before and after each send: a valid send is exactly one
44
+ * attempt (no internal retries); an invalid message or target is none.
45
+ */
46
+ attempts(): Promise<number>;
47
+ }
48
+ /** The optional message fields a channel may leave out by design. */
49
+ export type UndeliveredField = "url" | "tag" | "data";
50
+ /**
51
+ * The names of the two cases that depend on `goneTarget`. With `goneTarget: null`, the first
52
+ * passes without checking anything (an adapter may report it as skipped) and the second sends
53
+ * live, failing, live, failing.
54
+ */
55
+ export declare const GONE_CASE = "a gone target resolves gone (nothing to check when goneTarget is null)";
56
+ export declare const channelContract: readonly ContractCase<ChannelContractHarness<unknown>>[];
57
+ //# sourceMappingURL=contract.d.ts.map
@@ -0,0 +1 @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 * The shared contract every `NotificationChannel` adapter must pass. Import it from
3
+ * `@cardonjs/notify/contract` in the adapter's tests (it needs `@cardonjs/testing`) and run each case
4
+ * with the adapter's own runner against a harness over the channel (or a faithful stub of its
5
+ * provider).
6
+ */
7
+ import { defineContract, fail } from "@cardonjs/testing";
8
+ const UNDELIVERABLE = new Set(["url", "tag", "data"]);
9
+ /** Fails unless the harness fields every case relies on are well-formed. */
10
+ function checkHarness(harness) {
11
+ const undelivered = harness.undelivered;
12
+ if (undelivered === undefined)
13
+ return;
14
+ if (!Array.isArray(undelivered) || !undelivered.every((f) => UNDELIVERABLE.has(f))) {
15
+ fail('undelivered may only hold "url", "tag" or "data"', [`got ${canonical(undelivered)}`]);
16
+ }
17
+ }
18
+ /** Calls `run` and reports how it settled; a synchronous throw counts as a rejection. */
19
+ async function settle(run) {
20
+ try {
21
+ return { ok: true, value: await run() };
22
+ }
23
+ catch (error) {
24
+ return { ok: false, error };
25
+ }
26
+ }
27
+ function describeError(error) {
28
+ return error instanceof Error ? `${error.name}: ${error.message}` : String(error);
29
+ }
30
+ /** JSON with object keys sorted and `undefined` fields dropped, to compare values. */
31
+ function canonical(value) {
32
+ return JSON.stringify(value, (_key, v) => {
33
+ if (typeof v !== "object" || v === null || Array.isArray(v))
34
+ return v;
35
+ const sorted = {};
36
+ for (const key of Object.keys(v).sort())
37
+ sorted[key] = v[key];
38
+ return sorted;
39
+ });
40
+ }
41
+ /** Every string inside `value` with at least 6 characters (to check errors do not echo them). */
42
+ function stringsIn(value, found = [], depth = 0) {
43
+ if (typeof value === "string") {
44
+ if (value.length >= 6)
45
+ found.push(value);
46
+ }
47
+ else if (typeof value === "object" && value !== null && depth < 4) {
48
+ for (const entry of Object.values(value))
49
+ stringsIn(entry, found, depth + 1);
50
+ }
51
+ return found;
52
+ }
53
+ /** Fails unless `run` makes exactly `expected` provider attempts; returns what `run` settled to. */
54
+ async function withAttempts(harness, expected, title, run) {
55
+ const before = await harness.attempts();
56
+ const result = await settle(run);
57
+ const made = (await harness.attempts()) - before;
58
+ if (made !== expected) {
59
+ fail(title, [
60
+ `expected exactly ${expected} provider attempt(s), the provider received ${made}`,
61
+ ]);
62
+ }
63
+ return result;
64
+ }
65
+ async function sendExpecting(harness, channel, target, message, expected, title) {
66
+ const result = await withAttempts(harness, 1, title, () => channel.send(target, message));
67
+ if (!result.ok)
68
+ fail(title, [`send rejected: ${describeError(result.error)}`]);
69
+ if (canonical(result.value) !== canonical(expected)) {
70
+ fail(title, [`expected ${canonical(expected)}`, `got ${canonical(result.value)}`]);
71
+ }
72
+ }
73
+ /** `message` without the fields the harness declares undelivered. */
74
+ function deliverable(harness, message) {
75
+ const undelivered = harness.undelivered ?? [];
76
+ if (undelivered.length === 0)
77
+ return message;
78
+ const copy = { ...message };
79
+ for (const field of undelivered)
80
+ delete copy[field];
81
+ return copy;
82
+ }
83
+ async function expectReceived(harness, received, sent, title) {
84
+ const expected = sent.map((message) => deliverable(harness, message));
85
+ const got = await received();
86
+ if (got.length !== expected.length) {
87
+ fail(title, [`expected ${expected.length} message(s), received ${got.length}`]);
88
+ }
89
+ for (const [i, message] of expected.entries()) {
90
+ if (canonical(got[i]) !== canonical(message)) {
91
+ fail(title, [
92
+ `message #${i} changed on the way`,
93
+ `expected ${canonical(message)}`,
94
+ `received ${canonical(got[i])}`,
95
+ ]);
96
+ }
97
+ }
98
+ }
99
+ /**
100
+ * Fails unless `run` rejects (or throws) with a `TypeError` that echoes none of `secrets`,
101
+ * without any provider attempt.
102
+ */
103
+ async function expectTypeError(harness, run, title, secrets) {
104
+ const result = await withAttempts(harness, 0, title, run);
105
+ if (result.ok)
106
+ fail(title, [`it resolved ${canonical(result.value)}`]);
107
+ if (!(result.error instanceof TypeError)) {
108
+ fail(title, [`expected a TypeError, got ${describeError(result.error)}`]);
109
+ }
110
+ const message = result.error.message;
111
+ if (secrets.some((secret) => message.includes(secret))) {
112
+ fail(`${title}: the error message must not include the value`, [message]);
113
+ }
114
+ }
115
+ /** The gone target, or the first failing one when the provider never reports gone. */
116
+ async function otherTarget(harness) {
117
+ if (harness.goneTarget !== null) {
118
+ return { target: await harness.goneTarget(), result: { status: "gone" }, label: "gone" };
119
+ }
120
+ const failing = await harness.failingTargets();
121
+ const first = failing[0];
122
+ if (first === undefined)
123
+ fail("failingTargets must not be empty");
124
+ return {
125
+ target: first.target,
126
+ result: { status: "failed", retryable: first.retryable },
127
+ label: "failing",
128
+ };
129
+ }
130
+ const MARKER = "contract-marker-7f3a";
131
+ /** Every field, with unicode, emoji (outside the BMP and ZWJ sequences) and a newline. */
132
+ const FULL = {
133
+ title: "Tu pedido está listo 🎉",
134
+ body: 'Retiralo en el local — 日本語テキスト, café, 👩‍👩‍👧 and 🇦🇷.\nSecond line with "quotes".',
135
+ url: "https://shop.example.com/orders/1001?tab=pickup&lang=es#top",
136
+ tag: "order-1001:ready.v2",
137
+ data: { orderId: "1001", items: 3, ratio: 0.25, urgent: true, note: null, emoji: "🚚" },
138
+ };
139
+ const FIRST = { title: "First", body: "One", url: "/orders/1" };
140
+ /** An http URL on a local development host: accepted and delivered as given. */
141
+ const LOCAL = {
142
+ title: "Local",
143
+ body: "Development",
144
+ url: "http://localhost:5173/verify-email?token=abc",
145
+ };
146
+ /** Only the required fields: nothing may be added on the way. */
147
+ const SECOND = { title: "Second", body: "" };
148
+ const INVALID_MESSAGES = [
149
+ ["not an object", MARKER],
150
+ ["null", null],
151
+ ["an array", [{ title: "x", body: "" }]],
152
+ ["an empty title", { title: "", body: MARKER }],
153
+ ["a blank title", { title: " ", body: MARKER }],
154
+ ["a title over 120 characters", { title: `${MARKER}${"x".repeat(120)}`, body: "" }],
155
+ ["a body over 500 characters", { title: "Hi", body: `${MARKER}${"y".repeat(500)}` }],
156
+ ["a missing body", { title: MARKER }],
157
+ ["a javascript: url", { title: "Hi", body: "", url: `javascript:alert('${MARKER}')` }],
158
+ ["a data: url", { title: "Hi", body: "", url: `data:text/html,${MARKER}` }],
159
+ ["an http: url", { title: "Hi", body: "", url: `http://shop.example.com/${MARKER}` }],
160
+ [
161
+ "an http: url on a look-alike of localhost",
162
+ { title: "Hi", body: "", url: `http://localhost.example.com/${MARKER}` },
163
+ ],
164
+ ["an http: url on 0.0.0.0", { title: "Hi", body: "", url: `http://0.0.0.0/${MARKER}` }],
165
+ ["a protocol-relative //host url", { title: "Hi", body: "", url: `//evil.example/${MARKER}` }],
166
+ ["a /\\host url", { title: "Hi", body: "", url: `/\\evil.example/${MARKER}` }],
167
+ ["a url with a control character", { title: "Hi", body: "", url: `/orders/${MARKER}\n1` }],
168
+ ["a url with credentials", { title: "Hi", body: "", url: `https://${MARKER}@shop.example.com/` }],
169
+ ["a tag with spaces", { title: "Hi", body: "", tag: `${MARKER} tag` }],
170
+ ["nested data", { title: "Hi", body: "", data: { order: { id: MARKER } } }],
171
+ ["data with an array", { title: "Hi", body: "", data: { ids: [MARKER] } }],
172
+ [
173
+ "data with 21 keys",
174
+ {
175
+ title: "Hi",
176
+ body: "",
177
+ data: Object.fromEntries([...Array(21).keys()].map((i) => [`k${i}`, i])),
178
+ },
179
+ ],
180
+ ["a non-finite number", { title: "Hi", body: "", data: { amount: Number.NaN } }],
181
+ ["an unknown field", { title: "Hi", body: "", icon: `/${MARKER}.png` }],
182
+ [
183
+ "over 3000 bytes of JSON",
184
+ { title: "Hi", body: "", data: { blob: `${MARKER}${"z".repeat(3000)}` } },
185
+ ],
186
+ ];
187
+ /**
188
+ * The names of the two cases that depend on `goneTarget`. With `goneTarget: null`, the first
189
+ * passes without checking anything (an adapter may report it as skipped) and the second sends
190
+ * live, failing, live, failing.
191
+ */
192
+ export const GONE_CASE = "a gone target resolves gone (nothing to check when goneTarget is null)";
193
+ const CACHING_CASE = "results are not cached across targets (live then gone, or live then failing when goneTarget is null)";
194
+ const CASES = [
195
+ {
196
+ name: "a valid message arrives exactly once with every field intact",
197
+ async run(harness) {
198
+ const channel = await harness.create();
199
+ const live = await harness.liveTarget();
200
+ await sendExpecting(harness, channel, live.target, FULL, { status: "sent" }, "send to a live target must be sent");
201
+ await expectReceived(harness, live.received, [FULL], "the message must arrive exactly once, intact");
202
+ },
203
+ },
204
+ {
205
+ name: "two sends arrive in order as two messages",
206
+ async run(harness) {
207
+ const channel = await harness.create();
208
+ const live = await harness.liveTarget();
209
+ await sendExpecting(harness, channel, live.target, FIRST, { status: "sent" }, "the first send must be sent");
210
+ await sendExpecting(harness, channel, live.target, SECOND, { status: "sent" }, "the second send must be sent");
211
+ await expectReceived(harness, live.received, [FIRST, SECOND], "two sends must arrive in order as two messages");
212
+ },
213
+ },
214
+ {
215
+ name: "an http url on a local development host arrives intact",
216
+ async run(harness) {
217
+ const channel = await harness.create();
218
+ const live = await harness.liveTarget();
219
+ await sendExpecting(harness, channel, live.target, LOCAL, { status: "sent" }, "a send with an http url on localhost must be sent");
220
+ await expectReceived(harness, live.received, [LOCAL], "the message with an http url on localhost must arrive intact");
221
+ },
222
+ },
223
+ {
224
+ name: GONE_CASE,
225
+ async run(harness) {
226
+ // A provider that never reports gone while sending has nothing to check here.
227
+ if (harness.goneTarget === null)
228
+ return;
229
+ const channel = await harness.create();
230
+ const target = await harness.goneTarget();
231
+ await sendExpecting(harness, channel, target, FIRST, { status: "gone" }, "a gone target must resolve gone");
232
+ },
233
+ },
234
+ {
235
+ name: "each failing target resolves failed with the expected retryable, never a rejection",
236
+ async run(harness) {
237
+ const channel = await harness.create();
238
+ const failing = await harness.failingTargets();
239
+ if (failing.length === 0)
240
+ fail("failingTargets must not be empty");
241
+ for (const [i, { target, retryable }] of failing.entries()) {
242
+ await sendExpecting(harness, channel, target, FIRST, { status: "failed", retryable }, `failing target #${i} must resolve { status: "failed", retryable: ${retryable} }`);
243
+ }
244
+ },
245
+ },
246
+ {
247
+ name: "invalid messages reject with a TypeError and nothing is sent",
248
+ async run(harness) {
249
+ const channel = await harness.create();
250
+ const live = await harness.liveTarget();
251
+ for (const [label, message] of INVALID_MESSAGES) {
252
+ await expectTypeError(harness, () => channel.send(live.target, message), `send must reject ${label} with a TypeError`, [MARKER]);
253
+ }
254
+ await expectReceived(harness, live.received, [], "an invalid message must never be sent");
255
+ },
256
+ },
257
+ {
258
+ name: "invalid targets reject with a TypeError and no I/O",
259
+ async run(harness) {
260
+ const channel = await harness.create();
261
+ const live = await harness.liveTarget();
262
+ const invalid = await harness.invalidTargets();
263
+ if (invalid.length === 0)
264
+ fail("invalidTargets must not be empty");
265
+ for (const [i, target] of invalid.entries()) {
266
+ await expectTypeError(harness, () => channel.send(target, FIRST), `send must reject invalid target #${i} with a TypeError`, stringsIn(target));
267
+ }
268
+ await expectReceived(harness, live.received, [], "nothing may be sent for an invalid target");
269
+ },
270
+ },
271
+ {
272
+ name: CACHING_CASE,
273
+ async run(harness) {
274
+ const channel = await harness.create();
275
+ const live = await harness.liveTarget();
276
+ const other = await otherTarget(harness);
277
+ const sent = { status: "sent" };
278
+ await sendExpecting(harness, channel, live.target, FIRST, sent, "a live target must be sent");
279
+ await sendExpecting(harness, channel, other.target, FIRST, other.result, `a ${other.label} target after a live one must be ${other.label}`);
280
+ await sendExpecting(harness, channel, live.target, SECOND, sent, `a live target after a ${other.label} one must be sent`);
281
+ await sendExpecting(harness, channel, other.target, SECOND, other.result, `a ${other.label} target must stay ${other.label}`);
282
+ await expectReceived(harness, live.received, [FIRST, SECOND], "only the live sends must arrive");
283
+ },
284
+ },
285
+ ];
286
+ export const channelContract = defineContract(CASES.map(({ name, run }) => ({
287
+ name,
288
+ async run(harness) {
289
+ checkHarness(harness);
290
+ await run(harness);
291
+ },
292
+ })));
293
+ //# sourceMappingURL=contract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAqB,cAAc,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAwC5E,MAAM,aAAa,GAAyB,IAAI,GAAG,CAAmB,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC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,EAAE,CAAC;YAC5C,MAAM,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,4BAA4B,CAAC,CAAC;YAC9F,MAAM,aAAa,CACjB,OAAO,EACP,OAAO,EACP,KAAK,CAAC,MAAM,EACZ,KAAK,EACL,KAAK,CAAC,MAAM,EACZ,KAAK,KAAK,CAAC,KAAK,oCAAoC,KAAK,CAAC,KAAK,EAAE,CAClE,CAAC;YACF,MAAM,aAAa,CACjB,OAAO,EACP,OAAO,EACP,IAAI,CAAC,MAAM,EACX,MAAM,EACN,IAAI,EACJ,yBAAyB,KAAK,CAAC,KAAK,mBAAmB,CACxD,CAAC;YACF,MAAM,aAAa,CACjB,OAAO,EACP,OAAO,EACP,KAAK,CAAC,MAAM,EACZ,MAAM,EACN,KAAK,CAAC,MAAM,EACZ,KAAK,KAAK,CAAC,KAAK,qBAAqB,KAAK,CAAC,KAAK,EAAE,CACnD,CAAC;YACF,MAAM,cAAc,CAClB,OAAO,EACP,IAAI,CAAC,QAAQ,EACb,CAAC,KAAK,EAAE,MAAM,CAAC,EACf,iCAAiC,CAClC,CAAC;QACJ,CAAC;KACF;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAC1B,cAAc,CACZ,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC;IAC5B,IAAI;IACJ,KAAK,CAAC,GAAG,CAAC,OAAO;QACf,YAAY,CAAC,OAAO,CAAC,CAAC;QACtB,MAAM,GAAG,CAAC,OAAO,CAAC,CAAC;IACrB,CAAC;CACF,CAAC,CAAC,CACJ,CAAC"}
@@ -0,0 +1,6 @@
1
+ export { isLocalDevelopmentHost, isLocalHttpUrl } from "@cardonjs/core";
2
+ export { logChannel } from "./log-channel.js";
3
+ export type { NotificationChannel, NotificationMessage, SendResult } from "./notify.js";
4
+ export { defineTemplates, type Templates } from "./templates.js";
5
+ export { assertValidMessage, MAX_BODY_LENGTH, MAX_DATA_KEYS, MAX_MESSAGE_BYTES, MAX_TITLE_LENGTH, MAX_URL_LENGTH, validMessage, } from "./validation.js";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,YAAY,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACxF,OAAO,EAAE,eAAe,EAAE,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,YAAY,GACb,MAAM,iBAAiB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ // The local development rule of message URLs lives in @cardonjs/core (apps use it too).
2
+ export { isLocalDevelopmentHost, isLocalHttpUrl } from "@cardonjs/core";
3
+ export { logChannel } from "./log-channel.js";
4
+ export { defineTemplates } from "./templates.js";
5
+ export { assertValidMessage, MAX_BODY_LENGTH, MAX_DATA_KEYS, MAX_MESSAGE_BYTES, MAX_TITLE_LENGTH, MAX_URL_LENGTH, validMessage, } from "./validation.js";
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EAAE,eAAe,EAAkB,MAAM,gBAAgB,CAAC;AACjE,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,YAAY,GACb,MAAM,iBAAiB,CAAC"}