Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Should ignore SEAM_API_KEY with fromPersonalAccessToken and fromConsoleSessionToken #35

Merged
merged 1 commit into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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