diff --git a/packages/core/types/src/notification/provider.ts b/packages/core/types/src/notification/provider.ts index 218679d52b..89bf3c5ade 100644 --- a/packages/core/types/src/notification/provider.ts +++ b/packages/core/types/src/notification/provider.ts @@ -34,12 +34,6 @@ export type ProviderSendNotificationResultsDTO = { id?: string } -/** - * ## Overview - * - * Notification provider interface for the notification module. - * - */ export interface INotificationProvider { /** * This method is used to send a notification. diff --git a/packages/core/utils/src/notification/abstract-notification-provider.ts b/packages/core/utils/src/notification/abstract-notification-provider.ts index 04b96f55fd..4b2071ac5a 100644 --- a/packages/core/utils/src/notification/abstract-notification-provider.ts +++ b/packages/core/utils/src/notification/abstract-notification-provider.ts @@ -1,8 +1,78 @@ import { NotificationTypes, INotificationProvider } from "@medusajs/types" +/** + * ### constructor + * + * The constructor allows you to access resources from the module's container using the first parameter, + * and the module's options using the second parameter. + * + * If you're creating a client or establishing a connection with a third-party service, do it in the constructor. + * + * #### Example + * + * ```ts + * import { AbstractNotificationProviderService } from "@medusajs/utils" + * import { Logger } from "@medusajs/types" + * + * type InjectedDependencies = { + * logger: Logger + * } + * + * type Options = { + * apiKey: string + * } + * + * class MyNotificationProviderService extends AbstractNotificationProviderService { + * protected logger_: Logger + * protected options_: Options + * // assuming you're initializing a client + * protected client + * + * constructor ( + * { logger }: InjectedDependencies, + * options: Options + * ) { + * super() + * + * this.logger_ = logger + * this.options_ = options + * + * // assuming you're initializing a client + * this.client = new Client(options) + * } + * } + * + * export default MyNotificationProviderService + * ``` + */ export class AbstractNotificationProviderService implements INotificationProvider { + /** + * This method is used to send a notification using the third-party provider or your custom logic. + * + * @param {NotificationTypes.ProviderSendNotificationDTO} notification - The details of the + * notification to send. + * @returns {Promise} The result of sending + * the notification. + * + * @example + * class MyNotificationProviderService extends AbstractNotificationProviderService { + * // ... + * async send( + * notification: ProviderSendNotificationDTO + * ): Promise { + * // TODO send the notification using a third-party + * // provider or custom logic. + * // for example: + * return this.client.send({ + * email: notification.to, + * template: notification.template, + * template_data: notification.data + * }) + * } + * } + */ async send( notification: NotificationTypes.ProviderSendNotificationDTO ): Promise { diff --git a/www/utils/packages/typedoc-generate-references/src/constants/merger-custom-options/notification.ts b/www/utils/packages/typedoc-generate-references/src/constants/merger-custom-options/notification.ts index 4e723766da..14044ba5ae 100644 --- a/www/utils/packages/typedoc-generate-references/src/constants/merger-custom-options/notification.ts +++ b/www/utils/packages/typedoc-generate-references/src/constants/merger-custom-options/notification.ts @@ -1,14 +1,10 @@ import { FormattingOptionsType } from "types" const notificationOptions: FormattingOptionsType = { - "^notification": { - frontmatterData: { - displayed_sidebar: "core", - }, - }, "^notification/.*AbstractNotificationProviderService": { reflectionGroups: { Properties: false, + Constructors: false, }, reflectionDescription: `In this document, you’ll learn how to create a notification provider module and the methods you must implement in it.`, frontmatterData: {