@contractspec/module.notifications 1.46.2 → 1.48.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["available: NotificationChannel[]"],"sources":["../../src/channels/index.ts"],"sourcesContent":["/**\n * Notification channel interface.\n */\nexport interface NotificationChannel {\n /** Channel identifier */\n readonly channelId: string;\n /** Deliver a notification */\n send(notification: ChannelNotification): Promise<ChannelDeliveryResult>;\n /** Check if channel is available */\n isAvailable(): Promise<boolean>;\n}\n\n/**\n * Notification to deliver via a channel.\n */\nexport interface ChannelNotification {\n id: string;\n userId: string;\n title: string;\n body: string;\n actionUrl?: string;\n imageUrl?: string;\n metadata?: Record<string, unknown>;\n // Channel-specific data\n email?: {\n to: string;\n subject: string;\n html?: string;\n text?: string;\n };\n push?: {\n token: string;\n badge?: number;\n sound?: string;\n data?: Record<string, unknown>;\n };\n webhook?: {\n url: string;\n headers?: Record<string, string>;\n };\n}\n\n/**\n * Result of channel delivery attempt.\n */\nexport interface ChannelDeliveryResult {\n success: boolean;\n externalId?: string;\n responseCode?: string;\n responseMessage?: string;\n metadata?: Record<string, unknown>;\n}\n\n/**\n * In-app notification channel (stores in database).\n */\nexport class InAppChannel implements NotificationChannel {\n readonly channelId = 'IN_APP';\n\n async send(\n _notification: ChannelNotification\n ): Promise<ChannelDeliveryResult> {\n // In-app notifications are stored directly in the database\n // The actual delivery is handled by the notification service\n return {\n success: true,\n responseMessage: 'Stored in database',\n };\n }\n\n async isAvailable(): Promise<boolean> {\n return true;\n }\n}\n\n/**\n * Console channel for development/testing.\n */\nexport class ConsoleChannel implements NotificationChannel {\n readonly channelId = 'CONSOLE';\n\n async send(\n notification: ChannelNotification\n ): Promise<ChannelDeliveryResult> {\n console.log(`📬 [${notification.id}] ${notification.title}`);\n console.log(` ${notification.body}`);\n if (notification.actionUrl) {\n console.log(` Action: ${notification.actionUrl}`);\n }\n return {\n success: true,\n responseMessage: 'Logged to console',\n };\n }\n\n async isAvailable(): Promise<boolean> {\n return true;\n }\n}\n\n/**\n * Email channel interface (to be implemented with provider).\n */\nexport abstract class EmailChannel implements NotificationChannel {\n readonly channelId = 'EMAIL';\n\n abstract send(\n notification: ChannelNotification\n ): Promise<ChannelDeliveryResult>;\n\n async isAvailable(): Promise<boolean> {\n return true;\n }\n}\n\n/**\n * Push notification channel interface (to be implemented with provider).\n */\nexport abstract class PushChannel implements NotificationChannel {\n readonly channelId = 'PUSH';\n\n abstract send(\n notification: ChannelNotification\n ): Promise<ChannelDeliveryResult>;\n\n async isAvailable(): Promise<boolean> {\n return true;\n }\n}\n\n/**\n * Webhook channel for external integrations.\n */\nexport class WebhookChannel implements NotificationChannel {\n readonly channelId = 'WEBHOOK';\n\n async send(\n notification: ChannelNotification\n ): Promise<ChannelDeliveryResult> {\n if (!notification.webhook?.url) {\n return {\n success: false,\n responseMessage: 'No webhook URL configured',\n };\n }\n\n try {\n const response = await fetch(notification.webhook.url, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...notification.webhook.headers,\n },\n body: JSON.stringify({\n id: notification.id,\n title: notification.title,\n body: notification.body,\n actionUrl: notification.actionUrl,\n metadata: notification.metadata,\n }),\n });\n\n return {\n success: response.ok,\n responseCode: String(response.status),\n responseMessage: response.statusText,\n };\n } catch (error) {\n return {\n success: false,\n responseMessage:\n error instanceof Error ? error.message : 'Unknown error',\n };\n }\n }\n\n async isAvailable(): Promise<boolean> {\n return true;\n }\n}\n\n/**\n * Channel registry for managing available channels.\n */\nexport class ChannelRegistry {\n private channels = new Map<string, NotificationChannel>();\n\n register(channel: NotificationChannel): void {\n this.channels.set(channel.channelId, channel);\n }\n\n get(channelId: string): NotificationChannel | undefined {\n return this.channels.get(channelId);\n }\n\n getAll(): NotificationChannel[] {\n return Array.from(this.channels.values());\n }\n\n async getAvailable(): Promise<NotificationChannel[]> {\n const available: NotificationChannel[] = [];\n for (const channel of this.channels.values()) {\n if (await channel.isAvailable()) {\n available.push(channel);\n }\n }\n return available;\n }\n}\n\n/**\n * Create a default channel registry with standard channels.\n */\nexport function createChannelRegistry(): ChannelRegistry {\n const registry = new ChannelRegistry();\n registry.register(new InAppChannel());\n registry.register(new ConsoleChannel());\n registry.register(new WebhookChannel());\n return registry;\n}\n"],"mappings":";;;;AAwDA,IAAa,eAAb,MAAyD;CACvD,AAAS,YAAY;CAErB,MAAM,KACJ,eACgC;AAGhC,SAAO;GACL,SAAS;GACT,iBAAiB;GAClB;;CAGH,MAAM,cAAgC;AACpC,SAAO;;;;;;AAOX,IAAa,iBAAb,MAA2D;CACzD,AAAS,YAAY;CAErB,MAAM,KACJ,cACgC;AAChC,UAAQ,IAAI,OAAO,aAAa,GAAG,IAAI,aAAa,QAAQ;AAC5D,UAAQ,IAAI,MAAM,aAAa,OAAO;AACtC,MAAI,aAAa,UACf,SAAQ,IAAI,cAAc,aAAa,YAAY;AAErD,SAAO;GACL,SAAS;GACT,iBAAiB;GAClB;;CAGH,MAAM,cAAgC;AACpC,SAAO;;;;;;AAOX,IAAsB,eAAtB,MAAkE;CAChE,AAAS,YAAY;CAMrB,MAAM,cAAgC;AACpC,SAAO;;;;;;AAOX,IAAsB,cAAtB,MAAiE;CAC/D,AAAS,YAAY;CAMrB,MAAM,cAAgC;AACpC,SAAO;;;;;;AAOX,IAAa,iBAAb,MAA2D;CACzD,AAAS,YAAY;CAErB,MAAM,KACJ,cACgC;AAChC,MAAI,CAAC,aAAa,SAAS,IACzB,QAAO;GACL,SAAS;GACT,iBAAiB;GAClB;AAGH,MAAI;GACF,MAAM,WAAW,MAAM,MAAM,aAAa,QAAQ,KAAK;IACrD,QAAQ;IACR,SAAS;KACP,gBAAgB;KAChB,GAAG,aAAa,QAAQ;KACzB;IACD,MAAM,KAAK,UAAU;KACnB,IAAI,aAAa;KACjB,OAAO,aAAa;KACpB,MAAM,aAAa;KACnB,WAAW,aAAa;KACxB,UAAU,aAAa;KACxB,CAAC;IACH,CAAC;AAEF,UAAO;IACL,SAAS,SAAS;IAClB,cAAc,OAAO,SAAS,OAAO;IACrC,iBAAiB,SAAS;IAC3B;WACM,OAAO;AACd,UAAO;IACL,SAAS;IACT,iBACE,iBAAiB,QAAQ,MAAM,UAAU;IAC5C;;;CAIL,MAAM,cAAgC;AACpC,SAAO;;;;;;AAOX,IAAa,kBAAb,MAA6B;CAC3B,AAAQ,2BAAW,IAAI,KAAkC;CAEzD,SAAS,SAAoC;AAC3C,OAAK,SAAS,IAAI,QAAQ,WAAW,QAAQ;;CAG/C,IAAI,WAAoD;AACtD,SAAO,KAAK,SAAS,IAAI,UAAU;;CAGrC,SAAgC;AAC9B,SAAO,MAAM,KAAK,KAAK,SAAS,QAAQ,CAAC;;CAG3C,MAAM,eAA+C;EACnD,MAAMA,YAAmC,EAAE;AAC3C,OAAK,MAAM,WAAW,KAAK,SAAS,QAAQ,CAC1C,KAAI,MAAM,QAAQ,aAAa,CAC7B,WAAU,KAAK,QAAQ;AAG3B,SAAO;;;;;;AAOX,SAAgB,wBAAyC;CACvD,MAAM,WAAW,IAAI,iBAAiB;AACtC,UAAS,SAAS,IAAI,cAAc,CAAC;AACrC,UAAS,SAAS,IAAI,gBAAgB,CAAC;AACvC,UAAS,SAAS,IAAI,gBAAgB,CAAC;AACvC,QAAO"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/channels/index.ts"],"sourcesContent":["/**\n * Notification channel interface.\n */\nexport interface NotificationChannel {\n /** Channel identifier */\n readonly channelId: string;\n /** Deliver a notification */\n send(notification: ChannelNotification): Promise<ChannelDeliveryResult>;\n /** Check if channel is available */\n isAvailable(): Promise<boolean>;\n}\n\n/**\n * Notification to deliver via a channel.\n */\nexport interface ChannelNotification {\n id: string;\n userId: string;\n title: string;\n body: string;\n actionUrl?: string;\n imageUrl?: string;\n metadata?: Record<string, unknown>;\n // Channel-specific data\n email?: {\n to: string;\n subject: string;\n html?: string;\n text?: string;\n };\n push?: {\n token: string;\n badge?: number;\n sound?: string;\n data?: Record<string, unknown>;\n };\n webhook?: {\n url: string;\n headers?: Record<string, string>;\n };\n}\n\n/**\n * Result of channel delivery attempt.\n */\nexport interface ChannelDeliveryResult {\n success: boolean;\n externalId?: string;\n responseCode?: string;\n responseMessage?: string;\n metadata?: Record<string, unknown>;\n}\n\n/**\n * In-app notification channel (stores in database).\n */\nexport class InAppChannel implements NotificationChannel {\n readonly channelId = 'IN_APP';\n\n async send(\n _notification: ChannelNotification\n ): Promise<ChannelDeliveryResult> {\n // In-app notifications are stored directly in the database\n // The actual delivery is handled by the notification service\n return {\n success: true,\n responseMessage: 'Stored in database',\n };\n }\n\n async isAvailable(): Promise<boolean> {\n return true;\n }\n}\n\n/**\n * Console channel for development/testing.\n */\nexport class ConsoleChannel implements NotificationChannel {\n readonly channelId = 'CONSOLE';\n\n async send(\n notification: ChannelNotification\n ): Promise<ChannelDeliveryResult> {\n console.log(`📬 [${notification.id}] ${notification.title}`);\n console.log(` ${notification.body}`);\n if (notification.actionUrl) {\n console.log(` Action: ${notification.actionUrl}`);\n }\n return {\n success: true,\n responseMessage: 'Logged to console',\n };\n }\n\n async isAvailable(): Promise<boolean> {\n return true;\n }\n}\n\n/**\n * Email channel interface (to be implemented with provider).\n */\nexport abstract class EmailChannel implements NotificationChannel {\n readonly channelId = 'EMAIL';\n\n abstract send(\n notification: ChannelNotification\n ): Promise<ChannelDeliveryResult>;\n\n async isAvailable(): Promise<boolean> {\n return true;\n }\n}\n\n/**\n * Push notification channel interface (to be implemented with provider).\n */\nexport abstract class PushChannel implements NotificationChannel {\n readonly channelId = 'PUSH';\n\n abstract send(\n notification: ChannelNotification\n ): Promise<ChannelDeliveryResult>;\n\n async isAvailable(): Promise<boolean> {\n return true;\n }\n}\n\n/**\n * Webhook channel for external integrations.\n */\nexport class WebhookChannel implements NotificationChannel {\n readonly channelId = 'WEBHOOK';\n\n async send(\n notification: ChannelNotification\n ): Promise<ChannelDeliveryResult> {\n if (!notification.webhook?.url) {\n return {\n success: false,\n responseMessage: 'No webhook URL configured',\n };\n }\n\n try {\n const response = await fetch(notification.webhook.url, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...notification.webhook.headers,\n },\n body: JSON.stringify({\n id: notification.id,\n title: notification.title,\n body: notification.body,\n actionUrl: notification.actionUrl,\n metadata: notification.metadata,\n }),\n });\n\n return {\n success: response.ok,\n responseCode: String(response.status),\n responseMessage: response.statusText,\n };\n } catch (error) {\n return {\n success: false,\n responseMessage:\n error instanceof Error ? error.message : 'Unknown error',\n };\n }\n }\n\n async isAvailable(): Promise<boolean> {\n return true;\n }\n}\n\n/**\n * Channel registry for managing available channels.\n */\nexport class ChannelRegistry {\n private channels = new Map<string, NotificationChannel>();\n\n register(channel: NotificationChannel): void {\n this.channels.set(channel.channelId, channel);\n }\n\n get(channelId: string): NotificationChannel | undefined {\n return this.channels.get(channelId);\n }\n\n getAll(): NotificationChannel[] {\n return Array.from(this.channels.values());\n }\n\n async getAvailable(): Promise<NotificationChannel[]> {\n const available: NotificationChannel[] = [];\n for (const channel of this.channels.values()) {\n if (await channel.isAvailable()) {\n available.push(channel);\n }\n }\n return available;\n }\n}\n\n/**\n * Create a default channel registry with standard channels.\n */\nexport function createChannelRegistry(): ChannelRegistry {\n const registry = new ChannelRegistry();\n registry.register(new InAppChannel());\n registry.register(new ConsoleChannel());\n registry.register(new WebhookChannel());\n return registry;\n}\n"],"mappings":";;;;AAwDA,IAAa,eAAb,MAAyD;CACvD,AAAS,YAAY;CAErB,MAAM,KACJ,eACgC;AAGhC,SAAO;GACL,SAAS;GACT,iBAAiB;GAClB;;CAGH,MAAM,cAAgC;AACpC,SAAO;;;;;;AAOX,IAAa,iBAAb,MAA2D;CACzD,AAAS,YAAY;CAErB,MAAM,KACJ,cACgC;AAChC,UAAQ,IAAI,OAAO,aAAa,GAAG,IAAI,aAAa,QAAQ;AAC5D,UAAQ,IAAI,MAAM,aAAa,OAAO;AACtC,MAAI,aAAa,UACf,SAAQ,IAAI,cAAc,a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