@veritree/services 0.3.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 CHANGED
@@ -1,13 +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/forestTypes.js';
3
+ import { createForestTypesApiService } from './src/services/forest-types.js';
4
4
  import { createSubdomainsApiService } from './src/services/subdomains.js';
5
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';
6
8
 
7
9
  export {
8
10
  createSponsorsApiService,
9
11
  createOrgsApiService,
10
12
  createForestTypesApiService,
11
13
  createSubdomainsApiService,
12
- createCountriesApiService
14
+ createCountriesApiService,
15
+ createSubsitesApiService,
16
+ createTreeOrdersApiService
13
17
  }
package/package-lock.json CHANGED
@@ -1,5 +1,13 @@
1
1
  {
2
2
  "name": "@veritree/services",
3
- "version": "0.2.0",
4
- "lockfileVersion": 1
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.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",
@@ -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
+ };
@@ -8,7 +8,7 @@ export const createOrgsApiService = (orgId, orgType) => {
8
8
  const stats = {
9
9
  async get(isPublic) {
10
10
  const endpoint = _getStatsEndpoint(isPublic);
11
- const url = _getUrl(endpoint);
11
+ const url = `${_getUrl()}/${endpoint}?${_getUrlParams()}`;
12
12
  return await Api.get(url);
13
13
  },
14
14
  };
@@ -18,9 +18,13 @@ export const createOrgsApiService = (orgId, orgType) => {
18
18
  }
19
19
 
20
20
  const _getUrl = (endpoint) => {
21
- return `${Api.baseUrl}/${resource}/${endpoint}?org_id=${orgId}&org_type=${orgType}`;
21
+ return `${Api.baseUrl}/${resource}`;
22
22
  };
23
23
 
24
+ const _getUrlParams = () => {
25
+ return `org_id=${orgId}&org_type=${orgType}`
26
+ }
27
+
24
28
  return {
25
29
  stats,
26
30
  };
@@ -7,7 +7,7 @@ export const createSponsorsApiService = (orgId) => {
7
7
  // filter for map data
8
8
  const map = {
9
9
  async get() {
10
- const url = _getUrl('map-data');
10
+ const url = `${_getUrl()}/${orgId}/map-data`;
11
11
  return await Api.get(url);
12
12
  },
13
13
  };
@@ -15,13 +15,13 @@ export const createSponsorsApiService = (orgId) => {
15
15
  // filter for profile
16
16
  const profile = {
17
17
  async get() {
18
- const url = _getUrl('profile');
18
+ const url = `${_getUrl()}/${orgId}/profile`;
19
19
  return await Api.get(url);
20
20
  },
21
21
  };
22
22
 
23
- const _getUrl = (endpoint) => {
24
- return `${Api.baseUrl}/${resource}/${orgId}/${endpoint}`;
23
+ const _getUrl = () => {
24
+ return `${Api.baseUrl}/${resource}`;
25
25
  };
26
26
 
27
27
  return {
@@ -5,17 +5,19 @@ export const createSubdomainsApiService = () => {
5
5
 
6
6
  const get = {
7
7
  /**
8
+ * Gets org data related to subdomain
9
+ *
8
10
  * @param {string} id (name or id)
9
11
  * @returns {object} evenlop
10
12
  */
11
13
  async specific(id) {
12
- const url = _getUrl(id);
14
+ const url = `${_getUrl()}/${id}`;
13
15
  return await Api.get(url);
14
16
  },
15
17
  };
16
18
 
17
- function _getUrl(id) {
18
- return `${Api.baseUrl}/${resource}/${id}`;
19
+ function _getUrl() {
20
+ return `${Api.baseUrl}/${resource}`;
19
21
  }
20
22
 
21
23
  return {
@@ -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
+ };
@@ -1,41 +0,0 @@
1
- import Api from '../helpers/api';
2
-
3
- // TODO: Add all possible parameters as in API
4
- export const createForestTypesApiService = () => {
5
- /**
6
- * Gets the right resource for the request based on the isPublic flag.
7
- *
8
- * @param {boolean} isPublic
9
- * @returns {string} resource
10
- */
11
- const _getResource = (isPublic) => {
12
- return isPublic ? 'forest-type-profiles' : `forest-types`;
13
- };
14
-
15
- const get = {
16
- async all(isPublic = false) {
17
- const url = _handleUrl(isPublic);
18
- return await Api.get(url);
19
- },
20
-
21
- async specific(id, isPublic = false) {
22
- const url = _handleUrl(isPublic, id);
23
- return await Api.get(url);
24
- },
25
- };
26
-
27
- function _handleUrl(isPublic, id) {
28
- const resource = _getResource(isPublic);
29
- return _getUrl(resource, id);
30
- }
31
-
32
- function _getUrl(resource, id) {
33
- return id
34
- ? `${Api.baseUrl}/${resource}/${id}`
35
- : `${Api.baseUrl}/${resource}`;
36
- }
37
-
38
- return {
39
- get,
40
- };
41
- };