av6-core 1.6.4 → 1.6.6

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/index.js CHANGED
@@ -1590,7 +1590,6 @@ var buildJoiSchemaForOp = (cfg, op, ctx) => {
1590
1590
 
1591
1591
  // src/utils/dynamicOperation.utils.ts
1592
1592
  var import_av6_utils = require("av6-utils");
1593
- var import_decimal = __toESM(require("decimal.js"));
1594
1593
  var OP_PRECEDENCE = {
1595
1594
  "u-": 3,
1596
1595
  // unary minus
@@ -1796,9 +1795,12 @@ function getDynamicValueOrExpression(obj, accessorOrExpr) {
1796
1795
  }
1797
1796
  return getDynamicValue(obj, s);
1798
1797
  }
1798
+ function isDecimalLike(v) {
1799
+ return v !== null && typeof v === "object" && typeof v.toNumber === "function" && typeof v.toString === "function";
1800
+ }
1799
1801
  function toNumberDeep(val) {
1800
1802
  if (val === null || val === void 0) return val;
1801
- if (val instanceof import_decimal.default) return val.toNumber();
1803
+ if (isDecimalLike(val)) return val.toNumber();
1802
1804
  if (val instanceof Date) return val;
1803
1805
  if (Array.isArray(val)) return val.map(toNumberDeep);
1804
1806
  if (typeof val === "object") {
@@ -3526,26 +3528,28 @@ var NotificationService = class {
3526
3528
  // Should-send checks
3527
3529
  // --------------------------------------------------------------------------------------
3528
3530
  shouldSendEmail(cfg) {
3529
- return Boolean(cfg.allowEmail && cfg.serviceEvent.allowEmail && cfg.emailTemplateId);
3531
+ return Boolean(cfg.allowEmail && cfg.serviceEvent.allowEmail);
3530
3532
  }
3531
3533
  shouldSendSms(cfg) {
3532
- return Boolean(cfg.allowSms && cfg.serviceEvent.allowSms && cfg.smsTemplateId);
3534
+ return Boolean(cfg.allowSms && cfg.serviceEvent.allowSms);
3533
3535
  }
3534
3536
  shouldSendWhatsapp(cfg) {
3535
- return Boolean(cfg.allowWhatsapp && cfg.serviceEvent.allowWhatsapp && cfg.wpTemplateId);
3537
+ return Boolean(cfg.allowWhatsapp && cfg.serviceEvent.allowWhatsapp);
3536
3538
  }
3537
3539
  shouldSendApp(cfg) {
3538
- return Boolean(cfg.allowAppNotification && cfg.serviceEvent.allowAppNotification && cfg.appNotificationTemplateId);
3540
+ return Boolean(cfg.allowAppNotification && cfg.serviceEvent.allowAppNotification);
3539
3541
  }
3540
3542
  shouldSendWeb(cfg) {
3541
- return Boolean(cfg.allowWebNotification && cfg.serviceEvent.allowWebNotification && cfg.webNotificationTemplateId);
3543
+ return Boolean(cfg.allowWebNotification && cfg.serviceEvent.allowWebNotification);
3542
3544
  }
3543
3545
  // --------------------------------------------------------------------------------------
3544
3546
  // Channel processors
3545
3547
  // --------------------------------------------------------------------------------------
3546
3548
  async processEmailChannel(args) {
3547
3549
  const { cfg, evt, deliveryId } = args;
3548
- const tpl = await this.prisma.template.findUnique({ where: { id: cfg.emailTemplateId } });
3550
+ const tpl = await this.prisma.template.findFirst({
3551
+ where: { eventConfigId: cfg.id, templateType: "EMAIL" /* EMAIL */ }
3552
+ });
3549
3553
  if (!tpl) return;
3550
3554
  const recipients = args.recipients;
3551
3555
  if (!recipients.length) {
@@ -3572,7 +3576,9 @@ var NotificationService = class {
3572
3576
  }
3573
3577
  async processSmsChannel(args) {
3574
3578
  const { cfg, evt, deliveryId } = args;
3575
- const tpl = await this.prisma.template.findUnique({ where: { id: cfg.smsTemplateId } });
3579
+ const tpl = await this.prisma.template.findFirst({
3580
+ where: { eventConfigId: cfg.id, templateType: "SMS" /* SMS */ }
3581
+ });
3576
3582
  if (!tpl) return;
3577
3583
  const recipients = args.recipients ?? [];
3578
3584
  if (!recipients.length) {
@@ -3648,12 +3654,11 @@ var NotificationService = class {
3648
3654
  }
3649
3655
  async processAppChannel(args) {
3650
3656
  const { cfg, evt, deliveryId } = args;
3651
- const tpl = await this.prisma.template.findUnique({ where: { id: cfg.appNotificationTemplateId } });
3657
+ const tpl = await this.prisma.template.findFirst({
3658
+ where: { eventConfigId: cfg.id, templateType: "APP_NOTIFICATION" /* APP_NOTIFICATION */ }
3659
+ });
3652
3660
  if (!tpl) return;
3653
- let appUrlTpl = null;
3654
- if (cfg.allowAppNotification && cfg.serviceEvent.allowAppNotification && cfg.appNotificationUrlTemplateId) {
3655
- appUrlTpl = await this.prisma.template.findUnique({ where: { id: cfg.appNotificationUrlTemplateId } });
3656
- }
3661
+ let appUrlTpl = tpl.url;
3657
3662
  const userIds = (args.recipients ?? []).map((x) => Number(x)).filter((n) => Number.isFinite(n) && n > 0);
3658
3663
  if (!userIds.length) {
3659
3664
  this.logger.info("[NotificationService] APP: no userIds resolved");
@@ -3661,7 +3666,7 @@ var NotificationService = class {
3661
3666
  }
3662
3667
  const title = renderTemplate(tpl.subject ?? "", evt.data ?? {});
3663
3668
  const body = renderTemplate(tpl.bodyText ?? "", evt.data ?? {});
3664
- const route = appUrlTpl ? renderTemplate(appUrlTpl.bodyText ?? "", evt.data ?? {}) : null;
3669
+ const route = appUrlTpl ? renderTemplate(appUrlTpl ?? "", evt.data ?? {}) : null;
3665
3670
  const tokensMap = await this.getExpoTokensByUserIds(userIds);
3666
3671
  const expoProvider = new ExpoAppNotificationProvider(
3667
3672
  this.logger,
@@ -3740,21 +3745,21 @@ var NotificationService = class {
3740
3745
  }
3741
3746
  async processWebChannel(args) {
3742
3747
  const { cfg, evt, deliveryId } = args;
3743
- let webTpl = null;
3744
- if (cfg.allowWebNotification && cfg.serviceEvent.allowWebNotification && cfg.webNotificationTemplateId) {
3745
- webTpl = await this.prisma.template.findUnique({ where: { id: cfg.webNotificationTemplateId } });
3746
- }
3747
- let webUrlTpl = null;
3748
- if (cfg.allowWebNotification && cfg.serviceEvent.allowWebNotification && cfg.webNotificationUrlTemplateId) {
3749
- webUrlTpl = await this.prisma.template.findUnique({ where: { id: cfg.webNotificationUrlTemplateId } });
3748
+ const webTpl = await this.prisma.template.findFirst({
3749
+ where: { eventConfigId: cfg.id, templateType: "WEB_NOTIFICATION" /* WEB_NOTIFICATION */ }
3750
+ });
3751
+ if (!webTpl) {
3752
+ this.logger.error("[NotificationService] WEB: no template found");
3753
+ return;
3750
3754
  }
3755
+ let webUrlTpl = webTpl?.url;
3751
3756
  const recipients = args.recipients;
3752
3757
  if (!recipients.length) {
3753
- this.logger.info("[NotificationService] WEB: no recipients resolved");
3758
+ this.logger.error("[NotificationService] WEB: no recipients resolved");
3754
3759
  return;
3755
3760
  }
3756
3761
  const message = renderTemplate(webTpl.bodyText ?? "", evt.data ?? {});
3757
- const link = webUrlTpl ? renderTemplate(webUrlTpl.bodyText ?? "", evt.data ?? {}) : null;
3762
+ const link = webUrlTpl ? renderTemplate(webUrlTpl ?? "", evt.data ?? {}) : null;
3758
3763
  const provider = new WebNotificationProvider(this.prisma, this.logger);
3759
3764
  const bulk = await provider.sendBulk({
3760
3765
  source: evt.service,
@@ -3802,7 +3807,9 @@ var NotificationService = class {
3802
3807
  }
3803
3808
  async processWhatsappChannel(args) {
3804
3809
  const { cfg, evt, deliveryId } = args;
3805
- const tpl = await this.prisma.template.findUnique({ where: { id: cfg.wpTemplateId } });
3810
+ const tpl = await this.prisma.template.findFirst({
3811
+ where: { eventConfigId: cfg.id, templateType: "WHATSAPP" /* WHATSAPP */ }
3812
+ });
3806
3813
  if (!tpl) return;
3807
3814
  const recipients = args.recipients;
3808
3815
  if (!recipients.length) {
package/dist/index.mjs CHANGED
@@ -1540,7 +1540,6 @@ var buildJoiSchemaForOp = (cfg, op, ctx) => {
1540
1540
 
1541
1541
  // src/utils/dynamicOperation.utils.ts
1542
1542
  import { applyRound } from "av6-utils";
1543
- import Decimal from "decimal.js";
1544
1543
  var OP_PRECEDENCE = {
1545
1544
  "u-": 3,
1546
1545
  // unary minus
@@ -1746,9 +1745,12 @@ function getDynamicValueOrExpression(obj, accessorOrExpr) {
1746
1745
  }
1747
1746
  return getDynamicValue(obj, s);
1748
1747
  }
1748
+ function isDecimalLike(v) {
1749
+ return v !== null && typeof v === "object" && typeof v.toNumber === "function" && typeof v.toString === "function";
1750
+ }
1749
1751
  function toNumberDeep(val) {
1750
1752
  if (val === null || val === void 0) return val;
1751
- if (val instanceof Decimal) return val.toNumber();
1753
+ if (isDecimalLike(val)) return val.toNumber();
1752
1754
  if (val instanceof Date) return val;
1753
1755
  if (Array.isArray(val)) return val.map(toNumberDeep);
1754
1756
  if (typeof val === "object") {
@@ -3476,26 +3478,28 @@ var NotificationService = class {
3476
3478
  // Should-send checks
3477
3479
  // --------------------------------------------------------------------------------------
3478
3480
  shouldSendEmail(cfg) {
3479
- return Boolean(cfg.allowEmail && cfg.serviceEvent.allowEmail && cfg.emailTemplateId);
3481
+ return Boolean(cfg.allowEmail && cfg.serviceEvent.allowEmail);
3480
3482
  }
3481
3483
  shouldSendSms(cfg) {
3482
- return Boolean(cfg.allowSms && cfg.serviceEvent.allowSms && cfg.smsTemplateId);
3484
+ return Boolean(cfg.allowSms && cfg.serviceEvent.allowSms);
3483
3485
  }
3484
3486
  shouldSendWhatsapp(cfg) {
3485
- return Boolean(cfg.allowWhatsapp && cfg.serviceEvent.allowWhatsapp && cfg.wpTemplateId);
3487
+ return Boolean(cfg.allowWhatsapp && cfg.serviceEvent.allowWhatsapp);
3486
3488
  }
3487
3489
  shouldSendApp(cfg) {
3488
- return Boolean(cfg.allowAppNotification && cfg.serviceEvent.allowAppNotification && cfg.appNotificationTemplateId);
3490
+ return Boolean(cfg.allowAppNotification && cfg.serviceEvent.allowAppNotification);
3489
3491
  }
3490
3492
  shouldSendWeb(cfg) {
3491
- return Boolean(cfg.allowWebNotification && cfg.serviceEvent.allowWebNotification && cfg.webNotificationTemplateId);
3493
+ return Boolean(cfg.allowWebNotification && cfg.serviceEvent.allowWebNotification);
3492
3494
  }
3493
3495
  // --------------------------------------------------------------------------------------
3494
3496
  // Channel processors
3495
3497
  // --------------------------------------------------------------------------------------
3496
3498
  async processEmailChannel(args) {
3497
3499
  const { cfg, evt, deliveryId } = args;
3498
- const tpl = await this.prisma.template.findUnique({ where: { id: cfg.emailTemplateId } });
3500
+ const tpl = await this.prisma.template.findFirst({
3501
+ where: { eventConfigId: cfg.id, templateType: "EMAIL" /* EMAIL */ }
3502
+ });
3499
3503
  if (!tpl) return;
3500
3504
  const recipients = args.recipients;
3501
3505
  if (!recipients.length) {
@@ -3522,7 +3526,9 @@ var NotificationService = class {
3522
3526
  }
3523
3527
  async processSmsChannel(args) {
3524
3528
  const { cfg, evt, deliveryId } = args;
3525
- const tpl = await this.prisma.template.findUnique({ where: { id: cfg.smsTemplateId } });
3529
+ const tpl = await this.prisma.template.findFirst({
3530
+ where: { eventConfigId: cfg.id, templateType: "SMS" /* SMS */ }
3531
+ });
3526
3532
  if (!tpl) return;
3527
3533
  const recipients = args.recipients ?? [];
3528
3534
  if (!recipients.length) {
@@ -3598,12 +3604,11 @@ var NotificationService = class {
3598
3604
  }
3599
3605
  async processAppChannel(args) {
3600
3606
  const { cfg, evt, deliveryId } = args;
3601
- const tpl = await this.prisma.template.findUnique({ where: { id: cfg.appNotificationTemplateId } });
3607
+ const tpl = await this.prisma.template.findFirst({
3608
+ where: { eventConfigId: cfg.id, templateType: "APP_NOTIFICATION" /* APP_NOTIFICATION */ }
3609
+ });
3602
3610
  if (!tpl) return;
3603
- let appUrlTpl = null;
3604
- if (cfg.allowAppNotification && cfg.serviceEvent.allowAppNotification && cfg.appNotificationUrlTemplateId) {
3605
- appUrlTpl = await this.prisma.template.findUnique({ where: { id: cfg.appNotificationUrlTemplateId } });
3606
- }
3611
+ let appUrlTpl = tpl.url;
3607
3612
  const userIds = (args.recipients ?? []).map((x) => Number(x)).filter((n) => Number.isFinite(n) && n > 0);
3608
3613
  if (!userIds.length) {
3609
3614
  this.logger.info("[NotificationService] APP: no userIds resolved");
@@ -3611,7 +3616,7 @@ var NotificationService = class {
3611
3616
  }
3612
3617
  const title = renderTemplate(tpl.subject ?? "", evt.data ?? {});
3613
3618
  const body = renderTemplate(tpl.bodyText ?? "", evt.data ?? {});
3614
- const route = appUrlTpl ? renderTemplate(appUrlTpl.bodyText ?? "", evt.data ?? {}) : null;
3619
+ const route = appUrlTpl ? renderTemplate(appUrlTpl ?? "", evt.data ?? {}) : null;
3615
3620
  const tokensMap = await this.getExpoTokensByUserIds(userIds);
3616
3621
  const expoProvider = new ExpoAppNotificationProvider(
3617
3622
  this.logger,
@@ -3690,21 +3695,21 @@ var NotificationService = class {
3690
3695
  }
3691
3696
  async processWebChannel(args) {
3692
3697
  const { cfg, evt, deliveryId } = args;
3693
- let webTpl = null;
3694
- if (cfg.allowWebNotification && cfg.serviceEvent.allowWebNotification && cfg.webNotificationTemplateId) {
3695
- webTpl = await this.prisma.template.findUnique({ where: { id: cfg.webNotificationTemplateId } });
3696
- }
3697
- let webUrlTpl = null;
3698
- if (cfg.allowWebNotification && cfg.serviceEvent.allowWebNotification && cfg.webNotificationUrlTemplateId) {
3699
- webUrlTpl = await this.prisma.template.findUnique({ where: { id: cfg.webNotificationUrlTemplateId } });
3698
+ const webTpl = await this.prisma.template.findFirst({
3699
+ where: { eventConfigId: cfg.id, templateType: "WEB_NOTIFICATION" /* WEB_NOTIFICATION */ }
3700
+ });
3701
+ if (!webTpl) {
3702
+ this.logger.error("[NotificationService] WEB: no template found");
3703
+ return;
3700
3704
  }
3705
+ let webUrlTpl = webTpl?.url;
3701
3706
  const recipients = args.recipients;
3702
3707
  if (!recipients.length) {
3703
- this.logger.info("[NotificationService] WEB: no recipients resolved");
3708
+ this.logger.error("[NotificationService] WEB: no recipients resolved");
3704
3709
  return;
3705
3710
  }
3706
3711
  const message = renderTemplate(webTpl.bodyText ?? "", evt.data ?? {});
3707
- const link = webUrlTpl ? renderTemplate(webUrlTpl.bodyText ?? "", evt.data ?? {}) : null;
3712
+ const link = webUrlTpl ? renderTemplate(webUrlTpl ?? "", evt.data ?? {}) : null;
3708
3713
  const provider = new WebNotificationProvider(this.prisma, this.logger);
3709
3714
  const bulk = await provider.sendBulk({
3710
3715
  source: evt.service,
@@ -3752,7 +3757,9 @@ var NotificationService = class {
3752
3757
  }
3753
3758
  async processWhatsappChannel(args) {
3754
3759
  const { cfg, evt, deliveryId } = args;
3755
- const tpl = await this.prisma.template.findUnique({ where: { id: cfg.wpTemplateId } });
3760
+ const tpl = await this.prisma.template.findFirst({
3761
+ where: { eventConfigId: cfg.id, templateType: "WHATSAPP" /* WHATSAPP */ }
3762
+ });
3756
3763
  if (!tpl) return;
3757
3764
  const recipients = args.recipients;
3758
3765
  if (!recipients.length) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "av6-core",
3
- "version": "1.6.4",
3
+ "version": "1.6.6",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
@@ -25,7 +25,6 @@
25
25
  "dependencies": {
26
26
  "av6-utils": "^1.0.4",
27
27
  "axios": "^1.11.0",
28
- "decimal.js": "^10.6.0",
29
28
  "exceljs": "^4.4.0",
30
29
  "handlebars": "^4.7.8",
31
30
  "joi": "^17.13.3",