A comprehensive shared library for Catura Services providing data models, middleware, and services for document management, audit logging, and workflow automation.
npm install @dynamatix/cat-sharedA comprehensive shared library for Catura Services providing data models, middleware, and services for document management, audit logging, and workflow automation.
``bash`
npm install @dynamatix/cat-shared
`javascript
import {
DocumentModel,
AuditModel,
applyAuditMiddleware,
getContext
} from '@dynamatix/cat-shared';
// Use models directly
const document = new DocumentModel({
filename: 'example.pdf',
documentTypeId: '...',
// ... other fields
});
// Apply audit middleware to track changes
applyAuditMiddleware(DocumentModel);
// Set request context
setContext({ userId: 'user123', requestId: 'req456' });
`
, DocumentTypeModel, DocumentHistoryModel
- Audit & Compliance: AuditModel, AuditConfigModel
- Workflow Management: WorkflowConfigModel, WorkflowAlertModel
- Form Configuration: FormConfigurationModel
- Value Reference Mapping: ValueReferenceMapModel$3
- Automatic change tracking for MongoDB documents
- Configurable audit logging with custom resolvers
- Support for complex field descriptions and lookups
- Integration with request context for user attribution$3
- Request Context: AsyncLocalStorage-based context management
- Audit Hooks: Mongoose hooks for automatic audit logging๐ API Reference
$3
#### DocumentModel
`javascript
import { DocumentModel } from '@dynamatix/cat-shared';const document = new DocumentModel({
contextId: 'application123',
filename: 'document.pdf',
documentTypeId: 'type456',
documentUrl: 'https://storage.example.com/doc.pdf',
statusLid: 'status789',
uploadedBy: 'user123'
});
`#### AuditModel
`javascript
import { AuditModel } from '@dynamatix/cat-shared';const auditLog = new AuditModel({
name: 'Document Updated',
recordId: 'document123',
contextId: 'application456',
oldValue: { status: 'pending' },
newValue: { status: 'approved' },
createdBy: 'user789'
});
`$3
#### applyAuditMiddleware
`javascript
import { applyAuditMiddleware } from '@dynamatix/cat-shared';// Apply audit middleware to a model
applyAuditMiddleware(DocumentModel);
// The model will now automatically log all changes
`#### registerAuditHook
`javascript
import { registerAuditHook } from '@dynamatix/cat-shared';// Register custom audit hooks
registerAuditHook(DocumentModel, {
pre: (doc) => console.log('Before save:', doc),
post: (doc) => console.log('After save:', doc)
});
`$3
#### Request Context
`javascript
import { getContext, setContext } from '@dynamatix/cat-shared';// Set context for the current request
setContext({
userId: 'user123',
requestId: 'req456',
timestamp: new Date()
});
// Get context anywhere in the request lifecycle
const context = getContext();
console.log('Current user:', context.userId);
`๐ง Configuration
$3
The audit system uses AuditConfigModel to configure what fields to track and how to describe changes:`javascript
const auditConfig = new AuditConfigModel({
modelName: 'Document',
fields: ['status', 'filename'],
descriptionField: 'filename',
descriptionResolverType: 'direct'
});
`$3
Use ValueReferenceMapModel to configure how to resolve and display referenced fields:`javascript
const valueMap = new ValueReferenceMapModel({
field: 'createdBy',
model: 'User',
displayField: 'fullName',
descriptionResolverType: 'lookup'
});
`๐ฑ Seeding
The project includes seeders for initial data setup:
`bash
Run the value reference map seeder
node seeders/value-reference-map.seeder.js
`๐ Project Structure
`
cat-shared/
โโโ models/ # MongoDB/Mongoose data models
โ โโโ document.model.js
โ โโโ audit.model.js
โ โโโ workflow-*.model.js
โ โโโ index.js
โโโ middlewares/ # Express/Node.js middleware
โ โโโ audit.middleware.js
โ โโโ index.js
โโโ services/ # Business logic services
โ โโโ request-context.service.js
โ โโโ audit-log.hook.js
โ โโโ index.js
โโโ seeders/ # Database seeding scripts
โโโ utils/ # Utility functions
โโโ index.js # Main export file
`๐ Exports
The library provides the following export paths:
`javascript
// Main exports
import { DocumentModel, AuditModel } from '@dynamatix/cat-shared';// Specific module exports
import { DocumentModel } from '@dynamatix/cat-shared/models';
import { applyAuditMiddleware } from '@dynamatix/cat-shared/middlewares';
import { getContext } from '@dynamatix/cat-shared/services';
`๐งช Development
$3
- Node.js 18+
- MongoDB
- Mongoose 8.13.1+$3
`bash
Clone the repository
git clone
cd cat-sharedInstall dependencies
npm installRun tests (when implemented)
npm test
``ISC License
This is a shared library for Catura Services. Please contact the development team for contribution guidelines.
For support and questions, please contact the Catura Services development team.