import {z} from 'zod' export type GetApiTimeClockV1TimeClocksTimeClockIdGeofencesFenceIdArgs = {fenceId: string, timeClockId: number}; export type GetApiTimeClockV1TimeClocksTimeClockIdGeofencesFenceIdOptions = {baseUrl?: string | undefined, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const geoFenceJobIdsMode = z.enum(["any", "specific", "anyExcept"]); export const exitGeofenceAction = z.enum(["noAction", "sendNotification", "autoClockOut"]); export const gpsLocation = z.object({address: z.string(), latitude: z.string(), longitude: z.string()}); export const geoFenceWithFenceIdEntity = z.object({id: z.string(), name: z.string().min(1), isEnabled: z.boolean().optional(), fenceSize: z.number().int().gte(75).lte(1524).optional(), jobIds: z.array(z.string()).optional(), jobIdsMode: geoFenceJobIdsMode.optional(), onGeofenceExitAction: exitGeofenceAction.optional(), location: gpsLocation}); export const aPIResponseGeoFenceWithFenceIdEntity = z.object({requestId: z.string().optional(), data: geoFenceWithFenceIdEntity}); 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 geofence * * GET /time-clock/v1/time-clocks/{timeClockId}/geofences/{fenceId} * * Also accepts auth: OAuth2 */ export const getApiTimeClockV1TimeClocksTimeClockIdGeofencesFenceId = async (args: GetApiTimeClockV1TimeClocksTimeClockIdGeofencesFenceIdArgs, options?: GetApiTimeClockV1TimeClocksTimeClockIdGeofencesFenceIdOptions) => { const {baseUrl = "https://api.connecteam.com", fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (APIKeyHeader !== undefined) headers.set("X-API-KEY", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/time-clock/v1/time-clocks/${encodeURIComponent(String(args.timeClockId))}/geofences/${encodeURIComponent(String(args.fenceId))}${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(aPIResponseGeoFenceWithFenceIdEntity, await res.json()) };