@warlock.js/notifications 4.2.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.
Files changed (111) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/LICENSE +21 -0
  3. package/README.md +57 -0
  4. package/cjs/index.cjs +1034 -0
  5. package/cjs/index.cjs.map +1 -0
  6. package/esm/channels/database-channel.d.mts +10 -0
  7. package/esm/channels/database-channel.d.mts.map +1 -0
  8. package/esm/channels/database-channel.mjs +19 -0
  9. package/esm/channels/database-channel.mjs.map +1 -0
  10. package/esm/channels/index.d.mts +2 -0
  11. package/esm/channels/index.mjs +4 -0
  12. package/esm/channels/mail-channel.d.mts +11 -0
  13. package/esm/channels/mail-channel.d.mts.map +1 -0
  14. package/esm/channels/mail-channel.mjs +43 -0
  15. package/esm/channels/mail-channel.mjs.map +1 -0
  16. package/esm/config.d.mts +46 -0
  17. package/esm/config.d.mts.map +1 -0
  18. package/esm/config.mjs +32 -0
  19. package/esm/config.mjs.map +1 -0
  20. package/esm/contracts/channel.contract.d.mts +38 -0
  21. package/esm/contracts/channel.contract.d.mts.map +1 -0
  22. package/esm/contracts/index.d.mts +5 -0
  23. package/esm/contracts/notification.contract.d.mts +18 -0
  24. package/esm/contracts/notification.contract.d.mts.map +1 -0
  25. package/esm/contracts/preference-provider.contract.d.mts +20 -0
  26. package/esm/contracts/preference-provider.contract.d.mts.map +1 -0
  27. package/esm/contracts/queue-dispatcher.contract.d.mts +23 -0
  28. package/esm/contracts/queue-dispatcher.contract.d.mts.map +1 -0
  29. package/esm/contracts/rate-limiter.contract.d.mts +23 -0
  30. package/esm/contracts/rate-limiter.contract.d.mts.map +1 -0
  31. package/esm/dispatch/define-channel.d.mts +37 -0
  32. package/esm/dispatch/define-channel.d.mts.map +1 -0
  33. package/esm/dispatch/define-channel.mjs +39 -0
  34. package/esm/dispatch/define-channel.mjs.map +1 -0
  35. package/esm/dispatch/define-notification.d.mts +22 -0
  36. package/esm/dispatch/define-notification.d.mts.map +1 -0
  37. package/esm/dispatch/define-notification.mjs +125 -0
  38. package/esm/dispatch/define-notification.mjs.map +1 -0
  39. package/esm/dispatch/dispatch-id.mjs +15 -0
  40. package/esm/dispatch/dispatch-id.mjs.map +1 -0
  41. package/esm/dispatch/dispatcher.mjs +120 -0
  42. package/esm/dispatch/dispatcher.mjs.map +1 -0
  43. package/esm/dispatch/index.d.mts +4 -0
  44. package/esm/dispatch/index.mjs +6 -0
  45. package/esm/dispatch/notifications-event-bus.d.mts +18 -0
  46. package/esm/dispatch/notifications-event-bus.d.mts.map +1 -0
  47. package/esm/dispatch/notifications-event-bus.mjs +58 -0
  48. package/esm/dispatch/notifications-event-bus.mjs.map +1 -0
  49. package/esm/dispatch/notify.d.mts +20 -0
  50. package/esm/dispatch/notify.d.mts.map +1 -0
  51. package/esm/dispatch/notify.mjs +80 -0
  52. package/esm/dispatch/notify.mjs.map +1 -0
  53. package/esm/errors.d.mts +32 -0
  54. package/esm/errors.d.mts.map +1 -0
  55. package/esm/errors.mjs +56 -0
  56. package/esm/errors.mjs.map +1 -0
  57. package/esm/in-app/base-notifications-repository.d.mts +82 -0
  58. package/esm/in-app/base-notifications-repository.d.mts.map +1 -0
  59. package/esm/in-app/base-notifications-repository.mjs +187 -0
  60. package/esm/in-app/base-notifications-repository.mjs.map +1 -0
  61. package/esm/in-app/column-map.d.mts +65 -0
  62. package/esm/in-app/column-map.d.mts.map +1 -0
  63. package/esm/in-app/column-map.mjs +28 -0
  64. package/esm/in-app/column-map.mjs.map +1 -0
  65. package/esm/in-app/database-notification.d.mts +30 -0
  66. package/esm/in-app/database-notification.d.mts.map +1 -0
  67. package/esm/in-app/database-notification.mjs +70 -0
  68. package/esm/in-app/database-notification.mjs.map +1 -0
  69. package/esm/in-app/in-app.d.mts +56 -0
  70. package/esm/in-app/in-app.d.mts.map +1 -0
  71. package/esm/in-app/in-app.mjs +67 -0
  72. package/esm/in-app/in-app.mjs.map +1 -0
  73. package/esm/in-app/index.d.mts +4 -0
  74. package/esm/in-app/index.mjs +6 -0
  75. package/esm/index.d.mts +25 -0
  76. package/esm/index.mjs +23 -0
  77. package/esm/migration/index.d.mts +1 -0
  78. package/esm/migration/index.mjs +3 -0
  79. package/esm/migration/notification-columns.d.mts +13 -0
  80. package/esm/migration/notification-columns.d.mts.map +1 -0
  81. package/esm/migration/notification-columns.mjs +53 -0
  82. package/esm/migration/notification-columns.mjs.map +1 -0
  83. package/esm/queue/herald-queue.d.mts +10 -0
  84. package/esm/queue/herald-queue.d.mts.map +1 -0
  85. package/esm/queue/herald-queue.mjs +14 -0
  86. package/esm/queue/herald-queue.mjs.map +1 -0
  87. package/esm/queue/index.d.mts +3 -0
  88. package/esm/queue/index.mjs +5 -0
  89. package/esm/queue/load-herald.d.mts +6 -0
  90. package/esm/queue/load-herald.d.mts.map +1 -0
  91. package/esm/queue/load-herald.mjs +35 -0
  92. package/esm/queue/load-herald.mjs.map +1 -0
  93. package/esm/queue/notifications-worker.d.mts +9 -0
  94. package/esm/queue/notifications-worker.d.mts.map +1 -0
  95. package/esm/queue/notifications-worker.mjs +46 -0
  96. package/esm/queue/notifications-worker.mjs.map +1 -0
  97. package/esm/types.d.mts +130 -0
  98. package/esm/types.d.mts.map +1 -0
  99. package/llms-full.txt +994 -0
  100. package/llms.txt +17 -0
  101. package/package.json +40 -0
  102. package/skills/README.md +23 -0
  103. package/skills/configure-notifications/SKILL.md +138 -0
  104. package/skills/define-channel/SKILL.md +107 -0
  105. package/skills/define-notification/SKILL.md +133 -0
  106. package/skills/notifications-basics/SKILL.md +94 -0
  107. package/skills/observe-notifications/SKILL.md +66 -0
  108. package/skills/queue-notifications/SKILL.md +81 -0
  109. package/skills/send-ad-hoc/SKILL.md +95 -0
  110. package/skills/use-in-app/SKILL.md +168 -0
  111. package/skills/write-notification-migration/SKILL.md +70 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,21 @@
1
+ # Changelog — @warlock.js/notifications
2
+
3
+ All notable changes to `@warlock.js/notifications` are documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). `@warlock.js/*` packages are released in lockstep — every package shares the same version number, so a version below may list only the changes that affected this package.
6
+
7
+ ## [Unreleased]
8
+
9
+ ### Changed
10
+
11
+ - **In-app column mapping moved onto the model as `static columnMap`.** A notification model declares its physical columns once (`recipient` / `tenant` / `readAt` / `isRead`); `DatabaseNotification` accessors, `BaseNotificationsRepository` (read filter **and** write mapping), the `database` channel, and `notificationColumns` all derive from it — replacing the duplicated per-getter + `filterBy` column literals. New exported `NotificationColumnMap` type.
12
+ - **Read-state is presence-based.** Declaring `readAt`, `isRead`, or both selects the representation (timestamp / indexed boolean / both); omitting both defaults to a `read_at` timestamp. The mode-agnostic `unread` filter replaces the `isRead` filter key on `inApp` and the repository.
13
+ - **Multi-tenant support.** When the model declares a `tenant` column, the `database` channel reads the tenant value off the recipient and `createFor(recipientId, input, tenantId?)` writes it — no custom channel needed.
14
+ - `inApp.list` / `inApp.listUnread` now forward full list options (`page` / `limit` / `orderBy` + filters), not just filter keys.
15
+ - `notificationColumns(model)` names the recipient / tenant / read-state columns from `columnMap`; the SQL-vs-MongoDB `dataSource` branch is removed (declare the column names in `columnMap` instead).
16
+
17
+ ## 4.2.0
18
+
19
+ ### Added
20
+
21
+ - Shipped Warlock.js Notifications Package.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Hassan Zohdy
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,57 @@
1
+ # @warlock.js/notifications
2
+
3
+ Multi-channel notifications for Warlock.js — **define once, fire anywhere**.
4
+
5
+ - 📬 **Mail** via `@warlock.js/core`'s `sendMail`.
6
+ - 🗄️ **In-app database** with a recipient-scoped read API (no IDOR by construction).
7
+ - 🔌 **Custom channels** via `defineChannel` (3-line escape hatch).
8
+ - 🎚️ **Pluggable gates** for user preferences + rate limits.
9
+ - 🔐 **`force` + `idempotencyKey`** on every send.
10
+ - 📊 **Observability events** — `sent` / `failed` / `skipped`.
11
+
12
+ > WhatsApp / Telegram / Slack / Push channels arrive with `@warlock.js/bridges` (Phase 2). Until then, roll your own with `defineChannel` + `fetch` — see the example app's `internal-webhook.channel.ts`.
13
+
14
+ ## Quick start
15
+
16
+ ```bash
17
+ # installs the package, ejects a declarative config/notifications.ts,
18
+ # and scaffolds the in-app model + migration into src/app/notifications/*
19
+ npx warlock add notifications
20
+ ```
21
+
22
+ ```ts
23
+ // src/app/orders/notifications/order-shipped.ts
24
+ import { defineNotification } from "@warlock.js/notifications";
25
+
26
+ export const orderShipped = defineNotification<{ order: Order }>({
27
+ via: ["mail", "database"],
28
+ mail: ({ order }, to) => ({
29
+ subject: `Order #${order.number} shipped`,
30
+ html: `<p>Hi ${to.get("name")}, your order is on the way.</p>`,
31
+ }),
32
+ database: ({ order }) => ({
33
+ type: "order.shipped",
34
+ title: "Your order shipped",
35
+ payload: { orderId: order.id },
36
+ }),
37
+ });
38
+
39
+ // anywhere
40
+ await orderShipped.send(user, { order });
41
+ await orderShipped.queue(buyers, { order }, { delay: "10m" });
42
+
43
+ // ad-hoc
44
+ await notify.mail(user, { subject: "Welcome", html: "<p>Hi!</p>" });
45
+
46
+ // in-app reads
47
+ await inApp.listUnread(user);
48
+ await inApp.markAsRead(user); // recipient-scoped — no IDOR
49
+ ```
50
+
51
+ ## Skills
52
+
53
+ The package ships `skills/<task>/SKILL.md` files describing every public surface. Browse the index at [`skills/README.md`](./skills/README.md) or load them via `agent-kit`.
54
+
55
+ ## License
56
+
57
+ MIT