@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/src/agent.ts
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
import { DidString } from '@atproto/lex-schema'
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* A function that performs HTTP requests towards a service endpoint.
|
|
5
|
+
*
|
|
6
|
+
* The handler is responsible for adding the origin (protocol, hostname, and
|
|
7
|
+
* port) to the provided path, typically based on authentication or service
|
|
8
|
+
* configuration. The handler are also responsible for adding any necessary
|
|
9
|
+
* headers, such as authorization tokens.
|
|
10
|
+
*
|
|
11
|
+
* @param path - The URL path (pathname + query parameters) without the origin
|
|
12
|
+
* @param init - Standard fetch RequestInit options
|
|
13
|
+
* @returns A Promise resolving to the HTTP Response
|
|
14
|
+
*/
|
|
3
15
|
export type FetchHandler = (
|
|
4
16
|
/**
|
|
5
17
|
* The URL (pathname + query parameters) to make the request to, without the
|
|
@@ -10,8 +22,27 @@ export type FetchHandler = (
|
|
|
10
22
|
init: RequestInit,
|
|
11
23
|
) => Promise<Response>
|
|
12
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Core interface for making XRPC requests.
|
|
27
|
+
*
|
|
28
|
+
* An Agent encapsulates an identity and request handling for AT Protocol
|
|
29
|
+
* operations. It can represent an authenticated user session or an
|
|
30
|
+
* unauthenticated service client.
|
|
31
|
+
*
|
|
32
|
+
* @see {@link buildAgent} for creating (simple) Agent instances.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const agent: Agent = {
|
|
37
|
+
* did: 'did:plc:example123',
|
|
38
|
+
* fetchHandler: (path, init) => fetch(new URL(path, 'https://bsky.social'), init)
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
13
42
|
export interface Agent {
|
|
43
|
+
/** The DID of the authenticated user, or `undefined` if unauthenticated. */
|
|
14
44
|
readonly did?: DidString
|
|
45
|
+
/** The fetch handler used to make HTTP requests. */
|
|
15
46
|
fetchHandler: FetchHandler
|
|
16
47
|
}
|
|
17
48
|
|
|
@@ -43,8 +74,44 @@ export type AgentConfig = {
|
|
|
43
74
|
fetch?: typeof globalThis.fetch
|
|
44
75
|
}
|
|
45
76
|
|
|
77
|
+
/**
|
|
78
|
+
* Options for creating an Agent.
|
|
79
|
+
*
|
|
80
|
+
* Can be a full {@link AgentConfig} object, or a simple service URL string/{@link URL}.
|
|
81
|
+
*/
|
|
46
82
|
export type AgentOptions = AgentConfig | string | URL
|
|
47
83
|
|
|
84
|
+
/**
|
|
85
|
+
* Creates an {@link Agent} from various input types.
|
|
86
|
+
*
|
|
87
|
+
* This factory function accepts an existing Agent (returned as-is), a service URL,
|
|
88
|
+
* or a full configuration object. It handles the common case of creating an
|
|
89
|
+
* unauthenticated agent from just a service URL.
|
|
90
|
+
*
|
|
91
|
+
* @param options - Agent instance, configuration object, or service URL
|
|
92
|
+
* @returns A configured Agent ready for making requests
|
|
93
|
+
* @throws {TypeError} If fetch() is not available in the environment
|
|
94
|
+
*
|
|
95
|
+
* @example From URL string
|
|
96
|
+
* ```typescript
|
|
97
|
+
* const agent = buildAgent('https://public.api.bsky.app')
|
|
98
|
+
* ```
|
|
99
|
+
*
|
|
100
|
+
* @example From configuration
|
|
101
|
+
* ```typescript
|
|
102
|
+
* const agent = buildAgent({
|
|
103
|
+
* did: 'did:plc:example',
|
|
104
|
+
* service: 'https://bsky.social',
|
|
105
|
+
* headers: { 'Authorization': 'Bearer ...' }
|
|
106
|
+
* })
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* @example Pass-through existing agent
|
|
110
|
+
* ```typescript
|
|
111
|
+
* const existing: Agent = { ... }
|
|
112
|
+
* const agent = buildAgent(existing) // Returns existing unchanged
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
48
115
|
export function buildAgent(options: Agent | AgentOptions): Agent {
|
|
49
116
|
if (typeof options === 'object' && 'fetchHandler' in options) {
|
|
50
117
|
return options
|