@wasit-dev/core 0.6.0 → 0.8.0-beta.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.
Files changed (68) hide show
  1. package/README.md +12 -4
  2. package/dist/baseline.d.ts +109 -0
  3. package/dist/baseline.js +351 -0
  4. package/dist/catalogue.d.ts +10 -0
  5. package/dist/catalogue.js +69 -3
  6. package/dist/check.d.ts +78 -2
  7. package/dist/check.js +69 -10
  8. package/dist/ci-report.d.ts +74 -0
  9. package/dist/ci-report.js +391 -0
  10. package/dist/config.d.ts +205 -0
  11. package/dist/config.js +1011 -0
  12. package/dist/denied-env.d.ts +33 -0
  13. package/dist/denied-env.js +86 -0
  14. package/dist/errors.d.ts +44 -1
  15. package/dist/errors.js +151 -2
  16. package/dist/guard/budget.d.ts +135 -0
  17. package/dist/guard/budget.js +199 -0
  18. package/dist/guard/ci-event.d.ts +50 -0
  19. package/dist/guard/ci-event.js +125 -0
  20. package/dist/guard/mainnet-optin.d.ts +58 -0
  21. package/dist/guard/mainnet-optin.js +95 -0
  22. package/dist/guard/networks.d.ts +50 -0
  23. package/dist/guard/networks.js +80 -0
  24. package/dist/guard/rpc-identity.d.ts +45 -0
  25. package/dist/guard/rpc-identity.js +156 -0
  26. package/dist/guard/rpc-in-use.d.ts +48 -0
  27. package/dist/guard/rpc-in-use.js +84 -0
  28. package/dist/index.d.ts +34 -3
  29. package/dist/index.js +31 -2
  30. package/dist/mpp/channel-commitment.d.ts +48 -2
  31. package/dist/mpp/channel-commitment.js +80 -4
  32. package/dist/mpp/channel-credential.js +3 -0
  33. package/dist/mpp/channel.js +29 -0
  34. package/dist/mpp/charge.d.ts +25 -2
  35. package/dist/mpp/charge.js +100 -8
  36. package/dist/mpp/network.js +4 -1
  37. package/dist/mpp/suite.js +10 -2
  38. package/dist/report.d.ts +163 -0
  39. package/dist/report.js +282 -0
  40. package/dist/sanitize.d.ts +52 -0
  41. package/dist/sanitize.js +106 -0
  42. package/dist/settlement.d.ts +14 -0
  43. package/dist/settlement.js +1 -1
  44. package/dist/verdict.d.ts +24 -0
  45. package/dist/verdict.js +46 -0
  46. package/dist/versions.d.ts +50 -0
  47. package/dist/versions.js +123 -0
  48. package/dist/x402/chains/evm.d.ts +65 -0
  49. package/dist/x402/chains/evm.js +237 -0
  50. package/dist/x402/chains/index.d.ts +18 -0
  51. package/dist/x402/chains/index.js +28 -0
  52. package/dist/x402/chains/stellar.d.ts +38 -0
  53. package/dist/x402/chains/stellar.js +277 -0
  54. package/dist/x402/chains/svm.d.ts +69 -0
  55. package/dist/x402/chains/svm.js +333 -0
  56. package/dist/x402/chains/types.d.ts +152 -0
  57. package/dist/x402/chains/types.js +10 -0
  58. package/dist/x402/chains/wait.d.ts +36 -0
  59. package/dist/x402/chains/wait.js +42 -0
  60. package/dist/x402/plan.d.ts +82 -0
  61. package/dist/x402/plan.js +146 -0
  62. package/dist/x402/rejected-request.d.ts +146 -0
  63. package/dist/x402/rejected-request.js +269 -0
  64. package/dist/x402/requirements.d.ts +46 -0
  65. package/dist/x402/requirements.js +359 -0
  66. package/dist/x402/simulator.d.ts +74 -17
  67. package/dist/x402/simulator.js +907 -246
  68. package/package.json +11 -6
package/dist/config.js ADDED
@@ -0,0 +1,1011 @@
1
+ /**
2
+ * `wasit.config.json`, version 1: the schema and the loader.
3
+ *
4
+ * One file, read the same way by `wasit run`, the Action and `wasit init`. It
5
+ * is committed, so a pull request can change it, and every run reads it. That
6
+ * shapes the loader:
7
+ *
8
+ * - strict: an unknown key or version is an error that names the key, never a
9
+ * setting that is silently dropped;
10
+ * - closed: a secret, a secret variable name, the mainnet opt-in, a flag that
11
+ * enables MPP-13 and a per-payment cap have no place in the file, and each is
12
+ * refused with its own reason (the only cap the file may set is a LOWER
13
+ * per-run one, `maxRunUsd`, at most 5);
14
+ * - quiet: an error names the key and never the value, so a secret that was
15
+ * pasted into the file by mistake does not come back through the message;
16
+ * - bounded: a path cannot leave the origin of `baseUrl`, and a header that is
17
+ * a credential travels in an environment variable, not in the file.
18
+ *
19
+ * Pure and offline: it reads a file at most, and sends and signs nothing.
20
+ */
21
+ import { readFileSync, statSync } from "node:fs";
22
+ import { StrKey } from "@stellar/stellar-sdk";
23
+ import { PROTOCOL_IDS } from "./catalogue.js";
24
+ import { ConfigurationError } from "./errors.js";
25
+ import { networkClass } from "./guard/networks.js";
26
+ import { sanitizeText } from "./sanitize.js";
27
+ import { validateNetwork } from "./x402/requirements.js";
28
+ /** The only version this loader reads. */
29
+ export const CONFIG_VERSION = 1;
30
+ /** The most a config file may weigh. A real one is a few kilobytes. */
31
+ const MAX_CONFIG_BYTES = 256 * 1024;
32
+ /** The most a request body (or a reject variant's) may weigh once serialised. */
33
+ const MAX_BODY_BYTES = 64 * 1024;
34
+ const MAX_ENDPOINTS = 50;
35
+ const MAX_DEPTH = 32;
36
+ const MAX_ISSUES_SHOWN = 10;
37
+ /** The most the file may set a run to spend. The built-in per-run cap, which the file can only lower. */
38
+ const MAX_RUN_USD = 5;
39
+ /**
40
+ * The config cannot be used. A `ConfigurationError`: nothing is learned about
41
+ * any service, so it is no verdict and exits 2.
42
+ */
43
+ export class ConfigError extends ConfigurationError {
44
+ issues;
45
+ constructor(title, issues) {
46
+ const shown = issues
47
+ .slice(0, MAX_ISSUES_SHOWN)
48
+ .map((issue) => ` - ${issue.path === "" ? "(file)" : issue.path}: ${issue.message}`);
49
+ const more = issues.length > MAX_ISSUES_SHOWN ? [` - and ${issues.length - MAX_ISSUES_SHOWN} more`] : [];
50
+ super([title, ...shown, ...more].join("\n"));
51
+ this.name = "ConfigError";
52
+ this.issues = issues;
53
+ }
54
+ }
55
+ // ---------------------------------------------------------------------------
56
+ // Issues
57
+ class Issues {
58
+ list = [];
59
+ add(path, message) {
60
+ // A path is built from keys the file chose: sanitised, one line, bounded.
61
+ const clean = sanitizeText(path).replace(/\s+/g, " ").slice(0, 120);
62
+ this.list.push({ path: clean, message });
63
+ }
64
+ }
65
+ const TITLE = "Invalid wasit.config.json:";
66
+ function failIfAny(issues) {
67
+ if (issues.list.length > 0)
68
+ throw new ConfigError(TITLE, issues.list);
69
+ }
70
+ function at(parent, key) {
71
+ return parent === "" ? key : `${parent}.${key}`;
72
+ }
73
+ function isRecord(value) {
74
+ return typeof value === "object" && value !== null && !Array.isArray(value);
75
+ }
76
+ // ---------------------------------------------------------------------------
77
+ // Keys
78
+ /** Keys that have no place in the file, by what their name says, each with the reason. */
79
+ const FORBIDDEN_KEYS = [
80
+ {
81
+ match: /secret|privatekey|payerkey|commitment|passw|mnemonic|seed|apikey|accesskey|token|credential|signingkey|signer/,
82
+ reason: "secrets never go in this file, which is committed: give them to the run as environment variables",
83
+ },
84
+ {
85
+ match: /mainnet|optin|pubnet/,
86
+ reason: "the mainnet opt-in is never set in this file: it is a flag or an input on one run",
87
+ },
88
+ {
89
+ match: /destructive|mpp13|closechannel|allowclose/,
90
+ reason: "MPP-13 closes a channel for good and is never enabled from a file",
91
+ },
92
+ {
93
+ match: /^cap$|cap$|maxpayment|perpayment|paymentcap|paymentlimit|maxamount|spendlimit|maxspend|maxusd/,
94
+ reason: "the per-payment cap ($1) is fixed in the code and cannot be raised from a file; " +
95
+ "this file may only lower the per-run cap, with maxRunUsd",
96
+ },
97
+ ];
98
+ /** Why `key` is forbidden, if its name says so. */
99
+ function forbiddenKeyReason(key) {
100
+ const normal = key.toLowerCase().replace(/[^a-z0-9]/g, "");
101
+ return FORBIDDEN_KEYS.find((rule) => rule.match.test(normal))?.reason;
102
+ }
103
+ /** Refuses every key of `object` that is not in `allowed`, a forbidden one with its own reason. */
104
+ function checkKeys(object, allowed, path, issues) {
105
+ for (const key of Object.keys(object)) {
106
+ if (allowed.includes(key))
107
+ continue;
108
+ const reason = forbiddenKeyReason(key);
109
+ issues.add(at(path, key), reason === undefined
110
+ ? "unknown key: wasit.config.json version 1 has no such setting (a misspelt key is refused, not ignored)"
111
+ : `not allowed in this file: ${reason}`);
112
+ }
113
+ }
114
+ /** A Stellar secret key, as a value anywhere in the file. */
115
+ const STELLAR_SECRET = /S[A-Z2-7]{55}/;
116
+ /**
117
+ * Finds any string value shaped like a Stellar secret key, in the whole file,
118
+ * body and headers included. The path is reported; the value never is.
119
+ */
120
+ function scanForSecrets(value, path, depth, issues) {
121
+ if (typeof value === "string") {
122
+ if (STELLAR_SECRET.test(value)) {
123
+ issues.add(path, "contains a value shaped like a Stellar secret key; remove it from the file (and rotate the key if it is real)");
124
+ }
125
+ return;
126
+ }
127
+ if (typeof value !== "object" || value === null)
128
+ return;
129
+ if (depth > MAX_DEPTH) {
130
+ issues.add(path, `is nested more than ${MAX_DEPTH} levels deep`);
131
+ return;
132
+ }
133
+ if (Array.isArray(value)) {
134
+ value.forEach((item, index) => scanForSecrets(item, `${path}[${index}]`, depth + 1, issues));
135
+ return;
136
+ }
137
+ for (const [key, item] of Object.entries(value))
138
+ scanForSecrets(item, at(path, key), depth + 1, issues);
139
+ }
140
+ // ---------------------------------------------------------------------------
141
+ // Values
142
+ const NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
143
+ const CONTROL = /[\u0000-\u001f\u007f-\u009f]/;
144
+ const ADDRESS = /^[A-Za-z0-9]{20,128}$/;
145
+ /** The methods a request may use; the same set the checks accept. */
146
+ const HTTP_METHODS = ["GET", "HEAD", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"];
147
+ const BODYLESS_METHODS = ["GET", "HEAD"];
148
+ /** Parses an http(s) URL; the reason it is not one otherwise. Never echoes the URL. */
149
+ function readHttpUrl(value) {
150
+ if (typeof value !== "string")
151
+ return { problem: "must be a URL, written as a string" };
152
+ let url;
153
+ try {
154
+ url = new URL(value);
155
+ }
156
+ catch {
157
+ return { problem: "is not a valid absolute URL; include the scheme, e.g. http://127.0.0.1:3000" };
158
+ }
159
+ if (url.protocol !== "http:" && url.protocol !== "https:") {
160
+ return { problem: "must be an http or https URL" };
161
+ }
162
+ if (url.hostname === "")
163
+ return { problem: "has no host" };
164
+ return { url };
165
+ }
166
+ function hasCredentials(url) {
167
+ return url.username !== "" || url.password !== "";
168
+ }
169
+ function readBaseUrl(value, path, issues) {
170
+ const parsed = readHttpUrl(value);
171
+ if ("problem" in parsed) {
172
+ issues.add(path, parsed.problem);
173
+ return undefined;
174
+ }
175
+ const { url } = parsed;
176
+ if (hasCredentials(url)) {
177
+ issues.add(path, "must not carry credentials (user:password@): the URL is printed in reports");
178
+ return undefined;
179
+ }
180
+ if (url.search !== "" || url.hash !== "") {
181
+ issues.add(path, "must not carry a query or fragment: put those in an endpoint's path");
182
+ return undefined;
183
+ }
184
+ return url.origin + url.pathname.replace(/\/+$/, "");
185
+ }
186
+ /** A host that is this machine. The readiness wait probes nothing else. */
187
+ function isLoopbackHost(hostname) {
188
+ return hostname === "localhost" || hostname === "[::1]" || /^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(hostname);
189
+ }
190
+ /** True for an http(s) URL on this machine with no credentials: the only kind a readiness wait may probe. */
191
+ export function isLoopbackUrl(url) {
192
+ try {
193
+ const parsed = new URL(url);
194
+ return ((parsed.protocol === "http:" || parsed.protocol === "https:") &&
195
+ isLoopbackHost(parsed.hostname) &&
196
+ parsed.username === "" &&
197
+ parsed.password === "");
198
+ }
199
+ catch {
200
+ return false;
201
+ }
202
+ }
203
+ function readRpcUrl(value, path, issues) {
204
+ const parsed = readHttpUrl(value);
205
+ if ("problem" in parsed) {
206
+ issues.add(path, parsed.problem);
207
+ return undefined;
208
+ }
209
+ if (hasCredentials(parsed.url) || parsed.url.search !== "" || parsed.url.hash !== "") {
210
+ issues.add(path, "must not carry credentials, a query or a fragment: this file is committed, and an RPC key " +
211
+ "usually travels there. Set the full URL in the environment variable WASIT_RPC_URL instead");
212
+ return undefined;
213
+ }
214
+ return parsed.url.href;
215
+ }
216
+ function readName(value, path, what, issues) {
217
+ if (typeof value === "string" && NAME.test(value))
218
+ return value;
219
+ issues.add(path, `${what} must be 1 to 64 letters, digits, dots, underscores or hyphens, starting with a letter or digit`);
220
+ return undefined;
221
+ }
222
+ // ---------------------------------------------------------------------------
223
+ // Paths
224
+ /** Why `path` could leave the origin it is joined to, if it could. */
225
+ function pathProblem(path) {
226
+ if (typeof path !== "string")
227
+ return "must be a path, written as a string";
228
+ if (!path.startsWith("/"))
229
+ return "must start with a single / (a path on the service, not a URL or a host)";
230
+ // `//host` is a network-path reference and `/\host` is read as one by the URL parser.
231
+ if (path.startsWith("//") || path.startsWith("/\\"))
232
+ return "must start with a single /, not // or /\\";
233
+ // Tab and newline are removed by the URL parser, so `/<tab>/host` becomes `//host`; a backslash is a slash.
234
+ if (/[\\\s#\u0000-\u001f\u007f-\u009f]/.test(path)) {
235
+ return "must not contain a space, a control character, a backslash or a #";
236
+ }
237
+ return undefined;
238
+ }
239
+ /**
240
+ * Joins a base URL and a path, keeping the base URL's origin.
241
+ *
242
+ * The path is held to the rules above, and the result is checked to have the
243
+ * origin of `baseUrl`: a path that could carry a request to another host is
244
+ * refused, not repaired (spec A8 #5).
245
+ *
246
+ * @throws {ConfigError} For a path that could leave the origin, or a base URL that is not one.
247
+ */
248
+ export function joinTarget(baseUrl, path) {
249
+ const issues = new Issues();
250
+ const problem = pathProblem(path);
251
+ if (problem !== undefined)
252
+ issues.add("path", problem);
253
+ const base = readBaseUrl(baseUrl, "baseUrl", issues);
254
+ if (base === undefined || problem !== undefined)
255
+ throw new ConfigError("Cannot join the target:", issues.list);
256
+ const joined = new URL(base + path);
257
+ if (joined.origin !== new URL(base).origin) {
258
+ throw new ConfigError("Cannot join the target:", [{ path: "path", message: "leaves the origin of baseUrl" }]);
259
+ }
260
+ return joined.href;
261
+ }
262
+ // ---------------------------------------------------------------------------
263
+ // Headers
264
+ /** A header name's characters (RFC 9110 token). */
265
+ const HEADER_TOKEN = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
266
+ /** A name that carries a credential: it travels in the environment, never in a committed file. */
267
+ const CREDENTIAL_HEADER_PARTS = ["authorization", "cookie", "key", "token", "secret", "password"];
268
+ /** Headers Wasit sets itself, or the transport owns. A file or variable that sets one would change the request a check describes. */
269
+ const OWN_HEADERS = new Set([
270
+ "x-payment",
271
+ "payment-signature",
272
+ "payment-required",
273
+ "payment-response",
274
+ "host",
275
+ "content-length",
276
+ "connection",
277
+ "transfer-encoding",
278
+ ]);
279
+ const MAX_HEADER_VALUE = 1000;
280
+ /** The variable that carries the value of header `name`: upper case, `-` written as `_`. */
281
+ export function headerEnvName(name) {
282
+ return `WASIT_HEADER_${name.toUpperCase().replace(/-/g, "_")}`;
283
+ }
284
+ function readHeaders(raw, path, issues) {
285
+ if (raw === undefined)
286
+ return {};
287
+ if (!isRecord(raw)) {
288
+ issues.add(path, "must be an object of header names to string values");
289
+ return {};
290
+ }
291
+ const seen = new Set();
292
+ const headers = [];
293
+ for (const [name, value] of Object.entries(raw)) {
294
+ const here = at(path, name);
295
+ const lower = name.toLowerCase();
296
+ if (!HEADER_TOKEN.test(name)) {
297
+ issues.add(here, "is not a valid header name");
298
+ continue;
299
+ }
300
+ if (CREDENTIAL_HEADER_PARTS.some((part) => lower.includes(part))) {
301
+ issues.add(here, `a header named like a credential does not belong in a committed file: ` +
302
+ `send it with the environment variable ${headerEnvName(name)}`);
303
+ continue;
304
+ }
305
+ if (OWN_HEADERS.has(lower)) {
306
+ issues.add(here, "is a header Wasit or the transport sets itself, so it cannot be set here");
307
+ continue;
308
+ }
309
+ if (seen.has(lower)) {
310
+ issues.add(here, "is set twice (header names are not case-sensitive)");
311
+ continue;
312
+ }
313
+ seen.add(lower);
314
+ if (typeof value !== "string") {
315
+ issues.add(here, "must be a string");
316
+ }
317
+ else if (CONTROL.test(value)) {
318
+ issues.add(here, "must not contain a control character (a line break would add a header)");
319
+ }
320
+ else if (value.length > MAX_HEADER_VALUE) {
321
+ issues.add(here, `must be at most ${MAX_HEADER_VALUE} characters`);
322
+ }
323
+ else {
324
+ headers.push([name, value]);
325
+ }
326
+ }
327
+ return Object.fromEntries(headers);
328
+ }
329
+ /**
330
+ * The headers given in the environment, by name in lower case.
331
+ *
332
+ * `WASIT_HEADER_<NAME>` carries the header `<NAME>` written in upper case with
333
+ * `-` as `_`. Values are secrets: they are never printed, and a refusal names
334
+ * the variable, not the value. A header Wasit sets itself cannot be given this
335
+ * way either; the credential-like names the file refuses are exactly what this
336
+ * is for.
337
+ *
338
+ * @throws {ConfigError} For a variable whose name or value cannot be a header.
339
+ */
340
+ export function headersFromEnv(env) {
341
+ const prefix = "WASIT_HEADER_";
342
+ const headers = [];
343
+ for (const [variable, value] of Object.entries(env)) {
344
+ if (!variable.startsWith(prefix) || value === undefined || value === "")
345
+ continue;
346
+ const part = variable.slice(prefix.length);
347
+ const problem = (message) => {
348
+ throw new ConfigError("Cannot read the header variables:", [{ path: variable, message }]);
349
+ };
350
+ if (!/^[A-Z0-9][A-Z0-9_]*$/.test(part)) {
351
+ problem("after WASIT_HEADER_ use upper case letters, digits and underscores (an underscore stands for a hyphen)");
352
+ }
353
+ const name = part.toLowerCase().replace(/_/g, "-");
354
+ if (OWN_HEADERS.has(name))
355
+ problem("is a header Wasit or the transport sets itself, so it cannot be set here");
356
+ if (CONTROL.test(value))
357
+ problem("has a value with a control character (a line break would add a header)");
358
+ headers.push([name, value]);
359
+ }
360
+ return Object.fromEntries(headers);
361
+ }
362
+ // ---------------------------------------------------------------------------
363
+ // Body
364
+ function serializedBytes(body) {
365
+ return Buffer.byteLength(typeof body === "string" ? body : JSON.stringify(body), "utf-8");
366
+ }
367
+ /** A body as the wire carries it: a string verbatim, anything else as JSON. */
368
+ function serializeBody(body) {
369
+ return typeof body === "string" ? body : JSON.stringify(body);
370
+ }
371
+ function readBody(raw, method, path, issues) {
372
+ if (raw === undefined)
373
+ return undefined;
374
+ if (BODYLESS_METHODS.includes(method)) {
375
+ issues.add(path, `A request body cannot be sent with ${method}. Name the method the endpoint uses, e.g. POST`);
376
+ return undefined;
377
+ }
378
+ if (serializedBytes(raw) > MAX_BODY_BYTES) {
379
+ issues.add(path, `is larger than ${MAX_BODY_BYTES / 1024} KiB`);
380
+ return undefined;
381
+ }
382
+ return raw;
383
+ }
384
+ // ---------------------------------------------------------------------------
385
+ // Sections
386
+ function readService(raw, issues) {
387
+ if (raw === undefined)
388
+ return undefined;
389
+ if (!isRecord(raw)) {
390
+ issues.add("service", "must be an object");
391
+ return undefined;
392
+ }
393
+ checkKeys(raw, ["start", "ready"], "service", issues);
394
+ let start;
395
+ if (raw["start"] !== undefined) {
396
+ const value = raw["start"];
397
+ if (typeof value !== "string" || value.trim() === "" || value.length > 500 || CONTROL.test(value)) {
398
+ issues.add("service.start", "must be one line of at most 500 characters: the command that starts the service");
399
+ }
400
+ else {
401
+ start = value;
402
+ }
403
+ }
404
+ let ready;
405
+ if (raw["ready"] !== undefined) {
406
+ const value = raw["ready"];
407
+ if (!isRecord(value)) {
408
+ issues.add("service.ready", "must be an object with a url");
409
+ }
410
+ else {
411
+ checkKeys(value, ["url", "timeoutSeconds"], "service.ready", issues);
412
+ const parsed = readHttpUrl(value["url"]);
413
+ let url;
414
+ if ("problem" in parsed) {
415
+ issues.add("service.ready.url", parsed.problem);
416
+ }
417
+ else if (hasCredentials(parsed.url) || !isLoopbackHost(parsed.url.hostname)) {
418
+ issues.add("service.ready.url", "must be an address on this machine (localhost, 127.x.x.x or [::1]) with no credentials: " +
419
+ "the wait probes the service the run starts, nothing else");
420
+ }
421
+ else {
422
+ url = value["url"];
423
+ }
424
+ const timeout = value["timeoutSeconds"] === undefined ? 60 : value["timeoutSeconds"];
425
+ if (typeof timeout !== "number" || !Number.isInteger(timeout) || timeout < 1 || timeout > 600) {
426
+ issues.add("service.ready.timeoutSeconds", "must be a whole number of seconds from 1 to 600");
427
+ }
428
+ else if (url !== undefined) {
429
+ ready = { url, timeoutSeconds: timeout };
430
+ }
431
+ }
432
+ }
433
+ return { ...(start === undefined ? {} : { start }), ...(ready === undefined ? {} : { ready }) };
434
+ }
435
+ function readPin(raw, path, issues) {
436
+ if (!isRecord(raw)) {
437
+ issues.add(path, "must be an object with payTo and asset");
438
+ return undefined;
439
+ }
440
+ checkKeys(raw, ["payTo", "asset"], path, issues);
441
+ const fields = {};
442
+ for (const key of ["payTo", "asset"]) {
443
+ const value = raw[key];
444
+ if (typeof value !== "string" || !ADDRESS.test(value)) {
445
+ issues.add(at(path, key), "must be an address: 20 to 128 letters and digits, no spaces");
446
+ }
447
+ else {
448
+ fields[key] = value;
449
+ }
450
+ }
451
+ return fields["payTo"] !== undefined && fields["asset"] !== undefined
452
+ ? { payTo: fields["payTo"], asset: fields["asset"] }
453
+ : undefined;
454
+ }
455
+ function readEnvironment(raw, path, issues) {
456
+ if (!isRecord(raw)) {
457
+ issues.add(path, "must be an object");
458
+ return undefined;
459
+ }
460
+ checkKeys(raw, ["baseUrl", "network", "operatedByMe", "pinned", "rpcUrl", "maxRunUsd"], path, issues);
461
+ const before = issues.list.length;
462
+ const baseUrl = raw["baseUrl"] === undefined ? undefined : readBaseUrl(raw["baseUrl"], at(path, "baseUrl"), issues);
463
+ if (raw["baseUrl"] === undefined)
464
+ issues.add(at(path, "baseUrl"), "is required");
465
+ const networkRaw = raw["network"] === undefined ? "stellar:testnet" : raw["network"];
466
+ let network;
467
+ if (typeof networkRaw !== "string") {
468
+ issues.add(at(path, "network"), "must be a CAIP-2 network id, e.g. stellar:testnet");
469
+ }
470
+ else {
471
+ const verdict = validateNetwork(networkRaw);
472
+ if (verdict.valid)
473
+ network = networkRaw;
474
+ else
475
+ issues.add(at(path, "network"), `is not a usable network id. ${verdict.fix}`);
476
+ }
477
+ const operatedRaw = raw["operatedByMe"] === undefined ? false : raw["operatedByMe"];
478
+ if (typeof operatedRaw !== "boolean")
479
+ issues.add(at(path, "operatedByMe"), "must be true or false");
480
+ const pinned = raw["pinned"] === undefined ? undefined : readPin(raw["pinned"], at(path, "pinned"), issues);
481
+ const rpcUrl = raw["rpcUrl"] === undefined ? undefined : readRpcUrl(raw["rpcUrl"], at(path, "rpcUrl"), issues);
482
+ let maxRunUsd;
483
+ if (raw["maxRunUsd"] !== undefined) {
484
+ const value = raw["maxRunUsd"];
485
+ if (typeof value !== "number" || !Number.isFinite(value) || value <= 0 || value > MAX_RUN_USD) {
486
+ issues.add(at(path, "maxRunUsd"), `must be a number above 0 and at most ${MAX_RUN_USD}: this setting can only lower the per-run cap`);
487
+ }
488
+ else {
489
+ maxRunUsd = value;
490
+ }
491
+ }
492
+ if (issues.list.length > before || baseUrl === undefined || network === undefined)
493
+ return undefined;
494
+ return {
495
+ baseUrl,
496
+ network,
497
+ operatedByMe: operatedRaw,
498
+ ...(pinned === undefined ? {} : { pinned }),
499
+ ...(rpcUrl === undefined ? {} : { rpcUrl }),
500
+ ...(maxRunUsd === undefined ? {} : { maxRunUsd }),
501
+ };
502
+ }
503
+ function readReject(raw, endpointMethod, path, issues) {
504
+ if (!isRecord(raw)) {
505
+ issues.add(path, "must be an object with a method, headers or body that the service must refuse");
506
+ return undefined;
507
+ }
508
+ checkKeys(raw, ["method", "headers", "body", "note"], path, issues);
509
+ if (raw["method"] === undefined && raw["headers"] === undefined && raw["body"] === undefined) {
510
+ issues.add(path, "must change something: set a method, headers or body");
511
+ return undefined;
512
+ }
513
+ let method;
514
+ if (raw["method"] !== undefined) {
515
+ const value = typeof raw["method"] === "string" ? raw["method"].toUpperCase() : "";
516
+ if (HTTP_METHODS.includes(value))
517
+ method = value;
518
+ else
519
+ issues.add(at(path, "method"), `must be one of ${HTTP_METHODS.join(", ")}`);
520
+ }
521
+ const headers = readHeaders(raw["headers"], at(path, "headers"), issues);
522
+ const body = readBody(raw["body"], method ?? endpointMethod, at(path, "body"), issues);
523
+ let note;
524
+ if (raw["note"] !== undefined) {
525
+ if (typeof raw["note"] === "string" && raw["note"].length <= 200 && !CONTROL.test(raw["note"]))
526
+ note = raw["note"];
527
+ else
528
+ issues.add(at(path, "note"), "must be one line of at most 200 characters");
529
+ }
530
+ return {
531
+ ...(method === undefined ? {} : { method }),
532
+ headers,
533
+ ...(body === undefined ? {} : { body }),
534
+ ...(note === undefined ? {} : { note }),
535
+ };
536
+ }
537
+ function readExpectation(raw, path, issues) {
538
+ if (!isRecord(raw)) {
539
+ issues.add(path, "must be an object");
540
+ return undefined;
541
+ }
542
+ checkKeys(raw, ["token", "from", "to", "refundWaitingPeriod"], path, issues);
543
+ const expected = {};
544
+ if (raw["token"] !== undefined) {
545
+ if (typeof raw["token"] === "string" && StrKey.isValidContract(raw["token"]))
546
+ expected.token = raw["token"];
547
+ else
548
+ issues.add(at(path, "token"), "must be a Soroban contract address (C...)");
549
+ }
550
+ for (const key of ["from", "to"]) {
551
+ if (raw[key] === undefined)
552
+ continue;
553
+ const value = raw[key];
554
+ if (typeof value === "string" && StrKey.isValidEd25519PublicKey(value))
555
+ expected[key] = value;
556
+ else
557
+ issues.add(at(path, key), "must be a Stellar account address (G...)");
558
+ }
559
+ if (raw["refundWaitingPeriod"] !== undefined) {
560
+ const value = raw["refundWaitingPeriod"];
561
+ if (typeof value === "number" && Number.isInteger(value) && value > 0)
562
+ expected.refundWaitingPeriod = value;
563
+ else
564
+ issues.add(at(path, "refundWaitingPeriod"), "must be a positive whole number of ledgers");
565
+ }
566
+ return expected;
567
+ }
568
+ function readEndpoint(raw, index, taken, issues) {
569
+ const path = `endpoints[${index}]`;
570
+ if (!isRecord(raw)) {
571
+ issues.add(path, "must be an object");
572
+ return undefined;
573
+ }
574
+ checkKeys(raw, ["name", "protocol", "path", "method", "headers", "body", "reject", "channel", "expect"], path, issues);
575
+ const before = issues.list.length;
576
+ const name = readName(raw["name"], at(path, "name"), "name", issues);
577
+ if (name !== undefined) {
578
+ if (taken.has(name))
579
+ issues.add(at(path, "name"), "is already used by an earlier endpoint");
580
+ taken.add(name);
581
+ }
582
+ const protocol = raw["protocol"];
583
+ if (typeof protocol !== "string" || !PROTOCOL_IDS.includes(protocol)) {
584
+ issues.add(at(path, "protocol"), `must be one of ${PROTOCOL_IDS.slice(0, -1).join(", ")} or ${PROTOCOL_IDS.at(-1)}`);
585
+ }
586
+ const problem = pathProblem(raw["path"]);
587
+ if (problem !== undefined)
588
+ issues.add(at(path, "path"), problem);
589
+ const methodRaw = raw["method"] === undefined ? "GET" : raw["method"];
590
+ const method = typeof methodRaw === "string" ? methodRaw.toUpperCase() : "";
591
+ if (!HTTP_METHODS.includes(method))
592
+ issues.add(at(path, "method"), `must be one of ${HTTP_METHODS.join(", ")}`);
593
+ const headers = readHeaders(raw["headers"], at(path, "headers"), issues);
594
+ const body = readBody(raw["body"], method, at(path, "body"), issues);
595
+ const reject = raw["reject"] === undefined ? undefined : readReject(raw["reject"], method, at(path, "reject"), issues);
596
+ let channel;
597
+ let expect;
598
+ if (raw["channel"] !== undefined) {
599
+ if (protocol !== "mpp-channel")
600
+ issues.add(at(path, "channel"), "is only for the protocol mpp-channel");
601
+ else if (typeof raw["channel"] === "string" && StrKey.isValidContract(raw["channel"]))
602
+ channel = raw["channel"];
603
+ else
604
+ issues.add(at(path, "channel"), "must be a Soroban contract address (C...)");
605
+ }
606
+ if (raw["expect"] !== undefined) {
607
+ if (protocol !== "mpp-channel")
608
+ issues.add(at(path, "expect"), "is only for the protocol mpp-channel");
609
+ else
610
+ expect = readExpectation(raw["expect"], at(path, "expect"), issues);
611
+ }
612
+ if (issues.list.length > before || name === undefined)
613
+ return undefined;
614
+ return {
615
+ name,
616
+ protocol: protocol,
617
+ path: raw["path"],
618
+ method,
619
+ headers,
620
+ ...(body === undefined ? {} : { body }),
621
+ ...(reject === undefined ? {} : { reject }),
622
+ ...(channel === undefined ? {} : { channel }),
623
+ ...(expect === undefined ? {} : { expect }),
624
+ };
625
+ }
626
+ // ---------------------------------------------------------------------------
627
+ // The file
628
+ /**
629
+ * Validates parsed JSON as a version 1 config.
630
+ *
631
+ * @throws {ConfigError} Naming every key that is wrong, never a value.
632
+ */
633
+ export function validateConfig(value) {
634
+ const issues = new Issues();
635
+ if (!isRecord(value)) {
636
+ issues.add("", "must be a JSON object");
637
+ return failWith(issues);
638
+ }
639
+ // First: a secret anywhere. Nothing else is read, so no other message can echo it.
640
+ scanForSecrets(value, "", 0, issues);
641
+ failIfAny(issues);
642
+ checkKeys(value, ["$schema", "version", "service", "defaultEnvironment", "environments", "endpoints"], "", issues);
643
+ const version = value["version"];
644
+ if (version !== CONFIG_VERSION) {
645
+ issues.add("version", `this loader reads only version ${CONFIG_VERSION}` +
646
+ (typeof version === "number" && Number.isFinite(version) ? ` (this file says version ${version})` : " and the file must say `\"version\": 1`"));
647
+ }
648
+ if (value["$schema"] !== undefined && (typeof value["$schema"] !== "string" || value["$schema"].length > 200)) {
649
+ issues.add("$schema", "must be a string of at most 200 characters");
650
+ }
651
+ const service = readService(value["service"], issues);
652
+ const environments = [];
653
+ const environmentsRaw = value["environments"];
654
+ if (!isRecord(environmentsRaw) || Object.keys(environmentsRaw).length === 0) {
655
+ issues.add("environments", "must be an object with at least one environment");
656
+ }
657
+ else {
658
+ for (const [name, raw] of Object.entries(environmentsRaw)) {
659
+ const path = at("environments", name);
660
+ if (readName(name, path, "an environment name", issues) === undefined)
661
+ continue;
662
+ const environment = readEnvironment(raw, path, issues);
663
+ if (environment !== undefined)
664
+ environments.push([name, environment]);
665
+ }
666
+ }
667
+ let defaultEnvironment;
668
+ if (value["defaultEnvironment"] !== undefined) {
669
+ const named = value["defaultEnvironment"];
670
+ if (typeof named === "string" && isRecord(environmentsRaw) && Object.hasOwn(environmentsRaw, named)) {
671
+ defaultEnvironment = named;
672
+ }
673
+ else {
674
+ issues.add("defaultEnvironment", "is not one of the environments");
675
+ }
676
+ }
677
+ const endpoints = [];
678
+ const endpointsRaw = value["endpoints"];
679
+ if (!Array.isArray(endpointsRaw) || endpointsRaw.length === 0) {
680
+ issues.add("endpoints", "must be a list with at least one endpoint");
681
+ }
682
+ else if (endpointsRaw.length > MAX_ENDPOINTS) {
683
+ issues.add("endpoints", `must have at most ${MAX_ENDPOINTS} endpoints`);
684
+ }
685
+ else {
686
+ const taken = new Set();
687
+ endpointsRaw.forEach((raw, index) => {
688
+ const endpoint = readEndpoint(raw, index, taken, issues);
689
+ if (endpoint !== undefined)
690
+ endpoints.push(endpoint);
691
+ });
692
+ }
693
+ failIfAny(issues);
694
+ return {
695
+ version: CONFIG_VERSION,
696
+ ...(service === undefined ? {} : { service }),
697
+ ...(defaultEnvironment === undefined ? {} : { defaultEnvironment }),
698
+ environments: Object.fromEntries(environments),
699
+ endpoints,
700
+ };
701
+ }
702
+ function failWith(issues) {
703
+ throw new ConfigError(TITLE, issues.list);
704
+ }
705
+ /**
706
+ * The position of the first syntax error in `text`, if it is not JSON.
707
+ *
708
+ * V8's own message quotes the text around the error, which here could be a
709
+ * secret, so the position is found by a small scanner and the message is not
710
+ * used.
711
+ */
712
+ function jsonErrorPosition(text) {
713
+ let i = 0;
714
+ const fail = () => {
715
+ throw i;
716
+ };
717
+ const space = () => {
718
+ while (i < text.length && " \t\n\r".includes(text[i]))
719
+ i += 1;
720
+ };
721
+ const literal = (word) => {
722
+ if (!text.startsWith(word, i))
723
+ fail();
724
+ i += word.length;
725
+ };
726
+ const string = () => {
727
+ i += 1;
728
+ for (;;) {
729
+ const char = text[i];
730
+ if (char === undefined || char < " ")
731
+ fail();
732
+ if (char === '"') {
733
+ i += 1;
734
+ return;
735
+ }
736
+ if (char === "\\") {
737
+ i += 1;
738
+ const escape = text[i];
739
+ if (escape === "u") {
740
+ if (!/^[0-9a-fA-F]{4}/.test(text.slice(i + 1, i + 5)))
741
+ fail();
742
+ i += 4;
743
+ }
744
+ else if (escape === undefined || !'"\\/bfnrt'.includes(escape)) {
745
+ fail();
746
+ }
747
+ }
748
+ i += 1;
749
+ }
750
+ };
751
+ const number = /-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?/y;
752
+ const value = (depth) => {
753
+ if (depth > 256)
754
+ fail();
755
+ space();
756
+ const char = text[i];
757
+ if (char === "{") {
758
+ i += 1;
759
+ space();
760
+ if (text[i] === "}") {
761
+ i += 1;
762
+ return;
763
+ }
764
+ for (;;) {
765
+ space();
766
+ if (text[i] !== '"')
767
+ fail();
768
+ string();
769
+ space();
770
+ if (text[i] !== ":")
771
+ fail();
772
+ i += 1;
773
+ value(depth + 1);
774
+ space();
775
+ if (text[i] === ",")
776
+ i += 1;
777
+ else if (text[i] === "}") {
778
+ i += 1;
779
+ return;
780
+ }
781
+ else
782
+ fail();
783
+ }
784
+ }
785
+ else if (char === "[") {
786
+ i += 1;
787
+ space();
788
+ if (text[i] === "]") {
789
+ i += 1;
790
+ return;
791
+ }
792
+ for (;;) {
793
+ value(depth + 1);
794
+ space();
795
+ if (text[i] === ",")
796
+ i += 1;
797
+ else if (text[i] === "]") {
798
+ i += 1;
799
+ return;
800
+ }
801
+ else
802
+ fail();
803
+ }
804
+ }
805
+ else if (char === '"') {
806
+ string();
807
+ }
808
+ else if (char === "t") {
809
+ literal("true");
810
+ }
811
+ else if (char === "f") {
812
+ literal("false");
813
+ }
814
+ else if (char === "n") {
815
+ literal("null");
816
+ }
817
+ else {
818
+ number.lastIndex = i;
819
+ if (!number.test(text))
820
+ fail();
821
+ i = number.lastIndex;
822
+ }
823
+ };
824
+ try {
825
+ value(0);
826
+ space();
827
+ if (i < text.length)
828
+ fail();
829
+ }
830
+ catch (position) {
831
+ return typeof position === "number" ? position : undefined;
832
+ }
833
+ return undefined;
834
+ }
835
+ /** `line L, column C` of a position in `text`, counting from 1. */
836
+ function lineAndColumn(text, position) {
837
+ const before = text.slice(0, position);
838
+ const line = before.split("\n").length;
839
+ const column = position - (before.lastIndexOf("\n") + 1) + 1;
840
+ return `line ${line}, column ${column}`;
841
+ }
842
+ /**
843
+ * Parses config text.
844
+ *
845
+ * @throws {ConfigError} For text that is not JSON (located by line and column, never quoted), or a config that is not valid.
846
+ */
847
+ export function parseConfig(text) {
848
+ const source = text.charCodeAt(0) === 0xfeff ? text.slice(1) : text;
849
+ let value;
850
+ try {
851
+ value = JSON.parse(source);
852
+ }
853
+ catch {
854
+ const position = jsonErrorPosition(source);
855
+ throw new ConfigError(TITLE, [
856
+ { path: "", message: `is not valid JSON${position === undefined ? "" : ` (${lineAndColumn(source, position)})`}` },
857
+ ]);
858
+ }
859
+ return validateConfig(value);
860
+ }
861
+ /**
862
+ * Reads and parses a config file.
863
+ *
864
+ * @throws {ConfigError} For a file that cannot be read, is too large, or is not a valid config.
865
+ */
866
+ export function readConfigFile(path) {
867
+ const shown = sanitizeText(String(path)).replace(/\s+/g, " ").slice(0, 200);
868
+ let text;
869
+ try {
870
+ if (statSync(path).size > MAX_CONFIG_BYTES) {
871
+ throw new ConfigError(TITLE, [{ path: "", message: `${shown} is larger than ${MAX_CONFIG_BYTES / 1024} KiB` }]);
872
+ }
873
+ text = readFileSync(path, "utf-8");
874
+ }
875
+ catch (error) {
876
+ if (error instanceof ConfigError)
877
+ throw error;
878
+ const code = error.code;
879
+ throw new ConfigError(TITLE, [
880
+ { path: "", message: `cannot read ${shown}${typeof code === "string" ? ` (${code})` : ""}` },
881
+ ]);
882
+ }
883
+ return parseConfig(text);
884
+ }
885
+ function selectEnvironment(config, requested) {
886
+ const names = Object.keys(config.environments);
887
+ const list = `the environments are: ${names.join(", ")}`;
888
+ if (requested !== undefined) {
889
+ if (Object.hasOwn(config.environments, requested))
890
+ return requested;
891
+ throw new ConfigError("Cannot pick an environment:", [{ path: "--env", message: `no such environment; ${list}` }]);
892
+ }
893
+ if (config.defaultEnvironment !== undefined)
894
+ return config.defaultEnvironment;
895
+ if (names.length === 1)
896
+ return names[0];
897
+ throw new ConfigError("Cannot pick an environment:", [
898
+ { path: "--env", message: `more than one environment and no defaultEnvironment; pass --env. ${list}` },
899
+ ]);
900
+ }
901
+ function selectEndpoints(config, requested) {
902
+ if (requested === undefined || requested.length === 0)
903
+ return config.endpoints;
904
+ const known = new Set(config.endpoints.map((endpoint) => endpoint.name));
905
+ const missing = requested.filter((name) => !known.has(name));
906
+ if (missing.length > 0) {
907
+ throw new ConfigError("Cannot pick endpoints:", [
908
+ {
909
+ path: "--endpoint",
910
+ message: `no endpoint named ${missing.join(", ")}; the endpoints are: ${[...known].join(", ")}`,
911
+ },
912
+ ]);
913
+ }
914
+ const wanted = new Set(requested);
915
+ return config.endpoints.filter((endpoint) => wanted.has(endpoint.name));
916
+ }
917
+ /** Merges `over` onto `base` by header name, case-insensitively; the name keeps the case of the one that wins. */
918
+ function mergeHeaders(base, over) {
919
+ const overridden = new Set(Object.keys(over).map((name) => name.toLowerCase()));
920
+ return Object.fromEntries([
921
+ ...Object.entries(base).filter(([name]) => !overridden.has(name.toLowerCase())),
922
+ ...Object.entries(over),
923
+ ]);
924
+ }
925
+ /**
926
+ * Turns a validated config into what a run uses.
927
+ *
928
+ * Picks the environment and endpoints, joins each path to the base URL, applies
929
+ * the `WASIT_HEADER_*` and `WASIT_RPC_URL` variables of `env` (injected, so a
930
+ * test needs no process state), and serialises bodies.
931
+ *
932
+ * @throws {ConfigError} For an environment or endpoint that does not exist, a bad variable, or a path that could leave the origin.
933
+ */
934
+ export function resolveRun(config, selection, env) {
935
+ const name = selectEnvironment(config, selection.environment);
936
+ const environment = config.environments[name];
937
+ const endpoints = selectEndpoints(config, selection.endpoints);
938
+ const fromEnv = headersFromEnv(env);
939
+ let rpcUrl = environment.rpcUrl;
940
+ const override = env["WASIT_RPC_URL"];
941
+ if (override !== undefined && override !== "") {
942
+ const parsed = readHttpUrl(override);
943
+ if ("problem" in parsed) {
944
+ throw new ConfigError("Cannot read the RPC variable:", [{ path: "WASIT_RPC_URL", message: parsed.problem }]);
945
+ }
946
+ rpcUrl = override;
947
+ }
948
+ return {
949
+ environment: name,
950
+ baseUrl: environment.baseUrl,
951
+ network: environment.network,
952
+ networkClass: networkClass(environment.network),
953
+ operatedByMe: environment.operatedByMe,
954
+ ...(environment.pinned === undefined ? {} : { pinned: environment.pinned }),
955
+ ...(rpcUrl === undefined ? {} : { rpcUrl }),
956
+ ...(environment.maxRunUsd === undefined ? {} : { maxRunUsd: environment.maxRunUsd }),
957
+ ...(config.service === undefined ? {} : { service: config.service }),
958
+ endpoints: endpoints.map((endpoint) => ({
959
+ name: endpoint.name,
960
+ protocol: endpoint.protocol,
961
+ method: endpoint.method,
962
+ path: endpoint.path,
963
+ url: joinTarget(environment.baseUrl, endpoint.path),
964
+ headers: mergeHeaders(endpoint.headers, fromEnv),
965
+ ...(endpoint.body === undefined ? {} : { body: serializeBody(endpoint.body) }),
966
+ ...(endpoint.reject === undefined
967
+ ? {}
968
+ : {
969
+ reject: {
970
+ ...(endpoint.reject.method === undefined ? {} : { method: endpoint.reject.method }),
971
+ headers: endpoint.reject.headers,
972
+ ...(endpoint.reject.body === undefined ? {} : { body: serializeBody(endpoint.reject.body) }),
973
+ ...(endpoint.reject.note === undefined ? {} : { note: endpoint.reject.note }),
974
+ },
975
+ }),
976
+ ...(endpoint.channel === undefined ? {} : { channel: endpoint.channel }),
977
+ ...(endpoint.expect === undefined ? {} : { expect: endpoint.expect }),
978
+ })),
979
+ };
980
+ }
981
+ /** The origin of a URL, which is all of an RPC URL that is ever printed: a key often rides in its path or query. */
982
+ export function urlOrigin(url) {
983
+ try {
984
+ const parsed = new URL(url);
985
+ return parsed.protocol === "http:" || parsed.protocol === "https:" ? parsed.origin : "(not an http URL)";
986
+ }
987
+ catch {
988
+ return "(not a URL)";
989
+ }
990
+ }
991
+ const NETWORK_CLASS_LABEL = {
992
+ test: "test network",
993
+ "mainnet-optin": "mainnet",
994
+ unknown: "network Wasit does not know",
995
+ };
996
+ /**
997
+ * A short description of a run for a terminal or a log: the environment, base
998
+ * URL, network, the RPC origin and the endpoints. No header value, no pin
999
+ * secret, no RPC path or query. Sanitised.
1000
+ */
1001
+ export function describeRun(run) {
1002
+ const lines = [
1003
+ `Environment ${run.environment}: ${run.baseUrl}`,
1004
+ `Network: ${run.network} (${NETWORK_CLASS_LABEL[run.networkClass]})`,
1005
+ ...(run.rpcUrl === undefined ? [] : [`RPC: ${urlOrigin(run.rpcUrl)} (origin only)`]),
1006
+ ...(run.maxRunUsd === undefined ? [] : [`Per-run cap: $${run.maxRunUsd}`]),
1007
+ `Endpoints: ${run.endpoints.length}`,
1008
+ ...run.endpoints.map((endpoint) => ` ${endpoint.name} ${endpoint.protocol} ${endpoint.method} ${endpoint.path}`),
1009
+ ];
1010
+ return sanitizeText(lines.join("\n"));
1011
+ }