@seamapi/http 1.23.0 → 1.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 (182) hide show
  1. package/README.md +61 -0
  2. package/dist/connect.cjs +398 -170
  3. package/dist/connect.cjs.map +1 -1
  4. package/dist/connect.d.cts +78 -4
  5. package/dist/index.cjs +2 -2
  6. package/dist/index.cjs.map +1 -1
  7. package/lib/seam/connect/index.d.ts +2 -0
  8. package/lib/seam/connect/index.js +2 -0
  9. package/lib/seam/connect/index.js.map +1 -1
  10. package/lib/seam/connect/routes/access-codes-simulate.d.ts +2 -0
  11. package/lib/seam/connect/routes/access-codes-simulate.js +5 -1
  12. package/lib/seam/connect/routes/access-codes-simulate.js.map +1 -1
  13. package/lib/seam/connect/routes/access-codes-unmanaged.d.ts +2 -0
  14. package/lib/seam/connect/routes/access-codes-unmanaged.js +9 -5
  15. package/lib/seam/connect/routes/access-codes-unmanaged.js.map +1 -1
  16. package/lib/seam/connect/routes/access-codes.d.ts +2 -0
  17. package/lib/seam/connect/routes/access-codes.js +13 -9
  18. package/lib/seam/connect/routes/access-codes.js.map +1 -1
  19. package/lib/seam/connect/routes/acs-access-groups-unmanaged.d.ts +2 -0
  20. package/lib/seam/connect/routes/acs-access-groups-unmanaged.js +6 -2
  21. package/lib/seam/connect/routes/acs-access-groups-unmanaged.js.map +1 -1
  22. package/lib/seam/connect/routes/acs-access-groups.d.ts +2 -0
  23. package/lib/seam/connect/routes/acs-access-groups.js +10 -6
  24. package/lib/seam/connect/routes/acs-access-groups.js.map +1 -1
  25. package/lib/seam/connect/routes/acs-credential-pools.d.ts +2 -0
  26. package/lib/seam/connect/routes/acs-credential-pools.js +5 -1
  27. package/lib/seam/connect/routes/acs-credential-pools.js.map +1 -1
  28. package/lib/seam/connect/routes/acs-credential-provisioning-automations.d.ts +2 -0
  29. package/lib/seam/connect/routes/acs-credential-provisioning-automations.js +5 -1
  30. package/lib/seam/connect/routes/acs-credential-provisioning-automations.js.map +1 -1
  31. package/lib/seam/connect/routes/acs-credentials-unmanaged.d.ts +2 -0
  32. package/lib/seam/connect/routes/acs-credentials-unmanaged.js +6 -2
  33. package/lib/seam/connect/routes/acs-credentials-unmanaged.js.map +1 -1
  34. package/lib/seam/connect/routes/acs-credentials.d.ts +2 -0
  35. package/lib/seam/connect/routes/acs-credentials.js +13 -9
  36. package/lib/seam/connect/routes/acs-credentials.js.map +1 -1
  37. package/lib/seam/connect/routes/acs-encoders-simulate.d.ts +2 -0
  38. package/lib/seam/connect/routes/acs-encoders-simulate.js +8 -4
  39. package/lib/seam/connect/routes/acs-encoders-simulate.js.map +1 -1
  40. package/lib/seam/connect/routes/acs-encoders.d.ts +2 -0
  41. package/lib/seam/connect/routes/acs-encoders.js +7 -3
  42. package/lib/seam/connect/routes/acs-encoders.js.map +1 -1
  43. package/lib/seam/connect/routes/acs-entrances.d.ts +2 -0
  44. package/lib/seam/connect/routes/acs-entrances.js +8 -4
  45. package/lib/seam/connect/routes/acs-entrances.js.map +1 -1
  46. package/lib/seam/connect/routes/acs-systems.d.ts +2 -0
  47. package/lib/seam/connect/routes/acs-systems.js +7 -3
  48. package/lib/seam/connect/routes/acs-systems.js.map +1 -1
  49. package/lib/seam/connect/routes/acs-users-unmanaged.d.ts +2 -0
  50. package/lib/seam/connect/routes/acs-users-unmanaged.js +6 -2
  51. package/lib/seam/connect/routes/acs-users-unmanaged.js.map +1 -1
  52. package/lib/seam/connect/routes/acs-users.d.ts +2 -0
  53. package/lib/seam/connect/routes/acs-users.js +15 -11
  54. package/lib/seam/connect/routes/acs-users.js.map +1 -1
  55. package/lib/seam/connect/routes/acs.d.ts +3 -0
  56. package/lib/seam/connect/routes/acs.js +4 -0
  57. package/lib/seam/connect/routes/acs.js.map +1 -1
  58. package/lib/seam/connect/routes/action-attempts.d.ts +2 -0
  59. package/lib/seam/connect/routes/action-attempts.js +6 -2
  60. package/lib/seam/connect/routes/action-attempts.js.map +1 -1
  61. package/lib/seam/connect/routes/bridges.d.ts +2 -0
  62. package/lib/seam/connect/routes/bridges.js +6 -2
  63. package/lib/seam/connect/routes/bridges.js.map +1 -1
  64. package/lib/seam/connect/routes/client-sessions.d.ts +2 -0
  65. package/lib/seam/connect/routes/client-sessions.js +11 -7
  66. package/lib/seam/connect/routes/client-sessions.js.map +1 -1
  67. package/lib/seam/connect/routes/connect-webviews.d.ts +2 -0
  68. package/lib/seam/connect/routes/connect-webviews.js +8 -4
  69. package/lib/seam/connect/routes/connect-webviews.js.map +1 -1
  70. package/lib/seam/connect/routes/connected-accounts.d.ts +2 -0
  71. package/lib/seam/connect/routes/connected-accounts.js +8 -4
  72. package/lib/seam/connect/routes/connected-accounts.js.map +1 -1
  73. package/lib/seam/connect/routes/devices-simulate.d.ts +2 -0
  74. package/lib/seam/connect/routes/devices-simulate.js +7 -3
  75. package/lib/seam/connect/routes/devices-simulate.js.map +1 -1
  76. package/lib/seam/connect/routes/devices-unmanaged.d.ts +2 -0
  77. package/lib/seam/connect/routes/devices-unmanaged.js +7 -3
  78. package/lib/seam/connect/routes/devices-unmanaged.js.map +1 -1
  79. package/lib/seam/connect/routes/devices.d.ts +2 -0
  80. package/lib/seam/connect/routes/devices.js +9 -5
  81. package/lib/seam/connect/routes/devices.js.map +1 -1
  82. package/lib/seam/connect/routes/events.d.ts +2 -0
  83. package/lib/seam/connect/routes/events.js +6 -2
  84. package/lib/seam/connect/routes/events.js.map +1 -1
  85. package/lib/seam/connect/routes/locks.d.ts +2 -0
  86. package/lib/seam/connect/routes/locks.js +8 -4
  87. package/lib/seam/connect/routes/locks.js.map +1 -1
  88. package/lib/seam/connect/routes/networks.d.ts +2 -0
  89. package/lib/seam/connect/routes/networks.js +6 -2
  90. package/lib/seam/connect/routes/networks.js.map +1 -1
  91. package/lib/seam/connect/routes/noise-sensors-noise-thresholds.d.ts +2 -0
  92. package/lib/seam/connect/routes/noise-sensors-noise-thresholds.js +9 -5
  93. package/lib/seam/connect/routes/noise-sensors-noise-thresholds.js.map +1 -1
  94. package/lib/seam/connect/routes/noise-sensors-simulate.d.ts +2 -0
  95. package/lib/seam/connect/routes/noise-sensors-simulate.js +5 -1
  96. package/lib/seam/connect/routes/noise-sensors-simulate.js.map +1 -1
  97. package/lib/seam/connect/routes/noise-sensors.d.ts +2 -0
  98. package/lib/seam/connect/routes/noise-sensors.js +5 -1
  99. package/lib/seam/connect/routes/noise-sensors.js.map +1 -1
  100. package/lib/seam/connect/routes/phones-simulate.d.ts +2 -0
  101. package/lib/seam/connect/routes/phones-simulate.js +5 -1
  102. package/lib/seam/connect/routes/phones-simulate.js.map +1 -1
  103. package/lib/seam/connect/routes/phones.d.ts +6 -0
  104. package/lib/seam/connect/routes/phones.js +14 -2
  105. package/lib/seam/connect/routes/phones.js.map +1 -1
  106. package/lib/seam/connect/routes/thermostats-schedules.d.ts +2 -0
  107. package/lib/seam/connect/routes/thermostats-schedules.js +9 -5
  108. package/lib/seam/connect/routes/thermostats-schedules.js.map +1 -1
  109. package/lib/seam/connect/routes/thermostats-simulate.d.ts +2 -0
  110. package/lib/seam/connect/routes/thermostats-simulate.js +6 -2
  111. package/lib/seam/connect/routes/thermostats-simulate.js.map +1 -1
  112. package/lib/seam/connect/routes/thermostats.d.ts +2 -0
  113. package/lib/seam/connect/routes/thermostats.js +18 -14
  114. package/lib/seam/connect/routes/thermostats.js.map +1 -1
  115. package/lib/seam/connect/routes/user-identities-enrollment-automations.d.ts +2 -0
  116. package/lib/seam/connect/routes/user-identities-enrollment-automations.js +8 -4
  117. package/lib/seam/connect/routes/user-identities-enrollment-automations.js.map +1 -1
  118. package/lib/seam/connect/routes/user-identities.d.ts +2 -0
  119. package/lib/seam/connect/routes/user-identities.js +16 -12
  120. package/lib/seam/connect/routes/user-identities.js.map +1 -1
  121. package/lib/seam/connect/routes/webhooks.d.ts +2 -0
  122. package/lib/seam/connect/routes/webhooks.js +9 -5
  123. package/lib/seam/connect/routes/webhooks.js.map +1 -1
  124. package/lib/seam/connect/routes/workspaces.d.ts +2 -0
  125. package/lib/seam/connect/routes/workspaces.js +8 -4
  126. package/lib/seam/connect/routes/workspaces.js.map +1 -1
  127. package/lib/seam/connect/seam-http-request.d.ts +6 -3
  128. package/lib/seam/connect/seam-http-request.js +25 -14
  129. package/lib/seam/connect/seam-http-request.js.map +1 -1
  130. package/lib/seam/connect/seam-http.d.ts +3 -0
  131. package/lib/seam/connect/seam-http.js +4 -0
  132. package/lib/seam/connect/seam-http.js.map +1 -1
  133. package/lib/seam/connect/seam-paginator.d.ts +30 -0
  134. package/lib/seam/connect/seam-paginator.js +103 -0
  135. package/lib/seam/connect/seam-paginator.js.map +1 -0
  136. package/lib/version.d.ts +1 -1
  137. package/lib/version.js +1 -1
  138. package/package.json +4 -4
  139. package/src/lib/seam/connect/index.ts +2 -0
  140. package/src/lib/seam/connect/routes/access-codes-simulate.ts +8 -1
  141. package/src/lib/seam/connect/routes/access-codes-unmanaged.ts +12 -5
  142. package/src/lib/seam/connect/routes/access-codes.ts +16 -9
  143. package/src/lib/seam/connect/routes/acs-access-groups-unmanaged.ts +9 -2
  144. package/src/lib/seam/connect/routes/acs-access-groups.ts +13 -6
  145. package/src/lib/seam/connect/routes/acs-credential-pools.ts +8 -1
  146. package/src/lib/seam/connect/routes/acs-credential-provisioning-automations.ts +8 -1
  147. package/src/lib/seam/connect/routes/acs-credentials-unmanaged.ts +9 -2
  148. package/src/lib/seam/connect/routes/acs-credentials.ts +16 -9
  149. package/src/lib/seam/connect/routes/acs-encoders-simulate.ts +11 -4
  150. package/src/lib/seam/connect/routes/acs-encoders.ts +10 -3
  151. package/src/lib/seam/connect/routes/acs-entrances.ts +11 -4
  152. package/src/lib/seam/connect/routes/acs-systems.ts +10 -3
  153. package/src/lib/seam/connect/routes/acs-users-unmanaged.ts +9 -2
  154. package/src/lib/seam/connect/routes/acs-users.ts +18 -11
  155. package/src/lib/seam/connect/routes/acs.ts +8 -0
  156. package/src/lib/seam/connect/routes/action-attempts.ts +9 -2
  157. package/src/lib/seam/connect/routes/bridges.ts +9 -2
  158. package/src/lib/seam/connect/routes/client-sessions.ts +14 -7
  159. package/src/lib/seam/connect/routes/connect-webviews.ts +11 -4
  160. package/src/lib/seam/connect/routes/connected-accounts.ts +11 -4
  161. package/src/lib/seam/connect/routes/devices-simulate.ts +10 -3
  162. package/src/lib/seam/connect/routes/devices-unmanaged.ts +10 -3
  163. package/src/lib/seam/connect/routes/devices.ts +12 -5
  164. package/src/lib/seam/connect/routes/events.ts +9 -2
  165. package/src/lib/seam/connect/routes/locks.ts +11 -4
  166. package/src/lib/seam/connect/routes/networks.ts +9 -2
  167. package/src/lib/seam/connect/routes/noise-sensors-noise-thresholds.ts +12 -5
  168. package/src/lib/seam/connect/routes/noise-sensors-simulate.ts +8 -1
  169. package/src/lib/seam/connect/routes/noise-sensors.ts +8 -1
  170. package/src/lib/seam/connect/routes/phones-simulate.ts +8 -1
  171. package/src/lib/seam/connect/routes/phones.ts +26 -2
  172. package/src/lib/seam/connect/routes/thermostats-schedules.ts +12 -5
  173. package/src/lib/seam/connect/routes/thermostats-simulate.ts +9 -2
  174. package/src/lib/seam/connect/routes/thermostats.ts +21 -14
  175. package/src/lib/seam/connect/routes/user-identities-enrollment-automations.ts +11 -4
  176. package/src/lib/seam/connect/routes/user-identities.ts +19 -12
  177. package/src/lib/seam/connect/routes/webhooks.ts +12 -5
  178. package/src/lib/seam/connect/routes/workspaces.ts +11 -4
  179. package/src/lib/seam/connect/seam-http-request.ts +45 -23
  180. package/src/lib/seam/connect/seam-http.ts +8 -0
  181. package/src/lib/seam/connect/seam-paginator.ts +155 -0
  182. package/src/lib/version.ts +1 -1
@@ -31,6 +31,7 @@ import {
31
31
  parseOptions,
32
32
  } from 'lib/seam/connect/parse-options.js'
33
33
  import { SeamHttpRequest } from 'lib/seam/connect/seam-http-request.js'
34
+ import { SeamPaginator } from 'lib/seam/connect/seam-paginator.js'
34
35
  import type { SetNonNullable } from 'lib/types.js'
35
36
 
36
37
  import { SeamHttpClientSessions } from './client-sessions.js'
@@ -136,6 +137,12 @@ export class SeamHttpUserIdentities {
136
137
  return new SeamHttpUserIdentities(constructorOptions)
137
138
  }
138
139
 
140
+ createPaginator<const TResponse, const TResponseKey extends keyof TResponse>(
141
+ request: SeamHttpRequest<TResponse, TResponseKey>,
142
+ ): SeamPaginator<TResponse, TResponseKey> {
143
+ return new SeamPaginator<TResponse, TResponseKey>(this, request)
144
+ }
145
+
139
146
  async updateClientSessionToken(
140
147
  clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'],
141
148
  ): Promise<void> {
@@ -166,7 +173,7 @@ export class SeamHttpUserIdentities {
166
173
  body?: UserIdentitiesAddAcsUserBody,
167
174
  ): SeamHttpRequest<void, undefined> {
168
175
  return new SeamHttpRequest(this, {
169
- path: '/user_identities/add_acs_user',
176
+ pathname: '/user_identities/add_acs_user',
170
177
  method: 'post',
171
178
  body,
172
179
  responseKey: undefined,
@@ -177,7 +184,7 @@ export class SeamHttpUserIdentities {
177
184
  body?: UserIdentitiesCreateBody,
178
185
  ): SeamHttpRequest<UserIdentitiesCreateResponse, 'user_identity'> {
179
186
  return new SeamHttpRequest(this, {
180
- path: '/user_identities/create',
187
+ pathname: '/user_identities/create',
181
188
  method: 'post',
182
189
  body,
183
190
  responseKey: 'user_identity',
@@ -186,7 +193,7 @@ export class SeamHttpUserIdentities {
186
193
 
187
194
  delete(body?: UserIdentitiesDeleteParams): SeamHttpRequest<void, undefined> {
188
195
  return new SeamHttpRequest(this, {
189
- path: '/user_identities/delete',
196
+ pathname: '/user_identities/delete',
190
197
  method: 'post',
191
198
  body,
192
199
  responseKey: undefined,
@@ -197,7 +204,7 @@ export class SeamHttpUserIdentities {
197
204
  body?: UserIdentitiesGetParams,
198
205
  ): SeamHttpRequest<UserIdentitiesGetResponse, 'user_identity'> {
199
206
  return new SeamHttpRequest(this, {
200
- path: '/user_identities/get',
207
+ pathname: '/user_identities/get',
201
208
  method: 'post',
202
209
  body,
203
210
  responseKey: 'user_identity',
@@ -208,7 +215,7 @@ export class SeamHttpUserIdentities {
208
215
  body?: UserIdentitiesGrantAccessToDeviceBody,
209
216
  ): SeamHttpRequest<void, undefined> {
210
217
  return new SeamHttpRequest(this, {
211
- path: '/user_identities/grant_access_to_device',
218
+ pathname: '/user_identities/grant_access_to_device',
212
219
  method: 'post',
213
220
  body,
214
221
  responseKey: undefined,
@@ -219,7 +226,7 @@ export class SeamHttpUserIdentities {
219
226
  body?: UserIdentitiesListParams,
220
227
  ): SeamHttpRequest<UserIdentitiesListResponse, 'user_identities'> {
221
228
  return new SeamHttpRequest(this, {
222
- path: '/user_identities/list',
229
+ pathname: '/user_identities/list',
223
230
  method: 'post',
224
231
  body,
225
232
  responseKey: 'user_identities',
@@ -230,7 +237,7 @@ export class SeamHttpUserIdentities {
230
237
  body?: UserIdentitiesListAccessibleDevicesParams,
231
238
  ): SeamHttpRequest<UserIdentitiesListAccessibleDevicesResponse, 'devices'> {
232
239
  return new SeamHttpRequest(this, {
233
- path: '/user_identities/list_accessible_devices',
240
+ pathname: '/user_identities/list_accessible_devices',
234
241
  method: 'post',
235
242
  body,
236
243
  responseKey: 'devices',
@@ -241,7 +248,7 @@ export class SeamHttpUserIdentities {
241
248
  body?: UserIdentitiesListAcsSystemsParams,
242
249
  ): SeamHttpRequest<UserIdentitiesListAcsSystemsResponse, 'acs_systems'> {
243
250
  return new SeamHttpRequest(this, {
244
- path: '/user_identities/list_acs_systems',
251
+ pathname: '/user_identities/list_acs_systems',
245
252
  method: 'post',
246
253
  body,
247
254
  responseKey: 'acs_systems',
@@ -252,7 +259,7 @@ export class SeamHttpUserIdentities {
252
259
  body?: UserIdentitiesListAcsUsersParams,
253
260
  ): SeamHttpRequest<UserIdentitiesListAcsUsersResponse, 'acs_users'> {
254
261
  return new SeamHttpRequest(this, {
255
- path: '/user_identities/list_acs_users',
262
+ pathname: '/user_identities/list_acs_users',
256
263
  method: 'post',
257
264
  body,
258
265
  responseKey: 'acs_users',
@@ -263,7 +270,7 @@ export class SeamHttpUserIdentities {
263
270
  body?: UserIdentitiesRemoveAcsUserParams,
264
271
  ): SeamHttpRequest<void, undefined> {
265
272
  return new SeamHttpRequest(this, {
266
- path: '/user_identities/remove_acs_user',
273
+ pathname: '/user_identities/remove_acs_user',
267
274
  method: 'post',
268
275
  body,
269
276
  responseKey: undefined,
@@ -274,7 +281,7 @@ export class SeamHttpUserIdentities {
274
281
  body?: UserIdentitiesRevokeAccessToDeviceParams,
275
282
  ): SeamHttpRequest<void, undefined> {
276
283
  return new SeamHttpRequest(this, {
277
- path: '/user_identities/revoke_access_to_device',
284
+ pathname: '/user_identities/revoke_access_to_device',
278
285
  method: 'post',
279
286
  body,
280
287
  responseKey: undefined,
@@ -283,7 +290,7 @@ export class SeamHttpUserIdentities {
283
290
 
284
291
  update(body?: UserIdentitiesUpdateBody): SeamHttpRequest<void, undefined> {
285
292
  return new SeamHttpRequest(this, {
286
- path: '/user_identities/update',
293
+ pathname: '/user_identities/update',
287
294
  method: 'post',
288
295
  body,
289
296
  responseKey: undefined,
@@ -31,6 +31,7 @@ import {
31
31
  parseOptions,
32
32
  } from 'lib/seam/connect/parse-options.js'
33
33
  import { SeamHttpRequest } from 'lib/seam/connect/seam-http-request.js'
34
+ import { SeamPaginator } from 'lib/seam/connect/seam-paginator.js'
34
35
  import type { SetNonNullable } from 'lib/types.js'
35
36
 
36
37
  import { SeamHttpClientSessions } from './client-sessions.js'
@@ -135,6 +136,12 @@ export class SeamHttpWebhooks {
135
136
  return new SeamHttpWebhooks(constructorOptions)
136
137
  }
137
138
 
139
+ createPaginator<const TResponse, const TResponseKey extends keyof TResponse>(
140
+ request: SeamHttpRequest<TResponse, TResponseKey>,
141
+ ): SeamPaginator<TResponse, TResponseKey> {
142
+ return new SeamPaginator<TResponse, TResponseKey>(this, request)
143
+ }
144
+
138
145
  async updateClientSessionToken(
139
146
  clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'],
140
147
  ): Promise<void> {
@@ -158,7 +165,7 @@ export class SeamHttpWebhooks {
158
165
  body?: WebhooksCreateBody,
159
166
  ): SeamHttpRequest<WebhooksCreateResponse, 'webhook'> {
160
167
  return new SeamHttpRequest(this, {
161
- path: '/webhooks/create',
168
+ pathname: '/webhooks/create',
162
169
  method: 'post',
163
170
  body,
164
171
  responseKey: 'webhook',
@@ -167,7 +174,7 @@ export class SeamHttpWebhooks {
167
174
 
168
175
  delete(body?: WebhooksDeleteParams): SeamHttpRequest<void, undefined> {
169
176
  return new SeamHttpRequest(this, {
170
- path: '/webhooks/delete',
177
+ pathname: '/webhooks/delete',
171
178
  method: 'post',
172
179
  body,
173
180
  responseKey: undefined,
@@ -178,7 +185,7 @@ export class SeamHttpWebhooks {
178
185
  body?: WebhooksGetParams,
179
186
  ): SeamHttpRequest<WebhooksGetResponse, 'webhook'> {
180
187
  return new SeamHttpRequest(this, {
181
- path: '/webhooks/get',
188
+ pathname: '/webhooks/get',
182
189
  method: 'post',
183
190
  body,
184
191
  responseKey: 'webhook',
@@ -189,7 +196,7 @@ export class SeamHttpWebhooks {
189
196
  body?: WebhooksListParams,
190
197
  ): SeamHttpRequest<WebhooksListResponse, 'webhooks'> {
191
198
  return new SeamHttpRequest(this, {
192
- path: '/webhooks/list',
199
+ pathname: '/webhooks/list',
193
200
  method: 'post',
194
201
  body,
195
202
  responseKey: 'webhooks',
@@ -198,7 +205,7 @@ export class SeamHttpWebhooks {
198
205
 
199
206
  update(body?: WebhooksUpdateBody): SeamHttpRequest<void, undefined> {
200
207
  return new SeamHttpRequest(this, {
201
- path: '/webhooks/update',
208
+ pathname: '/webhooks/update',
202
209
  method: 'post',
203
210
  body,
204
211
  responseKey: undefined,
@@ -31,6 +31,7 @@ import {
31
31
  parseOptions,
32
32
  } from 'lib/seam/connect/parse-options.js'
33
33
  import { SeamHttpRequest } from 'lib/seam/connect/seam-http-request.js'
34
+ import { SeamPaginator } from 'lib/seam/connect/seam-paginator.js'
34
35
  import type { SetNonNullable } from 'lib/types.js'
35
36
 
36
37
  import { SeamHttpClientSessions } from './client-sessions.js'
@@ -135,6 +136,12 @@ export class SeamHttpWorkspaces {
135
136
  return new SeamHttpWorkspaces(constructorOptions)
136
137
  }
137
138
 
139
+ createPaginator<const TResponse, const TResponseKey extends keyof TResponse>(
140
+ request: SeamHttpRequest<TResponse, TResponseKey>,
141
+ ): SeamPaginator<TResponse, TResponseKey> {
142
+ return new SeamPaginator<TResponse, TResponseKey>(this, request)
143
+ }
144
+
138
145
  async updateClientSessionToken(
139
146
  clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'],
140
147
  ): Promise<void> {
@@ -158,7 +165,7 @@ export class SeamHttpWorkspaces {
158
165
  body?: WorkspacesCreateBody,
159
166
  ): SeamHttpRequest<WorkspacesCreateResponse, 'workspace'> {
160
167
  return new SeamHttpRequest(this, {
161
- path: '/workspaces/create',
168
+ pathname: '/workspaces/create',
162
169
  method: 'post',
163
170
  body,
164
171
  responseKey: 'workspace',
@@ -169,7 +176,7 @@ export class SeamHttpWorkspaces {
169
176
  body?: WorkspacesGetParams,
170
177
  ): SeamHttpRequest<WorkspacesGetResponse, 'workspace'> {
171
178
  return new SeamHttpRequest(this, {
172
- path: '/workspaces/get',
179
+ pathname: '/workspaces/get',
173
180
  method: 'post',
174
181
  body,
175
182
  responseKey: 'workspace',
@@ -180,7 +187,7 @@ export class SeamHttpWorkspaces {
180
187
  body?: WorkspacesListParams,
181
188
  ): SeamHttpRequest<WorkspacesListResponse, 'workspaces'> {
182
189
  return new SeamHttpRequest(this, {
183
- path: '/workspaces/list',
190
+ pathname: '/workspaces/list',
184
191
  method: 'post',
185
192
  body,
186
193
  responseKey: 'workspaces',
@@ -192,7 +199,7 @@ export class SeamHttpWorkspaces {
192
199
  options: Pick<SeamHttpRequestOptions, 'waitForActionAttempt'> = {},
193
200
  ): SeamHttpRequest<WorkspacesResetSandboxResponse, 'action_attempt'> {
194
201
  return new SeamHttpRequest(this, {
195
- path: '/workspaces/reset_sandbox',
202
+ pathname: '/workspaces/reset_sandbox',
196
203
  method: 'post',
197
204
  body,
198
205
  responseKey: 'action_attempt',
@@ -1,3 +1,4 @@
1
+ import type { ActionAttempt } from '@seamapi/types/connect'
1
2
  import { serializeUrlSearchParams } from '@seamapi/url-search-params-serializer'
2
3
  import type { Method } from 'axios'
3
4
 
@@ -12,7 +13,7 @@ interface SeamHttpRequestParent {
12
13
  }
13
14
 
14
15
  interface SeamHttpRequestConfig<TResponseKey> {
15
- readonly path: string
16
+ readonly pathname: string
16
17
  readonly method: Method
17
18
  readonly body?: unknown
18
19
  readonly params?: undefined | Record<string, unknown>
@@ -47,7 +48,6 @@ export class SeamHttpRequest<
47
48
 
48
49
  public get url(): URL {
49
50
  const { client } = this.#parent
50
- const { params } = this.#config
51
51
 
52
52
  const serializer =
53
53
  typeof client.defaults.paramsSerializer === 'function'
@@ -56,19 +56,28 @@ export class SeamHttpRequest<
56
56
 
57
57
  const origin = getUrlPrefix(client.defaults.baseURL ?? '')
58
58
 
59
- const pathname = this.#config.path.startsWith('/')
60
- ? this.#config.path
61
- : `/${this.#config.path}`
62
-
63
- const path = params == null ? pathname : `${pathname}?${serializer(params)}`
59
+ const path =
60
+ this.params == null
61
+ ? this.pathname
62
+ : `${this.pathname}?${serializer(this.params)}`
64
63
 
65
64
  return new URL(`${origin}${path}`)
66
65
  }
67
66
 
67
+ public get pathname(): string {
68
+ return this.#config.pathname.startsWith('/')
69
+ ? this.#config.pathname
70
+ : `/${this.#config.pathname}`
71
+ }
72
+
68
73
  public get method(): Method {
69
74
  return this.#config.method
70
75
  }
71
76
 
77
+ public get params(): undefined | Record<string, unknown> {
78
+ return this.#config.params
79
+ }
80
+
72
81
  public get body(): unknown {
73
82
  return this.#config.body
74
83
  }
@@ -76,37 +85,50 @@ export class SeamHttpRequest<
76
85
  async execute(): Promise<
77
86
  TResponseKey extends keyof TResponse ? TResponse[TResponseKey] : undefined
78
87
  > {
79
- const { client } = this.#parent
80
- const response = await client.request({
81
- url: this.#config.path,
82
- method: this.#config.method,
83
- data: this.#config.body,
84
- params: this.#config.params,
85
- })
88
+ const response = await this.fetchResponse()
89
+
90
+ type Response = TResponseKey extends keyof TResponse
91
+ ? TResponse[TResponseKey]
92
+ : undefined
93
+
86
94
  if (this.responseKey === undefined) {
87
- return undefined as TResponseKey extends keyof TResponse
88
- ? TResponse[TResponseKey]
89
- : undefined
95
+ return undefined as Response
90
96
  }
91
- const data = response.data[this.responseKey]
97
+
98
+ const data = response[this.responseKey] as unknown as Response
99
+
92
100
  if (this.responseKey === 'action_attempt') {
93
101
  const waitForActionAttempt =
94
102
  this.#config.options?.waitForActionAttempt ??
95
103
  this.#parent.defaults.waitForActionAttempt
104
+
96
105
  if (waitForActionAttempt !== false) {
97
- return await resolveActionAttempt(
98
- data,
99
- SeamHttpActionAttempts.fromClient(client, {
106
+ const actionAttempt = await resolveActionAttempt(
107
+ data as unknown as ActionAttempt,
108
+ SeamHttpActionAttempts.fromClient(this.#parent.client, {
100
109
  ...this.#parent.defaults,
101
110
  waitForActionAttempt: false,
102
111
  }),
103
112
  typeof waitForActionAttempt === 'boolean' ? {} : waitForActionAttempt,
104
113
  )
114
+ return actionAttempt as Response
105
115
  }
106
116
  }
117
+
107
118
  return data
108
119
  }
109
120
 
121
+ async fetchResponse(): Promise<TResponse> {
122
+ const { client } = this.#parent
123
+ const response = await client.request({
124
+ url: this.pathname,
125
+ method: this.method,
126
+ data: this.body,
127
+ params: this.params,
128
+ })
129
+ return response.data as unknown as TResponse
130
+ }
131
+
110
132
  async then<
111
133
  TResult1 = TResponseKey extends keyof TResponse
112
134
  ? TResponse[TResponseKey]
@@ -122,7 +144,7 @@ export class SeamHttpRequest<
122
144
  | null
123
145
  | undefined,
124
146
  onrejected?:
125
- | ((reason: any) => TResult2 | PromiseLike<TResult2>)
147
+ | ((reason: unknown) => TResult2 | PromiseLike<TResult2>)
126
148
  | null
127
149
  | undefined,
128
150
  ): Promise<TResult1 | TResult2> {
@@ -131,7 +153,7 @@ export class SeamHttpRequest<
131
153
 
132
154
  async catch<TResult = never>(
133
155
  onrejected?:
134
- | ((reason: any) => TResult | PromiseLike<TResult>)
156
+ | ((reason: unknown) => TResult | PromiseLike<TResult>)
135
157
  | null
136
158
  | undefined,
137
159
  ): Promise<
@@ -40,6 +40,8 @@ import {
40
40
  SeamHttpWebhooks,
41
41
  SeamHttpWorkspaces,
42
42
  } from './routes/index.js'
43
+ import type { SeamHttpRequest } from './seam-http-request.js'
44
+ import { SeamPaginator } from './seam-paginator.js'
43
45
 
44
46
  export class SeamHttp {
45
47
  client: Client
@@ -143,6 +145,12 @@ export class SeamHttp {
143
145
  return new SeamHttp(constructorOptions)
144
146
  }
145
147
 
148
+ createPaginator<const TResponse, const TResponseKey extends keyof TResponse>(
149
+ request: SeamHttpRequest<TResponse, TResponseKey>,
150
+ ): SeamPaginator<TResponse, TResponseKey> {
151
+ return new SeamPaginator<TResponse, TResponseKey>(this, request)
152
+ }
153
+
146
154
  async updateClientSessionToken(
147
155
  clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'],
148
156
  ): Promise<void> {
@@ -0,0 +1,155 @@
1
+ import type { Client } from './client.js'
2
+ import type { SeamHttpRequestOptions } from './options.js'
3
+ import { SeamHttpRequest } from './seam-http-request.js'
4
+
5
+ interface SeamPaginatorParent {
6
+ readonly client: Client
7
+ readonly defaults: Required<SeamHttpRequestOptions>
8
+ }
9
+
10
+ declare const $brand: unique symbol
11
+
12
+ type PageCursor = string & { [$brand]: 'SeamPageCursor' }
13
+
14
+ interface Pagination {
15
+ readonly hasNextPage: boolean
16
+ readonly nextPageCursor: PageCursor | null
17
+ readonly nextPageUrl: string | null
18
+ }
19
+
20
+ export class SeamPaginator<
21
+ const TResponse,
22
+ const TResponseKey extends keyof TResponse,
23
+ > implements AsyncIterable<EnsureReadonlyArray<TResponse[TResponseKey]>>
24
+ {
25
+ readonly #request: SeamHttpRequest<TResponse, TResponseKey>
26
+ readonly #parent: SeamPaginatorParent
27
+
28
+ constructor(
29
+ parent: SeamPaginatorParent,
30
+ request: SeamHttpRequest<TResponse, TResponseKey>,
31
+ ) {
32
+ if (request.responseKey == null) {
33
+ throw new Error(
34
+ `The ${request.pathname} endpoint does not support pagination`,
35
+ )
36
+ }
37
+ this.#parent = parent
38
+ this.#request = request
39
+ }
40
+
41
+ async firstPage(): Promise<
42
+ [EnsureReadonlyArray<TResponse[TResponseKey]>, Pagination]
43
+ > {
44
+ return await this.#fetch()
45
+ }
46
+
47
+ async nextPage(
48
+ nextPageCursor: Pagination['nextPageCursor'],
49
+ ): Promise<[EnsureReadonlyArray<TResponse[TResponseKey]>, Pagination]> {
50
+ if (nextPageCursor == null) {
51
+ throw new Error('Cannot get the next page with a null nextPageCursor')
52
+ }
53
+
54
+ return await this.#fetch(nextPageCursor)
55
+ }
56
+
57
+ async #fetch(
58
+ nextPageCursor?: Pagination['nextPageCursor'],
59
+ ): Promise<[EnsureReadonlyArray<TResponse[TResponseKey]>, Pagination]> {
60
+ const responseKey = this.#request.responseKey
61
+
62
+ if (responseKey == null) {
63
+ throw new Error('Cannot paginate a response without a responseKey')
64
+ }
65
+
66
+ const request = new SeamHttpRequest<TResponse, TResponseKey>(this.#parent, {
67
+ pathname: this.#request.pathname,
68
+ method: this.#request.method,
69
+ responseKey,
70
+ params:
71
+ this.#request.params != null
72
+ ? { ...this.#request.params, page_cursor: nextPageCursor }
73
+ : undefined,
74
+ body:
75
+ this.#request.body != null
76
+ ? { ...this.#request.body, page_cursor: nextPageCursor }
77
+ : undefined,
78
+ })
79
+
80
+ const response = await request.fetchResponse()
81
+ const data = response[responseKey]
82
+
83
+ const paginationData =
84
+ response != null &&
85
+ typeof response === 'object' &&
86
+ 'pagination' in response
87
+ ? (response.pagination as PaginationData)
88
+ : null
89
+
90
+ const pagination: Pagination = {
91
+ hasNextPage: paginationData?.has_next_page ?? false,
92
+ nextPageCursor: paginationData?.next_page_cursor ?? null,
93
+ nextPageUrl: paginationData?.next_page_url ?? null,
94
+ }
95
+
96
+ if (!Array.isArray(data)) {
97
+ throw new Error(
98
+ `Expected an array response for ${String(responseKey)} but got ${String(typeof data)}`,
99
+ )
100
+ }
101
+
102
+ return [
103
+ data as EnsureReadonlyArray<TResponse[TResponseKey]>,
104
+ pagination,
105
+ ] as const
106
+ }
107
+
108
+ async flattenToArray(): Promise<
109
+ EnsureReadonlyArray<TResponse[TResponseKey]>
110
+ > {
111
+ const items = [] as EnsureMutableArray<TResponse[TResponseKey]>
112
+ let [current, pagination] = await this.firstPage()
113
+ items.push(...current)
114
+ while (pagination.hasNextPage) {
115
+ ;[current, pagination] = await this.nextPage(pagination.nextPageCursor)
116
+ items.push(...current)
117
+ }
118
+ return items as EnsureReadonlyArray<TResponse[TResponseKey]>
119
+ }
120
+
121
+ async *flatten(): AsyncGenerator<
122
+ EnsureReadonlyArray<TResponse[TResponseKey]>
123
+ > {
124
+ let [current, pagination] = await this.firstPage()
125
+ for (const item of current) {
126
+ yield item
127
+ }
128
+ while (pagination.hasNextPage) {
129
+ ;[current, pagination] = await this.nextPage(pagination.nextPageCursor)
130
+ for (const item of current) {
131
+ yield item
132
+ }
133
+ }
134
+ }
135
+
136
+ async *[Symbol.asyncIterator](): AsyncGenerator<
137
+ EnsureReadonlyArray<TResponse[TResponseKey]>
138
+ > {
139
+ let [current, pagination] = await this.firstPage()
140
+ yield current
141
+ while (pagination.hasNextPage) {
142
+ ;[current, pagination] = await this.nextPage(pagination.nextPageCursor)
143
+ yield current
144
+ }
145
+ }
146
+ }
147
+
148
+ type EnsureReadonlyArray<T> = T extends readonly any[] ? T : never
149
+ type EnsureMutableArray<T> = T extends any[] ? T : never
150
+
151
+ interface PaginationData {
152
+ has_next_page: boolean
153
+ next_page_cursor: PageCursor | null
154
+ next_page_url: string | null
155
+ }
@@ -1,3 +1,3 @@
1
- const seamapiJavascriptHttpVersion = '1.23.0'
1
+ const seamapiJavascriptHttpVersion = '1.25.0'
2
2
 
3
3
  export default seamapiJavascriptHttpVersion