/* * Automatically generated by codegen/smith.ts. * Do not edit this file or add other files to this directory. */ import { seamApiLtsVersion } from 'lib/lts-version.js' import { getAuthHeadersForClientSessionToken, warnOnInsecureuserIdentifierKey, } from 'lib/seam/connect/auth.js' import { type Client, createClient } from 'lib/seam/connect/client.js' import { isSeamHttpOptionsWithApiKey, isSeamHttpOptionsWithClient, isSeamHttpOptionsWithClientSessionToken, isSeamHttpOptionsWithConsoleSessionToken, isSeamHttpOptionsWithPersonalAccessToken, type SeamHttpFromPublishableKeyOptions, SeamHttpInvalidOptionsError, type SeamHttpOptions, type SeamHttpOptionsWithApiKey, type SeamHttpOptionsWithClient, type SeamHttpOptionsWithClientSessionToken, type SeamHttpOptionsWithConsoleSessionToken, type SeamHttpOptionsWithPersonalAccessToken, type SeamHttpRequestOptions, } from 'lib/seam/connect/options.js' import { limitToSeamHttpRequestOptions, parseOptions, } from 'lib/seam/connect/parse-options.js' import type { ActionAttempt } from 'lib/seam/connect/resources/action-attempt.js' import type { Device } from 'lib/seam/connect/resources/device.js' import { SeamHttpClientSessions } from 'lib/seam/connect/routes/client-sessions/index.js' import { SeamHttpRequest } from 'lib/seam/connect/seam-http-request.js' import { SeamPaginator } from 'lib/seam/connect/seam-paginator.js' import { SeamHttpLocksSimulate } from './simulate/index.js' export class SeamHttpLocks { client: Client readonly defaults: Required readonly ltsVersion = seamApiLtsVersion static ltsVersion = seamApiLtsVersion constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) { const options = parseOptions(apiKeyOrOptions) this.client = 'client' in options ? options.client : createClient(options) this.defaults = limitToSeamHttpRequestOptions(options) } static fromClient( client: SeamHttpOptionsWithClient['client'], options: Omit = {}, ): SeamHttpLocks { const constructorOptions = { ...options, client } if (!isSeamHttpOptionsWithClient(constructorOptions)) { throw new SeamHttpInvalidOptionsError('Missing client') } return new SeamHttpLocks(constructorOptions) } static fromApiKey( apiKey: SeamHttpOptionsWithApiKey['apiKey'], options: Omit = {}, ): SeamHttpLocks { const constructorOptions = { ...options, apiKey } if (!isSeamHttpOptionsWithApiKey(constructorOptions)) { throw new SeamHttpInvalidOptionsError('Missing apiKey') } return new SeamHttpLocks(constructorOptions) } static fromClientSessionToken( clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'], options: Omit< SeamHttpOptionsWithClientSessionToken, 'clientSessionToken' > = {}, ): SeamHttpLocks { const constructorOptions = { ...options, clientSessionToken } if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) { throw new SeamHttpInvalidOptionsError('Missing clientSessionToken') } return new SeamHttpLocks(constructorOptions) } static async fromPublishableKey( publishableKey: string, userIdentifierKey: string, options: SeamHttpFromPublishableKeyOptions = {}, ): Promise { warnOnInsecureuserIdentifierKey(userIdentifierKey) const clientOptions = parseOptions({ ...options, publishableKey }) if (isSeamHttpOptionsWithClient(clientOptions)) { throw new SeamHttpInvalidOptionsError( 'The client option cannot be used with SeamHttpLocks.fromPublishableKey', ) } const client = createClient(clientOptions) const clientSessions = SeamHttpClientSessions.fromClient(client) const { token } = await clientSessions.getOrCreate({ user_identifier_key: userIdentifierKey, }) return SeamHttpLocks.fromClientSessionToken(token, options) } static fromConsoleSessionToken( consoleSessionToken: SeamHttpOptionsWithConsoleSessionToken['consoleSessionToken'], workspaceId: SeamHttpOptionsWithConsoleSessionToken['workspaceId'], options: Omit< SeamHttpOptionsWithConsoleSessionToken, 'consoleSessionToken' | 'workspaceId' > = {}, ): SeamHttpLocks { const constructorOptions = { ...options, consoleSessionToken, workspaceId } if (!isSeamHttpOptionsWithConsoleSessionToken(constructorOptions)) { throw new SeamHttpInvalidOptionsError( 'Missing consoleSessionToken or workspaceId', ) } return new SeamHttpLocks(constructorOptions) } static fromPersonalAccessToken( personalAccessToken: SeamHttpOptionsWithPersonalAccessToken['personalAccessToken'], workspaceId: SeamHttpOptionsWithPersonalAccessToken['workspaceId'], options: Omit< SeamHttpOptionsWithPersonalAccessToken, 'personalAccessToken' | 'workspaceId' > = {}, ): SeamHttpLocks { const constructorOptions = { ...options, personalAccessToken, workspaceId } if (!isSeamHttpOptionsWithPersonalAccessToken(constructorOptions)) { throw new SeamHttpInvalidOptionsError( 'Missing personalAccessToken or workspaceId', ) } return new SeamHttpLocks(constructorOptions) } createPaginator( request: SeamHttpRequest, ): SeamPaginator { return new SeamPaginator(this, request) } async updateClientSessionToken( clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'], ): Promise { const { headers } = this.client.defaults const authHeaders = getAuthHeadersForClientSessionToken({ clientSessionToken, }) for (const key of Object.keys(authHeaders)) { if (headers[key] == null) { throw new Error( 'Cannot update a clientSessionToken on a client created without a clientSessionToken', ) } } this.client.defaults.headers = { ...headers, ...authHeaders } const clientSessions = SeamHttpClientSessions.fromClient(this.client) await clientSessions.get() } get simulate(): SeamHttpLocksSimulate { return SeamHttpLocksSimulate.fromClient(this.client, this.defaults) } /** * Configures the auto-lock setting for a specified [lock](https://docs.seam.co/low-level-apis/smart-locks). */ configureAutoLock( parameters: LocksConfigureAutoLockParameters, options: LocksConfigureAutoLockOptions = {}, ): LocksConfigureAutoLockRequest { return new SeamHttpRequest(this, { pathname: '/locks/configure_auto_lock', method: 'POST', body: parameters, responseKey: 'action_attempt', options, }) } /** * Returns a specified [lock](https://docs.seam.co/low-level-apis/smart-locks). * @deprecated Use `/devices/get` instead. */ get( parameters?: LocksGetParameters, options: LocksGetOptions = {}, ): LocksGetRequest { return new SeamHttpRequest(this, { pathname: '/locks/get', method: 'POST', body: parameters, responseKey: 'device', options, }) } /** * Returns a list of all [locks](https://docs.seam.co/low-level-apis/smart-locks). */ list( parameters?: LocksListParameters, options: LocksListOptions = {}, ): LocksListRequest { return new SeamHttpRequest(this, { pathname: '/locks/list', method: 'POST', body: parameters, responseKey: 'devices', options, }) } /** * Locks a [lock](https://docs.seam.co/low-level-apis/smart-locks). See also [Locking and Unlocking Smart Locks](https://docs.seam.co/low-level-apis/smart-locks/lock-and-unlock). */ lockDoor( parameters: LocksLockDoorParameters, options: LocksLockDoorOptions = {}, ): LocksLockDoorRequest { return new SeamHttpRequest(this, { pathname: '/locks/lock_door', method: 'POST', body: parameters, responseKey: 'action_attempt', options, }) } /** * Unlocks a [lock](https://docs.seam.co/low-level-apis/smart-locks). See also [Locking and Unlocking Smart Locks](https://docs.seam.co/low-level-apis/smart-locks/lock-and-unlock). */ unlockDoor( parameters: LocksUnlockDoorParameters, options: LocksUnlockDoorOptions = {}, ): LocksUnlockDoorRequest { return new SeamHttpRequest(this, { pathname: '/locks/unlock_door', method: 'POST', body: parameters, responseKey: 'action_attempt', options, }) } } export type LocksConfigureAutoLockParameters = { /** * Delay in seconds before the lock automatically locks. Required when enabling auto-lock. Must be between 1 and 60. */ auto_lock_delay_seconds?: number | undefined /** * Whether to enable or disable auto-lock. */ auto_lock_enabled: boolean /** * ID of the lock for which you want to configure the auto-lock. */ device_id: string } /** * @deprecated Use LocksConfigureAutoLockRequest instead. */ export type LocksConfigureAutoLockResponse = { action_attempt: ActionAttempt } export type LocksConfigureAutoLockRequest = SeamHttpRequest< LocksConfigureAutoLockResponse, 'action_attempt' > export type LocksConfigureAutoLockOptions = Pick< SeamHttpRequestOptions, 'waitForActionAttempt' > export type LocksGetParameters = { /** * ID of the lock that you want to get. */ device_id?: string | undefined /** * Name of the lock that you want to get. */ name?: string | undefined } /** * @deprecated Use LocksGetRequest instead. */ export type LocksGetResponse = { device: Device } export type LocksGetRequest = SeamHttpRequest export interface LocksGetOptions {} export type LocksListParameters = { /** * ID of the Connect Webview for which you want to list devices. */ connect_webview_id?: string | undefined /** * ID of the connected account for which you want to list devices. */ connected_account_id?: string | undefined /** * Array of IDs of the connected accounts for which you want to list devices. */ connected_account_ids?: Array | undefined /** * Timestamp by which to limit returned devices. Returns devices created before this timestamp. */ created_before?: string | undefined /** * Set of key:value [custom metadata](https://docs.seam.co/core-concepts/devices/adding-custom-metadata-to-a-device) pairs for which you want to list devices. */ custom_metadata_has?: Record | undefined /** * Customer key for which you want to list devices. */ customer_key?: string | undefined /** * Array of device IDs for which you want to list devices. */ device_ids?: Array | undefined /** * Device type of the locks that you want to list. */ device_type?: | 'akuvox_lock' | 'august_lock' | 'brivo_access_point' | 'butterflymx_panel' | 'avigilon_alta_entry' | 'doorking_lock' | 'genie_door' | 'igloo_lock' | 'linear_lock' | 'lockly_lock' | 'kwikset_lock' | 'nuki_lock' | 'salto_lock' | 'schlage_lock' | 'smartthings_lock' | 'wyze_lock' | 'yale_lock' | 'two_n_intercom' | 'controlbyweb_device' | 'ttlock_lock' | 'igloohome_lock' | 'four_suites_door' | 'dormakaba_oracode_door' | 'tedee_lock' | 'akiles_lock' | 'ultraloq_lock' | 'keyincode_lock' | 'omnitec_lock' | 'kisi_lock' | 'aqara_lock' | undefined /** * Device types of the locks that you want to list. */ device_types?: | Array< | 'akuvox_lock' | 'august_lock' | 'brivo_access_point' | 'butterflymx_panel' | 'avigilon_alta_entry' | 'doorking_lock' | 'genie_door' | 'igloo_lock' | 'linear_lock' | 'lockly_lock' | 'kwikset_lock' | 'nuki_lock' | 'salto_lock' | 'schlage_lock' | 'smartthings_lock' | 'wyze_lock' | 'yale_lock' | 'two_n_intercom' | 'controlbyweb_device' | 'ttlock_lock' | 'igloohome_lock' | 'four_suites_door' | 'dormakaba_oracode_door' | 'tedee_lock' | 'akiles_lock' | 'ultraloq_lock' | 'keyincode_lock' | 'omnitec_lock' | 'kisi_lock' | 'aqara_lock' > | undefined /** * Numerical limit on the number of devices to return. */ limit?: number | undefined /** * Manufacturer of the locks that you want to list. */ manufacturer?: | 'akuvox' | 'august' | 'brivo' | 'butterflymx' | 'avigilon_alta' | 'doorking' | 'genie' | 'igloo' | 'linear' | 'lockly' | 'kwikset' | 'nuki' | 'salto' | 'schlage' | 'seam' | 'wyze' | 'yale' | 'two_n' | 'controlbyweb' | 'ttlock' | 'igloohome' | 'four_suites' | 'dormakaba_oracode' | 'tedee' | 'keyincode' | 'akiles' | 'aqara' | 'korelock' | 'smartthings' | 'ultraloq' | 'omnitec' | 'kisi' | undefined /** * Identifies the specific page of results to return, obtained from the previous page's `next_page_cursor`. */ page_cursor?: string | undefined /** * String for which to search. Filters returned devices to include all records that satisfy a partial match using `device_id` (full or partial UUID prefix, minimum 4 characters), `connected_account_id`, `display_name`, `custom_metadata` or `location.location_name`. */ search?: string | undefined /** * ID of the space for which you want to list devices. */ space_id?: string | undefined /** * @deprecated Use `space_id`. */ unstable_location_id?: string | undefined /** * Your own internal user ID for the user for which you want to list devices. */ user_identifier_key?: string | undefined } /** * @deprecated Use LocksListRequest instead. */ export type LocksListResponse = { devices: Array } export type LocksListRequest = SeamHttpRequest export interface LocksListOptions {} export type LocksLockDoorParameters = { /** * ID of the lock that you want to lock. */ device_id: string } /** * @deprecated Use LocksLockDoorRequest instead. */ export type LocksLockDoorResponse = { action_attempt: ActionAttempt } export type LocksLockDoorRequest = SeamHttpRequest< LocksLockDoorResponse, 'action_attempt' > export type LocksLockDoorOptions = Pick< SeamHttpRequestOptions, 'waitForActionAttempt' > export type LocksUnlockDoorParameters = { /** * ID of the lock that you want to unlock. */ device_id: string } /** * @deprecated Use LocksUnlockDoorRequest instead. */ export type LocksUnlockDoorResponse = { action_attempt: ActionAttempt } export type LocksUnlockDoorRequest = SeamHttpRequest< LocksUnlockDoorResponse, 'action_attempt' > export type LocksUnlockDoorOptions = Pick< SeamHttpRequestOptions, 'waitForActionAttempt' >