totalum-api-sdk 1.0.13 → 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 -157
- package/index.ts +33 -314
- 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,62 +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
|
-
runCustomAggregationQuery: 'api/v1/filter/custom-mongo-aggregation-query'
|
|
37
|
-
},
|
|
38
|
-
pdfTemplate: {
|
|
39
|
-
generatePdfByTemplate: 'api/v1/pdf-template/generatePdfByTemplate/:id'
|
|
40
|
-
},
|
|
41
|
-
googleIntegration: {
|
|
42
|
-
getEmails: 'api/v1/google-integration/get-emails',
|
|
43
|
-
sendEmail: 'api/v1/google-integration/send-email',
|
|
44
|
-
getCalendarEvents: 'api/v1/google-integration/get-calendar-events',
|
|
45
|
-
createCalendarEvent: 'api/v1/google-integration/create-calendar-event',
|
|
46
|
-
}
|
|
47
|
-
};
|
|
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");
|
|
48
9
|
class TotalumApiSdk {
|
|
49
10
|
constructor(authOptions) {
|
|
50
11
|
var _a, _b, _c;
|
|
51
|
-
this.
|
|
12
|
+
this._baseUrl = 'https://api.totalum.app/';
|
|
52
13
|
this.authOptions = authOptions;
|
|
53
14
|
if ((_a = this.authOptions.token) === null || _a === void 0 ? void 0 : _a.accessToken) {
|
|
54
|
-
this.
|
|
15
|
+
this._headers = {
|
|
55
16
|
authorization: this.authOptions.token.accessToken
|
|
56
17
|
};
|
|
57
18
|
}
|
|
58
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)) {
|
|
59
|
-
this.
|
|
20
|
+
this._headers = {
|
|
60
21
|
'api-key': this.authOptions.apiKey.apiKey,
|
|
61
22
|
'organization-id': this.authOptions.apiKey.organizationId,
|
|
62
23
|
'api-key-name': this.authOptions.apiKey.apiKeyName
|
|
@@ -65,118 +26,22 @@ class TotalumApiSdk {
|
|
|
65
26
|
else {
|
|
66
27
|
throw new Error('Error: invalid auth options');
|
|
67
28
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
this.baseUrl = newBaseUrl;
|
|
71
|
-
}
|
|
72
|
-
getUrl(pattern, params) {
|
|
73
|
-
let url = this.baseUrl + pattern;
|
|
74
|
-
for (const key in params) {
|
|
75
|
-
url = url.replace(`:${key}`, params[key]);
|
|
29
|
+
if (this.authOptions.baseUrl) {
|
|
30
|
+
this._baseUrl = this.authOptions.baseUrl;
|
|
76
31
|
}
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
getItemById(itemType, id) {
|
|
80
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
-
const url = this.getUrl(endpoints.crud.getObjectById, { typeId: itemType, id });
|
|
82
|
-
return axios_1.default.get(url, { headers: this.headers });
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
getItems(itemType, query) {
|
|
86
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
-
const url = this.getUrl(endpoints.crud.getObjects, { typeId: itemType });
|
|
88
|
-
return axios_1.default.get(url, { params: query, headers: this.headers });
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
deleteItemById(itemType, id) {
|
|
92
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
-
const url = this.getUrl(endpoints.crud.deleteObject, { typeId: itemType, id });
|
|
94
|
-
return axios_1.default.delete(url, { headers: this.headers });
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
editItemById(itemType, id, properties) {
|
|
98
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
99
|
-
const url = this.getUrl(endpoints.crud.editObjectProperties, { typeId: itemType, id });
|
|
100
|
-
return axios_1.default.patch(url, properties, { headers: this.headers });
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
createItem(itemType, item) {
|
|
104
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
-
const url = this.getUrl(endpoints.crud.createObject, { typeId: itemType });
|
|
106
|
-
return axios_1.default.post(url, item, { headers: this.headers });
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
generatePdfByTemplate(id, variables, name) {
|
|
110
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
-
const url = this.getUrl(endpoints.pdfTemplate.generatePdfByTemplate, { id });
|
|
112
|
-
return axios_1.default.post(url, { templateId: id, variables, name }, { headers: this.headers });
|
|
113
|
-
});
|
|
32
|
+
this.setRequestData();
|
|
114
33
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
customMongoFilter(customMongoFilter, rootTypeId, typeIdToGet, options) {
|
|
128
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
-
const url = this.getUrl(endpoints.filter.customMongoFilter, {});
|
|
130
|
-
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 };
|
|
131
|
-
const params = (options === null || options === void 0 ? void 0 : options.returnCount) ? { returnCount: options === null || options === void 0 ? void 0 : options.returnCount } : null;
|
|
132
|
-
return axios_1.default.post(url, body, { params: params, headers: this.headers });
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
getGoogleAccountEmails(accountEmail) {
|
|
136
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
-
const url = this.getUrl(endpoints.googleIntegration.getEmails, {});
|
|
138
|
-
const params = { userEmail: accountEmail };
|
|
139
|
-
return axios_1.default.get(url, { params: params, headers: this.headers });
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
googleAccountSendEmail(accountEmail, body) {
|
|
143
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
144
|
-
const url = this.getUrl(endpoints.googleIntegration.sendEmail, {});
|
|
145
|
-
const params = { userEmail: accountEmail };
|
|
146
|
-
return axios_1.default.post(url, body, { params: params, headers: this.headers });
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
getGoogleCalendarEvents(accountEmail) {
|
|
150
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
151
|
-
const url = this.getUrl(endpoints.googleIntegration.getCalendarEvents, {});
|
|
152
|
-
const params = { userEmail: accountEmail };
|
|
153
|
-
return axios_1.default.get(url, { params: params, headers: this.headers });
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
createCalendarEvent(accountEmail, body) {
|
|
157
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
158
|
-
const url = this.getUrl(endpoints.googleIntegration.createCalendarEvent, {});
|
|
159
|
-
const params = { userEmail: accountEmail };
|
|
160
|
-
return axios_1.default.post(url, body, { params: params, headers: this.headers });
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
lookUpFilter(idPage, query, idsOfMultipleNodesToSearch, returnCount) {
|
|
164
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
165
|
-
const url = this.getUrl(endpoints.filter.lookUpFilter, { idPage });
|
|
166
|
-
const params = {
|
|
167
|
-
query: encodeURIComponent(JSON.stringify(query)),
|
|
168
|
-
idsOfMultipleNodesToSearch: encodeURIComponent(JSON.stringify(idsOfMultipleNodesToSearch)),
|
|
169
|
-
returnCount: returnCount,
|
|
170
|
-
};
|
|
171
|
-
return axios_1.default.get(url, { params: params, headers: this.headers });
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
runCustomMongoAggregationQuery(type, customMongoQuery) {
|
|
175
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
176
|
-
const url = this.getUrl(endpoints.filter.runCustomAggregationQuery);
|
|
177
|
-
const body = { customMongoQuery, type };
|
|
178
|
-
return axios_1.default.post(url, body, { headers: this.headers });
|
|
179
|
-
});
|
|
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);
|
|
180
45
|
}
|
|
181
46
|
}
|
|
182
47
|
exports.TotalumApiSdk = TotalumApiSdk;
|
package/index.ts
CHANGED
|
@@ -1,237 +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
|
-
|
|
102
|
-
|
|
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
14
|
|
|
134
|
-
export type FiltersArrayI = Array<ISearchQueryFilterOr | ISearchQueryFilterOptions>;
|
|
135
15
|
|
|
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
|
-
runCustomAggregationQuery: 'api/v1/filter/custom-mongo-aggregation-query'
|
|
199
|
-
},
|
|
200
|
-
pdfTemplate: {
|
|
201
|
-
generatePdfByTemplate: 'api/v1/pdf-template/generatePdfByTemplate/:id'
|
|
202
|
-
},
|
|
203
|
-
googleIntegration: {
|
|
204
|
-
getEmails: 'api/v1/google-integration/get-emails',
|
|
205
|
-
sendEmail: 'api/v1/google-integration/send-email',
|
|
206
|
-
getCalendarEvents: 'api/v1/google-integration/get-calendar-events',
|
|
207
|
-
createCalendarEvent: 'api/v1/google-integration/create-calendar-event',
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
export interface AuthOptions {
|
|
212
|
-
token?: {
|
|
213
|
-
accessToken: string
|
|
214
|
-
},
|
|
215
|
-
apiKey?: {
|
|
216
|
-
apiKey: string,
|
|
217
|
-
apiKeyName: string,
|
|
218
|
-
organizationId: string,
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
16
|
|
|
222
17
|
export class TotalumApiSdk {
|
|
223
|
-
public baseUrl = 'https://api.totalum.app/';
|
|
224
18
|
private authOptions: AuthOptions;
|
|
225
|
-
|
|
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;
|
|
226
27
|
|
|
227
28
|
constructor(authOptions: AuthOptions) {
|
|
228
29
|
this.authOptions = authOptions;
|
|
229
30
|
if (this.authOptions.token?.accessToken) {
|
|
230
|
-
this.
|
|
31
|
+
this._headers = {
|
|
231
32
|
authorization: this.authOptions.token.accessToken
|
|
232
33
|
}
|
|
233
34
|
} else if (this.authOptions.apiKey?.apiKey && this.authOptions.apiKey?.organizationId) {
|
|
234
|
-
this.
|
|
35
|
+
this._headers = {
|
|
235
36
|
'api-key': this.authOptions.apiKey.apiKey,
|
|
236
37
|
'organization-id': this.authOptions.apiKey.organizationId,
|
|
237
38
|
'api-key-name': this.authOptions.apiKey.apiKeyName
|
|
@@ -239,107 +40,25 @@ export class TotalumApiSdk {
|
|
|
239
40
|
} else {
|
|
240
41
|
throw new Error('Error: invalid auth options')
|
|
241
42
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
public changeBaseUrl(newBaseUrl: string) {
|
|
245
|
-
this.baseUrl = newBaseUrl;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
private getUrl(pattern: string, params?: any): string {
|
|
249
|
-
let url = this.baseUrl + pattern;
|
|
250
|
-
for (const key in params) {
|
|
251
|
-
url = url.replace(`:${key}`, params[key]);
|
|
43
|
+
if (this.authOptions.baseUrl) {
|
|
44
|
+
this._baseUrl = this.authOptions.baseUrl;
|
|
252
45
|
}
|
|
253
|
-
|
|
46
|
+
this.setRequestData();
|
|
254
47
|
}
|
|
255
48
|
|
|
256
|
-
public
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
public async getItems(itemType: string, query?: FilterSearchQueryI) {
|
|
262
|
-
const url = this.getUrl(endpoints.crud.getObjects, { typeId: itemType });
|
|
263
|
-
return axios.get(url, { params: query, headers: this.headers });
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
public async deleteItemById(itemType: string, id: string) {
|
|
267
|
-
const url = this.getUrl(endpoints.crud.deleteObject, { typeId: itemType, id });
|
|
268
|
-
return axios.delete(url, { headers: this.headers });
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
public async editItemById(itemType: string, id: string, properties: any) {
|
|
272
|
-
const url = this.getUrl(endpoints.crud.editObjectProperties, { typeId: itemType, id });
|
|
273
|
-
return axios.patch(url, properties, { headers: this.headers });
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
public async createItem(itemType: string, item: DataProperties) {
|
|
277
|
-
const url = this.getUrl(endpoints.crud.createObject, { typeId: itemType });
|
|
278
|
-
return axios.post(url, item, { headers: this.headers });
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
public async generatePdfByTemplate(id: string, variables: { [variableName: string]: any }, name: string) {
|
|
282
|
-
const url = this.getUrl(endpoints.pdfTemplate.generatePdfByTemplate, { id });
|
|
283
|
-
return axios.post(url, { templateId: id, variables, name }, { headers: this.headers });
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
public async uploadFile(fileFormData: any) {
|
|
287
|
-
const url = this.getUrl(endpoints.files.uploadFile);
|
|
288
|
-
return axios.post(url, fileFormData, { headers: this.headers });
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
public async getDownloadUrl(fileName: string) {
|
|
292
|
-
const url = this.getUrl(endpoints.files.getDownloadUrl, { fileName });
|
|
293
|
-
return axios.get(url, { headers: this.headers });
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
public async customMongoFilter(customMongoFilter: string, rootTypeId: string, typeIdToGet: string, options?: { variables?: any, pagination?: any, sort?: any, returnCount?: boolean }) {
|
|
297
|
-
const url = this.getUrl(endpoints.filter.customMongoFilter, {});
|
|
298
|
-
const body = { sort: options?.sort, variables: options?.variables, customMongoFilter, pagination: options?.pagination, rootTypeId, typeIdToGet };
|
|
299
|
-
const params = options?.returnCount ? { returnCount: options?.returnCount } : null;
|
|
300
|
-
return axios.post(url, body, { params: params, headers: this.headers });
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
public async getGoogleAccountEmails(accountEmail: string) {
|
|
304
|
-
const url = this.getUrl(endpoints.googleIntegration.getEmails, {});
|
|
305
|
-
const params = { userEmail: accountEmail };
|
|
306
|
-
return axios.get(url, { params: params, headers: this.headers });
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
public async googleAccountSendEmail(accountEmail: string, body: {to: string, subject: string, message: string}) {
|
|
310
|
-
const url = this.getUrl(endpoints.googleIntegration.sendEmail, {});
|
|
311
|
-
const params = { userEmail: accountEmail };
|
|
312
|
-
return axios.post(url, body, { params: params, headers: this.headers });
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
public async getGoogleCalendarEvents(accountEmail: string) {
|
|
316
|
-
const url = this.getUrl(endpoints.googleIntegration.getCalendarEvents, {});
|
|
317
|
-
const params = { userEmail: accountEmail };
|
|
318
|
-
return axios.get(url, { params: params, headers: this.headers });
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
public async createCalendarEvent(accountEmail: string, body: GoogleCalendarI) {
|
|
322
|
-
const url = this.getUrl(endpoints.googleIntegration.createCalendarEvent, {});
|
|
323
|
-
const params = { userEmail: accountEmail };
|
|
324
|
-
return axios.post(url, body, { params: params, headers: this.headers });
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
public async lookUpFilter(idPage: string, query: FilterLookupSearchQueryI, idsOfMultipleNodesToSearch?: string[], returnCount?: boolean) {
|
|
328
|
-
const url = this.getUrl(endpoints.filter.lookUpFilter, { idPage });
|
|
329
|
-
const params = {
|
|
330
|
-
query: encodeURIComponent(JSON.stringify(query)),
|
|
331
|
-
idsOfMultipleNodesToSearch: encodeURIComponent(JSON.stringify(idsOfMultipleNodesToSearch)),
|
|
332
|
-
returnCount: returnCount,
|
|
333
|
-
};
|
|
334
|
-
return axios.get(url, { params: params, headers: this.headers });
|
|
49
|
+
public changeBaseUrl(newBaseUrl: string) {
|
|
50
|
+
this._baseUrl = newBaseUrl;
|
|
51
|
+
//update services with new implementation
|
|
52
|
+
this.setRequestData();
|
|
335
53
|
}
|
|
336
54
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
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);
|
|
341
61
|
}
|
|
342
62
|
|
|
343
63
|
|
|
344
|
-
|
|
345
|
-
}
|
|
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