av6-core 1.7.0 → 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 +46 -20
- package/dist/index.mjs +46 -20
- package/package.json +3 -1
package/dist/index.js
CHANGED
|
@@ -1983,12 +1983,13 @@ var commonService = (serviceDeps) => {
|
|
|
1983
1983
|
},
|
|
1984
1984
|
async commonExcelImport(searchParams) {
|
|
1985
1985
|
logger.info("entering::commonExcelImport::service");
|
|
1986
|
-
const
|
|
1987
|
-
if (!
|
|
1988
|
-
throw new Error("No file
|
|
1986
|
+
const file = searchParams.file;
|
|
1987
|
+
if (!file?.buffer) {
|
|
1988
|
+
throw new Error("No file buffer provided for Excel import");
|
|
1989
1989
|
}
|
|
1990
1990
|
const workbook = new import_exceljs.default.Workbook();
|
|
1991
|
-
|
|
1991
|
+
const buffer = searchParams.file.buffer;
|
|
1992
|
+
await workbook.xlsx.load(buffer);
|
|
1992
1993
|
const worksheet = workbook.worksheets[0];
|
|
1993
1994
|
if (!worksheet) {
|
|
1994
1995
|
throw new Error("No worksheet found in Excel file");
|
|
@@ -3064,7 +3065,7 @@ var getStaffInfoFromStaffIds = async (args) => {
|
|
|
3064
3065
|
select: { id: true, email: true, contactNo: true }
|
|
3065
3066
|
});
|
|
3066
3067
|
staffById = new Map(
|
|
3067
|
-
staffRows.map((s) => [s.id, { email: s.email ?? null, contactNo: s.contactNo ?? null, userId:
|
|
3068
|
+
staffRows.map((s) => [s.id, { email: s.email ?? null, contactNo: s.contactNo ?? null, userId: s.id }])
|
|
3068
3069
|
);
|
|
3069
3070
|
break;
|
|
3070
3071
|
case "LEVEL2": {
|
|
@@ -3082,7 +3083,7 @@ var getStaffInfoFromStaffIds = async (args) => {
|
|
|
3082
3083
|
}
|
|
3083
3084
|
});
|
|
3084
3085
|
staffById = new Map(
|
|
3085
|
-
result2.map((s) => [s.id, { email: s.email ?? null, contactNo: s.phoneNumber ?? null, userId:
|
|
3086
|
+
result2.map((s) => [s.id, { email: s.email ?? null, contactNo: s.phoneNumber ?? null, userId: s.id }])
|
|
3086
3087
|
);
|
|
3087
3088
|
break;
|
|
3088
3089
|
}
|
|
@@ -3101,7 +3102,7 @@ var getStaffInfoFromStaffIds = async (args) => {
|
|
|
3101
3102
|
}
|
|
3102
3103
|
});
|
|
3103
3104
|
staffById = new Map(
|
|
3104
|
-
result.map((s) => [s.id, { email: s.email ?? null, contactNo: s.phoneNumber ?? null, userId:
|
|
3105
|
+
result.map((s) => [s.id, { email: s.email ?? null, contactNo: s.phoneNumber ?? null, userId: s.id }])
|
|
3105
3106
|
);
|
|
3106
3107
|
break;
|
|
3107
3108
|
}
|
|
@@ -3433,6 +3434,7 @@ function renderEmailTemplate(tpl, data) {
|
|
|
3433
3434
|
}
|
|
3434
3435
|
|
|
3435
3436
|
// src/services/notification.service.ts
|
|
3437
|
+
var import_lodash = __toESM(require("lodash.merge"));
|
|
3436
3438
|
var NotificationService = class {
|
|
3437
3439
|
constructor(prisma, logger = console, helpers) {
|
|
3438
3440
|
this.prisma = prisma;
|
|
@@ -3487,7 +3489,17 @@ var NotificationService = class {
|
|
|
3487
3489
|
shortCode: evt.shortCode
|
|
3488
3490
|
},
|
|
3489
3491
|
include: {
|
|
3490
|
-
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
|
+
}
|
|
3491
3503
|
}
|
|
3492
3504
|
});
|
|
3493
3505
|
if (!cfg) {
|
|
@@ -3500,6 +3512,8 @@ var NotificationService = class {
|
|
|
3500
3512
|
return cfg;
|
|
3501
3513
|
}
|
|
3502
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 ?? {});
|
|
3503
3517
|
return this.prisma.eventDelivery.create({
|
|
3504
3518
|
data: {
|
|
3505
3519
|
eventId: cfg.serviceEvent.id,
|
|
@@ -3508,7 +3522,7 @@ var NotificationService = class {
|
|
|
3508
3522
|
eventConfigId: cfg.id,
|
|
3509
3523
|
service: evt.service,
|
|
3510
3524
|
priority: cfg.priority,
|
|
3511
|
-
payload:
|
|
3525
|
+
payload: mergedData,
|
|
3512
3526
|
status: "PROCESSING" /* PROCESSING */
|
|
3513
3527
|
}
|
|
3514
3528
|
});
|
|
@@ -3568,7 +3582,9 @@ var NotificationService = class {
|
|
|
3568
3582
|
this.logger.info("[NotificationService] Email: no recipients resolved");
|
|
3569
3583
|
return;
|
|
3570
3584
|
}
|
|
3571
|
-
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);
|
|
3572
3588
|
const provider = new EmailProvider(this.prisma, this.logger, cfg.serviceEvent.serviceDomain);
|
|
3573
3589
|
await this.sendPerRecipient({
|
|
3574
3590
|
deliveryId,
|
|
@@ -3598,7 +3614,9 @@ var NotificationService = class {
|
|
|
3598
3614
|
this.logger.info("[NotificationService] SMS: no recipients resolved");
|
|
3599
3615
|
return;
|
|
3600
3616
|
}
|
|
3601
|
-
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);
|
|
3602
3620
|
const provider = new SmsProvider(this.logger, {
|
|
3603
3621
|
apiUrl: cfg.serviceEvent.smsApiUrl ?? void 0,
|
|
3604
3622
|
apiKey: cfg.serviceEvent.smsApiKey ?? void 0,
|
|
@@ -3677,9 +3695,11 @@ var NotificationService = class {
|
|
|
3677
3695
|
this.logger.info("[NotificationService] APP: no userIds resolved");
|
|
3678
3696
|
return;
|
|
3679
3697
|
}
|
|
3680
|
-
const
|
|
3681
|
-
const
|
|
3682
|
-
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;
|
|
3683
3703
|
const tokensMap = await this.getExpoTokensByUserIds(userIds);
|
|
3684
3704
|
const expoProvider = new ExpoAppNotificationProvider(
|
|
3685
3705
|
this.logger,
|
|
@@ -3771,8 +3791,10 @@ var NotificationService = class {
|
|
|
3771
3791
|
this.logger.error("[NotificationService] WEB: no recipients resolved");
|
|
3772
3792
|
return;
|
|
3773
3793
|
}
|
|
3774
|
-
const
|
|
3775
|
-
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;
|
|
3776
3798
|
const provider = new WebNotificationProvider(this.prisma, this.logger);
|
|
3777
3799
|
const bulk = await provider.sendBulk({
|
|
3778
3800
|
source: evt.service,
|
|
@@ -3829,9 +3851,11 @@ var NotificationService = class {
|
|
|
3829
3851
|
this.logger.info("[NotificationService] WhatsApp: no recipients resolved");
|
|
3830
3852
|
return;
|
|
3831
3853
|
}
|
|
3832
|
-
const
|
|
3833
|
-
const
|
|
3834
|
-
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));
|
|
3835
3859
|
const fileName = getNestedValue(tpl.extra?.fileName);
|
|
3836
3860
|
const apiKey = cfg.serviceEvent.wpApiKey ?? "";
|
|
3837
3861
|
if (!apiKey.trim()) {
|
|
@@ -3883,10 +3907,12 @@ var NotificationService = class {
|
|
|
3883
3907
|
// Recipient resolution
|
|
3884
3908
|
// --------------------------------------------------------------------------------------
|
|
3885
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 ?? {});
|
|
3886
3912
|
const recipients = await resolveAllRecipients({
|
|
3887
3913
|
prisma: this.prisma,
|
|
3888
3914
|
eventConfig,
|
|
3889
|
-
evtData:
|
|
3915
|
+
evtData: mergedData
|
|
3890
3916
|
});
|
|
3891
3917
|
return recipients;
|
|
3892
3918
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1932,12 +1932,13 @@ var commonService = (serviceDeps) => {
|
|
|
1932
1932
|
},
|
|
1933
1933
|
async commonExcelImport(searchParams) {
|
|
1934
1934
|
logger.info("entering::commonExcelImport::service");
|
|
1935
|
-
const
|
|
1936
|
-
if (!
|
|
1937
|
-
throw new Error("No file
|
|
1935
|
+
const file = searchParams.file;
|
|
1936
|
+
if (!file?.buffer) {
|
|
1937
|
+
throw new Error("No file buffer provided for Excel import");
|
|
1938
1938
|
}
|
|
1939
1939
|
const workbook = new ExcelJs.Workbook();
|
|
1940
|
-
|
|
1940
|
+
const buffer = searchParams.file.buffer;
|
|
1941
|
+
await workbook.xlsx.load(buffer);
|
|
1941
1942
|
const worksheet = workbook.worksheets[0];
|
|
1942
1943
|
if (!worksheet) {
|
|
1943
1944
|
throw new Error("No worksheet found in Excel file");
|
|
@@ -3013,7 +3014,7 @@ var getStaffInfoFromStaffIds = async (args) => {
|
|
|
3013
3014
|
select: { id: true, email: true, contactNo: true }
|
|
3014
3015
|
});
|
|
3015
3016
|
staffById = new Map(
|
|
3016
|
-
staffRows.map((s) => [s.id, { email: s.email ?? null, contactNo: s.contactNo ?? null, userId:
|
|
3017
|
+
staffRows.map((s) => [s.id, { email: s.email ?? null, contactNo: s.contactNo ?? null, userId: s.id }])
|
|
3017
3018
|
);
|
|
3018
3019
|
break;
|
|
3019
3020
|
case "LEVEL2": {
|
|
@@ -3031,7 +3032,7 @@ var getStaffInfoFromStaffIds = async (args) => {
|
|
|
3031
3032
|
}
|
|
3032
3033
|
});
|
|
3033
3034
|
staffById = new Map(
|
|
3034
|
-
result2.map((s) => [s.id, { email: s.email ?? null, contactNo: s.phoneNumber ?? null, userId:
|
|
3035
|
+
result2.map((s) => [s.id, { email: s.email ?? null, contactNo: s.phoneNumber ?? null, userId: s.id }])
|
|
3035
3036
|
);
|
|
3036
3037
|
break;
|
|
3037
3038
|
}
|
|
@@ -3050,7 +3051,7 @@ var getStaffInfoFromStaffIds = async (args) => {
|
|
|
3050
3051
|
}
|
|
3051
3052
|
});
|
|
3052
3053
|
staffById = new Map(
|
|
3053
|
-
result.map((s) => [s.id, { email: s.email ?? null, contactNo: s.phoneNumber ?? null, userId:
|
|
3054
|
+
result.map((s) => [s.id, { email: s.email ?? null, contactNo: s.phoneNumber ?? null, userId: s.id }])
|
|
3054
3055
|
);
|
|
3055
3056
|
break;
|
|
3056
3057
|
}
|
|
@@ -3382,6 +3383,7 @@ function renderEmailTemplate(tpl, data) {
|
|
|
3382
3383
|
}
|
|
3383
3384
|
|
|
3384
3385
|
// src/services/notification.service.ts
|
|
3386
|
+
import merge from "lodash.merge";
|
|
3385
3387
|
var NotificationService = class {
|
|
3386
3388
|
constructor(prisma, logger = console, helpers) {
|
|
3387
3389
|
this.prisma = prisma;
|
|
@@ -3436,7 +3438,17 @@ var NotificationService = class {
|
|
|
3436
3438
|
shortCode: evt.shortCode
|
|
3437
3439
|
},
|
|
3438
3440
|
include: {
|
|
3439
|
-
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
|
+
}
|
|
3440
3452
|
}
|
|
3441
3453
|
});
|
|
3442
3454
|
if (!cfg) {
|
|
@@ -3449,6 +3461,8 @@ var NotificationService = class {
|
|
|
3449
3461
|
return cfg;
|
|
3450
3462
|
}
|
|
3451
3463
|
async createDeliveryParent(cfg, evt) {
|
|
3464
|
+
const defaultValues = cfg.eventConfigKeys?.map((x) => ({ [x.key]: x.defaultValue })) ?? {};
|
|
3465
|
+
const mergedData = merge({}, defaultValues, evt.data ?? {});
|
|
3452
3466
|
return this.prisma.eventDelivery.create({
|
|
3453
3467
|
data: {
|
|
3454
3468
|
eventId: cfg.serviceEvent.id,
|
|
@@ -3457,7 +3471,7 @@ var NotificationService = class {
|
|
|
3457
3471
|
eventConfigId: cfg.id,
|
|
3458
3472
|
service: evt.service,
|
|
3459
3473
|
priority: cfg.priority,
|
|
3460
|
-
payload:
|
|
3474
|
+
payload: mergedData,
|
|
3461
3475
|
status: "PROCESSING" /* PROCESSING */
|
|
3462
3476
|
}
|
|
3463
3477
|
});
|
|
@@ -3517,7 +3531,9 @@ var NotificationService = class {
|
|
|
3517
3531
|
this.logger.info("[NotificationService] Email: no recipients resolved");
|
|
3518
3532
|
return;
|
|
3519
3533
|
}
|
|
3520
|
-
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);
|
|
3521
3537
|
const provider = new EmailProvider(this.prisma, this.logger, cfg.serviceEvent.serviceDomain);
|
|
3522
3538
|
await this.sendPerRecipient({
|
|
3523
3539
|
deliveryId,
|
|
@@ -3547,7 +3563,9 @@ var NotificationService = class {
|
|
|
3547
3563
|
this.logger.info("[NotificationService] SMS: no recipients resolved");
|
|
3548
3564
|
return;
|
|
3549
3565
|
}
|
|
3550
|
-
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);
|
|
3551
3569
|
const provider = new SmsProvider(this.logger, {
|
|
3552
3570
|
apiUrl: cfg.serviceEvent.smsApiUrl ?? void 0,
|
|
3553
3571
|
apiKey: cfg.serviceEvent.smsApiKey ?? void 0,
|
|
@@ -3626,9 +3644,11 @@ var NotificationService = class {
|
|
|
3626
3644
|
this.logger.info("[NotificationService] APP: no userIds resolved");
|
|
3627
3645
|
return;
|
|
3628
3646
|
}
|
|
3629
|
-
const
|
|
3630
|
-
const
|
|
3631
|
-
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;
|
|
3632
3652
|
const tokensMap = await this.getExpoTokensByUserIds(userIds);
|
|
3633
3653
|
const expoProvider = new ExpoAppNotificationProvider(
|
|
3634
3654
|
this.logger,
|
|
@@ -3720,8 +3740,10 @@ var NotificationService = class {
|
|
|
3720
3740
|
this.logger.error("[NotificationService] WEB: no recipients resolved");
|
|
3721
3741
|
return;
|
|
3722
3742
|
}
|
|
3723
|
-
const
|
|
3724
|
-
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;
|
|
3725
3747
|
const provider = new WebNotificationProvider(this.prisma, this.logger);
|
|
3726
3748
|
const bulk = await provider.sendBulk({
|
|
3727
3749
|
source: evt.service,
|
|
@@ -3778,9 +3800,11 @@ var NotificationService = class {
|
|
|
3778
3800
|
this.logger.info("[NotificationService] WhatsApp: no recipients resolved");
|
|
3779
3801
|
return;
|
|
3780
3802
|
}
|
|
3781
|
-
const
|
|
3782
|
-
const
|
|
3783
|
-
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));
|
|
3784
3808
|
const fileName = getNestedValue(tpl.extra?.fileName);
|
|
3785
3809
|
const apiKey = cfg.serviceEvent.wpApiKey ?? "";
|
|
3786
3810
|
if (!apiKey.trim()) {
|
|
@@ -3832,10 +3856,12 @@ var NotificationService = class {
|
|
|
3832
3856
|
// Recipient resolution
|
|
3833
3857
|
// --------------------------------------------------------------------------------------
|
|
3834
3858
|
async getRecipients(eventConfig, evt) {
|
|
3859
|
+
const defaultValues = eventConfig.eventConfigKeys?.map((x) => ({ [x.key]: x.defaultValue })) ?? {};
|
|
3860
|
+
const mergedData = merge({}, defaultValues, evt.data ?? {});
|
|
3835
3861
|
const recipients = await resolveAllRecipients({
|
|
3836
3862
|
prisma: this.prisma,
|
|
3837
3863
|
eventConfig,
|
|
3838
|
-
evtData:
|
|
3864
|
+
evtData: mergedData
|
|
3839
3865
|
});
|
|
3840
3866
|
return recipients;
|
|
3841
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",
|