@develit-services/notification 0.0.34 → 0.0.35
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 -33
- package/dist/export/worker.d.cts +1 -0
- package/dist/export/worker.d.mts +1 -0
- package/dist/export/worker.d.ts +1 -0
- package/dist/export/worker.mjs +25 -34
- package/package.json +2 -2
package/dist/export/worker.cjs
CHANGED
|
@@ -98,39 +98,6 @@ class NotificationServiceBase extends backendSdk.develitWorker(
|
|
|
98
98
|
this.logInput({ message });
|
|
99
99
|
let notificationAction;
|
|
100
100
|
const { type, metadata, payload } = message.body;
|
|
101
|
-
if (type === "email") {
|
|
102
|
-
const [emailConnector, error2] = await backendSdk.useResult(
|
|
103
|
-
initiateEmailConnector(
|
|
104
|
-
this.env.EMAIL_PROVIDER,
|
|
105
|
-
this.env.EMAIL_API_KEY,
|
|
106
|
-
this.env.EMAIL_SMTP_HOST,
|
|
107
|
-
this.env.EMAIL_SENDER_EMAIL,
|
|
108
|
-
this.env.EMAIL_SENDER_NAME
|
|
109
|
-
)
|
|
110
|
-
);
|
|
111
|
-
if (error2) {
|
|
112
|
-
this.logError({ error: error2 });
|
|
113
|
-
message.retry();
|
|
114
|
-
continue;
|
|
115
|
-
}
|
|
116
|
-
this.emailConnector = emailConnector;
|
|
117
|
-
}
|
|
118
|
-
if (type === "sms") {
|
|
119
|
-
const [smsConnector, error2] = await backendSdk.useResult(
|
|
120
|
-
initiateSmsConnector(
|
|
121
|
-
this.env.SMS_PROVIDER,
|
|
122
|
-
this.env.SMS_ACCOUNT_ID,
|
|
123
|
-
this.env.SMS_AUTH_TOKEN,
|
|
124
|
-
this.env.SMS_SERVICE_ID
|
|
125
|
-
)
|
|
126
|
-
);
|
|
127
|
-
if (error2) {
|
|
128
|
-
this.logError({ error: error2 });
|
|
129
|
-
message.retry();
|
|
130
|
-
continue;
|
|
131
|
-
}
|
|
132
|
-
this.smsConnector = smsConnector;
|
|
133
|
-
}
|
|
134
101
|
switch (type) {
|
|
135
102
|
case "email":
|
|
136
103
|
notificationAction = async () => this._sendEmail({
|
|
@@ -220,6 +187,14 @@ class NotificationServiceBase extends backendSdk.develitWorker(
|
|
|
220
187
|
initiator: { service, userId }
|
|
221
188
|
}
|
|
222
189
|
} = params;
|
|
190
|
+
if (!this.smsConnector) {
|
|
191
|
+
this.smsConnector = await initiateSmsConnector(
|
|
192
|
+
this.env.SMS_PROVIDER,
|
|
193
|
+
this.env.SMS_ACCOUNT_ID,
|
|
194
|
+
this.env.SMS_AUTH_TOKEN,
|
|
195
|
+
this.env.SMS_SERVICE_ID
|
|
196
|
+
);
|
|
197
|
+
}
|
|
223
198
|
await this.smsConnector.sendSms({ message, to });
|
|
224
199
|
const { command } = await createAuditLogCommand({
|
|
225
200
|
db: this.db,
|
|
@@ -258,6 +233,19 @@ class NotificationServiceBase extends backendSdk.develitWorker(
|
|
|
258
233
|
}
|
|
259
234
|
);
|
|
260
235
|
}
|
|
236
|
+
async sendEmailSync(input) {
|
|
237
|
+
return this.handleAction(
|
|
238
|
+
{ data: input, schema: slack_connector.sendEmailInputSchema },
|
|
239
|
+
{ successMessage: "Email sent." },
|
|
240
|
+
async (params) => {
|
|
241
|
+
const { email, metadata } = params;
|
|
242
|
+
return this._sendEmail({
|
|
243
|
+
email,
|
|
244
|
+
metadata
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
);
|
|
248
|
+
}
|
|
261
249
|
async sendSms(input) {
|
|
262
250
|
return this.handleAction(
|
|
263
251
|
{ data: input, schema: slack_connector.sendSmsInputSchema },
|
|
@@ -316,6 +304,9 @@ __decorateClass([
|
|
|
316
304
|
__decorateClass([
|
|
317
305
|
backendSdk.action("public-send-email")
|
|
318
306
|
], NotificationServiceBase.prototype, "sendEmail");
|
|
307
|
+
__decorateClass([
|
|
308
|
+
backendSdk.action("public-send-email-sync")
|
|
309
|
+
], NotificationServiceBase.prototype, "sendEmailSync");
|
|
319
310
|
__decorateClass([
|
|
320
311
|
backendSdk.action("public-send-sms")
|
|
321
312
|
], NotificationServiceBase.prototype, "sendSms");
|
package/dist/export/worker.d.cts
CHANGED
|
@@ -20,6 +20,7 @@ declare class NotificationServiceBase extends NotificationServiceBase_base {
|
|
|
20
20
|
protected _sendEmail(input: SendEmailInput): Promise<IRPCResponse<SendEmailOutput>>;
|
|
21
21
|
protected _sendSms(input: SendSmsInput): Promise<IRPCResponse<SendSmsOutput>>;
|
|
22
22
|
sendEmail(input: SendEmailInput): Promise<IRPCResponse<SendEmailOutput>>;
|
|
23
|
+
sendEmailSync(input: SendEmailInput): Promise<IRPCResponse<SendEmailOutput>>;
|
|
23
24
|
sendSms(input: SendSmsInput): Promise<IRPCResponse<SendSmsOutput>>;
|
|
24
25
|
protected _sendPushNotification(): Promise<IRPCResponse<{}>>;
|
|
25
26
|
sendSlackNotification(input: SendSlackInput): Promise<IRPCResponse<SendSlackOutput>>;
|
package/dist/export/worker.d.mts
CHANGED
|
@@ -20,6 +20,7 @@ declare class NotificationServiceBase extends NotificationServiceBase_base {
|
|
|
20
20
|
protected _sendEmail(input: SendEmailInput): Promise<IRPCResponse<SendEmailOutput>>;
|
|
21
21
|
protected _sendSms(input: SendSmsInput): Promise<IRPCResponse<SendSmsOutput>>;
|
|
22
22
|
sendEmail(input: SendEmailInput): Promise<IRPCResponse<SendEmailOutput>>;
|
|
23
|
+
sendEmailSync(input: SendEmailInput): Promise<IRPCResponse<SendEmailOutput>>;
|
|
23
24
|
sendSms(input: SendSmsInput): Promise<IRPCResponse<SendSmsOutput>>;
|
|
24
25
|
protected _sendPushNotification(): Promise<IRPCResponse<{}>>;
|
|
25
26
|
sendSlackNotification(input: SendSlackInput): Promise<IRPCResponse<SendSlackOutput>>;
|
package/dist/export/worker.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ declare class NotificationServiceBase extends NotificationServiceBase_base {
|
|
|
20
20
|
protected _sendEmail(input: SendEmailInput): Promise<IRPCResponse<SendEmailOutput>>;
|
|
21
21
|
protected _sendSms(input: SendSmsInput): Promise<IRPCResponse<SendSmsOutput>>;
|
|
22
22
|
sendEmail(input: SendEmailInput): Promise<IRPCResponse<SendEmailOutput>>;
|
|
23
|
+
sendEmailSync(input: SendEmailInput): Promise<IRPCResponse<SendEmailOutput>>;
|
|
23
24
|
sendSms(input: SendSmsInput): Promise<IRPCResponse<SendSmsOutput>>;
|
|
24
25
|
protected _sendPushNotification(): Promise<IRPCResponse<{}>>;
|
|
25
26
|
sendSlackNotification(input: SendSlackInput): Promise<IRPCResponse<SendSlackOutput>>;
|
package/dist/export/worker.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createInternalError, uuidv4, develitWorker,
|
|
1
|
+
import { createInternalError, uuidv4, develitWorker, cloudflareQueue, action } from '@develit-io/backend-sdk';
|
|
2
2
|
import { E as EcomailConnector, T as TwilioConnector, S as SlackConnector, s as sendEmailInputSchema, a as sendSmsInputSchema, b as sendSlackInputSchema } from '../shared/notification.Di9LpjrD.mjs';
|
|
3
3
|
import { s as schema } from '../shared/notification.C0X8Orrh.mjs';
|
|
4
4
|
import 'drizzle-orm';
|
|
@@ -94,39 +94,6 @@ class NotificationServiceBase extends develitWorker(
|
|
|
94
94
|
this.logInput({ message });
|
|
95
95
|
let notificationAction;
|
|
96
96
|
const { type, metadata, payload } = message.body;
|
|
97
|
-
if (type === "email") {
|
|
98
|
-
const [emailConnector, error2] = await useResult(
|
|
99
|
-
initiateEmailConnector(
|
|
100
|
-
this.env.EMAIL_PROVIDER,
|
|
101
|
-
this.env.EMAIL_API_KEY,
|
|
102
|
-
this.env.EMAIL_SMTP_HOST,
|
|
103
|
-
this.env.EMAIL_SENDER_EMAIL,
|
|
104
|
-
this.env.EMAIL_SENDER_NAME
|
|
105
|
-
)
|
|
106
|
-
);
|
|
107
|
-
if (error2) {
|
|
108
|
-
this.logError({ error: error2 });
|
|
109
|
-
message.retry();
|
|
110
|
-
continue;
|
|
111
|
-
}
|
|
112
|
-
this.emailConnector = emailConnector;
|
|
113
|
-
}
|
|
114
|
-
if (type === "sms") {
|
|
115
|
-
const [smsConnector, error2] = await useResult(
|
|
116
|
-
initiateSmsConnector(
|
|
117
|
-
this.env.SMS_PROVIDER,
|
|
118
|
-
this.env.SMS_ACCOUNT_ID,
|
|
119
|
-
this.env.SMS_AUTH_TOKEN,
|
|
120
|
-
this.env.SMS_SERVICE_ID
|
|
121
|
-
)
|
|
122
|
-
);
|
|
123
|
-
if (error2) {
|
|
124
|
-
this.logError({ error: error2 });
|
|
125
|
-
message.retry();
|
|
126
|
-
continue;
|
|
127
|
-
}
|
|
128
|
-
this.smsConnector = smsConnector;
|
|
129
|
-
}
|
|
130
97
|
switch (type) {
|
|
131
98
|
case "email":
|
|
132
99
|
notificationAction = async () => this._sendEmail({
|
|
@@ -216,6 +183,14 @@ class NotificationServiceBase extends develitWorker(
|
|
|
216
183
|
initiator: { service, userId }
|
|
217
184
|
}
|
|
218
185
|
} = params;
|
|
186
|
+
if (!this.smsConnector) {
|
|
187
|
+
this.smsConnector = await initiateSmsConnector(
|
|
188
|
+
this.env.SMS_PROVIDER,
|
|
189
|
+
this.env.SMS_ACCOUNT_ID,
|
|
190
|
+
this.env.SMS_AUTH_TOKEN,
|
|
191
|
+
this.env.SMS_SERVICE_ID
|
|
192
|
+
);
|
|
193
|
+
}
|
|
219
194
|
await this.smsConnector.sendSms({ message, to });
|
|
220
195
|
const { command } = await createAuditLogCommand({
|
|
221
196
|
db: this.db,
|
|
@@ -254,6 +229,19 @@ class NotificationServiceBase extends develitWorker(
|
|
|
254
229
|
}
|
|
255
230
|
);
|
|
256
231
|
}
|
|
232
|
+
async sendEmailSync(input) {
|
|
233
|
+
return this.handleAction(
|
|
234
|
+
{ data: input, schema: sendEmailInputSchema },
|
|
235
|
+
{ successMessage: "Email sent." },
|
|
236
|
+
async (params) => {
|
|
237
|
+
const { email, metadata } = params;
|
|
238
|
+
return this._sendEmail({
|
|
239
|
+
email,
|
|
240
|
+
metadata
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
);
|
|
244
|
+
}
|
|
257
245
|
async sendSms(input) {
|
|
258
246
|
return this.handleAction(
|
|
259
247
|
{ data: input, schema: sendSmsInputSchema },
|
|
@@ -312,6 +300,9 @@ __decorateClass([
|
|
|
312
300
|
__decorateClass([
|
|
313
301
|
action("public-send-email")
|
|
314
302
|
], NotificationServiceBase.prototype, "sendEmail");
|
|
303
|
+
__decorateClass([
|
|
304
|
+
action("public-send-email-sync")
|
|
305
|
+
], NotificationServiceBase.prototype, "sendEmailSync");
|
|
315
306
|
__decorateClass([
|
|
316
307
|
action("public-send-sms")
|
|
317
308
|
], NotificationServiceBase.prototype, "sendSms");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@develit-services/notification",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.35",
|
|
4
4
|
"author": "Develit.io s.r.o.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"./dist"
|
|
31
31
|
],
|
|
32
32
|
"scripts": {
|
|
33
|
-
"dev": "wrangler dev --port
|
|
33
|
+
"dev": "wrangler dev --port 9235 --persist-to ../../.wrangler/state",
|
|
34
34
|
"wrangler:generate": "develit wrangler:generate",
|
|
35
35
|
"db:init": "wrangler d1 execute develit-notification --local --persist-to ../../.wrangler/state --command=\"SELECT 'Creating database...' AS status;\"",
|
|
36
36
|
"db:generate": "drizzle-kit generate",
|