@veritree/services 2.13.2 → 2.13.3

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/index.js CHANGED
@@ -24,6 +24,7 @@ import { Users } from './src/endpoints/users';
24
24
  import { Roles } from './src/endpoints/roles';
25
25
  import { FieldReports } from './src/endpoints/field-reports';
26
26
  import { ExternalReports } from './src/endpoints/external-reports';
27
+ import { Evidence } from './src/endpoints/evidence';
27
28
  import { Crumbs } from './src/endpoints/crumbs';
28
29
 
29
30
  export {
@@ -53,5 +54,6 @@ export {
53
54
  Roles,
54
55
  FieldReports,
55
56
  ExternalReports,
57
+ Evidence,
56
58
  Crumbs
57
59
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veritree/services",
3
- "version": "2.13.2",
3
+ "version": "2.13.3",
4
4
  "description": "A collection of javascript functions/services to talk to veritree API",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -1,21 +1,20 @@
1
-
2
- import Api from '../helpers/api';
1
+ import Api from "../helpers/api";
3
2
 
4
3
  class CrumbsApi extends Api {
5
- constructor(resource) {
6
- super(resource);
7
- this.resource = 'crumbs';
8
- }
9
-
10
- mapData(crumbId) {
11
- const all = async() => {
12
- const url = `${this.getUrl()}/${crumbId}/map-data`;
13
- return await this.get(url);
14
- }
15
- return {
16
- all,
17
- };
18
- }
4
+ constructor(resource) {
5
+ super(resource);
6
+ this.resource = "crumbs";
7
+ }
8
+
9
+ mapData(crumbId) {
10
+ const all = async () => {
11
+ const url = `${this.getUrl()}/${crumbId}/map-data`;
12
+ return await this.get(url);
13
+ };
14
+ return {
15
+ all,
16
+ };
17
+ }
19
18
  }
20
19
 
21
20
  export const Crumbs = new CrumbsApi();
@@ -0,0 +1,10 @@
1
+ import Api from "../helpers/api";
2
+
3
+ class EvidenceApi extends Api {
4
+ constructor(resource) {
5
+ super(resource);
6
+ this.resource = "evidence";
7
+ }
8
+ }
9
+
10
+ export const Evidence = new EvidenceApi();
@@ -17,9 +17,15 @@ class FieldReportsApi extends Api {
17
17
  return await this.post(url, formData);
18
18
  };
19
19
 
20
+ const detachImage = async (evidenceId) => {
21
+ const url = `${this.getUrl()}/${fieldReportId}/evidence/images/${evidenceId}${this.getUrlParams()}`;
22
+ return await this.post(url, null, "delete");
23
+ };
24
+
20
25
  return {
21
26
  all,
22
- attach
27
+ attach,
28
+ detachImage
23
29
  }
24
30
  }
25
31
  }
@@ -1,5 +1,6 @@
1
1
  import Api from "../helpers/api";
2
2
  import Relations from "../helpers/relations";
3
+
3
4
  class ImagesApi extends Api {
4
5
  constructor(resource) {
5
6
  super(resource);
@@ -49,9 +49,7 @@ class SponsorsApi extends Api {
49
49
  };
50
50
 
51
51
  const imageUploadUrl = async () => {
52
- const url = `${this.getUrl()}/${
53
- this.orgId
54
- }/cms/image-upload-url${urlParams}`;
52
+ const url = `${this.getUrl()}/${this.orgId}/cms/image-upload-url${urlParams}`;
55
53
  return await this.get(url);
56
54
  };
57
55
 
@@ -66,6 +64,23 @@ class SponsorsApi extends Api {
66
64
  credentials,
67
65
  };
68
66
  }
67
+
68
+ tools(args) {
69
+ const get = async (sponsorId) => {
70
+ const url = `${this.getUrl()}/${sponsorId}/tools${this.getUrlParams(args)}`;
71
+ return await this.get(url);
72
+ }
73
+
74
+ const create = async (sponsorId, data) => {
75
+ const url = `${this.getUrl()}/${sponsorId}/tools`;
76
+ return await this.post(url, data);
77
+ }
78
+
79
+ return {
80
+ get,
81
+ create
82
+ }
83
+ }
69
84
  }
70
85
 
71
86
  export const Sponsors = new SponsorsApi();
@@ -39,6 +39,16 @@ class SubsitesApi extends Api {
39
39
  delete: remove,
40
40
  };
41
41
  }
42
+
43
+ stats(subsite, args) {
44
+ const all = async () => {
45
+ const url = `${this.getUrl()}/${subsite}/stats${this.getUrlParams(args)}`;
46
+ return await this.get(url);
47
+ };
48
+ return {
49
+ all,
50
+ };
51
+ }
42
52
  }
43
53
 
44
54
  export const Subsites = new SubsitesApi();
@@ -1,6 +1,6 @@
1
- import { getCookie } from "./cookies";
2
- import { createParamsStringFromArgs } from "../utils/args";
3
- import { getSession } from "./session";
1
+ import { getCookie } from './cookies';
2
+ import { createParamsStringFromArgs } from '../utils/args';
3
+ import { getSession } from './session';
4
4
 
5
5
  /**
6
6
  * Adds the envelope argument to the url
@@ -9,10 +9,10 @@ import { getSession } from "./session";
9
9
  * @returns {string} url
10
10
  */
11
11
  function addVersionArg(url) {
12
- if (!url || url.includes("_result=1")) return url;
12
+ if (!url || url.includes('_result=1')) return url;
13
13
 
14
- const urlHasArgs = url.includes("?");
15
- const urlVersionArg = urlHasArgs ? "&_v=5.0.0" : "?_v=5.0.0";
14
+ const urlHasArgs = url.includes('?');
15
+ const urlVersionArg = urlHasArgs ? '&_v=5.0.0' : '?_v=5.0.0';
16
16
 
17
17
  return `${url}${urlVersionArg}`;
18
18
  }
@@ -25,10 +25,10 @@ function addVersionArg(url) {
25
25
  * @returns {object} data
26
26
  */
27
27
  function getConfig(method, data, as) {
28
- const isGet = method === "get";
28
+ const isGet = method === 'get';
29
29
  const isSpoofing = as;
30
30
  const isFormData = data instanceof FormData;
31
- const accessToken = `Bearer ${getCookie("access_token")}`;
31
+ const accessToken = `Bearer ${getCookie('access_token')}`;
32
32
 
33
33
  const config = {
34
34
  method,
@@ -38,7 +38,7 @@ function getConfig(method, data, as) {
38
38
  };
39
39
 
40
40
  if (!isFormData) {
41
- config.headers["Content-Type"] = "application/json";
41
+ config.headers['Content-Type'] = 'application/json';
42
42
  }
43
43
 
44
44
  // TODO: improve this ifs and elses
@@ -46,7 +46,7 @@ function getConfig(method, data, as) {
46
46
  if (!data) data = {};
47
47
 
48
48
  if (isFormData) {
49
- if (isSpoofing) data.set("_method", as.toUpperCase());
49
+ if (isSpoofing) data.set('_method', as.toUpperCase());
50
50
  config.body = data;
51
51
  } else {
52
52
  if (isSpoofing) data._method = as.toUpperCase();
@@ -60,7 +60,7 @@ function getConfig(method, data, as) {
60
60
  export default class Api {
61
61
  constructor(resource) {
62
62
  this.baseUrl = `${process.env.API_VERITREE_URL}/api`;
63
- this.resource = resource ? resource : "";
63
+ this.resource = resource ? resource : '';
64
64
  this.orgId = null;
65
65
  this.orgType = null;
66
66
  }
@@ -101,7 +101,7 @@ export default class Api {
101
101
  * @param {string} as - 'put' // necessary for updates because of how Laravel handles PUT requests
102
102
  * @returns {promise}
103
103
  */
104
- async update(id, data, as = "put", args) {
104
+ async update(id, data, as = 'put', args) {
105
105
  const url = `${this.getUrl(id)}${this.getUrlParams(args)}`;
106
106
  return await this.post(url, data, as);
107
107
  }
@@ -115,7 +115,7 @@ export default class Api {
115
115
  */
116
116
  async delete(id, args) {
117
117
  const url = `${this.getUrl(id)}${this.getUrlParams(args)}`;
118
- return await this.post(url, null, "delete");
118
+ return await this.post(url, null, 'delete');
119
119
  }
120
120
 
121
121
  /**
@@ -135,7 +135,7 @@ export default class Api {
135
135
  */
136
136
  async post(url, data, as, args) {
137
137
  if (!url) url = `${this.getUrl()}${this.getUrlParams(args)}`;
138
- return await this.unWrap(url, "post", data, as);
138
+ return await this.unWrap(url, 'post', data, as);
139
139
  }
140
140
 
141
141
  // ----------
@@ -146,7 +146,7 @@ export default class Api {
146
146
  * @returns
147
147
  */
148
148
  getUrl(id) {
149
- id = id ? `/${id}` : "";
149
+ id = id ? `/${id}` : '';
150
150
  return `${this.baseUrl}/${this.resource}${id}`;
151
151
  }
152
152
 
@@ -164,14 +164,15 @@ export default class Api {
164
164
 
165
165
  // while most of endpoints require an org id and type, some endpoints do not
166
166
  if (args) {
167
- isOrgLess = Object.hasOwn(args, "orgless");
168
- isOrgAs = Object.hasOwn(args, "org_id_as") && Object.hasOwn(args, "org_type_as");
167
+ isOrgLess = Object.hasOwn(args, 'orgless');
168
+ isOrgAs =
169
+ Object.hasOwn(args, 'org_id_as') && Object.hasOwn(args, 'org_type_as');
169
170
  }
170
-
171
+
171
172
  // a super admin user can create/edit data from other orgs
172
- // and for that, we can't use the org id and type in
173
+ // and for that, we can't use the org id and type in
173
174
  // the session.
174
- if(isOrgAs) {
175
+ if (isOrgAs) {
175
176
  orgIdParam = `org_id=${args.org_id_as}`;
176
177
  orgTypeParam = `&org_type=${args.org_type_as}`;
177
178
 
@@ -195,7 +196,7 @@ export default class Api {
195
196
  * @param {object} data
196
197
  * @returns {object} envelope
197
198
  */
198
- async unWrap(url, method = "get", data, as) {
199
+ async unWrap(url, method = 'get', data, as) {
199
200
  url = addVersionArg(url);
200
201
  const config = getConfig(method, data, as);
201
202
  const response = await fetch(url, config);