av6-core 1.7.9 → 1.7.11
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/.prettierignore +4 -4
- package/.prettierrc +6 -6
- package/README.md +234 -234
- package/dist/index.d.mts +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +64 -42
- package/dist/index.mjs +61 -42
- package/package.json +38 -38
package/.prettierignore
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
node_modules
|
|
2
|
-
build
|
|
3
|
-
dist
|
|
4
|
-
.vscode
|
|
1
|
+
node_modules
|
|
2
|
+
build
|
|
3
|
+
dist
|
|
4
|
+
.vscode
|
package/.prettierrc
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
{
|
|
2
|
-
"semi": true,
|
|
3
|
-
"singleQuote": false,
|
|
4
|
-
"trailingComma": "es5",
|
|
5
|
-
"printWidth": 120
|
|
6
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"semi": true,
|
|
3
|
+
"singleQuote": false,
|
|
4
|
+
"trailingComma": "es5",
|
|
5
|
+
"printWidth": 120
|
|
6
|
+
}
|
package/README.md
CHANGED
|
@@ -1,234 +1,234 @@
|
|
|
1
|
-
# AV6 Core
|
|
2
|
-
|
|
3
|
-
A comprehensive utility library for AV6 Node.js projects, providing common functionality for data operations, caching, and Excel handling.
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- **Dynamic Data Operations**: Flexible search, fetch, and CRUD operations with support for dynamic models
|
|
8
|
-
- **Caching Support**: Built-in Redis caching for improved performance
|
|
9
|
-
- **Excel Import/Export**: Seamless Excel file handling for data import and export
|
|
10
|
-
- **Pagination**: Built-in pagination for search results
|
|
11
|
-
- **DTO Mapping**: Support for Data Transfer Object mapping
|
|
12
|
-
- **Type Safety**: Written in TypeScript with comprehensive type definitions
|
|
13
|
-
- **UIN Config Management**: Unique Identification Number generation with configurable segments and automatic reset policies
|
|
14
|
-
|
|
15
|
-
## Installation
|
|
16
|
-
|
|
17
|
-
```bash
|
|
18
|
-
npm install av6-core
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## Usage
|
|
22
|
-
|
|
23
|
-
### Basic Setup
|
|
24
|
-
|
|
25
|
-
To use the library, you need to provide the necessary dependencies:
|
|
26
|
-
|
|
27
|
-
```typescript
|
|
28
|
-
import { commonService, Deps } from 'av6-core';
|
|
29
|
-
import { PrismaClient } from '@prisma/client';
|
|
30
|
-
import winston from 'winston';
|
|
31
|
-
import { AsyncLocalStorage } from 'async_hooks';
|
|
32
|
-
|
|
33
|
-
// Initialize dependencies
|
|
34
|
-
const deps: Deps = {
|
|
35
|
-
config: {
|
|
36
|
-
REDIS_PREFIX: 'your-prefix:',
|
|
37
|
-
CACHE_KEY_NAME: 'your-cache-key'
|
|
38
|
-
},
|
|
39
|
-
mapper: {
|
|
40
|
-
dtoMapping: {}, // Your DTO mapping functions
|
|
41
|
-
mappingExport: {}, // Your export mapping functions
|
|
42
|
-
mappingImport: {}, // Your import mapping functions
|
|
43
|
-
},
|
|
44
|
-
helpers: {
|
|
45
|
-
generateErrorMessage: (type, ...variables) => {
|
|
46
|
-
// Your error message generation logic
|
|
47
|
-
},
|
|
48
|
-
ErrorHandler: class ErrorHandler extends Error {
|
|
49
|
-
// Your error handler implementation
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
|
-
logger: winston.createLogger({
|
|
53
|
-
// Your logger configuration
|
|
54
|
-
}),
|
|
55
|
-
cacheAdapter: {
|
|
56
|
-
// Your cache adapter implementation
|
|
57
|
-
},
|
|
58
|
-
requestStorage: new AsyncLocalStorage(),
|
|
59
|
-
db: new PrismaClient()
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
// Initialize the service
|
|
63
|
-
const service = commonService(deps);
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
### Search Operations
|
|
67
|
-
|
|
68
|
-
```typescript
|
|
69
|
-
// Perform a search operation
|
|
70
|
-
const searchResult = await service.search({
|
|
71
|
-
pageNo: 1,
|
|
72
|
-
pageSize: 10,
|
|
73
|
-
shortCode: 'USER',
|
|
74
|
-
searchColumns: ['name', 'email'],
|
|
75
|
-
searchText: 'john',
|
|
76
|
-
sortBy: 'createdAt',
|
|
77
|
-
sortDir: 'DESC',
|
|
78
|
-
shortCodeData: {
|
|
79
|
-
shortCode: 'USER',
|
|
80
|
-
tableName: 'user',
|
|
81
|
-
isDTO: true,
|
|
82
|
-
isCacheable: true
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
### Fetch Record
|
|
88
|
-
|
|
89
|
-
```typescript
|
|
90
|
-
// Fetch a specific record
|
|
91
|
-
const record = await service.fetch({
|
|
92
|
-
shortCode: 'USER',
|
|
93
|
-
id: 123,
|
|
94
|
-
shortCodeData: {
|
|
95
|
-
shortCode: 'USER',
|
|
96
|
-
tableName: 'user',
|
|
97
|
-
isDTO: true,
|
|
98
|
-
isCacheable: true
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
### Excel Operations
|
|
104
|
-
|
|
105
|
-
```typescript
|
|
106
|
-
// Import data from Excel
|
|
107
|
-
const importResult = await service.commonExcelImport({
|
|
108
|
-
shortCode: 'USER',
|
|
109
|
-
file: excelFile, // File object from upload
|
|
110
|
-
shortCodeData: {
|
|
111
|
-
shortCode: 'USER',
|
|
112
|
-
tableName: 'user'
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
// Export data to Excel
|
|
117
|
-
const workbook = await service.commonExcelExport({
|
|
118
|
-
shortCode: 'USER',
|
|
119
|
-
isSample: false,
|
|
120
|
-
shortCodeData: {
|
|
121
|
-
shortCode: 'USER',
|
|
122
|
-
tableName: 'user'
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
### UIN Config Operations
|
|
128
|
-
|
|
129
|
-
```typescript
|
|
130
|
-
import { uinConfigService, UinDeps, UIN_RESET_POLICY, UinShortCode } from 'av6-core';
|
|
131
|
-
|
|
132
|
-
// Initialize UIN Config dependencies
|
|
133
|
-
const uinDeps: UinDeps = {
|
|
134
|
-
config: {
|
|
135
|
-
REDIS_PREFIX: 'your-prefix:',
|
|
136
|
-
CACHE_KEY_NAME: 'your-cache-key'
|
|
137
|
-
},
|
|
138
|
-
helpers: {
|
|
139
|
-
generateErrorMessage: (type, ...variables) => {
|
|
140
|
-
// Your error message generation logic
|
|
141
|
-
},
|
|
142
|
-
ErrorHandler: class ErrorHandler extends Error {
|
|
143
|
-
// Your error handler implementation
|
|
144
|
-
}
|
|
145
|
-
},
|
|
146
|
-
logger: winston.createLogger({
|
|
147
|
-
// Your logger configuration
|
|
148
|
-
}),
|
|
149
|
-
cacheAdapter: {
|
|
150
|
-
// Your cache adapter implementation
|
|
151
|
-
},
|
|
152
|
-
requestStorage: new AsyncLocalStorage(),
|
|
153
|
-
db: new PrismaClient(),
|
|
154
|
-
prisma: PrismaNamespace,
|
|
155
|
-
shortCode: 'UIN_CONFIG',
|
|
156
|
-
cacheKey: 'uin-config'
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
// Initialize the UIN Config service
|
|
160
|
-
const uinService = uinConfigService(uinDeps);
|
|
161
|
-
|
|
162
|
-
// Create a new UIN Config
|
|
163
|
-
const newUinConfig = await uinService.createUINConfig({
|
|
164
|
-
shortCode: UinShortCode.INVOICE,
|
|
165
|
-
seqResetPolicy: UIN_RESET_POLICY.monthly,
|
|
166
|
-
description: 'Invoice number generator',
|
|
167
|
-
uinSegments: [
|
|
168
|
-
{ order: 1, type: 'text', value: 'INV-' },
|
|
169
|
-
{ order: 2, type: 'dateFormat', value: 'YYYYMM' },
|
|
170
|
-
{ order: 3, type: 'separator', value: '-' },
|
|
171
|
-
{ order: 4, type: 'sequenceNo', minSeqLength: 5 }
|
|
172
|
-
]
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
// Generate a UIN preview
|
|
176
|
-
const uinPreview = await uinService.previewUIN({
|
|
177
|
-
uinSegments: [
|
|
178
|
-
{ order: 1, type: 'text', value: 'INV-' },
|
|
179
|
-
{ order: 2, type: 'dateFormat', value: 'YYYYMM' },
|
|
180
|
-
{ order: 3, type: 'separator', value: '-' },
|
|
181
|
-
{ order: 4, type: 'sequenceNo', minSeqLength: 5 }
|
|
182
|
-
]
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
// Get a UIN Config by ID
|
|
186
|
-
const uinConfig = await uinService.getUINConfigById(1);
|
|
187
|
-
|
|
188
|
-
// Generate a new UIN
|
|
189
|
-
const generatedUin = await uinService.generateUIN(UinShortCode.INVOICE);
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
## API Reference
|
|
193
|
-
|
|
194
|
-
### Common Service
|
|
195
|
-
|
|
196
|
-
The library provides a comprehensive service for common operations:
|
|
197
|
-
|
|
198
|
-
- `search`: Search records with pagination and filtering
|
|
199
|
-
- `dropdownSearch`: Search records for dropdown components
|
|
200
|
-
- `fixedSearch`: Search with fixed criteria
|
|
201
|
-
- `fixedSearchWoPaginationService`: Search with fixed criteria without pagination
|
|
202
|
-
- `commonExcelService`: Generate Excel workbooks
|
|
203
|
-
- `fetch`: Fetch a specific record by ID
|
|
204
|
-
- `commonExcelImport`: Import data from Excel files
|
|
205
|
-
- `commonExcelExport`: Export data to Excel files
|
|
206
|
-
- `delete`: Delete a record
|
|
207
|
-
- `updateStatus`: Update the status of a record
|
|
208
|
-
- `fetchImageStream`: Fetch an image as a stream
|
|
209
|
-
|
|
210
|
-
### UIN Config Service
|
|
211
|
-
|
|
212
|
-
The library provides a service for managing Unique Identification Numbers:
|
|
213
|
-
|
|
214
|
-
- `createUINConfig`: Create a new UIN configuration
|
|
215
|
-
- `updateUINConfig`: Update an existing UIN configuration
|
|
216
|
-
- `getUINConfigById`: Retrieve a UIN configuration by ID
|
|
217
|
-
- `getAllUINConfig`: Retrieve all UIN configurations
|
|
218
|
-
- `deleteUINConfig`: Delete a UIN configuration
|
|
219
|
-
- `generateUIN`: Generate a new UIN based on a shortcode
|
|
220
|
-
- `previewUIN`: Preview a UIN based on segment configuration
|
|
221
|
-
|
|
222
|
-
### Utility Functions
|
|
223
|
-
|
|
224
|
-
The library also provides utility functions:
|
|
225
|
-
|
|
226
|
-
- `customOmit`: Omit specific keys from an object
|
|
227
|
-
- `objectTo2DArray`: Convert an object to a 2D array
|
|
228
|
-
- `toRelativeImageUrl`: Convert an absolute path to a relative image URL
|
|
229
|
-
|
|
230
|
-
## License
|
|
231
|
-
|
|
232
|
-
ISC
|
|
233
|
-
|
|
234
|
-
|
|
1
|
+
# AV6 Core
|
|
2
|
+
|
|
3
|
+
A comprehensive utility library for AV6 Node.js projects, providing common functionality for data operations, caching, and Excel handling.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Dynamic Data Operations**: Flexible search, fetch, and CRUD operations with support for dynamic models
|
|
8
|
+
- **Caching Support**: Built-in Redis caching for improved performance
|
|
9
|
+
- **Excel Import/Export**: Seamless Excel file handling for data import and export
|
|
10
|
+
- **Pagination**: Built-in pagination for search results
|
|
11
|
+
- **DTO Mapping**: Support for Data Transfer Object mapping
|
|
12
|
+
- **Type Safety**: Written in TypeScript with comprehensive type definitions
|
|
13
|
+
- **UIN Config Management**: Unique Identification Number generation with configurable segments and automatic reset policies
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install av6-core
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
### Basic Setup
|
|
24
|
+
|
|
25
|
+
To use the library, you need to provide the necessary dependencies:
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { commonService, Deps } from 'av6-core';
|
|
29
|
+
import { PrismaClient } from '@prisma/client';
|
|
30
|
+
import winston from 'winston';
|
|
31
|
+
import { AsyncLocalStorage } from 'async_hooks';
|
|
32
|
+
|
|
33
|
+
// Initialize dependencies
|
|
34
|
+
const deps: Deps = {
|
|
35
|
+
config: {
|
|
36
|
+
REDIS_PREFIX: 'your-prefix:',
|
|
37
|
+
CACHE_KEY_NAME: 'your-cache-key'
|
|
38
|
+
},
|
|
39
|
+
mapper: {
|
|
40
|
+
dtoMapping: {}, // Your DTO mapping functions
|
|
41
|
+
mappingExport: {}, // Your export mapping functions
|
|
42
|
+
mappingImport: {}, // Your import mapping functions
|
|
43
|
+
},
|
|
44
|
+
helpers: {
|
|
45
|
+
generateErrorMessage: (type, ...variables) => {
|
|
46
|
+
// Your error message generation logic
|
|
47
|
+
},
|
|
48
|
+
ErrorHandler: class ErrorHandler extends Error {
|
|
49
|
+
// Your error handler implementation
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
logger: winston.createLogger({
|
|
53
|
+
// Your logger configuration
|
|
54
|
+
}),
|
|
55
|
+
cacheAdapter: {
|
|
56
|
+
// Your cache adapter implementation
|
|
57
|
+
},
|
|
58
|
+
requestStorage: new AsyncLocalStorage(),
|
|
59
|
+
db: new PrismaClient()
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// Initialize the service
|
|
63
|
+
const service = commonService(deps);
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Search Operations
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
// Perform a search operation
|
|
70
|
+
const searchResult = await service.search({
|
|
71
|
+
pageNo: 1,
|
|
72
|
+
pageSize: 10,
|
|
73
|
+
shortCode: 'USER',
|
|
74
|
+
searchColumns: ['name', 'email'],
|
|
75
|
+
searchText: 'john',
|
|
76
|
+
sortBy: 'createdAt',
|
|
77
|
+
sortDir: 'DESC',
|
|
78
|
+
shortCodeData: {
|
|
79
|
+
shortCode: 'USER',
|
|
80
|
+
tableName: 'user',
|
|
81
|
+
isDTO: true,
|
|
82
|
+
isCacheable: true
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Fetch Record
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
// Fetch a specific record
|
|
91
|
+
const record = await service.fetch({
|
|
92
|
+
shortCode: 'USER',
|
|
93
|
+
id: 123,
|
|
94
|
+
shortCodeData: {
|
|
95
|
+
shortCode: 'USER',
|
|
96
|
+
tableName: 'user',
|
|
97
|
+
isDTO: true,
|
|
98
|
+
isCacheable: true
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Excel Operations
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
// Import data from Excel
|
|
107
|
+
const importResult = await service.commonExcelImport({
|
|
108
|
+
shortCode: 'USER',
|
|
109
|
+
file: excelFile, // File object from upload
|
|
110
|
+
shortCodeData: {
|
|
111
|
+
shortCode: 'USER',
|
|
112
|
+
tableName: 'user'
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// Export data to Excel
|
|
117
|
+
const workbook = await service.commonExcelExport({
|
|
118
|
+
shortCode: 'USER',
|
|
119
|
+
isSample: false,
|
|
120
|
+
shortCodeData: {
|
|
121
|
+
shortCode: 'USER',
|
|
122
|
+
tableName: 'user'
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### UIN Config Operations
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
import { uinConfigService, UinDeps, UIN_RESET_POLICY, UinShortCode } from 'av6-core';
|
|
131
|
+
|
|
132
|
+
// Initialize UIN Config dependencies
|
|
133
|
+
const uinDeps: UinDeps = {
|
|
134
|
+
config: {
|
|
135
|
+
REDIS_PREFIX: 'your-prefix:',
|
|
136
|
+
CACHE_KEY_NAME: 'your-cache-key'
|
|
137
|
+
},
|
|
138
|
+
helpers: {
|
|
139
|
+
generateErrorMessage: (type, ...variables) => {
|
|
140
|
+
// Your error message generation logic
|
|
141
|
+
},
|
|
142
|
+
ErrorHandler: class ErrorHandler extends Error {
|
|
143
|
+
// Your error handler implementation
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
logger: winston.createLogger({
|
|
147
|
+
// Your logger configuration
|
|
148
|
+
}),
|
|
149
|
+
cacheAdapter: {
|
|
150
|
+
// Your cache adapter implementation
|
|
151
|
+
},
|
|
152
|
+
requestStorage: new AsyncLocalStorage(),
|
|
153
|
+
db: new PrismaClient(),
|
|
154
|
+
prisma: PrismaNamespace,
|
|
155
|
+
shortCode: 'UIN_CONFIG',
|
|
156
|
+
cacheKey: 'uin-config'
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
// Initialize the UIN Config service
|
|
160
|
+
const uinService = uinConfigService(uinDeps);
|
|
161
|
+
|
|
162
|
+
// Create a new UIN Config
|
|
163
|
+
const newUinConfig = await uinService.createUINConfig({
|
|
164
|
+
shortCode: UinShortCode.INVOICE,
|
|
165
|
+
seqResetPolicy: UIN_RESET_POLICY.monthly,
|
|
166
|
+
description: 'Invoice number generator',
|
|
167
|
+
uinSegments: [
|
|
168
|
+
{ order: 1, type: 'text', value: 'INV-' },
|
|
169
|
+
{ order: 2, type: 'dateFormat', value: 'YYYYMM' },
|
|
170
|
+
{ order: 3, type: 'separator', value: '-' },
|
|
171
|
+
{ order: 4, type: 'sequenceNo', minSeqLength: 5 }
|
|
172
|
+
]
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
// Generate a UIN preview
|
|
176
|
+
const uinPreview = await uinService.previewUIN({
|
|
177
|
+
uinSegments: [
|
|
178
|
+
{ order: 1, type: 'text', value: 'INV-' },
|
|
179
|
+
{ order: 2, type: 'dateFormat', value: 'YYYYMM' },
|
|
180
|
+
{ order: 3, type: 'separator', value: '-' },
|
|
181
|
+
{ order: 4, type: 'sequenceNo', minSeqLength: 5 }
|
|
182
|
+
]
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
// Get a UIN Config by ID
|
|
186
|
+
const uinConfig = await uinService.getUINConfigById(1);
|
|
187
|
+
|
|
188
|
+
// Generate a new UIN
|
|
189
|
+
const generatedUin = await uinService.generateUIN(UinShortCode.INVOICE);
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## API Reference
|
|
193
|
+
|
|
194
|
+
### Common Service
|
|
195
|
+
|
|
196
|
+
The library provides a comprehensive service for common operations:
|
|
197
|
+
|
|
198
|
+
- `search`: Search records with pagination and filtering
|
|
199
|
+
- `dropdownSearch`: Search records for dropdown components
|
|
200
|
+
- `fixedSearch`: Search with fixed criteria
|
|
201
|
+
- `fixedSearchWoPaginationService`: Search with fixed criteria without pagination
|
|
202
|
+
- `commonExcelService`: Generate Excel workbooks
|
|
203
|
+
- `fetch`: Fetch a specific record by ID
|
|
204
|
+
- `commonExcelImport`: Import data from Excel files
|
|
205
|
+
- `commonExcelExport`: Export data to Excel files
|
|
206
|
+
- `delete`: Delete a record
|
|
207
|
+
- `updateStatus`: Update the status of a record
|
|
208
|
+
- `fetchImageStream`: Fetch an image as a stream
|
|
209
|
+
|
|
210
|
+
### UIN Config Service
|
|
211
|
+
|
|
212
|
+
The library provides a service for managing Unique Identification Numbers:
|
|
213
|
+
|
|
214
|
+
- `createUINConfig`: Create a new UIN configuration
|
|
215
|
+
- `updateUINConfig`: Update an existing UIN configuration
|
|
216
|
+
- `getUINConfigById`: Retrieve a UIN configuration by ID
|
|
217
|
+
- `getAllUINConfig`: Retrieve all UIN configurations
|
|
218
|
+
- `deleteUINConfig`: Delete a UIN configuration
|
|
219
|
+
- `generateUIN`: Generate a new UIN based on a shortcode
|
|
220
|
+
- `previewUIN`: Preview a UIN based on segment configuration
|
|
221
|
+
|
|
222
|
+
### Utility Functions
|
|
223
|
+
|
|
224
|
+
The library also provides utility functions:
|
|
225
|
+
|
|
226
|
+
- `customOmit`: Omit specific keys from an object
|
|
227
|
+
- `objectTo2DArray`: Convert an object to a 2D array
|
|
228
|
+
- `toRelativeImageUrl`: Convert an absolute path to a relative image URL
|
|
229
|
+
|
|
230
|
+
## License
|
|
231
|
+
|
|
232
|
+
ISC
|
|
233
|
+
|
|
234
|
+
|
package/dist/index.d.mts
CHANGED
|
@@ -554,6 +554,16 @@ interface CreateTransaction {
|
|
|
554
554
|
*/
|
|
555
555
|
declare function findDifferences<T extends Record<string, any>>(obj1: T, obj2: T): CreateTransaction[];
|
|
556
556
|
|
|
557
|
+
declare function renderTemplate(tpl: string, data: any): string;
|
|
558
|
+
declare function renderEmailTemplate(tpl: {
|
|
559
|
+
subject?: string;
|
|
560
|
+
body: string;
|
|
561
|
+
}, data: any): {
|
|
562
|
+
subject: string | undefined;
|
|
563
|
+
body: string;
|
|
564
|
+
};
|
|
565
|
+
declare const convertArrayPatternToEachBlocksGeneric: (html?: string) => string;
|
|
566
|
+
|
|
557
567
|
interface ServiceCacheAdapter extends CacheAdapter {
|
|
558
568
|
addToCache(key: string, id: number | string, data: unknown): Promise<void>;
|
|
559
569
|
checkIsCacheable(shortCode: string): Promise<boolean>;
|
|
@@ -567,6 +577,7 @@ interface UinDeps {
|
|
|
567
577
|
requestStorage: AsyncLocalStorage<Store>;
|
|
568
578
|
db: PrismaClient;
|
|
569
579
|
prisma: typeof PrismaNamespace;
|
|
580
|
+
modelName?: string;
|
|
570
581
|
}
|
|
571
582
|
type UINSegmentType = "text" | "separator" | "dateFormat" | "sequenceNo";
|
|
572
583
|
type UIN_RESET_POLICY = "daily" | "weekly" | "monthly" | "yearly" | "no";
|
|
@@ -702,4 +713,4 @@ declare class AuditProxy<Module extends string = "OPD" | "PROCEDURE" | "GENERAL_
|
|
|
702
713
|
createAuditedService<T extends object>(serviceName: string, service: T): T;
|
|
703
714
|
}
|
|
704
715
|
|
|
705
|
-
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, formatDatesDeep, fromTimestampToSqlDatetime, getDynamicValue, getNestedValue, getNestedValueV2, getPattern, interpolate, objectTo2DArray, toNumberOrNull, toUINConfigDTO, uinConfigService, type updateStatusParams };
|
|
716
|
+
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, convertArrayPatternToEachBlocksGeneric, customOmit, findDifferences, formatDatesDeep, fromTimestampToSqlDatetime, getDynamicValue, getNestedValue, getNestedValueV2, getPattern, interpolate, objectTo2DArray, renderEmailTemplate, renderTemplate, toNumberOrNull, toUINConfigDTO, uinConfigService, type updateStatusParams };
|
package/dist/index.d.ts
CHANGED
|
@@ -554,6 +554,16 @@ interface CreateTransaction {
|
|
|
554
554
|
*/
|
|
555
555
|
declare function findDifferences<T extends Record<string, any>>(obj1: T, obj2: T): CreateTransaction[];
|
|
556
556
|
|
|
557
|
+
declare function renderTemplate(tpl: string, data: any): string;
|
|
558
|
+
declare function renderEmailTemplate(tpl: {
|
|
559
|
+
subject?: string;
|
|
560
|
+
body: string;
|
|
561
|
+
}, data: any): {
|
|
562
|
+
subject: string | undefined;
|
|
563
|
+
body: string;
|
|
564
|
+
};
|
|
565
|
+
declare const convertArrayPatternToEachBlocksGeneric: (html?: string) => string;
|
|
566
|
+
|
|
557
567
|
interface ServiceCacheAdapter extends CacheAdapter {
|
|
558
568
|
addToCache(key: string, id: number | string, data: unknown): Promise<void>;
|
|
559
569
|
checkIsCacheable(shortCode: string): Promise<boolean>;
|
|
@@ -567,6 +577,7 @@ interface UinDeps {
|
|
|
567
577
|
requestStorage: AsyncLocalStorage<Store>;
|
|
568
578
|
db: PrismaClient;
|
|
569
579
|
prisma: typeof PrismaNamespace;
|
|
580
|
+
modelName?: string;
|
|
570
581
|
}
|
|
571
582
|
type UINSegmentType = "text" | "separator" | "dateFormat" | "sequenceNo";
|
|
572
583
|
type UIN_RESET_POLICY = "daily" | "weekly" | "monthly" | "yearly" | "no";
|
|
@@ -702,4 +713,4 @@ declare class AuditProxy<Module extends string = "OPD" | "PROCEDURE" | "GENERAL_
|
|
|
702
713
|
createAuditedService<T extends object>(serviceName: string, service: T): T;
|
|
703
714
|
}
|
|
704
715
|
|
|
705
|
-
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, formatDatesDeep, fromTimestampToSqlDatetime, getDynamicValue, getNestedValue, getNestedValueV2, getPattern, interpolate, objectTo2DArray, toNumberOrNull, toUINConfigDTO, uinConfigService, type updateStatusParams };
|
|
716
|
+
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, convertArrayPatternToEachBlocksGeneric, customOmit, findDifferences, formatDatesDeep, fromTimestampToSqlDatetime, getDynamicValue, getNestedValue, getNestedValueV2, getPattern, interpolate, objectTo2DArray, renderEmailTemplate, renderTemplate, toNumberOrNull, toUINConfigDTO, uinConfigService, type updateStatusParams };
|
package/dist/index.js
CHANGED
|
@@ -35,6 +35,7 @@ __export(index_exports, {
|
|
|
35
35
|
AuditProxy: () => AuditProxy,
|
|
36
36
|
NotificationEmitter: () => NotificationEmitter,
|
|
37
37
|
commonService: () => commonService,
|
|
38
|
+
convertArrayPatternToEachBlocksGeneric: () => convertArrayPatternToEachBlocksGeneric,
|
|
38
39
|
customOmit: () => customOmit,
|
|
39
40
|
findDifferences: () => findDifferences,
|
|
40
41
|
formatDatesDeep: () => formatDatesDeep,
|
|
@@ -45,6 +46,8 @@ __export(index_exports, {
|
|
|
45
46
|
getPattern: () => getPattern,
|
|
46
47
|
interpolate: () => interpolate,
|
|
47
48
|
objectTo2DArray: () => objectTo2DArray,
|
|
49
|
+
renderEmailTemplate: () => renderEmailTemplate,
|
|
50
|
+
renderTemplate: () => renderTemplate,
|
|
48
51
|
toNumberOrNull: () => toNumberOrNull,
|
|
49
52
|
toUINConfigDTO: () => toUINConfigDTO,
|
|
50
53
|
uinConfigService: () => uinConfigService
|
|
@@ -2344,6 +2347,40 @@ function findDifferences(obj1, obj2) {
|
|
|
2344
2347
|
return differences;
|
|
2345
2348
|
}
|
|
2346
2349
|
|
|
2350
|
+
// src/utils/renderer.ts
|
|
2351
|
+
var import_handlebars = __toESM(require("handlebars"));
|
|
2352
|
+
function renderTemplate(tpl, data) {
|
|
2353
|
+
return import_handlebars.default.compile(tpl)(data);
|
|
2354
|
+
}
|
|
2355
|
+
function renderEmailTemplate(tpl, data) {
|
|
2356
|
+
return {
|
|
2357
|
+
subject: tpl.subject ? import_handlebars.default.compile(tpl.subject)(data) : void 0,
|
|
2358
|
+
body: import_handlebars.default.compile(convertArrayPatternToEachBlocksGeneric(tpl.body))(data)
|
|
2359
|
+
};
|
|
2360
|
+
}
|
|
2361
|
+
var convertArrayPatternToEachBlocksGeneric = (html) => {
|
|
2362
|
+
if (!html) return "";
|
|
2363
|
+
const blockTags = ["tr", "div", "li", "section", "tbody"];
|
|
2364
|
+
let output = html;
|
|
2365
|
+
blockTags.forEach((tag) => {
|
|
2366
|
+
const regex = new RegExp(`<${tag}\\b[^>]*>[\\s\\S]*?<\\/${tag}>`, "g");
|
|
2367
|
+
output = output.replace(regex, (blockHtml) => {
|
|
2368
|
+
const matches = [...blockHtml.matchAll(/{{\s*([a-zA-Z0-9_.-]+)\[\]\.([a-zA-Z0-9_.-]+)\s*}}/g)];
|
|
2369
|
+
if (!matches.length) return blockHtml;
|
|
2370
|
+
const uniqueArrays = Array.from(new Set(matches.map((m) => m[1])));
|
|
2371
|
+
if (uniqueArrays.length !== 1) return blockHtml;
|
|
2372
|
+
const arrayName = uniqueArrays[0];
|
|
2373
|
+
const escapedArray = arrayName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2374
|
+
const cleanedBlock = blockHtml.replace(
|
|
2375
|
+
new RegExp(`{{\\s*${escapedArray}\\[\\]\\.([a-zA-Z0-9_.-]+)\\s*}}`, "g"),
|
|
2376
|
+
"{{$1}}"
|
|
2377
|
+
);
|
|
2378
|
+
return `{{#each ${arrayName}}}${cleanedBlock}{{/each}}`;
|
|
2379
|
+
});
|
|
2380
|
+
});
|
|
2381
|
+
return output;
|
|
2382
|
+
};
|
|
2383
|
+
|
|
2347
2384
|
// src/mapper/uinConfig.mapper.ts
|
|
2348
2385
|
var toUINConfigDTO = (model) => {
|
|
2349
2386
|
return {
|
|
@@ -2366,12 +2403,13 @@ var uinConfigRepository = (uinDeps) => {
|
|
|
2366
2403
|
const db = uinDeps.db;
|
|
2367
2404
|
const logger = uinDeps.logger;
|
|
2368
2405
|
const requestStorage = uinDeps.requestStorage;
|
|
2406
|
+
const modelName = uinDeps.modelName || "uINConfig";
|
|
2369
2407
|
return {
|
|
2370
2408
|
async createUINConfigInDb(uinReq) {
|
|
2371
2409
|
logger.info("entering::createUINConfigInDb::repository");
|
|
2372
2410
|
const storage = requestStorage.getStore();
|
|
2373
2411
|
const { uinSegments, ...uinData } = uinReq;
|
|
2374
|
-
return db.
|
|
2412
|
+
return db[modelName].create({
|
|
2375
2413
|
data: {
|
|
2376
2414
|
...uinData,
|
|
2377
2415
|
uinSegments: JSON.stringify(uinSegments),
|
|
@@ -2383,7 +2421,7 @@ var uinConfigRepository = (uinDeps) => {
|
|
|
2383
2421
|
async updateUINConfigInDb(updatedConfig, prevConfig) {
|
|
2384
2422
|
logger.info("entering::updateUINConfig::repository");
|
|
2385
2423
|
const storage = requestStorage.getStore();
|
|
2386
|
-
const updated = await db.
|
|
2424
|
+
const updated = await db[modelName].update({
|
|
2387
2425
|
where: { id: updatedConfig.id },
|
|
2388
2426
|
data: {
|
|
2389
2427
|
shortCode: updatedConfig.shortCode,
|
|
@@ -2399,32 +2437,32 @@ var uinConfigRepository = (uinDeps) => {
|
|
|
2399
2437
|
},
|
|
2400
2438
|
async getUINConfigByIdFromDb(id) {
|
|
2401
2439
|
logger.info("entering::getUINConfigByIdFromDb::repository");
|
|
2402
|
-
return db.
|
|
2440
|
+
return db[modelName].findUnique({
|
|
2403
2441
|
where: { id, isActive: true }
|
|
2404
2442
|
});
|
|
2405
2443
|
},
|
|
2406
2444
|
async getUINConfigByShortCodeFromDb(shortCode) {
|
|
2407
2445
|
logger.info("entering::getUINConfigByShortCodeFromDb::repository");
|
|
2408
|
-
return db.
|
|
2446
|
+
return db[modelName].findFirst({
|
|
2409
2447
|
where: { shortCode, isActive: true }
|
|
2410
2448
|
});
|
|
2411
2449
|
},
|
|
2412
2450
|
async getAllUINConfigFromDb() {
|
|
2413
2451
|
logger.info("entering::getAllUINConfigFromDb::repository");
|
|
2414
|
-
return db.
|
|
2452
|
+
return db[modelName].findMany({
|
|
2415
2453
|
where: { isActive: true }
|
|
2416
2454
|
});
|
|
2417
2455
|
},
|
|
2418
2456
|
async updateSequenceNo(shortCode, next) {
|
|
2419
2457
|
logger.info("entering::updateSequenceNo::repository");
|
|
2420
|
-
await db.
|
|
2458
|
+
await db[modelName].updateMany({
|
|
2421
2459
|
where: { shortCode, isActive: true },
|
|
2422
2460
|
data: { sequenceNo: next }
|
|
2423
2461
|
});
|
|
2424
2462
|
},
|
|
2425
2463
|
async updateSequenceNoAndResetDate(shortCode, next, resetDate) {
|
|
2426
2464
|
logger.info("entering::updateSequenceNoAndResetDate::repository");
|
|
2427
|
-
await db.
|
|
2465
|
+
await db[modelName].updateMany({
|
|
2428
2466
|
where: { shortCode, isActive: true },
|
|
2429
2467
|
data: { sequenceNo: next, seqResetDate: resetDate }
|
|
2430
2468
|
});
|
|
@@ -2432,7 +2470,7 @@ var uinConfigRepository = (uinDeps) => {
|
|
|
2432
2470
|
async deleteUINConfigById(id) {
|
|
2433
2471
|
logger.info("entering::deleteUINConfigById::repository");
|
|
2434
2472
|
const storage = requestStorage.getStore();
|
|
2435
|
-
await db.
|
|
2473
|
+
await db[modelName].update({
|
|
2436
2474
|
where: { id },
|
|
2437
2475
|
data: {
|
|
2438
2476
|
isActive: false,
|
|
@@ -2653,6 +2691,8 @@ var ExpoAppNotificationProvider = class {
|
|
|
2653
2691
|
this.logger = logger;
|
|
2654
2692
|
this.url = url;
|
|
2655
2693
|
}
|
|
2694
|
+
logger;
|
|
2695
|
+
url;
|
|
2656
2696
|
/**
|
|
2657
2697
|
* Bulk send: one HTTP request with many messages.
|
|
2658
2698
|
*/
|
|
@@ -2702,6 +2742,10 @@ var EmailProvider = class {
|
|
|
2702
2742
|
this.serviceDomain = serviceDomain;
|
|
2703
2743
|
this.EMAIL_USERNAME = EMAIL_USERNAME;
|
|
2704
2744
|
}
|
|
2745
|
+
prisma;
|
|
2746
|
+
logger;
|
|
2747
|
+
serviceDomain;
|
|
2748
|
+
EMAIL_USERNAME;
|
|
2705
2749
|
async send({
|
|
2706
2750
|
body,
|
|
2707
2751
|
recipient,
|
|
@@ -2784,6 +2828,8 @@ var SmsProvider = class {
|
|
|
2784
2828
|
this.sender = args.senderId || "AlmaMedLab";
|
|
2785
2829
|
this.countryCode = (args.countryCode || "+233").trim();
|
|
2786
2830
|
}
|
|
2831
|
+
logger;
|
|
2832
|
+
args;
|
|
2787
2833
|
url;
|
|
2788
2834
|
token;
|
|
2789
2835
|
sender;
|
|
@@ -2922,6 +2968,8 @@ var WebNotificationProvider = class {
|
|
|
2922
2968
|
this.prisma = prisma;
|
|
2923
2969
|
this.logger = logger;
|
|
2924
2970
|
}
|
|
2971
|
+
prisma;
|
|
2972
|
+
logger;
|
|
2925
2973
|
async sendBulk(args) {
|
|
2926
2974
|
const rows = (args.recipients ?? []).map((r) => {
|
|
2927
2975
|
let data = {
|
|
@@ -3315,6 +3363,8 @@ var WhatsAppProvider = class {
|
|
|
3315
3363
|
this.apiUrl = args.apiUrl ?? "";
|
|
3316
3364
|
this.apiKey = args.apiKey;
|
|
3317
3365
|
}
|
|
3366
|
+
args;
|
|
3367
|
+
logger;
|
|
3318
3368
|
apiKey;
|
|
3319
3369
|
apiUrl;
|
|
3320
3370
|
/**
|
|
@@ -3464,40 +3514,6 @@ var WhatsAppProvider = class {
|
|
|
3464
3514
|
}
|
|
3465
3515
|
};
|
|
3466
3516
|
|
|
3467
|
-
// src/utils/renderer.ts
|
|
3468
|
-
var import_handlebars = __toESM(require("handlebars"));
|
|
3469
|
-
function renderTemplate(tpl, data) {
|
|
3470
|
-
return import_handlebars.default.compile(tpl)(data);
|
|
3471
|
-
}
|
|
3472
|
-
function renderEmailTemplate(tpl, data) {
|
|
3473
|
-
return {
|
|
3474
|
-
subject: tpl.subject ? import_handlebars.default.compile(tpl.subject)(data) : void 0,
|
|
3475
|
-
body: import_handlebars.default.compile(convertArrayPatternToEachBlocksGeneric(tpl.body))(data)
|
|
3476
|
-
};
|
|
3477
|
-
}
|
|
3478
|
-
var convertArrayPatternToEachBlocksGeneric = (html) => {
|
|
3479
|
-
if (!html) return "";
|
|
3480
|
-
const blockTags = ["tr", "div", "li", "section", "tbody"];
|
|
3481
|
-
let output = html;
|
|
3482
|
-
blockTags.forEach((tag) => {
|
|
3483
|
-
const regex = new RegExp(`<${tag}\\b[^>]*>[\\s\\S]*?<\\/${tag}>`, "g");
|
|
3484
|
-
output = output.replace(regex, (blockHtml) => {
|
|
3485
|
-
const matches = [...blockHtml.matchAll(/{{\s*([a-zA-Z0-9_.-]+)\[\]\.([a-zA-Z0-9_.-]+)\s*}}/g)];
|
|
3486
|
-
if (!matches.length) return blockHtml;
|
|
3487
|
-
const uniqueArrays = Array.from(new Set(matches.map((m) => m[1])));
|
|
3488
|
-
if (uniqueArrays.length !== 1) return blockHtml;
|
|
3489
|
-
const arrayName = uniqueArrays[0];
|
|
3490
|
-
const escapedArray = arrayName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3491
|
-
const cleanedBlock = blockHtml.replace(
|
|
3492
|
-
new RegExp(`{{\\s*${escapedArray}\\[\\]\\.([a-zA-Z0-9_.-]+)\\s*}}`, "g"),
|
|
3493
|
-
"{{$1}}"
|
|
3494
|
-
);
|
|
3495
|
-
return `{{#each ${arrayName}}}${cleanedBlock}{{/each}}`;
|
|
3496
|
-
});
|
|
3497
|
-
});
|
|
3498
|
-
return output;
|
|
3499
|
-
};
|
|
3500
|
-
|
|
3501
3517
|
// src/services/notification.service.ts
|
|
3502
3518
|
var import_lodash = __toESM(require("lodash.merge"));
|
|
3503
3519
|
var NotificationService = class {
|
|
@@ -3506,6 +3522,9 @@ var NotificationService = class {
|
|
|
3506
3522
|
this.logger = logger;
|
|
3507
3523
|
this.helpers = helpers;
|
|
3508
3524
|
}
|
|
3525
|
+
prisma;
|
|
3526
|
+
logger;
|
|
3527
|
+
helpers;
|
|
3509
3528
|
/**
|
|
3510
3529
|
* Main entry: handle one business event.
|
|
3511
3530
|
* Creates parent EventDelivery and one child EventDeliveryItem per attempt.
|
|
@@ -4269,6 +4288,7 @@ var AuditProxy = class {
|
|
|
4269
4288
|
AuditProxy,
|
|
4270
4289
|
NotificationEmitter,
|
|
4271
4290
|
commonService,
|
|
4291
|
+
convertArrayPatternToEachBlocksGeneric,
|
|
4272
4292
|
customOmit,
|
|
4273
4293
|
findDifferences,
|
|
4274
4294
|
formatDatesDeep,
|
|
@@ -4279,6 +4299,8 @@ var AuditProxy = class {
|
|
|
4279
4299
|
getPattern,
|
|
4280
4300
|
interpolate,
|
|
4281
4301
|
objectTo2DArray,
|
|
4302
|
+
renderEmailTemplate,
|
|
4303
|
+
renderTemplate,
|
|
4282
4304
|
toNumberOrNull,
|
|
4283
4305
|
toUINConfigDTO,
|
|
4284
4306
|
uinConfigService
|
package/dist/index.mjs
CHANGED
|
@@ -2291,6 +2291,40 @@ function findDifferences(obj1, obj2) {
|
|
|
2291
2291
|
return differences;
|
|
2292
2292
|
}
|
|
2293
2293
|
|
|
2294
|
+
// src/utils/renderer.ts
|
|
2295
|
+
import Handlebars from "handlebars";
|
|
2296
|
+
function renderTemplate(tpl, data) {
|
|
2297
|
+
return Handlebars.compile(tpl)(data);
|
|
2298
|
+
}
|
|
2299
|
+
function renderEmailTemplate(tpl, data) {
|
|
2300
|
+
return {
|
|
2301
|
+
subject: tpl.subject ? Handlebars.compile(tpl.subject)(data) : void 0,
|
|
2302
|
+
body: Handlebars.compile(convertArrayPatternToEachBlocksGeneric(tpl.body))(data)
|
|
2303
|
+
};
|
|
2304
|
+
}
|
|
2305
|
+
var convertArrayPatternToEachBlocksGeneric = (html) => {
|
|
2306
|
+
if (!html) return "";
|
|
2307
|
+
const blockTags = ["tr", "div", "li", "section", "tbody"];
|
|
2308
|
+
let output = html;
|
|
2309
|
+
blockTags.forEach((tag) => {
|
|
2310
|
+
const regex = new RegExp(`<${tag}\\b[^>]*>[\\s\\S]*?<\\/${tag}>`, "g");
|
|
2311
|
+
output = output.replace(regex, (blockHtml) => {
|
|
2312
|
+
const matches = [...blockHtml.matchAll(/{{\s*([a-zA-Z0-9_.-]+)\[\]\.([a-zA-Z0-9_.-]+)\s*}}/g)];
|
|
2313
|
+
if (!matches.length) return blockHtml;
|
|
2314
|
+
const uniqueArrays = Array.from(new Set(matches.map((m) => m[1])));
|
|
2315
|
+
if (uniqueArrays.length !== 1) return blockHtml;
|
|
2316
|
+
const arrayName = uniqueArrays[0];
|
|
2317
|
+
const escapedArray = arrayName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2318
|
+
const cleanedBlock = blockHtml.replace(
|
|
2319
|
+
new RegExp(`{{\\s*${escapedArray}\\[\\]\\.([a-zA-Z0-9_.-]+)\\s*}}`, "g"),
|
|
2320
|
+
"{{$1}}"
|
|
2321
|
+
);
|
|
2322
|
+
return `{{#each ${arrayName}}}${cleanedBlock}{{/each}}`;
|
|
2323
|
+
});
|
|
2324
|
+
});
|
|
2325
|
+
return output;
|
|
2326
|
+
};
|
|
2327
|
+
|
|
2294
2328
|
// src/mapper/uinConfig.mapper.ts
|
|
2295
2329
|
var toUINConfigDTO = (model) => {
|
|
2296
2330
|
return {
|
|
@@ -2313,12 +2347,13 @@ var uinConfigRepository = (uinDeps) => {
|
|
|
2313
2347
|
const db = uinDeps.db;
|
|
2314
2348
|
const logger = uinDeps.logger;
|
|
2315
2349
|
const requestStorage = uinDeps.requestStorage;
|
|
2350
|
+
const modelName = uinDeps.modelName || "uINConfig";
|
|
2316
2351
|
return {
|
|
2317
2352
|
async createUINConfigInDb(uinReq) {
|
|
2318
2353
|
logger.info("entering::createUINConfigInDb::repository");
|
|
2319
2354
|
const storage = requestStorage.getStore();
|
|
2320
2355
|
const { uinSegments, ...uinData } = uinReq;
|
|
2321
|
-
return db.
|
|
2356
|
+
return db[modelName].create({
|
|
2322
2357
|
data: {
|
|
2323
2358
|
...uinData,
|
|
2324
2359
|
uinSegments: JSON.stringify(uinSegments),
|
|
@@ -2330,7 +2365,7 @@ var uinConfigRepository = (uinDeps) => {
|
|
|
2330
2365
|
async updateUINConfigInDb(updatedConfig, prevConfig) {
|
|
2331
2366
|
logger.info("entering::updateUINConfig::repository");
|
|
2332
2367
|
const storage = requestStorage.getStore();
|
|
2333
|
-
const updated = await db.
|
|
2368
|
+
const updated = await db[modelName].update({
|
|
2334
2369
|
where: { id: updatedConfig.id },
|
|
2335
2370
|
data: {
|
|
2336
2371
|
shortCode: updatedConfig.shortCode,
|
|
@@ -2346,32 +2381,32 @@ var uinConfigRepository = (uinDeps) => {
|
|
|
2346
2381
|
},
|
|
2347
2382
|
async getUINConfigByIdFromDb(id) {
|
|
2348
2383
|
logger.info("entering::getUINConfigByIdFromDb::repository");
|
|
2349
|
-
return db.
|
|
2384
|
+
return db[modelName].findUnique({
|
|
2350
2385
|
where: { id, isActive: true }
|
|
2351
2386
|
});
|
|
2352
2387
|
},
|
|
2353
2388
|
async getUINConfigByShortCodeFromDb(shortCode) {
|
|
2354
2389
|
logger.info("entering::getUINConfigByShortCodeFromDb::repository");
|
|
2355
|
-
return db.
|
|
2390
|
+
return db[modelName].findFirst({
|
|
2356
2391
|
where: { shortCode, isActive: true }
|
|
2357
2392
|
});
|
|
2358
2393
|
},
|
|
2359
2394
|
async getAllUINConfigFromDb() {
|
|
2360
2395
|
logger.info("entering::getAllUINConfigFromDb::repository");
|
|
2361
|
-
return db.
|
|
2396
|
+
return db[modelName].findMany({
|
|
2362
2397
|
where: { isActive: true }
|
|
2363
2398
|
});
|
|
2364
2399
|
},
|
|
2365
2400
|
async updateSequenceNo(shortCode, next) {
|
|
2366
2401
|
logger.info("entering::updateSequenceNo::repository");
|
|
2367
|
-
await db.
|
|
2402
|
+
await db[modelName].updateMany({
|
|
2368
2403
|
where: { shortCode, isActive: true },
|
|
2369
2404
|
data: { sequenceNo: next }
|
|
2370
2405
|
});
|
|
2371
2406
|
},
|
|
2372
2407
|
async updateSequenceNoAndResetDate(shortCode, next, resetDate) {
|
|
2373
2408
|
logger.info("entering::updateSequenceNoAndResetDate::repository");
|
|
2374
|
-
await db.
|
|
2409
|
+
await db[modelName].updateMany({
|
|
2375
2410
|
where: { shortCode, isActive: true },
|
|
2376
2411
|
data: { sequenceNo: next, seqResetDate: resetDate }
|
|
2377
2412
|
});
|
|
@@ -2379,7 +2414,7 @@ var uinConfigRepository = (uinDeps) => {
|
|
|
2379
2414
|
async deleteUINConfigById(id) {
|
|
2380
2415
|
logger.info("entering::deleteUINConfigById::repository");
|
|
2381
2416
|
const storage = requestStorage.getStore();
|
|
2382
|
-
await db.
|
|
2417
|
+
await db[modelName].update({
|
|
2383
2418
|
where: { id },
|
|
2384
2419
|
data: {
|
|
2385
2420
|
isActive: false,
|
|
@@ -2600,6 +2635,8 @@ var ExpoAppNotificationProvider = class {
|
|
|
2600
2635
|
this.logger = logger;
|
|
2601
2636
|
this.url = url;
|
|
2602
2637
|
}
|
|
2638
|
+
logger;
|
|
2639
|
+
url;
|
|
2603
2640
|
/**
|
|
2604
2641
|
* Bulk send: one HTTP request with many messages.
|
|
2605
2642
|
*/
|
|
@@ -2649,6 +2686,10 @@ var EmailProvider = class {
|
|
|
2649
2686
|
this.serviceDomain = serviceDomain;
|
|
2650
2687
|
this.EMAIL_USERNAME = EMAIL_USERNAME;
|
|
2651
2688
|
}
|
|
2689
|
+
prisma;
|
|
2690
|
+
logger;
|
|
2691
|
+
serviceDomain;
|
|
2692
|
+
EMAIL_USERNAME;
|
|
2652
2693
|
async send({
|
|
2653
2694
|
body,
|
|
2654
2695
|
recipient,
|
|
@@ -2731,6 +2772,8 @@ var SmsProvider = class {
|
|
|
2731
2772
|
this.sender = args.senderId || "AlmaMedLab";
|
|
2732
2773
|
this.countryCode = (args.countryCode || "+233").trim();
|
|
2733
2774
|
}
|
|
2775
|
+
logger;
|
|
2776
|
+
args;
|
|
2734
2777
|
url;
|
|
2735
2778
|
token;
|
|
2736
2779
|
sender;
|
|
@@ -2869,6 +2912,8 @@ var WebNotificationProvider = class {
|
|
|
2869
2912
|
this.prisma = prisma;
|
|
2870
2913
|
this.logger = logger;
|
|
2871
2914
|
}
|
|
2915
|
+
prisma;
|
|
2916
|
+
logger;
|
|
2872
2917
|
async sendBulk(args) {
|
|
2873
2918
|
const rows = (args.recipients ?? []).map((r) => {
|
|
2874
2919
|
let data = {
|
|
@@ -3262,6 +3307,8 @@ var WhatsAppProvider = class {
|
|
|
3262
3307
|
this.apiUrl = args.apiUrl ?? "";
|
|
3263
3308
|
this.apiKey = args.apiKey;
|
|
3264
3309
|
}
|
|
3310
|
+
args;
|
|
3311
|
+
logger;
|
|
3265
3312
|
apiKey;
|
|
3266
3313
|
apiUrl;
|
|
3267
3314
|
/**
|
|
@@ -3411,40 +3458,6 @@ var WhatsAppProvider = class {
|
|
|
3411
3458
|
}
|
|
3412
3459
|
};
|
|
3413
3460
|
|
|
3414
|
-
// src/utils/renderer.ts
|
|
3415
|
-
import Handlebars from "handlebars";
|
|
3416
|
-
function renderTemplate(tpl, data) {
|
|
3417
|
-
return Handlebars.compile(tpl)(data);
|
|
3418
|
-
}
|
|
3419
|
-
function renderEmailTemplate(tpl, data) {
|
|
3420
|
-
return {
|
|
3421
|
-
subject: tpl.subject ? Handlebars.compile(tpl.subject)(data) : void 0,
|
|
3422
|
-
body: Handlebars.compile(convertArrayPatternToEachBlocksGeneric(tpl.body))(data)
|
|
3423
|
-
};
|
|
3424
|
-
}
|
|
3425
|
-
var convertArrayPatternToEachBlocksGeneric = (html) => {
|
|
3426
|
-
if (!html) return "";
|
|
3427
|
-
const blockTags = ["tr", "div", "li", "section", "tbody"];
|
|
3428
|
-
let output = html;
|
|
3429
|
-
blockTags.forEach((tag) => {
|
|
3430
|
-
const regex = new RegExp(`<${tag}\\b[^>]*>[\\s\\S]*?<\\/${tag}>`, "g");
|
|
3431
|
-
output = output.replace(regex, (blockHtml) => {
|
|
3432
|
-
const matches = [...blockHtml.matchAll(/{{\s*([a-zA-Z0-9_.-]+)\[\]\.([a-zA-Z0-9_.-]+)\s*}}/g)];
|
|
3433
|
-
if (!matches.length) return blockHtml;
|
|
3434
|
-
const uniqueArrays = Array.from(new Set(matches.map((m) => m[1])));
|
|
3435
|
-
if (uniqueArrays.length !== 1) return blockHtml;
|
|
3436
|
-
const arrayName = uniqueArrays[0];
|
|
3437
|
-
const escapedArray = arrayName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3438
|
-
const cleanedBlock = blockHtml.replace(
|
|
3439
|
-
new RegExp(`{{\\s*${escapedArray}\\[\\]\\.([a-zA-Z0-9_.-]+)\\s*}}`, "g"),
|
|
3440
|
-
"{{$1}}"
|
|
3441
|
-
);
|
|
3442
|
-
return `{{#each ${arrayName}}}${cleanedBlock}{{/each}}`;
|
|
3443
|
-
});
|
|
3444
|
-
});
|
|
3445
|
-
return output;
|
|
3446
|
-
};
|
|
3447
|
-
|
|
3448
3461
|
// src/services/notification.service.ts
|
|
3449
3462
|
import merge from "lodash.merge";
|
|
3450
3463
|
var NotificationService = class {
|
|
@@ -3453,6 +3466,9 @@ var NotificationService = class {
|
|
|
3453
3466
|
this.logger = logger;
|
|
3454
3467
|
this.helpers = helpers;
|
|
3455
3468
|
}
|
|
3469
|
+
prisma;
|
|
3470
|
+
logger;
|
|
3471
|
+
helpers;
|
|
3456
3472
|
/**
|
|
3457
3473
|
* Main entry: handle one business event.
|
|
3458
3474
|
* Creates parent EventDelivery and one child EventDeliveryItem per attempt.
|
|
@@ -4215,6 +4231,7 @@ export {
|
|
|
4215
4231
|
AuditProxy,
|
|
4216
4232
|
NotificationEmitter,
|
|
4217
4233
|
commonService,
|
|
4234
|
+
convertArrayPatternToEachBlocksGeneric,
|
|
4218
4235
|
customOmit,
|
|
4219
4236
|
findDifferences,
|
|
4220
4237
|
formatDatesDeep,
|
|
@@ -4225,6 +4242,8 @@ export {
|
|
|
4225
4242
|
getPattern,
|
|
4226
4243
|
interpolate,
|
|
4227
4244
|
objectTo2DArray,
|
|
4245
|
+
renderEmailTemplate,
|
|
4246
|
+
renderTemplate,
|
|
4228
4247
|
toNumberOrNull,
|
|
4229
4248
|
toUINConfigDTO,
|
|
4230
4249
|
uinConfigService
|
package/package.json
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "av6-core",
|
|
3
|
-
"version": "1.7.
|
|
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
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "av6-core",
|
|
3
|
+
"version": "1.7.11",
|
|
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
|
+
}
|