@seamapi/http 0.1.0 → 0.2.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/dist/connect.cjs +752 -366
- package/dist/connect.cjs.map +1 -1
- package/dist/connect.d.cts +186 -142
- package/lib/params-serializer.d.ts +5 -0
- package/lib/params-serializer.js +42 -0
- package/lib/params-serializer.js.map +1 -0
- package/lib/seam/connect/auth.d.ts +3 -2
- package/lib/seam/connect/auth.js +55 -4
- package/lib/seam/connect/auth.js.map +1 -1
- package/lib/seam/connect/client.d.ts +10 -22
- package/lib/seam/connect/client.js +17 -77
- package/lib/seam/connect/client.js.map +1 -1
- package/lib/seam/connect/index.d.ts +2 -1
- package/lib/seam/connect/index.js +2 -1
- package/lib/seam/connect/index.js.map +1 -1
- package/lib/seam/connect/{client-options.d.ts → options.d.ts} +7 -7
- package/lib/seam/connect/{client-options.js → options.js} +5 -10
- package/lib/seam/connect/options.js.map +1 -0
- package/lib/seam/connect/parse-options.d.ts +6 -2
- package/lib/seam/connect/parse-options.js +34 -16
- package/lib/seam/connect/parse-options.js.map +1 -1
- package/lib/seam/connect/routes/access-codes-unmanaged.d.ts +10 -9
- package/lib/seam/connect/routes/access-codes-unmanaged.js +26 -14
- package/lib/seam/connect/routes/access-codes-unmanaged.js.map +1 -1
- package/lib/seam/connect/routes/access-codes.d.ts +15 -14
- package/lib/seam/connect/routes/access-codes.js +29 -17
- package/lib/seam/connect/routes/access-codes.js.map +1 -1
- package/lib/seam/connect/routes/acs-access-groups.d.ts +13 -12
- package/lib/seam/connect/routes/acs-access-groups.js +26 -14
- package/lib/seam/connect/routes/acs-access-groups.js.map +1 -1
- package/lib/seam/connect/routes/acs-credentials.d.ts +9 -8
- package/lib/seam/connect/routes/acs-credentials.js +26 -14
- package/lib/seam/connect/routes/acs-credentials.js.map +1 -1
- package/lib/seam/connect/routes/acs-systems.d.ts +9 -8
- package/lib/seam/connect/routes/acs-systems.js +29 -17
- package/lib/seam/connect/routes/acs-systems.js.map +1 -1
- package/lib/seam/connect/routes/acs-users.d.ts +18 -11
- package/lib/seam/connect/routes/acs-users.js +40 -14
- package/lib/seam/connect/routes/acs-users.js.map +1 -1
- package/lib/seam/connect/routes/acs.d.ts +5 -4
- package/lib/seam/connect/routes/acs.js +26 -14
- package/lib/seam/connect/routes/acs.js.map +1 -1
- package/lib/seam/connect/routes/action-attempts.d.ts +7 -6
- package/lib/seam/connect/routes/action-attempts.js +26 -14
- package/lib/seam/connect/routes/action-attempts.js.map +1 -1
- package/lib/seam/connect/routes/client-sessions.d.ts +13 -9
- package/lib/seam/connect/routes/client-sessions.js +33 -14
- package/lib/seam/connect/routes/client-sessions.js.map +1 -1
- package/lib/seam/connect/routes/connect-webviews.d.ts +11 -10
- package/lib/seam/connect/routes/connect-webviews.js +29 -17
- package/lib/seam/connect/routes/connect-webviews.js.map +1 -1
- package/lib/seam/connect/routes/connected-accounts.d.ts +8 -7
- package/lib/seam/connect/routes/connected-accounts.js +26 -14
- package/lib/seam/connect/routes/connected-accounts.js.map +1 -1
- package/lib/seam/connect/routes/devices-unmanaged.d.ts +8 -7
- package/lib/seam/connect/routes/devices-unmanaged.js +26 -14
- package/lib/seam/connect/routes/devices-unmanaged.js.map +1 -1
- package/lib/seam/connect/routes/devices.d.ts +10 -9
- package/lib/seam/connect/routes/devices.js +26 -14
- package/lib/seam/connect/routes/devices.js.map +1 -1
- package/lib/seam/connect/routes/events.d.ts +7 -6
- package/lib/seam/connect/routes/events.js +26 -14
- package/lib/seam/connect/routes/events.js.map +1 -1
- package/lib/seam/connect/routes/locks.d.ts +9 -8
- package/lib/seam/connect/routes/locks.js +26 -14
- package/lib/seam/connect/routes/locks.js.map +1 -1
- package/lib/seam/connect/routes/noise-sensors-noise-thresholds.d.ts +10 -9
- package/lib/seam/connect/routes/noise-sensors-noise-thresholds.js +26 -14
- package/lib/seam/connect/routes/noise-sensors-noise-thresholds.js.map +1 -1
- package/lib/seam/connect/routes/noise-sensors.d.ts +5 -4
- package/lib/seam/connect/routes/noise-sensors.js +26 -14
- package/lib/seam/connect/routes/noise-sensors.js.map +1 -1
- package/lib/seam/connect/routes/thermostats-climate-setting-schedules.d.ts +10 -9
- package/lib/seam/connect/routes/thermostats-climate-setting-schedules.js +26 -14
- package/lib/seam/connect/routes/thermostats-climate-setting-schedules.js.map +1 -1
- package/lib/seam/connect/routes/thermostats.d.ts +13 -12
- package/lib/seam/connect/routes/thermostats.js +26 -14
- package/lib/seam/connect/routes/thermostats.js.map +1 -1
- package/lib/seam/connect/routes/webhooks.d.ts +9 -8
- package/lib/seam/connect/routes/webhooks.js +26 -14
- package/lib/seam/connect/routes/webhooks.js.map +1 -1
- package/lib/seam/connect/routes/workspaces.d.ts +8 -7
- package/lib/seam/connect/routes/workspaces.js +26 -14
- package/lib/seam/connect/routes/workspaces.js.map +1 -1
- package/lib/seam/connect/seam-http.d.ts +24 -0
- package/lib/seam/connect/seam-http.js +82 -0
- package/lib/seam/connect/seam-http.js.map +1 -0
- package/package.json +7 -4
- package/src/lib/params-serializer.ts +55 -0
- package/src/lib/seam/connect/auth.ts +94 -6
- package/src/lib/seam/connect/client.ts +22 -127
- package/src/lib/seam/connect/env.d.ts +11 -0
- package/src/lib/seam/connect/index.ts +2 -1
- package/src/lib/seam/connect/{client-options.ts → options.ts} +13 -19
- package/src/lib/seam/connect/parse-options.ts +50 -23
- package/src/lib/seam/connect/routes/access-codes-unmanaged.ts +44 -31
- package/src/lib/seam/connect/routes/access-codes.ts +48 -48
- package/src/lib/seam/connect/routes/acs-access-groups.ts +49 -40
- package/src/lib/seam/connect/routes/acs-credentials.ts +40 -28
- package/src/lib/seam/connect/routes/acs-systems.ts +40 -30
- package/src/lib/seam/connect/routes/acs-users.ts +70 -36
- package/src/lib/seam/connect/routes/acs.ts +33 -17
- package/src/lib/seam/connect/routes/action-attempts.ts +36 -22
- package/src/lib/seam/connect/routes/client-sessions.ts +58 -30
- package/src/lib/seam/connect/routes/connect-webviews.ts +45 -34
- package/src/lib/seam/connect/routes/connected-accounts.ts +40 -25
- package/src/lib/seam/connect/routes/devices-unmanaged.ts +39 -25
- package/src/lib/seam/connect/routes/devices.ts +39 -31
- package/src/lib/seam/connect/routes/events.ts +36 -22
- package/src/lib/seam/connect/routes/locks.ts +38 -28
- package/src/lib/seam/connect/routes/noise-sensors-noise-thresholds.ts +47 -31
- package/src/lib/seam/connect/routes/noise-sensors.ts +33 -17
- package/src/lib/seam/connect/routes/thermostats-climate-setting-schedules.ts +47 -31
- package/src/lib/seam/connect/routes/thermostats.ts +42 -40
- package/src/lib/seam/connect/routes/webhooks.ts +38 -28
- package/src/lib/seam/connect/routes/workspaces.ts +38 -25
- package/src/lib/seam/connect/seam-http.ts +141 -0
- package/lib/seam/connect/axios.d.ts +0 -3
- package/lib/seam/connect/axios.js +0 -19
- package/lib/seam/connect/axios.js.map +0 -1
- package/lib/seam/connect/client-options.js.map +0 -1
- package/src/lib/seam/connect/axios.ts +0 -25
|
@@ -4,50 +4,53 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import type { RouteRequestBody, RouteResponse } from '@seamapi/types/connect'
|
|
7
|
-
import type { Axios } from 'axios'
|
|
8
7
|
import type { SetNonNullable } from 'type-fest'
|
|
9
8
|
|
|
10
|
-
import {
|
|
9
|
+
import { warnOnInsecureuserIdentifierKey } from 'lib/seam/connect/auth.js'
|
|
10
|
+
import { type Client, createClient } from 'lib/seam/connect/client.js'
|
|
11
11
|
import {
|
|
12
12
|
isSeamHttpOptionsWithApiKey,
|
|
13
13
|
isSeamHttpOptionsWithClient,
|
|
14
14
|
isSeamHttpOptionsWithClientSessionToken,
|
|
15
|
+
type SeamHttpFromPublishableKeyOptions,
|
|
15
16
|
SeamHttpInvalidOptionsError,
|
|
16
17
|
type SeamHttpOptions,
|
|
17
18
|
type SeamHttpOptionsWithApiKey,
|
|
18
19
|
type SeamHttpOptionsWithClient,
|
|
19
20
|
type SeamHttpOptionsWithClientSessionToken,
|
|
20
|
-
} from 'lib/seam/connect/
|
|
21
|
+
} from 'lib/seam/connect/options.js'
|
|
21
22
|
import { parseOptions } from 'lib/seam/connect/parse-options.js'
|
|
22
23
|
|
|
24
|
+
import { SeamHttpClientSessions } from './client-sessions.js'
|
|
25
|
+
|
|
23
26
|
export class SeamHttpAcsAccessGroups {
|
|
24
|
-
client:
|
|
27
|
+
client: Client
|
|
25
28
|
|
|
26
|
-
constructor(apiKeyOrOptions: string | SeamHttpOptions) {
|
|
27
|
-
const
|
|
28
|
-
this.client =
|
|
29
|
+
constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) {
|
|
30
|
+
const clientOptions = parseOptions(apiKeyOrOptions)
|
|
31
|
+
this.client = createClient(clientOptions)
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
static fromClient(
|
|
32
35
|
client: SeamHttpOptionsWithClient['client'],
|
|
33
36
|
options: Omit<SeamHttpOptionsWithClient, 'client'> = {},
|
|
34
37
|
): SeamHttpAcsAccessGroups {
|
|
35
|
-
const
|
|
36
|
-
if (!isSeamHttpOptionsWithClient(
|
|
38
|
+
const constructorOptions = { ...options, client }
|
|
39
|
+
if (!isSeamHttpOptionsWithClient(constructorOptions)) {
|
|
37
40
|
throw new SeamHttpInvalidOptionsError('Missing client')
|
|
38
41
|
}
|
|
39
|
-
return new SeamHttpAcsAccessGroups(
|
|
42
|
+
return new SeamHttpAcsAccessGroups(constructorOptions)
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
static fromApiKey(
|
|
43
46
|
apiKey: SeamHttpOptionsWithApiKey['apiKey'],
|
|
44
47
|
options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
|
|
45
48
|
): SeamHttpAcsAccessGroups {
|
|
46
|
-
const
|
|
47
|
-
if (!isSeamHttpOptionsWithApiKey(
|
|
49
|
+
const constructorOptions = { ...options, apiKey }
|
|
50
|
+
if (!isSeamHttpOptionsWithApiKey(constructorOptions)) {
|
|
48
51
|
throw new SeamHttpInvalidOptionsError('Missing apiKey')
|
|
49
52
|
}
|
|
50
|
-
return new SeamHttpAcsAccessGroups(
|
|
53
|
+
return new SeamHttpAcsAccessGroups(constructorOptions)
|
|
51
54
|
}
|
|
52
55
|
|
|
53
56
|
static fromClientSessionToken(
|
|
@@ -57,11 +60,26 @@ export class SeamHttpAcsAccessGroups {
|
|
|
57
60
|
'clientSessionToken'
|
|
58
61
|
> = {},
|
|
59
62
|
): SeamHttpAcsAccessGroups {
|
|
60
|
-
const
|
|
61
|
-
if (!isSeamHttpOptionsWithClientSessionToken(
|
|
63
|
+
const constructorOptions = { ...options, clientSessionToken }
|
|
64
|
+
if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) {
|
|
62
65
|
throw new SeamHttpInvalidOptionsError('Missing clientSessionToken')
|
|
63
66
|
}
|
|
64
|
-
return new SeamHttpAcsAccessGroups(
|
|
67
|
+
return new SeamHttpAcsAccessGroups(constructorOptions)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static async fromPublishableKey(
|
|
71
|
+
publishableKey: string,
|
|
72
|
+
userIdentifierKey: string,
|
|
73
|
+
options: SeamHttpFromPublishableKeyOptions = {},
|
|
74
|
+
): Promise<SeamHttpAcsAccessGroups> {
|
|
75
|
+
warnOnInsecureuserIdentifierKey(userIdentifierKey)
|
|
76
|
+
const clientOptions = parseOptions({ ...options, publishableKey })
|
|
77
|
+
const client = createClient(clientOptions)
|
|
78
|
+
const clientSessions = SeamHttpClientSessions.fromClient(client)
|
|
79
|
+
const { token } = await clientSessions.getOrCreate({
|
|
80
|
+
user_identifier_key: userIdentifierKey,
|
|
81
|
+
})
|
|
82
|
+
return SeamHttpAcsAccessGroups.fromClientSessionToken(token, options)
|
|
65
83
|
}
|
|
66
84
|
|
|
67
85
|
async addUser(body: AcsAccessGroupsAddUserBody): Promise<void> {
|
|
@@ -142,65 +160,56 @@ export class SeamHttpAcsAccessGroups {
|
|
|
142
160
|
}
|
|
143
161
|
}
|
|
144
162
|
|
|
145
|
-
export type AcsAccessGroupsAddUserBody =
|
|
146
|
-
|
|
147
|
-
>
|
|
163
|
+
export type AcsAccessGroupsAddUserBody =
|
|
164
|
+
RouteRequestBody<'/acs/access_groups/add_user'>
|
|
148
165
|
|
|
149
166
|
export type AcsAccessGroupsAddUserResponse = SetNonNullable<
|
|
150
167
|
Required<RouteResponse<'/acs/access_groups/add_user'>>
|
|
151
168
|
>
|
|
152
169
|
|
|
153
|
-
export type AcsAccessGroupsCreateBody =
|
|
154
|
-
|
|
155
|
-
>
|
|
170
|
+
export type AcsAccessGroupsCreateBody =
|
|
171
|
+
RouteRequestBody<'/acs/access_groups/create'>
|
|
156
172
|
|
|
157
173
|
export type AcsAccessGroupsCreateResponse = SetNonNullable<
|
|
158
174
|
Required<RouteResponse<'/acs/access_groups/create'>>
|
|
159
175
|
>
|
|
160
176
|
|
|
161
|
-
export type AcsAccessGroupsDeleteBody =
|
|
162
|
-
|
|
163
|
-
>
|
|
177
|
+
export type AcsAccessGroupsDeleteBody =
|
|
178
|
+
RouteRequestBody<'/acs/access_groups/delete'>
|
|
164
179
|
|
|
165
180
|
export type AcsAccessGroupsDeleteResponse = SetNonNullable<
|
|
166
181
|
Required<RouteResponse<'/acs/access_groups/delete'>>
|
|
167
182
|
>
|
|
168
183
|
|
|
169
|
-
export type AcsAccessGroupsGetBody =
|
|
170
|
-
Required<RouteRequestBody<'/acs/access_groups/get'>>
|
|
171
|
-
>
|
|
184
|
+
export type AcsAccessGroupsGetBody = RouteRequestBody<'/acs/access_groups/get'>
|
|
172
185
|
|
|
173
186
|
export type AcsAccessGroupsGetResponse = SetNonNullable<
|
|
174
187
|
Required<RouteResponse<'/acs/access_groups/get'>>
|
|
175
188
|
>
|
|
176
189
|
|
|
177
|
-
export type AcsAccessGroupsListBody =
|
|
178
|
-
|
|
179
|
-
>
|
|
190
|
+
export type AcsAccessGroupsListBody =
|
|
191
|
+
RouteRequestBody<'/acs/access_groups/list'>
|
|
180
192
|
|
|
181
193
|
export type AcsAccessGroupsListResponse = SetNonNullable<
|
|
182
194
|
Required<RouteResponse<'/acs/access_groups/list'>>
|
|
183
195
|
>
|
|
184
196
|
|
|
185
|
-
export type AcsAccessGroupsListUsersBody =
|
|
186
|
-
|
|
187
|
-
>
|
|
197
|
+
export type AcsAccessGroupsListUsersBody =
|
|
198
|
+
RouteRequestBody<'/acs/access_groups/list_users'>
|
|
188
199
|
|
|
189
200
|
export type AcsAccessGroupsListUsersResponse = SetNonNullable<
|
|
190
201
|
Required<RouteResponse<'/acs/access_groups/list_users'>>
|
|
191
202
|
>
|
|
192
203
|
|
|
193
|
-
export type AcsAccessGroupsRemoveUserBody =
|
|
194
|
-
|
|
195
|
-
>
|
|
204
|
+
export type AcsAccessGroupsRemoveUserBody =
|
|
205
|
+
RouteRequestBody<'/acs/access_groups/remove_user'>
|
|
196
206
|
|
|
197
207
|
export type AcsAccessGroupsRemoveUserResponse = SetNonNullable<
|
|
198
208
|
Required<RouteResponse<'/acs/access_groups/remove_user'>>
|
|
199
209
|
>
|
|
200
210
|
|
|
201
|
-
export type AcsAccessGroupsUpdateBody =
|
|
202
|
-
|
|
203
|
-
>
|
|
211
|
+
export type AcsAccessGroupsUpdateBody =
|
|
212
|
+
RouteRequestBody<'/acs/access_groups/update'>
|
|
204
213
|
|
|
205
214
|
export type AcsAccessGroupsUpdateResponse = SetNonNullable<
|
|
206
215
|
Required<RouteResponse<'/acs/access_groups/update'>>
|
|
@@ -4,50 +4,53 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import type { RouteRequestBody, RouteResponse } from '@seamapi/types/connect'
|
|
7
|
-
import type { Axios } from 'axios'
|
|
8
7
|
import type { SetNonNullable } from 'type-fest'
|
|
9
8
|
|
|
10
|
-
import {
|
|
9
|
+
import { warnOnInsecureuserIdentifierKey } from 'lib/seam/connect/auth.js'
|
|
10
|
+
import { type Client, createClient } from 'lib/seam/connect/client.js'
|
|
11
11
|
import {
|
|
12
12
|
isSeamHttpOptionsWithApiKey,
|
|
13
13
|
isSeamHttpOptionsWithClient,
|
|
14
14
|
isSeamHttpOptionsWithClientSessionToken,
|
|
15
|
+
type SeamHttpFromPublishableKeyOptions,
|
|
15
16
|
SeamHttpInvalidOptionsError,
|
|
16
17
|
type SeamHttpOptions,
|
|
17
18
|
type SeamHttpOptionsWithApiKey,
|
|
18
19
|
type SeamHttpOptionsWithClient,
|
|
19
20
|
type SeamHttpOptionsWithClientSessionToken,
|
|
20
|
-
} from 'lib/seam/connect/
|
|
21
|
+
} from 'lib/seam/connect/options.js'
|
|
21
22
|
import { parseOptions } from 'lib/seam/connect/parse-options.js'
|
|
22
23
|
|
|
24
|
+
import { SeamHttpClientSessions } from './client-sessions.js'
|
|
25
|
+
|
|
23
26
|
export class SeamHttpAcsCredentials {
|
|
24
|
-
client:
|
|
27
|
+
client: Client
|
|
25
28
|
|
|
26
|
-
constructor(apiKeyOrOptions: string | SeamHttpOptions) {
|
|
27
|
-
const
|
|
28
|
-
this.client =
|
|
29
|
+
constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) {
|
|
30
|
+
const clientOptions = parseOptions(apiKeyOrOptions)
|
|
31
|
+
this.client = createClient(clientOptions)
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
static fromClient(
|
|
32
35
|
client: SeamHttpOptionsWithClient['client'],
|
|
33
36
|
options: Omit<SeamHttpOptionsWithClient, 'client'> = {},
|
|
34
37
|
): SeamHttpAcsCredentials {
|
|
35
|
-
const
|
|
36
|
-
if (!isSeamHttpOptionsWithClient(
|
|
38
|
+
const constructorOptions = { ...options, client }
|
|
39
|
+
if (!isSeamHttpOptionsWithClient(constructorOptions)) {
|
|
37
40
|
throw new SeamHttpInvalidOptionsError('Missing client')
|
|
38
41
|
}
|
|
39
|
-
return new SeamHttpAcsCredentials(
|
|
42
|
+
return new SeamHttpAcsCredentials(constructorOptions)
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
static fromApiKey(
|
|
43
46
|
apiKey: SeamHttpOptionsWithApiKey['apiKey'],
|
|
44
47
|
options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
|
|
45
48
|
): SeamHttpAcsCredentials {
|
|
46
|
-
const
|
|
47
|
-
if (!isSeamHttpOptionsWithApiKey(
|
|
49
|
+
const constructorOptions = { ...options, apiKey }
|
|
50
|
+
if (!isSeamHttpOptionsWithApiKey(constructorOptions)) {
|
|
48
51
|
throw new SeamHttpInvalidOptionsError('Missing apiKey')
|
|
49
52
|
}
|
|
50
|
-
return new SeamHttpAcsCredentials(
|
|
53
|
+
return new SeamHttpAcsCredentials(constructorOptions)
|
|
51
54
|
}
|
|
52
55
|
|
|
53
56
|
static fromClientSessionToken(
|
|
@@ -57,11 +60,26 @@ export class SeamHttpAcsCredentials {
|
|
|
57
60
|
'clientSessionToken'
|
|
58
61
|
> = {},
|
|
59
62
|
): SeamHttpAcsCredentials {
|
|
60
|
-
const
|
|
61
|
-
if (!isSeamHttpOptionsWithClientSessionToken(
|
|
63
|
+
const constructorOptions = { ...options, clientSessionToken }
|
|
64
|
+
if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) {
|
|
62
65
|
throw new SeamHttpInvalidOptionsError('Missing clientSessionToken')
|
|
63
66
|
}
|
|
64
|
-
return new SeamHttpAcsCredentials(
|
|
67
|
+
return new SeamHttpAcsCredentials(constructorOptions)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static async fromPublishableKey(
|
|
71
|
+
publishableKey: string,
|
|
72
|
+
userIdentifierKey: string,
|
|
73
|
+
options: SeamHttpFromPublishableKeyOptions = {},
|
|
74
|
+
): Promise<SeamHttpAcsCredentials> {
|
|
75
|
+
warnOnInsecureuserIdentifierKey(userIdentifierKey)
|
|
76
|
+
const clientOptions = parseOptions({ ...options, publishableKey })
|
|
77
|
+
const client = createClient(clientOptions)
|
|
78
|
+
const clientSessions = SeamHttpClientSessions.fromClient(client)
|
|
79
|
+
const { token } = await clientSessions.getOrCreate({
|
|
80
|
+
user_identifier_key: userIdentifierKey,
|
|
81
|
+
})
|
|
82
|
+
return SeamHttpAcsCredentials.fromClientSessionToken(token, options)
|
|
65
83
|
}
|
|
66
84
|
|
|
67
85
|
async create(
|
|
@@ -106,33 +124,27 @@ export class SeamHttpAcsCredentials {
|
|
|
106
124
|
}
|
|
107
125
|
}
|
|
108
126
|
|
|
109
|
-
export type AcsCredentialsCreateBody =
|
|
110
|
-
|
|
111
|
-
>
|
|
127
|
+
export type AcsCredentialsCreateBody =
|
|
128
|
+
RouteRequestBody<'/acs/credentials/create'>
|
|
112
129
|
|
|
113
130
|
export type AcsCredentialsCreateResponse = SetNonNullable<
|
|
114
131
|
Required<RouteResponse<'/acs/credentials/create'>>
|
|
115
132
|
>
|
|
116
133
|
|
|
117
|
-
export type AcsCredentialsDeleteBody =
|
|
118
|
-
|
|
119
|
-
>
|
|
134
|
+
export type AcsCredentialsDeleteBody =
|
|
135
|
+
RouteRequestBody<'/acs/credentials/delete'>
|
|
120
136
|
|
|
121
137
|
export type AcsCredentialsDeleteResponse = SetNonNullable<
|
|
122
138
|
Required<RouteResponse<'/acs/credentials/delete'>>
|
|
123
139
|
>
|
|
124
140
|
|
|
125
|
-
export type AcsCredentialsGetBody =
|
|
126
|
-
Required<RouteRequestBody<'/acs/credentials/get'>>
|
|
127
|
-
>
|
|
141
|
+
export type AcsCredentialsGetBody = RouteRequestBody<'/acs/credentials/get'>
|
|
128
142
|
|
|
129
143
|
export type AcsCredentialsGetResponse = SetNonNullable<
|
|
130
144
|
Required<RouteResponse<'/acs/credentials/get'>>
|
|
131
145
|
>
|
|
132
146
|
|
|
133
|
-
export type AcsCredentialsListBody =
|
|
134
|
-
Required<RouteRequestBody<'/acs/credentials/list'>>
|
|
135
|
-
>
|
|
147
|
+
export type AcsCredentialsListBody = RouteRequestBody<'/acs/credentials/list'>
|
|
136
148
|
|
|
137
149
|
export type AcsCredentialsListResponse = SetNonNullable<
|
|
138
150
|
Required<RouteResponse<'/acs/credentials/list'>>
|
|
@@ -3,55 +3,54 @@
|
|
|
3
3
|
* Do not edit this file or add other files to this directory.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import type {
|
|
7
|
-
RouteRequestBody,
|
|
8
|
-
RouteRequestParams,
|
|
9
|
-
RouteResponse,
|
|
10
|
-
} from '@seamapi/types/connect'
|
|
11
|
-
import type { Axios } from 'axios'
|
|
6
|
+
import type { RouteRequestBody, RouteResponse } from '@seamapi/types/connect'
|
|
12
7
|
import type { SetNonNullable } from 'type-fest'
|
|
13
8
|
|
|
14
|
-
import {
|
|
9
|
+
import { warnOnInsecureuserIdentifierKey } from 'lib/seam/connect/auth.js'
|
|
10
|
+
import { type Client, createClient } from 'lib/seam/connect/client.js'
|
|
15
11
|
import {
|
|
16
12
|
isSeamHttpOptionsWithApiKey,
|
|
17
13
|
isSeamHttpOptionsWithClient,
|
|
18
14
|
isSeamHttpOptionsWithClientSessionToken,
|
|
15
|
+
type SeamHttpFromPublishableKeyOptions,
|
|
19
16
|
SeamHttpInvalidOptionsError,
|
|
20
17
|
type SeamHttpOptions,
|
|
21
18
|
type SeamHttpOptionsWithApiKey,
|
|
22
19
|
type SeamHttpOptionsWithClient,
|
|
23
20
|
type SeamHttpOptionsWithClientSessionToken,
|
|
24
|
-
} from 'lib/seam/connect/
|
|
21
|
+
} from 'lib/seam/connect/options.js'
|
|
25
22
|
import { parseOptions } from 'lib/seam/connect/parse-options.js'
|
|
26
23
|
|
|
24
|
+
import { SeamHttpClientSessions } from './client-sessions.js'
|
|
25
|
+
|
|
27
26
|
export class SeamHttpAcsSystems {
|
|
28
|
-
client:
|
|
27
|
+
client: Client
|
|
29
28
|
|
|
30
|
-
constructor(apiKeyOrOptions: string | SeamHttpOptions) {
|
|
31
|
-
const
|
|
32
|
-
this.client =
|
|
29
|
+
constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) {
|
|
30
|
+
const clientOptions = parseOptions(apiKeyOrOptions)
|
|
31
|
+
this.client = createClient(clientOptions)
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
static fromClient(
|
|
36
35
|
client: SeamHttpOptionsWithClient['client'],
|
|
37
36
|
options: Omit<SeamHttpOptionsWithClient, 'client'> = {},
|
|
38
37
|
): SeamHttpAcsSystems {
|
|
39
|
-
const
|
|
40
|
-
if (!isSeamHttpOptionsWithClient(
|
|
38
|
+
const constructorOptions = { ...options, client }
|
|
39
|
+
if (!isSeamHttpOptionsWithClient(constructorOptions)) {
|
|
41
40
|
throw new SeamHttpInvalidOptionsError('Missing client')
|
|
42
41
|
}
|
|
43
|
-
return new SeamHttpAcsSystems(
|
|
42
|
+
return new SeamHttpAcsSystems(constructorOptions)
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
static fromApiKey(
|
|
47
46
|
apiKey: SeamHttpOptionsWithApiKey['apiKey'],
|
|
48
47
|
options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
|
|
49
48
|
): SeamHttpAcsSystems {
|
|
50
|
-
const
|
|
51
|
-
if (!isSeamHttpOptionsWithApiKey(
|
|
49
|
+
const constructorOptions = { ...options, apiKey }
|
|
50
|
+
if (!isSeamHttpOptionsWithApiKey(constructorOptions)) {
|
|
52
51
|
throw new SeamHttpInvalidOptionsError('Missing apiKey')
|
|
53
52
|
}
|
|
54
|
-
return new SeamHttpAcsSystems(
|
|
53
|
+
return new SeamHttpAcsSystems(constructorOptions)
|
|
55
54
|
}
|
|
56
55
|
|
|
57
56
|
static fromClientSessionToken(
|
|
@@ -61,11 +60,26 @@ export class SeamHttpAcsSystems {
|
|
|
61
60
|
'clientSessionToken'
|
|
62
61
|
> = {},
|
|
63
62
|
): SeamHttpAcsSystems {
|
|
64
|
-
const
|
|
65
|
-
if (!isSeamHttpOptionsWithClientSessionToken(
|
|
63
|
+
const constructorOptions = { ...options, clientSessionToken }
|
|
64
|
+
if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) {
|
|
66
65
|
throw new SeamHttpInvalidOptionsError('Missing clientSessionToken')
|
|
67
66
|
}
|
|
68
|
-
return new SeamHttpAcsSystems(
|
|
67
|
+
return new SeamHttpAcsSystems(constructorOptions)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static async fromPublishableKey(
|
|
71
|
+
publishableKey: string,
|
|
72
|
+
userIdentifierKey: string,
|
|
73
|
+
options: SeamHttpFromPublishableKeyOptions = {},
|
|
74
|
+
): Promise<SeamHttpAcsSystems> {
|
|
75
|
+
warnOnInsecureuserIdentifierKey(userIdentifierKey)
|
|
76
|
+
const clientOptions = parseOptions({ ...options, publishableKey })
|
|
77
|
+
const client = createClient(clientOptions)
|
|
78
|
+
const clientSessions = SeamHttpClientSessions.fromClient(client)
|
|
79
|
+
const { token } = await clientSessions.getOrCreate({
|
|
80
|
+
user_identifier_key: userIdentifierKey,
|
|
81
|
+
})
|
|
82
|
+
return SeamHttpAcsSystems.fromClientSessionToken(token, options)
|
|
69
83
|
}
|
|
70
84
|
|
|
71
85
|
async get(
|
|
@@ -80,28 +94,24 @@ export class SeamHttpAcsSystems {
|
|
|
80
94
|
}
|
|
81
95
|
|
|
82
96
|
async list(
|
|
83
|
-
|
|
97
|
+
body: AcsSystemsListBody,
|
|
84
98
|
): Promise<AcsSystemsListResponse['acs_systems']> {
|
|
85
99
|
const { data } = await this.client.request<AcsSystemsListResponse>({
|
|
86
100
|
url: '/acs/systems/list',
|
|
87
|
-
method: '
|
|
88
|
-
|
|
101
|
+
method: 'post',
|
|
102
|
+
data: body,
|
|
89
103
|
})
|
|
90
104
|
return data.acs_systems
|
|
91
105
|
}
|
|
92
106
|
}
|
|
93
107
|
|
|
94
|
-
export type AcsSystemsGetBody =
|
|
95
|
-
Required<RouteRequestBody<'/acs/systems/get'>>
|
|
96
|
-
>
|
|
108
|
+
export type AcsSystemsGetBody = RouteRequestBody<'/acs/systems/get'>
|
|
97
109
|
|
|
98
110
|
export type AcsSystemsGetResponse = SetNonNullable<
|
|
99
111
|
Required<RouteResponse<'/acs/systems/get'>>
|
|
100
112
|
>
|
|
101
113
|
|
|
102
|
-
export type
|
|
103
|
-
Required<RouteRequestParams<'/acs/systems/list'>>
|
|
104
|
-
>
|
|
114
|
+
export type AcsSystemsListBody = RouteRequestBody<'/acs/systems/list'>
|
|
105
115
|
|
|
106
116
|
export type AcsSystemsListResponse = SetNonNullable<
|
|
107
117
|
Required<RouteResponse<'/acs/systems/list'>>
|
|
@@ -4,50 +4,53 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import type { RouteRequestBody, RouteResponse } from '@seamapi/types/connect'
|
|
7
|
-
import type { Axios } from 'axios'
|
|
8
7
|
import type { SetNonNullable } from 'type-fest'
|
|
9
8
|
|
|
10
|
-
import {
|
|
9
|
+
import { warnOnInsecureuserIdentifierKey } from 'lib/seam/connect/auth.js'
|
|
10
|
+
import { type Client, createClient } from 'lib/seam/connect/client.js'
|
|
11
11
|
import {
|
|
12
12
|
isSeamHttpOptionsWithApiKey,
|
|
13
13
|
isSeamHttpOptionsWithClient,
|
|
14
14
|
isSeamHttpOptionsWithClientSessionToken,
|
|
15
|
+
type SeamHttpFromPublishableKeyOptions,
|
|
15
16
|
SeamHttpInvalidOptionsError,
|
|
16
17
|
type SeamHttpOptions,
|
|
17
18
|
type SeamHttpOptionsWithApiKey,
|
|
18
19
|
type SeamHttpOptionsWithClient,
|
|
19
20
|
type SeamHttpOptionsWithClientSessionToken,
|
|
20
|
-
} from 'lib/seam/connect/
|
|
21
|
+
} from 'lib/seam/connect/options.js'
|
|
21
22
|
import { parseOptions } from 'lib/seam/connect/parse-options.js'
|
|
22
23
|
|
|
24
|
+
import { SeamHttpClientSessions } from './client-sessions.js'
|
|
25
|
+
|
|
23
26
|
export class SeamHttpAcsUsers {
|
|
24
|
-
client:
|
|
27
|
+
client: Client
|
|
25
28
|
|
|
26
|
-
constructor(apiKeyOrOptions: string | SeamHttpOptions) {
|
|
27
|
-
const
|
|
28
|
-
this.client =
|
|
29
|
+
constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) {
|
|
30
|
+
const clientOptions = parseOptions(apiKeyOrOptions)
|
|
31
|
+
this.client = createClient(clientOptions)
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
static fromClient(
|
|
32
35
|
client: SeamHttpOptionsWithClient['client'],
|
|
33
36
|
options: Omit<SeamHttpOptionsWithClient, 'client'> = {},
|
|
34
37
|
): SeamHttpAcsUsers {
|
|
35
|
-
const
|
|
36
|
-
if (!isSeamHttpOptionsWithClient(
|
|
38
|
+
const constructorOptions = { ...options, client }
|
|
39
|
+
if (!isSeamHttpOptionsWithClient(constructorOptions)) {
|
|
37
40
|
throw new SeamHttpInvalidOptionsError('Missing client')
|
|
38
41
|
}
|
|
39
|
-
return new SeamHttpAcsUsers(
|
|
42
|
+
return new SeamHttpAcsUsers(constructorOptions)
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
static fromApiKey(
|
|
43
46
|
apiKey: SeamHttpOptionsWithApiKey['apiKey'],
|
|
44
47
|
options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
|
|
45
48
|
): SeamHttpAcsUsers {
|
|
46
|
-
const
|
|
47
|
-
if (!isSeamHttpOptionsWithApiKey(
|
|
49
|
+
const constructorOptions = { ...options, apiKey }
|
|
50
|
+
if (!isSeamHttpOptionsWithApiKey(constructorOptions)) {
|
|
48
51
|
throw new SeamHttpInvalidOptionsError('Missing apiKey')
|
|
49
52
|
}
|
|
50
|
-
return new SeamHttpAcsUsers(
|
|
53
|
+
return new SeamHttpAcsUsers(constructorOptions)
|
|
51
54
|
}
|
|
52
55
|
|
|
53
56
|
static fromClientSessionToken(
|
|
@@ -57,11 +60,26 @@ export class SeamHttpAcsUsers {
|
|
|
57
60
|
'clientSessionToken'
|
|
58
61
|
> = {},
|
|
59
62
|
): SeamHttpAcsUsers {
|
|
60
|
-
const
|
|
61
|
-
if (!isSeamHttpOptionsWithClientSessionToken(
|
|
63
|
+
const constructorOptions = { ...options, clientSessionToken }
|
|
64
|
+
if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) {
|
|
62
65
|
throw new SeamHttpInvalidOptionsError('Missing clientSessionToken')
|
|
63
66
|
}
|
|
64
|
-
return new SeamHttpAcsUsers(
|
|
67
|
+
return new SeamHttpAcsUsers(constructorOptions)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static async fromPublishableKey(
|
|
71
|
+
publishableKey: string,
|
|
72
|
+
userIdentifierKey: string,
|
|
73
|
+
options: SeamHttpFromPublishableKeyOptions = {},
|
|
74
|
+
): Promise<SeamHttpAcsUsers> {
|
|
75
|
+
warnOnInsecureuserIdentifierKey(userIdentifierKey)
|
|
76
|
+
const clientOptions = parseOptions({ ...options, publishableKey })
|
|
77
|
+
const client = createClient(clientOptions)
|
|
78
|
+
const clientSessions = SeamHttpClientSessions.fromClient(client)
|
|
79
|
+
const { token } = await clientSessions.getOrCreate({
|
|
80
|
+
user_identifier_key: userIdentifierKey,
|
|
81
|
+
})
|
|
82
|
+
return SeamHttpAcsUsers.fromClientSessionToken(token, options)
|
|
65
83
|
}
|
|
66
84
|
|
|
67
85
|
async addToAccessGroup(body: AcsUsersAddToAccessGroupBody): Promise<void> {
|
|
@@ -121,6 +139,22 @@ export class SeamHttpAcsUsers {
|
|
|
121
139
|
})
|
|
122
140
|
}
|
|
123
141
|
|
|
142
|
+
async suspend(body: AcsUsersSuspendBody): Promise<void> {
|
|
143
|
+
await this.client.request<AcsUsersSuspendResponse>({
|
|
144
|
+
url: '/acs/users/suspend',
|
|
145
|
+
method: 'post',
|
|
146
|
+
data: body,
|
|
147
|
+
})
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async unsuspend(body: AcsUsersUnsuspendBody): Promise<void> {
|
|
151
|
+
await this.client.request<AcsUsersUnsuspendResponse>({
|
|
152
|
+
url: '/acs/users/unsuspend',
|
|
153
|
+
method: 'post',
|
|
154
|
+
data: body,
|
|
155
|
+
})
|
|
156
|
+
}
|
|
157
|
+
|
|
124
158
|
async update(body: AcsUsersUpdateBody): Promise<void> {
|
|
125
159
|
await this.client.request<AcsUsersUpdateResponse>({
|
|
126
160
|
url: '/acs/users/update',
|
|
@@ -130,58 +164,58 @@ export class SeamHttpAcsUsers {
|
|
|
130
164
|
}
|
|
131
165
|
}
|
|
132
166
|
|
|
133
|
-
export type AcsUsersAddToAccessGroupBody =
|
|
134
|
-
|
|
135
|
-
>
|
|
167
|
+
export type AcsUsersAddToAccessGroupBody =
|
|
168
|
+
RouteRequestBody<'/acs/users/add_to_access_group'>
|
|
136
169
|
|
|
137
170
|
export type AcsUsersAddToAccessGroupResponse = SetNonNullable<
|
|
138
171
|
Required<RouteResponse<'/acs/users/add_to_access_group'>>
|
|
139
172
|
>
|
|
140
173
|
|
|
141
|
-
export type AcsUsersCreateBody =
|
|
142
|
-
Required<RouteRequestBody<'/acs/users/create'>>
|
|
143
|
-
>
|
|
174
|
+
export type AcsUsersCreateBody = RouteRequestBody<'/acs/users/create'>
|
|
144
175
|
|
|
145
176
|
export type AcsUsersCreateResponse = SetNonNullable<
|
|
146
177
|
Required<RouteResponse<'/acs/users/create'>>
|
|
147
178
|
>
|
|
148
179
|
|
|
149
|
-
export type AcsUsersDeleteBody =
|
|
150
|
-
Required<RouteRequestBody<'/acs/users/delete'>>
|
|
151
|
-
>
|
|
180
|
+
export type AcsUsersDeleteBody = RouteRequestBody<'/acs/users/delete'>
|
|
152
181
|
|
|
153
182
|
export type AcsUsersDeleteResponse = SetNonNullable<
|
|
154
183
|
Required<RouteResponse<'/acs/users/delete'>>
|
|
155
184
|
>
|
|
156
185
|
|
|
157
|
-
export type AcsUsersGetBody =
|
|
158
|
-
Required<RouteRequestBody<'/acs/users/get'>>
|
|
159
|
-
>
|
|
186
|
+
export type AcsUsersGetBody = RouteRequestBody<'/acs/users/get'>
|
|
160
187
|
|
|
161
188
|
export type AcsUsersGetResponse = SetNonNullable<
|
|
162
189
|
Required<RouteResponse<'/acs/users/get'>>
|
|
163
190
|
>
|
|
164
191
|
|
|
165
|
-
export type AcsUsersListBody =
|
|
166
|
-
Required<RouteRequestBody<'/acs/users/list'>>
|
|
167
|
-
>
|
|
192
|
+
export type AcsUsersListBody = RouteRequestBody<'/acs/users/list'>
|
|
168
193
|
|
|
169
194
|
export type AcsUsersListResponse = SetNonNullable<
|
|
170
195
|
Required<RouteResponse<'/acs/users/list'>>
|
|
171
196
|
>
|
|
172
197
|
|
|
173
|
-
export type AcsUsersRemoveFromAccessGroupBody =
|
|
174
|
-
|
|
175
|
-
>
|
|
198
|
+
export type AcsUsersRemoveFromAccessGroupBody =
|
|
199
|
+
RouteRequestBody<'/acs/users/remove_from_access_group'>
|
|
176
200
|
|
|
177
201
|
export type AcsUsersRemoveFromAccessGroupResponse = SetNonNullable<
|
|
178
202
|
Required<RouteResponse<'/acs/users/remove_from_access_group'>>
|
|
179
203
|
>
|
|
180
204
|
|
|
181
|
-
export type
|
|
182
|
-
|
|
205
|
+
export type AcsUsersSuspendBody = RouteRequestBody<'/acs/users/suspend'>
|
|
206
|
+
|
|
207
|
+
export type AcsUsersSuspendResponse = SetNonNullable<
|
|
208
|
+
Required<RouteResponse<'/acs/users/suspend'>>
|
|
209
|
+
>
|
|
210
|
+
|
|
211
|
+
export type AcsUsersUnsuspendBody = RouteRequestBody<'/acs/users/unsuspend'>
|
|
212
|
+
|
|
213
|
+
export type AcsUsersUnsuspendResponse = SetNonNullable<
|
|
214
|
+
Required<RouteResponse<'/acs/users/unsuspend'>>
|
|
183
215
|
>
|
|
184
216
|
|
|
217
|
+
export type AcsUsersUpdateBody = RouteRequestBody<'/acs/users/update'>
|
|
218
|
+
|
|
185
219
|
export type AcsUsersUpdateResponse = SetNonNullable<
|
|
186
220
|
Required<RouteResponse<'/acs/users/update'>>
|
|
187
221
|
>
|