@truly-you/trulyyou-web-sdk 0.1.18 → 0.1.20

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.
@@ -52,6 +52,7 @@ export declare class TrulyYouSDK {
52
52
  * Probe iframe to check if key exists in iframe's localStorage
53
53
  * Also checks backend to verify key exists and is active
54
54
  * REQUIRES authFlowId to be loaded first
55
+ * @param handoff - If true, probes for handoff keyId (with _handoff suffix)
55
56
  */
56
57
  private probeIframeForKey;
57
58
  /**
@@ -81,4 +82,10 @@ export declare class TrulyYouSDK {
81
82
  * Fetch with automatic payload signing
82
83
  */
83
84
  fetchWithSignature(url: string, options?: FetchOptions): Promise<FetchResult>;
85
+ /**
86
+ * Public method to probe for keyId - checks localStorage first, then probes TrulyYou frontend via iframe
87
+ * Returns the keyId if found, null otherwise
88
+ * @param handoff - If true, probes for handoff keyId (with _handoff suffix)
89
+ */
90
+ probeForKeyId(handoff?: boolean): Promise<string | null>;
84
91
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@truly-you/trulyyou-web-sdk",
3
- "version": "0.1.18",
3
+ "version": "0.1.20",
4
4
  "description": "TrulyYou Web SDK for secure authentication and payload signing",
5
5
  "type": "module",
6
6
  "main": "dist/index.esm.js",
@@ -308,8 +308,9 @@ export class TrulyYouSDK {
308
308
  * Probe iframe to check if key exists in iframe's localStorage
309
309
  * Also checks backend to verify key exists and is active
310
310
  * REQUIRES authFlowId to be loaded first
311
+ * @param handoff - If true, probes for handoff keyId (with _handoff suffix)
311
312
  */
312
- private async probeIframeForKey(): Promise<string | null> {
313
+ private async probeIframeForKey(handoff: boolean = false): Promise<string | null> {
313
314
  // Ensure authFlowId is loaded before probing
314
315
  await this.ensureAuthFlowIdLoaded()
315
316
 
@@ -332,7 +333,10 @@ export class TrulyYouSDK {
332
333
  // Add authFlowId (guaranteed to exist now after ensureAuthFlowIdLoaded)
333
334
  const authFlowId = this.brandingCache!.authFlowId!
334
335
  probeUrl.searchParams.set('authFlowId', authFlowId)
335
- console.log('[SDK-PROBE]: Adding authFlowId to probe:', authFlowId)
336
+ if (handoff) {
337
+ probeUrl.searchParams.set('handoff', 'true')
338
+ }
339
+ console.log(`[SDK-PROBE]: Adding authFlowId to probe: ${authFlowId}${handoff ? ' (handoff)' : ''}`)
336
340
 
337
341
  iframe.src = probeUrl.toString()
338
342
 
@@ -1884,5 +1888,35 @@ export class TrulyYouSDK {
1884
1888
  throw error
1885
1889
  }
1886
1890
  }
1891
+
1892
+ /**
1893
+ * Public method to probe for keyId - checks localStorage first, then probes TrulyYou frontend via iframe
1894
+ * Returns the keyId if found, null otherwise
1895
+ * @param handoff - If true, probes for handoff keyId (with _handoff suffix)
1896
+ */
1897
+ async probeForKeyId(handoff: boolean = false): Promise<string | null> {
1898
+ // Ensure authFlowId is loaded first
1899
+ await this.ensureAuthFlowIdLoaded()
1900
+
1901
+ if (!this.brandingCache?.authFlowId) {
1902
+ console.warn('[SDK-PROBE]: authFlowId is required but not available')
1903
+ return null
1904
+ }
1905
+
1906
+ const authFlowId = this.brandingCache.authFlowId
1907
+
1908
+ // First, check localStorage (same origin - this app's localStorage)
1909
+ const storageKey = handoff ? `trulyYouKeyId_${authFlowId}_handoff` : `trulyYouKeyId_${authFlowId}`
1910
+ const keyIdFromStorage = typeof window !== 'undefined' ? localStorage.getItem(storageKey) : null
1911
+
1912
+ if (keyIdFromStorage) {
1913
+ console.log(`[SDK-PROBE]: Found ${handoff ? 'handoff ' : ''}keyId in same-origin localStorage`)
1914
+ return keyIdFromStorage
1915
+ }
1916
+
1917
+ // If not found in same-origin localStorage, probe TrulyYou frontend's localStorage via iframe
1918
+ console.log(`[SDK-PROBE]: ${handoff ? 'Handoff ' : ''}KeyId not found in same-origin localStorage, probing TrulyYou frontend...`)
1919
+ return await this.probeIframeForKey(handoff)
1920
+ }
1887
1921
  }
1888
1922