@gravito/flare 2.0.0 → 3.0.1

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/dist/index.cjs CHANGED
@@ -369,7 +369,7 @@ var OrbitFlare = class _OrbitFlare {
369
369
  async install(core) {
370
370
  const manager = new NotificationManager(core);
371
371
  if (this.options.enableMail) {
372
- const mail = core.services.get("mail");
372
+ const mail = core.container.make("mail");
373
373
  if (mail) {
374
374
  manager.channel("mail", new MailChannel(mail));
375
375
  } else {
@@ -377,7 +377,7 @@ var OrbitFlare = class _OrbitFlare {
377
377
  }
378
378
  }
379
379
  if (this.options.enableDatabase) {
380
- const db = core.services.get("db");
380
+ const db = core.container.make("db");
381
381
  if (db) {
382
382
  manager.channel("database", new DatabaseChannel(db));
383
383
  } else {
@@ -385,7 +385,7 @@ var OrbitFlare = class _OrbitFlare {
385
385
  }
386
386
  }
387
387
  if (this.options.enableBroadcast) {
388
- const broadcast = core.services.get("broadcast");
388
+ const broadcast = core.container.make("broadcast");
389
389
  if (broadcast) {
390
390
  manager.channel("broadcast", new BroadcastChannel(broadcast));
391
391
  } else {
@@ -408,8 +408,8 @@ var OrbitFlare = class _OrbitFlare {
408
408
  core.logger.warn("[OrbitFlare] SMS configuration not found, sms channel disabled");
409
409
  }
410
410
  }
411
- core.services.set("notifications", manager);
412
- const queue = core.services.get("queue");
411
+ core.container.instance("notifications", manager);
412
+ const queue = core.container.make("queue");
413
413
  if (queue) {
414
414
  manager.setQueueManager({
415
415
  push: async (job, queueName, connection, delay) => {
package/dist/index.d.cts CHANGED
@@ -6,69 +6,95 @@ import { PlanetCore, GravitoOrbit } from '@gravito/core';
6
6
 
7
7
  /**
8
8
  * Notification channel interface.
9
+ * @public
9
10
  */
10
11
  interface NotificationChannel {
11
12
  /**
12
- * Send a notification.
13
- * @param notification - Notification instance
14
- * @param notifiable - Recipient
13
+ * Send a notification through the specified channel.
14
+ *
15
+ * @param notification - The notification instance containing data.
16
+ * @param notifiable - The recipient of the notification.
15
17
  */
16
18
  send(notification: Notification, notifiable: Notifiable): Promise<void>;
17
19
  }
18
20
  /**
19
- * Notifiable (notification recipient) interface.
21
+ * Interface for recipients that can receive notifications.
22
+ * @public
20
23
  */
21
24
  interface Notifiable {
22
25
  /**
23
- * Recipient identifier (usually an ID).
26
+ * Unique identifier for the recipient (e.g., User ID).
24
27
  */
25
28
  getNotifiableId(): string | number;
26
29
  /**
27
- * Recipient type (optional, for polymorphic relations).
30
+ * Optional recipient type (useful for polymorphic notifications).
28
31
  */
29
32
  getNotifiableType?(): string;
30
33
  /**
31
- * Preferred channels (optional).
34
+ * Optional list of preferred channels for this specific recipient.
32
35
  */
33
36
  preferredNotificationChannels?(): string[];
34
37
  }
35
38
  /**
36
- * Mail message payload.
39
+ * Payload for email notifications.
40
+ * @public
37
41
  */
38
42
  interface MailMessage {
43
+ /** Email subject line */
39
44
  subject: string;
45
+ /** View template path */
40
46
  view?: string;
47
+ /** Data to pass to the view template */
41
48
  data?: Record<string, unknown>;
49
+ /** Inline HTML content */
42
50
  html?: string;
51
+ /** Plain text content */
43
52
  text?: string;
53
+ /** Sender address */
44
54
  from?: string;
55
+ /** Target recipient(s) */
45
56
  to?: string | string[];
57
+ /** Carbon copy recipient(s) */
46
58
  cc?: string | string[];
59
+ /** Blind carbon copy recipient(s) */
47
60
  bcc?: string | string[];
48
61
  }
49
62
  /**
50
- * Database notification payload.
63
+ * Payload for database-stored notifications.
64
+ * @public
51
65
  */
52
66
  interface DatabaseNotification {
67
+ /** Type identifier for the notification */
53
68
  type: string;
69
+ /** JSON-serializable data payload */
54
70
  data: Record<string, unknown>;
71
+ /** Timestamp when the notification was marked as read */
55
72
  readAt?: Date | null;
56
73
  }
57
74
  /**
58
- * Broadcast notification payload.
75
+ * Payload for real-time broadcast notifications.
76
+ * @public
59
77
  */
60
78
  interface BroadcastNotification {
79
+ /** Event/Type identifier for the broadcast */
61
80
  type: string;
81
+ /** Data to be broadcasted to subscribers */
62
82
  data: Record<string, unknown>;
63
83
  }
64
84
  /**
65
- * Slack message payload.
85
+ * Payload for Slack channel notifications.
86
+ * @public
66
87
  */
67
88
  interface SlackMessage {
89
+ /** Main message text */
68
90
  text: string;
91
+ /** Target Slack channel */
69
92
  channel?: string;
93
+ /** Custom bot username */
70
94
  username?: string;
95
+ /** Icon emoji for the bot */
71
96
  iconEmoji?: string;
97
+ /** Array of Slack attachments for rich formatting */
72
98
  attachments?: Array<{
73
99
  color?: string;
74
100
  title?: string;
@@ -81,56 +107,42 @@ interface SlackMessage {
81
107
  }>;
82
108
  }
83
109
  /**
84
- * SMS message payload.
110
+ * Payload for SMS notifications.
111
+ * @public
85
112
  */
86
113
  interface SmsMessage {
114
+ /** Recipient phone number */
87
115
  to: string;
116
+ /** Message content */
88
117
  message: string;
118
+ /** Sender ID or phone number */
89
119
  from?: string;
90
120
  }
91
121
 
92
122
  /**
93
123
  * Marker interface for notifications that should be queued.
124
+ *
125
+ * Implementing this interface will cause the notification to be dispatched
126
+ * to a background queue automatically by the `NotificationManager`.
127
+ *
128
+ * @public
129
+ * @since 3.0.0
94
130
  */
95
131
  interface ShouldQueue {
96
- /**
97
- * Queue name (optional).
98
- */
132
+ /** The name of the queue to push this notification to. */
99
133
  queue?: string | undefined;
134
+ /** The connection name (e.g., 'redis', 'database') to use for queuing. */
100
135
  connection?: string | undefined;
136
+ /** Delay in seconds before the notification is delivered. */
101
137
  delay?: number | undefined;
102
138
  }
103
139
  /**
104
140
  * Base Notification class.
105
141
  *
106
- * All notifications should extend this class.
107
- * Notifications can be delivered via multiple channels (mail, database, broadcast, Slack, SMS, etc.).
142
+ * All application notifications should extend this class.
108
143
  *
109
- * @example
110
- * ```typescript
111
- * class InvoicePaid extends Notification {
112
- * constructor(private invoice: Invoice) {
113
- * super()
114
- * }
115
- *
116
- * via(user: User): string[] {
117
- * return ['mail', 'database']
118
- * }
119
- *
120
- * toMail(user: User): MailMessage {
121
- * return new MailMessage()
122
- * .subject('Invoice Paid')
123
- * .view('emails.invoice-paid', { invoice: this.invoice })
124
- * }
125
- *
126
- * toDatabase(user: User): DatabaseNotification {
127
- * return {
128
- * type: 'invoice-paid',
129
- * data: { invoice_id: this.invoice.id }
130
- * }
131
- * }
132
- * }
133
- * ```
144
+ * @public
145
+ * @since 3.0.0
134
146
  */
135
147
  declare abstract class Notification {
136
148
  /**
@@ -331,36 +343,41 @@ declare class NotificationManager {
331
343
  /**
332
344
  * OrbitFlare options.
333
345
  */
346
+ /**
347
+ * Options for configuring OrbitFlare.
348
+ * @public
349
+ */
334
350
  interface OrbitFlareOptions {
335
- /**
336
- * Enable mail channel.
337
- */
351
+ /** Enable or disable the email notification channel. */
338
352
  enableMail?: boolean;
339
- /**
340
- * Enable database channel.
341
- */
353
+ /** Enable or disable the database storage notification channel. */
342
354
  enableDatabase?: boolean;
343
- /**
344
- * Enable broadcast channel.
345
- */
355
+ /** Enable or disable the real-time broadcast notification channel. */
346
356
  enableBroadcast?: boolean;
347
- /**
348
- * Enable Slack channel.
349
- */
357
+ /** Enable or disable the Slack notification channel. */
350
358
  enableSlack?: boolean;
351
- /**
352
- * Enable SMS channel.
353
- */
359
+ /** Enable or disable the SMS notification channel. */
354
360
  enableSms?: boolean;
355
- /**
356
- * Custom channel configuration.
357
- */
361
+ /** Custom channel configuration records for flexible extension. */
358
362
  channels?: Record<string, unknown>;
359
363
  }
360
364
  /**
361
- * Notifications Orbit
365
+ * OrbitFlare is the official notification orbit for Gravito.
366
+ * It provides a unified API for sending notifications across multiple channels
367
+ * (Mail, Database, Broadcast, Slack, SMS) and supports background queuing.
368
+ *
369
+ * @example
370
+ * ```typescript
371
+ * const flare = new OrbitFlare({
372
+ * enableSlack: true,
373
+ * channels: { slack: { webhookUrl: '...' } }
374
+ * });
375
+ * core.addOrbit(flare);
362
376
  *
363
- * Provides notifications with multiple channels (mail, database, broadcast, Slack, SMS).
377
+ * // Usage in controller
378
+ * await ctx.get('notifications').send(user, new WelcomeNotification());
379
+ * ```
380
+ * @public
364
381
  */
365
382
  declare class OrbitFlare implements GravitoOrbit {
366
383
  private options;
@@ -379,5 +396,11 @@ declare class OrbitFlare implements GravitoOrbit {
379
396
  */
380
397
  install(core: PlanetCore): Promise<void>;
381
398
  }
399
+ declare module '@gravito/core' {
400
+ interface GravitoVariables {
401
+ /** Notification manager for multi-channel notifications */
402
+ notifications?: NotificationManager;
403
+ }
404
+ }
382
405
 
383
406
  export { BroadcastChannel, type BroadcastNotification, DatabaseChannel, type DatabaseNotification, MailChannel, type MailMessage, type Notifiable, Notification, type NotificationChannel, NotificationManager, OrbitFlare, type OrbitFlareOptions, type ShouldQueue, SlackChannel, type SlackChannelConfig, type SlackMessage, SmsChannel, type SmsChannelConfig, type SmsMessage };
package/dist/index.d.ts CHANGED
@@ -6,69 +6,95 @@ import { PlanetCore, GravitoOrbit } from '@gravito/core';
6
6
 
7
7
  /**
8
8
  * Notification channel interface.
9
+ * @public
9
10
  */
10
11
  interface NotificationChannel {
11
12
  /**
12
- * Send a notification.
13
- * @param notification - Notification instance
14
- * @param notifiable - Recipient
13
+ * Send a notification through the specified channel.
14
+ *
15
+ * @param notification - The notification instance containing data.
16
+ * @param notifiable - The recipient of the notification.
15
17
  */
16
18
  send(notification: Notification, notifiable: Notifiable): Promise<void>;
17
19
  }
18
20
  /**
19
- * Notifiable (notification recipient) interface.
21
+ * Interface for recipients that can receive notifications.
22
+ * @public
20
23
  */
21
24
  interface Notifiable {
22
25
  /**
23
- * Recipient identifier (usually an ID).
26
+ * Unique identifier for the recipient (e.g., User ID).
24
27
  */
25
28
  getNotifiableId(): string | number;
26
29
  /**
27
- * Recipient type (optional, for polymorphic relations).
30
+ * Optional recipient type (useful for polymorphic notifications).
28
31
  */
29
32
  getNotifiableType?(): string;
30
33
  /**
31
- * Preferred channels (optional).
34
+ * Optional list of preferred channels for this specific recipient.
32
35
  */
33
36
  preferredNotificationChannels?(): string[];
34
37
  }
35
38
  /**
36
- * Mail message payload.
39
+ * Payload for email notifications.
40
+ * @public
37
41
  */
38
42
  interface MailMessage {
43
+ /** Email subject line */
39
44
  subject: string;
45
+ /** View template path */
40
46
  view?: string;
47
+ /** Data to pass to the view template */
41
48
  data?: Record<string, unknown>;
49
+ /** Inline HTML content */
42
50
  html?: string;
51
+ /** Plain text content */
43
52
  text?: string;
53
+ /** Sender address */
44
54
  from?: string;
55
+ /** Target recipient(s) */
45
56
  to?: string | string[];
57
+ /** Carbon copy recipient(s) */
46
58
  cc?: string | string[];
59
+ /** Blind carbon copy recipient(s) */
47
60
  bcc?: string | string[];
48
61
  }
49
62
  /**
50
- * Database notification payload.
63
+ * Payload for database-stored notifications.
64
+ * @public
51
65
  */
52
66
  interface DatabaseNotification {
67
+ /** Type identifier for the notification */
53
68
  type: string;
69
+ /** JSON-serializable data payload */
54
70
  data: Record<string, unknown>;
71
+ /** Timestamp when the notification was marked as read */
55
72
  readAt?: Date | null;
56
73
  }
57
74
  /**
58
- * Broadcast notification payload.
75
+ * Payload for real-time broadcast notifications.
76
+ * @public
59
77
  */
60
78
  interface BroadcastNotification {
79
+ /** Event/Type identifier for the broadcast */
61
80
  type: string;
81
+ /** Data to be broadcasted to subscribers */
62
82
  data: Record<string, unknown>;
63
83
  }
64
84
  /**
65
- * Slack message payload.
85
+ * Payload for Slack channel notifications.
86
+ * @public
66
87
  */
67
88
  interface SlackMessage {
89
+ /** Main message text */
68
90
  text: string;
91
+ /** Target Slack channel */
69
92
  channel?: string;
93
+ /** Custom bot username */
70
94
  username?: string;
95
+ /** Icon emoji for the bot */
71
96
  iconEmoji?: string;
97
+ /** Array of Slack attachments for rich formatting */
72
98
  attachments?: Array<{
73
99
  color?: string;
74
100
  title?: string;
@@ -81,56 +107,42 @@ interface SlackMessage {
81
107
  }>;
82
108
  }
83
109
  /**
84
- * SMS message payload.
110
+ * Payload for SMS notifications.
111
+ * @public
85
112
  */
86
113
  interface SmsMessage {
114
+ /** Recipient phone number */
87
115
  to: string;
116
+ /** Message content */
88
117
  message: string;
118
+ /** Sender ID or phone number */
89
119
  from?: string;
90
120
  }
91
121
 
92
122
  /**
93
123
  * Marker interface for notifications that should be queued.
124
+ *
125
+ * Implementing this interface will cause the notification to be dispatched
126
+ * to a background queue automatically by the `NotificationManager`.
127
+ *
128
+ * @public
129
+ * @since 3.0.0
94
130
  */
95
131
  interface ShouldQueue {
96
- /**
97
- * Queue name (optional).
98
- */
132
+ /** The name of the queue to push this notification to. */
99
133
  queue?: string | undefined;
134
+ /** The connection name (e.g., 'redis', 'database') to use for queuing. */
100
135
  connection?: string | undefined;
136
+ /** Delay in seconds before the notification is delivered. */
101
137
  delay?: number | undefined;
102
138
  }
103
139
  /**
104
140
  * Base Notification class.
105
141
  *
106
- * All notifications should extend this class.
107
- * Notifications can be delivered via multiple channels (mail, database, broadcast, Slack, SMS, etc.).
142
+ * All application notifications should extend this class.
108
143
  *
109
- * @example
110
- * ```typescript
111
- * class InvoicePaid extends Notification {
112
- * constructor(private invoice: Invoice) {
113
- * super()
114
- * }
115
- *
116
- * via(user: User): string[] {
117
- * return ['mail', 'database']
118
- * }
119
- *
120
- * toMail(user: User): MailMessage {
121
- * return new MailMessage()
122
- * .subject('Invoice Paid')
123
- * .view('emails.invoice-paid', { invoice: this.invoice })
124
- * }
125
- *
126
- * toDatabase(user: User): DatabaseNotification {
127
- * return {
128
- * type: 'invoice-paid',
129
- * data: { invoice_id: this.invoice.id }
130
- * }
131
- * }
132
- * }
133
- * ```
144
+ * @public
145
+ * @since 3.0.0
134
146
  */
135
147
  declare abstract class Notification {
136
148
  /**
@@ -331,36 +343,41 @@ declare class NotificationManager {
331
343
  /**
332
344
  * OrbitFlare options.
333
345
  */
346
+ /**
347
+ * Options for configuring OrbitFlare.
348
+ * @public
349
+ */
334
350
  interface OrbitFlareOptions {
335
- /**
336
- * Enable mail channel.
337
- */
351
+ /** Enable or disable the email notification channel. */
338
352
  enableMail?: boolean;
339
- /**
340
- * Enable database channel.
341
- */
353
+ /** Enable or disable the database storage notification channel. */
342
354
  enableDatabase?: boolean;
343
- /**
344
- * Enable broadcast channel.
345
- */
355
+ /** Enable or disable the real-time broadcast notification channel. */
346
356
  enableBroadcast?: boolean;
347
- /**
348
- * Enable Slack channel.
349
- */
357
+ /** Enable or disable the Slack notification channel. */
350
358
  enableSlack?: boolean;
351
- /**
352
- * Enable SMS channel.
353
- */
359
+ /** Enable or disable the SMS notification channel. */
354
360
  enableSms?: boolean;
355
- /**
356
- * Custom channel configuration.
357
- */
361
+ /** Custom channel configuration records for flexible extension. */
358
362
  channels?: Record<string, unknown>;
359
363
  }
360
364
  /**
361
- * Notifications Orbit
365
+ * OrbitFlare is the official notification orbit for Gravito.
366
+ * It provides a unified API for sending notifications across multiple channels
367
+ * (Mail, Database, Broadcast, Slack, SMS) and supports background queuing.
368
+ *
369
+ * @example
370
+ * ```typescript
371
+ * const flare = new OrbitFlare({
372
+ * enableSlack: true,
373
+ * channels: { slack: { webhookUrl: '...' } }
374
+ * });
375
+ * core.addOrbit(flare);
362
376
  *
363
- * Provides notifications with multiple channels (mail, database, broadcast, Slack, SMS).
377
+ * // Usage in controller
378
+ * await ctx.get('notifications').send(user, new WelcomeNotification());
379
+ * ```
380
+ * @public
364
381
  */
365
382
  declare class OrbitFlare implements GravitoOrbit {
366
383
  private options;
@@ -379,5 +396,11 @@ declare class OrbitFlare implements GravitoOrbit {
379
396
  */
380
397
  install(core: PlanetCore): Promise<void>;
381
398
  }
399
+ declare module '@gravito/core' {
400
+ interface GravitoVariables {
401
+ /** Notification manager for multi-channel notifications */
402
+ notifications?: NotificationManager;
403
+ }
404
+ }
382
405
 
383
406
  export { BroadcastChannel, type BroadcastNotification, DatabaseChannel, type DatabaseNotification, MailChannel, type MailMessage, type Notifiable, Notification, type NotificationChannel, NotificationManager, OrbitFlare, type OrbitFlareOptions, type ShouldQueue, SlackChannel, type SlackChannelConfig, type SlackMessage, SmsChannel, type SmsChannelConfig, type SmsMessage };
package/dist/index.js CHANGED
@@ -336,7 +336,7 @@ var OrbitFlare = class _OrbitFlare {
336
336
  async install(core) {
337
337
  const manager = new NotificationManager(core);
338
338
  if (this.options.enableMail) {
339
- const mail = core.services.get("mail");
339
+ const mail = core.container.make("mail");
340
340
  if (mail) {
341
341
  manager.channel("mail", new MailChannel(mail));
342
342
  } else {
@@ -344,7 +344,7 @@ var OrbitFlare = class _OrbitFlare {
344
344
  }
345
345
  }
346
346
  if (this.options.enableDatabase) {
347
- const db = core.services.get("db");
347
+ const db = core.container.make("db");
348
348
  if (db) {
349
349
  manager.channel("database", new DatabaseChannel(db));
350
350
  } else {
@@ -352,7 +352,7 @@ var OrbitFlare = class _OrbitFlare {
352
352
  }
353
353
  }
354
354
  if (this.options.enableBroadcast) {
355
- const broadcast = core.services.get("broadcast");
355
+ const broadcast = core.container.make("broadcast");
356
356
  if (broadcast) {
357
357
  manager.channel("broadcast", new BroadcastChannel(broadcast));
358
358
  } else {
@@ -375,8 +375,8 @@ var OrbitFlare = class _OrbitFlare {
375
375
  core.logger.warn("[OrbitFlare] SMS configuration not found, sms channel disabled");
376
376
  }
377
377
  }
378
- core.services.set("notifications", manager);
379
- const queue = core.services.get("queue");
378
+ core.container.instance("notifications", manager);
379
+ const queue = core.container.make("queue");
380
380
  if (queue) {
381
381
  manager.setQueueManager({
382
382
  push: async (job, queueName, connection, delay) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravito/flare",
3
- "version": "2.0.0",
3
+ "version": "3.0.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },