@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,101 @@
|
|
|
1
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
+
|
|
3
|
+
import type NotificationsModuleService from "../../../../../modules/notifications/service"
|
|
4
|
+
import { NOTIFICATIONS_MODULE } from "../../../../../modules/notifications/types"
|
|
5
|
+
import { UpdateTemplateSchema } from "../../../../validators"
|
|
6
|
+
|
|
7
|
+
export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
|
|
8
|
+
const mpnService = req.scope.resolve(
|
|
9
|
+
NOTIFICATIONS_MODULE
|
|
10
|
+
) as NotificationsModuleService
|
|
11
|
+
const id = req.params.id
|
|
12
|
+
|
|
13
|
+
const result = await mpnService.getTemplateWithBlocks(id)
|
|
14
|
+
if (!result) {
|
|
15
|
+
return res.status(404).json({
|
|
16
|
+
success: false,
|
|
17
|
+
code: "NOT_FOUND",
|
|
18
|
+
message: `Template '${id}' not found`,
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return res.json({
|
|
23
|
+
success: true,
|
|
24
|
+
template: result.template,
|
|
25
|
+
blocks: result.blocks,
|
|
26
|
+
flat_blocks: result.flatBlocks,
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const POST = async (req: MedusaRequest, res: MedusaResponse) => {
|
|
31
|
+
const id = req.params.id
|
|
32
|
+
if (id.startsWith("system_")) {
|
|
33
|
+
return res.status(400).json({
|
|
34
|
+
success: false,
|
|
35
|
+
code: "SYSTEM_TEMPLATE_READONLY",
|
|
36
|
+
message:
|
|
37
|
+
"System templates are read-only. Clone the system preset to DB first.",
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const parsed = UpdateTemplateSchema.safeParse(req.body || {})
|
|
42
|
+
if (!parsed.success) {
|
|
43
|
+
return res.status(400).json({
|
|
44
|
+
success: false,
|
|
45
|
+
code: "VALIDATION_ERROR",
|
|
46
|
+
message: "Invalid template update payload",
|
|
47
|
+
details: parsed.error.flatten(),
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const mpnService = req.scope.resolve(
|
|
52
|
+
NOTIFICATIONS_MODULE
|
|
53
|
+
) as NotificationsModuleService
|
|
54
|
+
const { blocks, ...templateFields } = parsed.data
|
|
55
|
+
|
|
56
|
+
const updated = await mpnService.updateMpnTemplates({
|
|
57
|
+
id,
|
|
58
|
+
...templateFields,
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
if (Array.isArray(blocks)) {
|
|
62
|
+
await mpnService.replaceTemplateBlocks(id, blocks)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const full = await mpnService.getTemplateWithBlocks(id)
|
|
66
|
+
return res.json({
|
|
67
|
+
success: true,
|
|
68
|
+
template: full?.template || updated,
|
|
69
|
+
blocks: full?.blocks || [],
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export const DELETE = async (req: MedusaRequest, res: MedusaResponse) => {
|
|
74
|
+
const id = req.params.id
|
|
75
|
+
if (id.startsWith("system_")) {
|
|
76
|
+
return res.status(400).json({
|
|
77
|
+
success: false,
|
|
78
|
+
code: "SYSTEM_TEMPLATE_READONLY",
|
|
79
|
+
message: "System templates cannot be deleted",
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const mpnService = req.scope.resolve(
|
|
84
|
+
NOTIFICATIONS_MODULE
|
|
85
|
+
) as NotificationsModuleService
|
|
86
|
+
|
|
87
|
+
const existingBlocks = await mpnService.listMpnTemplateBlocks({
|
|
88
|
+
template_id: id,
|
|
89
|
+
})
|
|
90
|
+
if (existingBlocks.length > 0) {
|
|
91
|
+
await mpnService.deleteMpnTemplateBlocks(
|
|
92
|
+
existingBlocks.map((b: any) => b.id)
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
await mpnService.deleteMpnTemplates([id])
|
|
96
|
+
|
|
97
|
+
return res.json({
|
|
98
|
+
success: true,
|
|
99
|
+
deleted: id,
|
|
100
|
+
})
|
|
101
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
+
|
|
3
|
+
import type NotificationsModuleService from "../../../../modules/notifications/service"
|
|
4
|
+
import {
|
|
5
|
+
NOTIFICATIONS_MODULE,
|
|
6
|
+
type NotificationChannel,
|
|
7
|
+
} from "../../../../modules/notifications/types"
|
|
8
|
+
import { CreateOrCloneTemplateSchema } from "../../../validators"
|
|
9
|
+
|
|
10
|
+
export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
|
|
11
|
+
const mpnService = req.scope.resolve(
|
|
12
|
+
NOTIFICATIONS_MODULE
|
|
13
|
+
) as NotificationsModuleService
|
|
14
|
+
|
|
15
|
+
const channel =
|
|
16
|
+
typeof req.query.channel === "string"
|
|
17
|
+
? (req.query.channel as NotificationChannel)
|
|
18
|
+
: undefined
|
|
19
|
+
const source =
|
|
20
|
+
typeof req.query.source === "string"
|
|
21
|
+
? (req.query.source as "system" | "db" | "external")
|
|
22
|
+
: undefined
|
|
23
|
+
const locale =
|
|
24
|
+
typeof req.query.locale === "string" ? req.query.locale : undefined
|
|
25
|
+
|
|
26
|
+
const templates = await mpnService.listAllTemplates({
|
|
27
|
+
channel,
|
|
28
|
+
source,
|
|
29
|
+
locale,
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
return res.json({
|
|
33
|
+
templates,
|
|
34
|
+
count: templates.length,
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const POST = async (req: MedusaRequest, res: MedusaResponse) => {
|
|
39
|
+
const parsed = CreateOrCloneTemplateSchema.safeParse(req.body || {})
|
|
40
|
+
if (!parsed.success) {
|
|
41
|
+
return res.status(400).json({
|
|
42
|
+
success: false,
|
|
43
|
+
code: "VALIDATION_ERROR",
|
|
44
|
+
message: "Invalid template payload",
|
|
45
|
+
details: parsed.error.flatten(),
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const mpnService = req.scope.resolve(
|
|
50
|
+
NOTIFICATIONS_MODULE
|
|
51
|
+
) as NotificationsModuleService
|
|
52
|
+
const input = parsed.data
|
|
53
|
+
|
|
54
|
+
if (input.clone_from_preset_id) {
|
|
55
|
+
const cloned = await mpnService.cloneSystemPresetToDb(
|
|
56
|
+
input.clone_from_preset_id,
|
|
57
|
+
{
|
|
58
|
+
name: input.name,
|
|
59
|
+
label: input.label,
|
|
60
|
+
locale: input.locale,
|
|
61
|
+
}
|
|
62
|
+
)
|
|
63
|
+
return res.status(201).json({
|
|
64
|
+
success: true,
|
|
65
|
+
template: cloned.template,
|
|
66
|
+
blocks: cloned.blocks,
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const created = await mpnService.createMpnTemplates({
|
|
71
|
+
name: input.name || `template-${Date.now()}`,
|
|
72
|
+
label: input.label || input.name || "Untitled Template",
|
|
73
|
+
description: input.description ?? null,
|
|
74
|
+
channel: input.channel,
|
|
75
|
+
mode: input.mode,
|
|
76
|
+
locale: input.locale,
|
|
77
|
+
subject: input.subject ?? null,
|
|
78
|
+
raw_content: input.raw_content ?? null,
|
|
79
|
+
variable_map: input.variable_map ?? null,
|
|
80
|
+
meta_template_name: input.meta_template_name ?? null,
|
|
81
|
+
meta_language_code: input.meta_language_code ?? null,
|
|
82
|
+
styles: input.styles ?? null,
|
|
83
|
+
is_active: input.is_active ?? true,
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
let blocksTree: any[] = []
|
|
87
|
+
if (Array.isArray(input.blocks) && input.blocks.length > 0) {
|
|
88
|
+
blocksTree = await mpnService.replaceTemplateBlocks(
|
|
89
|
+
created.id,
|
|
90
|
+
input.blocks
|
|
91
|
+
)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return res.status(201).json({
|
|
95
|
+
success: true,
|
|
96
|
+
template: { ...created, source: "db" },
|
|
97
|
+
blocks: blocksTree,
|
|
98
|
+
})
|
|
99
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineMiddlewares,
|
|
3
|
+
type MedusaNextFunction,
|
|
4
|
+
type MedusaRequest,
|
|
5
|
+
type MedusaResponse,
|
|
6
|
+
} from "@medusajs/framework/http"
|
|
7
|
+
|
|
8
|
+
export * from "./validators"
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Storefront Anti-IDOR verification: ensures an authenticated customer can only manage
|
|
12
|
+
* their own consent/notification preferences when `customer_id` is present.
|
|
13
|
+
*/
|
|
14
|
+
export function verifyStoreCustomerSession(req: MedusaRequest): {
|
|
15
|
+
authenticated: boolean
|
|
16
|
+
customerId: string | null
|
|
17
|
+
} {
|
|
18
|
+
const actorId = (req as any).auth_context?.actor_id
|
|
19
|
+
const actorType = (req as any).auth_context?.actor_type
|
|
20
|
+
if (actorId && (!actorType || actorType === "customer")) {
|
|
21
|
+
return { authenticated: true, customerId: String(actorId) }
|
|
22
|
+
}
|
|
23
|
+
return { authenticated: false, customerId: null }
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default defineMiddlewares({
|
|
27
|
+
routes: [
|
|
28
|
+
{
|
|
29
|
+
matcher: "/store/mpn/webhooks/*",
|
|
30
|
+
bodyParser: { preserveRawBody: true },
|
|
31
|
+
middlewares: [
|
|
32
|
+
(
|
|
33
|
+
_req: MedusaRequest,
|
|
34
|
+
_res: MedusaResponse,
|
|
35
|
+
next: MedusaNextFunction
|
|
36
|
+
) => {
|
|
37
|
+
next()
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
})
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
+
|
|
3
|
+
import type NotificationsModuleService from "../../../../modules/notifications/service"
|
|
4
|
+
import { NOTIFICATIONS_MODULE } from "../../../../modules/notifications/types"
|
|
5
|
+
import { maskRecipientPii } from "../../../../modules/notifications/utils/security"
|
|
6
|
+
import { verifyStoreCustomerSession } from "../../../middlewares"
|
|
7
|
+
import { StoreConsentSchema } from "../../../validators"
|
|
8
|
+
|
|
9
|
+
export const POST = async (req: MedusaRequest, res: MedusaResponse) => {
|
|
10
|
+
const parsed = StoreConsentSchema.safeParse(req.body || {})
|
|
11
|
+
if (!parsed.success) {
|
|
12
|
+
return res.status(400).json({
|
|
13
|
+
success: false,
|
|
14
|
+
code: "VALIDATION_ERROR",
|
|
15
|
+
message: "Invalid consent request",
|
|
16
|
+
details: parsed.error.flatten(),
|
|
17
|
+
})
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const session = verifyStoreCustomerSession(req)
|
|
21
|
+
const mpnService = req.scope.resolve(
|
|
22
|
+
NOTIFICATIONS_MODULE
|
|
23
|
+
) as NotificationsModuleService
|
|
24
|
+
|
|
25
|
+
const record = await mpnService.upsertConsent({
|
|
26
|
+
identifier: parsed.data.identifier,
|
|
27
|
+
channel: parsed.data.channel,
|
|
28
|
+
customer_id: session.customerId,
|
|
29
|
+
action: parsed.data.action,
|
|
30
|
+
source: "checkout",
|
|
31
|
+
metadata: parsed.data.cart_id
|
|
32
|
+
? { cart_id: parsed.data.cart_id }
|
|
33
|
+
: undefined,
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
return res.json({
|
|
37
|
+
success: true,
|
|
38
|
+
consent: {
|
|
39
|
+
id: record.id,
|
|
40
|
+
channel: record.channel,
|
|
41
|
+
identifier_masked: maskRecipientPii(record.identifier),
|
|
42
|
+
status: record.status,
|
|
43
|
+
},
|
|
44
|
+
})
|
|
45
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { createHash, timingSafeEqual } from "node:crypto"
|
|
2
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
3
|
+
import type NotificationsModuleService from "../../../../../modules/notifications/service"
|
|
4
|
+
import { NOTIFICATIONS_MODULE } from "../../../../../modules/notifications/types"
|
|
5
|
+
import { verifyWebhookHmacSignature } from "../../../../../modules/notifications/utils/security"
|
|
6
|
+
|
|
7
|
+
function timingSafeStringEqual(a: string, b: string): boolean {
|
|
8
|
+
const hashA = new Uint8Array(createHash("sha256").update(a).digest())
|
|
9
|
+
const hashB = new Uint8Array(createHash("sha256").update(b).digest())
|
|
10
|
+
return timingSafeEqual(hashA, hashB)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const POST = async (req: MedusaRequest, res: MedusaResponse) => {
|
|
14
|
+
const provider = (req.params.provider || "").toLowerCase()
|
|
15
|
+
const mpnService = req.scope.resolve(
|
|
16
|
+
NOTIFICATIONS_MODULE
|
|
17
|
+
) as NotificationsModuleService
|
|
18
|
+
|
|
19
|
+
// Verify webhook signature when signing secret is configured
|
|
20
|
+
const signingSecret =
|
|
21
|
+
provider === "signalhouse"
|
|
22
|
+
? process.env.SIGNALHOUSE_WEBHOOK_SIGNING_SECRET
|
|
23
|
+
: provider === "telegram"
|
|
24
|
+
? process.env.TELEGRAM_WEBHOOK_SECRET
|
|
25
|
+
: process.env.MPN_WEBHOOK_SIGNING_SECRET
|
|
26
|
+
|
|
27
|
+
if (!signingSecret && process.env.NODE_ENV === "production") {
|
|
28
|
+
return res.status(500).json({
|
|
29
|
+
success: false,
|
|
30
|
+
code: "WEBHOOK_SECRET_NOT_CONFIGURED",
|
|
31
|
+
message: "Webhook signing secret is not configured",
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (signingSecret) {
|
|
36
|
+
if (provider === "telegram") {
|
|
37
|
+
const tgSecretHeader = String(
|
|
38
|
+
req.headers["x-telegram-bot-api-secret-token"] ?? ""
|
|
39
|
+
)
|
|
40
|
+
if (
|
|
41
|
+
!tgSecretHeader ||
|
|
42
|
+
!timingSafeStringEqual(tgSecretHeader, signingSecret)
|
|
43
|
+
) {
|
|
44
|
+
return res.status(401).json({
|
|
45
|
+
success: false,
|
|
46
|
+
code: "INVALID_WEBHOOK_SIGNATURE",
|
|
47
|
+
message: "Telegram webhook secret token mismatch",
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
} else {
|
|
51
|
+
const rawBody = (req as any).rawBody || JSON.stringify(req.body || {})
|
|
52
|
+
const sigHeader =
|
|
53
|
+
(req.headers["x-signalhouse-signature"] as string) ||
|
|
54
|
+
(req.headers["x-webhook-signature"] as string) ||
|
|
55
|
+
(req.headers["x-hub-signature-256"] as string)
|
|
56
|
+
if (!verifyWebhookHmacSignature(rawBody, sigHeader, signingSecret)) {
|
|
57
|
+
return res.status(401).json({
|
|
58
|
+
success: false,
|
|
59
|
+
code: "INVALID_WEBHOOK_SIGNATURE",
|
|
60
|
+
message: "Webhook HMAC signature verification failed",
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const body = (req.body || {}) as Record<string, any>
|
|
67
|
+
|
|
68
|
+
// 1. Telegram Bot `/start <customer_id>` deep-link opt-in & chat_id linking
|
|
69
|
+
if (provider === "telegram" && body.message?.text) {
|
|
70
|
+
const chatId = String(body.message.chat?.id || "")
|
|
71
|
+
const text = String(body.message.text || "").trim()
|
|
72
|
+
if (chatId && text.startsWith("/start")) {
|
|
73
|
+
const tokenArg = text.split(/\s+/)[1] || null
|
|
74
|
+
const record = await mpnService.upsertConsent({
|
|
75
|
+
identifier: chatId,
|
|
76
|
+
channel: "telegram",
|
|
77
|
+
customer_id: tokenArg,
|
|
78
|
+
action: "opt_in",
|
|
79
|
+
source: "telegram_bot_start",
|
|
80
|
+
metadata: {
|
|
81
|
+
username: body.message.from?.username || null,
|
|
82
|
+
},
|
|
83
|
+
})
|
|
84
|
+
return res.json({
|
|
85
|
+
success: true,
|
|
86
|
+
action: "telegram_linked",
|
|
87
|
+
consent_id: record.id,
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// 2. Inbound SMS / WhatsApp JOIN / STOP keyword handling (Signal House, Twilio, OpenWA/WAHA)
|
|
93
|
+
const fromPhone =
|
|
94
|
+
body.from || body.From || body.data?.from || body.sender || ""
|
|
95
|
+
const messageText =
|
|
96
|
+
body.text || body.Body || body.message || body.data?.body || ""
|
|
97
|
+
|
|
98
|
+
if (fromPhone && messageText) {
|
|
99
|
+
const channel =
|
|
100
|
+
provider === "whatsapp" || provider === "openwa" || provider === "waha"
|
|
101
|
+
? "whatsapp"
|
|
102
|
+
: "sms"
|
|
103
|
+
const result = await mpnService.processInboundConsentKeyword({
|
|
104
|
+
from: String(fromPhone),
|
|
105
|
+
body: String(messageText),
|
|
106
|
+
channel,
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
return res.json({
|
|
110
|
+
success: true,
|
|
111
|
+
...result,
|
|
112
|
+
})
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return res.json({
|
|
116
|
+
success: true,
|
|
117
|
+
handled: false,
|
|
118
|
+
})
|
|
119
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { z } from "zod"
|
|
2
|
+
import {
|
|
3
|
+
BLOCK_TYPES,
|
|
4
|
+
CONTEXT_TYPES,
|
|
5
|
+
NOTIFICATION_CHANNELS,
|
|
6
|
+
RECIPIENT_RULES,
|
|
7
|
+
SMS_DRIVERS,
|
|
8
|
+
SUPPORTED_LOCALES,
|
|
9
|
+
TEMPLATE_MODES,
|
|
10
|
+
WHATSAPP_DRIVERS,
|
|
11
|
+
} from "../modules/notifications/types"
|
|
12
|
+
|
|
13
|
+
export const BlockInputSchema = z.object({
|
|
14
|
+
id: z.string().max(120).optional(),
|
|
15
|
+
type: z.enum(BLOCK_TYPES),
|
|
16
|
+
position: z.number().int().min(0).default(0),
|
|
17
|
+
parent_id: z.string().max(120).nullable().optional(),
|
|
18
|
+
metadata: z.record(z.string(), z.unknown()).optional().default({}),
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
export const CreateOrCloneTemplateSchema = z.object({
|
|
22
|
+
clone_from_preset_id: z.string().max(120).optional(),
|
|
23
|
+
name: z.string().min(1).max(150).optional(),
|
|
24
|
+
label: z.string().min(1).max(200).optional(),
|
|
25
|
+
description: z.string().max(500).nullable().optional(),
|
|
26
|
+
channel: z.enum(NOTIFICATION_CHANNELS).optional().default("email"),
|
|
27
|
+
mode: z.enum(TEMPLATE_MODES).optional().default("blocks"),
|
|
28
|
+
locale: z.enum(SUPPORTED_LOCALES).optional().default("en"),
|
|
29
|
+
subject: z.string().max(300).nullable().optional(),
|
|
30
|
+
raw_content: z.string().max(250000).nullable().optional(),
|
|
31
|
+
variable_map: z.record(z.string(), z.string()).nullable().optional(),
|
|
32
|
+
meta_template_name: z.string().max(120).nullable().optional(),
|
|
33
|
+
meta_language_code: z.string().max(16).nullable().optional(),
|
|
34
|
+
styles: z.record(z.string(), z.unknown()).nullable().optional(),
|
|
35
|
+
is_active: z.boolean().optional().default(true),
|
|
36
|
+
blocks: z.array(BlockInputSchema).optional(),
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
export const UpdateTemplateSchema = z.object({
|
|
40
|
+
name: z.string().min(1).max(150).optional(),
|
|
41
|
+
label: z.string().min(1).max(200).optional(),
|
|
42
|
+
description: z.string().max(500).nullable().optional(),
|
|
43
|
+
channel: z.enum(NOTIFICATION_CHANNELS).optional(),
|
|
44
|
+
mode: z.enum(TEMPLATE_MODES).optional(),
|
|
45
|
+
locale: z.enum(SUPPORTED_LOCALES).optional(),
|
|
46
|
+
subject: z.string().max(300).nullable().optional(),
|
|
47
|
+
raw_content: z.string().max(250000).nullable().optional(),
|
|
48
|
+
variable_map: z.record(z.string(), z.string()).nullable().optional(),
|
|
49
|
+
meta_template_name: z.string().max(120).nullable().optional(),
|
|
50
|
+
meta_language_code: z.string().max(16).nullable().optional(),
|
|
51
|
+
styles: z.record(z.string(), z.unknown()).nullable().optional(),
|
|
52
|
+
is_active: z.boolean().optional(),
|
|
53
|
+
blocks: z.array(BlockInputSchema).optional(),
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
export const RenderTemplatePreviewSchema = z.object({
|
|
57
|
+
template_id: z.string().min(1).max(120),
|
|
58
|
+
context_type: z.enum(CONTEXT_TYPES).optional().default("order"),
|
|
59
|
+
entity_id: z.string().max(120).nullable().optional(),
|
|
60
|
+
locale: z.string().max(16).nullable().optional(),
|
|
61
|
+
subject: z.string().max(300).nullable().optional(),
|
|
62
|
+
data: z.record(z.string(), z.unknown()).optional(),
|
|
63
|
+
append_sms_consent_footer: z.boolean().optional(),
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
export const UpsertEventMappingSchema = z.object({
|
|
67
|
+
event_name: z.string().min(1).max(120),
|
|
68
|
+
channel: z.enum(NOTIFICATION_CHANNELS).default("email"),
|
|
69
|
+
template_id: z.string().min(1).max(120),
|
|
70
|
+
recipient_rule: z.enum(RECIPIENT_RULES).optional().default("customer_auto"),
|
|
71
|
+
custom_recipient: z.string().max(255).nullable().optional(),
|
|
72
|
+
sender_profile_index: z.number().int().min(1).max(5).optional().default(1),
|
|
73
|
+
telegram_thread_id: z.number().int().positive().nullable().optional(),
|
|
74
|
+
attach_document_types: z.array(z.string().max(40)).nullable().optional(),
|
|
75
|
+
variable_map: z.record(z.string(), z.string()).nullable().optional(),
|
|
76
|
+
conditions: z
|
|
77
|
+
.object({
|
|
78
|
+
region_ids: z.array(z.string()).optional(),
|
|
79
|
+
sales_channel_ids: z.array(z.string()).optional(),
|
|
80
|
+
currency_codes: z.array(z.string()).optional(),
|
|
81
|
+
min_order_total: z.number().min(0).optional(),
|
|
82
|
+
document_types: z.array(z.string()).optional(),
|
|
83
|
+
require_consent: z.boolean().optional(),
|
|
84
|
+
})
|
|
85
|
+
.nullable()
|
|
86
|
+
.optional(),
|
|
87
|
+
is_active: z.boolean().optional().default(true),
|
|
88
|
+
priority: z.number().int().min(-100).max(1000).optional().default(0),
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
export const UpdateChannelConfigSchema = z.object({
|
|
92
|
+
channel: z.enum(NOTIFICATION_CHANNELS),
|
|
93
|
+
driver: z
|
|
94
|
+
.union([z.enum(WHATSAPP_DRIVERS), z.enum(SMS_DRIVERS), z.string().max(64)])
|
|
95
|
+
.optional(),
|
|
96
|
+
is_enabled: z.boolean().optional(),
|
|
97
|
+
rate_limit_per_sec: z.number().int().min(1).max(500).optional(),
|
|
98
|
+
config_json: z.record(z.string(), z.unknown()).optional(),
|
|
99
|
+
action: z.enum(["save", "verify"]).optional().default("save"),
|
|
100
|
+
test_recipient: z.string().max(255).optional(),
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
export const ManualSendSchema = z.object({
|
|
104
|
+
channel: z.enum(NOTIFICATION_CHANNELS).optional(),
|
|
105
|
+
template_id: z.string().min(1).max(120).optional(),
|
|
106
|
+
event_name: z.string().max(120).optional(),
|
|
107
|
+
recipient: z.string().max(255).optional(),
|
|
108
|
+
order_id: z.string().max(120).nullable().optional(),
|
|
109
|
+
entity_id: z.string().max(120).nullable().optional(),
|
|
110
|
+
locale: z.string().max(16).optional(),
|
|
111
|
+
attach_document_types: z.array(z.string().max(40)).optional(),
|
|
112
|
+
telegram_thread_id: z.number().int().positive().nullable().optional(),
|
|
113
|
+
custom_data: z.record(z.string(), z.unknown()).optional(),
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
export const CreateBroadcastSchema = z.object({
|
|
117
|
+
name: z.string().min(1).max(150),
|
|
118
|
+
channel: z.enum(["sms", "whatsapp", "telegram", "email"]).default("sms"),
|
|
119
|
+
template_id: z.string().min(1).max(120),
|
|
120
|
+
customer_group_id: z.string().max(120).nullable().optional(),
|
|
121
|
+
custom_recipients: z
|
|
122
|
+
.array(z.string().max(255))
|
|
123
|
+
.max(500)
|
|
124
|
+
.nullable()
|
|
125
|
+
.optional(),
|
|
126
|
+
send_now: z.boolean().optional().default(false),
|
|
127
|
+
scheduled_at: z.string().nullable().optional(),
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
export const StoreConsentSchema = z.object({
|
|
131
|
+
identifier: z.string().min(3).max(255),
|
|
132
|
+
channel: z.enum(["sms", "whatsapp", "telegram"]).default("sms"),
|
|
133
|
+
action: z.enum(["opt_in", "opt_out"]).default("opt_in"),
|
|
134
|
+
cart_id: z.string().max(120).nullable().optional(),
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
export type BlockInput = z.infer<typeof BlockInputSchema>
|
|
138
|
+
export type CreateOrCloneTemplateInput = z.infer<
|
|
139
|
+
typeof CreateOrCloneTemplateSchema
|
|
140
|
+
>
|
|
141
|
+
export type UpdateTemplateInput = z.infer<typeof UpdateTemplateSchema>
|
|
142
|
+
export type RenderTemplatePreviewInput = z.infer<
|
|
143
|
+
typeof RenderTemplatePreviewSchema
|
|
144
|
+
>
|
|
145
|
+
export type UpsertEventMappingInput = z.infer<typeof UpsertEventMappingSchema>
|
|
146
|
+
export type UpdateChannelConfigInput = z.infer<typeof UpdateChannelConfigSchema>
|
|
147
|
+
export type ManualSendInput = z.infer<typeof ManualSendSchema>
|
|
148
|
+
export type CreateBroadcastInput = z.infer<typeof CreateBroadcastSchema>
|
|
149
|
+
export type StoreConsentInput = z.infer<typeof StoreConsentSchema>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from "./use-sdk-primitives"
|
|
2
|
+
export * from "./use-mpn-templates"
|
|
3
|
+
export * from "./use-mpn-mappings"
|
|
4
|
+
export * from "./use-mpn-channels"
|
|
5
|
+
export * from "./use-mpn-dispatch"
|
|
6
|
+
export * from "./use-order-notifications-widget-state"
|
|
7
|
+
export type {
|
|
8
|
+
NotificationsMutationHookOptions,
|
|
9
|
+
NotificationsQueryHookOptions,
|
|
10
|
+
StatusBannerState,
|
|
11
|
+
UseNotificationsMutationResult,
|
|
12
|
+
UseNotificationsQueryResult,
|
|
13
|
+
UseOrderNotificationsWidgetStateProps,
|
|
14
|
+
} from "../types"
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ListMpnChannelsResponse,
|
|
3
|
+
NotificationsMutationHookOptions,
|
|
4
|
+
NotificationsQueryHookOptions,
|
|
5
|
+
SaveOrVerifyMpnChannelPayload,
|
|
6
|
+
SaveOrVerifyMpnChannelResponse,
|
|
7
|
+
} from "../types"
|
|
8
|
+
import { notificationsAdminSdk } from "../sdk/client"
|
|
9
|
+
import { notificationsQueryKeys } from "../sdk/query-keys"
|
|
10
|
+
import {
|
|
11
|
+
useNotificationsMutation,
|
|
12
|
+
useNotificationsQuery,
|
|
13
|
+
} from "./use-sdk-primitives"
|
|
14
|
+
|
|
15
|
+
export function useMpnChannels(
|
|
16
|
+
options?: NotificationsQueryHookOptions<ListMpnChannelsResponse>
|
|
17
|
+
) {
|
|
18
|
+
const client = options?.client ?? notificationsAdminSdk
|
|
19
|
+
const queryKey = options?.queryKey ?? notificationsQueryKeys.channels()
|
|
20
|
+
|
|
21
|
+
return useNotificationsQuery<ListMpnChannelsResponse>(
|
|
22
|
+
queryKey,
|
|
23
|
+
() => client.listChannels(),
|
|
24
|
+
options
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function useSaveOrVerifyMpnChannel(
|
|
29
|
+
options?: NotificationsMutationHookOptions<
|
|
30
|
+
SaveOrVerifyMpnChannelResponse,
|
|
31
|
+
SaveOrVerifyMpnChannelPayload
|
|
32
|
+
>
|
|
33
|
+
) {
|
|
34
|
+
const client = options?.client ?? notificationsAdminSdk
|
|
35
|
+
return useNotificationsMutation<
|
|
36
|
+
SaveOrVerifyMpnChannelResponse,
|
|
37
|
+
SaveOrVerifyMpnChannelPayload
|
|
38
|
+
>(
|
|
39
|
+
(payload) => client.saveOrVerifyChannel(payload),
|
|
40
|
+
options,
|
|
41
|
+
notificationsQueryKeys.channels()
|
|
42
|
+
)
|
|
43
|
+
}
|