@veritree/services 2.34.0-0 → 2.35.0-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 +12 -5
  2. package/src/helpers/api.js +12 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veritree/services",
3
- "version": "2.34.0-0",
3
+ "version": "2.35.0-0",
4
4
  "description": "A collection of javascript functions/services to talk to veritree API",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -8,10 +8,17 @@
8
8
  "author": "cyroveritree <cyro@veritree.com>",
9
9
  "license": "MIT",
10
10
  "publishConfig": {
11
- "access": "public"
11
+ "registry": "https://registry.npmjs.org"
12
12
  },
13
- "dependencies": {
14
- "np": "^7.6.2"
13
+ "scripts": {
14
+ "release": "np --no-tests --no-2fa --branch=next"
15
15
  },
16
- "devDependencies": {}
16
+ "devDependencies": {
17
+ "np": "^8.0.4",
18
+ "prettier": "^2.7.1"
19
+ },
20
+ "engines": {
21
+ "npm": ">=8.0.0",
22
+ "node": ">=18.0.0"
23
+ }
17
24
  }
@@ -23,11 +23,11 @@ function addVersionParam(url) {
23
23
  return `${url}${urlVersionParam}`;
24
24
  }
25
25
 
26
- function getConfig(method, data, as) {
26
+ function getConfig(method, data, as, $api) {
27
27
  const isGet = method === 'get';
28
28
  const isSpoofing = as;
29
29
  const isFormData = data instanceof FormData;
30
- const accessToken = `Bearer ${getCookie('access_token')}`;
30
+ const accessToken = $api.getAccessToken();
31
31
 
32
32
  const config = {
33
33
  method,
@@ -58,6 +58,7 @@ function getConfig(method, data, as) {
58
58
 
59
59
  export default class Api {
60
60
  constructor(resource) {
61
+ this.accessToken = null;
61
62
  this.baseUrl = null;
62
63
  this.resource = resource ? resource : '';
63
64
  this.orgId = null;
@@ -68,6 +69,14 @@ export default class Api {
68
69
  this.baseUrl = baseUrl;
69
70
  }
70
71
 
72
+ setAccessToken(accessToken) {
73
+ this.accessToken = accessToken;
74
+ }
75
+
76
+ getAccessToken() {
77
+ return `Bearer ${this.accessToken || getCookie("access_token")}`;
78
+ }
79
+
71
80
  async all(args) {
72
81
  const url = `${this.getUrl()}${this.getUrlParams(args)}`;
73
82
  return await this.get(url);
@@ -158,7 +167,7 @@ export default class Api {
158
167
 
159
168
  async unWrap(url, method = 'get', data, as) {
160
169
  url = addVersionParam(url);
161
- const config = getConfig(method, data, as);
170
+ const config = getConfig(method, data, as, this);
162
171
  const response = await fetch(url, config);
163
172
 
164
173
  return new Promise((resolve, reject) => {