import {z} from 'zod' export type GetApiApiBusinessBusinessIdBranchBranchIdTillTillIdTillSessionArgs = {businessId: string, branchId: string, tillId: string, start_time?: string | undefined, end_time?: string | undefined, size?: number | undefined, page?: number | undefined}; export type GetApiApiBusinessBusinessIdBranchBranchIdTillTillIdTillSessionOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const tillSessionCount = z.object({type: z.enum(["CASH", "CREDIT", "DEBIT", "PHOREST_PAY_CREDIT_CARD", "PHOREST_PAY_DEBIT_CARD", "CHEQUE", "VOUCHER", "ACCOUNT", "MEMBERSHIP", "APPOINTMENT_DEPOSIT", "OTHER"]).optional(), supplementalPaymentTypeId: z.string().optional(), amount: z.number().optional()}); export const tillSession = z.object({tillSessionId: z.string().optional(), transactionNo: z.number().int().optional(), tillId: z.string().optional(), branchId: z.string().optional(), startTime: z.string().optional(), endTime: z.string().optional(), countTime: z.string().optional(), startingStaffId: z.string().optional(), endingStaffId: z.string().optional(), countingStaffId: z.string().optional(), systemCounted: z.boolean().optional(), openingCashAmount: z.number().optional(), closingCashAmount: z.number().optional(), counts: z.array(tillSessionCount).optional(), notes: z.string().optional(), createTime: z.string().optional(), updateTime: z.string().optional()}); export const pageMetadata = z.object({size: z.number().int().optional(), totalElements: z.number().int().optional(), totalPages: z.number().int().optional(), number: z.number().int().optional()}); export const dataPagedModelTillSession = z.object({_embedded: z.object({tillSessions: z.array(tillSession).optional()}).optional(), page: pageMetadata.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 till sessions * * GET /api/business/{businessId}/branch/{branchId}/till/{tillId}/till-session */ export const getApiApiBusinessBusinessIdBranchBranchIdTillTillIdTillSession = async (args: GetApiApiBusinessBusinessIdBranchBranchIdTillTillIdTillSessionArgs, options?: GetApiApiBusinessBusinessIdBranchBranchIdTillTillIdTillSessionOptions) => { const {baseUrl = "http://api-gateway-eu.phorest.com/third-party-api-server", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.start_time != null) query.append("start_time", String(args.start_time)) if (args.end_time != null) query.append("end_time", String(args.end_time)) if (args.size != null) query.append("size", String(args.size)) if (args.page != null) query.append("page", String(args.page)) if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/business/${encodeURIComponent(String(args.businessId))}/branch/${encodeURIComponent(String(args.branchId))}/till/${encodeURIComponent(String(args.tillId))}/till-session${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(dataPagedModelTillSession, await res.json()) };