totalum-api-sdk 1.0.6 → 1.0.8

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.
Files changed (3) hide show
  1. package/index.js +47 -35
  2. package/index.ts +101 -71
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -1,27 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -37,7 +14,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
37
14
  Object.defineProperty(exports, "__esModule", { value: true });
38
15
  exports.TotalumApiSdk = void 0;
39
16
  const axios_1 = __importDefault(require("axios"));
40
- const qs = __importStar(require("qs"));
41
17
  // ENDPOINTS
42
18
  const endpoints = {
43
19
  crud: {
@@ -49,6 +25,18 @@ const endpoints = {
49
25
  deleteObjectAndSubElements: 'api/v1/crud/:typeId/:id/:pageId/subelements',
50
26
  updateLastUsersActions: 'api/v1/crud/:typeId/:id/lastUsersActions'
51
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
+ },
52
40
  };
53
41
  class TotalumApiSdk {
54
42
  constructor(authOptions) {
@@ -83,9 +71,8 @@ class TotalumApiSdk {
83
71
  }
84
72
  getItems(itemType, query) {
85
73
  return __awaiter(this, void 0, void 0, function* () {
86
- const queryString = qs.stringify(query);
87
74
  const url = this.getUrl(endpoints.crud.getObjects, { typeId: itemType });
88
- return axios_1.default.get(url, { params: queryString, headers: this.headers });
75
+ return axios_1.default.get(url, { params: query, headers: this.headers });
89
76
  });
90
77
  }
91
78
  deleteItemById(itemType, id) {
@@ -106,16 +93,41 @@ class TotalumApiSdk {
106
93
  return axios_1.default.post(url, item, { headers: this.headers });
107
94
  });
108
95
  }
109
- /**
110
- *
111
- * @param customMongoFilter an string with the mongo filter query
112
- * @param rootTypeId an string with the id of the element that we make the aggregation query
113
- * @param typeIdToGet the id of the type that we want to get
114
- * @param options
115
- * @param returnCount
116
- */
117
- customMongoFilter(customMongoFilter, rootTypeId, typeIdToGet, options, returnCount) {
96
+ generatePdfByTemplate(id, variables, name) {
97
+ return __awaiter(this, void 0, void 0, function* () {
98
+ const url = this.getUrl(endpoints.pdfTemplate.generatePdfByTemplate, { id });
99
+ return axios_1.default.post(url, { templateId: id, variables, name }, { headers: this.headers });
100
+ });
101
+ }
102
+ uploadFile(fileFormData) {
103
+ return __awaiter(this, void 0, void 0, function* () {
104
+ const url = this.getUrl(endpoints.files.uploadFile);
105
+ return axios_1.default.post(url, fileFormData, { headers: this.headers });
106
+ });
107
+ }
108
+ getDownloadUrl(fileName) {
109
+ return __awaiter(this, void 0, void 0, function* () {
110
+ const url = this.getUrl(endpoints.files.getDownloadUrl, { fileName });
111
+ return axios_1.default.get(url, { headers: this.headers });
112
+ });
113
+ }
114
+ customMongoFilter(customMongoFilter, rootTypeId, typeIdToGet, options) {
118
115
  return __awaiter(this, void 0, void 0, function* () {
116
+ const url = this.getUrl(endpoints.filter.customMongoFilter, {});
117
+ 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 };
118
+ const params = (options === null || options === void 0 ? void 0 : options.returnCount) ? { returnCount: options === null || options === void 0 ? void 0 : options.returnCount } : null;
119
+ return axios_1.default.post(url, body, { params: params, headers: this.headers });
120
+ });
121
+ }
122
+ lookUpFilter(idPage, query, idsOfMultipleNodesToSearch, returnCount) {
123
+ return __awaiter(this, void 0, void 0, function* () {
124
+ const url = this.getUrl(endpoints.filter.lookUpFilter, { idPage });
125
+ const params = {
126
+ query: encodeURIComponent(JSON.stringify(query)),
127
+ idsOfMultipleNodesToSearch: encodeURIComponent(JSON.stringify(idsOfMultipleNodesToSearch)),
128
+ returnCount: returnCount,
129
+ };
130
+ return axios_1.default.get(url, { params: params, headers: this.headers });
119
131
  });
120
132
  }
121
133
  }
package/index.ts CHANGED
@@ -21,9 +21,9 @@ export interface FilterSearchQueryI {
21
21
 
22
22
  export type FilterLookupSearchQueryI = {
23
23
  pagination: {
24
- limit?: number;
25
- page?: number;
26
- skip?: number;
24
+ limit?: number;
25
+ page?: number;
26
+ skip?: number;
27
27
  };
28
28
  filters: FilterStructureLevelsI
29
29
  };
@@ -39,12 +39,12 @@ export interface ISearchQueryFilterOr {
39
39
  or: ISearchQueryFilterOptions[]
40
40
  }
41
41
 
42
- export interface ISearchQuerySort{
43
- [key : string]: 1 | -1
42
+ export interface ISearchQuerySort {
43
+ [key: string]: 1 | -1
44
44
  }
45
45
 
46
46
  export interface ISearchQueryFilterOptions {
47
- [key : string]: number | Date | boolean | string | PropertyQueryOptionsI
47
+ [key: string]: number | Date | boolean | string | PropertyQueryOptionsI
48
48
  }
49
49
 
50
50
  export interface PropertyQueryOptionsI {
@@ -74,7 +74,7 @@ export interface DataValues {
74
74
  }
75
75
 
76
76
  export interface DataProperties {
77
- [key: string] : {
77
+ [key: string]: {
78
78
  value: fieldValuesEnabled,
79
79
  },
80
80
  }
@@ -91,85 +91,115 @@ const endpoints = {
91
91
  deleteObjectAndSubElements: 'api/v1/crud/:typeId/:id/:pageId/subelements',
92
92
  updateLastUsersActions: 'api/v1/crud/:typeId/:id/lastUsersActions'
93
93
  },
94
+ files: {
95
+ uploadFile: 'api/v1/files/upload',
96
+ getDownloadUrl: 'api/v1/files/download/:fileName',
97
+ deleteFile: 'api/v1/files/:fileName',
98
+ },
99
+ filter: {
100
+ lookUpFilter: 'api/v1/filter/:idPage',
101
+ customMongoFilter: 'api/v1/filter/custom-mongo-filter'
102
+ },
103
+ pdfTemplate: {
104
+ generatePdfByTemplate: 'api/v1/pdf-template/generatePdfByTemplate/:id'
105
+ },
94
106
  }
95
107
 
96
108
  export interface AuthOptions {
97
- token?:{
109
+ token?: {
98
110
  accessToken: string
99
- },
111
+ },
100
112
  apiKey?: {
101
- apiKey:string,
102
- apiKeyName:string,
103
- organizationId:string,
113
+ apiKey: string,
114
+ apiKeyName: string,
115
+ organizationId: string,
104
116
  }
105
117
  }
106
118
 
107
119
  export class TotalumApiSdk {
108
- public baseUrl= 'https://api.totalum.app/';
109
- private authOptions: AuthOptions;
110
- private headers: {[key:string]: string};
111
-
112
- constructor(authOptions: AuthOptions) {
113
- this.authOptions = authOptions;
114
- if (this.authOptions.token?.accessToken){
115
- this.headers = {
116
- authorization: this.authOptions.token.accessToken
120
+ public baseUrl = 'https://api.totalum.app/';
121
+ private authOptions: AuthOptions;
122
+ private headers: { [key: string]: string };
123
+
124
+ constructor(authOptions: AuthOptions) {
125
+ this.authOptions = authOptions;
126
+ if (this.authOptions.token?.accessToken) {
127
+ this.headers = {
128
+ authorization: this.authOptions.token.accessToken
129
+ }
130
+ } else if (this.authOptions.apiKey?.apiKey && this.authOptions.apiKey?.organizationId) {
131
+ this.headers = {
132
+ 'api-key': this.authOptions.apiKey.apiKey,
133
+ 'organization-id': this.authOptions.apiKey.organizationId,
134
+ 'api-key-name': this.authOptions.apiKey.apiKeyName
135
+ }
136
+ } else {
137
+ throw new Error('Error: invalid auth options')
117
138
  }
118
- } else if(this.authOptions.apiKey?.apiKey && this.authOptions.apiKey?.organizationId) {
119
- this.headers = {
120
- 'api-key': this.authOptions.apiKey.apiKey,
121
- 'organization-id': this.authOptions.apiKey.organizationId,
122
- 'api-key-name': this.authOptions.apiKey.apiKeyName
139
+ }
140
+
141
+ public changeBaseUrl(newBaseUrl: string) {
142
+ this.baseUrl = newBaseUrl;
143
+ }
144
+
145
+ private getUrl(pattern: string, params?: any): string {
146
+ let url = this.baseUrl + pattern;
147
+ for (const key in params) {
148
+ url = url.replace(`:${key}`, params[key]);
123
149
  }
124
- } else {
125
- throw new Error('Error: invalid auth options')
150
+ return url;
151
+ }
152
+
153
+ public async getItems(itemType: string, query?: FilterSearchQueryI) {
154
+ const url = this.getUrl(endpoints.crud.getObjects, { typeId: itemType });
155
+ return axios.get(url, { params: query, headers: this.headers });
156
+ }
157
+
158
+ public async deleteItemById(itemType: string, id: string) {
159
+ const url = this.getUrl(endpoints.crud.deleteObject, { typeId: itemType, id });
160
+ return axios.delete(url, { headers: this.headers });
161
+ }
162
+
163
+ public async editItemById(itemType: string, id: string, properties: any) {
164
+ const url = this.getUrl(endpoints.crud.editObjectProperties, { typeId: itemType, id });
165
+ return axios.patch(url, properties, { headers: this.headers });
126
166
  }
127
- }
128
167
 
129
- public changeBaseUrl(newBaseUrl:string){
130
- this.baseUrl = newBaseUrl;
131
- }
168
+ public async createItem(itemType: string, item: DataProperties) {
169
+ const url = this.getUrl(endpoints.crud.createObject, { typeId: itemType });
170
+ return axios.post(url, item, { headers: this.headers });
171
+ }
172
+
173
+ public async generatePdfByTemplate(id: string, variables: { [variableName: string]: any }, name: string) {
174
+ const url = this.getUrl(endpoints.pdfTemplate.generatePdfByTemplate, { id });
175
+ return axios.post(url, { templateId: id, variables, name }, { headers: this.headers });
176
+ }
132
177
 
133
- private getUrl(pattern: string, params?: any): string {
134
- let url = this.baseUrl + pattern;
135
- for (const key in params) {
136
- url = url.replace(`:${key}`, params[key]);
178
+ public async uploadFile(fileFormData: any) {
179
+ const url = this.getUrl(endpoints.files.uploadFile);
180
+ return axios.post(url, fileFormData, { headers: this.headers });
137
181
  }
138
- return url;
139
- }
140
-
141
- public async getItems(itemType:string, query?:FilterSearchQueryI){
142
- const queryString = qs.stringify(query);
143
- const url = this.getUrl(endpoints.crud.getObjects, {typeId: itemType});
144
- return axios.get(url, { params: queryString, headers: this.headers });
145
- }
146
-
147
- public async deleteItemById(itemType:string, id:string){
148
- const url = this.getUrl(endpoints.crud.deleteObject, {typeId: itemType, id});
149
- return axios.delete(url, {headers: this.headers});
150
- }
151
-
152
- public async editItemById(itemType:string, id:string, properties:any){
153
- const url = this.getUrl(endpoints.crud.editObjectProperties, {typeId:itemType, id});
154
- return axios.patch(url, properties, {headers: this.headers});
155
- }
156
-
157
- public async createItem(itemType:string, item:DataProperties){
158
- const url = this.getUrl(endpoints.crud.createObject, {typeId: itemType});
159
- return axios.post(url, item, {headers: this.headers});
160
- }
161
-
162
- /**
163
- *
164
- * @param customMongoFilter an string with the mongo filter query
165
- * @param rootTypeId an string with the id of the element that we make the aggregation query
166
- * @param typeIdToGet the id of the type that we want to get
167
- * @param options
168
- * @param returnCount
169
- */
170
- public async customMongoFilter(customMongoFilter: string,rootTypeId:string, typeIdToGet:string, options?: {variables: any, pagination?: any, sort: any}, returnCount?:boolean){
171
-
172
- }
173
182
 
183
+ public async getDownloadUrl(fileName: string) {
184
+ const url = this.getUrl(endpoints.files.getDownloadUrl, { fileName });
185
+ return axios.get(url, { headers: this.headers });
186
+ }
187
+
188
+ public async customMongoFilter(customMongoFilter: string, rootTypeId: string, typeIdToGet: string, options?: { variables?: any, pagination?: any, sort?: any, returnCount?: boolean }) {
189
+ const url = this.getUrl(endpoints.filter.customMongoFilter, {});
190
+ const body = { sort: options?.sort, variables: options?.variables, customMongoFilter, pagination: options?.pagination, rootTypeId, typeIdToGet };
191
+ const params = options?.returnCount ? { returnCount: options?.returnCount } : null;
192
+ return axios.post(url, body, { params: params, headers: this.headers });
193
+ }
194
+
195
+ public async lookUpFilter(idPage: string, query: FilterLookupSearchQueryI, idsOfMultipleNodesToSearch?: string[], returnCount?: boolean) {
196
+ const url = this.getUrl(endpoints.filter.lookUpFilter, { idPage });
197
+ const params = {
198
+ query: encodeURIComponent(JSON.stringify(query)),
199
+ idsOfMultipleNodesToSearch: encodeURIComponent(JSON.stringify(idsOfMultipleNodesToSearch)),
200
+ returnCount: returnCount,
201
+ };
202
+ return axios.get(url, { params: params, headers: this.headers });
203
+ }
174
204
 
175
205
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "totalum-api-sdk",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "Totalum sdk wraper of totalum api",
5
5
  "main": "index.js",
6
6
  "scripts": {