@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.
- package/.medusa/server/src/admin/index.cjs +4215 -0
- package/.medusa/server/src/admin/index.js +4193 -0
- package/.medusa/server/src/api/admin/mpn/broadcasts/route.js +99 -0
- package/.medusa/server/src/api/admin/mpn/channels/route.js +109 -0
- package/.medusa/server/src/api/admin/mpn/logs/route.js +33 -0
- package/.medusa/server/src/api/admin/mpn/mappings/[id]/route.js +33 -0
- package/.medusa/server/src/api/admin/mpn/mappings/route.js +51 -0
- package/.medusa/server/src/api/admin/mpn/render-template/route.js +37 -0
- package/.medusa/server/src/api/admin/mpn/sandbox/route.js +36 -0
- package/.medusa/server/src/api/admin/mpn/send/route.js +135 -0
- package/.medusa/server/src/api/admin/mpn/templates/[id]/route.js +77 -0
- package/.medusa/server/src/api/admin/mpn/templates/route.js +71 -0
- package/.medusa/server/src/api/admin/plugin/route.js +4 -0
- package/.medusa/server/src/api/middlewares.js +28 -0
- package/.medusa/server/src/api/store/mpn/consent/route.js +37 -0
- package/.medusa/server/src/api/store/mpn/webhooks/[provider]/route.js +97 -0
- package/.medusa/server/src/api/store/plugin/route.js +4 -0
- package/.medusa/server/src/api/validators.js +118 -0
- package/.medusa/server/src/hooks/index.js +7 -0
- package/.medusa/server/src/hooks/use-mpn-channels.js +13 -0
- package/.medusa/server/src/hooks/use-mpn-dispatch.js +45 -0
- package/.medusa/server/src/hooks/use-mpn-mappings.js +21 -0
- package/.medusa/server/src/hooks/use-mpn-templates.js +34 -0
- package/.medusa/server/src/hooks/use-order-notifications-widget-state.js +79 -0
- package/.medusa/server/src/hooks/use-sdk-primitives.js +113 -0
- package/.medusa/server/src/index.js +14 -0
- package/.medusa/server/src/integrations/automations-action-handler.js +112 -0
- package/.medusa/server/src/jobs/abandoned-cart-recovery.js +123 -0
- package/.medusa/server/src/jobs/log-retention-and-broadcasts.js +15 -0
- package/.medusa/server/src/modules/notifications/i18n/index.js +65 -0
- package/.medusa/server/src/modules/notifications/i18n/locales/ar.js +76 -0
- package/.medusa/server/src/modules/notifications/i18n/locales/de.js +76 -0
- package/.medusa/server/src/modules/notifications/i18n/locales/en.js +76 -0
- package/.medusa/server/src/modules/notifications/i18n/locales/es.js +76 -0
- package/.medusa/server/src/modules/notifications/i18n/locales/fr.js +76 -0
- package/.medusa/server/src/modules/notifications/i18n/locales/it.js +76 -0
- package/.medusa/server/src/modules/notifications/i18n/locales/nl.js +76 -0
- package/.medusa/server/src/modules/notifications/i18n/locales/pl.js +76 -0
- package/.medusa/server/src/modules/notifications/i18n/locales/pt.js +76 -0
- package/.medusa/server/src/modules/notifications/i18n/locales/tr.js +76 -0
- package/.medusa/server/src/modules/notifications/i18n/types.js +2 -0
- package/.medusa/server/src/modules/notifications/index.js +9 -0
- package/.medusa/server/src/modules/notifications/integrations/documents-and-b2b-resolver.js +129 -0
- package/.medusa/server/src/modules/notifications/migrations/Migration20261010000000.js +184 -0
- package/.medusa/server/src/modules/notifications/models/index.js +118 -0
- package/.medusa/server/src/modules/notifications/renderer/block-helpers.js +36 -0
- package/.medusa/server/src/modules/notifications/renderer/email.js +161 -0
- package/.medusa/server/src/modules/notifications/renderer/index.js +240 -0
- package/.medusa/server/src/modules/notifications/renderer/slack.js +114 -0
- package/.medusa/server/src/modules/notifications/renderer/telegram.js +99 -0
- package/.medusa/server/src/modules/notifications/renderer/whatsapp.js +91 -0
- package/.medusa/server/src/modules/notifications/service-helpers/channel-config.js +45 -0
- package/.medusa/server/src/modules/notifications/service-helpers/consent.js +65 -0
- package/.medusa/server/src/modules/notifications/service-helpers/delivery-log.js +29 -0
- package/.medusa/server/src/modules/notifications/service-helpers/event-conditions.js +46 -0
- package/.medusa/server/src/modules/notifications/service-helpers/external-templates.js +80 -0
- package/.medusa/server/src/modules/notifications/service-helpers/recipient-resolution.js +85 -0
- package/.medusa/server/src/modules/notifications/service-helpers/sender-profiles.js +29 -0
- package/.medusa/server/src/modules/notifications/service-helpers/template-blocks.js +81 -0
- package/.medusa/server/src/modules/notifications/service-helpers/template-catalog.js +129 -0
- package/.medusa/server/src/modules/notifications/service-helpers/template-render.js +65 -0
- package/.medusa/server/src/modules/notifications/service.js +339 -0
- package/.medusa/server/src/modules/notifications/types.js +2 -0
- package/.medusa/server/src/modules/notifications/utils/auth-presets.js +140 -0
- package/.medusa/server/src/modules/notifications/utils/interpolation.js +178 -0
- package/.medusa/server/src/modules/notifications/utils/security.js +312 -0
- package/.medusa/server/src/modules/notifications/utils/system-presets.js +651 -0
- package/.medusa/server/src/modules/notifications/utils/transformers.js +358 -0
- package/.medusa/server/src/providers/dummy-sandbox/index.js +96 -0
- package/.medusa/server/src/providers/email-smtp/index.js +187 -0
- package/.medusa/server/src/providers/index.js +7 -0
- package/.medusa/server/src/providers/slack/index.js +54 -0
- package/.medusa/server/src/providers/sms/index.js +254 -0
- package/.medusa/server/src/providers/telegram/index.js +119 -0
- package/.medusa/server/src/providers/whatsapp/index.js +371 -0
- package/.medusa/server/src/rbac.js +109 -0
- package/.medusa/server/src/sdk/client.js +186 -0
- package/.medusa/server/src/sdk/index.js +3 -0
- package/.medusa/server/src/sdk/query-keys.js +61 -0
- package/.medusa/server/src/subscribers/customer-and-document-events.js +33 -0
- package/.medusa/server/src/subscribers/fulfillment-and-inventory-events.js +30 -0
- package/.medusa/server/src/subscribers/order-events.js +28 -0
- package/.medusa/server/src/types/constants.js +129 -0
- package/.medusa/server/src/types/core.js +2 -0
- package/.medusa/server/src/types/domain.js +2 -0
- package/.medusa/server/src/types/enums.js +53 -0
- package/.medusa/server/src/types/errors.js +28 -0
- package/.medusa/server/src/types/hooks.js +2 -0
- package/.medusa/server/src/types/index.js +12 -0
- package/.medusa/server/src/types/providers.js +2 -0
- package/.medusa/server/src/types/records.js +2 -0
- package/.medusa/server/src/types/render.js +2 -0
- package/.medusa/server/src/types/sdk-api.js +2 -0
- package/.medusa/server/src/types/translations.js +2 -0
- package/.medusa/server/src/workflows/index.js +461 -0
- package/LICENSE +21 -0
- package/README.md +389 -2
- package/package.json +138 -3
- package/src/admin/README.md +123 -0
- package/src/admin/components/mpn/broadcast-consent-section.tsx +62 -0
- package/src/admin/components/mpn/broadcasts-tab.tsx +208 -0
- package/src/admin/components/mpn/channels-main-section.tsx +205 -0
- package/src/admin/components/mpn/channels-side-section.tsx +88 -0
- package/src/admin/components/mpn/channels-tab.tsx +130 -0
- package/src/admin/components/mpn/constants.ts +8 -0
- package/src/admin/components/mpn/delivery-logs-tab.tsx +70 -0
- package/src/admin/components/mpn/event-mapping-form.tsx +191 -0
- package/src/admin/components/mpn/event-mappings-tab.tsx +165 -0
- package/src/admin/components/mpn/header-bar.tsx +35 -0
- package/src/admin/components/mpn/index.ts +17 -0
- package/src/admin/components/mpn/overview-cards.tsx +103 -0
- package/src/admin/components/mpn/sandbox-tab.tsx +93 -0
- package/src/admin/components/mpn/template-editor-section.tsx +203 -0
- package/src/admin/components/mpn/template-preview-section.tsx +122 -0
- package/src/admin/components/mpn/templates-list-section.tsx +115 -0
- package/src/admin/components/mpn/templates-tab.tsx +188 -0
- package/src/admin/components/mpn/use-notification-studio.ts +84 -0
- package/src/admin/components/rbac-guard.tsx +153 -0
- package/src/admin/i18n/README.md +134 -0
- package/src/admin/i18n/index.ts +23 -0
- package/src/admin/i18n/json/ar.json +157 -0
- package/src/admin/i18n/json/de.json +157 -0
- package/src/admin/i18n/json/en.json +157 -0
- package/src/admin/i18n/json/es.json +157 -0
- package/src/admin/i18n/json/fr.json +157 -0
- package/src/admin/i18n/json/it.json +157 -0
- package/src/admin/i18n/json/nl.json +157 -0
- package/src/admin/i18n/json/pl.json +157 -0
- package/src/admin/i18n/json/pt.json +157 -0
- package/src/admin/i18n/json/tr.json +157 -0
- package/src/admin/routes/mpn/broadcasts/page.tsx +75 -0
- package/src/admin/routes/mpn/channels/page.tsx +66 -0
- package/src/admin/routes/mpn/logs/page.tsx +50 -0
- package/src/admin/routes/mpn/mappings/page.tsx +62 -0
- package/src/admin/routes/mpn/page.tsx +200 -0
- package/src/admin/routes/mpn/sandbox/page.tsx +53 -0
- package/src/admin/routes/mpn/templates/page.tsx +55 -0
- package/src/admin/tsconfig.json +23 -0
- package/src/admin/vite-env.d.ts +1 -0
- package/src/admin/widgets/order-notifications-widget.tsx +178 -0
- package/src/api/README.md +98 -0
- package/src/api/admin/mpn/broadcasts/route.ts +130 -0
- package/src/api/admin/mpn/channels/route.ts +143 -0
- package/src/api/admin/mpn/logs/route.ts +41 -0
- package/src/api/admin/mpn/mappings/[id]/route.ts +45 -0
- package/src/api/admin/mpn/mappings/route.ts +68 -0
- package/src/api/admin/mpn/render-template/route.ts +46 -0
- package/src/api/admin/mpn/sandbox/route.ts +51 -0
- package/src/api/admin/mpn/send/route.ts +163 -0
- package/src/api/admin/mpn/templates/[id]/route.ts +101 -0
- package/src/api/admin/mpn/templates/route.ts +99 -0
- package/src/api/admin/plugin/route.ts +5 -0
- package/src/api/middlewares.ts +42 -0
- package/src/api/store/mpn/consent/route.ts +45 -0
- package/src/api/store/mpn/webhooks/[provider]/route.ts +119 -0
- package/src/api/store/plugin/route.ts +5 -0
- package/src/api/validators.ts +149 -0
- package/src/hooks/index.ts +14 -0
- package/src/hooks/use-mpn-channels.ts +43 -0
- package/src/hooks/use-mpn-dispatch.ts +149 -0
- package/src/hooks/use-mpn-mappings.ts +75 -0
- package/src/hooks/use-mpn-templates.ts +120 -0
- package/src/hooks/use-order-notifications-widget-state.ts +103 -0
- package/src/hooks/use-sdk-primitives.ts +157 -0
- package/src/index.ts +16 -0
- package/src/integrations/automations-action-handler.ts +156 -0
- package/src/jobs/README.md +41 -0
- package/src/jobs/abandoned-cart-recovery.ts +152 -0
- package/src/jobs/log-retention-and-broadcasts.ts +23 -0
- package/src/links/README.md +52 -0
- package/src/modules/README.md +99 -0
- package/src/modules/notifications/i18n/index.ts +83 -0
- package/src/modules/notifications/i18n/locales/ar.ts +84 -0
- package/src/modules/notifications/i18n/locales/de.ts +83 -0
- package/src/modules/notifications/i18n/locales/en.ts +84 -0
- package/src/modules/notifications/i18n/locales/es.ts +84 -0
- package/src/modules/notifications/i18n/locales/fr.ts +82 -0
- package/src/modules/notifications/i18n/locales/it.ts +82 -0
- package/src/modules/notifications/i18n/locales/nl.ts +83 -0
- package/src/modules/notifications/i18n/locales/pl.ts +84 -0
- package/src/modules/notifications/i18n/locales/pt.ts +82 -0
- package/src/modules/notifications/i18n/locales/tr.ts +86 -0
- package/src/modules/notifications/i18n/types.ts +1 -0
- package/src/modules/notifications/index.ts +10 -0
- package/src/modules/notifications/integrations/documents-and-b2b-resolver.ts +168 -0
- package/src/modules/notifications/migrations/Migration20261010000000.ts +185 -0
- package/src/modules/notifications/models/index.ts +125 -0
- package/src/modules/notifications/renderer/block-helpers.ts +51 -0
- package/src/modules/notifications/renderer/email.ts +281 -0
- package/src/modules/notifications/renderer/index.ts +301 -0
- package/src/modules/notifications/renderer/slack.ts +168 -0
- package/src/modules/notifications/renderer/telegram.ts +161 -0
- package/src/modules/notifications/renderer/whatsapp.ts +156 -0
- package/src/modules/notifications/service-helpers/channel-config.ts +65 -0
- package/src/modules/notifications/service-helpers/consent.ts +88 -0
- package/src/modules/notifications/service-helpers/delivery-log.ts +56 -0
- package/src/modules/notifications/service-helpers/event-conditions.ts +66 -0
- package/src/modules/notifications/service-helpers/external-templates.ts +127 -0
- package/src/modules/notifications/service-helpers/recipient-resolution.ts +124 -0
- package/src/modules/notifications/service-helpers/sender-profiles.ts +34 -0
- package/src/modules/notifications/service-helpers/template-blocks.ts +116 -0
- package/src/modules/notifications/service-helpers/template-catalog.ts +170 -0
- package/src/modules/notifications/service-helpers/template-render.ts +113 -0
- package/src/modules/notifications/service.ts +588 -0
- package/src/modules/notifications/types.ts +1 -0
- package/src/modules/notifications/utils/auth-presets.ts +145 -0
- package/src/modules/notifications/utils/interpolation.ts +231 -0
- package/src/modules/notifications/utils/security.ts +378 -0
- package/src/modules/notifications/utils/system-presets.ts +695 -0
- package/src/modules/notifications/utils/transformers.ts +456 -0
- package/src/providers/README.md +92 -0
- package/src/providers/dummy-sandbox/index.ts +143 -0
- package/src/providers/email-smtp/index.ts +257 -0
- package/src/providers/index.ts +38 -0
- package/src/providers/slack/index.ts +82 -0
- package/src/providers/sms/index.ts +342 -0
- package/src/providers/telegram/index.ts +181 -0
- package/src/providers/whatsapp/index.ts +505 -0
- package/src/rbac.ts +123 -0
- package/src/sdk/client.ts +319 -0
- package/src/sdk/index.ts +48 -0
- package/src/sdk/query-keys.ts +89 -0
- package/src/subscribers/README.md +50 -0
- package/src/subscribers/customer-and-document-events.ts +36 -0
- package/src/subscribers/fulfillment-and-inventory-events.ts +35 -0
- package/src/subscribers/order-events.ts +31 -0
- package/src/types/constants.ts +143 -0
- package/src/types/core.ts +96 -0
- package/src/types/domain.ts +84 -0
- package/src/types/enums.ts +73 -0
- package/src/types/errors.ts +32 -0
- package/src/types/hooks.ts +48 -0
- package/src/types/index.ts +11 -0
- package/src/types/providers.ts +96 -0
- package/src/types/records.ts +100 -0
- package/src/types/render.ts +74 -0
- package/src/types/sdk-api.ts +228 -0
- package/src/types/translations.ts +75 -0
- package/src/workflows/README.md +67 -0
- package/src/workflows/index.ts +619 -0
- package/tsconfig.json +40 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { NotificationTranslationDictionary } from "../types"
|
|
2
|
+
|
|
3
|
+
export const pt: NotificationTranslationDictionary = {
|
|
4
|
+
general: {
|
|
5
|
+
hello: "Olá",
|
|
6
|
+
thankYou: "Obrigado por comprar conosco!",
|
|
7
|
+
questionsContact: "Se tiver dúvidas, responda a esta mensagem.",
|
|
8
|
+
viewInStore: "Visitar Loja",
|
|
9
|
+
poweredBy: "Enviado por",
|
|
10
|
+
unsubscribeSms: "Responda STOP para cancelar.",
|
|
11
|
+
},
|
|
12
|
+
order: {
|
|
13
|
+
placedSubject: "Pedido #{{data.display_id}} Confirmado",
|
|
14
|
+
placedTitle: "Obrigado pelo seu pedido!",
|
|
15
|
+
placedIntro:
|
|
16
|
+
"Recebemos o seu pedido #{{data.display_id}} e estamos preparando o envio.",
|
|
17
|
+
completedSubject: "Pedido #{{data.display_id}} Concluído",
|
|
18
|
+
completedTitle: "Seu pedido foi concluído",
|
|
19
|
+
canceledSubject: "Pedido #{{data.display_id}} Cancelado",
|
|
20
|
+
canceledTitle: "Seu pedido foi cancelado",
|
|
21
|
+
updatedSubject: "Pedido #{{data.display_id}} Atualizado",
|
|
22
|
+
updatedTitle: "Seu pedido foi atualizado",
|
|
23
|
+
orderNumber: "Número do Pedido",
|
|
24
|
+
orderDate: "Data",
|
|
25
|
+
orderStatus: "Status",
|
|
26
|
+
paymentStatus: "Pagamento",
|
|
27
|
+
fulfillmentStatus: "Envio",
|
|
28
|
+
itemsHeader: "Itens do Pedido",
|
|
29
|
+
quantity: "Qtd",
|
|
30
|
+
unitPrice: "Preço",
|
|
31
|
+
subtotal: "Subtotal",
|
|
32
|
+
shipping: "Frete",
|
|
33
|
+
tax: "Impostos",
|
|
34
|
+
discount: "Desconto",
|
|
35
|
+
total: "Total",
|
|
36
|
+
shippingAddress: "Endereço de Entrega",
|
|
37
|
+
billingAddress: "Endereço de Cobrança",
|
|
38
|
+
trackOrderButton: "Ver Pedido",
|
|
39
|
+
downloadInvoiceButton: "Baixar Fatura PDF",
|
|
40
|
+
},
|
|
41
|
+
shipment: {
|
|
42
|
+
shippedSubject: "Seu Pedido #{{data.order_display_id}} foi enviado!",
|
|
43
|
+
shippedTitle: "Sua encomenda está a caminho",
|
|
44
|
+
shippedIntro:
|
|
45
|
+
"O pedido #{{data.order_display_id}} foi entregue à transportadora.",
|
|
46
|
+
deliveredSubject: "Pedido #{{data.order_display_id}} Entregue",
|
|
47
|
+
deliveredTitle: "Seu pedido foi entregue",
|
|
48
|
+
carrier: "Transportadora",
|
|
49
|
+
trackingNumber: "Código de Rastreio",
|
|
50
|
+
trackPackageButton: "Rastrear Pedido",
|
|
51
|
+
},
|
|
52
|
+
inventory: {
|
|
53
|
+
lowStockSubject: "[Alerta de Estoque] Estoque baixo para {{data.sku}}",
|
|
54
|
+
lowStockTitle: "Alerta de Estoque Baixo",
|
|
55
|
+
sku: "SKU",
|
|
56
|
+
location: "Localização",
|
|
57
|
+
stockedQuantity: "Em estoque",
|
|
58
|
+
reservedQuantity: "Reservado",
|
|
59
|
+
availableQuantity: "Disponível",
|
|
60
|
+
},
|
|
61
|
+
customer: {
|
|
62
|
+
welcomeSubject: "Bem-vindo à {{data.store_name}}!",
|
|
63
|
+
welcomeTitle: "Bem-vindo!",
|
|
64
|
+
welcomeIntro: "Sua conta está pronta.",
|
|
65
|
+
otpSubject: "Seu código de verificação é {{data.otp_code}}",
|
|
66
|
+
otpMessage:
|
|
67
|
+
"Seu código {{data.store_name}} é {{data.otp_code}}. Válido por {{data.expires_in_minutes}} minutos.",
|
|
68
|
+
},
|
|
69
|
+
cart: {
|
|
70
|
+
recoverySubject: "Você deixou itens no carrinho na {{data.store_name}}",
|
|
71
|
+
recoveryTitle: "Esqueceu alguma coisa?",
|
|
72
|
+
recoveryIntro: "Seu carrinho está salvo esperando por você.",
|
|
73
|
+
resumeCartButton: "Finalizar Compra",
|
|
74
|
+
},
|
|
75
|
+
document: {
|
|
76
|
+
readySubject:
|
|
77
|
+
"Documento {{data.document_number}} do Pedido #{{data.order_display_id}}",
|
|
78
|
+
readyTitle: "Seu documento fiscal está em anexo",
|
|
79
|
+
readyIntro:
|
|
80
|
+
"Segue em anexo {{data.document_type_label}} {{data.document_number}}.",
|
|
81
|
+
},
|
|
82
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { NotificationTranslationDictionary } from "../types"
|
|
2
|
+
|
|
3
|
+
export const tr: NotificationTranslationDictionary = {
|
|
4
|
+
general: {
|
|
5
|
+
hello: "Merhaba",
|
|
6
|
+
thankYou: "Bizi tercih ettiğiniz için teşekkür ederiz!",
|
|
7
|
+
questionsContact:
|
|
8
|
+
"Herhangi bir sorunuz varsa bu mesaja yanıt verebilir veya destek ekibimizle iletişime geçebilirsiniz.",
|
|
9
|
+
viewInStore: "Mağazayı Ziyaret Et",
|
|
10
|
+
poweredBy: "Gönderen",
|
|
11
|
+
unsubscribeSms: "İptal etmek için STOP yazıp yanıtlayın.",
|
|
12
|
+
},
|
|
13
|
+
order: {
|
|
14
|
+
placedSubject: "Sipariş #{{data.display_id}} Onaylandı",
|
|
15
|
+
placedTitle: "Siparişiniz için teşekkür ederiz!",
|
|
16
|
+
placedIntro:
|
|
17
|
+
"#{{data.display_id}} numaralı siparişinizi aldık ve gönderim için hazırlıyoruz.",
|
|
18
|
+
completedSubject: "Sipariş #{{data.display_id}} Tamamlandı",
|
|
19
|
+
completedTitle: "Siparişiniz tamamlandı",
|
|
20
|
+
canceledSubject: "Sipariş #{{data.display_id}} İptal Edildi",
|
|
21
|
+
canceledTitle: "Siparişiniz iptal edildi",
|
|
22
|
+
updatedSubject: "Sipariş #{{data.display_id}} Güncellendi",
|
|
23
|
+
updatedTitle: "Sipariş bilgileriniz güncellendi",
|
|
24
|
+
orderNumber: "Sipariş Numarası",
|
|
25
|
+
orderDate: "Sipariş Tarihi",
|
|
26
|
+
orderStatus: "Durum",
|
|
27
|
+
paymentStatus: "Ödeme",
|
|
28
|
+
fulfillmentStatus: "Teslimat Durumu",
|
|
29
|
+
itemsHeader: "Sipariş Edilen Ürünler",
|
|
30
|
+
quantity: "Adet",
|
|
31
|
+
unitPrice: "Birim Fiyat",
|
|
32
|
+
subtotal: "Ara Toplam",
|
|
33
|
+
shipping: "Kargo",
|
|
34
|
+
tax: "KDV",
|
|
35
|
+
discount: "İndirim",
|
|
36
|
+
total: "Toplam",
|
|
37
|
+
shippingAddress: "Teslimat Adresi",
|
|
38
|
+
billingAddress: "Fatura Adresi",
|
|
39
|
+
trackOrderButton: "Sipariş Durumunu Görüntüle",
|
|
40
|
+
downloadInvoiceButton: "PDF Faturayı İndir",
|
|
41
|
+
},
|
|
42
|
+
shipment: {
|
|
43
|
+
shippedSubject:
|
|
44
|
+
"#{{data.order_display_id}} Numaralı Siparişiniz Kargoya Verildi!",
|
|
45
|
+
shippedTitle: "Paketiniz yola çıktı",
|
|
46
|
+
shippedIntro:
|
|
47
|
+
"#{{data.order_display_id}} numaralı siparişiniz kargo firmasına teslim edildi.",
|
|
48
|
+
deliveredSubject: "Sipariş #{{data.order_display_id}} Teslim Edildi",
|
|
49
|
+
deliveredTitle: "Siparişiniz teslim edildi",
|
|
50
|
+
carrier: "Kargo Firması",
|
|
51
|
+
trackingNumber: "Takip Numarası",
|
|
52
|
+
trackPackageButton: "Kargoyu Takip Et",
|
|
53
|
+
},
|
|
54
|
+
inventory: {
|
|
55
|
+
lowStockSubject: "[Stok Uyarısı] {{data.sku}} için düşük stok",
|
|
56
|
+
lowStockTitle: "Düşük Stok Uyarısı",
|
|
57
|
+
sku: "Stok Kodu (SKU)",
|
|
58
|
+
location: "Depo Konumu",
|
|
59
|
+
stockedQuantity: "Stok Miktarı",
|
|
60
|
+
reservedQuantity: "Rezerve Edilen",
|
|
61
|
+
availableQuantity: "Kullanılabilir",
|
|
62
|
+
},
|
|
63
|
+
customer: {
|
|
64
|
+
welcomeSubject: "{{data.store_name}} mağazasına hoş geldiniz!",
|
|
65
|
+
welcomeTitle: "Aramıza hoş geldiniz!",
|
|
66
|
+
welcomeIntro:
|
|
67
|
+
"Müşteri hesabınız hazır. Hızlı alışveriş ve anlık sipariş bildirimlerinin keyfini çıkarın.",
|
|
68
|
+
otpSubject: "Doğrulama kodunuz: {{data.otp_code}}",
|
|
69
|
+
otpMessage:
|
|
70
|
+
"{{data.store_name}} doğrulama kodunuz: {{data.otp_code}}. {{data.expires_in_minutes}} dakika boyunca geçerlidir.",
|
|
71
|
+
},
|
|
72
|
+
cart: {
|
|
73
|
+
recoverySubject: "{{data.store_name}} sepetinizde ürünler bıraktınız",
|
|
74
|
+
recoveryTitle: "Sepetinizi unuttunuz mu?",
|
|
75
|
+
recoveryIntro:
|
|
76
|
+
"Sepetinizdeki ürünleri sizin için sakladık, istediğiniz zaman alışverişinizi tamamlayabilirsiniz.",
|
|
77
|
+
resumeCartButton: "Siparişi Tamamla",
|
|
78
|
+
},
|
|
79
|
+
document: {
|
|
80
|
+
readySubject:
|
|
81
|
+
"Sipariş #{{data.order_display_id}} için Belge {{data.document_number}}",
|
|
82
|
+
readyTitle: "Ticari belgeniz ektedir",
|
|
83
|
+
readyIntro:
|
|
84
|
+
"#{{data.order_display_id}} numaralı siparişinize ait {{data.document_type_label}} ({{data.document_number}}) ekte yer almaktadır.",
|
|
85
|
+
},
|
|
86
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { NotificationTranslationDictionary } from "../../../types"
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Module } from "@medusajs/framework/utils"
|
|
2
|
+
import NotificationsModuleService from "./service"
|
|
3
|
+
import { NOTIFICATIONS_MODULE } from "./types"
|
|
4
|
+
|
|
5
|
+
export default Module(NOTIFICATIONS_MODULE, {
|
|
6
|
+
service: NotificationsModuleService,
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
export * from "./types"
|
|
10
|
+
export { NotificationsModuleService }
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
B2BNotificationContacts,
|
|
3
|
+
NotificationAttachment,
|
|
4
|
+
} from "../../../types"
|
|
5
|
+
|
|
6
|
+
export type { B2BNotificationContacts } from "../../../types"
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Zero-hard-dependency B2B buyer & accounting contact resolver.
|
|
10
|
+
* Safely checks optional B2B module or order/customer metadata without breaking B2C stores.
|
|
11
|
+
*/
|
|
12
|
+
export async function resolveB2BNotificationContacts(
|
|
13
|
+
container: { resolve?: (key: string) => any } | null | undefined,
|
|
14
|
+
order: Record<string, any> | null | undefined
|
|
15
|
+
): Promise<B2BNotificationContacts> {
|
|
16
|
+
if (!order) return {}
|
|
17
|
+
|
|
18
|
+
const meta = (order.metadata || {}) as Record<string, any>
|
|
19
|
+
const customerMeta = (order.customer?.metadata || {}) as Record<string, any>
|
|
20
|
+
|
|
21
|
+
let companyName: string | null =
|
|
22
|
+
meta.b2b_company_name ||
|
|
23
|
+
customerMeta.b2b_company_name ||
|
|
24
|
+
order.billing_address?.company ||
|
|
25
|
+
order.shipping_address?.company ||
|
|
26
|
+
null
|
|
27
|
+
|
|
28
|
+
let accountingEmail: string | null =
|
|
29
|
+
meta.b2b_accounting_email ||
|
|
30
|
+
customerMeta.b2b_accounting_email ||
|
|
31
|
+
meta.accounting_email ||
|
|
32
|
+
null
|
|
33
|
+
|
|
34
|
+
let buyerEmail: string | null =
|
|
35
|
+
meta.b2b_buyer_email ||
|
|
36
|
+
customerMeta.b2b_buyer_email ||
|
|
37
|
+
order.email ||
|
|
38
|
+
order.customer?.email ||
|
|
39
|
+
null
|
|
40
|
+
|
|
41
|
+
let buyerPhone: string | null =
|
|
42
|
+
meta.b2b_buyer_phone ||
|
|
43
|
+
customerMeta.b2b_buyer_phone ||
|
|
44
|
+
order.shipping_address?.phone ||
|
|
45
|
+
order.billing_address?.phone ||
|
|
46
|
+
order.customer?.phone ||
|
|
47
|
+
null
|
|
48
|
+
|
|
49
|
+
let telegramChatId: string | null =
|
|
50
|
+
meta.telegram_chat_id || customerMeta.telegram_chat_id || null
|
|
51
|
+
|
|
52
|
+
if (container && typeof container.resolve === "function") {
|
|
53
|
+
for (const candidateKey of [
|
|
54
|
+
"b2bModuleService",
|
|
55
|
+
"companyModuleService",
|
|
56
|
+
"b2b",
|
|
57
|
+
]) {
|
|
58
|
+
try {
|
|
59
|
+
const b2bService = container.resolve(candidateKey)
|
|
60
|
+
if (
|
|
61
|
+
b2bService &&
|
|
62
|
+
typeof b2bService.resolveBuyerContext === "function"
|
|
63
|
+
) {
|
|
64
|
+
const resolved = await b2bService.resolveBuyerContext(order.id)
|
|
65
|
+
if (resolved) {
|
|
66
|
+
companyName = resolved.company_name || companyName
|
|
67
|
+
accountingEmail = resolved.accounting_email || accountingEmail
|
|
68
|
+
buyerEmail = resolved.buyer_contact_email || buyerEmail
|
|
69
|
+
buyerPhone = resolved.buyer_phone || buyerPhone
|
|
70
|
+
}
|
|
71
|
+
break
|
|
72
|
+
}
|
|
73
|
+
} catch {
|
|
74
|
+
// Optional B2B module not installed; fall back to metadata
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
company_name: companyName,
|
|
81
|
+
buyer_contact_email: buyerEmail,
|
|
82
|
+
accounting_email: accountingEmail || buyerEmail,
|
|
83
|
+
buyer_phone: buyerPhone,
|
|
84
|
+
telegram_chat_id: telegramChatId ? String(telegramChatId) : null,
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Zero-hard-dependency integration with sibling `medusa-documents-plugin` (`documentsModuleService`).
|
|
90
|
+
* When an Event Mapping requests `attach_document_types: ["invoice", "packing_slip"]`,
|
|
91
|
+
* this helper fetches existing PDF buffers (or triggers on-demand generation) and returns
|
|
92
|
+
* base64 `NotificationAttachment[]` ready for Email, WhatsApp/OpenWA, or Telegram `sendDocument`.
|
|
93
|
+
*/
|
|
94
|
+
export async function resolveOrderDocumentAttachments(
|
|
95
|
+
container: { resolve?: (key: string) => any } | null | undefined,
|
|
96
|
+
orderId: string | null | undefined,
|
|
97
|
+
documentTypes?: string[] | null
|
|
98
|
+
): Promise<NotificationAttachment[]> {
|
|
99
|
+
if (
|
|
100
|
+
!container ||
|
|
101
|
+
typeof container.resolve !== "function" ||
|
|
102
|
+
!orderId ||
|
|
103
|
+
!Array.isArray(documentTypes) ||
|
|
104
|
+
documentTypes.length === 0
|
|
105
|
+
) {
|
|
106
|
+
return []
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
let documentsService: any = null
|
|
110
|
+
for (const key of ["documentsModuleService", "documents"]) {
|
|
111
|
+
try {
|
|
112
|
+
documentsService = container.resolve(key)
|
|
113
|
+
if (documentsService) break
|
|
114
|
+
} catch {
|
|
115
|
+
// Sibling plugin not registered in container
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (!documentsService) {
|
|
120
|
+
return []
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const attachments: NotificationAttachment[] = []
|
|
124
|
+
|
|
125
|
+
for (const docType of documentTypes) {
|
|
126
|
+
try {
|
|
127
|
+
let targetDoc: any = null
|
|
128
|
+
if (typeof documentsService.listDocuments === "function") {
|
|
129
|
+
const existing = await documentsService.listDocuments({
|
|
130
|
+
order_id: orderId,
|
|
131
|
+
document_type: docType,
|
|
132
|
+
})
|
|
133
|
+
if (Array.isArray(existing) && existing.length > 0) {
|
|
134
|
+
targetDoc = existing[0]
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (
|
|
139
|
+
targetDoc &&
|
|
140
|
+
typeof documentsService.getDocumentPdfBuffer === "function"
|
|
141
|
+
) {
|
|
142
|
+
const { buffer, document } =
|
|
143
|
+
await documentsService.getDocumentPdfBuffer(targetDoc.id)
|
|
144
|
+
if (buffer && Buffer.isBuffer(buffer)) {
|
|
145
|
+
const docNum =
|
|
146
|
+
document?.document_number ||
|
|
147
|
+
targetDoc.document_number ||
|
|
148
|
+
targetDoc.id
|
|
149
|
+
const cleanName = `${docType}-${docNum}.pdf`.replace(
|
|
150
|
+
/[^a-zA-Z0-9._-]/g,
|
|
151
|
+
"-"
|
|
152
|
+
)
|
|
153
|
+
attachments.push({
|
|
154
|
+
filename: cleanName,
|
|
155
|
+
content: buffer.toString("base64"),
|
|
156
|
+
content_type: "application/pdf",
|
|
157
|
+
document_type: docType,
|
|
158
|
+
document_number: String(docNum),
|
|
159
|
+
})
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
} catch {
|
|
163
|
+
// Never block notification delivery if PDF retrieval fails
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return attachments
|
|
168
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { Migration } from "@mikro-orm/migrations"
|
|
2
|
+
|
|
3
|
+
export class Migration20261010000000 extends Migration {
|
|
4
|
+
async up(): Promise<void> {
|
|
5
|
+
this.addSql(`
|
|
6
|
+
CREATE TABLE IF NOT EXISTS "mpn_template" (
|
|
7
|
+
"id" TEXT NOT NULL PRIMARY KEY,
|
|
8
|
+
"name" TEXT NOT NULL,
|
|
9
|
+
"label" TEXT NOT NULL,
|
|
10
|
+
"description" TEXT NULL,
|
|
11
|
+
"channel" TEXT NOT NULL DEFAULT 'email',
|
|
12
|
+
"mode" TEXT NOT NULL DEFAULT 'blocks',
|
|
13
|
+
"locale" TEXT NOT NULL DEFAULT 'en',
|
|
14
|
+
"subject" TEXT NULL,
|
|
15
|
+
"raw_content" TEXT NULL,
|
|
16
|
+
"variable_map" JSONB NULL,
|
|
17
|
+
"meta_template_name" TEXT NULL,
|
|
18
|
+
"meta_language_code" TEXT NULL,
|
|
19
|
+
"styles" JSONB NULL,
|
|
20
|
+
"is_active" BOOLEAN NOT NULL DEFAULT TRUE,
|
|
21
|
+
"source_preset_id" TEXT NULL,
|
|
22
|
+
"metadata" JSONB NULL,
|
|
23
|
+
"created_at" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
24
|
+
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
25
|
+
"deleted_at" TIMESTAMPTZ NULL
|
|
26
|
+
);
|
|
27
|
+
CREATE INDEX IF NOT EXISTS "IDX_mpn_template_channel_locale" ON "mpn_template" ("channel", "locale") WHERE "deleted_at" IS NULL;
|
|
28
|
+
CREATE INDEX IF NOT EXISTS "IDX_mpn_template_name" ON "mpn_template" ("name") WHERE "deleted_at" IS NULL;
|
|
29
|
+
|
|
30
|
+
CREATE TABLE IF NOT EXISTS "mpn_template_block" (
|
|
31
|
+
"id" TEXT NOT NULL PRIMARY KEY,
|
|
32
|
+
"template_id" TEXT NOT NULL,
|
|
33
|
+
"type" TEXT NOT NULL,
|
|
34
|
+
"position" INTEGER NOT NULL DEFAULT 0,
|
|
35
|
+
"parent_id" TEXT NULL,
|
|
36
|
+
"metadata" JSONB NULL,
|
|
37
|
+
"created_at" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
38
|
+
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
39
|
+
"deleted_at" TIMESTAMPTZ NULL
|
|
40
|
+
);
|
|
41
|
+
CREATE INDEX IF NOT EXISTS "IDX_mpn_template_block_template_id" ON "mpn_template_block" ("template_id", "position") WHERE "deleted_at" IS NULL;
|
|
42
|
+
|
|
43
|
+
CREATE TABLE IF NOT EXISTS "mpn_event_mapping" (
|
|
44
|
+
"id" TEXT NOT NULL PRIMARY KEY,
|
|
45
|
+
"event_name" TEXT NOT NULL,
|
|
46
|
+
"channel" TEXT NOT NULL DEFAULT 'email',
|
|
47
|
+
"template_id" TEXT NOT NULL,
|
|
48
|
+
"recipient_rule" TEXT NOT NULL DEFAULT 'customer_auto',
|
|
49
|
+
"custom_recipient" TEXT NULL,
|
|
50
|
+
"sender_profile_index" INTEGER NOT NULL DEFAULT 1,
|
|
51
|
+
"telegram_thread_id" INTEGER NULL,
|
|
52
|
+
"attach_document_types" JSONB NULL,
|
|
53
|
+
"variable_map" JSONB NULL,
|
|
54
|
+
"conditions" JSONB NULL,
|
|
55
|
+
"is_active" BOOLEAN NOT NULL DEFAULT TRUE,
|
|
56
|
+
"priority" INTEGER NOT NULL DEFAULT 0,
|
|
57
|
+
"metadata" JSONB NULL,
|
|
58
|
+
"created_at" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
59
|
+
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
60
|
+
"deleted_at" TIMESTAMPTZ NULL
|
|
61
|
+
);
|
|
62
|
+
CREATE INDEX IF NOT EXISTS "IDX_mpn_event_mapping_event_active" ON "mpn_event_mapping" ("event_name", "is_active") WHERE "deleted_at" IS NULL;
|
|
63
|
+
|
|
64
|
+
CREATE TABLE IF NOT EXISTS "mpn_delivery_log" (
|
|
65
|
+
"id" TEXT NOT NULL PRIMARY KEY,
|
|
66
|
+
"idempotency_key" TEXT NOT NULL,
|
|
67
|
+
"event_name" TEXT NOT NULL,
|
|
68
|
+
"entity_id" TEXT NULL,
|
|
69
|
+
"channel" TEXT NOT NULL,
|
|
70
|
+
"provider_id" TEXT NULL,
|
|
71
|
+
"driver" TEXT NULL,
|
|
72
|
+
"template_id" TEXT NULL,
|
|
73
|
+
"mapping_id" TEXT NULL,
|
|
74
|
+
"recipient_masked" TEXT NOT NULL,
|
|
75
|
+
"recipient_hash" TEXT NOT NULL,
|
|
76
|
+
"status" TEXT NOT NULL DEFAULT 'pending',
|
|
77
|
+
"attempts" INTEGER NOT NULL DEFAULT 1,
|
|
78
|
+
"external_message_id" TEXT NULL,
|
|
79
|
+
"payload_redacted" JSONB NULL,
|
|
80
|
+
"error_code" TEXT NULL,
|
|
81
|
+
"error_message" TEXT NULL,
|
|
82
|
+
"sent_at" TIMESTAMPTZ NULL,
|
|
83
|
+
"delivered_at" TIMESTAMPTZ NULL,
|
|
84
|
+
"created_at" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
85
|
+
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
86
|
+
"deleted_at" TIMESTAMPTZ NULL
|
|
87
|
+
);
|
|
88
|
+
CREATE UNIQUE INDEX IF NOT EXISTS "UQ_mpn_delivery_log_idempotency_active"
|
|
89
|
+
ON "mpn_delivery_log" ("idempotency_key")
|
|
90
|
+
WHERE "status" IN ('pending', 'sent', 'delivered') AND "deleted_at" IS NULL;
|
|
91
|
+
CREATE INDEX IF NOT EXISTS "IDX_mpn_delivery_log_entity_id" ON "mpn_delivery_log" ("entity_id", "created_at" DESC) WHERE "deleted_at" IS NULL;
|
|
92
|
+
CREATE INDEX IF NOT EXISTS "IDX_mpn_delivery_log_channel_status" ON "mpn_delivery_log" ("channel", "status") WHERE "deleted_at" IS NULL;
|
|
93
|
+
|
|
94
|
+
CREATE TABLE IF NOT EXISTS "mpn_consent_record" (
|
|
95
|
+
"id" TEXT NOT NULL PRIMARY KEY,
|
|
96
|
+
"identifier" TEXT NOT NULL,
|
|
97
|
+
"channel" TEXT NOT NULL DEFAULT 'sms',
|
|
98
|
+
"customer_id" TEXT NULL,
|
|
99
|
+
"status" TEXT NOT NULL DEFAULT 'opted_in',
|
|
100
|
+
"source" TEXT NOT NULL DEFAULT 'checkout',
|
|
101
|
+
"first_message_sent" BOOLEAN NOT NULL DEFAULT FALSE,
|
|
102
|
+
"last_cart_recovery_at" TIMESTAMPTZ NULL,
|
|
103
|
+
"opted_in_at" TIMESTAMPTZ NULL,
|
|
104
|
+
"opted_out_at" TIMESTAMPTZ NULL,
|
|
105
|
+
"metadata" JSONB NULL,
|
|
106
|
+
"created_at" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
107
|
+
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
108
|
+
"deleted_at" TIMESTAMPTZ NULL
|
|
109
|
+
);
|
|
110
|
+
CREATE UNIQUE INDEX IF NOT EXISTS "UQ_mpn_consent_identifier_channel"
|
|
111
|
+
ON "mpn_consent_record" ("identifier", "channel")
|
|
112
|
+
WHERE "deleted_at" IS NULL;
|
|
113
|
+
CREATE INDEX IF NOT EXISTS "IDX_mpn_consent_customer" ON "mpn_consent_record" ("customer_id") WHERE "deleted_at" IS NULL;
|
|
114
|
+
|
|
115
|
+
CREATE TABLE IF NOT EXISTS "mpn_broadcast_campaign" (
|
|
116
|
+
"id" TEXT NOT NULL PRIMARY KEY,
|
|
117
|
+
"name" TEXT NOT NULL,
|
|
118
|
+
"channel" TEXT NOT NULL DEFAULT 'sms',
|
|
119
|
+
"template_id" TEXT NOT NULL,
|
|
120
|
+
"customer_group_id" TEXT NULL,
|
|
121
|
+
"custom_recipients" JSONB NULL,
|
|
122
|
+
"status" TEXT NOT NULL DEFAULT 'draft',
|
|
123
|
+
"scheduled_at" TIMESTAMPTZ NULL,
|
|
124
|
+
"sent_at" TIMESTAMPTZ NULL,
|
|
125
|
+
"total_recipients" INTEGER NOT NULL DEFAULT 0,
|
|
126
|
+
"sent_count" INTEGER NOT NULL DEFAULT 0,
|
|
127
|
+
"failed_count" INTEGER NOT NULL DEFAULT 0,
|
|
128
|
+
"attributed_orders_count" INTEGER NOT NULL DEFAULT 0,
|
|
129
|
+
"attributed_revenue" NUMERIC NOT NULL DEFAULT 0,
|
|
130
|
+
"metadata" JSONB NULL,
|
|
131
|
+
"created_at" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
132
|
+
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
133
|
+
"deleted_at" TIMESTAMPTZ NULL
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
CREATE TABLE IF NOT EXISTS "mpn_channel_config" (
|
|
137
|
+
"id" TEXT NOT NULL PRIMARY KEY,
|
|
138
|
+
"channel" TEXT NOT NULL,
|
|
139
|
+
"driver" TEXT NOT NULL DEFAULT 'default',
|
|
140
|
+
"is_enabled" BOOLEAN NOT NULL DEFAULT TRUE,
|
|
141
|
+
"is_verified" BOOLEAN NOT NULL DEFAULT FALSE,
|
|
142
|
+
"verified_at" TIMESTAMPTZ NULL,
|
|
143
|
+
"rate_limit_per_sec" INTEGER NOT NULL DEFAULT 10,
|
|
144
|
+
"config_json" JSONB NULL,
|
|
145
|
+
"created_at" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
146
|
+
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
147
|
+
"deleted_at" TIMESTAMPTZ NULL
|
|
148
|
+
);
|
|
149
|
+
CREATE UNIQUE INDEX IF NOT EXISTS "UQ_mpn_channel_config_channel"
|
|
150
|
+
ON "mpn_channel_config" ("channel")
|
|
151
|
+
WHERE "deleted_at" IS NULL;
|
|
152
|
+
|
|
153
|
+
CREATE TABLE IF NOT EXISTS "mpn_sandbox_message" (
|
|
154
|
+
"id" TEXT NOT NULL PRIMARY KEY,
|
|
155
|
+
"channel" TEXT NOT NULL DEFAULT 'sms',
|
|
156
|
+
"recipient" TEXT NOT NULL,
|
|
157
|
+
"sender" TEXT NULL,
|
|
158
|
+
"subject" TEXT NULL,
|
|
159
|
+
"body" TEXT NOT NULL,
|
|
160
|
+
"html" TEXT NULL,
|
|
161
|
+
"otp_code" TEXT NULL,
|
|
162
|
+
"media_urls" JSONB NULL,
|
|
163
|
+
"attachments_meta" JSONB NULL,
|
|
164
|
+
"metadata" JSONB NULL,
|
|
165
|
+
"created_at" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
166
|
+
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
167
|
+
"deleted_at" TIMESTAMPTZ NULL
|
|
168
|
+
);
|
|
169
|
+
CREATE INDEX IF NOT EXISTS "IDX_mpn_sandbox_message_created" ON "mpn_sandbox_message" ("created_at" DESC) WHERE "deleted_at" IS NULL;
|
|
170
|
+
`)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
async down(): Promise<void> {
|
|
174
|
+
this.addSql(`
|
|
175
|
+
DROP TABLE IF EXISTS "mpn_sandbox_message" CASCADE;
|
|
176
|
+
DROP TABLE IF EXISTS "mpn_channel_config" CASCADE;
|
|
177
|
+
DROP TABLE IF EXISTS "mpn_broadcast_campaign" CASCADE;
|
|
178
|
+
DROP TABLE IF EXISTS "mpn_consent_record" CASCADE;
|
|
179
|
+
DROP TABLE IF EXISTS "mpn_delivery_log" CASCADE;
|
|
180
|
+
DROP TABLE IF EXISTS "mpn_event_mapping" CASCADE;
|
|
181
|
+
DROP TABLE IF EXISTS "mpn_template_block" CASCADE;
|
|
182
|
+
DROP TABLE IF EXISTS "mpn_template" CASCADE;
|
|
183
|
+
`)
|
|
184
|
+
}
|
|
185
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { model } from "@medusajs/framework/utils"
|
|
2
|
+
|
|
3
|
+
export const MpnTemplate = model.define("mpn_template", {
|
|
4
|
+
id: model.id({ prefix: "mpntpl" }).primaryKey(),
|
|
5
|
+
name: model.text().searchable(),
|
|
6
|
+
label: model.text().searchable(),
|
|
7
|
+
description: model.text().nullable(),
|
|
8
|
+
channel: model.text().default("email"),
|
|
9
|
+
mode: model.text().default("blocks"), // "blocks" | "raw"
|
|
10
|
+
locale: model.text().default("en"),
|
|
11
|
+
subject: model.text().nullable(),
|
|
12
|
+
raw_content: model.text().nullable(),
|
|
13
|
+
variable_map: model.json().nullable(),
|
|
14
|
+
meta_template_name: model.text().nullable(),
|
|
15
|
+
meta_language_code: model.text().nullable(),
|
|
16
|
+
styles: model.json().nullable(),
|
|
17
|
+
is_active: model.boolean().default(true),
|
|
18
|
+
source_preset_id: model.text().nullable(),
|
|
19
|
+
metadata: model.json().nullable(),
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
export const MpnTemplateBlock = model.define("mpn_template_block", {
|
|
23
|
+
id: model.id({ prefix: "mpnblk" }).primaryKey(),
|
|
24
|
+
template_id: model.text(),
|
|
25
|
+
type: model.text(),
|
|
26
|
+
position: model.number().default(0),
|
|
27
|
+
parent_id: model.text().nullable(),
|
|
28
|
+
metadata: model.json().nullable(),
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
export const MpnEventMapping = model.define("mpn_event_mapping", {
|
|
32
|
+
id: model.id({ prefix: "mpnmap" }).primaryKey(),
|
|
33
|
+
event_name: model.text().searchable(),
|
|
34
|
+
channel: model.text().default("email"),
|
|
35
|
+
template_id: model.text(),
|
|
36
|
+
recipient_rule: model.text().default("customer_auto"),
|
|
37
|
+
custom_recipient: model.text().nullable(),
|
|
38
|
+
sender_profile_index: model.number().default(1),
|
|
39
|
+
telegram_thread_id: model.number().nullable(),
|
|
40
|
+
attach_document_types: model.json().nullable(), // e.g. ["invoice", "packing_slip"]
|
|
41
|
+
variable_map: model.json().nullable(),
|
|
42
|
+
conditions: model.json().nullable(),
|
|
43
|
+
is_active: model.boolean().default(true),
|
|
44
|
+
priority: model.number().default(0),
|
|
45
|
+
metadata: model.json().nullable(),
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
export const MpnDeliveryLog = model.define("mpn_delivery_log", {
|
|
49
|
+
id: model.id({ prefix: "mpnlog" }).primaryKey(),
|
|
50
|
+
idempotency_key: model.text(),
|
|
51
|
+
event_name: model.text().searchable(),
|
|
52
|
+
entity_id: model.text().nullable(),
|
|
53
|
+
channel: model.text(),
|
|
54
|
+
provider_id: model.text().nullable(),
|
|
55
|
+
driver: model.text().nullable(),
|
|
56
|
+
template_id: model.text().nullable(),
|
|
57
|
+
mapping_id: model.text().nullable(),
|
|
58
|
+
recipient_masked: model.text(),
|
|
59
|
+
recipient_hash: model.text(),
|
|
60
|
+
status: model.text().default("pending"),
|
|
61
|
+
attempts: model.number().default(1),
|
|
62
|
+
external_message_id: model.text().nullable(),
|
|
63
|
+
payload_redacted: model.json().nullable(),
|
|
64
|
+
error_code: model.text().nullable(),
|
|
65
|
+
error_message: model.text().nullable(),
|
|
66
|
+
sent_at: model.dateTime().nullable(),
|
|
67
|
+
delivered_at: model.dateTime().nullable(),
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
export const MpnConsentRecord = model.define("mpn_consent_record", {
|
|
71
|
+
id: model.id({ prefix: "mpncns" }).primaryKey(),
|
|
72
|
+
identifier: model.text().searchable(), // E.164 phone or Telegram chat_id/username
|
|
73
|
+
channel: model.text().default("sms"), // "sms" | "whatsapp" | "telegram"
|
|
74
|
+
customer_id: model.text().nullable(),
|
|
75
|
+
status: model.text().default("opted_in"), // "opted_in" | "opted_out" | "pending"
|
|
76
|
+
source: model.text().default("checkout"), // "checkout" | "webhook_join" | "webhook_stop" | "telegram_bot_start" | "admin"
|
|
77
|
+
first_message_sent: model.boolean().default(false),
|
|
78
|
+
last_cart_recovery_at: model.dateTime().nullable(),
|
|
79
|
+
opted_in_at: model.dateTime().nullable(),
|
|
80
|
+
opted_out_at: model.dateTime().nullable(),
|
|
81
|
+
metadata: model.json().nullable(),
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
export const MpnBroadcastCampaign = model.define("mpn_broadcast_campaign", {
|
|
85
|
+
id: model.id({ prefix: "mpnbrc" }).primaryKey(),
|
|
86
|
+
name: model.text().searchable(),
|
|
87
|
+
channel: model.text().default("sms"), // "sms" | "whatsapp" | "telegram" | "email"
|
|
88
|
+
template_id: model.text(),
|
|
89
|
+
customer_group_id: model.text().nullable(),
|
|
90
|
+
custom_recipients: model.json().nullable(),
|
|
91
|
+
status: model.text().default("draft"), // "draft" | "scheduled" | "sending" | "completed" | "canceled"
|
|
92
|
+
scheduled_at: model.dateTime().nullable(),
|
|
93
|
+
sent_at: model.dateTime().nullable(),
|
|
94
|
+
total_recipients: model.number().default(0),
|
|
95
|
+
sent_count: model.number().default(0),
|
|
96
|
+
failed_count: model.number().default(0),
|
|
97
|
+
attributed_orders_count: model.number().default(0),
|
|
98
|
+
attributed_revenue: model.number().default(0),
|
|
99
|
+
metadata: model.json().nullable(),
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
export const MpnChannelConfig = model.define("mpn_channel_config", {
|
|
103
|
+
id: model.id({ prefix: "mpncfg" }).primaryKey(),
|
|
104
|
+
channel: model.text(), // "email" | "whatsapp" | "telegram" | "sms" | "slack" | "dummy"
|
|
105
|
+
driver: model.text().default("default"),
|
|
106
|
+
is_enabled: model.boolean().default(true),
|
|
107
|
+
is_verified: model.boolean().default(false),
|
|
108
|
+
verified_at: model.dateTime().nullable(),
|
|
109
|
+
rate_limit_per_sec: model.number().default(10),
|
|
110
|
+
config_json: model.json().nullable(), // Non-secret operational config (e.g. channel_id, thread_ids, sender profiles, WABA ID, OpenWA URL)
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
export const MpnSandboxMessage = model.define("mpn_sandbox_message", {
|
|
114
|
+
id: model.id({ prefix: "mpnsbx" }).primaryKey(),
|
|
115
|
+
channel: model.text().default("sms"),
|
|
116
|
+
recipient: model.text().searchable(),
|
|
117
|
+
sender: model.text().nullable(),
|
|
118
|
+
subject: model.text().nullable(),
|
|
119
|
+
body: model.text(),
|
|
120
|
+
html: model.text().nullable(),
|
|
121
|
+
otp_code: model.text().nullable(),
|
|
122
|
+
media_urls: model.json().nullable(),
|
|
123
|
+
attachments_meta: model.json().nullable(),
|
|
124
|
+
metadata: model.json().nullable(),
|
|
125
|
+
})
|