av6-core 1.7.1 → 1.7.2
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 +38 -13
- package/dist/index.mjs +38 -13
- package/package.json +3 -1
package/dist/index.js
CHANGED
|
@@ -3434,6 +3434,7 @@ function renderEmailTemplate(tpl, data) {
|
|
|
3434
3434
|
}
|
|
3435
3435
|
|
|
3436
3436
|
// src/services/notification.service.ts
|
|
3437
|
+
var import_lodash = __toESM(require("lodash.merge"));
|
|
3437
3438
|
var NotificationService = class {
|
|
3438
3439
|
constructor(prisma, logger = console, helpers) {
|
|
3439
3440
|
this.prisma = prisma;
|
|
@@ -3488,7 +3489,17 @@ var NotificationService = class {
|
|
|
3488
3489
|
shortCode: evt.shortCode
|
|
3489
3490
|
},
|
|
3490
3491
|
include: {
|
|
3491
|
-
serviceEvent: true
|
|
3492
|
+
serviceEvent: true,
|
|
3493
|
+
eventConfigKeys: {
|
|
3494
|
+
where: {
|
|
3495
|
+
isActive: true
|
|
3496
|
+
},
|
|
3497
|
+
select: {
|
|
3498
|
+
id: true,
|
|
3499
|
+
key: true,
|
|
3500
|
+
defaultValue: true
|
|
3501
|
+
}
|
|
3502
|
+
}
|
|
3492
3503
|
}
|
|
3493
3504
|
});
|
|
3494
3505
|
if (!cfg) {
|
|
@@ -3501,6 +3512,8 @@ var NotificationService = class {
|
|
|
3501
3512
|
return cfg;
|
|
3502
3513
|
}
|
|
3503
3514
|
async createDeliveryParent(cfg, evt) {
|
|
3515
|
+
const defaultValues = cfg.eventConfigKeys?.map((x) => ({ [x.key]: x.defaultValue })) ?? {};
|
|
3516
|
+
const mergedData = (0, import_lodash.default)({}, defaultValues, evt.data ?? {});
|
|
3504
3517
|
return this.prisma.eventDelivery.create({
|
|
3505
3518
|
data: {
|
|
3506
3519
|
eventId: cfg.serviceEvent.id,
|
|
@@ -3509,7 +3522,7 @@ var NotificationService = class {
|
|
|
3509
3522
|
eventConfigId: cfg.id,
|
|
3510
3523
|
service: evt.service,
|
|
3511
3524
|
priority: cfg.priority,
|
|
3512
|
-
payload:
|
|
3525
|
+
payload: mergedData,
|
|
3513
3526
|
status: "PROCESSING" /* PROCESSING */
|
|
3514
3527
|
}
|
|
3515
3528
|
});
|
|
@@ -3569,7 +3582,9 @@ var NotificationService = class {
|
|
|
3569
3582
|
this.logger.info("[NotificationService] Email: no recipients resolved");
|
|
3570
3583
|
return;
|
|
3571
3584
|
}
|
|
3572
|
-
const
|
|
3585
|
+
const defaultValues = cfg.eventConfigKeys?.map((x) => ({ [x.key]: x.defaultValue })) ?? {};
|
|
3586
|
+
const mergedData = (0, import_lodash.default)({}, defaultValues, evt.data ?? {});
|
|
3587
|
+
const msg = renderEmailTemplate({ body: tpl.bodyHtml ?? "", subject: tpl.subject ?? "" }, mergedData);
|
|
3573
3588
|
const provider = new EmailProvider(this.prisma, this.logger, cfg.serviceEvent.serviceDomain);
|
|
3574
3589
|
await this.sendPerRecipient({
|
|
3575
3590
|
deliveryId,
|
|
@@ -3599,7 +3614,9 @@ var NotificationService = class {
|
|
|
3599
3614
|
this.logger.info("[NotificationService] SMS: no recipients resolved");
|
|
3600
3615
|
return;
|
|
3601
3616
|
}
|
|
3602
|
-
const
|
|
3617
|
+
const defaultValues = cfg.eventConfigKeys?.map((x) => ({ [x.key]: x.defaultValue })) ?? {};
|
|
3618
|
+
const mergedData = (0, import_lodash.default)({}, defaultValues, evt.data ?? {});
|
|
3619
|
+
const body = renderTemplate(tpl.bodyText ?? "", mergedData);
|
|
3603
3620
|
const provider = new SmsProvider(this.logger, {
|
|
3604
3621
|
apiUrl: cfg.serviceEvent.smsApiUrl ?? void 0,
|
|
3605
3622
|
apiKey: cfg.serviceEvent.smsApiKey ?? void 0,
|
|
@@ -3678,9 +3695,11 @@ var NotificationService = class {
|
|
|
3678
3695
|
this.logger.info("[NotificationService] APP: no userIds resolved");
|
|
3679
3696
|
return;
|
|
3680
3697
|
}
|
|
3681
|
-
const
|
|
3682
|
-
const
|
|
3683
|
-
const
|
|
3698
|
+
const defaultValues = cfg.eventConfigKeys?.map((x) => ({ [x.key]: x.defaultValue })) ?? {};
|
|
3699
|
+
const mergedData = (0, import_lodash.default)({}, defaultValues, evt.data ?? {});
|
|
3700
|
+
const title = renderTemplate(tpl.subject ?? "", mergedData);
|
|
3701
|
+
const body = renderTemplate(tpl.bodyText ?? "", mergedData);
|
|
3702
|
+
const route = appUrlTpl ? renderTemplate(appUrlTpl ?? "", mergedData) : null;
|
|
3684
3703
|
const tokensMap = await this.getExpoTokensByUserIds(userIds);
|
|
3685
3704
|
const expoProvider = new ExpoAppNotificationProvider(
|
|
3686
3705
|
this.logger,
|
|
@@ -3772,8 +3791,10 @@ var NotificationService = class {
|
|
|
3772
3791
|
this.logger.error("[NotificationService] WEB: no recipients resolved");
|
|
3773
3792
|
return;
|
|
3774
3793
|
}
|
|
3775
|
-
const
|
|
3776
|
-
const
|
|
3794
|
+
const defaultValues = cfg.eventConfigKeys?.map((x) => ({ [x.key]: x.defaultValue })) ?? {};
|
|
3795
|
+
const mergedData = (0, import_lodash.default)({}, defaultValues, evt.data ?? {});
|
|
3796
|
+
const message = renderTemplate(webTpl.bodyText ?? "", mergedData);
|
|
3797
|
+
const link = webUrlTpl ? renderTemplate(webUrlTpl ?? "", mergedData) : null;
|
|
3777
3798
|
const provider = new WebNotificationProvider(this.prisma, this.logger);
|
|
3778
3799
|
const bulk = await provider.sendBulk({
|
|
3779
3800
|
source: evt.service,
|
|
@@ -3830,9 +3851,11 @@ var NotificationService = class {
|
|
|
3830
3851
|
this.logger.info("[NotificationService] WhatsApp: no recipients resolved");
|
|
3831
3852
|
return;
|
|
3832
3853
|
}
|
|
3833
|
-
const
|
|
3834
|
-
const
|
|
3835
|
-
const
|
|
3854
|
+
const defaultValues = cfg.eventConfigKeys?.map((x) => ({ [x.key]: x.defaultValue })) ?? {};
|
|
3855
|
+
const mergedData = (0, import_lodash.default)({}, defaultValues, evt.data ?? {});
|
|
3856
|
+
const message = renderTemplate(tpl.bodyText ?? "", mergedData);
|
|
3857
|
+
const dataWp = tpl.extra?.bodyValues?.map((x) => getNestedValue(mergedData, x));
|
|
3858
|
+
const fileUrls = tpl.extra?.fileUrls?.map((x) => getNestedValue(mergedData, x));
|
|
3836
3859
|
const fileName = getNestedValue(tpl.extra?.fileName);
|
|
3837
3860
|
const apiKey = cfg.serviceEvent.wpApiKey ?? "";
|
|
3838
3861
|
if (!apiKey.trim()) {
|
|
@@ -3884,10 +3907,12 @@ var NotificationService = class {
|
|
|
3884
3907
|
// Recipient resolution
|
|
3885
3908
|
// --------------------------------------------------------------------------------------
|
|
3886
3909
|
async getRecipients(eventConfig, evt) {
|
|
3910
|
+
const defaultValues = eventConfig.eventConfigKeys?.map((x) => ({ [x.key]: x.defaultValue })) ?? {};
|
|
3911
|
+
const mergedData = (0, import_lodash.default)({}, defaultValues, evt.data ?? {});
|
|
3887
3912
|
const recipients = await resolveAllRecipients({
|
|
3888
3913
|
prisma: this.prisma,
|
|
3889
3914
|
eventConfig,
|
|
3890
|
-
evtData:
|
|
3915
|
+
evtData: mergedData
|
|
3891
3916
|
});
|
|
3892
3917
|
return recipients;
|
|
3893
3918
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -3383,6 +3383,7 @@ function renderEmailTemplate(tpl, data) {
|
|
|
3383
3383
|
}
|
|
3384
3384
|
|
|
3385
3385
|
// src/services/notification.service.ts
|
|
3386
|
+
import merge from "lodash.merge";
|
|
3386
3387
|
var NotificationService = class {
|
|
3387
3388
|
constructor(prisma, logger = console, helpers) {
|
|
3388
3389
|
this.prisma = prisma;
|
|
@@ -3437,7 +3438,17 @@ var NotificationService = class {
|
|
|
3437
3438
|
shortCode: evt.shortCode
|
|
3438
3439
|
},
|
|
3439
3440
|
include: {
|
|
3440
|
-
serviceEvent: true
|
|
3441
|
+
serviceEvent: true,
|
|
3442
|
+
eventConfigKeys: {
|
|
3443
|
+
where: {
|
|
3444
|
+
isActive: true
|
|
3445
|
+
},
|
|
3446
|
+
select: {
|
|
3447
|
+
id: true,
|
|
3448
|
+
key: true,
|
|
3449
|
+
defaultValue: true
|
|
3450
|
+
}
|
|
3451
|
+
}
|
|
3441
3452
|
}
|
|
3442
3453
|
});
|
|
3443
3454
|
if (!cfg) {
|
|
@@ -3450,6 +3461,8 @@ var NotificationService = class {
|
|
|
3450
3461
|
return cfg;
|
|
3451
3462
|
}
|
|
3452
3463
|
async createDeliveryParent(cfg, evt) {
|
|
3464
|
+
const defaultValues = cfg.eventConfigKeys?.map((x) => ({ [x.key]: x.defaultValue })) ?? {};
|
|
3465
|
+
const mergedData = merge({}, defaultValues, evt.data ?? {});
|
|
3453
3466
|
return this.prisma.eventDelivery.create({
|
|
3454
3467
|
data: {
|
|
3455
3468
|
eventId: cfg.serviceEvent.id,
|
|
@@ -3458,7 +3471,7 @@ var NotificationService = class {
|
|
|
3458
3471
|
eventConfigId: cfg.id,
|
|
3459
3472
|
service: evt.service,
|
|
3460
3473
|
priority: cfg.priority,
|
|
3461
|
-
payload:
|
|
3474
|
+
payload: mergedData,
|
|
3462
3475
|
status: "PROCESSING" /* PROCESSING */
|
|
3463
3476
|
}
|
|
3464
3477
|
});
|
|
@@ -3518,7 +3531,9 @@ var NotificationService = class {
|
|
|
3518
3531
|
this.logger.info("[NotificationService] Email: no recipients resolved");
|
|
3519
3532
|
return;
|
|
3520
3533
|
}
|
|
3521
|
-
const
|
|
3534
|
+
const defaultValues = cfg.eventConfigKeys?.map((x) => ({ [x.key]: x.defaultValue })) ?? {};
|
|
3535
|
+
const mergedData = merge({}, defaultValues, evt.data ?? {});
|
|
3536
|
+
const msg = renderEmailTemplate({ body: tpl.bodyHtml ?? "", subject: tpl.subject ?? "" }, mergedData);
|
|
3522
3537
|
const provider = new EmailProvider(this.prisma, this.logger, cfg.serviceEvent.serviceDomain);
|
|
3523
3538
|
await this.sendPerRecipient({
|
|
3524
3539
|
deliveryId,
|
|
@@ -3548,7 +3563,9 @@ var NotificationService = class {
|
|
|
3548
3563
|
this.logger.info("[NotificationService] SMS: no recipients resolved");
|
|
3549
3564
|
return;
|
|
3550
3565
|
}
|
|
3551
|
-
const
|
|
3566
|
+
const defaultValues = cfg.eventConfigKeys?.map((x) => ({ [x.key]: x.defaultValue })) ?? {};
|
|
3567
|
+
const mergedData = merge({}, defaultValues, evt.data ?? {});
|
|
3568
|
+
const body = renderTemplate(tpl.bodyText ?? "", mergedData);
|
|
3552
3569
|
const provider = new SmsProvider(this.logger, {
|
|
3553
3570
|
apiUrl: cfg.serviceEvent.smsApiUrl ?? void 0,
|
|
3554
3571
|
apiKey: cfg.serviceEvent.smsApiKey ?? void 0,
|
|
@@ -3627,9 +3644,11 @@ var NotificationService = class {
|
|
|
3627
3644
|
this.logger.info("[NotificationService] APP: no userIds resolved");
|
|
3628
3645
|
return;
|
|
3629
3646
|
}
|
|
3630
|
-
const
|
|
3631
|
-
const
|
|
3632
|
-
const
|
|
3647
|
+
const defaultValues = cfg.eventConfigKeys?.map((x) => ({ [x.key]: x.defaultValue })) ?? {};
|
|
3648
|
+
const mergedData = merge({}, defaultValues, evt.data ?? {});
|
|
3649
|
+
const title = renderTemplate(tpl.subject ?? "", mergedData);
|
|
3650
|
+
const body = renderTemplate(tpl.bodyText ?? "", mergedData);
|
|
3651
|
+
const route = appUrlTpl ? renderTemplate(appUrlTpl ?? "", mergedData) : null;
|
|
3633
3652
|
const tokensMap = await this.getExpoTokensByUserIds(userIds);
|
|
3634
3653
|
const expoProvider = new ExpoAppNotificationProvider(
|
|
3635
3654
|
this.logger,
|
|
@@ -3721,8 +3740,10 @@ var NotificationService = class {
|
|
|
3721
3740
|
this.logger.error("[NotificationService] WEB: no recipients resolved");
|
|
3722
3741
|
return;
|
|
3723
3742
|
}
|
|
3724
|
-
const
|
|
3725
|
-
const
|
|
3743
|
+
const defaultValues = cfg.eventConfigKeys?.map((x) => ({ [x.key]: x.defaultValue })) ?? {};
|
|
3744
|
+
const mergedData = merge({}, defaultValues, evt.data ?? {});
|
|
3745
|
+
const message = renderTemplate(webTpl.bodyText ?? "", mergedData);
|
|
3746
|
+
const link = webUrlTpl ? renderTemplate(webUrlTpl ?? "", mergedData) : null;
|
|
3726
3747
|
const provider = new WebNotificationProvider(this.prisma, this.logger);
|
|
3727
3748
|
const bulk = await provider.sendBulk({
|
|
3728
3749
|
source: evt.service,
|
|
@@ -3779,9 +3800,11 @@ var NotificationService = class {
|
|
|
3779
3800
|
this.logger.info("[NotificationService] WhatsApp: no recipients resolved");
|
|
3780
3801
|
return;
|
|
3781
3802
|
}
|
|
3782
|
-
const
|
|
3783
|
-
const
|
|
3784
|
-
const
|
|
3803
|
+
const defaultValues = cfg.eventConfigKeys?.map((x) => ({ [x.key]: x.defaultValue })) ?? {};
|
|
3804
|
+
const mergedData = merge({}, defaultValues, evt.data ?? {});
|
|
3805
|
+
const message = renderTemplate(tpl.bodyText ?? "", mergedData);
|
|
3806
|
+
const dataWp = tpl.extra?.bodyValues?.map((x) => getNestedValue(mergedData, x));
|
|
3807
|
+
const fileUrls = tpl.extra?.fileUrls?.map((x) => getNestedValue(mergedData, x));
|
|
3785
3808
|
const fileName = getNestedValue(tpl.extra?.fileName);
|
|
3786
3809
|
const apiKey = cfg.serviceEvent.wpApiKey ?? "";
|
|
3787
3810
|
if (!apiKey.trim()) {
|
|
@@ -3833,10 +3856,12 @@ var NotificationService = class {
|
|
|
3833
3856
|
// Recipient resolution
|
|
3834
3857
|
// --------------------------------------------------------------------------------------
|
|
3835
3858
|
async getRecipients(eventConfig, evt) {
|
|
3859
|
+
const defaultValues = eventConfig.eventConfigKeys?.map((x) => ({ [x.key]: x.defaultValue })) ?? {};
|
|
3860
|
+
const mergedData = merge({}, defaultValues, evt.data ?? {});
|
|
3836
3861
|
const recipients = await resolveAllRecipients({
|
|
3837
3862
|
prisma: this.prisma,
|
|
3838
3863
|
eventConfig,
|
|
3839
|
-
evtData:
|
|
3864
|
+
evtData: mergedData
|
|
3840
3865
|
});
|
|
3841
3866
|
return recipients;
|
|
3842
3867
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "av6-core",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.2",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@prisma/client": "^6.19.0",
|
|
17
|
+
"@types/lodash.merge": "^4.6.9",
|
|
17
18
|
"@types/nodemailer": "^7.0.3",
|
|
18
19
|
"tsup": "^8.5.0",
|
|
19
20
|
"typescript": "^5.9.2"
|
|
@@ -28,6 +29,7 @@
|
|
|
28
29
|
"exceljs": "^4.4.0",
|
|
29
30
|
"handlebars": "^4.7.8",
|
|
30
31
|
"joi": "^17.13.3",
|
|
32
|
+
"lodash.merge": "^4.6.2",
|
|
31
33
|
"node-cron": "^4.2.1",
|
|
32
34
|
"nodemailer": "^7.0.10",
|
|
33
35
|
"prettier": "^3.6.2",
|