/* * 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 { ThermostatDailyProgram } from 'lib/seam/connect/resources/thermostat-daily-program.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 SeamHttpThermostatsDailyPrograms { 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 = {}, ): SeamHttpThermostatsDailyPrograms { const constructorOptions = { ...options, client } if (!isSeamHttpOptionsWithClient(constructorOptions)) { throw new SeamHttpInvalidOptionsError('Missing client') } return new SeamHttpThermostatsDailyPrograms(constructorOptions) } static fromApiKey( apiKey: SeamHttpOptionsWithApiKey['apiKey'], options: Omit = {}, ): SeamHttpThermostatsDailyPrograms { const constructorOptions = { ...options, apiKey } if (!isSeamHttpOptionsWithApiKey(constructorOptions)) { throw new SeamHttpInvalidOptionsError('Missing apiKey') } return new SeamHttpThermostatsDailyPrograms(constructorOptions) } static fromClientSessionToken( clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'], options: Omit< SeamHttpOptionsWithClientSessionToken, 'clientSessionToken' > = {}, ): SeamHttpThermostatsDailyPrograms { const constructorOptions = { ...options, clientSessionToken } if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) { throw new SeamHttpInvalidOptionsError('Missing clientSessionToken') } return new SeamHttpThermostatsDailyPrograms(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 SeamHttpThermostatsDailyPrograms.fromPublishableKey', ) } const client = createClient(clientOptions) const clientSessions = SeamHttpClientSessions.fromClient(client) const { token } = await clientSessions.getOrCreate({ user_identifier_key: userIdentifierKey, }) return SeamHttpThermostatsDailyPrograms.fromClientSessionToken( token, options, ) } static fromConsoleSessionToken( consoleSessionToken: SeamHttpOptionsWithConsoleSessionToken['consoleSessionToken'], workspaceId: SeamHttpOptionsWithConsoleSessionToken['workspaceId'], options: Omit< SeamHttpOptionsWithConsoleSessionToken, 'consoleSessionToken' | 'workspaceId' > = {}, ): SeamHttpThermostatsDailyPrograms { const constructorOptions = { ...options, consoleSessionToken, workspaceId } if (!isSeamHttpOptionsWithConsoleSessionToken(constructorOptions)) { throw new SeamHttpInvalidOptionsError( 'Missing consoleSessionToken or workspaceId', ) } return new SeamHttpThermostatsDailyPrograms(constructorOptions) } static fromPersonalAccessToken( personalAccessToken: SeamHttpOptionsWithPersonalAccessToken['personalAccessToken'], workspaceId: SeamHttpOptionsWithPersonalAccessToken['workspaceId'], options: Omit< SeamHttpOptionsWithPersonalAccessToken, 'personalAccessToken' | 'workspaceId' > = {}, ): SeamHttpThermostatsDailyPrograms { const constructorOptions = { ...options, personalAccessToken, workspaceId } if (!isSeamHttpOptionsWithPersonalAccessToken(constructorOptions)) { throw new SeamHttpInvalidOptionsError( 'Missing personalAccessToken or workspaceId', ) } return new SeamHttpThermostatsDailyPrograms(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 thermostat daily program. A daily program consists of a set of periods, where each period includes a start time and the key of a configured climate preset. Once you have defined a daily program, you can assign it to one or more days within a weekly program. */ create( parameters: ThermostatsDailyProgramsCreateParameters, options: ThermostatsDailyProgramsCreateOptions = {}, ): ThermostatsDailyProgramsCreateRequest { return new SeamHttpRequest(this, { pathname: '/thermostats/daily_programs/create', method: 'POST', body: parameters, responseKey: 'thermostat_daily_program', options, }) } /** * Deletes a thermostat daily program. */ delete( parameters: ThermostatsDailyProgramsDeleteParameters, options: ThermostatsDailyProgramsDeleteOptions = {}, ): ThermostatsDailyProgramsDeleteRequest { return new SeamHttpRequest(this, { pathname: '/thermostats/daily_programs/delete', method: 'POST', body: parameters, responseKey: undefined, options, }) } /** * Updates a specified thermostat daily program. The periods that you specify overwrite any existing periods for the daily program. */ update( parameters: ThermostatsDailyProgramsUpdateParameters, options: ThermostatsDailyProgramsUpdateOptions = {}, ): ThermostatsDailyProgramsUpdateRequest { return new SeamHttpRequest(this, { pathname: '/thermostats/daily_programs/update', method: 'PATCH', body: parameters, responseKey: 'action_attempt', options, }) } } export type ThermostatsDailyProgramsCreateParameters = { /** * ID of the thermostat device for which you want to create a daily program. */ device_id: string /** * Name of the thermostat daily program. */ name: string /** * Array of thermostat daily program periods. */ periods: Array<{ /** * Key of the [climate preset](https://docs.seam.co/capability-guides/thermostats/creating-and-managing-climate-presets) to activate at the `starts_at_time`. */ climate_preset_key?: string | undefined /** * Time at which the thermostat daily program period starts, in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. */ starts_at_time?: string | undefined }> } /** * @deprecated Use ThermostatsDailyProgramsCreateRequest instead. */ export type ThermostatsDailyProgramsCreateResponse = { thermostat_daily_program: ThermostatDailyProgram } export type ThermostatsDailyProgramsCreateRequest = SeamHttpRequest< ThermostatsDailyProgramsCreateResponse, 'thermostat_daily_program' > export interface ThermostatsDailyProgramsCreateOptions {} export type ThermostatsDailyProgramsDeleteParameters = { /** * ID of the thermostat daily program that you want to delete. */ thermostat_daily_program_id: string } /** * @deprecated Use ThermostatsDailyProgramsDeleteRequest instead. */ export type ThermostatsDailyProgramsDeleteResponse = void export type ThermostatsDailyProgramsDeleteRequest = SeamHttpRequest< void, undefined > export interface ThermostatsDailyProgramsDeleteOptions {} export type ThermostatsDailyProgramsUpdateParameters = { /** * Name of the thermostat daily program that you want to update. */ name: string /** * Array of thermostat daily program periods. The periods that you specify overwrite any existing periods for the daily program. */ periods: Array<{ /** * Key of the [climate preset](https://docs.seam.co/capability-guides/thermostats/creating-and-managing-climate-presets) to activate at the `starts_at_time`. */ climate_preset_key?: string | undefined /** * Time at which the thermostat daily program period starts, in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. */ starts_at_time?: string | undefined }> /** * ID of the thermostat daily program that you want to update. */ thermostat_daily_program_id: string } /** * @deprecated Use ThermostatsDailyProgramsUpdateRequest instead. */ export type ThermostatsDailyProgramsUpdateResponse = { action_attempt: ActionAttempt } export type ThermostatsDailyProgramsUpdateRequest = SeamHttpRequest< ThermostatsDailyProgramsUpdateResponse, 'action_attempt' > export type ThermostatsDailyProgramsUpdateOptions = Pick< SeamHttpRequestOptions, 'waitForActionAttempt' >