@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,319 @@
|
|
|
1
|
+
import { MedusaError } from "@medusajs/framework/utils"
|
|
2
|
+
import type {
|
|
3
|
+
ClearMpnSandboxResponse,
|
|
4
|
+
CreateMpnBroadcastPayload,
|
|
5
|
+
CreateMpnBroadcastResponse,
|
|
6
|
+
CreateMpnMappingPayload,
|
|
7
|
+
CreateOrCloneMpnTemplatePayload,
|
|
8
|
+
DeleteMpnMappingResponse,
|
|
9
|
+
DeleteMpnTemplateResponse,
|
|
10
|
+
GetMpnTemplateResponse,
|
|
11
|
+
ListMpnBroadcastsResponse,
|
|
12
|
+
ListMpnChannelsResponse,
|
|
13
|
+
ListMpnLogsParams,
|
|
14
|
+
ListMpnLogsResponse,
|
|
15
|
+
ListMpnMappingsResponse,
|
|
16
|
+
ListMpnSandboxParams,
|
|
17
|
+
ListMpnSandboxResponse,
|
|
18
|
+
ListMpnTemplatesParams,
|
|
19
|
+
ListMpnTemplatesResponse,
|
|
20
|
+
NotificationsApiClientOptions,
|
|
21
|
+
RenderMpnTemplatePayload,
|
|
22
|
+
RenderMpnTemplateResponse,
|
|
23
|
+
SaveMpnMappingResponse,
|
|
24
|
+
SaveMpnTemplateResponse,
|
|
25
|
+
SaveOrVerifyMpnChannelPayload,
|
|
26
|
+
SaveOrVerifyMpnChannelResponse,
|
|
27
|
+
SendMpnNotificationPayload,
|
|
28
|
+
SendMpnNotificationResponse,
|
|
29
|
+
StoreUpdateConsentPayload,
|
|
30
|
+
StoreUpdateConsentResponse,
|
|
31
|
+
UpdateMpnTemplatePayload,
|
|
32
|
+
} from "../types"
|
|
33
|
+
|
|
34
|
+
function buildQueryString(params?: Record<string, unknown>): string {
|
|
35
|
+
if (!params) return ""
|
|
36
|
+
const search = new URLSearchParams()
|
|
37
|
+
for (const [key, value] of Object.entries(params)) {
|
|
38
|
+
if (value === undefined || value === null || value === "") continue
|
|
39
|
+
search.set(key, String(value))
|
|
40
|
+
}
|
|
41
|
+
const str = search.toString()
|
|
42
|
+
return str ? `?${str}` : ""
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Typed SDK client for `medusa-plugin-notifications` (MPN).
|
|
47
|
+
* Supports both `/admin` and `/store` routes with automatic JSON parsing
|
|
48
|
+
* and standard Medusa error extraction.
|
|
49
|
+
*/
|
|
50
|
+
export class NotificationsApiClient {
|
|
51
|
+
private readonly baseUrl: string
|
|
52
|
+
private readonly prefix: string
|
|
53
|
+
private readonly options: NotificationsApiClientOptions
|
|
54
|
+
|
|
55
|
+
constructor(
|
|
56
|
+
prefix: "/admin" | "/store" = "/store",
|
|
57
|
+
baseUrl: string = "",
|
|
58
|
+
options: NotificationsApiClientOptions = {}
|
|
59
|
+
) {
|
|
60
|
+
this.prefix = prefix
|
|
61
|
+
this.baseUrl = baseUrl.replace(/\/$/, "")
|
|
62
|
+
this.options = options
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public resolveUrl(
|
|
66
|
+
endpoint: string,
|
|
67
|
+
params?: Record<string, unknown>
|
|
68
|
+
): string {
|
|
69
|
+
const normalizedEndpoint = endpoint.startsWith("/")
|
|
70
|
+
? endpoint
|
|
71
|
+
: `/${endpoint}`
|
|
72
|
+
return `${this.baseUrl}${this.prefix}${normalizedEndpoint}${buildQueryString(params)}`
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
private buildHeaders(
|
|
76
|
+
customHeaders?: HeadersInit,
|
|
77
|
+
hasJsonBody = true
|
|
78
|
+
): Record<string, string> {
|
|
79
|
+
const headers: Record<string, string> = {
|
|
80
|
+
...(hasJsonBody ? { "Content-Type": "application/json" } : {}),
|
|
81
|
+
...this.options.headers,
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (this.options.publishableApiKey) {
|
|
85
|
+
headers["x-publishable-api-key"] = this.options.publishableApiKey
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (customHeaders) {
|
|
89
|
+
if (customHeaders instanceof Headers) {
|
|
90
|
+
customHeaders.forEach((v, k) => {
|
|
91
|
+
headers[k] = v
|
|
92
|
+
})
|
|
93
|
+
} else if (Array.isArray(customHeaders)) {
|
|
94
|
+
for (const [k, v] of customHeaders) {
|
|
95
|
+
headers[k] = v
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
Object.assign(headers, customHeaders)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return headers
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
private async fetch<T>(
|
|
106
|
+
endpoint: string,
|
|
107
|
+
options?: RequestInit,
|
|
108
|
+
queryParams?: Record<string, unknown>
|
|
109
|
+
): Promise<T> {
|
|
110
|
+
const url = this.resolveUrl(endpoint, queryParams)
|
|
111
|
+
const fetchFn = this.options.fetchImpl ?? globalThis.fetch
|
|
112
|
+
const hasJsonBody =
|
|
113
|
+
options?.body !== undefined && !(options.body instanceof FormData)
|
|
114
|
+
|
|
115
|
+
const response = await fetchFn(url, {
|
|
116
|
+
credentials: this.options.credentials ?? "include",
|
|
117
|
+
...options,
|
|
118
|
+
headers: this.buildHeaders(options?.headers, hasJsonBody),
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
if (response.status === 204) {
|
|
122
|
+
return {} as T
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const data = await response.json().catch(() => ({}))
|
|
126
|
+
|
|
127
|
+
if (!response.ok) {
|
|
128
|
+
throw new MedusaError(
|
|
129
|
+
MedusaError.Types.UNEXPECTED_STATE,
|
|
130
|
+
(data as { message?: string; detail?: string }).message ||
|
|
131
|
+
(data as { detail?: string }).detail ||
|
|
132
|
+
`Request failed with status ${response.status}`
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return data as T
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// ---------------------------------------------------------------------------
|
|
140
|
+
// Admin Templates & Preview Endpoints (/admin/mpn/templates & /render-template)
|
|
141
|
+
// ---------------------------------------------------------------------------
|
|
142
|
+
|
|
143
|
+
async listTemplates(
|
|
144
|
+
params?: ListMpnTemplatesParams
|
|
145
|
+
): Promise<ListMpnTemplatesResponse> {
|
|
146
|
+
return this.fetch<ListMpnTemplatesResponse>(
|
|
147
|
+
"/mpn/templates",
|
|
148
|
+
{ method: "GET" },
|
|
149
|
+
params as Record<string, unknown>
|
|
150
|
+
)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async getTemplate(id: string): Promise<GetMpnTemplateResponse> {
|
|
154
|
+
return this.fetch<GetMpnTemplateResponse>(
|
|
155
|
+
`/mpn/templates/${encodeURIComponent(id)}`,
|
|
156
|
+
{ method: "GET" }
|
|
157
|
+
)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async createOrCloneTemplate(
|
|
161
|
+
payload: CreateOrCloneMpnTemplatePayload
|
|
162
|
+
): Promise<SaveMpnTemplateResponse> {
|
|
163
|
+
return this.fetch<SaveMpnTemplateResponse>("/mpn/templates", {
|
|
164
|
+
method: "POST",
|
|
165
|
+
body: JSON.stringify(payload),
|
|
166
|
+
})
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
async updateTemplate(
|
|
170
|
+
id: string,
|
|
171
|
+
payload: UpdateMpnTemplatePayload
|
|
172
|
+
): Promise<SaveMpnTemplateResponse> {
|
|
173
|
+
return this.fetch<SaveMpnTemplateResponse>(
|
|
174
|
+
`/mpn/templates/${encodeURIComponent(id)}`,
|
|
175
|
+
{
|
|
176
|
+
method: "POST",
|
|
177
|
+
body: JSON.stringify(payload),
|
|
178
|
+
}
|
|
179
|
+
)
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
async deleteTemplate(id: string): Promise<DeleteMpnTemplateResponse> {
|
|
183
|
+
return this.fetch<DeleteMpnTemplateResponse>(
|
|
184
|
+
`/mpn/templates/${encodeURIComponent(id)}`,
|
|
185
|
+
{ method: "DELETE" }
|
|
186
|
+
)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
async renderTemplatePreview(
|
|
190
|
+
payload: RenderMpnTemplatePayload
|
|
191
|
+
): Promise<RenderMpnTemplateResponse> {
|
|
192
|
+
return this.fetch<RenderMpnTemplateResponse>("/mpn/render-template", {
|
|
193
|
+
method: "POST",
|
|
194
|
+
body: JSON.stringify(payload),
|
|
195
|
+
})
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// ---------------------------------------------------------------------------
|
|
199
|
+
// Admin Event Mappings Endpoints (/admin/mpn/mappings)
|
|
200
|
+
// ---------------------------------------------------------------------------
|
|
201
|
+
|
|
202
|
+
async listMappings(): Promise<ListMpnMappingsResponse> {
|
|
203
|
+
return this.fetch<ListMpnMappingsResponse>("/mpn/mappings", {
|
|
204
|
+
method: "GET",
|
|
205
|
+
})
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
async createMapping(
|
|
209
|
+
payload: CreateMpnMappingPayload
|
|
210
|
+
): Promise<SaveMpnMappingResponse> {
|
|
211
|
+
return this.fetch<SaveMpnMappingResponse>("/mpn/mappings", {
|
|
212
|
+
method: "POST",
|
|
213
|
+
body: JSON.stringify(payload),
|
|
214
|
+
})
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
async updateMapping(
|
|
218
|
+
id: string,
|
|
219
|
+
payload: Partial<CreateMpnMappingPayload>
|
|
220
|
+
): Promise<SaveMpnMappingResponse> {
|
|
221
|
+
return this.fetch<SaveMpnMappingResponse>(
|
|
222
|
+
`/mpn/mappings/${encodeURIComponent(id)}`,
|
|
223
|
+
{
|
|
224
|
+
method: "POST",
|
|
225
|
+
body: JSON.stringify(payload),
|
|
226
|
+
}
|
|
227
|
+
)
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
async deleteMapping(id: string): Promise<DeleteMpnMappingResponse> {
|
|
231
|
+
return this.fetch<DeleteMpnMappingResponse>(
|
|
232
|
+
`/mpn/mappings/${encodeURIComponent(id)}`,
|
|
233
|
+
{ method: "DELETE" }
|
|
234
|
+
)
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// ---------------------------------------------------------------------------
|
|
238
|
+
// Admin Channels, Logs, Broadcasts, Sandbox, & Send Endpoints (/admin/mpn/*)
|
|
239
|
+
// ---------------------------------------------------------------------------
|
|
240
|
+
|
|
241
|
+
async listChannels(): Promise<ListMpnChannelsResponse> {
|
|
242
|
+
return this.fetch<ListMpnChannelsResponse>("/mpn/channels", {
|
|
243
|
+
method: "GET",
|
|
244
|
+
})
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
async saveOrVerifyChannel(
|
|
248
|
+
payload: SaveOrVerifyMpnChannelPayload
|
|
249
|
+
): Promise<SaveOrVerifyMpnChannelResponse> {
|
|
250
|
+
return this.fetch<SaveOrVerifyMpnChannelResponse>("/mpn/channels", {
|
|
251
|
+
method: "POST",
|
|
252
|
+
body: JSON.stringify(payload),
|
|
253
|
+
})
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
async listLogs(params?: ListMpnLogsParams): Promise<ListMpnLogsResponse> {
|
|
257
|
+
return this.fetch<ListMpnLogsResponse>(
|
|
258
|
+
"/mpn/logs",
|
|
259
|
+
{ method: "GET" },
|
|
260
|
+
params as Record<string, unknown>
|
|
261
|
+
)
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
async listBroadcasts(): Promise<ListMpnBroadcastsResponse> {
|
|
265
|
+
return this.fetch<ListMpnBroadcastsResponse>("/mpn/broadcasts", {
|
|
266
|
+
method: "GET",
|
|
267
|
+
})
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
async createBroadcast(
|
|
271
|
+
payload: CreateMpnBroadcastPayload
|
|
272
|
+
): Promise<CreateMpnBroadcastResponse> {
|
|
273
|
+
return this.fetch<CreateMpnBroadcastResponse>("/mpn/broadcasts", {
|
|
274
|
+
method: "POST",
|
|
275
|
+
body: JSON.stringify(payload),
|
|
276
|
+
})
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
async listSandboxMessages(
|
|
280
|
+
params?: ListMpnSandboxParams
|
|
281
|
+
): Promise<ListMpnSandboxResponse> {
|
|
282
|
+
return this.fetch<ListMpnSandboxResponse>(
|
|
283
|
+
"/mpn/sandbox",
|
|
284
|
+
{ method: "GET" },
|
|
285
|
+
params as Record<string, unknown>
|
|
286
|
+
)
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
async clearSandboxMessages(): Promise<ClearMpnSandboxResponse> {
|
|
290
|
+
return this.fetch<ClearMpnSandboxResponse>("/mpn/sandbox", {
|
|
291
|
+
method: "DELETE",
|
|
292
|
+
})
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
async sendNotification(
|
|
296
|
+
payload: SendMpnNotificationPayload
|
|
297
|
+
): Promise<SendMpnNotificationResponse> {
|
|
298
|
+
return this.fetch<SendMpnNotificationResponse>("/mpn/send", {
|
|
299
|
+
method: "POST",
|
|
300
|
+
body: JSON.stringify(payload),
|
|
301
|
+
})
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// ---------------------------------------------------------------------------
|
|
305
|
+
// Storefront Consent Endpoint (/store/mpn/consent)
|
|
306
|
+
// ---------------------------------------------------------------------------
|
|
307
|
+
|
|
308
|
+
async updateConsent(
|
|
309
|
+
payload: StoreUpdateConsentPayload
|
|
310
|
+
): Promise<StoreUpdateConsentResponse> {
|
|
311
|
+
return this.fetch<StoreUpdateConsentResponse>("/mpn/consent", {
|
|
312
|
+
method: "POST",
|
|
313
|
+
body: JSON.stringify(payload),
|
|
314
|
+
})
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
export const notificationsAdminSdk = new NotificationsApiClient("/admin")
|
|
319
|
+
export const notificationsStoreSdk = new NotificationsApiClient("/store")
|
package/src/sdk/index.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export * from "./client"
|
|
2
|
+
export * from "./query-keys"
|
|
3
|
+
export type {
|
|
4
|
+
ClearMpnSandboxResponse,
|
|
5
|
+
CreateMpnBroadcastPayload,
|
|
6
|
+
CreateMpnBroadcastResponse,
|
|
7
|
+
CreateMpnMappingPayload,
|
|
8
|
+
CreateOrCloneMpnTemplatePayload,
|
|
9
|
+
DeleteMpnMappingResponse,
|
|
10
|
+
DeleteMpnTemplateResponse,
|
|
11
|
+
GetMpnTemplateResponse,
|
|
12
|
+
ListMpnBroadcastsResponse,
|
|
13
|
+
ListMpnChannelsResponse,
|
|
14
|
+
ListMpnLogsParams,
|
|
15
|
+
ListMpnLogsResponse,
|
|
16
|
+
ListMpnMappingsResponse,
|
|
17
|
+
ListMpnSandboxParams,
|
|
18
|
+
ListMpnSandboxResponse,
|
|
19
|
+
ListMpnTemplatesParams,
|
|
20
|
+
ListMpnTemplatesResponse,
|
|
21
|
+
MappedNotificationError,
|
|
22
|
+
MpnBroadcastRecord,
|
|
23
|
+
MpnChannel,
|
|
24
|
+
MpnChannelConfigRecord,
|
|
25
|
+
MpnConsentSummary,
|
|
26
|
+
MpnEventMappingRecord,
|
|
27
|
+
MpnLocale,
|
|
28
|
+
MpnLogRecord,
|
|
29
|
+
MpnRecipientRule,
|
|
30
|
+
MpnSandboxMessageRecord,
|
|
31
|
+
MpnSupportedEvent,
|
|
32
|
+
MpnTemplateBlockRecord,
|
|
33
|
+
MpnTemplateBlockType,
|
|
34
|
+
MpnTemplateMode,
|
|
35
|
+
MpnTemplateRecord,
|
|
36
|
+
NotificationsApiClientOptions,
|
|
37
|
+
RenderMpnTemplatePayload,
|
|
38
|
+
RenderMpnTemplateResponse,
|
|
39
|
+
SaveMpnMappingResponse,
|
|
40
|
+
SaveMpnTemplateResponse,
|
|
41
|
+
SaveOrVerifyMpnChannelPayload,
|
|
42
|
+
SaveOrVerifyMpnChannelResponse,
|
|
43
|
+
SendMpnNotificationPayload,
|
|
44
|
+
SendMpnNotificationResponse,
|
|
45
|
+
StoreUpdateConsentPayload,
|
|
46
|
+
StoreUpdateConsentResponse,
|
|
47
|
+
UpdateMpnTemplatePayload,
|
|
48
|
+
} from "../types"
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
export const NOTIFICATIONS_QUERY_KEY = "notifications" as const
|
|
2
|
+
|
|
3
|
+
type QueryInvalidationListener = (
|
|
4
|
+
invalidatedKeyPrefix: readonly unknown[]
|
|
5
|
+
) => void
|
|
6
|
+
|
|
7
|
+
const invalidationListeners = new Set<QueryInvalidationListener>()
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Hierarchical query key factory for `medusa-plugin-notifications`.
|
|
11
|
+
* Follows the same factory conventions as `boldQueryKeys` in `vicacha-medusa-plugins`.
|
|
12
|
+
*/
|
|
13
|
+
export const notificationsQueryKeys = {
|
|
14
|
+
all: [NOTIFICATIONS_QUERY_KEY] as const,
|
|
15
|
+
|
|
16
|
+
studio: () => [...notificationsQueryKeys.all, "studio"] as const,
|
|
17
|
+
|
|
18
|
+
templatesAll: () => [...notificationsQueryKeys.all, "templates"] as const,
|
|
19
|
+
templates: (params?: Record<string, unknown>) =>
|
|
20
|
+
params
|
|
21
|
+
? ([...notificationsQueryKeys.templatesAll(), params] as const)
|
|
22
|
+
: notificationsQueryKeys.templatesAll(),
|
|
23
|
+
template: (id: string) =>
|
|
24
|
+
[...notificationsQueryKeys.templatesAll(), "detail", id] as const,
|
|
25
|
+
|
|
26
|
+
mappingsAll: () => [...notificationsQueryKeys.all, "mappings"] as const,
|
|
27
|
+
mappings: (params?: Record<string, unknown>) =>
|
|
28
|
+
params
|
|
29
|
+
? ([...notificationsQueryKeys.mappingsAll(), params] as const)
|
|
30
|
+
: notificationsQueryKeys.mappingsAll(),
|
|
31
|
+
|
|
32
|
+
channels: () => [...notificationsQueryKeys.all, "channels"] as const,
|
|
33
|
+
|
|
34
|
+
logsAll: () => [...notificationsQueryKeys.all, "logs"] as const,
|
|
35
|
+
logs: (params?: Record<string, unknown>) =>
|
|
36
|
+
params
|
|
37
|
+
? ([...notificationsQueryKeys.logsAll(), params] as const)
|
|
38
|
+
: notificationsQueryKeys.logsAll(),
|
|
39
|
+
orderLogs: (orderId: string) =>
|
|
40
|
+
[...notificationsQueryKeys.logsAll(), "order", orderId] as const,
|
|
41
|
+
|
|
42
|
+
broadcasts: () => [...notificationsQueryKeys.all, "broadcasts"] as const,
|
|
43
|
+
|
|
44
|
+
sandbox: (params?: Record<string, unknown>) =>
|
|
45
|
+
params
|
|
46
|
+
? ([...notificationsQueryKeys.all, "sandbox", params] as const)
|
|
47
|
+
: ([...notificationsQueryKeys.all, "sandbox"] as const),
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function matchesNotificationsQueryKeyPrefix(
|
|
51
|
+
candidateKey: readonly unknown[],
|
|
52
|
+
prefixKey: readonly unknown[]
|
|
53
|
+
): boolean {
|
|
54
|
+
if (prefixKey.length > candidateKey.length) {
|
|
55
|
+
return false
|
|
56
|
+
}
|
|
57
|
+
for (let i = 0; i < prefixKey.length; i++) {
|
|
58
|
+
const a = candidateKey[i]
|
|
59
|
+
const b = prefixKey[i]
|
|
60
|
+
if (a === b) continue
|
|
61
|
+
if (
|
|
62
|
+
typeof a === "object" &&
|
|
63
|
+
a !== null &&
|
|
64
|
+
typeof b === "object" &&
|
|
65
|
+
b !== null
|
|
66
|
+
) {
|
|
67
|
+
if (JSON.stringify(a) === JSON.stringify(b)) continue
|
|
68
|
+
}
|
|
69
|
+
return false
|
|
70
|
+
}
|
|
71
|
+
return true
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function invalidateNotificationsQueries(
|
|
75
|
+
keyPrefix: readonly unknown[] = notificationsQueryKeys.all
|
|
76
|
+
): void {
|
|
77
|
+
for (const listener of invalidationListeners) {
|
|
78
|
+
listener(keyPrefix)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function subscribeNotificationsQueryInvalidation(
|
|
83
|
+
listener: QueryInvalidationListener
|
|
84
|
+
): () => void {
|
|
85
|
+
invalidationListeners.add(listener)
|
|
86
|
+
return () => {
|
|
87
|
+
invalidationListeners.delete(listener)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Subscribers
|
|
2
|
+
|
|
3
|
+
Event subscribers that listen to 25 Medusa core and custom plugin events and trigger database-driven notification mappings via `executeEventNotificationsDispatch`.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
subscribers/
|
|
7
|
+
├── order-events.ts 9 order.* lifecycle events
|
|
8
|
+
├── fulfillment-and-inventory-events.ts 6 shipment, delivery, fulfillment, and inventory events
|
|
9
|
+
└── customer-and-document-events.ts 10 customer, document, auth OTP, loyalty, wallet, membership & contact events
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Conventions
|
|
15
|
+
|
|
16
|
+
- Every subscriber delegates to `executeEventNotificationsDispatch(container, { event_name, event_data })` from `src/workflows/index.ts`.
|
|
17
|
+
- All subscribers wrap execution in a non-blocking `try / catch` block so store checkout, fulfillment, or customer creation workflows never fail if an external notification gateway is unreachable.
|
|
18
|
+
- `fulfillment-and-inventory-events.ts` normalizes `fulfillment.shipment_created` → `shipment.created` and `fulfillment.delivery_created` → `delivery.created` so merchants only need to configure a single canonical event mapping.
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Subscribed Events Reference
|
|
23
|
+
|
|
24
|
+
| Subscriber File | Event Name | Default Hydrated Context | Typical Channels & Presets |
|
|
25
|
+
| ------------------------------------- | ------------------------------ | --------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
26
|
+
| `order-events.ts` | `order.placed` | `order` | Email (`system_email_order_placed`), WhatsApp (`system_whatsapp_order_placed`), Telegram (`system_telegram_order_placed`), SMS (`system_sms_order_placed`), Slack (`system_slack_order_placed`) |
|
|
27
|
+
| `order-events.ts` | `order.completed` | `order` | Email, WhatsApp, Telegram, SMS |
|
|
28
|
+
| `order-events.ts` | `order.canceled` | `order` | Email, WhatsApp, Telegram, SMS |
|
|
29
|
+
| `order-events.ts` | `order.updated` | `order` | Email, Telegram |
|
|
30
|
+
| `order-events.ts` | `order.fulfillment_created` | `order` | Email, WhatsApp, SMS |
|
|
31
|
+
| `order-events.ts` | `order.fulfillment_canceled` | `order` | Email, Telegram |
|
|
32
|
+
| `order-events.ts` | `order.return_requested` | `order` | Email, Telegram, Slack |
|
|
33
|
+
| `order-events.ts` | `order.return_received` | `order` | Email, Telegram |
|
|
34
|
+
| `order-events.ts` | `order.refund_created` | `order` | Email (with Credit Note PDF), WhatsApp, SMS |
|
|
35
|
+
| `fulfillment-and-inventory-events.ts` | `shipment.created` | `shipment` | Email (`system_email_shipment_created`), WhatsApp (`system_whatsapp_shipment_created`), SMS (`system_sms_shipment_created`) |
|
|
36
|
+
| `fulfillment-and-inventory-events.ts` | `delivery.created` | `shipment` | Email, WhatsApp, SMS |
|
|
37
|
+
| `fulfillment-and-inventory-events.ts` | `fulfillment.created` | `shipment` | Email, Telegram |
|
|
38
|
+
| `fulfillment-and-inventory-events.ts` | `fulfillment.shipment_created` | `shipment` (normalized to `shipment.created`) | Email, WhatsApp, SMS |
|
|
39
|
+
| `fulfillment-and-inventory-events.ts` | `fulfillment.delivery_created` | `shipment` (normalized to `delivery.created`) | Email, WhatsApp, SMS |
|
|
40
|
+
| `fulfillment-and-inventory-events.ts` | `inventory-level.updated` | `inventory-level` | Email (`system_email_inventory_low`), Telegram (`system_telegram_inventory_low`), Slack |
|
|
41
|
+
| `customer-and-document-events.ts` | `customer.created` | `custom` | Email, WhatsApp, Telegram |
|
|
42
|
+
| `customer-and-document-events.ts` | `customer.updated` | `custom` | Email |
|
|
43
|
+
| `customer-and-document-events.ts` | `document.generated` | `document` | Email (`system_email_document_ready`), WhatsApp, Telegram (auto-attaches generated PDF from `medusa-plugin-documents`) |
|
|
44
|
+
| `customer-and-document-events.ts` | `auth.otp_generated` | `otp` | SMS (`system_sms_otp_code`), WhatsApp, Dummy Sandbox (`mpn-dummy-sandbox`) |
|
|
45
|
+
| `customer-and-document-events.ts` | `loyalty.points_credited` | `custom` | Email, SMS, WhatsApp |
|
|
46
|
+
| `customer-and-document-events.ts` | `loyalty.points_debited` | `custom` | Email, SMS |
|
|
47
|
+
| `customer-and-document-events.ts` | `wallet.credited` | `custom` | Email, SMS, Telegram |
|
|
48
|
+
| `customer-and-document-events.ts` | `wallet.debited` | `custom` | Email, SMS |
|
|
49
|
+
| `customer-and-document-events.ts` | `membership.tier_changed` | `custom` | Email, WhatsApp |
|
|
50
|
+
| `customer-and-document-events.ts` | `contact.form_submitted` | `custom` | Email, Telegram, Slack |
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { SubscriberArgs, SubscriberConfig } from "@medusajs/framework"
|
|
2
|
+
import { executeEventNotificationsDispatch } from "../workflows"
|
|
3
|
+
|
|
4
|
+
export default async function customerAndDocumentEventsSubscriber({
|
|
5
|
+
event: { name, data },
|
|
6
|
+
container,
|
|
7
|
+
}: SubscriberArgs<Record<string, any>>) {
|
|
8
|
+
if (!name) return
|
|
9
|
+
try {
|
|
10
|
+
await executeEventNotificationsDispatch(container, {
|
|
11
|
+
event_name: name,
|
|
12
|
+
event_data: data || {},
|
|
13
|
+
})
|
|
14
|
+
} catch {
|
|
15
|
+
// Non-blocking in event subscriber
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const config: SubscriberConfig = {
|
|
20
|
+
event: [
|
|
21
|
+
"customer.created",
|
|
22
|
+
"customer.updated",
|
|
23
|
+
"invite.created",
|
|
24
|
+
"invite.resent",
|
|
25
|
+
"auth.password_reset",
|
|
26
|
+
"auth.verification_requested",
|
|
27
|
+
"document.generated",
|
|
28
|
+
"auth.otp_generated",
|
|
29
|
+
"loyalty.points_credited",
|
|
30
|
+
"loyalty.points_debited",
|
|
31
|
+
"wallet.credited",
|
|
32
|
+
"wallet.debited",
|
|
33
|
+
"membership.tier_changed",
|
|
34
|
+
"contact.form_submitted",
|
|
35
|
+
],
|
|
36
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { SubscriberArgs, SubscriberConfig } from "@medusajs/framework"
|
|
2
|
+
import { executeEventNotificationsDispatch } from "../workflows"
|
|
3
|
+
|
|
4
|
+
export default async function fulfillmentAndInventorySubscriber({
|
|
5
|
+
event: { name, data },
|
|
6
|
+
container,
|
|
7
|
+
}: SubscriberArgs<Record<string, any>>) {
|
|
8
|
+
if (!name) return
|
|
9
|
+
const normalizedEvent =
|
|
10
|
+
name === "fulfillment.shipment_created"
|
|
11
|
+
? "shipment.created"
|
|
12
|
+
: name === "fulfillment.delivery_created"
|
|
13
|
+
? "delivery.created"
|
|
14
|
+
: name
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
await executeEventNotificationsDispatch(container, {
|
|
18
|
+
event_name: normalizedEvent,
|
|
19
|
+
event_data: data || {},
|
|
20
|
+
})
|
|
21
|
+
} catch {
|
|
22
|
+
// Non-blocking in event subscriber
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const config: SubscriberConfig = {
|
|
27
|
+
event: [
|
|
28
|
+
"shipment.created",
|
|
29
|
+
"delivery.created",
|
|
30
|
+
"fulfillment.created",
|
|
31
|
+
"fulfillment.shipment_created",
|
|
32
|
+
"fulfillment.delivery_created",
|
|
33
|
+
"inventory-level.updated",
|
|
34
|
+
],
|
|
35
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { SubscriberArgs, SubscriberConfig } from "@medusajs/framework"
|
|
2
|
+
import { executeEventNotificationsDispatch } from "../workflows"
|
|
3
|
+
|
|
4
|
+
export default async function orderEventsNotificationSubscriber({
|
|
5
|
+
event: { name, data },
|
|
6
|
+
container,
|
|
7
|
+
}: SubscriberArgs<Record<string, any>>) {
|
|
8
|
+
if (!name) return
|
|
9
|
+
try {
|
|
10
|
+
await executeEventNotificationsDispatch(container, {
|
|
11
|
+
event_name: name,
|
|
12
|
+
event_data: data || {},
|
|
13
|
+
})
|
|
14
|
+
} catch {
|
|
15
|
+
// Non-blocking in event subscriber so order lifecycle never fails
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const config: SubscriberConfig = {
|
|
20
|
+
event: [
|
|
21
|
+
"order.placed",
|
|
22
|
+
"order.completed",
|
|
23
|
+
"order.canceled",
|
|
24
|
+
"order.updated",
|
|
25
|
+
"order.fulfillment_created",
|
|
26
|
+
"order.fulfillment_canceled",
|
|
27
|
+
"order.return_requested",
|
|
28
|
+
"order.return_received",
|
|
29
|
+
"order.refund_created",
|
|
30
|
+
],
|
|
31
|
+
}
|