UNPKG

@webda/core

Version:

Expose API with Lambda

77 lines (76 loc) 2.28 kB
import { Ident } from "../models/ident.js"; import { User } from "../models/user.js"; import { Service, ServiceParameters } from "./service.js"; /** * Define a service that can notify a user based on his info * It can use email or SMS or any other media */ export interface NotificationService { /** * Check if this type of notification is available */ hasNotification(notification: string): Promise<boolean>; /** * Check if the service can deliver notification to this user * @param user */ handleNotificationFor(userOrIdent: User | Ident): Promise<boolean>; /** * Send the notification to the user * @param user * @param notification * @param replacements */ sendNotification(user: User | Ident, notification: string, replacements: any): Promise<void>; } /** * Parameters for multi notification service */ export declare class MultiNotificationParameters extends ServiceParameters { /** * Notification service that will send * The order of the array is important if multiple is false * When multiple is `false` the first available NotificationService will * be used, otherwise every available NotificationService will be used */ senders: string[]; /** * Define if it sends one or several notification per user * @default false */ multiple?: boolean; /** * @override */ constructor(params: any); } /** * Allow an aggregation of Notification to send via multiple media * like SMS and Email * * @WebdaModda */ export default class MultiNotificationService<T extends MultiNotificationParameters = MultiNotificationParameters> extends Service<T> implements NotificationService { senders: NotificationService[]; /** * @override */ loadParameters(params: any): MultiNotificationParameters; /** * @override */ resolve(): this; /** * @override */ sendNotification(user: User | Ident, notification: string, replacements: any): Promise<void>; /** * @override */ handleNotificationFor(user: User | Ident): Promise<boolean>; /** * @override */ hasNotification(notification: string): Promise<boolean>; } export { MultiNotificationService };