/* * 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 { Batch } from 'lib/seam/connect/resources/batch.js' import type { Space } from 'lib/seam/connect/resources/space.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' export class SeamHttpSpaces { 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 = {}, ): SeamHttpSpaces { const constructorOptions = { ...options, client } if (!isSeamHttpOptionsWithClient(constructorOptions)) { throw new SeamHttpInvalidOptionsError('Missing client') } return new SeamHttpSpaces(constructorOptions) } static fromApiKey( apiKey: SeamHttpOptionsWithApiKey['apiKey'], options: Omit = {}, ): SeamHttpSpaces { const constructorOptions = { ...options, apiKey } if (!isSeamHttpOptionsWithApiKey(constructorOptions)) { throw new SeamHttpInvalidOptionsError('Missing apiKey') } return new SeamHttpSpaces(constructorOptions) } static fromClientSessionToken( clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'], options: Omit< SeamHttpOptionsWithClientSessionToken, 'clientSessionToken' > = {}, ): SeamHttpSpaces { const constructorOptions = { ...options, clientSessionToken } if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) { throw new SeamHttpInvalidOptionsError('Missing clientSessionToken') } return new SeamHttpSpaces(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 SeamHttpSpaces.fromPublishableKey', ) } const client = createClient(clientOptions) const clientSessions = SeamHttpClientSessions.fromClient(client) const { token } = await clientSessions.getOrCreate({ user_identifier_key: userIdentifierKey, }) return SeamHttpSpaces.fromClientSessionToken(token, options) } static fromConsoleSessionToken( consoleSessionToken: SeamHttpOptionsWithConsoleSessionToken['consoleSessionToken'], workspaceId: SeamHttpOptionsWithConsoleSessionToken['workspaceId'], options: Omit< SeamHttpOptionsWithConsoleSessionToken, 'consoleSessionToken' | 'workspaceId' > = {}, ): SeamHttpSpaces { const constructorOptions = { ...options, consoleSessionToken, workspaceId } if (!isSeamHttpOptionsWithConsoleSessionToken(constructorOptions)) { throw new SeamHttpInvalidOptionsError( 'Missing consoleSessionToken or workspaceId', ) } return new SeamHttpSpaces(constructorOptions) } static fromPersonalAccessToken( personalAccessToken: SeamHttpOptionsWithPersonalAccessToken['personalAccessToken'], workspaceId: SeamHttpOptionsWithPersonalAccessToken['workspaceId'], options: Omit< SeamHttpOptionsWithPersonalAccessToken, 'personalAccessToken' | 'workspaceId' > = {}, ): SeamHttpSpaces { const constructorOptions = { ...options, personalAccessToken, workspaceId } if (!isSeamHttpOptionsWithPersonalAccessToken(constructorOptions)) { throw new SeamHttpInvalidOptionsError( 'Missing personalAccessToken or workspaceId', ) } return new SeamHttpSpaces(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() } /** * Adds [entrances](https://docs.seam.co/low-level-apis/access-systems/retrieving-entrance-details) to a specific space. */ addAcsEntrances( parameters: SpacesAddAcsEntrancesParameters, options: SpacesAddAcsEntrancesOptions = {}, ): SpacesAddAcsEntrancesRequest { return new SeamHttpRequest(this, { pathname: '/spaces/add_acs_entrances', method: 'PUT', body: parameters, responseKey: undefined, options, }) } /** * Adds a [connected account](https://docs.seam.co/core-concepts/connected-accounts) to a specific space. */ addConnectedAccount( parameters: SpacesAddConnectedAccountParameters, options: SpacesAddConnectedAccountOptions = {}, ): SpacesAddConnectedAccountRequest { return new SeamHttpRequest(this, { pathname: '/spaces/add_connected_account', method: 'PUT', body: parameters, responseKey: undefined, options, }) } /** * Adds devices to a specific space. */ addDevices( parameters: SpacesAddDevicesParameters, options: SpacesAddDevicesOptions = {}, ): SpacesAddDevicesRequest { return new SeamHttpRequest(this, { pathname: '/spaces/add_devices', method: 'PUT', body: parameters, responseKey: undefined, options, }) } /** * Creates a new space. */ create( parameters: SpacesCreateParameters, options: SpacesCreateOptions = {}, ): SpacesCreateRequest { return new SeamHttpRequest(this, { pathname: '/spaces/create', method: 'POST', body: parameters, responseKey: 'space', options, }) } /** * Deletes a space. */ delete( parameters: SpacesDeleteParameters, options: SpacesDeleteOptions = {}, ): SpacesDeleteRequest { return new SeamHttpRequest(this, { pathname: '/spaces/delete', method: 'POST', body: parameters, responseKey: undefined, options, }) } /** * Gets a space. */ get( parameters?: SpacesGetParameters, options: SpacesGetOptions = {}, ): SpacesGetRequest { return new SeamHttpRequest(this, { pathname: '/spaces/get', method: 'GET', params: parameters, responseKey: 'space', options, }) } /** * Gets all related resources for one or more Spaces. */ getRelated( parameters?: SpacesGetRelatedParameters, options: SpacesGetRelatedOptions = {}, ): SpacesGetRelatedRequest { return new SeamHttpRequest(this, { pathname: '/spaces/get_related', method: 'POST', body: parameters, responseKey: 'batch', options, }) } /** * Returns a list of all spaces. */ list( parameters?: SpacesListParameters, options: SpacesListOptions = {}, ): SpacesListRequest { return new SeamHttpRequest(this, { pathname: '/spaces/list', method: 'POST', body: parameters, responseKey: 'spaces', options, }) } /** * Removes [entrances](https://docs.seam.co/low-level-apis/access-systems/retrieving-entrance-details) from a specific space. */ removeAcsEntrances( parameters: SpacesRemoveAcsEntrancesParameters, options: SpacesRemoveAcsEntrancesOptions = {}, ): SpacesRemoveAcsEntrancesRequest { return new SeamHttpRequest(this, { pathname: '/spaces/remove_acs_entrances', method: 'POST', body: parameters, responseKey: undefined, options, }) } /** * Removes a [connected account](https://docs.seam.co/core-concepts/connected-accounts) from a specific space. */ removeConnectedAccount( parameters: SpacesRemoveConnectedAccountParameters, options: SpacesRemoveConnectedAccountOptions = {}, ): SpacesRemoveConnectedAccountRequest { return new SeamHttpRequest(this, { pathname: '/spaces/remove_connected_account', method: 'POST', body: parameters, responseKey: undefined, options, }) } /** * Removes devices from a specific space. */ removeDevices( parameters: SpacesRemoveDevicesParameters, options: SpacesRemoveDevicesOptions = {}, ): SpacesRemoveDevicesRequest { return new SeamHttpRequest(this, { pathname: '/spaces/remove_devices', method: 'POST', body: parameters, responseKey: undefined, options, }) } /** * Updates an existing space. */ update( parameters?: SpacesUpdateParameters, options: SpacesUpdateOptions = {}, ): SpacesUpdateRequest { return new SeamHttpRequest(this, { pathname: '/spaces/update', method: 'PATCH', body: parameters, responseKey: 'space', options, }) } } export type SpacesAddAcsEntrancesParameters = { /** * IDs of the entrances that you want to add to the space. */ acs_entrance_ids: Array /** * ID of the space to which you want to add entrances. */ space_id: string } /** * @deprecated Use SpacesAddAcsEntrancesRequest instead. */ export type SpacesAddAcsEntrancesResponse = void export type SpacesAddAcsEntrancesRequest = SeamHttpRequest export interface SpacesAddAcsEntrancesOptions {} export type SpacesAddConnectedAccountParameters = { /** * ID of the connected account that you want to add to the space. */ connected_account_id: string /** * ID of the space to which you want to add the connected account. */ space_id: string } /** * @deprecated Use SpacesAddConnectedAccountRequest instead. */ export type SpacesAddConnectedAccountResponse = void export type SpacesAddConnectedAccountRequest = SeamHttpRequest export interface SpacesAddConnectedAccountOptions {} export type SpacesAddDevicesParameters = { /** * IDs of the devices that you want to add to the space. */ device_ids: Array /** * ID of the space to which you want to add devices. */ space_id: string } /** * @deprecated Use SpacesAddDevicesRequest instead. */ export type SpacesAddDevicesResponse = void export type SpacesAddDevicesRequest = SeamHttpRequest export interface SpacesAddDevicesOptions {} export type SpacesCreateParameters = { /** * IDs of the entrances that you want to add to the new space. */ acs_entrance_ids?: Array | undefined /** * IDs of connected accounts to associate with the new space. Persisted on seam.location_third_party_account so the UI can show which provider account(s) a space came from. */ connected_account_ids?: Array | undefined /** * Reservation/stay-related defaults for the space. */ customer_data?: | { /** * Postal address for the space. */ address?: string | undefined /** * Default check-in time for reservations at the space, as HH:mm or HH:mm:ss. */ default_checkin_time?: string | undefined /** * Default check-out time for reservations at the space, as HH:mm or HH:mm:ss. */ default_checkout_time?: string | undefined /** * IANA time zone for the space, e.g. America/Los_Angeles. */ time_zone?: string | undefined } | undefined /** * Customer key for which you want to create the space. */ customer_key?: string | undefined /** * IDs of the devices that you want to add to the new space. */ device_ids?: Array | undefined /** * Name of the space that you want to create. */ name: string /** * Unique key for the space within the workspace. */ space_key?: string | undefined } /** * @deprecated Use SpacesCreateRequest instead. */ export type SpacesCreateResponse = { space: Space } export type SpacesCreateRequest = SeamHttpRequest export interface SpacesCreateOptions {} export type SpacesDeleteParameters = { /** * ID of the space that you want to delete. */ space_id: string } /** * @deprecated Use SpacesDeleteRequest instead. */ export type SpacesDeleteResponse = void export type SpacesDeleteRequest = SeamHttpRequest export interface SpacesDeleteOptions {} export type SpacesGetParameters = { /** * ID of the space that you want to get. */ space_id?: string | undefined /** * Unique key of the space that you want to get. */ space_key?: string | undefined } /** * @deprecated Use SpacesGetRequest instead. */ export type SpacesGetResponse = { space: Space } export type SpacesGetRequest = SeamHttpRequest export interface SpacesGetOptions {} export type SpacesGetRelatedParameters = { exclude?: | Array< | 'spaces' | 'devices' | 'acs_entrances' | 'connected_accounts' | 'acs_systems' | 'access_methods' > | undefined include?: | Array< | 'spaces' | 'devices' | 'acs_entrances' | 'connected_accounts' | 'acs_systems' | 'access_methods' > | undefined /** * IDs of the spaces that you want to get along with their related resources. */ space_ids?: Array | undefined /** * Keys of the spaces that you want to get along with their related resources. */ space_keys?: Array | undefined } /** * @deprecated Use SpacesGetRelatedRequest instead. */ export type SpacesGetRelatedResponse = { batch: Batch< | 'spaces' | 'devices' | 'acs_entrances' | 'connected_accounts' | 'acs_systems' | 'access_methods' > } export type SpacesGetRelatedRequest = SeamHttpRequest< SpacesGetRelatedResponse, 'batch' > export interface SpacesGetRelatedOptions {} export type SpacesListParameters = { /** * Customer key for which you want to list spaces. */ 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 spaces to include all records that satisfy a partial match using `name`, `space_key`, or `customer_key`. */ search?: string | undefined /** * Filter spaces by space_key. */ space_key?: string | undefined } /** * @deprecated Use SpacesListRequest instead. */ export type SpacesListResponse = { spaces: Array } export type SpacesListRequest = SeamHttpRequest export interface SpacesListOptions {} export type SpacesRemoveAcsEntrancesParameters = { /** * IDs of the entrances that you want to remove from the space. */ acs_entrance_ids: Array /** * ID of the space from which you want to remove entrances. */ space_id: string } /** * @deprecated Use SpacesRemoveAcsEntrancesRequest instead. */ export type SpacesRemoveAcsEntrancesResponse = void export type SpacesRemoveAcsEntrancesRequest = SeamHttpRequest export interface SpacesRemoveAcsEntrancesOptions {} export type SpacesRemoveConnectedAccountParameters = { /** * ID of the connected account that you want to remove from the space. */ connected_account_id: string /** * ID of the space from which you want to remove the connected account. */ space_id: string } /** * @deprecated Use SpacesRemoveConnectedAccountRequest instead. */ export type SpacesRemoveConnectedAccountResponse = void export type SpacesRemoveConnectedAccountRequest = SeamHttpRequest< void, undefined > export interface SpacesRemoveConnectedAccountOptions {} export type SpacesRemoveDevicesParameters = { /** * IDs of the devices that you want to remove from the space. */ device_ids: Array /** * ID of the space from which you want to remove devices. */ space_id: string } /** * @deprecated Use SpacesRemoveDevicesRequest instead. */ export type SpacesRemoveDevicesResponse = void export type SpacesRemoveDevicesRequest = SeamHttpRequest export interface SpacesRemoveDevicesOptions {} export type SpacesUpdateParameters = { /** * IDs of the entrances that you want to set for the space. If specified, this will replace all existing entrances. */ acs_entrance_ids?: Array | undefined /** * Reservation/stay-related defaults for the space. Only the keys you provide are updated; omit a key to leave it unchanged. Pass null on a key to clear it. */ customer_data?: | { /** * Postal address for the space. */ address?: string | undefined /** * Default check-in time for reservations at the space, as HH:mm or HH:mm:ss. */ default_checkin_time?: string | undefined /** * Default check-out time for reservations at the space, as HH:mm or HH:mm:ss. */ default_checkout_time?: string | undefined /** * IANA time zone for the space, e.g. America/Los_Angeles. */ time_zone?: string | undefined } | undefined /** * IDs of the devices that you want to set for the space. If specified, this will replace all existing devices. */ device_ids?: Array | undefined /** * Name of the space. */ name?: string | undefined /** * ID of the space that you want to update. */ space_id?: string | undefined /** * Unique key of the space that you want to update. */ space_key?: string | undefined } /** * @deprecated Use SpacesUpdateRequest instead. */ export type SpacesUpdateResponse = { space: Space } export type SpacesUpdateRequest = SeamHttpRequest export interface SpacesUpdateOptions {}