@seamapi/http 2.23.7 → 2.24.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 +5 -0
- package/lib/request-parameters.d.ts +1 -1
- package/lib/request-parameters.js +3 -3
- package/lib/request-parameters.js.map +1 -1
- package/lib/resolve-action-attempt.d.ts +2 -0
- package/lib/resolve-action-attempt.js +25 -27
- package/lib/resolve-action-attempt.js.map +1 -1
- package/lib/routes/access-codes/access-codes.d.ts +5 -5
- package/lib/routes/access-codes/access-codes.js +20 -1
- package/lib/routes/access-codes/access-codes.js.map +1 -1
- package/lib/routes/access-codes/simulate/simulate.d.ts +2 -2
- package/lib/routes/access-codes/simulate/simulate.js +2 -1
- package/lib/routes/access-codes/simulate/simulate.js.map +1 -1
- package/lib/routes/access-codes/unmanaged/unmanaged.d.ts +4 -4
- package/lib/routes/access-codes/unmanaged/unmanaged.js +6 -1
- package/lib/routes/access-codes/unmanaged/unmanaged.js.map +1 -1
- package/lib/routes/access-grants/access-grants.d.ts +6 -6
- package/lib/routes/access-grants/access-grants.js +19 -1
- package/lib/routes/access-grants/access-grants.js.map +1 -1
- package/lib/routes/access-grants/unmanaged/unmanaged.d.ts +3 -3
- package/lib/routes/access-grants/unmanaged/unmanaged.js +4 -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 +19 -1
- package/lib/routes/access-methods/access-methods.js.map +1 -1
- package/lib/routes/access-methods/unmanaged/unmanaged.d.ts +2 -2
- package/lib/routes/access-methods/unmanaged/unmanaged.js +3 -1
- package/lib/routes/access-methods/unmanaged/unmanaged.js.map +1 -1
- package/lib/routes/acs/access-groups/access-groups.d.ts +2 -2
- package/lib/routes/acs/access-groups/access-groups.js +8 -1
- package/lib/routes/acs/access-groups/access-groups.js.map +1 -1
- package/lib/routes/acs/acs.d.ts +2 -2
- package/lib/routes/acs/acs.js.map +1 -1
- package/lib/routes/acs/credentials/credentials.d.ts +3 -3
- package/lib/routes/acs/credentials/credentials.js +9 -1
- package/lib/routes/acs/credentials/credentials.js.map +1 -1
- package/lib/routes/acs/encoders/encoders.d.ts +3 -3
- package/lib/routes/acs/encoders/encoders.js +6 -1
- package/lib/routes/acs/encoders/encoders.js.map +1 -1
- package/lib/routes/acs/encoders/simulate/simulate.d.ts +2 -2
- package/lib/routes/acs/encoders/simulate/simulate.js +5 -1
- package/lib/routes/acs/encoders/simulate/simulate.js.map +1 -1
- package/lib/routes/acs/entrances/entrances.d.ts +3 -3
- package/lib/routes/acs/entrances/entrances.js +6 -1
- package/lib/routes/acs/entrances/entrances.js.map +1 -1
- package/lib/routes/acs/systems/systems.d.ts +2 -2
- package/lib/routes/acs/systems/systems.js +5 -1
- package/lib/routes/acs/systems/systems.js.map +1 -1
- package/lib/routes/acs/users/users.d.ts +10 -10
- package/lib/routes/acs/users/users.js +46 -1
- package/lib/routes/acs/users/users.js.map +1 -1
- package/lib/routes/action-attempts/action-attempts.d.ts +3 -3
- package/lib/routes/action-attempts/action-attempts.js +3 -1
- package/lib/routes/action-attempts/action-attempts.js.map +1 -1
- package/lib/routes/client-sessions/client-sessions.d.ts +3 -3
- package/lib/routes/client-sessions/client-sessions.js +15 -1
- package/lib/routes/client-sessions/client-sessions.js.map +1 -1
- package/lib/routes/connect-webviews/connect-webviews.d.ts +3 -3
- package/lib/routes/connect-webviews/connect-webviews.js +5 -1
- package/lib/routes/connect-webviews/connect-webviews.js.map +1 -1
- package/lib/routes/connected-accounts/connected-accounts.d.ts +4 -4
- package/lib/routes/connected-accounts/connected-accounts.js +6 -1
- package/lib/routes/connected-accounts/connected-accounts.js.map +1 -1
- package/lib/routes/connected-accounts/simulate/simulate.d.ts +2 -2
- package/lib/routes/connected-accounts/simulate/simulate.js +2 -1
- package/lib/routes/connected-accounts/simulate/simulate.js.map +1 -1
- package/lib/routes/customers/customers.d.ts +2 -2
- package/lib/routes/customers/customers.js +4 -1
- package/lib/routes/customers/customers.js.map +1 -1
- package/lib/routes/devices/devices.d.ts +4 -4
- package/lib/routes/devices/devices.js +6 -1
- package/lib/routes/devices/devices.js.map +1 -1
- package/lib/routes/devices/simulate/simulate.d.ts +2 -2
- package/lib/routes/devices/simulate/simulate.js +7 -1
- package/lib/routes/devices/simulate/simulate.js.map +1 -1
- package/lib/routes/devices/unmanaged/unmanaged.d.ts +4 -4
- package/lib/routes/devices/unmanaged/unmanaged.js +4 -1
- package/lib/routes/devices/unmanaged/unmanaged.js.map +1 -1
- package/lib/routes/events/events.d.ts +4 -4
- package/lib/routes/events/events.js +31 -1
- package/lib/routes/events/events.js.map +1 -1
- package/lib/routes/instant-keys/instant-keys.d.ts +3 -3
- package/lib/routes/instant-keys/instant-keys.js +4 -1
- package/lib/routes/instant-keys/instant-keys.js.map +1 -1
- package/lib/routes/locks/locks.d.ts +3 -3
- package/lib/routes/locks/locks.js +6 -1
- package/lib/routes/locks/locks.js.map +1 -1
- package/lib/routes/locks/simulate/simulate.d.ts +2 -2
- package/lib/routes/locks/simulate/simulate.js +3 -1
- package/lib/routes/locks/simulate/simulate.js.map +1 -1
- package/lib/routes/noise-sensors/noise-sensors.d.ts +2 -2
- package/lib/routes/noise-sensors/noise-sensors.js +2 -1
- package/lib/routes/noise-sensors/noise-sensors.js.map +1 -1
- package/lib/routes/noise-sensors/noise-thresholds/noise-thresholds.d.ts +2 -2
- package/lib/routes/noise-sensors/noise-thresholds/noise-thresholds.js +6 -1
- package/lib/routes/noise-sensors/noise-thresholds/noise-thresholds.js.map +1 -1
- package/lib/routes/noise-sensors/simulate/simulate.d.ts +2 -2
- package/lib/routes/noise-sensors/simulate/simulate.js +2 -1
- package/lib/routes/noise-sensors/simulate/simulate.js.map +1 -1
- package/lib/routes/phones/phones.d.ts +2 -2
- package/lib/routes/phones/phones.js +4 -1
- package/lib/routes/phones/phones.js.map +1 -1
- package/lib/routes/phones/simulate/simulate.d.ts +2 -2
- package/lib/routes/phones/simulate/simulate.js +2 -1
- package/lib/routes/phones/simulate/simulate.js.map +1 -1
- package/lib/routes/seam-http-endpoints.d.ts +2 -2
- package/lib/routes/seam-http-endpoints.js.map +1 -1
- package/lib/routes/seam-http.d.ts +2 -2
- package/lib/routes/seam-http.js.map +1 -1
- package/lib/routes/spaces/spaces.d.ts +5 -5
- package/lib/routes/spaces/spaces.js +18 -1
- package/lib/routes/spaces/spaces.js.map +1 -1
- package/lib/routes/thermostats/daily-programs/daily-programs.d.ts +2 -2
- package/lib/routes/thermostats/daily-programs/daily-programs.js +4 -1
- package/lib/routes/thermostats/daily-programs/daily-programs.js.map +1 -1
- package/lib/routes/thermostats/schedules/schedules.d.ts +2 -2
- package/lib/routes/thermostats/schedules/schedules.js +6 -1
- package/lib/routes/thermostats/schedules/schedules.js.map +1 -1
- package/lib/routes/thermostats/simulate/simulate.d.ts +2 -2
- package/lib/routes/thermostats/simulate/simulate.js +3 -1
- package/lib/routes/thermostats/simulate/simulate.js.map +1 -1
- package/lib/routes/thermostats/thermostats.d.ts +2 -2
- package/lib/routes/thermostats/thermostats.js +15 -1
- package/lib/routes/thermostats/thermostats.js.map +1 -1
- package/lib/routes/user-identities/unmanaged/unmanaged.d.ts +3 -3
- package/lib/routes/user-identities/unmanaged/unmanaged.js +4 -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 +21 -1
- package/lib/routes/user-identities/user-identities.js.map +1 -1
- package/lib/routes/webhooks/webhooks.d.ts +2 -2
- package/lib/routes/webhooks/webhooks.js +6 -1
- package/lib/routes/webhooks/webhooks.js.map +1 -1
- package/lib/routes/workspaces/workspaces.d.ts +2 -2
- package/lib/routes/workspaces/workspaces.js +6 -1
- package/lib/routes/workspaces/workspaces.js.map +1 -1
- package/lib/seam-http-request.d.ts +7 -2
- package/lib/seam-http-request.js +11 -5
- package/lib/seam-http-request.js.map +1 -1
- package/lib/seam-paginator.d.ts +2 -2
- package/lib/seam-paginator.js +12 -8
- package/lib/seam-paginator.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +1 -1
- package/src/lib/request-parameters.ts +5 -2
- package/src/lib/resolve-action-attempt.ts +34 -37
- package/src/lib/routes/access-codes/access-codes.ts +94 -59
- package/src/lib/routes/access-codes/simulate/simulate.ts +6 -2
- package/src/lib/routes/access-codes/unmanaged/unmanaged.ts +28 -17
- package/src/lib/routes/access-grants/access-grants.ts +101 -71
- package/src/lib/routes/access-grants/unmanaged/unmanaged.ts +9 -3
- package/src/lib/routes/access-methods/access-methods.ts +83 -51
- package/src/lib/routes/access-methods/unmanaged/unmanaged.ts +7 -2
- package/src/lib/routes/acs/access-groups/access-groups.ts +12 -2
- package/src/lib/routes/acs/acs.ts +2 -2
- package/src/lib/routes/acs/credentials/credentials.ts +14 -3
- package/src/lib/routes/acs/encoders/encoders.ts +11 -3
- package/src/lib/routes/acs/encoders/simulate/simulate.ts +9 -2
- package/src/lib/routes/acs/entrances/entrances.ts +11 -3
- package/src/lib/routes/acs/systems/systems.ts +9 -2
- package/src/lib/routes/acs/users/users.ts +214 -137
- package/src/lib/routes/action-attempts/action-attempts.ts +8 -3
- package/src/lib/routes/client-sessions/client-sessions.ts +54 -29
- package/src/lib/routes/connect-webviews/connect-webviews.ts +10 -3
- package/src/lib/routes/connected-accounts/connected-accounts.ts +24 -13
- package/src/lib/routes/connected-accounts/simulate/simulate.ts +6 -2
- package/src/lib/routes/customers/customers.ts +8 -2
- package/src/lib/routes/devices/devices.ts +27 -13
- package/src/lib/routes/devices/simulate/simulate.ts +11 -2
- package/src/lib/routes/devices/unmanaged/unmanaged.ts +22 -13
- package/src/lib/routes/events/events.ts +427 -362
- package/src/lib/routes/instant-keys/instant-keys.ts +21 -12
- package/src/lib/routes/locks/locks.ts +23 -12
- package/src/lib/routes/locks/simulate/simulate.ts +7 -2
- package/src/lib/routes/noise-sensors/noise-sensors.ts +6 -2
- package/src/lib/routes/noise-sensors/noise-thresholds/noise-thresholds.ts +10 -2
- package/src/lib/routes/noise-sensors/simulate/simulate.ts +6 -2
- package/src/lib/routes/phones/phones.ts +8 -2
- package/src/lib/routes/phones/simulate/simulate.ts +6 -2
- package/src/lib/routes/seam-http-endpoints.ts +2 -2
- package/src/lib/routes/seam-http.ts +2 -2
- package/src/lib/routes/spaces/spaces.ts +73 -44
- package/src/lib/routes/thermostats/daily-programs/daily-programs.ts +8 -2
- package/src/lib/routes/thermostats/schedules/schedules.ts +10 -2
- package/src/lib/routes/thermostats/simulate/simulate.ts +7 -2
- package/src/lib/routes/thermostats/thermostats.ts +19 -2
- package/src/lib/routes/user-identities/unmanaged/unmanaged.ts +9 -3
- package/src/lib/routes/user-identities/user-identities.ts +60 -28
- package/src/lib/routes/webhooks/webhooks.ts +10 -2
- package/src/lib/routes/workspaces/workspaces.ts +10 -2
- package/src/lib/seam-http-request.ts +24 -6
- package/src/lib/seam-paginator.ts +22 -12
- package/src/lib/version.ts +1 -1
|
@@ -28,6 +28,7 @@ interface SeamHttpRequestConfig<TResponseKey> {
|
|
|
28
28
|
readonly parameters?: unknown
|
|
29
29
|
readonly hasRequiredParameters?: boolean
|
|
30
30
|
readonly requiredParameterNames?: readonly string[]
|
|
31
|
+
readonly atLeastOneParameterNames?: readonly string[]
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
/**
|
|
@@ -52,6 +53,7 @@ interface SeamHttpRequestConfig<TResponseKey> {
|
|
|
52
53
|
export class SeamHttpRequest<
|
|
53
54
|
const TResponse,
|
|
54
55
|
const TResponseKey extends keyof TResponse | undefined,
|
|
56
|
+
const THasPagination extends boolean = boolean,
|
|
55
57
|
> implements Promise<
|
|
56
58
|
TResponseKey extends keyof TResponse ? TResponse[TResponseKey] : undefined
|
|
57
59
|
> {
|
|
@@ -82,8 +84,8 @@ export class SeamHttpRequest<
|
|
|
82
84
|
return this.#config.responseKey
|
|
83
85
|
}
|
|
84
86
|
|
|
85
|
-
public get hasPagination():
|
|
86
|
-
return this.#config.hasPagination ?? false
|
|
87
|
+
public get hasPagination(): THasPagination {
|
|
88
|
+
return (this.#config.hasPagination ?? false) as THasPagination
|
|
87
89
|
}
|
|
88
90
|
|
|
89
91
|
/**
|
|
@@ -92,10 +94,7 @@ export class SeamHttpRequest<
|
|
|
92
94
|
public get url(): URL {
|
|
93
95
|
const { client } = this.#parent
|
|
94
96
|
|
|
95
|
-
const serializer =
|
|
96
|
-
typeof client.defaults.paramsSerializer === 'function'
|
|
97
|
-
? client.defaults.paramsSerializer
|
|
98
|
-
: serializeUrlSearchParams
|
|
97
|
+
const serializer = getParamsSerializer(client.defaults.paramsSerializer)
|
|
99
98
|
|
|
100
99
|
const origin = getUrlPrefix(client.defaults.baseURL ?? '')
|
|
101
100
|
|
|
@@ -205,6 +204,7 @@ export class SeamHttpRequest<
|
|
|
205
204
|
this.pathname,
|
|
206
205
|
this.#config.hasRequiredParameters ?? false,
|
|
207
206
|
this.#config.requiredParameterNames ?? [],
|
|
207
|
+
this.#config.atLeastOneParameterNames ?? [],
|
|
208
208
|
)
|
|
209
209
|
|
|
210
210
|
const { client } = this.#parent
|
|
@@ -260,6 +260,24 @@ export class SeamHttpRequest<
|
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
262
|
|
|
263
|
+
const getParamsSerializer = (
|
|
264
|
+
paramsSerializer: Client['defaults']['paramsSerializer'],
|
|
265
|
+
): ((params: Record<string, unknown>) => string) => {
|
|
266
|
+
if (typeof paramsSerializer === 'function') return paramsSerializer
|
|
267
|
+
if (typeof paramsSerializer?.serialize === 'function') {
|
|
268
|
+
return paramsSerializer.serialize
|
|
269
|
+
}
|
|
270
|
+
return serializeUrlSearchParams
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* A SeamHttpRequest for an endpoint that supports pagination.
|
|
275
|
+
*/
|
|
276
|
+
export type SeamPaginatedRequest<
|
|
277
|
+
TResponse,
|
|
278
|
+
TResponseKey extends keyof TResponse | undefined,
|
|
279
|
+
> = SeamHttpRequest<TResponse, TResponseKey, true>
|
|
280
|
+
|
|
263
281
|
/**
|
|
264
282
|
* Reads the response data at the response key,
|
|
265
283
|
* throwing a {@link SeamHttpInvalidResponseError} for a success response
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import type { Client } from './client.js'
|
|
2
2
|
import type { SeamHttpRequestOptions } from './options.js'
|
|
3
3
|
import { SeamHttpInvalidResponseError } from './seam-http-error.js'
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
readResponseData,
|
|
6
|
+
SeamHttpRequest,
|
|
7
|
+
type SeamPaginatedRequest,
|
|
8
|
+
} from './seam-http-request.js'
|
|
5
9
|
|
|
6
10
|
interface SeamPaginatorParent {
|
|
7
11
|
readonly client: Client
|
|
@@ -34,12 +38,12 @@ export class SeamPaginator<
|
|
|
34
38
|
const TResponse,
|
|
35
39
|
const TResponseKey extends keyof TResponse,
|
|
36
40
|
> implements AsyncIterable<EnsureReadonlyArray<TResponse[TResponseKey]>> {
|
|
37
|
-
readonly #request:
|
|
41
|
+
readonly #request: SeamPaginatedRequest<TResponse, TResponseKey>
|
|
38
42
|
readonly #parent: SeamPaginatorParent
|
|
39
43
|
|
|
40
44
|
constructor(
|
|
41
45
|
parent: SeamPaginatorParent,
|
|
42
|
-
request:
|
|
46
|
+
request: SeamPaginatedRequest<TResponse, TResponseKey>,
|
|
43
47
|
) {
|
|
44
48
|
if (!request.hasPagination) {
|
|
45
49
|
throw new Error(
|
|
@@ -82,18 +86,21 @@ export class SeamPaginator<
|
|
|
82
86
|
throw new Error('Cannot paginate a response without a responseKey')
|
|
83
87
|
}
|
|
84
88
|
|
|
89
|
+
const method = this.#request.method
|
|
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
|
+
|
|
85
98
|
const request = new SeamHttpRequest<TResponse, TResponseKey>(this.#parent, {
|
|
86
99
|
pathname: this.#request.pathname,
|
|
87
|
-
method
|
|
100
|
+
method,
|
|
88
101
|
responseKey,
|
|
89
|
-
params:
|
|
90
|
-
|
|
91
|
-
? { ...this.#request.params, page_cursor: nextPageCursor }
|
|
92
|
-
: undefined,
|
|
93
|
-
body:
|
|
94
|
-
this.#request.body != null
|
|
95
|
-
? { ...this.#request.body, page_cursor: nextPageCursor }
|
|
96
|
-
: undefined,
|
|
102
|
+
params: usesParams(method) ? requestData : undefined,
|
|
103
|
+
body: usesParams(method) ? undefined : requestData,
|
|
97
104
|
})
|
|
98
105
|
|
|
99
106
|
const response = await request.fetchResponse()
|
|
@@ -186,6 +193,9 @@ export class SeamPaginator<
|
|
|
186
193
|
}
|
|
187
194
|
}
|
|
188
195
|
|
|
196
|
+
const usesParams = (method: string): boolean =>
|
|
197
|
+
['GET', 'DELETE'].includes(method.toUpperCase())
|
|
198
|
+
|
|
189
199
|
type EnsureReadonlyArray<T> = T extends readonly any[] ? T : never
|
|
190
200
|
type EnsureMutableArray<T> = T extends any[] ? T : never
|
|
191
201
|
type ElementOfArray<T> =
|
package/src/lib/version.ts
CHANGED