import {z} from 'zod' export type GetApiV1DevicesArgs = {ActorId?: number | undefined, isConnected?: boolean | undefined, pageNumber?: number | undefined, pageSize?: number | undefined, nayaxDeviceSerial?: string | undefined, orderId?: number | undefined, statusId?: number | undefined, createdDt?: string | undefined, updatedDt?: string | undefined, boardSerial?: string | undefined, imei?: string | undefined, chipId?: string | undefined}; export type GetApiV1DevicesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const deviceExtra = z.object({VposChipId: z.string().nullable().optional(), IsDeviceExists: z.boolean().optional(), FWVersionNumber: z.string().nullable().optional(), VposVersionNumber: z.string().nullable().optional(), DeviceID: z.number().int().nullable().optional(), ActorID: z.number().int().nullable().optional(), DeviceTypeLutID: z.number().int().nullable().optional(), DeviceSerial: z.string().nullable().optional(), IMEI: z.string().nullable().optional(), DeviceDescription: z.string().nullable().optional(), SimCardID: z.number().int().nullable().optional(), FWVersionID: z.number().int().nullable().optional(), RequestedFwID: z.number().int().nullable().optional(), PollInterval: z.number().int().nullable().optional(), StatusID: z.number().int().nullable().optional(), LastUpdated: z.string().nullable().optional(), IsCollectMultipleParameters: z.boolean().nullable().optional(), IsLogged: z.boolean().nullable().optional(), FRequestedNewVersionDate: z.string().nullable().optional(), FTookNewVersionDate: z.string().nullable().optional(), HardwareVersion: z.string().nullable().optional(), IsRental: z.boolean().nullable().optional(), RentalEndMonth: z.number().int().nullable().optional(), RentalEndYear: z.number().int().nullable().optional(), IsToBeReturned: z.boolean().nullable().optional(), FeeCommunicationThreshold: z.number().int().nullable().optional(), BillingPlanID: z.number().int().nullable().optional(), BillingPlanActivationDate: z.string().nullable().optional(), DeviceCreationDate: z.string().nullable().optional(), CreatedBy: z.number().int().nullable().optional(), UpdatedBy: z.number().int().nullable().optional(), DistributorBillingPlanID: z.number().int().nullable().optional(), ChipID: z.string().nullable().optional(), OrderID: z.number().int().nullable().optional(), ExternalFlashSize: z.number().int().nullable().optional(), BoardSerial: z.string().nullable().optional(), FlashSize: z.number().int().nullable().optional(), DeviceFamily: z.string().nullable().optional(), ModemModel: z.string().nullable().optional(), TrialEndDate: z.string().nullable().optional(), VerticalTypeID: z.number().int().nullable().optional(), VerticalProductTypeID: z.number().int().nullable().optional(), VerticalTypeLutID: z.number().int().nullable().optional(), VerticalProductTypeLutID: z.number().int().nullable().optional(), Refs: z.record(z.string(), z.string().nullable()).nullable().optional()}); export const getApiV1DevicesResponse = z.array(deviceExtra); 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 Devices * * GET /v1/devices */ export const getApiV1Devices = async (args: GetApiV1DevicesArgs, options?: GetApiV1DevicesOptions) => { const {baseUrl = "https://example.com:443", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.ActorId != null) query.append("ActorId", String(args.ActorId)) if (args.isConnected != null) query.append("isConnected", String(args.isConnected)) if (args.pageNumber != null) query.append("pageNumber", String(args.pageNumber)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.nayaxDeviceSerial != null) query.append("nayaxDeviceSerial", String(args.nayaxDeviceSerial)) if (args.orderId != null) query.append("orderId", String(args.orderId)) if (args.statusId != null) query.append("statusId", String(args.statusId)) if (args.createdDt != null) query.append("createdDt", String(args.createdDt)) if (args.updatedDt != null) query.append("updatedDt", String(args.updatedDt)) if (args.boardSerial != null) query.append("boardSerial", String(args.boardSerial)) if (args.imei != null) query.append("imei", String(args.imei)) if (args.chipId != null) query.append("chipId", String(args.chipId)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/devices${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(getApiV1DevicesResponse, await res.json()) };