import {z} from 'zod' export type CreateApiNotificationListArgs = {body: {endRow?: number | undefined, oldValues?: (Record | null) | undefined, operationType?: string | undefined, startRow?: number | undefined, textMatchStyle?: string | undefined, data?: ({_constructor?: string | undefined, operator?: string | undefined, criteria?: (Array<{fieldName?: string | undefined, operator?: string | undefined, value?: string | undefined}>) | undefined}) | undefined}}; export type CreateApiNotificationListOptions = {baseUrl?: string | undefined, basic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const notification = z.object({typedId: z.string().optional(), lastUpdateDate: z.string().optional(), dueDate: z.string().optional(), isRead: z.boolean().optional(), source: z.string().max(255).optional(), title: z.string().max(255).optional(), message: z.string().max(4096).optional(), version: z.number().int().optional(), actionLabel: z.string().max(255).nullable().optional(), actionType: z.enum(["UNKNOWN", "LINK", "DOWNLOAD", "INFO_MESSAGE", "MESSAGE_LINK", "CTX_LINK"]).max(255).optional(), createdBy: z.number().int().optional(), topic: z.enum(["VALIDATION", "CALCULATION", "DATA_DOWNLOAD", "MESSAGE", "GROOVY", "SYSTEM_NOTIFICATION"]).max(255).optional(), action: z.string().max(2000).nullable().optional(), recipientID: z.number().int().optional(), validUntil: z.string().max(255).optional(), status: z.enum(["UNKNOWN", "INFO", "WARNING", "ERROR", "SUCCESS"]).max(255).optional(), createDate: z.string().optional(), lastUpdateBy: z.number().int().optional()}); export const createApiNotificationListResponse = z.object({response: z.object({node: z.string().optional(), startRow: z.number().int().optional(), data: z.array(notification).optional(), endRow: z.number().int().optional(), totalRows: z.number().int().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 }; /** * List Notifications * * POST /notification.list * * Also accepts auth: X-PriceFx-jwt */ export const createApiNotificationList = async (args: CreateApiNotificationListArgs, options?: CreateApiNotificationListOptions) => { 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(/\/+$/, '')}/notification.list${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(createApiNotificationListResponse, await res.json()) };