import {z} from 'zod' export type DataChangeRequestMassChange = {typedId?: string | undefined, comments?: (string | null) | undefined, createdBy?: number | undefined, massChange?: ({definitions?: (Array<{fieldName?: string | undefined, fieldValue?: string | undefined, massEditOperator?: ('=' | '+' | '-' | '*') | undefined, itemAction?: ('edit' | 'recalculate') | undefined, changeStateReason?: (string | null) | undefined, precision?: (number | null) | undefined}>) | undefined, filter?: Record | undefined, type?: ('EDIT' | 'DELETE' | null) | undefined} | null) | undefined, lastUpdateDate?: string | undefined, version?: number | undefined, createDate?: string | undefined, lastUpdateBy?: number | undefined}; export type CreateApiDcrmanagerUpdatemassopIdArgs = {body: {data?: ({typedId?: string | undefined, massChange?: ({filter?: ({_constructor?: string | undefined, operator?: string | undefined, criteria?: (Array<{fieldName?: string | undefined, operator?: string | undefined, value?: Array | undefined}>) | undefined}) | undefined, definitions?: (Array<{fieldName?: string | undefined, massEditOperator?: string | undefined, fieldValue?: string | undefined, precision?: (number | null) | undefined}>) | undefined}) | undefined}) | undefined, oldValues?: DataChangeRequestMassChange | undefined, operationType?: string | undefined, textMatchStyle?: string | undefined}}; export type CreateApiDcrmanagerUpdatemassopIdOptions = {baseUrl?: string | undefined, basic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const dataChangeRequestMassChange = z.object({typedId: z.string().optional(), comments: z.string().max(255).nullable().optional(), createdBy: z.number().int().optional(), massChange: z.object({definitions: z.array(z.object({fieldName: z.string().optional(), fieldValue: z.string().optional(), massEditOperator: z.enum(["=", "+", "-", "*"]).optional(), itemAction: z.enum(["edit", "recalculate"]).optional(), changeStateReason: z.string().nullable().optional(), precision: z.number().int().nullable().optional()})).optional(), filter: z.object({}).optional(), type: z.enum(["EDIT", "DELETE"]).nullable().optional()}).nullable().optional(), lastUpdateDate: z.string().optional(), version: z.number().int().optional(), createDate: z.string().optional(), lastUpdateBy: z.number().int().optional()}); export const createApiDcrmanagerUpdatemassopIdResponse = z.object({response: z.object({node: z.string().optional(), data: z.array(dataChangeRequestMassChange).optional(), status: z.number().int().optional()}).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 Data Change Request Mass Changes * * POST /dcrmanager.updatemassop/{id} * * Also accepts auth: X-PriceFx-jwt */ export const createApiDcrmanagerUpdatemassopId = async (args: CreateApiDcrmanagerUpdatemassopIdArgs, options?: CreateApiDcrmanagerUpdatemassopIdOptions) => { const {baseUrl = "https://companynode.pricefx.com/pricefx/companypartition", fetch: fetchFn = fetch, basic} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (basic !== undefined) headers.set('authorization', `Basic ${btoa(`${basic.username}:${basic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/dcrmanager.updatemassop/${encodeURIComponent(String(args.id))}${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(createApiDcrmanagerUpdatemassopIdResponse, await res.json()) };