@swype-org/react-sdk 0.1.83 → 0.1.84

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.cjs CHANGED
@@ -716,7 +716,7 @@ function isSafari() {
716
716
  var POPUP_RESULT_TIMEOUT_MS = 12e4;
717
717
  var POPUP_CLOSED_POLL_MS = 500;
718
718
  var POPUP_CLOSED_GRACE_MS = 1e3;
719
- function createPasskeyViaPopup(options) {
719
+ function createPasskeyViaPopup(options, existingCredentialIds = []) {
720
720
  return new Promise((resolve, reject) => {
721
721
  const channelId = `swype-pk-${Date.now()}-${Math.random().toString(36).slice(2)}`;
722
722
  const payload = { ...options, channelId };
@@ -740,7 +740,19 @@ function createPasskeyViaPopup(options) {
740
740
  closedGraceTimer = setTimeout(() => {
741
741
  if (!settled) {
742
742
  cleanup();
743
- reject(new Error("Passkey setup window was closed before completing."));
743
+ checkServerForNewPasskey(
744
+ options.authToken,
745
+ options.apiBaseUrl,
746
+ existingCredentialIds
747
+ ).then((result) => {
748
+ if (result) {
749
+ resolve(result);
750
+ } else {
751
+ reject(new Error("Passkey setup window was closed before completing."));
752
+ }
753
+ }).catch(() => {
754
+ reject(new Error("Passkey setup window was closed before completing."));
755
+ });
744
756
  }
745
757
  }, POPUP_CLOSED_GRACE_MS);
746
758
  }
@@ -776,6 +788,18 @@ function createPasskeyViaPopup(options) {
776
788
  }
777
789
  });
778
790
  }
791
+ async function checkServerForNewPasskey(authToken, apiBaseUrl, existingCredentialIds) {
792
+ if (!authToken || !apiBaseUrl) return null;
793
+ const res = await fetch(`${apiBaseUrl}/v1/users/config`, {
794
+ headers: { Authorization: `Bearer ${authToken}` }
795
+ });
796
+ if (!res.ok) return null;
797
+ const body = await res.json();
798
+ const passkeys = body.config.passkeys ?? [];
799
+ const existingSet = new Set(existingCredentialIds);
800
+ const newPasskey = passkeys.find((p) => !existingSet.has(p.credentialId));
801
+ return newPasskey ?? null;
802
+ }
779
803
 
780
804
  // src/hooks.ts
781
805
  var WALLET_CLIENT_MAX_ATTEMPTS = 15;
@@ -970,7 +994,9 @@ function buildPasskeyPopupOptions(params) {
970
994
  residentKey: "preferred",
971
995
  userVerification: "required"
972
996
  },
973
- timeout: 6e4
997
+ timeout: 6e4,
998
+ authToken: params.authToken,
999
+ apiBaseUrl: params.apiBaseUrl
974
1000
  };
975
1001
  }
976
1002
  async function deviceHasPasskey(credentialId) {
@@ -4589,6 +4615,7 @@ function SwypePaymentInner({
4589
4615
  if (typeof window === "undefined") return null;
4590
4616
  return window.localStorage.getItem(ACTIVE_CREDENTIAL_STORAGE_KEY);
4591
4617
  });
4618
+ const [knownCredentialIds, setKnownCredentialIds] = react.useState([]);
4592
4619
  const [authInput, setAuthInput] = react.useState("");
4593
4620
  const [verificationTarget, setVerificationTarget] = react.useState(null);
4594
4621
  const [otpCode, setOtpCode] = react.useState("");
@@ -4878,6 +4905,7 @@ function SwypePaymentInner({
4878
4905
  setOneTapLimit(config.defaultAllowance);
4879
4906
  }
4880
4907
  const allPasskeys = config.passkeys ?? (config.passkey ? [config.passkey] : []);
4908
+ setKnownCredentialIds(allPasskeys.map((p) => p.credentialId));
4881
4909
  if (allPasskeys.length === 0) {
4882
4910
  setStep("create-passkey");
4883
4911
  return;
@@ -5394,12 +5422,18 @@ function SwypePaymentInner({
5394
5422
  setRegisteringPasskey(true);
5395
5423
  setError(null);
5396
5424
  try {
5425
+ const token = await getAccessToken();
5397
5426
  const passkeyDisplayName = user?.email?.address ?? user?.google?.name ?? user?.id ?? "Swype User";
5398
5427
  const popupOptions = buildPasskeyPopupOptions({
5399
5428
  userId: user?.id ?? "unknown",
5400
- displayName: passkeyDisplayName
5429
+ displayName: passkeyDisplayName,
5430
+ authToken: token ?? void 0,
5431
+ apiBaseUrl
5401
5432
  });
5402
- const { credentialId, publicKey } = await createPasskeyViaPopup(popupOptions);
5433
+ const { credentialId, publicKey } = await createPasskeyViaPopup(
5434
+ popupOptions,
5435
+ knownCredentialIds
5436
+ );
5403
5437
  await completePasskeyRegistration(credentialId, publicKey);
5404
5438
  } catch (err) {
5405
5439
  captureException(err);
@@ -5407,7 +5441,7 @@ function SwypePaymentInner({
5407
5441
  } finally {
5408
5442
  setRegisteringPasskey(false);
5409
5443
  }
5410
- }, [user, completePasskeyRegistration]);
5444
+ }, [user, completePasskeyRegistration, getAccessToken, apiBaseUrl, knownCredentialIds]);
5411
5445
  const handleSelectProvider = react.useCallback((providerId) => {
5412
5446
  setSelectedProviderId(providerId);
5413
5447
  setSelectedAccountId(null);