@veritree/services 2.34.0 → 2.35.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.
Files changed (51) hide show
  1. package/index.js +83 -83
  2. package/jsdoc.json +16 -0
  3. package/package.json +24 -16
  4. package/src/endpoints/bulk-uploads.js +4 -4
  5. package/src/endpoints/countries.js +5 -5
  6. package/src/endpoints/crumbs.js +20 -20
  7. package/src/endpoints/evidence.js +47 -47
  8. package/src/endpoints/external-reports.js +9 -9
  9. package/src/endpoints/field-reports.js +32 -37
  10. package/src/endpoints/field-udpate-verifications.js +5 -5
  11. package/src/endpoints/field-updates.js +16 -16
  12. package/src/endpoints/forest-type-species.js +4 -4
  13. package/src/endpoints/forest-types-profiles.js +4 -4
  14. package/src/endpoints/forest-types.js +14 -14
  15. package/src/endpoints/form-submissions.js +4 -4
  16. package/src/endpoints/geometries.js +4 -4
  17. package/src/endpoints/images-aggregated.js +4 -4
  18. package/src/endpoints/images.js +21 -21
  19. package/src/endpoints/methodologies.js +36 -36
  20. package/src/endpoints/notes.js +14 -14
  21. package/src/endpoints/organizations.js +65 -59
  22. package/src/endpoints/orgs.js +65 -65
  23. package/src/endpoints/password.js +68 -58
  24. package/src/endpoints/planting-sites.js +91 -110
  25. package/src/endpoints/regions.js +32 -41
  26. package/src/endpoints/resellers.js +37 -37
  27. package/src/endpoints/roles.js +4 -4
  28. package/src/endpoints/sdgs.js +4 -4
  29. package/src/endpoints/sponsors.js +100 -86
  30. package/src/endpoints/sso-token.js +5 -5
  31. package/src/endpoints/standards.js +33 -140
  32. package/src/endpoints/stats.js +16 -17
  33. package/src/endpoints/subdomains.js +4 -4
  34. package/src/endpoints/subsite-types.js +5 -5
  35. package/src/endpoints/subsites.js +88 -88
  36. package/src/endpoints/tags.js +14 -14
  37. package/src/endpoints/tasks.js +47 -47
  38. package/src/endpoints/tree-codes.js +43 -0
  39. package/src/endpoints/trees-orders.js +23 -23
  40. package/src/endpoints/user.js +27 -27
  41. package/src/endpoints/users.js +14 -14
  42. package/src/endpoints/utilities.js +35 -35
  43. package/src/endpoints/verifications.js +21 -21
  44. package/src/helpers/api.js +184 -293
  45. package/src/helpers/cookies.js +36 -36
  46. package/src/helpers/relations.js +32 -32
  47. package/src/helpers/sequestrations.js +19 -19
  48. package/src/helpers/session.js +3 -3
  49. package/src/helpers/team.js +45 -45
  50. package/src/utils/args.js +46 -46
  51. package/src/endpoints/tree-order-statuses.js +0 -5
@@ -1,36 +1,36 @@
1
- const converter = {
2
- read(value) {
3
- if (value[0] === '"') {
4
- value = value.slice(1, -1);
5
- }
6
-
7
- return value.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent);
8
- },
9
- };
10
-
11
- export function getCookie(name) {
12
- if (typeof document === 'undefined' || (arguments.length && !name)) {
13
- return;
14
- }
15
-
16
- // To prevent the for loop in the first place assign an empty array
17
- // in case there are no cookies at all.
18
- const cookies = document.cookie ? document.cookie.split('; ') : [];
19
-
20
- const jar = {};
21
- for (let i = 0; i < cookies.length; i++) {
22
- const parts = cookies[i].split('=');
23
- const value = parts.slice(1).join('=');
24
-
25
- try {
26
- const found = decodeURIComponent(parts[0]);
27
- jar[found] = converter.read(value, found);
28
-
29
- if (name === found) {
30
- break;
31
- }
32
- } catch (e) {}
33
- }
34
-
35
- return name ? jar[name] : jar;
36
- }
1
+ const converter = {
2
+ read(value) {
3
+ if (value[0] === '"') {
4
+ value = value.slice(1, -1);
5
+ }
6
+
7
+ return value.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent);
8
+ },
9
+ };
10
+
11
+ export function getCookie(name) {
12
+ if (typeof document === 'undefined' || (arguments.length && !name)) {
13
+ return;
14
+ }
15
+
16
+ // To prevent the for loop in the first place assign an empty array
17
+ // in case there are no cookies at all.
18
+ const cookies = document.cookie ? document.cookie.split('; ') : [];
19
+
20
+ const jar = {};
21
+ for (let i = 0; i < cookies.length; i++) {
22
+ const parts = cookies[i].split('=');
23
+ const value = parts.slice(1).join('=');
24
+
25
+ try {
26
+ const found = decodeURIComponent(parts[0]);
27
+ jar[found] = converter.read(value, found);
28
+
29
+ if (name === found) {
30
+ break;
31
+ }
32
+ } catch (e) {}
33
+ }
34
+
35
+ return name ? jar[name] : jar;
36
+ }
@@ -1,32 +1,32 @@
1
- const Relations = (api, relationPrefix, relationId) => {
2
- let url = `${api.baseUrl}/${relationPrefix}/${relationId}/${api.resource}`;
3
-
4
- const all = async (args) => {
5
- url = `${url}${api.getUrlParams(args)}`;
6
- return await api.get(url);
7
- };
8
-
9
- const single = async (id, args) => {
10
- url = `${url}/${id}${api.getUrlParams(args)}`;
11
- return await api.get(url);
12
- };
13
-
14
- const attach = async (id, data, args) => {
15
- url = `${url}/${id}/attach${api.getUrlParams(args)}`;
16
- return await api.post(url, data);
17
- };
18
-
19
- const detach = async (id, args) => {
20
- url = `${url}/${id}/detach${api.getUrlParams(args)}`;
21
- return await api.post(url, null, "delete");
22
- };
23
-
24
- return {
25
- all,
26
- single,
27
- attach,
28
- detach,
29
- };
30
- };
31
-
32
- export default Relations;
1
+ const Relations = (api, relationPrefix, relationId) => {
2
+ let url = `${api.baseUrl}/${relationPrefix}/${relationId}/${api.resource}`;
3
+
4
+ const all = async (args) => {
5
+ url = `${url}${api.getUrlParams(args)}`;
6
+ return await api.get(url);
7
+ };
8
+
9
+ const single = async (id, args) => {
10
+ url = `${url}/${id}${api.getUrlParams(args)}`;
11
+ return await api.get(url);
12
+ };
13
+
14
+ const attach = async (id, data, args) => {
15
+ url = `${url}/${id}/attach${api.getUrlParams(args)}`;
16
+ return await api.post(url, data);
17
+ };
18
+
19
+ const detach = async (id, args) => {
20
+ url = `${url}/${id}/detach${api.getUrlParams(args)}`;
21
+ return await api.post(url, null, "delete");
22
+ };
23
+
24
+ return {
25
+ all,
26
+ single,
27
+ attach,
28
+ detach,
29
+ };
30
+ };
31
+
32
+ export default Relations;
@@ -1,20 +1,20 @@
1
- const Sequestrations = (api, forestTypeId, args) => {
2
- let url = `${api.baseUrl}/${api.resource}/${forestTypeId}/sequestrations`;
3
-
4
- const all = async () => {
5
- url = `${url}${api.getUrlParams(args)}`;
6
- return await api.get(url);
7
- }
8
-
9
- const create = async(data) => {
10
- url = `${url}${api.getUrlParams(args)}`;
11
- return await api.post(url, data);
12
- }
13
-
14
- return {
15
- all,
16
- create
17
- }
18
- }
19
-
1
+ const Sequestrations = (api, forestTypeId, args) => {
2
+ let url = `${api.baseUrl}/${api.resource}/${forestTypeId}/sequestrations`;
3
+
4
+ const all = async () => {
5
+ url = `${url}${api.getUrlParams(args)}`;
6
+ return await api.get(url);
7
+ }
8
+
9
+ const create = async(data) => {
10
+ url = `${url}${api.getUrlParams(args)}`;
11
+ return await api.post(url, data);
12
+ }
13
+
14
+ return {
15
+ all,
16
+ create
17
+ }
18
+ }
19
+
20
20
  export default Sequestrations;
@@ -1,3 +1,3 @@
1
- export const getSession = () => {
2
- return JSON.parse(localStorage.getItem('session'));
3
- };
1
+ export const getSession = () => {
2
+ return JSON.parse(localStorage.getItem('session'));
3
+ };
@@ -1,46 +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 (params) => {
13
- url = `${url}${api.getUrlParams(params)}`;
14
- return await api.get(url);
15
- };
16
-
17
- const single = async (userId, params) => {
18
- url = `${url}/${userId}${api.getUrlParams(params)}`;
19
- return await api.get(url);
20
- };
21
-
22
- const create = async (data, params) => {
23
- url = `${url}${api.getUrlParams(params)}`;
24
- return await api.post(url, data);
25
- }
26
-
27
- const update = async (userId, data, params) => {
28
- url = `${url}/${userId}${api.getUrlParams(params)}`;
29
- return await api.post(url, data, 'patch');
30
- }
31
-
32
- const remove = async (userId, params) => {
33
- url = `${url}/${userId}${api.getUrlParams(params)}`;
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
-
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 (params) => {
13
+ url = `${url}${api.getUrlParams(params)}`;
14
+ return await api.get(url);
15
+ };
16
+
17
+ const single = async (userId, params) => {
18
+ url = `${url}/${userId}${api.getUrlParams(params)}`;
19
+ return await api.get(url);
20
+ };
21
+
22
+ const create = async (data, params) => {
23
+ url = `${url}${api.getUrlParams(params)}`;
24
+ return await api.post(url, data);
25
+ }
26
+
27
+ const update = async (userId, data, params) => {
28
+ url = `${url}/${userId}${api.getUrlParams(params)}`;
29
+ return await api.post(url, data, 'patch');
30
+ }
31
+
32
+ const remove = async (userId, params) => {
33
+ url = `${url}/${userId}${api.getUrlParams(params)}`;
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
46
  export default Team;
package/src/utils/args.js CHANGED
@@ -1,46 +1,46 @@
1
- export const createParamsStringFromArgs = (args) => {
2
- if (!args && typeof args !== "object" && !Array.isArray(args)) {
3
- return "";
4
- }
5
-
6
- const paramsString = [];
7
- let arr = [];
8
-
9
- Object.entries(args).forEach(([key, value]) => {
10
- if (value === null) return;
11
-
12
- if (Array.isArray(value)) {
13
- arr = value
14
- .map((item, index) => {
15
- const param = `${key}[]=${encodeURIComponent(item)}`;
16
- return index === 0 ? `${param}` : `&${param}`;
17
- })
18
- .join("");
19
-
20
- paramsString.push(arr);
21
- } else {
22
- if (value !== undefined) {
23
- /**
24
- * as args is an object, we can't pass same keys
25
- * and sometimes the api might need the keys
26
- * to be equal (e.g box=1&box=2...). As a
27
- * solution, we have this -x- to allow
28
- * same keys to be passed. The args
29
- * would look like:
30
- *
31
- * {
32
- * 'box-x-1': 1
33
- * 'box-x-2': 2
34
- * }
35
- *
36
- * and would be translated as expected:
37
- *
38
- * box=1&box=2
39
- */
40
- paramsString.push(`${key.split('-x-')[0]}=${encodeURIComponent(value)}`);
41
- }
42
- }
43
- });
44
-
45
- return paramsString.length ? `&${paramsString.join("&")}` : "";
46
- };
1
+ export const createParamsStringFromArgs = (args) => {
2
+ if (!args && typeof args !== "object" && !Array.isArray(args)) {
3
+ return "";
4
+ }
5
+
6
+ const paramsString = [];
7
+ let arr = [];
8
+
9
+ Object.entries(args).forEach(([key, value]) => {
10
+ if (value === null) return;
11
+
12
+ if (Array.isArray(value)) {
13
+ arr = value
14
+ .map((item, index) => {
15
+ const param = `${key}[]=${encodeURIComponent(item)}`;
16
+ return index === 0 ? `${param}` : `&${param}`;
17
+ })
18
+ .join("");
19
+
20
+ paramsString.push(arr);
21
+ } else {
22
+ if (value !== undefined) {
23
+ /**
24
+ * as args is an object, we can't pass same keys
25
+ * and sometimes the api might need the keys
26
+ * to be equal (e.g box=1&box=2...). As a
27
+ * solution, we have this -x- to allow
28
+ * same keys to be passed. The args
29
+ * would look like:
30
+ *
31
+ * {
32
+ * 'box-x-1': 1
33
+ * 'box-x-2': 2
34
+ * }
35
+ *
36
+ * and would be translated as expected:
37
+ *
38
+ * box=1&box=2
39
+ */
40
+ paramsString.push(`${key.split('-x-')[0]}=${encodeURIComponent(value)}`);
41
+ }
42
+ }
43
+ });
44
+
45
+ return paramsString.length ? `&${paramsString.join("&")}` : "";
46
+ };
@@ -1,5 +0,0 @@
1
- import Api from "../helpers/api";
2
-
3
- const resource = "tree-order-statuses";
4
-
5
- export const TreeOrderStatuses = new Api(resource);