@veritree/services 0.1.1 → 0.2.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,7 +1,11 @@
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';
4
+ import { createSubdomainsApiService } from './src/services/subdomains.js';
3
5
 
4
6
  export {
5
7
  createSponsorsApiService,
6
8
  createOrgsApiService,
9
+ createForestTypesApiService,
10
+ createSubdomainsApiService
7
11
  }
package/package-lock.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@veritree/services",
3
- "version": "0.0.2",
3
+ "version": "0.1.1",
4
4
  "lockfileVersion": 1
5
5
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veritree/services",
3
- "version": "0.1.1",
3
+ "version": "0.2.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,41 @@
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
+ };
@@ -0,0 +1,24 @@
1
+ import Api from '../helpers/api';
2
+
3
+ export const createSubdomainsApiService = () => {
4
+ const resource = 'subdomains';
5
+
6
+ const get = {
7
+ /**
8
+ * @param {string} id (name or id)
9
+ * @returns {object} evenlop
10
+ */
11
+ async specific(id) {
12
+ const url = _getUrl(id);
13
+ return await Api.get(url);
14
+ },
15
+ };
16
+
17
+ function _getUrl(id) {
18
+ return `${Api.baseUrl}/${resource}/${id}`;
19
+ }
20
+
21
+ return {
22
+ get,
23
+ };
24
+ };