@truly-you/trulyyou-web-sdk 0.1.22 → 0.1.24
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.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/sdk/TrulyYouSDK.d.ts +5 -0
- package/dist/types.d.ts +3 -0
- package/package.json +1 -1
- package/src/sdk/TrulyYouSDK.ts +70 -2
- package/src/types.ts +3 -0
|
@@ -88,4 +88,9 @@ export declare class TrulyYouSDK {
|
|
|
88
88
|
* @param handoff - If true, probes for handoff keyId (with _handoff suffix)
|
|
89
89
|
*/
|
|
90
90
|
probeForKeyId(handoff?: boolean): Promise<string | null>;
|
|
91
|
+
/**
|
|
92
|
+
* Clear all keys (both handoff and non-handoff) from localStorage
|
|
93
|
+
* Clears from both same-origin localStorage and TrulyYou frontend's localStorage via iframe
|
|
94
|
+
*/
|
|
95
|
+
clearAllKeys(): Promise<void>;
|
|
91
96
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -23,6 +23,9 @@ export interface TrulyYouSDKConfig {
|
|
|
23
23
|
}
|
|
24
24
|
export interface FetchOptions extends RequestInit {
|
|
25
25
|
headers?: Record<string, string>;
|
|
26
|
+
onSigningStart?: () => void;
|
|
27
|
+
onSigningComplete?: () => void;
|
|
28
|
+
onRequestStart?: () => void;
|
|
26
29
|
}
|
|
27
30
|
export interface SigningResult {
|
|
28
31
|
signature: string;
|
package/package.json
CHANGED
package/src/sdk/TrulyYouSDK.ts
CHANGED
|
@@ -1888,9 +1888,19 @@ export class TrulyYouSDK {
|
|
|
1888
1888
|
throw new Error('Failed to create signature: ' + (errorData.error || 'Creation request failed'))
|
|
1889
1889
|
}
|
|
1890
1890
|
|
|
1891
|
+
// Call onSigningStart callback if provided
|
|
1892
|
+
if (options.onSigningStart) {
|
|
1893
|
+
options.onSigningStart()
|
|
1894
|
+
}
|
|
1895
|
+
|
|
1891
1896
|
// Now sign the payload (pass signatureId for desktop handoff, and keyId if we have it)
|
|
1892
1897
|
const signingResult = await this.signPayload(apiCallStructure, signatureId, keyId || undefined)
|
|
1893
1898
|
|
|
1899
|
+
// Call onSigningComplete callback if provided
|
|
1900
|
+
if (options.onSigningComplete) {
|
|
1901
|
+
options.onSigningComplete()
|
|
1902
|
+
}
|
|
1903
|
+
|
|
1894
1904
|
// Make the actual API call with signature and signatureId in header
|
|
1895
1905
|
// Use keyId from signingResult (Device B's keyId for handoff, or localStorage keyId for mobile)
|
|
1896
1906
|
const signingResultKeyId = signingResult.keyId || ''
|
|
@@ -1899,10 +1909,18 @@ export class TrulyYouSDK {
|
|
|
1899
1909
|
console.log('[SDK]: ✅ Final keyId for auth header:', keyIdForAuth, '(from', signingResultKeyId && signingResultKeyId !== '' ? 'Device B' : 'localStorage fallback', ')')
|
|
1900
1910
|
const authHeaderValue = btoa(JSON.stringify({ signature: signingResult.signature, keyId: keyIdForAuth, signatureId }))
|
|
1901
1911
|
|
|
1912
|
+
// Call onRequestStart callback if provided
|
|
1913
|
+
if (options.onRequestStart) {
|
|
1914
|
+
options.onRequestStart()
|
|
1915
|
+
}
|
|
1916
|
+
|
|
1917
|
+
// Extract callback options to avoid passing them to fetch
|
|
1918
|
+
const { onSigningStart, onSigningComplete, onRequestStart, ...fetchOptions } = options
|
|
1919
|
+
|
|
1902
1920
|
const response = await fetch(url, {
|
|
1903
|
-
...
|
|
1921
|
+
...fetchOptions,
|
|
1904
1922
|
headers: {
|
|
1905
|
-
...
|
|
1923
|
+
...fetchOptions.headers,
|
|
1906
1924
|
'x-truly-auth': authHeaderValue
|
|
1907
1925
|
}
|
|
1908
1926
|
})
|
|
@@ -1969,5 +1987,55 @@ export class TrulyYouSDK {
|
|
|
1969
1987
|
console.log(`[SDK-PROBE]: ${handoff ? 'Handoff ' : ''}KeyId not found in same-origin localStorage, probing TrulyYou frontend...`)
|
|
1970
1988
|
return await this.probeIframeForKey(handoff)
|
|
1971
1989
|
}
|
|
1990
|
+
|
|
1991
|
+
/**
|
|
1992
|
+
* Clear all keys (both handoff and non-handoff) from localStorage
|
|
1993
|
+
* Clears from both same-origin localStorage and TrulyYou frontend's localStorage via iframe
|
|
1994
|
+
*/
|
|
1995
|
+
async clearAllKeys(): Promise<void> {
|
|
1996
|
+
// Ensure authFlowId is loaded first
|
|
1997
|
+
await this.ensureAuthFlowIdLoaded()
|
|
1998
|
+
|
|
1999
|
+
if (!this.brandingCache?.authFlowId) {
|
|
2000
|
+
console.warn('[SDK-CLEAR]: authFlowId is required but not available')
|
|
2001
|
+
return
|
|
2002
|
+
}
|
|
2003
|
+
|
|
2004
|
+
const authFlowId = this.brandingCache.authFlowId
|
|
2005
|
+
|
|
2006
|
+
// Clear from same-origin localStorage
|
|
2007
|
+
if (typeof window !== 'undefined') {
|
|
2008
|
+
const regularKey = `trulyYouKeyId_${authFlowId}`
|
|
2009
|
+
const handoffKey = `trulyYouKeyId_${authFlowId}_handoff`
|
|
2010
|
+
|
|
2011
|
+
localStorage.removeItem(regularKey)
|
|
2012
|
+
localStorage.removeItem(handoffKey)
|
|
2013
|
+
|
|
2014
|
+
console.log('[SDK-CLEAR]: ✅ Cleared keys from same-origin localStorage:', regularKey, handoffKey)
|
|
2015
|
+
}
|
|
2016
|
+
|
|
2017
|
+
// Also clear from TrulyYou frontend's localStorage via iframe
|
|
2018
|
+
try {
|
|
2019
|
+
const iframe = document.createElement('iframe')
|
|
2020
|
+
iframe.style.cssText = 'position: fixed; top: -9999px; left: -9999px; width: 1px; height: 1px; border: none; opacity: 0; pointer-events: none;'
|
|
2021
|
+
|
|
2022
|
+
const clearUrl = new URL(`${this.frontendUrl}/clear-keys.html`)
|
|
2023
|
+
clearUrl.searchParams.set('authFlowId', authFlowId)
|
|
2024
|
+
|
|
2025
|
+
iframe.src = clearUrl.toString()
|
|
2026
|
+
document.body.appendChild(iframe)
|
|
2027
|
+
|
|
2028
|
+
// Clean up after a delay
|
|
2029
|
+
setTimeout(() => {
|
|
2030
|
+
if (iframe.parentNode) {
|
|
2031
|
+
iframe.parentNode.removeChild(iframe)
|
|
2032
|
+
}
|
|
2033
|
+
}, 2000)
|
|
2034
|
+
|
|
2035
|
+
console.log('[SDK-CLEAR]: ✅ Cleared keys from TrulyYou frontend localStorage via iframe')
|
|
2036
|
+
} catch (error) {
|
|
2037
|
+
console.warn('[SDK-CLEAR]: Failed to clear keys from TrulyYou frontend localStorage:', error)
|
|
2038
|
+
}
|
|
2039
|
+
}
|
|
1972
2040
|
}
|
|
1973
2041
|
|
package/src/types.ts
CHANGED
|
@@ -24,6 +24,9 @@ export interface TrulyYouSDKConfig {
|
|
|
24
24
|
|
|
25
25
|
export interface FetchOptions extends RequestInit {
|
|
26
26
|
headers?: Record<string, string>
|
|
27
|
+
onSigningStart?: () => void
|
|
28
|
+
onSigningComplete?: () => void
|
|
29
|
+
onRequestStart?: () => void
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
export interface SigningResult {
|