@atproto/xrpc 0.7.6 → 0.8.0-next.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 CHANGED
@@ -1,5 +1,31 @@
1
1
  # @atproto/xrpc
2
2
 
3
+ ## 0.8.0-next.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#4929](https://github.com/bluesky-social/atproto/pull/4929) [`bb7491c`](https://github.com/bluesky-social/atproto/commit/bb7491c29e06181e1d2f8cf6eb454f9bb8ab961b) Thanks [@devinivy](https://github.com/devinivy)! - **BREAKING:** Drop support for Node.js 18 and 20. Node.js 22 is now the minimum supported version. Docker images now use Node.js 24.
8
+
9
+ - [#4943](https://github.com/bluesky-social/atproto/pull/4943) [`07ae5d4`](https://github.com/bluesky-social/atproto/commit/07ae5d4452df51e045e0239da7a04cf0bc154028) Thanks [@devinivy](https://github.com/devinivy)! - **BREAKING:** Convert to pure ESM. All packages now ship `"type": "module"` with ES module output and Node16 module resolution.
10
+
11
+ Node.js 22's `require()` compatibility layer can still load these packages in CommonJS code.
12
+
13
+ - [#4930](https://github.com/bluesky-social/atproto/pull/4930) [`042df15`](https://github.com/bluesky-social/atproto/commit/042df15087c0e62cd1e715fcbf58852fab875af9) Thanks [@devinivy](https://github.com/devinivy)! - Build with TypeScript 6.0. Emitted `.d.ts` files now use TypeScript 6's stricter `Uint8Array<ArrayBuffer>` typing in places where Web/Node APIs require buffer-backed (not shared-memory) byte arrays. Consumers compiling against these types on older TypeScript should see no runtime impact, but may need to widen or cast in spots that previously relied on `Uint8Array` defaulting to `<ArrayBufferLike>`.
14
+
15
+ Internal: tsconfig `moduleResolution: "node"` is silenced via `ignoreDeprecations: "6.0"` for now; the proper migration to `node16`/`bundler` resolution is deferred.
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies [[`bb7491c`](https://github.com/bluesky-social/atproto/commit/bb7491c29e06181e1d2f8cf6eb454f9bb8ab961b), [`07ae5d4`](https://github.com/bluesky-social/atproto/commit/07ae5d4452df51e045e0239da7a04cf0bc154028), [`042df15`](https://github.com/bluesky-social/atproto/commit/042df15087c0e62cd1e715fcbf58852fab875af9)]:
20
+ - @atproto/lexicon@0.7.0-next.0
21
+
22
+ ## 0.7.7
23
+
24
+ ### Patch Changes
25
+
26
+ - Updated dependencies [[`d551b0e`](https://github.com/bluesky-social/atproto/commit/d551b0e3527714c111c3ec6e4c90ad7f46369fab)]:
27
+ - @atproto/lexicon@0.6.0
28
+
3
29
  ## 0.7.6
4
30
 
5
31
  ### Patch Changes
@@ -190,7 +216,7 @@
190
216
  `AtpAgent`.
191
217
 
192
218
  ```ts
193
- import { Agent, AtpAgent } from "@atproto/api";
219
+ import { Agent, AtpAgent } from '@atproto/api'
194
220
 
195
221
  async function setupAgent(
196
222
  service: string,
@@ -202,30 +228,30 @@
202
228
  persistSession: (evt, session) => {
203
229
  // handle session update
204
230
  },
205
- });
231
+ })
206
232
 
207
- await agent.login(username, password);
233
+ await agent.login(username, password)
208
234
 
209
- return agent;
235
+ return agent
210
236
  }
211
237
  ```
212
238
 
213
239
  ```ts
214
- import { Agent } from "@atproto/api";
240
+ import { Agent } from '@atproto/api'
215
241
 
216
242
  async function doStuffWithAgent(agent: Agent, arg: string) {
217
- return agent.resolveHandle(arg);
243
+ return agent.resolveHandle(arg)
218
244
  }
219
245
  ```
220
246
 
221
247
  ```ts
222
- import { Agent, AtpAgent } from "@atproto/api";
248
+ import { Agent, AtpAgent } from '@atproto/api'
223
249
 
224
250
  class MyClass {
225
- agent: Agent;
251
+ agent: Agent
226
252
 
227
253
  constructor() {
228
- this.agent = new AtpAgent();
254
+ this.agent = new AtpAgent()
229
255
  }
230
256
  }
231
257
  ```
@@ -303,24 +329,24 @@
303
329
  <td>
304
330
 
305
331
  ```ts
306
- import { AtpBaseClient, ComAtprotoSyncSubscribeRepos } from "@atproto/api";
332
+ import { AtpBaseClient, ComAtprotoSyncSubscribeRepos } from '@atproto/api'
307
333
 
308
- const baseClient = new AtpBaseClient();
334
+ const baseClient = new AtpBaseClient()
309
335
 
310
- baseClient.xrpc.lex.assertValidXrpcMessage("io.example.doStuff", {
336
+ baseClient.xrpc.lex.assertValidXrpcMessage('io.example.doStuff', {
311
337
  // ...
312
- });
338
+ })
313
339
  ```
314
340
 
315
341
  </td>
316
342
  <td>
317
343
 
318
344
  ```ts
319
- import { lexicons } from "@atproto/api";
345
+ import { lexicons } from '@atproto/api'
320
346
 
321
- lexicons.assertValidXrpcMessage("io.example.doStuff", {
347
+ lexicons.assertValidXrpcMessage('io.example.doStuff', {
322
348
  // ...
323
- });
349
+ })
324
350
  ```
325
351
 
326
352
  </td>
@@ -337,23 +363,23 @@
337
363
  <td>
338
364
 
339
365
  ```ts
340
- import { BskyAgent } from "@atproto/api";
366
+ import { BskyAgent } from '@atproto/api'
341
367
 
342
368
  class MyAgent extends BskyAgent {
343
- private accessToken?: string;
369
+ private accessToken?: string
344
370
 
345
371
  async createOrRefreshSession(identifier: string, password: string) {
346
372
  // custom logic here
347
373
 
348
- this.accessToken = "my-access-jwt";
374
+ this.accessToken = 'my-access-jwt'
349
375
  }
350
376
 
351
377
  async doStuff() {
352
- return this.call("io.example.doStuff", {
378
+ return this.call('io.example.doStuff', {
353
379
  headers: {
354
380
  Authorization: this.accessToken && `Bearer ${this.accessToken}`,
355
381
  },
356
- });
382
+ })
357
383
  }
358
384
  }
359
385
  ```
@@ -362,11 +388,11 @@
362
388
  <td>
363
389
 
364
390
  ```ts
365
- import { Agent } from "@atproto/api";
391
+ import { Agent } from '@atproto/api'
366
392
 
367
393
  class MyAgent extends Agent {
368
- private accessToken?: string;
369
- public did?: string;
394
+ private accessToken?: string
395
+ public did?: string
370
396
 
371
397
  constructor(private readonly service: string | URL) {
372
398
  super({
@@ -375,21 +401,21 @@
375
401
  Authorization: () =>
376
402
  this.accessToken ? `Bearer ${this.accessToken}` : null,
377
403
  },
378
- });
404
+ })
379
405
  }
380
406
 
381
407
  clone(): MyAgent {
382
- const agent = new MyAgent(this.service);
383
- agent.accessToken = this.accessToken;
384
- agent.did = this.did;
385
- return this.copyInto(agent);
408
+ const agent = new MyAgent(this.service)
409
+ agent.accessToken = this.accessToken
410
+ agent.did = this.did
411
+ return this.copyInto(agent)
386
412
  }
387
413
 
388
414
  async createOrRefreshSession(identifier: string, password: string) {
389
415
  // custom logic here
390
416
 
391
- this.did = "did:example:123";
392
- this.accessToken = "my-access-jwt";
417
+ this.did = 'did:example:123'
418
+ this.accessToken = 'my-access-jwt'
393
419
  }
394
420
  }
395
421
  ```
@@ -408,38 +434,38 @@
408
434
  <td>
409
435
 
410
436
  ```ts
411
- import { BskyAgent } from "@atproto/api";
412
- import { RateLimitThreshold } from "rate-limit-threshold";
437
+ import { BskyAgent } from '@atproto/api'
438
+ import { RateLimitThreshold } from 'rate-limit-threshold'
413
439
 
414
- const agent = new BskyAgent();
415
- const limiter = new RateLimitThreshold(3000, 300_000);
440
+ const agent = new BskyAgent()
441
+ const limiter = new RateLimitThreshold(3000, 300_000)
416
442
 
417
- const origCall = agent.api.xrpc.call;
443
+ const origCall = agent.api.xrpc.call
418
444
  agent.api.xrpc.call = async function (...args) {
419
- await limiter.wait();
420
- return origCall.call(this, ...args);
421
- };
445
+ await limiter.wait()
446
+ return origCall.call(this, ...args)
447
+ }
422
448
  ```
423
449
 
424
450
  </td>
425
451
  <td>
426
452
 
427
453
  ```ts
428
- import { AtpAgent } from "@atproto/api";
429
- import { RateLimitThreshold } from "rate-limit-threshold";
454
+ import { AtpAgent } from '@atproto/api'
455
+ import { RateLimitThreshold } from 'rate-limit-threshold'
430
456
 
431
457
  class LimitedAtpAgent extends AtpAgent {
432
458
  constructor(options: AtpAgentOptions) {
433
- const fetch: typeof globalThis.fetch = options.fetch ?? globalThis.fetch;
434
- const limiter = new RateLimitThreshold(3000, 300_000);
459
+ const fetch: typeof globalThis.fetch = options.fetch ?? globalThis.fetch
460
+ const limiter = new RateLimitThreshold(3000, 300_000)
435
461
 
436
462
  super({
437
463
  ...options,
438
464
  fetch: async (...args) => {
439
- await limiter.wait();
440
- return fetch(...args);
465
+ await limiter.wait()
466
+ return fetch(...args)
441
467
  },
442
- });
468
+ })
443
469
  }
444
470
  }
445
471
  ```
@@ -460,40 +486,40 @@
460
486
  <td>
461
487
 
462
488
  ```ts
463
- import { BskyAgent, defaultFetchHandler } from "@atproto/api";
489
+ import { BskyAgent, defaultFetchHandler } from '@atproto/api'
464
490
 
465
491
  BskyAgent.configure({
466
492
  fetch: async (httpUri, httpMethod, httpHeaders, httpReqBody) => {
467
- const ua = httpHeaders["User-Agent"];
493
+ const ua = httpHeaders['User-Agent']
468
494
 
469
- httpHeaders["User-Agent"] = ua ? `${ua} ${userAgent}` : userAgent;
495
+ httpHeaders['User-Agent'] = ua ? `${ua} ${userAgent}` : userAgent
470
496
 
471
- return defaultFetchHandler(httpUri, httpMethod, httpHeaders, httpReqBody);
497
+ return defaultFetchHandler(httpUri, httpMethod, httpHeaders, httpReqBody)
472
498
  },
473
- });
499
+ })
474
500
  ```
475
501
 
476
502
  </td>
477
503
  <td>
478
504
 
479
505
  ```ts
480
- import { AtpAgent } from "@atproto/api";
506
+ import { AtpAgent } from '@atproto/api'
481
507
 
482
508
  class MyAtpAgent extends AtpAgent {
483
509
  constructor(options: AtpAgentOptions) {
484
- const fetch = options.fetch ?? globalThis.fetch;
510
+ const fetch = options.fetch ?? globalThis.fetch
485
511
 
486
512
  super({
487
513
  ...options,
488
514
  fetch: async (url, init) => {
489
- const headers = new Headers(init.headers);
515
+ const headers = new Headers(init.headers)
490
516
 
491
- const ua = headersList.get("User-Agent");
492
- headersList.set("User-Agent", ua ? `${ua} ${userAgent}` : userAgent);
517
+ const ua = headersList.get('User-Agent')
518
+ headersList.set('User-Agent', ua ? `${ua} ${userAgent}` : userAgent)
493
519
 
494
- return fetch(url, { ...init, headers });
520
+ return fetch(url, { ...init, headers })
495
521
  },
496
- });
522
+ })
497
523
  }
498
524
  }
499
525
  ```
@@ -552,7 +578,7 @@
552
578
  */
553
579
  url: string,
554
580
  init: RequestInit,
555
- ) => Promise<Response>;
581
+ ) => Promise<Response>
556
582
  ```
557
583
 
558
584
  A noticeable change that has been introduced is that the `uri` field of the
@@ -590,7 +616,7 @@
590
616
  <td>
591
617
 
592
618
  ```ts
593
- import client, { defaultFetchHandler } from "@atproto/xrpc";
619
+ import client, { defaultFetchHandler } from '@atproto/xrpc'
594
620
 
595
621
  client.fetch = function (
596
622
  httpUri: string,
@@ -599,50 +625,50 @@
599
625
  httpReqBody: unknown,
600
626
  ) {
601
627
  // Custom logic here
602
- return defaultFetchHandler(httpUri, httpMethod, httpHeaders, httpReqBody);
603
- };
628
+ return defaultFetchHandler(httpUri, httpMethod, httpHeaders, httpReqBody)
629
+ }
604
630
 
605
631
  client.addLexicon({
606
632
  lexicon: 1,
607
- id: "io.example.doStuff",
633
+ id: 'io.example.doStuff',
608
634
  defs: {},
609
- });
635
+ })
610
636
 
611
- const instance = client.service("http://my-service.com");
637
+ const instance = client.service('http://my-service.com')
612
638
 
613
- instance.setHeader("my-header", "my-value");
639
+ instance.setHeader('my-header', 'my-value')
614
640
 
615
- await instance.call("io.example.doStuff");
641
+ await instance.call('io.example.doStuff')
616
642
  ```
617
643
 
618
644
  </td>
619
645
  <td>
620
646
 
621
647
  ```ts
622
- import { XrpcClient } from "@atproto/xrpc";
648
+ import { XrpcClient } from '@atproto/xrpc'
623
649
 
624
650
  const instance = new XrpcClient(
625
651
  async (url, init) => {
626
- const headers = new Headers(init.headers);
652
+ const headers = new Headers(init.headers)
627
653
 
628
- headers.set("my-header", "my-value");
654
+ headers.set('my-header', 'my-value')
629
655
 
630
656
  // Custom logic here
631
657
 
632
- const fullUrl = new URL(url, "http://my-service.com");
658
+ const fullUrl = new URL(url, 'http://my-service.com')
633
659
 
634
- return fetch(fullUrl, { ...init, headers });
660
+ return fetch(fullUrl, { ...init, headers })
635
661
  },
636
662
  [
637
663
  {
638
664
  lexicon: 1,
639
- id: "io.example.doStuff",
665
+ id: 'io.example.doStuff',
640
666
  defs: {},
641
667
  },
642
668
  ],
643
- );
669
+ )
644
670
 
645
- await instance.call("io.example.doStuff");
671
+ await instance.call('io.example.doStuff')
646
672
  ```
647
673
 
648
674
  </td>
@@ -654,62 +680,62 @@
654
680
  previous example can be simplified to:
655
681
 
656
682
  ```ts
657
- import { XrpcClient } from "@atproto/xrpc";
683
+ import { XrpcClient } from '@atproto/xrpc'
658
684
 
659
- const instance = new XrpcClient("http://my-service.com", [
685
+ const instance = new XrpcClient('http://my-service.com', [
660
686
  {
661
687
  lexicon: 1,
662
- id: "io.example.doStuff",
688
+ id: 'io.example.doStuff',
663
689
  defs: {},
664
690
  },
665
- ]);
691
+ ])
666
692
  ```
667
693
 
668
694
  If you need to add static headers to all requests, you can instead instantiate
669
695
  the `XrpcClient` as follows:
670
696
 
671
697
  ```ts
672
- import { XrpcClient } from "@atproto/xrpc";
698
+ import { XrpcClient } from '@atproto/xrpc'
673
699
 
674
700
  const instance = new XrpcClient(
675
701
  {
676
- service: "http://my-service.com",
702
+ service: 'http://my-service.com',
677
703
  headers: {
678
- "my-header": "my-value",
704
+ 'my-header': 'my-value',
679
705
  },
680
706
  },
681
707
  [
682
708
  {
683
709
  lexicon: 1,
684
- id: "io.example.doStuff",
710
+ id: 'io.example.doStuff',
685
711
  defs: {},
686
712
  },
687
713
  ],
688
- );
714
+ )
689
715
  ```
690
716
 
691
717
  If you need the headers or service url to be dynamic, you can define them using
692
718
  functions:
693
719
 
694
720
  ```ts
695
- import { XrpcClient } from "@atproto/xrpc";
721
+ import { XrpcClient } from '@atproto/xrpc'
696
722
 
697
723
  const instance = new XrpcClient(
698
724
  {
699
- service: () => "http://my-service.com",
725
+ service: () => 'http://my-service.com',
700
726
  headers: {
701
- "my-header": () => "my-value",
702
- "my-ignored-header": () => null, // ignored
727
+ 'my-header': () => 'my-value',
728
+ 'my-ignored-header': () => null, // ignored
703
729
  },
704
730
  },
705
731
  [
706
732
  {
707
733
  lexicon: 1,
708
- id: "io.example.doStuff",
734
+ id: 'io.example.doStuff',
709
735
  defs: {},
710
736
  },
711
737
  ],
712
- );
738
+ )
713
739
  ```
714
740
 
715
741
  - [#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/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  Dual MIT/Apache-2.0 License
2
2
 
3
- Copyright (c) 2022-2025 Bluesky Social PBC, and Contributors
3
+ Copyright (c) 2022-2026 Bluesky Social PBC, and Contributors
4
4
 
5
5
  Except as otherwise noted in individual files, this software is licensed under the MIT license (<http://opensource.org/licenses/MIT>), or the Apache License, Version 2.0 (<http://www.apache.org/licenses/LICENSE-2.0>).
6
6
 
package/dist/client.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { LexiconDoc, Lexicons } from '@atproto/lexicon';
2
- import { CallOptions, QueryParams } from './types';
3
- import { XrpcClient } from './xrpc-client';
2
+ import { CallOptions, QueryParams } from './types.js';
3
+ import { XrpcClient } from './xrpc-client.js';
4
4
  /** @deprecated Use {@link XrpcClient} instead */
5
5
  export declare class Client {
6
6
  /** @deprecated */
@@ -8,7 +8,7 @@ export declare class Client {
8
8
  /** @deprecated */
9
9
  set fetch(_: never);
10
10
  lex: Lexicons;
11
- call(serviceUri: string | URL, methodNsid: string, params?: QueryParams, data?: BodyInit | null, opts?: CallOptions): Promise<import("./types").XRPCResponse>;
11
+ call(serviceUri: string | URL, methodNsid: string, params?: QueryParams, data?: BodyInit | null, opts?: CallOptions): Promise<import("./types.js").XRPCResponse>;
12
12
  service(serviceUri: string | URL): ServiceClient;
13
13
  addLexicon(doc: LexiconDoc): void;
14
14
  addLexicons(docs: LexiconDoc[]): void;
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","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AClB,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;IAIlC,UAAU,EAAE,MAAM;IAH3B,GAAG,EAAE,GAAG,CAAA;gBAGC,UAAU,EAAE,MAAM,EACzB,UAAU,EAAE,MAAM,GAAG,GAAG;CAQ3B"}
package/dist/client.js CHANGED
@@ -1,18 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ServiceClient = exports.Client = void 0;
4
- const lexicon_1 = require("@atproto/lexicon");
5
- const util_1 = require("./util");
6
- const xrpc_client_1 = require("./xrpc-client");
1
+ import { Lexicons } from '@atproto/lexicon';
2
+ import { combineHeaders } from './util.js';
3
+ import { XrpcClient } from './xrpc-client.js';
7
4
  /** @deprecated Use {@link XrpcClient} instead */
8
- class Client {
5
+ export class Client {
9
6
  constructor() {
10
- Object.defineProperty(this, "lex", {
11
- enumerable: true,
12
- configurable: true,
13
- writable: true,
14
- value: new lexicon_1.Lexicons()
15
- });
7
+ this.lex = new Lexicons();
16
8
  }
17
9
  /** @deprecated */
18
10
  get fetch() {
@@ -44,28 +36,15 @@ class Client {
44
36
  this.lex.remove(uri);
45
37
  }
46
38
  }
47
- exports.Client = Client;
48
39
  /** @deprecated Use {@link XrpcClient} instead */
49
- class ServiceClient extends xrpc_client_1.XrpcClient {
40
+ export class ServiceClient extends XrpcClient {
50
41
  constructor(baseClient, serviceUri) {
51
42
  super(async (input, init) => {
52
- const headers = (0, util_1.combineHeaders)(init.headers, Object.entries(this.headers));
43
+ const headers = combineHeaders(init.headers, Object.entries(this.headers));
53
44
  return fetch(new URL(input, this.uri), { ...init, headers });
54
45
  }, baseClient.lex);
55
- Object.defineProperty(this, "baseClient", {
56
- enumerable: true,
57
- configurable: true,
58
- writable: true,
59
- value: baseClient
60
- });
61
- Object.defineProperty(this, "uri", {
62
- enumerable: true,
63
- configurable: true,
64
- writable: true,
65
- value: void 0
66
- });
46
+ this.baseClient = baseClient;
67
47
  this.uri = typeof serviceUri === 'string' ? new URL(serviceUri) : serviceUri;
68
48
  }
69
49
  }
70
- exports.ServiceClient = ServiceClient;
71
50
  //# sourceMappingURL=client.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AAAA,8CAAuD;AAEvD,iCAAuC;AACvC,+CAA0C;AAE1C,iDAAiD;AACjD,MAAa,MAAM;IAAnB;QAeE;;;;mBAAM,IAAI,kBAAQ,EAAE;WAAA;IAmCtB,CAAC;IAjDC,kBAAkB;IAClB,IAAI,KAAK;QACP,MAAM,IAAI,KAAK,CACb,iEAAiE,CAClE,CAAA;IACH,CAAC;IAED,kBAAkB;IAClB,IAAI,KAAK,CAAC,CAAQ;QAChB,MAAM,IAAI,KAAK,CACb,iEAAiE,CAClE,CAAA;IACH,CAAC;IAID,eAAe;IACf,EAAE;IAEF,KAAK,CAAC,IAAI,CACR,UAAwB,EACxB,UAAkB,EAClB,MAAoB,EACpB,IAAsB,EACtB,IAAkB;QAElB,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;IACtE,CAAC;IAED,OAAO,CAAC,UAAwB;QAC9B,OAAO,IAAI,aAAa,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;IAC5C,CAAC;IAED,UAAU;IACV,IAAI;IAEJ,UAAU,CAAC,GAAe;QACxB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IACnB,CAAC;IAED,WAAW,CAAC,IAAkB;QAC5B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACvB,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;QACtB,CAAC;IACH,CAAC;IAED,aAAa,CAAC,GAAW;QACvB,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;IACtB,CAAC;CACF;AAlDD,wBAkDC;AAED,iDAAiD;AACjD,MAAa,aAAc,SAAQ,wBAAU;IAG3C,YACS,UAAkB,EACzB,UAAwB;QAExB,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;YAC1B,MAAM,OAAO,GAAG,IAAA,qBAAc,EAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,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;QAH3B;;;;;WAAQ;QAUN,IAAI,CAAC,GAAG,GAAG,OAAO,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAA;IAC9E,CAAC;CACF;AAbD,sCAaC","sourcesContent":["import { LexiconDoc, Lexicons } from '@atproto/lexicon'\nimport { CallOptions, QueryParams } from './types'\nimport { combineHeaders } from './util'\nimport { XrpcClient } from './xrpc-client'\n\n/** @deprecated Use {@link XrpcClient} instead */\nexport class Client {\n /** @deprecated */\n get fetch(): never {\n throw new Error(\n 'Client.fetch is no longer supported. Use an XrpcClient instead.',\n )\n }\n\n /** @deprecated */\n set fetch(_: never) {\n throw new Error(\n 'Client.fetch is no longer supported. Use an XrpcClient instead.',\n )\n }\n\n lex = new Lexicons()\n\n // method calls\n //\n\n async call(\n serviceUri: string | URL,\n methodNsid: string,\n params?: QueryParams,\n data?: BodyInit | null,\n opts?: CallOptions,\n ) {\n return this.service(serviceUri).call(methodNsid, params, data, opts)\n }\n\n service(serviceUri: string | URL) {\n return new ServiceClient(this, serviceUri)\n }\n\n // schemas\n // =\n\n addLexicon(doc: LexiconDoc) {\n this.lex.add(doc)\n }\n\n addLexicons(docs: LexiconDoc[]) {\n for (const doc of docs) {\n this.addLexicon(doc)\n }\n }\n\n removeLexicon(uri: string) {\n this.lex.remove(uri)\n }\n}\n\n/** @deprecated Use {@link XrpcClient} instead */\nexport class ServiceClient extends XrpcClient {\n uri: URL\n\n constructor(\n public baseClient: Client,\n serviceUri: string | URL,\n ) {\n super(async (input, init) => {\n const headers = combineHeaders(init.headers, Object.entries(this.headers))\n return fetch(new URL(input, this.uri), { ...init, headers })\n }, baseClient.lex)\n this.uri = typeof serviceUri === 'string' ? new URL(serviceUri) : serviceUri\n }\n}\n"]}
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAEvD,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C,iDAAiD;AACjD,MAAM,OAAO,MAAM;IAAnB;QAeE,QAAG,GAAG,IAAI,QAAQ,EAAE,CAAA;IAmCtB,CAAC;IAjDC,kBAAkB;IAClB,IAAI,KAAK;QACP,MAAM,IAAI,KAAK,CACb,iEAAiE,CAClE,CAAA;IACH,CAAC;IAED,kBAAkB;IAClB,IAAI,KAAK,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AAU,GAAV,UAAU,CAAQ;QAOzB,IAAI,CAAC,GAAG,GAAG,OAAO,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAA;IAC9E,CAAC;CACF","sourcesContent":["import { LexiconDoc, Lexicons } from '@atproto/lexicon'\nimport { CallOptions, QueryParams } from './types.js'\nimport { combineHeaders } from './util.js'\nimport { XrpcClient } from './xrpc-client.js'\n\n/** @deprecated Use {@link XrpcClient} instead */\nexport class Client {\n /** @deprecated */\n get fetch(): never {\n throw new Error(\n 'Client.fetch is no longer supported. Use an XrpcClient instead.',\n )\n }\n\n /** @deprecated */\n set fetch(_: never) {\n throw new Error(\n 'Client.fetch is no longer supported. Use an XrpcClient instead.',\n )\n }\n\n lex = new Lexicons()\n\n // method calls\n //\n\n async call(\n serviceUri: string | URL,\n methodNsid: string,\n params?: QueryParams,\n data?: BodyInit | null,\n opts?: CallOptions,\n ) {\n return this.service(serviceUri).call(methodNsid, params, data, opts)\n }\n\n service(serviceUri: string | URL) {\n return new ServiceClient(this, serviceUri)\n }\n\n // schemas\n // =\n\n addLexicon(doc: LexiconDoc) {\n this.lex.add(doc)\n }\n\n addLexicons(docs: LexiconDoc[]) {\n for (const doc of docs) {\n this.addLexicon(doc)\n }\n }\n\n removeLexicon(uri: string) {\n this.lex.remove(uri)\n }\n}\n\n/** @deprecated Use {@link XrpcClient} instead */\nexport class ServiceClient extends XrpcClient {\n uri: URL\n\n constructor(\n public baseClient: Client,\n serviceUri: string | URL,\n ) {\n super(async (input, init) => {\n const headers = combineHeaders(init.headers, Object.entries(this.headers))\n return fetch(new URL(input, this.uri), { ...init, headers })\n }, baseClient.lex)\n this.uri = typeof serviceUri === 'string' ? new URL(serviceUri) : serviceUri\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { Gettable } from './types';
1
+ import { Gettable } from './types.js';
2
2
  export type FetchHandler = (this: void,
3
3
  /**
4
4
  * The URL (pathname + query parameters) to make the request to, without the
@@ -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,WAAW,KACd,OAAO,CAAC,QAAQ,CAAC,CAAA;AAEtB,MAAM,MAAM,mBAAmB,GAAG,wBAAwB,GAAG,MAAM,GAAG,GAAG,CAAA;AAEzE,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;;OAIG;IACH,OAAO,EAAE,QAAQ,CAAC,MAAM,GAAG,GAAG,CAAC,CAAA;IAE/B;;;;OAIG;IACH,OAAO,CAAC,EAAE;SACP,CAAC,IAAI,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC,IAAI,GAAG,MAAM,CAAC;KACxC,CAAA;IAED;;;;;OAKG;IACH,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAA;CAChC,CAAA;AAED,MAAM,WAAW,kBAAkB;IACjC,YAAY,EAAE,CACZ,IAAI,EAAE,kBAAkB;IACxB;;;;OAIG;IACH,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,WAAW,KACd,OAAO,CAAC,QAAQ,CAAC,CAAA;CACvB;AAED,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,YAAY,GAAG,kBAAkB,GAAG,mBAAmB,GAC/D,YAAY,CAgCd"}
1
+ {"version":3,"file":"fetch-handler.d.ts","sourceRoot":"","sources":["../src/fetch-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAGrC,MAAM,MAAM,YAAY,GAAG,CACzB,IAAI,EAAE,IAAI;AACV;;;;GAIG;AACH,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,WAAW,KACd,OAAO,CAAC,QAAQ,CAAC,CAAA;AAEtB,MAAM,MAAM,mBAAmB,GAAG,wBAAwB,GAAG,MAAM,GAAG,GAAG,CAAA;AAEzE,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;;OAIG;IACH,OAAO,EAAE,QAAQ,CAAC,MAAM,GAAG,GAAG,CAAC,CAAA;IAE/B;;;;OAIG;IACH,OAAO,CAAC,EAAE;SACP,CAAC,IAAI,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC,IAAI,GAAG,MAAM,CAAC;KACxC,CAAA;IAED;;;;;OAKG;IACH,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAA;CAChC,CAAA;AAED,MAAM,WAAW,kBAAkB;IACjC,YAAY,EAAE,CACZ,IAAI,EAAE,kBAAkB;IACxB;;;;OAIG;IACH,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,WAAW,KACd,OAAO,CAAC,QAAQ,CAAC,CAAA;CACvB;AAED,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,YAAY,GAAG,kBAAkB,GAAG,mBAAmB,GAC/D,YAAY,CAgCd"}
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildFetchHandler = buildFetchHandler;
4
- const util_1 = require("./util");
5
- function buildFetchHandler(options) {
1
+ import { combineHeaders } from './util.js';
2
+ export function buildFetchHandler(options) {
6
3
  // Already a fetch handler (allowed for convenience)
7
4
  if (typeof options === 'function')
8
5
  return options;
@@ -19,7 +16,7 @@ function buildFetchHandler(options) {
19
16
  return async function (url, init) {
20
17
  const base = typeof service === 'function' ? service() : service;
21
18
  const fullUrl = new URL(url, base);
22
- const headers = (0, util_1.combineHeaders)(init.headers, defaultHeadersEntries);
19
+ const headers = combineHeaders(init.headers, defaultHeadersEntries);
23
20
  return fetch(fullUrl, { ...init, headers });
24
21
  };
25
22
  }
@@ -1 +1 @@
1
- {"version":3,"file":"fetch-handler.js","sourceRoot":"","sources":["../src/fet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import { Gettable } from './types'\nimport { combineHeaders } from './util'\n\nexport type FetchHandler = (\n this: void,\n /**\n * The URL (pathname + query parameters) to make the request to, without the\n * origin. The origin (protocol, hostname, and port) must be added by this\n * {@link FetchHandler}, typically based on authentication or other factors.\n */\n url: string,\n init: RequestInit,\n) => Promise<Response>\n\nexport type FetchHandlerOptions = BuildFetchHandlerOptions | string | URL\n\nexport type BuildFetchHandlerOptions = {\n /**\n * The service URL to make requests to. This can be a string, URL, or a\n * function that returns a string or URL. This is useful for dynamic URLs,\n * such as a service URL that changes based on authentication.\n */\n service: Gettable<string | URL>\n\n /**\n * Headers to be added to every request. If a function is provided, it will be\n * called on each request to get the headers. This is useful for dynamic\n * headers, such as authentication tokens that may expire.\n */\n headers?: {\n [_ in string]?: Gettable<null | string>\n }\n\n /**\n * Bring your own fetch implementation. Typically useful for testing, logging,\n * mocking, or adding retries, session management, signatures, proof of\n * possession (DPoP), SSRF protection, etc. Defaults to the global `fetch`\n * function.\n */\n fetch?: typeof globalThis.fetch\n}\n\nexport interface FetchHandlerObject {\n fetchHandler: (\n this: FetchHandlerObject,\n /**\n * The URL (pathname + query parameters) to make the request to, without the\n * origin. The origin (protocol, hostname, and port) must be added by this\n * {@link FetchHandler}, typically based on authentication or other factors.\n */\n url: string,\n init: RequestInit,\n ) => Promise<Response>\n}\n\nexport function buildFetchHandler(\n options: FetchHandler | FetchHandlerObject | FetchHandlerOptions,\n): FetchHandler {\n // Already a fetch handler (allowed for convenience)\n if (typeof options === 'function') return options\n if (typeof options === 'object' && 'fetchHandler' in options) {\n return options.fetchHandler.bind(options)\n }\n\n const {\n service,\n headers: defaultHeaders = undefined,\n fetch = globalThis.fetch,\n } = typeof options === 'string' || options instanceof URL\n ? { service: options }\n : options\n\n if (typeof fetch !== 'function') {\n throw new TypeError(\n 'XrpcDispatcher requires fetch() to be available in your environment.',\n )\n }\n\n const defaultHeadersEntries =\n defaultHeaders != null ? Object.entries(defaultHeaders) : undefined\n\n return async function (url, init) {\n const base = typeof service === 'function' ? service() : service\n const fullUrl = new URL(url, base)\n\n const headers = combineHeaders(init.headers, defaultHeadersEntries)\n\n return fetch(fullUrl, { ...init, headers })\n }\n}\n"]}
1
+ {"version":3,"file":"fetch-handler.js","sourceRoot":"","sources":["../src/fetch-handler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAsD1C,MAAM,UAAU,iBAAiB,CAC/B,OAAgE;IAEhE,oDAAoD;IACpD,IAAI,OAAO,OAAO,KAAK,UAAU;QAAE,OAAO,OAAO,CAAA;IACjD,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,cAAc,IAAI,OAAO,EAAE,CAAC;QAC7D,OAAO,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAC3C,CAAC;IAED,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,GAAG,OAAO,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,CAAA;QAChE,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;QAElC,MAAM,OAAO,GAAG,cAAc,CAAC,IAAI,CAAC,OAAO,EAAE,qBAAqB,CAAC,CAAA;QAEnE,OAAO,KAAK,CAAC,OAAO,EAAE,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,CAAC,CAAA;IAC7C,CAAC,CAAA;AACH,CAAC","sourcesContent":["import { Gettable } from './types.js'\nimport { combineHeaders } from './util.js'\n\nexport type FetchHandler = (\n this: void,\n /**\n * The URL (pathname + query parameters) to make the request to, without the\n * origin. The origin (protocol, hostname, and port) must be added by this\n * {@link FetchHandler}, typically based on authentication or other factors.\n */\n url: string,\n init: RequestInit,\n) => Promise<Response>\n\nexport type FetchHandlerOptions = BuildFetchHandlerOptions | string | URL\n\nexport type BuildFetchHandlerOptions = {\n /**\n * The service URL to make requests to. This can be a string, URL, or a\n * function that returns a string or URL. This is useful for dynamic URLs,\n * such as a service URL that changes based on authentication.\n */\n service: Gettable<string | URL>\n\n /**\n * Headers to be added to every request. If a function is provided, it will be\n * called on each request to get the headers. This is useful for dynamic\n * headers, such as authentication tokens that may expire.\n */\n headers?: {\n [_ in string]?: Gettable<null | string>\n }\n\n /**\n * Bring your own fetch implementation. Typically useful for testing, logging,\n * mocking, or adding retries, session management, signatures, proof of\n * possession (DPoP), SSRF protection, etc. Defaults to the global `fetch`\n * function.\n */\n fetch?: typeof globalThis.fetch\n}\n\nexport interface FetchHandlerObject {\n fetchHandler: (\n this: FetchHandlerObject,\n /**\n * The URL (pathname + query parameters) to make the request to, without the\n * origin. The origin (protocol, hostname, and port) must be added by this\n * {@link FetchHandler}, typically based on authentication or other factors.\n */\n url: string,\n init: RequestInit,\n ) => Promise<Response>\n}\n\nexport function buildFetchHandler(\n options: FetchHandler | FetchHandlerObject | FetchHandlerOptions,\n): FetchHandler {\n // Already a fetch handler (allowed for convenience)\n if (typeof options === 'function') return options\n if (typeof options === 'object' && 'fetchHandler' in options) {\n return options.fetchHandler.bind(options)\n }\n\n const {\n service,\n headers: defaultHeaders = undefined,\n fetch = globalThis.fetch,\n } = typeof options === 'string' || options instanceof URL\n ? { service: options }\n : options\n\n if (typeof fetch !== 'function') {\n throw new TypeError(\n 'XrpcDispatcher requires fetch() to be available in your environment.',\n )\n }\n\n const defaultHeadersEntries =\n defaultHeaders != null ? Object.entries(defaultHeaders) : undefined\n\n return async function (url, init) {\n const base = typeof service === 'function' ? service() : service\n const fullUrl = new URL(url, base)\n\n const headers = combineHeaders(init.headers, defaultHeadersEntries)\n\n return fetch(fullUrl, { ...init, headers })\n }\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- export * from './client';
2
- export * from './fetch-handler';
3
- export * from './types';
4
- export * from './util';
5
- export * from './xrpc-client';
6
- import { Client } from './client';
1
+ export * from './client.js';
2
+ export * from './fetch-handler.js';
3
+ export * from './types.js';
4
+ export * from './util.js';
5
+ export * from './xrpc-client.js';
6
+ import { Client } from './client.js';
7
7
  /** @deprecated create a local {@link XrpcClient} instance instead */
8
8
  declare const defaultInst: Client;
9
9
  export default defaultInst;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,SAAS,CAAA;AACvB,cAAc,QAAQ,CAAA;AACtB,cAAc,eAAe,CAAA;AAG7B,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,qEAAqE;AACrE,QAAA,MAAM,WAAW,QAAe,CAAA;AAChC,eAAe,WAAW,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,oBAAoB,CAAA;AAClC,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,kBAAkB,CAAA;AAEhC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,qEAAqE;AACrE,QAAA,MAAM,WAAW,QAAe,CAAA;AAChC,eAAe,WAAW,CAAA"}