av6-core 1.6.5 → 1.6.7
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.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +43 -27
- package/dist/index.mjs +42 -27
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -525,6 +525,7 @@ declare function customOmit<T extends object, K extends keyof T>(obj: T, keys: K
|
|
|
525
525
|
omitted: Pick<T, K>;
|
|
526
526
|
};
|
|
527
527
|
declare function getDynamicValue(obj: Record<string, any> | null | undefined, accessorKey: string): any | null;
|
|
528
|
+
declare function getNestedValue<T = unknown>(obj: unknown, path?: string | null, defaultValue?: T): T | undefined;
|
|
528
529
|
declare function objectTo2DArray<T>(obj: Record<string, T>, maxCols: number): (string | T)[][];
|
|
529
530
|
declare function toNumberOrNull(value: unknown): number | null;
|
|
530
531
|
declare const getPattern: {
|
|
@@ -694,4 +695,4 @@ declare class AuditProxy<Module extends string = "OPD" | "PROCEDURE" | "GENERAL_
|
|
|
694
695
|
createAuditedService<T extends object>(serviceName: string, service: T): T;
|
|
695
696
|
}
|
|
696
697
|
|
|
697
|
-
export { type AuditContext, type AuditContextProvider, AuditCore, type AuditLogPayload, AuditLogger, AuditProxy, type BulkAtomicResult, type BulkConfig, type BulkConflictConfig, type BulkOnConflict, type CacheAdapter, type CalculationRes, type ColValue, type CommonCreateRequestRepository, type CommonExcelRequest, type CommonFilterRequest, type CommonFilterWithDate, type CommonServiceResponse, type CommonUpdateRequestRepository, type Config, type Context, type CreateUINConfigRequest, type CrudContext, type CrudDelegate, type DataType, type DeepMerge, type DeleteParams, type DeleteRequestRepository, type Deps, type DropdownRequest, type DropdownRequestService, type DtoFromMapping, type DtoNullOnMissing, type DynamicCreateInput, type DynamicCrudConfig, type DynamicShortCode, type DynamicUpdateInput, type EmitPayload, type EmployeeCache, type ExcelConfig, type ExportExcel, type ExportExcelRequestService, type FetchRequest, type FetchRequestRepository, type FieldConfig, type FieldRules, type FieldType, type FixedMap, type FixedSearchRequest, type FixedSearchRequestService, type Helpers, type ImportExcel, type ImportExcelRequestService, type LockUnlockParams, type LockUnlockRequestRepository, type LogicNode, type Mapper, type MergeAll, type NewFixedSearchRequest, type NewFixedSearchRequestService, type NewSearchRequest, NotificationEmitter, type Op, type PaginatedResponse, type PathToSelectWithSelect, type PathValue, type PathsToSelectWithSelect, type Presence, type Recipient, type RelationConfig, type RelationStrategy, type RelationWriteConfig, type SearchRequest, type SearchRequestService, type ServiceCacheAdapter, type SingleValidationMapping, type SourcePath, type Store, type ToggleActive, type TxClient, type UINConfigDTO, type UINPreviewRequest, type UINSegment, type UINSegmentType, type UIN_RESET_POLICY, type UinDeps, type UnionToIntersection, type UniqueConfig, type UpdateConfigByCodeInput, type UpdateStatusRequestRepository, type UpdateUINConfigRequest, type ValidationErrorItem, commonService, customOmit, findDifferences, fromTimestampToSqlDatetime, getDynamicValue, getPattern, interpolate, objectTo2DArray, toNumberOrNull, toUINConfigDTO, uinConfigService, type updateStatusParams };
|
|
698
|
+
export { type AuditContext, type AuditContextProvider, AuditCore, type AuditLogPayload, AuditLogger, AuditProxy, type BulkAtomicResult, type BulkConfig, type BulkConflictConfig, type BulkOnConflict, type CacheAdapter, type CalculationRes, type ColValue, type CommonCreateRequestRepository, type CommonExcelRequest, type CommonFilterRequest, type CommonFilterWithDate, type CommonServiceResponse, type CommonUpdateRequestRepository, type Config, type Context, type CreateUINConfigRequest, type CrudContext, type CrudDelegate, type DataType, type DeepMerge, type DeleteParams, type DeleteRequestRepository, type Deps, type DropdownRequest, type DropdownRequestService, type DtoFromMapping, type DtoNullOnMissing, type DynamicCreateInput, type DynamicCrudConfig, type DynamicShortCode, type DynamicUpdateInput, type EmitPayload, type EmployeeCache, type ExcelConfig, type ExportExcel, type ExportExcelRequestService, type FetchRequest, type FetchRequestRepository, type FieldConfig, type FieldRules, type FieldType, type FixedMap, type FixedSearchRequest, type FixedSearchRequestService, type Helpers, type ImportExcel, type ImportExcelRequestService, type LockUnlockParams, type LockUnlockRequestRepository, type LogicNode, type Mapper, type MergeAll, type NewFixedSearchRequest, type NewFixedSearchRequestService, type NewSearchRequest, NotificationEmitter, type Op, type PaginatedResponse, type PathToSelectWithSelect, type PathValue, type PathsToSelectWithSelect, type Presence, type Recipient, type RelationConfig, type RelationStrategy, type RelationWriteConfig, type SearchRequest, type SearchRequestService, type ServiceCacheAdapter, type SingleValidationMapping, type SourcePath, type Store, type ToggleActive, type TxClient, type UINConfigDTO, type UINPreviewRequest, type UINSegment, type UINSegmentType, type UIN_RESET_POLICY, type UinDeps, type UnionToIntersection, type UniqueConfig, type UpdateConfigByCodeInput, type UpdateStatusRequestRepository, type UpdateUINConfigRequest, type ValidationErrorItem, commonService, customOmit, findDifferences, fromTimestampToSqlDatetime, getDynamicValue, getNestedValue, getPattern, interpolate, objectTo2DArray, toNumberOrNull, toUINConfigDTO, uinConfigService, type updateStatusParams };
|
package/dist/index.d.ts
CHANGED
|
@@ -525,6 +525,7 @@ declare function customOmit<T extends object, K extends keyof T>(obj: T, keys: K
|
|
|
525
525
|
omitted: Pick<T, K>;
|
|
526
526
|
};
|
|
527
527
|
declare function getDynamicValue(obj: Record<string, any> | null | undefined, accessorKey: string): any | null;
|
|
528
|
+
declare function getNestedValue<T = unknown>(obj: unknown, path?: string | null, defaultValue?: T): T | undefined;
|
|
528
529
|
declare function objectTo2DArray<T>(obj: Record<string, T>, maxCols: number): (string | T)[][];
|
|
529
530
|
declare function toNumberOrNull(value: unknown): number | null;
|
|
530
531
|
declare const getPattern: {
|
|
@@ -694,4 +695,4 @@ declare class AuditProxy<Module extends string = "OPD" | "PROCEDURE" | "GENERAL_
|
|
|
694
695
|
createAuditedService<T extends object>(serviceName: string, service: T): T;
|
|
695
696
|
}
|
|
696
697
|
|
|
697
|
-
export { type AuditContext, type AuditContextProvider, AuditCore, type AuditLogPayload, AuditLogger, AuditProxy, type BulkAtomicResult, type BulkConfig, type BulkConflictConfig, type BulkOnConflict, type CacheAdapter, type CalculationRes, type ColValue, type CommonCreateRequestRepository, type CommonExcelRequest, type CommonFilterRequest, type CommonFilterWithDate, type CommonServiceResponse, type CommonUpdateRequestRepository, type Config, type Context, type CreateUINConfigRequest, type CrudContext, type CrudDelegate, type DataType, type DeepMerge, type DeleteParams, type DeleteRequestRepository, type Deps, type DropdownRequest, type DropdownRequestService, type DtoFromMapping, type DtoNullOnMissing, type DynamicCreateInput, type DynamicCrudConfig, type DynamicShortCode, type DynamicUpdateInput, type EmitPayload, type EmployeeCache, type ExcelConfig, type ExportExcel, type ExportExcelRequestService, type FetchRequest, type FetchRequestRepository, type FieldConfig, type FieldRules, type FieldType, type FixedMap, type FixedSearchRequest, type FixedSearchRequestService, type Helpers, type ImportExcel, type ImportExcelRequestService, type LockUnlockParams, type LockUnlockRequestRepository, type LogicNode, type Mapper, type MergeAll, type NewFixedSearchRequest, type NewFixedSearchRequestService, type NewSearchRequest, NotificationEmitter, type Op, type PaginatedResponse, type PathToSelectWithSelect, type PathValue, type PathsToSelectWithSelect, type Presence, type Recipient, type RelationConfig, type RelationStrategy, type RelationWriteConfig, type SearchRequest, type SearchRequestService, type ServiceCacheAdapter, type SingleValidationMapping, type SourcePath, type Store, type ToggleActive, type TxClient, type UINConfigDTO, type UINPreviewRequest, type UINSegment, type UINSegmentType, type UIN_RESET_POLICY, type UinDeps, type UnionToIntersection, type UniqueConfig, type UpdateConfigByCodeInput, type UpdateStatusRequestRepository, type UpdateUINConfigRequest, type ValidationErrorItem, commonService, customOmit, findDifferences, fromTimestampToSqlDatetime, getDynamicValue, getPattern, interpolate, objectTo2DArray, toNumberOrNull, toUINConfigDTO, uinConfigService, type updateStatusParams };
|
|
698
|
+
export { type AuditContext, type AuditContextProvider, AuditCore, type AuditLogPayload, AuditLogger, AuditProxy, type BulkAtomicResult, type BulkConfig, type BulkConflictConfig, type BulkOnConflict, type CacheAdapter, type CalculationRes, type ColValue, type CommonCreateRequestRepository, type CommonExcelRequest, type CommonFilterRequest, type CommonFilterWithDate, type CommonServiceResponse, type CommonUpdateRequestRepository, type Config, type Context, type CreateUINConfigRequest, type CrudContext, type CrudDelegate, type DataType, type DeepMerge, type DeleteParams, type DeleteRequestRepository, type Deps, type DropdownRequest, type DropdownRequestService, type DtoFromMapping, type DtoNullOnMissing, type DynamicCreateInput, type DynamicCrudConfig, type DynamicShortCode, type DynamicUpdateInput, type EmitPayload, type EmployeeCache, type ExcelConfig, type ExportExcel, type ExportExcelRequestService, type FetchRequest, type FetchRequestRepository, type FieldConfig, type FieldRules, type FieldType, type FixedMap, type FixedSearchRequest, type FixedSearchRequestService, type Helpers, type ImportExcel, type ImportExcelRequestService, type LockUnlockParams, type LockUnlockRequestRepository, type LogicNode, type Mapper, type MergeAll, type NewFixedSearchRequest, type NewFixedSearchRequestService, type NewSearchRequest, NotificationEmitter, type Op, type PaginatedResponse, type PathToSelectWithSelect, type PathValue, type PathsToSelectWithSelect, type Presence, type Recipient, type RelationConfig, type RelationStrategy, type RelationWriteConfig, type SearchRequest, type SearchRequestService, type ServiceCacheAdapter, type SingleValidationMapping, type SourcePath, type Store, type ToggleActive, type TxClient, type UINConfigDTO, type UINPreviewRequest, type UINSegment, type UINSegmentType, type UIN_RESET_POLICY, type UinDeps, type UnionToIntersection, type UniqueConfig, type UpdateConfigByCodeInput, type UpdateStatusRequestRepository, type UpdateUINConfigRequest, type ValidationErrorItem, commonService, customOmit, findDifferences, fromTimestampToSqlDatetime, getDynamicValue, getNestedValue, getPattern, interpolate, objectTo2DArray, toNumberOrNull, toUINConfigDTO, uinConfigService, type updateStatusParams };
|
package/dist/index.js
CHANGED
|
@@ -39,6 +39,7 @@ __export(index_exports, {
|
|
|
39
39
|
findDifferences: () => findDifferences,
|
|
40
40
|
fromTimestampToSqlDatetime: () => fromTimestampToSqlDatetime,
|
|
41
41
|
getDynamicValue: () => getDynamicValue,
|
|
42
|
+
getNestedValue: () => getNestedValue,
|
|
42
43
|
getPattern: () => getPattern,
|
|
43
44
|
interpolate: () => interpolate,
|
|
44
45
|
objectTo2DArray: () => objectTo2DArray,
|
|
@@ -1329,6 +1330,15 @@ function getDynamicValue(obj, accessorKey) {
|
|
|
1329
1330
|
}
|
|
1330
1331
|
return result === void 0 ? null : result;
|
|
1331
1332
|
}
|
|
1333
|
+
function getNestedValue(obj, path, defaultValue) {
|
|
1334
|
+
if (!obj || !path) return defaultValue;
|
|
1335
|
+
const normalizedPath = path.replace(/\[(\d+)\]/g, ".$1");
|
|
1336
|
+
const result = normalizedPath.split(".").reduce((acc, key) => {
|
|
1337
|
+
if (acc == null) return void 0;
|
|
1338
|
+
return acc[key];
|
|
1339
|
+
}, obj);
|
|
1340
|
+
return result === void 0 ? defaultValue : result;
|
|
1341
|
+
}
|
|
1332
1342
|
function objectTo2DArray(obj, maxCols) {
|
|
1333
1343
|
if (maxCols < 2) {
|
|
1334
1344
|
throw new Error("maxCols must be at least 2");
|
|
@@ -3168,9 +3178,9 @@ async function resolveAllRecipients(args) {
|
|
|
3168
3178
|
}
|
|
3169
3179
|
if (r.sourceType === "KEY_VALUE") {
|
|
3170
3180
|
const recs = toArray(cfg.recipients).map((x) => {
|
|
3171
|
-
const userIdVal = args.evtData
|
|
3172
|
-
const level1Val = args.evtData
|
|
3173
|
-
const level2Val = x.level2Id ? args.evtData
|
|
3181
|
+
const userIdVal = getNestedValue(args.evtData, x.userId);
|
|
3182
|
+
const level1Val = getNestedValue(args.evtData, x.level1Id);
|
|
3183
|
+
const level2Val = x.level2Id ? getNestedValue(args.evtData, x.level2Id) : void 0;
|
|
3174
3184
|
return {
|
|
3175
3185
|
userId: userIdVal != null ? Number(userIdVal) : null,
|
|
3176
3186
|
level1Id: level1Val != null ? Number(level1Val) : null,
|
|
@@ -3205,7 +3215,7 @@ async function resolveAllRecipients(args) {
|
|
|
3205
3215
|
}
|
|
3206
3216
|
if (r.sourceType === "KEY_VALUE") {
|
|
3207
3217
|
for (const k of toArray(cfg.recipients)) {
|
|
3208
|
-
const v = args.evtData
|
|
3218
|
+
const v = getNestedValue(args.evtData, k);
|
|
3209
3219
|
if (typeof v === "string") res[type].push(v);
|
|
3210
3220
|
if (Array.isArray(v)) res[type].push(...v.filter((x) => typeof x === "string"));
|
|
3211
3221
|
}
|
|
@@ -3528,26 +3538,28 @@ var NotificationService = class {
|
|
|
3528
3538
|
// Should-send checks
|
|
3529
3539
|
// --------------------------------------------------------------------------------------
|
|
3530
3540
|
shouldSendEmail(cfg) {
|
|
3531
|
-
return Boolean(cfg.allowEmail && cfg.serviceEvent.allowEmail
|
|
3541
|
+
return Boolean(cfg.allowEmail && cfg.serviceEvent.allowEmail);
|
|
3532
3542
|
}
|
|
3533
3543
|
shouldSendSms(cfg) {
|
|
3534
|
-
return Boolean(cfg.allowSms && cfg.serviceEvent.allowSms
|
|
3544
|
+
return Boolean(cfg.allowSms && cfg.serviceEvent.allowSms);
|
|
3535
3545
|
}
|
|
3536
3546
|
shouldSendWhatsapp(cfg) {
|
|
3537
|
-
return Boolean(cfg.allowWhatsapp && cfg.serviceEvent.allowWhatsapp
|
|
3547
|
+
return Boolean(cfg.allowWhatsapp && cfg.serviceEvent.allowWhatsapp);
|
|
3538
3548
|
}
|
|
3539
3549
|
shouldSendApp(cfg) {
|
|
3540
|
-
return Boolean(cfg.allowAppNotification && cfg.serviceEvent.allowAppNotification
|
|
3550
|
+
return Boolean(cfg.allowAppNotification && cfg.serviceEvent.allowAppNotification);
|
|
3541
3551
|
}
|
|
3542
3552
|
shouldSendWeb(cfg) {
|
|
3543
|
-
return Boolean(cfg.allowWebNotification && cfg.serviceEvent.allowWebNotification
|
|
3553
|
+
return Boolean(cfg.allowWebNotification && cfg.serviceEvent.allowWebNotification);
|
|
3544
3554
|
}
|
|
3545
3555
|
// --------------------------------------------------------------------------------------
|
|
3546
3556
|
// Channel processors
|
|
3547
3557
|
// --------------------------------------------------------------------------------------
|
|
3548
3558
|
async processEmailChannel(args) {
|
|
3549
3559
|
const { cfg, evt, deliveryId } = args;
|
|
3550
|
-
const tpl = await this.prisma.template.
|
|
3560
|
+
const tpl = await this.prisma.template.findFirst({
|
|
3561
|
+
where: { eventConfigId: cfg.id, templateType: "EMAIL" /* EMAIL */ }
|
|
3562
|
+
});
|
|
3551
3563
|
if (!tpl) return;
|
|
3552
3564
|
const recipients = args.recipients;
|
|
3553
3565
|
if (!recipients.length) {
|
|
@@ -3574,7 +3586,9 @@ var NotificationService = class {
|
|
|
3574
3586
|
}
|
|
3575
3587
|
async processSmsChannel(args) {
|
|
3576
3588
|
const { cfg, evt, deliveryId } = args;
|
|
3577
|
-
const tpl = await this.prisma.template.
|
|
3589
|
+
const tpl = await this.prisma.template.findFirst({
|
|
3590
|
+
where: { eventConfigId: cfg.id, templateType: "SMS" /* SMS */ }
|
|
3591
|
+
});
|
|
3578
3592
|
if (!tpl) return;
|
|
3579
3593
|
const recipients = args.recipients ?? [];
|
|
3580
3594
|
if (!recipients.length) {
|
|
@@ -3650,12 +3664,11 @@ var NotificationService = class {
|
|
|
3650
3664
|
}
|
|
3651
3665
|
async processAppChannel(args) {
|
|
3652
3666
|
const { cfg, evt, deliveryId } = args;
|
|
3653
|
-
const tpl = await this.prisma.template.
|
|
3667
|
+
const tpl = await this.prisma.template.findFirst({
|
|
3668
|
+
where: { eventConfigId: cfg.id, templateType: "APP_NOTIFICATION" /* APP_NOTIFICATION */ }
|
|
3669
|
+
});
|
|
3654
3670
|
if (!tpl) return;
|
|
3655
|
-
let appUrlTpl =
|
|
3656
|
-
if (cfg.allowAppNotification && cfg.serviceEvent.allowAppNotification && cfg.appNotificationUrlTemplateId) {
|
|
3657
|
-
appUrlTpl = await this.prisma.template.findUnique({ where: { id: cfg.appNotificationUrlTemplateId } });
|
|
3658
|
-
}
|
|
3671
|
+
let appUrlTpl = tpl.url;
|
|
3659
3672
|
const userIds = (args.recipients ?? []).map((x) => Number(x)).filter((n) => Number.isFinite(n) && n > 0);
|
|
3660
3673
|
if (!userIds.length) {
|
|
3661
3674
|
this.logger.info("[NotificationService] APP: no userIds resolved");
|
|
@@ -3663,7 +3676,7 @@ var NotificationService = class {
|
|
|
3663
3676
|
}
|
|
3664
3677
|
const title = renderTemplate(tpl.subject ?? "", evt.data ?? {});
|
|
3665
3678
|
const body = renderTemplate(tpl.bodyText ?? "", evt.data ?? {});
|
|
3666
|
-
const route = appUrlTpl ? renderTemplate(appUrlTpl
|
|
3679
|
+
const route = appUrlTpl ? renderTemplate(appUrlTpl ?? "", evt.data ?? {}) : null;
|
|
3667
3680
|
const tokensMap = await this.getExpoTokensByUserIds(userIds);
|
|
3668
3681
|
const expoProvider = new ExpoAppNotificationProvider(
|
|
3669
3682
|
this.logger,
|
|
@@ -3742,21 +3755,21 @@ var NotificationService = class {
|
|
|
3742
3755
|
}
|
|
3743
3756
|
async processWebChannel(args) {
|
|
3744
3757
|
const { cfg, evt, deliveryId } = args;
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
webUrlTpl = await this.prisma.template.findUnique({ where: { id: cfg.webNotificationUrlTemplateId } });
|
|
3758
|
+
const webTpl = await this.prisma.template.findFirst({
|
|
3759
|
+
where: { eventConfigId: cfg.id, templateType: "WEB_NOTIFICATION" /* WEB_NOTIFICATION */ }
|
|
3760
|
+
});
|
|
3761
|
+
if (!webTpl) {
|
|
3762
|
+
this.logger.error("[NotificationService] WEB: no template found");
|
|
3763
|
+
return;
|
|
3752
3764
|
}
|
|
3765
|
+
let webUrlTpl = webTpl?.url;
|
|
3753
3766
|
const recipients = args.recipients;
|
|
3754
3767
|
if (!recipients.length) {
|
|
3755
|
-
this.logger.
|
|
3768
|
+
this.logger.error("[NotificationService] WEB: no recipients resolved");
|
|
3756
3769
|
return;
|
|
3757
3770
|
}
|
|
3758
3771
|
const message = renderTemplate(webTpl.bodyText ?? "", evt.data ?? {});
|
|
3759
|
-
const link = webUrlTpl ? renderTemplate(webUrlTpl
|
|
3772
|
+
const link = webUrlTpl ? renderTemplate(webUrlTpl ?? "", evt.data ?? {}) : null;
|
|
3760
3773
|
const provider = new WebNotificationProvider(this.prisma, this.logger);
|
|
3761
3774
|
const bulk = await provider.sendBulk({
|
|
3762
3775
|
source: evt.service,
|
|
@@ -3804,7 +3817,9 @@ var NotificationService = class {
|
|
|
3804
3817
|
}
|
|
3805
3818
|
async processWhatsappChannel(args) {
|
|
3806
3819
|
const { cfg, evt, deliveryId } = args;
|
|
3807
|
-
const tpl = await this.prisma.template.
|
|
3820
|
+
const tpl = await this.prisma.template.findFirst({
|
|
3821
|
+
where: { eventConfigId: cfg.id, templateType: "WHATSAPP" /* WHATSAPP */ }
|
|
3822
|
+
});
|
|
3808
3823
|
if (!tpl) return;
|
|
3809
3824
|
const recipients = args.recipients;
|
|
3810
3825
|
if (!recipients.length) {
|
|
@@ -4144,6 +4159,7 @@ var AuditProxy = class {
|
|
|
4144
4159
|
findDifferences,
|
|
4145
4160
|
fromTimestampToSqlDatetime,
|
|
4146
4161
|
getDynamicValue,
|
|
4162
|
+
getNestedValue,
|
|
4147
4163
|
getPattern,
|
|
4148
4164
|
interpolate,
|
|
4149
4165
|
objectTo2DArray,
|
package/dist/index.mjs
CHANGED
|
@@ -1279,6 +1279,15 @@ function getDynamicValue(obj, accessorKey) {
|
|
|
1279
1279
|
}
|
|
1280
1280
|
return result === void 0 ? null : result;
|
|
1281
1281
|
}
|
|
1282
|
+
function getNestedValue(obj, path, defaultValue) {
|
|
1283
|
+
if (!obj || !path) return defaultValue;
|
|
1284
|
+
const normalizedPath = path.replace(/\[(\d+)\]/g, ".$1");
|
|
1285
|
+
const result = normalizedPath.split(".").reduce((acc, key) => {
|
|
1286
|
+
if (acc == null) return void 0;
|
|
1287
|
+
return acc[key];
|
|
1288
|
+
}, obj);
|
|
1289
|
+
return result === void 0 ? defaultValue : result;
|
|
1290
|
+
}
|
|
1282
1291
|
function objectTo2DArray(obj, maxCols) {
|
|
1283
1292
|
if (maxCols < 2) {
|
|
1284
1293
|
throw new Error("maxCols must be at least 2");
|
|
@@ -3118,9 +3127,9 @@ async function resolveAllRecipients(args) {
|
|
|
3118
3127
|
}
|
|
3119
3128
|
if (r.sourceType === "KEY_VALUE") {
|
|
3120
3129
|
const recs = toArray(cfg.recipients).map((x) => {
|
|
3121
|
-
const userIdVal = args.evtData
|
|
3122
|
-
const level1Val = args.evtData
|
|
3123
|
-
const level2Val = x.level2Id ? args.evtData
|
|
3130
|
+
const userIdVal = getNestedValue(args.evtData, x.userId);
|
|
3131
|
+
const level1Val = getNestedValue(args.evtData, x.level1Id);
|
|
3132
|
+
const level2Val = x.level2Id ? getNestedValue(args.evtData, x.level2Id) : void 0;
|
|
3124
3133
|
return {
|
|
3125
3134
|
userId: userIdVal != null ? Number(userIdVal) : null,
|
|
3126
3135
|
level1Id: level1Val != null ? Number(level1Val) : null,
|
|
@@ -3155,7 +3164,7 @@ async function resolveAllRecipients(args) {
|
|
|
3155
3164
|
}
|
|
3156
3165
|
if (r.sourceType === "KEY_VALUE") {
|
|
3157
3166
|
for (const k of toArray(cfg.recipients)) {
|
|
3158
|
-
const v = args.evtData
|
|
3167
|
+
const v = getNestedValue(args.evtData, k);
|
|
3159
3168
|
if (typeof v === "string") res[type].push(v);
|
|
3160
3169
|
if (Array.isArray(v)) res[type].push(...v.filter((x) => typeof x === "string"));
|
|
3161
3170
|
}
|
|
@@ -3478,26 +3487,28 @@ var NotificationService = class {
|
|
|
3478
3487
|
// Should-send checks
|
|
3479
3488
|
// --------------------------------------------------------------------------------------
|
|
3480
3489
|
shouldSendEmail(cfg) {
|
|
3481
|
-
return Boolean(cfg.allowEmail && cfg.serviceEvent.allowEmail
|
|
3490
|
+
return Boolean(cfg.allowEmail && cfg.serviceEvent.allowEmail);
|
|
3482
3491
|
}
|
|
3483
3492
|
shouldSendSms(cfg) {
|
|
3484
|
-
return Boolean(cfg.allowSms && cfg.serviceEvent.allowSms
|
|
3493
|
+
return Boolean(cfg.allowSms && cfg.serviceEvent.allowSms);
|
|
3485
3494
|
}
|
|
3486
3495
|
shouldSendWhatsapp(cfg) {
|
|
3487
|
-
return Boolean(cfg.allowWhatsapp && cfg.serviceEvent.allowWhatsapp
|
|
3496
|
+
return Boolean(cfg.allowWhatsapp && cfg.serviceEvent.allowWhatsapp);
|
|
3488
3497
|
}
|
|
3489
3498
|
shouldSendApp(cfg) {
|
|
3490
|
-
return Boolean(cfg.allowAppNotification && cfg.serviceEvent.allowAppNotification
|
|
3499
|
+
return Boolean(cfg.allowAppNotification && cfg.serviceEvent.allowAppNotification);
|
|
3491
3500
|
}
|
|
3492
3501
|
shouldSendWeb(cfg) {
|
|
3493
|
-
return Boolean(cfg.allowWebNotification && cfg.serviceEvent.allowWebNotification
|
|
3502
|
+
return Boolean(cfg.allowWebNotification && cfg.serviceEvent.allowWebNotification);
|
|
3494
3503
|
}
|
|
3495
3504
|
// --------------------------------------------------------------------------------------
|
|
3496
3505
|
// Channel processors
|
|
3497
3506
|
// --------------------------------------------------------------------------------------
|
|
3498
3507
|
async processEmailChannel(args) {
|
|
3499
3508
|
const { cfg, evt, deliveryId } = args;
|
|
3500
|
-
const tpl = await this.prisma.template.
|
|
3509
|
+
const tpl = await this.prisma.template.findFirst({
|
|
3510
|
+
where: { eventConfigId: cfg.id, templateType: "EMAIL" /* EMAIL */ }
|
|
3511
|
+
});
|
|
3501
3512
|
if (!tpl) return;
|
|
3502
3513
|
const recipients = args.recipients;
|
|
3503
3514
|
if (!recipients.length) {
|
|
@@ -3524,7 +3535,9 @@ var NotificationService = class {
|
|
|
3524
3535
|
}
|
|
3525
3536
|
async processSmsChannel(args) {
|
|
3526
3537
|
const { cfg, evt, deliveryId } = args;
|
|
3527
|
-
const tpl = await this.prisma.template.
|
|
3538
|
+
const tpl = await this.prisma.template.findFirst({
|
|
3539
|
+
where: { eventConfigId: cfg.id, templateType: "SMS" /* SMS */ }
|
|
3540
|
+
});
|
|
3528
3541
|
if (!tpl) return;
|
|
3529
3542
|
const recipients = args.recipients ?? [];
|
|
3530
3543
|
if (!recipients.length) {
|
|
@@ -3600,12 +3613,11 @@ var NotificationService = class {
|
|
|
3600
3613
|
}
|
|
3601
3614
|
async processAppChannel(args) {
|
|
3602
3615
|
const { cfg, evt, deliveryId } = args;
|
|
3603
|
-
const tpl = await this.prisma.template.
|
|
3616
|
+
const tpl = await this.prisma.template.findFirst({
|
|
3617
|
+
where: { eventConfigId: cfg.id, templateType: "APP_NOTIFICATION" /* APP_NOTIFICATION */ }
|
|
3618
|
+
});
|
|
3604
3619
|
if (!tpl) return;
|
|
3605
|
-
let appUrlTpl =
|
|
3606
|
-
if (cfg.allowAppNotification && cfg.serviceEvent.allowAppNotification && cfg.appNotificationUrlTemplateId) {
|
|
3607
|
-
appUrlTpl = await this.prisma.template.findUnique({ where: { id: cfg.appNotificationUrlTemplateId } });
|
|
3608
|
-
}
|
|
3620
|
+
let appUrlTpl = tpl.url;
|
|
3609
3621
|
const userIds = (args.recipients ?? []).map((x) => Number(x)).filter((n) => Number.isFinite(n) && n > 0);
|
|
3610
3622
|
if (!userIds.length) {
|
|
3611
3623
|
this.logger.info("[NotificationService] APP: no userIds resolved");
|
|
@@ -3613,7 +3625,7 @@ var NotificationService = class {
|
|
|
3613
3625
|
}
|
|
3614
3626
|
const title = renderTemplate(tpl.subject ?? "", evt.data ?? {});
|
|
3615
3627
|
const body = renderTemplate(tpl.bodyText ?? "", evt.data ?? {});
|
|
3616
|
-
const route = appUrlTpl ? renderTemplate(appUrlTpl
|
|
3628
|
+
const route = appUrlTpl ? renderTemplate(appUrlTpl ?? "", evt.data ?? {}) : null;
|
|
3617
3629
|
const tokensMap = await this.getExpoTokensByUserIds(userIds);
|
|
3618
3630
|
const expoProvider = new ExpoAppNotificationProvider(
|
|
3619
3631
|
this.logger,
|
|
@@ -3692,21 +3704,21 @@ var NotificationService = class {
|
|
|
3692
3704
|
}
|
|
3693
3705
|
async processWebChannel(args) {
|
|
3694
3706
|
const { cfg, evt, deliveryId } = args;
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
webUrlTpl = await this.prisma.template.findUnique({ where: { id: cfg.webNotificationUrlTemplateId } });
|
|
3707
|
+
const webTpl = await this.prisma.template.findFirst({
|
|
3708
|
+
where: { eventConfigId: cfg.id, templateType: "WEB_NOTIFICATION" /* WEB_NOTIFICATION */ }
|
|
3709
|
+
});
|
|
3710
|
+
if (!webTpl) {
|
|
3711
|
+
this.logger.error("[NotificationService] WEB: no template found");
|
|
3712
|
+
return;
|
|
3702
3713
|
}
|
|
3714
|
+
let webUrlTpl = webTpl?.url;
|
|
3703
3715
|
const recipients = args.recipients;
|
|
3704
3716
|
if (!recipients.length) {
|
|
3705
|
-
this.logger.
|
|
3717
|
+
this.logger.error("[NotificationService] WEB: no recipients resolved");
|
|
3706
3718
|
return;
|
|
3707
3719
|
}
|
|
3708
3720
|
const message = renderTemplate(webTpl.bodyText ?? "", evt.data ?? {});
|
|
3709
|
-
const link = webUrlTpl ? renderTemplate(webUrlTpl
|
|
3721
|
+
const link = webUrlTpl ? renderTemplate(webUrlTpl ?? "", evt.data ?? {}) : null;
|
|
3710
3722
|
const provider = new WebNotificationProvider(this.prisma, this.logger);
|
|
3711
3723
|
const bulk = await provider.sendBulk({
|
|
3712
3724
|
source: evt.service,
|
|
@@ -3754,7 +3766,9 @@ var NotificationService = class {
|
|
|
3754
3766
|
}
|
|
3755
3767
|
async processWhatsappChannel(args) {
|
|
3756
3768
|
const { cfg, evt, deliveryId } = args;
|
|
3757
|
-
const tpl = await this.prisma.template.
|
|
3769
|
+
const tpl = await this.prisma.template.findFirst({
|
|
3770
|
+
where: { eventConfigId: cfg.id, templateType: "WHATSAPP" /* WHATSAPP */ }
|
|
3771
|
+
});
|
|
3758
3772
|
if (!tpl) return;
|
|
3759
3773
|
const recipients = args.recipients;
|
|
3760
3774
|
if (!recipients.length) {
|
|
@@ -4093,6 +4107,7 @@ export {
|
|
|
4093
4107
|
findDifferences,
|
|
4094
4108
|
fromTimestampToSqlDatetime,
|
|
4095
4109
|
getDynamicValue,
|
|
4110
|
+
getNestedValue,
|
|
4096
4111
|
getPattern,
|
|
4097
4112
|
interpolate,
|
|
4098
4113
|
objectTo2DArray,
|