@develit-services/notification 0.6.0 → 0.6.1

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.
@@ -145,24 +145,28 @@ let NotificationServiceBase = class extends backendSdk.develitWorker(
145
145
  );
146
146
  }
147
147
  await this.emailConnector.sendEmail(email);
148
- await this.pushToQueue(this.env.AUDIT_LOGS_QUEUE, {
149
- logType: "event",
150
- service: "notification",
151
- correlationId: backendSdk.uuidv4(),
152
- eventType: "notification.email_sent",
153
- actorUserId: userId,
154
- actorEmail: userId || "SYSTEM",
155
- targetType: "email",
156
- targetId: email.to,
157
- sourceIp: ip,
158
- userAgent,
159
- outcome: "success",
160
- description: `Email sent to ${email.to}`,
161
- details: JSON.stringify({
162
- subject: email.subject,
163
- templateId: email.templateId
164
- })
165
- });
148
+ try {
149
+ await this.pushToQueue(this.env.AUDIT_LOGS_QUEUE, {
150
+ logType: "event",
151
+ service: "notification",
152
+ correlationId: backendSdk.uuidv4(),
153
+ eventType: "notification.email_sent",
154
+ actorUserId: userId,
155
+ actorEmail: userId || "SYSTEM",
156
+ targetType: "email",
157
+ targetId: email.to,
158
+ sourceIp: ip,
159
+ userAgent,
160
+ outcome: "success",
161
+ description: `Email sent to ${email.to}`,
162
+ details: JSON.stringify({
163
+ subject: email.subject,
164
+ templateId: email.templateId
165
+ })
166
+ });
167
+ } catch (e) {
168
+ console.error("Failed to push email audit log", e);
169
+ }
166
170
  return {};
167
171
  }
168
172
  );
@@ -195,21 +199,25 @@ let NotificationServiceBase = class extends backendSdk.develitWorker(
195
199
  );
196
200
  }
197
201
  await this.smsConnector.sendSms({ message, to });
198
- await this.pushToQueue(this.env.AUDIT_LOGS_QUEUE, {
199
- logType: "event",
200
- service: "notification",
201
- correlationId: backendSdk.uuidv4(),
202
- eventType: "notification.sms_sent",
203
- actorUserId: userId,
204
- actorEmail: userId || "SYSTEM",
205
- targetType: "sms",
206
- targetId: to,
207
- sourceIp: ip,
208
- userAgent,
209
- outcome: "success",
210
- description: `SMS sent to ${to}`,
211
- details: JSON.stringify({ message })
212
- });
202
+ try {
203
+ await this.pushToQueue(this.env.AUDIT_LOGS_QUEUE, {
204
+ logType: "event",
205
+ service: "notification",
206
+ correlationId: backendSdk.uuidv4(),
207
+ eventType: "notification.sms_sent",
208
+ actorUserId: userId,
209
+ actorEmail: userId || "SYSTEM",
210
+ targetType: "sms",
211
+ targetId: to,
212
+ sourceIp: ip,
213
+ userAgent,
214
+ outcome: "success",
215
+ description: `SMS sent to ${to}`,
216
+ details: JSON.stringify({ message })
217
+ });
218
+ } catch (e) {
219
+ console.error("Failed to push sms audit log", e);
220
+ }
213
221
  return {};
214
222
  }
215
223
  );
@@ -290,8 +298,25 @@ let NotificationServiceBase = class extends backendSdk.develitWorker(
290
298
  },
291
299
  { successMessage: "Slack sent." },
292
300
  async (params) => {
293
- const { slack } = params;
301
+ const { slack, metadata } = params;
294
302
  await this.slackConnector.sendNotificationToAllSlack(slack.message);
303
+ await this.pushToQueue(this.env.AUDIT_LOGS_QUEUE, {
304
+ logType: "event",
305
+ service: "notification",
306
+ correlationId: backendSdk.uuidv4(),
307
+ eventType: "notification.slack_sent",
308
+ actorUserId: metadata?.initiator?.userId,
309
+ actorEmail: metadata?.initiator?.userId || "SYSTEM",
310
+ targetType: "slack",
311
+ targetId: "all-channels",
312
+ sourceIp: metadata?.ip,
313
+ userAgent: metadata?.userAgent,
314
+ outcome: "success",
315
+ description: "Slack notification sent",
316
+ details: JSON.stringify({
317
+ message: slack.message
318
+ })
319
+ });
295
320
  return {};
296
321
  }
297
322
  );
@@ -343,23 +368,27 @@ let NotificationServiceBase = class extends backendSdk.develitWorker(
343
368
  this.webhookConnector = new webhook_connector.WebhookConnector(privateKey);
344
369
  }
345
370
  await this.webhookConnector.sendWebhook(webhook);
346
- await this.pushToQueue(this.env.AUDIT_LOGS_QUEUE, {
347
- logType: "event",
348
- service: "notification",
349
- correlationId: backendSdk.uuidv4(),
350
- eventType: "notification.webhook_sent",
351
- actorUserId: userId,
352
- actorEmail: userId || "SYSTEM",
353
- targetType: "webhook",
354
- targetId: webhook.url,
355
- sourceIp: ip,
356
- userAgent,
357
- outcome: "success",
358
- description: `Webhook sent to ${webhook.url}`,
359
- details: JSON.stringify({
360
- url: webhook.url
361
- })
362
- });
371
+ try {
372
+ await this.pushToQueue(this.env.AUDIT_LOGS_QUEUE, {
373
+ logType: "event",
374
+ service: "notification",
375
+ correlationId: backendSdk.uuidv4(),
376
+ eventType: "notification.webhook_sent",
377
+ actorUserId: userId,
378
+ actorEmail: userId || "SYSTEM",
379
+ targetType: "webhook",
380
+ targetId: webhook.url,
381
+ sourceIp: ip,
382
+ userAgent,
383
+ outcome: "success",
384
+ description: `Webhook sent to ${webhook.url}`,
385
+ details: JSON.stringify({
386
+ url: webhook.url
387
+ })
388
+ });
389
+ } catch (e) {
390
+ console.error("Failed to push webhook audit log", e);
391
+ }
363
392
  return {};
364
393
  }
365
394
  );
@@ -141,24 +141,28 @@ let NotificationServiceBase = class extends develitWorker(
141
141
  );
142
142
  }
143
143
  await this.emailConnector.sendEmail(email);
144
- await this.pushToQueue(this.env.AUDIT_LOGS_QUEUE, {
145
- logType: "event",
146
- service: "notification",
147
- correlationId: uuidv4(),
148
- eventType: "notification.email_sent",
149
- actorUserId: userId,
150
- actorEmail: userId || "SYSTEM",
151
- targetType: "email",
152
- targetId: email.to,
153
- sourceIp: ip,
154
- userAgent,
155
- outcome: "success",
156
- description: `Email sent to ${email.to}`,
157
- details: JSON.stringify({
158
- subject: email.subject,
159
- templateId: email.templateId
160
- })
161
- });
144
+ try {
145
+ await this.pushToQueue(this.env.AUDIT_LOGS_QUEUE, {
146
+ logType: "event",
147
+ service: "notification",
148
+ correlationId: uuidv4(),
149
+ eventType: "notification.email_sent",
150
+ actorUserId: userId,
151
+ actorEmail: userId || "SYSTEM",
152
+ targetType: "email",
153
+ targetId: email.to,
154
+ sourceIp: ip,
155
+ userAgent,
156
+ outcome: "success",
157
+ description: `Email sent to ${email.to}`,
158
+ details: JSON.stringify({
159
+ subject: email.subject,
160
+ templateId: email.templateId
161
+ })
162
+ });
163
+ } catch (e) {
164
+ console.error("Failed to push email audit log", e);
165
+ }
162
166
  return {};
163
167
  }
164
168
  );
@@ -191,21 +195,25 @@ let NotificationServiceBase = class extends develitWorker(
191
195
  );
192
196
  }
193
197
  await this.smsConnector.sendSms({ message, to });
194
- await this.pushToQueue(this.env.AUDIT_LOGS_QUEUE, {
195
- logType: "event",
196
- service: "notification",
197
- correlationId: uuidv4(),
198
- eventType: "notification.sms_sent",
199
- actorUserId: userId,
200
- actorEmail: userId || "SYSTEM",
201
- targetType: "sms",
202
- targetId: to,
203
- sourceIp: ip,
204
- userAgent,
205
- outcome: "success",
206
- description: `SMS sent to ${to}`,
207
- details: JSON.stringify({ message })
208
- });
198
+ try {
199
+ await this.pushToQueue(this.env.AUDIT_LOGS_QUEUE, {
200
+ logType: "event",
201
+ service: "notification",
202
+ correlationId: uuidv4(),
203
+ eventType: "notification.sms_sent",
204
+ actorUserId: userId,
205
+ actorEmail: userId || "SYSTEM",
206
+ targetType: "sms",
207
+ targetId: to,
208
+ sourceIp: ip,
209
+ userAgent,
210
+ outcome: "success",
211
+ description: `SMS sent to ${to}`,
212
+ details: JSON.stringify({ message })
213
+ });
214
+ } catch (e) {
215
+ console.error("Failed to push sms audit log", e);
216
+ }
209
217
  return {};
210
218
  }
211
219
  );
@@ -286,8 +294,25 @@ let NotificationServiceBase = class extends develitWorker(
286
294
  },
287
295
  { successMessage: "Slack sent." },
288
296
  async (params) => {
289
- const { slack } = params;
297
+ const { slack, metadata } = params;
290
298
  await this.slackConnector.sendNotificationToAllSlack(slack.message);
299
+ await this.pushToQueue(this.env.AUDIT_LOGS_QUEUE, {
300
+ logType: "event",
301
+ service: "notification",
302
+ correlationId: uuidv4(),
303
+ eventType: "notification.slack_sent",
304
+ actorUserId: metadata?.initiator?.userId,
305
+ actorEmail: metadata?.initiator?.userId || "SYSTEM",
306
+ targetType: "slack",
307
+ targetId: "all-channels",
308
+ sourceIp: metadata?.ip,
309
+ userAgent: metadata?.userAgent,
310
+ outcome: "success",
311
+ description: "Slack notification sent",
312
+ details: JSON.stringify({
313
+ message: slack.message
314
+ })
315
+ });
291
316
  return {};
292
317
  }
293
318
  );
@@ -339,23 +364,27 @@ let NotificationServiceBase = class extends develitWorker(
339
364
  this.webhookConnector = new WebhookConnector(privateKey);
340
365
  }
341
366
  await this.webhookConnector.sendWebhook(webhook);
342
- await this.pushToQueue(this.env.AUDIT_LOGS_QUEUE, {
343
- logType: "event",
344
- service: "notification",
345
- correlationId: uuidv4(),
346
- eventType: "notification.webhook_sent",
347
- actorUserId: userId,
348
- actorEmail: userId || "SYSTEM",
349
- targetType: "webhook",
350
- targetId: webhook.url,
351
- sourceIp: ip,
352
- userAgent,
353
- outcome: "success",
354
- description: `Webhook sent to ${webhook.url}`,
355
- details: JSON.stringify({
356
- url: webhook.url
357
- })
358
- });
367
+ try {
368
+ await this.pushToQueue(this.env.AUDIT_LOGS_QUEUE, {
369
+ logType: "event",
370
+ service: "notification",
371
+ correlationId: uuidv4(),
372
+ eventType: "notification.webhook_sent",
373
+ actorUserId: userId,
374
+ actorEmail: userId || "SYSTEM",
375
+ targetType: "webhook",
376
+ targetId: webhook.url,
377
+ sourceIp: ip,
378
+ userAgent,
379
+ outcome: "success",
380
+ description: `Webhook sent to ${webhook.url}`,
381
+ details: JSON.stringify({
382
+ url: webhook.url
383
+ })
384
+ });
385
+ } catch (e) {
386
+ console.error("Failed to push webhook audit log", e);
387
+ }
359
388
  return {};
360
389
  }
361
390
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@develit-services/notification",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "author": "Develit.io s.r.o.",
5
5
  "type": "module",
6
6
  "exports": {