totalum-api-sdk 3.0.2 → 3.0.4
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,4 +1,4 @@
|
|
|
1
|
-
## Totalum API SDK (v3.0.
|
|
1
|
+
## Totalum API SDK (v3.0.4)
|
|
2
2
|
|
|
3
3
|
Official TypeScript/JavaScript SDK for the Totalum API. This library provides a fully typed, modern interface to interact with all Totalum endpoints.
|
|
4
4
|
|
|
@@ -17,82 +17,6 @@ npm i totalum-api-sdk
|
|
|
17
17
|
- **Improved Type Safety**: Full TypeScript support with detailed response types
|
|
18
18
|
- **No Breaking Changes in API**: Same Totalum API, just better developer experience
|
|
19
19
|
|
|
20
|
-
## Migration Guide (v2.x → v3.0)
|
|
21
|
-
|
|
22
|
-
### Breaking Changes
|
|
23
|
-
|
|
24
|
-
#### 1. Method Names (CRUD Service)
|
|
25
|
-
```javascript
|
|
26
|
-
// v2.x
|
|
27
|
-
await totalumClient.crud.getItemById(table, id);
|
|
28
|
-
await totalumClient.crud.getItems(table, query);
|
|
29
|
-
await totalumClient.crud.createItem(table, data);
|
|
30
|
-
await totalumClient.crud.editItemById(table, id, data);
|
|
31
|
-
await totalumClient.crud.deleteItemById(table, id);
|
|
32
|
-
await totalumClient.crud.addManyToManyReferenceItem(table, id, prop, refId);
|
|
33
|
-
await totalumClient.crud.dropManyToManyReferenceItem(table, id, prop, refId);
|
|
34
|
-
await totalumClient.crud.getManyToManyReferencesItems(table, id, prop, query);
|
|
35
|
-
|
|
36
|
-
// v3.0
|
|
37
|
-
await totalumClient.crud.getRecordById(table, id);
|
|
38
|
-
await totalumClient.crud.getRecords(table, query);
|
|
39
|
-
await totalumClient.crud.createRecord(table, data);
|
|
40
|
-
await totalumClient.crud.editRecordById(table, id, data);
|
|
41
|
-
await totalumClient.crud.deleteRecordById(table, id);
|
|
42
|
-
await totalumClient.crud.addManyToManyReferenceRecord(table, id, prop, refId);
|
|
43
|
-
await totalumClient.crud.dropManyToManyReferenceRecord(table, id, prop, refId);
|
|
44
|
-
await totalumClient.crud.getManyToManyReferencesRecords(table, id, prop, query);
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
#### 2. Response Structure
|
|
48
|
-
```javascript
|
|
49
|
-
// v2.x (using axios)
|
|
50
|
-
const result = await totalumClient.crud.getItems(table, {});
|
|
51
|
-
const items = result.data.data; // Double .data because of axios wrapper
|
|
52
|
-
|
|
53
|
-
// v3.0 (using fetch)
|
|
54
|
-
const result = await totalumClient.crud.getRecords(table, {});
|
|
55
|
-
if (result.errors) {
|
|
56
|
-
console.error('Error:', result.errors.errorMessage);
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
const records = result.data; // Direct access to data
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
#### 3. Error Handling
|
|
63
|
-
```javascript
|
|
64
|
-
// v2.x (axios throws errors)
|
|
65
|
-
try {
|
|
66
|
-
const result = await totalumClient.crud.getItems(table, {});
|
|
67
|
-
const items = result.data.data;
|
|
68
|
-
} catch (error) {
|
|
69
|
-
console.error('Error:', error.message);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// v3.0 (errors in response object)
|
|
73
|
-
const result = await totalumClient.crud.getRecords(table, {});
|
|
74
|
-
if (result.errors) {
|
|
75
|
-
console.error('Error:', result.errors.errorMessage);
|
|
76
|
-
console.error('Error Code:', result.errors.errorCode);
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
const records = result.data;
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
### Dependencies
|
|
83
|
-
```json
|
|
84
|
-
// v2.x
|
|
85
|
-
{
|
|
86
|
-
"dependencies": {
|
|
87
|
-
"axios": "^1.x.x"
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// v3.0 (no dependencies!)
|
|
92
|
-
{
|
|
93
|
-
"dependencies": {}
|
|
94
|
-
}
|
|
95
|
-
```
|
|
96
20
|
|
|
97
21
|
**Note:** v3.0 requires Node.js 18+ (for native fetch support). If you're using an older Node.js version, you'll need to polyfill `fetch` or upgrade to Node.js 18+.
|
|
98
22
|
|
|
@@ -178,7 +102,7 @@ const result = await totalumClient.crud.getRecords('your_table_name', {});
|
|
|
178
102
|
|
|
179
103
|
```html
|
|
180
104
|
<head>
|
|
181
|
-
<script src="https://cdn.jsdelivr.net/npm/totalum-api-sdk@3.0.
|
|
105
|
+
<script src="https://cdn.jsdelivr.net/npm/totalum-api-sdk@3.0.2/dist/totalum-sdk.min.js"></script>
|
|
182
106
|
</head>
|
|
183
107
|
<script>
|
|
184
108
|
//Example of use TotalumSdk in your custom html page
|
|
@@ -414,7 +338,7 @@ const tableNameToGet = 'client';
|
|
|
414
338
|
|
|
415
339
|
const result = await totalumClient.filter.nestedFilter(nestedFilter, tableNameToGet, filterOptions);
|
|
416
340
|
|
|
417
|
-
const clients = result.data
|
|
341
|
+
const clients = result.data;
|
|
418
342
|
|
|
419
343
|
```
|
|
420
344
|
|
|
@@ -461,7 +385,7 @@ const tableNameToGet = 'product';
|
|
|
461
385
|
|
|
462
386
|
const result = await totalumClient.filter.nestedFilter(nestedFilter, tableNameToGet, filterOptions);
|
|
463
387
|
|
|
464
|
-
const products = result.data
|
|
388
|
+
const products = result.data;
|
|
465
389
|
|
|
466
390
|
```
|
|
467
391
|
|
|
@@ -911,7 +835,7 @@ Depending on the platform you are using, you will need to transform the file to
|
|
|
911
835
|
'api-key': 'your api key here', // replace 'your api key here' with your api key
|
|
912
836
|
}
|
|
913
837
|
});
|
|
914
|
-
const fileNameId = result.data
|
|
838
|
+
const fileNameId = result.data;
|
|
915
839
|
```
|
|
916
840
|
|
|
917
841
|
|
|
@@ -1082,7 +1006,7 @@ if (result.errors) {
|
|
|
1082
1006
|
return;
|
|
1083
1007
|
}
|
|
1084
1008
|
|
|
1085
|
-
const invoiceData = result.data
|
|
1009
|
+
const invoiceData = result.data;
|
|
1086
1010
|
const metadata = result.data.metadata;
|
|
1087
1011
|
|
|
1088
1012
|
console.log('Invoice data:', invoiceData);
|
|
@@ -1136,7 +1060,7 @@ if (result.errors) {
|
|
|
1136
1060
|
return;
|
|
1137
1061
|
}
|
|
1138
1062
|
|
|
1139
|
-
const documentData = result.data
|
|
1063
|
+
const documentData = result.data;
|
|
1140
1064
|
const metadata = result.data.metadata;
|
|
1141
1065
|
|
|
1142
1066
|
console.log('Extracted data:', documentData);
|
|
@@ -10,6 +10,7 @@ export interface ErrorResult {
|
|
|
10
10
|
export interface TotalumApiResponse<T> {
|
|
11
11
|
data?: T;
|
|
12
12
|
errors?: ErrorResult | null;
|
|
13
|
+
metadata?: any;
|
|
13
14
|
}
|
|
14
15
|
export interface StructureLevels {
|
|
15
16
|
id: string;
|
|
@@ -83,10 +84,10 @@ export type fieldFileI = {
|
|
|
83
84
|
};
|
|
84
85
|
export type fieldTypesEnabled = 'string' | 'number' | 'boolean' | 'date' | 'options' | 'file' | 'long-string' | /*'array' |*/ 'objectReference';
|
|
85
86
|
export interface DataValues {
|
|
86
|
-
_id
|
|
87
|
-
createdAt
|
|
88
|
-
updatedAt
|
|
89
|
-
[key: string]: fieldValuesEnabled;
|
|
87
|
+
_id?: string;
|
|
88
|
+
createdAt?: Date;
|
|
89
|
+
updatedAt?: Date;
|
|
90
|
+
[key: string]: fieldValuesEnabled | any;
|
|
90
91
|
}
|
|
91
92
|
export interface DataProperties {
|
|
92
93
|
[key: string]: fieldValuesEnabled | any;
|
|
@@ -17,12 +17,6 @@ export interface DeleteObjectResponse {
|
|
|
17
17
|
/** The number of documents that were deleted */
|
|
18
18
|
deletedCount: number;
|
|
19
19
|
}
|
|
20
|
-
export interface GetObjectsResponse<T = DataValues> {
|
|
21
|
-
data: T[];
|
|
22
|
-
metadata?: {
|
|
23
|
-
count?: number;
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
20
|
export interface FileUploadResponse {
|
|
27
21
|
fileName: string;
|
|
28
22
|
}
|
|
@@ -74,23 +68,6 @@ export interface ScanInvoiceData {
|
|
|
74
68
|
[key: string]: any;
|
|
75
69
|
};
|
|
76
70
|
}
|
|
77
|
-
export interface ScanInvoiceResponse {
|
|
78
|
-
data: ScanInvoiceData;
|
|
79
|
-
metadata: {
|
|
80
|
-
ocrFullResult?: any;
|
|
81
|
-
usageUnits: number;
|
|
82
|
-
exactUsageUnits: number;
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
export interface ScanDocumentResponse {
|
|
86
|
-
data: any;
|
|
87
|
-
metadata: {
|
|
88
|
-
ocrFullResult?: any;
|
|
89
|
-
ocrFullResultText?: string;
|
|
90
|
-
usageUnits: number;
|
|
91
|
-
exactUsageUnits: number;
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
71
|
export interface PdfGenerationResponse {
|
|
95
72
|
fileName: string;
|
|
96
73
|
}
|
|
@@ -143,12 +120,6 @@ export interface LookupFilterResult {
|
|
|
143
120
|
result: DataValues[] | number;
|
|
144
121
|
count?: number;
|
|
145
122
|
}
|
|
146
|
-
export interface NestedFilterResponse {
|
|
147
|
-
data: DataValues[];
|
|
148
|
-
metadata?: {
|
|
149
|
-
count?: number;
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
123
|
export type CustomAggregationResponse = any;
|
|
153
124
|
export interface NotificationVisibility {
|
|
154
125
|
sendTo: "all" | "admins" | "specificUsers";
|
|
@@ -184,7 +155,7 @@ export interface UpdatesRecordResponse {
|
|
|
184
155
|
_id: string;
|
|
185
156
|
objectId: string;
|
|
186
157
|
typeId: string;
|
|
187
|
-
|
|
158
|
+
updatesRecord: UpdateRecordChange[];
|
|
188
159
|
}
|
|
189
160
|
export interface ManyToManyReferenceResponse {
|
|
190
161
|
acknowledged: boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TotalumApiResponse } from "../common/interfaces";
|
|
2
|
-
import { FileDeleteResponse, OcrImageResponse, OcrPdfResponse,
|
|
2
|
+
import { FileDeleteResponse, OcrImageResponse, OcrPdfResponse, ScanInvoiceData } from "../common/response-types";
|
|
3
3
|
import { FetchClient } from "../common/fetch-client";
|
|
4
4
|
export declare class FilesService {
|
|
5
5
|
private client;
|
|
@@ -71,9 +71,9 @@ export declare class FilesService {
|
|
|
71
71
|
* The response includes both data and metadata with OCR details and usage tracking.
|
|
72
72
|
* @param {string} fileName - The file name of the uploaded invoice
|
|
73
73
|
* @param {any} options - Optional scanning options
|
|
74
|
-
* @returns {Promise<TotalumApiResponse<
|
|
74
|
+
* @returns {Promise<TotalumApiResponse<ScanInvoiceData>>}
|
|
75
75
|
*/
|
|
76
|
-
scanInvoice(fileName: string, options?: any): Promise<TotalumApiResponse<
|
|
76
|
+
scanInvoice(fileName: string, options?: any): Promise<TotalumApiResponse<ScanInvoiceData>>;
|
|
77
77
|
/**
|
|
78
78
|
* Scans a document and extracts specified properties.
|
|
79
79
|
* The response includes both data (based on provided schema) and metadata with OCR details.
|
|
@@ -82,5 +82,5 @@ export declare class FilesService {
|
|
|
82
82
|
* @param {any} options - Optional scanning options
|
|
83
83
|
* @returns {Promise<TotalumApiResponse<ScanDocumentResponse>>}
|
|
84
84
|
*/
|
|
85
|
-
scanDocument(fileName: string, properties: any, options?: any): Promise<TotalumApiResponse<
|
|
85
|
+
scanDocument(fileName: string, properties: any, options?: any): Promise<TotalumApiResponse<any>>;
|
|
86
86
|
}
|
|
@@ -118,7 +118,7 @@ class FilesService {
|
|
|
118
118
|
* The response includes both data and metadata with OCR details and usage tracking.
|
|
119
119
|
* @param {string} fileName - The file name of the uploaded invoice
|
|
120
120
|
* @param {any} options - Optional scanning options
|
|
121
|
-
* @returns {Promise<TotalumApiResponse<
|
|
121
|
+
* @returns {Promise<TotalumApiResponse<ScanInvoiceData>>}
|
|
122
122
|
*/
|
|
123
123
|
scanInvoice(fileName, options) {
|
|
124
124
|
return __awaiter(this, void 0, void 0, function* () {
|