av6-core 1.7.4 → 1.7.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.d.mts CHANGED
@@ -533,7 +533,7 @@ declare const getPattern: {
533
533
  };
534
534
  declare const interpolate: (template: string, vars: Record<string, unknown>) => string;
535
535
  declare const fromTimestampToSqlDatetime: (date: string) => string;
536
- declare function formatDatesDeep(data: any, format?: string): any;
536
+ declare function formatDatesDeep<T>(data: T, format?: string): T;
537
537
 
538
538
  interface CreateTransaction {
539
539
  field: string;
package/dist/index.d.ts CHANGED
@@ -533,7 +533,7 @@ declare const getPattern: {
533
533
  };
534
534
  declare const interpolate: (template: string, vars: Record<string, unknown>) => string;
535
535
  declare const fromTimestampToSqlDatetime: (date: string) => string;
536
- declare function formatDatesDeep(data: any, format?: string): any;
536
+ declare function formatDatesDeep<T>(data: T, format?: string): T;
537
537
 
538
538
  interface CreateTransaction {
539
539
  field: string;
package/dist/index.js CHANGED
@@ -1446,9 +1446,9 @@ function formatDatesDeep(data, format = "YYYY-MM-DD") {
1446
1446
  const result = {};
1447
1447
  for (const key in data) {
1448
1448
  const value = data[key];
1449
- if (value instanceof Date || (0, import_dayjs.default)(value).isValid()) {
1449
+ if (value instanceof Date || typeof value === "string" && (0, import_dayjs.default)(value, "YYYY-MM-DD", true).isValid()) {
1450
1450
  result[key] = (0, import_dayjs.default)(value).format(format);
1451
- } else if (Array.isArray(value) || typeof value === "object") {
1451
+ } else if (Array.isArray(value) || typeof value === "object" && value !== null) {
1452
1452
  result[key] = formatDatesDeep(value, format);
1453
1453
  } else {
1454
1454
  result[key] = value;
@@ -3452,9 +3452,31 @@ function renderTemplate(tpl, data) {
3452
3452
  function renderEmailTemplate(tpl, data) {
3453
3453
  return {
3454
3454
  subject: tpl.subject ? import_handlebars.default.compile(tpl.subject)(data) : void 0,
3455
- body: import_handlebars.default.compile(tpl.body)(data)
3455
+ body: import_handlebars.default.compile(convertArrayPatternToEachBlocksGeneric(tpl.body))(data)
3456
3456
  };
3457
3457
  }
3458
+ var convertArrayPatternToEachBlocksGeneric = (html) => {
3459
+ if (!html) return "";
3460
+ const blockTags = ["tr", "div", "li", "section", "tbody"];
3461
+ let output = html;
3462
+ blockTags.forEach((tag) => {
3463
+ const regex = new RegExp(`<${tag}\\b[^>]*>[\\s\\S]*?<\\/${tag}>`, "g");
3464
+ output = output.replace(regex, (blockHtml) => {
3465
+ const matches = [...blockHtml.matchAll(/{{\s*([a-zA-Z0-9_.-]+)\[\]\.([a-zA-Z0-9_.-]+)\s*}}/g)];
3466
+ if (!matches.length) return blockHtml;
3467
+ const uniqueArrays = Array.from(new Set(matches.map((m) => m[1])));
3468
+ if (uniqueArrays.length !== 1) return blockHtml;
3469
+ const arrayName = uniqueArrays[0];
3470
+ const escapedArray = arrayName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
3471
+ const cleanedBlock = blockHtml.replace(
3472
+ new RegExp(`{{\\s*${escapedArray}\\[\\]\\.([a-zA-Z0-9_.-]+)\\s*}}`, "g"),
3473
+ "{{$1}}"
3474
+ );
3475
+ return `{{#each ${arrayName}}}${cleanedBlock}{{/each}}`;
3476
+ });
3477
+ });
3478
+ return output;
3479
+ };
3458
3480
 
3459
3481
  // src/services/notification.service.ts
3460
3482
  var import_lodash = __toESM(require("lodash.merge"));
package/dist/index.mjs CHANGED
@@ -1394,9 +1394,9 @@ function formatDatesDeep(data, format = "YYYY-MM-DD") {
1394
1394
  const result = {};
1395
1395
  for (const key in data) {
1396
1396
  const value = data[key];
1397
- if (value instanceof Date || dayjs(value).isValid()) {
1397
+ if (value instanceof Date || typeof value === "string" && dayjs(value, "YYYY-MM-DD", true).isValid()) {
1398
1398
  result[key] = dayjs(value).format(format);
1399
- } else if (Array.isArray(value) || typeof value === "object") {
1399
+ } else if (Array.isArray(value) || typeof value === "object" && value !== null) {
1400
1400
  result[key] = formatDatesDeep(value, format);
1401
1401
  } else {
1402
1402
  result[key] = value;
@@ -3400,9 +3400,31 @@ function renderTemplate(tpl, data) {
3400
3400
  function renderEmailTemplate(tpl, data) {
3401
3401
  return {
3402
3402
  subject: tpl.subject ? Handlebars.compile(tpl.subject)(data) : void 0,
3403
- body: Handlebars.compile(tpl.body)(data)
3403
+ body: Handlebars.compile(convertArrayPatternToEachBlocksGeneric(tpl.body))(data)
3404
3404
  };
3405
3405
  }
3406
+ var convertArrayPatternToEachBlocksGeneric = (html) => {
3407
+ if (!html) return "";
3408
+ const blockTags = ["tr", "div", "li", "section", "tbody"];
3409
+ let output = html;
3410
+ blockTags.forEach((tag) => {
3411
+ const regex = new RegExp(`<${tag}\\b[^>]*>[\\s\\S]*?<\\/${tag}>`, "g");
3412
+ output = output.replace(regex, (blockHtml) => {
3413
+ const matches = [...blockHtml.matchAll(/{{\s*([a-zA-Z0-9_.-]+)\[\]\.([a-zA-Z0-9_.-]+)\s*}}/g)];
3414
+ if (!matches.length) return blockHtml;
3415
+ const uniqueArrays = Array.from(new Set(matches.map((m) => m[1])));
3416
+ if (uniqueArrays.length !== 1) return blockHtml;
3417
+ const arrayName = uniqueArrays[0];
3418
+ const escapedArray = arrayName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
3419
+ const cleanedBlock = blockHtml.replace(
3420
+ new RegExp(`{{\\s*${escapedArray}\\[\\]\\.([a-zA-Z0-9_.-]+)\\s*}}`, "g"),
3421
+ "{{$1}}"
3422
+ );
3423
+ return `{{#each ${arrayName}}}${cleanedBlock}{{/each}}`;
3424
+ });
3425
+ });
3426
+ return output;
3427
+ };
3406
3428
 
3407
3429
  // src/services/notification.service.ts
3408
3430
  import merge from "lodash.merge";
package/package.json CHANGED
@@ -1,39 +1,38 @@
1
- {
2
- "name": "av6-core",
3
- "version": "1.7.4",
4
- "main": "dist/index.js",
5
- "module": "dist/index.mjs",
6
- "types": "dist/index.d.ts",
7
- "description": "All utility function for av6 node js projects.",
8
- "author": "Aniket Sarkar",
9
- "license": "ISC",
10
- "scripts": {
11
- "build": "npm run format && tsup",
12
- "p:gen": "prisma generate",
13
- "format": "prettier --write **/*.ts"
14
- },
15
- "devDependencies": {
16
- "@prisma/client": "^6.19.0",
17
- "@types/lodash.merge": "^4.6.9",
18
- "@types/nodemailer": "^7.0.3",
19
- "tsup": "^8.5.0",
20
- "typescript": "^5.9.2"
21
- },
22
- "peerDependencies": {
23
- "@prisma/client": "^6.19.0",
24
- "winston": "^3.17.0"
25
- },
26
- "dependencies": {
27
- "av6-utils": "^1.0.4",
28
- "axios": "^1.11.0",
29
- "dayjs": "^1.11.19",
30
- "exceljs": "^4.4.0",
31
- "handlebars": "^4.7.8",
32
- "joi": "^17.13.3",
33
- "lodash.merge": "^4.6.2",
34
- "node-cron": "^4.2.1",
35
- "nodemailer": "^7.0.10",
36
- "prettier": "^3.6.2",
37
- "prisma": "^6.19.0"
38
- }
39
- }
1
+ {
2
+ "name": "av6-core",
3
+ "version": "1.7.6",
4
+ "main": "dist/index.js",
5
+ "module": "dist/index.mjs",
6
+ "types": "dist/index.d.ts",
7
+ "description": "All utility function for av6 node js projects.",
8
+ "author": "Aniket Sarkar",
9
+ "license": "ISC",
10
+ "scripts": {
11
+ "build": "npm run format && tsup",
12
+ "p:gen": "prisma generate",
13
+ "format": "prettier --write **/*.ts"
14
+ },
15
+ "devDependencies": {
16
+ "@types/lodash.merge": "^4.6.9",
17
+ "@types/nodemailer": "^7.0.3",
18
+ "tsup": "^8.5.0",
19
+ "typescript": "^5.9.2"
20
+ },
21
+ "peerDependencies": {
22
+ "@prisma/client": "^6.19.0",
23
+ "winston": "^3.17.0"
24
+ },
25
+ "dependencies": {
26
+ "av6-utils": "^1.0.4",
27
+ "axios": "^1.11.0",
28
+ "dayjs": "^1.11.19",
29
+ "exceljs": "^4.4.0",
30
+ "handlebars": "^4.7.8",
31
+ "joi": "^17.13.3",
32
+ "lodash.merge": "^4.6.2",
33
+ "node-cron": "^4.2.1",
34
+ "nodemailer": "^7.0.10",
35
+ "prettier": "^3.6.2",
36
+ "prisma": "^6.19.0"
37
+ }
38
+ }
@@ -0,0 +1,12 @@
1
+ declare module "@prisma/client" {
2
+ export class PrismaClient {
3
+ [key: string]: any;
4
+ }
5
+
6
+ export namespace Prisma {
7
+ export type TransactionClient = any;
8
+ export type JsonValue = any;
9
+ export type JsonObject = any;
10
+ export type JsonArray = any;
11
+ }
12
+ }
@@ -1,100 +0,0 @@
1
- // #region agent log
2
- fetch('http://127.0.0.1:7244/ingest/0a9f7972-5d03-4255-b5c9-6164f846fb46',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'debug-check-prisma.ts:1',message:'Starting Prisma client check',data:{timestamp:Date.now()},sessionId:'debug-session',runId:'run1',hypothesisId:'A'})}).catch(()=>{});
3
- // #endregion
4
-
5
- import * as fs from 'fs';
6
- import * as path from 'path';
7
-
8
- const workspaceRoot = path.resolve(__dirname, '..');
9
- const nodeModulesPath = path.join(workspaceRoot, 'node_modules');
10
- const prismaClientPath = path.join(nodeModulesPath, '@prisma', 'client');
11
- const prismaGeneratedPath = path.join(nodeModulesPath, '.prisma', 'client');
12
-
13
- // #region agent log
14
- fetch('http://127.0.0.1:7244/ingest/0a9f7972-5d03-4255-b5c9-6164f846fb46',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'debug-check-prisma.ts:10',message:'Checking paths',data:{workspaceRoot,prismaClientPath,prismaGeneratedPath,prismaClientExists:fs.existsSync(prismaClientPath),prismaGeneratedExists:fs.existsSync(prismaGeneratedPath)},sessionId:'debug-session',runId:'run1',hypothesisId:'A'})}).catch(()=>{});
15
- // #endregion
16
-
17
- // Check if @prisma/client package exists
18
- const prismaClientExists = fs.existsSync(prismaClientPath);
19
- const prismaGeneratedExists = fs.existsSync(prismaGeneratedPath);
20
-
21
- // #region agent log
22
- fetch('http://127.0.0.1:7244/ingest/0a9f7972-5d03-4255-b5c9-6164f846fb46',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'debug-check-prisma.ts:18',message:'Path check results',data:{prismaClientExists,prismaGeneratedExists},sessionId:'debug-session',runId:'run1',hypothesisId:'A'})}).catch(()=>{});
23
- // #endregion
24
-
25
- // Try to read package.json from @prisma/client
26
- let prismaClientPackageJson: any = null;
27
- if (prismaClientExists) {
28
- try {
29
- const packageJsonPath = path.join(prismaClientPath, 'package.json');
30
- // #region agent log
31
- fetch('http://127.0.0.1:7244/ingest/0a9f7972-5d03-4255-b5c9-6164f846fb46',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'debug-check-prisma.ts:26',message:'Reading @prisma/client package.json',data:{packageJsonPath,exists:fs.existsSync(packageJsonPath)},sessionId:'debug-session',runId:'run1',hypothesisId:'B'})}).catch(()=>{});
32
- // #endregion
33
- if (fs.existsSync(packageJsonPath)) {
34
- prismaClientPackageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
35
- // #region agent log
36
- fetch('http://127.0.0.1:7244/ingest/0a9f7972-5d03-4255-b5c9-6164f846fb46',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'debug-check-prisma.ts:30',message:'@prisma/client package.json content',data:{name:prismaClientPackageJson?.name,version:prismaClientPackageJson?.version,exports:prismaClientPackageJson?.exports},sessionId:'debug-session',runId:'run1',hypothesisId:'B'})}).catch(()=>{});
37
- // #endregion
38
- }
39
- } catch (e) {
40
- // #region agent log
41
- fetch('http://127.0.0.1:7244/ingest/0a9f7972-5d03-4255-b5c9-6164f846fb46',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'debug-check-prisma.ts:34',message:'Error reading package.json',data:{error:String(e)},sessionId:'debug-session',runId:'run1',hypothesisId:'B'})}).catch(()=>{});
42
- // #endregion
43
- }
44
- }
45
-
46
- // Check index.d.ts in @prisma/client
47
- let indexDtsContent: string | null = null;
48
- if (prismaClientExists) {
49
- try {
50
- const indexDtsPath = path.join(prismaClientPath, 'index.d.ts');
51
- // #region agent log
52
- fetch('http://127.0.0.1:7244/ingest/0a9f7972-5d03-4255-b5c9-6164f846fb46',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'debug-check-prisma.ts:43',message:'Reading index.d.ts',data:{indexDtsPath,exists:fs.existsSync(indexDtsPath)},sessionId:'debug-session',runId:'run1',hypothesisId:'C'})}).catch(()=>{});
53
- // #endregion
54
- if (fs.existsSync(indexDtsPath)) {
55
- indexDtsContent = fs.readFileSync(indexDtsPath, 'utf-8');
56
- // #region agent log
57
- fetch('http://127.0.0.1:7244/ingest/0a9f7972-5d03-4255-b5c9-6164f846fb46',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'debug-check-prisma.ts:47',message:'index.d.ts content',data:{content:indexDtsContent.substring(0,200)},sessionId:'debug-session',runId:'run1',hypothesisId:'C'})}).catch(()=>{});
58
- // #endregion
59
- }
60
- } catch (e) {
61
- // #region agent log
62
- fetch('http://127.0.0.1:7244/ingest/0a9f7972-5d03-4255-b5c9-6164f846fb46',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'debug-check-prisma.ts:51',message:'Error reading index.d.ts',data:{error:String(e)},sessionId:'debug-session',runId:'run1',hypothesisId:'C'})}).catch(()=>{});
63
- // #endregion
64
- }
65
- }
66
-
67
- // Try to dynamically import PrismaClient
68
- let prismaClientImportSuccess = false;
69
- let prismaClientImportError: string | null = null;
70
- try {
71
- // #region agent log
72
- fetch('http://127.0.0.1:7244/ingest/0a9f7972-5d03-4255-b5c9-6164f846fb46',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'debug-check-prisma.ts:60',message:'Attempting dynamic import of PrismaClient',data:{},sessionId:'debug-session',runId:'run1',hypothesisId:'D'})}).catch(()=>{});
73
- // #endregion
74
- const prismaModule = require('@prisma/client');
75
- // #region agent log
76
- fetch('http://127.0.0.1:7244/ingest/0a9f7972-5d03-4255-b5c9-6164f846fb46',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'debug-check-prisma.ts:63',message:'Module loaded',data:{hasPrismaClient:!!prismaModule.PrismaClient,exports:Object.keys(prismaModule)},sessionId:'debug-session',runId:'run1',hypothesisId:'D'})}).catch(()=>{});
77
- // #endregion
78
- if (prismaModule.PrismaClient) {
79
- prismaClientImportSuccess = true;
80
- } else {
81
- prismaClientImportError = 'PrismaClient not found in exports: ' + Object.keys(prismaModule).join(', ');
82
- }
83
- } catch (e) {
84
- prismaClientImportError = String(e);
85
- // #region agent log
86
- fetch('http://127.0.0.1:7244/ingest/0a9f7972-5d03-4255-b5c9-6164f846fb46',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'debug-check-prisma.ts:72',message:'Dynamic import failed',data:{error:prismaClientImportError},sessionId:'debug-session',runId:'run1',hypothesisId:'D'})}).catch(()=>{});
87
- // #endregion
88
- }
89
-
90
- // #region agent log
91
- fetch('http://127.0.0.1:7244/ingest/0a9f7972-5d03-4255-b5c9-6164f846fb46',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'debug-check-prisma.ts:76',message:'Final summary',data:{prismaClientExists,prismaGeneratedExists,prismaClientImportSuccess,prismaClientImportError,hasPackageJson:!!prismaClientPackageJson,hasIndexDts:!!indexDtsContent},sessionId:'debug-session',runId:'run1',hypothesisId:'ALL'})}).catch(()=>{});
92
- // #endregion
93
-
94
- console.log('Prisma Client Check Complete');
95
- console.log('Prisma Client Package Exists:', prismaClientExists);
96
- console.log('Prisma Generated Client Exists:', prismaGeneratedExists);
97
- console.log('PrismaClient Import Success:', prismaClientImportSuccess);
98
- if (prismaClientImportError) {
99
- console.log('PrismaClient Import Error:', prismaClientImportError);
100
- }