import {z} from 'zod' export type ShareLinkSettings = {active?: boolean | undefined, allowDownload?: boolean | undefined, password?: (string | null) | undefined, expiresAt?: (string | null) | undefined, requireAccount?: boolean | undefined, comments?: ('hidden' | 'read_only' | 'allowed') | undefined, customFields?: ('hidden' | 'read_only' | 'editable') | undefined}; export type CreateApiV1ShowcasesArgs = {body: {name: string, description?: string | undefined, shareLink?: ShareLinkSettings | undefined}}; export type CreateApiV1ShowcasesOptions = {baseUrl: string, ApiKeyAuth?: string | undefined, WorkspaceIdAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const shareLink = z.object({id: z.string(), url: z.string(), active: z.boolean(), hasPassword: z.boolean(), expiresAt: z.string().nullable(), requireAccount: z.boolean(), allowDownload: z.boolean(), comments: z.enum(["hidden", "read_only", "allowed"]), customFields: z.enum(["hidden", "read_only", "editable"]), createdAt: z.string()}); export const showcase = z.object({id: z.string(), name: z.string(), description: z.string().nullable(), createdAt: z.string(), updatedAt: z.string(), stats: z.object({assetCount: z.number().int(), fileCount: z.number().int(), boardCount: z.number().int()}), shareLink: shareLink}); 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 }; /** * /showcases * * POST /v1/showcases * * Also accepts auth: BearerAuth + WorkspaceIdAuth */ export const createApiV1Showcases = async (args: CreateApiV1ShowcasesArgs, options: CreateApiV1ShowcasesOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKeyAuth, WorkspaceIdAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("x-api-key", ApiKeyAuth) if (WorkspaceIdAuth !== undefined) headers.set("x-air-workspace-id", WorkspaceIdAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/showcases${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(showcase, await res.json()) };