@proveanything/smartlinks-auth-ui 0.5.9 → 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.
package/dist/index.js CHANGED
@@ -3,7 +3,6 @@
3
3
  var jsxRuntime = require('react/jsx-runtime');
4
4
  var React = require('react');
5
5
  var smartlinks = require('@proveanything/smartlinks');
6
- var http = require('@proveanything/smartlinks/dist/http');
7
6
 
8
7
  function _interopNamespaceDefault(e) {
9
8
  var n = Object.create(null);
@@ -3117,24 +3116,25 @@ function isPossiblePhoneNumber(input, options, metadata) {
3117
3116
  }
3118
3117
  }
3119
3118
 
3120
- // Old metadata (< 1.0.18) had no "possible length" data.
3119
+ // Old (legacy) metadata (< 1.0.18) had no "possible length" data.
3120
+ // So `isPossibleNumber()` function is supported only for non-legacy metadata.
3121
3121
  if (metadata.possibleLengths()) {
3122
3122
  return isPossibleNumber(input.phone || input.nationalNumber, input.country, metadata);
3123
- } else {
3124
- // There was a bug between `1.7.35` and `1.7.37` where "possible_lengths"
3125
- // were missing for "non-geographical" numbering plans.
3126
- // Just assume the number is possible in such cases:
3127
- // it's unlikely that anyone generated their custom metadata
3128
- // in that short period of time (one day).
3129
- // This code can be removed in some future major version update.
3130
- if (input.countryCallingCode && metadata.isNonGeographicCallingCode(input.countryCallingCode)) {
3131
- // "Non-geographic entities" did't have `possibleLengths`
3132
- // due to a bug in metadata generation process.
3133
- return true;
3134
- } else {
3135
- throw new Error('Missing "possibleLengths" in metadata. Perhaps the metadata has been generated before v1.0.18.');
3136
- }
3137
3123
  }
3124
+
3125
+ // There was a bug in versions from `1.7.35` to `1.7.37` of `libphonenumber-js`
3126
+ // where "possible_lengths" property was missing from "non-geographical" numbering plans' metadata.
3127
+ // After that, the bug was noticed and fixed.
3128
+ // So for versions from `1.7.35` to `1.7.37`, just assume that all "non=geotraphical" numbers are possible.
3129
+ // The reason is that the bug was noticed relatively quickly (within a day or so)
3130
+ // and it's unlikely that anyone generated their custom metadata in that short time span.
3131
+ // And if they didn't generate any custom metadata then a follow-up package update would've silently fixed the bug.
3132
+ if (input.countryCallingCode && metadata.isNonGeographicCallingCode(input.countryCallingCode)) {
3133
+ return true;
3134
+ }
3135
+
3136
+ // `isPossibleNumber()` function is not supported.
3137
+ throw new Error('Missing "possibleLengths" in metadata. Perhaps the metadata has been generated before v1.0.18.');
3138
3138
  }
3139
3139
  function isPossibleNumber(nationalNumber, country, metadata) {
3140
3140
  //, isInternational) {
@@ -11375,7 +11375,7 @@ class AuthAPI {
11375
11375
  });
11376
11376
  // Exchange authorization code for tokens via backend
11377
11377
  // Use direct HTTP call since SDK may not have this method in authKit namespace yet
11378
- return http.post(`/authkit/${this.clientId}/google-code`, {
11378
+ return smartlinks.post(`/authkit/${this.clientId}/google-code`, {
11379
11379
  code,
11380
11380
  redirectUri,
11381
11381
  });
@@ -12056,6 +12056,7 @@ collectionId, enableContactSync, enableInteractionTracking, interactionAppId, in
12056
12056
  const callbacksRef = React.useRef(new Set());
12057
12057
  const initializingRef = React.useRef(false);
12058
12058
  const pendingVerificationRef = React.useRef(false);
12059
+ const proxyRefreshInFlightRef = React.useRef(false);
12059
12060
  // Stable refs for callbacks to avoid useEffect dependency cycles
12060
12061
  const syncContactRef = React.useRef();
12061
12062
  const trackInteractionRef = React.useRef();
@@ -12253,9 +12254,9 @@ collectionId, enableContactSync, enableInteractionTracking, interactionAppId, in
12253
12254
  try {
12254
12255
  if (proxyMode) {
12255
12256
  // Check if credentials exist before making the API call
12256
- const headers = http.getApiHeaders();
12257
+ const headers = smartlinks.getApiHeaders();
12257
12258
  const hasBearer = !!headers['Authorization'];
12258
- const hasSdkProxy = http.isProxyEnabled();
12259
+ const hasSdkProxy = smartlinks.isProxyEnabled();
12259
12260
  console.log('[AuthContext] 🔍 Proxy mode init:', {
12260
12261
  hasBearer,
12261
12262
  hasSdkProxy,
@@ -12417,6 +12418,85 @@ collectionId, enableContactSync, enableInteractionTracking, interactionAppId, in
12417
12418
  window.removeEventListener('message', handleParentMessage);
12418
12419
  };
12419
12420
  }, [proxyMode, notifyAuthStateChange]);
12421
+ // In proxy mode, mobile auth often returns from WhatsApp/Google via app switching,
12422
+ // so the page stays mounted while the parent session changes underneath it.
12423
+ // Re-check account state on focus/visibility/page restore so login/logout appears
12424
+ // immediately instead of waiting for a full refresh.
12425
+ React.useEffect(() => {
12426
+ if (!proxyMode)
12427
+ return;
12428
+ const clearProxyState = () => {
12429
+ setUser(null);
12430
+ setToken(null);
12431
+ setAccountData(null);
12432
+ setAccountInfo(null);
12433
+ setContact(null);
12434
+ setContactId(null);
12435
+ setIsVerified(false);
12436
+ pendingVerificationRef.current = false;
12437
+ notifyAuthStateChange('LOGOUT', null, null, null, null, false);
12438
+ };
12439
+ const refreshProxySession = async () => {
12440
+ if (proxyRefreshInFlightRef.current)
12441
+ return;
12442
+ const headers = smartlinks.getApiHeaders();
12443
+ const hasBearer = !!headers['Authorization'];
12444
+ const hasSdkProxy = smartlinks.isProxyEnabled();
12445
+ if (!hasBearer && !hasSdkProxy) {
12446
+ clearProxyState();
12447
+ return;
12448
+ }
12449
+ proxyRefreshInFlightRef.current = true;
12450
+ try {
12451
+ const accountResponse = await smartlinks__namespace.auth.getAccount();
12452
+ const accountAny = accountResponse;
12453
+ const hasValidSession = accountAny?.uid && accountAny.uid.length > 0;
12454
+ if (!hasValidSession) {
12455
+ clearProxyState();
12456
+ return;
12457
+ }
12458
+ const userObj = {
12459
+ uid: accountAny.uid,
12460
+ email: accountAny?.email,
12461
+ displayName: accountAny?.displayName || accountAny?.name,
12462
+ phoneNumber: accountAny?.phoneNumber,
12463
+ };
12464
+ setUser(userObj);
12465
+ setAccountData(accountResponse);
12466
+ setAccountInfo(accountResponse);
12467
+ setIsVerified(true);
12468
+ pendingVerificationRef.current = false;
12469
+ notifyAuthStateChange('CROSS_TAB_SYNC', userObj, null, accountResponse, accountResponse, true);
12470
+ }
12471
+ catch (error) {
12472
+ if (!isNetworkError(error)) {
12473
+ clearProxyState();
12474
+ }
12475
+ }
12476
+ finally {
12477
+ proxyRefreshInFlightRef.current = false;
12478
+ }
12479
+ };
12480
+ const handleFocus = () => {
12481
+ refreshProxySession().catch(() => { });
12482
+ };
12483
+ const handlePageShow = () => {
12484
+ refreshProxySession().catch(() => { });
12485
+ };
12486
+ const handleVisibilityChange = () => {
12487
+ if (document.visibilityState === 'visible') {
12488
+ refreshProxySession().catch(() => { });
12489
+ }
12490
+ };
12491
+ window.addEventListener('focus', handleFocus);
12492
+ window.addEventListener('pageshow', handlePageShow);
12493
+ document.addEventListener('visibilitychange', handleVisibilityChange);
12494
+ return () => {
12495
+ window.removeEventListener('focus', handleFocus);
12496
+ window.removeEventListener('pageshow', handlePageShow);
12497
+ document.removeEventListener('visibilitychange', handleVisibilityChange);
12498
+ };
12499
+ }, [proxyMode, notifyAuthStateChange, isNetworkError]);
12420
12500
  // Cross-tab synchronization - standalone mode only
12421
12501
  React.useEffect(() => {
12422
12502
  if (proxyMode)