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
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { TotalumApiResponse, TotalumHeaders, ErrorResult } from './interfaces';
|
|
2
|
+
export declare class TotalumError extends Error {
|
|
3
|
+
errorCode: string;
|
|
4
|
+
errorMessage: string;
|
|
5
|
+
hasManyErrors?: boolean;
|
|
6
|
+
multipleErrors?: {
|
|
7
|
+
errorCode: string;
|
|
8
|
+
errorMessage: string;
|
|
9
|
+
}[];
|
|
10
|
+
constructor(errorResult: ErrorResult);
|
|
11
|
+
toJSON(): ErrorResult;
|
|
12
|
+
}
|
|
13
|
+
export declare class FetchClient {
|
|
14
|
+
private baseUrl;
|
|
15
|
+
private headers;
|
|
16
|
+
constructor(baseUrl: string, headers: TotalumHeaders);
|
|
17
|
+
private handleResponse;
|
|
18
|
+
request<T>(endpoint: string, options?: RequestInit): Promise<TotalumApiResponse<T>>;
|
|
19
|
+
get<T>(endpoint: string, params?: Record<string, any>): Promise<TotalumApiResponse<T>>;
|
|
20
|
+
post<T>(endpoint: string, body?: any): Promise<TotalumApiResponse<T>>;
|
|
21
|
+
patch<T>(endpoint: string, body?: any): Promise<TotalumApiResponse<T>>;
|
|
22
|
+
delete<T>(endpoint: string): Promise<TotalumApiResponse<T>>;
|
|
23
|
+
put<T>(endpoint: string, body?: any): Promise<TotalumApiResponse<T>>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.FetchClient = exports.TotalumError = void 0;
|
|
13
|
+
class TotalumError extends Error {
|
|
14
|
+
constructor(errorResult) {
|
|
15
|
+
super(errorResult.errorMessage);
|
|
16
|
+
this.errorCode = errorResult.errorCode;
|
|
17
|
+
this.errorMessage = errorResult.errorMessage;
|
|
18
|
+
this.hasManyErrors = errorResult.hasManyErrors || false;
|
|
19
|
+
this.multipleErrors = errorResult.multipleErrors || [];
|
|
20
|
+
this.name = 'TotalumError';
|
|
21
|
+
Object.setPrototypeOf(this, TotalumError.prototype);
|
|
22
|
+
}
|
|
23
|
+
toJSON() {
|
|
24
|
+
return {
|
|
25
|
+
errorCode: this.errorCode,
|
|
26
|
+
errorMessage: this.errorMessage,
|
|
27
|
+
hasManyErrors: this.hasManyErrors,
|
|
28
|
+
multipleErrors: this.multipleErrors
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.TotalumError = TotalumError;
|
|
33
|
+
class FetchClient {
|
|
34
|
+
constructor(baseUrl, headers) {
|
|
35
|
+
this.baseUrl = baseUrl;
|
|
36
|
+
this.headers = headers;
|
|
37
|
+
}
|
|
38
|
+
handleResponse(response) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
let jsonData;
|
|
41
|
+
try {
|
|
42
|
+
jsonData = yield response.json();
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
// If response is not JSON, return error structure
|
|
46
|
+
return {
|
|
47
|
+
errors: {
|
|
48
|
+
errorCode: 'RESPONSE_PARSE_ERROR',
|
|
49
|
+
errorMessage: `Failed to parse response: ${response.statusText}`
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
// Always return the API response structure {data, errors}
|
|
54
|
+
// Even on HTTP errors, the API returns this structure
|
|
55
|
+
return jsonData;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
request(endpoint, options) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
const url = this.baseUrl + endpoint;
|
|
61
|
+
try {
|
|
62
|
+
const response = yield fetch(url, Object.assign(Object.assign({}, options), { headers: Object.assign(Object.assign({}, this.headers), options === null || options === void 0 ? void 0 : options.headers) }));
|
|
63
|
+
return this.handleResponse(response);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
// Network error or fetch failed
|
|
67
|
+
return {
|
|
68
|
+
errors: {
|
|
69
|
+
errorCode: 'NETWORK_ERROR',
|
|
70
|
+
errorMessage: error instanceof Error ? error.message : 'Network request failed'
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
get(endpoint, params) {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
let url = endpoint;
|
|
79
|
+
if (params) {
|
|
80
|
+
const queryString = new URLSearchParams(Object.entries(params).reduce((acc, [key, value]) => {
|
|
81
|
+
if (value !== undefined && value !== null) {
|
|
82
|
+
acc[key] = String(value);
|
|
83
|
+
}
|
|
84
|
+
return acc;
|
|
85
|
+
}, {})).toString();
|
|
86
|
+
if (queryString) {
|
|
87
|
+
url += '?' + queryString;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return this.request(url, { method: 'GET' });
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
post(endpoint, body) {
|
|
94
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
const isFormData = body instanceof FormData;
|
|
96
|
+
return this.request(endpoint, {
|
|
97
|
+
method: 'POST',
|
|
98
|
+
headers: isFormData ? {} : { 'Content-Type': 'application/json' },
|
|
99
|
+
body: isFormData ? body : JSON.stringify(body),
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
patch(endpoint, body) {
|
|
104
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
+
return this.request(endpoint, {
|
|
106
|
+
method: 'PATCH',
|
|
107
|
+
headers: { 'Content-Type': 'application/json' },
|
|
108
|
+
body: JSON.stringify(body),
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
delete(endpoint) {
|
|
113
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
+
return this.request(endpoint, { method: 'DELETE' });
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
put(endpoint, body) {
|
|
118
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
119
|
+
return this.request(endpoint, {
|
|
120
|
+
method: 'PUT',
|
|
121
|
+
headers: { 'Content-Type': 'application/json' },
|
|
122
|
+
body: JSON.stringify(body),
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
exports.FetchClient = FetchClient;
|
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
export interface ErrorResult {
|
|
2
|
+
errorCode: string;
|
|
3
|
+
errorMessage: string;
|
|
4
|
+
hasManyErrors?: boolean;
|
|
5
|
+
multipleErrors?: {
|
|
6
|
+
errorCode: string;
|
|
7
|
+
errorMessage: string;
|
|
8
|
+
}[];
|
|
9
|
+
}
|
|
10
|
+
export interface TotalumApiResponse<T> {
|
|
11
|
+
data?: T;
|
|
12
|
+
errors?: ErrorResult | null;
|
|
13
|
+
}
|
|
1
14
|
export interface StructureLevels {
|
|
2
15
|
id: string;
|
|
3
16
|
typeId: string;
|
|
@@ -60,13 +73,15 @@ export interface PropertyQueryOptionsI {
|
|
|
60
73
|
lt?: number | Date;
|
|
61
74
|
ne?: number | Date | boolean | string;
|
|
62
75
|
}
|
|
63
|
-
export type fieldValuesEnabled =
|
|
76
|
+
export type fieldValuesEnabled = string | number | boolean | Date | fieldFileI | fieldFileI[];
|
|
77
|
+
export type FileTypesI = 'image' | 'video' | 'audio' | 'word' | 'pdf' | 'excel' | 'other';
|
|
78
|
+
export type fieldFileI = {
|
|
64
79
|
name: string;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
};
|
|
80
|
+
url: string;
|
|
81
|
+
type?: FileTypesI;
|
|
82
|
+
order?: number;
|
|
69
83
|
};
|
|
84
|
+
export type fieldTypesEnabled = 'string' | 'number' | 'boolean' | 'date' | 'options' | 'file' | 'long-string' | /*'array' |*/ 'objectReference';
|
|
70
85
|
export interface DataValues {
|
|
71
86
|
_id: string;
|
|
72
87
|
createdAt: Date;
|
|
@@ -88,6 +103,12 @@ export interface AuthOptions {
|
|
|
88
103
|
};
|
|
89
104
|
baseUrl?: string;
|
|
90
105
|
}
|
|
106
|
+
export interface TotalumHeaders {
|
|
107
|
+
authorization?: string;
|
|
108
|
+
'api-key'?: string;
|
|
109
|
+
fromEvent?: string;
|
|
110
|
+
[key: string]: string | undefined;
|
|
111
|
+
}
|
|
91
112
|
export interface NotificationI {
|
|
92
113
|
name: string;
|
|
93
114
|
title: string;
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { DataValues } from './interfaces';
|
|
2
|
+
export { DataValues };
|
|
3
|
+
/**
|
|
4
|
+
* Response metadata (optional, used in some endpoints)
|
|
5
|
+
*/
|
|
6
|
+
export interface ResponseMetadata {
|
|
7
|
+
count?: number;
|
|
8
|
+
ocrFullResult?: any;
|
|
9
|
+
ocrFullResultText?: string;
|
|
10
|
+
usageUnits?: number;
|
|
11
|
+
exactUsageUnits?: number;
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
}
|
|
14
|
+
export interface DeleteObjectResponse {
|
|
15
|
+
/** Indicates whether this write result was acknowledged. If not, then all other members of this result will be undefined. */
|
|
16
|
+
acknowledged: boolean;
|
|
17
|
+
/** The number of documents that were deleted */
|
|
18
|
+
deletedCount: number;
|
|
19
|
+
}
|
|
20
|
+
export interface GetObjectsResponse<T = DataValues> {
|
|
21
|
+
data: T[];
|
|
22
|
+
metadata?: {
|
|
23
|
+
count?: number;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export interface FileUploadResponse {
|
|
27
|
+
fileName: string;
|
|
28
|
+
}
|
|
29
|
+
export interface FileDownloadUrlResponse {
|
|
30
|
+
url: string;
|
|
31
|
+
}
|
|
32
|
+
export interface FileDeleteResponse {
|
|
33
|
+
success: boolean;
|
|
34
|
+
message?: string;
|
|
35
|
+
}
|
|
36
|
+
export interface OcrImageResponse {
|
|
37
|
+
text: string;
|
|
38
|
+
confidence?: number;
|
|
39
|
+
fullDetails?: any;
|
|
40
|
+
}
|
|
41
|
+
export interface OcrPdfResponse {
|
|
42
|
+
text: string;
|
|
43
|
+
pages?: Array<{
|
|
44
|
+
text: string;
|
|
45
|
+
pageNumber: number;
|
|
46
|
+
}>;
|
|
47
|
+
fullDetails?: any;
|
|
48
|
+
}
|
|
49
|
+
export interface InvoiceLineItem {
|
|
50
|
+
fullDescription: string;
|
|
51
|
+
productReference?: string;
|
|
52
|
+
quantity: number;
|
|
53
|
+
unitPrice?: number;
|
|
54
|
+
taxes: number;
|
|
55
|
+
total: number;
|
|
56
|
+
}
|
|
57
|
+
export interface ScanInvoiceData {
|
|
58
|
+
totalAmountIncludingTaxes: number;
|
|
59
|
+
totalAmountExcludingTaxes: number;
|
|
60
|
+
dateOfInvoice: string;
|
|
61
|
+
irpf: number;
|
|
62
|
+
iva: number;
|
|
63
|
+
complete_invoice_number: string;
|
|
64
|
+
currency: "EUR" | "USD" | "GBP" | "OTHER";
|
|
65
|
+
fullNameOfCompanyIssuingInvoice: string;
|
|
66
|
+
addressOfCompanyIssuingInvoice: string;
|
|
67
|
+
nif_cif: string;
|
|
68
|
+
postalCode: string;
|
|
69
|
+
city: string;
|
|
70
|
+
province: string;
|
|
71
|
+
country: string;
|
|
72
|
+
invoiceListItems?: InvoiceLineItem[];
|
|
73
|
+
extraFields?: {
|
|
74
|
+
[key: string]: any;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
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
|
+
export interface PdfGenerationResponse {
|
|
95
|
+
fileName: string;
|
|
96
|
+
}
|
|
97
|
+
export interface EmailSendResponse {
|
|
98
|
+
success: true;
|
|
99
|
+
message: string;
|
|
100
|
+
messageId: string;
|
|
101
|
+
data?: any;
|
|
102
|
+
}
|
|
103
|
+
export interface OpenAIUsage {
|
|
104
|
+
prompt_tokens: number;
|
|
105
|
+
completion_tokens: number;
|
|
106
|
+
total_tokens: number;
|
|
107
|
+
}
|
|
108
|
+
export interface OpenAICompletionChoice {
|
|
109
|
+
text: string;
|
|
110
|
+
index: number;
|
|
111
|
+
logprobs: any;
|
|
112
|
+
finish_reason: string;
|
|
113
|
+
}
|
|
114
|
+
export interface OpenAICompletionResponse {
|
|
115
|
+
id: string;
|
|
116
|
+
object: string;
|
|
117
|
+
created: number;
|
|
118
|
+
model: string;
|
|
119
|
+
choices: OpenAICompletionChoice[];
|
|
120
|
+
usage: OpenAIUsage;
|
|
121
|
+
}
|
|
122
|
+
export interface OpenAIChatMessage {
|
|
123
|
+
role: string;
|
|
124
|
+
content: string;
|
|
125
|
+
}
|
|
126
|
+
export interface OpenAIChatCompletionChoice {
|
|
127
|
+
index: number;
|
|
128
|
+
message: OpenAIChatMessage;
|
|
129
|
+
finish_reason: string;
|
|
130
|
+
}
|
|
131
|
+
export interface OpenAIChatCompletionResponse {
|
|
132
|
+
id: string;
|
|
133
|
+
object: string;
|
|
134
|
+
created: number;
|
|
135
|
+
model: string;
|
|
136
|
+
choices: OpenAIChatCompletionChoice[];
|
|
137
|
+
usage: OpenAIUsage;
|
|
138
|
+
}
|
|
139
|
+
export interface ImageGenerationResponse {
|
|
140
|
+
fileName: string;
|
|
141
|
+
}
|
|
142
|
+
export interface LookupFilterResult {
|
|
143
|
+
result: DataValues[] | number;
|
|
144
|
+
count?: number;
|
|
145
|
+
}
|
|
146
|
+
export interface NestedFilterResponse {
|
|
147
|
+
data: DataValues[];
|
|
148
|
+
metadata?: {
|
|
149
|
+
count?: number;
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
export type CustomAggregationResponse = any;
|
|
153
|
+
export interface NotificationVisibility {
|
|
154
|
+
sendTo: "all" | "admins" | "specificUsers";
|
|
155
|
+
specificUsersEmails?: string[];
|
|
156
|
+
}
|
|
157
|
+
export interface NotificationAction {
|
|
158
|
+
actionType: "link" | "none";
|
|
159
|
+
actionName?: string;
|
|
160
|
+
link?: string;
|
|
161
|
+
}
|
|
162
|
+
export interface NotificationEmail {
|
|
163
|
+
sendEmail: boolean;
|
|
164
|
+
totalumSupportBtn?: boolean;
|
|
165
|
+
}
|
|
166
|
+
export interface NotificationResponse {
|
|
167
|
+
_id: string;
|
|
168
|
+
name: string;
|
|
169
|
+
type?: string;
|
|
170
|
+
title: string;
|
|
171
|
+
description: string;
|
|
172
|
+
visibility: NotificationVisibility;
|
|
173
|
+
action?: NotificationAction;
|
|
174
|
+
email?: NotificationEmail;
|
|
175
|
+
createdAt: Date | string;
|
|
176
|
+
}
|
|
177
|
+
export type StatisticResponse = number;
|
|
178
|
+
export interface UpdateRecordChange {
|
|
179
|
+
timestamp: Date | string;
|
|
180
|
+
userId: string;
|
|
181
|
+
changes: any;
|
|
182
|
+
}
|
|
183
|
+
export interface UpdatesRecordResponse {
|
|
184
|
+
_id: string;
|
|
185
|
+
objectId: string;
|
|
186
|
+
typeId: string;
|
|
187
|
+
updates: UpdateRecordChange[];
|
|
188
|
+
}
|
|
189
|
+
export interface CreateRecordResponse {
|
|
190
|
+
acknowledged: boolean;
|
|
191
|
+
insertedId: string;
|
|
192
|
+
}
|
|
193
|
+
export interface UpdatedRecordResponse {
|
|
194
|
+
/** Indicates whether this write result was acknowledged. If not, then all other members of this result will be undefined */
|
|
195
|
+
acknowledged: boolean;
|
|
196
|
+
/** The number of documents that matched the filter */
|
|
197
|
+
matchedCount?: number;
|
|
198
|
+
/** The number of documents that were modified */
|
|
199
|
+
modifiedCount?: number;
|
|
200
|
+
/** The number of documents that were upserted */
|
|
201
|
+
upsertedCount?: number;
|
|
202
|
+
/** The identifier of the inserted document if an upsert took place */
|
|
203
|
+
upsertedId?: string;
|
|
204
|
+
}
|
|
205
|
+
export interface ManyToManyReferenceResponse {
|
|
206
|
+
acknowledged: boolean;
|
|
207
|
+
matchedCount?: number;
|
|
208
|
+
modifiedCount?: number;
|
|
209
|
+
}
|
|
210
|
+
export type UpdatesRecordResponseOrEmpty = UpdatesRecordResponse | [];
|
package/dist/index.d.ts
CHANGED
|
@@ -7,11 +7,14 @@ import { NotificationService } from './services/NotificationService';
|
|
|
7
7
|
import { StatisticService } from './services/StatisticService';
|
|
8
8
|
import { EmailService } from './services/EmailService';
|
|
9
9
|
export * from './common/interfaces';
|
|
10
|
+
export * from './common/response-types';
|
|
10
11
|
export { EmailPayloadI } from './services/EmailService';
|
|
12
|
+
export { TotalumError } from './common/fetch-client';
|
|
11
13
|
export declare class TotalumApiSdk {
|
|
12
14
|
private authOptions;
|
|
13
15
|
private _baseUrl;
|
|
14
16
|
private _headers;
|
|
17
|
+
private client;
|
|
15
18
|
openai: OpenaiService;
|
|
16
19
|
files: FilesService;
|
|
17
20
|
filter: FilterService;
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.TotalumApiSdk = void 0;
|
|
17
|
+
exports.TotalumApiSdk = exports.TotalumError = void 0;
|
|
18
|
+
const fetch_client_1 = require("./common/fetch-client");
|
|
18
19
|
const OpenaiService_1 = require("./services/OpenaiService");
|
|
19
20
|
const FilterService_1 = require("./services/FilterService");
|
|
20
21
|
const FilesService_1 = require("./services/FilesService");
|
|
@@ -22,21 +23,23 @@ const CrudService_1 = require("./services/CrudService");
|
|
|
22
23
|
const NotificationService_1 = require("./services/NotificationService");
|
|
23
24
|
const StatisticService_1 = require("./services/StatisticService");
|
|
24
25
|
const EmailService_1 = require("./services/EmailService");
|
|
26
|
+
// Export all interfaces and types
|
|
25
27
|
__exportStar(require("./common/interfaces"), exports);
|
|
28
|
+
__exportStar(require("./common/response-types"), exports);
|
|
29
|
+
var fetch_client_2 = require("./common/fetch-client");
|
|
30
|
+
Object.defineProperty(exports, "TotalumError", { enumerable: true, get: function () { return fetch_client_2.TotalumError; } });
|
|
26
31
|
class TotalumApiSdk {
|
|
27
32
|
constructor(authOptions) {
|
|
28
33
|
var _a, _b;
|
|
29
34
|
this._baseUrl = 'https://api.totalum.app/';
|
|
30
35
|
this.authOptions = authOptions;
|
|
36
|
+
// Initialize headers
|
|
37
|
+
this._headers = {};
|
|
31
38
|
if ((_a = this.authOptions.token) === null || _a === void 0 ? void 0 : _a.accessToken) {
|
|
32
|
-
this._headers =
|
|
33
|
-
authorization: this.authOptions.token.accessToken
|
|
34
|
-
};
|
|
39
|
+
this._headers.authorization = this.authOptions.token.accessToken;
|
|
35
40
|
}
|
|
36
41
|
else if ((_b = this.authOptions.apiKey) === null || _b === void 0 ? void 0 : _b['api-key']) {
|
|
37
|
-
this._headers =
|
|
38
|
-
'api-key': this.authOptions.apiKey['api-key'],
|
|
39
|
-
};
|
|
42
|
+
this._headers['api-key'] = this.authOptions.apiKey['api-key'];
|
|
40
43
|
}
|
|
41
44
|
else {
|
|
42
45
|
throw new Error('Error: invalid auth options');
|
|
@@ -44,25 +47,28 @@ class TotalumApiSdk {
|
|
|
44
47
|
if (this.authOptions.baseUrl) {
|
|
45
48
|
this._baseUrl = this.authOptions.baseUrl;
|
|
46
49
|
}
|
|
47
|
-
// @ts-ignore
|
|
50
|
+
// @ts-ignore - fromEvent is an internal property
|
|
48
51
|
if (this.authOptions.fromEvent) {
|
|
49
|
-
this._headers
|
|
52
|
+
this._headers.fromEvent = 'true';
|
|
50
53
|
}
|
|
51
54
|
this.setRequestData();
|
|
52
55
|
}
|
|
53
56
|
changeBaseUrl(newBaseUrl) {
|
|
54
57
|
this._baseUrl = newBaseUrl;
|
|
55
|
-
//
|
|
58
|
+
// Update services with new base URL
|
|
56
59
|
this.setRequestData();
|
|
57
60
|
}
|
|
58
61
|
setRequestData() {
|
|
59
|
-
|
|
60
|
-
this.
|
|
61
|
-
|
|
62
|
-
this.
|
|
63
|
-
this.
|
|
64
|
-
this.
|
|
65
|
-
this.
|
|
62
|
+
// Create fetch client with base URL and headers
|
|
63
|
+
this.client = new fetch_client_1.FetchClient(this._baseUrl, this._headers);
|
|
64
|
+
// Initialize all services with the fetch client
|
|
65
|
+
this.crud = new CrudService_1.CrudService(this.client);
|
|
66
|
+
this.openai = new OpenaiService_1.OpenaiService(this.client);
|
|
67
|
+
this.files = new FilesService_1.FilesService(this.client);
|
|
68
|
+
this.filter = new FilterService_1.FilterService(this.client);
|
|
69
|
+
this.notification = new NotificationService_1.NotificationService(this.client);
|
|
70
|
+
this.statistic = new StatisticService_1.StatisticService(this.client);
|
|
71
|
+
this.email = new EmailService_1.EmailService(this.client);
|
|
66
72
|
}
|
|
67
73
|
}
|
|
68
74
|
exports.TotalumApiSdk = TotalumApiSdk;
|
|
@@ -1,48 +1,84 @@
|
|
|
1
|
-
import { FilterSearchQueryI, NestedQuery } from "../common/interfaces";
|
|
1
|
+
import { FilterSearchQueryI, NestedQuery, TotalumApiResponse } from "../common/interfaces";
|
|
2
|
+
import { CreateRecordResponse, DataValues, DeleteObjectResponse, UpdatedRecordResponse, UpdatesRecordResponse } from "../common/response-types";
|
|
3
|
+
import { FetchClient } from "../common/fetch-client";
|
|
2
4
|
export declare class CrudService {
|
|
3
|
-
private
|
|
4
|
-
|
|
5
|
-
constructor(baseUrl: string, headers: any);
|
|
5
|
+
private client;
|
|
6
|
+
constructor(client: FetchClient);
|
|
6
7
|
/**
|
|
7
|
-
* Fetches
|
|
8
|
-
* @param {string}
|
|
9
|
-
* @param {string} id - The ID of the
|
|
10
|
-
* @returns {Promise<
|
|
8
|
+
* Fetches a record by its ID.
|
|
9
|
+
* @param {string} tableName - The type of the record. (table name)
|
|
10
|
+
* @param {string} id - The ID of the record.
|
|
11
|
+
* @returns {Promise<TotalumApiResponse<T>>} - A promise that resolves to the record data.
|
|
11
12
|
*/
|
|
12
|
-
|
|
13
|
+
getRecordById<T = DataValues>(tableName: string, id: string): Promise<TotalumApiResponse<T>>;
|
|
13
14
|
/**
|
|
14
15
|
* Fetches the historic updates of a record by its ID.
|
|
15
16
|
* @param {string} recordId - The ID of the record to fetch the historic updates.
|
|
16
|
-
* @returns {Promise<
|
|
17
|
-
*/
|
|
18
|
-
getHistoricRecordUpdatesById(recordId: string): Promise<
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
*
|
|
29
|
-
* @param
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
*
|
|
36
|
-
* @param
|
|
37
|
-
* @param
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
*
|
|
43
|
-
* @param
|
|
44
|
-
* @param
|
|
45
|
-
* @param
|
|
46
|
-
|
|
47
|
-
|
|
17
|
+
* @returns {Promise<TotalumApiResponse<UpdatesRecordResponse>>} - A promise that resolves to the historic updates data.
|
|
18
|
+
*/
|
|
19
|
+
getHistoricRecordUpdatesById(recordId: string): Promise<TotalumApiResponse<UpdatesRecordResponse>>;
|
|
20
|
+
/**
|
|
21
|
+
* Fetches records with optional filtering, sorting, and pagination.
|
|
22
|
+
* The response data is an array of records. If returnCount is true, a metadata object with count is also returned.
|
|
23
|
+
* @param {string} tableName - The type of the record. (table name)
|
|
24
|
+
* @param {FilterSearchQueryI} query - Optional query parameters for filtering.
|
|
25
|
+
* @returns {Promise<TotalumApiResponse<T[]>>} - A promise that resolves to an array of records.
|
|
26
|
+
*/
|
|
27
|
+
getRecords<T = DataValues>(tableName: string, query?: FilterSearchQueryI): Promise<TotalumApiResponse<T[]>>;
|
|
28
|
+
/**
|
|
29
|
+
* Fetches nested data across related tables.
|
|
30
|
+
* @param {NestedQuery} nestedQuery - The nested query structure.
|
|
31
|
+
* @param {any} options - Optional configuration.
|
|
32
|
+
* @returns {Promise<TotalumApiResponse<T[]>>} - A promise that resolves to nested data array.
|
|
33
|
+
*/
|
|
34
|
+
getNestedData<T = DataValues>(nestedQuery: NestedQuery, options?: any): Promise<TotalumApiResponse<T[]>>;
|
|
35
|
+
/**
|
|
36
|
+
* Deletes a record by its ID.
|
|
37
|
+
* @param {string} tableName - The type of the record. (table name)
|
|
38
|
+
* @param {string} id - The ID of the record.
|
|
39
|
+
* @returns {Promise<TotalumApiResponse<DeleteObjectResponse>>} - A promise that resolves when deletion is complete.
|
|
40
|
+
*/
|
|
41
|
+
deleteRecordById(tableName: string, id: string): Promise<TotalumApiResponse<DeleteObjectResponse>>;
|
|
42
|
+
/**
|
|
43
|
+
* Edits a record by its ID.
|
|
44
|
+
* @param {string} tableName - The type of the record. (table name)
|
|
45
|
+
* @param {string} id - The ID of the record.
|
|
46
|
+
* @param {T} properties - The properties to update.
|
|
47
|
+
* @returns {Promise<TotalumApiResponse<UpdatedRecordResponse>>} - A promise that resolves to the updated record.
|
|
48
|
+
*/
|
|
49
|
+
editRecordById<T = DataValues>(tableName: string, id: string, properties: Partial<T>): Promise<TotalumApiResponse<UpdatedRecordResponse>>;
|
|
50
|
+
/**
|
|
51
|
+
* Creates a new record.
|
|
52
|
+
* @param {string} tableName - The type of the record. (table name)
|
|
53
|
+
* @param {T} record - The record data to create.
|
|
54
|
+
* @returns {Promise<TotalumApiResponse<T>>} - A promise that resolves to the created record.
|
|
55
|
+
*/
|
|
56
|
+
createRecord<T = DataValues>(tableName: string, record: Partial<T>): Promise<TotalumApiResponse<CreateRecordResponse>>;
|
|
57
|
+
/**
|
|
58
|
+
* Adds a many-to-many reference between records.
|
|
59
|
+
* @param {string} type - The type id of the record (table name)
|
|
60
|
+
* @param {string} id - The id of the record that we want to add a many to many reference
|
|
61
|
+
* @param {string} propertyName - The property that we want to add a many to many reference
|
|
62
|
+
* @param {string} referenceId - The id of the record that we want to add as a many to many reference
|
|
63
|
+
* @returns {Promise<TotalumApiResponse<CreateRecordResponse>>}
|
|
64
|
+
*/
|
|
65
|
+
addManyToManyReferenceRecord(type: string, id: string, propertyName: string, referenceId: string): Promise<TotalumApiResponse<CreateRecordResponse>>;
|
|
66
|
+
/**
|
|
67
|
+
* Drops a many-to-many reference between records.
|
|
68
|
+
* @param {string} type - The type id of the record (table name)
|
|
69
|
+
* @param {string} id - The id of the record that we want to drop a many to many reference
|
|
70
|
+
* @param {string} propertyName - The property that we want to drop a many to many reference
|
|
71
|
+
* @param {string} referenceId - The id of the record that we want to drop as a many to many reference
|
|
72
|
+
* @returns {Promise<TotalumApiResponse<DeleteObjectResponse>>}
|
|
73
|
+
*/
|
|
74
|
+
dropManyToManyReferenceRecord(type: string, id: string, propertyName: string, referenceId: string): Promise<TotalumApiResponse<DeleteObjectResponse>>;
|
|
75
|
+
/**
|
|
76
|
+
* Gets many-to-many reference records with optional filtering.
|
|
77
|
+
* @param {string} type - The type id of the record (table name)
|
|
78
|
+
* @param {string} id - The id of the record that we want to get many to many references
|
|
79
|
+
* @param {string} propertyName - The property that we want to get many to many references
|
|
80
|
+
* @param {FilterSearchQueryI} query - The query to filter and sort the results
|
|
81
|
+
* @returns {Promise<TotalumApiResponse<T[]>>}
|
|
82
|
+
*/
|
|
83
|
+
getManyToManyReferencesRecords<T = DataValues>(type: string, id: string, propertyName: string, query?: FilterSearchQueryI): Promise<TotalumApiResponse<T[]>>;
|
|
48
84
|
}
|