docs: fixes and changes based on latest updates (#7322)
* docs: changes based on DX changes * remove fields no longer needed * remove unnecessary parameters * fixes to authenticate middleware usage * add highlight to migrations config * change configuration to http * added missing remote link docs * fix name in sidebar * added notification module docs + updated file module docs * add vale exceptions * fix vale errors * added docs on custom cli scripts
This commit is contained in:
@@ -78,8 +78,9 @@ const customOptions: Record<string, Partial<TypeDocOptions>> = {
|
||||
],
|
||||
}),
|
||||
notification: getOptions({
|
||||
entryPointPath: "packages/medusa/src/interfaces/notification-service.ts",
|
||||
tsConfigName: "medusa.json",
|
||||
entryPointPath:
|
||||
"packages/core/utils/src/notification/abstract-notification-provider.ts",
|
||||
tsConfigName: "utils.json",
|
||||
name: "notification",
|
||||
parentIgnore: true,
|
||||
}),
|
||||
|
||||
+17
-16
@@ -64,26 +64,27 @@ The File Module accepts one provider only.
|
||||
</Note>
|
||||
|
||||
\`\`\`js title="medusa-config.js"
|
||||
module.exports = {
|
||||
const { Modules } = require("@medusajs/modules-sdk")
|
||||
|
||||
// ...
|
||||
|
||||
const modules = {
|
||||
// ...
|
||||
modules: {
|
||||
// ...
|
||||
[Modules.FILE]: {
|
||||
resolve: "@medusajs/file",
|
||||
options: {
|
||||
providers: [
|
||||
{
|
||||
resolve: "./dist/modules/my-file",
|
||||
options: {
|
||||
config: {
|
||||
"my-file": {
|
||||
// provider options...
|
||||
},
|
||||
[Modules.FILE]: {
|
||||
resolve: "@medusajs/file",
|
||||
options: {
|
||||
providers: [
|
||||
{
|
||||
resolve: "./dist/modules/my-file",
|
||||
options: {
|
||||
config: {
|
||||
"my-file": {
|
||||
// provider options...
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
+71
-49
@@ -1,76 +1,98 @@
|
||||
import { FormattingOptionsType } from "types"
|
||||
|
||||
const notificationOptions: FormattingOptionsType = {
|
||||
"^notification/.*AbstractNotificationService": {
|
||||
"^notification": {
|
||||
frontmatterData: {
|
||||
displayed_sidebar: "core",
|
||||
},
|
||||
},
|
||||
"^notification/.*AbstractNotificationProviderService": {
|
||||
reflectionGroups: {
|
||||
Properties: false,
|
||||
},
|
||||
reflectionDescription: `In this document, you’ll learn how to create a notification provider in the Medusa backend and the methods you must implement in it. Learn more about the notification architecture in [this documentation](https://docs.medusajs.com/development/notification/overview)`,
|
||||
reflectionDescription: `In this document, you’ll learn how to create a notification provider module and the methods you must implement in it.`,
|
||||
frontmatterData: {
|
||||
slug: "/references/notification-service",
|
||||
slug: "/references/notification-provider-module",
|
||||
},
|
||||
reflectionTitle: {
|
||||
fullReplacement: "How to Create a Notification Provider",
|
||||
fullReplacement: "How to Create a Notification Provider Module",
|
||||
},
|
||||
endSections: [
|
||||
`## Subscribe with Loaders
|
||||
shouldIncrementAfterStartSections: true,
|
||||
expandMembers: true,
|
||||
startSections: [
|
||||
`## 1. Create Module Directory
|
||||
|
||||
After creating your Notification Provider Service, you must create a [Loader](https://docs.medusajs.com/development/loaders/overview) that registers this Service as a notification handler of events.
|
||||
Start by creating a new directory for your module. For example, \`src/modules/my-notification\`.`,
|
||||
`## 2. Create the Notification Provider Service
|
||||
|
||||
For example, to register the \`email-sender\` Notification Provider as a handler for the \`order.placed\` event, create the file \`src/loaders/notification.ts\` with the following content:
|
||||
Create the file \`src/modules/my-notification/service.ts\` that holds the implementation of the notification service.
|
||||
|
||||
\`\`\`ts title="src/loaders/notification.ts"
|
||||
The Notification Provider Module's main service must extend the \`AbstractNotificationProviderService\` class imported from \`@medusajs/utils\`:
|
||||
|
||||
\`\`\`ts title="src/modules/my-notification/service.ts"
|
||||
import {
|
||||
MedusaContainer,
|
||||
NotificationService,
|
||||
} from "@medusajs/medusa"
|
||||
AbstractNotificationProviderService
|
||||
} from "@medusajs/utils"
|
||||
|
||||
export default async (
|
||||
container: MedusaContainer
|
||||
): Promise<void> => {
|
||||
const notificationService = container.resolve<
|
||||
NotificationService
|
||||
>("notificationService")
|
||||
class MyNotificationProviderService extends AbstractNotificationProviderService {
|
||||
// TODO add methods
|
||||
}
|
||||
|
||||
notificationService.subscribe(
|
||||
"order.placed",
|
||||
"email-sender"
|
||||
)
|
||||
export default MyNotificationProviderService
|
||||
\`\`\``,
|
||||
],
|
||||
endSections: [
|
||||
`## 3. Create Module Definition File
|
||||
|
||||
Create the file \`src/modules/my-notification/index.ts\` with the following content:
|
||||
|
||||
\`\`\`ts title="src/modules/my-notification/index.ts"
|
||||
import MyNotificationProviderService from "./service"
|
||||
|
||||
export default {
|
||||
service: MyNotificationProviderService,
|
||||
}
|
||||
\`\`\`
|
||||
|
||||
This loader accesses the \`notificationService\` through the [MedusaContainer](https://docs.medusajs.com/development/fundamentals/dependency-injection). The \`notificationService\` has a \`subscribe\` method that accepts 2 parameters. The first one is the name of the event to subscribe to, and the second is the identifier of the Notification Provider that's subscribing to that event.`,
|
||||
`## Test Sending a Notification
|
||||
This exports the module's definition, indicating that the \`MyNotificationProviderService\` is the main service of the module.`,
|
||||
`## 4. Use Module
|
||||
|
||||
Make sure you have an event bus module configured in your Medusa backend. You can learn more on how to do that in the [Configurations guide](https://docs.medusajs.com/development/backend/configurations#modules).
|
||||
To use your Notification Provider Module, add it to the \`providers\` array of the Notification Module:
|
||||
|
||||
Then:
|
||||
<Note>
|
||||
|
||||
1\\. Run the \`build\` command in the root directory of your Medusa backend:
|
||||
The Notification Module accepts one provider per channel.
|
||||
|
||||
\`\`\`bash npm2yarn
|
||||
npm run build
|
||||
</Note>
|
||||
|
||||
\`\`\`js title="medusa-config.js"
|
||||
const { Modules } = require("@medusajs/modules-sdk")
|
||||
|
||||
// ...
|
||||
|
||||
const modules = {
|
||||
// ...
|
||||
[Modules.NOTIFICATION]: {
|
||||
resolve: "@medusajs/notification",
|
||||
options: {
|
||||
providers: [
|
||||
{
|
||||
resolve: "./dist/modules/my-notification",
|
||||
options: {
|
||||
config: {
|
||||
"my-notification": {
|
||||
channels: ["email"],
|
||||
// provider options...
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
}
|
||||
\`\`\`
|
||||
|
||||
2\\. Start your Medusa backend:
|
||||
|
||||
\`\`\`bash npm2yarn
|
||||
npx medusa develop
|
||||
\`\`\`
|
||||
|
||||
3\\. Place an order either using the [REST APIs](https://docs.medusajs.com/api/store) or using the [storefront](https://docs.medusajs.com/starters/nextjs-medusa-starter).
|
||||
|
||||
4\\. After placing an order, you can see in your console the message “Notification Sent”. If you added your own notification sending logic, you should receive an email or alternatively the type of notification you’ve set up.`,
|
||||
`## Test Resending a Notification
|
||||
|
||||
To test resending a notification:
|
||||
|
||||
1. Retrieve the ID of the notification you just sent using the [List Notifications API Route](https://docs.medusajs.com/api/admin#notifications_getnotifications). You can pass as a body parameter the \`to\` or \`event_name\` parameters to filter out the notification you just sent.
|
||||
|
||||
2. Send a request to the [Resend Notification API Route](https://docs.medusajs.com/api/admin#notifications_postnotificationsnotificationresend) using the ID retrieved from the previous request. You can pass the \`to\` parameter in the body to change the receiver of the notification.
|
||||
|
||||
3. You should see the message “Notification Resent” in your console.
|
||||
`,
|
||||
`,
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user