@smithy/util-defaults-mode-browser 4.2.0 → 4.3.0

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.
@@ -1,15 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolveDefaultsModeConfig = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const property_provider_1 = require("@smithy/property-provider");
6
- const bowser_1 = tslib_1.__importDefault(require("bowser"));
7
5
  const constants_1 = require("./constants");
8
6
  const resolveDefaultsModeConfig = ({ defaultsMode, } = {}) => (0, property_provider_1.memoize)(async () => {
9
7
  const mode = typeof defaultsMode === "function" ? await defaultsMode() : defaultsMode;
10
8
  switch (mode?.toLowerCase()) {
11
9
  case "auto":
12
- return Promise.resolve(isMobileBrowser() ? "mobile" : "standard");
10
+ return Promise.resolve(useMobileConfiguration() ? "mobile" : "standard");
13
11
  case "mobile":
14
12
  case "in-region":
15
13
  case "cross-region":
@@ -23,10 +21,14 @@ const resolveDefaultsModeConfig = ({ defaultsMode, } = {}) => (0, property_provi
23
21
  }
24
22
  });
25
23
  exports.resolveDefaultsModeConfig = resolveDefaultsModeConfig;
26
- const isMobileBrowser = () => {
27
- const parsedUA = typeof window !== "undefined" && window?.navigator?.userAgent
28
- ? bowser_1.default.parse(window.navigator.userAgent)
29
- : undefined;
30
- const platform = parsedUA?.platform?.type;
31
- return platform === "tablet" || platform === "mobile";
24
+ const useMobileConfiguration = () => {
25
+ const navigator = window?.navigator;
26
+ if (navigator?.connection) {
27
+ const { effectiveType, rtt, downlink } = navigator?.connection;
28
+ const slow = (typeof effectiveType === "string" && effectiveType !== "4g") || Number(rtt) > 100 || Number(downlink) < 10;
29
+ if (slow) {
30
+ return true;
31
+ }
32
+ }
33
+ return (navigator?.userAgentData?.mobile || (typeof navigator?.maxTouchPoints === "number" && navigator?.maxTouchPoints > 1));
32
34
  };
@@ -1,11 +1,10 @@
1
1
  import { memoize } from "@smithy/property-provider";
2
- import bowser from "bowser";
3
2
  import { DEFAULTS_MODE_OPTIONS } from "./constants";
4
3
  export const resolveDefaultsModeConfig = ({ defaultsMode, } = {}) => memoize(async () => {
5
4
  const mode = typeof defaultsMode === "function" ? await defaultsMode() : defaultsMode;
6
5
  switch (mode?.toLowerCase()) {
7
6
  case "auto":
8
- return Promise.resolve(isMobileBrowser() ? "mobile" : "standard");
7
+ return Promise.resolve(useMobileConfiguration() ? "mobile" : "standard");
9
8
  case "mobile":
10
9
  case "in-region":
11
10
  case "cross-region":
@@ -18,10 +17,14 @@ export const resolveDefaultsModeConfig = ({ defaultsMode, } = {}) => memoize(asy
18
17
  throw new Error(`Invalid parameter for "defaultsMode", expect ${DEFAULTS_MODE_OPTIONS.join(", ")}, got ${mode}`);
19
18
  }
20
19
  });
21
- const isMobileBrowser = () => {
22
- const parsedUA = typeof window !== "undefined" && window?.navigator?.userAgent
23
- ? bowser.parse(window.navigator.userAgent)
24
- : undefined;
25
- const platform = parsedUA?.platform?.type;
26
- return platform === "tablet" || platform === "mobile";
20
+ const useMobileConfiguration = () => {
21
+ const navigator = window?.navigator;
22
+ if (navigator?.connection) {
23
+ const { effectiveType, rtt, downlink } = navigator?.connection;
24
+ const slow = (typeof effectiveType === "string" && effectiveType !== "4g") || Number(rtt) > 100 || Number(downlink) < 10;
25
+ if (slow) {
26
+ return true;
27
+ }
28
+ }
29
+ return (navigator?.userAgentData?.mobile || (typeof navigator?.maxTouchPoints === "number" && navigator?.maxTouchPoints > 1));
27
30
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smithy/util-defaults-mode-browser",
3
- "version": "4.2.0",
3
+ "version": "4.3.0",
4
4
  "scripts": {
5
5
  "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types && yarn build:types:downlevel'",
6
6
  "build:cjs": "node ../../scripts/inline util-defaults-mode-browser",
@@ -25,9 +25,8 @@
25
25
  "sideEffects": false,
26
26
  "dependencies": {
27
27
  "@smithy/property-provider": "^4.2.0",
28
- "@smithy/smithy-client": "^4.7.0",
28
+ "@smithy/smithy-client": "^4.7.1",
29
29
  "@smithy/types": "^4.6.0",
30
- "bowser": "^2.11.0",
31
30
  "tslib": "^2.6.2"
32
31
  },
33
32
  "devDependencies": {