@vllnt/convex-email 0.2.0-canary.934d8ce → 0.2.0-canary.ffbb610
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 +19 -1
- package/README.md +7 -0
- package/dist/client/index.d.ts +7 -3
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +7 -3
- package/dist/client/index.js.map +1 -1
- package/dist/component/mutations.d.ts +12 -2
- package/dist/component/mutations.d.ts.map +1 -1
- package/dist/component/mutations.js +41 -10
- package/dist/component/mutations.js.map +1 -1
- package/dist/shared.d.ts +11 -0
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +11 -0
- package/dist/shared.js.map +1 -1
- package/docs/API.md +12 -4
- package/llms.txt +4 -1
- package/package.json +1 -1
- package/src/client/index.ts +7 -3
- package/src/component/mutations.ts +50 -11
- package/src/shared.ts +12 -0
package/CHANGELOG.md
CHANGED
|
@@ -22,6 +22,22 @@ All notable changes to this project are documented here. The format is based on
|
|
|
22
22
|
`ConvexError({ code: "INVALID_MAX_ATTEMPTS" })`; 0.1.0 stored them. What to do: pass
|
|
23
23
|
non-empty strings, omit `idempotencyKey` instead of passing `""`, and use an integer
|
|
24
24
|
`maxAttempts` of 1 or more.
|
|
25
|
+
- **Breaking:** `enqueue` and `markSent` now reject oversized inputs with
|
|
26
|
+
`ConvexError({ code: "INVALID_ARGUMENT" })` and the message
|
|
27
|
+
`<field> must be at most <max> UTF-16 code units`: `messageId`, `transport`,
|
|
28
|
+
`idempotencyKey`, `subjectRef` (`enqueue`) and `providerId` (`markSent`) over 512, and `to`
|
|
29
|
+
or `from` over 4096. Length is counted in UTF-16 code units, as JavaScript `length` counts
|
|
30
|
+
them (an emoji counts 2). 0.1.0 stored any length. What to do: validate or truncate these
|
|
31
|
+
values before calling, and split a long `to` address list into several messages. Rows 0.1.0
|
|
32
|
+
stored with longer values stay readable (`get`, `listByStatus`) and still transition
|
|
33
|
+
(`markSending`, `markSent`, `markFailed`); their stored `to`, `from`, `transport`,
|
|
34
|
+
`messageId`, `subjectRef` and `idempotencyKey` are kept unchanged on update, a later
|
|
35
|
+
`markFailed` replaces their `error` with the new, truncated one and `markSent` clears it,
|
|
36
|
+
and an `enqueue` that repeats such an over-limit `idempotencyKey` now throws instead of
|
|
37
|
+
returning the old row. `markSent` on a message already `sent` stays a no-op whatever the
|
|
38
|
+
`providerId`. `markFailed` does not reject a long `error`: it keeps the first 2048 code
|
|
39
|
+
units (one fewer if the cut would split a surrogate pair), so a long provider error never
|
|
40
|
+
leaves a message stuck in `sending`.
|
|
25
41
|
- `buildEmailCreate`, `buildSubmitRequest`, `sendViaJmap` and `createJmapSender` senders now
|
|
26
42
|
reject CR or LF anywhere in `to`, as the docs and the SMTP helpers already did. Before, a
|
|
27
43
|
line break at the start or end of `to`, or next to a comma, was trimmed away and the message
|
|
@@ -42,7 +58,9 @@ All notable changes to this project are documented here. The format is based on
|
|
|
42
58
|
`description`, `keywords` and `homepage` (`https://oss.vllnt.com/packages/convex-email`)
|
|
43
59
|
updated to match.
|
|
44
60
|
- Internal: CI, release, test, doc-contract and release-age tooling; development dependencies
|
|
45
|
-
upgraded; example addresses use `example.com` and `example.org
|
|
61
|
+
upgraded; example addresses use `example.com` and `example.org`; no update bot; pnpm via
|
|
62
|
+
Corepack in CI; publish gates and package-test type-checks run in parallel; every push to
|
|
63
|
+
`main` publishes a canary.
|
|
46
64
|
|
|
47
65
|
### Fixed
|
|
48
66
|
|
package/README.md
CHANGED
|
@@ -449,6 +449,7 @@ validation before the component runs. Full table:
|
|
|
449
449
|
| Code | Message | Cause | Fix |
|
|
450
450
|
| ---------------------- | ------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- |
|
|
451
451
|
| `INVALID_ARGUMENT` | `<field> must not be empty` | `enqueue` got `""` for `messageId`, `to`, `from`, `transport` or `idempotencyKey` | Pass a non-empty string, or omit `idempotencyKey` |
|
|
452
|
+
| `INVALID_ARGUMENT` | `<field> must be at most <max> UTF-16 code units` | `enqueue` got a `messageId`, `transport`, `idempotencyKey` or `subjectRef` over 512, or a `to`/`from` over 4096; `markSent` got a `providerId` over 512 | Check or shorten the value before the call; split a long recipient list into several messages |
|
|
452
453
|
| `INVALID_MAX_ATTEMPTS` | `maxAttempts must be a positive integer` | `enqueue` got a `maxAttempts` (per call or client default) below 1 or not an integer | Pass an integer of 1 or more, or omit it (default 5) |
|
|
453
454
|
| `DUPLICATE_MESSAGE` | `message "<messageId>" already exists` | `enqueue` reused a `messageId` and no `idempotencyKey` matched | Use a new `messageId`, or pass the same `idempotencyKey` to get the existing message back |
|
|
454
455
|
| `NOT_FOUND` | `message "<messageId>" not found` | `markSending`, `markSent` or `markFailed` got an unknown id (or one already pruned) | Use the `messageId` returned by `enqueue` |
|
|
@@ -526,6 +527,12 @@ longer matches.
|
|
|
526
527
|
- `to`, `from` and `transport` are stored as given. The component does not
|
|
527
528
|
check addresses; the JMAP and SMTP helpers only reject empty values and line
|
|
528
529
|
breaks.
|
|
530
|
+
- Length limits, counted in UTF-16 code units, as JavaScript `length` counts
|
|
531
|
+
them (an emoji counts 2): `messageId`, `transport`, `idempotencyKey`,
|
|
532
|
+
`subjectRef` and `providerId` at most 512; `to` and `from` at most 4096.
|
|
533
|
+
A longer value throws `INVALID_ARGUMENT`. `markFailed` cuts an `error` longer
|
|
534
|
+
than 2048 to 2048 (never splitting an emoji) instead of throwing. Rows stored
|
|
535
|
+
by 0.1.0 with longer values stay readable and still transition.
|
|
529
536
|
- The payload is stored in the component's table and returned by `get`. Do not
|
|
530
537
|
put secrets in it.
|
|
531
538
|
- `buildEmailCreate` and `buildSubmitRequest` return objects with a
|
package/dist/client/index.d.ts
CHANGED
|
@@ -131,7 +131,9 @@ export declare class Email<TPayload = unknown> {
|
|
|
131
131
|
* data validated against `payloadValidator` before storage. When
|
|
132
132
|
* `opts.idempotencyKey` matches an existing message the existing id is returned
|
|
133
133
|
* (`deduplicated: true`) and no new row is inserted. The message starts
|
|
134
|
-
* `queued`.
|
|
134
|
+
* `queued`. Rejects (`INVALID_ARGUMENT`) a `messageId`, `transport`,
|
|
135
|
+
* `idempotencyKey` or `subjectRef` over 512 and a `to` or `from` over 4096
|
|
136
|
+
* UTF-16 code units, as JavaScript `length` counts them.
|
|
135
137
|
*/
|
|
136
138
|
enqueue(ctx: RunMutationCtx, messageId: string, to: string, from: string, transport: string, opts?: EnqueueOptions<TPayload>): Promise<EnqueueResult>;
|
|
137
139
|
/**
|
|
@@ -145,13 +147,15 @@ export declare class Email<TPayload = unknown> {
|
|
|
145
147
|
/**
|
|
146
148
|
* Record a successful send — the message moves to terminal `sent`, recording
|
|
147
149
|
* the transport's `opts.providerId`. Idempotent against a replayed callback.
|
|
148
|
-
* Rejects a missing id
|
|
150
|
+
* Rejects a missing id, an already-`failed` message, and a `providerId` over
|
|
151
|
+
* 512 UTF-16 code units (`INVALID_ARGUMENT`) unless the message is already `sent`.
|
|
149
152
|
*/
|
|
150
153
|
markSent(ctx: RunMutationCtx, messageId: string, opts?: {
|
|
151
154
|
providerId?: string;
|
|
152
155
|
}): Promise<null>;
|
|
153
156
|
/**
|
|
154
|
-
* Record a failed send attempt, recording `opts.error
|
|
157
|
+
* Record a failed send attempt, recording `opts.error` (cut to 2048 UTF-16 code
|
|
158
|
+
* units without splitting a surrogate pair). The message returns to
|
|
155
159
|
* `queued` for another attempt while attempts remain, or lands in terminal
|
|
156
160
|
* `failed` once exhausted (see the returned `retried` flag). Rejects a missing
|
|
157
161
|
* id and an already-terminal message.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EACV,YAAY,EACZ,cAAc,EACd,aAAa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,aAAa,CAAC,CAexB;IAED;;;;OAIG;IACH,WAAW,CAAC,GAAG,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,CAEjF;IAED;;;;;OAKG;IACH,QAAQ,CACN,GAAG,EAAE,cAAc,EACnB,SAAS,EAAE,MAAM,EACjB,IAAI,GAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAA;KAAO,GACjC,OAAO,CAAC,IAAI,CAAC,CAKf;IAED;;;;;;OAMG;IACH,UAAU,CACR,GAAG,EAAE,cAAc,EACnB,SAAS,EAAE,MAAM,EACjB,IAAI,GAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAO,GAC5B,OAAO,CAAC,gBAAgB,CAAC,CAK3B;IAED,kFAAkF;IAC5E,GAAG,CACP,GAAG,EAAE,WAAW,EAChB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,CAGvC;IAED;;;OAGG;IACG,YAAY,CAChB,GAAG,EAAE,WAAW,EAChB,MAAM,EAAE,aAAa,EACrB,cAAc,EAAE,iBAAiB,GAChC,OAAO,CAAC,gBAAgB,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,CAMlD;IAED;;;;;OAKG;IACH,KAAK,CACH,GAAG,EAAE,cAAc,EACnB,IAAI,GAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAO,GAC7C,OAAO,CAAC,MAAM,CAAC,CAKjB;CACF;AAED,YAAY,EACV,YAAY,EACZ,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,aAAa,EACb,WAAW,EACX,MAAM,GACP,CAAC"}
|
package/dist/client/index.js
CHANGED
|
@@ -82,7 +82,9 @@ export class Email {
|
|
|
82
82
|
* data validated against `payloadValidator` before storage. When
|
|
83
83
|
* `opts.idempotencyKey` matches an existing message the existing id is returned
|
|
84
84
|
* (`deduplicated: true`) and no new row is inserted. The message starts
|
|
85
|
-
* `queued`.
|
|
85
|
+
* `queued`. Rejects (`INVALID_ARGUMENT`) a `messageId`, `transport`,
|
|
86
|
+
* `idempotencyKey` or `subjectRef` over 512 and a `to` or `from` over 4096
|
|
87
|
+
* UTF-16 code units, as JavaScript `length` counts them.
|
|
86
88
|
*/
|
|
87
89
|
enqueue(ctx, messageId, to, from, transport, opts = {}) {
|
|
88
90
|
return ctx.runMutation(this.component.mutations.enqueue, {
|
|
@@ -111,7 +113,8 @@ export class Email {
|
|
|
111
113
|
/**
|
|
112
114
|
* Record a successful send — the message moves to terminal `sent`, recording
|
|
113
115
|
* the transport's `opts.providerId`. Idempotent against a replayed callback.
|
|
114
|
-
* Rejects a missing id
|
|
116
|
+
* Rejects a missing id, an already-`failed` message, and a `providerId` over
|
|
117
|
+
* 512 UTF-16 code units (`INVALID_ARGUMENT`) unless the message is already `sent`.
|
|
115
118
|
*/
|
|
116
119
|
markSent(ctx, messageId, opts = {}) {
|
|
117
120
|
return ctx.runMutation(this.component.mutations.markSent, {
|
|
@@ -120,7 +123,8 @@ export class Email {
|
|
|
120
123
|
});
|
|
121
124
|
}
|
|
122
125
|
/**
|
|
123
|
-
* Record a failed send attempt, recording `opts.error
|
|
126
|
+
* Record a failed send attempt, recording `opts.error` (cut to 2048 UTF-16 code
|
|
127
|
+
* units without splitting a surrogate pair). The message returns to
|
|
124
128
|
* `queued` for another attempt while attempts remain, or lands in terminal
|
|
125
129
|
* `failed` once exhausted (see the returned `retried` flag). Rejects a missing
|
|
126
130
|
* id and an already-terminal message.
|
package/dist/client/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAqGzE;;;;;;;;;;;;;;;;;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;SACzC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -16,7 +16,11 @@
|
|
|
16
16
|
* can never produce a duplicate send.
|
|
17
17
|
*
|
|
18
18
|
* @throws `ConvexError({ code: "INVALID_ARGUMENT" })` when `messageId`, `to`,
|
|
19
|
-
* `from`, `transport`, or a supplied `idempotencyKey` is an empty string
|
|
19
|
+
* `from`, `transport`, or a supplied `idempotencyKey` is an empty string; when
|
|
20
|
+
* `messageId`, `transport`, `idempotencyKey` or `subjectRef` is longer than
|
|
21
|
+
* `MAX_ID_LENGTH` (512); or when `to` or `from` is longer than
|
|
22
|
+
* `MAX_ADDRESS_LENGTH` (4096). Lengths are UTF-16 code units, as JavaScript
|
|
23
|
+
* `length` counts them.
|
|
20
24
|
* @throws `ConvexError({ code: "INVALID_MAX_ATTEMPTS" })` when `maxAttempts` is
|
|
21
25
|
* not a positive integer.
|
|
22
26
|
*/
|
|
@@ -57,6 +61,10 @@ export declare const markSending: import("convex/server").RegisteredMutation<"pu
|
|
|
57
61
|
* Any other terminal state (`failed`) is rejected — a `failed` message is final.
|
|
58
62
|
*
|
|
59
63
|
* @throws `ConvexError({ code: "NOT_FOUND" })` when no message has `messageId`.
|
|
64
|
+
* @throws `ConvexError({ code: "INVALID_ARGUMENT" })` when `providerId` is longer
|
|
65
|
+
* than `MAX_ID_LENGTH` (512 UTF-16 code units) and the message is `queued`
|
|
66
|
+
* or `sending` (a replay on a `sent` message stays a no-op; a `failed`
|
|
67
|
+
* message throws `TERMINAL_STATE`).
|
|
60
68
|
* @throws `ConvexError({ code: "TERMINAL_STATE" })` when the message is already
|
|
61
69
|
* `failed` (a final state may not be transitioned out of).
|
|
62
70
|
*/
|
|
@@ -65,7 +73,9 @@ export declare const markSent: import("convex/server").RegisteredMutation<"publi
|
|
|
65
73
|
providerId?: string;
|
|
66
74
|
}, Promise<null>>;
|
|
67
75
|
/**
|
|
68
|
-
* Record a failed send attempt, recording the host-supplied `error
|
|
76
|
+
* Record a failed send attempt, recording the host-supplied `error` (cut to
|
|
77
|
+
* `MAX_ERROR_LENGTH`, 2048 UTF-16 code units, without splitting a surrogate
|
|
78
|
+
* pair, so a long provider error never leaves a message stuck). The outcome
|
|
69
79
|
* depends on the retry budget: if `attempts < maxAttempts` the message returns to
|
|
70
80
|
* `queued` for another attempt (`retried: true`); once attempts are exhausted it
|
|
71
81
|
* lands in terminal `failed` (`retried: false`). The host's backoff scheduler
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutations.d.ts","sourceRoot":"","sources":["../../src/component/mutations.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mutations.d.ts","sourceRoot":"","sources":["../../src/component/mutations.ts"],"names":[],"mappings":"AAgCA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,OAAO;;;;;;;;;;;;GA8ElB,CAAC;AAEH;;;;;;;;;;GAUG;AACH,eAAO,MAAM,WAAW;;;;GAmCtB,CAAC;AAEH;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,QAAQ;;;iBAiCnB,CAAC;AAEH;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,UAAU;;;;;;GA8BrB,CAAC;AAEH;;;;;;;;;GASG;AACH,eAAO,MAAM,KAAK;;;mBA2ChB,CAAC"}
|
|
@@ -1,8 +1,26 @@
|
|
|
1
1
|
import { ConvexError, v } from "convex/values";
|
|
2
2
|
import { api } from "./_generated/api.js";
|
|
3
3
|
import { mutation } from "./_generated/server.js";
|
|
4
|
-
import { DEFAULT_RETENTION_MS, MAX_PRUNE_BATCH } from "../shared.js";
|
|
4
|
+
import { DEFAULT_RETENTION_MS, MAX_ADDRESS_LENGTH, MAX_ERROR_LENGTH, MAX_ID_LENGTH, MAX_PRUNE_BATCH, } from "../shared.js";
|
|
5
5
|
import { jsonValue } from "./validators.js";
|
|
6
|
+
/** Throw `INVALID_ARGUMENT` when `value` is longer than `max` UTF-16 code units. */
|
|
7
|
+
function assertMaxLength(name, value, max) {
|
|
8
|
+
if (value !== undefined && value.length > max) {
|
|
9
|
+
throw new ConvexError({
|
|
10
|
+
code: "INVALID_ARGUMENT",
|
|
11
|
+
message: `${name} must be at most ${max} UTF-16 code units`,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/** Cut `error` to `MAX_ERROR_LENGTH` code units without splitting a surrogate pair. */
|
|
16
|
+
function truncateError(error) {
|
|
17
|
+
if (error.length <= MAX_ERROR_LENGTH) {
|
|
18
|
+
return error;
|
|
19
|
+
}
|
|
20
|
+
const last = error.charCodeAt(MAX_ERROR_LENGTH - 1);
|
|
21
|
+
const highSurrogate = last >= 0xd800 && last <= 0xdbff;
|
|
22
|
+
return error.slice(0, highSurrogate ? MAX_ERROR_LENGTH - 1 : MAX_ERROR_LENGTH);
|
|
23
|
+
}
|
|
6
24
|
/**
|
|
7
25
|
* Enqueue an outbound message and return its id immediately — the durable queue
|
|
8
26
|
* entry. The message is inserted in `queued` state with `attempts: 0`,
|
|
@@ -21,7 +39,11 @@ import { jsonValue } from "./validators.js";
|
|
|
21
39
|
* can never produce a duplicate send.
|
|
22
40
|
*
|
|
23
41
|
* @throws `ConvexError({ code: "INVALID_ARGUMENT" })` when `messageId`, `to`,
|
|
24
|
-
* `from`, `transport`, or a supplied `idempotencyKey` is an empty string
|
|
42
|
+
* `from`, `transport`, or a supplied `idempotencyKey` is an empty string; when
|
|
43
|
+
* `messageId`, `transport`, `idempotencyKey` or `subjectRef` is longer than
|
|
44
|
+
* `MAX_ID_LENGTH` (512); or when `to` or `from` is longer than
|
|
45
|
+
* `MAX_ADDRESS_LENGTH` (4096). Lengths are UTF-16 code units, as JavaScript
|
|
46
|
+
* `length` counts them.
|
|
25
47
|
* @throws `ConvexError({ code: "INVALID_MAX_ATTEMPTS" })` when `maxAttempts` is
|
|
26
48
|
* not a positive integer.
|
|
27
49
|
*/
|
|
@@ -39,20 +61,22 @@ export const enqueue = mutation({
|
|
|
39
61
|
returns: v.object({ messageId: v.string(), deduplicated: v.boolean() }),
|
|
40
62
|
handler: async (ctx, args) => {
|
|
41
63
|
const fields = [
|
|
42
|
-
["messageId", args.messageId],
|
|
43
|
-
["to", args.to],
|
|
44
|
-
["from", args.from],
|
|
45
|
-
["transport", args.transport],
|
|
46
|
-
["idempotencyKey", args.idempotencyKey],
|
|
64
|
+
["messageId", args.messageId, MAX_ID_LENGTH],
|
|
65
|
+
["to", args.to, MAX_ADDRESS_LENGTH],
|
|
66
|
+
["from", args.from, MAX_ADDRESS_LENGTH],
|
|
67
|
+
["transport", args.transport, MAX_ID_LENGTH],
|
|
68
|
+
["idempotencyKey", args.idempotencyKey, MAX_ID_LENGTH],
|
|
47
69
|
];
|
|
48
|
-
for (const [name, value] of fields) {
|
|
70
|
+
for (const [name, value, max] of fields) {
|
|
49
71
|
if (value === "") {
|
|
50
72
|
throw new ConvexError({
|
|
51
73
|
code: "INVALID_ARGUMENT",
|
|
52
74
|
message: `${name} must not be empty`,
|
|
53
75
|
});
|
|
54
76
|
}
|
|
77
|
+
assertMaxLength(name, value, max);
|
|
55
78
|
}
|
|
79
|
+
assertMaxLength("subjectRef", args.subjectRef, MAX_ID_LENGTH);
|
|
56
80
|
if (!Number.isInteger(args.maxAttempts) || args.maxAttempts < 1) {
|
|
57
81
|
throw new ConvexError({
|
|
58
82
|
code: "INVALID_MAX_ATTEMPTS",
|
|
@@ -152,6 +176,10 @@ export const markSending = mutation({
|
|
|
152
176
|
* Any other terminal state (`failed`) is rejected — a `failed` message is final.
|
|
153
177
|
*
|
|
154
178
|
* @throws `ConvexError({ code: "NOT_FOUND" })` when no message has `messageId`.
|
|
179
|
+
* @throws `ConvexError({ code: "INVALID_ARGUMENT" })` when `providerId` is longer
|
|
180
|
+
* than `MAX_ID_LENGTH` (512 UTF-16 code units) and the message is `queued`
|
|
181
|
+
* or `sending` (a replay on a `sent` message stays a no-op; a `failed`
|
|
182
|
+
* message throws `TERMINAL_STATE`).
|
|
155
183
|
* @throws `ConvexError({ code: "TERMINAL_STATE" })` when the message is already
|
|
156
184
|
* `failed` (a final state may not be transitioned out of).
|
|
157
185
|
*/
|
|
@@ -178,6 +206,7 @@ export const markSent = mutation({
|
|
|
178
206
|
message: `message "${args.messageId}" is already failed and cannot transition`,
|
|
179
207
|
});
|
|
180
208
|
}
|
|
209
|
+
assertMaxLength("providerId", args.providerId, MAX_ID_LENGTH);
|
|
181
210
|
await ctx.db.patch("messages", msg._id, {
|
|
182
211
|
status: "sent",
|
|
183
212
|
providerId: args.providerId,
|
|
@@ -188,7 +217,9 @@ export const markSent = mutation({
|
|
|
188
217
|
},
|
|
189
218
|
});
|
|
190
219
|
/**
|
|
191
|
-
* Record a failed send attempt, recording the host-supplied `error
|
|
220
|
+
* Record a failed send attempt, recording the host-supplied `error` (cut to
|
|
221
|
+
* `MAX_ERROR_LENGTH`, 2048 UTF-16 code units, without splitting a surrogate
|
|
222
|
+
* pair, so a long provider error never leaves a message stuck). The outcome
|
|
192
223
|
* depends on the retry budget: if `attempts < maxAttempts` the message returns to
|
|
193
224
|
* `queued` for another attempt (`retried: true`); once attempts are exhausted it
|
|
194
225
|
* lands in terminal `failed` (`retried: false`). The host's backoff scheduler
|
|
@@ -223,7 +254,7 @@ export const markFailed = mutation({
|
|
|
223
254
|
const status = retried ? "queued" : "failed";
|
|
224
255
|
await ctx.db.patch("messages", msg._id, {
|
|
225
256
|
status,
|
|
226
|
-
error: args.error,
|
|
257
|
+
error: args.error === undefined ? undefined : truncateError(args.error),
|
|
227
258
|
updatedAt: Date.now(),
|
|
228
259
|
});
|
|
229
260
|
return { status, retried };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutations.js","sourceRoot":"","sources":["../../src/component/mutations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAC1C,OAAO,EAAE,QAAQ,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AAQ,CAAC,CAAC,EAAE,GAAG,CAAC,SAAS,CAAC,KAAK,EAAE;gBACnD,MAAM;gBACN,KAAK,EAAE,IAAI,CAAC,KAAK;aAClB,CAAC,CAAC;QACL,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF,CAAC,CAAC"}
|
package/dist/shared.d.ts
CHANGED
|
@@ -30,4 +30,15 @@ export declare const DEFAULT_RETENTION_MS = 2592000000;
|
|
|
30
30
|
/** Default page size for a `prune` pass before the sweep self-reschedules. */
|
|
31
31
|
export declare const DEFAULT_PRUNE_BATCH = 200;
|
|
32
32
|
export declare const MAX_PRUNE_BATCH = 500;
|
|
33
|
+
/**
|
|
34
|
+
* Input length caps, counted in UTF-16 code units as JavaScript `length` counts
|
|
35
|
+
* them (an astral character such as an emoji counts 2). `enqueue` rejects a
|
|
36
|
+
* longer `messageId`, `transport`, `idempotencyKey` or `subjectRef`
|
|
37
|
+
* (`MAX_ID_LENGTH`) and a longer `to` or `from` (`MAX_ADDRESS_LENGTH`);
|
|
38
|
+
* `markSent` rejects a longer `providerId` (`MAX_ID_LENGTH`). `markFailed`
|
|
39
|
+
* truncates a longer `error` to `MAX_ERROR_LENGTH` instead of rejecting it.
|
|
40
|
+
*/
|
|
41
|
+
export declare const MAX_ID_LENGTH = 512;
|
|
42
|
+
export declare const MAX_ADDRESS_LENGTH = 4096;
|
|
43
|
+
export declare const MAX_ERROR_LENGTH = 2048;
|
|
33
44
|
//# sourceMappingURL=shared.d.ts.map
|
package/dist/shared.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAEhE,eAAO,MAAM,cAAc,UAAU,CAAC;AAEtC;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,YAAI,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAU,CAAC;AAEjF,yCAAyC;AACzC,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE9D,iFAAiF;AACjF,eAAO,MAAM,iBAAiB,EAAE,WAAW,CAAC,aAAa,CAGvD,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,IAAI,CAAC;AAEtC;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,aAAgB,CAAC;AAElD,8EAA8E;AAC9E,eAAO,MAAM,mBAAmB,MAAM,CAAC;AACvC,eAAO,MAAM,eAAe,MAAM,CAAC"}
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAEhE,eAAO,MAAM,cAAc,UAAU,CAAC;AAEtC;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,YAAI,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAU,CAAC;AAEjF,yCAAyC;AACzC,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE9D,iFAAiF;AACjF,eAAO,MAAM,iBAAiB,EAAE,WAAW,CAAC,aAAa,CAGvD,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,IAAI,CAAC;AAEtC;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,aAAgB,CAAC;AAElD,8EAA8E;AAC9E,eAAO,MAAM,mBAAmB,MAAM,CAAC;AACvC,eAAO,MAAM,eAAe,MAAM,CAAC;AAEnC;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,MAAM,CAAC;AACjC,eAAO,MAAM,kBAAkB,OAAO,CAAC;AACvC,eAAO,MAAM,gBAAgB,OAAO,CAAC"}
|
package/dist/shared.js
CHANGED
|
@@ -31,4 +31,15 @@ export const DEFAULT_RETENTION_MS = 2_592_000_000;
|
|
|
31
31
|
/** Default page size for a `prune` pass before the sweep self-reschedules. */
|
|
32
32
|
export const DEFAULT_PRUNE_BATCH = 200;
|
|
33
33
|
export const MAX_PRUNE_BATCH = 500;
|
|
34
|
+
/**
|
|
35
|
+
* Input length caps, counted in UTF-16 code units as JavaScript `length` counts
|
|
36
|
+
* them (an astral character such as an emoji counts 2). `enqueue` rejects a
|
|
37
|
+
* longer `messageId`, `transport`, `idempotencyKey` or `subjectRef`
|
|
38
|
+
* (`MAX_ID_LENGTH`) and a longer `to` or `from` (`MAX_ADDRESS_LENGTH`);
|
|
39
|
+
* `markSent` rejects a longer `providerId` (`MAX_ID_LENGTH`). `markFailed`
|
|
40
|
+
* truncates a longer `error` to `MAX_ERROR_LENGTH` instead of rejecting it.
|
|
41
|
+
*/
|
|
42
|
+
export const MAX_ID_LENGTH = 512;
|
|
43
|
+
export const MAX_ADDRESS_LENGTH = 4096;
|
|
44
|
+
export const MAX_ERROR_LENGTH = 2048;
|
|
34
45
|
//# sourceMappingURL=shared.js.map
|
package/dist/shared.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAEhE,MAAM,CAAC,MAAM,cAAc,GAAG,OAAO,CAAC;AAEtC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAU,CAAC;AAKjF,iFAAiF;AACjF,MAAM,CAAC,MAAM,iBAAiB,GAA+B,IAAI,GAAG,CAAC;IACnE,MAAM;IACN,QAAQ;CACT,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAEtC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,aAAa,CAAC;AAElD,8EAA8E;AAC9E,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,CAAC;AACvC,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,CAAC"}
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAEhE,MAAM,CAAC,MAAM,cAAc,GAAG,OAAO,CAAC;AAEtC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAU,CAAC;AAKjF,iFAAiF;AACjF,MAAM,CAAC,MAAM,iBAAiB,GAA+B,IAAI,GAAG,CAAC;IACnE,MAAM;IACN,QAAQ;CACT,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAEtC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,aAAa,CAAC;AAElD,8EAA8E;AAC9E,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,CAAC;AACvC,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,CAAC;AAEnC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,CAAC;AACjC,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,CAAC;AACvC,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAC"}
|
package/docs/API.md
CHANGED
|
@@ -71,7 +71,9 @@ is a free-form tag your sender can switch on.
|
|
|
71
71
|
Checks, in order:
|
|
72
72
|
|
|
73
73
|
1. `messageId`, `to`, `from`, `transport` and a supplied `idempotencyKey` must
|
|
74
|
-
not be `""`
|
|
74
|
+
not be `""`; `messageId`, `transport`, `idempotencyKey` and `subjectRef` must
|
|
75
|
+
be at most 512 and `to` and `from` at most 4096 UTF-16 code units, as
|
|
76
|
+
JavaScript `length` counts them (an emoji counts 2) (`INVALID_ARGUMENT`).
|
|
75
77
|
2. `maxAttempts` (`opts.maxAttempts`, else the client default) must be an
|
|
76
78
|
integer of 1 or more (`INVALID_MAX_ATTEMPTS`).
|
|
77
79
|
3. If a stored message has the same `idempotencyKey`, nothing is inserted and
|
|
@@ -103,7 +105,10 @@ markSent(ctx, messageId: string, opts?: { providerId?: string }): Promise<null>
|
|
|
103
105
|
Sets `sent`, stores `opts.providerId` and clears `error`. On a message already
|
|
104
106
|
`sent` it returns `null` and changes nothing (the first `providerId` is kept).
|
|
105
107
|
Throws `NOT_FOUND` for an unknown id and `TERMINAL_STATE` for a `failed`
|
|
106
|
-
message. A `queued` message is accepted too.
|
|
108
|
+
message. A `queued` message is accepted too. A `providerId` over 512 UTF-16
|
|
109
|
+
code units throws `INVALID_ARGUMENT` (`providerId must be at most 512 UTF-16
|
|
110
|
+
code units`) on a `queued` or `sending` message. On a message already `sent`
|
|
111
|
+
the call stays a no-op, and a `failed` message throws `TERMINAL_STATE` first.
|
|
107
112
|
|
|
108
113
|
### `markFailed`
|
|
109
114
|
|
|
@@ -111,8 +116,10 @@ message. A `queued` message is accepted too.
|
|
|
111
116
|
markFailed(ctx, messageId: string, opts?: { error?: string }): Promise<MarkFailedResult>
|
|
112
117
|
```
|
|
113
118
|
|
|
114
|
-
Stores `opts.error
|
|
115
|
-
|
|
119
|
+
Stores `opts.error`, cut to its first 2048 UTF-16 code units when longer (one
|
|
120
|
+
fewer when the cut would split a surrogate pair, so an emoji is never broken);
|
|
121
|
+
it never throws for a long `error`. If `attempts < maxAttempts` the message
|
|
122
|
+
becomes `queued` and the result is `{ status: "queued", retried: true }`; otherwise it becomes
|
|
116
123
|
`failed` and the result is `{ status: "failed", retried: false }`. It sends
|
|
117
124
|
nothing and schedules nothing: the host schedules the next attempt. Throws
|
|
118
125
|
`NOT_FOUND` for an unknown id and `TERMINAL_STATE` for a `sent` or `failed`
|
|
@@ -246,6 +253,7 @@ Component errors are `ConvexError`s whose `data` is `{ code, message }`
|
|
|
246
253
|
| Code | Thrown by | Message |
|
|
247
254
|
| ---------------------- | ---------------------------------------- | ----------------------------------------------------------------- |
|
|
248
255
|
| `INVALID_ARGUMENT` | `enqueue` | `<field> must not be empty` |
|
|
256
|
+
| `INVALID_ARGUMENT` | `enqueue`, `markSent` | `<field> must be at most <max> UTF-16 code units` |
|
|
249
257
|
| `INVALID_MAX_ATTEMPTS` | `enqueue` | `maxAttempts must be a positive integer` |
|
|
250
258
|
| `DUPLICATE_MESSAGE` | `enqueue` | `message "<messageId>" already exists` |
|
|
251
259
|
| `NOT_FOUND` | `markSending`, `markSent`, `markFailed` | `message "<messageId>" not found` |
|
package/llms.txt
CHANGED
|
@@ -18,7 +18,10 @@ never sends email and never reads auth. Your action claims a message, sends it
|
|
|
18
18
|
with `createJmapSender` (`./jmap`, plain `fetch`, default runtime) or
|
|
19
19
|
`createSmtpSender` (`./smtp`, needs `nodemailer` and `"use node"`), then calls
|
|
20
20
|
`markSent` or `markFailed`, and schedules retries itself. An `idempotencyKey`
|
|
21
|
-
returns the existing message (`deduplicated: true`).
|
|
21
|
+
returns the existing message (`deduplicated: true`). Length limits in UTF-16
|
|
22
|
+
code units (JavaScript `length`): ids (`messageId`, `transport`,
|
|
23
|
+
`idempotencyKey`, `subjectRef`, `providerId`) 512, `to`/`from` 4096, else
|
|
24
|
+
`INVALID_ARGUMENT`; `markFailed` truncates `error` to 2048. Errors are `ConvexError`s
|
|
22
25
|
with `data.code` `INVALID_ARGUMENT`, `INVALID_MAX_ATTEMPTS`,
|
|
23
26
|
`DUPLICATE_MESSAGE`, `NOT_FOUND`, `TERMINAL_STATE`, `INVALID_TRANSITION`,
|
|
24
27
|
`INVALID_BATCH` or `INVALID_BEFORE`. A daily cron deletes `sent`/`failed`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vllnt/convex-email",
|
|
3
|
-
"version": "0.2.0-canary.
|
|
3
|
+
"version": "0.2.0-canary.ffbb610",
|
|
4
4
|
"description": "TypeScript Convex component for outbound transactional email: durable send queue, retry budget, idempotent enqueue, delivery status, SMTP and JMAP senders.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
package/src/client/index.ts
CHANGED
|
@@ -203,7 +203,9 @@ export class Email<TPayload = unknown> {
|
|
|
203
203
|
* data validated against `payloadValidator` before storage. When
|
|
204
204
|
* `opts.idempotencyKey` matches an existing message the existing id is returned
|
|
205
205
|
* (`deduplicated: true`) and no new row is inserted. The message starts
|
|
206
|
-
* `queued`.
|
|
206
|
+
* `queued`. Rejects (`INVALID_ARGUMENT`) a `messageId`, `transport`,
|
|
207
|
+
* `idempotencyKey` or `subjectRef` over 512 and a `to` or `from` over 4096
|
|
208
|
+
* UTF-16 code units, as JavaScript `length` counts them.
|
|
207
209
|
*/
|
|
208
210
|
enqueue(
|
|
209
211
|
ctx: RunMutationCtx,
|
|
@@ -241,7 +243,8 @@ export class Email<TPayload = unknown> {
|
|
|
241
243
|
/**
|
|
242
244
|
* Record a successful send — the message moves to terminal `sent`, recording
|
|
243
245
|
* the transport's `opts.providerId`. Idempotent against a replayed callback.
|
|
244
|
-
* Rejects a missing id
|
|
246
|
+
* Rejects a missing id, an already-`failed` message, and a `providerId` over
|
|
247
|
+
* 512 UTF-16 code units (`INVALID_ARGUMENT`) unless the message is already `sent`.
|
|
245
248
|
*/
|
|
246
249
|
markSent(
|
|
247
250
|
ctx: RunMutationCtx,
|
|
@@ -255,7 +258,8 @@ export class Email<TPayload = unknown> {
|
|
|
255
258
|
}
|
|
256
259
|
|
|
257
260
|
/**
|
|
258
|
-
* Record a failed send attempt, recording `opts.error
|
|
261
|
+
* Record a failed send attempt, recording `opts.error` (cut to 2048 UTF-16 code
|
|
262
|
+
* units without splitting a surrogate pair). The message returns to
|
|
259
263
|
* `queued` for another attempt while attempts remain, or lands in terminal
|
|
260
264
|
* `failed` once exhausted (see the returned `retried` flag). Rejects a missing
|
|
261
265
|
* id and an already-terminal message.
|
|
@@ -1,9 +1,35 @@
|
|
|
1
1
|
import { ConvexError, v } from "convex/values";
|
|
2
2
|
import { api } from "./_generated/api.js";
|
|
3
3
|
import { mutation } from "./_generated/server.js";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
DEFAULT_RETENTION_MS,
|
|
6
|
+
MAX_ADDRESS_LENGTH,
|
|
7
|
+
MAX_ERROR_LENGTH,
|
|
8
|
+
MAX_ID_LENGTH,
|
|
9
|
+
MAX_PRUNE_BATCH,
|
|
10
|
+
} from "../shared.js";
|
|
5
11
|
import { jsonValue } from "./validators.js";
|
|
6
12
|
|
|
13
|
+
/** Throw `INVALID_ARGUMENT` when `value` is longer than `max` UTF-16 code units. */
|
|
14
|
+
function assertMaxLength(name: string, value: string | undefined, max: number) {
|
|
15
|
+
if (value !== undefined && value.length > max) {
|
|
16
|
+
throw new ConvexError({
|
|
17
|
+
code: "INVALID_ARGUMENT",
|
|
18
|
+
message: `${name} must be at most ${max} UTF-16 code units`,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Cut `error` to `MAX_ERROR_LENGTH` code units without splitting a surrogate pair. */
|
|
24
|
+
function truncateError(error: string): string {
|
|
25
|
+
if (error.length <= MAX_ERROR_LENGTH) {
|
|
26
|
+
return error;
|
|
27
|
+
}
|
|
28
|
+
const last = error.charCodeAt(MAX_ERROR_LENGTH - 1);
|
|
29
|
+
const highSurrogate = last >= 0xd800 && last <= 0xdbff;
|
|
30
|
+
return error.slice(0, highSurrogate ? MAX_ERROR_LENGTH - 1 : MAX_ERROR_LENGTH);
|
|
31
|
+
}
|
|
32
|
+
|
|
7
33
|
/**
|
|
8
34
|
* Enqueue an outbound message and return its id immediately — the durable queue
|
|
9
35
|
* entry. The message is inserted in `queued` state with `attempts: 0`,
|
|
@@ -22,7 +48,11 @@ import { jsonValue } from "./validators.js";
|
|
|
22
48
|
* can never produce a duplicate send.
|
|
23
49
|
*
|
|
24
50
|
* @throws `ConvexError({ code: "INVALID_ARGUMENT" })` when `messageId`, `to`,
|
|
25
|
-
* `from`, `transport`, or a supplied `idempotencyKey` is an empty string
|
|
51
|
+
* `from`, `transport`, or a supplied `idempotencyKey` is an empty string; when
|
|
52
|
+
* `messageId`, `transport`, `idempotencyKey` or `subjectRef` is longer than
|
|
53
|
+
* `MAX_ID_LENGTH` (512); or when `to` or `from` is longer than
|
|
54
|
+
* `MAX_ADDRESS_LENGTH` (4096). Lengths are UTF-16 code units, as JavaScript
|
|
55
|
+
* `length` counts them.
|
|
26
56
|
* @throws `ConvexError({ code: "INVALID_MAX_ATTEMPTS" })` when `maxAttempts` is
|
|
27
57
|
* not a positive integer.
|
|
28
58
|
*/
|
|
@@ -39,21 +69,23 @@ export const enqueue = mutation({
|
|
|
39
69
|
},
|
|
40
70
|
returns: v.object({ messageId: v.string(), deduplicated: v.boolean() }),
|
|
41
71
|
handler: async (ctx, args) => {
|
|
42
|
-
const fields: Array<[string, string | undefined]> = [
|
|
43
|
-
["messageId", args.messageId],
|
|
44
|
-
["to", args.to],
|
|
45
|
-
["from", args.from],
|
|
46
|
-
["transport", args.transport],
|
|
47
|
-
["idempotencyKey", args.idempotencyKey],
|
|
72
|
+
const fields: Array<[string, string | undefined, number]> = [
|
|
73
|
+
["messageId", args.messageId, MAX_ID_LENGTH],
|
|
74
|
+
["to", args.to, MAX_ADDRESS_LENGTH],
|
|
75
|
+
["from", args.from, MAX_ADDRESS_LENGTH],
|
|
76
|
+
["transport", args.transport, MAX_ID_LENGTH],
|
|
77
|
+
["idempotencyKey", args.idempotencyKey, MAX_ID_LENGTH],
|
|
48
78
|
];
|
|
49
|
-
for (const [name, value] of fields) {
|
|
79
|
+
for (const [name, value, max] of fields) {
|
|
50
80
|
if (value === "") {
|
|
51
81
|
throw new ConvexError({
|
|
52
82
|
code: "INVALID_ARGUMENT",
|
|
53
83
|
message: `${name} must not be empty`,
|
|
54
84
|
});
|
|
55
85
|
}
|
|
86
|
+
assertMaxLength(name, value, max);
|
|
56
87
|
}
|
|
88
|
+
assertMaxLength("subjectRef", args.subjectRef, MAX_ID_LENGTH);
|
|
57
89
|
if (!Number.isInteger(args.maxAttempts) || args.maxAttempts < 1) {
|
|
58
90
|
throw new ConvexError({
|
|
59
91
|
code: "INVALID_MAX_ATTEMPTS",
|
|
@@ -160,6 +192,10 @@ export const markSending = mutation({
|
|
|
160
192
|
* Any other terminal state (`failed`) is rejected — a `failed` message is final.
|
|
161
193
|
*
|
|
162
194
|
* @throws `ConvexError({ code: "NOT_FOUND" })` when no message has `messageId`.
|
|
195
|
+
* @throws `ConvexError({ code: "INVALID_ARGUMENT" })` when `providerId` is longer
|
|
196
|
+
* than `MAX_ID_LENGTH` (512 UTF-16 code units) and the message is `queued`
|
|
197
|
+
* or `sending` (a replay on a `sent` message stays a no-op; a `failed`
|
|
198
|
+
* message throws `TERMINAL_STATE`).
|
|
163
199
|
* @throws `ConvexError({ code: "TERMINAL_STATE" })` when the message is already
|
|
164
200
|
* `failed` (a final state may not be transitioned out of).
|
|
165
201
|
*/
|
|
@@ -186,6 +222,7 @@ export const markSent = mutation({
|
|
|
186
222
|
message: `message "${args.messageId}" is already failed and cannot transition`,
|
|
187
223
|
});
|
|
188
224
|
}
|
|
225
|
+
assertMaxLength("providerId", args.providerId, MAX_ID_LENGTH);
|
|
189
226
|
|
|
190
227
|
await ctx.db.patch("messages", msg._id, {
|
|
191
228
|
status: "sent",
|
|
@@ -198,7 +235,9 @@ export const markSent = mutation({
|
|
|
198
235
|
});
|
|
199
236
|
|
|
200
237
|
/**
|
|
201
|
-
* Record a failed send attempt, recording the host-supplied `error
|
|
238
|
+
* Record a failed send attempt, recording the host-supplied `error` (cut to
|
|
239
|
+
* `MAX_ERROR_LENGTH`, 2048 UTF-16 code units, without splitting a surrogate
|
|
240
|
+
* pair, so a long provider error never leaves a message stuck). The outcome
|
|
202
241
|
* depends on the retry budget: if `attempts < maxAttempts` the message returns to
|
|
203
242
|
* `queued` for another attempt (`retried: true`); once attempts are exhausted it
|
|
204
243
|
* lands in terminal `failed` (`retried: false`). The host's backoff scheduler
|
|
@@ -234,7 +273,7 @@ export const markFailed = mutation({
|
|
|
234
273
|
const status = retried ? ("queued" as const) : ("failed" as const);
|
|
235
274
|
await ctx.db.patch("messages", msg._id, {
|
|
236
275
|
status,
|
|
237
|
-
error: args.error,
|
|
276
|
+
error: args.error === undefined ? undefined : truncateError(args.error),
|
|
238
277
|
updatedAt: Date.now(),
|
|
239
278
|
});
|
|
240
279
|
return { status, retried };
|
package/src/shared.ts
CHANGED
|
@@ -40,3 +40,15 @@ export const DEFAULT_RETENTION_MS = 2_592_000_000;
|
|
|
40
40
|
/** Default page size for a `prune` pass before the sweep self-reschedules. */
|
|
41
41
|
export const DEFAULT_PRUNE_BATCH = 200;
|
|
42
42
|
export const MAX_PRUNE_BATCH = 500;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Input length caps, counted in UTF-16 code units as JavaScript `length` counts
|
|
46
|
+
* them (an astral character such as an emoji counts 2). `enqueue` rejects a
|
|
47
|
+
* longer `messageId`, `transport`, `idempotencyKey` or `subjectRef`
|
|
48
|
+
* (`MAX_ID_LENGTH`) and a longer `to` or `from` (`MAX_ADDRESS_LENGTH`);
|
|
49
|
+
* `markSent` rejects a longer `providerId` (`MAX_ID_LENGTH`). `markFailed`
|
|
50
|
+
* truncates a longer `error` to `MAX_ERROR_LENGTH` instead of rejecting it.
|
|
51
|
+
*/
|
|
52
|
+
export const MAX_ID_LENGTH = 512;
|
|
53
|
+
export const MAX_ADDRESS_LENGTH = 4096;
|
|
54
|
+
export const MAX_ERROR_LENGTH = 2048;
|