Skip to content

Commit

Permalink
Merge pull request #35 from seamapi/fix-env-parsing
Browse files Browse the repository at this point in the history
fix: Should ignore SEAM_API_KEY with fromPersonalAccessToken and fromConsoleSessionToken
  • Loading branch information
razor-x authored Dec 21, 2023
2 parents b441dfb + dcd00a3 commit ce1e697
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/lib/seam/connect/parse-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ const getApiKeyFromEnv = (
if ('clientSessionToken' in options && options.clientSessionToken != null) {
return null
}
if ('consoleSessionToken' in options && options.consoleSessionToken != null) {
return null
}
if ('personalAccessToken' in options && options.personalAccessToken != null) {
return null
}
return globalThis.process?.env?.SEAM_API_KEY
}

Expand Down
48 changes: 46 additions & 2 deletions test/seam/connect/env.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ test.serial(
'SeamHttp: SEAM_API_KEY environment variable is ignored with fromClientSessionToken',
async (t) => {
const { seed, endpoint } = await getTestServer(t)
env.SEAM_API_KEY = 'some-invalid-api-key-4'
env.SEAM_API_KEY = seed.seam_apikey1_token
const seam = SeamHttp.fromClientSessionToken(seed.seam_cst1_token, {
endpoint,
})
Expand All @@ -168,7 +168,7 @@ test.serial(
'SeamHttp: SEAM_API_KEY environment variable is ignored with fromPublishableKey',
async (t) => {
const { seed, endpoint } = await getTestServer(t)
env.SEAM_API_KEY = 'some-invalid-api-key-5'
env.SEAM_API_KEY = seed.seam_apikey1_token
const seam = await SeamHttp.fromPublishableKey(
seed.seam_pk1_token,
seed.john_user_identifier_key,
Expand All @@ -184,6 +184,50 @@ test.serial(
},
)

// UPSTREAM: Fake does not support JWT.
// https://github.com/seamapi/fake-seam-connect/issues/124
test.serial.failing(
'SeamHttp: SEAM_API_KEY environment variable is ignored with fromConsoleSessionToken',
async (t) => {
const { seed, endpoint } = await getTestServer(t)
env.SEAM_API_KEY = seed.seam_apikey1_token
const seam = SeamHttp.fromConsoleSessionToken(
'ey_TODO',
seed.seed_workspace_1,
{
endpoint,
},
)
const device = await seam.devices.get({
device_id: seed.august_device_1,
})
t.is(device.workspace_id, seed.seed_workspace_1)
t.is(device.device_id, seed.august_device_1)
},
)

// UPSTREAM: Fake does not support personal access token.
// https://github.com/seamapi/fake-seam-connect/issues/126
test.serial.failing(
'SeamHttp: SEAM_API_KEY environment variable is ignored with personalAccessToken',
async (t) => {
const { seed, endpoint } = await getTestServer(t)
env.SEAM_API_KEY = seed.seam_apikey1_token
const seam = SeamHttp.fromPersonalAccessToken(
'seam_at_TODO',
seed.seed_workspace_1,
{
endpoint,
},
)
const device = await seam.devices.get({
device_id: seed.august_device_1,
})
t.is(device.workspace_id, seed.seed_workspace_1)
t.is(device.device_id, seed.august_device_1)
},
)

test.serial(
'SeamHttp: SEAM_ENDPOINT environment variable is used with fromPublishableKey',
async (t) => {
Expand Down

0 comments on commit ce1e697

Please sign in to comment.