chore(types, utils): add TSDocs for AbstractNotificationProviderService (#7556)

Add TSDocs for `AbstractNotificationProviderService` which will be used to generate a reference on how to create a notification provider module.
This commit is contained in:
Shahed Nasser
2024-06-04 16:36:06 +03:00
committed by GitHub
parent 1a1ef4f208
commit 6646a203df
3 changed files with 71 additions and 11 deletions

View File

@@ -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.

View File

@@ -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<NotificationTypes.ProviderSendNotificationResultsDTO>} The result of sending
* the notification.
*
* @example
* class MyNotificationProviderService extends AbstractNotificationProviderService {
* // ...
* async send(
* notification: ProviderSendNotificationDTO
* ): Promise<ProviderSendNotificationResultsDTO> {
* // 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<NotificationTypes.ProviderSendNotificationResultsDTO> {

View File

@@ -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, youll learn how to create a notification provider module and the methods you must implement in it.`,
frontmatterData: {