import {z} from 'zod' export type CreateApiAcsSystemsGetArgs = {body: {acs_system_id: string}}; export type CreateApiAcsSystemsGetOptions = {baseUrl?: string | undefined, patWithWorkspace?: string | undefined, fetch?: typeof fetch | undefined}; export const acsSystem = z.object({acs_access_group_count: z.number().optional(), acs_system_id: z.string(), acs_user_count: z.number().optional(), connected_account_id: z.string(), connected_account_ids: z.array(z.string()), created_at: z.string(), default_credential_manager_acs_system_id: z.string().nullable().optional(), errors: z.array(z.object({error_code: z.string().optional(), message: z.string().optional(), created_at: z.string().optional()})), external_type: z.enum(["pti_site", "avigilon_alta_org", "salto_ks_site", "salto_space_system", "brivo_account", "hid_credential_manager_organization", "visionline_system", "assa_abloy_credential_service", "latch_building", "dormakaba_community_site", "dormakaba_ambiance_site", "legic_connect_credential_service", "assa_abloy_vostio", "assa_abloy_vostio_credential_service", "hotek_site", "kisi_organization"]).optional(), external_type_display_name: z.string().optional(), image_alt_text: z.string(), image_url: z.string(), is_credential_manager: z.boolean(), location: z.object({time_zone: z.string().nullable()}), name: z.string(), system_type: z.enum(["pti_site", "avigilon_alta_org", "salto_ks_site", "salto_space_system", "brivo_account", "hid_credential_manager_organization", "visionline_system", "assa_abloy_credential_service", "latch_building", "dormakaba_community_site", "dormakaba_ambiance_site", "legic_connect_credential_service", "assa_abloy_vostio", "assa_abloy_vostio_credential_service", "hotek_site", "kisi_organization"]).optional(), system_type_display_name: z.string().optional(), visionline_metadata: z.object({lan_address: z.string().optional(), mobile_access_uuid: z.string().optional(), system_id: z.string().optional()}).optional(), warnings: z.array(z.discriminatedUnion("warning_code", [z.object({created_at: z.string(), message: z.string(), warning_code: z.literal("salto_ks_subscription_limit_almost_reached")}), z.object({created_at: z.string(), message: z.string(), misconfigured_acs_entrance_ids: z.array(z.string()).optional(), warning_code: z.literal("time_zone_does_not_match_location")}), z.object({created_at: z.string(), message: z.string(), warning_code: z.literal("setup_required")})])), workspace_id: z.string()}); export const createApiAcsSystemsGetResponse = z.object({acs_system: acsSystem}); 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 an ACS System * * POST /acs/systems/get * * Also accepts auth: console_session_with_workspace, api_key */ export const createApiAcsSystemsGet = async (args: CreateApiAcsSystemsGetArgs, options?: CreateApiAcsSystemsGetOptions) => { const {baseUrl = "https://connect.getseam.com", fetch: fetchFn = fetch, patWithWorkspace} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (patWithWorkspace !== undefined) headers.set('authorization', `Bearer ${patWithWorkspace}`) const url = `${baseUrl.replace(/\/+$/, '')}/acs/systems/get${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(createApiAcsSystemsGetResponse, await res.json()) };