@semiont/api-client 0.4.19 → 0.4.21

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/README.md CHANGED
@@ -17,7 +17,7 @@ The API is organized by the domain's verbs — the same verbs that organize the
17
17
  ```typescript
18
18
  import { SemiontApiClient } from '@semiont/api-client';
19
19
 
20
- const semiont = new SemiontApiClient({ baseUrl, eventBus, getToken });
20
+ const semiont = new SemiontApiClient({ baseUrl, eventBus, token$ });
21
21
 
22
22
  // Browse — reads from materialized views
23
23
  const resource = semiont.browse.resource(resourceId); // Observable
@@ -50,7 +50,7 @@ semiont.beckon.attention(annotationId, resourceId); // void (ephemeral
50
50
 
51
51
  ## Return Type Conventions
52
52
 
53
- - **Browse live queries** → `Observable` (events-stream driven, cached in BehaviorSubject)
53
+ - **Browse live queries** → `Observable` (bus-gateway driven, cached in BehaviorSubject)
54
54
  - **Browse one-shot reads** → `Promise` (fetch once, no cache)
55
55
  - **Commands** (mark, bind, yield.resource) → `Promise` (fire-and-forget)
56
56
  - **Long-running ops** (gather, match, yield.fromAnnotation, mark.assist) → `Observable` (progress + result)
@@ -58,22 +58,34 @@ semiont.beckon.attention(annotationId, resourceId); // void (ephemeral
58
58
 
59
59
  ## Auth is Internal
60
60
 
61
- The client takes a `getToken` function at construction. No per-call auth:
61
+ The client takes an observable `token$` at construction. All namespace
62
+ calls and the bus SSE connection read the current value. Update by
63
+ calling `.next(newToken)` on the BehaviorSubject — the client auto-starts
64
+ the bus actor the first time the token transitions from null to a real
65
+ value, and the actor reconnects with the new token after refresh.
62
66
 
63
67
  ```typescript
68
+ import { BehaviorSubject } from 'rxjs';
69
+
70
+ const token$ = new BehaviorSubject<AccessToken | null>(accessToken(token));
71
+
64
72
  const semiont = new SemiontApiClient({
65
73
  baseUrl: baseUrl('http://localhost:4000'),
66
74
  eventBus: new EventBus(),
67
- getToken: () => accessToken(token),
75
+ token$,
68
76
  });
69
77
 
70
78
  // No auth on individual calls
71
79
  const annotations = semiont.browse.annotations(resourceId);
72
80
  await semiont.mark.annotation(resourceId, input);
73
81
  await semiont.bind.body(resourceId, annotationId, operations);
82
+
83
+ // Token rotation — e.g. after refresh
84
+ token$.next(accessToken(newToken));
74
85
  ```
75
86
 
76
- Update the token getter at any time via `semiont.setTokenGetter(getter)`.
87
+ Omit `token$` entirely for unauthenticated usage (public endpoints only).
88
+ The bus actor will not connect until a non-null token is available.
77
89
 
78
90
  ## Installation
79
91
 
@@ -94,7 +106,7 @@ npm install @semiont/api-client
94
106
 
95
107
  - **Verb-oriented** — 7 domain namespaces mirror `@semiont/make-meaning`'s actor model
96
108
  - **Type-safe** — OpenAPI types from `@semiont/core`, branded identifiers
97
- - **Observable reads** — live-updating views via EventBus + events-stream SSE
109
+ - **Observable reads** — live-updating views via the bus gateway (single SSE connection)
98
110
  - **Framework-agnostic** — pure TypeScript + RxJS, no React dependency
99
111
 
100
112
  ## License