UNPKG

@scayle/storefront-core

Version:

Collection of essential utilities to work with the Storefront API

51 lines (50 loc) 1.65 kB
import type { RpcHandler, ShopUser } from '../../types'; /** * Retrieves the user from the context. * * @param context The RPC context. * * @returns An object containing the user object, or undefined if not logged in. */ declare const getUser: RpcHandler<{ user?: ShopUser; }>; /** * Fetches user data using the provided access token. * * @param param An object containing the access token. * @param param.accessToken The access token for authentication. * @param context The RPC context. * * @returns The fetched user data. It will return an `ErrorResponse` alternatively * if an error occurs during the API call. */ declare const fetchUser: RpcHandler<{ accessToken?: string; }, ShopUser>; /** * Refreshes the user session and data. * If the user is no longer logged in, the session is destroyed. * * @param context The RPC context. * * @returns An object containing the user object, or undefined if session is destroyed. * It will return an `ErrorResponse` if no session is found or other errors occur. */ declare const refreshUser: RpcHandler<{ user?: ShopUser; }>; /** * Retrieves or refreshes the access token. * * @param param The parameter containing the flag for forced token refresh. * @param param.forceTokenRefresh Whether to force a token refresh. Defaults to false. * @param context The RPC context. * * @returns The access token. It will return an `ErrorResponse` alternatively * if no session, access token, or refresh token is found. */ declare const getAccessToken: RpcHandler<{ forceTokenRefresh?: boolean; }, string>; export { getUser, fetchUser, refreshUser, getAccessToken };