@develit-services/notification 0.5.0 → 0.6.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 (35) hide show
  1. package/README.md +239 -0
  2. package/dist/database/schema.cjs +4 -6
  3. package/dist/database/schema.d.cts +6 -2
  4. package/dist/database/schema.d.mts +6 -2
  5. package/dist/database/schema.d.ts +6 -2
  6. package/dist/database/schema.mjs +5 -3
  7. package/dist/export/worker.cjs +270 -69
  8. package/dist/export/worker.d.cts +22 -3
  9. package/dist/export/worker.d.mts +22 -3
  10. package/dist/export/worker.d.ts +22 -3
  11. package/dist/export/worker.mjs +262 -61
  12. package/dist/export/wrangler.cjs +19 -1
  13. package/dist/export/wrangler.d.cts +5 -1
  14. package/dist/export/wrangler.d.mts +5 -1
  15. package/dist/export/wrangler.d.ts +5 -1
  16. package/dist/export/wrangler.mjs +19 -1
  17. package/dist/shared/{notification.Dk_5TX9v.cjs → notification.BLPB8Ib2.cjs} +109 -11
  18. package/dist/shared/{notification.2rSOcFrr.d.cts → notification.BiG4Q650.d.cts} +99 -8
  19. package/dist/shared/{notification.C1quYqlT.d.mts → notification.BiG4Q650.d.mts} +99 -8
  20. package/dist/shared/{notification.oEdhCsu_.d.ts → notification.BiG4Q650.d.ts} +99 -8
  21. package/dist/shared/{notification.CM_WoR0y.mjs → notification.CP_hFlNt.mjs} +105 -12
  22. package/dist/shared/{notification.BB9Jl8DI.d.ts → notification.CdlaOUd0.d.cts} +3 -0
  23. package/dist/shared/{notification.BB9Jl8DI.d.cts → notification.CdlaOUd0.d.mts} +3 -0
  24. package/dist/shared/{notification.BB9Jl8DI.d.mts → notification.CdlaOUd0.d.ts} +3 -0
  25. package/dist/types.cjs +19 -19
  26. package/dist/types.d.cts +6 -18
  27. package/dist/types.d.mts +6 -18
  28. package/dist/types.d.ts +6 -18
  29. package/dist/types.mjs +2 -10
  30. package/package.json +3 -3
  31. package/dist/shared/notification.4b3eUEIG.cjs +0 -22
  32. package/dist/shared/notification.BWLPh6Gb.d.cts +0 -140
  33. package/dist/shared/notification.BWLPh6Gb.d.mts +0 -140
  34. package/dist/shared/notification.BWLPh6Gb.d.ts +0 -140
  35. package/dist/shared/notification.C0X8Orrh.mjs +0 -19
package/README.md ADDED
@@ -0,0 +1,239 @@
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
+ | Webhook | WebhookConnector | Aktivni |
39
+ | Push | - | Neimplementovano |
40
+
41
+ ## Queue processing
42
+
43
+ Notifikace lze odesilat synchronne (primo) nebo asynchronne (pres frontu).
44
+
45
+ ### Async flow (vychozi)
46
+
47
+ ```
48
+ public-send-email / public-send-sms
49
+
50
+
51
+ NOTIFICATIONS_QUEUE
52
+
53
+
54
+ Queue handler (switch dle type)
55
+ ├─ email → _sendEmail()
56
+ ├─ sms → _sendSms()
57
+ ├─ slack → sendSlackNotification()
58
+ ├─ webhook → _sendWebhook()
59
+ └─ push → _sendPushNotification() (501)
60
+
61
+ ├─ success → message.ack()
62
+ └─ error → message.retry() (exponential backoff, base 60s)
63
+ ```
64
+
65
+ ### Sync flow
66
+
67
+ `public-send-email-sync` vola `_sendEmail()` primo bez fronty.
68
+
69
+ ### Queue message
70
+
71
+ ```typescript
72
+ {
73
+ type: 'email' | 'sms' | 'pushNotification' | 'slack' | 'webhook'
74
+ metadata: {
75
+ userAgent?: string
76
+ ip?: string
77
+ initiator: { service: string, userId?: string }
78
+ }
79
+ payload: {
80
+ email?: IEmail
81
+ sms?: ISms
82
+ pushNotification?: IPushNotification
83
+ slack?: ISlack
84
+ webhook?: IWebhook
85
+ }
86
+ }
87
+ ```
88
+
89
+ ## Konektory
90
+
91
+ ### Ecomail (email)
92
+
93
+ Provider pro transakcni emaily. Podporuje:
94
+ - Plain text a HTML emaily (`/transactional/send-message`)
95
+ - Template emaily s merge vars (`/transactional/send-template`)
96
+ - Prilohy (base64, max 10 priloh, celkem 25MB)
97
+ - CC, BCC, Reply-To
98
+
99
+ Omezeni: Ecomail odmita emaily s `localhost` v template variables - connector automaticky nahradi `localhost` za `origin`.
100
+
101
+ ### Twilio (SMS)
102
+
103
+ Provider pro SMS pres Twilio Messaging Service.
104
+
105
+ ### Slack (webhook)
106
+
107
+ Odesilani notifikaci pres Slack Incoming Webhook. Timeout 3s.
108
+
109
+ ### Webhook (HTTP callback)
110
+
111
+ Odesilani podepsanych HTTP POST callbacku na URL zadanou callerem. Timeout 10s.
112
+
113
+ Kazdy webhook je automaticky podepsan RSA-PKCS1-v1_5 (SHA-256) podpisem. Privatni klic se nacita ze Secrets Store (`NOTIFICATION_SERVICE_WEBHOOK_SIGNING_KEY`). Podpis se odesila v hlavicce `X-Webhook-Signature` (base64).
114
+
115
+ #### Generovani klicu
116
+
117
+ ```bash
118
+ # Private key (base64, jedna radka) → ulozit do Secrets Store jako NOTIFICATION_SERVICE_WEBHOOK_SIGNING_KEY
119
+ openssl genrsa 4096 2>/dev/null | base64 -w0
120
+
121
+ # Public key z private key → poskytnout prijemcum webhooku v API docs
122
+ echo "<PRIVATE_KEY_BASE64>" | base64 -d | openssl rsa -pubout 2>/dev/null | base64 -w0
123
+ ```
124
+
125
+ > Na macOS pouzit `base64` bez `-w0` (macOS verze nevypisuje newlines).
126
+
127
+ #### Overeni podpisu na strane prijemce
128
+
129
+ Podpis je `RSA-PKCS1-v1_5` se `SHA-256`, odeslany v hlavicce `X-Webhook-Signature` jako base64 string. Overeni:
130
+
131
+ ```bash
132
+ # Ulozit raw body requestu do souboru
133
+ echo -n '{"type":"payment.created","data":{...}}' > body.json
134
+
135
+ # Dekodovat podpis z hlavicky
136
+ echo -n "<hodnota X-Webhook-Signature>" | base64 -d > signature.bin
137
+
138
+ # Overit
139
+ openssl dgst -sha256 -verify webhook_public.pem -signature signature.bin body.json
140
+ # Vystup: "Verified OK" nebo "Verification Failure"
141
+ ```
142
+
143
+ Nebo programove (Node.js):
144
+
145
+ ```javascript
146
+ const crypto = require('crypto')
147
+
148
+ function verifyWebhook(rawBody, signatureBase64, publicKeyBase64) {
149
+ const publicKey = Buffer.from(publicKeyBase64, 'base64').toString('utf-8')
150
+ const verifier = crypto.createVerify('RSA-SHA256')
151
+ verifier.update(rawBody)
152
+ return verifier.verify(publicKey, signatureBase64, 'base64')
153
+ }
154
+ ```
155
+
156
+ ## RPC akce
157
+
158
+ Notification service je **RPC worker** - vsechny akce dostupne pres Cloudflare Worker binding.
159
+
160
+ ### Verejne akce
161
+
162
+ | Akce | Popis |
163
+ |------|-------|
164
+ | `public-send-email` | Zaradi email do fronty (async) |
165
+ | `public-send-email-sync` | Odesle email primo (sync) |
166
+ | `public-send-sms` | Zaradi SMS do fronty (async) |
167
+ | `send-slack-notification` | Odesle Slack notifikaci (sync) |
168
+ | `send-webhook` | Zaradi webhook do fronty (async) |
169
+
170
+ ### Interni akce
171
+
172
+ | Akce | Popis |
173
+ |------|-------|
174
+ | `private-send-email` | Odesle email pres konektor + audit log |
175
+ | `private-send-sms` | Odesle SMS pres konektor + audit log |
176
+ | `private-send-webhook` | Odesle webhook pres konektor + audit log |
177
+ | `send-push-notification` | Neimplementovano (501) |
178
+
179
+ ### Vstupy
180
+
181
+ Vsechny akce vyzaduji `metadata` objekt:
182
+
183
+ ```typescript
184
+ metadata: {
185
+ userAgent?: string
186
+ ip?: string // IPv4 nebo IPv6
187
+ initiator: {
188
+ service: string // nazev volajici sluzby
189
+ userId?: string
190
+ }
191
+ }
192
+ ```
193
+
194
+ **Email** podporuje: `to`, `cc`, `bcc`, `replyTo`, `from`, `subject`, `text`, `html`, `templateId`, `templateVariables`, `attachments`.
195
+
196
+ **SMS** podporuje: `message`, `to`.
197
+
198
+ **Slack** podporuje: `message`.
199
+
200
+ **Webhook** podporuje: `url`, `payload` (libovolny JSON objekt), `headers` (volitelne custom HTTP headers).
201
+
202
+ ## Audit logging
203
+
204
+ Kazdy uspesne odeslany email a SMS se zaznamenava do audit logu.
205
+
206
+ Zaznamenavane udaje: event type, IP adresa, user agent, popis (JSON vstupu), initiator service, initiator user ID.
207
+
208
+ ## Databazove schema
209
+
210
+ ### audit_log
211
+
212
+ | Sloupec | Typ | Popis |
213
+ |---------|-----|-------|
214
+ | `id` | text | UUID |
215
+ | `createdAt` | timestamp | Cas vytvoreni |
216
+ | `event` | text | `EMAIL` \| `SMS` \| `PUSH_NOTIFICATION` \| `SLACK` |
217
+ | `ip` | text | IP adresa (nullable) |
218
+ | `userAgent` | text | User agent (nullable) |
219
+ | `description` | text | JSON dump vstupu (nullable) |
220
+ | `initiatorService` | text | Nazev volajici sluzby |
221
+ | `initiatorUserId` | text | ID uzivatele (nullable) |
222
+
223
+ ## Error Codes
224
+
225
+ Format: `{CATEGORY}-N-{NUMBER}`
226
+
227
+ | Code | Status | Popis |
228
+ |------|--------|-------|
229
+ | `CONN-N-01` | 502 | Ecomail: failed to send email |
230
+ | `CONN-N-02` | 502 | Ecomail: failed to send template email |
231
+ | `CONN-N-03` | 502 | Twilio: failed to send SMS |
232
+ | `CONN-N-04` | 502 | Slack: failed to send notification |
233
+ | `CONN-N-05` | 504 | Slack: request timed out |
234
+ | `CONN-N-06` | 502 | Webhook: delivery failed |
235
+ | `CONN-N-07` | 504 | Webhook: request timed out |
236
+ | `VALID-N-01` | 404 | Unsupported email provider |
237
+ | `VALID-N-02` | 404 | Unsupported SMS provider |
238
+ | `SYS-N-01` | 501 | Push notifications not implemented |
239
+ | `SYS-N-02` | 500 | Webhook signing key not configured |
@@ -1,9 +1,7 @@
1
1
  'use strict';
2
2
 
3
- const database_schema = require('../shared/notification.4b3eUEIG.cjs');
4
- require('@develit-io/backend-sdk');
5
- require('drizzle-orm/sqlite-core');
3
+ const schema = {
4
+ __proto__: null
5
+ };
6
6
 
7
-
8
-
9
- exports.auditLog = database_schema.auditLog;
7
+ exports.schema = schema;
@@ -1,2 +1,6 @@
1
- export { a as auditLog } from '../shared/notification.BWLPh6Gb.cjs';
2
- import 'drizzle-orm/sqlite-core';
1
+ declare namespace schema {
2
+ export {
3
+ };
4
+ }
5
+
6
+ export { schema as s };
@@ -1,2 +1,6 @@
1
- export { a as auditLog } from '../shared/notification.BWLPh6Gb.mjs';
2
- import 'drizzle-orm/sqlite-core';
1
+ declare namespace schema {
2
+ export {
3
+ };
4
+ }
5
+
6
+ export { schema as s };
@@ -1,2 +1,6 @@
1
- export { a as auditLog } from '../shared/notification.BWLPh6Gb.js';
2
- import 'drizzle-orm/sqlite-core';
1
+ declare namespace schema {
2
+ export {
3
+ };
4
+ }
5
+
6
+ export { schema as s };
@@ -1,3 +1,5 @@
1
- export { a as auditLog } from '../shared/notification.C0X8Orrh.mjs';
2
- import '@develit-io/backend-sdk';
3
- import 'drizzle-orm/sqlite-core';
1
+ const schema = {
2
+ __proto__: null
3
+ };
4
+
5
+ export { schema as s };