@miso.ai/client-sdk-core 1.10.2-beta.6 → 1.10.2-beta.8

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 {
@@ -83,19 +83,30 @@ class UserPlugin extends _commons.Component {
83
83
  anonymous_id,
84
84
  user_id
85
85
  } = client.context;
86
- const baseObj = (0, _commons.trimObj)({
86
+ const userInfo = (0, _commons.trimObj)({
87
87
  anonymous_id,
88
88
  user_id
89
89
  });
90
- data = data.map(obj => Object.assign({}, baseObj, obj));
90
+ data = data.map(obj => Object.assign({}, userInfo, obj));
91
91
  return {
92
92
  data
93
93
  };
94
94
  }
95
95
  }
96
96
  exports.default = UserPlugin;
97
+ let _pageBasedAutoAnonymousId;
97
98
  function getAutoAnonymousId() {
98
- return (0, _commons.getOrComputeFromStorage)('miso_anonymous_id', _commons.uuidv4);
99
+ try {
100
+ return (0, _commons.getOrComputeFromStorage)('miso_anonymous_id', _commons.uuidv4);
101
+ } catch (e) {
102
+ // if the SDK is loaded as a 3rd party script, accessing cookie/localStorage may throw a SecurityError
103
+ // in this case, abort getting the auto anonymous id
104
+ if (e.name !== 'SecurityError') {
105
+ throw e;
106
+ }
107
+ }
108
+ // fallback to page-based auto anonymous id
109
+ return _pageBasedAutoAnonymousId || (_pageBasedAutoAnonymousId = (0, _commons.uuidv4)());
99
110
  }
100
111
  class UserContext {
101
112
  constructor(plugin) {
@@ -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.6';
7
+ var _default = exports.default = '1.10.2-beta.8';
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.6"
32
+ "@miso.ai/commons": "1.10.2-beta.8"
33
33
  },
34
- "version": "1.10.2-beta.6"
34
+ "version": "1.10.2-beta.8"
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 }) {
@@ -54,15 +54,27 @@ export default class UserPlugin extends Component {
54
54
 
55
55
  _modifyPayloadForInteractions(client, { data }) {
56
56
  const { anonymous_id, user_id } = client.context;
57
- const baseObj = trimObj({ anonymous_id, user_id });
58
- data = data.map(obj => ({ ...baseObj, ...obj }));
57
+ const userInfo = trimObj({ anonymous_id, user_id });
58
+ data = data.map(obj => ({ ...userInfo, ...obj }));
59
59
  return { data };
60
60
  }
61
61
 
62
62
  }
63
63
 
64
+ let _pageBasedAutoAnonymousId;
65
+
64
66
  function getAutoAnonymousId() {
65
- return getOrComputeFromStorage('miso_anonymous_id', uuidv4);
67
+ try {
68
+ return getOrComputeFromStorage('miso_anonymous_id', uuidv4);
69
+ } catch (e) {
70
+ // if the SDK is loaded as a 3rd party script, accessing cookie/localStorage may throw a SecurityError
71
+ // in this case, abort getting the auto anonymous id
72
+ if (e.name !== 'SecurityError') {
73
+ throw e;
74
+ }
75
+ }
76
+ // fallback to page-based auto anonymous id
77
+ return _pageBasedAutoAnonymousId || (_pageBasedAutoAnonymousId = uuidv4());
66
78
  }
67
79
 
68
80
  class UserContext {
package/src/version.js CHANGED
@@ -1 +1 @@
1
- export default '1.10.2-beta.6';
1
+ export default '1.10.2-beta.8';