@dynamatix/cat-shared 0.0.128 โ†’ 0.0.129

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 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';