@visulima/notification 1.0.8 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/channels/email/index.d.ts +23 -23
- package/dist/channels/email/index.js +1 -1
- package/dist/channels/inapp/index.d.ts +31 -31
- package/dist/digest/index.d.ts +55 -55
- package/dist/digest/index.js +1 -1
- package/dist/events/index.d.ts +16 -16
- package/dist/i18n/index.d.ts +21 -21
- package/dist/i18n/index.js +1 -1
- package/dist/index.d.ts +97 -108
- package/dist/index.js +1 -1
- package/dist/layouts/index.d.ts +28 -28
- package/dist/middleware/index.d.ts +49 -49
- package/dist/middleware/index.js +1 -1
- package/dist/packem_shared/{Notification-B22tuJPy.js → Notification-DH2mcFWI.js} +1 -1
- package/dist/packem_shared/NotificationError-B8CyoEaX.js +1 -0
- package/dist/packem_shared/{RequiredOptionError-CuL42XRq.js → RequiredOptionError-Bs282gKK.js} +1 -1
- package/dist/packem_shared/apnsProvider-BPH0pHvd.js +1 -0
- package/dist/packem_shared/{circuitBreakerMiddleware-BlZN7SVT.js → circuitBreakerMiddleware-CRBi0H7e.js} +1 -1
- package/dist/packem_shared/{createDigester-vMNPejGF.js → createDigester-DenmT8_X.js} +1 -1
- package/dist/packem_shared/{createNotificationWorkflow-B70OgeED.js → createNotificationWorkflow-5AY-ays0.js} +1 -1
- package/dist/packem_shared/{createTranslator-CY91C2eS.js → createTranslator-ByyvYNfG.js} +1 -1
- package/dist/packem_shared/{discordProvider-BhfXcCcI.js → discordProvider-BvKwrC8K.js} +1 -1
- package/dist/packem_shared/{emailChannel-CNDlX96Q.js → emailChannel-Cf8wZPZL.js} +1 -1
- package/dist/packem_shared/{expoProvider-DsZR4sUk.js → expoProvider-13gY7Ne8.js} +1 -1
- package/dist/packem_shared/{failoverProvider-D1dAmW8U.js → failoverProvider-DXcwmYev.js} +1 -1
- package/dist/packem_shared/{fcmProvider-DWRx8XBv.js → fcmProvider-DsGjzBzz.js} +1 -1
- package/dist/packem_shared/{messageBirdProvider-BfiTaNLn.js → messageBirdProvider-D1c3jUqj.js} +1 -1
- package/dist/packem_shared/{mockProvider-BLwTZlkw.js → mockProvider-DZ3immtm.js} +1 -1
- package/dist/packem_shared/{msTeamsProvider-DrmL3RYX.js → msTeamsProvider-Cd-BUhH1.js} +1 -1
- package/dist/packem_shared/notification.d-D0ado_cy.d.ts +104 -0
- package/dist/packem_shared/{plivoProvider-Dr8d5yD3.js → plivoProvider-C_koQ8X-.js} +1 -1
- package/dist/packem_shared/{provider.d-BQAGriz6.d.ts → provider.d-Dh32nRm9.d.ts} +10 -10
- package/dist/packem_shared/{roundRobinProvider-BetXJUUm.js → roundRobinProvider-CK3Vyc_u.js} +1 -1
- package/dist/packem_shared/{slackProvider-DPG1IlA0.js → slackProvider-B92QDf3e.js} +1 -1
- package/dist/packem_shared/{sms-CU-OZvNU.js → sms-64HGUCLu.js} +1 -1
- package/dist/packem_shared/{snsProvider-C2T2UxDK.js → snsProvider-CPGjOUP_.js} +1 -1
- package/dist/packem_shared/{telegramProvider-wyx3ksVm.js → telegramProvider-BmmroM5A.js} +1 -1
- package/dist/packem_shared/{telnyxProvider-jgpEwgPh.js → telnyxProvider-C41tE4VF.js} +1 -1
- package/dist/packem_shared/{tracer.d-Co1s_NwG.d.ts → tracer.d-BPznIQx9.d.ts} +2 -2
- package/dist/packem_shared/{twilioProvider-DMYWqvgZ.js → twilioProvider-DanDTzi3.js} +1 -1
- package/dist/packem_shared/{types.d-67TogK4k.d.ts → types.d--kw9ifOI.d.ts} +6 -6
- package/dist/packem_shared/types.d-BU-37j3S.d.ts +10 -0
- package/dist/packem_shared/{types.d-GUzX1jTk.d.ts → types.d-C7l7qdMG.d.ts} +52 -52
- package/dist/packem_shared/{types.d-CximoA8M.d.ts → types.d-CRs03TYV.d.ts} +13 -13
- package/dist/packem_shared/{types.d-C1GoEAlI.d-Bv3grfyD.d.ts → types.d-CcjfiGpo.d-DuZME7ry.d.ts} +27 -34
- package/dist/packem_shared/{vonageProvider-CT4KoWXu.js → vonageProvider-epeGBWW8.js} +1 -1
- package/dist/packem_shared/{webPushProvider-DwjmWASr.js → webPushProvider-K6-Drhaf.js} +1 -1
- package/dist/packem_shared/{webhookProvider-CPA1nKXJ.js → webhookProvider-DlwFyaGc.js} +1 -1
- package/dist/preferences/index.d.ts +19 -19
- package/dist/providers/chat/discord/index.d.ts +5 -5
- package/dist/providers/chat/discord/index.js +1 -1
- package/dist/providers/chat/msteams/index.d.ts +7 -7
- package/dist/providers/chat/msteams/index.js +1 -1
- package/dist/providers/chat/slack/index.d.ts +6 -6
- package/dist/providers/chat/slack/index.js +1 -1
- package/dist/providers/chat/telegram/index.d.ts +5 -5
- package/dist/providers/chat/telegram/index.js +1 -1
- package/dist/providers/failover/index.d.ts +7 -7
- package/dist/providers/failover/index.js +1 -1
- package/dist/providers/mock/index.d.ts +5 -5
- package/dist/providers/mock/index.js +1 -1
- package/dist/providers/opentelemetry/index.d.ts +14 -14
- package/dist/providers/push/apns/index.d.ts +9 -9
- package/dist/providers/push/apns/index.js +1 -1
- package/dist/providers/push/expo/index.d.ts +5 -5
- package/dist/providers/push/expo/index.js +1 -1
- package/dist/providers/push/fcm/index.d.ts +13 -13
- package/dist/providers/push/fcm/index.js +1 -1
- package/dist/providers/push/web-push/index.d.ts +11 -11
- package/dist/providers/push/web-push/index.js +1 -1
- package/dist/providers/roundrobin/index.d.ts +8 -8
- package/dist/providers/roundrobin/index.js +1 -1
- package/dist/providers/sms/messagebird/index.d.ts +5 -5
- package/dist/providers/sms/messagebird/index.js +1 -1
- package/dist/providers/sms/plivo/index.d.ts +5 -5
- package/dist/providers/sms/plivo/index.js +1 -1
- package/dist/providers/sms/sns/index.d.ts +6 -6
- package/dist/providers/sms/sns/index.js +1 -1
- package/dist/providers/sms/telnyx/index.d.ts +5 -5
- package/dist/providers/sms/telnyx/index.js +1 -1
- package/dist/providers/sms/twilio/index.d.ts +5 -5
- package/dist/providers/sms/twilio/index.js +1 -1
- package/dist/providers/sms/vonage/index.d.ts +5 -5
- package/dist/providers/sms/vonage/index.js +1 -1
- package/dist/providers/webhook/index.d.ts +7 -7
- package/dist/providers/webhook/index.js +1 -1
- package/dist/queue/bullmq-queue.d.ts +24 -24
- package/dist/queue/index.d.ts +15 -15
- package/dist/queue/pg-boss-queue.d.ts +26 -26
- package/dist/queue/sqs-queue.d.ts +27 -27
- package/dist/queue/unstorage-queue.d.ts +14 -14
- package/dist/routing/index.d.ts +22 -22
- package/dist/template-engines/handlebars.d.ts +13 -13
- package/dist/template-engines/handlebars.js +1 -1
- package/dist/template-engines/liquid.d.ts +13 -13
- package/dist/template-engines/liquid.js +1 -1
- package/dist/template-engines/string.d.ts +17 -17
- package/dist/utils/result.d.ts +32 -32
- package/dist/utils/result.js +1 -1
- package/dist/webhooks/index.d.ts +84 -84
- package/dist/workflow/index.d.ts +42 -42
- package/dist/workflow/index.js +1 -1
- package/package.json +2 -2
- package/dist/packem_shared/NotificationError-DVfMJQ1u.js +0 -1
- package/dist/packem_shared/apnsProvider-C9WSv5sc.js +0 -1
- package/dist/packem_shared/notification.d-DFCVTods.d.ts +0 -104
- package/dist/packem_shared/types.d-td-F2Oh0.d.ts +0 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
import c from"./NotificationError-
|
|
1
|
+
import c from"./NotificationError-B8CyoEaX.js";import d from"./RequiredOptionError-Bs282gKK.js";import{defineProvider as h}from"./defineProvider-C9q-7iwt.js";import{t as y}from"./credentials-CG0zkn-W.js";import{r as T}from"./http-DT3tyixg.js";const I=h(m=>{const e=m??{};if(!e.projectId)throw new d("fcm","projectId");if(!e.accessToken&&!e.getAccessToken)throw new d("fcm",["accessToken","getAccessToken"]);const i=e.endpoint??"https://fcm.googleapis.com",f=e.retries??3,u=e.timeout??3e4,p=`${i}/v1/projects/${e.projectId}/messages:send`,l=s=>{if(s)return Object.fromEntries(Object.entries(s).map(([r,o])=>[r,typeof o=="string"?o:JSON.stringify(o)]))},g=async(s,r,o)=>{const a={data:l(r.data),notification:{body:r.body,image:r.imageUrl,title:r.title},token:s},t=await T(p,{body:JSON.stringify({message:a}),headers:{Authorization:`Bearer ${o}`,"Content-Type":"application/json"},method:"POST",timeout:u},f);return!t.success||!t.data?{error:t.error instanceof Error?t.error.message:"Request failed",id:s,status:"failed"}:t.data.status>=400?{error:t.data.body.error?.message??`HTTP ${String(t.data.status)}`,id:s,status:"failed"}:{id:s,messageId:t.data.body.name,status:"sent"}};return{channel:"push",endpoint:i,features:{batchSending:!1,media:!0,richContent:!0},id:"fcm",initialize:()=>{},isAvailable:()=>!!(e.projectId&&(e.accessToken??e.getAccessToken)),options:e,send:async s=>{let r;try{r=e.getAccessToken?await e.getAccessToken():e.accessToken}catch(n){return{error:new c("fcm","Failed to obtain access token",{cause:n}),success:!1}}const o=y(s.to),a=[];for(const n of o)a.push(await g(n,s,r));const t=a.filter(n=>n.status==="sent");return t.length===0?{error:new c("fcm",a[0]?.error??"All tokens failed"),success:!1}:{data:{channel:"push",messageId:t[0]?.messageId??"",provider:"fcm",recipients:a,sent:!0,timestamp:new Date},success:!0}}}});export{I as default};
|
package/dist/packem_shared/{messageBirdProvider-BfiTaNLn.js → messageBirdProvider-D1c3jUqj.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import t from"./NotificationError-
|
|
1
|
+
import t from"./NotificationError-B8CyoEaX.js";import g from"./RequiredOptionError-Bs282gKK.js";import{defineProvider as l}from"./defineProvider-C9q-7iwt.js";import{t as y}from"./credentials-CG0zkn-W.js";import{r as b}from"./http-DT3tyixg.js";import{b as h}from"./sms-64HGUCLu.js";const v="https://rest.messagebird.com",$=l(n=>{const e=n??{};if(!e.accessKey)throw new g("messagebird","accessKey");const i=e.endpoint??v,d=e.retries??3,c=e.timeout??3e4,m=`${i}/messages`;return{channel:"sms",endpoint:i,features:{batchSending:!0,deliveryReceipts:!0,media:!1},id:"messagebird",initialize:()=>{},isAvailable:()=>!!e.accessKey,options:e,send:async r=>{const a=y(r.to),o=r.from??e.from;if(!o)return{error:new t("messagebird","Missing originator: provide `from` on the payload or provider config"),success:!1};const s=await b(m,{body:JSON.stringify({body:r.text,originator:o,recipients:a}),headers:{Authorization:`AccessKey ${e.accessKey}`,"Content-Type":"application/json"},method:"POST",timeout:c},d);if(!s.success||!s.data)return{error:new t("messagebird",s.error instanceof Error?s.error.message:"Request failed"),success:!1};if(s.data.status>=400)return{error:new t("messagebird",s.data.body.errors?.[0]?.description??`HTTP ${String(s.data.status)}`),success:!1};const f=s.data.body.id??"",p=a.map(u=>({id:u,messageId:f,status:"sent"}));return h("messagebird",p)},validateCredentials:()=>!!e.accessKey}});export{$ as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import c from"./NotificationError-
|
|
1
|
+
import c from"./NotificationError-B8CyoEaX.js";import{defineProvider as d}from"./defineProvider-C9q-7iwt.js";let n=0;const p=d((e={})=>{const t=[],s=e.channel??"sms",r=e.id??"mock",o={clear:()=>{t.length=0},last:()=>t.at(-1),sent:t};return{channel:s,getInstance:()=>o,id:r,initialize:()=>{},isAvailable:()=>!0,send:l=>{if(e.failWith!==void 0)return{error:new c(r,e.failWith),success:!1};n+=1;const a=new Date,i=`mock-${String(n)}`;return t.push({messageId:i,payload:l,timestamp:a}),{data:{channel:s,messageId:i,provider:r,sent:!0,timestamp:a},success:!0}},validateCredentials:()=>!0}});export{p as mockProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import r from"./NotificationError-
|
|
1
|
+
import r from"./NotificationError-B8CyoEaX.js";import m from"./RequiredOptionError-Bs282gKK.js";import{defineProvider as c}from"./defineProvider-C9q-7iwt.js";import{r as d}from"./http-DT3tyixg.js";import{n as l}from"./id-C_FRCsUM.js";const b=c(a=>{const e=a??{};if(!e.webhookUrl)throw new m("msteams","webhookUrl");const o=e.retries??3,n=e.timeout??3e4;return{channel:"chat",endpoint:e.webhookUrl,features:{batchSending:!1,richContent:!0},id:"msteams",initialize:()=>{},isAvailable:()=>!!e.webhookUrl,options:e,send:async s=>{const i=s.blocks??{"@context":"https://schema.org/extensions","@type":"MessageCard",text:s.text},t=await d(e.webhookUrl,{body:JSON.stringify(i),headers:{"Content-Type":"application/json"},method:"POST",timeout:n},o);return!t.success||!t.data?{error:new r("msteams",t.error instanceof Error?t.error.message:"Request failed"),success:!1}:t.data.status>=400?{error:new r("msteams",`HTTP ${String(t.data.status)}: ${t.data.body}`),success:!1}:{data:{channel:"chat",messageId:l("msteams"),provider:"msteams",sent:!0,timestamp:new Date},success:!0}},validateCredentials:()=>!!e.webhookUrl}});export{b as default};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { M as Middleware } from "./types.d-CRs03TYV.js";
|
|
2
|
+
import { P as Provider } from "./provider.d-Dh32nRm9.js";
|
|
3
|
+
import { b as ChatPayload, E as EmailChannelPayload, I as InAppPayload, P as PushPayload, S as SmsPayload, W as WebhookPayload, C as ChannelType, c as Receipt } from "./types.d-C7l7qdMG.js";
|
|
4
|
+
/**
|
|
5
|
+
* Maps each channel to its payload type.
|
|
6
|
+
*/
|
|
7
|
+
interface ChannelPayloadMap {
|
|
8
|
+
chat: ChatPayload;
|
|
9
|
+
email: EmailChannelPayload;
|
|
10
|
+
inapp: InAppPayload;
|
|
11
|
+
push: PushPayload;
|
|
12
|
+
sms: SmsPayload;
|
|
13
|
+
webhook: WebhookPayload;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A multi-channel message: a payload per channel to deliver on.
|
|
17
|
+
*/
|
|
18
|
+
type NotificationMessage = { [K in ChannelType]?: ChannelPayloadMap[K]; };
|
|
19
|
+
/**
|
|
20
|
+
* Providers registered per channel.
|
|
21
|
+
*/
|
|
22
|
+
type NotificationProviders = { [K in ChannelType]?: Provider<unknown, ChannelPayloadMap[K]>; };
|
|
23
|
+
interface SendManyOptions {
|
|
24
|
+
/** Maximum number of messages delivered concurrently (default 10). */
|
|
25
|
+
concurrency?: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The high-level multi-channel notification facade. Holds a provider per channel,
|
|
29
|
+
* a shared middleware chain and dispatches messages across channels.
|
|
30
|
+
*/
|
|
31
|
+
declare class Notification {
|
|
32
|
+
#private;
|
|
33
|
+
constructor(providers: NotificationProviders);
|
|
34
|
+
/**
|
|
35
|
+
* Registers a middleware. First registered runs outermost.
|
|
36
|
+
* @param middleware The middleware to add.
|
|
37
|
+
* @returns This instance for chaining.
|
|
38
|
+
*/
|
|
39
|
+
use(middleware: Middleware): this;
|
|
40
|
+
/**
|
|
41
|
+
* Sets a logger used by the facade.
|
|
42
|
+
* @param logger The console-like logger.
|
|
43
|
+
* @returns This instance for chaining.
|
|
44
|
+
*/
|
|
45
|
+
setLogger(logger: Console): this;
|
|
46
|
+
/**
|
|
47
|
+
* Returns the provider registered for a channel, if any.
|
|
48
|
+
* @param channel The channel whose registered provider should be looked up.
|
|
49
|
+
* @returns The provider or undefined.
|
|
50
|
+
*/
|
|
51
|
+
getProvider(channel: ChannelType): Provider | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Sends a payload on a single channel.
|
|
54
|
+
* @param channel The target channel.
|
|
55
|
+
* @param payload The channel-specific payload to deliver.
|
|
56
|
+
* @returns A receipt describing the outcome.
|
|
57
|
+
*/
|
|
58
|
+
sendToChannel<K extends ChannelType>(channel: K, payload: ChannelPayloadMap[K]): Promise<Receipt>;
|
|
59
|
+
/**
|
|
60
|
+
* Sends a multi-channel message, delivering each present channel in parallel.
|
|
61
|
+
* @param message The multi-channel message.
|
|
62
|
+
* @returns One receipt per attempted channel.
|
|
63
|
+
*/
|
|
64
|
+
send(message: NotificationMessage): Promise<Receipt[]>;
|
|
65
|
+
/**
|
|
66
|
+
* Sends many messages with bounded concurrency, yielding the receipts for each.
|
|
67
|
+
* @param messages The messages to send.
|
|
68
|
+
* @param options Concurrency options.
|
|
69
|
+
* @yields The receipts for each message, in completion order.
|
|
70
|
+
*/
|
|
71
|
+
sendMany(messages: Iterable<NotificationMessage>, options?: SendManyOptions): AsyncGenerator<Receipt[]>;
|
|
72
|
+
/**
|
|
73
|
+
* Initializes every registered provider.
|
|
74
|
+
*/
|
|
75
|
+
initialize(): Promise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* Shuts down every registered provider that supports it.
|
|
78
|
+
*/
|
|
79
|
+
shutdown(): Promise<void>;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Creates a {@link Notification} facade from a map of channel providers.
|
|
83
|
+
* @param providers Providers keyed by channel.
|
|
84
|
+
* @returns A configured notification facade.
|
|
85
|
+
*/
|
|
86
|
+
declare const createNotification: (providers: NotificationProviders) => Notification;
|
|
87
|
+
/**
|
|
88
|
+
* One-shot send through a single provider — the quickest path for a single-channel
|
|
89
|
+
* send without wiring a {@link Notification} facade. For multiple channels,
|
|
90
|
+
* middleware, routing or reuse, use {@link createNotification}.
|
|
91
|
+
* @param channel The channel to deliver on.
|
|
92
|
+
* @param provider The provider to deliver through.
|
|
93
|
+
* @param payload The channel-specific payload.
|
|
94
|
+
* @returns The send {@link Receipt}.
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* import { send } from "@visulima/notification";
|
|
98
|
+
* import { twilioProvider } from "@visulima/notification/providers/twilio";
|
|
99
|
+
*
|
|
100
|
+
* await send("sms", twilioProvider({ accountSid, authToken, from }), { to: "+15555550100", text: "Hi" });
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
declare const send: <ChannelT extends ChannelType>(channel: ChannelT, provider: Provider<unknown, ChannelPayloadMap[ChannelT]>, payload: ChannelPayloadMap[ChannelT]) => Promise<Receipt>;
|
|
104
|
+
export { ChannelPayloadMap as C, Notification as N, SendManyOptions as S, NotificationMessage as a, NotificationProviders as b, createNotification as c, send as s };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import o from"./NotificationError-
|
|
1
|
+
import o from"./NotificationError-B8CyoEaX.js";import d from"./RequiredOptionError-Bs282gKK.js";import{defineProvider as w}from"./defineProvider-C9q-7iwt.js";import{b as y,t as T}from"./credentials-CG0zkn-W.js";import{r as b}from"./http-DT3tyixg.js";import{b as I}from"./sms-64HGUCLu.js";const S="https://api.plivo.com",q=w(p=>{const e=p??{};if(!e.authId)throw new d("plivo","authId");if(!e.authToken)throw new d("plivo","authToken");const a=e.endpoint??S,m=e.retries??3,c=e.timeout??3e4,f=`${a}/v1/Account/${e.authId}/Message/`,l=y(e.authId,e.authToken);return{channel:"sms",endpoint:a,features:{batchSending:!0,deliveryReceipts:!0,media:!0},id:"plivo",initialize:()=>{},isAvailable:()=>!!(e.authId&&e.authToken),options:e,send:async s=>{const r=T(s.to),i=s.from??e.from;if(!i)return{error:new o("plivo","Missing sender: provide `from` on the payload or provider config"),success:!1};const t=await b(f,{body:JSON.stringify({dst:r.join("<"),src:i,text:s.text}),headers:{Authorization:l,"Content-Type":"application/json"},method:"POST",timeout:c},m);if(!t.success||!t.data)return{error:new o("plivo",t.error instanceof Error?t.error.message:"Request failed"),success:!1};if(t.data.status>=400)return{error:new o("plivo",t.data.body.error??`HTTP ${String(t.data.status)}`),success:!1};const{body:n}=t.data,h=n.message_uuid?.[0]??"",u=r.map((v,g)=>({id:v,messageId:n.message_uuid?.[g],status:"sent"}));return I("plivo",u.length>0?u:[{id:r[0]??"",messageId:h,status:"sent"}])},validateCredentials:()=>!!(e.authId&&e.authToken)}});export{q as default};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { B as BaseNotificationPayload, C as ChannelType, F as FeatureFlags, M as MaybePromise, N as NotificationEvent, a as NotificationResult, R as Result } from "./types.d-
|
|
1
|
+
import { B as BaseNotificationPayload, C as ChannelType, F as FeatureFlags, M as MaybePromise, N as NotificationEvent, a as NotificationResult, R as Result } from "./types.d-C7l7qdMG.js";
|
|
2
2
|
/**
|
|
3
|
-
* Standard provider interface for notification channels. Every provider belongs to
|
|
4
|
-
* exactly one {@link ChannelType} and accepts a channel-specific payload.
|
|
5
|
-
*/
|
|
3
|
+
* Standard provider interface for notification channels. Every provider belongs to
|
|
4
|
+
* exactly one {@link ChannelType} and accepts a channel-specific payload.
|
|
5
|
+
*/
|
|
6
6
|
interface Provider<OptionsT = unknown, PayloadT extends BaseNotificationPayload = BaseNotificationPayload, InstanceT = unknown> {
|
|
7
7
|
/** The channel this provider delivers on. */
|
|
8
8
|
readonly channel: ChannelType;
|
|
@@ -21,13 +21,13 @@ interface Provider<OptionsT = unknown, PayloadT extends BaseNotificationPayload
|
|
|
21
21
|
validateCredentials?: () => MaybePromise<boolean>;
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
|
-
* Type for a provider factory function.
|
|
25
|
-
*/
|
|
24
|
+
* Type for a provider factory function.
|
|
25
|
+
*/
|
|
26
26
|
type ProviderFactory<OptionsT = unknown, PayloadT extends BaseNotificationPayload = BaseNotificationPayload, InstanceT = unknown> = (options?: OptionsT) => Provider<OptionsT, PayloadT, InstanceT>;
|
|
27
27
|
/**
|
|
28
|
-
* Helper to define a notification provider (identity function for type inference).
|
|
29
|
-
* @param factory The provider factory function.
|
|
30
|
-
* @returns The same factory function.
|
|
31
|
-
*/
|
|
28
|
+
* Helper to define a notification provider (identity function for type inference).
|
|
29
|
+
* @param factory The provider factory function.
|
|
30
|
+
* @returns The same factory function.
|
|
31
|
+
*/
|
|
32
32
|
declare const defineProvider: <OptionsT = unknown, PayloadT extends BaseNotificationPayload = BaseNotificationPayload, InstanceT = unknown>(factory: ProviderFactory<OptionsT, PayloadT, InstanceT>) => ProviderFactory<OptionsT, PayloadT, InstanceT>;
|
|
33
33
|
export { Provider as P, ProviderFactory as a, defineProvider as d };
|
package/dist/packem_shared/{roundRobinProvider-BetXJUUm.js → roundRobinProvider-CK3Vyc_u.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import c from"./NotificationError-
|
|
1
|
+
import c from"./NotificationError-B8CyoEaX.js";const g=(e,a={})=>{if(e.length===0)throw new c("roundrobin","At least one provider is required");const t=a.id??"roundrobin",d=a.failover??!0,u=e[0];let i=0;return{channel:u.channel,id:t,initialize:async()=>{await Promise.all(e.map(async r=>r.initialize()))},isAvailable:async()=>(await Promise.all(e.map(async r=>r.isAvailable()))).some(Boolean),send:async r=>{const f=i;i=(i+1)%e.length;const o=[],h=d?e.length:1;for(let s=0;s<h;s+=1){const l=e[(f+s)%e.length],n=await l.send(r);if(n.success)return n;o.push(`${l.id}: ${n.error instanceof Error?n.error.message:String(n.error)}`)}return{error:new c(t,`Send failed: ${o.join("; ")}`),success:!1}}}};export{g as roundRobinProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import r from"./NotificationError-
|
|
1
|
+
import r from"./NotificationError-B8CyoEaX.js";import{defineProvider as b}from"./defineProvider-C9q-7iwt.js";import{r as m}from"./http-DT3tyixg.js";import{n as d}from"./id-C_FRCsUM.js";const w="https://slack.com/api",S=b(h=>{const e=h??{};if(!e.token&&!e.webhookUrl)throw new r("slack","Provide either `token` (Web API) or `webhookUrl`",{hint:"Set one of token/webhookUrl in the provider config"});const n=e.endpoint??w,k=e.retries??3,u=e.timeout??3e4;return{channel:"chat",endpoint:n,features:{batchSending:!1,richContent:!0},id:"slack",initialize:()=>{},isAvailable:()=>!!(e.token??e.webhookUrl),options:e,send:async s=>{const o=!!e.webhookUrl,f=o?e.webhookUrl:`${n}/chat.postMessage`,i=s.to??e.defaultChannel;if(!o&&!i)return{error:new r("slack","Missing channel: provide `to` or `defaultChannel`"),success:!1};const c={blocks:s.blocks,text:s.text,thread_ts:s.threadId};o||(c.channel=i);const l={"Content-Type":"application/json"};o||(l.Authorization=`Bearer ${e.token??""}`);const t=await m(f,{body:JSON.stringify(c),headers:l,method:"POST",timeout:u},k);if(!t.success||!t.data)return{error:new r("slack",t.error instanceof Error?t.error.message:"Request failed"),success:!1};if(o){if(t.data.status>=400||t.data.body!=="ok"){const p=typeof t.data.body=="string"?t.data.body:JSON.stringify(t.data.body);return{error:new r("slack",`Webhook failed: ${p}`),success:!1}}return{data:{channel:"chat",messageId:d("slack"),provider:"slack",sent:!0,timestamp:new Date},success:!0}}const a=t.data.body;return a.ok?{data:{channel:"chat",messageId:a.ts??d("slack"),provider:"slack",response:a,sent:!0,timestamp:new Date},success:!0}:{error:new r("slack",a.error??"Slack API error"),success:!1}},validateCredentials:()=>!!(e.token??e.webhookUrl)}});export{S as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import n from"./NotificationError-
|
|
1
|
+
import n from"./NotificationError-B8CyoEaX.js";const i=(t,e,s)=>{const r=s.filter(a=>a.status==="sent");return r.length===0?{error:new n(e,s[0]?.error??"All recipients failed"),success:!1}:{data:{channel:t,messageId:r[0]?.messageId??"",provider:e,recipients:s,sent:!0,timestamp:new Date},success:!0}},o=(t,e)=>i("sms",t,e),u=async(t,e)=>{const s=[];for(const r of t)s.push(await e(r));return s};export{i as a,o as b,u as s};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import x from"./RequiredOptionError-
|
|
1
|
+
import x from"./RequiredOptionError-Bs282gKK.js";import{defineProvider as K}from"./defineProvider-C9q-7iwt.js";import{t as z}from"./credentials-CG0zkn-W.js";import{r as C}from"./http-DT3tyixg.js";import{n as R}from"./id-C_FRCsUM.js";import{s as j,b as P}from"./sms-64HGUCLu.js";import{b as w,d as h,u as c,e as p}from"./webcrypto-bY7wJCB5.js";const b="sns",T="us-east-1",H=/<Message>([\s\S]*?)<\/Message>/,q=/<MessageId>([\s\S]*?)<\/MessageId>/,D=t=>{const e=t.toISOString().replaceAll(/[:-]|\.\d{3}/g,"");return{amzDate:e,dateStamp:e.slice(0,8)}},O=async(t,e,o)=>{const i=await p(c(`AWS4${t}`),c(e)),m=await p(i,c(o)),d=await p(m,c(b));return p(d,c("aws4_request"))},k=t=>{const{pathname:e}=new URL(t);return e===""||e==="/"?"/":e.split("/").map(o=>encodeURIComponent(o).replaceAll("*","%2A").replaceAll("'","%27").replaceAll("(","%28").replaceAll(")","%29").replaceAll("!","%21")).join("/")},L=async(t,e,o,i,m)=>{const{amzDate:d,dateStamp:S}=D(new Date),f=w(await h(c(m))),a={"Content-Type":"application/x-www-form-urlencoded",host:o,"x-amz-content-sha256":f,"x-amz-date":d};t.sessionToken&&(a["x-amz-security-token"]=t.sessionToken);const n={};for(const[l,g]of Object.entries(a))n[l.toLowerCase()]=g.trim();const s=Object.keys(n).toSorted((l,g)=>l.localeCompare(g)),u=s.join(";"),y=s.map(l=>`${l}:${n[l]??""}
|
|
2
2
|
`).join(""),r=["POST",k(i),"",y,u,f].join(`
|
|
3
3
|
`),A=`${S}/${e}/${b}/aws4_request`,$=["AWS4-HMAC-SHA256",d,A,w(await h(c(r)))].join(`
|
|
4
4
|
`),I=await O(t.secretAccessKey,S,e),M=w(await p(I,c($)));return a.Authorization=`AWS4-HMAC-SHA256 Credential=${t.accessKeyId}/${A}, SignedHeaders=${u}, Signature=${M}`,{headers:a,url:i}},B=K(t=>{const e=t??{};if(!e.accessKeyId||!e.secretAccessKey)throw new x("sns",["accessKeyId","secretAccessKey"]);const o=e.region??T,i=e.endpoint??`https://sns.${o}.amazonaws.com/`,{host:m}=new URL(i),d=e.retries??3,S=e.timeout??3e4,f=async(a,n)=>{const s=new URLSearchParams;s.set("Action","Publish"),s.set("Version","2010-03-31"),s.set("PhoneNumber",a),s.set("Message",n.text),n.from&&(s.set("MessageAttributes.entry.1.Name","AWS.SNS.SMS.SenderID"),s.set("MessageAttributes.entry.1.Value.DataType","String"),s.set("MessageAttributes.entry.1.Value.StringValue",n.from));const u=s.toString(),y=await L(e,o,m,i,u),r=await C(y.url,{body:u,headers:y.headers,method:"POST",timeout:S},d);if(!r.success||!r.data)return{error:r.error instanceof Error?r.error.message:"Request failed",id:a,status:"failed"};if(r.data.status>=400)return{error:H.exec(r.data.body)?.[1]??`HTTP ${String(r.data.status)}`,id:a,status:"failed"};const A=q.exec(r.data.body)?.[1];return{id:a,messageId:A??R("sns"),status:"sent"}};return{channel:"sms",endpoint:i,features:{batchSending:!1,deliveryReceipts:!1,media:!1,scheduling:!1},id:"sns",initialize:()=>{},isAvailable:()=>!!(e.accessKeyId&&e.secretAccessKey),options:e,send:async a=>{const n=await j(z(a.to),async s=>f(s,a));return P("sns",n)},validateCredentials:()=>!!(e.accessKeyId&&e.secretAccessKey)}});export{B as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import r from"./NotificationError-
|
|
1
|
+
import r from"./NotificationError-B8CyoEaX.js";import m from"./RequiredOptionError-Bs282gKK.js";import{defineProvider as p}from"./defineProvider-C9q-7iwt.js";import{r as u}from"./http-DT3tyixg.js";const f="https://api.telegram.org",T=p(i=>{const e=i??{};if(!e.botToken)throw new m("telegram","botToken");const o=e.endpoint??f,d=e.retries??3,c=e.timeout??3e4,l=`${o}/bot${e.botToken}/sendMessage`;return{channel:"chat",endpoint:o,features:{batchSending:!1,richContent:!0},id:"telegram",initialize:()=>{},isAvailable:()=>!!e.botToken,options:e,send:async a=>{const s=a.to??e.defaultChatId;if(s===void 0)return{error:new r("telegram","Missing chat id: provide `to` or `defaultChatId`"),success:!1};const n={chat_id:s,text:a.text};e.parseMode&&(n.parse_mode=e.parseMode);const t=await u(l,{body:JSON.stringify(n),headers:{"Content-Type":"application/json"},method:"POST",timeout:c},d);return!t.success||!t.data?{error:new r("telegram",t.error instanceof Error?t.error.message:"Request failed"),success:!1}:t.data.body.ok?{data:{channel:"chat",messageId:String(t.data.body.result?.message_id??""),provider:"telegram",response:t.data.body,sent:!0,timestamp:new Date},success:!0}:{error:new r("telegram",t.data.body.description??`HTTP ${String(t.data.status)}`),success:!1}},validateCredentials:()=>!!e.botToken}});export{T as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import u from"./RequiredOptionError-
|
|
1
|
+
import u from"./RequiredOptionError-Bs282gKK.js";import{defineProvider as p}from"./defineProvider-C9q-7iwt.js";import{t as g}from"./credentials-CG0zkn-W.js";import{r as c}from"./http-DT3tyixg.js";import{s as y,b as h}from"./sms-64HGUCLu.js";const x="https://api.telnyx.com",I=p(n=>{const e=n??{};if(!e.apiKey)throw new u("telnyx","apiKey");const o=e.endpoint??x,d=e.retries??3,m=e.timeout??3e4,l=`${o}/v2/messages`,f=async(t,s)=>{const i=s.from??e.from;if(!i&&!e.messagingProfileId)return{error:"Missing sender: provide `from`, provider `from`, or `messagingProfileId`",id:t,status:"failed"};const a={text:s.text,to:t};i&&(a.from=i),e.messagingProfileId&&(a.messaging_profile_id=e.messagingProfileId),s.mediaUrls&&s.mediaUrls.length>0&&(a.media_urls=s.mediaUrls);const r=await c(l,{body:JSON.stringify(a),headers:{Authorization:`Bearer ${e.apiKey}`,"Content-Type":"application/json"},method:"POST",timeout:m},d);return!r.success||!r.data?{error:r.error instanceof Error?r.error.message:"Request failed",id:t,status:"failed"}:r.data.status>=400?{error:r.data.body.errors?.[0]?.detail??`HTTP ${String(r.data.status)}`,id:t,status:"failed"}:{id:t,messageId:r.data.body.data?.id,status:"sent"}};return{channel:"sms",endpoint:o,features:{batchSending:!1,deliveryReceipts:!0,media:!0,scheduling:!0},id:"telnyx",initialize:()=>{},isAvailable:()=>!!e.apiKey,options:e,send:async t=>{const s=await y(g(t.to),async i=>f(i,t));return h("telnyx",s)},validateCredentials:()=>!!e.apiKey}});export{I as default};
|
|
@@ -221,7 +221,7 @@ declare enum SpanStatusCode {
|
|
|
221
221
|
/**
|
|
222
222
|
* The operation contains an error.
|
|
223
223
|
*/
|
|
224
|
-
ERROR = 2
|
|
224
|
+
ERROR = 2
|
|
225
225
|
}
|
|
226
226
|
/**
|
|
227
227
|
* A pointer from the current {@link Span} to another span in the same trace or
|
|
@@ -400,7 +400,7 @@ declare enum SpanKind {
|
|
|
400
400
|
* broker. Unlike client and server, there is no direct critical path latency
|
|
401
401
|
* relationship between producer and consumer spans.
|
|
402
402
|
*/
|
|
403
|
-
CONSUMER = 4
|
|
403
|
+
CONSUMER = 4
|
|
404
404
|
}
|
|
405
405
|
/**
|
|
406
406
|
* Options needed for span creation
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import n from"./RequiredOptionError-
|
|
1
|
+
import n from"./RequiredOptionError-Bs282gKK.js";import{defineProvider as g}from"./defineProvider-C9q-7iwt.js";import{b as S,t as h}from"./credentials-CG0zkn-W.js";import{r as w}from"./http-DT3tyixg.js";import{s as y,b as T}from"./sms-64HGUCLu.js";const v="https://api.twilio.com",M=g(d=>{const e=d??{};if(!e.accountSid)throw new n("twilio","accountSid");if(!e.authToken)throw new n("twilio","authToken");const a=e.endpoint??v,c=e.retries??3,u=e.timeout??3e4,m=`${a}/2010-04-01/Accounts/${e.accountSid}/Messages.json`,l=S(e.accountSid,e.authToken),f=async(t,o)=>{const i=new URLSearchParams;i.set("To",t),i.set("Body",o.text);const r=o.from??e.from;if(e.messagingServiceSid)i.set("MessagingServiceSid",e.messagingServiceSid);else if(r)i.set("From",r);else return{error:"Missing sender: provide `from` on the payload or provider config",id:t,status:"failed"};for(const p of o.mediaUrls??[])i.append("MediaUrl",p);const s=await w(m,{body:i.toString(),headers:{Authorization:l,"Content-Type":"application/x-www-form-urlencoded"},method:"POST",timeout:u},c);return!s.success||!s.data?{error:s.error instanceof Error?s.error.message:"Request failed",id:t,status:"failed"}:s.data.status>=400?{error:s.data.body.error_message??`HTTP ${String(s.data.status)}`,id:t,status:"failed"}:{id:t,messageId:s.data.body.sid,status:"sent"}};return{channel:"sms",endpoint:a,features:{batchSending:!1,deliveryReceipts:!0,media:!0,scheduling:!0},id:"twilio",initialize:()=>{},isAvailable:()=>!!(e.accountSid&&e.authToken),options:e,send:async t=>{const o=await y(h(t.to),async i=>f(i,t));return T("twilio",o)},validateCredentials:()=>!!(e.accountSid&&e.authToken)}});export{M as default};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { a as NotificationMessage } from "./notification.d-
|
|
1
|
+
import { a as NotificationMessage } from "./notification.d-D0ado_cy.js";
|
|
2
2
|
/**
|
|
3
|
-
* A queued notification job.
|
|
4
|
-
*/
|
|
3
|
+
* A queued notification job.
|
|
4
|
+
*/
|
|
5
5
|
interface QueueJob {
|
|
6
6
|
/** Number of delivery attempts so far. */
|
|
7
7
|
attempts: number;
|
|
@@ -13,9 +13,9 @@ interface QueueJob {
|
|
|
13
13
|
scheduledAt?: number;
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
|
-
* A durable notification queue. The default {@link import("./memory-queue").MemoryQueue}
|
|
17
|
-
* is in-process; adapters (unstorage, BullMQ, ...) back it with external stores.
|
|
18
|
-
*/
|
|
16
|
+
* A durable notification queue. The default {@link import("./memory-queue").MemoryQueue}
|
|
17
|
+
* is in-process; adapters (unstorage, BullMQ, ...) back it with external stores.
|
|
18
|
+
*/
|
|
19
19
|
interface NotificationQueue {
|
|
20
20
|
/** Acknowledges a reserved job as completed, removing it. */
|
|
21
21
|
ack: (id: string) => Promise<void> | void;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Template render function type. Engines accept a template, optional data and
|
|
3
|
+
* engine-specific options and return the rendered string (sync or async).
|
|
4
|
+
* @param template Template content (typically a string).
|
|
5
|
+
* @param data Data/variables to pass to the template.
|
|
6
|
+
* @param options Options specific to the template engine.
|
|
7
|
+
* @returns The rendered string.
|
|
8
|
+
*/
|
|
9
|
+
type TemplateRenderer = (template: unknown, data?: Record<string, unknown>, options?: Record<string, unknown>) => string | Promise<string>;
|
|
10
|
+
export { TemplateRenderer as T };
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
type EmailRecipients = EmailAddressLike | string | (EmailAddressLike | string)[];
|
|
2
2
|
/**
|
|
3
|
-
* Utility type for values that can be promises.
|
|
4
|
-
*/
|
|
3
|
+
* Utility type for values that can be promises.
|
|
4
|
+
*/
|
|
5
5
|
type MaybePromise<T> = T | Promise<T>;
|
|
6
6
|
/**
|
|
7
|
-
* The logical delivery channels a notification can be routed through.
|
|
8
|
-
*/
|
|
7
|
+
* The logical delivery channels a notification can be routed through.
|
|
8
|
+
*/
|
|
9
9
|
type ChannelType = "chat" | "email" | "inapp" | "push" | "sms" | "webhook";
|
|
10
10
|
/**
|
|
11
|
-
* Feature flags indicating what capabilities a provider supports. Used to gate
|
|
12
|
-
* payloads before sending (see `checkFeatureSupport`) and to surface capabilities
|
|
13
|
-
* to consumers.
|
|
14
|
-
*/
|
|
11
|
+
* Feature flags indicating what capabilities a provider supports. Used to gate
|
|
12
|
+
* payloads before sending (see `checkFeatureSupport`) and to surface capabilities
|
|
13
|
+
* to consumers.
|
|
14
|
+
*/
|
|
15
15
|
interface FeatureFlags {
|
|
16
16
|
/** Supports file/media attachments (MMS, rich push images). */
|
|
17
17
|
attachments?: boolean;
|
|
@@ -31,8 +31,8 @@ interface FeatureFlags {
|
|
|
31
31
|
tracking?: boolean;
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
|
-
* Base configuration shared by every provider.
|
|
35
|
-
*/
|
|
34
|
+
* Base configuration shared by every provider.
|
|
35
|
+
*/
|
|
36
36
|
interface BaseConfig {
|
|
37
37
|
debug?: boolean;
|
|
38
38
|
logger?: Console;
|
|
@@ -40,26 +40,26 @@ interface BaseConfig {
|
|
|
40
40
|
timeout?: number;
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
|
-
* Fields common to every channel payload.
|
|
44
|
-
*/
|
|
43
|
+
* Fields common to every channel payload.
|
|
44
|
+
*/
|
|
45
45
|
interface BaseNotificationPayload {
|
|
46
46
|
/**
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
* Idempotency key to dedupe retried sends at the provider (where supported)
|
|
48
|
+
* and in the dedupe middleware.
|
|
49
|
+
*/
|
|
50
50
|
idempotencyKey?: string;
|
|
51
51
|
/**
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
* Arbitrary metadata passed through to the provider and emitted on events.
|
|
53
|
+
*/
|
|
54
54
|
metadata?: Record<string, unknown>;
|
|
55
55
|
/**
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
* Optional scheduled send time (providers advertising `scheduling`).
|
|
57
|
+
*/
|
|
58
58
|
scheduledAt?: Date | string;
|
|
59
59
|
}
|
|
60
60
|
/**
|
|
61
|
-
* SMS / MMS payload.
|
|
62
|
-
*/
|
|
61
|
+
* SMS / MMS payload.
|
|
62
|
+
*/
|
|
63
63
|
interface SmsPayload extends BaseNotificationPayload {
|
|
64
64
|
/** Sender id or phone number (overrides provider default). */
|
|
65
65
|
from?: string;
|
|
@@ -71,8 +71,8 @@ interface SmsPayload extends BaseNotificationPayload {
|
|
|
71
71
|
to: string | string[];
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
74
|
-
* Push notification payload (mobile + web push).
|
|
75
|
-
*/
|
|
74
|
+
* Push notification payload (mobile + web push).
|
|
75
|
+
*/
|
|
76
76
|
interface PushPayload extends BaseNotificationPayload {
|
|
77
77
|
/** Badge count (iOS). */
|
|
78
78
|
badge?: number;
|
|
@@ -92,8 +92,8 @@ interface PushPayload extends BaseNotificationPayload {
|
|
|
92
92
|
to: string | string[];
|
|
93
93
|
}
|
|
94
94
|
/**
|
|
95
|
-
* Chat payload (Slack, Discord, Teams, Telegram, ...).
|
|
96
|
-
*/
|
|
95
|
+
* Chat payload (Slack, Discord, Teams, Telegram, ...).
|
|
96
|
+
*/
|
|
97
97
|
interface ChatPayload extends BaseNotificationPayload {
|
|
98
98
|
/** Provider-specific rich content (Slack blocks, Discord embeds, ...). */
|
|
99
99
|
blocks?: unknown;
|
|
@@ -105,8 +105,8 @@ interface ChatPayload extends BaseNotificationPayload {
|
|
|
105
105
|
to?: string;
|
|
106
106
|
}
|
|
107
107
|
/**
|
|
108
|
-
* In-app inbox payload.
|
|
109
|
-
*/
|
|
108
|
+
* In-app inbox payload.
|
|
109
|
+
*/
|
|
110
110
|
interface InAppPayload extends BaseNotificationPayload {
|
|
111
111
|
/** Optional CTA actions. */
|
|
112
112
|
actions?: {
|
|
@@ -123,16 +123,16 @@ interface InAppPayload extends BaseNotificationPayload {
|
|
|
123
123
|
to: string;
|
|
124
124
|
}
|
|
125
125
|
/**
|
|
126
|
-
* An email address, optionally with a display name.
|
|
127
|
-
*/
|
|
126
|
+
* An email address, optionally with a display name.
|
|
127
|
+
*/
|
|
128
128
|
interface EmailAddressLike {
|
|
129
129
|
email: string;
|
|
130
130
|
name?: string;
|
|
131
131
|
}
|
|
132
132
|
/**
|
|
133
|
-
* Email channel payload. Delivered through `@visulima/email` by the email channel adapter;
|
|
134
|
-
* the shape mirrors `EmailOptions` so it passes through with minimal mapping.
|
|
135
|
-
*/
|
|
133
|
+
* Email channel payload. Delivered through `@visulima/email` by the email channel adapter;
|
|
134
|
+
* the shape mirrors `EmailOptions` so it passes through with minimal mapping.
|
|
135
|
+
*/
|
|
136
136
|
interface EmailChannelPayload extends BaseNotificationPayload {
|
|
137
137
|
attachments?: unknown[];
|
|
138
138
|
bcc?: EmailRecipients;
|
|
@@ -146,8 +146,8 @@ interface EmailChannelPayload extends BaseNotificationPayload {
|
|
|
146
146
|
to: EmailRecipients;
|
|
147
147
|
}
|
|
148
148
|
/**
|
|
149
|
-
* Generic outbound webhook payload.
|
|
150
|
-
*/
|
|
149
|
+
* Generic outbound webhook payload.
|
|
150
|
+
*/
|
|
151
151
|
interface WebhookPayload extends BaseNotificationPayload {
|
|
152
152
|
/** JSON-serialisable request body. */
|
|
153
153
|
body: unknown;
|
|
@@ -159,12 +159,12 @@ interface WebhookPayload extends BaseNotificationPayload {
|
|
|
159
159
|
url?: string;
|
|
160
160
|
}
|
|
161
161
|
/**
|
|
162
|
-
* Union of all built-in channel payloads.
|
|
163
|
-
*/
|
|
162
|
+
* Union of all built-in channel payloads.
|
|
163
|
+
*/
|
|
164
164
|
type NotificationPayload = ChatPayload | EmailChannelPayload | InAppPayload | PushPayload | SmsPayload | WebhookPayload;
|
|
165
165
|
/**
|
|
166
|
-
* Per-recipient delivery outcome for multi-recipient sends.
|
|
167
|
-
*/
|
|
166
|
+
* Per-recipient delivery outcome for multi-recipient sends.
|
|
167
|
+
*/
|
|
168
168
|
interface RecipientResult {
|
|
169
169
|
error?: string;
|
|
170
170
|
id: string;
|
|
@@ -172,8 +172,8 @@ interface RecipientResult {
|
|
|
172
172
|
status: "failed" | "sent";
|
|
173
173
|
}
|
|
174
174
|
/**
|
|
175
|
-
* Normalised result of a successful provider send.
|
|
176
|
-
*/
|
|
175
|
+
* Normalised result of a successful provider send.
|
|
176
|
+
*/
|
|
177
177
|
interface NotificationResult {
|
|
178
178
|
channel?: ChannelType;
|
|
179
179
|
messageId: string;
|
|
@@ -185,8 +185,8 @@ interface NotificationResult {
|
|
|
185
185
|
timestamp: Date;
|
|
186
186
|
}
|
|
187
187
|
/**
|
|
188
|
-
* A successful send receipt.
|
|
189
|
-
*/
|
|
188
|
+
* A successful send receipt.
|
|
189
|
+
*/
|
|
190
190
|
interface SuccessReceipt {
|
|
191
191
|
channel?: ChannelType;
|
|
192
192
|
messageId: string;
|
|
@@ -196,8 +196,8 @@ interface SuccessReceipt {
|
|
|
196
196
|
timestamp: Date;
|
|
197
197
|
}
|
|
198
198
|
/**
|
|
199
|
-
* A failed send receipt.
|
|
200
|
-
*/
|
|
199
|
+
* A failed send receipt.
|
|
200
|
+
*/
|
|
201
201
|
interface FailureReceipt {
|
|
202
202
|
channel?: ChannelType;
|
|
203
203
|
errorMessages: string[];
|
|
@@ -205,24 +205,24 @@ interface FailureReceipt {
|
|
|
205
205
|
successful: false;
|
|
206
206
|
}
|
|
207
207
|
/**
|
|
208
|
-
* Discriminated send receipt returned by the high-level facade.
|
|
209
|
-
*/
|
|
208
|
+
* Discriminated send receipt returned by the high-level facade.
|
|
209
|
+
*/
|
|
210
210
|
type Receipt = FailureReceipt | SuccessReceipt;
|
|
211
211
|
/**
|
|
212
|
-
* Generic result tuple used across providers and middleware.
|
|
213
|
-
*/
|
|
212
|
+
* Generic result tuple used across providers and middleware.
|
|
213
|
+
*/
|
|
214
214
|
interface Result<T = unknown> {
|
|
215
215
|
data?: T;
|
|
216
216
|
error?: unknown;
|
|
217
217
|
success: boolean;
|
|
218
218
|
}
|
|
219
219
|
/**
|
|
220
|
-
* Lifecycle event names emitted on the event bus and parsed from provider webhooks.
|
|
221
|
-
*/
|
|
220
|
+
* Lifecycle event names emitted on the event bus and parsed from provider webhooks.
|
|
221
|
+
*/
|
|
222
222
|
type NotificationEventType = "bounced" | "clicked" | "delivered" | "failed" | "interacted" | "queued" | "read" | "sent";
|
|
223
223
|
/**
|
|
224
|
-
* Normalised lifecycle / delivery event.
|
|
225
|
-
*/
|
|
224
|
+
* Normalised lifecycle / delivery event.
|
|
225
|
+
*/
|
|
226
226
|
interface NotificationEvent {
|
|
227
227
|
channel?: ChannelType;
|
|
228
228
|
messageId: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { C as ChannelType, B as BaseNotificationPayload, a as NotificationResult, R as Result } from "./types.d-
|
|
1
|
+
import { C as ChannelType, B as BaseNotificationPayload, a as NotificationResult, R as Result } from "./types.d-C7l7qdMG.js";
|
|
2
2
|
/**
|
|
3
|
-
* Context passed through the middleware chain for a single send.
|
|
4
|
-
*/
|
|
3
|
+
* Context passed through the middleware chain for a single send.
|
|
4
|
+
*/
|
|
5
5
|
interface SendContext {
|
|
6
6
|
/** The channel being sent on. */
|
|
7
7
|
channel: ChannelType;
|
|
@@ -11,19 +11,19 @@ interface SendContext {
|
|
|
11
11
|
provider: string;
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
|
-
* The terminal send function and the type middleware wrap.
|
|
15
|
-
*/
|
|
14
|
+
* The terminal send function and the type middleware wrap.
|
|
15
|
+
*/
|
|
16
16
|
type SendFunction = (context: SendContext) => Promise<Result<NotificationResult>>;
|
|
17
17
|
/**
|
|
18
|
-
* A middleware wraps a {@link SendFunction}. The first registered middleware is the
|
|
19
|
-
* outermost wrapper (runs first on the way in, last on the way out).
|
|
20
|
-
*/
|
|
18
|
+
* A middleware wraps a {@link SendFunction}. The first registered middleware is the
|
|
19
|
+
* outermost wrapper (runs first on the way in, last on the way out).
|
|
20
|
+
*/
|
|
21
21
|
type Middleware = (context: SendContext, next: SendFunction) => Promise<Result<NotificationResult>>;
|
|
22
22
|
/**
|
|
23
|
-
* Composes middleware around a terminal send function.
|
|
24
|
-
* @param middlewares Middleware in registration order.
|
|
25
|
-
* @param terminal The terminal send function.
|
|
26
|
-
* @returns A single composed send function.
|
|
27
|
-
*/
|
|
23
|
+
* Composes middleware around a terminal send function.
|
|
24
|
+
* @param middlewares Middleware in registration order.
|
|
25
|
+
* @param terminal The terminal send function.
|
|
26
|
+
* @returns A single composed send function.
|
|
27
|
+
*/
|
|
28
28
|
declare const composeMiddleware: (middlewares: Middleware[], terminal: SendFunction) => SendFunction;
|
|
29
29
|
export { Middleware as M, SendContext as S, SendFunction as a, composeMiddleware as c };
|