@veritree/services 2.30.1-1 → 2.31.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
@@ -37,6 +37,7 @@ import { Organizations } from './src/endpoints/organizations';
37
37
  import { Tasks } from './src/endpoints/tasks';
38
38
  import { Geometries } from './src/endpoints/geometries';
39
39
  import { Password } from './src/endpoints/password';
40
+ import { TreeCodes } from './src/endpoints/tree-codes';
40
41
 
41
42
  export {
42
43
  BulkUploads,
@@ -77,5 +78,6 @@ export {
77
78
  Organizations,
78
79
  Tasks,
79
80
  Geometries,
80
- Password
81
+ Password,
82
+ TreeCodes
81
83
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veritree/services",
3
- "version": "2.30.1-1",
3
+ "version": "2.31.0",
4
4
  "description": "A collection of javascript functions/services to talk to veritree API",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -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
- * belonging to the Password domain.
6
- *
7
- * @namespace Password
4
+ * This is a namespace that contains documentation elements belonging to the Password domain.
5
+ *
6
+ * @class
7
+ * @module Password
8
8
  */
9
9
  class PasswordApi extends Api {
10
10
  constructor(resource) {
@@ -12,6 +12,11 @@ class PasswordApi extends Api {
12
12
  this.resource = "password";
13
13
  }
14
14
 
15
+ /**
16
+ * @function
17
+ * @name recovery
18
+ * @returns {Object}
19
+ */
15
20
  recovery() {
16
21
  /**
17
22
  * Sends a recovery password email to the specified email address.
@@ -32,6 +37,11 @@ class PasswordApi extends Api {
32
37
  };
33
38
  }
34
39
 
40
+ /**
41
+ * @function
42
+ * @name reset
43
+ * @returns {Object}
44
+ */
35
45
  reset() {
36
46
  /**
37
47
  * Sends a POST request to reset a password with the specified email, token, and password.
@@ -44,7 +54,7 @@ class PasswordApi extends Api {
44
54
  * @returns {Promise<Object>} - A Promise that resolves to the result of the POST request.
45
55
  */
46
56
  const post = async (data) => {
47
- const url = `${this.getUrl()}/reset`
57
+ const url = `${this.getUrl()}/reset`;
48
58
 
49
59
  return await this.post(url, data);
50
60
  };
@@ -55,4 +65,4 @@ class PasswordApi extends Api {
55
65
  }
56
66
  }
57
67
 
58
- export const Password = new PasswordApi();
68
+ export const Password = new PasswordApi();
@@ -0,0 +1,21 @@
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(args) {
10
+ const claim = async (treeCodeHolder) => {
11
+ const url = `${this.getUrl()}/holders/claim/${treeCodeHolder}${this.getUrlParams(args)}`;
12
+ return await this.get(url);
13
+ };
14
+
15
+ return {
16
+ claim,
17
+ };
18
+ }
19
+ }
20
+
21
+ export const TreeCodes = new TreeCodesApi();
@@ -23,13 +23,7 @@ function addVersionParam(url) {
23
23
  return `${url}${urlVersionParam}`;
24
24
  }
25
25
 
26
- /**
27
- * Handles how the data should be sent in the fetch method
28
- *
29
- * @param {string} method
30
- * @param {object} body
31
- * @returns {object} data
32
- */
26
+
33
27
  function getConfig(method, data, as) {
34
28
  const isGet = method === "get";
35
29
  const isSpoofing = as;
@@ -75,96 +69,45 @@ export default class Api {
75
69
  this.baseUrl = baseUrl;
76
70
  }
77
71
 
78
- /**
79
- *
80
- * @returns {promise}
81
- */
82
72
  async all(args) {
83
73
  const url = `${this.getUrl()}${this.getUrlParams(args)}`;
84
74
  return await this.get(url);
85
75
  }
86
76
 
87
- /**
88
- *
89
- * @param {string, number} id
90
- * @param {object} args/params
91
- * @returns {promise}
92
- */
93
77
  async single(id, args) {
94
78
  const url = `${this.getUrl(id)}${this.getUrlParams(args)}`;
95
79
  return await this.get(url);
96
80
  }
97
81
 
98
- /**
99
- *
100
- * @param {object} data
101
- * @returns {promise}
102
- */
103
82
  async create(data, args) {
104
83
  return await this.post(null, data, null, args);
105
84
  }
106
85
 
107
- /**
108
- *
109
- * @param {string} url
110
- * @param {object} data
111
- * @param {string} as - 'put' // necessary for updates because of how Laravel handles PUT requests
112
- * @returns {promise}
113
- */
114
86
  async update(id, data, as = "put", args) {
115
87
  const url = `${this.getUrl(id)}${this.getUrlParams(args)}`;
116
88
  return await this.post(url, data, as);
117
89
  }
118
90
 
119
- /**
120
- *
121
- * @param {string} url
122
- * @param {object} data
123
- * @param {string} as - 'put' // necessary for updates because of how Laravel handles PUT requests
124
- * @returns {promise}
125
- */
126
91
  async delete(id, args) {
127
92
  const url = `${this.getUrl(id)}${this.getUrlParams(args)}`;
128
93
  return await this.post(url, null, "delete");
129
94
  }
130
95
 
131
- /**
132
- *
133
- * @param {string} url
134
- * @returns {promise}
135
- */
136
96
  async get(url) {
97
+ console.log(url);
137
98
  return await this.unWrap(url);
138
99
  }
139
100
 
140
- /**
141
- *
142
- * @param {string} url
143
- * @param {object} data
144
- * @returns {promise}
145
- */
146
101
  async post(url, data, as, args) {
147
102
  if (!url) url = `${this.getUrl()}${this.getUrlParams(args)}`;
148
103
  return await this.unWrap(url, "post", data, as);
149
104
  }
150
105
 
151
- // ----------
152
- // --
153
- /**
154
- *
155
- * @param {string, number} id
156
- * @returns
157
- */
158
106
  getUrl(id) {
159
107
  id = id ? `/${id}` : "";
160
108
  return `${this.baseUrl}/${this.resource}${id}`;
161
109
  }
162
110
 
163
- /**
164
- *
165
- * @param {object} args
166
- * @returns {string}
167
- */
168
111
  getUrlParams(args) {
169
112
  this.setOrg();
170
113
  let isOrgLess = false;
@@ -209,14 +152,6 @@ export default class Api {
209
152
  )}`;
210
153
  }
211
154
 
212
- /**
213
- * Deals with all fetch requests
214
- *
215
- * @param {string} url
216
- * @param {string} method
217
- * @param {object} data
218
- * @returns {object} envelope
219
- */
220
155
  async unWrap(url, method = "get", data, as) {
221
156
  url = addVersionParam(url);
222
157
  const config = getConfig(method, data, as);