@develit-services/notification 0.0.18 → 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 -225
- 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 -214
- 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,231 +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
|
-
console.log("ecomail - sendEmail");
|
|
65
|
-
if (email.templateVariables) {
|
|
66
|
-
for (const [key, value] of Object.entries(email.templateVariables)) {
|
|
67
|
-
if (typeof value === "string" && String(value).includes("localhost") && key in email.templateVariables) {
|
|
68
|
-
email.templateVariables[key] = String(value).replace("localhost", "origin");
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
console.log("ecomail - convertEmail");
|
|
73
|
-
const emEmail = this.convertEmail(email);
|
|
74
|
-
const uri = emEmail.message.template_id ? "https://api2.ecomailapp.cz/transactional/send-template" : "https://api2.ecomailapp.cz/transactional/send-message";
|
|
75
|
-
console.log("ecomail - start with fetch", {
|
|
76
|
-
uri,
|
|
77
|
-
emEmail,
|
|
78
|
-
apiKey: this.API_KEY
|
|
79
|
-
});
|
|
80
|
-
const [_, error] = await backendSdk.useFetch(uri, {
|
|
81
|
-
method: "POST",
|
|
82
|
-
headers: {
|
|
83
|
-
"Content-Type": "application/json",
|
|
84
|
-
key: this.API_KEY
|
|
85
|
-
},
|
|
86
|
-
body: JSON.stringify(emEmail)
|
|
87
|
-
});
|
|
88
|
-
console.log("ecomail - fetch done");
|
|
89
|
-
if (error) throw error;
|
|
90
|
-
}
|
|
91
|
-
convertEmail(email) {
|
|
92
|
-
const toContacts = this.convertContacts(email.to);
|
|
93
|
-
const ccContacts = email.cc ? this.convertContacts(email.cc) : [];
|
|
94
|
-
const bccContacts = email.bcc ? this.convertContacts(email.bcc) : [];
|
|
95
|
-
const replyTo = email.replyTo ? this.convertContacts(email.replyTo)[0] : void 0;
|
|
96
|
-
const from = this.convertContact(email.from || this.SENDER);
|
|
97
|
-
const subject = email.subject;
|
|
98
|
-
const textAttachments = email.text ? [{ name: "plain", type: "text/plain", content: email.text }] : [];
|
|
99
|
-
const htmlAttachments = email.html ? [{ type: "text/html", content: email.html, name: "email_body.html" }] : [];
|
|
100
|
-
const attachments = [...textAttachments, ...htmlAttachments];
|
|
101
|
-
const contacts = toContacts.flatMap((to) => {
|
|
102
|
-
const entries = [];
|
|
103
|
-
if (ccContacts.length > 0) {
|
|
104
|
-
ccContacts.forEach((cc) => {
|
|
105
|
-
entries.push({ email: cc?.email, name: cc?.name, cc: cc?.email });
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
if (bccContacts.length > 0) {
|
|
109
|
-
bccContacts.forEach((bcc) => {
|
|
110
|
-
entries.push({ email: bcc?.email, name: bcc?.name, bcc: bcc?.email });
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
return entries.length > 0 ? entries : [to];
|
|
114
|
-
});
|
|
115
|
-
return {
|
|
116
|
-
message: {
|
|
117
|
-
from_email: from?.email,
|
|
118
|
-
from_name: from.name || "",
|
|
119
|
-
subject,
|
|
120
|
-
attachments,
|
|
121
|
-
to: contacts,
|
|
122
|
-
text: email.text,
|
|
123
|
-
html: email.html,
|
|
124
|
-
reply_to: replyTo?.email,
|
|
125
|
-
template_id: email.templateId,
|
|
126
|
-
global_merge_vars: email.templateVariables ? Object.keys(email.templateVariables).map((key) => ({
|
|
127
|
-
name: key,
|
|
128
|
-
content: email.templateVariables[key]
|
|
129
|
-
})) : null
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
convertContacts(contacts) {
|
|
134
|
-
if (!contacts) {
|
|
135
|
-
return [];
|
|
136
|
-
}
|
|
137
|
-
const contactArray = Array.isArray(contacts) ? contacts : [contacts];
|
|
138
|
-
return contactArray.map(this.convertContact);
|
|
139
|
-
}
|
|
140
|
-
convertContact(contact) {
|
|
141
|
-
if (typeof contact === "string") {
|
|
142
|
-
return { email: contact, name: void 0 };
|
|
143
|
-
}
|
|
144
|
-
return { email: contact?.email, name: contact?.name };
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
const sendEmailInputSchema = z__default.object({
|
|
149
|
-
email: iEmailSchema,
|
|
150
|
-
metadata: z__default.object({
|
|
151
|
-
userAgent: z__default.string().optional(),
|
|
152
|
-
ip: z__default.ipv4().or(z__default.ipv6()).optional(),
|
|
153
|
-
initiator: z__default.object({
|
|
154
|
-
service: z__default.string(),
|
|
155
|
-
userId: z__default.string().optional()
|
|
156
|
-
})
|
|
157
|
-
})
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
const sendSlackInputSchema = v4.z.object({
|
|
161
|
-
slack: v4.z.object({
|
|
162
|
-
message: v4.z.string()
|
|
163
|
-
}),
|
|
164
|
-
metadata: v4.z.object({
|
|
165
|
-
userAgent: v4.z.string().optional(),
|
|
166
|
-
ip: v4.z.ipv4().or(v4.z.ipv6()).optional(),
|
|
167
|
-
initiator: v4.z.object({
|
|
168
|
-
service: v4.z.string(),
|
|
169
|
-
userId: v4.z.string().optional()
|
|
170
|
-
})
|
|
171
|
-
})
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
const sendSmsInputSchema = z.z.object({
|
|
175
|
-
sms: z.z.object({
|
|
176
|
-
message: z.z.string(),
|
|
177
|
-
to: z.z.string()
|
|
178
|
-
}),
|
|
179
|
-
metadata: z.z.object({
|
|
180
|
-
userAgent: z.z.string().optional(),
|
|
181
|
-
ip: z.z.ipv4().or(z.z.ipv6()).optional(),
|
|
182
|
-
initiator: z.z.object({
|
|
183
|
-
service: z.z.string(),
|
|
184
|
-
userId: z.z.string().optional()
|
|
185
|
-
})
|
|
186
|
-
})
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
class ISmsConnector {
|
|
190
|
-
constructor({
|
|
191
|
-
ACCOUNT_ID,
|
|
192
|
-
AUTH_TOKEN,
|
|
193
|
-
SERVICE_ID
|
|
194
|
-
}) {
|
|
195
|
-
this.ACCOUNT_ID = ACCOUNT_ID;
|
|
196
|
-
this.AUTH_TOKEN = AUTH_TOKEN;
|
|
197
|
-
this.SERVICE_ID = SERVICE_ID;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
class TwilioConnector extends ISmsConnector {
|
|
202
|
-
static {
|
|
203
|
-
this.providerName = "twilio";
|
|
204
|
-
}
|
|
205
|
-
constructor({
|
|
206
|
-
ACCOUNT_ID,
|
|
207
|
-
AUTH_TOKEN,
|
|
208
|
-
SERVICE_ID
|
|
209
|
-
}) {
|
|
210
|
-
super({ ACCOUNT_ID, AUTH_TOKEN, SERVICE_ID });
|
|
211
|
-
this.twilioClient = twilio__default(ACCOUNT_ID, AUTH_TOKEN);
|
|
212
|
-
}
|
|
213
|
-
async sendSms(sms) {
|
|
214
|
-
const message = await this.twilioClient.messages.create({
|
|
215
|
-
body: sms.message,
|
|
216
|
-
messagingServiceSid: this.SERVICE_ID,
|
|
217
|
-
to: sms.to
|
|
218
|
-
});
|
|
219
|
-
if (message.errorMessage)
|
|
220
|
-
return backendSdk.createInternalError(null, {
|
|
221
|
-
message: message.errorMessage,
|
|
222
|
-
status: message.errorCode
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
}
|
|
12
|
+
require('zod');
|
|
13
|
+
require('zod/v4');
|
|
14
|
+
require('twilio');
|
|
226
15
|
|
|
227
16
|
const tables = database_schema.schema;
|
|
228
17
|
|
|
229
18
|
const initiateEmailConnector = async (provider, apiKey, smtpHost, sender) => {
|
|
230
|
-
const connector = [EcomailConnector].find(
|
|
19
|
+
const connector = [twilio_connector.EcomailConnector].find(
|
|
231
20
|
(conn) => conn.providerName === provider
|
|
232
21
|
);
|
|
233
22
|
if (!connector)
|
|
@@ -265,7 +54,7 @@ const createAuditLogCommand = async ({
|
|
|
265
54
|
};
|
|
266
55
|
|
|
267
56
|
const initiateSmsConnector = async (provider, accountId, authToken, serviceId) => {
|
|
268
|
-
const connector = [TwilioConnector].find(
|
|
57
|
+
const connector = [twilio_connector.TwilioConnector].find(
|
|
269
58
|
(conn) => conn.providerName === provider
|
|
270
59
|
);
|
|
271
60
|
if (!connector)
|
|
@@ -396,7 +185,7 @@ class NotificationServiceBase extends backendSdk.develitWorker(
|
|
|
396
185
|
}
|
|
397
186
|
async _sendEmail(input) {
|
|
398
187
|
return this.handleAction(
|
|
399
|
-
{ data: input, schema: sendEmailInputSchema },
|
|
188
|
+
{ data: input, schema: twilio_connector.sendEmailInputSchema },
|
|
400
189
|
{ successMessage: "Email sent." },
|
|
401
190
|
async (params) => {
|
|
402
191
|
const {
|
|
@@ -416,9 +205,6 @@ class NotificationServiceBase extends backendSdk.develitWorker(
|
|
|
416
205
|
);
|
|
417
206
|
}
|
|
418
207
|
await this.emailConnector.sendEmail(email);
|
|
419
|
-
this.log({
|
|
420
|
-
message: `Email sent to ${email.to}`
|
|
421
|
-
});
|
|
422
208
|
const { command } = await createAuditLogCommand({
|
|
423
209
|
db: this.db,
|
|
424
210
|
auditLog: {
|
|
@@ -438,7 +224,7 @@ class NotificationServiceBase extends backendSdk.develitWorker(
|
|
|
438
224
|
}
|
|
439
225
|
async _sendSms(input) {
|
|
440
226
|
return this.handleAction(
|
|
441
|
-
{ data: input, schema: sendSmsInputSchema },
|
|
227
|
+
{ data: input, schema: twilio_connector.sendSmsInputSchema },
|
|
442
228
|
{ successMessage: "Sms sent." },
|
|
443
229
|
async (params) => {
|
|
444
230
|
const {
|
|
@@ -469,7 +255,7 @@ class NotificationServiceBase extends backendSdk.develitWorker(
|
|
|
469
255
|
}
|
|
470
256
|
async sendEmail(input) {
|
|
471
257
|
return this.handleAction(
|
|
472
|
-
{ data: input, schema: sendEmailInputSchema },
|
|
258
|
+
{ data: input, schema: twilio_connector.sendEmailInputSchema },
|
|
473
259
|
{ successMessage: "Email sent." },
|
|
474
260
|
async (params) => {
|
|
475
261
|
const { email, metadata } = params;
|
|
@@ -489,7 +275,7 @@ class NotificationServiceBase extends backendSdk.develitWorker(
|
|
|
489
275
|
}
|
|
490
276
|
async sendSms(input) {
|
|
491
277
|
return this.handleAction(
|
|
492
|
-
{ data: input, schema: sendSmsInputSchema },
|
|
278
|
+
{ data: input, schema: twilio_connector.sendSmsInputSchema },
|
|
493
279
|
{ successMessage: "SMS sent." },
|
|
494
280
|
async (params) => {
|
|
495
281
|
const {
|
|
@@ -522,7 +308,7 @@ class NotificationServiceBase extends backendSdk.develitWorker(
|
|
|
522
308
|
return this.handleAction(
|
|
523
309
|
{
|
|
524
310
|
data: input,
|
|
525
|
-
schema: sendSlackInputSchema
|
|
311
|
+
schema: twilio_connector.sendSlackInputSchema
|
|
526
312
|
},
|
|
527
313
|
{ successMessage: "Slack sent." },
|
|
528
314
|
async (params) => {
|