@gravito/flare 1.0.0-alpha.2 → 1.0.0-alpha.6
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/README.md +38 -40
- package/README.zh-TW.md +35 -0
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
# @gravito/flare
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> Lightweight, high-performance notifications for Gravito with multi-channel delivery (mail, database, broadcast, Slack, SMS).
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
**Status**: v0.1.0 - core features complete with multiple channel support.
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## Features
|
|
8
8
|
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
- **AI
|
|
9
|
+
- **Zero runtime overhead**: Pure type wrappers that delegate to channel drivers
|
|
10
|
+
- **Multi-channel delivery**: Mail, database, broadcast, Slack, SMS
|
|
11
|
+
- **Modular by design**: Install only the channels you need
|
|
12
|
+
- **Queue support**: Works with `@gravito/stream` for async delivery
|
|
13
|
+
- **AI-friendly**: Strong typing, clear JSDoc, and predictable APIs
|
|
14
14
|
|
|
15
|
-
##
|
|
15
|
+
## Installation
|
|
16
16
|
|
|
17
17
|
```bash
|
|
18
18
|
bun add @gravito/flare
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
##
|
|
21
|
+
## Quick Start
|
|
22
22
|
|
|
23
|
-
### 1.
|
|
23
|
+
### 1. Create a notification
|
|
24
24
|
|
|
25
25
|
```typescript
|
|
26
26
|
import { Notification } from '@gravito/flare'
|
|
@@ -56,7 +56,7 @@ class InvoicePaid extends Notification {
|
|
|
56
56
|
}
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
-
### 2.
|
|
59
|
+
### 2. Configure OrbitFlare
|
|
60
60
|
|
|
61
61
|
```typescript
|
|
62
62
|
import { PlanetCore } from 'gravito-core'
|
|
@@ -82,23 +82,23 @@ const core = await PlanetCore.boot({
|
|
|
82
82
|
})
|
|
83
83
|
```
|
|
84
84
|
|
|
85
|
-
### 3.
|
|
85
|
+
### 3. Send a notification
|
|
86
86
|
|
|
87
87
|
```typescript
|
|
88
|
-
//
|
|
88
|
+
// In a controller
|
|
89
89
|
const notifications = c.get('notifications') as NotificationManager
|
|
90
90
|
|
|
91
91
|
await notifications.send(user, new InvoicePaid(invoice))
|
|
92
92
|
```
|
|
93
93
|
|
|
94
|
-
|
|
94
|
+
## Queueing Notifications
|
|
95
95
|
|
|
96
96
|
```typescript
|
|
97
97
|
import { Notification, ShouldQueue } from '@gravito/flare'
|
|
98
98
|
|
|
99
99
|
class SendEmailNotification extends Notification implements ShouldQueue {
|
|
100
100
|
queue = 'notifications'
|
|
101
|
-
delay = 60 //
|
|
101
|
+
delay = 60 // delay by 60 seconds
|
|
102
102
|
|
|
103
103
|
via(user: Notifiable): string[] {
|
|
104
104
|
return ['mail']
|
|
@@ -113,15 +113,14 @@ class SendEmailNotification extends Notification implements ShouldQueue {
|
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
// 自動推送到隊列
|
|
117
116
|
await notifications.send(user, new SendEmailNotification())
|
|
118
117
|
```
|
|
119
118
|
|
|
120
|
-
##
|
|
119
|
+
## Channels
|
|
121
120
|
|
|
122
|
-
###
|
|
121
|
+
### Mail
|
|
123
122
|
|
|
124
|
-
|
|
123
|
+
Requires `@gravito/signal`:
|
|
125
124
|
|
|
126
125
|
```typescript
|
|
127
126
|
via(user: Notifiable): string[] {
|
|
@@ -138,9 +137,9 @@ toMail(user: Notifiable): MailMessage {
|
|
|
138
137
|
}
|
|
139
138
|
```
|
|
140
139
|
|
|
141
|
-
###
|
|
140
|
+
### Database
|
|
142
141
|
|
|
143
|
-
|
|
142
|
+
Requires database support:
|
|
144
143
|
|
|
145
144
|
```typescript
|
|
146
145
|
via(user: Notifiable): string[] {
|
|
@@ -155,9 +154,9 @@ toDatabase(user: Notifiable): DatabaseNotification {
|
|
|
155
154
|
}
|
|
156
155
|
```
|
|
157
156
|
|
|
158
|
-
###
|
|
157
|
+
### Broadcast
|
|
159
158
|
|
|
160
|
-
|
|
159
|
+
Requires `@gravito/radiance`:
|
|
161
160
|
|
|
162
161
|
```typescript
|
|
163
162
|
via(user: Notifiable): string[] {
|
|
@@ -172,7 +171,7 @@ toBroadcast(user: Notifiable): BroadcastNotification {
|
|
|
172
171
|
}
|
|
173
172
|
```
|
|
174
173
|
|
|
175
|
-
### Slack
|
|
174
|
+
### Slack
|
|
176
175
|
|
|
177
176
|
```typescript
|
|
178
177
|
via(user: Notifiable): string[] {
|
|
@@ -187,7 +186,7 @@ toSlack(user: Notifiable): SlackMessage {
|
|
|
187
186
|
}
|
|
188
187
|
```
|
|
189
188
|
|
|
190
|
-
### SMS
|
|
189
|
+
### SMS
|
|
191
190
|
|
|
192
191
|
```typescript
|
|
193
192
|
via(user: Notifiable): string[] {
|
|
@@ -202,29 +201,28 @@ toSms(user: Notifiable): SmsMessage {
|
|
|
202
201
|
}
|
|
203
202
|
```
|
|
204
203
|
|
|
205
|
-
## API
|
|
204
|
+
## API Reference
|
|
206
205
|
|
|
207
206
|
### Notification
|
|
208
207
|
|
|
209
|
-
|
|
208
|
+
Every notification should extend `Notification`.
|
|
210
209
|
|
|
211
|
-
####
|
|
210
|
+
#### Methods
|
|
212
211
|
|
|
213
|
-
- `via(notifiable: Notifiable): string[]` -
|
|
214
|
-
- `toMail(notifiable: Notifiable): MailMessage` -
|
|
215
|
-
- `toDatabase(notifiable: Notifiable): DatabaseNotification` -
|
|
216
|
-
- `toBroadcast(notifiable: Notifiable): BroadcastNotification` -
|
|
217
|
-
- `toSlack(notifiable: Notifiable): SlackMessage` - Slack
|
|
218
|
-
- `toSms(notifiable: Notifiable): SmsMessage` - SMS
|
|
212
|
+
- `via(notifiable: Notifiable): string[]` - Choose delivery channels (required)
|
|
213
|
+
- `toMail(notifiable: Notifiable): MailMessage` - Mail payload (optional)
|
|
214
|
+
- `toDatabase(notifiable: Notifiable): DatabaseNotification` - Database payload (optional)
|
|
215
|
+
- `toBroadcast(notifiable: Notifiable): BroadcastNotification` - Broadcast payload (optional)
|
|
216
|
+
- `toSlack(notifiable: Notifiable): SlackMessage` - Slack payload (optional)
|
|
217
|
+
- `toSms(notifiable: Notifiable): SmsMessage` - SMS payload (optional)
|
|
219
218
|
|
|
220
219
|
### NotificationManager
|
|
221
220
|
|
|
222
|
-
####
|
|
221
|
+
#### Methods
|
|
223
222
|
|
|
224
|
-
- `send(notifiable: Notifiable, notification: Notification): Promise<void>` -
|
|
225
|
-
- `channel(name: string, channel: NotificationChannel): void` -
|
|
223
|
+
- `send(notifiable: Notifiable, notification: Notification): Promise<void>` - Send notification
|
|
224
|
+
- `channel(name: string, channel: NotificationChannel): void` - Register a custom channel
|
|
226
225
|
|
|
227
|
-
##
|
|
226
|
+
## License
|
|
228
227
|
|
|
229
228
|
MIT © Carl Lee
|
|
230
|
-
|
package/README.zh-TW.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# @gravito/flare
|
|
2
|
+
|
|
3
|
+
> Gravito 的通知模組,支援郵件、資料庫、廣播、Slack、SMS 等多種通道。
|
|
4
|
+
|
|
5
|
+
## 安裝
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add @gravito/flare
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 快速開始
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { Notification } from '@gravito/flare'
|
|
15
|
+
import type { MailMessage, Notifiable } from '@gravito/flare'
|
|
16
|
+
|
|
17
|
+
class WelcomeUser extends Notification {
|
|
18
|
+
via(user: Notifiable): string[] {
|
|
19
|
+
return ['mail']
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
toMail(user: Notifiable): MailMessage {
|
|
23
|
+
return {
|
|
24
|
+
subject: 'Welcome!',
|
|
25
|
+
view: 'emails.welcome',
|
|
26
|
+
to: user.email,
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
const notifications = c.get('notifications')
|
|
34
|
+
await notifications.send(user, new WelcomeUser())
|
|
35
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravito/flare",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.6",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -38,12 +38,12 @@
|
|
|
38
38
|
"author": "Carl Lee <carllee0520@gmail.com>",
|
|
39
39
|
"license": "MIT",
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"gravito-core": "1.0.0-beta.
|
|
41
|
+
"gravito-core": "1.0.0-beta.5"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
|
-
"@gravito/stream": "1.0.0-alpha.
|
|
45
|
-
"@gravito/signal": "1.0.0-alpha.
|
|
46
|
-
"@gravito/radiance": "1.0.0-alpha.
|
|
44
|
+
"@gravito/stream": "1.0.0-alpha.6",
|
|
45
|
+
"@gravito/signal": "1.0.0-alpha.6",
|
|
46
|
+
"@gravito/radiance": "1.0.0-alpha.6"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"bun-types": "latest",
|