Skip to content
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
25 changes: 0 additions & 25 deletions src/lib/auth/operations.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { randomBytes } from 'node:crypto'

import { type ConfigStore, getConfigStore } from 'lib/config/index.js'
import { type AuthContext, resolveAuth } from 'lib/context.js'
import {
Expand Down Expand Up @@ -134,29 +132,6 @@ export const selectWorkspace = (
config.set('current_workspace_id', workspaceId)
}

/**
* Point the CLI at a fake Seam Connect endpoint and store the well-known
* token it accepts. Returns the generated endpoint URL for reporting.
*/
export const selectFakeEndpoint = ({
urlSeed = randomBytes(5).toString('hex'),
config = getConfigStore(),
}: {
urlSeed?: string
config?: ConfigStore
} = {}): { endpoint: string; token: string } => {
const auth = resolveAuth(config)
assertMutable(auth, 'endpoint', 'select an endpoint')
assertMutable(auth, 'token', 'log in')

const endpoint = `https://${urlSeed}.fakeseamconnect.seam.vc`
const token = 'seam_apikey1_token'
storeEndpoint(endpoint, config)
config.set(`${endpoint}.pat`, token)

return { endpoint, token }
}

/** Store whether API definitions come from the endpoint instead of npm. */
export const setUseRemoteApiDefs = (
useRemoteApiDefs: boolean,
Expand Down
34 changes: 5 additions & 29 deletions src/lib/interactions/endpoint-selection.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
import { randomBytes } from 'node:crypto'

import {
assertMutable,
selectEndpoint,
selectFakeEndpoint,
} from 'lib/auth/operations.js'
import { assertMutable, selectEndpoint } from 'lib/auth/operations.js'
import { getConfigStore } from 'lib/config/index.js'
import { resolveAuth } from 'lib/context.js'
import { getOutput } from 'lib/output/get-output.js'
import { promptAutocomplete, promptText } from 'lib/prompt.js'
import { promptAutocomplete } from 'lib/prompt.js'

export async function interactForEndpointSelection() {
const config = getConfigStore()
assertMutable(resolveAuth(config), 'endpoint', 'select an endpoint')

const endpoints = [
'http://localhost:3020',
'https://connect.getseam.com',
'https://fakeseamconnect.seam.vc',
]
const endpoints = ['http://localhost:3020', 'https://connect.getseam.com']

// Searchable, as selecting a device or a command is.
const endpoint = await promptAutocomplete({
Expand All @@ -29,20 +19,6 @@ export async function interactForEndpointSelection() {
})),
})

const output = getOutput()
if (endpoint === endpoints[2]) {
let userUrlSeed = await promptText({
message:
'You can input a custom endpoint URL or leave this field empty to use a new fakeserver.',
})

if (userUrlSeed.trim().length === 0) {
userUrlSeed = randomBytes(5).toString('hex')
}
selectFakeEndpoint({ urlSeed: userUrlSeed, config })
output.info(`PAT set to use fakeseamconnect with "seam_apikey1_token"`)
} else {
selectEndpoint(endpoint, config)
}
output.info(`Endpoint set to ${endpoint}`)
selectEndpoint(endpoint, config)
getOutput().info(`Endpoint set to ${endpoint}`)
}
3 changes: 1 addition & 2 deletions src/lib/prompt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ test('searchChoices: matches any part of a name, not only its start', () => {
const endpoints = [
{ label: 'http://localhost:3020' },
{ label: 'https://connect.getseam.com' },
{ label: 'https://fakeseamconnect.seam.vc' },
]

expect(search('fake', endpoints)).toEqual([endpoints[2]])
expect(search('seam', endpoints)).toEqual([endpoints[1]])
})

test('searchChoices: offers every choice until something is typed', () => {
Expand Down
24 changes: 0 additions & 24 deletions test/auth/operations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
login,
logout,
selectEndpoint,
selectFakeEndpoint,
selectWorkspace,
storeToken,
} from 'lib/auth/operations.js'
Expand Down Expand Up @@ -212,26 +211,3 @@ test(`selectWorkspace: refuses while ${workspaceIdEnvVar} is set`, () => {
selectWorkspace('workspace1', store)
}).toThrow(`Cannot select a workspace while ${workspaceIdEnvVar} is set`)
})

test('selectFakeEndpoint: stores the endpoint and its well-known token', () => {
const store = createMemoryConfigStore({ current_workspace_id: 'workspace1' })

const { endpoint: fakeEndpoint } = selectFakeEndpoint({
urlSeed: 'abc123',
config: store,
})

expect(fakeEndpoint).toBe('https://abc123.fakeseamconnect.seam.vc')
expect(store.get('endpoint')).toBe(fakeEndpoint)
expect(store.get(`${fakeEndpoint}.pat`)).toBe('seam_apikey1_token')
expect(store.has('current_workspace_id')).toBe(false)
})

test(`selectFakeEndpoint: refuses while ${endpointEnvVar} is set`, () => {
process.env[endpointEnvVar] = endpoint
const store = createMemoryConfigStore()

expect(() =>
selectFakeEndpoint({ urlSeed: 'abc123', config: store }),
).toThrow(`Cannot select an endpoint while ${endpointEnvVar} is set`)
})
Loading