@veritree/services 2.69.1 → 2.71.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/package.json +1 -1
- package/src/endpoints/resellers.js +25 -3
- package/src/helpers/api.js +23 -23
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import Api from
|
|
1
|
+
import Api from '../helpers/api';
|
|
2
2
|
|
|
3
3
|
class ResellersApi extends Api {
|
|
4
4
|
constructor(resource) {
|
|
5
5
|
super(resource);
|
|
6
|
-
this.resource =
|
|
6
|
+
this.resource = 'resellers';
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
statsSold() {
|
|
@@ -13,7 +13,7 @@ class ResellersApi extends Api {
|
|
|
13
13
|
try {
|
|
14
14
|
response = await this.get(url);
|
|
15
15
|
} catch (e) {
|
|
16
|
-
console.log(
|
|
16
|
+
console.log('error ', e);
|
|
17
17
|
}
|
|
18
18
|
return response;
|
|
19
19
|
};
|
|
@@ -89,6 +89,28 @@ class ResellersApi extends Api {
|
|
|
89
89
|
all,
|
|
90
90
|
};
|
|
91
91
|
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Fetches all planting parter organizations for the specified reseller.
|
|
95
|
+
*
|
|
96
|
+
* @param {string} resellerId - The unique identifier of the reseller.
|
|
97
|
+
* @param {Object} params - Additional parameters for customizing the request.
|
|
98
|
+
* @returns {Promise} A promise that resolves to the organizations data.
|
|
99
|
+
* @memberof Resellers
|
|
100
|
+
*/
|
|
101
|
+
organizations(resellerId) {
|
|
102
|
+
const all = async (params) => {
|
|
103
|
+
const url = `${this.getUrl()}/${resellerId}/organizations${this.getUrlParams(
|
|
104
|
+
params
|
|
105
|
+
)}`;
|
|
106
|
+
|
|
107
|
+
return await this.get(url);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
all,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
92
114
|
}
|
|
93
115
|
|
|
94
116
|
export const Resellers = new ResellersApi();
|
package/src/helpers/api.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { getCookie } from
|
|
2
|
-
import { createParamsStringFromArgs } from
|
|
3
|
-
import { getSession } from
|
|
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(
|
|
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(
|
|
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 =
|
|
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 ===
|
|
74
|
+
const isGet = method === 'get';
|
|
75
75
|
const isSpoofing = as;
|
|
76
76
|
const isFormData = data instanceof FormData;
|
|
77
|
-
const accessToken = `Bearer ${getCookie(
|
|
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[
|
|
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(
|
|
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 =
|
|
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,
|
|
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,
|
|
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,
|
|
229
|
-
isOrgIdAs = Object.hasOwn(argsClone,
|
|
230
|
-
isOrgTypeAs = Object.hasOwn(argsClone,
|
|
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 =
|
|
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(
|
|
291
|
+
throw new Error('This response header content-type is not handled.');
|
|
292
292
|
}
|
|
293
293
|
});
|
|
294
294
|
}
|