@vicacha-devs/medusa-plugin-notifications 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (241) hide show
  1. package/.medusa/server/src/admin/index.cjs +4215 -0
  2. package/.medusa/server/src/admin/index.js +4193 -0
  3. package/.medusa/server/src/api/admin/mpn/broadcasts/route.js +99 -0
  4. package/.medusa/server/src/api/admin/mpn/channels/route.js +109 -0
  5. package/.medusa/server/src/api/admin/mpn/logs/route.js +33 -0
  6. package/.medusa/server/src/api/admin/mpn/mappings/[id]/route.js +33 -0
  7. package/.medusa/server/src/api/admin/mpn/mappings/route.js +51 -0
  8. package/.medusa/server/src/api/admin/mpn/render-template/route.js +37 -0
  9. package/.medusa/server/src/api/admin/mpn/sandbox/route.js +36 -0
  10. package/.medusa/server/src/api/admin/mpn/send/route.js +135 -0
  11. package/.medusa/server/src/api/admin/mpn/templates/[id]/route.js +77 -0
  12. package/.medusa/server/src/api/admin/mpn/templates/route.js +71 -0
  13. package/.medusa/server/src/api/admin/plugin/route.js +4 -0
  14. package/.medusa/server/src/api/middlewares.js +28 -0
  15. package/.medusa/server/src/api/store/mpn/consent/route.js +37 -0
  16. package/.medusa/server/src/api/store/mpn/webhooks/[provider]/route.js +97 -0
  17. package/.medusa/server/src/api/store/plugin/route.js +4 -0
  18. package/.medusa/server/src/api/validators.js +118 -0
  19. package/.medusa/server/src/hooks/index.js +7 -0
  20. package/.medusa/server/src/hooks/use-mpn-channels.js +13 -0
  21. package/.medusa/server/src/hooks/use-mpn-dispatch.js +45 -0
  22. package/.medusa/server/src/hooks/use-mpn-mappings.js +21 -0
  23. package/.medusa/server/src/hooks/use-mpn-templates.js +34 -0
  24. package/.medusa/server/src/hooks/use-order-notifications-widget-state.js +79 -0
  25. package/.medusa/server/src/hooks/use-sdk-primitives.js +113 -0
  26. package/.medusa/server/src/index.js +14 -0
  27. package/.medusa/server/src/integrations/automations-action-handler.js +112 -0
  28. package/.medusa/server/src/jobs/abandoned-cart-recovery.js +123 -0
  29. package/.medusa/server/src/jobs/log-retention-and-broadcasts.js +15 -0
  30. package/.medusa/server/src/modules/notifications/i18n/index.js +65 -0
  31. package/.medusa/server/src/modules/notifications/i18n/locales/ar.js +76 -0
  32. package/.medusa/server/src/modules/notifications/i18n/locales/de.js +76 -0
  33. package/.medusa/server/src/modules/notifications/i18n/locales/en.js +76 -0
  34. package/.medusa/server/src/modules/notifications/i18n/locales/es.js +76 -0
  35. package/.medusa/server/src/modules/notifications/i18n/locales/fr.js +76 -0
  36. package/.medusa/server/src/modules/notifications/i18n/locales/it.js +76 -0
  37. package/.medusa/server/src/modules/notifications/i18n/locales/nl.js +76 -0
  38. package/.medusa/server/src/modules/notifications/i18n/locales/pl.js +76 -0
  39. package/.medusa/server/src/modules/notifications/i18n/locales/pt.js +76 -0
  40. package/.medusa/server/src/modules/notifications/i18n/locales/tr.js +76 -0
  41. package/.medusa/server/src/modules/notifications/i18n/types.js +2 -0
  42. package/.medusa/server/src/modules/notifications/index.js +9 -0
  43. package/.medusa/server/src/modules/notifications/integrations/documents-and-b2b-resolver.js +129 -0
  44. package/.medusa/server/src/modules/notifications/migrations/Migration20261010000000.js +184 -0
  45. package/.medusa/server/src/modules/notifications/models/index.js +118 -0
  46. package/.medusa/server/src/modules/notifications/renderer/block-helpers.js +36 -0
  47. package/.medusa/server/src/modules/notifications/renderer/email.js +161 -0
  48. package/.medusa/server/src/modules/notifications/renderer/index.js +240 -0
  49. package/.medusa/server/src/modules/notifications/renderer/slack.js +114 -0
  50. package/.medusa/server/src/modules/notifications/renderer/telegram.js +99 -0
  51. package/.medusa/server/src/modules/notifications/renderer/whatsapp.js +91 -0
  52. package/.medusa/server/src/modules/notifications/service-helpers/channel-config.js +45 -0
  53. package/.medusa/server/src/modules/notifications/service-helpers/consent.js +65 -0
  54. package/.medusa/server/src/modules/notifications/service-helpers/delivery-log.js +29 -0
  55. package/.medusa/server/src/modules/notifications/service-helpers/event-conditions.js +46 -0
  56. package/.medusa/server/src/modules/notifications/service-helpers/external-templates.js +80 -0
  57. package/.medusa/server/src/modules/notifications/service-helpers/recipient-resolution.js +85 -0
  58. package/.medusa/server/src/modules/notifications/service-helpers/sender-profiles.js +29 -0
  59. package/.medusa/server/src/modules/notifications/service-helpers/template-blocks.js +81 -0
  60. package/.medusa/server/src/modules/notifications/service-helpers/template-catalog.js +129 -0
  61. package/.medusa/server/src/modules/notifications/service-helpers/template-render.js +65 -0
  62. package/.medusa/server/src/modules/notifications/service.js +339 -0
  63. package/.medusa/server/src/modules/notifications/types.js +2 -0
  64. package/.medusa/server/src/modules/notifications/utils/auth-presets.js +140 -0
  65. package/.medusa/server/src/modules/notifications/utils/interpolation.js +178 -0
  66. package/.medusa/server/src/modules/notifications/utils/security.js +312 -0
  67. package/.medusa/server/src/modules/notifications/utils/system-presets.js +651 -0
  68. package/.medusa/server/src/modules/notifications/utils/transformers.js +358 -0
  69. package/.medusa/server/src/providers/dummy-sandbox/index.js +96 -0
  70. package/.medusa/server/src/providers/email-smtp/index.js +187 -0
  71. package/.medusa/server/src/providers/index.js +7 -0
  72. package/.medusa/server/src/providers/slack/index.js +54 -0
  73. package/.medusa/server/src/providers/sms/index.js +254 -0
  74. package/.medusa/server/src/providers/telegram/index.js +119 -0
  75. package/.medusa/server/src/providers/whatsapp/index.js +371 -0
  76. package/.medusa/server/src/rbac.js +109 -0
  77. package/.medusa/server/src/sdk/client.js +186 -0
  78. package/.medusa/server/src/sdk/index.js +3 -0
  79. package/.medusa/server/src/sdk/query-keys.js +61 -0
  80. package/.medusa/server/src/subscribers/customer-and-document-events.js +33 -0
  81. package/.medusa/server/src/subscribers/fulfillment-and-inventory-events.js +30 -0
  82. package/.medusa/server/src/subscribers/order-events.js +28 -0
  83. package/.medusa/server/src/types/constants.js +129 -0
  84. package/.medusa/server/src/types/core.js +2 -0
  85. package/.medusa/server/src/types/domain.js +2 -0
  86. package/.medusa/server/src/types/enums.js +53 -0
  87. package/.medusa/server/src/types/errors.js +28 -0
  88. package/.medusa/server/src/types/hooks.js +2 -0
  89. package/.medusa/server/src/types/index.js +12 -0
  90. package/.medusa/server/src/types/providers.js +2 -0
  91. package/.medusa/server/src/types/records.js +2 -0
  92. package/.medusa/server/src/types/render.js +2 -0
  93. package/.medusa/server/src/types/sdk-api.js +2 -0
  94. package/.medusa/server/src/types/translations.js +2 -0
  95. package/.medusa/server/src/workflows/index.js +461 -0
  96. package/LICENSE +21 -0
  97. package/README.md +389 -2
  98. package/package.json +138 -3
  99. package/src/admin/README.md +123 -0
  100. package/src/admin/components/mpn/broadcast-consent-section.tsx +62 -0
  101. package/src/admin/components/mpn/broadcasts-tab.tsx +208 -0
  102. package/src/admin/components/mpn/channels-main-section.tsx +205 -0
  103. package/src/admin/components/mpn/channels-side-section.tsx +88 -0
  104. package/src/admin/components/mpn/channels-tab.tsx +130 -0
  105. package/src/admin/components/mpn/constants.ts +8 -0
  106. package/src/admin/components/mpn/delivery-logs-tab.tsx +70 -0
  107. package/src/admin/components/mpn/event-mapping-form.tsx +191 -0
  108. package/src/admin/components/mpn/event-mappings-tab.tsx +165 -0
  109. package/src/admin/components/mpn/header-bar.tsx +35 -0
  110. package/src/admin/components/mpn/index.ts +17 -0
  111. package/src/admin/components/mpn/overview-cards.tsx +103 -0
  112. package/src/admin/components/mpn/sandbox-tab.tsx +93 -0
  113. package/src/admin/components/mpn/template-editor-section.tsx +203 -0
  114. package/src/admin/components/mpn/template-preview-section.tsx +122 -0
  115. package/src/admin/components/mpn/templates-list-section.tsx +115 -0
  116. package/src/admin/components/mpn/templates-tab.tsx +188 -0
  117. package/src/admin/components/mpn/use-notification-studio.ts +84 -0
  118. package/src/admin/components/rbac-guard.tsx +153 -0
  119. package/src/admin/i18n/README.md +134 -0
  120. package/src/admin/i18n/index.ts +23 -0
  121. package/src/admin/i18n/json/ar.json +157 -0
  122. package/src/admin/i18n/json/de.json +157 -0
  123. package/src/admin/i18n/json/en.json +157 -0
  124. package/src/admin/i18n/json/es.json +157 -0
  125. package/src/admin/i18n/json/fr.json +157 -0
  126. package/src/admin/i18n/json/it.json +157 -0
  127. package/src/admin/i18n/json/nl.json +157 -0
  128. package/src/admin/i18n/json/pl.json +157 -0
  129. package/src/admin/i18n/json/pt.json +157 -0
  130. package/src/admin/i18n/json/tr.json +157 -0
  131. package/src/admin/routes/mpn/broadcasts/page.tsx +75 -0
  132. package/src/admin/routes/mpn/channels/page.tsx +66 -0
  133. package/src/admin/routes/mpn/logs/page.tsx +50 -0
  134. package/src/admin/routes/mpn/mappings/page.tsx +62 -0
  135. package/src/admin/routes/mpn/page.tsx +200 -0
  136. package/src/admin/routes/mpn/sandbox/page.tsx +53 -0
  137. package/src/admin/routes/mpn/templates/page.tsx +55 -0
  138. package/src/admin/tsconfig.json +23 -0
  139. package/src/admin/vite-env.d.ts +1 -0
  140. package/src/admin/widgets/order-notifications-widget.tsx +178 -0
  141. package/src/api/README.md +98 -0
  142. package/src/api/admin/mpn/broadcasts/route.ts +130 -0
  143. package/src/api/admin/mpn/channels/route.ts +143 -0
  144. package/src/api/admin/mpn/logs/route.ts +41 -0
  145. package/src/api/admin/mpn/mappings/[id]/route.ts +45 -0
  146. package/src/api/admin/mpn/mappings/route.ts +68 -0
  147. package/src/api/admin/mpn/render-template/route.ts +46 -0
  148. package/src/api/admin/mpn/sandbox/route.ts +51 -0
  149. package/src/api/admin/mpn/send/route.ts +163 -0
  150. package/src/api/admin/mpn/templates/[id]/route.ts +101 -0
  151. package/src/api/admin/mpn/templates/route.ts +99 -0
  152. package/src/api/admin/plugin/route.ts +5 -0
  153. package/src/api/middlewares.ts +42 -0
  154. package/src/api/store/mpn/consent/route.ts +45 -0
  155. package/src/api/store/mpn/webhooks/[provider]/route.ts +119 -0
  156. package/src/api/store/plugin/route.ts +5 -0
  157. package/src/api/validators.ts +149 -0
  158. package/src/hooks/index.ts +14 -0
  159. package/src/hooks/use-mpn-channels.ts +43 -0
  160. package/src/hooks/use-mpn-dispatch.ts +149 -0
  161. package/src/hooks/use-mpn-mappings.ts +75 -0
  162. package/src/hooks/use-mpn-templates.ts +120 -0
  163. package/src/hooks/use-order-notifications-widget-state.ts +103 -0
  164. package/src/hooks/use-sdk-primitives.ts +157 -0
  165. package/src/index.ts +16 -0
  166. package/src/integrations/automations-action-handler.ts +156 -0
  167. package/src/jobs/README.md +41 -0
  168. package/src/jobs/abandoned-cart-recovery.ts +152 -0
  169. package/src/jobs/log-retention-and-broadcasts.ts +23 -0
  170. package/src/links/README.md +52 -0
  171. package/src/modules/README.md +99 -0
  172. package/src/modules/notifications/i18n/index.ts +83 -0
  173. package/src/modules/notifications/i18n/locales/ar.ts +84 -0
  174. package/src/modules/notifications/i18n/locales/de.ts +83 -0
  175. package/src/modules/notifications/i18n/locales/en.ts +84 -0
  176. package/src/modules/notifications/i18n/locales/es.ts +84 -0
  177. package/src/modules/notifications/i18n/locales/fr.ts +82 -0
  178. package/src/modules/notifications/i18n/locales/it.ts +82 -0
  179. package/src/modules/notifications/i18n/locales/nl.ts +83 -0
  180. package/src/modules/notifications/i18n/locales/pl.ts +84 -0
  181. package/src/modules/notifications/i18n/locales/pt.ts +82 -0
  182. package/src/modules/notifications/i18n/locales/tr.ts +86 -0
  183. package/src/modules/notifications/i18n/types.ts +1 -0
  184. package/src/modules/notifications/index.ts +10 -0
  185. package/src/modules/notifications/integrations/documents-and-b2b-resolver.ts +168 -0
  186. package/src/modules/notifications/migrations/Migration20261010000000.ts +185 -0
  187. package/src/modules/notifications/models/index.ts +125 -0
  188. package/src/modules/notifications/renderer/block-helpers.ts +51 -0
  189. package/src/modules/notifications/renderer/email.ts +281 -0
  190. package/src/modules/notifications/renderer/index.ts +301 -0
  191. package/src/modules/notifications/renderer/slack.ts +168 -0
  192. package/src/modules/notifications/renderer/telegram.ts +161 -0
  193. package/src/modules/notifications/renderer/whatsapp.ts +156 -0
  194. package/src/modules/notifications/service-helpers/channel-config.ts +65 -0
  195. package/src/modules/notifications/service-helpers/consent.ts +88 -0
  196. package/src/modules/notifications/service-helpers/delivery-log.ts +56 -0
  197. package/src/modules/notifications/service-helpers/event-conditions.ts +66 -0
  198. package/src/modules/notifications/service-helpers/external-templates.ts +127 -0
  199. package/src/modules/notifications/service-helpers/recipient-resolution.ts +124 -0
  200. package/src/modules/notifications/service-helpers/sender-profiles.ts +34 -0
  201. package/src/modules/notifications/service-helpers/template-blocks.ts +116 -0
  202. package/src/modules/notifications/service-helpers/template-catalog.ts +170 -0
  203. package/src/modules/notifications/service-helpers/template-render.ts +113 -0
  204. package/src/modules/notifications/service.ts +588 -0
  205. package/src/modules/notifications/types.ts +1 -0
  206. package/src/modules/notifications/utils/auth-presets.ts +145 -0
  207. package/src/modules/notifications/utils/interpolation.ts +231 -0
  208. package/src/modules/notifications/utils/security.ts +378 -0
  209. package/src/modules/notifications/utils/system-presets.ts +695 -0
  210. package/src/modules/notifications/utils/transformers.ts +456 -0
  211. package/src/providers/README.md +92 -0
  212. package/src/providers/dummy-sandbox/index.ts +143 -0
  213. package/src/providers/email-smtp/index.ts +257 -0
  214. package/src/providers/index.ts +38 -0
  215. package/src/providers/slack/index.ts +82 -0
  216. package/src/providers/sms/index.ts +342 -0
  217. package/src/providers/telegram/index.ts +181 -0
  218. package/src/providers/whatsapp/index.ts +505 -0
  219. package/src/rbac.ts +123 -0
  220. package/src/sdk/client.ts +319 -0
  221. package/src/sdk/index.ts +48 -0
  222. package/src/sdk/query-keys.ts +89 -0
  223. package/src/subscribers/README.md +50 -0
  224. package/src/subscribers/customer-and-document-events.ts +36 -0
  225. package/src/subscribers/fulfillment-and-inventory-events.ts +35 -0
  226. package/src/subscribers/order-events.ts +31 -0
  227. package/src/types/constants.ts +143 -0
  228. package/src/types/core.ts +96 -0
  229. package/src/types/domain.ts +84 -0
  230. package/src/types/enums.ts +73 -0
  231. package/src/types/errors.ts +32 -0
  232. package/src/types/hooks.ts +48 -0
  233. package/src/types/index.ts +11 -0
  234. package/src/types/providers.ts +96 -0
  235. package/src/types/records.ts +100 -0
  236. package/src/types/render.ts +74 -0
  237. package/src/types/sdk-api.ts +228 -0
  238. package/src/types/translations.ts +75 -0
  239. package/src/workflows/README.md +67 -0
  240. package/src/workflows/index.ts +619 -0
  241. package/tsconfig.json +40 -0
@@ -0,0 +1,143 @@
1
+ export const NOTIFICATIONS_MODULE = "notificationsModuleService"
2
+
3
+ export const NOTIFICATION_CHANNELS = [
4
+ "email",
5
+ "whatsapp",
6
+ "telegram",
7
+ "sms",
8
+ "slack",
9
+ "dummy",
10
+ ] as const
11
+
12
+ export const CHANNELS = NOTIFICATION_CHANNELS
13
+
14
+ export const TEMPLATE_MODES = ["blocks", "raw"] as const
15
+
16
+ export const TEMPLATE_SOURCES = ["system", "db", "external"] as const
17
+
18
+ export const BLOCK_TYPES = [
19
+ "section",
20
+ "heading",
21
+ "text",
22
+ "row",
23
+ "separator",
24
+ "group",
25
+ "repeater",
26
+ "product-item",
27
+ "button",
28
+ "actions",
29
+ "divider",
30
+ "attachment",
31
+ ] as const
32
+
33
+ export const WHATSAPP_DRIVERS = [
34
+ "meta-cloud",
35
+ "openwa",
36
+ "waha",
37
+ "evolution",
38
+ ] as const
39
+
40
+ export const SMS_DRIVERS = [
41
+ "twilio",
42
+ "signalhouse",
43
+ "msg91",
44
+ "smsapi",
45
+ "webhook",
46
+ "dummy",
47
+ ] as const
48
+
49
+ export const RECIPIENT_RULES = [
50
+ "customer_auto",
51
+ "order_email",
52
+ "customer_email",
53
+ "order_phone",
54
+ "customer_phone",
55
+ "customer_telegram",
56
+ "merchant_channel",
57
+ "b2b_accounting_contact",
58
+ "custom_recipient",
59
+ ] as const
60
+
61
+ export const DELIVERY_STATUSES = [
62
+ "pending",
63
+ "sent",
64
+ "delivered",
65
+ "failed",
66
+ "skipped_idempotent",
67
+ "skipped_no_consent",
68
+ "rate_limited_delayed",
69
+ ] as const
70
+
71
+ export const CONSENT_STATUSES = ["opted_in", "opted_out", "pending"] as const
72
+
73
+ export const BROADCAST_STATUSES = [
74
+ "draft",
75
+ "scheduled",
76
+ "sending",
77
+ "completed",
78
+ "canceled",
79
+ ] as const
80
+
81
+ export const SUPPORTED_LOCALES = [
82
+ "en",
83
+ "es",
84
+ "pl",
85
+ "de",
86
+ "fr",
87
+ "pt",
88
+ "it",
89
+ "nl",
90
+ "tr",
91
+ "ar",
92
+ ] as const
93
+
94
+ export const SUPPORTED_EVENTS = [
95
+ "order.placed",
96
+ "order.completed",
97
+ "order.canceled",
98
+ "order.updated",
99
+ "order.fulfillment_created",
100
+ "order.fulfillment_canceled",
101
+ "order.return_requested",
102
+ "order.return_received",
103
+ "order.refund_created",
104
+ "shipment.created",
105
+ "delivery.created",
106
+ "customer.created",
107
+ "customer.updated",
108
+ "inventory-level.updated",
109
+ "document.generated",
110
+ "auth.otp_generated",
111
+ "cart.abandoned",
112
+ "loyalty.points_credited",
113
+ "loyalty.points_debited",
114
+ "wallet.credited",
115
+ "wallet.debited",
116
+ "membership.tier_changed",
117
+ "contact.form_submitted",
118
+ ] as const
119
+
120
+ export const CONTEXT_TYPES = [
121
+ "order",
122
+ "shipment",
123
+ "product",
124
+ "inventory-level",
125
+ "customer",
126
+ "cart",
127
+ "document",
128
+ "otp",
129
+ "custom",
130
+ ] as const
131
+
132
+ export const SUPPORTED_UI_LOCALES = [
133
+ { code: "en", label: "English (EN)" },
134
+ { code: "es", label: "Español (ES)" },
135
+ { code: "de", label: "Deutsch (DE)" },
136
+ { code: "fr", label: "Français (FR)" },
137
+ { code: "pt", label: "Português (PT)" },
138
+ { code: "it", label: "Italiano (IT)" },
139
+ { code: "nl", label: "Nederlands (NL)" },
140
+ { code: "pl", label: "Polski (PL)" },
141
+ { code: "tr", label: "Türkçe (TR)" },
142
+ { code: "ar", label: "العربية (AR)" },
143
+ ] as const
@@ -0,0 +1,96 @@
1
+ import type {
2
+ BLOCK_TYPES,
3
+ BROADCAST_STATUSES,
4
+ CONSENT_STATUSES,
5
+ CONTEXT_TYPES,
6
+ DELIVERY_STATUSES,
7
+ NOTIFICATION_CHANNELS,
8
+ RECIPIENT_RULES,
9
+ SMS_DRIVERS,
10
+ SUPPORTED_EVENTS,
11
+ SUPPORTED_LOCALES,
12
+ TEMPLATE_MODES,
13
+ TEMPLATE_SOURCES,
14
+ WHATSAPP_DRIVERS,
15
+ } from "./constants"
16
+ import type { RenderedNotificationPayload } from "./domain"
17
+
18
+ export type NotificationChannel = (typeof NOTIFICATION_CHANNELS)[number]
19
+ export type TemplateMode = (typeof TEMPLATE_MODES)[number]
20
+ export type TemplateSource = (typeof TEMPLATE_SOURCES)[number]
21
+ export type BlockType = (typeof BLOCK_TYPES)[number]
22
+ export type WhatsAppDriver = (typeof WHATSAPP_DRIVERS)[number]
23
+ export type SmsDriver = (typeof SMS_DRIVERS)[number]
24
+ export type RecipientRule = (typeof RECIPIENT_RULES)[number]
25
+ export type DeliveryStatus = (typeof DELIVERY_STATUSES)[number]
26
+ export type ConsentStatus = (typeof CONSENT_STATUSES)[number]
27
+ export type BroadcastStatus = (typeof BROADCAST_STATUSES)[number]
28
+ export type SupportedLocale = (typeof SUPPORTED_LOCALES)[number]
29
+ export type SupportedEventName = (typeof SUPPORTED_EVENTS)[number] | string
30
+ export type ContextType = (typeof CONTEXT_TYPES)[number]
31
+
32
+ // SDK & Hook Aliases
33
+ export type MpnChannel = NotificationChannel
34
+ export type MpnLocale = SupportedLocale
35
+ export type MpnRecipientRule = RecipientRule
36
+ export type MpnSupportedEvent = SupportedEventName
37
+ export type MpnTemplateBlockType = BlockType
38
+ export type MpnTemplateMode = TemplateMode
39
+
40
+ export interface MappedNotificationError {
41
+ code: string
42
+ message: string
43
+ retryable: boolean
44
+ }
45
+
46
+ export interface StatusBannerState {
47
+ type: "success" | "error"
48
+ text: string
49
+ }
50
+
51
+ export interface ExternalTemplateModuleConfig {
52
+ name: string
53
+ module?: Record<string, any>
54
+ path?: string
55
+ }
56
+
57
+ export interface ExternalTemplateService {
58
+ id: string
59
+ label?: string
60
+ channel?: NotificationChannel
61
+ templates?: ExternalTemplateModuleConfig[]
62
+ render?: (params: {
63
+ templateId: string
64
+ context: Record<string, any>
65
+ locale: string
66
+ translations: Record<string, any>
67
+ subject?: string | null
68
+ }) => Promise<Partial<RenderedNotificationPayload>>
69
+ getSystemTemplates?: () => Array<{
70
+ id: string
71
+ name: string
72
+ label: string
73
+ description?: string
74
+ channel: NotificationChannel
75
+ }>
76
+ }
77
+
78
+ export interface NotificationsPluginOptions {
79
+ defaultLocale?: SupportedLocale
80
+ storeName?: string
81
+ storeUrl?: string
82
+ logoUrl?: string
83
+ customTranslations?: Partial<Record<SupportedLocale, Record<string, any>>>
84
+ logRetentionDays?: number
85
+ sendConcurrency?: number
86
+ enableCartRecovery?: boolean
87
+ cartAbandonmentThresholdMinutes?: number
88
+ cartRecoveryUrlBase?: string
89
+ enableBroadcasts?: boolean
90
+ attributionWindowDays?: number
91
+ requireSmsConsent?: boolean
92
+ requireWhatsAppConsent?: boolean
93
+ extend?: {
94
+ services?: ExternalTemplateService[]
95
+ }
96
+ }
@@ -0,0 +1,84 @@
1
+ import type {
2
+ BlockType,
3
+ NotificationChannel,
4
+ SupportedLocale,
5
+ WhatsAppDriver,
6
+ } from "./core"
7
+
8
+ export interface TemplateBlockNode {
9
+ id: string
10
+ type: BlockType
11
+ position: number
12
+ parent_id?: string | null
13
+ metadata: Record<string, any>
14
+ children?: TemplateBlockNode[]
15
+ }
16
+
17
+ export interface NotificationAttachment {
18
+ filename: string
19
+ content: string // base64 encoded
20
+ content_type: string
21
+ document_type?: string
22
+ document_number?: string
23
+ }
24
+
25
+ export interface TelegramInlineButton {
26
+ text: string
27
+ url?: string
28
+ callback_data?: string
29
+ }
30
+
31
+ export interface WhatsAppInteractiveButton {
32
+ id: string
33
+ title: string
34
+ url?: string
35
+ }
36
+
37
+ export interface RenderedNotificationPayload {
38
+ channel: NotificationChannel
39
+ template_id: string
40
+ template_name: string
41
+ locale: SupportedLocale
42
+ subject?: string
43
+ html?: string
44
+ text: string
45
+ blocks_json?: Array<Record<string, any>>
46
+ telegram_options?: {
47
+ parse_mode: "HTML"
48
+ message_thread_id?: number | null
49
+ inline_keyboard?: TelegramInlineButton[][]
50
+ disable_web_page_preview?: boolean
51
+ }
52
+ whatsapp_options?: {
53
+ driver?: WhatsAppDriver
54
+ message_type: "template" | "text" | "interactive" | "document"
55
+ meta_template_name?: string | null
56
+ meta_language_code?: string
57
+ meta_components?: Array<Record<string, any>>
58
+ buttons?: WhatsAppInteractiveButton[]
59
+ }
60
+ sms_options?: {
61
+ encoding: "GSM-7" | "UCS-2"
62
+ segments: number
63
+ character_count: number
64
+ media_urls?: string[]
65
+ consent_footer_appended?: boolean
66
+ }
67
+ attachments?: NotificationAttachment[]
68
+ }
69
+
70
+ export interface EventMappingCondition {
71
+ region_ids?: string[]
72
+ sales_channel_ids?: string[]
73
+ currency_codes?: string[]
74
+ min_order_total?: number
75
+ document_types?: string[]
76
+ require_consent?: boolean
77
+ }
78
+
79
+ export interface SenderProfileConfig {
80
+ index: number
81
+ name: string
82
+ from_address: string
83
+ reply_to?: string
84
+ }
@@ -0,0 +1,73 @@
1
+ export const ENotificationChannel = {
2
+ EMAIL: "email",
3
+ WHATSAPP: "whatsapp",
4
+ TELEGRAM: "telegram",
5
+ SMS: "sms",
6
+ SLACK: "slack",
7
+ DUMMY: "dummy",
8
+ } as const
9
+ export type ENotificationChannel =
10
+ (typeof ENotificationChannel)[keyof typeof ENotificationChannel]
11
+
12
+ export const ETemplateMode = {
13
+ BLOCKS: "blocks",
14
+ RAW: "raw",
15
+ } as const
16
+ export type ETemplateMode = (typeof ETemplateMode)[keyof typeof ETemplateMode]
17
+
18
+ export const ETemplateSource = {
19
+ SYSTEM: "system",
20
+ DB: "db",
21
+ EXTERNAL: "external",
22
+ } as const
23
+ export type ETemplateSource =
24
+ (typeof ETemplateSource)[keyof typeof ETemplateSource]
25
+
26
+ export const EWhatsAppDriver = {
27
+ META_CLOUD: "meta-cloud",
28
+ OPENWA: "openwa",
29
+ WAHA: "waha",
30
+ EVOLUTION: "evolution",
31
+ } as const
32
+ export type EWhatsAppDriver =
33
+ (typeof EWhatsAppDriver)[keyof typeof EWhatsAppDriver]
34
+
35
+ export const ESmsDriver = {
36
+ TWILIO: "twilio",
37
+ SIGNALHOUSE: "signalhouse",
38
+ MSG91: "msg91",
39
+ SMSAPI: "smsapi",
40
+ WEBHOOK: "webhook",
41
+ DUMMY: "dummy",
42
+ } as const
43
+ export type ESmsDriver = (typeof ESmsDriver)[keyof typeof ESmsDriver]
44
+
45
+ export const EDeliveryStatus = {
46
+ PENDING: "pending",
47
+ SENT: "sent",
48
+ DELIVERED: "delivered",
49
+ FAILED: "failed",
50
+ SKIPPED_IDEMPOTENT: "skipped_idempotent",
51
+ SKIPPED_NO_CONSENT: "skipped_no_consent",
52
+ RATE_LIMITED_DELAYED: "rate_limited_delayed",
53
+ } as const
54
+ export type EDeliveryStatus =
55
+ (typeof EDeliveryStatus)[keyof typeof EDeliveryStatus]
56
+
57
+ export const EConsentStatus = {
58
+ OPTED_IN: "opted_in",
59
+ OPTED_OUT: "opted_out",
60
+ PENDING: "pending",
61
+ } as const
62
+ export type EConsentStatus =
63
+ (typeof EConsentStatus)[keyof typeof EConsentStatus]
64
+
65
+ export const EBroadcastStatus = {
66
+ DRAFT: "draft",
67
+ SCHEDULED: "scheduled",
68
+ SENDING: "sending",
69
+ COMPLETED: "completed",
70
+ CANCELED: "canceled",
71
+ } as const
72
+ export type EBroadcastStatus =
73
+ (typeof EBroadcastStatus)[keyof typeof EBroadcastStatus]
@@ -0,0 +1,32 @@
1
+ import type { MappedNotificationError } from "./index"
2
+
3
+ export const NOTIFICATIONS_ERROR_MAP: Record<string, MappedNotificationError> =
4
+ {
5
+ TEMPLATE_NOT_FOUND: {
6
+ code: "template_not_found",
7
+ message: "The requested notification template could not be found.",
8
+ retryable: false,
9
+ },
10
+ CHANNEL_NOT_CONFIGURED: {
11
+ code: "channel_not_configured",
12
+ message: "The target notification channel or driver is not configured.",
13
+ retryable: false,
14
+ },
15
+ CONSENT_REQUIRED: {
16
+ code: "consent_required",
17
+ message:
18
+ "Recipient has not opted in to receive notifications on this channel.",
19
+ retryable: false,
20
+ },
21
+ RATE_LIMIT_EXCEEDED: {
22
+ code: "rate_limit_exceeded",
23
+ message:
24
+ "Channel provider rate limit exceeded. Delivery will be retried.",
25
+ retryable: true,
26
+ },
27
+ PROVIDER_DELIVERY_FAILED: {
28
+ code: "provider_delivery_failed",
29
+ message: "The notification provider failed to deliver the message.",
30
+ retryable: true,
31
+ },
32
+ }
@@ -0,0 +1,48 @@
1
+ import type { NotificationsApiClient } from "../sdk/client"
2
+
3
+ export interface NotificationsQueryHookOptions<TData = unknown> {
4
+ client?: NotificationsApiClient
5
+ queryKey?: readonly unknown[]
6
+ enabled?: boolean
7
+ onSuccess?: (data: TData) => void
8
+ onError?: (error: Error) => void
9
+ }
10
+
11
+ export interface NotificationsMutationHookOptions<
12
+ TData = unknown,
13
+ TVariables = unknown,
14
+ > {
15
+ client?: NotificationsApiClient
16
+ queryKey?: readonly unknown[]
17
+ onSuccess?: (data: TData, variables: TVariables) => void
18
+ onError?: (error: Error, variables: TVariables) => void
19
+ }
20
+
21
+ export interface UseNotificationsQueryResult<TData> {
22
+ data: TData | undefined
23
+ isLoading: boolean
24
+ isFetching: boolean
25
+ error: Error | null
26
+ refetch: () => Promise<TData | undefined>
27
+ }
28
+
29
+ export interface UseNotificationsMutationResult<TData, TVariables> {
30
+ mutate: (
31
+ variables: TVariables,
32
+ callOptions?: {
33
+ onSuccess?: (data: TData, variables: TVariables) => void
34
+ onError?: (error: Error, variables: TVariables) => void
35
+ }
36
+ ) => void
37
+ mutateAsync: (variables: TVariables) => Promise<TData>
38
+ isPending: boolean
39
+ error: Error | null
40
+ data: TData | undefined
41
+ reset: () => void
42
+ }
43
+
44
+ export interface UseOrderNotificationsWidgetStateProps {
45
+ order?: Record<string, any>
46
+ client?: NotificationsApiClient
47
+ t?: (key: string, options?: Record<string, any>) => string
48
+ }
@@ -0,0 +1,11 @@
1
+ export * from "./constants"
2
+ export * from "./enums"
3
+ export * from "./errors"
4
+ export * from "./core"
5
+ export * from "./domain"
6
+ export * from "./records"
7
+ export * from "./translations"
8
+ export * from "./render"
9
+ export * from "./providers"
10
+ export * from "./sdk-api"
11
+ export * from "./hooks"
@@ -0,0 +1,96 @@
1
+ import type { SmsDriver, WhatsAppDriver } from "./core"
2
+
3
+ export interface SmtpEmailProviderOptions {
4
+ channels?: string[]
5
+ host?: string
6
+ port?: number
7
+ secure?: boolean
8
+ user?: string
9
+ pass?: string
10
+ from_name?: string
11
+ from_address?: string
12
+ webhook_url?: string
13
+ api_key?: string
14
+ allow_localhost?: boolean
15
+ local_preview?: boolean
16
+ local_preview_dir?: string
17
+ }
18
+
19
+ export interface WhatsAppProviderOptions {
20
+ channels?: string[]
21
+ driver?: WhatsAppDriver
22
+ enabled?: boolean
23
+ // Official Meta Cloud API options
24
+ accessToken?: string
25
+ wabaId?: string
26
+ phoneNumberId?: string
27
+ graphAPIVersion?: string
28
+ // Self-hosted OpenWA (@open-wa/wa-automate) / WAHA / Evolution API options
29
+ gatewayUrl?: string
30
+ gatewayApiKey?: string
31
+ sessionId?: string
32
+ allowLocalhost?: boolean
33
+ timeoutMs?: number
34
+ }
35
+
36
+ export interface TelegramProviderOptions {
37
+ channels?: string[]
38
+ botToken?: string
39
+ defaultChannelId?: string
40
+ globalRateLimitPerSec?: number
41
+ perChatRateLimitPerSec?: number
42
+ }
43
+
44
+ export interface SmsProviderOptions {
45
+ channels?: string[]
46
+ driver?: SmsDriver
47
+ // Twilio options (medusa-twilio-sms compatible)
48
+ account_sid?: string
49
+ auth_token?: string
50
+ from_number?: string
51
+ messaging_service_sid?: string
52
+ max_retries?: number
53
+ retry_delay?: number
54
+ // Signal House options (@signalhouse-sms/medusa-plugin compatible)
55
+ signalhouse_api_key?: string
56
+ signalhouse_sender_number?: string
57
+ signalhouse_base_url?: string
58
+ // MSG91 Flow options (medusa-msg91 compatible)
59
+ msg91_auth_key?: string
60
+ msg91_flow_id?: string
61
+ msg91_sender_id?: string
62
+ // SMSAPI options (@yanchesky/medusa-smsapi compatible)
63
+ smsapi_token?: string
64
+ smsapi_from?: string
65
+ // Generic HTTP Webhook SMS gateway
66
+ webhook_url?: string
67
+ webhook_api_key?: string
68
+ allow_localhost?: boolean
69
+ }
70
+
71
+ export interface SlackProviderOptions {
72
+ channels?: string[]
73
+ webhook_url?: string
74
+ bot_token?: string
75
+ default_channel?: string
76
+ allow_localhost?: boolean
77
+ }
78
+
79
+ export interface DummySandboxProviderOptions {
80
+ channels?: string[]
81
+ maxStoredMessages?: number
82
+ }
83
+
84
+ export interface CapturedSandboxEntry {
85
+ id: string
86
+ channel: string
87
+ recipient: string
88
+ sender: string | null
89
+ subject: string | null
90
+ body: string
91
+ html: string | null
92
+ otp_code: string | null
93
+ media_urls: string[]
94
+ attachments_meta: Array<{ filename: string; content_type: string }>
95
+ created_at: string
96
+ }
@@ -0,0 +1,100 @@
1
+ import type {
2
+ MpnChannel,
3
+ MpnLocale,
4
+ MpnRecipientRule,
5
+ MpnSupportedEvent,
6
+ MpnTemplateBlockType,
7
+ MpnTemplateMode,
8
+ } from "./core"
9
+
10
+ export interface MpnTemplateBlockRecord {
11
+ id: string
12
+ template_id?: string
13
+ type: MpnTemplateBlockType | string
14
+ position: number
15
+ parent_id?: string | null
16
+ metadata?: Record<string, any>
17
+ children?: MpnTemplateBlockRecord[]
18
+ }
19
+
20
+ export interface MpnTemplateRecord {
21
+ id: string
22
+ name?: string
23
+ label: string
24
+ channel: MpnChannel | string
25
+ locale?: MpnLocale | string
26
+ subject?: string | null
27
+ mode?: MpnTemplateMode | string
28
+ raw_content?: string | null
29
+ meta_template_name?: string | null
30
+ source?: "system" | "database" | string
31
+ is_active?: boolean
32
+ [key: string]: any
33
+ }
34
+
35
+ export interface MpnEventMappingRecord {
36
+ id: string
37
+ event_name: MpnSupportedEvent | string
38
+ channel: MpnChannel | string
39
+ template_id: string
40
+ recipient_rule: MpnRecipientRule | string
41
+ custom_recipients?: string[] | null
42
+ telegram_thread_id?: number | null
43
+ attach_document_types?: string[] | null
44
+ is_active: boolean
45
+ [key: string]: any
46
+ }
47
+
48
+ export interface MpnChannelConfigRecord {
49
+ id?: string
50
+ channel: MpnChannel | string
51
+ driver: string
52
+ config_json: Record<string, any>
53
+ is_verified?: boolean
54
+ is_active?: boolean
55
+ [key: string]: any
56
+ }
57
+
58
+ export interface MpnLogRecord {
59
+ id: string
60
+ channel: MpnChannel | string
61
+ driver?: string
62
+ event_name?: string | null
63
+ template_id?: string | null
64
+ entity_id?: string | null
65
+ recipient_masked: string
66
+ status: string
67
+ error_message?: string | null
68
+ created_at?: string
69
+ [key: string]: any
70
+ }
71
+
72
+ export interface MpnBroadcastRecord {
73
+ id: string
74
+ name: string
75
+ channel: MpnChannel | string
76
+ template_id: string
77
+ status: string
78
+ sent_count: number
79
+ total_recipients: number
80
+ [key: string]: any
81
+ }
82
+
83
+ export interface MpnConsentSummary {
84
+ opted_in_sms: number
85
+ opted_in_whatsapp: number
86
+ opted_in_telegram: number
87
+ opted_out_total: number
88
+ [key: string]: any
89
+ }
90
+
91
+ export interface MpnSandboxMessageRecord {
92
+ id: string
93
+ channel: MpnChannel | string
94
+ recipient: string
95
+ subject?: string | null
96
+ body: string
97
+ otp_code?: string | null
98
+ created_at?: string
99
+ [key: string]: any
100
+ }