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.
@@ -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(baseUrl, headers) {
21
- this.headers = headers;
22
- this.baseUrl = baseUrl;
16
+ constructor(client) {
17
+ this.client = client;
23
18
  }
24
19
  /**
25
- * Fetches an item by its ID.
26
- * @param {string} itemType - The type of the item. (table name)
27
- * @param {string} id - The ID of the item.
28
- * @returns {Promise<any>} - A promise that resolves to the item data.
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
- getItemById(itemType, id) {
25
+ getRecordById(tableName, id) {
31
26
  return __awaiter(this, void 0, void 0, function* () {
32
- const url = utils_1.UtilsService.getUrl(this.baseUrl, endpoints_1.endpoints.crud.getObjectById, { typeId: itemType, id });
33
- return axios_1.default.get(url, { headers: this.headers });
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<any>} - A promise that resolves to the historic updates data.
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(this.baseUrl, endpoints_1.endpoints.updatesRecord.getUpdateRecordByObjectId, { objectId: recordId });
44
- return axios_1.default.get(url, { headers: this.headers });
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
- getItems(itemType, query) {
48
- const url = utils_1.UtilsService.getUrl(this.baseUrl, endpoints_1.endpoints.crud.getObjects, { typeId: itemType });
49
- return axios_1.default.post(url, query, { headers: this.headers });
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(this.baseUrl, endpoints_1.endpoints.crud.getNestedData);
54
- return axios_1.default.post(url, { nestedQuery: nestedQuery, options: options }, { headers: this.headers });
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
- deleteItemById(itemType, id) {
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(this.baseUrl, endpoints_1.endpoints.crud.deleteObject, { typeId: itemType, id });
60
- return axios_1.default.delete(url, { headers: this.headers });
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
- editItemById(itemType, id, properties) {
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(this.baseUrl, endpoints_1.endpoints.crud.editObjectProperties, { typeId: itemType, id });
66
- return axios_1.default.patch(url, properties, { headers: this.headers });
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
- createItem(itemType, item) {
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(this.baseUrl, endpoints_1.endpoints.crud.createObject, { typeId: itemType });
72
- return axios_1.default.post(url, item, { headers: this.headers });
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 typeId the type id of the item (table name)
79
- * @param id the id of the item that we want to add a many to many reference
80
- * @param propertyId the property that we want to add a many to many reference
81
- * @param referenceId the id of the item that we want to add as a many to many reference
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
- addManyToManyReferenceItem(type, id, propertyName, referenceId) {
113
+ addManyToManyReferenceRecord(type, id, propertyName, referenceId) {
84
114
  return __awaiter(this, void 0, void 0, function* () {
85
- const url = utils_1.UtilsService.getUrl(this.baseUrl, endpoints_1.endpoints.crud.addManyToManyReference, { typeId: type, id });
86
- return axios_1.default.patch(url, { propertyId: propertyName, referenceId }, { headers: this.headers });
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 typeId the type id of the item (table name)
92
- * @param id the id of the item that we want to drop a many to many reference
93
- * @param propertyId the property that we want to drop a many to many reference
94
- * @param referenceId the id of the item that we want to drop as a many to many reference
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
- dropManyToManyReferenceItem(type, id, propertyName, referenceId) {
127
+ dropManyToManyReferenceRecord(type, id, propertyName, referenceId) {
97
128
  return __awaiter(this, void 0, void 0, function* () {
98
- const url = utils_1.UtilsService.getUrl(this.baseUrl, endpoints_1.endpoints.crud.dropManyToManyReference, { typeId: type, id });
99
- return axios_1.default.patch(url, { propertyId: propertyName, referenceId }, { headers: this.headers });
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 typeId the type id of the item (table name)
105
- * @param id the id of the item that we want to get many to many references
106
- * @param propertyName the property that we want to get many to many references
107
- * @param query the query to filter and sort the results
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
- getManyToManyReferencesItems(type, id, propertyName, query) {
141
+ getManyToManyReferencesRecords(type, id, propertyName, query) {
110
142
  return __awaiter(this, void 0, void 0, function* () {
111
- const url = utils_1.UtilsService.getUrl(this.baseUrl, endpoints_1.endpoints.crud.getManyToManyReferencesItems, { typeId: type, id, propertyName });
112
- return axios_1.default.get(url, { params: query, headers: this.headers });
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 headers;
17
- private baseUrl;
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<any>} - A promise that resolves to the email send response.
26
+ * @returns {Promise<TotalumApiResponse<EmailSendResponse>>} - A promise that resolves to the email send response.
25
27
  */
26
- sendEmail(emailPayload: EmailPayloadI): Promise<any>;
28
+ sendEmail(emailPayload: EmailPayloadI): Promise<TotalumApiResponse<EmailSendResponse>>;
27
29
  /**
28
- * Sends an email using the Resend service with the default domain.
29
- * @param {EmailPayloadI} emailPayload - The email configuration including recipients, subject, content, etc.
30
- * @returns {Promise<any>} - A promise that resolves to the email send response.
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(baseUrl, headers) {
21
- this.headers = headers;
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<any>} - A promise that resolves to the email send response.
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
- throw new Error(`Maximum number of attachments is 10. Received ${emailPayload.attachments.length}.`);
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
- throw new Error(`Attachment ${attachment.filename} must have a valid URL`);
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
- throw new Error(`Attachment ${attachment.filename} must have a valid HTTP/HTTPS URL`);
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
- * Sends an email using the Resend service with the default domain.
53
- * @param {EmailPayloadI} emailPayload - The email configuration including recipients, subject, content, etc.
54
- * @returns {Promise<any>} - A promise that resolves to the email send response.
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(this.baseUrl, endpoints_1.endpoints.email.sendEmail, {});
59
- return axios_1.default.post(url, emailPayload, { headers: this.headers });
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 headers;
3
- private baseUrl;
4
- constructor(baseUrl: string, headers: any);
5
+ private client;
6
+ constructor(client: FetchClient);
5
7
  /**
6
- *
7
- * @param fileFormData the form data of the file to upload
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: any, options?: {
14
+ uploadFile(fileFormData: FormData, options?: {
10
15
  compressFile?: boolean;
11
- }): Promise<import("axios").AxiosResponse<any, any>>;
16
+ }): Promise<TotalumApiResponse<string>>;
12
17
  /**
13
- *
14
- * @param fileName the name of the file to delete
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<import("axios").AxiosResponse<any, any>>;
22
+ deleteFile(fileName: string): Promise<TotalumApiResponse<FileDeleteResponse>>;
17
23
  /**
18
- *
19
- * @param fileName
20
- * @param options options.expirationTime - is the time in milliseconds that the signed URL should be valid for. The default is 128 hours
21
- * @returns
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<import("axios").AxiosResponse<any, any>>;
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<import("axios").AxiosResponse<any, any>>;
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<import("axios").AxiosResponse<any, any>>;
33
- ocrOfImage(fileName: string): Promise<import("axios").AxiosResponse<any, any>>;
34
- ocrOfPdf(fileName: string): Promise<import("axios").AxiosResponse<any, any>>;
35
- scanInvoice(fileName: string, options?: any): Promise<import("axios").AxiosResponse<any, any>>;
36
- scanDocument(fileName: string, properties: any, options?: any): Promise<import("axios").AxiosResponse<any, any>>;
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(baseUrl, headers) {
21
- this.headers = headers;
22
- this.baseUrl = baseUrl;
16
+ constructor(client) {
17
+ this.client = client;
23
18
  }
24
19
  /**
25
- *
26
- * @param fileFormData the form data of the file to upload
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(this.baseUrl, endpoints_1.endpoints.files.uploadFile);
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 axios_1.default.post(url, fileFormData, { headers: this.headers });
31
+ return this.client.post(url, fileFormData);
34
32
  });
35
33
  }
36
34
  /**
37
- *
38
- * @param fileName the name of the file to delete
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(this.baseUrl, endpoints_1.endpoints.files.deleteFile, { fileName });
43
- return axios_1.default.delete(url, { headers: this.headers });
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 options options.expirationTime - is the time in milliseconds that the signed URL should be valid for. The default is 128 hours
50
- * @returns
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(this.baseUrl, endpoints_1.endpoints.files.getDownloadUrl, { fileName });
55
- return axios_1.default.get(url, { headers: this.headers, params: options });
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(this.baseUrl, endpoints_1.endpoints.pdfTemplate.generatePdfByTemplate, { id });
61
- return axios_1.default.post(url, { templateId: id, variables, name }, { headers: this.headers });
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(this.baseUrl, endpoints_1.endpoints.pdfTemplate.createPdfFromHtml);
67
- // Encode HTML to base64
68
- const base64HtmlString = Buffer.from(data.html, 'utf-8').toString('base64');
69
- return axios_1.default.post(url, { base64HtmlString, name: data.name }, { headers: this.headers });
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(this.baseUrl, endpoints_1.endpoints.files.ocrOfImage);
75
- return axios_1.default.post(url, { fileName }, { headers: this.headers });
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(this.baseUrl, endpoints_1.endpoints.files.ocrOfPdf);
81
- return axios_1.default.post(url, { fileName }, { headers: this.headers });
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(this.baseUrl, endpoints_1.endpoints.files.scanInvoice);
87
- return axios_1.default.post(url, { fileName, options }, { headers: this.headers });
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(this.baseUrl, endpoints_1.endpoints.files.scanDocument);
93
- return axios_1.default.post(url, { fileName, properties, options }, { headers: this.headers });
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
  }