sently 0.7.2 → 0.9.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/AGENTS.md +34 -0
- package/CHANGELOG.md +49 -1
- package/README.md +89 -776
- package/dist/adapters/bun.js +1 -1
- package/dist/adapters/cf.js +2 -2
- package/dist/adapters/cf.js.map +2 -2
- package/dist/adapters/deno.js +1 -1
- package/dist/adapters/node.js +1 -1
- package/dist/auth/oauth2.js +2 -2
- package/dist/auth/oauth2.js.map +1 -1
- package/dist/chunk-0gqy32pe.js +4 -0
- package/dist/chunk-0gqy32pe.js.map +10 -0
- package/dist/{chunk-kebhy657.js → chunk-0qxws3kj.js} +2 -2
- package/dist/{chunk-kebhy657.js.map → chunk-0qxws3kj.js.map} +1 -1
- package/dist/chunk-29z7fkzy.js +4 -0
- package/dist/{chunk-74rha3ac.js.map → chunk-29z7fkzy.js.map} +2 -2
- package/dist/chunk-5915vbcj.js +4 -0
- package/dist/chunk-5915vbcj.js.map +10 -0
- package/dist/{chunk-keksa6fx.js → chunk-6npp3x3c.js} +2 -2
- package/dist/{chunk-keksa6fx.js.map → chunk-6npp3x3c.js.map} +1 -1
- package/dist/chunk-7gy2q9sh.js +4 -0
- package/dist/chunk-7gy2q9sh.js.map +10 -0
- package/dist/{chunk-gkkv7yqm.js → chunk-8dty8c4p.js} +3 -3
- package/dist/{chunk-gkkv7yqm.js.map → chunk-8dty8c4p.js.map} +2 -2
- package/dist/{chunk-qp4y0kp2.js → chunk-8njyga62.js} +2 -2
- package/dist/{chunk-qp4y0kp2.js.map → chunk-8njyga62.js.map} +1 -1
- package/dist/{chunk-gh5n759p.js → chunk-93vqxxj2.js} +3 -3
- package/dist/{chunk-gh5n759p.js.map → chunk-93vqxxj2.js.map} +1 -1
- package/dist/chunk-b602dhck.js +4 -0
- package/dist/{chunk-rm78s1ek.js.map → chunk-b602dhck.js.map} +2 -2
- package/dist/chunk-gp4fwrs8.js +4 -0
- package/dist/chunk-gp4fwrs8.js.map +10 -0
- package/dist/chunk-n0qeyzqm.js +13 -0
- package/dist/{chunk-cvrbfke9.js.map → chunk-n0qeyzqm.js.map} +2 -2
- package/dist/chunk-qtkd5bak.js +4 -0
- package/dist/chunk-qtkd5bak.js.map +11 -0
- package/dist/chunk-skqhj0rm.js +4 -0
- package/dist/{chunk-r7ee9tk7.js.map → chunk-skqhj0rm.js.map} +2 -2
- package/dist/{chunk-a1c87hn1.js → chunk-tamww15j.js} +2 -2
- package/dist/{chunk-a1c87hn1.js.map → chunk-tamww15j.js.map} +1 -1
- package/dist/chunk-vjpds2pf.js +3 -0
- package/dist/chunk-vjpds2pf.js.map +10 -0
- package/dist/chunk-yp311efr.js +4 -0
- package/dist/chunk-yp311efr.js.map +10 -0
- package/dist/chunk-ywq6s10g.js +5 -0
- package/dist/{chunk-d5rwm3br.js.map → chunk-ywq6s10g.js.map} +3 -3
- package/dist/core/base64.d.ts +10 -0
- package/dist/core/errors.js +2 -2
- package/dist/core/errors.js.map +1 -1
- package/dist/core/hooks.d.ts +14 -0
- package/dist/core/plugin.d.ts +7 -7
- package/dist/core/provider-label.d.ts +6 -0
- package/dist/core/push-endpoint.d.ts +29 -0
- package/dist/core/push-types.d.ts +98 -0
- package/dist/core/sms-types.d.ts +76 -0
- package/dist/core/smtp.js +2 -2
- package/dist/core/smtp.js.map +1 -1
- package/dist/core/types.d.ts +27 -4
- package/dist/core/whatsapp-types.d.ts +116 -0
- package/dist/detect.js +2 -2
- package/dist/detect.js.map +1 -1
- package/dist/dkim.js +2 -2
- package/dist/dkim.js.map +2 -2
- package/dist/idempotency.d.ts +1 -0
- package/dist/idempotency.js +2 -2
- package/dist/idempotency.js.map +3 -3
- package/dist/index.d.ts +24 -2
- package/dist/index.js +23 -0
- package/dist/mailer.js +2 -2
- package/dist/mailer.js.map +1 -1
- package/dist/observability/console.d.ts +12 -0
- package/dist/observability/console.js +3 -0
- package/dist/observability/console.js.map +10 -0
- package/dist/plugins/react.js +2 -2
- package/dist/plugins/react.js.map +2 -2
- package/dist/plugins/template.js +1 -1
- package/dist/pool/pool.js +2 -2
- package/dist/pool/pool.js.map +1 -1
- package/dist/push.d.ts +26 -0
- package/dist/push.js +3 -0
- package/dist/push.js.map +10 -0
- package/dist/sms.d.ts +26 -0
- package/dist/sms.js +3 -0
- package/dist/sms.js.map +10 -0
- package/dist/smtp-mailer.js +2 -2
- package/dist/smtp-mailer.js.map +2 -2
- package/dist/transports/brevo.d.ts +1 -0
- package/dist/transports/brevo.js +2 -2
- package/dist/transports/brevo.js.map +3 -3
- package/dist/transports/cloudflare-email.d.ts +58 -0
- package/dist/transports/cloudflare-email.js +3 -0
- package/dist/transports/cloudflare-email.js.map +10 -0
- package/dist/transports/fallback.d.ts +100 -0
- package/dist/transports/fallback.js +3 -0
- package/dist/transports/fallback.js.map +9 -0
- package/dist/transports/loops.d.ts +32 -0
- package/dist/transports/loops.js +3 -0
- package/dist/transports/loops.js.map +10 -0
- package/dist/transports/mailersend.d.ts +27 -0
- package/dist/transports/mailersend.js +3 -0
- package/dist/transports/mailersend.js.map +10 -0
- package/dist/transports/mailgun.d.ts +1 -0
- package/dist/transports/mailgun.js +2 -2
- package/dist/transports/mailgun.js.map +3 -3
- package/dist/transports/mailtrap.d.ts +36 -0
- package/dist/transports/mailtrap.js +3 -0
- package/dist/transports/mailtrap.js.map +10 -0
- package/dist/transports/msegat.d.ts +132 -0
- package/dist/transports/msegat.js +3 -0
- package/dist/transports/msegat.js.map +10 -0
- package/dist/transports/plunk.d.ts +29 -0
- package/dist/transports/plunk.js +3 -0
- package/dist/transports/plunk.js.map +10 -0
- package/dist/transports/postmark.d.ts +1 -0
- package/dist/transports/postmark.js +2 -2
- package/dist/transports/postmark.js.map +3 -3
- package/dist/transports/preview.d.ts +1 -0
- package/dist/transports/preview.js +2 -2
- package/dist/transports/preview.js.map +3 -3
- package/dist/transports/resend.d.ts +1 -0
- package/dist/transports/resend.js +2 -2
- package/dist/transports/resend.js.map +3 -3
- package/dist/transports/retry.d.ts +1 -0
- package/dist/transports/retry.js +2 -2
- package/dist/transports/retry.js.map +3 -3
- package/dist/transports/sendgrid.d.ts +1 -0
- package/dist/transports/sendgrid.js +2 -2
- package/dist/transports/sendgrid.js.map +3 -3
- package/dist/transports/ses.d.ts +1 -0
- package/dist/transports/ses.js +3 -3
- package/dist/transports/ses.js.map +3 -3
- package/dist/transports/smtp.d.ts +1 -0
- package/dist/transports/smtp.js +2 -2
- package/dist/transports/smtp.js.map +1 -1
- package/dist/transports/sndr.d.ts +41 -0
- package/dist/transports/sndr.js +3 -0
- package/dist/transports/sndr.js.map +10 -0
- package/dist/transports/sparkpost.d.ts +30 -0
- package/dist/transports/sparkpost.js +3 -0
- package/dist/transports/sparkpost.js.map +10 -0
- package/dist/transports/taqnyat-mail.d.ts +33 -0
- package/dist/transports/taqnyat-mail.js +3 -0
- package/dist/transports/taqnyat-mail.js.map +10 -0
- package/dist/transports/taqnyat-phone.d.ts +4 -0
- package/dist/transports/taqnyat-sms.d.ts +131 -0
- package/dist/transports/taqnyat-sms.js +3 -0
- package/dist/transports/taqnyat-sms.js.map +10 -0
- package/dist/transports/taqnyat-whatsapp.d.ts +51 -0
- package/dist/transports/taqnyat-whatsapp.js +3 -0
- package/dist/transports/taqnyat-whatsapp.js.map +10 -0
- package/dist/transports/twilio-sms.d.ts +66 -0
- package/dist/transports/twilio-sms.js +3 -0
- package/dist/transports/twilio-sms.js.map +10 -0
- package/dist/transports/webpush.d.ts +46 -0
- package/dist/transports/webpush.js +3 -0
- package/dist/transports/webpush.js.map +10 -0
- package/dist/transports/weighted-fallback.d.ts +65 -0
- package/dist/transports/weighted-fallback.js +3 -0
- package/dist/transports/weighted-fallback.js.map +10 -0
- package/dist/transports/whatsapp-cloud.d.ts +56 -0
- package/dist/transports/whatsapp-cloud.js +3 -0
- package/dist/transports/whatsapp-cloud.js.map +10 -0
- package/dist/webhooks/brevo.js +1 -1
- package/dist/webhooks/mailgun.js +1 -1
- package/dist/webhooks/postmark.js +1 -1
- package/dist/webhooks/resend.js +1 -1
- package/dist/webhooks/sendgrid.js +1 -1
- package/dist/webhooks/ses.js +1 -1
- package/dist/webhooks/sndr.d.ts +16 -0
- package/dist/webhooks/sndr.js +3 -0
- package/dist/webhooks/sndr.js.map +10 -0
- package/dist/webhooks/timing-safe-equal.js +1 -1
- package/dist/webhooks.d.ts +9 -2
- package/dist/webhooks.js +4 -0
- package/dist/whatsapp.d.ts +26 -0
- package/dist/whatsapp.js +3 -0
- package/dist/whatsapp.js.map +10 -0
- package/package.json +121 -4
- package/site/README.md +26 -0
- package/site/content/docs/ai/index.mdx +13 -0
- package/site/content/docs/ai/llms-txt.mdx +12 -0
- package/site/content/docs/ai/mcp.mdx +16 -0
- package/site/content/docs/ai/meta.json +9 -0
- package/site/content/docs/channels/email.mdx +100 -0
- package/site/content/docs/channels/hooks.mdx +87 -0
- package/site/content/docs/channels/index.mdx +81 -0
- package/site/content/docs/channels/meta.json +12 -0
- package/site/content/docs/channels/push.mdx +92 -0
- package/site/content/docs/channels/sms.mdx +88 -0
- package/site/content/docs/channels/whatsapp.mdx +95 -0
- package/site/content/docs/decorators/fallback.mdx +34 -0
- package/site/content/docs/decorators/idempotency.mdx +34 -0
- package/site/content/docs/decorators/index.mdx +50 -0
- package/site/content/docs/decorators/meta.json +12 -0
- package/site/content/docs/decorators/preview.mdx +34 -0
- package/site/content/docs/decorators/retry.mdx +34 -0
- package/site/content/docs/decorators/weighted-fallback.mdx +34 -0
- package/site/content/docs/get-started/entrypoints.mdx +114 -0
- package/site/content/docs/get-started/index.mdx +14 -0
- package/site/content/docs/get-started/installation.mdx +78 -0
- package/site/content/docs/get-started/introduction.mdx +77 -0
- package/site/content/docs/get-started/meta.json +12 -0
- package/site/content/docs/get-started/migrate-nodemailer.mdx +23 -0
- package/site/content/docs/get-started/runtimes.mdx +17 -0
- package/site/content/docs/guides/adapters.mdx +26 -0
- package/site/content/docs/guides/attachments.mdx +19 -0
- package/site/content/docs/guides/bundle-size.mdx +78 -0
- package/site/content/docs/guides/dkim.mdx +26 -0
- package/site/content/docs/guides/index.mdx +15 -0
- package/site/content/docs/guides/meta.json +21 -0
- package/site/content/docs/guides/oauth2.mdx +23 -0
- package/site/content/docs/guides/observability.mdx +16 -0
- package/site/content/docs/guides/plugins-template.mdx +22 -0
- package/site/content/docs/guides/pool.mdx +24 -0
- package/site/content/docs/guides/react-email.mdx +20 -0
- package/site/content/docs/guides/security.mdx +17 -0
- package/site/content/docs/guides/send-bulk.mdx +18 -0
- package/site/content/docs/guides/vendor-extras-otp.mdx +18 -0
- package/site/content/docs/guides/webhooks.mdx +120 -0
- package/site/content/docs/guides/webpush-interop.mdx +18 -0
- package/site/content/docs/index.mdx +15 -0
- package/site/content/docs/meta.json +15 -0
- package/site/content/docs/quick-start/email.mdx +40 -0
- package/site/content/docs/quick-start/index.mdx +15 -0
- package/site/content/docs/quick-start/meta.json +5 -0
- package/site/content/docs/quick-start/push.mdx +36 -0
- package/site/content/docs/quick-start/sms.mdx +36 -0
- package/site/content/docs/quick-start/whatsapp.mdx +38 -0
- package/site/content/docs/reference/errors.mdx +22 -0
- package/site/content/docs/reference/exports.mdx +83 -0
- package/site/content/docs/reference/index.mdx +15 -0
- package/site/content/docs/reference/mail-options.mdx +22 -0
- package/site/content/docs/reference/meta.json +15 -0
- package/site/content/docs/reference/push-options.mdx +20 -0
- package/site/content/docs/reference/sms-options.mdx +17 -0
- package/site/content/docs/reference/transport-contracts.mdx +17 -0
- package/site/content/docs/reference/webhook-events.mdx +70 -0
- package/site/content/docs/reference/whatsapp-options.mdx +15 -0
- package/site/content/docs/transports/brevo.mdx +40 -0
- package/site/content/docs/transports/cloudflare-email.mdx +40 -0
- package/site/content/docs/transports/index.mdx +105 -0
- package/site/content/docs/transports/loops.mdx +41 -0
- package/site/content/docs/transports/mailersend.mdx +40 -0
- package/site/content/docs/transports/mailgun.mdx +42 -0
- package/site/content/docs/transports/mailtrap.mdx +42 -0
- package/site/content/docs/transports/meta.json +32 -0
- package/site/content/docs/transports/msegat.mdx +42 -0
- package/site/content/docs/transports/plunk.mdx +40 -0
- package/site/content/docs/transports/postmark.mdx +40 -0
- package/site/content/docs/transports/resend.mdx +43 -0
- package/site/content/docs/transports/sendgrid.mdx +40 -0
- package/site/content/docs/transports/ses.mdx +44 -0
- package/site/content/docs/transports/smtp.mdx +47 -0
- package/site/content/docs/transports/sndr.mdx +144 -0
- package/site/content/docs/transports/sparkpost.mdx +41 -0
- package/site/content/docs/transports/taqnyat-mail.mdx +41 -0
- package/site/content/docs/transports/taqnyat-sms.mdx +41 -0
- package/site/content/docs/transports/taqnyat-whatsapp.mdx +40 -0
- package/site/content/docs/transports/twilio-sms.mdx +128 -0
- package/site/content/docs/transports/webpush.mdx +43 -0
- package/site/content/docs/transports/whatsapp-cloud.mdx +42 -0
- package/dist/chunk-4mvp3b85.js +0 -3
- package/dist/chunk-4mvp3b85.js.map +0 -10
- package/dist/chunk-74rha3ac.js +0 -4
- package/dist/chunk-cvrbfke9.js +0 -13
- package/dist/chunk-d5rwm3br.js +0 -5
- package/dist/chunk-ka6t8g77.js +0 -4
- package/dist/chunk-ka6t8g77.js.map +0 -11
- package/dist/chunk-r7ee9tk7.js +0 -4
- package/dist/chunk-rm78s1ek.js +0 -4
package/dist/core/types.d.ts
CHANGED
|
@@ -87,6 +87,13 @@ export interface SendResult {
|
|
|
87
87
|
deduped?: boolean;
|
|
88
88
|
/** Set when this item failed inside an otherwise successful batch HTTP response. */
|
|
89
89
|
batchError?: unknown;
|
|
90
|
+
/** Identifier of the transport that handled the send; set by FallbackTransport. */
|
|
91
|
+
provider?: string;
|
|
92
|
+
/**
|
|
93
|
+
* Zero-based index of the transport that handled the send in a fallback chain.
|
|
94
|
+
* Set by FallbackTransport (e.g. `1` means provider #0 failed and #1 succeeded).
|
|
95
|
+
*/
|
|
96
|
+
providerIndex?: number;
|
|
90
97
|
}
|
|
91
98
|
/** SMTP envelope addresses (MAIL FROM / RCPT TO). */
|
|
92
99
|
export interface Envelope {
|
|
@@ -134,6 +141,11 @@ export interface VerifyResult {
|
|
|
134
141
|
}
|
|
135
142
|
/** Pluggable mail delivery backend (SMTP, HTTP API, etc.). */
|
|
136
143
|
export interface Transport {
|
|
144
|
+
/**
|
|
145
|
+
* Stable provider identifier for observability (e.g. `"resend"`, `"ses"`).
|
|
146
|
+
* Prefer this over constructor-name inference in hooks and fallback diagnostics.
|
|
147
|
+
*/
|
|
148
|
+
readonly provider?: string;
|
|
137
149
|
/** Send a message through this transport. */
|
|
138
150
|
send(options: MailOptions): Promise<SendResult>;
|
|
139
151
|
/**
|
|
@@ -362,12 +374,23 @@ export interface MailerHookContext {
|
|
|
362
374
|
export interface MailerHooks {
|
|
363
375
|
/** Fired before the transport sends the message. */
|
|
364
376
|
onSend?: (ctx: MailerHookContext) => void | Promise<void>;
|
|
365
|
-
/**
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
377
|
+
/**
|
|
378
|
+
* Fired after a successful send.
|
|
379
|
+
* @param durationMs — elapsed milliseconds from send start to success (optional third argument).
|
|
380
|
+
*/
|
|
381
|
+
onSuccess?: (ctx: MailerHookContext, result: SendResult, durationMs?: number) => void | Promise<void>;
|
|
382
|
+
/**
|
|
383
|
+
* Fired when a send throws (error is re-thrown after the hook runs).
|
|
384
|
+
* @param durationMs — elapsed milliseconds from send start to failure (optional third argument).
|
|
385
|
+
*/
|
|
386
|
+
onError?: (ctx: MailerHookContext, error: unknown, durationMs?: number) => void | Promise<void>;
|
|
369
387
|
/** Fired before each retry attempt (requires {@link RetryTransport}). */
|
|
370
388
|
onRetry?: (ctx: MailerHookContext, attempt: number, error: unknown) => void | Promise<void>;
|
|
389
|
+
/**
|
|
390
|
+
* Fired when {@link FallbackTransport} fails over to the next provider.
|
|
391
|
+
* Requires a {@link FallbackTransport} (or {@link WeightedFallbackTransport}) in the mailer stack.
|
|
392
|
+
*/
|
|
393
|
+
onFallback?: (ctx: MailerHookContext, failedProvider: string, nextProvider: string, error: unknown) => void | Promise<void>;
|
|
371
394
|
}
|
|
372
395
|
/** Options for {@link createMailer} from `sently/mailer` — transport-only, smallest bundle. */
|
|
373
396
|
export interface TransportMailerOptions {
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* Shared WhatsApp channel contracts — sibling types to email MailOptions/Transport/Hooks.
|
|
4
|
+
*
|
|
5
|
+
* Sently-first: this contract is the stable WhatsApp surface. Provider transports
|
|
6
|
+
* implement {@link WhatsAppTransport}; multi-product vendors get a separate
|
|
7
|
+
* WhatsApp transport entry, not a mega vendor client.
|
|
8
|
+
*
|
|
9
|
+
* Meta requires a pre-approved template for business-initiated messages; free text
|
|
10
|
+
* is only allowed within an open 24h customer-service window. Model both shapes.
|
|
11
|
+
*/
|
|
12
|
+
import type { VerifyResult } from "./types.js";
|
|
13
|
+
/** Parameter inside a WhatsApp template component. */
|
|
14
|
+
export interface WhatsAppTemplateParameter {
|
|
15
|
+
/** Parameter value type. */
|
|
16
|
+
type: "text" | "currency" | "date_time";
|
|
17
|
+
/** Text value when {@link type} is `"text"`. */
|
|
18
|
+
text?: string;
|
|
19
|
+
}
|
|
20
|
+
/** Component of a WhatsApp template message (header, body, or button). */
|
|
21
|
+
export interface WhatsAppTemplateComponent {
|
|
22
|
+
/** Component role in the template. */
|
|
23
|
+
type: "header" | "body" | "button";
|
|
24
|
+
/** Substitution parameters for this component. */
|
|
25
|
+
parameters?: WhatsAppTemplateParameter[];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Business-initiated WhatsApp message using a pre-approved template.
|
|
29
|
+
* Required outside the 24h customer-service window.
|
|
30
|
+
*/
|
|
31
|
+
export interface WhatsAppTemplateMessage {
|
|
32
|
+
/** Recipient phone number (E.164 recommended). */
|
|
33
|
+
to: string;
|
|
34
|
+
/** Pre-approved template definition. */
|
|
35
|
+
template: {
|
|
36
|
+
/** Template name registered with Meta. */
|
|
37
|
+
name: string;
|
|
38
|
+
/** Language code (e.g. `"en_US"`). */
|
|
39
|
+
language: string;
|
|
40
|
+
/** Optional header/body/button components with parameters. */
|
|
41
|
+
components?: WhatsAppTemplateComponent[];
|
|
42
|
+
};
|
|
43
|
+
/** Client-supplied message identifier when known. */
|
|
44
|
+
messageId?: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Free-text WhatsApp message.
|
|
48
|
+
* Only valid within an open 24h customer-service window.
|
|
49
|
+
*/
|
|
50
|
+
export interface WhatsAppTextMessage {
|
|
51
|
+
/** Recipient phone number (E.164 recommended). */
|
|
52
|
+
to: string;
|
|
53
|
+
/** Plain text body. */
|
|
54
|
+
text: string;
|
|
55
|
+
/** Client-supplied message identifier when known. */
|
|
56
|
+
messageId?: string;
|
|
57
|
+
}
|
|
58
|
+
/** Options for sending a WhatsApp message (template or free text). */
|
|
59
|
+
export type WhatsAppOptions = WhatsAppTemplateMessage | WhatsAppTextMessage;
|
|
60
|
+
/** Result returned after a WhatsApp message is accepted for delivery. */
|
|
61
|
+
export interface WhatsAppSendResult {
|
|
62
|
+
/** Provider-assigned or client message identifier. */
|
|
63
|
+
messageId: string;
|
|
64
|
+
/** Recipient phone number. */
|
|
65
|
+
to: string;
|
|
66
|
+
/** Provider delivery status string (e.g. `"accepted"`). */
|
|
67
|
+
status: string;
|
|
68
|
+
/** Human-readable or raw status text from the provider. */
|
|
69
|
+
response: string;
|
|
70
|
+
/** Transport or provider identifier (e.g. `"whatsapp-cloud"`). */
|
|
71
|
+
provider?: string;
|
|
72
|
+
}
|
|
73
|
+
/** Pluggable WhatsApp delivery backend. */
|
|
74
|
+
export interface WhatsAppTransport {
|
|
75
|
+
/**
|
|
76
|
+
* Stable provider identifier for observability (e.g. `"whatsapp-cloud"`).
|
|
77
|
+
* Prefer this over constructor-name inference in hooks.
|
|
78
|
+
*/
|
|
79
|
+
readonly provider?: string;
|
|
80
|
+
/** Send a WhatsApp message through this transport. */
|
|
81
|
+
send(options: WhatsAppOptions): Promise<WhatsAppSendResult>;
|
|
82
|
+
/** Test connectivity and credentials without sending. */
|
|
83
|
+
verify?(): Promise<VerifyResult>;
|
|
84
|
+
/** Release resources held by the transport. */
|
|
85
|
+
close?(): Promise<void>;
|
|
86
|
+
}
|
|
87
|
+
/** Context passed to WhatsApp lifecycle hooks (no message body — avoids PII in logs). */
|
|
88
|
+
export interface WhatsAppHookContext {
|
|
89
|
+
/** Message-ID when known (from options or send result). */
|
|
90
|
+
messageId?: string;
|
|
91
|
+
/** Recipient phone number. */
|
|
92
|
+
to: string;
|
|
93
|
+
/** Transport or provider identifier (e.g. `"whatsapp-cloud"`). */
|
|
94
|
+
provider: string;
|
|
95
|
+
}
|
|
96
|
+
/** Optional lifecycle hooks for metrics, tracing, and observability on every WhatsApp send. */
|
|
97
|
+
export interface WhatsAppHooks {
|
|
98
|
+
/** Fired before the transport sends the message. */
|
|
99
|
+
onSend?: (ctx: WhatsAppHookContext) => void | Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* Fired after a successful send.
|
|
102
|
+
* @param durationMs — elapsed milliseconds from send start to success (optional third argument).
|
|
103
|
+
*/
|
|
104
|
+
onSuccess?: (ctx: WhatsAppHookContext, result: WhatsAppSendResult, durationMs?: number) => void | Promise<void>;
|
|
105
|
+
/**
|
|
106
|
+
* Fired when a send throws (error is re-thrown after the hook runs).
|
|
107
|
+
* @param durationMs — elapsed milliseconds from send start to failure (optional third argument).
|
|
108
|
+
*/
|
|
109
|
+
onError?: (ctx: WhatsAppHookContext, error: unknown, durationMs?: number) => void | Promise<void>;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* A WhatsApp plugin transforms {@link WhatsAppOptions} before the transport sends.
|
|
113
|
+
* Plugins run sequentially. Each receives the output of the previous.
|
|
114
|
+
* Return a new options object — do not mutate the input.
|
|
115
|
+
*/
|
|
116
|
+
export type WhatsAppPlugin = ((options: WhatsAppOptions) => WhatsAppOptions) | ((options: WhatsAppOptions) => Promise<WhatsAppOptions>);
|
package/dist/detect.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{J as a,K as b}from"./chunk-29z7fkzy.js";import"./chunk-6npp3x3c.js";export{a as detectRuntime,b as createDefaultAdapter};
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=D0D0974ACACB2BDE64756E2164756E21
|
package/dist/detect.js.map
CHANGED
package/dist/dkim.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{Y as G,ba as E}from"./chunk-ywq6s10g.js";import"./chunk-6npp3x3c.js";var j=`\r
|
|
2
2
|
`,C="from:to:subject:date:message-id:mime-version:content-type";function _(M,I){let x=F(M),K=[];for(let S of I){let Y=S.toLowerCase().trim(),z=x.get(Y);if(!z)continue;for(let D of z){let w=D.replace(/\r?\n/g,"").replace(/\s+/g," ").trim();K.push(`${Y}:${w}`)}}return K.length>0?`${K.join(j)}${j}`:""}function $(M){let x=M.replace(/\r\n/g,`
|
|
3
3
|
`).replace(/\r/g,`
|
|
4
4
|
`).split(`
|
|
@@ -6,4 +6,4 @@ import{P as G,S as E}from"./chunk-d5rwm3br.js";import"./chunk-keksa6fx.js";var j
|
|
|
6
6
|
\r
|
|
7
7
|
`),w=D>=0?z.slice(0,D):z,P=D>=0?z.slice(D+4):"",T=$(P),O=await k(E(T)),Q=x==="ed25519-sha256"?"ed25519-sha256":"rsa-sha256",X=Y.join(":"),Z=Math.floor(Date.now()/1000),W=["v=1",`a=${Q}`,"c=relaxed/relaxed",`d=${I.domainName}`,`s=${I.keySelector}`,`h=${X}`,`bh=${O}`,"b=",`t=${Z}`].join("; "),b="dkim-signature",H=`${w}${j}dkim-signature:${W}`,p=_(H,[...Y,"dkim-signature"]),A=await v(I.privateKey,x),R=E(p),U=await L(A,R,x),V=G(U).replace(/\r\n/g,"");return{header:`DKIM-Signature: v=1; a=${Q}; c=relaxed/relaxed; d=${I.domainName}; s=${I.keySelector}; h=${X}; bh=${O}; b=${V}; t=${Z}`}}function F(M){let I=new Map,x=M.split(/\r?\n/).filter((z)=>z.length>0),K="",S="",Y=()=>{if(!K)return;let z=K.toLowerCase(),D=I.get(z)??[];D.push(S),I.set(z,D),K="",S=""};for(let z of x){if(/^[ \t]/.test(z)&&K){S+=` ${z.trim()}`;continue}Y();let D=z.indexOf(":");if(D>0)K=z.slice(0,D).trim(),S=z.slice(D+1).trim()}return Y(),I}function B(M){let I=M.replace(/-----BEGIN[^-]+-----/g,"").replace(/-----END[^-]+-----/g,"").replace(/\s/g,""),x=atob(I),K=new Uint8Array(x.length);for(let S=0;S<x.length;S++)K[S]=x.charCodeAt(S);return K}function J(M){return M.buffer.slice(M.byteOffset,M.byteOffset+M.byteLength)}async function k(M){let I=await crypto.subtle.digest("SHA-256",J(M));return G(new Uint8Array(I)).replace(/\r\n/g,"")}async function L(M,I,x){let K=J(I);if(x==="ed25519-sha256"){let Y=await crypto.subtle.sign("Ed25519",M,K);return new Uint8Array(Y)}let S=await crypto.subtle.sign({name:"RSASSA-PKCS1-v1_5"},M,K);return new Uint8Array(S)}export{N as signDKIM,v as importPrivateKey,_ as canonicalizeHeadersRelaxed,$ as canonicalizeBodyRelaxed};
|
|
8
8
|
|
|
9
|
-
//# debugId=
|
|
9
|
+
//# debugId=16320E7654B927CA64756E2164756E21
|
package/dist/dkim.js.map
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"/**\n * DKIM signing implementation (RFC 6376). Public entry: `sently/dkim`.\n */\nimport { encodeBase64, encodeUtf8 } from \"./base64.js\";\nimport type { DKIMConfig } from \"./types.js\";\n\nconst CRLF = \"\\r\\n\";\nconst DEFAULT_HEADER_FIELDS = \"from:to:subject:date:message-id:mime-version:content-type\";\n\n/** Result of DKIM signing — the header line to prepend. */\nexport interface DKIMSignResult {\n /** Complete DKIM-Signature header line (without trailing CRLF). */\n header: string;\n}\n\n/**\n * Canonicalize headers using the relaxed algorithm (RFC 6376 §3.4.2).\n */\nexport function canonicalizeHeadersRelaxed(headers: string, fieldNames: string[]): string {\n const parsed = parseHeaders(headers);\n const lines: string[] = [];\n\n for (const name of fieldNames) {\n const key = name.toLowerCase().trim();\n const values = parsed.get(key);\n if (!values) {\n continue;\n }\n for (const value of values) {\n const unfolded = value.replace(/\\r?\\n/g, \"\").replace(/\\s+/g, \" \").trim();\n lines.push(`${key}:${unfolded}`);\n }\n }\n\n return lines.length > 0 ? `${lines.join(CRLF)}${CRLF}` : \"\";\n}\n\n/**\n * Canonicalize body using the relaxed algorithm (RFC 6376 §3.4.4).\n */\nexport function canonicalizeBodyRelaxed(body: string): string {\n const normalized = body.replace(/\\r\\n/g, \"\\n\").replace(/\\r/g, \"\\n\");\n const lines = normalized\n .split(\"\\n\")\n .map((line) => line.replace(/[ \\t]+$/g, \"\").replace(/[ \\t]+/g, \" \"))\n .filter((line) => line.length > 0);\n if (lines.length === 0) {\n return CRLF;\n }\n return `${lines.join(CRLF)}${CRLF}`;\n}\n\n/**\n * Import a PEM-encoded private key into a Web Crypto CryptoKey.\n */\nexport async function importPrivateKey(\n pem: string,\n algorithm: \"rsa-sha256\" | \"ed25519-sha256\",\n): Promise<CryptoKey> {\n if (algorithm === \"ed25519-sha256\" && /OPENSSH PRIVATE KEY/i.test(pem)) {\n throw new Error(\n \"Ed25519 keys must be in PKCS#8 PEM format (-----BEGIN PRIVATE KEY-----). Convert with: openssl pkcs8 -topk8 -nocrypt -in key.pem -out key_pkcs8.pem\",\n );\n }\n\n const der = pemToDer(pem);\n\n const derBuffer = toArrayBuffer(der);\n\n try {\n if (algorithm === \"ed25519-sha256\") {\n return await crypto.subtle.importKey(\"pkcs8\", derBuffer, { name: \"Ed25519\" }, false, [\n \"sign\",\n ]);\n }\n return await crypto.subtle.importKey(\n \"pkcs8\",\n derBuffer,\n { name: \"RSASSA-PKCS1-v1_5\", hash: \"SHA-256\" },\n false,\n [\"sign\"],\n );\n } catch (err) {\n if (algorithm === \"ed25519-sha256\" && err instanceof DOMException) {\n throw new Error(\"Ed25519 DKIM requires Node.js ≥ 18.4, Bun ≥ 1.0, or Cloudflare Workers\", {\n cause: err,\n });\n }\n throw err;\n }\n}\n\n/**\n * Sign a raw MIME message with DKIM.\n */\nexport async function signDKIM(\n rawMessage: Uint8Array,\n config: DKIMConfig,\n): Promise<DKIMSignResult> {\n const algorithm = config.algorithm ?? \"rsa-sha256\";\n const fieldList = (config.headerFieldNames ?? DEFAULT_HEADER_FIELDS)\n .split(\":\")\n .map((f) => f.trim().toLowerCase())\n .filter(Boolean);\n const skip = new Set(\n (config.skipFields ?? \"\")\n .split(\":\")\n .map((f) => f.trim().toLowerCase())\n .filter(Boolean),\n );\n const signFields = fieldList.filter((f) => !skip.has(f));\n\n const text = new TextDecoder().decode(rawMessage);\n const sep = text.indexOf(\"\\r\\n\\r\\n\");\n const headerPart = sep >= 0 ? text.slice(0, sep) : text;\n const bodyPart = sep >= 0 ? text.slice(sep + 4) : \"\";\n\n const bodyCanonical = canonicalizeBodyRelaxed(bodyPart);\n const bodyHash = await sha256Base64(encodeUtf8(bodyCanonical));\n\n const dkimAlgo = algorithm === \"ed25519-sha256\" ? \"ed25519-sha256\" : \"rsa-sha256\";\n const headerList = signFields.join(\":\");\n const timestamp = Math.floor(Date.now() / 1000);\n\n const dkimWithoutSig = [\n `v=1`,\n `a=${dkimAlgo}`,\n `c=relaxed/relaxed`,\n `d=${config.domainName}`,\n `s=${config.keySelector}`,\n `h=${headerList}`,\n `bh=${bodyHash}`,\n `b=`,\n `t=${timestamp}`,\n ].join(\"; \");\n\n const dkimHeaderName = \"dkim-signature\";\n const dkimHeaderValue = dkimWithoutSig;\n const headersWithDkim = `${headerPart}${CRLF}${dkimHeaderName}:${dkimHeaderValue}`;\n const canonical = canonicalizeHeadersRelaxed(headersWithDkim, [...signFields, dkimHeaderName]);\n\n const key = await importPrivateKey(config.privateKey, algorithm);\n const data = encodeUtf8(canonical);\n const signature = await signData(key, data, algorithm);\n const bValue = encodeBase64(signature).replace(/\\r\\n/g, \"\");\n\n const header = `DKIM-Signature: v=1; a=${dkimAlgo}; c=relaxed/relaxed; d=${config.domainName}; s=${config.keySelector}; h=${headerList}; bh=${bodyHash}; b=${bValue}; t=${timestamp}`;\n\n return { header };\n}\n\nfunction parseHeaders(headerBlock: string): Map<string, string[]> {\n const map = new Map<string, string[]>();\n const lines = headerBlock.split(/\\r?\\n/).filter((l) => l.length > 0);\n let currentName = \"\";\n let currentValue = \"\";\n\n const flush = (): void => {\n if (!currentName) {\n return;\n }\n const key = currentName.toLowerCase();\n const list = map.get(key) ?? [];\n list.push(currentValue);\n map.set(key, list);\n currentName = \"\";\n currentValue = \"\";\n };\n\n for (const line of lines) {\n if (/^[ \\t]/.test(line) && currentName) {\n currentValue += ` ${line.trim()}`;\n continue;\n }\n flush();\n const colon = line.indexOf(\":\");\n if (colon > 0) {\n currentName = line.slice(0, colon).trim();\n currentValue = line.slice(colon + 1).trim();\n }\n }\n flush();\n return map;\n}\n\nfunction pemToDer(pem: string): Uint8Array {\n const lines = pem\n .replace(/-----BEGIN[^-]+-----/g, \"\")\n .replace(/-----END[^-]+-----/g, \"\")\n .replace(/\\s/g, \"\");\n const binary = atob(lines);\n const der = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) {\n der[i] = binary.charCodeAt(i);\n }\n return der;\n}\n\nfunction toArrayBuffer(bytes: Uint8Array): ArrayBuffer {\n return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength) as ArrayBuffer;\n}\n\nasync function sha256Base64(data: Uint8Array): Promise<string> {\n const hash = await crypto.subtle.digest(\"SHA-256\", toArrayBuffer(data));\n return encodeBase64(new Uint8Array(hash)).replace(/\\r\\n/g, \"\");\n}\n\nasync function signData(\n key: CryptoKey,\n data: Uint8Array,\n algorithm: \"rsa-sha256\" | \"ed25519-sha256\",\n): Promise<Uint8Array> {\n const buf = toArrayBuffer(data);\n if (algorithm === \"ed25519-sha256\") {\n const sig = await crypto.subtle.sign(\"Ed25519\", key, buf);\n return new Uint8Array(sig);\n }\n const sig = await crypto.subtle.sign({ name: \"RSASSA-PKCS1-v1_5\" }, key, buf);\n return new Uint8Array(sig);\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": "kFAMA,FAAM,EAAO;AAAA,EACP,EAAwB,4DAWvB,SAAS,CAA0B,CAAC,EAAiB,EAA8B,CACxF,IAAM,EAAS,EAAa,CAAO,EAC7B,EAAkB,CAAC,EAEzB,QAAW,KAAQ,EAAY,CAC7B,IAAM,EAAM,EAAK,YAAY,EAAE,KAAK,EAC9B,EAAS,EAAO,IAAI,CAAG,EAC7B,GAAI,CAAC,EACH,SAEF,QAAW,KAAS,EAAQ,CAC1B,IAAM,EAAW,EAAM,QAAQ,SAAU,EAAE,EAAE,QAAQ,OAAQ,GAAG,EAAE,KAAK,EACvE,EAAM,KAAK,GAAG,KAAO,GAAU,GAInC,OAAO,EAAM,OAAS,EAAI,GAAG,EAAM,KAAK,CAAI,IAAI,IAAS,GAMpD,SAAS,CAAuB,CAAC,EAAsB,CAE5D,IAAM,EADa,EAAK,QAAQ,QAAS;AAAA,CAAI,EAAE,QAAQ,MAAO;AAAA,CAAI,EAE/D,MAAM;AAAA,CAAI,EACV,IAAI,CAAC,IAAS,EAAK,QAAQ,WAAY,EAAE,EAAE,QAAQ,UAAW,GAAG,CAAC,EAClE,OAAO,CAAC,IAAS,EAAK,OAAS,CAAC,EACnC,GAAI,EAAM,SAAW,EACnB,OAAO,EAET,MAAO,GAAG,EAAM,KAAK,CAAI,IAAI,IAM/B,eAAsB,CAAgB,CACpC,EACA,EACoB,CACpB,GAAI,IAAc,kBAAoB,uBAAuB,KAAK,CAAG,EACnE,MAAU,MACR,qJACF,EAGF,IAAM,EAAM,EAAS,CAAG,EAElB,EAAY,EAAc,CAAG,EAEnC,GAAI,CACF,GAAI,IAAc,iBAChB,OAAO,MAAM,OA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AAC,EAE9B,OAAO,EAGT,SAAS,CAAa,CAAC,EAAgC,CACrD,OAAO,EAAM,OAAO,MAAM,EAAM,WAAY,EAAM,WAAa,EAAM,UAAU,EAGjF,eAAe,CAAY,CAAC,EAAmC,CAC7D,IAAM,EAAO,MAAM,OAAO,OAAO,OAAO,UAAW,EAAc,CAAI,CAAC,EACtE,OAAO,EAAa,IAAI,WAAW,CAAI,CAAC,EAAE,QAAQ,QAAS,EAAE,EAG/D,eAAe,CAAQ,CACrB,EACA,EACA,EACqB,CACrB,IAAM,EAAM,EAAc,CAAI,EAC9B,GAAI,IAAc,iBAAkB,CAClC,IAAM,EAAM,MAAM,OAAO,OAAO,KAAK,UAAW,EAAK,CAAG,EACxD,OAAO,IAAI,WAAW,CAAG,EAE3B,IAAM,EAAM,MAAM,OAAO,OAAO,KAAK,CAAE,KAAM,mBAAoB,EAAG,EAAK,CAAG,EAC5E,OAAO,IAAI,WAAW,CAAG",
|
|
8
|
+
"debugId": "16320E7654B927CA64756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/dist/idempotency.d.ts
CHANGED
|
@@ -29,6 +29,7 @@ export interface IdempotencyTransportOptions {
|
|
|
29
29
|
export declare class IdempotencyTransport implements Transport {
|
|
30
30
|
/** Transport that performs the actual send when the key is new. */
|
|
31
31
|
private readonly inner;
|
|
32
|
+
readonly provider = "idempotency";
|
|
32
33
|
private readonly store;
|
|
33
34
|
private readonly ttlMs;
|
|
34
35
|
/** Wraps an inner transport with idempotency deduplication. */
|
package/dist/idempotency.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{H as F}from"./chunk-8njyga62.js";import{Q as C,S as B}from"./chunk-93vqxxj2.js";import"./chunk-ywq6s10g.js";import"./chunk-6npp3x3c.js";class G{entries=new Map;async has(q){let w=this.entries.get(q);if(w===void 0)return!1;if(w<=Date.now())return this.entries.delete(q),!1;return!0}async set(q,w){let z=w!==void 0?Date.now()+w:Number.POSITIVE_INFINITY;this.entries.set(q,z)}}function H(q){let w=C(q.from)[0],z=[...B(q.to),...q.cc?B(q.cc):[],...q.bcc?B(q.bcc):[]];return{messageId:q.messageId??"",accepted:B(q.to),rejected:[],response:"Deduped — idempotency key already recorded",envelope:{from:w?.address??"",to:z},deduped:!0}}class J{inner;provider="idempotency";store;ttlMs;constructor(q,w){this.inner=q;this.store=w?.store??new G,this.ttlMs=w?.ttlMs??86400000}async send(q){let w=F(q);if(w===void 0)return this.inner.send(q);if(await this.store.has(w))return H(q);let z=await this.inner.send(q);return await this.store.set(w,this.ttlMs),z}async sendBatch(q){if(this.inner.sendBatch)return this.inner.sendBatch(q);return Promise.all(q.map((w)=>this.send(w)))}async verify(){if(this.inner.verify)return this.inner.verify();return{ok:!0,provider:"idempotency"}}async close(){await this.inner.close?.()}}export{G as MemoryIdempotencyStore,J as IdempotencyTransport};
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=FFD2A6F7847E144564756E2164756E21
|
package/dist/idempotency.js.map
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/idempotency.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"/**\n * @module\n * IdempotencyTransport — decorator that deduplicates sends on retry or replay.\n *\n * Wrap **outside** RetryTransport so all retry attempts share one key:\n *\n * ```ts\n * new IdempotencyTransport(new RetryTransport(inner))\n * ```\n *\n * For production, supply a shared store (Redis, Dragonfly, etc.).\n *\n * @example\n * ```ts\n * import { IdempotencyTransport, MemoryIdempotencyStore } from \"sently/idempotency\";\n * import { RetryTransport } from \"sently/transports/retry\";\n * import { ResendTransport } from \"sently/transports/resend\";\n *\n * const transport = new IdempotencyTransport(\n * new RetryTransport(new ResendTransport({ apiKey })),\n * { store: new MemoryIdempotencyStore(), ttlMs: 86_400_000 },\n * );\n * ```\n */\nimport { extractEmails, parseAddresses } from \"./core/address.js\";\nimport { resolveIdempotencyKey } from \"./core/idempotency-key.js\";\nimport type { MailOptions, SendResult, Transport, VerifyResult } from \"./core/types.js\";\n\n/** Key-value store for idempotency deduplication. */\nexport interface IdempotencyStore {\n /** Returns true when the key was already recorded. */\n has(key: string): Promise<boolean>;\n /** Record a key, optionally expiring after `ttlMs` milliseconds. */\n set(key: string, ttlMs?: number): Promise<void>;\n}\n\n/** In-memory idempotency store with optional TTL expiry. Suitable for single-process use. */\nexport class MemoryIdempotencyStore implements IdempotencyStore {\n private readonly entries = new Map<string, number>();\n\n /** Returns true when the key exists and has not expired. */\n async has(key: string): Promise<boolean> {\n const expiresAt = this.entries.get(key);\n if (expiresAt === undefined) {\n return false;\n }\n if (expiresAt <= Date.now()) {\n this.entries.delete(key);\n return false;\n }\n return true;\n }\n\n /** Record a key with optional TTL in milliseconds. */\n async set(key: string, ttlMs?: number): Promise<void> {\n const expiresAt = ttlMs !== undefined ? Date.now() + ttlMs : Number.POSITIVE_INFINITY;\n this.entries.set(key, expiresAt);\n }\n}\n\n/** Options for {@link IdempotencyTransport}. */\nexport interface IdempotencyTransportOptions {\n /** Store used to track sent keys. Defaults to {@link MemoryIdempotencyStore}. */\n store?: IdempotencyStore;\n /** TTL in milliseconds for recorded keys. Default: 24 hours. */\n ttlMs?: number;\n}\n\nfunction syntheticDedupedResult(options: MailOptions): SendResult {\n const from = parseAddresses(options.from)[0];\n const to = [\n ...extractEmails(options.to),\n ...(options.cc ? extractEmails(options.cc) : []),\n ...(options.bcc ? extractEmails(options.bcc) : []),\n ];\n\n return {\n messageId: options.messageId ?? \"\",\n accepted: extractEmails(options.to),\n rejected: [],\n response: \"Deduped — idempotency key already recorded\",\n envelope: {\n from: from?.address ?? \"\",\n to,\n },\n deduped: true,\n };\n}\n\n/**\n * Transport decorator that skips duplicate sends when an idempotency key\n * was already recorded. Checks the store once before delegating to the inner\n * transport, so retries inside RetryTransport reuse the same key automatically.\n */\nexport class IdempotencyTransport implements Transport {\n private readonly store: IdempotencyStore;\n private readonly ttlMs: number;\n\n /** Wraps an inner transport with idempotency deduplication. */\n constructor(\n /** Transport that performs the actual send when the key is new. */\n private readonly inner: Transport,\n options?: IdempotencyTransportOptions,\n ) {\n this.store = options?.store ?? new MemoryIdempotencyStore();\n this.ttlMs = options?.ttlMs ?? 86_400_000;\n }\n\n /** Sends once per idempotency key; returns a synthetic result on duplicate keys. */\n async send(options: MailOptions): Promise<SendResult> {\n const key = resolveIdempotencyKey(options);\n if (key === undefined) {\n return this.inner.send(options);\n }\n\n if (await this.store.has(key)) {\n return syntheticDedupedResult(options);\n }\n\n const result = await this.inner.send(options);\n await this.store.set(key, this.ttlMs);\n return result;\n }\n\n /** Delegates batch sends to the inner transport when available. */\n async sendBatch(messages: MailOptions[]): Promise<SendResult[]> {\n if (this.inner.sendBatch) {\n return this.inner.sendBatch(messages);\n }\n return Promise.all(messages.map((message) => this.send(message)));\n }\n\n /** Delegates to the inner transport verify or returns a default success result. */\n async verify(): Promise<VerifyResult> {\n if (this.inner.verify) {\n return this.inner.verify();\n }\n return { ok: true, provider: \"idempotency\" };\n }\n\n /** Delegates close to the inner transport if available. */\n async close(): Promise<void> {\n await this.inner.close?.();\n }\n}\n"
|
|
5
|
+
"/**\n * @module\n * IdempotencyTransport — decorator that deduplicates sends on retry or replay.\n *\n * Wrap **outside** RetryTransport so all retry attempts share one key:\n *\n * ```ts\n * new IdempotencyTransport(new RetryTransport(inner))\n * ```\n *\n * For production, supply a shared store (Redis, Dragonfly, etc.).\n *\n * @example\n * ```ts\n * import { IdempotencyTransport, MemoryIdempotencyStore } from \"sently/idempotency\";\n * import { RetryTransport } from \"sently/transports/retry\";\n * import { ResendTransport } from \"sently/transports/resend\";\n *\n * const transport = new IdempotencyTransport(\n * new RetryTransport(new ResendTransport({ apiKey })),\n * { store: new MemoryIdempotencyStore(), ttlMs: 86_400_000 },\n * );\n * ```\n */\nimport { extractEmails, parseAddresses } from \"./core/address.js\";\nimport { resolveIdempotencyKey } from \"./core/idempotency-key.js\";\nimport type { MailOptions, SendResult, Transport, VerifyResult } from \"./core/types.js\";\n\n/** Key-value store for idempotency deduplication. */\nexport interface IdempotencyStore {\n /** Returns true when the key was already recorded. */\n has(key: string): Promise<boolean>;\n /** Record a key, optionally expiring after `ttlMs` milliseconds. */\n set(key: string, ttlMs?: number): Promise<void>;\n}\n\n/** In-memory idempotency store with optional TTL expiry. Suitable for single-process use. */\nexport class MemoryIdempotencyStore implements IdempotencyStore {\n private readonly entries = new Map<string, number>();\n\n /** Returns true when the key exists and has not expired. */\n async has(key: string): Promise<boolean> {\n const expiresAt = this.entries.get(key);\n if (expiresAt === undefined) {\n return false;\n }\n if (expiresAt <= Date.now()) {\n this.entries.delete(key);\n return false;\n }\n return true;\n }\n\n /** Record a key with optional TTL in milliseconds. */\n async set(key: string, ttlMs?: number): Promise<void> {\n const expiresAt = ttlMs !== undefined ? Date.now() + ttlMs : Number.POSITIVE_INFINITY;\n this.entries.set(key, expiresAt);\n }\n}\n\n/** Options for {@link IdempotencyTransport}. */\nexport interface IdempotencyTransportOptions {\n /** Store used to track sent keys. Defaults to {@link MemoryIdempotencyStore}. */\n store?: IdempotencyStore;\n /** TTL in milliseconds for recorded keys. Default: 24 hours. */\n ttlMs?: number;\n}\n\nfunction syntheticDedupedResult(options: MailOptions): SendResult {\n const from = parseAddresses(options.from)[0];\n const to = [\n ...extractEmails(options.to),\n ...(options.cc ? extractEmails(options.cc) : []),\n ...(options.bcc ? extractEmails(options.bcc) : []),\n ];\n\n return {\n messageId: options.messageId ?? \"\",\n accepted: extractEmails(options.to),\n rejected: [],\n response: \"Deduped — idempotency key already recorded\",\n envelope: {\n from: from?.address ?? \"\",\n to,\n },\n deduped: true,\n };\n}\n\n/**\n * Transport decorator that skips duplicate sends when an idempotency key\n * was already recorded. Checks the store once before delegating to the inner\n * transport, so retries inside RetryTransport reuse the same key automatically.\n */\nexport class IdempotencyTransport implements Transport {\n readonly provider = \"idempotency\";\n\n private readonly store: IdempotencyStore;\n private readonly ttlMs: number;\n\n /** Wraps an inner transport with idempotency deduplication. */\n constructor(\n /** Transport that performs the actual send when the key is new. */\n private readonly inner: Transport,\n options?: IdempotencyTransportOptions,\n ) {\n this.store = options?.store ?? new MemoryIdempotencyStore();\n this.ttlMs = options?.ttlMs ?? 86_400_000;\n }\n\n /** Sends once per idempotency key; returns a synthetic result on duplicate keys. */\n async send(options: MailOptions): Promise<SendResult> {\n const key = resolveIdempotencyKey(options);\n if (key === undefined) {\n return this.inner.send(options);\n }\n\n if (await this.store.has(key)) {\n return syntheticDedupedResult(options);\n }\n\n const result = await this.inner.send(options);\n await this.store.set(key, this.ttlMs);\n return result;\n }\n\n /** Delegates batch sends to the inner transport when available. */\n async sendBatch(messages: MailOptions[]): Promise<SendResult[]> {\n if (this.inner.sendBatch) {\n return this.inner.sendBatch(messages);\n }\n return Promise.all(messages.map((message) => this.send(message)));\n }\n\n /** Delegates to the inner transport verify or returns a default success result. */\n async verify(): Promise<VerifyResult> {\n if (this.inner.verify) {\n return this.inner.verify();\n }\n return { ok: true, provider: \"idempotency\" };\n }\n\n /** Delegates close to the inner transport if available. */\n async close(): Promise<void> {\n await this.inner.close?.();\n }\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": "iKAqCO,AAAM,LAAmD,LAC7C,QAAU,IAAI,SAGzB,IAAG,CAAC,EAA+B,CACvC,IAAM,EAAY,KAAK,QAAQ,IAAI,CAAG,EACtC,GAAI,IAAc,OAChB,MAAO,GAET,GAAI,GAAa,KAAK,IAAI,EAExB,OADA,KAAK,QAAQ,OAAO,CAAG,EAChB,GAET,MAAO,QAIH,IAAG,CAAC,EAAa,EAA+B,CACpD,IAAM,EAAY,IAAU,OAAY,KAAK,IAAI,EAAI,EAAQ,OAAO,kBACpE,KAAK,QAAQ,IAAI,EAAK,CAAS,EAEnC,CAUA,SAAS,CAAsB,CAAC,EAAkC,CAChE,IAAM,EAAO,EAAe,EAAQ,IAAI,EAAE,GACpC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|
|
|
2
2
|
* @module
|
|
3
3
|
* Main sently entrypoint — shared types, mailer factories, runtime detection, and OAuth2.
|
|
4
4
|
*
|
|
5
|
-
* Import transports
|
|
6
|
-
* (e.g. `sently/transports/resend`, `sently/webhooks`)
|
|
5
|
+
* Import provider transports and webhook parsers from their subpaths
|
|
6
|
+
* (e.g. `sently/transports/resend`, `sently/transports/sndr`, `sently/webhooks/sndr`)
|
|
7
|
+
* for the smallest bundle. The main barrel only re-exports core APIs plus
|
|
8
|
+
* routing helpers (`FallbackTransport`, `WeightedFallbackTransport`) and
|
|
9
|
+
* `CloudflareEmailTransport`.
|
|
7
10
|
*
|
|
8
11
|
* @example
|
|
9
12
|
* ```ts
|
|
@@ -45,5 +48,24 @@ export {
|
|
|
45
48
|
/** Create a mailer for custom transports (HTTP APIs, preview, retry). Prefer `sently/mailer` for smallest bundles. */
|
|
46
49
|
createMailer, } from "./mailer.js";
|
|
47
50
|
export {
|
|
51
|
+
/** Ready-made console logging hooks for mailer lifecycle events. */
|
|
52
|
+
consoleObserver, } from "./observability/console.js";
|
|
53
|
+
export {
|
|
48
54
|
/** Create a mailer from SMTP host/port config (pooling, adapters). Prefer `sently/smtp` for smallest SMTP bundles. */
|
|
49
55
|
createSMTPMailer, } from "./smtp-mailer.js";
|
|
56
|
+
export type { CloudflareEmailConfig, CloudflareEmailMessage, CloudflareSendEmailFn, } from "./transports/cloudflare-email.js";
|
|
57
|
+
export {
|
|
58
|
+
/** Error thrown when the Cloudflare Email binding rejects a send. */
|
|
59
|
+
CloudflareEmailError,
|
|
60
|
+
/** Cloudflare Workers `send_email` binding transport. */
|
|
61
|
+
CloudflareEmailTransport, } from "./transports/cloudflare-email.js";
|
|
62
|
+
export type { FallbackAttempt, FallbackOptions, FallbackProviderVerifyResult, FallbackVerifyAllResult, } from "./transports/fallback.js";
|
|
63
|
+
export {
|
|
64
|
+
/** Thrown when every transport in a fallback chain fails. */
|
|
65
|
+
FallbackError,
|
|
66
|
+
/** Provider failover decorator — routes through an ordered list of transports. */
|
|
67
|
+
FallbackTransport, } from "./transports/fallback.js";
|
|
68
|
+
export type { WeightedTransportEntry } from "./transports/weighted-fallback.js";
|
|
69
|
+
export {
|
|
70
|
+
/** Weighted provider routing with failover on error. */
|
|
71
|
+
WeightedFallbackTransport, } from "./transports/weighted-fallback.js";
|
package/dist/index.js
CHANGED
|
@@ -24,7 +24,30 @@ export {
|
|
|
24
24
|
|
|
25
25
|
createMailer,
|
|
26
26
|
} from "./mailer.js";
|
|
27
|
+
export {
|
|
28
|
+
|
|
29
|
+
consoleObserver,
|
|
30
|
+
} from "./observability/console.js";
|
|
27
31
|
export {
|
|
28
32
|
|
|
29
33
|
createSMTPMailer,
|
|
30
34
|
} from "./smtp-mailer.js";
|
|
35
|
+
|
|
36
|
+
export {
|
|
37
|
+
|
|
38
|
+
CloudflareEmailError,
|
|
39
|
+
|
|
40
|
+
CloudflareEmailTransport,
|
|
41
|
+
} from "./transports/cloudflare-email.js";
|
|
42
|
+
|
|
43
|
+
export {
|
|
44
|
+
|
|
45
|
+
FallbackError,
|
|
46
|
+
|
|
47
|
+
FallbackTransport,
|
|
48
|
+
} from "./transports/fallback.js";
|
|
49
|
+
|
|
50
|
+
export {
|
|
51
|
+
|
|
52
|
+
WeightedFallbackTransport,
|
|
53
|
+
} from "./transports/weighted-fallback.js";
|
package/dist/mailer.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{L as a,M as b}from"./chunk-5915vbcj.js";import"./chunk-gp4fwrs8.js";import"./chunk-0qxws3kj.js";import"./chunk-93vqxxj2.js";import"./chunk-qtkd5bak.js";import"./chunk-ywq6s10g.js";import"./chunk-tamww15j.js";import"./chunk-6npp3x3c.js";export{a as createMailer,b as MailerImpl};
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=E91F43209A181C3464756E2164756E21
|
package/dist/mailer.js.map
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* Ready-made observability helpers for sently.
|
|
4
|
+
*/
|
|
5
|
+
import type { MailerHooks } from "../core/types.js";
|
|
6
|
+
/**
|
|
7
|
+
* Returns {@link MailerHooks} that log lifecycle events to the console.
|
|
8
|
+
* For production, write your own hooks targeting your metrics/tracing system.
|
|
9
|
+
*
|
|
10
|
+
* @param prefix — log line prefix. Default: `'[sently]'`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function consoleObserver(prefix?: string): MailerHooks;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import"../chunk-6npp3x3c.js";function E(A="[sently]"){return{onSend:({subject:q})=>{console.log(`${A} sending: ${q}`)},onSuccess:({subject:q},C,z)=>{let B=z!==void 0?` (${z.toFixed(0)}ms)`:"";console.log(`${A} sent: ${q}${B}`)},onError:({subject:q},C,z)=>{let B=z!==void 0?` (${z.toFixed(0)}ms)`:"";console.error(`${A} failed: ${q}${B}`,C)}}}export{E as consoleObserver};
|
|
2
|
+
|
|
3
|
+
//# debugId=0D8FEC4487F45FD464756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/observability/console.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * @module\n * Ready-made observability helpers for sently.\n */\nimport type { MailerHooks } from \"../core/types.js\";\n\n/**\n * Returns {@link MailerHooks} that log lifecycle events to the console.\n * For production, write your own hooks targeting your metrics/tracing system.\n *\n * @param prefix — log line prefix. Default: `'[sently]'`.\n */\nexport function consoleObserver(prefix = \"[sently]\"): MailerHooks {\n return {\n onSend: ({ subject }) => {\n console.log(`${prefix} sending: ${subject}`);\n },\n onSuccess: ({ subject }, _result, durationMs) => {\n const timing = durationMs !== undefined ? ` (${durationMs.toFixed(0)}ms)` : \"\";\n console.log(`${prefix} sent: ${subject}${timing}`);\n },\n onError: ({ subject }, error, durationMs) => {\n const timing = durationMs !== undefined ? ` (${durationMs.toFixed(0)}ms)` : \"\";\n console.error(`${prefix} failed: ${subject}${timing}`, error);\n },\n };\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": "6BAYO,SAAS,CAAe,CAAC,EAAS,WAAyB,CAChE,MAAO,CACL,OAAQ,EAAG,aAAc,CACvB,QAAQ,IAAI,GAAG,cAAmB,GAAS,GAE7C,UAAW,EAAG,WAAW,EAAS,IAAe,CAC/C,IAAM,EAAS,IAAe,OAAY,KAAK,EAAW,QAAQ,CAAC,OAAS,GAC5E,QAAQ,IAAI,GAAG,WAAgB,IAAU,GAAQ,GAEnD,QAAS,EAAG,WAAW,EAAO,IAAe,CAC3C,IAAM,EAAS,IAAe,OAAY,KAAK,EAAW,QAAQ,CAAC,OAAS,GAC5E,QAAQ,MAAM,GAAG,aAAkB,IAAU,IAAU,CAAK,EAEhE",
|
|
8
|
+
"debugId": "0D8FEC4487F45FD464756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
package/dist/plugins/react.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{fa as B}from"../chunk-6npp3x3c.js";function F(){return async(j)=>{if(j.react===void 0||j.react===null)return j;let{render:k}=await import("@react-email/render"),q=j.html??await k(j.react,{pretty:!1}),z=j.text??await k(j.react,{plainText:!0}),{react:D,...A}=j;return{...A,html:q,text:z}}}export{F as reactPlugin};
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=688D707C4B4EB1C964756E2164756E21
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"/**\n * @module\n * React Email plugin for sently.\n * Renders a React element to HTML and plain text via `@react-email/render`.\n *\n * @example\n * ```ts\n * import { reactPlugin } from \"sently/react\";\n * import { WelcomeEmail } from \"./emails/welcome\";\n *\n * const mailer = await createMailer({\n * transport: new ResendTransport({ apiKey }),\n * plugins: [reactPlugin()],\n * });\n *\n * await mailer.send({\n * from: \"...\",\n * to: \"...\",\n * subject: \"Welcome!\",\n * react: WelcomeEmail({ name: \"Ali\" }),\n * });\n * ```\n */\nimport type { MailOptions, MailPlugin } from \"../core/types.js\";\n\n/** Mail options with a React element body (requires `react` peer). */\nexport interface ReactMailOptions extends Omit<MailOptions, \"react\"> {\n /** React element rendered to html + text by the react plugin. */\n react?: import(\"react\").ReactElement;\n}\n\n/**\n * Create a plugin that renders `options.react` to HTML and plain text.\n * Explicit `html` / `text` values always win. The `react` field is stripped\n * before options reach the transport.\n */\nexport function reactPlugin(): MailPlugin {\n return async (options: MailOptions): Promise<MailOptions> => {\n if (options.react === undefined || options.react === null) {\n return options;\n }\n\n const { render } = await import(\"@react-email/render\");\n\n const html =\n options.html ??\n (await render(options.react as Parameters<typeof render>[0], { pretty: false }));\n\n const text =\n options.text ??\n (await render(options.react as Parameters<typeof render>[0], { plainText: true }));\n\n const { react: _react, ...rest } = options;\n return { ...rest, html, text };\n };\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": "0CAoCO,SAAS,CAAW,EAAe,CACxC,MAAO,OAAO,IAA+C,CAC3D,GAAI,EAAQ,QAAU,QAAa,EAAQ,QAAU,KACnD,OAAO,EAGT,IAAQ,UAAW,KAAa,+BAE1B,EACJ,EAAQ,MACP,MAAM,EAAO,EAAQ,MAAuC,CAAE,OAAQ,EAAM,CAAC,EAE1E,EACJ,EAAQ,MACP,MAAM,EAAO,EAAQ,MAAuC,CAAE,UAAW,EAAK,CAAC,GAE1E,MAAO,KAAW,GAAS,EACnC,MAAO,IAAK,EAAM,OAAM,MAAK",
|
|
8
|
+
"debugId": "688D707C4B4EB1C964756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/dist/plugins/template.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import"../chunk-
|
|
1
|
+
import"../chunk-6npp3x3c.js";function E(q,j){return q.replace(/\{\{(\w+)\}\}/g,(z,A)=>{let w=j[A];return w!==void 0&&w!==null?String(w):""})}function F(q){return(j)=>{if(!j.template)return j;let z=q.templates[j.template];if(!z)throw Error(`sently: template "${j.template}" not found`);let A=q.engine(z,j.data??{}),{template:w,data:D,...B}=j;return{...B,html:A}}}export{F as templatePlugin,E as simpleEngine};
|
|
2
2
|
|
|
3
3
|
//# debugId=094B3D1AC9B011AB64756E2164756E21
|
package/dist/pool/pool.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{m as B,n as Q,o as U,p as V}from"../chunk-vjpds2pf.js";import"../chunk-b602dhck.js";import{u as K}from"../chunk-8dty8c4p.js";import"../chunk-n0qeyzqm.js";import{I as N}from"../chunk-skqhj0rm.js";import{O as G}from"../chunk-0qxws3kj.js";import"../chunk-93vqxxj2.js";import"../chunk-ywq6s10g.js";import"../chunk-tamww15j.js";import"../chunk-6npp3x3c.js";async function W(k){let q=B(k.config),w=await k.createAdapter();await w.connect(k.connectHost,q.port),await Q(w,q);let z=0,D=!0,F=Promise.resolve(),X=k.maxMessages;return{get idle(){return D},get messageCount(){return z},get usable(){return z<X},async send(H){let Y=async()=>{D=!1;try{let Z={...H,attachments:await N(H.attachments)},_=await K(Z,q.dkim),$=await U(w,_);return z+=1,$}finally{D=!0}},J=F.then(Y);return F=J.then(()=>{return},()=>{return}),J},async close(){await F,await V(w)}}}class b{config;maxConnections;maxMessages;createAdapterFn;rateLimiter;connections=[];queue=[];draining=!1;closed=!1;processChain=Promise.resolve();constructor(k,q){if(this.config=k,this.maxConnections=k.maxConnections??5,this.maxMessages=k.maxMessages??100,q?.createAdapter){let w=q.createAdapter;this.createAdapterFn=async()=>w()}else if(k.adapter)this.createAdapterFn=async()=>k.adapter;else throw Error("SMTPPool requires config.adapter or options.createAdapter");if(k.rateDelta!==void 0&&k.rateDelta>0)this.rateLimiter=new G(k.rateDelta,k.rateLimit??1000,q?.now);else this.rateLimiter=null}async send(k){if(this.draining)throw Error("SMTPPool is closing — no new messages accepted");if(this.closed)throw Error("SMTPPool is closed");if(this.rateLimiter)await this.rateLimiter.acquire();return new Promise((q,w)=>{this.queue.push({options:k,resolve:q,reject:w}),this.scheduleProcess()})}scheduleProcess(){this.processChain=this.processChain.then(()=>this.processQueue()).catch(()=>{return})}async verify(){try{let k=await this.spawnConnection();try{return{ok:!0,provider:"smtp-pool"}}finally{await k.close(),this.removeConnection(k)}}catch(k){return{ok:!1,provider:"smtp-pool",message:k instanceof Error?k.message:String(k)}}}async close(){this.draining=!0,await this.drainQueue(),await Promise.allSettled(this.connections.map((k)=>k.close())),this.connections.length=0,this.closed=!0}get connectionCount(){return this.connections.length}get queueSize(){return this.queue.length}async processQueue(){if(this.draining)return;while(this.queue.length>0){let k=this.connections.find((q)=>q.idle&&q.usable);if(k){let q=this.queue.shift();if(!q)break;try{let w=await k.send(q.options);if(q.resolve(w),!k.usable)await k.close(),this.removeConnection(k)}catch(w){q.reject(w),await k.close().catch(()=>{return}),this.removeConnection(k)}continue}if(this.connections.length<this.maxConnections){let q=this.queue.shift();if(!q)break;let w=await this.spawnConnection();try{let z=await w.send(q.options);if(q.resolve(z),!w.usable)await w.close(),this.removeConnection(w)}catch(z){q.reject(z),await w.close().catch(()=>{return}),this.removeConnection(w)}continue}break}}async spawnConnection(){let k=B(this.config),q=await W({config:this.config,maxMessages:this.maxMessages,connectHost:k.host,createAdapter:this.createAdapterFn});return this.connections.push(q),q}removeConnection(k){let q=this.connections.indexOf(k);if(q>=0)this.connections.splice(q,1)}async drainQueue(){while(this.queue.length>0||this.connections.some((k)=>!k.idle))if(await this.processQueue(),this.queue.length>0)await new Promise((k)=>setTimeout(k,10))}}export{b as SMTPPool,G as RateLimiter};
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=47D346C1EF337DEF64756E2164756E21
|
package/dist/pool/pool.js.map
CHANGED
|
@@ -6,6 +6,6 @@
|
|
|
6
6
|
"/**\n * @module\n * SMTP connection pool with optional rate limiting.\n *\n * @example\n * ```ts\n * import { SMTPPool } from \"sently/pool\";\n * import { NodeAdapter } from \"sently/adapters/node\";\n *\n * const pool = new SMTPPool({\n * host: \"smtp.example.com\",\n * auth: { user: \"you@example.com\", pass: \"secret\" },\n * adapter: new NodeAdapter(),\n * pool: true,\n * maxConnections: 5,\n * });\n *\n * await pool.send({\n * from: \"you@example.com\",\n * to: \"recipient@example.com\",\n * subject: \"Hello\",\n * text: \"Pooled send\",\n * });\n * ```\n */\n\nimport { RateLimiter } from \"../core/rate-limiter.js\";\nimport type {\n MailOptions,\n PoolConfig,\n SendResult,\n SMTPConfig,\n SocketAdapter,\n Transport,\n VerifyResult,\n} from \"../core/types.js\";\nimport { resolveSMTPConfig } from \"../transports/smtp.js\";\nimport { createPooledConnection, type PooledConnection } from \"./connection.js\";\n\n/** Options for {@link SMTPPool}. */\nexport interface SMTPPoolOptions {\n /** Factory for a new socket adapter per pooled connection. */\n createAdapter?: () => Promise<SocketAdapter> | SocketAdapter;\n /** Injectable clock for rate limiting (testing). */\n now?: () => number;\n}\n\ninterface QueueEntry {\n options: MailOptions;\n resolve: (result: SendResult) => void;\n reject: (error: unknown) => void;\n}\n\n/**\n * SMTP connection pool with optional rate limiting.\n */\nexport class SMTPPool implements Transport {\n /** Resolved SMTP and pool configuration. */\n private readonly config: SMTPConfig & PoolConfig;\n /** Maximum simultaneous pooled connections. */\n private readonly maxConnections: number;\n /** Maximum messages per connection before recycle. */\n private readonly maxMessages: number;\n /** Factory that creates a socket adapter for each new connection. */\n private readonly createAdapterFn: () => Promise<SocketAdapter>;\n /** Optional token-bucket rate limiter, or null when disabled. */\n private readonly rateLimiter: RateLimiter | null;\n /** Active pooled SMTP connections. */\n private readonly connections: PooledConnection[] = [];\n /** Pending send operations waiting for a connection. */\n private readonly queue: QueueEntry[] = [];\n /** True while {@link close} is draining; rejects new sends. */\n private draining = false;\n /** True after the pool has fully closed. */\n private closed = false;\n /** Serializes queue processing to avoid concurrent drain races. */\n private processChain: Promise<void> = Promise.resolve();\n\n /** Creates an SMTP connection pool. */\n constructor(config: SMTPConfig & PoolConfig, options?: SMTPPoolOptions) {\n this.config = config;\n this.maxConnections = config.maxConnections ?? 5;\n this.maxMessages = config.maxMessages ?? 100;\n\n if (options?.createAdapter) {\n const factory = options.createAdapter;\n this.createAdapterFn = async () => factory();\n } else if (config.adapter) {\n this.createAdapterFn = async () => config.adapter as SocketAdapter;\n } else {\n throw new Error(\"SMTPPool requires config.adapter or options.createAdapter\");\n }\n\n if (config.rateDelta !== undefined && config.rateDelta > 0) {\n this.rateLimiter = new RateLimiter(config.rateDelta, config.rateLimit ?? 1000, options?.now);\n } else {\n this.rateLimiter = null;\n }\n }\n\n /** Sends a message through the pool. */\n async send(options: MailOptions): Promise<SendResult> {\n if (this.draining) {\n throw new Error(\"SMTPPool is closing — no new messages accepted\");\n }\n if (this.closed) {\n throw new Error(\"SMTPPool is closed\");\n }\n if (this.rateLimiter) {\n await this.rateLimiter.acquire();\n }\n return new Promise<SendResult>((resolve, reject) => {\n this.queue.push({ options, resolve, reject });\n this.scheduleProcess();\n });\n }\n\n /** Schedules asynchronous processing of the send queue. */\n private scheduleProcess(): void {\n this.processChain = this.processChain.then(() => this.processQueue()).catch(() => undefined);\n }\n\n /** Verifies connectivity using a temporary connection. */\n async verify(): Promise<VerifyResult> {\n try {\n const conn = await this.spawnConnection();\n try {\n return { ok: true, provider: \"smtp-pool\" };\n } finally {\n await conn.close();\n this.removeConnection(conn);\n }\n } catch (err) {\n return {\n ok: false,\n provider: \"smtp-pool\",\n message: err instanceof Error ? err.message : String(err),\n };\n }\n }\n\n /** Drains the queue and closes all connections. */\n async close(): Promise<void> {\n this.draining = true;\n await this.drainQueue();\n await Promise.allSettled(this.connections.map((c) => c.close()));\n this.connections.length = 0;\n this.closed = true;\n }\n\n /** Current number of open pooled connections. */\n get connectionCount(): number {\n return this.connections.length;\n }\n\n /** Number of messages waiting in the send queue. */\n get queueSize(): number {\n return this.queue.length;\n }\n\n /** Dispatches queued messages to idle or newly spawned connections. */\n private async processQueue(): Promise<void> {\n if (this.draining) {\n return;\n }\n\n while (this.queue.length > 0) {\n const idleConn = this.connections.find((c) => c.idle && c.usable);\n if (idleConn) {\n const entry = this.queue.shift();\n if (!entry) {\n break;\n }\n try {\n const result = await idleConn.send(entry.options);\n entry.resolve(result);\n if (!idleConn.usable) {\n await idleConn.close();\n this.removeConnection(idleConn);\n }\n } catch (err) {\n entry.reject(err);\n await idleConn.close().catch(() => undefined);\n this.removeConnection(idleConn);\n }\n continue;\n }\n\n if (this.connections.length < this.maxConnections) {\n const entry = this.queue.shift();\n if (!entry) {\n break;\n }\n const conn = await this.spawnConnection();\n try {\n const result = await conn.send(entry.options);\n entry.resolve(result);\n if (!conn.usable) {\n await conn.close();\n this.removeConnection(conn);\n }\n } catch (err) {\n entry.reject(err);\n await conn.close().catch(() => undefined);\n this.removeConnection(conn);\n }\n continue;\n }\n\n break;\n }\n }\n\n /** Opens a new authenticated pooled SMTP connection. */\n private async spawnConnection(): Promise<PooledConnection> {\n const resolved = resolveSMTPConfig(this.config);\n const conn = await createPooledConnection({\n config: this.config,\n maxMessages: this.maxMessages,\n connectHost: resolved.host,\n createAdapter: this.createAdapterFn,\n });\n this.connections.push(conn);\n return conn;\n }\n\n /** Removes a connection from the active pool list. */\n private removeConnection(conn: PooledConnection): void {\n const index = this.connections.indexOf(conn);\n if (index >= 0) {\n this.connections.splice(index, 1);\n }\n }\n\n /** Waits until the send queue and in-flight work are fully drained. */\n private async drainQueue(): Promise<void> {\n while (this.queue.length > 0 || this.connections.some((c) => !c.idle)) {\n await this.processQueue();\n if (this.queue.length > 0) {\n await new Promise((r) => setTimeout(r, 10));\n }\n }\n }\n}\n\n/** @internal Exposed for deterministic rate limiter tests. */\nexport { RateLimiter } from \"../core/rate-limiter.js\";\n"
|
|
7
7
|
],
|
|
8
8
|
"mappings": "oZAuCA,UAAsB,JAAsB,JAC1C,HAC2B,JAC3B,DAAM,HA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,EACpB,KAAK,MAAM,OAAS,EACtB,MAAM,IAAI,QAAQ,CAAC,IAAM,WAAW,EAAG,EAAE,CAAC,EAIlD",
|
|
9
|
-
"debugId": "
|
|
9
|
+
"debugId": "47D346C1EF337DEF64756E2164756E21",
|
|
10
10
|
"names": []
|
|
11
11
|
}
|
package/dist/push.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { PushHooks, PushOptions, PushPlugin, PushSendResult, PushTransport } from "./core/push-types.js";
|
|
2
|
+
import type { VerifyResult } from "./core/types.js";
|
|
3
|
+
/** Configuration for {@link createPushSender}. */
|
|
4
|
+
export interface PushSenderConfig {
|
|
5
|
+
/** Push delivery transport. */
|
|
6
|
+
transport: PushTransport;
|
|
7
|
+
/** Optional plugins run before each send. */
|
|
8
|
+
plugins?: PushPlugin[];
|
|
9
|
+
/** Optional lifecycle hooks for metrics and tracing. */
|
|
10
|
+
hooks?: PushHooks;
|
|
11
|
+
}
|
|
12
|
+
/** Push sender returned by {@link createPushSender}. */
|
|
13
|
+
export interface PushSender {
|
|
14
|
+
/** Send a push notification through the configured transport. */
|
|
15
|
+
send(options: PushOptions): Promise<PushSendResult>;
|
|
16
|
+
/** Test connectivity and credentials without sending. */
|
|
17
|
+
verify(): Promise<VerifyResult>;
|
|
18
|
+
/** Release resources held by the transport. */
|
|
19
|
+
close(): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Create a push sender that wraps a {@link PushTransport}.
|
|
23
|
+
*
|
|
24
|
+
* Pipeline: plugins → onSend → transport.send → onSuccess / onError.
|
|
25
|
+
*/
|
|
26
|
+
export declare function createPushSender(config: PushSenderConfig): PushSender;
|
package/dist/push.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{V as I}from"./chunk-yp311efr.js";import{W as z,X as G}from"./chunk-qtkd5bak.js";import"./chunk-ywq6s10g.js";import"./chunk-6npp3x3c.js";async function M(y,m){return{...y.messageId!==void 0?{messageId:y.messageId}:{},endpoint:await I(y.subscription.endpoint),provider:m.provider??"push"}}function R(y){let{transport:m,plugins:J,hooks:A}=y;return{async send(K){let D=await G(K,J),B=await M(D,m);await z(A?.onSend,B);let F=performance.now();try{let q=await m.send(D),L={...B,messageId:q.messageId};return await z(A?.onSuccess,L,q,performance.now()-F),q}catch(q){throw await z(A?.onError,B,q,performance.now()-F),q}},async verify(){if(m.verify)return m.verify();return{ok:!0,provider:"push"}},async close(){if(m.close)await m.close()}}}export{R as createPushSender};
|
|
2
|
+
|
|
3
|
+
//# debugId=EF4B8931029EC5E464756E2164756E21
|
package/dist/push.js.map
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/push.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * @module\n * Web Push sender orchestrator — plugins, hooks, and transport.send pipeline.\n *\n * Sently-first: apps call {@link createPushSender}; providers implement\n * {@link PushTransport}.\n *\n * @example\n * ```ts\n * import { createPushSender } from \"sently/push\";\n * import { WebPushTransport } from \"sently/transports/webpush\";\n *\n * const push = createPushSender({\n * transport: new WebPushTransport({\n * vapidPublicKey: \"...\",\n * vapidPrivateKey: \"...\",\n * subject: \"mailto:you@example.com\",\n * }),\n * });\n *\n * await push.send({\n * subscription: { endpoint: \"...\", keys: { p256dh: \"...\", auth: \"...\" } },\n * title: \"Hello\",\n * body: \"World\",\n * });\n * ```\n */\nimport { invokeHook } from \"./core/hooks.js\";\nimport { runPlugins } from \"./core/plugin.js\";\nimport { redactPushEndpoint } from \"./core/push-endpoint.js\";\nimport type {\n PushHookContext,\n PushHooks,\n PushOptions,\n PushPlugin,\n PushSendResult,\n PushTransport,\n} from \"./core/push-types.js\";\nimport type { VerifyResult } from \"./core/types.js\";\n\n/** Configuration for {@link createPushSender}. */\nexport interface PushSenderConfig {\n /** Push delivery transport. */\n transport: PushTransport;\n /** Optional plugins run before each send. */\n plugins?: PushPlugin[];\n /** Optional lifecycle hooks for metrics and tracing. */\n hooks?: PushHooks;\n}\n\n/** Push sender returned by {@link createPushSender}. */\nexport interface PushSender {\n /** Send a push notification through the configured transport. */\n send(options: PushOptions): Promise<PushSendResult>;\n /** Test connectivity and credentials without sending. */\n verify(): Promise<VerifyResult>;\n /** Release resources held by the transport. */\n close(): Promise<void>;\n}\n\nasync function buildPushHookContext(\n options: PushOptions,\n transport: PushTransport,\n): Promise<PushHookContext> {\n return {\n ...(options.messageId !== undefined ? { messageId: options.messageId } : {}),\n endpoint: await redactPushEndpoint(options.subscription.endpoint),\n provider: transport.provider ?? \"push\",\n };\n}\n\n/**\n * Create a push sender that wraps a {@link PushTransport}.\n *\n * Pipeline: plugins → onSend → transport.send → onSuccess / onError.\n */\nexport function createPushSender(config: PushSenderConfig): PushSender {\n const { transport, plugins, hooks } = config;\n\n return {\n async send(options: PushOptions): Promise<PushSendResult> {\n const processed = await runPlugins(options, plugins);\n const ctx = await buildPushHookContext(processed, transport);\n\n await invokeHook(hooks?.onSend, ctx);\n\n const start = performance.now();\n\n try {\n const result = await transport.send(processed);\n const successCtx: PushHookContext = {\n ...ctx,\n messageId: result.messageId,\n };\n await invokeHook(hooks?.onSuccess, successCtx, result, performance.now() - start);\n return result;\n } catch (error) {\n await invokeHook(hooks?.onError, ctx, error, performance.now() - start);\n throw error;\n }\n },\n\n async verify(): Promise<VerifyResult> {\n if (transport.verify) {\n return transport.verify();\n }\n return { ok: true, provider: \"push\" };\n },\n\n async close(): Promise<void> {\n if (transport.close) {\n await transport.close();\n }\n },\n };\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": "iKA4DA,SAAe,LAAoB,LACjC,EACA,EAC0B,CAC1B,MAAO,IACD,EAAQ,YAAc,OAAY,CAAE,UAAW,EAAQ,SAAU,EAAI,CAAC,EAC1E,SAAU,MAAM,EAAmB,EAAQ,aAAa,QAAQ,EAChE,SAAU,EAAU,UAAY,MAClC,EAQK,SAAS,CAAgB,CAAC,EAAsC,CACrE,IAAQ,YAAW,UAAS,SAAU,EAEtC,MAAO,MACC,KAAI,CAAC,EAA+C,CACxD,IAAM,EAAY,MAAM,EAAW,EAAS,CAAO,EAC7C,EAAM,MAAM,EAAqB,EAAW,CAAS,EAE3D,MAAM,EAAW,GAAO,OAAQ,CAAG,EAEnC,IAAM,EAAQ,YAAY,IAAI,EAE9B,GAAI,CACF,IAAM,EAAS,MAAM,EAAU,KAAK,CAAS,EACvC,EAA8B,IAC/B,EACH,UAAW,EAAO,SACpB,EAEA,OADA,MAAM,EAAW,GAAO,UAAW,EAAY,EAAQ,YAAY,IAAI,EAAI,CAAK,EACzE,EACP,MAAO,EAAO,CAEd,MADA,MAAM,EAAW,GAAO,QAAS,EAAK,EAAO,YAAY,IAAI,EAAI,CAAK,EAChE,SAIJ,OAAM,EAA0B,CACpC,GAAI,EAAU,OACZ,OAAO,EAAU,OAAO,EAE1B,MAAO,CAAE,GAAI,GAAM,SAAU,MAAO,QAGhC,MAAK,EAAkB,CAC3B,GAAI,EAAU,MACZ,MAAM,EAAU,MAAM,EAG5B",
|
|
8
|
+
"debugId": "EF4B8931029EC5E464756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
package/dist/sms.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { SmsHooks, SmsOptions, SmsPlugin, SmsSendResult, SmsTransport } from "./core/sms-types.js";
|
|
2
|
+
import type { VerifyResult } from "./core/types.js";
|
|
3
|
+
/** Configuration for {@link createSmsSender}. */
|
|
4
|
+
export interface SmsSenderConfig {
|
|
5
|
+
/** SMS delivery transport. */
|
|
6
|
+
transport: SmsTransport;
|
|
7
|
+
/** Optional plugins run before each send. */
|
|
8
|
+
plugins?: SmsPlugin[];
|
|
9
|
+
/** Optional lifecycle hooks for metrics and tracing. */
|
|
10
|
+
hooks?: SmsHooks;
|
|
11
|
+
}
|
|
12
|
+
/** SMS sender returned by {@link createSmsSender}. */
|
|
13
|
+
export interface SmsSender {
|
|
14
|
+
/** Send an SMS through the configured transport. */
|
|
15
|
+
send(options: SmsOptions): Promise<SmsSendResult>;
|
|
16
|
+
/** Test connectivity and credentials without sending. */
|
|
17
|
+
verify(): Promise<VerifyResult>;
|
|
18
|
+
/** Release resources held by the transport. */
|
|
19
|
+
close(): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Create an SMS sender that wraps an {@link SmsTransport}.
|
|
23
|
+
*
|
|
24
|
+
* Pipeline: plugins → onSend → transport.send → onSuccess / onError.
|
|
25
|
+
*/
|
|
26
|
+
export declare function createSmsSender(config: SmsSenderConfig): SmsSender;
|
package/dist/sms.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{W as A,X as I}from"./chunk-qtkd5bak.js";import"./chunk-6npp3x3c.js";function N(z,q){return{...z.messageId!==void 0?{messageId:z.messageId}:{},to:z.to,provider:q.provider??"sms"}}function R(z){let{transport:q,plugins:J,hooks:B}=z;return{async send(K){let F=await I(K,J),D=N(F,q);await A(B?.onSend,D);let G=performance.now();try{let y=await q.send(F),L={...D,messageId:y.messageId};return await A(B?.onSuccess,L,y,performance.now()-G),y}catch(y){throw await A(B?.onError,D,y,performance.now()-G),y}},async verify(){if(q.verify)return q.verify();return{ok:!0,provider:"sms"}},async close(){if(q.close)await q.close()}}}export{R as createSmsSender};
|
|
2
|
+
|
|
3
|
+
//# debugId=9AD22B10712186FC64756E2164756E21
|