import {z} from 'zod' export type GetApiLogsV1FinanceNightAuditArgs = {statuses?: (Array<'InProgress' | 'Success' | 'Failure'>) | undefined, propertyIds?: Array | undefined, subjectIds?: Array | undefined, dateFilter?: Array | undefined, pageNumber?: number | undefined, pageSize?: number | undefined}; export type GetApiLogsV1FinanceNightAuditOptions = {baseUrl: string, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const nightAuditLogItemModel = z.object({ended: z.string(), setReservationsToNoShow: z.boolean(), status: z.enum(["InProgress", "Success", "Failure"]), failureCode: z.enum(["None", "ProcessNoShowsFailed", "ProcessFoliosFailed", "ProcessOccupiedUnitsFailed", "Unknown"]).nullable().optional(), failureReason: z.string().nullable().optional(), reservationIdsSetToNoShow: z.array(z.string()).nullable().optional(), propertyId: z.string(), created: z.string(), subjectId: z.string().nullable().optional()}); export const nightAuditLogListModel = z.object({logEntries: z.array(nightAuditLogItemModel), count: z.number().int()}); 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 }; /** * Returns the night audit logs. * * GET /logs/v1/finance/night-audit */ export const getApiLogsV1FinanceNightAudit = async (args: GetApiLogsV1FinanceNightAuditArgs, options: GetApiLogsV1FinanceNightAuditOptions) => { const {baseUrl, fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") for (const item of args.statuses ?? []) query.append("statuses", String(item)) for (const item of args.propertyIds ?? []) query.append("propertyIds", String(item)) for (const item of args.subjectIds ?? []) query.append("subjectIds", String(item)) for (const item of args.dateFilter ?? []) query.append("dateFilter", String(item)) if (args.pageNumber != null) query.append("pageNumber", String(args.pageNumber)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/logs/v1/finance/night-audit${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(nightAuditLogListModel, await res.json()) };