import {z} from 'zod' export type CommonExternalReferenceDto = {type?: (string | null) | undefined, externalId: string, displayId?: (string | null) | undefined, status?: (string | null) | undefined, url?: (string | null) | undefined, modifiedUtc?: (string | null) | undefined, lastSyncedUtc?: (string | null) | undefined}; export type InventoryEventDetailsUpdateDto = {externalReferences?: ({[key: string]: CommonExternalReferenceDto} | null) | undefined}; export type UpdateApiApiInventoryEventsInventoryEventIdDetailsArgs = {inventoryEventId: string, body: InventoryEventDetailsUpdateDto}; export type UpdateApiApiInventoryEventsInventoryEventIdDetailsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const commonExternalReferenceDto = z.object({type: z.string().max(50).nullable().optional(), externalId: z.string().max(500), displayId: z.string().max(500).nullable().optional(), status: z.string().nullable().optional(), url: z.string().nullable().optional(), modifiedUtc: z.string().nullable().optional(), lastSyncedUtc: z.string().nullable().optional()}); export const inventoryEventDetailsDto = z.object({externalReferences: z.record(z.string(), commonExternalReferenceDto).nullable().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 }; /** * Update a specific inventory event details * * PUT /api/inventory-events/{inventoryEventId}/details */ export const updateApiApiInventoryEventsInventoryEventIdDetails = async (args: UpdateApiApiInventoryEventsInventoryEventIdDetailsArgs, options?: UpdateApiApiInventoryEventsInventoryEventIdDetailsOptions) => { const {baseUrl = "https://api.fulcrumpro.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/inventory-events/${encodeURIComponent(String(args.inventoryEventId))}/details${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(inventoryEventDetailsDto, await res.json()) };