@seamapi/http 0.5.0 → 0.7.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 +2 -2
- package/dist/connect.cjs +307 -124
- package/dist/connect.cjs.map +1 -1
- package/dist/connect.d.cts +76 -12
- package/lib/seam/connect/auth.js +13 -9
- package/lib/seam/connect/auth.js.map +1 -1
- package/lib/seam/connect/index.d.ts +2 -0
- package/lib/seam/connect/index.js +2 -0
- package/lib/seam/connect/index.js.map +1 -1
- package/lib/seam/connect/options.d.ts +15 -0
- package/lib/seam/connect/options.js +23 -8
- package/lib/seam/connect/options.js.map +1 -1
- package/lib/seam/connect/parse-options.d.ts +3 -3
- package/lib/seam/connect/parse-options.js +3 -1
- package/lib/seam/connect/parse-options.js.map +1 -1
- package/lib/seam/connect/routes/acs-access-groups.d.ts +0 -9
- package/lib/seam/connect/routes/acs-access-groups.js +0 -22
- package/lib/seam/connect/routes/acs-access-groups.js.map +1 -1
- package/lib/seam/connect/routes/acs-credentials.d.ts +6 -0
- package/lib/seam/connect/routes/acs-credentials.js +14 -0
- package/lib/seam/connect/routes/acs-credentials.js.map +1 -1
- package/lib/seam/connect/routes/client-sessions.d.ts +3 -0
- package/lib/seam/connect/routes/client-sessions.js +7 -0
- package/lib/seam/connect/routes/client-sessions.js.map +1 -1
- package/lib/seam/connect/routes/index.d.ts +1 -0
- package/lib/seam/connect/routes/index.js +1 -0
- package/lib/seam/connect/routes/index.js.map +1 -1
- package/lib/seam/connect/routes/user-identities.d.ts +38 -0
- package/lib/seam/connect/routes/user-identities.js +121 -0
- package/lib/seam/connect/routes/user-identities.js.map +1 -0
- package/lib/seam/connect/seam-http-multi-workspace.d.ts +11 -0
- package/lib/seam/connect/seam-http-multi-workspace.js +35 -0
- package/lib/seam/connect/seam-http-multi-workspace.js.map +1 -0
- package/lib/seam/connect/seam-http.d.ts +2 -1
- package/lib/seam/connect/seam-http.js +4 -1
- package/lib/seam/connect/seam-http.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +2 -2
- package/src/lib/seam/connect/auth.ts +28 -10
- package/src/lib/seam/connect/index.ts +2 -0
- package/src/lib/seam/connect/options.ts +63 -17
- package/src/lib/seam/connect/parse-options.ts +6 -1
- package/src/lib/seam/connect/routes/acs-access-groups.ts +0 -48
- package/src/lib/seam/connect/routes/acs-credentials.ts +30 -0
- package/src/lib/seam/connect/routes/client-sessions.ts +15 -0
- package/src/lib/seam/connect/routes/index.ts +1 -0
- package/src/lib/seam/connect/routes/user-identities.ts +261 -0
- package/src/lib/seam/connect/seam-http-multi-workspace.ts +77 -0
- package/src/lib/seam/connect/seam-http.ts +5 -0
- package/src/lib/version.ts +1 -1
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { Client, ClientOptions } from './client.js'
|
|
2
2
|
|
|
3
|
+
export type SeamHttpMultiWorkspaceOptions =
|
|
4
|
+
| SeamHttpMultiWorkspaceOptionsWithClient
|
|
5
|
+
| SeamHttpMultiWorkspaceOptionsWithConsoleSessionToken
|
|
6
|
+
| SeamHttpMultiWorkspaceOptionsWithPersonalAccessToken
|
|
7
|
+
|
|
3
8
|
export type SeamHttpOptions =
|
|
4
9
|
| SeamHttpOptionsFromEnv
|
|
5
10
|
| SeamHttpOptionsWithClient
|
|
@@ -17,6 +22,15 @@ export interface SeamHttpFromPublishableKeyOptions
|
|
|
17
22
|
|
|
18
23
|
export interface SeamHttpOptionsFromEnv extends SeamHttpCommonOptions {}
|
|
19
24
|
|
|
25
|
+
export interface SeamHttpMultiWorkspaceOptionsWithClient {
|
|
26
|
+
client: Client
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const isSeamHttpMultiWorkspaceOptionsWithClient = (
|
|
30
|
+
options: SeamHttpOptions,
|
|
31
|
+
): options is SeamHttpMultiWorkspaceOptionsWithClient =>
|
|
32
|
+
isSeamHttpOptionsWithClient(options)
|
|
33
|
+
|
|
20
34
|
export interface SeamHttpOptionsWithClient {
|
|
21
35
|
client: Client
|
|
22
36
|
}
|
|
@@ -102,24 +116,17 @@ export const isSeamHttpOptionsWithClientSessionToken = (
|
|
|
102
116
|
return true
|
|
103
117
|
}
|
|
104
118
|
|
|
105
|
-
export interface
|
|
119
|
+
export interface SeamHttpMultiWorkspaceOptionsWithConsoleSessionToken
|
|
106
120
|
extends SeamHttpCommonOptions {
|
|
107
121
|
consoleSessionToken: string
|
|
108
|
-
workspaceId: string
|
|
109
122
|
}
|
|
110
123
|
|
|
111
|
-
export const
|
|
124
|
+
export const isSeamHttpMultiWorkspaceOptionsWithConsoleSessionToken = (
|
|
112
125
|
options: SeamHttpOptions,
|
|
113
|
-
): options is
|
|
126
|
+
): options is SeamHttpMultiWorkspaceOptionsWithConsoleSessionToken => {
|
|
114
127
|
if (!('consoleSessionToken' in options)) return false
|
|
115
128
|
if (options.consoleSessionToken == null) return false
|
|
116
129
|
|
|
117
|
-
if (!('workspaceId' in options) || options.workspaceId == null) {
|
|
118
|
-
throw new SeamHttpInvalidOptionsError(
|
|
119
|
-
'Must pass a workspaceId when using a consoleSessionToken',
|
|
120
|
-
)
|
|
121
|
-
}
|
|
122
|
-
|
|
123
130
|
if ('apiKey' in options && options.apiKey != null) {
|
|
124
131
|
throw new SeamHttpInvalidOptionsError(
|
|
125
132
|
'The apiKey option cannot be used with the consoleSessionToken option',
|
|
@@ -141,24 +148,39 @@ export const isSeamHttpOptionsWithConsoleSessionToken = (
|
|
|
141
148
|
return true
|
|
142
149
|
}
|
|
143
150
|
|
|
144
|
-
export interface
|
|
151
|
+
export interface SeamHttpOptionsWithConsoleSessionToken
|
|
145
152
|
extends SeamHttpCommonOptions {
|
|
146
|
-
|
|
153
|
+
consoleSessionToken: string
|
|
147
154
|
workspaceId: string
|
|
148
155
|
}
|
|
149
156
|
|
|
150
|
-
export const
|
|
157
|
+
export const isSeamHttpOptionsWithConsoleSessionToken = (
|
|
151
158
|
options: SeamHttpOptions,
|
|
152
|
-
): options is
|
|
153
|
-
if (!(
|
|
154
|
-
|
|
159
|
+
): options is SeamHttpOptionsWithConsoleSessionToken => {
|
|
160
|
+
if (!isSeamHttpMultiWorkspaceOptionsWithConsoleSessionToken(options)) {
|
|
161
|
+
return false
|
|
162
|
+
}
|
|
155
163
|
|
|
156
164
|
if (!('workspaceId' in options) || options.workspaceId == null) {
|
|
157
165
|
throw new SeamHttpInvalidOptionsError(
|
|
158
|
-
'Must pass a workspaceId when using a
|
|
166
|
+
'Must pass a workspaceId when using a consoleSessionToken',
|
|
159
167
|
)
|
|
160
168
|
}
|
|
161
169
|
|
|
170
|
+
return true
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export interface SeamHttpMultiWorkspaceOptionsWithPersonalAccessToken
|
|
174
|
+
extends SeamHttpCommonOptions {
|
|
175
|
+
personalAccessToken: string
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export const isSeamHttpMultiWorkspaceOptionsWithPersonalAccessToken = (
|
|
179
|
+
options: SeamHttpOptions,
|
|
180
|
+
): options is SeamHttpMultiWorkspaceOptionsWithPersonalAccessToken => {
|
|
181
|
+
if (!('personalAccessToken' in options)) return false
|
|
182
|
+
if (options.personalAccessToken == null) return false
|
|
183
|
+
|
|
162
184
|
if ('apiKey' in options && options.apiKey != null) {
|
|
163
185
|
throw new SeamHttpInvalidOptionsError(
|
|
164
186
|
'The apiKey option cannot be used with the personalAccessToken option',
|
|
@@ -180,6 +202,28 @@ export const isSeamHttpOptionsWithPersonalAccessToken = (
|
|
|
180
202
|
return true
|
|
181
203
|
}
|
|
182
204
|
|
|
205
|
+
export interface SeamHttpOptionsWithPersonalAccessToken
|
|
206
|
+
extends SeamHttpCommonOptions {
|
|
207
|
+
personalAccessToken: string
|
|
208
|
+
workspaceId: string
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export const isSeamHttpOptionsWithPersonalAccessToken = (
|
|
212
|
+
options: SeamHttpOptions,
|
|
213
|
+
): options is SeamHttpOptionsWithPersonalAccessToken => {
|
|
214
|
+
if (!isSeamHttpMultiWorkspaceOptionsWithPersonalAccessToken(options)) {
|
|
215
|
+
return false
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (!('workspaceId' in options) || options.workspaceId == null) {
|
|
219
|
+
throw new SeamHttpInvalidOptionsError(
|
|
220
|
+
'Must pass a workspaceId when using a personalAccessToken',
|
|
221
|
+
)
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return true
|
|
225
|
+
}
|
|
226
|
+
|
|
183
227
|
export class SeamHttpInvalidOptionsError extends Error {
|
|
184
228
|
constructor(message: string) {
|
|
185
229
|
super(`SeamHttp received invalid options: ${message}`)
|
|
@@ -187,3 +231,5 @@ export class SeamHttpInvalidOptionsError extends Error {
|
|
|
187
231
|
Error.captureStackTrace(this, this.constructor)
|
|
188
232
|
}
|
|
189
233
|
}
|
|
234
|
+
|
|
235
|
+
export class SeamHttpMultiWorkspaceInvalidOptionsError extends SeamHttpInvalidOptionsError {}
|
|
@@ -3,8 +3,10 @@ import version from 'lib/version.js'
|
|
|
3
3
|
import { getAuthHeaders } from './auth.js'
|
|
4
4
|
import type { ClientOptions } from './client.js'
|
|
5
5
|
import {
|
|
6
|
+
isSeamHttpMultiWorkspaceOptionsWithClient,
|
|
6
7
|
isSeamHttpOptionsWithClient,
|
|
7
8
|
isSeamHttpOptionsWithClientSessionToken,
|
|
9
|
+
type SeamHttpMultiWorkspaceOptions,
|
|
8
10
|
type SeamHttpOptions,
|
|
9
11
|
} from './options.js'
|
|
10
12
|
|
|
@@ -15,7 +17,9 @@ const sdkHeaders = {
|
|
|
15
17
|
'seam-sdk-version': version,
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
export type Options =
|
|
20
|
+
export type Options =
|
|
21
|
+
| SeamHttpMultiWorkspaceOptions
|
|
22
|
+
| (SeamHttpOptions & { publishableKey?: string })
|
|
19
23
|
|
|
20
24
|
export const parseOptions = (
|
|
21
25
|
apiKeyOrOptions: string | Options,
|
|
@@ -23,6 +27,7 @@ export const parseOptions = (
|
|
|
23
27
|
const options = getNormalizedOptions(apiKeyOrOptions)
|
|
24
28
|
|
|
25
29
|
if (isSeamHttpOptionsWithClient(options)) return options
|
|
30
|
+
if (isSeamHttpMultiWorkspaceOptionsWithClient(options)) return options
|
|
26
31
|
|
|
27
32
|
return {
|
|
28
33
|
axiosOptions: {
|
|
@@ -128,25 +128,6 @@ export class SeamHttpAcsAccessGroups {
|
|
|
128
128
|
})
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
async create(
|
|
132
|
-
body?: AcsAccessGroupsCreateBody,
|
|
133
|
-
): Promise<AcsAccessGroupsCreateResponse['acs_access_group']> {
|
|
134
|
-
const { data } = await this.client.request<AcsAccessGroupsCreateResponse>({
|
|
135
|
-
url: '/acs/access_groups/create',
|
|
136
|
-
method: 'post',
|
|
137
|
-
data: body,
|
|
138
|
-
})
|
|
139
|
-
return data.acs_access_group
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
async delete(body?: AcsAccessGroupsDeleteBody): Promise<void> {
|
|
143
|
-
await this.client.request<AcsAccessGroupsDeleteResponse>({
|
|
144
|
-
url: '/acs/access_groups/delete',
|
|
145
|
-
method: 'post',
|
|
146
|
-
data: body,
|
|
147
|
-
})
|
|
148
|
-
}
|
|
149
|
-
|
|
150
131
|
async get(
|
|
151
132
|
body?: AcsAccessGroupsGetParams,
|
|
152
133
|
): Promise<AcsAccessGroupsGetResponse['acs_access_group']> {
|
|
@@ -188,14 +169,6 @@ export class SeamHttpAcsAccessGroups {
|
|
|
188
169
|
data: body,
|
|
189
170
|
})
|
|
190
171
|
}
|
|
191
|
-
|
|
192
|
-
async update(body?: AcsAccessGroupsUpdateBody): Promise<void> {
|
|
193
|
-
await this.client.request<AcsAccessGroupsUpdateResponse>({
|
|
194
|
-
url: '/acs/access_groups/update',
|
|
195
|
-
method: 'post',
|
|
196
|
-
data: body,
|
|
197
|
-
})
|
|
198
|
-
}
|
|
199
172
|
}
|
|
200
173
|
|
|
201
174
|
export type AcsAccessGroupsAddUserBody =
|
|
@@ -205,20 +178,6 @@ export type AcsAccessGroupsAddUserResponse = SetNonNullable<
|
|
|
205
178
|
Required<RouteResponse<'/acs/access_groups/add_user'>>
|
|
206
179
|
>
|
|
207
180
|
|
|
208
|
-
export type AcsAccessGroupsCreateBody =
|
|
209
|
-
RouteRequestBody<'/acs/access_groups/create'>
|
|
210
|
-
|
|
211
|
-
export type AcsAccessGroupsCreateResponse = SetNonNullable<
|
|
212
|
-
Required<RouteResponse<'/acs/access_groups/create'>>
|
|
213
|
-
>
|
|
214
|
-
|
|
215
|
-
export type AcsAccessGroupsDeleteBody =
|
|
216
|
-
RouteRequestBody<'/acs/access_groups/delete'>
|
|
217
|
-
|
|
218
|
-
export type AcsAccessGroupsDeleteResponse = SetNonNullable<
|
|
219
|
-
Required<RouteResponse<'/acs/access_groups/delete'>>
|
|
220
|
-
>
|
|
221
|
-
|
|
222
181
|
export type AcsAccessGroupsGetParams =
|
|
223
182
|
RouteRequestBody<'/acs/access_groups/get'>
|
|
224
183
|
|
|
@@ -246,10 +205,3 @@ export type AcsAccessGroupsRemoveUserBody =
|
|
|
246
205
|
export type AcsAccessGroupsRemoveUserResponse = SetNonNullable<
|
|
247
206
|
Required<RouteResponse<'/acs/access_groups/remove_user'>>
|
|
248
207
|
>
|
|
249
|
-
|
|
250
|
-
export type AcsAccessGroupsUpdateBody =
|
|
251
|
-
RouteRequestBody<'/acs/access_groups/update'>
|
|
252
|
-
|
|
253
|
-
export type AcsAccessGroupsUpdateResponse = SetNonNullable<
|
|
254
|
-
Required<RouteResponse<'/acs/access_groups/update'>>
|
|
255
|
-
>
|
|
@@ -120,6 +120,14 @@ export class SeamHttpAcsCredentials {
|
|
|
120
120
|
return new SeamHttpAcsCredentials(constructorOptions)
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
+
async assign(body?: AcsCredentialsAssignBody): Promise<void> {
|
|
124
|
+
await this.client.request<AcsCredentialsAssignResponse>({
|
|
125
|
+
url: '/acs/credentials/assign',
|
|
126
|
+
method: 'post',
|
|
127
|
+
data: body,
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
|
|
123
131
|
async create(
|
|
124
132
|
body?: AcsCredentialsCreateBody,
|
|
125
133
|
): Promise<AcsCredentialsCreateResponse['acs_credential']> {
|
|
@@ -160,8 +168,23 @@ export class SeamHttpAcsCredentials {
|
|
|
160
168
|
})
|
|
161
169
|
return data.acs_credentials
|
|
162
170
|
}
|
|
171
|
+
|
|
172
|
+
async unassign(body?: AcsCredentialsUnassignBody): Promise<void> {
|
|
173
|
+
await this.client.request<AcsCredentialsUnassignResponse>({
|
|
174
|
+
url: '/acs/credentials/unassign',
|
|
175
|
+
method: 'post',
|
|
176
|
+
data: body,
|
|
177
|
+
})
|
|
178
|
+
}
|
|
163
179
|
}
|
|
164
180
|
|
|
181
|
+
export type AcsCredentialsAssignBody =
|
|
182
|
+
RouteRequestBody<'/acs/credentials/assign'>
|
|
183
|
+
|
|
184
|
+
export type AcsCredentialsAssignResponse = SetNonNullable<
|
|
185
|
+
Required<RouteResponse<'/acs/credentials/assign'>>
|
|
186
|
+
>
|
|
187
|
+
|
|
165
188
|
export type AcsCredentialsCreateBody =
|
|
166
189
|
RouteRequestBody<'/acs/credentials/create'>
|
|
167
190
|
|
|
@@ -187,3 +210,10 @@ export type AcsCredentialsListParams = RouteRequestBody<'/acs/credentials/list'>
|
|
|
187
210
|
export type AcsCredentialsListResponse = SetNonNullable<
|
|
188
211
|
Required<RouteResponse<'/acs/credentials/list'>>
|
|
189
212
|
>
|
|
213
|
+
|
|
214
|
+
export type AcsCredentialsUnassignBody =
|
|
215
|
+
RouteRequestBody<'/acs/credentials/unassign'>
|
|
216
|
+
|
|
217
|
+
export type AcsCredentialsUnassignResponse = SetNonNullable<
|
|
218
|
+
Required<RouteResponse<'/acs/credentials/unassign'>>
|
|
219
|
+
>
|
|
@@ -182,6 +182,14 @@ export class SeamHttpClientSessions {
|
|
|
182
182
|
})
|
|
183
183
|
return data.client_sessions
|
|
184
184
|
}
|
|
185
|
+
|
|
186
|
+
async revoke(body?: ClientSessionsRevokeBody): Promise<void> {
|
|
187
|
+
await this.client.request<ClientSessionsRevokeResponse>({
|
|
188
|
+
url: '/client_sessions/revoke',
|
|
189
|
+
method: 'post',
|
|
190
|
+
data: body,
|
|
191
|
+
})
|
|
192
|
+
}
|
|
185
193
|
}
|
|
186
194
|
|
|
187
195
|
export type ClientSessionsCreateBody =
|
|
@@ -223,3 +231,10 @@ export type ClientSessionsListParams = RouteRequestBody<'/client_sessions/list'>
|
|
|
223
231
|
export type ClientSessionsListResponse = SetNonNullable<
|
|
224
232
|
Required<RouteResponse<'/client_sessions/list'>>
|
|
225
233
|
>
|
|
234
|
+
|
|
235
|
+
export type ClientSessionsRevokeBody =
|
|
236
|
+
RouteRequestBody<'/client_sessions/revoke'>
|
|
237
|
+
|
|
238
|
+
export type ClientSessionsRevokeResponse = SetNonNullable<
|
|
239
|
+
Required<RouteResponse<'/client_sessions/revoke'>>
|
|
240
|
+
>
|
|
@@ -17,5 +17,6 @@ export * from './noise-sensors.js'
|
|
|
17
17
|
export * from './noise-sensors-noise-thresholds.js'
|
|
18
18
|
export * from './thermostats.js'
|
|
19
19
|
export * from './thermostats-climate-setting-schedules.js'
|
|
20
|
+
export * from './user-identities.js'
|
|
20
21
|
export * from './webhooks.js'
|
|
21
22
|
export * from './workspaces.js'
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Automatically generated by generate-routes.ts.
|
|
3
|
+
* Do not edit this file or add other files to this directory.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { RouteRequestBody, RouteResponse } from '@seamapi/types/connect'
|
|
7
|
+
import type { SetNonNullable } from 'type-fest'
|
|
8
|
+
|
|
9
|
+
import { warnOnInsecureuserIdentifierKey } from 'lib/seam/connect/auth.js'
|
|
10
|
+
import { type Client, createClient } from 'lib/seam/connect/client.js'
|
|
11
|
+
import {
|
|
12
|
+
isSeamHttpOptionsWithApiKey,
|
|
13
|
+
isSeamHttpOptionsWithClient,
|
|
14
|
+
isSeamHttpOptionsWithClientSessionToken,
|
|
15
|
+
isSeamHttpOptionsWithConsoleSessionToken,
|
|
16
|
+
isSeamHttpOptionsWithPersonalAccessToken,
|
|
17
|
+
type SeamHttpFromPublishableKeyOptions,
|
|
18
|
+
SeamHttpInvalidOptionsError,
|
|
19
|
+
type SeamHttpOptions,
|
|
20
|
+
type SeamHttpOptionsWithApiKey,
|
|
21
|
+
type SeamHttpOptionsWithClient,
|
|
22
|
+
type SeamHttpOptionsWithClientSessionToken,
|
|
23
|
+
type SeamHttpOptionsWithConsoleSessionToken,
|
|
24
|
+
type SeamHttpOptionsWithPersonalAccessToken,
|
|
25
|
+
} from 'lib/seam/connect/options.js'
|
|
26
|
+
import { parseOptions } from 'lib/seam/connect/parse-options.js'
|
|
27
|
+
|
|
28
|
+
import { SeamHttpClientSessions } from './client-sessions.js'
|
|
29
|
+
|
|
30
|
+
export class SeamHttpUserIdentities {
|
|
31
|
+
client: Client
|
|
32
|
+
|
|
33
|
+
constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) {
|
|
34
|
+
const clientOptions = parseOptions(apiKeyOrOptions)
|
|
35
|
+
this.client = createClient(clientOptions)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static fromClient(
|
|
39
|
+
client: SeamHttpOptionsWithClient['client'],
|
|
40
|
+
options: Omit<SeamHttpOptionsWithClient, 'client'> = {},
|
|
41
|
+
): SeamHttpUserIdentities {
|
|
42
|
+
const constructorOptions = { ...options, client }
|
|
43
|
+
if (!isSeamHttpOptionsWithClient(constructorOptions)) {
|
|
44
|
+
throw new SeamHttpInvalidOptionsError('Missing client')
|
|
45
|
+
}
|
|
46
|
+
return new SeamHttpUserIdentities(constructorOptions)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
static fromApiKey(
|
|
50
|
+
apiKey: SeamHttpOptionsWithApiKey['apiKey'],
|
|
51
|
+
options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
|
|
52
|
+
): SeamHttpUserIdentities {
|
|
53
|
+
const constructorOptions = { ...options, apiKey }
|
|
54
|
+
if (!isSeamHttpOptionsWithApiKey(constructorOptions)) {
|
|
55
|
+
throw new SeamHttpInvalidOptionsError('Missing apiKey')
|
|
56
|
+
}
|
|
57
|
+
return new SeamHttpUserIdentities(constructorOptions)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
static fromClientSessionToken(
|
|
61
|
+
clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'],
|
|
62
|
+
options: Omit<
|
|
63
|
+
SeamHttpOptionsWithClientSessionToken,
|
|
64
|
+
'clientSessionToken'
|
|
65
|
+
> = {},
|
|
66
|
+
): SeamHttpUserIdentities {
|
|
67
|
+
const constructorOptions = { ...options, clientSessionToken }
|
|
68
|
+
if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) {
|
|
69
|
+
throw new SeamHttpInvalidOptionsError('Missing clientSessionToken')
|
|
70
|
+
}
|
|
71
|
+
return new SeamHttpUserIdentities(constructorOptions)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
static async fromPublishableKey(
|
|
75
|
+
publishableKey: string,
|
|
76
|
+
userIdentifierKey: string,
|
|
77
|
+
options: SeamHttpFromPublishableKeyOptions = {},
|
|
78
|
+
): Promise<SeamHttpUserIdentities> {
|
|
79
|
+
warnOnInsecureuserIdentifierKey(userIdentifierKey)
|
|
80
|
+
const clientOptions = parseOptions({ ...options, publishableKey })
|
|
81
|
+
const client = createClient(clientOptions)
|
|
82
|
+
const clientSessions = SeamHttpClientSessions.fromClient(client)
|
|
83
|
+
const { token } = await clientSessions.getOrCreate({
|
|
84
|
+
user_identifier_key: userIdentifierKey,
|
|
85
|
+
})
|
|
86
|
+
return SeamHttpUserIdentities.fromClientSessionToken(token, options)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
static fromConsoleSessionToken(
|
|
90
|
+
consoleSessionToken: SeamHttpOptionsWithConsoleSessionToken['consoleSessionToken'],
|
|
91
|
+
workspaceId: SeamHttpOptionsWithConsoleSessionToken['workspaceId'],
|
|
92
|
+
options: Omit<
|
|
93
|
+
SeamHttpOptionsWithConsoleSessionToken,
|
|
94
|
+
'consoleSessionToken' | 'workspaceId'
|
|
95
|
+
> = {},
|
|
96
|
+
): SeamHttpUserIdentities {
|
|
97
|
+
const constructorOptions = { ...options, consoleSessionToken, workspaceId }
|
|
98
|
+
if (!isSeamHttpOptionsWithConsoleSessionToken(constructorOptions)) {
|
|
99
|
+
throw new SeamHttpInvalidOptionsError(
|
|
100
|
+
'Missing consoleSessionToken or workspaceId',
|
|
101
|
+
)
|
|
102
|
+
}
|
|
103
|
+
return new SeamHttpUserIdentities(constructorOptions)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
static fromPersonalAccessToken(
|
|
107
|
+
personalAccessToken: SeamHttpOptionsWithPersonalAccessToken['personalAccessToken'],
|
|
108
|
+
workspaceId: SeamHttpOptionsWithPersonalAccessToken['workspaceId'],
|
|
109
|
+
options: Omit<
|
|
110
|
+
SeamHttpOptionsWithPersonalAccessToken,
|
|
111
|
+
'personalAccessToken' | 'workspaceId'
|
|
112
|
+
> = {},
|
|
113
|
+
): SeamHttpUserIdentities {
|
|
114
|
+
const constructorOptions = { ...options, personalAccessToken, workspaceId }
|
|
115
|
+
if (!isSeamHttpOptionsWithPersonalAccessToken(constructorOptions)) {
|
|
116
|
+
throw new SeamHttpInvalidOptionsError(
|
|
117
|
+
'Missing personalAccessToken or workspaceId',
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
return new SeamHttpUserIdentities(constructorOptions)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async addAcsUser(body?: UserIdentitiesAddAcsUserBody): Promise<void> {
|
|
124
|
+
await this.client.request<UserIdentitiesAddAcsUserResponse>({
|
|
125
|
+
url: '/user_identities/add_acs_user',
|
|
126
|
+
method: 'post',
|
|
127
|
+
data: body,
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async create(
|
|
132
|
+
body?: UserIdentitiesCreateBody,
|
|
133
|
+
): Promise<UserIdentitiesCreateResponse['user_identity']> {
|
|
134
|
+
const { data } = await this.client.request<UserIdentitiesCreateResponse>({
|
|
135
|
+
url: '/user_identities/create',
|
|
136
|
+
method: 'post',
|
|
137
|
+
data: body,
|
|
138
|
+
})
|
|
139
|
+
return data.user_identity
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async get(
|
|
143
|
+
body?: UserIdentitiesGetParams,
|
|
144
|
+
): Promise<UserIdentitiesGetResponse['user_identity']> {
|
|
145
|
+
const { data } = await this.client.request<UserIdentitiesGetResponse>({
|
|
146
|
+
url: '/user_identities/get',
|
|
147
|
+
method: 'post',
|
|
148
|
+
data: body,
|
|
149
|
+
})
|
|
150
|
+
return data.user_identity
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async grantAccessToDevice(
|
|
154
|
+
body?: UserIdentitiesGrantAccessToDeviceBody,
|
|
155
|
+
): Promise<void> {
|
|
156
|
+
await this.client.request<UserIdentitiesGrantAccessToDeviceResponse>({
|
|
157
|
+
url: '/user_identities/grant_access_to_device',
|
|
158
|
+
method: 'post',
|
|
159
|
+
data: body,
|
|
160
|
+
})
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
async listAccessibleDevices(
|
|
164
|
+
body?: UserIdentitiesListAccessibleDevicesParams,
|
|
165
|
+
): Promise<
|
|
166
|
+
UserIdentitiesListAccessibleDevicesResponse['accessible_devices']
|
|
167
|
+
> {
|
|
168
|
+
const { data } =
|
|
169
|
+
await this.client.request<UserIdentitiesListAccessibleDevicesResponse>({
|
|
170
|
+
url: '/user_identities/list_accessible_devices',
|
|
171
|
+
method: 'post',
|
|
172
|
+
data: body,
|
|
173
|
+
})
|
|
174
|
+
return data.accessible_devices
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
async listAcsUsers(
|
|
178
|
+
body?: UserIdentitiesListAcsUsersParams,
|
|
179
|
+
): Promise<UserIdentitiesListAcsUsersResponse['acs_users']> {
|
|
180
|
+
const { data } =
|
|
181
|
+
await this.client.request<UserIdentitiesListAcsUsersResponse>({
|
|
182
|
+
url: '/user_identities/list_acs_users',
|
|
183
|
+
method: 'post',
|
|
184
|
+
data: body,
|
|
185
|
+
})
|
|
186
|
+
return data.acs_users
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
async removeAcsUser(body?: UserIdentitiesRemoveAcsUserBody): Promise<void> {
|
|
190
|
+
await this.client.request<UserIdentitiesRemoveAcsUserResponse>({
|
|
191
|
+
url: '/user_identities/remove_acs_user',
|
|
192
|
+
method: 'post',
|
|
193
|
+
data: body,
|
|
194
|
+
})
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
async revokeAccessToDevice(
|
|
198
|
+
body?: UserIdentitiesRevokeAccessToDeviceBody,
|
|
199
|
+
): Promise<void> {
|
|
200
|
+
await this.client.request<UserIdentitiesRevokeAccessToDeviceResponse>({
|
|
201
|
+
url: '/user_identities/revoke_access_to_device',
|
|
202
|
+
method: 'post',
|
|
203
|
+
data: body,
|
|
204
|
+
})
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export type UserIdentitiesAddAcsUserBody =
|
|
209
|
+
RouteRequestBody<'/user_identities/add_acs_user'>
|
|
210
|
+
|
|
211
|
+
export type UserIdentitiesAddAcsUserResponse = SetNonNullable<
|
|
212
|
+
Required<RouteResponse<'/user_identities/add_acs_user'>>
|
|
213
|
+
>
|
|
214
|
+
|
|
215
|
+
export type UserIdentitiesCreateBody =
|
|
216
|
+
RouteRequestBody<'/user_identities/create'>
|
|
217
|
+
|
|
218
|
+
export type UserIdentitiesCreateResponse = SetNonNullable<
|
|
219
|
+
Required<RouteResponse<'/user_identities/create'>>
|
|
220
|
+
>
|
|
221
|
+
|
|
222
|
+
export type UserIdentitiesGetParams = RouteRequestBody<'/user_identities/get'>
|
|
223
|
+
|
|
224
|
+
export type UserIdentitiesGetResponse = SetNonNullable<
|
|
225
|
+
Required<RouteResponse<'/user_identities/get'>>
|
|
226
|
+
>
|
|
227
|
+
|
|
228
|
+
export type UserIdentitiesGrantAccessToDeviceBody =
|
|
229
|
+
RouteRequestBody<'/user_identities/grant_access_to_device'>
|
|
230
|
+
|
|
231
|
+
export type UserIdentitiesGrantAccessToDeviceResponse = SetNonNullable<
|
|
232
|
+
Required<RouteResponse<'/user_identities/grant_access_to_device'>>
|
|
233
|
+
>
|
|
234
|
+
|
|
235
|
+
export type UserIdentitiesListAccessibleDevicesParams =
|
|
236
|
+
RouteRequestBody<'/user_identities/list_accessible_devices'>
|
|
237
|
+
|
|
238
|
+
export type UserIdentitiesListAccessibleDevicesResponse = SetNonNullable<
|
|
239
|
+
Required<RouteResponse<'/user_identities/list_accessible_devices'>>
|
|
240
|
+
>
|
|
241
|
+
|
|
242
|
+
export type UserIdentitiesListAcsUsersParams =
|
|
243
|
+
RouteRequestBody<'/user_identities/list_acs_users'>
|
|
244
|
+
|
|
245
|
+
export type UserIdentitiesListAcsUsersResponse = SetNonNullable<
|
|
246
|
+
Required<RouteResponse<'/user_identities/list_acs_users'>>
|
|
247
|
+
>
|
|
248
|
+
|
|
249
|
+
export type UserIdentitiesRemoveAcsUserBody =
|
|
250
|
+
RouteRequestBody<'/user_identities/remove_acs_user'>
|
|
251
|
+
|
|
252
|
+
export type UserIdentitiesRemoveAcsUserResponse = SetNonNullable<
|
|
253
|
+
Required<RouteResponse<'/user_identities/remove_acs_user'>>
|
|
254
|
+
>
|
|
255
|
+
|
|
256
|
+
export type UserIdentitiesRevokeAccessToDeviceBody =
|
|
257
|
+
RouteRequestBody<'/user_identities/revoke_access_to_device'>
|
|
258
|
+
|
|
259
|
+
export type UserIdentitiesRevokeAccessToDeviceResponse = SetNonNullable<
|
|
260
|
+
Required<RouteResponse<'/user_identities/revoke_access_to_device'>>
|
|
261
|
+
>
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { type Client, createClient } from './client.js'
|
|
2
|
+
import {
|
|
3
|
+
isSeamHttpMultiWorkspaceOptionsWithClient,
|
|
4
|
+
isSeamHttpMultiWorkspaceOptionsWithConsoleSessionToken,
|
|
5
|
+
isSeamHttpMultiWorkspaceOptionsWithPersonalAccessToken,
|
|
6
|
+
SeamHttpMultiWorkspaceInvalidOptionsError,
|
|
7
|
+
type SeamHttpMultiWorkspaceOptions,
|
|
8
|
+
type SeamHttpMultiWorkspaceOptionsWithClient,
|
|
9
|
+
type SeamHttpMultiWorkspaceOptionsWithConsoleSessionToken,
|
|
10
|
+
type SeamHttpMultiWorkspaceOptionsWithPersonalAccessToken,
|
|
11
|
+
} from './options.js'
|
|
12
|
+
import { parseOptions } from './parse-options.js'
|
|
13
|
+
import { SeamHttpWorkspaces } from './routes/index.js'
|
|
14
|
+
|
|
15
|
+
export class SeamHttpMultiWorkspace {
|
|
16
|
+
client: Client
|
|
17
|
+
|
|
18
|
+
constructor(options: SeamHttpMultiWorkspaceOptions) {
|
|
19
|
+
const clientOptions = parseOptions(options)
|
|
20
|
+
this.client = createClient(clientOptions)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static fromClient(
|
|
24
|
+
client: SeamHttpMultiWorkspaceOptionsWithClient['client'],
|
|
25
|
+
options: Omit<SeamHttpMultiWorkspaceOptionsWithClient, 'client'> = {},
|
|
26
|
+
): SeamHttpMultiWorkspace {
|
|
27
|
+
const constructorOptions = { ...options, client }
|
|
28
|
+
if (!isSeamHttpMultiWorkspaceOptionsWithClient(constructorOptions)) {
|
|
29
|
+
throw new SeamHttpMultiWorkspaceInvalidOptionsError('Missing client')
|
|
30
|
+
}
|
|
31
|
+
return new SeamHttpMultiWorkspace(constructorOptions)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static fromConsoleSessionToken(
|
|
35
|
+
consoleSessionToken: SeamHttpMultiWorkspaceOptionsWithConsoleSessionToken['consoleSessionToken'],
|
|
36
|
+
options: Omit<
|
|
37
|
+
SeamHttpMultiWorkspaceOptionsWithConsoleSessionToken,
|
|
38
|
+
'consoleSessionToken'
|
|
39
|
+
> = {},
|
|
40
|
+
): SeamHttpMultiWorkspace {
|
|
41
|
+
const constructorOptions = { ...options, consoleSessionToken }
|
|
42
|
+
if (
|
|
43
|
+
!isSeamHttpMultiWorkspaceOptionsWithConsoleSessionToken(
|
|
44
|
+
constructorOptions,
|
|
45
|
+
)
|
|
46
|
+
) {
|
|
47
|
+
throw new SeamHttpMultiWorkspaceInvalidOptionsError(
|
|
48
|
+
'Missing consoleSessionToken',
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
return new SeamHttpMultiWorkspace(constructorOptions)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static fromPersonalAccessToken(
|
|
55
|
+
personalAccessToken: SeamHttpMultiWorkspaceOptionsWithPersonalAccessToken['personalAccessToken'],
|
|
56
|
+
options: Omit<
|
|
57
|
+
SeamHttpMultiWorkspaceOptionsWithPersonalAccessToken,
|
|
58
|
+
'personalAccessToken'
|
|
59
|
+
> = {},
|
|
60
|
+
): SeamHttpMultiWorkspace {
|
|
61
|
+
const constructorOptions = { ...options, personalAccessToken }
|
|
62
|
+
if (
|
|
63
|
+
!isSeamHttpMultiWorkspaceOptionsWithPersonalAccessToken(
|
|
64
|
+
constructorOptions,
|
|
65
|
+
)
|
|
66
|
+
) {
|
|
67
|
+
throw new SeamHttpMultiWorkspaceInvalidOptionsError(
|
|
68
|
+
'Missing personalAccessToken',
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
return new SeamHttpMultiWorkspace(constructorOptions)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
get workspaces(): SeamHttpWorkspaces {
|
|
75
|
+
return SeamHttpWorkspaces.fromClient(this.client)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
SeamHttpLocks,
|
|
29
29
|
SeamHttpNoiseSensors,
|
|
30
30
|
SeamHttpThermostats,
|
|
31
|
+
SeamHttpUserIdentities,
|
|
31
32
|
SeamHttpWebhooks,
|
|
32
33
|
SeamHttpWorkspaces,
|
|
33
34
|
} from './routes/index.js'
|
|
@@ -169,6 +170,10 @@ export class SeamHttp {
|
|
|
169
170
|
return SeamHttpThermostats.fromClient(this.client)
|
|
170
171
|
}
|
|
171
172
|
|
|
173
|
+
get userIdentities(): SeamHttpUserIdentities {
|
|
174
|
+
return SeamHttpUserIdentities.fromClient(this.client)
|
|
175
|
+
}
|
|
176
|
+
|
|
172
177
|
get webhooks(): SeamHttpWebhooks {
|
|
173
178
|
return SeamHttpWebhooks.fromClient(this.client)
|
|
174
179
|
}
|
package/src/lib/version.ts
CHANGED