roboto-js 1.5.6 → 1.6.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/dist/esm/index.js CHANGED
@@ -8,7 +8,7 @@ export { RbtApi, RbtObject, RbtFile
8
8
  export default class Roboto {
9
9
  constructor({
10
10
  host,
11
- apiKey,
11
+ accessKey,
12
12
  localStorageAdaptor
13
13
  }, proxyReq = null) {
14
14
  if (Roboto.instance && !proxyReq) {
@@ -18,8 +18,8 @@ export default class Roboto {
18
18
  }
19
19
  const isBrowser = typeof window !== "undefined";
20
20
  this.config = {
21
- apiKey: apiKey,
22
- // Use passed apiKey
21
+ accessKey: accessKey,
22
+ // Use passed accessKey
23
23
  baseUrl: `https://${host}`,
24
24
  // Use passed host
25
25
  localStorageAdaptor: localStorageAdaptor
@@ -32,10 +32,14 @@ export default class Roboto {
32
32
  if (proxyReq && proxyReq.headers) {
33
33
  const authtoken = proxyReq.headers.authtoken;
34
34
  const accesskey = proxyReq.headers.accesskey;
35
+ const apikey = proxyReq.headers.apikey;
35
36
  // Optionally add more headers as needed
36
37
  if (authtoken) {
37
38
  this.config.authtoken = authtoken; // Set the authtoken in the config
38
39
  }
40
+ if (apikey) {
41
+ this.config.apikey = apikey; // Set the authtoken in the config
42
+ }
39
43
  if (accesskey) {
40
44
  this.config.accesskey = accesskey; // Set the accesskey in the config
41
45
  }
@@ -7,17 +7,16 @@ import _ from 'lodash';
7
7
  import { openDB } from 'idb';
8
8
  export default class RbtApi {
9
9
  constructor({
10
- apiKey,
11
10
  baseUrl,
11
+ accesskey,
12
12
  authtoken = null,
13
- accesskey = null,
13
+ apikey = null,
14
14
  localStorageAdaptor = null
15
15
  }) {
16
16
  this.axios = axios.create({
17
17
  baseURL: baseUrl,
18
18
  headers: {
19
- 'accesskey': accesskey || apiKey
20
- //'authtoken': authTokenToUse
19
+ 'accesskey': accesskey
21
20
  }
22
21
  });
23
22
  if (localStorageAdaptor) {
@@ -37,7 +36,12 @@ export default class RbtApi {
37
36
  this.requestCache = {};
38
37
 
39
38
  // Use the storageAdaptor to get the authToken, if available
40
- this.initAuthToken(authtoken);
39
+ if (authtoken) {
40
+ this.initAuthToken(authtoken);
41
+ }
42
+ if (apikey) {
43
+ this.initApiKey(apikey);
44
+ }
41
45
  }
42
46
  async initAuthToken(authtoken) {
43
47
  if (!authtoken && this.localStorageAdaptor) {
@@ -46,6 +50,13 @@ export default class RbtApi {
46
50
  this.authtoken = authtoken;
47
51
  this.axios.defaults.headers.common['authtoken'] = this.authtoken;
48
52
  }
53
+ async initApiKey(apikey) {
54
+ if (!apikey && this.localStorageAdaptor) {
55
+ apikey = await this.localStorageAdaptor.getItem('apikey');
56
+ }
57
+ this.apikey = apikey;
58
+ this.axios.defaults.headers.common['apikey'] = this.apikey;
59
+ }
49
60
  async initLocalDb() {
50
61
  this.localDb = await openDB('RBTFileDatabase', 1, {
51
62
  upgrade(db) {
@@ -170,7 +181,10 @@ export default class RbtApi {
170
181
  if (this.currentUser) {
171
182
  return this.currentUser;
172
183
  }
173
- if (this.authtoken) {
184
+ if (this.apikey) {
185
+ // NOT IMPLEMENTED
186
+ return null;
187
+ } else if (this.authtoken) {
174
188
  let response = await this.refreshAuthToken(this.authtoken);
175
189
  if (!response) return null;
176
190
  if (response?.user) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roboto-js",
3
- "version": "1.5.6",
3
+ "version": "1.6.0",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "main": "dist/cjs/index.cjs",
package/src/index.js CHANGED
@@ -13,7 +13,7 @@ export {
13
13
 
14
14
  export default class Roboto{
15
15
 
16
- constructor({ host, apiKey, localStorageAdaptor }, proxyReq = null) {
16
+ constructor({ host, accessKey, localStorageAdaptor }, proxyReq = null) {
17
17
 
18
18
  if (Roboto.instance && !proxyReq) {
19
19
  // if on client, there can only be one instance
@@ -24,7 +24,7 @@ export default class Roboto{
24
24
  const isBrowser = typeof window !== "undefined";
25
25
 
26
26
  this.config = {
27
- apiKey: apiKey, // Use passed apiKey
27
+ accessKey: accessKey, // Use passed accessKey
28
28
  baseUrl: `https://${host}`, // Use passed host
29
29
  localStorageAdaptor: localStorageAdaptor
30
30
  };
@@ -36,13 +36,18 @@ export default class Roboto{
36
36
  if (proxyReq && proxyReq.headers) {
37
37
  const authtoken = proxyReq.headers.authtoken;
38
38
  const accesskey = proxyReq.headers.accesskey;
39
+ const apikey = proxyReq.headers.apikey;
39
40
  // Optionally add more headers as needed
40
41
  if (authtoken) {
41
42
  this.config.authtoken = authtoken; // Set the authtoken in the config
42
43
  }
44
+ if (apikey) {
45
+ this.config.apikey = apikey; // Set the authtoken in the config
46
+ }
43
47
  if (accesskey) {
44
48
  this.config.accesskey = accesskey; // Set the accesskey in the config
45
49
  }
50
+
46
51
  }
47
52
 
48
53
  this.api = new RbtApi(this.config);
package/src/rbt_api.js CHANGED
@@ -8,13 +8,12 @@ import { openDB } from 'idb';
8
8
 
9
9
  export default class RbtApi {
10
10
 
11
- constructor({ apiKey, baseUrl, authtoken=null, accesskey=null, localStorageAdaptor=null }) {
11
+ constructor({ baseUrl, accesskey, authtoken=null, apikey=null, localStorageAdaptor=null }) {
12
12
 
13
13
  this.axios = axios.create({
14
14
  baseURL: baseUrl,
15
15
  headers: {
16
- 'accesskey': accesskey || apiKey,
17
- //'authtoken': authTokenToUse
16
+ 'accesskey': accesskey
18
17
  }
19
18
  });
20
19
 
@@ -36,7 +35,12 @@ export default class RbtApi {
36
35
  this.requestCache = {};
37
36
 
38
37
  // Use the storageAdaptor to get the authToken, if available
39
- this.initAuthToken(authtoken);
38
+ if(authtoken){
39
+ this.initAuthToken(authtoken);
40
+ }
41
+ if(apikey){
42
+ this.initApiKey(apikey);
43
+ }
40
44
 
41
45
  }
42
46
 
@@ -51,6 +55,17 @@ export default class RbtApi {
51
55
 
52
56
  }
53
57
 
58
+ async initApiKey(apikey) {
59
+
60
+ if(!apikey && this.localStorageAdaptor){
61
+ apikey = await this.localStorageAdaptor.getItem('apikey');
62
+ }
63
+
64
+ this.apikey = apikey;
65
+ this.axios.defaults.headers.common['apikey'] = this.apikey;
66
+
67
+ }
68
+
54
69
  async initLocalDb(){
55
70
 
56
71
  this.localDb = await openDB('RBTFileDatabase', 1, {
@@ -215,7 +230,13 @@ export default class RbtApi {
215
230
  return this.currentUser;
216
231
  }
217
232
 
218
- if(this.authtoken){
233
+ if(this.apikey){
234
+
235
+ // NOT IMPLEMENTED
236
+ return null;
237
+
238
+ }
239
+ else if(this.authtoken){
219
240
 
220
241
  let response = await this.refreshAuthToken(this.authtoken);
221
242
  if(!response) return null;