forked from medusajs/medusa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add the basic implementation of notification module (medusajs#7282
) * feat: Add the basic implementation of notification module * fix: Minor fixes and introduction of idempotency key * fix: Changes based on PR review
- Loading branch information
Showing
43 changed files
with
1,666 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
"@medusajs/modules-sdk": minor | ||
"@medusajs/types": minor | ||
"@medusajs/utils": minor | ||
"@medusajs/notification": patch | ||
--- | ||
|
||
Add basic implementation of a notification module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
import { BaseFilterable } from "../dal" | ||
import { OperatorMap } from "../dal/utils" | ||
|
||
/** | ||
* @interface | ||
* | ||
* A notification's data. | ||
*/ | ||
export interface NotificationDTO { | ||
/** | ||
* The ID of the notification. | ||
*/ | ||
id: string | ||
/** | ||
* The recipient of the notification. It can be email, phone number, or username, depending on the channel. | ||
*/ | ||
to: string | ||
/** | ||
* The channel through which the notification is sent, such as 'email' or 'sms' | ||
*/ | ||
channel: string | ||
/** | ||
* The template name in the provider's system. | ||
*/ | ||
template: string | ||
/** | ||
* The data that gets passed over to the provider for rendering the notification. | ||
*/ | ||
data: Record<string, unknown> | null | ||
/** | ||
* The event name, the workflow, or anything else that can help to identify what triggered the notification. | ||
*/ | ||
trigger_type?: string | null | ||
/** | ||
* The ID of the resource this notification is for, if applicable. Useful for displaying relevant information in the UI | ||
*/ | ||
resource_id?: string | null | ||
/** | ||
* The type of the resource this notification is for, if applicable, eg. "order" | ||
*/ | ||
resource_type?: string | null | ||
/** | ||
* The ID of the customer this notification is for, if applicable. | ||
*/ | ||
receiver_id?: string | null | ||
/** | ||
* The original notification, in case this is a retried notification. | ||
*/ | ||
original_notification_id?: string | null | ||
/** | ||
* The id of the notification in the external system, if applicable | ||
*/ | ||
external_id?: string | null | ||
/** | ||
* The ID of the notification provider. | ||
*/ | ||
provider_id: string | ||
/** | ||
* Information about the notification provider | ||
*/ | ||
provider: NotificationProviderDTO | ||
/** | ||
* The date and time the notification was created. | ||
*/ | ||
created_at: Date | ||
} | ||
|
||
/** | ||
* @interface | ||
* | ||
* Information about the notification provider | ||
*/ | ||
export interface NotificationProviderDTO { | ||
/** | ||
* The ID of the notification provider. | ||
*/ | ||
id: string | ||
/** | ||
* The handle of the notification provider. | ||
*/ | ||
handle: string | ||
/** | ||
* A user-friendly name of the notification provider. | ||
*/ | ||
name: string | ||
/** | ||
* The supported channels by the notification provider. | ||
*/ | ||
channels: string[] | ||
} | ||
|
||
/** | ||
* @interface | ||
* | ||
* The filters to apply on retrieved notifications. | ||
* | ||
* @prop q - Search through the notifications' attributes, such as trigger types and recipients, using this search term. | ||
*/ | ||
|
||
export interface FilterableNotificationProps | ||
extends BaseFilterable<FilterableNotificationProps> { | ||
/** | ||
* Search through the notifications' attributes, such as trigger types and recipients, using this search term. | ||
*/ | ||
q?: string | ||
/** | ||
* Filter based on the recipient of the notification. | ||
*/ | ||
to?: string | string[] | OperatorMap<string | string[]> | ||
/** | ||
* Filter based on the channel through which the notification is sent, such as 'email' or 'sms' | ||
*/ | ||
channel?: string | string[] | OperatorMap<string | string[]> | ||
/** | ||
* Filter based on the template name. | ||
*/ | ||
template?: string | string[] | OperatorMap<string | string[]> | ||
/** | ||
* Filter based on the trigger type. | ||
*/ | ||
trigger_type?: string | string[] | OperatorMap<string | string[]> | ||
/** | ||
* Filter based on the resource that was the trigger for the notification. | ||
*/ | ||
resource_id?: string | string[] | OperatorMap<string | string[]> | ||
/** | ||
* T* Filter based on the resource type that was the trigger for the notification. | ||
*/ | ||
resource_type?: string | string[] | OperatorMap<string | string[]> | ||
/** | ||
* Filter based on the customer ID. | ||
*/ | ||
receiver_id?: string | string[] | OperatorMap<string | string[]> | ||
/** | ||
* Filters a notification based on when it was sent and created in the database | ||
*/ | ||
created_at?: OperatorMap<string> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export * from "./common" | ||
export * from "./providers" | ||
export * from "./mutations" | ||
export * from "./service" | ||
export * from "./provider" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* @interface | ||
* | ||
* A notification to send and have created in the DB | ||
* | ||
*/ | ||
export interface CreateNotificationDTO { | ||
/** | ||
* The recipient of the notification. It can be email, phone number, or username, depending on the channel. | ||
*/ | ||
to: string | ||
/** | ||
* The channel through which the notification is sent, such as 'email' or 'sms' | ||
*/ | ||
channel: string | ||
/** | ||
* The template name in the provider's system. | ||
*/ | ||
template: string | ||
/** | ||
* The data that gets passed over to the provider for rendering the notification. | ||
*/ | ||
data?: Record<string, unknown> | null | ||
/** | ||
* The event name, the workflow, or anything else that can help to identify what triggered the notification. | ||
*/ | ||
trigger_type?: string | null | ||
/** | ||
* The ID of the resource this notification is for, if applicable. Useful for displaying relevant information in the UI | ||
*/ | ||
resource_id?: string | null | ||
/** | ||
* The type of the resource this notification is for, if applicable, eg. "order" | ||
*/ | ||
resource_type?: string | null | ||
/** | ||
* The ID of the customer this notification is for, if applicable. | ||
*/ | ||
receiver_id?: string | null | ||
/** | ||
* The original notification, in case this is a retried notification. | ||
*/ | ||
original_notification_id?: string | null | ||
/** | ||
* An idempotency key that ensures the same notification is not sent multiple times. | ||
*/ | ||
idempotency_key?: string | null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* @interface | ||
* | ||
* The details of the notification to send. | ||
*/ | ||
export type ProviderSendNotificationDTO = { | ||
/** | ||
* The recipient of the notification. It can be email, phone number, or username, depending on the channel. | ||
*/ | ||
to: string | ||
/** | ||
* The channel through which the notification is sent, such as 'email' or 'sms' | ||
*/ | ||
channel: string | ||
/** | ||
* The template name in the provider's system. | ||
*/ | ||
template: string | ||
/** | ||
* The data that gets passed over to the provider for rendering the notification. | ||
*/ | ||
data?: Record<string, unknown> | null | ||
} | ||
|
||
/** | ||
* @interface | ||
* | ||
* The result of sending the notification | ||
*/ | ||
export type ProviderSendNotificationResultsDTO = { | ||
/** | ||
* The ID of the notification in the external system, if provided in the response | ||
*/ | ||
id?: string | ||
} | ||
|
||
/** | ||
* ## Overview | ||
* | ||
* Notification provider interface for the notification module. | ||
* | ||
*/ | ||
export interface INotificationProvider { | ||
/** | ||
* This method is used to send a notification. | ||
* | ||
* @param {ProviderSendNotificationDTO} notification - All information needed to send a notification. | ||
* @returns {Promise<ProviderSendNotificationResultsDTO>} The result of sending the notification. | ||
* | ||
*/ | ||
send( | ||
notification: ProviderSendNotificationDTO | ||
): Promise<ProviderSendNotificationResultsDTO> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./local" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export interface LocalNotificationServiceOptions {} |
Oops, something went wrong.