UNPKG

@scayle/storefront-nuxt

Version:

Nuxt integration for the SCAYLE Commerce Engine and Storefront API

189 lines (188 loc) 8.07 kB
import type { HashAlgorithm, ShopUser, StorefrontHooks, RpcMethodName, RpcContext } from '@scayle/storefront-core'; import type { CompressionEncodings } from '@scayle/unstorage-compression-driver'; import type { BuiltinDriverName, BuiltinDriverOptions } from 'unstorage'; import type { CheckoutShopConfigType, SessionType, StorageType, SapiConfigType, ShopConfigType, StorefrontRuntimeConfigType, StorefrontPublicRuntimeConfigType, IdpType, ModuleOptionType } from '../utils/zodSchema.js'; import type { HookResult } from '@nuxt/schema'; export type { LogLevel } from '@scayle/storefront-core'; /** * Represents shop-specific configuration relating to the SCAYLE Checkout. * * @see https://scayle.dev/en/core-documentation/checkout-guide/authentication-accounts/authetication/headless/authenticate#creating-api-clients */ export type CheckoutShopConfig = CheckoutShopConfigType; /** * Representation of options to configure how the storefront core manages sessions * * @see https://scayle.dev/en/core-documentation/storefront-guide/storefront-application/technical-foundation/sessions#session-configuration */ export type SessionConfig = SessionType; /** * Representation of a custom [Unstorage](https://unstorage.unjs.io/) driver name. * * @see https://unstorage.unjs.io/guide/custom-driver */ type CustomDriverName = string & { _custom?: unknown; }; /** * Representation of an [Unstorage](https://unstorage.unjs.io/) storage entity. * * @template Driver The storage driver. * @template DriverOptions The driver options. * * @see https://scayle.dev/en/core-documentation/storefront-guide/storefront-application/technical-foundation/storage#configuration-of-storage-mounts */ export type StorageEntity<Driver extends SupportedDriverName | CustomDriverName | unknown = unknown, DriverOptions = Driver extends keyof BuiltinDriverOptions ? BuiltinDriverOptions[Driver] : unknown> = { driver: Driver; compression?: CompressionEncodings; } & DriverOptions; /** * Represents the storage configuration for [Unstorage](https://unstorage.unjs.io/), leveraging the Nitro caching system. * Storefront Core utilizes pre-configured and reusable mount points built on top of Unstorage * and the Nitro Storage Layer, providing various caching capabilities. * * @see https://scayle.dev/en/core-documentation/storefront-guide/storefront-application/technical-foundation/storage */ export interface StorageConfig { /** * The cache storage configuration. * * Should no dedicated `StorageType` / `StorageEntity` be configured, * Storefront Core will use an In-Memory driver as default for this storage mountpoints. * * @see https://scayle.dev/en/core-documentation/storefront-guide/storefront-application/technical-foundation/storage#configuration-of-storage-mounts */ cache?: StorageType; /** * The session storage configuration. * * Should no dedicated `StorageType` / `StorageEntity` be configured, * Storefront Core will use an In-Memory driver as default for this storage mountpoints. * * @see https://scayle.dev/en/core-documentation/storefront-guide/storefront-application/technical-foundation/storage#configuration-of-storage-mounts */ session?: StorageType; } /** * Represents the Storefront API configuration used authenticate with it. * * @see https://scayle.dev/en/api-guides/storefront-api/getting-started/authentication * @see https://scayle.dev/en/core-documentation/storefront-guide/storefront-application/technical-foundation/configuration#storefront-api */ export type SapiConfig = SapiConfigType; /** * Representation of Application-specific keys, * defining how keys are generated for baskets and wishlists. * * @see https://scayle.dev/en/core-documentation/storefront-guide/storefront-application/technical-foundation/sessions#app-keys-for-baskets-and-wishlists */ export interface AppKeys { /** The wishlist key used as prefix to generate user-specific wishlist identifier. */ wishlistKey: string; /** The basket key used as prefix to generate user-specific basket identifier. */ basketKey: string; /** The hash algorithm used to generate user-specific basket and wishlist identifier. */ hashAlgorithm: HashAlgorithm; } /** * Provides a structure for additional shop configuration. * Extending this interface allows to add custom metadata to each shop's settings * in a Storefront application. * * @see https://scayle.dev/en/core-documentation/storefront-guide/storefront-application/technical-foundation/configuration#additional-shop-data */ export interface AdditionalShopConfig { } /** * Shop configuration. */ export type ShopConfig = ShopConfigType & AdditionalShopConfig; /** * Shop configuration indexed by shop ID. */ export type ShopConfigIndexed = Record<string, ShopConfig>; /** * Public shop configuration. This configuration is accessible on the client-side. */ export interface PublicShopConfig extends Pick<ShopConfig, 'shopId' | 'domain' | 'locale' | 'currency' | 'currencyFractionDigits'> { /** Checkout configuration. */ checkout: Pick<CheckoutShopConfig, 'host'>; /** API base path. */ apiBasePath: string; /** IDP configuration. */ idp?: IdpType; /** Path. */ path?: string; } /** * Storefront configuration. */ export interface StorefrontRuntimeConfig extends Omit<StorefrontRuntimeConfigType, 'shops'> { shops: ShopConfigIndexed; } export type SupportedDriverName = BuiltinDriverName | 'scayleKv'; /** * Module base options. Extends `StorefrontConfig` and `ModuleOption`. */ export type ModuleOptions = ModuleOptionType; /** * @deprecated - will be removed in the next major version. Please switch to `CheckoutEvent` in the Storefront Application (v1.15.0). * Checkout event used for tracking with Google Tag Manager. * * @see https://scayle.dev/en/core-documentation/storefront/checkout-guide/implementation/webcomponent#tracking */ export interface CheckoutEvent { /** Action. */ action?: 'authenticated'; /** Type. */ type?: 'tracking'; /** User. */ user: ShopUser; /** * The OAuth 2.0 access token for the authenticated user. * This token can be used to access protected resources on behalf of the user. * * @see https://www.rfc-editor.org/rfc/rfc6749 */ accessToken: string; /** * Details about a specific event within the checkout process. * This field is optional and is only used when tracking specific actions * like `add_to_cart` or `remove_from_cart`. * * @see https://scayle.dev/en/core-documentation/storefront/checkout-guide/tracking */ event?: { /** Event name. */ event: 'login' | 'add_to_cart' | 'remove_from_cart'; /** Event status. */ status: 'successful' | 'error'; }; } export interface ModulePublicRuntimeConfig extends StorefrontPublicRuntimeConfigType { } declare module '@nuxt/schema' { interface RuntimeConfig { storefront: StorefrontRuntimeConfig; } interface PublicRuntimeConfig { storefront: ModulePublicRuntimeConfig; } } declare module 'nitropack' { /** * Nitro runtime hooks. * * @see https://nitro.build/guide/plugins#nitro-runtime-hooks */ interface NitroRuntimeHooks extends StorefrontHooks { /** Storefront hook called after the RPC context created . */ 'storefront:context:created': (context: RpcContext) => HookResult; /** Storefront hook called before the RPC method is executed. */ 'storefront:rpc:before': (rpcName: RpcMethodName, context: RpcContext, payload: unknown) => HookResult; /** Storefront hook called after the RPC method is executed. */ 'storefront:rpc:after': (rpcName: RpcMethodName, context: RpcContext, result: unknown) => HookResult; /** Storefront hook called if an error occurs during RPC method execution. */ 'storefront:rpc:error': (rpcName: RpcMethodName, context: RpcContext, error: unknown) => HookResult; } }