@bowmark/web 1.24.2 → 1.25.0

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/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  /// <reference path="./generated/library.d.ts" />
2
2
  import { type ClientOptions, type RunEnvelope } from "./transport.js";
3
3
  export { type WireProblem, wireProblem } from "./guard.js";
4
- export { client, openManagedSession, type SessionHandle, session } from "./session.js";
5
- export { type AuthNeed, BowmarkError, BowmarkNeedsUserError, type CallEnvelope, type ClientOptions, type ClosedSession, type FetchLike, type Handoff, type OpenedSession, type RunEnvelope, } from "./transport.js";
4
+ export { client, type ConnectionsApi, openManagedSession, type SessionHandle, session, } from "./session.js";
5
+ export { type AuthNeed, BowmarkError, BowmarkNeedsUserError, type CallEnvelope, type ClientOptions, type ClosedSession, type ConnectionSummary, type FetchLike, type Handoff, type OpenedSession, type RunEnvelope, } from "./transport.js";
6
6
  /** The whole callable library, typed. `await bowmark.music.search("aphex twin")`.
7
7
  *
8
8
  * Each call opens its own one-shot session, which is right for ONE call and wrong
package/dist/index.js CHANGED
@@ -17,7 +17,7 @@
17
17
  import { client } from "./session.js";
18
18
  import { postRun, resolveClient } from "./transport.js";
19
19
  export { wireProblem } from "./guard.js";
20
- export { client, openManagedSession, session } from "./session.js";
20
+ export { client, openManagedSession, session, } from "./session.js";
21
21
  export { BowmarkError, BowmarkNeedsUserError, } from "./transport.js";
22
22
  /** The whole callable library, typed. `await bowmark.music.search("aphex twin")`.
23
23
  *
package/dist/session.d.ts CHANGED
@@ -1,4 +1,38 @@
1
- import { type ClientOptions, type ClosedSession } from "./transport.js";
1
+ import { type ClientOptions, type ClosedSession, type ConnectionLogout, type ConnectionSummary } from "./transport.js";
2
+ /** Build the `bowmark`-shaped Proxy over a dispatcher.
3
+ *
4
+ * **The Proxy accepts every name at runtime** — `bowmark.anything.at.all()` builds a
5
+ * path and sends it. That is not a bug, it is why the generated types are
6
+ * load-bearing rather than decorative: the Proxy makes a correct call work without
7
+ * enumerating half a million names, and TypeScript makes a wrong one a compile
8
+ * error. Neither half is sufficient alone, and it is the same split
9
+ * `packages/runtime/src/namespace.ts` already ships inside the sandbox. */
10
+ /** `bm.connections.*`'s shape. Hand-written rather than read off the ambient
11
+ * `BowmarkConnections` ` .d.ts` declares (`scripts/gen-public-types.ts`'s
12
+ * `AMBIENT_DECLARATIONS`) — `libraryProxy`'s return is asserted `as BowmarkLibrary`
13
+ * as a whole, so nothing here is structurally checked against that ambient type at
14
+ * runtime, and this file's own contract is what actually has to type-check. Keep
15
+ * the two in step by hand, the same way `CallEnvelope` already tracks the api's
16
+ * `SessionEnvelope`. */
17
+ export interface ConnectionsApi {
18
+ list(filter?: {
19
+ provider?: string;
20
+ }): Promise<ConnectionSummary[]>;
21
+ delete(id: string): Promise<{
22
+ revoked: string;
23
+ provider: string;
24
+ scope: string;
25
+ }>;
26
+ logout(id: string): Promise<ConnectionLogout>;
27
+ update(id: string, patch: {
28
+ keepAlive?: {
29
+ everyHours: number;
30
+ } | false;
31
+ expiresAt?: string | null;
32
+ }): Promise<{
33
+ updated: true;
34
+ }>;
35
+ }
2
36
  /** Everything a session block hands its callback. */
3
37
  export interface SessionHandle {
4
38
  /** The server-side id. Present so a caller can quote it in a bug report or find
package/dist/session.js CHANGED
@@ -12,7 +12,62 @@
12
12
  // else's toolchain. Playwright was asked to fix that class of bug and formally
13
13
  // declined. See `docs/decisions/2026-08-03-the-session-surface-and-why-run-string-stays.md`.
14
14
  import { assertArgShape, assertWireSafeArgs } from "./guard.js";
15
- import { BowmarkError, callInSession, closeSession, openSession, resolveClient, } from "./transport.js";
15
+ import { BowmarkError, callInSession, closeSession, deleteConnection, listConnections, logoutConnection, openSession, resolveClient, updateConnection, } from "./transport.js";
16
+ // ── `login()`'s password channel ─────────────────────────────────────────────
17
+ //
18
+ // `bowmark.providers.<id>.login({ username, password, … })` declares its argument
19
+ // as `LoginInput` — plain strings, because that is what a caller of a TYPED client
20
+ // actually holds. The server's dispatch chokepoint (`packages/runtime/src/
21
+ // login-dispatch.ts`'s `resolveLoginCreds`) instead REQUIRES each credential field
22
+ // to be a `SecretRef` — the same fence a script's `bowmark.secret()` produces — so
23
+ // a literal string in the request body is refused outright rather than silently
24
+ // accepted. This is the client-side half of that contract: lift each credential
25
+ // field into a per-request `x-bowmark-credential-<name>` header, and replace it in
26
+ // the outgoing body with the identical `SecretRef` placeholder shape, so the
27
+ // plaintext never rides in the JSON a run row, a log or a trace could carry.
28
+ const CREDENTIAL_HEADER_PREFIX = "x-bowmark-credential-";
29
+ /** The `LoginInput` fields that are credentials, and the secret-name suffix each
30
+ * is stored under — the SAME convention `loginSecretName` (`@bowmark/schema`)
31
+ * uses server-side (`<provider>_<field>`), restated here for the same
32
+ * zero-runtime-dependency reason `guard.ts` copies `wire.ts`. */
33
+ const CREDENTIAL_FIELD_SUFFIX = {
34
+ username: "username",
35
+ password: "password",
36
+ totpCode: "totp_code",
37
+ totpSeed: "totp_seed",
38
+ };
39
+ /** `bowmark.providers.<id>.login(creds)` — the one call this client rewrites
40
+ * before it reaches the wire. */
41
+ function isLoginCall(path) {
42
+ return path.length === 3 && path[0] === "providers" && path[2] === "login";
43
+ }
44
+ /** The exact shape `bowmark.secret(name)` produces server-side (`SecretRef`,
45
+ * `@bowmark/schema`) — reconstructed here rather than imported, for the same
46
+ * reason every other wire shape in this package is a checked copy. */
47
+ function secretRefPlaceholder(name) {
48
+ return { __secretRef: true, name };
49
+ }
50
+ /** Lift `login()`'s plaintext credential fields into per-request headers, and
51
+ * replace them in the outgoing body with `SecretRef` placeholders. `keepAlive`
52
+ * and `expiresAt` are plain values on both sides and are left untouched. */
53
+ function liftLoginCredentials(providerId, args) {
54
+ const creds = args[0];
55
+ if (creds === null || typeof creds !== "object" || Array.isArray(creds)) {
56
+ return { args: [...args], headers: {} };
57
+ }
58
+ const input = creds;
59
+ const rewritten = { ...input };
60
+ const headers = {};
61
+ for (const field of Object.keys(CREDENTIAL_FIELD_SUFFIX)) {
62
+ const value = input[field];
63
+ if (typeof value !== "string")
64
+ continue;
65
+ const name = `${providerId}_${CREDENTIAL_FIELD_SUFFIX[field]}`;
66
+ headers[`${CREDENTIAL_HEADER_PREFIX}${name}`] = value;
67
+ rewritten[field] = secretRefPlaceholder(name);
68
+ }
69
+ return { args: [rewritten, ...args.slice(1)], headers };
70
+ }
16
71
  /** Property names a proxy must NOT answer with another node.
17
72
  *
18
73
  * `then` is the load-bearing one: `await bowmark.music` would otherwise find a
@@ -20,15 +75,7 @@ import { BowmarkError, callInSession, closeSession, openSession, resolveClient,
20
75
  * never a call. The other two round out the Promise protocol, and `toJSON` stops a
21
76
  * node being silently serialized into somebody's log. */
22
77
  const NOT_A_PATH_SEGMENT = new Set(["then", "catch", "finally", "toJSON"]);
23
- /** Build the `bowmark`-shaped Proxy over a dispatcher.
24
- *
25
- * **The Proxy accepts every name at runtime** — `bowmark.anything.at.all()` builds a
26
- * path and sends it. That is not a bug, it is why the generated types are
27
- * load-bearing rather than decorative: the Proxy makes a correct call work without
28
- * enumerating half a million names, and TypeScript makes a wrong one a compile
29
- * error. Neither half is sufficient alone, and it is the same split
30
- * `packages/runtime/src/namespace.ts` already ships inside the sandbox. */
31
- function libraryProxy(dispatch) {
78
+ function libraryProxy(dispatch, connections) {
32
79
  const node = (path) => {
33
80
  // The target is a FUNCTION so the proxy is callable at any depth. A plain
34
81
  // object target makes `apply` an illegal trap and every call a TypeError.
@@ -39,6 +86,13 @@ function libraryProxy(dispatch) {
39
86
  return undefined;
40
87
  if (NOT_A_PATH_SEGMENT.has(property))
41
88
  return undefined;
89
+ // `bm.connections.*` bypasses the generic dispatch entirely — REST over
90
+ // `/v1/connections`, never `/v1/session/:id/call`. Special-cased at the
91
+ // ROOT only: `connections` is not a real unit namespace, so nothing here
92
+ // would otherwise stop a caller building `bowmark.connections.anything`
93
+ // and sending it as an ordinary (and meaningless) capability call.
94
+ if (path.length === 0 && property === "connections")
95
+ return connections;
42
96
  return node([...path, property]);
43
97
  },
44
98
  apply(_target, _thisArg, args) {
@@ -48,6 +102,15 @@ function libraryProxy(dispatch) {
48
102
  };
49
103
  return node([]);
50
104
  }
105
+ /** `bm.connections.list/delete/logout/update`, bound to one resolved client. */
106
+ function connectionsApi(client) {
107
+ return {
108
+ list: (filter) => listConnections(client, filter),
109
+ delete: (id) => deleteConnection(client, id),
110
+ logout: (id) => logoutConnection(client, id),
111
+ update: (id, patch) => updateConnection(client, id, patch),
112
+ };
113
+ }
51
114
  /** `get_library` is real, and it is not here.
52
115
  *
53
116
  * It is an MCP tool and `GET /v1/library?query=`, never an export of this
@@ -92,8 +155,18 @@ function dispatchThrough(send) {
92
155
  // message is about JSON. `assertArgShape` answers "does it match what this
93
156
  // function declares". Shape-first would report a `Date` as "expected a string"
94
157
  // and point the caller at the wrong bug.
158
+ //
159
+ // Both run against the CALLER's original args — `LoginInput`'s declared shape
160
+ // is plain strings, and that is the promise being checked here. The rewrite
161
+ // into `SecretRef` placeholders happens AFTER, and only for the one call it
162
+ // applies to, so a caller's mistake is still reported against what they wrote.
95
163
  assertWireSafeArgs(label, args);
96
164
  assertArgShape(label, path, args);
165
+ if (isLoginCall(path)) {
166
+ const providerId = path[1];
167
+ const { args: wireArgs, headers } = liftLoginCredentials(providerId, args);
168
+ return send(path, wireArgs, headers);
169
+ }
97
170
  return send(path, args);
98
171
  };
99
172
  }
@@ -117,7 +190,7 @@ function dispatchThrough(send) {
117
190
  export async function session(callback, opts = {}) {
118
191
  const client = resolveClient(opts);
119
192
  const opened = await openSession(client);
120
- const proxy = libraryProxy(dispatchThrough((path, args) => callInSession(client, opened.sessionId, path, args)));
193
+ const proxy = libraryProxy(dispatchThrough((path, args, extraHeaders) => callInSession(client, opened.sessionId, path, args, extraHeaders)), connectionsApi(client));
121
194
  try {
122
195
  return await callback(proxy, { sessionId: opened.sessionId, expiresAt: opened.expiresAt });
123
196
  }
@@ -140,7 +213,7 @@ export async function openManagedSession(opts = {}) {
140
213
  const client = resolveClient(opts);
141
214
  const opened = await openSession(client);
142
215
  return {
143
- bowmark: libraryProxy(dispatchThrough((path, args) => callInSession(client, opened.sessionId, path, args))),
216
+ bowmark: libraryProxy(dispatchThrough((path, args, extraHeaders) => callInSession(client, opened.sessionId, path, args, extraHeaders)), connectionsApi(client)),
144
217
  sessionId: opened.sessionId,
145
218
  expiresAt: opened.expiresAt,
146
219
  close: () => closeSession(client, opened.sessionId),
@@ -154,7 +227,7 @@ export async function openManagedSession(opts = {}) {
154
227
  * echoed back, then reports `item_count: 0`). Use `session()` for anything
155
228
  * multi-step. */
156
229
  export function client(opts = {}) {
157
- return libraryProxy(dispatchThrough(async (path, args) => {
230
+ return libraryProxy(dispatchThrough(async (path, args, extraHeaders) => {
158
231
  // Resolved per CALL, not once at construction. The exported `bowmark` is
159
232
  // built at module load, and a consumer whose `fetch` or `BOWMARK_API_KEY`
160
233
  // arrives after the import would otherwise be frozen against the environment
@@ -162,7 +235,7 @@ export function client(opts = {}) {
162
235
  const resolved = resolveClient(opts);
163
236
  const opened = await openSession(resolved);
164
237
  try {
165
- return await callInSession(resolved, opened.sessionId, path, args);
238
+ return await callInSession(resolved, opened.sessionId, path, args, extraHeaders);
166
239
  }
167
240
  finally {
168
241
  await closeSession(resolved, opened.sessionId).catch((err) => {
@@ -170,5 +243,12 @@ export function client(opts = {}) {
170
243
  return null;
171
244
  });
172
245
  }
173
- }));
246
+ }),
247
+ // Resolved per call too, for the identical reason.
248
+ {
249
+ list: (filter) => listConnections(resolveClient(opts), filter),
250
+ delete: (id) => deleteConnection(resolveClient(opts), id),
251
+ logout: (id) => logoutConnection(resolveClient(opts), id),
252
+ update: (id, patch) => updateConnection(resolveClient(opts), id, patch),
253
+ });
174
254
  }
@@ -155,9 +155,71 @@ export declare function openSession(client: ResolvedClient): Promise<OpenedSessi
155
155
  * Returns the capability's own return value, because that is what the generated
156
156
  * types promise. The envelope's other fields are not dropped: `logs` go to `onLog`,
157
157
  * and everything that is not `status: "ok"` becomes a throw carrying `code`. */
158
- export declare function callInSession(client: ResolvedClient, sessionId: string, path: readonly string[], args: readonly unknown[]): Promise<unknown>;
158
+ export declare function callInSession(client: ResolvedClient, sessionId: string, path: readonly string[], args: readonly unknown[], extraHeaders?: Record<string, string>): Promise<unknown>;
159
159
  /** Close a session. Idempotent server-side, so a `finally` that runs twice is fine. */
160
160
  export declare function closeSession(client: ResolvedClient, sessionId: string): Promise<ClosedSession | null>;
161
+ /** One saved login, as `GET /v1/connections` reports it. Mirrors the `.d.ts`'s
162
+ * ambient `ConnectionSummary` — see `scripts/gen-public-types.ts`'s
163
+ * `AMBIENT_DECLARATIONS`, which must stay in step with this by hand, the same way
164
+ * `CallEnvelope` above already does. */
165
+ export interface ConnectionSummary {
166
+ id: string;
167
+ provider: string;
168
+ scope: string;
169
+ subject: string | null;
170
+ status: string;
171
+ method: string;
172
+ replayLevel: string;
173
+ expiresAt: string;
174
+ validatedAt: string | null;
175
+ lastUsedAt: string | null;
176
+ createdAt: string;
177
+ keepAlive: {
178
+ everyHours: number;
179
+ } | false;
180
+ forcedExpiresAt: string | null;
181
+ }
182
+ /** `GET /v1/connections`. The route itself takes no filter — `provider` is applied
183
+ * CLIENT-SIDE, after the fetch, which is cheap at the scale one account's saved
184
+ * logins reach. */
185
+ export declare function listConnections(client: ResolvedClient, filter?: {
186
+ provider?: string;
187
+ }): Promise<ConnectionSummary[]>;
188
+ /** What `POST /v1/connections/:id/logout` answers. */
189
+ export interface ConnectionLogout {
190
+ loggedOut: string;
191
+ provider: string;
192
+ /** True only when the provider ended the session on the site AND Bowmark checked
193
+ * the site no longer accepts it. */
194
+ siteSignedOut: boolean;
195
+ /** Whether this provider can end a site session at all. */
196
+ siteLogout: "supported" | "unsupported";
197
+ /** Why the site session could not be ended, when it could not. */
198
+ siteError?: string;
199
+ }
200
+ /** `POST /v1/connections/:id/logout`. Drops the cookies Bowmark held, ends the
201
+ * session on the site where the provider can, and KEEPS the entry as `logged_out`
202
+ * so a later `login({ connection: id })` revives it. The other half of grill
203
+ * decision 4 is `deleteConnection` below. */
204
+ export declare function logoutConnection(client: ResolvedClient, id: string): Promise<ConnectionLogout>;
205
+ /** `DELETE /v1/connections/:id`. Forgets the entry and its cookies — it does NOT
206
+ * sign out on the site. `logoutConnection` above is the action that does. */
207
+ export declare function deleteConnection(client: ResolvedClient, id: string): Promise<{
208
+ revoked: string;
209
+ provider: string;
210
+ scope: string;
211
+ }>;
212
+ /** `PATCH /v1/connections/:id` — the two knobs `login({ keepAlive, expiresAt })`
213
+ * sets at acquisition, changeable later. `undefined` leaves a field alone;
214
+ * `expiresAt: null` clears a forced ceiling, `keepAlive: false` turns it off. */
215
+ export declare function updateConnection(client: ResolvedClient, id: string, patch: {
216
+ keepAlive?: {
217
+ everyHours: number;
218
+ } | false;
219
+ expiresAt?: string | null;
220
+ }): Promise<{
221
+ updated: true;
222
+ }>;
161
223
  /** The string surface. Returns the ENVELOPE rather than throwing, because a script
162
224
  * is composite: a `needs_user` or an `error` is a fact about the run that a caller
163
225
  * reads alongside `logs` and `result`, not an exception in their control flow. */
package/dist/transport.js CHANGED
@@ -81,17 +81,23 @@ export function resolveClient(opts = {}) {
81
81
  onLog: opts.onLog,
82
82
  };
83
83
  }
84
- /** POST JSON and parse JSON back.
84
+ /** Send one request and parse JSON back. `postJson` and the `bm.connections.*` REST
85
+ * calls both go through this — the only difference between them is the method and
86
+ * whether there is a body.
85
87
  *
86
- * The caller's headers are merged FIRST so `authorization` and `content-type` win —
87
- * a header that silently replaced the api key would make an unauthenticated call
88
- * look like a permissions problem on our side. */
89
- async function postJson(client, path, body) {
88
+ * The caller's headers are merged FIRST, then `extraHeaders` — a PER-CALL addition
89
+ * (multi-account connections' `login()` credential lift is the one caller today) —
90
+ * so `authorization` and `content-type`, set last, always win. A header that
91
+ * silently replaced the api key would make an unauthenticated call look like a
92
+ * permissions problem on our side. */
93
+ async function sendRequest(client, method, path, body, extraHeaders) {
90
94
  const headers = {
91
95
  ...client.headers,
92
- "content-type": "application/json",
96
+ ...extraHeaders,
93
97
  accept: "application/json",
94
98
  };
99
+ if (body !== undefined)
100
+ headers["content-type"] = "application/json";
95
101
  // Refused HERE rather than sent: the api would answer 401 with the same steps,
96
102
  // and a round trip that can only fail is a slower way to say it.
97
103
  if (!client.apiKey)
@@ -100,9 +106,9 @@ async function postJson(client, path, body) {
100
106
  let response;
101
107
  try {
102
108
  response = await client.fetch(`${client.baseUrl}${path}`, {
103
- method: "POST",
109
+ method,
104
110
  headers,
105
- body: JSON.stringify(body),
111
+ ...(body !== undefined ? { body: JSON.stringify(body) } : {}),
106
112
  signal: client.signal,
107
113
  });
108
114
  }
@@ -126,6 +132,11 @@ async function postJson(client, path, body) {
126
132
  }
127
133
  return { status: response.status, payload: payload };
128
134
  }
135
+ /** POST JSON and parse JSON back. `extraHeaders` rides THIS call only — never
136
+ * captured, never applied to a later call on the same client. */
137
+ async function postJson(client, path, body, extraHeaders) {
138
+ return sendRequest(client, "POST", path, body, extraHeaders);
139
+ }
129
140
  export async function openSession(client) {
130
141
  const { status, payload } = await postJson(client, "/v1/session", {});
131
142
  if (status !== 200 || !payload?.sessionId) {
@@ -141,9 +152,9 @@ export async function openSession(client) {
141
152
  * Returns the capability's own return value, because that is what the generated
142
153
  * types promise. The envelope's other fields are not dropped: `logs` go to `onLog`,
143
154
  * and everything that is not `status: "ok"` becomes a throw carrying `code`. */
144
- export async function callInSession(client, sessionId, path, args) {
155
+ export async function callInSession(client, sessionId, path, args, extraHeaders) {
145
156
  const label = ["bowmark", ...path].join(".");
146
- const { status, payload } = await postJson(client, `/v1/session/${encodeURIComponent(sessionId)}/call`, { path, args });
157
+ const { status, payload } = await postJson(client, `/v1/session/${encodeURIComponent(sessionId)}/call`, { path, args }, extraHeaders);
147
158
  if (client.onLog)
148
159
  for (const line of payload?.logs ?? [])
149
160
  client.onLog(line);
@@ -175,6 +186,66 @@ export async function closeSession(client, sessionId) {
175
186
  return null;
176
187
  return { ok: true, calls: payload.calls, ms: payload.ms };
177
188
  }
189
+ /** `GET /v1/connections`. The route itself takes no filter — `provider` is applied
190
+ * CLIENT-SIDE, after the fetch, which is cheap at the scale one account's saved
191
+ * logins reach. */
192
+ export async function listConnections(client, filter = {}) {
193
+ const { status, payload } = await sendRequest(client, "GET", "/v1/connections");
194
+ if (status !== 200 || !payload?.connections) {
195
+ throw new BowmarkError(payload?.error ?? `could not list connections (HTTP ${status})`, {
196
+ code: `http_${status}`,
197
+ httpStatus: status,
198
+ });
199
+ }
200
+ return filter.provider
201
+ ? payload.connections.filter((c) => c.provider === filter.provider)
202
+ : payload.connections;
203
+ }
204
+ /** `POST /v1/connections/:id/logout`. Drops the cookies Bowmark held, ends the
205
+ * session on the site where the provider can, and KEEPS the entry as `logged_out`
206
+ * so a later `login({ connection: id })` revives it. The other half of grill
207
+ * decision 4 is `deleteConnection` below. */
208
+ export async function logoutConnection(client, id) {
209
+ const { status, payload } = await sendRequest(client, "POST", `/v1/connections/${encodeURIComponent(id)}/logout`);
210
+ if (status !== 200 || !payload?.loggedOut) {
211
+ throw new BowmarkError(payload?.error ?? `could not log out connection ${id} (HTTP ${status})`, {
212
+ code: `http_${status}`,
213
+ httpStatus: status,
214
+ });
215
+ }
216
+ return {
217
+ loggedOut: payload.loggedOut,
218
+ provider: payload.provider ?? "",
219
+ siteSignedOut: payload.siteSignedOut === true,
220
+ siteLogout: payload.siteLogout === "supported" ? "supported" : "unsupported",
221
+ ...(payload.siteError ? { siteError: payload.siteError } : {}),
222
+ };
223
+ }
224
+ /** `DELETE /v1/connections/:id`. Forgets the entry and its cookies — it does NOT
225
+ * sign out on the site. `logoutConnection` above is the action that does. */
226
+ export async function deleteConnection(client, id) {
227
+ const { status, payload } = await sendRequest(client, "DELETE", `/v1/connections/${encodeURIComponent(id)}`);
228
+ if (status !== 200 || !payload?.revoked) {
229
+ throw new BowmarkError(payload?.error ?? `could not delete connection ${id} (HTTP ${status})`, {
230
+ code: `http_${status}`,
231
+ httpStatus: status,
232
+ });
233
+ }
234
+ return { revoked: payload.revoked, provider: payload.provider ?? "", scope: payload.scope ?? "" };
235
+ }
236
+ /** `PATCH /v1/connections/:id` — the two knobs `login({ keepAlive, expiresAt })`
237
+ * sets at acquisition, changeable later. `undefined` leaves a field alone;
238
+ * `expiresAt: null` clears a forced ceiling, `keepAlive: false` turns it off. */
239
+ export async function updateConnection(client, id, patch) {
240
+ const { status, payload } = await sendRequest(client, "PATCH", `/v1/connections/${encodeURIComponent(id)}`, patch);
241
+ if (status !== 200 || !payload?.updated) {
242
+ throw new BowmarkError(payload?.error ?? `could not update connection ${id} (HTTP ${status})`, {
243
+ code: `http_${status}`,
244
+ httpStatus: status,
245
+ });
246
+ }
247
+ return { updated: true };
248
+ }
178
249
  /** The string surface. Returns the ENVELOPE rather than throwing, because a script
179
250
  * is composite: a `needs_user` or an `error` is a fact about the run that a caller
180
251
  * reads alongside `logs` and `result`, not an exception in their control flow. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bowmark/web",
3
- "version": "1.24.2",
3
+ "version": "1.25.0",
4
4
  "type": "module",
5
5
  "description": "The public client for the Bowmark capability library — real TypeScript for the whole bowmark.* surface, with no Bowmark source on the caller's disk. ZERO runtime dependencies, deliberately and permanently.",
6
6
  "license": "MIT",