@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
package/src/agent.ts DELETED
@@ -1,186 +0,0 @@
1
- import { DidString } from '@atproto/lex-schema'
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 can also be 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
- */
15
- export type FetchHandler = (
16
- /**
17
- * The URL (pathname + query parameters) to make the request to, without the
18
- * origin. The origin (protocol, hostname, and port) must be added by this
19
- * {@link FetchHandler}, typically based on authentication or other factors.
20
- */
21
- path: `/${string}`,
22
- init: RequestInit,
23
- ) => Promise<Response>
24
-
25
- /**
26
- * Core interface for making XRPC requests towards a specific service.
27
- *
28
- * An {@link Agent} encapsulates an identity and request handling for AT
29
- * Protocol operations. Agents will typically handle authentication, service URL
30
- * resolution, and other request configuration, allowing client code to make
31
- * requests without needing to manage these details directly. The key component
32
- * of an Agent is the {@link FetchHandler}, which is responsible for
33
- * constructing the full request URL and adding any necessary headers or
34
- * authentication tokens. The Agent's `did` property represents the
35
- * authenticated user's DID, if available, and can be used for operations that
36
- * require knowledge of the user's identity (such as creating AT Protocol
37
- * records).
38
- *
39
- * @see {@link buildAgent} for creating (simple) Agent instances.
40
- *
41
- * @example
42
- * ```typescript
43
- * const agent: Agent = {
44
- * did: 'did:plc:example123',
45
- * fetchHandler: async (path, init) => {
46
- * const url = new URL(path, 'https://bsky.social')
47
- * return fetch(url, init)
48
- * }
49
- * }
50
- * ```
51
- */
52
- export interface Agent {
53
- /** The DID of the authenticated user, or `undefined` if unauthenticated. */
54
- readonly did?: DidString
55
- /** The fetch handler used to make HTTP requests. */
56
- fetchHandler: FetchHandler
57
- }
58
-
59
- export function isAgent(value: unknown): value is Agent {
60
- return (
61
- typeof value === 'object' &&
62
- value !== null &&
63
- 'fetchHandler' in value &&
64
- typeof value.fetchHandler === 'function' &&
65
- (!('did' in value) ||
66
- value.did === undefined ||
67
- typeof value.did === 'string')
68
- )
69
- }
70
-
71
- export type AgentConfig = {
72
- /**
73
- * The identifier (DID) of the user represented by this agent.
74
- */
75
- did?: DidString
76
-
77
- /**
78
- * The service URL to make requests to. This can be a string, URL, or a
79
- * function that returns a string or URL. This is useful for dynamic URLs,
80
- * such as a service URL that changes based on authentication.
81
- */
82
- service: string | URL
83
-
84
- /**
85
- * Optional headers to include with every request made by this agent, unless
86
- * overridden by the request-specific headers provided to the fetch handler.
87
- */
88
- headers?: HeadersInit
89
-
90
- /**
91
- * Bring your own fetch implementation. Typically useful for testing, logging,
92
- * mocking, or adding retries, session management, signatures, proof of
93
- * possession (DPoP), SSRF protection, etc. Defaults to the global `fetch`
94
- * function.
95
- */
96
- fetch?: typeof globalThis.fetch
97
- }
98
-
99
- /**
100
- * Options for creating an Agent.
101
- *
102
- * Can be a full {@link AgentConfig} object, or a simple service URL string/{@link URL}.
103
- */
104
- export type AgentOptions = AgentConfig | FetchHandler | string | URL
105
-
106
- /**
107
- * Creates an {@link Agent} from various input types.
108
- *
109
- * This factory function accepts an existing Agent (returned as-is), a service
110
- * URL, or a full configuration object. It handles the common case of creating
111
- * an unauthenticated agent from just a service URL.
112
- *
113
- * @param options - Agent instance, configuration object, or service URL
114
- * @returns A configured Agent ready for making requests
115
- * @throws {TypeError} If fetch() is not available in the environment
116
- *
117
- * @example // From URL string
118
- * ```typescript
119
- * const agent = buildAgent('https://public.api.bsky.app')
120
- * ```
121
- *
122
- * @example // From configuration
123
- * ```typescript
124
- * const agent = buildAgent({
125
- * did: 'did:plc:example',
126
- * service: 'https://bsky.social',
127
- * headers: { 'Authorization': 'Bearer ...' }
128
- * })
129
- * ```
130
- */
131
- export function buildAgent<O extends Agent | AgentOptions>(
132
- options: O,
133
- ): O extends Agent ? O : Agent
134
- export function buildAgent(options: Agent | AgentOptions): Agent {
135
- const config: Agent | AgentConfig =
136
- typeof options === 'function'
137
- ? { did: undefined, fetchHandler: options }
138
- : typeof options === 'string' || options instanceof URL
139
- ? { did: undefined, service: options }
140
- : options
141
-
142
- if (isAgent(config)) return config
143
-
144
- const { service, fetch = globalThis.fetch } = config
145
-
146
- if (typeof fetch !== 'function') {
147
- throw new TypeError('fetch() is not available in this environment')
148
- }
149
-
150
- return {
151
- get did() {
152
- return config.did
153
- },
154
-
155
- async fetchHandler(path, init) {
156
- const headers =
157
- config.headers != null && init.headers != null
158
- ? mergeHeaders(config.headers, init.headers)
159
- : config.headers || init.headers
160
-
161
- return fetch(
162
- new URL(path, service),
163
- headers !== init.headers ? { ...init, headers } : init,
164
- )
165
- },
166
- }
167
- }
168
-
169
- function mergeHeaders(
170
- defaultHeaders: HeadersInit,
171
- requestHeaders: HeadersInit,
172
- ): Headers {
173
- // We don't want to alter the original Headers objects, so we create a new one
174
- const result = new Headers(defaultHeaders)
175
-
176
- const overrides =
177
- requestHeaders instanceof Headers
178
- ? requestHeaders
179
- : new Headers(requestHeaders)
180
-
181
- for (const [key, value] of overrides.entries()) {
182
- result.set(key, value)
183
- }
184
-
185
- return result
186
- }