import {z} from 'zod' export type EntityLink = {properties?: ({[key: string]: Record | null} | null) | undefined, renditions?: ({[key: string]: Record | null} | null) | undefined, permissions?: (Array | null) | undefined, identifier?: (string | null) | undefined, href?: (string | null) | undefined, filename_properties?: (Array | null) | undefined, title?: (string | null) | undefined, templated?: boolean | undefined}; export type Link = {href?: (string | null) | undefined, filename_properties?: (Array | null) | undefined, title?: (string | null) | undefined, templated?: boolean | undefined}; export type RelationResource = {parents?: (Array | null) | undefined, parent?: EntityLink | undefined, children?: (Array | null) | undefined, child?: EntityLink | undefined, inherits_security?: (boolean | null) | undefined, parent_total?: (number | null) | undefined, child_total?: (number | null) | undefined, self?: Link | undefined}; export type EntityPostResource = {id?: (number | null) | undefined, identifier?: (string | null) | undefined, properties?: ({[key: string]: Record | null} | null) | undefined, relations?: ({[key: string]: RelationResource} | null) | undefined, is_root_taxonomy_item?: (boolean | null) | undefined, is_path_root?: (boolean | null) | undefined, entitydefinition?: Link | undefined, is_system_owned?: boolean | undefined, inherits_security?: boolean | undefined, self?: Link | undefined}; export type EntityPostCollectionResource = {items?: (Array | null) | undefined}; export type CreateApiApiJobsIdTargetsBulkArgs = {id: number, body: EntityPostCollectionResource}; export type CreateApiApiJobsIdTargetsBulkOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const link = z.object({href: z.string().nullable().optional(), filename_properties: z.array(z.string()).nullable().optional(), title: z.string().nullable().optional(), templated: z.boolean().optional()}); export const entityCreatedResource = z.object({id: z.number().int().optional(), identifier: z.string().nullable().optional(), link: link.optional(), self: link.optional()}); export const entityCreatedCollectionResource = z.object({items: z.array(entityCreatedResource).nullable().optional(), total_items: z.number().int().nullable().optional(), returned_items: z.number().int().nullable().optional(), offset: z.number().int().nullable().optional(), next: link.optional(), previous: link.optional(), identifier: z.string().nullable().optional(), self: link.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 multiple job targets at once * * POST /api/jobs/{id}/targets/bulk */ export const createApiApiJobsIdTargetsBulk = async (args: CreateApiApiJobsIdTargetsBulkArgs, options?: CreateApiApiJobsIdTargetsBulkOptions) => { const {baseUrl = "https://your-server", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/jobs/${encodeURIComponent(String(args.id))}/targets/bulk${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(entityCreatedCollectionResource, await res.json()) };