UNPKG

@scayle/storefront-nuxt

Version:

Nuxt integration for the SCAYLE Commerce Engine and Storefront API

25 lines (24 loc) 1.47 kB
import type { RpcContext, RpcMethodName, RpcMethodParameters, RpcMethodReturnType } from '@scayle/storefront-core'; import type { NuxtApp } from 'nuxt/app'; import type { PublicShopConfig } from '../types/module.js'; /** * Invokes an RPC method on the client or server. * Uses an HTTP request on the client and a direct call on the server via `$fetch`. * * The HTTP verb is read from the build-time manifest `#virtual/rpcHttpMethods`, * from each `defineRpcHandler`; `POST` when not listed. * * @see https://nuxt.com/docs/api/utils/dollarfetch * * @template N The RPC method name. * @template P The RPC method parameters. * @template TResult The unwrapped return type of the RPC method, excluding the Response type. * @template TakesParameters A boolean indicating whether the method takes parameters (undefined if it doesn't). * * @param nuxtApp The Nuxt app instance. * @param method The name of the RPC method to call. * @param shop The public shop configuration. * * @returns A function that takes parameters (if required) and returns a Promise resolving to the result. */ export declare const rpcCall: <N extends RpcMethodName, P extends RpcMethodParameters<N>, TResult extends Exclude<Awaited<RpcMethodReturnType<N>>, Response>, TakesParameters = P extends RpcContext ? undefined : boolean>(nuxtApp: NuxtApp, method: N, shop: PublicShopConfig) => TakesParameters extends undefined ? () => Promise<TResult> : (params: P) => Promise<TResult>;