@wasit-dev/core 0.7.0 → 0.8.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -2
- package/dist/baseline.d.ts +109 -0
- package/dist/baseline.js +353 -0
- package/dist/catalogue.js +10 -0
- package/dist/check.d.ts +57 -2
- package/dist/check.js +46 -6
- package/dist/ci-report.d.ts +74 -0
- package/dist/ci-report.js +399 -0
- package/dist/config-writer.d.ts +96 -0
- package/dist/config-writer.js +281 -0
- package/dist/config.d.ts +205 -0
- package/dist/config.js +1011 -0
- package/dist/denied-env.d.ts +33 -0
- package/dist/denied-env.js +86 -0
- package/dist/errors.d.ts +44 -1
- package/dist/errors.js +151 -2
- package/dist/guard/budget.d.ts +138 -0
- package/dist/guard/budget.js +206 -0
- package/dist/guard/ci-event.d.ts +56 -0
- package/dist/guard/ci-event.js +129 -0
- package/dist/guard/ci-mainnet.d.ts +59 -0
- package/dist/guard/ci-mainnet.js +149 -0
- package/dist/guard/horizon.d.ts +30 -0
- package/dist/guard/horizon.js +107 -0
- package/dist/guard/mainnet-payer.d.ts +66 -0
- package/dist/guard/mainnet-payer.js +92 -0
- package/dist/guard/mainnet-plan.d.ts +133 -0
- package/dist/guard/mainnet-plan.js +208 -0
- package/dist/guard/mainnet-run.d.ts +87 -0
- package/dist/guard/mainnet-run.js +225 -0
- package/dist/guard/networks.d.ts +51 -0
- package/dist/guard/networks.js +91 -0
- package/dist/guard/optin.d.ts +106 -0
- package/dist/guard/optin.js +202 -0
- package/dist/guard/rpc-identity.d.ts +45 -0
- package/dist/guard/rpc-identity.js +156 -0
- package/dist/guard/rpc-in-use.d.ts +48 -0
- package/dist/guard/rpc-in-use.js +84 -0
- package/dist/guard/run-ledger.d.ts +212 -0
- package/dist/guard/run-ledger.js +426 -0
- package/dist/guard/run-lock.d.ts +62 -0
- package/dist/guard/run-lock.js +172 -0
- package/dist/guard/signed-terms.d.ts +96 -0
- package/dist/guard/signed-terms.js +207 -0
- package/dist/index.d.ts +44 -4
- package/dist/index.js +42 -2
- package/dist/mpp/channel-commitment.d.ts +48 -2
- package/dist/mpp/channel-commitment.js +80 -4
- package/dist/mpp/channel-credential.d.ts +13 -1
- package/dist/mpp/channel-credential.js +21 -2
- package/dist/mpp/channel.d.ts +6 -0
- package/dist/mpp/channel.js +36 -3
- package/dist/mpp/charge.d.ts +33 -1
- package/dist/mpp/charge.js +90 -20
- package/dist/mpp/network.js +4 -1
- package/dist/mpp/plan.d.ts +77 -0
- package/dist/mpp/plan.js +188 -0
- package/dist/mpp/suite.d.ts +6 -0
- package/dist/mpp/suite.js +12 -3
- package/dist/report.d.ts +163 -0
- package/dist/report.js +282 -0
- package/dist/route-reader.d.ts +124 -0
- package/dist/route-reader.js +349 -0
- package/dist/sanitize.d.ts +52 -0
- package/dist/sanitize.js +106 -0
- package/dist/settlement.d.ts +14 -0
- package/dist/settlement.js +1 -1
- package/dist/verdict.d.ts +24 -0
- package/dist/verdict.js +46 -0
- package/dist/versions.d.ts +50 -0
- package/dist/versions.js +123 -0
- package/dist/wallet.d.ts +58 -1
- package/dist/wallet.js +128 -0
- package/dist/x402/chains/evm.js +3 -0
- package/dist/x402/chains/index.d.ts +8 -0
- package/dist/x402/chains/index.js +13 -2
- package/dist/x402/chains/stellar.d.ts +8 -1
- package/dist/x402/chains/stellar.js +259 -4
- package/dist/x402/chains/types.d.ts +104 -2
- package/dist/x402/plan.d.ts +184 -0
- package/dist/x402/plan.js +520 -0
- package/dist/x402/rejected-request.d.ts +156 -0
- package/dist/x402/rejected-request.js +287 -0
- package/dist/x402/requirements.d.ts +1 -0
- package/dist/x402/requirements.js +37 -4
- package/dist/x402/simulator.d.ts +86 -1
- package/dist/x402/simulator.js +863 -87
- package/package.json +1 -1
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The config writer of `wasit init` (spec C; init-skeleton-plan.md section 6,
|
|
3
|
+
* Najmi's rule of 2026-11-15: the writer takes only data that is certain).
|
|
4
|
+
*
|
|
5
|
+
* Data in, the text of a `wasit.config.json` out, checked by the same
|
|
6
|
+
* validator `wasit run` and the Action read it with, so init can never write
|
|
7
|
+
* a file they refuse. Every field is given: the writer has no defaults of its
|
|
8
|
+
* own and guesses nothing. It writes an environment only for a service its
|
|
9
|
+
* operator runs (`operatedByMe` true, literally) and, in this version, only on
|
|
10
|
+
* a test network. It never writes a secret (the validator refuses one), a
|
|
11
|
+
* header of the endpoint (a credential goes in `WASIT_HEADER_*`), the mainnet
|
|
12
|
+
* opt-in (not a config value at all) or anything that enables MPP-13.
|
|
13
|
+
*
|
|
14
|
+
* Adding to an existing file is the default: the file is read as it is, its
|
|
15
|
+
* own keys kept, and the new endpoints appended; an endpoint name it already
|
|
16
|
+
* has, or an environment of the same name with other values, is refused, never
|
|
17
|
+
* overwritten. One exception, so init can be run again on the same route (to
|
|
18
|
+
* set up its key, say): an endpoint the file already has with every value init
|
|
19
|
+
* writes the same, in an environment the file already has the same, is left as
|
|
20
|
+
* it is and counted as unchanged. `replace` starts from nothing.
|
|
21
|
+
*
|
|
22
|
+
* Pure: no file, no network, no key.
|
|
23
|
+
*/
|
|
24
|
+
import { ConfigError, validateConfig } from "./config.js";
|
|
25
|
+
import { ConfigurationError } from "./errors.js";
|
|
26
|
+
import { networkClass } from "./guard/networks.js";
|
|
27
|
+
import { sanitizeText } from "./sanitize.js";
|
|
28
|
+
/** The writer will not write this config: nothing is written. */
|
|
29
|
+
export class ConfigWriteError extends ConfigurationError {
|
|
30
|
+
constructor(message) {
|
|
31
|
+
super(message);
|
|
32
|
+
this.name = "ConfigWriteError";
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function isRecord(value) {
|
|
36
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
37
|
+
}
|
|
38
|
+
/** A name or a value for a message: one line, no control characters, bounded. */
|
|
39
|
+
function shown(value) {
|
|
40
|
+
const text = sanitizeText(String(value)).replace(/\s+/g, " ");
|
|
41
|
+
return JSON.stringify(text.length > 80 ? `${text.slice(0, 77)}...` : text);
|
|
42
|
+
}
|
|
43
|
+
function rawEnvironment(environment) {
|
|
44
|
+
return {
|
|
45
|
+
baseUrl: environment.baseUrl,
|
|
46
|
+
network: environment.network,
|
|
47
|
+
operatedByMe: environment.operatedByMe,
|
|
48
|
+
...(environment.pinned === undefined ? {} : { pinned: { payTo: environment.pinned.payTo, asset: environment.pinned.asset } }),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function rawEndpoint(endpoint) {
|
|
52
|
+
const reject = endpoint.reject;
|
|
53
|
+
return {
|
|
54
|
+
name: endpoint.name,
|
|
55
|
+
protocol: endpoint.protocol,
|
|
56
|
+
path: endpoint.path,
|
|
57
|
+
method: endpoint.method,
|
|
58
|
+
...(endpoint.body === undefined ? {} : { body: endpoint.body }),
|
|
59
|
+
...(reject === undefined
|
|
60
|
+
? {}
|
|
61
|
+
: {
|
|
62
|
+
reject: {
|
|
63
|
+
...(reject.method === undefined ? {} : { method: reject.method }),
|
|
64
|
+
...(reject.headers === undefined ? {} : { headers: { ...reject.headers } }),
|
|
65
|
+
...(reject.body === undefined ? {} : { body: reject.body }),
|
|
66
|
+
...(reject.note === undefined ? {} : { note: reject.note }),
|
|
67
|
+
},
|
|
68
|
+
}),
|
|
69
|
+
...(endpoint.channel === undefined ? {} : { channel: endpoint.channel }),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function rawService(service) {
|
|
73
|
+
return { start: service.start, ready: { url: service.ready.url, timeoutSeconds: service.ready.timeoutSeconds } };
|
|
74
|
+
}
|
|
75
|
+
/** The rules on the data itself, before any file is looked at. */
|
|
76
|
+
function assertCertain(input) {
|
|
77
|
+
const { environment, endpoints } = input;
|
|
78
|
+
if (environment.operatedByMe !== true) {
|
|
79
|
+
throw new ConfigWriteError("init writes an environment only for a service you operate (operatedByMe true): Wasit tests only services " +
|
|
80
|
+
"their operator runs. Nothing was written.");
|
|
81
|
+
}
|
|
82
|
+
const kind = networkClass(environment.network);
|
|
83
|
+
if (kind !== "test") {
|
|
84
|
+
throw new ConfigWriteError(kind === "mainnet-optin"
|
|
85
|
+
? `${shown(environment.network)} is Stellar mainnet: init writes test networks only in this version. Nothing was written.`
|
|
86
|
+
: `${shown(environment.network)} is not on Wasit's list of test networks, so init does not write it. Nothing was written.`);
|
|
87
|
+
}
|
|
88
|
+
if (endpoints.length === 0)
|
|
89
|
+
throw new ConfigWriteError("init writes at least one endpoint. Nothing was written.");
|
|
90
|
+
const names = new Set();
|
|
91
|
+
for (const endpoint of endpoints) {
|
|
92
|
+
if (names.has(endpoint.name)) {
|
|
93
|
+
throw new ConfigWriteError(`The endpoint name ${shown(endpoint.name)} is given twice. Nothing was written.`);
|
|
94
|
+
}
|
|
95
|
+
names.add(endpoint.name);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/** The existing file's JSON, valid as a config, or why init leaves it as it is. */
|
|
99
|
+
function existingConfig(text) {
|
|
100
|
+
const source = text.charCodeAt(0) === 0xfeff ? text.slice(1) : text;
|
|
101
|
+
let raw;
|
|
102
|
+
try {
|
|
103
|
+
raw = JSON.parse(source);
|
|
104
|
+
validateConfig(raw);
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
const why = error instanceof ConfigError ? error.message : "it is not valid JSON";
|
|
108
|
+
throw new ConfigWriteError(`The config already there is not valid, so init does not change it (${sanitizeText(why).replace(/\s+/g, " ")}). ` +
|
|
109
|
+
`Fix it, or replace it (--force).`);
|
|
110
|
+
}
|
|
111
|
+
return raw;
|
|
112
|
+
}
|
|
113
|
+
/** Whether the file's environment is the one being written: the same URL, network, operator and pin. */
|
|
114
|
+
function sameEnvironment(existing, environment) {
|
|
115
|
+
if (!isRecord(existing))
|
|
116
|
+
return false;
|
|
117
|
+
const network = existing["network"] ?? "stellar:testnet";
|
|
118
|
+
const pinned = existing["pinned"];
|
|
119
|
+
const pinSame = environment.pinned === undefined
|
|
120
|
+
? pinned === undefined
|
|
121
|
+
: isRecord(pinned) && pinned["payTo"] === environment.pinned.payTo && pinned["asset"] === environment.pinned.asset;
|
|
122
|
+
return existing["baseUrl"] === environment.baseUrl && network === environment.network && existing["operatedByMe"] === true && pinSame;
|
|
123
|
+
}
|
|
124
|
+
/** Whether two JSON values are equal: objects by their keys, in any order; arrays in order. */
|
|
125
|
+
function sameJson(a, b) {
|
|
126
|
+
if (a === b)
|
|
127
|
+
return true;
|
|
128
|
+
if (Array.isArray(a) || Array.isArray(b)) {
|
|
129
|
+
return Array.isArray(a) && Array.isArray(b) && a.length === b.length && a.every((item, index) => sameJson(item, b[index]));
|
|
130
|
+
}
|
|
131
|
+
if (!isRecord(a) || !isRecord(b))
|
|
132
|
+
return false;
|
|
133
|
+
const keys = Object.keys(a);
|
|
134
|
+
return keys.length === Object.keys(b).length && keys.every((key) => Object.hasOwn(b, key) && sameJson(a[key], b[key]));
|
|
135
|
+
}
|
|
136
|
+
/** A method as the loader reads it: GET when it is left out, in capitals. */
|
|
137
|
+
function methodOf(value) {
|
|
138
|
+
const method = value ?? "GET";
|
|
139
|
+
return typeof method === "string" ? method.toUpperCase() : method;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* The values init writes of an endpoint, as the loader reads them, from the
|
|
143
|
+
* file or from what init would write. `headers` and `expect` are not among
|
|
144
|
+
* them: init never writes either (a credential goes in `WASIT_HEADER_*`, and
|
|
145
|
+
* a channel's on-chain terms are the builder's to add by hand), so the file's
|
|
146
|
+
* own are the builder's and are kept.
|
|
147
|
+
*/
|
|
148
|
+
function writtenValues(endpoint) {
|
|
149
|
+
const reject = endpoint["reject"];
|
|
150
|
+
return {
|
|
151
|
+
name: endpoint["name"],
|
|
152
|
+
protocol: endpoint["protocol"],
|
|
153
|
+
path: endpoint["path"],
|
|
154
|
+
method: methodOf(endpoint["method"]),
|
|
155
|
+
body: endpoint["body"],
|
|
156
|
+
reject: isRecord(reject) ? { ...reject, ...(reject["method"] === undefined ? {} : { method: methodOf(reject["method"]) }) } : reject,
|
|
157
|
+
channel: endpoint["channel"],
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
/** The values of an endpoint init writes that differ between the file's endpoint and the one given: their keys, in order. */
|
|
161
|
+
function endpointDifferences(existing, given) {
|
|
162
|
+
const there = writtenValues(existing);
|
|
163
|
+
const here = writtenValues(given);
|
|
164
|
+
return Object.keys(here).filter((key) => !sameJson(there[key], here[key]));
|
|
165
|
+
}
|
|
166
|
+
/** "path", "method and body", "path, method and body". */
|
|
167
|
+
function listed(words) {
|
|
168
|
+
return words.length <= 1 ? (words[0] ?? "") : `${words.slice(0, -1).join(", ")} and ${words.at(-1)}`;
|
|
169
|
+
}
|
|
170
|
+
function sameService(existing, service) {
|
|
171
|
+
if (!isRecord(existing))
|
|
172
|
+
return false;
|
|
173
|
+
const ready = existing["ready"];
|
|
174
|
+
return (existing["start"] === service.start &&
|
|
175
|
+
isRecord(ready) &&
|
|
176
|
+
ready["url"] === service.ready.url &&
|
|
177
|
+
ready["timeoutSeconds"] === service.ready.timeoutSeconds);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* The text of the config with `input` in it: a new file, or `existing` with
|
|
181
|
+
* the new endpoints appended. Checked by `validateConfig` before it is
|
|
182
|
+
* returned.
|
|
183
|
+
*
|
|
184
|
+
* @throws {ConfigWriteError} When the data, the existing file or the result is not one init writes. Nothing is to be written then.
|
|
185
|
+
*/
|
|
186
|
+
export function writeConfigText(input, options = {}) {
|
|
187
|
+
assertCertain(input);
|
|
188
|
+
const { environment } = input;
|
|
189
|
+
const endpoints = input.endpoints.map(rawEndpoint);
|
|
190
|
+
const base = options.existing !== undefined && options.replace !== true ? existingConfig(options.existing) : undefined;
|
|
191
|
+
let ordered;
|
|
192
|
+
let environmentAdded = true;
|
|
193
|
+
let serviceAdded = input.service !== undefined;
|
|
194
|
+
let appended = endpoints;
|
|
195
|
+
const unchanged = [];
|
|
196
|
+
if (base === undefined) {
|
|
197
|
+
ordered = {
|
|
198
|
+
version: 1,
|
|
199
|
+
...(input.service === undefined ? {} : { service: rawService(input.service) }),
|
|
200
|
+
defaultEnvironment: environment.name,
|
|
201
|
+
environments: { [environment.name]: rawEnvironment(environment) },
|
|
202
|
+
endpoints,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
const environments = { ...base["environments"] };
|
|
207
|
+
if (Object.hasOwn(environments, environment.name)) {
|
|
208
|
+
if (!sameEnvironment(environments[environment.name], environment)) {
|
|
209
|
+
throw new ConfigWriteError(`The config already has an environment named ${shown(environment.name)} with another URL, network, operator or ` +
|
|
210
|
+
`pin, and init does not overwrite it. Choose another environment name, or replace the file (--force).`);
|
|
211
|
+
}
|
|
212
|
+
environmentAdded = false;
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
environments[environment.name] = rawEnvironment(environment);
|
|
216
|
+
}
|
|
217
|
+
const before = base["endpoints"];
|
|
218
|
+
appended = [];
|
|
219
|
+
for (const endpoint of endpoints) {
|
|
220
|
+
const there = before.find((other) => other["name"] === endpoint["name"]);
|
|
221
|
+
if (there === undefined) {
|
|
222
|
+
appended.push(endpoint);
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
const differences = endpointDifferences(there, endpoint);
|
|
226
|
+
// The same route in the same environment: nothing to add, and nothing overwritten.
|
|
227
|
+
if (differences.length === 0 && !environmentAdded) {
|
|
228
|
+
unchanged.push(endpoint["name"]);
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
throw new ConfigWriteError(differences.length === 0
|
|
232
|
+
? `The config already has an endpoint named ${shown(endpoint["name"])}, and init does not add it again with the ` +
|
|
233
|
+
`new environment ${shown(environment.name)}. Choose another name, or replace the file (--force).`
|
|
234
|
+
: `The config already has an endpoint named ${shown(endpoint["name"])} whose ${listed(differences)} ` +
|
|
235
|
+
`${differences.length === 1 ? "differs" : "differ"}, and init does not overwrite it. Choose another name, or ` +
|
|
236
|
+
"replace the file (--force).");
|
|
237
|
+
}
|
|
238
|
+
let service = base["service"];
|
|
239
|
+
if (input.service !== undefined) {
|
|
240
|
+
if (service === undefined) {
|
|
241
|
+
service = rawService(input.service);
|
|
242
|
+
}
|
|
243
|
+
else if (!sameService(service, input.service)) {
|
|
244
|
+
throw new ConfigWriteError("The config already says how to start the service, differently, and init does not overwrite it. " +
|
|
245
|
+
"Leave the start command out, or replace the file (--force).");
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
serviceAdded = false;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
// A file with one environment and no defaultEnvironment ran that environment; with a second one it keeps doing so.
|
|
252
|
+
const previous = Object.keys(base["environments"]);
|
|
253
|
+
const defaultEnvironment = base["defaultEnvironment"] ?? (previous.length === 1 ? previous[0] : undefined);
|
|
254
|
+
ordered = {
|
|
255
|
+
...(base["$schema"] === undefined ? {} : { $schema: base["$schema"] }),
|
|
256
|
+
version: 1,
|
|
257
|
+
...(service === undefined ? {} : { service }),
|
|
258
|
+
...(defaultEnvironment === undefined ? {} : { defaultEnvironment }),
|
|
259
|
+
environments,
|
|
260
|
+
endpoints: [...before, ...appended],
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
const text = `${JSON.stringify(ordered, null, 2)}\n`;
|
|
264
|
+
try {
|
|
265
|
+
validateConfig(JSON.parse(text));
|
|
266
|
+
}
|
|
267
|
+
catch (error) {
|
|
268
|
+
if (error instanceof ConfigError) {
|
|
269
|
+
throw new ConfigWriteError(`init would write a config that wasit run does not accept, so it writes nothing:\n${error.message}`);
|
|
270
|
+
}
|
|
271
|
+
throw error;
|
|
272
|
+
}
|
|
273
|
+
return {
|
|
274
|
+
text,
|
|
275
|
+
added: appended.map((endpoint) => endpoint["name"]),
|
|
276
|
+
unchanged,
|
|
277
|
+
environmentAdded,
|
|
278
|
+
serviceAdded,
|
|
279
|
+
changed: appended.length > 0 || environmentAdded || serviceAdded,
|
|
280
|
+
};
|
|
281
|
+
}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
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 { type ProtocolId } from "./catalogue.js";
|
|
22
|
+
import { ConfigurationError } from "./errors.js";
|
|
23
|
+
import { type NetworkClass } from "./guard/networks.js";
|
|
24
|
+
/** The only version this loader reads. */
|
|
25
|
+
export declare const CONFIG_VERSION = 1;
|
|
26
|
+
/** One problem found in a config, located by the key it is about. */
|
|
27
|
+
export interface ConfigIssue {
|
|
28
|
+
/** Dotted path of the key, e.g. `endpoints[1].headers.authorization`. Empty for the file itself. */
|
|
29
|
+
readonly path: string;
|
|
30
|
+
/** What is wrong and what to do. Never contains a value from the file. */
|
|
31
|
+
readonly message: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The config cannot be used. A `ConfigurationError`: nothing is learned about
|
|
35
|
+
* any service, so it is no verdict and exits 2.
|
|
36
|
+
*/
|
|
37
|
+
export declare class ConfigError extends ConfigurationError {
|
|
38
|
+
readonly issues: readonly ConfigIssue[];
|
|
39
|
+
constructor(title: string, issues: readonly ConfigIssue[]);
|
|
40
|
+
}
|
|
41
|
+
/** A JSON value, as a request body may be. */
|
|
42
|
+
export type JsonValue = null | boolean | number | string | readonly JsonValue[] | {
|
|
43
|
+
readonly [key: string]: JsonValue;
|
|
44
|
+
};
|
|
45
|
+
export interface ReadyConfig {
|
|
46
|
+
readonly url: string;
|
|
47
|
+
readonly timeoutSeconds: number;
|
|
48
|
+
}
|
|
49
|
+
export interface ServiceConfig {
|
|
50
|
+
readonly start?: string;
|
|
51
|
+
readonly ready?: ReadyConfig;
|
|
52
|
+
}
|
|
53
|
+
export interface PinConfig {
|
|
54
|
+
readonly payTo: string;
|
|
55
|
+
readonly asset: string;
|
|
56
|
+
}
|
|
57
|
+
export interface EnvironmentConfig {
|
|
58
|
+
/** An http(s) URL with no credentials, query or fragment; no trailing slash. */
|
|
59
|
+
readonly baseUrl: string;
|
|
60
|
+
/** A CAIP-2 id. Default `stellar:testnet`. */
|
|
61
|
+
readonly network: string;
|
|
62
|
+
/** Must be true for any payment check to run on this environment. Default false. */
|
|
63
|
+
readonly operatedByMe: boolean;
|
|
64
|
+
readonly pinned?: PinConfig;
|
|
65
|
+
/** Env `WASIT_RPC_URL` wins. Only its origin is ever printed. */
|
|
66
|
+
readonly rpcUrl?: string;
|
|
67
|
+
/** A LOWER per-run cap in USD, above 0 and at most 5. */
|
|
68
|
+
readonly maxRunUsd?: number;
|
|
69
|
+
}
|
|
70
|
+
export interface RejectConfig {
|
|
71
|
+
readonly method?: string;
|
|
72
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
73
|
+
readonly body?: JsonValue;
|
|
74
|
+
readonly note?: string;
|
|
75
|
+
}
|
|
76
|
+
export interface ChannelExpectation {
|
|
77
|
+
readonly token?: string;
|
|
78
|
+
readonly from?: string;
|
|
79
|
+
readonly to?: string;
|
|
80
|
+
readonly refundWaitingPeriod?: number;
|
|
81
|
+
}
|
|
82
|
+
export interface EndpointConfig {
|
|
83
|
+
readonly name: string;
|
|
84
|
+
readonly protocol: ProtocolId;
|
|
85
|
+
/** Starts with a single `/`; joined to `baseUrl`, it keeps the origin. */
|
|
86
|
+
readonly path: string;
|
|
87
|
+
/** Upper case. Default GET. */
|
|
88
|
+
readonly method: string;
|
|
89
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
90
|
+
/** A JSON value (serialised by Wasit) or a string (sent verbatim). */
|
|
91
|
+
readonly body?: JsonValue;
|
|
92
|
+
readonly reject?: RejectConfig;
|
|
93
|
+
readonly channel?: string;
|
|
94
|
+
readonly expect?: ChannelExpectation;
|
|
95
|
+
}
|
|
96
|
+
export interface WasitConfig {
|
|
97
|
+
readonly version: 1;
|
|
98
|
+
readonly service?: ServiceConfig;
|
|
99
|
+
readonly defaultEnvironment?: string;
|
|
100
|
+
readonly environments: Readonly<Record<string, EnvironmentConfig>>;
|
|
101
|
+
readonly endpoints: readonly EndpointConfig[];
|
|
102
|
+
}
|
|
103
|
+
/** True for an http(s) URL on this machine with no credentials: the only kind a readiness wait may probe. */
|
|
104
|
+
export declare function isLoopbackUrl(url: string): boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Joins a base URL and a path, keeping the base URL's origin.
|
|
107
|
+
*
|
|
108
|
+
* The path is held to the rules above, and the result is checked to have the
|
|
109
|
+
* origin of `baseUrl`: a path that could carry a request to another host is
|
|
110
|
+
* refused, not repaired (spec A8 #5).
|
|
111
|
+
*
|
|
112
|
+
* @throws {ConfigError} For a path that could leave the origin, or a base URL that is not one.
|
|
113
|
+
*/
|
|
114
|
+
export declare function joinTarget(baseUrl: string, path: string): string;
|
|
115
|
+
/** The variable that carries the value of header `name`: upper case, `-` written as `_`. */
|
|
116
|
+
export declare function headerEnvName(name: string): string;
|
|
117
|
+
/**
|
|
118
|
+
* The headers given in the environment, by name in lower case.
|
|
119
|
+
*
|
|
120
|
+
* `WASIT_HEADER_<NAME>` carries the header `<NAME>` written in upper case with
|
|
121
|
+
* `-` as `_`. Values are secrets: they are never printed, and a refusal names
|
|
122
|
+
* the variable, not the value. A header Wasit sets itself cannot be given this
|
|
123
|
+
* way either; the credential-like names the file refuses are exactly what this
|
|
124
|
+
* is for.
|
|
125
|
+
*
|
|
126
|
+
* @throws {ConfigError} For a variable whose name or value cannot be a header.
|
|
127
|
+
*/
|
|
128
|
+
export declare function headersFromEnv(env: Readonly<Record<string, string | undefined>>): Record<string, string>;
|
|
129
|
+
/**
|
|
130
|
+
* Validates parsed JSON as a version 1 config.
|
|
131
|
+
*
|
|
132
|
+
* @throws {ConfigError} Naming every key that is wrong, never a value.
|
|
133
|
+
*/
|
|
134
|
+
export declare function validateConfig(value: unknown): WasitConfig;
|
|
135
|
+
/**
|
|
136
|
+
* Parses config text.
|
|
137
|
+
*
|
|
138
|
+
* @throws {ConfigError} For text that is not JSON (located by line and column, never quoted), or a config that is not valid.
|
|
139
|
+
*/
|
|
140
|
+
export declare function parseConfig(text: string): WasitConfig;
|
|
141
|
+
/**
|
|
142
|
+
* Reads and parses a config file.
|
|
143
|
+
*
|
|
144
|
+
* @throws {ConfigError} For a file that cannot be read, is too large, or is not a valid config.
|
|
145
|
+
*/
|
|
146
|
+
export declare function readConfigFile(path: string | URL): WasitConfig;
|
|
147
|
+
export interface RunSelection {
|
|
148
|
+
/** `--env`. Else the config's `defaultEnvironment`, else the only environment. */
|
|
149
|
+
readonly environment?: string;
|
|
150
|
+
/** `--endpoint`, by name. Else all, in the config's order. */
|
|
151
|
+
readonly endpoints?: readonly string[];
|
|
152
|
+
}
|
|
153
|
+
export interface ResolvedReject {
|
|
154
|
+
readonly method?: string;
|
|
155
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
156
|
+
readonly body?: string;
|
|
157
|
+
readonly note?: string;
|
|
158
|
+
}
|
|
159
|
+
export interface ResolvedEndpoint {
|
|
160
|
+
readonly name: string;
|
|
161
|
+
readonly protocol: ProtocolId;
|
|
162
|
+
readonly method: string;
|
|
163
|
+
readonly path: string;
|
|
164
|
+
/** `baseUrl` + `path`; always the origin of `baseUrl`. */
|
|
165
|
+
readonly url: string;
|
|
166
|
+
/** The file's headers with `WASIT_HEADER_*` over them. Values are secrets: never print this object. */
|
|
167
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
168
|
+
/** Serialised: a JSON value as JSON, a string verbatim. */
|
|
169
|
+
readonly body?: string;
|
|
170
|
+
/** Exactly what the file says; the check that uses it decides how it applies to the request. */
|
|
171
|
+
readonly reject?: ResolvedReject;
|
|
172
|
+
readonly channel?: string;
|
|
173
|
+
readonly expect?: ChannelExpectation;
|
|
174
|
+
}
|
|
175
|
+
export interface ResolvedRun {
|
|
176
|
+
readonly environment: string;
|
|
177
|
+
readonly baseUrl: string;
|
|
178
|
+
readonly network: string;
|
|
179
|
+
readonly networkClass: NetworkClass;
|
|
180
|
+
readonly operatedByMe: boolean;
|
|
181
|
+
readonly pinned?: PinConfig;
|
|
182
|
+
/** Full URL: may carry a key. Print only {@link urlOrigin} of it. */
|
|
183
|
+
readonly rpcUrl?: string;
|
|
184
|
+
readonly maxRunUsd?: number;
|
|
185
|
+
readonly service?: ServiceConfig;
|
|
186
|
+
readonly endpoints: readonly ResolvedEndpoint[];
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Turns a validated config into what a run uses.
|
|
190
|
+
*
|
|
191
|
+
* Picks the environment and endpoints, joins each path to the base URL, applies
|
|
192
|
+
* the `WASIT_HEADER_*` and `WASIT_RPC_URL` variables of `env` (injected, so a
|
|
193
|
+
* test needs no process state), and serialises bodies.
|
|
194
|
+
*
|
|
195
|
+
* @throws {ConfigError} For an environment or endpoint that does not exist, a bad variable, or a path that could leave the origin.
|
|
196
|
+
*/
|
|
197
|
+
export declare function resolveRun(config: WasitConfig, selection: RunSelection, env: Readonly<Record<string, string | undefined>>): ResolvedRun;
|
|
198
|
+
/** 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. */
|
|
199
|
+
export declare function urlOrigin(url: string): string;
|
|
200
|
+
/**
|
|
201
|
+
* A short description of a run for a terminal or a log: the environment, base
|
|
202
|
+
* URL, network, the RPC origin and the endpoints. No header value, no pin
|
|
203
|
+
* secret, no RPC path or query. Sanitised.
|
|
204
|
+
*/
|
|
205
|
+
export declare function describeRun(run: ResolvedRun): string;
|