From 885c88476862d4839abd82b83e0f87404ef1ec52 Mon Sep 17 00:00:00 2001 From: Seam Bot Date: Thu, 7 Mar 2024 13:52:09 +0000 Subject: [PATCH] ci: Generate code --- src/lib/seam/connect/routes/index.ts | 1 + .../seam/connect/routes/phones-simulate.ts | 177 ++++++++++++++++++ src/lib/seam/connect/routes/phones.ts | 5 + 3 files changed, 183 insertions(+) create mode 100644 src/lib/seam/connect/routes/phones-simulate.ts diff --git a/src/lib/seam/connect/routes/index.ts b/src/lib/seam/connect/routes/index.ts index 416f9192..b580e487 100644 --- a/src/lib/seam/connect/routes/index.ts +++ b/src/lib/seam/connect/routes/index.ts @@ -20,6 +20,7 @@ export * from './networks.js' export * from './noise-sensors.js' export * from './noise-sensors-noise-thresholds.js' export * from './phones.js' +export * from './phones-simulate.js' export * from './thermostats.js' export * from './thermostats-climate-setting-schedules.js' export * from './user-identities.js' diff --git a/src/lib/seam/connect/routes/phones-simulate.ts b/src/lib/seam/connect/routes/phones-simulate.ts new file mode 100644 index 00000000..c75450ad --- /dev/null +++ b/src/lib/seam/connect/routes/phones-simulate.ts @@ -0,0 +1,177 @@ +/* + * Automatically generated by generate-routes.ts. + * Do not edit this file or add other files to this directory. + */ + +import type { RouteRequestBody, RouteResponse } from '@seamapi/types/connect' +import type { SetNonNullable } from 'type-fest' + +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 './client-sessions.js' + +export class SeamHttpPhonesSimulate { + client: Client + readonly defaults: Required + + 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 = {}, + ): SeamHttpPhonesSimulate { + const constructorOptions = { ...options, client } + if (!isSeamHttpOptionsWithClient(constructorOptions)) { + throw new SeamHttpInvalidOptionsError('Missing client') + } + return new SeamHttpPhonesSimulate(constructorOptions) + } + + static fromApiKey( + apiKey: SeamHttpOptionsWithApiKey['apiKey'], + options: Omit = {}, + ): SeamHttpPhonesSimulate { + const constructorOptions = { ...options, apiKey } + if (!isSeamHttpOptionsWithApiKey(constructorOptions)) { + throw new SeamHttpInvalidOptionsError('Missing apiKey') + } + return new SeamHttpPhonesSimulate(constructorOptions) + } + + static fromClientSessionToken( + clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'], + options: Omit< + SeamHttpOptionsWithClientSessionToken, + 'clientSessionToken' + > = {}, + ): SeamHttpPhonesSimulate { + const constructorOptions = { ...options, clientSessionToken } + if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) { + throw new SeamHttpInvalidOptionsError('Missing clientSessionToken') + } + return new SeamHttpPhonesSimulate(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 SeamHttp.fromPublishableKey', + ) + } + const client = createClient(clientOptions) + const clientSessions = SeamHttpClientSessions.fromClient(client) + const { token } = await clientSessions.getOrCreate({ + user_identifier_key: userIdentifierKey, + }) + return SeamHttpPhonesSimulate.fromClientSessionToken(token, options) + } + + static fromConsoleSessionToken( + consoleSessionToken: SeamHttpOptionsWithConsoleSessionToken['consoleSessionToken'], + workspaceId: SeamHttpOptionsWithConsoleSessionToken['workspaceId'], + options: Omit< + SeamHttpOptionsWithConsoleSessionToken, + 'consoleSessionToken' | 'workspaceId' + > = {}, + ): SeamHttpPhonesSimulate { + const constructorOptions = { ...options, consoleSessionToken, workspaceId } + if (!isSeamHttpOptionsWithConsoleSessionToken(constructorOptions)) { + throw new SeamHttpInvalidOptionsError( + 'Missing consoleSessionToken or workspaceId', + ) + } + return new SeamHttpPhonesSimulate(constructorOptions) + } + + static fromPersonalAccessToken( + personalAccessToken: SeamHttpOptionsWithPersonalAccessToken['personalAccessToken'], + workspaceId: SeamHttpOptionsWithPersonalAccessToken['workspaceId'], + options: Omit< + SeamHttpOptionsWithPersonalAccessToken, + 'personalAccessToken' | 'workspaceId' + > = {}, + ): SeamHttpPhonesSimulate { + const constructorOptions = { ...options, personalAccessToken, workspaceId } + if (!isSeamHttpOptionsWithPersonalAccessToken(constructorOptions)) { + throw new SeamHttpInvalidOptionsError( + 'Missing personalAccessToken or workspaceId', + ) + } + return new SeamHttpPhonesSimulate(constructorOptions) + } + + 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() + } + + async createSandboxPhone( + body?: PhonesSimulateCreateSandboxPhoneBody, + ): Promise { + const { data } = + await this.client.request({ + url: '/phones/simulate/create_sandbox_phone', + method: 'post', + data: body, + }) + + return data.phone + } +} + +export type PhonesSimulateCreateSandboxPhoneBody = + RouteRequestBody<'/phones/simulate/create_sandbox_phone'> + +export type PhonesSimulateCreateSandboxPhoneResponse = SetNonNullable< + Required> +> + +export type PhonesSimulateCreateSandboxPhoneOptions = never diff --git a/src/lib/seam/connect/routes/phones.ts b/src/lib/seam/connect/routes/phones.ts index e0ce67df..526ec7ce 100644 --- a/src/lib/seam/connect/routes/phones.ts +++ b/src/lib/seam/connect/routes/phones.ts @@ -33,6 +33,7 @@ import { } from 'lib/seam/connect/parse-options.js' import { SeamHttpClientSessions } from './client-sessions.js' +import { SeamHttpPhonesSimulate } from './phones-simulate.js' export class SeamHttpPhones { client: Client @@ -153,6 +154,10 @@ export class SeamHttpPhones { await clientSessions.get() } + get simulate(): SeamHttpPhonesSimulate { + return SeamHttpPhonesSimulate.fromClient(this.client, this.defaults) + } + async deactivate(body?: PhonesDeactivateBody): Promise { await this.client.request({ url: '/phones/deactivate',