@veritree/services 2.69.1 → 2.70.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/helpers/api.js +23 -23
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veritree/services",
3
- "version": "2.69.1",
3
+ "version": "2.70.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,6 +1,6 @@
1
- import { getCookie } from "./cookies";
2
- import { createParamsStringFromArgs } from "../utils/args";
3
- import { getSession } from "./session";
1
+ import { getCookie } from './cookies';
2
+ import { createParamsStringFromArgs } from '../utils/args';
3
+ import { getSession } from './session';
4
4
 
5
5
  /**
6
6
  * Returns the runtime configuration object for Nuxt 3.
@@ -43,20 +43,20 @@ import { getSession } from "./session";
43
43
  */
44
44
  function addVersionParam(url) {
45
45
  // If URL is invalid or already has the result parameter, return it as is
46
- if (!url || url.includes("_result=1")) {
46
+ if (!url || url.includes('_result=1')) {
47
47
  return url;
48
48
  }
49
49
 
50
50
  // Check if URL already has the version parameter
51
- if (url.includes("_v=")) {
51
+ if (url.includes('_v=')) {
52
52
  return url;
53
53
  }
54
54
 
55
55
  // Use environment variable if available, otherwise use default version
56
- const version = "11.0.0";
56
+ const version = '13.0.0';
57
57
 
58
58
  // Append version parameter to URL
59
- const urlVersionParam = url.includes("?")
59
+ const urlVersionParam = url.includes('?')
60
60
  ? `&_v=${version}`
61
61
  : `?_v=${version}`;
62
62
 
@@ -71,10 +71,10 @@ function addVersionParam(url) {
71
71
  * @returns {object} data
72
72
  */
73
73
  function getConfig(method, data, as) {
74
- const isGet = method === "get";
74
+ const isGet = method === 'get';
75
75
  const isSpoofing = as;
76
76
  const isFormData = data instanceof FormData;
77
- const accessToken = `Bearer ${getCookie("access_token")}`;
77
+ const accessToken = `Bearer ${getCookie('access_token')}`;
78
78
 
79
79
  const config = {
80
80
  method,
@@ -84,7 +84,7 @@ function getConfig(method, data, as) {
84
84
  };
85
85
 
86
86
  if (!isFormData) {
87
- config.headers["Content-Type"] = "application/json";
87
+ config.headers['Content-Type'] = 'application/json';
88
88
  }
89
89
 
90
90
  // TODO: improve this ifs and elses
@@ -92,7 +92,7 @@ function getConfig(method, data, as) {
92
92
  if (!data) data = {};
93
93
 
94
94
  if (isFormData) {
95
- if (isSpoofing) data.set("_method", as.toUpperCase());
95
+ if (isSpoofing) data.set('_method', as.toUpperCase());
96
96
  config.body = data;
97
97
  } else {
98
98
  if (isSpoofing) data._method = as.toUpperCase();
@@ -115,7 +115,7 @@ export default class Api {
115
115
  // this.baseUrl = url + "/api";
116
116
 
117
117
  this.baseUrl = process.env ? `${process.env.API_VERITREE_URL}/api` : null;
118
- this.resource = resource ? resource : "";
118
+ this.resource = resource ? resource : '';
119
119
  this.orgId = null;
120
120
  this.orgType = null;
121
121
  }
@@ -160,7 +160,7 @@ export default class Api {
160
160
  * @param {string} as - 'put' // necessary for updates because of how Laravel handles PUT requests
161
161
  * @returns {promise}
162
162
  */
163
- async update(id, data, as = "put", args) {
163
+ async update(id, data, as = 'put', args) {
164
164
  const url = `${this.getUrl(id)}${this.getUrlParams(args)}`;
165
165
  return await this.post(url, data, as);
166
166
  }
@@ -174,7 +174,7 @@ export default class Api {
174
174
  */
175
175
  async delete(id, args) {
176
176
  const url = `${this.getUrl(id)}${this.getUrlParams(args)}`;
177
- return await this.post(url, null, "delete");
177
+ return await this.post(url, null, 'delete');
178
178
  }
179
179
 
180
180
  /**
@@ -194,7 +194,7 @@ export default class Api {
194
194
  */
195
195
  async post(url, data, as, args) {
196
196
  if (!url) url = `${this.getUrl()}${this.getUrlParams(args)}`;
197
- return await this.unWrap(url, "post", data, as);
197
+ return await this.unWrap(url, 'post', data, as);
198
198
  }
199
199
 
200
200
  // ----------
@@ -205,7 +205,7 @@ export default class Api {
205
205
  * @returns
206
206
  */
207
207
  getUrl(id) {
208
- id = id ? `/${id}` : "";
208
+ id = id ? `/${id}` : '';
209
209
  return `${this.baseUrl}/${this.resource}${id}`;
210
210
  }
211
211
 
@@ -219,15 +219,15 @@ export default class Api {
219
219
  let isOrgLess = false;
220
220
  let isOrgIdAs = false;
221
221
  let isOrgTypeAs = false;
222
- let orgIdParam = "";
223
- let orgTypeParam = "";
222
+ let orgIdParam = '';
223
+ let orgTypeParam = '';
224
224
  let argsClone = structuredClone(args); // avoids mutating object
225
225
 
226
226
  // while most of endpoints require an org id and type, some endpoints do not
227
227
  if (argsClone) {
228
- isOrgLess = Object.hasOwn(argsClone, "orgless");
229
- isOrgIdAs = Object.hasOwn(argsClone, "org_id_as");
230
- isOrgTypeAs = Object.hasOwn(argsClone, "org_type_as");
228
+ isOrgLess = Object.hasOwn(argsClone, 'orgless');
229
+ isOrgIdAs = Object.hasOwn(argsClone, 'org_id_as');
230
+ isOrgTypeAs = Object.hasOwn(argsClone, 'org_type_as');
231
231
  }
232
232
 
233
233
  // a super admin user can create/edit data from other orgs
@@ -266,7 +266,7 @@ export default class Api {
266
266
  * @param {object} data
267
267
  * @returns {object} envelope
268
268
  */
269
- async unWrap(url, method = "get", data, as) {
269
+ async unWrap(url, method = 'get', data, as) {
270
270
  url = addVersionParam(url);
271
271
  const config = getConfig(method, data, as);
272
272
  const response = await fetch(url, config);
@@ -288,7 +288,7 @@ export default class Api {
288
288
  response.ok ? resolve(res) : reject(res);
289
289
  });
290
290
  } else {
291
- throw new Error("This response header content-type is not handled.");
291
+ throw new Error('This response header content-type is not handled.');
292
292
  }
293
293
  });
294
294
  }