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 ProductionWorkScheduleAssignment = {id?: string | undefined, version?: string | undefined, alternative?: boolean | undefined, articleId: string, createdDate?: number | undefined, customAttributes?: Array | undefined, lastModifiedDate?: number | undefined, productionWorkScheduleId: string, validFrom?: number | undefined, validTo?: number | undefined}; export type CreateApiProductionWorkScheduleAssignmentArgs = {dryRun?: boolean | undefined, body: ProductionWorkScheduleAssignment}; export type CreateApiProductionWorkScheduleAssignmentOptions = {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 productionWorkScheduleAssignment = z.object({id: z.string().optional(), version: z.string().optional(), alternative: z.boolean().optional(), articleId: z.string(), createdDate: z.number().int().optional(), customAttributes: z.array(customAttribute).optional(), lastModifiedDate: z.number().int().optional(), productionWorkScheduleId: z.string(), validFrom: z.number().int().optional(), validTo: z.number().int().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 productionWorkScheduleAssignment * * POST /productionWorkScheduleAssignment */ export const createApiProductionWorkScheduleAssignment = async (args: CreateApiProductionWorkScheduleAssignmentArgs, options: CreateApiProductionWorkScheduleAssignmentOptions) => { 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(/\/+$/, '')}/productionWorkScheduleAssignment${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(productionWorkScheduleAssignment, await res.json()) };