roboto-js 1.1.1 → 1.1.2
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 +221 -168
- package/dist/cjs/rbt_object.cjs +20 -2
- package/dist/esm/index.js +86 -67
- package/dist/esm/rbt_api.js +221 -168
- package/dist/esm/rbt_object.js +20 -2
- package/package.json +1 -1
- package/src/index.js +3 -0
- package/src/rbt_api.js +37 -1
- 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
|
@@ -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
|
|
@@ -133,6 +161,7 @@ export default class RbtApi {
|
|
|
133
161
|
}
|
|
134
162
|
return new RbtObject(record, this.axios);
|
|
135
163
|
} catch (e) {
|
|
164
|
+
debugger;
|
|
136
165
|
return this._handleError(e);
|
|
137
166
|
}
|
|
138
167
|
}
|
|
@@ -449,6 +478,7 @@ export default class RbtApi {
|
|
|
449
478
|
|
|
450
479
|
_handleError(err) {
|
|
451
480
|
|
|
481
|
+
debugger;
|
|
452
482
|
// Invoke the custom error handler if provided
|
|
453
483
|
if (this.customErrorHandler) {
|
|
454
484
|
let res = this.customErrorHandler(err);
|
|
@@ -457,7 +487,13 @@ export default class RbtApi {
|
|
|
457
487
|
|
|
458
488
|
if (_.isObject(err) && _.get(err, 'response')) {
|
|
459
489
|
const msg = _.get(err, 'response.data.message', 'Error in API response');
|
|
460
|
-
|
|
490
|
+
|
|
491
|
+
if(msg.key){
|
|
492
|
+
throw new Error(msg.key);
|
|
493
|
+
}
|
|
494
|
+
else{
|
|
495
|
+
throw new Error(msg);
|
|
496
|
+
}
|
|
461
497
|
} else {
|
|
462
498
|
throw new Error(err.message || 'Unknown error');
|
|
463
499
|
}
|
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
|
}
|