@adobe/alloy 2.14.0-alpha.11 → 2.14.0-alpha.13

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.
@@ -36,12 +36,14 @@ var getScreenOrientationViaProperty = function getScreenOrientationViaProperty(w
36
36
  };
37
37
 
38
38
  var getScreenOrientationViaMediaQuery = function getScreenOrientationViaMediaQuery(window) {
39
- if (window.matchMedia("(orientation: portrait)").matches) {
40
- return "portrait";
41
- }
39
+ if ((0, _utils.isFunction)(window.matchMedia)) {
40
+ if (window.matchMedia("(orientation: portrait)").matches) {
41
+ return "portrait";
42
+ }
42
43
 
43
- if (window.matchMedia("(orientation: landscape)").matches) {
44
- return "landscape";
44
+ if (window.matchMedia("(orientation: landscape)").matches) {
45
+ return "landscape";
46
+ }
45
47
  }
46
48
 
47
49
  return null;
@@ -52,19 +54,30 @@ var _default = function _default(window) {
52
54
  var _window$screen = window.screen,
53
55
  width = _window$screen.width,
54
56
  height = _window$screen.height;
55
- var device = {
56
- screenHeight: height,
57
- screenWidth: width
58
- };
57
+ var device = {};
58
+ var screenHeight = (0, _utils.toInteger)(height);
59
+
60
+ if (screenHeight >= 0) {
61
+ device.screenHeight = screenHeight;
62
+ }
63
+
64
+ var screenWidth = (0, _utils.toInteger)(width);
65
+
66
+ if (screenWidth >= 0) {
67
+ device.screenWidth = screenWidth;
68
+ }
69
+
59
70
  var orientation = getScreenOrientationViaProperty(window) || getScreenOrientationViaMediaQuery(window);
60
71
 
61
72
  if (orientation) {
62
73
  device.screenOrientation = orientation;
63
74
  }
64
75
 
65
- (0, _utils.deepAssign)(xdm, {
66
- device: device
67
- });
76
+ if (Object.keys(device).length > 0) {
77
+ (0, _utils.deepAssign)(xdm, {
78
+ device: device
79
+ });
80
+ }
68
81
  };
69
82
  };
70
83
 
@@ -24,14 +24,21 @@ var _default = function _default(window) {
24
24
  var environment = {
25
25
  type: "browser"
26
26
  };
27
+ var viewportWidth = (0, _utils.toInteger)(clientWidth);
27
28
 
28
- if ((0, _utils.isNumber)(clientWidth) && clientWidth >= 0 && (0, _utils.isNumber)(clientHeight) && clientHeight >= 0) {
29
+ if (viewportWidth >= 0) {
29
30
  environment.browserDetails = {
30
- viewportWidth: Math.round(clientWidth),
31
- viewportHeight: Math.round(clientHeight)
31
+ viewportWidth: viewportWidth
32
32
  };
33
33
  }
34
34
 
35
+ var viewportHeight = (0, _utils.toInteger)(clientHeight);
36
+
37
+ if (viewportHeight >= 0) {
38
+ environment.browserDetails = environment.browserDetails || {};
39
+ environment.browserDetails.viewportHeight = viewportHeight;
40
+ }
41
+
35
42
  (0, _utils.deepAssign)(xdm, {
36
43
  environment: environment
37
44
  });
@@ -6,17 +6,20 @@ var _utils = require("../../utils");
6
6
 
7
7
  var _highEntropyUserAgentClientHints = require("../../constants/highEntropyUserAgentClientHints");
8
8
 
9
- /*
10
- Copyright 2022 Adobe. All rights reserved.
11
- This file is licensed to you under the Apache License, Version 2.0 (the "License");
12
- you may not use this file except in compliance with the License. You may obtain a copy
13
- of the License at http://www.apache.org/licenses/LICENSE-2.0
14
-
15
- Unless required by applicable law or agreed to in writing, software distributed under
16
- the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
17
- OF ANY KIND, either express or implied. See the License for the specific language
18
- governing permissions and limitations under the License.
19
- */
9
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
10
+
11
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
12
+
13
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
14
+
15
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
16
+
17
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
18
+
19
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
20
+
21
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
22
+
20
23
  var browserSupportsUserAgentClientHints = function browserSupportsUserAgentClientHints(navigator) {
21
24
  return typeof navigator.userAgentData !== "undefined";
22
25
  };
@@ -28,12 +31,20 @@ var _default = function _default(navigator) {
28
31
 
29
32
  return function (xdm, logger) {
30
33
  try {
31
- return navigator.userAgentData.getHighEntropyValues(_highEntropyUserAgentClientHints.default).then(function (hints) {
34
+ return navigator.userAgentData.getHighEntropyValues(_highEntropyUserAgentClientHints.default.map(function (hint) {
35
+ return hint[0];
36
+ })).then(function (hints) {
32
37
  var userAgentClientHints = {};
33
38
 
34
- _highEntropyUserAgentClientHints.default.forEach(function (hint) {
35
- if (Object.prototype.hasOwnProperty.call(hints, hint)) {
36
- userAgentClientHints[hint] = hints[hint];
39
+ _highEntropyUserAgentClientHints.default.forEach(function (_ref) {
40
+ var _ref2 = _slicedToArray(_ref, 2),
41
+ hintName = _ref2[0],
42
+ hintType = _ref2[1];
43
+
44
+ if (Object.prototype.hasOwnProperty.call(hints, hintName) &&
45
+ /* eslint-disable-next-line valid-typeof */
46
+ _typeof(hints[hintName]) === hintType) {
47
+ userAgentClientHints[hintName] = hints[hintName];
37
48
  }
38
49
  });
39
50
 
@@ -19,8 +19,9 @@ var _default = function _default(_ref) {
19
19
  var logger = _ref.logger,
20
20
  orgId = _ref.orgId,
21
21
  awaitVisitorOptIn = _ref.awaitVisitorOptIn;
22
- var Visitor = (0, _getVisitor.default)(window);
23
22
  return function () {
23
+ var Visitor = (0, _getVisitor.default)(window);
24
+
24
25
  if (Visitor) {
25
26
  // Need to explicitly wait for optIn because visitor will call callback
26
27
  // with invalid values prior to optIn being approved
@@ -13,5 +13,5 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
13
13
  OF ANY KIND, either express or implied. See the License for the specific language
14
14
  governing permissions and limitations under the License.
15
15
  */
16
- var _default = ["architecture", "bitness", "model", "platformVersion", "wow64"];
16
+ var _default = [["architecture", "string"], ["bitness", "string"], ["model", "string"], ["platformVersion", "string"], ["wow64", "boolean"]];
17
17
  exports.default = _default;
@@ -15,5 +15,5 @@ governing permissions and limitations under the License.
15
15
  */
16
16
  // The __VERSION__ keyword will be replace at alloy build time with the package.json version.
17
17
  // see babel-plugin-version
18
- var _default = "2.14.0-alpha.11";
18
+ var _default = "2.14.0-alpha.13";
19
19
  exports.default = _default;
@@ -2,6 +2,10 @@
2
2
 
3
3
  exports.default = void 0;
4
4
 
5
+ var _isNumber = require("./isNumber");
6
+
7
+ var _isString = require("./isString");
8
+
5
9
  /*
6
10
  Copyright 2022 Adobe. All rights reserved.
7
11
  This file is licensed to you under the Apache License, Version 2.0 (the "License");
@@ -16,11 +20,19 @@ governing permissions and limitations under the License.
16
20
 
17
21
  /*
18
22
  * coerce `value` to a number or return `defaultValue` if it cannot be.
23
+ *
24
+ * The coersion is attempted if value is a number or string.
19
25
  */
20
26
  var _default = function _default(value, defaultValue) {
21
- var n = Math.round(Number(value)); // eslint-disable-next-line no-restricted-globals
27
+ if ((0, _isNumber.default)(value) || (0, _isString.default)(value)) {
28
+ var n = Math.round(Number(value)); // eslint-disable-next-line no-restricted-globals
29
+
30
+ if (!isNaN(n)) {
31
+ return n;
32
+ }
33
+ }
22
34
 
23
- return isNaN(n) ? defaultValue : n;
35
+ return defaultValue;
24
36
  };
25
37
 
26
38
  exports.default = _default;
@@ -9,7 +9,7 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
9
9
  OF ANY KIND, either express or implied. See the License for the specific language
10
10
  governing permissions and limitations under the License.
11
11
  */
12
- import { deepAssign } from "../../utils";
12
+ import { deepAssign, isFunction, toInteger } from "../../utils";
13
13
 
14
14
  const getScreenOrientationViaProperty = window => {
15
15
  const {
@@ -36,12 +36,14 @@ const getScreenOrientationViaProperty = window => {
36
36
  };
37
37
 
38
38
  const getScreenOrientationViaMediaQuery = window => {
39
- if (window.matchMedia("(orientation: portrait)").matches) {
40
- return "portrait";
41
- }
39
+ if (isFunction(window.matchMedia)) {
40
+ if (window.matchMedia("(orientation: portrait)").matches) {
41
+ return "portrait";
42
+ }
42
43
 
43
- if (window.matchMedia("(orientation: landscape)").matches) {
44
- return "landscape";
44
+ if (window.matchMedia("(orientation: landscape)").matches) {
45
+ return "landscape";
46
+ }
45
47
  }
46
48
 
47
49
  return null;
@@ -55,18 +57,29 @@ export default (window => {
55
57
  height
56
58
  }
57
59
  } = window;
58
- const device = {
59
- screenHeight: height,
60
- screenWidth: width
61
- };
60
+ const device = {};
61
+ const screenHeight = toInteger(height);
62
+
63
+ if (screenHeight >= 0) {
64
+ device.screenHeight = screenHeight;
65
+ }
66
+
67
+ const screenWidth = toInteger(width);
68
+
69
+ if (screenWidth >= 0) {
70
+ device.screenWidth = screenWidth;
71
+ }
72
+
62
73
  const orientation = getScreenOrientationViaProperty(window) || getScreenOrientationViaMediaQuery(window);
63
74
 
64
75
  if (orientation) {
65
76
  device.screenOrientation = orientation;
66
77
  }
67
78
 
68
- deepAssign(xdm, {
69
- device
70
- });
79
+ if (Object.keys(device).length > 0) {
80
+ deepAssign(xdm, {
81
+ device
82
+ });
83
+ }
71
84
  };
72
85
  });
@@ -9,7 +9,7 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
9
9
  OF ANY KIND, either express or implied. See the License for the specific language
10
10
  governing permissions and limitations under the License.
11
11
  */
12
- import { deepAssign, isNumber } from "../../utils";
12
+ import { deepAssign, toInteger } from "../../utils";
13
13
  export default (window => {
14
14
  return xdm => {
15
15
  const {
@@ -23,14 +23,21 @@ export default (window => {
23
23
  const environment = {
24
24
  type: "browser"
25
25
  };
26
+ const viewportWidth = toInteger(clientWidth);
26
27
 
27
- if (isNumber(clientWidth) && clientWidth >= 0 && isNumber(clientHeight) && clientHeight >= 0) {
28
+ if (viewportWidth >= 0) {
28
29
  environment.browserDetails = {
29
- viewportWidth: Math.round(clientWidth),
30
- viewportHeight: Math.round(clientHeight)
30
+ viewportWidth
31
31
  };
32
32
  }
33
33
 
34
+ const viewportHeight = toInteger(clientHeight);
35
+
36
+ if (viewportHeight >= 0) {
37
+ environment.browserDetails = environment.browserDetails || {};
38
+ environment.browserDetails.viewportHeight = viewportHeight;
39
+ }
40
+
34
41
  deepAssign(xdm, {
35
42
  environment
36
43
  });
@@ -23,11 +23,13 @@ export default (navigator => {
23
23
 
24
24
  return (xdm, logger) => {
25
25
  try {
26
- return navigator.userAgentData.getHighEntropyValues(highEntropyUserAgentHints).then(hints => {
26
+ return navigator.userAgentData.getHighEntropyValues(highEntropyUserAgentHints.map(hint => hint[0])).then(hints => {
27
27
  const userAgentClientHints = {};
28
- highEntropyUserAgentHints.forEach(hint => {
29
- if (Object.prototype.hasOwnProperty.call(hints, hint)) {
30
- userAgentClientHints[hint] = hints[hint];
28
+ highEntropyUserAgentHints.forEach(([hintName, hintType]) => {
29
+ if (Object.prototype.hasOwnProperty.call(hints, hintName) &&
30
+ /* eslint-disable-next-line valid-typeof */
31
+ typeof hints[hintName] === hintType) {
32
+ userAgentClientHints[hintName] = hints[hintName];
31
33
  }
32
34
  });
33
35
  deepAssign(xdm, {
@@ -15,8 +15,9 @@ export default (({
15
15
  orgId,
16
16
  awaitVisitorOptIn
17
17
  }) => {
18
- const Visitor = getVisitor(window);
19
18
  return () => {
19
+ const Visitor = getVisitor(window);
20
+
20
21
  if (Visitor) {
21
22
  // Need to explicitly wait for optIn because visitor will call callback
22
23
  // with invalid values prior to optIn being approved
@@ -9,4 +9,4 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
9
9
  OF ANY KIND, either express or implied. See the License for the specific language
10
10
  governing permissions and limitations under the License.
11
11
  */
12
- export default ["architecture", "bitness", "model", "platformVersion", "wow64"];
12
+ export default [["architecture", "string"], ["bitness", "string"], ["model", "string"], ["platformVersion", "string"], ["wow64", "boolean"]];
@@ -11,4 +11,4 @@ governing permissions and limitations under the License.
11
11
  */
12
12
  // The __VERSION__ keyword will be replace at alloy build time with the package.json version.
13
13
  // see babel-plugin-version
14
- export default "2.14.0-alpha.11";
14
+ export default "2.14.0-alpha.13";
@@ -9,12 +9,22 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
9
9
  OF ANY KIND, either express or implied. See the License for the specific language
10
10
  governing permissions and limitations under the License.
11
11
  */
12
-
12
+ import isNumber from "./isNumber";
13
+ import isString from "./isString";
13
14
  /*
14
15
  * coerce `value` to a number or return `defaultValue` if it cannot be.
16
+ *
17
+ * The coersion is attempted if value is a number or string.
15
18
  */
19
+
16
20
  export default ((value, defaultValue) => {
17
- const n = Math.round(Number(value)); // eslint-disable-next-line no-restricted-globals
21
+ if (isNumber(value) || isString(value)) {
22
+ const n = Math.round(Number(value)); // eslint-disable-next-line no-restricted-globals
23
+
24
+ if (!isNaN(n)) {
25
+ return n;
26
+ }
27
+ }
18
28
 
19
- return isNaN(n) ? defaultValue : n;
29
+ return defaultValue;
20
30
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/alloy",
3
- "version": "2.14.0-alpha.11",
3
+ "version": "2.14.0-alpha.13",
4
4
  "description": "Adobe Experience Platform Web SDK",
5
5
  "main": "libEs5/index.js",
6
6
  "module": "libEs6/index.js",
@@ -64,7 +64,7 @@
64
64
  "uuid": "^3.3.2"
65
65
  },
66
66
  "devDependencies": {
67
- "@adobe/alloy": "^2.14.0-alpha.10",
67
+ "@adobe/alloy": "^2.14.0-alpha.12",
68
68
  "@babel/cli": "^7.12.8",
69
69
  "@babel/core": "^7.2.2",
70
70
  "@babel/plugin-proposal-object-rest-spread": "^7.3.2",