@veritree/services 1.0.0-4 → 1.0.0-5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veritree/services",
3
- "version": "1.0.0-4",
3
+ "version": "1.0.0-5",
4
4
  "description": "A collection of javascript functions/services to talk to veritree API",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -55,9 +55,9 @@ export default class Api {
55
55
  * @param {string} url
56
56
  * @returns {promise}
57
57
  */
58
- get = async function (url) {
58
+ async get(url) {
59
59
  return await this.unWrap(url);
60
- };
60
+ }
61
61
 
62
62
  /**
63
63
  *
@@ -65,27 +65,25 @@ export default class Api {
65
65
  * @param {object} data
66
66
  * @returns {promise}
67
67
  */
68
- post = async function (url, data, as) {
68
+ async post(url, data, as) {
69
69
  if (!url) url = `${this.getUrl()}${this.getUrlParams()}`;
70
70
  return await this.unWrap(url, "post", data, as);
71
- };
71
+ }
72
72
 
73
73
  // ----------
74
74
  // --
75
- getUrl = () => {
75
+ getUrl() {
76
76
  return `${this.baseUrl}/${this.resource}`;
77
- };
77
+ }
78
78
 
79
- getUrlParams = (args) => {
79
+ getUrlParams(args) {
80
80
  this.setOrg();
81
81
 
82
82
  const orgIdParam = this.orgId ? `org_id=${this.orgId}` : "";
83
83
  const orgTypeParam = this.orgType ? `org_type=${this.orgType}` : "";
84
84
 
85
- return `?${orgIdParam}&${orgTypeParam}${createParamsStringFromArgs(
86
- args
87
- )}`;
88
- };
85
+ return `?${orgIdParam}&${orgTypeParam}${createParamsStringFromArgs(args)}`;
86
+ }
89
87
 
90
88
  /**
91
89
  * Deals with all fetch requests
@@ -95,7 +93,7 @@ export default class Api {
95
93
  * @param {object} data
96
94
  * @returns {object} envelope
97
95
  */
98
- unWrap = async function (url, method = "get", data, as) {
96
+ async unWrap(url, method = "get", data, as) {
99
97
  url = this.handleEnvelopParam(url, data); // TODO: remove when API is fully migrated to envelopes
100
98
  const config = this.getConfig(method, data, as);
101
99
 
@@ -107,7 +105,7 @@ export default class Api {
107
105
  } catch (err) {
108
106
  throw new Error(err);
109
107
  }
110
- };
108
+ }
111
109
 
112
110
  /**
113
111
  * Handles how the data should be sent in the fetch method
@@ -116,7 +114,7 @@ export default class Api {
116
114
  * @param {object} body
117
115
  * @returns {object} data
118
116
  */
119
- getConfig = function (method, data, as) {
117
+ getConfig(method, data, as) {
120
118
  const isGet = method === "get";
121
119
  const isPut = as === "put";
122
120
  const isFormData = this.isFormData(data);
@@ -145,11 +143,11 @@ export default class Api {
145
143
  }
146
144
 
147
145
  return config;
148
- };
146
+ }
149
147
 
150
- setOrg = () => {
148
+ setOrg() {
151
149
  const session = getSession();
152
- if(!session) return;
150
+ if (!session) return;
153
151
  const { orgId, orgType } = session;
154
152
  this.orgId = orgId;
155
153
  this.orgType = orgType;
@@ -161,14 +159,16 @@ export default class Api {
161
159
  * @param {string} url
162
160
  * @returns {string} url
163
161
  */
164
- handleEnvelopParam = function (url) {
162
+ handleEnvelopParam(url) {
165
163
  if (!url || url.includes("_result=1")) return url;
166
164
 
167
165
  const urlHasArgs = url.includes("?");
168
166
  const urlEvenlopeArg = urlHasArgs ? "&_result=1" : "?_result=1";
169
167
 
170
168
  return `${url}${urlEvenlopeArg}`;
171
- };
169
+ }
172
170
 
173
- isFormData = (data) => data instanceof FormData;
171
+ isFormData(data) {
172
+ data instanceof FormData;
173
+ }
174
174
  }
@@ -1,9 +1,9 @@
1
- import Api from '../helpers/api';
1
+ import Api from "../helpers/api";
2
2
 
3
3
  class OrgsApi extends Api {
4
4
  constructor(resource) {
5
5
  super(resource);
6
- this.resource = 'orgs';
6
+ this.resource = "orgs";
7
7
  }
8
8
 
9
9
  async stats() {
@@ -16,8 +16,8 @@ class OrgsApi extends Api {
16
16
  return await this.get(url);
17
17
  }
18
18
 
19
- _geStatstUrl = (isPublic) => {
20
- const endpoint = isPublic ? 'pstats' : 'stats';
19
+ _geStatstUrl(isPublic) {
20
+ const endpoint = isPublic ? "pstats" : "stats";
21
21
  return `${this.getUrl()}/${endpoint}${this.getUrlParams()}`;
22
22
  }
23
23
  }