@develit-services/notification 0.0.2 → 0.0.3
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/@types/email/IEmail.connector.ts +1 -1
- package/@types/email/ecomail/ecomail.connector.ts +1 -2
- package/@types/io/sendEmail.ts +1 -1
- package/@types/queue.ts +1 -6
- package/@types/sms/ISms.connector.ts +1 -1
- package/@types/sms/twilio/twilio.connector.ts +1 -2
- package/CHANGELOG.md +4 -0
- package/build.config.ts +1 -0
- package/package.json +12 -1
- package/src/database/schema/audit-log.schema.ts +1 -1
- package/src/defineNotificationService.ts +14 -7
- package/src/index.ts +3 -0
- package/src/utils/database/command/create-audit-log.command.ts +2 -2
- package/src/utils/email.ts +1 -1
- package/src/utils/sms.ts +1 -4
- package/test/unit/connectors/ecomail.connector.ts +1 -1
- package/wrangler.jsonc +16 -6
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { useResult } from '@develit-io/backend-sdk'
|
|
2
|
-
// TODO: Tests fail when imported as from '@services/notification/@types'`
|
|
3
2
|
import {
|
|
4
3
|
type EMAttachment,
|
|
5
4
|
type EMContact,
|
|
@@ -7,7 +6,7 @@ import {
|
|
|
7
6
|
type IContact,
|
|
8
7
|
type IEmail,
|
|
9
8
|
IEmailConnector,
|
|
10
|
-
} from '
|
|
9
|
+
} from '../../email'
|
|
11
10
|
|
|
12
11
|
export class EcomailConnector extends IEmailConnector {
|
|
13
12
|
static providerName = 'ecomail'
|
package/@types/io/sendEmail.ts
CHANGED
package/@types/queue.ts
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
IEmail,
|
|
3
|
-
IPushNotification,
|
|
4
|
-
ISlack,
|
|
5
|
-
ISms,
|
|
6
|
-
} from '@services/notification/@types'
|
|
1
|
+
import type { IEmail, IPushNotification, ISlack, ISms } from './'
|
|
7
2
|
|
|
8
3
|
export interface NotificationQueueMessage {
|
|
9
4
|
type: 'email' | 'sms' | 'pushNotification' | 'slack'
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
// TODO: Tests fail when imported as from '@services/notification/@types'`
|
|
2
1
|
import {
|
|
3
2
|
type InternalError,
|
|
4
3
|
createInternalError,
|
|
5
4
|
} from '@develit-io/backend-sdk'
|
|
6
|
-
import { type ISms, ISmsConnector } from '
|
|
5
|
+
import { type ISms, ISmsConnector } from '../'
|
|
7
6
|
import twilio from 'twilio'
|
|
8
7
|
|
|
9
8
|
export class TwilioConnector extends ISmsConnector {
|
package/CHANGELOG.md
CHANGED
package/build.config.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@develit-services/notification",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"author": "Develit.io s.r.o.",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./dist/src.mjs",
|
|
9
|
+
"require": "./dist/src.cjs",
|
|
10
|
+
"types": "./dist/src.d.ts"
|
|
11
|
+
},
|
|
12
|
+
"./package.json": "./package.json"
|
|
13
|
+
},
|
|
14
|
+
"bin": {
|
|
15
|
+
"notification-wrangler": "./scripts/generate-wrangler.ts"
|
|
16
|
+
},
|
|
6
17
|
"scripts": {
|
|
7
18
|
"postinstall": "bun cf:typegen",
|
|
8
19
|
"wrangler:generate": "bun ./scripts/generate-wrangler.ts",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { base } from '@develit-io/backend-sdk'
|
|
2
|
-
import type { AuditLogEventType } from '
|
|
2
|
+
import type { AuditLogEventType } from '../../../@types'
|
|
3
3
|
import { sqliteTable, text } from 'drizzle-orm/sqlite-core'
|
|
4
4
|
|
|
5
5
|
export const auditLog = sqliteTable('audit_log', {
|
|
@@ -20,13 +20,13 @@ import {
|
|
|
20
20
|
sendEmailInputSchema,
|
|
21
21
|
sendSlackInputSchema,
|
|
22
22
|
sendSmsInputSchema,
|
|
23
|
-
} from '
|
|
24
|
-
import { tables } from '
|
|
23
|
+
} from '../@types'
|
|
24
|
+
import { tables } from './database/drizzle'
|
|
25
25
|
import {
|
|
26
26
|
createAuditLogCommand,
|
|
27
27
|
initiateEmailConnector,
|
|
28
28
|
initiateSmsConnector,
|
|
29
|
-
} from '
|
|
29
|
+
} from './utils'
|
|
30
30
|
import { WorkerEntrypoint } from 'cloudflare:workers'
|
|
31
31
|
import { type DrizzleD1Database, drizzle } from 'drizzle-orm/d1'
|
|
32
32
|
import { SlackConnector } from '../@types/slack/slack.connector'
|
|
@@ -120,6 +120,10 @@ export class NotificationServiceBase extends develitWorker(
|
|
|
120
120
|
metadata,
|
|
121
121
|
})
|
|
122
122
|
break
|
|
123
|
+
default:
|
|
124
|
+
this.logError({ error: `Unknown notification type: ${type}` })
|
|
125
|
+
message.retry()
|
|
126
|
+
continue
|
|
123
127
|
}
|
|
124
128
|
|
|
125
129
|
const { error, message: errorMessage } = await notificationAction()
|
|
@@ -135,7 +139,7 @@ export class NotificationServiceBase extends develitWorker(
|
|
|
135
139
|
}
|
|
136
140
|
|
|
137
141
|
@action('private-send-email')
|
|
138
|
-
|
|
142
|
+
protected async _sendEmail(
|
|
139
143
|
input: SendEmailInput,
|
|
140
144
|
): Promise<IRPCResponse<SendEmailOutput>> {
|
|
141
145
|
return this.handleAction(
|
|
@@ -189,7 +193,7 @@ export class NotificationServiceBase extends develitWorker(
|
|
|
189
193
|
}
|
|
190
194
|
|
|
191
195
|
@action('private-send-sms')
|
|
192
|
-
|
|
196
|
+
protected async _sendSms(
|
|
193
197
|
input: SendSmsInput,
|
|
194
198
|
): Promise<IRPCResponse<SendSmsOutput>> {
|
|
195
199
|
return this.handleAction(
|
|
@@ -284,7 +288,7 @@ export class NotificationServiceBase extends develitWorker(
|
|
|
284
288
|
}
|
|
285
289
|
|
|
286
290
|
@action('send-push-notification')
|
|
287
|
-
|
|
291
|
+
protected async _sendPushNotification(): Promise<IRPCResponse<{}>> {
|
|
288
292
|
this.logInput({})
|
|
289
293
|
|
|
290
294
|
this.logError({ error: 'Method not implemented.' })
|
|
@@ -312,7 +316,10 @@ export class NotificationServiceBase extends develitWorker(
|
|
|
312
316
|
}
|
|
313
317
|
}
|
|
314
318
|
|
|
315
|
-
export function defineNotificationService()
|
|
319
|
+
export function defineNotificationService(): new (
|
|
320
|
+
ctx: ExecutionContext,
|
|
321
|
+
env: NotificationEnv,
|
|
322
|
+
) => NotificationServiceBase {
|
|
316
323
|
return class NotificationService extends NotificationServiceBase {
|
|
317
324
|
constructor(ctx: ExecutionContext, env: NotificationEnv) {
|
|
318
325
|
super(ctx, env)
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { defineNotificationService } from './defineNotificationService'
|
|
2
|
+
import { defineNotificationServiceWrangler } from './defineNotificationWrangler'
|
|
2
3
|
import type { WorkerEntrypoint } from 'cloudflare:workers'
|
|
3
4
|
|
|
4
5
|
const NotificationService = defineNotificationService()
|
|
@@ -7,3 +8,5 @@ export default NotificationService as new (
|
|
|
7
8
|
ctx: ExecutionContext,
|
|
8
9
|
env: NotificationEnv,
|
|
9
10
|
) => WorkerEntrypoint<NotificationEnv>
|
|
11
|
+
|
|
12
|
+
export { defineNotificationService, defineNotificationServiceWrangler }
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { uuidv4 } from '@develit-io/backend-sdk'
|
|
2
|
-
import type { AuditLogInsertType } from '
|
|
3
|
-
import { tables } from '
|
|
2
|
+
import type { AuditLogInsertType } from '../../../../@types'
|
|
3
|
+
import { tables } from '../../../database/drizzle'
|
|
4
4
|
import type { DrizzleD1Database } from 'drizzle-orm/d1'
|
|
5
5
|
|
|
6
6
|
export const createAuditLogCommand = async ({
|
package/src/utils/email.ts
CHANGED
package/src/utils/sms.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { createInternalError } from '@develit-io/backend-sdk'
|
|
2
|
-
import {
|
|
3
|
-
type ISmsConnector,
|
|
4
|
-
TwilioConnector,
|
|
5
|
-
} from '@services/notification/@types/sms'
|
|
2
|
+
import { type ISmsConnector, TwilioConnector } from '../../@types'
|
|
6
3
|
|
|
7
4
|
export const initiateSmsConnector = async (
|
|
8
5
|
provider: string,
|
package/wrangler.jsonc
CHANGED
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
"name": "develit-notification",
|
|
6
6
|
"main": "./src/index.ts",
|
|
7
7
|
"compatibility_date": "2025-06-04",
|
|
8
|
-
"compatibility_flags": [
|
|
8
|
+
"compatibility_flags": [
|
|
9
|
+
"nodejs_compat"
|
|
10
|
+
],
|
|
9
11
|
"d1_databases": [
|
|
10
12
|
{
|
|
11
13
|
"binding": "NOTIFICATION_D1",
|
|
@@ -44,7 +46,9 @@
|
|
|
44
46
|
"SMS_ACCOUNT_ID": "",
|
|
45
47
|
"SMS_AUTH_TOKEN": "",
|
|
46
48
|
"SMS_SERVICE_ID": "",
|
|
47
|
-
"SLACK_WEBHOOKS": [
|
|
49
|
+
"SLACK_WEBHOOKS": [
|
|
50
|
+
""
|
|
51
|
+
],
|
|
48
52
|
"ENVIRONMENT": "dev"
|
|
49
53
|
},
|
|
50
54
|
"d1_databases": [
|
|
@@ -85,7 +89,9 @@
|
|
|
85
89
|
"SMS_ACCOUNT_ID": "",
|
|
86
90
|
"SMS_AUTH_TOKEN": "",
|
|
87
91
|
"SMS_SERVICE_ID": "",
|
|
88
|
-
"SLACK_WEBHOOKS": [
|
|
92
|
+
"SLACK_WEBHOOKS": [
|
|
93
|
+
""
|
|
94
|
+
],
|
|
89
95
|
"ENVIRONMENT": "test"
|
|
90
96
|
},
|
|
91
97
|
"d1_databases": [
|
|
@@ -126,7 +132,9 @@
|
|
|
126
132
|
"SMS_ACCOUNT_ID": "",
|
|
127
133
|
"SMS_AUTH_TOKEN": "",
|
|
128
134
|
"SMS_SERVICE_ID": "",
|
|
129
|
-
"SLACK_WEBHOOKS": [
|
|
135
|
+
"SLACK_WEBHOOKS": [
|
|
136
|
+
""
|
|
137
|
+
],
|
|
130
138
|
"ENVIRONMENT": "staging"
|
|
131
139
|
},
|
|
132
140
|
"d1_databases": [
|
|
@@ -167,7 +175,9 @@
|
|
|
167
175
|
"SMS_ACCOUNT_ID": "",
|
|
168
176
|
"SMS_AUTH_TOKEN": "",
|
|
169
177
|
"SMS_SERVICE_ID": "",
|
|
170
|
-
"SLACK_WEBHOOKS": [
|
|
178
|
+
"SLACK_WEBHOOKS": [
|
|
179
|
+
""
|
|
180
|
+
],
|
|
171
181
|
"ENVIRONMENT": "production"
|
|
172
182
|
},
|
|
173
183
|
"d1_databases": [
|
|
@@ -196,4 +206,4 @@
|
|
|
196
206
|
}
|
|
197
207
|
}
|
|
198
208
|
}
|
|
199
|
-
}
|
|
209
|
+
}
|