av6-core 1.6.6 → 1.6.8

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 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: {
@@ -622,7 +623,6 @@ type EmitPayload = {
622
623
  service: string;
623
624
  shortCode: string;
624
625
  data?: Record<string, any>;
625
- dataWp?: any[];
626
626
  };
627
627
  type ILogger = winston.Logger | Console;
628
628
  type NotificationEmitterDeps = {
@@ -694,4 +694,4 @@ declare class AuditProxy<Module extends string = "OPD" | "PROCEDURE" | "GENERAL_
694
694
  createAuditedService<T extends object>(serviceName: string, service: T): T;
695
695
  }
696
696
 
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 };
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, 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: {
@@ -622,7 +623,6 @@ type EmitPayload = {
622
623
  service: string;
623
624
  shortCode: string;
624
625
  data?: Record<string, any>;
625
- dataWp?: any[];
626
626
  };
627
627
  type ILogger = winston.Logger | Console;
628
628
  type NotificationEmitterDeps = {
@@ -694,4 +694,4 @@ declare class AuditProxy<Module extends string = "OPD" | "PROCEDURE" | "GENERAL_
694
694
  createAuditedService<T extends object>(serviceName: string, service: T): T;
695
695
  }
696
696
 
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 };
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, 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?.[x.userId];
3172
- const level1Val = args.evtData?.[x.level1Id];
3173
- const level2Val = x.level2Id ? args.evtData?.[x.level2Id] : void 0;
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?.[k];
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
  }
@@ -3379,7 +3389,7 @@ var WhatsAppProvider = class {
3379
3389
  }
3380
3390
  };
3381
3391
  if (inp.fileUrl) {
3382
- requestBody.template.headerValues = [inp.fileUrl];
3392
+ requestBody.template.headerValues = inp.fileUrl;
3383
3393
  if (inp.fileName) requestBody.template.fileName = inp.fileName;
3384
3394
  }
3385
3395
  const headers = {
@@ -3816,6 +3826,10 @@ var NotificationService = class {
3816
3826
  this.logger.info("[NotificationService] WhatsApp: no recipients resolved");
3817
3827
  return;
3818
3828
  }
3829
+ const message = renderTemplate(tpl.bodyText ?? "", evt.data ?? {});
3830
+ const dataWp = tpl.extra?.bodyValues?.map((x) => getNestedValue(evt.data, x));
3831
+ const fileUrls = tpl.extra?.fileUrls?.map((x) => getNestedValue(evt.data, x));
3832
+ const fileName = getNestedValue(tpl.extra?.fileName);
3819
3833
  const apiKey = cfg.serviceEvent.wpApiKey ?? "";
3820
3834
  if (!apiKey.trim()) {
3821
3835
  await this.writeSystemFailureItem({
@@ -3840,9 +3854,11 @@ var NotificationService = class {
3840
3854
  const bulk = await this.sendWhatsappBulkSafe({
3841
3855
  provider: waProvider,
3842
3856
  recipients,
3843
- bodyValues: evt.dataWp ?? [],
3857
+ bodyValues: dataWp ?? [],
3844
3858
  concurrency: 5,
3845
- includeMaster: Boolean(cfg.serviceEvent.masterPhone)
3859
+ includeMaster: Boolean(cfg.serviceEvent.masterPhone),
3860
+ fileName,
3861
+ fileUrls
3846
3862
  });
3847
3863
  for (const it of bulk.items) {
3848
3864
  await this.prisma.eventDeliveryItem.create({
@@ -3850,8 +3866,7 @@ var NotificationService = class {
3850
3866
  deliveryId,
3851
3867
  notificationType: "WHATSAPP" /* WHATSAPP */,
3852
3868
  recipient: it.recipient,
3853
- messageContent: null,
3854
- // Interakt template; body content not stored
3869
+ messageContent: message,
3855
3870
  thirdPartyResponse: it.meta ?? void 0,
3856
3871
  isSent: it.ok,
3857
3872
  sentAt: it.ok ? /* @__PURE__ */ new Date() : null,
@@ -3940,7 +3955,9 @@ var NotificationService = class {
3940
3955
  recipients: uniq,
3941
3956
  bodyValues: args.bodyValues,
3942
3957
  includeMaster: args.includeMaster,
3943
- concurrency: args.concurrency
3958
+ concurrency: args.concurrency,
3959
+ fileName: args.fileName,
3960
+ fileUrl: args.fileUrls
3944
3961
  });
3945
3962
  const items2 = (bulkRes?.items ?? []).map((x) => ({
3946
3963
  recipient: String(x.recipient ?? ""),
@@ -4149,6 +4166,7 @@ var AuditProxy = class {
4149
4166
  findDifferences,
4150
4167
  fromTimestampToSqlDatetime,
4151
4168
  getDynamicValue,
4169
+ getNestedValue,
4152
4170
  getPattern,
4153
4171
  interpolate,
4154
4172
  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?.[x.userId];
3122
- const level1Val = args.evtData?.[x.level1Id];
3123
- const level2Val = x.level2Id ? args.evtData?.[x.level2Id] : void 0;
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?.[k];
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
  }
@@ -3329,7 +3338,7 @@ var WhatsAppProvider = class {
3329
3338
  }
3330
3339
  };
3331
3340
  if (inp.fileUrl) {
3332
- requestBody.template.headerValues = [inp.fileUrl];
3341
+ requestBody.template.headerValues = inp.fileUrl;
3333
3342
  if (inp.fileName) requestBody.template.fileName = inp.fileName;
3334
3343
  }
3335
3344
  const headers = {
@@ -3766,6 +3775,10 @@ var NotificationService = class {
3766
3775
  this.logger.info("[NotificationService] WhatsApp: no recipients resolved");
3767
3776
  return;
3768
3777
  }
3778
+ const message = renderTemplate(tpl.bodyText ?? "", evt.data ?? {});
3779
+ const dataWp = tpl.extra?.bodyValues?.map((x) => getNestedValue(evt.data, x));
3780
+ const fileUrls = tpl.extra?.fileUrls?.map((x) => getNestedValue(evt.data, x));
3781
+ const fileName = getNestedValue(tpl.extra?.fileName);
3769
3782
  const apiKey = cfg.serviceEvent.wpApiKey ?? "";
3770
3783
  if (!apiKey.trim()) {
3771
3784
  await this.writeSystemFailureItem({
@@ -3790,9 +3803,11 @@ var NotificationService = class {
3790
3803
  const bulk = await this.sendWhatsappBulkSafe({
3791
3804
  provider: waProvider,
3792
3805
  recipients,
3793
- bodyValues: evt.dataWp ?? [],
3806
+ bodyValues: dataWp ?? [],
3794
3807
  concurrency: 5,
3795
- includeMaster: Boolean(cfg.serviceEvent.masterPhone)
3808
+ includeMaster: Boolean(cfg.serviceEvent.masterPhone),
3809
+ fileName,
3810
+ fileUrls
3796
3811
  });
3797
3812
  for (const it of bulk.items) {
3798
3813
  await this.prisma.eventDeliveryItem.create({
@@ -3800,8 +3815,7 @@ var NotificationService = class {
3800
3815
  deliveryId,
3801
3816
  notificationType: "WHATSAPP" /* WHATSAPP */,
3802
3817
  recipient: it.recipient,
3803
- messageContent: null,
3804
- // Interakt template; body content not stored
3818
+ messageContent: message,
3805
3819
  thirdPartyResponse: it.meta ?? void 0,
3806
3820
  isSent: it.ok,
3807
3821
  sentAt: it.ok ? /* @__PURE__ */ new Date() : null,
@@ -3890,7 +3904,9 @@ var NotificationService = class {
3890
3904
  recipients: uniq,
3891
3905
  bodyValues: args.bodyValues,
3892
3906
  includeMaster: args.includeMaster,
3893
- concurrency: args.concurrency
3907
+ concurrency: args.concurrency,
3908
+ fileName: args.fileName,
3909
+ fileUrl: args.fileUrls
3894
3910
  });
3895
3911
  const items2 = (bulkRes?.items ?? []).map((x) => ({
3896
3912
  recipient: String(x.recipient ?? ""),
@@ -4098,6 +4114,7 @@ export {
4098
4114
  findDifferences,
4099
4115
  fromTimestampToSqlDatetime,
4100
4116
  getDynamicValue,
4117
+ getNestedValue,
4101
4118
  getPattern,
4102
4119
  interpolate,
4103
4120
  objectTo2DArray,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "av6-core",
3
- "version": "1.6.6",
3
+ "version": "1.6.8",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",