@web-ts-toolkit/email-service 0.73.0 → 0.74.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/mongoose.mjs CHANGED
@@ -364,7 +364,7 @@ function encodeEvidence(input, code, capacity) {
364
364
 
365
365
  // src/internal/smtp-capacity.ts
366
366
  var MIN_RECIPIENTS = MESSAGE_LIMITS.recipients + 1;
367
- var MAX_RECIPIENTS = 1e3;
367
+ var MAX_SMTP_RECIPIENTS = 1e3;
368
368
  var KIB = 1024;
369
369
  var limits = Object.freeze({
370
370
  snapshotBytes: 2 * KIB * KIB,
@@ -392,7 +392,7 @@ function readBinding(input, code) {
392
392
  return Object.freeze({
393
393
  format,
394
394
  namespace: uuidV4(namespace, code),
395
- maxRecipients: integer(maxRecipients, MIN_RECIPIENTS, MAX_RECIPIENTS, code)
395
+ maxRecipients: integer(maxRecipients, MIN_RECIPIENTS, MAX_SMTP_RECIPIENTS, code)
396
396
  });
397
397
  }
398
398
  function readCapacityOption(raw) {
@@ -478,6 +478,26 @@ function readRecipientCounts(input, code, capacity) {
478
478
  function smtpMessageId(attemptId) {
479
479
  return `<${attemptId}@email.invalid>`;
480
480
  }
481
+ function readRecipientResults(input, code, { limit, allowAccepted, ordered }) {
482
+ const seen = /* @__PURE__ */ new Set();
483
+ let previous = -1;
484
+ return readArray(input, limit, code, (value) => {
485
+ const { group, index: rawIndex, status } = readRecord(value, ["group", "index", "status"], [], code);
486
+ if (group !== "to" && group !== "cc" && group !== "bcc") invalid(code);
487
+ if (status !== "rejected" && (status !== "accepted" || !allowAccepted)) invalid(code);
488
+ const index = integer(rawIndex, 0, limit - 1, code);
489
+ if (ordered) {
490
+ const position = recipientGroups.indexOf(group) * limit + index;
491
+ if (position <= previous) invalid(code);
492
+ previous = position;
493
+ } else {
494
+ const key = `${group}:${index}`;
495
+ if (seen.has(key)) invalid(code);
496
+ seen.add(key);
497
+ }
498
+ return Object.freeze({ group, index, status });
499
+ });
500
+ }
481
501
  function readHint(input, reason, code) {
482
502
  if (reason !== "rate_deferred" && reason !== "sendgrid_throttled") invalid(code);
483
503
  const raw = readRecord(input, [], ["delayMs", "notBefore"], code);
@@ -511,24 +531,10 @@ function readAttemptResult(input, code = "invalid_command", projected = false, c
511
531
  let recipients;
512
532
  if (hasRecipients) {
513
533
  if (origin !== "smtp" && origin !== "provider" || stage !== "envelope" && stage !== "data") invalid(code);
514
- const seen = /* @__PURE__ */ new Set();
515
- const limit = recipientLimit(capacity);
516
- let previous = -1;
517
- recipients = readArray(raw.recipients, limit, code, (value) => {
518
- const { group, index: rawIndex, status } = readRecord(value, ["group", "index", "status"], [], code);
519
- if (group !== "to" && group !== "cc" && group !== "bcc") invalid(code);
520
- if (status !== "rejected" && (status !== "accepted" || !smtpSuccess)) invalid(code);
521
- const index = integer(rawIndex, 0, limit - 1, code);
522
- if (capacity) {
523
- const position = recipientGroups.indexOf(group) * limit + index;
524
- if (position <= previous) invalid(code);
525
- previous = position;
526
- } else {
527
- const key = `${group}:${index}`;
528
- if (seen.has(key)) invalid(code);
529
- seen.add(key);
530
- }
531
- return Object.freeze({ group, index, status });
534
+ recipients = readRecipientResults(raw.recipients, code, {
535
+ limit: recipientLimit(capacity),
536
+ allowAccepted: smtpSuccess,
537
+ ordered: Boolean(capacity)
532
538
  });
533
539
  const accepted = recipients.filter(({ status }) => status === "accepted").length;
534
540
  if (reason === "smtp_accepted" && (!accepted || accepted !== recipients.length) || reason === "smtp_partial" && (!accepted || accepted === recipients.length)) {
@@ -1687,6 +1693,11 @@ function readJobRecord(scope2, input, capacity) {
1687
1693
  return job;
1688
1694
  }
1689
1695
 
1696
+ // src/internal/smtp-attachments.ts
1697
+ function assertSmtpAttachmentTypes(refs) {
1698
+ if (refs.some(({ contentType }) => /^(?:message|multipart)\//.test(contentType))) invalid("invalid_snapshot");
1699
+ }
1700
+
1690
1701
  // src/internal/job-transitions.ts
1691
1702
  function guard(job, { now }, before) {
1692
1703
  if (unixMs(now, "store_unavailable") < job.updatedAt || before !== void 0 && now >= before) {
@@ -1717,6 +1728,7 @@ function newJob(admission, time2, capacity) {
1717
1728
  if (snapshot.preparedAt - now > MAX_PREPARED_AT_SKEW_MS) invalid("invalid_snapshot");
1718
1729
  const nextAt = Math.max(now, scheduleAt ?? now);
1719
1730
  if (nextAt >= snapshot.expiresAt) invalid("expired");
1731
+ if (snapshot.kind === "smtp") assertSmtpAttachmentTypes(snapshot.attachments);
1720
1732
  return Object.freeze({
1721
1733
  version: EMAIL_FORMAT_VERSION,
1722
1734
  ...capacityTag(capacity),
@@ -1759,9 +1771,13 @@ function liveLease(job, fence, phase, now) {
1759
1771
  }
1760
1772
  return lease;
1761
1773
  }
1774
+ function claimEligibility(job, now) {
1775
+ if (job.state.state !== "queued" || job.state.nextAt > now) return "not_due";
1776
+ return now >= job.expiresAt ? "expired" : "eligible";
1777
+ }
1762
1778
  function claimJob(job, claim, time2, capacity) {
1763
1779
  const { now } = time2;
1764
- if (job.state.state !== "queued" || job.state.nextAt > now || now >= job.expiresAt) return null;
1780
+ if (claimEligibility(job, now) !== "eligible") return null;
1765
1781
  const manual = hasRedrive(job);
1766
1782
  const ordinal2 = job.attempts.length + 1;
1767
1783
  if (ordinal2 > MAX_ATTEMPT_LEDGER || !manual && ordinal2 > job.retry.maxAttempts) invalid("store_incompatible");
@@ -1789,6 +1805,20 @@ function claimJob(job, claim, time2, capacity) {
1789
1805
  Math.min(job.expiresAt, lease.leaseEndsAt)
1790
1806
  );
1791
1807
  }
1808
+ var EXPIRY_MAINTENANCE_REQUIRED = Object.freeze({ status: "expiry_maintenance_required" });
1809
+ function claimWindow(claim, candidateLimit, capacity) {
1810
+ let expired = 0;
1811
+ return {
1812
+ decide(job, time2) {
1813
+ const decision = claimJob(job, claim, time2, capacity);
1814
+ if (decision === null && claimEligibility(job, time2.now) === "expired") expired++;
1815
+ return decision;
1816
+ },
1817
+ result(next) {
1818
+ return next.status !== "applied" && expired === candidateLimit ? EXPIRY_MAINTENANCE_REQUIRED : next;
1819
+ }
1820
+ };
1821
+ }
1792
1822
  function renewJob(job, fence, leaseMs, time2) {
1793
1823
  const lease = liveLease(job, fence, "pre_handoff", time2.now);
1794
1824
  if (!lease || time2.now >= job.expiresAt) return null;
@@ -2902,6 +2932,13 @@ var MongoOperations = class {
2902
2932
  }
2903
2933
  return invalid("busy");
2904
2934
  }
2935
+ get dueCandidateLimit() {
2936
+ return this.capacity?.limits.dueCandidates ?? MAX_STORE_CANDIDATES;
2937
+ }
2938
+ async claimNext(scope2, claim) {
2939
+ const window = claimWindow(claim, this.dueCandidateLimit, this.capacity);
2940
+ return window.result(await this.next(scope2, "nextAt", window.decide));
2941
+ }
2905
2942
  async next(scope2, due, decide) {
2906
2943
  const selectionAt = await this.now();
2907
2944
  const { name, state, sort } = dueIndexes[due];
@@ -2913,7 +2950,7 @@ var MongoOperations = class {
2913
2950
  [due]: { $exists: true, $lte: selectionAt }
2914
2951
  },
2915
2952
  name,
2916
- this.capacity?.limits.dueCandidates ?? MAX_STORE_CANDIDATES,
2953
+ this.dueCandidateLimit,
2917
2954
  "majority",
2918
2955
  sort,
2919
2956
  { _id: 0, jobId: 1 }
@@ -3194,7 +3231,7 @@ function createMongooseEmailStore(connection, options = {}) {
3194
3231
  claimNext(scope2, input, call) {
3195
3232
  return run(call, true, (ops) => {
3196
3233
  const safe = readClaim(input);
3197
- return ops.next(scopeToken(scope2), "nextAt", (job, time2) => claimJob(job, safe, time2, capacity));
3234
+ return ops.claimNext(scopeToken(scope2), safe);
3198
3235
  });
3199
3236
  },
3200
3237
  renew(scope2, fence, leaseMs, call) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@web-ts-toolkit/email-service",
3
3
  "description": "Typed email preparation, queue and submission contracts for Node.js",
4
- "version": "0.73.0",
4
+ "version": "0.74.0",
5
5
  "keywords": [
6
6
  "email",
7
7
  "handlebars",
@@ -62,6 +62,7 @@ type AttachmentRef = {
62
62
  readonly id: string;
63
63
  readonly version: string;
64
64
  readonly filename: string;
65
+ /** Lower-case MIME `type/subtype` without parameters. New SMTP messages reject `message/*` and `multipart/*`. */
65
66
  readonly contentType: string;
66
67
  readonly byteLength: number;
67
68
  readonly sha256: string;
@@ -152,7 +153,7 @@ type RetryHint = {
152
153
  readonly notBefore?: UnixMs;
153
154
  };
154
155
  /** Normalized, bounded evidence; never a raw SDK code or response message. */
155
- type ProviderReason = 'smtp_accepted' | 'smtp_partial' | 'smtp_transient_reply' | 'smtp_permanent_reply' | 'sendgrid_accepted' | 'sendgrid_validated' | 'sendgrid_throttled' | 'sendgrid_rejected' | 'not_transmitted' | 'provider_configuration' | 'transport_uncertain' | 'provider_timeout' | 'provider_aborted';
156
+ type ProviderReason = ProviderResult['reason'];
156
157
  type AttemptReason = ProviderReason | 'attachment_unavailable' | 'attachment_timeout' | 'attachment_invalid' | 'attachment_resolver_error' | 'rate_deferred' | 'rate_timeout' | 'rate_error' | 'profile_unavailable' | 'provider_preflight_error' | 'pre_handoff_timeout' | 'worker_stopped' | 'pre_handoff_lease_expired' | 'launch_window_closed' | 'post_handoff_lease_expired' | 'expired' | 'cancelled';
157
158
  type AttemptResult = {
158
159
  readonly outcome: SubmissionOutcome;
@@ -164,10 +165,51 @@ type AttemptResult = {
164
165
  readonly messageId?: string;
165
166
  readonly providerMessageId?: string;
166
167
  };
167
- type ProviderResult = Omit<AttemptResult, 'stage' | 'reason'> & {
168
- readonly stage: Exclude<SubmissionStage, 'pre_handoff' | 'attachment' | 'rate_limit'>;
169
- readonly reason: ProviderReason;
170
- };
168
+ type ProviderStage = Exclude<SubmissionStage, 'pre_handoff' | 'attachment' | 'rate_limit'>;
169
+ type SmtpStage = Exclude<ProviderStage, 'http'>;
170
+ type EvidenceField = 'recipients' | 'messageId' | 'providerMessageId' | 'retryHint';
171
+ type ProviderEvidence<Reason extends string, Outcome extends SubmissionOutcome, Retry extends RetryClass, Stage extends ProviderStage, Details = Record<never, never>> = Readonly<{
172
+ reason: Reason;
173
+ outcome: Outcome;
174
+ retry: Retry;
175
+ stage: Stage;
176
+ }> & Readonly<Details> & {
177
+ readonly [Field in Exclude<EvidenceField, keyof Details>]?: never;
178
+ };
179
+ type RecipientWithStatus<Status extends RecipientResult['status']> = RecipientResult & {
180
+ readonly status: Status;
181
+ };
182
+ type AcceptedSmtpRecipients = readonly [RecipientWithStatus<'accepted'>, ...RecipientWithStatus<'accepted'>[]];
183
+ type MixedSmtpRecipients = readonly [RecipientResult, RecipientResult, ...RecipientResult[]] & {
184
+ readonly __checkedSmtpMixedRecipients: never;
185
+ };
186
+ type SmtpAcceptance<Recipients extends readonly RecipientResult[]> = {
187
+ recipients: Recipients;
188
+ messageId?: string;
189
+ };
190
+ type RejectedRecipients = {
191
+ readonly recipients?: never;
192
+ } | {
193
+ readonly stage: 'envelope' | 'data';
194
+ readonly recipients: readonly RecipientWithStatus<'rejected'>[];
195
+ };
196
+ type ThrottleHint = RetryHint & (Readonly<{
197
+ delayMs: number;
198
+ }> | Readonly<{
199
+ notBefore: UnixMs;
200
+ }>);
201
+ type TransportEvidence<Reason extends string, Outcome extends SubmissionOutcome, Retry extends RetryClass> = Reason extends string ? ProviderEvidence<Reason, Outcome, Retry, ProviderStage, RejectedRecipients> : never;
202
+ /**
203
+ * Submission evidence discriminated by `reason`. Full SMTP acceptance requires a nonempty
204
+ * all-accepted tuple. Use `createSmtpAcceptanceResult` to check a dynamic list or produce
205
+ * partial acceptance. The worker still checks the actual envelope and profile kind/mode.
206
+ * Invalid evidence after handoff is unknown, not permission to retry.
207
+ */
208
+ type ProviderResult = ProviderEvidence<'smtp_accepted', 'accepted', 'never', 'data', SmtpAcceptance<AcceptedSmtpRecipients>> | ProviderEvidence<'smtp_partial', 'partially_accepted', 'never', 'data', SmtpAcceptance<MixedSmtpRecipients>> | ProviderEvidence<'smtp_transient_reply', 'rejected', 'safe_transient', SmtpStage, RejectedRecipients> | ProviderEvidence<'smtp_permanent_reply', 'rejected', 'never', SmtpStage, RejectedRecipients> | ProviderEvidence<'sendgrid_accepted', 'accepted', 'never', 'http', {
209
+ providerMessageId?: string;
210
+ }> | ProviderEvidence<'sendgrid_validated', 'validated', 'never', 'http'> | ProviderEvidence<'sendgrid_throttled', 'rejected', 'safe_transient', 'http', {
211
+ retryHint?: ThrottleHint;
212
+ }> | ProviderEvidence<'sendgrid_rejected', 'rejected', 'never', 'http'> | TransportEvidence<'not_transmitted', 'unsubmitted', 'safe_transient'> | TransportEvidence<'provider_configuration', 'unsubmitted', 'never'> | TransportEvidence<'transport_uncertain' | 'provider_timeout' | 'provider_aborted', 'unknown', 'never'>;
171
213
  type ProviderSubmission<M extends EmailSnapshot> = {
172
214
  readonly jobId: EmailJobId;
173
215
  readonly attemptId: EmailAttemptId;
@@ -196,4 +238,4 @@ interface EmailProvider<M extends EmailSnapshot> {
196
238
  }
197
239
  type ConfiguredEmailProvider = EmailProvider<SmtpSnapshot> | EmailProvider<SendGridSnapshot>;
198
240
 
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 };
241
+ 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, ProviderResult as h, AttachmentResolution as i, AttachmentResolver as j, AttemptReason as k, AttemptResult as l, ConfiguredEmailProvider as m, EmailAttemptId as n, EmailJobId as o, EmailProvider as p, EmailSnapshot as q, PreparedEmailSubmission as r, ProviderCall as s, ProviderReason as t, ProviderSubmission as u, ResolvedAttachment as v, RetryClass as w, RetryHint as x, SendGridSnapshot as y, SmtpSnapshot as z };
@@ -62,6 +62,7 @@ type AttachmentRef = {
62
62
  readonly id: string;
63
63
  readonly version: string;
64
64
  readonly filename: string;
65
+ /** Lower-case MIME `type/subtype` without parameters. New SMTP messages reject `message/*` and `multipart/*`. */
65
66
  readonly contentType: string;
66
67
  readonly byteLength: number;
67
68
  readonly sha256: string;
@@ -152,7 +153,7 @@ type RetryHint = {
152
153
  readonly notBefore?: UnixMs;
153
154
  };
154
155
  /** Normalized, bounded evidence; never a raw SDK code or response message. */
155
- type ProviderReason = 'smtp_accepted' | 'smtp_partial' | 'smtp_transient_reply' | 'smtp_permanent_reply' | 'sendgrid_accepted' | 'sendgrid_validated' | 'sendgrid_throttled' | 'sendgrid_rejected' | 'not_transmitted' | 'provider_configuration' | 'transport_uncertain' | 'provider_timeout' | 'provider_aborted';
156
+ type ProviderReason = ProviderResult['reason'];
156
157
  type AttemptReason = ProviderReason | 'attachment_unavailable' | 'attachment_timeout' | 'attachment_invalid' | 'attachment_resolver_error' | 'rate_deferred' | 'rate_timeout' | 'rate_error' | 'profile_unavailable' | 'provider_preflight_error' | 'pre_handoff_timeout' | 'worker_stopped' | 'pre_handoff_lease_expired' | 'launch_window_closed' | 'post_handoff_lease_expired' | 'expired' | 'cancelled';
157
158
  type AttemptResult = {
158
159
  readonly outcome: SubmissionOutcome;
@@ -164,10 +165,51 @@ type AttemptResult = {
164
165
  readonly messageId?: string;
165
166
  readonly providerMessageId?: string;
166
167
  };
167
- type ProviderResult = Omit<AttemptResult, 'stage' | 'reason'> & {
168
- readonly stage: Exclude<SubmissionStage, 'pre_handoff' | 'attachment' | 'rate_limit'>;
169
- readonly reason: ProviderReason;
170
- };
168
+ type ProviderStage = Exclude<SubmissionStage, 'pre_handoff' | 'attachment' | 'rate_limit'>;
169
+ type SmtpStage = Exclude<ProviderStage, 'http'>;
170
+ type EvidenceField = 'recipients' | 'messageId' | 'providerMessageId' | 'retryHint';
171
+ type ProviderEvidence<Reason extends string, Outcome extends SubmissionOutcome, Retry extends RetryClass, Stage extends ProviderStage, Details = Record<never, never>> = Readonly<{
172
+ reason: Reason;
173
+ outcome: Outcome;
174
+ retry: Retry;
175
+ stage: Stage;
176
+ }> & Readonly<Details> & {
177
+ readonly [Field in Exclude<EvidenceField, keyof Details>]?: never;
178
+ };
179
+ type RecipientWithStatus<Status extends RecipientResult['status']> = RecipientResult & {
180
+ readonly status: Status;
181
+ };
182
+ type AcceptedSmtpRecipients = readonly [RecipientWithStatus<'accepted'>, ...RecipientWithStatus<'accepted'>[]];
183
+ type MixedSmtpRecipients = readonly [RecipientResult, RecipientResult, ...RecipientResult[]] & {
184
+ readonly __checkedSmtpMixedRecipients: never;
185
+ };
186
+ type SmtpAcceptance<Recipients extends readonly RecipientResult[]> = {
187
+ recipients: Recipients;
188
+ messageId?: string;
189
+ };
190
+ type RejectedRecipients = {
191
+ readonly recipients?: never;
192
+ } | {
193
+ readonly stage: 'envelope' | 'data';
194
+ readonly recipients: readonly RecipientWithStatus<'rejected'>[];
195
+ };
196
+ type ThrottleHint = RetryHint & (Readonly<{
197
+ delayMs: number;
198
+ }> | Readonly<{
199
+ notBefore: UnixMs;
200
+ }>);
201
+ type TransportEvidence<Reason extends string, Outcome extends SubmissionOutcome, Retry extends RetryClass> = Reason extends string ? ProviderEvidence<Reason, Outcome, Retry, ProviderStage, RejectedRecipients> : never;
202
+ /**
203
+ * Submission evidence discriminated by `reason`. Full SMTP acceptance requires a nonempty
204
+ * all-accepted tuple. Use `createSmtpAcceptanceResult` to check a dynamic list or produce
205
+ * partial acceptance. The worker still checks the actual envelope and profile kind/mode.
206
+ * Invalid evidence after handoff is unknown, not permission to retry.
207
+ */
208
+ type ProviderResult = ProviderEvidence<'smtp_accepted', 'accepted', 'never', 'data', SmtpAcceptance<AcceptedSmtpRecipients>> | ProviderEvidence<'smtp_partial', 'partially_accepted', 'never', 'data', SmtpAcceptance<MixedSmtpRecipients>> | ProviderEvidence<'smtp_transient_reply', 'rejected', 'safe_transient', SmtpStage, RejectedRecipients> | ProviderEvidence<'smtp_permanent_reply', 'rejected', 'never', SmtpStage, RejectedRecipients> | ProviderEvidence<'sendgrid_accepted', 'accepted', 'never', 'http', {
209
+ providerMessageId?: string;
210
+ }> | ProviderEvidence<'sendgrid_validated', 'validated', 'never', 'http'> | ProviderEvidence<'sendgrid_throttled', 'rejected', 'safe_transient', 'http', {
211
+ retryHint?: ThrottleHint;
212
+ }> | ProviderEvidence<'sendgrid_rejected', 'rejected', 'never', 'http'> | TransportEvidence<'not_transmitted', 'unsubmitted', 'safe_transient'> | TransportEvidence<'provider_configuration', 'unsubmitted', 'never'> | TransportEvidence<'transport_uncertain' | 'provider_timeout' | 'provider_aborted', 'unknown', 'never'>;
171
213
  type ProviderSubmission<M extends EmailSnapshot> = {
172
214
  readonly jobId: EmailJobId;
173
215
  readonly attemptId: EmailAttemptId;
@@ -196,4 +238,4 @@ interface EmailProvider<M extends EmailSnapshot> {
196
238
  }
197
239
  type ConfiguredEmailProvider = EmailProvider<SmtpSnapshot> | EmailProvider<SendGridSnapshot>;
198
240
 
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 };
241
+ 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, ProviderResult as h, AttachmentResolution as i, AttachmentResolver as j, AttemptReason as k, AttemptResult as l, ConfiguredEmailProvider as m, EmailAttemptId as n, EmailJobId as o, EmailProvider as p, EmailSnapshot as q, PreparedEmailSubmission as r, ProviderCall as s, ProviderReason 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, y as SendGridSnapshot } from './provider-DC_av0SQ.mjs';
1
+ import { p as EmailProvider, y as SendGridSnapshot } from './provider-CeUryYAf.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, y as SendGridSnapshot } from './provider-DC_av0SQ.js';
1
+ import { p as EmailProvider, y as SendGridSnapshot } from './provider-CeUryYAf.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
@@ -372,7 +372,7 @@ function encodeEvidence(input, code, capacity) {
372
372
 
373
373
  // src/internal/smtp-capacity.ts
374
374
  var MIN_RECIPIENTS = MESSAGE_LIMITS.recipients + 1;
375
- var MAX_RECIPIENTS = 1e3;
375
+ var MAX_SMTP_RECIPIENTS = 1e3;
376
376
  var KIB = 1024;
377
377
  var limits = Object.freeze({
378
378
  snapshotBytes: 2 * KIB * KIB,
@@ -400,7 +400,7 @@ function readBinding(input, code) {
400
400
  return Object.freeze({
401
401
  format,
402
402
  namespace: uuidV4(namespace, code),
403
- maxRecipients: integer(maxRecipients, MIN_RECIPIENTS, MAX_RECIPIENTS, code)
403
+ maxRecipients: integer(maxRecipients, MIN_RECIPIENTS, MAX_SMTP_RECIPIENTS, code)
404
404
  });
405
405
  }
406
406
  function capacityTag(capacity) {
@@ -473,6 +473,26 @@ function recipientCounts(envelope) {
473
473
  function smtpMessageId(attemptId) {
474
474
  return `<${attemptId}@email.invalid>`;
475
475
  }
476
+ function readRecipientResults(input, code, { limit, allowAccepted, ordered }) {
477
+ const seen = /* @__PURE__ */ new Set();
478
+ let previous = -1;
479
+ return readArray(input, limit, code, (value) => {
480
+ const { group, index: rawIndex, status } = readRecord(value, ["group", "index", "status"], [], code);
481
+ if (group !== "to" && group !== "cc" && group !== "bcc") invalid(code);
482
+ if (status !== "rejected" && (status !== "accepted" || !allowAccepted)) invalid(code);
483
+ const index = integer(rawIndex, 0, limit - 1, code);
484
+ if (ordered) {
485
+ const position = recipientGroups.indexOf(group) * limit + index;
486
+ if (position <= previous) invalid(code);
487
+ previous = position;
488
+ } else {
489
+ const key = `${group}:${index}`;
490
+ if (seen.has(key)) invalid(code);
491
+ seen.add(key);
492
+ }
493
+ return Object.freeze({ group, index, status });
494
+ });
495
+ }
476
496
  function readHint(input, reason, code) {
477
497
  if (reason !== "rate_deferred" && reason !== "sendgrid_throttled") invalid(code);
478
498
  const raw = readRecord(input, [], ["delayMs", "notBefore"], code);
@@ -506,24 +526,10 @@ function readAttemptResult(input, code = "invalid_command", projected = false, c
506
526
  let recipients;
507
527
  if (hasRecipients) {
508
528
  if (origin !== "smtp" && origin !== "provider" || stage !== "envelope" && stage !== "data") invalid(code);
509
- const seen = /* @__PURE__ */ new Set();
510
- const limit = recipientLimit(capacity);
511
- let previous = -1;
512
- recipients = readArray(raw.recipients, limit, code, (value) => {
513
- const { group, index: rawIndex, status } = readRecord(value, ["group", "index", "status"], [], code);
514
- if (group !== "to" && group !== "cc" && group !== "bcc") invalid(code);
515
- if (status !== "rejected" && (status !== "accepted" || !smtpSuccess)) invalid(code);
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
- }
526
- return Object.freeze({ group, index, status });
529
+ recipients = readRecipientResults(raw.recipients, code, {
530
+ limit: recipientLimit(capacity),
531
+ allowAccepted: smtpSuccess,
532
+ ordered: Boolean(capacity)
527
533
  });
528
534
  const accepted = recipients.filter(({ status }) => status === "accepted").length;
529
535
  if (reason === "smtp_accepted" && (!accepted || accepted !== recipients.length) || reason === "smtp_partial" && (!accepted || accepted === recipients.length)) {
@@ -982,11 +988,9 @@ function retryHint(after, reset, now) {
982
988
  const delayMs = after !== void 0 && SECONDS.test(after) ? secondsMs(after) : void 0;
983
989
  const date = after !== void 0 && delayMs === void 0 ? httpDate(after, now) : void 0;
984
990
  const resetMs = reset !== void 0 && SECONDS.test(reset) ? secondsMs(reset) : void 0;
985
- if (delayMs === void 0 && date === void 0 && resetMs === void 0) return;
986
- return {
987
- ...delayMs === void 0 ? {} : { delayMs },
988
- ...date === void 0 && resetMs === void 0 ? {} : { notBefore: Math.max(date ?? 0, resetMs ?? 0) }
989
- };
991
+ const notBefore = date === void 0 && resetMs === void 0 ? void 0 : Math.max(date ?? 0, resetMs ?? 0);
992
+ if (delayMs !== void 0) return notBefore === void 0 ? { delayMs } : { delayMs, notBefore };
993
+ if (notBefore !== void 0) return { notBefore };
990
994
  }
991
995
 
992
996
  // src/providers/sendgrid/response.ts
package/sendgrid.mjs CHANGED
@@ -346,7 +346,7 @@ function encodeEvidence(input, code, capacity) {
346
346
 
347
347
  // src/internal/smtp-capacity.ts
348
348
  var MIN_RECIPIENTS = MESSAGE_LIMITS.recipients + 1;
349
- var MAX_RECIPIENTS = 1e3;
349
+ var MAX_SMTP_RECIPIENTS = 1e3;
350
350
  var KIB = 1024;
351
351
  var limits = Object.freeze({
352
352
  snapshotBytes: 2 * KIB * KIB,
@@ -374,7 +374,7 @@ function readBinding(input, code) {
374
374
  return Object.freeze({
375
375
  format,
376
376
  namespace: uuidV4(namespace, code),
377
- maxRecipients: integer(maxRecipients, MIN_RECIPIENTS, MAX_RECIPIENTS, code)
377
+ maxRecipients: integer(maxRecipients, MIN_RECIPIENTS, MAX_SMTP_RECIPIENTS, code)
378
378
  });
379
379
  }
380
380
  function capacityTag(capacity) {
@@ -447,6 +447,26 @@ function recipientCounts(envelope) {
447
447
  function smtpMessageId(attemptId) {
448
448
  return `<${attemptId}@email.invalid>`;
449
449
  }
450
+ function readRecipientResults(input, code, { limit, allowAccepted, ordered }) {
451
+ const seen = /* @__PURE__ */ new Set();
452
+ let previous = -1;
453
+ return readArray(input, limit, code, (value) => {
454
+ const { group, index: rawIndex, status } = readRecord(value, ["group", "index", "status"], [], code);
455
+ if (group !== "to" && group !== "cc" && group !== "bcc") invalid(code);
456
+ if (status !== "rejected" && (status !== "accepted" || !allowAccepted)) invalid(code);
457
+ const index = integer(rawIndex, 0, limit - 1, code);
458
+ if (ordered) {
459
+ const position = recipientGroups.indexOf(group) * limit + index;
460
+ if (position <= previous) invalid(code);
461
+ previous = position;
462
+ } else {
463
+ const key = `${group}:${index}`;
464
+ if (seen.has(key)) invalid(code);
465
+ seen.add(key);
466
+ }
467
+ return Object.freeze({ group, index, status });
468
+ });
469
+ }
450
470
  function readHint(input, reason, code) {
451
471
  if (reason !== "rate_deferred" && reason !== "sendgrid_throttled") invalid(code);
452
472
  const raw = readRecord(input, [], ["delayMs", "notBefore"], code);
@@ -480,24 +500,10 @@ function readAttemptResult(input, code = "invalid_command", projected = false, c
480
500
  let recipients;
481
501
  if (hasRecipients) {
482
502
  if (origin !== "smtp" && origin !== "provider" || stage !== "envelope" && stage !== "data") invalid(code);
483
- const seen = /* @__PURE__ */ new Set();
484
- const limit = recipientLimit(capacity);
485
- let previous = -1;
486
- recipients = readArray(raw.recipients, limit, code, (value) => {
487
- const { group, index: rawIndex, status } = readRecord(value, ["group", "index", "status"], [], code);
488
- if (group !== "to" && group !== "cc" && group !== "bcc") invalid(code);
489
- if (status !== "rejected" && (status !== "accepted" || !smtpSuccess)) invalid(code);
490
- const index = integer(rawIndex, 0, limit - 1, code);
491
- if (capacity) {
492
- const position = recipientGroups.indexOf(group) * limit + index;
493
- if (position <= previous) invalid(code);
494
- previous = position;
495
- } else {
496
- const key = `${group}:${index}`;
497
- if (seen.has(key)) invalid(code);
498
- seen.add(key);
499
- }
500
- return Object.freeze({ group, index, status });
503
+ recipients = readRecipientResults(raw.recipients, code, {
504
+ limit: recipientLimit(capacity),
505
+ allowAccepted: smtpSuccess,
506
+ ordered: Boolean(capacity)
501
507
  });
502
508
  const accepted = recipients.filter(({ status }) => status === "accepted").length;
503
509
  if (reason === "smtp_accepted" && (!accepted || accepted !== recipients.length) || reason === "smtp_partial" && (!accepted || accepted === recipients.length)) {
@@ -956,11 +962,9 @@ function retryHint(after, reset, now) {
956
962
  const delayMs = after !== void 0 && SECONDS.test(after) ? secondsMs(after) : void 0;
957
963
  const date = after !== void 0 && delayMs === void 0 ? httpDate(after, now) : void 0;
958
964
  const resetMs = reset !== void 0 && SECONDS.test(reset) ? secondsMs(reset) : void 0;
959
- if (delayMs === void 0 && date === void 0 && resetMs === void 0) return;
960
- return {
961
- ...delayMs === void 0 ? {} : { delayMs },
962
- ...date === void 0 && resetMs === void 0 ? {} : { notBefore: Math.max(date ?? 0, resetMs ?? 0) }
963
- };
965
+ const notBefore = date === void 0 && resetMs === void 0 ? void 0 : Math.max(date ?? 0, resetMs ?? 0);
966
+ if (delayMs !== void 0) return notBefore === void 0 ? { delayMs } : { delayMs, notBefore };
967
+ if (notBefore !== void 0) return { notBefore };
964
968
  }
965
969
 
966
970
  // src/providers/sendgrid/response.ts
package/smtp.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { S as SmtpCapacity, o as EmailProvider, z as SmtpSnapshot } from './provider-DC_av0SQ.mjs';
1
+ import { S as SmtpCapacity, p as EmailProvider, z as SmtpSnapshot } from './provider-CeUryYAf.mjs';
2
2
 
3
3
  /** Configuration for a direct, unpooled ESMTP connection with verified TLS 1.2 or newer. */
4
4
  type SmtpProviderOptions = {
@@ -10,7 +10,10 @@ type SmtpProviderOptions = {
10
10
  /** Defaults to 465 for implicit TLS or 587 for required STARTTLS. */
11
11
  port?: number;
12
12
  tls: 'implicit' | 'starttls';
13
- /** Optional DNS name for SNI and certificate verification. Otherwise verify `host`, including IP SANs. */
13
+ /**
14
+ * Optional DNS name for TLS SNI and server certificate verification. Otherwise verify `host`,
15
+ * including IP SANs. This does not change the fixed `EHLO email.invalid` client greeting.
16
+ */
14
17
  servername?: string;
15
18
  /** PEM CA certificates (one per entry). Replaces the default Node trust roots when provided. */
16
19
  ca?: readonly string[];
package/smtp.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { S as SmtpCapacity, o as EmailProvider, z as SmtpSnapshot } from './provider-DC_av0SQ.js';
1
+ import { S as SmtpCapacity, p as EmailProvider, z as SmtpSnapshot } from './provider-CeUryYAf.js';
2
2
 
3
3
  /** Configuration for a direct, unpooled ESMTP connection with verified TLS 1.2 or newer. */
4
4
  type SmtpProviderOptions = {
@@ -10,7 +10,10 @@ type SmtpProviderOptions = {
10
10
  /** Defaults to 465 for implicit TLS or 587 for required STARTTLS. */
11
11
  port?: number;
12
12
  tls: 'implicit' | 'starttls';
13
- /** Optional DNS name for SNI and certificate verification. Otherwise verify `host`, including IP SANs. */
13
+ /**
14
+ * Optional DNS name for TLS SNI and server certificate verification. Otherwise verify `host`,
15
+ * including IP SANs. This does not change the fixed `EHLO email.invalid` client greeting.
16
+ */
14
17
  servername?: string;
15
18
  /** PEM CA certificates (one per entry). Replaces the default Node trust roots when provided. */
16
19
  ca?: readonly string[];