import {z} from 'zod' export type GetApiV3MerchantsMIdDevicesDeviceIdCashEventsArgs = {'User-Agent': string, mId: string, deviceId: string, filter?: string | undefined, expand?: string | undefined}; export type GetApiV3MerchantsMIdDevicesDeviceIdCashEventsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV3MerchantsMIdDevicesDeviceIdCashEventsResponse = z.object({type: z.enum(["LOAD", "TRANSACTION", "OPEN", "ADJUSTMENT", "COUNT", "UNLOAD"]).optional(), amountChange: z.number().int().optional(), timestamp: z.number().int().optional(), note: z.string().optional(), employee: z.object({id: z.string().optional(), name: z.string(), nickname: z.string().optional(), customId: z.string().optional(), email: z.string().optional(), inviteSent: z.boolean().optional(), claimedTime: z.number().int().optional(), deletedTime: z.number().int().optional(), pin: z.string().optional(), unhashedPin: z.string().optional(), role: z.enum(["OWNER", "ADMIN", "MANAGER", "EMPLOYEE"]).optional(), roles: z.array(z.object({id: z.string().optional()})).optional(), isOwner: z.boolean().optional(), shifts: z.array(z.object({id: z.string().optional()})).optional(), payments: z.array(z.object({id: z.string().optional()})).optional(), orders: z.array(z.object({id: z.string().optional()})).optional(), employeeCards: z.array(z.object({id: z.string().optional()})).optional(), merchant: z.object({id: z.string().optional()}).optional()}).optional(), device: z.object({id: z.string().optional(), name: z.string().optional(), model: z.string().optional(), merchant: z.object({id: z.string().optional()}).optional(), orderPrefix: z.string().optional(), terminalId: z.string().optional(), terminalPrefix: z.number().int().optional(), serial: z.string().optional(), buildNumber: z.number().int().optional(), secureId: z.string().optional(), buildType: z.enum(["ENG", "USER", "USERDEBUG"]).optional(), cpuId: z.string().optional(), imei: z.string().optional(), imsi: z.string().optional(), simIccid: z.string().optional(), deviceCertificate: z.string().optional(), pedCertificate: z.string().optional(), deviceTypeName: z.string().optional(), productName: z.string().optional(), pinDisabled: z.boolean().optional(), offlinePayments: z.boolean().optional(), offlinePaymentsAll: z.boolean().optional(), offlinePaymentsLimit: z.number().int().optional(), offlinePaymentsPromptThreshold: z.number().int().optional(), offlinePaymentsTotalPaymentsLimit: z.number().int().optional(), offlinePaymentsLimitDefault: z.number().int().optional(), offlinePaymentsPromptThresholdDefault: z.number().int().optional(), offlinePaymentsTotalPaymentsLimitDefault: z.number().int().optional(), offlinePaymentsMaxLimit: z.number().int().optional(), offlinePaymentsMaxTotalPaymentsLimit: z.number().int().optional(), showOfflinePayments: z.boolean().optional(), maxOfflineDays: z.number().int().optional(), allowStoreAndForward: z.boolean().optional(), secureReports: z.array(z.object({id: z.string().optional()})).optional(), bundleIndicator: z.string().optional(), deviceType: z.object({id: z.string().optional()}).optional()}).optional(), merchant: z.object({id: z.string().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 }; /** * Get all cash events for a device * * GET /v3/merchants/{mId}/devices/{deviceId}/cash_events */ export const getApiV3MerchantsMIdDevicesDeviceIdCashEvents = async (args: GetApiV3MerchantsMIdDevicesDeviceIdCashEventsArgs, options?: GetApiV3MerchantsMIdDevicesDeviceIdCashEventsOptions) => { const {baseUrl = "https://apisandbox.dev.clover.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['User-Agent'] != null) headers.set("User-Agent", String(args['User-Agent'])) if (args.filter != null) query.append("filter", String(args.filter)) if (args.expand != null) query.append("expand", String(args.expand)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v3/merchants/${encodeURIComponent(String(args.mId))}/devices/${encodeURIComponent(String(args.deviceId))}/cash_events${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(getApiV3MerchantsMIdDevicesDeviceIdCashEventsResponse, await res.json()) };