mailery 0.2.0 → 0.2.2

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.
@@ -365,6 +365,54 @@ type QueueDriverConfig = {
365
365
  driver: 'noop';
366
366
  };
367
367
 
368
+ /**
369
+ * Shared enums — string-literal unions for status fields and other discriminators.
370
+ * Kept separate from types.ts so the client can import these without pulling in
371
+ * server-shaped interfaces.
372
+ */
373
+ type SubscriptionStatus = 'subscribed' | 'pending_doi' | 'unsubscribed' | 'bounced' | 'complained';
374
+ type SendStatus = 'queued' | 'sending' | 'sent' | 'delivered' | 'bounced' | 'complained' | 'failed' | 'suppressed';
375
+ type TemplateKind = 'transactional' | 'marketing';
376
+ type SuppressionScope = 'all' | 'marketing' | 'transactional';
377
+ type SuppressionReason = 'unsubscribed' | 'hard_bounce' | 'complaint' | 'manual' | 'list_cleaning' | 'gdpr_forget';
378
+ type FlowRunStatus = 'active' | 'completed' | 'exited' | 'failed';
379
+ type BroadcastStatus = 'draft' | 'scheduled' | 'sending' | 'sent' | 'cancelled' | 'failed';
380
+ type HealthStatus = 'healthy' | 'degraded' | 'tripped';
381
+ type FlowGoal = 'activation' | 'conversion' | 'retention' | 'reactivation' | 'transactional' | 'broadcast';
382
+
383
+ /**
384
+ * Sender-domain validator.
385
+ *
386
+ * Hosts may declare a `senderDomains` registry mapping a domain to which kind
387
+ * of email is allowed to send from it. Used to isolate marketing reputation
388
+ * from transactional reputation:
389
+ *
390
+ * senderDomains: {
391
+ * 'news.example.com': { kind: 'marketing' },
392
+ * 'mail.example.com': { kind: 'transactional' },
393
+ * 'tools.example.com': { kind: 'both' }, // OK for either kind
394
+ * }
395
+ *
396
+ * The check runs at template publish time. If a template's `fromEmail` domain
397
+ * isn't declared, or is declared for the wrong kind, publish fails with a
398
+ * descriptive 400. Hosts who don't set `senderDomains` get no enforcement —
399
+ * back-compat default.
400
+ */
401
+
402
+ interface SenderDomainConfig {
403
+ /** Which template `kind` may use this domain as a From address. */
404
+ kind: 'marketing' | 'transactional' | 'both';
405
+ }
406
+ type SenderDomainRegistry = Record<string, SenderDomainConfig>;
407
+ type SenderDomainValidation = {
408
+ ok: true;
409
+ } | {
410
+ ok: false;
411
+ code: 'invalid_email' | 'unregistered_domain' | 'wrong_kind';
412
+ reason: string;
413
+ };
414
+ declare function validateSenderDomain(fromEmail: string, templateKind: TemplateKind, registry: SenderDomainRegistry | undefined): SenderDomainValidation;
415
+
368
416
  /**
369
417
  * Mailer configuration shape. Required + optional surfaces with sane defaults.
370
418
  */
@@ -412,6 +460,15 @@ interface MailerConfig {
412
460
  name: string;
413
461
  email: string;
414
462
  };
463
+ /**
464
+ * Optional registry of sender domains by kind. When set, mailery enforces at
465
+ * template publish time that a template's `fromEmail` domain is declared and
466
+ * matches the template's `kind`. Used to keep marketing reputation isolated
467
+ * from transactional reputation by sending from separate verified domains.
468
+ *
469
+ * Domains are case-insensitive. If unset, no enforcement happens.
470
+ */
471
+ senderDomains?: SenderDomainRegistry;
415
472
  requireDoubleOptIn?: boolean;
416
473
  unsubscribeTokenLifetimeDays?: number;
417
474
  transactionalRespectUnsubscribe?: boolean;
@@ -450,21 +507,6 @@ type ResolvedConfig = Required<Pick<MailerConfig, 'collectionPrefix' | 'requireD
450
507
  circuitBreaker: CircuitBreakerThresholds;
451
508
  } & MailerConfig;
452
509
 
453
- /**
454
- * Shared enums — string-literal unions for status fields and other discriminators.
455
- * Kept separate from types.ts so the client can import these without pulling in
456
- * server-shaped interfaces.
457
- */
458
- type SubscriptionStatus = 'subscribed' | 'pending_doi' | 'unsubscribed' | 'bounced' | 'complained';
459
- type SendStatus = 'queued' | 'sending' | 'sent' | 'delivered' | 'bounced' | 'complained' | 'failed' | 'suppressed';
460
- type TemplateKind = 'transactional' | 'marketing';
461
- type SuppressionScope = 'all' | 'marketing' | 'transactional';
462
- type SuppressionReason = 'unsubscribed' | 'hard_bounce' | 'complaint' | 'manual' | 'list_cleaning' | 'gdpr_forget';
463
- type FlowRunStatus = 'active' | 'completed' | 'exited' | 'failed';
464
- type BroadcastStatus = 'draft' | 'scheduled' | 'sending' | 'sent' | 'cancelled' | 'failed';
465
- type HealthStatus = 'healthy' | 'degraded' | 'tripped';
466
- type FlowGoal = 'activation' | 'conversion' | 'retention' | 'reactivation' | 'transactional' | 'broadcast';
467
-
468
510
  /**
469
511
  * Mongo collection helpers + indexes for every mailer-owned collection.
470
512
  *
@@ -978,4 +1020,4 @@ declare class NullProvider implements MailProvider {
978
1020
  reset(): void;
979
1021
  }
980
1022
 
981
- export { type AdapterFilter as A, type BroadcastDoc as B, type ContactAdapter as C, type TemplateKind as D, type EventDoc as E, type FlowStep as F, type TemplateVersionDoc as G, type HealthDoc as H, ensureIndexes as I, getCollections as J, type LeadDoc as L, type MailProvider as M, type NormalizedEvent as N, type OutboxDoc as O, type Predicate as P, type RunnerContext as R, type SendArgs as S, type TemplateDoc as T, type WebhookEventDoc as W, type Contact as a, type SendResult as b, Mailer as c, type SuppressionScope as d, type SegmentFilter as e, type AuditLogDoc as f, type BroadcastStatus as g, type CircuitBreakerThresholds as h, type Collections as i, type ContactTagDoc as j, type FlowDoc as k, type FlowGoal as l, type FlowRunDoc as m, type FlowRunStatus as n, type FlowVersionDoc as o, type HealthStatus as p, type MailerConfig as q, NullProvider as r, type RedisOptions as s, type SegmentDefinition as t, type SendDoc as u, type SendStatus as v, type SubscriptionDoc as w, type SubscriptionStatus as x, type SuppressionDoc as y, type SuppressionReason as z };
1023
+ export { type AdapterFilter as A, type BroadcastDoc as B, type ContactAdapter as C, type SubscriptionStatus as D, type EventDoc as E, type FlowStep as F, type SuppressionDoc as G, type HealthDoc as H, type SuppressionReason as I, type TemplateKind as J, type TemplateVersionDoc as K, type LeadDoc as L, type MailProvider as M, type NormalizedEvent as N, type OutboxDoc as O, type Predicate as P, ensureIndexes as Q, type RunnerContext as R, type SendArgs as S, type TemplateDoc as T, getCollections as U, validateSenderDomain as V, type WebhookEventDoc as W, type Contact as a, type SendResult as b, Mailer as c, type SuppressionScope as d, type SegmentFilter as e, type AuditLogDoc as f, type BroadcastStatus as g, type CircuitBreakerThresholds as h, type Collections as i, type ContactTagDoc as j, type FlowDoc as k, type FlowGoal as l, type FlowRunDoc as m, type FlowRunStatus as n, type FlowVersionDoc as o, type HealthStatus as p, type MailerConfig as q, NullProvider as r, type RedisOptions as s, type SegmentDefinition as t, type SendDoc as u, type SendStatus as v, type SenderDomainConfig as w, type SenderDomainRegistry as x, type SenderDomainValidation as y, type SubscriptionDoc as z };
@@ -365,6 +365,54 @@ type QueueDriverConfig = {
365
365
  driver: 'noop';
366
366
  };
367
367
 
368
+ /**
369
+ * Shared enums — string-literal unions for status fields and other discriminators.
370
+ * Kept separate from types.ts so the client can import these without pulling in
371
+ * server-shaped interfaces.
372
+ */
373
+ type SubscriptionStatus = 'subscribed' | 'pending_doi' | 'unsubscribed' | 'bounced' | 'complained';
374
+ type SendStatus = 'queued' | 'sending' | 'sent' | 'delivered' | 'bounced' | 'complained' | 'failed' | 'suppressed';
375
+ type TemplateKind = 'transactional' | 'marketing';
376
+ type SuppressionScope = 'all' | 'marketing' | 'transactional';
377
+ type SuppressionReason = 'unsubscribed' | 'hard_bounce' | 'complaint' | 'manual' | 'list_cleaning' | 'gdpr_forget';
378
+ type FlowRunStatus = 'active' | 'completed' | 'exited' | 'failed';
379
+ type BroadcastStatus = 'draft' | 'scheduled' | 'sending' | 'sent' | 'cancelled' | 'failed';
380
+ type HealthStatus = 'healthy' | 'degraded' | 'tripped';
381
+ type FlowGoal = 'activation' | 'conversion' | 'retention' | 'reactivation' | 'transactional' | 'broadcast';
382
+
383
+ /**
384
+ * Sender-domain validator.
385
+ *
386
+ * Hosts may declare a `senderDomains` registry mapping a domain to which kind
387
+ * of email is allowed to send from it. Used to isolate marketing reputation
388
+ * from transactional reputation:
389
+ *
390
+ * senderDomains: {
391
+ * 'news.example.com': { kind: 'marketing' },
392
+ * 'mail.example.com': { kind: 'transactional' },
393
+ * 'tools.example.com': { kind: 'both' }, // OK for either kind
394
+ * }
395
+ *
396
+ * The check runs at template publish time. If a template's `fromEmail` domain
397
+ * isn't declared, or is declared for the wrong kind, publish fails with a
398
+ * descriptive 400. Hosts who don't set `senderDomains` get no enforcement —
399
+ * back-compat default.
400
+ */
401
+
402
+ interface SenderDomainConfig {
403
+ /** Which template `kind` may use this domain as a From address. */
404
+ kind: 'marketing' | 'transactional' | 'both';
405
+ }
406
+ type SenderDomainRegistry = Record<string, SenderDomainConfig>;
407
+ type SenderDomainValidation = {
408
+ ok: true;
409
+ } | {
410
+ ok: false;
411
+ code: 'invalid_email' | 'unregistered_domain' | 'wrong_kind';
412
+ reason: string;
413
+ };
414
+ declare function validateSenderDomain(fromEmail: string, templateKind: TemplateKind, registry: SenderDomainRegistry | undefined): SenderDomainValidation;
415
+
368
416
  /**
369
417
  * Mailer configuration shape. Required + optional surfaces with sane defaults.
370
418
  */
@@ -412,6 +460,15 @@ interface MailerConfig {
412
460
  name: string;
413
461
  email: string;
414
462
  };
463
+ /**
464
+ * Optional registry of sender domains by kind. When set, mailery enforces at
465
+ * template publish time that a template's `fromEmail` domain is declared and
466
+ * matches the template's `kind`. Used to keep marketing reputation isolated
467
+ * from transactional reputation by sending from separate verified domains.
468
+ *
469
+ * Domains are case-insensitive. If unset, no enforcement happens.
470
+ */
471
+ senderDomains?: SenderDomainRegistry;
415
472
  requireDoubleOptIn?: boolean;
416
473
  unsubscribeTokenLifetimeDays?: number;
417
474
  transactionalRespectUnsubscribe?: boolean;
@@ -450,21 +507,6 @@ type ResolvedConfig = Required<Pick<MailerConfig, 'collectionPrefix' | 'requireD
450
507
  circuitBreaker: CircuitBreakerThresholds;
451
508
  } & MailerConfig;
452
509
 
453
- /**
454
- * Shared enums — string-literal unions for status fields and other discriminators.
455
- * Kept separate from types.ts so the client can import these without pulling in
456
- * server-shaped interfaces.
457
- */
458
- type SubscriptionStatus = 'subscribed' | 'pending_doi' | 'unsubscribed' | 'bounced' | 'complained';
459
- type SendStatus = 'queued' | 'sending' | 'sent' | 'delivered' | 'bounced' | 'complained' | 'failed' | 'suppressed';
460
- type TemplateKind = 'transactional' | 'marketing';
461
- type SuppressionScope = 'all' | 'marketing' | 'transactional';
462
- type SuppressionReason = 'unsubscribed' | 'hard_bounce' | 'complaint' | 'manual' | 'list_cleaning' | 'gdpr_forget';
463
- type FlowRunStatus = 'active' | 'completed' | 'exited' | 'failed';
464
- type BroadcastStatus = 'draft' | 'scheduled' | 'sending' | 'sent' | 'cancelled' | 'failed';
465
- type HealthStatus = 'healthy' | 'degraded' | 'tripped';
466
- type FlowGoal = 'activation' | 'conversion' | 'retention' | 'reactivation' | 'transactional' | 'broadcast';
467
-
468
510
  /**
469
511
  * Mongo collection helpers + indexes for every mailer-owned collection.
470
512
  *
@@ -978,4 +1020,4 @@ declare class NullProvider implements MailProvider {
978
1020
  reset(): void;
979
1021
  }
980
1022
 
981
- export { type AdapterFilter as A, type BroadcastDoc as B, type ContactAdapter as C, type TemplateKind as D, type EventDoc as E, type FlowStep as F, type TemplateVersionDoc as G, type HealthDoc as H, ensureIndexes as I, getCollections as J, type LeadDoc as L, type MailProvider as M, type NormalizedEvent as N, type OutboxDoc as O, type Predicate as P, type RunnerContext as R, type SendArgs as S, type TemplateDoc as T, type WebhookEventDoc as W, type Contact as a, type SendResult as b, Mailer as c, type SuppressionScope as d, type SegmentFilter as e, type AuditLogDoc as f, type BroadcastStatus as g, type CircuitBreakerThresholds as h, type Collections as i, type ContactTagDoc as j, type FlowDoc as k, type FlowGoal as l, type FlowRunDoc as m, type FlowRunStatus as n, type FlowVersionDoc as o, type HealthStatus as p, type MailerConfig as q, NullProvider as r, type RedisOptions as s, type SegmentDefinition as t, type SendDoc as u, type SendStatus as v, type SubscriptionDoc as w, type SubscriptionStatus as x, type SuppressionDoc as y, type SuppressionReason as z };
1023
+ export { type AdapterFilter as A, type BroadcastDoc as B, type ContactAdapter as C, type SubscriptionStatus as D, type EventDoc as E, type FlowStep as F, type SuppressionDoc as G, type HealthDoc as H, type SuppressionReason as I, type TemplateKind as J, type TemplateVersionDoc as K, type LeadDoc as L, type MailProvider as M, type NormalizedEvent as N, type OutboxDoc as O, type Predicate as P, ensureIndexes as Q, type RunnerContext as R, type SendArgs as S, type TemplateDoc as T, getCollections as U, validateSenderDomain as V, type WebhookEventDoc as W, type Contact as a, type SendResult as b, Mailer as c, type SuppressionScope as d, type SegmentFilter as e, type AuditLogDoc as f, type BroadcastStatus as g, type CircuitBreakerThresholds as h, type Collections as i, type ContactTagDoc as j, type FlowDoc as k, type FlowGoal as l, type FlowRunDoc as m, type FlowRunStatus as n, type FlowVersionDoc as o, type HealthStatus as p, type MailerConfig as q, NullProvider as r, type RedisOptions as s, type SegmentDefinition as t, type SendDoc as u, type SendStatus as v, type SenderDomainConfig as w, type SenderDomainRegistry as x, type SenderDomainValidation as y, type SubscriptionDoc as z };
package/dist/testing.cjs CHANGED
@@ -15943,6 +15943,25 @@ async function promoteSoftBounces(ctx) {
15943
15943
  // src/server/runner/tick.ts
15944
15944
  var STRANDED_SEND_THRESHOLD_MS = 5 * 60 * 1e3;
15945
15945
  async function runTick(ctx) {
15946
+ await ctx.collections.health.updateOne(
15947
+ { _id: "singleton" },
15948
+ {
15949
+ $set: { updatedAt: /* @__PURE__ */ new Date() },
15950
+ $setOnInsert: {
15951
+ _id: "singleton",
15952
+ windowStartedAt: /* @__PURE__ */ new Date(),
15953
+ windowDurationMs: ctx.config.circuitBreaker.windowMinutes * 60 * 1e3,
15954
+ status: "healthy",
15955
+ trippedAt: null,
15956
+ trippedReason: null,
15957
+ manuallyResumedAt: null,
15958
+ counters: { sent: 0, delivered: 0, bounced: 0, hardBounced: 0, softBounced: 0, complained: 0, failedToSend: 0 },
15959
+ rates: { bounceRate: 0, hardBounceRate: 0, complaintRate: 0, failureRate: 0 }
15960
+ }
15961
+ },
15962
+ { upsert: true }
15963
+ ).catch(() => {
15964
+ });
15946
15965
  await processNewlyFiredEventTriggers(ctx).catch((err) => {
15947
15966
  console.error("mailery: triggers scan failed", err);
15948
15967
  });