mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
chore(lint): replace ESLint with Oxlint and clear anti-slop findings
This commit is contained in:
1 parent
c6c13335e5
commit
b625acfc0c
1083 files changed
+67089
-80136
No files matched your search
+24
-11
@@ -1,6 +1,7 @@
|
||||
import { readState } from './state.js'
|
||||
import { readState, type OcmState } from './state.js'
|
||||
import { getToken, describeTokenStore } from './internal-token-store.js'
|
||||
import { TokenStoreError } from './token-store.js'
|
||||
import type { TokenStoreDescription } from './token-store.js'
|
||||
import { ManagerApi } from './manager-api.js'
|
||||
import { trimUrlTrailingSlashes } from '@opencode-manager/shared/utils'
|
||||
|
||||
@@ -16,11 +17,20 @@ export type ResolveManagerApiResult =
|
||||
| { ok: true; auth: ManagerAuthOk; api: ManagerApi }
|
||||
| { ok: false; message: string }
|
||||
|
||||
/** Resolves the Manager URL and token used to authenticate CLI requests. */
|
||||
export interface ManagerAuthDeps {
|
||||
readState: () => OcmState | null
|
||||
getToken: (account: string) => Promise<string | null>
|
||||
describeTokenStore: () => TokenStoreDescription
|
||||
}
|
||||
|
||||
export const managerAuthDeps: ManagerAuthDeps = { readState, getToken, describeTokenStore }
|
||||
|
||||
export async function resolveManagerAuth(
|
||||
rawManagerUrl: string | undefined = readState()?.managerUrl,
|
||||
rawManagerUrl?: string,
|
||||
deps: ManagerAuthDeps = managerAuthDeps,
|
||||
): Promise<ManagerAuth> {
|
||||
const managerUrl = rawManagerUrl ? trimUrlTrailingSlashes(rawManagerUrl) : ''
|
||||
const requestedUrl = rawManagerUrl ?? deps.readState()?.managerUrl
|
||||
const managerUrl = requestedUrl ? trimUrlTrailingSlashes(requestedUrl) : ''
|
||||
if (!managerUrl) {
|
||||
return {
|
||||
ok: false,
|
||||
@@ -31,13 +41,13 @@ export async function resolveManagerAuth(
|
||||
|
||||
let token: string | null
|
||||
try {
|
||||
token = await getToken(managerUrl)
|
||||
token = await deps.getToken(managerUrl)
|
||||
} catch (err) {
|
||||
if (!(err instanceof TokenStoreError)) throw err
|
||||
return {
|
||||
ok: false,
|
||||
reason: 'token-store',
|
||||
message: `token store error (${tokenStoreLabel()}): ${err.message}. Run \`ocm login ${managerUrl}\` after fixing the store.`,
|
||||
message: `token store error (${tokenStoreLabel(deps)}): ${err.message}. Run \`ocm login ${managerUrl}\` after fixing the store.`,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,20 +55,23 @@ export async function resolveManagerAuth(
|
||||
return {
|
||||
ok: false,
|
||||
reason: 'no-token',
|
||||
message: `no token stored for ${managerUrl} (${tokenStoreLabel()}). Run \`ocm login ${managerUrl}\`.`,
|
||||
message: `no token stored for ${managerUrl} (${tokenStoreLabel(deps)}). Run \`ocm login ${managerUrl}\`.`,
|
||||
}
|
||||
}
|
||||
|
||||
return { ok: true, managerUrl, token }
|
||||
}
|
||||
|
||||
function tokenStoreLabel(): string {
|
||||
const store = describeTokenStore()
|
||||
function tokenStoreLabel(deps: ManagerAuthDeps): string {
|
||||
const store = deps.describeTokenStore()
|
||||
return `${store.kind}: ${store.location}`
|
||||
}
|
||||
|
||||
export async function resolveManagerApi(managerUrl?: string): Promise<ResolveManagerApiResult> {
|
||||
const auth = await resolveManagerAuth(managerUrl)
|
||||
export async function resolveManagerApi(
|
||||
managerUrl?: string,
|
||||
deps: ManagerAuthDeps = managerAuthDeps,
|
||||
): Promise<ResolveManagerApiResult> {
|
||||
const auth = await resolveManagerAuth(managerUrl, deps)
|
||||
if (!auth.ok) return { ok: false, message: auth.message }
|
||||
return { ok: true, auth, api: new ManagerApi(auth.managerUrl, auth.token) }
|
||||
}
|
||||
Reference in new issue
Block a user