Skip to content

Commit 2d59cd3

Browse files
committed
fix: SeamHttpMultiWorkspace with SEAM_PERSONAL_ACCESS_TOKEN
1 parent 986c22d commit 2d59cd3

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

ava.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ export default () => {
44
delete env.SEAM_API_KEY
55
delete env.SEAM_ENDPOINT
66
delete env.SEAM_API_URL
7+
delete env.SEAM_PERSONAL_ACCESS_TOKEN
8+
delete env.SEAM_WORKSPACE_ID
79

810
return {
911
ignoredByWatcher: ['tmp/**/*'],

src/lib/seam/connect/env.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ declare global {
44
SEAM_API_KEY?: string
55
SEAM_API_URL?: string
66
SEAM_ENDPOINT?: string
7+
SEAM_PERSONAL_ACCESS_TOKEN?: string
8+
SEAM_WORKSPACE_ID?: string
79
}
810
}
911
}

src/lib/seam/connect/parse-options.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,8 @@ const getNormalizedOptions = (
9999
return {
100100
...options,
101101
...(apiKey != null ? { apiKey } : {}),
102-
...(personalAccessToken != null && workspaceId != null
103-
? { personalAccessToken, workspaceId }
104-
: {}),
102+
...(workspaceId != null ? { workspaceId } : {}),
103+
...(personalAccessToken != null ? { personalAccessToken } : {}),
105104
...requestOptions,
106105
}
107106
}
@@ -133,11 +132,11 @@ const getPersonalAccessTokenFromEnv = (
133132
if ('consoleSessionToken' in options && options.consoleSessionToken != null) {
134133
return null
135134
}
136-
return globalThis.process?.env?.['SEAM_PERSONAL_ACCESS_TOKEN']
135+
return globalThis.process?.env?.SEAM_PERSONAL_ACCESS_TOKEN
137136
}
138137

139138
const getWorkspaceIdFromEnv = (): string | null | undefined => {
140-
return globalThis.process?.env?.['SEAM_WORKSPACE_ID']
139+
return globalThis.process?.env?.SEAM_WORKSPACE_ID
141140
}
142141

143142
const getEndpointFromEnv = (): string | null | undefined => {

test/seam/connect/env.test.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ const cleanupEnv = (): void => {
1717
delete env.SEAM_API_KEY
1818
delete env.SEAM_ENDPOINT
1919
delete env.SEAM_API_URL
20+
delete env.SEAM_PERSONAL_ACCESS_TOKEN
21+
delete env.SEAM_WORKSPACE_ID
2022
}
2123
test.afterEach(cleanupEnv)
2224
test.beforeEach(cleanupEnv)
@@ -282,8 +284,8 @@ test.serial(
282284
'SeamHttp: constructor uses SEAM_PERSONAL_ACCESS_TOKEN and SEAM_WORKSPACE_ID environment variables',
283285
async (t) => {
284286
const { seed, endpoint } = await getTestServer(t)
285-
env['SEAM_PERSONAL_ACCESS_TOKEN'] = seed.seam_at1_token
286-
env['SEAM_WORKSPACE_ID'] = seed.seed_workspace_1
287+
env.SEAM_PERSONAL_ACCESS_TOKEN = seed.seam_at1_token
288+
env.SEAM_WORKSPACE_ID = seed.seed_workspace_1
287289
const seam = new SeamHttp({ endpoint })
288290
const device = await seam.devices.get({
289291
device_id: seed.august_device_1,
@@ -297,8 +299,8 @@ test.serial(
297299
'SeamHttp: throws error when both SEAM_API_KEY and SEAM_PERSONAL_ACCESS_TOKEN are defined',
298300
(t) => {
299301
env.SEAM_API_KEY = 'some-api-key'
300-
env['SEAM_PERSONAL_ACCESS_TOKEN'] = 'some-access-token'
301-
env['SEAM_WORKSPACE_ID'] = 'some-workspace-id'
302+
env.SEAM_PERSONAL_ACCESS_TOKEN = 'some-access-token'
303+
env.SEAM_WORKSPACE_ID = 'some-workspace-id'
302304
t.throws(() => new SeamHttp(), {
303305
instanceOf: SeamHttpInvalidOptionsError,
304306
message:
@@ -311,8 +313,8 @@ test.serial(
311313
'SeamHttp: personalAccessToken option overrides environment variables',
312314
async (t) => {
313315
const { seed, endpoint } = await getTestServer(t)
314-
env['SEAM_PERSONAL_ACCESS_TOKEN'] = 'some-invalid-token'
315-
env['SEAM_WORKSPACE_ID'] = seed.seed_workspace_1
316+
env.SEAM_PERSONAL_ACCESS_TOKEN = 'some-invalid-token'
317+
env.SEAM_WORKSPACE_ID = seed.seed_workspace_1
316318
const seam = new SeamHttp({
317319
personalAccessToken: seed.seam_at1_token,
318320
endpoint,
@@ -329,8 +331,8 @@ test.serial(
329331
'SeamHttp: workspaceId option overrides environment variables',
330332
async (t) => {
331333
const { seed, endpoint } = await getTestServer(t)
332-
env['SEAM_PERSONAL_ACCESS_TOKEN'] = seed.seam_at1_token
333-
env['SEAM_WORKSPACE_ID'] = 'some-invalid-workspace'
334+
env.SEAM_PERSONAL_ACCESS_TOKEN = seed.seam_at1_token
335+
env.SEAM_WORKSPACE_ID = 'some-invalid-workspace'
334336
const seam = new SeamHttp({
335337
workspaceId: seed.seed_workspace_1,
336338
endpoint,
@@ -347,7 +349,7 @@ test.serial(
347349
'SeamHttpMultiWorkspace: constructor uses SEAM_PERSONAL_ACCESS_TOKEN environment variable',
348350
async (t) => {
349351
const { seed, endpoint } = await getTestServer(t)
350-
env['SEAM_PERSONAL_ACCESS_TOKEN'] = seed.seam_at1_token
352+
env.SEAM_PERSONAL_ACCESS_TOKEN = seed.seam_at1_token
351353
const multiWorkspace = new SeamHttpMultiWorkspace({ endpoint })
352354
const workspaces = await multiWorkspace.workspaces.list()
353355
t.true(workspaces.length > 0)
@@ -358,7 +360,7 @@ test.serial(
358360
'SeamHttpMultiWorkspace: personalAccessToken option overrides environment variables',
359361
async (t) => {
360362
const { seed, endpoint } = await getTestServer(t)
361-
env['SEAM_PERSONAL_ACCESS_TOKEN'] = 'some-invalid-token'
363+
env.SEAM_PERSONAL_ACCESS_TOKEN = 'some-invalid-token'
362364
const multiWorkspace = new SeamHttpMultiWorkspace({
363365
personalAccessToken: seed.seam_at1_token,
364366
endpoint,

0 commit comments

Comments
 (0)