@seamapi/http 2.24.0 → 2.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.
- package/README.md +37 -0
- package/lib/error-interceptor.js +2 -2
- package/lib/error-interceptor.js.map +1 -1
- package/lib/resources/access-grant.d.ts +1 -1
- package/lib/resources/event.d.ts +9 -4
- package/lib/routes/access-codes/access-codes.js +2 -2
- package/lib/routes/access-codes/access-codes.js.map +1 -1
- package/lib/routes/access-codes/simulate/simulate.js +1 -1
- package/lib/routes/access-codes/simulate/simulate.js.map +1 -1
- package/lib/routes/access-codes/unmanaged/unmanaged.js +1 -1
- package/lib/routes/access-codes/unmanaged/unmanaged.js.map +1 -1
- package/lib/routes/access-grants/access-grants.d.ts +25 -25
- package/lib/routes/access-grants/access-grants.js +1 -1
- package/lib/routes/access-grants/access-grants.js.map +1 -1
- package/lib/routes/access-grants/unmanaged/unmanaged.js +1 -1
- package/lib/routes/access-grants/unmanaged/unmanaged.js.map +1 -1
- package/lib/routes/access-methods/access-methods.d.ts +5 -5
- package/lib/routes/access-methods/access-methods.js +2 -2
- package/lib/routes/access-methods/access-methods.js.map +1 -1
- package/lib/routes/access-methods/unmanaged/unmanaged.js +1 -1
- package/lib/routes/access-methods/unmanaged/unmanaged.js.map +1 -1
- package/lib/routes/acs/access-groups/access-groups.js +1 -1
- package/lib/routes/acs/access-groups/access-groups.js.map +1 -1
- package/lib/routes/acs/acs.js +1 -1
- package/lib/routes/acs/acs.js.map +1 -1
- package/lib/routes/acs/credentials/credentials.js +1 -1
- package/lib/routes/acs/credentials/credentials.js.map +1 -1
- package/lib/routes/acs/encoders/encoders.js +1 -1
- package/lib/routes/acs/encoders/encoders.js.map +1 -1
- package/lib/routes/acs/encoders/simulate/simulate.d.ts +5 -5
- package/lib/routes/acs/encoders/simulate/simulate.js +1 -1
- package/lib/routes/acs/encoders/simulate/simulate.js.map +1 -1
- package/lib/routes/acs/entrances/entrances.js +1 -1
- package/lib/routes/acs/entrances/entrances.js.map +1 -1
- package/lib/routes/acs/systems/systems.js +1 -1
- package/lib/routes/acs/systems/systems.js.map +1 -1
- package/lib/routes/acs/users/users.js +1 -1
- package/lib/routes/acs/users/users.js.map +1 -1
- package/lib/routes/action-attempts/action-attempts.js +1 -1
- package/lib/routes/action-attempts/action-attempts.js.map +1 -1
- package/lib/routes/client-sessions/client-sessions.js +1 -1
- package/lib/routes/client-sessions/client-sessions.js.map +1 -1
- package/lib/routes/connect-webviews/connect-webviews.js +1 -1
- package/lib/routes/connect-webviews/connect-webviews.js.map +1 -1
- package/lib/routes/connected-accounts/connected-accounts.js +1 -1
- package/lib/routes/connected-accounts/connected-accounts.js.map +1 -1
- package/lib/routes/connected-accounts/simulate/simulate.js +1 -1
- package/lib/routes/connected-accounts/simulate/simulate.js.map +1 -1
- package/lib/routes/customers/customers.d.ts +185 -185
- package/lib/routes/customers/customers.js +1 -1
- package/lib/routes/customers/customers.js.map +1 -1
- package/lib/routes/devices/devices.js +1 -1
- package/lib/routes/devices/devices.js.map +1 -1
- package/lib/routes/devices/simulate/simulate.js +1 -1
- package/lib/routes/devices/simulate/simulate.js.map +1 -1
- package/lib/routes/devices/unmanaged/unmanaged.js +1 -1
- package/lib/routes/devices/unmanaged/unmanaged.js.map +1 -1
- package/lib/routes/events/events.js +1 -1
- package/lib/routes/events/events.js.map +1 -1
- package/lib/routes/instant-keys/instant-keys.js +1 -1
- package/lib/routes/instant-keys/instant-keys.js.map +1 -1
- package/lib/routes/locks/locks.js +1 -1
- package/lib/routes/locks/locks.js.map +1 -1
- package/lib/routes/locks/simulate/simulate.js +1 -1
- package/lib/routes/locks/simulate/simulate.js.map +1 -1
- package/lib/routes/noise-sensors/noise-sensors.js +1 -1
- package/lib/routes/noise-sensors/noise-sensors.js.map +1 -1
- package/lib/routes/noise-sensors/noise-thresholds/noise-thresholds.js +2 -2
- package/lib/routes/noise-sensors/noise-thresholds/noise-thresholds.js.map +1 -1
- package/lib/routes/noise-sensors/simulate/simulate.js +1 -1
- package/lib/routes/noise-sensors/simulate/simulate.js.map +1 -1
- package/lib/routes/phones/phones.js +1 -1
- package/lib/routes/phones/phones.js.map +1 -1
- package/lib/routes/phones/simulate/simulate.js +1 -1
- package/lib/routes/phones/simulate/simulate.js.map +1 -1
- package/lib/routes/seam-http-endpoints.js +1 -1
- package/lib/routes/seam-http-endpoints.js.map +1 -1
- package/lib/routes/seam-http.js +1 -1
- package/lib/routes/seam-http.js.map +1 -1
- package/lib/routes/spaces/spaces.js +1 -1
- package/lib/routes/spaces/spaces.js.map +1 -1
- package/lib/routes/thermostats/daily-programs/daily-programs.js +1 -1
- package/lib/routes/thermostats/daily-programs/daily-programs.js.map +1 -1
- package/lib/routes/thermostats/schedules/schedules.js +1 -1
- package/lib/routes/thermostats/schedules/schedules.js.map +1 -1
- package/lib/routes/thermostats/simulate/simulate.d.ts +8 -8
- package/lib/routes/thermostats/simulate/simulate.js +1 -1
- package/lib/routes/thermostats/simulate/simulate.js.map +1 -1
- package/lib/routes/thermostats/thermostats.d.ts +5 -5
- package/lib/routes/thermostats/thermostats.js +1 -1
- package/lib/routes/thermostats/thermostats.js.map +1 -1
- package/lib/routes/user-identities/unmanaged/unmanaged.js +1 -1
- package/lib/routes/user-identities/unmanaged/unmanaged.js.map +1 -1
- package/lib/routes/user-identities/user-identities.d.ts +5 -5
- package/lib/routes/user-identities/user-identities.js +2 -2
- package/lib/routes/user-identities/user-identities.js.map +1 -1
- package/lib/routes/webhooks/webhooks.js +1 -1
- package/lib/routes/webhooks/webhooks.js.map +1 -1
- package/lib/routes/workspaces/workspaces.d.ts +1 -1
- package/lib/routes/workspaces/workspaces.js +1 -1
- package/lib/routes/workspaces/workspaces.js.map +1 -1
- package/lib/seam-http-error.d.ts +16 -3
- package/lib/seam-http-error.js +18 -6
- package/lib/seam-http-error.js.map +1 -1
- package/lib/seam-http-request.d.ts +4 -0
- package/lib/seam-http-request.js +18 -0
- package/lib/seam-http-request.js.map +1 -1
- package/lib/seam-paginator.d.ts +1 -7
- package/lib/seam-paginator.js +3 -19
- package/lib/seam-paginator.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +3 -3
- package/src/lib/error-interceptor.ts +6 -2
- package/src/lib/resources/access-grant.ts +1 -1
- package/src/lib/resources/event.ts +10 -5
- package/src/lib/routes/access-codes/access-codes.ts +2 -2
- package/src/lib/routes/access-codes/simulate/simulate.ts +1 -1
- package/src/lib/routes/access-codes/unmanaged/unmanaged.ts +1 -1
- package/src/lib/routes/access-grants/access-grants.ts +28 -28
- package/src/lib/routes/access-grants/unmanaged/unmanaged.ts +1 -1
- package/src/lib/routes/access-methods/access-methods.ts +7 -7
- package/src/lib/routes/access-methods/unmanaged/unmanaged.ts +1 -1
- package/src/lib/routes/acs/access-groups/access-groups.ts +1 -1
- package/src/lib/routes/acs/acs.ts +1 -1
- package/src/lib/routes/acs/credentials/credentials.ts +1 -1
- package/src/lib/routes/acs/encoders/encoders.ts +1 -1
- package/src/lib/routes/acs/encoders/simulate/simulate.ts +6 -7
- package/src/lib/routes/acs/entrances/entrances.ts +1 -1
- package/src/lib/routes/acs/systems/systems.ts +1 -1
- package/src/lib/routes/acs/users/users.ts +1 -1
- package/src/lib/routes/action-attempts/action-attempts.ts +1 -1
- package/src/lib/routes/client-sessions/client-sessions.ts +1 -1
- package/src/lib/routes/connect-webviews/connect-webviews.ts +1 -1
- package/src/lib/routes/connected-accounts/connected-accounts.ts +1 -1
- package/src/lib/routes/connected-accounts/simulate/simulate.ts +1 -1
- package/src/lib/routes/customers/customers.ts +236 -237
- package/src/lib/routes/devices/devices.ts +1 -1
- package/src/lib/routes/devices/simulate/simulate.ts +1 -1
- package/src/lib/routes/devices/unmanaged/unmanaged.ts +1 -1
- package/src/lib/routes/events/events.ts +1 -1
- package/src/lib/routes/instant-keys/instant-keys.ts +1 -1
- package/src/lib/routes/locks/locks.ts +1 -1
- package/src/lib/routes/locks/simulate/simulate.ts +1 -1
- package/src/lib/routes/noise-sensors/noise-sensors.ts +1 -1
- package/src/lib/routes/noise-sensors/noise-thresholds/noise-thresholds.ts +2 -2
- package/src/lib/routes/noise-sensors/simulate/simulate.ts +1 -1
- package/src/lib/routes/phones/phones.ts +1 -1
- package/src/lib/routes/phones/simulate/simulate.ts +1 -1
- package/src/lib/routes/seam-http-endpoints.ts +1 -1
- package/src/lib/routes/seam-http.ts +1 -1
- package/src/lib/routes/spaces/spaces.ts +1 -1
- package/src/lib/routes/thermostats/daily-programs/daily-programs.ts +1 -1
- package/src/lib/routes/thermostats/schedules/schedules.ts +1 -1
- package/src/lib/routes/thermostats/simulate/simulate.ts +10 -11
- package/src/lib/routes/thermostats/thermostats.ts +8 -8
- package/src/lib/routes/user-identities/unmanaged/unmanaged.ts +1 -1
- package/src/lib/routes/user-identities/user-identities.ts +7 -7
- package/src/lib/routes/webhooks/webhooks.ts +1 -1
- package/src/lib/routes/workspaces/workspaces.ts +2 -2
- package/src/lib/seam-http-error.ts +43 -6
- package/src/lib/seam-http-request.ts +23 -0
- package/src/lib/seam-paginator.ts +2 -33
- package/src/lib/version.ts +1 -1
|
@@ -138,7 +138,7 @@ export class SeamHttpThermostatsSimulate {
|
|
|
138
138
|
createPaginator<const TResponse, const TResponseKey extends keyof TResponse>(
|
|
139
139
|
request: SeamPaginatedRequest<TResponse, TResponseKey>,
|
|
140
140
|
): SeamPaginator<TResponse, TResponseKey> {
|
|
141
|
-
return new SeamPaginator<TResponse, TResponseKey>(
|
|
141
|
+
return new SeamPaginator<TResponse, TResponseKey>(request)
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
async updateClientSessionToken(
|
|
@@ -202,16 +202,6 @@ export class SeamHttpThermostatsSimulate {
|
|
|
202
202
|
}
|
|
203
203
|
|
|
204
204
|
export type ThermostatsSimulateHvacModeAdjustedParameters = {
|
|
205
|
-
/**
|
|
206
|
-
* ID of the thermostat device for which you want to simulate having adjusted the HVAC mode.
|
|
207
|
-
*/
|
|
208
|
-
device_id: string
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* HVAC mode that you want to simulate.
|
|
212
|
-
*/
|
|
213
|
-
hvac_mode: 'off' | 'cool' | 'heat' | 'heat_cool'
|
|
214
|
-
|
|
215
205
|
/**
|
|
216
206
|
* Cooling [set point](https://docs.seam.co/capability-guides/thermostats/understanding-thermostat-concepts/set-points) in °C that you want to simulate. You must set `cooling_set_point_celsius` or `cooling_set_point_fahrenheit`.
|
|
217
207
|
*/
|
|
@@ -220,6 +210,11 @@ export type ThermostatsSimulateHvacModeAdjustedParameters = {
|
|
|
220
210
|
* Cooling [set point](https://docs.seam.co/capability-guides/thermostats/understanding-thermostat-concepts/set-points) in °F that you want to simulate. You must set `cooling_set_point_fahrenheit` or `cooling_set_point_celsius`.
|
|
221
211
|
*/
|
|
222
212
|
cooling_set_point_fahrenheit?: number | undefined
|
|
213
|
+
/**
|
|
214
|
+
* ID of the thermostat device for which you want to simulate having adjusted the HVAC mode.
|
|
215
|
+
*/
|
|
216
|
+
device_id: string
|
|
217
|
+
|
|
223
218
|
/**
|
|
224
219
|
* Heating [set point](https://docs.seam.co/capability-guides/thermostats/understanding-thermostat-concepts/set-points) in °C that you want to simulate. You must set `heating_set_point_celsius` or `heating_set_point_fahrenheit`.
|
|
225
220
|
*/
|
|
@@ -228,6 +223,10 @@ export type ThermostatsSimulateHvacModeAdjustedParameters = {
|
|
|
228
223
|
* Heating [set point](https://docs.seam.co/capability-guides/thermostats/understanding-thermostat-concepts/set-points) in °F that you want to simulate. You must set `heating_set_point_fahrenheit` or `heating_set_point_celsius`.
|
|
229
224
|
*/
|
|
230
225
|
heating_set_point_fahrenheit?: number | undefined
|
|
226
|
+
/**
|
|
227
|
+
* HVAC mode that you want to simulate.
|
|
228
|
+
*/
|
|
229
|
+
hvac_mode: 'off' | 'cool' | 'heat' | 'heat_cool'
|
|
231
230
|
}
|
|
232
231
|
|
|
233
232
|
/**
|
|
@@ -145,7 +145,7 @@ export class SeamHttpThermostats {
|
|
|
145
145
|
createPaginator<const TResponse, const TResponseKey extends keyof TResponse>(
|
|
146
146
|
request: SeamPaginatedRequest<TResponse, TResponseKey>,
|
|
147
147
|
): SeamPaginator<TResponse, TResponseKey> {
|
|
148
|
-
return new SeamPaginator<TResponse, TResponseKey>(
|
|
148
|
+
return new SeamPaginator<TResponse, TResponseKey>(request)
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
async updateClientSessionToken(
|
|
@@ -879,13 +879,6 @@ export type ThermostatsSetFanModeOptions = Pick<
|
|
|
879
879
|
>
|
|
880
880
|
|
|
881
881
|
export type ThermostatsSetHvacModeParameters = {
|
|
882
|
-
/**
|
|
883
|
-
* ID of the thermostat device for which you want to set the HVAC mode.
|
|
884
|
-
*/
|
|
885
|
-
device_id: string
|
|
886
|
-
|
|
887
|
-
hvac_mode_setting: 'off' | 'cool' | 'heat' | 'heat_cool' | 'eco'
|
|
888
|
-
|
|
889
882
|
/**
|
|
890
883
|
* [Cooling set point](https://docs.seam.co/capability-guides/thermostats/understanding-thermostat-concepts/set-points) in °C that you want to set for the thermostat. You must set one of the `cooling_set_point` parameters.
|
|
891
884
|
*/
|
|
@@ -894,6 +887,11 @@ export type ThermostatsSetHvacModeParameters = {
|
|
|
894
887
|
* [Cooling set point](https://docs.seam.co/capability-guides/thermostats/understanding-thermostat-concepts/set-points) in °F that you want to set for the thermostat. You must set one of the `cooling_set_point` parameters.
|
|
895
888
|
*/
|
|
896
889
|
cooling_set_point_fahrenheit?: number | undefined
|
|
890
|
+
/**
|
|
891
|
+
* ID of the thermostat device for which you want to set the HVAC mode.
|
|
892
|
+
*/
|
|
893
|
+
device_id: string
|
|
894
|
+
|
|
897
895
|
/**
|
|
898
896
|
* [Heating set point](https://docs.seam.co/capability-guides/thermostats/understanding-thermostat-concepts/set-points) in °C that you want to set for the thermostat. You must set one of the `heating_set_point` parameters.
|
|
899
897
|
*/
|
|
@@ -902,6 +900,8 @@ export type ThermostatsSetHvacModeParameters = {
|
|
|
902
900
|
* [Heating set point](https://docs.seam.co/capability-guides/thermostats/understanding-thermostat-concepts/set-points) in °F that you want to set for the thermostat. You must set one of the `heating_set_point` parameters.
|
|
903
901
|
*/
|
|
904
902
|
heating_set_point_fahrenheit?: number | undefined
|
|
903
|
+
|
|
904
|
+
hvac_mode_setting: 'off' | 'cool' | 'heat' | 'heat_cool' | 'eco'
|
|
905
905
|
}
|
|
906
906
|
|
|
907
907
|
/**
|
|
@@ -142,7 +142,7 @@ export class SeamHttpUserIdentitiesUnmanaged {
|
|
|
142
142
|
createPaginator<const TResponse, const TResponseKey extends keyof TResponse>(
|
|
143
143
|
request: SeamPaginatedRequest<TResponse, TResponseKey>,
|
|
144
144
|
): SeamPaginator<TResponse, TResponseKey> {
|
|
145
|
-
return new SeamPaginator<TResponse, TResponseKey>(
|
|
145
|
+
return new SeamPaginator<TResponse, TResponseKey>(request)
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
async updateClientSessionToken(
|
|
@@ -147,7 +147,7 @@ export class SeamHttpUserIdentities {
|
|
|
147
147
|
createPaginator<const TResponse, const TResponseKey extends keyof TResponse>(
|
|
148
148
|
request: SeamPaginatedRequest<TResponse, TResponseKey>,
|
|
149
149
|
): SeamPaginator<TResponse, TResponseKey> {
|
|
150
|
-
return new SeamPaginator<TResponse, TResponseKey>(
|
|
150
|
+
return new SeamPaginator<TResponse, TResponseKey>(request)
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
async updateClientSessionToken(
|
|
@@ -423,8 +423,8 @@ export class SeamHttpUserIdentities {
|
|
|
423
423
|
requiredParameterNames: [],
|
|
424
424
|
atLeastOneParameterNames: [
|
|
425
425
|
'merged_user_identity_ids',
|
|
426
|
-
'user_identity_id',
|
|
427
426
|
'merged_user_identity_keys',
|
|
427
|
+
'user_identity_id',
|
|
428
428
|
'user_identity_key',
|
|
429
429
|
],
|
|
430
430
|
responseKey: undefined,
|
|
@@ -772,22 +772,22 @@ export type UserIdentitiesMergeParameters = RequireAtLeastOne<
|
|
|
772
772
|
* IDs of the user identities to merge into the primary user identity. These user identities are deleted.
|
|
773
773
|
*/
|
|
774
774
|
merged_user_identity_ids?: Array<string> | undefined
|
|
775
|
-
/**
|
|
776
|
-
* ID of the primary user identity to keep.
|
|
777
|
-
*/
|
|
778
|
-
user_identity_id?: string | undefined
|
|
779
775
|
/**
|
|
780
776
|
* Keys of the user identities to merge into the primary user identity. These user identities are deleted.
|
|
781
777
|
*/
|
|
782
778
|
merged_user_identity_keys?: Array<string> | undefined
|
|
779
|
+
/**
|
|
780
|
+
* ID of the primary user identity to keep.
|
|
781
|
+
*/
|
|
782
|
+
user_identity_id?: string | undefined
|
|
783
783
|
/**
|
|
784
784
|
* Key of the primary user identity to keep.
|
|
785
785
|
*/
|
|
786
786
|
user_identity_key?: string | undefined
|
|
787
787
|
},
|
|
788
788
|
| 'merged_user_identity_ids'
|
|
789
|
-
| 'user_identity_id'
|
|
790
789
|
| 'merged_user_identity_keys'
|
|
790
|
+
| 'user_identity_id'
|
|
791
791
|
| 'user_identity_key'
|
|
792
792
|
>
|
|
793
793
|
|
|
@@ -139,7 +139,7 @@ export class SeamHttpWebhooks {
|
|
|
139
139
|
createPaginator<const TResponse, const TResponseKey extends keyof TResponse>(
|
|
140
140
|
request: SeamPaginatedRequest<TResponse, TResponseKey>,
|
|
141
141
|
): SeamPaginator<TResponse, TResponseKey> {
|
|
142
|
-
return new SeamPaginator<TResponse, TResponseKey>(
|
|
142
|
+
return new SeamPaginator<TResponse, TResponseKey>(request)
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
async updateClientSessionToken(
|
|
@@ -141,7 +141,7 @@ export class SeamHttpWorkspaces {
|
|
|
141
141
|
createPaginator<const TResponse, const TResponseKey extends keyof TResponse>(
|
|
142
142
|
request: SeamPaginatedRequest<TResponse, TResponseKey>,
|
|
143
143
|
): SeamPaginator<TResponse, TResponseKey> {
|
|
144
|
-
return new SeamPaginator<TResponse, TResponseKey>(
|
|
144
|
+
return new SeamPaginator<TResponse, TResponseKey>(request)
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
async updateClientSessionToken(
|
|
@@ -312,7 +312,7 @@ export type WorkspacesCreateParameters = {
|
|
|
312
312
|
name: string
|
|
313
313
|
|
|
314
314
|
/**
|
|
315
|
-
* ID of the organization to associate with the new workspace.
|
|
315
|
+
* ID of the organization to associate with the new workspace. If omitted, the new workspace is associated with the organization that you administer, if you administer exactly one.
|
|
316
316
|
*/
|
|
317
317
|
organization_id?: string | undefined
|
|
318
318
|
/**
|
|
@@ -22,9 +22,14 @@ export class SeamHttpApiError extends Error {
|
|
|
22
22
|
*/
|
|
23
23
|
data?: unknown
|
|
24
24
|
|
|
25
|
-
constructor(
|
|
25
|
+
constructor(
|
|
26
|
+
error: ApiError,
|
|
27
|
+
statusCode: number,
|
|
28
|
+
requestId: string,
|
|
29
|
+
options: ErrorOptions = {},
|
|
30
|
+
) {
|
|
26
31
|
const { type, message, data } = error
|
|
27
|
-
super(message)
|
|
32
|
+
super(message, options)
|
|
28
33
|
this.name = this.constructor.name
|
|
29
34
|
this.code = type
|
|
30
35
|
this.statusCode = statusCode
|
|
@@ -49,10 +54,15 @@ export class SeamHttpUnauthorizedError extends SeamHttpApiError {
|
|
|
49
54
|
override code: 'unauthorized'
|
|
50
55
|
override statusCode: 401
|
|
51
56
|
|
|
52
|
-
constructor(requestId: string) {
|
|
57
|
+
constructor(requestId: string, error?: ApiError, options: ErrorOptions = {}) {
|
|
53
58
|
const type = 'unauthorized'
|
|
54
59
|
const status = 401
|
|
55
|
-
super(
|
|
60
|
+
super(
|
|
61
|
+
error ?? { type, message: 'Unauthorized' },
|
|
62
|
+
status,
|
|
63
|
+
requestId,
|
|
64
|
+
options,
|
|
65
|
+
)
|
|
56
66
|
this.name = this.constructor.name
|
|
57
67
|
this.code = type
|
|
58
68
|
this.statusCode = status
|
|
@@ -69,6 +79,15 @@ export const isSeamHttpUnauthorizedError = (
|
|
|
69
79
|
return error instanceof SeamHttpUnauthorizedError
|
|
70
80
|
}
|
|
71
81
|
|
|
82
|
+
/**
|
|
83
|
+
* A request parameter that failed validation,
|
|
84
|
+
* along with the messages explaining why.
|
|
85
|
+
*/
|
|
86
|
+
export interface SeamValidationError {
|
|
87
|
+
parameterName: string
|
|
88
|
+
errorMessages: string[]
|
|
89
|
+
}
|
|
90
|
+
|
|
72
91
|
/**
|
|
73
92
|
* Error thrown when the Seam API returns an `invalid_input` error response.
|
|
74
93
|
*/
|
|
@@ -77,13 +96,31 @@ export class SeamHttpInvalidInputError extends SeamHttpApiError {
|
|
|
77
96
|
|
|
78
97
|
readonly #validationErrors: NonNullable<ApiError['validation_errors']>
|
|
79
98
|
|
|
80
|
-
constructor(
|
|
81
|
-
|
|
99
|
+
constructor(
|
|
100
|
+
error: ApiError,
|
|
101
|
+
statusCode: number,
|
|
102
|
+
requestId: string,
|
|
103
|
+
options: ErrorOptions = {},
|
|
104
|
+
) {
|
|
105
|
+
super(error, statusCode, requestId, options)
|
|
82
106
|
this.name = this.constructor.name
|
|
83
107
|
this.code = 'invalid_input'
|
|
84
108
|
this.#validationErrors = error.validation_errors ?? {}
|
|
85
109
|
}
|
|
86
110
|
|
|
111
|
+
/**
|
|
112
|
+
* Validation errors returned by the Seam API,
|
|
113
|
+
* one entry per request parameter that failed validation.
|
|
114
|
+
*/
|
|
115
|
+
get validationErrors(): SeamValidationError[] {
|
|
116
|
+
return Object.entries(this.#validationErrors)
|
|
117
|
+
.filter(([parameterName]) => parameterName !== '_errors')
|
|
118
|
+
.map(([parameterName, { _errors }]) => ({
|
|
119
|
+
parameterName,
|
|
120
|
+
errorMessages: _errors,
|
|
121
|
+
}))
|
|
122
|
+
}
|
|
123
|
+
|
|
87
124
|
/**
|
|
88
125
|
* Returns the validation error messages for the request parameter,
|
|
89
126
|
* or an empty array if the parameter had no validation errors.
|
|
@@ -124,6 +124,29 @@ export class SeamHttpRequest<
|
|
|
124
124
|
return this.#config.body
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
+
/**
|
|
128
|
+
* Returns a copy of this request with the page cursor set.
|
|
129
|
+
*/
|
|
130
|
+
withPageCursor(
|
|
131
|
+
pageCursor?: string,
|
|
132
|
+
): SeamHttpRequest<TResponse, TResponseKey> {
|
|
133
|
+
const usesParams = ['GET', 'DELETE'].includes(this.method.toUpperCase())
|
|
134
|
+
|
|
135
|
+
const requestData = {
|
|
136
|
+
...(usesParams
|
|
137
|
+
? (this.#config.params ?? {})
|
|
138
|
+
: ((this.#config.body as Record<string, unknown> | null) ?? {})),
|
|
139
|
+
page_cursor: pageCursor,
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return new SeamHttpRequest(this.#parent, {
|
|
143
|
+
...this.#config,
|
|
144
|
+
parameters: requestData,
|
|
145
|
+
params: usesParams ? requestData : undefined,
|
|
146
|
+
body: usesParams ? undefined : requestData,
|
|
147
|
+
})
|
|
148
|
+
}
|
|
149
|
+
|
|
127
150
|
/**
|
|
128
151
|
* Sends the request and returns the response data.
|
|
129
152
|
* If the response contains an action attempt,
|
|
@@ -1,17 +1,9 @@
|
|
|
1
|
-
import type { Client } from './client.js'
|
|
2
|
-
import type { SeamHttpRequestOptions } from './options.js'
|
|
3
1
|
import { SeamHttpInvalidResponseError } from './seam-http-error.js'
|
|
4
2
|
import {
|
|
5
3
|
readResponseData,
|
|
6
|
-
SeamHttpRequest,
|
|
7
4
|
type SeamPaginatedRequest,
|
|
8
5
|
} from './seam-http-request.js'
|
|
9
6
|
|
|
10
|
-
interface SeamPaginatorParent {
|
|
11
|
-
readonly client: Client
|
|
12
|
-
readonly defaults: Required<SeamHttpRequestOptions>
|
|
13
|
-
}
|
|
14
|
-
|
|
15
7
|
declare const $brand: unique symbol
|
|
16
8
|
|
|
17
9
|
/**
|
|
@@ -39,18 +31,13 @@ export class SeamPaginator<
|
|
|
39
31
|
const TResponseKey extends keyof TResponse,
|
|
40
32
|
> implements AsyncIterable<EnsureReadonlyArray<TResponse[TResponseKey]>> {
|
|
41
33
|
readonly #request: SeamPaginatedRequest<TResponse, TResponseKey>
|
|
42
|
-
readonly #parent: SeamPaginatorParent
|
|
43
34
|
|
|
44
|
-
constructor(
|
|
45
|
-
parent: SeamPaginatorParent,
|
|
46
|
-
request: SeamPaginatedRequest<TResponse, TResponseKey>,
|
|
47
|
-
) {
|
|
35
|
+
constructor(request: SeamPaginatedRequest<TResponse, TResponseKey>) {
|
|
48
36
|
if (!request.hasPagination) {
|
|
49
37
|
throw new Error(
|
|
50
38
|
`The ${request.pathname} endpoint does not support pagination`,
|
|
51
39
|
)
|
|
52
40
|
}
|
|
53
|
-
this.#parent = parent
|
|
54
41
|
this.#request = request
|
|
55
42
|
}
|
|
56
43
|
|
|
@@ -86,22 +73,7 @@ export class SeamPaginator<
|
|
|
86
73
|
throw new Error('Cannot paginate a response without a responseKey')
|
|
87
74
|
}
|
|
88
75
|
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
const requestData = {
|
|
92
|
-
...(usesParams(method)
|
|
93
|
-
? (this.#request.params ?? {})
|
|
94
|
-
: ((this.#request.body as Record<string, unknown> | null) ?? {})),
|
|
95
|
-
page_cursor: nextPageCursor,
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const request = new SeamHttpRequest<TResponse, TResponseKey>(this.#parent, {
|
|
99
|
-
pathname: this.#request.pathname,
|
|
100
|
-
method,
|
|
101
|
-
responseKey,
|
|
102
|
-
params: usesParams(method) ? requestData : undefined,
|
|
103
|
-
body: usesParams(method) ? undefined : requestData,
|
|
104
|
-
})
|
|
76
|
+
const request = this.#request.withPageCursor(nextPageCursor ?? undefined)
|
|
105
77
|
|
|
106
78
|
const response = await request.fetchResponse()
|
|
107
79
|
const data = readResponseData(response, responseKey, request.pathname)
|
|
@@ -193,9 +165,6 @@ export class SeamPaginator<
|
|
|
193
165
|
}
|
|
194
166
|
}
|
|
195
167
|
|
|
196
|
-
const usesParams = (method: string): boolean =>
|
|
197
|
-
['GET', 'DELETE'].includes(method.toUpperCase())
|
|
198
|
-
|
|
199
168
|
type EnsureReadonlyArray<T> = T extends readonly any[] ? T : never
|
|
200
169
|
type EnsureMutableArray<T> = T extends any[] ? T : never
|
|
201
170
|
type ElementOfArray<T> =
|
package/src/lib/version.ts
CHANGED