@scayle/storefront-nuxt
Version:
Nuxt integration for the SCAYLE Commerce Engine and Storefront API
80 lines (79 loc) • 3.41 kB
TypeScript
import type { H3Event } from 'h3';
import type { ModuleOptions, PublicShopConfig, ShopConfig, ShopConfigIndexed } from '../../../module.js';
import type { NitroRuntimeConfigApp } from 'nitropack';
import type { StorefrontRuntimeConfigType } from '../../utils/zodSchema.js';
/**
* Represents the bootstrapped path information.
*/
interface BootstrapPath {
/** The bootstrapped path. */
path: string;
/** The original request path. */
originalPath: string;
}
/**
* Gets the bootstrap path from the URL.
*
* Handles the special case of Nuxt error pages to extract the correct path for bootstrapping.
*
* @param url The request URL.
* @param baseUrl The base URL of the application.
*
* @returns A `BootstrapPath` object containing the resolved path and original path.
*/
export declare function getBootstrapPath(url: URL, baseUrl: string): BootstrapPath;
/**
* Gets the shop configuration based on the request path.
*
* @param event The H3 event object.
* @param shops An array of shop configurations.
* @param appBasePath The base path of the application.
*
* @returns The matching shop configuration, or undefined if not found.
*/
export declare const getShopByPath: (event: H3Event, shops: ShopConfig[], appBasePath: string) => ShopConfig | undefined;
/**
* Converts the shops configuration to a list.
* Handles cases where shops are provided as an array or an indexed object.
*
* @param shops The shops configuration, either as an array or an indexed object.
*
* @returns The shops as an array.
*/
export declare const convertShopsToList: (shops: ShopConfig[] | ShopConfigIndexed | StorefrontRuntimeConfigType["shops"]) => ShopConfig[];
/**
* Gets the API base path.
*
* @param storefrontConfig The storefront module configuration.
* @param baseUrl The base URL.
*
* @returns The API base path.
*/
export declare function getApiBasePath(storefrontConfig: Pick<ModuleOptions, 'apiBasePath'>, baseUrl: string): string;
/**
* Retrieves the current shop configuration for a given request.
*
* @param event The H3 event object.
* @param storefrontConfig The storefront configuration containing shop details and selector.
* @param runtimeConfig The Nitro runtime configuration.
*
* @returns The shop config for the current request if found or undefined.
*/
export declare function getCurrentShopConfigForRequest(event: H3Event, storefrontConfig: Pick<StorefrontRuntimeConfigType, 'shops' | 'shopSelector'>, runtimeConfig: NitroRuntimeConfigApp): ShopConfig | undefined;
/**
* Transforms shop configuration data into a public representation, including active status.
*
* Selects specific properties from the provided shop configuration (`data`) to create a public version suitable
* for client-side use. Also determines if the shop is currently active based on the `currentShopId`.
*
* @param data The shop configuration data.
* @param currentShopId The ID of the currently active shop.
* @param apiBasePath The base path for the API.
* @param publicShopData An optional array of additional shop configuration keys to include in the public data.
*
* @returns A public representation of the shop configuration, including an `isActive` flag.
*/
export declare function getPublicShopData(data: ShopConfig, currentShopId: number, apiBasePath: string, publicShopData?: (keyof ShopConfig)[]): PublicShopConfig & {
isActive: boolean;
};
export {};