import {z} from 'zod' export type CreateApiProjectsProjectIdItemsBulkArgs = {projectId: string, body: {items: Array<{id?: (string | null) | undefined, sourceId?: (string | null) | undefined, type: string, title: string, statusName: string, author?: ({id: string} | {email: string} | null) | undefined, reporter?: ({id: string} | {email: string} | null) | undefined, assignee?: ({id: string} | {email: string} | null) | undefined, introducedInVersion?: ({id: string} | null) | undefined, obsoleteInVersion?: ({id: string} | null) | undefined, selectedVersions?: (Array<{id: string}> | null) | undefined, fields?: (Array<{label: string, type: 'string' | 'select' | 'date', value: string} | {label: string, type: 'jdf', value: unknown} | {label: string, type: 'multiselect', value: Array}> | null) | undefined, relations?: (Array<{type: string, toItem: {id: string} | {sourceId: string} | {system: 'ADO' | 'BUILD' | 'GIT' | 'LINEAR' | 'JAMA' | 'JIRA' | 'CONFLUENCE' | 'KETRYX' | 'POLARION' | 'QMETRY' | 'TESTRAIL' | 'GHSA' | 'NVD' | 'JIRA_DATA_CENTER', value: string}}> | null) | undefined}>}}; export type CreateApiProjectsProjectIdItemsBulkOptions = {baseUrl?: string | undefined, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiProjectsProjectIdItemsBulkResponse = z.object({items: z.array(z.object({success: z.boolean(), id: z.string().nullable(), sourceId: z.string().min(1).optional(), currentRecord: z.object({id: z.string().min(1)}).nullable()}))}); 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 }; /** * Bulk create or patch items in a project (subject to change) * * POST /projects/{projectId}/items/bulk */ export const createApiProjectsProjectIdItemsBulk = async (args: CreateApiProjectsProjectIdItemsBulkArgs, options?: CreateApiProjectsProjectIdItemsBulkOptions) => { const {baseUrl = "https://app.ketryx.com/api/v1", fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Authorization !== undefined) headers.set('authorization', `Bearer ${Authorization}`) const url = `${baseUrl.replace(/\/+$/, '')}/projects/${encodeURIComponent(String(args.projectId))}/items/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(createApiProjectsProjectIdItemsBulkResponse, await res.json()) };