import {z} from 'zod' export type GetApiGeofenceV1GeofencesGeofenceIdDevicesArgs = {'X-Esper-Tenant-Id': string, 'X-Caller-Id': string, geofence_id: string, offset?: number | undefined, limit?: number | undefined, inside?: boolean | undefined, blueprint_id?: string | undefined, blueprint_version_number?: number | undefined}; export type GetApiGeofenceV1GeofencesGeofenceIdDevicesOptions = {baseUrl?: string | undefined, geofenceBearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const geofenceDeviceListingItem = z.object({device_id: z.string(), blueprint_id: z.string(), blueprint_version_number: z.number().int(), inside: z.boolean().nullable().optional(), state_changed_at: z.string().nullable().optional(), latitude: z.number().nullable().optional(), longitude: z.number().nullable().optional(), location_updated_at: z.string().nullable().optional()}); export const getApiGeofenceV1GeofencesGeofenceIdDevicesResponse = z.object({content: z.object({next: z.string().nullable().optional(), previous: z.string().nullable().optional(), results: z.array(geofenceDeviceListingItem).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 devices for a geofence * * GET /geofence/v1/geofences/{geofence_id}/devices */ export const getApiGeofenceV1GeofencesGeofenceIdDevices = async (args: GetApiGeofenceV1GeofencesGeofenceIdDevicesArgs, options?: GetApiGeofenceV1GeofencesGeofenceIdDevicesOptions) => { const {baseUrl = "https://develop-api.esper.cloud/api", fetch: fetchFn = fetch, geofenceBearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-Esper-Tenant-Id'] != null) headers.set("X-Esper-Tenant-Id", String(args['X-Esper-Tenant-Id'])) if (args['X-Caller-Id'] != null) headers.set("X-Caller-Id", String(args['X-Caller-Id'])) if (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.inside != null) query.append("inside", String(args.inside)) if (args.blueprint_id != null) query.append("blueprint_id", String(args.blueprint_id)) if (args.blueprint_version_number != null) query.append("blueprint_version_number", String(args.blueprint_version_number)) if (geofenceBearerAuth !== undefined) headers.set('authorization', `Bearer ${geofenceBearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/geofence/v1/geofences/${encodeURIComponent(String(args.geofence_id))}/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(getApiGeofenceV1GeofencesGeofenceIdDevicesResponse, await res.json()) };