@develit-services/notification 0.5.0 → 0.5.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/README.md +182 -0
- package/dist/export/worker.cjs +11 -5
- package/dist/export/worker.d.cts +1 -1
- package/dist/export/worker.d.mts +1 -1
- package/dist/export/worker.d.ts +1 -1
- package/dist/export/worker.mjs +11 -5
- package/dist/shared/{notification.Dk_5TX9v.cjs → notification.B0pktSz9.cjs} +31 -12
- package/dist/shared/{notification.2rSOcFrr.d.cts → notification.B4ZLWDCP.d.cts} +1 -2
- package/dist/shared/{notification.CM_WoR0y.mjs → notification.CmITLO7E.mjs} +31 -12
- package/dist/shared/{notification.C1quYqlT.d.mts → notification.CpFoKjoN.d.mts} +1 -2
- package/dist/shared/{notification.oEdhCsu_.d.ts → notification.DWuoMDHY.d.ts} +1 -2
- package/dist/types.cjs +1 -1
- package/dist/types.d.cts +3 -4
- package/dist/types.d.mts +3 -4
- package/dist/types.d.ts +3 -4
- package/dist/types.mjs +1 -1
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
# Notification Service
|
|
2
|
+
|
|
3
|
+
Microsluzba pro odesilani notifikaci (email, SMS, Slack, push). Postavena na Cloudflare Workers s D1 databazi.
|
|
4
|
+
|
|
5
|
+
## Obsah
|
|
6
|
+
|
|
7
|
+
- [Architektura](#architektura)
|
|
8
|
+
- [Kanaly notifikaci](#kanaly-notifikaci)
|
|
9
|
+
- [Queue processing](#queue-processing)
|
|
10
|
+
- [Konektory](#konektory)
|
|
11
|
+
- [RPC akce](#rpc-akce)
|
|
12
|
+
- [Audit logging](#audit-logging)
|
|
13
|
+
- [Databazove schema](#databazove-schema)
|
|
14
|
+
- [Error Codes](#error-codes)
|
|
15
|
+
|
|
16
|
+
## Architektura
|
|
17
|
+
|
|
18
|
+
Sluzba se sklada z:
|
|
19
|
+
|
|
20
|
+
- **Akce (Actions)** - RPC endpointy pro odesilani notifikaci
|
|
21
|
+
- **Queue handler** - Asynchronni zpracovani notifikaci z fronty
|
|
22
|
+
- **Konektory** - Abstrakce nad API externich sluzeb (Ecomail, Twilio, Slack)
|
|
23
|
+
- **Audit log** - Zaznamenani vsech odeslanych notifikaci do D1
|
|
24
|
+
|
|
25
|
+
Bindings:
|
|
26
|
+
- `NOTIFICATION_D1` - Cloudflare D1 databaze
|
|
27
|
+
- `NOTIFICATIONS_QUEUE` - Fronta pro asynchronni zpracovani
|
|
28
|
+
- `SECRETS_STORE` - Service binding na secrets store
|
|
29
|
+
- `SLACK_WEBHOOK` - Webhook URL pro Slack notifikace
|
|
30
|
+
|
|
31
|
+
## Kanaly notifikaci
|
|
32
|
+
|
|
33
|
+
| Kanal | Konektor | Stav |
|
|
34
|
+
|-------|----------|------|
|
|
35
|
+
| Email | Ecomail | Aktivni |
|
|
36
|
+
| SMS | Twilio | Aktivni |
|
|
37
|
+
| Slack | Slack Webhook | Aktivni |
|
|
38
|
+
| Push | - | Neimplementovano |
|
|
39
|
+
|
|
40
|
+
## Queue processing
|
|
41
|
+
|
|
42
|
+
Notifikace lze odesilat synchronne (primo) nebo asynchronne (pres frontu).
|
|
43
|
+
|
|
44
|
+
### Async flow (vychozi)
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
public-send-email / public-send-sms
|
|
48
|
+
│
|
|
49
|
+
▼
|
|
50
|
+
NOTIFICATIONS_QUEUE
|
|
51
|
+
│
|
|
52
|
+
▼
|
|
53
|
+
Queue handler (switch dle type)
|
|
54
|
+
├─ email → _sendEmail()
|
|
55
|
+
├─ sms → _sendSms()
|
|
56
|
+
├─ slack → sendSlackNotification()
|
|
57
|
+
└─ push → _sendPushNotification() (501)
|
|
58
|
+
│
|
|
59
|
+
├─ success → message.ack()
|
|
60
|
+
└─ error → message.retry() (exponential backoff, base 60s)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Sync flow
|
|
64
|
+
|
|
65
|
+
`public-send-email-sync` vola `_sendEmail()` primo bez fronty.
|
|
66
|
+
|
|
67
|
+
### Queue message
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
{
|
|
71
|
+
type: 'email' | 'sms' | 'pushNotification' | 'slack'
|
|
72
|
+
metadata: {
|
|
73
|
+
userAgent?: string
|
|
74
|
+
ip?: string
|
|
75
|
+
initiator: { service: string, userId?: string }
|
|
76
|
+
}
|
|
77
|
+
payload: {
|
|
78
|
+
email?: IEmail
|
|
79
|
+
sms?: ISms
|
|
80
|
+
pushNotification?: IPushNotification
|
|
81
|
+
slack?: ISlack
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Konektory
|
|
87
|
+
|
|
88
|
+
### Ecomail (email)
|
|
89
|
+
|
|
90
|
+
Provider pro transakcni emaily. Podporuje:
|
|
91
|
+
- Plain text a HTML emaily (`/transactional/send-message`)
|
|
92
|
+
- Template emaily s merge vars (`/transactional/send-template`)
|
|
93
|
+
- Prilohy (base64, max 10 priloh, celkem 25MB)
|
|
94
|
+
- CC, BCC, Reply-To
|
|
95
|
+
|
|
96
|
+
Omezeni: Ecomail odmita emaily s `localhost` v template variables - connector automaticky nahradi `localhost` za `origin`.
|
|
97
|
+
|
|
98
|
+
### Twilio (SMS)
|
|
99
|
+
|
|
100
|
+
Provider pro SMS pres Twilio Messaging Service.
|
|
101
|
+
|
|
102
|
+
### Slack (webhook)
|
|
103
|
+
|
|
104
|
+
Odesilani notifikaci pres Slack Incoming Webhook. Timeout 3s.
|
|
105
|
+
|
|
106
|
+
## RPC akce
|
|
107
|
+
|
|
108
|
+
Notification service je **RPC worker** - vsechny akce dostupne pres Cloudflare Worker binding.
|
|
109
|
+
|
|
110
|
+
### Verejne akce
|
|
111
|
+
|
|
112
|
+
| Akce | Popis |
|
|
113
|
+
|------|-------|
|
|
114
|
+
| `public-send-email` | Zaradi email do fronty (async) |
|
|
115
|
+
| `public-send-email-sync` | Odesle email primo (sync) |
|
|
116
|
+
| `public-send-sms` | Zaradi SMS do fronty (async) |
|
|
117
|
+
| `send-slack-notification` | Odesle Slack notifikaci (sync) |
|
|
118
|
+
|
|
119
|
+
### Interni akce
|
|
120
|
+
|
|
121
|
+
| Akce | Popis |
|
|
122
|
+
|------|-------|
|
|
123
|
+
| `private-send-email` | Odesle email pres konektor + audit log |
|
|
124
|
+
| `private-send-sms` | Odesle SMS pres konektor + audit log |
|
|
125
|
+
| `send-push-notification` | Neimplementovano (501) |
|
|
126
|
+
|
|
127
|
+
### Vstupy
|
|
128
|
+
|
|
129
|
+
Vsechny akce vyzaduji `metadata` objekt:
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
metadata: {
|
|
133
|
+
userAgent?: string
|
|
134
|
+
ip?: string // IPv4 nebo IPv6
|
|
135
|
+
initiator: {
|
|
136
|
+
service: string // nazev volajici sluzby
|
|
137
|
+
userId?: string
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
**Email** podporuje: `to`, `cc`, `bcc`, `replyTo`, `from`, `subject`, `text`, `html`, `templateId`, `templateVariables`, `attachments`.
|
|
143
|
+
|
|
144
|
+
**SMS** podporuje: `message`, `to`.
|
|
145
|
+
|
|
146
|
+
**Slack** podporuje: `message`.
|
|
147
|
+
|
|
148
|
+
## Audit logging
|
|
149
|
+
|
|
150
|
+
Kazdy uspesne odeslany email a SMS se zaznamenava do audit logu.
|
|
151
|
+
|
|
152
|
+
Zaznamenavane udaje: event type, IP adresa, user agent, popis (JSON vstupu), initiator service, initiator user ID.
|
|
153
|
+
|
|
154
|
+
## Databazove schema
|
|
155
|
+
|
|
156
|
+
### audit_log
|
|
157
|
+
|
|
158
|
+
| Sloupec | Typ | Popis |
|
|
159
|
+
|---------|-----|-------|
|
|
160
|
+
| `id` | text | UUID |
|
|
161
|
+
| `createdAt` | timestamp | Cas vytvoreni |
|
|
162
|
+
| `event` | text | `EMAIL` \| `SMS` \| `PUSH_NOTIFICATION` \| `SLACK` |
|
|
163
|
+
| `ip` | text | IP adresa (nullable) |
|
|
164
|
+
| `userAgent` | text | User agent (nullable) |
|
|
165
|
+
| `description` | text | JSON dump vstupu (nullable) |
|
|
166
|
+
| `initiatorService` | text | Nazev volajici sluzby |
|
|
167
|
+
| `initiatorUserId` | text | ID uzivatele (nullable) |
|
|
168
|
+
|
|
169
|
+
## Error Codes
|
|
170
|
+
|
|
171
|
+
Format: `{CATEGORY}-N-{NUMBER}`
|
|
172
|
+
|
|
173
|
+
| Code | Status | Popis |
|
|
174
|
+
|------|--------|-------|
|
|
175
|
+
| `CONN-N-01` | 502 | Ecomail: failed to send email |
|
|
176
|
+
| `CONN-N-02` | 502 | Ecomail: failed to send template email |
|
|
177
|
+
| `CONN-N-03` | 502 | Twilio: failed to send SMS |
|
|
178
|
+
| `CONN-N-04` | 502 | Slack: failed to send notification |
|
|
179
|
+
| `CONN-N-05` | 504 | Slack: request timed out |
|
|
180
|
+
| `VALID-N-01` | 404 | Unsupported email provider |
|
|
181
|
+
| `VALID-N-02` | 404 | Unsupported SMS provider |
|
|
182
|
+
| `SYS-N-01` | 501 | Push notifications not implemented |
|
package/dist/export/worker.cjs
CHANGED
|
@@ -6,7 +6,7 @@ const backendSdk = require('@develit-io/backend-sdk');
|
|
|
6
6
|
const database_schema = require('../shared/notification.4b3eUEIG.cjs');
|
|
7
7
|
require('drizzle-orm');
|
|
8
8
|
require('drizzle-orm/sqlite-core');
|
|
9
|
-
const slack_connector = require('../shared/notification.
|
|
9
|
+
const slack_connector = require('../shared/notification.B0pktSz9.cjs');
|
|
10
10
|
const cloudflare_workers = require('cloudflare:workers');
|
|
11
11
|
const d1 = require('drizzle-orm/d1');
|
|
12
12
|
require('zod');
|
|
@@ -22,6 +22,7 @@ const initiateEmailConnector = async (provider, apiKey, smtpHost, senderEmail, s
|
|
|
22
22
|
if (!connector)
|
|
23
23
|
throw backendSdk.createInternalError(null, {
|
|
24
24
|
message: "Unsupported email provider",
|
|
25
|
+
code: "VALID-N-01",
|
|
25
26
|
status: 404
|
|
26
27
|
});
|
|
27
28
|
return new connector({
|
|
@@ -64,7 +65,8 @@ const initiateSmsConnector = async (provider, accountId, authToken, serviceId) =
|
|
|
64
65
|
);
|
|
65
66
|
if (!connector)
|
|
66
67
|
throw backendSdk.createInternalError(null, {
|
|
67
|
-
message: "Unsupported
|
|
68
|
+
message: "Unsupported SMS provider",
|
|
69
|
+
code: "VALID-N-02",
|
|
68
70
|
status: 404
|
|
69
71
|
});
|
|
70
72
|
return new connector({
|
|
@@ -280,9 +282,13 @@ let NotificationServiceBase = class extends backendSdk.develitWorker(
|
|
|
280
282
|
);
|
|
281
283
|
}
|
|
282
284
|
async _sendPushNotification() {
|
|
283
|
-
this.
|
|
284
|
-
|
|
285
|
-
|
|
285
|
+
return this.handleAction(null, { successMessage: "" }, async () => {
|
|
286
|
+
throw backendSdk.createInternalError(null, {
|
|
287
|
+
message: "Push notifications not implemented",
|
|
288
|
+
code: "SYS-N-01",
|
|
289
|
+
status: 501
|
|
290
|
+
});
|
|
291
|
+
});
|
|
286
292
|
}
|
|
287
293
|
async sendSlackNotification(input) {
|
|
288
294
|
return this.handleAction(
|
package/dist/export/worker.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _develit_io_backend_sdk from '@develit-io/backend-sdk';
|
|
2
2
|
import { IRPCResponse } from '@develit-io/backend-sdk';
|
|
3
|
-
import { S as SlackConnector, I as IEmailConnector, a as ISmsConnector, t as tables, N as NotificationQueueMessage, b as SendEmailInput, c as SendEmailOutput, d as SendSmsInput, e as SendSmsOutput, f as SendSlackInput, g as SendSlackOutput } from '../shared/notification.
|
|
3
|
+
import { S as SlackConnector, I as IEmailConnector, a as ISmsConnector, t as tables, N as NotificationQueueMessage, b as SendEmailInput, c as SendEmailOutput, d as SendSmsInput, e as SendSmsOutput, f as SendSlackInput, g as SendSlackOutput } from '../shared/notification.B4ZLWDCP.cjs';
|
|
4
4
|
import { WorkerEntrypoint } from 'cloudflare:workers';
|
|
5
5
|
import { DrizzleD1Database } from 'drizzle-orm/d1';
|
|
6
6
|
import '../shared/notification.BWLPh6Gb.cjs';
|
package/dist/export/worker.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _develit_io_backend_sdk from '@develit-io/backend-sdk';
|
|
2
2
|
import { IRPCResponse } from '@develit-io/backend-sdk';
|
|
3
|
-
import { S as SlackConnector, I as IEmailConnector, a as ISmsConnector, t as tables, N as NotificationQueueMessage, b as SendEmailInput, c as SendEmailOutput, d as SendSmsInput, e as SendSmsOutput, f as SendSlackInput, g as SendSlackOutput } from '../shared/notification.
|
|
3
|
+
import { S as SlackConnector, I as IEmailConnector, a as ISmsConnector, t as tables, N as NotificationQueueMessage, b as SendEmailInput, c as SendEmailOutput, d as SendSmsInput, e as SendSmsOutput, f as SendSlackInput, g as SendSlackOutput } from '../shared/notification.CpFoKjoN.mjs';
|
|
4
4
|
import { WorkerEntrypoint } from 'cloudflare:workers';
|
|
5
5
|
import { DrizzleD1Database } from 'drizzle-orm/d1';
|
|
6
6
|
import '../shared/notification.BWLPh6Gb.mjs';
|
package/dist/export/worker.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _develit_io_backend_sdk from '@develit-io/backend-sdk';
|
|
2
2
|
import { IRPCResponse } from '@develit-io/backend-sdk';
|
|
3
|
-
import { S as SlackConnector, I as IEmailConnector, a as ISmsConnector, t as tables, N as NotificationQueueMessage, b as SendEmailInput, c as SendEmailOutput, d as SendSmsInput, e as SendSmsOutput, f as SendSlackInput, g as SendSlackOutput } from '../shared/notification.
|
|
3
|
+
import { S as SlackConnector, I as IEmailConnector, a as ISmsConnector, t as tables, N as NotificationQueueMessage, b as SendEmailInput, c as SendEmailOutput, d as SendSmsInput, e as SendSmsOutput, f as SendSlackInput, g as SendSlackOutput } from '../shared/notification.DWuoMDHY.js';
|
|
4
4
|
import { WorkerEntrypoint } from 'cloudflare:workers';
|
|
5
5
|
import { DrizzleD1Database } from 'drizzle-orm/d1';
|
|
6
6
|
import '../shared/notification.BWLPh6Gb.js';
|
package/dist/export/worker.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { createInternalError, uuidv4, develitWorker, cloudflareQueue, action, se
|
|
|
2
2
|
import { s as schema } from '../shared/notification.C0X8Orrh.mjs';
|
|
3
3
|
import 'drizzle-orm';
|
|
4
4
|
import 'drizzle-orm/sqlite-core';
|
|
5
|
-
import { E as EcomailConnector, T as TwilioConnector, S as SlackConnector, s as sendEmailInputSchema, a as sendSmsInputSchema, b as sendSlackInputSchema } from '../shared/notification.
|
|
5
|
+
import { E as EcomailConnector, T as TwilioConnector, S as SlackConnector, s as sendEmailInputSchema, a as sendSmsInputSchema, b as sendSlackInputSchema } from '../shared/notification.CmITLO7E.mjs';
|
|
6
6
|
import { WorkerEntrypoint } from 'cloudflare:workers';
|
|
7
7
|
import { drizzle } from 'drizzle-orm/d1';
|
|
8
8
|
import 'zod';
|
|
@@ -18,6 +18,7 @@ const initiateEmailConnector = async (provider, apiKey, smtpHost, senderEmail, s
|
|
|
18
18
|
if (!connector)
|
|
19
19
|
throw createInternalError(null, {
|
|
20
20
|
message: "Unsupported email provider",
|
|
21
|
+
code: "VALID-N-01",
|
|
21
22
|
status: 404
|
|
22
23
|
});
|
|
23
24
|
return new connector({
|
|
@@ -60,7 +61,8 @@ const initiateSmsConnector = async (provider, accountId, authToken, serviceId) =
|
|
|
60
61
|
);
|
|
61
62
|
if (!connector)
|
|
62
63
|
throw createInternalError(null, {
|
|
63
|
-
message: "Unsupported
|
|
64
|
+
message: "Unsupported SMS provider",
|
|
65
|
+
code: "VALID-N-02",
|
|
64
66
|
status: 404
|
|
65
67
|
});
|
|
66
68
|
return new connector({
|
|
@@ -276,9 +278,13 @@ let NotificationServiceBase = class extends develitWorker(
|
|
|
276
278
|
);
|
|
277
279
|
}
|
|
278
280
|
async _sendPushNotification() {
|
|
279
|
-
this.
|
|
280
|
-
|
|
281
|
-
|
|
281
|
+
return this.handleAction(null, { successMessage: "" }, async () => {
|
|
282
|
+
throw createInternalError(null, {
|
|
283
|
+
message: "Push notifications not implemented",
|
|
284
|
+
code: "SYS-N-01",
|
|
285
|
+
status: 501
|
|
286
|
+
});
|
|
287
|
+
});
|
|
282
288
|
}
|
|
283
289
|
async sendSlackNotification(input) {
|
|
284
290
|
return this.handleAction(
|
|
@@ -107,7 +107,12 @@ class EcomailConnector extends IEmailConnector {
|
|
|
107
107
|
},
|
|
108
108
|
body: JSON.stringify(emEmail)
|
|
109
109
|
});
|
|
110
|
-
if (error)
|
|
110
|
+
if (error)
|
|
111
|
+
throw backendSdk.createInternalError(error, {
|
|
112
|
+
message: `Ecomail: failed to send ${emEmail.message.template_id ? "template " : ""}email: ${error.message}`,
|
|
113
|
+
code: emEmail.message.template_id ? "CONN-N-02" : "CONN-N-01",
|
|
114
|
+
status: 502
|
|
115
|
+
});
|
|
111
116
|
}
|
|
112
117
|
convertEmail(email) {
|
|
113
118
|
const toContacts = this.convertContacts(email.to);
|
|
@@ -246,8 +251,9 @@ class TwilioConnector extends ISmsConnector {
|
|
|
246
251
|
to: sms.to
|
|
247
252
|
});
|
|
248
253
|
if (message.errorMessage)
|
|
249
|
-
|
|
250
|
-
message: message.errorMessage
|
|
254
|
+
throw backendSdk.createInternalError(null, {
|
|
255
|
+
message: `Twilio: ${message.errorMessage}`,
|
|
256
|
+
code: "CONN-N-03",
|
|
251
257
|
status: message.errorCode
|
|
252
258
|
});
|
|
253
259
|
}
|
|
@@ -260,16 +266,29 @@ class SlackConnector {
|
|
|
260
266
|
async sendNotificationToAllSlack(message) {
|
|
261
267
|
const controller = new AbortController();
|
|
262
268
|
const timeoutId = setTimeout(() => controller.abort(), 3e3);
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
269
|
+
let response;
|
|
270
|
+
try {
|
|
271
|
+
response = await fetch(this.webhook, {
|
|
272
|
+
method: "POST",
|
|
273
|
+
body: JSON.stringify({ text: message }),
|
|
274
|
+
headers: { "Content-Type": "application/json" },
|
|
275
|
+
signal: controller.signal
|
|
276
|
+
});
|
|
277
|
+
} catch (error) {
|
|
278
|
+
clearTimeout(timeoutId);
|
|
279
|
+
throw backendSdk.createInternalError(error, {
|
|
280
|
+
message: "Slack: request timed out",
|
|
281
|
+
code: "CONN-N-05",
|
|
282
|
+
status: 504
|
|
283
|
+
});
|
|
272
284
|
}
|
|
285
|
+
clearTimeout(timeoutId);
|
|
286
|
+
if (!response.ok)
|
|
287
|
+
throw backendSdk.createInternalError(null, {
|
|
288
|
+
message: `Slack: failed to send notification (${response.status})`,
|
|
289
|
+
code: "CONN-N-04",
|
|
290
|
+
status: 502
|
|
291
|
+
});
|
|
273
292
|
}
|
|
274
293
|
}
|
|
275
294
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { s as schema } from './notification.BWLPh6Gb.cjs';
|
|
2
2
|
import z$1, { z } from 'zod';
|
|
3
3
|
import { z as z$2 } from 'zod/v4';
|
|
4
|
-
import { InternalError } from '@develit-io/backend-sdk';
|
|
5
4
|
|
|
6
5
|
declare const tables: typeof schema;
|
|
7
6
|
|
|
@@ -212,7 +211,7 @@ declare abstract class ISmsConnector {
|
|
|
212
211
|
AUTH_TOKEN: string;
|
|
213
212
|
SERVICE_ID: string;
|
|
214
213
|
});
|
|
215
|
-
abstract sendSms(sms: ISms): Promise<
|
|
214
|
+
abstract sendSms(sms: ISms): Promise<void>;
|
|
216
215
|
}
|
|
217
216
|
|
|
218
217
|
interface ISlack {
|
|
@@ -100,7 +100,12 @@ class EcomailConnector extends IEmailConnector {
|
|
|
100
100
|
},
|
|
101
101
|
body: JSON.stringify(emEmail)
|
|
102
102
|
});
|
|
103
|
-
if (error)
|
|
103
|
+
if (error)
|
|
104
|
+
throw createInternalError(error, {
|
|
105
|
+
message: `Ecomail: failed to send ${emEmail.message.template_id ? "template " : ""}email: ${error.message}`,
|
|
106
|
+
code: emEmail.message.template_id ? "CONN-N-02" : "CONN-N-01",
|
|
107
|
+
status: 502
|
|
108
|
+
});
|
|
104
109
|
}
|
|
105
110
|
convertEmail(email) {
|
|
106
111
|
const toContacts = this.convertContacts(email.to);
|
|
@@ -239,8 +244,9 @@ class TwilioConnector extends ISmsConnector {
|
|
|
239
244
|
to: sms.to
|
|
240
245
|
});
|
|
241
246
|
if (message.errorMessage)
|
|
242
|
-
|
|
243
|
-
message: message.errorMessage
|
|
247
|
+
throw createInternalError(null, {
|
|
248
|
+
message: `Twilio: ${message.errorMessage}`,
|
|
249
|
+
code: "CONN-N-03",
|
|
244
250
|
status: message.errorCode
|
|
245
251
|
});
|
|
246
252
|
}
|
|
@@ -253,16 +259,29 @@ class SlackConnector {
|
|
|
253
259
|
async sendNotificationToAllSlack(message) {
|
|
254
260
|
const controller = new AbortController();
|
|
255
261
|
const timeoutId = setTimeout(() => controller.abort(), 3e3);
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
262
|
+
let response;
|
|
263
|
+
try {
|
|
264
|
+
response = await fetch(this.webhook, {
|
|
265
|
+
method: "POST",
|
|
266
|
+
body: JSON.stringify({ text: message }),
|
|
267
|
+
headers: { "Content-Type": "application/json" },
|
|
268
|
+
signal: controller.signal
|
|
269
|
+
});
|
|
270
|
+
} catch (error) {
|
|
271
|
+
clearTimeout(timeoutId);
|
|
272
|
+
throw createInternalError(error, {
|
|
273
|
+
message: "Slack: request timed out",
|
|
274
|
+
code: "CONN-N-05",
|
|
275
|
+
status: 504
|
|
276
|
+
});
|
|
265
277
|
}
|
|
278
|
+
clearTimeout(timeoutId);
|
|
279
|
+
if (!response.ok)
|
|
280
|
+
throw createInternalError(null, {
|
|
281
|
+
message: `Slack: failed to send notification (${response.status})`,
|
|
282
|
+
code: "CONN-N-04",
|
|
283
|
+
status: 502
|
|
284
|
+
});
|
|
266
285
|
}
|
|
267
286
|
}
|
|
268
287
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { s as schema } from './notification.BWLPh6Gb.mjs';
|
|
2
2
|
import z$1, { z } from 'zod';
|
|
3
3
|
import { z as z$2 } from 'zod/v4';
|
|
4
|
-
import { InternalError } from '@develit-io/backend-sdk';
|
|
5
4
|
|
|
6
5
|
declare const tables: typeof schema;
|
|
7
6
|
|
|
@@ -212,7 +211,7 @@ declare abstract class ISmsConnector {
|
|
|
212
211
|
AUTH_TOKEN: string;
|
|
213
212
|
SERVICE_ID: string;
|
|
214
213
|
});
|
|
215
|
-
abstract sendSms(sms: ISms): Promise<
|
|
214
|
+
abstract sendSms(sms: ISms): Promise<void>;
|
|
216
215
|
}
|
|
217
216
|
|
|
218
217
|
interface ISlack {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { s as schema } from './notification.BWLPh6Gb.js';
|
|
2
2
|
import z$1, { z } from 'zod';
|
|
3
3
|
import { z as z$2 } from 'zod/v4';
|
|
4
|
-
import { InternalError } from '@develit-io/backend-sdk';
|
|
5
4
|
|
|
6
5
|
declare const tables: typeof schema;
|
|
7
6
|
|
|
@@ -212,7 +211,7 @@ declare abstract class ISmsConnector {
|
|
|
212
211
|
AUTH_TOKEN: string;
|
|
213
212
|
SERVICE_ID: string;
|
|
214
213
|
});
|
|
215
|
-
abstract sendSms(sms: ISms): Promise<
|
|
214
|
+
abstract sendSms(sms: ISms): Promise<void>;
|
|
216
215
|
}
|
|
217
216
|
|
|
218
217
|
interface ISlack {
|
package/dist/types.cjs
CHANGED
package/dist/types.d.cts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { I as IEmailConnector, h as IEmail, i as IContact, a as ISmsConnector, j as ISms, t as tables } from './shared/notification.
|
|
2
|
-
export { k as IAttachment, l as IPushNotification, m as ISlack, N as NotificationQueueMessage, b as SendEmailInput, c as SendEmailOutput, f as SendSlackInput, g as SendSlackOutput, d as SendSmsInput, e as SendSmsOutput, S as SlackConnector, n as iAttachmentSchema, o as iContactSchema, p as iEmailSchema, s as sendEmailInputSchema, q as sendSlackInputSchema, r as sendSmsInputSchema } from './shared/notification.
|
|
3
|
-
import { InternalError } from '@develit-io/backend-sdk';
|
|
1
|
+
import { I as IEmailConnector, h as IEmail, i as IContact, a as ISmsConnector, j as ISms, t as tables } from './shared/notification.B4ZLWDCP.cjs';
|
|
2
|
+
export { k as IAttachment, l as IPushNotification, m as ISlack, N as NotificationQueueMessage, b as SendEmailInput, c as SendEmailOutput, f as SendSlackInput, g as SendSlackOutput, d as SendSmsInput, e as SendSmsOutput, S as SlackConnector, n as iAttachmentSchema, o as iContactSchema, p as iEmailSchema, s as sendEmailInputSchema, q as sendSlackInputSchema, r as sendSmsInputSchema } from './shared/notification.B4ZLWDCP.cjs';
|
|
4
3
|
import twilio from 'twilio';
|
|
5
4
|
import { InferInsertModel, InferSelectModel } from 'drizzle-orm';
|
|
6
5
|
export { a as NotificationServiceEnv, b as NotificationServiceEnvironmentConfig, N as NotificationServiceWranglerConfig } from './shared/notification.BB9Jl8DI.cjs';
|
|
@@ -57,7 +56,7 @@ declare class TwilioConnector extends ISmsConnector {
|
|
|
57
56
|
AUTH_TOKEN: string;
|
|
58
57
|
SERVICE_ID: string;
|
|
59
58
|
});
|
|
60
|
-
sendSms(sms: ISms): Promise<
|
|
59
|
+
sendSms(sms: ISms): Promise<void>;
|
|
61
60
|
}
|
|
62
61
|
|
|
63
62
|
interface AuditLogSelectType extends InferSelectModel<typeof tables.auditLog> {
|
package/dist/types.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { I as IEmailConnector, h as IEmail, i as IContact, a as ISmsConnector, j as ISms, t as tables } from './shared/notification.
|
|
2
|
-
export { k as IAttachment, l as IPushNotification, m as ISlack, N as NotificationQueueMessage, b as SendEmailInput, c as SendEmailOutput, f as SendSlackInput, g as SendSlackOutput, d as SendSmsInput, e as SendSmsOutput, S as SlackConnector, n as iAttachmentSchema, o as iContactSchema, p as iEmailSchema, s as sendEmailInputSchema, q as sendSlackInputSchema, r as sendSmsInputSchema } from './shared/notification.
|
|
3
|
-
import { InternalError } from '@develit-io/backend-sdk';
|
|
1
|
+
import { I as IEmailConnector, h as IEmail, i as IContact, a as ISmsConnector, j as ISms, t as tables } from './shared/notification.CpFoKjoN.mjs';
|
|
2
|
+
export { k as IAttachment, l as IPushNotification, m as ISlack, N as NotificationQueueMessage, b as SendEmailInput, c as SendEmailOutput, f as SendSlackInput, g as SendSlackOutput, d as SendSmsInput, e as SendSmsOutput, S as SlackConnector, n as iAttachmentSchema, o as iContactSchema, p as iEmailSchema, s as sendEmailInputSchema, q as sendSlackInputSchema, r as sendSmsInputSchema } from './shared/notification.CpFoKjoN.mjs';
|
|
4
3
|
import twilio from 'twilio';
|
|
5
4
|
import { InferInsertModel, InferSelectModel } from 'drizzle-orm';
|
|
6
5
|
export { a as NotificationServiceEnv, b as NotificationServiceEnvironmentConfig, N as NotificationServiceWranglerConfig } from './shared/notification.BB9Jl8DI.mjs';
|
|
@@ -57,7 +56,7 @@ declare class TwilioConnector extends ISmsConnector {
|
|
|
57
56
|
AUTH_TOKEN: string;
|
|
58
57
|
SERVICE_ID: string;
|
|
59
58
|
});
|
|
60
|
-
sendSms(sms: ISms): Promise<
|
|
59
|
+
sendSms(sms: ISms): Promise<void>;
|
|
61
60
|
}
|
|
62
61
|
|
|
63
62
|
interface AuditLogSelectType extends InferSelectModel<typeof tables.auditLog> {
|
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { I as IEmailConnector, h as IEmail, i as IContact, a as ISmsConnector, j as ISms, t as tables } from './shared/notification.
|
|
2
|
-
export { k as IAttachment, l as IPushNotification, m as ISlack, N as NotificationQueueMessage, b as SendEmailInput, c as SendEmailOutput, f as SendSlackInput, g as SendSlackOutput, d as SendSmsInput, e as SendSmsOutput, S as SlackConnector, n as iAttachmentSchema, o as iContactSchema, p as iEmailSchema, s as sendEmailInputSchema, q as sendSlackInputSchema, r as sendSmsInputSchema } from './shared/notification.
|
|
3
|
-
import { InternalError } from '@develit-io/backend-sdk';
|
|
1
|
+
import { I as IEmailConnector, h as IEmail, i as IContact, a as ISmsConnector, j as ISms, t as tables } from './shared/notification.DWuoMDHY.js';
|
|
2
|
+
export { k as IAttachment, l as IPushNotification, m as ISlack, N as NotificationQueueMessage, b as SendEmailInput, c as SendEmailOutput, f as SendSlackInput, g as SendSlackOutput, d as SendSmsInput, e as SendSmsOutput, S as SlackConnector, n as iAttachmentSchema, o as iContactSchema, p as iEmailSchema, s as sendEmailInputSchema, q as sendSlackInputSchema, r as sendSmsInputSchema } from './shared/notification.DWuoMDHY.js';
|
|
4
3
|
import twilio from 'twilio';
|
|
5
4
|
import { InferInsertModel, InferSelectModel } from 'drizzle-orm';
|
|
6
5
|
export { a as NotificationServiceEnv, b as NotificationServiceEnvironmentConfig, N as NotificationServiceWranglerConfig } from './shared/notification.BB9Jl8DI.js';
|
|
@@ -57,7 +56,7 @@ declare class TwilioConnector extends ISmsConnector {
|
|
|
57
56
|
AUTH_TOKEN: string;
|
|
58
57
|
SERVICE_ID: string;
|
|
59
58
|
});
|
|
60
|
-
sendSms(sms: ISms): Promise<
|
|
59
|
+
sendSms(sms: ISms): Promise<void>;
|
|
61
60
|
}
|
|
62
61
|
|
|
63
62
|
interface AuditLogSelectType extends InferSelectModel<typeof tables.auditLog> {
|
package/dist/types.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { E as EcomailConnector, I as IEmailConnector, c as ISmsConnector, S as SlackConnector, T as TwilioConnector, i as iAttachmentSchema, d as iContactSchema, e as iEmailSchema, s as sendEmailInputSchema, b as sendSlackInputSchema, a as sendSmsInputSchema } from './shared/notification.
|
|
1
|
+
export { E as EcomailConnector, I as IEmailConnector, c as ISmsConnector, S as SlackConnector, T as TwilioConnector, i as iAttachmentSchema, d as iContactSchema, e as iEmailSchema, s as sendEmailInputSchema, b as sendSlackInputSchema, a as sendSmsInputSchema } from './shared/notification.CmITLO7E.mjs';
|
|
2
2
|
import 'zod';
|
|
3
3
|
import '@develit-io/backend-sdk';
|
|
4
4
|
import 'zod/v4';
|