@veritree/services 2.31.1-0 → 2.32.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/index.js +1 -3
- package/package.json +2 -3
- package/src/endpoints/organizations.js +2 -8
- package/src/endpoints/password.js +8 -18
- package/src/endpoints/planting-sites.js +30 -0
- package/src/endpoints/standards.js +87 -2
- package/src/helpers/api.js +119 -5
- package/jsdoc.json +0 -16
- package/src/endpoints/tree-codes.js +0 -21
package/index.js
CHANGED
|
@@ -37,7 +37,6 @@ import { Organizations } from './src/endpoints/organizations';
|
|
|
37
37
|
import { Tasks } from './src/endpoints/tasks';
|
|
38
38
|
import { Geometries } from './src/endpoints/geometries';
|
|
39
39
|
import { Password } from './src/endpoints/password';
|
|
40
|
-
import { TreeCodes } from './src/endpoints/tree-codes';
|
|
41
40
|
|
|
42
41
|
export {
|
|
43
42
|
BulkUploads,
|
|
@@ -78,6 +77,5 @@ export {
|
|
|
78
77
|
Organizations,
|
|
79
78
|
Tasks,
|
|
80
79
|
Geometries,
|
|
81
|
-
Password
|
|
82
|
-
TreeCodes
|
|
80
|
+
Password
|
|
83
81
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veritree/services",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.32.0",
|
|
4
4
|
"description": "A collection of javascript functions/services to talk to veritree API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -12,6 +12,5 @@
|
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"np": "^7.6.2"
|
|
15
|
-
}
|
|
16
|
-
"devDependencies": {}
|
|
15
|
+
}
|
|
17
16
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import Api from
|
|
1
|
+
import Api from '../helpers/api';
|
|
2
2
|
|
|
3
3
|
class OrganizationsApi extends Api {
|
|
4
4
|
constructor(resource) {
|
|
5
5
|
super(resource);
|
|
6
|
-
this.resource =
|
|
6
|
+
this.resource = 'organizations';
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
tasks(orgId) {
|
|
@@ -14,12 +14,6 @@ class OrganizationsApi extends Api {
|
|
|
14
14
|
return await this.get(url);
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
/**
|
|
18
|
-
* Creates a new task with the specified data.
|
|
19
|
-
*
|
|
20
|
-
* @param {Object} taskData - An object containing the data for the new task.
|
|
21
|
-
* @returns {Promise<Object>} - A Promise that resolves to the created task object.
|
|
22
|
-
*/
|
|
23
17
|
const create = async (data) => {
|
|
24
18
|
url = `${url}${this.getUrlParams()}`;
|
|
25
19
|
return await this.post(url, data);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import Api from "../helpers/api";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* This is a namespace that contains documentation elements
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* @
|
|
4
|
+
* This is a namespace that contains documentation elements
|
|
5
|
+
* belonging to the Password domain.
|
|
6
|
+
*
|
|
7
|
+
* @namespace Password
|
|
8
8
|
*/
|
|
9
9
|
class PasswordApi extends Api {
|
|
10
10
|
constructor(resource) {
|
|
@@ -12,18 +12,13 @@ class PasswordApi extends Api {
|
|
|
12
12
|
this.resource = "password";
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
/**
|
|
16
|
-
* @function
|
|
17
|
-
* @name recovery
|
|
18
|
-
* @returns {Object}
|
|
19
|
-
*/
|
|
20
15
|
recovery() {
|
|
21
16
|
/**
|
|
22
17
|
* Sends a recovery password email to the specified email address.
|
|
23
18
|
*
|
|
24
19
|
* @param {Object} data - An object containing the following properties:
|
|
25
|
-
*
|
|
26
|
-
*
|
|
20
|
+
* @param {string} data.email - The email address to send the recovery email to.
|
|
21
|
+
* @param {string} [data.return_url] - The URL to redirect the user to after they reset their password.
|
|
27
22
|
* @returns {Promise<boolean>} - A Promise that resolves to a boolean indicating whether the email was sent successfully.
|
|
28
23
|
*/
|
|
29
24
|
const post = async (data) => {
|
|
@@ -37,11 +32,6 @@ class PasswordApi extends Api {
|
|
|
37
32
|
};
|
|
38
33
|
}
|
|
39
34
|
|
|
40
|
-
/**
|
|
41
|
-
* @function
|
|
42
|
-
* @name reset
|
|
43
|
-
* @returns {Object}
|
|
44
|
-
*/
|
|
45
35
|
reset() {
|
|
46
36
|
/**
|
|
47
37
|
* Sends a POST request to reset a password with the specified email, token, and password.
|
|
@@ -54,7 +44,7 @@ class PasswordApi extends Api {
|
|
|
54
44
|
* @returns {Promise<Object>} - A Promise that resolves to the result of the POST request.
|
|
55
45
|
*/
|
|
56
46
|
const post = async (data) => {
|
|
57
|
-
const url = `${this.getUrl()}/reset
|
|
47
|
+
const url = `${this.getUrl()}/reset`
|
|
58
48
|
|
|
59
49
|
return await this.post(url, data);
|
|
60
50
|
};
|
|
@@ -65,4 +55,4 @@ class PasswordApi extends Api {
|
|
|
65
55
|
}
|
|
66
56
|
}
|
|
67
57
|
|
|
68
|
-
export const Password = new PasswordApi();
|
|
58
|
+
export const Password = new PasswordApi();
|
|
@@ -75,6 +75,36 @@ class PlantingSitesApi extends Api {
|
|
|
75
75
|
all,
|
|
76
76
|
};
|
|
77
77
|
}
|
|
78
|
+
|
|
79
|
+
evidence(subsiteId, params) {
|
|
80
|
+
let url = `${this.getUrl()}/${subsiteId}/evidence`;
|
|
81
|
+
|
|
82
|
+
console.log(url);
|
|
83
|
+
|
|
84
|
+
const all = async () => {
|
|
85
|
+
url = `${url}${this.getUrlParams(params)}`;
|
|
86
|
+
return await this.get(url);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const attach = async (formData) => {
|
|
90
|
+
url = `${url}${this.getUrlParams(params)}`;
|
|
91
|
+
return await this.post(url, formData);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const remove = async (evidenceType, evidenceId) => {
|
|
95
|
+
url = `${url}/${evidenceType}/${evidenceId}${this.getUrlParams(
|
|
96
|
+
params
|
|
97
|
+
)}`;
|
|
98
|
+
|
|
99
|
+
return await this.post(url, null, "delete");
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
all,
|
|
104
|
+
attach,
|
|
105
|
+
delete: remove,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
78
108
|
}
|
|
79
109
|
|
|
80
110
|
export const PlantingSites = new PlantingSitesApi();
|
|
@@ -13,19 +13,104 @@ class StandardsApi extends Api {
|
|
|
13
13
|
return await this.get(url);
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
+
const create = async (data, args) => {
|
|
17
|
+
const url = `${this.getUrl()}/themes?${createParamsStringFromArgs(args)}`;
|
|
18
|
+
return await this.post(url, data);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const update = async (themeId, data, args) => {
|
|
22
|
+
const url = `${this.getUrl()}/themes/${themeId}?${createParamsStringFromArgs(
|
|
23
|
+
args
|
|
24
|
+
)}`;
|
|
25
|
+
return await this.post(url, data, 'patch');
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const remove = async (args) => {
|
|
29
|
+
const url = `${this.getUrl()}/themes/${themeId}?${createParamsStringFromArgs(
|
|
30
|
+
args
|
|
31
|
+
)}`;
|
|
32
|
+
return await this.post(url, data, 'delete');
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const goals = (themeId) => {
|
|
36
|
+
const create = async (data, args) => {
|
|
37
|
+
const url = `${this.getUrl()}/themes/${themeId}/goals?${createParamsStringFromArgs(
|
|
38
|
+
args
|
|
39
|
+
)}`;
|
|
40
|
+
return await this.post(url, data);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const indicators = (goalId) => {
|
|
44
|
+
const create = async (data, args) => {
|
|
45
|
+
const url = `${this.getUrl()}/themes/${themeId}/goals/${goalId}/indicators?${createParamsStringFromArgs(
|
|
46
|
+
args
|
|
47
|
+
)}`;
|
|
48
|
+
return await this.post(url, data);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
create,
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
create,
|
|
58
|
+
indicators,
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
16
62
|
return {
|
|
17
63
|
all,
|
|
64
|
+
create,
|
|
65
|
+
update,
|
|
66
|
+
delete: remove,
|
|
67
|
+
goals,
|
|
18
68
|
};
|
|
19
69
|
}
|
|
20
70
|
|
|
21
|
-
goals() {
|
|
22
|
-
const single = async (
|
|
71
|
+
goals(goalId) {
|
|
72
|
+
const single = async () => {
|
|
73
|
+
const url = `${this.getUrl()}/goals/${goalId}`;
|
|
74
|
+
return await this.get(url);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const update = async (data) => {
|
|
78
|
+
const url = `${this.getUrl()}/goals/${goalId}`;
|
|
79
|
+
return await this.post(url, data, 'patch');
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const remove = async () => {
|
|
23
83
|
const url = `${this.getUrl()}/goals/${goalId}`;
|
|
84
|
+
return await this.post(url, null, 'delete');
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
single,
|
|
89
|
+
update,
|
|
90
|
+
delete: remove,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
indicators(indicatorId) {
|
|
95
|
+
const single = async () => {
|
|
96
|
+
const url = `${this.getUrl()}/indicators/${indicatorId}`;
|
|
24
97
|
return await this.get(url);
|
|
25
98
|
};
|
|
26
99
|
|
|
100
|
+
const update = async (data) => {
|
|
101
|
+
const url = `${this.getUrl()}/indicators/${indicatorId}`;
|
|
102
|
+
return await this.post(url, data, 'patch');
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const remove = async () => {
|
|
106
|
+
const url = `${this.getUrl()}/indicators/${indicatorId}`;
|
|
107
|
+
return await this.post(url, null, 'delete');
|
|
108
|
+
};
|
|
109
|
+
|
|
27
110
|
return {
|
|
28
111
|
single,
|
|
112
|
+
update,
|
|
113
|
+
delete: remove,
|
|
29
114
|
};
|
|
30
115
|
}
|
|
31
116
|
}
|
package/src/helpers/api.js
CHANGED
|
@@ -1,7 +1,46 @@
|
|
|
1
1
|
import { getCookie } from "./cookies";
|
|
2
|
-
import { getSession } from "./session";
|
|
3
2
|
import { createParamsStringFromArgs } from "../utils/args";
|
|
3
|
+
import { getSession } from "./session";
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Returns the runtime configuration object for Nuxt 3.
|
|
7
|
+
*
|
|
8
|
+
* Note:
|
|
9
|
+
* This function should only be used with Nuxt 3.
|
|
10
|
+
* For Nuxt 2, the environment variables will work as expected.
|
|
11
|
+
*
|
|
12
|
+
* @returns {Object|null} - The runtime configuration object, or null if it's not available.
|
|
13
|
+
*/
|
|
14
|
+
// function getNuxtRuntimeConfig() {
|
|
15
|
+
// if (typeof useRuntimeConfig === "function") {
|
|
16
|
+
// return useRuntimeConfig();
|
|
17
|
+
// } else {
|
|
18
|
+
// return null;
|
|
19
|
+
// }
|
|
20
|
+
// }
|
|
21
|
+
|
|
22
|
+
// function getVersion() {
|
|
23
|
+
// if (process) {
|
|
24
|
+
// process?.env?.API_VERITREE_VERSION;
|
|
25
|
+
// } else {
|
|
26
|
+
// const nuxtRuntimeConfig = getNuxtRuntimeConfig();
|
|
27
|
+
|
|
28
|
+
// if (nuxtRuntimeConfig) {
|
|
29
|
+
// return nuxtRuntimeConfig.public.API_VERITREE_VERSION;
|
|
30
|
+
// }
|
|
31
|
+
// }
|
|
32
|
+
|
|
33
|
+
// return "5.0.0";
|
|
34
|
+
// }
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Adds a version parameter to a URL if it does not already have one.
|
|
38
|
+
* If an environment variable called API_VERITREE_VERSION is defined, its value is used as the version,
|
|
39
|
+
* otherwise the default version "5.0.0" is used.
|
|
40
|
+
*
|
|
41
|
+
* @param {string} url - The URL to modify.
|
|
42
|
+
* @returns {string} The modified URL with the version parameter appended to it.
|
|
43
|
+
*/
|
|
5
44
|
function addVersionParam(url) {
|
|
6
45
|
// If URL is invalid or already has the result parameter, return it as is
|
|
7
46
|
if (!url || url.includes("_result=1")) {
|
|
@@ -13,7 +52,8 @@ function addVersionParam(url) {
|
|
|
13
52
|
return url;
|
|
14
53
|
}
|
|
15
54
|
|
|
16
|
-
|
|
55
|
+
// Use environment variable if available, otherwise use default version
|
|
56
|
+
const version = process.env.API_VERITREE_VERSION || "5.0.0";
|
|
17
57
|
|
|
18
58
|
// Append version parameter to URL
|
|
19
59
|
const urlVersionParam = url.includes("?")
|
|
@@ -23,7 +63,13 @@ function addVersionParam(url) {
|
|
|
23
63
|
return `${url}${urlVersionParam}`;
|
|
24
64
|
}
|
|
25
65
|
|
|
26
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Handles how the data should be sent in the fetch method
|
|
68
|
+
*
|
|
69
|
+
* @param {string} method
|
|
70
|
+
* @param {object} body
|
|
71
|
+
* @returns {object} data
|
|
72
|
+
*/
|
|
27
73
|
function getConfig(method, data, as) {
|
|
28
74
|
const isGet = method === "get";
|
|
29
75
|
const isSpoofing = as;
|
|
@@ -59,7 +105,16 @@ function getConfig(method, data, as) {
|
|
|
59
105
|
|
|
60
106
|
export default class Api {
|
|
61
107
|
constructor(resource) {
|
|
62
|
-
|
|
108
|
+
// Nuxt 3
|
|
109
|
+
// const nuxtConfig = getNuxtRuntimeConfig();
|
|
110
|
+
// const url =
|
|
111
|
+
// nuxtConfig?.public?.API_VERITREE_URL ||
|
|
112
|
+
// process?.env?.API_VERITREE_URL ||
|
|
113
|
+
// null;
|
|
114
|
+
|
|
115
|
+
// this.baseUrl = url + "/api";
|
|
116
|
+
|
|
117
|
+
this.baseUrl = process.env ? `${process.env.API_VERITREE_URL}/api` : null;
|
|
63
118
|
this.resource = resource ? resource : "";
|
|
64
119
|
this.orgId = null;
|
|
65
120
|
this.orgType = null;
|
|
@@ -69,45 +124,96 @@ export default class Api {
|
|
|
69
124
|
this.baseUrl = baseUrl;
|
|
70
125
|
}
|
|
71
126
|
|
|
127
|
+
/**
|
|
128
|
+
*
|
|
129
|
+
* @returns {promise}
|
|
130
|
+
*/
|
|
72
131
|
async all(args) {
|
|
73
132
|
const url = `${this.getUrl()}${this.getUrlParams(args)}`;
|
|
74
133
|
return await this.get(url);
|
|
75
134
|
}
|
|
76
135
|
|
|
136
|
+
/**
|
|
137
|
+
*
|
|
138
|
+
* @param {string, number} id
|
|
139
|
+
* @param {object} args/params
|
|
140
|
+
* @returns {promise}
|
|
141
|
+
*/
|
|
77
142
|
async single(id, args) {
|
|
78
143
|
const url = `${this.getUrl(id)}${this.getUrlParams(args)}`;
|
|
79
144
|
return await this.get(url);
|
|
80
145
|
}
|
|
81
146
|
|
|
147
|
+
/**
|
|
148
|
+
*
|
|
149
|
+
* @param {object} data
|
|
150
|
+
* @returns {promise}
|
|
151
|
+
*/
|
|
82
152
|
async create(data, args) {
|
|
83
153
|
return await this.post(null, data, null, args);
|
|
84
154
|
}
|
|
85
155
|
|
|
156
|
+
/**
|
|
157
|
+
*
|
|
158
|
+
* @param {string} url
|
|
159
|
+
* @param {object} data
|
|
160
|
+
* @param {string} as - 'put' // necessary for updates because of how Laravel handles PUT requests
|
|
161
|
+
* @returns {promise}
|
|
162
|
+
*/
|
|
86
163
|
async update(id, data, as = "put", args) {
|
|
87
164
|
const url = `${this.getUrl(id)}${this.getUrlParams(args)}`;
|
|
88
165
|
return await this.post(url, data, as);
|
|
89
166
|
}
|
|
90
167
|
|
|
168
|
+
/**
|
|
169
|
+
*
|
|
170
|
+
* @param {string} url
|
|
171
|
+
* @param {object} data
|
|
172
|
+
* @param {string} as - 'put' // necessary for updates because of how Laravel handles PUT requests
|
|
173
|
+
* @returns {promise}
|
|
174
|
+
*/
|
|
91
175
|
async delete(id, args) {
|
|
92
176
|
const url = `${this.getUrl(id)}${this.getUrlParams(args)}`;
|
|
93
177
|
return await this.post(url, null, "delete");
|
|
94
178
|
}
|
|
95
179
|
|
|
180
|
+
/**
|
|
181
|
+
*
|
|
182
|
+
* @param {string} url
|
|
183
|
+
* @returns {promise}
|
|
184
|
+
*/
|
|
96
185
|
async get(url) {
|
|
97
|
-
console.log(url);
|
|
98
186
|
return await this.unWrap(url);
|
|
99
187
|
}
|
|
100
188
|
|
|
189
|
+
/**
|
|
190
|
+
*
|
|
191
|
+
* @param {string} url
|
|
192
|
+
* @param {object} data
|
|
193
|
+
* @returns {promise}
|
|
194
|
+
*/
|
|
101
195
|
async post(url, data, as, args) {
|
|
102
196
|
if (!url) url = `${this.getUrl()}${this.getUrlParams(args)}`;
|
|
103
197
|
return await this.unWrap(url, "post", data, as);
|
|
104
198
|
}
|
|
105
199
|
|
|
200
|
+
// ----------
|
|
201
|
+
// --
|
|
202
|
+
/**
|
|
203
|
+
*
|
|
204
|
+
* @param {string, number} id
|
|
205
|
+
* @returns
|
|
206
|
+
*/
|
|
106
207
|
getUrl(id) {
|
|
107
208
|
id = id ? `/${id}` : "";
|
|
108
209
|
return `${this.baseUrl}/${this.resource}${id}`;
|
|
109
210
|
}
|
|
110
211
|
|
|
212
|
+
/**
|
|
213
|
+
*
|
|
214
|
+
* @param {object} args
|
|
215
|
+
* @returns {string}
|
|
216
|
+
*/
|
|
111
217
|
getUrlParams(args) {
|
|
112
218
|
this.setOrg();
|
|
113
219
|
let isOrgLess = false;
|
|
@@ -152,6 +258,14 @@ export default class Api {
|
|
|
152
258
|
)}`;
|
|
153
259
|
}
|
|
154
260
|
|
|
261
|
+
/**
|
|
262
|
+
* Deals with all fetch requests
|
|
263
|
+
*
|
|
264
|
+
* @param {string} url
|
|
265
|
+
* @param {string} method
|
|
266
|
+
* @param {object} data
|
|
267
|
+
* @returns {object} envelope
|
|
268
|
+
*/
|
|
155
269
|
async unWrap(url, method = "get", data, as) {
|
|
156
270
|
url = addVersionParam(url);
|
|
157
271
|
const config = getConfig(method, data, as);
|
package/jsdoc.json
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"source": {
|
|
3
|
-
"include": ["src/endpoints"],
|
|
4
|
-
"includePattern": ".js$",
|
|
5
|
-
"excludePattern": "(node_modules/|docs)"
|
|
6
|
-
},
|
|
7
|
-
"plugins": ["plugins/markdown"],
|
|
8
|
-
"templates": {
|
|
9
|
-
"cleverLinks": true,
|
|
10
|
-
"monospaceLinks": true
|
|
11
|
-
},
|
|
12
|
-
"opts": {
|
|
13
|
-
"recurse": true,
|
|
14
|
-
"destination": "./documentation/"
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import Api from "../helpers/api";
|
|
2
|
-
|
|
3
|
-
class TreeCodesApi extends Api {
|
|
4
|
-
constructor(resource) {
|
|
5
|
-
super(resource);
|
|
6
|
-
this.resource = "tree-codes";
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
holders(args) {
|
|
10
|
-
const claim = async (treeCodeHolder) => {
|
|
11
|
-
const url = `${this.getUrl()}/holders/claim/${treeCodeHolder}${this.getUrlParams(args)}`;
|
|
12
|
-
return await this.get(url);
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
return {
|
|
16
|
-
claim,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const TreeCodes = new TreeCodesApi();
|