@atproto/lex-client 0.0.11 → 0.0.13
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.
- package/CHANGELOG.md +26 -0
- package/dist/agent.d.ts +67 -0
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +31 -0
- package/dist/agent.js.map +1 -1
- package/dist/client.d.ts +443 -45
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +145 -1
- package/dist/client.js.map +1 -1
- package/dist/errors.d.ts +162 -9
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +132 -8
- package/dist/errors.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/createRecord.defs.d.ts +29 -25
- package/dist/lexicons/com/atproto/repo/createRecord.defs.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/repo/createRecord.defs.js +3 -2
- package/dist/lexicons/com/atproto/repo/createRecord.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/deleteRecord.defs.d.ts +17 -17
- package/dist/lexicons/com/atproto/repo/deleteRecord.defs.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/repo/deleteRecord.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/getRecord.defs.d.ts +9 -9
- package/dist/lexicons/com/atproto/repo/getRecord.defs.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/repo/getRecord.defs.js +1 -1
- package/dist/lexicons/com/atproto/repo/getRecord.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/listRecords.defs.d.ts +8 -8
- package/dist/lexicons/com/atproto/repo/listRecords.defs.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/repo/listRecords.defs.js +1 -1
- package/dist/lexicons/com/atproto/repo/listRecords.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/putRecord.defs.d.ts +31 -27
- package/dist/lexicons/com/atproto/repo/putRecord.defs.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/repo/putRecord.defs.js +3 -2
- package/dist/lexicons/com/atproto/repo/putRecord.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/uploadBlob.defs.d.ts +7 -7
- package/dist/lexicons/com/atproto/repo/uploadBlob.defs.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/repo/uploadBlob.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/sync/getBlob.defs.d.ts +3 -3
- package/dist/lexicons/com/atproto/sync/getBlob.defs.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/sync/getBlob.defs.js.map +1 -1
- package/dist/response.d.ts +14 -4
- package/dist/response.d.ts.map +1 -1
- package/dist/response.js +19 -9
- package/dist/response.js.map +1 -1
- package/dist/types.d.ts +51 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/util.d.ts +40 -5
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +22 -0
- package/dist/util.js.map +1 -1
- package/dist/www-authenticate.d.ts +23 -0
- package/dist/www-authenticate.d.ts.map +1 -1
- package/dist/www-authenticate.js.map +1 -1
- package/dist/xrpc.d.ts +81 -1
- package/dist/xrpc.d.ts.map +1 -1
- package/dist/xrpc.js.map +1 -1
- package/package.json +7 -7
- package/src/agent.ts +67 -0
- package/src/client.ts +424 -11
- package/src/errors.ts +165 -12
- package/src/lexicons/com/atproto/repo/createRecord.defs.ts +15 -7
- package/src/lexicons/com/atproto/repo/deleteRecord.defs.ts +11 -5
- package/src/lexicons/com/atproto/repo/getRecord.defs.ts +7 -4
- package/src/lexicons/com/atproto/repo/listRecords.defs.ts +8 -5
- package/src/lexicons/com/atproto/repo/putRecord.defs.ts +15 -7
- package/src/lexicons/com/atproto/repo/uploadBlob.defs.ts +11 -5
- package/src/lexicons/com/atproto/sync/getBlob.defs.ts +6 -3
- package/src/response.ts +22 -19
- package/src/types.ts +52 -0
- package/src/util.ts +50 -5
- package/src/www-authenticate.ts +24 -0
- package/src/xrpc.ts +83 -4
package/dist/errors.d.ts
CHANGED
|
@@ -1,11 +1,35 @@
|
|
|
1
1
|
import { LexError, LexErrorCode, LexErrorData } from '@atproto/lex-data';
|
|
2
2
|
import { InferMethodError, Procedure, Query, ResultFailure } from '@atproto/lex-schema';
|
|
3
|
-
import {
|
|
3
|
+
import { XrpcResponsePayload } from './util.js';
|
|
4
4
|
import { WWWAuthenticate } from './www-authenticate.js';
|
|
5
|
+
/**
|
|
6
|
+
* HTTP status codes that indicate a transient error that may succeed on retry.
|
|
7
|
+
*
|
|
8
|
+
* Includes:
|
|
9
|
+
* - 408 Request Timeout
|
|
10
|
+
* - 425 Too Early
|
|
11
|
+
* - 429 Too Many Requests (rate limited)
|
|
12
|
+
* - 500 Internal Server Error
|
|
13
|
+
* - 502 Bad Gateway
|
|
14
|
+
* - 503 Service Unavailable
|
|
15
|
+
* - 504 Gateway Timeout
|
|
16
|
+
* - 522 Connection Timed Out (Cloudflare)
|
|
17
|
+
* - 524 A Timeout Occurred (Cloudflare)
|
|
18
|
+
*/
|
|
5
19
|
export declare const RETRYABLE_HTTP_STATUS_CODES: ReadonlySet<number>;
|
|
6
20
|
export { LexError };
|
|
7
21
|
export type { LexErrorCode, LexErrorData };
|
|
8
|
-
|
|
22
|
+
/**
|
|
23
|
+
* The payload structure for XRPC error responses.
|
|
24
|
+
*
|
|
25
|
+
* All XRPC errors return JSON with an `error` code and optional `message`.
|
|
26
|
+
*
|
|
27
|
+
* @typeParam N - The specific error code type
|
|
28
|
+
*/
|
|
29
|
+
export type XrpcErrorPayload<N extends LexErrorCode = LexErrorCode> = {
|
|
30
|
+
body: LexErrorData<N>;
|
|
31
|
+
encoding: 'application/json';
|
|
32
|
+
};
|
|
9
33
|
/**
|
|
10
34
|
* All unsuccessful responses should follow a standard error response
|
|
11
35
|
* schema. The Content-Type should be application/json, and the payload
|
|
@@ -18,7 +42,21 @@ export type XrpcErrorPayload<N extends LexErrorCode = LexErrorCode> = XrpcPayloa
|
|
|
18
42
|
*
|
|
19
43
|
* This function checks whether a given payload matches this schema.
|
|
20
44
|
*/
|
|
21
|
-
export declare function isXrpcErrorPayload(payload:
|
|
45
|
+
export declare function isXrpcErrorPayload(payload: XrpcResponsePayload | null | undefined): payload is XrpcErrorPayload;
|
|
46
|
+
/**
|
|
47
|
+
* Abstract base class for all XRPC errors.
|
|
48
|
+
*
|
|
49
|
+
* Extends {@link LexError} and implements {@link ResultFailure} for use with
|
|
50
|
+
* safe/result-based error handling patterns.
|
|
51
|
+
*
|
|
52
|
+
* @typeParam M - The XRPC method type (Procedure or Query)
|
|
53
|
+
* @typeParam N - The error code type
|
|
54
|
+
* @typeParam TReason - The reason type for ResultFailure
|
|
55
|
+
*
|
|
56
|
+
* @see {@link XrpcResponseError} - For valid XRPC error responses
|
|
57
|
+
* @see {@link XrpcUpstreamError} - For invalid/unexpected responses
|
|
58
|
+
* @see {@link XrpcInternalError} - For network/internal errors
|
|
59
|
+
*/
|
|
22
60
|
export declare abstract class XrpcError<M extends Procedure | Query = Procedure | Query, N extends LexErrorCode = LexErrorCode, TReason = unknown> extends LexError<N> implements ResultFailure<TReason> {
|
|
23
61
|
readonly method: M;
|
|
24
62
|
name: string;
|
|
@@ -38,8 +76,28 @@ export declare abstract class XrpcError<M extends Procedure | Query = Procedure
|
|
|
38
76
|
matchesSchema(): this is XrpcError<M, InferMethodError<M>>;
|
|
39
77
|
}
|
|
40
78
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
79
|
+
* Error class for valid XRPC error responses from the server.
|
|
80
|
+
*
|
|
81
|
+
* This represents a properly formatted XRPC error where the server returned
|
|
82
|
+
* a non-2xx status with a valid JSON error payload containing `error` and
|
|
83
|
+
* optional `message` fields.
|
|
84
|
+
*
|
|
85
|
+
* Use {@link matchesSchema} to check if the error matches the method's declared
|
|
86
|
+
* error types for type-safe error handling.
|
|
87
|
+
*
|
|
88
|
+
* @typeParam M - The XRPC method type
|
|
89
|
+
* @typeParam N - The error code type (inferred from method or generic)
|
|
90
|
+
*
|
|
91
|
+
* @example Handling specific errors
|
|
92
|
+
* ```typescript
|
|
93
|
+
* try {
|
|
94
|
+
* await client.xrpc(someMethod, options)
|
|
95
|
+
* } catch (err) {
|
|
96
|
+
* if (err instanceof XrpcResponseError && err.error === 'RecordNotFound') {
|
|
97
|
+
* // Handle not found case
|
|
98
|
+
* }
|
|
99
|
+
* }
|
|
100
|
+
* ```
|
|
43
101
|
*/
|
|
44
102
|
export declare class XrpcResponseError<M extends Procedure | Query = Procedure | Query, N extends LexErrorCode = InferMethodError<M> | LexErrorCode> extends XrpcError<M, N, XrpcResponseError<M, N>> {
|
|
45
103
|
readonly response: Response;
|
|
@@ -53,25 +111,81 @@ export declare class XrpcResponseError<M extends Procedure | Query = Procedure |
|
|
|
53
111
|
get body(): LexErrorData;
|
|
54
112
|
}
|
|
55
113
|
export type { WWWAuthenticate };
|
|
114
|
+
/**
|
|
115
|
+
* Error class for 401 Unauthorized XRPC responses.
|
|
116
|
+
*
|
|
117
|
+
* Extends {@link XrpcResponseError} with access to parsed WWW-Authenticate header
|
|
118
|
+
* information, useful for implementing authentication flows.
|
|
119
|
+
*
|
|
120
|
+
* Authentication errors are never retryable as they require user intervention
|
|
121
|
+
* (e.g., re-authentication, token refresh).
|
|
122
|
+
*
|
|
123
|
+
* @typeParam M - The XRPC method type
|
|
124
|
+
* @typeParam N - The error code type
|
|
125
|
+
*
|
|
126
|
+
* @example Handling authentication errors
|
|
127
|
+
* ```typescript
|
|
128
|
+
* try {
|
|
129
|
+
* await client.xrpc(someMethod, options)
|
|
130
|
+
* } catch (err) {
|
|
131
|
+
* if (err instanceof XrpcAuthenticationError) {
|
|
132
|
+
* const { DPoP } = err.wwwAuthenticate
|
|
133
|
+
* if (DPoP?.error === 'use_dpop_nonce') {
|
|
134
|
+
* // Handle DPoP nonce requirement
|
|
135
|
+
* }
|
|
136
|
+
* }
|
|
137
|
+
* }
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
56
140
|
export declare class XrpcAuthenticationError<M extends Procedure | Query = Procedure | Query, N extends LexErrorCode = LexErrorCode> extends XrpcResponseError<M, N> {
|
|
57
141
|
#private;
|
|
58
142
|
name: string;
|
|
59
143
|
shouldRetry(): boolean;
|
|
144
|
+
/**
|
|
145
|
+
* Parsed WWW-Authenticate header from the response.
|
|
146
|
+
* Contains authentication scheme parameters (e.g., Bearer realm, DPoP nonce).
|
|
147
|
+
*/
|
|
60
148
|
get wwwAuthenticate(): WWWAuthenticate;
|
|
61
149
|
}
|
|
62
150
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
151
|
+
* Error class for invalid or unprocessable XRPC responses from upstream servers.
|
|
152
|
+
*
|
|
153
|
+
* This occurs when the server returns a response that doesn't conform to the
|
|
154
|
+
* XRPC protocol, such as:
|
|
155
|
+
* - Missing or invalid Content-Type header
|
|
156
|
+
* - Response body that doesn't match the method's output schema
|
|
157
|
+
* - Non-JSON error responses
|
|
158
|
+
* - Responses from non-XRPC endpoints
|
|
159
|
+
*
|
|
160
|
+
* The error code is always 'UpstreamFailure' and maps to HTTP 502 Bad Gateway
|
|
161
|
+
* when converted to a response.
|
|
162
|
+
*
|
|
163
|
+
* @typeParam M - The XRPC method type
|
|
65
164
|
*/
|
|
66
165
|
export declare class XrpcUpstreamError<M extends Procedure | Query = Procedure | Query> extends XrpcError<M, 'UpstreamFailure', XrpcUpstreamError<M>> {
|
|
67
166
|
readonly response: Response;
|
|
68
|
-
readonly payload:
|
|
167
|
+
readonly payload: XrpcResponsePayload | null;
|
|
69
168
|
name: string;
|
|
70
|
-
constructor(method: M, response: Response, payload
|
|
169
|
+
constructor(method: M, response: Response, payload?: XrpcResponsePayload | null, message?: string, options?: ErrorOptions);
|
|
71
170
|
get reason(): this;
|
|
72
171
|
shouldRetry(): boolean;
|
|
73
172
|
toResponse(): Response;
|
|
74
173
|
}
|
|
174
|
+
/**
|
|
175
|
+
* Error class for internal/client-side errors during XRPC requests.
|
|
176
|
+
*
|
|
177
|
+
* This represents errors that occur before or during the request that are not
|
|
178
|
+
* server responses, such as:
|
|
179
|
+
* - Network errors (connection refused, DNS failure)
|
|
180
|
+
* - Request timeouts
|
|
181
|
+
* - Request aborted via AbortSignal
|
|
182
|
+
* - Invalid request construction
|
|
183
|
+
*
|
|
184
|
+
* The error code is always 'InternalServerError' and these errors are
|
|
185
|
+
* optimistically considered retryable.
|
|
186
|
+
*
|
|
187
|
+
* @typeParam M - The XRPC method type
|
|
188
|
+
*/
|
|
75
189
|
export declare class XrpcInternalError<M extends Procedure | Query = Procedure | Query> extends XrpcError<M, 'InternalServerError', XrpcInternalError<M>> {
|
|
76
190
|
name: string;
|
|
77
191
|
constructor(method: M, message?: string, options?: ErrorOptions);
|
|
@@ -79,6 +193,45 @@ export declare class XrpcInternalError<M extends Procedure | Query = Procedure |
|
|
|
79
193
|
shouldRetry(): true;
|
|
80
194
|
toResponse(): Response;
|
|
81
195
|
}
|
|
196
|
+
/**
|
|
197
|
+
* Union type of all possible XRPC failure types.
|
|
198
|
+
*
|
|
199
|
+
* Used as the return type for safe/non-throwing XRPC methods. Check the
|
|
200
|
+
* `success` property to distinguish between success and failure:
|
|
201
|
+
*
|
|
202
|
+
* @typeParam M - The XRPC method type
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* ```typescript
|
|
206
|
+
* const result = await client.xrpcSafe(someMethod, options)
|
|
207
|
+
* if (result.success) {
|
|
208
|
+
* console.log(result.body) // XrpcResponse
|
|
209
|
+
* } else {
|
|
210
|
+
* // result is XrpcFailure (XrpcResponseError | XrpcUpstreamError | XrpcInternalError)
|
|
211
|
+
* console.error(result.error, result.message)
|
|
212
|
+
* }
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
82
215
|
export type XrpcFailure<M extends Procedure | Query = Procedure | Query> = XrpcResponseError<M> | XrpcUpstreamError<M> | XrpcInternalError<M>;
|
|
216
|
+
/**
|
|
217
|
+
* Converts an unknown error into an appropriate {@link XrpcFailure} type.
|
|
218
|
+
*
|
|
219
|
+
* If the error is already an XrpcFailure for the given method, returns it as-is.
|
|
220
|
+
* Otherwise, wraps it in an {@link XrpcInternalError}.
|
|
221
|
+
*
|
|
222
|
+
* @param method - The XRPC method that was called
|
|
223
|
+
* @param cause - The error to convert
|
|
224
|
+
* @returns An XrpcFailure instance
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```typescript
|
|
228
|
+
* try {
|
|
229
|
+
* const response = await fetch(...)
|
|
230
|
+
* // ... process response
|
|
231
|
+
* } catch (err) {
|
|
232
|
+
* return asXrpcFailure(method, err)
|
|
233
|
+
* }
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
83
236
|
export declare function asXrpcFailure<M extends Procedure | Query>(method: M, cause: unknown): XrpcFailure<M>;
|
|
84
237
|
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACxE,OAAO,EACL,gBAAgB,EAChB,SAAS,EACT,KAAK,EACL,aAAa,EAEd,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACxE,OAAO,EACL,gBAAgB,EAChB,SAAS,EACT,KAAK,EACL,aAAa,EAEd,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,EACL,eAAe,EAEhB,MAAM,uBAAuB,CAAA;AAE9B;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,2BAA2B,EAAE,WAAW,CAAC,MAAM,CAE1D,CAAA;AAEF,OAAO,EAAE,QAAQ,EAAE,CAAA;AACnB,YA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,MAA4C,EACrD,OAAO,CAAC,EAAE,YAAY;IAKxB,IAAa,MAAM,IAAI,IAAI,CAE1B;IAEQ,WAAW,IAAI,OAAO;IAItB,UAAU,IAAI,QAAQ;CAGhC;AAED;;;;;;;;;;;;;;GAcG;AACH,qBAAa,iBAAiB,CAC5B,CAAC,SAAS,SAAS,GAAG,KAAK,GAAG,SAAS,GAAG,KAAK,CAC/C,SAAQ,SAAS,CAAC,CAAC,EAAE,qBAAqB,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC;IACjE,IAAI,SAAsB;gBAEd,MAAM,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;IAS/D,IAAa,MAAM,IAAI,IAAI,CAE1B;IAEQ,WAAW,IAAI,IAAI;IAQnB,UAAU,IAAI,QAAQ;CAIhC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,SAAS,GAAG,KAAK,GAAG,SAAS,GAAG,KAAK,IAEnE,iBAAiB,CAAC,CAAC,CAAC,GAEpB,iBAAiB,CAAC,CAAC,CAAC,GAEpB,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
|
@@ -7,6 +7,20 @@ const lex_data_1 = require("@atproto/lex-data");
|
|
|
7
7
|
Object.defineProperty(exports, "LexError", { enumerable: true, get: function () { return lex_data_1.LexError; } });
|
|
8
8
|
const lex_schema_1 = require("@atproto/lex-schema");
|
|
9
9
|
const www_authenticate_js_1 = require("./www-authenticate.js");
|
|
10
|
+
/**
|
|
11
|
+
* HTTP status codes that indicate a transient error that may succeed on retry.
|
|
12
|
+
*
|
|
13
|
+
* Includes:
|
|
14
|
+
* - 408 Request Timeout
|
|
15
|
+
* - 425 Too Early
|
|
16
|
+
* - 429 Too Many Requests (rate limited)
|
|
17
|
+
* - 500 Internal Server Error
|
|
18
|
+
* - 502 Bad Gateway
|
|
19
|
+
* - 503 Service Unavailable
|
|
20
|
+
* - 504 Gateway Timeout
|
|
21
|
+
* - 522 Connection Timed Out (Cloudflare)
|
|
22
|
+
* - 524 A Timeout Occurred (Cloudflare)
|
|
23
|
+
*/
|
|
10
24
|
exports.RETRYABLE_HTTP_STATUS_CODES = new Set([
|
|
11
25
|
408, 425, 429, 500, 502, 503, 504, 522, 524,
|
|
12
26
|
]);
|
|
@@ -23,10 +37,24 @@ exports.RETRYABLE_HTTP_STATUS_CODES = new Set([
|
|
|
23
37
|
* This function checks whether a given payload matches this schema.
|
|
24
38
|
*/
|
|
25
39
|
function isXrpcErrorPayload(payload) {
|
|
26
|
-
return (payload
|
|
40
|
+
return (payload != null &&
|
|
27
41
|
payload.encoding === 'application/json' &&
|
|
28
42
|
lex_schema_1.lexErrorDataSchema.matches(payload.body));
|
|
29
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Abstract base class for all XRPC errors.
|
|
46
|
+
*
|
|
47
|
+
* Extends {@link LexError} and implements {@link ResultFailure} for use with
|
|
48
|
+
* safe/result-based error handling patterns.
|
|
49
|
+
*
|
|
50
|
+
* @typeParam M - The XRPC method type (Procedure or Query)
|
|
51
|
+
* @typeParam N - The error code type
|
|
52
|
+
* @typeParam TReason - The reason type for ResultFailure
|
|
53
|
+
*
|
|
54
|
+
* @see {@link XrpcResponseError} - For valid XRPC error responses
|
|
55
|
+
* @see {@link XrpcUpstreamError} - For invalid/unexpected responses
|
|
56
|
+
* @see {@link XrpcInternalError} - For network/internal errors
|
|
57
|
+
*/
|
|
30
58
|
class XrpcError extends lex_data_1.LexError {
|
|
31
59
|
method;
|
|
32
60
|
name = 'XrpcError';
|
|
@@ -44,8 +72,28 @@ class XrpcError extends lex_data_1.LexError {
|
|
|
44
72
|
}
|
|
45
73
|
exports.XrpcError = XrpcError;
|
|
46
74
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
75
|
+
* Error class for valid XRPC error responses from the server.
|
|
76
|
+
*
|
|
77
|
+
* This represents a properly formatted XRPC error where the server returned
|
|
78
|
+
* a non-2xx status with a valid JSON error payload containing `error` and
|
|
79
|
+
* optional `message` fields.
|
|
80
|
+
*
|
|
81
|
+
* Use {@link matchesSchema} to check if the error matches the method's declared
|
|
82
|
+
* error types for type-safe error handling.
|
|
83
|
+
*
|
|
84
|
+
* @typeParam M - The XRPC method type
|
|
85
|
+
* @typeParam N - The error code type (inferred from method or generic)
|
|
86
|
+
*
|
|
87
|
+
* @example Handling specific errors
|
|
88
|
+
* ```typescript
|
|
89
|
+
* try {
|
|
90
|
+
* await client.xrpc(someMethod, options)
|
|
91
|
+
* } catch (err) {
|
|
92
|
+
* if (err instanceof XrpcResponseError && err.error === 'RecordNotFound') {
|
|
93
|
+
* // Handle not found case
|
|
94
|
+
* }
|
|
95
|
+
* }
|
|
96
|
+
* ```
|
|
49
97
|
*/
|
|
50
98
|
class XrpcResponseError extends XrpcError {
|
|
51
99
|
response;
|
|
@@ -83,27 +131,68 @@ class XrpcResponseError extends XrpcError {
|
|
|
83
131
|
}
|
|
84
132
|
}
|
|
85
133
|
exports.XrpcResponseError = XrpcResponseError;
|
|
134
|
+
/**
|
|
135
|
+
* Error class for 401 Unauthorized XRPC responses.
|
|
136
|
+
*
|
|
137
|
+
* Extends {@link XrpcResponseError} with access to parsed WWW-Authenticate header
|
|
138
|
+
* information, useful for implementing authentication flows.
|
|
139
|
+
*
|
|
140
|
+
* Authentication errors are never retryable as they require user intervention
|
|
141
|
+
* (e.g., re-authentication, token refresh).
|
|
142
|
+
*
|
|
143
|
+
* @typeParam M - The XRPC method type
|
|
144
|
+
* @typeParam N - The error code type
|
|
145
|
+
*
|
|
146
|
+
* @example Handling authentication errors
|
|
147
|
+
* ```typescript
|
|
148
|
+
* try {
|
|
149
|
+
* await client.xrpc(someMethod, options)
|
|
150
|
+
* } catch (err) {
|
|
151
|
+
* if (err instanceof XrpcAuthenticationError) {
|
|
152
|
+
* const { DPoP } = err.wwwAuthenticate
|
|
153
|
+
* if (DPoP?.error === 'use_dpop_nonce') {
|
|
154
|
+
* // Handle DPoP nonce requirement
|
|
155
|
+
* }
|
|
156
|
+
* }
|
|
157
|
+
* }
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
86
160
|
class XrpcAuthenticationError extends XrpcResponseError {
|
|
87
161
|
name = 'XrpcAuthenticationError';
|
|
88
162
|
shouldRetry() {
|
|
89
163
|
return false;
|
|
90
164
|
}
|
|
91
|
-
#
|
|
165
|
+
#wwwAuthenticateCached;
|
|
166
|
+
/**
|
|
167
|
+
* Parsed WWW-Authenticate header from the response.
|
|
168
|
+
* Contains authentication scheme parameters (e.g., Bearer realm, DPoP nonce).
|
|
169
|
+
*/
|
|
92
170
|
get wwwAuthenticate() {
|
|
93
|
-
return (this.#
|
|
171
|
+
return (this.#wwwAuthenticateCached ??=
|
|
94
172
|
(0, www_authenticate_js_1.parseWWWAuthenticateHeader)(this.response.headers.get('www-authenticate')) ?? {});
|
|
95
173
|
}
|
|
96
174
|
}
|
|
97
175
|
exports.XrpcAuthenticationError = XrpcAuthenticationError;
|
|
98
176
|
/**
|
|
99
|
-
*
|
|
100
|
-
*
|
|
177
|
+
* Error class for invalid or unprocessable XRPC responses from upstream servers.
|
|
178
|
+
*
|
|
179
|
+
* This occurs when the server returns a response that doesn't conform to the
|
|
180
|
+
* XRPC protocol, such as:
|
|
181
|
+
* - Missing or invalid Content-Type header
|
|
182
|
+
* - Response body that doesn't match the method's output schema
|
|
183
|
+
* - Non-JSON error responses
|
|
184
|
+
* - Responses from non-XRPC endpoints
|
|
185
|
+
*
|
|
186
|
+
* The error code is always 'UpstreamFailure' and maps to HTTP 502 Bad Gateway
|
|
187
|
+
* when converted to a response.
|
|
188
|
+
*
|
|
189
|
+
* @typeParam M - The XRPC method type
|
|
101
190
|
*/
|
|
102
191
|
class XrpcUpstreamError extends XrpcError {
|
|
103
192
|
response;
|
|
104
193
|
payload;
|
|
105
194
|
name = 'XrpcUpstreamError';
|
|
106
|
-
constructor(method, response, payload, message = `Unexpected upstream XRPC response`, options) {
|
|
195
|
+
constructor(method, response, payload = null, message = `Unexpected upstream XRPC response`, options) {
|
|
107
196
|
super(method, 'UpstreamFailure', message, options);
|
|
108
197
|
this.response = response;
|
|
109
198
|
this.payload = payload;
|
|
@@ -119,6 +208,21 @@ class XrpcUpstreamError extends XrpcError {
|
|
|
119
208
|
}
|
|
120
209
|
}
|
|
121
210
|
exports.XrpcUpstreamError = XrpcUpstreamError;
|
|
211
|
+
/**
|
|
212
|
+
* Error class for internal/client-side errors during XRPC requests.
|
|
213
|
+
*
|
|
214
|
+
* This represents errors that occur before or during the request that are not
|
|
215
|
+
* server responses, such as:
|
|
216
|
+
* - Network errors (connection refused, DNS failure)
|
|
217
|
+
* - Request timeouts
|
|
218
|
+
* - Request aborted via AbortSignal
|
|
219
|
+
* - Invalid request construction
|
|
220
|
+
*
|
|
221
|
+
* The error code is always 'InternalServerError' and these errors are
|
|
222
|
+
* optimistically considered retryable.
|
|
223
|
+
*
|
|
224
|
+
* @typeParam M - The XRPC method type
|
|
225
|
+
*/
|
|
122
226
|
class XrpcInternalError extends XrpcError {
|
|
123
227
|
name = 'XrpcInternalError';
|
|
124
228
|
constructor(method, message, options) {
|
|
@@ -140,6 +244,26 @@ class XrpcInternalError extends XrpcError {
|
|
|
140
244
|
}
|
|
141
245
|
}
|
|
142
246
|
exports.XrpcInternalError = XrpcInternalError;
|
|
247
|
+
/**
|
|
248
|
+
* Converts an unknown error into an appropriate {@link XrpcFailure} type.
|
|
249
|
+
*
|
|
250
|
+
* If the error is already an XrpcFailure for the given method, returns it as-is.
|
|
251
|
+
* Otherwise, wraps it in an {@link XrpcInternalError}.
|
|
252
|
+
*
|
|
253
|
+
* @param method - The XRPC method that was called
|
|
254
|
+
* @param cause - The error to convert
|
|
255
|
+
* @returns An XrpcFailure instance
|
|
256
|
+
*
|
|
257
|
+
* @example
|
|
258
|
+
* ```typescript
|
|
259
|
+
* try {
|
|
260
|
+
* const response = await fetch(...)
|
|
261
|
+
* // ... process response
|
|
262
|
+
* } catch (err) {
|
|
263
|
+
* return asXrpcFailure(method, err)
|
|
264
|
+
* }
|
|
265
|
+
* ```
|
|
266
|
+
*/
|
|
143
267
|
function asXrpcFailure(method, cause) {
|
|
144
268
|
if (cause instanceof XrpcResponseError ||
|
|
145
269
|
cause instanceof XrpcUpstreamError ||
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAoCA,gDAQC;AAwLD,sCAaC;AAjPD,gDAAwE;AAkB/D,yFAlBA,mBAAQ,OAkBA;AAjBjB,oDAM4B;AAE5B,+DAG8B;AAEjB,QAAA,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;AAQF;;;;;;;;;;;GAWG;AACH,SAAgB,kBAAkB,CAChC,OAA2B;IAE3B,OAAO,CACL,OAAO,KAAK,IAAI;QAChB,OAAO,CAAC,QAAQ,KAAK,kBAAkB;QACvC,+BAAkB,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CACzC,CAAA;AACH,CAAC;AAED,MAAsB,SAKpB,SAAQ,mBAAW;IAMR;IAHX,IAAI,GAAG,WAAW,CAAA;IAElB,YACW,MAAS,EAClB,KAAQ,EACR,UAAkB,GAAG,KAAK,oBAAoB,EAC9C,OAAsB;QAEtB,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;QALrB,WAAM,GAAN,MAAM,CA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,CAAC,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAA;IACtD,CAAC;CACF;AA1BD,8CA0BC;AAED,MAAa,iBAEX,SAAQ,SAAyD;IACjE,IAAI,GAAG,mBAAmB,CAAA;IAE1B,YAAY,MAAS,EAAE,OAAgB,EAAE,OAAsB;QAC7D,KAAK,CACH,MAAM,EACN,qBAAqB,EACrB,OAAO,IAAI,gCAAgC,EAC3C,OAAO,CACR,CAAA;IACH,CAAC;IAED,IAAa,MAAM;QACjB,OAAO,IAAI,CAAA;IACb,CAAC;IAEQ,WAAW;QAClB,sEAAsE;QACtE,uEAAuE;QACvE,mEAAmE;QACnE,wBAAwB;QACxB,OAAO,IAAI,CAAA;IACb,CAAC;IAEQ,UAAU;QACjB,6DAA6D;QAC7D,OAAO,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAA;IAC9D,CAAC;CACF;AA9BD,8CA8BC;AAUD,SAAgB,aAAa,CAC3B,MAAS,EACT,KAAc;IAEd,IACE,KAAK,YAAY,iBAAiB;QAClC,KAAK,YAAY,iBAAiB;QAClC,KAAK,YAAY,iBAAiB,EAClC,CAAC;QACD,IAAI,KAAK,CAAC,MAAM,KAAK,MAAM;YAAE,OAAO,KAAK,CAAA;IAC3C,CAAC;IAED,OAAO,IAAI,iBAAiB,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;AAC5D,CAAC","sourcesContent":["import { LexError, LexErrorCode, LexErrorData } from '@atproto/lex-data'\nimport {\n InferMethodError,\n Procedure,\n Query,\n ResultFailure,\n lexErrorDataSchema,\n} from '@atproto/lex-schema'\nimport { XrpcPayload } from './util.js'\nimport {\n WWWAuthenticate,\n parseWWWAuthenticateHeader,\n} from './www-authenticate.js'\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\nexport type XrpcErrorPayload<N extends LexErrorCode = LexErrorCode> =\n XrpcPayload<LexErrorData<N>, 'application/json'>\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: XrpcPayload | null,\n): payload is XrpcErrorPayload {\n return (\n payload !== null &&\n payload.encoding === 'application/json' &&\n lexErrorDataSchema.matches(payload.body)\n )\n}\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 matchesSchema(): this is XrpcError<M, InferMethodError<M>> {\n return this.method.errors?.includes(this.error) ?? false\n }\n}\n\n/**\n * Class used to represent an HTTP request that resulted in an XRPC method\n * error. That is, a non-2xx response with a valid XRPC error payload.\n */\nexport class XrpcResponseError<\n M extends Procedure | Query = Procedure | Query,\n N extends LexErrorCode = InferMethodError<M> | LexErrorCode,\n> extends XrpcError<M, N, XrpcResponseError<M, N>> {\n name = 'XrpcResponseError'\n\n constructor(\n method: M,\n readonly response: Response,\n readonly payload: XrpcErrorPayload<N>,\n options?: ErrorOptions,\n ) {\n const { error, message } = payload.body\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() {\n return this.payload.body\n }\n\n override toResponse(): Response {\n // Re-expose schema-valid errors as-is to downstream clients\n if (this.matchesSchema()) {\n const status = this.response.status >= 500 ? 502 : this.response.status\n return Response.json(this.toJSON(), { status })\n }\n\n return this.response.status >= 500\n ? // The upstream server had an error, return a generic upstream failure\n Response.json({ error: 'UpstreamFailure' }, { status: 502 })\n : // If the error is on our side, return a generic internal server error\n Response.json({ error: 'InternalServerError' }, { status: 500 })\n }\n\n get body(): LexErrorData {\n return this.payload.body\n }\n}\n\nexport type { WWWAuthenticate }\nexport class XrpcAuthenticationError<\n M extends Procedure | Query = Procedure | Query,\n N extends LexErrorCode = LexErrorCode,\n> extends XrpcResponseError<M, N> {\n name = 'XrpcAuthenticationError'\n\n override shouldRetry(): boolean {\n return false\n }\n\n #wwwAuthenticate?: WWWAuthenticate\n get wwwAuthenticate(): WWWAuthenticate {\n return (this.#wwwAuthenticate ??=\n parseWWWAuthenticateHeader(\n this.response.headers.get('www-authenticate'),\n ) ?? {})\n }\n}\n\n/**\n * This class represents invalid or unprocessable XRPC response from the\n * upstream server.\n */\nexport class XrpcUpstreamError<\n M extends Procedure | Query = Procedure | Query,\n> extends XrpcError<M, 'UpstreamFailure', XrpcUpstreamError<M>> {\n name = 'XrpcUpstreamError'\n\n constructor(\n method: M,\n readonly response: Response,\n readonly payload: XrpcPayload | null,\n message: string = `Unexpected upstream XRPC response`,\n options?: ErrorOptions,\n ) {\n super(method, 'UpstreamFailure', 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 toResponse(): Response {\n return Response.json(this.toJSON(), { status: 502 })\n }\n}\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(): true {\n // Ideally, we would inspect the reason to determine if it's retryable\n // (by detecting network errors, timeouts, etc.). Since these cases are\n // highly platform-dependent, we optimistically assume all internal\n // errors are retryable.\n return true\n }\n\n override toResponse(): Response {\n // Do not expose internal error details to downstream clients\n return Response.json({ error: this.error }, { status: 500 })\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 | XrpcUpstreamError<M>\n // Something went wrong (network error, etc.)\n | XrpcInternalError<M>\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 XrpcUpstreamError ||\n cause instanceof XrpcInternalError\n ) {\n if (cause.method === method) return cause\n }\n\n return new XrpcInternalError(method, undefined, { cause })\n}\n"]}
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AA2DA,gDAQC;AA0TD,sCAaC;AA1YD,gDAAwE;AAgC/D,yFAhCA,mBAAQ,OAgCA;AA/BjB,oDAM4B;AAE5B,+DAG8B;AAE9B;;;;;;;;;;;;;GAaG;AACU,QAAA,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;AAiBF;;;;;;;;;;;GAWG;AACH,SAAgB,kBAAkB,CAChC,OAA+C;IAE/C,OAAO,CACL,OAAO,IAAI,IAAI;QACf,OAAO,CAAC,QAAQ,KAAK,kBAAkB;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,KAAK,YAAY,iBAAiB;QAClC,KAAK,YAAY,iBAAiB,EAClC,CAAC;QACD,IAAI,KAAK,CAAC,MAAM,KAAK,MAAM;YAAE,OAAO,KAAK,CAAA;IAC3C,CAAC;IAED,OAAO,IAAI,iBAAiB,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;AAC5D,CAAC","sourcesContent":["import { LexError, LexErrorCode, LexErrorData } from '@atproto/lex-data'\nimport {\n InferMethodError,\n Procedure,\n Query,\n ResultFailure,\n lexErrorDataSchema,\n} from '@atproto/lex-schema'\nimport { XrpcResponsePayload } from './util.js'\nimport {\n WWWAuthenticate,\n parseWWWAuthenticateHeader,\n} from './www-authenticate.js'\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: XrpcResponsePayload | 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 XrpcUpstreamError} - 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 matchesSchema(): 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 matchesSchema} 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 N extends LexErrorCode = InferMethodError<M> | LexErrorCode,\n> extends XrpcError<M, N, XrpcResponseError<M, N>> {\n name = 'XrpcResponseError'\n\n constructor(\n method: M,\n readonly response: Response,\n readonly payload: XrpcErrorPayload<N>,\n options?: ErrorOptions,\n ) {\n const { error, message } = payload.body\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() {\n return this.payload.body\n }\n\n override toResponse(): Response {\n // Re-expose schema-valid errors as-is to downstream clients\n if (this.matchesSchema()) {\n const status = this.response.status >= 500 ? 502 : this.response.status\n return Response.json(this.toJSON(), { status })\n }\n\n return this.response.status >= 500\n ? // The upstream server had an error, return a generic upstream failure\n Response.json({ error: 'UpstreamFailure' }, { status: 502 })\n : // If the error is on our side, return a generic internal server error\n Response.json({ error: 'InternalServerError' }, { status: 500 })\n }\n\n get body(): LexErrorData {\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 N extends LexErrorCode = LexErrorCode,\n> extends XrpcResponseError<M, N> {\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 'UpstreamFailure' and maps to HTTP 502 Bad Gateway\n * when converted to a response.\n *\n * @typeParam M - The XRPC method type\n */\nexport class XrpcUpstreamError<\n M extends Procedure | Query = Procedure | Query,\n> extends XrpcError<M, 'UpstreamFailure', XrpcUpstreamError<M>> {\n name = 'XrpcUpstreamError'\n\n constructor(\n method: M,\n readonly response: Response,\n readonly payload: XrpcResponsePayload | null = null,\n message: string = `Unexpected upstream XRPC response`,\n options?: ErrorOptions,\n ) {\n super(method, 'UpstreamFailure', 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 toResponse(): Response {\n return Response.json(this.toJSON(), { status: 502 })\n }\n}\n\n/**\n * Error class for internal/client-side errors during XRPC requests.\n *\n * This represents errors that occur before or during the request that are not\n * server responses, such as:\n * - Network errors (connection refused, DNS failure)\n * - Request timeouts\n * - Request aborted via AbortSignal\n * - Invalid request construction\n *\n * The error code is always 'InternalServerError' and these errors are\n * optimistically considered retryable.\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(): true {\n // Ideally, we would inspect the reason to determine if it's retryable\n // (by detecting network errors, timeouts, etc.). Since these cases are\n // highly platform-dependent, we optimistically assume all internal\n // errors are retryable.\n return true\n }\n\n override toResponse(): Response {\n // Do not expose internal error details to downstream clients\n return Response.json({ error: this.error }, { status: 500 })\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 | XrpcUpstreamError | 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 | XrpcUpstreamError<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 XrpcUpstreamError ||\n cause instanceof XrpcInternalError\n ) {\n if (cause.method === method) return cause\n }\n\n return new XrpcInternalError(method, undefined, { cause })\n}\n"]}
|
|
@@ -4,61 +4,65 @@ declare const $nsid = "com.atproto.repo.createRecord";
|
|
|
4
4
|
export { $nsid };
|
|
5
5
|
/** Create a single new repository record. Requires auth, implemented by PDS. */
|
|
6
6
|
declare const main: l.Procedure<"com.atproto.repo.createRecord", l.ParamsSchema<{}>, l.Payload<"application/json", l.ObjectSchema<{
|
|
7
|
-
|
|
7
|
+
repo: l.StringSchema<{
|
|
8
8
|
readonly format: "at-identifier";
|
|
9
9
|
}>;
|
|
10
|
-
|
|
10
|
+
collection: l.StringSchema<{
|
|
11
11
|
readonly format: "nsid";
|
|
12
12
|
}>;
|
|
13
|
-
|
|
13
|
+
rkey: l.OptionalSchema<l.StringSchema<{
|
|
14
14
|
readonly format: "record-key";
|
|
15
15
|
readonly maxLength: 512;
|
|
16
16
|
}>>;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
validate: l.OptionalSchema<l.BooleanSchema>;
|
|
18
|
+
record: l.LexMapSchema;
|
|
19
|
+
swapCommit: l.OptionalSchema<l.StringSchema<{
|
|
20
20
|
readonly format: "cid";
|
|
21
21
|
}>>;
|
|
22
22
|
}>>, l.Payload<"application/json", l.ObjectSchema<{
|
|
23
|
-
|
|
23
|
+
uri: l.StringSchema<{
|
|
24
24
|
readonly format: "at-uri";
|
|
25
25
|
}>;
|
|
26
|
-
|
|
26
|
+
cid: l.StringSchema<{
|
|
27
27
|
readonly format: "cid";
|
|
28
28
|
}>;
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
commit: l.OptionalSchema<l.RefSchema<l.Validator<RepoDefs.CommitMeta, RepoDefs.CommitMeta>>>;
|
|
30
|
+
validationStatus: l.OptionalSchema<l.StringSchema<{
|
|
31
|
+
knownValues: ["valid", "unknown"];
|
|
32
|
+
}>>;
|
|
31
33
|
}>>, readonly ["InvalidSwap"]>;
|
|
32
34
|
export { main };
|
|
33
|
-
export type Params = l.InferMethodParams<typeof main>;
|
|
34
|
-
export type Input = l.InferMethodInput<typeof main>;
|
|
35
|
-
export type InputBody = l.InferMethodInputBody<typeof main>;
|
|
36
|
-
export type Output = l.InferMethodOutput<typeof main>;
|
|
37
|
-
export type OutputBody = l.InferMethodOutputBody<typeof main>;
|
|
35
|
+
export type $Params = l.InferMethodParams<typeof main>;
|
|
36
|
+
export type $Input<B = l.BinaryData> = l.InferMethodInput<typeof main, B>;
|
|
37
|
+
export type $InputBody<B = l.BinaryData> = l.InferMethodInputBody<typeof main, B>;
|
|
38
|
+
export type $Output<B = l.BinaryData> = l.InferMethodOutput<typeof main, B>;
|
|
39
|
+
export type $OutputBody<B = l.BinaryData> = l.InferMethodOutputBody<typeof main, B>;
|
|
38
40
|
export declare const $lxm: "com.atproto.repo.createRecord", $params: l.ParamsSchema<{}>, $input: l.Payload<"application/json", l.ObjectSchema<{
|
|
39
|
-
|
|
41
|
+
repo: l.StringSchema<{
|
|
40
42
|
readonly format: "at-identifier";
|
|
41
43
|
}>;
|
|
42
|
-
|
|
44
|
+
collection: l.StringSchema<{
|
|
43
45
|
readonly format: "nsid";
|
|
44
46
|
}>;
|
|
45
|
-
|
|
47
|
+
rkey: l.OptionalSchema<l.StringSchema<{
|
|
46
48
|
readonly format: "record-key";
|
|
47
49
|
readonly maxLength: 512;
|
|
48
50
|
}>>;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
validate: l.OptionalSchema<l.BooleanSchema>;
|
|
52
|
+
record: l.LexMapSchema;
|
|
53
|
+
swapCommit: l.OptionalSchema<l.StringSchema<{
|
|
52
54
|
readonly format: "cid";
|
|
53
55
|
}>>;
|
|
54
56
|
}>>, $output: l.Payload<"application/json", l.ObjectSchema<{
|
|
55
|
-
|
|
57
|
+
uri: l.StringSchema<{
|
|
56
58
|
readonly format: "at-uri";
|
|
57
59
|
}>;
|
|
58
|
-
|
|
60
|
+
cid: l.StringSchema<{
|
|
59
61
|
readonly format: "cid";
|
|
60
62
|
}>;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
+
commit: l.OptionalSchema<l.RefSchema<l.Validator<RepoDefs.CommitMeta, RepoDefs.CommitMeta>>>;
|
|
64
|
+
validationStatus: l.OptionalSchema<l.StringSchema<{
|
|
65
|
+
knownValues: ["valid", "unknown"];
|
|
66
|
+
}>>;
|
|
63
67
|
}>>;
|
|
64
68
|
//# sourceMappingURL=createRecord.defs.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRecord.defs.d.ts","sourceRoot":"","sources":["../../../../../src/lexicons/com/atproto/repo/createRecord.defs.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,CAAC,EAAE,MAAM,qBAAqB,CAAA;AACvC,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAA;AAE1C,QAAA,MAAM,KAAK,kCAAkC,CAAA;AAE7C,OAAO,EAAE,KAAK,EAAE,CAAA;AAEhB,gFAAgF;AAChF,QAAA,MAAM,IAAI
|
|
1
|
+
{"version":3,"file":"createRecord.defs.d.ts","sourceRoot":"","sources":["../../../../../src/lexicons/com/atproto/repo/createRecord.defs.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,CAAC,EAAE,MAAM,qBAAqB,CAAA;AACvC,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAA;AAE1C,QAAA,MAAM,KAAK,kCAAkC,CAAA;AAE7C,OAAO,EAAE,KAAK,EAAE,CAAA;AAEhB,gFAAgF;AAChF,QAAA,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;8BA8BP,CAAA;AACH,OAAO,EAAE,IAAI,EAAE,CAAA;AAEf,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,iBAAiB,CAAC,OAAO,IAAI,CAAC,CAAA;AACtD,MAAM,MAAM,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC,gBAAgB,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,CAAA;AACzE,MAAM,MAAM,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC,oBAAoB,CAC/D,OAAO,IAAI,EACX,CAAC,CACF,CAAA;AACD,MAAM,MAAM,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC,iBAAiB,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,CAAA;AAC3E,MAAM,MAAM,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC,qBAAqB,CACjE,OAAO,IAAI,EACX,CAAC,CACF,CAAA;AAED,eAAO,MAAM,IAAI,iCAA0B,EACzC,OAAO,oBAAgC,EACvC,MAAM;;;;;;;;;;;;;;;;GAA2B,EACjC,OAAO;;;;;;;;;;;GAA4B,CAAA"}
|
|
@@ -20,7 +20,7 @@ lex_schema_1.l.procedure($nsid,
|
|
|
20
20
|
rkey: /*#__PURE__*/ lex_schema_1.l.optional(
|
|
21
21
|
/*#__PURE__*/ lex_schema_1.l.string({ format: 'record-key', maxLength: 512 })),
|
|
22
22
|
validate: /*#__PURE__*/ lex_schema_1.l.optional(/*#__PURE__*/ lex_schema_1.l.boolean()),
|
|
23
|
-
record: /*#__PURE__*/ lex_schema_1.l.
|
|
23
|
+
record: /*#__PURE__*/ lex_schema_1.l.lexMap(),
|
|
24
24
|
swapCommit: /*#__PURE__*/ lex_schema_1.l.optional(
|
|
25
25
|
/*#__PURE__*/ lex_schema_1.l.string({ format: 'cid' })),
|
|
26
26
|
}),
|
|
@@ -29,7 +29,8 @@ lex_schema_1.l.procedure($nsid,
|
|
|
29
29
|
cid: /*#__PURE__*/ lex_schema_1.l.string({ format: 'cid' }),
|
|
30
30
|
commit: /*#__PURE__*/ lex_schema_1.l.optional(
|
|
31
31
|
/*#__PURE__*/ lex_schema_1.l.ref((() => RepoDefs.commitMeta))),
|
|
32
|
-
validationStatus: /*#__PURE__*/ lex_schema_1.l.optional(
|
|
32
|
+
validationStatus: /*#__PURE__*/ lex_schema_1.l.optional(
|
|
33
|
+
/*#__PURE__*/ lex_schema_1.l.string()),
|
|
33
34
|
}), ['InvalidSwap']);
|
|
34
35
|
exports.main = main;
|
|
35
36
|
exports.$lxm = main.nsid, exports.$params = main.parameters, exports.$input = main.input, exports.$output = main.output;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRecord.defs.js","sourceRoot":"","sources":["../../../../../src/lexicons/com/atproto/repo/createRecord.defs.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,oDAAuC;AACvC,iEAA0C;AAE1C,MAAM,KAAK,GAAG,+BAA+B,CAAA;AAEpC,sBAAK;AAEd,gFAAgF;AAChF,MAAM,IAAI;AACR,aAAa;AACb,cAAC,CAAC,SAAS,CACT,KAAK;AACL,aAAa,CAAC,cAAC,CAAC,MAAM,EAAE;AACxB,aAAa,CAAC,cAAC,CAAC,WAAW,CAAC;IAC1B,IAAI,EAAE,aAAa,CAAC,cAAC,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,eAAe,EAAE,CAAC;IACzD,UAAU,EAAE,aAAa,CAAC,cAAC,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;IACtD,IAAI,EAAE,aAAa,CAAC,cAAC,CAAC,QAAQ;IAC5B,aAAa,CAAC,cAAC,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,CACjE;IACD,QAAQ,EAAE,aAAa,CAAC,cAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,cAAC,CAAC,OAAO,EAAE,CAAC;IAC7D,MAAM,EAAE,aAAa,CAAC,cAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"createRecord.defs.js","sourceRoot":"","sources":["../../../../../src/lexicons/com/atproto/repo/createRecord.defs.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,oDAAuC;AACvC,iEAA0C;AAE1C,MAAM,KAAK,GAAG,+BAA+B,CAAA;AAEpC,sBAAK;AAEd,gFAAgF;AAChF,MAAM,IAAI;AACR,aAAa;AACb,cAAC,CAAC,SAAS,CACT,KAAK;AACL,aAAa,CAAC,cAAC,CAAC,MAAM,EAAE;AACxB,aAAa,CAAC,cAAC,CAAC,WAAW,CAAC;IAC1B,IAAI,E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AI,CAAC,UAAU,EACvC,QAAA,MAAM,GAAiB,IAAI,CAAC,KAAK,EACjC,QAAA,OAAO,GAAiB,IAAI,CAAC,MAAM,CAAA","sourcesContent":["/*\n * THIS FILE WAS GENERATED BY \"@atproto/lex\". DO NOT EDIT.\n */\n\nimport { l } from '@atproto/lex-schema'\nimport * as RepoDefs from './defs.defs.js'\n\nconst $nsid = 'com.atproto.repo.createRecord'\n\nexport { $nsid }\n\n/** Create a single new repository record. Requires auth, implemented by PDS. */\nconst main =\n /*#__PURE__*/\n l.procedure(\n $nsid,\n /*#__PURE__*/ l.params(),\n /*#__PURE__*/ l.jsonPayload({\n repo: /*#__PURE__*/ l.string({ format: 'at-identifier' }),\n collection: /*#__PURE__*/ l.string({ format: 'nsid' }),\n rkey: /*#__PURE__*/ l.optional(\n /*#__PURE__*/ l.string({ format: 'record-key', maxLength: 512 }),\n ),\n validate: /*#__PURE__*/ l.optional(/*#__PURE__*/ l.boolean()),\n record: /*#__PURE__*/ l.lexMap(),\n swapCommit: /*#__PURE__*/ l.optional(\n /*#__PURE__*/ l.string({ format: 'cid' }),\n ),\n }),\n /*#__PURE__*/ l.jsonPayload({\n uri: /*#__PURE__*/ l.string({ format: 'at-uri' }),\n cid: /*#__PURE__*/ l.string({ format: 'cid' }),\n commit: /*#__PURE__*/ l.optional(\n /*#__PURE__*/ l.ref<RepoDefs.CommitMeta>(\n (() => RepoDefs.commitMeta) as any,\n ),\n ),\n validationStatus: /*#__PURE__*/ l.optional(\n /*#__PURE__*/ l.string<{ knownValues: ['valid', 'unknown'] }>(),\n ),\n }),\n ['InvalidSwap'],\n )\nexport { main }\n\nexport type $Params = l.InferMethodParams<typeof main>\nexport type $Input<B = l.BinaryData> = l.InferMethodInput<typeof main, B>\nexport type $InputBody<B = l.BinaryData> = l.InferMethodInputBody<\n typeof main,\n B\n>\nexport type $Output<B = l.BinaryData> = l.InferMethodOutput<typeof main, B>\nexport type $OutputBody<B = l.BinaryData> = l.InferMethodOutputBody<\n typeof main,\n B\n>\n\nexport const $lxm = /*#__PURE__*/ main.nsid,\n $params = /*#__PURE__*/ main.parameters,\n $input = /*#__PURE__*/ main.input,\n $output = /*#__PURE__*/ main.output\n"]}
|