roboto-js 1.4.15 → 1.4.17

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.
@@ -138,55 +138,57 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
138
138
  * @param {Object} params - The login parameters.
139
139
  * @param {string} params.email - The email of the user.
140
140
  * @param {string} params.password - The password of the user.
141
+ * @param {string} params.code - The password of the user.
141
142
  * @returns {Promise<Object>} - The response data from the API.
142
143
  */
143
144
  }, {
144
145
  key: "login",
145
146
  value: (function () {
146
147
  var _login = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params) {
147
- var hash_password, response;
148
+ var response;
148
149
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
149
150
  while (1) switch (_context3.prev = _context3.next) {
150
151
  case 0:
151
152
  _context3.prev = 0;
152
- // create a md5 hash of the password using crypto-js
153
- hash_password = _cryptoJs["default"].MD5(params.password).toString(_cryptoJs["default"].enc.Hex);
154
- _context3.next = 4;
153
+ _context3.next = 3;
155
154
  return this.axios.post('/user_service/loginUser', [{
156
155
  email: params.email,
157
- password: hash_password,
158
- passwd: params.password
156
+ password: params.password ? _cryptoJs["default"].MD5(params.password).toString(_cryptoJs["default"].enc.Hex) : null,
157
+ // legacy hash password (md5)
158
+ passwd: params.password || null,
159
+ // current password
160
+ code: params.code || null // single-use signon code (password resets)
159
161
  }]);
160
- case 4:
162
+ case 3:
161
163
  response = _context3.sent;
162
164
  if (!(response.data.ok === false)) {
163
- _context3.next = 7;
165
+ _context3.next = 6;
164
166
  break;
165
167
  }
166
168
  return _context3.abrupt("return", this._handleError(response));
167
- case 7:
169
+ case 6:
168
170
  this.iac_session = response.data;
169
171
  this.currentUser = this.iac_session ? new _rbt_user["default"](this.iac_session.user, this.axios) : null;
170
172
  // update axios instance headers with authtoken
171
173
  this.axios.defaults.headers.common['authtoken'] = response.data.authToken;
172
174
  this.authtoken = response.data.authToken;
173
175
  if (!this.localStorageAdaptor) {
174
- _context3.next = 14;
176
+ _context3.next = 13;
175
177
  break;
176
178
  }
177
- _context3.next = 14;
179
+ _context3.next = 13;
178
180
  return this.localStorageAdaptor.setItem('authtoken', response.data.authToken);
179
- case 14:
181
+ case 13:
180
182
  return _context3.abrupt("return", response.data);
181
- case 17:
182
- _context3.prev = 17;
183
+ case 16:
184
+ _context3.prev = 16;
183
185
  _context3.t0 = _context3["catch"](0);
184
186
  this._handleError(_context3.t0);
185
- case 20:
187
+ case 19:
186
188
  case "end":
187
189
  return _context3.stop();
188
190
  }
189
- }, _callee3, this, [[0, 17]]);
191
+ }, _callee3, this, [[0, 16]]);
190
192
  }));
191
193
  function login(_x2) {
192
194
  return _login.apply(this, arguments);
@@ -45,7 +45,25 @@ var RbtObject = exports["default"] = /*#__PURE__*/function () {
45
45
  }, {
46
46
  key: "getData",
47
47
  value: function getData() {
48
- return _objectSpread({}, this._data);
48
+ var _this = this;
49
+ var keys = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
50
+ // Check if keys are provided
51
+ if (keys && Array.isArray(keys)) {
52
+ // Return an object with only the specified keys
53
+ return keys.reduce(function (result, key) {
54
+ // Use lodash.get to handle deep key paths
55
+ var value = _lodash["default"].get(_this._data, key);
56
+ // If the value exists, add it to the result object using the key path as the property name
57
+ if (value !== undefined) {
58
+ // Create nested structure based on the key path
59
+ _lodash["default"].set(result, key, value);
60
+ }
61
+ return result;
62
+ }, {});
63
+ } else {
64
+ // Return a shallow copy of the full data if no keys are provided
65
+ return _objectSpread({}, this._data);
66
+ }
49
67
  }
50
68
  }, {
51
69
  key: "_addChange",
@@ -80,14 +98,14 @@ var RbtObject = exports["default"] = /*#__PURE__*/function () {
80
98
  }, {
81
99
  key: "setData",
82
100
  value: function setData(newData) {
83
- var _this = this;
101
+ var _this2 = this;
84
102
  if (_typeof(newData) !== 'object' || newData === null) {
85
103
  throw new Error('setData expects an object');
86
104
  }
87
105
  Object.keys(newData).forEach(function (key) {
88
- if (!_lodash["default"].isEqual(_lodash["default"].get(_this._data, key), newData[key])) {
89
- _lodash["default"].set(_this._data, key, newData[key]);
90
- _this._addChange(key);
106
+ if (!_lodash["default"].isEqual(_lodash["default"].get(_this2._data, key), newData[key])) {
107
+ _lodash["default"].set(_this2._data, key, newData[key]);
108
+ _this2._addChange(key);
91
109
  }
92
110
  });
93
111
  }
@@ -142,11 +160,12 @@ var RbtObject = exports["default"] = /*#__PURE__*/function () {
142
160
  throw new Error(response.data.message);
143
161
  case 9:
144
162
  if (!(((_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.result) == 'NO_CHANGES')) {
145
- _context.next = 11;
163
+ _context.next = 12;
146
164
  break;
147
165
  }
166
+ this.rpcMeta.isNew = false;
148
167
  return _context.abrupt("return", this);
149
- case 11:
168
+ case 12:
150
169
  if ((_response$data2 = response.data) !== null && _response$data2 !== void 0 && _response$data2.newData) {
151
170
  // apply new incoming data
152
171
  this.setData(response.newData);
@@ -156,18 +175,18 @@ var RbtObject = exports["default"] = /*#__PURE__*/function () {
156
175
  this.type = response.data.type;
157
176
  this.rpcMeta.isNew = false;
158
177
  return _context.abrupt("return", this);
159
- case 19:
160
- _context.prev = 19;
178
+ case 20:
179
+ _context.prev = 20;
161
180
  _context.t0 = _context["catch"](2);
162
181
  console.log('RbtObject.save.error:', _context.t0);
163
182
  this._error = _context.t0;
164
183
  //console.log(e.response.data);
165
184
  throw _context.t0;
166
- case 24:
185
+ case 25:
167
186
  case "end":
168
187
  return _context.stop();
169
188
  }
170
- }, _callee, this, [[2, 19]]);
189
+ }, _callee, this, [[2, 20]]);
171
190
  }));
172
191
  function save() {
173
192
  return _save.apply(this, arguments);
@@ -67,16 +67,18 @@ export default class RbtApi {
67
67
  * @param {Object} params - The login parameters.
68
68
  * @param {string} params.email - The email of the user.
69
69
  * @param {string} params.password - The password of the user.
70
+ * @param {string} params.code - The password of the user.
70
71
  * @returns {Promise<Object>} - The response data from the API.
71
72
  */
72
73
  async login(params) {
73
74
  try {
74
- // create a md5 hash of the password using crypto-js
75
- const hash_password = CryptoJS.MD5(params.password).toString(CryptoJS.enc.Hex);
76
75
  const response = await this.axios.post('/user_service/loginUser', [{
77
76
  email: params.email,
78
- password: hash_password,
79
- passwd: params.password
77
+ password: params.password ? CryptoJS.MD5(params.password).toString(CryptoJS.enc.Hex) : null,
78
+ // legacy hash password (md5)
79
+ passwd: params.password || null,
80
+ // current password
81
+ code: params.code || null // single-use signon code (password resets)
80
82
  }]);
81
83
  if (response.data.ok === false) {
82
84
  return this._handleError(response);
@@ -19,10 +19,26 @@ export default class RbtObject {
19
19
  get(path) {
20
20
  return _.get(this._data, path);
21
21
  }
22
- getData() {
23
- return {
24
- ...this._data
25
- };
22
+ getData(keys = null) {
23
+ // Check if keys are provided
24
+ if (keys && Array.isArray(keys)) {
25
+ // Return an object with only the specified keys
26
+ return keys.reduce((result, key) => {
27
+ // Use lodash.get to handle deep key paths
28
+ const value = _.get(this._data, key);
29
+ // If the value exists, add it to the result object using the key path as the property name
30
+ if (value !== undefined) {
31
+ // Create nested structure based on the key path
32
+ _.set(result, key, value);
33
+ }
34
+ return result;
35
+ }, {});
36
+ } else {
37
+ // Return a shallow copy of the full data if no keys are provided
38
+ return {
39
+ ...this._data
40
+ };
41
+ }
26
42
  }
27
43
  _addChange(path) {
28
44
  // Ensure no duplicate paths
@@ -92,6 +108,7 @@ export default class RbtObject {
92
108
  throw new Error(response.data.message);
93
109
  }
94
110
  if (response.data?.result == 'NO_CHANGES') {
111
+ this.rpcMeta.isNew = false;
95
112
  return this;
96
113
  }
97
114
  if (response.data?.newData) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roboto-js",
3
- "version": "1.4.15",
3
+ "version": "1.4.17",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "main": "dist/cjs/index.cjs",
package/src/rbt_api.js CHANGED
@@ -75,19 +75,17 @@ export default class RbtApi {
75
75
  * @param {Object} params - The login parameters.
76
76
  * @param {string} params.email - The email of the user.
77
77
  * @param {string} params.password - The password of the user.
78
+ * @param {string} params.code - The password of the user.
78
79
  * @returns {Promise<Object>} - The response data from the API.
79
80
  */
80
81
  async login(params) {
81
82
  try {
82
83
 
83
- // create a md5 hash of the password using crypto-js
84
- const hash_password = CryptoJS.MD5(params.password).toString(CryptoJS.enc.Hex);
85
-
86
-
87
84
  const response = await this.axios.post('/user_service/loginUser', [{
88
85
  email: params.email,
89
- password: hash_password,
90
- passwd: params.password
86
+ password: (params.password)? CryptoJS.MD5(params.password).toString(CryptoJS.enc.Hex): null, // legacy hash password (md5)
87
+ passwd: params.password || null, // current password
88
+ code: params.code || null // single-use signon code (password resets)
91
89
  }]);
92
90
 
93
91
  if (response.data.ok === false) {
package/src/rbt_object.js CHANGED
@@ -25,10 +25,24 @@ export default class RbtObject {
25
25
  return _.get(this._data, path);
26
26
  }
27
27
 
28
- getData() {
29
- return {
30
- ...this._data
31
- };
28
+ getData(keys = null) {
29
+ // Check if keys are provided
30
+ if (keys && Array.isArray(keys)) {
31
+ // Return an object with only the specified keys
32
+ return keys.reduce((result, key) => {
33
+ // Use lodash.get to handle deep key paths
34
+ const value = _.get(this._data, key);
35
+ // If the value exists, add it to the result object using the key path as the property name
36
+ if (value !== undefined) {
37
+ // Create nested structure based on the key path
38
+ _.set(result, key, value);
39
+ }
40
+ return result;
41
+ }, {});
42
+ } else {
43
+ // Return a shallow copy of the full data if no keys are provided
44
+ return { ...this._data };
45
+ }
32
46
  }
33
47
 
34
48
  _addChange(path) {
@@ -107,6 +121,7 @@ export default class RbtObject {
107
121
  }
108
122
 
109
123
  if(response.data?.result == 'NO_CHANGES'){
124
+ this.rpcMeta.isNew = false;
110
125
  return this;
111
126
  }
112
127