/* * 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 { ClientSession } from 'lib/seam/connect/resources/client-session.js' import { SeamHttpRequest } from 'lib/seam/connect/seam-http-request.js' import { SeamPaginator } from 'lib/seam/connect/seam-paginator.js' export class SeamHttpClientSessions { 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 = {}, ): SeamHttpClientSessions { const constructorOptions = { ...options, client } if (!isSeamHttpOptionsWithClient(constructorOptions)) { throw new SeamHttpInvalidOptionsError('Missing client') } return new SeamHttpClientSessions(constructorOptions) } static fromApiKey( apiKey: SeamHttpOptionsWithApiKey['apiKey'], options: Omit = {}, ): SeamHttpClientSessions { const constructorOptions = { ...options, apiKey } if (!isSeamHttpOptionsWithApiKey(constructorOptions)) { throw new SeamHttpInvalidOptionsError('Missing apiKey') } return new SeamHttpClientSessions(constructorOptions) } static fromClientSessionToken( clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'], options: Omit< SeamHttpOptionsWithClientSessionToken, 'clientSessionToken' > = {}, ): SeamHttpClientSessions { const constructorOptions = { ...options, clientSessionToken } if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) { throw new SeamHttpInvalidOptionsError('Missing clientSessionToken') } return new SeamHttpClientSessions(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 SeamHttpClientSessions.fromPublishableKey', ) } const client = createClient(clientOptions) const clientSessions = SeamHttpClientSessions.fromClient(client) const { token } = await clientSessions.getOrCreate({ user_identifier_key: userIdentifierKey, }) return SeamHttpClientSessions.fromClientSessionToken(token, options) } static fromConsoleSessionToken( consoleSessionToken: SeamHttpOptionsWithConsoleSessionToken['consoleSessionToken'], workspaceId: SeamHttpOptionsWithConsoleSessionToken['workspaceId'], options: Omit< SeamHttpOptionsWithConsoleSessionToken, 'consoleSessionToken' | 'workspaceId' > = {}, ): SeamHttpClientSessions { const constructorOptions = { ...options, consoleSessionToken, workspaceId } if (!isSeamHttpOptionsWithConsoleSessionToken(constructorOptions)) { throw new SeamHttpInvalidOptionsError( 'Missing consoleSessionToken or workspaceId', ) } return new SeamHttpClientSessions(constructorOptions) } static fromPersonalAccessToken( personalAccessToken: SeamHttpOptionsWithPersonalAccessToken['personalAccessToken'], workspaceId: SeamHttpOptionsWithPersonalAccessToken['workspaceId'], options: Omit< SeamHttpOptionsWithPersonalAccessToken, 'personalAccessToken' | 'workspaceId' > = {}, ): SeamHttpClientSessions { const constructorOptions = { ...options, personalAccessToken, workspaceId } if (!isSeamHttpOptionsWithPersonalAccessToken(constructorOptions)) { throw new SeamHttpInvalidOptionsError( 'Missing personalAccessToken or workspaceId', ) } return new SeamHttpClientSessions(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 [client session](https://docs.seam.co/core-concepts/authentication/client-session-tokens). */ create( parameters?: ClientSessionsCreateParameters, options: ClientSessionsCreateOptions = {}, ): ClientSessionsCreateRequest { return new SeamHttpRequest(this, { pathname: '/client_sessions/create', method: 'PUT', body: parameters, responseKey: 'client_session', options, }) } /** * Deletes a [client session](https://docs.seam.co/core-concepts/authentication/client-session-tokens). */ delete( parameters: ClientSessionsDeleteParameters, options: ClientSessionsDeleteOptions = {}, ): ClientSessionsDeleteRequest { return new SeamHttpRequest(this, { pathname: '/client_sessions/delete', method: 'POST', body: parameters, responseKey: undefined, options, }) } /** * Returns a specified [client session](https://docs.seam.co/core-concepts/authentication/client-session-tokens). */ get( parameters?: ClientSessionsGetParameters, options: ClientSessionsGetOptions = {}, ): ClientSessionsGetRequest { return new SeamHttpRequest(this, { pathname: '/client_sessions/get', method: 'POST', body: parameters, responseKey: 'client_session', options, }) } /** * Returns a [client session](https://docs.seam.co/core-concepts/authentication/client-session-tokens) with specific characteristics or creates a new client session with these characteristics if it does not yet exist. */ getOrCreate( parameters?: ClientSessionsGetOrCreateParameters, options: ClientSessionsGetOrCreateOptions = {}, ): ClientSessionsGetOrCreateRequest { return new SeamHttpRequest(this, { pathname: '/client_sessions/get_or_create', method: 'POST', body: parameters, responseKey: 'client_session', options, }) } /** * Grants a [client session](https://docs.seam.co/core-concepts/authentication/client-session-tokens) access to one or more resources, such as [Connect Webviews](https://docs.seam.co/core-concepts/connect-webviews), [user identities](https://docs.seam.co/capability-guides/mobile-access/managing-mobile-app-user-accounts-with-user-identities#what-is-a-user-identity), and so on. */ grantAccess( parameters?: ClientSessionsGrantAccessParameters, options: ClientSessionsGrantAccessOptions = {}, ): ClientSessionsGrantAccessRequest { return new SeamHttpRequest(this, { pathname: '/client_sessions/grant_access', method: 'PATCH', body: parameters, responseKey: undefined, options, }) } /** * Returns a list of all [client sessions](https://docs.seam.co/core-concepts/authentication/client-session-tokens). */ list( parameters?: ClientSessionsListParameters, options: ClientSessionsListOptions = {}, ): ClientSessionsListRequest { return new SeamHttpRequest(this, { pathname: '/client_sessions/list', method: 'POST', body: parameters, responseKey: 'client_sessions', options, }) } /** * Revokes a [client session](https://docs.seam.co/core-concepts/authentication/client-session-tokens). * * Note that [deleting a client session](https://docs.seam.co/api/client_sessions/delete) is a separate action. */ revoke( parameters: ClientSessionsRevokeParameters, options: ClientSessionsRevokeOptions = {}, ): ClientSessionsRevokeRequest { return new SeamHttpRequest(this, { pathname: '/client_sessions/revoke', method: 'POST', body: parameters, responseKey: undefined, options, }) } } export type ClientSessionsCreateParameters = { /** * IDs of the [Connect Webviews](https://docs.seam.co/core-concepts/connect-webviews) for which you want to create a client session. */ connect_webview_ids?: Array | undefined /** * IDs of the [connected accounts](https://docs.seam.co/core-concepts/connected-accounts) for which you want to create a client session. */ connected_account_ids?: Array | undefined /** * Customer ID that you want to associate with the new client session. */ customer_id?: string | undefined /** * Customer key that you want to associate with the new client session. */ customer_key?: string | undefined /** * Date and time at which the client session should expire, in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. */ expires_at?: string | undefined /** * Your user ID for the user for whom you want to create a client session. */ user_identifier_key?: string | undefined /** * ID of the [user identity](https://docs.seam.co/capability-guides/mobile-access/managing-mobile-app-user-accounts-with-user-identities#what-is-a-user-identity) for which you want to create a client session. */ user_identity_id?: string | undefined /** * IDs of the [user identities](https://docs.seam.co/capability-guides/mobile-access/managing-mobile-app-user-accounts-with-user-identities#what-is-a-user-identity) that you want to associate with the client session. * @deprecated Use `user_identity_id` instead. */ user_identity_ids?: Array | undefined } /** * @deprecated Use ClientSessionsCreateRequest instead. */ export type ClientSessionsCreateResponse = { client_session: ClientSession } export type ClientSessionsCreateRequest = SeamHttpRequest< ClientSessionsCreateResponse, 'client_session' > export interface ClientSessionsCreateOptions {} export type ClientSessionsDeleteParameters = { /** * ID of the client session that you want to delete. */ client_session_id: string } /** * @deprecated Use ClientSessionsDeleteRequest instead. */ export type ClientSessionsDeleteResponse = void export type ClientSessionsDeleteRequest = SeamHttpRequest export interface ClientSessionsDeleteOptions {} export type ClientSessionsGetParameters = { /** * ID of the client session that you want to get. */ client_session_id?: string | undefined /** * User identifier key associated with the client session that you want to get. */ user_identifier_key?: string | undefined } /** * @deprecated Use ClientSessionsGetRequest instead. */ export type ClientSessionsGetResponse = { client_session: ClientSession } export type ClientSessionsGetRequest = SeamHttpRequest< ClientSessionsGetResponse, 'client_session' > export interface ClientSessionsGetOptions {} export type ClientSessionsGetOrCreateParameters = { /** * IDs of the [Connect Webviews](https://docs.seam.co/core-concepts/connect-webviews) that you want to associate with the client session (or that are already associated with the existing client session). */ connect_webview_ids?: Array | undefined /** * IDs of the [connected accounts](https://docs.seam.co/api/connected_accounts) that you want to associate with the client session (or that are already associated with the existing client session). */ connected_account_ids?: Array | undefined /** * Date and time at which the client session should expire in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. If the client session already exists, this will update the expiration before returning it. */ expires_at?: string | undefined /** * Your user ID for the user that you want to associate with the client session (or that is already associated with the existing client session). */ user_identifier_key?: string | undefined /** * ID of the [user identity](https://docs.seam.co/capability-guides/mobile-access/managing-mobile-app-user-accounts-with-user-identities#what-is-a-user-identity) that you want to associate with the client session (or that are already associated with the existing client session). */ user_identity_id?: string | undefined /** * IDs of the [user identities](https://docs.seam.co/capability-guides/mobile-access/managing-mobile-app-user-accounts-with-user-identities#what-is-a-user-identity) that you want to associate with the client session. * @deprecated Use `user_identity_id`. */ user_identity_ids?: Array | undefined } /** * @deprecated Use ClientSessionsGetOrCreateRequest instead. */ export type ClientSessionsGetOrCreateResponse = { client_session: ClientSession } export type ClientSessionsGetOrCreateRequest = SeamHttpRequest< ClientSessionsGetOrCreateResponse, 'client_session' > export interface ClientSessionsGetOrCreateOptions {} export type ClientSessionsGrantAccessParameters = { /** * ID of the client session to which you want to grant access to resources. */ client_session_id?: string | undefined /** * IDs of the [Connect Webviews](https://docs.seam.co/core-concepts/connect-webviews) that you want to associate with the client session. */ connect_webview_ids?: Array | undefined /** * IDs of the [connected accounts](https://docs.seam.co/core-concepts/connected-accounts) that you want to associate with the client session. */ connected_account_ids?: Array | undefined /** * Your user ID for the user that you want to associate with the client session. */ user_identifier_key?: string | undefined /** * ID of the [user identity](https://docs.seam.co/capability-guides/mobile-access/managing-mobile-app-user-accounts-with-user-identities#what-is-a-user-identity) that you want to associate with the client session. */ user_identity_id?: string | undefined /** * IDs of the [user identities](https://docs.seam.co/capability-guides/mobile-access/managing-mobile-app-user-accounts-with-user-identities#what-is-a-user-identity) that you want to associate with the client session. * @deprecated Use `user_identity_id`. */ user_identity_ids?: Array | undefined } /** * @deprecated Use ClientSessionsGrantAccessRequest instead. */ export type ClientSessionsGrantAccessResponse = void export type ClientSessionsGrantAccessRequest = SeamHttpRequest export interface ClientSessionsGrantAccessOptions {} export type ClientSessionsListParameters = { /** * ID of the client session that you want to retrieve. */ client_session_id?: string | undefined /** * ID of the [Connect Webview](https://docs.seam.co/core-concepts/connect-webviews) for which you want to retrieve client sessions. */ connect_webview_id?: string | undefined /** * Your user ID for the user by which you want to filter client sessions. */ user_identifier_key?: string | undefined /** * ID of the [user identity](https://docs.seam.co/capability-guides/mobile-access/managing-mobile-app-user-accounts-with-user-identities#what-is-a-user-identity) for which you want to retrieve client sessions. */ user_identity_id?: string | undefined /** * Indicates whether to retrieve only client sessions without associated user identifier keys. */ without_user_identifier_key?: boolean | undefined } /** * @deprecated Use ClientSessionsListRequest instead. */ export type ClientSessionsListResponse = { client_sessions: Array } export type ClientSessionsListRequest = SeamHttpRequest< ClientSessionsListResponse, 'client_sessions' > export interface ClientSessionsListOptions {} export type ClientSessionsRevokeParameters = { /** * ID of the client session that you want to revoke. */ client_session_id: string } /** * @deprecated Use ClientSessionsRevokeRequest instead. */ export type ClientSessionsRevokeResponse = void export type ClientSessionsRevokeRequest = SeamHttpRequest export interface ClientSessionsRevokeOptions {}