[SDK] Remove @atproto/api (#11386)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import {XRPCError} from '@atproto/api'
|
||||
import {LexError, XrpcResponseError} from '@atproto/lex'
|
||||
import {beforeAll, describe, expect, it} from '@jest/globals'
|
||||
import {i18n} from '@lingui/core'
|
||||
@@ -72,20 +71,10 @@ describe('cleanError', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('matches the upstream-failure branch on a legacy XRPC error', () => {
|
||||
const e = new XRPCError(502)
|
||||
expect(cleanError(e)).toBe(
|
||||
'The server appears to be experiencing issues. Please try again in a few moments.',
|
||||
)
|
||||
})
|
||||
|
||||
it('matches NotEnoughResources on both error shapes', () => {
|
||||
it('matches NotEnoughResources', () => {
|
||||
expect(cleanError(xrpcStatusError(503))).toBe(
|
||||
'The server appears to be experiencing issues. Please try again in a few moments.',
|
||||
)
|
||||
expect(cleanError(new XRPCError(503))).toBe(
|
||||
'The server appears to be experiencing issues. Please try again in a few moments.',
|
||||
)
|
||||
})
|
||||
|
||||
it('matches the app-password branch on a lex error message', () => {
|
||||
@@ -105,7 +94,8 @@ describe('cleanError', () => {
|
||||
it('surfaces the authentication-required code of a lex error', () => {
|
||||
/*
|
||||
* The lex client derives `AuthenticationRequired` from a 401 with no XRPC
|
||||
* payload, where `@atproto/api` used the spaced "Authentication Required".
|
||||
* payload, where the pre-migration client used the spaced
|
||||
* "Authentication Required".
|
||||
* Neither is special-cased in `cleanError`, so what matters is that the
|
||||
* class- and code-prefixed stringification does not reach the user.
|
||||
*/
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import {XRPCError} from '@atproto/api'
|
||||
import {LexError} from '@atproto/lex'
|
||||
import {t} from '@lingui/core/macro'
|
||||
|
||||
import {isXrpcError} from '#/lib/xrpc-error'
|
||||
|
||||
/**
|
||||
* The text to show the user when no special case applies.
|
||||
*
|
||||
@@ -39,7 +40,7 @@ export function cleanError(e: unknown): string {
|
||||
return t`Unable to connect. Please check your internet connection and try again.`
|
||||
}
|
||||
/*
|
||||
* `@atproto/api` names these with spaces ("Upstream Failure"); lexicon error
|
||||
* The legacy client named these with spaces ("Upstream Failure"); lexicon error
|
||||
* codes are space-free ("UpstreamFailure"). Match both while the app throws
|
||||
* both shapes.
|
||||
*/
|
||||
@@ -97,9 +98,20 @@ export function isNetworkError(e: unknown) {
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* The PDS answers an app-password-scope rejection with the lexicon code
|
||||
* `InvalidToken` and a message of 'Bad token scope' or 'Bad token method'
|
||||
* (pipethrough), so the typed path matches the code AND the message. The
|
||||
* pre-migration check compared against 'TokenInvalid', which the PDS never
|
||||
* sends - the string fallback was doing all the work.
|
||||
*/
|
||||
export function isErrorMaybeAppPasswordPermissions(e: unknown) {
|
||||
if (e instanceof XRPCError && e.error === 'TokenInvalid') {
|
||||
return true
|
||||
if (isXrpcError(e)) {
|
||||
return (
|
||||
e.error === 'InvalidToken' &&
|
||||
(e.message.includes('Bad token scope') ||
|
||||
e.message.includes('Bad token method'))
|
||||
)
|
||||
}
|
||||
const str = String(e)
|
||||
return str.includes('Bad token scope') || str.includes('Bad token method')
|
||||
@@ -124,5 +136,5 @@ export function isRetryableHttpStatus(status: number) {
|
||||
}
|
||||
|
||||
export function shouldRetryError(e: unknown) {
|
||||
return e instanceof XRPCError && isRetryableHttpStatus(e.status)
|
||||
return isXrpcError(e) && e.shouldRetry()
|
||||
}
|
||||
|
||||
@@ -30,26 +30,3 @@ export function richTextToString(rt: RichText, loose: boolean): string {
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Widens facets typed by the legacy `@atproto/api` codegen into the shape the
|
||||
* SDK's `RichText` accepts.
|
||||
*
|
||||
* The two are the same lexicon and identical at runtime; they differ only in
|
||||
* that the SDK brands `did`/`uri` as template literal types, which makes the
|
||||
* legacy `string` versions unassignable. Call this where facets read off an
|
||||
* `@atproto/api` view type are handed to `new RichText(...)`.
|
||||
*
|
||||
* Transitional: it goes away once the view types come from the SDK too.
|
||||
*/
|
||||
export function asSdkFacets(
|
||||
facets: {index: {byteStart: number; byteEnd: number}; features: unknown[]}[],
|
||||
): app.bsky.richtext.facet.Main[]
|
||||
export function asSdkFacets(
|
||||
facets:
|
||||
| {index: {byteStart: number; byteEnd: number}; features: unknown[]}[]
|
||||
| undefined,
|
||||
): app.bsky.richtext.facet.Main[] | undefined
|
||||
export function asSdkFacets(facets: unknown) {
|
||||
return facets as app.bsky.richtext.facet.Main[] | undefined
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {AtUri} from '@atproto/api'
|
||||
import {AtUri} from '@atproto/syntax'
|
||||
|
||||
import type * as bsky from '#/types/bsky'
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {AtUri} from '@atproto/api'
|
||||
import {AtUri} from '@atproto/syntax'
|
||||
import {parse} from 'psl'
|
||||
import TLDs from 'tlds'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user