From c143d784552125cead9c6ed84278f1f0126eea49 Mon Sep 17 00:00:00 2001 From: Evan Sosenko Date: Thu, 16 Nov 2023 17:05:49 +0900 Subject: [PATCH] Use limitToSeamHttpRequestOptions --- generate-routes.ts | 5 ++++- src/lib/seam/connect/options.ts | 8 +------ src/lib/seam/connect/parse-options.ts | 21 +++++++++++++++++++ .../connect/routes/access-codes-unmanaged.ts | 15 +++++++------ src/lib/seam/connect/routes/access-codes.ts | 15 +++++++------ .../seam/connect/routes/acs-access-groups.ts | 15 +++++++------ .../seam/connect/routes/acs-credentials.ts | 15 +++++++------ src/lib/seam/connect/routes/acs-systems.ts | 15 +++++++------ src/lib/seam/connect/routes/acs-users.ts | 15 +++++++------ src/lib/seam/connect/routes/acs.ts | 15 +++++++------ .../seam/connect/routes/action-attempts.ts | 15 +++++++------ .../seam/connect/routes/client-sessions.ts | 15 +++++++------ .../seam/connect/routes/connect-webviews.ts | 15 +++++++------ .../seam/connect/routes/connected-accounts.ts | 15 +++++++------ .../seam/connect/routes/devices-unmanaged.ts | 15 +++++++------ src/lib/seam/connect/routes/devices.ts | 15 +++++++------ src/lib/seam/connect/routes/events.ts | 15 +++++++------ src/lib/seam/connect/routes/locks.ts | 15 +++++++------ .../routes/noise-sensors-noise-thresholds.ts | 15 +++++++------ src/lib/seam/connect/routes/noise-sensors.ts | 15 +++++++------ .../thermostats-climate-setting-schedules.ts | 15 +++++++------ src/lib/seam/connect/routes/thermostats.ts | 15 +++++++------ .../seam/connect/routes/user-identities.ts | 15 +++++++------ src/lib/seam/connect/routes/webhooks.ts | 15 +++++++------ src/lib/seam/connect/routes/workspaces.ts | 15 +++++++------ .../seam/connect/seam-http-multi-workspace.ts | 8 +++---- src/lib/seam/connect/seam-http.ts | 8 +++---- 27 files changed, 230 insertions(+), 150 deletions(-) diff --git a/generate-routes.ts b/generate-routes.ts index 58fef54a..29c98048 100644 --- a/generate-routes.ts +++ b/generate-routes.ts @@ -256,7 +256,10 @@ import { type SeamHttpOptionsWithPersonalAccessToken, type SeamHttpRequestOptions, } from 'lib/seam/connect/options.js' -import { parseOptions } from 'lib/seam/connect/parse-options.js' +import { + limitToSeamHttpRequestOptions, + parseOptions +} from 'lib/seam/connect/parse-options.js' import { resolveActionAttempt, } from 'lib/seam/connect/resolve-action-attempt.js' diff --git a/src/lib/seam/connect/options.ts b/src/lib/seam/connect/options.ts index 4204e242..35fc63e7 100644 --- a/src/lib/seam/connect/options.ts +++ b/src/lib/seam/connect/options.ts @@ -1,4 +1,5 @@ import type { Client, ClientOptions } from './client.js' +import { isSeamHttpRequestOption } from './parse-options.js' import type { ResolveActionAttemptOptions } from './resolve-action-attempt.js' export type SeamHttpMultiWorkspaceOptions = @@ -22,13 +23,6 @@ export interface SeamHttpRequestOptions { waitForActionAttempt?: boolean | ResolveActionAttemptOptions } -const isSeamHttpRequestOption = (key: string): boolean => { - const keys: Record = { - waitForActionAttempt: true, - } - return Object.keys(keys).includes(key) -} - export interface SeamHttpFromPublishableKeyOptions extends SeamHttpCommonOptions {} diff --git a/src/lib/seam/connect/parse-options.ts b/src/lib/seam/connect/parse-options.ts index da7efc49..a1104071 100644 --- a/src/lib/seam/connect/parse-options.ts +++ b/src/lib/seam/connect/parse-options.ts @@ -96,3 +96,24 @@ const getEndpointFromEnv = (): string | null | undefined => { globalThis.process?.env?.SEAM_API_URL ) } + +export const limitToSeamHttpRequestOptions = ( + options: Required, +): Required => { + return Object.keys(options) + .filter(isSeamHttpRequestOption) + .reduce( + (obj, key) => ({ + ...obj, + [key]: options[key as keyof SeamHttpRequestOptions], + }), + {}, + ) as Required +} + +export const isSeamHttpRequestOption = (key: string): boolean => { + const keys: Record = { + waitForActionAttempt: true, + } + return Object.keys(keys).includes(key) +} diff --git a/src/lib/seam/connect/routes/access-codes-unmanaged.ts b/src/lib/seam/connect/routes/access-codes-unmanaged.ts index 476ff1f2..7d3c8521 100644 --- a/src/lib/seam/connect/routes/access-codes-unmanaged.ts +++ b/src/lib/seam/connect/routes/access-codes-unmanaged.ts @@ -24,7 +24,10 @@ import { type SeamHttpOptionsWithPersonalAccessToken, type SeamHttpRequestOptions, } from 'lib/seam/connect/options.js' -import { parseOptions } from 'lib/seam/connect/parse-options.js' +import { + limitToSeamHttpRequestOptions, + parseOptions, +} from 'lib/seam/connect/parse-options.js' import { SeamHttpClientSessions } from './client-sessions.js' @@ -33,11 +36,9 @@ export class SeamHttpAccessCodesUnmanaged { readonly defaults: Required constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) { - const { waitForActionAttempt, ...options } = parseOptions(apiKeyOrOptions) + const options = parseOptions(apiKeyOrOptions) this.client = 'client' in options ? options.client : createClient(options) - this.defaults = { - waitForActionAttempt, - } + this.defaults = limitToSeamHttpRequestOptions(options) } static fromClient( @@ -84,7 +85,9 @@ export class SeamHttpAccessCodesUnmanaged { warnOnInsecureuserIdentifierKey(userIdentifierKey) const clientOptions = parseOptions({ ...options, publishableKey }) if (isSeamHttpOptionsWithClient(clientOptions)) { - throw new Error('Cannot pass a client when using fromPublishableKey') + throw new SeamHttpInvalidOptionsError( + 'The client option cannot be used with SeamHttp.fromPublishableKey', + ) } const client = createClient(clientOptions) const clientSessions = SeamHttpClientSessions.fromClient(client) diff --git a/src/lib/seam/connect/routes/access-codes.ts b/src/lib/seam/connect/routes/access-codes.ts index 35ae0939..757d5d5b 100644 --- a/src/lib/seam/connect/routes/access-codes.ts +++ b/src/lib/seam/connect/routes/access-codes.ts @@ -24,7 +24,10 @@ import { type SeamHttpOptionsWithPersonalAccessToken, type SeamHttpRequestOptions, } from 'lib/seam/connect/options.js' -import { parseOptions } from 'lib/seam/connect/parse-options.js' +import { + limitToSeamHttpRequestOptions, + parseOptions, +} from 'lib/seam/connect/parse-options.js' import { SeamHttpAccessCodesUnmanaged } from './access-codes-unmanaged.js' import { SeamHttpClientSessions } from './client-sessions.js' @@ -34,11 +37,9 @@ export class SeamHttpAccessCodes { readonly defaults: Required constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) { - const { waitForActionAttempt, ...options } = parseOptions(apiKeyOrOptions) + const options = parseOptions(apiKeyOrOptions) this.client = 'client' in options ? options.client : createClient(options) - this.defaults = { - waitForActionAttempt, - } + this.defaults = limitToSeamHttpRequestOptions(options) } static fromClient( @@ -85,7 +86,9 @@ export class SeamHttpAccessCodes { warnOnInsecureuserIdentifierKey(userIdentifierKey) const clientOptions = parseOptions({ ...options, publishableKey }) if (isSeamHttpOptionsWithClient(clientOptions)) { - throw new Error('Cannot pass a client when using fromPublishableKey') + throw new SeamHttpInvalidOptionsError( + 'The client option cannot be used with SeamHttp.fromPublishableKey', + ) } const client = createClient(clientOptions) const clientSessions = SeamHttpClientSessions.fromClient(client) diff --git a/src/lib/seam/connect/routes/acs-access-groups.ts b/src/lib/seam/connect/routes/acs-access-groups.ts index d5765f1f..8829480e 100644 --- a/src/lib/seam/connect/routes/acs-access-groups.ts +++ b/src/lib/seam/connect/routes/acs-access-groups.ts @@ -24,7 +24,10 @@ import { type SeamHttpOptionsWithPersonalAccessToken, type SeamHttpRequestOptions, } from 'lib/seam/connect/options.js' -import { parseOptions } from 'lib/seam/connect/parse-options.js' +import { + limitToSeamHttpRequestOptions, + parseOptions, +} from 'lib/seam/connect/parse-options.js' import { SeamHttpClientSessions } from './client-sessions.js' @@ -33,11 +36,9 @@ export class SeamHttpAcsAccessGroups { readonly defaults: Required constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) { - const { waitForActionAttempt, ...options } = parseOptions(apiKeyOrOptions) + const options = parseOptions(apiKeyOrOptions) this.client = 'client' in options ? options.client : createClient(options) - this.defaults = { - waitForActionAttempt, - } + this.defaults = limitToSeamHttpRequestOptions(options) } static fromClient( @@ -84,7 +85,9 @@ export class SeamHttpAcsAccessGroups { warnOnInsecureuserIdentifierKey(userIdentifierKey) const clientOptions = parseOptions({ ...options, publishableKey }) if (isSeamHttpOptionsWithClient(clientOptions)) { - throw new Error('Cannot pass a client when using fromPublishableKey') + throw new SeamHttpInvalidOptionsError( + 'The client option cannot be used with SeamHttp.fromPublishableKey', + ) } const client = createClient(clientOptions) const clientSessions = SeamHttpClientSessions.fromClient(client) diff --git a/src/lib/seam/connect/routes/acs-credentials.ts b/src/lib/seam/connect/routes/acs-credentials.ts index e3474bd0..d49ab14f 100644 --- a/src/lib/seam/connect/routes/acs-credentials.ts +++ b/src/lib/seam/connect/routes/acs-credentials.ts @@ -24,7 +24,10 @@ import { type SeamHttpOptionsWithPersonalAccessToken, type SeamHttpRequestOptions, } from 'lib/seam/connect/options.js' -import { parseOptions } from 'lib/seam/connect/parse-options.js' +import { + limitToSeamHttpRequestOptions, + parseOptions, +} from 'lib/seam/connect/parse-options.js' import { SeamHttpClientSessions } from './client-sessions.js' @@ -33,11 +36,9 @@ export class SeamHttpAcsCredentials { readonly defaults: Required constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) { - const { waitForActionAttempt, ...options } = parseOptions(apiKeyOrOptions) + const options = parseOptions(apiKeyOrOptions) this.client = 'client' in options ? options.client : createClient(options) - this.defaults = { - waitForActionAttempt, - } + this.defaults = limitToSeamHttpRequestOptions(options) } static fromClient( @@ -84,7 +85,9 @@ export class SeamHttpAcsCredentials { warnOnInsecureuserIdentifierKey(userIdentifierKey) const clientOptions = parseOptions({ ...options, publishableKey }) if (isSeamHttpOptionsWithClient(clientOptions)) { - throw new Error('Cannot pass a client when using fromPublishableKey') + throw new SeamHttpInvalidOptionsError( + 'The client option cannot be used with SeamHttp.fromPublishableKey', + ) } const client = createClient(clientOptions) const clientSessions = SeamHttpClientSessions.fromClient(client) diff --git a/src/lib/seam/connect/routes/acs-systems.ts b/src/lib/seam/connect/routes/acs-systems.ts index 8aaae789..9e8a83d3 100644 --- a/src/lib/seam/connect/routes/acs-systems.ts +++ b/src/lib/seam/connect/routes/acs-systems.ts @@ -24,7 +24,10 @@ import { type SeamHttpOptionsWithPersonalAccessToken, type SeamHttpRequestOptions, } from 'lib/seam/connect/options.js' -import { parseOptions } from 'lib/seam/connect/parse-options.js' +import { + limitToSeamHttpRequestOptions, + parseOptions, +} from 'lib/seam/connect/parse-options.js' import { SeamHttpClientSessions } from './client-sessions.js' @@ -33,11 +36,9 @@ export class SeamHttpAcsSystems { readonly defaults: Required constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) { - const { waitForActionAttempt, ...options } = parseOptions(apiKeyOrOptions) + const options = parseOptions(apiKeyOrOptions) this.client = 'client' in options ? options.client : createClient(options) - this.defaults = { - waitForActionAttempt, - } + this.defaults = limitToSeamHttpRequestOptions(options) } static fromClient( @@ -84,7 +85,9 @@ export class SeamHttpAcsSystems { warnOnInsecureuserIdentifierKey(userIdentifierKey) const clientOptions = parseOptions({ ...options, publishableKey }) if (isSeamHttpOptionsWithClient(clientOptions)) { - throw new Error('Cannot pass a client when using fromPublishableKey') + throw new SeamHttpInvalidOptionsError( + 'The client option cannot be used with SeamHttp.fromPublishableKey', + ) } const client = createClient(clientOptions) const clientSessions = SeamHttpClientSessions.fromClient(client) diff --git a/src/lib/seam/connect/routes/acs-users.ts b/src/lib/seam/connect/routes/acs-users.ts index 3bfb4c0c..beeb2c0d 100644 --- a/src/lib/seam/connect/routes/acs-users.ts +++ b/src/lib/seam/connect/routes/acs-users.ts @@ -24,7 +24,10 @@ import { type SeamHttpOptionsWithPersonalAccessToken, type SeamHttpRequestOptions, } from 'lib/seam/connect/options.js' -import { parseOptions } from 'lib/seam/connect/parse-options.js' +import { + limitToSeamHttpRequestOptions, + parseOptions, +} from 'lib/seam/connect/parse-options.js' import { SeamHttpClientSessions } from './client-sessions.js' @@ -33,11 +36,9 @@ export class SeamHttpAcsUsers { readonly defaults: Required constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) { - const { waitForActionAttempt, ...options } = parseOptions(apiKeyOrOptions) + const options = parseOptions(apiKeyOrOptions) this.client = 'client' in options ? options.client : createClient(options) - this.defaults = { - waitForActionAttempt, - } + this.defaults = limitToSeamHttpRequestOptions(options) } static fromClient( @@ -84,7 +85,9 @@ export class SeamHttpAcsUsers { warnOnInsecureuserIdentifierKey(userIdentifierKey) const clientOptions = parseOptions({ ...options, publishableKey }) if (isSeamHttpOptionsWithClient(clientOptions)) { - throw new Error('Cannot pass a client when using fromPublishableKey') + throw new SeamHttpInvalidOptionsError( + 'The client option cannot be used with SeamHttp.fromPublishableKey', + ) } const client = createClient(clientOptions) const clientSessions = SeamHttpClientSessions.fromClient(client) diff --git a/src/lib/seam/connect/routes/acs.ts b/src/lib/seam/connect/routes/acs.ts index f5e46c8d..cdfceb14 100644 --- a/src/lib/seam/connect/routes/acs.ts +++ b/src/lib/seam/connect/routes/acs.ts @@ -21,7 +21,10 @@ import { type SeamHttpOptionsWithPersonalAccessToken, type SeamHttpRequestOptions, } from 'lib/seam/connect/options.js' -import { parseOptions } from 'lib/seam/connect/parse-options.js' +import { + limitToSeamHttpRequestOptions, + parseOptions, +} from 'lib/seam/connect/parse-options.js' import { SeamHttpAcsAccessGroups } from './acs-access-groups.js' import { SeamHttpAcsCredentials } from './acs-credentials.js' @@ -34,11 +37,9 @@ export class SeamHttpAcs { readonly defaults: Required constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) { - const { waitForActionAttempt, ...options } = parseOptions(apiKeyOrOptions) + const options = parseOptions(apiKeyOrOptions) this.client = 'client' in options ? options.client : createClient(options) - this.defaults = { - waitForActionAttempt, - } + this.defaults = limitToSeamHttpRequestOptions(options) } static fromClient( @@ -85,7 +86,9 @@ export class SeamHttpAcs { warnOnInsecureuserIdentifierKey(userIdentifierKey) const clientOptions = parseOptions({ ...options, publishableKey }) if (isSeamHttpOptionsWithClient(clientOptions)) { - throw new Error('Cannot pass a client when using fromPublishableKey') + throw new SeamHttpInvalidOptionsError( + 'The client option cannot be used with SeamHttp.fromPublishableKey', + ) } const client = createClient(clientOptions) const clientSessions = SeamHttpClientSessions.fromClient(client) diff --git a/src/lib/seam/connect/routes/action-attempts.ts b/src/lib/seam/connect/routes/action-attempts.ts index a3c80fe4..585fb674 100644 --- a/src/lib/seam/connect/routes/action-attempts.ts +++ b/src/lib/seam/connect/routes/action-attempts.ts @@ -24,7 +24,10 @@ import { type SeamHttpOptionsWithPersonalAccessToken, type SeamHttpRequestOptions, } from 'lib/seam/connect/options.js' -import { parseOptions } from 'lib/seam/connect/parse-options.js' +import { + limitToSeamHttpRequestOptions, + parseOptions, +} from 'lib/seam/connect/parse-options.js' import { resolveActionAttempt } from 'lib/seam/connect/resolve-action-attempt.js' import { SeamHttpClientSessions } from './client-sessions.js' @@ -34,11 +37,9 @@ export class SeamHttpActionAttempts { readonly defaults: Required constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) { - const { waitForActionAttempt, ...options } = parseOptions(apiKeyOrOptions) + const options = parseOptions(apiKeyOrOptions) this.client = 'client' in options ? options.client : createClient(options) - this.defaults = { - waitForActionAttempt, - } + this.defaults = limitToSeamHttpRequestOptions(options) } static fromClient( @@ -85,7 +86,9 @@ export class SeamHttpActionAttempts { warnOnInsecureuserIdentifierKey(userIdentifierKey) const clientOptions = parseOptions({ ...options, publishableKey }) if (isSeamHttpOptionsWithClient(clientOptions)) { - throw new Error('Cannot pass a client when using fromPublishableKey') + throw new SeamHttpInvalidOptionsError( + 'The client option cannot be used with SeamHttp.fromPublishableKey', + ) } const client = createClient(clientOptions) const clientSessions = SeamHttpClientSessions.fromClient(client) diff --git a/src/lib/seam/connect/routes/client-sessions.ts b/src/lib/seam/connect/routes/client-sessions.ts index f15f7008..824bbce1 100644 --- a/src/lib/seam/connect/routes/client-sessions.ts +++ b/src/lib/seam/connect/routes/client-sessions.ts @@ -24,18 +24,19 @@ import { type SeamHttpOptionsWithPersonalAccessToken, type SeamHttpRequestOptions, } from 'lib/seam/connect/options.js' -import { parseOptions } from 'lib/seam/connect/parse-options.js' +import { + limitToSeamHttpRequestOptions, + parseOptions, +} from 'lib/seam/connect/parse-options.js' export class SeamHttpClientSessions { client: Client readonly defaults: Required constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) { - const { waitForActionAttempt, ...options } = parseOptions(apiKeyOrOptions) + const options = parseOptions(apiKeyOrOptions) this.client = 'client' in options ? options.client : createClient(options) - this.defaults = { - waitForActionAttempt, - } + this.defaults = limitToSeamHttpRequestOptions(options) } static fromClient( @@ -82,7 +83,9 @@ export class SeamHttpClientSessions { warnOnInsecureuserIdentifierKey(userIdentifierKey) const clientOptions = parseOptions({ ...options, publishableKey }) if (isSeamHttpOptionsWithClient(clientOptions)) { - throw new Error('Cannot pass a client when using fromPublishableKey') + throw new SeamHttpInvalidOptionsError( + 'The client option cannot be used with SeamHttp.fromPublishableKey', + ) } const client = createClient(clientOptions) const clientSessions = SeamHttpClientSessions.fromClient(client) diff --git a/src/lib/seam/connect/routes/connect-webviews.ts b/src/lib/seam/connect/routes/connect-webviews.ts index 2cbc052b..f98678a0 100644 --- a/src/lib/seam/connect/routes/connect-webviews.ts +++ b/src/lib/seam/connect/routes/connect-webviews.ts @@ -28,7 +28,10 @@ import { type SeamHttpOptionsWithPersonalAccessToken, type SeamHttpRequestOptions, } from 'lib/seam/connect/options.js' -import { parseOptions } from 'lib/seam/connect/parse-options.js' +import { + limitToSeamHttpRequestOptions, + parseOptions, +} from 'lib/seam/connect/parse-options.js' import { SeamHttpClientSessions } from './client-sessions.js' @@ -37,11 +40,9 @@ export class SeamHttpConnectWebviews { readonly defaults: Required constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) { - const { waitForActionAttempt, ...options } = parseOptions(apiKeyOrOptions) + const options = parseOptions(apiKeyOrOptions) this.client = 'client' in options ? options.client : createClient(options) - this.defaults = { - waitForActionAttempt, - } + this.defaults = limitToSeamHttpRequestOptions(options) } static fromClient( @@ -88,7 +89,9 @@ export class SeamHttpConnectWebviews { warnOnInsecureuserIdentifierKey(userIdentifierKey) const clientOptions = parseOptions({ ...options, publishableKey }) if (isSeamHttpOptionsWithClient(clientOptions)) { - throw new Error('Cannot pass a client when using fromPublishableKey') + throw new SeamHttpInvalidOptionsError( + 'The client option cannot be used with SeamHttp.fromPublishableKey', + ) } const client = createClient(clientOptions) const clientSessions = SeamHttpClientSessions.fromClient(client) diff --git a/src/lib/seam/connect/routes/connected-accounts.ts b/src/lib/seam/connect/routes/connected-accounts.ts index f07fed38..fff6c7ac 100644 --- a/src/lib/seam/connect/routes/connected-accounts.ts +++ b/src/lib/seam/connect/routes/connected-accounts.ts @@ -28,7 +28,10 @@ import { type SeamHttpOptionsWithPersonalAccessToken, type SeamHttpRequestOptions, } from 'lib/seam/connect/options.js' -import { parseOptions } from 'lib/seam/connect/parse-options.js' +import { + limitToSeamHttpRequestOptions, + parseOptions, +} from 'lib/seam/connect/parse-options.js' import { SeamHttpClientSessions } from './client-sessions.js' @@ -37,11 +40,9 @@ export class SeamHttpConnectedAccounts { readonly defaults: Required constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) { - const { waitForActionAttempt, ...options } = parseOptions(apiKeyOrOptions) + const options = parseOptions(apiKeyOrOptions) this.client = 'client' in options ? options.client : createClient(options) - this.defaults = { - waitForActionAttempt, - } + this.defaults = limitToSeamHttpRequestOptions(options) } static fromClient( @@ -88,7 +89,9 @@ export class SeamHttpConnectedAccounts { warnOnInsecureuserIdentifierKey(userIdentifierKey) const clientOptions = parseOptions({ ...options, publishableKey }) if (isSeamHttpOptionsWithClient(clientOptions)) { - throw new Error('Cannot pass a client when using fromPublishableKey') + throw new SeamHttpInvalidOptionsError( + 'The client option cannot be used with SeamHttp.fromPublishableKey', + ) } const client = createClient(clientOptions) const clientSessions = SeamHttpClientSessions.fromClient(client) diff --git a/src/lib/seam/connect/routes/devices-unmanaged.ts b/src/lib/seam/connect/routes/devices-unmanaged.ts index 6aadde23..d25bc53d 100644 --- a/src/lib/seam/connect/routes/devices-unmanaged.ts +++ b/src/lib/seam/connect/routes/devices-unmanaged.ts @@ -24,7 +24,10 @@ import { type SeamHttpOptionsWithPersonalAccessToken, type SeamHttpRequestOptions, } from 'lib/seam/connect/options.js' -import { parseOptions } from 'lib/seam/connect/parse-options.js' +import { + limitToSeamHttpRequestOptions, + parseOptions, +} from 'lib/seam/connect/parse-options.js' import { SeamHttpClientSessions } from './client-sessions.js' @@ -33,11 +36,9 @@ export class SeamHttpDevicesUnmanaged { readonly defaults: Required constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) { - const { waitForActionAttempt, ...options } = parseOptions(apiKeyOrOptions) + const options = parseOptions(apiKeyOrOptions) this.client = 'client' in options ? options.client : createClient(options) - this.defaults = { - waitForActionAttempt, - } + this.defaults = limitToSeamHttpRequestOptions(options) } static fromClient( @@ -84,7 +85,9 @@ export class SeamHttpDevicesUnmanaged { warnOnInsecureuserIdentifierKey(userIdentifierKey) const clientOptions = parseOptions({ ...options, publishableKey }) if (isSeamHttpOptionsWithClient(clientOptions)) { - throw new Error('Cannot pass a client when using fromPublishableKey') + throw new SeamHttpInvalidOptionsError( + 'The client option cannot be used with SeamHttp.fromPublishableKey', + ) } const client = createClient(clientOptions) const clientSessions = SeamHttpClientSessions.fromClient(client) diff --git a/src/lib/seam/connect/routes/devices.ts b/src/lib/seam/connect/routes/devices.ts index 1c798ee6..b2eff086 100644 --- a/src/lib/seam/connect/routes/devices.ts +++ b/src/lib/seam/connect/routes/devices.ts @@ -24,7 +24,10 @@ import { type SeamHttpOptionsWithPersonalAccessToken, type SeamHttpRequestOptions, } from 'lib/seam/connect/options.js' -import { parseOptions } from 'lib/seam/connect/parse-options.js' +import { + limitToSeamHttpRequestOptions, + parseOptions, +} from 'lib/seam/connect/parse-options.js' import { SeamHttpClientSessions } from './client-sessions.js' import { SeamHttpDevicesUnmanaged } from './devices-unmanaged.js' @@ -34,11 +37,9 @@ export class SeamHttpDevices { readonly defaults: Required constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) { - const { waitForActionAttempt, ...options } = parseOptions(apiKeyOrOptions) + const options = parseOptions(apiKeyOrOptions) this.client = 'client' in options ? options.client : createClient(options) - this.defaults = { - waitForActionAttempt, - } + this.defaults = limitToSeamHttpRequestOptions(options) } static fromClient( @@ -85,7 +86,9 @@ export class SeamHttpDevices { warnOnInsecureuserIdentifierKey(userIdentifierKey) const clientOptions = parseOptions({ ...options, publishableKey }) if (isSeamHttpOptionsWithClient(clientOptions)) { - throw new Error('Cannot pass a client when using fromPublishableKey') + throw new SeamHttpInvalidOptionsError( + 'The client option cannot be used with SeamHttp.fromPublishableKey', + ) } const client = createClient(clientOptions) const clientSessions = SeamHttpClientSessions.fromClient(client) diff --git a/src/lib/seam/connect/routes/events.ts b/src/lib/seam/connect/routes/events.ts index 5872ee0a..89684634 100644 --- a/src/lib/seam/connect/routes/events.ts +++ b/src/lib/seam/connect/routes/events.ts @@ -24,7 +24,10 @@ import { type SeamHttpOptionsWithPersonalAccessToken, type SeamHttpRequestOptions, } from 'lib/seam/connect/options.js' -import { parseOptions } from 'lib/seam/connect/parse-options.js' +import { + limitToSeamHttpRequestOptions, + parseOptions, +} from 'lib/seam/connect/parse-options.js' import { SeamHttpClientSessions } from './client-sessions.js' @@ -33,11 +36,9 @@ export class SeamHttpEvents { readonly defaults: Required constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) { - const { waitForActionAttempt, ...options } = parseOptions(apiKeyOrOptions) + const options = parseOptions(apiKeyOrOptions) this.client = 'client' in options ? options.client : createClient(options) - this.defaults = { - waitForActionAttempt, - } + this.defaults = limitToSeamHttpRequestOptions(options) } static fromClient( @@ -84,7 +85,9 @@ export class SeamHttpEvents { warnOnInsecureuserIdentifierKey(userIdentifierKey) const clientOptions = parseOptions({ ...options, publishableKey }) if (isSeamHttpOptionsWithClient(clientOptions)) { - throw new Error('Cannot pass a client when using fromPublishableKey') + throw new SeamHttpInvalidOptionsError( + 'The client option cannot be used with SeamHttp.fromPublishableKey', + ) } const client = createClient(clientOptions) const clientSessions = SeamHttpClientSessions.fromClient(client) diff --git a/src/lib/seam/connect/routes/locks.ts b/src/lib/seam/connect/routes/locks.ts index cf1f1462..5dfd7906 100644 --- a/src/lib/seam/connect/routes/locks.ts +++ b/src/lib/seam/connect/routes/locks.ts @@ -24,7 +24,10 @@ import { type SeamHttpOptionsWithPersonalAccessToken, type SeamHttpRequestOptions, } from 'lib/seam/connect/options.js' -import { parseOptions } from 'lib/seam/connect/parse-options.js' +import { + limitToSeamHttpRequestOptions, + parseOptions, +} from 'lib/seam/connect/parse-options.js' import { resolveActionAttempt } from 'lib/seam/connect/resolve-action-attempt.js' import { SeamHttpActionAttempts } from './action-attempts.js' @@ -35,11 +38,9 @@ export class SeamHttpLocks { readonly defaults: Required constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) { - const { waitForActionAttempt, ...options } = parseOptions(apiKeyOrOptions) + const options = parseOptions(apiKeyOrOptions) this.client = 'client' in options ? options.client : createClient(options) - this.defaults = { - waitForActionAttempt, - } + this.defaults = limitToSeamHttpRequestOptions(options) } static fromClient( @@ -86,7 +87,9 @@ export class SeamHttpLocks { warnOnInsecureuserIdentifierKey(userIdentifierKey) const clientOptions = parseOptions({ ...options, publishableKey }) if (isSeamHttpOptionsWithClient(clientOptions)) { - throw new Error('Cannot pass a client when using fromPublishableKey') + throw new SeamHttpInvalidOptionsError( + 'The client option cannot be used with SeamHttp.fromPublishableKey', + ) } const client = createClient(clientOptions) const clientSessions = SeamHttpClientSessions.fromClient(client) diff --git a/src/lib/seam/connect/routes/noise-sensors-noise-thresholds.ts b/src/lib/seam/connect/routes/noise-sensors-noise-thresholds.ts index e38d9c74..6077bfdd 100644 --- a/src/lib/seam/connect/routes/noise-sensors-noise-thresholds.ts +++ b/src/lib/seam/connect/routes/noise-sensors-noise-thresholds.ts @@ -24,7 +24,10 @@ import { type SeamHttpOptionsWithPersonalAccessToken, type SeamHttpRequestOptions, } from 'lib/seam/connect/options.js' -import { parseOptions } from 'lib/seam/connect/parse-options.js' +import { + limitToSeamHttpRequestOptions, + parseOptions, +} from 'lib/seam/connect/parse-options.js' import { SeamHttpClientSessions } from './client-sessions.js' @@ -33,11 +36,9 @@ export class SeamHttpNoiseSensorsNoiseThresholds { readonly defaults: Required constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) { - const { waitForActionAttempt, ...options } = parseOptions(apiKeyOrOptions) + const options = parseOptions(apiKeyOrOptions) this.client = 'client' in options ? options.client : createClient(options) - this.defaults = { - waitForActionAttempt, - } + this.defaults = limitToSeamHttpRequestOptions(options) } static fromClient( @@ -84,7 +85,9 @@ export class SeamHttpNoiseSensorsNoiseThresholds { warnOnInsecureuserIdentifierKey(userIdentifierKey) const clientOptions = parseOptions({ ...options, publishableKey }) if (isSeamHttpOptionsWithClient(clientOptions)) { - throw new Error('Cannot pass a client when using fromPublishableKey') + throw new SeamHttpInvalidOptionsError( + 'The client option cannot be used with SeamHttp.fromPublishableKey', + ) } const client = createClient(clientOptions) const clientSessions = SeamHttpClientSessions.fromClient(client) diff --git a/src/lib/seam/connect/routes/noise-sensors.ts b/src/lib/seam/connect/routes/noise-sensors.ts index f8379f45..ccbda2aa 100644 --- a/src/lib/seam/connect/routes/noise-sensors.ts +++ b/src/lib/seam/connect/routes/noise-sensors.ts @@ -21,7 +21,10 @@ import { type SeamHttpOptionsWithPersonalAccessToken, type SeamHttpRequestOptions, } from 'lib/seam/connect/options.js' -import { parseOptions } from 'lib/seam/connect/parse-options.js' +import { + limitToSeamHttpRequestOptions, + parseOptions, +} from 'lib/seam/connect/parse-options.js' import { SeamHttpClientSessions } from './client-sessions.js' import { SeamHttpNoiseSensorsNoiseThresholds } from './noise-sensors-noise-thresholds.js' @@ -31,11 +34,9 @@ export class SeamHttpNoiseSensors { readonly defaults: Required constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) { - const { waitForActionAttempt, ...options } = parseOptions(apiKeyOrOptions) + const options = parseOptions(apiKeyOrOptions) this.client = 'client' in options ? options.client : createClient(options) - this.defaults = { - waitForActionAttempt, - } + this.defaults = limitToSeamHttpRequestOptions(options) } static fromClient( @@ -82,7 +83,9 @@ export class SeamHttpNoiseSensors { warnOnInsecureuserIdentifierKey(userIdentifierKey) const clientOptions = parseOptions({ ...options, publishableKey }) if (isSeamHttpOptionsWithClient(clientOptions)) { - throw new Error('Cannot pass a client when using fromPublishableKey') + throw new SeamHttpInvalidOptionsError( + 'The client option cannot be used with SeamHttp.fromPublishableKey', + ) } const client = createClient(clientOptions) const clientSessions = SeamHttpClientSessions.fromClient(client) diff --git a/src/lib/seam/connect/routes/thermostats-climate-setting-schedules.ts b/src/lib/seam/connect/routes/thermostats-climate-setting-schedules.ts index 2ac46a07..a5a2b9db 100644 --- a/src/lib/seam/connect/routes/thermostats-climate-setting-schedules.ts +++ b/src/lib/seam/connect/routes/thermostats-climate-setting-schedules.ts @@ -24,7 +24,10 @@ import { type SeamHttpOptionsWithPersonalAccessToken, type SeamHttpRequestOptions, } from 'lib/seam/connect/options.js' -import { parseOptions } from 'lib/seam/connect/parse-options.js' +import { + limitToSeamHttpRequestOptions, + parseOptions, +} from 'lib/seam/connect/parse-options.js' import { SeamHttpClientSessions } from './client-sessions.js' @@ -33,11 +36,9 @@ export class SeamHttpThermostatsClimateSettingSchedules { readonly defaults: Required constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) { - const { waitForActionAttempt, ...options } = parseOptions(apiKeyOrOptions) + const options = parseOptions(apiKeyOrOptions) this.client = 'client' in options ? options.client : createClient(options) - this.defaults = { - waitForActionAttempt, - } + this.defaults = limitToSeamHttpRequestOptions(options) } static fromClient( @@ -84,7 +85,9 @@ export class SeamHttpThermostatsClimateSettingSchedules { warnOnInsecureuserIdentifierKey(userIdentifierKey) const clientOptions = parseOptions({ ...options, publishableKey }) if (isSeamHttpOptionsWithClient(clientOptions)) { - throw new Error('Cannot pass a client when using fromPublishableKey') + throw new SeamHttpInvalidOptionsError( + 'The client option cannot be used with SeamHttp.fromPublishableKey', + ) } const client = createClient(clientOptions) const clientSessions = SeamHttpClientSessions.fromClient(client) diff --git a/src/lib/seam/connect/routes/thermostats.ts b/src/lib/seam/connect/routes/thermostats.ts index 91f00a3c..d50abf33 100644 --- a/src/lib/seam/connect/routes/thermostats.ts +++ b/src/lib/seam/connect/routes/thermostats.ts @@ -24,7 +24,10 @@ import { type SeamHttpOptionsWithPersonalAccessToken, type SeamHttpRequestOptions, } from 'lib/seam/connect/options.js' -import { parseOptions } from 'lib/seam/connect/parse-options.js' +import { + limitToSeamHttpRequestOptions, + parseOptions, +} from 'lib/seam/connect/parse-options.js' import { SeamHttpClientSessions } from './client-sessions.js' import { SeamHttpThermostatsClimateSettingSchedules } from './thermostats-climate-setting-schedules.js' @@ -34,11 +37,9 @@ export class SeamHttpThermostats { readonly defaults: Required constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) { - const { waitForActionAttempt, ...options } = parseOptions(apiKeyOrOptions) + const options = parseOptions(apiKeyOrOptions) this.client = 'client' in options ? options.client : createClient(options) - this.defaults = { - waitForActionAttempt, - } + this.defaults = limitToSeamHttpRequestOptions(options) } static fromClient( @@ -85,7 +86,9 @@ export class SeamHttpThermostats { warnOnInsecureuserIdentifierKey(userIdentifierKey) const clientOptions = parseOptions({ ...options, publishableKey }) if (isSeamHttpOptionsWithClient(clientOptions)) { - throw new Error('Cannot pass a client when using fromPublishableKey') + throw new SeamHttpInvalidOptionsError( + 'The client option cannot be used with SeamHttp.fromPublishableKey', + ) } const client = createClient(clientOptions) const clientSessions = SeamHttpClientSessions.fromClient(client) diff --git a/src/lib/seam/connect/routes/user-identities.ts b/src/lib/seam/connect/routes/user-identities.ts index 26863406..da272feb 100644 --- a/src/lib/seam/connect/routes/user-identities.ts +++ b/src/lib/seam/connect/routes/user-identities.ts @@ -24,7 +24,10 @@ import { type SeamHttpOptionsWithPersonalAccessToken, type SeamHttpRequestOptions, } from 'lib/seam/connect/options.js' -import { parseOptions } from 'lib/seam/connect/parse-options.js' +import { + limitToSeamHttpRequestOptions, + parseOptions, +} from 'lib/seam/connect/parse-options.js' import { SeamHttpClientSessions } from './client-sessions.js' @@ -33,11 +36,9 @@ export class SeamHttpUserIdentities { readonly defaults: Required constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) { - const { waitForActionAttempt, ...options } = parseOptions(apiKeyOrOptions) + const options = parseOptions(apiKeyOrOptions) this.client = 'client' in options ? options.client : createClient(options) - this.defaults = { - waitForActionAttempt, - } + this.defaults = limitToSeamHttpRequestOptions(options) } static fromClient( @@ -84,7 +85,9 @@ export class SeamHttpUserIdentities { warnOnInsecureuserIdentifierKey(userIdentifierKey) const clientOptions = parseOptions({ ...options, publishableKey }) if (isSeamHttpOptionsWithClient(clientOptions)) { - throw new Error('Cannot pass a client when using fromPublishableKey') + throw new SeamHttpInvalidOptionsError( + 'The client option cannot be used with SeamHttp.fromPublishableKey', + ) } const client = createClient(clientOptions) const clientSessions = SeamHttpClientSessions.fromClient(client) diff --git a/src/lib/seam/connect/routes/webhooks.ts b/src/lib/seam/connect/routes/webhooks.ts index caf4dd9c..c7850bc3 100644 --- a/src/lib/seam/connect/routes/webhooks.ts +++ b/src/lib/seam/connect/routes/webhooks.ts @@ -28,7 +28,10 @@ import { type SeamHttpOptionsWithPersonalAccessToken, type SeamHttpRequestOptions, } from 'lib/seam/connect/options.js' -import { parseOptions } from 'lib/seam/connect/parse-options.js' +import { + limitToSeamHttpRequestOptions, + parseOptions, +} from 'lib/seam/connect/parse-options.js' import { SeamHttpClientSessions } from './client-sessions.js' @@ -37,11 +40,9 @@ export class SeamHttpWebhooks { readonly defaults: Required constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) { - const { waitForActionAttempt, ...options } = parseOptions(apiKeyOrOptions) + const options = parseOptions(apiKeyOrOptions) this.client = 'client' in options ? options.client : createClient(options) - this.defaults = { - waitForActionAttempt, - } + this.defaults = limitToSeamHttpRequestOptions(options) } static fromClient( @@ -88,7 +89,9 @@ export class SeamHttpWebhooks { warnOnInsecureuserIdentifierKey(userIdentifierKey) const clientOptions = parseOptions({ ...options, publishableKey }) if (isSeamHttpOptionsWithClient(clientOptions)) { - throw new Error('Cannot pass a client when using fromPublishableKey') + throw new SeamHttpInvalidOptionsError( + 'The client option cannot be used with SeamHttp.fromPublishableKey', + ) } const client = createClient(clientOptions) const clientSessions = SeamHttpClientSessions.fromClient(client) diff --git a/src/lib/seam/connect/routes/workspaces.ts b/src/lib/seam/connect/routes/workspaces.ts index a2febe09..6a48b806 100644 --- a/src/lib/seam/connect/routes/workspaces.ts +++ b/src/lib/seam/connect/routes/workspaces.ts @@ -28,7 +28,10 @@ import { type SeamHttpOptionsWithPersonalAccessToken, type SeamHttpRequestOptions, } from 'lib/seam/connect/options.js' -import { parseOptions } from 'lib/seam/connect/parse-options.js' +import { + limitToSeamHttpRequestOptions, + parseOptions, +} from 'lib/seam/connect/parse-options.js' import { SeamHttpClientSessions } from './client-sessions.js' @@ -37,11 +40,9 @@ export class SeamHttpWorkspaces { readonly defaults: Required constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) { - const { waitForActionAttempt, ...options } = parseOptions(apiKeyOrOptions) + const options = parseOptions(apiKeyOrOptions) this.client = 'client' in options ? options.client : createClient(options) - this.defaults = { - waitForActionAttempt, - } + this.defaults = limitToSeamHttpRequestOptions(options) } static fromClient( @@ -88,7 +89,9 @@ export class SeamHttpWorkspaces { warnOnInsecureuserIdentifierKey(userIdentifierKey) const clientOptions = parseOptions({ ...options, publishableKey }) if (isSeamHttpOptionsWithClient(clientOptions)) { - throw new Error('Cannot pass a client when using fromPublishableKey') + throw new SeamHttpInvalidOptionsError( + 'The client option cannot be used with SeamHttp.fromPublishableKey', + ) } const client = createClient(clientOptions) const clientSessions = SeamHttpClientSessions.fromClient(client) diff --git a/src/lib/seam/connect/seam-http-multi-workspace.ts b/src/lib/seam/connect/seam-http-multi-workspace.ts index 69d51af0..c4e65abe 100644 --- a/src/lib/seam/connect/seam-http-multi-workspace.ts +++ b/src/lib/seam/connect/seam-http-multi-workspace.ts @@ -10,7 +10,7 @@ import { type SeamHttpMultiWorkspaceOptionsWithPersonalAccessToken, type SeamHttpRequestOptions, } from './options.js' -import { parseOptions } from './parse-options.js' +import { limitToSeamHttpRequestOptions, parseOptions } from './parse-options.js' import { SeamHttpWorkspaces } from './routes/index.js' export class SeamHttpMultiWorkspace { @@ -18,11 +18,9 @@ export class SeamHttpMultiWorkspace { readonly defaults: Required constructor(options: SeamHttpMultiWorkspaceOptions) { - const { waitForActionAttempt, ...opts } = parseOptions(options) + const opts = parseOptions(options) this.client = 'client' in opts ? opts.client : createClient(opts) - this.defaults = { - waitForActionAttempt, - } + this.defaults = limitToSeamHttpRequestOptions(opts) } static fromClient( diff --git a/src/lib/seam/connect/seam-http.ts b/src/lib/seam/connect/seam-http.ts index 5bd1353a..7e0bcb37 100644 --- a/src/lib/seam/connect/seam-http.ts +++ b/src/lib/seam/connect/seam-http.ts @@ -16,7 +16,7 @@ import { type SeamHttpOptionsWithPersonalAccessToken, type SeamHttpRequestOptions, } from './options.js' -import { parseOptions } from './parse-options.js' +import { limitToSeamHttpRequestOptions, parseOptions } from './parse-options.js' import { SeamHttpAccessCodes, SeamHttpAcs, @@ -39,11 +39,9 @@ export class SeamHttp { readonly defaults: Required constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) { - const { waitForActionAttempt, ...options } = parseOptions(apiKeyOrOptions) + const options = parseOptions(apiKeyOrOptions) this.client = 'client' in options ? options.client : createClient(options) - this.defaults = { - waitForActionAttempt, - } + this.defaults = limitToSeamHttpRequestOptions(options) } static fromClient(