@atcute/client 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,17 @@
1
+ Permission is hereby granted, free of charge, to any person obtaining a copy
2
+ of this software and associated documentation files (the "Software"), to deal
3
+ in the Software without restriction, including without limitation the rights
4
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
5
+ copies of the Software, and to permit persons to whom the Software is
6
+ furnished to do so, subject to the following conditions:
7
+
8
+ The above copyright notice and this permission notice shall be included in all
9
+ copies or substantial portions of the Software.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # @atcute/client
2
+
3
+ lightweight and cute API client for AT Protocol.
4
+
5
+ - Small, comes in at ~1,720 b minified (~904 b minzipped).
6
+ - No validations, type definitions match actual HTTP responses.
7
+
8
+ This package only contains the base AT Protocol lexicons and endpoints, along with an authentication middleware.
9
+ For Bluesky-related lexicons, see `@atcute/bluesky` package.
10
+
11
+ ```ts
12
+ import { XRPC } from '@atcute/client';
13
+ import { AtpAuth } from '@atcute/client/middlewares/auth';
14
+
15
+ const rpc = new XRPC({ service: 'https://bsky.social' });
16
+ const auth = new AtpAuth(rpc);
17
+
18
+ await auth.login({ identifier: 'example.com', password: 'ofki-yrwl-hmcc-cvau' });
19
+
20
+ console.log(auth.session);
21
+ // -> { refreshJwt: 'eyJhb...', ... }
22
+
23
+ const { data } = await rpc.get('com.atproto.identity.resolveHandle', {
24
+ params: {
25
+ handle: 'pfrazee.com',
26
+ },
27
+ });
28
+
29
+ console.log(data.did);
30
+ // -> did:plc:ragtjsm2j2vknwkz3zp4oxrd
31
+ ```
@@ -0,0 +1,177 @@
1
+ /**
2
+ * @module
3
+ * Handles the actual XRPC client functionalities.
4
+ */
5
+ import type { At, Procedures, Queries } from './lexicons.ts';
6
+ export type Headers = Record<string, string>;
7
+ /** Possible response status from an XRPC service, status <100 is used for the library itself. */
8
+ export declare const enum ResponseType {
9
+ /** Unknown error from the library */
10
+ Unknown = 1,
11
+ /** The server returned an invalid response */
12
+ InvalidResponse = 2,
13
+ /** Successful response from the service */
14
+ Success = 200,
15
+ /** Request was considered invalid by the service */
16
+ InvalidRequest = 400,
17
+ /** Service requires an authentication token */
18
+ AuthRequired = 401,
19
+ /** Request is forbidden by the service */
20
+ Forbidden = 403,
21
+ /** Not a XRPC service */
22
+ XRPCNotSupported = 404,
23
+ /** Payload is considered too large by the service */
24
+ PayloadTooLarge = 413,
25
+ /** Ratelimit was exceeded */
26
+ RateLimitExceeded = 429,
27
+ /** Internal server error */
28
+ InternalServerError = 500,
29
+ /** Method hasn't been implemented */
30
+ MethodNotImplemented = 501,
31
+ /** Failure by an upstream service */
32
+ UpstreamFailure = 502,
33
+ /** Not enough resources */
34
+ NotEnoughResouces = 503,
35
+ /** Timeout from upstream service */
36
+ UpstreamTimeout = 504
37
+ }
38
+ /** XRPC response status which are recoverable (network error) */
39
+ export declare const RECOVERABLE_RESPONSE_STATUS: number[];
40
+ /** Request type, either query (GET) or procedure (POST) */
41
+ export type RequestType = 'get' | 'post';
42
+ /** XRPC that gets passed around middlewares and eventually to the service. */
43
+ export interface XRPCRequest {
44
+ service: string;
45
+ type: RequestType;
46
+ nsid: string;
47
+ headers: Headers;
48
+ params: Record<string, unknown>;
49
+ encoding?: string;
50
+ data?: FormData | Blob | ArrayBufferView | Record<string, unknown>;
51
+ signal?: AbortSignal;
52
+ }
53
+ /** Response from XRPC service */
54
+ export interface XRPCResponse<T = any> {
55
+ data: T;
56
+ headers: Headers;
57
+ }
58
+ /** Options for constructing an XRPC error */
59
+ export interface XRPCErrorOptions {
60
+ kind?: string;
61
+ message?: string;
62
+ headers?: Headers;
63
+ cause?: unknown;
64
+ }
65
+ /** Error coming from the XRPC service */
66
+ export declare class XRPCError extends Error {
67
+ name: string;
68
+ /** Response status */
69
+ status: number;
70
+ /** Response headers */
71
+ headers: Headers;
72
+ /** Error kind */
73
+ kind?: string;
74
+ constructor(status: number, { kind, message, headers, cause }?: XRPCErrorOptions);
75
+ }
76
+ /** Response returned from middlewares and XRPC service */
77
+ export interface XRPCFetchReturn {
78
+ status: number;
79
+ headers: Headers;
80
+ body: unknown;
81
+ }
82
+ /** Fetch function */
83
+ export type XRPCFetch = (req: XRPCRequest) => Promise<XRPCFetchReturn>;
84
+ /** Function that constructs a middleware */
85
+ export type XRPCHook = (next: XRPCFetch) => XRPCFetch;
86
+ /** Options for constructing an XRPC class */
87
+ export interface XRPCOptions {
88
+ service: string;
89
+ }
90
+ /** Base options for the query/procedure request */
91
+ interface BaseRPCOptions {
92
+ /** `Content-Type` encoding for the input, defaults to `application/json` if passing a JSON object */
93
+ encoding?: string;
94
+ /** Request headers to make */
95
+ headers?: Headers;
96
+ /** Signal for aborting the request */
97
+ signal?: AbortSignal;
98
+ }
99
+ /** Options for the query/procedure request */
100
+ export type RPCOptions<T> = BaseRPCOptions & (T extends {
101
+ params: any;
102
+ } ? {
103
+ params: T['params'];
104
+ } : {}) & (T extends {
105
+ input: any;
106
+ } ? {
107
+ data: T['input'];
108
+ } : {});
109
+ type OutputOf<T> = T extends {
110
+ output: any;
111
+ } ? T['output'] : never;
112
+ /** The client that sends out requests. */
113
+ export declare class XRPC {
114
+ #private;
115
+ /** The service it should connect to */
116
+ service: string;
117
+ /** XRPC fetch handler */
118
+ fetch: XRPCFetch;
119
+ constructor(options: XRPCOptions);
120
+ /**
121
+ * Adds a hook to intercept XRPC requests.
122
+ * Hooks are executed from last-registered to first-registered
123
+ * @param fn Hook function
124
+ */
125
+ hook(fn: XRPCHook): void;
126
+ /**
127
+ * Makes a query (GET) request
128
+ * @param nsid Namespace ID of a query endpoint
129
+ * @param options Options to include like parameters
130
+ * @returns The response of the request
131
+ */
132
+ get<K extends keyof Queries>(nsid: K, options: RPCOptions<Queries[K]>): Promise<XRPCResponse<OutputOf<Queries[K]>>>;
133
+ /**
134
+ * Makes a procedure (POST) request
135
+ * @param nsid Namespace ID of a procedure endpoint
136
+ * @param options Options to include like input body or parameters
137
+ * @returns The response of the request
138
+ */
139
+ call<K extends keyof Procedures>(nsid: K, options: RPCOptions<Procedures[K]>): Promise<XRPCResponse<OutputOf<Procedures[K]>>>;
140
+ }
141
+ /**
142
+ * Clones an XRPC instance
143
+ * @param rpc Base instance
144
+ * @returns The cloned instance
145
+ */
146
+ export declare const clone: (rpc: XRPC) => XRPC;
147
+ /**
148
+ * Clones an existing XRPC instance, with a proxy on top.
149
+ * @param rpc Base instance
150
+ * @param opts Proxying options
151
+ * @returns Cloned instance with a proxy added
152
+ */
153
+ export declare const withProxy: (rpc: XRPC, opts: ProxyOptions) => XRPC;
154
+ /** Known endpoint types for proxying */
155
+ export type ProxyType = 'atproto_labeler' | 'bsky_fg';
156
+ /** Options for proxying a request */
157
+ export interface ProxyOptions {
158
+ /** Service it should proxy requests to */
159
+ service: At.DID;
160
+ /** The endpoint to connect */
161
+ type: ProxyType | (string & {});
162
+ }
163
+ /** Default fetch handler */
164
+ export declare const fetchHandler: XRPCFetch;
165
+ /**
166
+ * Check if provided value is an error object
167
+ * @param value Response value
168
+ * @param names If provided, also checks if the error name matches what you expect
169
+ * @returns A boolean on the check
170
+ */
171
+ export declare const isErrorResponse: (value: any, names?: string[]) => value is ErrorResponseBody;
172
+ /** Response body from a thrown query/procedure */
173
+ export interface ErrorResponseBody {
174
+ error?: string;
175
+ message?: string;
176
+ }
177
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,207 @@
1
+ /**
2
+ * @module
3
+ * Handles the actual XRPC client functionalities.
4
+ */
5
+ /** Possible response status from an XRPC service, status <100 is used for the library itself. */
6
+ export var ResponseType;
7
+ (function (ResponseType) {
8
+ /** Unknown error from the library */
9
+ ResponseType[ResponseType["Unknown"] = 1] = "Unknown";
10
+ /** The server returned an invalid response */
11
+ ResponseType[ResponseType["InvalidResponse"] = 2] = "InvalidResponse";
12
+ /** Successful response from the service */
13
+ ResponseType[ResponseType["Success"] = 200] = "Success";
14
+ /** Request was considered invalid by the service */
15
+ ResponseType[ResponseType["InvalidRequest"] = 400] = "InvalidRequest";
16
+ /** Service requires an authentication token */
17
+ ResponseType[ResponseType["AuthRequired"] = 401] = "AuthRequired";
18
+ /** Request is forbidden by the service */
19
+ ResponseType[ResponseType["Forbidden"] = 403] = "Forbidden";
20
+ /** Not a XRPC service */
21
+ ResponseType[ResponseType["XRPCNotSupported"] = 404] = "XRPCNotSupported";
22
+ /** Payload is considered too large by the service */
23
+ ResponseType[ResponseType["PayloadTooLarge"] = 413] = "PayloadTooLarge";
24
+ /** Ratelimit was exceeded */
25
+ ResponseType[ResponseType["RateLimitExceeded"] = 429] = "RateLimitExceeded";
26
+ /** Internal server error */
27
+ ResponseType[ResponseType["InternalServerError"] = 500] = "InternalServerError";
28
+ /** Method hasn't been implemented */
29
+ ResponseType[ResponseType["MethodNotImplemented"] = 501] = "MethodNotImplemented";
30
+ /** Failure by an upstream service */
31
+ ResponseType[ResponseType["UpstreamFailure"] = 502] = "UpstreamFailure";
32
+ /** Not enough resources */
33
+ ResponseType[ResponseType["NotEnoughResouces"] = 503] = "NotEnoughResouces";
34
+ /** Timeout from upstream service */
35
+ ResponseType[ResponseType["UpstreamTimeout"] = 504] = "UpstreamTimeout";
36
+ })(ResponseType || (ResponseType = {}));
37
+ /** XRPC response status which are recoverable (network error) */
38
+ export const RECOVERABLE_RESPONSE_STATUS = [1, 408, 425, 429, 500, 502, 503, 504, 522, 524];
39
+ /** Error coming from the XRPC service */
40
+ export class XRPCError extends Error {
41
+ name = 'XRPCError';
42
+ /** Response status */
43
+ status;
44
+ /** Response headers */
45
+ headers;
46
+ /** Error kind */
47
+ kind;
48
+ constructor(status, { kind, message, headers, cause } = {}) {
49
+ super(message || `Unspecified error message`, { cause });
50
+ this.status = status;
51
+ this.kind = kind;
52
+ this.headers = headers || {};
53
+ }
54
+ }
55
+ /** The client that sends out requests. */
56
+ export class XRPC {
57
+ /** The service it should connect to */
58
+ service;
59
+ /** XRPC fetch handler */
60
+ fetch = fetchHandler;
61
+ constructor(options) {
62
+ this.service = options.service;
63
+ }
64
+ /**
65
+ * Adds a hook to intercept XRPC requests.
66
+ * Hooks are executed from last-registered to first-registered
67
+ * @param fn Hook function
68
+ */
69
+ hook(fn) {
70
+ this.fetch = fn(this.fetch);
71
+ }
72
+ /**
73
+ * Makes a query (GET) request
74
+ * @param nsid Namespace ID of a query endpoint
75
+ * @param options Options to include like parameters
76
+ * @returns The response of the request
77
+ */
78
+ get(nsid, options) {
79
+ return this.#call({ type: 'get', nsid: nsid, ...options });
80
+ }
81
+ /**
82
+ * Makes a procedure (POST) request
83
+ * @param nsid Namespace ID of a procedure endpoint
84
+ * @param options Options to include like input body or parameters
85
+ * @returns The response of the request
86
+ */
87
+ call(nsid, options) {
88
+ return this.#call({ type: 'post', nsid: nsid, ...options });
89
+ }
90
+ async #call(request) {
91
+ const { status, headers, body } = await this.fetch({
92
+ ...request,
93
+ service: this.service,
94
+ headers: request.headers === undefined ? {} : request.headers,
95
+ params: request.params === undefined ? {} : request.params,
96
+ });
97
+ if (status === ResponseType.Success) {
98
+ return { data: body, headers: headers };
99
+ }
100
+ else if (isErrorResponse(body)) {
101
+ throw new XRPCError(status, { kind: body.error, message: body.message, headers });
102
+ }
103
+ else {
104
+ throw new XRPCError(status, { headers });
105
+ }
106
+ }
107
+ }
108
+ /**
109
+ * Clones an XRPC instance
110
+ * @param rpc Base instance
111
+ * @returns The cloned instance
112
+ */
113
+ export const clone = (rpc) => {
114
+ const cloned = new XRPC({ service: rpc.service });
115
+ cloned.fetch = rpc.fetch;
116
+ return cloned;
117
+ };
118
+ /**
119
+ * Clones an existing XRPC instance, with a proxy on top.
120
+ * @param rpc Base instance
121
+ * @param opts Proxying options
122
+ * @returns Cloned instance with a proxy added
123
+ */
124
+ export const withProxy = (rpc, opts) => {
125
+ const cloned = clone(rpc);
126
+ cloned.hook((next) => (request) => {
127
+ return next({
128
+ ...request,
129
+ headers: {
130
+ ...request.headers,
131
+ 'atproto-proxy': `${opts.service}#${opts.type}`,
132
+ },
133
+ });
134
+ });
135
+ return cloned;
136
+ };
137
+ /** Default fetch handler */
138
+ export const fetchHandler = async ({ service, type, nsid, headers, params, encoding, data: input, signal, }) => {
139
+ const uri = new URL(`/xrpc/${nsid}`, service);
140
+ const searchParams = uri.searchParams;
141
+ for (const key in params) {
142
+ const value = params[key];
143
+ if (value !== undefined) {
144
+ if (Array.isArray(value)) {
145
+ for (let idx = 0, len = value.length; idx < len; idx++) {
146
+ const val = value[idx];
147
+ searchParams.append(key, val);
148
+ }
149
+ }
150
+ else {
151
+ searchParams.set(key, value);
152
+ }
153
+ }
154
+ }
155
+ const isProcedure = type === 'post';
156
+ const isJson = typeof input === 'object' &&
157
+ !(input instanceof FormData || input instanceof Blob || ArrayBuffer.isView(input));
158
+ const response = await fetch(uri, {
159
+ signal: signal,
160
+ method: isProcedure ? 'POST' : 'GET',
161
+ headers: encoding || isJson ? { ...headers, 'Content-Type': encoding || 'application/json' } : headers,
162
+ body: isJson ? JSON.stringify(input) : input,
163
+ });
164
+ const responseHeaders = response.headers;
165
+ const responseType = responseHeaders.get('Content-Type');
166
+ let promise;
167
+ let data;
168
+ if (responseType) {
169
+ if (responseType.startsWith('application/json')) {
170
+ promise = response.json();
171
+ }
172
+ else if (responseType.startsWith('text/')) {
173
+ promise = response.text();
174
+ }
175
+ }
176
+ try {
177
+ data = await (promise || response.arrayBuffer().then((buffer) => new Uint8Array(buffer)));
178
+ }
179
+ catch (err) {
180
+ throw new XRPCError(ResponseType.InvalidResponse, {
181
+ cause: err,
182
+ message: `Failed to parse response body`,
183
+ });
184
+ }
185
+ return {
186
+ status: response.status,
187
+ headers: Object.fromEntries(responseHeaders),
188
+ body: data,
189
+ };
190
+ };
191
+ /**
192
+ * Check if provided value is an error object
193
+ * @param value Response value
194
+ * @param names If provided, also checks if the error name matches what you expect
195
+ * @returns A boolean on the check
196
+ */
197
+ export const isErrorResponse = (value, names) => {
198
+ if (typeof value !== 'object' || !value) {
199
+ return false;
200
+ }
201
+ const kindType = typeof value.error;
202
+ const messageType = typeof value.message;
203
+ return ((kindType === 'undefined' || kindType === 'string') &&
204
+ (messageType === 'undefined' || messageType === 'string') &&
205
+ (!names || names.includes(value.error)));
206
+ };
207
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,iGAAiG;AACjG,MAAM,CAAN,IAAkB,YA8BjB;AA9BD,WAAkB,YAAY;IAC7B,qCAAqC;IACrC,qDAAW,CAAA;IACX,8CAA8C;IAC9C,qEAAmB,CAAA;IAEnB,2CAA2C;IAC3C,uDAAa,CAAA;IACb,oDAAoD;IACpD,qEAAoB,CAAA;IACpB,+CAA+C;IAC/C,iEAAkB,CAAA;IAClB,0CAA0C;IAC1C,2DAAe,CAAA;IACf,yBAAyB;IACzB,yEAAsB,CAAA;IACtB,qDAAqD;IACrD,uEAAqB,CAAA;IACrB,6BAA6B;IAC7B,2EAAuB,CAAA;IACvB,4BAA4B;IAC5B,+EAAyB,CAAA;IACzB,qCAAqC;IACrC,iFAA0B,CAAA;IAC1B,qCAAqC;IACrC,uEAAqB,CAAA;IACrB,2BAA2B;IAC3B,2EAAuB,CAAA;IACvB,oCAAoC;IACpC,uEAAqB,C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