totalum-api-sdk 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.MD +65 -1
- package/index.ts +25 -5
- package/package.json +1 -1
package/README.MD
CHANGED
|
@@ -1,3 +1,67 @@
|
|
|
1
1
|
## Totalum api sdk wraper
|
|
2
2
|
|
|
3
|
-
This library wraps the totalum public api, so you can easy call all endpoints
|
|
3
|
+
This library wraps the totalum public api, so you can easy call all endpoints.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## Usage:
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm i totalum-api-sdk
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
We recomend you to use the api key instead of the token.
|
|
13
|
+
|
|
14
|
+
```javascript
|
|
15
|
+
// IN TYPESCRIPT
|
|
16
|
+
|
|
17
|
+
import {AuthOptions, TotalumApiSdk} from 'totalum-api-sdk';
|
|
18
|
+
|
|
19
|
+
// the auth using token
|
|
20
|
+
const options: AuthOptions = {
|
|
21
|
+
token:{
|
|
22
|
+
accessToken: 'YOUR TOKEN'
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// the auth using api key
|
|
27
|
+
const options: AuthOptions = {
|
|
28
|
+
apiKey:{
|
|
29
|
+
'api-key': 'your_api_key',
|
|
30
|
+
'api-key-name': 'your_api_key_name',
|
|
31
|
+
'organization-id': 'your_organization_id'
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const totalumClient = new TotalumApiSdk(options);
|
|
36
|
+
|
|
37
|
+
// execute some function
|
|
38
|
+
|
|
39
|
+
const result = await totalumClient.getItems('your_item', {});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
```javascript
|
|
43
|
+
// IN JAVASCRIPT
|
|
44
|
+
|
|
45
|
+
const totalum = require('totalum-api-sdk');
|
|
46
|
+
|
|
47
|
+
// the auth using token
|
|
48
|
+
const options = {
|
|
49
|
+
token:{
|
|
50
|
+
accessToken: 'YOUR TOKEN'
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// the auth using api key
|
|
55
|
+
const options: AuthOptions = {
|
|
56
|
+
apiKey:{
|
|
57
|
+
'api-key': 'your_api_key',
|
|
58
|
+
'api-key-name': 'your_api_key_name',
|
|
59
|
+
'organization-id': 'your_organization_id'
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const totalumClient = new totalum.TotalumApiSdk(options);
|
|
64
|
+
|
|
65
|
+
const result = await totalumClient.getItems('your_item', {});
|
|
66
|
+
|
|
67
|
+
```
|
package/index.ts
CHANGED
|
@@ -99,12 +99,13 @@ export interface AuthOptions {
|
|
|
99
99
|
},
|
|
100
100
|
apiKey?: {
|
|
101
101
|
apiKey:string,
|
|
102
|
-
|
|
102
|
+
apiKeyName:string,
|
|
103
|
+
organizationId:string,
|
|
103
104
|
}
|
|
104
105
|
}
|
|
105
106
|
|
|
106
107
|
export class TotalumApiSdk {
|
|
107
|
-
|
|
108
|
+
public baseUrl= 'https://api.totalum.app/';
|
|
108
109
|
private authOptions: AuthOptions;
|
|
109
110
|
private headers: {[key:string]: string};
|
|
110
111
|
|
|
@@ -116,13 +117,18 @@ export class TotalumApiSdk {
|
|
|
116
117
|
}
|
|
117
118
|
} else if(this.authOptions.apiKey?.apiKey && this.authOptions.apiKey?.organizationId) {
|
|
118
119
|
this.headers = {
|
|
119
|
-
|
|
120
|
-
|
|
120
|
+
'api-key': this.authOptions.apiKey.apiKey,
|
|
121
|
+
'organization-id': this.authOptions.apiKey.organizationId,
|
|
122
|
+
'api-key-name': this.authOptions.apiKey.apiKeyName
|
|
121
123
|
}
|
|
122
124
|
} else {
|
|
123
125
|
throw new Error('Error: invalid auth options')
|
|
124
126
|
}
|
|
125
|
-
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
public changeBaseUrl(newBaseUrl:string){
|
|
130
|
+
this.baseUrl = newBaseUrl;
|
|
131
|
+
}
|
|
126
132
|
|
|
127
133
|
private getUrl(pattern: string, params?: any): string {
|
|
128
134
|
let url = this.baseUrl + pattern;
|
|
@@ -152,4 +158,18 @@ export class TotalumApiSdk {
|
|
|
152
158
|
const url = this.getUrl(endpoints.crud.createObject, {typeId: itemType});
|
|
153
159
|
return axios.post(url, item, {headers: this.headers});
|
|
154
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
|
+
|
|
174
|
+
|
|
155
175
|
}
|