@atproto/xrpc 0.6.0 → 0.6.2

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,21 @@
1
1
  # @atproto/xrpc
2
2
 
3
+ ## 0.6.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2464](https://github.com/bluesky-social/atproto/pull/2464) [`98711a147`](https://github.com/bluesky-social/atproto/commit/98711a147a8674337f605c6368f39fc10c2fae93) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Add UnsupportedMediaType response type
8
+
9
+ ## 0.6.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [#2714](https://github.com/bluesky-social/atproto/pull/2714) [`d9ffa3c46`](https://github.com/bluesky-social/atproto/commit/d9ffa3c460924010d7002b616cb7a0c66111cc6c) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Improve handling of fetchHandler errors when turning them into `XrpcError`.
14
+
15
+ - [#2714](https://github.com/bluesky-social/atproto/pull/2714) [`d9ffa3c46`](https://github.com/bluesky-social/atproto/commit/d9ffa3c460924010d7002b616cb7a0c66111cc6c) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Add ability to instantiate XrpcClient from FetchHandlerObject type
16
+
17
+ - [#2714](https://github.com/bluesky-social/atproto/pull/2714) [`d9ffa3c46`](https://github.com/bluesky-social/atproto/commit/d9ffa3c460924010d7002b616cb7a0c66111cc6c) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Add global headers to `XrpcClient` instances
18
+
3
19
  ## 0.6.0
4
20
 
5
21
  ### Minor Changes
@@ -42,7 +58,7 @@
42
58
  `AtpAgent`.
43
59
 
44
60
  ```ts
45
- import { Agent, AtpAgent } from '@atproto/api'
61
+ import { Agent, AtpAgent } from "@atproto/api";
46
62
 
47
63
  async function setupAgent(
48
64
  service: string,
@@ -54,30 +70,30 @@
54
70
  persistSession: (evt, session) => {
55
71
  // handle session update
56
72
  },
57
- })
73
+ });
58
74
 
59
- await agent.login(username, password)
75
+ await agent.login(username, password);
60
76
 
61
- return agent
77
+ return agent;
62
78
  }
63
79
  ```
64
80
 
65
81
  ```ts
66
- import { Agent } from '@atproto/api'
82
+ import { Agent } from "@atproto/api";
67
83
 
68
84
  async function doStuffWithAgent(agent: Agent, arg: string) {
69
- return agent.resolveHandle(arg)
85
+ return agent.resolveHandle(arg);
70
86
  }
71
87
  ```
72
88
 
73
89
  ```ts
74
- import { Agent, AtpAgent } from '@atproto/api'
90
+ import { Agent, AtpAgent } from "@atproto/api";
75
91
 
76
92
  class MyClass {
77
- agent: Agent
93
+ agent: Agent;
78
94
 
79
95
  constructor() {
80
- this.agent = new AtpAgent()
96
+ this.agent = new AtpAgent();
81
97
  }
82
98
  }
83
99
  ```
@@ -155,24 +171,24 @@
155
171
  <td>
156
172
 
157
173
  ```ts
158
- import { AtpBaseClient, ComAtprotoSyncSubscribeRepos } from '@atproto/api'
174
+ import { AtpBaseClient, ComAtprotoSyncSubscribeRepos } from "@atproto/api";
159
175
 
160
- const baseClient = new AtpBaseClient()
176
+ const baseClient = new AtpBaseClient();
161
177
 
162
- baseClient.xrpc.lex.assertValidXrpcMessage('io.example.doStuff', {
178
+ baseClient.xrpc.lex.assertValidXrpcMessage("io.example.doStuff", {
163
179
  // ...
164
- })
180
+ });
165
181
  ```
166
182
 
167
183
  </td>
168
184
  <td>
169
185
 
170
186
  ```ts
171
- import { lexicons } from '@atproto/api'
187
+ import { lexicons } from "@atproto/api";
172
188
 
173
- lexicons.assertValidXrpcMessage('io.example.doStuff', {
189
+ lexicons.assertValidXrpcMessage("io.example.doStuff", {
174
190
  // ...
175
- })
191
+ });
176
192
  ```
177
193
 
178
194
  </td>
@@ -189,23 +205,23 @@
189
205
  <td>
190
206
 
191
207
  ```ts
192
- import { BskyAgent } from '@atproto/api'
208
+ import { BskyAgent } from "@atproto/api";
193
209
 
194
210
  class MyAgent extends BskyAgent {
195
- private accessToken?: string
211
+ private accessToken?: string;
196
212
 
197
213
  async createOrRefreshSession(identifier: string, password: string) {
198
214
  // custom logic here
199
215
 
200
- this.accessToken = 'my-access-jwt'
216
+ this.accessToken = "my-access-jwt";
201
217
  }
202
218
 
203
219
  async doStuff() {
204
- return this.call('io.example.doStuff', {
220
+ return this.call("io.example.doStuff", {
205
221
  headers: {
206
222
  Authorization: this.accessToken && `Bearer ${this.accessToken}`,
207
223
  },
208
- })
224
+ });
209
225
  }
210
226
  }
211
227
  ```
@@ -214,11 +230,11 @@
214
230
  <td>
215
231
 
216
232
  ```ts
217
- import { Agent } from '@atproto/api'
233
+ import { Agent } from "@atproto/api";
218
234
 
219
235
  class MyAgent extends Agent {
220
- private accessToken?: string
221
- public did?: string
236
+ private accessToken?: string;
237
+ public did?: string;
222
238
 
223
239
  constructor(private readonly service: string | URL) {
224
240
  super({
@@ -227,21 +243,21 @@
227
243
  Authorization: () =>
228
244
  this.accessToken ? `Bearer ${this.accessToken}` : null,
229
245
  },
230
- })
246
+ });
231
247
  }
232
248
 
233
249
  clone(): MyAgent {
234
- const agent = new MyAgent(this.service)
235
- agent.accessToken = this.accessToken
236
- agent.did = this.did
237
- return this.copyInto(agent)
250
+ const agent = new MyAgent(this.service);
251
+ agent.accessToken = this.accessToken;
252
+ agent.did = this.did;
253
+ return this.copyInto(agent);
238
254
  }
239
255
 
240
256
  async createOrRefreshSession(identifier: string, password: string) {
241
257
  // custom logic here
242
258
 
243
- this.did = 'did:example:123'
244
- this.accessToken = 'my-access-jwt'
259
+ this.did = "did:example:123";
260
+ this.accessToken = "my-access-jwt";
245
261
  }
246
262
  }
247
263
  ```
@@ -260,38 +276,38 @@
260
276
  <td>
261
277
 
262
278
  ```ts
263
- import { BskyAgent } from '@atproto/api'
264
- import { RateLimitThreshold } from 'rate-limit-threshold'
279
+ import { BskyAgent } from "@atproto/api";
280
+ import { RateLimitThreshold } from "rate-limit-threshold";
265
281
 
266
- const agent = new BskyAgent()
267
- const limiter = new RateLimitThreshold(3000, 300_000)
282
+ const agent = new BskyAgent();
283
+ const limiter = new RateLimitThreshold(3000, 300_000);
268
284
 
269
- const origCall = agent.api.xrpc.call
285
+ const origCall = agent.api.xrpc.call;
270
286
  agent.api.xrpc.call = async function (...args) {
271
- await limiter.wait()
272
- return origCall.call(this, ...args)
273
- }
287
+ await limiter.wait();
288
+ return origCall.call(this, ...args);
289
+ };
274
290
  ```
275
291
 
276
292
  </td>
277
293
  <td>
278
294
 
279
295
  ```ts
280
- import { AtpAgent } from '@atproto/api'
281
- import { RateLimitThreshold } from 'rate-limit-threshold'
296
+ import { AtpAgent } from "@atproto/api";
297
+ import { RateLimitThreshold } from "rate-limit-threshold";
282
298
 
283
299
  class LimitedAtpAgent extends AtpAgent {
284
300
  constructor(options: AtpAgentOptions) {
285
- const fetch: typeof globalThis.fetch = options.fetch ?? globalThis.fetch
286
- const limiter = new RateLimitThreshold(3000, 300_000)
301
+ const fetch: typeof globalThis.fetch = options.fetch ?? globalThis.fetch;
302
+ const limiter = new RateLimitThreshold(3000, 300_000);
287
303
 
288
304
  super({
289
305
  ...options,
290
306
  fetch: async (...args) => {
291
- await limiter.wait()
292
- return fetch(...args)
307
+ await limiter.wait();
308
+ return fetch(...args);
293
309
  },
294
- })
310
+ });
295
311
  }
296
312
  }
297
313
  ```
@@ -312,40 +328,40 @@
312
328
  <td>
313
329
 
314
330
  ```ts
315
- import { BskyAgent, defaultFetchHandler } from '@atproto/api'
331
+ import { BskyAgent, defaultFetchHandler } from "@atproto/api";
316
332
 
317
333
  BskyAgent.configure({
318
334
  fetch: async (httpUri, httpMethod, httpHeaders, httpReqBody) => {
319
- const ua = httpHeaders['User-Agent']
335
+ const ua = httpHeaders["User-Agent"];
320
336
 
321
- httpHeaders['User-Agent'] = ua ? `${ua} ${userAgent}` : userAgent
337
+ httpHeaders["User-Agent"] = ua ? `${ua} ${userAgent}` : userAgent;
322
338
 
323
- return defaultFetchHandler(httpUri, httpMethod, httpHeaders, httpReqBody)
339
+ return defaultFetchHandler(httpUri, httpMethod, httpHeaders, httpReqBody);
324
340
  },
325
- })
341
+ });
326
342
  ```
327
343
 
328
344
  </td>
329
345
  <td>
330
346
 
331
347
  ```ts
332
- import { AtpAgent } from '@atproto/api'
348
+ import { AtpAgent } from "@atproto/api";
333
349
 
334
350
  class MyAtpAgent extends AtpAgent {
335
351
  constructor(options: AtpAgentOptions) {
336
- const fetch = options.fetch ?? globalThis.fetch
352
+ const fetch = options.fetch ?? globalThis.fetch;
337
353
 
338
354
  super({
339
355
  ...options,
340
356
  fetch: async (url, init) => {
341
- const headers = new Headers(init.headers)
357
+ const headers = new Headers(init.headers);
342
358
 
343
- const ua = headersList.get('User-Agent')
344
- headersList.set('User-Agent', ua ? `${ua} ${userAgent}` : userAgent)
359
+ const ua = headersList.get("User-Agent");
360
+ headersList.set("User-Agent", ua ? `${ua} ${userAgent}` : userAgent);
345
361
 
346
- return fetch(url, { ...init, headers })
362
+ return fetch(url, { ...init, headers });
347
363
  },
348
- })
364
+ });
349
365
  }
350
366
  }
351
367
  ```
@@ -404,7 +420,7 @@
404
420
  */
405
421
  url: string,
406
422
  init: RequestInit,
407
- ) => Promise<Response>
423
+ ) => Promise<Response>;
408
424
  ```
409
425
 
410
426
  A noticeable change that has been introduced is that the `uri` field of the
@@ -442,7 +458,7 @@
442
458
  <td>
443
459
 
444
460
  ```ts
445
- import client, { defaultFetchHandler } from '@atproto/xrpc'
461
+ import client, { defaultFetchHandler } from "@atproto/xrpc";
446
462
 
447
463
  client.fetch = function (
448
464
  httpUri: string,
@@ -451,50 +467,50 @@
451
467
  httpReqBody: unknown,
452
468
  ) {
453
469
  // Custom logic here
454
- return defaultFetchHandler(httpUri, httpMethod, httpHeaders, httpReqBody)
455
- }
470
+ return defaultFetchHandler(httpUri, httpMethod, httpHeaders, httpReqBody);
471
+ };
456
472
 
457
473
  client.addLexicon({
458
474
  lexicon: 1,
459
- id: 'io.example.doStuff',
475
+ id: "io.example.doStuff",
460
476
  defs: {},
461
- })
477
+ });
462
478
 
463
- const instance = client.service('http://my-service.com')
479
+ const instance = client.service("http://my-service.com");
464
480
 
465
- instance.setHeader('my-header', 'my-value')
481
+ instance.setHeader("my-header", "my-value");
466
482
 
467
- await instance.call('io.example.doStuff')
483
+ await instance.call("io.example.doStuff");
468
484
  ```
469
485
 
470
486
  </td>
471
487
  <td>
472
488
 
473
489
  ```ts
474
- import { XrpcClient } from '@atproto/xrpc'
490
+ import { XrpcClient } from "@atproto/xrpc";
475
491
 
476
492
  const instance = new XrpcClient(
477
493
  async (url, init) => {
478
- const headers = new Headers(init.headers)
494
+ const headers = new Headers(init.headers);
479
495
 
480
- headers.set('my-header', 'my-value')
496
+ headers.set("my-header", "my-value");
481
497
 
482
498
  // Custom logic here
483
499
 
484
- const fullUrl = new URL(url, 'http://my-service.com')
500
+ const fullUrl = new URL(url, "http://my-service.com");
485
501
 
486
- return fetch(fullUrl, { ...init, headers })
502
+ return fetch(fullUrl, { ...init, headers });
487
503
  },
488
504
  [
489
505
  {
490
506
  lexicon: 1,
491
- id: 'io.example.doStuff',
507
+ id: "io.example.doStuff",
492
508
  defs: {},
493
509
  },
494
510
  ],
495
- )
511
+ );
496
512
 
497
- await instance.call('io.example.doStuff')
513
+ await instance.call("io.example.doStuff");
498
514
  ```
499
515
 
500
516
  </td>
@@ -506,62 +522,62 @@
506
522
  previous example can be simplified to:
507
523
 
508
524
  ```ts
509
- import { XrpcClient } from '@atproto/xrpc'
525
+ import { XrpcClient } from "@atproto/xrpc";
510
526
 
511
- const instance = new XrpcClient('http://my-service.com', [
527
+ const instance = new XrpcClient("http://my-service.com", [
512
528
  {
513
529
  lexicon: 1,
514
- id: 'io.example.doStuff',
530
+ id: "io.example.doStuff",
515
531
  defs: {},
516
532
  },
517
- ])
533
+ ]);
518
534
  ```
519
535
 
520
536
  If you need to add static headers to all requests, you can instead instantiate
521
537
  the `XrpcClient` as follows:
522
538
 
523
539
  ```ts
524
- import { XrpcClient } from '@atproto/xrpc'
540
+ import { XrpcClient } from "@atproto/xrpc";
525
541
 
526
542
  const instance = new XrpcClient(
527
543
  {
528
- service: 'http://my-service.com',
544
+ service: "http://my-service.com",
529
545
  headers: {
530
- 'my-header': 'my-value',
546
+ "my-header": "my-value",
531
547
  },
532
548
  },
533
549
  [
534
550
  {
535
551
  lexicon: 1,
536
- id: 'io.example.doStuff',
552
+ id: "io.example.doStuff",
537
553
  defs: {},
538
554
  },
539
555
  ],
540
- )
556
+ );
541
557
  ```
542
558
 
543
559
  If you need the headers or service url to be dynamic, you can define them using
544
560
  functions:
545
561
 
546
562
  ```ts
547
- import { XrpcClient } from '@atproto/xrpc'
563
+ import { XrpcClient } from "@atproto/xrpc";
548
564
 
549
565
  const instance = new XrpcClient(
550
566
  {
551
- service: () => 'http://my-service.com',
567
+ service: () => "http://my-service.com",
552
568
  headers: {
553
- 'my-header': () => 'my-value',
554
- 'my-ignored-header': () => null, // ignored
569
+ "my-header": () => "my-value",
570
+ "my-ignored-header": () => null, // ignored
555
571
  },
556
572
  },
557
573
  [
558
574
  {
559
575
  lexicon: 1,
560
- id: 'io.example.doStuff',
576
+ id: "io.example.doStuff",
561
577
  defs: {},
562
578
  },
563
579
  ],
564
- )
580
+ );
565
581
  ```
566
582
 
567
583
  - [#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/dist/client.d.ts CHANGED
@@ -18,9 +18,6 @@ export declare class Client {
18
18
  export declare class ServiceClient extends XrpcClient {
19
19
  baseClient: Client;
20
20
  uri: URL;
21
- headers: Record<string, string>;
22
21
  constructor(baseClient: Client, serviceUri: string | URL);
23
- setHeader(key: string, value: string): void;
24
- unsetHeader(key: string): void;
25
22
  }
26
23
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/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AAE,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;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
@@ -64,20 +64,8 @@ class ServiceClient extends xrpc_client_1.XrpcClient {
64
64
  writable: true,
65
65
  value: void 0
66
66
  });
67
- Object.defineProperty(this, "headers", {
68
- enumerable: true,
69
- configurable: true,
70
- writable: true,
71
- value: {}
72
- });
73
67
  this.uri = typeof serviceUri === 'string' ? new URL(serviceUri) : serviceUri;
74
68
  }
75
- setHeader(key, value) {
76
- this.headers[key] = value;
77
- }
78
- unsetHeader(key) {
79
- delete this.headers[key];
80
- }
81
69
  }
82
70
  exports.ServiceClient = ServiceClient;
83
71
  //# sourceMappingURL=client.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AAAA,8CAAuD;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AU,CAAA;IAC9E,CAAC;CACF;AAbD,sCAaC"}
@@ -29,5 +29,14 @@ export type BuildFetchHandlerOptions = {
29
29
  */
30
30
  fetch?: typeof globalThis.fetch;
31
31
  };
32
- export declare function buildFetchHandler(options: FetchHandler | FetchHandlerOptions): FetchHandler;
32
+ export interface FetchHandlerObject {
33
+ fetchHandler: (this: FetchHandlerObject,
34
+ /**
35
+ * The URL (pathname + query parameters) to make the request to, without the
36
+ * origin. The origin (protocol, hostname, and port) must be added by this
37
+ * {@link FetchHandler}, typically based on authentication or other factors.
38
+ */
39
+ url: string, init: RequestInit) => Promise<Response>;
40
+ }
41
+ export declare function buildFetchHandler(options: FetchHandler | FetchHandlerObject | FetchHandlerOptions): FetchHandler;
33
42
  //# 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,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;;;;OAIG;IACH,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAA;CAChC,CAAA;AAED,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,YAAY,GAAG,mBAAmB,GAC1C,YAAY,CA6Bd"}
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;;;;OAIG;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"}
@@ -6,6 +6,9 @@ function buildFetchHandler(options) {
6
6
  // Already a fetch handler (allowed for convenience)
7
7
  if (typeof options === 'function')
8
8
  return options;
9
+ if (typeof options === 'object' && 'fetchHandler' in options) {
10
+ return options.fetchHandler.bind(options);
11
+ }
9
12
  const { service, headers: defaultHeaders = undefined, fetch = globalThis.fetch, } = typeof options === 'string' || options instanceof URL
10
13
  ? { service: options }
11
14
  : options;
@@ -1 +1 @@
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,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,IAAA,qBAAc,EAAC,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;AA/BD,8CA+BC"}
1
+ {"version":3,"file":"fetch-handler.js","sourceRoot":"","sources":["../src/fetch-handler.ts"],"names":[],"mappings":";;;AACA,iCAAuC;AAqDvC,SAAg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ValidationError } from '@atproto/lexicon';
3
3
  export type QueryParams = Record<string, any>;
4
4
  export type HeadersMap = Record<string, string>;
5
+ export type {
5
6
  /** @deprecated not to be confused with the WHATWG Headers constructor */
6
- export type Headers = HeadersMap;
7
+ HeadersMap as Headers, };
7
8
  export type Gettable<T> = T | (() => T);
8
9
  export interface CallOptions {
9
10
  encoding?: string;
@@ -30,6 +31,7 @@ export declare enum ResponseType {
30
31
  Forbidden = 403,
31
32
  XRPCNotSupported = 404,
32
33
  PayloadTooLarge = 413,
34
+ UnsupportedMediaType = 415,
33
35
  RateLimitExceeded = 429,
34
36
  InternalServerError = 500,
35
37
  MethodNotImplemented = 501,
@@ -47,6 +49,7 @@ export declare const ResponseTypeNames: {
47
49
  403: string;
48
50
  404: string;
49
51
  413: string;
52
+ 415: string;
50
53
  429: string;
51
54
  500: string;
52
55
  501: string;
@@ -64,6 +67,7 @@ export declare const ResponseTypeStrings: {
64
67
  403: string;
65
68
  404: string;
66
69
  413: string;
70
+ 415: string;
67
71
  429: string;
68
72
  500: string;
69
73
  501: string;
@@ -74,9 +78,9 @@ export declare const ResponseTypeStrings: {
74
78
  export declare function httpResponseCodeToString(status: number): string;
75
79
  export declare class XRPCResponse {
76
80
  data: any;
77
- headers: Headers;
81
+ headers: HeadersMap;
78
82
  success: boolean;
79
- constructor(data: any, headers: Headers);
83
+ constructor(data: any, headers: HeadersMap);
80
84
  }
81
85
  export declare class XRPCError extends Error {
82
86
  error: string;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAElD,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;AAC7C,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAE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e,EAChC,YAAY,EAAE,OAAO;CAU/B"}
package/dist/types.js CHANGED
@@ -16,6 +16,7 @@ var ResponseType;
16
16
  ResponseType[ResponseType["Forbidden"] = 403] = "Forbidden";
17
17
  ResponseType[ResponseType["XRPCNotSupported"] = 404] = "XRPCNotSupported";
18
18
  ResponseType[ResponseType["PayloadTooLarge"] = 413] = "PayloadTooLarge";
19
+ ResponseType[ResponseType["UnsupportedMediaType"] = 415] = "UnsupportedMediaType";
19
20
  ResponseType[ResponseType["RateLimitExceeded"] = 429] = "RateLimitExceeded";
20
21
  ResponseType[ResponseType["InternalServerError"] = 500] = "InternalServerError";
21
22
  ResponseType[ResponseType["MethodNotImplemented"] = 501] = "MethodNotImplemented";
@@ -53,6 +54,7 @@ exports.ResponseTypeNames = {
53
54
  [ResponseType.Forbidden]: 'Forbidden',
54
55
  [ResponseType.XRPCNotSupported]: 'XRPCNotSupported',
55
56
  [ResponseType.PayloadTooLarge]: 'PayloadTooLarge',
57
+ [ResponseType.UnsupportedMediaType]: 'UnsupportedMediaType',
56
58
  [ResponseType.RateLimitExceeded]: 'RateLimitExceeded',
57
59
  [ResponseType.InternalServerError]: 'InternalServerError',
58
60
  [ResponseType.MethodNotImplemented]: 'MethodNotImplemented',
@@ -73,6 +75,7 @@ exports.ResponseTypeStrings = {
73
75
  [ResponseType.Forbidden]: 'Forbidden',
74
76
  [ResponseType.XRPCNotSupported]: 'XRPC Not Supported',
75
77
  [ResponseType.PayloadTooLarge]: 'Payload Too Large',
78
+ [ResponseType.UnsupportedMediaType]: 'Unsupported Media Type',
76
79
  [ResponseType.RateLimitExceeded]: 'Rate Limit Exceeded',
77
80
  [ResponseType.InternalServerError]: 'Internal Server Error',
78
81
  [ResponseType.MethodNotImplemented]: 'Method Not Implemented',
@@ -145,17 +148,29 @@ class XRPCError extends Error {
145
148
  if (cause instanceof XRPCError) {
146
149
  return cause;
147
150
  }
151
+ // Type cast the cause to an Error if it is one
152
+ const causeErr = cause instanceof Error ? cause : undefined;
153
+ // Try and find a Response object in the cause
154
+ const causeResponse = cause instanceof Response
155
+ ? cause
156
+ : cause?.['response'] instanceof Response
157
+ ? cause['response']
158
+ : undefined;
159
+ const statusCode =
148
160
  // Extract status code from "http-errors" like errors
149
- const statusCode = cause instanceof Error
150
- ? ('statusCode' in cause ? cause.statusCode : undefined) ??
151
- ('status' in cause ? cause.status : undefined)
152
- : undefined;
161
+ causeErr?.['statusCode'] ??
162
+ causeErr?.['status'] ??
163
+ // Use the status code from the response object as fallback
164
+ causeResponse?.status;
165
+ // Convert the status code to a ResponseType
153
166
  const status = typeof statusCode === 'number'
154
167
  ? httpResponseCodeToEnum(statusCode)
155
168
  : fallbackStatus ?? ResponseType.Unknown;
156
- const error = exports.ResponseTypeNames[status];
157
- const message = cause instanceof Error ? cause.message : String(cause);
158
- return new XRPCError(status, error, message, undefined, { cause });
169
+ const message = causeErr?.message ?? String(cause);
170
+ const headers = causeResponse
171
+ ? Object.fromEntries(causeResponse.headers.entries())
172
+ : undefined;
173
+ return new XRPCError(status, undefined, message, headers, { cause });
159
174
  }
160
175
  }
161
176
  exports.XRPCError = XRPCError;
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAAA,6BAAuB;AAiBV,QAAA,iBAAiB,GAAG,OAAC,CAAC,MAAM,CAAC;IACxC,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC5B,OAAO,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC/B,CAAC,CAAA;AAGF,IAAY,YAeX;AAfD,WAAY,YAAY;IACtB,qDAAW,CAAA;IACX,qEAAmB,CAAA;IACnB,uDAAa,CAAA;IACb,qEAAoB,CAAA;IACpB,iEAAkB,CAAA;IAClB,2DAAe,CAAA;IACf,yEAAsB,CAAA;IACtB,uEAAqB,CAAA;IACrB,2EAAuB,CAAA;IACvB,+EAAyB,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AAK,EAAE,eAAe,EAAE,CAC3B,CAAA;QAVD;;;;mBAAO,WAAW;WAAQ;QAC1B;;;;mBAAO,eAAe;WAAiB;QACvC;;;;mBAAO,YAAY;WAAS;IAS9B,CAAC;CACF;AAdD,4DAcC"}
@@ -1,10 +1,14 @@
1
1
  import { LexiconDoc, Lexicons } from '@atproto/lexicon';
2
- import { FetchHandler, FetchHandlerOptions } from './fetch-handler';
3
- import { CallOptions, QueryParams, XRPCResponse } from './types';
2
+ import { FetchHandler, FetchHandlerObject, FetchHandlerOptions } from './fetch-handler';
3
+ import { CallOptions, Gettable, QueryParams, XRPCResponse } from './types';
4
4
  export declare class XrpcClient {
5
5
  readonly fetchHandler: FetchHandler;
6
+ readonly headers: Map<string, Gettable<string | null>>;
6
7
  readonly lex: Lexicons;
7
- constructor(fetchHandlerOpts: FetchHandler | FetchHandlerOptions, lex: Lexicons | Iterable<LexiconDoc>);
8
+ constructor(fetchHandlerOpts: FetchHandler | FetchHandlerObject | FetchHandlerOptions, lex: Lexicons | Iterable<LexiconDoc>);
9
+ setHeader(key: string, value: Gettable<null | string>): void;
10
+ unsetHeader(key: string): void;
11
+ clearHeaders(): void;
8
12
  call(methodNsid: string, params?: QueryParams, data?: unknown, opts?: CallOptions): Promise<XRPCResponse>;
9
13
  }
10
14
  //# 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,CAA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
18
  });
19
+ Object.defineProperty(this, "headers", {
20
+ enumerable: true,
21
+ configurable: true,
22
+ writable: true,
23
+ value: new Map()
24
+ });
19
25
  Object.defineProperty(this, "lex", {
20
26
  enumerable: true,
21
27
  configurable: true,
@@ -25,6 +31,15 @@ class XrpcClient {
25
31
  this.fetchHandler = (0, fetch_handler_1.buildFetchHandler)(fetchHandlerOpts);
26
32
  this.lex = lex instanceof lexicon_1.Lexicons ? lex : new lexicon_1.Lexicons(lex);
27
33
  }
34
+ setHeader(key, value) {
35
+ this.headers.set(key.toLowerCase(), value);
36
+ }
37
+ unsetHeader(key) {
38
+ this.headers.delete(key.toLowerCase());
39
+ }
40
+ clearHeaders() {
41
+ this.headers.clear();
42
+ }
28
43
  async call(methodNsid, params, data, opts) {
29
44
  const def = this.lex.getDefOrThrow(methodNsid);
30
45
  if (!def || (def.type !== 'query' && def.type !== 'procedure')) {
@@ -43,7 +58,7 @@ class XrpcClient {
43
58
  // anywhere in docs or types. See whatwg/fetch#1438, nodejs/node#46221.
44
59
  const init = {
45
60
  method: reqMethod,
46
- headers: reqHeaders,
61
+ headers: (0, util_1.combineHeaders)(reqHeaders, this.headers),
47
62
  body: reqBody,
48
63
  duplex: 'half',
49
64
  signal: opts?.signal,
@@ -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,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,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AE,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;AA/FD,gCA+FC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atproto/xrpc",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "license": "MIT",
5
5
  "description": "atproto HTTP API (XRPC) client library",
6
6
  "keywords": [
package/src/client.ts CHANGED
@@ -59,7 +59,6 @@ export class Client {
59
59
  /** @deprecated Use {@link XrpcClient} instead */
60
60
  export class ServiceClient extends XrpcClient {
61
61
  uri: URL
62
- headers: Record<string, string> = {}
63
62
 
64
63
  constructor(
65
64
  public baseClient: Client,
@@ -71,12 +70,4 @@ export class ServiceClient extends XrpcClient {
71
70
  }, baseClient.lex)
72
71
  this.uri = typeof serviceUri === 'string' ? new URL(serviceUri) : serviceUri
73
72
  }
74
-
75
- setHeader(key: string, value: string): void {
76
- this.headers[key] = value
77
- }
78
-
79
- unsetHeader(key: string): void {
80
- delete this.headers[key]
81
- }
82
73
  }
@@ -39,11 +39,27 @@ export type BuildFetchHandlerOptions = {
39
39
  fetch?: typeof globalThis.fetch
40
40
  }
41
41
 
42
+ export interface FetchHandlerObject {
43
+ fetchHandler: (
44
+ this: FetchHandlerObject,
45
+ /**
46
+ * The URL (pathname + query parameters) to make the request to, without the
47
+ * origin. The origin (protocol, hostname, and port) must be added by this
48
+ * {@link FetchHandler}, typically based on authentication or other factors.
49
+ */
50
+ url: string,
51
+ init: RequestInit,
52
+ ) => Promise<Response>
53
+ }
54
+
42
55
  export function buildFetchHandler(
43
- options: FetchHandler | FetchHandlerOptions,
56
+ options: FetchHandler | FetchHandlerObject | FetchHandlerOptions,
44
57
  ): FetchHandler {
45
58
  // Already a fetch handler (allowed for convenience)
46
59
  if (typeof options === 'function') return options
60
+ if (typeof options === 'object' && 'fetchHandler' in options) {
61
+ return options.fetchHandler.bind(options)
62
+ }
47
63
 
48
64
  const {
49
65
  service,
package/src/types.ts CHANGED
@@ -4,8 +4,10 @@ import { ValidationError } from '@atproto/lexicon'
4
4
  export type QueryParams = Record<string, any>
5
5
  export type HeadersMap = Record<string, string>
6
6
 
7
- /** @deprecated not to be confused with the WHATWG Headers constructor */
8
- export type Headers = HeadersMap
7
+ export type {
8
+ /** @deprecated not to be confused with the WHATWG Headers constructor */
9
+ HeadersMap as Headers,
10
+ }
9
11
 
10
12
  export type Gettable<T> = T | (() => T)
11
13
 
@@ -30,6 +32,7 @@ export enum ResponseType {
30
32
  Forbidden = 403,
31
33
  XRPCNotSupported = 404,
32
34
  PayloadTooLarge = 413,
35
+ UnsupportedMediaType = 415,
33
36
  RateLimitExceeded = 429,
34
37
  InternalServerError = 500,
35
38
  MethodNotImplemented = 501,
@@ -63,6 +66,7 @@ export const ResponseTypeNames = {
63
66
  [ResponseType.Forbidden]: 'Forbidden',
64
67
  [ResponseType.XRPCNotSupported]: 'XRPCNotSupported',
65
68
  [ResponseType.PayloadTooLarge]: 'PayloadTooLarge',
69
+ [ResponseType.UnsupportedMediaType]: 'UnsupportedMediaType',
66
70
  [ResponseType.RateLimitExceeded]: 'RateLimitExceeded',
67
71
  [ResponseType.InternalServerError]: 'InternalServerError',
68
72
  [ResponseType.MethodNotImplemented]: 'MethodNotImplemented',
@@ -84,6 +88,7 @@ export const ResponseTypeStrings = {
84
88
  [ResponseType.Forbidden]: 'Forbidden',
85
89
  [ResponseType.XRPCNotSupported]: 'XRPC Not Supported',
86
90
  [ResponseType.PayloadTooLarge]: 'Payload Too Large',
91
+ [ResponseType.UnsupportedMediaType]: 'Unsupported Media Type',
87
92
  [ResponseType.RateLimitExceeded]: 'Rate Limit Exceeded',
88
93
  [ResponseType.InternalServerError]: 'Internal Server Error',
89
94
  [ResponseType.MethodNotImplemented]: 'Method Not Implemented',
@@ -101,7 +106,7 @@ export class XRPCResponse {
101
106
 
102
107
  constructor(
103
108
  public data: any,
104
- public headers: Headers,
109
+ public headers: HeadersMap,
105
110
  ) {}
106
111
  }
107
112
 
@@ -114,7 +119,7 @@ export class XRPCError extends Error {
114
119
  statusCode: number,
115
120
  public error: string = httpResponseCodeToName(statusCode),
116
121
  message?: string,
117
- public headers?: Headers,
122
+ public headers?: HeadersMap,
118
123
  options?: ErrorOptions,
119
124
  ) {
120
125
  super(message || error || httpResponseCodeToString(statusCode), options)
@@ -133,22 +138,37 @@ export class XRPCError extends Error {
133
138
  return cause
134
139
  }
135
140
 
136
- // Extract status code from "http-errors" like errors
141
+ // Type cast the cause to an Error if it is one
142
+ const causeErr = cause instanceof Error ? cause : undefined
143
+
144
+ // Try and find a Response object in the cause
145
+ const causeResponse: Response | undefined =
146
+ cause instanceof Response
147
+ ? cause
148
+ : cause?.['response'] instanceof Response
149
+ ? cause['response']
150
+ : undefined
151
+
137
152
  const statusCode: unknown =
138
- cause instanceof Error
139
- ? ('statusCode' in cause ? cause.statusCode : undefined) ??
140
- ('status' in cause ? cause.status : undefined)
141
- : undefined
153
+ // Extract status code from "http-errors" like errors
154
+ causeErr?.['statusCode'] ??
155
+ causeErr?.['status'] ??
156
+ // Use the status code from the response object as fallback
157
+ causeResponse?.status
142
158
 
159
+ // Convert the status code to a ResponseType
143
160
  const status: ResponseType =
144
161
  typeof statusCode === 'number'
145
162
  ? httpResponseCodeToEnum(statusCode)
146
163
  : fallbackStatus ?? ResponseType.Unknown
147
164
 
148
- const error = ResponseTypeNames[status]
149
- const message = cause instanceof Error ? cause.message : String(cause)
165
+ const message = causeErr?.message ?? String(cause)
166
+
167
+ const headers = causeResponse
168
+ ? Object.fromEntries(causeResponse.headers.entries())
169
+ : undefined
150
170
 
151
- return new XRPCError(status, error, message, undefined, { cause })
171
+ return new XRPCError(status, undefined, message, headers, { cause })
152
172
  }
153
173
  }
154
174
 
@@ -1,11 +1,13 @@
1
1
  import { LexiconDoc, Lexicons, ValidationError } from '@atproto/lexicon'
2
2
  import {
3
3
  FetchHandler,
4
+ FetchHandlerObject,
4
5
  FetchHandlerOptions,
5
6
  buildFetchHandler,
6
7
  } from './fetch-handler'
7
8
  import {
8
9
  CallOptions,
10
+ Gettable,
9
11
  QueryParams,
10
12
  ResponseType,
11
13
  XRPCError,
@@ -14,6 +16,7 @@ import {
14
16
  httpResponseCodeToEnum,
15
17
  } from './types'
16
18
  import {
19
+ combineHeaders,
17
20
  constructMethodCallHeaders,
18
21
  constructMethodCallUrl,
19
22
  encodeMethodCallBody,
@@ -24,10 +27,11 @@ import {
24
27
 
25
28
  export class XrpcClient {
26
29
  readonly fetchHandler: FetchHandler
30
+ readonly headers = new Map<string, Gettable<null | string>>()
27
31
  readonly lex: Lexicons
28
32
 
29
33
  constructor(
30
- fetchHandlerOpts: FetchHandler | FetchHandlerOptions,
34
+ fetchHandlerOpts: FetchHandler | FetchHandlerObject | FetchHandlerOptions,
31
35
  // "Lexicons" is redundant here (because that class implements
32
36
  // "Iterable<LexiconDoc>") but we keep it for explicitness:
33
37
  lex: Lexicons | Iterable<LexiconDoc>,
@@ -37,6 +41,18 @@ export class XrpcClient {
37
41
  this.lex = lex instanceof Lexicons ? lex : new Lexicons(lex)
38
42
  }
39
43
 
44
+ setHeader(key: string, value: Gettable<null | string>): void {
45
+ this.headers.set(key.toLowerCase(), value)
46
+ }
47
+
48
+ unsetHeader(key: string): void {
49
+ this.headers.delete(key.toLowerCase())
50
+ }
51
+
52
+ clearHeaders(): void {
53
+ this.headers.clear()
54
+ }
55
+
40
56
  async call(
41
57
  methodNsid: string,
42
58
  params?: QueryParams,
@@ -65,7 +81,7 @@ export class XrpcClient {
65
81
  // anywhere in docs or types. See whatwg/fetch#1438, nodejs/node#46221.
66
82
  const init: RequestInit & { duplex: 'half' } = {
67
83
  method: reqMethod,
68
- headers: reqHeaders,
84
+ headers: combineHeaders(reqHeaders, this.headers),
69
85
  body: reqBody,
70
86
  duplex: 'half',
71
87
  signal: opts?.signal,