@onehat/data 1.19.4 → 1.19.6

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.4",
3
+ "version": "1.19.6",
4
4
  "description": "JS data modeling package with adapters for many storage mediums.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -7,8 +7,6 @@ import _ from 'lodash';
7
7
  /**
8
8
  * Repository representing a browser's LocalStorage implementation
9
9
  * Uses store2 package
10
- * Note: LocalStorage is only active for the current browser session.
11
- * It does not persist across sessions. For that, use SessionStorage.
12
10
  * @extends OfflineRepository
13
11
  */
14
12
  class LocalStorageRepository extends OfflineRepository {
@@ -0,0 +1,84 @@
1
+ /** @module Repository */
2
+
3
+ import LocalStorageRepository from '@onehat/data/src/Integration/Browser/Repository/LocalStorage';
4
+ import AES from 'crypto-js/aes';
5
+ import _ from 'lodash';
6
+
7
+ /**
8
+ * Repository representing an encrypted version of the browser's LocalStorage implementation
9
+ * Requires crypto-js - https://www.npmjs.com/package/crypto-js
10
+ * @extends LocalStorageRepository
11
+ */
12
+ class SecureLocalStorageRepository extends LocalStorageRepository {
13
+
14
+ constructor(config = {}) {
15
+ super(...arguments);
16
+
17
+ if (_.isEmpty(config.passphrase)) {
18
+ throw new Error('SecureLocalStorageRepository requires a passphrase!');
19
+ }
20
+
21
+ this.passphrase = config.passphrase;
22
+ }
23
+
24
+ _storageGetValue = (name) => {
25
+ try {
26
+
27
+ if (this.debugMode) {
28
+ console.log(this.name, 'LocalStorage.get', name);
29
+ }
30
+
31
+ // BEGIN MOD
32
+ let result = this._store(name);
33
+ result = AES.decrypt(result, this.passphrase);
34
+ // END MOD
35
+
36
+ if (this.debugMode) {
37
+ console.log(this.name, 'LocalStorage.get results', name, result);
38
+ }
39
+
40
+ let value = null;
41
+ if (!_.isNil(result)) {
42
+ try {
43
+ value = JSON.parse(result);
44
+ } catch (e) {
45
+ // Invalid JSON, just return raw result
46
+ value = result;
47
+ }
48
+ }
49
+ return value;
50
+ } catch (error) {
51
+ if (this.debugMode) {
52
+ const msg = error && error.message;
53
+ debugger;
54
+ }
55
+ }
56
+ }
57
+
58
+ _storageSetValue = (name, value) => {
59
+ try {
60
+ if (this.debugMode) {
61
+ console.log(this.name, 'LocalStorage.set', name, value);
62
+ }
63
+ if (!_.isString(value)) {
64
+ value = JSON.stringify(value);
65
+ }
66
+
67
+ value = AES.encrypt(value, this.passphrase); // MOD
68
+
69
+ return this._store(name, value);
70
+
71
+ } catch (error) {
72
+ if (this.debugMode) {
73
+ const msg = error && error.message;
74
+ debugger;
75
+ }
76
+ }
77
+ }
78
+
79
+ };
80
+
81
+ SecureLocalStorageRepository.className = 'SecureLocalStorage';
82
+ SecureLocalStorageRepository.type = 'secureLocal';
83
+
84
+ export default SecureLocalStorageRepository;
@@ -0,0 +1,56 @@
1
+ /** @module Repository */
2
+
3
+ import SessionStorageRepository from '@onehat/data/src/Integration/Browser/Repository/SessionStorage';
4
+ import AES from 'crypto-js/aes';
5
+ import _ from 'lodash';
6
+
7
+ /**
8
+ * Repository representing an encrypted version of the browser's SessionStorage implementation
9
+ * Requires crypto-js - https://www.npmjs.com/package/crypto-js
10
+ * @extends SessionStorageRepository
11
+ */
12
+ class SecureSessionStorageRepository extends SessionStorageRepository {
13
+
14
+ constructor(config = {}) {
15
+ super(...arguments);
16
+
17
+ if (_.isEmpty(config.passphrase)) {
18
+ throw new Error('SecureSessionStorageRepository requires a passphrase!');
19
+ }
20
+
21
+ this.passphrase = config.passphrase;
22
+ }
23
+
24
+ _storageGetValue = (name) => {
25
+
26
+ // BEGIN MOD
27
+ let result = this._store.session(name);
28
+ result = AES.decrypt(result, this.passphrase);
29
+ // END MOD
30
+
31
+ let value;
32
+ try {
33
+ value = JSON.parse(result);
34
+ } catch (e) {
35
+ // Invalid JSON, just return raw result
36
+ value = result;
37
+ }
38
+ return value;
39
+ }
40
+
41
+ _storageSetValue = (name, value) => {
42
+ if (!_.isString(value)) {
43
+ value = JSON.stringify(value);
44
+ }
45
+
46
+ value = AES.encrypt(value, this.passphrase); // MOD
47
+
48
+ return this._store.session(name, value);
49
+ }
50
+
51
+ };
52
+
53
+ SecureSessionStorageRepository.className = 'SecureSessionStorage';
54
+ SecureSessionStorageRepository.type = 'secureSession';
55
+
56
+ export default SecureSessionStorageRepository;
@@ -7,6 +7,8 @@ import _ from 'lodash';
7
7
  /**
8
8
  * Repository representing a browser's SessionStorage implementation
9
9
  * Uses store2 package
10
+ * Note: SessionStorage is only active for the current browser session.
11
+ * It does not persist across sessions. For that, use LocalStorage.
10
12
  * @extends OfflineRepository
11
13
  */
12
14
  class SessionStorageRepository extends OfflineRepository {
@@ -128,6 +128,11 @@ export default class Property extends EventEmitter {
128
128
  */
129
129
  isFilteringDisabled: false,
130
130
 
131
+ /**
132
+ * @member {object} viewerType - The UI viewer type of this property
133
+ */
134
+ viewerType: null,
135
+
131
136
  /**
132
137
  * @member {object} editorType - The UI editor type of this property
133
138
  */
@@ -236,10 +236,6 @@ class OneBuildRepository extends AjaxRepository {
236
236
  };
237
237
  }
238
238
 
239
- if (!result) {
240
- debugger;
241
- }
242
-
243
239
  const
244
240
  response = _.isPlainObject(result.data) ? result.data : this.reader.read(result.data),
245
241
  root = response[this.rootProperty],