@develit-services/notification 0.0.2

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 (58) hide show
  1. package/@types/consts/audit-log.consts.ts +7 -0
  2. package/@types/consts/index.ts +1 -0
  3. package/@types/database/audit-log.types.ts +7 -0
  4. package/@types/database/index.ts +1 -0
  5. package/@types/email/IEmail.connector.ts +21 -0
  6. package/@types/email/IEmail.types.ts +25 -0
  7. package/@types/email/ecomail/ecomail.connector.ts +140 -0
  8. package/@types/email/ecomail/ecomail.types.ts +27 -0
  9. package/@types/email/ecomail/index.ts +2 -0
  10. package/@types/email/index.ts +3 -0
  11. package/@types/index.ts +9 -0
  12. package/@types/io/index.ts +3 -0
  13. package/@types/io/sendEmail.ts +18 -0
  14. package/@types/io/sendSlack.ts +19 -0
  15. package/@types/io/sendSms.ts +20 -0
  16. package/@types/pushNotification/IPushNotification.ts +1 -0
  17. package/@types/pushNotification/index.ts +1 -0
  18. package/@types/queue.ts +24 -0
  19. package/@types/service.ts +30 -0
  20. package/@types/slack/ISlack.types.ts +3 -0
  21. package/@types/slack/index.ts +1 -0
  22. package/@types/slack/slack.connector.ts +27 -0
  23. package/@types/sms/ISms.connector.ts +22 -0
  24. package/@types/sms/ISms.types.ts +4 -0
  25. package/@types/sms/index.ts +3 -0
  26. package/@types/sms/twilio/index.ts +1 -0
  27. package/@types/sms/twilio/twilio.connector.ts +36 -0
  28. package/CHANGELOG.md +28 -0
  29. package/build.config.ts +28 -0
  30. package/drizzle.config.ts +3 -0
  31. package/package.json +40 -0
  32. package/scripts/generate-wrangler.ts +13 -0
  33. package/src/database/drizzle.ts +6 -0
  34. package/src/database/migrations/0000_funny_beast.sql +12 -0
  35. package/src/database/migrations/meta/0000_snapshot.json +101 -0
  36. package/src/database/migrations/meta/_journal.json +13 -0
  37. package/src/database/schema/audit-log.schema.ts +13 -0
  38. package/src/database/schema/index.ts +1 -0
  39. package/src/defineNotificationService.ts +321 -0
  40. package/src/defineNotificationWrangler.ts +78 -0
  41. package/src/index.ts +9 -0
  42. package/src/utils/connectors.ts +1 -0
  43. package/src/utils/database/command/create-audit-log.command.ts +34 -0
  44. package/src/utils/database/command/index.ts +1 -0
  45. package/src/utils/database/index.ts +1 -0
  46. package/src/utils/email.ts +25 -0
  47. package/src/utils/index.ts +3 -0
  48. package/src/utils/sms.ts +28 -0
  49. package/test/env.d.ts +7 -0
  50. package/test/integration/sendEmail.test.ts +88 -0
  51. package/test/setup/migrations.ts +3 -0
  52. package/test/unit/connectors/ecomail.connector.ts +715 -0
  53. package/test/unit/email.test.ts +55 -0
  54. package/tsconfig.json +3 -0
  55. package/vitest.config.ts +31 -0
  56. package/worker-configuration.d.ts +25 -0
  57. package/wrangler.jsonc +199 -0
  58. package/wrangler.ts +106 -0
@@ -0,0 +1,55 @@
1
+ // import { initiateEmailConnector } from '@develit-services/notification/src/utils'
2
+ import { describe, expect, it } from 'vitest'
3
+
4
+ describe('unit placeholder', () => {
5
+ it('should pass', () => {
6
+ expect(true).toBe(true)
7
+ })
8
+ })
9
+
10
+ // describe('initiateEmailConnector', () => {
11
+ // describe('should initiate email connector when', () => {
12
+ // it('the input is valid', () => {
13
+ // const result = initiateEmailConnector(
14
+ // 'ecomail',
15
+ // '2de39f9c-d098-4cfc-93d9-5396a2f19a06',
16
+ // 'smtp.gmail.com',
17
+ // {
18
+ // email: 'example@gmail.com',
19
+ // name: undefined,
20
+ // },
21
+ // )
22
+ // expect(result).toEqual({
23
+ // API_KEY: '2de39f9c-d098-4cfc-93d9-5396a2f19a06',
24
+ // SENDER: {
25
+ // email: 'example@gmail.com',
26
+ // name: undefined,
27
+ // },
28
+ // SMTP_HOST: 'smtp.gmail.com',
29
+ // })
30
+ // })
31
+ // })
32
+
33
+ // describe('should return an error when', () => {
34
+ // it('the given email provider is not supported', () => {
35
+ // expect(
36
+ // async () =>
37
+ // await initiateEmailConnector(
38
+ // 'fakemail',
39
+ // '2de39f9c-d098-4cfc-93d9-5396a2f19a06',
40
+ // 'smtp.gmail.com',
41
+ // {
42
+ // email: 'example@gmail.com',
43
+ // name: undefined,
44
+ // },
45
+ // ),
46
+ // ).rejects.toThrowError(
47
+ // expect.objectContaining({
48
+ // code: 'UNKNOWN_ERROR',
49
+ // message: 'Unsupported email provider',
50
+ // status: 404,
51
+ // }),
52
+ // )
53
+ // })
54
+ // })
55
+ // })
package/tsconfig.json ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": "../../tsconfig.json"
3
+ }
@@ -0,0 +1,31 @@
1
+ import {
2
+ defineWorkersProject,
3
+ readD1Migrations,
4
+ } from '@cloudflare/vitest-pool-workers/config'
5
+
6
+ export default defineWorkersProject({
7
+ test: {
8
+ printConsoleTrace: true,
9
+ deps: {
10
+ optimizer: {
11
+ ssr: {
12
+ enabled: true,
13
+ include: ['@develit-io/backend-sdk'],
14
+ },
15
+ },
16
+ },
17
+ poolOptions: {
18
+ workers: {
19
+ singleWorker: true,
20
+ miniflare: {
21
+ bindings: {
22
+ MIGRATIONS: await readD1Migrations('./src/database/migrations'),
23
+ },
24
+ },
25
+ wrangler: {
26
+ configPath: './wrangler.jsonc',
27
+ },
28
+ },
29
+ },
30
+ },
31
+ })
@@ -0,0 +1,25 @@
1
+ /* eslint-disable */
2
+ // Generated by Wrangler by running `wrangler types --include-runtime false --env-interface NotificationEnv` (hash: f27bf2311bf7e2e03c649acaff98bf39)
3
+ declare namespace Cloudflare {
4
+ interface Env {
5
+ EMAIL_PROVIDER: "ecomail";
6
+ EMAIL_SENDER: {"email":"noreply@notify.develit.io","name":"develit"};
7
+ EMAIL_SMTP_HOST: "notify.develit.io";
8
+ EMAIL_API_KEY: "";
9
+ SMS_PROVIDER: "twilio";
10
+ SMS_ACCOUNT_ID: "";
11
+ SMS_AUTH_TOKEN: "";
12
+ SMS_SERVICE_ID: "";
13
+ SLACK_WEBHOOKS: [""];
14
+ ENVIRONMENT: "dev" | "test" | "staging" | "production";
15
+ NOTIFICATION_D1: D1Database;
16
+ NOTIFICATIONS_QUEUE: Queue;
17
+ }
18
+ }
19
+ interface NotificationEnv extends Cloudflare.Env {}
20
+ type StringifyValues<EnvType extends Record<string, unknown>> = {
21
+ [Binding in keyof EnvType]: EnvType[Binding] extends string ? EnvType[Binding] : string;
22
+ };
23
+ declare namespace NodeJS {
24
+ interface ProcessEnv extends StringifyValues<Pick<Cloudflare.Env, "EMAIL_PROVIDER" | "EMAIL_SENDER" | "EMAIL_SMTP_HOST" | "EMAIL_API_KEY" | "SMS_PROVIDER" | "SMS_ACCOUNT_ID" | "SMS_AUTH_TOKEN" | "SMS_SERVICE_ID" | "SLACK_WEBHOOKS" | "ENVIRONMENT">> {}
25
+ }
package/wrangler.jsonc ADDED
@@ -0,0 +1,199 @@
1
+ // ⚠️ AUTO-GENERATED FILE. DO NOT EDIT.
2
+ // To make changes, update wrangler.ts and re-run the generation script.
3
+
4
+ {
5
+ "name": "develit-notification",
6
+ "main": "./src/index.ts",
7
+ "compatibility_date": "2025-06-04",
8
+ "compatibility_flags": ["nodejs_compat"],
9
+ "d1_databases": [
10
+ {
11
+ "binding": "NOTIFICATION_D1",
12
+ "database_name": "develit-notification",
13
+ "database_id": "00000000-da3f-4c28-a72c-4cb2920f7a3e",
14
+ "migrations_dir": "./src/database/migrations"
15
+ }
16
+ ],
17
+ "queues": {
18
+ "producers": [
19
+ {
20
+ "binding": "NOTIFICATIONS_QUEUE",
21
+ "queue": "develit-notification"
22
+ }
23
+ ],
24
+ "consumers": [
25
+ {
26
+ "queue": "develit-notification",
27
+ "max_batch_size": 1,
28
+ "max_batch_timeout": 5,
29
+ "dead_letter_queue": "develit-notification-dlq"
30
+ }
31
+ ]
32
+ },
33
+ "env": {
34
+ "dev": {
35
+ "vars": {
36
+ "EMAIL_PROVIDER": "ecomail",
37
+ "EMAIL_SENDER": {
38
+ "email": "noreply@notify.develit.io",
39
+ "name": "develit"
40
+ },
41
+ "EMAIL_SMTP_HOST": "notify.develit.io",
42
+ "EMAIL_API_KEY": "",
43
+ "SMS_PROVIDER": "twilio",
44
+ "SMS_ACCOUNT_ID": "",
45
+ "SMS_AUTH_TOKEN": "",
46
+ "SMS_SERVICE_ID": "",
47
+ "SLACK_WEBHOOKS": [""],
48
+ "ENVIRONMENT": "dev"
49
+ },
50
+ "d1_databases": [
51
+ {
52
+ "binding": "NOTIFICATION_D1",
53
+ "database_name": "develit-notification-dev",
54
+ "database_id": "5ee14d35-25a8-4f6a-835d-bbb7cf335b48",
55
+ "migrations_dir": "./src/database/migrations"
56
+ }
57
+ ],
58
+ "queues": {
59
+ "producers": [
60
+ {
61
+ "binding": "NOTIFICATIONS_QUEUE",
62
+ "queue": "develit-notification-dev"
63
+ }
64
+ ],
65
+ "consumers": [
66
+ {
67
+ "queue": "develit-notification-dev",
68
+ "max_batch_size": 1,
69
+ "max_batch_timeout": 5,
70
+ "dead_letter_queue": "develit-notification-dlq-dev"
71
+ }
72
+ ]
73
+ }
74
+ },
75
+ "test": {
76
+ "vars": {
77
+ "EMAIL_PROVIDER": "ecomail",
78
+ "EMAIL_SENDER": {
79
+ "email": "noreply@notify.develit.io",
80
+ "name": "develit"
81
+ },
82
+ "EMAIL_SMTP_HOST": "notify.develit.io",
83
+ "EMAIL_API_KEY": "",
84
+ "SMS_PROVIDER": "twilio",
85
+ "SMS_ACCOUNT_ID": "",
86
+ "SMS_AUTH_TOKEN": "",
87
+ "SMS_SERVICE_ID": "",
88
+ "SLACK_WEBHOOKS": [""],
89
+ "ENVIRONMENT": "test"
90
+ },
91
+ "d1_databases": [
92
+ {
93
+ "binding": "NOTIFICATION_D1",
94
+ "database_name": "develit-notification-test",
95
+ "database_id": "aa97cfa8-bf12-4e0d-837d-ef14e716db0d",
96
+ "migrations_dir": "./src/database/migrations"
97
+ }
98
+ ],
99
+ "queues": {
100
+ "producers": [
101
+ {
102
+ "binding": "NOTIFICATIONS_QUEUE",
103
+ "queue": "develit-notification-test"
104
+ }
105
+ ],
106
+ "consumers": [
107
+ {
108
+ "queue": "develit-notification-test",
109
+ "max_batch_size": 1,
110
+ "max_batch_timeout": 5,
111
+ "dead_letter_queue": "develit-notification-dlq-test"
112
+ }
113
+ ]
114
+ }
115
+ },
116
+ "staging": {
117
+ "vars": {
118
+ "EMAIL_PROVIDER": "ecomail",
119
+ "EMAIL_SENDER": {
120
+ "email": "noreply@notify.develit.io",
121
+ "name": "develit"
122
+ },
123
+ "EMAIL_SMTP_HOST": "notify.develit.io",
124
+ "EMAIL_API_KEY": "",
125
+ "SMS_PROVIDER": "twilio",
126
+ "SMS_ACCOUNT_ID": "",
127
+ "SMS_AUTH_TOKEN": "",
128
+ "SMS_SERVICE_ID": "",
129
+ "SLACK_WEBHOOKS": [""],
130
+ "ENVIRONMENT": "staging"
131
+ },
132
+ "d1_databases": [
133
+ {
134
+ "binding": "NOTIFICATION_D1",
135
+ "database_name": "develit-notification-staging",
136
+ "database_id": "38ada081-b75d-4814-b162-02e89baa6e35",
137
+ "migrations_dir": "./src/database/migrations"
138
+ }
139
+ ],
140
+ "queues": {
141
+ "producers": [
142
+ {
143
+ "binding": "NOTIFICATIONS_QUEUE",
144
+ "queue": "develit-notification-staging"
145
+ }
146
+ ],
147
+ "consumers": [
148
+ {
149
+ "queue": "develit-notification-staging",
150
+ "max_batch_size": 1,
151
+ "max_batch_timeout": 5,
152
+ "dead_letter_queue": "develit-notification-dlq-staging"
153
+ }
154
+ ]
155
+ }
156
+ },
157
+ "production": {
158
+ "vars": {
159
+ "EMAIL_PROVIDER": "ecomail",
160
+ "EMAIL_SENDER": {
161
+ "email": "noreply@notify.develit.io",
162
+ "name": "develit"
163
+ },
164
+ "EMAIL_SMTP_HOST": "notify.develit.io",
165
+ "EMAIL_API_KEY": "",
166
+ "SMS_PROVIDER": "twilio",
167
+ "SMS_ACCOUNT_ID": "",
168
+ "SMS_AUTH_TOKEN": "",
169
+ "SMS_SERVICE_ID": "",
170
+ "SLACK_WEBHOOKS": [""],
171
+ "ENVIRONMENT": "production"
172
+ },
173
+ "d1_databases": [
174
+ {
175
+ "binding": "NOTIFICATION_D1",
176
+ "database_name": "develit-notification-production",
177
+ "database_id": "a1b7886f-cba5-46da-871b-8a02ec50c8c4",
178
+ "migrations_dir": "./src/database/migrations"
179
+ }
180
+ ],
181
+ "queues": {
182
+ "producers": [
183
+ {
184
+ "binding": "NOTIFICATIONS_QUEUE",
185
+ "queue": "develit-notification-production"
186
+ }
187
+ ],
188
+ "consumers": [
189
+ {
190
+ "queue": "develit-notification-production",
191
+ "max_batch_size": 1,
192
+ "max_batch_timeout": 5,
193
+ "dead_letter_queue": "develit-notification-dlq-production"
194
+ }
195
+ ]
196
+ }
197
+ }
198
+ }
199
+ }
package/wrangler.ts ADDED
@@ -0,0 +1,106 @@
1
+ import { defineNotificationServiceWrangler } from './src/defineNotificationWrangler'
2
+
3
+ export default defineNotificationServiceWrangler({
4
+ name: 'develit-notification',
5
+ envs: {
6
+ local: {
7
+ d1: {
8
+ id: '00000000-da3f-4c28-a72c-4cb2920f7a3e',
9
+ },
10
+ vars: {
11
+ EMAIL_PROVIDER: 'ecomail',
12
+ EMAIL_SENDER: {
13
+ email: 'noreply@notify.develit.io',
14
+ name: 'develit',
15
+ },
16
+ EMAIL_SMTP_HOST: 'notify.develit.io',
17
+ EMAIL_API_KEY: '',
18
+ SMS_PROVIDER: 'twilio',
19
+ SMS_ACCOUNT_ID: '',
20
+ SMS_AUTH_TOKEN: '',
21
+ SMS_SERVICE_ID: '',
22
+ SLACK_WEBHOOKS: [''],
23
+ },
24
+ },
25
+ dev: {
26
+ d1: {
27
+ id: '5ee14d35-25a8-4f6a-835d-bbb7cf335b48',
28
+ },
29
+ vars: {
30
+ EMAIL_PROVIDER: 'ecomail',
31
+ EMAIL_SENDER: {
32
+ email: 'noreply@notify.develit.io',
33
+ name: 'develit',
34
+ },
35
+ EMAIL_SMTP_HOST: 'notify.develit.io',
36
+ EMAIL_API_KEY: '',
37
+ SMS_PROVIDER: 'twilio',
38
+ SMS_ACCOUNT_ID: '',
39
+ SMS_AUTH_TOKEN: '',
40
+ SMS_SERVICE_ID: '',
41
+ SLACK_WEBHOOKS: [''],
42
+ },
43
+ },
44
+ test: {
45
+ d1: {
46
+ id: 'aa97cfa8-bf12-4e0d-837d-ef14e716db0d',
47
+ },
48
+ vars: {
49
+ EMAIL_PROVIDER: 'ecomail',
50
+ EMAIL_SENDER: {
51
+ email: 'noreply@notify.develit.io',
52
+ name: 'develit',
53
+ },
54
+ EMAIL_SMTP_HOST: 'notify.develit.io',
55
+ EMAIL_API_KEY: '',
56
+ SMS_PROVIDER: 'twilio',
57
+ SMS_ACCOUNT_ID: '',
58
+ SMS_AUTH_TOKEN: '',
59
+ SMS_SERVICE_ID: '',
60
+ SLACK_WEBHOOKS: [''],
61
+ },
62
+ },
63
+ staging: {
64
+ d1: {
65
+ id: '38ada081-b75d-4814-b162-02e89baa6e35',
66
+ },
67
+ queue: {
68
+ max_batch_size: 1,
69
+ max_batch_timeout: 5,
70
+ },
71
+ vars: {
72
+ EMAIL_PROVIDER: 'ecomail',
73
+ EMAIL_SENDER: {
74
+ email: 'noreply@notify.develit.io',
75
+ name: 'develit',
76
+ },
77
+ EMAIL_SMTP_HOST: 'notify.develit.io',
78
+ EMAIL_API_KEY: '',
79
+ SMS_PROVIDER: 'twilio',
80
+ SMS_ACCOUNT_ID: '',
81
+ SMS_AUTH_TOKEN: '',
82
+ SMS_SERVICE_ID: '',
83
+ SLACK_WEBHOOKS: [''],
84
+ },
85
+ },
86
+ production: {
87
+ d1: {
88
+ id: 'a1b7886f-cba5-46da-871b-8a02ec50c8c4',
89
+ },
90
+ vars: {
91
+ EMAIL_PROVIDER: 'ecomail',
92
+ EMAIL_SENDER: {
93
+ email: 'noreply@notify.develit.io',
94
+ name: 'develit',
95
+ },
96
+ EMAIL_SMTP_HOST: 'notify.develit.io',
97
+ EMAIL_API_KEY: '',
98
+ SMS_PROVIDER: 'twilio',
99
+ SMS_ACCOUNT_ID: '',
100
+ SMS_AUTH_TOKEN: '',
101
+ SMS_SERVICE_ID: '',
102
+ SLACK_WEBHOOKS: [''],
103
+ },
104
+ },
105
+ },
106
+ })