@atproto/xrpc 0.6.0-rc.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,39 +1,585 @@
1
1
  # @atproto/xrpc
2
2
 
3
- ## 0.6.0-rc.0
3
+ ## 0.6.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#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`.
8
+
9
+ - [#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
10
+
11
+ - [#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
12
+
13
+ ## 0.6.0
4
14
 
5
15
  ### Minor Changes
6
16
 
7
- - [#2483](https://github.com/bluesky-social/atproto/pull/2483) [`2ded0156b`](https://github.com/bluesky-social/atproto/commit/2ded0156b9adf33b9cce66583a375bff922d383b) Thanks [@matthieusieben](https://github.com/matthieusieben)! - **New Features**:
17
+ - [#2483](https://github.com/bluesky-social/atproto/pull/2483) [`b934b396b`](https://github.com/bluesky-social/atproto/commit/b934b396b13ba32bf2bf7e75ecdf6871e5f310dd) Thanks [@matthieusieben](https://github.com/matthieusieben)!
18
+
19
+ #### Motivation
20
+
21
+ The motivation for these changes is the need to make the `@atproto/api` package
22
+ compatible with OAuth session management. We don't have OAuth client support
23
+ "launched" and documented quite yet, so you can keep using the current app
24
+ password authentication system. When we do "launch" OAuth support and begin
25
+ encouraging its usage in the near future (see the [OAuth
26
+ Roadmap](https://github.com/bluesky-social/atproto/discussions/2656)), these
27
+ changes will make it easier to migrate.
28
+
29
+ In addition, the redesigned session management system fixes a bug that could
30
+ cause the session data to become invalid when Agent clones are created (e.g.
31
+ using `agent.withProxy()`).
32
+
33
+ #### New Features
34
+
35
+ We've restructured the `XrpcClient` HTTP fetch handler to be specified during
36
+ the instantiation of the XRPC client, through the constructor, instead of using
37
+ a default implementation (which was statically defined).
38
+
39
+ With this refactor, the XRPC client is now more modular and reusable. Session
40
+ management, retries, cryptographic signing, and other request-specific logic can
41
+ be implemented in the fetch handler itself rather than by the calling code.
8
42
 
9
- 1. Improved Separation of Concerns: We've restructured the XRPC HTTP call
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.
43
+ A new abstract class named `Agent`, has been added to `@atproto/api`. This class
44
+ will be the base class for all Bluesky agents classes in the `@atproto`
45
+ ecosystem. It is meant to be extended by implementations that provide session
46
+ management and fetch handling.
15
47
 
16
- **Compatibility**:
48
+ As you adapt your code to these changes, make sure to use the `Agent` type
49
+ wherever you expect to receive an agent, and use the `AtpAgent` type (class)
50
+ only to instantiate your client. The reason for this is to be forward compatible
51
+ with the OAuth agent implementation that will also extend `Agent`, and not
52
+ `AtpAgent`.
53
+
54
+ ```ts
55
+ import { Agent, AtpAgent } from "@atproto/api";
56
+
57
+ async function setupAgent(
58
+ service: string,
59
+ username: string,
60
+ password: string,
61
+ ): Promise<Agent> {
62
+ const agent = new AtpAgent({
63
+ service,
64
+ persistSession: (evt, session) => {
65
+ // handle session update
66
+ },
67
+ });
68
+
69
+ await agent.login(username, password);
70
+
71
+ return agent;
72
+ }
73
+ ```
74
+
75
+ ```ts
76
+ import { Agent } from "@atproto/api";
77
+
78
+ async function doStuffWithAgent(agent: Agent, arg: string) {
79
+ return agent.resolveHandle(arg);
80
+ }
81
+ ```
82
+
83
+ ```ts
84
+ import { Agent, AtpAgent } from "@atproto/api";
85
+
86
+ class MyClass {
87
+ agent: Agent;
88
+
89
+ constructor() {
90
+ this.agent = new AtpAgent();
91
+ }
92
+ }
93
+ ```
94
+
95
+ #### Breaking changes
17
96
 
18
97
  Most of the changes introduced in this version are backward-compatible. However,
19
98
  there are a couple of breaking changes you should be aware of:
20
99
 
21
- - Customizing `fetchHandler`: The ability to customize the fetchHandler on the
22
- XRPC Client and AtpAgent classes has been modified. Please review your code if
23
- you rely on custom fetch handlers.
24
- - Managing Sessions: Previously, you had the ability to manage sessions directly
25
- through AtpAgent instances. Now, session management must be handled through a
26
- dedicated `SessionManager` instance. If you were making authenticated
27
- requests, you'll need to update your code to use explicit session management.
100
+ - Customizing `fetch`: The ability to customize the `fetch: FetchHandler`
101
+ property of `@atproto/xrpc`'s `Client` and `@atproto/api`'s `AtpAgent` classes
102
+ has been removed. Previously, the `fetch` property could be set to a function
103
+ that would be used as the fetch handler for that instance, and was initialized
104
+ to a default fetch handler. That property is still accessible in a read-only
105
+ fashion through the `fetchHandler` property and can only be set during the
106
+ instance creation. Attempting to set/get the `fetch` property will now result
107
+ in an error.
28
108
  - The `fetch()` method, as well as WhatWG compliant `Request` and `Headers`
29
- constructors, must be globally available in your environment.
30
-
31
- - [#2483](https://github.com/bluesky-social/atproto/pull/2483) [`2ded0156b`](https://github.com/bluesky-social/atproto/commit/2ded0156b9adf33b9cce66583a375bff922d383b) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Add the ability to use `fetch()` compatible `BodyInit` body when making XRPC calls.
109
+ constructors, must be globally available in your environment. Use a polyfill
110
+ if necessary.
111
+ - The `AtpBaseClient` has been removed. The `AtpServiceClient` has been renamed
112
+ `AtpBaseClient`. Any code using either of these classes will need to be
113
+ updated.
114
+ - Instead of _wrapping_ an `XrpcClient` in its `xrpc` property, the
115
+ `AtpBaseClient` (formerly `AtpServiceClient`) class - created through
116
+ `lex-cli` - now _extends_ the `XrpcClient` class. This means that a client
117
+ instance now passes the `instanceof XrpcClient` check. The `xrpc` property now
118
+ returns the instance itself and has been deprecated.
119
+ - `setSessionPersistHandler` is no longer available on the `AtpAgent` or
120
+ `BskyAgent` classes. The session handler can only be set though the
121
+ `persistSession` options of the `AtpAgent` constructor.
122
+ - The new class hierarchy is as follows:
123
+ - `BskyAgent` extends `AtpAgent`: but add no functionality (hence its
124
+ deprecation).
125
+ - `AtpAgent` extends `Agent`: adds password based session management.
126
+ - `Agent` extends `AtpBaseClient`: this abstract class that adds syntactic sugar
127
+ methods `app.bsky` lexicons. It also adds abstract session management
128
+ methods and adds atproto specific utilities
129
+ (`labelers` & `proxy` headers, cloning capability)
130
+ - `AtpBaseClient` extends `XrpcClient`: automatically code that adds fully
131
+ typed lexicon defined namespaces (`instance.app.bsky.feed.getPosts()`) to
132
+ the `XrpcClient`.
133
+ - `XrpcClient` is the base class.
134
+
135
+ #### Non-breaking changes
136
+
137
+ - The `com.*` and `app.*` namespaces have been made directly available to every
138
+ `Agent` instances.
139
+
140
+ #### Deprecations
141
+
142
+ - The default export of the `@atproto/xrpc` package has been deprecated. Use
143
+ named exports instead.
144
+ - The `Client` and `ServiceClient` classes are now deprecated. They are replaced by a single `XrpcClient` class.
145
+ - The default export of the `@atproto/api` package has been deprecated. Use
146
+ named exports instead.
147
+ - The `BskyAgent` has been deprecated. Use the `AtpAgent` class instead.
148
+ - The `xrpc` property of the `AtpClient` instances has been deprecated. The
149
+ instance itself should be used as the XRPC client.
150
+ - The `api` property of the `AtpAgent` and `BskyAgent` instances has been
151
+ deprecated. Use the instance itself instead.
152
+
153
+ #### Migration
154
+
155
+ ##### The `@atproto/api` package
156
+
157
+ If you were relying on the `AtpBaseClient` solely to perform validation, use
158
+ this:
159
+
160
+ <table>
161
+ <tr>
162
+ <td><center>Before</center></td> <td><center>After</center></td>
163
+ </tr>
164
+ <tr>
165
+ <td>
166
+
167
+ ```ts
168
+ import { AtpBaseClient, ComAtprotoSyncSubscribeRepos } from "@atproto/api";
169
+
170
+ const baseClient = new AtpBaseClient();
171
+
172
+ baseClient.xrpc.lex.assertValidXrpcMessage("io.example.doStuff", {
173
+ // ...
174
+ });
175
+ ```
176
+
177
+ </td>
178
+ <td>
179
+
180
+ ```ts
181
+ import { lexicons } from "@atproto/api";
182
+
183
+ lexicons.assertValidXrpcMessage("io.example.doStuff", {
184
+ // ...
185
+ });
186
+ ```
187
+
188
+ </td>
189
+ </tr>
190
+ </table>
191
+
192
+ If you are extending the `BskyAgent` to perform custom `session` manipulation, define your own `Agent` subclass instead:
193
+
194
+ <table>
195
+ <tr>
196
+ <td><center>Before</center></td> <td><center>After</center></td>
197
+ </tr>
198
+ <tr>
199
+ <td>
200
+
201
+ ```ts
202
+ import { BskyAgent } from "@atproto/api";
203
+
204
+ class MyAgent extends BskyAgent {
205
+ private accessToken?: string;
206
+
207
+ async createOrRefreshSession(identifier: string, password: string) {
208
+ // custom logic here
209
+
210
+ this.accessToken = "my-access-jwt";
211
+ }
212
+
213
+ async doStuff() {
214
+ return this.call("io.example.doStuff", {
215
+ headers: {
216
+ Authorization: this.accessToken && `Bearer ${this.accessToken}`,
217
+ },
218
+ });
219
+ }
220
+ }
221
+ ```
222
+
223
+ </td>
224
+ <td>
225
+
226
+ ```ts
227
+ import { Agent } from "@atproto/api";
228
+
229
+ class MyAgent extends Agent {
230
+ private accessToken?: string;
231
+ public did?: string;
232
+
233
+ constructor(private readonly service: string | URL) {
234
+ super({
235
+ service,
236
+ headers: {
237
+ Authorization: () =>
238
+ this.accessToken ? `Bearer ${this.accessToken}` : null,
239
+ },
240
+ });
241
+ }
242
+
243
+ clone(): MyAgent {
244
+ const agent = new MyAgent(this.service);
245
+ agent.accessToken = this.accessToken;
246
+ agent.did = this.did;
247
+ return this.copyInto(agent);
248
+ }
249
+
250
+ async createOrRefreshSession(identifier: string, password: string) {
251
+ // custom logic here
252
+
253
+ this.did = "did:example:123";
254
+ this.accessToken = "my-access-jwt";
255
+ }
256
+ }
257
+ ```
258
+
259
+ </td>
260
+ </tr>
261
+ </table>
262
+
263
+ If you are monkey patching the `xrpc` service client to perform client-side rate limiting, you can now do this in the `FetchHandler` function:
264
+
265
+ <table>
266
+ <tr>
267
+ <td><center>Before</center></td> <td><center>After</center></td>
268
+ </tr>
269
+ <tr>
270
+ <td>
271
+
272
+ ```ts
273
+ import { BskyAgent } from "@atproto/api";
274
+ import { RateLimitThreshold } from "rate-limit-threshold";
275
+
276
+ const agent = new BskyAgent();
277
+ const limiter = new RateLimitThreshold(3000, 300_000);
278
+
279
+ const origCall = agent.api.xrpc.call;
280
+ agent.api.xrpc.call = async function (...args) {
281
+ await limiter.wait();
282
+ return origCall.call(this, ...args);
283
+ };
284
+ ```
285
+
286
+ </td>
287
+ <td>
288
+
289
+ ```ts
290
+ import { AtpAgent } from "@atproto/api";
291
+ import { RateLimitThreshold } from "rate-limit-threshold";
292
+
293
+ class LimitedAtpAgent extends AtpAgent {
294
+ constructor(options: AtpAgentOptions) {
295
+ const fetch: typeof globalThis.fetch = options.fetch ?? globalThis.fetch;
296
+ const limiter = new RateLimitThreshold(3000, 300_000);
297
+
298
+ super({
299
+ ...options,
300
+ fetch: async (...args) => {
301
+ await limiter.wait();
302
+ return fetch(...args);
303
+ },
304
+ });
305
+ }
306
+ }
307
+ ```
308
+
309
+ </td>
310
+ </tr>
311
+ </table>
312
+
313
+ If you configure a static `fetch` handler on the `BskyAgent` class - for example
314
+ to modify the headers of every request - you can now do this by providing your
315
+ own `fetch` function:
316
+
317
+ <table>
318
+ <tr>
319
+ <td><center>Before</center></td> <td><center>After</center></td>
320
+ </tr>
321
+ <tr>
322
+ <td>
323
+
324
+ ```ts
325
+ import { BskyAgent, defaultFetchHandler } from "@atproto/api";
326
+
327
+ BskyAgent.configure({
328
+ fetch: async (httpUri, httpMethod, httpHeaders, httpReqBody) => {
329
+ const ua = httpHeaders["User-Agent"];
330
+
331
+ httpHeaders["User-Agent"] = ua ? `${ua} ${userAgent}` : userAgent;
332
+
333
+ return defaultFetchHandler(httpUri, httpMethod, httpHeaders, httpReqBody);
334
+ },
335
+ });
336
+ ```
337
+
338
+ </td>
339
+ <td>
340
+
341
+ ```ts
342
+ import { AtpAgent } from "@atproto/api";
343
+
344
+ class MyAtpAgent extends AtpAgent {
345
+ constructor(options: AtpAgentOptions) {
346
+ const fetch = options.fetch ?? globalThis.fetch;
347
+
348
+ super({
349
+ ...options,
350
+ fetch: async (url, init) => {
351
+ const headers = new Headers(init.headers);
352
+
353
+ const ua = headersList.get("User-Agent");
354
+ headersList.set("User-Agent", ua ? `${ua} ${userAgent}` : userAgent);
355
+
356
+ return fetch(url, { ...init, headers });
357
+ },
358
+ });
359
+ }
360
+ }
361
+ ```
362
+
363
+ </td>
364
+ </tr>
365
+ </table>
366
+
367
+ <!-- <table>
368
+ <tr>
369
+ <td><center>Before</center></td> <td><center>After</center></td>
370
+ </tr>
371
+ <tr>
372
+ <td>
373
+
374
+ ```ts
375
+ // before
376
+ ```
377
+
378
+ </td>
379
+ <td>
380
+
381
+ ```ts
382
+ // after
383
+ ```
384
+
385
+ </td>
386
+ </tr>
387
+ </table> -->
388
+
389
+ ##### The `@atproto/xrpc` package
390
+
391
+ The `Client` and `ServiceClient` classes are now **deprecated**. If you need a
392
+ lexicon based client, you should update the code to use the `XrpcClient` class
393
+ instead.
394
+
395
+ The deprecated `ServiceClient` class now extends the new `XrpcClient` class.
396
+ Because of this, the `fetch` `FetchHandler` can no longer be configured on the
397
+ `Client` instances (including the default export of the package). If you are not
398
+ relying on the `fetch` `FetchHandler`, the new changes should have no impact on
399
+ your code. Beware that the deprecated classes will eventually be removed in a
400
+ future version.
401
+
402
+ Since its use has completely changed, the `FetchHandler` type has also
403
+ completely changed. The new `FetchHandler` type is now a function that receives
404
+ a `url` pathname and a `RequestInit` object and returns a `Promise<Response>`.
405
+ This function is responsible for making the actual request to the server.
406
+
407
+ ```ts
408
+ export type FetchHandler = (
409
+ this: void,
410
+ /**
411
+ * The URL (pathname + query parameters) to make the request to, without the
412
+ * origin. The origin (protocol, hostname, and port) must be added by this
413
+ * {@link FetchHandler}, typically based on authentication or other factors.
414
+ */
415
+ url: string,
416
+ init: RequestInit,
417
+ ) => Promise<Response>;
418
+ ```
419
+
420
+ A noticeable change that has been introduced is that the `uri` field of the
421
+ `ServiceClient` class has _not_ been ported to the new `XrpcClient` class. It is
422
+ now the responsibility of the `FetchHandler` to determine the full URL to make
423
+ the request to. The same goes for the `headers`, which should now be set through
424
+ the `FetchHandler` function.
425
+
426
+ If you _do_ rely on the legacy `Client.fetch` property to perform custom logic
427
+ upon request, you will need to migrate your code to use the new `XrpcClient`
428
+ class. The `XrpcClient` class has a similar API to the old `ServiceClient`
429
+ class, but with a few differences:
430
+
431
+ - The `Client` + `ServiceClient` duality was removed in favor of a single
432
+ `XrpcClient` class. This means that:
433
+
434
+ - There no longer exists a centralized lexicon registry. If you need a global
435
+ lexicon registry, you can maintain one yourself using a `new Lexicons` (from
436
+ `@atproto/lexicon`).
437
+ - The `FetchHandler` is no longer a statically defined property of the
438
+ `Client` class. Instead, it is passed as an argument to the `XrpcClient`
439
+ constructor.
440
+
441
+ - The `XrpcClient` constructor now requires a `FetchHandler` function as the
442
+ first argument, and an optional `Lexicon` instance as the second argument.
443
+ - The `setHeader` and `unsetHeader` methods were not ported to the new
444
+ `XrpcClient` class. If you need to set or unset headers, you should do so in
445
+ the `FetchHandler` function provided in the constructor arg.
446
+
447
+ <table>
448
+ <tr>
449
+ <td><center>Before</center></td> <td><center>After</center></td>
450
+ </tr>
451
+ <tr>
452
+ <td>
453
+
454
+ ```ts
455
+ import client, { defaultFetchHandler } from "@atproto/xrpc";
456
+
457
+ client.fetch = function (
458
+ httpUri: string,
459
+ httpMethod: string,
460
+ httpHeaders: Headers,
461
+ httpReqBody: unknown,
462
+ ) {
463
+ // Custom logic here
464
+ return defaultFetchHandler(httpUri, httpMethod, httpHeaders, httpReqBody);
465
+ };
466
+
467
+ client.addLexicon({
468
+ lexicon: 1,
469
+ id: "io.example.doStuff",
470
+ defs: {},
471
+ });
472
+
473
+ const instance = client.service("http://my-service.com");
474
+
475
+ instance.setHeader("my-header", "my-value");
476
+
477
+ await instance.call("io.example.doStuff");
478
+ ```
479
+
480
+ </td>
481
+ <td>
482
+
483
+ ```ts
484
+ import { XrpcClient } from "@atproto/xrpc";
485
+
486
+ const instance = new XrpcClient(
487
+ async (url, init) => {
488
+ const headers = new Headers(init.headers);
489
+
490
+ headers.set("my-header", "my-value");
491
+
492
+ // Custom logic here
493
+
494
+ const fullUrl = new URL(url, "http://my-service.com");
495
+
496
+ return fetch(fullUrl, { ...init, headers });
497
+ },
498
+ [
499
+ {
500
+ lexicon: 1,
501
+ id: "io.example.doStuff",
502
+ defs: {},
503
+ },
504
+ ],
505
+ );
506
+
507
+ await instance.call("io.example.doStuff");
508
+ ```
509
+
510
+ </td>
511
+ </tr>
512
+ </table>
513
+
514
+ If your fetch handler does not require any "custom logic", and all you need is
515
+ an `XrpcClient` that makes its HTTP requests towards a static service URL, the
516
+ previous example can be simplified to:
517
+
518
+ ```ts
519
+ import { XrpcClient } from "@atproto/xrpc";
520
+
521
+ const instance = new XrpcClient("http://my-service.com", [
522
+ {
523
+ lexicon: 1,
524
+ id: "io.example.doStuff",
525
+ defs: {},
526
+ },
527
+ ]);
528
+ ```
529
+
530
+ If you need to add static headers to all requests, you can instead instantiate
531
+ the `XrpcClient` as follows:
532
+
533
+ ```ts
534
+ import { XrpcClient } from "@atproto/xrpc";
535
+
536
+ const instance = new XrpcClient(
537
+ {
538
+ service: "http://my-service.com",
539
+ headers: {
540
+ "my-header": "my-value",
541
+ },
542
+ },
543
+ [
544
+ {
545
+ lexicon: 1,
546
+ id: "io.example.doStuff",
547
+ defs: {},
548
+ },
549
+ ],
550
+ );
551
+ ```
552
+
553
+ If you need the headers or service url to be dynamic, you can define them using
554
+ functions:
555
+
556
+ ```ts
557
+ import { XrpcClient } from "@atproto/xrpc";
558
+
559
+ const instance = new XrpcClient(
560
+ {
561
+ service: () => "http://my-service.com",
562
+ headers: {
563
+ "my-header": () => "my-value",
564
+ "my-ignored-header": () => null, // ignored
565
+ },
566
+ },
567
+ [
568
+ {
569
+ lexicon: 1,
570
+ id: "io.example.doStuff",
571
+ defs: {},
572
+ },
573
+ ],
574
+ );
575
+ ```
576
+
577
+ - [#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
578
 
33
579
  ### Patch Changes
34
580
 
35
- - Updated dependencies [[`2ded0156b`](https://github.com/bluesky-social/atproto/commit/2ded0156b9adf33b9cce66583a375bff922d383b), [`2ded0156b`](https://github.com/bluesky-social/atproto/commit/2ded0156b9adf33b9cce66583a375bff922d383b)]:
36
- - @atproto/lexicon@0.4.1-rc.0
581
+ - Updated dependencies [[`b934b396b`](https://github.com/bluesky-social/atproto/commit/b934b396b13ba32bf2bf7e75ecdf6871e5f310dd), [`2bdf75d7a`](https://github.com/bluesky-social/atproto/commit/2bdf75d7a63924c10e7a311f16cb447d595b933e)]:
582
+ - @atproto/lexicon@0.4.1
37
583
 
38
584
  ## 0.5.0
39
585
 
package/dist/client.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { LexiconDoc, Lexicons } from '@atproto/lexicon';
2
- import { CallOptions, Gettable, QueryParams } from './types';
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,6 @@ export declare class Client {
18
18
  export declare class ServiceClient extends XrpcClient {
19
19
  baseClient: Client;
20
20
  uri: URL;
21
- protected headers: Map<string, Gettable<string | null>>;
22
21
  constructor(baseClient: Client, serviceUri: string | URL);
23
- setHeader(key: string, value: Gettable<null | 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/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AACvD,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAC5D,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,SAAS,CAAC,OAAO,uCAA6C;gBAGrD,UAAU,EAAE,MAAM,EACzB,UAAU,EAAE,MAAM,GAAG,GAAG;IAS1B,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,IAAI,GAAG,MAAM,CAAC,GAAG,IAAI;IAI5D,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;CAG/B"}
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;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
@@ -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", {
@@ -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: new Map()
72
- });
73
67
  this.uri = typeof serviceUri === 'string' ? new URL(serviceUri) : serviceUri;
74
68
  }
75
- setHeader(key, value) {
76
- this.headers.set(key.toLowerCase(), value);
77
- }
78
- unsetHeader(key) {
79
- this.headers.delete(key.toLowerCase());
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;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,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,CA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AAK,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"}
@@ -29,5 +29,14 @@ export type BuildFetchHandlerOptions = {
29
29
  */
30
30
  fetch?: typeof globalThis.fetch;
31
31
  };
32
- export declare function buildFetchHandler(options: 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