totalum-api-sdk 2.0.42 → 3.0.0
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 +641 -213
- package/dist/common/fetch-client.d.ts +24 -0
- package/dist/common/fetch-client.js +127 -0
- package/dist/common/interfaces.d.ts +26 -5
- package/dist/common/response-types.d.ts +210 -0
- package/dist/common/response-types.js +2 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +23 -17
- package/dist/services/CrudService.d.ts +77 -41
- package/dist/services/CrudService.js +88 -56
- package/dist/services/EmailService.d.ts +11 -9
- package/dist/services/EmailService.js +27 -17
- package/dist/services/FilesService.d.ts +67 -21
- package/dist/services/FilesService.js +82 -35
- package/dist/services/FilterService.d.ts +23 -20
- package/dist/services/FilterService.js +32 -36
- package/dist/services/NotificationService.d.ts +9 -9
- package/dist/services/NotificationService.js +7 -13
- package/dist/services/OpenaiService.d.ts +21 -24
- package/dist/services/OpenaiService.js +21 -26
- package/dist/services/StatisticService.d.ts +11 -5
- package/dist/services/StatisticService.js +10 -9
- package/dist/totalum-sdk.min.js +1 -1
- package/package.json +6 -5
|
@@ -8,108 +8,140 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
12
|
exports.CrudService = void 0;
|
|
16
|
-
const axios_1 = __importDefault(require("axios"));
|
|
17
13
|
const utils_1 = require("../utils");
|
|
18
14
|
const endpoints_1 = require("../common/endpoints");
|
|
19
15
|
class CrudService {
|
|
20
|
-
constructor(
|
|
21
|
-
this.
|
|
22
|
-
this.baseUrl = baseUrl;
|
|
16
|
+
constructor(client) {
|
|
17
|
+
this.client = client;
|
|
23
18
|
}
|
|
24
19
|
/**
|
|
25
|
-
* Fetches
|
|
26
|
-
* @param {string}
|
|
27
|
-
* @param {string} id - The ID of the
|
|
28
|
-
* @returns {Promise<
|
|
20
|
+
* Fetches a record by its ID.
|
|
21
|
+
* @param {string} tableName - The type of the record. (table name)
|
|
22
|
+
* @param {string} id - The ID of the record.
|
|
23
|
+
* @returns {Promise<TotalumApiResponse<T>>} - A promise that resolves to the record data.
|
|
29
24
|
*/
|
|
30
|
-
|
|
25
|
+
getRecordById(tableName, id) {
|
|
31
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
-
const url = utils_1.UtilsService.getUrl(
|
|
33
|
-
return
|
|
27
|
+
const url = utils_1.UtilsService.getUrl('', endpoints_1.endpoints.crud.getObjectById, { typeId: tableName, id });
|
|
28
|
+
return this.client.get(url);
|
|
34
29
|
});
|
|
35
30
|
}
|
|
36
31
|
/**
|
|
37
32
|
* Fetches the historic updates of a record by its ID.
|
|
38
33
|
* @param {string} recordId - The ID of the record to fetch the historic updates.
|
|
39
|
-
* @returns {Promise<
|
|
34
|
+
* @returns {Promise<TotalumApiResponse<UpdatesRecordResponse>>} - A promise that resolves to the historic updates data.
|
|
40
35
|
*/
|
|
41
36
|
getHistoricRecordUpdatesById(recordId) {
|
|
42
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
-
const url = utils_1.UtilsService.getUrl(
|
|
44
|
-
return
|
|
38
|
+
const url = utils_1.UtilsService.getUrl('', endpoints_1.endpoints.updatesRecord.getUpdateRecordByObjectId, { objectId: recordId });
|
|
39
|
+
return this.client.get(url);
|
|
45
40
|
});
|
|
46
41
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Fetches records with optional filtering, sorting, and pagination.
|
|
44
|
+
* The response data is an array of records. If returnCount is true, a metadata object with count is also returned.
|
|
45
|
+
* @param {string} tableName - The type of the record. (table name)
|
|
46
|
+
* @param {FilterSearchQueryI} query - Optional query parameters for filtering.
|
|
47
|
+
* @returns {Promise<TotalumApiResponse<T[]>>} - A promise that resolves to an array of records.
|
|
48
|
+
*/
|
|
49
|
+
getRecords(tableName, query) {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
const url = utils_1.UtilsService.getUrl('', endpoints_1.endpoints.crud.getObjects, { typeId: tableName });
|
|
52
|
+
return this.client.post(url, query);
|
|
53
|
+
});
|
|
50
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Fetches nested data across related tables.
|
|
57
|
+
* @param {NestedQuery} nestedQuery - The nested query structure.
|
|
58
|
+
* @param {any} options - Optional configuration.
|
|
59
|
+
* @returns {Promise<TotalumApiResponse<T[]>>} - A promise that resolves to nested data array.
|
|
60
|
+
*/
|
|
51
61
|
getNestedData(nestedQuery, options) {
|
|
52
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
-
const url = utils_1.UtilsService.getUrl(
|
|
54
|
-
return
|
|
63
|
+
const url = utils_1.UtilsService.getUrl('', endpoints_1.endpoints.crud.getNestedData);
|
|
64
|
+
return this.client.post(url, { nestedQuery: nestedQuery, options: options });
|
|
55
65
|
});
|
|
56
66
|
}
|
|
57
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Deletes a record by its ID.
|
|
69
|
+
* @param {string} tableName - The type of the record. (table name)
|
|
70
|
+
* @param {string} id - The ID of the record.
|
|
71
|
+
* @returns {Promise<TotalumApiResponse<DeleteObjectResponse>>} - A promise that resolves when deletion is complete.
|
|
72
|
+
*/
|
|
73
|
+
deleteRecordById(tableName, id) {
|
|
58
74
|
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
-
const url = utils_1.UtilsService.getUrl(
|
|
60
|
-
return
|
|
75
|
+
const url = utils_1.UtilsService.getUrl('', endpoints_1.endpoints.crud.deleteObject, { typeId: tableName, id });
|
|
76
|
+
return this.client.delete(url);
|
|
61
77
|
});
|
|
62
78
|
}
|
|
63
|
-
|
|
79
|
+
/**
|
|
80
|
+
* Edits a record by its ID.
|
|
81
|
+
* @param {string} tableName - The type of the record. (table name)
|
|
82
|
+
* @param {string} id - The ID of the record.
|
|
83
|
+
* @param {T} properties - The properties to update.
|
|
84
|
+
* @returns {Promise<TotalumApiResponse<UpdatedRecordResponse>>} - A promise that resolves to the updated record.
|
|
85
|
+
*/
|
|
86
|
+
editRecordById(tableName, id, properties) {
|
|
64
87
|
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
-
const url = utils_1.UtilsService.getUrl(
|
|
66
|
-
return
|
|
88
|
+
const url = utils_1.UtilsService.getUrl('', endpoints_1.endpoints.crud.editObjectProperties, { typeId: tableName, id });
|
|
89
|
+
return this.client.patch(url, properties);
|
|
67
90
|
});
|
|
68
91
|
}
|
|
69
|
-
|
|
92
|
+
/**
|
|
93
|
+
* Creates a new record.
|
|
94
|
+
* @param {string} tableName - The type of the record. (table name)
|
|
95
|
+
* @param {T} record - The record data to create.
|
|
96
|
+
* @returns {Promise<TotalumApiResponse<T>>} - A promise that resolves to the created record.
|
|
97
|
+
*/
|
|
98
|
+
createRecord(tableName, record) {
|
|
70
99
|
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
-
const url = utils_1.UtilsService.getUrl(
|
|
72
|
-
return
|
|
100
|
+
const url = utils_1.UtilsService.getUrl('', endpoints_1.endpoints.crud.createObject, { typeId: tableName });
|
|
101
|
+
return this.client.post(url, record);
|
|
73
102
|
});
|
|
74
103
|
}
|
|
75
|
-
// many to many functions
|
|
104
|
+
// many to many functions
|
|
76
105
|
/**
|
|
77
|
-
*
|
|
78
|
-
* @param
|
|
79
|
-
* @param id
|
|
80
|
-
* @param
|
|
81
|
-
* @param referenceId
|
|
106
|
+
* Adds a many-to-many reference between records.
|
|
107
|
+
* @param {string} type - The type id of the record (table name)
|
|
108
|
+
* @param {string} id - The id of the record that we want to add a many to many reference
|
|
109
|
+
* @param {string} propertyName - The property that we want to add a many to many reference
|
|
110
|
+
* @param {string} referenceId - The id of the record that we want to add as a many to many reference
|
|
111
|
+
* @returns {Promise<TotalumApiResponse<CreateRecordResponse>>}
|
|
82
112
|
*/
|
|
83
|
-
|
|
113
|
+
addManyToManyReferenceRecord(type, id, propertyName, referenceId) {
|
|
84
114
|
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
-
const url = utils_1.UtilsService.getUrl(
|
|
86
|
-
return
|
|
115
|
+
const url = utils_1.UtilsService.getUrl('', endpoints_1.endpoints.crud.addManyToManyReference, { typeId: type, id });
|
|
116
|
+
return this.client.patch(url, { propertyId: propertyName, referenceId });
|
|
87
117
|
});
|
|
88
118
|
}
|
|
89
119
|
/**
|
|
90
|
-
*
|
|
91
|
-
* @param
|
|
92
|
-
* @param id
|
|
93
|
-
* @param
|
|
94
|
-
* @param referenceId
|
|
120
|
+
* Drops a many-to-many reference between records.
|
|
121
|
+
* @param {string} type - The type id of the record (table name)
|
|
122
|
+
* @param {string} id - The id of the record that we want to drop a many to many reference
|
|
123
|
+
* @param {string} propertyName - The property that we want to drop a many to many reference
|
|
124
|
+
* @param {string} referenceId - The id of the record that we want to drop as a many to many reference
|
|
125
|
+
* @returns {Promise<TotalumApiResponse<DeleteObjectResponse>>}
|
|
95
126
|
*/
|
|
96
|
-
|
|
127
|
+
dropManyToManyReferenceRecord(type, id, propertyName, referenceId) {
|
|
97
128
|
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
-
const url = utils_1.UtilsService.getUrl(
|
|
99
|
-
return
|
|
129
|
+
const url = utils_1.UtilsService.getUrl('', endpoints_1.endpoints.crud.dropManyToManyReference, { typeId: type, id });
|
|
130
|
+
return this.client.patch(url, { propertyId: propertyName, referenceId });
|
|
100
131
|
});
|
|
101
132
|
}
|
|
102
133
|
/**
|
|
103
|
-
*
|
|
104
|
-
* @param
|
|
105
|
-
* @param id
|
|
106
|
-
* @param propertyName
|
|
107
|
-
* @param query
|
|
134
|
+
* Gets many-to-many reference records with optional filtering.
|
|
135
|
+
* @param {string} type - The type id of the record (table name)
|
|
136
|
+
* @param {string} id - The id of the record that we want to get many to many references
|
|
137
|
+
* @param {string} propertyName - The property that we want to get many to many references
|
|
138
|
+
* @param {FilterSearchQueryI} query - The query to filter and sort the results
|
|
139
|
+
* @returns {Promise<TotalumApiResponse<T[]>>}
|
|
108
140
|
*/
|
|
109
|
-
|
|
141
|
+
getManyToManyReferencesRecords(type, id, propertyName, query) {
|
|
110
142
|
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
-
const url = utils_1.UtilsService.getUrl(
|
|
112
|
-
return
|
|
143
|
+
const url = utils_1.UtilsService.getUrl('', endpoints_1.endpoints.crud.getManyToManyReferencesItems, { typeId: type, id, propertyName });
|
|
144
|
+
return this.client.get(url, query);
|
|
113
145
|
});
|
|
114
146
|
}
|
|
115
147
|
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { TotalumApiResponse } from "../common/interfaces";
|
|
2
|
+
import { EmailSendResponse } from "../common/response-types";
|
|
3
|
+
import { FetchClient } from "../common/fetch-client";
|
|
1
4
|
export interface EmailPayloadI {
|
|
2
5
|
to: string[];
|
|
3
6
|
subject: string;
|
|
@@ -13,21 +16,20 @@ export interface EmailPayloadI {
|
|
|
13
16
|
}[];
|
|
14
17
|
}
|
|
15
18
|
export declare class EmailService {
|
|
16
|
-
private
|
|
17
|
-
|
|
18
|
-
constructor(baseUrl: string, headers: any);
|
|
19
|
+
private client;
|
|
20
|
+
constructor(client: FetchClient);
|
|
19
21
|
/**
|
|
20
22
|
* Sends an email with custom validation and attachment processing.
|
|
21
23
|
* All attachments must be provided as URLs.
|
|
22
24
|
* Maximum 10 attachments, each up to 15MB.
|
|
23
25
|
* @param {EmailPayloadI} emailPayload - The email configuration.
|
|
24
|
-
* @returns {Promise<
|
|
26
|
+
* @returns {Promise<TotalumApiResponse<EmailSendResponse>>} - A promise that resolves to the email send response.
|
|
25
27
|
*/
|
|
26
|
-
sendEmail(emailPayload: EmailPayloadI): Promise<
|
|
28
|
+
sendEmail(emailPayload: EmailPayloadI): Promise<TotalumApiResponse<EmailSendResponse>>;
|
|
27
29
|
/**
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
* Sends an email using the Resend service with the default domain.
|
|
31
|
+
* @param {EmailPayloadI} emailPayload - The email configuration including recipients, subject, content, etc.
|
|
32
|
+
* @returns {Promise<TotalumApiResponse<EmailSendResponse>>} - A promise that resolves to the email send response.
|
|
33
|
+
*/
|
|
32
34
|
private sendEmailWithDefaultDomain;
|
|
33
35
|
}
|
|
@@ -8,40 +8,50 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
12
|
exports.EmailService = void 0;
|
|
16
|
-
const axios_1 = __importDefault(require("axios"));
|
|
17
13
|
const endpoints_1 = require("../common/endpoints");
|
|
18
14
|
const utils_1 = require("../utils");
|
|
19
15
|
class EmailService {
|
|
20
|
-
constructor(
|
|
21
|
-
this.
|
|
22
|
-
this.baseUrl = baseUrl;
|
|
16
|
+
constructor(client) {
|
|
17
|
+
this.client = client;
|
|
23
18
|
}
|
|
24
19
|
/**
|
|
25
20
|
* Sends an email with custom validation and attachment processing.
|
|
26
21
|
* All attachments must be provided as URLs.
|
|
27
22
|
* Maximum 10 attachments, each up to 15MB.
|
|
28
23
|
* @param {EmailPayloadI} emailPayload - The email configuration.
|
|
29
|
-
* @returns {Promise<
|
|
24
|
+
* @returns {Promise<TotalumApiResponse<EmailSendResponse>>} - A promise that resolves to the email send response.
|
|
30
25
|
*/
|
|
31
26
|
sendEmail(emailPayload) {
|
|
32
27
|
return __awaiter(this, void 0, void 0, function* () {
|
|
33
28
|
// Validate attachments count
|
|
34
29
|
if (emailPayload.attachments && emailPayload.attachments.length > 10) {
|
|
35
|
-
|
|
30
|
+
return {
|
|
31
|
+
errors: {
|
|
32
|
+
errorCode: 'TOO_MANY_ATTACHMENTS',
|
|
33
|
+
errorMessage: `Maximum number of attachments is 10. Received ${emailPayload.attachments.length}.`
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
36
|
}
|
|
37
37
|
// Validate attachment URLs
|
|
38
38
|
if (emailPayload.attachments) {
|
|
39
39
|
for (const attachment of emailPayload.attachments) {
|
|
40
40
|
if (!attachment.url || typeof attachment.url !== 'string') {
|
|
41
|
-
|
|
41
|
+
return {
|
|
42
|
+
errors: {
|
|
43
|
+
errorCode: 'INVALID_ATTACHMENT_URL',
|
|
44
|
+
errorMessage: `Attachment ${attachment.filename} must have a valid URL`
|
|
45
|
+
}
|
|
46
|
+
};
|
|
42
47
|
}
|
|
43
48
|
if (!attachment.url.startsWith('http://') && !attachment.url.startsWith('https://')) {
|
|
44
|
-
|
|
49
|
+
return {
|
|
50
|
+
errors: {
|
|
51
|
+
errorCode: 'INVALID_ATTACHMENT_URL',
|
|
52
|
+
errorMessage: `Attachment ${attachment.filename} must have a valid HTTP/HTTPS URL`
|
|
53
|
+
}
|
|
54
|
+
};
|
|
45
55
|
}
|
|
46
56
|
}
|
|
47
57
|
}
|
|
@@ -49,14 +59,14 @@ class EmailService {
|
|
|
49
59
|
});
|
|
50
60
|
}
|
|
51
61
|
/**
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
62
|
+
* Sends an email using the Resend service with the default domain.
|
|
63
|
+
* @param {EmailPayloadI} emailPayload - The email configuration including recipients, subject, content, etc.
|
|
64
|
+
* @returns {Promise<TotalumApiResponse<EmailSendResponse>>} - A promise that resolves to the email send response.
|
|
65
|
+
*/
|
|
56
66
|
sendEmailWithDefaultDomain(emailPayload) {
|
|
57
67
|
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
-
const url = utils_1.UtilsService.getUrl(
|
|
59
|
-
return
|
|
68
|
+
const url = utils_1.UtilsService.getUrl('', endpoints_1.endpoints.email.sendEmail, {});
|
|
69
|
+
return this.client.post(url, emailPayload);
|
|
60
70
|
});
|
|
61
71
|
}
|
|
62
72
|
}
|
|
@@ -1,37 +1,83 @@
|
|
|
1
|
+
import { TotalumApiResponse } from "../common/interfaces";
|
|
2
|
+
import { FileDeleteResponse, OcrImageResponse, OcrPdfResponse, ScanInvoiceResponse, ScanDocumentResponse } from "../common/response-types";
|
|
3
|
+
import { FetchClient } from "../common/fetch-client";
|
|
1
4
|
export declare class FilesService {
|
|
2
|
-
private
|
|
3
|
-
|
|
4
|
-
constructor(baseUrl: string, headers: any);
|
|
5
|
+
private client;
|
|
6
|
+
constructor(client: FetchClient);
|
|
5
7
|
/**
|
|
6
|
-
*
|
|
7
|
-
* @param fileFormData
|
|
8
|
+
* Uploads a file to Totalum.
|
|
9
|
+
* @param {FormData} fileFormData - The form data containing the file to upload
|
|
10
|
+
* @param {object} options - Optional upload options
|
|
11
|
+
* @param {boolean} options.compressFile - Whether to compress the file
|
|
12
|
+
* @returns {Promise<TotalumApiResponse<string>>} - File name ID
|
|
8
13
|
*/
|
|
9
|
-
uploadFile(fileFormData:
|
|
14
|
+
uploadFile(fileFormData: FormData, options?: {
|
|
10
15
|
compressFile?: boolean;
|
|
11
|
-
}): Promise<
|
|
16
|
+
}): Promise<TotalumApiResponse<string>>;
|
|
12
17
|
/**
|
|
13
|
-
*
|
|
14
|
-
* @param fileName
|
|
18
|
+
* Deletes a file from Totalum.
|
|
19
|
+
* @param {string} fileName - The name of the file to delete
|
|
20
|
+
* @returns {Promise<TotalumApiResponse<FileDeleteResponse>>}
|
|
15
21
|
*/
|
|
16
|
-
deleteFile(fileName: string): Promise<
|
|
22
|
+
deleteFile(fileName: string): Promise<TotalumApiResponse<FileDeleteResponse>>;
|
|
17
23
|
/**
|
|
18
|
-
*
|
|
19
|
-
* @param fileName
|
|
20
|
-
* @param
|
|
21
|
-
* @
|
|
24
|
+
* Gets a signed download URL for a file.
|
|
25
|
+
* @param {string} fileName - The name of the file
|
|
26
|
+
* @param {object} options - Optional configuration
|
|
27
|
+
* @param {number} options.expirationTime - Expiration time in milliseconds (default: 128 hours)
|
|
28
|
+
* @returns {Promise<TotalumApiResponse<string>>} - The download URL
|
|
22
29
|
*/
|
|
23
30
|
getDownloadUrl(fileName: string, options?: {
|
|
24
31
|
expirationTime?: number;
|
|
25
|
-
}): Promise<
|
|
32
|
+
}): Promise<TotalumApiResponse<string>>;
|
|
33
|
+
/**
|
|
34
|
+
* Generates a PDF from a template.
|
|
35
|
+
* @param {string} id - Template ID
|
|
36
|
+
* @param {Record<string, any>} variables - Variables to replace in template
|
|
37
|
+
* @param {string} name - Name for the generated PDF
|
|
38
|
+
* @returns {Promise<TotalumApiResponse<string>>} - The generated PDF filename
|
|
39
|
+
*/
|
|
26
40
|
generatePdfByTemplate(id: string, variables: {
|
|
27
41
|
[variableName: string]: any;
|
|
28
|
-
}, name: string): Promise<
|
|
42
|
+
}, name: string): Promise<TotalumApiResponse<string>>;
|
|
43
|
+
/**
|
|
44
|
+
* Creates a PDF from HTML content.
|
|
45
|
+
* @param {object} data - PDF creation data
|
|
46
|
+
* @param {string} data.html - HTML content to convert
|
|
47
|
+
* @param {string} data.name - Name for the generated PDF
|
|
48
|
+
* @returns {Promise<TotalumApiResponse<string>>} - The generated PDF filename
|
|
49
|
+
*/
|
|
29
50
|
createPdfFromHtml(data: {
|
|
30
51
|
html: string;
|
|
31
52
|
name: string;
|
|
32
|
-
}): Promise<
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
53
|
+
}): Promise<TotalumApiResponse<string>>;
|
|
54
|
+
/**
|
|
55
|
+
* Performs OCR on an image file.
|
|
56
|
+
* @param {string} fileName - The file name of the uploaded image
|
|
57
|
+
* @returns {Promise<TotalumApiResponse<OcrImageResponse>>}
|
|
58
|
+
*/
|
|
59
|
+
ocrOfImage(fileName: string): Promise<TotalumApiResponse<OcrImageResponse>>;
|
|
60
|
+
/**
|
|
61
|
+
* Performs OCR on a PDF file.
|
|
62
|
+
* @param {string} fileName - The file name of the uploaded PDF
|
|
63
|
+
* @returns {Promise<TotalumApiResponse<OcrPdfResponse>>}
|
|
64
|
+
*/
|
|
65
|
+
ocrOfPdf(fileName: string): Promise<TotalumApiResponse<OcrPdfResponse>>;
|
|
66
|
+
/**
|
|
67
|
+
* Scans an invoice and extracts information.
|
|
68
|
+
* The response includes both data and metadata with OCR details and usage tracking.
|
|
69
|
+
* @param {string} fileName - The file name of the uploaded invoice
|
|
70
|
+
* @param {any} options - Optional scanning options
|
|
71
|
+
* @returns {Promise<TotalumApiResponse<ScanInvoiceResponse>>}
|
|
72
|
+
*/
|
|
73
|
+
scanInvoice(fileName: string, options?: any): Promise<TotalumApiResponse<ScanInvoiceResponse>>;
|
|
74
|
+
/**
|
|
75
|
+
* Scans a document and extracts specified properties.
|
|
76
|
+
* The response includes both data (based on provided schema) and metadata with OCR details.
|
|
77
|
+
* @param {string} fileName - The file name of the uploaded document
|
|
78
|
+
* @param {any} properties - Properties schema to extract from the document (JSON Schema format)
|
|
79
|
+
* @param {any} options - Optional scanning options
|
|
80
|
+
* @returns {Promise<TotalumApiResponse<ScanDocumentResponse>>}
|
|
81
|
+
*/
|
|
82
|
+
scanDocument(fileName: string, properties: any, options?: any): Promise<TotalumApiResponse<ScanDocumentResponse>>;
|
|
37
83
|
}
|
|
@@ -8,89 +8,136 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
12
|
exports.FilesService = void 0;
|
|
16
|
-
const axios_1 = __importDefault(require("axios"));
|
|
17
13
|
const utils_1 = require("../utils");
|
|
18
14
|
const endpoints_1 = require("../common/endpoints");
|
|
19
15
|
class FilesService {
|
|
20
|
-
constructor(
|
|
21
|
-
this.
|
|
22
|
-
this.baseUrl = baseUrl;
|
|
16
|
+
constructor(client) {
|
|
17
|
+
this.client = client;
|
|
23
18
|
}
|
|
24
19
|
/**
|
|
25
|
-
*
|
|
26
|
-
* @param fileFormData
|
|
20
|
+
* Uploads a file to Totalum.
|
|
21
|
+
* @param {FormData} fileFormData - The form data containing the file to upload
|
|
22
|
+
* @param {object} options - Optional upload options
|
|
23
|
+
* @param {boolean} options.compressFile - Whether to compress the file
|
|
24
|
+
* @returns {Promise<TotalumApiResponse<string>>} - File name ID
|
|
27
25
|
*/
|
|
28
26
|
uploadFile(fileFormData, options) {
|
|
29
27
|
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
-
let url = utils_1.UtilsService.getUrl(
|
|
28
|
+
let url = utils_1.UtilsService.getUrl('', endpoints_1.endpoints.files.uploadFile);
|
|
31
29
|
if (options === null || options === void 0 ? void 0 : options.compressFile)
|
|
32
30
|
url += '?compressFile=true';
|
|
33
|
-
return
|
|
31
|
+
return this.client.post(url, fileFormData);
|
|
34
32
|
});
|
|
35
33
|
}
|
|
36
34
|
/**
|
|
37
|
-
*
|
|
38
|
-
* @param fileName
|
|
35
|
+
* Deletes a file from Totalum.
|
|
36
|
+
* @param {string} fileName - The name of the file to delete
|
|
37
|
+
* @returns {Promise<TotalumApiResponse<FileDeleteResponse>>}
|
|
39
38
|
*/
|
|
40
39
|
deleteFile(fileName) {
|
|
41
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
const url = utils_1.UtilsService.getUrl(
|
|
43
|
-
return
|
|
41
|
+
const url = utils_1.UtilsService.getUrl('', endpoints_1.endpoints.files.deleteFile, { fileName });
|
|
42
|
+
return this.client.delete(url);
|
|
44
43
|
});
|
|
45
44
|
}
|
|
46
45
|
/**
|
|
47
|
-
*
|
|
48
|
-
* @param fileName
|
|
49
|
-
* @param
|
|
50
|
-
* @
|
|
46
|
+
* Gets a signed download URL for a file.
|
|
47
|
+
* @param {string} fileName - The name of the file
|
|
48
|
+
* @param {object} options - Optional configuration
|
|
49
|
+
* @param {number} options.expirationTime - Expiration time in milliseconds (default: 128 hours)
|
|
50
|
+
* @returns {Promise<TotalumApiResponse<string>>} - The download URL
|
|
51
51
|
*/
|
|
52
52
|
getDownloadUrl(fileName, options) {
|
|
53
53
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
-
const url = utils_1.UtilsService.getUrl(
|
|
55
|
-
return
|
|
54
|
+
const url = utils_1.UtilsService.getUrl('', endpoints_1.endpoints.files.getDownloadUrl, { fileName });
|
|
55
|
+
return this.client.get(url, options);
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Generates a PDF from a template.
|
|
60
|
+
* @param {string} id - Template ID
|
|
61
|
+
* @param {Record<string, any>} variables - Variables to replace in template
|
|
62
|
+
* @param {string} name - Name for the generated PDF
|
|
63
|
+
* @returns {Promise<TotalumApiResponse<string>>} - The generated PDF filename
|
|
64
|
+
*/
|
|
58
65
|
generatePdfByTemplate(id, variables, name) {
|
|
59
66
|
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
-
const url = utils_1.UtilsService.getUrl(
|
|
61
|
-
return
|
|
67
|
+
const url = utils_1.UtilsService.getUrl('', endpoints_1.endpoints.pdfTemplate.generatePdfByTemplate, { id });
|
|
68
|
+
return this.client.post(url, { templateId: id, variables, name });
|
|
62
69
|
});
|
|
63
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Creates a PDF from HTML content.
|
|
73
|
+
* @param {object} data - PDF creation data
|
|
74
|
+
* @param {string} data.html - HTML content to convert
|
|
75
|
+
* @param {string} data.name - Name for the generated PDF
|
|
76
|
+
* @returns {Promise<TotalumApiResponse<string>>} - The generated PDF filename
|
|
77
|
+
*/
|
|
64
78
|
createPdfFromHtml(data) {
|
|
65
79
|
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
-
const url = utils_1.UtilsService.getUrl(
|
|
67
|
-
//
|
|
68
|
-
|
|
69
|
-
|
|
80
|
+
const url = utils_1.UtilsService.getUrl('', endpoints_1.endpoints.pdfTemplate.createPdfFromHtml);
|
|
81
|
+
// Cross-platform base64 encoding (works in both Node.js and browser)
|
|
82
|
+
let base64HtmlString;
|
|
83
|
+
if (typeof window === 'undefined') {
|
|
84
|
+
// Node.js environment
|
|
85
|
+
base64HtmlString = Buffer.from(data.html, 'utf-8').toString('base64');
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
// Browser environment
|
|
89
|
+
base64HtmlString = btoa(unescape(encodeURIComponent(data.html)));
|
|
90
|
+
}
|
|
91
|
+
return this.client.post(url, { base64HtmlString, name: data.name });
|
|
70
92
|
});
|
|
71
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Performs OCR on an image file.
|
|
96
|
+
* @param {string} fileName - The file name of the uploaded image
|
|
97
|
+
* @returns {Promise<TotalumApiResponse<OcrImageResponse>>}
|
|
98
|
+
*/
|
|
72
99
|
ocrOfImage(fileName) {
|
|
73
100
|
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
-
const url = utils_1.UtilsService.getUrl(
|
|
75
|
-
return
|
|
101
|
+
const url = utils_1.UtilsService.getUrl('', endpoints_1.endpoints.files.ocrOfImage);
|
|
102
|
+
return this.client.post(url, { fileName });
|
|
76
103
|
});
|
|
77
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Performs OCR on a PDF file.
|
|
107
|
+
* @param {string} fileName - The file name of the uploaded PDF
|
|
108
|
+
* @returns {Promise<TotalumApiResponse<OcrPdfResponse>>}
|
|
109
|
+
*/
|
|
78
110
|
ocrOfPdf(fileName) {
|
|
79
111
|
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
-
const url = utils_1.UtilsService.getUrl(
|
|
81
|
-
return
|
|
112
|
+
const url = utils_1.UtilsService.getUrl('', endpoints_1.endpoints.files.ocrOfPdf);
|
|
113
|
+
return this.client.post(url, { fileName });
|
|
82
114
|
});
|
|
83
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Scans an invoice and extracts information.
|
|
118
|
+
* The response includes both data and metadata with OCR details and usage tracking.
|
|
119
|
+
* @param {string} fileName - The file name of the uploaded invoice
|
|
120
|
+
* @param {any} options - Optional scanning options
|
|
121
|
+
* @returns {Promise<TotalumApiResponse<ScanInvoiceResponse>>}
|
|
122
|
+
*/
|
|
84
123
|
scanInvoice(fileName, options) {
|
|
85
124
|
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
-
const url = utils_1.UtilsService.getUrl(
|
|
87
|
-
return
|
|
125
|
+
const url = utils_1.UtilsService.getUrl('', endpoints_1.endpoints.files.scanInvoice);
|
|
126
|
+
return this.client.post(url, { fileName, options });
|
|
88
127
|
});
|
|
89
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* Scans a document and extracts specified properties.
|
|
131
|
+
* The response includes both data (based on provided schema) and metadata with OCR details.
|
|
132
|
+
* @param {string} fileName - The file name of the uploaded document
|
|
133
|
+
* @param {any} properties - Properties schema to extract from the document (JSON Schema format)
|
|
134
|
+
* @param {any} options - Optional scanning options
|
|
135
|
+
* @returns {Promise<TotalumApiResponse<ScanDocumentResponse>>}
|
|
136
|
+
*/
|
|
90
137
|
scanDocument(fileName, properties, options) {
|
|
91
138
|
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
-
const url = utils_1.UtilsService.getUrl(
|
|
93
|
-
return
|
|
139
|
+
const url = utils_1.UtilsService.getUrl('', endpoints_1.endpoints.files.scanDocument);
|
|
140
|
+
return this.client.post(url, { fileName, properties, options });
|
|
94
141
|
});
|
|
95
142
|
}
|
|
96
143
|
}
|