@visulima/notification 1.0.12 → 1.0.13

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.
Files changed (149) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/channels/email/index.js +1 -1
  3. package/dist/channels/inapp/index.js +1 -1
  4. package/dist/digest/index.js +1 -1
  5. package/dist/events/index.js +1 -1
  6. package/dist/i18n/index.js +1 -1
  7. package/dist/index.js +1 -1
  8. package/dist/layouts/index.js +1 -1
  9. package/dist/middleware/index.js +1 -1
  10. package/dist/packem_shared/MemoryDigestStore-BDavAEpi.js +1 -0
  11. package/dist/packem_shared/{MemoryInAppStore-48qlrDCx.js → MemoryInAppStore-B-j6qUql.js} +1 -1
  12. package/dist/packem_shared/MemoryQueue-6z5qeFnj.js +1 -0
  13. package/dist/packem_shared/Notification-BjqFrFwT.js +1 -0
  14. package/dist/packem_shared/NotificationError-tZsXfB7V.js +1 -0
  15. package/dist/packem_shared/NotificationMessageBuilder-InFFCs8J.js +1 -0
  16. package/dist/packem_shared/RequiredOptionError-CAuRlc0R.js +1 -0
  17. package/dist/packem_shared/UnstorageDigestStore-CmCl_gjY.js +1 -0
  18. package/dist/packem_shared/UnstorageInAppStore-ygHFsRM3.js +1 -0
  19. package/dist/packem_shared/apnsProvider-Dfgwt-6Z.js +1 -0
  20. package/dist/packem_shared/circuitBreakerMiddleware-B56jCgAH.js +1 -0
  21. package/dist/packem_shared/composeMiddleware-B3RCDFsy.js +1 -0
  22. package/dist/packem_shared/createDigester-g8Iqc2o3.js +1 -0
  23. package/dist/packem_shared/createNotificationWorkflow-C0ggMc1C.js +1 -0
  24. package/dist/packem_shared/createQueueWorker-BU-pYjrf.js +1 -0
  25. package/dist/packem_shared/createTranslator-DAi__AX0.js +1 -0
  26. package/dist/packem_shared/credentials-D9KXFoo0.js +1 -0
  27. package/dist/packem_shared/dedupeMiddleware-CRqssoJS.js +1 -0
  28. package/dist/packem_shared/defineLayout-BU6DLIGc.js +1 -0
  29. package/dist/packem_shared/discordProvider-B9rc2nrV.js +1 -0
  30. package/dist/packem_shared/emailChannel-CnmD8yb2.js +1 -0
  31. package/dist/packem_shared/expoProvider-DofT1sEf.js +1 -0
  32. package/dist/packem_shared/failoverProvider-CyYOOitI.js +1 -0
  33. package/dist/packem_shared/fcmProvider-86S6m7zk.js +1 -0
  34. package/dist/packem_shared/getHeader-BF9s-Tgp.js +1 -0
  35. package/dist/packem_shared/hmacBase64-Dtvoq4Ry.js +1 -0
  36. package/dist/packem_shared/http-YFt2eXXy.js +1 -0
  37. package/dist/packem_shared/id-FYdbBSpb.js +1 -0
  38. package/dist/packem_shared/inAppProvider-DWO4D6VN.js +1 -0
  39. package/dist/packem_shared/loggingMiddleware-BWgqUAe_.js +1 -0
  40. package/dist/packem_shared/messageBirdProvider-CnsBOuY6.js +1 -0
  41. package/dist/packem_shared/mockProvider-OaWdPlKU.js +1 -0
  42. package/dist/packem_shared/msTeamsProvider-BAgW_ba5.js +1 -0
  43. package/dist/packem_shared/otelProvider-DdnT7q6B.js +1 -0
  44. package/dist/packem_shared/plivoProvider-C27zpwI3.js +1 -0
  45. package/dist/packem_shared/rateLimitMiddleware-D5dvn-t9.js +1 -0
  46. package/dist/packem_shared/retryMiddleware-CxmRthT8.js +1 -0
  47. package/dist/packem_shared/roundRobinProvider-BrujhDY6.js +1 -0
  48. package/dist/packem_shared/{slackProvider-Caxbs4Pa.js → slackProvider-CP35fu9-.js} +1 -1
  49. package/dist/packem_shared/slackWebhook-CGbFBgpo.js +1 -0
  50. package/dist/packem_shared/{sms-BbxkOLQm.js → sms-CT04IxF8.js} +1 -1
  51. package/dist/packem_shared/snsProvider-BtlNUN7u.js +4 -0
  52. package/dist/packem_shared/snsWebhook-eOX1eh23.js +1 -0
  53. package/dist/packem_shared/standardWebhook-DV_fVNtX.js +1 -0
  54. package/dist/packem_shared/suppressionMiddleware-DsmnFP8W.js +1 -0
  55. package/dist/packem_shared/telegramProvider-CyaUiWkh.js +1 -0
  56. package/dist/packem_shared/telemetryMiddleware-CpyLbJHB.js +1 -0
  57. package/dist/packem_shared/telnyxProvider-M23jXIyu.js +1 -0
  58. package/dist/packem_shared/twilioProvider-CaoTEqz-.js +1 -0
  59. package/dist/packem_shared/twilioWebhook-DScQeZta.js +1 -0
  60. package/dist/packem_shared/vonageProvider-CYNivc-x.js +1 -0
  61. package/dist/packem_shared/webPushProvider-CUDMDRKw.js +1 -0
  62. package/dist/packem_shared/webcrypto-Cz40u9vp.js +1 -0
  63. package/dist/packem_shared/webhookProvider-C13EqjLL.js +1 -0
  64. package/dist/preferences/index.js +1 -1
  65. package/dist/providers/chat/discord/index.js +1 -1
  66. package/dist/providers/chat/msteams/index.js +1 -1
  67. package/dist/providers/chat/slack/index.js +1 -1
  68. package/dist/providers/chat/telegram/index.js +1 -1
  69. package/dist/providers/failover/index.js +1 -1
  70. package/dist/providers/mock/index.js +1 -1
  71. package/dist/providers/opentelemetry/index.d.ts +1 -1
  72. package/dist/providers/opentelemetry/index.js +1 -1
  73. package/dist/providers/push/apns/index.js +1 -1
  74. package/dist/providers/push/expo/index.js +1 -1
  75. package/dist/providers/push/fcm/index.js +1 -1
  76. package/dist/providers/push/web-push/index.js +1 -1
  77. package/dist/providers/roundrobin/index.js +1 -1
  78. package/dist/providers/sms/messagebird/index.js +1 -1
  79. package/dist/providers/sms/plivo/index.js +1 -1
  80. package/dist/providers/sms/sns/index.js +1 -1
  81. package/dist/providers/sms/telnyx/index.js +1 -1
  82. package/dist/providers/sms/twilio/index.js +1 -1
  83. package/dist/providers/sms/vonage/index.js +1 -1
  84. package/dist/providers/webhook/index.js +1 -1
  85. package/dist/queue/bullmq-queue.js +1 -1
  86. package/dist/queue/index.js +1 -1
  87. package/dist/queue/pg-boss-queue.js +1 -1
  88. package/dist/queue/sqs-queue.js +1 -1
  89. package/dist/queue/unstorage-queue.js +1 -1
  90. package/dist/routing/index.js +1 -1
  91. package/dist/template-engines/handlebars.js +1 -1
  92. package/dist/template-engines/liquid.js +1 -1
  93. package/dist/template-engines/string.js +1 -1
  94. package/dist/utils/result.js +1 -1
  95. package/dist/webhooks/index.js +1 -1
  96. package/dist/workflow/index.d.ts +1 -1
  97. package/dist/workflow/index.js +1 -1
  98. package/package.json +17 -17
  99. package/dist/packem_shared/MemoryDigestStore-Bw-sE5MI.js +0 -1
  100. package/dist/packem_shared/MemoryQueue-CXgWoZoY.js +0 -1
  101. package/dist/packem_shared/Notification-BuS_QjJv.js +0 -1
  102. package/dist/packem_shared/NotificationError-B1ZZqWxL.js +0 -1
  103. package/dist/packem_shared/NotificationMessageBuilder-Br_aZusY.js +0 -1
  104. package/dist/packem_shared/RequiredOptionError-CH4g-BZM.js +0 -1
  105. package/dist/packem_shared/UnstorageDigestStore-QAcO3Vb_.js +0 -1
  106. package/dist/packem_shared/UnstorageInAppStore-Bq2LoDMO.js +0 -1
  107. package/dist/packem_shared/apnsProvider-BV5-wOvD.js +0 -1
  108. package/dist/packem_shared/circuitBreakerMiddleware-o3G_6N3s.js +0 -1
  109. package/dist/packem_shared/composeMiddleware-D6dR8DUS.js +0 -1
  110. package/dist/packem_shared/createDigester-DCwWhmpi.js +0 -1
  111. package/dist/packem_shared/createNotificationWorkflow-lseG_9fC.js +0 -1
  112. package/dist/packem_shared/createQueueWorker-BIXWHJLY.js +0 -1
  113. package/dist/packem_shared/createTranslator-BL2M8eeD.js +0 -1
  114. package/dist/packem_shared/credentials-CG0zkn-W.js +0 -1
  115. package/dist/packem_shared/dedupeMiddleware-CQmPJd_h.js +0 -1
  116. package/dist/packem_shared/defineLayout-73TNxYPq.js +0 -1
  117. package/dist/packem_shared/discordProvider-D4LpBljj.js +0 -1
  118. package/dist/packem_shared/emailChannel-BoLLbyrn.js +0 -1
  119. package/dist/packem_shared/expoProvider-BPJr9c0e.js +0 -1
  120. package/dist/packem_shared/failoverProvider-CJsDGjzf.js +0 -1
  121. package/dist/packem_shared/fcmProvider-qIR12R9m.js +0 -1
  122. package/dist/packem_shared/getHeader-C_gkdnMQ.js +0 -1
  123. package/dist/packem_shared/hmacBase64-CNksyDoB.js +0 -1
  124. package/dist/packem_shared/http-DT3tyixg.js +0 -1
  125. package/dist/packem_shared/id-C_FRCsUM.js +0 -1
  126. package/dist/packem_shared/inAppProvider-ElbahgSj.js +0 -1
  127. package/dist/packem_shared/loggingMiddleware-Cs6EDLcL.js +0 -1
  128. package/dist/packem_shared/messageBirdProvider-FK9_UONf.js +0 -1
  129. package/dist/packem_shared/mockProvider-C2hHPSVa.js +0 -1
  130. package/dist/packem_shared/msTeamsProvider-DeGPjmCt.js +0 -1
  131. package/dist/packem_shared/otelProvider-b6LVo0BS.js +0 -1
  132. package/dist/packem_shared/plivoProvider-DaCu7J3X.js +0 -1
  133. package/dist/packem_shared/rateLimitMiddleware-DWmEYq-m.js +0 -1
  134. package/dist/packem_shared/retryMiddleware-uUJDcUoP.js +0 -1
  135. package/dist/packem_shared/roundRobinProvider-HowYifRe.js +0 -1
  136. package/dist/packem_shared/slackWebhook-IB4mVnBk.js +0 -1
  137. package/dist/packem_shared/snsProvider-BS4D6w-i.js +0 -4
  138. package/dist/packem_shared/snsWebhook-BKBTQyEW.js +0 -1
  139. package/dist/packem_shared/standardWebhook-C_AQWUi5.js +0 -1
  140. package/dist/packem_shared/suppressionMiddleware-CY-Qo1A_.js +0 -1
  141. package/dist/packem_shared/telegramProvider-BIc_GgpY.js +0 -1
  142. package/dist/packem_shared/telemetryMiddleware-B1N4k171.js +0 -1
  143. package/dist/packem_shared/telnyxProvider-wjmTXBwh.js +0 -1
  144. package/dist/packem_shared/twilioProvider-Bf_zsF9z.js +0 -1
  145. package/dist/packem_shared/twilioWebhook-Hhf9aWV1.js +0 -1
  146. package/dist/packem_shared/vonageProvider-oRg9dpS1.js +0 -1
  147. package/dist/packem_shared/webPushProvider-BtZHb_X_.js +0 -1
  148. package/dist/packem_shared/webcrypto-CFuQmh5-.js +0 -1
  149. package/dist/packem_shared/webhookProvider-CwkDb1cZ.js +0 -1
@@ -1 +1 @@
1
- import{hmacBase64 as r,hmacHex as t,timingSafeEqual as a}from"../packem_shared/hmacBase64-CNksyDoB.js";import{slackWebhook as f}from"../packem_shared/slackWebhook-IB4mVnBk.js";import{snsWebhook as h}from"../packem_shared/snsWebhook-BKBTQyEW.js";import{standardWebhook as k}from"../packem_shared/standardWebhook-C_AQWUi5.js";import{twilioWebhook as b}from"../packem_shared/twilioWebhook-Hhf9aWV1.js";import{getHeader as W}from"../packem_shared/getHeader-C_gkdnMQ.js";export{W as getHeader,r as hmacBase64,t as hmacHex,f as slackWebhook,h as snsWebhook,k as standardWebhook,a as timingSafeEqual,b as twilioWebhook};
1
+ import{hmacBase64 as r,hmacHex as t,timingSafeEqual as a}from"../packem_shared/hmacBase64-Dtvoq4Ry.js";import{slackWebhook as f}from"../packem_shared/slackWebhook-CGbFBgpo.js";import{snsWebhook as h}from"../packem_shared/snsWebhook-eOX1eh23.js";import{standardWebhook as k}from"../packem_shared/standardWebhook-DV_fVNtX.js";import{twilioWebhook as b}from"../packem_shared/twilioWebhook-DScQeZta.js";import{getHeader as W}from"../packem_shared/getHeader-BF9s-Tgp.js";export{W as getHeader,r as hmacBase64,t as hmacHex,f as slackWebhook,h as snsWebhook,k as standardWebhook,a as timingSafeEqual,b as twilioWebhook};
@@ -1,7 +1,7 @@
1
1
  import { M as MaybePromise, D as Duration, W as WorkflowConfig, a as WorkflowDefinition } from "../packem_shared/types.d-CcjfiGpo.d-DuZME7ry.js";
2
- import '@standard-schema/spec';
3
2
  import { C as ChannelPayloadMap, N as Notification } from "../packem_shared/notification.d-D0ado_cy.js";
4
3
  import { C as ChannelType, c as Receipt } from "../packem_shared/types.d-C7l7qdMG.js";
4
+ import '@standard-schema/spec';
5
5
  import "../packem_shared/types.d-CRs03TYV.js";
6
6
  import "../packem_shared/provider.d-Dh32nRm9.js";
7
7
  /** The context handed to a step resolver / skip predicate. */
@@ -1 +1 @@
1
- import{default as a}from"../packem_shared/createNotificationWorkflow-lseG_9fC.js";export{a as createNotificationWorkflow};
1
+ import{default as a}from"../packem_shared/createNotificationWorkflow-C0ggMc1C.js";export{a as createNotificationWorkflow};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visulima/notification",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "description": "A reusable, ESM-only, edge-ready multi-channel notification library with SMS, push, chat, in-app and webhook providers",
5
5
  "keywords": [
6
6
  "apns",
@@ -37,11 +37,6 @@
37
37
  ],
38
38
  "homepage": "https://visulima.com/packages/notification",
39
39
  "bugs": "https://github.com/visulima/visulima/issues",
40
- "license": "MIT",
41
- "author": {
42
- "name": "Daniel Bannert",
43
- "email": "d.bannert@anolilab.de"
44
- },
45
40
  "repository": {
46
41
  "type": "git",
47
42
  "url": "git+https://github.com/visulima/visulima.git",
@@ -57,13 +52,13 @@
57
52
  "url": "https://anolilab.com/support"
58
53
  }
59
54
  ],
60
- "files": [
61
- "dist",
62
- "README.md",
63
- "CHANGELOG.md"
64
- ],
65
- "type": "module",
55
+ "license": "MIT",
56
+ "author": {
57
+ "name": "Daniel Bannert",
58
+ "email": "d.bannert@anolilab.de"
59
+ },
66
60
  "sideEffects": false,
61
+ "type": "module",
67
62
  "exports": {
68
63
  ".": {
69
64
  "types": "./dist/index.d.ts",
@@ -227,14 +222,15 @@
227
222
  },
228
223
  "./package.json": "./package.json"
229
224
  },
230
- "publishConfig": {
231
- "access": "public",
232
- "provenance": true
233
- },
225
+ "files": [
226
+ "dist",
227
+ "README.md",
228
+ "CHANGELOG.md"
229
+ ],
234
230
  "peerDependencies": {
235
231
  "@aws-sdk/client-sqs": "^3.0.0",
236
232
  "@opentelemetry/api": "^1.0.0 || ^2.0.0",
237
- "@visulima/email": "2.1.8",
233
+ "@visulima/email": "2.1.9",
238
234
  "@visulima/workflow": "3.0.0",
239
235
  "bullmq": "^5.0.0",
240
236
  "croner": "^10.0.1",
@@ -281,5 +277,9 @@
281
277
  },
282
278
  "engines": {
283
279
  "node": "^22.14.0 || >=24.10.0"
280
+ },
281
+ "publishConfig": {
282
+ "access": "public",
283
+ "provenance": true
284
284
  }
285
285
  }
@@ -1 +0,0 @@
1
- class a{#e=new Map;append(e,s,r){const t=this.#e.get(e);return t===void 0?(this.#e.set(e,{events:[s],key:e,wakeAt:r}),Promise.resolve(!0)):(t.events.push(s),Promise.resolve(!1))}read(e){return Promise.resolve(this.#e.get(e))}remove(e){return this.#e.delete(e),Promise.resolve()}due(e,s){const r=[...this.#e.values()].filter(t=>t.wakeAt<=e).toSorted((t,o)=>t.wakeAt-o.wakeAt).slice(0,s).map(t=>t.key);return Promise.resolve(r)}}export{a as default};
@@ -1 +0,0 @@
1
- import{n}from"./id-C_FRCsUM.js";class r{#e=[];#t=new Map;enqueue(t,s){const e={attempts:0,id:n("job"),message:t,scheduledAt:s?.scheduledAt};return this.#e.push(e),e.id}reserve(){const t=Date.now(),s=this.#e.findIndex(i=>(i.scheduledAt??0)<=t);if(s===-1)return;const e=this.#e.splice(s,1)[0];return e.attempts+=1,this.#t.set(e.id,e),e}ack(t){this.#t.delete(t)}retry(t,s=0){const e=this.#t.get(t);e&&(this.#t.delete(t),e.scheduledAt=Date.now()+s,this.#e.push(e))}size(){return this.#e.length}}export{r as default};
@@ -1 +0,0 @@
1
- import h from"./NotificationError-B1ZZqWxL.js";import{composeMiddleware as u}from"./composeMiddleware-D6dR8DUS.js";const c=(a,s,e)=>{if(a.success&&a.data)return{channel:s,messageId:a.data.messageId,provider:a.data.provider??e,response:a.data.response,successful:!0,timestamp:a.data.timestamp};const{error:t}=a;let i;return t instanceof Error?i=t.message:t==null?i="Unknown error":typeof t=="string"?i=t:i=JSON.stringify(t),{channel:s,errorMessages:[i],provider:e,successful:!1}};class l{#s;#e=[];#t=new Map;#a;constructor(s){this.#s=s}use(s){return this.#e.push(s),this}setLogger(s){return this.#a=s,this}getProvider(s){return this.#s[s]}async sendToChannel(s,e){const t=this.#s[s];if(!t)return{channel:s,errorMessages:[`No provider registered for channel "${s}"`],successful:!1};try{await this.#i(t)}catch(n){return c({error:n,success:!1},s,t.id)}const i=async n=>t.send(n.payload),r=u(this.#e,i);try{const n=await r({channel:s,payload:e,provider:t.id});return c(n,s,t.id)}catch(n){return c({error:n,success:!1},s,t.id)}}async send(s){const e=Object.keys(s);if(e.length===0)throw new h("notification","send() called with an empty message");return Promise.all(e.map(async t=>this.sendToChannel(t,s[t])))}async*sendMany(s,e={}){const t=Math.max(1,e.concurrency??10),i=[...s];let r=0;for(;r<i.length;){const n=i.slice(r,r+t);r+=t;const d=await Promise.all(n.map(async o=>this.send(o)));for(const o of d)yield o}}async initialize(){await Promise.all(Object.values(this.#s).map(async s=>this.#i(s)))}async shutdown(){await Promise.all(Object.values(this.#s).map(async s=>{const{shutdown:e}=s;e&&await e()}))}async#i(s){const e=this.#t.get(s.id);if(e){await e;return}const t=(async()=>{await s.initialize(),this.#a?.debug(`[@visulima/notification] initialized provider "${s.id}"`)})();this.#t.set(s.id,t);try{await t}catch(i){throw this.#t.delete(s.id),i}}}const m=a=>new l(a),p=async(a,s,e)=>new l({[a]:s}).sendToChannel(a,e);export{l as Notification,m as createNotification,p as send};
@@ -1 +0,0 @@
1
- class h extends Error{loc;title;hint;type="VisulimaError";constructor({cause:t,hint:e,location:s,message:o,name:a,stack:c,title:n}){super(o,{cause:t}),this.title=n,this.name=a,this.stack=c??this.stack,this.loc=s,this.hint=e}setLocation(t){this.loc=t}setName(t){this.name=t}setMessage(t){this.message=t}setHint(t){this.hint=t}}class r extends h{component;code;constructor(t,e,s){super({cause:s?.cause,hint:s?.hint,message:`[@visulima/notification] [${t}] ${e}`,name:"NotificationError",title:`Notification ${t} Error`}),this.component=t,this.code=s?.code}}export{r as default};
@@ -1 +0,0 @@
1
- class r{#t={};#i;#s;sms(t){return this.#t.sms=t,this}push(t){return this.#t.push=t,this}chat(t){return this.#t.chat=t,this}inApp(t){return this.#t.inapp=t,this}webhook(t){return this.#t.webhook=t,this}email(t){return this.#t.email=t,this}metadata(t){return this.#i=t,this}idempotencyKey(t){return this.#s=t,this}build(){const t=this.#i,s=this.#s;if(t===void 0&&s===void 0)return{...this.#t};const e={},o=Object.keys(this.#t);for(const h of o){const n=this.#t[h];if(n!==void 0){const i={};t!==void 0&&(i.metadata=t),s!==void 0&&(i.idempotencyKey=s),Object.assign(i,n),e[h]=i}}return e}}const c=()=>new r;export{r as NotificationMessageBuilder,c as createNotificationMessage};
@@ -1 +0,0 @@
1
- import s from"./NotificationError-B1ZZqWxL.js";class a extends s{constructor(o,e){const r=Array.isArray(e)?`Missing required options: ${e.map(i=>`'${i}'`).join(", ")}`:`Missing required option: '${e}'`;super(o,r,{hint:Array.isArray(e)?`Please provide the following required options: ${e.map(i=>`'${i}'`).join(", ")}`:`Please provide the required option: '${e}'`}),this.name="RequiredOptionError"}}export{a as default};
@@ -1 +0,0 @@
1
- const a="digest:w:";class o{#t;constructor(t){this.#t=t}async append(t,s,i){const e=await this.#t.getItem(a+t);return e!==null?(e.events.push(s),await this.#t.setItem(a+t,e),!1):(await this.#t.setItem(a+t,{events:[s],key:t,wakeAt:i}),!0)}async read(t){return await this.#t.getItem(a+t)??void 0}async remove(t){await this.#t.removeItem(a+t)}async due(t,s){const i=await this.#t.getKeys(a);return(await Promise.all(i.map(async e=>this.#t.getItem(e)))).filter(e=>e!==null&&e.wakeAt<=t).toSorted((e,n)=>e.wakeAt-n.wakeAt).slice(0,s).map(e=>e.key)}}export{o as default};
@@ -1 +0,0 @@
1
- import{n as c}from"./id-C_FRCsUM.js";class h{#t;#s;constructor(t,a="notification:inapp"){this.#t=t,this.#s=a}async add(t){const a={...t,createdAt:Date.now(),id:t.id??c("inapp"),read:!1};return await this.#t.setItem(this.#a(a.id),a),await this.#n(a.subscriberId,a.id),a}async list(t,a={}){const i=await this.#r(t),s=(a.unreadOnly?i.filter(e=>!e.read):i).toSorted((e,n)=>n.createdAt-e.createdAt);return a.limit?s.slice(0,a.limit):s}async markRead(t){const a=await this.#t.getItem(this.#a(t));a&&(a.read=!0,await this.#t.setItem(this.#a(t),a))}async markAllRead(t){const a=await this.#i(t);await Promise.all(a.map(async i=>this.markRead(i)))}async unreadCount(t){return(await this.#r(t)).filter(a=>!a.read).length}async remove(t){const a=await this.#t.getItem(this.#a(t));await this.#t.removeItem(this.#a(t)),a&&await this.#c(a.subscriberId,t)}#a(t){return`${this.#s}:item:${t}`}#e(t){return`${this.#s}:index:${t}`}async#i(t){return await this.#t.getItem(this.#e(t))??[]}async#r(t){const a=await this.#i(t);return(await Promise.all(a.map(async i=>await this.#t.getItem(this.#a(i))))).filter(i=>i!==null)}async#n(t,a){const i=await this.#i(t);i.includes(a)||(i.push(a),await this.#t.setItem(this.#e(t),i))}async#c(t,a){const i=(await this.#i(t)).filter(s=>s!==a);await this.#t.setItem(this.#e(t),i)}}const d=(r,t)=>new h(r,t);export{h as UnstorageInAppStore,d as createUnstorageInAppStore};
@@ -1 +0,0 @@
1
- import{createRequire as I}from"node:module";import g from"./RequiredOptionError-CH4g-BZM.js";import{defineProvider as k}from"./defineProvider-C9q-7iwt.js";import{t as N}from"./credentials-CG0zkn-W.js";import{a as R}from"./sms-BbxkOLQm.js";let S;const T=s=>(S??=I(import.meta.url))(s),f=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,y=s=>{if(typeof f<"u"&&f.versions&&f.versions.node){const[t,r]=f.versions.node.split(".").map(Number);if(t>22||t===22&&r>=3||t===20&&r>=16)return f.getBuiltinModule(s)}return T(s)},{sign:$,createPrivateKey:P}=y("node:crypto"),{connect:j}=y("node:http2"),q="https://api.push.apple.com",J="https://api.sandbox.push.apple.com",K=3e3*1e3,O=200,h=s=>Buffer.from(s,"utf8").toString("base64url"),B=(s,t,r)=>{const l=h(JSON.stringify({alg:"ES256",kid:s.keyId,typ:"JWT"})),p=h(JSON.stringify({iat:r,iss:s.teamId})),u=`${l}.${p}`,n=$("sha256",Buffer.from(u,"utf8"),{dsaEncoding:"ieee-p1363",key:t}).toString("base64url");return`${u}.${n}`},A=k(s=>{const t=s??{};if(!t.teamId)throw new g("apns","teamId");if(!t.keyId)throw new g("apns","keyId");if(!t.signingKey)throw new g("apns","signingKey");if(!t.bundleId)throw new g("apns","bundleId");const r=t.production?q:J;let l,p,u=0,n;const b=()=>(l??=P({format:"pem",key:t.signingKey}),l),_=()=>{const e=Date.now();return(!p||e-u>K)&&(p=B(t,b(),Math.floor(e/1e3)),u=e),p},w=()=>((!n||n.closed||n.destroyed)&&(n=j(r),n.on("error",e=>{t.logger?.warn(`[@visulima/notification] [apns] HTTP/2 session error: ${e.message}`)})),n),v=async(e,m)=>new Promise(a=>{const i=w().request({":method":"POST",":path":`/3/device/${e}`,"apns-topic":t.bundleId,authorization:`bearer ${_()}`,"content-type":"application/json"});let d=0,c="";i.setEncoding("utf8"),i.on("response",o=>{d=o[":status"]??0}),i.on("data",o=>{c+=o}),i.on("error",o=>{a({error:o.message,id:e,status:"failed"})}),i.on("end",()=>{if(d===O){a({id:e,messageId:e,status:"sent"});return}let o=`HTTP ${String(d)}`;if(c)try{o=JSON.parse(c).reason??o}catch{o=c}a({error:o,id:e,status:"failed"})}),i.end(m)});return{channel:"push",endpoint:r,features:{batchSending:!1,media:!0,richContent:!0},id:"apns",initialize:()=>{},isAvailable:()=>!0,options:t,send:async e=>{const m=N(e.to),a={alert:{body:e.body,title:e.title}};e.sound!==void 0&&(a.sound=e.sound),e.badge!==void 0&&(a.badge=e.badge);const i=JSON.stringify({...e.data,aps:a}),d=[];for(const c of m)d.push(await v(c,i));return R("push","apns",d)},shutdown:()=>{n&&!n.closed&&n.close(),n=void 0}}});export{A as default};
@@ -1 +0,0 @@
1
- import u from"./NotificationError-B1ZZqWxL.js";const p=(o={})=>{const i=o.threshold??5,n=o.resetTimeout??3e4;let r=0,s=0,e="closed";return async(t,a)=>{if(e==="open")if(Date.now()-s>=n)e="half-open";else return{error:new u("circuit-breaker",`Circuit open for "${t.provider}"`),success:!1};const c=await a(t);return c.success?(r=0,e="closed"):(r+=1,r>=i&&(e="open",s=Date.now())),c}};export{p as circuitBreakerMiddleware};
@@ -1 +0,0 @@
1
- const n=(o,t)=>{let e=t;for(const r of o.toReversed()){const s=e;e=c=>r(c,s)}return e};export{n as composeMiddleware};
@@ -1 +0,0 @@
1
- import r from"./NotificationError-B1ZZqWxL.js";import u from"./MemoryDigestStore-Bw-sE5MI.js";const d={days:864e5,hours:36e5,milliseconds:1,minutes:6e4,ms:1,seconds:1e3,weeks:6048e5},c=async(e,t)=>{if(typeof e=="number"){if(!Number.isFinite(e))throw new r("digest",`Window must be a finite number of milliseconds. Received: ${String(e)}.`);return t+Math.max(0,e)}if("cron"in e){let i;try{i=await import("croner")}catch(o){throw new r("digest","croner is not installed (required for cron windows). Please install it: pnpm add croner",{cause:o})}const n=new i.Cron(e.cron,e.tz?{timezone:e.tz}:{}).nextRun(new Date(t));if(n===null)throw new r("digest",`Cron expression "${e.cron}" has no future occurrence.`);return n.getTime()}if(!Number.isFinite(e.amount))throw new r("digest",`Window amount must be a finite number. Received: ${String(e.amount)}.`);return t+Math.max(0,e.amount)*d[e.unit]},m=()=>globalThis.crypto.randomUUID(),p=e=>{const t=e.store??new u;return{add:async i=>{const n=e.key(i),o=typeof e.window=="function"?e.window(i):e.window,s={id:m(),payload:i,time:Date.now()};return t.append(n,s,await c(o,Date.now()))},sweep:async(i=Date.now(),n=100)=>{if(!Number.isInteger(n)||n<=0)throw new r("digest",`sweep limit must be a positive integer. Received: ${String(n)}.`);const o=await t.due(i,n);let s=0;for(const w of o){const a=await t.read(w);a!==void 0&&a.events.length>0&&(await e.onFlush(a.events,w),s+=1),a!==void 0&&await t.remove(w)}return s}}};export{p as default};
@@ -1 +0,0 @@
1
- import{defineWorkflow as y}from"@visulima/workflow";import c from"./NotificationError-B1ZZqWxL.js";const m=(d,p)=>{const l=e=>{const n=async(a,s,o,r)=>e.step(s,async()=>{if(r?.skip&&await r.skip({payload:e.payload}))return;const u=await o({payload:e.payload}),t=await d.sendToChannel(a,u);if(r?.throwOnFailure&&!t.successful)throw new c(a,t.errorMessages.join("; "));return t}),i={chat:(a,s,o)=>n("chat",a,s,o),custom:(a,s)=>e.step(a,s),delay:(a,s)=>e.sleep(a,s),email:(a,s,o)=>n("email",a,s,o),inApp:(a,s,o)=>n("inapp",a,s,o),push:(a,s,o)=>n("push",a,s,o),sms:(a,s,o)=>n("sms",a,s,o),webhook:(a,s,o)=>n("webhook",a,s,o)};return p.run({payload:e.payload,runId:e.runId,step:i})};return y({id:p.id,payload:p.payload,run:l,tags:p.tags})};export{m as default};
@@ -1 +0,0 @@
1
- const u=async a=>new Promise(o=>{setTimeout(o,a)}),w=(a,o,e={})=>{const f=e.maxAttempts??5,l=e.pollInterval??1e3,n=e.backoff??(t=>Math.min(3e4,1e3*2**(t-1)));let r=!1;const i=async()=>{const t=await a.reserve();if(!t)return!1;try{const s=await o.send(t.message);s.some(c=>!c.successful)?t.attempts>=f?(await a.ack(t.id),e.onDrop?.(t,s)):await a.retry(t.id,n(t.attempts)):await a.ack(t.id)}catch(s){e.onError?.(s,t);try{await a.retry(t.id,n(t.attempts))}catch(c){e.onError?.(c,t)}}return!0},m=async()=>{for(;r;){let t=!1;try{t=await i()}catch(s){e.onError?.(s)}t||await u(l)}};return{drain:async()=>{for(;await i(););},start:()=>{r||(r=!0,m().catch(()=>{r=!1}))},stop:()=>{r=!1}}};export{w as createQueueWorker};
@@ -1 +0,0 @@
1
- import{IntlMessageFormat as f}from"intl-messageformat";import g from"./NotificationError-B1ZZqWxL.js";const u=/[-_]/u,m=e=>e.split(u)[0]??e,$=e=>{const n=new Map,c=(t,o)=>{for(const s of[t,m(t),e.fallbackLocale,m(e.fallbackLocale)]){const a=e.messages[s]?.[o];if(a!==void 0)return{locale:s,message:a}}};return{has:(t,o)=>c(t,o)!==void 0,translate:(t,o,s)=>{const a=c(t,o);if(a===void 0)return e.onMissing?e.onMissing(t,o):o;const r=`${a.locale}\0${o}`;let l=n.get(r);l===void 0&&(l=new f(a.message,a.locale.replaceAll("_","-")),n.set(r,l));try{return String(l.format(s))}catch(i){throw new g("i18n",`Failed to format message "${o}" for locale "${a.locale}": ${i.message}`,{cause:i})}}}};export{$ as default};
@@ -1 +0,0 @@
1
- const s=(t,a)=>`Basic ${btoa(`${t}:${a}`)}`,i=t=>Array.isArray(t)?t:[t];export{s as b,i as t};
@@ -1 +0,0 @@
1
- const i=(s={})=>{const r=s.ttl??6e4,t=new Map;return async(e,a)=>{const n=s.keyFn?s.keyFn(e):e.payload.idempotencyKey;if(!n)return a(e);const o=Date.now();for(const[d,p]of t)p<o&&t.delete(d);if(t.has(n))return{data:{channel:e.channel,messageId:`deduped:${n}`,provider:e.provider,sent:!1,timestamp:new Date},success:!0};const c=await a(e);return c.success&&t.set(n,o+r),c}};export{i as dedupeMiddleware};
@@ -1 +0,0 @@
1
- import s from"../template-engines/string.js";const c=r=>{const t=r.render??s,e=r.slot??"content";return{render:async(n,o={})=>t(r.template,{...o,[e]:n})}};export{c as default};
@@ -1 +0,0 @@
1
- import s from"./NotificationError-B1ZZqWxL.js";import c from"./RequiredOptionError-CH4g-BZM.js";import{defineProvider as l}from"./defineProvider-C9q-7iwt.js";import{r as m}from"./http-DT3tyixg.js";import{n as u}from"./id-C_FRCsUM.js";const k=l(a=>{const e=a??{};if(!e.webhookUrl)throw new c("discord","webhookUrl");const i=e.retries??3,d=e.timeout??3e4,n=e.webhookUrl.includes("?")?`${e.webhookUrl}&wait=true`:`${e.webhookUrl}?wait=true`;return{channel:"chat",endpoint:e.webhookUrl,features:{batchSending:!1,richContent:!0},id:"discord",initialize:()=>{},isAvailable:()=>!!e.webhookUrl,options:e,send:async r=>{const o={content:r.text,embeds:r.blocks,username:e.username};r.threadId&&(o.thread_id=r.threadId);const t=await m(n,{body:JSON.stringify(o),headers:{"Content-Type":"application/json"},method:"POST",timeout:d},i);return!t.success||!t.data?{error:new s("discord",t.error instanceof Error?t.error.message:"Request failed"),success:!1}:t.data.status>=400?{error:new s("discord",t.data.body.message??`HTTP ${String(t.data.status)}`),success:!1}:{data:{channel:"chat",messageId:t.data.body.id??u("discord"),provider:"discord",sent:!0,timestamp:new Date},success:!0}},validateCredentials:()=>!!e.webhookUrl}});export{k as default};
@@ -1 +0,0 @@
1
- import n from"./NotificationError-B1ZZqWxL.js";const c=(t,r={})=>{const a=r.id??"email";return{channel:"email",features:{attachments:!0,batchSending:!0,richContent:!0,templates:!0,tracking:!0},id:a,initialize:()=>{},isAvailable:()=>!0,send:async s=>{const e=await t.send(s);return!e.success||!e.data?{error:new n(a,e.error instanceof Error?e.error.message:"Email send failed",{cause:e.error}),success:!1}:{data:{channel:"email",messageId:e.data.messageId,provider:e.data.provider??a,response:e.data.response,sent:e.data.sent??!0,timestamp:e.data.timestamp??new Date},success:!0}}}};export{c as emailChannel};
@@ -1 +0,0 @@
1
- import d from"./NotificationError-B1ZZqWxL.js";import{defineProvider as x}from"./defineProvider-C9q-7iwt.js";import{t as T}from"./credentials-CG0zkn-W.js";import{r as w}from"./http-DT3tyixg.js";import{n as A}from"./id-C_FRCsUM.js";const $="https://exp.host",R=x(l=>{const t=l??{},u=t.endpoint??$,f=t.retries??3,h=t.timeout??3e4,g=`${u}/--/api/v2/push/send`;return{channel:"push",endpoint:u,features:{batchSending:!0,media:!0,richContent:!0},id:"expo",initialize:()=>{},isAvailable:()=>!0,options:t,send:async s=>{const p=T(s.to),y=p.map(r=>({badge:s.badge,body:s.body,data:s.data,sound:s.sound??"default",title:s.title,to:r})),c={"Content-Type":"application/json"};t.accessToken&&(c.Authorization=`Bearer ${t.accessToken}`);const e=await w(g,{body:JSON.stringify(y),headers:c,method:"POST",timeout:h},f);if(!e.success||!e.data)return{error:new d("expo",e.error instanceof Error?e.error.message:"Request failed"),success:!1};if(e.data.status>=400)return{error:new d("expo",`HTTP ${String(e.data.status)}`),success:!1};const a=e.data.body.data;let n;Array.isArray(a)?n=a:n=a?[a]:[];const i=p.map((r,b)=>{const o=n[b];return o?.status==="error"?{error:o.details?.error??o.message??"error",id:r,status:"failed"}:{id:r,messageId:o?.id,status:"sent"}}),m=i.filter(r=>r.status==="sent");return m.length===0?{error:new d("expo",i[0]?.error??"All tokens failed"),success:!1}:{data:{channel:"push",messageId:m[0]?.messageId??A("expo"),provider:"expo",recipients:i,sent:!0,timestamp:new Date},success:!0}}}});export{R as default};
@@ -1 +0,0 @@
1
- import l from"./NotificationError-B1ZZqWxL.js";const d=(r,o={})=>{if(r.length===0)throw new l("failover","At least one provider is required");const n=o.id??"failover";return{channel:r[0].channel,id:n,initialize:async()=>{await Promise.all(r.map(async e=>e.initialize()))},isAvailable:async()=>(await Promise.all(r.map(async e=>e.isAvailable()))).some(Boolean),send:async e=>{const s=[];for(const a of r){const i=await a.send(e);if(i.success)return i;const t=i.error instanceof Error?i.error.message:String(i.error);s.push(`${a.id}: ${t}`),o.logger?.warn(`[@visulima/notification] [${n}] provider "${a.id}" failed, trying next`)}return{error:new l(n,`All ${String(r.length)} providers failed: ${s.join("; ")}`),success:!1}}}};export{d as failoverProvider};
@@ -1 +0,0 @@
1
- import g from"./NotificationError-B1ZZqWxL.js";import n from"./RequiredOptionError-CH4g-BZM.js";import{defineProvider as l}from"./defineProvider-C9q-7iwt.js";import{t as h}from"./credentials-CG0zkn-W.js";import{r as y}from"./http-DT3tyixg.js";import{a as T}from"./sms-BbxkOLQm.js";const O=l(c=>{const e=c??{};if(!e.projectId)throw new n("fcm","projectId");if(!e.accessToken&&!e.getAccessToken)throw new n("fcm",["accessToken","getAccessToken"]);const i=e.endpoint??"https://fcm.googleapis.com",d=e.retries??3,m=e.timeout??3e4,f=`${i}/v1/projects/${e.projectId}/messages:send`,p=s=>{if(s)return Object.fromEntries(Object.entries(s).map(([o,r])=>[o,typeof r=="string"?r:JSON.stringify(r)]))},u=async(s,o,r)=>{const a={data:p(o.data),notification:{body:o.body,image:o.imageUrl,title:o.title},token:s},t=await y(f,{body:JSON.stringify({message:a}),headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json"},method:"POST",timeout:m},d);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 o;try{o=e.getAccessToken?await e.getAccessToken():e.accessToken}catch(t){return{error:new g("fcm","Failed to obtain access token",{cause:t}),success:!1}}const r=h(s.to),a=[];for(const t of r)a.push(await u(t,s,o));return T("push","fcm",a)}}});export{O as default};
@@ -1 +0,0 @@
1
- const a=t=>{try{const r=JSON.parse(t);return typeof r=="object"&&r!==null&&!Array.isArray(r)?r:void 0}catch{return}},c=(t,r)=>{const s=r.toLowerCase();for(const o of Object.keys(t))if(o.toLowerCase()===s){const e=t[o];return Array.isArray(e)?e[0]:e}};export{c as getHeader,a as tryParseObject};
@@ -1 +0,0 @@
1
- import{t as o,h as r,a as s}from"./webcrypto-CFuQmh5-.js";const l=300,c=async(a,e,t)=>s(await r(a,e,t)),f=async(a,e,t)=>o(await r(a,e,t)),h=(a,e)=>{if(a.length!==e.length)return!1;let t=0;for(let n=0;n<a.length;n+=1)t|=(a.codePointAt(n)??0)^(e.codePointAt(n)??0);return t===0},m=(a,e)=>{if(a===void 0)return!1;const t=Number.parseInt(a,10);if(Number.isNaN(t))return!1;const n=Math.floor(Date.now()/1e3);return Math.abs(n-t)<=e};export{l as REPLAY_WINDOW_SECONDS,f as hmacBase64,c as hmacHex,m as isWithinReplayWindow,h as timingSafeEqual};
@@ -1 +0,0 @@
1
- const i=async(a,s={})=>{const u=new AbortController,c=s.timeout??3e4,e=setTimeout(()=>{u.abort()},c);try{const t=await fetch(a,{body:s.body,headers:s.headers,method:s.method??"GET",signal:u.signal}),r=await t.text();let o=r;if(r.length>0)try{o=JSON.parse(r)}catch{o=r}const n={};return t.headers.forEach((d,h)=>{n[h]=d}),{data:{body:o,headers:n,status:t.status,statusText:t.statusText},success:!0}}catch(t){return{error:t,success:!1}}finally{clearTimeout(e)}},l=a=>a===408||a===429||a>=500,m=async(a,s={},u=3,c=250)=>{let e=await i(a,s);for(let t=0;t<u;t+=1){if(!(!e.success||e.data!==void 0&&l(e.data.status)))return e;const r=c*2**t+Math.floor(Math.random()*c);await new Promise(o=>setTimeout(o,r)),e=await i(a,s)}return e};export{i as m,m as r};
@@ -1 +0,0 @@
1
- let n=0;const t=o=>{n+=1;const r=globalThis.crypto;return r?.randomUUID?`${o}-${r.randomUUID()}`:`${o}-${String(n)}-${Math.floor(Math.random()*1e9).toString(36)}`};export{t as n};
@@ -1 +0,0 @@
1
- import{MemoryInAppStore as r}from"./MemoryInAppStore-48qlrDCx.js";const o=(t={})=>{const a=t.id??"inapp",n=t.store??new r;return{channel:"inapp",features:{richContent:!0},getInstance:()=>n,id:a,initialize:()=>{},isAvailable:()=>!0,send:async e=>{const i=await n.add({actions:e.actions,body:e.body,data:e.data,subscriberId:e.to,title:e.title});return{data:{channel:"inapp",messageId:i.id,provider:a,sent:!0,timestamp:new Date(i.createdAt)},success:!0}}}};export{o as inAppProvider};
@@ -1 +0,0 @@
1
- const s=(n={})=>{const i=n.logger??console;return async(r,o)=>{i.debug(`[@visulima/notification] sending via "${r.provider}" (${r.channel})`);const e=await o(r);if(e.success)i.debug(`[@visulima/notification] sent ${e.data?.messageId??""} via "${r.provider}"`);else{const a=e.error instanceof Error?e.error.message:String(e.error);i.warn(`[@visulima/notification] send failed via "${r.provider}": ${a}`)}return e}};export{s as loggingMiddleware};
@@ -1 +0,0 @@
1
- import t from"./NotificationError-B1ZZqWxL.js";import g from"./RequiredOptionError-CH4g-BZM.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-BbxkOLQm.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 +0,0 @@
1
- import c from"./NotificationError-B1ZZqWxL.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 +0,0 @@
1
- import r from"./NotificationError-B1ZZqWxL.js";import m from"./RequiredOptionError-CH4g-BZM.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};
@@ -1 +0,0 @@
1
- const i="notification.send",a=(e,o={})=>{const{tracer:t}=o;return{...e,send:async s=>{if(!t)return e.send(s);const n=t.startSpan(i,{attributes:{"notification.channel":e.channel,"notification.provider":e.id}});try{const r=await e.send(s);if(!r.success){const c=r.error instanceof Error?r.error.message:String(r.error);n.setStatus({code:2,message:c})}return r}catch(r){throw n.recordException(r),n.setStatus({code:2,message:r instanceof Error?r.message:String(r)}),r}finally{n.end()}}}};export{a as otelProvider};
@@ -1 +0,0 @@
1
- import o from"./NotificationError-B1ZZqWxL.js";import d from"./RequiredOptionError-CH4g-BZM.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-BbxkOLQm.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 +0,0 @@
1
- const c=async t=>new Promise(e=>{setTimeout(e,t)}),l=t=>{const e=t.interval??1e3,a=Math.max(1,t.rate);let n=a,i=Date.now();const s=()=>{const o=Date.now(),r=o-i;n=Math.min(a,n+r/e*a),i=o};return async(o,r)=>{for(s();n<1;)await c(Math.ceil(e/a)),s();return n-=1,r(o)}};export{l as rateLimitMiddleware};
@@ -1 +0,0 @@
1
- const l=async r=>new Promise(e=>{setTimeout(e,r)}),c=(r={})=>{const e=r.retries??3,s=r.baseDelay??250;return async(o,n)=>{let t=await n(o);for(let a=0;a<e&&!t.success&&!(r.shouldRetry&&!r.shouldRetry(t.error));a+=1)await l(s*2**a+Math.floor(Math.random()*s)),t=await n(o);return t}};export{c as retryMiddleware};
@@ -1 +0,0 @@
1
- import c from"./NotificationError-B1ZZqWxL.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 +0,0 @@
1
- import{isWithinReplayWindow as o,REPLAY_WINDOW_SECONDS as c,hmacHex as l,timingSafeEqual as m}from"./hmacBase64-CNksyDoB.js";import{getHeader as a,tryParseObject as p}from"./getHeader-C_gkdnMQ.js";const d="X-Slack-Signature",f="X-Slack-Request-Timestamp",y={parse:r=>{const e=p(r);if(e===void 0)return;const t=e.event??e,n=typeof t.channel=="string"?t.channel:void 0,i=typeof t.ts=="string"?t.ts:"";return{channel:"chat",messageId:typeof e.event_id=="string"?e.event_id:i,provider:"slack",recipient:n,timestamp:new Date,type:"delivered"}},verify:async(r,e,t)=>{if(t.trim()==="")return!1;const n=a(e,d),i=a(e,f);if(n===void 0||i===void 0||!o(i,c))return!1;const s=await l(t,`v0:${i}:${r}`,"SHA-256");return m(`v0=${s}`,n)}};export{y as slackWebhook};
@@ -1,4 +0,0 @@
1
- import x from"./RequiredOptionError-CH4g-BZM.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-BbxkOLQm.js";import{a as w,g as h,u as c,i as p}from"./webcrypto-CFuQmh5-.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,A]of Object.entries(a))n[l.toLowerCase()]=A.trim();const s=Object.keys(n).toSorted((l,A)=>l.localeCompare(A)),u=s.join(";"),y=s.map(l=>`${l}:${n[l]??""}
2
- `).join(""),r=["POST",k(i),"",y,u,f].join(`
3
- `),g=`${S}/${e}/${b}/aws4_request`,$=["AWS4-HMAC-SHA256",d,g,w(await h(c(r)))].join(`
4
- `),I=await O(t.secretAccessKey,S,e),M=w(await p(I,c($)));return a.Authorization=`AWS4-HMAC-SHA256 Credential=${t.accessKeyId}/${g}, 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 g=q.exec(r.data.body)?.[1];return{id:a,messageId:g??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 +0,0 @@
1
- import{tryParseObject as t}from"./getHeader-C_gkdnMQ.js";const i=s=>t(s),a={parse:s=>{const e=i(s);if(e?.Type===void 0)return;const r={type:e.Type};return e.Type==="SubscriptionConfirmation"||e.Type==="UnsubscribeConfirmation"?r.subscribeUrl=e.SubscribeURL:e.Message!==void 0&&(r.message=e.Message),{messageId:e.MessageId??"",metadata:r,provider:"sns",timestamp:e.Timestamp===void 0?new Date:new Date(e.Timestamp),type:"delivered"}},verify:()=>Promise.resolve(!1)};export{a as snsWebhook};
@@ -1 +0,0 @@
1
- import{isWithinReplayWindow as m,REPLAY_WINDOW_SECONDS as v,hmacBase64 as w,hmacHex as y,timingSafeEqual as p}from"./hmacBase64-CNksyDoB.js";import{getHeader as s,tryParseObject as g}from"./getHeader-C_gkdnMQ.js";const b="webhook-id",k="webhook-timestamp",A="webhook-signature",S=new Set(["bounced","clicked","delivered","failed","interacted","queued","read","sent"]),W=r=>{const e=atob(r),t=new Uint8Array(e.length);for(let i=0;i<e.length;i+=1)t[i]=e.codePointAt(i)??0;return t},D={parse:r=>{const e=g(r);if(e===void 0)return;const t=typeof e.type=="string"?e.type:void 0,i=t!==void 0&&S.has(t)?t:"delivered";return{messageId:typeof e.id=="string"?e.id:"",provider:"standard-webhooks",recipient:typeof e.recipient=="string"?e.recipient:void 0,timestamp:new Date,type:i}},verify:async(r,e,t)=>{if(t.trim()==="")return!1;const i=s(e,b),o=s(e,k),a=s(e,A);if(i===void 0||o===void 0||a===void 0||!m(o,v))return!1;const d=t.startsWith("whsec_")?W(t.slice(6)):t,c=`${i}.${o}.${r}`,l=await w(d,c,"SHA-256"),u=await y(d,c,"SHA-256"),h=a.split(" ");for(const n of h){const f=n.includes(",")?n.split(",")[1]??"":n;if(p(l,f)||p(u,f))return!0}return!1}};export{D as standardWebhook};
@@ -1 +0,0 @@
1
- const i=e=>typeof e=="string"?e:JSON.stringify(e),n=e=>{const{to:r}=e;if(r!=null)return Array.isArray(r)?r.map(s=>i(s)).join(","):i(r)},o=e=>{const r=e.resolveRecipient??n;return async(s,a)=>{const t=r(s.payload);return t===void 0?a(s):await e.isSuppressed(t,s.channel)?{data:{channel:s.channel,messageId:`suppressed:${t}`,provider:s.provider,sent:!1,timestamp:new Date},success:!0}:a(s)}};export{o as suppressionMiddleware};
@@ -1 +0,0 @@
1
- import r from"./NotificationError-B1ZZqWxL.js";import m from"./RequiredOptionError-CH4g-BZM.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 +0,0 @@
1
- const l="notification.send",p=(d={})=>{const{meter:n,tracer:u}=d;let i,r;return n&&(i=n.createCounter("notification.send.count",{description:"Number of notification send attempts"}),r=n.createHistogram("notification.send.duration",{description:"Notification send duration in milliseconds",unit:"ms"})),async(c,f)=>{const o={"notification.channel":c.channel,"notification.provider":c.provider},e=u?.startSpan(l,{attributes:o}),s=Date.now();try{const t=await f(c),a=t.success?"success":"failure";if(!t.success&&e){const m=t.error instanceof Error?t.error.message:String(t.error);e.setStatus({code:2,message:m})}return i?.add(1,{...o,"notification.outcome":a}),r?.record(Date.now()-s,{...o,"notification.outcome":a}),t}catch(t){throw e&&(e.recordException(t),e.setStatus({code:2,message:t instanceof Error?t.message:String(t)})),i?.add(1,{...o,"notification.outcome":"error"}),r?.record(Date.now()-s,{...o,"notification.outcome":"error"}),t}finally{e?.end()}}};export{p as telemetryMiddleware};
@@ -1 +0,0 @@
1
- import u from"./RequiredOptionError-CH4g-BZM.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-BbxkOLQm.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};
@@ -1 +0,0 @@
1
- import n from"./RequiredOptionError-CH4g-BZM.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-BbxkOLQm.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 +0,0 @@
1
- import{hmacBase64 as u,timingSafeEqual as c}from"./hmacBase64-CNksyDoB.js";import{getHeader as s}from"./getHeader-C_gkdnMQ.js";const f="X-Twilio-Signature",m={delivered:"delivered",failed:"failed",queued:"queued",sending:"queued",sent:"sent",undelivered:"failed"},S=(r,e)=>{const i=Object.keys(e).toSorted();let t=r;for(const o of i)t+=`${o}${e[o]??""}`;return t},a=r=>{const e={};return new URLSearchParams(r).forEach((i,t)=>{e[t]=i}),e},p={parse:r=>{const e=a(r),i=e.MessageStatus??e.SmsStatus??e.CallStatus;if(i===void 0)return;const t=m[i.toLowerCase()];return t===void 0?void 0:{channel:"sms",messageId:e.MessageSid??e.SmsSid??e.CallSid??"",provider:"twilio",recipient:e.To,timestamp:new Date,type:t}},verify:async(r,e,i)=>{if(i.trim()==="")return!1;const t=s(e,f),o=s(e,"x-twilio-signature-url");if(t===void 0||o===void 0)return!1;const n=a(r),d=S(o,n),l=await u(i,d,"SHA-1");return c(l,t)}};export{p as twilioWebhook};
@@ -1 +0,0 @@
1
- import n from"./RequiredOptionError-CH4g-BZM.js";import{defineProvider as l}from"./defineProvider-C9q-7iwt.js";import{t as g}from"./credentials-CG0zkn-W.js";import{r as y}from"./http-DT3tyixg.js";import{s as v,b as w}from"./sms-BbxkOLQm.js";const S="https://rest.nexmo.com",P=l(d=>{const e=d??{};if(!e.apiKey)throw new n("vonage","apiKey");if(!e.apiSecret)throw new n("vonage","apiSecret");const o=e.endpoint??S,p=e.retries??3,c=e.timeout??3e4,m=`${o}/sms/json`,f=async(t,a)=>{const s=a.from??e.from;if(!s)return{error:"Missing sender: provide `from` on the payload or provider config",id:t,status:"failed"};const u=new URLSearchParams({api_key:e.apiKey,api_secret:e.apiSecret,from:s,text:a.text,to:t}),r=await y(m,{body:u.toString(),headers:{"Content-Type":"application/x-www-form-urlencoded"},method:"POST",timeout:c},p);if(!r.success||!r.data)return{error:r.error instanceof Error?r.error.message:"Request failed",id:t,status:"failed"};const i=r.data.body.messages?.[0];return i?.status!=="0"?{error:i?.["error-text"]??`Vonage status ${i?.status??"unknown"}`,id:t,status:"failed"}:{id:t,messageId:i["message-id"],status:"sent"}};return{channel:"sms",endpoint:o,features:{batchSending:!1,deliveryReceipts:!0,media:!1},id:"vonage",initialize:()=>{},isAvailable:()=>!!(e.apiKey&&e.apiSecret),options:e,send:async t=>{const a=await v(g(t.to),async s=>f(s,t));return w("vonage",a)},validateCredentials:()=>!!(e.apiKey&&e.apiSecret)}});export{P as default};
@@ -1 +0,0 @@
1
- import K from"./RequiredOptionError-CH4g-BZM.js";import{defineProvider as C}from"./defineProvider-C9q-7iwt.js";import{t as A}from"./credentials-CG0zkn-W.js";import{m as E}from"./http-DT3tyixg.js";import{n as U}from"./id-C_FRCsUM.js";import{a as $}from"./sms-BbxkOLQm.js";import{u as y,f as S,b as f,s as d,r as k,c as g,d as P,e as T}from"./webcrypto-CFuQmh5-.js";const j=2419200,x=i=>{let e=i;if(typeof i=="string")try{e=JSON.parse(i)}catch{return}const t=e;if(!(!t||typeof t.endpoint!="string"||typeof t.keys?.p256dh!="string"||typeof t.keys.auth!="string"))return t},B=async(i,e)=>{const t=S(e),p=f(t.slice(1,33)),r=f(t.slice(33,65));return d().importKey("jwk",{crv:"P-256",d:i,ext:!0,key_ops:["sign"],kty:"EC",x:p,y:r},{name:"ECDSA",namedCurve:"P-256"},!1,["sign"])},D=async(i,e,t)=>{const p=f(y(JSON.stringify({alg:"ES256",typ:"JWT"}))),r=f(y(JSON.stringify({aud:i,exp:Math.floor(Date.now()/1e3)+720*60,sub:e}))),u=`${p}.${r}`,a=await d().sign({hash:"SHA-256",name:"ECDSA"},t,y(u));return`${u}.${f(new Uint8Array(a))}`},H=async(i,e)=>{const t=S(i.keys.p256dh),p=S(i.keys.auth),r=k(16),u=await d().generateKey({name:"ECDH",namedCurve:"P-256"},!0,["deriveBits"]),a=new Uint8Array(await d().exportKey("raw",u.publicKey)),n=await d().importKey("raw",t,{name:"ECDH",namedCurve:"P-256"},!1,[]),m=new Uint8Array(await d().deriveBits({name:"ECDH",public:n},u.privateKey,256)),s=g(y("WebPush: info\0"),t,a),l=await P(p,m,s,32),b=await P(r,l,y("Content-Encoding: aes128gcm\0"),16),v=await P(r,l,y("Content-Encoding: nonce\0"),12),w=await d().importKey("raw",b,{name:"AES-GCM"},!1,["encrypt"]),h=g(e,new Uint8Array([2])),o=new Uint8Array(await d().encrypt({iv:v,name:"AES-GCM"},w,h)),c=g(r,T(4096,4),new Uint8Array([a.length]),a);return g(c,o)},z=C(i=>{const e=i??{};if(!e.vapidPublicKey||!e.vapidPrivateKey||!e.vapidSubject)throw new K("web-push",["vapidPublicKey","vapidPrivateKey","vapidSubject"]);const t=e.ttl??j,p=e.urgency??"normal",r=e.timeout??3e4,u=async(a,n,m)=>{const s=x(a);if(!s)return{error:"Invalid push subscription (expected { endpoint, keys: { p256dh, auth } })",id:a,status:"failed"};const{origin:l}=new URL(s.endpoint),b=await D(l,e.vapidSubject,m),v=JSON.stringify({badge:n.badge,body:n.body,data:n.data,image:n.imageUrl,title:n.title}),w=await H(s,y(v)),h={Authorization:`vapid t=${b},k=${e.vapidPublicKey}`,"Content-Encoding":"aes128gcm","Content-Type":"application/octet-stream",TTL:String(t),Urgency:p},o=await E(s.endpoint,{body:w,headers:h,method:"POST",timeout:r});if(!o.success||!o.data)return{error:o.error instanceof Error?o.error.message:"Request failed",id:a,status:"failed"};const{status:c}=o.data;return c===404||c===410?{error:`Subscription gone (HTTP ${String(c)}) — remove this subscription`,id:a,status:"failed"}:c>=400?{error:`HTTP ${String(c)}: ${typeof o.data.body=="string"?o.data.body:""}`.trim(),id:a,status:"failed"}:{id:a,messageId:U("web-push"),status:"sent"}};return{channel:"push",features:{batchSending:!1,media:!1,richContent:!0},id:"web-push",initialize:()=>{},isAvailable:()=>!!(e.vapidPublicKey&&e.vapidPrivateKey&&e.vapidSubject),options:e,send:async a=>{const n=A(a.to),m=await B(e.vapidPrivateKey,e.vapidPublicKey),s=[];for(const l of n)s.push(await u(l,a,m));return $("push","web-push",s)},validateCredentials:()=>!!(e.vapidPublicKey&&e.vapidPrivateKey&&e.vapidSubject)}});export{z as default};
@@ -1 +0,0 @@
1
- const l=r=>new Uint8Array(new ArrayBuffer(r)),i=r=>{if(r.buffer instanceof ArrayBuffer)return r;const t=l(r.length);return t.set(r),t},o=()=>globalThis.crypto.subtle,u=r=>{const t=l(r);return globalThis.crypto.getRandomValues(t),t},c=r=>{const t=new TextEncoder().encode(r),e=l(t.length);return e.set(t),e},y=(...r)=>{let t=0;for(const a of r)t+=a.length;const e=l(t);let n=0;for(const a of r)e.set(a,n),n+=a.length;return e},g=r=>{let t="";for(const e of r)t+=e.toString(16).padStart(2,"0");return t},h=r=>{let t="";for(const e of r)t+=String.fromCodePoint(e);return btoa(t)},A=r=>{let t=h(r).replaceAll("+","-").replaceAll("/","_");for(;t.endsWith("=");)t=t.slice(0,-1);return t},w=r=>{const t=r.replaceAll("-","+").replaceAll("_","/"),e=t.padEnd(t.length+(4-t.length%4)%4,"="),n=atob(e),a=l(n.length);for(let s=0;s<n.length;s+=1)a[s]=n.codePointAt(s)??0;return a},d=(r,t)=>{const e=l(t);let n=r;for(let a=t-1;a>=0;a-=1)e[a]=n%256,n=Math.floor(n/256);return e},p=async r=>{const t=await o().digest("SHA-256",r);return new Uint8Array(t)},m=async(r,t)=>{const e=await o().importKey("raw",r,{hash:"SHA-256",name:"HMAC"},!1,["sign"]),n=await o().sign("HMAC",e,t);return new Uint8Array(n)},B=async(r,t,e)=>{const n=typeof r=="string"?c(r):i(r),a=typeof t=="string"?c(t):i(t),s=await o().importKey("raw",n,{hash:e,name:"HMAC"},!1,["sign"]),f=await o().sign("HMAC",s,a);return new Uint8Array(f)},H=async(r,t,e,n)=>{const a=await o().importKey("raw",t,"HKDF",!1,["deriveBits"]),s=await o().deriveBits({hash:"SHA-256",info:e,name:"HKDF",salt:r},a,n*8);return new Uint8Array(s)};export{g as a,A as b,y as c,H as d,d as e,w as f,p as g,B as h,m as i,u as r,o as s,h as t,c as u};
@@ -1 +0,0 @@
1
- import s from"./NotificationError-B1ZZqWxL.js";import i from"./RequiredOptionError-CH4g-BZM.js";import{r as d}from"./http-DT3tyixg.js";import{n as u}from"./id-C_FRCsUM.js";const l=(t={})=>{const a=t.retries??3,n=t.timeout??3e4;return{channel:"webhook",endpoint:t.url,features:{},id:"webhook",initialize:()=>{},isAvailable:()=>!0,send:async o=>{const r=o.url??t.url;if(!r)return{error:new i("webhook","url"),success:!1};const e=await d(r,{body:typeof o.body=="string"?o.body:JSON.stringify(o.body),headers:{"Content-Type":"application/json",...t.headers,...o.headers},method:o.method??t.method??"POST",timeout:n},a);return!e.success||!e.data?{error:new s("webhook",e.error instanceof Error?e.error.message:"Request failed"),success:!1}:e.data.status>=400?{error:new s("webhook",`HTTP ${String(e.data.status)}`),success:!1}:{data:{channel:"webhook",messageId:u("webhook"),provider:"webhook",response:e.data.body,sent:!0,timestamp:new Date},success:!0}}}};export{l as webhookProvider};