@develit-services/notification 0.6.2 → 0.6.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/dist/export/worker.cjs +24 -1
- package/dist/export/worker.d.cts +3 -0
- package/dist/export/worker.d.mts +3 -0
- package/dist/export/worker.d.ts +3 -0
- package/dist/export/worker.mjs +24 -1
- package/dist/export/wrangler.d.cts +3 -1
- package/dist/export/wrangler.d.mts +3 -1
- package/dist/export/wrangler.d.ts +3 -1
- package/dist/shared/{notification.Csi9Hg5K.d.cts → notification.mdV1ug8W.d.cts} +2 -0
- package/dist/shared/{notification.Csi9Hg5K.d.mts → notification.mdV1ug8W.d.mts} +2 -0
- package/dist/shared/{notification.Csi9Hg5K.d.ts → notification.mdV1ug8W.d.ts} +2 -0
- package/dist/types.d.cts +1 -1
- package/dist/types.d.mts +1 -1
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
package/dist/export/worker.cjs
CHANGED
|
@@ -66,6 +66,28 @@ let NotificationServiceBase = class extends backendSdk.develitWorker(
|
|
|
66
66
|
super(ctx, env);
|
|
67
67
|
this.slackConnector = new webhook_connector.SlackConnector(this.env.SLACK_WEBHOOK);
|
|
68
68
|
}
|
|
69
|
+
getContactEmail(contact) {
|
|
70
|
+
return typeof contact === "string" ? contact : contact.email;
|
|
71
|
+
}
|
|
72
|
+
isEmailAllowed(email, allowedEmails) {
|
|
73
|
+
return allowedEmails.includes(email.toLowerCase());
|
|
74
|
+
}
|
|
75
|
+
applyEmailWhitelist(email) {
|
|
76
|
+
const whitelist = this.env.EMAIL_WHITELIST;
|
|
77
|
+
if (!whitelist) return email;
|
|
78
|
+
const fallback = this.env.EMAIL_WHITELIST_FALLBACK;
|
|
79
|
+
const allowedEmails = whitelist.split(",").map((e) => e.trim().toLowerCase());
|
|
80
|
+
const toEmail = this.getContactEmail(
|
|
81
|
+
Array.isArray(email.to) ? email.to[0] : email.to
|
|
82
|
+
);
|
|
83
|
+
if (this.isEmailAllowed(toEmail, allowedEmails)) return email;
|
|
84
|
+
if (fallback) return { ...email, to: fallback };
|
|
85
|
+
throw backendSdk.createInternalError(null, {
|
|
86
|
+
message: `Email not on whitelist and no fallback configured: ${toEmail}`,
|
|
87
|
+
code: "SYS-N-03",
|
|
88
|
+
status: 400
|
|
89
|
+
});
|
|
90
|
+
}
|
|
69
91
|
async queue(batch) {
|
|
70
92
|
for (const message of batch.messages) {
|
|
71
93
|
this.logInput({ message });
|
|
@@ -137,7 +159,8 @@ let NotificationServiceBase = class extends backendSdk.develitWorker(
|
|
|
137
159
|
this.env.EMAIL_SENDER_NAME
|
|
138
160
|
);
|
|
139
161
|
}
|
|
140
|
-
|
|
162
|
+
const filteredEmail = this.applyEmailWhitelist(email);
|
|
163
|
+
await this.emailConnector.sendEmail(filteredEmail);
|
|
141
164
|
try {
|
|
142
165
|
await this.pushToQueue(this.env.AUDIT_LOGS_QUEUE, {
|
|
143
166
|
logType: "event",
|
package/dist/export/worker.d.cts
CHANGED
|
@@ -12,6 +12,9 @@ declare class NotificationServiceBase extends NotificationServiceBase_base {
|
|
|
12
12
|
protected emailConnector: IEmailConnector;
|
|
13
13
|
protected smsConnector: ISmsConnector;
|
|
14
14
|
constructor(ctx: ExecutionContext, env: NotificationEnv);
|
|
15
|
+
private getContactEmail;
|
|
16
|
+
private isEmailAllowed;
|
|
17
|
+
private applyEmailWhitelist;
|
|
15
18
|
queue(batch: MessageBatch<NotificationQueueMessage>): Promise<void>;
|
|
16
19
|
protected _sendEmail(input: SendEmailInput): Promise<IRPCResponse<SendEmailOutput>>;
|
|
17
20
|
protected _sendSms(input: SendSmsInput): Promise<IRPCResponse<SendSmsOutput>>;
|
package/dist/export/worker.d.mts
CHANGED
|
@@ -12,6 +12,9 @@ declare class NotificationServiceBase extends NotificationServiceBase_base {
|
|
|
12
12
|
protected emailConnector: IEmailConnector;
|
|
13
13
|
protected smsConnector: ISmsConnector;
|
|
14
14
|
constructor(ctx: ExecutionContext, env: NotificationEnv);
|
|
15
|
+
private getContactEmail;
|
|
16
|
+
private isEmailAllowed;
|
|
17
|
+
private applyEmailWhitelist;
|
|
15
18
|
queue(batch: MessageBatch<NotificationQueueMessage>): Promise<void>;
|
|
16
19
|
protected _sendEmail(input: SendEmailInput): Promise<IRPCResponse<SendEmailOutput>>;
|
|
17
20
|
protected _sendSms(input: SendSmsInput): Promise<IRPCResponse<SendSmsOutput>>;
|
package/dist/export/worker.d.ts
CHANGED
|
@@ -12,6 +12,9 @@ declare class NotificationServiceBase extends NotificationServiceBase_base {
|
|
|
12
12
|
protected emailConnector: IEmailConnector;
|
|
13
13
|
protected smsConnector: ISmsConnector;
|
|
14
14
|
constructor(ctx: ExecutionContext, env: NotificationEnv);
|
|
15
|
+
private getContactEmail;
|
|
16
|
+
private isEmailAllowed;
|
|
17
|
+
private applyEmailWhitelist;
|
|
15
18
|
queue(batch: MessageBatch<NotificationQueueMessage>): Promise<void>;
|
|
16
19
|
protected _sendEmail(input: SendEmailInput): Promise<IRPCResponse<SendEmailOutput>>;
|
|
17
20
|
protected _sendSms(input: SendSmsInput): Promise<IRPCResponse<SendSmsOutput>>;
|
package/dist/export/worker.mjs
CHANGED
|
@@ -62,6 +62,28 @@ let NotificationServiceBase = class extends develitWorker(
|
|
|
62
62
|
super(ctx, env);
|
|
63
63
|
this.slackConnector = new SlackConnector(this.env.SLACK_WEBHOOK);
|
|
64
64
|
}
|
|
65
|
+
getContactEmail(contact) {
|
|
66
|
+
return typeof contact === "string" ? contact : contact.email;
|
|
67
|
+
}
|
|
68
|
+
isEmailAllowed(email, allowedEmails) {
|
|
69
|
+
return allowedEmails.includes(email.toLowerCase());
|
|
70
|
+
}
|
|
71
|
+
applyEmailWhitelist(email) {
|
|
72
|
+
const whitelist = this.env.EMAIL_WHITELIST;
|
|
73
|
+
if (!whitelist) return email;
|
|
74
|
+
const fallback = this.env.EMAIL_WHITELIST_FALLBACK;
|
|
75
|
+
const allowedEmails = whitelist.split(",").map((e) => e.trim().toLowerCase());
|
|
76
|
+
const toEmail = this.getContactEmail(
|
|
77
|
+
Array.isArray(email.to) ? email.to[0] : email.to
|
|
78
|
+
);
|
|
79
|
+
if (this.isEmailAllowed(toEmail, allowedEmails)) return email;
|
|
80
|
+
if (fallback) return { ...email, to: fallback };
|
|
81
|
+
throw createInternalError(null, {
|
|
82
|
+
message: `Email not on whitelist and no fallback configured: ${toEmail}`,
|
|
83
|
+
code: "SYS-N-03",
|
|
84
|
+
status: 400
|
|
85
|
+
});
|
|
86
|
+
}
|
|
65
87
|
async queue(batch) {
|
|
66
88
|
for (const message of batch.messages) {
|
|
67
89
|
this.logInput({ message });
|
|
@@ -133,7 +155,8 @@ let NotificationServiceBase = class extends develitWorker(
|
|
|
133
155
|
this.env.EMAIL_SENDER_NAME
|
|
134
156
|
);
|
|
135
157
|
}
|
|
136
|
-
|
|
158
|
+
const filteredEmail = this.applyEmailWhitelist(email);
|
|
159
|
+
await this.emailConnector.sendEmail(filteredEmail);
|
|
137
160
|
try {
|
|
138
161
|
await this.pushToQueue(this.env.AUDIT_LOGS_QUEUE, {
|
|
139
162
|
logType: "event",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { N as NotificationServiceWranglerConfig } from '../shared/notification.
|
|
1
|
+
import { N as NotificationServiceWranglerConfig } from '../shared/notification.mdV1ug8W.cjs';
|
|
2
2
|
|
|
3
3
|
declare function defineNotificationServiceWrangler(config: NotificationServiceWranglerConfig): {
|
|
4
4
|
vars: {
|
|
@@ -9,6 +9,8 @@ declare function defineNotificationServiceWrangler(config: NotificationServiceWr
|
|
|
9
9
|
EMAIL_SMTP_HOST: string;
|
|
10
10
|
SMS_PROVIDER: "twilio";
|
|
11
11
|
SLACK_WEBHOOK: string;
|
|
12
|
+
EMAIL_WHITELIST?: string;
|
|
13
|
+
EMAIL_WHITELIST_FALLBACK?: string;
|
|
12
14
|
};
|
|
13
15
|
services: {
|
|
14
16
|
binding: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { N as NotificationServiceWranglerConfig } from '../shared/notification.
|
|
1
|
+
import { N as NotificationServiceWranglerConfig } from '../shared/notification.mdV1ug8W.mjs';
|
|
2
2
|
|
|
3
3
|
declare function defineNotificationServiceWrangler(config: NotificationServiceWranglerConfig): {
|
|
4
4
|
vars: {
|
|
@@ -9,6 +9,8 @@ declare function defineNotificationServiceWrangler(config: NotificationServiceWr
|
|
|
9
9
|
EMAIL_SMTP_HOST: string;
|
|
10
10
|
SMS_PROVIDER: "twilio";
|
|
11
11
|
SLACK_WEBHOOK: string;
|
|
12
|
+
EMAIL_WHITELIST?: string;
|
|
13
|
+
EMAIL_WHITELIST_FALLBACK?: string;
|
|
12
14
|
};
|
|
13
15
|
services: {
|
|
14
16
|
binding: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { N as NotificationServiceWranglerConfig } from '../shared/notification.
|
|
1
|
+
import { N as NotificationServiceWranglerConfig } from '../shared/notification.mdV1ug8W.js';
|
|
2
2
|
|
|
3
3
|
declare function defineNotificationServiceWrangler(config: NotificationServiceWranglerConfig): {
|
|
4
4
|
vars: {
|
|
@@ -9,6 +9,8 @@ declare function defineNotificationServiceWrangler(config: NotificationServiceWr
|
|
|
9
9
|
EMAIL_SMTP_HOST: string;
|
|
10
10
|
SMS_PROVIDER: "twilio";
|
|
11
11
|
SLACK_WEBHOOK: string;
|
|
12
|
+
EMAIL_WHITELIST?: string;
|
|
13
|
+
EMAIL_WHITELIST_FALLBACK?: string;
|
|
12
14
|
};
|
|
13
15
|
services: {
|
|
14
16
|
binding: string;
|
package/dist/types.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { I as IEmailConnector, n as IEmail, o as IContact, a as ISmsConnector, p as ISms } from './shared/notification.BiG4Q650.cjs';
|
|
2
2
|
export { C as ClearReceivedEmailsInput, m as ClearReceivedEmailsOutput, G as GetReceivedEmailsInput, j as GetReceivedEmailsOutput, q as IAttachment, r as IPushNotification, s as ISlack, t as IWebhook, N as NotificationQueueMessage, R as ReceivedEmail, b as SendEmailInput, c as SendEmailOutput, f as SendSlackInput, g as SendSlackOutput, d as SendSmsInput, e as SendSmsOutput, h as SendWebhookInput, i as SendWebhookOutput, S as SlackConnector, k as WaitForEmailInput, l as WaitForEmailOutput, W as WebhookConnector, u as clearReceivedEmailsInputSchema, v as getReceivedEmailsInputSchema, w as iAttachmentSchema, x as iContactSchema, y as iEmailSchema, z as sendEmailInputSchema, A as sendSlackInputSchema, B as sendSmsInputSchema, D as sendWebhookInputSchema, E as waitForEmailInputSchema } from './shared/notification.BiG4Q650.cjs';
|
|
3
3
|
import twilio from 'twilio';
|
|
4
|
-
export { a as NotificationServiceEnv, b as NotificationServiceEnvironmentConfig, N as NotificationServiceWranglerConfig } from './shared/notification.
|
|
4
|
+
export { a as NotificationServiceEnv, b as NotificationServiceEnvironmentConfig, N as NotificationServiceWranglerConfig } from './shared/notification.mdV1ug8W.cjs';
|
|
5
5
|
import 'zod';
|
|
6
6
|
import 'zod/v4';
|
|
7
7
|
|
package/dist/types.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { I as IEmailConnector, n as IEmail, o as IContact, a as ISmsConnector, p as ISms } from './shared/notification.BiG4Q650.mjs';
|
|
2
2
|
export { C as ClearReceivedEmailsInput, m as ClearReceivedEmailsOutput, G as GetReceivedEmailsInput, j as GetReceivedEmailsOutput, q as IAttachment, r as IPushNotification, s as ISlack, t as IWebhook, N as NotificationQueueMessage, R as ReceivedEmail, b as SendEmailInput, c as SendEmailOutput, f as SendSlackInput, g as SendSlackOutput, d as SendSmsInput, e as SendSmsOutput, h as SendWebhookInput, i as SendWebhookOutput, S as SlackConnector, k as WaitForEmailInput, l as WaitForEmailOutput, W as WebhookConnector, u as clearReceivedEmailsInputSchema, v as getReceivedEmailsInputSchema, w as iAttachmentSchema, x as iContactSchema, y as iEmailSchema, z as sendEmailInputSchema, A as sendSlackInputSchema, B as sendSmsInputSchema, D as sendWebhookInputSchema, E as waitForEmailInputSchema } from './shared/notification.BiG4Q650.mjs';
|
|
3
3
|
import twilio from 'twilio';
|
|
4
|
-
export { a as NotificationServiceEnv, b as NotificationServiceEnvironmentConfig, N as NotificationServiceWranglerConfig } from './shared/notification.
|
|
4
|
+
export { a as NotificationServiceEnv, b as NotificationServiceEnvironmentConfig, N as NotificationServiceWranglerConfig } from './shared/notification.mdV1ug8W.mjs';
|
|
5
5
|
import 'zod';
|
|
6
6
|
import 'zod/v4';
|
|
7
7
|
|
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { I as IEmailConnector, n as IEmail, o as IContact, a as ISmsConnector, p as ISms } from './shared/notification.BiG4Q650.js';
|
|
2
2
|
export { C as ClearReceivedEmailsInput, m as ClearReceivedEmailsOutput, G as GetReceivedEmailsInput, j as GetReceivedEmailsOutput, q as IAttachment, r as IPushNotification, s as ISlack, t as IWebhook, N as NotificationQueueMessage, R as ReceivedEmail, b as SendEmailInput, c as SendEmailOutput, f as SendSlackInput, g as SendSlackOutput, d as SendSmsInput, e as SendSmsOutput, h as SendWebhookInput, i as SendWebhookOutput, S as SlackConnector, k as WaitForEmailInput, l as WaitForEmailOutput, W as WebhookConnector, u as clearReceivedEmailsInputSchema, v as getReceivedEmailsInputSchema, w as iAttachmentSchema, x as iContactSchema, y as iEmailSchema, z as sendEmailInputSchema, A as sendSlackInputSchema, B as sendSmsInputSchema, D as sendWebhookInputSchema, E as waitForEmailInputSchema } from './shared/notification.BiG4Q650.js';
|
|
3
3
|
import twilio from 'twilio';
|
|
4
|
-
export { a as NotificationServiceEnv, b as NotificationServiceEnvironmentConfig, N as NotificationServiceWranglerConfig } from './shared/notification.
|
|
4
|
+
export { a as NotificationServiceEnv, b as NotificationServiceEnvironmentConfig, N as NotificationServiceWranglerConfig } from './shared/notification.mdV1ug8W.js';
|
|
5
5
|
import 'zod';
|
|
6
6
|
import 'zod/v4';
|
|
7
7
|
|