import {z} from 'zod' export type LinkStationId = string; export type Name = string; export type PatchApiV1LinkStationsIdArgs = {id: LinkStationId, body: {name?: Name | undefined}}; export type PatchApiV1LinkStationsIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const linkStationId = z.string(); export const linkstationModelKey = z.literal("linkstation"); export const deviceState = z.enum(["CONNECTED", "CONNECTING", "DISCONNECTED"]); export const name = z.string(); export const mac = z.string(); export const linkStationIsAlarmHub = z.boolean(); export const linkStationLedIsEnabled = z.boolean(); export const linkStationLedSettings = z.object({isEnabled: linkStationLedIsEnabled}); export const linkStationLastEvent = z.number().nullable(); export const alarmHubStatus = z.object({armed: z.enum(["on", "off"]), battery: z.object({charging: z.enum(["on", "off"]).optional(), connection: z.enum(["connected", "disconnected"]).optional(), voltage: z.number().optional(), batteryStatus: z.enum(["ok", "low", "critical"]).optional()}).optional(), buckboost: z.enum(["on", "off"]), connector: z.object({emergency: z.object({"+": z.enum(["connected", "disconnected"]), "-": z.enum(["connected", "disconnected"])}).optional(), "12v": z.record(z.string(), z.object({"+": z.enum(["connected", "disconnected"]), "-": z.enum(["connected", "disconnected"])})).optional(), relay: z.record(z.string(), z.object({com: z.enum(["connected", "disconnected"]), nc: z.enum(["connected", "disconnected"]), no: z.enum(["connected", "disconnected"])})).optional(), tb: z.record(z.string(), z.object({"+": z.enum(["connected", "disconnected"]), "-": z.enum(["connected", "disconnected"])})).optional(), battery: z.enum(["connected", "disconnected"]).optional(), poeout: z.enum(["connected", "disconnected"]).optional()}).optional(), cover: z.object({distance: z.number().int().optional(), status: z.enum(["open", "close"]).optional()}).optional(), currentMeterChannelStatus: z.record(z.string(), z.object({criticalAlarm: z.enum(["normal", "alert"]), criticalThreshold: z.number(), value: z.number(), warningAlarm: z.enum(["normal", "alert"]), warningThreshold: z.number()})), currentMeterStatus: z.record(z.string(), z.object({critical: z.enum(["normal", "alert"]), efuse: z.enum(["normal", "warning", "fault"]), enable: z.enum(["on", "off"]), powerValid: z.enum(["normal", "alert"]), timingControl: z.enum(["normal", "alert"]), warning: z.enum(["normal", "alert"])})), inputPower: z.object({bt: z.enum(["low", "high"]).optional(), typ1: z.enum(["low", "high"]).optional(), typ2: z.enum(["low", "high"]).optional()}).optional(), poeout: z.object({connection: z.enum(["connected", "disconnected"]).optional(), powerSupply: z.enum(["on", "off"]).optional()}).optional(), powerMeter: z.record(z.string(), z.object({alarm: z.enum(["normal", "alert"]), current: z.number(), efuse: z.enum(["normal", "warning", "fault"]), enable: z.enum(["on", "off"]), power: z.number(), powerThreshold: z.number(), voltage: z.number()})), output: z.record(z.string(), z.object({enable: z.enum(["on", "off"]), active: z.enum(["on", "off"]), status: z.enum(["wet", "dry"]), delay: z.number().int().optional(), duration: z.number().int().optional(), name: z.string().optional()})), input: z.record(z.string(), z.object({enable: z.enum(["on", "off"]), type: z.union([z.literal("no"), z.literal("nc")]), eolr: z.number().int().gte(0).lte(2), resistor: z.number().gte(0).lte(10), status: z.enum(["normal", "alarm", "fault", "short", "cut"]), trigger: z.number().int(), name: z.string().optional(), inputType: z.enum(["MOTION", "ENTRY", "SMOKE", "GLASS_BREAK", "EMERGENCY_BUTTON"]).optional(), allowedArmingProfiles: z.array(z.string()).optional(), triggerWhenDisarmed: z.enum(["on", "off"]).optional(), triggerOnCurrentArmingProfile: z.enum(["on", "off"]).optional(), lastTriggeredAt: z.number().nullable().optional(), cameraId: z.string().nullable().optional(), powerReset: z.boolean().optional()})), inputTerminalStatus: z.record(z.string(), z.object({plusPinStatus: z.enum(["disabled", "idle", "not-connected", "tamper", "triggered", "cut", "short"]), minusPinStatus: z.enum(["disabled", "idle", "not-connected", "tamper", "triggered", "cut", "short"]), terminalStatus: z.enum(["disabled", "idle", "not-connected", "tamper", "triggered", "cut", "short", "partially-connected"]), idleSubState: z.enum(["open", "closed"]).optional()})).optional(), outputTerminalStatus: z.record(z.string(), z.object({pins: z.object({no: z.enum(["disabled", "idle", "not-connected", "tamper", "triggered", "cut", "short"]), com: z.enum(["disabled", "idle", "not-connected", "tamper", "triggered", "cut", "short"]), nc: z.enum(["disabled", "idle", "not-connected", "tamper", "triggered", "cut", "short"])}), statusLabel: z.enum(["disabled", "off", "active"]), mode: z.enum(["dry-contact", "powered-12v"]), efuseAlert: z.enum(["none", "high-current", "over-current"]), wiredPins: z.array(z.enum(["+", "-", "nc", "no", "com"]))})).optional(), emergencyTerminalStatus: z.object({plusPinStatus: z.enum(["disabled", "idle", "not-connected", "tamper", "triggered", "cut", "short"]), minusPinStatus: z.enum(["disabled", "idle", "not-connected", "tamper", "triggered", "cut", "short"]), terminalStatus: z.enum(["disabled", "idle", "not-connected", "tamper", "triggered", "cut", "short", "partially-connected"]), idleSubState: z.enum(["open", "closed"]).optional()}).nullable().optional(), auxiliaryPowerTerminalStatus: z.record(z.string(), z.object({plusPinStatus: z.enum(["disabled", "idle", "not-connected", "tamper", "triggered", "cut", "short"]), minusPinStatus: z.enum(["disabled", "idle", "not-connected", "tamper", "triggered", "cut", "short"]), status: z.enum(["not-connected", "partially-connected", "connected"]), currentMa: z.number().optional(), loadPercent: z.number().optional()})).optional()}); export const linkStation = z.object({id: linkStationId, modelKey: linkstationModelKey, state: deviceState, name: name.nullable(), mac: mac, isAlarmHub: linkStationIsAlarmHub, ledSettings: linkStationLedSettings, lastEvent: linkStationLastEvent, alarmHub: alarmHubStatus.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 }; /** * Patch link station settings * * PATCH /v1/link-stations/{id} */ export const patchApiV1LinkStationsId = async (args: PatchApiV1LinkStationsIdArgs, options?: PatchApiV1LinkStationsIdOptions) => { const {baseUrl = "https://api.ui.com/v1/connector/consoles/942A6FF664C0000000000964970E0000000009E710560000000068A9873F:9999999999/proxy/protect/integration", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v1/link-stations/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(linkStation, await res.json()) };