From 1b3d8882c33c0a432bac835bb211894bde410c2b Mon Sep 17 00:00:00 2001 From: Evan Sosenko Date: Mon, 25 Sep 2023 19:44:20 -0700 Subject: [PATCH] Handle isSeamHttpOptionsWithClient in createAxiosClient --- src/lib/seam/connect/axios.ts | 2 ++ src/lib/seam/connect/client.ts | 3 +-- src/lib/seam/connect/routes/access-codes-unmanaged.ts | 3 +-- src/lib/seam/connect/routes/access-codes.ts | 3 +-- src/lib/seam/connect/routes/acs-access-groups.ts | 3 +-- src/lib/seam/connect/routes/acs-credentials.ts | 3 +-- src/lib/seam/connect/routes/acs-systems.ts | 3 +-- src/lib/seam/connect/routes/acs-users.ts | 3 +-- src/lib/seam/connect/routes/action-attempts.ts | 3 +-- src/lib/seam/connect/routes/client-sessions.ts | 3 +-- src/lib/seam/connect/routes/connect-webviews.ts | 3 +-- src/lib/seam/connect/routes/connected-accounts.ts | 3 +-- src/lib/seam/connect/routes/devices-unmanaged.ts | 3 +-- src/lib/seam/connect/routes/devices.ts | 3 +-- src/lib/seam/connect/routes/events.ts | 3 +-- src/lib/seam/connect/routes/locks.ts | 3 +-- src/lib/seam/connect/routes/noise-sensors-noise-thresholds.ts | 3 +-- .../connect/routes/thermostats-climate-setting-schedules.ts | 3 +-- src/lib/seam/connect/routes/thermostats.ts | 3 +-- src/lib/seam/connect/routes/webhooks.ts | 3 +-- src/lib/seam/connect/routes/workspaces.ts | 3 +-- 21 files changed, 22 insertions(+), 40 deletions(-) diff --git a/src/lib/seam/connect/axios.ts b/src/lib/seam/connect/axios.ts index d55336c0..0aade7de 100644 --- a/src/lib/seam/connect/axios.ts +++ b/src/lib/seam/connect/axios.ts @@ -2,6 +2,7 @@ import axios, { type Axios } from 'axios' import { getAuthHeaders } from './auth.js' import { + isSeamHttpOptionsWithClient, isSeamHttpOptionsWithClientSessionToken, type SeamHttpOptions, } from './client-options.js' @@ -9,6 +10,7 @@ import { export const createAxiosClient = ( options: Required, ): Axios => { + if (isSeamHttpOptionsWithClient(options)) return options.client // TODO: axiosRetry? Allow options to configure this if so return axios.create({ baseURL: options.endpoint, diff --git a/src/lib/seam/connect/client.ts b/src/lib/seam/connect/client.ts index eae1e73b..6da57055 100644 --- a/src/lib/seam/connect/client.ts +++ b/src/lib/seam/connect/client.ts @@ -23,8 +23,7 @@ export class SeamHttp { constructor(apiKeyOrOptions: string | SeamHttpOptions) { const options = parseOptions(apiKeyOrOptions) this.#legacy = options.enableLegacyMethodBehaivor - const client = 'client' in options ? options.client : null - this.client = client ?? createAxiosClient(options) + this.client = createAxiosClient(options) } static fromClient( diff --git a/src/lib/seam/connect/routes/access-codes-unmanaged.ts b/src/lib/seam/connect/routes/access-codes-unmanaged.ts index 27e0843a..61a282f7 100644 --- a/src/lib/seam/connect/routes/access-codes-unmanaged.ts +++ b/src/lib/seam/connect/routes/access-codes-unmanaged.ts @@ -23,8 +23,7 @@ export class SeamHttpAccessCodesUnmanaged { constructor(apiKeyOrOptions: string | SeamHttpOptions) { const options = parseOptions(apiKeyOrOptions) - const client = 'client' in options ? options.client : null - this.client = client ?? createAxiosClient(options) + this.client = createAxiosClient(options) } static fromClient( diff --git a/src/lib/seam/connect/routes/access-codes.ts b/src/lib/seam/connect/routes/access-codes.ts index c304e02f..ce349c06 100644 --- a/src/lib/seam/connect/routes/access-codes.ts +++ b/src/lib/seam/connect/routes/access-codes.ts @@ -23,8 +23,7 @@ export class SeamHttpAccessCodes { constructor(apiKeyOrOptions: string | SeamHttpOptions) { const options = parseOptions(apiKeyOrOptions) - const client = 'client' in options ? options.client : null - this.client = client ?? createAxiosClient(options) + this.client = createAxiosClient(options) } static fromClient( diff --git a/src/lib/seam/connect/routes/acs-access-groups.ts b/src/lib/seam/connect/routes/acs-access-groups.ts index b15001db..3dd14945 100644 --- a/src/lib/seam/connect/routes/acs-access-groups.ts +++ b/src/lib/seam/connect/routes/acs-access-groups.ts @@ -23,8 +23,7 @@ export class SeamHttpAcsAccessGroups { constructor(apiKeyOrOptions: string | SeamHttpOptions) { const options = parseOptions(apiKeyOrOptions) - const client = 'client' in options ? options.client : null - this.client = client ?? createAxiosClient(options) + this.client = createAxiosClient(options) } static fromClient( diff --git a/src/lib/seam/connect/routes/acs-credentials.ts b/src/lib/seam/connect/routes/acs-credentials.ts index 5a0b2d9a..2e7d641e 100644 --- a/src/lib/seam/connect/routes/acs-credentials.ts +++ b/src/lib/seam/connect/routes/acs-credentials.ts @@ -23,8 +23,7 @@ export class SeamHttpAcsCredentials { constructor(apiKeyOrOptions: string | SeamHttpOptions) { const options = parseOptions(apiKeyOrOptions) - const client = 'client' in options ? options.client : null - this.client = client ?? createAxiosClient(options) + this.client = createAxiosClient(options) } static fromClient( diff --git a/src/lib/seam/connect/routes/acs-systems.ts b/src/lib/seam/connect/routes/acs-systems.ts index 80a1ea37..56aa8c6e 100644 --- a/src/lib/seam/connect/routes/acs-systems.ts +++ b/src/lib/seam/connect/routes/acs-systems.ts @@ -23,8 +23,7 @@ export class SeamHttpAcsSystems { constructor(apiKeyOrOptions: string | SeamHttpOptions) { const options = parseOptions(apiKeyOrOptions) - const client = 'client' in options ? options.client : null - this.client = client ?? createAxiosClient(options) + this.client = createAxiosClient(options) } static fromClient( diff --git a/src/lib/seam/connect/routes/acs-users.ts b/src/lib/seam/connect/routes/acs-users.ts index f1f9d16f..167c14e7 100644 --- a/src/lib/seam/connect/routes/acs-users.ts +++ b/src/lib/seam/connect/routes/acs-users.ts @@ -23,8 +23,7 @@ export class SeamHttpAcsUsers { constructor(apiKeyOrOptions: string | SeamHttpOptions) { const options = parseOptions(apiKeyOrOptions) - const client = 'client' in options ? options.client : null - this.client = client ?? createAxiosClient(options) + this.client = createAxiosClient(options) } static fromClient( diff --git a/src/lib/seam/connect/routes/action-attempts.ts b/src/lib/seam/connect/routes/action-attempts.ts index b6030d8f..762fd179 100644 --- a/src/lib/seam/connect/routes/action-attempts.ts +++ b/src/lib/seam/connect/routes/action-attempts.ts @@ -23,8 +23,7 @@ export class SeamHttpActionAttempts { constructor(apiKeyOrOptions: string | SeamHttpOptions) { const options = parseOptions(apiKeyOrOptions) - const client = 'client' in options ? options.client : null - this.client = client ?? createAxiosClient(options) + this.client = createAxiosClient(options) } static fromClient( diff --git a/src/lib/seam/connect/routes/client-sessions.ts b/src/lib/seam/connect/routes/client-sessions.ts index 24d51d93..61a0e1e5 100644 --- a/src/lib/seam/connect/routes/client-sessions.ts +++ b/src/lib/seam/connect/routes/client-sessions.ts @@ -23,8 +23,7 @@ export class SeamHttpClientSessions { constructor(apiKeyOrOptions: string | SeamHttpOptions) { const options = parseOptions(apiKeyOrOptions) - const client = 'client' in options ? options.client : null - this.client = client ?? createAxiosClient(options) + this.client = createAxiosClient(options) } static fromClient( diff --git a/src/lib/seam/connect/routes/connect-webviews.ts b/src/lib/seam/connect/routes/connect-webviews.ts index aa95883d..10754e0e 100644 --- a/src/lib/seam/connect/routes/connect-webviews.ts +++ b/src/lib/seam/connect/routes/connect-webviews.ts @@ -23,8 +23,7 @@ export class SeamHttpConnectWebviews { constructor(apiKeyOrOptions: string | SeamHttpOptions) { const options = parseOptions(apiKeyOrOptions) - const client = 'client' in options ? options.client : null - this.client = client ?? createAxiosClient(options) + this.client = createAxiosClient(options) } static fromClient( diff --git a/src/lib/seam/connect/routes/connected-accounts.ts b/src/lib/seam/connect/routes/connected-accounts.ts index 89ca497a..bbac66b0 100644 --- a/src/lib/seam/connect/routes/connected-accounts.ts +++ b/src/lib/seam/connect/routes/connected-accounts.ts @@ -23,8 +23,7 @@ export class SeamHttpConnectedAccounts { constructor(apiKeyOrOptions: string | SeamHttpOptions) { const options = parseOptions(apiKeyOrOptions) - const client = 'client' in options ? options.client : null - this.client = client ?? createAxiosClient(options) + this.client = createAxiosClient(options) } static fromClient( diff --git a/src/lib/seam/connect/routes/devices-unmanaged.ts b/src/lib/seam/connect/routes/devices-unmanaged.ts index 605bf15c..a342c3e9 100644 --- a/src/lib/seam/connect/routes/devices-unmanaged.ts +++ b/src/lib/seam/connect/routes/devices-unmanaged.ts @@ -23,8 +23,7 @@ export class SeamHttpDevicesUnmanaged { constructor(apiKeyOrOptions: string | SeamHttpOptions) { const options = parseOptions(apiKeyOrOptions) - const client = 'client' in options ? options.client : null - this.client = client ?? createAxiosClient(options) + this.client = createAxiosClient(options) } static fromClient( diff --git a/src/lib/seam/connect/routes/devices.ts b/src/lib/seam/connect/routes/devices.ts index 6c519485..4aa2d11f 100644 --- a/src/lib/seam/connect/routes/devices.ts +++ b/src/lib/seam/connect/routes/devices.ts @@ -23,8 +23,7 @@ export class SeamHttpDevices { constructor(apiKeyOrOptions: string | SeamHttpOptions) { const options = parseOptions(apiKeyOrOptions) - const client = 'client' in options ? options.client : null - this.client = client ?? createAxiosClient(options) + this.client = createAxiosClient(options) } static fromClient( diff --git a/src/lib/seam/connect/routes/events.ts b/src/lib/seam/connect/routes/events.ts index 9488b605..bac05e86 100644 --- a/src/lib/seam/connect/routes/events.ts +++ b/src/lib/seam/connect/routes/events.ts @@ -23,8 +23,7 @@ export class SeamHttpEvents { constructor(apiKeyOrOptions: string | SeamHttpOptions) { const options = parseOptions(apiKeyOrOptions) - const client = 'client' in options ? options.client : null - this.client = client ?? createAxiosClient(options) + this.client = createAxiosClient(options) } static fromClient( diff --git a/src/lib/seam/connect/routes/locks.ts b/src/lib/seam/connect/routes/locks.ts index 9a850c55..7caf44e9 100644 --- a/src/lib/seam/connect/routes/locks.ts +++ b/src/lib/seam/connect/routes/locks.ts @@ -23,8 +23,7 @@ export class SeamHttpLocks { constructor(apiKeyOrOptions: string | SeamHttpOptions) { const options = parseOptions(apiKeyOrOptions) - const client = 'client' in options ? options.client : null - this.client = client ?? createAxiosClient(options) + this.client = createAxiosClient(options) } static fromClient( 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 42abdead..c52f9b32 100644 --- a/src/lib/seam/connect/routes/noise-sensors-noise-thresholds.ts +++ b/src/lib/seam/connect/routes/noise-sensors-noise-thresholds.ts @@ -23,8 +23,7 @@ export class SeamHttpNoiseSensorsNoiseThresholds { constructor(apiKeyOrOptions: string | SeamHttpOptions) { const options = parseOptions(apiKeyOrOptions) - const client = 'client' in options ? options.client : null - this.client = client ?? createAxiosClient(options) + this.client = createAxiosClient(options) } static fromClient( 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 6cf04cde..cac92c67 100644 --- a/src/lib/seam/connect/routes/thermostats-climate-setting-schedules.ts +++ b/src/lib/seam/connect/routes/thermostats-climate-setting-schedules.ts @@ -23,8 +23,7 @@ export class SeamHttpThermostatsClimateSettingSchedules { constructor(apiKeyOrOptions: string | SeamHttpOptions) { const options = parseOptions(apiKeyOrOptions) - const client = 'client' in options ? options.client : null - this.client = client ?? createAxiosClient(options) + this.client = createAxiosClient(options) } static fromClient( diff --git a/src/lib/seam/connect/routes/thermostats.ts b/src/lib/seam/connect/routes/thermostats.ts index f06b418c..8bddc308 100644 --- a/src/lib/seam/connect/routes/thermostats.ts +++ b/src/lib/seam/connect/routes/thermostats.ts @@ -23,8 +23,7 @@ export class SeamHttpThermostats { constructor(apiKeyOrOptions: string | SeamHttpOptions) { const options = parseOptions(apiKeyOrOptions) - const client = 'client' in options ? options.client : null - this.client = client ?? createAxiosClient(options) + this.client = createAxiosClient(options) } static fromClient( diff --git a/src/lib/seam/connect/routes/webhooks.ts b/src/lib/seam/connect/routes/webhooks.ts index a870bd80..a25ec030 100644 --- a/src/lib/seam/connect/routes/webhooks.ts +++ b/src/lib/seam/connect/routes/webhooks.ts @@ -23,8 +23,7 @@ export class SeamHttpWebhooks { constructor(apiKeyOrOptions: string | SeamHttpOptions) { const options = parseOptions(apiKeyOrOptions) - const client = 'client' in options ? options.client : null - this.client = client ?? createAxiosClient(options) + this.client = createAxiosClient(options) } static fromClient( diff --git a/src/lib/seam/connect/routes/workspaces.ts b/src/lib/seam/connect/routes/workspaces.ts index c6bd1318..4496926a 100644 --- a/src/lib/seam/connect/routes/workspaces.ts +++ b/src/lib/seam/connect/routes/workspaces.ts @@ -23,8 +23,7 @@ export class SeamHttpWorkspaces { constructor(apiKeyOrOptions: string | SeamHttpOptions) { const options = parseOptions(apiKeyOrOptions) - const client = 'client' in options ? options.client : null - this.client = client ?? createAxiosClient(options) + this.client = createAxiosClient(options) } static fromClient(