@miso.ai/client-sdk-core 1.10.2-beta.7 → 1.10.2-beta.9

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.
@@ -26,7 +26,7 @@ class UserPlugin extends _commons.Component {
26
26
  _injectClient(client) {
27
27
  const context = new UserContext(this);
28
28
  this._contexts.set(client, context);
29
- (0, _commons.delegateProperties)(client.context, context, ['anonymous_id', 'user_id', 'user_hash']);
29
+ (0, _commons.delegateProperties)(client.context, context, ['anonymous_id', 'user_id', 'user_hash', 'user_type']);
30
30
  }
31
31
  _modifyPayload(_ref) {
32
32
  let {
@@ -94,24 +94,19 @@ class UserPlugin extends _commons.Component {
94
94
  }
95
95
  }
96
96
  exports.default = UserPlugin;
97
+ let _pageBasedAutoAnonymousId;
97
98
  function getAutoAnonymousId() {
98
- try {
99
- return [(0, _commons.getOrComputeFromStorage)('miso_anonymous_id', _commons.uuidv4)];
100
- } catch (e) {
101
- // if the SDK is loaded as a 3rd party script, accessing cookie/localStorage may throw a SecurityError
102
- // in this case, abort getting the auto anonymous id
103
- if (e.name !== 'SecurityError') {
104
- throw e;
105
- }
106
- }
107
- return [];
99
+ // 1. Cache the value for the page
100
+ // 2. Get and set the value from cookies/localStorage is possible
101
+ // 3. In case cookies/localStorage are disabled, generate a new value for each page
102
+ return _pageBasedAutoAnonymousId || (_pageBasedAutoAnonymousId = (0, _commons.getOrComputeFromStorage)('miso_anonymous_id', _commons.uuidv4));
108
103
  }
109
104
  class UserContext {
110
105
  constructor(plugin) {
111
106
  this._plugin = plugin;
112
107
  }
113
108
  get anonymous_id() {
114
- return this._anonymousId || (this._autoAnonymousId || (this._autoAnonymousId = getAutoAnonymousId()))[0];
109
+ return this._anonymousId || getAutoAnonymousId();
115
110
  }
116
111
  set anonymous_id(value) {
117
112
  value = (0, _commons.asString)(value);
@@ -4,4 +4,4 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = exports.default = '1.10.2-beta.7';
7
+ var _default = exports.default = '1.10.2-beta.9';
package/package.json CHANGED
@@ -29,7 +29,7 @@
29
29
  "url": "https://github.com/MisoAI/miso-client-js-sdk/issues"
30
30
  },
31
31
  "dependencies": {
32
- "@miso.ai/commons": "1.10.2-beta.7"
32
+ "@miso.ai/commons": "1.10.2-beta.9"
33
33
  },
34
- "version": "1.10.2-beta.7"
34
+ "version": "1.10.2-beta.9"
35
35
  }
@@ -24,7 +24,7 @@ export default class UserPlugin extends Component {
24
24
  _injectClient(client) {
25
25
  const context = new UserContext(this);
26
26
  this._contexts.set(client, context);
27
- delegateProperties(client.context, context, ['anonymous_id', 'user_id', 'user_hash']);
27
+ delegateProperties(client.context, context, ['anonymous_id', 'user_id', 'user_hash', 'user_type']);
28
28
  }
29
29
 
30
30
  _modifyPayload({ client, apiGroup, apiName, payload }) {
@@ -61,17 +61,13 @@ export default class UserPlugin extends Component {
61
61
 
62
62
  }
63
63
 
64
+ let _pageBasedAutoAnonymousId;
65
+
64
66
  function getAutoAnonymousId() {
65
- try {
66
- return [getOrComputeFromStorage('miso_anonymous_id', uuidv4)];
67
- } catch (e) {
68
- // if the SDK is loaded as a 3rd party script, accessing cookie/localStorage may throw a SecurityError
69
- // in this case, abort getting the auto anonymous id
70
- if (e.name !== 'SecurityError') {
71
- throw e;
72
- }
73
- }
74
- return [];
67
+ // 1. Cache the value for the page
68
+ // 2. Get and set the value from cookies/localStorage is possible
69
+ // 3. In case cookies/localStorage are disabled, generate a new value for each page
70
+ return _pageBasedAutoAnonymousId || (_pageBasedAutoAnonymousId = getOrComputeFromStorage('miso_anonymous_id', uuidv4));
75
71
  }
76
72
 
77
73
  class UserContext {
@@ -81,7 +77,7 @@ class UserContext {
81
77
  }
82
78
 
83
79
  get anonymous_id() {
84
- return this._anonymousId || (this._autoAnonymousId || (this._autoAnonymousId = getAutoAnonymousId()))[0];
80
+ return this._anonymousId || getAutoAnonymousId();
85
81
  }
86
82
 
87
83
  set anonymous_id(value) {
package/src/version.js CHANGED
@@ -1 +1 @@
1
- export default '1.10.2-beta.7';
1
+ export default '1.10.2-beta.9';