@cslug/notification 0.11.0 → 0.12.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cslug/notification",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "Notifications over mail, database, WhatsApp and SMS channels.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -29,10 +29,10 @@
29
29
  "bun": ">=1.3.14"
30
30
  },
31
31
  "peerDependencies": {
32
- "@cslug/core": "0.11.0",
33
- "@cslug/mail": "0.11.0",
34
- "@cslug/queue": "0.11.0",
35
- "@cslug/database": "0.11.0"
32
+ "@cslug/core": "0.12.0",
33
+ "@cslug/mail": "0.12.0",
34
+ "@cslug/queue": "0.12.0",
35
+ "@cslug/database": "0.12.0"
36
36
  },
37
37
  "peerDependenciesMeta": {
38
38
  "@cslug/mail": {
@@ -0,0 +1,12 @@
1
+ import { join } from 'node:path'
2
+ import { defineGenerator } from '@cslug/core'
3
+
4
+ const STUBS = join(import.meta.dir, '../stubs')
5
+
6
+ /** `cslug make:notification CheckinDue` → `app/notifications/checkin-due-notification.ts`. */
7
+ export const MakeNotificationCommand = defineGenerator({
8
+ kind: 'notification',
9
+ description: 'Create a notification',
10
+ stubs: STUBS,
11
+ files: (n) => [{ stub: 'notification.stub', target: `app/notifications/${n.file}.ts` }],
12
+ })
package/src/index.ts CHANGED
@@ -3,6 +3,7 @@
3
3
  * delivery, delivery records, and a fake for tests.
4
4
  */
5
5
  export { installNotificationFake, NotificationFake, type SentNotification } from './fake'
6
+ export { MakeNotificationCommand } from './generators'
6
7
  export { Notification, type Recipient, recipient, routeOf } from './notification'
7
8
  export {
8
9
  type Channel,
package/src/provider.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { join } from 'node:path'
2
2
  import { type Application, Logger, resolve, ServiceProvider } from '@cslug/core'
3
+ import { MakeNotificationCommand } from './generators'
3
4
  import {
4
5
  type Delivery,
5
6
  LogChannel,
@@ -59,6 +60,7 @@ async function databaseStore(app: Application): Promise<NotificationStore | unde
59
60
  */
60
61
  export class NotificationProvider extends ServiceProvider {
61
62
  register() {
63
+ this.commands([MakeNotificationCommand])
62
64
  this.app.singleton(Notifier, (c) => {
63
65
  const config = this.app.config<NotificationConfig | undefined>('notification') ?? {}
64
66
  const log = c.resolve(Logger)
@@ -0,0 +1,18 @@
1
+ import { Notification, type Recipient } from '@cslug/notification'
2
+
3
+ export class {{ class }} extends Notification {
4
+ constructor(private subjectId: string) {
5
+ super()
6
+ }
7
+
8
+ /** The channels for this recipient. */
9
+ via(to: Recipient) {
10
+ return to.email ? ['mail', 'database'] : ['database']
11
+ }
12
+
13
+ // toMail() { return new SomethingMail(…) }
14
+
15
+ toDatabase() {
16
+ return { subjectId: this.subjectId }
17
+ }
18
+ }