import {z} from 'zod' export type CreateApiConnectWebviewsCreateArgs = {body: {accepted_capabilities?: (Array<'lock' | 'thermostat' | 'noise_sensor' | 'access_control' | 'camera'>) | undefined, accepted_providers?: (Array<'hotek' | 'dormakaba_community' | 'legic_connect' | 'akuvox' | 'august' | 'avigilon_alta' | 'brivo' | 'butterflymx' | 'schlage' | 'smartthings' | 'yale' | 'genie' | 'doorking' | 'salto' | 'salto_ks' | 'salto_ks_accept' | 'lockly' | 'ttlock' | 'linear' | 'noiseaware' | 'nuki' | 'igloo' | 'kwikset' | 'minut' | 'my_2n' | 'controlbyweb' | 'nest' | 'igloohome' | 'ecobee' | 'four_suites' | 'dormakaba_oracode' | 'pti' | 'wyze' | 'seam_passport' | 'visionline' | 'assa_abloy_credential_service' | 'tedee' | 'honeywell_resideo' | 'first_alert' | 'latch' | 'akiles' | 'assa_abloy_vostio' | 'assa_abloy_vostio_credential_service' | 'tado' | 'salto_space' | 'sensi' | 'keynest' | 'korelock' | 'keyincode' | 'dormakaba_ambiance' | 'ultraloq' | 'dusaw' | 'sifely' | 'thirty_three_lock' | 'ring' | 'ical' | 'lodgify' | 'hostaway' | 'guesty' | 'acuity_scheduling' | 'omnitec' | 'kisi' | 'yale_access' | 'hid_cm' | 'google_nest' | 'slack'>) | undefined, automatically_manage_new_devices?: boolean | undefined, custom_metadata?: ({[key: string]: string | boolean | null}) | undefined, custom_redirect_failure_url?: string | undefined, custom_redirect_url?: string | undefined, customer_key?: string | undefined, excluded_providers?: Array | undefined, provider_category?: ('stable' | 'consumer_smartlocks' | 'beta' | 'thermostats' | 'noise_sensors' | 'access_control_systems' | 'cameras' | 'connectors' | 'internal_beta') | undefined, wait_for_device_creation?: boolean | undefined}}; export type CreateApiConnectWebviewsCreateOptions = {baseUrl?: string | undefined, clientSession?: string | undefined, fetch?: typeof fetch | undefined}; export const connectWebview = z.object({accepted_capabilities: z.array(z.enum(["lock", "thermostat", "noise_sensor", "access_control", "camera"])), accepted_providers: z.array(z.string()), any_provider_allowed: z.boolean(), authorized_at: z.string().nullable(), automatically_manage_new_devices: z.boolean(), connect_webview_id: z.string(), connected_account_id: z.string().nullable(), created_at: z.string(), custom_metadata: z.record(z.string(), z.union([z.string(), z.boolean()])), custom_redirect_failure_url: z.string().nullable(), custom_redirect_url: z.string().nullable(), customer_key: z.string().optional(), device_selection_mode: z.enum(["none", "single", "multiple"]), login_successful: z.boolean(), selected_provider: z.string().nullable(), status: z.enum(["pending", "failed", "authorized"]), url: z.string(), wait_for_device_creation: z.boolean(), workspace_id: z.string()}); export const createApiConnectWebviewsCreateResponse = z.object({connect_webview: connectWebview}); 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 Connect Webview * * POST /connect_webviews/create * * Also accepts auth: client_session_with_customer, pat_with_workspace, console_session_with_workspace, api_key */ export const createApiConnectWebviewsCreate = async (args: CreateApiConnectWebviewsCreateArgs, options?: CreateApiConnectWebviewsCreateOptions) => { const {baseUrl = "https://connect.getseam.com", fetch: fetchFn = fetch, clientSession} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (clientSession !== undefined) headers.set('authorization', `Bearer ${clientSession}`) const url = `${baseUrl.replace(/\/+$/, '')}/connect_webviews/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(createApiConnectWebviewsCreateResponse, await res.json()) };