import {z} from 'zod' export type CreateApiAuthoringV1ContentIdCreateDraftArgs = {id: string, 'If-Match'?: string | undefined, include?: string | undefined, fields?: string | undefined}; export type CreateApiAuthoringV1ContentIdCreateDraftOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const createApiAuthoringV1ContentIdCreateDraftResponse = z.object({id: z.string().optional(), rev: z.string().optional(), name: z.string().optional(), description: z.string().optional(), typeId: z.string().optional(), type: z.string().optional(), kind: z.string().optional(), lastModified: z.string().optional(), lastModifierId: z.string().optional(), lastModifier: z.string().optional(), created: z.string().optional(), creatorId: z.string().optional(), creator: z.string().optional(), classification: z.literal("content").optional(), status: z.enum(["draft", "ready", "retired"]).optional(), linkedDocId: z.string().optional(), elements: z.object({}).optional(), tags: z.array(z.string()).optional(), links: z.object({self: z.object({href: z.string().optional()}).optional(), linkedDoc: z.object({href: z.string().optional()}).optional(), draft: z.object({href: z.string().optional()}).optional(), "create-draft": z.object({href: z.string().optional()}).optional(), ready: z.object({href: z.string().optional()}).optional(), retire: z.object({href: z.string().optional()}).optional(), type: z.object({href: z.string().optional()}).optional()}).optional(), thumbnail: z.object({id: z.string().optional(), path: z.string().optional(), url: z.string().optional()}).optional(), isSystem: z.boolean().optional(), libraryId: z.string().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 }; /** * Create a draft version of an existing content item. * * POST /authoring/v1/content/{id}/create-draft */ export const createApiAuthoringV1ContentIdCreateDraft = async (args: CreateApiAuthoringV1ContentIdCreateDraftArgs, options: CreateApiAuthoringV1ContentIdCreateDraftOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['If-Match'] != null) headers.set("If-Match", String(args['If-Match'])) if (args.include != null) query.append("include", String(args.include)) if (args.fields != null) query.append("fields", String(args.fields)) const url = `${baseUrl.replace(/\/+$/, '')}/authoring/v1/content/${encodeURIComponent(String(args.id))}/create-draft${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiAuthoringV1ContentIdCreateDraftResponse, await res.json()) };