Skip to content

Commit ce1e697

Browse files
authored
Merge pull request #35 from seamapi/fix-env-parsing
fix: Should ignore SEAM_API_KEY with fromPersonalAccessToken and fromConsoleSessionToken
2 parents b441dfb + dcd00a3 commit ce1e697

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

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

+6
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ const getApiKeyFromEnv = (
8787
if ('clientSessionToken' in options && options.clientSessionToken != null) {
8888
return null
8989
}
90+
if ('consoleSessionToken' in options && options.consoleSessionToken != null) {
91+
return null
92+
}
93+
if ('personalAccessToken' in options && options.personalAccessToken != null) {
94+
return null
95+
}
9096
return globalThis.process?.env?.SEAM_API_KEY
9197
}
9298

test/seam/connect/env.test.ts

+46-2
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ test.serial(
152152
'SeamHttp: SEAM_API_KEY environment variable is ignored with fromClientSessionToken',
153153
async (t) => {
154154
const { seed, endpoint } = await getTestServer(t)
155-
env.SEAM_API_KEY = 'some-invalid-api-key-4'
155+
env.SEAM_API_KEY = seed.seam_apikey1_token
156156
const seam = SeamHttp.fromClientSessionToken(seed.seam_cst1_token, {
157157
endpoint,
158158
})
@@ -168,7 +168,7 @@ test.serial(
168168
'SeamHttp: SEAM_API_KEY environment variable is ignored with fromPublishableKey',
169169
async (t) => {
170170
const { seed, endpoint } = await getTestServer(t)
171-
env.SEAM_API_KEY = 'some-invalid-api-key-5'
171+
env.SEAM_API_KEY = seed.seam_apikey1_token
172172
const seam = await SeamHttp.fromPublishableKey(
173173
seed.seam_pk1_token,
174174
seed.john_user_identifier_key,
@@ -184,6 +184,50 @@ test.serial(
184184
},
185185
)
186186

187+
// UPSTREAM: Fake does not support JWT.
188+
// https://github.com/seamapi/fake-seam-connect/issues/124
189+
test.serial.failing(
190+
'SeamHttp: SEAM_API_KEY environment variable is ignored with fromConsoleSessionToken',
191+
async (t) => {
192+
const { seed, endpoint } = await getTestServer(t)
193+
env.SEAM_API_KEY = seed.seam_apikey1_token
194+
const seam = SeamHttp.fromConsoleSessionToken(
195+
'ey_TODO',
196+
seed.seed_workspace_1,
197+
{
198+
endpoint,
199+
},
200+
)
201+
const device = await seam.devices.get({
202+
device_id: seed.august_device_1,
203+
})
204+
t.is(device.workspace_id, seed.seed_workspace_1)
205+
t.is(device.device_id, seed.august_device_1)
206+
},
207+
)
208+
209+
// UPSTREAM: Fake does not support personal access token.
210+
// https://github.com/seamapi/fake-seam-connect/issues/126
211+
test.serial.failing(
212+
'SeamHttp: SEAM_API_KEY environment variable is ignored with personalAccessToken',
213+
async (t) => {
214+
const { seed, endpoint } = await getTestServer(t)
215+
env.SEAM_API_KEY = seed.seam_apikey1_token
216+
const seam = SeamHttp.fromPersonalAccessToken(
217+
'seam_at_TODO',
218+
seed.seed_workspace_1,
219+
{
220+
endpoint,
221+
},
222+
)
223+
const device = await seam.devices.get({
224+
device_id: seed.august_device_1,
225+
})
226+
t.is(device.workspace_id, seed.seed_workspace_1)
227+
t.is(device.device_id, seed.august_device_1)
228+
},
229+
)
230+
187231
test.serial(
188232
'SeamHttp: SEAM_ENDPOINT environment variable is used with fromPublishableKey',
189233
async (t) => {

0 commit comments

Comments
 (0)