@veritree/services 2.34.0-0 → 2.35.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 +3 -3
- package/package.json +2 -3
- package/src/endpoints/field-reports.js +5 -0
- package/src/endpoints/organizations.js +2 -8
- package/src/endpoints/orgs.js +5 -5
- package/src/endpoints/password.js +8 -18
- package/src/endpoints/planting-sites.js +45 -15
- package/src/endpoints/regions.js +9 -0
- package/src/endpoints/sponsors.js +13 -27
- package/src/endpoints/standards.js +109 -2
- package/src/endpoints/stats.js +3 -2
- package/src/endpoints/tree-order-statuses.js +5 -0
- package/src/helpers/api.js +151 -33
- package/jsdoc.json +0 -16
- package/src/endpoints/tree-codes.js +0 -43
package/index.js
CHANGED
|
@@ -21,6 +21,7 @@ import { Subsites } from './src/endpoints/subsites';
|
|
|
21
21
|
import { SubsiteTypes } from './src/endpoints/subsite-types';
|
|
22
22
|
import { Tags } from './src/endpoints/tags';
|
|
23
23
|
import { TreeOrders } from './src/endpoints/trees-orders';
|
|
24
|
+
import { TreeOrderStatuses } from './src/endpoints/tree-order-statuses';
|
|
24
25
|
import { User } from './src/endpoints/user';
|
|
25
26
|
import { Users } from './src/endpoints/users';
|
|
26
27
|
import { Utilities } from './src/endpoints/utilities';
|
|
@@ -37,7 +38,6 @@ import { Organizations } from './src/endpoints/organizations';
|
|
|
37
38
|
import { Tasks } from './src/endpoints/tasks';
|
|
38
39
|
import { Geometries } from './src/endpoints/geometries';
|
|
39
40
|
import { Password } from './src/endpoints/password';
|
|
40
|
-
import { TreeCodes } from './src/endpoints/tree-codes';
|
|
41
41
|
|
|
42
42
|
export {
|
|
43
43
|
BulkUploads,
|
|
@@ -63,6 +63,7 @@ export {
|
|
|
63
63
|
SubsiteTypes,
|
|
64
64
|
Tags,
|
|
65
65
|
TreeOrders,
|
|
66
|
+
TreeOrderStatuses,
|
|
66
67
|
User,
|
|
67
68
|
Users,
|
|
68
69
|
Utilities,
|
|
@@ -78,6 +79,5 @@ export {
|
|
|
78
79
|
Organizations,
|
|
79
80
|
Tasks,
|
|
80
81
|
Geometries,
|
|
81
|
-
Password
|
|
82
|
-
TreeCodes
|
|
82
|
+
Password
|
|
83
83
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veritree/services",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.35.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
|
}
|
|
@@ -28,6 +28,11 @@ class FieldReportsApi extends Api {
|
|
|
28
28
|
detach
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
+
|
|
32
|
+
blockchain(fieldReportId, params) {
|
|
33
|
+
const url = `${this.getUrl()}/${fieldReportId}${this.getUrlParams(params)}`;
|
|
34
|
+
return this.get(url)
|
|
35
|
+
}
|
|
31
36
|
}
|
|
32
37
|
|
|
33
38
|
export const FieldReports = new FieldReportsApi();
|
|
@@ -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);
|
package/src/endpoints/orgs.js
CHANGED
|
@@ -24,12 +24,12 @@ class OrgsApi extends Api {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
async stats() {
|
|
27
|
-
const url = `${this.
|
|
27
|
+
const url = `${this._geStatstUrl()}`;
|
|
28
28
|
return await this.get(url);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
async publicStats(
|
|
32
|
-
const url = `${this.
|
|
31
|
+
async publicStats() {
|
|
32
|
+
const url = `${this._geStatstUrl(true)}`;
|
|
33
33
|
return await this.get(url);
|
|
34
34
|
}
|
|
35
35
|
|
|
@@ -56,9 +56,9 @@ class OrgsApi extends Api {
|
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
_geStatstUrl(isPublic) {
|
|
60
60
|
const endpoint = isPublic ? 'pstats' : 'stats';
|
|
61
|
-
return `${this.getUrl()}/${endpoint}${this.getUrlParams(
|
|
61
|
+
return `${this.getUrl()}/${endpoint}${this.getUrlParams()}`;
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
|
|
@@ -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();
|
|
@@ -1,20 +1,9 @@
|
|
|
1
|
-
import Api from
|
|
1
|
+
import Api from '../helpers/api';
|
|
2
2
|
|
|
3
3
|
class PlantingSitesApi extends Api {
|
|
4
4
|
constructor(resource) {
|
|
5
5
|
super(resource);
|
|
6
|
-
this.resource =
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
public() {
|
|
10
|
-
const single = async (plantingSiteId) => {
|
|
11
|
-
const url = `${this.getUrl()}/public/${plantingSiteId}`;
|
|
12
|
-
return await this.get(url);
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
return {
|
|
16
|
-
single,
|
|
17
|
-
};
|
|
6
|
+
this.resource = 'planting-sites';
|
|
18
7
|
}
|
|
19
8
|
|
|
20
9
|
users(plantingSiteId) {
|
|
@@ -43,7 +32,7 @@ class PlantingSitesApi extends Api {
|
|
|
43
32
|
url = `${this.getUrl()}/${subsiteId}/media/images/${imageId}${this.getUrlParams(
|
|
44
33
|
params
|
|
45
34
|
)}`;
|
|
46
|
-
return await this.post(url, null,
|
|
35
|
+
return await this.post(url, null, 'delete');
|
|
47
36
|
};
|
|
48
37
|
|
|
49
38
|
return {
|
|
@@ -65,7 +54,7 @@ class PlantingSitesApi extends Api {
|
|
|
65
54
|
url = `${this.getUrl()}/${subsiteId}/media/attachments/${attachmentId}${this.getUrlParams(
|
|
66
55
|
params
|
|
67
56
|
)}`;
|
|
68
|
-
return await this.post(url, null,
|
|
57
|
+
return await this.post(url, null, 'delete');
|
|
69
58
|
};
|
|
70
59
|
|
|
71
60
|
return {
|
|
@@ -86,6 +75,47 @@ class PlantingSitesApi extends Api {
|
|
|
86
75
|
all,
|
|
87
76
|
};
|
|
88
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
|
+
}
|
|
108
|
+
|
|
109
|
+
stats(subsiteId) {
|
|
110
|
+
const all = async (args) => {
|
|
111
|
+
const url = `${this.getUrl()}/${subsiteId}/stats${this.getUrlParams(args)}`;
|
|
112
|
+
return await this.get(url);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
all,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
89
119
|
}
|
|
90
120
|
|
|
91
121
|
export const PlantingSites = new PlantingSitesApi();
|
package/src/endpoints/regions.js
CHANGED
|
@@ -27,6 +27,15 @@ class RegionsApi extends Api {
|
|
|
27
27
|
all,
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
|
+
listRegions(orgId,orgType) {
|
|
31
|
+
const all = async () => {
|
|
32
|
+
const url = `${this.getUrl()}/public?org_id=${orgId}&org_type=${orgType}&_v=10.0.0`;
|
|
33
|
+
return await this.get(url);
|
|
34
|
+
};
|
|
35
|
+
return {
|
|
36
|
+
all,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
30
39
|
}
|
|
31
40
|
|
|
32
41
|
export const Regions = new RegionsApi();
|
|
@@ -6,38 +6,28 @@ class SponsorsApi extends Api {
|
|
|
6
6
|
this.resource = 'sponsors';
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
async map(
|
|
9
|
+
async map() {
|
|
10
|
+
this.setOrg();
|
|
10
11
|
|
|
11
|
-
if (!orgId) {
|
|
12
|
+
if (!this.orgId) {
|
|
12
13
|
throw new Error('No org id provided');
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
const url = `${this.getUrl()}/${orgId}/map-data`;
|
|
16
|
+
const url = `${this.getUrl()}/${this.orgId}/map-data`;
|
|
16
17
|
return await this.get(url);
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
async profile(
|
|
20
|
-
|
|
20
|
+
async profile() {
|
|
21
|
+
this.setOrg();
|
|
21
22
|
|
|
22
23
|
if (!this.orgId) {
|
|
23
24
|
throw new Error('No org id provided');
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
const url = `${this.getUrl()}/${this.orgId}/profile
|
|
27
|
+
const url = `${this.getUrl()}/${this.orgId}/profile`;
|
|
27
28
|
return await this.get(url);
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
plantingSites(orgId) {
|
|
31
|
-
const all = async () => {
|
|
32
|
-
const url = `${this.getUrl()}/${orgId}/planting-sites`;
|
|
33
|
-
return await this.get(url);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
return {
|
|
37
|
-
all
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
31
|
async plantingStats(args) {
|
|
42
32
|
const url = `${this.getUrl()}/planting-stats${this.getUrlParams(args)}`;
|
|
43
33
|
return await this.get(url);
|
|
@@ -59,9 +49,7 @@ class SponsorsApi extends Api {
|
|
|
59
49
|
};
|
|
60
50
|
|
|
61
51
|
const imageUploadUrl = async () => {
|
|
62
|
-
const url = `${this.getUrl()}/${
|
|
63
|
-
this.orgId
|
|
64
|
-
}/cms/image-upload-url${urlParams}`;
|
|
52
|
+
const url = `${this.getUrl()}/${this.orgId}/cms/image-upload-url${urlParams}`;
|
|
65
53
|
return await this.get(url);
|
|
66
54
|
};
|
|
67
55
|
|
|
@@ -79,21 +67,19 @@ class SponsorsApi extends Api {
|
|
|
79
67
|
|
|
80
68
|
tools(args) {
|
|
81
69
|
const get = async (sponsorId) => {
|
|
82
|
-
const url = `${this.getUrl()}/${sponsorId}/tools${this.getUrlParams(
|
|
83
|
-
args
|
|
84
|
-
)}`;
|
|
70
|
+
const url = `${this.getUrl()}/${sponsorId}/tools${this.getUrlParams(args)}`;
|
|
85
71
|
return await this.get(url);
|
|
86
|
-
}
|
|
72
|
+
}
|
|
87
73
|
|
|
88
74
|
const create = async (sponsorId, data) => {
|
|
89
75
|
const url = `${this.getUrl()}/${sponsorId}/tools`;
|
|
90
76
|
return await this.post(url, data);
|
|
91
|
-
}
|
|
77
|
+
}
|
|
92
78
|
|
|
93
79
|
return {
|
|
94
80
|
get,
|
|
95
|
-
create
|
|
96
|
-
}
|
|
81
|
+
create
|
|
82
|
+
}
|
|
97
83
|
}
|
|
98
84
|
}
|
|
99
85
|
|
|
@@ -13,19 +13,126 @@ 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
|
+
|
|
62
|
+
const UNSDGs = (themeId) => {
|
|
63
|
+
const create = async (data) => {
|
|
64
|
+
console.log('this.getUrl:', this.getUrl())
|
|
65
|
+
const url = `${this.getUrl()}/themes/${themeId}/attach-sdg`;
|
|
66
|
+
return await this.post(url, data);
|
|
67
|
+
};
|
|
68
|
+
return {
|
|
69
|
+
create
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
|
|
16
73
|
return {
|
|
17
74
|
all,
|
|
75
|
+
create,
|
|
76
|
+
update,
|
|
77
|
+
delete: remove,
|
|
78
|
+
goals,
|
|
79
|
+
UNSDGs
|
|
18
80
|
};
|
|
19
81
|
}
|
|
20
82
|
|
|
21
|
-
goals() {
|
|
22
|
-
const single = async (
|
|
83
|
+
goals(goalId) {
|
|
84
|
+
const single = async () => {
|
|
23
85
|
const url = `${this.getUrl()}/goals/${goalId}`;
|
|
24
86
|
return await this.get(url);
|
|
25
87
|
};
|
|
26
88
|
|
|
89
|
+
const update = async (data) => {
|
|
90
|
+
const url = `${this.getUrl()}/goals/${goalId}`;
|
|
91
|
+
return await this.post(url, data, 'patch');
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const remove = async () => {
|
|
95
|
+
const url = `${this.getUrl()}/goals/${goalId}`;
|
|
96
|
+
return await this.post(url, null, 'delete');
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
single,
|
|
101
|
+
update,
|
|
102
|
+
delete: remove,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
indicators(indicatorId) {
|
|
107
|
+
const single = async () => {
|
|
108
|
+
const url = `${this.getUrl()}/indicators/${indicatorId}`;
|
|
109
|
+
return await this.get(url);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const update = async (data) => {
|
|
113
|
+
const url = `${this.getUrl()}/indicators/${indicatorId}`;
|
|
114
|
+
return await this.post(url, data, 'patch');
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const remove = async () => {
|
|
118
|
+
const url = `${this.getUrl()}/indicators/${indicatorId}`;
|
|
119
|
+
return await this.post(url, null, 'delete');
|
|
120
|
+
};
|
|
121
|
+
|
|
27
122
|
return {
|
|
28
123
|
single,
|
|
124
|
+
update,
|
|
125
|
+
delete: remove,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
UNSDGs(themeId){
|
|
129
|
+
const attach = async (data) => {
|
|
130
|
+
const url = `${this.getUrl()}/themes/${themeId}/attach-sdg`;
|
|
131
|
+
return await this.update(url,{"sdg_id":data})
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
return {
|
|
135
|
+
attach
|
|
29
136
|
};
|
|
30
137
|
}
|
|
31
138
|
}
|
package/src/endpoints/stats.js
CHANGED
|
@@ -5,12 +5,13 @@ class StatsApi extends Api {
|
|
|
5
5
|
super(resource);
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
async crumb(id
|
|
8
|
+
async crumb(id) {
|
|
9
9
|
this.resource = 'pstats';
|
|
10
|
-
const url = `${this.getUrl()}/${id}${this.getUrlParams(
|
|
10
|
+
const url = `${this.getUrl()}/${id}${this.getUrlParams()}`;
|
|
11
11
|
|
|
12
12
|
return await this.get(url);
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export const Stats = new StatsApi();
|
|
17
|
+
|
package/src/helpers/api.js
CHANGED
|
@@ -1,33 +1,80 @@
|
|
|
1
|
-
import { getCookie } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { getCookie } from "./cookies";
|
|
2
|
+
import { createParamsStringFromArgs } from "../utils/args";
|
|
3
|
+
import { getSession } from "./session";
|
|
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
|
-
if (!url || url.includes(
|
|
46
|
+
if (!url || url.includes("_result=1")) {
|
|
8
47
|
return url;
|
|
9
48
|
}
|
|
10
49
|
|
|
11
50
|
// Check if URL already has the version parameter
|
|
12
|
-
if (url.includes(
|
|
51
|
+
if (url.includes("_v=")) {
|
|
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
|
-
const urlVersionParam = url.includes(
|
|
59
|
+
const urlVersionParam = url.includes("?")
|
|
20
60
|
? `&_v=${version}`
|
|
21
61
|
: `?_v=${version}`;
|
|
22
62
|
|
|
23
63
|
return `${url}${urlVersionParam}`;
|
|
24
64
|
}
|
|
25
65
|
|
|
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
|
+
*/
|
|
26
73
|
function getConfig(method, data, as) {
|
|
27
|
-
const isGet = method ===
|
|
74
|
+
const isGet = method === "get";
|
|
28
75
|
const isSpoofing = as;
|
|
29
76
|
const isFormData = data instanceof FormData;
|
|
30
|
-
const accessToken = `Bearer ${getCookie(
|
|
77
|
+
const accessToken = `Bearer ${getCookie("access_token")}`;
|
|
31
78
|
|
|
32
79
|
const config = {
|
|
33
80
|
method,
|
|
@@ -37,7 +84,7 @@ function getConfig(method, data, as) {
|
|
|
37
84
|
};
|
|
38
85
|
|
|
39
86
|
if (!isFormData) {
|
|
40
|
-
config.headers[
|
|
87
|
+
config.headers["Content-Type"] = "application/json";
|
|
41
88
|
}
|
|
42
89
|
|
|
43
90
|
// TODO: improve this ifs and elses
|
|
@@ -45,7 +92,7 @@ function getConfig(method, data, as) {
|
|
|
45
92
|
if (!data) data = {};
|
|
46
93
|
|
|
47
94
|
if (isFormData) {
|
|
48
|
-
if (isSpoofing) data.set(
|
|
95
|
+
if (isSpoofing) data.set("_method", as.toUpperCase());
|
|
49
96
|
config.body = data;
|
|
50
97
|
} else {
|
|
51
98
|
if (isSpoofing) data._method = as.toUpperCase();
|
|
@@ -58,8 +105,17 @@ function getConfig(method, data, as) {
|
|
|
58
105
|
|
|
59
106
|
export default class Api {
|
|
60
107
|
constructor(resource) {
|
|
61
|
-
|
|
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;
|
|
118
|
+
this.resource = resource ? resource : "";
|
|
63
119
|
this.orgId = null;
|
|
64
120
|
this.orgType = null;
|
|
65
121
|
}
|
|
@@ -68,58 +124,110 @@ export default class Api {
|
|
|
68
124
|
this.baseUrl = baseUrl;
|
|
69
125
|
}
|
|
70
126
|
|
|
127
|
+
/**
|
|
128
|
+
*
|
|
129
|
+
* @returns {promise}
|
|
130
|
+
*/
|
|
71
131
|
async all(args) {
|
|
72
132
|
const url = `${this.getUrl()}${this.getUrlParams(args)}`;
|
|
73
133
|
return await this.get(url);
|
|
74
134
|
}
|
|
75
135
|
|
|
136
|
+
/**
|
|
137
|
+
*
|
|
138
|
+
* @param {string, number} id
|
|
139
|
+
* @param {object} args/params
|
|
140
|
+
* @returns {promise}
|
|
141
|
+
*/
|
|
76
142
|
async single(id, args) {
|
|
77
|
-
const
|
|
78
|
-
const url = `${this.getUrl(id)}${params}`;
|
|
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
|
|
|
86
|
-
|
|
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
|
+
*/
|
|
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
|
-
return await this.post(url, null,
|
|
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
186
|
return await this.unWrap(url);
|
|
98
187
|
}
|
|
99
188
|
|
|
189
|
+
/**
|
|
190
|
+
*
|
|
191
|
+
* @param {string} url
|
|
192
|
+
* @param {object} data
|
|
193
|
+
* @returns {promise}
|
|
194
|
+
*/
|
|
100
195
|
async post(url, data, as, args) {
|
|
101
196
|
if (!url) url = `${this.getUrl()}${this.getUrlParams(args)}`;
|
|
102
|
-
return await this.unWrap(url,
|
|
197
|
+
return await this.unWrap(url, "post", data, as);
|
|
103
198
|
}
|
|
104
199
|
|
|
200
|
+
// ----------
|
|
201
|
+
// --
|
|
202
|
+
/**
|
|
203
|
+
*
|
|
204
|
+
* @param {string, number} id
|
|
205
|
+
* @returns
|
|
206
|
+
*/
|
|
105
207
|
getUrl(id) {
|
|
106
|
-
id = id ? `/${id}` :
|
|
208
|
+
id = id ? `/${id}` : "";
|
|
107
209
|
return `${this.baseUrl}/${this.resource}${id}`;
|
|
108
210
|
}
|
|
109
211
|
|
|
212
|
+
/**
|
|
213
|
+
*
|
|
214
|
+
* @param {object} args
|
|
215
|
+
* @returns {string}
|
|
216
|
+
*/
|
|
110
217
|
getUrlParams(args) {
|
|
218
|
+
this.setOrg();
|
|
111
219
|
let isOrgLess = false;
|
|
112
220
|
let isOrgIdAs = false;
|
|
113
221
|
let isOrgTypeAs = false;
|
|
114
|
-
let orgIdParam =
|
|
115
|
-
let orgTypeParam =
|
|
116
|
-
let argsClone =
|
|
222
|
+
let orgIdParam = "";
|
|
223
|
+
let orgTypeParam = "";
|
|
224
|
+
let argsClone = structuredClone(args); // avoids mutating object
|
|
117
225
|
|
|
118
226
|
// while most of endpoints require an org id and type, some endpoints do not
|
|
119
227
|
if (argsClone) {
|
|
120
|
-
isOrgLess = Object.hasOwn(argsClone,
|
|
121
|
-
isOrgIdAs = Object.hasOwn(argsClone,
|
|
122
|
-
isOrgTypeAs = Object.hasOwn(argsClone,
|
|
228
|
+
isOrgLess = Object.hasOwn(argsClone, "orgless");
|
|
229
|
+
isOrgIdAs = Object.hasOwn(argsClone, "org_id_as");
|
|
230
|
+
isOrgTypeAs = Object.hasOwn(argsClone, "org_type_as");
|
|
123
231
|
}
|
|
124
232
|
|
|
125
233
|
// a super admin user can create/edit data from other orgs
|
|
@@ -145,18 +253,20 @@ export default class Api {
|
|
|
145
253
|
}
|
|
146
254
|
}
|
|
147
255
|
|
|
148
|
-
if (!this.orgId && !this.orgType) {
|
|
149
|
-
const session = getSession();
|
|
150
|
-
this.orgId = session.orgId;
|
|
151
|
-
this.orgType = session.orgType;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
256
|
return `?${orgIdParam}${orgTypeParam}${createParamsStringFromArgs(
|
|
155
257
|
argsClone
|
|
156
258
|
)}`;
|
|
157
259
|
}
|
|
158
260
|
|
|
159
|
-
|
|
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
|
+
*/
|
|
269
|
+
async unWrap(url, method = "get", data, as) {
|
|
160
270
|
url = addVersionParam(url);
|
|
161
271
|
const config = getConfig(method, data, as);
|
|
162
272
|
const response = await fetch(url, config);
|
|
@@ -172,4 +282,12 @@ export default class Api {
|
|
|
172
282
|
});
|
|
173
283
|
});
|
|
174
284
|
}
|
|
285
|
+
|
|
286
|
+
setOrg() {
|
|
287
|
+
const session = getSession();
|
|
288
|
+
if (!session) return;
|
|
289
|
+
const { orgId, orgType } = session;
|
|
290
|
+
this.orgId = orgId;
|
|
291
|
+
this.orgType = orgType;
|
|
292
|
+
}
|
|
175
293
|
}
|
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,43 +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() {
|
|
10
|
-
const claim = async (treeCodeHolder) => {
|
|
11
|
-
const url = `${this.getUrl()}/holders/claim/${treeCodeHolder}`;
|
|
12
|
-
return await this.get(url);
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
return {
|
|
16
|
-
claim,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
stats() {
|
|
21
|
-
const all = async () => {
|
|
22
|
-
const url = `${this.getUrl()}/stats`;
|
|
23
|
-
return await this.get(url);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return {
|
|
27
|
-
all
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
status() {
|
|
32
|
-
const single = async (treeCodeHolder) => {
|
|
33
|
-
const url = `${this.getUrl()}/status/${treeCodeHolder}`;
|
|
34
|
-
return await this.get(url);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return {
|
|
38
|
-
single
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export const TreeCodes = new TreeCodesApi();
|