@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,695 @@
1
+ import type {
2
+ BlockType,
3
+ SystemTemplatePreset,
4
+ TemplateBlockNode,
5
+ } from "../../../types"
6
+ import { AUTH_SYSTEM_TEMPLATE_PRESETS } from "./auth-presets"
7
+
8
+ export type { SystemTemplatePreset } from "../../../types"
9
+
10
+ /**
11
+ * Converts a flat array of block rows (`mpn_template_block` or preset blocks)
12
+ * into a hierarchical tree sorted by `position`.
13
+ */
14
+ export function buildBlockTreeFromFlatBlocks(
15
+ flatBlocks: Array<{
16
+ id: string
17
+ type: BlockType | string
18
+ position?: number
19
+ parent_id?: string | null
20
+ metadata?: Record<string, any> | null
21
+ }>
22
+ ): TemplateBlockNode[] {
23
+ const nodeMap = new Map<string, TemplateBlockNode>()
24
+ const roots: TemplateBlockNode[] = []
25
+
26
+ const sorted = [...flatBlocks].toSorted(
27
+ (a, b) => Number(a.position ?? 0) - Number(b.position ?? 0)
28
+ )
29
+
30
+ for (const item of sorted) {
31
+ nodeMap.set(item.id, {
32
+ id: item.id,
33
+ type: item.type as BlockType,
34
+ position: Number(item.position ?? 0),
35
+ parent_id: item.parent_id ?? null,
36
+ metadata: item.metadata ? { ...item.metadata } : {},
37
+ children: [],
38
+ })
39
+ }
40
+
41
+ for (const item of sorted) {
42
+ const node = nodeMap.get(item.id)!
43
+ if (item.parent_id && nodeMap.has(item.parent_id)) {
44
+ nodeMap.get(item.parent_id)!.children!.push(node)
45
+ } else {
46
+ roots.push(node)
47
+ }
48
+ }
49
+
50
+ return roots
51
+ }
52
+
53
+ export const SYSTEM_TEMPLATE_PRESETS: SystemTemplatePreset[] = [
54
+ // =========================================================================
55
+ // 1. EMAIL PRESETS (codee-sh Visual Block Tree + @sam-ael Raw HTML)
56
+ // =========================================================================
57
+ {
58
+ id: "system_email_order_placed",
59
+ name: "order-placed-email",
60
+ label: "Order Placed Confirmation (Email)",
61
+ description:
62
+ "Responsive order confirmation email with line-item repeater, totals breakdown, and order status CTA button.",
63
+ channel: "email",
64
+ mode: "blocks",
65
+ default_event: "order.placed",
66
+ subject: "{{translations.order.placedSubject}}",
67
+ blocks: [
68
+ {
69
+ id: "blk_ep_1",
70
+ type: "heading",
71
+ position: 0,
72
+ parent_id: null,
73
+ metadata: {
74
+ level: 1,
75
+ align: "center",
76
+ text: "{{translations.order.placedTitle}}",
77
+ },
78
+ },
79
+ {
80
+ id: "blk_ep_2",
81
+ type: "text",
82
+ position: 1,
83
+ parent_id: null,
84
+ metadata: {
85
+ align: "left",
86
+ text: "{{translations.general.hello}} {{data.first_name}}, {{translations.order.placedIntro}}",
87
+ },
88
+ },
89
+ {
90
+ id: "blk_ep_3",
91
+ type: "separator",
92
+ position: 2,
93
+ parent_id: null,
94
+ metadata: {},
95
+ },
96
+ {
97
+ id: "blk_ep_4",
98
+ type: "heading",
99
+ position: 3,
100
+ parent_id: null,
101
+ metadata: {
102
+ level: 2,
103
+ text: "{{translations.order.itemsHeader}} (#{{data.display_id}})",
104
+ },
105
+ },
106
+ {
107
+ id: "blk_ep_5",
108
+ type: "repeater",
109
+ position: 4,
110
+ parent_id: null,
111
+ metadata: {
112
+ arrayKey: "items",
113
+ },
114
+ },
115
+ {
116
+ id: "blk_ep_5_child",
117
+ type: "product-item",
118
+ position: 0,
119
+ parent_id: "blk_ep_5",
120
+ metadata: {
121
+ variant: "order_item",
122
+ showSku: true,
123
+ showThumbnail: true,
124
+ },
125
+ },
126
+ {
127
+ id: "blk_ep_6",
128
+ type: "separator",
129
+ position: 5,
130
+ parent_id: null,
131
+ metadata: {},
132
+ },
133
+ {
134
+ id: "blk_ep_7",
135
+ type: "row",
136
+ position: 6,
137
+ parent_id: null,
138
+ metadata: {
139
+ label: "{{translations.order.subtotal}}",
140
+ value: "{{data.subtotal_formatted}}",
141
+ },
142
+ },
143
+ {
144
+ id: "blk_ep_8",
145
+ type: "row",
146
+ position: 7,
147
+ parent_id: null,
148
+ metadata: {
149
+ label: "{{translations.order.shipping}}",
150
+ value: "{{data.shipping_total_formatted}}",
151
+ },
152
+ },
153
+ {
154
+ id: "blk_ep_9",
155
+ type: "row",
156
+ position: 8,
157
+ parent_id: null,
158
+ metadata: {
159
+ label: "{{translations.order.tax}}",
160
+ value: "{{data.tax_total_formatted}}",
161
+ },
162
+ },
163
+ {
164
+ id: "blk_ep_10",
165
+ type: "row",
166
+ position: 9,
167
+ parent_id: null,
168
+ metadata: {
169
+ label: "{{translations.order.total}}",
170
+ value: "{{data.total_formatted}}",
171
+ bold: true,
172
+ },
173
+ },
174
+ {
175
+ id: "blk_ep_11",
176
+ type: "button",
177
+ position: 10,
178
+ parent_id: null,
179
+ metadata: {
180
+ text: "{{translations.order.trackOrderButton}}",
181
+ url: "{{data.order_url}}",
182
+ align: "center",
183
+ },
184
+ },
185
+ ],
186
+ },
187
+ {
188
+ id: "system_email_shipment_created",
189
+ name: "shipment-created-email",
190
+ label: "Order Shipped with Tracking (Email)",
191
+ description:
192
+ "Notifies the customer when a shipment is created with carrier and tracking link.",
193
+ channel: "email",
194
+ mode: "blocks",
195
+ default_event: "shipment.created",
196
+ subject: "{{translations.shipment.shippedSubject}}",
197
+ blocks: [
198
+ {
199
+ id: "blk_es_1",
200
+ type: "heading",
201
+ position: 0,
202
+ parent_id: null,
203
+ metadata: {
204
+ level: 1,
205
+ text: "{{translations.shipment.shippedTitle}}",
206
+ },
207
+ },
208
+ {
209
+ id: "blk_es_2",
210
+ type: "text",
211
+ position: 1,
212
+ parent_id: null,
213
+ metadata: {
214
+ text: "{{translations.general.hello}} {{data.first_name}}, {{translations.shipment.shippedIntro}}",
215
+ },
216
+ },
217
+ {
218
+ id: "blk_es_3",
219
+ type: "row",
220
+ position: 2,
221
+ parent_id: null,
222
+ metadata: {
223
+ label: "{{translations.shipment.carrier}}",
224
+ value: "{{data.carrier}}",
225
+ },
226
+ },
227
+ {
228
+ id: "blk_es_4",
229
+ type: "row",
230
+ position: 3,
231
+ parent_id: null,
232
+ metadata: {
233
+ label: "{{translations.shipment.trackingNumber}}",
234
+ value: "{{data.tracking_number}}",
235
+ bold: true,
236
+ },
237
+ },
238
+ {
239
+ id: "blk_es_5",
240
+ type: "button",
241
+ position: 4,
242
+ parent_id: null,
243
+ metadata: {
244
+ text: "{{translations.shipment.trackPackageButton}}",
245
+ url: "{{data.tracking_url}}",
246
+ },
247
+ },
248
+ ],
249
+ },
250
+ {
251
+ id: "system_email_document_ready",
252
+ name: "document-ready-email",
253
+ label: "Commercial Document / Invoice Attached (Email)",
254
+ description:
255
+ "Delivers PDF Invoices, Packing Slips, or Credit Notes generated by medusa-documents-plugin.",
256
+ channel: "email",
257
+ mode: "blocks",
258
+ default_event: "document.generated",
259
+ subject: "{{translations.document.readySubject}}",
260
+ blocks: [
261
+ {
262
+ id: "blk_ed_1",
263
+ type: "heading",
264
+ position: 0,
265
+ parent_id: null,
266
+ metadata: {
267
+ level: 1,
268
+ text: "{{translations.document.readyTitle}}",
269
+ },
270
+ },
271
+ {
272
+ id: "blk_ed_2",
273
+ type: "text",
274
+ position: 1,
275
+ parent_id: null,
276
+ metadata: {
277
+ text: "{{translations.general.hello}} {{data.first_name}}, {{translations.document.readyIntro}}",
278
+ },
279
+ },
280
+ {
281
+ id: "blk_ed_3",
282
+ type: "attachment",
283
+ position: 2,
284
+ parent_id: null,
285
+ metadata: {
286
+ document_type: "invoice",
287
+ description: "{{data.document_number}}.pdf",
288
+ },
289
+ },
290
+ ],
291
+ },
292
+ {
293
+ id: "system_email_inventory_low",
294
+ name: "inventory-low-email",
295
+ label: "Low Stock Alert (Email)",
296
+ description: "Merchant alert when stock drops below threshold.",
297
+ channel: "email",
298
+ mode: "blocks",
299
+ default_event: "inventory-level.updated",
300
+ subject: "{{translations.inventory.lowStockSubject}}",
301
+ blocks: [
302
+ {
303
+ id: "blk_ei_1",
304
+ type: "heading",
305
+ position: 0,
306
+ parent_id: null,
307
+ metadata: {
308
+ level: 1,
309
+ text: "{{translations.inventory.lowStockTitle}}",
310
+ },
311
+ },
312
+ {
313
+ id: "blk_ei_2",
314
+ type: "product-item",
315
+ position: 1,
316
+ parent_id: null,
317
+ metadata: {
318
+ variant: "inventory_item",
319
+ },
320
+ },
321
+ ],
322
+ },
323
+
324
+ // =========================================================================
325
+ // 2. WHATSAPP / OPENWA PRESETS (Meta Cloud Templates + OpenWA/WAHA Rich Text & Buttons)
326
+ // =========================================================================
327
+ {
328
+ id: "system_whatsapp_order_placed",
329
+ name: "order-placed-whatsapp",
330
+ label: "Order Placed + Interactive Buttons (WhatsApp / OpenWA)",
331
+ description:
332
+ "Supports both OpenWA/WAHA/Evolution rich text with interactive buttons AND Meta Cloud API template parameters.",
333
+ channel: "whatsapp",
334
+ mode: "blocks",
335
+ default_event: "order.placed",
336
+ meta_template_name: "order_confirmation",
337
+ meta_language_code: "en",
338
+ variable_map: {
339
+ customer_name: "first_name",
340
+ order_id: "display_id",
341
+ order_total: "total_formatted",
342
+ },
343
+ blocks: [
344
+ {
345
+ id: "blk_wa_1",
346
+ type: "heading",
347
+ position: 0,
348
+ parent_id: null,
349
+ metadata: {
350
+ text: "🛍️ {{translations.order.placedTitle}}",
351
+ },
352
+ },
353
+ {
354
+ id: "blk_wa_2",
355
+ type: "text",
356
+ position: 1,
357
+ parent_id: null,
358
+ metadata: {
359
+ text: "{{translations.general.hello}} *{{data.first_name}}*! {{translations.order.placedIntro}}",
360
+ },
361
+ },
362
+ {
363
+ id: "blk_wa_3",
364
+ type: "repeater",
365
+ position: 2,
366
+ parent_id: null,
367
+ metadata: {
368
+ arrayKey: "items",
369
+ },
370
+ },
371
+ {
372
+ id: "blk_wa_3_child",
373
+ type: "product-item",
374
+ position: 0,
375
+ parent_id: "blk_wa_3",
376
+ metadata: {
377
+ variant: "order_item",
378
+ },
379
+ },
380
+ {
381
+ id: "blk_wa_4",
382
+ type: "row",
383
+ position: 3,
384
+ parent_id: null,
385
+ metadata: {
386
+ label: "{{translations.order.total}}",
387
+ value: "{{data.total_formatted}}",
388
+ bold: true,
389
+ },
390
+ },
391
+ {
392
+ id: "blk_wa_5",
393
+ type: "actions",
394
+ position: 4,
395
+ parent_id: null,
396
+ metadata: {
397
+ buttons: [
398
+ {
399
+ id: "btn_track_order",
400
+ title: "{{translations.order.trackOrderButton}}",
401
+ url: "{{data.order_url}}",
402
+ },
403
+ {
404
+ id: "btn_visit_store",
405
+ title: "{{translations.general.viewInStore}}",
406
+ url: "{{data.store_url}}",
407
+ },
408
+ ],
409
+ },
410
+ },
411
+ ],
412
+ },
413
+ {
414
+ id: "system_whatsapp_shipment_created",
415
+ name: "shipment-created-whatsapp",
416
+ label: "Order Shipped Tracking Alert (WhatsApp / OpenWA)",
417
+ description:
418
+ "WhatsApp shipping notification with carrier, tracking code, and interactive tracking button.",
419
+ channel: "whatsapp",
420
+ mode: "blocks",
421
+ default_event: "shipment.created",
422
+ meta_template_name: "order_shipped",
423
+ meta_language_code: "en",
424
+ variable_map: {
425
+ customer_name: "first_name",
426
+ order_id: "order_display_id",
427
+ carrier: "carrier",
428
+ tracking_number: "tracking_number",
429
+ },
430
+ blocks: [
431
+ {
432
+ id: "blk_was_1",
433
+ type: "heading",
434
+ position: 0,
435
+ parent_id: null,
436
+ metadata: {
437
+ text: "📦 {{translations.shipment.shippedTitle}}",
438
+ },
439
+ },
440
+ {
441
+ id: "blk_was_2",
442
+ type: "text",
443
+ position: 1,
444
+ parent_id: null,
445
+ metadata: {
446
+ text: "{{translations.shipment.shippedIntro}}\n• *{{translations.shipment.carrier}}:* {{data.carrier}}\n• *{{translations.shipment.trackingNumber}}:* `{{data.tracking_number}}`",
447
+ },
448
+ },
449
+ {
450
+ id: "blk_was_3",
451
+ type: "actions",
452
+ position: 2,
453
+ parent_id: null,
454
+ metadata: {
455
+ buttons: [
456
+ {
457
+ id: "btn_track_shipment",
458
+ title: "{{translations.shipment.trackPackageButton}}",
459
+ url: "{{data.tracking_url}}",
460
+ },
461
+ ],
462
+ },
463
+ },
464
+ ],
465
+ },
466
+
467
+ // =========================================================================
468
+ // 3. TELEGRAM PRESETS (Merchant Ops Forum Topics + Customer Inline Keyboard)
469
+ // =========================================================================
470
+ {
471
+ id: "system_telegram_order_placed",
472
+ name: "order-placed-telegram",
473
+ label: "Order Notification + Inline Keyboard (Telegram)",
474
+ description:
475
+ "HTML-formatted Telegram notification with line-item list and InlineKeyboard buttons (works for both Merchant Channel Topics and Customer DM).",
476
+ channel: "telegram",
477
+ mode: "blocks",
478
+ default_event: "order.placed",
479
+ blocks: [
480
+ {
481
+ id: "blk_tg_1",
482
+ type: "heading",
483
+ position: 0,
484
+ parent_id: null,
485
+ metadata: {
486
+ text: "🛒 {{translations.order.placedTitle}} (#{{data.display_id}})",
487
+ },
488
+ },
489
+ {
490
+ id: "blk_tg_2",
491
+ type: "text",
492
+ position: 1,
493
+ parent_id: null,
494
+ metadata: {
495
+ text: "<b>{{translations.general.hello}} {{data.first_name}}</b>\n{{translations.order.placedIntro}}",
496
+ },
497
+ },
498
+ {
499
+ id: "blk_tg_3",
500
+ type: "repeater",
501
+ position: 2,
502
+ parent_id: null,
503
+ metadata: {
504
+ arrayKey: "items",
505
+ },
506
+ },
507
+ {
508
+ id: "blk_tg_3_child",
509
+ type: "product-item",
510
+ position: 0,
511
+ parent_id: "blk_tg_3",
512
+ metadata: {
513
+ variant: "order_item",
514
+ },
515
+ },
516
+ {
517
+ id: "blk_tg_4",
518
+ type: "row",
519
+ position: 3,
520
+ parent_id: null,
521
+ metadata: {
522
+ label: "{{translations.order.total}}",
523
+ value: "{{data.total_formatted}}",
524
+ bold: true,
525
+ },
526
+ },
527
+ {
528
+ id: "blk_tg_5",
529
+ type: "actions",
530
+ position: 4,
531
+ parent_id: null,
532
+ metadata: {
533
+ buttons: [
534
+ {
535
+ text: "{{translations.order.trackOrderButton}}",
536
+ url: "{{data.order_url}}",
537
+ },
538
+ {
539
+ text: "{{translations.general.viewInStore}}",
540
+ url: "{{data.store_url}}",
541
+ },
542
+ ],
543
+ },
544
+ },
545
+ ],
546
+ },
547
+ {
548
+ id: "system_telegram_inventory_low",
549
+ name: "inventory-low-telegram",
550
+ label: "Low Stock Ops Alert (Telegram Topic)",
551
+ description:
552
+ "Merchant operations alert formatted for Telegram supergroup topics.",
553
+ channel: "telegram",
554
+ mode: "blocks",
555
+ default_event: "inventory-level.updated",
556
+ blocks: [
557
+ {
558
+ id: "blk_tgi_1",
559
+ type: "heading",
560
+ position: 0,
561
+ parent_id: null,
562
+ metadata: {
563
+ text: "⚠️ {{translations.inventory.lowStockTitle}}",
564
+ },
565
+ },
566
+ {
567
+ id: "blk_tgi_2",
568
+ type: "product-item",
569
+ position: 1,
570
+ parent_id: null,
571
+ metadata: {
572
+ variant: "inventory_item",
573
+ },
574
+ },
575
+ ],
576
+ },
577
+
578
+ // =========================================================================
579
+ // 4. SMS PRESETS (GSM-7 Optimized Transactional, OTP & Cart Recovery)
580
+ // =========================================================================
581
+ {
582
+ id: "system_sms_order_placed",
583
+ name: "order-placed-sms",
584
+ label: "Order Confirmation (SMS)",
585
+ description:
586
+ "Single-segment GSM-7 order confirmation SMS with direct status link.",
587
+ channel: "sms",
588
+ mode: "raw",
589
+ default_event: "order.placed",
590
+ raw_content:
591
+ "{{data.store_name}}: {{translations.general.hello}} {{data.first_name}}, order #{{data.display_id}} ({{data.total_formatted}}) is confirmed! View status: {{data.order_url}}",
592
+ blocks: [],
593
+ },
594
+ {
595
+ id: "system_sms_shipment_created",
596
+ name: "shipment-created-sms",
597
+ label: "Order Shipped Tracking (SMS)",
598
+ description: "SMS shipping alert with carrier and tracking link.",
599
+ channel: "sms",
600
+ mode: "raw",
601
+ default_event: "shipment.created",
602
+ raw_content:
603
+ "{{data.store_name}}: Order #{{data.order_display_id}} shipped via {{data.carrier}} ({{data.tracking_number}}). Track: {{data.tracking_url}}",
604
+ blocks: [],
605
+ },
606
+ {
607
+ id: "system_sms_otp_code",
608
+ name: "otp-verification-sms",
609
+ label: "OTP Verification Code (SMS / Sandbox)",
610
+ description:
611
+ "One-Time Password verification SMS compatible with Twilio, SignalHouse, MSG91, and Dummy SMS Sandbox.",
612
+ channel: "sms",
613
+ mode: "raw",
614
+ default_event: "auth.otp_generated",
615
+ raw_content: "{{translations.customer.otpMessage}}",
616
+ blocks: [],
617
+ },
618
+ {
619
+ id: "system_sms_cart_recovery",
620
+ name: "abandoned-cart-recovery-sms",
621
+ label: "Abandoned Cart Recovery (SMS)",
622
+ description:
623
+ "10DLC-compliant abandoned cart recovery SMS with direct checkout resume link.",
624
+ channel: "sms",
625
+ mode: "raw",
626
+ default_event: "cart.abandoned",
627
+ raw_content:
628
+ "{{data.store_name}}: {{translations.general.hello}} {{data.first_name}}, {{translations.cart.recoveryIntro}} ({{data.total_formatted}}): {{data.recovery_url}}",
629
+ blocks: [],
630
+ },
631
+
632
+ // =========================================================================
633
+ // 5. SLACK PRESETS (Slack Block Kit JSON)
634
+ // =========================================================================
635
+ {
636
+ id: "system_slack_order_placed",
637
+ name: "order-placed-slack",
638
+ label: "New Order Alert (Slack Block Kit)",
639
+ description:
640
+ "Merchant Slack channel notification using Slack Block Kit header, sections, and action buttons.",
641
+ channel: "slack",
642
+ mode: "blocks",
643
+ default_event: "order.placed",
644
+ blocks: [
645
+ {
646
+ id: "blk_slk_1",
647
+ type: "heading",
648
+ position: 0,
649
+ parent_id: null,
650
+ metadata: {
651
+ text: "🎉 New Order #{{data.display_id}} ({{data.total_formatted}})",
652
+ },
653
+ },
654
+ {
655
+ id: "blk_slk_2",
656
+ type: "section",
657
+ position: 1,
658
+ parent_id: null,
659
+ metadata: {
660
+ text: "*Customer:* {{data.customer_name}} ({{data.email}})\n*Items:* {{data.items_count}} | *Payment:* {{data.payment_status}}",
661
+ },
662
+ },
663
+ {
664
+ id: "blk_slk_3",
665
+ type: "divider",
666
+ position: 2,
667
+ parent_id: null,
668
+ metadata: {},
669
+ },
670
+ {
671
+ id: "blk_slk_4",
672
+ type: "actions",
673
+ position: 3,
674
+ parent_id: null,
675
+ metadata: {
676
+ buttons: [
677
+ {
678
+ text: "View Order",
679
+ url: "{{data.order_url}}",
680
+ },
681
+ ],
682
+ },
683
+ },
684
+ ],
685
+ },
686
+ ...AUTH_SYSTEM_TEMPLATE_PRESETS,
687
+ ]
688
+
689
+ export function getSystemPresetById(
690
+ presetId: string
691
+ ): SystemTemplatePreset | undefined {
692
+ return SYSTEM_TEMPLATE_PRESETS.find(
693
+ (p) => p.id === presetId || p.name === presetId
694
+ )
695
+ }