@bluestep-systems/b6p-core 1.8.1 → 1.9.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.
Files changed (43) hide show
  1. package/README.md +85 -10
  2. package/dist/B6PCore.js +40 -1
  3. package/dist/B6PCore.js.map +1 -1
  4. package/dist/Err.d.ts +42 -3
  5. package/dist/Err.js +51 -1
  6. package/dist/Err.js.map +1 -1
  7. package/dist/auth/BearerAuthProvider.d.ts +43 -13
  8. package/dist/auth/BearerAuthProvider.js +151 -22
  9. package/dist/auth/BearerAuthProvider.js.map +1 -1
  10. package/dist/constants/Gateway.d.ts +78 -1
  11. package/dist/constants/Gateway.js +79 -1
  12. package/dist/constants/Gateway.js.map +1 -1
  13. package/dist/gateway/GatewayClient.d.ts +72 -0
  14. package/dist/gateway/GatewayClient.js +132 -15
  15. package/dist/gateway/GatewayClient.js.map +1 -1
  16. package/dist/gateway/GatewayContext.d.ts +10 -3
  17. package/dist/gateway/GatewayKb.d.ts +2 -2
  18. package/dist/gateway/GatewayKb.js +6 -6
  19. package/dist/gateway/GatewayKb.js.map +1 -1
  20. package/dist/gateway/GatewayService.d.ts +8 -1
  21. package/dist/gateway/GatewayService.js +8 -0
  22. package/dist/gateway/GatewayService.js.map +1 -1
  23. package/dist/gateway/GatewaySignIn.d.ts +372 -0
  24. package/dist/gateway/GatewaySignIn.js +825 -0
  25. package/dist/gateway/GatewaySignIn.js.map +1 -0
  26. package/dist/gateway/GatewayToken.d.ts +19 -4
  27. package/dist/gateway/GatewayToken.js +51 -10
  28. package/dist/gateway/GatewayToken.js.map +1 -1
  29. package/dist/gateway/GatewayTokenService.d.ts +2 -2
  30. package/dist/gateway/GatewayTokenService.js +20 -9
  31. package/dist/gateway/GatewayTokenService.js.map +1 -1
  32. package/dist/index.d.ts +7 -5
  33. package/dist/index.js +8 -3
  34. package/dist/index.js.map +1 -1
  35. package/dist/persistence/PersistenceKeys.d.ts +6 -1
  36. package/dist/persistence/PersistenceKeys.js +5 -0
  37. package/dist/persistence/PersistenceKeys.js.map +1 -1
  38. package/dist/providers.d.ts +66 -3
  39. package/dist/testing/FakeGateway.d.ts +135 -1
  40. package/dist/testing/FakeGateway.js +197 -1
  41. package/dist/testing/FakeGateway.js.map +1 -1
  42. package/dist/types.d.ts +78 -0
  43. package/package.json +2 -2
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BearerAuthProvider = void 0;
4
4
  const constants_1 = require("../constants");
5
+ const lockedMutation_1 = require("../persistence/lockedMutation");
6
+ const GatewayToken_1 = require("../gateway/GatewayToken");
5
7
  const PERSISTENCE_KEY = "bearerAuth";
6
8
  /**
7
9
  * Secret-storage key written by the removed `BasicAuthProvider`. Purged by
@@ -29,10 +31,16 @@ class BearerAuthProvider {
29
31
  }
30
32
  /**
31
33
  * Returns the bearer auth header value (`"Bearer <token>"`).
32
- * Prompts for a token if none is stored.
34
+ * Prompts for a token if none is stored. A stored value that is not a platform token (a reserved `b6p_o_` one,
35
+ * say, stored before 1.9.0 refused it) is never put in a header: it throws, the value unquoted.
36
+ * @lastreviewed null
33
37
  */
34
38
  async authHeaderValue() {
35
39
  const { token } = await this.getOrCreate();
40
+ const problem = (0, GatewayToken_1.gatewayTokenProblem)(token);
41
+ if (problem !== null) {
42
+ throw new Error(`The stored access token is not a platform token (${problem}); it was not sent.`);
43
+ }
36
44
  return `${constants_1.AuthTypes.BEARER_PREFIX}${token}`;
37
45
  }
38
46
  async getOrCreate() {
@@ -77,7 +85,16 @@ class BearerAuthProvider {
77
85
  return false;
78
86
  }
79
87
  const candidate = value;
80
- return candidate.scheme === BEARER_SCHEME && typeof candidate.token === "string" && candidate.token.length > 0;
88
+ if (!(candidate.scheme === BEARER_SCHEME && typeof candidate.token === "string" && candidate.token.length > 0)) {
89
+ return false;
90
+ }
91
+ // A sign-in record that is not well formed is dropped, never the token: the token still works, and b6p then
92
+ // treats it as pasted (it does not revoke or renew what it cannot describe).
93
+ if (candidate.signIn !== undefined && !isSignInRecord(candidate.signIn)) {
94
+ this.logger.warn("The stored sign-in record is malformed; the token is kept and treated as pasted.");
95
+ delete candidate.signIn;
96
+ }
97
+ return true;
81
98
  }
82
99
  /**
83
100
  * Prompt for a new token and store it.
@@ -88,6 +105,9 @@ class BearerAuthProvider {
88
105
  * false right after a "Token stored" log line, and the next `authHeaderValue()`
89
106
  * re-prompted, giving a user who keeps pressing Enter an unbounded prompt loop.
90
107
  *
108
+ * A value that is not a platform token (`b6p_g_`, `b6p_t_`, `b6pt_`; the reserved `b6p_o_` is not one) is refused
109
+ * unstored, as is a new value given to {@link update}.
110
+ *
91
111
  * Note {@link update} deliberately reads empty as "keep the current token"; there
92
112
  * is no current token to keep here.
93
113
  * @lastreviewed null
@@ -97,6 +117,7 @@ class BearerAuthProvider {
97
117
  if (token === undefined || token.length === 0) {
98
118
  throw new Error("Token entry cancelled");
99
119
  }
120
+ refuseNonPlatform(token);
100
121
  const creds = { scheme: BEARER_SCHEME, token };
101
122
  await this.persistence.setSecret(PERSISTENCE_KEY, JSON.stringify(creds));
102
123
  this.logger.info("Token stored");
@@ -115,7 +136,11 @@ class BearerAuthProvider {
115
136
  this.prompt.info("Cancelled");
116
137
  return existing;
117
138
  }
118
- const creds = { scheme: BEARER_SCHEME, token: newToken || existing.token };
139
+ if (newToken) {
140
+ refuseNonPlatform(newToken);
141
+ }
142
+ // Keeping the current token keeps what is known about it (a device sign-in's record); a new one is pasted.
143
+ const creds = newToken ? { scheme: BEARER_SCHEME, token: newToken } : existing;
119
144
  await this.persistence.setSecret(PERSISTENCE_KEY, JSON.stringify(creds));
120
145
  if (creds.token === existing.token) {
121
146
  this.prompt.info("No changes made to the token.");
@@ -161,37 +186,141 @@ class BearerAuthProvider {
161
186
  * Never prompts, and neither value is logged or put in an error message.
162
187
  *
163
188
  * This is the write behind rotating the stored token through the gateway: the gateway has
164
- * already revoked `expected`, so `next` must take its place. It is the only write the gateway
165
- * side has; it does not touch the web session, which still bootstraps through
166
- * {@link authHeaderValue}.
189
+ * already revoked `expected`, so `next` must take its place. It does not touch the web session,
190
+ * which still bootstraps through {@link authHeaderValue}. A device sign-in's record follows the
191
+ * token: `minted` (the gateway's answer) gives its new id, expiry and scopes; without it the id
192
+ * becomes unknown (`null`).
167
193
  *
168
- * The check is an in-process compare-then-write, **not** atomic across processes: it reads, then
169
- * writes, with awaits between, and the persistence layer holds no cross-process lock. It catches
170
- * a token that something else (another b6p process, `auth update`) stored before the read; a
171
- * write by another process that lands between this read and this write is overwritten. The
172
- * value is read back after the write, so an overwrite that lands before that read-back is
173
- * reported (thrown) rather than reported as stored.
194
+ * The compare-then-write runs under the store's lock ({@link storeSignIn} and {@link forget} take
195
+ * the same one; across processes only when the persistence can lock). `auth set` / `auth update`
196
+ * do not take it, so a write by them, or by a persistence that cannot lock, that lands between this
197
+ * read and this write is overwritten. The value is read back after the write, so an overwrite that
198
+ * lands before that read-back is reported (thrown) rather than reported as stored.
174
199
  *
175
200
  * @throws {Error} when `next` is empty, the stored token is no longer `expected`, the write fails,
176
201
  * or the read-back finds something other than `next`
177
202
  * @lastreviewed null
178
203
  */
179
- async replaceStoredToken(expected, next) {
204
+ async replaceStoredToken(expected, next, minted) {
180
205
  if (next.length === 0) {
181
206
  throw new Error("The replacement token is empty; the stored token was left as it was.");
182
207
  }
208
+ await (0, lockedMutation_1.exclusive)(this.persistence, PERSISTENCE_KEY, async () => {
209
+ const stored = await this.readStored();
210
+ if (stored?.token !== expected) {
211
+ throw new Error("The stored token is no longer the one that was rotated; it was left as it was.");
212
+ }
213
+ const creds = { scheme: BEARER_SCHEME, token: next };
214
+ if (stored.signIn) {
215
+ // A rotation keeps the alias; the id, expiry and scopes are the replacement's when the gateway said them.
216
+ creds.signIn = minted
217
+ ? {
218
+ ...stored.signIn,
219
+ tokenId: minted.id,
220
+ scopes: [...minted.scopes],
221
+ expiresAt: minted.expiresAt,
222
+ refreshable: minted.refreshable,
223
+ storedAt: new Date().toISOString(),
224
+ }
225
+ : { ...stored.signIn, tokenId: null, storedAt: new Date().toISOString() };
226
+ }
227
+ await this.persistence.setSecret(PERSISTENCE_KEY, JSON.stringify(creds));
228
+ // Read it back: another process sharing the store can write its stale copy over this one.
229
+ if ((await this.readStored())?.token !== next) {
230
+ throw new Error("The stored token was overwritten right after the replacement was written; it is not stored.");
231
+ }
232
+ });
233
+ this.logger.info("Token replaced");
234
+ }
235
+ /**
236
+ * The stored token and its sign-in record (`null` for a pasted token), or `undefined` when none is stored. Never
237
+ * prompts and never logs the value.
238
+ * @lastreviewed null
239
+ */
240
+ async storedSignIn() {
183
241
  const stored = await this.readStored();
184
- if (stored?.token !== expected) {
185
- throw new Error("The stored token is no longer the one that was rotated; it was left as it was.");
186
- }
187
- const creds = { scheme: BEARER_SCHEME, token: next };
188
- await this.persistence.setSecret(PERSISTENCE_KEY, JSON.stringify(creds));
189
- // Read it back: another process sharing the store can write its stale copy over this one.
190
- if ((await this.readStored())?.token !== next) {
191
- throw new Error("The stored token was overwritten right after the replacement was written; it is not stored.");
242
+ return stored === undefined ? undefined : { token: stored.token, signIn: stored.signIn ?? null };
243
+ }
244
+ /**
245
+ * Store `token`, made by a device sign-in, with its record, in place of whatever is stored, and read it back.
246
+ * Runs under the store's lock (across processes when the persistence can lock), and reads what it replaces
247
+ * inside it. Never prompts; neither value reaches a log line or a message.
248
+ *
249
+ * @returns what it replaced, `undefined` when nothing was stored
250
+ * @throws {Error} the token or record is not usable, the write failed, or the read-back found something else
251
+ * @lastreviewed null
252
+ */
253
+ async storeSignIn(token, signIn) {
254
+ if (token.length === 0 || !isSignInRecord(signIn)) {
255
+ throw new Error("The signed-in token or its record is not usable; nothing was stored.");
192
256
  }
193
- this.logger.info("Token replaced");
257
+ return (0, lockedMutation_1.exclusive)(this.persistence, PERSISTENCE_KEY, async () => {
258
+ const previous = await this.storedSignIn();
259
+ const creds = { scheme: BEARER_SCHEME, token, signIn };
260
+ await this.persistence.setSecret(PERSISTENCE_KEY, JSON.stringify(creds));
261
+ if ((await this.readStored())?.token !== token) {
262
+ throw new Error("The stored token was overwritten right after the new one was written; it is not stored.");
263
+ }
264
+ this.logger.info("Token stored");
265
+ return previous;
266
+ });
267
+ }
268
+ /**
269
+ * Forget the stored token when it is still `expected` (under the store's lock), along with any credentials left
270
+ * behind by the removed basic-auth provider. Never prompts.
271
+ *
272
+ * @returns `true` when it was forgotten (or nothing was stored), `false` when another token is stored now; that
273
+ * one is left as it is
274
+ * @lastreviewed null
275
+ */
276
+ async forget(expected) {
277
+ return (0, lockedMutation_1.exclusive)(this.persistence, PERSISTENCE_KEY, async () => {
278
+ const stored = await this.readStored();
279
+ if (stored !== undefined && stored.token !== expected) {
280
+ return false;
281
+ }
282
+ await this.clear();
283
+ return true;
284
+ });
194
285
  }
195
286
  }
196
287
  exports.BearerAuthProvider = BearerAuthProvider;
288
+ /**
289
+ * Refuse, before anything is stored, a value that is not a platform token (`b6p_g_`, `b6p_t_`, `b6pt_`): the
290
+ * reserved `b6p_o_`, a value with no prefix, or one with whitespace. The value is never quoted.
291
+ * @lastreviewed null
292
+ */
293
+ function refuseNonPlatform(token) {
294
+ const problem = (0, GatewayToken_1.gatewayTokenProblem)(token);
295
+ if (problem !== null) {
296
+ throw new Error(`That is not a platform access token (${problem}); nothing was stored.`);
297
+ }
298
+ }
299
+ /**
300
+ * Whether `value` is a well-formed {@link GatewaySignInRecord}.
301
+ * @lastreviewed null
302
+ */
303
+ function isSignInRecord(value) {
304
+ if (typeof value !== "object" || value === null) {
305
+ return false;
306
+ }
307
+ const r = value;
308
+ return (typeof r.gateway === "string" &&
309
+ r.gateway.length > 0 &&
310
+ (r.tokenId === null || (typeof r.tokenId === "string" && r.tokenId.length > 0)) &&
311
+ typeof r.alias === "string" &&
312
+ (r.account === null || isAccount(r.account)) &&
313
+ Array.isArray(r.scopes) &&
314
+ r.scopes.every((scope) => typeof scope === "string") &&
315
+ (r.expiresAt === null || (typeof r.expiresAt === "string" && !Number.isNaN(Date.parse(r.expiresAt)))) &&
316
+ typeof r.refreshable === "boolean" &&
317
+ typeof r.storedAt === "string");
318
+ }
319
+ function isAccount(value) {
320
+ if (typeof value !== "object" || value === null) {
321
+ return false;
322
+ }
323
+ const a = value;
324
+ return typeof a.name === "string" && typeof a.login === "string";
325
+ }
197
326
  //# sourceMappingURL=BearerAuthProvider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"BearerAuthProvider.js","sourceRoot":"","sources":["../../src/auth/BearerAuthProvider.ts"],"names":[],"mappings":";;;AACA,4CAAyC;AAGzC,MAAM,eAAe,GAAG,YAAY,CAAC;AAErC;;;;GAIG;AACH,MAAM,4BAA4B,GAAG,WAAW,CAAC;AAEjD,kFAAkF;AAClF,MAAM,aAAa,GAAG,QAAQ,CAAC;AAE/B;;;;;;GAMG;AACH;IAEqB,WAAW;IACX,MAAM;IACN,MAAM;IAHzB,YACmB,WAAwB,EACxB,MAAc,EACd,MAAc;2BAFd,WAAW;sBACX,MAAM;sBACN,MAAM;IACtB,CAAC;IAEJ;;;OAGG;IACH,KAAK,CAAC,eAAe;QACnB,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC;QAC3C,OAAO,GAAG,qBAAS,CAAC,aAAa,GAAG,KAAK,EAAE,CAAC;IAC9C,CAAC;IAED,KAAK,CAAC,WAAW;QACf,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;QACvC,IAAI,MAAM,EAAE,CAAC;YACX,OAAO,MAAM,CAAC;QAChB,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,oDAAoD,CAAC,CAAC;QACvE,OAAO,IAAI,CAAC,SAAS,EAAE,CAAC;IAC1B,CAAC;IAED;;;;;;;;;OASG;IACK,KAAK,CAAC,UAAU;QACtB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC;QAC9D,IAAI,CAAC,GAAG,E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AAK,CAAC;IACf,CAAC;IACD,MAAM,CAAC,GAAG,KAA6D,CAAC;IACxE,OAAO,OAAO,CAAC,CAAC,IAAI,KAAK,QAAQ,IAAI,OAAO,CAAC,CAAC,KAAK,KAAK,QAAQ,CAAC;AACnE,CAAC"}
@@ -11,7 +11,31 @@ export declare namespace Gateway {
11
11
  */
12
12
  const DEFAULT_URL = "https://gateway.bluestep.net";
13
13
  /**
14
- * Every global-user access token the gateway accepts starts with this.
14
+ * The prefixes of the platform tokens b6p accepts, stores and sends (web-shared `TokenPrefix`):
15
+ * - `b6p_g_`: a global user's token, as minted since web-global's strict mints;
16
+ * - `b6p_t_`: a tenant's own user's token;
17
+ * - `b6pt_`: the legacy global token, still accepted everywhere (deprecated by the platform, never minted again).
18
+ *
19
+ * Minted tokens are the prefix and 48 lower-case hex characters; b6p checks only the prefix and that the rest is
20
+ * printable ASCII (the alphabet is the platform's business). No prefix is a prefix of another.
21
+ * @lastreviewed null
22
+ */
23
+ const TOKEN_PREFIXES: readonly ["b6p_g_", "b6p_t_", "b6pt_"];
24
+ /**
25
+ * Prefixes the platform reserves and b6p never accepts as a platform token: `b6p_o_` is for OAuth access tokens.
26
+ * A value with one is still a secret, so it is redacted like the others ({@link SECRET_PREFIXES}).
27
+ * @lastreviewed null
28
+ */
29
+ const RESERVED_TOKEN_PREFIXES: readonly ["b6p_o_"];
30
+ /**
31
+ * Every prefix that marks a secret: {@link TOKEN_PREFIXES} and {@link RESERVED_TOKEN_PREFIXES}. Anything starting
32
+ * with one (in any letter case) is redacted from messages and refused where an id, alias, page or name belongs.
33
+ * @lastreviewed null
34
+ */
35
+ const SECRET_PREFIXES: readonly ["b6p_g_", "b6p_t_", "b6pt_", "b6p_o_"];
36
+ /**
37
+ * The legacy prefix alone. Kept for consumers that imported it; core no longer reads it.
38
+ * @deprecated Use {@link TOKEN_PREFIXES} to accept tokens and {@link SECRET_PREFIXES} to recognise secrets.
15
39
  * @lastreviewed null
16
40
  */
17
41
  const TOKEN_PREFIX = "b6pt_";
@@ -46,6 +70,44 @@ export declare namespace Gateway {
46
70
  * @lastreviewed null
47
71
  */
48
72
  const REFRESH_DAYS: readonly [30, 60, 90, 180, 365];
73
+ /**
74
+ * Device sign-in (`b6p auth login`) and the renewal of the token it makes. The token's scopes, lifetime and name
75
+ * are the gateway's (`mcp, kb:read, kb:push, registry:read, tokens:self`; 90 days; refreshable;
76
+ * `b6p on <host> <yyyy-MM-dd HH:mm>`): b6p asks for none of them.
77
+ * @lastreviewed null
78
+ */
79
+ namespace SignIn {
80
+ /**
81
+ * The `client` b6p names itself as when it starts a sign-in.
82
+ * @lastreviewed null
83
+ */
84
+ const CLIENT = "b6p";
85
+ /**
86
+ * The most code points of the computer's name sent as `host` (the gateway cuts to this too).
87
+ * @lastreviewed null
88
+ */
89
+ const MAX_HOST = 40;
90
+ /**
91
+ * The most code points of `client`, `clientVersion` and `platform`.
92
+ * @lastreviewed null
93
+ */
94
+ const MAX_LABEL = 32;
95
+ /**
96
+ * A renewal is due when this many days or fewer are left.
97
+ * @lastreviewed null
98
+ */
99
+ const RENEW_WITHIN_DAYS = 30;
100
+ /**
101
+ * A renewal gives the token this many days from the moment of renewal (the sign-in's own lifetime).
102
+ * @lastreviewed null
103
+ */
104
+ const RENEW_DAYS = 90;
105
+ /**
106
+ * A due renewal is tried at most once in this long on one computer (unless forced).
107
+ * @lastreviewed null
108
+ */
109
+ const RENEW_ATTEMPT_INTERVAL_MS: number;
110
+ }
49
111
  /**
50
112
  * Request headers specific to the gateway contract.
51
113
  * @lastreviewed null
@@ -80,6 +142,21 @@ export declare namespace Gateway {
80
142
  const REGISTRY_TOMBSTONES = "/api/v1/registry/tombstones";
81
143
  const GIT = "/api/v1/git";
82
144
  const TOKENS = "/api/v1/tokens";
145
+ /**
146
+ * Device sign-in's start (`POST`, no token): b6p's `b6p auth login`.
147
+ * @lastreviewed null
148
+ */
149
+ const DEVICE_LOGINS = "/api/v1/device-logins";
150
+ /**
151
+ * Device sign-in's poll (`POST {deviceCode}`, no token).
152
+ * @lastreviewed null
153
+ */
154
+ const DEVICE_LOGIN_POLL = "/api/v1/device-logins/poll";
155
+ /**
156
+ * The gateway's sign-in options (`GET`, anonymous); `deviceLogin: true` when device sign-in is on.
157
+ * @lastreviewed null
158
+ */
159
+ const AUTH_OPTIONS = "/api/v1/auth/options";
83
160
  /**
84
161
  * The gateway's MCP endpoint (streamable HTTP), which takes the same `b6pt_` token with the `mcp` scope.
85
162
  * @lastreviewed null
@@ -15,7 +15,31 @@ var Gateway;
15
15
  */
16
16
  Gateway.DEFAULT_URL = "https://gateway.bluestep.net";
17
17
  /**
18
- * Every global-user access token the gateway accepts starts with this.
18
+ * The prefixes of the platform tokens b6p accepts, stores and sends (web-shared `TokenPrefix`):
19
+ * - `b6p_g_`: a global user's token, as minted since web-global's strict mints;
20
+ * - `b6p_t_`: a tenant's own user's token;
21
+ * - `b6pt_`: the legacy global token, still accepted everywhere (deprecated by the platform, never minted again).
22
+ *
23
+ * Minted tokens are the prefix and 48 lower-case hex characters; b6p checks only the prefix and that the rest is
24
+ * printable ASCII (the alphabet is the platform's business). No prefix is a prefix of another.
25
+ * @lastreviewed null
26
+ */
27
+ Gateway.TOKEN_PREFIXES = ["b6p_g_", "b6p_t_", "b6pt_"];
28
+ /**
29
+ * Prefixes the platform reserves and b6p never accepts as a platform token: `b6p_o_` is for OAuth access tokens.
30
+ * A value with one is still a secret, so it is redacted like the others ({@link SECRET_PREFIXES}).
31
+ * @lastreviewed null
32
+ */
33
+ Gateway.RESERVED_TOKEN_PREFIXES = ["b6p_o_"];
34
+ /**
35
+ * Every prefix that marks a secret: {@link TOKEN_PREFIXES} and {@link RESERVED_TOKEN_PREFIXES}. Anything starting
36
+ * with one (in any letter case) is redacted from messages and refused where an id, alias, page or name belongs.
37
+ * @lastreviewed null
38
+ */
39
+ Gateway.SECRET_PREFIXES = [...Gateway.TOKEN_PREFIXES, ...Gateway.RESERVED_TOKEN_PREFIXES];
40
+ /**
41
+ * The legacy prefix alone. Kept for consumers that imported it; core no longer reads it.
42
+ * @deprecated Use {@link TOKEN_PREFIXES} to accept tokens and {@link SECRET_PREFIXES} to recognise secrets.
19
43
  * @lastreviewed null
20
44
  */
21
45
  Gateway.TOKEN_PREFIX = "b6pt_";
@@ -50,6 +74,45 @@ var Gateway;
50
74
  * @lastreviewed null
51
75
  */
52
76
  Gateway.REFRESH_DAYS = [30, 60, 90, 180, 365];
77
+ /**
78
+ * Device sign-in (`b6p auth login`) and the renewal of the token it makes. The token's scopes, lifetime and name
79
+ * are the gateway's (`mcp, kb:read, kb:push, registry:read, tokens:self`; 90 days; refreshable;
80
+ * `b6p on <host> <yyyy-MM-dd HH:mm>`): b6p asks for none of them.
81
+ * @lastreviewed null
82
+ */
83
+ let SignIn;
84
+ (function (SignIn) {
85
+ /**
86
+ * The `client` b6p names itself as when it starts a sign-in.
87
+ * @lastreviewed null
88
+ */
89
+ SignIn.CLIENT = "b6p";
90
+ /**
91
+ * The most code points of the computer's name sent as `host` (the gateway cuts to this too).
92
+ * @lastreviewed null
93
+ */
94
+ SignIn.MAX_HOST = 40;
95
+ /**
96
+ * The most code points of `client`, `clientVersion` and `platform`.
97
+ * @lastreviewed null
98
+ */
99
+ SignIn.MAX_LABEL = 32;
100
+ /**
101
+ * A renewal is due when this many days or fewer are left.
102
+ * @lastreviewed null
103
+ */
104
+ SignIn.RENEW_WITHIN_DAYS = 30;
105
+ /**
106
+ * A renewal gives the token this many days from the moment of renewal (the sign-in's own lifetime).
107
+ * @lastreviewed null
108
+ */
109
+ SignIn.RENEW_DAYS = 90;
110
+ /**
111
+ * A due renewal is tried at most once in this long on one computer (unless forced).
112
+ * @lastreviewed null
113
+ */
114
+ SignIn.RENEW_ATTEMPT_INTERVAL_MS = 24 * 60 * 60 * 1_000;
115
+ })(SignIn = Gateway.SignIn || (Gateway.SignIn = {}));
53
116
  /**
54
117
  * Request headers specific to the gateway contract.
55
118
  * @lastreviewed null
@@ -86,6 +149,21 @@ var Gateway;
86
149
  Paths.REGISTRY_TOMBSTONES = "/api/v1/registry/tombstones";
87
150
  Paths.GIT = "/api/v1/git";
88
151
  Paths.TOKENS = "/api/v1/tokens";
152
+ /**
153
+ * Device sign-in's start (`POST`, no token): b6p's `b6p auth login`.
154
+ * @lastreviewed null
155
+ */
156
+ Paths.DEVICE_LOGINS = "/api/v1/device-logins";
157
+ /**
158
+ * Device sign-in's poll (`POST {deviceCode}`, no token).
159
+ * @lastreviewed null
160
+ */
161
+ Paths.DEVICE_LOGIN_POLL = "/api/v1/device-logins/poll";
162
+ /**
163
+ * The gateway's sign-in options (`GET`, anonymous); `deviceLogin: true` when device sign-in is on.
164
+ * @lastreviewed null
165
+ */
166
+ Paths.AUTH_OPTIONS = "/api/v1/auth/options";
89
167
  /**
90
168
  * The gateway's MCP endpoint (streamable HTTP), which takes the same `b6pt_` token with the `mcp` scope.
91
169
  * @lastreviewed null
@@ -1 +1 @@
1
- {"version":3,"file":"Gateway.js","sourceRoot":"","sources":["../../src/constants/Gateway.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,IAAiB,OAAO,CAqHvB;AArHD,WAAiB,OAAO;IACtB;;;OAGG;IACU,mBAAW,GAAG,8BAA8B,CAAC;IAE1D;;;OAGG;IACU,oBAAY,GAAG,OAAO,CAAC;IAEpC;;;OAGG;IACU,0BAAkB,GAAG,MAAM,CAAC;IAEzC;;;;OAIG;IACU,iCAAyB,GAAG,MAAM,CAAC;IAEhD;;;;;OAKG;IACU,2BAAmB,GAAG,MAAM,CAAC;IAE1C;;;;;OAKG;IACU,wBAAgB,GAAG,GAAG,CAAC;IAEpC;;;;OAIG;IACU,oBAAY,GAAG,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,CAAU,CAAC;IAE5D;;;OAGG;IACH,IAAiB,OAAO,CAcvB;IAdD,WAAiB,OAAO;QACtB;;;;WAIG;QACU,uBAAe,GAAG,iBAAiB,CAAC;QAEjD;;;;WAIG;QAC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tC;;;OAGG;IACH,IAAiB,KAAK,CAoCrB;IApCD,WAAiB,KAAK;QACP,qBAAe,GAAG,yBAAyB,CAAC;QAC5C,oBAAc,GAAG,wBAAwB,CAAC;QAC1C,yBAAmB,GAAG,6BAA6B,CAAC;QACpD,SAAG,GAAG,aAAa,CAAC;QACpB,YAAM,GAAG,gBAAgB,CAAC;QACvC;;;WAGG;QACU,mBAAa,GAAG,uBAAuB,CAAC;QACrD;;;WAGG;QACU,uBAAiB,GAAG,4BAA4B,CAAC;QAC9D;;;WAGG;QACU,kBAAY,GAAG,sBAAsB,CAAC;QACnD;;;WAGG;QACU,SAAG,GAAG,MAAM,CAAC;QAC1B;;;WAGG;QACU,kBAAY,GAAG,eAAe,CAAC;QAC5C;;;WAGG;QACU,oBAAc,GAAG,eAAe,CAAC;IAChD,CAAC,EApCgB,KAAK,GAAL,QAAA,KAAK,KAAL,QAAA,KAAK,QAoCrB;IAED;;;;OAIG;IACH,IAAiB,MAAM,CAQtB;IARD,WAAiB,MAAM;QACR,cAAO,GAAG,SAAS,CAAC;QACpB,cAAO,GAAG,SAAS,CAAC;QACpB,gBAAS,GAAG,WAAW,CAAC;QACxB,oBAAa,GAAG,eAAe,CAAC;QAChC,oBAAa,GAAG,eAAe,CAAC;QAChC,UAAG,GAAG,KAAK,CAAC;QACZ,kBAAW,GAAG,aAAa,CAAC;IAC3C,CAAC,EARgB,MAAM,GAAN,QAAA,MAAM,KAAN,QAAA,MAAM,QAQtB;AACH,CAAC,EAtMgB,OAAO,aAAP,OAAO,GAAP,OAAO,QAsMvB"}
@@ -137,6 +137,48 @@ export interface GatewayMcpProbe {
137
137
  status: number;
138
138
  refusal: Err.GatewayError | null;
139
139
  }
140
+ /**
141
+ * What pins an operation's requests ({@link GatewayClient.sequenceAs}, {@link GatewayClient.anonymous}): the one
142
+ * gateway origin they all go to (a configured gateway that no longer is this origin is refused with
143
+ * {@link Err.GatewayConfigError}, nothing sent), and the signal that stops them, queued or under way
144
+ * ({@link Err.GatewayAbortedError}).
145
+ * @lastreviewed null
146
+ */
147
+ export interface GatewayPin {
148
+ origin: string;
149
+ signal?: AbortSignal;
150
+ }
151
+ /**
152
+ * An answer to {@link GatewayClient.anonymous}, whatever its status.
153
+ * @lastreviewed null
154
+ */
155
+ export interface GatewayAnonymousResponse {
156
+ /**
157
+ * The HTTP status (never a redirect: that is thrown).
158
+ * @lastreviewed null
159
+ */
160
+ status: number;
161
+ /**
162
+ * The parsed JSON body; `undefined` when it was empty, not JSON, or (for a refusal) did not arrive.
163
+ * @lastreviewed null
164
+ */
165
+ body: JsonValue | undefined;
166
+ /**
167
+ * The body's `error` code, when it had one.
168
+ * @lastreviewed null
169
+ */
170
+ code: string | null;
171
+ /**
172
+ * The `Retry-After` header in seconds, when it was a whole number.
173
+ * @lastreviewed null
174
+ */
175
+ retryAfterSeconds: number | null;
176
+ /**
177
+ * What was asked, for messages (`POST /api/v1/device-logins`).
178
+ * @lastreviewed null
179
+ */
180
+ what: string;
181
+ }
140
182
  /**
141
183
  * Validate a configured gateway URL and reduce it to its origin. Throws
142
184
  * {@link Err.GatewayConfigError} for anything the token must not be sent to.
@@ -228,6 +270,36 @@ export declare class GatewayClient {
228
270
  * @lastreviewed null
229
271
  */
230
272
  sequence<T>(unit: (seq: GatewaySequence) => Promise<T>): Promise<T>;
273
+ /**
274
+ * {@link sequence}, presenting `token` instead of the stored one (and, with `pin`, only to the pinned origin, and
275
+ * stopped by its signal; see {@link GatewayPin}): for a request that must be made with a token
276
+ * b6p holds but is not (or soon not) the stored one, such as revoking the token a new sign-in replaced, with
277
+ * that token's own `tokens:self`. `token` is checked as the stored one is ({@link gatewayTokenProblem}); every
278
+ * other rule is {@link sequence}'s (gateway origin only, queued, no redirects, never in a message).
279
+ * @lastreviewed null
280
+ */
281
+ sequenceAs<T>(token: string, unit: (seq: GatewaySequence) => Promise<T>, pin?: GatewayPin): Promise<T>;
282
+ /**
283
+ * One JSON request that carries no token and no cookie, for the gateway's anonymous routes (device sign-in's
284
+ * start and poll, the sign-in options). Queued like every request, gateway origin only, never redirected.
285
+ * Unlike {@link request} it does not throw for a non-2xx answer: the caller reads `status`, `code` and
286
+ * `retryAfterSeconds` and decides. The server's own message is never returned, so nothing it echoes (a code
287
+ * from the body) can reach a message.
288
+ *
289
+ * @throws {Err.GatewayUnavailableError} no answer (network, timeout), or a 2xx whose body broke off
290
+ * @throws {Err.GatewayUnexpectedResponseError} a redirect (`redirect-refused`)
291
+ * @throws {Err.GatewayConfigError} the configured gateway URL or the path is unusable
292
+ * @lastreviewed null
293
+ */
294
+ anonymous(method: string, path: string, body?: JsonValue, pin?: Partial<GatewayPin>): Promise<GatewayAnonymousResponse>;
295
+ /**
296
+ * `pin.origin`, after checking the configured gateway still is that origin: a setting changed in the middle of
297
+ * an operation is refused, so nothing an operation began on one gateway (a device code, a token) is sent to
298
+ * another.
299
+ * @lastreviewed null
300
+ */
301
+ private pinnedOrigin;
302
+ private queue;
231
303
  /**
232
304
  * The `Authorization` header an MCP client sends to the gateway's `/mcp`, from the stored token: what a
233
305
  * header helper (Claude Code's `headersHelper`, Codex's `http_headers_helper`) prints. Offline: it reads the