@develit-services/notification 0.0.14 → 0.0.16
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/dist/database/schema.cjs +9 -0
- package/dist/database/schema.d.cts +2 -0
- package/dist/database/schema.d.mts +2 -0
- package/dist/database/schema.d.ts +2 -0
- package/dist/database/schema.mjs +3 -0
- package/dist/export/worker.cjs +41 -41
- package/dist/export/worker.d.cts +2 -201
- package/dist/export/worker.d.mts +2 -201
- package/dist/export/worker.d.ts +2 -201
- package/dist/export/worker.mjs +41 -41
- package/dist/shared/notification.4b3eUEIG.cjs +22 -0
- package/dist/shared/notification.BJyMXKGH.d.cts +203 -0
- package/dist/shared/notification.BJyMXKGH.d.mts +203 -0
- package/dist/shared/notification.BJyMXKGH.d.ts +203 -0
- package/dist/shared/notification.C0X8Orrh.mjs +19 -0
- package/package.json +5 -5
- package/@types/consts/audit-log.consts.ts +0 -7
- package/@types/consts/index.ts +0 -1
- package/@types/database/audit-log.types.ts +0 -7
- package/@types/database/index.ts +0 -1
- package/@types/email/IEmail.connector.ts +0 -21
- package/@types/email/IEmail.types.ts +0 -25
- package/@types/email/ecomail/ecomail.connector.ts +0 -139
- package/@types/email/ecomail/ecomail.types.ts +0 -27
- package/@types/email/ecomail/index.ts +0 -2
- package/@types/email/index.ts +0 -3
- package/@types/index.ts +0 -9
- package/@types/io/index.ts +0 -3
- package/@types/io/sendEmail.ts +0 -18
- package/@types/io/sendSlack.ts +0 -19
- package/@types/io/sendSms.ts +0 -20
- package/@types/pushNotification/IPushNotification.ts +0 -1
- package/@types/pushNotification/index.ts +0 -1
- package/@types/queue.ts +0 -19
- package/@types/service.ts +0 -30
- package/@types/slack/ISlack.types.ts +0 -3
- package/@types/slack/index.ts +0 -1
- package/@types/slack/slack.connector.ts +0 -27
- package/@types/sms/ISms.connector.ts +0 -22
- package/@types/sms/ISms.types.ts +0 -4
- package/@types/sms/index.ts +0 -3
- package/@types/sms/twilio/index.ts +0 -1
- package/@types/sms/twilio/twilio.connector.ts +0 -35
- package/src/database/schema/audit-log.schema.ts +0 -13
- package/src/database/schema/index.ts +0 -1
package/@types/email/index.ts
DELETED
package/@types/index.ts
DELETED
package/@types/io/index.ts
DELETED
package/@types/io/sendEmail.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { iEmailSchema } from '../'
|
|
2
|
-
import z from 'zod'
|
|
3
|
-
|
|
4
|
-
export const sendEmailInputSchema = z.object({
|
|
5
|
-
email: iEmailSchema,
|
|
6
|
-
metadata: z.object({
|
|
7
|
-
userAgent: z.string().optional(),
|
|
8
|
-
ip: z.ipv4().or(z.ipv6()).optional(),
|
|
9
|
-
initiator: z.object({
|
|
10
|
-
service: z.string(),
|
|
11
|
-
userId: z.string().optional(),
|
|
12
|
-
}),
|
|
13
|
-
}),
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
export interface SendEmailInput extends z.infer<typeof sendEmailInputSchema> {}
|
|
17
|
-
|
|
18
|
-
export interface SendEmailOutput {}
|
package/@types/io/sendSlack.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod/v4'
|
|
2
|
-
|
|
3
|
-
export const sendSlackInputSchema = z.object({
|
|
4
|
-
slack: z.object({
|
|
5
|
-
message: z.string(),
|
|
6
|
-
}),
|
|
7
|
-
metadata: z.object({
|
|
8
|
-
userAgent: z.string().optional(),
|
|
9
|
-
ip: z.ipv4().or(z.ipv6()).optional(),
|
|
10
|
-
initiator: z.object({
|
|
11
|
-
service: z.string(),
|
|
12
|
-
userId: z.string().optional(),
|
|
13
|
-
}),
|
|
14
|
-
}),
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
export interface SendSlackInput extends z.infer<typeof sendSlackInputSchema> {}
|
|
18
|
-
|
|
19
|
-
export interface SendSlackOutput {}
|
package/@types/io/sendSms.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod'
|
|
2
|
-
|
|
3
|
-
export const sendSmsInputSchema = z.object({
|
|
4
|
-
sms: z.object({
|
|
5
|
-
message: z.string(),
|
|
6
|
-
to: z.string(),
|
|
7
|
-
}),
|
|
8
|
-
metadata: z.object({
|
|
9
|
-
userAgent: z.string().optional(),
|
|
10
|
-
ip: z.ipv4().or(z.ipv6()).optional(),
|
|
11
|
-
initiator: z.object({
|
|
12
|
-
service: z.string(),
|
|
13
|
-
userId: z.string().optional(),
|
|
14
|
-
}),
|
|
15
|
-
}),
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
export interface SendSmsInput extends z.infer<typeof sendSmsInputSchema> {}
|
|
19
|
-
|
|
20
|
-
export interface SendSmsOutput {}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export interface IPushNotification {}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './IPushNotification'
|
package/@types/queue.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { IEmail, IPushNotification, ISlack, ISms } from './'
|
|
2
|
-
|
|
3
|
-
export interface NotificationQueueMessage {
|
|
4
|
-
type: 'email' | 'sms' | 'pushNotification' | 'slack'
|
|
5
|
-
metadata: {
|
|
6
|
-
userAgent?: string
|
|
7
|
-
ip?: string
|
|
8
|
-
initiator: {
|
|
9
|
-
service: string
|
|
10
|
-
userId?: string
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
payload: {
|
|
14
|
-
email?: IEmail
|
|
15
|
-
sms?: ISms
|
|
16
|
-
pushNotification?: IPushNotification
|
|
17
|
-
slack?: ISlack
|
|
18
|
-
}
|
|
19
|
-
}
|
package/@types/service.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export interface NotificationServiceEnvironmentConfig {
|
|
2
|
-
queue?: {
|
|
3
|
-
max_batch_size?: number
|
|
4
|
-
max_batch_timeout?: number
|
|
5
|
-
}
|
|
6
|
-
d1: {
|
|
7
|
-
id: string
|
|
8
|
-
}
|
|
9
|
-
vars: {
|
|
10
|
-
EMAIL_PROVIDER: 'ecomail'
|
|
11
|
-
EMAIL_SENDER: { name: string; email: string }
|
|
12
|
-
EMAIL_SMTP_HOST: string
|
|
13
|
-
EMAIL_API_KEY: string
|
|
14
|
-
SMS_PROVIDER: 'twilio'
|
|
15
|
-
SMS_ACCOUNT_ID: string
|
|
16
|
-
SMS_AUTH_TOKEN: string
|
|
17
|
-
SMS_SERVICE_ID: string | number
|
|
18
|
-
SLACK_WEBHOOKS: [string]
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface NotificationServiceWranglerConfig {
|
|
23
|
-
name: string
|
|
24
|
-
envs: {
|
|
25
|
-
local: NotificationServiceEnvironmentConfig
|
|
26
|
-
[key: string]: NotificationServiceEnvironmentConfig
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface NotificationServiceEnv extends NotificationEnv {}
|
package/@types/slack/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './ISlack.types'
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export class SlackConnector {
|
|
2
|
-
private webhooks: string[]
|
|
3
|
-
|
|
4
|
-
constructor(webhooks: string[]) {
|
|
5
|
-
this.webhooks = webhooks
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
async sendNotificationToAllSlack(message: string) {
|
|
9
|
-
const controller = new AbortController()
|
|
10
|
-
const timeoutId = setTimeout(() => controller.abort(), 3000)
|
|
11
|
-
|
|
12
|
-
for (const webhook of this.webhooks) {
|
|
13
|
-
let response = await fetch(webhook, {
|
|
14
|
-
method: 'POST',
|
|
15
|
-
body: JSON.stringify({ text: message }),
|
|
16
|
-
headers: { 'Content-Type': 'application/json' },
|
|
17
|
-
signal: controller.signal,
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
clearTimeout(timeoutId)
|
|
21
|
-
|
|
22
|
-
if (!response.ok) {
|
|
23
|
-
throw new Error('Failed sending Slack notification to ' + message)
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { InternalError } from '@develit-io/backend-sdk'
|
|
2
|
-
import type { ISms } from '../'
|
|
3
|
-
|
|
4
|
-
export abstract class ISmsConnector {
|
|
5
|
-
static providerName: string
|
|
6
|
-
|
|
7
|
-
public ACCOUNT_ID: string
|
|
8
|
-
public AUTH_TOKEN: string
|
|
9
|
-
public SERVICE_ID: string
|
|
10
|
-
|
|
11
|
-
protected constructor({
|
|
12
|
-
ACCOUNT_ID,
|
|
13
|
-
AUTH_TOKEN,
|
|
14
|
-
SERVICE_ID,
|
|
15
|
-
}: { ACCOUNT_ID: string; AUTH_TOKEN: string; SERVICE_ID: string }) {
|
|
16
|
-
this.ACCOUNT_ID = ACCOUNT_ID
|
|
17
|
-
this.AUTH_TOKEN = AUTH_TOKEN
|
|
18
|
-
this.SERVICE_ID = SERVICE_ID
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
abstract sendSms(sms: ISms): Promise<InternalError | void>
|
|
22
|
-
}
|
package/@types/sms/ISms.types.ts
DELETED
package/@types/sms/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './twilio.connector'
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type InternalError,
|
|
3
|
-
createInternalError,
|
|
4
|
-
} from '@develit-io/backend-sdk'
|
|
5
|
-
import { type ISms, ISmsConnector } from '../'
|
|
6
|
-
import twilio from 'twilio'
|
|
7
|
-
|
|
8
|
-
export class TwilioConnector extends ISmsConnector {
|
|
9
|
-
static providerName = 'twilio'
|
|
10
|
-
|
|
11
|
-
readonly twilioClient: twilio.Twilio
|
|
12
|
-
|
|
13
|
-
constructor({
|
|
14
|
-
ACCOUNT_ID,
|
|
15
|
-
AUTH_TOKEN,
|
|
16
|
-
SERVICE_ID,
|
|
17
|
-
}: { ACCOUNT_ID: string; AUTH_TOKEN: string; SERVICE_ID: string }) {
|
|
18
|
-
super({ ACCOUNT_ID, AUTH_TOKEN, SERVICE_ID })
|
|
19
|
-
this.twilioClient = twilio(ACCOUNT_ID, AUTH_TOKEN)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async sendSms(sms: ISms): Promise<InternalError | void> {
|
|
23
|
-
const message = await this.twilioClient.messages.create({
|
|
24
|
-
body: sms.message,
|
|
25
|
-
messagingServiceSid: this.SERVICE_ID,
|
|
26
|
-
to: sms.to,
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
if (message.errorMessage)
|
|
30
|
-
return createInternalError(null, {
|
|
31
|
-
message: message.errorMessage,
|
|
32
|
-
status: message.errorCode,
|
|
33
|
-
})
|
|
34
|
-
}
|
|
35
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { base } from '@develit-io/backend-sdk'
|
|
2
|
-
import type { AuditLogEventType } from '../../../@types'
|
|
3
|
-
import { sqliteTable, text } from 'drizzle-orm/sqlite-core'
|
|
4
|
-
|
|
5
|
-
export const auditLog = sqliteTable('audit_log', {
|
|
6
|
-
...base,
|
|
7
|
-
event: text('event').$type<AuditLogEventType>().notNull(),
|
|
8
|
-
ip: text('ip'),
|
|
9
|
-
userAgent: text('user_agent'),
|
|
10
|
-
description: text('description'),
|
|
11
|
-
initiatorService: text('initiator_service').notNull(),
|
|
12
|
-
initiatorUserId: text('initiator_user_id'),
|
|
13
|
-
})
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './audit-log.schema'
|