import {z} from 'zod' export type CreateApiAcsCredentialsCreateArgs = {body: {access_method: 'code' | 'card' | 'mobile_key' | 'cloud_key', acs_system_id?: string | undefined, acs_user_id?: string | undefined, allowed_acs_entrance_ids?: Array | undefined, assa_abloy_vostio_metadata?: ({auto_join?: boolean | undefined, join_all_guest_acs_entrances?: boolean | undefined, override_all_guest_acs_entrances?: boolean | undefined, override_guest_acs_entrance_ids?: Array | undefined}) | undefined, code?: string | undefined, credential_manager_acs_system_id?: string | undefined, ends_at?: string | undefined, is_multi_phone_sync_credential?: boolean | undefined, salto_space_metadata?: ({assign_new_key?: boolean | undefined}) | undefined, starts_at?: string | undefined, user_identity_id?: string | undefined, visionline_metadata?: ({auto_join?: boolean | undefined, card_format?: ('TLCode' | 'rfid48') | undefined, card_function_type?: ('guest' | 'staff') | undefined, joiner_acs_credential_ids?: Array | undefined, override?: boolean | undefined}) | undefined}}; export type CreateApiAcsCredentialsCreateOptions = {baseUrl?: string | undefined, patWithWorkspace?: string | undefined, fetch?: typeof fetch | undefined}; export const acsCredential = z.object({access_method: z.enum(["code", "card", "mobile_key", "cloud_key"]), acs_credential_id: z.string(), acs_credential_pool_id: z.string().optional(), acs_system_id: z.string(), acs_user_id: z.string().optional(), assa_abloy_vostio_metadata: z.object({auto_join: z.boolean().optional(), door_names: z.array(z.string()).optional(), endpoint_id: z.string().optional(), key_id: z.string().optional(), key_issuing_request_id: z.string().optional(), override_guest_acs_entrance_ids: z.array(z.string()).optional()}).optional(), card_number: z.string().nullable().optional(), code: z.string().nullable().optional(), connected_account_id: z.string(), created_at: z.string(), display_name: z.string().min(1), ends_at: z.string().optional(), errors: z.array(z.object({error_code: z.string(), message: z.string()})), external_type: z.enum(["pti_card", "brivo_credential", "hid_credential", "visionline_card", "salto_ks_credential", "assa_abloy_vostio_key", "salto_space_key", "latch_access", "dormakaba_ambiance_credential", "hotek_card", "salto_ks_tag", "avigilon_alta_credential", "kisi_credential"]).optional(), external_type_display_name: z.string().optional(), is_issued: z.boolean().optional(), is_latest_desired_state_synced_with_provider: z.boolean().nullable().optional(), is_managed: z.literal(true), is_multi_phone_sync_credential: z.boolean().optional(), is_one_time_use: z.boolean().optional(), issued_at: z.string().nullable().optional(), latest_desired_state_synced_with_provider_at: z.string().nullable().optional(), parent_acs_credential_id: z.string().optional(), starts_at: z.string().optional(), user_identity_id: z.string().optional(), visionline_metadata: z.object({auto_join: z.boolean().optional(), card_function_type: z.enum(["guest", "staff"]).optional(), card_id: z.string().optional(), common_acs_entrance_ids: z.array(z.string()).optional(), credential_id: z.string().optional(), guest_acs_entrance_ids: z.array(z.string()).optional(), is_valid: z.boolean().optional(), joiner_acs_credential_ids: z.array(z.string()).optional()}).optional(), warnings: z.array(z.object({error_code: z.string().optional(), message: z.string().optional(), created_at: z.string().optional()})), workspace_id: z.string()}); export const createApiAcsCredentialsCreateResponse = z.object({acs_credential: acsCredential}); 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 }; /** * Create a Credential for an ACS User * * POST /acs/credentials/create * * Also accepts auth: console_session_with_workspace, api_key */ export const createApiAcsCredentialsCreate = async (args: CreateApiAcsCredentialsCreateArgs, options?: CreateApiAcsCredentialsCreateOptions) => { 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/credentials/create${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(createApiAcsCredentialsCreateResponse, await res.json()) };