import {z} from 'zod' export type ArmProfileId = string; export type ArmProfileName = string; export type AutomationId = string; export type Automations = Array; export type ArmScheduleStart = string; export type ArmScheduleEnd = string; export type ArmSchedule = {start: ArmScheduleStart, end: ArmScheduleEnd}; export type Schedules = Array; export type RecordEverything = boolean; export type ActivationDelay = number | number | number | number; export type PatchApiV1ArmProfilesIdArgs = {id: ArmProfileId, body: {name?: ArmProfileName | undefined, automations?: Automations | undefined, schedules?: Schedules | undefined, recordEverything?: RecordEverything | undefined, activationDelay?: ActivationDelay | undefined}}; export type PatchApiV1ArmProfilesIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const armProfileId = z.string(); export const armProfileName = z.string().min(1).max(255); export const automationId = z.string(); export const automations = z.array(automationId); export const userId = z.string(); export const armScheduleStart = z.string(); export const armScheduleEnd = z.string(); export const armSchedule = z.object({start: armScheduleStart, end: armScheduleEnd}); export const schedules = z.array(armSchedule); export const recordEverything = z.boolean(); export const activationDelay = z.union([z.literal(0), z.literal(60000), z.literal(300000), z.literal(600000)]); export const createdAt = z.number(); export const updatedAt = z.number(); export const armProfile = z.object({id: armProfileId, name: armProfileName, automations: automations, creator: userId.nullable(), schedules: schedules, recordEverything: recordEverything, activationDelay: activationDelay, createdAt: createdAt, updatedAt: updatedAt}); 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 }; /** * Update arm profile * * PATCH /v1/arm-profiles/{id} */ export const patchApiV1ArmProfilesId = async (args: PatchApiV1ArmProfilesIdArgs, options?: PatchApiV1ArmProfilesIdOptions) => { 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/arm-profiles/${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(armProfile, await res.json()) };