From 77cddf730e3e47aafaaa1b71c3016ca6a5df9896 Mon Sep 17 00:00:00 2001 From: Evan Sosenko Date: Wed, 10 Jan 2024 15:06:33 -0800 Subject: [PATCH 1/3] feat: Add enrollmentAutomations and phones --- generate-routes.ts | 6 +- src/lib/seam/connect/routes/index.ts | 2 + src/lib/seam/connect/routes/network.ts | 169 ++++++++++++++ src/lib/seam/connect/routes/phones.ts | 151 ++++++++++++ .../user-identities-enrollment-automations.ts | 214 ++++++++++++++++++ .../seam/connect/routes/user-identities.ts | 8 + src/lib/seam/connect/seam-http.ts | 5 + 7 files changed, 554 insertions(+), 1 deletion(-) create mode 100644 src/lib/seam/connect/routes/network.ts create mode 100644 src/lib/seam/connect/routes/phones.ts create mode 100644 src/lib/seam/connect/routes/user-identities-enrollment-automations.ts diff --git a/generate-routes.ts b/generate-routes.ts index 25f1a516..b230b376 100644 --- a/generate-routes.ts +++ b/generate-routes.ts @@ -30,9 +30,11 @@ const routePaths = [ '/locks', '/noise_sensors', '/noise_sensors/noise_thresholds', - '/thermostats/climate_setting_schedules', + '/phones', '/thermostats', + '/thermostats/climate_setting_schedules', '/user_identities', + '/user_identities/enrollment_automations', '/webhooks', '/workspaces', ] as const @@ -53,6 +55,7 @@ const routePathSubresources: Partial< '/devices': ['unmanaged'], '/noise_sensors': ['noise_thresholds'], '/thermostats': ['climate_setting_schedules'], + '/user_identities': ['enrollment_automations'], } const ignoredEndpointPaths = [ @@ -63,6 +66,7 @@ const ignoredEndpointPaths = [ '/health/get_service_health', '/health/service/[service_name]', '/noise_sensors/simulate/trigger_noise_threshold', + '/phones/simulate/create_sandbox_phone', ] as const const endpointResources: Partial> = { diff --git a/src/lib/seam/connect/routes/index.ts b/src/lib/seam/connect/routes/index.ts index fcbb8d2c..1ec83dd5 100644 --- a/src/lib/seam/connect/routes/index.ts +++ b/src/lib/seam/connect/routes/index.ts @@ -18,8 +18,10 @@ export * from './events.js' export * from './locks.js' export * from './noise-sensors.js' export * from './noise-sensors-noise-thresholds.js' +export * from './phones.js' export * from './thermostats.js' export * from './thermostats-climate-setting-schedules.js' export * from './user-identities.js' +export * from './user-identities-enrollment-automations.js' export * from './webhooks.js' export * from './workspaces.js' diff --git a/src/lib/seam/connect/routes/network.ts b/src/lib/seam/connect/routes/network.ts new file mode 100644 index 00000000..6372a33f --- /dev/null +++ b/src/lib/seam/connect/routes/network.ts @@ -0,0 +1,169 @@ +/* + * 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 { 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 SeamHttpNetwork { + 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 = {}, + ): SeamHttpNetwork { + const constructorOptions = { ...options, client } + if (!isSeamHttpOptionsWithClient(constructorOptions)) { + throw new SeamHttpInvalidOptionsError('Missing client') + } + return new SeamHttpNetwork(constructorOptions) + } + + static fromApiKey( + apiKey: SeamHttpOptionsWithApiKey['apiKey'], + options: Omit = {}, + ): SeamHttpNetwork { + const constructorOptions = { ...options, apiKey } + if (!isSeamHttpOptionsWithApiKey(constructorOptions)) { + throw new SeamHttpInvalidOptionsError('Missing apiKey') + } + return new SeamHttpNetwork(constructorOptions) + } + + static fromClientSessionToken( + clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'], + options: Omit< + SeamHttpOptionsWithClientSessionToken, + 'clientSessionToken' + > = {}, + ): SeamHttpNetwork { + const constructorOptions = { ...options, clientSessionToken } + if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) { + throw new SeamHttpInvalidOptionsError('Missing clientSessionToken') + } + return new SeamHttpNetwork(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 SeamHttpNetwork.fromClientSessionToken(token, options) + } + + static fromConsoleSessionToken( + consoleSessionToken: SeamHttpOptionsWithConsoleSessionToken['consoleSessionToken'], + workspaceId: SeamHttpOptionsWithConsoleSessionToken['workspaceId'], + options: Omit< + SeamHttpOptionsWithConsoleSessionToken, + 'consoleSessionToken' | 'workspaceId' + > = {}, + ): SeamHttpNetwork { + const constructorOptions = { ...options, consoleSessionToken, workspaceId } + if (!isSeamHttpOptionsWithConsoleSessionToken(constructorOptions)) { + throw new SeamHttpInvalidOptionsError( + 'Missing consoleSessionToken or workspaceId', + ) + } + return new SeamHttpNetwork(constructorOptions) + } + + static fromPersonalAccessToken( + personalAccessToken: SeamHttpOptionsWithPersonalAccessToken['personalAccessToken'], + workspaceId: SeamHttpOptionsWithPersonalAccessToken['workspaceId'], + options: Omit< + SeamHttpOptionsWithPersonalAccessToken, + 'personalAccessToken' | 'workspaceId' + > = {}, + ): SeamHttpNetwork { + const constructorOptions = { ...options, personalAccessToken, workspaceId } + if (!isSeamHttpOptionsWithPersonalAccessToken(constructorOptions)) { + throw new SeamHttpInvalidOptionsError( + 'Missing personalAccessToken or workspaceId', + ) + } + return new SeamHttpNetwork(constructorOptions) + } + + async get(body?: NetworkGetBody): Promise { + const { data } = await this.client.request({ + url: '/networks/get', + method: 'post', + data: body, + }) + + return data.network + } + + async list(body?: NetworkListBody): Promise { + const { data } = await this.client.request({ + url: '/networks/list', + method: 'post', + data: body, + }) + + return data.networks + } +} + +export type NetworkGetBody = RouteRequestBody<'/networks/get'> + +export type NetworkGetResponse = SetNonNullable< + Required> +> + +export type NetworkGetOptions = never + +export type NetworkListBody = RouteRequestBody<'/networks/list'> + +export type NetworkListResponse = SetNonNullable< + Required> +> + +export type NetworkListOptions = never diff --git a/src/lib/seam/connect/routes/phones.ts b/src/lib/seam/connect/routes/phones.ts new file mode 100644 index 00000000..feeedb6b --- /dev/null +++ b/src/lib/seam/connect/routes/phones.ts @@ -0,0 +1,151 @@ +/* + * 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 { 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 SeamHttpPhones { + 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 = {}, + ): SeamHttpPhones { + const constructorOptions = { ...options, client } + if (!isSeamHttpOptionsWithClient(constructorOptions)) { + throw new SeamHttpInvalidOptionsError('Missing client') + } + return new SeamHttpPhones(constructorOptions) + } + + static fromApiKey( + apiKey: SeamHttpOptionsWithApiKey['apiKey'], + options: Omit = {}, + ): SeamHttpPhones { + const constructorOptions = { ...options, apiKey } + if (!isSeamHttpOptionsWithApiKey(constructorOptions)) { + throw new SeamHttpInvalidOptionsError('Missing apiKey') + } + return new SeamHttpPhones(constructorOptions) + } + + static fromClientSessionToken( + clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'], + options: Omit< + SeamHttpOptionsWithClientSessionToken, + 'clientSessionToken' + > = {}, + ): SeamHttpPhones { + const constructorOptions = { ...options, clientSessionToken } + if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) { + throw new SeamHttpInvalidOptionsError('Missing clientSessionToken') + } + return new SeamHttpPhones(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 SeamHttpPhones.fromClientSessionToken(token, options) + } + + static fromConsoleSessionToken( + consoleSessionToken: SeamHttpOptionsWithConsoleSessionToken['consoleSessionToken'], + workspaceId: SeamHttpOptionsWithConsoleSessionToken['workspaceId'], + options: Omit< + SeamHttpOptionsWithConsoleSessionToken, + 'consoleSessionToken' | 'workspaceId' + > = {}, + ): SeamHttpPhones { + const constructorOptions = { ...options, consoleSessionToken, workspaceId } + if (!isSeamHttpOptionsWithConsoleSessionToken(constructorOptions)) { + throw new SeamHttpInvalidOptionsError( + 'Missing consoleSessionToken or workspaceId', + ) + } + return new SeamHttpPhones(constructorOptions) + } + + static fromPersonalAccessToken( + personalAccessToken: SeamHttpOptionsWithPersonalAccessToken['personalAccessToken'], + workspaceId: SeamHttpOptionsWithPersonalAccessToken['workspaceId'], + options: Omit< + SeamHttpOptionsWithPersonalAccessToken, + 'personalAccessToken' | 'workspaceId' + > = {}, + ): SeamHttpPhones { + const constructorOptions = { ...options, personalAccessToken, workspaceId } + if (!isSeamHttpOptionsWithPersonalAccessToken(constructorOptions)) { + throw new SeamHttpInvalidOptionsError( + 'Missing personalAccessToken or workspaceId', + ) + } + return new SeamHttpPhones(constructorOptions) + } + + async list(body?: PhonesListParams): Promise { + const { data } = await this.client.request({ + url: '/phones/list', + method: 'post', + data: body, + }) + + return data.phones + } +} + +export type PhonesListParams = RouteRequestBody<'/phones/list'> + +export type PhonesListResponse = SetNonNullable< + Required> +> + +export type PhonesListOptions = never diff --git a/src/lib/seam/connect/routes/user-identities-enrollment-automations.ts b/src/lib/seam/connect/routes/user-identities-enrollment-automations.ts new file mode 100644 index 00000000..e4cbfac8 --- /dev/null +++ b/src/lib/seam/connect/routes/user-identities-enrollment-automations.ts @@ -0,0 +1,214 @@ +/* + * 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 { 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 SeamHttpUserIdentitiesEnrollmentAutomations { + 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 = {}, + ): SeamHttpUserIdentitiesEnrollmentAutomations { + const constructorOptions = { ...options, client } + if (!isSeamHttpOptionsWithClient(constructorOptions)) { + throw new SeamHttpInvalidOptionsError('Missing client') + } + return new SeamHttpUserIdentitiesEnrollmentAutomations(constructorOptions) + } + + static fromApiKey( + apiKey: SeamHttpOptionsWithApiKey['apiKey'], + options: Omit = {}, + ): SeamHttpUserIdentitiesEnrollmentAutomations { + const constructorOptions = { ...options, apiKey } + if (!isSeamHttpOptionsWithApiKey(constructorOptions)) { + throw new SeamHttpInvalidOptionsError('Missing apiKey') + } + return new SeamHttpUserIdentitiesEnrollmentAutomations(constructorOptions) + } + + static fromClientSessionToken( + clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'], + options: Omit< + SeamHttpOptionsWithClientSessionToken, + 'clientSessionToken' + > = {}, + ): SeamHttpUserIdentitiesEnrollmentAutomations { + const constructorOptions = { ...options, clientSessionToken } + if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) { + throw new SeamHttpInvalidOptionsError('Missing clientSessionToken') + } + return new SeamHttpUserIdentitiesEnrollmentAutomations(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 SeamHttpUserIdentitiesEnrollmentAutomations.fromClientSessionToken( + token, + options, + ) + } + + static fromConsoleSessionToken( + consoleSessionToken: SeamHttpOptionsWithConsoleSessionToken['consoleSessionToken'], + workspaceId: SeamHttpOptionsWithConsoleSessionToken['workspaceId'], + options: Omit< + SeamHttpOptionsWithConsoleSessionToken, + 'consoleSessionToken' | 'workspaceId' + > = {}, + ): SeamHttpUserIdentitiesEnrollmentAutomations { + const constructorOptions = { ...options, consoleSessionToken, workspaceId } + if (!isSeamHttpOptionsWithConsoleSessionToken(constructorOptions)) { + throw new SeamHttpInvalidOptionsError( + 'Missing consoleSessionToken or workspaceId', + ) + } + return new SeamHttpUserIdentitiesEnrollmentAutomations(constructorOptions) + } + + static fromPersonalAccessToken( + personalAccessToken: SeamHttpOptionsWithPersonalAccessToken['personalAccessToken'], + workspaceId: SeamHttpOptionsWithPersonalAccessToken['workspaceId'], + options: Omit< + SeamHttpOptionsWithPersonalAccessToken, + 'personalAccessToken' | 'workspaceId' + > = {}, + ): SeamHttpUserIdentitiesEnrollmentAutomations { + const constructorOptions = { ...options, personalAccessToken, workspaceId } + if (!isSeamHttpOptionsWithPersonalAccessToken(constructorOptions)) { + throw new SeamHttpInvalidOptionsError( + 'Missing personalAccessToken or workspaceId', + ) + } + return new SeamHttpUserIdentitiesEnrollmentAutomations(constructorOptions) + } + + async get( + body?: UserIdentitiesEnrollmentAutomationsGetParams, + ): Promise< + UserIdentitiesEnrollmentAutomationsGetResponse['enrollment_automation'] + > { + const { data } = + await this.client.request( + { + url: '/user_identities/enrollment_automations/get', + method: 'post', + data: body, + }, + ) + + return data.enrollment_automation + } + + async launch( + body?: UserIdentitiesEnrollmentAutomationsLaunchBody, + ): Promise< + UserIdentitiesEnrollmentAutomationsLaunchResponse['enrollment_automation'] + > { + const { data } = + await this.client.request( + { + url: '/user_identities/enrollment_automations/launch', + method: 'post', + data: body, + }, + ) + + return data.enrollment_automation + } + + async list( + body?: UserIdentitiesEnrollmentAutomationsListParams, + ): Promise< + UserIdentitiesEnrollmentAutomationsListResponse['enrollment_automations'] + > { + const { data } = + await this.client.request( + { + url: '/user_identities/enrollment_automations/list', + method: 'post', + data: body, + }, + ) + + return data.enrollment_automations + } +} + +export type UserIdentitiesEnrollmentAutomationsGetParams = + RouteRequestBody<'/user_identities/enrollment_automations/get'> + +export type UserIdentitiesEnrollmentAutomationsGetResponse = SetNonNullable< + Required> +> + +export type UserIdentitiesEnrollmentAutomationsGetOptions = never + +export type UserIdentitiesEnrollmentAutomationsLaunchBody = + RouteRequestBody<'/user_identities/enrollment_automations/launch'> + +export type UserIdentitiesEnrollmentAutomationsLaunchResponse = SetNonNullable< + Required> +> + +export type UserIdentitiesEnrollmentAutomationsLaunchOptions = never + +export type UserIdentitiesEnrollmentAutomationsListParams = + RouteRequestBody<'/user_identities/enrollment_automations/list'> + +export type UserIdentitiesEnrollmentAutomationsListResponse = SetNonNullable< + Required> +> + +export type UserIdentitiesEnrollmentAutomationsListOptions = never diff --git a/src/lib/seam/connect/routes/user-identities.ts b/src/lib/seam/connect/routes/user-identities.ts index eabe0b6f..9a7b09dc 100644 --- a/src/lib/seam/connect/routes/user-identities.ts +++ b/src/lib/seam/connect/routes/user-identities.ts @@ -34,6 +34,7 @@ import { } from 'lib/seam/connect/parse-options.js' import { SeamHttpClientSessions } from './client-sessions.js' +import { SeamHttpUserIdentitiesEnrollmentAutomations } from './user-identities-enrollment-automations.js' export class SeamHttpUserIdentities { client: Client @@ -135,6 +136,13 @@ export class SeamHttpUserIdentities { return new SeamHttpUserIdentities(constructorOptions) } + get enrollmentAutomations(): SeamHttpUserIdentitiesEnrollmentAutomations { + return SeamHttpUserIdentitiesEnrollmentAutomations.fromClient( + this.client, + this.defaults, + ) + } + async addAcsUser(body?: UserIdentitiesAddAcsUserBody): Promise { await this.client.request({ url: '/user_identities/add_acs_user', diff --git a/src/lib/seam/connect/seam-http.ts b/src/lib/seam/connect/seam-http.ts index 897506eb..1855bbfa 100644 --- a/src/lib/seam/connect/seam-http.ts +++ b/src/lib/seam/connect/seam-http.ts @@ -28,6 +28,7 @@ import { SeamHttpEvents, SeamHttpLocks, SeamHttpNoiseSensors, + SeamHttpPhones, SeamHttpThermostats, SeamHttpUserIdentities, SeamHttpWebhooks, @@ -174,6 +175,10 @@ export class SeamHttp { return SeamHttpNoiseSensors.fromClient(this.client, this.defaults) } + get phones(): SeamHttpPhones { + return SeamHttpPhones.fromClient(this.client, this.defaults) + } + get thermostats(): SeamHttpThermostats { return SeamHttpThermostats.fromClient(this.client, this.defaults) } From 595560ae5769cf00ac3a22bdb55139f2aa4b515b Mon Sep 17 00:00:00 2001 From: Evan Sosenko Date: Wed, 10 Jan 2024 16:26:26 -0800 Subject: [PATCH 2/3] feat: Add networks --- generate-routes.ts | 1 + src/lib/seam/connect/routes/index.ts | 1 + .../routes/{network.ts => networks.ts} | 48 ++++++++++--------- src/lib/seam/connect/seam-http.ts | 5 ++ 4 files changed, 32 insertions(+), 23 deletions(-) rename src/lib/seam/connect/routes/{network.ts => networks.ts} (80%) diff --git a/generate-routes.ts b/generate-routes.ts index b230b376..25cc1160 100644 --- a/generate-routes.ts +++ b/generate-routes.ts @@ -28,6 +28,7 @@ const routePaths = [ '/devices/unmanaged', '/events', '/locks', + '/networks', '/noise_sensors', '/noise_sensors/noise_thresholds', '/phones', diff --git a/src/lib/seam/connect/routes/index.ts b/src/lib/seam/connect/routes/index.ts index 1ec83dd5..416f9192 100644 --- a/src/lib/seam/connect/routes/index.ts +++ b/src/lib/seam/connect/routes/index.ts @@ -16,6 +16,7 @@ export * from './devices.js' export * from './devices-unmanaged.js' export * from './events.js' export * from './locks.js' +export * from './networks.js' export * from './noise-sensors.js' export * from './noise-sensors-noise-thresholds.js' export * from './phones.js' diff --git a/src/lib/seam/connect/routes/network.ts b/src/lib/seam/connect/routes/networks.ts similarity index 80% rename from src/lib/seam/connect/routes/network.ts rename to src/lib/seam/connect/routes/networks.ts index 6372a33f..92160cb7 100644 --- a/src/lib/seam/connect/routes/network.ts +++ b/src/lib/seam/connect/routes/networks.ts @@ -31,7 +31,7 @@ import { import { SeamHttpClientSessions } from './client-sessions.js' -export class SeamHttpNetwork { +export class SeamHttpNetworks { client: Client readonly defaults: Required @@ -44,23 +44,23 @@ export class SeamHttpNetwork { static fromClient( client: SeamHttpOptionsWithClient['client'], options: Omit = {}, - ): SeamHttpNetwork { + ): SeamHttpNetworks { const constructorOptions = { ...options, client } if (!isSeamHttpOptionsWithClient(constructorOptions)) { throw new SeamHttpInvalidOptionsError('Missing client') } - return new SeamHttpNetwork(constructorOptions) + return new SeamHttpNetworks(constructorOptions) } static fromApiKey( apiKey: SeamHttpOptionsWithApiKey['apiKey'], options: Omit = {}, - ): SeamHttpNetwork { + ): SeamHttpNetworks { const constructorOptions = { ...options, apiKey } if (!isSeamHttpOptionsWithApiKey(constructorOptions)) { throw new SeamHttpInvalidOptionsError('Missing apiKey') } - return new SeamHttpNetwork(constructorOptions) + return new SeamHttpNetworks(constructorOptions) } static fromClientSessionToken( @@ -69,19 +69,19 @@ export class SeamHttpNetwork { SeamHttpOptionsWithClientSessionToken, 'clientSessionToken' > = {}, - ): SeamHttpNetwork { + ): SeamHttpNetworks { const constructorOptions = { ...options, clientSessionToken } if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) { throw new SeamHttpInvalidOptionsError('Missing clientSessionToken') } - return new SeamHttpNetwork(constructorOptions) + return new SeamHttpNetworks(constructorOptions) } static async fromPublishableKey( publishableKey: string, userIdentifierKey: string, options: SeamHttpFromPublishableKeyOptions = {}, - ): Promise { + ): Promise { warnOnInsecureuserIdentifierKey(userIdentifierKey) const clientOptions = parseOptions({ ...options, publishableKey }) if (isSeamHttpOptionsWithClient(clientOptions)) { @@ -94,7 +94,7 @@ export class SeamHttpNetwork { const { token } = await clientSessions.getOrCreate({ user_identifier_key: userIdentifierKey, }) - return SeamHttpNetwork.fromClientSessionToken(token, options) + return SeamHttpNetworks.fromClientSessionToken(token, options) } static fromConsoleSessionToken( @@ -104,14 +104,14 @@ export class SeamHttpNetwork { SeamHttpOptionsWithConsoleSessionToken, 'consoleSessionToken' | 'workspaceId' > = {}, - ): SeamHttpNetwork { + ): SeamHttpNetworks { const constructorOptions = { ...options, consoleSessionToken, workspaceId } if (!isSeamHttpOptionsWithConsoleSessionToken(constructorOptions)) { throw new SeamHttpInvalidOptionsError( 'Missing consoleSessionToken or workspaceId', ) } - return new SeamHttpNetwork(constructorOptions) + return new SeamHttpNetworks(constructorOptions) } static fromPersonalAccessToken( @@ -121,18 +121,18 @@ export class SeamHttpNetwork { SeamHttpOptionsWithPersonalAccessToken, 'personalAccessToken' | 'workspaceId' > = {}, - ): SeamHttpNetwork { + ): SeamHttpNetworks { const constructorOptions = { ...options, personalAccessToken, workspaceId } if (!isSeamHttpOptionsWithPersonalAccessToken(constructorOptions)) { throw new SeamHttpInvalidOptionsError( 'Missing personalAccessToken or workspaceId', ) } - return new SeamHttpNetwork(constructorOptions) + return new SeamHttpNetworks(constructorOptions) } - async get(body?: NetworkGetBody): Promise { - const { data } = await this.client.request({ + async get(body?: NetworksGetParams): Promise { + const { data } = await this.client.request({ url: '/networks/get', method: 'post', data: body, @@ -141,8 +141,10 @@ export class SeamHttpNetwork { return data.network } - async list(body?: NetworkListBody): Promise { - const { data } = await this.client.request({ + async list( + body?: NetworksListParams, + ): Promise { + const { data } = await this.client.request({ url: '/networks/list', method: 'post', data: body, @@ -152,18 +154,18 @@ export class SeamHttpNetwork { } } -export type NetworkGetBody = RouteRequestBody<'/networks/get'> +export type NetworksGetParams = RouteRequestBody<'/networks/get'> -export type NetworkGetResponse = SetNonNullable< +export type NetworksGetResponse = SetNonNullable< Required> > -export type NetworkGetOptions = never +export type NetworksGetOptions = never -export type NetworkListBody = RouteRequestBody<'/networks/list'> +export type NetworksListParams = RouteRequestBody<'/networks/list'> -export type NetworkListResponse = SetNonNullable< +export type NetworksListResponse = SetNonNullable< Required> > -export type NetworkListOptions = never +export type NetworksListOptions = never diff --git a/src/lib/seam/connect/seam-http.ts b/src/lib/seam/connect/seam-http.ts index 1855bbfa..31c2a42d 100644 --- a/src/lib/seam/connect/seam-http.ts +++ b/src/lib/seam/connect/seam-http.ts @@ -18,6 +18,7 @@ import { } from './options.js' import { limitToSeamHttpRequestOptions, parseOptions } from './parse-options.js' import { + SeamHttpNetworks, SeamHttpAccessCodes, SeamHttpAcs, SeamHttpActionAttempts, @@ -171,6 +172,10 @@ export class SeamHttp { return SeamHttpLocks.fromClient(this.client, this.defaults) } + get networks(): SeamHttpNetworks { + return SeamHttpNetworks.fromClient(this.client, this.defaults) + } + get noiseSensors(): SeamHttpNoiseSensors { return SeamHttpNoiseSensors.fromClient(this.client, this.defaults) } From 89d5a987adbd7fa1417e54fb5e77235dc728a65c Mon Sep 17 00:00:00 2001 From: Seam Bot Date: Thu, 11 Jan 2024 00:27:14 +0000 Subject: [PATCH 3/3] ci: Format code --- src/lib/seam/connect/seam-http.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/seam/connect/seam-http.ts b/src/lib/seam/connect/seam-http.ts index 31c2a42d..6652790a 100644 --- a/src/lib/seam/connect/seam-http.ts +++ b/src/lib/seam/connect/seam-http.ts @@ -18,7 +18,6 @@ import { } from './options.js' import { limitToSeamHttpRequestOptions, parseOptions } from './parse-options.js' import { - SeamHttpNetworks, SeamHttpAccessCodes, SeamHttpAcs, SeamHttpActionAttempts, @@ -28,6 +27,7 @@ import { SeamHttpDevices, SeamHttpEvents, SeamHttpLocks, + SeamHttpNetworks, SeamHttpNoiseSensors, SeamHttpPhones, SeamHttpThermostats,