import {z} from 'zod' export type LocateItemsRequest = {items_to_locate: Array, project_id: number, delete_existing?: boolean | undefined, search_in?: Array | undefined, selected_tags?: Array | undefined}; export type CreateApiApiV1ProjectProjectsIdLocateItemsArgs = {id: string, body: LocateItemsRequest}; export type CreateApiApiV1ProjectProjectsIdLocateItemsOptions = {baseUrl: string, AuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const taskIdResponse = z.object({task_id: z.string()}); 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 }; /** * POST /api/v1/project/projects/{id}/locate_items/ */ export const createApiApiV1ProjectProjectsIdLocateItems = async (args: CreateApiApiV1ProjectProjectsIdLocateItemsArgs, options: CreateApiApiV1ProjectProjectsIdLocateItemsOptions) => { const {baseUrl, fetch: fetchFn = fetch, AuthToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (AuthToken !== undefined) headers.set("Authorization", AuthToken) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/project/projects/${encodeURIComponent(String(args.id))}/locate_items/${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(taskIdResponse, await res.json()) };