import {z} from 'zod' export type CreateApiV0EnterpriseEnterpriseIdCreateApplyGeoFenceArgs = {enterprise_id: string, body: BodyInit}; export type CreateApiV0EnterpriseEnterpriseIdCreateApplyGeoFenceOptions = {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 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 }; /** * Create a geofence * * POST /v0/enterprise/{enterprise_id}/create-apply-geo-fence/ */ export const createApiV0EnterpriseEnterpriseIdCreateApplyGeoFence = async (args: CreateApiV0EnterpriseEnterpriseIdCreateApplyGeoFenceArgs, options?: CreateApiV0EnterpriseEnterpriseIdCreateApplyGeoFenceOptions) => { const {baseUrl = "https://develop-api.esper.cloud/api", fetch: fetchFn = fetch, esperCloudApiApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "*/*") headers.set('accept', "application/json") 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: "POST", headers, body: args.body}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(esperCloudApiGeofence, await res.json()) };