import {z} from 'zod' export type CreateApiApiPreviewProjectsArgs = {body: {color?: (string | null) | undefined, description?: string | undefined, name: string, organization_id?: (string | null) | undefined, slug?: string | undefined, visibility?: ('self' | 'org_view' | 'org_edit') | undefined}}; export type CreateApiApiPreviewProjectsOptions = {baseUrl: string, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiPreviewProjectsResponse = z.object({capsule_count: z.number().int().gte(-9007199254740991).lte(9007199254740991).optional(), capsules: z.array(z.record(z.string(), z.unknown())).optional(), color: z.string().max(128).nullable().optional(), content_bytes: z.number().int().gte(-9007199254740991).lte(9007199254740991).nullable().optional(), created_at: z.string().max(64).optional(), defaulted_type_count: z.number().int().gte(-9007199254740991).lte(9007199254740991).optional(), description: z.string().max(4000).nullable().optional(), id: z.string().max(36), name: z.string().max(200).optional(), organization_id: z.string().max(128).nullable().optional(), slug: z.string().max(200).optional(), types: z.array(z.record(z.string(), z.unknown())).optional(), updated_at: z.string().max(64).optional(), user_id: z.string().max(128).optional(), visibility: z.string().max(128).optional(), workspace_id: z.string().max(128).nullable().optional()}).and(z.record(z.string(), z.unknown())); 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 }; /** * Create a project * * POST /api/preview/projects * * Also accepts auth: cookieAuth, oauth2 */ export const createApiApiPreviewProjects = async (args: CreateApiApiPreviewProjectsArgs, options: CreateApiApiPreviewProjectsOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/preview/projects${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(createApiApiPreviewProjectsResponse, await res.json()) };