@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.
- 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 +340 -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 +133 -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 +589 -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,74 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BlockType,
|
|
3
|
+
ContextType,
|
|
4
|
+
NotificationChannel,
|
|
5
|
+
NotificationsPluginOptions,
|
|
6
|
+
TemplateMode,
|
|
7
|
+
} from "./core"
|
|
8
|
+
import type { NotificationAttachment, TemplateBlockNode } from "./domain"
|
|
9
|
+
|
|
10
|
+
export interface B2BNotificationContacts {
|
|
11
|
+
company_name?: string | null
|
|
12
|
+
buyer_contact_email?: string | null
|
|
13
|
+
accounting_email?: string | null
|
|
14
|
+
buyer_phone?: string | null
|
|
15
|
+
telegram_chat_id?: string | null
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface MultiInterpolateOptions {
|
|
19
|
+
escapeHtmlValues?: boolean
|
|
20
|
+
removeUnmatched?: boolean
|
|
21
|
+
maxPasses?: number
|
|
22
|
+
arrayPath?: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface SystemTemplatePreset {
|
|
26
|
+
id: string
|
|
27
|
+
name: string
|
|
28
|
+
label: string
|
|
29
|
+
description: string
|
|
30
|
+
channel: NotificationChannel
|
|
31
|
+
mode: TemplateMode
|
|
32
|
+
default_event: string
|
|
33
|
+
subject?: string
|
|
34
|
+
raw_content?: string
|
|
35
|
+
meta_template_name?: string
|
|
36
|
+
meta_language_code?: string
|
|
37
|
+
variable_map?: Record<string, string>
|
|
38
|
+
blocks: Array<{
|
|
39
|
+
id: string
|
|
40
|
+
type: BlockType
|
|
41
|
+
position: number
|
|
42
|
+
parent_id?: string | null
|
|
43
|
+
metadata: Record<string, any>
|
|
44
|
+
}>
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface RenderTemplateInput {
|
|
48
|
+
template_id: string
|
|
49
|
+
template_name: string
|
|
50
|
+
channel: NotificationChannel
|
|
51
|
+
mode: TemplateMode
|
|
52
|
+
locale?: string | null
|
|
53
|
+
subject?: string | null
|
|
54
|
+
raw_content?: string | null
|
|
55
|
+
blocks?: TemplateBlockNode[]
|
|
56
|
+
variable_map?: Record<string, string> | null
|
|
57
|
+
meta_template_name?: string | null
|
|
58
|
+
meta_language_code?: string | null
|
|
59
|
+
styles?: Record<string, any> | null
|
|
60
|
+
data: Record<string, any>
|
|
61
|
+
translations?: Record<string, any>
|
|
62
|
+
pluginOptions?: NotificationsPluginOptions
|
|
63
|
+
attachments?: NotificationAttachment[]
|
|
64
|
+
telegram_thread_id?: number | null
|
|
65
|
+
append_sms_consent_footer?: boolean
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface HydrateEntityContextInput {
|
|
69
|
+
event_name?: string
|
|
70
|
+
context_type?: ContextType
|
|
71
|
+
entity_id?: string | null
|
|
72
|
+
event_data?: Record<string, any> | null
|
|
73
|
+
locale?: string | null
|
|
74
|
+
}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
MpnChannel,
|
|
3
|
+
MpnLocale,
|
|
4
|
+
MpnRecipientRule,
|
|
5
|
+
MpnSupportedEvent,
|
|
6
|
+
MpnTemplateMode,
|
|
7
|
+
} from "./core"
|
|
8
|
+
import type {
|
|
9
|
+
MpnBroadcastRecord,
|
|
10
|
+
MpnChannelConfigRecord,
|
|
11
|
+
MpnConsentSummary,
|
|
12
|
+
MpnEventMappingRecord,
|
|
13
|
+
MpnLogRecord,
|
|
14
|
+
MpnSandboxMessageRecord,
|
|
15
|
+
MpnTemplateBlockRecord,
|
|
16
|
+
MpnTemplateRecord,
|
|
17
|
+
} from "./records"
|
|
18
|
+
|
|
19
|
+
export interface NotificationsApiClientOptions {
|
|
20
|
+
headers?: Record<string, string>
|
|
21
|
+
publishableApiKey?: string
|
|
22
|
+
credentials?: RequestCredentials
|
|
23
|
+
fetchImpl?: typeof fetch
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface ListMpnTemplatesParams {
|
|
27
|
+
channel?: MpnChannel | string
|
|
28
|
+
locale?: MpnLocale | string
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface ListMpnTemplatesResponse {
|
|
32
|
+
success?: boolean
|
|
33
|
+
templates: MpnTemplateRecord[]
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface GetMpnTemplateResponse {
|
|
37
|
+
success?: boolean
|
|
38
|
+
template: MpnTemplateRecord
|
|
39
|
+
blocks: MpnTemplateBlockRecord[]
|
|
40
|
+
flat_blocks: MpnTemplateBlockRecord[]
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface CreateOrCloneMpnTemplatePayload {
|
|
44
|
+
clone_from_preset_id?: string
|
|
45
|
+
name?: string
|
|
46
|
+
label?: string
|
|
47
|
+
channel?: MpnChannel | string
|
|
48
|
+
locale?: MpnLocale | string
|
|
49
|
+
subject?: string | null
|
|
50
|
+
mode?: MpnTemplateMode | string
|
|
51
|
+
raw_content?: string | null
|
|
52
|
+
meta_template_name?: string | null
|
|
53
|
+
blocks?: Array<Record<string, any>>
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface UpdateMpnTemplatePayload {
|
|
57
|
+
label?: string
|
|
58
|
+
subject?: string | null
|
|
59
|
+
mode?: MpnTemplateMode | string
|
|
60
|
+
raw_content?: string | null
|
|
61
|
+
meta_template_name?: string | null
|
|
62
|
+
is_active?: boolean
|
|
63
|
+
blocks?: Array<Record<string, any>>
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface SaveMpnTemplateResponse {
|
|
67
|
+
success?: boolean
|
|
68
|
+
template: MpnTemplateRecord
|
|
69
|
+
blocks?: MpnTemplateBlockRecord[]
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface DeleteMpnTemplateResponse {
|
|
73
|
+
success?: boolean
|
|
74
|
+
deleted: string
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface RenderMpnTemplatePayload {
|
|
78
|
+
template_id: string
|
|
79
|
+
context_type?: string
|
|
80
|
+
locale?: MpnLocale | string
|
|
81
|
+
subject?: string | null
|
|
82
|
+
data?: Record<string, any>
|
|
83
|
+
append_sms_consent_footer?: boolean
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface RenderMpnTemplateResponse {
|
|
87
|
+
success?: boolean
|
|
88
|
+
rendered: {
|
|
89
|
+
subject?: string
|
|
90
|
+
html?: string
|
|
91
|
+
text?: string
|
|
92
|
+
[key: string]: any
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface ListMpnMappingsResponse {
|
|
97
|
+
success?: boolean
|
|
98
|
+
mappings: MpnEventMappingRecord[]
|
|
99
|
+
supported_events: string[]
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface CreateMpnMappingPayload {
|
|
103
|
+
event_name: MpnSupportedEvent | string
|
|
104
|
+
channel: MpnChannel | string
|
|
105
|
+
template_id: string
|
|
106
|
+
recipient_rule?: MpnRecipientRule | string
|
|
107
|
+
custom_recipients?: string[] | null
|
|
108
|
+
telegram_thread_id?: number | null
|
|
109
|
+
attach_document_types?: string[] | null
|
|
110
|
+
is_active?: boolean
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface SaveMpnMappingResponse {
|
|
114
|
+
success?: boolean
|
|
115
|
+
mapping: MpnEventMappingRecord
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export interface DeleteMpnMappingResponse {
|
|
119
|
+
success?: boolean
|
|
120
|
+
deleted: string
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export interface ListMpnChannelsResponse {
|
|
124
|
+
success?: boolean
|
|
125
|
+
channels: MpnChannelConfigRecord[]
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export interface SaveOrVerifyMpnChannelPayload {
|
|
129
|
+
channel: MpnChannel | string
|
|
130
|
+
driver: string
|
|
131
|
+
config_json?: Record<string, any>
|
|
132
|
+
action?: "save" | "verify"
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export interface SaveOrVerifyMpnChannelResponse {
|
|
136
|
+
success?: boolean
|
|
137
|
+
channel?: MpnChannelConfigRecord
|
|
138
|
+
verified?: boolean
|
|
139
|
+
message?: string
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export interface ListMpnLogsParams {
|
|
143
|
+
channel?: MpnChannel | string
|
|
144
|
+
status?: string
|
|
145
|
+
entity_id?: string
|
|
146
|
+
limit?: number
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export interface ListMpnLogsResponse {
|
|
150
|
+
success?: boolean
|
|
151
|
+
logs: MpnLogRecord[]
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export interface ListMpnBroadcastsResponse {
|
|
155
|
+
success?: boolean
|
|
156
|
+
broadcasts: MpnBroadcastRecord[]
|
|
157
|
+
consent_summary: MpnConsentSummary | null
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export interface CreateMpnBroadcastPayload {
|
|
161
|
+
name: string
|
|
162
|
+
channel: MpnChannel | string
|
|
163
|
+
template_id: string
|
|
164
|
+
send_now?: boolean
|
|
165
|
+
scheduled_at?: string | null
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export interface CreateMpnBroadcastResponse {
|
|
169
|
+
success?: boolean
|
|
170
|
+
broadcast: MpnBroadcastRecord
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export interface ListMpnSandboxParams {
|
|
174
|
+
channel?: MpnChannel | string
|
|
175
|
+
recipient?: string
|
|
176
|
+
limit?: number
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export interface ListMpnSandboxResponse {
|
|
180
|
+
success?: boolean
|
|
181
|
+
messages: MpnSandboxMessageRecord[]
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export interface ClearMpnSandboxResponse {
|
|
185
|
+
success?: boolean
|
|
186
|
+
cleared?: boolean
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export interface SendMpnNotificationPayload {
|
|
190
|
+
channel: MpnChannel | string
|
|
191
|
+
recipient: string
|
|
192
|
+
template_id?: string
|
|
193
|
+
order_id?: string
|
|
194
|
+
context_type?: string
|
|
195
|
+
locale?: MpnLocale | string
|
|
196
|
+
subject?: string
|
|
197
|
+
text?: string
|
|
198
|
+
html?: string
|
|
199
|
+
data?: Record<string, any>
|
|
200
|
+
attach_invoice_pdf?: boolean
|
|
201
|
+
attach_document_types?: Array<
|
|
202
|
+
"invoice" | "packing_slip" | "credit_note" | "receipt"
|
|
203
|
+
>
|
|
204
|
+
thread_id?: number
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export interface SendMpnNotificationResponse {
|
|
208
|
+
success?: boolean
|
|
209
|
+
result?: Record<string, any>
|
|
210
|
+
log?: MpnLogRecord
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export interface StoreUpdateConsentPayload {
|
|
214
|
+
identifier: string
|
|
215
|
+
channel: "sms" | "whatsapp" | "telegram" | "email"
|
|
216
|
+
action: "opt_in" | "opt_out"
|
|
217
|
+
cart_id?: string
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export interface StoreUpdateConsentResponse {
|
|
221
|
+
success: boolean
|
|
222
|
+
consent: {
|
|
223
|
+
id: string
|
|
224
|
+
channel: string
|
|
225
|
+
identifier_masked: string
|
|
226
|
+
status: string
|
|
227
|
+
}
|
|
228
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export interface NotificationTranslationDictionary {
|
|
2
|
+
general: {
|
|
3
|
+
hello: string
|
|
4
|
+
thankYou: string
|
|
5
|
+
questionsContact: string
|
|
6
|
+
viewInStore: string
|
|
7
|
+
poweredBy: string
|
|
8
|
+
unsubscribeSms: string
|
|
9
|
+
}
|
|
10
|
+
order: {
|
|
11
|
+
placedSubject: string
|
|
12
|
+
placedTitle: string
|
|
13
|
+
placedIntro: string
|
|
14
|
+
completedSubject: string
|
|
15
|
+
completedTitle: string
|
|
16
|
+
canceledSubject: string
|
|
17
|
+
canceledTitle: string
|
|
18
|
+
updatedSubject: string
|
|
19
|
+
updatedTitle: string
|
|
20
|
+
orderNumber: string
|
|
21
|
+
orderDate: string
|
|
22
|
+
orderStatus: string
|
|
23
|
+
paymentStatus: string
|
|
24
|
+
fulfillmentStatus: string
|
|
25
|
+
itemsHeader: string
|
|
26
|
+
quantity: string
|
|
27
|
+
unitPrice: string
|
|
28
|
+
subtotal: string
|
|
29
|
+
shipping: string
|
|
30
|
+
tax: string
|
|
31
|
+
discount: string
|
|
32
|
+
total: string
|
|
33
|
+
shippingAddress: string
|
|
34
|
+
billingAddress: string
|
|
35
|
+
trackOrderButton: string
|
|
36
|
+
downloadInvoiceButton: string
|
|
37
|
+
}
|
|
38
|
+
shipment: {
|
|
39
|
+
shippedSubject: string
|
|
40
|
+
shippedTitle: string
|
|
41
|
+
shippedIntro: string
|
|
42
|
+
deliveredSubject: string
|
|
43
|
+
deliveredTitle: string
|
|
44
|
+
carrier: string
|
|
45
|
+
trackingNumber: string
|
|
46
|
+
trackPackageButton: string
|
|
47
|
+
}
|
|
48
|
+
inventory: {
|
|
49
|
+
lowStockSubject: string
|
|
50
|
+
lowStockTitle: string
|
|
51
|
+
sku: string
|
|
52
|
+
location: string
|
|
53
|
+
stockedQuantity: string
|
|
54
|
+
reservedQuantity: string
|
|
55
|
+
availableQuantity: string
|
|
56
|
+
}
|
|
57
|
+
customer: {
|
|
58
|
+
welcomeSubject: string
|
|
59
|
+
welcomeTitle: string
|
|
60
|
+
welcomeIntro: string
|
|
61
|
+
otpSubject: string
|
|
62
|
+
otpMessage: string
|
|
63
|
+
}
|
|
64
|
+
cart: {
|
|
65
|
+
recoverySubject: string
|
|
66
|
+
recoveryTitle: string
|
|
67
|
+
recoveryIntro: string
|
|
68
|
+
resumeCartButton: string
|
|
69
|
+
}
|
|
70
|
+
document: {
|
|
71
|
+
readySubject: string
|
|
72
|
+
readyTitle: string
|
|
73
|
+
readyIntro: string
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Workflows
|
|
2
|
+
|
|
3
|
+
Medusa workflows (`@medusajs/framework/workflows-sdk`) and orchestration helpers that hydrate entity contexts, render multi-channel templates, evaluate event mappings, attach documents, and dispatch notifications.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
workflows/
|
|
7
|
+
└── index.ts Workflows, steps, and core hydration/dispatch orchestration functions
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Exported Workflows & Steps
|
|
13
|
+
|
|
14
|
+
| Symbol | Type | ID | Trigger / Caller |
|
|
15
|
+
| ------------------------------------------------------ | -------- | -------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
16
|
+
| `renderNotificationTemplateWorkflow` | Workflow | `"render-notification-template"` | `POST /admin/mpn/render-template`, custom routes |
|
|
17
|
+
| `renderTemplateStep` (`resolveAndRenderTemplateStep`) | Step | `"render-template"` | Internal step of `renderNotificationTemplateWorkflow` |
|
|
18
|
+
| `dispatchEventNotificationsWorkflow` | Workflow | `"dispatch-event-notifications"` | Subscribers, scheduled jobs, `POST /admin/mpn/send` |
|
|
19
|
+
| `dispatchEventStep` (`dispatchEventNotificationsStep`) | Step | `"dispatch-event"` | Internal step of `dispatchEventNotificationsWorkflow` |
|
|
20
|
+
| `hydrateEntityContextData` | Helper | — | Hydrates live entity graph (`order`, `shipment`, `inventory-level`, `product`, `cart`, `document`, `otp`) via `query.graph` with safe mock fallback |
|
|
21
|
+
| `executeEventNotificationsDispatch` | Helper | — | Evaluates active `mpn_event_mapping` rules, consent, idempotency, optional `medusa-plugin-documents` PDF attachments, and dispatches via `Modules.NOTIFICATION` or Sandbox |
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## 1. `renderNotificationTemplateWorkflow`
|
|
26
|
+
|
|
27
|
+
Resolves live entity data via `hydrateEntityContextData` (or uses provided `input.data` / mock preview context) and compiles the target template (`system_*` preset or `mpntpl_*` DB template) into channel-ready HTML, plain text, Slack Block Kit JSON, WhatsApp options, Telegram options, and SMS segment metrics.
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import { renderNotificationTemplateWorkflow } from "@vicacha-devs/medusa-plugin-notifications/workflows"
|
|
31
|
+
|
|
32
|
+
const { result } = await renderNotificationTemplateWorkflow(req.scope).run({
|
|
33
|
+
input: {
|
|
34
|
+
template_id: "system_email_order_placed",
|
|
35
|
+
context_type: "order",
|
|
36
|
+
entity_id: "order_01J...",
|
|
37
|
+
locale: "es",
|
|
38
|
+
},
|
|
39
|
+
})
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## 2. `dispatchEventNotificationsWorkflow` & `executeEventNotificationsDispatch`
|
|
45
|
+
|
|
46
|
+
Executes the full 8-stage notification pipeline for any emitted Medusa or custom store event:
|
|
47
|
+
|
|
48
|
+
1. **Mapping Lookup & Priority Sort**: Queries `mpn_event_mapping` for `{ event_name, is_active: true }` sorted by descending `priority`.
|
|
49
|
+
2. **Entity Hydration (`hydrateEntityContextData`)**: Queries `order` or `fulfillment` via `ContainerRegistrationKeys.QUERY` (`query.graph`) and normalizes data through `transformOrderData`, `transformShipmentData`, `transformInventoryLevelData`, or `transformProductData`.
|
|
50
|
+
3. **Condition & Channel Verification**: Evaluates `mapping.conditions` (`evaluateEventConditions`), checks `mpn_channel_config.is_enabled`, and enforces the Telegram Admin Verification Gate (`channelConfig.is_verified`) when `recipient_rule === "merchant_channel"`.
|
|
51
|
+
4. **Recipient & B2B Contact Resolution**: Resolves recipient via `resolveRecipientForRule` and `resolveB2BNotificationContacts`.
|
|
52
|
+
5. **TCPA / 10DLC & Bot Consent Check**: Calls `verifyRecipientConsent` against `mpn_consent_record` and appends `"Reply STOP to opt out"` on the first SMS message.
|
|
53
|
+
6. **Idempotency Check**: Calls `checkIdempotency` (`event_name:entity_id:channel:template_id:recipient`) to prevent duplicate sends.
|
|
54
|
+
7. **Optional Document Attachment (`resolveOrderDocumentAttachments`)**: Fetches generated PDF Invoices, Packing Slips, or Credit Notes from `medusa-plugin-documents` (`documentsModuleService`) when `mapping.attach_document_types` is non-empty.
|
|
55
|
+
8. **Render, Dispatch & Redacted Audit Log**: Compiles the template, dispatches via `Modules.NOTIFICATION` (`notificationModuleService.createNotifications`) or captures in `mpn_sandbox_message`, and records a PII-masked entry in `mpn_delivery_log`.
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import { dispatchEventNotificationsWorkflow } from "@vicacha-devs/medusa-plugin-notifications/workflows"
|
|
59
|
+
|
|
60
|
+
const { result } = await dispatchEventNotificationsWorkflow(req.scope).run({
|
|
61
|
+
input: {
|
|
62
|
+
event_name: "order.placed",
|
|
63
|
+
event_data: { id: "order_01J..." },
|
|
64
|
+
force_send: false,
|
|
65
|
+
},
|
|
66
|
+
})
|
|
67
|
+
```
|