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

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 +340 -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 +133 -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 +589 -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,123 @@
1
+ # Admin
2
+
3
+ Medusa v2 Admin extension — multi-route pages, `LayoutComposer` sections, order activity widget, and data-fetching hooks for `@vicacha-devs/medusa-plugin-notifications`.
4
+
5
+ ```sh
6
+ admin/
7
+ ├── tsconfig.json TypeScript config (moduleResolution: bundler, noEmit: true)
8
+ ├── vite-env.d.ts Vite client type definitions
9
+ ├── i18n/ react-i18next setup and 10-locale translation files (mpn namespace)
10
+ │ ├── index.ts Exports 10 locale translation maps (ar, de, en, es, fr, it, nl, pl, pt, tr)
11
+ │ └── json/ One JSON file per locale
12
+ ├── components/
13
+ │ └── mpn/ 18 modular Notification Studio files (< 170 lines each)
14
+ │ ├── index.ts Barrel re-exporting all MPN Admin UI components & hooks
15
+ │ ├── broadcast-consent-section.tsx TCPA/10DLC consent summary side section
16
+ │ ├── broadcasts-tab.tsx Customer group broadcasts form & campaign history table
17
+ │ ├── channels-main-section.tsx WhatsApp/OpenWA & Telegram gateway configuration cards
18
+ │ ├── channels-side-section.tsx SMS carrier driver configuration side card
19
+ │ ├── channels-tab.tsx Multi-driver channel gateway coordinator
20
+ │ ├── constants.ts Re-exported channel/block/locale constants
21
+ │ ├── delivery-logs-tab.tsx PII-masked delivery ledger table
22
+ │ ├── event-mapping-form.tsx Store event → channel → template mapping form
23
+ │ ├── event-mappings-tab.tsx Event mappings section & active rules table
24
+ │ ├── header-bar.tsx Studio header with Toaster and refresh action
25
+ │ ├── overview-cards.tsx Shared StatCard and NavigationCard components
26
+ │ ├── sandbox-tab.tsx Dummy OTP & local sandbox message inspector
27
+ │ ├── template-editor-section.tsx Block tree / raw editor & metadata inputs
28
+ │ ├── template-preview-section.tsx Multi-locale live rendered preview card
29
+ │ ├── templates-list-section.tsx Channel-filtered templates & system presets table
30
+ │ ├── templates-tab.tsx Templates builder coordinator
31
+ │ └── use-notification-studio.ts Studio data orchestration hook backed by src/hooks/*
32
+ ├── routes/
33
+ │ └── mpn/ Page routes registered in the Medusa Admin shell
34
+ │ ├── page.tsx /app/mpn — Overview dashboard (StatCards + NavigationCards)
35
+ │ ├── templates/
36
+ │ │ └── page.tsx /app/mpn/templates — Visual Block & Raw Template Builder
37
+ │ ├── mappings/
38
+ │ │ └── page.tsx /app/mpn/mappings — Event Mappings Orchestrator
39
+ │ ├── channels/
40
+ │ │ └── page.tsx /app/mpn/channels — Multi-Driver Gateway Configuration
41
+ │ ├── logs/
42
+ │ │ └── page.tsx /app/mpn/logs — Redacted Delivery Logs
43
+ │ ├── broadcasts/
44
+ │ │ └── page.tsx /app/mpn/broadcasts — Broadcasts & Consent Ledger
45
+ │ └── sandbox/
46
+ │ └── page.tsx /app/mpn/sandbox — Dummy OTP Sandbox
47
+ └── widgets/
48
+ └── order-notifications-widget.tsx Order details activity widget (zone: order.details.after)
49
+ ```
50
+
51
+ ---
52
+
53
+ ## Route Registration & Breadcrumbs
54
+
55
+ Each `page.tsx` under `src/admin/routes/mpn/` exports a `config` created with `defineRouteConfig` (including `translationNs: "mpn"`) and a `handle` object with a `breadcrumb` component:
56
+
57
+ ```tsx
58
+ export const config = defineRouteConfig({
59
+ label: "Notifications",
60
+ translationNs: "mpn",
61
+ icon: ChatBubbleLeftRight,
62
+ })
63
+
64
+ export const handle = {
65
+ breadcrumb: () => <Breadcrumb />,
66
+ }
67
+ ```
68
+
69
+ | Route Path | File | Layout ID | Widget Zone Prefix | Description |
70
+ | --------------------- | -------------------------------- | --------------- | ------------------ | ----------------------------------------------------------------------------------------------- |
71
+ | `/app/mpn` | `routes/mpn/page.tsx` | `SINGLE_COLUMN` | `mpn.overview` | Overview dashboard with `StatCard` KPIs and `NavigationCard` links to all 6 sub-routes |
72
+ | `/app/mpn/templates` | `routes/mpn/templates/page.tsx` | `SINGLE_COLUMN` | `mpn.templates` | Visual Block Tree & Raw Template Builder, 1-click preset cloning, and live multi-locale preview |
73
+ | `/app/mpn/mappings` | `routes/mpn/mappings/page.tsx` | `SINGLE_COLUMN` | `mpn.mappings` | Store Event → Channel → Template → Recipient Rule mapping form and active rules table |
74
+ | `/app/mpn/channels` | `routes/mpn/channels/page.tsx` | `TWO_COLUMN` | `mpn.channels` | WhatsApp/OpenWA & Telegram verification gate in `main`; SMS carrier selector in `side` |
75
+ | `/app/mpn/logs` | `routes/mpn/logs/page.tsx` | `SINGLE_COLUMN` | `mpn.logs` | PII-masked, idempotent delivery ledger table |
76
+ | `/app/mpn/broadcasts` | `routes/mpn/broadcasts/page.tsx` | `TWO_COLUMN` | `mpn.broadcasts` | Broadcast campaign form & history table in `main`; TCPA/10DLC consent summary in `side` |
77
+ | `/app/mpn/sandbox` | `routes/mpn/sandbox/page.tsx` | `SINGLE_COLUMN` | `mpn.sandbox` | Dummy OTP & local sandbox message inspector with 1-click clear |
78
+
79
+ ---
80
+
81
+ ## Component Architecture (`components/mpn/`)
82
+
83
+ All Admin UI components are modular, single-responsibility files kept strictly under **170 lines per file**:
84
+
85
+ | File | Responsibility |
86
+ | ------------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
87
+ | `index.ts` | Barrel exporting all Notification Studio components, constants, and `useNotificationStudio` |
88
+ | `constants.ts` | Re-exports `CHANNELS`, `CONTEXT_TYPES`, `BLOCK_TYPES`, and `LOCALES` from `src/types` |
89
+ | `header-bar.tsx` | Studio header bar with `<Toaster />`, subtitle, and refresh action button |
90
+ | `overview-cards.tsx` | Reusable `StatCard` and `NavigationCard` components for `/app/mpn` |
91
+ | `templates-tab.tsx` | Coordinates `TemplatesListSection`, `TemplateEditorSection`, and `TemplatePreviewSection` |
92
+ | `templates-list-section.tsx` | Channel-filtered table of `system_*` presets and `mpntpl_*` DB templates with Preview/Clone actions |
93
+ | `template-editor-section.tsx` | Subject, Meta WABA template name, Raw content textarea, and hierarchical Block Tree editor |
94
+ | `template-preview-section.tsx` | Live rendered preview across 10 locales and 7 entity context types with SMS encoding/segment badges |
95
+ | `event-mappings-tab.tsx` | Combines `EventMappingForm` and the active event mappings table with delete action |
96
+ | `event-mapping-form.tsx` | `KeyboundForm` for binding a Medusa event to a channel, template, recipient rule, thread ID, and PDF invoice attachment |
97
+ | `channels-tab.tsx` | Coordinator rendering `ChannelsMainSection` and `ChannelsSideSection` |
98
+ | `channels-main-section.tsx` | WhatsApp driver selector (`meta-cloud`, `openwa`, `waha`, `evolution`) and Telegram supergroup verification gate |
99
+ | `channels-side-section.tsx` | SMS carrier driver selector (`twilio`, `signalhouse`, `msg91`, `smsapi`, `dummy`) |
100
+ | `delivery-logs-tab.tsx` | Paginated table of PII-masked `mpn_delivery_log` records with status badges |
101
+ | `broadcasts-tab.tsx` | Customer group / custom recipient broadcast campaign form and campaign history table |
102
+ | `broadcast-consent-section.tsx` | Side card displaying opted-in vs. opted-out counts (`mpn_consent_record`) and webhook keywords (`JOIN`/`STOP`, `/start`) |
103
+ | `sandbox-tab.tsx` | Table of captured sandbox messages (`mpn_sandbox_message`) highlighting extracted OTP codes |
104
+ | `use-notification-studio.ts` | Unified studio state hook composing the domain hooks from `src/hooks/*` |
105
+
106
+ ---
107
+
108
+ ## Data Fetching & Hooks
109
+
110
+ All server communication goes through the typed SDK (`src/sdk/client.ts`) and React hooks (`src/hooks/`):
111
+
112
+ - `useNotificationStudio` (`components/mpn/use-notification-studio.ts`) — orchestrates studio state, active template selection, block tree editing, live preview rendering, and mutations for `/app/mpn/*` routes.
113
+ - `useMpnTemplates`, `useMpnTemplateDetail`, `useCreateOrCloneMpnTemplate`, `useUpdateMpnTemplate`, `useDeleteMpnTemplate`, `useRenderMpnTemplatePreview` (`src/hooks/use-mpn-templates.ts`).
114
+ - `useMpnMappings`, `useCreateMpnMapping`, `useUpdateMpnMapping`, `useDeleteMpnMapping` (`src/hooks/use-mpn-mappings.ts`).
115
+ - `useMpnChannels`, `useSaveOrVerifyMpnChannel` (`src/hooks/use-mpn-channels.ts`).
116
+ - `useMpnLogs`, `useMpnOrderLogs`, `useMpnBroadcasts`, `useCreateMpnBroadcast`, `useMpnSandboxMessages`, `useClearMpnSandbox`, `useSendMpnNotification`, `useUpdateStoreMpnConsent` (`src/hooks/use-mpn-dispatch.ts`).
117
+ - `useOrderNotificationsWidgetState` (`src/hooks/use-order-notifications-widget-state.ts`) — powers `widgets/order-notifications-widget.tsx` (`order.details.after`).
118
+
119
+ ---
120
+
121
+ ## i18n
122
+
123
+ Translations are configured in `src/admin/i18n/` using `react-i18next` across 10 locales (`ar`, `de`, `en`, `es`, `fr`, `it`, `nl`, `pl`, `pt`, `tr`) with automatic RTL support for Arabic (`ar`). See [`i18n/README.md`](./i18n/README.md) for details.
@@ -0,0 +1,62 @@
1
+ import { SectionRow } from "@medusajs/dashboard/components"
2
+ import { Badge, Container, Heading, StatusBadge } from "@medusajs/ui"
3
+ import React from "react"
4
+ import { useTranslation } from "react-i18next"
5
+
6
+ export interface BroadcastConsentSectionProps {
7
+ consentSummary: Record<string, any> | null
8
+ }
9
+
10
+ export const BroadcastConsentSection: React.FC<
11
+ BroadcastConsentSectionProps
12
+ > = ({ consentSummary }) => {
13
+ const { t } = useTranslation()
14
+
15
+ return (
16
+ <Container className="divide-y p-0">
17
+ <div className="flex items-center justify-between px-6 py-4">
18
+ <Heading level="h2">{t("tabs.broadcasts")}</Heading>
19
+ </div>
20
+ <SectionRow
21
+ title="SMS"
22
+ value={
23
+ <StatusBadge color="green">
24
+ {t("broadcasts.smsOptedIn", {
25
+ count: consentSummary?.opted_in_sms ?? 0,
26
+ })}
27
+ </StatusBadge>
28
+ }
29
+ />
30
+ <SectionRow
31
+ title="WhatsApp"
32
+ value={
33
+ <StatusBadge color="green">
34
+ {t("broadcasts.whatsappOptedIn", {
35
+ count: consentSummary?.opted_in_whatsapp ?? 0,
36
+ })}
37
+ </StatusBadge>
38
+ }
39
+ />
40
+ <SectionRow
41
+ title="Telegram"
42
+ value={
43
+ <Badge size="2xsmall" color="blue">
44
+ {t("broadcasts.telegramLinked", {
45
+ count: consentSummary?.opted_in_telegram ?? 0,
46
+ })}
47
+ </Badge>
48
+ }
49
+ />
50
+ <SectionRow
51
+ title="STOP"
52
+ value={
53
+ <StatusBadge color="red">
54
+ {t("broadcasts.optedOut", {
55
+ count: consentSummary?.opted_out_total ?? 0,
56
+ })}
57
+ </StatusBadge>
58
+ }
59
+ />
60
+ </Container>
61
+ )
62
+ }
@@ -0,0 +1,208 @@
1
+ import { Form, KeyboundForm } from "@medusajs/dashboard/components"
2
+ import {
3
+ Badge,
4
+ Button,
5
+ Container,
6
+ Heading,
7
+ Input,
8
+ Label,
9
+ Select,
10
+ StatusBadge,
11
+ Table,
12
+ Toaster,
13
+ toast,
14
+ } from "@medusajs/ui"
15
+ import React, { useState } from "react"
16
+ import { useForm } from "react-hook-form"
17
+ import { useTranslation } from "react-i18next"
18
+ import { useCreateMpnBroadcast } from "../../../hooks"
19
+ import { BroadcastConsentSection } from "./broadcast-consent-section"
20
+ import type { StatusBannerState } from "./constants"
21
+
22
+ export interface BroadcastsConsentTabProps {
23
+ broadcasts: Array<Record<string, any>>
24
+ consentSummary: Record<string, any> | null
25
+ templates: Array<Record<string, any>>
26
+ onRefresh: () => Promise<void>
27
+ onStatus?: (status: StatusBannerState) => void
28
+ section?: "main" | "side" | "all"
29
+ }
30
+
31
+ export const BroadcastsConsentTab: React.FC<BroadcastsConsentTabProps> = ({
32
+ broadcasts,
33
+ consentSummary,
34
+ templates,
35
+ onRefresh,
36
+ onStatus,
37
+ section = "all",
38
+ }) => {
39
+ const { t } = useTranslation()
40
+ const [broadcastName, setBroadcastName] = useState<string>("")
41
+ const [broadcastChannel, setBroadcastChannel] = useState<string>("sms")
42
+ const [broadcastTemplateId, setBroadcastTemplateId] = useState<string>(
43
+ "system_sms_order_placed"
44
+ )
45
+
46
+ const form = useForm({
47
+ defaultValues: {
48
+ name: "",
49
+ channel: "sms",
50
+ template_id: "system_sms_order_placed",
51
+ },
52
+ })
53
+
54
+ const createBroadcastMutation = useCreateMpnBroadcast()
55
+
56
+ const handleSendBroadcast = async () => {
57
+ if (!broadcastName.trim()) return
58
+ try {
59
+ await createBroadcastMutation.mutateAsync({
60
+ name: broadcastName,
61
+ channel: broadcastChannel,
62
+ template_id: broadcastTemplateId,
63
+ send_now: true,
64
+ })
65
+ setBroadcastName("")
66
+ const msg = t("messages.broadcastSentSuccess")
67
+ toast.success(msg)
68
+ onStatus?.({
69
+ type: "success",
70
+ text: msg,
71
+ })
72
+ await onRefresh()
73
+ } catch (err: any) {
74
+ toast.error(err?.message || t("messages.loadStudioError"))
75
+ }
76
+ }
77
+
78
+ const mainSection = (
79
+ <Container className="divide-y p-0">
80
+ <div className="flex items-center justify-between px-6 py-4">
81
+ <Heading level="h2">{t("broadcasts.title")}</Heading>
82
+ <StatusBadge color="green">{broadcasts.length}</StatusBadge>
83
+ </div>
84
+
85
+ <Form {...form}>
86
+ <KeyboundForm
87
+ onSubmit={(e) => {
88
+ e.preventDefault()
89
+ void handleSendBroadcast()
90
+ }}
91
+ className="px-6 py-4"
92
+ >
93
+ <div className="grid grid-cols-1 gap-4 md:grid-cols-4">
94
+ <div className="flex flex-col gap-y-2">
95
+ <Label size="small">{t("broadcasts.campaignNameLabel")}</Label>
96
+ <Input
97
+ size="small"
98
+ placeholder={t("broadcasts.campaignNamePlaceholder")}
99
+ value={broadcastName}
100
+ onChange={(e) => setBroadcastName(e.target.value)}
101
+ />
102
+ </div>
103
+ <div className="flex flex-col gap-y-2">
104
+ <Label size="small">{t("broadcasts.channelLabel")}</Label>
105
+ <Select
106
+ size="small"
107
+ value={broadcastChannel}
108
+ onValueChange={setBroadcastChannel}
109
+ >
110
+ <Select.Trigger>
111
+ <Select.Value />
112
+ </Select.Trigger>
113
+ <Select.Content>
114
+ <Select.Item value="sms">SMS</Select.Item>
115
+ <Select.Item value="whatsapp">WhatsApp</Select.Item>
116
+ <Select.Item value="telegram">Telegram</Select.Item>
117
+ </Select.Content>
118
+ </Select>
119
+ </div>
120
+ <div className="flex flex-col gap-y-2">
121
+ <Label size="small">{t("broadcasts.templateLabel")}</Label>
122
+ <Select
123
+ size="small"
124
+ value={broadcastTemplateId}
125
+ onValueChange={setBroadcastTemplateId}
126
+ >
127
+ <Select.Trigger>
128
+ <Select.Value />
129
+ </Select.Trigger>
130
+ <Select.Content>
131
+ {templates.map((tpl) => (
132
+ <Select.Item key={tpl.id} value={tpl.id}>
133
+ [{tpl.channel}] {tpl.label}
134
+ </Select.Item>
135
+ ))}
136
+ </Select.Content>
137
+ </Select>
138
+ </div>
139
+ <div className="flex items-end">
140
+ <Button
141
+ size="small"
142
+ variant="primary"
143
+ type="submit"
144
+ isLoading={createBroadcastMutation.isPending}
145
+ >
146
+ {t("broadcasts.sendNowButton")}
147
+ </Button>
148
+ </div>
149
+ </div>
150
+ </KeyboundForm>
151
+ </Form>
152
+
153
+ <Table>
154
+ <Table.Header>
155
+ <Table.Row>
156
+ <Table.HeaderCell>{t("broadcasts.colCampaign")}</Table.HeaderCell>
157
+ <Table.HeaderCell>{t("broadcasts.colChannel")}</Table.HeaderCell>
158
+ <Table.HeaderCell>{t("broadcasts.colStatus")}</Table.HeaderCell>
159
+ <Table.HeaderCell>{t("broadcasts.colSentTotal")}</Table.HeaderCell>
160
+ </Table.Row>
161
+ </Table.Header>
162
+ <Table.Body>
163
+ {broadcasts.map((b) => (
164
+ <Table.Row key={b.id}>
165
+ <Table.Cell>{b.name}</Table.Cell>
166
+ <Table.Cell>
167
+ <Badge size="2xsmall" color="blue">
168
+ {b.channel}
169
+ </Badge>
170
+ </Table.Cell>
171
+ <Table.Cell>
172
+ <StatusBadge color="green">{b.status}</StatusBadge>
173
+ </Table.Cell>
174
+ <Table.Cell>
175
+ {b.sent_count} / {b.total_recipients}
176
+ </Table.Cell>
177
+ </Table.Row>
178
+ ))}
179
+ </Table.Body>
180
+ </Table>
181
+ </Container>
182
+ )
183
+
184
+ const sideSection = (
185
+ <BroadcastConsentSection consentSummary={consentSummary} />
186
+ )
187
+
188
+ if (section === "main") {
189
+ return (
190
+ <>
191
+ <Toaster />
192
+ {mainSection}
193
+ </>
194
+ )
195
+ }
196
+
197
+ if (section === "side") {
198
+ return sideSection
199
+ }
200
+
201
+ return (
202
+ <div className="grid grid-cols-1 gap-4 lg:grid-cols-3">
203
+ <Toaster />
204
+ <div className="lg:col-span-2">{mainSection}</div>
205
+ <div>{sideSection}</div>
206
+ </div>
207
+ )
208
+ }
@@ -0,0 +1,205 @@
1
+ import { Form, KeyboundForm, SectionRow } from "@medusajs/dashboard/components"
2
+ import {
3
+ Badge,
4
+ Button,
5
+ Container,
6
+ Heading,
7
+ Input,
8
+ Label,
9
+ Select,
10
+ StatusBadge,
11
+ Text,
12
+ } from "@medusajs/ui"
13
+ import React from "react"
14
+ import { useForm } from "react-hook-form"
15
+ import { useTranslation } from "react-i18next"
16
+
17
+ export interface ChannelsMainSectionProps {
18
+ whatsappDriverInput: string
19
+ openWaUrlInput: string
20
+ telegramChannelInput: string
21
+ tgVerified: boolean
22
+ verifyCooldown: boolean
23
+ isPending: boolean
24
+ onWhatsappDriverChange: (driver: string) => void
25
+ onOpenWaUrlChange: (url: string) => void
26
+ onTelegramChannelChange: (channelId: string) => void
27
+ onSaveOrVerify: (
28
+ channel: string,
29
+ driver: string,
30
+ configJson: Record<string, any>,
31
+ action: "save" | "verify"
32
+ ) => void
33
+ }
34
+
35
+ export const ChannelsMainSection: React.FC<ChannelsMainSectionProps> = ({
36
+ whatsappDriverInput,
37
+ openWaUrlInput,
38
+ telegramChannelInput,
39
+ tgVerified,
40
+ verifyCooldown,
41
+ isPending,
42
+ onWhatsappDriverChange,
43
+ onOpenWaUrlChange,
44
+ onTelegramChannelChange,
45
+ onSaveOrVerify,
46
+ }) => {
47
+ const { t } = useTranslation()
48
+ const form = useForm({
49
+ defaultValues: {
50
+ whatsapp_driver: whatsappDriverInput,
51
+ gateway_url: openWaUrlInput,
52
+ merchant_channel_id: telegramChannelInput,
53
+ },
54
+ })
55
+
56
+ return (
57
+ <div className="flex flex-col gap-y-4">
58
+ <Container className="divide-y p-0">
59
+ <div className="flex items-center justify-between px-6 py-4">
60
+ <div>
61
+ <Heading level="h2">{t("channels.whatsappTitle")}</Heading>
62
+ <Text className="text-ui-fg-subtle text-xs mt-1">
63
+ {t("channels.whatsappSubtitle")}
64
+ </Text>
65
+ </div>
66
+ <Badge size="2xsmall" color="blue">
67
+ {whatsappDriverInput}
68
+ </Badge>
69
+ </div>
70
+
71
+ <SectionRow
72
+ title={t("channels.activeDriverLabel")}
73
+ value={whatsappDriverInput}
74
+ />
75
+
76
+ <Form {...form}>
77
+ <KeyboundForm
78
+ onSubmit={(e) => {
79
+ e.preventDefault()
80
+ onSaveOrVerify(
81
+ "whatsapp",
82
+ whatsappDriverInput,
83
+ { gateway_url: openWaUrlInput },
84
+ "save"
85
+ )
86
+ }}
87
+ className="flex flex-col gap-y-3 px-6 py-4"
88
+ >
89
+ <div className="flex flex-col gap-y-2">
90
+ <Label size="small">{t("channels.activeDriverLabel")}</Label>
91
+ <Select
92
+ size="small"
93
+ value={whatsappDriverInput}
94
+ onValueChange={onWhatsappDriverChange}
95
+ >
96
+ <Select.Trigger>
97
+ <Select.Value />
98
+ </Select.Trigger>
99
+ <Select.Content>
100
+ <Select.Item value="meta-cloud">
101
+ {t("channels.driverMetaCloud")}
102
+ </Select.Item>
103
+ <Select.Item value="openwa">
104
+ {t("channels.driverOpenWa")}
105
+ </Select.Item>
106
+ <Select.Item value="waha">
107
+ {t("channels.driverWaha")}
108
+ </Select.Item>
109
+ <Select.Item value="evolution">
110
+ {t("channels.driverEvolution")}
111
+ </Select.Item>
112
+ </Select.Content>
113
+ </Select>
114
+ </div>
115
+ <div className="flex flex-col gap-y-2">
116
+ <Label size="small">{t("channels.gatewayUrlLabel")}</Label>
117
+ <Input
118
+ size="small"
119
+ placeholder="http://127.0.0.1:8082"
120
+ value={openWaUrlInput}
121
+ onChange={(e) => onOpenWaUrlChange(e.target.value)}
122
+ />
123
+ </div>
124
+ <div className="flex justify-end">
125
+ <Button
126
+ size="small"
127
+ variant="primary"
128
+ type="submit"
129
+ isLoading={isPending}
130
+ >
131
+ {t("channels.saveWhatsappButton")}
132
+ </Button>
133
+ </div>
134
+ </KeyboundForm>
135
+ </Form>
136
+ </Container>
137
+
138
+ <Container className="divide-y p-0">
139
+ <div className="flex items-center justify-between px-6 py-4">
140
+ <div>
141
+ <Heading level="h2">{t("channels.telegramTitle")}</Heading>
142
+ <Text className="text-ui-fg-subtle text-xs mt-1">
143
+ {t("channels.telegramSubtitle")}
144
+ </Text>
145
+ </div>
146
+ <StatusBadge color={tgVerified ? "green" : "orange"}>
147
+ {tgVerified
148
+ ? t("channels.verifiedBadge")
149
+ : t("channels.unverifiedBadge")}
150
+ </StatusBadge>
151
+ </div>
152
+
153
+ <SectionRow
154
+ title={t("channels.merchantChannelLabel")}
155
+ value={telegramChannelInput || "—"}
156
+ />
157
+
158
+ <div className="flex flex-col gap-y-3 px-6 py-4">
159
+ <div className="flex flex-col gap-y-2">
160
+ <Label size="small">{t("channels.merchantChannelLabel")}</Label>
161
+ <Input
162
+ size="small"
163
+ placeholder={t("channels.merchantChannelPlaceholder")}
164
+ value={telegramChannelInput}
165
+ onChange={(e) => onTelegramChannelChange(e.target.value)}
166
+ />
167
+ </div>
168
+ <div className="flex justify-end gap-x-2">
169
+ <Button
170
+ size="small"
171
+ variant="secondary"
172
+ isLoading={isPending}
173
+ onClick={() =>
174
+ onSaveOrVerify(
175
+ "telegram",
176
+ "telegram-bot",
177
+ { merchant_channel_id: telegramChannelInput },
178
+ "save"
179
+ )
180
+ }
181
+ >
182
+ {t("channels.saveChannelIdButton")}
183
+ </Button>
184
+ <Button
185
+ size="small"
186
+ variant="primary"
187
+ disabled={verifyCooldown}
188
+ isLoading={isPending}
189
+ onClick={() =>
190
+ onSaveOrVerify(
191
+ "telegram",
192
+ "telegram-bot",
193
+ { merchant_channel_id: telegramChannelInput },
194
+ "verify"
195
+ )
196
+ }
197
+ >
198
+ {t("channels.sendTestButton")}
199
+ </Button>
200
+ </div>
201
+ </div>
202
+ </Container>
203
+ </div>
204
+ )
205
+ }