@seamapi/http 0.0.2 → 0.1.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 +1386 -61
- package/dist/connect.cjs.map +1 -1
- package/dist/connect.d.cts +420 -7
- package/lib/seam/connect/auth.d.ts +1 -1
- package/lib/seam/connect/auth.js +7 -7
- package/lib/seam/connect/auth.js.map +1 -1
- package/lib/seam/connect/axios.js +3 -1
- package/lib/seam/connect/axios.js.map +1 -1
- package/lib/seam/connect/client-options.d.ts +7 -3
- package/lib/seam/connect/client-options.js +18 -3
- package/lib/seam/connect/client-options.js.map +1 -1
- package/lib/seam/connect/client.d.ts +16 -4
- package/lib/seam/connect/client.js +55 -28
- package/lib/seam/connect/client.js.map +1 -1
- package/lib/seam/connect/parse-options.d.ts +1 -1
- package/lib/seam/connect/parse-options.js +8 -1
- package/lib/seam/connect/parse-options.js.map +1 -1
- package/lib/seam/connect/routes/access-codes-unmanaged.d.ts +26 -0
- package/lib/seam/connect/routes/access-codes-unmanaged.js +72 -0
- package/lib/seam/connect/routes/access-codes-unmanaged.js.map +1 -0
- package/lib/seam/connect/routes/access-codes.d.ts +37 -0
- package/lib/seam/connect/routes/access-codes.js +101 -0
- package/lib/seam/connect/routes/access-codes.js.map +1 -0
- package/lib/seam/connect/routes/acs-access-groups.d.ts +35 -0
- package/lib/seam/connect/routes/acs-access-groups.js +95 -0
- package/lib/seam/connect/routes/acs-access-groups.js.map +1 -0
- package/lib/seam/connect/routes/acs-credentials.d.ts +23 -0
- package/lib/seam/connect/routes/acs-credentials.js +66 -0
- package/lib/seam/connect/routes/acs-credentials.js.map +1 -0
- package/lib/seam/connect/routes/acs-systems.d.ts +17 -0
- package/lib/seam/connect/routes/acs-systems.js +51 -0
- package/lib/seam/connect/routes/acs-systems.js.map +1 -0
- package/lib/seam/connect/routes/acs-users.d.ts +32 -0
- package/lib/seam/connect/routes/acs-users.js +87 -0
- package/lib/seam/connect/routes/acs-users.js.map +1 -0
- package/lib/seam/connect/routes/acs.d.ts +17 -0
- package/lib/seam/connect/routes/acs.js +51 -0
- package/lib/seam/connect/routes/acs.js.map +1 -0
- package/lib/seam/connect/routes/action-attempts.d.ts +17 -0
- package/lib/seam/connect/routes/action-attempts.js +51 -0
- package/lib/seam/connect/routes/action-attempts.js.map +1 -0
- package/lib/seam/connect/routes/client-sessions.d.ts +26 -0
- package/lib/seam/connect/routes/client-sessions.js +74 -0
- package/lib/seam/connect/routes/client-sessions.js.map +1 -0
- package/lib/seam/connect/routes/connect-webviews.d.ts +26 -0
- package/lib/seam/connect/routes/connect-webviews.js +73 -0
- package/lib/seam/connect/routes/connect-webviews.js.map +1 -0
- package/lib/seam/connect/routes/connected-accounts.d.ts +20 -0
- package/lib/seam/connect/routes/connected-accounts.js +58 -0
- package/lib/seam/connect/routes/connected-accounts.js.map +1 -0
- package/lib/seam/connect/routes/devices-unmanaged.d.ts +20 -0
- package/lib/seam/connect/routes/devices-unmanaged.js +58 -0
- package/lib/seam/connect/routes/devices-unmanaged.js.map +1 -0
- package/lib/seam/connect/routes/devices.d.ts +28 -0
- package/lib/seam/connect/routes/devices.js +77 -0
- package/lib/seam/connect/routes/devices.js.map +1 -0
- package/lib/seam/connect/routes/events.d.ts +17 -0
- package/lib/seam/connect/routes/events.js +51 -0
- package/lib/seam/connect/routes/events.js.map +1 -0
- package/lib/seam/connect/routes/index.d.ts +21 -0
- package/lib/seam/connect/routes/index.js +22 -0
- package/lib/seam/connect/routes/index.js.map +1 -0
- package/lib/seam/connect/routes/locks.d.ts +23 -0
- package/lib/seam/connect/routes/locks.js +67 -0
- package/lib/seam/connect/routes/locks.js.map +1 -0
- package/lib/seam/connect/routes/noise-sensors-noise-thresholds.d.ts +26 -0
- package/lib/seam/connect/routes/noise-sensors-noise-thresholds.js +72 -0
- package/lib/seam/connect/routes/noise-sensors-noise-thresholds.js.map +1 -0
- package/lib/seam/connect/routes/noise-sensors.d.ts +11 -0
- package/lib/seam/connect/routes/noise-sensors.js +39 -0
- package/lib/seam/connect/routes/noise-sensors.js.map +1 -0
- package/lib/seam/connect/routes/thermostats-climate-setting-schedules.d.ts +26 -0
- package/lib/seam/connect/routes/thermostats-climate-setting-schedules.js +73 -0
- package/lib/seam/connect/routes/thermostats-climate-setting-schedules.js.map +1 -0
- package/lib/seam/connect/routes/thermostats.d.ts +37 -0
- package/lib/seam/connect/routes/thermostats.js +97 -0
- package/lib/seam/connect/routes/thermostats.js.map +1 -0
- package/lib/seam/connect/routes/webhooks.d.ts +23 -0
- package/lib/seam/connect/routes/webhooks.js +66 -0
- package/lib/seam/connect/routes/webhooks.js.map +1 -0
- package/lib/seam/connect/routes/workspaces.d.ts +14 -5
- package/lib/seam/connect/routes/workspaces.js +48 -10
- package/lib/seam/connect/routes/workspaces.js.map +1 -1
- package/package.json +4 -1
- package/src/lib/seam/connect/auth.ts +7 -7
- package/src/lib/seam/connect/axios.ts +2 -0
- package/src/lib/seam/connect/client-options.ts +32 -4
- package/src/lib/seam/connect/client.ts +88 -15
- package/src/lib/seam/connect/parse-options.ts +16 -2
- package/src/lib/seam/connect/routes/access-codes-unmanaged.ts +157 -0
- package/src/lib/seam/connect/routes/access-codes.ts +226 -0
- package/src/lib/seam/connect/routes/acs-access-groups.ts +207 -0
- package/src/lib/seam/connect/routes/acs-credentials.ts +139 -0
- package/src/lib/seam/connect/routes/acs-systems.ts +108 -0
- package/src/lib/seam/connect/routes/acs-users.ts +187 -0
- package/src/lib/seam/connect/routes/acs.ts +85 -0
- package/src/lib/seam/connect/routes/action-attempts.ts +104 -0
- package/src/lib/seam/connect/routes/client-sessions.ts +159 -0
- package/src/lib/seam/connect/routes/connect-webviews.ts +159 -0
- package/src/lib/seam/connect/routes/connected-accounts.ts +124 -0
- package/src/lib/seam/connect/routes/devices-unmanaged.ts +120 -0
- package/src/lib/seam/connect/routes/devices.ts +158 -0
- package/src/lib/seam/connect/routes/events.ts +100 -0
- package/src/lib/seam/connect/routes/index.ts +21 -0
- package/src/lib/seam/connect/routes/locks.ts +138 -0
- package/src/lib/seam/connect/routes/noise-sensors-noise-thresholds.ts +154 -0
- package/src/lib/seam/connect/routes/noise-sensors.ts +70 -0
- package/src/lib/seam/connect/routes/thermostats-climate-setting-schedules.ts +176 -0
- package/src/lib/seam/connect/routes/thermostats.ts +206 -0
- package/src/lib/seam/connect/routes/webhooks.ts +141 -0
- package/src/lib/seam/connect/routes/workspaces.ts +100 -17
- package/lib/seam/connect/legacy/workspaces.d.ts +0 -8
- package/lib/seam/connect/legacy/workspaces.js +0 -10
- package/lib/seam/connect/legacy/workspaces.js.map +0 -1
- package/src/lib/seam/connect/legacy/workspaces.ts +0 -26
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
InvalidSeamHttpOptionsError,
|
|
3
2
|
isSeamHttpOptionsWithApiKey,
|
|
4
3
|
isSeamHttpOptionsWithClientSessionToken,
|
|
4
|
+
SeamHttpInvalidOptionsError,
|
|
5
5
|
type SeamHttpOptions,
|
|
6
6
|
type SeamHttpOptionsWithApiKey,
|
|
7
7
|
type SeamHttpOptionsWithClientSessionToken,
|
|
@@ -18,7 +18,7 @@ export const getAuthHeaders = (options: SeamHttpOptions): Headers => {
|
|
|
18
18
|
return getAuthHeadersForClientSessionToken(options)
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
throw new
|
|
21
|
+
throw new SeamHttpInvalidOptionsError(
|
|
22
22
|
'Must specify an apiKey or clientSessionToken',
|
|
23
23
|
)
|
|
24
24
|
}
|
|
@@ -27,19 +27,19 @@ const getAuthHeadersForApiKey = ({
|
|
|
27
27
|
apiKey,
|
|
28
28
|
}: SeamHttpOptionsWithApiKey): Headers => {
|
|
29
29
|
if (isClientSessionToken(apiKey)) {
|
|
30
|
-
throw new
|
|
30
|
+
throw new SeamHttpInvalidTokenError(
|
|
31
31
|
'A Client Session Token cannot be used as an apiKey',
|
|
32
32
|
)
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
if (isAccessToken(apiKey)) {
|
|
36
|
-
throw new
|
|
36
|
+
throw new SeamHttpInvalidTokenError(
|
|
37
37
|
'An access token cannot be used as an apiKey',
|
|
38
38
|
)
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
if (isJwt(apiKey) || !isSeamToken(apiKey)) {
|
|
42
|
-
throw new
|
|
42
|
+
throw new SeamHttpInvalidTokenError(
|
|
43
43
|
`Unknown or invalid apiKey format, expected token to start with ${tokenPrefix}`,
|
|
44
44
|
)
|
|
45
45
|
}
|
|
@@ -53,7 +53,7 @@ const getAuthHeadersForClientSessionToken = ({
|
|
|
53
53
|
clientSessionToken,
|
|
54
54
|
}: SeamHttpOptionsWithClientSessionToken): Headers => {
|
|
55
55
|
if (!isClientSessionToken(clientSessionToken)) {
|
|
56
|
-
throw new
|
|
56
|
+
throw new SeamHttpInvalidTokenError(
|
|
57
57
|
`Unknown or invalid clientSessionToken format, expected token to start with ${clientSessionTokenPrefix}`,
|
|
58
58
|
)
|
|
59
59
|
}
|
|
@@ -64,7 +64,7 @@ const getAuthHeadersForClientSessionToken = ({
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
export class
|
|
67
|
+
export class SeamHttpInvalidTokenError extends Error {
|
|
68
68
|
constructor(message: string) {
|
|
69
69
|
super(`SeamHttp received an invalid token: ${message}`)
|
|
70
70
|
this.name = this.constructor.name
|
|
@@ -2,6 +2,7 @@ import axios, { type Axios } from 'axios'
|
|
|
2
2
|
|
|
3
3
|
import { getAuthHeaders } from './auth.js'
|
|
4
4
|
import {
|
|
5
|
+
isSeamHttpOptionsWithClient,
|
|
5
6
|
isSeamHttpOptionsWithClientSessionToken,
|
|
6
7
|
type SeamHttpOptions,
|
|
7
8
|
} from './client-options.js'
|
|
@@ -9,6 +10,7 @@ import {
|
|
|
9
10
|
export const createAxiosClient = (
|
|
10
11
|
options: Required<SeamHttpOptions>,
|
|
11
12
|
): Axios => {
|
|
13
|
+
if (isSeamHttpOptionsWithClient(options)) return options.client
|
|
12
14
|
// TODO: axiosRetry? Allow options to configure this if so
|
|
13
15
|
return axios.create({
|
|
14
16
|
baseURL: options.endpoint,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { AxiosRequestConfig } from 'axios'
|
|
1
|
+
import type { Axios, AxiosRequestConfig } from 'axios'
|
|
2
2
|
|
|
3
3
|
export type SeamHttpOptions =
|
|
4
|
+
| SeamHttpOptionsWithClient
|
|
4
5
|
| SeamHttpOptionsWithApiKey
|
|
5
6
|
| SeamHttpOptionsWithClientSessionToken
|
|
6
7
|
|
|
@@ -10,6 +11,31 @@ interface SeamHttpCommonOptions {
|
|
|
10
11
|
enableLegacyMethodBehaivor?: boolean
|
|
11
12
|
}
|
|
12
13
|
|
|
14
|
+
export interface SeamHttpOptionsWithClient
|
|
15
|
+
extends Pick<SeamHttpCommonOptions, 'enableLegacyMethodBehaivor'> {
|
|
16
|
+
client: Axios
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const isSeamHttpOptionsWithClient = (
|
|
20
|
+
options: SeamHttpOptions,
|
|
21
|
+
): options is SeamHttpOptionsWithClient => {
|
|
22
|
+
if (!('client' in options)) return false
|
|
23
|
+
if (options.client == null) return false
|
|
24
|
+
|
|
25
|
+
const keys = Object.keys(options).filter(
|
|
26
|
+
(k) => !['client', 'enableLegacyMethodBehaivor'].includes(k),
|
|
27
|
+
)
|
|
28
|
+
if (keys.length > 0) {
|
|
29
|
+
throw new SeamHttpInvalidOptionsError(
|
|
30
|
+
`The client option cannot be used with any other option except enableLegacyMethodBehaivor, but received: ${keys.join(
|
|
31
|
+
', ',
|
|
32
|
+
)}`,
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return true
|
|
37
|
+
}
|
|
38
|
+
|
|
13
39
|
export interface SeamHttpOptionsWithApiKey extends SeamHttpCommonOptions {
|
|
14
40
|
apiKey: string
|
|
15
41
|
}
|
|
@@ -18,9 +44,10 @@ export const isSeamHttpOptionsWithApiKey = (
|
|
|
18
44
|
options: SeamHttpOptions,
|
|
19
45
|
): options is SeamHttpOptionsWithApiKey => {
|
|
20
46
|
if (!('apiKey' in options)) return false
|
|
47
|
+
if (options.apiKey == null) return false
|
|
21
48
|
|
|
22
49
|
if ('clientSessionToken' in options && options.clientSessionToken != null) {
|
|
23
|
-
throw new
|
|
50
|
+
throw new SeamHttpInvalidOptionsError(
|
|
24
51
|
'The clientSessionToken option cannot be used with the apiKey option.',
|
|
25
52
|
)
|
|
26
53
|
}
|
|
@@ -37,9 +64,10 @@ export const isSeamHttpOptionsWithClientSessionToken = (
|
|
|
37
64
|
options: SeamHttpOptions,
|
|
38
65
|
): options is SeamHttpOptionsWithClientSessionToken => {
|
|
39
66
|
if (!('clientSessionToken' in options)) return false
|
|
67
|
+
if (options.clientSessionToken == null) return false
|
|
40
68
|
|
|
41
69
|
if ('apiKey' in options && options.apiKey != null) {
|
|
42
|
-
throw new
|
|
70
|
+
throw new SeamHttpInvalidOptionsError(
|
|
43
71
|
'The clientSessionToken option cannot be used with the apiKey option.',
|
|
44
72
|
)
|
|
45
73
|
}
|
|
@@ -47,7 +75,7 @@ export const isSeamHttpOptionsWithClientSessionToken = (
|
|
|
47
75
|
return true
|
|
48
76
|
}
|
|
49
77
|
|
|
50
|
-
export class
|
|
78
|
+
export class SeamHttpInvalidOptionsError extends Error {
|
|
51
79
|
constructor(message: string) {
|
|
52
80
|
super(`SeamHttp received invalid options: ${message}`)
|
|
53
81
|
this.name = this.constructor.name
|
|
@@ -2,35 +2,61 @@ import type { Axios } from 'axios'
|
|
|
2
2
|
|
|
3
3
|
import { createAxiosClient } from './axios.js'
|
|
4
4
|
import {
|
|
5
|
-
InvalidSeamHttpOptionsError,
|
|
6
5
|
isSeamHttpOptionsWithApiKey,
|
|
6
|
+
isSeamHttpOptionsWithClient,
|
|
7
7
|
isSeamHttpOptionsWithClientSessionToken,
|
|
8
|
+
SeamHttpInvalidOptionsError,
|
|
8
9
|
type SeamHttpOptions,
|
|
9
10
|
type SeamHttpOptionsWithApiKey,
|
|
11
|
+
type SeamHttpOptionsWithClient,
|
|
10
12
|
type SeamHttpOptionsWithClientSessionToken,
|
|
11
13
|
} from './client-options.js'
|
|
12
|
-
import { LegacyWorkspacesHttp } from './legacy/workspaces.js'
|
|
13
14
|
import { parseOptions } from './parse-options.js'
|
|
14
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
SeamHttpAccessCodes,
|
|
17
|
+
SeamHttpAcs,
|
|
18
|
+
SeamHttpActionAttempts,
|
|
19
|
+
SeamHttpClientSessions,
|
|
20
|
+
SeamHttpConnectedAccounts,
|
|
21
|
+
SeamHttpConnectWebviews,
|
|
22
|
+
SeamHttpDevices,
|
|
23
|
+
SeamHttpEvents,
|
|
24
|
+
SeamHttpLocks,
|
|
25
|
+
SeamHttpNoiseSensors,
|
|
26
|
+
SeamHttpThermostats,
|
|
27
|
+
SeamHttpWebhooks,
|
|
28
|
+
SeamHttpWorkspaces,
|
|
29
|
+
} from './routes/index.js'
|
|
15
30
|
|
|
16
31
|
export class SeamHttp {
|
|
17
32
|
client: Axios
|
|
18
33
|
|
|
19
|
-
#legacy: boolean
|
|
34
|
+
// #legacy: boolean
|
|
20
35
|
|
|
21
36
|
constructor(apiKeyOrOptions: string | SeamHttpOptions) {
|
|
22
37
|
const options = parseOptions(apiKeyOrOptions)
|
|
23
|
-
this.#legacy = options.enableLegacyMethodBehaivor
|
|
38
|
+
// this.#legacy = options.enableLegacyMethodBehaivor
|
|
24
39
|
this.client = createAxiosClient(options)
|
|
25
40
|
}
|
|
26
41
|
|
|
42
|
+
static fromClient(
|
|
43
|
+
client: SeamHttpOptionsWithClient['client'],
|
|
44
|
+
options: Omit<SeamHttpOptionsWithClient, 'client'> = {},
|
|
45
|
+
): SeamHttp {
|
|
46
|
+
const opts = { ...options, client }
|
|
47
|
+
if (!isSeamHttpOptionsWithClient(opts)) {
|
|
48
|
+
throw new SeamHttpInvalidOptionsError('Missing client')
|
|
49
|
+
}
|
|
50
|
+
return new SeamHttp(opts)
|
|
51
|
+
}
|
|
52
|
+
|
|
27
53
|
static fromApiKey(
|
|
28
54
|
apiKey: SeamHttpOptionsWithApiKey['apiKey'],
|
|
29
55
|
options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
|
|
30
56
|
): SeamHttp {
|
|
31
57
|
const opts = { ...options, apiKey }
|
|
32
58
|
if (!isSeamHttpOptionsWithApiKey(opts)) {
|
|
33
|
-
throw new
|
|
59
|
+
throw new SeamHttpInvalidOptionsError('Missing apiKey')
|
|
34
60
|
}
|
|
35
61
|
return new SeamHttp(opts)
|
|
36
62
|
}
|
|
@@ -44,20 +70,67 @@ export class SeamHttp {
|
|
|
44
70
|
): SeamHttp {
|
|
45
71
|
const opts = { ...options, clientSessionToken }
|
|
46
72
|
if (!isSeamHttpOptionsWithClientSessionToken(opts)) {
|
|
47
|
-
throw new
|
|
73
|
+
throw new SeamHttpInvalidOptionsError('Missing clientSessionToken')
|
|
48
74
|
}
|
|
49
75
|
return new SeamHttp(opts)
|
|
50
76
|
}
|
|
51
77
|
|
|
52
|
-
|
|
53
|
-
|
|
78
|
+
get accessCodes(): SeamHttpAccessCodes {
|
|
79
|
+
return SeamHttpAccessCodes.fromClient(this.client)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
get acs(): SeamHttpAcs {
|
|
83
|
+
return SeamHttpAcs.fromClient(this.client)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
get actionAttempts(): SeamHttpActionAttempts {
|
|
87
|
+
return SeamHttpActionAttempts.fromClient(this.client)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
get clientSessions(): SeamHttpClientSessions {
|
|
91
|
+
return SeamHttpClientSessions.fromClient(this.client)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
get connectedAccounts(): SeamHttpConnectedAccounts {
|
|
95
|
+
return SeamHttpConnectedAccounts.fromClient(this.client)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
get connectWebviews(): SeamHttpConnectWebviews {
|
|
99
|
+
return SeamHttpConnectWebviews.fromClient(this.client)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
get devices(): SeamHttpDevices {
|
|
103
|
+
return SeamHttpDevices.fromClient(this.client)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
get events(): SeamHttpEvents {
|
|
107
|
+
return SeamHttpEvents.fromClient(this.client)
|
|
108
|
+
}
|
|
54
109
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
110
|
+
get locks(): SeamHttpLocks {
|
|
111
|
+
return SeamHttpLocks.fromClient(this.client)
|
|
112
|
+
}
|
|
58
113
|
|
|
59
|
-
get
|
|
60
|
-
|
|
61
|
-
|
|
114
|
+
get noiseSensors(): SeamHttpNoiseSensors {
|
|
115
|
+
return SeamHttpNoiseSensors.fromClient(this.client)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
get thermostats(): SeamHttpThermostats {
|
|
119
|
+
return SeamHttpThermostats.fromClient(this.client)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
get webhooks(): SeamHttpWebhooks {
|
|
123
|
+
return SeamHttpWebhooks.fromClient(this.client)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
get workspaces(): SeamHttpWorkspaces {
|
|
127
|
+
return SeamHttpWorkspaces.fromClient(this.client)
|
|
62
128
|
}
|
|
63
129
|
}
|
|
130
|
+
|
|
131
|
+
// TODO
|
|
132
|
+
// static fromPublishableKey and deprecate getClientSessionToken
|
|
133
|
+
|
|
134
|
+
// TODO: Should we keep makeRequest?
|
|
135
|
+
// Better to implement error handling and wrapping in an error handler.
|
|
136
|
+
// makeRequest
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
isSeamHttpOptionsWithClient,
|
|
3
|
+
type SeamHttpOptions,
|
|
4
|
+
} from './client-options.js'
|
|
5
|
+
|
|
6
|
+
const enableLegacyMethodBehaivorDefault = true
|
|
7
|
+
|
|
2
8
|
export const parseOptions = (
|
|
3
9
|
apiKeyOrOptions: string | SeamHttpOptions,
|
|
4
10
|
): Required<SeamHttpOptions> => {
|
|
@@ -7,6 +13,13 @@ export const parseOptions = (
|
|
|
7
13
|
? { apiKey: apiKeyOrOptions }
|
|
8
14
|
: apiKeyOrOptions
|
|
9
15
|
|
|
16
|
+
if (isSeamHttpOptionsWithClient(options))
|
|
17
|
+
return {
|
|
18
|
+
...options,
|
|
19
|
+
enableLegacyMethodBehaivor:
|
|
20
|
+
options.enableLegacyMethodBehaivor ?? enableLegacyMethodBehaivorDefault,
|
|
21
|
+
}
|
|
22
|
+
|
|
10
23
|
const endpoint =
|
|
11
24
|
options.endpoint ??
|
|
12
25
|
globalThis.process?.env?.['SEAM_ENDPOINT'] ??
|
|
@@ -23,6 +36,7 @@ export const parseOptions = (
|
|
|
23
36
|
...(apiKey != null ? { apiKey } : {}),
|
|
24
37
|
endpoint,
|
|
25
38
|
axiosOptions: options.axiosOptions ?? {},
|
|
26
|
-
enableLegacyMethodBehaivor:
|
|
39
|
+
enableLegacyMethodBehaivor:
|
|
40
|
+
options.enableLegacyMethodBehaivor ?? enableLegacyMethodBehaivorDefault,
|
|
27
41
|
}
|
|
28
42
|
}
|
|
@@ -0,0 +1,157 @@
|
|
|
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 { Axios } from 'axios'
|
|
8
|
+
import type { SetNonNullable } from 'type-fest'
|
|
9
|
+
|
|
10
|
+
import { createAxiosClient } from 'lib/seam/connect/axios.js'
|
|
11
|
+
import {
|
|
12
|
+
isSeamHttpOptionsWithApiKey,
|
|
13
|
+
isSeamHttpOptionsWithClient,
|
|
14
|
+
isSeamHttpOptionsWithClientSessionToken,
|
|
15
|
+
SeamHttpInvalidOptionsError,
|
|
16
|
+
type SeamHttpOptions,
|
|
17
|
+
type SeamHttpOptionsWithApiKey,
|
|
18
|
+
type SeamHttpOptionsWithClient,
|
|
19
|
+
type SeamHttpOptionsWithClientSessionToken,
|
|
20
|
+
} from 'lib/seam/connect/client-options.js'
|
|
21
|
+
import { parseOptions } from 'lib/seam/connect/parse-options.js'
|
|
22
|
+
|
|
23
|
+
export class SeamHttpAccessCodesUnmanaged {
|
|
24
|
+
client: Axios
|
|
25
|
+
|
|
26
|
+
constructor(apiKeyOrOptions: string | SeamHttpOptions) {
|
|
27
|
+
const options = parseOptions(apiKeyOrOptions)
|
|
28
|
+
this.client = createAxiosClient(options)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static fromClient(
|
|
32
|
+
client: SeamHttpOptionsWithClient['client'],
|
|
33
|
+
options: Omit<SeamHttpOptionsWithClient, 'client'> = {},
|
|
34
|
+
): SeamHttpAccessCodesUnmanaged {
|
|
35
|
+
const opts = { ...options, client }
|
|
36
|
+
if (!isSeamHttpOptionsWithClient(opts)) {
|
|
37
|
+
throw new SeamHttpInvalidOptionsError('Missing client')
|
|
38
|
+
}
|
|
39
|
+
return new SeamHttpAccessCodesUnmanaged(opts)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static fromApiKey(
|
|
43
|
+
apiKey: SeamHttpOptionsWithApiKey['apiKey'],
|
|
44
|
+
options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
|
|
45
|
+
): SeamHttpAccessCodesUnmanaged {
|
|
46
|
+
const opts = { ...options, apiKey }
|
|
47
|
+
if (!isSeamHttpOptionsWithApiKey(opts)) {
|
|
48
|
+
throw new SeamHttpInvalidOptionsError('Missing apiKey')
|
|
49
|
+
}
|
|
50
|
+
return new SeamHttpAccessCodesUnmanaged(opts)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
static fromClientSessionToken(
|
|
54
|
+
clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'],
|
|
55
|
+
options: Omit<
|
|
56
|
+
SeamHttpOptionsWithClientSessionToken,
|
|
57
|
+
'clientSessionToken'
|
|
58
|
+
> = {},
|
|
59
|
+
): SeamHttpAccessCodesUnmanaged {
|
|
60
|
+
const opts = { ...options, clientSessionToken }
|
|
61
|
+
if (!isSeamHttpOptionsWithClientSessionToken(opts)) {
|
|
62
|
+
throw new SeamHttpInvalidOptionsError('Missing clientSessionToken')
|
|
63
|
+
}
|
|
64
|
+
return new SeamHttpAccessCodesUnmanaged(opts)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async convertToManaged(
|
|
68
|
+
body: AccessCodesUnmanagedConvertToManagedBody,
|
|
69
|
+
): Promise<void> {
|
|
70
|
+
await this.client.request<AccessCodesUnmanagedConvertToManagedResponse>({
|
|
71
|
+
url: '/access_codes/unmanaged/convert_to_managed',
|
|
72
|
+
method: 'post',
|
|
73
|
+
data: body,
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async delete(body: AccessCodesUnmanagedDeleteBody): Promise<void> {
|
|
78
|
+
await this.client.request<AccessCodesUnmanagedDeleteResponse>({
|
|
79
|
+
url: '/access_codes/unmanaged/delete',
|
|
80
|
+
method: 'post',
|
|
81
|
+
data: body,
|
|
82
|
+
})
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async get(
|
|
86
|
+
body: AccessCodesUnmanagedGetBody,
|
|
87
|
+
): Promise<AccessCodesUnmanagedGetResponse['access_code']> {
|
|
88
|
+
const { data } = await this.client.request<AccessCodesUnmanagedGetResponse>(
|
|
89
|
+
{
|
|
90
|
+
url: '/access_codes/unmanaged/get',
|
|
91
|
+
method: 'post',
|
|
92
|
+
data: body,
|
|
93
|
+
},
|
|
94
|
+
)
|
|
95
|
+
return data.access_code
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async list(
|
|
99
|
+
body: AccessCodesUnmanagedListBody,
|
|
100
|
+
): Promise<AccessCodesUnmanagedListResponse['access_codes']> {
|
|
101
|
+
const { data } =
|
|
102
|
+
await this.client.request<AccessCodesUnmanagedListResponse>({
|
|
103
|
+
url: '/access_codes/unmanaged/list',
|
|
104
|
+
method: 'post',
|
|
105
|
+
data: body,
|
|
106
|
+
})
|
|
107
|
+
return data.access_codes
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async update(body: AccessCodesUnmanagedUpdateBody): Promise<void> {
|
|
111
|
+
await this.client.request<AccessCodesUnmanagedUpdateResponse>({
|
|
112
|
+
url: '/access_codes/unmanaged/update',
|
|
113
|
+
method: 'post',
|
|
114
|
+
data: body,
|
|
115
|
+
})
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export type AccessCodesUnmanagedConvertToManagedBody = SetNonNullable<
|
|
120
|
+
Required<RouteRequestBody<'/access_codes/unmanaged/convert_to_managed'>>
|
|
121
|
+
>
|
|
122
|
+
|
|
123
|
+
export type AccessCodesUnmanagedConvertToManagedResponse = SetNonNullable<
|
|
124
|
+
Required<RouteResponse<'/access_codes/unmanaged/convert_to_managed'>>
|
|
125
|
+
>
|
|
126
|
+
|
|
127
|
+
export type AccessCodesUnmanagedDeleteBody = SetNonNullable<
|
|
128
|
+
Required<RouteRequestBody<'/access_codes/unmanaged/delete'>>
|
|
129
|
+
>
|
|
130
|
+
|
|
131
|
+
export type AccessCodesUnmanagedDeleteResponse = SetNonNullable<
|
|
132
|
+
Required<RouteResponse<'/access_codes/unmanaged/delete'>>
|
|
133
|
+
>
|
|
134
|
+
|
|
135
|
+
export type AccessCodesUnmanagedGetBody = SetNonNullable<
|
|
136
|
+
Required<RouteRequestBody<'/access_codes/unmanaged/get'>>
|
|
137
|
+
>
|
|
138
|
+
|
|
139
|
+
export type AccessCodesUnmanagedGetResponse = SetNonNullable<
|
|
140
|
+
Required<RouteResponse<'/access_codes/unmanaged/get'>>
|
|
141
|
+
>
|
|
142
|
+
|
|
143
|
+
export type AccessCodesUnmanagedListBody = SetNonNullable<
|
|
144
|
+
Required<RouteRequestBody<'/access_codes/unmanaged/list'>>
|
|
145
|
+
>
|
|
146
|
+
|
|
147
|
+
export type AccessCodesUnmanagedListResponse = SetNonNullable<
|
|
148
|
+
Required<RouteResponse<'/access_codes/unmanaged/list'>>
|
|
149
|
+
>
|
|
150
|
+
|
|
151
|
+
export type AccessCodesUnmanagedUpdateBody = SetNonNullable<
|
|
152
|
+
Required<RouteRequestBody<'/access_codes/unmanaged/update'>>
|
|
153
|
+
>
|
|
154
|
+
|
|
155
|
+
export type AccessCodesUnmanagedUpdateResponse = SetNonNullable<
|
|
156
|
+
Required<RouteResponse<'/access_codes/unmanaged/update'>>
|
|
157
|
+
>
|