@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
|
@@ -3,54 +3,55 @@
|
|
|
3
3
|
* Do not edit this file or add other files to this directory.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
import { createAxiosClient } from 'lib/seam/connect/axios.js'
|
|
6
|
+
import { warnOnInsecureuserIdentifierKey } from 'lib/seam/connect/auth.js'
|
|
7
|
+
import { type Client, createClient } from 'lib/seam/connect/client.js'
|
|
9
8
|
import {
|
|
10
9
|
isSeamHttpOptionsWithApiKey,
|
|
11
10
|
isSeamHttpOptionsWithClient,
|
|
12
11
|
isSeamHttpOptionsWithClientSessionToken,
|
|
12
|
+
type SeamHttpFromPublishableKeyOptions,
|
|
13
13
|
SeamHttpInvalidOptionsError,
|
|
14
14
|
type SeamHttpOptions,
|
|
15
15
|
type SeamHttpOptionsWithApiKey,
|
|
16
16
|
type SeamHttpOptionsWithClient,
|
|
17
17
|
type SeamHttpOptionsWithClientSessionToken,
|
|
18
|
-
} from 'lib/seam/connect/
|
|
18
|
+
} from 'lib/seam/connect/options.js'
|
|
19
19
|
import { parseOptions } from 'lib/seam/connect/parse-options.js'
|
|
20
20
|
|
|
21
21
|
import { SeamHttpAcsAccessGroups } from './acs-access-groups.js'
|
|
22
22
|
import { SeamHttpAcsCredentials } from './acs-credentials.js'
|
|
23
23
|
import { SeamHttpAcsSystems } from './acs-systems.js'
|
|
24
24
|
import { SeamHttpAcsUsers } from './acs-users.js'
|
|
25
|
+
import { SeamHttpClientSessions } from './client-sessions.js'
|
|
25
26
|
|
|
26
27
|
export class SeamHttpAcs {
|
|
27
|
-
client:
|
|
28
|
+
client: Client
|
|
28
29
|
|
|
29
|
-
constructor(apiKeyOrOptions: string | SeamHttpOptions) {
|
|
30
|
-
const
|
|
31
|
-
this.client =
|
|
30
|
+
constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) {
|
|
31
|
+
const clientOptions = parseOptions(apiKeyOrOptions)
|
|
32
|
+
this.client = createClient(clientOptions)
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
static fromClient(
|
|
35
36
|
client: SeamHttpOptionsWithClient['client'],
|
|
36
37
|
options: Omit<SeamHttpOptionsWithClient, 'client'> = {},
|
|
37
38
|
): SeamHttpAcs {
|
|
38
|
-
const
|
|
39
|
-
if (!isSeamHttpOptionsWithClient(
|
|
39
|
+
const constructorOptions = { ...options, client }
|
|
40
|
+
if (!isSeamHttpOptionsWithClient(constructorOptions)) {
|
|
40
41
|
throw new SeamHttpInvalidOptionsError('Missing client')
|
|
41
42
|
}
|
|
42
|
-
return new SeamHttpAcs(
|
|
43
|
+
return new SeamHttpAcs(constructorOptions)
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
static fromApiKey(
|
|
46
47
|
apiKey: SeamHttpOptionsWithApiKey['apiKey'],
|
|
47
48
|
options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
|
|
48
49
|
): SeamHttpAcs {
|
|
49
|
-
const
|
|
50
|
-
if (!isSeamHttpOptionsWithApiKey(
|
|
50
|
+
const constructorOptions = { ...options, apiKey }
|
|
51
|
+
if (!isSeamHttpOptionsWithApiKey(constructorOptions)) {
|
|
51
52
|
throw new SeamHttpInvalidOptionsError('Missing apiKey')
|
|
52
53
|
}
|
|
53
|
-
return new SeamHttpAcs(
|
|
54
|
+
return new SeamHttpAcs(constructorOptions)
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
static fromClientSessionToken(
|
|
@@ -60,11 +61,26 @@ export class SeamHttpAcs {
|
|
|
60
61
|
'clientSessionToken'
|
|
61
62
|
> = {},
|
|
62
63
|
): SeamHttpAcs {
|
|
63
|
-
const
|
|
64
|
-
if (!isSeamHttpOptionsWithClientSessionToken(
|
|
64
|
+
const constructorOptions = { ...options, clientSessionToken }
|
|
65
|
+
if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) {
|
|
65
66
|
throw new SeamHttpInvalidOptionsError('Missing clientSessionToken')
|
|
66
67
|
}
|
|
67
|
-
return new SeamHttpAcs(
|
|
68
|
+
return new SeamHttpAcs(constructorOptions)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static async fromPublishableKey(
|
|
72
|
+
publishableKey: string,
|
|
73
|
+
userIdentifierKey: string,
|
|
74
|
+
options: SeamHttpFromPublishableKeyOptions = {},
|
|
75
|
+
): Promise<SeamHttpAcs> {
|
|
76
|
+
warnOnInsecureuserIdentifierKey(userIdentifierKey)
|
|
77
|
+
const clientOptions = parseOptions({ ...options, publishableKey })
|
|
78
|
+
const client = createClient(clientOptions)
|
|
79
|
+
const clientSessions = SeamHttpClientSessions.fromClient(client)
|
|
80
|
+
const { token } = await clientSessions.getOrCreate({
|
|
81
|
+
user_identifier_key: userIdentifierKey,
|
|
82
|
+
})
|
|
83
|
+
return SeamHttpAcs.fromClientSessionToken(token, options)
|
|
68
84
|
}
|
|
69
85
|
|
|
70
86
|
get accessGroups(): SeamHttpAcsAccessGroups {
|
|
@@ -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 SeamHttpActionAttempts {
|
|
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
|
): SeamHttpActionAttempts {
|
|
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 SeamHttpActionAttempts(
|
|
42
|
+
return new SeamHttpActionAttempts(constructorOptions)
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
static fromApiKey(
|
|
43
46
|
apiKey: SeamHttpOptionsWithApiKey['apiKey'],
|
|
44
47
|
options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
|
|
45
48
|
): SeamHttpActionAttempts {
|
|
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 SeamHttpActionAttempts(
|
|
53
|
+
return new SeamHttpActionAttempts(constructorOptions)
|
|
51
54
|
}
|
|
52
55
|
|
|
53
56
|
static fromClientSessionToken(
|
|
@@ -57,11 +60,26 @@ export class SeamHttpActionAttempts {
|
|
|
57
60
|
'clientSessionToken'
|
|
58
61
|
> = {},
|
|
59
62
|
): SeamHttpActionAttempts {
|
|
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 SeamHttpActionAttempts(
|
|
67
|
+
return new SeamHttpActionAttempts(constructorOptions)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static async fromPublishableKey(
|
|
71
|
+
publishableKey: string,
|
|
72
|
+
userIdentifierKey: string,
|
|
73
|
+
options: SeamHttpFromPublishableKeyOptions = {},
|
|
74
|
+
): Promise<SeamHttpActionAttempts> {
|
|
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 SeamHttpActionAttempts.fromClientSessionToken(token, options)
|
|
65
83
|
}
|
|
66
84
|
|
|
67
85
|
async get(
|
|
@@ -87,17 +105,13 @@ export class SeamHttpActionAttempts {
|
|
|
87
105
|
}
|
|
88
106
|
}
|
|
89
107
|
|
|
90
|
-
export type ActionAttemptsGetBody =
|
|
91
|
-
Required<RouteRequestBody<'/action_attempts/get'>>
|
|
92
|
-
>
|
|
108
|
+
export type ActionAttemptsGetBody = RouteRequestBody<'/action_attempts/get'>
|
|
93
109
|
|
|
94
110
|
export type ActionAttemptsGetResponse = SetNonNullable<
|
|
95
111
|
Required<RouteResponse<'/action_attempts/get'>>
|
|
96
112
|
>
|
|
97
113
|
|
|
98
|
-
export type ActionAttemptsListBody =
|
|
99
|
-
Required<RouteRequestBody<'/action_attempts/list'>>
|
|
100
|
-
>
|
|
114
|
+
export type ActionAttemptsListBody = RouteRequestBody<'/action_attempts/list'>
|
|
101
115
|
|
|
102
116
|
export type ActionAttemptsListResponse = SetNonNullable<
|
|
103
117
|
Required<RouteResponse<'/action_attempts/list'>>
|
|
@@ -4,50 +4,51 @@
|
|
|
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
|
|
|
23
24
|
export class SeamHttpClientSessions {
|
|
24
|
-
client:
|
|
25
|
+
client: Client
|
|
25
26
|
|
|
26
|
-
constructor(apiKeyOrOptions: string | SeamHttpOptions) {
|
|
27
|
-
const
|
|
28
|
-
this.client =
|
|
27
|
+
constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) {
|
|
28
|
+
const clientOptions = parseOptions(apiKeyOrOptions)
|
|
29
|
+
this.client = createClient(clientOptions)
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
static fromClient(
|
|
32
33
|
client: SeamHttpOptionsWithClient['client'],
|
|
33
34
|
options: Omit<SeamHttpOptionsWithClient, 'client'> = {},
|
|
34
35
|
): SeamHttpClientSessions {
|
|
35
|
-
const
|
|
36
|
-
if (!isSeamHttpOptionsWithClient(
|
|
36
|
+
const constructorOptions = { ...options, client }
|
|
37
|
+
if (!isSeamHttpOptionsWithClient(constructorOptions)) {
|
|
37
38
|
throw new SeamHttpInvalidOptionsError('Missing client')
|
|
38
39
|
}
|
|
39
|
-
return new SeamHttpClientSessions(
|
|
40
|
+
return new SeamHttpClientSessions(constructorOptions)
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
static fromApiKey(
|
|
43
44
|
apiKey: SeamHttpOptionsWithApiKey['apiKey'],
|
|
44
45
|
options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
|
|
45
46
|
): SeamHttpClientSessions {
|
|
46
|
-
const
|
|
47
|
-
if (!isSeamHttpOptionsWithApiKey(
|
|
47
|
+
const constructorOptions = { ...options, apiKey }
|
|
48
|
+
if (!isSeamHttpOptionsWithApiKey(constructorOptions)) {
|
|
48
49
|
throw new SeamHttpInvalidOptionsError('Missing apiKey')
|
|
49
50
|
}
|
|
50
|
-
return new SeamHttpClientSessions(
|
|
51
|
+
return new SeamHttpClientSessions(constructorOptions)
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
static fromClientSessionToken(
|
|
@@ -57,11 +58,26 @@ export class SeamHttpClientSessions {
|
|
|
57
58
|
'clientSessionToken'
|
|
58
59
|
> = {},
|
|
59
60
|
): SeamHttpClientSessions {
|
|
60
|
-
const
|
|
61
|
-
if (!isSeamHttpOptionsWithClientSessionToken(
|
|
61
|
+
const constructorOptions = { ...options, clientSessionToken }
|
|
62
|
+
if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) {
|
|
62
63
|
throw new SeamHttpInvalidOptionsError('Missing clientSessionToken')
|
|
63
64
|
}
|
|
64
|
-
return new SeamHttpClientSessions(
|
|
65
|
+
return new SeamHttpClientSessions(constructorOptions)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
static async fromPublishableKey(
|
|
69
|
+
publishableKey: string,
|
|
70
|
+
userIdentifierKey: string,
|
|
71
|
+
options: SeamHttpFromPublishableKeyOptions = {},
|
|
72
|
+
): Promise<SeamHttpClientSessions> {
|
|
73
|
+
warnOnInsecureuserIdentifierKey(userIdentifierKey)
|
|
74
|
+
const clientOptions = parseOptions({ ...options, publishableKey })
|
|
75
|
+
const client = createClient(clientOptions)
|
|
76
|
+
const clientSessions = SeamHttpClientSessions.fromClient(client)
|
|
77
|
+
const { token } = await clientSessions.getOrCreate({
|
|
78
|
+
user_identifier_key: userIdentifierKey,
|
|
79
|
+
})
|
|
80
|
+
return SeamHttpClientSessions.fromClientSessionToken(token, options)
|
|
65
81
|
}
|
|
66
82
|
|
|
67
83
|
async create(
|
|
@@ -94,6 +110,18 @@ export class SeamHttpClientSessions {
|
|
|
94
110
|
return data.client_session
|
|
95
111
|
}
|
|
96
112
|
|
|
113
|
+
async getOrCreate(
|
|
114
|
+
body: ClientSessionsGetOrCreateBody,
|
|
115
|
+
): Promise<ClientSessionsGetOrCreateResponse['client_session']> {
|
|
116
|
+
const { data } =
|
|
117
|
+
await this.client.request<ClientSessionsGetOrCreateResponse>({
|
|
118
|
+
url: '/client_sessions/get_or_create',
|
|
119
|
+
method: 'post',
|
|
120
|
+
data: body,
|
|
121
|
+
})
|
|
122
|
+
return data.client_session
|
|
123
|
+
}
|
|
124
|
+
|
|
97
125
|
async grantAccess(
|
|
98
126
|
body: ClientSessionsGrantAccessBody,
|
|
99
127
|
): Promise<ClientSessionsGrantAccessResponse['client_session']> {
|
|
@@ -118,41 +146,41 @@ export class SeamHttpClientSessions {
|
|
|
118
146
|
}
|
|
119
147
|
}
|
|
120
148
|
|
|
121
|
-
export type ClientSessionsCreateBody =
|
|
122
|
-
|
|
123
|
-
>
|
|
149
|
+
export type ClientSessionsCreateBody =
|
|
150
|
+
RouteRequestBody<'/client_sessions/create'>
|
|
124
151
|
|
|
125
152
|
export type ClientSessionsCreateResponse = SetNonNullable<
|
|
126
153
|
Required<RouteResponse<'/client_sessions/create'>>
|
|
127
154
|
>
|
|
128
155
|
|
|
129
|
-
export type ClientSessionsDeleteBody =
|
|
130
|
-
|
|
131
|
-
>
|
|
156
|
+
export type ClientSessionsDeleteBody =
|
|
157
|
+
RouteRequestBody<'/client_sessions/delete'>
|
|
132
158
|
|
|
133
159
|
export type ClientSessionsDeleteResponse = SetNonNullable<
|
|
134
160
|
Required<RouteResponse<'/client_sessions/delete'>>
|
|
135
161
|
>
|
|
136
162
|
|
|
137
|
-
export type ClientSessionsGetBody =
|
|
138
|
-
Required<RouteRequestBody<'/client_sessions/get'>>
|
|
139
|
-
>
|
|
163
|
+
export type ClientSessionsGetBody = RouteRequestBody<'/client_sessions/get'>
|
|
140
164
|
|
|
141
165
|
export type ClientSessionsGetResponse = SetNonNullable<
|
|
142
166
|
Required<RouteResponse<'/client_sessions/get'>>
|
|
143
167
|
>
|
|
144
168
|
|
|
145
|
-
export type
|
|
146
|
-
|
|
169
|
+
export type ClientSessionsGetOrCreateBody =
|
|
170
|
+
RouteRequestBody<'/client_sessions/get_or_create'>
|
|
171
|
+
|
|
172
|
+
export type ClientSessionsGetOrCreateResponse = SetNonNullable<
|
|
173
|
+
Required<RouteResponse<'/client_sessions/get_or_create'>>
|
|
147
174
|
>
|
|
148
175
|
|
|
176
|
+
export type ClientSessionsGrantAccessBody =
|
|
177
|
+
RouteRequestBody<'/client_sessions/grant_access'>
|
|
178
|
+
|
|
149
179
|
export type ClientSessionsGrantAccessResponse = SetNonNullable<
|
|
150
180
|
Required<RouteResponse<'/client_sessions/grant_access'>>
|
|
151
181
|
>
|
|
152
182
|
|
|
153
|
-
export type ClientSessionsListBody =
|
|
154
|
-
Required<RouteRequestBody<'/client_sessions/list'>>
|
|
155
|
-
>
|
|
183
|
+
export type ClientSessionsListBody = RouteRequestBody<'/client_sessions/list'>
|
|
156
184
|
|
|
157
185
|
export type ClientSessionsListResponse = SetNonNullable<
|
|
158
186
|
Required<RouteResponse<'/client_sessions/list'>>
|
|
@@ -8,50 +8,53 @@ import type {
|
|
|
8
8
|
RouteRequestParams,
|
|
9
9
|
RouteResponse,
|
|
10
10
|
} from '@seamapi/types/connect'
|
|
11
|
-
import type { Axios } from 'axios'
|
|
12
11
|
import type { SetNonNullable } from 'type-fest'
|
|
13
12
|
|
|
14
|
-
import {
|
|
13
|
+
import { warnOnInsecureuserIdentifierKey } from 'lib/seam/connect/auth.js'
|
|
14
|
+
import { type Client, createClient } from 'lib/seam/connect/client.js'
|
|
15
15
|
import {
|
|
16
16
|
isSeamHttpOptionsWithApiKey,
|
|
17
17
|
isSeamHttpOptionsWithClient,
|
|
18
18
|
isSeamHttpOptionsWithClientSessionToken,
|
|
19
|
+
type SeamHttpFromPublishableKeyOptions,
|
|
19
20
|
SeamHttpInvalidOptionsError,
|
|
20
21
|
type SeamHttpOptions,
|
|
21
22
|
type SeamHttpOptionsWithApiKey,
|
|
22
23
|
type SeamHttpOptionsWithClient,
|
|
23
24
|
type SeamHttpOptionsWithClientSessionToken,
|
|
24
|
-
} from 'lib/seam/connect/
|
|
25
|
+
} from 'lib/seam/connect/options.js'
|
|
25
26
|
import { parseOptions } from 'lib/seam/connect/parse-options.js'
|
|
26
27
|
|
|
28
|
+
import { SeamHttpClientSessions } from './client-sessions.js'
|
|
29
|
+
|
|
27
30
|
export class SeamHttpConnectWebviews {
|
|
28
|
-
client:
|
|
31
|
+
client: Client
|
|
29
32
|
|
|
30
|
-
constructor(apiKeyOrOptions: string | SeamHttpOptions) {
|
|
31
|
-
const
|
|
32
|
-
this.client =
|
|
33
|
+
constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) {
|
|
34
|
+
const clientOptions = parseOptions(apiKeyOrOptions)
|
|
35
|
+
this.client = createClient(clientOptions)
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
static fromClient(
|
|
36
39
|
client: SeamHttpOptionsWithClient['client'],
|
|
37
40
|
options: Omit<SeamHttpOptionsWithClient, 'client'> = {},
|
|
38
41
|
): SeamHttpConnectWebviews {
|
|
39
|
-
const
|
|
40
|
-
if (!isSeamHttpOptionsWithClient(
|
|
42
|
+
const constructorOptions = { ...options, client }
|
|
43
|
+
if (!isSeamHttpOptionsWithClient(constructorOptions)) {
|
|
41
44
|
throw new SeamHttpInvalidOptionsError('Missing client')
|
|
42
45
|
}
|
|
43
|
-
return new SeamHttpConnectWebviews(
|
|
46
|
+
return new SeamHttpConnectWebviews(constructorOptions)
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
static fromApiKey(
|
|
47
50
|
apiKey: SeamHttpOptionsWithApiKey['apiKey'],
|
|
48
51
|
options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
|
|
49
52
|
): SeamHttpConnectWebviews {
|
|
50
|
-
const
|
|
51
|
-
if (!isSeamHttpOptionsWithApiKey(
|
|
53
|
+
const constructorOptions = { ...options, apiKey }
|
|
54
|
+
if (!isSeamHttpOptionsWithApiKey(constructorOptions)) {
|
|
52
55
|
throw new SeamHttpInvalidOptionsError('Missing apiKey')
|
|
53
56
|
}
|
|
54
|
-
return new SeamHttpConnectWebviews(
|
|
57
|
+
return new SeamHttpConnectWebviews(constructorOptions)
|
|
55
58
|
}
|
|
56
59
|
|
|
57
60
|
static fromClientSessionToken(
|
|
@@ -61,11 +64,26 @@ export class SeamHttpConnectWebviews {
|
|
|
61
64
|
'clientSessionToken'
|
|
62
65
|
> = {},
|
|
63
66
|
): SeamHttpConnectWebviews {
|
|
64
|
-
const
|
|
65
|
-
if (!isSeamHttpOptionsWithClientSessionToken(
|
|
67
|
+
const constructorOptions = { ...options, clientSessionToken }
|
|
68
|
+
if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) {
|
|
66
69
|
throw new SeamHttpInvalidOptionsError('Missing clientSessionToken')
|
|
67
70
|
}
|
|
68
|
-
return new SeamHttpConnectWebviews(
|
|
71
|
+
return new SeamHttpConnectWebviews(constructorOptions)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
static async fromPublishableKey(
|
|
75
|
+
publishableKey: string,
|
|
76
|
+
userIdentifierKey: string,
|
|
77
|
+
options: SeamHttpFromPublishableKeyOptions = {},
|
|
78
|
+
): Promise<SeamHttpConnectWebviews> {
|
|
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 SeamHttpConnectWebviews.fromClientSessionToken(token, options)
|
|
69
87
|
}
|
|
70
88
|
|
|
71
89
|
async create(
|
|
@@ -99,12 +117,12 @@ export class SeamHttpConnectWebviews {
|
|
|
99
117
|
}
|
|
100
118
|
|
|
101
119
|
async list(
|
|
102
|
-
|
|
120
|
+
body: ConnectWebviewsListBody,
|
|
103
121
|
): Promise<ConnectWebviewsListResponse['connect_webviews']> {
|
|
104
122
|
const { data } = await this.client.request<ConnectWebviewsListResponse>({
|
|
105
123
|
url: '/connect_webviews/list',
|
|
106
|
-
method: '
|
|
107
|
-
|
|
124
|
+
method: 'post',
|
|
125
|
+
data: body,
|
|
108
126
|
})
|
|
109
127
|
return data.connect_webviews
|
|
110
128
|
}
|
|
@@ -118,41 +136,34 @@ export class SeamHttpConnectWebviews {
|
|
|
118
136
|
}
|
|
119
137
|
}
|
|
120
138
|
|
|
121
|
-
export type ConnectWebviewsCreateBody =
|
|
122
|
-
|
|
123
|
-
>
|
|
139
|
+
export type ConnectWebviewsCreateBody =
|
|
140
|
+
RouteRequestBody<'/connect_webviews/create'>
|
|
124
141
|
|
|
125
142
|
export type ConnectWebviewsCreateResponse = SetNonNullable<
|
|
126
143
|
Required<RouteResponse<'/connect_webviews/create'>>
|
|
127
144
|
>
|
|
128
145
|
|
|
129
|
-
export type ConnectWebviewsDeleteBody =
|
|
130
|
-
|
|
131
|
-
>
|
|
146
|
+
export type ConnectWebviewsDeleteBody =
|
|
147
|
+
RouteRequestBody<'/connect_webviews/delete'>
|
|
132
148
|
|
|
133
149
|
export type ConnectWebviewsDeleteResponse = SetNonNullable<
|
|
134
150
|
Required<RouteResponse<'/connect_webviews/delete'>>
|
|
135
151
|
>
|
|
136
152
|
|
|
137
|
-
export type ConnectWebviewsGetBody =
|
|
138
|
-
Required<RouteRequestBody<'/connect_webviews/get'>>
|
|
139
|
-
>
|
|
153
|
+
export type ConnectWebviewsGetBody = RouteRequestBody<'/connect_webviews/get'>
|
|
140
154
|
|
|
141
155
|
export type ConnectWebviewsGetResponse = SetNonNullable<
|
|
142
156
|
Required<RouteResponse<'/connect_webviews/get'>>
|
|
143
157
|
>
|
|
144
158
|
|
|
145
|
-
export type
|
|
146
|
-
Required<RouteRequestParams<'/connect_webviews/list'>>
|
|
147
|
-
>
|
|
159
|
+
export type ConnectWebviewsListBody = RouteRequestBody<'/connect_webviews/list'>
|
|
148
160
|
|
|
149
161
|
export type ConnectWebviewsListResponse = SetNonNullable<
|
|
150
162
|
Required<RouteResponse<'/connect_webviews/list'>>
|
|
151
163
|
>
|
|
152
164
|
|
|
153
|
-
export type ConnectWebviewsViewParams =
|
|
154
|
-
|
|
155
|
-
>
|
|
165
|
+
export type ConnectWebviewsViewParams =
|
|
166
|
+
RouteRequestParams<'/connect_webviews/view'>
|
|
156
167
|
|
|
157
168
|
export type ConnectWebviewsViewResponse = SetNonNullable<
|
|
158
169
|
Required<RouteResponse<'/connect_webviews/view'>>
|
|
@@ -8,50 +8,53 @@ import type {
|
|
|
8
8
|
RouteRequestParams,
|
|
9
9
|
RouteResponse,
|
|
10
10
|
} from '@seamapi/types/connect'
|
|
11
|
-
import type { Axios } from 'axios'
|
|
12
11
|
import type { SetNonNullable } from 'type-fest'
|
|
13
12
|
|
|
14
|
-
import {
|
|
13
|
+
import { warnOnInsecureuserIdentifierKey } from 'lib/seam/connect/auth.js'
|
|
14
|
+
import { type Client, createClient } from 'lib/seam/connect/client.js'
|
|
15
15
|
import {
|
|
16
16
|
isSeamHttpOptionsWithApiKey,
|
|
17
17
|
isSeamHttpOptionsWithClient,
|
|
18
18
|
isSeamHttpOptionsWithClientSessionToken,
|
|
19
|
+
type SeamHttpFromPublishableKeyOptions,
|
|
19
20
|
SeamHttpInvalidOptionsError,
|
|
20
21
|
type SeamHttpOptions,
|
|
21
22
|
type SeamHttpOptionsWithApiKey,
|
|
22
23
|
type SeamHttpOptionsWithClient,
|
|
23
24
|
type SeamHttpOptionsWithClientSessionToken,
|
|
24
|
-
} from 'lib/seam/connect/
|
|
25
|
+
} from 'lib/seam/connect/options.js'
|
|
25
26
|
import { parseOptions } from 'lib/seam/connect/parse-options.js'
|
|
26
27
|
|
|
28
|
+
import { SeamHttpClientSessions } from './client-sessions.js'
|
|
29
|
+
|
|
27
30
|
export class SeamHttpConnectedAccounts {
|
|
28
|
-
client:
|
|
31
|
+
client: Client
|
|
29
32
|
|
|
30
|
-
constructor(apiKeyOrOptions: string | SeamHttpOptions) {
|
|
31
|
-
const
|
|
32
|
-
this.client =
|
|
33
|
+
constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) {
|
|
34
|
+
const clientOptions = parseOptions(apiKeyOrOptions)
|
|
35
|
+
this.client = createClient(clientOptions)
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
static fromClient(
|
|
36
39
|
client: SeamHttpOptionsWithClient['client'],
|
|
37
40
|
options: Omit<SeamHttpOptionsWithClient, 'client'> = {},
|
|
38
41
|
): SeamHttpConnectedAccounts {
|
|
39
|
-
const
|
|
40
|
-
if (!isSeamHttpOptionsWithClient(
|
|
42
|
+
const constructorOptions = { ...options, client }
|
|
43
|
+
if (!isSeamHttpOptionsWithClient(constructorOptions)) {
|
|
41
44
|
throw new SeamHttpInvalidOptionsError('Missing client')
|
|
42
45
|
}
|
|
43
|
-
return new SeamHttpConnectedAccounts(
|
|
46
|
+
return new SeamHttpConnectedAccounts(constructorOptions)
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
static fromApiKey(
|
|
47
50
|
apiKey: SeamHttpOptionsWithApiKey['apiKey'],
|
|
48
51
|
options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
|
|
49
52
|
): SeamHttpConnectedAccounts {
|
|
50
|
-
const
|
|
51
|
-
if (!isSeamHttpOptionsWithApiKey(
|
|
53
|
+
const constructorOptions = { ...options, apiKey }
|
|
54
|
+
if (!isSeamHttpOptionsWithApiKey(constructorOptions)) {
|
|
52
55
|
throw new SeamHttpInvalidOptionsError('Missing apiKey')
|
|
53
56
|
}
|
|
54
|
-
return new SeamHttpConnectedAccounts(
|
|
57
|
+
return new SeamHttpConnectedAccounts(constructorOptions)
|
|
55
58
|
}
|
|
56
59
|
|
|
57
60
|
static fromClientSessionToken(
|
|
@@ -61,11 +64,26 @@ export class SeamHttpConnectedAccounts {
|
|
|
61
64
|
'clientSessionToken'
|
|
62
65
|
> = {},
|
|
63
66
|
): SeamHttpConnectedAccounts {
|
|
64
|
-
const
|
|
65
|
-
if (!isSeamHttpOptionsWithClientSessionToken(
|
|
67
|
+
const constructorOptions = { ...options, clientSessionToken }
|
|
68
|
+
if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) {
|
|
66
69
|
throw new SeamHttpInvalidOptionsError('Missing clientSessionToken')
|
|
67
70
|
}
|
|
68
|
-
return new SeamHttpConnectedAccounts(
|
|
71
|
+
return new SeamHttpConnectedAccounts(constructorOptions)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
static async fromPublishableKey(
|
|
75
|
+
publishableKey: string,
|
|
76
|
+
userIdentifierKey: string,
|
|
77
|
+
options: SeamHttpFromPublishableKeyOptions = {},
|
|
78
|
+
): Promise<SeamHttpConnectedAccounts> {
|
|
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 SeamHttpConnectedAccounts.fromClientSessionToken(token, options)
|
|
69
87
|
}
|
|
70
88
|
|
|
71
89
|
async delete(body: ConnectedAccountsDeleteBody): Promise<void> {
|
|
@@ -99,25 +117,22 @@ export class SeamHttpConnectedAccounts {
|
|
|
99
117
|
}
|
|
100
118
|
}
|
|
101
119
|
|
|
102
|
-
export type ConnectedAccountsDeleteBody =
|
|
103
|
-
|
|
104
|
-
>
|
|
120
|
+
export type ConnectedAccountsDeleteBody =
|
|
121
|
+
RouteRequestBody<'/connected_accounts/delete'>
|
|
105
122
|
|
|
106
123
|
export type ConnectedAccountsDeleteResponse = SetNonNullable<
|
|
107
124
|
Required<RouteResponse<'/connected_accounts/delete'>>
|
|
108
125
|
>
|
|
109
126
|
|
|
110
|
-
export type ConnectedAccountsGetBody =
|
|
111
|
-
|
|
112
|
-
>
|
|
127
|
+
export type ConnectedAccountsGetBody =
|
|
128
|
+
RouteRequestBody<'/connected_accounts/get'>
|
|
113
129
|
|
|
114
130
|
export type ConnectedAccountsGetResponse = SetNonNullable<
|
|
115
131
|
Required<RouteResponse<'/connected_accounts/get'>>
|
|
116
132
|
>
|
|
117
133
|
|
|
118
|
-
export type ConnectedAccountsListParams =
|
|
119
|
-
|
|
120
|
-
>
|
|
134
|
+
export type ConnectedAccountsListParams =
|
|
135
|
+
RouteRequestParams<'/connected_accounts/list'>
|
|
121
136
|
|
|
122
137
|
export type ConnectedAccountsListResponse = SetNonNullable<
|
|
123
138
|
Required<RouteResponse<'/connected_accounts/list'>>
|