import type { Except, KsAppClientData, RendererId, TemplateSuggestionsGetFn, ApiRoute, TemplateInfo, GeneralDiscovery, KsTemplateSpec, PathAbsolute, PathRelative, RendererDiscovery, PackageJson } from '@knapsack/types'; import type { Request } from 'express'; export interface KnapsackDataStoreSaveBody { state: KsAppClientData; } export type PatternRenderDataWithDemoId = { patternId: string; templateId: string; assetSetId: string; demoId: string; }; export type PatternRenderData = { /** * Not needed if `demo` is type `data-w-template-info` - only used to retrieve the rendererId */ patternId: string | undefined; /** * Not needed if `demo` is type `data-w-template-info` - only used to retrieve the rendererId */ templateId: string | undefined; assetSetId?: string; wrapHtml?: boolean; isInIframe?: boolean; cacheBuster?: string; /** * Data id for Demo from `saveData()` * @see {@link Demo} */ dataId: string; /** * ID for @see {ContentStateForRendering} */ stateId: string; }; export type TemplateSuggestionsReqParams = Except[0], 'state'> & { /** * ID from saving {@link ContentStateForRendering} to `api.knapsack.cloud/render-data */ stateId: string; }; export type TemplateSuggestionsResBody = { type: 'success'; data: Awaited>; } | { type: 'error.invalidParams'; message: string; } | { type: 'error.pathNotFound'; message: string; } | { type: 'error.couldNotParse'; message: string; }; export type RouteDiscovery = ApiRoute<{ path: '/api/v2/discovery'; method: 'GET'; output: GeneralDiscovery; }>; export type RouteRendererDiscovery = ApiRoute<{ path: '/api/v2/renderer-discovery'; method: 'GET'; input: { rendererId: TheRendererId; }; output: RendererDiscovery; }>; export type RoutePkgInfo = ApiRoute<{ path: '/api/v2/pkg-info'; method: 'GET'; input: { pkgName: string; }; output: { pkgName: string; pkgJson: PackageJson; isFromNodeModules: boolean; relativePath: PathRelative; }; }>; /** * Send up a JSON object, get back a dataId that can be used to render a demo */ export type SaveDataRoute = ApiRoute<{ path: '/api/v1/save-data'; method: 'POST'; input: Record; output: { ok: true; data: { dataId: string; }; }; }>; export type RouteInspect = ApiRoute<{ path: '/api/v2/inspect'; method: 'GET'; input: TemplateInfo; output: { type: 'success'; spec: KsTemplateSpec; } | { type: 'noSpecInferred'; } | { type: 'error.unknown'; message: string; } | { type: 'renderer.notFound'; } | { type: 'renderer.noInspectSupported'; }; }>; export type RouteBase = ApiRoute<{ path: '/api/v1'; method: 'GET'; output: { buildTime: string; buildId: string; host: string; siteId: string; ksVersions: { app: string; }; }; }>; export type EndpointPaths = '/' | '/demo-urls-data' | RouteInspect['path'] | RouteDiscovery['path'] | RouteRendererDiscovery['path'] | RoutePkgInfo['path'] | '/demo-urls' | RouteBase['path'] | '/api/v1/data-store' | '/api/v1/data/metaState' | '/api/v1/data-store-prep' | '/api/v1/files' | '/api/v1/render' | '/api/v1/render-demo-id' | '/api/v1/plugins' | '/api/v1/template-suggestions' | '/api/v1/save-data'; /** * A setting for the minimum role required for an endpoint * Is currently a single string and not a boolean to allow for future expansion * If absent then the endpoint is public * VIEWER means either site is private and user at least a viewer or site is public */ export type EndpointAuthLevel = 'VIEWER'; export type EndpointGet, ResBody extends Record | string, EndpointPath extends EndpointPaths = EndpointPaths> = { path: EndpointPath; method: 'GET'; validateQuery?: (query: Data) => void; handle: (req: Request) => Promise; authLevel?: EndpointAuthLevel; }; type EndpointPost, ResBody extends Record | string, EndpointPath extends EndpointPaths = EndpointPaths> = { path: EndpointPath; method: 'POST'; validateBody?: (body: Data) => void; handle: (req: Request) => Promise; authLevel?: EndpointAuthLevel; }; export type Endpoint, ResBody extends Record | string, EndpointPath extends EndpointPaths = EndpointPaths> = EndpointGet | EndpointPost; export type ExtractEndpointData> = T extends Endpoint ? Data : never; export type ExtractEndpointResBody> = T extends Endpoint ? ResBody : never; export type EndpointFiles = EndpointPost<{ type: 'verify'; payload: { path: string; rendererId: RendererId; }; }, { type: 'verify'; payload: { exists: boolean; relativePath: PathRelative; absolutePath: PathAbsolute; type: 'absolute' | 'relative' | 'package' | 'unknown'; }; }, '/api/v1/files'>; export type EndpointPlugins = EndpointPost<{ type: 'getContent'; pluginId: string; }, { type: 'getContent'; ok: boolean; message?: string; payload: Record; }, '/api/v1/plugins'>; export {}; //# sourceMappingURL=endpoints.d.ts.map