@vulog/aima-document 1.1.89 → 1.1.92
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 +217 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1 +1,218 @@
|
|
|
1
1
|
# @vulog/aima-document
|
|
2
|
+
|
|
3
|
+
Document management module for the AIMA platform. This module provides functionality to manage user documents, including creation, updates, and status management.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @vulog/aima-client @vulog/aima-core @vulog/aima-document
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Initialize Client
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
import { getClient } from '@vulog/aima-client';
|
|
17
|
+
import { createOrUpdateDocument, getUserDocuments, updateDocumentStatus } from '@vulog/aima-document';
|
|
18
|
+
|
|
19
|
+
const client = getClient({
|
|
20
|
+
apiKey: 'your-api-key',
|
|
21
|
+
baseUrl: 'https://your-api-base-url',
|
|
22
|
+
clientId: 'your-client-id',
|
|
23
|
+
clientSecret: 'your-client-secret',
|
|
24
|
+
fleetId: 'your-fleet-id',
|
|
25
|
+
});
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## API Reference
|
|
29
|
+
|
|
30
|
+
### createOrUpdateDocument
|
|
31
|
+
|
|
32
|
+
Create a new document or update an existing one for a user.
|
|
33
|
+
|
|
34
|
+
```javascript
|
|
35
|
+
const document = await createOrUpdateDocument(client, {
|
|
36
|
+
entityId: 'user-uuid-here',
|
|
37
|
+
documentType: 'DRIVER_LICENSE',
|
|
38
|
+
fileData: 'base64-encoded-file-data',
|
|
39
|
+
fileName: 'license.pdf',
|
|
40
|
+
mimeType: 'application/pdf'
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
**Parameters:**
|
|
45
|
+
- `client`: AIMA client instance
|
|
46
|
+
- `payload`: Document configuration object
|
|
47
|
+
- `entityId`: User UUID
|
|
48
|
+
- `documentType`: Type of document (e.g., 'DRIVER_LICENSE', 'ID_CARD', 'PASSPORT')
|
|
49
|
+
- `fileData`: Base64 encoded file data
|
|
50
|
+
- `fileName`: Name of the file
|
|
51
|
+
- `mimeType`: MIME type of the file
|
|
52
|
+
|
|
53
|
+
### getUserDocuments
|
|
54
|
+
|
|
55
|
+
Retrieve all documents for a specific user.
|
|
56
|
+
|
|
57
|
+
```javascript
|
|
58
|
+
const documents = await getUserDocuments(client, 'user-uuid-here');
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
**Parameters:**
|
|
62
|
+
- `client`: AIMA client instance
|
|
63
|
+
- `entityId`: User UUID
|
|
64
|
+
|
|
65
|
+
**Returns:** Array of user documents
|
|
66
|
+
|
|
67
|
+
### updateDocumentStatus
|
|
68
|
+
|
|
69
|
+
Update the status of a document.
|
|
70
|
+
|
|
71
|
+
```javascript
|
|
72
|
+
const updatedDocument = await updateDocumentStatus(client, {
|
|
73
|
+
documentId: 'document-id-here',
|
|
74
|
+
status: 'APPROVED',
|
|
75
|
+
notes: 'Document verified successfully'
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**Parameters:**
|
|
80
|
+
- `client`: AIMA client instance
|
|
81
|
+
- `payload`: Status update configuration
|
|
82
|
+
- `documentId`: Document identifier
|
|
83
|
+
- `status`: New status ('PENDING', 'APPROVED', 'REJECTED')
|
|
84
|
+
- `notes`: Optional notes about the status change
|
|
85
|
+
|
|
86
|
+
## Types
|
|
87
|
+
|
|
88
|
+
### Document
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
interface Document {
|
|
92
|
+
id: string;
|
|
93
|
+
entityId: string;
|
|
94
|
+
documentType: string;
|
|
95
|
+
fileName: string;
|
|
96
|
+
mimeType: string;
|
|
97
|
+
fileSize: number;
|
|
98
|
+
status: 'PENDING' | 'APPROVED' | 'REJECTED';
|
|
99
|
+
uploadDate: string;
|
|
100
|
+
lastModified: string;
|
|
101
|
+
notes?: string;
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### DocumentType
|
|
106
|
+
|
|
107
|
+
Common document types include:
|
|
108
|
+
- `DRIVER_LICENSE`: Driver's license
|
|
109
|
+
- `ID_CARD`: National ID card
|
|
110
|
+
- `PASSPORT`: Passport
|
|
111
|
+
- `INSURANCE`: Insurance document
|
|
112
|
+
- `REGISTRATION`: Vehicle registration
|
|
113
|
+
|
|
114
|
+
## Error Handling
|
|
115
|
+
|
|
116
|
+
All functions include validation and will throw appropriate errors if:
|
|
117
|
+
- Required parameters are missing
|
|
118
|
+
- Invalid document types are provided
|
|
119
|
+
- File data is invalid
|
|
120
|
+
- User or document not found
|
|
121
|
+
|
|
122
|
+
## Examples
|
|
123
|
+
|
|
124
|
+
### Complete Document Management Workflow
|
|
125
|
+
|
|
126
|
+
```javascript
|
|
127
|
+
import { getClient } from '@vulog/aima-client';
|
|
128
|
+
import { createOrUpdateDocument, getUserDocuments, updateDocumentStatus } from '@vulog/aima-document';
|
|
129
|
+
import fs from 'fs';
|
|
130
|
+
|
|
131
|
+
const client = getClient({
|
|
132
|
+
apiKey: 'your-api-key',
|
|
133
|
+
baseUrl: 'https://your-api-base-url',
|
|
134
|
+
clientId: 'your-client-id',
|
|
135
|
+
clientSecret: 'your-client-secret',
|
|
136
|
+
fleetId: 'your-fleet-id',
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
async function documentWorkflow() {
|
|
140
|
+
try {
|
|
141
|
+
// Read and encode a file
|
|
142
|
+
const fileBuffer = fs.readFileSync('path/to/license.pdf');
|
|
143
|
+
const base64Data = fileBuffer.toString('base64');
|
|
144
|
+
|
|
145
|
+
// Create a new document
|
|
146
|
+
const document = await createOrUpdateDocument(client, {
|
|
147
|
+
entityId: 'user-uuid-here',
|
|
148
|
+
documentType: 'DRIVER_LICENSE',
|
|
149
|
+
fileData: base64Data,
|
|
150
|
+
fileName: 'license.pdf',
|
|
151
|
+
mimeType: 'application/pdf'
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
console.log('Document created:', document);
|
|
155
|
+
|
|
156
|
+
// Get all user documents
|
|
157
|
+
const documents = await getUserDocuments(client, 'user-uuid-here');
|
|
158
|
+
console.log('User documents:', documents);
|
|
159
|
+
|
|
160
|
+
// Update document status
|
|
161
|
+
const updatedDocument = await updateDocumentStatus(client, {
|
|
162
|
+
documentId: document.id,
|
|
163
|
+
status: 'APPROVED',
|
|
164
|
+
notes: 'License verified and approved'
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
console.log('Document status updated:', updatedDocument);
|
|
168
|
+
|
|
169
|
+
} catch (error) {
|
|
170
|
+
console.error('Document management error:', error);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### File Upload Helper
|
|
176
|
+
|
|
177
|
+
```javascript
|
|
178
|
+
import { createOrUpdateDocument } from '@vulog/aima-document';
|
|
179
|
+
import fs from 'fs';
|
|
180
|
+
|
|
181
|
+
async function uploadDocument(client, filePath, documentType, entityId) {
|
|
182
|
+
try {
|
|
183
|
+
// Read file
|
|
184
|
+
const fileBuffer = fs.readFileSync(filePath);
|
|
185
|
+
const base64Data = fileBuffer.toString('base64');
|
|
186
|
+
|
|
187
|
+
// Get file info
|
|
188
|
+
const stats = fs.statSync(filePath);
|
|
189
|
+
const fileName = filePath.split('/').pop();
|
|
190
|
+
const mimeType = getMimeType(fileName);
|
|
191
|
+
|
|
192
|
+
// Upload document
|
|
193
|
+
return await createOrUpdateDocument(client, {
|
|
194
|
+
entityId,
|
|
195
|
+
documentType,
|
|
196
|
+
fileData: base64Data,
|
|
197
|
+
fileName,
|
|
198
|
+
mimeType
|
|
199
|
+
});
|
|
200
|
+
} catch (error) {
|
|
201
|
+
console.error('File upload error:', error);
|
|
202
|
+
throw error;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function getMimeType(fileName) {
|
|
207
|
+
const ext = fileName.split('.').pop().toLowerCase();
|
|
208
|
+
const mimeTypes = {
|
|
209
|
+
'pdf': 'application/pdf',
|
|
210
|
+
'jpg': 'image/jpeg',
|
|
211
|
+
'jpeg': 'image/jpeg',
|
|
212
|
+
'png': 'image/png',
|
|
213
|
+
'doc': 'application/msword',
|
|
214
|
+
'docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
|
|
215
|
+
};
|
|
216
|
+
return mimeTypes[ext] || 'application/octet-stream';
|
|
217
|
+
}
|
|
218
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vulog/aima-document",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.92",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"author": "Vulog",
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@vulog/aima-client": "1.1.
|
|
23
|
-
"@vulog/aima-core": "1.1.
|
|
22
|
+
"@vulog/aima-client": "1.1.92",
|
|
23
|
+
"@vulog/aima-core": "1.1.92"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"zod": "^3.25.76"
|