@seamapi/http 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/dist/connect.cjs +752 -366
  2. package/dist/connect.cjs.map +1 -1
  3. package/dist/connect.d.cts +186 -142
  4. package/lib/params-serializer.d.ts +5 -0
  5. package/lib/params-serializer.js +42 -0
  6. package/lib/params-serializer.js.map +1 -0
  7. package/lib/seam/connect/auth.d.ts +3 -2
  8. package/lib/seam/connect/auth.js +55 -4
  9. package/lib/seam/connect/auth.js.map +1 -1
  10. package/lib/seam/connect/client.d.ts +10 -22
  11. package/lib/seam/connect/client.js +17 -77
  12. package/lib/seam/connect/client.js.map +1 -1
  13. package/lib/seam/connect/index.d.ts +2 -1
  14. package/lib/seam/connect/index.js +2 -1
  15. package/lib/seam/connect/index.js.map +1 -1
  16. package/lib/seam/connect/{client-options.d.ts → options.d.ts} +7 -7
  17. package/lib/seam/connect/{client-options.js → options.js} +5 -10
  18. package/lib/seam/connect/options.js.map +1 -0
  19. package/lib/seam/connect/parse-options.d.ts +6 -2
  20. package/lib/seam/connect/parse-options.js +34 -16
  21. package/lib/seam/connect/parse-options.js.map +1 -1
  22. package/lib/seam/connect/routes/access-codes-unmanaged.d.ts +10 -9
  23. package/lib/seam/connect/routes/access-codes-unmanaged.js +26 -14
  24. package/lib/seam/connect/routes/access-codes-unmanaged.js.map +1 -1
  25. package/lib/seam/connect/routes/access-codes.d.ts +15 -14
  26. package/lib/seam/connect/routes/access-codes.js +29 -17
  27. package/lib/seam/connect/routes/access-codes.js.map +1 -1
  28. package/lib/seam/connect/routes/acs-access-groups.d.ts +13 -12
  29. package/lib/seam/connect/routes/acs-access-groups.js +26 -14
  30. package/lib/seam/connect/routes/acs-access-groups.js.map +1 -1
  31. package/lib/seam/connect/routes/acs-credentials.d.ts +9 -8
  32. package/lib/seam/connect/routes/acs-credentials.js +26 -14
  33. package/lib/seam/connect/routes/acs-credentials.js.map +1 -1
  34. package/lib/seam/connect/routes/acs-systems.d.ts +9 -8
  35. package/lib/seam/connect/routes/acs-systems.js +29 -17
  36. package/lib/seam/connect/routes/acs-systems.js.map +1 -1
  37. package/lib/seam/connect/routes/acs-users.d.ts +18 -11
  38. package/lib/seam/connect/routes/acs-users.js +40 -14
  39. package/lib/seam/connect/routes/acs-users.js.map +1 -1
  40. package/lib/seam/connect/routes/acs.d.ts +5 -4
  41. package/lib/seam/connect/routes/acs.js +26 -14
  42. package/lib/seam/connect/routes/acs.js.map +1 -1
  43. package/lib/seam/connect/routes/action-attempts.d.ts +7 -6
  44. package/lib/seam/connect/routes/action-attempts.js +26 -14
  45. package/lib/seam/connect/routes/action-attempts.js.map +1 -1
  46. package/lib/seam/connect/routes/client-sessions.d.ts +13 -9
  47. package/lib/seam/connect/routes/client-sessions.js +33 -14
  48. package/lib/seam/connect/routes/client-sessions.js.map +1 -1
  49. package/lib/seam/connect/routes/connect-webviews.d.ts +11 -10
  50. package/lib/seam/connect/routes/connect-webviews.js +29 -17
  51. package/lib/seam/connect/routes/connect-webviews.js.map +1 -1
  52. package/lib/seam/connect/routes/connected-accounts.d.ts +8 -7
  53. package/lib/seam/connect/routes/connected-accounts.js +26 -14
  54. package/lib/seam/connect/routes/connected-accounts.js.map +1 -1
  55. package/lib/seam/connect/routes/devices-unmanaged.d.ts +8 -7
  56. package/lib/seam/connect/routes/devices-unmanaged.js +26 -14
  57. package/lib/seam/connect/routes/devices-unmanaged.js.map +1 -1
  58. package/lib/seam/connect/routes/devices.d.ts +10 -9
  59. package/lib/seam/connect/routes/devices.js +26 -14
  60. package/lib/seam/connect/routes/devices.js.map +1 -1
  61. package/lib/seam/connect/routes/events.d.ts +7 -6
  62. package/lib/seam/connect/routes/events.js +26 -14
  63. package/lib/seam/connect/routes/events.js.map +1 -1
  64. package/lib/seam/connect/routes/locks.d.ts +9 -8
  65. package/lib/seam/connect/routes/locks.js +26 -14
  66. package/lib/seam/connect/routes/locks.js.map +1 -1
  67. package/lib/seam/connect/routes/noise-sensors-noise-thresholds.d.ts +10 -9
  68. package/lib/seam/connect/routes/noise-sensors-noise-thresholds.js +26 -14
  69. package/lib/seam/connect/routes/noise-sensors-noise-thresholds.js.map +1 -1
  70. package/lib/seam/connect/routes/noise-sensors.d.ts +5 -4
  71. package/lib/seam/connect/routes/noise-sensors.js +26 -14
  72. package/lib/seam/connect/routes/noise-sensors.js.map +1 -1
  73. package/lib/seam/connect/routes/thermostats-climate-setting-schedules.d.ts +10 -9
  74. package/lib/seam/connect/routes/thermostats-climate-setting-schedules.js +26 -14
  75. package/lib/seam/connect/routes/thermostats-climate-setting-schedules.js.map +1 -1
  76. package/lib/seam/connect/routes/thermostats.d.ts +13 -12
  77. package/lib/seam/connect/routes/thermostats.js +26 -14
  78. package/lib/seam/connect/routes/thermostats.js.map +1 -1
  79. package/lib/seam/connect/routes/webhooks.d.ts +9 -8
  80. package/lib/seam/connect/routes/webhooks.js +26 -14
  81. package/lib/seam/connect/routes/webhooks.js.map +1 -1
  82. package/lib/seam/connect/routes/workspaces.d.ts +8 -7
  83. package/lib/seam/connect/routes/workspaces.js +26 -14
  84. package/lib/seam/connect/routes/workspaces.js.map +1 -1
  85. package/lib/seam/connect/seam-http.d.ts +24 -0
  86. package/lib/seam/connect/seam-http.js +82 -0
  87. package/lib/seam/connect/seam-http.js.map +1 -0
  88. package/package.json +7 -4
  89. package/src/lib/params-serializer.ts +55 -0
  90. package/src/lib/seam/connect/auth.ts +94 -6
  91. package/src/lib/seam/connect/client.ts +22 -127
  92. package/src/lib/seam/connect/env.d.ts +11 -0
  93. package/src/lib/seam/connect/index.ts +2 -1
  94. package/src/lib/seam/connect/{client-options.ts → options.ts} +13 -19
  95. package/src/lib/seam/connect/parse-options.ts +50 -23
  96. package/src/lib/seam/connect/routes/access-codes-unmanaged.ts +44 -31
  97. package/src/lib/seam/connect/routes/access-codes.ts +48 -48
  98. package/src/lib/seam/connect/routes/acs-access-groups.ts +49 -40
  99. package/src/lib/seam/connect/routes/acs-credentials.ts +40 -28
  100. package/src/lib/seam/connect/routes/acs-systems.ts +40 -30
  101. package/src/lib/seam/connect/routes/acs-users.ts +70 -36
  102. package/src/lib/seam/connect/routes/acs.ts +33 -17
  103. package/src/lib/seam/connect/routes/action-attempts.ts +36 -22
  104. package/src/lib/seam/connect/routes/client-sessions.ts +58 -30
  105. package/src/lib/seam/connect/routes/connect-webviews.ts +45 -34
  106. package/src/lib/seam/connect/routes/connected-accounts.ts +40 -25
  107. package/src/lib/seam/connect/routes/devices-unmanaged.ts +39 -25
  108. package/src/lib/seam/connect/routes/devices.ts +39 -31
  109. package/src/lib/seam/connect/routes/events.ts +36 -22
  110. package/src/lib/seam/connect/routes/locks.ts +38 -28
  111. package/src/lib/seam/connect/routes/noise-sensors-noise-thresholds.ts +47 -31
  112. package/src/lib/seam/connect/routes/noise-sensors.ts +33 -17
  113. package/src/lib/seam/connect/routes/thermostats-climate-setting-schedules.ts +47 -31
  114. package/src/lib/seam/connect/routes/thermostats.ts +42 -40
  115. package/src/lib/seam/connect/routes/webhooks.ts +38 -28
  116. package/src/lib/seam/connect/routes/workspaces.ts +38 -25
  117. package/src/lib/seam/connect/seam-http.ts +141 -0
  118. package/lib/seam/connect/axios.d.ts +0 -3
  119. package/lib/seam/connect/axios.js +0 -19
  120. package/lib/seam/connect/axios.js.map +0 -1
  121. package/lib/seam/connect/client-options.js.map +0 -1
  122. package/src/lib/seam/connect/axios.ts +0 -25
@@ -3,51 +3,52 @@
3
3
  * Do not edit this file or add other files to this directory.
4
4
  */
5
5
 
6
- import type { Axios } from 'axios'
7
-
8
- import { createAxiosClient } from 'lib/seam/connect/axios.js'
6
+ import { warnOnInsecureuserIdentifierKey } from 'lib/seam/connect/auth.js'
7
+ import { type Client, createClient } from 'lib/seam/connect/client.js'
9
8
  import {
10
9
  isSeamHttpOptionsWithApiKey,
11
10
  isSeamHttpOptionsWithClient,
12
11
  isSeamHttpOptionsWithClientSessionToken,
12
+ type SeamHttpFromPublishableKeyOptions,
13
13
  SeamHttpInvalidOptionsError,
14
14
  type SeamHttpOptions,
15
15
  type SeamHttpOptionsWithApiKey,
16
16
  type SeamHttpOptionsWithClient,
17
17
  type SeamHttpOptionsWithClientSessionToken,
18
- } from 'lib/seam/connect/client-options.js'
18
+ } from 'lib/seam/connect/options.js'
19
19
  import { parseOptions } from 'lib/seam/connect/parse-options.js'
20
20
 
21
+ import { SeamHttpClientSessions } from './client-sessions.js'
21
22
  import { SeamHttpNoiseSensorsNoiseThresholds } from './noise-sensors-noise-thresholds.js'
22
23
 
23
24
  export class SeamHttpNoiseSensors {
24
- client: Axios
25
+ client: Client
25
26
 
26
- constructor(apiKeyOrOptions: string | SeamHttpOptions) {
27
- const options = parseOptions(apiKeyOrOptions)
28
- this.client = createAxiosClient(options)
27
+ constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) {
28
+ const clientOptions = parseOptions(apiKeyOrOptions)
29
+ this.client = createClient(clientOptions)
29
30
  }
30
31
 
31
32
  static fromClient(
32
33
  client: SeamHttpOptionsWithClient['client'],
33
34
  options: Omit<SeamHttpOptionsWithClient, 'client'> = {},
34
35
  ): SeamHttpNoiseSensors {
35
- const opts = { ...options, client }
36
- if (!isSeamHttpOptionsWithClient(opts)) {
36
+ const constructorOptions = { ...options, client }
37
+ if (!isSeamHttpOptionsWithClient(constructorOptions)) {
37
38
  throw new SeamHttpInvalidOptionsError('Missing client')
38
39
  }
39
- return new SeamHttpNoiseSensors(opts)
40
+ return new SeamHttpNoiseSensors(constructorOptions)
40
41
  }
41
42
 
42
43
  static fromApiKey(
43
44
  apiKey: SeamHttpOptionsWithApiKey['apiKey'],
44
45
  options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
45
46
  ): SeamHttpNoiseSensors {
46
- const opts = { ...options, apiKey }
47
- if (!isSeamHttpOptionsWithApiKey(opts)) {
47
+ const constructorOptions = { ...options, apiKey }
48
+ if (!isSeamHttpOptionsWithApiKey(constructorOptions)) {
48
49
  throw new SeamHttpInvalidOptionsError('Missing apiKey')
49
50
  }
50
- return new SeamHttpNoiseSensors(opts)
51
+ return new SeamHttpNoiseSensors(constructorOptions)
51
52
  }
52
53
 
53
54
  static fromClientSessionToken(
@@ -57,11 +58,26 @@ export class SeamHttpNoiseSensors {
57
58
  'clientSessionToken'
58
59
  > = {},
59
60
  ): SeamHttpNoiseSensors {
60
- const opts = { ...options, clientSessionToken }
61
- if (!isSeamHttpOptionsWithClientSessionToken(opts)) {
61
+ const constructorOptions = { ...options, clientSessionToken }
62
+ if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) {
62
63
  throw new SeamHttpInvalidOptionsError('Missing clientSessionToken')
63
64
  }
64
- return new SeamHttpNoiseSensors(opts)
65
+ return new SeamHttpNoiseSensors(constructorOptions)
66
+ }
67
+
68
+ static async fromPublishableKey(
69
+ publishableKey: string,
70
+ userIdentifierKey: string,
71
+ options: SeamHttpFromPublishableKeyOptions = {},
72
+ ): Promise<SeamHttpNoiseSensors> {
73
+ warnOnInsecureuserIdentifierKey(userIdentifierKey)
74
+ const clientOptions = parseOptions({ ...options, publishableKey })
75
+ const client = createClient(clientOptions)
76
+ const clientSessions = SeamHttpClientSessions.fromClient(client)
77
+ const { token } = await clientSessions.getOrCreate({
78
+ user_identifier_key: userIdentifierKey,
79
+ })
80
+ return SeamHttpNoiseSensors.fromClientSessionToken(token, options)
65
81
  }
66
82
 
67
83
  get noiseThresholds(): SeamHttpNoiseSensorsNoiseThresholds {
@@ -4,50 +4,53 @@
4
4
  */
5
5
 
6
6
  import type { RouteRequestBody, RouteResponse } from '@seamapi/types/connect'
7
- import type { Axios } from 'axios'
8
7
  import type { SetNonNullable } from 'type-fest'
9
8
 
10
- import { createAxiosClient } from 'lib/seam/connect/axios.js'
9
+ import { warnOnInsecureuserIdentifierKey } from 'lib/seam/connect/auth.js'
10
+ import { type Client, createClient } from 'lib/seam/connect/client.js'
11
11
  import {
12
12
  isSeamHttpOptionsWithApiKey,
13
13
  isSeamHttpOptionsWithClient,
14
14
  isSeamHttpOptionsWithClientSessionToken,
15
+ type SeamHttpFromPublishableKeyOptions,
15
16
  SeamHttpInvalidOptionsError,
16
17
  type SeamHttpOptions,
17
18
  type SeamHttpOptionsWithApiKey,
18
19
  type SeamHttpOptionsWithClient,
19
20
  type SeamHttpOptionsWithClientSessionToken,
20
- } from 'lib/seam/connect/client-options.js'
21
+ } from 'lib/seam/connect/options.js'
21
22
  import { parseOptions } from 'lib/seam/connect/parse-options.js'
22
23
 
24
+ import { SeamHttpClientSessions } from './client-sessions.js'
25
+
23
26
  export class SeamHttpThermostatsClimateSettingSchedules {
24
- client: Axios
27
+ client: Client
25
28
 
26
- constructor(apiKeyOrOptions: string | SeamHttpOptions) {
27
- const options = parseOptions(apiKeyOrOptions)
28
- this.client = createAxiosClient(options)
29
+ constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) {
30
+ const clientOptions = parseOptions(apiKeyOrOptions)
31
+ this.client = createClient(clientOptions)
29
32
  }
30
33
 
31
34
  static fromClient(
32
35
  client: SeamHttpOptionsWithClient['client'],
33
36
  options: Omit<SeamHttpOptionsWithClient, 'client'> = {},
34
37
  ): SeamHttpThermostatsClimateSettingSchedules {
35
- const opts = { ...options, client }
36
- if (!isSeamHttpOptionsWithClient(opts)) {
38
+ const constructorOptions = { ...options, client }
39
+ if (!isSeamHttpOptionsWithClient(constructorOptions)) {
37
40
  throw new SeamHttpInvalidOptionsError('Missing client')
38
41
  }
39
- return new SeamHttpThermostatsClimateSettingSchedules(opts)
42
+ return new SeamHttpThermostatsClimateSettingSchedules(constructorOptions)
40
43
  }
41
44
 
42
45
  static fromApiKey(
43
46
  apiKey: SeamHttpOptionsWithApiKey['apiKey'],
44
47
  options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
45
48
  ): SeamHttpThermostatsClimateSettingSchedules {
46
- const opts = { ...options, apiKey }
47
- if (!isSeamHttpOptionsWithApiKey(opts)) {
49
+ const constructorOptions = { ...options, apiKey }
50
+ if (!isSeamHttpOptionsWithApiKey(constructorOptions)) {
48
51
  throw new SeamHttpInvalidOptionsError('Missing apiKey')
49
52
  }
50
- return new SeamHttpThermostatsClimateSettingSchedules(opts)
53
+ return new SeamHttpThermostatsClimateSettingSchedules(constructorOptions)
51
54
  }
52
55
 
53
56
  static fromClientSessionToken(
@@ -57,11 +60,29 @@ export class SeamHttpThermostatsClimateSettingSchedules {
57
60
  'clientSessionToken'
58
61
  > = {},
59
62
  ): SeamHttpThermostatsClimateSettingSchedules {
60
- const opts = { ...options, clientSessionToken }
61
- if (!isSeamHttpOptionsWithClientSessionToken(opts)) {
63
+ const constructorOptions = { ...options, clientSessionToken }
64
+ if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) {
62
65
  throw new SeamHttpInvalidOptionsError('Missing clientSessionToken')
63
66
  }
64
- return new SeamHttpThermostatsClimateSettingSchedules(opts)
67
+ return new SeamHttpThermostatsClimateSettingSchedules(constructorOptions)
68
+ }
69
+
70
+ static async fromPublishableKey(
71
+ publishableKey: string,
72
+ userIdentifierKey: string,
73
+ options: SeamHttpFromPublishableKeyOptions = {},
74
+ ): Promise<SeamHttpThermostatsClimateSettingSchedules> {
75
+ warnOnInsecureuserIdentifierKey(userIdentifierKey)
76
+ const clientOptions = parseOptions({ ...options, publishableKey })
77
+ const client = createClient(clientOptions)
78
+ const clientSessions = SeamHttpClientSessions.fromClient(client)
79
+ const { token } = await clientSessions.getOrCreate({
80
+ user_identifier_key: userIdentifierKey,
81
+ })
82
+ return SeamHttpThermostatsClimateSettingSchedules.fromClientSessionToken(
83
+ token,
84
+ options,
85
+ )
65
86
  }
66
87
 
67
88
  async create(
@@ -135,41 +156,36 @@ export class SeamHttpThermostatsClimateSettingSchedules {
135
156
  }
136
157
  }
137
158
 
138
- export type ThermostatsClimateSettingSchedulesCreateBody = SetNonNullable<
139
- Required<RouteRequestBody<'/thermostats/climate_setting_schedules/create'>>
140
- >
159
+ export type ThermostatsClimateSettingSchedulesCreateBody =
160
+ RouteRequestBody<'/thermostats/climate_setting_schedules/create'>
141
161
 
142
162
  export type ThermostatsClimateSettingSchedulesCreateResponse = SetNonNullable<
143
163
  Required<RouteResponse<'/thermostats/climate_setting_schedules/create'>>
144
164
  >
145
165
 
146
- export type ThermostatsClimateSettingSchedulesDeleteBody = SetNonNullable<
147
- Required<RouteRequestBody<'/thermostats/climate_setting_schedules/delete'>>
148
- >
166
+ export type ThermostatsClimateSettingSchedulesDeleteBody =
167
+ RouteRequestBody<'/thermostats/climate_setting_schedules/delete'>
149
168
 
150
169
  export type ThermostatsClimateSettingSchedulesDeleteResponse = SetNonNullable<
151
170
  Required<RouteResponse<'/thermostats/climate_setting_schedules/delete'>>
152
171
  >
153
172
 
154
- export type ThermostatsClimateSettingSchedulesGetBody = SetNonNullable<
155
- Required<RouteRequestBody<'/thermostats/climate_setting_schedules/get'>>
156
- >
173
+ export type ThermostatsClimateSettingSchedulesGetBody =
174
+ RouteRequestBody<'/thermostats/climate_setting_schedules/get'>
157
175
 
158
176
  export type ThermostatsClimateSettingSchedulesGetResponse = SetNonNullable<
159
177
  Required<RouteResponse<'/thermostats/climate_setting_schedules/get'>>
160
178
  >
161
179
 
162
- export type ThermostatsClimateSettingSchedulesListBody = SetNonNullable<
163
- Required<RouteRequestBody<'/thermostats/climate_setting_schedules/list'>>
164
- >
180
+ export type ThermostatsClimateSettingSchedulesListBody =
181
+ RouteRequestBody<'/thermostats/climate_setting_schedules/list'>
165
182
 
166
183
  export type ThermostatsClimateSettingSchedulesListResponse = SetNonNullable<
167
184
  Required<RouteResponse<'/thermostats/climate_setting_schedules/list'>>
168
185
  >
169
186
 
170
- export type ThermostatsClimateSettingSchedulesUpdateBody = SetNonNullable<
171
- Required<RouteRequestBody<'/thermostats/climate_setting_schedules/update'>>
172
- >
187
+ export type ThermostatsClimateSettingSchedulesUpdateBody =
188
+ RouteRequestBody<'/thermostats/climate_setting_schedules/update'>
173
189
 
174
190
  export type ThermostatsClimateSettingSchedulesUpdateResponse = SetNonNullable<
175
191
  Required<RouteResponse<'/thermostats/climate_setting_schedules/update'>>
@@ -4,52 +4,54 @@
4
4
  */
5
5
 
6
6
  import type { RouteRequestBody, RouteResponse } from '@seamapi/types/connect'
7
- import type { Axios } from 'axios'
8
7
  import type { SetNonNullable } from 'type-fest'
9
8
 
10
- import { createAxiosClient } from 'lib/seam/connect/axios.js'
9
+ import { warnOnInsecureuserIdentifierKey } from 'lib/seam/connect/auth.js'
10
+ import { type Client, createClient } from 'lib/seam/connect/client.js'
11
11
  import {
12
12
  isSeamHttpOptionsWithApiKey,
13
13
  isSeamHttpOptionsWithClient,
14
14
  isSeamHttpOptionsWithClientSessionToken,
15
+ type SeamHttpFromPublishableKeyOptions,
15
16
  SeamHttpInvalidOptionsError,
16
17
  type SeamHttpOptions,
17
18
  type SeamHttpOptionsWithApiKey,
18
19
  type SeamHttpOptionsWithClient,
19
20
  type SeamHttpOptionsWithClientSessionToken,
20
- } from 'lib/seam/connect/client-options.js'
21
+ } from 'lib/seam/connect/options.js'
21
22
  import { parseOptions } from 'lib/seam/connect/parse-options.js'
22
23
 
24
+ import { SeamHttpClientSessions } from './client-sessions.js'
23
25
  import { SeamHttpThermostatsClimateSettingSchedules } from './thermostats-climate-setting-schedules.js'
24
26
 
25
27
  export class SeamHttpThermostats {
26
- client: Axios
28
+ client: Client
27
29
 
28
- constructor(apiKeyOrOptions: string | SeamHttpOptions) {
29
- const options = parseOptions(apiKeyOrOptions)
30
- this.client = createAxiosClient(options)
30
+ constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) {
31
+ const clientOptions = parseOptions(apiKeyOrOptions)
32
+ this.client = createClient(clientOptions)
31
33
  }
32
34
 
33
35
  static fromClient(
34
36
  client: SeamHttpOptionsWithClient['client'],
35
37
  options: Omit<SeamHttpOptionsWithClient, 'client'> = {},
36
38
  ): SeamHttpThermostats {
37
- const opts = { ...options, client }
38
- if (!isSeamHttpOptionsWithClient(opts)) {
39
+ const constructorOptions = { ...options, client }
40
+ if (!isSeamHttpOptionsWithClient(constructorOptions)) {
39
41
  throw new SeamHttpInvalidOptionsError('Missing client')
40
42
  }
41
- return new SeamHttpThermostats(opts)
43
+ return new SeamHttpThermostats(constructorOptions)
42
44
  }
43
45
 
44
46
  static fromApiKey(
45
47
  apiKey: SeamHttpOptionsWithApiKey['apiKey'],
46
48
  options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
47
49
  ): SeamHttpThermostats {
48
- const opts = { ...options, apiKey }
49
- if (!isSeamHttpOptionsWithApiKey(opts)) {
50
+ const constructorOptions = { ...options, apiKey }
51
+ if (!isSeamHttpOptionsWithApiKey(constructorOptions)) {
50
52
  throw new SeamHttpInvalidOptionsError('Missing apiKey')
51
53
  }
52
- return new SeamHttpThermostats(opts)
54
+ return new SeamHttpThermostats(constructorOptions)
53
55
  }
54
56
 
55
57
  static fromClientSessionToken(
@@ -59,11 +61,26 @@ export class SeamHttpThermostats {
59
61
  'clientSessionToken'
60
62
  > = {},
61
63
  ): SeamHttpThermostats {
62
- const opts = { ...options, clientSessionToken }
63
- if (!isSeamHttpOptionsWithClientSessionToken(opts)) {
64
+ const constructorOptions = { ...options, clientSessionToken }
65
+ if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) {
64
66
  throw new SeamHttpInvalidOptionsError('Missing clientSessionToken')
65
67
  }
66
- return new SeamHttpThermostats(opts)
68
+ return new SeamHttpThermostats(constructorOptions)
69
+ }
70
+
71
+ static async fromPublishableKey(
72
+ publishableKey: string,
73
+ userIdentifierKey: string,
74
+ options: SeamHttpFromPublishableKeyOptions = {},
75
+ ): Promise<SeamHttpThermostats> {
76
+ warnOnInsecureuserIdentifierKey(userIdentifierKey)
77
+ const clientOptions = parseOptions({ ...options, publishableKey })
78
+ const client = createClient(clientOptions)
79
+ const clientSessions = SeamHttpClientSessions.fromClient(client)
80
+ const { token } = await clientSessions.getOrCreate({
81
+ user_identifier_key: userIdentifierKey,
82
+ })
83
+ return SeamHttpThermostats.fromClientSessionToken(token, options)
67
84
  }
68
85
 
69
86
  get climateSettingSchedules(): SeamHttpThermostatsClimateSettingSchedules {
@@ -141,65 +158,50 @@ export class SeamHttpThermostats {
141
158
  }
142
159
  }
143
160
 
144
- export type ThermostatsCoolBody = SetNonNullable<
145
- Required<RouteRequestBody<'/thermostats/cool'>>
146
- >
161
+ export type ThermostatsCoolBody = RouteRequestBody<'/thermostats/cool'>
147
162
 
148
163
  export type ThermostatsCoolResponse = SetNonNullable<
149
164
  Required<RouteResponse<'/thermostats/cool'>>
150
165
  >
151
166
 
152
- export type ThermostatsGetBody = SetNonNullable<
153
- Required<RouteRequestBody<'/thermostats/get'>>
154
- >
167
+ export type ThermostatsGetBody = RouteRequestBody<'/thermostats/get'>
155
168
 
156
169
  export type ThermostatsGetResponse = SetNonNullable<
157
170
  Required<RouteResponse<'/thermostats/get'>>
158
171
  >
159
172
 
160
- export type ThermostatsHeatBody = SetNonNullable<
161
- Required<RouteRequestBody<'/thermostats/heat'>>
162
- >
173
+ export type ThermostatsHeatBody = RouteRequestBody<'/thermostats/heat'>
163
174
 
164
175
  export type ThermostatsHeatResponse = SetNonNullable<
165
176
  Required<RouteResponse<'/thermostats/heat'>>
166
177
  >
167
178
 
168
- export type ThermostatsHeatCoolBody = SetNonNullable<
169
- Required<RouteRequestBody<'/thermostats/heat_cool'>>
170
- >
179
+ export type ThermostatsHeatCoolBody = RouteRequestBody<'/thermostats/heat_cool'>
171
180
 
172
181
  export type ThermostatsHeatCoolResponse = SetNonNullable<
173
182
  Required<RouteResponse<'/thermostats/heat_cool'>>
174
183
  >
175
184
 
176
- export type ThermostatsListBody = SetNonNullable<
177
- Required<RouteRequestBody<'/thermostats/list'>>
178
- >
185
+ export type ThermostatsListBody = RouteRequestBody<'/thermostats/list'>
179
186
 
180
187
  export type ThermostatsListResponse = SetNonNullable<
181
188
  Required<RouteResponse<'/thermostats/list'>>
182
189
  >
183
190
 
184
- export type ThermostatsOffBody = SetNonNullable<
185
- Required<RouteRequestBody<'/thermostats/off'>>
186
- >
191
+ export type ThermostatsOffBody = RouteRequestBody<'/thermostats/off'>
187
192
 
188
193
  export type ThermostatsOffResponse = SetNonNullable<
189
194
  Required<RouteResponse<'/thermostats/off'>>
190
195
  >
191
196
 
192
- export type ThermostatsSetFanModeBody = SetNonNullable<
193
- Required<RouteRequestBody<'/thermostats/set_fan_mode'>>
194
- >
197
+ export type ThermostatsSetFanModeBody =
198
+ RouteRequestBody<'/thermostats/set_fan_mode'>
195
199
 
196
200
  export type ThermostatsSetFanModeResponse = SetNonNullable<
197
201
  Required<RouteResponse<'/thermostats/set_fan_mode'>>
198
202
  >
199
203
 
200
- export type ThermostatsUpdateBody = SetNonNullable<
201
- Required<RouteRequestBody<'/thermostats/update'>>
202
- >
204
+ export type ThermostatsUpdateBody = RouteRequestBody<'/thermostats/update'>
203
205
 
204
206
  export type ThermostatsUpdateResponse = SetNonNullable<
205
207
  Required<RouteResponse<'/thermostats/update'>>
@@ -8,50 +8,53 @@ import type {
8
8
  RouteRequestParams,
9
9
  RouteResponse,
10
10
  } from '@seamapi/types/connect'
11
- import type { Axios } from 'axios'
12
11
  import type { SetNonNullable } from 'type-fest'
13
12
 
14
- import { createAxiosClient } from 'lib/seam/connect/axios.js'
13
+ import { warnOnInsecureuserIdentifierKey } from 'lib/seam/connect/auth.js'
14
+ import { type Client, createClient } from 'lib/seam/connect/client.js'
15
15
  import {
16
16
  isSeamHttpOptionsWithApiKey,
17
17
  isSeamHttpOptionsWithClient,
18
18
  isSeamHttpOptionsWithClientSessionToken,
19
+ type SeamHttpFromPublishableKeyOptions,
19
20
  SeamHttpInvalidOptionsError,
20
21
  type SeamHttpOptions,
21
22
  type SeamHttpOptionsWithApiKey,
22
23
  type SeamHttpOptionsWithClient,
23
24
  type SeamHttpOptionsWithClientSessionToken,
24
- } from 'lib/seam/connect/client-options.js'
25
+ } from 'lib/seam/connect/options.js'
25
26
  import { parseOptions } from 'lib/seam/connect/parse-options.js'
26
27
 
28
+ import { SeamHttpClientSessions } from './client-sessions.js'
29
+
27
30
  export class SeamHttpWebhooks {
28
- client: Axios
31
+ client: Client
29
32
 
30
- constructor(apiKeyOrOptions: string | SeamHttpOptions) {
31
- const options = parseOptions(apiKeyOrOptions)
32
- this.client = createAxiosClient(options)
33
+ constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) {
34
+ const clientOptions = parseOptions(apiKeyOrOptions)
35
+ this.client = createClient(clientOptions)
33
36
  }
34
37
 
35
38
  static fromClient(
36
39
  client: SeamHttpOptionsWithClient['client'],
37
40
  options: Omit<SeamHttpOptionsWithClient, 'client'> = {},
38
41
  ): SeamHttpWebhooks {
39
- const opts = { ...options, client }
40
- if (!isSeamHttpOptionsWithClient(opts)) {
42
+ const constructorOptions = { ...options, client }
43
+ if (!isSeamHttpOptionsWithClient(constructorOptions)) {
41
44
  throw new SeamHttpInvalidOptionsError('Missing client')
42
45
  }
43
- return new SeamHttpWebhooks(opts)
46
+ return new SeamHttpWebhooks(constructorOptions)
44
47
  }
45
48
 
46
49
  static fromApiKey(
47
50
  apiKey: SeamHttpOptionsWithApiKey['apiKey'],
48
51
  options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
49
52
  ): SeamHttpWebhooks {
50
- const opts = { ...options, apiKey }
51
- if (!isSeamHttpOptionsWithApiKey(opts)) {
53
+ const constructorOptions = { ...options, apiKey }
54
+ if (!isSeamHttpOptionsWithApiKey(constructorOptions)) {
52
55
  throw new SeamHttpInvalidOptionsError('Missing apiKey')
53
56
  }
54
- return new SeamHttpWebhooks(opts)
57
+ return new SeamHttpWebhooks(constructorOptions)
55
58
  }
56
59
 
57
60
  static fromClientSessionToken(
@@ -61,11 +64,26 @@ export class SeamHttpWebhooks {
61
64
  'clientSessionToken'
62
65
  > = {},
63
66
  ): SeamHttpWebhooks {
64
- const opts = { ...options, clientSessionToken }
65
- if (!isSeamHttpOptionsWithClientSessionToken(opts)) {
67
+ const constructorOptions = { ...options, clientSessionToken }
68
+ if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) {
66
69
  throw new SeamHttpInvalidOptionsError('Missing clientSessionToken')
67
70
  }
68
- return new SeamHttpWebhooks(opts)
71
+ return new SeamHttpWebhooks(constructorOptions)
72
+ }
73
+
74
+ static async fromPublishableKey(
75
+ publishableKey: string,
76
+ userIdentifierKey: string,
77
+ options: SeamHttpFromPublishableKeyOptions = {},
78
+ ): Promise<SeamHttpWebhooks> {
79
+ warnOnInsecureuserIdentifierKey(userIdentifierKey)
80
+ const clientOptions = parseOptions({ ...options, publishableKey })
81
+ const client = createClient(clientOptions)
82
+ const clientSessions = SeamHttpClientSessions.fromClient(client)
83
+ const { token } = await clientSessions.getOrCreate({
84
+ user_identifier_key: userIdentifierKey,
85
+ })
86
+ return SeamHttpWebhooks.fromClientSessionToken(token, options)
69
87
  }
70
88
 
71
89
  async create(
@@ -108,33 +126,25 @@ export class SeamHttpWebhooks {
108
126
  }
109
127
  }
110
128
 
111
- export type WebhooksCreateBody = SetNonNullable<
112
- Required<RouteRequestBody<'/webhooks/create'>>
113
- >
129
+ export type WebhooksCreateBody = RouteRequestBody<'/webhooks/create'>
114
130
 
115
131
  export type WebhooksCreateResponse = SetNonNullable<
116
132
  Required<RouteResponse<'/webhooks/create'>>
117
133
  >
118
134
 
119
- export type WebhooksDeleteBody = SetNonNullable<
120
- Required<RouteRequestBody<'/webhooks/delete'>>
121
- >
135
+ export type WebhooksDeleteBody = RouteRequestBody<'/webhooks/delete'>
122
136
 
123
137
  export type WebhooksDeleteResponse = SetNonNullable<
124
138
  Required<RouteResponse<'/webhooks/delete'>>
125
139
  >
126
140
 
127
- export type WebhooksGetBody = SetNonNullable<
128
- Required<RouteRequestBody<'/webhooks/get'>>
129
- >
141
+ export type WebhooksGetBody = RouteRequestBody<'/webhooks/get'>
130
142
 
131
143
  export type WebhooksGetResponse = SetNonNullable<
132
144
  Required<RouteResponse<'/webhooks/get'>>
133
145
  >
134
146
 
135
- export type WebhooksListParams = SetNonNullable<
136
- Required<RouteRequestParams<'/webhooks/list'>>
137
- >
147
+ export type WebhooksListParams = RouteRequestParams<'/webhooks/list'>
138
148
 
139
149
  export type WebhooksListResponse = SetNonNullable<
140
150
  Required<RouteResponse<'/webhooks/list'>>