UNPKG

@snap/camera-kit

Version:
88 lines 3.31 kB
import type { LensRepository } from "../lens/LensRepository"; import type { Lens } from "../lens/Lens"; import type { LensState } from "../session/lensState"; import type { SessionState } from "../session/sessionState"; import type { MetricsClient } from "../clients/metricsClient"; import type { UriHandler } from "./UriHandlers"; /** * Status of a Remote API response. */ export type RemoteApiStatus = "success" | "redirected" | "badRequest" | "accessDenied" | "notFound" | "timeout" | "requestTooLarge" | "serverError" | "cancelled" | "proxyError"; /** * Remote API request sent by a lens. */ export interface RemoteApiRequest { /** * Unique id of the remote API service specification. */ apiSpecId: string; /** * Unique id of the remote API service endpoint requested by this request. */ endpointId: string; /** * A map of named parameters associated with the request. */ parameters: Record<string, string>; /** * Additional binary request payload. */ body: ArrayBuffer; } /** * Remote API response to a request sent by a lens. */ export interface RemoteApiResponse { /** * Status of the response */ status: RemoteApiStatus; /** * A map of named metadata associated with the response. */ metadata: Record<string, string>; /** * Additional binary request payload. */ body: ArrayBuffer; } /** * Represents a Remote API request cancellation handler function. */ export type RemoteApiCancelRequestHandler = () => void; /** * Represents a Remote API request handler function. * It is provided with a reply callback that must be invoked to send a response back to the lens. * The reply callback can be invoked multiple times if needed. * Additionally, the handler can return a cancellation callback, which is triggered when the lens cancels the request. */ export type RemoteApiRequestHandler = (reply: (response: RemoteApiResponse) => void) => RemoteApiCancelRequestHandler | void; /** * Service to handle a lens Remote API request. */ export interface RemoteApiService { /** * Remote API spec ID(s). */ apiSpecId: string; /** * This method is called by Camera Kit when a lens triggers a Remote API request with a corresponding spec ID. * If the service can handle the request, the method returns a request handler; otherwise, it returns nothing. * @param request Remote API request object. * @param lens Lens that triggers the request. * @returns A request handler if applicable. */ getRequestHandler(request: RemoteApiRequest, lens: Lens): RemoteApiRequestHandler | undefined; } export type RemoteApiServices = RemoteApiService[]; export declare const remoteApiServicesFactory: { (): RemoteApiServices; token: "remoteApiServices"; dependencies: []; }; /** * Provides a URI handler that searches for a match within the provided services to handle Remote API requests, * i.e., those whose URI starts with 'app://remote-api/performApiRequest'. */ export declare function getRemoteApiUriHandler(registeredServices: RemoteApiService[], sessionState: SessionState, lensState: LensState, lensRepository: LensRepository, metrics: MetricsClient): UriHandler; //# sourceMappingURL=RemoteApiServices.d.ts.map