@wild-framework/notifications 0.1.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Wild Framework contributors
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,28 @@
1
+ # @wild-framework/notifications
2
+
3
+ Multi-channel notifications for [Wild Framework](https://github.com/your-org/wild-framework).
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pnpm add @wild-framework/notifications
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { Notification, NotificationManager } from "@wild-framework/notifications";
15
+
16
+ class WelcomeNotification extends Notification {
17
+ via() { return ["mail", "database"] as const; }
18
+ toMail() { return { subject: "Welcome!", html: "<h1>Hello</h1>" }; }
19
+ toDatabase() { return { type: "welcome" }; }
20
+ }
21
+
22
+ const notifications = app.resolve(NotificationManager);
23
+ await notifications.send(user, new WelcomeNotification(user));
24
+ ```
25
+
26
+ ## License
27
+
28
+ MIT
@@ -0,0 +1,5 @@
1
+ export { NotificationManager } from "./manager.js";
2
+ export { NotificationProvider } from "./provider.js";
3
+ export { Notification } from "./notification.js";
4
+ export type { DatabaseNotification, Notifiable } from "./notification.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,YAAY,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export { NotificationManager } from "./manager.js";
2
+ export { NotificationProvider } from "./provider.js";
3
+ export { Notification } from "./notification.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { Container } from "@wild-framework/container";
2
+ import type { Notification, Notifiable } from "./notification.js";
3
+ /**
4
+ * Sends notifications to notifiables across their declared channels.
5
+ *
6
+ * Channel dispatch:
7
+ * - `"mail"` → resolves `Mail`, sends the `toMail()` payload
8
+ * - `"database"` → resolves `Database`, inserts into the `notifications` table
9
+ */
10
+ export declare class NotificationManager {
11
+ private container;
12
+ constructor(container: Container);
13
+ /**
14
+ * Send a notification to a notifiable across all declared channels.
15
+ */
16
+ send(notifiable: Notifiable, notification: Notification): Promise<void>;
17
+ private sendMail;
18
+ private sendToDatabase;
19
+ }
20
+ //# sourceMappingURL=manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../src/manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAGtD,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAElE;;;;;;GAMG;AACH,qBAAa,mBAAmB;IAChB,OAAO,CAAC,SAAS;gBAAT,SAAS,EAAE,SAAS;IAExC;;OAEG;IACG,IAAI,CAAC,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;YAqB/D,QAAQ;YAUR,cAAc;CAW/B"}
@@ -0,0 +1,56 @@
1
+ import { Container } from "@wild-framework/container";
2
+ import { Mail } from "@wild-framework/mail";
3
+ import { Database } from "@wild-framework/database";
4
+ /**
5
+ * Sends notifications to notifiables across their declared channels.
6
+ *
7
+ * Channel dispatch:
8
+ * - `"mail"` → resolves `Mail`, sends the `toMail()` payload
9
+ * - `"database"` → resolves `Database`, inserts into the `notifications` table
10
+ */
11
+ export class NotificationManager {
12
+ container;
13
+ constructor(container) {
14
+ this.container = container;
15
+ }
16
+ /**
17
+ * Send a notification to a notifiable across all declared channels.
18
+ */
19
+ async send(notifiable, notification) {
20
+ const channels = notification.via(notifiable);
21
+ for (const channel of channels) {
22
+ switch (channel) {
23
+ case "mail":
24
+ await this.sendMail(notifiable, notification);
25
+ break;
26
+ case "database":
27
+ await this.sendToDatabase(notifiable, notification);
28
+ break;
29
+ default:
30
+ throw new Error(`Unknown notification channel "${String(channel)}".`);
31
+ }
32
+ }
33
+ }
34
+ // -------------------------------------------------------------------
35
+ // Channels
36
+ // -------------------------------------------------------------------
37
+ async sendMail(notifiable, notification) {
38
+ if (!notifiable.email) {
39
+ throw new Error(`Cannot send mail notification — notifiable has no email.`);
40
+ }
41
+ const message = notification.toMail(notifiable);
42
+ const mail = this.container.resolve(Mail);
43
+ await mail.send({ ...message, to: notifiable.email });
44
+ }
45
+ async sendToDatabase(notifiable, notification) {
46
+ const record = notification.toDatabase(notifiable);
47
+ const db = this.container.resolve(Database);
48
+ db.insert("notifications", {
49
+ notifiableId: notifiable.id,
50
+ type: record.type,
51
+ data: record.data,
52
+ readAt: record.readAt ?? null,
53
+ });
54
+ }
55
+ }
56
+ //# sourceMappingURL=manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manager.js","sourceRoot":"","sources":["../src/manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAGpD;;;;;;GAMG;AACH,MAAM,OAAO,mBAAmB;IACR;IAApB,YAAoB,SAAoB;QAApB,cAAS,GAAT,SAAS,CAAW;IAAG,CAAC;IAE5C;;OAEG;IACH,KAAK,CAAC,IAAI,CAAC,UAAsB,EAAE,YAA0B;QACzD,MAAM,QAAQ,GAAG,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAE9C,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC7B,QAAQ,OAAO,EAAE,CAAC;gBACd,KAAK,MAAM;oBACP,MAAM,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;oBAC9C,MAAM;gBACV,KAAK,UAAU;oBACX,MAAM,IAAI,CAAC,cAAc,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;oBACpD,MAAM;gBACV;oBACI,MAAM,IAAI,KAAK,CAAC,iCAAiC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAC9E,CAAC;QACL,CAAC;IACL,CAAC;IAED,sEAAsE;IACtE,WAAW;IACX,sEAAsE;IAE9D,KAAK,CAAC,QAAQ,CAAC,UAAsB,EAAE,YAA0B;QACrE,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;QAChF,CAAC;QAED,MAAM,OAAO,GAAG,YAAY,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAChD,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAO,IAAI,CAAC,CAAC;QAChD,MAAM,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,OAAO,EAAE,EAAE,EAAE,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC;IAC1D,CAAC;IAEO,KAAK,CAAC,cAAc,CAAC,UAAsB,EAAE,YAA0B;QAC3E,MAAM,MAAM,GAAG,YAAY,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;QACnD,MAAM,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAW,QAAQ,CAAC,CAAC;QAEtD,EAAE,CAAC,MAAM,CAAC,eAAe,EAAE;YACvB,YAAY,EAAE,UAAU,CAAC,EAAE;YAC3B,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,IAAI;SAChC,CAAC,CAAC;IACP,CAAC;CACJ"}
@@ -0,0 +1,44 @@
1
+ import type { MailMessage } from "@wild-framework/mail";
2
+ /**
3
+ * A record stored in the database channel's notifications table.
4
+ */
5
+ export interface DatabaseNotification {
6
+ type: string;
7
+ data?: Record<string, unknown>;
8
+ readAt?: string | null;
9
+ }
10
+ /**
11
+ * An object that can receive notifications.
12
+ */
13
+ export interface Notifiable {
14
+ id: string | number;
15
+ email?: string;
16
+ }
17
+ /**
18
+ * Base class for notifications.
19
+ *
20
+ * Subclasses declare their channels via `via()` and provide
21
+ * channel-specific payloads via `toMail()` / `toDatabase()`.
22
+ *
23
+ * @example
24
+ * class WelcomeNotification extends Notification {
25
+ * via() { return ["mail", "database"] as const; }
26
+ * toMail(notifiable) { return { subject: "Welcome!", html: "<h1>Hi</h1>" }; }
27
+ * toDatabase(notifiable) { return { type: "welcome" }; }
28
+ * }
29
+ */
30
+ export declare abstract class Notification {
31
+ /**
32
+ * Channels to send on. Implement in subclasses.
33
+ */
34
+ abstract via(notifiable: Notifiable): readonly string[];
35
+ /**
36
+ * Payload for the mail channel. Implement if `via()` includes "mail".
37
+ */
38
+ toMail(_notifiable: Notifiable): MailMessage;
39
+ /**
40
+ * Payload for the database channel. Implement if `via()` includes "database".
41
+ */
42
+ toDatabase(_notifiable: Notifiable): DatabaseNotification;
43
+ }
44
+ //# sourceMappingURL=notification.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notification.d.ts","sourceRoot":"","sources":["../src/notification.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExD;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACvB,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;;;GAYG;AACH,8BAAsB,YAAY;IAC9B;;OAEG;IACH,QAAQ,CAAC,GAAG,CAAC,UAAU,EAAE,UAAU,GAAG,SAAS,MAAM,EAAE;IAEvD;;OAEG;IACH,MAAM,CAAC,WAAW,EAAE,UAAU,GAAG,WAAW;IAI5C;;OAEG;IACH,UAAU,CAAC,WAAW,EAAE,UAAU,GAAG,oBAAoB;CAG5D"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Base class for notifications.
3
+ *
4
+ * Subclasses declare their channels via `via()` and provide
5
+ * channel-specific payloads via `toMail()` / `toDatabase()`.
6
+ *
7
+ * @example
8
+ * class WelcomeNotification extends Notification {
9
+ * via() { return ["mail", "database"] as const; }
10
+ * toMail(notifiable) { return { subject: "Welcome!", html: "<h1>Hi</h1>" }; }
11
+ * toDatabase(notifiable) { return { type: "welcome" }; }
12
+ * }
13
+ */
14
+ export class Notification {
15
+ /**
16
+ * Payload for the mail channel. Implement if `via()` includes "mail".
17
+ */
18
+ toMail(_notifiable) {
19
+ throw new Error(`Notification "${this.constructor.name}" does not support the mail channel.`);
20
+ }
21
+ /**
22
+ * Payload for the database channel. Implement if `via()` includes "database".
23
+ */
24
+ toDatabase(_notifiable) {
25
+ throw new Error(`Notification "${this.constructor.name}" does not support the database channel.`);
26
+ }
27
+ }
28
+ //# sourceMappingURL=notification.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notification.js","sourceRoot":"","sources":["../src/notification.ts"],"names":[],"mappings":"AAmBA;;;;;;;;;;;;GAYG;AACH,MAAM,OAAgB,YAAY;IAM9B;;OAEG;IACH,MAAM,CAAC,WAAuB;QAC1B,MAAM,IAAI,KAAK,CAAC,iBAAiB,IAAI,CAAC,WAAW,CAAC,IAAI,sCAAsC,CAAC,CAAC;IAClG,CAAC;IAED;;OAEG;IACH,UAAU,CAAC,WAAuB;QAC9B,MAAM,IAAI,KAAK,CAAC,iBAAiB,IAAI,CAAC,WAAW,CAAC,IAAI,0CAA0C,CAAC,CAAC;IACtG,CAAC;CACJ"}
@@ -0,0 +1,11 @@
1
+ import type { Provider, Application } from "@wild-framework/core";
2
+ /**
3
+ * Registers the notification system with the application.
4
+ *
5
+ * Binds a `NotificationManager` into the container.
6
+ * Requires `@wild-framework/mail` and `@wild-framework/database` providers for channels.
7
+ */
8
+ export declare class NotificationProvider implements Provider {
9
+ register(app: Application): void;
10
+ }
11
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAIlE;;;;;GAKG;AACH,qBAAa,oBAAqB,YAAW,QAAQ;IACjD,QAAQ,CAAC,GAAG,EAAE,WAAW,GAAG,IAAI;CAKnC"}
@@ -0,0 +1,16 @@
1
+ import { Container } from "@wild-framework/container";
2
+ import { NotificationManager } from "./manager.js";
3
+ /**
4
+ * Registers the notification system with the application.
5
+ *
6
+ * Binds a `NotificationManager` into the container.
7
+ * Requires `@wild-framework/mail` and `@wild-framework/database` providers for channels.
8
+ */
9
+ export class NotificationProvider {
10
+ register(app) {
11
+ const container = app.resolve(Container);
12
+ const manager = new NotificationManager(container);
13
+ container.singleton(NotificationManager, () => manager);
14
+ }
15
+ }
16
+ //# sourceMappingURL=provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAEnD;;;;;GAKG;AACH,MAAM,OAAO,oBAAoB;IAC7B,QAAQ,CAAC,GAAgB;QACrB,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QACzC,MAAM,OAAO,GAAG,IAAI,mBAAmB,CAAC,SAAS,CAAC,CAAC;QACnD,SAAS,CAAC,SAAS,CAAC,mBAAmB,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,CAAC;IAC5D,CAAC;CACJ"}
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@wild-framework/notifications",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js"
11
+ }
12
+ },
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "license": "MIT",
20
+ "author": "Sphah",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/KhandaSoftware/wild-framework.git"
24
+ },
25
+ "description": "Multi-channel notifications for Wild Framework.",
26
+ "keywords": [
27
+ "wild",
28
+ "framework",
29
+ "notifications",
30
+ "mail",
31
+ "channels"
32
+ ],
33
+ "dependencies": {
34
+ "@wild-framework/core": "0.1.0",
35
+ "@wild-framework/container": "0.1.0",
36
+ "@wild-framework/mail": "0.1.0",
37
+ "@wild-framework/database": "0.1.0"
38
+ },
39
+ "scripts": {
40
+ "build": "tsc",
41
+ "clean": "rm -rf dist",
42
+ "test": "vitest run"
43
+ }
44
+ }