/* * 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 { UnmanagedAccessGrant } from 'lib/seam/connect/resources/unmanaged-access-grant.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 SeamHttpAccessGrantsUnmanaged { 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 = {}, ): SeamHttpAccessGrantsUnmanaged { const constructorOptions = { ...options, client } if (!isSeamHttpOptionsWithClient(constructorOptions)) { throw new SeamHttpInvalidOptionsError('Missing client') } return new SeamHttpAccessGrantsUnmanaged(constructorOptions) } static fromApiKey( apiKey: SeamHttpOptionsWithApiKey['apiKey'], options: Omit = {}, ): SeamHttpAccessGrantsUnmanaged { const constructorOptions = { ...options, apiKey } if (!isSeamHttpOptionsWithApiKey(constructorOptions)) { throw new SeamHttpInvalidOptionsError('Missing apiKey') } return new SeamHttpAccessGrantsUnmanaged(constructorOptions) } static fromClientSessionToken( clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'], options: Omit< SeamHttpOptionsWithClientSessionToken, 'clientSessionToken' > = {}, ): SeamHttpAccessGrantsUnmanaged { const constructorOptions = { ...options, clientSessionToken } if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) { throw new SeamHttpInvalidOptionsError('Missing clientSessionToken') } return new SeamHttpAccessGrantsUnmanaged(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 SeamHttpAccessGrantsUnmanaged.fromPublishableKey', ) } const client = createClient(clientOptions) const clientSessions = SeamHttpClientSessions.fromClient(client) const { token } = await clientSessions.getOrCreate({ user_identifier_key: userIdentifierKey, }) return SeamHttpAccessGrantsUnmanaged.fromClientSessionToken(token, options) } static fromConsoleSessionToken( consoleSessionToken: SeamHttpOptionsWithConsoleSessionToken['consoleSessionToken'], workspaceId: SeamHttpOptionsWithConsoleSessionToken['workspaceId'], options: Omit< SeamHttpOptionsWithConsoleSessionToken, 'consoleSessionToken' | 'workspaceId' > = {}, ): SeamHttpAccessGrantsUnmanaged { const constructorOptions = { ...options, consoleSessionToken, workspaceId } if (!isSeamHttpOptionsWithConsoleSessionToken(constructorOptions)) { throw new SeamHttpInvalidOptionsError( 'Missing consoleSessionToken or workspaceId', ) } return new SeamHttpAccessGrantsUnmanaged(constructorOptions) } static fromPersonalAccessToken( personalAccessToken: SeamHttpOptionsWithPersonalAccessToken['personalAccessToken'], workspaceId: SeamHttpOptionsWithPersonalAccessToken['workspaceId'], options: Omit< SeamHttpOptionsWithPersonalAccessToken, 'personalAccessToken' | 'workspaceId' > = {}, ): SeamHttpAccessGrantsUnmanaged { const constructorOptions = { ...options, personalAccessToken, workspaceId } if (!isSeamHttpOptionsWithPersonalAccessToken(constructorOptions)) { throw new SeamHttpInvalidOptionsError( 'Missing personalAccessToken or workspaceId', ) } return new SeamHttpAccessGrantsUnmanaged(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 an unmanaged Access Grant (where is_managed = false). */ get( parameters: AccessGrantsUnmanagedGetParameters, options: AccessGrantsUnmanagedGetOptions = {}, ): AccessGrantsUnmanagedGetRequest { return new SeamHttpRequest(this, { pathname: '/access_grants/unmanaged/get', method: 'POST', body: parameters, responseKey: 'access_grant', options, }) } /** * Gets unmanaged Access Grants (where is_managed = false). */ list( parameters?: AccessGrantsUnmanagedListParameters, options: AccessGrantsUnmanagedListOptions = {}, ): AccessGrantsUnmanagedListRequest { return new SeamHttpRequest(this, { pathname: '/access_grants/unmanaged/list', method: 'POST', body: parameters, responseKey: 'access_grants', options, }) } /** * Updates an unmanaged Access Grant to make it managed. * * This endpoint can only be used to convert unmanaged access grants to managed ones by setting `is_managed` to `true`. It cannot be used to convert managed access grants back to unmanaged. * * When converting an unmanaged access grant to managed, all associated access methods will also be converted to managed. */ update( parameters: AccessGrantsUnmanagedUpdateParameters, options: AccessGrantsUnmanagedUpdateOptions = {}, ): AccessGrantsUnmanagedUpdateRequest { return new SeamHttpRequest(this, { pathname: '/access_grants/unmanaged/update', method: 'PATCH', body: parameters, responseKey: undefined, options, }) } } export type AccessGrantsUnmanagedGetParameters = { /** * ID of unmanaged Access Grant to get. */ access_grant_id: string } /** * @deprecated Use AccessGrantsUnmanagedGetRequest instead. */ export type AccessGrantsUnmanagedGetResponse = { access_grant: UnmanagedAccessGrant } export type AccessGrantsUnmanagedGetRequest = SeamHttpRequest< AccessGrantsUnmanagedGetResponse, 'access_grant' > export interface AccessGrantsUnmanagedGetOptions {} export type AccessGrantsUnmanagedListParameters = { /** * ID of the entrance by which you want to filter the list of unmanaged Access Grants. */ acs_entrance_id?: string | undefined /** * ID of the access system by which you want to filter the list of unmanaged Access Grants. */ acs_system_id?: string | undefined /** * Numerical limit on the number of unmanaged access grants to return. */ limit?: number | undefined /** * Identifies the specific page of results to return, obtained from the previous page's `next_page_cursor`. */ page_cursor?: string | undefined /** * Filter unmanaged Access Grants by reservation_key. */ reservation_key?: string | undefined /** * ID of user identity by which you want to filter the list of unmanaged Access Grants. */ user_identity_id?: string | undefined } /** * @deprecated Use AccessGrantsUnmanagedListRequest instead. */ export type AccessGrantsUnmanagedListResponse = { access_grants: Array } export type AccessGrantsUnmanagedListRequest = SeamHttpRequest< AccessGrantsUnmanagedListResponse, 'access_grants' > export interface AccessGrantsUnmanagedListOptions {} export type AccessGrantsUnmanagedUpdateParameters = { /** * ID of the unmanaged Access Grant to update. */ access_grant_id: string /** * Unique key for the access grant. If not provided, the existing key will be preserved. */ access_grant_key?: string | undefined /** * Must be set to true to convert the unmanaged access grant to managed. */ is_managed: boolean } /** * @deprecated Use AccessGrantsUnmanagedUpdateRequest instead. */ export type AccessGrantsUnmanagedUpdateResponse = void export type AccessGrantsUnmanagedUpdateRequest = SeamHttpRequest< void, undefined > export interface AccessGrantsUnmanagedUpdateOptions {}