/* * 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 { ConnectedAccount } from 'lib/seam/connect/resources/connected-account.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 { SeamHttpConnectedAccountsSimulate } from './simulate/index.js' export class SeamHttpConnectedAccounts { 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 = {}, ): SeamHttpConnectedAccounts { const constructorOptions = { ...options, client } if (!isSeamHttpOptionsWithClient(constructorOptions)) { throw new SeamHttpInvalidOptionsError('Missing client') } return new SeamHttpConnectedAccounts(constructorOptions) } static fromApiKey( apiKey: SeamHttpOptionsWithApiKey['apiKey'], options: Omit = {}, ): SeamHttpConnectedAccounts { const constructorOptions = { ...options, apiKey } if (!isSeamHttpOptionsWithApiKey(constructorOptions)) { throw new SeamHttpInvalidOptionsError('Missing apiKey') } return new SeamHttpConnectedAccounts(constructorOptions) } static fromClientSessionToken( clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'], options: Omit< SeamHttpOptionsWithClientSessionToken, 'clientSessionToken' > = {}, ): SeamHttpConnectedAccounts { const constructorOptions = { ...options, clientSessionToken } if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) { throw new SeamHttpInvalidOptionsError('Missing clientSessionToken') } return new SeamHttpConnectedAccounts(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 SeamHttpConnectedAccounts.fromPublishableKey', ) } const client = createClient(clientOptions) const clientSessions = SeamHttpClientSessions.fromClient(client) const { token } = await clientSessions.getOrCreate({ user_identifier_key: userIdentifierKey, }) return SeamHttpConnectedAccounts.fromClientSessionToken(token, options) } static fromConsoleSessionToken( consoleSessionToken: SeamHttpOptionsWithConsoleSessionToken['consoleSessionToken'], workspaceId: SeamHttpOptionsWithConsoleSessionToken['workspaceId'], options: Omit< SeamHttpOptionsWithConsoleSessionToken, 'consoleSessionToken' | 'workspaceId' > = {}, ): SeamHttpConnectedAccounts { const constructorOptions = { ...options, consoleSessionToken, workspaceId } if (!isSeamHttpOptionsWithConsoleSessionToken(constructorOptions)) { throw new SeamHttpInvalidOptionsError( 'Missing consoleSessionToken or workspaceId', ) } return new SeamHttpConnectedAccounts(constructorOptions) } static fromPersonalAccessToken( personalAccessToken: SeamHttpOptionsWithPersonalAccessToken['personalAccessToken'], workspaceId: SeamHttpOptionsWithPersonalAccessToken['workspaceId'], options: Omit< SeamHttpOptionsWithPersonalAccessToken, 'personalAccessToken' | 'workspaceId' > = {}, ): SeamHttpConnectedAccounts { const constructorOptions = { ...options, personalAccessToken, workspaceId } if (!isSeamHttpOptionsWithPersonalAccessToken(constructorOptions)) { throw new SeamHttpInvalidOptionsError( 'Missing personalAccessToken or workspaceId', ) } return new SeamHttpConnectedAccounts(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(): SeamHttpConnectedAccountsSimulate { return SeamHttpConnectedAccountsSimulate.fromClient( this.client, this.defaults, ) } /** * Deletes a specified [connected account](https://docs.seam.co/core-concepts/connected-accounts). * * Deleting a connected account triggers a `connected_account.deleted` event and removes the connected account and all data associated with the connected account from Seam, including devices, events, access codes, and so on. For every deleted resource, Seam sends a corresponding deleted event, but the resource is not deleted from the provider. * * For example, if you delete a connected account with a device that has an access code, Seam sends a `connected_account.deleted` event, a `device.deleted` event, and an `access_code.deleted` event, but Seam does not remove the access code from the device. */ delete( parameters: ConnectedAccountsDeleteParameters, options: ConnectedAccountsDeleteOptions = {}, ): ConnectedAccountsDeleteRequest { return new SeamHttpRequest(this, { pathname: '/connected_accounts/delete', method: 'POST', body: parameters, responseKey: undefined, options, }) } /** * Returns a specified [connected account](https://docs.seam.co/core-concepts/connected-accounts). */ get( parameters?: ConnectedAccountsGetParameters, options: ConnectedAccountsGetOptions = {}, ): ConnectedAccountsGetRequest { return new SeamHttpRequest(this, { pathname: '/connected_accounts/get', method: 'GET', params: parameters, responseKey: 'connected_account', options, }) } /** * Returns a list of all [connected accounts](https://docs.seam.co/core-concepts/connected-accounts). */ list( parameters?: ConnectedAccountsListParameters, options: ConnectedAccountsListOptions = {}, ): ConnectedAccountsListRequest { return new SeamHttpRequest(this, { pathname: '/connected_accounts/list', method: 'POST', body: parameters, responseKey: 'connected_accounts', options, }) } /** * Request a [connected account](https://docs.seam.co/core-concepts/connected-accounts) sync attempt for the specified `connected_account_id`. */ sync( parameters: ConnectedAccountsSyncParameters, options: ConnectedAccountsSyncOptions = {}, ): ConnectedAccountsSyncRequest { return new SeamHttpRequest(this, { pathname: '/connected_accounts/sync', method: 'POST', body: parameters, responseKey: undefined, options, }) } /** * Updates a [connected account](https://docs.seam.co/core-concepts/connected-accounts). */ update( parameters: ConnectedAccountsUpdateParameters, options: ConnectedAccountsUpdateOptions = {}, ): ConnectedAccountsUpdateRequest { return new SeamHttpRequest(this, { pathname: '/connected_accounts/update', method: 'PATCH', body: parameters, responseKey: undefined, options, }) } } export type ConnectedAccountsDeleteParameters = { /** * ID of the connected account that you want to delete. */ connected_account_id: string } /** * @deprecated Use ConnectedAccountsDeleteRequest instead. */ export type ConnectedAccountsDeleteResponse = void export type ConnectedAccountsDeleteRequest = SeamHttpRequest export interface ConnectedAccountsDeleteOptions {} export type ConnectedAccountsGetParameters = { /** * ID of the connected account that you want to get. */ connected_account_id?: string | undefined /** * Email address associated with the connected account that you want to get. */ email?: string | undefined } /** * @deprecated Use ConnectedAccountsGetRequest instead. */ export type ConnectedAccountsGetResponse = { connected_account: ConnectedAccount } export type ConnectedAccountsGetRequest = SeamHttpRequest< ConnectedAccountsGetResponse, 'connected_account' > export interface ConnectedAccountsGetOptions {} export type ConnectedAccountsListParameters = { /** * Custom metadata pairs by which you want to filter connected accounts. Returns connected accounts with `custom_metadata` that contains all of the provided key:value pairs. */ custom_metadata_has?: Record | undefined /** * Customer key by which you want to filter connected accounts. */ customer_key?: string | undefined /** * Maximum number of records to return per page. */ limit?: number | 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 connected accounts to include all records that satisfy a partial match using `connected_account_id`, `account_type`, `customer_key`, `custom_metadata`, `user_identifier.username`, `user_identifier.email` or `user_identifier.phone`. */ search?: string | undefined /** * ID of the space by which you want to filter connected accounts. */ space_id?: string | undefined /** * Your user ID for the user by which you want to filter connected accounts. */ user_identifier_key?: string | undefined } /** * @deprecated Use ConnectedAccountsListRequest instead. */ export type ConnectedAccountsListResponse = { connected_accounts: Array } export type ConnectedAccountsListRequest = SeamHttpRequest< ConnectedAccountsListResponse, 'connected_accounts' > export interface ConnectedAccountsListOptions {} export type ConnectedAccountsSyncParameters = { /** * ID of the connected account that you want to sync. */ connected_account_id: string } /** * @deprecated Use ConnectedAccountsSyncRequest instead. */ export type ConnectedAccountsSyncResponse = void export type ConnectedAccountsSyncRequest = SeamHttpRequest export interface ConnectedAccountsSyncOptions {} export type ConnectedAccountsUpdateParameters = { /** * List of accepted device capabilities that restrict the types of devices that can be connected through this connected account. Valid values are `lock`, `thermostat`, `noise_sensor`, and `access_control`. */ accepted_capabilities?: | Array< 'lock' | 'thermostat' | 'noise_sensor' | 'access_control' | 'camera' > | undefined /** * Indicates whether newly-added devices should appear as [managed devices](https://docs.seam.co/core-concepts/devices/managed-and-unmanaged-devices). */ automatically_manage_new_devices?: boolean | undefined /** * ID of the connected account that you want to update. */ connected_account_id: string /** * Custom metadata that you want to associate with the connected account. Entirely replaces the existing custom metadata object. If a new Connect Webview contains custom metadata and is used to reconnect a connected account, the custom metadata from the Connect Webview will entirely replace the entire custom metadata object on the connected account. Supports up to 50 JSON key:value pairs. [Adding custom metadata to a connected account](https://docs.seam.co/core-concepts/connected-accounts/adding-custom-metadata-to-a-connected-account) enables you to store custom information, like customer details or internal IDs from your application. Then, you can [filter connected accounts by the desired metadata](https://docs.seam.co/core-concepts/connected-accounts/filtering-connected-accounts-by-custom-metadata). */ custom_metadata?: Record | undefined /** * The customer key to associate with this connected account. If provided, the connected account and all resources under the connected account will be moved to this customer. May only be provided if the connected account is not already associated with a customer. */ customer_key?: string | undefined /** * Human-readable name for the connected account, shown in the dashboard. For example, `Booking from Airbnb House 1`. */ display_name?: string | undefined } /** * @deprecated Use ConnectedAccountsUpdateRequest instead. */ export type ConnectedAccountsUpdateResponse = void export type ConnectedAccountsUpdateRequest = SeamHttpRequest export interface ConnectedAccountsUpdateOptions {}