@proveanything/smartlinks-auth-ui 0.5.8 → 0.5.10

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 +1 @@
1
- {"version":3,"file":"AuthContext.d.ts","sourceRoot":"","sources":["../../src/context/AuthContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8E,MAAM,OAAO,CAAC;AAOnG,OAAO,KAAK,EAAqC,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAGvG,eAAO,MAAM,WAAW,6CAAyD,CAAC;AAGlF,YAAY,EAAE,gBAAgB,EAAE,CAAC;AAEjC,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAw4BpD,CAAC;AAEF,eAAO,MAAM,OAAO,QAAO,gBAM1B,CAAC"}
1
+ {"version":3,"file":"AuthContext.d.ts","sourceRoot":"","sources":["../../src/context/AuthContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8E,MAAM,OAAO,CAAC;AAOnG,OAAO,KAAK,EAAqC,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAGvG,eAAO,MAAM,WAAW,6CAAyD,CAAC;AAGlF,YAAY,EAAE,gBAAgB,EAAE,CAAC;AAEjC,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAm+BpD,CAAC;AAEF,eAAO,MAAM,OAAO,QAAO,gBAM1B,CAAC"}
package/dist/index.esm.js CHANGED
@@ -1,8 +1,7 @@
1
1
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
2
  import React, { useEffect, useState, useMemo, useRef, useCallback, createContext, useContext } from 'react';
3
3
  import * as smartlinks from '@proveanything/smartlinks';
4
- import { SmartlinksApiError, iframe } from '@proveanything/smartlinks';
5
- import { post, getApiHeaders, isProxyEnabled } from '@proveanything/smartlinks/dist/http';
4
+ import { SmartlinksApiError, post, iframe, getApiHeaders, isProxyEnabled } from '@proveanything/smartlinks';
6
5
 
7
6
  const AuthContainer = ({ children, theme = 'light', className = '', config, minimal = false, }) => {
8
7
  // Apply CSS variables for customization
@@ -3097,24 +3096,25 @@ function isPossiblePhoneNumber(input, options, metadata) {
3097
3096
  }
3098
3097
  }
3099
3098
 
3100
- // Old metadata (< 1.0.18) had no "possible length" data.
3099
+ // Old (legacy) metadata (< 1.0.18) had no "possible length" data.
3100
+ // So `isPossibleNumber()` function is supported only for non-legacy metadata.
3101
3101
  if (metadata.possibleLengths()) {
3102
3102
  return isPossibleNumber(input.phone || input.nationalNumber, input.country, metadata);
3103
- } else {
3104
- // There was a bug between `1.7.35` and `1.7.37` where "possible_lengths"
3105
- // were missing for "non-geographical" numbering plans.
3106
- // Just assume the number is possible in such cases:
3107
- // it's unlikely that anyone generated their custom metadata
3108
- // in that short period of time (one day).
3109
- // This code can be removed in some future major version update.
3110
- if (input.countryCallingCode && metadata.isNonGeographicCallingCode(input.countryCallingCode)) {
3111
- // "Non-geographic entities" did't have `possibleLengths`
3112
- // due to a bug in metadata generation process.
3113
- return true;
3114
- } else {
3115
- throw new Error('Missing "possibleLengths" in metadata. Perhaps the metadata has been generated before v1.0.18.');
3116
- }
3117
3103
  }
3104
+
3105
+ // There was a bug in versions from `1.7.35` to `1.7.37` of `libphonenumber-js`
3106
+ // where "possible_lengths" property was missing from "non-geographical" numbering plans' metadata.
3107
+ // After that, the bug was noticed and fixed.
3108
+ // So for versions from `1.7.35` to `1.7.37`, just assume that all "non=geotraphical" numbers are possible.
3109
+ // The reason is that the bug was noticed relatively quickly (within a day or so)
3110
+ // and it's unlikely that anyone generated their custom metadata in that short time span.
3111
+ // And if they didn't generate any custom metadata then a follow-up package update would've silently fixed the bug.
3112
+ if (input.countryCallingCode && metadata.isNonGeographicCallingCode(input.countryCallingCode)) {
3113
+ return true;
3114
+ }
3115
+
3116
+ // `isPossibleNumber()` function is not supported.
3117
+ throw new Error('Missing "possibleLengths" in metadata. Perhaps the metadata has been generated before v1.0.18.');
3118
3118
  }
3119
3119
  function isPossibleNumber(nationalNumber, country, metadata) {
3120
3120
  //, isInternational) {
@@ -12036,6 +12036,7 @@ collectionId, enableContactSync, enableInteractionTracking, interactionAppId, in
12036
12036
  const callbacksRef = useRef(new Set());
12037
12037
  const initializingRef = useRef(false);
12038
12038
  const pendingVerificationRef = useRef(false);
12039
+ const proxyRefreshInFlightRef = useRef(false);
12039
12040
  // Stable refs for callbacks to avoid useEffect dependency cycles
12040
12041
  const syncContactRef = useRef();
12041
12042
  const trackInteractionRef = useRef();
@@ -12397,6 +12398,85 @@ collectionId, enableContactSync, enableInteractionTracking, interactionAppId, in
12397
12398
  window.removeEventListener('message', handleParentMessage);
12398
12399
  };
12399
12400
  }, [proxyMode, notifyAuthStateChange]);
12401
+ // In proxy mode, mobile auth often returns from WhatsApp/Google via app switching,
12402
+ // so the page stays mounted while the parent session changes underneath it.
12403
+ // Re-check account state on focus/visibility/page restore so login/logout appears
12404
+ // immediately instead of waiting for a full refresh.
12405
+ useEffect(() => {
12406
+ if (!proxyMode)
12407
+ return;
12408
+ const clearProxyState = () => {
12409
+ setUser(null);
12410
+ setToken(null);
12411
+ setAccountData(null);
12412
+ setAccountInfo(null);
12413
+ setContact(null);
12414
+ setContactId(null);
12415
+ setIsVerified(false);
12416
+ pendingVerificationRef.current = false;
12417
+ notifyAuthStateChange('LOGOUT', null, null, null, null, false);
12418
+ };
12419
+ const refreshProxySession = async () => {
12420
+ if (proxyRefreshInFlightRef.current)
12421
+ return;
12422
+ const headers = getApiHeaders();
12423
+ const hasBearer = !!headers['Authorization'];
12424
+ const hasSdkProxy = isProxyEnabled();
12425
+ if (!hasBearer && !hasSdkProxy) {
12426
+ clearProxyState();
12427
+ return;
12428
+ }
12429
+ proxyRefreshInFlightRef.current = true;
12430
+ try {
12431
+ const accountResponse = await smartlinks.auth.getAccount();
12432
+ const accountAny = accountResponse;
12433
+ const hasValidSession = accountAny?.uid && accountAny.uid.length > 0;
12434
+ if (!hasValidSession) {
12435
+ clearProxyState();
12436
+ return;
12437
+ }
12438
+ const userObj = {
12439
+ uid: accountAny.uid,
12440
+ email: accountAny?.email,
12441
+ displayName: accountAny?.displayName || accountAny?.name,
12442
+ phoneNumber: accountAny?.phoneNumber,
12443
+ };
12444
+ setUser(userObj);
12445
+ setAccountData(accountResponse);
12446
+ setAccountInfo(accountResponse);
12447
+ setIsVerified(true);
12448
+ pendingVerificationRef.current = false;
12449
+ notifyAuthStateChange('CROSS_TAB_SYNC', userObj, null, accountResponse, accountResponse, true);
12450
+ }
12451
+ catch (error) {
12452
+ if (!isNetworkError(error)) {
12453
+ clearProxyState();
12454
+ }
12455
+ }
12456
+ finally {
12457
+ proxyRefreshInFlightRef.current = false;
12458
+ }
12459
+ };
12460
+ const handleFocus = () => {
12461
+ refreshProxySession().catch(() => { });
12462
+ };
12463
+ const handlePageShow = () => {
12464
+ refreshProxySession().catch(() => { });
12465
+ };
12466
+ const handleVisibilityChange = () => {
12467
+ if (document.visibilityState === 'visible') {
12468
+ refreshProxySession().catch(() => { });
12469
+ }
12470
+ };
12471
+ window.addEventListener('focus', handleFocus);
12472
+ window.addEventListener('pageshow', handlePageShow);
12473
+ document.addEventListener('visibilitychange', handleVisibilityChange);
12474
+ return () => {
12475
+ window.removeEventListener('focus', handleFocus);
12476
+ window.removeEventListener('pageshow', handlePageShow);
12477
+ document.removeEventListener('visibilitychange', handleVisibilityChange);
12478
+ };
12479
+ }, [proxyMode, notifyAuthStateChange, isNetworkError]);
12400
12480
  // Cross-tab synchronization - standalone mode only
12401
12481
  useEffect(() => {
12402
12482
  if (proxyMode)