roboto-js 1.1.1 → 1.1.3
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/cjs/index.cjs +86 -67
- package/dist/cjs/rbt_api.cjs +215 -167
- package/dist/cjs/rbt_object.cjs +20 -2
- package/dist/esm/index.js +86 -67
- package/dist/esm/rbt_api.js +215 -167
- package/dist/esm/rbt_object.js +20 -2
- package/package.json +1 -1
- package/src/index.js +3 -0
- package/src/rbt_api.js +32 -2
- package/src/rbt_object.js +20 -3
package/dist/esm/rbt_object.js
CHANGED
|
@@ -31,9 +31,9 @@ var RbtObject = exports["default"] = /*#__PURE__*/function () {
|
|
|
31
31
|
isNew: options.isNew || false
|
|
32
32
|
};
|
|
33
33
|
if (record.data) {
|
|
34
|
-
this._data = record.data;
|
|
34
|
+
this._data = this._deepUnpackJson(record.data);
|
|
35
35
|
} else {
|
|
36
|
-
this._data = record.dataJson ?
|
|
36
|
+
this._data = record.dataJson ? this._deepUnpackJson(record.dataJson) : {};
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
_createClass(RbtObject, [{
|
|
@@ -195,6 +195,24 @@ var RbtObject = exports["default"] = /*#__PURE__*/function () {
|
|
|
195
195
|
}
|
|
196
196
|
return _delete;
|
|
197
197
|
}()
|
|
198
|
+
}, {
|
|
199
|
+
key: "_deepUnpackJson",
|
|
200
|
+
value: function _deepUnpackJson(value) {
|
|
201
|
+
if (typeof value === 'string') {
|
|
202
|
+
try {
|
|
203
|
+
var parsed = JSON.parse(value);
|
|
204
|
+
return this._deepUnpackJson(parsed); // Recursively parse if the result is a string, object, or array
|
|
205
|
+
} catch (e) {
|
|
206
|
+
return value; // Return the original string if parsing fails
|
|
207
|
+
}
|
|
208
|
+
} else if (value !== null && _typeof(value) === 'object') {
|
|
209
|
+
// If it's an object (including arrays), recursively parse each value
|
|
210
|
+
for (var key in value) {
|
|
211
|
+
value[key] = this._deepUnpackJson(value[key]);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return value;
|
|
215
|
+
}
|
|
198
216
|
}]);
|
|
199
217
|
return RbtObject;
|
|
200
218
|
}();
|
package/package.json
CHANGED
package/src/index.js
CHANGED
package/src/rbt_api.js
CHANGED
|
@@ -2,7 +2,7 @@ import axios from 'axios';
|
|
|
2
2
|
import CryptoJS from 'crypto-js';
|
|
3
3
|
import RbtObject from './rbt_object.js';
|
|
4
4
|
import RbtUser from './rbt_user.js';
|
|
5
|
-
import RbtFile from './rbt_file.js';
|
|
5
|
+
import RbtFile from './rbt_file.js';
|
|
6
6
|
import _ from 'lodash';
|
|
7
7
|
import { openDB } from 'idb';
|
|
8
8
|
|
|
@@ -76,6 +76,34 @@ export default class RbtApi {
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
async logout() {
|
|
80
|
+
try {
|
|
81
|
+
// Call logout endpoint if necessary. Here, I assume there's a '/user_service/logoutUser' endpoint.
|
|
82
|
+
// This is optional and depends on how your backend is set up.
|
|
83
|
+
const response = await this.axios.post('/user_service/logoutUser');
|
|
84
|
+
|
|
85
|
+
if (response.data.ok === false) {
|
|
86
|
+
return this._handleError(response);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Clear the iac_session and remove the auth token from axios headers
|
|
90
|
+
this.iac_session = null;
|
|
91
|
+
if (this.axios.defaults.headers.common['authtoken']) {
|
|
92
|
+
delete this.axios.defaults.headers.common['authtoken'];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Clear localStorage if it's being used
|
|
96
|
+
if (typeof localStorage !== 'undefined') {
|
|
97
|
+
localStorage.removeItem('authtoken');
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Return some kind of success response or the response from the server
|
|
101
|
+
return response.data;
|
|
102
|
+
} catch (e) {
|
|
103
|
+
this._handleError(e);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
79
107
|
async loadCurrentUser(){
|
|
80
108
|
|
|
81
109
|
// TODO - get the actual user from the session
|
|
@@ -131,8 +159,9 @@ export default class RbtApi {
|
|
|
131
159
|
if(dataHash){
|
|
132
160
|
record.data = dataHash;
|
|
133
161
|
}
|
|
134
|
-
return new
|
|
162
|
+
return new RbtUser(record, this.axios);
|
|
135
163
|
} catch (e) {
|
|
164
|
+
debugger;
|
|
136
165
|
return this._handleError(e);
|
|
137
166
|
}
|
|
138
167
|
}
|
|
@@ -458,6 +487,7 @@ export default class RbtApi {
|
|
|
458
487
|
if (_.isObject(err) && _.get(err, 'response')) {
|
|
459
488
|
const msg = _.get(err, 'response.data.message', 'Error in API response');
|
|
460
489
|
throw new Error(msg);
|
|
490
|
+
|
|
461
491
|
} else {
|
|
462
492
|
throw new Error(err.message || 'Unknown error');
|
|
463
493
|
}
|
package/src/rbt_object.js
CHANGED
|
@@ -11,11 +11,11 @@ export default class RbtObject {
|
|
|
11
11
|
changes: [],
|
|
12
12
|
isNew: options.isNew || false
|
|
13
13
|
};
|
|
14
|
-
|
|
14
|
+
|
|
15
15
|
if(record.data){
|
|
16
|
-
this._data = record.data;
|
|
16
|
+
this._data = this._deepUnpackJson(record.data);
|
|
17
17
|
} else {
|
|
18
|
-
this._data = record.dataJson ?
|
|
18
|
+
this._data = record.dataJson ? this._deepUnpackJson(record.dataJson) : {};
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
}
|
|
@@ -133,4 +133,21 @@ export default class RbtObject {
|
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
+
_deepUnpackJson(value){
|
|
137
|
+
if (typeof value === 'string') {
|
|
138
|
+
try {
|
|
139
|
+
const parsed = JSON.parse(value);
|
|
140
|
+
return this._deepUnpackJson(parsed); // Recursively parse if the result is a string, object, or array
|
|
141
|
+
} catch (e) {
|
|
142
|
+
return value; // Return the original string if parsing fails
|
|
143
|
+
}
|
|
144
|
+
} else if (value !== null && typeof value === 'object') {
|
|
145
|
+
// If it's an object (including arrays), recursively parse each value
|
|
146
|
+
for (const key in value) {
|
|
147
|
+
value[key] = this._deepUnpackJson(value[key]);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return value;
|
|
151
|
+
}
|
|
152
|
+
|
|
136
153
|
}
|