@onehat/data 1.19.21 → 1.19.24

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onehat/data",
3
- "version": "1.19.21",
3
+ "version": "1.19.24",
4
4
  "description": "JS data modeling package with adapters for many storage mediums.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -1,6 +1,7 @@
1
1
  /** @module Repository */
2
2
 
3
3
  import LocalStorageRepository from '@onehat/data/src/Integration/Browser/Repository/LocalStorage';
4
+ import CryptoJS from 'crypto-js';
4
5
  import AES from 'crypto-js/aes';
5
6
  import _ from 'lodash';
6
7
 
@@ -31,7 +32,7 @@ class SecureLocalStorageRepository extends LocalStorageRepository {
31
32
  // BEGIN MOD
32
33
  let result = this._store(name);
33
34
  if (!_.isEmpty(result)) {
34
- result = AES.decrypt(result, this.passphrase);
35
+ result = AES.decrypt(result, this.passphrase).toString(CryptoJS.enc.Utf8);
35
36
  }
36
37
  // END MOD
37
38
 
@@ -66,7 +67,7 @@ class SecureLocalStorageRepository extends LocalStorageRepository {
66
67
  value = JSON.stringify(value);
67
68
  }
68
69
 
69
- value = AES.encrypt(value, this.passphrase); // MOD
70
+ value = AES.encrypt(value, this.passphrase).toString(); // MOD
70
71
 
71
72
  return this._store(name, value);
72
73
 
@@ -1,6 +1,7 @@
1
1
  /** @module Repository */
2
2
 
3
3
  import SessionStorageRepository from '@onehat/data/src/Integration/Browser/Repository/SessionStorage';
4
+ import CryptoJS from 'crypto-js';
4
5
  import AES from 'crypto-js/aes';
5
6
  import _ from 'lodash';
6
7
 
@@ -26,7 +27,7 @@ class SecureSessionStorageRepository extends SessionStorageRepository {
26
27
  // BEGIN MOD
27
28
  let result = this._store.session(name);
28
29
  if (!_.isEmpty(result)) {
29
- result = AES.decrypt(result, this.passphrase);
30
+ result = AES.decrypt(result, this.passphrase).toString(CryptoJS.enc.Utf8);
30
31
  }
31
32
  // END MOD
32
33
 
@@ -45,7 +46,7 @@ class SecureSessionStorageRepository extends SessionStorageRepository {
45
46
  value = JSON.stringify(value);
46
47
  }
47
48
 
48
- value = AES.encrypt(value, this.passphrase); // MOD
49
+ value = AES.encrypt(value, this.passphrase).toString(); // MOD
49
50
 
50
51
  return this._store.session(name, value);
51
52
  }
@@ -277,20 +277,24 @@ class LocalFromRemoteRepository extends EventEmitter {
277
277
  // NORMAL PROCESS, basically call super()
278
278
  // This adds to the local repository, so we can sync later,
279
279
  // if needed.
280
- const normalAdd = this._getActiveRepository().add(data);
280
+ const normalAdd = await this._getActiveRepository().add(data);
281
281
  if (this.mode !== MODE_COMMAND_QUEUE || !this.isOnline) {
282
282
  return normalAdd;
283
283
  }
284
284
 
285
285
  // MODE_COMMAND_QUEUE -- try to sync now!
286
- const entity = await normalAdd;
287
- return await this.sync(entity);
286
+ return await this.sync(normalAdd);
288
287
  }
289
288
 
290
289
  /**
291
290
  * Syncs local and remote repositories, based on operation mode.
292
291
  */
293
292
  sync = async (entity, callback = null) => {
293
+
294
+ if (this.debugMode) {
295
+ console.log('sync');
296
+ }
297
+
294
298
  try {
295
299
  if (!this.isOnline) {
296
300
  this._doAutoSync(true);
@@ -317,6 +317,10 @@ class OneBuildRepository extends AjaxRepository {
317
317
  return;
318
318
  }
319
319
 
320
+ if (!id) {
321
+ return null;
322
+ }
323
+
320
324
  const idPropertyName = this.getSchema().model.idProperty;
321
325
  const params = {};
322
326
  params['conditions[' + idPropertyName + ']'] = id;
@@ -324,7 +328,7 @@ class OneBuildRepository extends AjaxRepository {
324
328
  const data = _.merge(params, this._baseParams);
325
329
 
326
330
  if (this.debugMode) {
327
- console.log('Sending ' + url, options);
331
+ console.log('getSingleEntityFromServer', data);
328
332
  }
329
333
 
330
334
  return this._send(this.methods.get, this.api.get, data)
@@ -347,7 +351,7 @@ class OneBuildRepository extends AjaxRepository {
347
351
  } = this._processServerResponse(result);
348
352
 
349
353
  if (!root[0]) {
350
- throw Error('Record does not exist!')
354
+ return null;
351
355
  }
352
356
 
353
357
  return this.createStandaloneEntity(root[0]);