@seamapi/http 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/connect.cjs +165 -102
- package/dist/connect.cjs.map +1 -1
- package/dist/connect.d.cts +31 -3
- package/lib/seam/connect/auth.js +13 -9
- package/lib/seam/connect/auth.js.map +1 -1
- package/lib/seam/connect/index.d.ts +2 -0
- package/lib/seam/connect/index.js +2 -0
- package/lib/seam/connect/index.js.map +1 -1
- package/lib/seam/connect/options.d.ts +15 -0
- package/lib/seam/connect/options.js +23 -8
- package/lib/seam/connect/options.js.map +1 -1
- package/lib/seam/connect/parse-options.d.ts +3 -3
- package/lib/seam/connect/parse-options.js +3 -1
- package/lib/seam/connect/parse-options.js.map +1 -1
- package/lib/seam/connect/seam-http-multi-workspace.d.ts +11 -0
- package/lib/seam/connect/seam-http-multi-workspace.js +35 -0
- package/lib/seam/connect/seam-http-multi-workspace.js.map +1 -0
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +1 -1
- package/src/lib/seam/connect/auth.ts +28 -10
- package/src/lib/seam/connect/index.ts +2 -0
- package/src/lib/seam/connect/options.ts +63 -17
- package/src/lib/seam/connect/parse-options.ts +6 -1
- package/src/lib/seam/connect/seam-http-multi-workspace.ts +77 -0
- package/src/lib/version.ts +1 -1
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { Client, ClientOptions } from './client.js'
|
|
2
2
|
|
|
3
|
+
export type SeamHttpMultiWorkspaceOptions =
|
|
4
|
+
| SeamHttpMultiWorkspaceOptionsWithClient
|
|
5
|
+
| SeamHttpMultiWorkspaceOptionsWithConsoleSessionToken
|
|
6
|
+
| SeamHttpMultiWorkspaceOptionsWithPersonalAccessToken
|
|
7
|
+
|
|
3
8
|
export type SeamHttpOptions =
|
|
4
9
|
| SeamHttpOptionsFromEnv
|
|
5
10
|
| SeamHttpOptionsWithClient
|
|
@@ -17,6 +22,15 @@ export interface SeamHttpFromPublishableKeyOptions
|
|
|
17
22
|
|
|
18
23
|
export interface SeamHttpOptionsFromEnv extends SeamHttpCommonOptions {}
|
|
19
24
|
|
|
25
|
+
export interface SeamHttpMultiWorkspaceOptionsWithClient {
|
|
26
|
+
client: Client
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const isSeamHttpMultiWorkspaceOptionsWithClient = (
|
|
30
|
+
options: SeamHttpOptions,
|
|
31
|
+
): options is SeamHttpMultiWorkspaceOptionsWithClient =>
|
|
32
|
+
isSeamHttpOptionsWithClient(options)
|
|
33
|
+
|
|
20
34
|
export interface SeamHttpOptionsWithClient {
|
|
21
35
|
client: Client
|
|
22
36
|
}
|
|
@@ -102,24 +116,17 @@ export const isSeamHttpOptionsWithClientSessionToken = (
|
|
|
102
116
|
return true
|
|
103
117
|
}
|
|
104
118
|
|
|
105
|
-
export interface
|
|
119
|
+
export interface SeamHttpMultiWorkspaceOptionsWithConsoleSessionToken
|
|
106
120
|
extends SeamHttpCommonOptions {
|
|
107
121
|
consoleSessionToken: string
|
|
108
|
-
workspaceId: string
|
|
109
122
|
}
|
|
110
123
|
|
|
111
|
-
export const
|
|
124
|
+
export const isSeamHttpMultiWorkspaceOptionsWithConsoleSessionToken = (
|
|
112
125
|
options: SeamHttpOptions,
|
|
113
|
-
): options is
|
|
126
|
+
): options is SeamHttpMultiWorkspaceOptionsWithConsoleSessionToken => {
|
|
114
127
|
if (!('consoleSessionToken' in options)) return false
|
|
115
128
|
if (options.consoleSessionToken == null) return false
|
|
116
129
|
|
|
117
|
-
if (!('workspaceId' in options) || options.workspaceId == null) {
|
|
118
|
-
throw new SeamHttpInvalidOptionsError(
|
|
119
|
-
'Must pass a workspaceId when using a consoleSessionToken',
|
|
120
|
-
)
|
|
121
|
-
}
|
|
122
|
-
|
|
123
130
|
if ('apiKey' in options && options.apiKey != null) {
|
|
124
131
|
throw new SeamHttpInvalidOptionsError(
|
|
125
132
|
'The apiKey option cannot be used with the consoleSessionToken option',
|
|
@@ -141,24 +148,39 @@ export const isSeamHttpOptionsWithConsoleSessionToken = (
|
|
|
141
148
|
return true
|
|
142
149
|
}
|
|
143
150
|
|
|
144
|
-
export interface
|
|
151
|
+
export interface SeamHttpOptionsWithConsoleSessionToken
|
|
145
152
|
extends SeamHttpCommonOptions {
|
|
146
|
-
|
|
153
|
+
consoleSessionToken: string
|
|
147
154
|
workspaceId: string
|
|
148
155
|
}
|
|
149
156
|
|
|
150
|
-
export const
|
|
157
|
+
export const isSeamHttpOptionsWithConsoleSessionToken = (
|
|
151
158
|
options: SeamHttpOptions,
|
|
152
|
-
): options is
|
|
153
|
-
if (!(
|
|
154
|
-
|
|
159
|
+
): options is SeamHttpOptionsWithConsoleSessionToken => {
|
|
160
|
+
if (!isSeamHttpMultiWorkspaceOptionsWithConsoleSessionToken(options)) {
|
|
161
|
+
return false
|
|
162
|
+
}
|
|
155
163
|
|
|
156
164
|
if (!('workspaceId' in options) || options.workspaceId == null) {
|
|
157
165
|
throw new SeamHttpInvalidOptionsError(
|
|
158
|
-
'Must pass a workspaceId when using a
|
|
166
|
+
'Must pass a workspaceId when using a consoleSessionToken',
|
|
159
167
|
)
|
|
160
168
|
}
|
|
161
169
|
|
|
170
|
+
return true
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export interface SeamHttpMultiWorkspaceOptionsWithPersonalAccessToken
|
|
174
|
+
extends SeamHttpCommonOptions {
|
|
175
|
+
personalAccessToken: string
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export const isSeamHttpMultiWorkspaceOptionsWithPersonalAccessToken = (
|
|
179
|
+
options: SeamHttpOptions,
|
|
180
|
+
): options is SeamHttpMultiWorkspaceOptionsWithPersonalAccessToken => {
|
|
181
|
+
if (!('personalAccessToken' in options)) return false
|
|
182
|
+
if (options.personalAccessToken == null) return false
|
|
183
|
+
|
|
162
184
|
if ('apiKey' in options && options.apiKey != null) {
|
|
163
185
|
throw new SeamHttpInvalidOptionsError(
|
|
164
186
|
'The apiKey option cannot be used with the personalAccessToken option',
|
|
@@ -180,6 +202,28 @@ export const isSeamHttpOptionsWithPersonalAccessToken = (
|
|
|
180
202
|
return true
|
|
181
203
|
}
|
|
182
204
|
|
|
205
|
+
export interface SeamHttpOptionsWithPersonalAccessToken
|
|
206
|
+
extends SeamHttpCommonOptions {
|
|
207
|
+
personalAccessToken: string
|
|
208
|
+
workspaceId: string
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export const isSeamHttpOptionsWithPersonalAccessToken = (
|
|
212
|
+
options: SeamHttpOptions,
|
|
213
|
+
): options is SeamHttpOptionsWithPersonalAccessToken => {
|
|
214
|
+
if (!isSeamHttpMultiWorkspaceOptionsWithPersonalAccessToken(options)) {
|
|
215
|
+
return false
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (!('workspaceId' in options) || options.workspaceId == null) {
|
|
219
|
+
throw new SeamHttpInvalidOptionsError(
|
|
220
|
+
'Must pass a workspaceId when using a personalAccessToken',
|
|
221
|
+
)
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return true
|
|
225
|
+
}
|
|
226
|
+
|
|
183
227
|
export class SeamHttpInvalidOptionsError extends Error {
|
|
184
228
|
constructor(message: string) {
|
|
185
229
|
super(`SeamHttp received invalid options: ${message}`)
|
|
@@ -187,3 +231,5 @@ export class SeamHttpInvalidOptionsError extends Error {
|
|
|
187
231
|
Error.captureStackTrace(this, this.constructor)
|
|
188
232
|
}
|
|
189
233
|
}
|
|
234
|
+
|
|
235
|
+
export class SeamHttpMultiWorkspaceInvalidOptionsError extends SeamHttpInvalidOptionsError {}
|
|
@@ -3,8 +3,10 @@ import version from 'lib/version.js'
|
|
|
3
3
|
import { getAuthHeaders } from './auth.js'
|
|
4
4
|
import type { ClientOptions } from './client.js'
|
|
5
5
|
import {
|
|
6
|
+
isSeamHttpMultiWorkspaceOptionsWithClient,
|
|
6
7
|
isSeamHttpOptionsWithClient,
|
|
7
8
|
isSeamHttpOptionsWithClientSessionToken,
|
|
9
|
+
type SeamHttpMultiWorkspaceOptions,
|
|
8
10
|
type SeamHttpOptions,
|
|
9
11
|
} from './options.js'
|
|
10
12
|
|
|
@@ -15,7 +17,9 @@ const sdkHeaders = {
|
|
|
15
17
|
'seam-sdk-version': version,
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
export type Options =
|
|
20
|
+
export type Options =
|
|
21
|
+
| SeamHttpMultiWorkspaceOptions
|
|
22
|
+
| (SeamHttpOptions & { publishableKey?: string })
|
|
19
23
|
|
|
20
24
|
export const parseOptions = (
|
|
21
25
|
apiKeyOrOptions: string | Options,
|
|
@@ -23,6 +27,7 @@ export const parseOptions = (
|
|
|
23
27
|
const options = getNormalizedOptions(apiKeyOrOptions)
|
|
24
28
|
|
|
25
29
|
if (isSeamHttpOptionsWithClient(options)) return options
|
|
30
|
+
if (isSeamHttpMultiWorkspaceOptionsWithClient(options)) return options
|
|
26
31
|
|
|
27
32
|
return {
|
|
28
33
|
axiosOptions: {
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { type Client, createClient } from './client.js'
|
|
2
|
+
import {
|
|
3
|
+
isSeamHttpMultiWorkspaceOptionsWithClient,
|
|
4
|
+
isSeamHttpMultiWorkspaceOptionsWithConsoleSessionToken,
|
|
5
|
+
isSeamHttpMultiWorkspaceOptionsWithPersonalAccessToken,
|
|
6
|
+
SeamHttpMultiWorkspaceInvalidOptionsError,
|
|
7
|
+
type SeamHttpMultiWorkspaceOptions,
|
|
8
|
+
type SeamHttpMultiWorkspaceOptionsWithClient,
|
|
9
|
+
type SeamHttpMultiWorkspaceOptionsWithConsoleSessionToken,
|
|
10
|
+
type SeamHttpMultiWorkspaceOptionsWithPersonalAccessToken,
|
|
11
|
+
} from './options.js'
|
|
12
|
+
import { parseOptions } from './parse-options.js'
|
|
13
|
+
import { SeamHttpWorkspaces } from './routes/index.js'
|
|
14
|
+
|
|
15
|
+
export class SeamHttpMultiWorkspace {
|
|
16
|
+
client: Client
|
|
17
|
+
|
|
18
|
+
constructor(options: SeamHttpMultiWorkspaceOptions) {
|
|
19
|
+
const clientOptions = parseOptions(options)
|
|
20
|
+
this.client = createClient(clientOptions)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static fromClient(
|
|
24
|
+
client: SeamHttpMultiWorkspaceOptionsWithClient['client'],
|
|
25
|
+
options: Omit<SeamHttpMultiWorkspaceOptionsWithClient, 'client'> = {},
|
|
26
|
+
): SeamHttpMultiWorkspace {
|
|
27
|
+
const constructorOptions = { ...options, client }
|
|
28
|
+
if (!isSeamHttpMultiWorkspaceOptionsWithClient(constructorOptions)) {
|
|
29
|
+
throw new SeamHttpMultiWorkspaceInvalidOptionsError('Missing client')
|
|
30
|
+
}
|
|
31
|
+
return new SeamHttpMultiWorkspace(constructorOptions)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static fromConsoleSessionToken(
|
|
35
|
+
consoleSessionToken: SeamHttpMultiWorkspaceOptionsWithConsoleSessionToken['consoleSessionToken'],
|
|
36
|
+
options: Omit<
|
|
37
|
+
SeamHttpMultiWorkspaceOptionsWithConsoleSessionToken,
|
|
38
|
+
'consoleSessionToken'
|
|
39
|
+
> = {},
|
|
40
|
+
): SeamHttpMultiWorkspace {
|
|
41
|
+
const constructorOptions = { ...options, consoleSessionToken }
|
|
42
|
+
if (
|
|
43
|
+
!isSeamHttpMultiWorkspaceOptionsWithConsoleSessionToken(
|
|
44
|
+
constructorOptions,
|
|
45
|
+
)
|
|
46
|
+
) {
|
|
47
|
+
throw new SeamHttpMultiWorkspaceInvalidOptionsError(
|
|
48
|
+
'Missing consoleSessionToken',
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
return new SeamHttpMultiWorkspace(constructorOptions)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static fromPersonalAccessToken(
|
|
55
|
+
personalAccessToken: SeamHttpMultiWorkspaceOptionsWithPersonalAccessToken['personalAccessToken'],
|
|
56
|
+
options: Omit<
|
|
57
|
+
SeamHttpMultiWorkspaceOptionsWithPersonalAccessToken,
|
|
58
|
+
'personalAccessToken'
|
|
59
|
+
> = {},
|
|
60
|
+
): SeamHttpMultiWorkspace {
|
|
61
|
+
const constructorOptions = { ...options, personalAccessToken }
|
|
62
|
+
if (
|
|
63
|
+
!isSeamHttpMultiWorkspaceOptionsWithPersonalAccessToken(
|
|
64
|
+
constructorOptions,
|
|
65
|
+
)
|
|
66
|
+
) {
|
|
67
|
+
throw new SeamHttpMultiWorkspaceInvalidOptionsError(
|
|
68
|
+
'Missing personalAccessToken',
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
return new SeamHttpMultiWorkspace(constructorOptions)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
get workspaces(): SeamHttpWorkspaces {
|
|
75
|
+
return SeamHttpWorkspaces.fromClient(this.client)
|
|
76
|
+
}
|
|
77
|
+
}
|
package/src/lib/version.ts
CHANGED