@vllnt/convex-suppression 0.1.1-canary.a84a8a2 → 0.2.0-canary.4bb2fbc
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 +12 -1
- package/README.md +12 -3
- package/dist/client/index.d.ts +15 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +15 -1
- package/dist/client/index.js.map +1 -1
- package/dist/component/mutations.d.ts +18 -4
- package/dist/component/mutations.d.ts.map +1 -1
- package/dist/component/mutations.js +25 -10
- package/dist/component/mutations.js.map +1 -1
- package/dist/component/validators.d.ts +14 -5
- package/dist/component/validators.d.ts.map +1 -1
- package/dist/component/validators.js +29 -7
- package/dist/component/validators.js.map +1 -1
- package/docs/API.md +22 -10
- package/llms.txt +3 -1
- package/package.json +1 -1
- package/src/client/index.ts +15 -1
- package/src/component/mutations.ts +25 -10
- package/src/component/validators.ts +35 -7
package/CHANGELOG.md
CHANGED
|
@@ -4,7 +4,7 @@ All notable changes to this project are documented here. The format is based on
|
|
|
4
4
|
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project
|
|
5
5
|
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
-
## [0.
|
|
7
|
+
## [0.2.0] - Unreleased
|
|
8
8
|
|
|
9
9
|
### Added
|
|
10
10
|
|
|
@@ -16,6 +16,17 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
|
16
16
|
|
|
17
17
|
### Changed
|
|
18
18
|
|
|
19
|
+
- **Breaking:** `suppress` and `recordOptIn` now throw
|
|
20
|
+
`ConvexError({ code: "INVALID_ARGUMENT", field })` for a `contactHash`,
|
|
21
|
+
`channel`, `listKey` or `source` over 256 UTF-8 bytes, and for an opt-in
|
|
22
|
+
`proof` over 16384 UTF-8 bytes of its JSON form (`field: "proof"`). Sizes
|
|
23
|
+
count UTF-8 bytes, not characters: `"é"` is 2 bytes. Hash and normalize each
|
|
24
|
+
contact to a short fixed-length key such as a hex SHA-256 (64 bytes), keep
|
|
25
|
+
`proof` small, and store large evidence in the host and pass a reference.
|
|
26
|
+
Rows stored earlier with longer keys stay readable through `isSuppressed`,
|
|
27
|
+
`isEligible` and `getOptInProof`; `suppress` or `recordOptIn` on such a key
|
|
28
|
+
now throws and leaves the row unchanged; `unsuppress` is not size-checked and
|
|
29
|
+
still removes it.
|
|
19
30
|
- Removed the `by_hash` index; it was unused and a prefix of `by_hash_channel`.
|
|
20
31
|
One less index entry written per suppression and less index storage. No
|
|
21
32
|
migration is needed; the next deploy drops the index.
|
package/README.md
CHANGED
|
@@ -330,7 +330,7 @@ read `error.data.code` and `error.data.field`.
|
|
|
330
330
|
|
|
331
331
|
| Code or message | Thrown by | Cause | Fix |
|
|
332
332
|
| -------------------------------------- | ----------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
|
|
333
|
-
| `INVALID_ARGUMENT` | `suppress`, `recordOptIn` | `field` names
|
|
333
|
+
| `INVALID_ARGUMENT` | `suppress`, `recordOptIn` | `field` names a key that is empty or longer than 256 UTF-8 bytes: `contactHash` or `channel` (`suppress`); `contactHash`, `listKey` or `source` (`recordOptIn`). Or `field` is `proof`, over 16384 UTF-8 bytes of its JSON form (`recordOptIn`) | Check the value before calling. Omit `channel` or `listKey` for the global entry instead of passing `""`. Hash contacts to a short fixed-length key (a hex SHA-256 is 64 bytes); store large proof evidence in your app and pass a reference |
|
|
334
334
|
| Convex argument validation error | any method | An argument has the wrong type, or `reason` is not one of the five `SuppressionReason` values | Pass a `SuppressionReason`; TypeScript catches this at compile time |
|
|
335
335
|
| The error your `proofValidator` throws | `recordOptIn` (before the write), `getOptInProof` (on read) | Your parser rejected `proof`. From `recordOptIn` it is a synchronous throw, not a rejected promise: a try/catch around the call catches it (with or without `await`), and a `.catch()` on the returned promise never runs | Fix the proof, or let the parser accept every shape you have stored before |
|
|
336
336
|
|
|
@@ -371,10 +371,19 @@ returns that entry if one exists, otherwise `null`). `getOptInProof` returns
|
|
|
371
371
|
- An empty `contactHash` or `channel` makes `isEligible` return `false`. For
|
|
372
372
|
`isSuppressed`, an empty `contactHash` returns `null` (not suppressed), and an
|
|
373
373
|
empty `channel` checks only the global entry. Use `isEligible` as the gate.
|
|
374
|
+
- Keys (`contactHash`, `channel`, `listKey`, `source`) are at most 256 UTF-8
|
|
375
|
+
bytes, and `proof` is at most 16384 UTF-8 bytes of its JSON form
|
|
376
|
+
(`JSON.stringify(convexToJson(proof))`). Sizes count bytes, not characters:
|
|
377
|
+
`"é"` is 2 bytes. A larger value makes `suppress` or `recordOptIn` throw
|
|
378
|
+
`INVALID_ARGUMENT` and write nothing.
|
|
379
|
+
- Rows stored by a version before 0.2.0 with a key over 256 UTF-8 bytes stay
|
|
380
|
+
readable through `isSuppressed`, `isEligible` and `getOptInProof`.
|
|
381
|
+
`suppress` or `recordOptIn` on such a key throws and leaves the row
|
|
382
|
+
unchanged; `unsuppress` is not size-checked and still removes it.
|
|
374
383
|
- No expiry, TTL or cron. Entries stay until `unsuppress`; proofs stay until
|
|
375
384
|
replaced. There is no method to list entries, export them or delete a proof.
|
|
376
|
-
- `proof` is stored as any Convex value (no functions or class instances)
|
|
377
|
-
|
|
385
|
+
- `proof` is stored as any Convex value (no functions or class instances),
|
|
386
|
+
within the 16384-UTF-8-byte limit above. Hashes and proof can still be
|
|
378
387
|
personal data; store only what you need.
|
|
379
388
|
- Writes need a context with `runMutation` (a mutation or action); reads need
|
|
380
389
|
`runQuery` (a query, mutation or action).
|
package/dist/client/index.d.ts
CHANGED
|
@@ -105,12 +105,19 @@ export declare class Suppression<TProof = unknown> {
|
|
|
105
105
|
* `opts.channel` scopes the suppression to one channel; omit it for a global
|
|
106
106
|
* (all-channel) suppression. Idempotent on `(contactHash, channel)`. `reason` is
|
|
107
107
|
* recorded for audit.
|
|
108
|
+
*
|
|
109
|
+
* `contactHash` and `opts.channel` are each at most 256 UTF-8 bytes (pass a short
|
|
110
|
+
* fixed-length hash such as a hex SHA-256). An empty or longer key throws
|
|
111
|
+
* `ConvexError({ code: "INVALID_ARGUMENT", field })` and writes nothing, also for
|
|
112
|
+
* a longer key stored by an earlier version (remove that row with `unsuppress`).
|
|
108
113
|
*/
|
|
109
114
|
suppress(ctx: RunMutationCtx, contactHash: string, reason: SuppressionReason, opts?: SuppressOptions): Promise<null>;
|
|
110
115
|
/**
|
|
111
116
|
* Remove a `(contactHash, channel)` from the do-not-contact list (a rare,
|
|
112
117
|
* audited re-subscribe). Omit `channel` to clear the global entry. Returns `true`
|
|
113
|
-
* if an entry was removed, `false` if none matched.
|
|
118
|
+
* if an entry was removed, `false` if none matched. Keys are not size-checked,
|
|
119
|
+
* so a row stored by an earlier version with a key over 256 UTF-8 bytes can
|
|
120
|
+
* still be removed.
|
|
114
121
|
*/
|
|
115
122
|
unsuppress(ctx: RunMutationCtx, contactHash: string, channel?: string): Promise<boolean>;
|
|
116
123
|
/**
|
|
@@ -124,6 +131,13 @@ export declare class Suppression<TProof = unknown> {
|
|
|
124
131
|
* a confirmed opt-in. `opts.listKey` scopes the proof to one list; omit it for a
|
|
125
132
|
* global opt-in. `opts.proof` is opaque host evidence validated against
|
|
126
133
|
* `proofValidator` before storage. Idempotent on `(contactHash, listKey)`.
|
|
134
|
+
*
|
|
135
|
+
* `contactHash`, `opts.listKey` and `opts.source` are each at most 256 UTF-8
|
|
136
|
+
* bytes, and `opts.proof` is at most 16384 UTF-8 bytes of its JSON form
|
|
137
|
+
* (`JSON.stringify(convexToJson(proof))`); store large evidence in the host and
|
|
138
|
+
* pass a reference. An empty or longer key, or a larger proof, throws
|
|
139
|
+
* `ConvexError({ code: "INVALID_ARGUMENT", field })` (`field` is the key name or
|
|
140
|
+
* `"proof"`) and writes nothing.
|
|
127
141
|
*/
|
|
128
142
|
recordOptIn(ctx: RunMutationCtx, contactHash: string, opts: RecordOptInOptions<TProof>): Promise<null>;
|
|
129
143
|
/**
|
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AAE,iBAAiB,EACzB,IAAI,GAAE,eAAoB,GACzB,OAAO,CAAC,IAAI,CAAC,CAMf;IAED;;;;;;OAMG;IACH,UAAU,CACR,GAAG,EAAE,cAAc,EACnB,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,OAAO,CAAC,CAKlB;IAED;;;;OAIG;IACH,YAAY,CACV,GAAG,EAAE,WAAW,EAChB,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAKjC;IAED;;;;;;;;;;;;OAYG;IACH,WAAW,CACT,GAAG,EAAE,cAAc,EACnB,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,kBAAkB,CAAC,MAAM,CAAC,GAC/B,OAAO,CAAC,IAAI,CAAC,CAOf;IAED;;;;OAIG;IACG,aAAa,CACjB,GAAG,EAAE,WAAW,EAChB,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,CAexC;IAED;;;;;OAKG;IACH,UAAU,CACR,GAAG,EAAE,WAAW,EAChB,WAAW,EAAE,MAAM,EACnB,IAAI,GAAE,iBAAsB,GAC3B,OAAO,CAAC,OAAO,CAAC,CAOlB;CACF;AAED,YAAY,EACV,iBAAiB,EACjB,cAAc,EACd,MAAM,EACN,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,eAAe,GAChB,CAAC"}
|
package/dist/client/index.js
CHANGED
|
@@ -57,6 +57,11 @@ export class Suppression {
|
|
|
57
57
|
* `opts.channel` scopes the suppression to one channel; omit it for a global
|
|
58
58
|
* (all-channel) suppression. Idempotent on `(contactHash, channel)`. `reason` is
|
|
59
59
|
* recorded for audit.
|
|
60
|
+
*
|
|
61
|
+
* `contactHash` and `opts.channel` are each at most 256 UTF-8 bytes (pass a short
|
|
62
|
+
* fixed-length hash such as a hex SHA-256). An empty or longer key throws
|
|
63
|
+
* `ConvexError({ code: "INVALID_ARGUMENT", field })` and writes nothing, also for
|
|
64
|
+
* a longer key stored by an earlier version (remove that row with `unsuppress`).
|
|
60
65
|
*/
|
|
61
66
|
suppress(ctx, contactHash, reason, opts = {}) {
|
|
62
67
|
return ctx.runMutation(this.component.mutations.suppress, {
|
|
@@ -68,7 +73,9 @@ export class Suppression {
|
|
|
68
73
|
/**
|
|
69
74
|
* Remove a `(contactHash, channel)` from the do-not-contact list (a rare,
|
|
70
75
|
* audited re-subscribe). Omit `channel` to clear the global entry. Returns `true`
|
|
71
|
-
* if an entry was removed, `false` if none matched.
|
|
76
|
+
* if an entry was removed, `false` if none matched. Keys are not size-checked,
|
|
77
|
+
* so a row stored by an earlier version with a key over 256 UTF-8 bytes can
|
|
78
|
+
* still be removed.
|
|
72
79
|
*/
|
|
73
80
|
unsuppress(ctx, contactHash, channel) {
|
|
74
81
|
return ctx.runMutation(this.component.mutations.unsuppress, {
|
|
@@ -92,6 +99,13 @@ export class Suppression {
|
|
|
92
99
|
* a confirmed opt-in. `opts.listKey` scopes the proof to one list; omit it for a
|
|
93
100
|
* global opt-in. `opts.proof` is opaque host evidence validated against
|
|
94
101
|
* `proofValidator` before storage. Idempotent on `(contactHash, listKey)`.
|
|
102
|
+
*
|
|
103
|
+
* `contactHash`, `opts.listKey` and `opts.source` are each at most 256 UTF-8
|
|
104
|
+
* bytes, and `opts.proof` is at most 16384 UTF-8 bytes of its JSON form
|
|
105
|
+
* (`JSON.stringify(convexToJson(proof))`); store large evidence in the host and
|
|
106
|
+
* pass a reference. An empty or longer key, or a larger proof, throws
|
|
107
|
+
* `ConvexError({ code: "INVALID_ARGUMENT", field })` (`field` is the key name or
|
|
108
|
+
* `"proof"`) and writes nothing.
|
|
95
109
|
*/
|
|
96
110
|
recordOptIn(ctx, contactHash, opts) {
|
|
97
111
|
return ctx.runMutation(this.component.mutations.recordOptIn, {
|
package/dist/client/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAkF9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,OAAO,WAAW;IASH,SAAS;IARX,cAAc,CAA6B;IAE5D;;;;OAIG;IACH,YACmB,SAA+B,EAChD,OAAO,GAA+B,EAAE;yBADvB,SAAS;QAG1B,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;IAC/C,CAAC;IAED,gGAAgG;IACxF,KAAK,CAAC,KAAc;QAC1B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,IAAI,IAAI,CAAC,cAAc,KAAK,SAAS,EAAE,CAAC;YACtC,OAAO,KAAe,CAAC;QACzB,CAAC;QACD,OAAO,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;IAED
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAkF9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,OAAO,WAAW;IASH,SAAS;IARX,cAAc,CAA6B;IAE5D;;;;OAIG;IACH,YACmB,SAA+B,EAChD,OAAO,GAA+B,EAAE;yBADvB,SAAS;QAG1B,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;IAC/C,CAAC;IAED,gGAAgG;IACxF,KAAK,CAAC,KAAc;QAC1B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,IAAI,IAAI,CAAC,cAAc,KAAK,SAAS,EAAE,CAAC;YACtC,OAAO,KAAe,CAAC;QACzB,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AED;;;;OAIG;IACH,KAAK,CAAC,aAAa,CACjB,GAAgB,EAChB,WAAmB,EACnB,OAAgB;QAEhB,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,aAAa,EAAE;YACnE,WAAW;YACX,OAAO,EAAE,OAAO,IAAI,cAAc;SACnC,CAAC,CAAC;QACH,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;YACjB,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO;YACL,WAAW,EAAE,GAAG,CAAC,WAAW;YAC5B,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC;YAC5B,WAAW,EAAE,GAAG,CAAC,WAAW;SAC7B,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACH,UAAU,CACR,GAAgB,EAChB,WAAmB,EACnB,IAAI,GAAsB,EAAE;QAE5B,OAAO,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,EAAE;YACrD,WAAW;YACX,OAAO,EAAE,IAAI,CAAC,OAAO,IAAI,cAAc;YACvC,OAAO,EAAE,IAAI,CAAC,OAAO,IAAI,cAAc;YACvC,YAAY,EAAE,IAAI,CAAC,YAAY,IAAI,KAAK;SACzC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -10,8 +10,13 @@
|
|
|
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).
|
|
14
|
-
*
|
|
13
|
+
* caller-supplied).
|
|
14
|
+
*
|
|
15
|
+
* Limits: `contactHash` and `channel` are each at most 256 UTF-8 bytes (pass a
|
|
16
|
+
* short fixed-length hash such as a hex SHA-256). An empty or longer key throws
|
|
17
|
+
* `ConvexError({ code: "INVALID_ARGUMENT", field })` and writes nothing, also when
|
|
18
|
+
* the key matches a longer row stored by an earlier version (remove such a row
|
|
19
|
+
* with `unsuppress`, which is not size-checked).
|
|
15
20
|
*/
|
|
16
21
|
export declare const suppress: import("convex/server").RegisteredMutation<"public", {
|
|
17
22
|
channel: string;
|
|
@@ -24,6 +29,8 @@ export declare const suppress: import("convex/server").RegisteredMutation<"publi
|
|
|
24
29
|
* only the global row, not per-channel entries; removing a channel row clears only
|
|
25
30
|
* that channel. Returns `true` if an entry was removed, `false` if none matched (a
|
|
26
31
|
* no-op unsuppress of an address that was never suppressed is not an error).
|
|
32
|
+
* Keys are not size-checked, so a row stored by an earlier version with a key over
|
|
33
|
+
* the 256-UTF-8-byte limit can still be removed.
|
|
27
34
|
*/
|
|
28
35
|
export declare const unsuppress: import("convex/server").RegisteredMutation<"public", {
|
|
29
36
|
channel: string;
|
|
@@ -39,8 +46,15 @@ export declare const unsuppress: import("convex/server").RegisteredMutation<"pub
|
|
|
39
46
|
*
|
|
40
47
|
* Idempotent on `(contactHash, listKey)`: a second confirmation updates `source`,
|
|
41
48
|
* `proof`, and `confirmedAt` rather than inserting a duplicate. `confirmedAt` is
|
|
42
|
-
* server-sourced.
|
|
43
|
-
*
|
|
49
|
+
* server-sourced.
|
|
50
|
+
*
|
|
51
|
+
* Limits: `contactHash`, `listKey`, and `source` are each at most 256 UTF-8 bytes,
|
|
52
|
+
* and `proof` is at most 16384 UTF-8 bytes of its JSON form
|
|
53
|
+
* (`JSON.stringify(convexToJson(proof))`); store large evidence in the host and
|
|
54
|
+
* pass a reference. An empty or longer key, or a larger proof, throws
|
|
55
|
+
* `ConvexError({ code: "INVALID_ARGUMENT", field })` (`field` is the key name or
|
|
56
|
+
* `"proof"`) and writes nothing, also when the key matches a longer row stored by
|
|
57
|
+
* an earlier version (that row stays readable, unchanged).
|
|
44
58
|
*/
|
|
45
59
|
export declare const recordOptIn: import("convex/server").RegisteredMutation<"public", {
|
|
46
60
|
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;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,QAAQ;;;;iBAgCnB,CAAC;AAEH;;;;;;;;GAQG;AACH,eAAO,MAAM,UAAU;;;oBAgBrB,CAAC;AAEH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,WAAW;;;;;iBAqCtB,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { v } from "convex/values";
|
|
2
2
|
import { mutation } from "./_generated/server.js";
|
|
3
|
-
import {
|
|
3
|
+
import { assertKey, assertProofSize, 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,8 +13,13 @@ import { assertNonEmpty, jsonValue, suppressionReason } from "./validators.js";
|
|
|
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).
|
|
17
|
-
*
|
|
16
|
+
* caller-supplied).
|
|
17
|
+
*
|
|
18
|
+
* Limits: `contactHash` and `channel` are each at most 256 UTF-8 bytes (pass a
|
|
19
|
+
* short fixed-length hash such as a hex SHA-256). An empty or longer key throws
|
|
20
|
+
* `ConvexError({ code: "INVALID_ARGUMENT", field })` and writes nothing, also when
|
|
21
|
+
* the key matches a longer row stored by an earlier version (remove such a row
|
|
22
|
+
* with `unsuppress`, which is not size-checked).
|
|
18
23
|
*/
|
|
19
24
|
export const suppress = mutation({
|
|
20
25
|
args: {
|
|
@@ -24,8 +29,8 @@ export const suppress = mutation({
|
|
|
24
29
|
},
|
|
25
30
|
returns: v.null(),
|
|
26
31
|
handler: async (ctx, args) => {
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
assertKey("contactHash", args.contactHash);
|
|
33
|
+
assertKey("channel", args.channel);
|
|
29
34
|
const existing = await ctx.db
|
|
30
35
|
.query("suppressions")
|
|
31
36
|
.withIndex("by_hash_channel", (q) => q.eq("contactHash", args.contactHash).eq("channel", args.channel))
|
|
@@ -53,6 +58,8 @@ export const suppress = mutation({
|
|
|
53
58
|
* only the global row, not per-channel entries; removing a channel row clears only
|
|
54
59
|
* that channel. Returns `true` if an entry was removed, `false` if none matched (a
|
|
55
60
|
* no-op unsuppress of an address that was never suppressed is not an error).
|
|
61
|
+
* Keys are not size-checked, so a row stored by an earlier version with a key over
|
|
62
|
+
* the 256-UTF-8-byte limit can still be removed.
|
|
56
63
|
*/
|
|
57
64
|
export const unsuppress = mutation({
|
|
58
65
|
args: { contactHash: v.string(), channel: v.string() },
|
|
@@ -79,8 +86,15 @@ export const unsuppress = mutation({
|
|
|
79
86
|
*
|
|
80
87
|
* Idempotent on `(contactHash, listKey)`: a second confirmation updates `source`,
|
|
81
88
|
* `proof`, and `confirmedAt` rather than inserting a duplicate. `confirmedAt` is
|
|
82
|
-
* server-sourced.
|
|
83
|
-
*
|
|
89
|
+
* server-sourced.
|
|
90
|
+
*
|
|
91
|
+
* Limits: `contactHash`, `listKey`, and `source` are each at most 256 UTF-8 bytes,
|
|
92
|
+
* and `proof` is at most 16384 UTF-8 bytes of its JSON form
|
|
93
|
+
* (`JSON.stringify(convexToJson(proof))`); store large evidence in the host and
|
|
94
|
+
* pass a reference. An empty or longer key, or a larger proof, throws
|
|
95
|
+
* `ConvexError({ code: "INVALID_ARGUMENT", field })` (`field` is the key name or
|
|
96
|
+
* `"proof"`) and writes nothing, also when the key matches a longer row stored by
|
|
97
|
+
* an earlier version (that row stays readable, unchanged).
|
|
84
98
|
*/
|
|
85
99
|
export const recordOptIn = mutation({
|
|
86
100
|
args: {
|
|
@@ -91,9 +105,10 @@ export const recordOptIn = mutation({
|
|
|
91
105
|
},
|
|
92
106
|
returns: v.null(),
|
|
93
107
|
handler: async (ctx, args) => {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
108
|
+
assertKey("contactHash", args.contactHash);
|
|
109
|
+
assertKey("listKey", args.listKey);
|
|
110
|
+
assertKey("source", args.source);
|
|
111
|
+
assertProofSize(args.proof);
|
|
97
112
|
const existing = await ctx.db
|
|
98
113
|
.query("optInProofs")
|
|
99
114
|
.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,wBAAwB,CAAC;AAClD,OAAO,EAAE,
|
|
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,SAAS,EAAE,eAAe,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAE3F;;;;;;;;;;;;;;;;;;;GAmBG;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,OAA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AAC;QAC5B,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"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type Value } from "convex/values";
|
|
1
2
|
/**
|
|
2
3
|
* Opaque host-owned legal evidence attached to an opt-in proof — e.g. the IP,
|
|
3
4
|
* user-agent, double-opt-in token ref, or form snapshot the host captured at
|
|
@@ -48,10 +49,18 @@ export declare const optInProofView: import("convex/values").VObject<{
|
|
|
48
49
|
confirmedAt: import("convex/values").VFloat64<number, "required">;
|
|
49
50
|
}, "required", "confirmedAt" | "contactHash" | "listKey" | "proof" | "source" | `proof.${string}`>;
|
|
50
51
|
/**
|
|
51
|
-
* Reject an empty key. The host hashes contacts, so a real
|
|
52
|
-
* `channel`, or `listKey` is never `""`; an empty one means an
|
|
53
|
-
* (an unset value passed through) and must not become a row or a
|
|
54
|
-
* "not suppressed" answer.
|
|
52
|
+
* Reject an empty or oversized key. The host hashes contacts, so a real
|
|
53
|
+
* `contactHash`, `channel`, or `listKey` is never `""`; an empty one means an
|
|
54
|
+
* upstream bug (an unset value passed through) and must not become a row or a
|
|
55
|
+
* silent "not suppressed" answer. A key over 256 UTF-8 bytes is rejected to bound
|
|
56
|
+
* row size (a hex SHA-256 is 64 bytes). Throws
|
|
57
|
+
* `ConvexError({ code: "INVALID_ARGUMENT", field })`.
|
|
55
58
|
*/
|
|
56
|
-
export declare function
|
|
59
|
+
export declare function assertKey(field: string, value: string): void;
|
|
60
|
+
/**
|
|
61
|
+
* Reject an opt-in `proof` over 16384 UTF-8 bytes of its JSON form
|
|
62
|
+
* (`JSON.stringify(convexToJson(proof))`); an absent proof passes. Throws
|
|
63
|
+
* `ConvexError({ code: "INVALID_ARGUMENT", field: "proof" })`.
|
|
64
|
+
*/
|
|
65
|
+
export declare function assertProofSize(proof: Value | undefined): void;
|
|
57
66
|
//# sourceMappingURL=validators.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/component/validators.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/component/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgC,KAAK,KAAK,EAAE,MAAM,eAAe,CAAC;AAczE;;;;;;;;;;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;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAI5D;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,GAAG,IAAI,CAO9D"}
|
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import { ConvexError, v } from "convex/values";
|
|
1
|
+
import { ConvexError, convexToJson, v } from "convex/values";
|
|
2
|
+
/** Largest accepted key (`contactHash`/`channel`/`listKey`/`source`), in UTF-8 bytes. */
|
|
3
|
+
const MAX_KEY_BYTES = 256;
|
|
4
|
+
/** Largest accepted opt-in `proof`, in UTF-8 bytes of `JSON.stringify(convexToJson(proof))`. */
|
|
5
|
+
const MAX_PROOF_BYTES = 16384;
|
|
6
|
+
const utf8 = new TextEncoder();
|
|
7
|
+
/** The UTF-8 byte length of `value` (not its UTF-16 `.length`). */
|
|
8
|
+
function utf8Bytes(value) {
|
|
9
|
+
return utf8.encode(value).length;
|
|
10
|
+
}
|
|
2
11
|
/**
|
|
3
12
|
* Opaque host-owned legal evidence attached to an opt-in proof — e.g. the IP,
|
|
4
13
|
* user-agent, double-opt-in token ref, or form snapshot the host captured at
|
|
@@ -38,14 +47,27 @@ export const optInProofView = v.object({
|
|
|
38
47
|
confirmedAt: v.number(),
|
|
39
48
|
});
|
|
40
49
|
/**
|
|
41
|
-
* Reject an empty key. The host hashes contacts, so a real
|
|
42
|
-
* `channel`, or `listKey` is never `""`; an empty one means an
|
|
43
|
-
* (an unset value passed through) and must not become a row or a
|
|
44
|
-
* "not suppressed" answer.
|
|
50
|
+
* Reject an empty or oversized key. The host hashes contacts, so a real
|
|
51
|
+
* `contactHash`, `channel`, or `listKey` is never `""`; an empty one means an
|
|
52
|
+
* upstream bug (an unset value passed through) and must not become a row or a
|
|
53
|
+
* silent "not suppressed" answer. A key over 256 UTF-8 bytes is rejected to bound
|
|
54
|
+
* row size (a hex SHA-256 is 64 bytes). Throws
|
|
55
|
+
* `ConvexError({ code: "INVALID_ARGUMENT", field })`.
|
|
45
56
|
*/
|
|
46
|
-
export function
|
|
47
|
-
if (value === "") {
|
|
57
|
+
export function assertKey(field, value) {
|
|
58
|
+
if (value === "" || utf8Bytes(value) > MAX_KEY_BYTES) {
|
|
48
59
|
throw new ConvexError({ code: "INVALID_ARGUMENT", field });
|
|
49
60
|
}
|
|
50
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Reject an opt-in `proof` over 16384 UTF-8 bytes of its JSON form
|
|
64
|
+
* (`JSON.stringify(convexToJson(proof))`); an absent proof passes. Throws
|
|
65
|
+
* `ConvexError({ code: "INVALID_ARGUMENT", field: "proof" })`.
|
|
66
|
+
*/
|
|
67
|
+
export function assertProofSize(proof) {
|
|
68
|
+
if (proof !== undefined &&
|
|
69
|
+
utf8Bytes(JSON.stringify(convexToJson(proof))) > MAX_PROOF_BYTES) {
|
|
70
|
+
throw new ConvexError({ code: "INVALID_ARGUMENT", field: "proof" });
|
|
71
|
+
}
|
|
72
|
+
}
|
|
51
73
|
//# sourceMappingURL=validators.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../../src/component/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../../src/component/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,CAAC,EAAc,MAAM,eAAe,CAAC;AAEzE,yFAAyF;AACzF,MAAM,aAAa,GAAG,GAAG,CAAC;AAC1B,gGAAgG;AAChG,MAAM,eAAe,GAAG,KAAK,CAAC;AAE9B,MAAM,IAAI,GAAG,IAAI,WAAW,EAAE,CAAC;AAE/B,mEAAmE;AACnE,SAAS,SAAS,CAAC,KAAa;IAC9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AK,EAAE,IAAI,SAAS,CAAC,KAAK,CAAC,GAAG,aAAa,EAAE,CAAC;QACrD,MAAM,IAAI,WAAW,CAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,KAAK,EAAE,CAAC,CAAC;IAC7D,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,KAAwB;IACtD,IACE,KAAK,KAAK,SAAS;QACnB,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,eAAe,EAChE,CAAC;QACD,MAAM,IAAI,WAAW,CAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;IACtE,CAAC;AACH,CAAC"}
|
package/docs/API.md
CHANGED
|
@@ -89,7 +89,10 @@ replaces its `reason` and refreshes `createdAt` instead of inserting a second
|
|
|
89
89
|
row, so a replayed bounce or complaint webhook never adds rows.
|
|
90
90
|
|
|
91
91
|
Throws `INVALID_ARGUMENT` with `field` `contactHash` or `channel` when that
|
|
92
|
-
value is `""
|
|
92
|
+
value is `""` or longer than 256 UTF-8 bytes (bytes, not characters: `"é"` is
|
|
93
|
+
2 bytes). Pass a short fixed-length hash such as a hex SHA-256 (64 bytes). An
|
|
94
|
+
entry stored by an earlier version with a longer key stays readable, but
|
|
95
|
+
`suppress` on it throws and leaves it unchanged; remove it with `unsuppress`.
|
|
93
96
|
|
|
94
97
|
### `unsuppress`
|
|
95
98
|
|
|
@@ -99,7 +102,9 @@ Removes the exact `(contactHash, channel)` entry. Omit `channel` to remove the
|
|
|
99
102
|
global entry. Removing the global entry leaves channel entries, and removing a
|
|
100
103
|
channel entry leaves the global one. Returns `true` if an entry was removed and
|
|
101
104
|
`false` if none matched (including an empty `contactHash`); it never throws
|
|
102
|
-
`INVALID_ARGUMENT`.
|
|
105
|
+
`INVALID_ARGUMENT`. Keys are not size-checked, so it also removes an entry stored
|
|
106
|
+
by an earlier version with a key over 256 UTF-8 bytes. Opt-in proofs are not
|
|
107
|
+
touched.
|
|
103
108
|
|
|
104
109
|
### `isSuppressed`
|
|
105
110
|
|
|
@@ -133,10 +138,15 @@ latest proof, not a history. Recording again without `proof` removes the stored
|
|
|
133
138
|
proof. It does not remove any suppression.
|
|
134
139
|
|
|
135
140
|
`proof` is stored as any Convex value (`v.any()` in the component), so it must
|
|
136
|
-
be a Convex-serializable value
|
|
141
|
+
be a Convex-serializable value. It is limited to 16384 UTF-8 bytes of its JSON
|
|
142
|
+
form (`JSON.stringify(convexToJson(proof))`); store large evidence in your app
|
|
143
|
+
and pass a reference.
|
|
137
144
|
|
|
138
145
|
Throws `INVALID_ARGUMENT` with `field` `contactHash`, `listKey` or `source` when
|
|
139
|
-
that value is `""
|
|
146
|
+
that value is `""` or longer than 256 UTF-8 bytes, and with `field` `proof` when
|
|
147
|
+
`proof` is over 16384 UTF-8 bytes of its JSON form. A proof stored by an earlier
|
|
148
|
+
version with a longer key stays readable through `getOptInProof`, but
|
|
149
|
+
`recordOptIn` on that key throws and leaves it unchanged.
|
|
140
150
|
|
|
141
151
|
### `getOptInProof`
|
|
142
152
|
|
|
@@ -179,12 +189,14 @@ sentinel when omitted) and `requireOptIn` (default `false`).
|
|
|
179
189
|
|
|
180
190
|
### `SuppressOptions`
|
|
181
191
|
|
|
182
|
-
`{ channel?: string }`. Omit `channel` for a global entry
|
|
192
|
+
`{ channel?: string }`. Omit `channel` for a global entry; `channel` is at most
|
|
193
|
+
256 UTF-8 bytes.
|
|
183
194
|
|
|
184
195
|
### `RecordOptInOptions`
|
|
185
196
|
|
|
186
197
|
`{ listKey?: string; source: string; proof?: TProof }`. Omit `listKey` for a
|
|
187
|
-
global opt-in; `source` must not be `""`.
|
|
198
|
+
global opt-in; `source` must not be `""`. Each key is at most 256 UTF-8 bytes
|
|
199
|
+
and `proof` at most 16384 UTF-8 bytes of its JSON form.
|
|
188
200
|
|
|
189
201
|
### `IsEligibleOptions`
|
|
190
202
|
|
|
@@ -244,9 +256,9 @@ component, as used by the host's generated `components.suppression`.
|
|
|
244
256
|
The component throws one coded error, a `ConvexError` with `data` of the form
|
|
245
257
|
`{ code, field }`:
|
|
246
258
|
|
|
247
|
-
| Code | Thrown by | When
|
|
248
|
-
| ------------------ | ------------------------- |
|
|
249
|
-
| `INVALID_ARGUMENT` | `suppress`, `recordOptIn` | `field` is
|
|
259
|
+
| Code | Thrown by | When |
|
|
260
|
+
| ------------------ | ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
261
|
+
| `INVALID_ARGUMENT` | `suppress`, `recordOptIn` | `field` is empty or longer than 256 UTF-8 bytes: `contactHash` or `channel` (`suppress`); `contactHash`, `listKey` or `source` (`recordOptIn`). Or `field` is `proof`, over 16384 UTF-8 bytes of its JSON form (`recordOptIn`). |
|
|
250
262
|
|
|
251
263
|
Other failures are not component error codes:
|
|
252
264
|
|
|
@@ -268,7 +280,7 @@ Everything else is total: a missing entry or proof is `null` or `false`,
|
|
|
268
280
|
## Key matching
|
|
269
281
|
|
|
270
282
|
`contactHash`, `channel` and `listKey` are matched exactly (case- and
|
|
271
|
-
whitespace-sensitive). The component does no normalization, trimming or
|
|
283
|
+
whitespace-sensitive), and each written key is at most 256 UTF-8 bytes. The component does no normalization, trimming or
|
|
272
284
|
plus-address folding. Normalize and hash contacts the same way everywhere, and
|
|
273
285
|
use one spelling per channel and list (always `"email"`, never `"Email"`).
|
|
274
286
|
|
package/llms.txt
CHANGED
|
@@ -29,7 +29,9 @@ again without `proof`, and never removes a suppression. `unsuppress` removes one
|
|
|
29
29
|
exact entry. Keys match exactly (no trimming or case folding). The only error
|
|
30
30
|
code is `ConvexError` `data.code` `INVALID_ARGUMENT` (with `data.field`), thrown
|
|
31
31
|
by `suppress` and `recordOptIn` for an empty `contactHash`, `channel`, `listKey`
|
|
32
|
-
or `source
|
|
32
|
+
or `source`, for one of those keys over 256 UTF-8 bytes, and for a `proof` over
|
|
33
|
+
16384 UTF-8 bytes of its JSON form (`data.field` `proof`). Rows stored earlier
|
|
34
|
+
with longer keys stay readable; `unsuppress` still removes them. `proofValidator` is a host parser `(unknown) => TProof` (not
|
|
33
35
|
`v.*.parse`), run on write and on read. There is no TTL, cron, listing, export
|
|
34
36
|
or proof deletion, no auth (the host authorizes every call) and no React entry.
|
|
35
37
|
Mount it more than once (`app.use(suppression, { name })`) for separate lists.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vllnt/convex-suppression",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0-canary.4bb2fbc",
|
|
4
4
|
"description": "TypeScript Convex component for a do-not-contact suppression list (GDPR, CAN-SPAM): unsubscribes, bounces and complaints by contact hash, plus opt-in proof.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
package/src/client/index.ts
CHANGED
|
@@ -157,6 +157,11 @@ export class Suppression<TProof = unknown> {
|
|
|
157
157
|
* `opts.channel` scopes the suppression to one channel; omit it for a global
|
|
158
158
|
* (all-channel) suppression. Idempotent on `(contactHash, channel)`. `reason` is
|
|
159
159
|
* recorded for audit.
|
|
160
|
+
*
|
|
161
|
+
* `contactHash` and `opts.channel` are each at most 256 UTF-8 bytes (pass a short
|
|
162
|
+
* fixed-length hash such as a hex SHA-256). An empty or longer key throws
|
|
163
|
+
* `ConvexError({ code: "INVALID_ARGUMENT", field })` and writes nothing, also for
|
|
164
|
+
* a longer key stored by an earlier version (remove that row with `unsuppress`).
|
|
160
165
|
*/
|
|
161
166
|
suppress(
|
|
162
167
|
ctx: RunMutationCtx,
|
|
@@ -174,7 +179,9 @@ export class Suppression<TProof = unknown> {
|
|
|
174
179
|
/**
|
|
175
180
|
* Remove a `(contactHash, channel)` from the do-not-contact list (a rare,
|
|
176
181
|
* audited re-subscribe). Omit `channel` to clear the global entry. Returns `true`
|
|
177
|
-
* if an entry was removed, `false` if none matched.
|
|
182
|
+
* if an entry was removed, `false` if none matched. Keys are not size-checked,
|
|
183
|
+
* so a row stored by an earlier version with a key over 256 UTF-8 bytes can
|
|
184
|
+
* still be removed.
|
|
178
185
|
*/
|
|
179
186
|
unsuppress(
|
|
180
187
|
ctx: RunMutationCtx,
|
|
@@ -208,6 +215,13 @@ export class Suppression<TProof = unknown> {
|
|
|
208
215
|
* a confirmed opt-in. `opts.listKey` scopes the proof to one list; omit it for a
|
|
209
216
|
* global opt-in. `opts.proof` is opaque host evidence validated against
|
|
210
217
|
* `proofValidator` before storage. Idempotent on `(contactHash, listKey)`.
|
|
218
|
+
*
|
|
219
|
+
* `contactHash`, `opts.listKey` and `opts.source` are each at most 256 UTF-8
|
|
220
|
+
* bytes, and `opts.proof` is at most 16384 UTF-8 bytes of its JSON form
|
|
221
|
+
* (`JSON.stringify(convexToJson(proof))`); store large evidence in the host and
|
|
222
|
+
* pass a reference. An empty or longer key, or a larger proof, throws
|
|
223
|
+
* `ConvexError({ code: "INVALID_ARGUMENT", field })` (`field` is the key name or
|
|
224
|
+
* `"proof"`) and writes nothing.
|
|
211
225
|
*/
|
|
212
226
|
recordOptIn(
|
|
213
227
|
ctx: RunMutationCtx,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { v } from "convex/values";
|
|
2
2
|
import { mutation } from "./_generated/server.js";
|
|
3
|
-
import {
|
|
3
|
+
import { assertKey, assertProofSize, 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,8 +14,13 @@ import { assertNonEmpty, jsonValue, suppressionReason } from "./validators.js";
|
|
|
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).
|
|
18
|
-
*
|
|
17
|
+
* caller-supplied).
|
|
18
|
+
*
|
|
19
|
+
* Limits: `contactHash` and `channel` are each at most 256 UTF-8 bytes (pass a
|
|
20
|
+
* short fixed-length hash such as a hex SHA-256). An empty or longer key throws
|
|
21
|
+
* `ConvexError({ code: "INVALID_ARGUMENT", field })` and writes nothing, also when
|
|
22
|
+
* the key matches a longer row stored by an earlier version (remove such a row
|
|
23
|
+
* with `unsuppress`, which is not size-checked).
|
|
19
24
|
*/
|
|
20
25
|
export const suppress = mutation({
|
|
21
26
|
args: {
|
|
@@ -25,8 +30,8 @@ export const suppress = mutation({
|
|
|
25
30
|
},
|
|
26
31
|
returns: v.null(),
|
|
27
32
|
handler: async (ctx, args) => {
|
|
28
|
-
|
|
29
|
-
|
|
33
|
+
assertKey("contactHash", args.contactHash);
|
|
34
|
+
assertKey("channel", args.channel);
|
|
30
35
|
const existing = await ctx.db
|
|
31
36
|
.query("suppressions")
|
|
32
37
|
.withIndex("by_hash_channel", (q) =>
|
|
@@ -57,6 +62,8 @@ export const suppress = mutation({
|
|
|
57
62
|
* only the global row, not per-channel entries; removing a channel row clears only
|
|
58
63
|
* that channel. Returns `true` if an entry was removed, `false` if none matched (a
|
|
59
64
|
* no-op unsuppress of an address that was never suppressed is not an error).
|
|
65
|
+
* Keys are not size-checked, so a row stored by an earlier version with a key over
|
|
66
|
+
* the 256-UTF-8-byte limit can still be removed.
|
|
60
67
|
*/
|
|
61
68
|
export const unsuppress = mutation({
|
|
62
69
|
args: { contactHash: v.string(), channel: v.string() },
|
|
@@ -86,8 +93,15 @@ export const unsuppress = mutation({
|
|
|
86
93
|
*
|
|
87
94
|
* Idempotent on `(contactHash, listKey)`: a second confirmation updates `source`,
|
|
88
95
|
* `proof`, and `confirmedAt` rather than inserting a duplicate. `confirmedAt` is
|
|
89
|
-
* server-sourced.
|
|
90
|
-
*
|
|
96
|
+
* server-sourced.
|
|
97
|
+
*
|
|
98
|
+
* Limits: `contactHash`, `listKey`, and `source` are each at most 256 UTF-8 bytes,
|
|
99
|
+
* and `proof` is at most 16384 UTF-8 bytes of its JSON form
|
|
100
|
+
* (`JSON.stringify(convexToJson(proof))`); store large evidence in the host and
|
|
101
|
+
* pass a reference. An empty or longer key, or a larger proof, throws
|
|
102
|
+
* `ConvexError({ code: "INVALID_ARGUMENT", field })` (`field` is the key name or
|
|
103
|
+
* `"proof"`) and writes nothing, also when the key matches a longer row stored by
|
|
104
|
+
* an earlier version (that row stays readable, unchanged).
|
|
91
105
|
*/
|
|
92
106
|
export const recordOptIn = mutation({
|
|
93
107
|
args: {
|
|
@@ -98,9 +112,10 @@ export const recordOptIn = mutation({
|
|
|
98
112
|
},
|
|
99
113
|
returns: v.null(),
|
|
100
114
|
handler: async (ctx, args) => {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
115
|
+
assertKey("contactHash", args.contactHash);
|
|
116
|
+
assertKey("listKey", args.listKey);
|
|
117
|
+
assertKey("source", args.source);
|
|
118
|
+
assertProofSize(args.proof);
|
|
104
119
|
const existing = await ctx.db
|
|
105
120
|
.query("optInProofs")
|
|
106
121
|
.withIndex("by_hash_list", (q) =>
|
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
import { ConvexError, v } from "convex/values";
|
|
1
|
+
import { ConvexError, convexToJson, v, type Value } from "convex/values";
|
|
2
|
+
|
|
3
|
+
/** Largest accepted key (`contactHash`/`channel`/`listKey`/`source`), in UTF-8 bytes. */
|
|
4
|
+
const MAX_KEY_BYTES = 256;
|
|
5
|
+
/** Largest accepted opt-in `proof`, in UTF-8 bytes of `JSON.stringify(convexToJson(proof))`. */
|
|
6
|
+
const MAX_PROOF_BYTES = 16384;
|
|
7
|
+
|
|
8
|
+
const utf8 = new TextEncoder();
|
|
9
|
+
|
|
10
|
+
/** The UTF-8 byte length of `value` (not its UTF-16 `.length`). */
|
|
11
|
+
function utf8Bytes(value: string): number {
|
|
12
|
+
return utf8.encode(value).length;
|
|
13
|
+
}
|
|
2
14
|
|
|
3
15
|
/**
|
|
4
16
|
* Opaque host-owned legal evidence attached to an opt-in proof — e.g. the IP,
|
|
@@ -49,13 +61,29 @@ export const optInProofView = v.object({
|
|
|
49
61
|
});
|
|
50
62
|
|
|
51
63
|
/**
|
|
52
|
-
* Reject an empty key. The host hashes contacts, so a real
|
|
53
|
-
* `channel`, or `listKey` is never `""`; an empty one means an
|
|
54
|
-
* (an unset value passed through) and must not become a row or a
|
|
55
|
-
* "not suppressed" answer.
|
|
64
|
+
* Reject an empty or oversized key. The host hashes contacts, so a real
|
|
65
|
+
* `contactHash`, `channel`, or `listKey` is never `""`; an empty one means an
|
|
66
|
+
* upstream bug (an unset value passed through) and must not become a row or a
|
|
67
|
+
* silent "not suppressed" answer. A key over 256 UTF-8 bytes is rejected to bound
|
|
68
|
+
* row size (a hex SHA-256 is 64 bytes). Throws
|
|
69
|
+
* `ConvexError({ code: "INVALID_ARGUMENT", field })`.
|
|
56
70
|
*/
|
|
57
|
-
export function
|
|
58
|
-
if (value === "") {
|
|
71
|
+
export function assertKey(field: string, value: string): void {
|
|
72
|
+
if (value === "" || utf8Bytes(value) > MAX_KEY_BYTES) {
|
|
59
73
|
throw new ConvexError({ code: "INVALID_ARGUMENT", field });
|
|
60
74
|
}
|
|
61
75
|
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Reject an opt-in `proof` over 16384 UTF-8 bytes of its JSON form
|
|
79
|
+
* (`JSON.stringify(convexToJson(proof))`); an absent proof passes. Throws
|
|
80
|
+
* `ConvexError({ code: "INVALID_ARGUMENT", field: "proof" })`.
|
|
81
|
+
*/
|
|
82
|
+
export function assertProofSize(proof: Value | undefined): void {
|
|
83
|
+
if (
|
|
84
|
+
proof !== undefined &&
|
|
85
|
+
utf8Bytes(JSON.stringify(convexToJson(proof))) > MAX_PROOF_BYTES
|
|
86
|
+
) {
|
|
87
|
+
throw new ConvexError({ code: "INVALID_ARGUMENT", field: "proof" });
|
|
88
|
+
}
|
|
89
|
+
}
|