import {z} from 'zod' export type GetApiV0EnterpriseEnterpriseIdCreateApplyGeoFenceArgs = {enterprise_id: string, search?: string | undefined, limit?: number | undefined, offset?: number | undefined}; export type GetApiV0EnterpriseEnterpriseIdCreateApplyGeoFenceOptions = {baseUrl?: string | undefined, esperCloudApiApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const esperCloudApiGeofence = z.object({id: z.string().optional(), name: z.string(), description: z.string().optional(), enterprise: z.string().optional(), latitude: z.string(), longitude: z.string(), radius: z.number().int().optional(), radius_unit: z.enum(["KILOMETERS", "METERS", "MILES"]).optional(), device_actions: z.array(z.enum(["LOCK_DOWN", "BEEP"])).optional(), device_count: z.number().int().optional(), created_by: z.string().optional(), created_on: z.string().optional(), updated_on: z.string().optional()}); export const getApiV0EnterpriseEnterpriseIdCreateApplyGeoFenceResponse = z.object({count: z.number().int(), next: z.string().nullable().optional(), previous: z.string().nullable().optional(), results: z.array(esperCloudApiGeofence)}); 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 Geofences in Enterprise * * GET /v0/enterprise/{enterprise_id}/create-apply-geo-fence/ */ export const getApiV0EnterpriseEnterpriseIdCreateApplyGeoFence = async (args: GetApiV0EnterpriseEnterpriseIdCreateApplyGeoFenceArgs, options?: GetApiV0EnterpriseEnterpriseIdCreateApplyGeoFenceOptions) => { const {baseUrl = "https://develop-api.esper.cloud/api", fetch: fetchFn = fetch, esperCloudApiApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.search != null) query.append("search", String(args.search)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (esperCloudApiApiKey !== undefined) headers.set('authorization', `Bearer ${esperCloudApiApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v0/enterprise/${encodeURIComponent(String(args.enterprise_id))}/create-apply-geo-fence/${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(getApiV0EnterpriseEnterpriseIdCreateApplyGeoFenceResponse, await res.json()) };