import {z} from 'zod' export type EntityReference = {entityId?: string | undefined, entityName?: string | undefined}; export type OnlyId = {id?: string | undefined}; export type CustomAttribute = {attributeDefinitionId?: string | undefined, booleanValue?: boolean | undefined, dateValue?: number | undefined, entityId?: string | undefined, entityReferences?: Array | undefined, numberValue?: unknown | undefined, selectedValueId?: string | undefined, selectedValues?: Array | undefined, stringValue?: string | undefined}; export type ItemPick = {id?: string | undefined, version?: string | undefined, batchNumber?: string | undefined, bookedDate?: number | undefined, confirmedByUserId?: string | undefined, confirmedDate?: number | undefined, createdDate?: number | undefined, customAttributes?: Array | undefined, internalTransportReferenceId?: string | undefined, lastModifiedDate?: number | undefined, orderItemId?: string | undefined, quantity: unknown, serialNumbers: Array, sourceInternalTransportReferenceId?: string | undefined, sourceStoragePlaceId?: string | undefined, storagePlaceId: string, transportationOrderId?: string | undefined}; export type ProductionOrderItem = {id?: string | undefined, version?: string | undefined, actualPickDate?: number | undefined, actualQuantity?: unknown | undefined, articleId?: string | undefined, createdDate?: number | undefined, customAttributes?: Array | undefined, lastModifiedDate?: number | undefined, note?: string | undefined, picks?: Array | undefined, positionNumber?: number | undefined, quantity?: unknown | undefined, targetPickDate?: number | undefined, targetQuantity?: unknown | undefined}; export type ProductionOrderStatusHistory = {status?: ('CANCELLED' | 'CLOSED' | 'DOCUMENTS_PRINTED' | 'ENTRY_IN_PROGRESS' | 'INTERRUPTED' | 'NEW' | 'STARTED') | undefined, statusDate?: number | undefined, userId?: string | undefined}; export type ProductionOrderWorkItem = {id?: string | undefined, version?: string | undefined, book?: boolean | undefined, createdDate?: number | undefined, customAttributes?: Array | undefined, description?: string | undefined, lastModifiedDate?: number | undefined, manualItem?: boolean | undefined, positionNumber?: number | undefined, shortDescription?: string | undefined, status: 'BOOKED' | 'CLOSED' | 'OPEN', targetEndDate?: number | undefined, targetOrderTime?: number | undefined, targetStartDate?: number | undefined, timeType: 'SINGLE_TIME' | 'TIME_PER_UNIT', unitTime?: unknown | undefined}; export type ProductionOrder = {id?: string | undefined, version?: string | undefined, actualEndDate?: number | undefined, actualQuantity?: unknown | undefined, actualStartDate?: number | undefined, articleId: string, assemblyStoragePlaceId?: string | undefined, createdDate?: number | undefined, customAttributes?: Array | undefined, lastModifiedDate?: number | undefined, pickingInstructions?: string | undefined, picksComplete?: boolean | undefined, productionOrderItems?: Array | undefined, productionOrderNumber?: string | undefined, purchaseOrderItemId?: string | undefined, salesOrderItemId?: string | undefined, status: 'CANCELLED' | 'CLOSED' | 'DOCUMENTS_PRINTED' | 'ENTRY_IN_PROGRESS' | 'INTERRUPTED' | 'NEW' | 'STARTED', statusHistory?: Array | undefined, targetEndDate: number, targetQuantity: unknown, targetStartDate: number, warehouseId?: string | undefined, workItems?: Array | undefined}; export type CreateApiProductionOrderArgs = {dryRun?: boolean | undefined, body: ProductionOrder}; export type CreateApiProductionOrderOptions = {baseUrl: string, APIToken?: string | undefined, fetch?: typeof fetch | undefined}; export const entityReference = z.object({entityId: z.string().optional(), entityName: z.string().optional()}); export const onlyId = z.object({id: z.string().optional()}); export const customAttribute = z.object({attributeDefinitionId: z.string().optional(), booleanValue: z.boolean().optional(), dateValue: z.number().int().optional(), entityId: z.string().optional(), entityReferences: z.array(entityReference).optional(), numberValue: z.string().optional(), selectedValueId: z.string().optional(), selectedValues: z.array(onlyId).optional(), stringValue: z.string().optional()}); export const itemPick = z.object({id: z.string().optional(), version: z.string().optional(), batchNumber: z.string().optional(), bookedDate: z.number().int().optional(), confirmedByUserId: z.string().optional(), confirmedDate: z.number().int().optional(), createdDate: z.number().int().optional(), customAttributes: z.array(customAttribute).optional(), internalTransportReferenceId: z.string().optional(), lastModifiedDate: z.number().int().optional(), orderItemId: z.string().optional(), quantity: z.string(), serialNumbers: z.array(z.string()), sourceInternalTransportReferenceId: z.string().optional(), sourceStoragePlaceId: z.string().optional(), storagePlaceId: z.string(), transportationOrderId: z.string().optional()}); export const productionOrderItem = z.object({id: z.string().optional(), version: z.string().optional(), actualPickDate: z.number().int().optional(), actualQuantity: z.string().optional(), articleId: z.string().optional(), createdDate: z.number().int().optional(), customAttributes: z.array(customAttribute).optional(), lastModifiedDate: z.number().int().optional(), note: z.string().optional(), picks: z.array(itemPick).optional(), positionNumber: z.number().int().optional(), quantity: z.string().optional(), targetPickDate: z.number().int().optional(), targetQuantity: z.string().optional()}); export const productionOrderStatusHistory = z.object({status: z.enum(["CANCELLED", "CLOSED", "DOCUMENTS_PRINTED", "ENTRY_IN_PROGRESS", "INTERRUPTED", "NEW", "STARTED"]).optional(), statusDate: z.number().int().optional(), userId: z.string().optional()}); export const productionOrderWorkItem = z.object({id: z.string().optional(), version: z.string().optional(), book: z.boolean().optional(), createdDate: z.number().int().optional(), customAttributes: z.array(customAttribute).optional(), description: z.string().optional(), lastModifiedDate: z.number().int().optional(), manualItem: z.boolean().optional(), positionNumber: z.number().int().optional(), shortDescription: z.string().optional(), status: z.enum(["BOOKED", "CLOSED", "OPEN"]), targetEndDate: z.number().int().optional(), targetOrderTime: z.number().int().optional(), targetStartDate: z.number().int().optional(), timeType: z.enum(["SINGLE_TIME", "TIME_PER_UNIT"]), unitTime: z.string().optional()}); export const productionOrder = z.object({id: z.string().optional(), version: z.string().optional(), actualEndDate: z.number().int().optional(), actualQuantity: z.string().optional(), actualStartDate: z.number().int().optional(), articleId: z.string(), assemblyStoragePlaceId: z.string().optional(), createdDate: z.number().int().optional(), customAttributes: z.array(customAttribute).optional(), lastModifiedDate: z.number().int().optional(), pickingInstructions: z.string().optional(), picksComplete: z.boolean().optional(), productionOrderItems: z.array(productionOrderItem).optional(), productionOrderNumber: z.string().optional(), purchaseOrderItemId: z.string().optional(), salesOrderItemId: z.string().optional(), status: z.enum(["CANCELLED", "CLOSED", "DOCUMENTS_PRINTED", "ENTRY_IN_PROGRESS", "INTERRUPTED", "NEW", "STARTED"]), statusHistory: z.array(productionOrderStatusHistory).optional(), targetEndDate: z.number().int(), targetQuantity: z.string(), targetStartDate: z.number().int(), warehouseId: z.string().optional(), workItems: z.array(productionOrderWorkItem).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 productionOrder * * POST /productionOrder */ export const createApiProductionOrder = async (args: CreateApiProductionOrderArgs, options: CreateApiProductionOrderOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.dryRun != null) query.append("dryRun", String(args.dryRun)) if (APIToken !== undefined) headers.set("AuthenticationToken", APIToken) const url = `${baseUrl.replace(/\/+$/, '')}/productionOrder${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(productionOrder, await res.json()) };