@veritree/services 0.1.0 → 0.4.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 +10 -0
- package/package-lock.json +10 -2
- package/package.json +2 -3
- package/src/services/countries.js +23 -0
- package/src/services/forest-types.js +41 -0
- package/src/services/orgs.js +10 -5
- package/src/services/sponsors.js +6 -4
- package/src/services/subdomains.js +26 -0
- package/src/services/subsites.js +43 -0
- package/src/services/trees-orders.js +44 -0
package/index.js
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import { createSponsorsApiService } from './src/services/sponsors.js';
|
|
2
2
|
import { createOrgsApiService } from './src/services/orgs.js';
|
|
3
|
+
import { createForestTypesApiService } from './src/services/forest-types.js';
|
|
4
|
+
import { createSubdomainsApiService } from './src/services/subdomains.js';
|
|
5
|
+
import { createCountriesApiService } from './src/services/countries.js';
|
|
6
|
+
import { createSubsitesApiService } from './src/services/subsites.js';
|
|
7
|
+
import { createTreeOrdersApiService } from './src/services/trees-orders.js';
|
|
3
8
|
|
|
4
9
|
export {
|
|
5
10
|
createSponsorsApiService,
|
|
6
11
|
createOrgsApiService,
|
|
12
|
+
createForestTypesApiService,
|
|
13
|
+
createSubdomainsApiService,
|
|
14
|
+
createCountriesApiService,
|
|
15
|
+
createSubsitesApiService,
|
|
16
|
+
createTreeOrdersApiService
|
|
7
17
|
}
|
package/package-lock.json
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veritree/services",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"lockfileVersion":
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"lockfileVersion": 2,
|
|
5
|
+
"requires": true,
|
|
6
|
+
"packages": {
|
|
7
|
+
"": {
|
|
8
|
+
"name": "@veritree/services",
|
|
9
|
+
"version": "0.3.0",
|
|
10
|
+
"license": "MIT"
|
|
11
|
+
}
|
|
12
|
+
}
|
|
5
13
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veritree/services",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "A collection of javascript functions/services to talk to veritree API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -9,6 +9,5 @@
|
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"publishConfig": {
|
|
11
11
|
"access": "public"
|
|
12
|
-
}
|
|
13
|
-
"devDependencies": {}
|
|
12
|
+
}
|
|
14
13
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import Api from '../helpers/api';
|
|
2
|
+
|
|
3
|
+
export const createCountriesApiService = (countryId) => {
|
|
4
|
+
|
|
5
|
+
const resource = 'countries';
|
|
6
|
+
|
|
7
|
+
const stats = {
|
|
8
|
+
async get() {
|
|
9
|
+
// Look for a country ID if none provided global stats will be sent
|
|
10
|
+
const type = countryId ? `${countryId}` : 'global';
|
|
11
|
+
const url = _getUrl(type +'/stats');
|
|
12
|
+
return await Api.get(url);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const _getUrl = (endpoint) => {
|
|
17
|
+
return `${Api.baseUrl}/${resource}/${endpoint}`;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
stats
|
|
22
|
+
};
|
|
23
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import Api from '../helpers/api';
|
|
2
|
+
|
|
3
|
+
// TODO: Add all possible parameters as in API
|
|
4
|
+
export const createForestTypesApiService = () => {
|
|
5
|
+
const get = {
|
|
6
|
+
/**
|
|
7
|
+
* Gets all forest types of an organization
|
|
8
|
+
*
|
|
9
|
+
* @param {boolean} isPublic
|
|
10
|
+
* @returns {object} envelope
|
|
11
|
+
*/
|
|
12
|
+
async all(isPublic = false) {
|
|
13
|
+
const url = `${_getUrl(isPublic)}`;
|
|
14
|
+
return await Api.get(url);
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Gets a speficific forest type of an organization
|
|
19
|
+
*
|
|
20
|
+
* @param {number/string} id
|
|
21
|
+
* @param {boolean} isPublic
|
|
22
|
+
* @returns {object} envelope
|
|
23
|
+
*/
|
|
24
|
+
async specific(id, isPublic = false) {
|
|
25
|
+
const url = `${_getUrl(isPublic)}/${id}`;
|
|
26
|
+
return await Api.get(url);
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const _getResource = (isPublic) => {
|
|
31
|
+
return isPublic ? 'forest-type-profiles' : `forest-types`;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const _getUrl = (isPublic) => {
|
|
35
|
+
return `${Api.baseUrl}/${_getResource(isPublic)}`
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
get,
|
|
40
|
+
};
|
|
41
|
+
};
|
package/src/services/orgs.js
CHANGED
|
@@ -3,23 +3,28 @@ import Api from '../helpers/api';
|
|
|
3
3
|
export const createOrgsApiService = (orgId, orgType) => {
|
|
4
4
|
if (!orgId && !orgType) throw new Error('No org id and/or type provided');
|
|
5
5
|
const resource = 'orgs';
|
|
6
|
-
|
|
6
|
+
|
|
7
|
+
// filter for stats data
|
|
7
8
|
const stats = {
|
|
8
9
|
async get(isPublic) {
|
|
9
|
-
const endpoint =
|
|
10
|
-
const url = _getUrl(endpoint)
|
|
10
|
+
const endpoint = _getStatsEndpoint(isPublic);
|
|
11
|
+
const url = `${_getUrl()}/${endpoint}?${_getUrlParams()}`;
|
|
11
12
|
return await Api.get(url);
|
|
12
13
|
},
|
|
13
14
|
};
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
const _getStatsEndpoint = (isPublic) => {
|
|
16
17
|
return isPublic ? 'pstats' : 'stats';
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
const _getUrl = (endpoint) => {
|
|
20
|
-
return `${Api.baseUrl}/${resource}
|
|
21
|
+
return `${Api.baseUrl}/${resource}`;
|
|
21
22
|
};
|
|
22
23
|
|
|
24
|
+
const _getUrlParams = () => {
|
|
25
|
+
return `org_id=${orgId}&org_type=${orgType}`
|
|
26
|
+
}
|
|
27
|
+
|
|
23
28
|
return {
|
|
24
29
|
stats,
|
|
25
30
|
};
|
package/src/services/sponsors.js
CHANGED
|
@@ -4,22 +4,24 @@ export const createSponsorsApiService = (orgId) => {
|
|
|
4
4
|
if (!orgId) throw new Error('No org id provided');
|
|
5
5
|
const resource = 'sponsors';
|
|
6
6
|
|
|
7
|
+
// filter for map data
|
|
7
8
|
const map = {
|
|
8
9
|
async get() {
|
|
9
|
-
const url = _getUrl(
|
|
10
|
+
const url = `${_getUrl()}/${orgId}/map-data`;
|
|
10
11
|
return await Api.get(url);
|
|
11
12
|
},
|
|
12
13
|
};
|
|
13
14
|
|
|
15
|
+
// filter for profile
|
|
14
16
|
const profile = {
|
|
15
17
|
async get() {
|
|
16
|
-
const url = _getUrl(
|
|
18
|
+
const url = `${_getUrl()}/${orgId}/profile`;
|
|
17
19
|
return await Api.get(url);
|
|
18
20
|
},
|
|
19
21
|
};
|
|
20
22
|
|
|
21
|
-
const _getUrl = (
|
|
22
|
-
return `${Api.baseUrl}/${resource}
|
|
23
|
+
const _getUrl = () => {
|
|
24
|
+
return `${Api.baseUrl}/${resource}`;
|
|
23
25
|
};
|
|
24
26
|
|
|
25
27
|
return {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import Api from '../helpers/api';
|
|
2
|
+
|
|
3
|
+
export const createSubdomainsApiService = () => {
|
|
4
|
+
const resource = 'subdomains';
|
|
5
|
+
|
|
6
|
+
const get = {
|
|
7
|
+
/**
|
|
8
|
+
* Gets org data related to subdomain
|
|
9
|
+
*
|
|
10
|
+
* @param {string} id (name or id)
|
|
11
|
+
* @returns {object} evenlop
|
|
12
|
+
*/
|
|
13
|
+
async specific(id) {
|
|
14
|
+
const url = `${_getUrl()}/${id}`;
|
|
15
|
+
return await Api.get(url);
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
function _getUrl() {
|
|
20
|
+
return `${Api.baseUrl}/${resource}`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
get,
|
|
25
|
+
};
|
|
26
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import Api from '../helpers/api';
|
|
2
|
+
|
|
3
|
+
export const createSubsitesApiService = (orgId, orgType) => {
|
|
4
|
+
if (!orgId) throw new Error('orgId is required');
|
|
5
|
+
const resource = 'subsites';
|
|
6
|
+
|
|
7
|
+
const get = {
|
|
8
|
+
/**
|
|
9
|
+
* Gets all subsites of an organization
|
|
10
|
+
*
|
|
11
|
+
* @param {number/string} page
|
|
12
|
+
* @returns {object} envelope
|
|
13
|
+
*/
|
|
14
|
+
async all(page = 1) {
|
|
15
|
+
const url = `${_getUrl()}?${_getUrlParams(page)}`;
|
|
16
|
+
return await Api.get(url);
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Gets a speficific subsite of an organization
|
|
21
|
+
*
|
|
22
|
+
* @param {number/string} id
|
|
23
|
+
* @param {number/string} page
|
|
24
|
+
* @returns {object} envelope
|
|
25
|
+
*/
|
|
26
|
+
async specific(id, page = 1) {
|
|
27
|
+
const url = `${_getUrl()}/${id}?${_getUrlParams(page)}`;
|
|
28
|
+
return await Api.get(url);
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const _getUrl = () => {
|
|
33
|
+
return `${Api.baseUrl}/${resource}`;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const _getUrlParams = (page = 1) => {
|
|
37
|
+
return `org_id=${orgId}&org_type=${orgType}&page=${page}`;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
get,
|
|
42
|
+
};
|
|
43
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import Api from '../helpers/api';
|
|
2
|
+
|
|
3
|
+
export const createTreeOrdersApiService = (orgId, orgType) => {
|
|
4
|
+
const resource = 'tree-orders';
|
|
5
|
+
|
|
6
|
+
const get = {
|
|
7
|
+
/**
|
|
8
|
+
* Gets all orders of an organization
|
|
9
|
+
*
|
|
10
|
+
* @param {number/string} page
|
|
11
|
+
* @param {number/string} pageSize
|
|
12
|
+
* @returns {object} envelope
|
|
13
|
+
*/
|
|
14
|
+
async all(page = 1, pageSize = 10) {
|
|
15
|
+
const url = `${_getUrl()}?${_getUrlParams(page, pageSize)}`;
|
|
16
|
+
return await Api.get(url);
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Gets a specifi order of an organization
|
|
21
|
+
*
|
|
22
|
+
* @param {number/string} id
|
|
23
|
+
* @param {number/string} page
|
|
24
|
+
* @param {number/string} pageSize
|
|
25
|
+
* @returns {object} envelope
|
|
26
|
+
*/
|
|
27
|
+
async specific(id, page = 1, pageSize = 10) {
|
|
28
|
+
const url = `${_getUrl()}/${id}?${_getUrlParams(page, pageSize)}`;
|
|
29
|
+
return await Api.get(url);
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const _getUrl = () => {
|
|
34
|
+
return `${Api.baseUrl}/${resource}`;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const _getUrlParams = (page, pageSize) => {
|
|
38
|
+
return `org_id=${orgId}&org_type=${orgType}&page=${page}&page_size=${pageSize}&include=tree_allocations`;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
get,
|
|
43
|
+
};
|
|
44
|
+
};
|