@atproto/lex-client 0.1.5 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/agent.d.ts +1 -1
  3. package/dist/agent.d.ts.map +1 -1
  4. package/dist/agent.js.map +1 -1
  5. package/dist/client.d.ts +42 -21
  6. package/dist/client.d.ts.map +1 -1
  7. package/dist/client.js +97 -16
  8. package/dist/client.js.map +1 -1
  9. package/dist/errors.d.ts +6 -4
  10. package/dist/errors.d.ts.map +1 -1
  11. package/dist/errors.js +3 -3
  12. package/dist/errors.js.map +1 -1
  13. package/dist/response.d.ts +3 -2
  14. package/dist/response.d.ts.map +1 -1
  15. package/dist/response.js +2 -1
  16. package/dist/response.js.map +1 -1
  17. package/dist/types.d.ts +1 -1
  18. package/dist/types.d.ts.map +1 -1
  19. package/dist/types.js.map +1 -1
  20. package/dist/util.d.ts +6 -2
  21. package/dist/util.d.ts.map +1 -1
  22. package/dist/util.js +25 -0
  23. package/dist/util.js.map +1 -1
  24. package/dist/write-operation-builder.d.ts +3 -2
  25. package/dist/write-operation-builder.d.ts.map +1 -1
  26. package/dist/write-operation-builder.js +2 -2
  27. package/dist/write-operation-builder.js.map +1 -1
  28. package/dist/xrpc.d.ts +8 -6
  29. package/dist/xrpc.d.ts.map +1 -1
  30. package/dist/xrpc.js +1 -1
  31. package/dist/xrpc.js.map +1 -1
  32. package/package.json +11 -14
  33. package/src/agent.test.ts +0 -216
  34. package/src/agent.ts +0 -186
  35. package/src/client.ts +0 -1086
  36. package/src/errors.test.ts +0 -626
  37. package/src/errors.ts +0 -570
  38. package/src/index.ts +0 -6
  39. package/src/lexicons/com/atproto/repo/applyWrites.defs.ts +0 -201
  40. package/src/lexicons/com/atproto/repo/applyWrites.ts +0 -6
  41. package/src/lexicons/com/atproto/repo/createRecord.defs.ts +0 -58
  42. package/src/lexicons/com/atproto/repo/createRecord.ts +0 -6
  43. package/src/lexicons/com/atproto/repo/defs.defs.ts +0 -28
  44. package/src/lexicons/com/atproto/repo/defs.ts +0 -5
  45. package/src/lexicons/com/atproto/repo/deleteRecord.defs.ts +0 -52
  46. package/src/lexicons/com/atproto/repo/deleteRecord.ts +0 -6
  47. package/src/lexicons/com/atproto/repo/getRecord.defs.ts +0 -37
  48. package/src/lexicons/com/atproto/repo/getRecord.ts +0 -6
  49. package/src/lexicons/com/atproto/repo/listRecords.defs.ts +0 -65
  50. package/src/lexicons/com/atproto/repo/listRecords.ts +0 -6
  51. package/src/lexicons/com/atproto/repo/putRecord.defs.ts +0 -59
  52. package/src/lexicons/com/atproto/repo/putRecord.ts +0 -6
  53. package/src/lexicons/com/atproto/repo/uploadBlob.defs.ts +0 -35
  54. package/src/lexicons/com/atproto/repo/uploadBlob.ts +0 -6
  55. package/src/lexicons/com/atproto/repo.ts +0 -12
  56. package/src/lexicons/com/atproto/sync/getBlob.defs.ts +0 -37
  57. package/src/lexicons/com/atproto/sync/getBlob.ts +0 -6
  58. package/src/lexicons/com/atproto/sync.ts +0 -5
  59. package/src/lexicons/com/atproto.ts +0 -6
  60. package/src/lexicons/com.ts +0 -5
  61. package/src/lexicons/index.ts +0 -5
  62. package/src/response.bench.ts +0 -113
  63. package/src/response.ts +0 -366
  64. package/src/types.ts +0 -71
  65. package/src/util.test.ts +0 -333
  66. package/src/util.ts +0 -182
  67. package/src/write-operation-builder.ts +0 -110
  68. package/src/www-authenticate.test.ts +0 -227
  69. package/src/www-authenticate.ts +0 -101
  70. package/src/xrpc.test.ts +0 -1450
  71. package/src/xrpc.ts +0 -446
  72. package/tsconfig.build.json +0 -12
  73. package/tsconfig.json +0 -7
  74. package/tsconfig.tests.json +0 -8
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,EAaL,SAAS,EACT,KAAK,EACL,YAAY,EAEZ,OAAO,GACR,MAAM,qBAAqB,CAAA;A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,CAAC,IAAI,IAAI,mBAAmB,CAAC,MAAM,CAAC,CAAA;QACxD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;QAC5D,OAAO,QAAQ,CAAC,IAAI,CAAA;IACtB,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,IAAI,CACR,EAAW,EACX,OAAqB;QAErB,MAAM,MAAM,GAAG,OAAO,CAAC,EAAE,CAAC,CAAA;QAC1B,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;QAE9D,MAAM,OAAO,GAA2B,EAAE,CAAA;QAC1C,MAAM,OAAO,GAAa,EAAE,CAAA;QAE5B,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAClC,MAAM,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;YAChD,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;gBACnB,OAAO,CAAC,IAAI,CAAC,EAAE,GAAG,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAA;YAClD,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;YAC5B,CAAC;QACH,CAAC;QAED,OAAO,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAA;IACtC,CAAC;CACF","sourcesContent":["import { LexMap, LexValue, TypedLexMap } from '@atproto/lex-data'\nimport {\n AtIdentifierString,\n AtUriString,\n CidString,\n DidString,\n Infer,\n InferMethodInputBody,\n InferMethodOutputBody,\n InferRecordKey,\n LexiconRecordKey,\n Main,\n NsidString,\n Params,\n Procedure,\n Query,\n RecordSchema,\n Restricted,\n getMain,\n} from '@atproto/lex-schema'\nimport { Agent, AgentOptions, buildAgent } from './agent.js'\nimport { XrpcFailure } from './errors.js'\n// @NOTE We could use import { com } from \"./lexicons/index.js\" here, but some\n// consumers might not know how to properly tree-shake that, so we import only\n// the needed lexicon schemas directly.\nimport applyWrites from './lexicons/com/atproto/repo/applyWrites.js'\nimport createRecord from './lexicons/com/atproto/repo/createRecord.js'\nimport deleteRecord from './lexicons/com/atproto/repo/deleteRecord.js'\nimport getRecord from './lexicons/com/atproto/repo/getRecord.js'\nimport listRecords from './lexicons/com/atproto/repo/listRecords.js'\nimport putRecord from './lexicons/com/atproto/repo/putRecord.js'\nimport uploadBlob from './lexicons/com/atproto/repo/uploadBlob.js'\nimport getBlob from './lexicons/com/atproto/sync/getBlob.js'\nimport {\n XrpcResponse,\n XrpcResponseBody,\n XrpcResponseOptions,\n} from './response.js'\nimport { BinaryBodyInit, Service } from './types.js'\nimport {\n RecordKeyOptions,\n XrpcRequestHeadersOptions,\n applyDefaults,\n buildXrpcRequestHeaders,\n getDefaultRecordKey,\n getLiteralRecordKey,\n} from './util.js'\nimport {\n WriteOperation,\n WriteOperationCreateOptions,\n WriteOperationDeleteOptions,\n WriteOperationHelper,\n WriteOperationUpdateOptions,\n WriteOperationsFactory,\n} from './write-operation-builder.js'\nimport {\n XrpcOptions,\n XrpcRequestParams,\n XrpcRequestProcessingOptions,\n xrpc,\n xrpcSafe,\n} from './xrpc.js'\n\nexport {\n type AtIdentifierString,\n type CidString,\n type DidString,\n type Infer,\n type InferMethodInputBody,\n type InferMethodOutputBody,\n type InferRecordKey,\n type LexMap,\n type LexValue,\n type LexiconRecordKey,\n type Main,\n type NsidString,\n type Params,\n Procedure,\n Query,\n RecordSchema,\n type Restricted,\n type TypedLexMap,\n type WriteOperation,\n type WriteOperationCreateOptions,\n type WriteOperationDeleteOptions,\n WriteOperationHelper,\n type WriteOperationUpdateOptions,\n type WriteOperationsFactory,\n}\n\n/**\n * Configuration options for creating a {@link Client}.\n *\n * @property {@link ClientOptions.labelers} - An iterable of labeler DIDs to include in requests. These will be combined with any global app labelers configured via {@link Client.configure}.\n * @property {@link ClientOptions.service} - An optional service identifier (DID or URL) for routing requests with service proxying.\n * @property {@link ClientOptions.headers} - Custom headers to include in all requests made by this client instance.\n * @property {@link ClientOptions.validateRequest} - If true, validates request bodies against their lexicon schemas before sending. Defaults to false for performance.\n * @property {@link ClientOptions.validateResponse} - If false, skips validation of response bodies against their lexicon schemas. Defaults to true to catch errors, but can be disabled for performance if you trust the server responses. Note that defaults will not be applied if validation is disabled, which can cause typing inconsistencies, so use with caution.\n * @property {@link ClientOptions.strictResponseProcessing} - If false, relaxes certain validation rules during response processing (e.g., allowing floats, deeper nesting, etc.). Defaults to true for strict compliance with {@link https://atproto.com/specs/data-model lexicon data model}, but can be disabled to handle non-compliant responses.\n *\n * @see {@link XrpcRequestHeadersOptions}\n * @see {@link XrpcRequestProcessingOptions}\n * @see {@link XrpcResponseOptions}\n *\n * @example\n * ```typescript\n * const options: ClientOptions = {\n * labelers: ['did:plc:labeler1'],\n * service: 'did:web:api.bsky.app#bsky_appview',\n * headers: { 'X-Custom-Header': 'value' },\n * validateRequest: false,\n * validateResponse: true,\n * strictResponseProcessing: false,\n * }\n * ```\n */\nexport type ClientOptions = XrpcRequestHeadersOptions &\n Pick<XrpcRequestProcessingOptions, 'validateRequest'> &\n XrpcResponseOptions\n\nexport type ActionOptions = {\n /** AbortSignal to cancel the request. */\n signal?: AbortSignal\n}\n\n/**\n * A composable action that can be invoked via {@link Client.call}.\n *\n * Actions provide a way to define custom operations that integrate with the\n * Client's call interface, enabling type-safe, reusable business logic.\n *\n * @typeParam I - The input type for the action\n * @typeParam O - The output type for the action\n *\n * @example\n * ```typescript\n * const myAction: Action<{ userId: string }, { profile: Profile }> = async (client, input, options) => {\n * const response = await client.xrpc(someMethod, { params: { actor: input.userId }, ...options })\n * return { profile: response.body }\n * }\n * ```\n */\nexport type Action<I = any, O = any> = (\n client: Client,\n input: I,\n options: ActionOptions,\n) => O | Promise<O>\n\n/**\n * Extracts the input type from an {@link Action}.\n * @typeParam A - The Action type to extract from\n */\nexport type InferActionInput<A extends Action> =\n A extends Action<infer I, any> ? I : never\n\n/**\n * Extracts the output type from an {@link Action}.\n * @typeParam A - The Action type to extract from\n */\nexport type InferActionOutput<A extends Action> =\n A extends Action<any, infer O> ? O : never\n\n/**\n * Options for creating a record in an AT Protocol repository.\n *\n * @see {@link Client.createRecord}\n */\nexport type CreateRecordOptions = Omit<\n XrpcOptions<typeof createRecord>,\n 'body'\n> & {\n /** Repository identifier (DID or handle). Defaults to authenticated user's DID. */\n repo?: AtIdentifierString\n /** Compare-and-swap on the repo commit. If specified, must match current commit. */\n swapCommit?: string\n /**\n * Whether the PDS should validate the record against its lexicon schema.\n * When `true`, the PDS is asked to explicitly validate the record. When\n * `false`, the PDS is asked to explicitly skip validation. When `undefined`\n * (default), the PDS decides -- typically validating only collections whose\n * schemas it knows. This is server-side validation; for client-side\n * validation before sending, use {@link XrpcRequestProcessingOptions.validateRequest}.\n */\n validate?: boolean\n}\n\n/**\n * Options for deleting a record from an AT Protocol repository.\n *\n * @see {@link Client.deleteRecord}\n */\nexport type DeleteRecordOptions = Omit<\n XrpcOptions<typeof deleteRecord>,\n 'body'\n> & {\n /** Repository identifier (DID or handle). Defaults to authenticated user's DID. */\n repo?: AtIdentifierString\n /** Compare-and-swap on the repo commit. If specified, must match current commit. */\n swapCommit?: string\n /** Compare-and-swap on the record CID. If specified, must match current record. */\n swapRecord?: string\n}\n\n/**\n * Options for retrieving a record from an AT Protocol repository.\n *\n * @see {@link Client.getRecord}\n */\nexport type GetRecordOptions = Omit<XrpcOptions<typeof getRecord>, 'params'> & {\n /** Repository identifier (DID or handle). Defaults to authenticated user's DID. */\n repo?: AtIdentifierString\n}\n\n/**\n * Options for creating or updating a record in an AT Protocol repository.\n *\n * @see {@link Client.putRecord}\n */\nexport type PutRecordOptions = Omit<XrpcOptions<typeof putRecord>, 'body'> & {\n /** Repository identifier (DID or handle). Defaults to authenticated user's DID. */\n repo?: AtIdentifierString\n /** Compare-and-swap on the repo commit. If specified, must match current commit. */\n swapCommit?: string\n /** Compare-and-swap on the record CID. If specified, must match current record. */\n swapRecord?: string\n /**\n * Whether the PDS should validate the record against its lexicon schema.\n * When `true`, the PDS is asked to explicitly validate the record. When\n * `false`, the PDS is asked to explicitly skip validation. When `undefined`\n * (default), the PDS decides — typically validating only collections whose\n * schemas it knows. This is server-side validation; for client-side\n * validation before sending, use {@link XrpcRequestProcessingOptions.validateRequest}.\n */\n validate?: boolean\n}\n\n/**\n * Options for listing records in an AT Protocol repository collection.\n *\n * @see {@link Client.listRecords}\n */\nexport type ListRecordsOptions = Omit<\n XrpcOptions<typeof listRecords>,\n 'params'\n> & {\n /** Repository identifier (DID or handle). Defaults to authenticated user's DID. */\n repo?: AtIdentifierString\n /** Maximum number of records to return. */\n limit?: number\n /** Pagination cursor from a previous response. */\n cursor?: string\n /** If true, returns records in reverse chronological order. */\n reverse?: boolean\n}\n\n/**\n * Options for applying a batch of writes (create/update/delete) to an AT Protocol repository.\n *\n * @see {@link Client.applyWrites}\n */\nexport type ApplyWritesOptions = Omit<\n XrpcOptions<typeof applyWrites>,\n 'body'\n> & {\n /** Repository identifier (DID or handle). Defaults to authenticated user's DID. */\n repo?: AtIdentifierString\n /**\n * Whether the PDS should validate the records against their lexicon schemas.\n * When `true`, the PDS is asked to explicitly validate every record. When\n * `false`, the PDS is asked to explicitly skip validation. When `undefined`\n * (default), the PDS decides — typically validating only collections whose\n * schemas it knows.\n */\n validate?: boolean\n /** Compare-and-swap on the repo commit. If specified, must match current commit. */\n swapCommit?: CidString\n}\n\nexport type UploadBlobOptions = Omit<XrpcOptions<typeof uploadBlob>, 'body'>\n\nexport type GetBlobOptions = Omit<XrpcOptions<typeof getBlob>, 'params'>\n\n/**\n * Type-safe options for {@link Client.create}, combining record options with key requirements.\n * @typeParam T - The record schema type\n * @see {@link CreateRecordOptions}\n */\nexport type CreateOptions<T extends RecordSchema> = CreateRecordOptions &\n RecordKeyOptions<T, 'tid' | 'any'>\n\n/**\n * Output type for record creation operations.\n * Contains the URI and CID of the newly created record.\n */\nexport type CreateOutput = InferMethodOutputBody<\n typeof createRecord,\n Uint8Array\n>\n\n/**\n * Type-safe options for {@link Client.delete}, combining delete options with key requirements.\n * @typeParam T - The record schema type\n */\nexport type DeleteOptions<T extends RecordSchema> = DeleteRecordOptions &\n RecordKeyOptions<T>\n\n/**\n * Output type for record deletion operations.\n */\nexport type DeleteOutput = InferMethodOutputBody<\n typeof deleteRecord,\n Uint8Array\n>\n\n/**\n * Type-safe options for {@link Client.get}, combining get options with key requirements.\n * @typeParam T - The record schema type\n */\nexport type GetOptions<T extends RecordSchema> = GetRecordOptions &\n RecordKeyOptions<T>\n\n/**\n * Output type for record retrieval operations.\n * Contains the record value validated against the schema type.\n * @typeParam T - The record schema type\n */\nexport type GetOutput<T extends RecordSchema> = Omit<\n InferMethodOutputBody<typeof getRecord, Uint8Array>,\n 'value'\n> & { value: Infer<T> }\n\n/**\n * Type-safe options for {@link Client.put}, combining put options with key requirements.\n * @typeParam T - The record schema type\n */\nexport type PutOptions<T extends RecordSchema> = PutRecordOptions &\n RecordKeyOptions<T>\n\n/**\n * Output type for record put (create/update) operations.\n * Contains the URI and CID of the record.\n */\nexport type PutOutput = InferMethodOutputBody<typeof putRecord, Uint8Array>\n\n/**\n * Options for {@link Client.list} operations.\n */\nexport type ListOptions = ListRecordsOptions\n\n/**\n * Output type for record listing operations.\n * Contains validated records and any invalid records that failed schema validation.\n * @typeParam T - The record schema type\n */\nexport type ListOutput<T extends RecordSchema> = InferMethodOutputBody<\n typeof listRecords,\n Uint8Array\n> & {\n /** Records that successfully validated against the schema. */\n records: ListRecord<Infer<T>>[]\n // @NOTE Because the schema uses \"type\": \"unknown\" instead of an open union,\n // we have to use LexMap instead of Unknown$TypedObject here, which is\n // unfortunate.\n /** Records that failed schema validation. */\n invalid: LexMap[]\n}\n\n/**\n * A record from a list operation with its value typed to the schema.\n * @typeParam Value - The validated record value type\n */\nexport type ListRecord<Value extends LexMap> = {\n uri: AtUriString\n cid: CidString\n value: Value\n}\n\n/**\n * The Client class is the primary interface for interacting with AT Protocol\n * services. It provides type-safe methods for XRPC calls, record operations,\n * and blob handling.\n *\n * @example\n * ```typescript\n * import { Client } from '@atproto/lex'\n * import { app } from '#/lexicons\n *\n * const client = new Client(oauthSession)\n *\n * const response = await client.xrpc(app.bsky.feed.getTimeline.main, {\n * params: { limit: 50 }\n * })\n * ```\n */\nexport class Client implements Agent {\n static appLabelers: readonly DidString[] = []\n\n /**\n * Configures the Client (or its sub classes) globally.\n */\n static configure(opts: { appLabelers?: Iterable<DidString> }) {\n if (opts.appLabelers) this.appLabelers = [...opts.appLabelers]\n }\n\n /** The underlying agent used for making requests. */\n public readonly agent: Agent\n\n /** Custom headers included in all requests. */\n public readonly headers: Headers\n\n /** Optional service identifier for routing requests. */\n public readonly service?: Service\n\n /** Set of labeler DIDs specific to this client instance. */\n public readonly labelers: Set<DidString>\n\n public readonly xrpcDefaults: {\n readonly validateRequest: boolean\n readonly validateResponse: boolean\n readonly strictResponseProcessing: boolean\n }\n\n constructor(agent: Agent | AgentOptions, options: ClientOptions = {}) {\n this.agent = buildAgent(agent)\n this.service = options.service\n this.labelers = new Set(options.labelers)\n this.headers = new Headers(options.headers)\n this.xrpcDefaults = Object.freeze({\n validateRequest: options.validateRequest ?? false,\n validateResponse: options.validateResponse ?? true,\n strictResponseProcessing: options.strictResponseProcessing ?? true,\n })\n }\n\n /**\n * The DID of the authenticated user, or `undefined` if not authenticated.\n */\n get did(): DidString | undefined {\n return this.agent.did\n }\n\n /**\n * The DID of the authenticated user.\n * @throws {Error} if not authenticated\n */\n get assertDid(): DidString {\n this.assertAuthenticated()\n return this.did\n }\n\n /**\n * Asserts that the client is authenticated.\n * Use as a type guard when you need to ensure authentication.\n *\n * @throws {Error} if not authenticated\n *\n * @example\n * ```typescript\n * client.assertAuthenticated()\n * // TypeScript now knows client.did is defined\n * console.log(client.did)\n * ```\n */\n public assertAuthenticated(): asserts this is { did: DidString } {\n if (!this.did) throw new Error('Client is not authenticated')\n }\n\n /**\n * Replaces all labelers with the given set.\n * @param labelers - Iterable of labeler DIDs\n */\n public setLabelers(labelers: Iterable<DidString> = []) {\n this.clearLabelers()\n this.addLabelers(labelers)\n }\n\n /**\n * Adds labelers to the current set.\n * @param labelers - Iterable of labeler DIDs to add\n */\n public addLabelers(labelers: Iterable<DidString>) {\n for (const labeler of labelers) this.labelers.add(labeler)\n }\n\n /**\n * Removes all labelers from this client instance.\n */\n public clearLabelers() {\n this.labelers.clear()\n }\n\n /**\n * {@link Agent}'s {@link Agent.fetchHandler} implementation, which adds\n * labelers and service proxying headers. This method allow a {@link Client}\n * instance to be used directly as an {@link Agent} for another\n * {@link Client}, enabling composition of headers (labelers, proxying, etc.).\n *\n * @param path - The request path\n * @param init - Request initialization options\n */\n public fetchHandler(\n path: `/${string}`,\n init: RequestInit,\n ): Promise<Response> {\n const headers = buildXrpcRequestHeaders({\n headers: init.headers,\n service: this.service,\n labelers: [\n ...(this.constructor as typeof Client).appLabelers.map(\n (l) => `${l};redact` as const,\n ),\n ...this.labelers,\n ],\n })\n\n // Incoming headers take precedence\n for (const [key, value] of this.headers) {\n if (!headers.has(key)) headers.set(key, value)\n }\n\n // @NOTE The agent here could be another Client instance.\n return this.agent.fetchHandler(path, { ...init, headers })\n }\n\n /**\n * Makes an XRPC request. Throws on failure.\n *\n * @param ns - The lexicon method definition (e.g., `app.bsky.feed.getTimeline`)\n * @param options - Request options including params and body\n * @returns The successful XRPC response\n * @throws {XrpcFailure} when the request fails or returns an error\n *\n * @example Query with parameters\n * ```typescript\n * const response = await client.xrpc(app.bsky.feed.getTimeline, {\n * params: { limit: 50, cursor: 'abc123' }\n * })\n * console.log(response.body.feed)\n * ```\n *\n * @example Procedure with body\n * ```typescript\n * const response = await client.xrpc(com.atproto.repo.createRecord, {\n * body: {\n * repo: client.assertDid,\n * collection: 'app.bsky.feed.post',\n * record: { text: 'Hello!', createdAt: new Date().toISOString() }\n * }\n * })\n * ```\n *\n * @see {@link xrpcSafe} for a non-throwing variant\n */\n async xrpc<const M extends Query | Procedure>(\n ns: NonNullable<unknown> extends XrpcOptions<M>\n ? Main<M>\n : Restricted<'This XRPC method requires an \"options\" argument'>,\n ): Promise<XrpcResponse<M>>\n async xrpc<const M extends Query | Procedure>(\n ns: Main<M>,\n options: XrpcOptions<M>,\n ): Promise<XrpcResponse<M>>\n async xrpc<const M extends Query | Procedure>(\n ns: Main<M>,\n options: XrpcOptions<M> = {} as XrpcOptions<M>,\n ): Promise<XrpcResponse<M>> {\n return xrpc(this, ns, applyDefaults(options, this.xrpcDefaults))\n }\n\n /**\n * Makes an XRPC request without throwing on failure.\n * Returns either a successful response or a failure object.\n *\n * @param ns - The lexicon method definition\n * @param options - Request options\n * @returns Either an XrpcResponse on success or XrpcFailure on failure\n *\n * @example\n * ```typescript\n * const result = await client.xrpcSafe(app.bsky.actor.getProfile.main, {\n * params: { actor: 'alice.bsky.social' }\n * })\n *\n * if (result.success) {\n * console.log(result.body.displayName)\n * } else {\n * console.error('Failed:', result.error)\n * }\n * ```\n *\n * @see {@link xrpc} for a throwing variant\n */\n async xrpcSafe<const M extends Query | Procedure>(\n ns: NonNullable<unknown> extends XrpcOptions<M>\n ? Main<M>\n : Restricted<'This XRPC method requires an \"options\" argument'>,\n ): Promise<XrpcResponse<M> | XrpcFailure<M>>\n async xrpcSafe<const M extends Query | Procedure>(\n ns: Main<M>,\n options: XrpcOptions<M>,\n ): Promise<XrpcResponse<M> | XrpcFailure<M>>\n async xrpcSafe<const M extends Query | Procedure>(\n ns: Main<M>,\n options: XrpcOptions<M> = {} as XrpcOptions<M>,\n ): Promise<XrpcResponse<M> | XrpcFailure<M>> {\n return xrpcSafe(this, ns, applyDefaults(options, this.xrpcDefaults))\n }\n\n /**\n * Creates a new record in an AT Protocol repository.\n *\n * @param record - The record to create, must include an {@link NsidString} `$type`\n * @param rkey - Optional record key; if omitted, server generates a TID\n * @param options - Create options including repo, swapCommit, validate\n * @returns The XRPC response containing the created record's URI and CID\n *\n * @example\n * ```typescript\n * const response = await client.createRecord(\n * { $type: 'app.bsky.feed.post', text: 'Hello!', createdAt: new Date().toISOString() },\n * undefined, // Let server generate rkey\n * { validate: true }\n * )\n * console.log(response.body.uri)\n * ```\n *\n * @see {@link create} for a higher-level typed alternative\n */\n public async createRecord(\n record: TypedLexMap<NsidString>,\n rkey?: string,\n options?: CreateRecordOptions,\n ) {\n return this.xrpc(createRecord, {\n ...options,\n body: {\n repo: options?.repo ?? this.assertDid,\n collection: record.$type,\n record,\n rkey,\n validate: options?.validate,\n swapCommit: options?.swapCommit,\n },\n })\n }\n\n /**\n * Deletes a record from an AT Protocol repository.\n *\n * @param collection - The collection NSID\n * @param rkey - The record key\n * @param options - Delete options including repo, swapCommit, swapRecord\n *\n * @see {@link delete} for a higher-level typed alternative\n */\n async deleteRecord(\n collection: NsidString,\n rkey: string,\n options?: DeleteRecordOptions,\n ) {\n return this.xrpc(deleteRecord, {\n ...options,\n body: {\n repo: options?.repo ?? this.assertDid,\n collection,\n rkey,\n swapCommit: options?.swapCommit,\n swapRecord: options?.swapRecord,\n },\n })\n }\n\n /**\n * Retrieves a record from an AT Protocol repository.\n *\n * @param collection - The collection NSID\n * @param rkey - The record key\n * @param options - Get options including repo\n *\n * @see {@link get} for a higher-level typed alternative\n */\n public async getRecord(\n collection: NsidString,\n rkey: string,\n options?: GetRecordOptions,\n ) {\n return this.xrpc(getRecord, {\n ...options,\n params: {\n repo: options?.repo ?? this.assertDid,\n collection,\n rkey,\n },\n })\n }\n\n /**\n * Creates or updates a record in a repository.\n *\n * @param record - The record to put, must include an {@link NsidString} `$type`\n * @param rkey - The record key\n * @param options - Put options including repo, swapCommit, swapRecord, validate\n *\n * @see {@link put} for a higher-level typed alternative\n */\n async putRecord(\n record: TypedLexMap<NsidString>,\n rkey: string,\n options?: PutRecordOptions,\n ) {\n return this.xrpc(putRecord, {\n ...options,\n body: {\n repo: options?.repo ?? this.assertDid,\n collection: record.$type,\n rkey,\n record,\n validate: options?.validate,\n swapCommit: options?.swapCommit,\n swapRecord: options?.swapRecord,\n },\n })\n }\n\n /**\n * Lists records in a collection.\n *\n * @param nsid - The collection NSID\n * @param options - List options including repo, limit, cursor, reverse\n *\n * @see {@link list} for a higher-level typed alternative\n */\n async listRecords(nsid: NsidString, options?: ListRecordsOptions) {\n return this.xrpc(listRecords, {\n ...options,\n params: {\n repo: options?.repo ?? this.assertDid,\n collection: nsid,\n cursor: options?.cursor,\n limit: options?.limit,\n reverse: options?.reverse,\n },\n })\n }\n\n /**\n * Performs an atomic batch of create, update, and delete operations on records in a repository.\n *\n * @param builder - A function that receives an {@link ApplyWritesOperations} instance to build the operations\n * @param options - ApplyWrites options including repo, validate, swapCommit\n * @returns The XRPC response from the applyWrites call\n *\n * @example\n * ```typescript\n * const response = await client.applyWrites((op) => [\n * op.create(app.bsky.feed.post, { text: 'Hello!' }),\n * op.update(app.bsky.feed.post, { text: 'Updated text' }, { rkey: 'post123' }),\n * op.delete(app.bsky.feed.post, 'post456'),\n * op.update(app.bsky.actor.profile, { displayName: 'Alice' }),\n * ], {\n * validate: true,\n * })\n *\n * for (const result of response.body.results) {\n * console.log(result.uri)\n * }\n * ```\n */\n async applyWrites(\n factory: WriteOperationsFactory,\n options?: ApplyWritesOptions,\n ) {\n return this.xrpc(applyWrites, {\n ...options,\n body: {\n repo: options?.repo ?? this.assertDid,\n writes: WriteOperationHelper.build(factory),\n validate: options?.validate,\n swapCommit: options?.swapCommit,\n },\n })\n }\n\n /**\n * Uploads a blob to an AT Protocol repository.\n *\n * @param body - The blob data (Uint8Array, ReadableStream, Blob, etc.)\n * @param options - Upload options including encoding hint\n * @returns Response containing the blob reference\n *\n * @example\n * ```typescript\n * const imageData = await fetch('image.png').then(r => r.arrayBuffer())\n * const response = await client.uploadBlob(new Uint8Array(imageData), {\n * encoding: 'image/png'\n * })\n * console.log(response.body.blob) // Use this ref in records\n * ```\n */\n async uploadBlob(body: BinaryBodyInit, options?: UploadBlobOptions) {\n return this.xrpc(uploadBlob, { ...options, body })\n }\n\n /**\n * Retrieves a blob by DID and CID.\n *\n * @param did - The DID of the repository containing the blob\n * @param cid - The CID of the blob\n * @param options - Call options\n */\n async getBlob(did: DidString, cid: CidString, options?: GetBlobOptions) {\n return this.xrpc(getBlob, {\n ...options,\n params: { did, cid },\n })\n }\n\n /**\n * Universal call method for queries, procedures, and custom actions.\n * Automatically determines the call type based on the lexicon definition.\n *\n * @param ns - The lexicon method or action definition\n * @param arg - The input argument (params for queries, body for procedures, input for actions)\n * @param options - Call options\n * @returns The method response body or action output\n * @see {@link xrpc} if you need access to the full response object\n *\n * @example Query\n * ```typescript\n * const profile = await client.call(app.bsky.actor.getProfile.main, {\n * actor: 'alice.bsky.social'\n * })\n * ```\n *\n * @example Procedure\n * ```typescript\n * const result = await client.call(com.atproto.repo.createRecord.main, {\n * repo: did,\n * collection: 'app.bsky.feed.post',\n * record: { text: 'Hello!' }\n * })\n * ```\n */\n public async call<const T extends Query>(\n ns: NonNullable<unknown> extends XrpcRequestParams<T>\n ? Main<T>\n : Restricted<'This query type requires a \"params\" argument'>,\n ): Promise<XrpcResponseBody<T>>\n public async call<const T extends Procedure>(\n ns: undefined extends InferMethodInputBody<T, Uint8Array>\n ? Main<T>\n : Restricted<'This procedure type requires an \"input\" argument'>,\n ): Promise<XrpcResponseBody<T>>\n public async call<const T extends Action>(\n ns: void extends InferActionInput<T>\n ? Main<T>\n : Restricted<'This action type requires an \"input\" argument'>,\n ): Promise<InferActionOutput<T>>\n public async call<const T extends Action | Procedure | Query>(\n ns: Main<T>,\n arg: T extends Action\n ? InferActionInput<T>\n : T extends Procedure\n ? InferMethodInputBody<T, Uint8Array>\n : T extends Query\n ? XrpcRequestParams<T>\n : never,\n options?: T extends Action\n ? ActionOptions\n : T extends Procedure\n ? Omit<XrpcOptions<T>, 'body'>\n : T extends Query\n ? Omit<XrpcOptions<T>, 'params'>\n : never,\n ): Promise<\n T extends Action\n ? InferActionOutput<T>\n : T extends Procedure\n ? XrpcResponseBody<T>\n : T extends Query\n ? XrpcResponseBody<T>\n : never\n >\n public async call(\n ns: Main<Action> | Main<Procedure> | Main<Query>,\n arg?: LexValue | Params,\n options: ActionOptions = {},\n ): Promise<unknown> {\n const method = getMain(ns)\n\n if (typeof method === 'function') {\n return method(this, arg, options)\n }\n\n if (method instanceof Procedure) {\n const result = await this.xrpc(method, { ...options, body: arg as any })\n return result.body\n } else if (method instanceof Query) {\n const result = await this.xrpc(method, { ...options, params: arg as any })\n return result.body\n } else {\n throw new TypeError('Invalid lexicon')\n }\n }\n\n /**\n * Creates a new record with full type safety based on the schema.\n *\n * @param ns - The record schema definition\n * @param input - The record data (without `$type`, which is added automatically)\n * @param options - Create options including rkey (required for some record types)\n * @returns The create output including URI and CID\n *\n * @example Creating a post\n * ```typescript\n * const result = await client.create(app.bsky.feed.post.main, {\n * text: 'Hello, world!',\n * createdAt: new Date().toISOString()\n * })\n * console.log(result.uri)\n * ```\n *\n * @example Creating a record with explicit rkey\n * ```typescript\n * const result = await client.create(app.bsky.actor.profile.main, {\n * displayName: 'Alice'\n * }, { rkey: 'self' })\n * ```\n */\n public async create<const T extends RecordSchema>(\n ns: NonNullable<unknown> extends CreateOptions<T>\n ? Main<T>\n : Restricted<'This record type requires an \"options\" argument'>,\n input: Omit<Infer<T>, '$type'>,\n ): Promise<CreateOutput>\n public async create<const T extends RecordSchema>(\n ns: Main<T>,\n input: Omit<Infer<T>, '$type'>,\n options: CreateOptions<T>,\n ): Promise<CreateOutput>\n public async create<const T extends RecordSchema>(\n ns: Main<T>,\n input: Omit<Infer<T>, '$type'>,\n options: CreateOptions<T> = {} as CreateOptions<T>,\n ): Promise<CreateOutput> {\n const schema: T = getMain(ns)\n const record = schema.build(input) as TypedLexMap<NsidString>\n if (options?.validateRequest) schema.validate(record)\n const rkey = options.rkey ?? getDefaultRecordKey(schema)\n if (rkey !== undefined) schema.keySchema.assert(rkey)\n const response = await this.createRecord(record, rkey, options)\n return response.body\n }\n\n /**\n * Deletes a record with type-safe options.\n *\n * @param ns - The record schema definition\n * @param options - Delete options (rkey required for non-literal keys)\n * @returns The delete output\n */\n public async delete<const T extends RecordSchema>(\n ns: NonNullable<unknown> extends DeleteOptions<T>\n ? Main<T>\n : Restricted<'This record type requires an \"options\" argument'>,\n ): Promise<DeleteOutput>\n public async delete<const T extends RecordSchema>(\n ns: Main<T>,\n options?: DeleteOptions<T>,\n ): Promise<DeleteOutput>\n public async delete<const T extends RecordSchema>(\n ns: Main<T>,\n options: DeleteOptions<T> = {} as DeleteOptions<T>,\n ): Promise<DeleteOutput> {\n const schema = getMain(ns)\n const rkey = schema.keySchema.parse(\n options.rkey ?? getLiteralRecordKey(schema),\n )\n const response = await this.deleteRecord(schema.$type, rkey, options)\n return response.body\n }\n\n /**\n * Retrieves a record with type-safe validation.\n *\n * @param ns - The record schema definition\n * @param options - Get options (rkey required for non-literal keys)\n * @returns The record data validated against the schema\n *\n * @example\n * ```typescript\n * const profile = await client.get(app.bsky.actor.profile.main)\n * // profile.value is typed as app.bsky.actor.profile.Record\n * console.log(profile.value.displayName)\n * ```\n */\n public async get<const T extends RecordSchema>(\n ns: T['key'] extends `literal:${string}`\n ? Main<T>\n : Restricted<'This record type requires an \"options\" argument'>,\n ): Promise<GetOutput<T>>\n public async get<const T extends RecordSchema>(\n ns: Main<T>,\n options: GetOptions<T>,\n ): Promise<GetOutput<T>>\n public async get<const T extends RecordSchema>(\n ns: Main<T>,\n options: GetOptions<T> = {} as GetOptions<T>,\n ): Promise<GetOutput<T>> {\n const schema = getMain(ns)\n const rkey = schema.keySchema.parse(\n options.rkey ?? getLiteralRecordKey(schema),\n )\n const response = await this.getRecord(schema.$type, rkey, options)\n const value = schema.validate(response.body.value)\n return { ...response.body, value }\n }\n\n /**\n * Creates or updates a record with full type safety.\n *\n * @param ns - The record schema definition\n * @param input - The record data\n * @param options - Put options (rkey required for non-literal keys)\n * @returns The put output including URI and CID\n */\n public async put<const T extends RecordSchema>(\n ns: NonNullable<unknown> extends PutOptions<T>\n ? Main<T>\n : Restricted<'This record type requires an \"options\" argument'>,\n input: Omit<Infer<T>, '$type'>,\n ): Promise<PutOutput>\n public async put<const T extends RecordSchema>(\n ns: Main<T>,\n input: Omit<Infer<T>, '$type'>,\n options: PutOptions<T>,\n ): Promise<PutOutput>\n public async put<const T extends RecordSchema>(\n ns: Main<T>,\n input: Omit<Infer<T>, '$type'>,\n options: PutOptions<T> = {} as PutOptions<T>,\n ): Promise<PutOutput> {\n const schema: T = getMain(ns)\n const record = schema.build(input) as TypedLexMap<NsidString>\n if (options?.validateRequest) schema.validate(record)\n const rkey = options.rkey ?? getLiteralRecordKey(schema)\n const response = await this.putRecord(record, rkey, options)\n return response.body\n }\n\n /**\n * Lists records with type-safe validation and separation of valid/invalid records.\n *\n * @param ns - The record schema definition\n * @param options - List options\n * @returns Records split into valid (matching schema) and invalid arrays\n *\n * @example\n * ```typescript\n * const result = await client.list(app.bsky.feed.post.main, { limit: 100 })\n * console.log(`Found ${result.records.length} valid posts`)\n * console.log(`Found ${result.invalid.length} invalid records`)\n * ```\n */\n async list<const T extends RecordSchema>(\n ns: Main<T>,\n options?: ListOptions,\n ): Promise<ListOutput<T>> {\n const schema = getMain(ns)\n const { body } = await this.listRecords(schema.$type, options)\n\n const records: ListRecord<Infer<T>>[] = []\n const invalid: LexMap[] = []\n\n for (const record of body.records) {\n const parsed = schema.safeValidate(record.value)\n if (parsed.success) {\n records.push({ ...record, value: parsed.value })\n } else {\n invalid.push(record.value)\n }\n }\n\n return { ...body, records, invalid }\n }\n}\n"]}
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAE7E,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAEvC,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SAAM,CAAC;QACN,OAAO,EAAE,GAAG,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,CAAA;IACpC,CAAC;AACH,CAAC","sourcesContent":["import type { LexMap, LexValue, TypedLexMap } from '@atproto/lex-data'\nimport type {\n AtIdentifierString,\n AtUriString,\n CidString,\n DidString,\n Infer,\n InferMethodInputBody,\n InferMethodOutputBody,\n InferRecordKey,\n LexiconRecordKey,\n Main,\n NsidString,\n Params,\n Restricted,\n} from '@atproto/lex-schema'\nimport { Procedure, Query, RecordSchema, getMain } from '@atproto/lex-schema'\nimport type { Agent, AgentOptions } from './agent.js'\nimport { buildAgent } from './agent.js'\nimport type { XrpcFailure } from './errors.js'\nimport { XrpcError, XrpcResponseError } from './errors.js'\n// @NOTE We could use import { com } from \"./lexicons/index.js\" here, but some\n// consumers might not know how to properly tree-shake that, so we import only\n// the needed lexicon schemas directly.\nimport applyWrites from './lexicons/com/atproto/repo/applyWrites.js'\nimport createRecord from './lexicons/com/atproto/repo/createRecord.js'\nimport deleteRecord from './lexicons/com/atproto/repo/deleteRecord.js'\nimport getRecord from './lexicons/com/atproto/repo/getRecord.js'\nimport listRecords, {\n type Record as ListRecordsRecord,\n} from './lexicons/com/atproto/repo/listRecords.js'\nimport putRecord from './lexicons/com/atproto/repo/putRecord.js'\nimport uploadBlob from './lexicons/com/atproto/repo/uploadBlob.js'\nimport getBlob from './lexicons/com/atproto/sync/getBlob.js'\nimport {\n XrpcResponse,\n type XrpcResponseBody,\n type XrpcResponseOptions,\n} from './response.js'\nimport type { BinaryBodyInit, Service } from './types.js'\nimport {\n type RecordKeyOptions,\n type XrpcRequestHeadersOptions,\n applyDefaults,\n buildXrpcRequestHeaders,\n getDefaultRecordKey,\n getLiteralRecordKey,\n wait,\n} from './util.js'\nimport {\n type WriteOperation,\n type WriteOperationCreateOptions,\n type WriteOperationDeleteOptions,\n WriteOperationHelper,\n type WriteOperationUpdateOptions,\n type WriteOperationsFactory,\n} from './write-operation-builder.js'\nimport {\n type XrpcOptions,\n type XrpcRequestParams,\n type XrpcRequestProcessingOptions,\n xrpc,\n xrpcSafe,\n} from './xrpc.js'\n\nexport {\n type AtIdentifierString,\n type CidString,\n type DidString,\n type Infer,\n type InferMethodInputBody,\n type InferMethodOutputBody,\n type InferRecordKey,\n type LexMap,\n type LexValue,\n type LexiconRecordKey,\n type Main,\n type NsidString,\n type Params,\n Procedure,\n Query,\n RecordSchema,\n type Restricted,\n type TypedLexMap,\n type WriteOperation,\n type WriteOperationCreateOptions,\n type WriteOperationDeleteOptions,\n WriteOperationHelper,\n type WriteOperationUpdateOptions,\n type WriteOperationsFactory,\n}\n\n/**\n * Configuration options for creating a {@link Client}.\n *\n * @property {@link ClientOptions.labelers} - An iterable of labeler DIDs to include in requests. These will be combined with any global app labelers configured via {@link Client.configure}.\n * @property {@link ClientOptions.service} - An optional service identifier (DID or URL) for routing requests with service proxying.\n * @property {@link ClientOptions.headers} - Custom headers to include in all requests made by this client instance.\n * @property {@link ClientOptions.validateRequest} - If true, validates request bodies against their lexicon schemas before sending. Defaults to false for performance.\n * @property {@link ClientOptions.validateResponse} - If false, skips validation of response bodies against their lexicon schemas. Defaults to true to catch errors, but can be disabled for performance if you trust the server responses. Note that defaults will not be applied if validation is disabled, which can cause typing inconsistencies, so use with caution.\n * @property {@link ClientOptions.strictResponseProcessing} - If false, relaxes certain validation rules during response processing (e.g., allowing floats, deeper nesting, etc.). Defaults to true for strict compliance with {@link https://atproto.com/specs/data-model lexicon data model}, but can be disabled to handle non-compliant responses.\n *\n * @see {@link XrpcRequestHeadersOptions}\n * @see {@link XrpcRequestProcessingOptions}\n * @see {@link XrpcResponseOptions}\n *\n * @example\n * ```typescript\n * const options: ClientOptions = {\n * labelers: ['did:plc:labeler1'],\n * service: 'did:web:api.bsky.app#bsky_appview',\n * headers: { 'X-Custom-Header': 'value' },\n * validateRequest: false,\n * validateResponse: true,\n * strictResponseProcessing: false,\n * }\n * ```\n */\nexport type ClientOptions = XrpcRequestHeadersOptions &\n Pick<XrpcRequestProcessingOptions, 'validateRequest'> &\n XrpcResponseOptions\n\nexport type ActionOptions = {\n /** AbortSignal to cancel the request. */\n signal?: AbortSignal\n}\n\n/**\n * A composable action that can be invoked via {@link Client.call}.\n *\n * Actions provide a way to define custom operations that integrate with the\n * Client's call interface, enabling type-safe, reusable business logic.\n *\n * @typeParam I - The input type for the action\n * @typeParam O - The output type for the action\n *\n * @example\n * ```typescript\n * const myAction: Action<{ userId: string }, { profile: Profile }> = async (client, input, options) => {\n * const response = await client.xrpc(someMethod, { params: { actor: input.userId }, ...options })\n * return { profile: response.body }\n * }\n * ```\n */\nexport type Action<I = any, O = any> = (\n client: Client,\n input: I,\n options: ActionOptions,\n) => O | Promise<O>\n\n/**\n * Extracts the input type from an {@link Action}.\n * @typeParam A - The Action type to extract from\n */\nexport type InferActionInput<A extends Action> =\n A extends Action<infer I, any> ? I : never\n\n/**\n * Extracts the output type from an {@link Action}.\n * @typeParam A - The Action type to extract from\n */\nexport type InferActionOutput<A extends Action> =\n A extends Action<any, infer O> ? O : never\n\n/**\n * Options for creating a record in an AT Protocol repository.\n *\n * @see {@link Client.createRecord}\n */\nexport type CreateRecordOptions = Omit<\n XrpcOptions<typeof createRecord>,\n 'body'\n> & {\n /** Repository identifier (DID or handle). Defaults to authenticated user's DID. */\n repo?: AtIdentifierString\n /** Compare-and-swap on the repo commit. If specified, must match current commit. */\n swapCommit?: string\n /**\n * Whether the PDS should validate the record against its lexicon schema.\n * When `true`, the PDS is asked to explicitly validate the record. When\n * `false`, the PDS is asked to explicitly skip validation. When `undefined`\n * (default), the PDS decides -- typically validating only collections whose\n * schemas it knows. This is server-side validation; for client-side\n * validation before sending, use {@link XrpcRequestProcessingOptions.validateRequest}.\n */\n validate?: boolean\n}\n\n/**\n * Options for deleting a record from an AT Protocol repository.\n *\n * @see {@link Client.deleteRecord}\n */\nexport type DeleteRecordOptions = Omit<\n XrpcOptions<typeof deleteRecord>,\n 'body'\n> & {\n /** Repository identifier (DID or handle). Defaults to authenticated user's DID. */\n repo?: AtIdentifierString\n /** Compare-and-swap on the repo commit. If specified, must match current commit. */\n swapCommit?: string\n /** Compare-and-swap on the record CID. If specified, must match current record. */\n swapRecord?: string\n}\n\n/**\n * Options for retrieving a record from an AT Protocol repository.\n *\n * @see {@link Client.getRecord}\n */\nexport type GetRecordOptions = Omit<XrpcOptions<typeof getRecord>, 'params'> & {\n /** Repository identifier (DID or handle). Defaults to authenticated user's DID. */\n repo?: AtIdentifierString\n}\n\n/**\n * Options for creating or updating a record in an AT Protocol repository.\n *\n * @see {@link Client.putRecord}\n */\nexport type PutRecordOptions = Omit<XrpcOptions<typeof putRecord>, 'body'> & {\n /** Repository identifier (DID or handle). Defaults to authenticated user's DID. */\n repo?: AtIdentifierString\n /** Compare-and-swap on the repo commit. If specified, must match current commit. */\n swapCommit?: string\n /** Compare-and-swap on the record CID. If specified, must match current record. */\n swapRecord?: string\n /**\n * Whether the PDS should validate the record against its lexicon schema.\n * When `true`, the PDS is asked to explicitly validate the record. When\n * `false`, the PDS is asked to explicitly skip validation. When `undefined`\n * (default), the PDS decides — typically validating only collections whose\n * schemas it knows. This is server-side validation; for client-side\n * validation before sending, use {@link XrpcRequestProcessingOptions.validateRequest}.\n */\n validate?: boolean\n}\n\n/**\n * Options for listing records in an AT Protocol repository collection.\n *\n * @see {@link Client.listRecords}\n */\nexport type ListRecordsOptions = Omit<\n XrpcOptions<typeof listRecords>,\n 'params'\n> & {\n /** Repository identifier (DID or handle). Defaults to authenticated user's DID. */\n repo?: AtIdentifierString\n /** Maximum number of records to return. */\n limit?: number\n /** Pagination cursor from a previous response. */\n cursor?: string\n /** If true, returns records in reverse chronological order. */\n reverse?: boolean\n}\n\n/**\n * Options for applying a batch of writes (create/update/delete) to an AT Protocol repository.\n *\n * @see {@link Client.applyWrites}\n */\nexport type ApplyWritesOptions = Omit<\n XrpcOptions<typeof applyWrites>,\n 'body'\n> & {\n /** Repository identifier (DID or handle). Defaults to authenticated user's DID. */\n repo?: AtIdentifierString\n /**\n * Whether the PDS should validate the records against their lexicon schemas.\n * When `true`, the PDS is asked to explicitly validate every record. When\n * `false`, the PDS is asked to explicitly skip validation. When `undefined`\n * (default), the PDS decides — typically validating only collections whose\n * schemas it knows.\n */\n validate?: boolean\n /** Compare-and-swap on the repo commit. If specified, must match current commit. */\n swapCommit?: CidString\n}\n\nexport type UploadBlobOptions = Omit<XrpcOptions<typeof uploadBlob>, 'body'>\n\nexport type GetBlobOptions = Omit<XrpcOptions<typeof getBlob>, 'params'>\n\n/**\n * Type-safe options for {@link Client.create}, combining record options with key requirements.\n * @typeParam T - The record schema type\n * @see {@link CreateRecordOptions}\n */\nexport type CreateOptions<T extends RecordSchema> = CreateRecordOptions &\n RecordKeyOptions<T, 'tid' | 'any'>\n\n/**\n * Output type for record creation operations.\n * Contains the URI and CID of the newly created record.\n */\nexport type CreateOutput = InferMethodOutputBody<\n typeof createRecord,\n Uint8Array\n>\n\n/**\n * Type-safe options for {@link Client.delete}, combining delete options with key requirements.\n * @typeParam T - The record schema type\n */\nexport type DeleteOptions<T extends RecordSchema> = DeleteRecordOptions &\n RecordKeyOptions<T>\n\n/**\n * Output type for record deletion operations.\n */\nexport type DeleteOutput = InferMethodOutputBody<\n typeof deleteRecord,\n Uint8Array\n>\n\n/**\n * Type-safe options for {@link Client.get}, combining get options with key requirements.\n * @typeParam T - The record schema type\n */\nexport type GetOptions<T extends RecordSchema> = GetRecordOptions &\n RecordKeyOptions<T>\n\n/**\n * Output type for record retrieval operations.\n * Contains the record value validated against the schema type.\n * @typeParam T - The record schema type\n */\nexport type GetOutput<T extends RecordSchema> = Omit<\n InferMethodOutputBody<typeof getRecord, Uint8Array>,\n 'value'\n> & { value: Infer<T> }\n\n/**\n * Type-safe options for {@link Client.put}, combining put options with key requirements.\n * @typeParam T - The record schema type\n */\nexport type PutOptions<T extends RecordSchema> = PutRecordOptions &\n RecordKeyOptions<T>\n\n/**\n * Output type for record put (create/update) operations.\n * Contains the URI and CID of the record.\n */\nexport type PutOutput = InferMethodOutputBody<typeof putRecord, Uint8Array>\n\n/**\n * Options for {@link Client.list} operations.\n */\nexport type ListOptions = ListRecordsOptions\n\n/**\n * Output type for record listing operations.\n * Contains validated records and any invalid records that failed schema validation.\n * @typeParam T - The record schema type\n */\nexport type ListOutput<T extends RecordSchema> = Omit<\n InferMethodOutputBody<typeof listRecords>,\n 'records'\n> & {\n /** Records that successfully validated against the schema. */\n records: ListRecordItem<Infer<T>>[]\n}\n\n/**\n * A discriminated union type representing the result of a record listing\n * operation.\n */\nexport type ListRecordItem<Value extends LexMap> =\n | { uri: AtUriString; cid: CidString; valid: true; value: Value }\n | { uri: AtUriString; cid: CidString; valid: false; value: LexMap }\n\n/**\n * The Client class is the primary interface for interacting with AT Protocol\n * services. It provides type-safe methods for XRPC calls, record operations,\n * and blob handling.\n *\n * @example\n * ```typescript\n * import { Client } from '@atproto/lex'\n * import { app } from '#/lexicons\n *\n * const client = new Client(oauthSession)\n *\n * const response = await client.xrpc(app.bsky.feed.getTimeline.main, {\n * params: { limit: 50 }\n * })\n * ```\n */\nexport class Client implements Agent {\n static appLabelers: readonly DidString[] = []\n\n /**\n * Configures the Client (or its sub classes) globally.\n */\n static configure(opts: { appLabelers?: Iterable<DidString> }) {\n if (opts.appLabelers) this.appLabelers = [...opts.appLabelers]\n }\n\n /** The underlying agent used for making requests. */\n public readonly agent: Agent\n\n /** Custom headers included in all requests. */\n public readonly headers: Headers\n\n /** Optional service identifier for routing requests. */\n public readonly service?: Service\n\n /** Set of labeler DIDs specific to this client instance. */\n public readonly labelers: Set<DidString>\n\n public readonly xrpcDefaults: {\n readonly validateRequest: boolean\n readonly validateResponse: boolean\n readonly strictResponseProcessing: boolean\n }\n\n constructor(agent: Agent | AgentOptions, options: ClientOptions = {}) {\n this.agent = buildAgent(agent)\n this.service = options.service\n this.labelers = new Set(options.labelers)\n this.headers = new Headers(options.headers)\n this.xrpcDefaults = Object.freeze({\n validateRequest: options.validateRequest ?? false,\n validateResponse: options.validateResponse ?? true,\n strictResponseProcessing: options.strictResponseProcessing ?? true,\n })\n }\n\n /**\n * The DID of the authenticated user, or `undefined` if not authenticated.\n */\n get did(): DidString | undefined {\n return this.agent.did\n }\n\n /**\n * The DID of the authenticated user.\n * @throws {Error} if not authenticated\n */\n get assertDid(): DidString {\n this.assertAuthenticated()\n return this.did\n }\n\n /**\n * Asserts that the client is authenticated.\n * Use as a type guard when you need to ensure authentication.\n *\n * @throws {Error} if not authenticated\n *\n * @example\n * ```typescript\n * client.assertAuthenticated()\n * // TypeScript now knows client.did is defined\n * console.log(client.did)\n * ```\n */\n public assertAuthenticated(): asserts this is { did: DidString } {\n if (!this.did) throw new Error('Client is not authenticated')\n }\n\n /**\n * Replaces all labelers with the given set.\n * @param labelers - Iterable of labeler DIDs\n */\n public setLabelers(labelers: Iterable<DidString> = []) {\n this.clearLabelers()\n this.addLabelers(labelers)\n }\n\n /**\n * Adds labelers to the current set.\n * @param labelers - Iterable of labeler DIDs to add\n */\n public addLabelers(labelers: Iterable<DidString>) {\n for (const labeler of labelers) this.labelers.add(labeler)\n }\n\n /**\n * Removes all labelers from this client instance.\n */\n public clearLabelers() {\n this.labelers.clear()\n }\n\n /**\n * {@link Agent}'s {@link Agent.fetchHandler} implementation, which adds\n * labelers and service proxying headers. This method allow a {@link Client}\n * instance to be used directly as an {@link Agent} for another\n * {@link Client}, enabling composition of headers (labelers, proxying, etc.).\n *\n * @param path - The request path\n * @param init - Request initialization options\n */\n public fetchHandler(\n path: `/${string}`,\n init: RequestInit,\n ): Promise<Response> {\n const headers = buildXrpcRequestHeaders({\n headers: init.headers,\n service: this.service,\n labelers: [\n ...(this.constructor as typeof Client).appLabelers.map(\n (l) => `${l};redact` as const,\n ),\n ...this.labelers,\n ],\n })\n\n // Incoming headers take precedence\n for (const [key, value] of this.headers) {\n if (!headers.has(key)) headers.set(key, value)\n }\n\n // @NOTE The agent here could be another Client instance.\n return this.agent.fetchHandler(path, { ...init, headers })\n }\n\n /**\n * Makes an XRPC request. Throws on failure.\n *\n * @param ns - The lexicon method definition (e.g., `app.bsky.feed.getTimeline`)\n * @param options - Request options including params and body\n * @returns The successful XRPC response\n * @throws {XrpcFailure} when the request fails or returns an error\n *\n * @example Query with parameters\n * ```typescript\n * const response = await client.xrpc(app.bsky.feed.getTimeline, {\n * params: { limit: 50, cursor: 'abc123' }\n * })\n * console.log(response.body.feed)\n * ```\n *\n * @example Procedure with body\n * ```typescript\n * const response = await client.xrpc(com.atproto.repo.createRecord, {\n * body: {\n * repo: client.assertDid,\n * collection: 'app.bsky.feed.post',\n * record: { text: 'Hello!', createdAt: new Date().toISOString() }\n * }\n * })\n * ```\n *\n * @see {@link xrpcSafe} for a non-throwing variant\n */\n async xrpc<const M extends Query | Procedure>(\n ns: NonNullable<unknown> extends XrpcOptions<M>\n ? Main<M>\n : Restricted<'This XRPC method requires an \"options\" argument'>,\n ): Promise<XrpcResponse<M>>\n async xrpc<const M extends Query | Procedure>(\n ns: Main<M>,\n options: XrpcOptions<M>,\n ): Promise<XrpcResponse<M>>\n async xrpc<const M extends Query | Procedure>(\n ns: Main<M>,\n options: XrpcOptions<M> = {} as XrpcOptions<M>,\n ): Promise<XrpcResponse<M>> {\n return xrpc(this, ns, applyDefaults(options, this.xrpcDefaults))\n }\n\n /**\n * Makes an XRPC request without throwing on failure.\n * Returns either a successful response or a failure object.\n *\n * @param ns - The lexicon method definition\n * @param options - Request options\n * @returns Either an XrpcResponse on success or XrpcFailure on failure\n *\n * @example\n * ```typescript\n * const result = await client.xrpcSafe(app.bsky.actor.getProfile.main, {\n * params: { actor: 'alice.bsky.social' }\n * })\n *\n * if (result.success) {\n * console.log(result.body.displayName)\n * } else {\n * console.error('Failed:', result.error)\n * }\n * ```\n *\n * @see {@link xrpc} for a throwing variant\n */\n async xrpcSafe<const M extends Query | Procedure>(\n ns: NonNullable<unknown> extends XrpcOptions<M>\n ? Main<M>\n : Restricted<'This XRPC method requires an \"options\" argument'>,\n ): Promise<XrpcResponse<M> | XrpcFailure<M>>\n async xrpcSafe<const M extends Query | Procedure>(\n ns: Main<M>,\n options: XrpcOptions<M>,\n ): Promise<XrpcResponse<M> | XrpcFailure<M>>\n async xrpcSafe<const M extends Query | Procedure>(\n ns: Main<M>,\n options: XrpcOptions<M> = {} as XrpcOptions<M>,\n ): Promise<XrpcResponse<M> | XrpcFailure<M>> {\n return xrpcSafe(this, ns, applyDefaults(options, this.xrpcDefaults))\n }\n\n /**\n * Creates a new record in an AT Protocol repository.\n *\n * @param record - The record to create, must include an {@link NsidString} `$type`\n * @param rkey - Optional record key; if omitted, server generates a TID\n * @param options - Create options including repo, swapCommit, validate\n * @returns The XRPC response containing the created record's URI and CID\n *\n * @example\n * ```typescript\n * const response = await client.createRecord(\n * { $type: 'app.bsky.feed.post', text: 'Hello!', createdAt: new Date().toISOString() },\n * undefined, // Let server generate rkey\n * { validate: true }\n * )\n * console.log(response.body.uri)\n * ```\n *\n * @see {@link create} for a higher-level typed alternative\n */\n public async createRecord(\n record: TypedLexMap<NsidString>,\n rkey?: string,\n options?: CreateRecordOptions,\n ) {\n return this.xrpc(createRecord, {\n ...options,\n body: {\n repo: options?.repo ?? this.assertDid,\n collection: record.$type,\n record,\n rkey,\n validate: options?.validate,\n swapCommit: options?.swapCommit,\n },\n })\n }\n\n /**\n * Deletes a record from an AT Protocol repository.\n *\n * @param collection - The collection NSID\n * @param rkey - The record key\n * @param options - Delete options including repo, swapCommit, swapRecord\n *\n * @see {@link delete} for a higher-level typed alternative\n */\n async deleteRecord(\n collection: NsidString,\n rkey: string,\n options?: DeleteRecordOptions,\n ) {\n return this.xrpc(deleteRecord, {\n ...options,\n body: {\n repo: options?.repo ?? this.assertDid,\n collection,\n rkey,\n swapCommit: options?.swapCommit,\n swapRecord: options?.swapRecord,\n },\n })\n }\n\n /**\n * Retrieves a record from an AT Protocol repository.\n *\n * @param collection - The collection NSID\n * @param rkey - The record key\n * @param options - Get options including repo\n *\n * @see {@link get} for a higher-level typed alternative\n */\n public async getRecord(\n collection: NsidString,\n rkey: string,\n options?: GetRecordOptions,\n ) {\n return this.xrpc(getRecord, {\n ...options,\n params: {\n repo: options?.repo ?? this.assertDid,\n collection,\n rkey,\n },\n })\n }\n\n /**\n * Creates or updates a record in a repository.\n *\n * @param record - The record to put, must include an {@link NsidString} `$type`\n * @param rkey - The record key\n * @param options - Put options including repo, swapCommit, swapRecord, validate\n *\n * @see {@link put} for a higher-level typed alternative\n */\n async putRecord(\n record: TypedLexMap<NsidString>,\n rkey: string,\n options?: PutRecordOptions,\n ) {\n return this.xrpc(putRecord, {\n ...options,\n body: {\n repo: options?.repo ?? this.assertDid,\n collection: record.$type,\n rkey,\n record,\n validate: options?.validate,\n swapCommit: options?.swapCommit,\n swapRecord: options?.swapRecord,\n },\n })\n }\n\n /**\n * Lists records in a collection.\n *\n * @param nsid - The collection NSID\n * @param options - List options including repo, limit, cursor, reverse\n *\n * @see {@link list} for a higher-level typed alternative\n */\n async listRecords(nsid: NsidString, options?: ListRecordsOptions) {\n return this.xrpc(listRecords, {\n ...options,\n params: {\n repo: options?.repo ?? this.assertDid,\n collection: nsid,\n cursor: options?.cursor,\n limit: options?.limit,\n reverse: options?.reverse,\n },\n })\n }\n\n /**\n * Performs an atomic batch of create, update, and delete operations on records in a repository.\n *\n * @param builder - A function that receives an {@link ApplyWritesOperations} instance to build the operations\n * @param options - ApplyWrites options including repo, validate, swapCommit\n * @returns The XRPC response from the applyWrites call\n *\n * @example\n * ```typescript\n * const response = await client.applyWrites((op) => [\n * op.create(app.bsky.feed.post, { text: 'Hello!' }),\n * op.update(app.bsky.feed.post, { text: 'Updated text' }, { rkey: 'post123' }),\n * op.delete(app.bsky.feed.post, 'post456'),\n * op.update(app.bsky.actor.profile, { displayName: 'Alice' }),\n * ], {\n * validate: true,\n * })\n *\n * for (const result of response.body.results) {\n * console.log(result.uri)\n * }\n * ```\n */\n async applyWrites(\n factory: WriteOperationsFactory,\n options?: ApplyWritesOptions,\n ) {\n return this.xrpc(applyWrites, {\n ...options,\n body: {\n repo: options?.repo ?? this.assertDid,\n writes: WriteOperationHelper.build(factory),\n validate: options?.validate,\n swapCommit: options?.swapCommit,\n },\n })\n }\n\n /**\n * Uploads a blob to an AT Protocol repository.\n *\n * @param body - The blob data (Uint8Array, ReadableStream, Blob, etc.)\n * @param options - Upload options including encoding hint\n * @returns Response containing the blob reference\n *\n * @example\n * ```typescript\n * const imageData = await fetch('image.png').then(r => r.arrayBuffer())\n * const response = await client.uploadBlob(new Uint8Array(imageData), {\n * encoding: 'image/png'\n * })\n * console.log(response.body.blob) // Use this ref in records\n * ```\n */\n async uploadBlob(body: BinaryBodyInit, options?: UploadBlobOptions) {\n return this.xrpc(uploadBlob, { ...options, body })\n }\n\n /**\n * Retrieves a blob by DID and CID.\n *\n * @param did - The DID of the repository containing the blob\n * @param cid - The CID of the blob\n * @param options - Call options\n */\n async getBlob(did: DidString, cid: CidString, options?: GetBlobOptions) {\n return this.xrpc(getBlob, {\n ...options,\n params: { did, cid },\n })\n }\n\n /**\n * Universal call method for queries, procedures, and custom actions.\n * Automatically determines the call type based on the lexicon definition.\n *\n * @param ns - The lexicon method or action definition\n * @param arg - The input argument (params for queries, body for procedures, input for actions)\n * @param options - Call options\n * @returns The method response body or action output\n * @see {@link xrpc} if you need access to the full response object\n *\n * @example Query\n * ```typescript\n * const profile = await client.call(app.bsky.actor.getProfile.main, {\n * actor: 'alice.bsky.social'\n * })\n * ```\n *\n * @example Procedure\n * ```typescript\n * const result = await client.call(com.atproto.repo.createRecord.main, {\n * repo: did,\n * collection: 'app.bsky.feed.post',\n * record: { text: 'Hello!' }\n * })\n * ```\n */\n public async call<const T extends Query>(\n ns: NonNullable<unknown> extends XrpcRequestParams<T>\n ? Main<T>\n : Restricted<'This query type requires a \"params\" argument'>,\n ): Promise<XrpcResponseBody<T>>\n public async call<const T extends Procedure>(\n ns: undefined extends InferMethodInputBody<T, Uint8Array>\n ? Main<T>\n : Restricted<'This procedure type requires an \"input\" argument'>,\n ): Promise<XrpcResponseBody<T>>\n public async call<const T extends Action>(\n ns: void extends InferActionInput<T>\n ? Main<T>\n : Restricted<'This action type requires an \"input\" argument'>,\n ): Promise<InferActionOutput<T>>\n public async call<const T extends Action | Procedure | Query>(\n ns: Main<T>,\n arg: T extends Action\n ? InferActionInput<T>\n : T extends Procedure\n ? InferMethodInputBody<T, Uint8Array>\n : T extends Query\n ? XrpcRequestParams<T>\n : never,\n options?: T extends Action\n ? ActionOptions\n : T extends Procedure\n ? Omit<XrpcOptions<T>, 'body'>\n : T extends Query\n ? Omit<XrpcOptions<T>, 'params'>\n : never,\n ): Promise<\n T extends Action\n ? InferActionOutput<T>\n : T extends Procedure\n ? XrpcResponseBody<T>\n : T extends Query\n ? XrpcResponseBody<T>\n : never\n >\n public async call(\n ns: Main<Action> | Main<Procedure> | Main<Query>,\n arg?: LexValue | Params,\n options: ActionOptions = {},\n ): Promise<unknown> {\n const method = getMain(ns)\n\n if (typeof method === 'function') {\n return method(this, arg, options)\n }\n\n if (method instanceof Procedure) {\n const result = await this.xrpc(method, { ...options, body: arg as any })\n return result.body\n } else if (method instanceof Query) {\n const result = await this.xrpc(method, { ...options, params: arg as any })\n return result.body\n } else {\n throw new TypeError('Invalid lexicon')\n }\n }\n\n /**\n * Creates a new record with full type safety based on the schema.\n *\n * @param ns - The record schema definition\n * @param input - The record data (without `$type`, which is added automatically)\n * @param options - Create options including rkey (required for some record types)\n * @returns The create output including URI and CID\n *\n * @example Creating a post\n * ```typescript\n * const result = await client.create(app.bsky.feed.post.main, {\n * text: 'Hello, world!',\n * createdAt: new Date().toISOString()\n * })\n * console.log(result.uri)\n * ```\n *\n * @example Creating a record with explicit rkey\n * ```typescript\n * const result = await client.create(app.bsky.actor.profile.main, {\n * displayName: 'Alice'\n * }, { rkey: 'self' })\n * ```\n */\n public async create<const T extends RecordSchema>(\n ns: NonNullable<unknown> extends CreateOptions<T>\n ? Main<T>\n : Restricted<'This record type requires an \"options\" argument'>,\n input: Omit<Infer<T>, '$type'>,\n ): Promise<CreateOutput>\n public async create<const T extends RecordSchema>(\n ns: Main<T>,\n input: Omit<Infer<T>, '$type'>,\n options: CreateOptions<T>,\n ): Promise<CreateOutput>\n public async create<const T extends RecordSchema>(\n ns: Main<T>,\n input: Omit<Infer<T>, '$type'>,\n options: CreateOptions<T> = {} as CreateOptions<T>,\n ): Promise<CreateOutput> {\n const schema: T = getMain(ns)\n const record = schema.build(input) as TypedLexMap<NsidString>\n if (options?.validateRequest) schema.validate(record)\n const rkey = options.rkey ?? getDefaultRecordKey(schema)\n if (rkey !== undefined) schema.keySchema.assert(rkey)\n const response = await this.createRecord(record, rkey, options)\n return response.body\n }\n\n /**\n * Deletes a record with type-safe options.\n *\n * @param ns - The record schema definition\n * @param options - Delete options (rkey required for non-literal keys)\n * @returns The delete output\n */\n public async delete<const T extends RecordSchema>(\n ns: NonNullable<unknown> extends DeleteOptions<T>\n ? Main<T>\n : Restricted<'This record type requires an \"options\" argument'>,\n ): Promise<DeleteOutput>\n public async delete<const T extends RecordSchema>(\n ns: Main<T>,\n options?: DeleteOptions<T>,\n ): Promise<DeleteOutput>\n public async delete<const T extends RecordSchema>(\n ns: Main<T>,\n options: DeleteOptions<T> = {} as DeleteOptions<T>,\n ): Promise<DeleteOutput> {\n const schema = getMain(ns)\n const rkey = schema.keySchema.parse(\n options.rkey ?? getLiteralRecordKey(schema),\n )\n const response = await this.deleteRecord(schema.$type, rkey, options)\n return response.body\n }\n\n /**\n * Retrieves a record with type-safe validation.\n *\n * @param ns - The record schema definition\n * @param options - Get options (rkey required for non-literal keys)\n * @returns The record data validated against the schema\n *\n * @example\n * ```typescript\n * const profile = await client.get(app.bsky.actor.profile.main)\n * // profile.value is typed as app.bsky.actor.profile.Record\n * console.log(profile.value.displayName)\n * ```\n */\n public async get<const T extends RecordSchema>(\n ns: T['key'] extends `literal:${string}`\n ? Main<T>\n : Restricted<'This record type requires an \"options\" argument'>,\n ): Promise<GetOutput<T>>\n public async get<const T extends RecordSchema>(\n ns: Main<T>,\n options: GetOptions<T>,\n ): Promise<GetOutput<T>>\n public async get<const T extends RecordSchema>(\n ns: Main<T>,\n options: GetOptions<T> = {} as GetOptions<T>,\n ): Promise<GetOutput<T>> {\n const schema = getMain(ns)\n const rkey = schema.keySchema.parse(\n options.rkey ?? getLiteralRecordKey(schema),\n )\n const response = await this.getRecord(schema.$type, rkey, options)\n const value = schema.validate(response.body.value)\n return { ...response.body, value }\n }\n\n /**\n * Creates or updates a record with full type safety.\n *\n * @param ns - The record schema definition\n * @param input - The record data\n * @param options - Put options (rkey required for non-literal keys)\n * @returns The put output including URI and CID\n */\n public async put<const T extends RecordSchema>(\n ns: NonNullable<unknown> extends PutOptions<T>\n ? Main<T>\n : Restricted<'This record type requires an \"options\" argument'>,\n input: Omit<Infer<T>, '$type'>,\n ): Promise<PutOutput>\n public async put<const T extends RecordSchema>(\n ns: Main<T>,\n input: Omit<Infer<T>, '$type'>,\n options: PutOptions<T>,\n ): Promise<PutOutput>\n public async put<const T extends RecordSchema>(\n ns: Main<T>,\n input: Omit<Infer<T>, '$type'>,\n options: PutOptions<T> = {} as PutOptions<T>,\n ): Promise<PutOutput> {\n const schema: T = getMain(ns)\n const record = schema.build(input) as TypedLexMap<NsidString>\n if (options?.validateRequest) schema.validate(record)\n const rkey = options.rkey ?? getLiteralRecordKey(schema)\n const response = await this.putRecord(record, rkey, options)\n return response.body\n }\n\n /**\n * Lists records with type-safe validation and separation of valid/invalid records.\n *\n * @param ns - The record schema definition\n * @param options - List options\n * @returns Records validated against the schema, with invalid records included as LexMap\n *\n * @example\n * ```typescript\n * const result = await client.list(app.bsky.feed.post.main, { limit: 100 })\n * for (const record of result.records) {\n * if (record.valid) {\n * record.value // Fully typed\n * } else {\n * record.value // Invalid record, typed as LexMap\n * }\n * }\n * ```\n */\n async list<const T extends RecordSchema>(\n ns: Main<T>,\n options?: ListOptions,\n ): Promise<ListOutput<T>> {\n const schema = getMain(ns)\n const { body } = await this.listRecords(schema.$type, options)\n const records = body.records.map(processListRecord, schema)\n return { ...body, records }\n }\n\n /**\n * Asynchronously iterates over all records in a collection, handling\n * pagination automatically.\n *\n * @param ns - The record schema definition\n * @param options - List options including limit and cursor\n * @returns An async generator yielding each record validated against the schema\n */\n async *listAll<const T extends RecordSchema>(\n ns: Main<T>,\n { maxRetries = 3, ...options }: ListOptions & { maxRetries?: number } = {},\n ): AsyncGenerator<ListRecordItem<Infer<T>>, void, unknown> {\n const schema = getMain(ns)\n let currentErrorCount = 0\n\n do {\n options.signal?.throwIfAborted()\n\n try {\n const { body } = await this.listRecords(schema.$type, options)\n\n // We got a successful response, reset error count\n currentErrorCount = 0\n\n // We don't use this.list() here so that we can lazily process records as\n // they come in, rather than mapping and yielding the entire page at once.\n for (const record of body.records) {\n yield processListRecord.call(schema, record)\n }\n\n // If the server returns the same cursor, we may be in a loop. Stop\n // iteration.\n if (body.cursor && body.cursor === options.cursor) {\n return\n }\n\n options.cursor = body.cursor\n } catch (err) {\n currentErrorCount++\n if (currentErrorCount > maxRetries) {\n throw err\n }\n\n if (err instanceof XrpcResponseError) {\n // Page not found, return empty iterator\n if (err.status === 404 || err.error === 'NotFound') {\n return\n }\n\n // Rate limit error\n if (err.status === 429 || err.error === 'RateLimitExceeded') {\n const resetsAt = err.headers.get('RateLimit-Reset') // epoch\n if (resetsAt != null && /^\\s*\\d+\\s*$/.test(resetsAt)) {\n const resetsIn = Number(resetsAt) * 1000 - Date.now()\n await wait(Math.max(resetsIn, 1e3), options)\n continue\n }\n\n // Unable to determine when to retry; fall through\n }\n\n // Server asks to retry after a certain time\n const retryAfter = err.headers.get('Retry-After')\n if (retryAfter != null) {\n const waitTime = /^\\s*\\d+\\s*$/.test(retryAfter)\n ? // Retry-After is in seconds\n Number(retryAfter) * 1000\n : // Retry-After is an http-date\n new Date(retryAfter).getTime() - Date.now()\n\n if (!Number.isNaN(waitTime)) {\n await wait(Math.max(waitTime, 1e3), options)\n continue\n }\n\n // Invalid date; fall through\n }\n }\n\n // Exponential backoff for transient errors\n if (err instanceof XrpcError && err.shouldRetry()) {\n const waitTime = Math.min(2 ** currentErrorCount * 1000, 30_000)\n await wait(waitTime, options)\n continue\n }\n\n // Propagate unexpected and non-retryable errors\n throw err\n }\n } while (options.cursor)\n }\n}\n\nfunction processListRecord<T extends RecordSchema>(\n this: T,\n record: ListRecordsRecord,\n): ListRecordItem<Infer<T>> {\n const result = this.safeValidate(record.value)\n if (result.success) {\n return { ...record, valid: true, value: result.value }\n } else {\n return { ...record, valid: false }\n }\n}\n"]}
package/dist/errors.d.ts CHANGED
@@ -1,7 +1,9 @@
1
- import { LexError, LexErrorCode, LexErrorData, LexValue } from '@atproto/lex-data';
2
- import { InferMethodError, LexValidationError, Procedure, Query, ResultFailure } from '@atproto/lex-schema';
3
- import { XrpcUnknownResponsePayload } from './types.js';
4
- import { WWWAuthenticate } from './www-authenticate.js';
1
+ import type { LexErrorCode, LexErrorData, LexValue } from '@atproto/lex-data';
2
+ import { LexError } from '@atproto/lex-data';
3
+ import { LexValidationError, Procedure, Query } from '@atproto/lex-schema';
4
+ import type { InferMethodError, ResultFailure } from '@atproto/lex-schema';
5
+ import type { XrpcUnknownResponsePayload } from './types.js';
6
+ import type { WWWAuthenticate } from './www-authenticate.js';
5
7
  export type { XrpcUnknownResponsePayload };
6
8
  export type DownstreamError<N extends LexErrorCode = LexErrorCode> = {
7
9
  status: number;
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,QAAQ,EACT,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,SAAS,EACT,KAAK,EACL,aAAa,EAEd,MAAM,qBAAqB,CAAA;AAG5B,OAAO,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAA;AACvD,OAAO,EACL,eAAe,EAEhB,MAAM,uBAAuB,C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CAAC,CAAC;IACjE,IAAI,SAAsB;IAE1B,YAAY,MAAM,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,EAO9D;IAED,IAAa,MAAM,IAAI,IAAI,CAE1B;IAEQ,WAAW,IAAI,OAAO,CAE9B;IAEQ,MAAM,IAAI,YAAY,CAG9B;IAEQ,iBAAiB,IAAI,eAAe,CAE5C;CACF;AAED;;;;;;;;;GASG;AACH,qBAAa,cAAc,CACzB,CAAC,SAAS,SAAS,GAAG,KAAK,GAAG,SAAS,GAAG,KAAK,CAC/C,SAAQ,iBAAiB,CAAC,CAAC,CAAC;IAC5B,IAAI,SAAmB;IAEvB,YAAY,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,EAGpC;IAEQ,WAAW,IAAI,OAAO,CAM9B;IAEQ,MAAM,IAAI,YAAY,CAG9B;IAEQ,iBAAiB,IAAI,eAAe,CAO5C;CACF;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,SAAS,GAAG,KAAK,GAAG,SAAS,GAAG,KAAK,IAEnE,iBAAiB,CAAC,CAAC,CAAC,GAEpB,wBAAwB,CAAC,CAAC,CAAC,GAE3B,iBAAiB,CAAC,CAAC,CAAC,CAAA;AAExB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,SAAS,GAAG,KAAK,EACvD,MAAM,EAAE,CAAC,EACT,KAAK,EAAE,OAAO,GACb,WAAW,CAAC,CAAC,CAAC,CAUhB"}
package/dist/errors.js CHANGED
@@ -1,6 +1,6 @@
1
- import { LexError, } from '@atproto/lex-data';
2
- import { lexErrorDataSchema, } from '@atproto/lex-schema';
3
- import { parseWWWAuthenticateHeader, } from './www-authenticate.js';
1
+ import { LexError } from '@atproto/lex-data';
2
+ import { LexValidationError, Procedure, Query, lexErrorDataSchema, } from '@atproto/lex-schema';
3
+ import { parseWWWAuthenticateHeader } from './www-authenticate.js';
4
4
  /**
5
5
  * Mapping that allows generating an XRPC error code from an HTTP status code
6
6
  * when the response does not contain a valid XRPC error payload. This is used
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,GAIT,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAML,kBAAkB,GACnB,MAAM,qBAAqB,CAAA;AAI5B,OAAO,EAEL,0BAA0B,GAC3B,MAAM,uBAAuB,CAAA;AAE9B;;;;;GAKG;AACH,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAuB;IACrD,CAAC,GAAG,EAAE,gBAAgB,CAAC;IACvB,CAAC,GAAG,EAAE,wBAAwB,CAAC;IAC/B,CAAC,GAAG,EAAE,WAAW,CAAC;IAClB,CAAC,GAAG,EAAE,kBAAkB,CAAC;IACzB,CAAC,GAAG,EAAE,eAAe,CAAC;IACtB,CAAC,GAAG,EAAE,iBAAiB,CAAC;IACxB,CAAC,GAAG,EAAE,sBAAsB,CAAC;IAC7B,CAAC,GAAG,EAAE,mBAAmB,CAAC;IAC1B,CAAC,GAAG,EAAE,qBAAqB,CAAC;IAC5B,CAAC,GAAG,EAAE,sBAAsB,CAAC;IAC7B,CAAC,GAAG,EAAE,iBAAiB,CAAC;IACxB,CAAC,GAAG,EAAE,oBAAoB,CAAC;IAC3B,CAAC,GAAG,EAAE,iBAAiB,CAAC;CACzB,CAAC,CAAA;AAWF;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAwB,IAAI,GAAG,CAAC;IACtE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG;CAC5C,CAAC,CAAA;AAEF,OAAO,EAAE,QAAQ,EAAE,CAAA;AAenB;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,kBAAkB,CAChC,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,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAA;IAEjC,OAAO,MAAM,CAAA;AACf,CAAC;AAED,SAAS,4BAA4B,CAAC,QAAkB;IACtD,IAAI,QAAQ,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;QAC1B,OAAO,0DAA0D,QAAQ,CAAC,MAAM,GAAG,CAAA;IACrF,CAAC;IAED,OAAO,oCAAoC,QAAQ,CAAC,MAAM,QAAQ,CAAA;AACpE,CAAC","sourcesContent":["import {\n LexError,\n LexErrorCode,\n LexErrorData,\n LexValue,\n} from '@atproto/lex-data'\nimport {\n InferMethodError,\n LexValidationError,\n Procedure,\n Query,\n ResultFailure,\n lexErrorDataSchema,\n} from '@atproto/lex-schema'\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nimport { Agent } from './agent.js'\nimport { XrpcUnknownResponsePayload } from './types.js'\nimport {\n WWWAuthenticate,\n parseWWWAuthenticateHeader,\n} from './www-authenticate.js'\n\n/**\n * Mapping that allows generating an XRPC error code from an HTTP status code\n * when the response does not contain a valid XRPC error payload. This is used\n * to convert non-XRPC error responses from upstream servers into a standardized\n * XRPC error for downstream clients.\n */\nconst StatusErrorCodes = new Map<number, LexErrorCode>([\n [400, 'InvalidRequest'],\n [401, 'AuthenticationRequired'],\n [403, 'Forbidden'],\n [404, 'XRPCNotSupported'],\n [406, 'NotAcceptable'],\n [413, 'PayloadTooLarge'],\n [415, 'UnsupportedMediaType'],\n [429, 'RateLimitExceeded'],\n [500, 'InternalServerError'],\n [501, 'MethodNotImplemented'],\n [502, 'UpstreamFailure'],\n [503, 'NotEnoughResources'],\n [504, 'UpstreamTimeout'],\n])\n\nexport type { XrpcUnknownResponsePayload }\n\nexport type DownstreamError<N extends LexErrorCode = LexErrorCode> = {\n status: number\n headers?: Headers\n encoding?: 'application/json'\n body: LexErrorData<N>\n}\n\n/**\n * HTTP status codes that indicate a transient error that may succeed on retry.\n *\n * Includes:\n * - 408 Request Timeout\n * - 425 Too Early\n * - 429 Too Many Requests (rate limited)\n * - 500 Internal Server Error\n * - 502 Bad Gateway\n * - 503 Service Unavailable\n * - 504 Gateway Timeout\n * - 522 Connection Timed Out (Cloudflare)\n * - 524 A Timeout Occurred (Cloudflare)\n */\nexport const RETRYABLE_HTTP_STATUS_CODES: ReadonlySet<number> = new Set([\n 408, 425, 429, 500, 502, 503, 504, 522, 524,\n])\n\nexport { LexError }\nexport type { LexErrorCode, LexErrorData }\n\n/**\n * The payload structure for XRPC error responses.\n *\n * All XRPC errors return JSON with an `error` code and optional `message`.\n *\n * @typeParam N - The specific error code type\n */\nexport type XrpcErrorPayload<N extends LexErrorCode = LexErrorCode> = {\n body: LexErrorData<N>\n encoding: 'application/json'\n}\n\n/**\n * All unsuccessful responses should follow a standard error response\n * schema. The Content-Type should be application/json, and the payload\n * should be a JSON object with the following fields:\n *\n * - `error` (string, required): type name of the error (generic ASCII\n * constant, no whitespace)\n * - `message` (string, optional): description of the error, appropriate for\n * display to humans\n *\n * This function checks whether a given payload matches this schema.\n */\nexport function isXrpcErrorPayload(\n payload: XrpcUnknownResponsePayload | null | undefined,\n): payload is XrpcErrorPayload {\n return (\n payload != null &&\n payload.encoding === 'application/json' &&\n lexErrorDataSchema.matches(payload.body)\n )\n}\n\n/**\n * Abstract base class for all XRPC errors.\n *\n * Extends {@link LexError} and implements {@link ResultFailure} for use with\n * safe/result-based error handling patterns.\n *\n * @typeParam M - The XRPC method type (Procedure or Query)\n * @typeParam N - The error code type\n * @typeParam TReason - The reason type for ResultFailure\n *\n * @see {@link XrpcResponseError} - For valid XRPC error responses\n * @see {@link XrpcInvalidResponseError} - For invalid/unexpected responses\n * @see {@link XrpcInternalError} - For network/internal errors\n */\nexport abstract class XrpcError<\n M extends Procedure | Query = Procedure | Query,\n N extends LexErrorCode = LexErrorCode,\n TReason = unknown,\n >\n extends LexError<N>\n implements ResultFailure<TReason>\n{\n name = 'XrpcError'\n\n constructor(\n readonly method: M,\n error: N,\n message: string = `${error} Lexicon RPC error`,\n options?: ErrorOptions,\n ) {\n super(error, message, options)\n }\n\n /**\n * @see {@link ResultFailure.success}\n */\n readonly success = false as const\n\n /**\n * @see {@link ResultFailure.reason}\n */\n abstract readonly reason: TReason\n\n /**\n * Indicates whether the error is transient and can be retried.\n */\n abstract shouldRetry(): boolean\n\n abstract toDownstreamError(): DownstreamError\n\n matchesSchemaErrors(): this is XrpcError<M, InferMethodError<M>> {\n return this.method.errors?.includes(this.error) ?? false\n }\n}\n\n/**\n * Error class for valid XRPC error responses from the server.\n *\n * This represents a properly formatted XRPC error where the server returned\n * a non-2xx status with a valid JSON error payload containing `error` and\n * optional `message` fields.\n *\n * Use {@link matchesSchemaErrors} to check if the error matches the method's declared\n * error types for type-safe error handling.\n *\n * @typeParam M - The XRPC method type\n * @typeParam N - The error code type (inferred from method or generic)\n *\n * @example Handling specific errors\n * ```typescript\n * try {\n * await client.xrpc(someMethod, options)\n * } catch (err) {\n * if (err instanceof XrpcResponseError && err.error === 'RecordNotFound') {\n * // Handle not found case\n * }\n * }\n * ```\n */\nexport class XrpcResponseError<\n M extends Procedure | Query = Procedure | Query,\n> extends XrpcError<M, LexErrorCode, XrpcResponseError<M>> {\n name = 'XrpcResponseError'\n\n constructor(\n method: M,\n readonly response: Response,\n readonly payload?: XrpcUnknownResponsePayload,\n options?: ErrorOptions,\n ) {\n const { error, message } = isXrpcErrorPayload(payload)\n ? payload.body\n : {\n error:\n StatusErrorCodes.get(response.status) ??\n (response.status >= 500 ? 'UpstreamFailure' : 'InvalidRequest'),\n message: buildResponseOverviewMessage(response),\n }\n super(method, error, message, options)\n }\n\n override get reason(): this {\n return this\n }\n\n override shouldRetry(): boolean {\n return RETRYABLE_HTTP_STATUS_CODES.has(this.response.status)\n }\n\n override toJSON(): LexErrorData {\n // Return the original error payload if it's a valid XRPC error, otherwise\n // convert to an XRPC error format.\n const { payload } = this\n if (isXrpcErrorPayload(payload)) {\n return payload.body\n }\n\n return super.toJSON()\n }\n\n override toDownstreamError(): DownstreamError {\n const { status, headers } = this.response\n // If the upstream server returned a 500 error, we want to return a 502 Bad\n // Gateway to downstream clients, as the issue is with the upstream server,\n // not us. We still return the original error code and message in the body\n // for transparency, but we do not want to expose internal server errors\n // from the upstream server as-is to downstream clients.\n return {\n status: status === 500 ? 502 : status,\n headers: stripHopByHopHeaders(headers),\n body: this.toJSON(),\n }\n }\n\n get status(): number {\n return this.response.status\n }\n\n get headers(): Headers {\n return this.response.headers\n }\n\n get body(): undefined | Uint8Array | LexValue {\n return this.payload?.body\n }\n}\n\nexport type { WWWAuthenticate }\n\n/**\n * Error class for 401 Unauthorized XRPC responses.\n *\n * Extends {@link XrpcResponseError} with access to parsed WWW-Authenticate header\n * information, useful for implementing authentication flows.\n *\n * Authentication errors are never retryable as they require user intervention\n * (e.g., re-authentication, token refresh).\n *\n * @typeParam M - The XRPC method type\n * @typeParam N - The error code type\n *\n * @example Handling authentication errors\n * ```typescript\n * try {\n * await client.xrpc(someMethod, options)\n * } catch (err) {\n * if (err instanceof XrpcAuthenticationError) {\n * const { DPoP } = err.wwwAuthenticate\n * if (DPoP?.error === 'use_dpop_nonce') {\n * // Handle DPoP nonce requirement\n * }\n * }\n * }\n * ```\n */\nexport class XrpcAuthenticationError<\n M extends Procedure | Query = Procedure | Query,\n> extends XrpcResponseError<M> {\n name = 'XrpcAuthenticationError'\n\n override shouldRetry(): boolean {\n return false\n }\n\n #wwwAuthenticateCached?: WWWAuthenticate\n /**\n * Parsed WWW-Authenticate header from the response.\n * Contains authentication scheme parameters (e.g., Bearer realm, DPoP nonce).\n */\n get wwwAuthenticate(): WWWAuthenticate {\n return (this.#wwwAuthenticateCached ??=\n parseWWWAuthenticateHeader(\n this.response.headers.get('www-authenticate'),\n ) ?? {})\n }\n}\n\n/**\n * Error class for invalid or unprocessable XRPC responses from upstream servers.\n *\n * This occurs when the server returns a response that doesn't conform to the\n * XRPC protocol, such as:\n * - Missing or invalid Content-Type header\n * - Response body that doesn't match the method's output schema\n * - Non-JSON error responses\n * - Responses from non-XRPC endpoints\n *\n * The error code is always 'InvalidResponse' and maps to HTTP 502 Bad Gateway\n * when converted to a response. This should allow downstream clients to\n * determine at which boundary the error occurred.\n *\n * @typeParam M - The XRPC method type\n */\nexport class XrpcInvalidResponseError<\n M extends Procedure | Query = Procedure | Query,\n> extends XrpcError<M, 'InvalidResponse', XrpcInvalidResponseError<M>> {\n name = 'XrpcInvalidResponseError'\n\n constructor(\n method: M,\n readonly response: Response,\n readonly payload?: XrpcUnknownResponsePayload,\n message: string = buildResponseOverviewMessage(response),\n options?: ErrorOptions,\n ) {\n super(method, 'InvalidResponse', message, options)\n }\n\n override get reason(): this {\n return this\n }\n\n override shouldRetry(): boolean {\n return RETRYABLE_HTTP_STATUS_CODES.has(this.response.status)\n }\n\n override toDownstreamError(): DownstreamError {\n return { status: 502, body: this.toJSON() }\n }\n}\n\n/**\n * Error class for invalid XRPC responses that fail schema validation.\n *\n * This is a specific type of {@link XrpcInvalidResponseError} that indicates the\n * upstream server returned a response that was structurally valid but did not\n * conform to the expected schema for the method. This likely indicates a\n * mismatch between client and server versions or an issue with the server's\n * XRPC implementation.\n *\n * @typeParam M - The XRPC method type\n */\nexport class XrpcResponseValidationError<\n M extends Procedure | Query = Procedure | Query,\n> extends XrpcInvalidResponseError<M> {\n name = 'XrpcResponseValidationError'\n\n constructor(\n method: M,\n response: Response,\n payload: XrpcUnknownResponsePayload,\n readonly cause: LexValidationError,\n ) {\n super(\n method,\n response,\n payload,\n `Invalid response payload: ${cause.message}`,\n { cause },\n )\n }\n}\n\n/**\n * Error class for unexpected internal/client-side errors during XRPC requests.\n *\n * The error code is always 'InternalServerError' and these errors not\n * considered retryable as they stem from unforeseen issues in the\n * implementation.\n *\n * @typeParam M - The XRPC method type\n */\nexport class XrpcInternalError<\n M extends Procedure | Query = Procedure | Query,\n> extends XrpcError<M, 'InternalServerError', XrpcInternalError<M>> {\n name = 'XrpcInternalError'\n\n constructor(method: M, message?: string, options?: ErrorOptions) {\n super(\n method,\n 'InternalServerError',\n message ?? 'Unable to fulfill XRPC request',\n options,\n )\n }\n\n override get reason(): this {\n return this\n }\n\n override shouldRetry(): boolean {\n return false\n }\n\n override toJSON(): LexErrorData {\n // @NOTE Do not expose internal error details to downstream clients\n return { error: this.error, message: 'Internal Server Error' }\n }\n\n override toDownstreamError(): DownstreamError {\n return { status: 500, body: this.toJSON() }\n }\n}\n\n/**\n * Special case of XrpcInternalError that specifically represents errors thrown\n * by {@link Agent.fetchHandler} during the XRPC request. This includes:\n * - Network errors (connection refused, DNS failure)\n * - Request timeouts\n * - Request aborted via AbortSignal\n *\n * These errors are optimistically considered retryable, as many fetch errors\n * are transient and may succeed on retry.\n */\nexport class XrpcFetchError<\n M extends Procedure | Query = Procedure | Query,\n> extends XrpcInternalError<M> {\n name = 'XrpcFetchError'\n\n constructor(method: M, cause: unknown) {\n const message = cause instanceof Error ? cause.message : String(cause)\n super(method, `Unexpected fetchHandler() error: ${message}`, { cause })\n }\n\n override shouldRetry(): boolean {\n // Ideally, we would inspect the reason to determine if it's retryable (by\n // detecting network errors, timeouts, etc.). Since these cases are highly\n // platform-dependent, we optimistically assume all fetch errors are\n // transient and retryable.\n return true\n }\n\n override toJSON(): LexErrorData {\n // @NOTE Do not expose internal error details to downstream clients\n return { error: this.error, message: 'Failed to perform upstream request' }\n }\n\n override toDownstreamError(): DownstreamError {\n // While it might technically be a 500 error, we use 502 Bad Gateway here to\n // indicate that the error occurred while communicating with the upstream\n // server, allowing downstream clients to distinguish between errors in our\n // internal processing (500) and errors in the upstream server or network\n // (502).\n return { status: 502, body: this.toJSON() }\n }\n}\n\n/**\n * Union type of all possible XRPC failure types.\n *\n * Used as the return type for safe/non-throwing XRPC methods. Check the\n * `success` property to distinguish between success and failure:\n *\n * @typeParam M - The XRPC method type\n *\n * @example\n * ```typescript\n * const result = await client.xrpcSafe(someMethod, options)\n * if (result.success) {\n * console.log(result.body) // XrpcResponse\n * } else {\n * // result is XrpcFailure (XrpcResponseError | XrpcInvalidResponseError | XrpcInternalError)\n * console.error(result.error, result.message)\n * }\n * ```\n */\nexport type XrpcFailure<M extends Procedure | Query = Procedure | Query> =\n // The server returned a valid XRPC error response\n | XrpcResponseError<M>\n // The response was not a valid XRPC response, or it does not match the schema\n | XrpcInvalidResponseError<M>\n // Something went wrong (network error, etc.)\n | XrpcInternalError<M>\n\n/**\n * Converts an unknown error into an appropriate {@link XrpcFailure} type.\n *\n * If the error is already an XrpcFailure for the given method, returns it as-is.\n * Otherwise, wraps it in an {@link XrpcInternalError}.\n *\n * @param method - The XRPC method that was called\n * @param cause - The error to convert\n * @returns An XrpcFailure instance\n *\n * @example\n * ```typescript\n * try {\n * const response = await fetch(...)\n * // ... process response\n * } catch (err) {\n * return asXrpcFailure(method, err)\n * }\n * ```\n */\nexport function asXrpcFailure<M extends Procedure | Query>(\n method: M,\n cause: unknown,\n): XrpcFailure<M> {\n if (\n cause instanceof XrpcResponseError ||\n cause instanceof XrpcInvalidResponseError ||\n cause instanceof XrpcInternalError\n ) {\n if (cause.method === method) return cause\n }\n\n return new XrpcInternalError(method, undefined, { cause })\n}\n\nconst HOP_BY_HOP_HEADERS = new Set([\n 'connection',\n 'keep-alive',\n 'proxy-authenticate',\n 'proxy-authorization',\n 'te',\n 'trailer',\n 'transfer-encoding',\n 'upgrade',\n])\n\nfunction stripHopByHopHeaders(headers: Headers): Headers {\n const result = new Headers(headers)\n\n // Remove statically known hop-by-hop headers\n for (const name of HOP_BY_HOP_HEADERS) {\n result.delete(name)\n }\n\n // Remove headers listed in the \"Connection\" header\n const connection = headers.get('connection')\n if (connection) {\n for (const name of connection.split(',')) {\n result.delete(name.trim())\n }\n }\n\n // These are not actually hop-by-hop headers, but we remove them because the\n // upstream payload gets parsed and re-serialized, so content length and\n // encoding may no longer be accurate.\n result.delete('content-length')\n result.delete('content-encoding')\n\n return result\n}\n\nfunction buildResponseOverviewMessage(response: Response): string {\n if (response.status < 400) {\n return `Upstream server responded with an invalid status code (${response.status})`\n }\n\n return `Upstream server responded with a ${response.status} error`\n}\n"]}
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,EACL,kBAAkB,EAClB,SAAS,EACT,KAAK,EACL,kBAAkB,GACnB,MAAM,qBAAqB,CAAA;AAM5B,OAAO,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAA;AAElE;;;;;GAKG;AACH,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAuB;IACrD,CAAC,GAAG,EAAE,gBAAgB,CAAC;IACvB,CAAC,GAAG,EAAE,wBAAwB,CAAC;IAC/B,CAAC,GAAG,EAAE,WAAW,CAAC;IAClB,CAAC,GAAG,EAAE,kBAAkB,CAAC;IACzB,CAAC,GAAG,EAAE,eAAe,CAAC;IACtB,CAAC,GAAG,EAAE,iBAAiB,CAAC;IACxB,CAAC,GAAG,EAAE,sBAAsB,CAAC;IAC7B,CAAC,GAAG,EAAE,mBAAmB,CAAC;IAC1B,CAAC,GAAG,EAAE,qBAAqB,CAAC;IAC5B,CAAC,GAAG,EAAE,sBAAsB,CAAC;IAC7B,CAAC,GAAG,EAAE,iBAAiB,CAAC;IACxB,CAAC,GAAG,EAAE,oBAAoB,CAAC;IAC3B,CAAC,GAAG,EAAE,iBAAiB,CAAC;CACzB,CAAC,CAAA;AAWF;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAwB,IAAI,GAAG,CAAC;IACtE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG;CAC5C,CAAC,CAAA;AAEF,OAAO,EAAE,QAAQ,EAAE,CAAA;AAenB;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,kBAAkB,CAChC,OAAsD;IAEtD,OAAO,CACL,OAAO,IAAI,IAAI;QACf,OAAO,CA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O,MAAM,CAAA;AACf,CAAC;AAED,SAAS,4BAA4B,CAAC,QAAkB;IACtD,IAAI,QAAQ,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;QAC1B,OAAO,0DAA0D,QAAQ,CAAC,MAAM,GAAG,CAAA;IACrF,CAAC;IAED,OAAO,oCAAoC,QAAQ,CAAC,MAAM,QAAQ,CAAA;AACpE,CAAC","sourcesContent":["import type { LexErrorCode, LexErrorData, LexValue } from '@atproto/lex-data'\nimport { LexError } from '@atproto/lex-data'\nimport {\n LexValidationError,\n Procedure,\n Query,\n lexErrorDataSchema,\n} from '@atproto/lex-schema'\nimport type { InferMethodError, ResultFailure } from '@atproto/lex-schema'\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nimport type { Agent } from './agent.js'\nimport type { XrpcUnknownResponsePayload } from './types.js'\nimport type { WWWAuthenticate } from './www-authenticate.js'\nimport { parseWWWAuthenticateHeader } from './www-authenticate.js'\n\n/**\n * Mapping that allows generating an XRPC error code from an HTTP status code\n * when the response does not contain a valid XRPC error payload. This is used\n * to convert non-XRPC error responses from upstream servers into a standardized\n * XRPC error for downstream clients.\n */\nconst StatusErrorCodes = new Map<number, LexErrorCode>([\n [400, 'InvalidRequest'],\n [401, 'AuthenticationRequired'],\n [403, 'Forbidden'],\n [404, 'XRPCNotSupported'],\n [406, 'NotAcceptable'],\n [413, 'PayloadTooLarge'],\n [415, 'UnsupportedMediaType'],\n [429, 'RateLimitExceeded'],\n [500, 'InternalServerError'],\n [501, 'MethodNotImplemented'],\n [502, 'UpstreamFailure'],\n [503, 'NotEnoughResources'],\n [504, 'UpstreamTimeout'],\n])\n\nexport type { XrpcUnknownResponsePayload }\n\nexport type DownstreamError<N extends LexErrorCode = LexErrorCode> = {\n status: number\n headers?: Headers\n encoding?: 'application/json'\n body: LexErrorData<N>\n}\n\n/**\n * HTTP status codes that indicate a transient error that may succeed on retry.\n *\n * Includes:\n * - 408 Request Timeout\n * - 425 Too Early\n * - 429 Too Many Requests (rate limited)\n * - 500 Internal Server Error\n * - 502 Bad Gateway\n * - 503 Service Unavailable\n * - 504 Gateway Timeout\n * - 522 Connection Timed Out (Cloudflare)\n * - 524 A Timeout Occurred (Cloudflare)\n */\nexport const RETRYABLE_HTTP_STATUS_CODES: ReadonlySet<number> = new Set([\n 408, 425, 429, 500, 502, 503, 504, 522, 524,\n])\n\nexport { LexError }\nexport type { LexErrorCode, LexErrorData }\n\n/**\n * The payload structure for XRPC error responses.\n *\n * All XRPC errors return JSON with an `error` code and optional `message`.\n *\n * @typeParam N - The specific error code type\n */\nexport type XrpcErrorPayload<N extends LexErrorCode = LexErrorCode> = {\n body: LexErrorData<N>\n encoding: 'application/json'\n}\n\n/**\n * All unsuccessful responses should follow a standard error response\n * schema. The Content-Type should be application/json, and the payload\n * should be a JSON object with the following fields:\n *\n * - `error` (string, required): type name of the error (generic ASCII\n * constant, no whitespace)\n * - `message` (string, optional): description of the error, appropriate for\n * display to humans\n *\n * This function checks whether a given payload matches this schema.\n */\nexport function isXrpcErrorPayload(\n payload: XrpcUnknownResponsePayload | null | undefined,\n): payload is XrpcErrorPayload {\n return (\n payload != null &&\n payload.encoding === 'application/json' &&\n lexErrorDataSchema.matches(payload.body)\n )\n}\n\n/**\n * Abstract base class for all XRPC errors.\n *\n * Extends {@link LexError} and implements {@link ResultFailure} for use with\n * safe/result-based error handling patterns.\n *\n * @typeParam M - The XRPC method type (Procedure or Query)\n * @typeParam N - The error code type\n * @typeParam TReason - The reason type for ResultFailure\n *\n * @see {@link XrpcResponseError} - For valid XRPC error responses\n * @see {@link XrpcInvalidResponseError} - For invalid/unexpected responses\n * @see {@link XrpcInternalError} - For network/internal errors\n */\nexport abstract class XrpcError<\n M extends Procedure | Query = Procedure | Query,\n N extends LexErrorCode = LexErrorCode,\n TReason = unknown,\n >\n extends LexError<N>\n implements ResultFailure<TReason>\n{\n name = 'XrpcError'\n\n constructor(\n readonly method: M,\n error: N,\n message: string = `${error} Lexicon RPC error`,\n options?: ErrorOptions,\n ) {\n super(error, message, options)\n }\n\n /**\n * @see {@link ResultFailure.success}\n */\n readonly success = false as const\n\n /**\n * @see {@link ResultFailure.reason}\n */\n abstract readonly reason: TReason\n\n /**\n * Indicates whether the error is transient and can be retried.\n */\n abstract shouldRetry(): boolean\n\n abstract toDownstreamError(): DownstreamError\n\n matchesSchemaErrors(): this is XrpcError<M, InferMethodError<M>> {\n return this.method.errors?.includes(this.error) ?? false\n }\n}\n\n/**\n * Error class for valid XRPC error responses from the server.\n *\n * This represents a properly formatted XRPC error where the server returned\n * a non-2xx status with a valid JSON error payload containing `error` and\n * optional `message` fields.\n *\n * Use {@link matchesSchemaErrors} to check if the error matches the method's declared\n * error types for type-safe error handling.\n *\n * @typeParam M - The XRPC method type\n * @typeParam N - The error code type (inferred from method or generic)\n *\n * @example Handling specific errors\n * ```typescript\n * try {\n * await client.xrpc(someMethod, options)\n * } catch (err) {\n * if (err instanceof XrpcResponseError && err.error === 'RecordNotFound') {\n * // Handle not found case\n * }\n * }\n * ```\n */\nexport class XrpcResponseError<\n M extends Procedure | Query = Procedure | Query,\n> extends XrpcError<M, LexErrorCode, XrpcResponseError<M>> {\n name = 'XrpcResponseError'\n\n constructor(\n method: M,\n readonly response: Response,\n readonly payload?: XrpcUnknownResponsePayload,\n options?: ErrorOptions,\n ) {\n const { error, message } = isXrpcErrorPayload(payload)\n ? payload.body\n : {\n error:\n StatusErrorCodes.get(response.status) ??\n (response.status >= 500 ? 'UpstreamFailure' : 'InvalidRequest'),\n message: buildResponseOverviewMessage(response),\n }\n super(method, error, message, options)\n }\n\n override get reason(): this {\n return this\n }\n\n override shouldRetry(): boolean {\n return RETRYABLE_HTTP_STATUS_CODES.has(this.response.status)\n }\n\n override toJSON(): LexErrorData {\n // Return the original error payload if it's a valid XRPC error, otherwise\n // convert to an XRPC error format.\n const { payload } = this\n if (isXrpcErrorPayload(payload)) {\n return payload.body\n }\n\n return super.toJSON()\n }\n\n override toDownstreamError(): DownstreamError {\n const { status, headers } = this.response\n // If the upstream server returned a 500 error, we want to return a 502 Bad\n // Gateway to downstream clients, as the issue is with the upstream server,\n // not us. We still return the original error code and message in the body\n // for transparency, but we do not want to expose internal server errors\n // from the upstream server as-is to downstream clients.\n return {\n status: status === 500 ? 502 : status,\n headers: stripHopByHopHeaders(headers),\n body: this.toJSON(),\n }\n }\n\n get status(): number {\n return this.response.status\n }\n\n get headers(): Headers {\n return this.response.headers\n }\n\n get body(): undefined | Uint8Array | LexValue {\n return this.payload?.body\n }\n}\n\nexport type { WWWAuthenticate }\n\n/**\n * Error class for 401 Unauthorized XRPC responses.\n *\n * Extends {@link XrpcResponseError} with access to parsed WWW-Authenticate header\n * information, useful for implementing authentication flows.\n *\n * Authentication errors are never retryable as they require user intervention\n * (e.g., re-authentication, token refresh).\n *\n * @typeParam M - The XRPC method type\n * @typeParam N - The error code type\n *\n * @example Handling authentication errors\n * ```typescript\n * try {\n * await client.xrpc(someMethod, options)\n * } catch (err) {\n * if (err instanceof XrpcAuthenticationError) {\n * const { DPoP } = err.wwwAuthenticate\n * if (DPoP?.error === 'use_dpop_nonce') {\n * // Handle DPoP nonce requirement\n * }\n * }\n * }\n * ```\n */\nexport class XrpcAuthenticationError<\n M extends Procedure | Query = Procedure | Query,\n> extends XrpcResponseError<M> {\n name = 'XrpcAuthenticationError'\n\n override shouldRetry(): boolean {\n return false\n }\n\n #wwwAuthenticateCached?: WWWAuthenticate\n /**\n * Parsed WWW-Authenticate header from the response.\n * Contains authentication scheme parameters (e.g., Bearer realm, DPoP nonce).\n */\n get wwwAuthenticate(): WWWAuthenticate {\n return (this.#wwwAuthenticateCached ??=\n parseWWWAuthenticateHeader(\n this.response.headers.get('www-authenticate'),\n ) ?? {})\n }\n}\n\n/**\n * Error class for invalid or unprocessable XRPC responses from upstream servers.\n *\n * This occurs when the server returns a response that doesn't conform to the\n * XRPC protocol, such as:\n * - Missing or invalid Content-Type header\n * - Response body that doesn't match the method's output schema\n * - Non-JSON error responses\n * - Responses from non-XRPC endpoints\n *\n * The error code is always 'InvalidResponse' and maps to HTTP 502 Bad Gateway\n * when converted to a response. This should allow downstream clients to\n * determine at which boundary the error occurred.\n *\n * @typeParam M - The XRPC method type\n */\nexport class XrpcInvalidResponseError<\n M extends Procedure | Query = Procedure | Query,\n> extends XrpcError<M, 'InvalidResponse', XrpcInvalidResponseError<M>> {\n name = 'XrpcInvalidResponseError'\n\n constructor(\n method: M,\n readonly response: Response,\n readonly payload?: XrpcUnknownResponsePayload,\n message: string = buildResponseOverviewMessage(response),\n options?: ErrorOptions,\n ) {\n super(method, 'InvalidResponse', message, options)\n }\n\n override get reason(): this {\n return this\n }\n\n override shouldRetry(): boolean {\n return RETRYABLE_HTTP_STATUS_CODES.has(this.response.status)\n }\n\n override toDownstreamError(): DownstreamError {\n return { status: 502, body: this.toJSON() }\n }\n}\n\n/**\n * Error class for invalid XRPC responses that fail schema validation.\n *\n * This is a specific type of {@link XrpcInvalidResponseError} that indicates the\n * upstream server returned a response that was structurally valid but did not\n * conform to the expected schema for the method. This likely indicates a\n * mismatch between client and server versions or an issue with the server's\n * XRPC implementation.\n *\n * @typeParam M - The XRPC method type\n */\nexport class XrpcResponseValidationError<\n M extends Procedure | Query = Procedure | Query,\n> extends XrpcInvalidResponseError<M> {\n name = 'XrpcResponseValidationError'\n\n constructor(\n method: M,\n response: Response,\n payload: XrpcUnknownResponsePayload,\n readonly cause: LexValidationError,\n ) {\n super(\n method,\n response,\n payload,\n `Invalid response payload: ${cause.message}`,\n { cause },\n )\n }\n}\n\n/**\n * Error class for unexpected internal/client-side errors during XRPC requests.\n *\n * The error code is always 'InternalServerError' and these errors not\n * considered retryable as they stem from unforeseen issues in the\n * implementation.\n *\n * @typeParam M - The XRPC method type\n */\nexport class XrpcInternalError<\n M extends Procedure | Query = Procedure | Query,\n> extends XrpcError<M, 'InternalServerError', XrpcInternalError<M>> {\n name = 'XrpcInternalError'\n\n constructor(method: M, message?: string, options?: ErrorOptions) {\n super(\n method,\n 'InternalServerError',\n message ?? 'Unable to fulfill XRPC request',\n options,\n )\n }\n\n override get reason(): this {\n return this\n }\n\n override shouldRetry(): boolean {\n return false\n }\n\n override toJSON(): LexErrorData {\n // @NOTE Do not expose internal error details to downstream clients\n return { error: this.error, message: 'Internal Server Error' }\n }\n\n override toDownstreamError(): DownstreamError {\n return { status: 500, body: this.toJSON() }\n }\n}\n\n/**\n * Special case of XrpcInternalError that specifically represents errors thrown\n * by {@link Agent.fetchHandler} during the XRPC request. This includes:\n * - Network errors (connection refused, DNS failure)\n * - Request timeouts\n * - Request aborted via AbortSignal\n *\n * These errors are optimistically considered retryable, as many fetch errors\n * are transient and may succeed on retry.\n */\nexport class XrpcFetchError<\n M extends Procedure | Query = Procedure | Query,\n> extends XrpcInternalError<M> {\n name = 'XrpcFetchError'\n\n constructor(method: M, cause: unknown) {\n const message = cause instanceof Error ? cause.message : String(cause)\n super(method, `Unexpected fetchHandler() error: ${message}`, { cause })\n }\n\n override shouldRetry(): boolean {\n // Ideally, we would inspect the reason to determine if it's retryable (by\n // detecting network errors, timeouts, etc.). Since these cases are highly\n // platform-dependent, we optimistically assume all fetch errors are\n // transient and retryable.\n return true\n }\n\n override toJSON(): LexErrorData {\n // @NOTE Do not expose internal error details to downstream clients\n return { error: this.error, message: 'Failed to perform upstream request' }\n }\n\n override toDownstreamError(): DownstreamError {\n // While it might technically be a 500 error, we use 502 Bad Gateway here to\n // indicate that the error occurred while communicating with the upstream\n // server, allowing downstream clients to distinguish between errors in our\n // internal processing (500) and errors in the upstream server or network\n // (502).\n return { status: 502, body: this.toJSON() }\n }\n}\n\n/**\n * Union type of all possible XRPC failure types.\n *\n * Used as the return type for safe/non-throwing XRPC methods. Check the\n * `success` property to distinguish between success and failure:\n *\n * @typeParam M - The XRPC method type\n *\n * @example\n * ```typescript\n * const result = await client.xrpcSafe(someMethod, options)\n * if (result.success) {\n * console.log(result.body) // XrpcResponse\n * } else {\n * // result is XrpcFailure (XrpcResponseError | XrpcInvalidResponseError | XrpcInternalError)\n * console.error(result.error, result.message)\n * }\n * ```\n */\nexport type XrpcFailure<M extends Procedure | Query = Procedure | Query> =\n // The server returned a valid XRPC error response\n | XrpcResponseError<M>\n // The response was not a valid XRPC response, or it does not match the schema\n | XrpcInvalidResponseError<M>\n // Something went wrong (network error, etc.)\n | XrpcInternalError<M>\n\n/**\n * Converts an unknown error into an appropriate {@link XrpcFailure} type.\n *\n * If the error is already an XrpcFailure for the given method, returns it as-is.\n * Otherwise, wraps it in an {@link XrpcInternalError}.\n *\n * @param method - The XRPC method that was called\n * @param cause - The error to convert\n * @returns An XrpcFailure instance\n *\n * @example\n * ```typescript\n * try {\n * const response = await fetch(...)\n * // ... process response\n * } catch (err) {\n * return asXrpcFailure(method, err)\n * }\n * ```\n */\nexport function asXrpcFailure<M extends Procedure | Query>(\n method: M,\n cause: unknown,\n): XrpcFailure<M> {\n if (\n cause instanceof XrpcResponseError ||\n cause instanceof XrpcInvalidResponseError ||\n cause instanceof XrpcInternalError\n ) {\n if (cause.method === method) return cause\n }\n\n return new XrpcInternalError(method, undefined, { cause })\n}\n\nconst HOP_BY_HOP_HEADERS = new Set([\n 'connection',\n 'keep-alive',\n 'proxy-authenticate',\n 'proxy-authorization',\n 'te',\n 'trailer',\n 'transfer-encoding',\n 'upgrade',\n])\n\nfunction stripHopByHopHeaders(headers: Headers): Headers {\n const result = new Headers(headers)\n\n // Remove statically known hop-by-hop headers\n for (const name of HOP_BY_HOP_HEADERS) {\n result.delete(name)\n }\n\n // Remove headers listed in the \"Connection\" header\n const connection = headers.get('connection')\n if (connection) {\n for (const name of connection.split(',')) {\n result.delete(name.trim())\n }\n }\n\n // These are not actually hop-by-hop headers, but we remove them because the\n // upstream payload gets parsed and re-serialized, so content length and\n // encoding may no longer be accurate.\n result.delete('content-length')\n result.delete('content-encoding')\n\n return result\n}\n\nfunction buildResponseOverviewMessage(response: Response): string {\n if (response.status < 400) {\n return `Upstream server responded with an invalid status code (${response.status})`\n }\n\n return `Upstream server responded with a ${response.status} error`\n}\n"]}
@@ -1,5 +1,6 @@
1
- import { InferMethodOutputEncoding, InferOutput, LexValue, Payload, Procedure, Query, ResultSuccess, Validator } from '@atproto/lex-schema';
2
- import { EncodingString } from './types.js';
1
+ import type { InferMethodOutputEncoding, InferOutput, LexValue, ResultSuccess, Validator } from '@atproto/lex-schema';
2
+ import { Payload, Procedure, Query } from '@atproto/lex-schema';
3
+ import type { EncodingString } from './types.js';
3
4
  type InferEncodingType<TEncoding extends string> = TEncoding extends '*/*' ? EncodingString : TEncoding extends `${infer T extends string}/*` ? `${T}/${string}` : TEncoding;
4
5
  type InferBodyType<TEncoding extends string, TSchema> = TSchema extends Validator ? InferOutput<TSchema> : TEncoding extends `application/json` ? LexValue : Uint8Array;
5
6
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../src/response.ts"],"names":[],"mappings":"AACA,OAAO,EACL,yBAAyB,EACzB,WAAW,EACX,QAAQ,EACR,OAAO,EACP,SAAS,EACT,KAAK,EACL,aAAa,EACb,SAAS,EACV,MAAM,qBAAqB,CAAA;AAO5B,OAAO,EACL,cAAc,EAGf,MAAM,YAAY,CAAA;AAWnB,KAAK,iBAAiB,CAAC,SAAS,SAAS,MAAM,IAAI,SAAS,SAAS,KAAK,GACtE,cAAc,GACd,SAAS,SAAS,GAAG,MAAM,CAAC,SAAS,MAAM,IAAI,GAC7C,GAAG,CAAC,IAAI,MAAM,EAAE,GAChB,SAAS,CAAA;AAEf,KAAK,aAAa,CAChB,SAAS,SAAS,MAAM,EACxB,OAAO,IACL,OAAO,SAAS,SAAS,GACzB,WAAW,CAAC,OAAO,CAAC,GACpB,SAAS,SAAS,kBAAkB,GAClC,QAAQ,GACR,UAAU,CAAA;AAEhB;;;;;;;GAOG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,SAAS,GAAG,KAAK,IACtD,CAAC,CAAC,QAAQ,CAAC,SAAS,OAAO,CAAC,MAAM,SAAS,EAAE,MAA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AI,IAAI,CAEhB;IAED,YACW,MAAM,EAAE,CAAC,EACT,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,mBAAmB,CAAC,CAAC,CAAC,EACtC;IAEJ;;;OAGG;IACH,IAAI,QAAQ,YAEX;IAED;;;OAGG;IACH,IAAI,QAAQ,IACuB,yBAAyB,CAAC,CAAC,CAAC,CAC9D;IAED;;;;;;OAMG;IACH,IAAI,IAAI,IACuB,gBAAgB,CAAC,CAAC,CAAC,CACjD;IAED;;;;;;;OAOG;IACH,OAAa,iBAAiB,CAAC,KAAK,CAAC,CAAC,SAAS,SAAS,GAAG,KAAK,EAC9D,MAAM,EAAE,CAAC,EACT,QAAQ,EAAE,QAAQ,EAClB,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAiG1B;CACF"}
package/dist/response.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { jsonToLex } from '@atproto/lex-json';
2
+ import { Payload, Procedure, Query } from '@atproto/lex-schema';
2
3
  import { XrpcAuthenticationError, XrpcInvalidResponseError, XrpcResponseError, XrpcResponseValidationError, } from './errors.js';
3
- import { isEncodingString, } from './types.js';
4
+ import { isEncodingString } from './types.js';
4
5
  const CONTENT_TYPE_BINARY = 'application/octet-stream';
5
6
  const CONTENT_TYPE_JSON = 'application/json';
6
7
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"response.js","sourceRoot":"","sources":["../src/response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAW9D,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,iBAAiB,EACjB,2BAA2B,GAC5B,MAAM,aAAa,CAAA;AACpB,OAAO,EAGL,gBAAgB,GACjB,MAAM,YAAY,CAAA;AAEnB,MAAM,mBAAmB,GAAG,0BAA0B,CAAA;AACtD,MAAM,iBAAiB,GAAG,kBAAkB,CAAA;AA8F5C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D,OAAO,QAAQ,CAAC,CAAC,CAAC,IAAI,QAAQ,GAAG,CAAC,CAAC,CAAC,YAAY,CAAA;AAClD,CAAC","sourcesContent":["import { LexParseOptions, jsonToLex } from '@atproto/lex-json'\nimport {\n InferMethodOutputEncoding,\n InferOutput,\n LexValue,\n Payload,\n Procedure,\n Query,\n ResultSuccess,\n Validator,\n} from '@atproto/lex-schema'\nimport {\n XrpcAuthenticationError,\n XrpcInvalidResponseError,\n XrpcResponseError,\n XrpcResponseValidationError,\n} from './errors.js'\nimport {\n EncodingString,\n XrpcUnknownResponsePayload,\n isEncodingString,\n} from './types.js'\n\nconst CONTENT_TYPE_BINARY = 'application/octet-stream'\nconst CONTENT_TYPE_JSON = 'application/json'\n\n// @NOTE the output schema is used in \"parse\" mode (safeParse), which means that\n// defaults will be applied and coercions will be performed, so we need to use\n// InferOutput here to get the final parsed type, not Infer/InferInput. For this\n// reason, we cannot use InferMethodOutputBody and InferMethodOutput from\n// lex-schema here.\n\ntype InferEncodingType<TEncoding extends string> = TEncoding extends '*/*'\n ? EncodingString\n : TEncoding extends `${infer T extends string}/*`\n ? `${T}/${string}`\n : TEncoding\n\ntype InferBodyType<\n TEncoding extends string,\n TSchema,\n> = TSchema extends Validator\n ? InferOutput<TSchema>\n : TEncoding extends `application/json`\n ? LexValue\n : Uint8Array\n\n/**\n * The body type of an XRPC response, inferred from the method's output schema.\n *\n * For JSON responses, this is the parsed LexValue. For binary responses,\n * this is a Uint8Array.\n *\n * @typeParam M - The XRPC method type (Procedure or Query)\n */\nexport type XrpcResponseBody<M extends Procedure | Query> =\n M['output'] extends Payload<infer TEncoding, infer TSchema>\n ? TEncoding extends string\n ? InferBodyType<TEncoding, TSchema>\n : undefined | LexValue | Uint8Array\n : never\n\n/**\n * The full payload type of an XRPC response, including body and encoding.\n *\n * Returns `null` for methods that have no output.\n *\n * @typeParam M - The XRPC method type (Procedure or Query)\n */\nexport type XrpcResponsePayload<M extends Procedure | Query> =\n M['output'] extends Payload<infer TEncoding, infer TSchema>\n ? TEncoding extends string\n ? {\n encoding: InferEncodingType<TEncoding>\n body: InferBodyType<TEncoding, TSchema>\n }\n : // If the schema does not specify an output encoding, anything could be\n // returned, including no payload at all (undefined).\n undefined | { body: LexValue | Uint8Array; encoding: string }\n : never\n\nexport type XrpcResponseOptions = {\n /**\n * Whether to validate the response against the method's output schema.\n * Disabling this can improve performance but may lead to runtime errors if\n * the response does not conform to the expected schema. Only set this to\n * `false` if you are certain that the upstream service will always return\n * valid responses.\n *\n * @default true\n */\n validateResponse?: boolean\n\n /**\n * Whether to strictly process response payloads according to Lex encoding\n * rules. By default, the client will reject responses with invalid Lex data\n * (floats and invalid $bytes / $link objects).\n *\n * Setting this option to `false` will allow the client to accept such\n * responses in a non-strict mode, where invalid Lex data will be returned\n * as-is (e.g., floats will not be rejected, and invalid $bytes / $link\n * objects will not be converted to Uint8Array / Cid). When in non-strict\n * mode, the validation will also be relaxed when validating the response\n * against the method's output schema, allowing values that do not strictly\n * conform to the schema (e.g. datetime strings that are not valid RFC3339\n * format, blobs that are not of the right size/mime-type, etc.) to be\n * accepted as long as their basic structure is correct.\n *\n * When validation is enabled (the default), the values defined through the\n * method schema will be enforced, ensuring that the client can still process\n * the response even if the server returns invalid Lex data.\n *\n * @default true\n * @see {@link LexParseOptions.strict}\n */\n strictResponseProcessing?: boolean\n}\n\n/**\n * Small container for XRPC response.\n *\n * @implements {ResultSuccess<XrpcResponse<M>>} for convenience in result handling contexts.\n *\n * @example\n *\n * ```typescript\n * import { app } from '#/lexicons'\n * import { XrpcResponse } from '@atproto/lex-client'\n *\n * const fetchResponse = await fetch('https://example.com/xrpc/app.bsky.feed.getTimeline')\n *\n * const response = await XrpcResponse.fromFetchResponse(\n * app.bsky.feed.getTimeline.main,\n * fetchResponse,\n * )\n *\n * // Fully typed (validated) response body, according to the method's output schema\n * const { cursor, feed } = response.body\n * ```\n */\nexport class XrpcResponse<M extends Procedure | Query>\n implements ResultSuccess<XrpcResponse<M>>\n{\n /** @see {@link ResultSuccess.success} */\n readonly success = true as const\n\n /** @see {@link ResultSuccess.value} */\n get value(): this {\n return this\n }\n\n constructor(\n readonly method: M,\n readonly status: number,\n readonly headers: Headers,\n readonly payload: XrpcResponsePayload<M>,\n ) {}\n\n /**\n * Whether the response payload was parsed as {@link LexValue} (`true`) or is\n * in binary form {@link Uint8Array} (`false`).\n */\n get isParsed() {\n return this.method.output.encoding === CONTENT_TYPE_JSON\n }\n\n /**\n * The Content-Type encoding of the response (e.g., 'application/json').\n * Returns `undefined` if the response has no body.\n */\n get encoding() {\n return this.payload?.encoding as InferMethodOutputEncoding<M>\n }\n\n /**\n * The parsed response body.\n *\n * For 'application/json' responses, this is the parsed and validated LexValue.\n * For binary responses, this is a Uint8Array.\n * Returns `undefined` if the response has no body.\n */\n get body() {\n return this.payload?.body as XrpcResponseBody<M>\n }\n\n /**\n * @throws {XrpcResponseError} in case of (valid) XRPC error responses. Use\n * {@link XrpcResponseError.matchesSchemaErrors} to narrow the error type based on\n * the method's declared error schema. This can be narrowed further as a\n * {@link XrpcAuthenticationError} if the error is an authentication error.\n * @throws {XrpcInvalidResponseError} when the response is not a valid XRPC\n * response, or if the response does not conform to the method's schema.\n */\n static async fromFetchResponse<const M extends Procedure | Query>(\n method: M,\n response: Response,\n options?: XrpcResponseOptions,\n ): Promise<XrpcResponse<M>> {\n // @NOTE The body MUST either be read or canceled to avoid resource leaks.\n // Since nothing should cause an exception before \"readPayload\" is\n // called, we can safely not use a try/finally here.\n\n // Always turn 4xx/5xx responses into XrpcResponseError\n if (response.status >= 400) {\n const payload = await readPayload(method, response, {\n // Always parse errors in non-strict mode\n parse: { strict: false },\n })\n\n if (response.status === 401) {\n throw new XrpcAuthenticationError<M>(method, response, payload)\n }\n\n throw new XrpcResponseError<M>(method, response, payload)\n }\n\n // @NOTE redirect is set to 'follow', so we shouldn't get 3xx responses here\n if (response.status < 200 || response.status >= 300) {\n await response.body?.cancel()\n\n throw new XrpcInvalidResponseError(\n method,\n response,\n undefined,\n `Unexpected status code ${response.status}`,\n )\n }\n\n const payload = await readPayload(method, response, {\n // Parse response if there is a schema, or if the encoding is\n // \"application/json\"\n parse:\n method.output.schema || method.output.encoding === CONTENT_TYPE_JSON\n ? { strict: options?.strictResponseProcessing ?? true }\n : // If there is no declared output encoding, we'll parse the output (in loose mode)\n method.output.encoding == null\n ? { strict: false }\n : false,\n })\n\n if (!method.output.matchesEncoding(payload?.encoding)) {\n throw new XrpcInvalidResponseError(\n method,\n response,\n payload,\n `Expected ${stringifyEncoding(method.output.encoding)} response (got ${stringifyEncoding(payload?.encoding)})`,\n )\n }\n\n // Response is successful (2xx). Validate payload (data and encoding) against schema.\n if (method.output.encoding != null) {\n // If the schema specifies an output, verify that the response properly\n // matches the expected format (encoding and schema, if present). If no\n // output is specified, any payload could be returned.\n\n // Needed for type safety. Should never happen since matchesEncoding()\n // should return not succeed if there is a schema encoding but no payload.\n if (!payload) throw new Error('Expected payload')\n\n // Assert valid response body.\n if (method.output.schema && options?.validateResponse !== false) {\n const result = method.output.schema.safeParse(payload.body, {\n strict: options?.strictResponseProcessing ?? true,\n })\n\n if (!result.success) {\n throw new XrpcResponseValidationError(\n method,\n response,\n payload,\n result.reason,\n )\n }\n\n const parsedPayload = {\n body: result.value,\n encoding: payload.encoding,\n } as XrpcResponsePayload<M>\n\n return new XrpcResponse<M>(\n method,\n response.status,\n response.headers,\n parsedPayload,\n )\n }\n }\n\n return new XrpcResponse<M>(\n method,\n response.status,\n response.headers,\n payload as XrpcResponsePayload<M>,\n )\n }\n}\n\ntype ReadPayloadOptions = {\n /**\n * Whether to parse the response body as JSON and convert it to LexValue.\n *\n * @default false\n */\n parse?: false | LexParseOptions\n}\n\n/**\n * @note this function always consumes the response body\n */\nasync function readPayload(\n method: Query | Procedure,\n response: Response,\n options?: ReadPayloadOptions,\n): Promise<undefined | XrpcUnknownResponsePayload> {\n try {\n // @TODO Should we limit the maximum response size here (this could also be\n // done by the FetchHandler)?\n\n const encoding = response.headers\n .get('content-type')\n ?.split(';')[0]\n .trim()\n .toLowerCase()\n\n // Response content-type is undefined\n if (!encoding) {\n // If the body is empty, return undefined (= no payload)\n const arrayBuffer = await response.arrayBuffer()\n if (arrayBuffer.byteLength === 0) return undefined\n\n // If we got data despite no content-type, treat it as binary\n return {\n encoding: CONTENT_TYPE_BINARY,\n body: new Uint8Array(arrayBuffer),\n }\n }\n\n if (!isEncodingString(encoding)) {\n throw new TypeError(`Invalid content-type \"${encoding}\" in response`)\n }\n\n if (options?.parse && encoding === CONTENT_TYPE_JSON) {\n // @NOTE See ./response.bench.ts to comparison of different parsing approaches.\n const json = await response.json()\n const body = jsonToLex(json, options.parse)\n return { encoding, body }\n }\n\n const arrayBuffer = await response.arrayBuffer()\n return { encoding, body: new Uint8Array(arrayBuffer) }\n } catch (cause) {\n const message = 'Unable to parse response payload'\n const messageDetail = cause instanceof TypeError ? cause.message : undefined\n throw new XrpcInvalidResponseError(\n method,\n response,\n undefined,\n messageDetail ? `${message}: ${messageDetail}` : message,\n { cause },\n )\n }\n}\n\nfunction stringifyEncoding(encoding: string | undefined) {\n return encoding ? `\"${encoding}\"` : 'no payload'\n}\n"]}
1
+ {"version":3,"file":"response.js","sourceRoot":"","sources":["../src/response.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAQ7C,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC/D,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,iBAAiB,EACjB,2BAA2B,GAC5B,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAG7C,MAAM,mBAAmB,GAAG,0BAA0B,CAAA;AACtD,MAAM,iBAAiB,GAAG,kBAAkB,CAAA;AA8F5C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,YAAY;IAMvB,uCAAuC;IACvC,IAAI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;AAClD,CAAC","sourcesContent":["import type { LexParseOptions } from '@atproto/lex-json'\nimport { jsonToLex } from '@atproto/lex-json'\nimport type {\n InferMethodOutputEncoding,\n InferOutput,\n LexValue,\n ResultSuccess,\n Validator,\n} from '@atproto/lex-schema'\nimport { Payload, Procedure, Query } from '@atproto/lex-schema'\nimport {\n XrpcAuthenticationError,\n XrpcInvalidResponseError,\n XrpcResponseError,\n XrpcResponseValidationError,\n} from './errors.js'\nimport { isEncodingString } from './types.js'\nimport type { EncodingString, XrpcUnknownResponsePayload } from './types.js'\n\nconst CONTENT_TYPE_BINARY = 'application/octet-stream'\nconst CONTENT_TYPE_JSON = 'application/json'\n\n// @NOTE the output schema is used in \"parse\" mode (safeParse), which means that\n// defaults will be applied and coercions will be performed, so we need to use\n// InferOutput here to get the final parsed type, not Infer/InferInput. For this\n// reason, we cannot use InferMethodOutputBody and InferMethodOutput from\n// lex-schema here.\n\ntype InferEncodingType<TEncoding extends string> = TEncoding extends '*/*'\n ? EncodingString\n : TEncoding extends `${infer T extends string}/*`\n ? `${T}/${string}`\n : TEncoding\n\ntype InferBodyType<\n TEncoding extends string,\n TSchema,\n> = TSchema extends Validator\n ? InferOutput<TSchema>\n : TEncoding extends `application/json`\n ? LexValue\n : Uint8Array\n\n/**\n * The body type of an XRPC response, inferred from the method's output schema.\n *\n * For JSON responses, this is the parsed LexValue. For binary responses,\n * this is a Uint8Array.\n *\n * @typeParam M - The XRPC method type (Procedure or Query)\n */\nexport type XrpcResponseBody<M extends Procedure | Query> =\n M['output'] extends Payload<infer TEncoding, infer TSchema>\n ? TEncoding extends string\n ? InferBodyType<TEncoding, TSchema>\n : undefined | LexValue | Uint8Array\n : never\n\n/**\n * The full payload type of an XRPC response, including body and encoding.\n *\n * Returns `null` for methods that have no output.\n *\n * @typeParam M - The XRPC method type (Procedure or Query)\n */\nexport type XrpcResponsePayload<M extends Procedure | Query> =\n M['output'] extends Payload<infer TEncoding, infer TSchema>\n ? TEncoding extends string\n ? {\n encoding: InferEncodingType<TEncoding>\n body: InferBodyType<TEncoding, TSchema>\n }\n : // If the schema does not specify an output encoding, anything could be\n // returned, including no payload at all (undefined).\n undefined | { body: LexValue | Uint8Array; encoding: string }\n : never\n\nexport type XrpcResponseOptions = {\n /**\n * Whether to validate the response against the method's output schema.\n * Disabling this can improve performance but may lead to runtime errors if\n * the response does not conform to the expected schema. Only set this to\n * `false` if you are certain that the upstream service will always return\n * valid responses.\n *\n * @default true\n */\n validateResponse?: boolean\n\n /**\n * Whether to strictly process response payloads according to Lex encoding\n * rules. By default, the client will reject responses with invalid Lex data\n * (floats and invalid $bytes / $link objects).\n *\n * Setting this option to `false` will allow the client to accept such\n * responses in a non-strict mode, where invalid Lex data will be returned\n * as-is (e.g., floats will not be rejected, and invalid $bytes / $link\n * objects will not be converted to Uint8Array / Cid). When in non-strict\n * mode, the validation will also be relaxed when validating the response\n * against the method's output schema, allowing values that do not strictly\n * conform to the schema (e.g. datetime strings that are not valid RFC3339\n * format, blobs that are not of the right size/mime-type, etc.) to be\n * accepted as long as their basic structure is correct.\n *\n * When validation is enabled (the default), the values defined through the\n * method schema will be enforced, ensuring that the client can still process\n * the response even if the server returns invalid Lex data.\n *\n * @default true\n * @see {@link LexParseOptions.strict}\n */\n strictResponseProcessing?: boolean\n}\n\n/**\n * Small container for XRPC response.\n *\n * @implements {ResultSuccess<XrpcResponse<M>>} for convenience in result handling contexts.\n *\n * @example\n *\n * ```typescript\n * import { app } from '#/lexicons'\n * import { XrpcResponse } from '@atproto/lex-client'\n *\n * const fetchResponse = await fetch('https://example.com/xrpc/app.bsky.feed.getTimeline')\n *\n * const response = await XrpcResponse.fromFetchResponse(\n * app.bsky.feed.getTimeline.main,\n * fetchResponse,\n * )\n *\n * // Fully typed (validated) response body, according to the method's output schema\n * const { cursor, feed } = response.body\n * ```\n */\nexport class XrpcResponse<M extends Procedure | Query>\n implements ResultSuccess<XrpcResponse<M>>\n{\n /** @see {@link ResultSuccess.success} */\n readonly success = true as const\n\n /** @see {@link ResultSuccess.value} */\n get value(): this {\n return this\n }\n\n constructor(\n readonly method: M,\n readonly status: number,\n readonly headers: Headers,\n readonly payload: XrpcResponsePayload<M>,\n ) {}\n\n /**\n * Whether the response payload was parsed as {@link LexValue} (`true`) or is\n * in binary form {@link Uint8Array} (`false`).\n */\n get isParsed() {\n return this.method.output.encoding === CONTENT_TYPE_JSON\n }\n\n /**\n * The Content-Type encoding of the response (e.g., 'application/json').\n * Returns `undefined` if the response has no body.\n */\n get encoding() {\n return this.payload?.encoding as InferMethodOutputEncoding<M>\n }\n\n /**\n * The parsed response body.\n *\n * For 'application/json' responses, this is the parsed and validated LexValue.\n * For binary responses, this is a Uint8Array.\n * Returns `undefined` if the response has no body.\n */\n get body() {\n return this.payload?.body as XrpcResponseBody<M>\n }\n\n /**\n * @throws {XrpcResponseError} in case of (valid) XRPC error responses. Use\n * {@link XrpcResponseError.matchesSchemaErrors} to narrow the error type based on\n * the method's declared error schema. This can be narrowed further as a\n * {@link XrpcAuthenticationError} if the error is an authentication error.\n * @throws {XrpcInvalidResponseError} when the response is not a valid XRPC\n * response, or if the response does not conform to the method's schema.\n */\n static async fromFetchResponse<const M extends Procedure | Query>(\n method: M,\n response: Response,\n options?: XrpcResponseOptions,\n ): Promise<XrpcResponse<M>> {\n // @NOTE The body MUST either be read or canceled to avoid resource leaks.\n // Since nothing should cause an exception before \"readPayload\" is\n // called, we can safely not use a try/finally here.\n\n // Always turn 4xx/5xx responses into XrpcResponseError\n if (response.status >= 400) {\n const payload = await readPayload(method, response, {\n // Always parse errors in non-strict mode\n parse: { strict: false },\n })\n\n if (response.status === 401) {\n throw new XrpcAuthenticationError<M>(method, response, payload)\n }\n\n throw new XrpcResponseError<M>(method, response, payload)\n }\n\n // @NOTE redirect is set to 'follow', so we shouldn't get 3xx responses here\n if (response.status < 200 || response.status >= 300) {\n await response.body?.cancel()\n\n throw new XrpcInvalidResponseError(\n method,\n response,\n undefined,\n `Unexpected status code ${response.status}`,\n )\n }\n\n const payload = await readPayload(method, response, {\n // Parse response if there is a schema, or if the encoding is\n // \"application/json\"\n parse:\n method.output.schema || method.output.encoding === CONTENT_TYPE_JSON\n ? { strict: options?.strictResponseProcessing ?? true }\n : // If there is no declared output encoding, we'll parse the output (in loose mode)\n method.output.encoding == null\n ? { strict: false }\n : false,\n })\n\n if (!method.output.matchesEncoding(payload?.encoding)) {\n throw new XrpcInvalidResponseError(\n method,\n response,\n payload,\n `Expected ${stringifyEncoding(method.output.encoding)} response (got ${stringifyEncoding(payload?.encoding)})`,\n )\n }\n\n // Response is successful (2xx). Validate payload (data and encoding) against schema.\n if (method.output.encoding != null) {\n // If the schema specifies an output, verify that the response properly\n // matches the expected format (encoding and schema, if present). If no\n // output is specified, any payload could be returned.\n\n // Needed for type safety. Should never happen since matchesEncoding()\n // should return not succeed if there is a schema encoding but no payload.\n if (!payload) throw new Error('Expected payload')\n\n // Assert valid response body.\n if (method.output.schema && options?.validateResponse !== false) {\n const result = method.output.schema.safeParse(payload.body, {\n strict: options?.strictResponseProcessing ?? true,\n })\n\n if (!result.success) {\n throw new XrpcResponseValidationError(\n method,\n response,\n payload,\n result.reason,\n )\n }\n\n const parsedPayload = {\n body: result.value,\n encoding: payload.encoding,\n } as XrpcResponsePayload<M>\n\n return new XrpcResponse<M>(\n method,\n response.status,\n response.headers,\n parsedPayload,\n )\n }\n }\n\n return new XrpcResponse<M>(\n method,\n response.status,\n response.headers,\n payload as XrpcResponsePayload<M>,\n )\n }\n}\n\ntype ReadPayloadOptions = {\n /**\n * Whether to parse the response body as JSON and convert it to LexValue.\n *\n * @default false\n */\n parse?: false | LexParseOptions\n}\n\n/**\n * @note this function always consumes the response body\n */\nasync function readPayload(\n method: Query | Procedure,\n response: Response,\n options?: ReadPayloadOptions,\n): Promise<undefined | XrpcUnknownResponsePayload> {\n try {\n // @TODO Should we limit the maximum response size here (this could also be\n // done by the FetchHandler)?\n\n const encoding = response.headers\n .get('content-type')\n ?.split(';')[0]\n .trim()\n .toLowerCase()\n\n // Response content-type is undefined\n if (!encoding) {\n // If the body is empty, return undefined (= no payload)\n const arrayBuffer = await response.arrayBuffer()\n if (arrayBuffer.byteLength === 0) return undefined\n\n // If we got data despite no content-type, treat it as binary\n return {\n encoding: CONTENT_TYPE_BINARY,\n body: new Uint8Array(arrayBuffer),\n }\n }\n\n if (!isEncodingString(encoding)) {\n throw new TypeError(`Invalid content-type \"${encoding}\" in response`)\n }\n\n if (options?.parse && encoding === CONTENT_TYPE_JSON) {\n // @NOTE See ./response.bench.ts to comparison of different parsing approaches.\n const json = await response.json()\n const body = jsonToLex(json, options.parse)\n return { encoding, body }\n }\n\n const arrayBuffer = await response.arrayBuffer()\n return { encoding, body: new Uint8Array(arrayBuffer) }\n } catch (cause) {\n const message = 'Unable to parse response payload'\n const messageDetail = cause instanceof TypeError ? cause.message : undefined\n throw new XrpcInvalidResponseError(\n method,\n response,\n undefined,\n messageDetail ? `${message}: ${messageDetail}` : message,\n { cause },\n )\n }\n}\n\nfunction stringifyEncoding(encoding: string | undefined) {\n return encoding ? `\"${encoding}\"` : 'no payload'\n}\n"]}
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { DidString, LexValue, UnknownString } from '@atproto/lex-schema';
1
+ import type { DidString, LexValue, UnknownString } from '@atproto/lex-schema';
2
2
  export type { DidString, LexValue, UnknownString };
3
3
  /**
4
4
  * Service identifier fragment for DID service endpoints.
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAExE,YAAY,EAAE,SAAS,EAAE,QAAQ,EAAE,aAAa,EAAE,CAAA;AAElD;;;;;GAKG;AACH,MAAM,MAAM,oBAAoB,GAAG,iBAAiB,GAAG,aAAa,CAAA;AAEpE;;;;;;;;;GASG;AACH,MAAM,MAAM,OAAO,GAAG,GAAG,SAAS,IA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AAO,SAAS,cAAc,GAAG,UAAU,IACzC;IACF,QAAQ,EAAE,cAAc,CAAA;IACxB,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAA;CACzB,CAAA"}
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AA2DA,MAAM,UAAU,gBAAgB,CAC9B,WAAmB;IAEnB,OAAO,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;AAClC,CAAC","sourcesContent":["import { DidString, LexValue, UnknownString } from '@atproto/lex-schema'\n\nexport type { DidString, LexValue, UnknownString }\n\n/**\n * Service identifier fragment for DID service endpoints.\n *\n * Common values include 'atproto_labeler' for labeling services,\n * or custom service identifiers.\n */\nexport type DidServiceIdentifier = 'atproto_labeler' | UnknownString\n\n/**\n * A full service proxy identifier combining a DID with a service fragment.\n *\n * Used to route requests through a specific service endpoint.\n *\n * @example\n * ```typescript\n * const service: Service = 'did:web:api.bsky.app#bsky_appview'\n * ```\n */\nexport type Service = `${DidString}#${DidServiceIdentifier}`\n\n/**\n * Valid input types for binary request bodies.\n *\n * These types can be used as the body for procedures that expect\n * non-JSON content (e.g., blob uploads, binary data).\n *\n * @example Uploading a blob\n * ```typescript\n * const imageData: BinaryBodyInit = new Uint8Array(buffer)\n * await client.uploadBlob(imageData, { encoding: 'image/png' })\n * ```\n *\n * @example Streaming upload\n * ```typescript\n * const stream: BinaryBodyInit = someReadableStream\n * await client.xrpc(uploadMethod, { body: stream })\n * ```\n *\n * @example File upload in browser\n * ```typescript\n * const fileInput = document.querySelector('input[type=\"file\"]') as HTMLInputElement\n * const file: BinaryBodyInit = fileInput.files[0]\n * await client.xrpc(uploadMethod, { body: file })\n * ```\n */\nexport type BinaryBodyInit =\n | string\n | Blob\n | Uint8Array\n | ArrayBuffer\n | ReadableStream<Uint8Array>\n | AsyncIterable<Uint8Array>\n\nexport type EncodingString = `${string}/${string}`\n\nexport function isEncodingString(\n contentType: string,\n): contentType is EncodingString {\n return contentType.includes('/')\n}\n\nexport type XrpcUnknownResponsePayload<\n TBinary extends BinaryBodyInit = Uint8Array,\n> = {\n encoding: EncodingString\n body: LexValue | TBinary\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AA2DA,MAAM,UAAU,gBAAgB,CAC9B,WAAmB;IAEnB,OAAO,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;AAClC,CAAC","sourcesContent":["import type { DidString, LexValue, UnknownString } from '@atproto/lex-schema'\n\nexport type { DidString, LexValue, UnknownString }\n\n/**\n * Service identifier fragment for DID service endpoints.\n *\n * Common values include 'atproto_labeler' for labeling services,\n * or custom service identifiers.\n */\nexport type DidServiceIdentifier = 'atproto_labeler' | UnknownString\n\n/**\n * A full service proxy identifier combining a DID with a service fragment.\n *\n * Used to route requests through a specific service endpoint.\n *\n * @example\n * ```typescript\n * const service: Service = 'did:web:api.bsky.app#bsky_appview'\n * ```\n */\nexport type Service = `${DidString}#${DidServiceIdentifier}`\n\n/**\n * Valid input types for binary request bodies.\n *\n * These types can be used as the body for procedures that expect\n * non-JSON content (e.g., blob uploads, binary data).\n *\n * @example Uploading a blob\n * ```typescript\n * const imageData: BinaryBodyInit = new Uint8Array(buffer)\n * await client.uploadBlob(imageData, { encoding: 'image/png' })\n * ```\n *\n * @example Streaming upload\n * ```typescript\n * const stream: BinaryBodyInit = someReadableStream\n * await client.xrpc(uploadMethod, { body: stream })\n * ```\n *\n * @example File upload in browser\n * ```typescript\n * const fileInput = document.querySelector('input[type=\"file\"]') as HTMLInputElement\n * const file: BinaryBodyInit = fileInput.files[0]\n * await client.xrpc(uploadMethod, { body: file })\n * ```\n */\nexport type BinaryBodyInit =\n | string\n | Blob\n | Uint8Array\n | ArrayBuffer\n | ReadableStream<Uint8Array>\n | AsyncIterable<Uint8Array>\n\nexport type EncodingString = `${string}/${string}`\n\nexport function isEncodingString(\n contentType: string,\n): contentType is EncodingString {\n return contentType.includes('/')\n}\n\nexport type XrpcUnknownResponsePayload<\n TBinary extends BinaryBodyInit = Uint8Array,\n> = {\n encoding: EncodingString\n body: LexValue | TBinary\n}\n"]}
package/dist/util.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { InferRecordKey, LexiconRecordKey, RecordSchema } from '@atproto/lex-schema';
2
- import type { DidString, Service } from './types.js';
1
+ import type { InferRecordKey, LexiconRecordKey } from '@atproto/lex-schema';
2
+ import { RecordSchema } from '@atproto/lex-schema';
3
+ import type { DidString, Service } from './types.ts';
3
4
  export declare function applyDefaults<TDefaults extends Record<string, unknown>, TOptions extends {
4
5
  [K in keyof TDefaults]?: TDefaults[K];
5
6
  }>(options: TOptions, defaults: TDefaults): TOptions & TDefaults;
@@ -43,4 +44,7 @@ export type RecordKeyOptions<T extends RecordSchema, AlsoOptionalWhenRecordKeyIs
43
44
  };
44
45
  export declare function getDefaultRecordKey<const T extends RecordSchema>(schema: T): undefined | InferRecordKey<T>;
45
46
  export declare function getLiteralRecordKey<const T extends RecordSchema>(schema: T): InferRecordKey<T>;
47
+ export declare function wait(ms: number, { signal }?: {
48
+ signal?: AbortSignal;
49
+ }): Promise<void>;
46
50
  //# sourceMappingURL=util.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,YAAY,EACb,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEpD,wBAAgB,aAAa,CAC3B,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACzC,QAAQ,SAAS;KACd,CAAC,IAAI,MAAM,SAAS,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC;CACtC,EACD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,GAAG,Q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