@contractspec/module.notifications 1.44.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.
- package/LICENSE +21 -0
- package/README.md +121 -0
- package/dist/channels/index.d.ts +107 -0
- package/dist/channels/index.d.ts.map +1 -0
- package/dist/channels/index.js +127 -0
- package/dist/channels/index.js.map +1 -0
- package/dist/contracts/index.d.ts +638 -0
- package/dist/contracts/index.d.ts.map +1 -0
- package/dist/contracts/index.js +433 -0
- package/dist/contracts/index.js.map +1 -0
- package/dist/entities/index.d.ts +183 -0
- package/dist/entities/index.d.ts.map +1 -0
- package/dist/entities/index.js +254 -0
- package/dist/entities/index.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +7 -0
- package/dist/notifications.feature.d.ts +12 -0
- package/dist/notifications.feature.d.ts.map +1 -0
- package/dist/notifications.feature.js +70 -0
- package/dist/notifications.feature.js.map +1 -0
- package/dist/templates/index.d.ts +92 -0
- package/dist/templates/index.d.ts.map +1 -0
- package/dist/templates/index.js +202 -0
- package/dist/templates/index.js.map +1 -0
- package/package.json +65 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Chaman Ventures, SASU
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# @contractspec/module.notifications
|
|
2
|
+
|
|
3
|
+
Website: https://contractspec.io/
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
Notification center module for ContractSpec applications.
|
|
7
|
+
|
|
8
|
+
## Purpose
|
|
9
|
+
|
|
10
|
+
Provides a unified notification system supporting multiple delivery channels (email, in-app, push, webhook). Handles notification preferences, templates, and delivery tracking.
|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
- **Multi-Channel Delivery**: Email, in-app, push notifications, webhooks
|
|
15
|
+
- **User Preferences**: Per-user notification preferences by type and channel
|
|
16
|
+
- **Templates**: Template-based notifications with variable substitution
|
|
17
|
+
- **Delivery Tracking**: Track delivery status and read receipts
|
|
18
|
+
- **Batching**: Digest and batch notifications to reduce noise
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
bun add @contractspec/module.notifications
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
### Entity Specs (for schema generation)
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { notificationsSchemaContribution } from '@contractspec/module.notifications/entities';
|
|
32
|
+
|
|
33
|
+
// Use in schema composition
|
|
34
|
+
const config = {
|
|
35
|
+
modules: [notificationsSchemaContribution],
|
|
36
|
+
};
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Send Notifications
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
import { NotificationService } from '@contractspec/module.notifications';
|
|
43
|
+
|
|
44
|
+
const service = new NotificationService({
|
|
45
|
+
channels: {
|
|
46
|
+
email: emailChannel,
|
|
47
|
+
inApp: inAppChannel,
|
|
48
|
+
push: pushChannel,
|
|
49
|
+
},
|
|
50
|
+
defaultChannel: 'inApp',
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// Send a notification
|
|
54
|
+
await service.send({
|
|
55
|
+
userId: 'user-123',
|
|
56
|
+
templateId: 'welcome',
|
|
57
|
+
variables: {
|
|
58
|
+
name: 'John',
|
|
59
|
+
actionUrl: 'https://app.example.com/onboarding',
|
|
60
|
+
},
|
|
61
|
+
channels: ['email', 'inApp'],
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Configure Templates
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
import { defineTemplate } from '@contractspec/module.notifications/templates';
|
|
69
|
+
|
|
70
|
+
const welcomeTemplate = defineTemplate({
|
|
71
|
+
id: 'welcome',
|
|
72
|
+
name: 'Welcome Email',
|
|
73
|
+
channels: {
|
|
74
|
+
email: {
|
|
75
|
+
subject: 'Welcome to {{appName}}, {{name}}!',
|
|
76
|
+
body: `
|
|
77
|
+
<h1>Welcome, {{name}}!</h1>
|
|
78
|
+
<p>Thanks for joining. Get started by clicking below.</p>
|
|
79
|
+
<a href="{{actionUrl}}">Get Started</a>
|
|
80
|
+
`,
|
|
81
|
+
},
|
|
82
|
+
inApp: {
|
|
83
|
+
title: 'Welcome to {{appName}}!',
|
|
84
|
+
body: 'Click here to complete your profile.',
|
|
85
|
+
actionUrl: '{{actionUrl}}',
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### User Preferences
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
// Get user preferences
|
|
95
|
+
const prefs = await service.getPreferences('user-123');
|
|
96
|
+
|
|
97
|
+
// Update preferences
|
|
98
|
+
await service.updatePreferences('user-123', {
|
|
99
|
+
email: { marketing: false, transactional: true },
|
|
100
|
+
push: { mentions: true, updates: false },
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Entity Overview
|
|
105
|
+
|
|
106
|
+
| Entity | Description |
|
|
107
|
+
|--------|-------------|
|
|
108
|
+
| Notification | Individual notification instance |
|
|
109
|
+
| NotificationTemplate | Notification templates |
|
|
110
|
+
| NotificationPreference | User notification preferences |
|
|
111
|
+
| DeliveryLog | Delivery attempt tracking |
|
|
112
|
+
|
|
113
|
+
## Channels
|
|
114
|
+
|
|
115
|
+
| Channel | Description |
|
|
116
|
+
|---------|-------------|
|
|
117
|
+
| email | Email delivery (SMTP, SendGrid, etc.) |
|
|
118
|
+
| inApp | In-application notifications |
|
|
119
|
+
| push | Push notifications (FCM, APNs) |
|
|
120
|
+
| webhook | Webhook delivery for integrations |
|
|
121
|
+
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
//#region src/channels/index.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Notification channel interface.
|
|
4
|
+
*/
|
|
5
|
+
interface NotificationChannel {
|
|
6
|
+
/** Channel identifier */
|
|
7
|
+
readonly channelId: string;
|
|
8
|
+
/** Deliver a notification */
|
|
9
|
+
send(notification: ChannelNotification): Promise<ChannelDeliveryResult>;
|
|
10
|
+
/** Check if channel is available */
|
|
11
|
+
isAvailable(): Promise<boolean>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Notification to deliver via a channel.
|
|
15
|
+
*/
|
|
16
|
+
interface ChannelNotification {
|
|
17
|
+
id: string;
|
|
18
|
+
userId: string;
|
|
19
|
+
title: string;
|
|
20
|
+
body: string;
|
|
21
|
+
actionUrl?: string;
|
|
22
|
+
imageUrl?: string;
|
|
23
|
+
metadata?: Record<string, unknown>;
|
|
24
|
+
email?: {
|
|
25
|
+
to: string;
|
|
26
|
+
subject: string;
|
|
27
|
+
html?: string;
|
|
28
|
+
text?: string;
|
|
29
|
+
};
|
|
30
|
+
push?: {
|
|
31
|
+
token: string;
|
|
32
|
+
badge?: number;
|
|
33
|
+
sound?: string;
|
|
34
|
+
data?: Record<string, unknown>;
|
|
35
|
+
};
|
|
36
|
+
webhook?: {
|
|
37
|
+
url: string;
|
|
38
|
+
headers?: Record<string, string>;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Result of channel delivery attempt.
|
|
43
|
+
*/
|
|
44
|
+
interface ChannelDeliveryResult {
|
|
45
|
+
success: boolean;
|
|
46
|
+
externalId?: string;
|
|
47
|
+
responseCode?: string;
|
|
48
|
+
responseMessage?: string;
|
|
49
|
+
metadata?: Record<string, unknown>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* In-app notification channel (stores in database).
|
|
53
|
+
*/
|
|
54
|
+
declare class InAppChannel implements NotificationChannel {
|
|
55
|
+
readonly channelId = "IN_APP";
|
|
56
|
+
send(_notification: ChannelNotification): Promise<ChannelDeliveryResult>;
|
|
57
|
+
isAvailable(): Promise<boolean>;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Console channel for development/testing.
|
|
61
|
+
*/
|
|
62
|
+
declare class ConsoleChannel implements NotificationChannel {
|
|
63
|
+
readonly channelId = "CONSOLE";
|
|
64
|
+
send(notification: ChannelNotification): Promise<ChannelDeliveryResult>;
|
|
65
|
+
isAvailable(): Promise<boolean>;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Email channel interface (to be implemented with provider).
|
|
69
|
+
*/
|
|
70
|
+
declare abstract class EmailChannel implements NotificationChannel {
|
|
71
|
+
readonly channelId = "EMAIL";
|
|
72
|
+
abstract send(notification: ChannelNotification): Promise<ChannelDeliveryResult>;
|
|
73
|
+
isAvailable(): Promise<boolean>;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Push notification channel interface (to be implemented with provider).
|
|
77
|
+
*/
|
|
78
|
+
declare abstract class PushChannel implements NotificationChannel {
|
|
79
|
+
readonly channelId = "PUSH";
|
|
80
|
+
abstract send(notification: ChannelNotification): Promise<ChannelDeliveryResult>;
|
|
81
|
+
isAvailable(): Promise<boolean>;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Webhook channel for external integrations.
|
|
85
|
+
*/
|
|
86
|
+
declare class WebhookChannel implements NotificationChannel {
|
|
87
|
+
readonly channelId = "WEBHOOK";
|
|
88
|
+
send(notification: ChannelNotification): Promise<ChannelDeliveryResult>;
|
|
89
|
+
isAvailable(): Promise<boolean>;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Channel registry for managing available channels.
|
|
93
|
+
*/
|
|
94
|
+
declare class ChannelRegistry {
|
|
95
|
+
private channels;
|
|
96
|
+
register(channel: NotificationChannel): void;
|
|
97
|
+
get(channelId: string): NotificationChannel | undefined;
|
|
98
|
+
getAll(): NotificationChannel[];
|
|
99
|
+
getAvailable(): Promise<NotificationChannel[]>;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Create a default channel registry with standard channels.
|
|
103
|
+
*/
|
|
104
|
+
declare function createChannelRegistry(): ChannelRegistry;
|
|
105
|
+
//#endregion
|
|
106
|
+
export { ChannelDeliveryResult, ChannelNotification, ChannelRegistry, ConsoleChannel, EmailChannel, InAppChannel, NotificationChannel, PushChannel, WebhookChannel, createChannelRegistry };
|
|
107
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/channels/index.ts"],"sourcesContent":[],"mappings":";;AAGA;;AAImD,UAJlC,mBAAA,CAIkC;EAAR;EAE1B,SAAA,SAAA,EAAA,MAAA;EAAO;EAMP,IAAA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AA;EAcf,WAAA,CAAA,CAAA,EA/IO,OA+IP,CAAA,OAAqB,CAAA;;;;;cAvIxB,cAAA,YAA0B;;qBAIrB,sBACb,QAAQ;iBAYU;;;;;uBAQD,YAAA,YAAwB;;8BAI5B,sBACb,QAAQ;iBAEU;;;;;uBAQD,WAAA,YAAuB;;8BAI3B,sBACb,QAAQ;iBAEU;;;;;cAQV,cAAA,YAA0B;;qBAIrB,sBACb,QAAQ;iBAsCU;;;;;cAQV,eAAA;;oBAGO;0BAIM;YAId;kBAIY,QAAQ;;;;;iBAchB,qBAAA,CAAA,GAAyB"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
//#region src/channels/index.ts
|
|
2
|
+
/**
|
|
3
|
+
* In-app notification channel (stores in database).
|
|
4
|
+
*/
|
|
5
|
+
var InAppChannel = class {
|
|
6
|
+
channelId = "IN_APP";
|
|
7
|
+
async send(_notification) {
|
|
8
|
+
return {
|
|
9
|
+
success: true,
|
|
10
|
+
responseMessage: "Stored in database"
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
async isAvailable() {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Console channel for development/testing.
|
|
19
|
+
*/
|
|
20
|
+
var ConsoleChannel = class {
|
|
21
|
+
channelId = "CONSOLE";
|
|
22
|
+
async send(notification) {
|
|
23
|
+
console.log(`📬 [${notification.id}] ${notification.title}`);
|
|
24
|
+
console.log(` ${notification.body}`);
|
|
25
|
+
if (notification.actionUrl) console.log(` Action: ${notification.actionUrl}`);
|
|
26
|
+
return {
|
|
27
|
+
success: true,
|
|
28
|
+
responseMessage: "Logged to console"
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
async isAvailable() {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Email channel interface (to be implemented with provider).
|
|
37
|
+
*/
|
|
38
|
+
var EmailChannel = class {
|
|
39
|
+
channelId = "EMAIL";
|
|
40
|
+
async isAvailable() {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Push notification channel interface (to be implemented with provider).
|
|
46
|
+
*/
|
|
47
|
+
var PushChannel = class {
|
|
48
|
+
channelId = "PUSH";
|
|
49
|
+
async isAvailable() {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Webhook channel for external integrations.
|
|
55
|
+
*/
|
|
56
|
+
var WebhookChannel = class {
|
|
57
|
+
channelId = "WEBHOOK";
|
|
58
|
+
async send(notification) {
|
|
59
|
+
if (!notification.webhook?.url) return {
|
|
60
|
+
success: false,
|
|
61
|
+
responseMessage: "No webhook URL configured"
|
|
62
|
+
};
|
|
63
|
+
try {
|
|
64
|
+
const response = await fetch(notification.webhook.url, {
|
|
65
|
+
method: "POST",
|
|
66
|
+
headers: {
|
|
67
|
+
"Content-Type": "application/json",
|
|
68
|
+
...notification.webhook.headers
|
|
69
|
+
},
|
|
70
|
+
body: JSON.stringify({
|
|
71
|
+
id: notification.id,
|
|
72
|
+
title: notification.title,
|
|
73
|
+
body: notification.body,
|
|
74
|
+
actionUrl: notification.actionUrl,
|
|
75
|
+
metadata: notification.metadata
|
|
76
|
+
})
|
|
77
|
+
});
|
|
78
|
+
return {
|
|
79
|
+
success: response.ok,
|
|
80
|
+
responseCode: String(response.status),
|
|
81
|
+
responseMessage: response.statusText
|
|
82
|
+
};
|
|
83
|
+
} catch (error) {
|
|
84
|
+
return {
|
|
85
|
+
success: false,
|
|
86
|
+
responseMessage: error instanceof Error ? error.message : "Unknown error"
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
async isAvailable() {
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Channel registry for managing available channels.
|
|
96
|
+
*/
|
|
97
|
+
var ChannelRegistry = class {
|
|
98
|
+
channels = /* @__PURE__ */ new Map();
|
|
99
|
+
register(channel) {
|
|
100
|
+
this.channels.set(channel.channelId, channel);
|
|
101
|
+
}
|
|
102
|
+
get(channelId) {
|
|
103
|
+
return this.channels.get(channelId);
|
|
104
|
+
}
|
|
105
|
+
getAll() {
|
|
106
|
+
return Array.from(this.channels.values());
|
|
107
|
+
}
|
|
108
|
+
async getAvailable() {
|
|
109
|
+
const available = [];
|
|
110
|
+
for (const channel of this.channels.values()) if (await channel.isAvailable()) available.push(channel);
|
|
111
|
+
return available;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Create a default channel registry with standard channels.
|
|
116
|
+
*/
|
|
117
|
+
function createChannelRegistry() {
|
|
118
|
+
const registry = new ChannelRegistry();
|
|
119
|
+
registry.register(new InAppChannel());
|
|
120
|
+
registry.register(new ConsoleChannel());
|
|
121
|
+
registry.register(new WebhookChannel());
|
|
122
|
+
return registry;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
//#endregion
|
|
126
|
+
export { ChannelRegistry, ConsoleChannel, EmailChannel, InAppChannel, PushChannel, WebhookChannel, createChannelRegistry };
|
|
127
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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,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