import {z} from 'zod' export type GetApiV1GeofencesAssetEventsArgs = {start_date?: string | undefined, end_date?: string | undefined, 'geofence_ids[]'?: Array | undefined, 'asset_ids[]'?: Array | undefined, updated_after?: string | undefined, per_page?: number | undefined, page_no?: number | undefined}; export type GetApiV1GeofencesAssetEventsOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV1GeofencesAssetEventsResponse = z.object({geofence_events: z.array(z.object({geofence_event: z.object({id: z.number().int().optional(), geofence_id: z.number().int().optional(), start_time: z.string().optional(), end_time: z.string().optional(), duration: z.number().int().optional(), asset: z.object({id: z.number().int().optional(), name: z.string().optional(), status: z.string().optional(), type: z.string().optional(), vin: z.unknown(), license_plate_state: z.unknown(), license_plate_number: z.unknown(), make: z.string().optional(), model: z.string().optional(), year: z.string().optional(), axle: z.unknown(), weight_metric_units: z.boolean().optional(), length_metric_units: z.boolean().optional(), leased: z.boolean().optional(), notes: z.unknown(), length: z.unknown(), gvwr: z.number().int().optional(), gawr: z.number().int().optional(), asset_gateway: z.object({id: z.number().int().optional(), identifier: z.string().optional(), active: z.boolean().optional()}).optional(), external_ids: z.array(z.object({})).optional()}).optional()}).optional()})).optional(), pagination: z.object({per_page: z.number().int().optional(), page_no: z.number().int().optional(), total: 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 all the asset Geofence events * * GET /v1/geofences/asset_events */ export const getApiV1GeofencesAssetEvents = async (args: GetApiV1GeofencesAssetEventsArgs, options?: GetApiV1GeofencesAssetEventsOptions) => { const {baseUrl = "https://api.gomotive.com", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.start_date != null) query.append("start_date", String(args.start_date)) if (args.end_date != null) query.append("end_date", String(args.end_date)) for (const item of args['geofence_ids[]'] ?? []) query.append("geofence_ids[]", String(item)) for (const item of args['asset_ids[]'] ?? []) query.append("asset_ids[]", String(item)) if (args.updated_after != null) query.append("updated_after", String(args.updated_after)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (args.page_no != null) query.append("page_no", String(args.page_no)) if (sec0 !== undefined) headers.set("x-api-key", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/v1/geofences/asset_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(getApiV1GeofencesAssetEventsResponse, await res.json()) };