pinnace 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/README.md +15 -0
- package/dist/car/car-build.d.ts +26 -0
- package/dist/car/car-build.d.ts.map +1 -0
- package/dist/car/car-build.js +113 -0
- package/dist/car/car-build.js.map +1 -0
- package/dist/ci/ci-emit.d.ts +116 -0
- package/dist/ci/ci-emit.d.ts.map +1 -0
- package/dist/ci/ci-emit.js +190 -0
- package/dist/ci/ci-emit.js.map +1 -0
- package/dist/cli/bin.d.ts +3 -0
- package/dist/cli/bin.d.ts.map +1 -0
- package/dist/cli/bin.js +17 -0
- package/dist/cli/bin.js.map +1 -0
- package/dist/cli/run.d.ts +78 -0
- package/dist/cli/run.d.ts.map +1 -0
- package/dist/cli/run.js +506 -0
- package/dist/cli/run.js.map +1 -0
- package/dist/config/config-resolution.d.ts +186 -0
- package/dist/config/config-resolution.d.ts.map +1 -0
- package/dist/config/config-resolution.js +137 -0
- package/dist/config/config-resolution.js.map +1 -0
- package/dist/deploy/deploy.d.ts +121 -0
- package/dist/deploy/deploy.d.ts.map +1 -0
- package/dist/deploy/deploy.js +150 -0
- package/dist/deploy/deploy.js.map +1 -0
- package/dist/derive/ipns-key-derivation.d.ts +37 -0
- package/dist/derive/ipns-key-derivation.d.ts.map +1 -0
- package/dist/derive/ipns-key-derivation.js +130 -0
- package/dist/derive/ipns-key-derivation.js.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/node/node-commands.d.ts +115 -0
- package/dist/node/node-commands.d.ts.map +1 -0
- package/dist/node/node-commands.js +227 -0
- package/dist/node/node-commands.js.map +1 -0
- package/dist/provision/cloud-init.d.ts +137 -0
- package/dist/provision/cloud-init.d.ts.map +1 -0
- package/dist/provision/cloud-init.js +390 -0
- package/dist/provision/cloud-init.js.map +1 -0
- package/dist/publisher/key-import.d.ts +105 -0
- package/dist/publisher/key-import.d.ts.map +1 -0
- package/dist/publisher/key-import.js +76 -0
- package/dist/publisher/key-import.js.map +1 -0
- package/dist/publisher/record-sequence.d.ts +90 -0
- package/dist/publisher/record-sequence.d.ts.map +1 -0
- package/dist/publisher/record-sequence.js +250 -0
- package/dist/publisher/record-sequence.js.map +1 -0
- package/dist/rpc/kubo-rpc-client.d.ts +154 -0
- package/dist/rpc/kubo-rpc-client.d.ts.map +1 -0
- package/dist/rpc/kubo-rpc-client.js +207 -0
- package/dist/rpc/kubo-rpc-client.js.map +1 -0
- package/dist/rpc/mock-kubo.d.ts +87 -0
- package/dist/rpc/mock-kubo.d.ts.map +1 -0
- package/dist/rpc/mock-kubo.js +129 -0
- package/dist/rpc/mock-kubo.js.map +1 -0
- package/dist/site/site-management.d.ts +126 -0
- package/dist/site/site-management.d.ts.map +1 -0
- package/dist/site/site-management.js +123 -0
- package/dist/site/site-management.js.map +1 -0
- package/dist/status/status-report.d.ts +145 -0
- package/dist/status/status-report.d.ts.map +1 -0
- package/dist/status/status-report.js +192 -0
- package/dist/status/status-report.js.map +1 -0
- package/package.json +45 -2
- package/src/car/car-build.ts +135 -0
- package/src/ci/ci-emit.ts +284 -0
- package/src/cli/bin.ts +20 -0
- package/src/cli/run.ts +654 -0
- package/src/config/config-resolution.ts +264 -0
- package/src/deploy/deploy.ts +250 -0
- package/src/derive/ipns-key-derivation.ts +173 -0
- package/src/index.ts +146 -0
- package/src/node/node-commands.ts +391 -0
- package/src/provision/cloud-init.ts +551 -0
- package/src/publisher/key-import.ts +141 -0
- package/src/publisher/record-sequence.ts +336 -0
- package/src/rpc/kubo-rpc-client.ts +281 -0
- package/src/rpc/mock-kubo.ts +194 -0
- package/src/site/site-management.ts +241 -0
- package/src/status/status-report.ts +291 -0
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `status` core operation — pinnace's discoverability VERIFICATION surface
|
|
3
|
+
* (CONTEXT.md `gateway warming`; spec user story 18).
|
|
4
|
+
*
|
|
5
|
+
* For every site auto-discovered from MFS `/sites/*` (over the Kubo RPC seam) it
|
|
6
|
+
* reports FOUR fields so an operator can confirm a deploy actually landed
|
|
7
|
+
* everywhere:
|
|
8
|
+
*
|
|
9
|
+
* 1. current CID — `files/stat --hash` (via {@link discoverSites}).
|
|
10
|
+
* 2. IPNS id — from `key/list -l` IF a key of the SAME name exists
|
|
11
|
+
* (ipfs-mode sites have none).
|
|
12
|
+
* 3. network-announce — does the NETWORK announce THIS node for the CID? The
|
|
13
|
+
* external delegated-routing providers list for the
|
|
14
|
+
* CID contains this node's PeerID (`id`).
|
|
15
|
+
* 4. gateway-serves — does a COLD public gateway serve it? An HTTP
|
|
16
|
+
* range/HEAD result from a public gateway.
|
|
17
|
+
*
|
|
18
|
+
* The two checks in (3) and (4) reach OUTSIDE the node. They are INJECTABLE
|
|
19
|
+
* ({@link ProvidersLookup}, {@link GatewayProbe}) so tests run against a fake
|
|
20
|
+
* HTTP layer and never the live network; production supplies the default
|
|
21
|
+
* `fetch`-backed implementations below.
|
|
22
|
+
*
|
|
23
|
+
* Behaviour ported (NOT copied) from the reference prototype
|
|
24
|
+
* `~/searches/ipfs-hetzner/status.sh`: the delegated-routing providers lookup at
|
|
25
|
+
* `https://delegated-ipfs.dev/routing/v1/providers/<cid>` (does
|
|
26
|
+
* `.Providers[].ID` include our PeerID?) and the
|
|
27
|
+
* `https://<cid>.ipfs.dweb.link/` range-request cold-gateway probe. The shell's
|
|
28
|
+
* `jq .Providers[].ID == $PEERID` and `curl -r 0-0 -w %{http_code}` shapes
|
|
29
|
+
* become the two TS predicates here.
|
|
30
|
+
*
|
|
31
|
+
* SEAM NOTE: this module OWNS the per-site status checks; the on-box `status`
|
|
32
|
+
* verb (`../node/node-commands.ts`) consumes them via its injectable
|
|
33
|
+
* `NodeCommandOps.status` seam — {@link makeStatusOp} adapts this core into that
|
|
34
|
+
* seam. The dashboard persistence (`status.json`) is the command layer's job,
|
|
35
|
+
* not this module's: this module PRODUCES the report and stops.
|
|
36
|
+
*
|
|
37
|
+
* A failed external check is a REPORTED outcome, never a throw: a
|
|
38
|
+
* delegated-routing lookup that errors reports `announced=false` (not findable
|
|
39
|
+
* right now) and a gateway probe that errors reports `gatewayServes=false`. One
|
|
40
|
+
* cold gateway or one flaky routing endpoint must not fail the whole report.
|
|
41
|
+
*/
|
|
42
|
+
import {discoverSites, type DiscoveredSite} from '../node/node-commands.js';
|
|
43
|
+
import type {KuboRpcClient} from '../rpc/kubo-rpc-client.js';
|
|
44
|
+
import type {NodeCommandContext, NodeOpResult} from '../node/node-commands.js';
|
|
45
|
+
|
|
46
|
+
/** The delegated-routing providers endpoint (path takes the CID). */
|
|
47
|
+
const DELEGATED_ROUTING_BASE =
|
|
48
|
+
'https://delegated-ipfs.dev/routing/v1/providers';
|
|
49
|
+
|
|
50
|
+
/** The public gateway used for the cold-serve probe (`<cid>.ipfs.<host>`). */
|
|
51
|
+
const DWEB_LINK_HOST = 'ipfs.dweb.link';
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The subset of the delegated-routing `/routing/v1/providers/<cid>` JSON we
|
|
55
|
+
* read: the `Providers` array, each with an `ID` (a PeerID). Other fields are
|
|
56
|
+
* ignored.
|
|
57
|
+
*/
|
|
58
|
+
export interface ProvidersResponse {
|
|
59
|
+
Providers?: Array<{ID?: string}> | null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* An injectable delegated-routing providers lookup: given a CID, return the
|
|
64
|
+
* providers response (whose `.Providers[].ID` we scan for our PeerID). Tests
|
|
65
|
+
* inject a fake; production uses {@link defaultProvidersLookup}. Throwing is
|
|
66
|
+
* treated as "not findable" (announced=false), never propagated.
|
|
67
|
+
*/
|
|
68
|
+
export type ProvidersLookup = (cid: string) => Promise<ProvidersResponse>;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* An injectable cold-gateway probe: given a CID, return the HTTP status a
|
|
72
|
+
* public gateway responds with (a 2xx/206 means it served). Tests inject a
|
|
73
|
+
* fake; production uses {@link defaultGatewayProbe}. Throwing is treated as
|
|
74
|
+
* "did not serve" (gatewayServes=false), never propagated.
|
|
75
|
+
*/
|
|
76
|
+
export type GatewayProbe = (cid: string) => Promise<number>;
|
|
77
|
+
|
|
78
|
+
/** The status of one site: the four report fields plus its `id`. */
|
|
79
|
+
export interface SiteStatus {
|
|
80
|
+
/** The site's single `id` (its MFS entry under `/sites/`). */
|
|
81
|
+
id: string;
|
|
82
|
+
/** The current content root CID (`files/stat --hash`). */
|
|
83
|
+
cid: string;
|
|
84
|
+
/** The IPNS id, if a same-named keystore key exists (else undefined). */
|
|
85
|
+
ipns?: string;
|
|
86
|
+
/** True when the delegated-routing providers list for the CID has our PeerID. */
|
|
87
|
+
announced: boolean;
|
|
88
|
+
/** The HTTP status the cold public gateway probe returned (undefined on error). */
|
|
89
|
+
gatewayHttp?: number;
|
|
90
|
+
/** True when the gateway probe status indicates the CID was served (2xx/206). */
|
|
91
|
+
gatewayServes: boolean;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** The full status report: this node's PeerID plus a per-site status line. */
|
|
95
|
+
export interface StatusReport {
|
|
96
|
+
/** This node's PeerID (from Kubo `id`); the announce check looks for it. */
|
|
97
|
+
peerId: string;
|
|
98
|
+
/** One {@link SiteStatus} per site discovered under MFS `/sites/*`. */
|
|
99
|
+
sites: SiteStatus[];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Inputs to {@link statusReport}. */
|
|
103
|
+
export interface StatusReportInput {
|
|
104
|
+
/** The Kubo RPC client for THIS node (files/ls, files/stat, key/list, id). */
|
|
105
|
+
client: KuboRpcClient;
|
|
106
|
+
/** The MFS directory sites live under (default `/sites`). */
|
|
107
|
+
sitesDir?: string;
|
|
108
|
+
/**
|
|
109
|
+
* The delegated-routing providers lookup (injectable; defaults to the live
|
|
110
|
+
* `delegated-ipfs.dev` fetch via {@link defaultProvidersLookup}).
|
|
111
|
+
*/
|
|
112
|
+
providersLookup?: ProvidersLookup;
|
|
113
|
+
/**
|
|
114
|
+
* The cold-gateway probe (injectable; defaults to the live `dweb.link`
|
|
115
|
+
* range-request via {@link defaultGatewayProbe}).
|
|
116
|
+
*/
|
|
117
|
+
gatewayProbe?: GatewayProbe;
|
|
118
|
+
/**
|
|
119
|
+
* Pre-discovered sites (optional). When set, discovery is SKIPPED and these
|
|
120
|
+
* are used as-is — the node-command layer already walked MFS, so the adapter
|
|
121
|
+
* ({@link makeStatusOp}) passes them straight through rather than re-listing.
|
|
122
|
+
*/
|
|
123
|
+
sites?: DiscoveredSite[];
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Build the per-site status report. Discovers sites (unless supplied), reads
|
|
128
|
+
* this node's PeerID and its keystore once, then for each site runs the two
|
|
129
|
+
* external checks (through the injected/default fakes) to fill the four fields.
|
|
130
|
+
* External-check failures degrade to `false`, never throw.
|
|
131
|
+
*/
|
|
132
|
+
export async function statusReport(
|
|
133
|
+
input: StatusReportInput,
|
|
134
|
+
): Promise<StatusReport> {
|
|
135
|
+
const sitesDir = input.sitesDir ?? '/sites';
|
|
136
|
+
const providersLookup = input.providersLookup ?? defaultProvidersLookup;
|
|
137
|
+
const gatewayProbe = input.gatewayProbe ?? defaultGatewayProbe;
|
|
138
|
+
|
|
139
|
+
const sites = input.sites ?? (await discoverSites(input.client, sitesDir));
|
|
140
|
+
const peerId = await readPeerId(input.client);
|
|
141
|
+
const keys = await listKeys(input.client);
|
|
142
|
+
|
|
143
|
+
const statuses: SiteStatus[] = [];
|
|
144
|
+
for (const site of sites) {
|
|
145
|
+
const announced = await checkAnnounced(providersLookup, site.cid, peerId);
|
|
146
|
+
const gatewayHttp = await probeGateway(gatewayProbe, site.cid);
|
|
147
|
+
statuses.push({
|
|
148
|
+
id: site.id,
|
|
149
|
+
cid: site.cid,
|
|
150
|
+
ipns: keys.get(site.id),
|
|
151
|
+
announced,
|
|
152
|
+
gatewayHttp,
|
|
153
|
+
gatewayServes: gatewayHttp !== undefined && servesStatus(gatewayHttp),
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return {peerId, sites: statuses};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Adapt {@link statusReport} into a {@link NodeCommandContext} `status` op so
|
|
162
|
+
* the on-box `status` verb can inject it (its `ops.status` seam). The command
|
|
163
|
+
* layer discovers sites and passes them in; this adapter runs the four-field
|
|
164
|
+
* checks over them and flattens the result into a {@link NodeOpResult} (its
|
|
165
|
+
* per-site outcomes carry the announce + gateway outcomes too).
|
|
166
|
+
*/
|
|
167
|
+
export function makeStatusOp(
|
|
168
|
+
checks: {providersLookup?: ProvidersLookup; gatewayProbe?: GatewayProbe} = {},
|
|
169
|
+
): (ctx: NodeCommandContext, sites: DiscoveredSite[]) => Promise<NodeOpResult> {
|
|
170
|
+
return async (ctx, sites) => {
|
|
171
|
+
const report = await statusReport({
|
|
172
|
+
client: ctx.client,
|
|
173
|
+
sitesDir: ctx.sitesDir,
|
|
174
|
+
sites,
|
|
175
|
+
providersLookup: checks.providersLookup,
|
|
176
|
+
gatewayProbe: checks.gatewayProbe,
|
|
177
|
+
});
|
|
178
|
+
return {
|
|
179
|
+
sites: report.sites.map((s) => ({
|
|
180
|
+
id: s.id,
|
|
181
|
+
cid: s.cid,
|
|
182
|
+
ipns: s.ipns ?? '',
|
|
183
|
+
announced: s.announced,
|
|
184
|
+
gatewayServes: s.gatewayServes,
|
|
185
|
+
gatewayHttp: s.gatewayHttp,
|
|
186
|
+
status: s.gatewayServes && s.announced ? 'ok' : 'unverified',
|
|
187
|
+
})),
|
|
188
|
+
};
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// ---------------------------------------------------------------------------
|
|
193
|
+
// Per-site checks (fail-soft).
|
|
194
|
+
// ---------------------------------------------------------------------------
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Ask delegated routing who provides the CID and answer: is OUR PeerID among
|
|
198
|
+
* them? A lookup error is "not findable right now" -> false, never thrown (one
|
|
199
|
+
* flaky routing endpoint must not fail the report). Ports the shell's
|
|
200
|
+
* `jq '.Providers[]|select(.ID==$p)'`.
|
|
201
|
+
*/
|
|
202
|
+
async function checkAnnounced(
|
|
203
|
+
lookup: ProvidersLookup,
|
|
204
|
+
cid: string,
|
|
205
|
+
peerId: string,
|
|
206
|
+
): Promise<boolean> {
|
|
207
|
+
if (!peerId) return false;
|
|
208
|
+
try {
|
|
209
|
+
const res = await lookup(cid);
|
|
210
|
+
return (res.Providers ?? []).some((p) => p?.ID === peerId);
|
|
211
|
+
} catch {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Probe a cold public gateway for the CID and return its HTTP status, or
|
|
218
|
+
* undefined if the probe itself errored (network down, DNS, ...). Ports the
|
|
219
|
+
* shell's `curl -r 0-0 -w %{http_code}`.
|
|
220
|
+
*/
|
|
221
|
+
async function probeGateway(
|
|
222
|
+
probe: GatewayProbe,
|
|
223
|
+
cid: string,
|
|
224
|
+
): Promise<number | undefined> {
|
|
225
|
+
try {
|
|
226
|
+
return await probe(cid);
|
|
227
|
+
} catch {
|
|
228
|
+
return undefined;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** A gateway HTTP status counts as "served" iff it is 2xx (including 206). */
|
|
233
|
+
function servesStatus(status: number): boolean {
|
|
234
|
+
return status >= 200 && status < 300;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// ---------------------------------------------------------------------------
|
|
238
|
+
// Kubo reads.
|
|
239
|
+
// ---------------------------------------------------------------------------
|
|
240
|
+
|
|
241
|
+
/** Read this node's PeerID from Kubo `id` (empty string if unavailable). */
|
|
242
|
+
async function readPeerId(client: KuboRpcClient): Promise<string> {
|
|
243
|
+
try {
|
|
244
|
+
const res = await client.id<{ID?: string}>();
|
|
245
|
+
return res?.ID ?? '';
|
|
246
|
+
} catch {
|
|
247
|
+
return '';
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** Map site/key name -> IPNS id from `key/list -l` (same shape as node-commands). */
|
|
252
|
+
async function listKeys(client: KuboRpcClient): Promise<Map<string, string>> {
|
|
253
|
+
const res = await client.keyList<{
|
|
254
|
+
Keys?: Array<{Name?: string; Id?: string}> | null;
|
|
255
|
+
}>();
|
|
256
|
+
const map = new Map<string, string>();
|
|
257
|
+
for (const k of res.Keys ?? []) {
|
|
258
|
+
if (k?.Name && k?.Id) map.set(k.Name, k.Id);
|
|
259
|
+
}
|
|
260
|
+
return map;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// ---------------------------------------------------------------------------
|
|
264
|
+
// Default (LIVE) external checks. Production wiring; tests inject fakes instead.
|
|
265
|
+
// ---------------------------------------------------------------------------
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* The default delegated-routing lookup: GET
|
|
269
|
+
* `https://delegated-ipfs.dev/routing/v1/providers/<cid>` and parse its JSON.
|
|
270
|
+
* (Injected fakes replace this in tests; it is the only place the live routing
|
|
271
|
+
* endpoint is named.)
|
|
272
|
+
*/
|
|
273
|
+
export const defaultProvidersLookup: ProvidersLookup = async (cid) => {
|
|
274
|
+
const res = await fetch(`${DELEGATED_ROUTING_BASE}/${cid}`, {
|
|
275
|
+
headers: {accept: 'application/json'},
|
|
276
|
+
});
|
|
277
|
+
if (!res.ok) return {Providers: []};
|
|
278
|
+
return (await res.json()) as ProvidersResponse;
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* The default cold-gateway probe: a single-byte range request to
|
|
283
|
+
* `https://<cid>.ipfs.dweb.link/` returning the HTTP status. (Injected fakes
|
|
284
|
+
* replace this in tests; it is the only place the live gateway is named.)
|
|
285
|
+
*/
|
|
286
|
+
export const defaultGatewayProbe: GatewayProbe = async (cid) => {
|
|
287
|
+
const res = await fetch(`https://${cid}.${DWEB_LINK_HOST}/`, {
|
|
288
|
+
headers: {range: 'bytes=0-0'},
|
|
289
|
+
});
|
|
290
|
+
return res.status;
|
|
291
|
+
};
|