@vllnt/convex-suppression 0.1.0 → 0.1.1-canary.054f7dd
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +140 -46
- package/dist/component/mutations.d.ts +4 -2
- package/dist/component/mutations.d.ts.map +1 -1
- package/dist/component/mutations.js +15 -5
- package/dist/component/mutations.js.map +1 -1
- package/dist/component/queries.d.ts +2 -1
- package/dist/component/queries.d.ts.map +1 -1
- package/dist/component/queries.js +11 -4
- package/dist/component/queries.js.map +1 -1
- package/dist/component/schema.js +1 -1
- package/dist/component/schema.js.map +1 -1
- package/dist/component/validators.d.ts +7 -0
- package/dist/component/validators.d.ts.map +1 -1
- package/dist/component/validators.js +12 -1
- package/dist/component/validators.js.map +1 -1
- package/package.json +25 -15
- package/src/component/mutations.ts +15 -5
- package/src/component/queries.ts +12 -5
- package/src/component/schema.ts +1 -1
- package/src/component/validators.ts +13 -1
- package/src/test.ts +2 -1
package/README.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<!-- Badges -->
|
|
2
|
+
|
|
2
3
|
[](https://www.convex.dev/components)
|
|
3
4
|
[](https://www.npmjs.com/package/@vllnt/convex-suppression)
|
|
4
5
|
[](https://github.com/vllnt/convex-suppression/actions/workflows/ci.yml)
|
|
@@ -16,30 +17,47 @@ 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
|
|
20
|
-
|
|
21
|
-
|
|
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`,
|
|
26
|
-
|
|
27
|
-
- **
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
- **
|
|
31
|
-
|
|
32
|
-
- **
|
|
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.
|
|
51
|
+
Peer dependency: `convex@^1.45.0`. This README follows `main`; the `canary`
|
|
52
|
+
dist-tag carries pre-release builds (pin an exact canary version for
|
|
53
|
+
reproducible installs).
|
|
54
|
+
|
|
55
|
+
## Quick start
|
|
41
56
|
|
|
42
|
-
|
|
57
|
+
After mounting, run `pnpm exec convex dev` to generate `components.suppression`.
|
|
58
|
+
These internal functions accept a contact hash from trusted server code. The
|
|
59
|
+
host must normalize and hash contacts consistently, authenticate webhooks, and
|
|
60
|
+
verify opt-in before calling them.
|
|
43
61
|
|
|
44
62
|
```ts
|
|
45
63
|
// convex/convex.config.ts
|
|
@@ -54,61 +72,110 @@ export default app;
|
|
|
54
72
|
```ts
|
|
55
73
|
// convex/email.ts — host owns auth + hashing; pass an opaque contactHash in.
|
|
56
74
|
import { components } from "./_generated/api";
|
|
57
|
-
import {
|
|
75
|
+
import { internalMutation, internalQuery } from "./_generated/server";
|
|
58
76
|
import { v } from "convex/values";
|
|
59
77
|
import { Suppression } from "@vllnt/convex-suppression";
|
|
60
78
|
|
|
61
79
|
const dnc = new Suppression<{ ip: string }>(components.suppression, {
|
|
62
|
-
proofValidator:
|
|
80
|
+
proofValidator: (value) => {
|
|
81
|
+
if (
|
|
82
|
+
typeof value !== "object" ||
|
|
83
|
+
value === null ||
|
|
84
|
+
!("ip" in value) ||
|
|
85
|
+
typeof value.ip !== "string"
|
|
86
|
+
) {
|
|
87
|
+
throw new Error("Expected an ip string");
|
|
88
|
+
}
|
|
89
|
+
return { ip: value.ip };
|
|
90
|
+
},
|
|
63
91
|
});
|
|
64
|
-
const hash = (email: string) => myHash(email.trim().toLowerCase()); // host's hashing + salt policy
|
|
65
92
|
|
|
66
93
|
// The send gate — call before every send.
|
|
67
|
-
export const canEmail =
|
|
68
|
-
args: {
|
|
69
|
-
handler: (ctx, {
|
|
70
|
-
dnc.isEligible(ctx,
|
|
94
|
+
export const canEmail = internalQuery({
|
|
95
|
+
args: { contactHash: v.string() },
|
|
96
|
+
handler: (ctx, { contactHash }) =>
|
|
97
|
+
dnc.isEligible(ctx, contactHash, {
|
|
98
|
+
channel: "email",
|
|
99
|
+
listKey: "newsletter",
|
|
100
|
+
requireOptIn: true,
|
|
101
|
+
}),
|
|
71
102
|
});
|
|
72
103
|
|
|
73
104
|
// A provider webhook suppresses on complaint; a confirmed double opt-in records proof.
|
|
74
|
-
export const onComplaint =
|
|
75
|
-
args: {
|
|
76
|
-
handler: (ctx, {
|
|
105
|
+
export const onComplaint = internalMutation({
|
|
106
|
+
args: { contactHash: v.string() },
|
|
107
|
+
handler: (ctx, { contactHash }) =>
|
|
108
|
+
dnc.suppress(ctx, contactHash, "complaint", { channel: "email" }),
|
|
77
109
|
});
|
|
78
|
-
export const confirmOptIn =
|
|
79
|
-
args: {
|
|
80
|
-
handler: (ctx, {
|
|
81
|
-
dnc.recordOptIn(ctx,
|
|
110
|
+
export const confirmOptIn = internalMutation({
|
|
111
|
+
args: { contactHash: v.string(), ip: v.string() },
|
|
112
|
+
handler: (ctx, { contactHash, ip }) =>
|
|
113
|
+
dnc.recordOptIn(ctx, contactHash, {
|
|
114
|
+
listKey: "newsletter",
|
|
115
|
+
source: "double-opt-in",
|
|
116
|
+
proof: { ip },
|
|
117
|
+
}),
|
|
82
118
|
});
|
|
83
119
|
```
|
|
84
120
|
|
|
85
|
-
Client options: `new Suppression(component, { proofValidator? })`. Omitting
|
|
121
|
+
Client options: `new Suppression(component, { proofValidator? })`. Omitting
|
|
122
|
+
`channel`/`listKey` targets the global entry.
|
|
86
123
|
|
|
87
124
|
## API Reference
|
|
88
125
|
|
|
89
|
-
| Method
|
|
90
|
-
|
|
126
|
+
| Method | Kind | Result |
|
|
127
|
+
| ------------------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------- |
|
|
91
128
|
| `suppress(ctx, contactHash, reason, opts?)` | mutation | `null` (`reason`: `"unsubscribe" \| "bounce" \| "complaint" \| "manual" \| "global"`; `opts`: `{ channel? }`) |
|
|
92
|
-
| `unsuppress(ctx, contactHash, channel?)`
|
|
93
|
-
| `recordOptIn(ctx, contactHash, opts)`
|
|
94
|
-
| `isSuppressed(ctx, contactHash, channel?)`
|
|
95
|
-
| `getOptInProof(ctx, contactHash, listKey?)` | query
|
|
96
|
-
| `isEligible(ctx, contactHash, opts?)`
|
|
129
|
+
| `unsuppress(ctx, contactHash, channel?)` | mutation | `boolean` (`true` if an entry was removed) |
|
|
130
|
+
| `recordOptIn(ctx, contactHash, opts)` | mutation | `null` (`opts`: `{ listKey?; source; proof? }`) |
|
|
131
|
+
| `isSuppressed(ctx, contactHash, channel?)` | query | `SuppressionView \| null` |
|
|
132
|
+
| `getOptInProof(ctx, contactHash, listKey?)` | query | `OptInProofView \| null` |
|
|
133
|
+
| `isEligible(ctx, contactHash, opts?)` | query | `boolean` (`opts`: `{ channel?; listKey?; requireOptIn? }`) |
|
|
97
134
|
|
|
98
135
|
Full reference: [docs/API.md](docs/API.md).
|
|
99
136
|
|
|
100
|
-
##
|
|
137
|
+
## Options and limitations
|
|
138
|
+
|
|
139
|
+
- The only constructor option is `proofValidator`, a parser
|
|
140
|
+
`(unknown) => TProof`, not `v.*.parse`.
|
|
141
|
+
- A channel-specific check first checks the global `"*"` suppression. Omitting
|
|
142
|
+
`channel` checks only the global row, not all channel rows. Always pass the
|
|
143
|
+
send's channel.
|
|
144
|
+
- Opt-in uses an exact `listKey` match: global proof is not a fallback for a
|
|
145
|
+
named list. `recordOptIn` does not remove suppression; `unsuppress` removes
|
|
146
|
+
only the exact channel/global row.
|
|
147
|
+
- No TTL, pruning, or cron exists. Suppressions remain until `unsuppress`;
|
|
148
|
+
opt-in proofs remain and are overwritten on re-recording, with no public
|
|
149
|
+
delete method.
|
|
150
|
+
- Keys are matched exactly: `contactHash`, `channel`, and `listKey` are case-
|
|
151
|
+
and whitespace-sensitive, with no trimming or plus-address folding. Normalize
|
|
152
|
+
them consistently in the host (`"Email"` is not `"email"`).
|
|
153
|
+
- Writes with an empty `contactHash`/`channel`/`listKey`/`source` throw
|
|
154
|
+
`INVALID_ARGUMENT`; `isEligible` answers `false` for an empty `contactHash` or
|
|
155
|
+
`channel`, so the gate fails closed.
|
|
156
|
+
- Hashing is host-owned and does not make data automatically anonymous. Proof
|
|
157
|
+
may contain personal data; minimize it and choose a compliant retention
|
|
158
|
+
policy. This package is not a legal-compliance guarantee.
|
|
159
|
+
- Mount separately with `app.use(suppression, { name: "marketingDnc" })` and
|
|
160
|
+
`new Suppression(components.marketingDnc)`.
|
|
161
|
+
|
|
162
|
+
## Integrations
|
|
101
163
|
|
|
102
164
|
Backend-only — no `./react` entry. The consumer surface is a server-side
|
|
103
|
-
`isEligible` gate and webhook-driven `suppress` writes; a reactive
|
|
104
|
-
badge, if ever needed, is an ordinary `useQuery` over the host's
|
|
105
|
-
`isSuppressed` ref.
|
|
165
|
+
`isEligible` gate and webhook-driven `suppress` writes; a reactive
|
|
166
|
+
do-not-contact badge, if ever needed, is an ordinary `useQuery` over the host's
|
|
167
|
+
re-exported `isSuppressed` ref.
|
|
106
168
|
|
|
107
169
|
## Security
|
|
108
170
|
|
|
109
|
-
- **Auth-agnostic** — the host authenticates the caller, decides who may
|
|
110
|
-
|
|
111
|
-
|
|
171
|
+
- **Auth-agnostic** — the host authenticates the caller, decides who may
|
|
172
|
+
suppress/query a hash, and passes an opaque `contactHash`; tables are
|
|
173
|
+
sandboxed.
|
|
174
|
+
- **Hash-keyed, never raw PII** — the host hashes and normalizes the contact and
|
|
175
|
+
owns the salt policy; a suppression survives erasure of the subject.
|
|
176
|
+
- **Server-sourced time** — `createdAt`/`confirmedAt` come from `Date.now()` in
|
|
177
|
+
each handler, never the caller; the opt-in `proof` is opaque, narrowed by the
|
|
178
|
+
host validator.
|
|
112
179
|
|
|
113
180
|
See [docs/API.md](docs/API.md).
|
|
114
181
|
|
|
@@ -119,7 +186,32 @@ pnpm test # single run
|
|
|
119
186
|
pnpm test:coverage # enforced 100% on covered files
|
|
120
187
|
```
|
|
121
188
|
|
|
122
|
-
Tests run against the real component runtime via `convex-test`
|
|
189
|
+
Tests run against the real component runtime via `convex-test`
|
|
190
|
+
(`@edge-runtime/vm`), not mocks.
|
|
191
|
+
|
|
192
|
+
### Testing your app
|
|
193
|
+
|
|
194
|
+
`@vllnt/convex-suppression/test` exports `register(t, name = "suppression")` to
|
|
195
|
+
mount the component in a `convex-test` instance. It needs `convex-test` and
|
|
196
|
+
`vitest` (with Vite's `import.meta.glob`) in the consuming app:
|
|
197
|
+
|
|
198
|
+
```ts
|
|
199
|
+
/// <reference types="vite/client" />
|
|
200
|
+
import { convexTest } from "convex-test";
|
|
201
|
+
import { register } from "@vllnt/convex-suppression/test";
|
|
202
|
+
import schema from "./schema";
|
|
203
|
+
|
|
204
|
+
const t = convexTest(schema, import.meta.glob("./**/*.ts"));
|
|
205
|
+
register(t);
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## Documentation
|
|
209
|
+
|
|
210
|
+
`llms.txt` is the maintained discovery index. `pnpm generate:llms` checks its
|
|
211
|
+
heading and local links without generating a source bundle.
|
|
212
|
+
|
|
213
|
+
[API reference](docs/API.md) · [LLM index](llms.txt) ·
|
|
214
|
+
[Security policy](SECURITY.md)
|
|
123
215
|
|
|
124
216
|
## Contributing
|
|
125
217
|
|
|
@@ -127,9 +219,11 @@ See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
|
127
219
|
|
|
128
220
|
## Author
|
|
129
221
|
|
|
130
|
-
Built by [bntvllnt](https://github.com/bntvllnt) ·
|
|
222
|
+
Built by [bntvllnt](https://github.com/bntvllnt) ·
|
|
223
|
+
[bntvllnt.com](https://bntvllnt.com) · [X @bntvllnt](https://x.com/bntvllnt)
|
|
131
224
|
|
|
132
|
-
Part of the [@vllnt](https://github.com/vllnt) Convex component fleet —
|
|
225
|
+
Part of the [@vllnt](https://github.com/vllnt) Convex component fleet —
|
|
226
|
+
[vllnt.com](https://vllnt.com)
|
|
133
227
|
|
|
134
228
|
If this is useful, [sponsor the work](https://github.com/sponsors/bntvllnt).
|
|
135
229
|
|
|
@@ -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
|
|
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, {
|
|
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":"mutations.js","sourceRoot":"","sources":["../../src/component/mutations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"mutations.js","sourceRoot":"","sources":["../../src/component/mutations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAE/E;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,QAAQ,CAAC;IAC/B,IAAI,EAAE;QACJ,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;QACvB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;QACnB,MAAM,EAAE,iBAAiB;KAC1B;IACD,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE;IACjB,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QAC3B,cAAc,CAAC,aAAa,EAAE,IAAI,CAAC,WAAW,CAAC,CAA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AAE,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
|
|
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,
|
|
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,wBAAwB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGlE,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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gBACnB,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAC,CAAC"}
|
package/dist/component/schema.js
CHANGED
|
@@ -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
|
*
|
|
@@ -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,
|
|
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,iBAAiB,CAAC;AAE/D;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAe,YAAY,CAAC;IAC1B,YAAY,EAAE,WAAW,CAAC;QACxB,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;QACvB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;QACnB,MAAM,EAAE,iBAAiB;QACzB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;KACtB,CAAC;SACC,KAAK,CAAC,SAAS,EAAE,CAAC,aAAa,CAAC,CAAC;SACjC,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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AM,EAAE;CACxB,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,KAAa,EAAE,KAAa;IACzD,IAAI,KAAK,KAAK,EAAE,EAAE,CAAC;QACjB,MAAM,IAAI,WAAW,CAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,KAAK,EAAE,CAAC,CAAC;IAC7D,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vllnt/convex-suppression",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1-canary.054f7dd",
|
|
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@
|
|
7
|
+
"packageManager": "pnpm@10.34.8",
|
|
8
8
|
"files": [
|
|
9
9
|
"dist",
|
|
10
10
|
"src"
|
|
@@ -37,17 +37,14 @@
|
|
|
37
37
|
"build": "tsc --project ./tsconfig.build.json",
|
|
38
38
|
"build:codegen": "pnpm codegen && pnpm build",
|
|
39
39
|
"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 .",
|
|
40
|
+
"typecheck": "tsc --noEmit --incremental --tsBuildInfoFile node_modules/.cache/tsc/typecheck.tsbuildinfo",
|
|
41
|
+
"typecheck:ci": "tsc --noEmit --incremental --tsBuildInfoFile node_modules/.cache/tsc/typecheck-ci.tsbuildinfo --project tsconfig.ci.json",
|
|
42
|
+
"lint": "pnpm check:agents && eslint --cache --cache-location node_modules/.cache/eslint/ .",
|
|
43
43
|
"test": "vitest run --passWithNoTests",
|
|
44
44
|
"test:watch": "vitest --typecheck --clearScreen false",
|
|
45
45
|
"test:coverage": "vitest run --coverage --coverage.reporter=text",
|
|
46
46
|
"generate:llms": "node scripts/generate-llms.mjs",
|
|
47
47
|
"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
48
|
"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
49
|
"codegen": "pnpm convex codegen --component-dir ./src/component"
|
|
53
50
|
},
|
|
@@ -57,16 +54,16 @@
|
|
|
57
54
|
"devDependencies": {
|
|
58
55
|
"@edge-runtime/vm": "^5.0.0",
|
|
59
56
|
"@typescript/native": "npm:typescript@7.0.2",
|
|
60
|
-
"@vitest/coverage-v8": "^
|
|
57
|
+
"@vitest/coverage-v8": "^5.0.5",
|
|
61
58
|
"@vllnt/eslint-config": "2.0.0",
|
|
62
59
|
"@vllnt/typescript": "2.0.0",
|
|
63
|
-
"convex": "^1.
|
|
64
|
-
"convex-test": "^0.0.
|
|
60
|
+
"convex": "^1.48.0",
|
|
61
|
+
"convex-test": "^0.0.65",
|
|
65
62
|
"eslint": "^9.39.5",
|
|
66
|
-
"prettier": "^3.9.
|
|
63
|
+
"prettier": "^3.9.10",
|
|
67
64
|
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
68
|
-
"vite": "^8.
|
|
69
|
-
"vitest": "^
|
|
65
|
+
"vite": "^8.3.5",
|
|
66
|
+
"vitest": "^5.0.5"
|
|
70
67
|
},
|
|
71
68
|
"homepage": "https://github.com/vllnt/convex-suppression#readme",
|
|
72
69
|
"bugs": {
|
|
@@ -100,5 +97,18 @@
|
|
|
100
97
|
"gdpr",
|
|
101
98
|
"can-spam",
|
|
102
99
|
"opt-in"
|
|
103
|
-
]
|
|
100
|
+
],
|
|
101
|
+
"pnpm": {
|
|
102
|
+
"overrides": {
|
|
103
|
+
"deepmerge-ts@<8.0.0": "8.0.2",
|
|
104
|
+
"handlebars": "4.7.10"
|
|
105
|
+
},
|
|
106
|
+
"minimumReleaseAge": 10080,
|
|
107
|
+
"minimumReleaseAgeExclude": [
|
|
108
|
+
"@vllnt/*"
|
|
109
|
+
],
|
|
110
|
+
"ignoredBuiltDependencies": [
|
|
111
|
+
"esbuild"
|
|
112
|
+
]
|
|
113
|
+
}
|
|
104
114
|
}
|
|
@@ -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, {
|
|
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) =>
|
package/src/component/queries.ts
CHANGED
|
@@ -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) =>
|
package/src/component/schema.ts
CHANGED
|
@@ -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.
|
|
@@ -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
|
+
}
|