@atproto/lex 0.2.3 → 0.3.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.
Files changed (3) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +62 -58
  3. package/package.json +4 -4
package/CHANGELOG.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # @atproto/lex
2
2
 
3
+ ## 0.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies []:
8
+ - @atproto/lex-installer@0.1.10
9
+
10
+ ## 0.3.0
11
+
12
+ ### Minor Changes
13
+
14
+ - [#5185](https://github.com/bluesky-social/atproto/pull/5185) [`f8267c3`](https://github.com/bluesky-social/atproto/commit/f8267c3ada1645a2472c81c1ba95157466108b6e) Thanks [@matthieusieben](https://github.com/matthieusieben)! - **Breaking:** Rework the `Client` class and its `service` / `labelers` options to give callers full control over the `atproto-proxy` and `atproto-accept-labelers` request headers.
15
+
16
+ A single `Client` can now be configured to talk to a proxied service (e.g. an AppView) by default, while still being able to reach other services — including the user's PDS directly — on a per-request basis. This is the foundation for SDK-style `Action`s that compose AppView and PDS calls through a single client instance.
17
+
18
+ - The `service` and `labelers` options set on a `Client` now act as _defaults_ for that client's requests. Per-request options merge with those defaults using conventional option-merging semantics: `undefined` (or omitted) inherits the client's default, while a defined value replaces it (**breaking:** previously, per-request `labelers` were appended to the client's, and a per-request `service` could not unset the client's).
19
+ - `service: null` and `labelers: null` can now be passed on a per-request basis to opt out of the client's defaults, sending the request without the `atproto-proxy` or `atproto-accept-labelers` header.
20
+ - **Breaking:** The record helper methods (`create()`, `get()`, `put()`, `delete()`, `list()`, `listAll()`, `createRecord()`, `getRecord()`, `putRecord()`, `deleteRecord()`, `listRecords()`, `applyWrites()`, `uploadBlob()`, `getBlob()`) now always target the user's PDS: they default to `service: null` and `labelers: null`, ignoring the client's instance-wide defaults (unless explicitly overridden through their options).
21
+ - **Breaking:** `Client` no longer implements the `Agent` interface (its `fetchHandler` method was removed), meaning that a `Client` can no longer be used as the agent of another `Client`. To share authentication between differently-configured clients, build them from the same session, or reuse an existing client's `agent` (`new Client(otherClient.agent, { ... })`).
22
+ - Static app labelers (`Client.appLabelers`, configured via `Client.configure()`) are still always applied — with the `;redact` param — and can now be overridden per client instance or per request through the new `appLabelers` option (`appLabelers: null` disables them).
23
+ - An `atproto-proxy` header provided through the `Client` constructor's `headers` option is now used as a fallback for the `service` option, making the two equivalent at the client level. A per-request `service` value (including `null`) always takes precedence. Per-request `atproto-proxy` headers are ignored by `Client` methods (use the `service` option instead), while `atproto-accept-labelers` headers are merged with the labelers from the `labelers` and `appLabelers` options (unless `labelers: null` is used).
24
+
25
+ ### Patch Changes
26
+
27
+ - Updated dependencies [[`f8267c3`](https://github.com/bluesky-social/atproto/commit/f8267c3ada1645a2472c81c1ba95157466108b6e)]:
28
+ - @atproto/lex-client@0.3.0
29
+ - @atproto/lex-installer@0.1.9
30
+
3
31
  ## 0.2.3
4
32
 
5
33
  ### Patch Changes
package/README.md CHANGED
@@ -110,7 +110,7 @@ const posts = await client.list(app.bsky.feed.post, { limit: 10 })
110
110
  - [Using Actions](#using-actions)
111
111
  - [Composing Multiple Operations](#composing-multiple-operations)
112
112
  - [Higher-Order Actions](#higher-order-actions)
113
- - [Creating a Client from Another Client](#creating-a-client-from-another-client)
113
+ - [Using a Single Client for Multiple Services](#using-a-single-client-for-multiple-services)
114
114
  - [Building Library-Style APIs with Actions](#building-library-style-apis-with-actions)
115
115
  - [Creating Posts](#creating-posts)
116
116
  - [Following Users](#following-users)
@@ -174,7 +174,7 @@ This generates TypeScript files in `./src/lexicons` (by default) with type-safe
174
174
  > To avoid committing generated files, add the output directory to your `.gitignore`:
175
175
  >
176
176
  > ```bash
177
- > echo "./src/lexicons" >> .gitignore
177
+ > echo "/src/lexicons" >> .gitignore
178
178
  > ```
179
179
 
180
180
  **4. Use in your code**
@@ -610,7 +610,7 @@ Both `xrpc()` and `xrpcSafe()` accept `validateRequest`, `validateResponse`, and
610
610
 
611
611
  The `Client` class provides high-level helpers for common AT Protocol "repo" operations: `create()`, `get()`, `put()`, `delete()`, `list()`, `uploadBlob()`, and more. A `Client` instance is typically useful for making requests in the context of an authenticated user session, as it automatically handles headers and provides default values based on the authenticated user's DID.
612
612
 
613
- A `Client` instance is also useful to encapsulate configuration for a specific service, by specifying the `service` option (for proxying) and `labelers` option (for content labeling). Additionally, a `Client` can be used as an `Agent` for another `Client`, allowing you to compose headers and configuration across multiple services.
613
+ A `Client` instance is also useful to encapsulate configuration for a specific service, by specifying the `service` option (for proxying) and `labelers` option (for content labeling). These act as _defaults_ for the client's requests and can be overridden — or disabled with `null` — on a per-request basis, allowing a single client to talk both to a proxied service (e.g. an AppView) and directly to the user's PDS.
614
614
 
615
615
  ### Creating a Client
616
616
 
@@ -1020,6 +1020,30 @@ client.setLabelers(['did:plc:labeler5'])
1020
1020
  client.clearLabelers()
1021
1021
  ```
1022
1022
 
1023
+ The client's `labelers` act as a default for its requests. A per-request `labelers` option replaces that default for that request, and `labelers: null` disables the `atproto-accept-labelers` header entirely:
1024
+
1025
+ ```typescript
1026
+ // Uses the client's labelers
1027
+ await client.call(app.bsky.actor.getProfile, { actor })
1028
+
1029
+ // Uses only 'did:plc:other' for this request
1030
+ await client.xrpc(app.bsky.actor.getProfile, {
1031
+ params: { actor },
1032
+ labelers: ['did:plc:other'],
1033
+ })
1034
+
1035
+ // No atproto-accept-labelers header for this request (except appLabelers,
1036
+ // which are applied unless explicitly disabled)
1037
+ await client.xrpc(app.bsky.actor.getProfile, {
1038
+ params: { actor },
1039
+ labelers: null,
1040
+ })
1041
+ ```
1042
+
1043
+ App-level labelers (`appLabelers`) are always added to the `atproto-accept-labelers` header with the `;redact` param. They default to the static `Client.appLabelers` (set via `Client.configure()`), and can be overridden through the client's or a request's `appLabelers` option (`appLabelers: null` disables them for that client or request).
1044
+
1045
+ The same defaulting logic applies to the `service` option (`atproto-proxy` header): a per-request `service` replaces the client's default, and `service: null` disables proxying for that request.
1046
+
1023
1047
  ### Low-Level XRPC
1024
1048
 
1025
1049
  For advanced use cases, use `client.xrpc()` to get the full response (headers, status, body):
@@ -1512,77 +1536,57 @@ const enableAdultContent: Action<void, Preference[]> = async (
1512
1536
  await client.call(enableAdultContent)
1513
1537
  ```
1514
1538
 
1515
- ### Creating a Client from Another Client
1516
-
1517
- You can create a new `Client` instance from an existing client. The new client will share the same underlying configuration (authentication, headers, labelers, service proxy), with the ability to override specific settings.
1539
+ ### Using a Single Client for Multiple Services
1518
1540
 
1519
- > [!NOTE]
1520
- >
1521
- > When you create a client from another client, the child client inherits the base client's configuration. On every request, the child client merges its own configuration with the base client's current configuration, with the child's settings taking precedence. Changes to the base client's configuration (like `baseClient.setLabelers()`) will be reflected in child client requests, but changes to child clients do not affect the base client.
1541
+ Because the client's `service` and `labelers` options are just _defaults_, a single `Client` instance can be used to talk to multiple services. This is the recommended pattern for SDK-style code: configure the client to talk to an AppView by default, and override `service` on a per-request basis when a request must reach another service — or the user's PDS directly (`service: null`).
1522
1542
 
1523
1543
  ```typescript
1524
1544
  import { Client } from '@atproto/lex'
1545
+ import * as app from './lexicons/app.js'
1546
+ import * as com from './lexicons/com.js'
1525
1547
 
1526
- // Base client with authentication
1527
- const baseClient = new Client(session)
1548
+ const client = new Client(session, {
1549
+ // All requests are proxied to the AppView by default
1550
+ service: 'did:web:api.bsky.app#bsky_appview',
1551
+ })
1528
1552
 
1529
- baseClient.setLabelers(['did:plc:labelerA', 'did:plc:labelerB'])
1530
- baseClient.headers.set('x-app-version', '1.0.0')
1553
+ // Proxied to the AppView (client default)
1554
+ const { feed } = await client.call(app.bsky.feed.getTimeline)
1531
1555
 
1532
- // Create a new client with additional configuration that will get merged with
1533
- // baseClient's settings on every request.
1534
- const configuredClient = new Client(baseClient, {
1535
- labelers: ['did:plc:labelerC'],
1536
- headers: { 'x-trace-id': 'abc123' },
1556
+ // Sent directly to the user's PDS (no atproto-proxy header)
1557
+ const { body } = await client.xrpc(com.atproto.repo.getRecord, {
1558
+ service: null,
1559
+ params: {
1560
+ repo: client.assertDid,
1561
+ collection: 'app.bsky.actor.profile',
1562
+ rkey: 'self',
1563
+ },
1537
1564
  })
1538
- ```
1539
1565
 
1540
- This pattern is particularly useful when you need to:
1566
+ // Proxied to a different service, just for this request
1567
+ await client.xrpc(app.bsky.actor.getProfile, {
1568
+ service: 'did:web:com.example.other#other_service',
1569
+ params: { actor: client.assertDid },
1570
+ })
1571
+ ```
1541
1572
 
1542
- - Configure labelers after authentication
1543
- - Add application-specific headers
1544
- - Create multiple clients with different configurations from the same session
1573
+ > [!NOTE]
1574
+ >
1575
+ > The record helpers (`create()`, `get()`, `put()`, `delete()`, `list()`, `createRecord()`, `getRecord()`, `putRecord()`, `deleteRecord()`, `listRecords()`, `applyWrites()`, `uploadBlob()`, `getBlob()`) always target the user's PDS: they default to `service: null` and `labelers: null`, ignoring the client's instance-wide defaults (unless explicitly overridden in their options).
1545
1576
 
1546
- **Example: Configuring labelers after sign-in**
1577
+ If you need clients with different configurations sharing the same authentication, create them from the same session (or reuse an existing client's `agent`):
1547
1578
 
1548
1579
  ```typescript
1549
- import { Client } from '@atproto/lex'
1550
- import * as app from './lexicons/app.js'
1551
-
1552
- async function createBaseClient(session: OAuthSession) {
1553
- // Create base client
1554
- const client = new Client(session, {
1555
- service: 'did:web:api.bsky.app#bsky_appview',
1556
- })
1557
-
1558
- // Fetch user preferences
1559
- const { preferences } = await client.call(app.bsky.actor.getPreferences)
1560
-
1561
- // Extract labeler preferences
1562
- const labelerPref = preferences.findLast((p) =>
1563
- app.bsky.actor.defs.labelersPref.check(p),
1564
- )
1565
- const labelers = labelerPref?.labelers.map((l) => l.did) ?? []
1566
-
1567
- // Configure the client with the user's preferred labelers
1568
- client.setLabelers(labelers)
1569
-
1570
- return client
1571
- }
1572
-
1573
- // Usage
1574
- const baseClient = await createBaseClient(session)
1575
-
1576
- // Create a new client with a different service, but reusing the labelers
1577
- // from the base client.
1578
- const otherClient = new Client(baseClient, {
1579
- service: 'did:web:com.example.other#other_service',
1580
+ const pdsClient = new Client(session)
1581
+ const bskyClient = new Client(pdsClient.agent, {
1582
+ service: 'did:web:api.bsky.app#bsky_appview',
1580
1583
  })
1581
-
1582
- // Whenever you update labelers on the base client, the other client will automatically
1583
- // receive the same updates, since they share the same labeler set.
1584
1584
  ```
1585
1585
 
1586
+ > [!NOTE]
1587
+ >
1588
+ > In previous version of this library, `Client` implemented the `Agent` interface, and its `fetchHandler` method could be used as the agent of another `Client`. This lead to confusing bugs ([#5110](https://github.com/bluesky-social/atproto/issues/5110)) where the inner agent (client) would set `atproto-proxy` and `atproto-accept-labelers` headers on requests where the outer client explicitly set `service: null` and `labelers: null`. This is no longer the case: a `Client` can no longer be used as the agent of another `Client`. To share authentication between differently-configured clients, build them from the same session.
1589
+
1586
1590
  ### Building Library-Style APIs with Actions
1587
1591
 
1588
1592
  Actions enable you to create high-level, convenience APIs similar to [@atproto/api](https://www.npmjs.com/package/@atproto/api)'s `Agent` class. Here are patterns for common operations:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atproto/lex",
3
- "version": "0.2.3",
3
+ "version": "0.3.1",
4
4
  "license": "MIT",
5
5
  "description": "Lexicon tooling for AT",
6
6
  "keywords": [
@@ -38,11 +38,11 @@
38
38
  "dependencies": {
39
39
  "tslib": "^2.8.1",
40
40
  "yargs": "^18.0.0",
41
+ "@atproto/lex-client": "^0.3.0",
41
42
  "@atproto/lex-builder": "^0.1.8",
42
- "@atproto/lex-client": "^0.2.4",
43
- "@atproto/lex-data": "^0.1.5",
44
43
  "@atproto/lex-json": "^0.1.4",
45
- "@atproto/lex-installer": "^0.1.8",
44
+ "@atproto/lex-data": "^0.1.5",
45
+ "@atproto/lex-installer": "^0.1.10",
46
46
  "@atproto/lex-schema": "^0.2.2"
47
47
  },
48
48
  "devDependencies": {