/* * Automatically generated by codegen/smith.ts. * Do not edit this file or add other files to this directory. */ import type { RouteRequestBody, RouteResponse } from '@seamapi/types/connect' 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 { 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 type { SetNonNullable } from 'lib/types.js' export class SeamHttpUnstablePartnerBuildingBlocks { client: Client readonly defaults: Required readonly ltsVersion = seamApiLtsVersion static ltsVersion = seamApiLtsVersion constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) { const options = parseOptions(apiKeyOrOptions) if (!options.isUndocumentedApiEnabled) { throw new Error( 'Cannot use undocumented API without isUndocumentedApiEnabled', ) } this.client = 'client' in options ? options.client : createClient(options) this.defaults = limitToSeamHttpRequestOptions(options) } static fromClient( client: SeamHttpOptionsWithClient['client'], options: Omit = {}, ): SeamHttpUnstablePartnerBuildingBlocks { const constructorOptions = { ...options, client } if (!isSeamHttpOptionsWithClient(constructorOptions)) { throw new SeamHttpInvalidOptionsError('Missing client') } return new SeamHttpUnstablePartnerBuildingBlocks(constructorOptions) } static fromApiKey( apiKey: SeamHttpOptionsWithApiKey['apiKey'], options: Omit = {}, ): SeamHttpUnstablePartnerBuildingBlocks { const constructorOptions = { ...options, apiKey } if (!isSeamHttpOptionsWithApiKey(constructorOptions)) { throw new SeamHttpInvalidOptionsError('Missing apiKey') } return new SeamHttpUnstablePartnerBuildingBlocks(constructorOptions) } static fromClientSessionToken( clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'], options: Omit< SeamHttpOptionsWithClientSessionToken, 'clientSessionToken' > = {}, ): SeamHttpUnstablePartnerBuildingBlocks { const constructorOptions = { ...options, clientSessionToken } if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) { throw new SeamHttpInvalidOptionsError('Missing clientSessionToken') } return new SeamHttpUnstablePartnerBuildingBlocks(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 SeamHttpUnstablePartnerBuildingBlocks.fromPublishableKey', ) } const client = createClient(clientOptions) const clientSessions = SeamHttpClientSessions.fromClient(client) const { token } = await clientSessions.getOrCreate({ user_identifier_key: userIdentifierKey, }) return SeamHttpUnstablePartnerBuildingBlocks.fromClientSessionToken( token, options, ) } static fromConsoleSessionToken( consoleSessionToken: SeamHttpOptionsWithConsoleSessionToken['consoleSessionToken'], workspaceId: SeamHttpOptionsWithConsoleSessionToken['workspaceId'], options: Omit< SeamHttpOptionsWithConsoleSessionToken, 'consoleSessionToken' | 'workspaceId' > = {}, ): SeamHttpUnstablePartnerBuildingBlocks { const constructorOptions = { ...options, consoleSessionToken, workspaceId } if (!isSeamHttpOptionsWithConsoleSessionToken(constructorOptions)) { throw new SeamHttpInvalidOptionsError( 'Missing consoleSessionToken or workspaceId', ) } return new SeamHttpUnstablePartnerBuildingBlocks(constructorOptions) } static fromPersonalAccessToken( personalAccessToken: SeamHttpOptionsWithPersonalAccessToken['personalAccessToken'], workspaceId: SeamHttpOptionsWithPersonalAccessToken['workspaceId'], options: Omit< SeamHttpOptionsWithPersonalAccessToken, 'personalAccessToken' | 'workspaceId' > = {}, ): SeamHttpUnstablePartnerBuildingBlocks { const constructorOptions = { ...options, personalAccessToken, workspaceId } if (!isSeamHttpOptionsWithPersonalAccessToken(constructorOptions)) { throw new SeamHttpInvalidOptionsError( 'Missing personalAccessToken or workspaceId', ) } return new SeamHttpUnstablePartnerBuildingBlocks(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() } connectAccounts( parameters?: UnstablePartnerBuildingBlocksConnectAccountsParameters, options: UnstablePartnerBuildingBlocksConnectAccountsOptions = {}, ): UnstablePartnerBuildingBlocksConnectAccountsRequest { if (!this.defaults.isUndocumentedApiEnabled) { throw new Error( 'Cannot use undocumented API without isUndocumentedApiEnabled', ) } return new SeamHttpRequest(this, { pathname: '/unstable_partner/building_blocks/connect_accounts', method: 'POST', body: parameters, responseKey: 'magic_link', options, }) } generateMagicLink( parameters?: UnstablePartnerBuildingBlocksGenerateMagicLinkParameters, options: UnstablePartnerBuildingBlocksGenerateMagicLinkOptions = {}, ): UnstablePartnerBuildingBlocksGenerateMagicLinkRequest { if (!this.defaults.isUndocumentedApiEnabled) { throw new Error( 'Cannot use undocumented API without isUndocumentedApiEnabled', ) } return new SeamHttpRequest(this, { pathname: '/unstable_partner/building_blocks/generate_magic_link', method: 'POST', body: parameters, responseKey: 'magic_link', options, }) } manageDevices( parameters?: UnstablePartnerBuildingBlocksManageDevicesParameters, options: UnstablePartnerBuildingBlocksManageDevicesOptions = {}, ): UnstablePartnerBuildingBlocksManageDevicesRequest { if (!this.defaults.isUndocumentedApiEnabled) { throw new Error( 'Cannot use undocumented API without isUndocumentedApiEnabled', ) } return new SeamHttpRequest(this, { pathname: '/unstable_partner/building_blocks/manage_devices', method: 'POST', body: parameters, responseKey: 'magic_link', options, }) } organizeSpaces( parameters?: UnstablePartnerBuildingBlocksOrganizeSpacesParameters, options: UnstablePartnerBuildingBlocksOrganizeSpacesOptions = {}, ): UnstablePartnerBuildingBlocksOrganizeSpacesRequest { if (!this.defaults.isUndocumentedApiEnabled) { throw new Error( 'Cannot use undocumented API without isUndocumentedApiEnabled', ) } return new SeamHttpRequest(this, { pathname: '/unstable_partner/building_blocks/organize_spaces', method: 'POST', body: parameters, responseKey: 'magic_link', options, }) } } export type UnstablePartnerBuildingBlocksConnectAccountsParameters = RouteRequestBody<'/unstable_partner/building_blocks/connect_accounts'> /** * @deprecated Use UnstablePartnerBuildingBlocksConnectAccountsParameters instead. */ export type UnstablePartnerBuildingBlocksConnectAccountsBody = UnstablePartnerBuildingBlocksConnectAccountsParameters /** * @deprecated Use UnstablePartnerBuildingBlocksConnectAccountsRequest instead. */ export type UnstablePartnerBuildingBlocksConnectAccountsResponse = SetNonNullable< Required< RouteResponse<'/unstable_partner/building_blocks/connect_accounts'> > > export type UnstablePartnerBuildingBlocksConnectAccountsRequest = SeamHttpRequest< UnstablePartnerBuildingBlocksConnectAccountsResponse, 'magic_link' > export interface UnstablePartnerBuildingBlocksConnectAccountsOptions {} export type UnstablePartnerBuildingBlocksGenerateMagicLinkParameters = RouteRequestBody<'/unstable_partner/building_blocks/generate_magic_link'> /** * @deprecated Use UnstablePartnerBuildingBlocksGenerateMagicLinkParameters instead. */ export type UnstablePartnerBuildingBlocksGenerateMagicLinkParams = UnstablePartnerBuildingBlocksGenerateMagicLinkParameters /** * @deprecated Use UnstablePartnerBuildingBlocksGenerateMagicLinkRequest instead. */ export type UnstablePartnerBuildingBlocksGenerateMagicLinkResponse = SetNonNullable< Required< RouteResponse<'/unstable_partner/building_blocks/generate_magic_link'> > > export type UnstablePartnerBuildingBlocksGenerateMagicLinkRequest = SeamHttpRequest< UnstablePartnerBuildingBlocksGenerateMagicLinkResponse, 'magic_link' > export interface UnstablePartnerBuildingBlocksGenerateMagicLinkOptions {} export type UnstablePartnerBuildingBlocksManageDevicesParameters = RouteRequestBody<'/unstable_partner/building_blocks/manage_devices'> /** * @deprecated Use UnstablePartnerBuildingBlocksManageDevicesParameters instead. */ export type UnstablePartnerBuildingBlocksManageDevicesBody = UnstablePartnerBuildingBlocksManageDevicesParameters /** * @deprecated Use UnstablePartnerBuildingBlocksManageDevicesRequest instead. */ export type UnstablePartnerBuildingBlocksManageDevicesResponse = SetNonNullable< Required> > export type UnstablePartnerBuildingBlocksManageDevicesRequest = SeamHttpRequest< UnstablePartnerBuildingBlocksManageDevicesResponse, 'magic_link' > export interface UnstablePartnerBuildingBlocksManageDevicesOptions {} export type UnstablePartnerBuildingBlocksOrganizeSpacesParameters = RouteRequestBody<'/unstable_partner/building_blocks/organize_spaces'> /** * @deprecated Use UnstablePartnerBuildingBlocksOrganizeSpacesParameters instead. */ export type UnstablePartnerBuildingBlocksOrganizeSpacesBody = UnstablePartnerBuildingBlocksOrganizeSpacesParameters /** * @deprecated Use UnstablePartnerBuildingBlocksOrganizeSpacesRequest instead. */ export type UnstablePartnerBuildingBlocksOrganizeSpacesResponse = SetNonNullable< Required> > export type UnstablePartnerBuildingBlocksOrganizeSpacesRequest = SeamHttpRequest< UnstablePartnerBuildingBlocksOrganizeSpacesResponse, 'magic_link' > export interface UnstablePartnerBuildingBlocksOrganizeSpacesOptions {}