@develit-services/notification 0.0.16 → 0.0.18
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 +21 -18
- package/dist/export/worker.d.cts +1 -1
- package/dist/export/worker.d.mts +1 -1
- package/dist/export/worker.d.ts +1 -1
- package/dist/export/worker.mjs +22 -19
- package/dist/export/wrangler.cjs +17 -0
- package/dist/export/wrangler.d.cts +24 -2
- package/dist/export/wrangler.d.mts +24 -2
- package/dist/export/wrangler.d.ts +24 -2
- package/dist/export/wrangler.mjs +17 -0
- package/package.json +1 -1
package/dist/export/worker.cjs
CHANGED
|
@@ -61,6 +61,7 @@ class EcomailConnector extends IEmailConnector {
|
|
|
61
61
|
super({ API_KEY, SMTP_HOST, SENDER });
|
|
62
62
|
}
|
|
63
63
|
async sendEmail(email) {
|
|
64
|
+
console.log("ecomail - sendEmail");
|
|
64
65
|
if (email.templateVariables) {
|
|
65
66
|
for (const [key, value] of Object.entries(email.templateVariables)) {
|
|
66
67
|
if (typeof value === "string" && String(value).includes("localhost") && key in email.templateVariables) {
|
|
@@ -68,20 +69,24 @@ class EcomailConnector extends IEmailConnector {
|
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
71
|
}
|
|
72
|
+
console.log("ecomail - convertEmail");
|
|
71
73
|
const emEmail = this.convertEmail(email);
|
|
72
74
|
const uri = emEmail.message.template_id ? "https://api2.ecomailapp.cz/transactional/send-template" : "https://api2.ecomailapp.cz/transactional/send-message";
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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");
|
|
83
89
|
if (error) throw error;
|
|
84
|
-
return data;
|
|
85
90
|
}
|
|
86
91
|
convertEmail(email) {
|
|
87
92
|
const toContacts = this.convertContacts(email.to);
|
|
@@ -402,20 +407,18 @@ class NotificationServiceBase extends backendSdk.develitWorker(
|
|
|
402
407
|
initiator: { service, userId }
|
|
403
408
|
}
|
|
404
409
|
} = params;
|
|
405
|
-
if (!this.emailConnector)
|
|
410
|
+
if (!this.emailConnector) {
|
|
406
411
|
this.emailConnector = await initiateEmailConnector(
|
|
407
412
|
this.env.EMAIL_PROVIDER,
|
|
408
413
|
this.env.EMAIL_API_KEY,
|
|
409
414
|
this.env.EMAIL_SMTP_HOST,
|
|
410
415
|
this.env.EMAIL_SENDER
|
|
411
416
|
);
|
|
412
|
-
const response = await this.emailConnector.sendEmail(email);
|
|
413
|
-
if (!response?.ok) {
|
|
414
|
-
throw backendSdk.createInternalError(null, {
|
|
415
|
-
message: `Could not send email: ${JSON.stringify(await response?.json())}`,
|
|
416
|
-
status: 500
|
|
417
|
-
});
|
|
418
417
|
}
|
|
418
|
+
await this.emailConnector.sendEmail(email);
|
|
419
|
+
this.log({
|
|
420
|
+
message: `Email sent to ${email.to}`
|
|
421
|
+
});
|
|
419
422
|
const { command } = await createAuditLogCommand({
|
|
420
423
|
db: this.db,
|
|
421
424
|
auditLog: {
|
package/dist/export/worker.d.cts
CHANGED
|
@@ -63,7 +63,7 @@ declare abstract class IEmailConnector {
|
|
|
63
63
|
SMTP_HOST: string;
|
|
64
64
|
SENDER: IContact;
|
|
65
65
|
});
|
|
66
|
-
abstract sendEmail(email: IEmail): Promise<
|
|
66
|
+
abstract sendEmail(email: IEmail): Promise<void>;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
declare const sendEmailInputSchema: z$1.ZodObject<{
|
package/dist/export/worker.d.mts
CHANGED
|
@@ -63,7 +63,7 @@ declare abstract class IEmailConnector {
|
|
|
63
63
|
SMTP_HOST: string;
|
|
64
64
|
SENDER: IContact;
|
|
65
65
|
});
|
|
66
|
-
abstract sendEmail(email: IEmail): Promise<
|
|
66
|
+
abstract sendEmail(email: IEmail): Promise<void>;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
declare const sendEmailInputSchema: z$1.ZodObject<{
|
package/dist/export/worker.d.ts
CHANGED
|
@@ -63,7 +63,7 @@ declare abstract class IEmailConnector {
|
|
|
63
63
|
SMTP_HOST: string;
|
|
64
64
|
SENDER: IContact;
|
|
65
65
|
});
|
|
66
|
-
abstract sendEmail(email: IEmail): Promise<
|
|
66
|
+
abstract sendEmail(email: IEmail): Promise<void>;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
declare const sendEmailInputSchema: z$1.ZodObject<{
|
package/dist/export/worker.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useFetch, createInternalError, uuidv4, develitWorker, useResult, cloudflareQueue, action } from '@develit-io/backend-sdk';
|
|
2
2
|
import z$1, { z } from 'zod';
|
|
3
3
|
import { z as z$2 } from 'zod/v4';
|
|
4
4
|
import twilio from 'twilio';
|
|
@@ -52,6 +52,7 @@ class EcomailConnector extends IEmailConnector {
|
|
|
52
52
|
super({ API_KEY, SMTP_HOST, SENDER });
|
|
53
53
|
}
|
|
54
54
|
async sendEmail(email) {
|
|
55
|
+
console.log("ecomail - sendEmail");
|
|
55
56
|
if (email.templateVariables) {
|
|
56
57
|
for (const [key, value] of Object.entries(email.templateVariables)) {
|
|
57
58
|
if (typeof value === "string" && String(value).includes("localhost") && key in email.templateVariables) {
|
|
@@ -59,20 +60,24 @@ class EcomailConnector extends IEmailConnector {
|
|
|
59
60
|
}
|
|
60
61
|
}
|
|
61
62
|
}
|
|
63
|
+
console.log("ecomail - convertEmail");
|
|
62
64
|
const emEmail = this.convertEmail(email);
|
|
63
65
|
const uri = emEmail.message.template_id ? "https://api2.ecomailapp.cz/transactional/send-template" : "https://api2.ecomailapp.cz/transactional/send-message";
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
66
|
+
console.log("ecomail - start with fetch", {
|
|
67
|
+
uri,
|
|
68
|
+
emEmail,
|
|
69
|
+
apiKey: this.API_KEY
|
|
70
|
+
});
|
|
71
|
+
const [_, error] = await useFetch(uri, {
|
|
72
|
+
method: "POST",
|
|
73
|
+
headers: {
|
|
74
|
+
"Content-Type": "application/json",
|
|
75
|
+
key: this.API_KEY
|
|
76
|
+
},
|
|
77
|
+
body: JSON.stringify(emEmail)
|
|
78
|
+
});
|
|
79
|
+
console.log("ecomail - fetch done");
|
|
74
80
|
if (error) throw error;
|
|
75
|
-
return data;
|
|
76
81
|
}
|
|
77
82
|
convertEmail(email) {
|
|
78
83
|
const toContacts = this.convertContacts(email.to);
|
|
@@ -393,20 +398,18 @@ class NotificationServiceBase extends develitWorker(
|
|
|
393
398
|
initiator: { service, userId }
|
|
394
399
|
}
|
|
395
400
|
} = params;
|
|
396
|
-
if (!this.emailConnector)
|
|
401
|
+
if (!this.emailConnector) {
|
|
397
402
|
this.emailConnector = await initiateEmailConnector(
|
|
398
403
|
this.env.EMAIL_PROVIDER,
|
|
399
404
|
this.env.EMAIL_API_KEY,
|
|
400
405
|
this.env.EMAIL_SMTP_HOST,
|
|
401
406
|
this.env.EMAIL_SENDER
|
|
402
407
|
);
|
|
403
|
-
const response = await this.emailConnector.sendEmail(email);
|
|
404
|
-
if (!response?.ok) {
|
|
405
|
-
throw createInternalError(null, {
|
|
406
|
-
message: `Could not send email: ${JSON.stringify(await response?.json())}`,
|
|
407
|
-
status: 500
|
|
408
|
-
});
|
|
409
408
|
}
|
|
409
|
+
await this.emailConnector.sendEmail(email);
|
|
410
|
+
this.log({
|
|
411
|
+
message: `Email sent to ${email.to}`
|
|
412
|
+
});
|
|
410
413
|
const { command } = await createAuditLogCommand({
|
|
411
414
|
db: this.db,
|
|
412
415
|
auditLog: {
|
package/dist/export/wrangler.cjs
CHANGED
|
@@ -7,6 +7,23 @@ function defineNotificationServiceWrangler(config) {
|
|
|
7
7
|
main: "./src/index.ts",
|
|
8
8
|
compatibility_date: "2025-06-04",
|
|
9
9
|
compatibility_flags: ["nodejs_compat"],
|
|
10
|
+
observability: {
|
|
11
|
+
enabled: true,
|
|
12
|
+
head_sampling_rate: 1,
|
|
13
|
+
logs: {
|
|
14
|
+
invocation_logs: false
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
preview_urls: false,
|
|
18
|
+
workers_dev: false,
|
|
19
|
+
vars: {
|
|
20
|
+
//secrets
|
|
21
|
+
EMAIL_API_KEY: "",
|
|
22
|
+
SMS_AUTH_TOKEN: "",
|
|
23
|
+
//vars
|
|
24
|
+
...envs.local.vars,
|
|
25
|
+
ENVIRONMENT: "local"
|
|
26
|
+
},
|
|
10
27
|
d1_databases: [
|
|
11
28
|
{
|
|
12
29
|
binding: "NOTIFICATION_D1",
|
|
@@ -13,10 +13,8 @@ interface NotificationServiceEnvironmentConfig {
|
|
|
13
13
|
email: string;
|
|
14
14
|
};
|
|
15
15
|
EMAIL_SMTP_HOST: string;
|
|
16
|
-
EMAIL_API_KEY: string;
|
|
17
16
|
SMS_PROVIDER: 'twilio';
|
|
18
17
|
SMS_ACCOUNT_ID: string;
|
|
19
|
-
SMS_AUTH_TOKEN: string;
|
|
20
18
|
SMS_SERVICE_ID: string | number;
|
|
21
19
|
SLACK_WEBHOOKS: [string];
|
|
22
20
|
};
|
|
@@ -36,6 +34,30 @@ declare function defineNotificationServiceWrangler(config: NotificationServiceWr
|
|
|
36
34
|
main: string;
|
|
37
35
|
compatibility_date: string;
|
|
38
36
|
compatibility_flags: string[];
|
|
37
|
+
observability: {
|
|
38
|
+
enabled: boolean;
|
|
39
|
+
head_sampling_rate: number;
|
|
40
|
+
logs: {
|
|
41
|
+
invocation_logs: boolean;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
preview_urls: boolean;
|
|
45
|
+
workers_dev: boolean;
|
|
46
|
+
vars: {
|
|
47
|
+
ENVIRONMENT: string;
|
|
48
|
+
EMAIL_PROVIDER: "ecomail";
|
|
49
|
+
EMAIL_SENDER: {
|
|
50
|
+
name: string;
|
|
51
|
+
email: string;
|
|
52
|
+
};
|
|
53
|
+
EMAIL_SMTP_HOST: string;
|
|
54
|
+
SMS_PROVIDER: "twilio";
|
|
55
|
+
SMS_ACCOUNT_ID: string;
|
|
56
|
+
SMS_SERVICE_ID: string | number;
|
|
57
|
+
SLACK_WEBHOOKS: [string];
|
|
58
|
+
EMAIL_API_KEY: string;
|
|
59
|
+
SMS_AUTH_TOKEN: string;
|
|
60
|
+
};
|
|
39
61
|
d1_databases: {
|
|
40
62
|
binding: string;
|
|
41
63
|
database_name: string;
|
|
@@ -13,10 +13,8 @@ interface NotificationServiceEnvironmentConfig {
|
|
|
13
13
|
email: string;
|
|
14
14
|
};
|
|
15
15
|
EMAIL_SMTP_HOST: string;
|
|
16
|
-
EMAIL_API_KEY: string;
|
|
17
16
|
SMS_PROVIDER: 'twilio';
|
|
18
17
|
SMS_ACCOUNT_ID: string;
|
|
19
|
-
SMS_AUTH_TOKEN: string;
|
|
20
18
|
SMS_SERVICE_ID: string | number;
|
|
21
19
|
SLACK_WEBHOOKS: [string];
|
|
22
20
|
};
|
|
@@ -36,6 +34,30 @@ declare function defineNotificationServiceWrangler(config: NotificationServiceWr
|
|
|
36
34
|
main: string;
|
|
37
35
|
compatibility_date: string;
|
|
38
36
|
compatibility_flags: string[];
|
|
37
|
+
observability: {
|
|
38
|
+
enabled: boolean;
|
|
39
|
+
head_sampling_rate: number;
|
|
40
|
+
logs: {
|
|
41
|
+
invocation_logs: boolean;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
preview_urls: boolean;
|
|
45
|
+
workers_dev: boolean;
|
|
46
|
+
vars: {
|
|
47
|
+
ENVIRONMENT: string;
|
|
48
|
+
EMAIL_PROVIDER: "ecomail";
|
|
49
|
+
EMAIL_SENDER: {
|
|
50
|
+
name: string;
|
|
51
|
+
email: string;
|
|
52
|
+
};
|
|
53
|
+
EMAIL_SMTP_HOST: string;
|
|
54
|
+
SMS_PROVIDER: "twilio";
|
|
55
|
+
SMS_ACCOUNT_ID: string;
|
|
56
|
+
SMS_SERVICE_ID: string | number;
|
|
57
|
+
SLACK_WEBHOOKS: [string];
|
|
58
|
+
EMAIL_API_KEY: string;
|
|
59
|
+
SMS_AUTH_TOKEN: string;
|
|
60
|
+
};
|
|
39
61
|
d1_databases: {
|
|
40
62
|
binding: string;
|
|
41
63
|
database_name: string;
|
|
@@ -13,10 +13,8 @@ interface NotificationServiceEnvironmentConfig {
|
|
|
13
13
|
email: string;
|
|
14
14
|
};
|
|
15
15
|
EMAIL_SMTP_HOST: string;
|
|
16
|
-
EMAIL_API_KEY: string;
|
|
17
16
|
SMS_PROVIDER: 'twilio';
|
|
18
17
|
SMS_ACCOUNT_ID: string;
|
|
19
|
-
SMS_AUTH_TOKEN: string;
|
|
20
18
|
SMS_SERVICE_ID: string | number;
|
|
21
19
|
SLACK_WEBHOOKS: [string];
|
|
22
20
|
};
|
|
@@ -36,6 +34,30 @@ declare function defineNotificationServiceWrangler(config: NotificationServiceWr
|
|
|
36
34
|
main: string;
|
|
37
35
|
compatibility_date: string;
|
|
38
36
|
compatibility_flags: string[];
|
|
37
|
+
observability: {
|
|
38
|
+
enabled: boolean;
|
|
39
|
+
head_sampling_rate: number;
|
|
40
|
+
logs: {
|
|
41
|
+
invocation_logs: boolean;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
preview_urls: boolean;
|
|
45
|
+
workers_dev: boolean;
|
|
46
|
+
vars: {
|
|
47
|
+
ENVIRONMENT: string;
|
|
48
|
+
EMAIL_PROVIDER: "ecomail";
|
|
49
|
+
EMAIL_SENDER: {
|
|
50
|
+
name: string;
|
|
51
|
+
email: string;
|
|
52
|
+
};
|
|
53
|
+
EMAIL_SMTP_HOST: string;
|
|
54
|
+
SMS_PROVIDER: "twilio";
|
|
55
|
+
SMS_ACCOUNT_ID: string;
|
|
56
|
+
SMS_SERVICE_ID: string | number;
|
|
57
|
+
SLACK_WEBHOOKS: [string];
|
|
58
|
+
EMAIL_API_KEY: string;
|
|
59
|
+
SMS_AUTH_TOKEN: string;
|
|
60
|
+
};
|
|
39
61
|
d1_databases: {
|
|
40
62
|
binding: string;
|
|
41
63
|
database_name: string;
|
package/dist/export/wrangler.mjs
CHANGED
|
@@ -5,6 +5,23 @@ function defineNotificationServiceWrangler(config) {
|
|
|
5
5
|
main: "./src/index.ts",
|
|
6
6
|
compatibility_date: "2025-06-04",
|
|
7
7
|
compatibility_flags: ["nodejs_compat"],
|
|
8
|
+
observability: {
|
|
9
|
+
enabled: true,
|
|
10
|
+
head_sampling_rate: 1,
|
|
11
|
+
logs: {
|
|
12
|
+
invocation_logs: false
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
preview_urls: false,
|
|
16
|
+
workers_dev: false,
|
|
17
|
+
vars: {
|
|
18
|
+
//secrets
|
|
19
|
+
EMAIL_API_KEY: "",
|
|
20
|
+
SMS_AUTH_TOKEN: "",
|
|
21
|
+
//vars
|
|
22
|
+
...envs.local.vars,
|
|
23
|
+
ENVIRONMENT: "local"
|
|
24
|
+
},
|
|
8
25
|
d1_databases: [
|
|
9
26
|
{
|
|
10
27
|
binding: "NOTIFICATION_D1",
|