@bowmark/web 1.24.2 → 1.25.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/README.md CHANGED
@@ -14,18 +14,6 @@
14
14
  lmstudio://add_mcp?name=bowmark&config=eyJ1cmwiOiJodHRwczovL2FwaS5ib3dtYXJrLmFpL21jcC9iYWRnZS1sbXN0dWRpbyJ9
15
15
  ```
16
16
 
17
- > **Status:** PUBLISHED · `@bowmark/web@1.0.0` on npm, 2026-08-06, alongside
18
- > `bowmark-web` and `bowmark-web-stubs` on PyPI at the same version. The plan that built it
19
- > is deleted; the reasoning is in the four
20
- > [`docs/decisions/2026-08-06-*`](../../../docs/decisions/) records and the enforceable half
21
- > is [`.claude/rules/public-types.md`](../../../.claude/rules/public-types.md). Since
22
- > 2026-09-01 the TARBALL ships compiled `dist/`, not raw `src/` — see
23
- > [`docs/decisions/2026-09-01-the-published-npm-client-ships-compiled-js.md`](../../../docs/decisions/2026-09-01-the-published-npm-client-ships-compiled-js.md).
24
- > **What would make THIS doc wrong:** the declarations moving out into a second package,
25
- > a runtime dependency landing in `package.json`, or a build step reappearing where a
26
- > CONSUMER or this MONOREPO has to run it — the one that ships is at publish time only,
27
- > in the public mirror's own CI, and neither of those two ever sees it.
28
-
29
17
  ```sh
30
18
  npm i @bowmark/web
31
19
  ```
@@ -119,6 +107,64 @@ literal gets no typechecking, so the generated types cover `session()` and `bowm
119
107
  and never this. It returns the envelope rather than throwing, because a script is
120
108
  composite: `status`, `logs` and `result` are read together.
121
109
 
110
+ **`run()` is designed for agents, not for you.** If you're writing code in your editor,
111
+ use `session()` instead. For **reading a page** — fetching and parsing HTML — use the
112
+ `read.page()` capability from within a `session()` callback:
113
+
114
+ ```ts
115
+ import { session } from "@bowmark/web";
116
+
117
+ const parsed = await session(async (bm) => {
118
+ return await bm.read.page(url); // fetches and parses the page
119
+ }, { apiKey: "bmk_…" });
120
+ ```
121
+
122
+ ### Signing in — `login()`, `{ connection }`, and `bm.connections.*`
123
+
124
+ ```ts
125
+ import { session } from "@bowmark/web";
126
+
127
+ await session(async (bm) => {
128
+ const a = await bm.providers.reddit.login({ username: "u1", password: "p1" });
129
+ const b = await bm.providers.reddit.login({ username: "u2", password: "p2" });
130
+
131
+ await bm.providers.reddit.vote({ id: "t3_x", direction: "up" }, { connection: a.connection });
132
+ await bm.providers.reddit.vote({ id: "t3_y", direction: "up" }, { connection: b.connection });
133
+
134
+ await bm.connections.update(a.connection, { keepAlive: { everyHours: 6 } });
135
+ await bm.connections.logout(a.connection); // ends the site session, keeps the entry
136
+ await bm.connections.delete(b.connection); // forgets the entry, site session untouched
137
+ });
138
+ ```
139
+
140
+ **`login()` exists on any provider with login adapters, and every login is a NEW,
141
+ separate connection** — calling it twice never replaces the first. Pass `connection: id`
142
+ in its argument to sign back in to an existing one instead (its id and settings are kept; a
143
+ `logged_out` one is revived). The returned `connection` works on the very next call, and
144
+ `warnings` names your other connections to that site. Its `username` /
145
+ `password` / `totpCode` / `totpSeed` are plain strings, unlike the `bowmark.secret()`
146
+ references a `run()` script must use: this client's transport lifts each one into a
147
+ per-request `x-bowmark-credential-<name>` header before the call leaves your process,
148
+ so the value never rides in the request body a run row, a log or a trace could carry.
149
+ `keepAlive`/`expiresAt` are ordinary values and travel in the body unchanged — absent
150
+ means a 12-hour keep-alive.
151
+
152
+ **Every signed-in function accepts a trailing `{ connection }`.** Omit it and the call
153
+ uses the provider's default connection; several live and none marked default throws a
154
+ caller-fixable `ConnectionAmbiguous` error listing them. `login()`'s own return value
155
+ is `{ connection, account, expiresAt }` — pass `connection` straight into a later call.
156
+
157
+ **`bm.connections.list/logout/delete/update`** are REST over `/v1/connections`, not part
158
+ of the generic capability dispatch. `logout` drops Bowmark's cookies, ends the session on
159
+ the site where the provider can (`siteSignedOut: true` is checked, not assumed;
160
+ `siteLogout: "unsupported"` says the site offers no way), and KEEPS the entry as
161
+ `logged_out` so `login({ connection: id })` can revive it. `delete` forgets Bowmark's own
162
+ row and cookies; it does **not** sign the account out on the site.
163
+
164
+ **Python note:** `bowmark_web-stubs` types `login()` and `{ connection }` for parity,
165
+ but the Python **runtime** does not yet lift credentials into a header the way this
166
+ client does — see `packages/bowmark-web/python/README.md` if you hit this from Python.
167
+
122
168
  ### What it throws
123
169
 
124
170
  | Class | When | What to do |
@@ -139,7 +185,20 @@ takes them — or set `BOWMARK_API_KEY` and `BOWMARK_API_URL`, read at CALL time
139
185
  is required**: without one the first call throws `code: "no_api_key"` and sends nothing.
140
186
  A caller header cannot displace the key.
141
187
 
142
- ## The two halves, and why they are split
188
+ ---
189
+
190
+ ## For maintainers of this package
191
+
192
+ Everything below describes how `@bowmark/web` is built, generated and published. Skip
193
+ this section unless you are changing how the SDK itself works.
194
+
195
+ ## Internals — how this package is built, generated and published
196
+
197
+ Everything above is what you need to call the library. Everything below is for someone
198
+ working on this package itself — the generator, the guards, the publish pipeline. Skip
199
+ it unless you're changing how the SDK is built.
200
+
201
+ ### The two halves, and why they are split
143
202
 
144
203
  - **`src/{index,session,transport,guard,validate}.ts`** — hand-written, ~700 lines,
145
204
  changes almost never.
@@ -174,7 +233,7 @@ argument the wire cannot carry.
174
233
  that, `await bowmark.music` would find a callable `then`, invoke it as a thenable, and
175
234
  hang forever waiting for a resolve a path segment can never call.
176
235
 
177
- ## The wire guard is a checked COPY
236
+ ### The wire guard is a checked COPY
178
237
 
179
238
  `src/guard.ts` duplicates `wireProblem` from `packages/schema/src/wire.ts`, because
180
239
  importing the workspace package would break the tarball for everyone outside this repo.
@@ -188,7 +247,7 @@ things (a circular structure and a `BigInt`) and silently mangles everything els
188
247
  → dropped. Temporal shipped that exact bug, diagnosed it as a typing problem, and closed
189
248
  it won't-fix.
190
249
 
191
- ## The argument guard is TWO guards, in this order
250
+ ### The argument guard is TWO guards, in this order
192
251
 
193
252
  `assertWireSafeArgs` asks whether the value can cross at all — a `Date`, a `Map`, a
194
253
  function, a circular structure. `assertArgShape` asks whether it matches what the
@@ -244,7 +303,7 @@ refuses one, with no exception set — an exception would be a declaration that
244
303
  parameter is uncallable. Found once, on `pizzahut.priceOrder`, by generating validators
245
304
  for all 253 typed parameters.
246
305
 
247
- ## What ships is compiled, not `src/` verbatim
306
+ ### What ships is compiled, not `src/` verbatim
248
307
 
249
308
  `main`/`types` point at `dist/index.{js,d.ts}`. `dist/` is never committed — it does not
250
309
  exist in this workspace and does not exist in the public mirror's git history either — it
@@ -262,7 +321,8 @@ Why compiled at all: Node refuses to strip types out of a `.ts` file found insid
262
321
  `node_modules`, so shipping `main: src/index.ts` made plain `node app.mjs` fail with
263
322
  `ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING` for every consumer who was not already on
264
323
  `tsx`, Bun, or a bundler.
265
- [`docs/decisions/2026-09-01-the-published-npm-client-ships-compiled-js.md`](../../../docs/decisions/2026-09-01-the-published-npm-client-ships-compiled-js.md).
324
+ `docs/decisions/2026-09-01-the-published-npm-client-ships-compiled-js.md` in Bowmark's
325
+ internal engineering repo (not public).
266
326
 
267
327
  **One thing `tsc`'s declaration emit does not do on its own, and `build.mjs` does by
268
328
  hand:** `src/generated/library.d.ts` is ambient (no imports, no exports — see below) and
@@ -273,7 +333,7 @@ all and `BowmarkLibrary` — the type this package exists to ship — reads as `
273
333
  name`. `build.mjs` re-inserts the reference line and copies `library.d.ts` into
274
334
  `dist/generated/` verbatim (it has nothing to compile).
275
335
 
276
- ## Regenerating
336
+ ### Regenerating
277
337
 
278
338
  ```bash
279
339
  pnpm run gen:public-types # writes src/generated/{library.d.ts,validators.ts}
@@ -297,7 +357,7 @@ TypeScript with no build step, so a generate-at-build artifact leaves `tsc` and
297
357
  with nothing to read on a fresh clone. Committed plus a staleness gate is the only shape
298
358
  that works. Never hand-edit it.
299
359
 
300
- ## Four things the generator does that look like bugs and are not
360
+ ### Four things the generator does that look like bugs and are not
301
361
 
302
362
  **One namespace per unit.** `music` and `flights` both declare `CallOptions`; `Track` and
303
363
  `Store` are names any provider may take. Each unit's `types` block is emitted VERBATIM
@@ -334,7 +394,7 @@ declare is refused, so their interface is empty. The generated file says so in w
334
394
  because an empty interface reads as "this unit does nothing", which is a different and
335
395
  wronger claim than "we can make no typed claim about anything it does".
336
396
 
337
- ## Scale
397
+ ### Scale
338
398
 
339
399
  Measured 2026-08-05 on synthetic units, one namespace each:
340
400