@seamapi/http 0.24.0 → 0.25.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 (124) hide show
  1. package/README.md +15 -0
  2. package/dist/connect.cjs +762 -732
  3. package/dist/connect.cjs.map +1 -1
  4. package/dist/connect.d.cts +149 -126
  5. package/lib/seam/connect/routes/access-codes-unmanaged.d.ts +6 -5
  6. package/lib/seam/connect/routes/access-codes-unmanaged.js +26 -22
  7. package/lib/seam/connect/routes/access-codes-unmanaged.js.map +1 -1
  8. package/lib/seam/connect/routes/access-codes.d.ts +9 -8
  9. package/lib/seam/connect/routes/access-codes.js +41 -38
  10. package/lib/seam/connect/routes/access-codes.js.map +1 -1
  11. package/lib/seam/connect/routes/acs-access-groups.d.ts +6 -5
  12. package/lib/seam/connect/routes/acs-access-groups.js +26 -23
  13. package/lib/seam/connect/routes/acs-access-groups.js.map +1 -1
  14. package/lib/seam/connect/routes/acs-credential-pools.d.ts +2 -1
  15. package/lib/seam/connect/routes/acs-credential-pools.js +6 -5
  16. package/lib/seam/connect/routes/acs-credential-pools.js.map +1 -1
  17. package/lib/seam/connect/routes/acs-credential-provisioning-automations.d.ts +2 -1
  18. package/lib/seam/connect/routes/acs-credential-provisioning-automations.js +6 -5
  19. package/lib/seam/connect/routes/acs-credential-provisioning-automations.js.map +1 -1
  20. package/lib/seam/connect/routes/acs-credentials.d.ts +8 -7
  21. package/lib/seam/connect/routes/acs-credentials.js +36 -34
  22. package/lib/seam/connect/routes/acs-credentials.js.map +1 -1
  23. package/lib/seam/connect/routes/acs-entrances.d.ts +5 -4
  24. package/lib/seam/connect/routes/acs-entrances.js +21 -19
  25. package/lib/seam/connect/routes/acs-entrances.js.map +1 -1
  26. package/lib/seam/connect/routes/acs-systems.d.ts +3 -2
  27. package/lib/seam/connect/routes/acs-systems.js +11 -10
  28. package/lib/seam/connect/routes/acs-systems.js.map +1 -1
  29. package/lib/seam/connect/routes/acs-users.d.ts +12 -11
  30. package/lib/seam/connect/routes/acs-users.js +56 -48
  31. package/lib/seam/connect/routes/acs-users.js.map +1 -1
  32. package/lib/seam/connect/routes/action-attempts.d.ts +3 -2
  33. package/lib/seam/connect/routes/action-attempts.js +12 -18
  34. package/lib/seam/connect/routes/action-attempts.js.map +1 -1
  35. package/lib/seam/connect/routes/client-sessions.d.ts +8 -7
  36. package/lib/seam/connect/routes/client-sessions.js +36 -33
  37. package/lib/seam/connect/routes/client-sessions.js.map +1 -1
  38. package/lib/seam/connect/routes/connect-webviews.d.ts +6 -5
  39. package/lib/seam/connect/routes/connect-webviews.js +25 -22
  40. package/lib/seam/connect/routes/connect-webviews.js.map +1 -1
  41. package/lib/seam/connect/routes/connected-accounts.d.ts +5 -4
  42. package/lib/seam/connect/routes/connected-accounts.js +21 -19
  43. package/lib/seam/connect/routes/connected-accounts.js.map +1 -1
  44. package/lib/seam/connect/routes/devices-simulate.d.ts +2 -1
  45. package/lib/seam/connect/routes/devices-simulate.js +6 -4
  46. package/lib/seam/connect/routes/devices-simulate.js.map +1 -1
  47. package/lib/seam/connect/routes/devices-unmanaged.d.ts +4 -3
  48. package/lib/seam/connect/routes/devices-unmanaged.js +16 -14
  49. package/lib/seam/connect/routes/devices-unmanaged.js.map +1 -1
  50. package/lib/seam/connect/routes/devices.d.ts +6 -5
  51. package/lib/seam/connect/routes/devices.js +26 -23
  52. package/lib/seam/connect/routes/devices.js.map +1 -1
  53. package/lib/seam/connect/routes/events.d.ts +3 -2
  54. package/lib/seam/connect/routes/events.js +11 -10
  55. package/lib/seam/connect/routes/events.js.map +1 -1
  56. package/lib/seam/connect/routes/locks.d.ts +5 -4
  57. package/lib/seam/connect/routes/locks.js +23 -36
  58. package/lib/seam/connect/routes/locks.js.map +1 -1
  59. package/lib/seam/connect/routes/networks.d.ts +3 -2
  60. package/lib/seam/connect/routes/networks.js +11 -10
  61. package/lib/seam/connect/routes/networks.js.map +1 -1
  62. package/lib/seam/connect/routes/noise-sensors-noise-thresholds.d.ts +6 -5
  63. package/lib/seam/connect/routes/noise-sensors-noise-thresholds.js +26 -23
  64. package/lib/seam/connect/routes/noise-sensors-noise-thresholds.js.map +1 -1
  65. package/lib/seam/connect/routes/phones-simulate.d.ts +2 -1
  66. package/lib/seam/connect/routes/phones-simulate.js +6 -5
  67. package/lib/seam/connect/routes/phones-simulate.js.map +1 -1
  68. package/lib/seam/connect/routes/phones.d.ts +3 -2
  69. package/lib/seam/connect/routes/phones.js +11 -9
  70. package/lib/seam/connect/routes/phones.js.map +1 -1
  71. package/lib/seam/connect/routes/thermostats-climate-setting-schedules.d.ts +6 -5
  72. package/lib/seam/connect/routes/thermostats-climate-setting-schedules.js +26 -23
  73. package/lib/seam/connect/routes/thermostats-climate-setting-schedules.js.map +1 -1
  74. package/lib/seam/connect/routes/thermostats.d.ts +9 -8
  75. package/lib/seam/connect/routes/thermostats.js +46 -76
  76. package/lib/seam/connect/routes/thermostats.js.map +1 -1
  77. package/lib/seam/connect/routes/user-identities-enrollment-automations.d.ts +5 -4
  78. package/lib/seam/connect/routes/user-identities-enrollment-automations.js +21 -19
  79. package/lib/seam/connect/routes/user-identities-enrollment-automations.js.map +1 -1
  80. package/lib/seam/connect/routes/user-identities.d.ts +13 -12
  81. package/lib/seam/connect/routes/user-identities.js +61 -54
  82. package/lib/seam/connect/routes/user-identities.js.map +1 -1
  83. package/lib/seam/connect/routes/webhooks.d.ts +6 -5
  84. package/lib/seam/connect/routes/webhooks.js +26 -23
  85. package/lib/seam/connect/routes/webhooks.js.map +1 -1
  86. package/lib/seam/connect/routes/workspaces.d.ts +5 -4
  87. package/lib/seam/connect/routes/workspaces.js +21 -19
  88. package/lib/seam/connect/routes/workspaces.js.map +1 -1
  89. package/lib/seam/connect/seam-http-request.d.ts +26 -0
  90. package/lib/seam/connect/seam-http-request.js +87 -0
  91. package/lib/seam/connect/seam-http-request.js.map +1 -0
  92. package/lib/version.d.ts +1 -1
  93. package/lib/version.js +1 -1
  94. package/package.json +2 -2
  95. package/src/lib/seam/connect/routes/access-codes-unmanaged.ts +37 -34
  96. package/src/lib/seam/connect/routes/access-codes.ts +56 -60
  97. package/src/lib/seam/connect/routes/acs-access-groups.ts +33 -32
  98. package/src/lib/seam/connect/routes/acs-credential-pools.ts +7 -7
  99. package/src/lib/seam/connect/routes/acs-credential-provisioning-automations.ts +11 -13
  100. package/src/lib/seam/connect/routes/acs-credentials.ts +42 -46
  101. package/src/lib/seam/connect/routes/acs-entrances.ts +31 -28
  102. package/src/lib/seam/connect/routes/acs-systems.ts +13 -14
  103. package/src/lib/seam/connect/routes/acs-users.ts +66 -61
  104. package/src/lib/seam/connect/routes/action-attempts.ts +14 -26
  105. package/src/lib/seam/connect/routes/client-sessions.ts +45 -49
  106. package/src/lib/seam/connect/routes/connect-webviews.ts +28 -28
  107. package/src/lib/seam/connect/routes/connected-accounts.ts +26 -29
  108. package/src/lib/seam/connect/routes/devices-simulate.ts +6 -4
  109. package/src/lib/seam/connect/routes/devices-unmanaged.ts +18 -18
  110. package/src/lib/seam/connect/routes/devices.ts +30 -31
  111. package/src/lib/seam/connect/routes/events.ts +11 -12
  112. package/src/lib/seam/connect/routes/locks.ts +25 -50
  113. package/src/lib/seam/connect/routes/networks.ts +14 -13
  114. package/src/lib/seam/connect/routes/noise-sensors-noise-thresholds.ts +48 -38
  115. package/src/lib/seam/connect/routes/phones-simulate.ts +9 -10
  116. package/src/lib/seam/connect/routes/phones.ts +11 -10
  117. package/src/lib/seam/connect/routes/thermostats-climate-setting-schedules.ts +47 -55
  118. package/src/lib/seam/connect/routes/thermostats.ts +53 -110
  119. package/src/lib/seam/connect/routes/user-identities-enrollment-automations.ts +39 -48
  120. package/src/lib/seam/connect/routes/user-identities.ts +81 -78
  121. package/src/lib/seam/connect/routes/webhooks.ts +30 -28
  122. package/src/lib/seam/connect/routes/workspaces.ts +26 -25
  123. package/src/lib/seam/connect/seam-http-request.ts +144 -0
  124. package/src/lib/version.ts +1 -1
@@ -31,6 +31,7 @@ import {
31
31
  limitToSeamHttpRequestOptions,
32
32
  parseOptions,
33
33
  } from 'lib/seam/connect/parse-options.js'
34
+ import { SeamHttpRequest } from 'lib/seam/connect/seam-http-request.js'
34
35
 
35
36
  import { SeamHttpClientSessions } from './client-sessions.js'
36
37
  import { SeamHttpUserIdentitiesEnrollmentAutomations } from './user-identities-enrollment-automations.js'
@@ -161,132 +162,134 @@ export class SeamHttpUserIdentities {
161
162
  )
162
163
  }
163
164
 
164
- async addAcsUser(body?: UserIdentitiesAddAcsUserBody): Promise<void> {
165
- await this.client.request<UserIdentitiesAddAcsUserResponse>({
166
- url: '/user_identities/add_acs_user',
165
+ addAcsUser(
166
+ body?: UserIdentitiesAddAcsUserBody,
167
+ ): SeamHttpRequest<void, undefined> {
168
+ return new SeamHttpRequest(this, {
169
+ path: '/user_identities/add_acs_user',
167
170
  method: 'post',
168
- data: body,
171
+ body,
172
+ responseKey: undefined,
169
173
  })
170
174
  }
171
175
 
172
- async create(
176
+ create(
173
177
  body?: UserIdentitiesCreateBody,
174
- ): Promise<UserIdentitiesCreateResponse['user_identity']> {
175
- const { data } = await this.client.request<UserIdentitiesCreateResponse>({
176
- url: '/user_identities/create',
178
+ ): SeamHttpRequest<UserIdentitiesCreateResponse, 'user_identity'> {
179
+ return new SeamHttpRequest(this, {
180
+ path: '/user_identities/create',
177
181
  method: 'post',
178
- data: body,
182
+ body,
183
+ responseKey: 'user_identity',
179
184
  })
180
-
181
- return data.user_identity
182
185
  }
183
186
 
184
- async delete(body?: UserIdentitiesDeleteBody): Promise<void> {
185
- await this.client.request<UserIdentitiesDeleteResponse>({
186
- url: '/user_identities/delete',
187
+ delete(body?: UserIdentitiesDeleteBody): SeamHttpRequest<void, undefined> {
188
+ return new SeamHttpRequest(this, {
189
+ path: '/user_identities/delete',
187
190
  method: 'post',
188
- data: body,
191
+ body,
192
+ responseKey: undefined,
189
193
  })
190
194
  }
191
195
 
192
- async get(
196
+ get(
193
197
  body?: UserIdentitiesGetParams,
194
- ): Promise<UserIdentitiesGetResponse['user_identity']> {
195
- const { data } = await this.client.request<UserIdentitiesGetResponse>({
196
- url: '/user_identities/get',
198
+ ): SeamHttpRequest<UserIdentitiesGetResponse, 'user_identity'> {
199
+ return new SeamHttpRequest(this, {
200
+ path: '/user_identities/get',
197
201
  method: 'post',
198
- data: body,
202
+ body,
203
+ responseKey: 'user_identity',
199
204
  })
200
-
201
- return data.user_identity
202
205
  }
203
206
 
204
- async grantAccessToDevice(
207
+ grantAccessToDevice(
205
208
  body?: UserIdentitiesGrantAccessToDeviceBody,
206
- ): Promise<void> {
207
- await this.client.request<UserIdentitiesGrantAccessToDeviceResponse>({
208
- url: '/user_identities/grant_access_to_device',
209
+ ): SeamHttpRequest<void, undefined> {
210
+ return new SeamHttpRequest(this, {
211
+ path: '/user_identities/grant_access_to_device',
209
212
  method: 'post',
210
- data: body,
213
+ body,
214
+ responseKey: undefined,
211
215
  })
212
216
  }
213
217
 
214
- async list(
218
+ list(
215
219
  body?: UserIdentitiesListParams,
216
- ): Promise<UserIdentitiesListResponse['user_identities']> {
217
- const { data } = await this.client.request<UserIdentitiesListResponse>({
218
- url: '/user_identities/list',
220
+ ): SeamHttpRequest<UserIdentitiesListResponse, 'user_identities'> {
221
+ return new SeamHttpRequest(this, {
222
+ path: '/user_identities/list',
219
223
  method: 'post',
220
- data: body,
224
+ body,
225
+ responseKey: 'user_identities',
221
226
  })
222
-
223
- return data.user_identities
224
227
  }
225
228
 
226
- async listAccessibleDevices(
229
+ listAccessibleDevices(
227
230
  body?: UserIdentitiesListAccessibleDevicesParams,
228
- ): Promise<
229
- UserIdentitiesListAccessibleDevicesResponse['accessible_devices']
231
+ ): SeamHttpRequest<
232
+ UserIdentitiesListAccessibleDevicesResponse,
233
+ 'accessible_devices'
230
234
  > {
231
- const { data } =
232
- await this.client.request<UserIdentitiesListAccessibleDevicesResponse>({
233
- url: '/user_identities/list_accessible_devices',
234
- method: 'post',
235
- data: body,
236
- })
237
-
238
- return data.accessible_devices
235
+ return new SeamHttpRequest(this, {
236
+ path: '/user_identities/list_accessible_devices',
237
+ method: 'post',
238
+ body,
239
+ responseKey: 'accessible_devices',
240
+ })
239
241
  }
240
242
 
241
- async listAcsSystems(
243
+ listAcsSystems(
242
244
  body?: UserIdentitiesListAcsSystemsParams,
243
- ): Promise<UserIdentitiesListAcsSystemsResponse['acs_systems']> {
244
- const { data } =
245
- await this.client.request<UserIdentitiesListAcsSystemsResponse>({
246
- url: '/user_identities/list_acs_systems',
247
- method: 'post',
248
- data: body,
249
- })
250
-
251
- return data.acs_systems
245
+ ): SeamHttpRequest<UserIdentitiesListAcsSystemsResponse, 'acs_systems'> {
246
+ return new SeamHttpRequest(this, {
247
+ path: '/user_identities/list_acs_systems',
248
+ method: 'post',
249
+ body,
250
+ responseKey: 'acs_systems',
251
+ })
252
252
  }
253
253
 
254
- async listAcsUsers(
254
+ listAcsUsers(
255
255
  body?: UserIdentitiesListAcsUsersParams,
256
- ): Promise<UserIdentitiesListAcsUsersResponse['acs_users']> {
257
- const { data } =
258
- await this.client.request<UserIdentitiesListAcsUsersResponse>({
259
- url: '/user_identities/list_acs_users',
260
- method: 'post',
261
- data: body,
262
- })
263
-
264
- return data.acs_users
256
+ ): SeamHttpRequest<UserIdentitiesListAcsUsersResponse, 'acs_users'> {
257
+ return new SeamHttpRequest(this, {
258
+ path: '/user_identities/list_acs_users',
259
+ method: 'post',
260
+ body,
261
+ responseKey: 'acs_users',
262
+ })
265
263
  }
266
264
 
267
- async removeAcsUser(body?: UserIdentitiesRemoveAcsUserBody): Promise<void> {
268
- await this.client.request<UserIdentitiesRemoveAcsUserResponse>({
269
- url: '/user_identities/remove_acs_user',
265
+ removeAcsUser(
266
+ body?: UserIdentitiesRemoveAcsUserBody,
267
+ ): SeamHttpRequest<void, undefined> {
268
+ return new SeamHttpRequest(this, {
269
+ path: '/user_identities/remove_acs_user',
270
270
  method: 'post',
271
- data: body,
271
+ body,
272
+ responseKey: undefined,
272
273
  })
273
274
  }
274
275
 
275
- async revokeAccessToDevice(
276
+ revokeAccessToDevice(
276
277
  body?: UserIdentitiesRevokeAccessToDeviceBody,
277
- ): Promise<void> {
278
- await this.client.request<UserIdentitiesRevokeAccessToDeviceResponse>({
279
- url: '/user_identities/revoke_access_to_device',
278
+ ): SeamHttpRequest<void, undefined> {
279
+ return new SeamHttpRequest(this, {
280
+ path: '/user_identities/revoke_access_to_device',
280
281
  method: 'post',
281
- data: body,
282
+ body,
283
+ responseKey: undefined,
282
284
  })
283
285
  }
284
286
 
285
- async update(body?: UserIdentitiesUpdateBody): Promise<void> {
286
- await this.client.request<UserIdentitiesUpdateResponse>({
287
- url: '/user_identities/update',
287
+ update(body?: UserIdentitiesUpdateBody): SeamHttpRequest<void, undefined> {
288
+ return new SeamHttpRequest(this, {
289
+ path: '/user_identities/update',
288
290
  method: 'post',
289
- data: body,
291
+ body,
292
+ responseKey: undefined,
290
293
  })
291
294
  }
292
295
  }
@@ -31,6 +31,7 @@ import {
31
31
  limitToSeamHttpRequestOptions,
32
32
  parseOptions,
33
33
  } from 'lib/seam/connect/parse-options.js'
34
+ import { SeamHttpRequest } from 'lib/seam/connect/seam-http-request.js'
34
35
 
35
36
  import { SeamHttpClientSessions } from './client-sessions.js'
36
37
 
@@ -153,53 +154,54 @@ export class SeamHttpWebhooks {
153
154
  await clientSessions.get()
154
155
  }
155
156
 
156
- async create(
157
+ create(
157
158
  body?: WebhooksCreateBody,
158
- ): Promise<WebhooksCreateResponse['webhook']> {
159
- const { data } = await this.client.request<WebhooksCreateResponse>({
160
- url: '/webhooks/create',
159
+ ): SeamHttpRequest<WebhooksCreateResponse, 'webhook'> {
160
+ return new SeamHttpRequest(this, {
161
+ path: '/webhooks/create',
161
162
  method: 'post',
162
- data: body,
163
+ body,
164
+ responseKey: 'webhook',
163
165
  })
164
-
165
- return data.webhook
166
166
  }
167
167
 
168
- async delete(body?: WebhooksDeleteBody): Promise<void> {
169
- await this.client.request<WebhooksDeleteResponse>({
170
- url: '/webhooks/delete',
168
+ delete(body?: WebhooksDeleteBody): SeamHttpRequest<void, undefined> {
169
+ return new SeamHttpRequest(this, {
170
+ path: '/webhooks/delete',
171
171
  method: 'post',
172
- data: body,
172
+ body,
173
+ responseKey: undefined,
173
174
  })
174
175
  }
175
176
 
176
- async get(body?: WebhooksGetParams): Promise<WebhooksGetResponse['webhook']> {
177
- const { data } = await this.client.request<WebhooksGetResponse>({
178
- url: '/webhooks/get',
177
+ get(
178
+ body?: WebhooksGetParams,
179
+ ): SeamHttpRequest<WebhooksGetResponse, 'webhook'> {
180
+ return new SeamHttpRequest(this, {
181
+ path: '/webhooks/get',
179
182
  method: 'post',
180
- data: body,
183
+ body,
184
+ responseKey: 'webhook',
181
185
  })
182
-
183
- return data.webhook
184
186
  }
185
187
 
186
- async list(
188
+ list(
187
189
  body?: WebhooksListParams,
188
- ): Promise<WebhooksListResponse['webhooks']> {
189
- const { data } = await this.client.request<WebhooksListResponse>({
190
- url: '/webhooks/list',
190
+ ): SeamHttpRequest<WebhooksListResponse, 'webhooks'> {
191
+ return new SeamHttpRequest(this, {
192
+ path: '/webhooks/list',
191
193
  method: 'post',
192
- data: body,
194
+ body,
195
+ responseKey: 'webhooks',
193
196
  })
194
-
195
- return data.webhooks
196
197
  }
197
198
 
198
- async update(body?: WebhooksUpdateBody): Promise<void> {
199
- await this.client.request<WebhooksUpdateResponse>({
200
- url: '/webhooks/update',
199
+ update(body?: WebhooksUpdateBody): SeamHttpRequest<void, undefined> {
200
+ return new SeamHttpRequest(this, {
201
+ path: '/webhooks/update',
201
202
  method: 'post',
202
- data: body,
203
+ body,
204
+ responseKey: undefined,
203
205
  })
204
206
  }
205
207
  }
@@ -31,6 +31,7 @@ import {
31
31
  limitToSeamHttpRequestOptions,
32
32
  parseOptions,
33
33
  } from 'lib/seam/connect/parse-options.js'
34
+ import { SeamHttpRequest } from 'lib/seam/connect/seam-http-request.js'
34
35
 
35
36
  import { SeamHttpClientSessions } from './client-sessions.js'
36
37
 
@@ -153,47 +154,47 @@ export class SeamHttpWorkspaces {
153
154
  await clientSessions.get()
154
155
  }
155
156
 
156
- async create(
157
+ create(
157
158
  body?: WorkspacesCreateBody,
158
- ): Promise<WorkspacesCreateResponse['workspace']> {
159
- const { data } = await this.client.request<WorkspacesCreateResponse>({
160
- url: '/workspaces/create',
159
+ ): SeamHttpRequest<WorkspacesCreateResponse, 'workspace'> {
160
+ return new SeamHttpRequest(this, {
161
+ path: '/workspaces/create',
161
162
  method: 'post',
162
- data: body,
163
+ body,
164
+ responseKey: 'workspace',
163
165
  })
164
-
165
- return data.workspace
166
166
  }
167
167
 
168
- async get(
168
+ get(
169
169
  body?: WorkspacesGetParams,
170
- ): Promise<WorkspacesGetResponse['workspace']> {
171
- const { data } = await this.client.request<WorkspacesGetResponse>({
172
- url: '/workspaces/get',
170
+ ): SeamHttpRequest<WorkspacesGetResponse, 'workspace'> {
171
+ return new SeamHttpRequest(this, {
172
+ path: '/workspaces/get',
173
173
  method: 'post',
174
- data: body,
174
+ body,
175
+ responseKey: 'workspace',
175
176
  })
176
-
177
- return data.workspace
178
177
  }
179
178
 
180
- async list(
179
+ list(
181
180
  body?: WorkspacesListParams,
182
- ): Promise<WorkspacesListResponse['workspaces']> {
183
- const { data } = await this.client.request<WorkspacesListResponse>({
184
- url: '/workspaces/list',
181
+ ): SeamHttpRequest<WorkspacesListResponse, 'workspaces'> {
182
+ return new SeamHttpRequest(this, {
183
+ path: '/workspaces/list',
185
184
  method: 'post',
186
- data: body,
185
+ body,
186
+ responseKey: 'workspaces',
187
187
  })
188
-
189
- return data.workspaces
190
188
  }
191
189
 
192
- async resetSandbox(body?: WorkspacesResetSandboxBody): Promise<void> {
193
- await this.client.request<WorkspacesResetSandboxResponse>({
194
- url: '/workspaces/reset_sandbox',
190
+ resetSandbox(
191
+ body?: WorkspacesResetSandboxBody,
192
+ ): SeamHttpRequest<void, undefined> {
193
+ return new SeamHttpRequest(this, {
194
+ path: '/workspaces/reset_sandbox',
195
195
  method: 'post',
196
- data: body,
196
+ body,
197
+ responseKey: undefined,
197
198
  })
198
199
  }
199
200
  }
@@ -0,0 +1,144 @@
1
+ import { serializeUrlSearchParams } from '@seamapi/url-search-params-serializer'
2
+ import type { Method } from 'axios'
3
+
4
+ import type { Client } from './client.js'
5
+ import type { SeamHttpRequestOptions } from './options.js'
6
+ import { resolveActionAttempt } from './resolve-action-attempt.js'
7
+ import { SeamHttpActionAttempts } from './routes/index.js'
8
+
9
+ interface SeamHttpRequestParent {
10
+ readonly client: Client
11
+ readonly defaults: Required<SeamHttpRequestOptions>
12
+ }
13
+
14
+ interface SeamHttpRequestConfig<TResponseKey> {
15
+ readonly path: string
16
+ readonly method: Method
17
+ readonly body?: unknown
18
+ readonly params?: undefined | Record<string, unknown>
19
+ readonly responseKey: TResponseKey
20
+ readonly options?: Pick<SeamHttpRequestOptions, 'waitForActionAttempt'>
21
+ }
22
+
23
+ export class SeamHttpRequest<
24
+ const TResponse,
25
+ const TResponseKey extends keyof TResponse | undefined,
26
+ > implements
27
+ PromiseLike<
28
+ TResponseKey extends keyof TResponse ? TResponse[TResponseKey] : undefined
29
+ >
30
+ {
31
+ readonly #parent: SeamHttpRequestParent
32
+ readonly #config: SeamHttpRequestConfig<TResponseKey>
33
+
34
+ constructor(
35
+ parent: SeamHttpRequestParent,
36
+ config: SeamHttpRequestConfig<TResponseKey>,
37
+ ) {
38
+ this.#parent = parent
39
+ this.#config = config
40
+ }
41
+
42
+ public get responseKey(): TResponseKey {
43
+ return this.#config.responseKey
44
+ }
45
+
46
+ public get url(): URL {
47
+ const { client } = this.#parent
48
+ const { params } = this.#config
49
+
50
+ const serializer =
51
+ typeof client.defaults.paramsSerializer === 'function'
52
+ ? client.defaults.paramsSerializer
53
+ : serializeUrlSearchParams
54
+
55
+ const origin = getUrlPrefix(client.defaults.baseURL ?? '')
56
+
57
+ const pathname = this.#config.path.startsWith('/')
58
+ ? this.#config.path
59
+ : `/${this.#config.path}`
60
+
61
+ const path = params == null ? pathname : `${pathname}?${serializer(params)}`
62
+
63
+ return new URL(`${origin}${path}`)
64
+ }
65
+
66
+ public get method(): Method {
67
+ return this.#config.method
68
+ }
69
+
70
+ public get body(): unknown {
71
+ return this.#config.body
72
+ }
73
+
74
+ async execute(): Promise<
75
+ TResponseKey extends keyof TResponse ? TResponse[TResponseKey] : undefined
76
+ > {
77
+ const { client } = this.#parent
78
+ const response = await client.request({
79
+ url: this.#config.path,
80
+ method: this.#config.method,
81
+ data: this.#config.body,
82
+ params: this.#config.params,
83
+ })
84
+ if (this.responseKey === undefined) {
85
+ return undefined as TResponseKey extends keyof TResponse
86
+ ? TResponse[TResponseKey]
87
+ : undefined
88
+ }
89
+ const data = response.data[this.responseKey]
90
+ if (this.responseKey === 'action_attempt') {
91
+ const waitForActionAttempt =
92
+ this.#config.options?.waitForActionAttempt ??
93
+ this.#parent.defaults.waitForActionAttempt
94
+ if (waitForActionAttempt !== false) {
95
+ return await resolveActionAttempt(
96
+ data,
97
+ SeamHttpActionAttempts.fromClient(client, {
98
+ ...this.#parent.defaults,
99
+ waitForActionAttempt: false,
100
+ }),
101
+ typeof waitForActionAttempt === 'boolean' ? {} : waitForActionAttempt,
102
+ )
103
+ }
104
+ }
105
+ return data
106
+ }
107
+
108
+ then<
109
+ TResult1 = TResponseKey extends keyof TResponse
110
+ ? TResponse[TResponseKey]
111
+ : undefined,
112
+ TResult2 = never,
113
+ >(
114
+ onfulfilled?:
115
+ | ((
116
+ value: TResponseKey extends keyof TResponse
117
+ ? TResponse[TResponseKey]
118
+ : undefined,
119
+ ) => TResult1 | PromiseLike<TResult1>)
120
+ | null
121
+ | undefined,
122
+ onrejected?:
123
+ | ((reason: any) => TResult2 | PromiseLike<TResult2>)
124
+ | null
125
+ | undefined,
126
+ ): PromiseLike<TResult1 | TResult2> {
127
+ return this.execute().then(onfulfilled, onrejected)
128
+ }
129
+ }
130
+
131
+ const getUrlPrefix = (input: string): string => {
132
+ if (URL.canParse(input)) {
133
+ const url = new URL(input).toString()
134
+ if (url.endsWith('/')) return url.slice(0, -1)
135
+ return url
136
+ }
137
+ if (globalThis.location != null) {
138
+ const pathname = input.startsWith('/') ? input : `/${input}`
139
+ return new URL(`${globalThis.location.origin}${pathname}`).toString()
140
+ }
141
+ throw new Error(
142
+ `Cannot resolve origin from ${input} in a non-browser environment`,
143
+ )
144
+ }
@@ -1,3 +1,3 @@
1
- const seamapiJavascriptHttpVersion = '0.24.0'
1
+ const seamapiJavascriptHttpVersion = '0.25.0'
2
2
 
3
3
  export default seamapiJavascriptHttpVersion