Skip to content

Commit 394e657

Browse files
committed
Add endpointMethods overrides
1 parent fd3a4eb commit 394e657

File tree

5 files changed

+65
-27
lines changed

5 files changed

+65
-27
lines changed

generate-routes.ts

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ const ignoredEndpointPaths = [
4141
'/noise_sensors/simulate/trigger_noise_threshold',
4242
]
4343

44+
const endpointMethods: Partial<Record<keyof typeof openapi.paths, Method>> = {
45+
'/access_codes/create_multiple': 'POST',
46+
'/access_codes/unmanaged/convert_to_managed': 'POST',
47+
// '/access_codes/update': 'PATCH',
48+
'/client_sessions/create': 'POST',
49+
// '/noise_sensors/noise_thresholds/update': 'PATCH',
50+
'/thermostats/climate_setting_schedules/delete': 'DELETE',
51+
// '/thermostats/climate_setting_schedules/update': 'PATCH',
52+
}
53+
4454
const endpointResources: Partial<
4555
Record<
4656
keyof typeof openapi.paths,
@@ -137,7 +147,7 @@ const createEndpoint = (
137147
throw new Error(`Did not find ${endpointPath} in OpenAPI spec`)
138148
}
139149
const spec = openapi.paths[endpointPath]
140-
const method = deriveSemanticMethod(Object.keys(spec))
150+
const method = deriveSemanticMethod(endpointPath, Object.keys(spec))
141151
const name = endpointPath.split(routePath)[1]?.slice(1)
142152
if (name == null) {
143153
throw new Error(`Could not parse name from ${endpointPath}`)
@@ -158,10 +168,8 @@ const deriveResource = (
158168
name: string,
159169
method: Method,
160170
): string | null => {
161-
if (endpointPath in endpointResources) {
162-
return (
163-
endpointResources[endpointPath as keyof typeof endpointResources] ?? null
164-
)
171+
if (isEndpointResource(endpointPath)) {
172+
return endpointResources[endpointPath] ?? null
165173
}
166174
if (['DELETE', 'PATCH', 'PUT'].includes(method)) return null
167175
if (['update', 'delete'].includes(name)) return null
@@ -189,7 +197,17 @@ const deriveGroupFromRoutePath = (routePath: string): string | undefined => {
189197
return parts[0]
190198
}
191199

192-
const deriveSemanticMethod = (methods: string[]): Method => {
200+
const deriveSemanticMethod = (
201+
endpointPath: string,
202+
methods: string[],
203+
): Method => {
204+
if (isEndpointMethod(endpointPath)) {
205+
const endpointMethod = endpointMethods[endpointPath]
206+
if (endpointMethod == null) {
207+
throw new Error(`Got undefined method for ${endpointMethod}`)
208+
}
209+
return endpointMethod
210+
}
193211
if (methods.includes('get')) return 'GET'
194212
if (methods.includes('delete')) return 'DELETE'
195213
if (methods.includes('patch')) return 'PATCH'
@@ -198,6 +216,13 @@ const deriveSemanticMethod = (methods: string[]): Method => {
198216
throw new Error(`Could not find valid method in ${methods.join(', ')}`)
199217
}
200218

219+
const isEndpointResource = (
220+
key: string,
221+
): key is keyof typeof endpointResources => key in endpointResources
222+
223+
const isEndpointMethod = (key: string): key is keyof typeof endpointMethods =>
224+
key in endpointMethods
225+
201226
const isOpenApiPath = (key: string): key is keyof typeof openapi.paths =>
202227
key in openapi.paths
203228

src/lib/seam/connect/routes/access-codes-unmanaged.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,14 @@ export class SeamHttpAccessCodesUnmanaged {
6666

6767
async convertToManaged(
6868
body: AccessCodesUnmanagedConvertToManagedBody,
69-
): Promise<void> {
70-
await this.client.request<AccessCodesUnmanagedConvertToManagedResponse>({
71-
url: '/access_codes/unmanaged/convert_to_managed',
72-
method: 'patch',
73-
data: body,
74-
})
69+
): Promise<AccessCodesUnmanagedConvertToManagedResponse['access_code']> {
70+
const { data } =
71+
await this.client.request<AccessCodesUnmanagedConvertToManagedResponse>({
72+
url: '/access_codes/unmanaged/convert_to_managed',
73+
method: 'post',
74+
data: body,
75+
})
76+
return data.access_code
7577
}
7678

7779
async delete(body: AccessCodesUnmanagedDeleteBody): Promise<void> {

src/lib/seam/connect/routes/access-codes.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,16 @@ export class SeamHttpAccessCodes {
7979
return data.access_code
8080
}
8181

82-
async createMultiple(body: AccessCodesCreateMultipleBody): Promise<void> {
83-
await this.client.request<AccessCodesCreateMultipleResponse>({
84-
url: '/access_codes/create_multiple',
85-
method: 'put',
86-
data: body,
87-
})
82+
async createMultiple(
83+
body: AccessCodesCreateMultipleBody,
84+
): Promise<AccessCodesCreateMultipleResponse['access_code']> {
85+
const { data } =
86+
await this.client.request<AccessCodesCreateMultipleResponse>({
87+
url: '/access_codes/create_multiple',
88+
method: 'post',
89+
data: body,
90+
})
91+
return data.access_code
8892
}
8993

9094
async delete(body: AccessCodesDeleteBody): Promise<void> {

src/lib/seam/connect/routes/client-sessions.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,15 @@ export class SeamHttpClientSessions {
6464
return new SeamHttpClientSessions(opts)
6565
}
6666

67-
async create(body: ClientSessionsCreateBody): Promise<void> {
68-
await this.client.request<ClientSessionsCreateResponse>({
67+
async create(
68+
body: ClientSessionsCreateBody,
69+
): Promise<ClientSessionsCreateResponse['client_session']> {
70+
const { data } = await this.client.request<ClientSessionsCreateResponse>({
6971
url: '/client_sessions/create',
70-
method: 'put',
72+
method: 'post',
7173
data: body,
7274
})
75+
return data.client_session
7376
}
7477

7578
async delete(body: ClientSessionsDeleteBody): Promise<void> {

src/lib/seam/connect/routes/thermostats-climate-setting-schedules.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
* Do not edit this file or add other files to this directory.
44
*/
55

6-
import type { RouteRequestBody, RouteResponse } from '@seamapi/types/connect'
6+
import type {
7+
RouteRequestBody,
8+
RouteRequestParams,
9+
RouteResponse,
10+
} from '@seamapi/types/connect'
711
import type { Axios } from 'axios'
812
import type { SetNonNullable } from 'type-fest'
913

@@ -81,13 +85,13 @@ export class SeamHttpThermostatsClimateSettingSchedules {
8185
}
8286

8387
async delete(
84-
body: ThermostatsClimateSettingSchedulesDeleteBody,
88+
params?: ThermostatsClimateSettingSchedulesDeleteParams,
8589
): Promise<void> {
8690
await this.client.request<ThermostatsClimateSettingSchedulesDeleteResponse>(
8791
{
8892
url: '/thermostats/climate_setting_schedules/delete',
89-
method: 'put',
90-
data: body,
93+
method: 'delete',
94+
params,
9195
},
9296
)
9397
}
@@ -143,8 +147,8 @@ export type ThermostatsClimateSettingSchedulesCreateResponse = SetNonNullable<
143147
Required<RouteResponse<'/thermostats/climate_setting_schedules/create'>>
144148
>
145149

146-
export type ThermostatsClimateSettingSchedulesDeleteBody = SetNonNullable<
147-
Required<RouteRequestBody<'/thermostats/climate_setting_schedules/delete'>>
150+
export type ThermostatsClimateSettingSchedulesDeleteParams = SetNonNullable<
151+
Required<RouteRequestParams<'/thermostats/climate_setting_schedules/delete'>>
148152
>
149153

150154
export type ThermostatsClimateSettingSchedulesDeleteResponse = SetNonNullable<

0 commit comments

Comments
 (0)