totalum-api-sdk 1.0.12 → 2.0.1
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/common/endpoints.ts +36 -0
- package/common/interfaces.ts +186 -0
- package/index.js +22 -149
- package/index.ts +33 -307
- package/package.json +3 -2
- package/services/CrudService.ts +44 -0
- package/services/FilesService.ts +32 -0
- package/services/FilterService.ts +43 -0
- package/services/GoogleService.ts +49 -0
- package/services/OpenaiService.ts +55 -0
- package/tsconfig.json +1 -1
- package/utils.ts +12 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// ENDPOINTS
|
|
2
|
+
export const endpoints = {
|
|
3
|
+
crud: {
|
|
4
|
+
getObjectById: 'api/v1/crud/:typeId/:id',
|
|
5
|
+
getObjects: 'api/v1/crud/:typeId',
|
|
6
|
+
createObject: 'api/v1/crud/:typeId',
|
|
7
|
+
editObjectProperties: 'api/v1/crud/:typeId/:id',
|
|
8
|
+
deleteObject: 'api/v1/crud/:typeId/:id',
|
|
9
|
+
deleteObjectAndSubElements: 'api/v1/crud/:typeId/:id/:pageId/subelements',
|
|
10
|
+
updateLastUsersActions: 'api/v1/crud/:typeId/:id/lastUsersActions'
|
|
11
|
+
},
|
|
12
|
+
files: {
|
|
13
|
+
uploadFile: 'api/v1/files/upload',
|
|
14
|
+
getDownloadUrl: 'api/v1/files/download/:fileName',
|
|
15
|
+
deleteFile: 'api/v1/files/:fileName',
|
|
16
|
+
},
|
|
17
|
+
filter: {
|
|
18
|
+
lookUpFilter: 'api/v1/filter/:idPage',
|
|
19
|
+
customMongoFilter: 'api/v1/filter/custom-mongo-filter',
|
|
20
|
+
runCustomAggregationQuery: 'api/v1/filter/custom-mongo-aggregation-query'
|
|
21
|
+
},
|
|
22
|
+
pdfTemplate: {
|
|
23
|
+
generatePdfByTemplate: 'api/v1/pdf-template/generatePdfByTemplate/:id'
|
|
24
|
+
},
|
|
25
|
+
googleIntegration: {
|
|
26
|
+
getEmails: 'api/v1/google-integration/get-emails',
|
|
27
|
+
sendEmail: 'api/v1/google-integration/send-email',
|
|
28
|
+
getCalendarEvents: 'api/v1/google-integration/get-calendar-events',
|
|
29
|
+
createCalendarEvent: 'api/v1/google-integration/create-calendar-event',
|
|
30
|
+
},
|
|
31
|
+
openai: {
|
|
32
|
+
createCompletion: 'api/v1/openai/completion',
|
|
33
|
+
createChatCompletion: 'api/v1/openai/chat-completion',
|
|
34
|
+
generateImage: 'api/v1/openai/image',
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
//INTERFACES
|
|
2
|
+
|
|
3
|
+
export interface GoogleCalendarI {
|
|
4
|
+
summary: string;
|
|
5
|
+
location?: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
start: {
|
|
8
|
+
dateTime: string;
|
|
9
|
+
timeZone?: string;
|
|
10
|
+
};
|
|
11
|
+
end: {
|
|
12
|
+
dateTime: string;
|
|
13
|
+
timeZone?: string;
|
|
14
|
+
};
|
|
15
|
+
attendees?: {email: string}[];
|
|
16
|
+
reminders?: Reminders;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface Reminders {
|
|
20
|
+
useDefault: boolean;
|
|
21
|
+
overrides?: {
|
|
22
|
+
method: string;
|
|
23
|
+
minutes: number;
|
|
24
|
+
}[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface GoogleCalendarEventsResponseI {
|
|
28
|
+
accessRole: string;
|
|
29
|
+
defaultReminders: { method: string; minutes: number }[];
|
|
30
|
+
etag: string;
|
|
31
|
+
items: {
|
|
32
|
+
kind: string;
|
|
33
|
+
etag: string;
|
|
34
|
+
id: string;
|
|
35
|
+
attendees?: {
|
|
36
|
+
email: string;
|
|
37
|
+
responseStatus: string;
|
|
38
|
+
}[];
|
|
39
|
+
created: string;
|
|
40
|
+
creator: {
|
|
41
|
+
email: string;
|
|
42
|
+
self?: boolean;
|
|
43
|
+
};
|
|
44
|
+
description: string;
|
|
45
|
+
end: {
|
|
46
|
+
dateTime: string;
|
|
47
|
+
timeZone: string;
|
|
48
|
+
};
|
|
49
|
+
eventType: string;
|
|
50
|
+
htmlLink: string;
|
|
51
|
+
iCalUID: string;
|
|
52
|
+
location: string;
|
|
53
|
+
organizer: {
|
|
54
|
+
email: string;
|
|
55
|
+
self?: boolean;
|
|
56
|
+
};
|
|
57
|
+
reminders: { useDefault: boolean };
|
|
58
|
+
sequence: number;
|
|
59
|
+
start: {
|
|
60
|
+
dateTime: string;
|
|
61
|
+
timeZone: string;
|
|
62
|
+
};
|
|
63
|
+
status: string;
|
|
64
|
+
summary: string;
|
|
65
|
+
// Additional fields can be added here
|
|
66
|
+
}[];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface GoogleEmailI {
|
|
70
|
+
to: string;
|
|
71
|
+
subject: string;
|
|
72
|
+
message: string;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface GoogleEmailResponseI {
|
|
76
|
+
id: string;
|
|
77
|
+
threadId: string;
|
|
78
|
+
labelIds: string[];
|
|
79
|
+
snippet: string;
|
|
80
|
+
payload: {
|
|
81
|
+
partId: string;
|
|
82
|
+
mimeType: string;
|
|
83
|
+
filename: string;
|
|
84
|
+
headers: {
|
|
85
|
+
name: string;
|
|
86
|
+
value: string;
|
|
87
|
+
}[];
|
|
88
|
+
body: {
|
|
89
|
+
size: number;
|
|
90
|
+
data: string;
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
sizeEstimate: number;
|
|
94
|
+
historyId: string;
|
|
95
|
+
internalDate: string;
|
|
96
|
+
fullText: string;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
export interface StructureLevels {
|
|
101
|
+
id: string, // the id of the node
|
|
102
|
+
typeId: string,
|
|
103
|
+
propertyId?: string,
|
|
104
|
+
children: Array<StructureLevels>
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface FilterSearchQueryI {
|
|
108
|
+
filter?: FiltersArrayI,
|
|
109
|
+
sort?: ISearchQuerySort[],
|
|
110
|
+
pagination?: {
|
|
111
|
+
limit?: number,
|
|
112
|
+
page?: number,
|
|
113
|
+
skip?: number
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export type FilterLookupSearchQueryI = {
|
|
118
|
+
pagination: {
|
|
119
|
+
limit?: number;
|
|
120
|
+
page?: number;
|
|
121
|
+
skip?: number;
|
|
122
|
+
};
|
|
123
|
+
filters: FilterStructureLevelsI
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
export interface FilterStructureLevelsI extends StructureLevels {
|
|
127
|
+
filters?: FiltersArrayI;
|
|
128
|
+
children: FilterStructureLevelsI[];
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export type FiltersArrayI = Array<ISearchQueryFilterOr | ISearchQueryFilterOptions>;
|
|
132
|
+
|
|
133
|
+
export interface ISearchQueryFilterOr {
|
|
134
|
+
or: ISearchQueryFilterOptions[]
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export interface ISearchQuerySort {
|
|
138
|
+
[key: string]: 1 | -1
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export interface ISearchQueryFilterOptions {
|
|
142
|
+
[key: string]: number | Date | boolean | string | PropertyQueryOptionsI
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export interface PropertyQueryOptionsI {
|
|
146
|
+
regex?: number | string,
|
|
147
|
+
// options field is only valid for regex
|
|
148
|
+
options?: 'i' | 'm' | 'x' | 's', //for more info check: https://www.mongodb.com/docs/manual/reference/operator/query/regex/
|
|
149
|
+
gte?: number | Date,
|
|
150
|
+
lte?: number | Date,
|
|
151
|
+
gt?: number | Date,
|
|
152
|
+
lt?: number | Date
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export type fieldValuesEnabled = string | number | boolean | Date
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
export interface DataValues {
|
|
159
|
+
typeId: string,
|
|
160
|
+
id: string,
|
|
161
|
+
_id: string,
|
|
162
|
+
properties: DataProperties,
|
|
163
|
+
updates?: string,
|
|
164
|
+
createdAt?: Date,
|
|
165
|
+
updatedAt?: Date,
|
|
166
|
+
lastUsersActions?: {
|
|
167
|
+
[key: string]: any
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export interface DataProperties {
|
|
172
|
+
[key: string]: fieldValuesEnabled | {name: string, previousFilename: string},
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
export interface AuthOptions {
|
|
177
|
+
token?: {
|
|
178
|
+
accessToken: string
|
|
179
|
+
},
|
|
180
|
+
apiKey?: {
|
|
181
|
+
apiKey: string,
|
|
182
|
+
apiKeyName: string,
|
|
183
|
+
organizationId: string,
|
|
184
|
+
},
|
|
185
|
+
baseUrl?: string
|
|
186
|
+
}
|
package/index.js
CHANGED
|
@@ -1,61 +1,23 @@
|
|
|
1
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
3
|
exports.TotalumApiSdk = void 0;
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
getObjects: 'api/v1/crud/:typeId',
|
|
22
|
-
createObject: 'api/v1/crud/:typeId',
|
|
23
|
-
editObjectProperties: 'api/v1/crud/:typeId/:id',
|
|
24
|
-
deleteObject: 'api/v1/crud/:typeId/:id',
|
|
25
|
-
deleteObjectAndSubElements: 'api/v1/crud/:typeId/:id/:pageId/subelements',
|
|
26
|
-
updateLastUsersActions: 'api/v1/crud/:typeId/:id/lastUsersActions'
|
|
27
|
-
},
|
|
28
|
-
files: {
|
|
29
|
-
uploadFile: 'api/v1/files/upload',
|
|
30
|
-
getDownloadUrl: 'api/v1/files/download/:fileName',
|
|
31
|
-
deleteFile: 'api/v1/files/:fileName',
|
|
32
|
-
},
|
|
33
|
-
filter: {
|
|
34
|
-
lookUpFilter: 'api/v1/filter/:idPage',
|
|
35
|
-
customMongoFilter: 'api/v1/filter/custom-mongo-filter'
|
|
36
|
-
},
|
|
37
|
-
pdfTemplate: {
|
|
38
|
-
generatePdfByTemplate: 'api/v1/pdf-template/generatePdfByTemplate/:id'
|
|
39
|
-
},
|
|
40
|
-
googleIntegration: {
|
|
41
|
-
getEmails: 'api/v1/google-integration/get-emails',
|
|
42
|
-
sendEmail: 'api/v1/google-integration/send-email',
|
|
43
|
-
getCalendarEvents: 'api/v1/google-integration/get-calendar-events',
|
|
44
|
-
createCalendarEvent: 'api/v1/google-integration/create-calendar-event',
|
|
45
|
-
}
|
|
46
|
-
};
|
|
4
|
+
const OpenaiService_1 = require("./services/OpenaiService");
|
|
5
|
+
const GoogleService_1 = require("./services/GoogleService");
|
|
6
|
+
const FilterService_1 = require("./services/FilterService");
|
|
7
|
+
const FilesService_1 = require("./services/FilesService");
|
|
8
|
+
const CrudService_1 = require("./services/CrudService");
|
|
47
9
|
class TotalumApiSdk {
|
|
48
10
|
constructor(authOptions) {
|
|
49
11
|
var _a, _b, _c;
|
|
50
|
-
this.
|
|
12
|
+
this._baseUrl = 'https://api.totalum.app/';
|
|
51
13
|
this.authOptions = authOptions;
|
|
52
14
|
if ((_a = this.authOptions.token) === null || _a === void 0 ? void 0 : _a.accessToken) {
|
|
53
|
-
this.
|
|
15
|
+
this._headers = {
|
|
54
16
|
authorization: this.authOptions.token.accessToken
|
|
55
17
|
};
|
|
56
18
|
}
|
|
57
19
|
else if (((_b = this.authOptions.apiKey) === null || _b === void 0 ? void 0 : _b.apiKey) && ((_c = this.authOptions.apiKey) === null || _c === void 0 ? void 0 : _c.organizationId)) {
|
|
58
|
-
this.
|
|
20
|
+
this._headers = {
|
|
59
21
|
'api-key': this.authOptions.apiKey.apiKey,
|
|
60
22
|
'organization-id': this.authOptions.apiKey.organizationId,
|
|
61
23
|
'api-key-name': this.authOptions.apiKey.apiKeyName
|
|
@@ -64,111 +26,22 @@ class TotalumApiSdk {
|
|
|
64
26
|
else {
|
|
65
27
|
throw new Error('Error: invalid auth options');
|
|
66
28
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
this.baseUrl = newBaseUrl;
|
|
70
|
-
}
|
|
71
|
-
getUrl(pattern, params) {
|
|
72
|
-
let url = this.baseUrl + pattern;
|
|
73
|
-
for (const key in params) {
|
|
74
|
-
url = url.replace(`:${key}`, params[key]);
|
|
29
|
+
if (this.authOptions.baseUrl) {
|
|
30
|
+
this._baseUrl = this.authOptions.baseUrl;
|
|
75
31
|
}
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
getItemById(itemType, id) {
|
|
79
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
-
const url = this.getUrl(endpoints.crud.getObjectById, { typeId: itemType, id });
|
|
81
|
-
return axios_1.default.get(url, { headers: this.headers });
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
getItems(itemType, query) {
|
|
85
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
-
const url = this.getUrl(endpoints.crud.getObjects, { typeId: itemType });
|
|
87
|
-
return axios_1.default.get(url, { params: query, headers: this.headers });
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
deleteItemById(itemType, id) {
|
|
91
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
-
const url = this.getUrl(endpoints.crud.deleteObject, { typeId: itemType, id });
|
|
93
|
-
return axios_1.default.delete(url, { headers: this.headers });
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
editItemById(itemType, id, properties) {
|
|
97
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
-
const url = this.getUrl(endpoints.crud.editObjectProperties, { typeId: itemType, id });
|
|
99
|
-
return axios_1.default.patch(url, properties, { headers: this.headers });
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
createItem(itemType, item) {
|
|
103
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
-
const url = this.getUrl(endpoints.crud.createObject, { typeId: itemType });
|
|
105
|
-
return axios_1.default.post(url, item, { headers: this.headers });
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
generatePdfByTemplate(id, variables, name) {
|
|
109
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
-
const url = this.getUrl(endpoints.pdfTemplate.generatePdfByTemplate, { id });
|
|
111
|
-
return axios_1.default.post(url, { templateId: id, variables, name }, { headers: this.headers });
|
|
112
|
-
});
|
|
32
|
+
this.setRequestData();
|
|
113
33
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
customMongoFilter(customMongoFilter, rootTypeId, typeIdToGet, options) {
|
|
127
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
-
const url = this.getUrl(endpoints.filter.customMongoFilter, {});
|
|
129
|
-
const body = { sort: options === null || options === void 0 ? void 0 : options.sort, variables: options === null || options === void 0 ? void 0 : options.variables, customMongoFilter, pagination: options === null || options === void 0 ? void 0 : options.pagination, rootTypeId, typeIdToGet };
|
|
130
|
-
const params = (options === null || options === void 0 ? void 0 : options.returnCount) ? { returnCount: options === null || options === void 0 ? void 0 : options.returnCount } : null;
|
|
131
|
-
return axios_1.default.post(url, body, { params: params, headers: this.headers });
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
getGoogleAccountEmails(accountEmail) {
|
|
135
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
136
|
-
const url = this.getUrl(endpoints.googleIntegration.getEmails, {});
|
|
137
|
-
const params = { userEmail: accountEmail };
|
|
138
|
-
return axios_1.default.get(url, { params: params, headers: this.headers });
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
googleAccountSendEmail(accountEmail, body) {
|
|
142
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
143
|
-
const url = this.getUrl(endpoints.googleIntegration.sendEmail, {});
|
|
144
|
-
const params = { userEmail: accountEmail };
|
|
145
|
-
return axios_1.default.post(url, body, { params: params, headers: this.headers });
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
getGoogleCalendarEvents(accountEmail) {
|
|
149
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
-
const url = this.getUrl(endpoints.googleIntegration.getCalendarEvents, {});
|
|
151
|
-
const params = { userEmail: accountEmail };
|
|
152
|
-
return axios_1.default.get(url, { params: params, headers: this.headers });
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
createCalendarEvent(accountEmail, body) {
|
|
156
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
157
|
-
const url = this.getUrl(endpoints.googleIntegration.createCalendarEvent, {});
|
|
158
|
-
const params = { userEmail: accountEmail };
|
|
159
|
-
return axios_1.default.post(url, body, { params: params, headers: this.headers });
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
lookUpFilter(idPage, query, idsOfMultipleNodesToSearch, returnCount) {
|
|
163
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
164
|
-
const url = this.getUrl(endpoints.filter.lookUpFilter, { idPage });
|
|
165
|
-
const params = {
|
|
166
|
-
query: encodeURIComponent(JSON.stringify(query)),
|
|
167
|
-
idsOfMultipleNodesToSearch: encodeURIComponent(JSON.stringify(idsOfMultipleNodesToSearch)),
|
|
168
|
-
returnCount: returnCount,
|
|
169
|
-
};
|
|
170
|
-
return axios_1.default.get(url, { params: params, headers: this.headers });
|
|
171
|
-
});
|
|
34
|
+
changeBaseUrl(newBaseUrl) {
|
|
35
|
+
this._baseUrl = newBaseUrl;
|
|
36
|
+
//update services with new implementation
|
|
37
|
+
this.setRequestData();
|
|
38
|
+
}
|
|
39
|
+
setRequestData() {
|
|
40
|
+
this.crud = new CrudService_1.CrudService(this._baseUrl, this._headers);
|
|
41
|
+
this.openai = new OpenaiService_1.OpenaiService(this._baseUrl, this._headers);
|
|
42
|
+
this.files = new FilesService_1.FilesService(this._baseUrl, this._headers);
|
|
43
|
+
this.google = new GoogleService_1.GoogleService(this._baseUrl, this._headers);
|
|
44
|
+
this.filter = new FilterService_1.FilterService(this._baseUrl, this._headers);
|
|
172
45
|
}
|
|
173
46
|
}
|
|
174
47
|
exports.TotalumApiSdk = TotalumApiSdk;
|
package/index.ts
CHANGED
|
@@ -1,236 +1,38 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
|
+
import { ChatCompletionCreateParamsBase } from 'openai/resources/chat/completions';
|
|
3
|
+
import { Completion, CompletionCreateParamsBase } from 'openai/resources/completions';
|
|
2
4
|
import * as qs from 'qs';
|
|
5
|
+
import { AuthOptions, FilterSearchQueryI, DataProperties, GoogleCalendarI } from './common/interfaces';
|
|
3
6
|
|
|
4
|
-
|
|
7
|
+
import { OpenaiService } from './services/OpenaiService';
|
|
8
|
+
import { UtilsService } from './utils';
|
|
9
|
+
import { GoogleService } from './services/GoogleService';
|
|
10
|
+
import { FilterService } from './services/FilterService';
|
|
11
|
+
import { FilesService } from './services/FilesService';
|
|
12
|
+
import { CrudService } from './services/CrudService';
|
|
5
13
|
|
|
6
|
-
export interface GoogleCalendarI {
|
|
7
|
-
summary: string;
|
|
8
|
-
location?: string;
|
|
9
|
-
description?: string;
|
|
10
|
-
start: {
|
|
11
|
-
dateTime: string;
|
|
12
|
-
timeZone?: string;
|
|
13
|
-
};
|
|
14
|
-
end: {
|
|
15
|
-
dateTime: string;
|
|
16
|
-
timeZone?: string;
|
|
17
|
-
};
|
|
18
|
-
attendees?: {email: string}[];
|
|
19
|
-
reminders?: Reminders;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
interface Reminders {
|
|
23
|
-
useDefault: boolean;
|
|
24
|
-
overrides?: {
|
|
25
|
-
method: string;
|
|
26
|
-
minutes: number;
|
|
27
|
-
}[];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface GoogleCalendarEventsResponseI {
|
|
31
|
-
accessRole: string;
|
|
32
|
-
defaultReminders: { method: string; minutes: number }[];
|
|
33
|
-
etag: string;
|
|
34
|
-
items: {
|
|
35
|
-
kind: string;
|
|
36
|
-
etag: string;
|
|
37
|
-
id: string;
|
|
38
|
-
attendees?: {
|
|
39
|
-
email: string;
|
|
40
|
-
responseStatus: string;
|
|
41
|
-
}[];
|
|
42
|
-
created: string;
|
|
43
|
-
creator: {
|
|
44
|
-
email: string;
|
|
45
|
-
self?: boolean;
|
|
46
|
-
};
|
|
47
|
-
description: string;
|
|
48
|
-
end: {
|
|
49
|
-
dateTime: string;
|
|
50
|
-
timeZone: string;
|
|
51
|
-
};
|
|
52
|
-
eventType: string;
|
|
53
|
-
htmlLink: string;
|
|
54
|
-
iCalUID: string;
|
|
55
|
-
location: string;
|
|
56
|
-
organizer: {
|
|
57
|
-
email: string;
|
|
58
|
-
self?: boolean;
|
|
59
|
-
};
|
|
60
|
-
reminders: { useDefault: boolean };
|
|
61
|
-
sequence: number;
|
|
62
|
-
start: {
|
|
63
|
-
dateTime: string;
|
|
64
|
-
timeZone: string;
|
|
65
|
-
};
|
|
66
|
-
status: string;
|
|
67
|
-
summary: string;
|
|
68
|
-
// Additional fields can be added here
|
|
69
|
-
}[];
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export interface GoogleEmailI {
|
|
73
|
-
to: string;
|
|
74
|
-
subject: string;
|
|
75
|
-
message: string;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export interface GoogleEmailResponseI {
|
|
79
|
-
id: string;
|
|
80
|
-
threadId: string;
|
|
81
|
-
labelIds: string[];
|
|
82
|
-
snippet: string;
|
|
83
|
-
payload: {
|
|
84
|
-
partId: string;
|
|
85
|
-
mimeType: string;
|
|
86
|
-
filename: string;
|
|
87
|
-
headers: {
|
|
88
|
-
name: string;
|
|
89
|
-
value: string;
|
|
90
|
-
}[];
|
|
91
|
-
body: {
|
|
92
|
-
size: number;
|
|
93
|
-
data: string;
|
|
94
|
-
};
|
|
95
|
-
};
|
|
96
|
-
sizeEstimate: number;
|
|
97
|
-
historyId: string;
|
|
98
|
-
internalDate: string;
|
|
99
|
-
fullText: string;
|
|
100
|
-
}
|
|
101
14
|
|
|
102
15
|
|
|
103
|
-
export interface StructureLevels {
|
|
104
|
-
id: string, // the id of the node
|
|
105
|
-
typeId: string,
|
|
106
|
-
propertyId?: string,
|
|
107
|
-
children: Array<StructureLevels>
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export interface FilterSearchQueryI {
|
|
111
|
-
filter?: FiltersArrayI,
|
|
112
|
-
sort?: ISearchQuerySort[],
|
|
113
|
-
pagination?: {
|
|
114
|
-
limit?: number,
|
|
115
|
-
page?: number,
|
|
116
|
-
skip?: number
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export type FilterLookupSearchQueryI = {
|
|
121
|
-
pagination: {
|
|
122
|
-
limit?: number;
|
|
123
|
-
page?: number;
|
|
124
|
-
skip?: number;
|
|
125
|
-
};
|
|
126
|
-
filters: FilterStructureLevelsI
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
export interface FilterStructureLevelsI extends StructureLevels {
|
|
130
|
-
filters?: FiltersArrayI;
|
|
131
|
-
children: FilterStructureLevelsI[];
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export type FiltersArrayI = Array<ISearchQueryFilterOr | ISearchQueryFilterOptions>;
|
|
135
|
-
|
|
136
|
-
export interface ISearchQueryFilterOr {
|
|
137
|
-
or: ISearchQueryFilterOptions[]
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
export interface ISearchQuerySort {
|
|
141
|
-
[key: string]: 1 | -1
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
export interface ISearchQueryFilterOptions {
|
|
145
|
-
[key: string]: number | Date | boolean | string | PropertyQueryOptionsI
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export interface PropertyQueryOptionsI {
|
|
149
|
-
regex?: number | string,
|
|
150
|
-
// options field is only valid for regex
|
|
151
|
-
options?: 'i' | 'm' | 'x' | 's', //for more info check: https://www.mongodb.com/docs/manual/reference/operator/query/regex/
|
|
152
|
-
gte?: number | Date,
|
|
153
|
-
lte?: number | Date,
|
|
154
|
-
gt?: number | Date,
|
|
155
|
-
lt?: number | Date
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
export type fieldValuesEnabled = string | number | boolean | Date
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
export interface DataValues {
|
|
162
|
-
typeId: string,
|
|
163
|
-
id: string,
|
|
164
|
-
_id: string,
|
|
165
|
-
properties: DataProperties,
|
|
166
|
-
updates?: string,
|
|
167
|
-
createdAt?: Date,
|
|
168
|
-
updatedAt?: Date,
|
|
169
|
-
lastUsersActions?: {
|
|
170
|
-
[key: string]: any
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
export interface DataProperties {
|
|
175
|
-
[key: string]: fieldValuesEnabled | {name: string, previousFilename: string},
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
// ENDPOINTS
|
|
180
|
-
const endpoints = {
|
|
181
|
-
crud: {
|
|
182
|
-
getObjectById: 'api/v1/crud/:typeId/:id',
|
|
183
|
-
getObjects: 'api/v1/crud/:typeId',
|
|
184
|
-
createObject: 'api/v1/crud/:typeId',
|
|
185
|
-
editObjectProperties: 'api/v1/crud/:typeId/:id',
|
|
186
|
-
deleteObject: 'api/v1/crud/:typeId/:id',
|
|
187
|
-
deleteObjectAndSubElements: 'api/v1/crud/:typeId/:id/:pageId/subelements',
|
|
188
|
-
updateLastUsersActions: 'api/v1/crud/:typeId/:id/lastUsersActions'
|
|
189
|
-
},
|
|
190
|
-
files: {
|
|
191
|
-
uploadFile: 'api/v1/files/upload',
|
|
192
|
-
getDownloadUrl: 'api/v1/files/download/:fileName',
|
|
193
|
-
deleteFile: 'api/v1/files/:fileName',
|
|
194
|
-
},
|
|
195
|
-
filter: {
|
|
196
|
-
lookUpFilter: 'api/v1/filter/:idPage',
|
|
197
|
-
customMongoFilter: 'api/v1/filter/custom-mongo-filter'
|
|
198
|
-
},
|
|
199
|
-
pdfTemplate: {
|
|
200
|
-
generatePdfByTemplate: 'api/v1/pdf-template/generatePdfByTemplate/:id'
|
|
201
|
-
},
|
|
202
|
-
googleIntegration: {
|
|
203
|
-
getEmails: 'api/v1/google-integration/get-emails',
|
|
204
|
-
sendEmail: 'api/v1/google-integration/send-email',
|
|
205
|
-
getCalendarEvents: 'api/v1/google-integration/get-calendar-events',
|
|
206
|
-
createCalendarEvent: 'api/v1/google-integration/create-calendar-event',
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
export interface AuthOptions {
|
|
211
|
-
token?: {
|
|
212
|
-
accessToken: string
|
|
213
|
-
},
|
|
214
|
-
apiKey?: {
|
|
215
|
-
apiKey: string,
|
|
216
|
-
apiKeyName: string,
|
|
217
|
-
organizationId: string,
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
16
|
|
|
221
17
|
export class TotalumApiSdk {
|
|
222
|
-
public baseUrl = 'https://api.totalum.app/';
|
|
223
18
|
private authOptions: AuthOptions;
|
|
224
|
-
|
|
19
|
+
|
|
20
|
+
private _baseUrl: string = 'https://api.totalum.app/';
|
|
21
|
+
private _headers: any;
|
|
22
|
+
public openai: OpenaiService;
|
|
23
|
+
public files: FilesService;
|
|
24
|
+
public google: GoogleService;
|
|
25
|
+
public filter: FilterService;
|
|
26
|
+
public crud:CrudService;
|
|
225
27
|
|
|
226
28
|
constructor(authOptions: AuthOptions) {
|
|
227
29
|
this.authOptions = authOptions;
|
|
228
30
|
if (this.authOptions.token?.accessToken) {
|
|
229
|
-
this.
|
|
31
|
+
this._headers = {
|
|
230
32
|
authorization: this.authOptions.token.accessToken
|
|
231
33
|
}
|
|
232
34
|
} else if (this.authOptions.apiKey?.apiKey && this.authOptions.apiKey?.organizationId) {
|
|
233
|
-
this.
|
|
35
|
+
this._headers = {
|
|
234
36
|
'api-key': this.authOptions.apiKey.apiKey,
|
|
235
37
|
'organization-id': this.authOptions.apiKey.organizationId,
|
|
236
38
|
'api-key-name': this.authOptions.apiKey.apiKeyName
|
|
@@ -238,101 +40,25 @@ export class TotalumApiSdk {
|
|
|
238
40
|
} else {
|
|
239
41
|
throw new Error('Error: invalid auth options')
|
|
240
42
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
public changeBaseUrl(newBaseUrl: string) {
|
|
244
|
-
this.baseUrl = newBaseUrl;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
private getUrl(pattern: string, params?: any): string {
|
|
248
|
-
let url = this.baseUrl + pattern;
|
|
249
|
-
for (const key in params) {
|
|
250
|
-
url = url.replace(`:${key}`, params[key]);
|
|
43
|
+
if (this.authOptions.baseUrl) {
|
|
44
|
+
this._baseUrl = this.authOptions.baseUrl;
|
|
251
45
|
}
|
|
252
|
-
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
public async getItemById(itemType: string, id: string) {
|
|
256
|
-
const url = this.getUrl(endpoints.crud.getObjectById, { typeId: itemType, id });
|
|
257
|
-
return axios.get(url, { headers: this.headers });
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
public async getItems(itemType: string, query?: FilterSearchQueryI) {
|
|
261
|
-
const url = this.getUrl(endpoints.crud.getObjects, { typeId: itemType });
|
|
262
|
-
return axios.get(url, { params: query, headers: this.headers });
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
public async deleteItemById(itemType: string, id: string) {
|
|
266
|
-
const url = this.getUrl(endpoints.crud.deleteObject, { typeId: itemType, id });
|
|
267
|
-
return axios.delete(url, { headers: this.headers });
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
public async editItemById(itemType: string, id: string, properties: any) {
|
|
271
|
-
const url = this.getUrl(endpoints.crud.editObjectProperties, { typeId: itemType, id });
|
|
272
|
-
return axios.patch(url, properties, { headers: this.headers });
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
public async createItem(itemType: string, item: DataProperties) {
|
|
276
|
-
const url = this.getUrl(endpoints.crud.createObject, { typeId: itemType });
|
|
277
|
-
return axios.post(url, item, { headers: this.headers });
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
public async generatePdfByTemplate(id: string, variables: { [variableName: string]: any }, name: string) {
|
|
281
|
-
const url = this.getUrl(endpoints.pdfTemplate.generatePdfByTemplate, { id });
|
|
282
|
-
return axios.post(url, { templateId: id, variables, name }, { headers: this.headers });
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
public async uploadFile(fileFormData: any) {
|
|
286
|
-
const url = this.getUrl(endpoints.files.uploadFile);
|
|
287
|
-
return axios.post(url, fileFormData, { headers: this.headers });
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
public async getDownloadUrl(fileName: string) {
|
|
291
|
-
const url = this.getUrl(endpoints.files.getDownloadUrl, { fileName });
|
|
292
|
-
return axios.get(url, { headers: this.headers });
|
|
46
|
+
this.setRequestData();
|
|
293
47
|
}
|
|
294
48
|
|
|
295
|
-
public
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
return axios.post(url, body, { params: params, headers: this.headers });
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
public async getGoogleAccountEmails(accountEmail: string) {
|
|
303
|
-
const url = this.getUrl(endpoints.googleIntegration.getEmails, {});
|
|
304
|
-
const params = { userEmail: accountEmail };
|
|
305
|
-
return axios.get(url, { params: params, headers: this.headers });
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
public async googleAccountSendEmail(accountEmail: string, body: {to: string, subject: string, message: string}) {
|
|
309
|
-
const url = this.getUrl(endpoints.googleIntegration.sendEmail, {});
|
|
310
|
-
const params = { userEmail: accountEmail };
|
|
311
|
-
return axios.post(url, body, { params: params, headers: this.headers });
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
public async getGoogleCalendarEvents(accountEmail: string) {
|
|
315
|
-
const url = this.getUrl(endpoints.googleIntegration.getCalendarEvents, {});
|
|
316
|
-
const params = { userEmail: accountEmail };
|
|
317
|
-
return axios.get(url, { params: params, headers: this.headers });
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
public async createCalendarEvent(accountEmail: string, body: GoogleCalendarI) {
|
|
321
|
-
const url = this.getUrl(endpoints.googleIntegration.createCalendarEvent, {});
|
|
322
|
-
const params = { userEmail: accountEmail };
|
|
323
|
-
return axios.post(url, body, { params: params, headers: this.headers });
|
|
49
|
+
public changeBaseUrl(newBaseUrl: string) {
|
|
50
|
+
this._baseUrl = newBaseUrl;
|
|
51
|
+
//update services with new implementation
|
|
52
|
+
this.setRequestData();
|
|
324
53
|
}
|
|
325
54
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
};
|
|
333
|
-
return axios.get(url, { params: params, headers: this.headers });
|
|
55
|
+
private setRequestData() {
|
|
56
|
+
this.crud = new CrudService(this._baseUrl, this._headers);
|
|
57
|
+
this.openai = new OpenaiService(this._baseUrl, this._headers);
|
|
58
|
+
this.files = new FilesService(this._baseUrl, this._headers);
|
|
59
|
+
this.google = new GoogleService(this._baseUrl, this._headers);
|
|
60
|
+
this.filter = new FilterService(this._baseUrl, this._headers);
|
|
334
61
|
}
|
|
335
62
|
|
|
336
63
|
|
|
337
|
-
|
|
338
|
-
}
|
|
64
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "totalum-api-sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Totalum sdk wraper of totalum api",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"build":"tsc"
|
|
7
|
+
"build": "tsc"
|
|
8
8
|
},
|
|
9
9
|
"author": "Totalum",
|
|
10
10
|
"license": "ISC",
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@types/axios": "^0.14.0",
|
|
17
17
|
"axios": "^1.4.0",
|
|
18
|
+
"openai": "^4.4.0",
|
|
18
19
|
"qs": "^6.11.2"
|
|
19
20
|
}
|
|
20
21
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { FilterSearchQueryI, DataProperties } from "../common/interfaces";
|
|
3
|
+
import { UtilsService } from "../utils";
|
|
4
|
+
import { endpoints } from "../common/endpoints";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export class CrudService {
|
|
9
|
+
|
|
10
|
+
private headers: any;
|
|
11
|
+
private baseUrl: string;
|
|
12
|
+
|
|
13
|
+
constructor(baseUrl: string, headers: any) {
|
|
14
|
+
this.headers = headers
|
|
15
|
+
this.baseUrl = baseUrl;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public async getItemById(itemType: string, id: string) {
|
|
19
|
+
const url = UtilsService.getUrl(this.baseUrl, endpoints.crud.getObjectById, { typeId: itemType, id });
|
|
20
|
+
return axios.get(url, { headers: this.headers });
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public getItems(itemType: string, query?: FilterSearchQueryI) {
|
|
24
|
+
const url = UtilsService.getUrl(this.baseUrl, endpoints.crud.getObjects, { typeId: itemType });
|
|
25
|
+
return axios.get(url, { params: query, headers: this.headers });
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public async deleteItemById(itemType: string, id: string) {
|
|
29
|
+
const url = UtilsService.getUrl(this.baseUrl, endpoints.crud.deleteObject, { typeId: itemType, id });
|
|
30
|
+
return axios.delete(url, { headers: this.headers });
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public async editItemById(itemType: string, id: string, properties: any) {
|
|
34
|
+
const url = UtilsService.getUrl(this.baseUrl, endpoints.crud.editObjectProperties, { typeId: itemType, id });
|
|
35
|
+
return axios.patch(url, properties, { headers: this.headers });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public async createItem(itemType: string, item: DataProperties) {
|
|
39
|
+
const url = UtilsService.getUrl(this.baseUrl, endpoints.crud.createObject, { typeId: itemType });
|
|
40
|
+
return axios.post(url, item, { headers: this.headers });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { UtilsService } from "../utils";
|
|
3
|
+
import { endpoints } from "../common/endpoints";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export class FilesService {
|
|
7
|
+
|
|
8
|
+
private headers: any;
|
|
9
|
+
private baseUrl: string;
|
|
10
|
+
|
|
11
|
+
constructor(baseUrl: string, headers: any) {
|
|
12
|
+
this.headers = headers
|
|
13
|
+
this.baseUrl = baseUrl;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
public async uploadFile(fileFormData: any) {
|
|
18
|
+
const url = UtilsService.getUrl(this.baseUrl, endpoints.files.uploadFile);
|
|
19
|
+
return axios.post(url, fileFormData, { headers: this.headers });
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public async getDownloadUrl(fileName: string) {
|
|
23
|
+
const url = UtilsService.getUrl(this.baseUrl, endpoints.files.getDownloadUrl, { fileName });
|
|
24
|
+
return axios.get(url, { headers: this.headers });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public async generatePdfByTemplate(id: string, variables: { [variableName: string]: any }, name: string) {
|
|
28
|
+
const url = UtilsService.getUrl(this.baseUrl, endpoints.pdfTemplate.generatePdfByTemplate, { id });
|
|
29
|
+
return axios.post(url, { templateId: id, variables, name }, { headers: this.headers });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { endpoints } from "../common/endpoints";
|
|
3
|
+
import { UtilsService } from "../utils";
|
|
4
|
+
import { FilterLookupSearchQueryI } from "../common/interfaces";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export class FilterService {
|
|
9
|
+
|
|
10
|
+
private headers: any;
|
|
11
|
+
private baseUrl: string;
|
|
12
|
+
|
|
13
|
+
constructor(baseUrl: string, headers: any) {
|
|
14
|
+
this.headers = headers
|
|
15
|
+
this.baseUrl = baseUrl;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/*public async customMongoFilter(customMongoFilter: string, rootTypeId: string, typeIdToGet: string, options?: { variables?: any, pagination?: any, sort?: any, returnCount?: boolean }) {
|
|
19
|
+
const url = UtilsService.getUrl(this.baseUrl, endpoints.filter.customMongoFilter, {});
|
|
20
|
+
const body = { sort: options?.sort, variables: options?.variables, customMongoFilter, pagination: options?.pagination, rootTypeId, typeIdToGet };
|
|
21
|
+
const params = options?.returnCount ? { returnCount: options?.returnCount } : null;
|
|
22
|
+
return axios.post(url, body, { params: params, headers: this.headers });
|
|
23
|
+
}*/
|
|
24
|
+
|
|
25
|
+
public async lookUpFilter(idPage: string, query: FilterLookupSearchQueryI, idsOfMultipleNodesToSearch?: string[], returnCount?: boolean) {
|
|
26
|
+
const url = UtilsService.getUrl(this.baseUrl, endpoints.filter.lookUpFilter, { idPage });
|
|
27
|
+
|
|
28
|
+
const params = {
|
|
29
|
+
query: encodeURIComponent(JSON.stringify(query)),
|
|
30
|
+
idsOfMultipleNodesToSearch: encodeURIComponent(JSON.stringify(idsOfMultipleNodesToSearch)),
|
|
31
|
+
returnCount: returnCount,
|
|
32
|
+
};
|
|
33
|
+
return axios.get(url, { params: params, headers: this.headers });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public async runCustomMongoAggregationQuery(type: string, customMongoQuery: string) {
|
|
37
|
+
const url = UtilsService.getUrl(this.baseUrl, endpoints.filter.runCustomAggregationQuery);
|
|
38
|
+
const body = { customMongoQuery, type };
|
|
39
|
+
return axios.post(url, body, { headers: this.headers });
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { endpoints } from "../common/endpoints";
|
|
3
|
+
import { GoogleCalendarI } from "../common/interfaces";
|
|
4
|
+
import { UtilsService } from "../utils";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export class GoogleService {
|
|
10
|
+
|
|
11
|
+
private headers: any;
|
|
12
|
+
private baseUrl: string;
|
|
13
|
+
|
|
14
|
+
constructor(baseUrl: string, headers: any) {
|
|
15
|
+
this.headers = headers
|
|
16
|
+
this.baseUrl = baseUrl;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public async getGoogleAccountEmails(accountEmail: string) {
|
|
20
|
+
|
|
21
|
+
const url = UtilsService.getUrl(this.baseUrl, endpoints.googleIntegration.getEmails, {});
|
|
22
|
+
const params = { userEmail: accountEmail };
|
|
23
|
+
return axios.get(url, { params: params, headers: this.headers });
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public async googleAccountSendEmail(accountEmail: string, body: {to: string, subject: string, message: string}) {
|
|
27
|
+
|
|
28
|
+
const url = UtilsService.getUrl(this.baseUrl, endpoints.googleIntegration.sendEmail, {});
|
|
29
|
+
const params = { userEmail: accountEmail };
|
|
30
|
+
return axios.post(url, body, { params: params, headers: this.headers });
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public async getGoogleCalendarEvents(accountEmail: string) {
|
|
34
|
+
|
|
35
|
+
const url = UtilsService.getUrl(this.baseUrl, endpoints.googleIntegration.getCalendarEvents, {});
|
|
36
|
+
const params = { userEmail: accountEmail };
|
|
37
|
+
return axios.get(url, { params: params, headers: this.headers });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public async createCalendarEvent(accountEmail: string, body: GoogleCalendarI) {
|
|
41
|
+
|
|
42
|
+
const url = UtilsService.getUrl(this.baseUrl, endpoints.googleIntegration.createCalendarEvent, {});
|
|
43
|
+
const params = { userEmail: accountEmail };
|
|
44
|
+
return axios.post(url, body, { params: params, headers: this.headers });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import axios, { AxiosResponse } from "axios";
|
|
2
|
+
import { Completion } from "openai/resources";
|
|
3
|
+
import { ChatCompletionCreateParamsBase } from "openai/resources/chat/completions";
|
|
4
|
+
import { CompletionCreateParamsBase } from "openai/resources/completions";
|
|
5
|
+
import { UtilsService } from "../utils";
|
|
6
|
+
import { endpoints } from "../common/endpoints";
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export class OpenaiService {
|
|
10
|
+
|
|
11
|
+
private headers: any;
|
|
12
|
+
private baseUrl: string;
|
|
13
|
+
|
|
14
|
+
constructor(baseUrl: string, headers: any) {
|
|
15
|
+
this.headers = headers
|
|
16
|
+
this.baseUrl = baseUrl;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @param body the openai completion body, more info here: https://platform.openai.com/docs/api-reference/completions/create
|
|
22
|
+
* @returns the completion provided by openai api
|
|
23
|
+
* @deprecated use createChatCompletion instead
|
|
24
|
+
*/
|
|
25
|
+
public async createCompletion(body: CompletionCreateParamsBase): Promise<AxiosResponse<{data:Completion}>> {
|
|
26
|
+
const url = UtilsService.getUrl(this.baseUrl, endpoints.openai.createCompletion);
|
|
27
|
+
const b = body;
|
|
28
|
+
return axios.post(url, b, { headers: this.headers });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
*
|
|
33
|
+
* @param body the openai chat completion body, more info here: https://platform.openai.com/docs/api-reference/chat/create
|
|
34
|
+
* @returns the chat completion provided by openai api
|
|
35
|
+
*/
|
|
36
|
+
public async createChatCompletion(body: ChatCompletionCreateParamsBase): Promise<AxiosResponse<{data:Completion}>> {
|
|
37
|
+
|
|
38
|
+
const url = UtilsService.getUrl(this.baseUrl, endpoints.openai.createChatCompletion);
|
|
39
|
+
const b = body;
|
|
40
|
+
return axios.post(url, b, { headers: this.headers });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
*
|
|
45
|
+
* @param body the openai chat completion body, more info here: https://platform.openai.com/docs/api-reference/chat/create
|
|
46
|
+
* @returns the chat completion provided by openai api
|
|
47
|
+
*/
|
|
48
|
+
public async generateImage(body: {prompt:string, size: '256x256' | '512x512' | '1024x1024', fileName: string}): Promise<AxiosResponse<{data:Completion}>> {
|
|
49
|
+
|
|
50
|
+
const url = UtilsService.getUrl(this.baseUrl, endpoints.openai.generateImage);
|
|
51
|
+
const b = body;
|
|
52
|
+
return axios.post(url, b, { headers: this.headers });
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
|
88
88
|
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
|
89
89
|
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
|
90
|
-
|
|
90
|
+
"strictPropertyInitialization": false, /* Check for class properties that are declared but not set in the constructor. */
|
|
91
91
|
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
|
92
92
|
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
|
93
93
|
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
package/utils.ts
ADDED