@web-ts-toolkit/email-service 0.72.0 → 0.73.0
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 +148 -10
- package/index.d.mts +15 -7
- package/index.d.ts +15 -7
- package/index.js +479 -246
- package/index.mjs +479 -246
- package/mongoose.d.mts +7 -4
- package/mongoose.d.ts +7 -4
- package/mongoose.js +546 -280
- package/mongoose.mjs +546 -280
- package/package.json +1 -1
- package/{provider-HisBc6hk.d.mts → provider-DC_av0SQ.d.mts} +17 -1
- package/{provider-HisBc6hk.d.ts → provider-DC_av0SQ.d.ts} +17 -1
- package/sendgrid.d.mts +1 -1
- package/sendgrid.d.ts +1 -1
- package/sendgrid.js +116 -32
- package/sendgrid.mjs +116 -32
- package/smtp.d.mts +3 -1
- package/smtp.d.ts +3 -1
- package/smtp.js +138 -38
- package/smtp.mjs +138 -38
- package/{store-D4YAI6Rk.d.mts → store-Bi5iZ910.d.ts} +18 -4
- package/{store-Vb63Gocz.d.ts → store-DlABKTjt.d.mts} +18 -4
package/package.json
CHANGED
|
@@ -5,6 +5,17 @@ type EmailScope = string;
|
|
|
5
5
|
type EmailJobId = string;
|
|
6
6
|
type EmailAttemptId = string;
|
|
7
7
|
type Awaitable<T> = T | PromiseLike<T>;
|
|
8
|
+
/**
|
|
9
|
+
* Trusted live SMTP opt-in. Pass the same tuple at each factory in the queue; omit it for V1 (50 recipients).
|
|
10
|
+
* `namespace` is a canonical lowercase UUIDv4 for one logical backing. Keep its cap fixed; use a new namespace
|
|
11
|
+
* to change it. `maxRecipients` is an integer from 51 to 1,000, counting To, Cc and Bcc together.
|
|
12
|
+
* `format` selects storage, not the DTO's `version: 1`. Never select the binding from request data.
|
|
13
|
+
*/
|
|
14
|
+
type SmtpCapacity = Readonly<{
|
|
15
|
+
format: 'smtp-v2';
|
|
16
|
+
namespace: string;
|
|
17
|
+
maxRecipients: number;
|
|
18
|
+
}>;
|
|
8
19
|
/** Plain JSON at the validation boundary; this type alone does not check serialization or size. */
|
|
9
20
|
type JsonValue = null | boolean | number | string | readonly JsonValue[] | JsonObject;
|
|
10
21
|
type JsonObject = {
|
|
@@ -87,6 +98,7 @@ type EmailSnapshot = SnapshotFields & ({
|
|
|
87
98
|
readonly provider: Extract<ProviderRef, {
|
|
88
99
|
kind: 'smtp';
|
|
89
100
|
}>;
|
|
101
|
+
readonly smtpCapacity?: SmtpCapacity;
|
|
90
102
|
readonly subject: string;
|
|
91
103
|
readonly html?: string;
|
|
92
104
|
readonly text?: string;
|
|
@@ -95,12 +107,15 @@ type EmailSnapshot = SnapshotFields & ({
|
|
|
95
107
|
readonly provider: Extract<ProviderRef, {
|
|
96
108
|
kind: 'sendgrid';
|
|
97
109
|
}>;
|
|
110
|
+
readonly smtpCapacity?: never;
|
|
98
111
|
readonly templateId: string;
|
|
99
112
|
readonly data: JsonObject;
|
|
100
113
|
});
|
|
101
114
|
/** Versioned, sensitive outbox value. Store it with the host's business write, then relay it unchanged. */
|
|
102
115
|
type PreparedEmailCommand = {
|
|
103
116
|
readonly version: 1;
|
|
117
|
+
/** Present on every staged message from an opted-in SMTP lane, even below 51 recipients. */
|
|
118
|
+
readonly smtpCapacity?: SmtpCapacity;
|
|
104
119
|
readonly scope: EmailScope;
|
|
105
120
|
readonly key: EmailAdmissionKey;
|
|
106
121
|
readonly scheduleAt: UnixMs | null;
|
|
@@ -175,9 +190,10 @@ interface PreparedEmailSubmission {
|
|
|
175
190
|
}
|
|
176
191
|
interface EmailProvider<M extends EmailSnapshot> {
|
|
177
192
|
readonly ref: M['provider'];
|
|
193
|
+
readonly smtpCapacity?: SmtpCapacity;
|
|
178
194
|
/** Validate and prepare without I/O. Direct unmanaged submission has no queue or retry guarantees. */
|
|
179
195
|
prepare(input: ProviderSubmission<M>): PreparedEmailSubmission;
|
|
180
196
|
}
|
|
181
197
|
type ConfiguredEmailProvider = EmailProvider<SmtpSnapshot> | EmailProvider<SendGridSnapshot>;
|
|
182
198
|
|
|
183
|
-
export type { Awaitable as A,
|
|
199
|
+
export type { Awaitable as A, SubmissionOutcome as B, Correlation as C, SubmissionStage as D, EmailEnvelope as E, JsonObject as J, Mailbox as M, ProviderRef as P, RecipientResult as R, SmtpCapacity as S, TemplateIdentity as T, UnixMs as U, EmailScope as a, EmailAdmissionKey as b, AttachmentRef as c, JsonValue as d, CallOptions as e, PreparedEmailCommand as f, EmailClock as g, AttachmentResolution as h, AttachmentResolver as i, AttemptReason as j, AttemptResult as k, ConfiguredEmailProvider as l, EmailAttemptId as m, EmailJobId as n, EmailProvider as o, EmailSnapshot as p, PreparedEmailSubmission as q, ProviderCall as r, ProviderReason as s, ProviderResult as t, ProviderSubmission as u, ResolvedAttachment as v, RetryClass as w, RetryHint as x, SendGridSnapshot as y, SmtpSnapshot as z };
|
|
@@ -5,6 +5,17 @@ type EmailScope = string;
|
|
|
5
5
|
type EmailJobId = string;
|
|
6
6
|
type EmailAttemptId = string;
|
|
7
7
|
type Awaitable<T> = T | PromiseLike<T>;
|
|
8
|
+
/**
|
|
9
|
+
* Trusted live SMTP opt-in. Pass the same tuple at each factory in the queue; omit it for V1 (50 recipients).
|
|
10
|
+
* `namespace` is a canonical lowercase UUIDv4 for one logical backing. Keep its cap fixed; use a new namespace
|
|
11
|
+
* to change it. `maxRecipients` is an integer from 51 to 1,000, counting To, Cc and Bcc together.
|
|
12
|
+
* `format` selects storage, not the DTO's `version: 1`. Never select the binding from request data.
|
|
13
|
+
*/
|
|
14
|
+
type SmtpCapacity = Readonly<{
|
|
15
|
+
format: 'smtp-v2';
|
|
16
|
+
namespace: string;
|
|
17
|
+
maxRecipients: number;
|
|
18
|
+
}>;
|
|
8
19
|
/** Plain JSON at the validation boundary; this type alone does not check serialization or size. */
|
|
9
20
|
type JsonValue = null | boolean | number | string | readonly JsonValue[] | JsonObject;
|
|
10
21
|
type JsonObject = {
|
|
@@ -87,6 +98,7 @@ type EmailSnapshot = SnapshotFields & ({
|
|
|
87
98
|
readonly provider: Extract<ProviderRef, {
|
|
88
99
|
kind: 'smtp';
|
|
89
100
|
}>;
|
|
101
|
+
readonly smtpCapacity?: SmtpCapacity;
|
|
90
102
|
readonly subject: string;
|
|
91
103
|
readonly html?: string;
|
|
92
104
|
readonly text?: string;
|
|
@@ -95,12 +107,15 @@ type EmailSnapshot = SnapshotFields & ({
|
|
|
95
107
|
readonly provider: Extract<ProviderRef, {
|
|
96
108
|
kind: 'sendgrid';
|
|
97
109
|
}>;
|
|
110
|
+
readonly smtpCapacity?: never;
|
|
98
111
|
readonly templateId: string;
|
|
99
112
|
readonly data: JsonObject;
|
|
100
113
|
});
|
|
101
114
|
/** Versioned, sensitive outbox value. Store it with the host's business write, then relay it unchanged. */
|
|
102
115
|
type PreparedEmailCommand = {
|
|
103
116
|
readonly version: 1;
|
|
117
|
+
/** Present on every staged message from an opted-in SMTP lane, even below 51 recipients. */
|
|
118
|
+
readonly smtpCapacity?: SmtpCapacity;
|
|
104
119
|
readonly scope: EmailScope;
|
|
105
120
|
readonly key: EmailAdmissionKey;
|
|
106
121
|
readonly scheduleAt: UnixMs | null;
|
|
@@ -175,9 +190,10 @@ interface PreparedEmailSubmission {
|
|
|
175
190
|
}
|
|
176
191
|
interface EmailProvider<M extends EmailSnapshot> {
|
|
177
192
|
readonly ref: M['provider'];
|
|
193
|
+
readonly smtpCapacity?: SmtpCapacity;
|
|
178
194
|
/** Validate and prepare without I/O. Direct unmanaged submission has no queue or retry guarantees. */
|
|
179
195
|
prepare(input: ProviderSubmission<M>): PreparedEmailSubmission;
|
|
180
196
|
}
|
|
181
197
|
type ConfiguredEmailProvider = EmailProvider<SmtpSnapshot> | EmailProvider<SendGridSnapshot>;
|
|
182
198
|
|
|
183
|
-
export type { Awaitable as A,
|
|
199
|
+
export type { Awaitable as A, SubmissionOutcome as B, Correlation as C, SubmissionStage as D, EmailEnvelope as E, JsonObject as J, Mailbox as M, ProviderRef as P, RecipientResult as R, SmtpCapacity as S, TemplateIdentity as T, UnixMs as U, EmailScope as a, EmailAdmissionKey as b, AttachmentRef as c, JsonValue as d, CallOptions as e, PreparedEmailCommand as f, EmailClock as g, AttachmentResolution as h, AttachmentResolver as i, AttemptReason as j, AttemptResult as k, ConfiguredEmailProvider as l, EmailAttemptId as m, EmailJobId as n, EmailProvider as o, EmailSnapshot as p, PreparedEmailSubmission as q, ProviderCall as r, ProviderReason as s, ProviderResult as t, ProviderSubmission as u, ResolvedAttachment as v, RetryClass as w, RetryHint as x, SendGridSnapshot as y, SmtpSnapshot as z };
|
package/sendgrid.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { o as EmailProvider,
|
|
1
|
+
import { o as EmailProvider, y as SendGridSnapshot } from './provider-DC_av0SQ.mjs';
|
|
2
2
|
|
|
3
3
|
/** Instance-owned credentials for HTTPS Mail Send only, not for template administration. */
|
|
4
4
|
type SendGridProviderOptions = {
|
package/sendgrid.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { o as EmailProvider,
|
|
1
|
+
import { o as EmailProvider, y as SendGridSnapshot } from './provider-DC_av0SQ.js';
|
|
2
2
|
|
|
3
3
|
/** Instance-owned credentials for HTTPS Mail Send only, not for template administration. */
|
|
4
4
|
type SendGridProviderOptions = {
|
package/sendgrid.js
CHANGED
|
@@ -262,6 +262,12 @@ function opaqueToken(value, maxBytes, code) {
|
|
|
262
262
|
function identifier(value, code) {
|
|
263
263
|
return opaqueToken(value, MESSAGE_LIMITS.identifierBytes, code);
|
|
264
264
|
}
|
|
265
|
+
function uuidV4(value, code) {
|
|
266
|
+
if (typeof value !== "string" || value.length !== 36 || !/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/.test(value)) {
|
|
267
|
+
invalid(code);
|
|
268
|
+
}
|
|
269
|
+
return value;
|
|
270
|
+
}
|
|
265
271
|
function hashToken(value, code) {
|
|
266
272
|
if (typeof value !== "string" || value.length !== 64 || !/^[0-9a-f]{64}$/.test(value)) invalid(code);
|
|
267
273
|
return value;
|
|
@@ -275,9 +281,9 @@ function jsonKey(key, code) {
|
|
|
275
281
|
|
|
276
282
|
// src/internal/canonical-json.ts
|
|
277
283
|
var treeLimits = { depth: MESSAGE_LIMITS.jsonDepth, values: MESSAGE_LIMITS.jsonValues };
|
|
278
|
-
function canonicalJson(input, maxBytes, code = "invalid_snapshot",
|
|
284
|
+
function canonicalJson(input, maxBytes, code = "invalid_snapshot", limits2 = treeLimits) {
|
|
279
285
|
let bytesLeft = maxBytes;
|
|
280
|
-
let valuesLeft =
|
|
286
|
+
let valuesLeft = limits2.values;
|
|
281
287
|
const chunks = [];
|
|
282
288
|
const ancestors = /* @__PURE__ */ new Set();
|
|
283
289
|
function append(text, bytes = text.length) {
|
|
@@ -296,7 +302,7 @@ function canonicalJson(input, maxBytes, code = "invalid_snapshot", limits = tree
|
|
|
296
302
|
append(JSON.stringify(text), bytes);
|
|
297
303
|
}
|
|
298
304
|
function visit(value2, depth) {
|
|
299
|
-
if (depth >
|
|
305
|
+
if (depth > limits2.depth || --valuesLeft < 0 || bytesLeft < 1) invalid(code);
|
|
300
306
|
switch (typeof value2) {
|
|
301
307
|
case "string":
|
|
302
308
|
appendString(value2);
|
|
@@ -320,7 +326,7 @@ function canonicalJson(input, maxBytes, code = "invalid_snapshot", limits = tree
|
|
|
320
326
|
if (ancestors.has(value2)) invalid(code);
|
|
321
327
|
ancestors.add(value2);
|
|
322
328
|
try {
|
|
323
|
-
const maxChildren = depth ===
|
|
329
|
+
const maxChildren = depth === limits2.depth ? 0 : valuesLeft;
|
|
324
330
|
if (isArray(value2, code)) {
|
|
325
331
|
const length = denseArrayLength(value2, maxChildren, code);
|
|
326
332
|
if (length && 2 * length + 1 > bytesLeft) invalid(code);
|
|
@@ -360,6 +366,67 @@ function copyJsonObject(input, maxBytes, code) {
|
|
|
360
366
|
function sha256(input) {
|
|
361
367
|
return (0, import_node_crypto.createHash)("sha256").update(input).digest("hex");
|
|
362
368
|
}
|
|
369
|
+
function encodeEvidence(input, code, capacity) {
|
|
370
|
+
return canonicalJson(input, capacity?.limits.evidenceBytes ?? 8192, code, capacity?.limits.evidenceTree).encoded;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// src/internal/smtp-capacity.ts
|
|
374
|
+
var MIN_RECIPIENTS = MESSAGE_LIMITS.recipients + 1;
|
|
375
|
+
var MAX_RECIPIENTS = 1e3;
|
|
376
|
+
var KIB = 1024;
|
|
377
|
+
var limits = Object.freeze({
|
|
378
|
+
snapshotBytes: 2 * KIB * KIB,
|
|
379
|
+
snapshotTree: Object.freeze({ depth: 4, values: 4096 }),
|
|
380
|
+
evidenceBytes: 64 * KIB,
|
|
381
|
+
evidenceTree: Object.freeze({ depth: 5, values: 4096 }),
|
|
382
|
+
jobBsonBytes: 4 * KIB * KIB,
|
|
383
|
+
activityBsonBytes: 128 * KIB,
|
|
384
|
+
registryCache: Object.freeze({ min: 0, default: 8, max: 16 }),
|
|
385
|
+
registryPending: Object.freeze({ min: 1, default: 2, max: 4 }),
|
|
386
|
+
servicePending: 4,
|
|
387
|
+
workerProfiles: 16,
|
|
388
|
+
workerConcurrency: Object.freeze({ min: 1, default: 1, max: 2 }),
|
|
389
|
+
runClaims: Object.freeze({ min: 1, default: 4, max: 16 }),
|
|
390
|
+
runMaintenance: Object.freeze({ min: 0, default: 4, max: 16 }),
|
|
391
|
+
adminMaintenance: Object.freeze({ min: 1, default: 4, max: 16 }),
|
|
392
|
+
page: Object.freeze({ min: 1, default: 8, max: 16 }),
|
|
393
|
+
memoryJobs: Object.freeze({ min: 1, default: 8, max: 16 }),
|
|
394
|
+
mongoInFlight: 4,
|
|
395
|
+
dueCandidates: 4
|
|
396
|
+
});
|
|
397
|
+
function readBinding(input, code) {
|
|
398
|
+
const { format, namespace, maxRecipients } = readRecord(input, ["format", "namespace", "maxRecipients"], [], code);
|
|
399
|
+
if (format !== "smtp-v2") invalid(code);
|
|
400
|
+
return Object.freeze({
|
|
401
|
+
format,
|
|
402
|
+
namespace: uuidV4(namespace, code),
|
|
403
|
+
maxRecipients: integer(maxRecipients, MIN_RECIPIENTS, MAX_RECIPIENTS, code)
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
function capacityTag(capacity) {
|
|
407
|
+
return capacity ? { smtpCapacity: capacity.binding } : {};
|
|
408
|
+
}
|
|
409
|
+
function recipientLimit(capacity) {
|
|
410
|
+
return capacity?.binding.maxRecipients ?? MESSAGE_LIMITS.recipients;
|
|
411
|
+
}
|
|
412
|
+
function matchesBinding(input, capacity, code) {
|
|
413
|
+
const binding = readBinding(input, code);
|
|
414
|
+
if (binding.namespace !== capacity.binding.namespace || binding.maxRecipients !== capacity.binding.maxRecipients) {
|
|
415
|
+
invalid(code);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
function assertCapacityTag(raw, capacity, code) {
|
|
419
|
+
const tagged = Object.hasOwn(raw, "smtpCapacity");
|
|
420
|
+
if (capacity) {
|
|
421
|
+
if (!tagged) invalid(code);
|
|
422
|
+
matchesBinding(raw.smtpCapacity, capacity, code);
|
|
423
|
+
} else if (tagged) {
|
|
424
|
+
invalid(code);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
function assertCapacityProvider(provider, capacity, code) {
|
|
428
|
+
if (capacity && provider.kind !== "smtp") invalid(code);
|
|
429
|
+
}
|
|
363
430
|
|
|
364
431
|
// src/internal/attempt-codecs.ts
|
|
365
432
|
var smtpStages = ["connect", "tls", "auth", "envelope", "data"];
|
|
@@ -399,6 +466,7 @@ function readAttemptReason(value, code) {
|
|
|
399
466
|
if (typeof value !== "string" || !Object.hasOwn(evidence, value)) invalid(code);
|
|
400
467
|
return value;
|
|
401
468
|
}
|
|
469
|
+
var recipientGroups = ["to", "cc", "bcc"];
|
|
402
470
|
function recipientCounts(envelope) {
|
|
403
471
|
return Object.freeze({ to: envelope.to.length, cc: envelope.cc.length, bcc: envelope.bcc.length });
|
|
404
472
|
}
|
|
@@ -418,7 +486,7 @@ function readHint(input, reason, code) {
|
|
|
418
486
|
...hasFloor ? { notBefore: unixMs(raw.notBefore, code) } : {}
|
|
419
487
|
});
|
|
420
488
|
}
|
|
421
|
-
function readAttemptResult(input, code = "invalid_command", projected = false) {
|
|
489
|
+
function readAttemptResult(input, code = "invalid_command", projected = false, capacity) {
|
|
422
490
|
const raw = readRecord(
|
|
423
491
|
input,
|
|
424
492
|
["outcome", "retry", "stage", "reason"],
|
|
@@ -429,6 +497,7 @@ function readAttemptResult(input, code = "invalid_command", projected = false) {
|
|
|
429
497
|
const [outcome, retry, stages, origin] = evidence[reason];
|
|
430
498
|
const stage = stages.find((value) => value === raw.stage);
|
|
431
499
|
if (raw.outcome !== outcome || raw.retry !== retry || !stage) invalid(code);
|
|
500
|
+
if (capacity && (origin === "sendgrid" || stage === "http")) invalid(code);
|
|
432
501
|
const hasHint = Object.hasOwn(raw, "retryHint");
|
|
433
502
|
if (projected && hasHint || !projected && reason === "rate_deferred" && !hasHint) invalid(code);
|
|
434
503
|
const smtpSuccess = reason === "smtp_accepted" || reason === "smtp_partial";
|
|
@@ -438,14 +507,22 @@ function readAttemptResult(input, code = "invalid_command", projected = false) {
|
|
|
438
507
|
if (hasRecipients) {
|
|
439
508
|
if (origin !== "smtp" && origin !== "provider" || stage !== "envelope" && stage !== "data") invalid(code);
|
|
440
509
|
const seen = /* @__PURE__ */ new Set();
|
|
441
|
-
|
|
510
|
+
const limit = recipientLimit(capacity);
|
|
511
|
+
let previous = -1;
|
|
512
|
+
recipients = readArray(raw.recipients, limit, code, (value) => {
|
|
442
513
|
const { group, index: rawIndex, status } = readRecord(value, ["group", "index", "status"], [], code);
|
|
443
514
|
if (group !== "to" && group !== "cc" && group !== "bcc") invalid(code);
|
|
444
515
|
if (status !== "rejected" && (status !== "accepted" || !smtpSuccess)) invalid(code);
|
|
445
|
-
const index = integer(rawIndex, 0,
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
516
|
+
const index = integer(rawIndex, 0, limit - 1, code);
|
|
517
|
+
if (capacity) {
|
|
518
|
+
const position = recipientGroups.indexOf(group) * limit + index;
|
|
519
|
+
if (position <= previous) invalid(code);
|
|
520
|
+
previous = position;
|
|
521
|
+
} else {
|
|
522
|
+
const key = `${group}:${index}`;
|
|
523
|
+
if (seen.has(key)) invalid(code);
|
|
524
|
+
seen.add(key);
|
|
525
|
+
}
|
|
449
526
|
return Object.freeze({ group, index, status });
|
|
450
527
|
});
|
|
451
528
|
const accepted = recipients.filter(({ status }) => status === "accepted").length;
|
|
@@ -460,7 +537,7 @@ function readAttemptResult(input, code = "invalid_command", projected = false) {
|
|
|
460
537
|
if (hasProviderId && (reason !== "sendgrid_accepted" || typeof providerMessageId !== "string" || providerMessageId.length > 128 || !/^[A-Za-z0-9][A-Za-z0-9._=-]{0,127}$/.test(providerMessageId))) {
|
|
461
538
|
invalid(code);
|
|
462
539
|
}
|
|
463
|
-
|
|
540
|
+
const result = Object.freeze({
|
|
464
541
|
outcome,
|
|
465
542
|
retry,
|
|
466
543
|
stage,
|
|
@@ -470,6 +547,8 @@ function readAttemptResult(input, code = "invalid_command", projected = false) {
|
|
|
470
547
|
...typeof messageId === "string" ? { messageId } : {},
|
|
471
548
|
...typeof providerMessageId === "string" ? { providerMessageId } : {}
|
|
472
549
|
});
|
|
550
|
+
if (capacity && !projected) encodeEvidence(result, code, capacity);
|
|
551
|
+
return result;
|
|
473
552
|
}
|
|
474
553
|
function assertEvidenceContext(result, provider, attemptId, counts, code) {
|
|
475
554
|
const { reason, stage, recipients, messageId } = result;
|
|
@@ -486,9 +565,9 @@ function assertEvidenceContext(result, provider, attemptId, counts, code) {
|
|
|
486
565
|
}
|
|
487
566
|
}
|
|
488
567
|
}
|
|
489
|
-
function readProviderResult(input, provider, attemptId, envelope) {
|
|
568
|
+
function readProviderResult(input, provider, attemptId, envelope, capacity) {
|
|
490
569
|
const code = "invalid_command";
|
|
491
|
-
const result = readAttemptResult(input, code);
|
|
570
|
+
const result = readAttemptResult(input, code, false, capacity);
|
|
492
571
|
const origin = evidence[result.reason][3];
|
|
493
572
|
if (origin !== "smtp" && origin !== "sendgrid" && origin !== "provider") invalid(code);
|
|
494
573
|
assertEvidenceContext(result, provider, attemptId, recipientCounts(envelope), code);
|
|
@@ -638,7 +717,8 @@ function validateMailbox(input, code = SNAPSHOT) {
|
|
|
638
717
|
...Object.hasOwn(mailbox2, "name") ? { name: headerString(mailbox2.name, L.displayNameBytes, code) } : {}
|
|
639
718
|
});
|
|
640
719
|
}
|
|
641
|
-
function validateEnvelope(input, kind, code = SNAPSHOT) {
|
|
720
|
+
function validateEnvelope(input, kind, code = SNAPSHOT, capacity) {
|
|
721
|
+
const limit = recipientLimit(capacity);
|
|
642
722
|
const envelope = readRecord(input, ["from", "to", "cc", "bcc"], ["replyTo"], code);
|
|
643
723
|
const seen = /* @__PURE__ */ new Set();
|
|
644
724
|
const recipient = (raw) => {
|
|
@@ -649,9 +729,9 @@ function validateEnvelope(input, kind, code = SNAPSHOT) {
|
|
|
649
729
|
return mailbox2;
|
|
650
730
|
};
|
|
651
731
|
const from = validateMailbox(envelope.from, code);
|
|
652
|
-
const to = readArray(envelope.to,
|
|
653
|
-
const cc = readArray(envelope.cc,
|
|
654
|
-
const bcc = readArray(envelope.bcc,
|
|
732
|
+
const to = readArray(envelope.to, limit, code, recipient);
|
|
733
|
+
const cc = readArray(envelope.cc, limit - to.length, code, recipient);
|
|
734
|
+
const bcc = readArray(envelope.bcc, limit - to.length - cc.length, code, recipient);
|
|
655
735
|
if (seen.size === 0 || kind === "sendgrid" && to.length === 0) invalid(code);
|
|
656
736
|
return Object.freeze({
|
|
657
737
|
from,
|
|
@@ -739,12 +819,17 @@ function validateExpiry(input, preparedAt, scheduleAt, code = SNAPSHOT) {
|
|
|
739
819
|
}
|
|
740
820
|
return expiresAt;
|
|
741
821
|
}
|
|
742
|
-
function hashSnapshot(snapshot) {
|
|
822
|
+
function hashSnapshot(snapshot, capacity) {
|
|
743
823
|
return sha256(
|
|
744
|
-
canonicalJson(
|
|
824
|
+
canonicalJson(
|
|
825
|
+
snapshot,
|
|
826
|
+
capacity?.limits.snapshotBytes ?? L.snapshotBytes,
|
|
827
|
+
SNAPSHOT,
|
|
828
|
+
capacity?.limits.snapshotTree ?? { depth: L.jsonDepth + 1, values: L.jsonValues + 256 }
|
|
829
|
+
).encoded
|
|
745
830
|
);
|
|
746
831
|
}
|
|
747
|
-
function readSnapshot(input) {
|
|
832
|
+
function readSnapshot(input, capacity) {
|
|
748
833
|
const dto = readRecord(
|
|
749
834
|
input,
|
|
750
835
|
[
|
|
@@ -759,17 +844,19 @@ function readSnapshot(input) {
|
|
|
759
844
|
"attachments",
|
|
760
845
|
"correlation"
|
|
761
846
|
],
|
|
762
|
-
["subject", "html", "text", "templateId", "data"],
|
|
847
|
+
["subject", "html", "text", "templateId", "data", "smtpCapacity"],
|
|
763
848
|
SNAPSHOT
|
|
764
849
|
);
|
|
765
850
|
if (dto.version !== EMAIL_FORMAT_VERSION || dto.kind !== "smtp" && dto.kind !== "sendgrid") invalid(SNAPSHOT);
|
|
851
|
+
assertCapacityTag(dto, capacity, SNAPSHOT);
|
|
766
852
|
const provider = validateProviderRef(dto.provider);
|
|
767
853
|
if (provider.kind !== dto.kind) invalid("provider_mismatch");
|
|
854
|
+
assertCapacityProvider(provider, capacity, "provider_mismatch");
|
|
768
855
|
const preparedAt = unixMs(dto.preparedAt, SNAPSHOT);
|
|
769
856
|
const common = {
|
|
770
857
|
version: EMAIL_FORMAT_VERSION,
|
|
771
858
|
template: validateTemplateIdentity(dto.template),
|
|
772
|
-
envelope: validateEnvelope(dto.envelope, provider.kind),
|
|
859
|
+
envelope: validateEnvelope(dto.envelope, provider.kind, SNAPSHOT, capacity),
|
|
773
860
|
preparedAt,
|
|
774
861
|
expiresAt: validateExpiry(dto.expiresAt, preparedAt, null),
|
|
775
862
|
priority: integer(dto.priority, PRIORITY.min, PRIORITY.max, SNAPSHOT),
|
|
@@ -783,7 +870,7 @@ function readSnapshot(input) {
|
|
|
783
870
|
...Object.hasOwn(dto, "html") ? { html: dto.html } : {},
|
|
784
871
|
...Object.hasOwn(dto, "text") ? { text: dto.text } : {}
|
|
785
872
|
});
|
|
786
|
-
return Object.freeze({ ...common, kind: provider.kind, provider, ...content });
|
|
873
|
+
return Object.freeze({ ...common, kind: provider.kind, provider, ...capacityTag(capacity), ...content });
|
|
787
874
|
}
|
|
788
875
|
if (Object.hasOwn(dto, "subject") || Object.hasOwn(dto, "html") || Object.hasOwn(dto, "text")) invalid(SNAPSHOT);
|
|
789
876
|
return Object.freeze({
|
|
@@ -794,31 +881,28 @@ function readSnapshot(input) {
|
|
|
794
881
|
data: copyJsonObject(dto.data, L.dataBytes, SNAPSHOT)
|
|
795
882
|
});
|
|
796
883
|
}
|
|
797
|
-
function validateSnapshot(input) {
|
|
798
|
-
const snapshot = readSnapshot(input);
|
|
799
|
-
return { snapshot, snapshotHash: hashSnapshot(snapshot) };
|
|
884
|
+
function validateSnapshot(input, capacity) {
|
|
885
|
+
const snapshot = readSnapshot(input, capacity);
|
|
886
|
+
return { snapshot, snapshotHash: hashSnapshot(snapshot, capacity) };
|
|
800
887
|
}
|
|
801
888
|
|
|
802
889
|
// src/internal/store-codecs.ts
|
|
803
890
|
var REQUEST = "invalid_command";
|
|
804
891
|
var LEASE = WORKER_LIMIT_BOUNDS.leaseMs;
|
|
805
892
|
function readStoreId(value, code = REQUEST) {
|
|
806
|
-
|
|
807
|
-
invalid(code);
|
|
808
|
-
}
|
|
809
|
-
return value;
|
|
893
|
+
return uuidV4(value, code);
|
|
810
894
|
}
|
|
811
895
|
|
|
812
896
|
// src/internal/provider-preparation.ts
|
|
813
897
|
function sameRef(a, b) {
|
|
814
898
|
return a.resolverKey === b.resolverKey && a.id === b.id && a.version === b.version && a.filename === b.filename && a.contentType === b.contentType && a.byteLength === b.byteLength && a.sha256 === b.sha256;
|
|
815
899
|
}
|
|
816
|
-
function readProviderSubmission(input, ref) {
|
|
900
|
+
function readProviderSubmission(input, ref, capacity) {
|
|
817
901
|
const code = "invalid_snapshot";
|
|
818
902
|
const raw = readRecord(input, ["jobId", "attemptId", "snapshot", "attachments"], [], code);
|
|
819
903
|
const jobId = readStoreId(raw.jobId, code);
|
|
820
904
|
const attemptId = readStoreId(raw.attemptId, code);
|
|
821
|
-
const { snapshot } = validateSnapshot(raw.snapshot);
|
|
905
|
+
const { snapshot } = validateSnapshot(raw.snapshot, capacity);
|
|
822
906
|
if (ref.kind !== snapshot.kind || ref.key !== snapshot.provider.key || ref.mode !== snapshot.provider.mode) {
|
|
823
907
|
invalid("provider_mismatch");
|
|
824
908
|
}
|