@atproto/xrpc 0.6.0-rc.0 → 0.6.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/CHANGELOG.md +557 -21
- package/dist/client.d.ts +3 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +4 -4
- package/dist/client.js.map +1 -1
- package/dist/fetch-handler.d.ts +1 -1
- package/dist/fetch-handler.d.ts.map +1 -1
- package/dist/fetch-handler.js +3 -0
- package/dist/fetch-handler.js.map +1 -1
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +13 -78
- package/dist/util.js.map +1 -1
- package/dist/xrpc-client.d.ts +1 -1
- package/dist/xrpc-client.d.ts.map +1 -1
- package/dist/xrpc-client.js +6 -6
- package/dist/xrpc-client.js.map +1 -1
- package/package.json +2 -2
- package/src/client.ts +6 -6
- package/src/fetch-handler.ts +6 -1
- package/src/util.ts +16 -85
- package/src/xrpc-client.ts +5 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,39 +1,575 @@
|
|
|
1
1
|
# @atproto/xrpc
|
|
2
2
|
|
|
3
|
-
## 0.6.0
|
|
3
|
+
## 0.6.0
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
7
|
-
- [#2483](https://github.com/bluesky-social/atproto/pull/2483) [`
|
|
7
|
+
- [#2483](https://github.com/bluesky-social/atproto/pull/2483) [`b934b396b`](https://github.com/bluesky-social/atproto/commit/b934b396b13ba32bf2bf7e75ecdf6871e5f310dd) Thanks [@matthieusieben](https://github.com/matthieusieben)!
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
dispatcher into a distinct class. This means cleaner code organization and
|
|
11
|
-
better clarity on responsibilities.
|
|
12
|
-
2. Enhanced Evolutivity: With this refactor, the XRPC client is now more
|
|
13
|
-
adaptable to various use cases. You can easily extend and customize the
|
|
14
|
-
dispatcher perform session management, retries, and more.
|
|
9
|
+
#### Motivation
|
|
15
10
|
|
|
16
|
-
|
|
11
|
+
The motivation for these changes is the need to make the `@atproto/api` package
|
|
12
|
+
compatible with OAuth session management. We don't have OAuth client support
|
|
13
|
+
"launched" and documented quite yet, so you can keep using the current app
|
|
14
|
+
password authentication system. When we do "launch" OAuth support and begin
|
|
15
|
+
encouraging its usage in the near future (see the [OAuth
|
|
16
|
+
Roadmap](https://github.com/bluesky-social/atproto/discussions/2656)), these
|
|
17
|
+
changes will make it easier to migrate.
|
|
18
|
+
|
|
19
|
+
In addition, the redesigned session management system fixes a bug that could
|
|
20
|
+
cause the session data to become invalid when Agent clones are created (e.g.
|
|
21
|
+
using `agent.withProxy()`).
|
|
22
|
+
|
|
23
|
+
#### New Features
|
|
24
|
+
|
|
25
|
+
We've restructured the `XrpcClient` HTTP fetch handler to be specified during
|
|
26
|
+
the instantiation of the XRPC client, through the constructor, instead of using
|
|
27
|
+
a default implementation (which was statically defined).
|
|
28
|
+
|
|
29
|
+
With this refactor, the XRPC client is now more modular and reusable. Session
|
|
30
|
+
management, retries, cryptographic signing, and other request-specific logic can
|
|
31
|
+
be implemented in the fetch handler itself rather than by the calling code.
|
|
32
|
+
|
|
33
|
+
A new abstract class named `Agent`, has been added to `@atproto/api`. This class
|
|
34
|
+
will be the base class for all Bluesky agents classes in the `@atproto`
|
|
35
|
+
ecosystem. It is meant to be extended by implementations that provide session
|
|
36
|
+
management and fetch handling.
|
|
37
|
+
|
|
38
|
+
As you adapt your code to these changes, make sure to use the `Agent` type
|
|
39
|
+
wherever you expect to receive an agent, and use the `AtpAgent` type (class)
|
|
40
|
+
only to instantiate your client. The reason for this is to be forward compatible
|
|
41
|
+
with the OAuth agent implementation that will also extend `Agent`, and not
|
|
42
|
+
`AtpAgent`.
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import { Agent, AtpAgent } from '@atproto/api'
|
|
46
|
+
|
|
47
|
+
async function setupAgent(
|
|
48
|
+
service: string,
|
|
49
|
+
username: string,
|
|
50
|
+
password: string,
|
|
51
|
+
): Promise<Agent> {
|
|
52
|
+
const agent = new AtpAgent({
|
|
53
|
+
service,
|
|
54
|
+
persistSession: (evt, session) => {
|
|
55
|
+
// handle session update
|
|
56
|
+
},
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
await agent.login(username, password)
|
|
60
|
+
|
|
61
|
+
return agent
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
import { Agent } from '@atproto/api'
|
|
67
|
+
|
|
68
|
+
async function doStuffWithAgent(agent: Agent, arg: string) {
|
|
69
|
+
return agent.resolveHandle(arg)
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
import { Agent, AtpAgent } from '@atproto/api'
|
|
75
|
+
|
|
76
|
+
class MyClass {
|
|
77
|
+
agent: Agent
|
|
78
|
+
|
|
79
|
+
constructor() {
|
|
80
|
+
this.agent = new AtpAgent()
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
#### Breaking changes
|
|
17
86
|
|
|
18
87
|
Most of the changes introduced in this version are backward-compatible. However,
|
|
19
88
|
there are a couple of breaking changes you should be aware of:
|
|
20
89
|
|
|
21
|
-
- Customizing `
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
90
|
+
- Customizing `fetch`: The ability to customize the `fetch: FetchHandler`
|
|
91
|
+
property of `@atproto/xrpc`'s `Client` and `@atproto/api`'s `AtpAgent` classes
|
|
92
|
+
has been removed. Previously, the `fetch` property could be set to a function
|
|
93
|
+
that would be used as the fetch handler for that instance, and was initialized
|
|
94
|
+
to a default fetch handler. That property is still accessible in a read-only
|
|
95
|
+
fashion through the `fetchHandler` property and can only be set during the
|
|
96
|
+
instance creation. Attempting to set/get the `fetch` property will now result
|
|
97
|
+
in an error.
|
|
28
98
|
- The `fetch()` method, as well as WhatWG compliant `Request` and `Headers`
|
|
29
|
-
constructors, must be globally available in your environment.
|
|
30
|
-
|
|
31
|
-
-
|
|
99
|
+
constructors, must be globally available in your environment. Use a polyfill
|
|
100
|
+
if necessary.
|
|
101
|
+
- The `AtpBaseClient` has been removed. The `AtpServiceClient` has been renamed
|
|
102
|
+
`AtpBaseClient`. Any code using either of these classes will need to be
|
|
103
|
+
updated.
|
|
104
|
+
- Instead of _wrapping_ an `XrpcClient` in its `xrpc` property, the
|
|
105
|
+
`AtpBaseClient` (formerly `AtpServiceClient`) class - created through
|
|
106
|
+
`lex-cli` - now _extends_ the `XrpcClient` class. This means that a client
|
|
107
|
+
instance now passes the `instanceof XrpcClient` check. The `xrpc` property now
|
|
108
|
+
returns the instance itself and has been deprecated.
|
|
109
|
+
- `setSessionPersistHandler` is no longer available on the `AtpAgent` or
|
|
110
|
+
`BskyAgent` classes. The session handler can only be set though the
|
|
111
|
+
`persistSession` options of the `AtpAgent` constructor.
|
|
112
|
+
- The new class hierarchy is as follows:
|
|
113
|
+
- `BskyAgent` extends `AtpAgent`: but add no functionality (hence its
|
|
114
|
+
deprecation).
|
|
115
|
+
- `AtpAgent` extends `Agent`: adds password based session management.
|
|
116
|
+
- `Agent` extends `AtpBaseClient`: this abstract class that adds syntactic sugar
|
|
117
|
+
methods `app.bsky` lexicons. It also adds abstract session management
|
|
118
|
+
methods and adds atproto specific utilities
|
|
119
|
+
(`labelers` & `proxy` headers, cloning capability)
|
|
120
|
+
- `AtpBaseClient` extends `XrpcClient`: automatically code that adds fully
|
|
121
|
+
typed lexicon defined namespaces (`instance.app.bsky.feed.getPosts()`) to
|
|
122
|
+
the `XrpcClient`.
|
|
123
|
+
- `XrpcClient` is the base class.
|
|
124
|
+
|
|
125
|
+
#### Non-breaking changes
|
|
126
|
+
|
|
127
|
+
- The `com.*` and `app.*` namespaces have been made directly available to every
|
|
128
|
+
`Agent` instances.
|
|
129
|
+
|
|
130
|
+
#### Deprecations
|
|
131
|
+
|
|
132
|
+
- The default export of the `@atproto/xrpc` package has been deprecated. Use
|
|
133
|
+
named exports instead.
|
|
134
|
+
- The `Client` and `ServiceClient` classes are now deprecated. They are replaced by a single `XrpcClient` class.
|
|
135
|
+
- The default export of the `@atproto/api` package has been deprecated. Use
|
|
136
|
+
named exports instead.
|
|
137
|
+
- The `BskyAgent` has been deprecated. Use the `AtpAgent` class instead.
|
|
138
|
+
- The `xrpc` property of the `AtpClient` instances has been deprecated. The
|
|
139
|
+
instance itself should be used as the XRPC client.
|
|
140
|
+
- The `api` property of the `AtpAgent` and `BskyAgent` instances has been
|
|
141
|
+
deprecated. Use the instance itself instead.
|
|
142
|
+
|
|
143
|
+
#### Migration
|
|
144
|
+
|
|
145
|
+
##### The `@atproto/api` package
|
|
146
|
+
|
|
147
|
+
If you were relying on the `AtpBaseClient` solely to perform validation, use
|
|
148
|
+
this:
|
|
149
|
+
|
|
150
|
+
<table>
|
|
151
|
+
<tr>
|
|
152
|
+
<td><center>Before</center></td> <td><center>After</center></td>
|
|
153
|
+
</tr>
|
|
154
|
+
<tr>
|
|
155
|
+
<td>
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
import { AtpBaseClient, ComAtprotoSyncSubscribeRepos } from '@atproto/api'
|
|
159
|
+
|
|
160
|
+
const baseClient = new AtpBaseClient()
|
|
161
|
+
|
|
162
|
+
baseClient.xrpc.lex.assertValidXrpcMessage('io.example.doStuff', {
|
|
163
|
+
// ...
|
|
164
|
+
})
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
</td>
|
|
168
|
+
<td>
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
import { lexicons } from '@atproto/api'
|
|
172
|
+
|
|
173
|
+
lexicons.assertValidXrpcMessage('io.example.doStuff', {
|
|
174
|
+
// ...
|
|
175
|
+
})
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
</td>
|
|
179
|
+
</tr>
|
|
180
|
+
</table>
|
|
181
|
+
|
|
182
|
+
If you are extending the `BskyAgent` to perform custom `session` manipulation, define your own `Agent` subclass instead:
|
|
183
|
+
|
|
184
|
+
<table>
|
|
185
|
+
<tr>
|
|
186
|
+
<td><center>Before</center></td> <td><center>After</center></td>
|
|
187
|
+
</tr>
|
|
188
|
+
<tr>
|
|
189
|
+
<td>
|
|
190
|
+
|
|
191
|
+
```ts
|
|
192
|
+
import { BskyAgent } from '@atproto/api'
|
|
193
|
+
|
|
194
|
+
class MyAgent extends BskyAgent {
|
|
195
|
+
private accessToken?: string
|
|
196
|
+
|
|
197
|
+
async createOrRefreshSession(identifier: string, password: string) {
|
|
198
|
+
// custom logic here
|
|
199
|
+
|
|
200
|
+
this.accessToken = 'my-access-jwt'
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
async doStuff() {
|
|
204
|
+
return this.call('io.example.doStuff', {
|
|
205
|
+
headers: {
|
|
206
|
+
Authorization: this.accessToken && `Bearer ${this.accessToken}`,
|
|
207
|
+
},
|
|
208
|
+
})
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
</td>
|
|
214
|
+
<td>
|
|
215
|
+
|
|
216
|
+
```ts
|
|
217
|
+
import { Agent } from '@atproto/api'
|
|
218
|
+
|
|
219
|
+
class MyAgent extends Agent {
|
|
220
|
+
private accessToken?: string
|
|
221
|
+
public did?: string
|
|
222
|
+
|
|
223
|
+
constructor(private readonly service: string | URL) {
|
|
224
|
+
super({
|
|
225
|
+
service,
|
|
226
|
+
headers: {
|
|
227
|
+
Authorization: () =>
|
|
228
|
+
this.accessToken ? `Bearer ${this.accessToken}` : null,
|
|
229
|
+
},
|
|
230
|
+
})
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
clone(): MyAgent {
|
|
234
|
+
const agent = new MyAgent(this.service)
|
|
235
|
+
agent.accessToken = this.accessToken
|
|
236
|
+
agent.did = this.did
|
|
237
|
+
return this.copyInto(agent)
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
async createOrRefreshSession(identifier: string, password: string) {
|
|
241
|
+
// custom logic here
|
|
242
|
+
|
|
243
|
+
this.did = 'did:example:123'
|
|
244
|
+
this.accessToken = 'my-access-jwt'
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
</td>
|
|
250
|
+
</tr>
|
|
251
|
+
</table>
|
|
252
|
+
|
|
253
|
+
If you are monkey patching the `xrpc` service client to perform client-side rate limiting, you can now do this in the `FetchHandler` function:
|
|
254
|
+
|
|
255
|
+
<table>
|
|
256
|
+
<tr>
|
|
257
|
+
<td><center>Before</center></td> <td><center>After</center></td>
|
|
258
|
+
</tr>
|
|
259
|
+
<tr>
|
|
260
|
+
<td>
|
|
261
|
+
|
|
262
|
+
```ts
|
|
263
|
+
import { BskyAgent } from '@atproto/api'
|
|
264
|
+
import { RateLimitThreshold } from 'rate-limit-threshold'
|
|
265
|
+
|
|
266
|
+
const agent = new BskyAgent()
|
|
267
|
+
const limiter = new RateLimitThreshold(3000, 300_000)
|
|
268
|
+
|
|
269
|
+
const origCall = agent.api.xrpc.call
|
|
270
|
+
agent.api.xrpc.call = async function (...args) {
|
|
271
|
+
await limiter.wait()
|
|
272
|
+
return origCall.call(this, ...args)
|
|
273
|
+
}
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
</td>
|
|
277
|
+
<td>
|
|
278
|
+
|
|
279
|
+
```ts
|
|
280
|
+
import { AtpAgent } from '@atproto/api'
|
|
281
|
+
import { RateLimitThreshold } from 'rate-limit-threshold'
|
|
282
|
+
|
|
283
|
+
class LimitedAtpAgent extends AtpAgent {
|
|
284
|
+
constructor(options: AtpAgentOptions) {
|
|
285
|
+
const fetch: typeof globalThis.fetch = options.fetch ?? globalThis.fetch
|
|
286
|
+
const limiter = new RateLimitThreshold(3000, 300_000)
|
|
287
|
+
|
|
288
|
+
super({
|
|
289
|
+
...options,
|
|
290
|
+
fetch: async (...args) => {
|
|
291
|
+
await limiter.wait()
|
|
292
|
+
return fetch(...args)
|
|
293
|
+
},
|
|
294
|
+
})
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
</td>
|
|
300
|
+
</tr>
|
|
301
|
+
</table>
|
|
302
|
+
|
|
303
|
+
If you configure a static `fetch` handler on the `BskyAgent` class - for example
|
|
304
|
+
to modify the headers of every request - you can now do this by providing your
|
|
305
|
+
own `fetch` function:
|
|
306
|
+
|
|
307
|
+
<table>
|
|
308
|
+
<tr>
|
|
309
|
+
<td><center>Before</center></td> <td><center>After</center></td>
|
|
310
|
+
</tr>
|
|
311
|
+
<tr>
|
|
312
|
+
<td>
|
|
313
|
+
|
|
314
|
+
```ts
|
|
315
|
+
import { BskyAgent, defaultFetchHandler } from '@atproto/api'
|
|
316
|
+
|
|
317
|
+
BskyAgent.configure({
|
|
318
|
+
fetch: async (httpUri, httpMethod, httpHeaders, httpReqBody) => {
|
|
319
|
+
const ua = httpHeaders['User-Agent']
|
|
320
|
+
|
|
321
|
+
httpHeaders['User-Agent'] = ua ? `${ua} ${userAgent}` : userAgent
|
|
322
|
+
|
|
323
|
+
return defaultFetchHandler(httpUri, httpMethod, httpHeaders, httpReqBody)
|
|
324
|
+
},
|
|
325
|
+
})
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
</td>
|
|
329
|
+
<td>
|
|
330
|
+
|
|
331
|
+
```ts
|
|
332
|
+
import { AtpAgent } from '@atproto/api'
|
|
333
|
+
|
|
334
|
+
class MyAtpAgent extends AtpAgent {
|
|
335
|
+
constructor(options: AtpAgentOptions) {
|
|
336
|
+
const fetch = options.fetch ?? globalThis.fetch
|
|
337
|
+
|
|
338
|
+
super({
|
|
339
|
+
...options,
|
|
340
|
+
fetch: async (url, init) => {
|
|
341
|
+
const headers = new Headers(init.headers)
|
|
342
|
+
|
|
343
|
+
const ua = headersList.get('User-Agent')
|
|
344
|
+
headersList.set('User-Agent', ua ? `${ua} ${userAgent}` : userAgent)
|
|
345
|
+
|
|
346
|
+
return fetch(url, { ...init, headers })
|
|
347
|
+
},
|
|
348
|
+
})
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
</td>
|
|
354
|
+
</tr>
|
|
355
|
+
</table>
|
|
356
|
+
|
|
357
|
+
<!-- <table>
|
|
358
|
+
<tr>
|
|
359
|
+
<td><center>Before</center></td> <td><center>After</center></td>
|
|
360
|
+
</tr>
|
|
361
|
+
<tr>
|
|
362
|
+
<td>
|
|
363
|
+
|
|
364
|
+
```ts
|
|
365
|
+
// before
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
</td>
|
|
369
|
+
<td>
|
|
370
|
+
|
|
371
|
+
```ts
|
|
372
|
+
// after
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
</td>
|
|
376
|
+
</tr>
|
|
377
|
+
</table> -->
|
|
378
|
+
|
|
379
|
+
##### The `@atproto/xrpc` package
|
|
380
|
+
|
|
381
|
+
The `Client` and `ServiceClient` classes are now **deprecated**. If you need a
|
|
382
|
+
lexicon based client, you should update the code to use the `XrpcClient` class
|
|
383
|
+
instead.
|
|
384
|
+
|
|
385
|
+
The deprecated `ServiceClient` class now extends the new `XrpcClient` class.
|
|
386
|
+
Because of this, the `fetch` `FetchHandler` can no longer be configured on the
|
|
387
|
+
`Client` instances (including the default export of the package). If you are not
|
|
388
|
+
relying on the `fetch` `FetchHandler`, the new changes should have no impact on
|
|
389
|
+
your code. Beware that the deprecated classes will eventually be removed in a
|
|
390
|
+
future version.
|
|
391
|
+
|
|
392
|
+
Since its use has completely changed, the `FetchHandler` type has also
|
|
393
|
+
completely changed. The new `FetchHandler` type is now a function that receives
|
|
394
|
+
a `url` pathname and a `RequestInit` object and returns a `Promise<Response>`.
|
|
395
|
+
This function is responsible for making the actual request to the server.
|
|
396
|
+
|
|
397
|
+
```ts
|
|
398
|
+
export type FetchHandler = (
|
|
399
|
+
this: void,
|
|
400
|
+
/**
|
|
401
|
+
* The URL (pathname + query parameters) to make the request to, without the
|
|
402
|
+
* origin. The origin (protocol, hostname, and port) must be added by this
|
|
403
|
+
* {@link FetchHandler}, typically based on authentication or other factors.
|
|
404
|
+
*/
|
|
405
|
+
url: string,
|
|
406
|
+
init: RequestInit,
|
|
407
|
+
) => Promise<Response>
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
A noticeable change that has been introduced is that the `uri` field of the
|
|
411
|
+
`ServiceClient` class has _not_ been ported to the new `XrpcClient` class. It is
|
|
412
|
+
now the responsibility of the `FetchHandler` to determine the full URL to make
|
|
413
|
+
the request to. The same goes for the `headers`, which should now be set through
|
|
414
|
+
the `FetchHandler` function.
|
|
415
|
+
|
|
416
|
+
If you _do_ rely on the legacy `Client.fetch` property to perform custom logic
|
|
417
|
+
upon request, you will need to migrate your code to use the new `XrpcClient`
|
|
418
|
+
class. The `XrpcClient` class has a similar API to the old `ServiceClient`
|
|
419
|
+
class, but with a few differences:
|
|
420
|
+
|
|
421
|
+
- The `Client` + `ServiceClient` duality was removed in favor of a single
|
|
422
|
+
`XrpcClient` class. This means that:
|
|
423
|
+
|
|
424
|
+
- There no longer exists a centralized lexicon registry. If you need a global
|
|
425
|
+
lexicon registry, you can maintain one yourself using a `new Lexicons` (from
|
|
426
|
+
`@atproto/lexicon`).
|
|
427
|
+
- The `FetchHandler` is no longer a statically defined property of the
|
|
428
|
+
`Client` class. Instead, it is passed as an argument to the `XrpcClient`
|
|
429
|
+
constructor.
|
|
430
|
+
|
|
431
|
+
- The `XrpcClient` constructor now requires a `FetchHandler` function as the
|
|
432
|
+
first argument, and an optional `Lexicon` instance as the second argument.
|
|
433
|
+
- The `setHeader` and `unsetHeader` methods were not ported to the new
|
|
434
|
+
`XrpcClient` class. If you need to set or unset headers, you should do so in
|
|
435
|
+
the `FetchHandler` function provided in the constructor arg.
|
|
436
|
+
|
|
437
|
+
<table>
|
|
438
|
+
<tr>
|
|
439
|
+
<td><center>Before</center></td> <td><center>After</center></td>
|
|
440
|
+
</tr>
|
|
441
|
+
<tr>
|
|
442
|
+
<td>
|
|
443
|
+
|
|
444
|
+
```ts
|
|
445
|
+
import client, { defaultFetchHandler } from '@atproto/xrpc'
|
|
446
|
+
|
|
447
|
+
client.fetch = function (
|
|
448
|
+
httpUri: string,
|
|
449
|
+
httpMethod: string,
|
|
450
|
+
httpHeaders: Headers,
|
|
451
|
+
httpReqBody: unknown,
|
|
452
|
+
) {
|
|
453
|
+
// Custom logic here
|
|
454
|
+
return defaultFetchHandler(httpUri, httpMethod, httpHeaders, httpReqBody)
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
client.addLexicon({
|
|
458
|
+
lexicon: 1,
|
|
459
|
+
id: 'io.example.doStuff',
|
|
460
|
+
defs: {},
|
|
461
|
+
})
|
|
462
|
+
|
|
463
|
+
const instance = client.service('http://my-service.com')
|
|
464
|
+
|
|
465
|
+
instance.setHeader('my-header', 'my-value')
|
|
466
|
+
|
|
467
|
+
await instance.call('io.example.doStuff')
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
</td>
|
|
471
|
+
<td>
|
|
472
|
+
|
|
473
|
+
```ts
|
|
474
|
+
import { XrpcClient } from '@atproto/xrpc'
|
|
475
|
+
|
|
476
|
+
const instance = new XrpcClient(
|
|
477
|
+
async (url, init) => {
|
|
478
|
+
const headers = new Headers(init.headers)
|
|
479
|
+
|
|
480
|
+
headers.set('my-header', 'my-value')
|
|
481
|
+
|
|
482
|
+
// Custom logic here
|
|
483
|
+
|
|
484
|
+
const fullUrl = new URL(url, 'http://my-service.com')
|
|
485
|
+
|
|
486
|
+
return fetch(fullUrl, { ...init, headers })
|
|
487
|
+
},
|
|
488
|
+
[
|
|
489
|
+
{
|
|
490
|
+
lexicon: 1,
|
|
491
|
+
id: 'io.example.doStuff',
|
|
492
|
+
defs: {},
|
|
493
|
+
},
|
|
494
|
+
],
|
|
495
|
+
)
|
|
496
|
+
|
|
497
|
+
await instance.call('io.example.doStuff')
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
</td>
|
|
501
|
+
</tr>
|
|
502
|
+
</table>
|
|
503
|
+
|
|
504
|
+
If your fetch handler does not require any "custom logic", and all you need is
|
|
505
|
+
an `XrpcClient` that makes its HTTP requests towards a static service URL, the
|
|
506
|
+
previous example can be simplified to:
|
|
507
|
+
|
|
508
|
+
```ts
|
|
509
|
+
import { XrpcClient } from '@atproto/xrpc'
|
|
510
|
+
|
|
511
|
+
const instance = new XrpcClient('http://my-service.com', [
|
|
512
|
+
{
|
|
513
|
+
lexicon: 1,
|
|
514
|
+
id: 'io.example.doStuff',
|
|
515
|
+
defs: {},
|
|
516
|
+
},
|
|
517
|
+
])
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
If you need to add static headers to all requests, you can instead instantiate
|
|
521
|
+
the `XrpcClient` as follows:
|
|
522
|
+
|
|
523
|
+
```ts
|
|
524
|
+
import { XrpcClient } from '@atproto/xrpc'
|
|
525
|
+
|
|
526
|
+
const instance = new XrpcClient(
|
|
527
|
+
{
|
|
528
|
+
service: 'http://my-service.com',
|
|
529
|
+
headers: {
|
|
530
|
+
'my-header': 'my-value',
|
|
531
|
+
},
|
|
532
|
+
},
|
|
533
|
+
[
|
|
534
|
+
{
|
|
535
|
+
lexicon: 1,
|
|
536
|
+
id: 'io.example.doStuff',
|
|
537
|
+
defs: {},
|
|
538
|
+
},
|
|
539
|
+
],
|
|
540
|
+
)
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
If you need the headers or service url to be dynamic, you can define them using
|
|
544
|
+
functions:
|
|
545
|
+
|
|
546
|
+
```ts
|
|
547
|
+
import { XrpcClient } from '@atproto/xrpc'
|
|
548
|
+
|
|
549
|
+
const instance = new XrpcClient(
|
|
550
|
+
{
|
|
551
|
+
service: () => 'http://my-service.com',
|
|
552
|
+
headers: {
|
|
553
|
+
'my-header': () => 'my-value',
|
|
554
|
+
'my-ignored-header': () => null, // ignored
|
|
555
|
+
},
|
|
556
|
+
},
|
|
557
|
+
[
|
|
558
|
+
{
|
|
559
|
+
lexicon: 1,
|
|
560
|
+
id: 'io.example.doStuff',
|
|
561
|
+
defs: {},
|
|
562
|
+
},
|
|
563
|
+
],
|
|
564
|
+
)
|
|
565
|
+
```
|
|
566
|
+
|
|
567
|
+
- [#2483](https://github.com/bluesky-social/atproto/pull/2483) [`b934b396b`](https://github.com/bluesky-social/atproto/commit/b934b396b13ba32bf2bf7e75ecdf6871e5f310dd) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Add the ability to use `fetch()` compatible `BodyInit` body when making XRPC calls.
|
|
32
568
|
|
|
33
569
|
### Patch Changes
|
|
34
570
|
|
|
35
|
-
- Updated dependencies [[`
|
|
36
|
-
- @atproto/lexicon@0.4.1
|
|
571
|
+
- Updated dependencies [[`b934b396b`](https://github.com/bluesky-social/atproto/commit/b934b396b13ba32bf2bf7e75ecdf6871e5f310dd), [`2bdf75d7a`](https://github.com/bluesky-social/atproto/commit/2bdf75d7a63924c10e7a311f16cb447d595b933e)]:
|
|
572
|
+
- @atproto/lexicon@0.4.1
|
|
37
573
|
|
|
38
574
|
## 0.5.0
|
|
39
575
|
|
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LexiconDoc, Lexicons } from '@atproto/lexicon';
|
|
2
|
-
import { CallOptions,
|
|
2
|
+
import { CallOptions, QueryParams } from './types';
|
|
3
3
|
import { XrpcClient } from './xrpc-client';
|
|
4
4
|
/** @deprecated Use {@link XrpcClient} instead */
|
|
5
5
|
export declare class Client {
|
|
@@ -18,9 +18,9 @@ export declare class Client {
|
|
|
18
18
|
export declare class ServiceClient extends XrpcClient {
|
|
19
19
|
baseClient: Client;
|
|
20
20
|
uri: URL;
|
|
21
|
-
|
|
21
|
+
headers: Record<string, string>;
|
|
22
22
|
constructor(baseClient: Client, serviceUri: string | URL);
|
|
23
|
-
setHeader(key: string, value:
|
|
23
|
+
setHeader(key: string, value: string): void;
|
|
24
24
|
unsetHeader(key: string): void;
|
|
25
25
|
}
|
|
26
26
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AACvD,OAAO,EAAE,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AACvD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAG1C,iDAAiD;AACjD,qBAAa,MAAM;IACjB,kBAAkB;IAClB,IAAI,KAAK,IAAI,KAAK,CAIjB;IAED,kBAAkB;IAClB,IAAI,KAAK,CAAC,CAAC,EAAE,KAAK,EAIjB;IAED,GAAG,WAAiB;IAKd,IAAI,CACR,UAAU,EAAE,MAAM,GAAG,GAAG,EACxB,UAAU,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,WAAW,EACpB,IAAI,CAAC,EAAE,QAAQ,GAAG,IAAI,EACtB,IAAI,CAAC,EAAE,WAAW;IAKpB,OAAO,CAAC,UAAU,EAAE,MAAM,GAAG,GAAG;IAOhC,UAAU,CAAC,GAAG,EAAE,UAAU;IAI1B,WAAW,CAAC,IAAI,EAAE,UAAU,EAAE;IAM9B,aAAa,CAAC,GAAG,EAAE,MAAM;CAG1B;AAED,iDAAiD;AACjD,qBAAa,aAAc,SAAQ,UAAU;IAKlC,UAAU,EAAE,MAAM;IAJ3B,GAAG,EAAE,GAAG,CAAA;IACR,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAK;gBAG3B,UAAU,EAAE,MAAM,EACzB,UAAU,EAAE,MAAM,GAAG,GAAG;IAS1B,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAI3C,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;CAG/B"}
|
package/dist/client.js
CHANGED
|
@@ -49,7 +49,7 @@ exports.Client = Client;
|
|
|
49
49
|
class ServiceClient extends xrpc_client_1.XrpcClient {
|
|
50
50
|
constructor(baseClient, serviceUri) {
|
|
51
51
|
super(async (input, init) => {
|
|
52
|
-
const headers = (0, util_1.combineHeaders)(init.headers, this.headers);
|
|
52
|
+
const headers = (0, util_1.combineHeaders)(init.headers, Object.entries(this.headers));
|
|
53
53
|
return fetch(new URL(input, this.uri), { ...init, headers });
|
|
54
54
|
}, baseClient.lex);
|
|
55
55
|
Object.defineProperty(this, "baseClient", {
|
|
@@ -68,15 +68,15 @@ class ServiceClient extends xrpc_client_1.XrpcClient {
|
|
|
68
68
|
enumerable: true,
|
|
69
69
|
configurable: true,
|
|
70
70
|
writable: true,
|
|
71
|
-
value:
|
|
71
|
+
value: {}
|
|
72
72
|
});
|
|
73
73
|
this.uri = typeof serviceUri === 'string' ? new URL(serviceUri) : serviceUri;
|
|
74
74
|
}
|
|
75
75
|
setHeader(key, value) {
|
|
76
|
-
this.headers
|
|
76
|
+
this.headers[key] = value;
|
|
77
77
|
}
|
|
78
78
|
unsetHeader(key) {
|
|
79
|
-
this.headers
|
|
79
|
+
delete this.headers[key];
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
exports.ServiceClient = ServiceClient;
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AAAA,8CAAuD;AAEvD,+CAA0C;AAC1C,iCAAuC;AAEvC,iDAAiD;AACjD,MAAa,MAAM;IAAnB;QAeE;;;;mBAAM,IAAI,kBAAQ,EAAE;WAAA;IAmCtB,CAAC;IAjDC,kBAAkB;IAClB,IAAI,KAAK;QACP,MAAM,IAAI,KA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AC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAA;YAC1E,OAAO,KAAK,CAAC,IAAI,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,CAAC,CAAA;QAC9D,CAAC,EAAE,UAAU,CAAC,GAAG,CAAC,CAAA;QANlB;;;;mBAAO,UAAU;WAAQ;QAJ3B;;;;;WAAQ;QACR;;;;mBAAkC,EAAE;WAAA;QAUlC,IAAI,CAAC,GAAG,GAAG,OAAO,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAA;IAC9E,CAAC;IAED,SAAS,CAAC,GAAW,EAAE,KAAa;QAClC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;IAC3B,CAAC;IAED,WAAW,CAAC,GAAW;QACrB,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IAC1B,CAAC;CACF;AAtBD,sCAsBC"}
|
package/dist/fetch-handler.d.ts
CHANGED
|
@@ -29,5 +29,5 @@ export type BuildFetchHandlerOptions = {
|
|
|
29
29
|
*/
|
|
30
30
|
fetch?: typeof globalThis.fetch;
|
|
31
31
|
};
|
|
32
|
-
export declare function buildFetchHandler(options: FetchHandlerOptions): FetchHandler;
|
|
32
|
+
export declare function buildFetchHandler(options: FetchHandler | FetchHandlerOptions): FetchHandler;
|
|
33
33
|
//# sourceMappingURL=fetch-handler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-handler.d.ts","sourceRoot":"","sources":["../src/fetch-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAGlC,MAAM,MAAM,YAAY,GAAG,CACzB,IAAI,EAAE,IAAI;AACV;;;;GAIG;AACH,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,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ler.js
CHANGED
|
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.buildFetchHandler = void 0;
|
|
4
4
|
const util_1 = require("./util");
|
|
5
5
|
function buildFetchHandler(options) {
|
|
6
|
+
// Already a fetch handler (allowed for convenience)
|
|
7
|
+
if (typeof options === 'function')
|
|
8
|
+
return options;
|
|
6
9
|
const { service, headers: defaultHeaders = undefined, fetch = globalThis.fetch, } = typeof options === 'string' || options instanceof URL
|
|
7
10
|
? { service: options }
|
|
8
11
|
: options;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-handler.js","sourceRoot":"","sources":["../src/fetch-handler.ts"],"names":[],"mappings":";;;AACA,iCAAuC;AAwCvC,SAAgB,iBAAiB,
|
|
1
|
+
{"version":3,"file":"fetch-handler.js","sourceRoot":"","sources":["../src/fetch-handler.ts"],"names":[],"mappings":";;;AACA,iCAAuC;AAwCvC,SAAgB,iBAAiB,CAC/B,OAA2C;IAE3C,oDAAoD;IACpD,IAAI,OAAO,OAAO,KAAK,UAAU;QAAE,OAAO,OAAO,CAAA;IAEjD,MAAM,EACJ,OAAO,EACP,OAAO,EAAE,cAAc,GAAG,SAAS,EACnC,KAAK,GAAG,UAAU,CAAC,KAAK,GACzB,GAAG,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,YAAY,GAAG;QACvD,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE;QACtB,CAAC,CAAC,OAAO,CAAA;IAEX,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;QAChC,MAAM,IAAI,SAAS,CACjB,sEAAsE,CACvE,CAAA;IACH,CAAC;IAED,MAAM,qBAAqB,GACzB,cAAc,IAAI,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IAErE,OAAO,KAAK,WAAW,GAAG,EAAE,IAAI;QAC9B,MAAM,IAAI,G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AE,MAAM,EACZ,MAAM,EAAE,gBAAgB,GAAG,YAAY,EACvC,MAAM,CAAC,EAAE,WAAW,GACnB,MAAM,CA6BR;AAED,wBAAgB,gBAAgB,CAC9B,IAAI,EACA,QAAQ,GACR,OAAO,GACP,SAAS,GACT,SAAS,GACT,UAAU,GACV,OAAO,GACP,SAAS,EACb,KAAK,EAAE,GAAG,GACT,MAAM,CAiBR;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,gBAAgB,GAAG,YAAY,EACvC,IAAI,CAAC,EAAE,OAAO,EACd,IAAI,CAAC,EAAE,WAAW,GACjB,OAAO,CAoET;AAED,wBAAgB,cAAc,CAC5B,WAAW,EAAE,SAAS,GAAG,WAAW,EACpC,cAAc,CAAC,EAAE,QAAQ,CAAC,CAAC,MAAM,EAAE,SAAS,GAAG,QAAQ,CAAC,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,GACvE,SAAS,GAAG,WAAW,CAuBzB;AAmBD,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAgB5D;AAED,wBAAgB,UAAU,CACxB,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,QAAQ,CAAC,OAAO,CAAC,GAAG,aAAa,CAAC,OAAO,CAAC,CAMrD;AAED,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,OAAO,EAChB,IAAI,CAAC,EAAE,OAAO,GACb,QAAQ,GAAG,SAAS,CAqEtB;AAwBD,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,MAAM,GAAG,IAAI,EACvB,IAAI,EAAE,WAAW,GAAG,SAAS,GAC5B,GAAG,CAwBL"}
|
package/dist/util.js
CHANGED
|
@@ -147,22 +147,22 @@ function combineHeaders(headersInit, defaultHeaders) {
|
|
|
147
147
|
if (!defaultHeaders)
|
|
148
148
|
return headersInit;
|
|
149
149
|
let headers = undefined;
|
|
150
|
-
for (const [
|
|
150
|
+
for (const [name, definition] of defaultHeaders) {
|
|
151
151
|
// Ignore undefined values (allowed for convenience when using
|
|
152
152
|
// Object.entries).
|
|
153
|
-
if (
|
|
153
|
+
if (definition === undefined)
|
|
154
154
|
continue;
|
|
155
155
|
// Lazy initialization of the headers object
|
|
156
156
|
headers ?? (headers = new Headers(headersInit));
|
|
157
|
-
if (headers.has(
|
|
157
|
+
if (headers.has(name))
|
|
158
158
|
continue;
|
|
159
|
-
const value = typeof
|
|
159
|
+
const value = typeof definition === 'function' ? definition() : definition;
|
|
160
160
|
if (typeof value === 'string')
|
|
161
|
-
headers.set(
|
|
161
|
+
headers.set(name, value);
|
|
162
162
|
else if (value === null)
|
|
163
|
-
headers.delete(
|
|
163
|
+
headers.delete(name);
|
|
164
164
|
else
|
|
165
|
-
throw new TypeError(`Invalid "${
|
|
165
|
+
throw new TypeError(`Invalid "${name}" header value: ${typeof value}`);
|
|
166
166
|
}
|
|
167
167
|
return headers ?? headersInit;
|
|
168
168
|
}
|
|
@@ -266,78 +266,13 @@ function iterableToReadableStream(iterable) {
|
|
|
266
266
|
if ('from' in ReadableStream && typeof ReadableStream.from === 'function') {
|
|
267
267
|
return ReadableStream.from(iterable);
|
|
268
268
|
}
|
|
269
|
-
//
|
|
270
|
-
//
|
|
271
|
-
//
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
let generator;
|
|
276
|
-
return new ReadableStream({
|
|
277
|
-
type: 'bytes',
|
|
278
|
-
start() {
|
|
279
|
-
// Wrap the iterable in an async generator to handle both sync and async
|
|
280
|
-
// iterables, and make sure that the return() method exists.
|
|
281
|
-
generator = (async function* () {
|
|
282
|
-
yield* iterable;
|
|
283
|
-
})();
|
|
284
|
-
},
|
|
285
|
-
async pull(controller) {
|
|
286
|
-
const { done, value } = await generator.next();
|
|
287
|
-
if (done) {
|
|
288
|
-
controller.close();
|
|
289
|
-
}
|
|
290
|
-
else {
|
|
291
|
-
try {
|
|
292
|
-
const buf = toUint8Array(value);
|
|
293
|
-
if (buf)
|
|
294
|
-
controller.enqueue(buf);
|
|
295
|
-
}
|
|
296
|
-
catch (cause) {
|
|
297
|
-
// ReadableStream won't call cancel() if the stream is errored.
|
|
298
|
-
await generator.return();
|
|
299
|
-
controller.error(new TypeError('Converting iterable body to ReadableStream requires Buffer, ArrayBuffer or string values', { cause }));
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
},
|
|
303
|
-
async cancel() {
|
|
304
|
-
await generator.return();
|
|
305
|
-
},
|
|
306
|
-
});
|
|
269
|
+
// If you see this error, consider using a polyfill for ReadableStream. For
|
|
270
|
+
// example, the "web-streams-polyfill" package:
|
|
271
|
+
// https://github.com/MattiasBuelens/web-streams-polyfill
|
|
272
|
+
throw new TypeError('ReadableStream.from() is not supported in this environment. ' +
|
|
273
|
+
'It is required to support using iterables as the request body. ' +
|
|
274
|
+
'Consider using a polyfill or re-write your code to use a different body type.');
|
|
307
275
|
}
|
|
308
|
-
// Browsers don't have Buffer. This syntax is to avoid bundlers from including
|
|
309
|
-
// a Buffer polyfill in the bundle if it's not used elsewhere.
|
|
310
|
-
const globalName = `${{ toString: () => 'Buf' }}fer`;
|
|
311
|
-
const Buffer = typeof globalThis[globalName] === 'function'
|
|
312
|
-
? globalThis[globalName]
|
|
313
|
-
: undefined;
|
|
314
|
-
const toUint8Array = Buffer
|
|
315
|
-
? (value) => {
|
|
316
|
-
// @ts-expect-error Buffer.from will throw if value is not a valid input
|
|
317
|
-
const buf = Buffer.isBuffer(value) ? value : Buffer.from(value);
|
|
318
|
-
return buf.byteLength ? new Uint8Array(buf) : undefined;
|
|
319
|
-
}
|
|
320
|
-
: (value) => {
|
|
321
|
-
if (value instanceof ArrayBuffer) {
|
|
322
|
-
const buf = new Uint8Array(value);
|
|
323
|
-
return buf.byteLength ? buf : undefined;
|
|
324
|
-
}
|
|
325
|
-
// Simulate Buffer.from() behavior for strings and and coercion
|
|
326
|
-
if (typeof value === 'string') {
|
|
327
|
-
return value.length ? new TextEncoder().encode(value) : undefined;
|
|
328
|
-
}
|
|
329
|
-
else if (typeof value?.valueOf === 'function') {
|
|
330
|
-
const coerced = value.valueOf();
|
|
331
|
-
if (coerced instanceof ArrayBuffer) {
|
|
332
|
-
const buf = new Uint8Array(coerced);
|
|
333
|
-
return buf.byteLength ? buf : undefined;
|
|
334
|
-
}
|
|
335
|
-
else if (typeof coerced === 'string') {
|
|
336
|
-
return coerced.length ? new TextEncoder().encode(coerced) : undefined;
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
throw new TypeError(`Unable to convert "${typeof value}" to Uint8Array`);
|
|
340
|
-
};
|
|
341
276
|
function httpResponseBodyParse(mimeType, data) {
|
|
342
277
|
try {
|
|
343
278
|
if (mimeType) {
|
package/dist/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;;AAAA,8CAKyB;AACzB,mCAQgB;AAEhB,MAAM,cAAc,GAClB,UAAU,CAAC,cAAc;IACxB;QACC;YACE,yEAAyE;YACzE,mBAAmB;YACnB,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAA;QACxE,CAAC;KACmC,CAAA;AAExC,SAAgB,mBAAmB,CAAC,CAAU;IAC5C,OAAO,yBAAiB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,OAAO,CAAA;AAC/C,CAAC;AAFD,kDAEC;AAED,SAAgB,yBAAyB,CACvC,MAAuC;IAEvC,IAAI,MAAM,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;QAChC,OAAO,MAAM,CAAA;IACf,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC;AAPD,8DAOC;AAED,SAAgB,sBAAsB,CACpC,IAAY,EACZ,MAAuC,EACvC,UAAe,EACf,MAAoB;IAEpB,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,UAAU,CAAC,CAAA;IAC7E,OAAO,GAAG,CAA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 import { CallOptions, QueryParams, XRPCResponse } from './types';
|
|
|
4
4
|
export declare class XrpcClient {
|
|
5
5
|
readonly fetchHandler: FetchHandler;
|
|
6
6
|
readonly lex: Lexicons;
|
|
7
|
-
constructor(
|
|
7
|
+
constructor(fetchHandlerOpts: FetchHandler | FetchHandlerOptions, lex: Lexicons | Iterable<LexiconDoc>);
|
|
8
8
|
call(methodNsid: string, params?: QueryParams, data?: unknown, opts?: CallOptions): Promise<XRPCResponse>;
|
|
9
9
|
}
|
|
10
10
|
//# sourceMappingURL=xrpc-client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xrpc-client.d.ts","sourceRoot":"","sources":["../src/xrpc-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAmB,MAAM,kBAAkB,CAAA;AACxE,OAAO,EACL,YAAY,EACZ,mBAAmB,EAEpB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,WAAW,EACX,WAAW,EAIX,YAAY,EAEb,MAAM,SAAS,CAAA;AAUhB,qBAAa,UAAU;IACrB,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAA;IACnC,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAA;gBAGpB,
|
|
1
|
+
{"version":3,"file":"xrpc-client.d.ts","sourceRoot":"","sources":["../src/xrpc-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAmB,MAAM,kBAAkB,CAAA;AACxE,OAAO,EACL,YAAY,EACZ,mBAAmB,EAEpB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,WAAW,EACX,WAAW,EAIX,YAAY,EAEb,MAAM,SAAS,CAAA;AAUhB,qBAAa,UAAU;IACrB,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAA;IACnC,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAA;gBAGpB,gBAAgB,EAAE,YAAY,GAAG,mBAAmB,EAGpD,GAAG,EAAE,QAAQ,GAAG,QAAQ,CAAC,UAAU,CAAC;IAOhC,IAAI,CACR,UAAU,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,WAAW,EACpB,IAAI,CAAC,EAAE,OAAO,EACd,IAAI,CAAC,EAAE,WAAW,GACjB,OAAO,CAAC,YAAY,CAAC;CA8DzB"}
|
package/dist/xrpc-client.js
CHANGED
|
@@ -6,7 +6,10 @@ const fetch_handler_1 = require("./fetch-handler");
|
|
|
6
6
|
const types_1 = require("./types");
|
|
7
7
|
const util_1 = require("./util");
|
|
8
8
|
class XrpcClient {
|
|
9
|
-
constructor(
|
|
9
|
+
constructor(fetchHandlerOpts,
|
|
10
|
+
// "Lexicons" is redundant here (because that class implements
|
|
11
|
+
// "Iterable<LexiconDoc>") but we keep it for explicitness:
|
|
12
|
+
lex) {
|
|
10
13
|
Object.defineProperty(this, "fetchHandler", {
|
|
11
14
|
enumerable: true,
|
|
12
15
|
configurable: true,
|
|
@@ -19,10 +22,7 @@ class XrpcClient {
|
|
|
19
22
|
writable: true,
|
|
20
23
|
value: void 0
|
|
21
24
|
});
|
|
22
|
-
this.fetchHandler =
|
|
23
|
-
typeof fetchHandler === 'function'
|
|
24
|
-
? fetchHandler
|
|
25
|
-
: (0, fetch_handler_1.buildFetchHandler)(fetchHandler);
|
|
25
|
+
this.fetchHandler = (0, fetch_handler_1.buildFetchHandler)(fetchHandlerOpts);
|
|
26
26
|
this.lex = lex instanceof lexicon_1.Lexicons ? lex : new lexicon_1.Lexicons(lex);
|
|
27
27
|
}
|
|
28
28
|
async call(methodNsid, params, data, opts) {
|
|
@@ -30,7 +30,7 @@ class XrpcClient {
|
|
|
30
30
|
if (!def || (def.type !== 'query' && def.type !== 'procedure')) {
|
|
31
31
|
throw new TypeError(`Invalid lexicon: ${methodNsid}. Must be a query or procedure.`);
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
// @TODO: should we validate the params and data here?
|
|
34
34
|
// this.lex.assertValidXrpcParams(methodNsid, params)
|
|
35
35
|
// if (data !== undefined) {
|
|
36
36
|
// this.lex.assertValidXrpcInput(methodNsid, data)
|
package/dist/xrpc-client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xrpc-client.js","sourceRoot":"","sources":["../src/xrpc-client.ts"],"names":[],"mappings":";;;AAAA,8CAAwE;AACxE,mDAIwB;AACxB,mCAQgB;AAChB,iCAOe;AAEf,MAAa,UAAU;IAIrB,YACE,
|
|
1
|
+
{"version":3,"file":"xrpc-client.js","sourceRoot":"","sources":["../src/xrpc-client.ts"],"names":[],"mappings":";;;AAAA,8CAAwE;AACxE,mDAIwB;AACxB,mCAQgB;AAChB,iCAOe;AAEf,MAAa,UAAU;IAIrB,YACE,gBAAoD;IACpD,8DAA8D;IAC9D,2DAA2D;IAC3D,GAAoC;QAP7B;;;;;WAA0B;QAC1B;;;;;WAAa;QAQpB,IAAI,CAAC,YAAY,GAAG,IAAA,iCAAiB,EAAC,gBAAgB,CAAC,CAAA;QAEvD,IAAI,CAAC,GAAG,GAAG,GAAG,YAAY,kBAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,kBAAQ,CAAC,GAAG,CAAC,CAAA;IAC9D,CAAC;IAED,KAAK,CAAC,IAAI,CACR,UAAkB,EAClB,MAAoB,EACpB,IAAc,EACd,IAAkB;QAElB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,UAAU,CAAC,CAAA;QAC9C,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,KAAK,OAAO,IAAI,GAAG,CAAC,IAAI,KAAK,WAAW,CAAC,EAAE,CAAC;YAC/D,MAAM,IAAI,SAAS,CACjB,oBAAoB,UAAU,iCAAiC,CAChE,CAAA;QACH,CAAC;QAED,sDAAsD;QACtD,qDAAqD;QACrD,4BAA4B;QAC5B,oDAAoD;QACpD,IAAI;QAEJ,MAAM,MAAM,GAAG,IAAA,6BAAsB,EAAC,UAAU,E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C,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,CAAC,CAAA;YAC1D,CAAC;YAED,IAAI,CAAC;gBACH,IAAI,CAAC,GAAG,CAAC,qBAAqB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;YACrD,CAAC;YAAC,OAAO,CAAU,EAAE,CAAC;gBACpB,IAAI,CAAC,YAAY,yBAAe,EAAE,CAAC;oBACjC,MAAM,IAAI,gCAAwB,CAAC,UAAU,EAAE,CAAC,EAAE,OAAO,CAAC,CAAA;gBAC5D,CAAC;gBAED,MAAM,CAAC,CAAA;YACT,CAAC;YAED,OAAO,IAAI,oBAAY,CAAC,OAAO,EAAE,UAAU,CAAC,CAAA;QAC9C,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,iBAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAC3B,CAAC;IACH,CAAC;CACF;AAlFD,gCAkFC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atproto/xrpc",
|
|
3
|
-
"version": "0.6.0
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "atproto HTTP API (XRPC) client library",
|
|
6
6
|
"keywords": [
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"types": "dist/index.d.ts",
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"zod": "^3.23.8",
|
|
20
|
-
"@atproto/lexicon": "^0.4.1
|
|
20
|
+
"@atproto/lexicon": "^0.4.1"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"typescript": "^5.3.3"
|
package/src/client.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LexiconDoc, Lexicons } from '@atproto/lexicon'
|
|
2
|
-
import { CallOptions,
|
|
2
|
+
import { CallOptions, QueryParams } from './types'
|
|
3
3
|
import { XrpcClient } from './xrpc-client'
|
|
4
4
|
import { combineHeaders } from './util'
|
|
5
5
|
|
|
@@ -59,24 +59,24 @@ export class Client {
|
|
|
59
59
|
/** @deprecated Use {@link XrpcClient} instead */
|
|
60
60
|
export class ServiceClient extends XrpcClient {
|
|
61
61
|
uri: URL
|
|
62
|
-
|
|
62
|
+
headers: Record<string, string> = {}
|
|
63
63
|
|
|
64
64
|
constructor(
|
|
65
65
|
public baseClient: Client,
|
|
66
66
|
serviceUri: string | URL,
|
|
67
67
|
) {
|
|
68
68
|
super(async (input, init) => {
|
|
69
|
-
const headers = combineHeaders(init.headers, this.headers)
|
|
69
|
+
const headers = combineHeaders(init.headers, Object.entries(this.headers))
|
|
70
70
|
return fetch(new URL(input, this.uri), { ...init, headers })
|
|
71
71
|
}, baseClient.lex)
|
|
72
72
|
this.uri = typeof serviceUri === 'string' ? new URL(serviceUri) : serviceUri
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
setHeader(key: string, value:
|
|
76
|
-
this.headers
|
|
75
|
+
setHeader(key: string, value: string): void {
|
|
76
|
+
this.headers[key] = value
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
unsetHeader(key: string): void {
|
|
80
|
-
this.headers
|
|
80
|
+
delete this.headers[key]
|
|
81
81
|
}
|
|
82
82
|
}
|
package/src/fetch-handler.ts
CHANGED
|
@@ -39,7 +39,12 @@ export type BuildFetchHandlerOptions = {
|
|
|
39
39
|
fetch?: typeof globalThis.fetch
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
export function buildFetchHandler(
|
|
42
|
+
export function buildFetchHandler(
|
|
43
|
+
options: FetchHandler | FetchHandlerOptions,
|
|
44
|
+
): FetchHandler {
|
|
45
|
+
// Already a fetch handler (allowed for convenience)
|
|
46
|
+
if (typeof options === 'function') return options
|
|
47
|
+
|
|
43
48
|
const {
|
|
44
49
|
service,
|
|
45
50
|
headers: defaultHeaders = undefined,
|
package/src/util.ts
CHANGED
|
@@ -193,21 +193,21 @@ export function combineHeaders(
|
|
|
193
193
|
|
|
194
194
|
let headers: Headers | undefined = undefined
|
|
195
195
|
|
|
196
|
-
for (const [
|
|
196
|
+
for (const [name, definition] of defaultHeaders) {
|
|
197
197
|
// Ignore undefined values (allowed for convenience when using
|
|
198
198
|
// Object.entries).
|
|
199
|
-
if (
|
|
199
|
+
if (definition === undefined) continue
|
|
200
200
|
|
|
201
201
|
// Lazy initialization of the headers object
|
|
202
202
|
headers ??= new Headers(headersInit)
|
|
203
203
|
|
|
204
|
-
if (headers.has(
|
|
204
|
+
if (headers.has(name)) continue
|
|
205
205
|
|
|
206
|
-
const value = typeof
|
|
206
|
+
const value = typeof definition === 'function' ? definition() : definition
|
|
207
207
|
|
|
208
|
-
if (typeof value === 'string') headers.set(
|
|
209
|
-
else if (value === null) headers.delete(
|
|
210
|
-
else throw new TypeError(`Invalid "${
|
|
208
|
+
if (typeof value === 'string') headers.set(name, value)
|
|
209
|
+
else if (value === null) headers.delete(name)
|
|
210
|
+
else throw new TypeError(`Invalid "${name}" header value: ${typeof value}`)
|
|
211
211
|
}
|
|
212
212
|
|
|
213
213
|
return headers ?? headersInit
|
|
@@ -343,85 +343,16 @@ function iterableToReadableStream(
|
|
|
343
343
|
return ReadableStream.from(iterable)
|
|
344
344
|
}
|
|
345
345
|
|
|
346
|
-
//
|
|
347
|
-
//
|
|
348
|
-
//
|
|
349
|
-
// things simple, we'll just allow the anonymous ReadableStream constructor
|
|
350
|
-
// to throw an error in those environments, hinting the user of the lib to find
|
|
351
|
-
// an alternate solution in that case (e.g. use a Blob if available).
|
|
352
|
-
|
|
353
|
-
let generator: AsyncGenerator<unknown, void, undefined>
|
|
354
|
-
return new ReadableStream<Uint8Array>({
|
|
355
|
-
type: 'bytes',
|
|
356
|
-
start() {
|
|
357
|
-
// Wrap the iterable in an async generator to handle both sync and async
|
|
358
|
-
// iterables, and make sure that the return() method exists.
|
|
359
|
-
generator = (async function* () {
|
|
360
|
-
yield* iterable
|
|
361
|
-
})()
|
|
362
|
-
},
|
|
363
|
-
async pull(controller: ReadableStreamDefaultController) {
|
|
364
|
-
const { done, value } = await generator.next()
|
|
365
|
-
if (done) {
|
|
366
|
-
controller.close()
|
|
367
|
-
} else {
|
|
368
|
-
try {
|
|
369
|
-
const buf = toUint8Array(value)
|
|
370
|
-
if (buf) controller.enqueue(buf)
|
|
371
|
-
} catch (cause) {
|
|
372
|
-
// ReadableStream won't call cancel() if the stream is errored.
|
|
373
|
-
await generator.return()
|
|
374
|
-
|
|
375
|
-
controller.error(
|
|
376
|
-
new TypeError(
|
|
377
|
-
'Converting iterable body to ReadableStream requires Buffer, ArrayBuffer or string values',
|
|
378
|
-
{ cause },
|
|
379
|
-
),
|
|
380
|
-
)
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
},
|
|
384
|
-
async cancel() {
|
|
385
|
-
await generator.return()
|
|
386
|
-
},
|
|
387
|
-
})
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
// Browsers don't have Buffer. This syntax is to avoid bundlers from including
|
|
391
|
-
// a Buffer polyfill in the bundle if it's not used elsewhere.
|
|
392
|
-
const globalName = `${{ toString: () => 'Buf' }}fer` as 'Buffer'
|
|
393
|
-
const Buffer =
|
|
394
|
-
typeof globalThis[globalName] === 'function'
|
|
395
|
-
? globalThis[globalName]
|
|
396
|
-
: undefined
|
|
397
|
-
|
|
398
|
-
const toUint8Array: (value: unknown) => Uint8Array | undefined = Buffer
|
|
399
|
-
? (value) => {
|
|
400
|
-
// @ts-expect-error Buffer.from will throw if value is not a valid input
|
|
401
|
-
const buf = Buffer.isBuffer(value) ? value : Buffer.from(value)
|
|
402
|
-
return buf.byteLength ? new Uint8Array(buf) : undefined
|
|
403
|
-
}
|
|
404
|
-
: (value) => {
|
|
405
|
-
if (value instanceof ArrayBuffer) {
|
|
406
|
-
const buf = new Uint8Array(value)
|
|
407
|
-
return buf.byteLength ? buf : undefined
|
|
408
|
-
}
|
|
346
|
+
// If you see this error, consider using a polyfill for ReadableStream. For
|
|
347
|
+
// example, the "web-streams-polyfill" package:
|
|
348
|
+
// https://github.com/MattiasBuelens/web-streams-polyfill
|
|
409
349
|
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
const buf = new Uint8Array(coerced)
|
|
417
|
-
return buf.byteLength ? buf : undefined
|
|
418
|
-
} else if (typeof coerced === 'string') {
|
|
419
|
-
return coerced.length ? new TextEncoder().encode(coerced) : undefined
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
throw new TypeError(`Unable to convert "${typeof value}" to Uint8Array`)
|
|
424
|
-
}
|
|
350
|
+
throw new TypeError(
|
|
351
|
+
'ReadableStream.from() is not supported in this environment. ' +
|
|
352
|
+
'It is required to support using iterables as the request body. ' +
|
|
353
|
+
'Consider using a polyfill or re-write your code to use a different body type.',
|
|
354
|
+
)
|
|
355
|
+
}
|
|
425
356
|
|
|
426
357
|
export function httpResponseBodyParse(
|
|
427
358
|
mimeType: string | null,
|
package/src/xrpc-client.ts
CHANGED
|
@@ -27,13 +27,12 @@ export class XrpcClient {
|
|
|
27
27
|
readonly lex: Lexicons
|
|
28
28
|
|
|
29
29
|
constructor(
|
|
30
|
-
|
|
30
|
+
fetchHandlerOpts: FetchHandler | FetchHandlerOptions,
|
|
31
|
+
// "Lexicons" is redundant here (because that class implements
|
|
32
|
+
// "Iterable<LexiconDoc>") but we keep it for explicitness:
|
|
31
33
|
lex: Lexicons | Iterable<LexiconDoc>,
|
|
32
34
|
) {
|
|
33
|
-
this.fetchHandler =
|
|
34
|
-
typeof fetchHandler === 'function'
|
|
35
|
-
? fetchHandler
|
|
36
|
-
: buildFetchHandler(fetchHandler)
|
|
35
|
+
this.fetchHandler = buildFetchHandler(fetchHandlerOpts)
|
|
37
36
|
|
|
38
37
|
this.lex = lex instanceof Lexicons ? lex : new Lexicons(lex)
|
|
39
38
|
}
|
|
@@ -51,7 +50,7 @@ export class XrpcClient {
|
|
|
51
50
|
)
|
|
52
51
|
}
|
|
53
52
|
|
|
54
|
-
|
|
53
|
+
// @TODO: should we validate the params and data here?
|
|
55
54
|
// this.lex.assertValidXrpcParams(methodNsid, params)
|
|
56
55
|
// if (data !== undefined) {
|
|
57
56
|
// this.lex.assertValidXrpcInput(methodNsid, data)
|