@atproto/xrpc 0.7.6 → 0.7.7
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 +97 -90
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @atproto/xrpc
|
|
2
2
|
|
|
3
|
+
## 0.7.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`d551b0e`](https://github.com/bluesky-social/atproto/commit/d551b0e3527714c111c3ec6e4c90ad7f46369fab)]:
|
|
8
|
+
- @atproto/lexicon@0.6.0
|
|
9
|
+
|
|
3
10
|
## 0.7.6
|
|
4
11
|
|
|
5
12
|
### Patch Changes
|
|
@@ -190,7 +197,7 @@
|
|
|
190
197
|
`AtpAgent`.
|
|
191
198
|
|
|
192
199
|
```ts
|
|
193
|
-
import { Agent, AtpAgent } from
|
|
200
|
+
import { Agent, AtpAgent } from '@atproto/api'
|
|
194
201
|
|
|
195
202
|
async function setupAgent(
|
|
196
203
|
service: string,
|
|
@@ -202,30 +209,30 @@
|
|
|
202
209
|
persistSession: (evt, session) => {
|
|
203
210
|
// handle session update
|
|
204
211
|
},
|
|
205
|
-
})
|
|
212
|
+
})
|
|
206
213
|
|
|
207
|
-
await agent.login(username, password)
|
|
214
|
+
await agent.login(username, password)
|
|
208
215
|
|
|
209
|
-
return agent
|
|
216
|
+
return agent
|
|
210
217
|
}
|
|
211
218
|
```
|
|
212
219
|
|
|
213
220
|
```ts
|
|
214
|
-
import { Agent } from
|
|
221
|
+
import { Agent } from '@atproto/api'
|
|
215
222
|
|
|
216
223
|
async function doStuffWithAgent(agent: Agent, arg: string) {
|
|
217
|
-
return agent.resolveHandle(arg)
|
|
224
|
+
return agent.resolveHandle(arg)
|
|
218
225
|
}
|
|
219
226
|
```
|
|
220
227
|
|
|
221
228
|
```ts
|
|
222
|
-
import { Agent, AtpAgent } from
|
|
229
|
+
import { Agent, AtpAgent } from '@atproto/api'
|
|
223
230
|
|
|
224
231
|
class MyClass {
|
|
225
|
-
agent: Agent
|
|
232
|
+
agent: Agent
|
|
226
233
|
|
|
227
234
|
constructor() {
|
|
228
|
-
this.agent = new AtpAgent()
|
|
235
|
+
this.agent = new AtpAgent()
|
|
229
236
|
}
|
|
230
237
|
}
|
|
231
238
|
```
|
|
@@ -303,24 +310,24 @@
|
|
|
303
310
|
<td>
|
|
304
311
|
|
|
305
312
|
```ts
|
|
306
|
-
import { AtpBaseClient, ComAtprotoSyncSubscribeRepos } from
|
|
313
|
+
import { AtpBaseClient, ComAtprotoSyncSubscribeRepos } from '@atproto/api'
|
|
307
314
|
|
|
308
|
-
const baseClient = new AtpBaseClient()
|
|
315
|
+
const baseClient = new AtpBaseClient()
|
|
309
316
|
|
|
310
|
-
baseClient.xrpc.lex.assertValidXrpcMessage(
|
|
317
|
+
baseClient.xrpc.lex.assertValidXrpcMessage('io.example.doStuff', {
|
|
311
318
|
// ...
|
|
312
|
-
})
|
|
319
|
+
})
|
|
313
320
|
```
|
|
314
321
|
|
|
315
322
|
</td>
|
|
316
323
|
<td>
|
|
317
324
|
|
|
318
325
|
```ts
|
|
319
|
-
import { lexicons } from
|
|
326
|
+
import { lexicons } from '@atproto/api'
|
|
320
327
|
|
|
321
|
-
lexicons.assertValidXrpcMessage(
|
|
328
|
+
lexicons.assertValidXrpcMessage('io.example.doStuff', {
|
|
322
329
|
// ...
|
|
323
|
-
})
|
|
330
|
+
})
|
|
324
331
|
```
|
|
325
332
|
|
|
326
333
|
</td>
|
|
@@ -337,23 +344,23 @@
|
|
|
337
344
|
<td>
|
|
338
345
|
|
|
339
346
|
```ts
|
|
340
|
-
import { BskyAgent } from
|
|
347
|
+
import { BskyAgent } from '@atproto/api'
|
|
341
348
|
|
|
342
349
|
class MyAgent extends BskyAgent {
|
|
343
|
-
private accessToken?: string
|
|
350
|
+
private accessToken?: string
|
|
344
351
|
|
|
345
352
|
async createOrRefreshSession(identifier: string, password: string) {
|
|
346
353
|
// custom logic here
|
|
347
354
|
|
|
348
|
-
this.accessToken =
|
|
355
|
+
this.accessToken = 'my-access-jwt'
|
|
349
356
|
}
|
|
350
357
|
|
|
351
358
|
async doStuff() {
|
|
352
|
-
return this.call(
|
|
359
|
+
return this.call('io.example.doStuff', {
|
|
353
360
|
headers: {
|
|
354
361
|
Authorization: this.accessToken && `Bearer ${this.accessToken}`,
|
|
355
362
|
},
|
|
356
|
-
})
|
|
363
|
+
})
|
|
357
364
|
}
|
|
358
365
|
}
|
|
359
366
|
```
|
|
@@ -362,11 +369,11 @@
|
|
|
362
369
|
<td>
|
|
363
370
|
|
|
364
371
|
```ts
|
|
365
|
-
import { Agent } from
|
|
372
|
+
import { Agent } from '@atproto/api'
|
|
366
373
|
|
|
367
374
|
class MyAgent extends Agent {
|
|
368
|
-
private accessToken?: string
|
|
369
|
-
public did?: string
|
|
375
|
+
private accessToken?: string
|
|
376
|
+
public did?: string
|
|
370
377
|
|
|
371
378
|
constructor(private readonly service: string | URL) {
|
|
372
379
|
super({
|
|
@@ -375,21 +382,21 @@
|
|
|
375
382
|
Authorization: () =>
|
|
376
383
|
this.accessToken ? `Bearer ${this.accessToken}` : null,
|
|
377
384
|
},
|
|
378
|
-
})
|
|
385
|
+
})
|
|
379
386
|
}
|
|
380
387
|
|
|
381
388
|
clone(): MyAgent {
|
|
382
|
-
const agent = new MyAgent(this.service)
|
|
383
|
-
agent.accessToken = this.accessToken
|
|
384
|
-
agent.did = this.did
|
|
385
|
-
return this.copyInto(agent)
|
|
389
|
+
const agent = new MyAgent(this.service)
|
|
390
|
+
agent.accessToken = this.accessToken
|
|
391
|
+
agent.did = this.did
|
|
392
|
+
return this.copyInto(agent)
|
|
386
393
|
}
|
|
387
394
|
|
|
388
395
|
async createOrRefreshSession(identifier: string, password: string) {
|
|
389
396
|
// custom logic here
|
|
390
397
|
|
|
391
|
-
this.did =
|
|
392
|
-
this.accessToken =
|
|
398
|
+
this.did = 'did:example:123'
|
|
399
|
+
this.accessToken = 'my-access-jwt'
|
|
393
400
|
}
|
|
394
401
|
}
|
|
395
402
|
```
|
|
@@ -408,38 +415,38 @@
|
|
|
408
415
|
<td>
|
|
409
416
|
|
|
410
417
|
```ts
|
|
411
|
-
import { BskyAgent } from
|
|
412
|
-
import { RateLimitThreshold } from
|
|
418
|
+
import { BskyAgent } from '@atproto/api'
|
|
419
|
+
import { RateLimitThreshold } from 'rate-limit-threshold'
|
|
413
420
|
|
|
414
|
-
const agent = new BskyAgent()
|
|
415
|
-
const limiter = new RateLimitThreshold(3000, 300_000)
|
|
421
|
+
const agent = new BskyAgent()
|
|
422
|
+
const limiter = new RateLimitThreshold(3000, 300_000)
|
|
416
423
|
|
|
417
|
-
const origCall = agent.api.xrpc.call
|
|
424
|
+
const origCall = agent.api.xrpc.call
|
|
418
425
|
agent.api.xrpc.call = async function (...args) {
|
|
419
|
-
await limiter.wait()
|
|
420
|
-
return origCall.call(this, ...args)
|
|
421
|
-
}
|
|
426
|
+
await limiter.wait()
|
|
427
|
+
return origCall.call(this, ...args)
|
|
428
|
+
}
|
|
422
429
|
```
|
|
423
430
|
|
|
424
431
|
</td>
|
|
425
432
|
<td>
|
|
426
433
|
|
|
427
434
|
```ts
|
|
428
|
-
import { AtpAgent } from
|
|
429
|
-
import { RateLimitThreshold } from
|
|
435
|
+
import { AtpAgent } from '@atproto/api'
|
|
436
|
+
import { RateLimitThreshold } from 'rate-limit-threshold'
|
|
430
437
|
|
|
431
438
|
class LimitedAtpAgent extends AtpAgent {
|
|
432
439
|
constructor(options: AtpAgentOptions) {
|
|
433
|
-
const fetch: typeof globalThis.fetch = options.fetch ?? globalThis.fetch
|
|
434
|
-
const limiter = new RateLimitThreshold(3000, 300_000)
|
|
440
|
+
const fetch: typeof globalThis.fetch = options.fetch ?? globalThis.fetch
|
|
441
|
+
const limiter = new RateLimitThreshold(3000, 300_000)
|
|
435
442
|
|
|
436
443
|
super({
|
|
437
444
|
...options,
|
|
438
445
|
fetch: async (...args) => {
|
|
439
|
-
await limiter.wait()
|
|
440
|
-
return fetch(...args)
|
|
446
|
+
await limiter.wait()
|
|
447
|
+
return fetch(...args)
|
|
441
448
|
},
|
|
442
|
-
})
|
|
449
|
+
})
|
|
443
450
|
}
|
|
444
451
|
}
|
|
445
452
|
```
|
|
@@ -460,40 +467,40 @@
|
|
|
460
467
|
<td>
|
|
461
468
|
|
|
462
469
|
```ts
|
|
463
|
-
import { BskyAgent, defaultFetchHandler } from
|
|
470
|
+
import { BskyAgent, defaultFetchHandler } from '@atproto/api'
|
|
464
471
|
|
|
465
472
|
BskyAgent.configure({
|
|
466
473
|
fetch: async (httpUri, httpMethod, httpHeaders, httpReqBody) => {
|
|
467
|
-
const ua = httpHeaders[
|
|
474
|
+
const ua = httpHeaders['User-Agent']
|
|
468
475
|
|
|
469
|
-
httpHeaders[
|
|
476
|
+
httpHeaders['User-Agent'] = ua ? `${ua} ${userAgent}` : userAgent
|
|
470
477
|
|
|
471
|
-
return defaultFetchHandler(httpUri, httpMethod, httpHeaders, httpReqBody)
|
|
478
|
+
return defaultFetchHandler(httpUri, httpMethod, httpHeaders, httpReqBody)
|
|
472
479
|
},
|
|
473
|
-
})
|
|
480
|
+
})
|
|
474
481
|
```
|
|
475
482
|
|
|
476
483
|
</td>
|
|
477
484
|
<td>
|
|
478
485
|
|
|
479
486
|
```ts
|
|
480
|
-
import { AtpAgent } from
|
|
487
|
+
import { AtpAgent } from '@atproto/api'
|
|
481
488
|
|
|
482
489
|
class MyAtpAgent extends AtpAgent {
|
|
483
490
|
constructor(options: AtpAgentOptions) {
|
|
484
|
-
const fetch = options.fetch ?? globalThis.fetch
|
|
491
|
+
const fetch = options.fetch ?? globalThis.fetch
|
|
485
492
|
|
|
486
493
|
super({
|
|
487
494
|
...options,
|
|
488
495
|
fetch: async (url, init) => {
|
|
489
|
-
const headers = new Headers(init.headers)
|
|
496
|
+
const headers = new Headers(init.headers)
|
|
490
497
|
|
|
491
|
-
const ua = headersList.get(
|
|
492
|
-
headersList.set(
|
|
498
|
+
const ua = headersList.get('User-Agent')
|
|
499
|
+
headersList.set('User-Agent', ua ? `${ua} ${userAgent}` : userAgent)
|
|
493
500
|
|
|
494
|
-
return fetch(url, { ...init, headers })
|
|
501
|
+
return fetch(url, { ...init, headers })
|
|
495
502
|
},
|
|
496
|
-
})
|
|
503
|
+
})
|
|
497
504
|
}
|
|
498
505
|
}
|
|
499
506
|
```
|
|
@@ -552,7 +559,7 @@
|
|
|
552
559
|
*/
|
|
553
560
|
url: string,
|
|
554
561
|
init: RequestInit,
|
|
555
|
-
) => Promise<Response
|
|
562
|
+
) => Promise<Response>
|
|
556
563
|
```
|
|
557
564
|
|
|
558
565
|
A noticeable change that has been introduced is that the `uri` field of the
|
|
@@ -590,7 +597,7 @@
|
|
|
590
597
|
<td>
|
|
591
598
|
|
|
592
599
|
```ts
|
|
593
|
-
import client, { defaultFetchHandler } from
|
|
600
|
+
import client, { defaultFetchHandler } from '@atproto/xrpc'
|
|
594
601
|
|
|
595
602
|
client.fetch = function (
|
|
596
603
|
httpUri: string,
|
|
@@ -599,50 +606,50 @@
|
|
|
599
606
|
httpReqBody: unknown,
|
|
600
607
|
) {
|
|
601
608
|
// Custom logic here
|
|
602
|
-
return defaultFetchHandler(httpUri, httpMethod, httpHeaders, httpReqBody)
|
|
603
|
-
}
|
|
609
|
+
return defaultFetchHandler(httpUri, httpMethod, httpHeaders, httpReqBody)
|
|
610
|
+
}
|
|
604
611
|
|
|
605
612
|
client.addLexicon({
|
|
606
613
|
lexicon: 1,
|
|
607
|
-
id:
|
|
614
|
+
id: 'io.example.doStuff',
|
|
608
615
|
defs: {},
|
|
609
|
-
})
|
|
616
|
+
})
|
|
610
617
|
|
|
611
|
-
const instance = client.service(
|
|
618
|
+
const instance = client.service('http://my-service.com')
|
|
612
619
|
|
|
613
|
-
instance.setHeader(
|
|
620
|
+
instance.setHeader('my-header', 'my-value')
|
|
614
621
|
|
|
615
|
-
await instance.call(
|
|
622
|
+
await instance.call('io.example.doStuff')
|
|
616
623
|
```
|
|
617
624
|
|
|
618
625
|
</td>
|
|
619
626
|
<td>
|
|
620
627
|
|
|
621
628
|
```ts
|
|
622
|
-
import { XrpcClient } from
|
|
629
|
+
import { XrpcClient } from '@atproto/xrpc'
|
|
623
630
|
|
|
624
631
|
const instance = new XrpcClient(
|
|
625
632
|
async (url, init) => {
|
|
626
|
-
const headers = new Headers(init.headers)
|
|
633
|
+
const headers = new Headers(init.headers)
|
|
627
634
|
|
|
628
|
-
headers.set(
|
|
635
|
+
headers.set('my-header', 'my-value')
|
|
629
636
|
|
|
630
637
|
// Custom logic here
|
|
631
638
|
|
|
632
|
-
const fullUrl = new URL(url,
|
|
639
|
+
const fullUrl = new URL(url, 'http://my-service.com')
|
|
633
640
|
|
|
634
|
-
return fetch(fullUrl, { ...init, headers })
|
|
641
|
+
return fetch(fullUrl, { ...init, headers })
|
|
635
642
|
},
|
|
636
643
|
[
|
|
637
644
|
{
|
|
638
645
|
lexicon: 1,
|
|
639
|
-
id:
|
|
646
|
+
id: 'io.example.doStuff',
|
|
640
647
|
defs: {},
|
|
641
648
|
},
|
|
642
649
|
],
|
|
643
|
-
)
|
|
650
|
+
)
|
|
644
651
|
|
|
645
|
-
await instance.call(
|
|
652
|
+
await instance.call('io.example.doStuff')
|
|
646
653
|
```
|
|
647
654
|
|
|
648
655
|
</td>
|
|
@@ -654,62 +661,62 @@
|
|
|
654
661
|
previous example can be simplified to:
|
|
655
662
|
|
|
656
663
|
```ts
|
|
657
|
-
import { XrpcClient } from
|
|
664
|
+
import { XrpcClient } from '@atproto/xrpc'
|
|
658
665
|
|
|
659
|
-
const instance = new XrpcClient(
|
|
666
|
+
const instance = new XrpcClient('http://my-service.com', [
|
|
660
667
|
{
|
|
661
668
|
lexicon: 1,
|
|
662
|
-
id:
|
|
669
|
+
id: 'io.example.doStuff',
|
|
663
670
|
defs: {},
|
|
664
671
|
},
|
|
665
|
-
])
|
|
672
|
+
])
|
|
666
673
|
```
|
|
667
674
|
|
|
668
675
|
If you need to add static headers to all requests, you can instead instantiate
|
|
669
676
|
the `XrpcClient` as follows:
|
|
670
677
|
|
|
671
678
|
```ts
|
|
672
|
-
import { XrpcClient } from
|
|
679
|
+
import { XrpcClient } from '@atproto/xrpc'
|
|
673
680
|
|
|
674
681
|
const instance = new XrpcClient(
|
|
675
682
|
{
|
|
676
|
-
service:
|
|
683
|
+
service: 'http://my-service.com',
|
|
677
684
|
headers: {
|
|
678
|
-
|
|
685
|
+
'my-header': 'my-value',
|
|
679
686
|
},
|
|
680
687
|
},
|
|
681
688
|
[
|
|
682
689
|
{
|
|
683
690
|
lexicon: 1,
|
|
684
|
-
id:
|
|
691
|
+
id: 'io.example.doStuff',
|
|
685
692
|
defs: {},
|
|
686
693
|
},
|
|
687
694
|
],
|
|
688
|
-
)
|
|
695
|
+
)
|
|
689
696
|
```
|
|
690
697
|
|
|
691
698
|
If you need the headers or service url to be dynamic, you can define them using
|
|
692
699
|
functions:
|
|
693
700
|
|
|
694
701
|
```ts
|
|
695
|
-
import { XrpcClient } from
|
|
702
|
+
import { XrpcClient } from '@atproto/xrpc'
|
|
696
703
|
|
|
697
704
|
const instance = new XrpcClient(
|
|
698
705
|
{
|
|
699
|
-
service: () =>
|
|
706
|
+
service: () => 'http://my-service.com',
|
|
700
707
|
headers: {
|
|
701
|
-
|
|
702
|
-
|
|
708
|
+
'my-header': () => 'my-value',
|
|
709
|
+
'my-ignored-header': () => null, // ignored
|
|
703
710
|
},
|
|
704
711
|
},
|
|
705
712
|
[
|
|
706
713
|
{
|
|
707
714
|
lexicon: 1,
|
|
708
|
-
id:
|
|
715
|
+
id: 'io.example.doStuff',
|
|
709
716
|
defs: {},
|
|
710
717
|
},
|
|
711
718
|
],
|
|
712
|
-
)
|
|
719
|
+
)
|
|
713
720
|
```
|
|
714
721
|
|
|
715
722
|
- [#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.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atproto/xrpc",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.7",
|
|
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.
|
|
20
|
+
"@atproto/lexicon": "^0.6.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"typescript": "^5.6.3"
|