import {z} from 'zod' export type GetApiGeofenceV1GeofencesGeofenceIdDeviceSummaryArgs = {'X-Esper-Tenant-Id': string, 'X-Caller-Id': string, geofence_id: string}; export type GetApiGeofenceV1GeofencesGeofenceIdDeviceSummaryOptions = {baseUrl?: string | undefined, geofenceBearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const geofenceDeviceSummaryResponse = z.object({total_devices: z.number().int().gte(0), inside_count: z.number().int().gte(0), outside_count: z.number().int().gte(0), unknown_count: z.number().int().gte(0)}); export const getApiGeofenceV1GeofencesGeofenceIdDeviceSummaryResponse = z.object({content: geofenceDeviceSummaryResponse.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 device summary for a geofence * * GET /geofence/v1/geofences/{geofence_id}/device-summary */ export const getApiGeofenceV1GeofencesGeofenceIdDeviceSummary = async (args: GetApiGeofenceV1GeofencesGeofenceIdDeviceSummaryArgs, options?: GetApiGeofenceV1GeofencesGeofenceIdDeviceSummaryOptions) => { 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 (geofenceBearerAuth !== undefined) headers.set('authorization', `Bearer ${geofenceBearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/geofence/v1/geofences/${encodeURIComponent(String(args.geofence_id))}/device-summary${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(getApiGeofenceV1GeofencesGeofenceIdDeviceSummaryResponse, await res.json()) };