@veritree/services 2.30.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/jsdoc.json ADDED
@@ -0,0 +1,16 @@
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veritree/services",
3
- "version": "2.30.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",
@@ -12,5 +12,6 @@
12
12
  },
13
13
  "dependencies": {
14
14
  "np": "^7.6.2"
15
- }
15
+ },
16
+ "devDependencies": {}
16
17
  }
@@ -1,9 +1,9 @@
1
- import Api from '../helpers/api';
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 = 'organizations';
6
+ this.resource = "organizations";
7
7
  }
8
8
 
9
9
  tasks(orgId) {
@@ -14,6 +14,12 @@ 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
+ */
17
23
  const create = async (data) => {
18
24
  url = `${url}${this.getUrlParams()}`;
19
25
  return await this.post(url, data);
@@ -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();
@@ -1,46 +1,7 @@
1
1
  import { getCookie } from "./cookies";
2
- import { createParamsStringFromArgs } from "../utils/args";
3
2
  import { getSession } from "./session";
3
+ import { createParamsStringFromArgs } from "../utils/args";
4
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
- */
44
5
  function addVersionParam(url) {
45
6
  // If URL is invalid or already has the result parameter, return it as is
46
7
  if (!url || url.includes("_result=1")) {
@@ -52,8 +13,7 @@ function addVersionParam(url) {
52
13
  return url;
53
14
  }
54
15
 
55
- // Use environment variable if available, otherwise use default version
56
- const version = process.env.API_VERITREE_VERSION || "5.0.0";
16
+ const version = '10.0.0';
57
17
 
58
18
  // Append version parameter to URL
59
19
  const urlVersionParam = url.includes("?")
@@ -63,13 +23,7 @@ function addVersionParam(url) {
63
23
  return `${url}${urlVersionParam}`;
64
24
  }
65
25
 
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
27
  function getConfig(method, data, as) {
74
28
  const isGet = method === "get";
75
29
  const isSpoofing = as;
@@ -105,16 +59,7 @@ function getConfig(method, data, as) {
105
59
 
106
60
  export default class Api {
107
61
  constructor(resource) {
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;
62
+ this.baseUrl = null;
118
63
  this.resource = resource ? resource : "";
119
64
  this.orgId = null;
120
65
  this.orgType = null;
@@ -124,96 +69,45 @@ export default class Api {
124
69
  this.baseUrl = baseUrl;
125
70
  }
126
71
 
127
- /**
128
- *
129
- * @returns {promise}
130
- */
131
72
  async all(args) {
132
73
  const url = `${this.getUrl()}${this.getUrlParams(args)}`;
133
74
  return await this.get(url);
134
75
  }
135
76
 
136
- /**
137
- *
138
- * @param {string, number} id
139
- * @param {object} args/params
140
- * @returns {promise}
141
- */
142
77
  async single(id, args) {
143
78
  const url = `${this.getUrl(id)}${this.getUrlParams(args)}`;
144
79
  return await this.get(url);
145
80
  }
146
81
 
147
- /**
148
- *
149
- * @param {object} data
150
- * @returns {promise}
151
- */
152
82
  async create(data, args) {
153
83
  return await this.post(null, data, null, args);
154
84
  }
155
85
 
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
86
  async update(id, data, as = "put", args) {
164
87
  const url = `${this.getUrl(id)}${this.getUrlParams(args)}`;
165
88
  return await this.post(url, data, as);
166
89
  }
167
90
 
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
- */
175
91
  async delete(id, args) {
176
92
  const url = `${this.getUrl(id)}${this.getUrlParams(args)}`;
177
93
  return await this.post(url, null, "delete");
178
94
  }
179
95
 
180
- /**
181
- *
182
- * @param {string} url
183
- * @returns {promise}
184
- */
185
96
  async get(url) {
97
+ console.log(url);
186
98
  return await this.unWrap(url);
187
99
  }
188
100
 
189
- /**
190
- *
191
- * @param {string} url
192
- * @param {object} data
193
- * @returns {promise}
194
- */
195
101
  async post(url, data, as, args) {
196
102
  if (!url) url = `${this.getUrl()}${this.getUrlParams(args)}`;
197
103
  return await this.unWrap(url, "post", data, as);
198
104
  }
199
105
 
200
- // ----------
201
- // --
202
- /**
203
- *
204
- * @param {string, number} id
205
- * @returns
206
- */
207
106
  getUrl(id) {
208
107
  id = id ? `/${id}` : "";
209
108
  return `${this.baseUrl}/${this.resource}${id}`;
210
109
  }
211
110
 
212
- /**
213
- *
214
- * @param {object} args
215
- * @returns {string}
216
- */
217
111
  getUrlParams(args) {
218
112
  this.setOrg();
219
113
  let isOrgLess = false;
@@ -258,14 +152,6 @@ export default class Api {
258
152
  )}`;
259
153
  }
260
154
 
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
155
  async unWrap(url, method = "get", data, as) {
270
156
  url = addVersionParam(url);
271
157
  const config = getConfig(method, data, as);