import {z} from 'zod' export type CreateApiApiPreviewProjectsIdMoveToWorkspaceArgs = {id: string, body: {confirm_exposure?: boolean | undefined, mode?: ('move' | 'copy') | undefined, targetWorkspaceId: string, typeMap?: ({[key: string]: string | 'create'}) | undefined}}; export type CreateApiApiPreviewProjectsIdMoveToWorkspaceOptions = {baseUrl: string, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiPreviewProjectsIdMoveToWorkspaceResponse = z.object({failed: z.array(z.object({code: z.string().max(128), error: z.string().max(4000), id: z.string().max(36)}).and(z.record(z.string(), z.unknown()))), pending: z.array(z.object({capsule_id: z.string().max(36), change_id: z.string().max(36), review_url: z.string().max(128)}).and(z.record(z.string(), z.unknown()))).optional(), project_id: z.string().max(36), skipped: z.array(z.object({capsule_id: z.string().max(36), code: z.string().max(128)}).and(z.record(z.string(), z.unknown()))), succeeded: z.array(z.object({capsuleId: z.string().max(36), droppedCollections: z.array(z.object({id: z.string().max(36), name: z.string().max(200), slug: z.string().max(200)}).and(z.record(z.string(), z.unknown()))), id: z.string().max(36), mode: z.enum(["move", "copy"]), newRefId: z.number().int().gte(-9007199254740991).lte(9007199254740991), newSlug: z.string().max(200).nullable(), previousRefId: z.number().int().gte(-9007199254740991).lte(9007199254740991).nullable(), previousSlug: z.string().max(200).nullable(), typeId: z.string().max(36), workspaceId: z.string().max(36)}).and(z.record(z.string(), z.unknown()))), workspace_id: z.string().max(36)}).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 }; /** * Move or copy a personal project and its capsules into an organization workspace * * POST /api/preview/projects/{id}/move-to-workspace * * Also accepts auth: cookieAuth, oauth2 */ export const createApiApiPreviewProjectsIdMoveToWorkspace = async (args: CreateApiApiPreviewProjectsIdMoveToWorkspaceArgs, options: CreateApiApiPreviewProjectsIdMoveToWorkspaceOptions) => { 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/${encodeURIComponent(String(args.id))}/move-to-workspace${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(createApiApiPreviewProjectsIdMoveToWorkspaceResponse, await res.json()) };