import {z} from 'zod' export type GetApiV1ResourceownerGeofence3Options = {baseUrl: string, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const geographicPosition = z.object({Latitude: z.number().optional(), Longitude: z.number().optional()}); export const geofencePolygon = z.object({Coordinates: z.array(geographicPosition).optional()}); export const timeSpan = z.object({Ticks: z.number().int().optional(), Days: z.number().int().optional(), Hours: z.number().int().optional(), Milliseconds: z.number().int().optional(), Microseconds: z.number().int().optional(), Nanoseconds: z.number().int().optional(), Minutes: z.number().int().optional(), Seconds: z.number().int().optional(), TotalDays: z.number().optional(), TotalHours: z.number().optional(), TotalMilliseconds: z.number().optional(), TotalMicroseconds: z.number().optional(), TotalNanoseconds: z.number().optional(), TotalMinutes: z.number().optional(), TotalSeconds: z.number().optional()}); export const geofenceScheduleModel = z.object({GeofenceScheduleId: z.number().int().optional(), Monday: z.boolean().optional(), Tuesday: z.boolean().optional(), Wednesday: z.boolean().optional(), Thursday: z.boolean().optional(), Friday: z.boolean().optional(), Saturday: z.boolean().optional(), Sunday: z.boolean().optional(), StartTime: timeSpan.optional(), EndTime: timeSpan.optional()}); export const geofenceModel3 = z.object({GeofenceId: z.number().int().optional(), Name: z.string().optional(), Description: z.string().optional(), GeofencePolygon: geofencePolygon.optional(), GeofenceType: z.union([z.literal(0), z.literal(1), z.literal(2)]).optional(), Schedules: z.array(geofenceScheduleModel).optional(), OrganizationNodeId: z.number().int().optional(), IsEditable: z.boolean().optional()}); export const getApiV1ResourceownerGeofence3Response = z.array(geofenceModel3); 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 a list of geofencese organization is associated with * * GET /v1/resourceowner/geofence3 */ export const getApiV1ResourceownerGeofence3 = async (options: GetApiV1ResourceownerGeofence3Options) => { const {baseUrl, fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/resourceowner/geofence3${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(getApiV1ResourceownerGeofence3Response, await res.json()) };