@bluestep-systems/b6p-core 0.9.0 → 1.0.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 (136) hide show
  1. package/README.md +264 -25
  2. package/dist/B6PCore.d.ts +7 -0
  3. package/dist/B6PCore.js +54 -1
  4. package/dist/B6PCore.js.map +1 -1
  5. package/dist/B6PUri.d.ts +6 -8
  6. package/dist/B6PUri.js +6 -8
  7. package/dist/B6PUri.js.map +1 -1
  8. package/dist/Err.d.ts +415 -0
  9. package/dist/Err.js +552 -0
  10. package/dist/Err.js.map +1 -1
  11. package/dist/auth/BearerAuthProvider.d.ts +32 -0
  12. package/dist/auth/BearerAuthProvider.js +49 -0
  13. package/dist/auth/BearerAuthProvider.js.map +1 -1
  14. package/dist/cache/OrgCache.js.map +1 -1
  15. package/dist/cache/ScriptMetaDataStore.js.map +1 -1
  16. package/dist/constants/ApiEndpoints.d.ts +1 -0
  17. package/dist/constants/ApiEndpoints.js +1 -0
  18. package/dist/constants/ApiEndpoints.js.map +1 -1
  19. package/dist/constants/AuthTypes.js.map +1 -1
  20. package/dist/constants/BlueHQ.js.map +1 -1
  21. package/dist/constants/CryptoAlgorithms.js.map +1 -1
  22. package/dist/constants/ExtensionConfig.js.map +1 -1
  23. package/dist/constants/FileExtensions.js.map +1 -1
  24. package/dist/constants/FolderNames.js.map +1 -1
  25. package/dist/constants/Gateway.d.ts +71 -0
  26. package/dist/constants/Gateway.js +79 -0
  27. package/dist/constants/Gateway.js.map +1 -0
  28. package/dist/constants/GitHubUrls.js.map +1 -1
  29. package/dist/constants/Http.js.map +1 -1
  30. package/dist/constants/MimeTypes.js.map +1 -1
  31. package/dist/constants/Numerical.js.map +1 -1
  32. package/dist/constants/OutputChannels.js.map +1 -1
  33. package/dist/constants/SettingsKeys.d.ts +5 -0
  34. package/dist/constants/SettingsKeys.js +5 -0
  35. package/dist/constants/SettingsKeys.js.map +1 -1
  36. package/dist/constants/SpecialFiles.js.map +1 -1
  37. package/dist/constants/WebDAVElements.js.map +1 -1
  38. package/dist/constants/index.d.ts +1 -0
  39. package/dist/constants/index.js +3 -1
  40. package/dist/constants/index.js.map +1 -1
  41. package/dist/data/DownstairsPathParser.js.map +1 -1
  42. package/dist/data/GlobMatcher.js.map +1 -1
  43. package/dist/data/IdUtility.js.map +1 -1
  44. package/dist/data/OrgWorker.js.map +1 -1
  45. package/dist/data/ScriptKey.js.map +1 -1
  46. package/dist/data/ScriptUrlParser.js.map +1 -1
  47. package/dist/data/ServerVersion.d.ts +76 -0
  48. package/dist/data/ServerVersion.js +111 -0
  49. package/dist/data/ServerVersion.js.map +1 -0
  50. package/dist/data/index.d.ts +2 -0
  51. package/dist/data/index.js +7 -1
  52. package/dist/data/index.js.map +1 -1
  53. package/dist/gateway/GatewayClient.d.ts +147 -0
  54. package/dist/gateway/GatewayClient.js +395 -0
  55. package/dist/gateway/GatewayClient.js.map +1 -0
  56. package/dist/gateway/GatewayContext.d.ts +43 -0
  57. package/dist/gateway/GatewayContext.js +3 -0
  58. package/dist/gateway/GatewayContext.js.map +1 -0
  59. package/dist/gateway/GatewayGit.d.ts +291 -0
  60. package/dist/gateway/GatewayGit.js +731 -0
  61. package/dist/gateway/GatewayGit.js.map +1 -0
  62. package/dist/gateway/GatewayKb.d.ts +173 -0
  63. package/dist/gateway/GatewayKb.js +354 -0
  64. package/dist/gateway/GatewayKb.js.map +1 -0
  65. package/dist/gateway/GatewayMarketplace.d.ts +116 -0
  66. package/dist/gateway/GatewayMarketplace.js +278 -0
  67. package/dist/gateway/GatewayMarketplace.js.map +1 -0
  68. package/dist/gateway/GatewayService.d.ts +47 -0
  69. package/dist/gateway/GatewayService.js +54 -0
  70. package/dist/gateway/GatewayService.js.map +1 -0
  71. package/dist/gateway/GatewayToken.d.ts +18 -0
  72. package/dist/gateway/GatewayToken.js +43 -0
  73. package/dist/gateway/GatewayToken.js.map +1 -0
  74. package/dist/gateway/GatewayTokenService.d.ts +101 -0
  75. package/dist/gateway/GatewayTokenService.js +465 -0
  76. package/dist/gateway/GatewayTokenService.js.map +1 -0
  77. package/dist/index.d.ts +24 -9
  78. package/dist/index.js +33 -7
  79. package/dist/index.js.map +1 -1
  80. package/dist/network/HttpClient.js.map +1 -1
  81. package/dist/network/HttpClientProvider.js.map +1 -1
  82. package/dist/network/StatusCodes.js.map +1 -1
  83. package/dist/persistence/PersistablePseudoMap.js.map +1 -1
  84. package/dist/persistence/PersistenceKeys.js.map +1 -1
  85. package/dist/persistence/PrivatePersistanceMap.js.map +1 -1
  86. package/dist/persistence/PseudoMap.js.map +1 -1
  87. package/dist/persistence/PublicPersistanceMap.js.map +1 -1
  88. package/dist/persistence/Serializable.js.map +1 -1
  89. package/dist/persistence/SharedFilePersistence.d.ts +22 -0
  90. package/dist/persistence/SharedFilePersistence.js +65 -14
  91. package/dist/persistence/SharedFilePersistence.js.map +1 -1
  92. package/dist/persistence/TypedMap.js.map +1 -1
  93. package/dist/persistence/TypedPersistable.js.map +1 -1
  94. package/dist/persistence/TypedPrivatePersistable.js.map +1 -1
  95. package/dist/persistence/dirLockdown.js.map +1 -1
  96. package/dist/providers.d.ts +36 -19
  97. package/dist/script/GitIdentity.js.map +1 -1
  98. package/dist/script/GitSync.d.ts +78 -11
  99. package/dist/script/GitSync.js +84 -17
  100. package/dist/script/GitSync.js.map +1 -1
  101. package/dist/script/ScriptContext.d.ts +1 -8
  102. package/dist/script/ScriptFactory.d.ts +1 -2
  103. package/dist/script/ScriptFactory.js +1 -2
  104. package/dist/script/ScriptFactory.js.map +1 -1
  105. package/dist/script/ScriptFile.js.map +1 -1
  106. package/dist/script/ScriptFolder.js.map +1 -1
  107. package/dist/script/ScriptNode.js.map +1 -1
  108. package/dist/script/ScriptRoot.d.ts +0 -63
  109. package/dist/script/ScriptRoot.js +0 -178
  110. package/dist/script/ScriptRoot.js.map +1 -1
  111. package/dist/script/ScriptService.d.ts +45 -11
  112. package/dist/script/ScriptService.js +44 -6
  113. package/dist/script/ScriptService.js.map +1 -1
  114. package/dist/script/ServerCompile.d.ts +35 -0
  115. package/dist/script/ServerCompile.js +40 -0
  116. package/dist/script/ServerCompile.js.map +1 -0
  117. package/dist/script/TsConfig.d.ts +2 -2
  118. package/dist/script/TsConfig.js +3 -3
  119. package/dist/script/TsConfig.js.map +1 -1
  120. package/dist/script/push.d.ts +117 -77
  121. package/dist/script/push.js +151 -170
  122. package/dist/script/push.js.map +1 -1
  123. package/dist/session/SessionManager.js.map +1 -1
  124. package/dist/testing/FakeGateway.d.ts +280 -0
  125. package/dist/testing/FakeGateway.js +627 -0
  126. package/dist/testing/FakeGateway.js.map +1 -0
  127. package/dist/testing/MockFileSystem.js.map +1 -1
  128. package/dist/types.d.ts +332 -0
  129. package/dist/update/UpdateService.js.map +1 -1
  130. package/package.json +8 -7
  131. package/dist/script/ScriptTranspiler.d.ts +0 -183
  132. package/dist/script/ScriptTranspiler.js +0 -425
  133. package/dist/script/ScriptTranspiler.js.map +0 -1
  134. package/dist/script/TsLibResolver.d.ts +0 -60
  135. package/dist/script/TsLibResolver.js +0 -134
  136. package/dist/script/TsLibResolver.js.map +0 -1
@@ -0,0 +1,280 @@
1
+ import * as http from "node:http";
2
+ import type { GatewayErrorBody, GatewayKnowledgeBase, GatewayMarketplaceRepo } from "../types";
3
+ /**
4
+ * What the gateway answers in place of a rotation's real answer, after acting: a status, or a
5
+ * dropped connection.
6
+ * @lastreviewed null
7
+ */
8
+ export type FakeGatewayLostAnswer = {
9
+ status: 502 | 503 | 504;
10
+ } | "drop";
11
+ /**
12
+ * Metadata for a token granted with {@link FakeGateway.grantToken}. Everything is optional.
13
+ * @lastreviewed null
14
+ */
15
+ export interface FakeGatewayTokenOptions {
16
+ /**
17
+ * Defaults to `tok_<n>`.
18
+ * @lastreviewed null
19
+ */
20
+ id?: string;
21
+ /**
22
+ * Defaults to `token-<n>`.
23
+ * @lastreviewed null
24
+ */
25
+ alias?: string;
26
+ /**
27
+ * The global user who owns it; the token routes only show a user their own. Defaults to `"user"`.
28
+ * @lastreviewed null
29
+ */
30
+ owner?: string;
31
+ /**
32
+ * ISO 8601; defaults to now. `null` is a token minted before the gateway recorded creation times.
33
+ * @lastreviewed null
34
+ */
35
+ createdAt?: string | null;
36
+ /**
37
+ * ISO 8601 or `null` (never expires); defaults to 90 days after `createdAt`.
38
+ * @lastreviewed null
39
+ */
40
+ expiresAt?: string | null;
41
+ }
42
+ /**
43
+ * A token the {@link FakeGateway} accepts, secret included, as {@link FakeGateway.issuedTokens}
44
+ * reports it for assertions.
45
+ * @lastreviewed null
46
+ */
47
+ export interface FakeGatewayToken {
48
+ secret: string;
49
+ id: string;
50
+ alias: string;
51
+ owner: string;
52
+ scopes: string[];
53
+ createdAt: string | null;
54
+ expiresAt: string | null;
55
+ lastUsedAt: string | null;
56
+ }
57
+ /**
58
+ * One request the {@link FakeGateway} received, as recorded for assertions.
59
+ * @lastreviewed null
60
+ */
61
+ export interface FakeGatewayRequest {
62
+ method: string;
63
+ /**
64
+ * Path without the query string.
65
+ * @lastreviewed null
66
+ */
67
+ path: string;
68
+ query: Record<string, string>;
69
+ /**
70
+ * The raw `Authorization` header, if any.
71
+ * @lastreviewed null
72
+ */
73
+ authorization: string | undefined;
74
+ /**
75
+ * The request body (always `""` for a custom {@link FakeGatewayRoute}, whose body is left unread).
76
+ * @lastreviewed null
77
+ */
78
+ body: string;
79
+ /**
80
+ * The raw `Idempotency-Key` header, if any.
81
+ * @lastreviewed null
82
+ */
83
+ idempotencyKey: string | undefined;
84
+ }
85
+ /**
86
+ * A canned failure for the next request, served instead of the normal answer.
87
+ * @lastreviewed null
88
+ */
89
+ export interface FakeGatewayFailure {
90
+ status: number;
91
+ /**
92
+ * A contract error body (sent as JSON), a raw string, or nothing.
93
+ * @lastreviewed null
94
+ */
95
+ body?: GatewayErrorBody | string;
96
+ /**
97
+ * Serve this failure to the next request with this HTTP method rather than the very next
98
+ * request, leaving requests of other methods alone. Lets a spec fail a `POST` that a `GET`
99
+ * (the token list) precedes.
100
+ * @lastreviewed null
101
+ */
102
+ method?: string;
103
+ }
104
+ /**
105
+ * An extra route, checked before the built-in REST routes. The git layer's specs mount the smart
106
+ * HTTP endpoints here. The token is checked first (Bearer, or Basic with the token as password, as
107
+ * the contract allows on git routes) and, when `scope` is given, that scope too; the handler only
108
+ * sees authorised requests. Its body stream is left unread for the handler.
109
+ * @lastreviewed null
110
+ */
111
+ export interface FakeGatewayRoute {
112
+ method: string;
113
+ /**
114
+ * Matched against the start of the request path.
115
+ * @lastreviewed null
116
+ */
117
+ prefix: string;
118
+ scope?: string;
119
+ handler(req: http.IncomingMessage, res: http.ServerResponse): void | Promise<void>;
120
+ }
121
+ /**
122
+ * An in-process gateway on `127.0.0.1` (an ephemeral port) answering the b6p gateway contract's
123
+ * REST shapes and error codes, for specs in this package and its consumers. It is a real HTTP
124
+ * server rather than an injected fetch so that the same instance can also serve git smart HTTP
125
+ * (via {@link route}) to a git client that brings its own HTTP stack.
126
+ *
127
+ * Built in: `GET /api/v1/knowledge-bases` (scope `kb:read`, `?scope=` and `?tenant=` filters),
128
+ * `GET /api/v1/registry/repos` (scope `registry:read`), the self-service token routes
129
+ * (`GET`/`POST /api/v1/tokens`, `DELETE /api/v1/tokens/{id}`, `POST /api/v1/tokens/{id}/rotate`,
130
+ * scope `tokens:self`, with `scope-escalation` and `alias-taken`), and `404 not-found` for anything else.
131
+ * A rotation honours `Idempotency-Key`: a retry with the same presenting token and key within 10
132
+ * minutes gets the first attempt's answer and rotates nothing (see {@link loseNextRotateAnswer}).
133
+ * Tokens are granted explicitly with their scopes; a request without one is `401 token-missing`,
134
+ * an unknown or expired one `401 token-invalid`, a missing scope `403 scope-missing` with `scope`.
135
+ * @lastreviewed null
136
+ */
137
+ export declare class FakeGateway {
138
+ private readonly server;
139
+ /**
140
+ * The gateway origin, e.g. `http://127.0.0.1:41234`, to use as `gatewayUrl`.
141
+ * @lastreviewed null
142
+ */
143
+ readonly url: string;
144
+ /**
145
+ * When `true`, a mint or rotate of a token with any scope but `mcp` is refused `403 not-permitted`
146
+ * with reason `restricted-mints-disabled` (the gateway's rollout switch).
147
+ * @lastreviewed null
148
+ */
149
+ restrictedMintsDisabled: boolean;
150
+ /**
151
+ * When `true`, a mint or rotate of a token holding `kb:rewrite` is refused `403 not-permitted` with
152
+ * reason `rewrite-not-permitted` and `scope: "kb:rewrite"` (this account may not rewrite knowledge bases).
153
+ * @lastreviewed null
154
+ */
155
+ rewriteNotPermitted: boolean;
156
+ /**
157
+ * When `true`, simulates the gateway before web-global #81's fix: a rotation retry that presents
158
+ * the token the first attempt rotated away is `401 token-invalid` instead of a replay. When
159
+ * `false` (the contract), the replay is served even though the presenting token is now revoked.
160
+ * @lastreviewed null
161
+ */
162
+ selfRotationRetryRefused: boolean;
163
+ /**
164
+ * How many rotations actually happened (a replay does not count).
165
+ * @lastreviewed null
166
+ */
167
+ rotations: number;
168
+ /**
169
+ * Every request received, in arrival order.
170
+ * @lastreviewed null
171
+ */
172
+ readonly requests: FakeGatewayRequest[];
173
+ /**
174
+ * Knowledge bases the list route returns (to every token with `kb:read`).
175
+ * @lastreviewed null
176
+ */
177
+ knowledgeBases: GatewayKnowledgeBase[];
178
+ /**
179
+ * Marketplace repos the registry route returns.
180
+ * @lastreviewed null
181
+ */
182
+ repos: GatewayMarketplaceRepo[];
183
+ /**
184
+ * Milliseconds each built-in route waits before answering (to observe concurrency).
185
+ * @lastreviewed null
186
+ */
187
+ delayMs: number;
188
+ /**
189
+ * The most requests that were ever being handled at once.
190
+ * @lastreviewed null
191
+ */
192
+ maxInFlight: number;
193
+ /**
194
+ * Every secret this fake has ever accepted, granted or minted, revoked ones included, in issue
195
+ * order. For leak checks: a spec can assert none of them reached a log line or an error.
196
+ * @lastreviewed null
197
+ */
198
+ readonly issuedSecrets: string[];
199
+ private inFlight;
200
+ private readonly tokens;
201
+ private tokenSerial;
202
+ private readonly failures;
203
+ private readonly routes;
204
+ private readonly replays;
205
+ private readonly lostAnswers;
206
+ private constructor();
207
+ /**
208
+ * Start a fake gateway on `127.0.0.1` and an ephemeral port.
209
+ * @lastreviewed null
210
+ */
211
+ static start(): Promise<FakeGateway>;
212
+ /**
213
+ * Accept `token` with these scopes (replacing any earlier grant).
214
+ * @lastreviewed null
215
+ */
216
+ grantToken(token: string, scopes: readonly string[], options?: FakeGatewayTokenOptions): void;
217
+ /**
218
+ * Every token this fake currently accepts, secrets included (granted or minted through the
219
+ * token routes).
220
+ * @lastreviewed null
221
+ */
222
+ issuedTokens(): FakeGatewayToken[];
223
+ /**
224
+ * Stop accepting `token`; it then answers `401 token-invalid`.
225
+ * @lastreviewed null
226
+ */
227
+ revokeToken(token: string): void;
228
+ /**
229
+ * Serve `failure` for the next request, before any auth check. Queued failures are served in order.
230
+ * @lastreviewed null
231
+ */
232
+ failNext(failure: FakeGatewayFailure): void;
233
+ /**
234
+ * Act on the next rotation (or replay of one) as usual, then answer `lost` instead of its result:
235
+ * the lost `503` (or dropped connection) after which a client cannot tell whether it rotated.
236
+ * Defaults to `{ status: 503 }`. Queued losses are used in order.
237
+ * @lastreviewed null
238
+ */
239
+ loseNextRotateAnswer(lost?: FakeGatewayLostAnswer): void;
240
+ /**
241
+ * Mount an extra route; see {@link FakeGatewayRoute}.
242
+ * @lastreviewed null
243
+ */
244
+ route(route: FakeGatewayRoute): void;
245
+ /**
246
+ * The git URL the real gateway would give `org`/`repo`, on this fake's origin.
247
+ * @lastreviewed null
248
+ */
249
+ gitUrl(org: string, repo: string): string;
250
+ /**
251
+ * Stop the server and drop its open connections.
252
+ * @lastreviewed null
253
+ */
254
+ stop(): Promise<void>;
255
+ private handle;
256
+ /**
257
+ * The contract's §Tokens routes, for a request already authorised with `tokens:self`.
258
+ * @lastreviewed null
259
+ */
260
+ private handleTokens;
261
+ /**
262
+ * Serve a remembered rotation to a retry before the usual auth check, so a retry presenting the
263
+ * token that rotation revoked still gets its answer (unless {@link selfRotationRetryRefused}).
264
+ * Returns `false`, having sent nothing, when the request is not such a retry.
265
+ * @lastreviewed null
266
+ */
267
+ private replayRotation;
268
+ private freshReplay;
269
+ /**
270
+ * Send a rotation's answer, or the next {@link loseNextRotateAnswer} loss in its place.
271
+ * @lastreviewed null
272
+ */
273
+ private answerRotation;
274
+ private mint;
275
+ /**
276
+ * Check the token (and scope); answer the contract's error and return `false` when it fails.
277
+ * @lastreviewed null
278
+ */
279
+ private authorize;
280
+ }