@swype-org/react-sdk 0.1.85 → 0.1.87

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
@@ -167,6 +167,7 @@ __export(api_exports, {
167
167
  fetchUserConfig: () => fetchUserConfig,
168
168
  registerPasskey: () => registerPasskey,
169
169
  reportActionCompletion: () => reportActionCompletion,
170
+ reportPasskeyActivity: () => reportPasskeyActivity,
170
171
  signTransfer: () => signTransfer,
171
172
  updateUserConfig: () => updateUserConfig,
172
173
  updateUserConfigBySession: () => updateUserConfigBySession
@@ -289,6 +290,17 @@ async function registerPasskey(apiBaseUrl, token, credentialId, publicKey) {
289
290
  });
290
291
  if (!res.ok) await throwApiError(res);
291
292
  }
293
+ async function reportPasskeyActivity(apiBaseUrl, token, credentialId) {
294
+ const res = await fetch(`${apiBaseUrl}/v1/users/config/passkey`, {
295
+ method: "PATCH",
296
+ headers: {
297
+ "Content-Type": "application/json",
298
+ Authorization: `Bearer ${token}`
299
+ },
300
+ body: JSON.stringify({ credentialId })
301
+ });
302
+ if (!res.ok) await throwApiError(res);
303
+ }
292
304
  async function fetchUserConfig(apiBaseUrl, token) {
293
305
  const res = await fetch(`${apiBaseUrl}/v1/users/config`, {
294
306
  headers: { Authorization: `Bearer ${token}` }
@@ -792,7 +804,12 @@ var VERIFY_POPUP_TIMEOUT_MS = 6e4;
792
804
  function findDevicePasskeyViaPopup(options) {
793
805
  return new Promise((resolve, reject) => {
794
806
  const channelId = `swype-pv-${Date.now()}-${Math.random().toString(36).slice(2)}`;
795
- const payload = { ...options, channelId };
807
+ const verificationToken = crypto.randomUUID();
808
+ const payload = {
809
+ ...options,
810
+ channelId,
811
+ verificationToken
812
+ };
796
813
  const encoded = btoa(JSON.stringify(payload));
797
814
  const popupUrl = `${window.location.origin}/passkey-verify#${encoded}`;
798
815
  const popup = window.open(popupUrl, "swype-passkey-verify");
@@ -812,7 +829,15 @@ function findDevicePasskeyViaPopup(options) {
812
829
  setTimeout(() => {
813
830
  if (!settled) {
814
831
  cleanup();
815
- resolve(null);
832
+ checkServerForVerifiedPasskey(
833
+ options.authToken,
834
+ options.apiBaseUrl,
835
+ verificationToken
836
+ ).then((credentialId) => {
837
+ resolve(credentialId);
838
+ }).catch(() => {
839
+ resolve(null);
840
+ });
816
841
  }
817
842
  }, POPUP_CLOSED_GRACE_MS);
818
843
  }
@@ -848,6 +873,17 @@ function findDevicePasskeyViaPopup(options) {
848
873
  }
849
874
  });
850
875
  }
876
+ async function checkServerForVerifiedPasskey(authToken, apiBaseUrl, verificationToken) {
877
+ if (!authToken || !apiBaseUrl) return null;
878
+ const res = await fetch(`${apiBaseUrl}/v1/users/config`, {
879
+ headers: { Authorization: `Bearer ${authToken}` }
880
+ });
881
+ if (!res.ok) return null;
882
+ const body = await res.json();
883
+ const passkeys = body.config.passkeys ?? [];
884
+ const matched = passkeys.find((p) => p.lastVerificationToken === verificationToken);
885
+ return matched?.credentialId ?? null;
886
+ }
851
887
  async function checkServerForNewPasskey(authToken, apiBaseUrl, existingCredentialIds) {
852
888
  if (!authToken || !apiBaseUrl) return null;
853
889
  const res = await fetch(`${apiBaseUrl}/v1/users/config`, {
@@ -5052,6 +5088,8 @@ function SwypePaymentInner({
5052
5088
  if (matched) {
5053
5089
  setActiveCredentialId(matched);
5054
5090
  window.localStorage.setItem(ACTIVE_CREDENTIAL_STORAGE_KEY, matched);
5091
+ reportPasskeyActivity(apiBaseUrl, token, matched).catch(() => {
5092
+ });
5055
5093
  await restoreOrDeposit(matched, token);
5056
5094
  return;
5057
5095
  }
@@ -5577,13 +5615,20 @@ function SwypePaymentInner({
5577
5615
  setVerifyingPasskeyPopup(true);
5578
5616
  setError(null);
5579
5617
  try {
5618
+ const token = await getAccessToken();
5580
5619
  const matched = await findDevicePasskeyViaPopup({
5581
5620
  credentialIds: knownCredentialIds,
5582
- rpId: resolvePasskeyRpId()
5621
+ rpId: resolvePasskeyRpId(),
5622
+ authToken: token ?? void 0,
5623
+ apiBaseUrl
5583
5624
  });
5584
5625
  if (matched) {
5585
5626
  setActiveCredentialId(matched);
5586
5627
  window.localStorage.setItem(ACTIVE_CREDENTIAL_STORAGE_KEY, matched);
5628
+ if (token) {
5629
+ reportPasskeyActivity(apiBaseUrl, token, matched).catch(() => {
5630
+ });
5631
+ }
5587
5632
  setStep("login");
5588
5633
  } else {
5589
5634
  setStep("create-passkey");
@@ -5593,7 +5638,7 @@ function SwypePaymentInner({
5593
5638
  } finally {
5594
5639
  setVerifyingPasskeyPopup(false);
5595
5640
  }
5596
- }, [knownCredentialIds]);
5641
+ }, [knownCredentialIds, getAccessToken, apiBaseUrl]);
5597
5642
  const handleSelectProvider = react.useCallback((providerId) => {
5598
5643
  setSelectedProviderId(providerId);
5599
5644
  setSelectedAccountId(null);