@seamapi/http 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +212 -1
- package/dist/connect.cjs +643 -4
- package/dist/connect.cjs.map +1 -1
- package/dist/connect.d.cts +84 -2
- package/lib/seam/connect/api-error-type.d.ts +8 -0
- package/lib/seam/connect/api-error-type.js +3 -0
- package/lib/seam/connect/api-error-type.js.map +1 -0
- package/lib/seam/connect/auth.js +55 -4
- package/lib/seam/connect/auth.js.map +1 -1
- package/lib/seam/connect/client.js +5 -0
- package/lib/seam/connect/client.js.map +1 -1
- package/lib/seam/connect/error-interceptor.d.ts +1 -0
- package/lib/seam/connect/error-interceptor.js +43 -0
- package/lib/seam/connect/error-interceptor.js.map +1 -0
- package/lib/seam/connect/index.d.ts +3 -1
- package/lib/seam/connect/index.js +3 -1
- package/lib/seam/connect/index.js.map +1 -1
- package/lib/seam/connect/options.d.ts +11 -1
- package/lib/seam/connect/options.js +51 -1
- package/lib/seam/connect/options.js.map +1 -1
- package/lib/seam/connect/routes/access-codes-unmanaged.d.ts +3 -1
- package/lib/seam/connect/routes/access-codes-unmanaged.js +15 -1
- package/lib/seam/connect/routes/access-codes-unmanaged.js.map +1 -1
- package/lib/seam/connect/routes/access-codes.d.ts +3 -1
- package/lib/seam/connect/routes/access-codes.js +15 -1
- package/lib/seam/connect/routes/access-codes.js.map +1 -1
- package/lib/seam/connect/routes/acs-access-groups.d.ts +3 -1
- package/lib/seam/connect/routes/acs-access-groups.js +15 -1
- package/lib/seam/connect/routes/acs-access-groups.js.map +1 -1
- package/lib/seam/connect/routes/acs-credentials.d.ts +3 -1
- package/lib/seam/connect/routes/acs-credentials.js +15 -1
- package/lib/seam/connect/routes/acs-credentials.js.map +1 -1
- package/lib/seam/connect/routes/acs-systems.d.ts +3 -1
- package/lib/seam/connect/routes/acs-systems.js +15 -1
- package/lib/seam/connect/routes/acs-systems.js.map +1 -1
- package/lib/seam/connect/routes/acs-users.d.ts +3 -1
- package/lib/seam/connect/routes/acs-users.js +15 -1
- package/lib/seam/connect/routes/acs-users.js.map +1 -1
- package/lib/seam/connect/routes/acs.d.ts +3 -1
- package/lib/seam/connect/routes/acs.js +15 -1
- package/lib/seam/connect/routes/acs.js.map +1 -1
- package/lib/seam/connect/routes/action-attempts.d.ts +3 -1
- package/lib/seam/connect/routes/action-attempts.js +15 -1
- package/lib/seam/connect/routes/action-attempts.js.map +1 -1
- package/lib/seam/connect/routes/client-sessions.d.ts +3 -1
- package/lib/seam/connect/routes/client-sessions.js +15 -1
- package/lib/seam/connect/routes/client-sessions.js.map +1 -1
- package/lib/seam/connect/routes/connect-webviews.d.ts +3 -1
- package/lib/seam/connect/routes/connect-webviews.js +15 -1
- package/lib/seam/connect/routes/connect-webviews.js.map +1 -1
- package/lib/seam/connect/routes/connected-accounts.d.ts +3 -1
- package/lib/seam/connect/routes/connected-accounts.js +15 -1
- package/lib/seam/connect/routes/connected-accounts.js.map +1 -1
- package/lib/seam/connect/routes/devices-unmanaged.d.ts +3 -1
- package/lib/seam/connect/routes/devices-unmanaged.js +15 -1
- package/lib/seam/connect/routes/devices-unmanaged.js.map +1 -1
- package/lib/seam/connect/routes/devices.d.ts +3 -1
- package/lib/seam/connect/routes/devices.js +15 -1
- package/lib/seam/connect/routes/devices.js.map +1 -1
- package/lib/seam/connect/routes/events.d.ts +3 -1
- package/lib/seam/connect/routes/events.js +15 -1
- package/lib/seam/connect/routes/events.js.map +1 -1
- package/lib/seam/connect/routes/locks.d.ts +3 -1
- package/lib/seam/connect/routes/locks.js +15 -1
- package/lib/seam/connect/routes/locks.js.map +1 -1
- package/lib/seam/connect/routes/noise-sensors-noise-thresholds.d.ts +3 -1
- package/lib/seam/connect/routes/noise-sensors-noise-thresholds.js +15 -1
- package/lib/seam/connect/routes/noise-sensors-noise-thresholds.js.map +1 -1
- package/lib/seam/connect/routes/noise-sensors.d.ts +3 -1
- package/lib/seam/connect/routes/noise-sensors.js +15 -1
- package/lib/seam/connect/routes/noise-sensors.js.map +1 -1
- package/lib/seam/connect/routes/thermostats-climate-setting-schedules.d.ts +3 -1
- package/lib/seam/connect/routes/thermostats-climate-setting-schedules.js +15 -1
- package/lib/seam/connect/routes/thermostats-climate-setting-schedules.js.map +1 -1
- package/lib/seam/connect/routes/thermostats.d.ts +3 -1
- package/lib/seam/connect/routes/thermostats.js +15 -1
- package/lib/seam/connect/routes/thermostats.js.map +1 -1
- package/lib/seam/connect/routes/webhooks.d.ts +3 -1
- package/lib/seam/connect/routes/webhooks.js +15 -1
- package/lib/seam/connect/routes/webhooks.js.map +1 -1
- package/lib/seam/connect/routes/workspaces.d.ts +3 -1
- package/lib/seam/connect/routes/workspaces.js +15 -1
- package/lib/seam/connect/routes/workspaces.js.map +1 -1
- package/lib/seam/connect/seam-http-error.d.ts +20 -0
- package/lib/seam/connect/seam-http-error.js +43 -0
- package/lib/seam/connect/seam-http-error.js.map +1 -0
- package/lib/seam/connect/seam-http.d.ts +3 -1
- package/lib/seam/connect/seam-http.js +15 -1
- package/lib/seam/connect/seam-http.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +3 -2
- package/src/lib/seam/connect/api-error-type.ts +11 -0
- package/src/lib/seam/connect/auth.ts +95 -3
- package/src/lib/seam/connect/client.ts +8 -0
- package/src/lib/seam/connect/error-interceptor.ts +61 -0
- package/src/lib/seam/connect/index.ts +3 -1
- package/src/lib/seam/connect/options.ts +105 -1
- package/src/lib/seam/connect/routes/access-codes-unmanaged.ts +38 -0
- package/src/lib/seam/connect/routes/access-codes.ts +38 -0
- package/src/lib/seam/connect/routes/acs-access-groups.ts +38 -0
- package/src/lib/seam/connect/routes/acs-credentials.ts +38 -0
- package/src/lib/seam/connect/routes/acs-systems.ts +38 -0
- package/src/lib/seam/connect/routes/acs-users.ts +38 -0
- package/src/lib/seam/connect/routes/acs.ts +38 -0
- package/src/lib/seam/connect/routes/action-attempts.ts +38 -0
- package/src/lib/seam/connect/routes/client-sessions.ts +38 -0
- package/src/lib/seam/connect/routes/connect-webviews.ts +38 -0
- package/src/lib/seam/connect/routes/connected-accounts.ts +38 -0
- package/src/lib/seam/connect/routes/devices-unmanaged.ts +38 -0
- package/src/lib/seam/connect/routes/devices.ts +38 -0
- package/src/lib/seam/connect/routes/events.ts +38 -0
- package/src/lib/seam/connect/routes/locks.ts +38 -0
- package/src/lib/seam/connect/routes/noise-sensors-noise-thresholds.ts +38 -0
- package/src/lib/seam/connect/routes/noise-sensors.ts +38 -0
- package/src/lib/seam/connect/routes/thermostats-climate-setting-schedules.ts +38 -0
- package/src/lib/seam/connect/routes/thermostats.ts +38 -0
- package/src/lib/seam/connect/routes/webhooks.ts +38 -0
- package/src/lib/seam/connect/routes/workspaces.ts +38 -0
- package/src/lib/seam/connect/seam-http-error.ts +64 -0
- package/src/lib/seam/connect/seam-http.ts +38 -0
- package/src/lib/version.ts +1 -1
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isSeamHttpOptionsWithApiKey,
|
|
3
3
|
isSeamHttpOptionsWithClientSessionToken,
|
|
4
|
+
isSeamHttpOptionsWithConsoleSessionToken,
|
|
5
|
+
isSeamHttpOptionsWithPersonalAccessToken,
|
|
4
6
|
SeamHttpInvalidOptionsError,
|
|
5
7
|
type SeamHttpOptionsWithApiKey,
|
|
6
8
|
type SeamHttpOptionsWithClientSessionToken,
|
|
9
|
+
type SeamHttpOptionsWithConsoleSessionToken,
|
|
10
|
+
type SeamHttpOptionsWithPersonalAccessToken,
|
|
7
11
|
} from './options.js'
|
|
8
12
|
import type { Options } from './parse-options.js'
|
|
9
13
|
|
|
@@ -22,8 +26,23 @@ export const getAuthHeaders = (options: Options): Headers => {
|
|
|
22
26
|
return getAuthHeadersForClientSessionToken(options)
|
|
23
27
|
}
|
|
24
28
|
|
|
29
|
+
if (isSeamHttpOptionsWithConsoleSessionToken(options)) {
|
|
30
|
+
return getAuthHeadersForConsoleSessionToken(options)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (isSeamHttpOptionsWithPersonalAccessToken(options)) {
|
|
34
|
+
return getAuthHeadersForPersonalAccessToken(options)
|
|
35
|
+
}
|
|
36
|
+
|
|
25
37
|
throw new SeamHttpInvalidOptionsError(
|
|
26
|
-
|
|
38
|
+
[
|
|
39
|
+
'Must specify',
|
|
40
|
+
'an apiKey,',
|
|
41
|
+
'clientSessionToken,',
|
|
42
|
+
'publishableKey,',
|
|
43
|
+
'consoleSessionToken with a workspaceId',
|
|
44
|
+
'or personalAccessToken with a workspaceId',
|
|
45
|
+
].join(' '),
|
|
27
46
|
)
|
|
28
47
|
}
|
|
29
48
|
|
|
@@ -96,6 +115,74 @@ const getAuthHeadersForClientSessionToken = ({
|
|
|
96
115
|
}
|
|
97
116
|
}
|
|
98
117
|
|
|
118
|
+
const getAuthHeadersForConsoleSessionToken = ({
|
|
119
|
+
consoleSessionToken,
|
|
120
|
+
workspaceId,
|
|
121
|
+
}: SeamHttpOptionsWithConsoleSessionToken): Headers => {
|
|
122
|
+
if (isAccessToken(consoleSessionToken)) {
|
|
123
|
+
throw new SeamHttpInvalidTokenError(
|
|
124
|
+
'An Access Token cannot be used as a consoleSessionToken',
|
|
125
|
+
)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (isClientSessionToken(consoleSessionToken)) {
|
|
129
|
+
throw new SeamHttpInvalidTokenError(
|
|
130
|
+
'A Client Session Token cannot be used as a consoleSessionToken',
|
|
131
|
+
)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (isPublishableKey(consoleSessionToken)) {
|
|
135
|
+
throw new SeamHttpInvalidTokenError(
|
|
136
|
+
'A Publishable Key cannot be used as a consoleSessionToken',
|
|
137
|
+
)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (!isJwt(consoleSessionToken)) {
|
|
141
|
+
throw new SeamHttpInvalidTokenError(
|
|
142
|
+
`Unknown or invalid consoleSessionToken format, expected a JWT which starts with ${jwtPrefix}`,
|
|
143
|
+
)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return {
|
|
147
|
+
authorization: `Bearer ${consoleSessionToken}`,
|
|
148
|
+
'seam-workspace-id': workspaceId,
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const getAuthHeadersForPersonalAccessToken = ({
|
|
153
|
+
personalAccessToken,
|
|
154
|
+
workspaceId,
|
|
155
|
+
}: SeamHttpOptionsWithPersonalAccessToken): Headers => {
|
|
156
|
+
if (isJwt(personalAccessToken)) {
|
|
157
|
+
throw new SeamHttpInvalidTokenError(
|
|
158
|
+
'A JWT cannot be used as a personalAccessToken',
|
|
159
|
+
)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (isClientSessionToken(personalAccessToken)) {
|
|
163
|
+
throw new SeamHttpInvalidTokenError(
|
|
164
|
+
'A Client Session Token cannot be used as a personalAccessToken',
|
|
165
|
+
)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (isPublishableKey(personalAccessToken)) {
|
|
169
|
+
throw new SeamHttpInvalidTokenError(
|
|
170
|
+
'A Publishable Key cannot be used as a personalAccessToken',
|
|
171
|
+
)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (!isAccessToken(personalAccessToken)) {
|
|
175
|
+
throw new SeamHttpInvalidTokenError(
|
|
176
|
+
`Unknown or invalid personalAccessToken format, expected token to start with ${accessTokenPrefix}`,
|
|
177
|
+
)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return {
|
|
181
|
+
authorization: `Bearer ${personalAccessToken}`,
|
|
182
|
+
'seam-workspace-id': workspaceId,
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
99
186
|
const getAuthHeadersForPublishableKey = (publishableKey: string): Headers => {
|
|
100
187
|
if (isJwt(publishableKey)) {
|
|
101
188
|
throw new SeamHttpInvalidTokenError(
|
|
@@ -153,6 +240,10 @@ export const warnOnInsecureuserIdentifierKey = (
|
|
|
153
240
|
|
|
154
241
|
const tokenPrefix = 'seam_'
|
|
155
242
|
|
|
243
|
+
const accessTokenPrefix = 'seam_at'
|
|
244
|
+
|
|
245
|
+
const jwtPrefix = 'ey'
|
|
246
|
+
|
|
156
247
|
const clientSessionTokenPrefix = 'seam_cst'
|
|
157
248
|
|
|
158
249
|
const publishableKeyTokenPrefix = 'seam_pk'
|
|
@@ -160,9 +251,10 @@ const publishableKeyTokenPrefix = 'seam_pk'
|
|
|
160
251
|
const isClientSessionToken = (token: string): boolean =>
|
|
161
252
|
token.startsWith(clientSessionTokenPrefix)
|
|
162
253
|
|
|
163
|
-
const isAccessToken = (token: string): boolean =>
|
|
254
|
+
const isAccessToken = (token: string): boolean =>
|
|
255
|
+
token.startsWith(accessTokenPrefix)
|
|
164
256
|
|
|
165
|
-
const isJwt = (token: string): boolean => token.startsWith(
|
|
257
|
+
const isJwt = (token: string): boolean => token.startsWith(jwtPrefix)
|
|
166
258
|
|
|
167
259
|
const isSeamToken = (token: string): boolean => token.startsWith(tokenPrefix)
|
|
168
260
|
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import axios, { type AxiosInstance, type AxiosRequestConfig } from 'axios'
|
|
2
|
+
// @ts-expect-error https://github.com/svsool/axios-better-stacktrace/issues/12
|
|
3
|
+
import axiosBetterStacktrace from 'axios-better-stacktrace'
|
|
2
4
|
import axiosRetry, { type AxiosRetry, exponentialDelay } from 'axios-retry'
|
|
3
5
|
|
|
4
6
|
import { paramsSerializer } from 'lib/params-serializer.js'
|
|
5
7
|
|
|
8
|
+
import { errorInterceptor } from './error-interceptor.js'
|
|
9
|
+
|
|
6
10
|
export type Client = AxiosInstance
|
|
7
11
|
|
|
8
12
|
export interface ClientOptions {
|
|
@@ -21,6 +25,8 @@ export const createClient = (options: ClientOptions): AxiosInstance => {
|
|
|
21
25
|
...options.axiosOptions,
|
|
22
26
|
})
|
|
23
27
|
|
|
28
|
+
axiosBetterStacktrace(axios)
|
|
29
|
+
|
|
24
30
|
// @ts-expect-error https://github.com/softonic/axios-retry/issues/159
|
|
25
31
|
axiosRetry(client, {
|
|
26
32
|
retries: 2,
|
|
@@ -28,5 +34,7 @@ export const createClient = (options: ClientOptions): AxiosInstance => {
|
|
|
28
34
|
...options.axiosRetryOptions,
|
|
29
35
|
})
|
|
30
36
|
|
|
37
|
+
client.interceptors.response.use(undefined, errorInterceptor)
|
|
38
|
+
|
|
31
39
|
return client
|
|
32
40
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { type AxiosError, isAxiosError } from 'axios'
|
|
2
|
+
|
|
3
|
+
import type { ApiErrorResponse } from './api-error-type.js'
|
|
4
|
+
import {
|
|
5
|
+
SeamHttpApiError,
|
|
6
|
+
SeamHttpInvalidInputError,
|
|
7
|
+
SeamHttpUnauthorizedError,
|
|
8
|
+
} from './seam-http-error.js'
|
|
9
|
+
|
|
10
|
+
export const errorInterceptor = async (err: unknown): Promise<void> => {
|
|
11
|
+
if (!isAxiosError(err)) throw err
|
|
12
|
+
|
|
13
|
+
const { response } = err
|
|
14
|
+
const status = response?.status
|
|
15
|
+
const headers = response?.headers
|
|
16
|
+
const requestId = headers?.['seam-request-id'] ?? ''
|
|
17
|
+
|
|
18
|
+
if (status == null) throw err
|
|
19
|
+
|
|
20
|
+
if (status === 401) {
|
|
21
|
+
throw new SeamHttpUnauthorizedError(requestId)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!isApiErrorResponse(response)) throw err
|
|
25
|
+
|
|
26
|
+
const { type } = response.data.error
|
|
27
|
+
|
|
28
|
+
const args = [response.data.error, status, requestId] as const
|
|
29
|
+
|
|
30
|
+
if (type === 'invalid_input') throw new SeamHttpInvalidInputError(...args)
|
|
31
|
+
throw new SeamHttpApiError(...args)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const isApiErrorResponse = (
|
|
35
|
+
response: AxiosError['response'],
|
|
36
|
+
): response is NonNullable<AxiosError<ApiErrorResponse>['response']> => {
|
|
37
|
+
if (response == null) return false
|
|
38
|
+
const { headers, data } = response
|
|
39
|
+
|
|
40
|
+
if (headers == null) return false
|
|
41
|
+
|
|
42
|
+
const contentType = headers['content-type']
|
|
43
|
+
if (
|
|
44
|
+
typeof contentType === 'string' &&
|
|
45
|
+
!contentType.startsWith('application/json')
|
|
46
|
+
) {
|
|
47
|
+
return false
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (typeof data === 'object' && data != null) {
|
|
51
|
+
return (
|
|
52
|
+
'error' in data &&
|
|
53
|
+
typeof data.error === 'object' &&
|
|
54
|
+
data.error != null &&
|
|
55
|
+
'type' in data.error &&
|
|
56
|
+
typeof data.error.type === 'string'
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return false
|
|
61
|
+
}
|
|
@@ -5,6 +5,8 @@ export type SeamHttpOptions =
|
|
|
5
5
|
| SeamHttpOptionsWithClient
|
|
6
6
|
| SeamHttpOptionsWithApiKey
|
|
7
7
|
| SeamHttpOptionsWithClientSessionToken
|
|
8
|
+
| SeamHttpOptionsWithConsoleSessionToken
|
|
9
|
+
| SeamHttpOptionsWithPersonalAccessToken
|
|
8
10
|
|
|
9
11
|
interface SeamHttpCommonOptions extends ClientOptions {
|
|
10
12
|
endpoint?: string
|
|
@@ -53,6 +55,18 @@ export const isSeamHttpOptionsWithApiKey = (
|
|
|
53
55
|
)
|
|
54
56
|
}
|
|
55
57
|
|
|
58
|
+
if ('consoleSessionToken' in options && options.consoleSessionToken != null) {
|
|
59
|
+
throw new SeamHttpInvalidOptionsError(
|
|
60
|
+
'The consoleSessionToken option cannot be used with the apiKey option',
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if ('personalAccessToken' in options && options.personalAccessToken != null) {
|
|
65
|
+
throw new SeamHttpInvalidOptionsError(
|
|
66
|
+
'The personalAccessToken option cannot be used with the apiKey option',
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
56
70
|
return true
|
|
57
71
|
}
|
|
58
72
|
|
|
@@ -69,7 +83,97 @@ export const isSeamHttpOptionsWithClientSessionToken = (
|
|
|
69
83
|
|
|
70
84
|
if ('apiKey' in options && options.apiKey != null) {
|
|
71
85
|
throw new SeamHttpInvalidOptionsError(
|
|
72
|
-
'The
|
|
86
|
+
'The apiKey option cannot be used with the clientSessionToken option',
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if ('consoleSessionToken' in options && options.consoleSessionToken != null) {
|
|
91
|
+
throw new SeamHttpInvalidOptionsError(
|
|
92
|
+
'The consoleSessionToken option cannot be used with the clientSessionToken option',
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if ('personalAccessToken' in options && options.personalAccessToken != null) {
|
|
97
|
+
throw new SeamHttpInvalidOptionsError(
|
|
98
|
+
'The personalAccessToken option cannot be used with the clientSessionToken option',
|
|
99
|
+
)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return true
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export interface SeamHttpOptionsWithConsoleSessionToken
|
|
106
|
+
extends SeamHttpCommonOptions {
|
|
107
|
+
consoleSessionToken: string
|
|
108
|
+
workspaceId: string
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export const isSeamHttpOptionsWithConsoleSessionToken = (
|
|
112
|
+
options: SeamHttpOptions,
|
|
113
|
+
): options is SeamHttpOptionsWithConsoleSessionToken => {
|
|
114
|
+
if (!('consoleSessionToken' in options)) return false
|
|
115
|
+
if (options.consoleSessionToken == null) return false
|
|
116
|
+
|
|
117
|
+
if (!('workspaceId' in options) || options.workspaceId == null) {
|
|
118
|
+
throw new SeamHttpInvalidOptionsError(
|
|
119
|
+
'Must pass a workspaceId when using a consoleSessionToken',
|
|
120
|
+
)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if ('apiKey' in options && options.apiKey != null) {
|
|
124
|
+
throw new SeamHttpInvalidOptionsError(
|
|
125
|
+
'The apiKey option cannot be used with the consoleSessionToken option',
|
|
126
|
+
)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if ('clientSessionToken' in options && options.clientSessionToken != null) {
|
|
130
|
+
throw new SeamHttpInvalidOptionsError(
|
|
131
|
+
'The clientSessionToken option cannot be used with the consoleSessionToken option',
|
|
132
|
+
)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if ('personalAccessToken' in options && options.personalAccessToken != null) {
|
|
136
|
+
throw new SeamHttpInvalidOptionsError(
|
|
137
|
+
'The personalAccessToken option cannot be used with the consoleSessionToken option',
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return true
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export interface SeamHttpOptionsWithPersonalAccessToken
|
|
145
|
+
extends SeamHttpCommonOptions {
|
|
146
|
+
personalAccessToken: string
|
|
147
|
+
workspaceId: string
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export const isSeamHttpOptionsWithPersonalAccessToken = (
|
|
151
|
+
options: SeamHttpOptions,
|
|
152
|
+
): options is SeamHttpOptionsWithPersonalAccessToken => {
|
|
153
|
+
if (!('personalAccessToken' in options)) return false
|
|
154
|
+
if (options.personalAccessToken == null) return false
|
|
155
|
+
|
|
156
|
+
if (!('workspaceId' in options) || options.workspaceId == null) {
|
|
157
|
+
throw new SeamHttpInvalidOptionsError(
|
|
158
|
+
'Must pass a workspaceId when using a personalAccessToken',
|
|
159
|
+
)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if ('apiKey' in options && options.apiKey != null) {
|
|
163
|
+
throw new SeamHttpInvalidOptionsError(
|
|
164
|
+
'The apiKey option cannot be used with the personalAccessToken option',
|
|
165
|
+
)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if ('clientSessionToken' in options && options.clientSessionToken != null) {
|
|
169
|
+
throw new SeamHttpInvalidOptionsError(
|
|
170
|
+
'The clientSessionToken option cannot be used with the personalAccessToken option',
|
|
171
|
+
)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if ('consoleSessionToken' in options && options.consoleSessionToken != null) {
|
|
175
|
+
throw new SeamHttpInvalidOptionsError(
|
|
176
|
+
'The consoleSessionToken option cannot be used with the personalAccessToken option',
|
|
73
177
|
)
|
|
74
178
|
}
|
|
75
179
|
|
|
@@ -12,12 +12,16 @@ import {
|
|
|
12
12
|
isSeamHttpOptionsWithApiKey,
|
|
13
13
|
isSeamHttpOptionsWithClient,
|
|
14
14
|
isSeamHttpOptionsWithClientSessionToken,
|
|
15
|
+
isSeamHttpOptionsWithConsoleSessionToken,
|
|
16
|
+
isSeamHttpOptionsWithPersonalAccessToken,
|
|
15
17
|
type SeamHttpFromPublishableKeyOptions,
|
|
16
18
|
SeamHttpInvalidOptionsError,
|
|
17
19
|
type SeamHttpOptions,
|
|
18
20
|
type SeamHttpOptionsWithApiKey,
|
|
19
21
|
type SeamHttpOptionsWithClient,
|
|
20
22
|
type SeamHttpOptionsWithClientSessionToken,
|
|
23
|
+
type SeamHttpOptionsWithConsoleSessionToken,
|
|
24
|
+
type SeamHttpOptionsWithPersonalAccessToken,
|
|
21
25
|
} from 'lib/seam/connect/options.js'
|
|
22
26
|
import { parseOptions } from 'lib/seam/connect/parse-options.js'
|
|
23
27
|
|
|
@@ -82,6 +86,40 @@ export class SeamHttpAccessCodesUnmanaged {
|
|
|
82
86
|
return SeamHttpAccessCodesUnmanaged.fromClientSessionToken(token, options)
|
|
83
87
|
}
|
|
84
88
|
|
|
89
|
+
static fromConsoleSessionToken(
|
|
90
|
+
consoleSessionToken: SeamHttpOptionsWithConsoleSessionToken['consoleSessionToken'],
|
|
91
|
+
workspaceId: SeamHttpOptionsWithConsoleSessionToken['workspaceId'],
|
|
92
|
+
options: Omit<
|
|
93
|
+
SeamHttpOptionsWithConsoleSessionToken,
|
|
94
|
+
'consoleSessionToken' | 'workspaceId'
|
|
95
|
+
> = {},
|
|
96
|
+
): SeamHttpAccessCodesUnmanaged {
|
|
97
|
+
const constructorOptions = { ...options, consoleSessionToken, workspaceId }
|
|
98
|
+
if (!isSeamHttpOptionsWithConsoleSessionToken(constructorOptions)) {
|
|
99
|
+
throw new SeamHttpInvalidOptionsError(
|
|
100
|
+
'Missing consoleSessionToken or workspaceId',
|
|
101
|
+
)
|
|
102
|
+
}
|
|
103
|
+
return new SeamHttpAccessCodesUnmanaged(constructorOptions)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
static fromPersonalAccessToken(
|
|
107
|
+
personalAccessToken: SeamHttpOptionsWithPersonalAccessToken['personalAccessToken'],
|
|
108
|
+
workspaceId: SeamHttpOptionsWithPersonalAccessToken['workspaceId'],
|
|
109
|
+
options: Omit<
|
|
110
|
+
SeamHttpOptionsWithPersonalAccessToken,
|
|
111
|
+
'personalAccessToken' | 'workspaceId'
|
|
112
|
+
> = {},
|
|
113
|
+
): SeamHttpAccessCodesUnmanaged {
|
|
114
|
+
const constructorOptions = { ...options, personalAccessToken, workspaceId }
|
|
115
|
+
if (!isSeamHttpOptionsWithPersonalAccessToken(constructorOptions)) {
|
|
116
|
+
throw new SeamHttpInvalidOptionsError(
|
|
117
|
+
'Missing personalAccessToken or workspaceId',
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
return new SeamHttpAccessCodesUnmanaged(constructorOptions)
|
|
121
|
+
}
|
|
122
|
+
|
|
85
123
|
async convertToManaged(
|
|
86
124
|
body?: AccessCodesUnmanagedConvertToManagedBody,
|
|
87
125
|
): Promise<void> {
|
|
@@ -12,12 +12,16 @@ import {
|
|
|
12
12
|
isSeamHttpOptionsWithApiKey,
|
|
13
13
|
isSeamHttpOptionsWithClient,
|
|
14
14
|
isSeamHttpOptionsWithClientSessionToken,
|
|
15
|
+
isSeamHttpOptionsWithConsoleSessionToken,
|
|
16
|
+
isSeamHttpOptionsWithPersonalAccessToken,
|
|
15
17
|
type SeamHttpFromPublishableKeyOptions,
|
|
16
18
|
SeamHttpInvalidOptionsError,
|
|
17
19
|
type SeamHttpOptions,
|
|
18
20
|
type SeamHttpOptionsWithApiKey,
|
|
19
21
|
type SeamHttpOptionsWithClient,
|
|
20
22
|
type SeamHttpOptionsWithClientSessionToken,
|
|
23
|
+
type SeamHttpOptionsWithConsoleSessionToken,
|
|
24
|
+
type SeamHttpOptionsWithPersonalAccessToken,
|
|
21
25
|
} from 'lib/seam/connect/options.js'
|
|
22
26
|
import { parseOptions } from 'lib/seam/connect/parse-options.js'
|
|
23
27
|
|
|
@@ -83,6 +87,40 @@ export class SeamHttpAccessCodes {
|
|
|
83
87
|
return SeamHttpAccessCodes.fromClientSessionToken(token, options)
|
|
84
88
|
}
|
|
85
89
|
|
|
90
|
+
static fromConsoleSessionToken(
|
|
91
|
+
consoleSessionToken: SeamHttpOptionsWithConsoleSessionToken['consoleSessionToken'],
|
|
92
|
+
workspaceId: SeamHttpOptionsWithConsoleSessionToken['workspaceId'],
|
|
93
|
+
options: Omit<
|
|
94
|
+
SeamHttpOptionsWithConsoleSessionToken,
|
|
95
|
+
'consoleSessionToken' | 'workspaceId'
|
|
96
|
+
> = {},
|
|
97
|
+
): SeamHttpAccessCodes {
|
|
98
|
+
const constructorOptions = { ...options, consoleSessionToken, workspaceId }
|
|
99
|
+
if (!isSeamHttpOptionsWithConsoleSessionToken(constructorOptions)) {
|
|
100
|
+
throw new SeamHttpInvalidOptionsError(
|
|
101
|
+
'Missing consoleSessionToken or workspaceId',
|
|
102
|
+
)
|
|
103
|
+
}
|
|
104
|
+
return new SeamHttpAccessCodes(constructorOptions)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
static fromPersonalAccessToken(
|
|
108
|
+
personalAccessToken: SeamHttpOptionsWithPersonalAccessToken['personalAccessToken'],
|
|
109
|
+
workspaceId: SeamHttpOptionsWithPersonalAccessToken['workspaceId'],
|
|
110
|
+
options: Omit<
|
|
111
|
+
SeamHttpOptionsWithPersonalAccessToken,
|
|
112
|
+
'personalAccessToken' | 'workspaceId'
|
|
113
|
+
> = {},
|
|
114
|
+
): SeamHttpAccessCodes {
|
|
115
|
+
const constructorOptions = { ...options, personalAccessToken, workspaceId }
|
|
116
|
+
if (!isSeamHttpOptionsWithPersonalAccessToken(constructorOptions)) {
|
|
117
|
+
throw new SeamHttpInvalidOptionsError(
|
|
118
|
+
'Missing personalAccessToken or workspaceId',
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
return new SeamHttpAccessCodes(constructorOptions)
|
|
122
|
+
}
|
|
123
|
+
|
|
86
124
|
get unmanaged(): SeamHttpAccessCodesUnmanaged {
|
|
87
125
|
return SeamHttpAccessCodesUnmanaged.fromClient(this.client)
|
|
88
126
|
}
|
|
@@ -12,12 +12,16 @@ import {
|
|
|
12
12
|
isSeamHttpOptionsWithApiKey,
|
|
13
13
|
isSeamHttpOptionsWithClient,
|
|
14
14
|
isSeamHttpOptionsWithClientSessionToken,
|
|
15
|
+
isSeamHttpOptionsWithConsoleSessionToken,
|
|
16
|
+
isSeamHttpOptionsWithPersonalAccessToken,
|
|
15
17
|
type SeamHttpFromPublishableKeyOptions,
|
|
16
18
|
SeamHttpInvalidOptionsError,
|
|
17
19
|
type SeamHttpOptions,
|
|
18
20
|
type SeamHttpOptionsWithApiKey,
|
|
19
21
|
type SeamHttpOptionsWithClient,
|
|
20
22
|
type SeamHttpOptionsWithClientSessionToken,
|
|
23
|
+
type SeamHttpOptionsWithConsoleSessionToken,
|
|
24
|
+
type SeamHttpOptionsWithPersonalAccessToken,
|
|
21
25
|
} from 'lib/seam/connect/options.js'
|
|
22
26
|
import { parseOptions } from 'lib/seam/connect/parse-options.js'
|
|
23
27
|
|
|
@@ -82,6 +86,40 @@ export class SeamHttpAcsAccessGroups {
|
|
|
82
86
|
return SeamHttpAcsAccessGroups.fromClientSessionToken(token, options)
|
|
83
87
|
}
|
|
84
88
|
|
|
89
|
+
static fromConsoleSessionToken(
|
|
90
|
+
consoleSessionToken: SeamHttpOptionsWithConsoleSessionToken['consoleSessionToken'],
|
|
91
|
+
workspaceId: SeamHttpOptionsWithConsoleSessionToken['workspaceId'],
|
|
92
|
+
options: Omit<
|
|
93
|
+
SeamHttpOptionsWithConsoleSessionToken,
|
|
94
|
+
'consoleSessionToken' | 'workspaceId'
|
|
95
|
+
> = {},
|
|
96
|
+
): SeamHttpAcsAccessGroups {
|
|
97
|
+
const constructorOptions = { ...options, consoleSessionToken, workspaceId }
|
|
98
|
+
if (!isSeamHttpOptionsWithConsoleSessionToken(constructorOptions)) {
|
|
99
|
+
throw new SeamHttpInvalidOptionsError(
|
|
100
|
+
'Missing consoleSessionToken or workspaceId',
|
|
101
|
+
)
|
|
102
|
+
}
|
|
103
|
+
return new SeamHttpAcsAccessGroups(constructorOptions)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
static fromPersonalAccessToken(
|
|
107
|
+
personalAccessToken: SeamHttpOptionsWithPersonalAccessToken['personalAccessToken'],
|
|
108
|
+
workspaceId: SeamHttpOptionsWithPersonalAccessToken['workspaceId'],
|
|
109
|
+
options: Omit<
|
|
110
|
+
SeamHttpOptionsWithPersonalAccessToken,
|
|
111
|
+
'personalAccessToken' | 'workspaceId'
|
|
112
|
+
> = {},
|
|
113
|
+
): SeamHttpAcsAccessGroups {
|
|
114
|
+
const constructorOptions = { ...options, personalAccessToken, workspaceId }
|
|
115
|
+
if (!isSeamHttpOptionsWithPersonalAccessToken(constructorOptions)) {
|
|
116
|
+
throw new SeamHttpInvalidOptionsError(
|
|
117
|
+
'Missing personalAccessToken or workspaceId',
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
return new SeamHttpAcsAccessGroups(constructorOptions)
|
|
121
|
+
}
|
|
122
|
+
|
|
85
123
|
async addUser(body?: AcsAccessGroupsAddUserBody): Promise<void> {
|
|
86
124
|
await this.client.request<AcsAccessGroupsAddUserResponse>({
|
|
87
125
|
url: '/acs/access_groups/add_user',
|
|
@@ -12,12 +12,16 @@ import {
|
|
|
12
12
|
isSeamHttpOptionsWithApiKey,
|
|
13
13
|
isSeamHttpOptionsWithClient,
|
|
14
14
|
isSeamHttpOptionsWithClientSessionToken,
|
|
15
|
+
isSeamHttpOptionsWithConsoleSessionToken,
|
|
16
|
+
isSeamHttpOptionsWithPersonalAccessToken,
|
|
15
17
|
type SeamHttpFromPublishableKeyOptions,
|
|
16
18
|
SeamHttpInvalidOptionsError,
|
|
17
19
|
type SeamHttpOptions,
|
|
18
20
|
type SeamHttpOptionsWithApiKey,
|
|
19
21
|
type SeamHttpOptionsWithClient,
|
|
20
22
|
type SeamHttpOptionsWithClientSessionToken,
|
|
23
|
+
type SeamHttpOptionsWithConsoleSessionToken,
|
|
24
|
+
type SeamHttpOptionsWithPersonalAccessToken,
|
|
21
25
|
} from 'lib/seam/connect/options.js'
|
|
22
26
|
import { parseOptions } from 'lib/seam/connect/parse-options.js'
|
|
23
27
|
|
|
@@ -82,6 +86,40 @@ export class SeamHttpAcsCredentials {
|
|
|
82
86
|
return SeamHttpAcsCredentials.fromClientSessionToken(token, options)
|
|
83
87
|
}
|
|
84
88
|
|
|
89
|
+
static fromConsoleSessionToken(
|
|
90
|
+
consoleSessionToken: SeamHttpOptionsWithConsoleSessionToken['consoleSessionToken'],
|
|
91
|
+
workspaceId: SeamHttpOptionsWithConsoleSessionToken['workspaceId'],
|
|
92
|
+
options: Omit<
|
|
93
|
+
SeamHttpOptionsWithConsoleSessionToken,
|
|
94
|
+
'consoleSessionToken' | 'workspaceId'
|
|
95
|
+
> = {},
|
|
96
|
+
): SeamHttpAcsCredentials {
|
|
97
|
+
const constructorOptions = { ...options, consoleSessionToken, workspaceId }
|
|
98
|
+
if (!isSeamHttpOptionsWithConsoleSessionToken(constructorOptions)) {
|
|
99
|
+
throw new SeamHttpInvalidOptionsError(
|
|
100
|
+
'Missing consoleSessionToken or workspaceId',
|
|
101
|
+
)
|
|
102
|
+
}
|
|
103
|
+
return new SeamHttpAcsCredentials(constructorOptions)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
static fromPersonalAccessToken(
|
|
107
|
+
personalAccessToken: SeamHttpOptionsWithPersonalAccessToken['personalAccessToken'],
|
|
108
|
+
workspaceId: SeamHttpOptionsWithPersonalAccessToken['workspaceId'],
|
|
109
|
+
options: Omit<
|
|
110
|
+
SeamHttpOptionsWithPersonalAccessToken,
|
|
111
|
+
'personalAccessToken' | 'workspaceId'
|
|
112
|
+
> = {},
|
|
113
|
+
): SeamHttpAcsCredentials {
|
|
114
|
+
const constructorOptions = { ...options, personalAccessToken, workspaceId }
|
|
115
|
+
if (!isSeamHttpOptionsWithPersonalAccessToken(constructorOptions)) {
|
|
116
|
+
throw new SeamHttpInvalidOptionsError(
|
|
117
|
+
'Missing personalAccessToken or workspaceId',
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
return new SeamHttpAcsCredentials(constructorOptions)
|
|
121
|
+
}
|
|
122
|
+
|
|
85
123
|
async create(
|
|
86
124
|
body?: AcsCredentialsCreateBody,
|
|
87
125
|
): Promise<AcsCredentialsCreateResponse['acs_credential']> {
|
|
@@ -12,12 +12,16 @@ import {
|
|
|
12
12
|
isSeamHttpOptionsWithApiKey,
|
|
13
13
|
isSeamHttpOptionsWithClient,
|
|
14
14
|
isSeamHttpOptionsWithClientSessionToken,
|
|
15
|
+
isSeamHttpOptionsWithConsoleSessionToken,
|
|
16
|
+
isSeamHttpOptionsWithPersonalAccessToken,
|
|
15
17
|
type SeamHttpFromPublishableKeyOptions,
|
|
16
18
|
SeamHttpInvalidOptionsError,
|
|
17
19
|
type SeamHttpOptions,
|
|
18
20
|
type SeamHttpOptionsWithApiKey,
|
|
19
21
|
type SeamHttpOptionsWithClient,
|
|
20
22
|
type SeamHttpOptionsWithClientSessionToken,
|
|
23
|
+
type SeamHttpOptionsWithConsoleSessionToken,
|
|
24
|
+
type SeamHttpOptionsWithPersonalAccessToken,
|
|
21
25
|
} from 'lib/seam/connect/options.js'
|
|
22
26
|
import { parseOptions } from 'lib/seam/connect/parse-options.js'
|
|
23
27
|
|
|
@@ -82,6 +86,40 @@ export class SeamHttpAcsSystems {
|
|
|
82
86
|
return SeamHttpAcsSystems.fromClientSessionToken(token, options)
|
|
83
87
|
}
|
|
84
88
|
|
|
89
|
+
static fromConsoleSessionToken(
|
|
90
|
+
consoleSessionToken: SeamHttpOptionsWithConsoleSessionToken['consoleSessionToken'],
|
|
91
|
+
workspaceId: SeamHttpOptionsWithConsoleSessionToken['workspaceId'],
|
|
92
|
+
options: Omit<
|
|
93
|
+
SeamHttpOptionsWithConsoleSessionToken,
|
|
94
|
+
'consoleSessionToken' | 'workspaceId'
|
|
95
|
+
> = {},
|
|
96
|
+
): SeamHttpAcsSystems {
|
|
97
|
+
const constructorOptions = { ...options, consoleSessionToken, workspaceId }
|
|
98
|
+
if (!isSeamHttpOptionsWithConsoleSessionToken(constructorOptions)) {
|
|
99
|
+
throw new SeamHttpInvalidOptionsError(
|
|
100
|
+
'Missing consoleSessionToken or workspaceId',
|
|
101
|
+
)
|
|
102
|
+
}
|
|
103
|
+
return new SeamHttpAcsSystems(constructorOptions)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
static fromPersonalAccessToken(
|
|
107
|
+
personalAccessToken: SeamHttpOptionsWithPersonalAccessToken['personalAccessToken'],
|
|
108
|
+
workspaceId: SeamHttpOptionsWithPersonalAccessToken['workspaceId'],
|
|
109
|
+
options: Omit<
|
|
110
|
+
SeamHttpOptionsWithPersonalAccessToken,
|
|
111
|
+
'personalAccessToken' | 'workspaceId'
|
|
112
|
+
> = {},
|
|
113
|
+
): SeamHttpAcsSystems {
|
|
114
|
+
const constructorOptions = { ...options, personalAccessToken, workspaceId }
|
|
115
|
+
if (!isSeamHttpOptionsWithPersonalAccessToken(constructorOptions)) {
|
|
116
|
+
throw new SeamHttpInvalidOptionsError(
|
|
117
|
+
'Missing personalAccessToken or workspaceId',
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
return new SeamHttpAcsSystems(constructorOptions)
|
|
121
|
+
}
|
|
122
|
+
|
|
85
123
|
async get(
|
|
86
124
|
body?: AcsSystemsGetParams,
|
|
87
125
|
): Promise<AcsSystemsGetResponse['acs_system']> {
|