@atproto/api 0.13.0 → 0.13.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,5 +1,11 @@
1
1
  # @atproto/api
2
2
 
3
+ ## 0.13.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2708](https://github.com/bluesky-social/atproto/pull/2708) [`22af354a5`](https://github.com/bluesky-social/atproto/commit/22af354a5db595d7cbc0e65f02601de3565337e1) Thanks [@devinivy](https://github.com/devinivy)! - Export AtpAgentOptions type to better support extending AtpAgent.
8
+
3
9
  ## 0.13.0
4
10
 
5
11
  ### Minor Changes
@@ -42,7 +48,7 @@
42
48
  `AtpAgent`.
43
49
 
44
50
  ```ts
45
- import { Agent, AtpAgent } from '@atproto/api'
51
+ import { Agent, AtpAgent } from "@atproto/api";
46
52
 
47
53
  async function setupAgent(
48
54
  service: string,
@@ -54,30 +60,30 @@
54
60
  persistSession: (evt, session) => {
55
61
  // handle session update
56
62
  },
57
- })
63
+ });
58
64
 
59
- await agent.login(username, password)
65
+ await agent.login(username, password);
60
66
 
61
- return agent
67
+ return agent;
62
68
  }
63
69
  ```
64
70
 
65
71
  ```ts
66
- import { Agent } from '@atproto/api'
72
+ import { Agent } from "@atproto/api";
67
73
 
68
74
  async function doStuffWithAgent(agent: Agent, arg: string) {
69
- return agent.resolveHandle(arg)
75
+ return agent.resolveHandle(arg);
70
76
  }
71
77
  ```
72
78
 
73
79
  ```ts
74
- import { Agent, AtpAgent } from '@atproto/api'
80
+ import { Agent, AtpAgent } from "@atproto/api";
75
81
 
76
82
  class MyClass {
77
- agent: Agent
83
+ agent: Agent;
78
84
 
79
85
  constructor() {
80
- this.agent = new AtpAgent()
86
+ this.agent = new AtpAgent();
81
87
  }
82
88
  }
83
89
  ```
@@ -155,24 +161,24 @@
155
161
  <td>
156
162
 
157
163
  ```ts
158
- import { AtpBaseClient, ComAtprotoSyncSubscribeRepos } from '@atproto/api'
164
+ import { AtpBaseClient, ComAtprotoSyncSubscribeRepos } from "@atproto/api";
159
165
 
160
- const baseClient = new AtpBaseClient()
166
+ const baseClient = new AtpBaseClient();
161
167
 
162
- baseClient.xrpc.lex.assertValidXrpcMessage('io.example.doStuff', {
168
+ baseClient.xrpc.lex.assertValidXrpcMessage("io.example.doStuff", {
163
169
  // ...
164
- })
170
+ });
165
171
  ```
166
172
 
167
173
  </td>
168
174
  <td>
169
175
 
170
176
  ```ts
171
- import { lexicons } from '@atproto/api'
177
+ import { lexicons } from "@atproto/api";
172
178
 
173
- lexicons.assertValidXrpcMessage('io.example.doStuff', {
179
+ lexicons.assertValidXrpcMessage("io.example.doStuff", {
174
180
  // ...
175
- })
181
+ });
176
182
  ```
177
183
 
178
184
  </td>
@@ -189,23 +195,23 @@
189
195
  <td>
190
196
 
191
197
  ```ts
192
- import { BskyAgent } from '@atproto/api'
198
+ import { BskyAgent } from "@atproto/api";
193
199
 
194
200
  class MyAgent extends BskyAgent {
195
- private accessToken?: string
201
+ private accessToken?: string;
196
202
 
197
203
  async createOrRefreshSession(identifier: string, password: string) {
198
204
  // custom logic here
199
205
 
200
- this.accessToken = 'my-access-jwt'
206
+ this.accessToken = "my-access-jwt";
201
207
  }
202
208
 
203
209
  async doStuff() {
204
- return this.call('io.example.doStuff', {
210
+ return this.call("io.example.doStuff", {
205
211
  headers: {
206
212
  Authorization: this.accessToken && `Bearer ${this.accessToken}`,
207
213
  },
208
- })
214
+ });
209
215
  }
210
216
  }
211
217
  ```
@@ -214,11 +220,11 @@
214
220
  <td>
215
221
 
216
222
  ```ts
217
- import { Agent } from '@atproto/api'
223
+ import { Agent } from "@atproto/api";
218
224
 
219
225
  class MyAgent extends Agent {
220
- private accessToken?: string
221
- public did?: string
226
+ private accessToken?: string;
227
+ public did?: string;
222
228
 
223
229
  constructor(private readonly service: string | URL) {
224
230
  super({
@@ -227,21 +233,21 @@
227
233
  Authorization: () =>
228
234
  this.accessToken ? `Bearer ${this.accessToken}` : null,
229
235
  },
230
- })
236
+ });
231
237
  }
232
238
 
233
239
  clone(): MyAgent {
234
- const agent = new MyAgent(this.service)
235
- agent.accessToken = this.accessToken
236
- agent.did = this.did
237
- return this.copyInto(agent)
240
+ const agent = new MyAgent(this.service);
241
+ agent.accessToken = this.accessToken;
242
+ agent.did = this.did;
243
+ return this.copyInto(agent);
238
244
  }
239
245
 
240
246
  async createOrRefreshSession(identifier: string, password: string) {
241
247
  // custom logic here
242
248
 
243
- this.did = 'did:example:123'
244
- this.accessToken = 'my-access-jwt'
249
+ this.did = "did:example:123";
250
+ this.accessToken = "my-access-jwt";
245
251
  }
246
252
  }
247
253
  ```
@@ -260,38 +266,38 @@
260
266
  <td>
261
267
 
262
268
  ```ts
263
- import { BskyAgent } from '@atproto/api'
264
- import { RateLimitThreshold } from 'rate-limit-threshold'
269
+ import { BskyAgent } from "@atproto/api";
270
+ import { RateLimitThreshold } from "rate-limit-threshold";
265
271
 
266
- const agent = new BskyAgent()
267
- const limiter = new RateLimitThreshold(3000, 300_000)
272
+ const agent = new BskyAgent();
273
+ const limiter = new RateLimitThreshold(3000, 300_000);
268
274
 
269
- const origCall = agent.api.xrpc.call
275
+ const origCall = agent.api.xrpc.call;
270
276
  agent.api.xrpc.call = async function (...args) {
271
- await limiter.wait()
272
- return origCall.call(this, ...args)
273
- }
277
+ await limiter.wait();
278
+ return origCall.call(this, ...args);
279
+ };
274
280
  ```
275
281
 
276
282
  </td>
277
283
  <td>
278
284
 
279
285
  ```ts
280
- import { AtpAgent } from '@atproto/api'
281
- import { RateLimitThreshold } from 'rate-limit-threshold'
286
+ import { AtpAgent } from "@atproto/api";
287
+ import { RateLimitThreshold } from "rate-limit-threshold";
282
288
 
283
289
  class LimitedAtpAgent extends AtpAgent {
284
290
  constructor(options: AtpAgentOptions) {
285
- const fetch: typeof globalThis.fetch = options.fetch ?? globalThis.fetch
286
- const limiter = new RateLimitThreshold(3000, 300_000)
291
+ const fetch: typeof globalThis.fetch = options.fetch ?? globalThis.fetch;
292
+ const limiter = new RateLimitThreshold(3000, 300_000);
287
293
 
288
294
  super({
289
295
  ...options,
290
296
  fetch: async (...args) => {
291
- await limiter.wait()
292
- return fetch(...args)
297
+ await limiter.wait();
298
+ return fetch(...args);
293
299
  },
294
- })
300
+ });
295
301
  }
296
302
  }
297
303
  ```
@@ -312,40 +318,40 @@
312
318
  <td>
313
319
 
314
320
  ```ts
315
- import { BskyAgent, defaultFetchHandler } from '@atproto/api'
321
+ import { BskyAgent, defaultFetchHandler } from "@atproto/api";
316
322
 
317
323
  BskyAgent.configure({
318
324
  fetch: async (httpUri, httpMethod, httpHeaders, httpReqBody) => {
319
- const ua = httpHeaders['User-Agent']
325
+ const ua = httpHeaders["User-Agent"];
320
326
 
321
- httpHeaders['User-Agent'] = ua ? `${ua} ${userAgent}` : userAgent
327
+ httpHeaders["User-Agent"] = ua ? `${ua} ${userAgent}` : userAgent;
322
328
 
323
- return defaultFetchHandler(httpUri, httpMethod, httpHeaders, httpReqBody)
329
+ return defaultFetchHandler(httpUri, httpMethod, httpHeaders, httpReqBody);
324
330
  },
325
- })
331
+ });
326
332
  ```
327
333
 
328
334
  </td>
329
335
  <td>
330
336
 
331
337
  ```ts
332
- import { AtpAgent } from '@atproto/api'
338
+ import { AtpAgent } from "@atproto/api";
333
339
 
334
340
  class MyAtpAgent extends AtpAgent {
335
341
  constructor(options: AtpAgentOptions) {
336
- const fetch = options.fetch ?? globalThis.fetch
342
+ const fetch = options.fetch ?? globalThis.fetch;
337
343
 
338
344
  super({
339
345
  ...options,
340
346
  fetch: async (url, init) => {
341
- const headers = new Headers(init.headers)
347
+ const headers = new Headers(init.headers);
342
348
 
343
- const ua = headersList.get('User-Agent')
344
- headersList.set('User-Agent', ua ? `${ua} ${userAgent}` : userAgent)
349
+ const ua = headersList.get("User-Agent");
350
+ headersList.set("User-Agent", ua ? `${ua} ${userAgent}` : userAgent);
345
351
 
346
- return fetch(url, { ...init, headers })
352
+ return fetch(url, { ...init, headers });
347
353
  },
348
- })
354
+ });
349
355
  }
350
356
  }
351
357
  ```
@@ -404,7 +410,7 @@
404
410
  */
405
411
  url: string,
406
412
  init: RequestInit,
407
- ) => Promise<Response>
413
+ ) => Promise<Response>;
408
414
  ```
409
415
 
410
416
  A noticeable change that has been introduced is that the `uri` field of the
@@ -442,7 +448,7 @@
442
448
  <td>
443
449
 
444
450
  ```ts
445
- import client, { defaultFetchHandler } from '@atproto/xrpc'
451
+ import client, { defaultFetchHandler } from "@atproto/xrpc";
446
452
 
447
453
  client.fetch = function (
448
454
  httpUri: string,
@@ -451,50 +457,50 @@
451
457
  httpReqBody: unknown,
452
458
  ) {
453
459
  // Custom logic here
454
- return defaultFetchHandler(httpUri, httpMethod, httpHeaders, httpReqBody)
455
- }
460
+ return defaultFetchHandler(httpUri, httpMethod, httpHeaders, httpReqBody);
461
+ };
456
462
 
457
463
  client.addLexicon({
458
464
  lexicon: 1,
459
- id: 'io.example.doStuff',
465
+ id: "io.example.doStuff",
460
466
  defs: {},
461
- })
467
+ });
462
468
 
463
- const instance = client.service('http://my-service.com')
469
+ const instance = client.service("http://my-service.com");
464
470
 
465
- instance.setHeader('my-header', 'my-value')
471
+ instance.setHeader("my-header", "my-value");
466
472
 
467
- await instance.call('io.example.doStuff')
473
+ await instance.call("io.example.doStuff");
468
474
  ```
469
475
 
470
476
  </td>
471
477
  <td>
472
478
 
473
479
  ```ts
474
- import { XrpcClient } from '@atproto/xrpc'
480
+ import { XrpcClient } from "@atproto/xrpc";
475
481
 
476
482
  const instance = new XrpcClient(
477
483
  async (url, init) => {
478
- const headers = new Headers(init.headers)
484
+ const headers = new Headers(init.headers);
479
485
 
480
- headers.set('my-header', 'my-value')
486
+ headers.set("my-header", "my-value");
481
487
 
482
488
  // Custom logic here
483
489
 
484
- const fullUrl = new URL(url, 'http://my-service.com')
490
+ const fullUrl = new URL(url, "http://my-service.com");
485
491
 
486
- return fetch(fullUrl, { ...init, headers })
492
+ return fetch(fullUrl, { ...init, headers });
487
493
  },
488
494
  [
489
495
  {
490
496
  lexicon: 1,
491
- id: 'io.example.doStuff',
497
+ id: "io.example.doStuff",
492
498
  defs: {},
493
499
  },
494
500
  ],
495
- )
501
+ );
496
502
 
497
- await instance.call('io.example.doStuff')
503
+ await instance.call("io.example.doStuff");
498
504
  ```
499
505
 
500
506
  </td>
@@ -506,62 +512,62 @@
506
512
  previous example can be simplified to:
507
513
 
508
514
  ```ts
509
- import { XrpcClient } from '@atproto/xrpc'
515
+ import { XrpcClient } from "@atproto/xrpc";
510
516
 
511
- const instance = new XrpcClient('http://my-service.com', [
517
+ const instance = new XrpcClient("http://my-service.com", [
512
518
  {
513
519
  lexicon: 1,
514
- id: 'io.example.doStuff',
520
+ id: "io.example.doStuff",
515
521
  defs: {},
516
522
  },
517
- ])
523
+ ]);
518
524
  ```
519
525
 
520
526
  If you need to add static headers to all requests, you can instead instantiate
521
527
  the `XrpcClient` as follows:
522
528
 
523
529
  ```ts
524
- import { XrpcClient } from '@atproto/xrpc'
530
+ import { XrpcClient } from "@atproto/xrpc";
525
531
 
526
532
  const instance = new XrpcClient(
527
533
  {
528
- service: 'http://my-service.com',
534
+ service: "http://my-service.com",
529
535
  headers: {
530
- 'my-header': 'my-value',
536
+ "my-header": "my-value",
531
537
  },
532
538
  },
533
539
  [
534
540
  {
535
541
  lexicon: 1,
536
- id: 'io.example.doStuff',
542
+ id: "io.example.doStuff",
537
543
  defs: {},
538
544
  },
539
545
  ],
540
- )
546
+ );
541
547
  ```
542
548
 
543
549
  If you need the headers or service url to be dynamic, you can define them using
544
550
  functions:
545
551
 
546
552
  ```ts
547
- import { XrpcClient } from '@atproto/xrpc'
553
+ import { XrpcClient } from "@atproto/xrpc";
548
554
 
549
555
  const instance = new XrpcClient(
550
556
  {
551
- service: () => 'http://my-service.com',
557
+ service: () => "http://my-service.com",
552
558
  headers: {
553
- 'my-header': () => 'my-value',
554
- 'my-ignored-header': () => null, // ignored
559
+ "my-header": () => "my-value",
560
+ "my-ignored-header": () => null, // ignored
555
561
  },
556
562
  },
557
563
  [
558
564
  {
559
565
  lexicon: 1,
560
- id: 'io.example.doStuff',
566
+ id: "io.example.doStuff",
561
567
  defs: {},
562
568
  },
563
569
  ],
564
- )
570
+ );
565
571
  ```
566
572
 
567
573
  - [#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/index.d.ts CHANGED
@@ -15,7 +15,7 @@ export * from './moderation/types';
15
15
  export * from './mocker';
16
16
  export { LABELS, DEFAULT_LABEL_SETTINGS } from './moderation/const/labels';
17
17
  export { Agent } from './agent';
18
- export { AtpAgent } from './atp-agent';
18
+ export { AtpAgent, type AtpAgentOptions } from './atp-agent';
19
19
  export { BskyAgent } from './bsky-agent';
20
20
  /** @deprecated */
21
21
  export { AtpAgent as default } from './atp-agent';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAG3C,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AACvC,OAAO,EACL,OAAO,EACP,SAAS,EACT,YAAY,EACZ,SAAS,EACT,eAAe,GAChB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA;AACvB,cAAc,QAAQ,CAAA;AACtB,cAAc,UAAU,CAAA;AACxB,cAAc,uBAAuB,CAAA;AACrC,cAAc,0BAA0B,CAAA;AACxC,cAAc,qBAAqB,CAAA;AACnC,cAAc,kBAAkB,CAAA;AAChC,cAAc,cAAc,CAAA;AAC5B,cAAc,oBAAoB,CAAA;AAClC,cAAc,UAA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,CAAA;AAIjD,eAAO,MAAM,QAAQ,UAAiC,CAAA"}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,8CAA2C;AAC3C,gDAAgE;AAEhE,0CAAuC;AAA9B,+FAAA,KAAK,OAAA;AACd,4CAMyB;AALvB,kGAAA,OAAO,OAAA;AACP,oGAAA,SAAS,OAAA;AACT,uGAAA,YAAY,OAAA;AACZ,oGAAA,SAAS,OAAA;AACT,0GAAA,eAAe,OAAA;AAEjB,kDAAmD;AAA1C,2GAAA,aAAa,OAAA;AACtB,0CAAuB;AACvB,0CAAuB;AACvB,yCAAsB;AACtB,2CAAwB;AACxB,wDAAqC;AACrC,2DAAwC;AACxC,sDAAmC;AACnC,mDAAgC;AAChC,+CAA4B;AAC5B,qDAAkC;AAClC,2CAAwB;AACxB,oDAA0E;AAAjE,gGAAA,MAAM,OAAA;AAAE,gHAAA,sBAAsB,OAAA;AACvC,iCAA+B;AAAtB,8FAAA,KAAK,OAAA;AAEd,yCAAsC;AAA7B,qGAAA,QAAQ,OAAA;AACjB,2CAAwC;AAA/B,uGAAA,SAAS,OAAA;AAElB,kBAAkB;AAClB,yCAAiD;AAAxC,oGAAA,QAAQ,OAAW;AAE5B,+EAA+E;AAC/E,2BAA2B;AACd,QAAA,QAAQ,GAAG,IAAI,kBAAQ,CAAC,mBAAgB,CAAC,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,8CAA2C;AAC3C,gDAAgE;AAEhE,0CAAuC;AAA9B,+FAAA,KAAK,OAAA;AACd,4CAMyB;AALvB,kGAAA,OAAO,OAAA;AACP,oGAAA,SAAS,OAAA;AACT,uGAAA,YAAY,OAAA;AACZ,oGAAA,SAAS,OAAA;AACT,0GAAA,eAAe,OAAA;AAEjB,kDAAmD;AAA1C,2GAAA,aAAa,OAAA;AACtB,0CAAuB;AACvB,0CAAuB;AACvB,yCAAsB;AACtB,2CAAwB;AACxB,wDAAqC;AACrC,2DAAwC;AACxC,sDAAmC;AACnC,mDAAgC;AAChC,+CAA4B;AAC5B,qDAAkC;AAClC,2CAAwB;AACxB,oDAA0E;AAAjE,gGAAA,MAAM,OAAA;AAAE,gHAAA,sBAAsB,OAAA;AACvC,iCAA+B;AAAtB,8FAAA,KAAK,OAAA;AAEd,yCAA4D;AAAnD,qGAAA,QAAQ,OAAA;AACjB,2CAAwC;AAA/B,uGAAA,SAAS,OAAA;AAElB,kBAAkB;AAClB,yCAAiD;AAAxC,oGAAA,QAAQ,OAAW;AAE5B,+EAA+E;AAC/E,2BAA2B;AACd,QAAA,QAAQ,GAAG,IAAI,kBAAQ,CAAC,mBAAgB,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atproto/api",
3
- "version": "0.13.0",
3
+ "version": "0.13.1",
4
4
  "license": "MIT",
5
5
  "description": "Client library for atproto and Bluesky",
6
6
  "keywords": [
package/src/index.ts CHANGED
@@ -24,7 +24,7 @@ export * from './mocker'
24
24
  export { LABELS, DEFAULT_LABEL_SETTINGS } from './moderation/const/labels'
25
25
  export { Agent } from './agent'
26
26
 
27
- export { AtpAgent } from './atp-agent'
27
+ export { AtpAgent, type AtpAgentOptions } from './atp-agent'
28
28
  export { BskyAgent } from './bsky-agent'
29
29
 
30
30
  /** @deprecated */