@atproto/xrpc 0.6.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 +100 -90
- package/dist/client.d.ts +0 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +0 -12
- package/dist/client.js.map +1 -1
- package/dist/fetch-handler.d.ts +10 -1
- package/dist/fetch-handler.d.ts.map +1 -1
- package/dist/fetch-handler.js +3 -0
- package/dist/fetch-handler.js.map +1 -1
- package/dist/types.d.ts +4 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +19 -7
- package/dist/types.js.map +1 -1
- package/dist/xrpc-client.d.ts +7 -3
- package/dist/xrpc-client.d.ts.map +1 -1
- package/dist/xrpc-client.js +16 -1
- package/dist/xrpc-client.js.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +0 -9
- package/src/fetch-handler.ts +17 -1
- package/src/types.ts +29 -12
- package/src/xrpc-client.ts +18 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @atproto/xrpc
|
|
2
2
|
|
|
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
|
+
|
|
3
13
|
## 0.6.0
|
|
4
14
|
|
|
5
15
|
### Minor Changes
|
|
@@ -42,7 +52,7 @@
|
|
|
42
52
|
`AtpAgent`.
|
|
43
53
|
|
|
44
54
|
```ts
|
|
45
|
-
import { Agent, AtpAgent } from
|
|
55
|
+
import { Agent, AtpAgent } from "@atproto/api";
|
|
46
56
|
|
|
47
57
|
async function setupAgent(
|
|
48
58
|
service: string,
|
|
@@ -54,30 +64,30 @@
|
|
|
54
64
|
persistSession: (evt, session) => {
|
|
55
65
|
// handle session update
|
|
56
66
|
},
|
|
57
|
-
})
|
|
67
|
+
});
|
|
58
68
|
|
|
59
|
-
await agent.login(username, password)
|
|
69
|
+
await agent.login(username, password);
|
|
60
70
|
|
|
61
|
-
return agent
|
|
71
|
+
return agent;
|
|
62
72
|
}
|
|
63
73
|
```
|
|
64
74
|
|
|
65
75
|
```ts
|
|
66
|
-
import { Agent } from
|
|
76
|
+
import { Agent } from "@atproto/api";
|
|
67
77
|
|
|
68
78
|
async function doStuffWithAgent(agent: Agent, arg: string) {
|
|
69
|
-
return agent.resolveHandle(arg)
|
|
79
|
+
return agent.resolveHandle(arg);
|
|
70
80
|
}
|
|
71
81
|
```
|
|
72
82
|
|
|
73
83
|
```ts
|
|
74
|
-
import { Agent, AtpAgent } from
|
|
84
|
+
import { Agent, AtpAgent } from "@atproto/api";
|
|
75
85
|
|
|
76
86
|
class MyClass {
|
|
77
|
-
agent: Agent
|
|
87
|
+
agent: Agent;
|
|
78
88
|
|
|
79
89
|
constructor() {
|
|
80
|
-
this.agent = new AtpAgent()
|
|
90
|
+
this.agent = new AtpAgent();
|
|
81
91
|
}
|
|
82
92
|
}
|
|
83
93
|
```
|
|
@@ -155,24 +165,24 @@
|
|
|
155
165
|
<td>
|
|
156
166
|
|
|
157
167
|
```ts
|
|
158
|
-
import { AtpBaseClient, ComAtprotoSyncSubscribeRepos } from
|
|
168
|
+
import { AtpBaseClient, ComAtprotoSyncSubscribeRepos } from "@atproto/api";
|
|
159
169
|
|
|
160
|
-
const baseClient = new AtpBaseClient()
|
|
170
|
+
const baseClient = new AtpBaseClient();
|
|
161
171
|
|
|
162
|
-
baseClient.xrpc.lex.assertValidXrpcMessage(
|
|
172
|
+
baseClient.xrpc.lex.assertValidXrpcMessage("io.example.doStuff", {
|
|
163
173
|
// ...
|
|
164
|
-
})
|
|
174
|
+
});
|
|
165
175
|
```
|
|
166
176
|
|
|
167
177
|
</td>
|
|
168
178
|
<td>
|
|
169
179
|
|
|
170
180
|
```ts
|
|
171
|
-
import { lexicons } from
|
|
181
|
+
import { lexicons } from "@atproto/api";
|
|
172
182
|
|
|
173
|
-
lexicons.assertValidXrpcMessage(
|
|
183
|
+
lexicons.assertValidXrpcMessage("io.example.doStuff", {
|
|
174
184
|
// ...
|
|
175
|
-
})
|
|
185
|
+
});
|
|
176
186
|
```
|
|
177
187
|
|
|
178
188
|
</td>
|
|
@@ -189,23 +199,23 @@
|
|
|
189
199
|
<td>
|
|
190
200
|
|
|
191
201
|
```ts
|
|
192
|
-
import { BskyAgent } from
|
|
202
|
+
import { BskyAgent } from "@atproto/api";
|
|
193
203
|
|
|
194
204
|
class MyAgent extends BskyAgent {
|
|
195
|
-
private accessToken?: string
|
|
205
|
+
private accessToken?: string;
|
|
196
206
|
|
|
197
207
|
async createOrRefreshSession(identifier: string, password: string) {
|
|
198
208
|
// custom logic here
|
|
199
209
|
|
|
200
|
-
this.accessToken =
|
|
210
|
+
this.accessToken = "my-access-jwt";
|
|
201
211
|
}
|
|
202
212
|
|
|
203
213
|
async doStuff() {
|
|
204
|
-
return this.call(
|
|
214
|
+
return this.call("io.example.doStuff", {
|
|
205
215
|
headers: {
|
|
206
216
|
Authorization: this.accessToken && `Bearer ${this.accessToken}`,
|
|
207
217
|
},
|
|
208
|
-
})
|
|
218
|
+
});
|
|
209
219
|
}
|
|
210
220
|
}
|
|
211
221
|
```
|
|
@@ -214,11 +224,11 @@
|
|
|
214
224
|
<td>
|
|
215
225
|
|
|
216
226
|
```ts
|
|
217
|
-
import { Agent } from
|
|
227
|
+
import { Agent } from "@atproto/api";
|
|
218
228
|
|
|
219
229
|
class MyAgent extends Agent {
|
|
220
|
-
private accessToken?: string
|
|
221
|
-
public did?: string
|
|
230
|
+
private accessToken?: string;
|
|
231
|
+
public did?: string;
|
|
222
232
|
|
|
223
233
|
constructor(private readonly service: string | URL) {
|
|
224
234
|
super({
|
|
@@ -227,21 +237,21 @@
|
|
|
227
237
|
Authorization: () =>
|
|
228
238
|
this.accessToken ? `Bearer ${this.accessToken}` : null,
|
|
229
239
|
},
|
|
230
|
-
})
|
|
240
|
+
});
|
|
231
241
|
}
|
|
232
242
|
|
|
233
243
|
clone(): MyAgent {
|
|
234
|
-
const agent = new MyAgent(this.service)
|
|
235
|
-
agent.accessToken = this.accessToken
|
|
236
|
-
agent.did = this.did
|
|
237
|
-
return this.copyInto(agent)
|
|
244
|
+
const agent = new MyAgent(this.service);
|
|
245
|
+
agent.accessToken = this.accessToken;
|
|
246
|
+
agent.did = this.did;
|
|
247
|
+
return this.copyInto(agent);
|
|
238
248
|
}
|
|
239
249
|
|
|
240
250
|
async createOrRefreshSession(identifier: string, password: string) {
|
|
241
251
|
// custom logic here
|
|
242
252
|
|
|
243
|
-
this.did =
|
|
244
|
-
this.accessToken =
|
|
253
|
+
this.did = "did:example:123";
|
|
254
|
+
this.accessToken = "my-access-jwt";
|
|
245
255
|
}
|
|
246
256
|
}
|
|
247
257
|
```
|
|
@@ -260,38 +270,38 @@
|
|
|
260
270
|
<td>
|
|
261
271
|
|
|
262
272
|
```ts
|
|
263
|
-
import { BskyAgent } from
|
|
264
|
-
import { RateLimitThreshold } from
|
|
273
|
+
import { BskyAgent } from "@atproto/api";
|
|
274
|
+
import { RateLimitThreshold } from "rate-limit-threshold";
|
|
265
275
|
|
|
266
|
-
const agent = new BskyAgent()
|
|
267
|
-
const limiter = new RateLimitThreshold(3000, 300_000)
|
|
276
|
+
const agent = new BskyAgent();
|
|
277
|
+
const limiter = new RateLimitThreshold(3000, 300_000);
|
|
268
278
|
|
|
269
|
-
const origCall = agent.api.xrpc.call
|
|
279
|
+
const origCall = agent.api.xrpc.call;
|
|
270
280
|
agent.api.xrpc.call = async function (...args) {
|
|
271
|
-
await limiter.wait()
|
|
272
|
-
return origCall.call(this, ...args)
|
|
273
|
-
}
|
|
281
|
+
await limiter.wait();
|
|
282
|
+
return origCall.call(this, ...args);
|
|
283
|
+
};
|
|
274
284
|
```
|
|
275
285
|
|
|
276
286
|
</td>
|
|
277
287
|
<td>
|
|
278
288
|
|
|
279
289
|
```ts
|
|
280
|
-
import { AtpAgent } from
|
|
281
|
-
import { RateLimitThreshold } from
|
|
290
|
+
import { AtpAgent } from "@atproto/api";
|
|
291
|
+
import { RateLimitThreshold } from "rate-limit-threshold";
|
|
282
292
|
|
|
283
293
|
class LimitedAtpAgent extends AtpAgent {
|
|
284
294
|
constructor(options: AtpAgentOptions) {
|
|
285
|
-
const fetch: typeof globalThis.fetch = options.fetch ?? globalThis.fetch
|
|
286
|
-
const limiter = new RateLimitThreshold(3000, 300_000)
|
|
295
|
+
const fetch: typeof globalThis.fetch = options.fetch ?? globalThis.fetch;
|
|
296
|
+
const limiter = new RateLimitThreshold(3000, 300_000);
|
|
287
297
|
|
|
288
298
|
super({
|
|
289
299
|
...options,
|
|
290
300
|
fetch: async (...args) => {
|
|
291
|
-
await limiter.wait()
|
|
292
|
-
return fetch(...args)
|
|
301
|
+
await limiter.wait();
|
|
302
|
+
return fetch(...args);
|
|
293
303
|
},
|
|
294
|
-
})
|
|
304
|
+
});
|
|
295
305
|
}
|
|
296
306
|
}
|
|
297
307
|
```
|
|
@@ -312,40 +322,40 @@
|
|
|
312
322
|
<td>
|
|
313
323
|
|
|
314
324
|
```ts
|
|
315
|
-
import { BskyAgent, defaultFetchHandler } from
|
|
325
|
+
import { BskyAgent, defaultFetchHandler } from "@atproto/api";
|
|
316
326
|
|
|
317
327
|
BskyAgent.configure({
|
|
318
328
|
fetch: async (httpUri, httpMethod, httpHeaders, httpReqBody) => {
|
|
319
|
-
const ua = httpHeaders[
|
|
329
|
+
const ua = httpHeaders["User-Agent"];
|
|
320
330
|
|
|
321
|
-
httpHeaders[
|
|
331
|
+
httpHeaders["User-Agent"] = ua ? `${ua} ${userAgent}` : userAgent;
|
|
322
332
|
|
|
323
|
-
return defaultFetchHandler(httpUri, httpMethod, httpHeaders, httpReqBody)
|
|
333
|
+
return defaultFetchHandler(httpUri, httpMethod, httpHeaders, httpReqBody);
|
|
324
334
|
},
|
|
325
|
-
})
|
|
335
|
+
});
|
|
326
336
|
```
|
|
327
337
|
|
|
328
338
|
</td>
|
|
329
339
|
<td>
|
|
330
340
|
|
|
331
341
|
```ts
|
|
332
|
-
import { AtpAgent } from
|
|
342
|
+
import { AtpAgent } from "@atproto/api";
|
|
333
343
|
|
|
334
344
|
class MyAtpAgent extends AtpAgent {
|
|
335
345
|
constructor(options: AtpAgentOptions) {
|
|
336
|
-
const fetch = options.fetch ?? globalThis.fetch
|
|
346
|
+
const fetch = options.fetch ?? globalThis.fetch;
|
|
337
347
|
|
|
338
348
|
super({
|
|
339
349
|
...options,
|
|
340
350
|
fetch: async (url, init) => {
|
|
341
|
-
const headers = new Headers(init.headers)
|
|
351
|
+
const headers = new Headers(init.headers);
|
|
342
352
|
|
|
343
|
-
const ua = headersList.get(
|
|
344
|
-
headersList.set(
|
|
353
|
+
const ua = headersList.get("User-Agent");
|
|
354
|
+
headersList.set("User-Agent", ua ? `${ua} ${userAgent}` : userAgent);
|
|
345
355
|
|
|
346
|
-
return fetch(url, { ...init, headers })
|
|
356
|
+
return fetch(url, { ...init, headers });
|
|
347
357
|
},
|
|
348
|
-
})
|
|
358
|
+
});
|
|
349
359
|
}
|
|
350
360
|
}
|
|
351
361
|
```
|
|
@@ -404,7 +414,7 @@
|
|
|
404
414
|
*/
|
|
405
415
|
url: string,
|
|
406
416
|
init: RequestInit,
|
|
407
|
-
) => Promise<Response
|
|
417
|
+
) => Promise<Response>;
|
|
408
418
|
```
|
|
409
419
|
|
|
410
420
|
A noticeable change that has been introduced is that the `uri` field of the
|
|
@@ -442,7 +452,7 @@
|
|
|
442
452
|
<td>
|
|
443
453
|
|
|
444
454
|
```ts
|
|
445
|
-
import client, { defaultFetchHandler } from
|
|
455
|
+
import client, { defaultFetchHandler } from "@atproto/xrpc";
|
|
446
456
|
|
|
447
457
|
client.fetch = function (
|
|
448
458
|
httpUri: string,
|
|
@@ -451,50 +461,50 @@
|
|
|
451
461
|
httpReqBody: unknown,
|
|
452
462
|
) {
|
|
453
463
|
// Custom logic here
|
|
454
|
-
return defaultFetchHandler(httpUri, httpMethod, httpHeaders, httpReqBody)
|
|
455
|
-
}
|
|
464
|
+
return defaultFetchHandler(httpUri, httpMethod, httpHeaders, httpReqBody);
|
|
465
|
+
};
|
|
456
466
|
|
|
457
467
|
client.addLexicon({
|
|
458
468
|
lexicon: 1,
|
|
459
|
-
id:
|
|
469
|
+
id: "io.example.doStuff",
|
|
460
470
|
defs: {},
|
|
461
|
-
})
|
|
471
|
+
});
|
|
462
472
|
|
|
463
|
-
const instance = client.service(
|
|
473
|
+
const instance = client.service("http://my-service.com");
|
|
464
474
|
|
|
465
|
-
instance.setHeader(
|
|
475
|
+
instance.setHeader("my-header", "my-value");
|
|
466
476
|
|
|
467
|
-
await instance.call(
|
|
477
|
+
await instance.call("io.example.doStuff");
|
|
468
478
|
```
|
|
469
479
|
|
|
470
480
|
</td>
|
|
471
481
|
<td>
|
|
472
482
|
|
|
473
483
|
```ts
|
|
474
|
-
import { XrpcClient } from
|
|
484
|
+
import { XrpcClient } from "@atproto/xrpc";
|
|
475
485
|
|
|
476
486
|
const instance = new XrpcClient(
|
|
477
487
|
async (url, init) => {
|
|
478
|
-
const headers = new Headers(init.headers)
|
|
488
|
+
const headers = new Headers(init.headers);
|
|
479
489
|
|
|
480
|
-
headers.set(
|
|
490
|
+
headers.set("my-header", "my-value");
|
|
481
491
|
|
|
482
492
|
// Custom logic here
|
|
483
493
|
|
|
484
|
-
const fullUrl = new URL(url,
|
|
494
|
+
const fullUrl = new URL(url, "http://my-service.com");
|
|
485
495
|
|
|
486
|
-
return fetch(fullUrl, { ...init, headers })
|
|
496
|
+
return fetch(fullUrl, { ...init, headers });
|
|
487
497
|
},
|
|
488
498
|
[
|
|
489
499
|
{
|
|
490
500
|
lexicon: 1,
|
|
491
|
-
id:
|
|
501
|
+
id: "io.example.doStuff",
|
|
492
502
|
defs: {},
|
|
493
503
|
},
|
|
494
504
|
],
|
|
495
|
-
)
|
|
505
|
+
);
|
|
496
506
|
|
|
497
|
-
await instance.call(
|
|
507
|
+
await instance.call("io.example.doStuff");
|
|
498
508
|
```
|
|
499
509
|
|
|
500
510
|
</td>
|
|
@@ -506,62 +516,62 @@
|
|
|
506
516
|
previous example can be simplified to:
|
|
507
517
|
|
|
508
518
|
```ts
|
|
509
|
-
import { XrpcClient } from
|
|
519
|
+
import { XrpcClient } from "@atproto/xrpc";
|
|
510
520
|
|
|
511
|
-
const instance = new XrpcClient(
|
|
521
|
+
const instance = new XrpcClient("http://my-service.com", [
|
|
512
522
|
{
|
|
513
523
|
lexicon: 1,
|
|
514
|
-
id:
|
|
524
|
+
id: "io.example.doStuff",
|
|
515
525
|
defs: {},
|
|
516
526
|
},
|
|
517
|
-
])
|
|
527
|
+
]);
|
|
518
528
|
```
|
|
519
529
|
|
|
520
530
|
If you need to add static headers to all requests, you can instead instantiate
|
|
521
531
|
the `XrpcClient` as follows:
|
|
522
532
|
|
|
523
533
|
```ts
|
|
524
|
-
import { XrpcClient } from
|
|
534
|
+
import { XrpcClient } from "@atproto/xrpc";
|
|
525
535
|
|
|
526
536
|
const instance = new XrpcClient(
|
|
527
537
|
{
|
|
528
|
-
service:
|
|
538
|
+
service: "http://my-service.com",
|
|
529
539
|
headers: {
|
|
530
|
-
|
|
540
|
+
"my-header": "my-value",
|
|
531
541
|
},
|
|
532
542
|
},
|
|
533
543
|
[
|
|
534
544
|
{
|
|
535
545
|
lexicon: 1,
|
|
536
|
-
id:
|
|
546
|
+
id: "io.example.doStuff",
|
|
537
547
|
defs: {},
|
|
538
548
|
},
|
|
539
549
|
],
|
|
540
|
-
)
|
|
550
|
+
);
|
|
541
551
|
```
|
|
542
552
|
|
|
543
553
|
If you need the headers or service url to be dynamic, you can define them using
|
|
544
554
|
functions:
|
|
545
555
|
|
|
546
556
|
```ts
|
|
547
|
-
import { XrpcClient } from
|
|
557
|
+
import { XrpcClient } from "@atproto/xrpc";
|
|
548
558
|
|
|
549
559
|
const instance = new XrpcClient(
|
|
550
560
|
{
|
|
551
|
-
service: () =>
|
|
561
|
+
service: () => "http://my-service.com",
|
|
552
562
|
headers: {
|
|
553
|
-
|
|
554
|
-
|
|
563
|
+
"my-header": () => "my-value",
|
|
564
|
+
"my-ignored-header": () => null, // ignored
|
|
555
565
|
},
|
|
556
566
|
},
|
|
557
567
|
[
|
|
558
568
|
{
|
|
559
569
|
lexicon: 1,
|
|
560
|
-
id:
|
|
570
|
+
id: "io.example.doStuff",
|
|
561
571
|
defs: {},
|
|
562
572
|
},
|
|
563
573
|
],
|
|
564
|
-
)
|
|
574
|
+
);
|
|
565
575
|
```
|
|
566
576
|
|
|
567
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.
|
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
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AACvD,OAAO,EAAE,WAAW,EAAE,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;
|
|
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
|
@@ -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
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AAAA,8CAAuD;AAEvD,+CAA0C;AAC1C,iCAAuC;AAEvC,iDAAiD;AACjD,MAAa,MAAM;IAAnB;QAeE;;;;mBAAM,IAAI,kBAAQ,EAAE;WAAA;IAmCtB,CAAC;IAjDC,kBAAkB;IAClB,IAAI,KAAK;QACP,MAAM,IAAI,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;
|
|
1
|
+
{"version":3,"file":"client.js","sour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E,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"}
|
package/dist/fetch-handler.d.ts
CHANGED
|
@@ -29,5 +29,14 @@ export type BuildFetchHandlerOptions = {
|
|
|
29
29
|
*/
|
|
30
30
|
fetch?: typeof globalThis.fetch;
|
|
31
31
|
};
|
|
32
|
-
export
|
|
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,CA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AAC,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"}
|
package/dist/fetch-handler.js
CHANGED
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"fetch-handler.js","sourceRoot":"","sources":["../src/fetch-handler.ts"],"names":[],"mappings":";;;AACA,iCAAuC;AAqDvC,SAAgB,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,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;AAlCD,8CAkCC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -2,8 +2,9 @@ import { z } from 'zod';
|
|
|
2
2
|
import { 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
|
-
|
|
7
|
+
HeadersMap as Headers, };
|
|
7
8
|
export type Gettable<T> = T | (() => T);
|
|
8
9
|
export interface CallOptions {
|
|
9
10
|
encoding?: string;
|
|
@@ -74,9 +75,9 @@ export declare const ResponseTypeStrings: {
|
|
|
74
75
|
export declare function httpResponseCodeToString(status: number): string;
|
|
75
76
|
export declare class XRPCResponse {
|
|
76
77
|
data: any;
|
|
77
|
-
headers:
|
|
78
|
+
headers: HeadersMap;
|
|
78
79
|
success: boolean;
|
|
79
|
-
constructor(data: any, headers:
|
|
80
|
+
constructor(data: any, headers: HeadersMap);
|
|
80
81
|
}
|
|
81
82
|
export declare class XRPCError extends Error {
|
|
82
83
|
error: string;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -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/C,yEAAyE;AACzE,
|
|
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/C,YAAY;AACV,yEAAyE;AACzE,UAAU,IAAI,OAAO,GACtB,CAAA;AAED,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAA;AAEvC,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,OAAO,CA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AG,SAAS;CAqCtE;AAED,qBAAa,wBAAyB,SAAQ,SAAS;IAE5C,WAAW,EAAE,MAAM;IACnB,eAAe,EAAE,eAAe;IAChC,YAAY,EAAE,OAAO;gBAFrB,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,eAAe,EAChC,YAAY,EAAE,OAAO;CAU/B"}
|
package/dist/types.js
CHANGED
|
@@ -145,17 +145,29 @@ class XRPCError extends Error {
|
|
|
145
145
|
if (cause instanceof XRPCError) {
|
|
146
146
|
return cause;
|
|
147
147
|
}
|
|
148
|
+
// Type cast the cause to an Error if it is one
|
|
149
|
+
const causeErr = cause instanceof Error ? cause : undefined;
|
|
150
|
+
// Try and find a Response object in the cause
|
|
151
|
+
const causeResponse = cause instanceof Response
|
|
152
|
+
? cause
|
|
153
|
+
: cause?.['response'] instanceof Response
|
|
154
|
+
? cause['response']
|
|
155
|
+
: undefined;
|
|
156
|
+
const statusCode =
|
|
148
157
|
// Extract status code from "http-errors" like errors
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
158
|
+
causeErr?.['statusCode'] ??
|
|
159
|
+
causeErr?.['status'] ??
|
|
160
|
+
// Use the status code from the response object as fallback
|
|
161
|
+
causeResponse?.status;
|
|
162
|
+
// Convert the status code to a ResponseType
|
|
153
163
|
const status = typeof statusCode === 'number'
|
|
154
164
|
? httpResponseCodeToEnum(statusCode)
|
|
155
165
|
: fallbackStatus ?? ResponseType.Unknown;
|
|
156
|
-
const
|
|
157
|
-
const
|
|
158
|
-
|
|
166
|
+
const message = causeErr?.message ?? String(cause);
|
|
167
|
+
const headers = causeResponse
|
|
168
|
+
? Object.fromEntries(causeResponse.headers.entries())
|
|
169
|
+
: undefined;
|
|
170
|
+
return new XRPCError(status, undefined, message, headers, { cause });
|
|
159
171
|
}
|
|
160
172
|
}
|
|
161
173
|
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;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAAA,6BAAuB;AAmBV,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,CAAA;IACzB,iFAA0B,CAAA;IAC1B,uEAAqB,CAAA;IACrB,6EAAwB,CAAA;IACxB,uEAAqB,CAAA;AACvB,CAAC,EAfW,YAAY,4BAAZ,YAAY,QAevB;AAED,SAAgB,sBAAsB,CAAC,MAAc;IACnD,IAAI,MAAM,IAAI,YAAY,EAAE,CAAC;QAC3B,OAAO,MAAM,CAAA;IACf,CAAC;SAAM,IAAI,MAAM,IAAI,GAAG,IAAI,MAAM,GAAG,GAAG,EAAE,CAAC;QACzC,OAAO,YAAY,CAAC,gBAAgB,CAAA;IACtC,CAAC;SAAM,IAAI,MAAM,IAAI,GAAG,IAAI,MAAM,GAAG,GAAG,EAAE,CAAC;QACzC,OAAO,YAAY,CAAC,OAAO,CAAA;IAC7B,CAAC;SAAM,IAAI,MAAM,IAAI,GAAG,IAAI,MAAM,GAAG,GAAG,EAAE,CAAC;QACzC,OAAO,YAAY,CAAC,gBAAgB,CAAA;IACtC,CAAC;SAAM,IAAI,MAAM,IAAI,GAAG,IAAI,MAAM,GAAG,GAAG,EAAE,CAAC;QACz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,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;IACtE,CAAC;CACF;AA5DD,8BA4DC;AAED,MAAa,wBAAyB,SAAQ,SAAS;IACrD,YACS,WAAmB,EACnB,eAAgC,EAChC,YAAqB;QAE5B,KAAK,CACH,YAAY,CAAC,eAAe,EAC5B,2BAAmB,CAAC,YAAY,CAAC,eAAe,CAAC,EACjD,6DAA6D,EAC7D,SAAS,EACT,EAAE,KAAK,EAAE,eAAe,EAAE,CAC3B,CAAA;QAVD;;;;mBAAO,WAAW;WAAQ;QAC1B;;;;mBAAO,eAAe;WAAiB;QACvC;;;;mBAAO,YAAY;WAAS;IAS9B,CAAC;CACF;AAdD,4DAcC"}
|
package/dist/xrpc-client.d.ts
CHANGED
|
@@ -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;
|
|
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,kBAAkB,EAClB,mBAAmB,EAEpB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,WAAW,EACX,QAAQ,EACR,WAAW,EAIX,YAAY,EAEb,MAAM,SAAS,CAAA;AAWhB,qBAAa,UAAU;IACrB,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAA;IACnC,QAAQ,CAAC,OAAO,uCAA6C;IAC7D,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAA;gBAGpB,gBAAgB,EAAE,YAAY,GAAG,kBAAkB,GAAG,mBAAmB,EAGzE,GAAG,EAAE,QAAQ,GAAG,QAAQ,CAAC,UAAU,CAAC;IAOtC,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,IAAI,GAAG,MAAM,CAAC,GAAG,IAAI;IAI5D,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAI9B,YAAY,IAAI,IAAI;IAId,IAAI,CACR,UAAU,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,WAAW,EACpB,IAAI,CAAC,EAAE,OAAO,EACd,IAAI,CAAC,EAAE,WAAW,GACjB,OAAO,CAAC,YAAY,CAAC;CA8DzB"}
|
package/dist/xrpc-client.js
CHANGED
|
@@ -16,6 +16,12 @@ class XrpcClient {
|
|
|
16
16
|
writable: true,
|
|
17
17
|
value: void 0
|
|
18
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,
|
package/dist/xrpc-client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xrpc-client.js","sourceRoot":"","sources":["../src/xrpc-client.ts"],"names":[],"mappings":";;;AAAA,8CAAwE;AACxE,
|
|
1
|
+
{"version":3,"file":"xrpc-client.js","sourceRoot":"","sources":["../src/xrpc-client.ts"],"names":[],"mappings":";;;AAAA,8CAAwE;AACxE,mDAKwB;AACxB,mCASgB;AAChB,iCAQe;AAEf,MAAa,UAAU;IAKrB,YACE,gBAAyE;IACzE,8DAA8D;IAC9D,2DAA2D;IAC3D,GAAoC;QAR7B;;;;;WAA0B;QAC1B;;;;mBAAU,IAAI,GAAG,EAAmC;WAAA;QACpD;;;;;WAAa;QAQpB,IAAI,CAAC,YAAY,GAAG,IAAA,iCAAiB,EAAC,gBAAgB,CAAC,CAAA;QAEvD,IAAI,CAAC,GAAG,GAAG,GAAG,YAAY,kBAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,kBAAQ,CAAC,GAAG,CAAC,CAAA;IAC9D,CAAC;IAED,SAAS,CAAC,GAAW,EAAE,KAA8B;QACnD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,KAAK,CAAC,CAAA;IAC5C,CAAC;IAED,WAAW,CAAC,GAAW;QACrB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAA;IACxC,CAAC;IAED,YAAY;QACV,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAA;IACtB,CAAC;IAED,KAAK,CAAC,IAAI,CACR,UAAkB,EAClB,MAAoB,EACpB,IAAc,EACd,IAAkB;QAElB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,UAAU,CAAC,CAAA;QAC9C,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,KAAK,OAAO,IAAI,GAAG,CAAC,IAAI,KAAK,WAAW,CAAC,EAAE,CAAC;YAC/D,MAAM,IAAI,SAAS,CACjB,oBAAoB,UAAU,i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BACrC,MAAM,EAAE,KAAK,GAAG,SAAS,EAAE,OAAO,GAAG,SAAS,EAAE,GAC9C,OAAO,IAAI,IAAA,0BAAmB,EAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAA;gBACxD,MAAM,IAAI,iBAAS,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,CAAC,CAAA;YAC1D,CAAC;YAED,IAAI,CAAC;gBACH,IAAI,CAAC,GAAG,CAAC,qBAAqB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;YACrD,CAAC;YAAC,OAAO,CAAU,EAAE,CAAC;gBACpB,IAAI,CAAC,YAAY,yBAAe,EAAE,CAAC;oBACjC,MAAM,IAAI,gCAAwB,CAAC,UAAU,EAAE,CAAC,EAAE,OAAO,CAAC,CAAA;gBAC5D,CAAC;gBAED,MAAM,CAAC,CAAA;YACT,CAAC;YAED,OAAO,IAAI,oBAAY,CAAC,OAAO,EAAE,UAAU,CAAC,CAAA;QAC9C,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,iBAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAC3B,CAAC;IACH,CAAC;CACF;AA/FD,gCA+FC"}
|
package/package.json
CHANGED
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
|
}
|
package/src/fetch-handler.ts
CHANGED
|
@@ -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
|
-
|
|
8
|
-
|
|
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
|
|
|
@@ -101,7 +103,7 @@ export class XRPCResponse {
|
|
|
101
103
|
|
|
102
104
|
constructor(
|
|
103
105
|
public data: any,
|
|
104
|
-
public headers:
|
|
106
|
+
public headers: HeadersMap,
|
|
105
107
|
) {}
|
|
106
108
|
}
|
|
107
109
|
|
|
@@ -114,7 +116,7 @@ export class XRPCError extends Error {
|
|
|
114
116
|
statusCode: number,
|
|
115
117
|
public error: string = httpResponseCodeToName(statusCode),
|
|
116
118
|
message?: string,
|
|
117
|
-
public headers?:
|
|
119
|
+
public headers?: HeadersMap,
|
|
118
120
|
options?: ErrorOptions,
|
|
119
121
|
) {
|
|
120
122
|
super(message || error || httpResponseCodeToString(statusCode), options)
|
|
@@ -133,22 +135,37 @@ export class XRPCError extends Error {
|
|
|
133
135
|
return cause
|
|
134
136
|
}
|
|
135
137
|
|
|
136
|
-
//
|
|
138
|
+
// Type cast the cause to an Error if it is one
|
|
139
|
+
const causeErr = cause instanceof Error ? cause : undefined
|
|
140
|
+
|
|
141
|
+
// Try and find a Response object in the cause
|
|
142
|
+
const causeResponse: Response | undefined =
|
|
143
|
+
cause instanceof Response
|
|
144
|
+
? cause
|
|
145
|
+
: cause?.['response'] instanceof Response
|
|
146
|
+
? cause['response']
|
|
147
|
+
: undefined
|
|
148
|
+
|
|
137
149
|
const statusCode: unknown =
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
150
|
+
// Extract status code from "http-errors" like errors
|
|
151
|
+
causeErr?.['statusCode'] ??
|
|
152
|
+
causeErr?.['status'] ??
|
|
153
|
+
// Use the status code from the response object as fallback
|
|
154
|
+
causeResponse?.status
|
|
142
155
|
|
|
156
|
+
// Convert the status code to a ResponseType
|
|
143
157
|
const status: ResponseType =
|
|
144
158
|
typeof statusCode === 'number'
|
|
145
159
|
? httpResponseCodeToEnum(statusCode)
|
|
146
160
|
: fallbackStatus ?? ResponseType.Unknown
|
|
147
161
|
|
|
148
|
-
const
|
|
149
|
-
|
|
162
|
+
const message = causeErr?.message ?? String(cause)
|
|
163
|
+
|
|
164
|
+
const headers = causeResponse
|
|
165
|
+
? Object.fromEntries(causeResponse.headers.entries())
|
|
166
|
+
: undefined
|
|
150
167
|
|
|
151
|
-
return new XRPCError(status,
|
|
168
|
+
return new XRPCError(status, undefined, message, headers, { cause })
|
|
152
169
|
}
|
|
153
170
|
}
|
|
154
171
|
|
package/src/xrpc-client.ts
CHANGED
|
@@ -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,
|