@vllnt/convex-suppression 0.1.0 → 0.1.1-canary.5677f98

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,86 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here. The format is based on
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project
5
+ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ### Added
10
+
11
+ - The npm package now ships `docs/*.md`, `CHANGELOG.md` and `llms.txt`, so
12
+ coding agents can read docs that match the installed version from
13
+ `node_modules/@vllnt/convex-suppression/`. `llms.txt` links to bundled files
14
+ with `./` paths. A test fails when a required file is missing from the
15
+ tarball.
16
+
17
+ ### Changed
18
+
19
+ - Every push to `main` that touches the package or its shipped docs publishes a
20
+ `@canary` build; the opt-in repository-variable gate is removed.
21
+
22
+ - Removed the `by_hash` index; it was unused and a prefix of `by_hash_channel`.
23
+ One less index entry written per suppression and less index storage.
24
+
25
+ ## [0.1.1] - Unreleased
26
+
27
+ ### Fixed
28
+
29
+ - `suppress` and `recordOptIn` now throw
30
+ `ConvexError({ code: "INVALID_ARGUMENT", field })` for an empty `contactHash`,
31
+ `channel`, `listKey` or `source`. `isEligible` previously answered `true` for
32
+ an empty `contactHash` or `channel`; it now answers `false`, so the send gate
33
+ fails closed. Documented that keys are matched exactly (no case, whitespace or
34
+ plus-address normalization; the host normalizes).
35
+ - The `./test` entry now type-checks for consumers using
36
+ `moduleResolution: nodenext` (relative imports use `.js`; Vite client types
37
+ are referenced). The README documents the `convex-test` and `vitest`
38
+ requirement.
39
+
40
+ ### Changed
41
+
42
+ - Release automation: pinned actions, least-privilege permissions, npm trusted
43
+ publishing with provenance; `@latest` is published only from a `vX.Y.Z` tag on
44
+ `main`.
45
+ - Dev tooling: pnpm 10 with a release-age gate, low-memory test/lint defaults,
46
+ `deepmerge-ts` override for a dev-only advisory.
47
+ - The README install command now installs the stable release.
48
+
49
+ ## [0.1.0] - 2026-09-01
50
+
51
+ ### Added
52
+
53
+ - First release of `@vllnt/convex-suppression` — the hash-keyed do-not-contact
54
+ suppression list + opt-in proof (GDPR opt-out / CAN-SPAM).
55
+ - `suppress(contactHash, reason, { channel? })` adds a `(contactHash, channel)`
56
+ anti-membership tombstone; `reason` is `unsubscribe`/`bounce`/`complaint`/
57
+ `manual`/`global`. Omitting `channel` marks a global all-channel suppression.
58
+ - `unsuppress(contactHash, channel?)` removes an entry (a rare, audited
59
+ re-subscribe); returns whether an entry was removed.
60
+ - `isSuppressed(contactHash, channel?)` returns the matching suppression (a
61
+ global tombstone matches every channel and wins) or `null`.
62
+ - `recordOptIn(contactHash, { listKey?, source, proof? })` records an opt-in
63
+ proof; `getOptInProof(contactHash, listKey?)` fetches it.
64
+ - `isEligible(contactHash, { channel?, listKey?, requireOptIn? })` — the single
65
+ send gate: `¬suppressed [∧ confirmed]`. Suppression always blocks; the opt-in
66
+ requirement is per call.
67
+ - Hash-keyed: the component stores only the host's opaque `contactHash`, never
68
+ raw PII, so a suppression survives erasure of the subject.
69
+ - Idempotent writes: re-suppressing or re-recording an opt-in on its key tuple
70
+ updates in place — a replayed bounce/complaint/confirmation webhook never
71
+ duplicates a row.
72
+ - Typed generics: `Suppression<TProof>` with an optional `proofValidator` host
73
+ parser narrowing the opaque stored opt-in `proof` at the client boundary on
74
+ write and read — no `v.any()` dump, no unchecked cast.
75
+ - Server-sourced time: every handler stamps `createdAt`/`confirmedAt` from
76
+ `Date.now()` inside the mutation — no caller-supplied clock.
77
+ - Mount-safe: correct under multiple `app.use(component, { name })` mounts —
78
+ each instance is a sandboxed, independent do-not-contact list.
79
+
80
+ ### Changed
81
+
82
+ - Treat Convex `_generated` output as CLI-owned, exclude it from formatting, and
83
+ expose a dedicated codegen script.
84
+ - Refresh all direct dependencies to their latest compatible releases for canary
85
+ validation.
86
+ - Require `convex@^1.45.0` and update `convex-test` to `^0.0.56`.
package/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  <!-- Badges -->
2
+
2
3
  [![convex-component](https://img.shields.io/badge/convex-component-EE342F.svg)](https://www.convex.dev/components)
3
4
  [![npm](https://img.shields.io/npm/v/@vllnt/convex-suppression.svg)](https://www.npmjs.com/package/@vllnt/convex-suppression)
4
5
  [![CI](https://github.com/vllnt/convex-suppression/actions/workflows/ci.yml/badge.svg)](https://github.com/vllnt/convex-suppression/actions/workflows/ci.yml)
@@ -16,30 +17,46 @@ const canSend = await dnc.isEligible(ctx, contactHash, { channel: "email" });
16
17
 
17
18
  The GDPR opt-out / CAN-SPAM primitive: a global do-not-contact list keyed by an
18
19
  opaque **`contactHash`** (never raw PII, so it survives erasure) plus an opt-in
19
- proof ledger. Before every send the host asks `isEligible`; an unsubscribe / bounce
20
- / complaint calls `suppress`; a double-opt-in confirmation calls `recordOptIn`.
21
- Domain-neutral — channels and reasons are the host's.
20
+ proof store (latest proof per contact/list, not append-only history). Before
21
+ every send the host asks `isEligible`; an unsubscribe / bounce / complaint calls
22
+ `suppress`; a double-opt-in confirmation calls `recordOptIn`. Domain-neutral —
23
+ channels are host-defined; reasons use the fixed union listed below.
22
24
 
23
25
  ## Features
24
26
 
25
- - **Hash-keyed, erasure-surviving** — stores only the opaque `contactHash`, never raw PII, so a tombstone outlives erasure of the subject.
26
- - **Channel-aware** — scope a suppression to one channel (`"email"`/`"sms"`/`"push"`), or omit `channel` for a global all-channel tombstone.
27
- - **One send gate** — `isEligible` answers `¬suppressed [∧ confirmed]` in one call; suppression always blocks, opt-in is per call.
28
- - **Opt-in proof ledger** — `recordOptIn` / `getOptInProof` store legal proof-of-consent per list, kept separate from any authz store.
29
- - **Idempotent** — re-suppressing / re-recording on its key tuple updates in place, so a replayed webhook never duplicates a row.
30
- - **Typed, opaque proof** — `Suppression<TProof>` with an optional `proofValidator` narrows the stored evidence at the boundary.
31
- - **Server-sourced time** — `createdAt`/`confirmedAt` are stamped from the server clock; a caller can never supply a timestamp.
32
- - **Mount-safe** — correct under multiple named `app.use` mounts (e.g. marketing vs. transactional lists), each an isolated sandbox.
27
+ - **Hash-keyed, erasure-surviving** — stores only the opaque `contactHash`,
28
+ never raw PII, so a tombstone outlives erasure of the subject.
29
+ - **Channel-aware** — scope a suppression to one channel
30
+ (`"email"`/`"sms"`/`"push"`), or omit `channel` for a global all-channel
31
+ tombstone.
32
+ - **One send gate** — `isEligible` answers `¬suppressed [∧ confirmed]` in one
33
+ call; suppression always blocks, opt-in is per call.
34
+ - **Opt-in proof ledger** — `recordOptIn` / `getOptInProof` store legal
35
+ proof-of-consent per list, kept separate from any authz store.
36
+ - **Idempotent** — re-suppressing / re-recording on its key tuple updates in
37
+ place, so a replayed webhook never duplicates a row.
38
+ - **Typed, opaque proof** — `Suppression<TProof>` with an optional
39
+ `proofValidator` narrows the stored evidence at the boundary.
40
+ - **Server-sourced time** — `createdAt`/`confirmedAt` are stamped from the
41
+ server clock; a caller can never supply a timestamp.
42
+ - **Mount-safe** — correct under multiple named `app.use` mounts (e.g. marketing
43
+ vs. transactional lists), each an isolated sandbox.
33
44
 
34
45
  ## Installation
35
46
 
36
47
  ```bash
37
- pnpm add @vllnt/convex-suppression
48
+ pnpm add @vllnt/convex-suppression convex@^1.45.0
38
49
  ```
39
50
 
40
- Peer dependency: `convex@^1.41.0`.
51
+ Peer dependency: `convex@^1.45.0`. The `canary` dist-tag carries pre-release
52
+ builds (pin an exact canary version for reproducible installs).
53
+
54
+ ## Quick start
41
55
 
42
- ## Usage
56
+ After mounting, run `pnpm exec convex dev` to generate `components.suppression`.
57
+ These internal functions accept a contact hash from trusted server code. The
58
+ host must normalize and hash contacts consistently, authenticate webhooks, and
59
+ verify opt-in before calling them.
43
60
 
44
61
  ```ts
45
62
  // convex/convex.config.ts
@@ -54,61 +71,110 @@ export default app;
54
71
  ```ts
55
72
  // convex/email.ts — host owns auth + hashing; pass an opaque contactHash in.
56
73
  import { components } from "./_generated/api";
57
- import { mutation, query } from "./_generated/server";
74
+ import { internalMutation, internalQuery } from "./_generated/server";
58
75
  import { v } from "convex/values";
59
76
  import { Suppression } from "@vllnt/convex-suppression";
60
77
 
61
78
  const dnc = new Suppression<{ ip: string }>(components.suppression, {
62
- proofValidator: v.object({ ip: v.string() }).parse,
79
+ proofValidator: (value) => {
80
+ if (
81
+ typeof value !== "object" ||
82
+ value === null ||
83
+ !("ip" in value) ||
84
+ typeof value.ip !== "string"
85
+ ) {
86
+ throw new Error("Expected an ip string");
87
+ }
88
+ return { ip: value.ip };
89
+ },
63
90
  });
64
- const hash = (email: string) => myHash(email.trim().toLowerCase()); // host's hashing + salt policy
65
91
 
66
92
  // The send gate — call before every send.
67
- export const canEmail = query({
68
- args: { email: v.string() },
69
- handler: (ctx, { email }) =>
70
- dnc.isEligible(ctx, hash(email), { channel: "email", listKey: "newsletter", requireOptIn: true }),
93
+ export const canEmail = internalQuery({
94
+ args: { contactHash: v.string() },
95
+ handler: (ctx, { contactHash }) =>
96
+ dnc.isEligible(ctx, contactHash, {
97
+ channel: "email",
98
+ listKey: "newsletter",
99
+ requireOptIn: true,
100
+ }),
71
101
  });
72
102
 
73
103
  // A provider webhook suppresses on complaint; a confirmed double opt-in records proof.
74
- export const onComplaint = mutation({
75
- args: { email: v.string() },
76
- handler: (ctx, { email }) => dnc.suppress(ctx, hash(email), "complaint", { channel: "email" }),
104
+ export const onComplaint = internalMutation({
105
+ args: { contactHash: v.string() },
106
+ handler: (ctx, { contactHash }) =>
107
+ dnc.suppress(ctx, contactHash, "complaint", { channel: "email" }),
77
108
  });
78
- export const confirmOptIn = mutation({
79
- args: { email: v.string(), ip: v.string() },
80
- handler: (ctx, { email, ip }) =>
81
- dnc.recordOptIn(ctx, hash(email), { listKey: "newsletter", source: "double-opt-in", proof: { ip } }),
109
+ export const confirmOptIn = internalMutation({
110
+ args: { contactHash: v.string(), ip: v.string() },
111
+ handler: (ctx, { contactHash, ip }) =>
112
+ dnc.recordOptIn(ctx, contactHash, {
113
+ listKey: "newsletter",
114
+ source: "double-opt-in",
115
+ proof: { ip },
116
+ }),
82
117
  });
83
118
  ```
84
119
 
85
- Client options: `new Suppression(component, { proofValidator? })`. Omitting `channel`/`listKey` targets the global entry.
120
+ Client options: `new Suppression(component, { proofValidator? })`. Omitting
121
+ `channel`/`listKey` targets the global entry.
86
122
 
87
123
  ## API Reference
88
124
 
89
- | Method | Kind | Result |
90
- |--------|------|--------|
125
+ | Method | Kind | Result |
126
+ | ------------------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------- |
91
127
  | `suppress(ctx, contactHash, reason, opts?)` | mutation | `null` (`reason`: `"unsubscribe" \| "bounce" \| "complaint" \| "manual" \| "global"`; `opts`: `{ channel? }`) |
92
- | `unsuppress(ctx, contactHash, channel?)` | mutation | `boolean` (`true` if an entry was removed) |
93
- | `recordOptIn(ctx, contactHash, opts)` | mutation | `null` (`opts`: `{ listKey?; source; proof? }`) |
94
- | `isSuppressed(ctx, contactHash, channel?)` | query | `SuppressionView \| null` |
95
- | `getOptInProof(ctx, contactHash, listKey?)` | query | `OptInProofView \| null` |
96
- | `isEligible(ctx, contactHash, opts?)` | query | `boolean` (`opts`: `{ channel?; listKey?; requireOptIn? }`) |
128
+ | `unsuppress(ctx, contactHash, channel?)` | mutation | `boolean` (`true` if an entry was removed) |
129
+ | `recordOptIn(ctx, contactHash, opts)` | mutation | `null` (`opts`: `{ listKey?; source; proof? }`) |
130
+ | `isSuppressed(ctx, contactHash, channel?)` | query | `SuppressionView \| null` |
131
+ | `getOptInProof(ctx, contactHash, listKey?)` | query | `OptInProofView \| null` |
132
+ | `isEligible(ctx, contactHash, opts?)` | query | `boolean` (`opts`: `{ channel?; listKey?; requireOptIn? }`) |
97
133
 
98
134
  Full reference: [docs/API.md](docs/API.md).
99
135
 
100
- ## React
136
+ ## Options and limitations
137
+
138
+ - The only constructor option is `proofValidator`, a parser
139
+ `(unknown) => TProof`, not `v.*.parse`.
140
+ - A channel-specific check first checks the global `"*"` suppression. Omitting
141
+ `channel` checks only the global row, not all channel rows. Always pass the
142
+ send's channel.
143
+ - Opt-in uses an exact `listKey` match: global proof is not a fallback for a
144
+ named list. `recordOptIn` does not remove suppression; `unsuppress` removes
145
+ only the exact channel/global row.
146
+ - No TTL, pruning, or cron exists. Suppressions remain until `unsuppress`;
147
+ opt-in proofs remain and are overwritten on re-recording, with no public
148
+ delete method.
149
+ - Keys are matched exactly: `contactHash`, `channel`, and `listKey` are case-
150
+ and whitespace-sensitive, with no trimming or plus-address folding. Normalize
151
+ them consistently in the host (`"Email"` is not `"email"`).
152
+ - Writes with an empty `contactHash`/`channel`/`listKey`/`source` throw
153
+ `INVALID_ARGUMENT`; `isEligible` answers `false` for an empty `contactHash` or
154
+ `channel`, so the gate fails closed.
155
+ - Hashing is host-owned and does not make data automatically anonymous. Proof
156
+ may contain personal data; minimize it and choose a compliant retention
157
+ policy. This package is not a legal-compliance guarantee.
158
+ - Mount separately with `app.use(suppression, { name: "marketingDnc" })` and
159
+ `new Suppression(components.marketingDnc)`.
160
+
161
+ ## Integrations
101
162
 
102
163
  Backend-only — no `./react` entry. The consumer surface is a server-side
103
- `isEligible` gate and webhook-driven `suppress` writes; a reactive do-not-contact
104
- badge, if ever needed, is an ordinary `useQuery` over the host's re-exported
105
- `isSuppressed` ref.
164
+ `isEligible` gate and webhook-driven `suppress` writes; a reactive
165
+ do-not-contact badge, if ever needed, is an ordinary `useQuery` over the host's
166
+ re-exported `isSuppressed` ref.
106
167
 
107
168
  ## Security
108
169
 
109
- - **Auth-agnostic** — the host authenticates the caller, decides who may suppress/query a hash, and passes an opaque `contactHash`; tables are sandboxed.
110
- - **Hash-keyed, never raw PII** — the host hashes and normalizes the contact and owns the salt policy; a suppression survives erasure of the subject.
111
- - **Server-sourced time** — `createdAt`/`confirmedAt` come from `Date.now()` in each handler, never the caller; the opt-in `proof` is opaque, narrowed by the host validator.
170
+ - **Auth-agnostic** — the host authenticates the caller, decides who may
171
+ suppress/query a hash, and passes an opaque `contactHash`; tables are
172
+ sandboxed.
173
+ - **Hash-keyed, never raw PII** — the host hashes and normalizes the contact and
174
+ owns the salt policy; a suppression survives erasure of the subject.
175
+ - **Server-sourced time** — `createdAt`/`confirmedAt` come from `Date.now()` in
176
+ each handler, never the caller; the opt-in `proof` is opaque, narrowed by the
177
+ host validator.
112
178
 
113
179
  See [docs/API.md](docs/API.md).
114
180
 
@@ -119,20 +185,67 @@ pnpm test # single run
119
185
  pnpm test:coverage # enforced 100% on covered files
120
186
  ```
121
187
 
122
- Tests run against the real component runtime via `convex-test` (`@edge-runtime/vm`), not mocks.
188
+ Tests run against the real component runtime via `convex-test`
189
+ (`@edge-runtime/vm`), not mocks.
190
+
191
+ ### Testing your app
192
+
193
+ `@vllnt/convex-suppression/test` exports `register(t, name = "suppression")` to
194
+ mount the component in a `convex-test` instance. It needs `convex-test` and
195
+ `vitest` (with Vite's `import.meta.glob`) in the consuming app:
196
+
197
+ ```ts
198
+ /// <reference types="vite/client" />
199
+ import { convexTest } from "convex-test";
200
+ import { register } from "@vllnt/convex-suppression/test";
201
+ import schema from "./schema";
202
+
203
+ const t = convexTest(schema, import.meta.glob("./**/*.ts"));
204
+ register(t);
205
+ ```
206
+
207
+ ## For coding agents
208
+
209
+ The docs are bundled in the package at
210
+ `node_modules/@vllnt/convex-suppression/docs/`, next to `README.md`,
211
+ `CHANGELOG.md`, `llms.txt` and the TypeScript source in `src/`. They match the
212
+ installed version. Read them before writing code.
213
+
214
+ ## Documentation
215
+
216
+ `llms.txt` is the maintained discovery index. `pnpm generate:llms` checks its
217
+ heading and local links without generating a source bundle.
218
+
219
+ [API reference](docs/API.md) · [LLM index](llms.txt) ·
220
+ [Security policy](https://github.com/vllnt/convex-suppression/blob/main/SECURITY.md)
221
+
222
+ ## Related packages
223
+
224
+ - [`@vllnt/convex-email`](https://oss.vllnt.com/packages/convex-email) — the
225
+ outbound email queue. Use it to send; call `isEligible` here before you
226
+ enqueue a message.
227
+ - [`@vllnt/convex-consent`](https://oss.vllnt.com/packages/convex-consent) — an
228
+ append-only consent ledger per subject and purpose (GDPR Art. 6/7). Use it for
229
+ consent to processing with withdrawal and history; use this package for the
230
+ do-not-contact list that must survive erasure.
231
+ - [`@vllnt/convex-memberships`](https://oss.vllnt.com/packages/convex-memberships)
232
+ — membership edges. Use it for who is on a subscriber list; this package only
233
+ records who must never be contacted.
123
234
 
124
235
  ## Contributing
125
236
 
126
- See [CONTRIBUTING.md](CONTRIBUTING.md).
237
+ See
238
+ [CONTRIBUTING.md](https://github.com/vllnt/convex-suppression/blob/main/CONTRIBUTING.md).
127
239
 
128
240
  ## Author
129
241
 
130
- Built by [bntvllnt](https://github.com/bntvllnt) · [bntvllnt.com](https://bntvllnt.com) · [X @bntvllnt](https://x.com/bntvllnt)
131
-
132
- Part of the [@vllnt](https://github.com/vllnt) Convex component fleet — [vllnt.com](https://vllnt.com)
242
+ Built by [bntvllnt](https://github.com/bntvllnt) ·
243
+ [bntvllnt.com](https://bntvllnt.com) · [X @bntvllnt](https://x.com/bntvllnt)
133
244
 
134
245
  If this is useful, [sponsor the work](https://github.com/sponsors/bntvllnt).
135
246
 
136
247
  ## License
137
248
 
138
249
  MIT — see [LICENSE](LICENSE).
250
+
251
+ Part of vllnt oss: https://oss.vllnt.com
@@ -75,7 +75,7 @@ interface RunMutationCtx {
75
75
  * @example
76
76
  * ```ts
77
77
  * const dnc = new Suppression(components.suppression, {
78
- * proofValidator: v.object({ ip: v.string() }).parse,
78
+ * proofValidator: (value) => parseIpProof(value), // host parser: (unknown) => TProof
79
79
  * });
80
80
  * // a webhook suppresses on complaint:
81
81
  * await dnc.suppress(ctx, contactHash, "complaint", { channel: "email" });
@@ -16,7 +16,7 @@ import { GLOBAL_CHANNEL } from "../shared.js";
16
16
  * @example
17
17
  * ```ts
18
18
  * const dnc = new Suppression(components.suppression, {
19
- * proofValidator: v.object({ ip: v.string() }).parse,
19
+ * proofValidator: (value) => parseIpProof(value), // host parser: (unknown) => TProof
20
20
  * });
21
21
  * // a webhook suppresses on complaint:
22
22
  * await dnc.suppress(ctx, contactHash, "complaint", { channel: "email" });
@@ -3,9 +3,10 @@
3
3
  export type SuppressionReason = "unsubscribe" | "bounce" | "complaint" | "manual" | "global";
4
4
  /**
5
5
  * Validates and narrows opaque host opt-in evidence to a host type `T` at the
6
- * client boundary. Receives the raw value the component returned (`unknown`) and
7
- * MUST return a typed `T` or throw. A `convex/values` validator's `.parse` (or a
8
- * Zod `.parse`) fits directly; omit it to keep the value unvalidated.
6
+ * client boundary. Receives the opaque value (`unknown`) on write before storage
7
+ * and on read after the component returns it, and MUST return a typed `T` or
8
+ * throw. A Zod `.parse` fits directly; `convex/values` validators have no
9
+ * `.parse`. Omit it to keep the value unvalidated.
9
10
  *
10
11
  * @typeParam T - The host's stored opt-in `proof` type.
11
12
  */
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAE5D,0EAA0E;AAC1E,MAAM,MAAM,iBAAiB,GACzB,aAAa,GACb,QAAQ,GACR,WAAW,GACX,QAAQ,GACR,QAAQ,CAAC;AAEb;;;;;;;GAOG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,KAAK,CAAC,CAAC;AAE9C,qFAAqF;AACrF,MAAM,WAAW,eAAe;IAC9B,gEAAgE;IAChE,WAAW,EAAE,MAAM,CAAC;IACpB,2FAA2F;IAC3F,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,8EAA8E;IAC9E,MAAM,EAAE,iBAAiB,CAAC;IAC1B,0DAA0D;IAC1D,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,wFAAwF;AACxF,MAAM,WAAW,cAAc,CAAC,MAAM,GAAG,OAAO;IAC9C,sCAAsC;IACtC,WAAW,EAAE,MAAM,CAAC;IACpB,6EAA6E;IAC7E,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,0E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AE,iBAAiB,CAAC;IAC1B,0DAA0D;IAC1D,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,wFAAwF;AACxF,MAAM,WAAW,cAAc,CAAC,MAAM,GAAG,OAAO;IAC9C,sCAAsC;IACtC,WAAW,EAAE,MAAM,CAAC;IACpB,6EAA6E;IAC7E,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,0EAA0E;IAC1E,MAAM,EAAE,MAAM,CAAC;IACf,wEAAwE;IACxE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,sDAAsD;IACtD,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,yDAAyD;AACzD,MAAM,WAAW,eAAe;IAC9B,oFAAoF;IACpF,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,4DAA4D;AAC5D,MAAM,WAAW,kBAAkB,CAAC,MAAM;IACxC,wEAAwE;IACxE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mCAAmC;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,gFAAgF;IAChF,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,2DAA2D;AAC3D,MAAM,WAAW,iBAAiB;IAChC,sFAAsF;IACtF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iFAAiF;IACjF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uEAAuE;IACvE,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,+DAA+D;AAC/D,MAAM,WAAW,kBAAkB,CAAC,MAAM;IACxC;;;;;OAKG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;CACjC"}
@@ -10,7 +10,8 @@
10
10
  * its `reason` and refreshes `createdAt` rather than inserting a duplicate, so a
11
11
  * replayed bounce/complaint webhook can never fan the table out. `createdAt` is
12
12
  * stamped from the server clock (`Date.now()` inside the handler — never
13
- * caller-supplied).
13
+ * caller-supplied). An empty `contactHash` or `channel` throws
14
+ * `INVALID_ARGUMENT`.
14
15
  */
15
16
  export declare const suppress: import("convex/server").RegisteredMutation<"public", {
16
17
  channel: string;
@@ -38,7 +39,8 @@ export declare const unsuppress: import("convex/server").RegisteredMutation<"pub
38
39
  *
39
40
  * Idempotent on `(contactHash, listKey)`: a second confirmation updates `source`,
40
41
  * `proof`, and `confirmedAt` rather than inserting a duplicate. `confirmedAt` is
41
- * server-sourced.
42
+ * server-sourced. An empty `contactHash`, `listKey`, or `source` throws
43
+ * `INVALID_ARGUMENT`.
42
44
  */
43
45
  export declare const recordOptIn: import("convex/server").RegisteredMutation<"public", {
44
46
  contactHash: string;
@@ -1 +1 @@
1
- {"version":3,"file":"mutations.d.ts","sourceRoot":"","sources":["../../src/component/mutations.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,QAAQ;;;;iBA2BnB,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,UAAU;;;oBAgBrB,CAAC;AAEH;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,WAAW;;;;;iBAiCtB,CAAC"}
1
+ {"version":3,"file":"mutations.d.ts","sourceRoot":"","sources":["../../src/component/mutations.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,QAAQ;;;;iBAgCnB,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,UAAU;;;oBAgBrB,CAAC;AAEH;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,WAAW;;;;;iBAoCtB,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { v } from "convex/values";
2
- import { mutation } from "./_generated/server";
3
- import { jsonValue, suppressionReason } from "./validators";
2
+ import { mutation } from "./_generated/server.js";
3
+ import { assertNonEmpty, jsonValue, suppressionReason } from "./validators.js";
4
4
  /**
5
5
  * Suppress a `(contactHash, channel)` — add it to the do-not-contact list. The
6
6
  * host hashes and normalizes the contact itself and passes the opaque
@@ -13,7 +13,8 @@ import { jsonValue, suppressionReason } from "./validators";
13
13
  * its `reason` and refreshes `createdAt` rather than inserting a duplicate, so a
14
14
  * replayed bounce/complaint webhook can never fan the table out. `createdAt` is
15
15
  * stamped from the server clock (`Date.now()` inside the handler — never
16
- * caller-supplied).
16
+ * caller-supplied). An empty `contactHash` or `channel` throws
17
+ * `INVALID_ARGUMENT`.
17
18
  */
18
19
  export const suppress = mutation({
19
20
  args: {
@@ -23,13 +24,18 @@ export const suppress = mutation({
23
24
  },
24
25
  returns: v.null(),
25
26
  handler: async (ctx, args) => {
27
+ assertNonEmpty("contactHash", args.contactHash);
28
+ assertNonEmpty("channel", args.channel);
26
29
  const existing = await ctx.db
27
30
  .query("suppressions")
28
31
  .withIndex("by_hash_channel", (q) => q.eq("contactHash", args.contactHash).eq("channel", args.channel))
29
32
  .unique();
30
33
  const now = Date.now();
31
34
  if (existing !== null) {
32
- await ctx.db.patch("suppressions", existing._id, { reason: args.reason, createdAt: now });
35
+ await ctx.db.patch("suppressions", existing._id, {
36
+ reason: args.reason,
37
+ createdAt: now,
38
+ });
33
39
  return null;
34
40
  }
35
41
  await ctx.db.insert("suppressions", {
@@ -73,7 +79,8 @@ export const unsuppress = mutation({
73
79
  *
74
80
  * Idempotent on `(contactHash, listKey)`: a second confirmation updates `source`,
75
81
  * `proof`, and `confirmedAt` rather than inserting a duplicate. `confirmedAt` is
76
- * server-sourced.
82
+ * server-sourced. An empty `contactHash`, `listKey`, or `source` throws
83
+ * `INVALID_ARGUMENT`.
77
84
  */
78
85
  export const recordOptIn = mutation({
79
86
  args: {
@@ -84,6 +91,9 @@ export const recordOptIn = mutation({
84
91
  },
85
92
  returns: v.null(),
86
93
  handler: async (ctx, args) => {
94
+ assertNonEmpty("contactHash", args.contactHash);
95
+ assertNonEmpty("listKey", args.listKey);
96
+ assertNonEmpty("source", args.source);
87
97
  const existing = await ctx.db
88
98
  .query("optInProofs")
89
99
  .withIndex("by_hash_list", (q) => q.eq("contactHash", args.contactHash).eq("listKey", args.listKey))
@@ -1 +1 @@
1
- {"version":3,"file":"m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B,cAAc,CAAC,aAAa,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QAChD,cAAc,CAAC,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QACxC,cAAc,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QACtC,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,EAAE;aAC1B,KAAK,CAAC,aAAa,CAAC;aACpB,SAAS,CAAC,cAAc,EAAE,CAAC,CAAC,EAAE,EAAE,CAC/B,CAAC,CAAC,EAAE,CAAC,aAAa,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,CAClE;aACA,MAAM,EAAE,CAAC;QACZ,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;YACtB,MAAM,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,aAAa,EAAE,QAAQ,CAAC,GAAG,EAAE;gBAC9C,MAAM,EAAE,IAAI,CAAC,MAAM;gBACnB,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,WAAW,EAAE,GAAG;aACjB,CAAC,CAAC;YACH,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,aAAa,EAAE;YACjC,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,WAAW,EAAE,GAAG;SACjB,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAC,CAAC"}
@@ -35,7 +35,8 @@ export declare const getOptInProof: import("convex/server").RegisteredQuery<"pub
35
35
  * `requireOptIn` is set — has a recorded opt-in proof for `listKey`. This is the
36
36
  * single call a sender makes before every send: `¬suppressed [∧ confirmed]`.
37
37
  * Suppression always blocks; the opt-in requirement is opt-in per call (marketing
38
- * mail sets it; a transactional send may not).
38
+ * mail sets it; a transactional send may not). An empty `contactHash` or
39
+ * `channel` answers `false` (fail closed).
39
40
  */
40
41
  export declare const isEligible: import("convex/server").RegisteredQuery<"public", {
41
42
  channel: string;
@@ -1 +1 @@
1
- {"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../../src/component/queries.ts"],"names":[],"mappings":"AAgBA;;;;;;GAMG;AACH,eAAO,MAAM,YAAY;;;;;;;;UAwBvB,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,aAAa;;;;;;;;;UAqBxB,CAAC;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU;;;;;oBA0CrB,CAAC"}
1
+ {"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../../src/component/queries.ts"],"names":[],"mappings":"AAgBA;;;;;;GAMG;AACH,eAAO,MAAM,YAAY;;;;;;;;UAwBvB,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,aAAa;;;;;;;;;UAqBxB,CAAC;AAEH;;;;;;;;GAQG;AACH,eAAO,MAAM,UAAU;;;;;oBAgDrB,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import { v } from "convex/values";
2
- import { query } from "./_generated/server";
3
- import { GLOBAL_CHANNEL } from "../shared";
4
- import { optInProofView, suppressionView } from "./validators";
2
+ import { query } from "./_generated/server.js";
3
+ import { GLOBAL_CHANNEL } from "../shared.js";
4
+ import { optInProofView, suppressionView } from "./validators.js";
5
5
  /** Project a stored suppression row to its public view (drops internal fields). */
6
6
  function view(row) {
7
7
  return {
@@ -70,7 +70,8 @@ export const getOptInProof = query({
70
70
  * `requireOptIn` is set — has a recorded opt-in proof for `listKey`. This is the
71
71
  * single call a sender makes before every send: `¬suppressed [∧ confirmed]`.
72
72
  * Suppression always blocks; the opt-in requirement is opt-in per call (marketing
73
- * mail sets it; a transactional send may not).
73
+ * mail sets it; a transactional send may not). An empty `contactHash` or
74
+ * `channel` answers `false` (fail closed).
74
75
  */
75
76
  export const isEligible = query({
76
77
  args: {
@@ -81,6 +82,12 @@ export const isEligible = query({
81
82
  },
82
83
  returns: v.boolean(),
83
84
  handler: async (ctx, args) => {
85
+ // Fail closed: an empty key can never match a suppression row, so answering
86
+ // "eligible" for it would be a silent fail-open. Reactive callers may pass
87
+ // placeholders while ids load, so answer "not eligible" instead of throwing.
88
+ if (args.contactHash === "" || args.channel === "") {
89
+ return false;
90
+ }
84
91
  const globalRow = await ctx.db
85
92
  .query("suppressions")
86
93
  .withIndex("by_hash_channel", (q) => q.eq("contactHash", args.contactHash).eq("channel", GLOBAL_CHANNEL))
@@ -1 +1 @@
1
- {"version":3,"file":"queries.js","sourceRoot":"","sources":["../../src/component/queries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAG/D,mFAAmF;AACnF,SAAS,IAAI,CAAC,GAAwB;IACpC,OAAO;QACL,WAAW,EAAE,GAAG,CAAC,WAAW;QAC5B,OAAO,EAAE,GAAG,CAAC,OAAO,KAAK,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO;QAC5D,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,SAAS,EAAE,GAAG,CAAC,SAAS;KACzB,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,CAAC;IAChC,IAAI,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE;IACtD,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC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AE,EAAE,CAClC,CAAC,CAAC,EAAE,CAAC,aAAa,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,CAClE;iBACA,MAAM,EAAE,CAAC;YACZ,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;gBACxB,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;QACD,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACtB,MAAM,KAAK,GAAG,MAAM,GAAG,CAAC,EAAE;iBACvB,KAAK,CAAC,aAAa,CAAC;iBACpB,SAAS,CAAC,cAAc,EAAE,CAAC,CAAC,EAAE,EAAE,CAC/B,CAAC,CAAC,EAAE,CAAC,aAAa,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,CAClE;iBACA,MAAM,EAAE,CAAC;YACZ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;gBACnB,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAC,CAAC"}
@@ -8,7 +8,7 @@
8
8
  * holds the host channel (`"email"`/`"sms"`/…) or the `GLOBAL_CHANNEL` sentinel
9
9
  * `"*"` for an all-channel suppression. `reason` is recorded for audit. Indexed
10
10
  * `by_hash_channel` (the exact-channel and global lookups an `isSuppressed` check
11
- * makes) and `by_hash` (every entry for a hash, for `unsuppress` and audit).
11
+ * makes).
12
12
  *
13
13
  * `optInProofs` is the legal evidence (not an authz relation): a `(contactHash,
14
14
  * listKey)` record of a confirmed opt-in. `listKey` scopes it to one list/purpose
@@ -28,7 +28,6 @@ declare const _default: import("convex/server").SchemaDefinition<{
28
28
  reason: import("convex/values").VUnion<"bounce" | "complaint" | "global" | "manual" | "unsubscribe", [import("convex/values").VLiteral<"unsubscribe", "required">, import("convex/values").VLiteral<"bounce", "required">, import("convex/values").VLiteral<"complaint", "required">, import("convex/values").VLiteral<"manual", "required">, import("convex/values").VLiteral<"global", "required">], "required", never>;
29
29
  createdAt: import("convex/values").VFloat64<number, "required">;
30
30
  }, "required", "channel" | "contactHash" | "createdAt" | "reason">, {
31
- by_hash: ["contactHash", "_creationTime"];
32
31
  by_hash_channel: ["contactHash", "channel", "_creationTime"];
33
32
  }, {}, {}>;
34
33
  optInProofs: import("convex/server").TableDefinition<import("convex/values").VObject<{
@@ -1,6 +1,6 @@
1
1
  import { defineSchema, defineTable } from "convex/server";
2
2
  import { v } from "convex/values";
3
- import { jsonValue, suppressionReason } from "./validators";
3
+ import { jsonValue, suppressionReason } from "./validators.js";
4
4
  /**
5
5
  * Two sandboxed tables — the do-not-contact gate's own concern.
6
6
  *
@@ -11,7 +11,7 @@ import { jsonValue, suppressionReason } from "./validators";
11
11
  * holds the host channel (`"email"`/`"sms"`/…) or the `GLOBAL_CHANNEL` sentinel
12
12
  * `"*"` for an all-channel suppression. `reason` is recorded for audit. Indexed
13
13
  * `by_hash_channel` (the exact-channel and global lookups an `isSuppressed` check
14
- * makes) and `by_hash` (every entry for a hash, for `unsuppress` and audit).
14
+ * makes).
15
15
  *
16
16
  * `optInProofs` is the legal evidence (not an authz relation): a `(contactHash,
17
17
  * listKey)` record of a confirmed opt-in. `listKey` scopes it to one list/purpose
@@ -26,7 +26,6 @@ export default defineSchema({
26
26
  reason: suppressionReason,
27
27
  createdAt: v.number(),
28
28
  })
29
- .index("by_hash", ["contactHash"])
30
29
  .index("by_hash_channel", ["contactHash", "channel"]),
31
30
  optInProofs: defineTable({
32
31
  contactHash: v.string(),
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/component/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM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AAC;SACC,KAAK,CAAC,iBAAiB,EAAE,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;IAEvD,WAAW,EAAE,WAAW,CAAC;QACvB,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;QACvB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;QACnB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;QAClB,KAAK,EAAE,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC;QAC5B,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;KACxB,CAAC,CAAC,KAAK,CAAC,cAAc,EAAE,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;CACrD,CAAC,CAAC"}
@@ -47,4 +47,11 @@ export declare const optInProofView: import("convex/values").VObject<{
47
47
  proof: import("convex/values").VAny<any, "optional", string>;
48
48
  confirmedAt: import("convex/values").VFloat64<number, "required">;
49
49
  }, "required", "confirmedAt" | "contactHash" | "listKey" | "proof" | "source" | `proof.${string}`>;
50
+ /**
51
+ * Reject an empty key. The host hashes contacts, so a real `contactHash`,
52
+ * `channel`, or `listKey` is never `""`; an empty one means an upstream bug
53
+ * (an unset value passed through) and must not become a row or a silent
54
+ * "not suppressed" answer. Throws `ConvexError({ code: "INVALID_ARGUMENT", field })`.
55
+ */
56
+ export declare function assertNonEmpty(field: string, value: string): void;
50
57
  //# sourceMappingURL=validators.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/component/validators.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,SAAS,uDAAU,CAAC;AAEjC,0EAA0E;AAC1E,eAAO,MAAM,iBAAiB,mZAM7B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe;;;;;;;;;;kEAK1B,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,cAAc;;;;;;;;;;;;kGAMzB,CAAC"}
1
+ {"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/component/validators.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,SAAS,uDAAU,CAAC;AAEjC,0EAA0E;AAC1E,eAAO,MAAM,iBAAiB,mZAM7B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe;;;;;;;;;;kEAK1B,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,cAAc;;;;;;;;;;;;kGAMzB,CAAC;AAEH;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAIjE"}
@@ -1,4 +1,4 @@
1
- import { v } from "convex/values";
1
+ import { ConvexError, v } from "convex/values";
2
2
  /**
3
3
  * Opaque host-owned legal evidence attached to an opt-in proof — e.g. the IP,
4
4
  * user-agent, double-opt-in token ref, or form snapshot the host captured at
@@ -37,4 +37,15 @@ export const optInProofView = v.object({
37
37
  proof: v.optional(jsonValue),
38
38
  confirmedAt: v.number(),
39
39
  });
40
+ /**
41
+ * Reject an empty key. The host hashes contacts, so a real `contactHash`,
42
+ * `channel`, or `listKey` is never `""`; an empty one means an upstream bug
43
+ * (an unset value passed through) and must not become a row or a silent
44
+ * "not suppressed" answer. Throws `ConvexError({ code: "INVALID_ARGUMENT", field })`.
45
+ */
46
+ export function assertNonEmpty(field, value) {
47
+ if (value === "") {
48
+ throw new ConvexError({ code: "INVALID_ARGUMENT", field });
49
+ }
50
+ }
40
51
  //# sourceMappingURL=validators.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"validators.js","sourceRoot":"","sources":["../../src/component/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAElC;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;AAEjC,0EAA0E;AAC1E,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CACt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
8
+ | ------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
9
+ | `@vllnt/convex-suppression` | `Suppression<TProof>` class; types `SuppressionComponent`, `SuppressionOptions`, `SuppressOptions`, `RecordOptInOptions`, `IsEligibleOptions`, `SuppressionView`, `OptInProofView`, `SuppressionReason`, `Parser` |
10
+ | `@vllnt/convex-suppression/convex.config` | default export: the component definition for `app.use(...)` (also `./convex.config.js`) |
11
+ | `@vllnt/convex-suppression/test` | `register(t, name = "suppression")` for `convex-test` (TypeScript source; needs `convex-test` and Vite's `import.meta.glob`) |
12
+ | `@vllnt/convex-suppression/_generated/component` | type-only `ComponentApi` from Convex codegen (also `./_generated/component.js`) |
13
+
14
+ Construct the client with the mounted component and an optional host proof
15
+ validator:
16
+
17
+ ```ts
18
+ import { Suppression } from "@vllnt/convex-suppression";
19
+
20
+ const dnc = new Suppression<{ ip: string }>(components.suppression, {
21
+ proofValidator: (value) => {
22
+ if (
23
+ typeof value !== "object" ||
24
+ value === null ||
25
+ !("ip" in value) ||
26
+ typeof value.ip !== "string"
27
+ ) {
28
+ throw new Error("Expected an ip string");
29
+ }
30
+ return { ip: value.ip };
31
+ },
32
+ });
33
+ ```
34
+
35
+ `Suppression<TProof = unknown>` is generic over the host's opaque opt-in `proof`
36
+ type. All methods take the host `ctx` (a query or mutation context) as the first
37
+ argument and the host's opaque `contactHash` (`hash(normalize(contact))`) as the
38
+ second — the component never sees a raw email/phone.
39
+
40
+ **Hash-keyed.** The host hashes and normalizes the contact, owns the salt
41
+ policy, and keeps the raw ↔ hash mapping. A suppression survives erasure of the
42
+ subject because it is keyed only by the hash.
43
+
44
+ **Channel & list defaults.** Omitting `channel` targets a global (all-channel)
45
+ suppression; omitting `listKey` targets a global opt-in. Internally these map to
46
+ a `"*"` sentinel. Channel-specific suppression checks include the global row,
47
+ but list-specific proof reads are exact: global proof is not a fallback for a
48
+ named list.
49
+
50
+ **Time is server-sourced.** Every handler stamps `createdAt`/`confirmedAt` from
51
+ `Date.now()` itself; no method accepts a caller-supplied clock.
52
+
53
+ **Validation.** When `proofValidator` is set it runs at the client boundary:
54
+ over the `proof` written by `recordOptIn` (before storage) and over the `proof`
55
+ returned by `getOptInProof` (on read). It must return the typed value or throw.
56
+ Omit it to leave the opaque evidence unvalidated.
57
+
58
+ ## Mutations
59
+
60
+ ### `suppress(ctx, contactHash, reason, opts?) → null`
61
+
62
+ `reason` is `"unsubscribe" | "bounce" | "complaint" | "manual" | "global"`.
63
+ `opts`: `{ channel?: string }`.
64
+
65
+ Add `(contactHash, channel)` to the do-not-contact list. `opts.channel` scopes
66
+ the suppression to one channel (`"email"`/`"sms"`/…); omit it for a global
67
+ all-channel suppression. `reason` is recorded for audit and never changes the
68
+ effect (a suppressed hash is suppressed regardless of why). `createdAt` is
69
+ server-stamped.
70
+
71
+ **Idempotent** on `(contactHash, channel)`: re-suppressing an existing entry
72
+ updates its `reason` and refreshes `createdAt` rather than inserting a
73
+ duplicate, so a replayed bounce/complaint webhook can never fan the table out.
74
+
75
+ ### `unsuppress(ctx, contactHash, channel?) → boolean`
76
+
77
+ Remove `(contactHash, channel)` from the do-not-contact list — a rare, audited
78
+ re-subscribe. Omit `channel` to clear the global entry; clearing a global row
79
+ does not clear per-channel rows and vice versa. Returns `true` if an entry was
80
+ removed, `false` if none matched (a no-op unsuppress is not an error).
81
+
82
+ ### `recordOptIn(ctx, contactHash, opts) → null`
83
+
84
+ `opts`: `{ listKey?: string; source: string; proof?: TProof }`.
85
+
86
+ Record an opt-in proof for `(contactHash, listKey)` — the legal evidence of a
87
+ confirmed opt-in for one list/purpose. `opts.listKey` scopes the proof to one
88
+ list; omit it for a global opt-in. `opts.source` tags how it was captured
89
+ (`"double-opt-in"`, `"checkbox"`, …); `opts.proof` is opaque host evidence
90
+ validated against `proofValidator` before storage. `confirmedAt` is
91
+ server-stamped.
92
+
93
+ **Idempotent** on `(contactHash, listKey)`: a second confirmation updates
94
+ `source`, `proof`, and `confirmedAt` rather than inserting a duplicate. This is
95
+ a latest-proof store, not an append-only audit ledger; it does not remove any
96
+ suppression.
97
+
98
+ ## Queries
99
+
100
+ ### `isSuppressed(ctx, contactHash, channel?) → SuppressionView | null`
101
+
102
+ The matching suppression for `(contactHash, channel)`, or `null` if the contact
103
+ is not suppressed on that channel. A `channel` argument matches a global
104
+ (all-channel) suppression OR a channel-specific one — a global tombstone wins.
105
+ Omit `channel` to check the global entry only. `SuppressionView` is
106
+ `{ contactHash, channel, reason, createdAt }`; `channel` is `null` for a global
107
+ entry.
108
+
109
+ ### `getOptInProof(ctx, contactHash, listKey?) → OptInProofView | null`
110
+
111
+ The opt-in proof for `(contactHash, listKey)`, or `null` if none is recorded.
112
+ Omit `listKey` for a global opt-in. `OptInProofView` is
113
+ `{ contactHash, listKey, source, proof?, confirmedAt }`; `listKey` is `null` for
114
+ a global opt-in and `proof` is narrowed by the host validator when set.
115
+
116
+ ### `isEligible(ctx, contactHash, opts?) → boolean`
117
+
118
+ `opts`: `{ channel?: string; listKey?: string; requireOptIn?: boolean }`
119
+ (defaults: global channel/list, `requireOptIn = false`).
120
+
121
+ The send gate. Returns `true` when the contact may be contacted: NOT suppressed
122
+ on `opts.channel` (global or channel-specific) AND — when `opts.requireOptIn` is
123
+ set — holding a recorded opt-in proof for `opts.listKey`. Suppression always
124
+ blocks; the opt-in requirement is per call. This is the single call a sender
125
+ makes before every send (`¬suppressed [∧ confirmed]`).
126
+
127
+ ## Error codes
128
+
129
+ Operations are otherwise total: a missing suppression / opt-in is a `null` or
130
+ `false` return, an unsuppress of an unknown address is a no-op `false`, and a
131
+ re-suppress / re-opt-in is an idempotent update rather than a conflict. Invalid
132
+ `reason` values are rejected by the `args` validator before the handler runs; an
133
+ opt-in `proof` failing the host `proofValidator` throws the host's own error at
134
+ the client boundary, never a component error code.
135
+
136
+ The component throws one coded `ConvexError`, with `data` of the form
137
+ `{ code, field }`:
138
+
139
+ | Code | Thrown by | When |
140
+ | ------------------ | ---------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
141
+ | `INVALID_ARGUMENT` | `suppress`, `recordOptIn` (via the client too) | `field` is an empty string: `contactHash`/`channel` (suppress), `contactHash`/`listKey`/`source` (recordOptIn). |
142
+
143
+ `isEligible` answers `false` for an empty `contactHash` or `channel` (it never
144
+ throws this error), so the send gate fails closed. `isSuppressed`,
145
+ `getOptInProof`, and `unsuppress` never throw this error (`unsuppress` returns
146
+ `false` when nothing matches).
147
+
148
+ ## Key matching
149
+
150
+ `contactHash`, `channel`, and `listKey` are matched exactly (case- and
151
+ whitespace-sensitive); the component applies no normalization, trimming, or
152
+ plus-address folding. The host must normalize and hash contacts, and use one
153
+ canonical spelling per channel and list (for example always `"email"`, never
154
+ `"Email"`), because `"Email"` is a different channel from `"email"`. There is no
155
+ expiry: a suppression lasts until `unsuppress`.
156
+
157
+ ## Cron / Maintenance
158
+
159
+ None. Suppressions and opt-in proofs have no automatic expiry or retention
160
+ sweep. `unsuppress` deletes only an exact suppression row, not its opt-in proof.
161
+ Proofs are retained indefinitely and replaced by `recordOptIn`; no public
162
+ proof-delete API is provided. Hashes and opaque proof may still be personal
163
+ data. The host owns legal basis, data minimization, retention obligations, and
164
+ verification of consent.
package/llms.txt ADDED
@@ -0,0 +1,35 @@
1
+ # @vllnt/convex-suppression
2
+
3
+ > Do-not-contact suppression list + opt-in proof (GDPR/CAN-SPAM), hash-keyed and channel-aware, as a Convex component
4
+
5
+ `@vllnt/convex-suppression` is a publishable Convex component. It targets `convex@^1.45.0`.
6
+ It stores two sandboxed tables: `suppressions` (a `(contactHash, channel)` anti-membership tombstone with a `reason` of `unsubscribe`/`bounce`/`complaint`/`manual`/`global` and a `createdAt` server timestamp) and `optInProofs` (a `(contactHash, listKey)` record of a confirmed opt-in with a `source`, opaque host `proof`, and a `confirmedAt` server timestamp). The component is keyed by a host-supplied `contactHash` (`hash(normalize(email|phone))`) rather than a raw contact (opaque proof can still contain personal data), so a "do not contact" tombstone survives erasure of the subject — the GDPR crux. A sender calls `isEligible(contactHash, { channel?, listKey?, requireOptIn? })` before every send (`¬suppressed [∧ confirmed]`); an unsubscribe/bounce/complaint calls `suppress(contactHash, reason, { channel? })`; a confirmed double opt-in calls `recordOptIn(contactHash, { listKey?, source, proof? })`; rare re-subscribes call `unsuppress`. A suppression with no channel is a global all-channel tombstone (stored under a `"*"` sentinel) that matches every channel; a channel entry matches only itself. Writes are idempotent on their key tuple (a replayed webhook updates in place, never duplicates). Suppression is explicitly the residue that is NOT a membership — a subscriber list is a flat membership edge or host data, modeled elsewhere. Time is read from the server clock inside every handler — no caller-supplied clock. The host owns the raw contact, the hashing + salt policy, auth, and the opt-in `proof` type (the client is generic over it, with an optional `proofValidator` parser narrowing the opaque stored value at the boundary — never a `v.any()` dump); the component owns only the hash-keyed do-not-contact gate. Mount-safe: it runs correctly under multiple named `app.use` mounts (e.g. a separate marketing vs. transactional list).
7
+
8
+ Omitting channel checks only global suppression; named-channel checks include it. Opt-in proof uses exact list keys without global fallback and does not clear suppression. No TTL/cron exists: suppression persists until unsuppress, proof persists and is replaced by recordOptIn with no public deletion method. Hashes are not necessarily anonymous; legal compliance is host-owned. Host parsers are `(unknown) => T`, not `v.*.parse`.
9
+
10
+ ## For coding agents
11
+
12
+ The docs are bundled in the package at `node_modules/@vllnt/convex-suppression/docs/` (with `README.md`, `CHANGELOG.md`, this `llms.txt` and the TypeScript source in `src/`). They match the installed version. Read them before writing code. Links below that start with `./` point to those bundled files; GitHub links follow `main`.
13
+
14
+ ## Docs
15
+
16
+ - [README](./README.md): Project overview, installation, usage examples, limitations
17
+ - [API Reference](./docs/API.md): Package exports, client methods, return shapes, error codes
18
+ - [Changelog](./CHANGELOG.md): Version history and release notes
19
+ - [Contributing](https://github.com/vllnt/convex-suppression/blob/main/CONTRIBUTING.md): Development setup, validation commands, release workflow
20
+
21
+ ## Examples
22
+
23
+ - [Example component wrapper](https://github.com/vllnt/convex-suppression/blob/main/example/convex/example.ts): Host-app wrapper functions
24
+ - [Example tests](https://github.com/vllnt/convex-suppression/blob/main/example/convex/example.test.ts): End-to-end usage coverage with `convex-test`
25
+
26
+ ## Ecosystem
27
+
28
+ - [vllnt oss](https://oss.vllnt.com/llms.txt): Index of every @vllnt package
29
+
30
+ ## Optional
31
+
32
+ - [AGENTS](https://github.com/vllnt/convex-suppression/blob/main/AGENTS.md): Agent instructions for contributors to this repository
33
+ - [Security Policy](https://github.com/vllnt/convex-suppression/blob/main/SECURITY.md): Vulnerability reporting policy
34
+ - [Code of Conduct](https://github.com/vllnt/convex-suppression/blob/main/CODE_OF_CONDUCT.md): Community participation guidelines
35
+ - [License](./LICENSE): MIT license
package/package.json CHANGED
@@ -1,13 +1,18 @@
1
1
  {
2
2
  "name": "@vllnt/convex-suppression",
3
- "version": "0.1.0",
3
+ "version": "0.1.1-canary.5677f98",
4
4
  "description": "Do-not-contact suppression list + opt-in proof (GDPR/CAN-SPAM), hash-keyed and channel-aware, as a Convex component",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
- "packageManager": "pnpm@9.15.4",
7
+ "packageManager": "pnpm@10.34.9",
8
8
  "files": [
9
9
  "dist",
10
- "src"
10
+ "src",
11
+ "docs/*.md",
12
+ "CHANGELOG.md",
13
+ "llms.txt",
14
+ "!src/**/*.test.*",
15
+ "!src/**/*.spec.*"
11
16
  ],
12
17
  "exports": {
13
18
  "./package.json": "./package.json",
@@ -37,17 +42,14 @@
37
42
  "build": "tsc --project ./tsconfig.build.json",
38
43
  "build:codegen": "pnpm codegen && pnpm build",
39
44
  "build:clean": "rm -rf dist *.tsbuildinfo && pnpm build:codegen",
40
- "typecheck": "tsc --noEmit",
41
- "typecheck:ci": "tsc --noEmit --project tsconfig.ci.json",
42
- "lint": "pnpm check:agents && eslint .",
45
+ "typecheck": "tsc --noEmit --incremental --tsBuildInfoFile node_modules/.cache/tsc/typecheck.tsbuildinfo",
46
+ "typecheck:ci": "tsc --noEmit --incremental --tsBuildInfoFile node_modules/.cache/tsc/typecheck-ci.tsbuildinfo --project tsconfig.ci.json",
47
+ "lint": "pnpm check:agents && eslint --cache --cache-location node_modules/.cache/eslint/ .",
43
48
  "test": "vitest run --passWithNoTests",
44
49
  "test:watch": "vitest --typecheck --clearScreen false",
45
50
  "test:coverage": "vitest run --coverage --coverage.reporter=text",
46
51
  "generate:llms": "node scripts/generate-llms.mjs",
47
52
  "preversion": "pnpm install --frozen-lockfile && pnpm build && pnpm test:coverage && pnpm typecheck && pnpm generate:llms",
48
- "prepublishOnly": "npm whoami || npm login",
49
- "alpha": "npm version prerelease --preid alpha && npm publish --tag alpha && git push --follow-tags",
50
- "release": "npm version patch && npm publish && git push --follow-tags",
51
53
  "check:agents": "node -e \"const f=require('node:fs');if(!f.existsSync('AGENTS.md')||f.existsSync('CLAUDE.md')||f.existsSync('.claude'))process.exit(1)\"",
52
54
  "codegen": "pnpm convex codegen --component-dir ./src/component"
53
55
  },
@@ -57,18 +59,18 @@
57
59
  "devDependencies": {
58
60
  "@edge-runtime/vm": "^5.0.0",
59
61
  "@typescript/native": "npm:typescript@7.0.2",
60
- "@vitest/coverage-v8": "^4.1.11",
61
- "@vllnt/eslint-config": "2.0.0",
62
- "@vllnt/typescript": "2.0.0",
63
- "convex": "^1.45.0",
64
- "convex-test": "^0.0.56",
65
- "eslint": "^9.39.5",
66
- "prettier": "^3.9.6",
62
+ "@vitest/coverage-v8": "^5.1.1",
63
+ "@vllnt/eslint-config": "2.1.0",
64
+ "@vllnt/typescript": "3.0.0",
65
+ "convex": "^1.51.0",
66
+ "convex-test": "^0.0.73",
67
+ "eslint": "^10.15.0",
68
+ "prettier": "^3.10.1",
67
69
  "typescript": "npm:@typescript/typescript6@^6.0.2",
68
- "vite": "^8.2.2",
69
- "vitest": "^4.1.11"
70
+ "vite": "^8.3.8",
71
+ "vitest": "^5.1.1"
70
72
  },
71
- "homepage": "https://github.com/vllnt/convex-suppression#readme",
73
+ "homepage": "https://oss.vllnt.com/packages/convex-suppression",
72
74
  "bugs": {
73
75
  "url": "https://github.com/vllnt/convex-suppression/issues"
74
76
  },
@@ -100,5 +102,19 @@
100
102
  "gdpr",
101
103
  "can-spam",
102
104
  "opt-in"
103
- ]
105
+ ],
106
+ "pnpm": {
107
+ "overrides": {
108
+ "minimatch@>=7.0.0 <11.0.1": "11.0.9",
109
+ "deepmerge-ts@<8.0.0": "8.0.2",
110
+ "handlebars": "4.7.10"
111
+ },
112
+ "minimumReleaseAge": 10080,
113
+ "minimumReleaseAgeExclude": [
114
+ "@vllnt/*"
115
+ ],
116
+ "ignoredBuiltDependencies": [
117
+ "esbuild"
118
+ ]
119
+ }
104
120
  }
@@ -112,7 +112,7 @@ interface RunMutationCtx {
112
112
  * @example
113
113
  * ```ts
114
114
  * const dnc = new Suppression(components.suppression, {
115
- * proofValidator: v.object({ ip: v.string() }).parse,
115
+ * proofValidator: (value) => parseIpProof(value), // host parser: (unknown) => TProof
116
116
  * });
117
117
  * // a webhook suppresses on complaint:
118
118
  * await dnc.suppress(ctx, contactHash, "complaint", { channel: "email" });
@@ -10,9 +10,10 @@ export type SuppressionReason =
10
10
 
11
11
  /**
12
12
  * Validates and narrows opaque host opt-in evidence to a host type `T` at the
13
- * client boundary. Receives the raw value the component returned (`unknown`) and
14
- * MUST return a typed `T` or throw. A `convex/values` validator's `.parse` (or a
15
- * Zod `.parse`) fits directly; omit it to keep the value unvalidated.
13
+ * client boundary. Receives the opaque value (`unknown`) on write before storage
14
+ * and on read after the component returns it, and MUST return a typed `T` or
15
+ * throw. A Zod `.parse` fits directly; `convex/values` validators have no
16
+ * `.parse`. Omit it to keep the value unvalidated.
16
17
  *
17
18
  * @typeParam T - The host's stored opt-in `proof` type.
18
19
  */
@@ -1,6 +1,6 @@
1
1
  import { v } from "convex/values";
2
- import { mutation } from "./_generated/server";
3
- import { jsonValue, suppressionReason } from "./validators";
2
+ import { mutation } from "./_generated/server.js";
3
+ import { assertNonEmpty, jsonValue, suppressionReason } from "./validators.js";
4
4
 
5
5
  /**
6
6
  * Suppress a `(contactHash, channel)` — add it to the do-not-contact list. The
@@ -14,7 +14,8 @@ import { jsonValue, suppressionReason } from "./validators";
14
14
  * its `reason` and refreshes `createdAt` rather than inserting a duplicate, so a
15
15
  * replayed bounce/complaint webhook can never fan the table out. `createdAt` is
16
16
  * stamped from the server clock (`Date.now()` inside the handler — never
17
- * caller-supplied).
17
+ * caller-supplied). An empty `contactHash` or `channel` throws
18
+ * `INVALID_ARGUMENT`.
18
19
  */
19
20
  export const suppress = mutation({
20
21
  args: {
@@ -24,6 +25,8 @@ export const suppress = mutation({
24
25
  },
25
26
  returns: v.null(),
26
27
  handler: async (ctx, args) => {
28
+ assertNonEmpty("contactHash", args.contactHash);
29
+ assertNonEmpty("channel", args.channel);
27
30
  const existing = await ctx.db
28
31
  .query("suppressions")
29
32
  .withIndex("by_hash_channel", (q) =>
@@ -32,7 +35,10 @@ export const suppress = mutation({
32
35
  .unique();
33
36
  const now = Date.now();
34
37
  if (existing !== null) {
35
- await ctx.db.patch("suppressions", existing._id, { reason: args.reason, createdAt: now });
38
+ await ctx.db.patch("suppressions", existing._id, {
39
+ reason: args.reason,
40
+ createdAt: now,
41
+ });
36
42
  return null;
37
43
  }
38
44
  await ctx.db.insert("suppressions", {
@@ -80,7 +86,8 @@ export const unsuppress = mutation({
80
86
  *
81
87
  * Idempotent on `(contactHash, listKey)`: a second confirmation updates `source`,
82
88
  * `proof`, and `confirmedAt` rather than inserting a duplicate. `confirmedAt` is
83
- * server-sourced.
89
+ * server-sourced. An empty `contactHash`, `listKey`, or `source` throws
90
+ * `INVALID_ARGUMENT`.
84
91
  */
85
92
  export const recordOptIn = mutation({
86
93
  args: {
@@ -91,6 +98,9 @@ export const recordOptIn = mutation({
91
98
  },
92
99
  returns: v.null(),
93
100
  handler: async (ctx, args) => {
101
+ assertNonEmpty("contactHash", args.contactHash);
102
+ assertNonEmpty("listKey", args.listKey);
103
+ assertNonEmpty("source", args.source);
94
104
  const existing = await ctx.db
95
105
  .query("optInProofs")
96
106
  .withIndex("by_hash_list", (q) =>
@@ -1,8 +1,8 @@
1
1
  import { v } from "convex/values";
2
- import { query } from "./_generated/server";
3
- import { GLOBAL_CHANNEL } from "../shared";
4
- import { optInProofView, suppressionView } from "./validators";
5
- import type { Doc } from "./_generated/dataModel";
2
+ import { query } from "./_generated/server.js";
3
+ import { GLOBAL_CHANNEL } from "../shared.js";
4
+ import { optInProofView, suppressionView } from "./validators.js";
5
+ import type { Doc } from "./_generated/dataModel.js";
6
6
 
7
7
  /** Project a stored suppression row to its public view (drops internal fields). */
8
8
  function view(row: Doc<"suppressions">) {
@@ -81,7 +81,8 @@ export const getOptInProof = query({
81
81
  * `requireOptIn` is set — has a recorded opt-in proof for `listKey`. This is the
82
82
  * single call a sender makes before every send: `¬suppressed [∧ confirmed]`.
83
83
  * Suppression always blocks; the opt-in requirement is opt-in per call (marketing
84
- * mail sets it; a transactional send may not).
84
+ * mail sets it; a transactional send may not). An empty `contactHash` or
85
+ * `channel` answers `false` (fail closed).
85
86
  */
86
87
  export const isEligible = query({
87
88
  args: {
@@ -92,6 +93,12 @@ export const isEligible = query({
92
93
  },
93
94
  returns: v.boolean(),
94
95
  handler: async (ctx, args) => {
96
+ // Fail closed: an empty key can never match a suppression row, so answering
97
+ // "eligible" for it would be a silent fail-open. Reactive callers may pass
98
+ // placeholders while ids load, so answer "not eligible" instead of throwing.
99
+ if (args.contactHash === "" || args.channel === "") {
100
+ return false;
101
+ }
95
102
  const globalRow = await ctx.db
96
103
  .query("suppressions")
97
104
  .withIndex("by_hash_channel", (q) =>
@@ -1,6 +1,6 @@
1
1
  import { defineSchema, defineTable } from "convex/server";
2
2
  import { v } from "convex/values";
3
- import { jsonValue, suppressionReason } from "./validators";
3
+ import { jsonValue, suppressionReason } from "./validators.js";
4
4
 
5
5
  /**
6
6
  * Two sandboxed tables — the do-not-contact gate's own concern.
@@ -12,7 +12,7 @@ import { jsonValue, suppressionReason } from "./validators";
12
12
  * holds the host channel (`"email"`/`"sms"`/…) or the `GLOBAL_CHANNEL` sentinel
13
13
  * `"*"` for an all-channel suppression. `reason` is recorded for audit. Indexed
14
14
  * `by_hash_channel` (the exact-channel and global lookups an `isSuppressed` check
15
- * makes) and `by_hash` (every entry for a hash, for `unsuppress` and audit).
15
+ * makes).
16
16
  *
17
17
  * `optInProofs` is the legal evidence (not an authz relation): a `(contactHash,
18
18
  * listKey)` record of a confirmed opt-in. `listKey` scopes it to one list/purpose
@@ -27,7 +27,6 @@ export default defineSchema({
27
27
  reason: suppressionReason,
28
28
  createdAt: v.number(),
29
29
  })
30
- .index("by_hash", ["contactHash"])
31
30
  .index("by_hash_channel", ["contactHash", "channel"]),
32
31
 
33
32
  optInProofs: defineTable({
@@ -1,4 +1,4 @@
1
- import { v } from "convex/values";
1
+ import { ConvexError, v } from "convex/values";
2
2
 
3
3
  /**
4
4
  * Opaque host-owned legal evidence attached to an opt-in proof — e.g. the IP,
@@ -47,3 +47,15 @@ export const optInProofView = v.object({
47
47
  proof: v.optional(jsonValue),
48
48
  confirmedAt: v.number(),
49
49
  });
50
+
51
+ /**
52
+ * Reject an empty key. The host hashes contacts, so a real `contactHash`,
53
+ * `channel`, or `listKey` is never `""`; an empty one means an upstream bug
54
+ * (an unset value passed through) and must not become a row or a silent
55
+ * "not suppressed" answer. Throws `ConvexError({ code: "INVALID_ARGUMENT", field })`.
56
+ */
57
+ export function assertNonEmpty(field: string, value: string): void {
58
+ if (value === "") {
59
+ throw new ConvexError({ code: "INVALID_ARGUMENT", field });
60
+ }
61
+ }
package/src/test.ts CHANGED
@@ -1,5 +1,6 @@
1
+ /// <reference types="vite/client" />
1
2
  import type { TestConvex } from "convex-test";
2
- import schema from "./component/schema";
3
+ import schema from "./component/schema.js";
3
4
 
4
5
  const modules = import.meta.glob("./component/**/*.ts");
5
6