ffba34c548
lex-client's strict mode rejects the legacy blob reference format
({cid, mimeType}) still present in older records; the old stack
tolerated it. Route all client construction through the factory.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
33 lines
899 B
TypeScript
33 lines
899 B
TypeScript
import {useQuery} from '@tanstack/react-query'
|
|
|
|
import {createLexClient} from '#/lib/lexClient'
|
|
import {com} from '#/lexicons'
|
|
|
|
const RQKEY_ROOT = 'service'
|
|
export const RQKEY = (serviceUrl: string) => [RQKEY_ROOT, serviceUrl]
|
|
|
|
export function useServiceQuery(serviceUrl: string) {
|
|
return useQuery({
|
|
queryKey: RQKEY(serviceUrl),
|
|
queryFn: async () => {
|
|
/*
|
|
* Unauthenticated throwaway client pointed at the candidate service -
|
|
* describeServer is a public endpoint on the target PDS/entryway.
|
|
*/
|
|
const client = createLexClient({service: serviceUrl})
|
|
return await client.call(com.atproto.server.describeServer)
|
|
},
|
|
enabled: isValidUrl(serviceUrl),
|
|
})
|
|
}
|
|
|
|
function isValidUrl(url: string) {
|
|
try {
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
const urlp = new URL(url)
|
|
return true
|
|
} catch {
|
|
return false
|
|
}
|
|
}
|