totalum-api-sdk 1.0.6 → 1.0.7

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 +46 -9
  2. package/index.ts +102 -71
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -49,6 +49,18 @@ const endpoints = {
49
49
  deleteObjectAndSubElements: 'api/v1/crud/:typeId/:id/:pageId/subelements',
50
50
  updateLastUsersActions: 'api/v1/crud/:typeId/:id/lastUsersActions'
51
51
  },
52
+ files: {
53
+ uploadFile: 'api/v1/files/upload',
54
+ getDownloadUrl: 'api/v1/files/download/:fileName',
55
+ deleteFile: 'api/v1/files/:fileName',
56
+ },
57
+ filter: {
58
+ lookUpFilter: 'api/v1/filter/:idPage',
59
+ customMongoFilter: 'api/v1/filter/custom-mongo-filter'
60
+ },
61
+ pdfTemplate: {
62
+ generatePdfByTemplate: 'api/v1/pdf-template/generatePdfByTemplate/:id'
63
+ },
52
64
  };
53
65
  class TotalumApiSdk {
54
66
  constructor(authOptions) {
@@ -106,16 +118,41 @@ class TotalumApiSdk {
106
118
  return axios_1.default.post(url, item, { headers: this.headers });
107
119
  });
108
120
  }
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) {
121
+ generatePdfByTemplate(id, variables, name) {
122
+ return __awaiter(this, void 0, void 0, function* () {
123
+ const url = this.getUrl(endpoints.pdfTemplate.generatePdfByTemplate, { id });
124
+ return axios_1.default.post(url, { templateId: id, variables, name }, { headers: this.headers });
125
+ });
126
+ }
127
+ uploadFile(fileFormData) {
128
+ return __awaiter(this, void 0, void 0, function* () {
129
+ const url = this.getUrl(endpoints.files.uploadFile);
130
+ return axios_1.default.post(url, fileFormData, { headers: this.headers });
131
+ });
132
+ }
133
+ getDownloadUrl(fileName) {
134
+ return __awaiter(this, void 0, void 0, function* () {
135
+ const url = this.getUrl(endpoints.files.getDownloadUrl, { fileName });
136
+ return axios_1.default.get(url, { headers: this.headers });
137
+ });
138
+ }
139
+ customMongoFilter(customMongoFilter, rootTypeId, typeIdToGet, options) {
118
140
  return __awaiter(this, void 0, void 0, function* () {
141
+ const url = this.getUrl(endpoints.filter.customMongoFilter, {});
142
+ 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 };
143
+ const params = (options === null || options === void 0 ? void 0 : options.returnCount) ? { returnCount: options === null || options === void 0 ? void 0 : options.returnCount } : null;
144
+ return axios_1.default.post(url, body, { params: params, headers: this.headers });
145
+ });
146
+ }
147
+ lookUpFilter(idPage, query, idsOfMultipleNodesToSearch, returnCount) {
148
+ return __awaiter(this, void 0, void 0, function* () {
149
+ const url = this.getUrl(endpoints.filter.lookUpFilter, { idPage });
150
+ const params = {
151
+ query: encodeURIComponent(JSON.stringify(query)),
152
+ idsOfMultipleNodesToSearch: encodeURIComponent(JSON.stringify(idsOfMultipleNodesToSearch)),
153
+ returnCount: returnCount,
154
+ };
155
+ return axios_1.default.get(url, { params: params, headers: this.headers });
119
156
  });
120
157
  }
121
158
  }
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,116 @@ 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 queryString = qs.stringify(query);
155
+ const url = this.getUrl(endpoints.crud.getObjects, { typeId: itemType });
156
+ return axios.get(url, { params: queryString, headers: this.headers });
157
+ }
158
+
159
+ public async deleteItemById(itemType: string, id: string) {
160
+ const url = this.getUrl(endpoints.crud.deleteObject, { typeId: itemType, id });
161
+ return axios.delete(url, { headers: this.headers });
162
+ }
163
+
164
+ public async editItemById(itemType: string, id: string, properties: any) {
165
+ const url = this.getUrl(endpoints.crud.editObjectProperties, { typeId: itemType, id });
166
+ return axios.patch(url, properties, { headers: this.headers });
126
167
  }
127
- }
128
168
 
129
- public changeBaseUrl(newBaseUrl:string){
130
- this.baseUrl = newBaseUrl;
131
- }
169
+ public async createItem(itemType: string, item: DataProperties) {
170
+ const url = this.getUrl(endpoints.crud.createObject, { typeId: itemType });
171
+ return axios.post(url, item, { headers: this.headers });
172
+ }
173
+
174
+ public async generatePdfByTemplate(id: string, variables: { [variableName: string]: any }, name: string) {
175
+ const url = this.getUrl(endpoints.pdfTemplate.generatePdfByTemplate, { id });
176
+ return axios.post(url, { templateId: id, variables, name }, { headers: this.headers });
177
+ }
132
178
 
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]);
179
+ public async uploadFile(fileFormData: any) {
180
+ const url = this.getUrl(endpoints.files.uploadFile);
181
+ return axios.post(url, fileFormData, { headers: this.headers });
137
182
  }
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
183
 
184
+ public async getDownloadUrl(fileName: string) {
185
+ const url = this.getUrl(endpoints.files.getDownloadUrl, { fileName });
186
+ return axios.get(url, { headers: this.headers });
187
+ }
188
+
189
+ public async customMongoFilter(customMongoFilter: string, rootTypeId: string, typeIdToGet: string, options?: { variables?: any, pagination?: any, sort?: any, returnCount?: boolean }) {
190
+ const url = this.getUrl(endpoints.filter.customMongoFilter, {});
191
+ const body = { sort: options?.sort, variables: options?.variables, customMongoFilter, pagination: options?.pagination, rootTypeId, typeIdToGet };
192
+ const params = options?.returnCount ? { returnCount: options?.returnCount } : null;
193
+ return axios.post(url, body, { params: params, headers: this.headers });
194
+ }
195
+
196
+ public async lookUpFilter(idPage: string, query: FilterLookupSearchQueryI, idsOfMultipleNodesToSearch?: string[], returnCount?: boolean) {
197
+ const url = this.getUrl(endpoints.filter.lookUpFilter, { idPage });
198
+ const params = {
199
+ query: encodeURIComponent(JSON.stringify(query)),
200
+ idsOfMultipleNodesToSearch: encodeURIComponent(JSON.stringify(idsOfMultipleNodesToSearch)),
201
+ returnCount: returnCount,
202
+ };
203
+ return axios.get(url, { params: params, headers: this.headers });
204
+ }
174
205
 
175
206
  }
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.7",
4
4
  "description": "Totalum sdk wraper of totalum api",
5
5
  "main": "index.js",
6
6
  "scripts": {