roboto-js 1.5.6 → 1.6.1
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/client_test.js +1 -1
- package/dist/cjs/index.cjs +7 -3
- package/dist/cjs/rbt_api.cjs +390 -351
- package/dist/esm/index.js +7 -3
- package/dist/esm/rbt_api.js +21 -7
- package/package.json +1 -1
- package/src/index.js +7 -2
- package/src/rbt_api.js +27 -7
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
|
-
|
|
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
|
-
|
|
22
|
-
// Use passed
|
|
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
|
}
|
package/dist/esm/rbt_api.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|
20
|
-
//'authtoken': authTokenToUse
|
|
19
|
+
'accesskey': accesskey
|
|
21
20
|
}
|
|
22
21
|
});
|
|
23
22
|
if (localStorageAdaptor) {
|
|
@@ -38,13 +37,25 @@ export default class RbtApi {
|
|
|
38
37
|
|
|
39
38
|
// Use the storageAdaptor to get the authToken, if available
|
|
40
39
|
this.initAuthToken(authtoken);
|
|
40
|
+
this.initApiKey(apikey);
|
|
41
41
|
}
|
|
42
42
|
async initAuthToken(authtoken) {
|
|
43
43
|
if (!authtoken && this.localStorageAdaptor) {
|
|
44
44
|
authtoken = await this.localStorageAdaptor.getItem('authtoken');
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
if (authtoken) {
|
|
47
|
+
this.authtoken = authtoken;
|
|
48
|
+
this.axios.defaults.headers.common['authtoken'] = this.authtoken;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async initApiKey(apikey) {
|
|
52
|
+
if (!apikey && this.localStorageAdaptor) {
|
|
53
|
+
apikey = await this.localStorageAdaptor.getItem('apikey');
|
|
54
|
+
}
|
|
55
|
+
if (apikey) {
|
|
56
|
+
this.apikey = apikey;
|
|
57
|
+
this.axios.defaults.headers.common['apikey'] = this.apikey;
|
|
58
|
+
}
|
|
48
59
|
}
|
|
49
60
|
async initLocalDb() {
|
|
50
61
|
this.localDb = await openDB('RBTFileDatabase', 1, {
|
|
@@ -170,7 +181,10 @@ export default class RbtApi {
|
|
|
170
181
|
if (this.currentUser) {
|
|
171
182
|
return this.currentUser;
|
|
172
183
|
}
|
|
173
|
-
if (this.
|
|
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
package/src/index.js
CHANGED
|
@@ -13,7 +13,7 @@ export {
|
|
|
13
13
|
|
|
14
14
|
export default class Roboto{
|
|
15
15
|
|
|
16
|
-
constructor({ host,
|
|
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
|
-
|
|
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({
|
|
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
|
|
17
|
-
//'authtoken': authTokenToUse
|
|
16
|
+
'accesskey': accesskey
|
|
18
17
|
}
|
|
19
18
|
});
|
|
20
19
|
|
|
@@ -37,7 +36,8 @@ export default class RbtApi {
|
|
|
37
36
|
|
|
38
37
|
// Use the storageAdaptor to get the authToken, if available
|
|
39
38
|
this.initAuthToken(authtoken);
|
|
40
|
-
|
|
39
|
+
this.initApiKey(apikey);
|
|
40
|
+
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
async initAuthToken(authtoken) {
|
|
@@ -46,8 +46,22 @@ export default class RbtApi {
|
|
|
46
46
|
authtoken = await this.localStorageAdaptor.getItem('authtoken');
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
if(authtoken){
|
|
50
|
+
this.authtoken = authtoken;
|
|
51
|
+
this.axios.defaults.headers.common['authtoken'] = this.authtoken;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async initApiKey(apikey) {
|
|
56
|
+
|
|
57
|
+
if(!apikey && this.localStorageAdaptor){
|
|
58
|
+
apikey = await this.localStorageAdaptor.getItem('apikey');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if(apikey){
|
|
62
|
+
this.apikey = apikey;
|
|
63
|
+
this.axios.defaults.headers.common['apikey'] = this.apikey;
|
|
64
|
+
}
|
|
51
65
|
|
|
52
66
|
}
|
|
53
67
|
|
|
@@ -215,7 +229,13 @@ export default class RbtApi {
|
|
|
215
229
|
return this.currentUser;
|
|
216
230
|
}
|
|
217
231
|
|
|
218
|
-
if(this.
|
|
232
|
+
if(this.apikey){
|
|
233
|
+
|
|
234
|
+
// NOT IMPLEMENTED
|
|
235
|
+
return null;
|
|
236
|
+
|
|
237
|
+
}
|
|
238
|
+
else if(this.authtoken){
|
|
219
239
|
|
|
220
240
|
let response = await this.refreshAuthToken(this.authtoken);
|
|
221
241
|
if(!response) return null;
|