@dynamatix/cat-shared 0.0.125 โ 0.0.126
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/README.md +226 -226
- package/index.js +2 -2
- package/middlewares/audit.middleware.js +355 -355
- package/middlewares/index.js +2 -2
- package/models/audit-config.model.js +15 -15
- package/models/audit.model.js +16 -16
- package/models/document-history.model.js +51 -51
- package/models/document-type.model.js +25 -25
- package/models/document.model.js +68 -68
- package/models/form-configuration.model.js +277 -273
- package/models/index.js +10 -10
- package/models/meta.model.js +9 -9
- package/models/property-metadata.model.js +57 -57
- package/models/value-reference-map.model.js +16 -16
- package/models/workflow-alert.model.js +61 -61
- package/models/workflow-config.model.js +29 -29
- package/package.json +22 -22
- package/seeders/value-reference-map.seeder.js +66 -66
- package/services/audit-log.hook.js +2 -2
- package/services/index.js +1 -1
- package/services/request-context.service.js +8 -8
package/README.md
CHANGED
|
@@ -1,227 +1,227 @@
|
|
|
1
|
-
# @dynamatix/cat-shared
|
|
2
|
-
|
|
3
|
-
A comprehensive shared library for Catura Services providing data models, middleware, and services for document management, audit logging, and workflow automation.
|
|
4
|
-
|
|
5
|
-
## ๐ฆ Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install @dynamatix/cat-shared
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## ๐ Quick Start
|
|
12
|
-
|
|
13
|
-
```javascript
|
|
14
|
-
import {
|
|
15
|
-
DocumentModel,
|
|
16
|
-
AuditModel,
|
|
17
|
-
applyAuditMiddleware,
|
|
18
|
-
getContext
|
|
19
|
-
} from '@dynamatix/cat-shared';
|
|
20
|
-
|
|
21
|
-
// Use models directly
|
|
22
|
-
const document = new DocumentModel({
|
|
23
|
-
filename: 'example.pdf',
|
|
24
|
-
documentTypeId: '...',
|
|
25
|
-
// ... other fields
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
// Apply audit middleware to track changes
|
|
29
|
-
applyAuditMiddleware(DocumentModel);
|
|
30
|
-
|
|
31
|
-
// Set request context
|
|
32
|
-
setContext({ userId: 'user123', requestId: 'req456' });
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
## ๐ Features
|
|
36
|
-
|
|
37
|
-
### ๐ **Data Models**
|
|
38
|
-
- **Document Management**: `DocumentModel`, `DocumentTypeModel`, `DocumentHistoryModel`
|
|
39
|
-
- **Audit & Compliance**: `AuditModel`, `AuditConfigModel`
|
|
40
|
-
- **Workflow Management**: `WorkflowConfigModel`, `WorkflowAlertModel`
|
|
41
|
-
- **Form Configuration**: `FormConfigurationModel`
|
|
42
|
-
- **Value Reference Mapping**: `ValueReferenceMapModel`
|
|
43
|
-
|
|
44
|
-
### ๐ก๏ธ **Audit Middleware**
|
|
45
|
-
- Automatic change tracking for MongoDB documents
|
|
46
|
-
- Configurable audit logging with custom resolvers
|
|
47
|
-
- Support for complex field descriptions and lookups
|
|
48
|
-
- Integration with request context for user attribution
|
|
49
|
-
|
|
50
|
-
### ๐ง **Services**
|
|
51
|
-
- **Request Context**: AsyncLocalStorage-based context management
|
|
52
|
-
- **Audit Hooks**: Mongoose hooks for automatic audit logging
|
|
53
|
-
|
|
54
|
-
## ๐ API Reference
|
|
55
|
-
|
|
56
|
-
### Models
|
|
57
|
-
|
|
58
|
-
#### DocumentModel
|
|
59
|
-
```javascript
|
|
60
|
-
import { DocumentModel } from '@dynamatix/cat-shared';
|
|
61
|
-
|
|
62
|
-
const document = new DocumentModel({
|
|
63
|
-
contextId: 'application123',
|
|
64
|
-
filename: 'document.pdf',
|
|
65
|
-
documentTypeId: 'type456',
|
|
66
|
-
documentUrl: 'https://storage.example.com/doc.pdf',
|
|
67
|
-
statusLid: 'status789',
|
|
68
|
-
uploadedBy: 'user123'
|
|
69
|
-
});
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
#### AuditModel
|
|
73
|
-
```javascript
|
|
74
|
-
import { AuditModel } from '@dynamatix/cat-shared';
|
|
75
|
-
|
|
76
|
-
const auditLog = new AuditModel({
|
|
77
|
-
name: 'Document Updated',
|
|
78
|
-
recordId: 'document123',
|
|
79
|
-
contextId: 'application456',
|
|
80
|
-
oldValue: { status: 'pending' },
|
|
81
|
-
newValue: { status: 'approved' },
|
|
82
|
-
createdBy: 'user789'
|
|
83
|
-
});
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
### Middleware
|
|
87
|
-
|
|
88
|
-
#### applyAuditMiddleware
|
|
89
|
-
```javascript
|
|
90
|
-
import { applyAuditMiddleware } from '@dynamatix/cat-shared';
|
|
91
|
-
|
|
92
|
-
// Apply audit middleware to a model
|
|
93
|
-
applyAuditMiddleware(DocumentModel);
|
|
94
|
-
|
|
95
|
-
// The model will now automatically log all changes
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
#### registerAuditHook
|
|
99
|
-
```javascript
|
|
100
|
-
import { registerAuditHook } from '@dynamatix/cat-shared';
|
|
101
|
-
|
|
102
|
-
// Register custom audit hooks
|
|
103
|
-
registerAuditHook(DocumentModel, {
|
|
104
|
-
pre: (doc) => console.log('Before save:', doc),
|
|
105
|
-
post: (doc) => console.log('After save:', doc)
|
|
106
|
-
});
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
### Services
|
|
110
|
-
|
|
111
|
-
#### Request Context
|
|
112
|
-
```javascript
|
|
113
|
-
import { getContext, setContext } from '@dynamatix/cat-shared';
|
|
114
|
-
|
|
115
|
-
// Set context for the current request
|
|
116
|
-
setContext({
|
|
117
|
-
userId: 'user123',
|
|
118
|
-
requestId: 'req456',
|
|
119
|
-
timestamp: new Date()
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
// Get context anywhere in the request lifecycle
|
|
123
|
-
const context = getContext();
|
|
124
|
-
console.log('Current user:', context.userId);
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
## ๐ง Configuration
|
|
128
|
-
|
|
129
|
-
### Audit Configuration
|
|
130
|
-
The audit system uses `AuditConfigModel` to configure what fields to track and how to describe changes:
|
|
131
|
-
|
|
132
|
-
```javascript
|
|
133
|
-
const auditConfig = new AuditConfigModel({
|
|
134
|
-
modelName: 'Document',
|
|
135
|
-
fields: ['status', 'filename'],
|
|
136
|
-
descriptionField: 'filename',
|
|
137
|
-
descriptionResolverType: 'direct'
|
|
138
|
-
});
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
### Value Reference Mapping
|
|
142
|
-
Use `ValueReferenceMapModel` to configure how to resolve and display referenced fields:
|
|
143
|
-
|
|
144
|
-
```javascript
|
|
145
|
-
const valueMap = new ValueReferenceMapModel({
|
|
146
|
-
field: 'createdBy',
|
|
147
|
-
model: 'User',
|
|
148
|
-
displayField: 'fullName',
|
|
149
|
-
descriptionResolverType: 'lookup'
|
|
150
|
-
});
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
## ๐ฑ Seeding
|
|
154
|
-
|
|
155
|
-
The project includes seeders for initial data setup:
|
|
156
|
-
|
|
157
|
-
```bash
|
|
158
|
-
# Run the value reference map seeder
|
|
159
|
-
node seeders/value-reference-map.seeder.js
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
## ๐ Project Structure
|
|
163
|
-
|
|
164
|
-
```
|
|
165
|
-
cat-shared/
|
|
166
|
-
โโโ models/ # MongoDB/Mongoose data models
|
|
167
|
-
โ โโโ document.model.js
|
|
168
|
-
โ โโโ audit.model.js
|
|
169
|
-
โ โโโ workflow-*.model.js
|
|
170
|
-
โ โโโ index.js
|
|
171
|
-
โโโ middlewares/ # Express/Node.js middleware
|
|
172
|
-
โ โโโ audit.middleware.js
|
|
173
|
-
โ โโโ index.js
|
|
174
|
-
โโโ services/ # Business logic services
|
|
175
|
-
โ โโโ request-context.service.js
|
|
176
|
-
โ โโโ audit-log.hook.js
|
|
177
|
-
โ โโโ index.js
|
|
178
|
-
โโโ seeders/ # Database seeding scripts
|
|
179
|
-
โโโ utils/ # Utility functions
|
|
180
|
-
โโโ index.js # Main export file
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
## ๐ Exports
|
|
184
|
-
|
|
185
|
-
The library provides the following export paths:
|
|
186
|
-
|
|
187
|
-
```javascript
|
|
188
|
-
// Main exports
|
|
189
|
-
import { DocumentModel, AuditModel } from '@dynamatix/cat-shared';
|
|
190
|
-
|
|
191
|
-
// Specific module exports
|
|
192
|
-
import { DocumentModel } from '@dynamatix/cat-shared/models';
|
|
193
|
-
import { applyAuditMiddleware } from '@dynamatix/cat-shared/middlewares';
|
|
194
|
-
import { getContext } from '@dynamatix/cat-shared/services';
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
## ๐งช Development
|
|
198
|
-
|
|
199
|
-
### Prerequisites
|
|
200
|
-
- Node.js 18+
|
|
201
|
-
- MongoDB
|
|
202
|
-
- Mongoose 8.13.1+
|
|
203
|
-
|
|
204
|
-
### Local Development
|
|
205
|
-
```bash
|
|
206
|
-
# Clone the repository
|
|
207
|
-
git clone <repository-url>
|
|
208
|
-
cd cat-shared
|
|
209
|
-
|
|
210
|
-
# Install dependencies
|
|
211
|
-
npm install
|
|
212
|
-
|
|
213
|
-
# Run tests (when implemented)
|
|
214
|
-
npm test
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
## ๐ License
|
|
218
|
-
|
|
219
|
-
ISC License
|
|
220
|
-
|
|
221
|
-
## ๐ค Contributing
|
|
222
|
-
|
|
223
|
-
This is a shared library for Catura Services. Please contact the development team for contribution guidelines.
|
|
224
|
-
|
|
225
|
-
## ๐ Support
|
|
226
|
-
|
|
1
|
+
# @dynamatix/cat-shared
|
|
2
|
+
|
|
3
|
+
A comprehensive shared library for Catura Services providing data models, middleware, and services for document management, audit logging, and workflow automation.
|
|
4
|
+
|
|
5
|
+
## ๐ฆ Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @dynamatix/cat-shared
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## ๐ Quick Start
|
|
12
|
+
|
|
13
|
+
```javascript
|
|
14
|
+
import {
|
|
15
|
+
DocumentModel,
|
|
16
|
+
AuditModel,
|
|
17
|
+
applyAuditMiddleware,
|
|
18
|
+
getContext
|
|
19
|
+
} from '@dynamatix/cat-shared';
|
|
20
|
+
|
|
21
|
+
// Use models directly
|
|
22
|
+
const document = new DocumentModel({
|
|
23
|
+
filename: 'example.pdf',
|
|
24
|
+
documentTypeId: '...',
|
|
25
|
+
// ... other fields
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// Apply audit middleware to track changes
|
|
29
|
+
applyAuditMiddleware(DocumentModel);
|
|
30
|
+
|
|
31
|
+
// Set request context
|
|
32
|
+
setContext({ userId: 'user123', requestId: 'req456' });
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## ๐ Features
|
|
36
|
+
|
|
37
|
+
### ๐ **Data Models**
|
|
38
|
+
- **Document Management**: `DocumentModel`, `DocumentTypeModel`, `DocumentHistoryModel`
|
|
39
|
+
- **Audit & Compliance**: `AuditModel`, `AuditConfigModel`
|
|
40
|
+
- **Workflow Management**: `WorkflowConfigModel`, `WorkflowAlertModel`
|
|
41
|
+
- **Form Configuration**: `FormConfigurationModel`
|
|
42
|
+
- **Value Reference Mapping**: `ValueReferenceMapModel`
|
|
43
|
+
|
|
44
|
+
### ๐ก๏ธ **Audit Middleware**
|
|
45
|
+
- Automatic change tracking for MongoDB documents
|
|
46
|
+
- Configurable audit logging with custom resolvers
|
|
47
|
+
- Support for complex field descriptions and lookups
|
|
48
|
+
- Integration with request context for user attribution
|
|
49
|
+
|
|
50
|
+
### ๐ง **Services**
|
|
51
|
+
- **Request Context**: AsyncLocalStorage-based context management
|
|
52
|
+
- **Audit Hooks**: Mongoose hooks for automatic audit logging
|
|
53
|
+
|
|
54
|
+
## ๐ API Reference
|
|
55
|
+
|
|
56
|
+
### Models
|
|
57
|
+
|
|
58
|
+
#### DocumentModel
|
|
59
|
+
```javascript
|
|
60
|
+
import { DocumentModel } from '@dynamatix/cat-shared';
|
|
61
|
+
|
|
62
|
+
const document = new DocumentModel({
|
|
63
|
+
contextId: 'application123',
|
|
64
|
+
filename: 'document.pdf',
|
|
65
|
+
documentTypeId: 'type456',
|
|
66
|
+
documentUrl: 'https://storage.example.com/doc.pdf',
|
|
67
|
+
statusLid: 'status789',
|
|
68
|
+
uploadedBy: 'user123'
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
#### AuditModel
|
|
73
|
+
```javascript
|
|
74
|
+
import { AuditModel } from '@dynamatix/cat-shared';
|
|
75
|
+
|
|
76
|
+
const auditLog = new AuditModel({
|
|
77
|
+
name: 'Document Updated',
|
|
78
|
+
recordId: 'document123',
|
|
79
|
+
contextId: 'application456',
|
|
80
|
+
oldValue: { status: 'pending' },
|
|
81
|
+
newValue: { status: 'approved' },
|
|
82
|
+
createdBy: 'user789'
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Middleware
|
|
87
|
+
|
|
88
|
+
#### applyAuditMiddleware
|
|
89
|
+
```javascript
|
|
90
|
+
import { applyAuditMiddleware } from '@dynamatix/cat-shared';
|
|
91
|
+
|
|
92
|
+
// Apply audit middleware to a model
|
|
93
|
+
applyAuditMiddleware(DocumentModel);
|
|
94
|
+
|
|
95
|
+
// The model will now automatically log all changes
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
#### registerAuditHook
|
|
99
|
+
```javascript
|
|
100
|
+
import { registerAuditHook } from '@dynamatix/cat-shared';
|
|
101
|
+
|
|
102
|
+
// Register custom audit hooks
|
|
103
|
+
registerAuditHook(DocumentModel, {
|
|
104
|
+
pre: (doc) => console.log('Before save:', doc),
|
|
105
|
+
post: (doc) => console.log('After save:', doc)
|
|
106
|
+
});
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Services
|
|
110
|
+
|
|
111
|
+
#### Request Context
|
|
112
|
+
```javascript
|
|
113
|
+
import { getContext, setContext } from '@dynamatix/cat-shared';
|
|
114
|
+
|
|
115
|
+
// Set context for the current request
|
|
116
|
+
setContext({
|
|
117
|
+
userId: 'user123',
|
|
118
|
+
requestId: 'req456',
|
|
119
|
+
timestamp: new Date()
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// Get context anywhere in the request lifecycle
|
|
123
|
+
const context = getContext();
|
|
124
|
+
console.log('Current user:', context.userId);
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## ๐ง Configuration
|
|
128
|
+
|
|
129
|
+
### Audit Configuration
|
|
130
|
+
The audit system uses `AuditConfigModel` to configure what fields to track and how to describe changes:
|
|
131
|
+
|
|
132
|
+
```javascript
|
|
133
|
+
const auditConfig = new AuditConfigModel({
|
|
134
|
+
modelName: 'Document',
|
|
135
|
+
fields: ['status', 'filename'],
|
|
136
|
+
descriptionField: 'filename',
|
|
137
|
+
descriptionResolverType: 'direct'
|
|
138
|
+
});
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Value Reference Mapping
|
|
142
|
+
Use `ValueReferenceMapModel` to configure how to resolve and display referenced fields:
|
|
143
|
+
|
|
144
|
+
```javascript
|
|
145
|
+
const valueMap = new ValueReferenceMapModel({
|
|
146
|
+
field: 'createdBy',
|
|
147
|
+
model: 'User',
|
|
148
|
+
displayField: 'fullName',
|
|
149
|
+
descriptionResolverType: 'lookup'
|
|
150
|
+
});
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## ๐ฑ Seeding
|
|
154
|
+
|
|
155
|
+
The project includes seeders for initial data setup:
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
# Run the value reference map seeder
|
|
159
|
+
node seeders/value-reference-map.seeder.js
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## ๐ Project Structure
|
|
163
|
+
|
|
164
|
+
```
|
|
165
|
+
cat-shared/
|
|
166
|
+
โโโ models/ # MongoDB/Mongoose data models
|
|
167
|
+
โ โโโ document.model.js
|
|
168
|
+
โ โโโ audit.model.js
|
|
169
|
+
โ โโโ workflow-*.model.js
|
|
170
|
+
โ โโโ index.js
|
|
171
|
+
โโโ middlewares/ # Express/Node.js middleware
|
|
172
|
+
โ โโโ audit.middleware.js
|
|
173
|
+
โ โโโ index.js
|
|
174
|
+
โโโ services/ # Business logic services
|
|
175
|
+
โ โโโ request-context.service.js
|
|
176
|
+
โ โโโ audit-log.hook.js
|
|
177
|
+
โ โโโ index.js
|
|
178
|
+
โโโ seeders/ # Database seeding scripts
|
|
179
|
+
โโโ utils/ # Utility functions
|
|
180
|
+
โโโ index.js # Main export file
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## ๐ Exports
|
|
184
|
+
|
|
185
|
+
The library provides the following export paths:
|
|
186
|
+
|
|
187
|
+
```javascript
|
|
188
|
+
// Main exports
|
|
189
|
+
import { DocumentModel, AuditModel } from '@dynamatix/cat-shared';
|
|
190
|
+
|
|
191
|
+
// Specific module exports
|
|
192
|
+
import { DocumentModel } from '@dynamatix/cat-shared/models';
|
|
193
|
+
import { applyAuditMiddleware } from '@dynamatix/cat-shared/middlewares';
|
|
194
|
+
import { getContext } from '@dynamatix/cat-shared/services';
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## ๐งช Development
|
|
198
|
+
|
|
199
|
+
### Prerequisites
|
|
200
|
+
- Node.js 18+
|
|
201
|
+
- MongoDB
|
|
202
|
+
- Mongoose 8.13.1+
|
|
203
|
+
|
|
204
|
+
### Local Development
|
|
205
|
+
```bash
|
|
206
|
+
# Clone the repository
|
|
207
|
+
git clone <repository-url>
|
|
208
|
+
cd cat-shared
|
|
209
|
+
|
|
210
|
+
# Install dependencies
|
|
211
|
+
npm install
|
|
212
|
+
|
|
213
|
+
# Run tests (when implemented)
|
|
214
|
+
npm test
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## ๐ License
|
|
218
|
+
|
|
219
|
+
ISC License
|
|
220
|
+
|
|
221
|
+
## ๐ค Contributing
|
|
222
|
+
|
|
223
|
+
This is a shared library for Catura Services. Please contact the development team for contribution guidelines.
|
|
224
|
+
|
|
225
|
+
## ๐ Support
|
|
226
|
+
|
|
227
227
|
For support and questions, please contact the Catura Services development team.
|
package/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './models/index.js';
|
|
2
|
-
export * from './middlewares/index.js';
|
|
1
|
+
export * from './models/index.js';
|
|
2
|
+
export * from './middlewares/index.js';
|
|
3
3
|
export * from './services/index.js';
|