@develit-services/notification 0.0.19 → 0.0.20
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/@types.cjs +25 -0
- package/dist/@types.d.cts +70 -0
- package/dist/@types.d.mts +70 -0
- package/dist/@types.d.ts +70 -0
- package/dist/@types.mjs +14 -0
- package/dist/export/worker.cjs +11 -214
- package/dist/export/worker.d.cts +4 -196
- package/dist/export/worker.d.mts +4 -196
- package/dist/export/worker.d.ts +4 -196
- package/dist/export/worker.mjs +5 -203
- package/dist/export/wrangler.d.cts +1 -28
- package/dist/export/wrangler.d.mts +1 -28
- package/dist/export/wrangler.d.ts +1 -28
- package/dist/shared/notification.B2I1pTPy.d.cts +32 -0
- package/dist/shared/notification.B2I1pTPy.d.mts +32 -0
- package/dist/shared/notification.B2I1pTPy.d.ts +32 -0
- package/dist/shared/notification.B8IIgYsS.cjs +220 -0
- package/dist/shared/notification.Bc0Z2CT6.d.cts +199 -0
- package/dist/shared/notification.Bc0Z2CT6.d.mts +199 -0
- package/dist/shared/notification.Bc0Z2CT6.d.ts +199 -0
- package/dist/shared/notification.D1sgZDH0.mjs +205 -0
- package/package.json +6 -1
package/dist/@types.cjs
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const twilio_connector = require('./shared/notification.B8IIgYsS.cjs');
|
|
4
|
+
require('zod');
|
|
5
|
+
require('@develit-io/backend-sdk');
|
|
6
|
+
require('zod/v4');
|
|
7
|
+
require('twilio');
|
|
8
|
+
|
|
9
|
+
const AUDIT_LOG_EVENT_TYPES = [
|
|
10
|
+
"EMAIL",
|
|
11
|
+
"SMS",
|
|
12
|
+
"PUSH_NOTIFICATION",
|
|
13
|
+
"SLACK"
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
exports.EcomailConnector = twilio_connector.EcomailConnector;
|
|
17
|
+
exports.IEmailConnector = twilio_connector.IEmailConnector;
|
|
18
|
+
exports.ISmsConnector = twilio_connector.ISmsConnector;
|
|
19
|
+
exports.TwilioConnector = twilio_connector.TwilioConnector;
|
|
20
|
+
exports.iContactSchema = twilio_connector.iContactSchema;
|
|
21
|
+
exports.iEmailSchema = twilio_connector.iEmailSchema;
|
|
22
|
+
exports.sendEmailInputSchema = twilio_connector.sendEmailInputSchema;
|
|
23
|
+
exports.sendSlackInputSchema = twilio_connector.sendSlackInputSchema;
|
|
24
|
+
exports.sendSmsInputSchema = twilio_connector.sendSmsInputSchema;
|
|
25
|
+
exports.AUDIT_LOG_EVENT_TYPES = AUDIT_LOG_EVENT_TYPES;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { I as IEmailConnector, g as IContact, h as IEmail, a as ISmsConnector, i as ISms } from './shared/notification.Bc0Z2CT6.cjs';
|
|
2
|
+
export { n as IPushNotification, o as ISlack, N as NotificationQueueMessage, S as SendEmailInput, b as SendEmailOutput, e as SendSlackInput, f as SendSlackOutput, c as SendSmsInput, d as SendSmsOutput, j as iContactSchema, k as iEmailSchema, s as sendEmailInputSchema, l as sendSlackInputSchema, m as sendSmsInputSchema } from './shared/notification.Bc0Z2CT6.cjs';
|
|
3
|
+
import { InternalError } from '@develit-io/backend-sdk';
|
|
4
|
+
import twilio from 'twilio';
|
|
5
|
+
import { tables } from '@services/notification/src/database/drizzle';
|
|
6
|
+
import { InferSelectModel, InferInsertModel } from 'drizzle-orm';
|
|
7
|
+
export { b as NotificationServiceEnv, a as NotificationServiceEnvironmentConfig, N as NotificationServiceWranglerConfig } from './shared/notification.B2I1pTPy.cjs';
|
|
8
|
+
import 'zod';
|
|
9
|
+
import 'zod/v4';
|
|
10
|
+
|
|
11
|
+
declare class EcomailConnector extends IEmailConnector {
|
|
12
|
+
static providerName: string;
|
|
13
|
+
constructor({ API_KEY, SMTP_HOST, SENDER, }: {
|
|
14
|
+
API_KEY: string;
|
|
15
|
+
SMTP_HOST: string;
|
|
16
|
+
SENDER: IContact;
|
|
17
|
+
});
|
|
18
|
+
sendEmail(email: IEmail): Promise<void>;
|
|
19
|
+
protected convertEmail(email: IEmail): EMEmail;
|
|
20
|
+
protected convertContacts(contacts: IContact | IContact[]): EMContact[];
|
|
21
|
+
protected convertContact(contact: IContact): EMContact;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface EMContact {
|
|
25
|
+
email: string;
|
|
26
|
+
name?: string;
|
|
27
|
+
cc?: string;
|
|
28
|
+
bcc?: string;
|
|
29
|
+
}
|
|
30
|
+
interface EMAttachment {
|
|
31
|
+
type: string;
|
|
32
|
+
name: string;
|
|
33
|
+
content: string;
|
|
34
|
+
}
|
|
35
|
+
interface EMEmail {
|
|
36
|
+
message: {
|
|
37
|
+
template_id?: number;
|
|
38
|
+
subject: string;
|
|
39
|
+
from_name: string;
|
|
40
|
+
from_email: string;
|
|
41
|
+
reply_to?: string;
|
|
42
|
+
to: EMContact[];
|
|
43
|
+
attachments: EMAttachment[];
|
|
44
|
+
text?: string;
|
|
45
|
+
html?: string;
|
|
46
|
+
global_merge_vars: object | null;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
declare class TwilioConnector extends ISmsConnector {
|
|
51
|
+
static providerName: string;
|
|
52
|
+
readonly twilioClient: twilio.Twilio;
|
|
53
|
+
constructor({ ACCOUNT_ID, AUTH_TOKEN, SERVICE_ID, }: {
|
|
54
|
+
ACCOUNT_ID: string;
|
|
55
|
+
AUTH_TOKEN: string;
|
|
56
|
+
SERVICE_ID: string;
|
|
57
|
+
});
|
|
58
|
+
sendSms(sms: ISms): Promise<InternalError | void>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
interface AuditLogSelectType extends InferSelectModel<typeof tables.auditLog> {
|
|
62
|
+
}
|
|
63
|
+
interface AuditLogInsertType extends InferInsertModel<typeof tables.auditLog> {
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
declare const AUDIT_LOG_EVENT_TYPES: readonly ["EMAIL", "SMS", "PUSH_NOTIFICATION", "SLACK"];
|
|
67
|
+
type AuditLogEventType = (typeof AUDIT_LOG_EVENT_TYPES)[number];
|
|
68
|
+
|
|
69
|
+
export { AUDIT_LOG_EVENT_TYPES, EcomailConnector, IContact, IEmail, IEmailConnector, ISms, ISmsConnector, TwilioConnector };
|
|
70
|
+
export type { AuditLogEventType, AuditLogInsertType, AuditLogSelectType, EMAttachment, EMContact, EMEmail };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { I as IEmailConnector, g as IContact, h as IEmail, a as ISmsConnector, i as ISms } from './shared/notification.Bc0Z2CT6.mjs';
|
|
2
|
+
export { n as IPushNotification, o as ISlack, N as NotificationQueueMessage, S as SendEmailInput, b as SendEmailOutput, e as SendSlackInput, f as SendSlackOutput, c as SendSmsInput, d as SendSmsOutput, j as iContactSchema, k as iEmailSchema, s as sendEmailInputSchema, l as sendSlackInputSchema, m as sendSmsInputSchema } from './shared/notification.Bc0Z2CT6.mjs';
|
|
3
|
+
import { InternalError } from '@develit-io/backend-sdk';
|
|
4
|
+
import twilio from 'twilio';
|
|
5
|
+
import { tables } from '@services/notification/src/database/drizzle';
|
|
6
|
+
import { InferSelectModel, InferInsertModel } from 'drizzle-orm';
|
|
7
|
+
export { b as NotificationServiceEnv, a as NotificationServiceEnvironmentConfig, N as NotificationServiceWranglerConfig } from './shared/notification.B2I1pTPy.mjs';
|
|
8
|
+
import 'zod';
|
|
9
|
+
import 'zod/v4';
|
|
10
|
+
|
|
11
|
+
declare class EcomailConnector extends IEmailConnector {
|
|
12
|
+
static providerName: string;
|
|
13
|
+
constructor({ API_KEY, SMTP_HOST, SENDER, }: {
|
|
14
|
+
API_KEY: string;
|
|
15
|
+
SMTP_HOST: string;
|
|
16
|
+
SENDER: IContact;
|
|
17
|
+
});
|
|
18
|
+
sendEmail(email: IEmail): Promise<void>;
|
|
19
|
+
protected convertEmail(email: IEmail): EMEmail;
|
|
20
|
+
protected convertContacts(contacts: IContact | IContact[]): EMContact[];
|
|
21
|
+
protected convertContact(contact: IContact): EMContact;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface EMContact {
|
|
25
|
+
email: string;
|
|
26
|
+
name?: string;
|
|
27
|
+
cc?: string;
|
|
28
|
+
bcc?: string;
|
|
29
|
+
}
|
|
30
|
+
interface EMAttachment {
|
|
31
|
+
type: string;
|
|
32
|
+
name: string;
|
|
33
|
+
content: string;
|
|
34
|
+
}
|
|
35
|
+
interface EMEmail {
|
|
36
|
+
message: {
|
|
37
|
+
template_id?: number;
|
|
38
|
+
subject: string;
|
|
39
|
+
from_name: string;
|
|
40
|
+
from_email: string;
|
|
41
|
+
reply_to?: string;
|
|
42
|
+
to: EMContact[];
|
|
43
|
+
attachments: EMAttachment[];
|
|
44
|
+
text?: string;
|
|
45
|
+
html?: string;
|
|
46
|
+
global_merge_vars: object | null;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
declare class TwilioConnector extends ISmsConnector {
|
|
51
|
+
static providerName: string;
|
|
52
|
+
readonly twilioClient: twilio.Twilio;
|
|
53
|
+
constructor({ ACCOUNT_ID, AUTH_TOKEN, SERVICE_ID, }: {
|
|
54
|
+
ACCOUNT_ID: string;
|
|
55
|
+
AUTH_TOKEN: string;
|
|
56
|
+
SERVICE_ID: string;
|
|
57
|
+
});
|
|
58
|
+
sendSms(sms: ISms): Promise<InternalError | void>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
interface AuditLogSelectType extends InferSelectModel<typeof tables.auditLog> {
|
|
62
|
+
}
|
|
63
|
+
interface AuditLogInsertType extends InferInsertModel<typeof tables.auditLog> {
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
declare const AUDIT_LOG_EVENT_TYPES: readonly ["EMAIL", "SMS", "PUSH_NOTIFICATION", "SLACK"];
|
|
67
|
+
type AuditLogEventType = (typeof AUDIT_LOG_EVENT_TYPES)[number];
|
|
68
|
+
|
|
69
|
+
export { AUDIT_LOG_EVENT_TYPES, EcomailConnector, IContact, IEmail, IEmailConnector, ISms, ISmsConnector, TwilioConnector };
|
|
70
|
+
export type { AuditLogEventType, AuditLogInsertType, AuditLogSelectType, EMAttachment, EMContact, EMEmail };
|
package/dist/@types.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { I as IEmailConnector, g as IContact, h as IEmail, a as ISmsConnector, i as ISms } from './shared/notification.Bc0Z2CT6.js';
|
|
2
|
+
export { n as IPushNotification, o as ISlack, N as NotificationQueueMessage, S as SendEmailInput, b as SendEmailOutput, e as SendSlackInput, f as SendSlackOutput, c as SendSmsInput, d as SendSmsOutput, j as iContactSchema, k as iEmailSchema, s as sendEmailInputSchema, l as sendSlackInputSchema, m as sendSmsInputSchema } from './shared/notification.Bc0Z2CT6.js';
|
|
3
|
+
import { InternalError } from '@develit-io/backend-sdk';
|
|
4
|
+
import twilio from 'twilio';
|
|
5
|
+
import { tables } from '@services/notification/src/database/drizzle';
|
|
6
|
+
import { InferSelectModel, InferInsertModel } from 'drizzle-orm';
|
|
7
|
+
export { b as NotificationServiceEnv, a as NotificationServiceEnvironmentConfig, N as NotificationServiceWranglerConfig } from './shared/notification.B2I1pTPy.js';
|
|
8
|
+
import 'zod';
|
|
9
|
+
import 'zod/v4';
|
|
10
|
+
|
|
11
|
+
declare class EcomailConnector extends IEmailConnector {
|
|
12
|
+
static providerName: string;
|
|
13
|
+
constructor({ API_KEY, SMTP_HOST, SENDER, }: {
|
|
14
|
+
API_KEY: string;
|
|
15
|
+
SMTP_HOST: string;
|
|
16
|
+
SENDER: IContact;
|
|
17
|
+
});
|
|
18
|
+
sendEmail(email: IEmail): Promise<void>;
|
|
19
|
+
protected convertEmail(email: IEmail): EMEmail;
|
|
20
|
+
protected convertContacts(contacts: IContact | IContact[]): EMContact[];
|
|
21
|
+
protected convertContact(contact: IContact): EMContact;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface EMContact {
|
|
25
|
+
email: string;
|
|
26
|
+
name?: string;
|
|
27
|
+
cc?: string;
|
|
28
|
+
bcc?: string;
|
|
29
|
+
}
|
|
30
|
+
interface EMAttachment {
|
|
31
|
+
type: string;
|
|
32
|
+
name: string;
|
|
33
|
+
content: string;
|
|
34
|
+
}
|
|
35
|
+
interface EMEmail {
|
|
36
|
+
message: {
|
|
37
|
+
template_id?: number;
|
|
38
|
+
subject: string;
|
|
39
|
+
from_name: string;
|
|
40
|
+
from_email: string;
|
|
41
|
+
reply_to?: string;
|
|
42
|
+
to: EMContact[];
|
|
43
|
+
attachments: EMAttachment[];
|
|
44
|
+
text?: string;
|
|
45
|
+
html?: string;
|
|
46
|
+
global_merge_vars: object | null;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
declare class TwilioConnector extends ISmsConnector {
|
|
51
|
+
static providerName: string;
|
|
52
|
+
readonly twilioClient: twilio.Twilio;
|
|
53
|
+
constructor({ ACCOUNT_ID, AUTH_TOKEN, SERVICE_ID, }: {
|
|
54
|
+
ACCOUNT_ID: string;
|
|
55
|
+
AUTH_TOKEN: string;
|
|
56
|
+
SERVICE_ID: string;
|
|
57
|
+
});
|
|
58
|
+
sendSms(sms: ISms): Promise<InternalError | void>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
interface AuditLogSelectType extends InferSelectModel<typeof tables.auditLog> {
|
|
62
|
+
}
|
|
63
|
+
interface AuditLogInsertType extends InferInsertModel<typeof tables.auditLog> {
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
declare const AUDIT_LOG_EVENT_TYPES: readonly ["EMAIL", "SMS", "PUSH_NOTIFICATION", "SLACK"];
|
|
67
|
+
type AuditLogEventType = (typeof AUDIT_LOG_EVENT_TYPES)[number];
|
|
68
|
+
|
|
69
|
+
export { AUDIT_LOG_EVENT_TYPES, EcomailConnector, IContact, IEmail, IEmailConnector, ISms, ISmsConnector, TwilioConnector };
|
|
70
|
+
export type { AuditLogEventType, AuditLogInsertType, AuditLogSelectType, EMAttachment, EMContact, EMEmail };
|
package/dist/@types.mjs
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { E as EcomailConnector, I as IEmailConnector, d as ISmsConnector, T as TwilioConnector, i as iContactSchema, c as iEmailSchema, s as sendEmailInputSchema, b as sendSlackInputSchema, a as sendSmsInputSchema } from './shared/notification.D1sgZDH0.mjs';
|
|
2
|
+
import 'zod';
|
|
3
|
+
import '@develit-io/backend-sdk';
|
|
4
|
+
import 'zod/v4';
|
|
5
|
+
import 'twilio';
|
|
6
|
+
|
|
7
|
+
const AUDIT_LOG_EVENT_TYPES = [
|
|
8
|
+
"EMAIL",
|
|
9
|
+
"SMS",
|
|
10
|
+
"PUSH_NOTIFICATION",
|
|
11
|
+
"SLACK"
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
export { AUDIT_LOG_EVENT_TYPES };
|
package/dist/export/worker.cjs
CHANGED
|
@@ -3,223 +3,20 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
const backendSdk = require('@develit-io/backend-sdk');
|
|
6
|
-
const
|
|
7
|
-
const v4 = require('zod/v4');
|
|
8
|
-
const twilio = require('twilio');
|
|
6
|
+
const twilio_connector = require('../shared/notification.B8IIgYsS.cjs');
|
|
9
7
|
const database_schema = require('../shared/notification.4b3eUEIG.cjs');
|
|
10
8
|
require('drizzle-orm');
|
|
11
9
|
require('drizzle-orm/sqlite-core');
|
|
12
10
|
const cloudflare_workers = require('cloudflare:workers');
|
|
13
11
|
const d1 = require('drizzle-orm/d1');
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const z__default = /*#__PURE__*/_interopDefaultCompat(z);
|
|
18
|
-
const twilio__default = /*#__PURE__*/_interopDefaultCompat(twilio);
|
|
19
|
-
|
|
20
|
-
const iContactSchema = z.z.union([
|
|
21
|
-
z.z.string(),
|
|
22
|
-
z.z.object({
|
|
23
|
-
email: z.z.string(),
|
|
24
|
-
name: z.z.union([z.z.string(), z.z.undefined()])
|
|
25
|
-
})
|
|
26
|
-
]);
|
|
27
|
-
const iEmailSchema = z.z.object({
|
|
28
|
-
to: z.z.union([iContactSchema, z.z.array(iContactSchema)]),
|
|
29
|
-
replyTo: z.z.union([iContactSchema, z.z.array(iContactSchema)]).optional(),
|
|
30
|
-
cc: z.z.union([iContactSchema, z.z.array(iContactSchema)]).optional(),
|
|
31
|
-
bcc: z.z.union([iContactSchema, z.z.array(iContactSchema)]).optional(),
|
|
32
|
-
from: iContactSchema.optional(),
|
|
33
|
-
subject: z.z.string(),
|
|
34
|
-
text: z.z.string().optional(),
|
|
35
|
-
html: z.z.string().optional(),
|
|
36
|
-
templateId: z.z.number().optional(),
|
|
37
|
-
templateVariables: z.z.record(z.z.string(), z.z.string()).optional()
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
class IEmailConnector {
|
|
41
|
-
constructor({
|
|
42
|
-
API_KEY,
|
|
43
|
-
SMTP_HOST,
|
|
44
|
-
SENDER
|
|
45
|
-
}) {
|
|
46
|
-
this.API_KEY = API_KEY;
|
|
47
|
-
this.SMTP_HOST = SMTP_HOST;
|
|
48
|
-
this.SENDER = SENDER;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
class EcomailConnector extends IEmailConnector {
|
|
53
|
-
static {
|
|
54
|
-
this.providerName = "ecomail";
|
|
55
|
-
}
|
|
56
|
-
constructor({
|
|
57
|
-
API_KEY,
|
|
58
|
-
SMTP_HOST,
|
|
59
|
-
SENDER
|
|
60
|
-
}) {
|
|
61
|
-
super({ API_KEY, SMTP_HOST, SENDER });
|
|
62
|
-
}
|
|
63
|
-
async sendEmail(email) {
|
|
64
|
-
if (email.templateVariables) {
|
|
65
|
-
for (const [key, value] of Object.entries(email.templateVariables)) {
|
|
66
|
-
if (typeof value === "string" && String(value).includes("localhost") && key in email.templateVariables) {
|
|
67
|
-
email.templateVariables[key] = String(value).replace("localhost", "origin");
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
const emEmail = this.convertEmail(email);
|
|
72
|
-
const uri = emEmail.message.template_id ? "https://api2.ecomailapp.cz/transactional/send-template" : "https://api2.ecomailapp.cz/transactional/send-message";
|
|
73
|
-
const [_, error] = await backendSdk.useFetch(uri, {
|
|
74
|
-
method: "POST",
|
|
75
|
-
headers: {
|
|
76
|
-
"Content-Type": "application/json",
|
|
77
|
-
key: this.API_KEY
|
|
78
|
-
},
|
|
79
|
-
body: JSON.stringify(emEmail)
|
|
80
|
-
});
|
|
81
|
-
if (error) throw error;
|
|
82
|
-
}
|
|
83
|
-
convertEmail(email) {
|
|
84
|
-
const toContacts = this.convertContacts(email.to);
|
|
85
|
-
const ccContacts = email.cc ? this.convertContacts(email.cc) : [];
|
|
86
|
-
const bccContacts = email.bcc ? this.convertContacts(email.bcc) : [];
|
|
87
|
-
const replyTo = email.replyTo ? this.convertContacts(email.replyTo)[0] : void 0;
|
|
88
|
-
const from = this.convertContact(email.from || this.SENDER);
|
|
89
|
-
const subject = email.subject;
|
|
90
|
-
const textAttachments = email.text ? [{ name: "plain", type: "text/plain", content: email.text }] : [];
|
|
91
|
-
const htmlAttachments = email.html ? [{ type: "text/html", content: email.html, name: "email_body.html" }] : [];
|
|
92
|
-
const attachments = [...textAttachments, ...htmlAttachments];
|
|
93
|
-
const contacts = toContacts.flatMap((to) => {
|
|
94
|
-
const entries = [];
|
|
95
|
-
if (ccContacts.length > 0) {
|
|
96
|
-
ccContacts.forEach((cc) => {
|
|
97
|
-
entries.push({ email: cc?.email, name: cc?.name, cc: cc?.email });
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
if (bccContacts.length > 0) {
|
|
101
|
-
bccContacts.forEach((bcc) => {
|
|
102
|
-
entries.push({ email: bcc?.email, name: bcc?.name, bcc: bcc?.email });
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
return entries.length > 0 ? entries : [to];
|
|
106
|
-
});
|
|
107
|
-
return {
|
|
108
|
-
message: {
|
|
109
|
-
from_email: from?.email,
|
|
110
|
-
from_name: from.name || "",
|
|
111
|
-
subject,
|
|
112
|
-
attachments,
|
|
113
|
-
to: contacts,
|
|
114
|
-
text: email.text,
|
|
115
|
-
html: email.html,
|
|
116
|
-
reply_to: replyTo?.email,
|
|
117
|
-
template_id: email.templateId,
|
|
118
|
-
global_merge_vars: email.templateVariables ? Object.keys(email.templateVariables).map((key) => ({
|
|
119
|
-
name: key,
|
|
120
|
-
content: email.templateVariables[key]
|
|
121
|
-
})) : null
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
convertContacts(contacts) {
|
|
126
|
-
if (!contacts) {
|
|
127
|
-
return [];
|
|
128
|
-
}
|
|
129
|
-
const contactArray = Array.isArray(contacts) ? contacts : [contacts];
|
|
130
|
-
return contactArray.map(this.convertContact);
|
|
131
|
-
}
|
|
132
|
-
convertContact(contact) {
|
|
133
|
-
if (typeof contact === "string") {
|
|
134
|
-
return { email: contact, name: void 0 };
|
|
135
|
-
}
|
|
136
|
-
return { email: contact?.email, name: contact?.name };
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const sendEmailInputSchema = z__default.object({
|
|
141
|
-
email: iEmailSchema,
|
|
142
|
-
metadata: z__default.object({
|
|
143
|
-
userAgent: z__default.string().optional(),
|
|
144
|
-
ip: z__default.ipv4().or(z__default.ipv6()).optional(),
|
|
145
|
-
initiator: z__default.object({
|
|
146
|
-
service: z__default.string(),
|
|
147
|
-
userId: z__default.string().optional()
|
|
148
|
-
})
|
|
149
|
-
})
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
const sendSlackInputSchema = v4.z.object({
|
|
153
|
-
slack: v4.z.object({
|
|
154
|
-
message: v4.z.string()
|
|
155
|
-
}),
|
|
156
|
-
metadata: v4.z.object({
|
|
157
|
-
userAgent: v4.z.string().optional(),
|
|
158
|
-
ip: v4.z.ipv4().or(v4.z.ipv6()).optional(),
|
|
159
|
-
initiator: v4.z.object({
|
|
160
|
-
service: v4.z.string(),
|
|
161
|
-
userId: v4.z.string().optional()
|
|
162
|
-
})
|
|
163
|
-
})
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
const sendSmsInputSchema = z.z.object({
|
|
167
|
-
sms: z.z.object({
|
|
168
|
-
message: z.z.string(),
|
|
169
|
-
to: z.z.string()
|
|
170
|
-
}),
|
|
171
|
-
metadata: z.z.object({
|
|
172
|
-
userAgent: z.z.string().optional(),
|
|
173
|
-
ip: z.z.ipv4().or(z.z.ipv6()).optional(),
|
|
174
|
-
initiator: z.z.object({
|
|
175
|
-
service: z.z.string(),
|
|
176
|
-
userId: z.z.string().optional()
|
|
177
|
-
})
|
|
178
|
-
})
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
class ISmsConnector {
|
|
182
|
-
constructor({
|
|
183
|
-
ACCOUNT_ID,
|
|
184
|
-
AUTH_TOKEN,
|
|
185
|
-
SERVICE_ID
|
|
186
|
-
}) {
|
|
187
|
-
this.ACCOUNT_ID = ACCOUNT_ID;
|
|
188
|
-
this.AUTH_TOKEN = AUTH_TOKEN;
|
|
189
|
-
this.SERVICE_ID = SERVICE_ID;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
class TwilioConnector extends ISmsConnector {
|
|
194
|
-
static {
|
|
195
|
-
this.providerName = "twilio";
|
|
196
|
-
}
|
|
197
|
-
constructor({
|
|
198
|
-
ACCOUNT_ID,
|
|
199
|
-
AUTH_TOKEN,
|
|
200
|
-
SERVICE_ID
|
|
201
|
-
}) {
|
|
202
|
-
super({ ACCOUNT_ID, AUTH_TOKEN, SERVICE_ID });
|
|
203
|
-
this.twilioClient = twilio__default(ACCOUNT_ID, AUTH_TOKEN);
|
|
204
|
-
}
|
|
205
|
-
async sendSms(sms) {
|
|
206
|
-
const message = await this.twilioClient.messages.create({
|
|
207
|
-
body: sms.message,
|
|
208
|
-
messagingServiceSid: this.SERVICE_ID,
|
|
209
|
-
to: sms.to
|
|
210
|
-
});
|
|
211
|
-
if (message.errorMessage)
|
|
212
|
-
return backendSdk.createInternalError(null, {
|
|
213
|
-
message: message.errorMessage,
|
|
214
|
-
status: message.errorCode
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
}
|
|
12
|
+
require('zod');
|
|
13
|
+
require('zod/v4');
|
|
14
|
+
require('twilio');
|
|
218
15
|
|
|
219
16
|
const tables = database_schema.schema;
|
|
220
17
|
|
|
221
18
|
const initiateEmailConnector = async (provider, apiKey, smtpHost, sender) => {
|
|
222
|
-
const connector = [EcomailConnector].find(
|
|
19
|
+
const connector = [twilio_connector.EcomailConnector].find(
|
|
223
20
|
(conn) => conn.providerName === provider
|
|
224
21
|
);
|
|
225
22
|
if (!connector)
|
|
@@ -257,7 +54,7 @@ const createAuditLogCommand = async ({
|
|
|
257
54
|
};
|
|
258
55
|
|
|
259
56
|
const initiateSmsConnector = async (provider, accountId, authToken, serviceId) => {
|
|
260
|
-
const connector = [TwilioConnector].find(
|
|
57
|
+
const connector = [twilio_connector.TwilioConnector].find(
|
|
261
58
|
(conn) => conn.providerName === provider
|
|
262
59
|
);
|
|
263
60
|
if (!connector)
|
|
@@ -388,7 +185,7 @@ class NotificationServiceBase extends backendSdk.develitWorker(
|
|
|
388
185
|
}
|
|
389
186
|
async _sendEmail(input) {
|
|
390
187
|
return this.handleAction(
|
|
391
|
-
{ data: input, schema: sendEmailInputSchema },
|
|
188
|
+
{ data: input, schema: twilio_connector.sendEmailInputSchema },
|
|
392
189
|
{ successMessage: "Email sent." },
|
|
393
190
|
async (params) => {
|
|
394
191
|
const {
|
|
@@ -427,7 +224,7 @@ class NotificationServiceBase extends backendSdk.develitWorker(
|
|
|
427
224
|
}
|
|
428
225
|
async _sendSms(input) {
|
|
429
226
|
return this.handleAction(
|
|
430
|
-
{ data: input, schema: sendSmsInputSchema },
|
|
227
|
+
{ data: input, schema: twilio_connector.sendSmsInputSchema },
|
|
431
228
|
{ successMessage: "Sms sent." },
|
|
432
229
|
async (params) => {
|
|
433
230
|
const {
|
|
@@ -458,7 +255,7 @@ class NotificationServiceBase extends backendSdk.develitWorker(
|
|
|
458
255
|
}
|
|
459
256
|
async sendEmail(input) {
|
|
460
257
|
return this.handleAction(
|
|
461
|
-
{ data: input, schema: sendEmailInputSchema },
|
|
258
|
+
{ data: input, schema: twilio_connector.sendEmailInputSchema },
|
|
462
259
|
{ successMessage: "Email sent." },
|
|
463
260
|
async (params) => {
|
|
464
261
|
const { email, metadata } = params;
|
|
@@ -478,7 +275,7 @@ class NotificationServiceBase extends backendSdk.develitWorker(
|
|
|
478
275
|
}
|
|
479
276
|
async sendSms(input) {
|
|
480
277
|
return this.handleAction(
|
|
481
|
-
{ data: input, schema: sendSmsInputSchema },
|
|
278
|
+
{ data: input, schema: twilio_connector.sendSmsInputSchema },
|
|
482
279
|
{ successMessage: "SMS sent." },
|
|
483
280
|
async (params) => {
|
|
484
281
|
const {
|
|
@@ -511,7 +308,7 @@ class NotificationServiceBase extends backendSdk.develitWorker(
|
|
|
511
308
|
return this.handleAction(
|
|
512
309
|
{
|
|
513
310
|
data: input,
|
|
514
|
-
schema: sendSlackInputSchema
|
|
311
|
+
schema: twilio_connector.sendSlackInputSchema
|
|
515
312
|
},
|
|
516
313
|
{ successMessage: "Slack sent." },
|
|
517
314
|
async (params) => {
|