/* * 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 { Workspace } from 'lib/seam/connect/resources/workspace.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 SeamHttpWorkspaces { 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 = {}, ): SeamHttpWorkspaces { const constructorOptions = { ...options, client } if (!isSeamHttpOptionsWithClient(constructorOptions)) { throw new SeamHttpInvalidOptionsError('Missing client') } return new SeamHttpWorkspaces(constructorOptions) } static fromApiKey( apiKey: SeamHttpOptionsWithApiKey['apiKey'], options: Omit = {}, ): SeamHttpWorkspaces { const constructorOptions = { ...options, apiKey } if (!isSeamHttpOptionsWithApiKey(constructorOptions)) { throw new SeamHttpInvalidOptionsError('Missing apiKey') } return new SeamHttpWorkspaces(constructorOptions) } static fromClientSessionToken( clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'], options: Omit< SeamHttpOptionsWithClientSessionToken, 'clientSessionToken' > = {}, ): SeamHttpWorkspaces { const constructorOptions = { ...options, clientSessionToken } if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) { throw new SeamHttpInvalidOptionsError('Missing clientSessionToken') } return new SeamHttpWorkspaces(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 SeamHttpWorkspaces.fromPublishableKey', ) } const client = createClient(clientOptions) const clientSessions = SeamHttpClientSessions.fromClient(client) const { token } = await clientSessions.getOrCreate({ user_identifier_key: userIdentifierKey, }) return SeamHttpWorkspaces.fromClientSessionToken(token, options) } static fromConsoleSessionToken( consoleSessionToken: SeamHttpOptionsWithConsoleSessionToken['consoleSessionToken'], workspaceId: SeamHttpOptionsWithConsoleSessionToken['workspaceId'], options: Omit< SeamHttpOptionsWithConsoleSessionToken, 'consoleSessionToken' | 'workspaceId' > = {}, ): SeamHttpWorkspaces { const constructorOptions = { ...options, consoleSessionToken, workspaceId } if (!isSeamHttpOptionsWithConsoleSessionToken(constructorOptions)) { throw new SeamHttpInvalidOptionsError( 'Missing consoleSessionToken or workspaceId', ) } return new SeamHttpWorkspaces(constructorOptions) } static fromPersonalAccessToken( personalAccessToken: SeamHttpOptionsWithPersonalAccessToken['personalAccessToken'], workspaceId: SeamHttpOptionsWithPersonalAccessToken['workspaceId'], options: Omit< SeamHttpOptionsWithPersonalAccessToken, 'personalAccessToken' | 'workspaceId' > = {}, ): SeamHttpWorkspaces { const constructorOptions = { ...options, personalAccessToken, workspaceId } if (!isSeamHttpOptionsWithPersonalAccessToken(constructorOptions)) { throw new SeamHttpInvalidOptionsError( 'Missing personalAccessToken or workspaceId', ) } return new SeamHttpWorkspaces(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() } /** * Creates a new [workspace](https://docs.seam.co/core-concepts/workspaces). */ create( parameters: WorkspacesCreateParameters, options: WorkspacesCreateOptions = {}, ): WorkspacesCreateRequest { return new SeamHttpRequest(this, { pathname: '/workspaces/create', method: 'POST', body: parameters, responseKey: 'workspace', options, }) } /** * Returns the [workspace](https://docs.seam.co/core-concepts/workspaces) associated with the authentication value. */ get( parameters?: WorkspacesGetParameters, options: WorkspacesGetOptions = {}, ): WorkspacesGetRequest { return new SeamHttpRequest(this, { pathname: '/workspaces/get', method: 'GET', params: parameters, responseKey: 'workspace', options, }) } /** * Returns a list of [workspaces](https://docs.seam.co/core-concepts/workspaces) associated with the authentication value. */ list( parameters?: WorkspacesListParameters, options: WorkspacesListOptions = {}, ): WorkspacesListRequest { return new SeamHttpRequest(this, { pathname: '/workspaces/list', method: 'GET', params: parameters, responseKey: 'workspaces', options, }) } /** * Resets the [sandbox workspace](https://docs.seam.co/core-concepts/workspaces#sandbox-workspaces) associated with the authentication value. Note that this endpoint is only available for sandbox workspaces. */ resetSandbox( parameters?: WorkspacesResetSandboxParameters, options: WorkspacesResetSandboxOptions = {}, ): WorkspacesResetSandboxRequest { return new SeamHttpRequest(this, { pathname: '/workspaces/reset_sandbox', method: 'POST', body: parameters, responseKey: 'action_attempt', options, }) } /** * Updates the [workspace](https://docs.seam.co/core-concepts/workspaces) associated with the authentication value. */ update( parameters?: WorkspacesUpdateParameters, options: WorkspacesUpdateOptions = {}, ): WorkspacesUpdateRequest { return new SeamHttpRequest(this, { pathname: '/workspaces/update', method: 'PATCH', body: parameters, responseKey: undefined, options, }) } } export type WorkspacesCreateParameters = { /** * Company name for the new workspace. */ company_name?: string | undefined /** * Connect partner name for the new workspace. * @deprecated Use `company_name` instead. */ connect_partner_name?: string | undefined /** * [Connect Webview](https://docs.seam.co/core-concepts/connect-webviews) customizations for the new workspace. See also [Customize the Look and Feel of Your Connect Webviews](https://docs.seam.co/core-concepts/connect-webviews/customizing-connect-webviews#customize-the-look-and-feel-of-your-connect-webviews). */ connect_webview_customization?: | { /** * Logo shape for [Connect Webviews](https://docs.seam.co/core-concepts/connect-webviews) in the new workspace. See also [Customize the Look and Feel of Your Connect Webviews](https://docs.seam.co/core-concepts/connect-webviews/customizing-connect-webviews#customize-the-look-and-feel-of-your-connect-webviews). */ logo_shape?: 'circle' | 'square' | undefined /** * Primary button color for [Connect Webviews](https://docs.seam.co/core-concepts/connect-webviews) in the new workspace. See also [Customize the Look and Feel of Your Connect Webviews](https://docs.seam.co/core-concepts/connect-webviews/customizing-connect-webviews#customize-the-look-and-feel-of-your-connect-webviews). */ primary_button_color?: string | undefined /** * Primary button text color for [Connect Webviews](https://docs.seam.co/core-concepts/connect-webviews) in the new workspace. See also [Customize the Look and Feel of Your Connect Webviews](https://docs.seam.co/core-concepts/connect-webviews/customizing-connect-webviews#customize-the-look-and-feel-of-your-connect-webviews). */ primary_button_text_color?: string | undefined /** * Success message for [Connect Webviews](https://docs.seam.co/core-concepts/connect-webviews) in the new workspace. See also [Customize the Look and Feel of Your Connect Webviews](https://docs.seam.co/core-concepts/connect-webviews/customizing-connect-webviews#customize-the-look-and-feel-of-your-connect-webviews). */ success_message?: string | undefined } | undefined /** * Indicates whether the new workspace is a [sandbox workspace](https://docs.seam.co/core-concepts/workspaces#sandbox-workspaces). */ is_sandbox?: boolean | undefined /** * Name of the new workspace. */ name: string /** * ID of the organization to associate with the new workspace. */ organization_id?: string | undefined /** * @deprecated Use `connect_webview_customization.webview_logo_shape` instead. */ webview_logo_shape?: 'circle' | 'square' | undefined /** * @deprecated Use `connect_webview_customization.webview_primary_button_color` instead. */ webview_primary_button_color?: string | undefined /** * @deprecated Use `connect_webview_customization.webview_primary_button_text_color` instead. */ webview_primary_button_text_color?: string | undefined /** * @deprecated Use `connect_webview_customization.webview_success_message` instead. */ webview_success_message?: string | undefined } /** * @deprecated Use WorkspacesCreateRequest instead. */ export type WorkspacesCreateResponse = { workspace: Workspace } export type WorkspacesCreateRequest = SeamHttpRequest< WorkspacesCreateResponse, 'workspace' > export interface WorkspacesCreateOptions {} export type WorkspacesGetParameters = {} /** * @deprecated Use WorkspacesGetRequest instead. */ export type WorkspacesGetResponse = { workspace: Workspace } export type WorkspacesGetRequest = SeamHttpRequest< WorkspacesGetResponse, 'workspace' > export interface WorkspacesGetOptions {} export type WorkspacesListParameters = {} /** * @deprecated Use WorkspacesListRequest instead. */ export type WorkspacesListResponse = { workspaces: Array } export type WorkspacesListRequest = SeamHttpRequest< WorkspacesListResponse, 'workspaces' > export interface WorkspacesListOptions {} export type WorkspacesResetSandboxParameters = {} /** * @deprecated Use WorkspacesResetSandboxRequest instead. */ export type WorkspacesResetSandboxResponse = { action_attempt: ActionAttempt } export type WorkspacesResetSandboxRequest = SeamHttpRequest< WorkspacesResetSandboxResponse, 'action_attempt' > export type WorkspacesResetSandboxOptions = Pick< SeamHttpRequestOptions, 'waitForActionAttempt' > export type WorkspacesUpdateParameters = { /** * Connect partner name for the workspace. */ connect_partner_name?: string | undefined /** * [Connect Webview](https://docs.seam.co/core-concepts/connect-webviews) customizations for the workspace. See also [Customize the Look and Feel of Your Connect Webviews](https://docs.seam.co/core-concepts/connect-webviews/customizing-connect-webviews#customize-the-look-and-feel-of-your-connect-webviews). */ connect_webview_customization?: | { /** * Logo shape for [Connect Webviews](https://docs.seam.co/core-concepts/connect-webviews) in the workspace. See also [Customize the Look and Feel of Your Connect Webviews](https://docs.seam.co/core-concepts/connect-webviews/customizing-connect-webviews#customize-the-look-and-feel-of-your-connect-webviews). */ logo_shape?: 'circle' | 'square' | undefined /** * Primary button color for [Connect Webviews](https://docs.seam.co/core-concepts/connect-webviews) in the workspace. See also [Customize the Look and Feel of Your Connect Webviews](https://docs.seam.co/core-concepts/connect-webviews/customizing-connect-webviews#customize-the-look-and-feel-of-your-connect-webviews). */ primary_button_color?: string | undefined /** * Primary button text color for [Connect Webviews](https://docs.seam.co/core-concepts/connect-webviews) in the workspace. See also [Customize the Look and Feel of Your Connect Webviews](https://docs.seam.co/core-concepts/connect-webviews/customizing-connect-webviews#customize-the-look-and-feel-of-your-connect-webviews). */ primary_button_text_color?: string | undefined /** * Success message for [Connect Webviews](https://docs.seam.co/core-concepts/connect-webviews) in the workspace. See also [Customize the Look and Feel of Your Connect Webviews](https://docs.seam.co/core-concepts/connect-webviews/customizing-connect-webviews#customize-the-look-and-feel-of-your-connect-webviews). */ success_message?: string | undefined } | undefined /** * Indicates whether publishable key authentication is enabled for this workspace. */ is_publishable_key_auth_enabled?: boolean | undefined /** * Indicates whether the workspace is suspended. */ is_suspended?: boolean | undefined /** * Name of the workspace. */ name?: string | undefined /** * ID of the organization to assign the workspace to. The authenticated user must be the owner of the workspace and an admin of the target organization. */ organization_id?: string | undefined } /** * @deprecated Use WorkspacesUpdateRequest instead. */ export type WorkspacesUpdateResponse = void export type WorkspacesUpdateRequest = SeamHttpRequest export interface WorkspacesUpdateOptions {}