@yourself_id/siwys-react-js 0.33.2-sapp-761-missing-extension-detection-handler.66.0 → 0.33.2-sapp-761-missing-extension-detection-handler.69.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.
package/README.md CHANGED
@@ -6,9 +6,11 @@ React components for Sign in with your SELF.
6
6
 
7
7
  `SignInWithYourSelf` and `ConnectYourSelf` use the browser-extension flow on
8
8
  desktop Chrome, Edge, Firefox, and Safari. If the extension is missing, the
9
- active window goes to that browser's store listing. iPhone and iPad go to the
10
- SELF App Store listing. Android goes to the Play Store listing. Set
11
- `extensionConfig` to `false` to skip the extension check on desktop.
9
+ active window goes to that browser's store listing. On iPhone, iPad, and
10
+ Android, the sign-in button opens the challenge link so the installed SELF app
11
+ can handle it. If the app does not open, the active window goes to the App
12
+ Store or Play Store. Set `extensionConfig` to `false` to skip the extension
13
+ check on desktop.
12
14
 
13
15
  ```tsx
14
16
  <SignInWithYourSelf
package/dist/index.js CHANGED
@@ -1197,6 +1197,7 @@ var MOBILE_APP_STORE_URLS = {
1197
1197
  ios: "https://apps.apple.com/us/app/self-id/id1663745416",
1198
1198
  android: "https://play.google.com/store/apps/details?id=id.selfid"
1199
1199
  };
1200
+ var MOBILE_APP_OPEN_FALLBACK_MS = 1500;
1200
1201
  var resolveDesktopExtensionBrowser = function resolveDesktopExtensionBrowser() {
1201
1202
  if (typeof navigator === "undefined") return null;
1202
1203
  var userAgent = navigator.userAgent;
@@ -1220,6 +1221,36 @@ var resolveMobileAppStoreUrl = function resolveMobileAppStoreUrl() {
1220
1221
  var assignActiveWindow = function assignActiveWindow(url) {
1221
1222
  window.location.assign(url);
1222
1223
  };
1224
+ var openInstalledMobileApp = function openInstalledMobileApp(challengeUrl, storeUrl) {
1225
+ var assign = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : assignActiveWindow, fallbackMs = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : MOBILE_APP_OPEN_FALLBACK_MS;
1226
+ var settled = false;
1227
+ var timer = 0;
1228
+ var cancel = function cancel() {
1229
+ if (settled) return;
1230
+ settled = true;
1231
+ window.clearTimeout(timer);
1232
+ document.removeEventListener("visibilitychange", onVisibilityChange);
1233
+ window.removeEventListener("pagehide", onPageHide);
1234
+ };
1235
+ var onPageHide = function onPageHide() {
1236
+ cancel();
1237
+ };
1238
+ var onVisibilityChange = function onVisibilityChange() {
1239
+ if (document.visibilityState === "hidden") {
1240
+ cancel();
1241
+ }
1242
+ };
1243
+ document.addEventListener("visibilitychange", onVisibilityChange);
1244
+ window.addEventListener("pagehide", onPageHide);
1245
+ timer = window.setTimeout(function() {
1246
+ if (document.visibilityState === "visible") {
1247
+ assign(storeUrl);
1248
+ }
1249
+ cancel();
1250
+ }, fallbackMs);
1251
+ assign(challengeUrl);
1252
+ return cancel;
1253
+ };
1223
1254
  var detectExtension = function detectExtension() {
1224
1255
  var detectionTimeoutMs = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : DEFAULT_DETECTION_TIMEOUT_MS;
1225
1256
  if (typeof window === "undefined") return Promise.resolve(false);
@@ -1392,6 +1423,7 @@ var SignInWithYourSelf = function SignInWithYourSelf(param) {
1392
1423
  var _ref5 = _sliced_to_array((0, import_react4.useState)(""), 2), extensionError = _ref5[0], setExtensionError = _ref5[1];
1393
1424
  var _ref6 = _sliced_to_array((0, import_react4.useState)(false), 2), isReplacingChallenge = _ref6[0], setIsReplacingChallenge = _ref6[1];
1394
1425
  var removeStatusListener = (0, import_react4.useRef)();
1426
+ var cancelMobileOpen = (0, import_react4.useRef)();
1395
1427
  var isMounted = (0, import_react4.useRef)(true);
1396
1428
  var replacingRef = (0, import_react4.useRef)(false);
1397
1429
  var challengeRequestRef = (0, import_react4.useRef)(0);
@@ -1406,8 +1438,9 @@ var SignInWithYourSelf = function SignInWithYourSelf(param) {
1406
1438
  (0, import_react4.useEffect)(function() {
1407
1439
  isMounted.current = true;
1408
1440
  return function() {
1409
- var _removeStatusListener_current;
1441
+ var _cancelMobileOpen_current, _removeStatusListener_current;
1410
1442
  isMounted.current = false;
1443
+ (_cancelMobileOpen_current = cancelMobileOpen.current) === null || _cancelMobileOpen_current === void 0 ? void 0 : _cancelMobileOpen_current.call(cancelMobileOpen);
1411
1444
  (_removeStatusListener_current = removeStatusListener.current) === null || _removeStatusListener_current === void 0 ? void 0 : _removeStatusListener_current.call(removeStatusListener);
1412
1445
  };
1413
1446
  }, []);
@@ -1624,7 +1657,9 @@ var SignInWithYourSelf = function SignInWithYourSelf(param) {
1624
1657
  }
1625
1658
  var mobileStoreUrl = resolveMobileAppStoreUrl();
1626
1659
  if (mobileStoreUrl) {
1627
- assignActiveWindow(mobileStoreUrl);
1660
+ var _cancelMobileOpen_current;
1661
+ (_cancelMobileOpen_current = cancelMobileOpen.current) === null || _cancelMobileOpen_current === void 0 ? void 0 : _cancelMobileOpen_current.call(cancelMobileOpen);
1662
+ cancelMobileOpen.current = openInstalledMobileApp(challengeUrl, mobileStoreUrl, assignActiveWindow);
1628
1663
  return;
1629
1664
  }
1630
1665
  window.open(challengeUrl, "_blank");