@veritree/services 1.5.0 → 2.0.0
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/package.json +1 -1
- package/src/endpoints/field-updates.js +13 -2
- package/src/endpoints/images.js +6 -0
- package/src/endpoints/orgs.js +12 -0
- package/src/helpers/api.js +7 -7
- package/src/helpers/team.js +46 -0
package/package.json
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import Api from "../helpers/api";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
class FieldUpdatesApi extends Api {
|
|
4
|
+
constructor(resource) {
|
|
5
|
+
super(resource);
|
|
6
|
+
this.resource = "field-updates";
|
|
7
|
+
}
|
|
4
8
|
|
|
5
|
-
|
|
9
|
+
async images(fieldUpdateId, args) {
|
|
10
|
+
const url = `${this.getUrl()}/${fieldUpdateId}/images${this.getUrlParams(args)}`;
|
|
11
|
+
|
|
12
|
+
return await this.get(url);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const FieldUpdates = new FieldUpdatesApi();
|
package/src/endpoints/images.js
CHANGED
|
@@ -6,6 +6,12 @@ class ImagesApi extends Api {
|
|
|
6
6
|
this.resource = "images";
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
rotate(id, data) {
|
|
10
|
+
const url = `${id}/rotate${this.getUrlParams()}`;
|
|
11
|
+
|
|
12
|
+
return this.update(url, data, 'patch');
|
|
13
|
+
}
|
|
14
|
+
|
|
9
15
|
relation(prefix, id) {
|
|
10
16
|
return Relations(this, prefix, id);
|
|
11
17
|
}
|
package/src/endpoints/orgs.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import Api from "../helpers/api";
|
|
2
|
+
import Team from "../helpers/team";
|
|
3
|
+
import { getSession } from "../helpers/session";
|
|
2
4
|
|
|
3
5
|
class OrgsApi extends Api {
|
|
4
6
|
constructor(resource) {
|
|
@@ -6,6 +8,16 @@ class OrgsApi extends Api {
|
|
|
6
8
|
this.resource = "orgs";
|
|
7
9
|
}
|
|
8
10
|
|
|
11
|
+
users() {
|
|
12
|
+
const { orgId } = getSession();
|
|
13
|
+
return Team(this, orgId);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async roles(orgId, params) {
|
|
17
|
+
const url = `${this.getUrl()}/${orgId}/roles${this.getUrlParams(params)}`;
|
|
18
|
+
return await this.get(url);
|
|
19
|
+
}
|
|
20
|
+
|
|
9
21
|
async stats() {
|
|
10
22
|
const url = `${this._geStatstUrl()}`;
|
|
11
23
|
return await this.get(url);
|
package/src/helpers/api.js
CHANGED
|
@@ -8,13 +8,13 @@ import { getSession } from "./session";
|
|
|
8
8
|
* @param {string} url
|
|
9
9
|
* @returns {string} url
|
|
10
10
|
*/
|
|
11
|
-
function
|
|
11
|
+
function addVersionArg(url) {
|
|
12
12
|
if (!url || url.includes("_result=1")) return url;
|
|
13
13
|
|
|
14
14
|
const urlHasArgs = url.includes("?");
|
|
15
|
-
const
|
|
15
|
+
const urlVersionArg = urlHasArgs ? "&_v=5.0.0" : "?_v=5.0.0";
|
|
16
16
|
|
|
17
|
-
return `${url}${
|
|
17
|
+
return `${url}${urlVersionArg}`;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
/**
|
|
@@ -91,7 +91,7 @@ export default class Api {
|
|
|
91
91
|
* @returns {promise}
|
|
92
92
|
*/
|
|
93
93
|
async create(data, args) {
|
|
94
|
-
return await this.post(null, data, args);
|
|
94
|
+
return await this.post(null, data, null, args);
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
/**
|
|
@@ -133,8 +133,8 @@ export default class Api {
|
|
|
133
133
|
* @param {object} data
|
|
134
134
|
* @returns {promise}
|
|
135
135
|
*/
|
|
136
|
-
async post(url, data, as) {
|
|
137
|
-
if (!url) url = `${this.getUrl()}${this.getUrlParams()}`;
|
|
136
|
+
async post(url, data, as, args) {
|
|
137
|
+
if (!url) url = `${this.getUrl()}${this.getUrlParams(args)}`;
|
|
138
138
|
return await this.unWrap(url, "post", data, as);
|
|
139
139
|
}
|
|
140
140
|
|
|
@@ -183,7 +183,7 @@ export default class Api {
|
|
|
183
183
|
* @returns {object} envelope
|
|
184
184
|
*/
|
|
185
185
|
async unWrap(url, method = "get", data, as) {
|
|
186
|
-
url =
|
|
186
|
+
url = addVersionArg(url);
|
|
187
187
|
const config = getConfig(method, data, as);
|
|
188
188
|
const response = await fetch(url, config);
|
|
189
189
|
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates an abstract team object that can be used
|
|
3
|
+
* for CRUD operations related to an org users.
|
|
4
|
+
*
|
|
5
|
+
* @param {object} api
|
|
6
|
+
* @param {number} id
|
|
7
|
+
* @returns {object}
|
|
8
|
+
*/
|
|
9
|
+
const Team = (api, id) => {
|
|
10
|
+
let url = `${api.baseUrl}/${api.resource}/${id}/users`;
|
|
11
|
+
|
|
12
|
+
const all = async (args) => {
|
|
13
|
+
url = `${url}${api.getUrlParams(args)}`;
|
|
14
|
+
return await api.get(url);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const single = async (userId, args) => {
|
|
18
|
+
url = `${url}/${userId}${api.getUrlParams(args)}`;
|
|
19
|
+
return await api.get(url);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const create = async (data) => {
|
|
23
|
+
url = `${url}${api.getUrlParams()}`;
|
|
24
|
+
return await api.post(url, data);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const update = async (userId, data) => {
|
|
28
|
+
url = `${url}/${userId}${api.getUrlParams()}`;
|
|
29
|
+
return await api.update(url, data, 'patch');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const remove = async (userId) => {
|
|
33
|
+
url = `${url}/${userId}${api.getUrlParams()}`;
|
|
34
|
+
return await api.post(url, null, "delete");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
all,
|
|
39
|
+
single,
|
|
40
|
+
create,
|
|
41
|
+
update,
|
|
42
|
+
delete: remove
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export default Team;
|