@stacksjs/composables 0.75.227 → 0.75.229
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.d.ts +3 -0
- package/dist/index.js +1 -1
- package/dist/session-handoff.d.ts +16 -1
- package/dist/session-handoff.js +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -276,10 +276,13 @@ export { watchThrottled as throttledWatch } from './watchThrottled';
|
|
|
276
276
|
// redirect) and @stacksjs/browser (which consumes it), so the storage format
|
|
277
277
|
// is never re-derived by an application.
|
|
278
278
|
export {
|
|
279
|
+
buildSessionHandoffCodeUrl,
|
|
279
280
|
buildSessionHandoffUrl,
|
|
280
281
|
decodeSessionHandoff,
|
|
281
282
|
encodeSessionHandoff,
|
|
282
283
|
readSessionHandoff,
|
|
284
|
+
readSessionHandoffCode,
|
|
285
|
+
SESSION_HANDOFF_CODE_KEY,
|
|
283
286
|
SESSION_HANDOFF_KEY,
|
|
284
287
|
stripSessionHandoff,
|
|
285
288
|
type SessionHandoffPack,
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{defaultDocument,defaultNavigator,defaultWindow,isRef,noop,toValue,unref}from"./_shared";export{getSSRHandler,setSSRHandler,customStorageEventName}from"./ssrHandlers";export{useStorage}from"./useStorage";export{useLocalStorage}from"./useLocalStorage";export{useSessionStorage}from"./useSessionStorage";export{useDark,usePreferredDark}from"./useDark";export{useColorMode}from"./useColorMode";export{usePreferredColorScheme}from"./usePreferredColorScheme";export{usePreferredContrast}from"./usePreferredContrast";export{usePreferredReducedMotion}from"./usePreferredReducedMotion";export{useOnline}from"./useOnline";export{useNetwork}from"./useNetwork";export{useToggle}from"./useToggle";export{useFetch}from"./useFetch";export{createFetch}from"./createFetch";export{createQueryClient,queryClient,useMutation,useQuery}from"./useQuery";export{emptyCategories,OPTIONAL_CATEGORIES,parseDecision,useCookieConsent}from"./useCookieConsent";export{useForm}from"./useForm";export{useDateFormat}from"./useDateFormat";export{useNow}from"./useNow";export{useTimestamp}from"./useTimestamp";export{useTimeAgo}from"./useTimeAgo";export{useEventListener}from"./useEventListener";export{useEventBus}from"./useEventBus";export{createEventHook}from"./createEventHook";export{useDebounceFn}from"./useDebounceFn";export{useThrottleFn}from"./useThrottleFn";export{useDebouncedRef}from"./useDebouncedRef";export{useThrottledRef}from"./useThrottledRef";export{useDebounce}from"./useDebounce";export{useThrottle}from"./useThrottle";export{useInterval}from"./useInterval";export{useIntervalFn}from"./useIntervalFn";export{useTimeout}from"./useTimeout";export{useTimeoutFn}from"./useTimeoutFn";export{useTimeoutPoll}from"./useTimeoutPoll";export{useRafFn}from"./useRafFn";export{useFps}from"./useFps";export{useClipboard}from"./useClipboard";export{useClipboardItems}from"./useClipboardItems";export{useMediaQuery}from"./useMediaQuery";export{breakpointsAntDesign,breakpointsBootstrap,breakpointsBootstrapV5,breakpointsMasterCss,breakpointsQuasar,breakpointsSematic,breakpointsTailwind,breakpointsMaterialDesign,useBreakpoints}from"./useBreakpoints";export{useTitle}from"./useTitle";export{useFavicon}from"./useFavicon";export{useDocumentVisibility}from"./useDocumentVisibility";export{useTextDirection}from"./useTextDirection";export{useTextSelection}from"./useTextSelection";export{useUrlSearchParams}from"./useUrlSearchParams";export{useBrowserLocation}from"./useBrowserLocation";export{useWindowSize}from"./useWindowSize";export{useWindowFocus}from"./useWindowFocus";export{useWindowScroll}from"./useWindowScroll";export{useScroll}from"./useScroll";export{useScrollLock}from"./useScrollLock";export{useInfiniteScroll}from"./useInfiniteScroll";export{useFullscreen}from"./useFullscreen";export{onClickOutside}from"./onClickOutside";export{onKeyStroke,onKeyDown,onKeyUp}from"./onKeyStroke";export{onLongPress}from"./onLongPress";export{onStartTyping}from"./onStartTyping";export{useKeyModifier}from"./useKeyModifier";export{useMagicKeys}from"./useMagicKeys";export{and,logicNot,logicOr,or,useAbs,useAverage,useCeil,useClamp,useFloor,useMax,useMin,usePrecision,useRound,useSum,useTrunc}from"./useMath";export{useCounter}from"./useCounter";export{usePrevious}from"./usePrevious";export{useLastChanged}from"./useLastChanged";export{useStepper}from"./useStepper";export{useCycleList}from"./useCycleList";export{useSorted}from"./useSorted";export{useCloned}from"./useCloned";export{useManualRefHistory}from"./useManualRefHistory";export{useRefHistory}from"./useRefHistory";export{useDebouncedRefHistory}from"./useDebouncedRefHistory";export{useThrottledRefHistory}from"./useThrottledRefHistory";export{useAsyncState}from"./useAsyncState";export{useAsyncQueue}from"./useAsyncQueue";export{whenever}from"./whenever";export{watchOnce}from"./watchOnce";export{watchDebounced}from"./watchDebounced";export{watchThrottled}from"./watchThrottled";export{watchPausable,pausableWatch}from"./watchPausable";export{watchIgnorable,ignorableWatch}from"./watchIgnorable";export{watchArray}from"./watchArray";export{watchAtMost}from"./watchAtMost";export{watchDeep}from"./watchDeep";export{watchImmediate}from"./watchImmediate";export{watchTriggerable}from"./watchTriggerable";export{watchWithFilter}from"./watchWithFilter";export{useWebSocket}from"./useWebSocket";export{useEventSource}from"./useEventSource";export{useBroadcastChannel}from"./useBroadcastChannel";export{computedAsync}from"./computedAsync";export{computedEager}from"./computedEager";export{useIntersectionObserver}from"./useIntersectionObserver";export{useResizeObserver}from"./useResizeObserver";export{useMutationObserver}from"./useMutationObserver";export{useElementSize}from"./useElementSize";export{useElementBounding}from"./useElementBounding";export{useElementVisibility}from"./useElementVisibility";export{useElementHover}from"./useElementHover";export{useElementByPoint}from"./useElementByPoint";export{useCssVar}from"./useCssVar";export{unrefElement}from"./unrefElement";export{useMouse}from"./useMouse";export{useMouseInElement}from"./useMouseInElement";export{useMousePressed}from"./useMousePressed";export{usePointer}from"./usePointer";export{useSwipe}from"./useSwipe";export{usePointerSwipe}from"./usePointerSwipe";export{usePointerLock}from"./usePointerLock";export{useParallax}from"./useParallax";export{useGeolocation}from"./useGeolocation";export{useDeviceMotion}from"./useDeviceMotion";export{useDeviceOrientation}from"./useDeviceOrientation";export{useDevicePixelRatio}from"./useDevicePixelRatio";export{useBattery}from"./useBattery";export{useFocus}from"./useFocus";export{useFocusWithin}from"./useFocusWithin";export{useActiveElement}from"./useActiveElement";export{useIdle}from"./useIdle";export{usePageLeave}from"./usePageLeave";export{useMounted}from"./useMounted";export{useDraggable}from"./useDraggable";export{useDropZone}from"./useDropZone";export{useNavigatorLanguage}from"./useNavigatorLanguage";export{usePreferredLanguages}from"./usePreferredLanguages";export{useScreenOrientation}from"./useScreenOrientation";export{useScreenSafeArea}from"./useScreenSafeArea";export{useParentElement}from"./useParentElement";export{usePermission}from"./usePermission";export{useShare}from"./useShare";export{useObjectUrl}from"./useObjectUrl";export{useImage}from"./useImage";export{useBase64}from"./useBase64";export{useAnimate}from"./useAnimate";export{useTransition,executeTransition,TransitionPresets}from"./useTransition";export{useScriptTag}from"./useScriptTag";export{useStyleTag}from"./useStyleTag";export{useConfirmDialog}from"./useConfirmDialog";export{useFileDialog}from"./useFileDialog";export{useEyeDropper}from"./useEyeDropper";export{useTextareaAutosize}from"./useTextareaAutosize";export{useWebNotification}from"./useWebNotification";export{useVibrate}from"./useVibrate";export{useWakeLock}from"./useWakeLock";export{useWebWorker,useWebWorkerFn}from"./useWebWorker";export{useVirtualList}from"./useVirtualList";export{useOffsetPagination}from"./useOffsetPagination";export{isDefined}from"./isDefined";export{useSupported}from"./useSupported";export{useToNumber}from"./useToNumber";export{useToString}from"./useToString";export{refDefault}from"./refDefault";export{refAutoReset,autoResetRef}from"./refAutoReset";export{cloneFnJSON}from"./cloneFnJSON";export{formatTimeAgo}from"./formatTimeAgo";export{until}from"./until";export{resolveRef}from"./resolveRef";export{extendRef}from"./extendRef";export{useMemoize}from"./useMemoize";export{makeDestructurable}from"./makeDestructurable";export{syncRef,syncRefs}from"./syncRef";export{createGlobalState}from"./createGlobalState";export{createSharedComposable}from"./createSharedComposable";export{tryOnMounted,tryOnBeforeMount,tryOnUnmounted,tryOnBeforeUnmount,tryOnScopeDispose}from"./tryOnMounted";export{useArrayDifference,useArrayEvery,useArrayFilter,useArrayFind,useArrayFindIndex,useArrayIncludes,useArrayMap,useArrayReduce,useArraySome,useArrayUnique}from"./useArrayUtils";export{computedAsync as asyncComputed}from"./computedAsync";export{computedEager as eagerComputed}from"./computedEager";export{useDebouncedRef as debouncedRef}from"./useDebouncedRef";export{useDebouncedRef as refDebounced}from"./useDebouncedRef";export{useThrottledRef as throttledRef}from"./useThrottledRef";export{useThrottledRef as refThrottled}from"./useThrottledRef";export{watchDebounced as debouncedWatch}from"./watchDebounced";export{watchThrottled as throttledWatch}from"./watchThrottled";export{buildSessionHandoffUrl,decodeSessionHandoff,encodeSessionHandoff,readSessionHandoff,SESSION_HANDOFF_KEY,stripSessionHandoff}from"./session-handoff";
|
|
1
|
+
export{defaultDocument,defaultNavigator,defaultWindow,isRef,noop,toValue,unref}from"./_shared";export{getSSRHandler,setSSRHandler,customStorageEventName}from"./ssrHandlers";export{useStorage}from"./useStorage";export{useLocalStorage}from"./useLocalStorage";export{useSessionStorage}from"./useSessionStorage";export{useDark,usePreferredDark}from"./useDark";export{useColorMode}from"./useColorMode";export{usePreferredColorScheme}from"./usePreferredColorScheme";export{usePreferredContrast}from"./usePreferredContrast";export{usePreferredReducedMotion}from"./usePreferredReducedMotion";export{useOnline}from"./useOnline";export{useNetwork}from"./useNetwork";export{useToggle}from"./useToggle";export{useFetch}from"./useFetch";export{createFetch}from"./createFetch";export{createQueryClient,queryClient,useMutation,useQuery}from"./useQuery";export{emptyCategories,OPTIONAL_CATEGORIES,parseDecision,useCookieConsent}from"./useCookieConsent";export{useForm}from"./useForm";export{useDateFormat}from"./useDateFormat";export{useNow}from"./useNow";export{useTimestamp}from"./useTimestamp";export{useTimeAgo}from"./useTimeAgo";export{useEventListener}from"./useEventListener";export{useEventBus}from"./useEventBus";export{createEventHook}from"./createEventHook";export{useDebounceFn}from"./useDebounceFn";export{useThrottleFn}from"./useThrottleFn";export{useDebouncedRef}from"./useDebouncedRef";export{useThrottledRef}from"./useThrottledRef";export{useDebounce}from"./useDebounce";export{useThrottle}from"./useThrottle";export{useInterval}from"./useInterval";export{useIntervalFn}from"./useIntervalFn";export{useTimeout}from"./useTimeout";export{useTimeoutFn}from"./useTimeoutFn";export{useTimeoutPoll}from"./useTimeoutPoll";export{useRafFn}from"./useRafFn";export{useFps}from"./useFps";export{useClipboard}from"./useClipboard";export{useClipboardItems}from"./useClipboardItems";export{useMediaQuery}from"./useMediaQuery";export{breakpointsAntDesign,breakpointsBootstrap,breakpointsBootstrapV5,breakpointsMasterCss,breakpointsQuasar,breakpointsSematic,breakpointsTailwind,breakpointsMaterialDesign,useBreakpoints}from"./useBreakpoints";export{useTitle}from"./useTitle";export{useFavicon}from"./useFavicon";export{useDocumentVisibility}from"./useDocumentVisibility";export{useTextDirection}from"./useTextDirection";export{useTextSelection}from"./useTextSelection";export{useUrlSearchParams}from"./useUrlSearchParams";export{useBrowserLocation}from"./useBrowserLocation";export{useWindowSize}from"./useWindowSize";export{useWindowFocus}from"./useWindowFocus";export{useWindowScroll}from"./useWindowScroll";export{useScroll}from"./useScroll";export{useScrollLock}from"./useScrollLock";export{useInfiniteScroll}from"./useInfiniteScroll";export{useFullscreen}from"./useFullscreen";export{onClickOutside}from"./onClickOutside";export{onKeyStroke,onKeyDown,onKeyUp}from"./onKeyStroke";export{onLongPress}from"./onLongPress";export{onStartTyping}from"./onStartTyping";export{useKeyModifier}from"./useKeyModifier";export{useMagicKeys}from"./useMagicKeys";export{and,logicNot,logicOr,or,useAbs,useAverage,useCeil,useClamp,useFloor,useMax,useMin,usePrecision,useRound,useSum,useTrunc}from"./useMath";export{useCounter}from"./useCounter";export{usePrevious}from"./usePrevious";export{useLastChanged}from"./useLastChanged";export{useStepper}from"./useStepper";export{useCycleList}from"./useCycleList";export{useSorted}from"./useSorted";export{useCloned}from"./useCloned";export{useManualRefHistory}from"./useManualRefHistory";export{useRefHistory}from"./useRefHistory";export{useDebouncedRefHistory}from"./useDebouncedRefHistory";export{useThrottledRefHistory}from"./useThrottledRefHistory";export{useAsyncState}from"./useAsyncState";export{useAsyncQueue}from"./useAsyncQueue";export{whenever}from"./whenever";export{watchOnce}from"./watchOnce";export{watchDebounced}from"./watchDebounced";export{watchThrottled}from"./watchThrottled";export{watchPausable,pausableWatch}from"./watchPausable";export{watchIgnorable,ignorableWatch}from"./watchIgnorable";export{watchArray}from"./watchArray";export{watchAtMost}from"./watchAtMost";export{watchDeep}from"./watchDeep";export{watchImmediate}from"./watchImmediate";export{watchTriggerable}from"./watchTriggerable";export{watchWithFilter}from"./watchWithFilter";export{useWebSocket}from"./useWebSocket";export{useEventSource}from"./useEventSource";export{useBroadcastChannel}from"./useBroadcastChannel";export{computedAsync}from"./computedAsync";export{computedEager}from"./computedEager";export{useIntersectionObserver}from"./useIntersectionObserver";export{useResizeObserver}from"./useResizeObserver";export{useMutationObserver}from"./useMutationObserver";export{useElementSize}from"./useElementSize";export{useElementBounding}from"./useElementBounding";export{useElementVisibility}from"./useElementVisibility";export{useElementHover}from"./useElementHover";export{useElementByPoint}from"./useElementByPoint";export{useCssVar}from"./useCssVar";export{unrefElement}from"./unrefElement";export{useMouse}from"./useMouse";export{useMouseInElement}from"./useMouseInElement";export{useMousePressed}from"./useMousePressed";export{usePointer}from"./usePointer";export{useSwipe}from"./useSwipe";export{usePointerSwipe}from"./usePointerSwipe";export{usePointerLock}from"./usePointerLock";export{useParallax}from"./useParallax";export{useGeolocation}from"./useGeolocation";export{useDeviceMotion}from"./useDeviceMotion";export{useDeviceOrientation}from"./useDeviceOrientation";export{useDevicePixelRatio}from"./useDevicePixelRatio";export{useBattery}from"./useBattery";export{useFocus}from"./useFocus";export{useFocusWithin}from"./useFocusWithin";export{useActiveElement}from"./useActiveElement";export{useIdle}from"./useIdle";export{usePageLeave}from"./usePageLeave";export{useMounted}from"./useMounted";export{useDraggable}from"./useDraggable";export{useDropZone}from"./useDropZone";export{useNavigatorLanguage}from"./useNavigatorLanguage";export{usePreferredLanguages}from"./usePreferredLanguages";export{useScreenOrientation}from"./useScreenOrientation";export{useScreenSafeArea}from"./useScreenSafeArea";export{useParentElement}from"./useParentElement";export{usePermission}from"./usePermission";export{useShare}from"./useShare";export{useObjectUrl}from"./useObjectUrl";export{useImage}from"./useImage";export{useBase64}from"./useBase64";export{useAnimate}from"./useAnimate";export{useTransition,executeTransition,TransitionPresets}from"./useTransition";export{useScriptTag}from"./useScriptTag";export{useStyleTag}from"./useStyleTag";export{useConfirmDialog}from"./useConfirmDialog";export{useFileDialog}from"./useFileDialog";export{useEyeDropper}from"./useEyeDropper";export{useTextareaAutosize}from"./useTextareaAutosize";export{useWebNotification}from"./useWebNotification";export{useVibrate}from"./useVibrate";export{useWakeLock}from"./useWakeLock";export{useWebWorker,useWebWorkerFn}from"./useWebWorker";export{useVirtualList}from"./useVirtualList";export{useOffsetPagination}from"./useOffsetPagination";export{isDefined}from"./isDefined";export{useSupported}from"./useSupported";export{useToNumber}from"./useToNumber";export{useToString}from"./useToString";export{refDefault}from"./refDefault";export{refAutoReset,autoResetRef}from"./refAutoReset";export{cloneFnJSON}from"./cloneFnJSON";export{formatTimeAgo}from"./formatTimeAgo";export{until}from"./until";export{resolveRef}from"./resolveRef";export{extendRef}from"./extendRef";export{useMemoize}from"./useMemoize";export{makeDestructurable}from"./makeDestructurable";export{syncRef,syncRefs}from"./syncRef";export{createGlobalState}from"./createGlobalState";export{createSharedComposable}from"./createSharedComposable";export{tryOnMounted,tryOnBeforeMount,tryOnUnmounted,tryOnBeforeUnmount,tryOnScopeDispose}from"./tryOnMounted";export{useArrayDifference,useArrayEvery,useArrayFilter,useArrayFind,useArrayFindIndex,useArrayIncludes,useArrayMap,useArrayReduce,useArraySome,useArrayUnique}from"./useArrayUtils";export{computedAsync as asyncComputed}from"./computedAsync";export{computedEager as eagerComputed}from"./computedEager";export{useDebouncedRef as debouncedRef}from"./useDebouncedRef";export{useDebouncedRef as refDebounced}from"./useDebouncedRef";export{useThrottledRef as throttledRef}from"./useThrottledRef";export{useThrottledRef as refThrottled}from"./useThrottledRef";export{watchDebounced as debouncedWatch}from"./watchDebounced";export{watchThrottled as throttledWatch}from"./watchThrottled";export{buildSessionHandoffCodeUrl,buildSessionHandoffUrl,decodeSessionHandoff,encodeSessionHandoff,readSessionHandoff,readSessionHandoffCode,SESSION_HANDOFF_CODE_KEY,SESSION_HANDOFF_KEY,stripSessionHandoff}from"./session-handoff";
|
|
@@ -17,8 +17,12 @@ export declare function decodeSessionHandoff(value: string | null | undefined):
|
|
|
17
17
|
export declare function buildSessionHandoffUrl(redirectTo: string, pack: SessionHandoffPack): string;
|
|
18
18
|
/** Pull the handoff out of a `location.hash`-shaped string. */
|
|
19
19
|
export declare function readSessionHandoff(hash: string | null | undefined): SessionHandoffPack | null;
|
|
20
|
+
/** Append a one-use handoff code to a redirect target, preserving any existing fragment. */
|
|
21
|
+
export declare function buildSessionHandoffCodeUrl(redirectTo: string, code: string): string;
|
|
22
|
+
/** The handoff code in a `location.hash`-shaped string, or null. Never throws. */
|
|
23
|
+
export declare function readSessionHandoffCode(hash: string | null | undefined): string | null;
|
|
20
24
|
/**
|
|
21
|
-
* The same hash with the handoff removed, ready for `history.replaceState`.
|
|
25
|
+
* The same hash with the handoff (pack or code) removed, ready for `history.replaceState`.
|
|
22
26
|
*
|
|
23
27
|
* Returns '' when nothing else was in it, so the caller can drop the `#`
|
|
24
28
|
* entirely rather than leaving a bare one in the address bar.
|
|
@@ -55,6 +59,17 @@ export declare function stripSessionHandoff(hash: string | null | undefined): st
|
|
|
55
59
|
*/
|
|
56
60
|
/** The fragment key the handoff travels under. */
|
|
57
61
|
export declare const SESSION_HANDOFF_KEY: 'stx_auth';
|
|
62
|
+
/**
|
|
63
|
+
* The fragment key a one-use handoff CODE travels under.
|
|
64
|
+
*
|
|
65
|
+
* This is the stronger design the note above describes, and the one the
|
|
66
|
+
* framework's own social callback uses: the fragment carries a 60-second,
|
|
67
|
+
* single-use code bound to the browser's cookie (or to a verifier a native
|
|
68
|
+
* app holds), never a bearer token. The page POSTs it to `/auth/handoff`,
|
|
69
|
+
* which answers with the session. A code read from history, a log or a
|
|
70
|
+
* screenshot is already spent or expired, and useless in any other browser.
|
|
71
|
+
*/
|
|
72
|
+
export declare const SESSION_HANDOFF_CODE_KEY: 'stx_handoff';
|
|
58
73
|
export declare interface SessionHandoffPack {
|
|
59
74
|
token: string
|
|
60
75
|
refreshToken?: string
|
package/dist/session-handoff.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SESSION_HANDOFF_KEY="stx_auth";function toBase64Url(input){const bytes=new TextEncoder().encode(input);let binary="";for(const byte of bytes)binary+=String.fromCharCode(byte);return btoa(binary).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function fromBase64Url(input){const padded=input.replace(/-/g,"+").replace(/_/g,"/")+"=".repeat((4-input.length%4)%4),binary=atob(padded),bytes=new Uint8Array(binary.length);for(let i=0;i<binary.length;i++)bytes[i]=binary.charCodeAt(i);return new TextDecoder().decode(bytes)}export function encodeSessionHandoff(pack){return toBase64Url(JSON.stringify({token:pack.token,refresh_token:pack.refreshToken,user:pack.user,expires_in:pack.expiresIn}))}export function decodeSessionHandoff(value){if(!value)return null;try{const parsed=JSON.parse(fromBase64Url(value)),token=parsed.token??parsed.access_token;if(typeof token!=="string"||token.length===0)return null;return{token,refreshToken:typeof parsed.refresh_token==="string"?parsed.refresh_token:void 0,user:parsed.user,expiresIn:typeof parsed.expires_in==="number"?parsed.expires_in:void 0}}catch{return null}}export function buildSessionHandoffUrl(redirectTo,pack){const encoded=encodeSessionHandoff(pack),[base,existingHash]=splitHash(redirectTo),prefix=existingHash?`${existingHash}&`:"";return`${base}#${prefix}${SESSION_HANDOFF_KEY}=${encoded}`}export function readSessionHandoff(hash){if(!hash)return null;const params=new URLSearchParams(hash.startsWith("#")?hash.slice(1):hash);return decodeSessionHandoff(params.get(SESSION_HANDOFF_KEY))}export function stripSessionHandoff(hash){if(!hash)return"";const params=new URLSearchParams(hash.startsWith("#")?hash.slice(1):hash);params.delete(SESSION_HANDOFF_KEY);const rest=params.toString();return rest?`#${rest}`:""}function splitHash(url){const at=url.indexOf("#");return at===-1?[url,""]:[url.slice(0,at),url.slice(at+1)]}
|
|
1
|
+
export const SESSION_HANDOFF_KEY="stx_auth",SESSION_HANDOFF_CODE_KEY="stx_handoff";const HANDOFF_CODE_SHAPE=/^[a-f0-9]{64}$/;function toBase64Url(input){const bytes=new TextEncoder().encode(input);let binary="";for(const byte of bytes)binary+=String.fromCharCode(byte);return btoa(binary).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function fromBase64Url(input){const padded=input.replace(/-/g,"+").replace(/_/g,"/")+"=".repeat((4-input.length%4)%4),binary=atob(padded),bytes=new Uint8Array(binary.length);for(let i=0;i<binary.length;i++)bytes[i]=binary.charCodeAt(i);return new TextDecoder().decode(bytes)}export function encodeSessionHandoff(pack){return toBase64Url(JSON.stringify({token:pack.token,refresh_token:pack.refreshToken,user:pack.user,expires_in:pack.expiresIn}))}export function decodeSessionHandoff(value){if(!value)return null;try{const parsed=JSON.parse(fromBase64Url(value)),token=parsed.token??parsed.access_token;if(typeof token!=="string"||token.length===0)return null;return{token,refreshToken:typeof parsed.refresh_token==="string"?parsed.refresh_token:void 0,user:parsed.user,expiresIn:typeof parsed.expires_in==="number"?parsed.expires_in:void 0}}catch{return null}}export function buildSessionHandoffUrl(redirectTo,pack){const encoded=encodeSessionHandoff(pack),[base,existingHash]=splitHash(redirectTo),prefix=existingHash?`${existingHash}&`:"";return`${base}#${prefix}${SESSION_HANDOFF_KEY}=${encoded}`}export function readSessionHandoff(hash){if(!hash)return null;const params=new URLSearchParams(hash.startsWith("#")?hash.slice(1):hash);return decodeSessionHandoff(params.get(SESSION_HANDOFF_KEY))}export function buildSessionHandoffCodeUrl(redirectTo,code){if(!HANDOFF_CODE_SHAPE.test(code))throw TypeError("A session handoff code is 64 lowercase hex characters.");const[base,existingHash]=splitHash(redirectTo),prefix=existingHash?`${existingHash}&`:"";return`${base}#${prefix}${SESSION_HANDOFF_CODE_KEY}=${code}`}export function readSessionHandoffCode(hash){if(!hash)return null;const code=new URLSearchParams(hash.startsWith("#")?hash.slice(1):hash).get(SESSION_HANDOFF_CODE_KEY);return code&&HANDOFF_CODE_SHAPE.test(code)?code:null}export function stripSessionHandoff(hash){if(!hash)return"";const params=new URLSearchParams(hash.startsWith("#")?hash.slice(1):hash);params.delete(SESSION_HANDOFF_KEY);params.delete(SESSION_HANDOFF_CODE_KEY);const rest=params.toString();return rest?`#${rest}`:""}function splitHash(url){const at=url.indexOf("#");return at===-1?[url,""]:[url.slice(0,at),url.slice(at+1)]}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@stacksjs/composables",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"version": "0.75.
|
|
5
|
+
"version": "0.75.229",
|
|
6
6
|
"description": "Stacks composables powered by stx reactivity.",
|
|
7
7
|
"author": "Chris Breuer",
|
|
8
8
|
"contributors": [
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@stacksjs/stx": "^0.2.567",
|
|
55
|
-
"@stacksjs/datetime": "0.75.
|
|
55
|
+
"@stacksjs/datetime": "0.75.229"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"better-dx": "^0.2.24"
|