chore: move ModuleRegistrationName to utils (#7911)

This commit is contained in:
Carlos R. L. Rodrigues
2024-07-03 06:30:56 -03:00
committed by GitHub
parent 46f15b4909
commit a7844efd09
339 changed files with 7203 additions and 7620 deletions
@@ -15,17 +15,26 @@ In your resource, such as a subscriber, resolve the Notification Module's main s
export const highlights = [
["12", "notificationModuleService", "Resolve the Notification Module."],
["17", "create", "Create the notification to be sent."],
["19", '"email"', "Use the module provider defined for the `email` channel to send an email."],
["20", '"product-created"', "The ID of the template defined in the third-party service, such as SendGrid."],
["21", "data", "The data to pass to the template defined in the third-party service."]
[
"19",
'"email"',
"Use the module provider defined for the `email` channel to send an email.",
],
[
"20",
'"product-created"',
"The ID of the template defined in the third-party service, such as SendGrid.",
],
[
"21",
"data",
"The data to pass to the template defined in the third-party service.",
],
]
```ts title="src/subscribers/product-created.ts" highlights={highlights} collapsibleLines="1-7" expandButtonLabel="Show Imports"
import type {
SubscriberArgs,
SubscriberConfig,
} from "@medusajs/medusa"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import type { SubscriberArgs, SubscriberConfig } from "@medusajs/medusa"
import { ModuleRegistrationName } from "@medusajs/utils"
import { INotificationModuleService } from "@medusajs/types"
export default async function productCreateHandler({
@@ -33,9 +42,7 @@ export default async function productCreateHandler({
container,
}: SubscriberArgs<{ id: string }>) {
const notificationModuleService: INotificationModuleService =
container.resolve(
ModuleRegistrationName.NOTIFICATION
)
container.resolve(ModuleRegistrationName.NOTIFICATION)
await notificationModuleService.create({
to: "shahednasser@gmail.com",
@@ -57,26 +64,29 @@ The `create` method accepts an object or an array of objects having the followin
{
name: "to",
type: "`string`",
description: "The destination to send the notification to. When sending an email, it'll be the email address. When sending an SMS, it'll be the phone number.",
description:
"The destination to send the notification to. When sending an email, it'll be the email address. When sending an SMS, it'll be the phone number.",
optional: false,
},
{
name: "channel",
type: "`string`",
description: "The channel to send the notification through. For example, `email` or `sms`. The module provider defined for that channel will be used to send the notification.",
optional: false
description:
"The channel to send the notification through. For example, `email` or `sms`. The module provider defined for that channel will be used to send the notification.",
optional: false,
},
{
name: "template",
type: "`string`",
description: "The ID of the template used for the notification. This is useful for providers like SendGrid, where you define templates within SendGrid and use their IDs here.",
optional: false
description:
"The ID of the template used for the notification. This is useful for providers like SendGrid, where you define templates within SendGrid and use their IDs here.",
optional: false,
},
{
name: "data",
type: "`Record<string, unknown>`",
description: "The data to pass along to the template, if necessary."
}
description: "The data to pass along to the template, if necessary.",
},
]}
sectionTitle="Use the Create Method"
/>
@@ -86,40 +86,19 @@ SENDGRID_FROM=<YOUR_SENDGRID_FROM>
</Table.Header>
<Table.Body>
<Table.Row>
<Table.Cell>`channels`</Table.Cell>
<Table.Cell>
`channels`
</Table.Cell>
<Table.Cell>
The channels this notification module is used to send notifications for. Only one provider can be defined for a channel.
The channels this notification module is used to send notifications for.
Only one provider can be defined for a channel.
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
`api_key`
</Table.Cell>
<Table.Cell>
The SendGrid API key.
</Table.Cell>
<Table.Cell>`api_key`</Table.Cell>
<Table.Cell>The SendGrid API key.</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
`from`
</Table.Cell>
<Table.Cell>
The SendGrid from email.
</Table.Cell>
<Table.Cell>`from`</Table.Cell>
<Table.Cell>The SendGrid from email.</Table.Cell>
</Table.Row>
</Table.Body>
</Table>
@@ -141,17 +120,18 @@ To test the module out, create a simple subscriber at `src/subscribers/product-c
export const highlights = [
["12", "notificationModuleService", "Resolve the Notification Module."],
["17", "create", "Create the notification to be sent."],
["19", '"email"', "By specifying the `email` channel, SendGrid will be used to send the notification."],
[
"19",
'"email"',
"By specifying the `email` channel, SendGrid will be used to send the notification.",
],
["20", '"product-created"', "The ID of the template defined in SendGrid."],
["21", "data", "The data to pass to the template defined in SendGrid."]
["21", "data", "The data to pass to the template defined in SendGrid."],
]
```ts title="src/subscribers/product-created.ts" highlights={highlights} collapsibleLines="1-7" expandButtonLabel="Show Imports"
import type {
SubscriberArgs,
SubscriberConfig,
} from "@medusajs/medusa"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import type { SubscriberArgs, SubscriberConfig } from "@medusajs/medusa"
import { ModuleRegistrationName } from "@medusajs/utils"
import { INotificationModuleService } from "@medusajs/types"
export default async function productCreateHandler({
@@ -159,9 +139,7 @@ export default async function productCreateHandler({
container,
}: SubscriberArgs<{ id: string }>) {
const notificationModuleService: INotificationModuleService =
container.resolve(
ModuleRegistrationName.NOTIFICATION
)
container.resolve(ModuleRegistrationName.NOTIFICATION)
await notificationModuleService.create({
to: "test@gmail.com",
@@ -178,7 +156,7 @@ export const config: SubscriberConfig = {
In this subscriber:
- Resolve the Notification Module's main service.
- Resolve the Notification Module's main service.
- Use the `create` method of the main service to create a notification to be sent to the specified email.
- By specifying the `email` channel, the SendGrid Notification Module Provider is used to send the notification.
- The `template` property of the `create` method's parameter specifies the ID of the template defined in SendGrid.