import {z} from 'zod' export type DynamicFieldValueSourceEnum = 0 | 1 | 2 | 3 | 4 | 5; export type TextStyle = {style?: (string | null) | undefined, color?: (string | null) | undefined}; export type DynamicFieldSegment = {type?: (string | null) | undefined, value?: (string | null) | undefined, entity?: DynamicFieldValueSourceEnum | undefined, key?: (string | null) | undefined, label?: (string | null) | undefined, textStyle?: TextStyle | undefined}; export type ItemCondition = {propertyKey?: (string | null) | undefined, propertyValue?: (string | null) | undefined}; export type DynamicField = {index?: number | undefined, name?: (string | null) | undefined, key?: (string | null) | undefined, valueSource?: DynamicFieldValueSourceEnum | undefined, segments?: (Array | null) | undefined, itemCondition?: ItemCondition | undefined}; export type UpdateApiV1OperationsOperationIdLineArgs = {operationId: number, Account: unknown, body: Array}; export type UpdateApiV1OperationsOperationIdLineOptions = {baseUrl: string, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const dynamicFieldValueSourceEnum = z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(3), z.literal(4), z.literal(5)]); export const textStyle = z.object({style: z.string().nullable().optional(), color: z.string().nullable().optional()}); export const dynamicFieldSegment = z.object({type: z.string().nullable().optional(), value: z.string().nullable().optional(), entity: dynamicFieldValueSourceEnum.optional(), key: z.string().nullable().optional(), label: z.string().nullable().optional(), textStyle: textStyle.optional()}); export const itemCondition = z.object({propertyKey: z.string().nullable().optional(), propertyValue: z.string().nullable().optional()}); export const dynamicField = z.object({index: z.number().int().optional(), name: z.string().nullable().optional(), key: z.string().nullable().optional(), valueSource: dynamicFieldValueSourceEnum.optional(), segments: z.array(dynamicFieldSegment).nullable().optional(), itemCondition: itemCondition.optional()}); export const operationDynamicContentResponse = z.object({operationId: z.number().int().optional(), slots: z.array(dynamicField).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 operation scan line layout * * PUT /v1/Operations/{operationId}/line */ export const updateApiV1OperationsOperationIdLine = async (args: UpdateApiV1OperationsOperationIdLineArgs, options: UpdateApiV1OperationsOperationIdLineOptions) => { const {baseUrl, fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json-patch+json; x-api-version=1.0") headers.set('accept', "application/json") if (args.Account != null) query.append("Account", String(args.Account)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/Operations/${encodeURIComponent(String(args.operationId))}/line${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(operationDynamicContentResponse, await res.json()) };