@veritree/services 2.18.1-3 → 2.18.1-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/index.js CHANGED
@@ -10,6 +10,7 @@ import { Images } from './src/endpoints/images';
10
10
  import { Orgs } from './src/endpoints/orgs';
11
11
  import { Notes } from './src/endpoints/notes';
12
12
  import { Regions } from './src/endpoints/regions';
13
+ import { Resellers } from './src/endpoints/resellers';
13
14
  import { SDGs } from './src/endpoints/sdgs';
14
15
  import { Sponsors } from './src/endpoints/sponsors';
15
16
  import { Standards } from './src/endpoints/standards';
@@ -26,7 +27,7 @@ import { FieldReports } from './src/endpoints/field-reports';
26
27
  import { ExternalReports } from './src/endpoints/external-reports';
27
28
  import { Evidence } from './src/endpoints/evidence';
28
29
  import { Crumbs } from './src/endpoints/crumbs';
29
- import { Verifications } from './src/endpoints/verifications';
30
+ import { Verifications } from './src/endpoints/verifications';
30
31
  import { ImagesAggregated } from './src/endpoints/images-aggregated';
31
32
  import { ssoToken } from './src/endpoints/sso-token';
32
33
 
@@ -43,6 +44,7 @@ export {
43
44
  Orgs,
44
45
  Notes,
45
46
  Regions,
47
+ Resellers,
46
48
  SDGs,
47
49
  Sponsors,
48
50
  Standards,
@@ -61,5 +63,5 @@ export {
61
63
  Crumbs,
62
64
  Verifications,
63
65
  ImagesAggregated,
64
- ssoToken
66
+ ssoToken,
65
67
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veritree/services",
3
- "version": "2.18.1-3",
3
+ "version": "2.18.1-5",
4
4
  "description": "A collection of javascript functions/services to talk to veritree API",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -0,0 +1,37 @@
1
+ import Api from '../helpers/api';
2
+
3
+ class ResellersApi extends Api {
4
+ constructor(resource) {
5
+ super(resource);
6
+ this.resource = 'resellers';
7
+ }
8
+
9
+ statsSold() {
10
+ const all = async () => {
11
+ const url = `${this.getUrl()}/1/pstats/sold?pretty=1`;
12
+ let response;
13
+ try {
14
+ response = await this.get(url);
15
+ } catch (e) {
16
+ console.log('error ', e);
17
+ }
18
+ return response;
19
+ };
20
+
21
+ return {
22
+ all,
23
+ };
24
+ }
25
+
26
+ statsPurchased() {
27
+ const all = async () => {
28
+ const url = `${this.getUrl()}/1/pstats/purchased?pretty=1`;
29
+ };
30
+
31
+ return {
32
+ all,
33
+ };
34
+ }
35
+ }
36
+
37
+ export const Resellers = new ResellersApi();
@@ -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
  * Adds the envelope argument to the url
@@ -9,10 +9,15 @@ import { getSession } from './session';
9
9
  * @returns {string} url
10
10
  */
11
11
  function addVersionArg(url) {
12
- if (!url || url.includes('_result=1')) return url;
13
-
14
- const version = process.env ? process.env.API_VERITREE_VERSION ? process.env.API_VERITREE_VERSION : '5.0.0' : '5.0.0' || '5.0.0';
15
- const urlHasArgs = url.includes('?');
12
+ if (!url || url.includes("_result=1")) return url;
13
+
14
+ const version =
15
+ process && process.env
16
+ ? process.env.API_VERITREE_VERSION
17
+ ? process.env.API_VERITREE_VERSION
18
+ : "5.0.0"
19
+ : "5.0.0" || "5.0.0";
20
+ const urlHasArgs = url.includes("?");
16
21
  const urlVersionArg = urlHasArgs ? `&_v=${version}` : `?_v=${version}`;
17
22
 
18
23
  return `${url}${urlVersionArg}`;
@@ -26,10 +31,10 @@ function addVersionArg(url) {
26
31
  * @returns {object} data
27
32
  */
28
33
  function getConfig(method, data, as) {
29
- const isGet = method === 'get';
34
+ const isGet = method === "get";
30
35
  const isSpoofing = as;
31
36
  const isFormData = data instanceof FormData;
32
- const accessToken = `Bearer ${getCookie('access_token')}`;
37
+ const accessToken = `Bearer ${getCookie("access_token")}`;
33
38
 
34
39
  const config = {
35
40
  method,
@@ -39,7 +44,7 @@ function getConfig(method, data, as) {
39
44
  };
40
45
 
41
46
  if (!isFormData) {
42
- config.headers['Content-Type'] = 'application/json';
47
+ config.headers["Content-Type"] = "application/json";
43
48
  }
44
49
 
45
50
  // TODO: improve this ifs and elses
@@ -47,7 +52,7 @@ function getConfig(method, data, as) {
47
52
  if (!data) data = {};
48
53
 
49
54
  if (isFormData) {
50
- if (isSpoofing) data.set('_method', as.toUpperCase());
55
+ if (isSpoofing) data.set("_method", as.toUpperCase());
51
56
  config.body = data;
52
57
  } else {
53
58
  if (isSpoofing) data._method = as.toUpperCase();
@@ -60,8 +65,13 @@ function getConfig(method, data, as) {
60
65
 
61
66
  export default class Api {
62
67
  constructor(resource) {
63
- this.baseUrl = process.env ? `${process.env.API_VERITREE_URL}/api` : null;
64
- this.resource = resource ? resource : '';
68
+ this.baseUrl =
69
+ process && process.env
70
+ ? process.env.API_VERITREE_URL
71
+ ? `${process.env.API_VERITREE_URL}/api`
72
+ : null
73
+ : null;
74
+ this.resource = resource ? resource : "";
65
75
  this.orgId = null;
66
76
  this.orgType = null;
67
77
  }
@@ -106,7 +116,7 @@ export default class Api {
106
116
  * @param {string} as - 'put' // necessary for updates because of how Laravel handles PUT requests
107
117
  * @returns {promise}
108
118
  */
109
- async update(id, data, as = 'put', args) {
119
+ async update(id, data, as = "put", args) {
110
120
  const url = `${this.getUrl(id)}${this.getUrlParams(args)}`;
111
121
  return await this.post(url, data, as);
112
122
  }
@@ -120,7 +130,7 @@ export default class Api {
120
130
  */
121
131
  async delete(id, args) {
122
132
  const url = `${this.getUrl(id)}${this.getUrlParams(args)}`;
123
- return await this.post(url, null, 'delete');
133
+ return await this.post(url, null, "delete");
124
134
  }
125
135
 
126
136
  /**
@@ -140,7 +150,7 @@ export default class Api {
140
150
  */
141
151
  async post(url, data, as, args) {
142
152
  if (!url) url = `${this.getUrl()}${this.getUrlParams(args)}`;
143
- return await this.unWrap(url, 'post', data, as);
153
+ return await this.unWrap(url, "post", data, as);
144
154
  }
145
155
 
146
156
  // ----------
@@ -151,7 +161,7 @@ export default class Api {
151
161
  * @returns
152
162
  */
153
163
  getUrl(id) {
154
- id = id ? `/${id}` : '';
164
+ id = id ? `/${id}` : "";
155
165
  return `${this.baseUrl}/${this.resource}${id}`;
156
166
  }
157
167
 
@@ -164,14 +174,14 @@ export default class Api {
164
174
  this.setOrg();
165
175
  let isOrgLess = false;
166
176
  let isOrgAs = false;
167
- let orgIdParam = '';
168
- let orgTypeParam = '';
177
+ let orgIdParam = "";
178
+ let orgTypeParam = "";
169
179
 
170
180
  // while most of endpoints require an org id and type, some endpoints do not
171
181
  if (args) {
172
- isOrgLess = Object.hasOwn(args, 'orgless');
182
+ isOrgLess = Object.hasOwn(args, "orgless");
173
183
  isOrgAs =
174
- Object.hasOwn(args, 'org_id_as') && Object.hasOwn(args, 'org_type_as');
184
+ Object.hasOwn(args, "org_id_as") && Object.hasOwn(args, "org_type_as");
175
185
  }
176
186
 
177
187
  // a super admin user can create/edit data from other orgs
@@ -201,7 +211,7 @@ export default class Api {
201
211
  * @param {object} data
202
212
  * @returns {object} envelope
203
213
  */
204
- async unWrap(url, method = 'get', data, as) {
214
+ async unWrap(url, method = "get", data, as) {
205
215
  url = addVersionArg(url);
206
216
  const config = getConfig(method, data, as);
207
217
  const response = await fetch(url, config);