UNPKG

@scayle/storefront-nuxt

Version:

Nuxt integration for the SCAYLE Commerce Engine and Storefront API

49 lines (48 loc) 1.88 kB
import type { Session } from '@scayle/h3-session'; import type { RuntimeConfig } from '@nuxt/schema'; import type { H3Event } from 'h3'; import type { Log, RpcContext, Cache as CacheInterface } from '@scayle/storefront-core'; import { StorefrontAPIClient } from '@scayle/storefront-core'; import type { ShopConfig } from '../module.js'; import type { StorefrontRuntimeConfigType } from './utils/zodSchema.js'; /** * Interface defining the options for the context builder. */ export interface ContextBuilderOptions { $cache: CacheInterface; $shopConfig: ShopConfig; $storefront: StorefrontRuntimeConfigType; $log: Log; sessionId?: string; session?: Session; config: RuntimeConfig; event: H3Event; } /** * Builds the RPC context. * * It builds the RPC context by gathering data from different sources like * shop config, storefront config, session, etc. * It initializes the SAPI client, caching function, and various context properties. * It also sets up getters for IP, headers, user, access tokens, * and functions for session management and user updates. * * @see https://scayle.dev/en/core-documentation/storefront-guide/storefront-application/technical-foundation/rpc-methods#rpc-context * * @param context The context builder options. * @param context.$cache The cache instance. * @param context.$shopConfig The shop configuration. * @param context.$storefront The storefront configuration. * @param context.$log The log instance. * @param context.config The runtime configuration. * @param context.event The H3 event. * @param context.session The session object. * * @returns The built RPC context. */ export declare const buildContext: (context: ContextBuilderOptions) => Promise<RpcContext>; declare module '@scayle/storefront-core' { interface AdditionalRpcContext { sapiClient: StorefrontAPIClient; } }