@mnmal-ai/substrate 1.0.0-alpha.1 → 1.0.0-alpha.11
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 +48 -6
- package/dist/boot-store-C5vNZJ3i.js +4065 -0
- package/dist/{runtime-metrics-DwpDJ8vz.d.ts → bridge-COu0Tg_h.d.ts} +2 -87
- package/dist/cli-BrwW4tjO.js +3144 -0
- package/dist/client.d.ts +129 -8
- package/dist/client.js +6 -5
- package/dist/{agent-token-BIboWOU0.js → env-utils-CGNazUNt.js} +31 -2
- package/dist/{errors-D4vKuwz8.d.ts → errors-BOllGhVx.d.ts} +15 -2
- package/dist/{index-D7mSOFlM.d.ts → index-Cp74OcmS.d.ts} +1 -1
- package/dist/node-version-C5FSmwJX.js +26 -0
- package/dist/pack.d.ts +2 -2
- package/dist/pack.js +1 -1
- package/dist/pg-edges-store-BLsbcXkk.js +381 -0
- package/dist/{plugin-BuQQEzL-.js → plugin-DIYm2cZE.js} +171 -18
- package/dist/proposals-bootstrap.js +6 -4
- package/dist/proposals.config.schema.json +5 -0
- package/dist/proposals.d.ts +14 -4
- package/dist/proposals.default-config.json +2 -1
- package/dist/proposals.js +2 -2
- package/dist/recall-bootstrap.js +13 -4
- package/dist/recall.config.schema.json +12 -0
- package/dist/recall.d.ts +53 -9
- package/dist/recall.js +2 -2
- package/dist/{repl-C52wyfMs.js → repl-B8gy0YM7.js} +63 -30
- package/dist/{row-ByLFE2Wx.d.ts → row-DwaDU4b-.d.ts} +58 -9
- package/dist/run-B18qtGKc.js +2012 -0
- package/dist/{plugin-t2g2wX0b.d.ts → schema-CijHRfuk.d.ts} +957 -16
- package/dist/script-C6DSa_Na.js +134 -0
- package/dist/sdk.d.ts +104 -16
- package/dist/sdk.js +5 -110
- package/dist/{src-DuopV8u7.js → src-Br6aDUti.js} +153 -20
- package/dist/{src-5hVbeiAu.js → src-D041j6GS.js} +697 -57
- package/dist/{src-YXlv_RyL.js → src-DK7VEQT6.js} +4099 -1040
- package/dist/{src-C4DzaIQZ.js → src-Dbvuel6w.js} +392 -282
- package/dist/{row-DK7lPZVe.js → src-DpPdw2oL.js} +11 -11
- package/dist/{src-zcyUofMJ.js → src-DptNGNYQ.js} +39 -15
- package/dist/src-gz4I1F29.js +5097 -0
- package/dist/substrate-admin.js +17 -781
- package/dist/substrate.js +4 -5476
- package/dist/testing.d.ts +582 -9
- package/dist/testing.js +39 -3
- package/dist/{ws-C72iVS5T.d.ts → ws-DC8OhMaV.d.ts} +2 -3
- package/package.json +22 -20
- package/dist/dataset-DOXGRz50.js +0 -1535
- package/dist/env-utils-B7SGmoeJ.js +0 -21
- package/dist/schema-g4FQLr0V.d.ts +0 -433
- package/dist/src-CjEwiKXw.js +0 -2327
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createRequire as __binCreateRequire } from 'node:module'; const require = __binCreateRequire(import.meta.url);
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { c as makeTokenProvider, i as DEFAULT_CAPABILITIES, n as trimTrailingSlashes } from "./env-utils-CGNazUNt.js";
|
|
3
|
+
import { D as isActiveAdminKeyRow, O as capabilitiesFor, T as SYSTEM_NAMESPACE } from "./src-DpPdw2oL.js";
|
|
4
|
+
import { C as parseQualifiedKey, a as buildDecodePlan, f as SchemaDriftError, i as applyDecodePlanInPlace, o as decodeWsEnvelope, p as decodeEnvelope, s as encodeWsFrame, t as WS_SUBPROTOCOL_SUBSTRATE_PACK } from "./src-Dbvuel6w.js";
|
|
4
5
|
import { signal } from "@preact/signals-core";
|
|
5
6
|
import { WebSocket } from "ws";
|
|
6
7
|
|
|
@@ -26,6 +27,7 @@ const CHECK_ADMIN = "admin-capability";
|
|
|
26
27
|
const CHECK_FLOOR = "admin-floor";
|
|
27
28
|
const CHECK_NAMESPACES = "namespaces";
|
|
28
29
|
const CHECK_DIR = "key-directory";
|
|
30
|
+
const CHECK_STORAGE = "storage";
|
|
29
31
|
/** Every check downstream of a failure, so a skip is never silent. */
|
|
30
32
|
const DOWNSTREAM = {
|
|
31
33
|
[CHECK_REACHABLE]: [
|
|
@@ -35,21 +37,28 @@ const DOWNSTREAM = {
|
|
|
35
37
|
CHECK_ADMIN,
|
|
36
38
|
CHECK_FLOOR,
|
|
37
39
|
CHECK_NAMESPACES,
|
|
38
|
-
CHECK_DIR
|
|
40
|
+
CHECK_DIR,
|
|
41
|
+
CHECK_STORAGE
|
|
39
42
|
],
|
|
40
43
|
[CHECK_CREDENTIAL]: [
|
|
41
44
|
CHECK_IDENTITY,
|
|
42
45
|
CHECK_ADMIN,
|
|
43
46
|
CHECK_FLOOR,
|
|
44
47
|
CHECK_NAMESPACES,
|
|
45
|
-
CHECK_DIR
|
|
48
|
+
CHECK_DIR,
|
|
49
|
+
CHECK_STORAGE
|
|
46
50
|
],
|
|
47
51
|
[CHECK_IDENTITY]: [
|
|
48
52
|
CHECK_ADMIN,
|
|
49
53
|
CHECK_FLOOR,
|
|
50
|
-
CHECK_DIR
|
|
54
|
+
CHECK_DIR,
|
|
55
|
+
CHECK_STORAGE
|
|
56
|
+
],
|
|
57
|
+
[CHECK_ADMIN]: [
|
|
58
|
+
CHECK_FLOOR,
|
|
59
|
+
CHECK_DIR,
|
|
60
|
+
CHECK_STORAGE
|
|
51
61
|
],
|
|
52
|
-
[CHECK_ADMIN]: [CHECK_FLOOR, CHECK_DIR],
|
|
53
62
|
[CHECK_FLOOR]: [CHECK_DIR]
|
|
54
63
|
};
|
|
55
64
|
var Checks = class {
|
|
@@ -275,7 +284,8 @@ const DIAGNOSE_CHECKS = [
|
|
|
275
284
|
CHECK_ADMIN,
|
|
276
285
|
CHECK_FLOOR,
|
|
277
286
|
CHECK_NAMESPACES,
|
|
278
|
-
CHECK_DIR
|
|
287
|
+
CHECK_DIR,
|
|
288
|
+
CHECK_STORAGE
|
|
279
289
|
];
|
|
280
290
|
/**
|
|
281
291
|
* Runs every check against `opts.baseUrl`, in dependency order. A failure
|
|
@@ -285,7 +295,7 @@ async function diagnose(opts) {
|
|
|
285
295
|
const checks = new Checks();
|
|
286
296
|
const fetchImpl = opts.fetch ?? fetch;
|
|
287
297
|
const adminCapability = opts.adminCapability ?? "admin";
|
|
288
|
-
const baseUrl = opts.baseUrl
|
|
298
|
+
const baseUrl = trimTrailingSlashes(opts.baseUrl);
|
|
289
299
|
let identityId = null;
|
|
290
300
|
let facts = {};
|
|
291
301
|
const done = () => ({
|
|
@@ -349,7 +359,8 @@ async function diagnose(opts) {
|
|
|
349
359
|
for (const name of [
|
|
350
360
|
CHECK_ADMIN,
|
|
351
361
|
CHECK_FLOOR,
|
|
352
|
-
CHECK_DIR
|
|
362
|
+
CHECK_DIR,
|
|
363
|
+
CHECK_STORAGE
|
|
353
364
|
]) checks.skip(name, "not asked — this identity was not expected to be an admin");
|
|
354
365
|
return done();
|
|
355
366
|
}
|
|
@@ -363,6 +374,16 @@ async function diagnose(opts) {
|
|
|
363
374
|
return done();
|
|
364
375
|
}
|
|
365
376
|
checks.ok(CHECK_ADMIN, `the grant confers '${adminCapability}' on ${SYSTEM_NAMESPACE} — this identity can administer`);
|
|
377
|
+
const config = await getJson(`${baseUrl}/substrate/v1/config`, fetchImpl, { authorization });
|
|
378
|
+
const storage = "error" in config ? void 0 : config.body.storage;
|
|
379
|
+
if ("error" in config || config.status !== 200) checks.skip(CHECK_STORAGE, `not asked — /substrate/v1/config ${"error" in config ? `could not be reached: ${config.error}` : `answered HTTP ${config.status}`}`);
|
|
380
|
+
else if (storage === void 0) checks.skip(CHECK_STORAGE, "not asked — the server reports no storage section (memory store)");
|
|
381
|
+
else {
|
|
382
|
+
const warnings = Array.isArray(storage.warnings) ? storage.warnings.map(String) : [];
|
|
383
|
+
const info = Array.isArray(storage.info) ? storage.info.map((l) => `\n${String(l)}`).join("") : "";
|
|
384
|
+
if (warnings.length === 0) checks.ok(CHECK_STORAGE, `${String(storage.layout)} layout, no warnings${info}`);
|
|
385
|
+
else checks.no(CHECK_STORAGE, `${String(storage.layout)} layout, ${warnings.length} warning(s):\n${warnings.join("\n")}${info}`, "Each warning names what to move or drop; indexes are never dropped automatically.");
|
|
386
|
+
}
|
|
366
387
|
const floor = await listLiveKeys(baseUrl, authorization, fetchImpl);
|
|
367
388
|
if ("error" in floor) {
|
|
368
389
|
checks.no(CHECK_FLOOR, `could not read ${SYSTEM_NAMESPACE}/Key: ${floor.error}`, "The identity is admin, so this is a route or store problem rather than a permission one — read `journalctl -u substrate-binary`.");
|
|
@@ -886,6 +907,12 @@ function reduceSubscribeRows(current, qualifiedKey, event) {
|
|
|
886
907
|
default: return current;
|
|
887
908
|
}
|
|
888
909
|
}
|
|
910
|
+
/** End reasons after which the transport resubscribes rather than finishing. */
|
|
911
|
+
const SURVIVABLE_END_REASONS = /* @__PURE__ */ new Set([
|
|
912
|
+
"server_restart",
|
|
913
|
+
"credential_expired",
|
|
914
|
+
"credential_changed"
|
|
915
|
+
]);
|
|
889
916
|
/**
|
|
890
917
|
* Fold a single-key subscription's event stream into a live row-set: yields the
|
|
891
918
|
* current `T[]` after every snapshot / add / update / remove. Completes on `end`
|
|
@@ -901,7 +928,8 @@ function reduceSubscribeRows(current, qualifiedKey, event) {
|
|
|
901
928
|
async function* watchRows(events, qualifiedKey) {
|
|
902
929
|
let rows = [];
|
|
903
930
|
for await (const event of events) {
|
|
904
|
-
if (event.kind === "end") return;
|
|
931
|
+
if (event.kind === "end" && !SURVIVABLE_END_REASONS.has(event.reason ?? "")) return;
|
|
932
|
+
if (event.kind === "end") continue;
|
|
905
933
|
if (event.kind === "error") {
|
|
906
934
|
const first = event.errors[0];
|
|
907
935
|
throw new SubscribeError(first?.message ?? "subscribe error", first?.code ?? "unknown");
|
|
@@ -1042,7 +1070,11 @@ var CacheStore = class {
|
|
|
1042
1070
|
|
|
1043
1071
|
//#endregion
|
|
1044
1072
|
//#region ../../packages/substrate-client/src/diagnostics.ts
|
|
1045
|
-
const HANDLED = /* @__PURE__ */ new Set([
|
|
1073
|
+
const HANDLED = /* @__PURE__ */ new Set([
|
|
1074
|
+
"unknownProjectionFields",
|
|
1075
|
+
"filterValidationSkipped",
|
|
1076
|
+
"plan"
|
|
1077
|
+
]);
|
|
1046
1078
|
/**
|
|
1047
1079
|
* Reduce one envelope entry to a diagnostic, or `undefined` when it holds
|
|
1048
1080
|
* nothing worth reporting — an entry present but empty, or one whose only
|
|
@@ -1108,7 +1140,7 @@ function createDefaultDiagnosticsSink() {
|
|
|
1108
1140
|
seen.add(dedupeKey);
|
|
1109
1141
|
const parts = [];
|
|
1110
1142
|
if (fields.length > 0) parts.push(`projected field(s) the type does not declare: ${fields.join(", ")}. The read succeeded — these are null on EVERY row, which is indistinguishable from a declared field that is always null. Check for a typo, or a substrate that has not restarted with your schema yet.`);
|
|
1111
|
-
if (filterValidationSkipped !== void 0) parts.push(`the where-clause was not schema-validated (${filterValidationSkipped}), so
|
|
1143
|
+
if (filterValidationSkipped !== void 0) parts.push(`the where-clause was not schema-validated (${filterValidationSkipped}), so its operators and operands were never checked against the field kinds. Results are still correct — the substrate refuses a predicate it cannot honour — but a malformed filter fails later and less clearly.`);
|
|
1112
1144
|
if (unrecognized.length > 0) parts.push(`the substrate reported diagnostic(s) this client cannot read: ${unrecognized.join(", ")}. Upgrade @mnmal-ai/substrate-client to surface them.`);
|
|
1113
1145
|
console.warn(`[substrate-client] ${opKey}: ${parts.join(" Also, ")} (Pass \`onDiagnostics\` to SubstrateClient to route this elsewhere.)`);
|
|
1114
1146
|
};
|
|
@@ -1271,7 +1303,7 @@ var HttpTransport = class {
|
|
|
1271
1303
|
#getToken;
|
|
1272
1304
|
constructor(opts) {
|
|
1273
1305
|
if (opts.token !== void 0 && opts.getToken !== void 0) throw new Error("HttpTransport: provide `token` OR `getToken`, not both");
|
|
1274
|
-
this.#endpoint = opts.endpoint
|
|
1306
|
+
this.#endpoint = trimTrailingSlashes(opts.endpoint);
|
|
1275
1307
|
this.#fetch = (opts.fetch ?? globalThis.fetch).bind(globalThis);
|
|
1276
1308
|
this.#token = opts.token;
|
|
1277
1309
|
this.#getToken = opts.getToken;
|
|
@@ -1643,6 +1675,13 @@ var WsTransport = class {
|
|
|
1643
1675
|
*/
|
|
1644
1676
|
#lastCloseCode = null;
|
|
1645
1677
|
/**
|
|
1678
|
+
* Backoff for closes that come AFTER an accepted upgrade (1013 overload,
|
|
1679
|
+
* 4001 on a lapsed credential). It lives on the transport, not the open
|
|
1680
|
+
* loop, so repeated churn grows the delay; a socket that delivers a frame
|
|
1681
|
+
* and outlives `maxDelayMs` proves healthy and resets it.
|
|
1682
|
+
*/
|
|
1683
|
+
#churn;
|
|
1684
|
+
/**
|
|
1646
1685
|
* Retry forever only once a socket has opened. Before that, a failure is
|
|
1647
1686
|
* most likely a wrong endpoint or a broken token, so it surfaces instead.
|
|
1648
1687
|
*/
|
|
@@ -1657,6 +1696,7 @@ var WsTransport = class {
|
|
|
1657
1696
|
...DEFAULT_RECONNECT,
|
|
1658
1697
|
...opts.reconnect
|
|
1659
1698
|
};
|
|
1699
|
+
this.#churn = new ReconnectScheduler(this.#reconnectOpts);
|
|
1660
1700
|
this.#encoding = opts.encoding ?? "json";
|
|
1661
1701
|
this.#overloadResubscribe = {
|
|
1662
1702
|
...DEFAULT_OVERLOAD_RESUBSCRIBE,
|
|
@@ -1715,12 +1755,21 @@ var WsTransport = class {
|
|
|
1715
1755
|
async #openLoop() {
|
|
1716
1756
|
const scheduler = new ReconnectScheduler(this.#reconnectOpts);
|
|
1717
1757
|
const wasGracefulRestart = this.#lastCloseCode === 1012;
|
|
1758
|
+
const churned = this.#lastCloseCode === 1013 || this.#lastCloseCode === 4001;
|
|
1718
1759
|
this.#lastCloseCode = null;
|
|
1760
|
+
if (churned) {
|
|
1761
|
+
await this.#churn.schedule();
|
|
1762
|
+
if (this.#destroyed) throw new NetworkError("WsTransport destroyed", null);
|
|
1763
|
+
}
|
|
1719
1764
|
let firstFailure = true;
|
|
1720
1765
|
while (true) {
|
|
1721
1766
|
if (this.#destroyed) throw new NetworkError("WsTransport destroyed", null);
|
|
1722
1767
|
try {
|
|
1723
1768
|
const mux = await this.#openOnce();
|
|
1769
|
+
if (this.#destroyed) {
|
|
1770
|
+
mux.close();
|
|
1771
|
+
throw new NetworkError("WsTransport destroyed", null);
|
|
1772
|
+
}
|
|
1724
1773
|
scheduler.reset();
|
|
1725
1774
|
this.#hasOpened = true;
|
|
1726
1775
|
this.#mux = mux;
|
|
@@ -1776,9 +1825,16 @@ var WsTransport = class {
|
|
|
1776
1825
|
rawWs.addEventListener("error", onError);
|
|
1777
1826
|
});
|
|
1778
1827
|
const mux = new MultiplexedSocket(ws, { usePack: this.#encoding === "pack" });
|
|
1828
|
+
const openedAt = Date.now();
|
|
1829
|
+
let delivered = false;
|
|
1830
|
+
ws.addEventListener("message", () => {
|
|
1831
|
+
delivered = true;
|
|
1832
|
+
}, { once: true });
|
|
1779
1833
|
ws.addEventListener("close", (ev) => {
|
|
1780
1834
|
if (this.#destroyed) return;
|
|
1781
|
-
|
|
1835
|
+
const healthy = delivered && Date.now() - openedAt >= this.#reconnectOpts.maxDelayMs;
|
|
1836
|
+
if (healthy) this.#churn.reset();
|
|
1837
|
+
if (ev.code === 4001 && !(healthy && this.#canRefreshToken())) {
|
|
1782
1838
|
if (this.#mux === mux) this.#mux = null;
|
|
1783
1839
|
this.#failActiveSubs(new NetworkError(`WS closed 4001 unauthorized by ${this.#endpoint} — bearer rejected (wrong/expired token, or none configured against an auth-gated server)`, ev));
|
|
1784
1840
|
return;
|
|
@@ -1791,6 +1847,10 @@ var WsTransport = class {
|
|
|
1791
1847
|
});
|
|
1792
1848
|
return mux;
|
|
1793
1849
|
}
|
|
1850
|
+
/** Only a provider can mint a fresh token; a fixed `token` would be refused again. */
|
|
1851
|
+
#canRefreshToken() {
|
|
1852
|
+
return this.#token === void 0 && this.#getToken !== void 0;
|
|
1853
|
+
}
|
|
1794
1854
|
/** Terminate every active sub with `err` — delivered so next() throws. */
|
|
1795
1855
|
#failActiveSubs(err) {
|
|
1796
1856
|
for (const [, sub] of this.#activeSubs) {
|
|
@@ -1925,6 +1985,7 @@ var WsTransport = class {
|
|
|
1925
1985
|
if (msg.kind === "end") {
|
|
1926
1986
|
if (msg.reason === REASON_SUBSCRIPTION_OVERLOADED && cfg.enabled && sub.retryTimer !== null) return "suppress";
|
|
1927
1987
|
if (msg.reason === REASON_SERVER_RESTART) return "survive";
|
|
1988
|
+
if ((msg.reason === "credential_expired" || msg.reason === "credential_changed") && this.#canRefreshToken()) return "survive";
|
|
1928
1989
|
return "terminal";
|
|
1929
1990
|
}
|
|
1930
1991
|
return "data";
|
|
@@ -2129,7 +2190,7 @@ var SubstrateClient = class {
|
|
|
2129
2190
|
...opts.getToken !== void 0 ? { getToken: opts.getToken } : {},
|
|
2130
2191
|
...opts.fetch !== void 0 ? { fetch: opts.fetch } : {}
|
|
2131
2192
|
});
|
|
2132
|
-
this.#wsEndpoint = `${opts.endpoint.replace(/^http/, "ws")
|
|
2193
|
+
this.#wsEndpoint = `${trimTrailingSlashes(opts.endpoint.replace(/^http/, "ws"))}/substrate/v1/ws`;
|
|
2133
2194
|
this.#wsToken = opts.token;
|
|
2134
2195
|
this.#wsGetToken = opts.getToken;
|
|
2135
2196
|
this.#wsEncoding = opts.wsEncoding ?? "json";
|
|
@@ -2272,10 +2333,19 @@ var SubstrateClient = class {
|
|
|
2272
2333
|
async #decode(raw, frame, wire) {
|
|
2273
2334
|
let env;
|
|
2274
2335
|
if (wire === "pack" && isPackMarker(raw)) {
|
|
2275
|
-
const
|
|
2276
|
-
const
|
|
2277
|
-
|
|
2278
|
-
|
|
2336
|
+
const bytes = raw.__packBytes;
|
|
2337
|
+
const decode = (expectedSchemaVersion) => decodeEnvelope(bytes, {
|
|
2338
|
+
...this.#buildDecodeCtx(frame, this.#schemaCache ?? {}),
|
|
2339
|
+
...expectedSchemaVersion !== void 0 ? { expectedSchemaVersion } : {}
|
|
2340
|
+
});
|
|
2341
|
+
try {
|
|
2342
|
+
env = decode(this.#driftCachedVersion ?? void 0);
|
|
2343
|
+
} catch (err) {
|
|
2344
|
+
if (!(err instanceof SchemaDriftError)) throw err;
|
|
2345
|
+
await this.#refetchSchema();
|
|
2346
|
+
this.#driftCachedVersion = err.envelopeSchemaVersion;
|
|
2347
|
+
env = decode();
|
|
2348
|
+
}
|
|
2279
2349
|
} else env = decodeJsonEnvelope(raw);
|
|
2280
2350
|
if (this.#driftCachedVersion === null) this.#driftCachedVersion = env.schemaVersion;
|
|
2281
2351
|
else if (this.#driftCachedVersion !== env.schemaVersion) {
|
|
@@ -2405,4 +2475,67 @@ function noRedirectFetch(fetchImpl = fetch) {
|
|
|
2405
2475
|
}
|
|
2406
2476
|
|
|
2407
2477
|
//#endregion
|
|
2408
|
-
|
|
2478
|
+
//#region ../../packages/substrate-client/src/from-env.ts
|
|
2479
|
+
/**
|
|
2480
|
+
* The capabilities a client asks for, from `SUBSTRATE_AGENT_CAPABILITIES` (csv),
|
|
2481
|
+
* defaulting to `substrate-policy`'s default.
|
|
2482
|
+
*
|
|
2483
|
+
* Not `ADMIN_CAPABILITIES`: a dataset-registry key intersects the claim, but a
|
|
2484
|
+
* file-registry key takes it verbatim, so a wider default would promote every
|
|
2485
|
+
* agent on such a deployment to admin.
|
|
2486
|
+
*/
|
|
2487
|
+
function resolveAgentCapabilities(env) {
|
|
2488
|
+
const raw = env.SUBSTRATE_AGENT_CAPABILITIES;
|
|
2489
|
+
if (raw === void 0 || raw.trim().length === 0) return DEFAULT_CAPABILITIES;
|
|
2490
|
+
const parsed = raw.split(",").map((c) => c.trim()).filter((c) => c.length > 0);
|
|
2491
|
+
return parsed.length > 0 ? parsed : DEFAULT_CAPABILITIES;
|
|
2492
|
+
}
|
|
2493
|
+
/**
|
|
2494
|
+
* Builds a client from `SUBSTRATE_URL` and `SUBSTRATE_AGENT_KEY_ID` +
|
|
2495
|
+
* `SUBSTRATE_AGENT_KEY_PATH`, signing every request as that kid.
|
|
2496
|
+
*
|
|
2497
|
+
* Redirects are refused and the token's audience is the endpoint's origin.
|
|
2498
|
+
*
|
|
2499
|
+
* @throws Error when `SUBSTRATE_URL` is unset or unsafe for a credential, when
|
|
2500
|
+
* only one of the key pair is set, when the key cannot be read, or when no
|
|
2501
|
+
* key is set and `allowAnonymous` is not.
|
|
2502
|
+
*/
|
|
2503
|
+
function createClientFromEnv(opts = {}) {
|
|
2504
|
+
const { env = process.env, allowAnonymous = false, fetch: fetchImpl, ...rest } = opts;
|
|
2505
|
+
const endpoint = trimTrailingSlashes(env.SUBSTRATE_URL ?? "");
|
|
2506
|
+
if (endpoint === "") throw new Error("SUBSTRATE_URL is required");
|
|
2507
|
+
const keyPath = env.SUBSTRATE_AGENT_KEY_PATH ?? "";
|
|
2508
|
+
const kid = env.SUBSTRATE_AGENT_KEY_ID ?? "";
|
|
2509
|
+
if (keyPath === "" !== (kid === "")) throw new Error(`SUBSTRATE_AGENT_KEY_PATH and SUBSTRATE_AGENT_KEY_ID must be set together; only ${keyPath !== "" ? "SUBSTRATE_AGENT_KEY_PATH" : "SUBSTRATE_AGENT_KEY_ID"} is set`);
|
|
2510
|
+
const base = {
|
|
2511
|
+
...rest,
|
|
2512
|
+
endpoint,
|
|
2513
|
+
fetch: noRedirectFetch(fetchImpl)
|
|
2514
|
+
};
|
|
2515
|
+
if (kid === "") {
|
|
2516
|
+
if (!allowAnonymous) throw new Error("no signing key: set SUBSTRATE_AGENT_KEY_ID and SUBSTRATE_AGENT_KEY_PATH, or pass allowAnonymous");
|
|
2517
|
+
return {
|
|
2518
|
+
client: new SubstrateClient(base),
|
|
2519
|
+
endpoint,
|
|
2520
|
+
kid: null
|
|
2521
|
+
};
|
|
2522
|
+
}
|
|
2523
|
+
const getToken = makeTokenProvider({
|
|
2524
|
+
keyPath,
|
|
2525
|
+
kid
|
|
2526
|
+
}, {
|
|
2527
|
+
capabilities: resolveAgentCapabilities(env),
|
|
2528
|
+
audience: tokenAudience(endpoint)
|
|
2529
|
+
});
|
|
2530
|
+
return {
|
|
2531
|
+
client: new SubstrateClient({
|
|
2532
|
+
...base,
|
|
2533
|
+
getToken
|
|
2534
|
+
}),
|
|
2535
|
+
endpoint,
|
|
2536
|
+
kid
|
|
2537
|
+
};
|
|
2538
|
+
}
|
|
2539
|
+
|
|
2540
|
+
//#endregion
|
|
2541
|
+
export { diagnose as C, DIAGNOSE_CHECKS as S, SKIPPABLE_STEPS as _, SubstrateClient as a, planOnboarding as b, reduceSubscribeRows as c, NetworkError as d, SubscribeError as f, ONBOARD_STEPS as g, CURRENT_MARK as h, tokenAudience as i, watchRows as l, BACKFILL_CHUNK as m, resolveAgentCapabilities as n, collectDiagnostics as o, AdminBackfillError as p, noRedirectFetch as r, createDefaultDiagnosticsSink as s, createClientFromEnv as t, AuthError as u, STEP_MARKS as v, reconcileIdentities as w, requiredOutstanding as x, currentStep as y };
|