import {z} from 'zod' export type CreateApiAcsCredentialsListArgs = {body: {acs_user_id: string, created_before?: string | undefined, is_multi_phone_sync_credential?: boolean | undefined, limit?: number | undefined, page_cursor?: (string | null) | undefined, search?: string | undefined} | {acs_system_id: string, created_before?: string | undefined, is_multi_phone_sync_credential?: boolean | undefined, limit?: number | undefined, page_cursor?: (string | null) | undefined, search?: string | undefined} | {acs_system_id: string, acs_user_id: string, created_before?: string | undefined, is_multi_phone_sync_credential?: boolean | undefined, limit?: number | undefined, page_cursor?: (string | null) | undefined, search?: string | undefined} | {user_identity_id: string, created_before?: string | undefined, is_multi_phone_sync_credential?: boolean | undefined, limit?: number | undefined, page_cursor?: (string | null) | undefined, search?: string | undefined} | {created_before?: string | undefined, is_multi_phone_sync_credential?: boolean | undefined, limit?: number | undefined, page_cursor?: (string | null) | undefined, search?: string | undefined}}; export type CreateApiAcsCredentialsListOptions = {baseUrl?: string | undefined, apiKey?: 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 pagination = z.object({has_next_page: z.boolean(), next_page_cursor: z.string().nullable(), next_page_url: z.string().nullable()}); export const createApiAcsCredentialsListResponse = z.object({acs_credentials: z.array(acsCredential), pagination: pagination}); 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 }; /** * List Credentials * * POST /acs/credentials/list * * Also accepts auth: client_session, pat_with_workspace, console_session_with_workspace */ export const createApiAcsCredentialsList = async (args: CreateApiAcsCredentialsListArgs, options?: CreateApiAcsCredentialsListOptions) => { const {baseUrl = "https://connect.getseam.com", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (apiKey !== undefined) headers.set('authorization', `Bearer ${apiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/acs/credentials/list${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(createApiAcsCredentialsListResponse, await res.json()) };