@veritree/services 2.38.0 → 2.40.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veritree/services",
3
- "version": "2.38.0",
3
+ "version": "2.40.0",
4
4
  "description": "A collection of javascript functions/services to talk to veritree API",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -8,9 +8,17 @@
8
8
  "author": "cyroveritree <cyro@veritree.com>",
9
9
  "license": "MIT",
10
10
  "publishConfig": {
11
- "access": "public"
11
+ "registry": "https://registry.npmjs.org"
12
12
  },
13
- "dependencies": {
14
- "np": "^7.6.2"
13
+ "scripts": {
14
+ "release": "np --no-tests --no-2fa"
15
+ },
16
+ "devDependencies": {
17
+ "np": "^8.0.4",
18
+ "prettier": "^2.7.1"
19
+ },
20
+ "engines": {
21
+ "npm": ">=8.0.0",
22
+ "node": ">=18.0.0"
15
23
  }
16
24
  }
@@ -54,17 +54,6 @@ class OrganizationsApi extends Api {
54
54
 
55
55
  return { all };
56
56
  }
57
-
58
- plantingReport(orgId) {
59
- const all = async (params) => {
60
- const url = `${this.getUrl()}/${orgId}/planting-report${this.getUrlParams(
61
- params
62
- )}`;
63
-
64
- return await this.get(url);
65
- };
66
- return {all}
67
- }
68
57
  }
69
58
 
70
59
  export const Organizations = new OrganizationsApi();
@@ -29,10 +29,22 @@ class RegionsApi extends Api {
29
29
  all,
30
30
  };
31
31
  }
32
+
33
+ getPlantingSites(regionId) {
34
+ const all = async (params) => {
35
+ const url = `${this.getUrl()}/${regionId}/planting-sites${this.getUrlParams(
36
+ params
37
+ )}`;
38
+ return await this.get(url);
39
+ };
40
+ return {
41
+ all,
42
+ }
43
+ }
32
44
 
33
- public() {
45
+ public(args) {
34
46
  const all = async () => {
35
- const url = `${this.getUrl()}/public${this.getUrlParams()}`;
47
+ const url = `${this.getUrl()}/public${this.getUrlParams(args)}`;
36
48
  return await this.get(url);
37
49
  };
38
50
 
@@ -42,4 +54,6 @@ class RegionsApi extends Api {
42
54
  }
43
55
  }
44
56
 
57
+
45
58
  export const Regions = new RegionsApi();
59
+
@@ -1,16 +1,16 @@
1
- import Api from '../helpers/api';
1
+ import Api from "../helpers/api";
2
2
 
3
3
  class SponsorsApi extends Api {
4
4
  constructor(resource) {
5
5
  super(resource);
6
- this.resource = 'sponsors';
6
+ this.resource = "sponsors";
7
7
  }
8
8
 
9
9
  async map() {
10
10
  this.setOrg();
11
11
 
12
12
  if (!this.orgId) {
13
- throw new Error('No org id provided');
13
+ throw new Error("No org id provided");
14
14
  }
15
15
 
16
16
  const url = `${this.getUrl()}/${this.orgId}/map-data`;
@@ -21,7 +21,7 @@ class SponsorsApi extends Api {
21
21
  this.setOrg();
22
22
 
23
23
  if (!this.orgId) {
24
- throw new Error('No org id provided');
24
+ throw new Error("No org id provided");
25
25
  }
26
26
 
27
27
  const url = `${this.getUrl()}/${this.orgId}/profile`;
@@ -49,7 +49,9 @@ class SponsorsApi extends Api {
49
49
  };
50
50
 
51
51
  const imageUploadUrl = async () => {
52
- const url = `${this.getUrl()}/${this.orgId}/cms/image-upload-url${urlParams}`;
52
+ const url = `${this.getUrl()}/${
53
+ this.orgId
54
+ }/cms/image-upload-url${urlParams}`;
53
55
  return await this.get(url);
54
56
  };
55
57
 
@@ -67,18 +69,56 @@ class SponsorsApi extends Api {
67
69
 
68
70
  tools(args) {
69
71
  const get = async (sponsorId) => {
70
- const url = `${this.getUrl()}/${sponsorId}/tools${this.getUrlParams(args)}`;
72
+ const url = `${this.getUrl()}/${sponsorId}/tools${this.getUrlParams(
73
+ args
74
+ )}`;
71
75
  return await this.get(url);
72
- }
76
+ };
73
77
 
74
78
  const create = async (sponsorId, data) => {
75
79
  const url = `${this.getUrl()}/${sponsorId}/tools`;
76
80
  return await this.post(url, data);
77
- }
81
+ };
78
82
 
79
83
  return {
80
84
  get,
81
- create
85
+ create,
86
+ };
87
+ }
88
+
89
+ treeOrderSummary(args) {
90
+ const all = async (sponsorId) => {
91
+ const url = `${this.getUrl()}/${sponsorId}/tree-order-summary${this.getUrlParams(
92
+ args
93
+ )}`;
94
+
95
+ return await this.get(url);
96
+ };
97
+
98
+ return {
99
+ all,
100
+ };
101
+ }
102
+
103
+ region(regionId, args) {
104
+ this.setOrg();
105
+
106
+ const stats = () => {
107
+ const all = async () => {
108
+ const url = `${this.getUrl()}/${this.orgId}/regions/${regionId}/stats${this.getUrlParams(
109
+ args
110
+ )}`;
111
+
112
+ return await this.get(url);
113
+ }
114
+
115
+ return {
116
+ all
117
+ }
118
+ }
119
+
120
+ return {
121
+ stats
82
122
  }
83
123
  }
84
124
  }
@@ -1,10 +1,10 @@
1
- import Api from '../helpers/api';
2
- import { createParamsStringFromArgs } from '../utils/args';
1
+ import Api from "../helpers/api";
2
+ import { createParamsStringFromArgs } from "../utils/args";
3
3
 
4
4
  class StandardsApi extends Api {
5
5
  constructor(resource) {
6
6
  super(resource);
7
- this.resource = 'standards';
7
+ this.resource = "standards";
8
8
  }
9
9
 
10
10
  themes() {
@@ -29,14 +29,14 @@ class StandardsApi extends Api {
29
29
  const url = `${this.getUrl()}/themes/${themeId}?${createParamsStringFromArgs(
30
30
  args
31
31
  )}`;
32
- return await this.post(url, data, 'patch');
32
+ return await this.post(url, data, "patch");
33
33
  };
34
34
 
35
35
  const remove = async (args) => {
36
36
  const url = `${this.getUrl()}/themes/${themeId}?${createParamsStringFromArgs(
37
37
  args
38
38
  )}`;
39
- return await this.post(url, data, 'delete');
39
+ return await this.post(url, data, "delete");
40
40
  };
41
41
 
42
42
  const goals = (themeId) => {
@@ -95,12 +95,12 @@ class StandardsApi extends Api {
95
95
 
96
96
  const update = async (data) => {
97
97
  const url = `${this.getUrl()}/goals/${goalId}`;
98
- return await this.post(url, data, 'patch');
98
+ return await this.post(url, data, "patch");
99
99
  };
100
100
 
101
101
  const remove = async () => {
102
102
  const url = `${this.getUrl()}/goals/${goalId}`;
103
- return await this.post(url, null, 'delete');
103
+ return await this.post(url, null, "delete");
104
104
  };
105
105
 
106
106
  return {
@@ -118,12 +118,12 @@ class StandardsApi extends Api {
118
118
 
119
119
  const update = async (data) => {
120
120
  const url = `${this.getUrl()}/indicators/${indicatorId}`;
121
- return await this.post(url, data, 'patch');
121
+ return await this.post(url, data, "patch");
122
122
  };
123
123
 
124
124
  const remove = async () => {
125
125
  const url = `${this.getUrl()}/indicators/${indicatorId}`;
126
- return await this.post(url, null, 'delete');
126
+ return await this.post(url, null, "delete");
127
127
  };
128
128
 
129
129
  return {
@@ -135,11 +135,17 @@ class StandardsApi extends Api {
135
135
  UNSDGs(themeId) {
136
136
  const attach = async (data) => {
137
137
  const url = `${this.getUrl()}/themes/${themeId}/attach-sdg`;
138
- return await this.update(url, { sdg_id: data });
138
+ return await this.post(url, { sdg_id: data });
139
+ };
140
+
141
+ const remove = async (data) => {
142
+ const url = `${this.getUrl()}/themes/${themeId}/detach-sdg`;
143
+ return await this.post(url, { sdg_id: data });
139
144
  };
140
145
 
141
146
  return {
142
147
  attach,
148
+ remove,
143
149
  };
144
150
  }
145
151
  }
@@ -277,22 +277,6 @@ export default class Api {
277
277
  return;
278
278
  }
279
279
 
280
- const contentType = response.headers.get('content-type');
281
-
282
- if (contentType.includes('json')) {
283
- response.json().then((json) => {
284
- response.ok ? resolve(json) : reject(json);
285
- });
286
- return;
287
- }
288
-
289
- if (contentType.includes('csv')) {
290
- response.text().then((res) => {
291
- response.ok ? resolve(res) : reject(res);
292
- });
293
- return;
294
- }
295
-
296
280
  response.json().then((json) => {
297
281
  response.ok ? resolve(json) : reject(json);
298
282
  });