import {z} from 'zod' export type GetApiV1PromptsPromptIdArgs = {prompt_id: string}; export type GetApiV1PromptsPromptIdOptions = {baseUrl?: string | undefined, LightsageApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const publicPromptTopic = z.object({id: z.string(), name: z.string(), created_at: z.string().nullable().optional(), updated_at: z.string().nullable().optional()}); export const publicPromptPlatform = z.object({id: z.string(), name: z.string()}); export const publicPromptTag = z.object({id: z.string(), name: z.string(), created_at: z.string().nullable().optional(), updated_at: z.string().nullable().optional()}); export const publicPrompt = z.object({id: z.string(), topic_id: z.string(), text: z.string(), is_branded: z.boolean().optional(), language_id: z.string().nullable().optional(), region_id: z.string().nullable().optional(), status: z.enum(["active", "inactive", "archived"]), topic: publicPromptTopic.nullable().optional(), platforms: z.array(publicPromptPlatform).optional(), tags: z.array(publicPromptTag).optional(), created_at: z.string().nullable().optional(), updated_at: z.string().nullable().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Retrieve Prompt * * GET /v1/prompts/{prompt_id} */ export const getApiV1PromptsPromptId = async (args: GetApiV1PromptsPromptIdArgs, options?: GetApiV1PromptsPromptIdOptions) => { const {baseUrl = "https://api.lightsage.com", fetch: fetchFn = fetch, LightsageApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (LightsageApiKeyAuth !== undefined) headers.set("X-Lightsage-Api-Key", LightsageApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/prompts/${encodeURIComponent(String(args.prompt_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(publicPrompt, await res.json()) };