@ipab/cli 0.1.0-rc.10 → 0.1.0-rc.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 +10 -2
- package/dist/authoring.d.ts +3 -0
- package/dist/authoring.d.ts.map +1 -1
- package/dist/authoring.js +34 -1
- package/dist/authoring.js.map +1 -1
- package/dist/builtins/template.bundle-viewer.car +0 -0
- package/dist/builtins/template.check.car +0 -0
- package/dist/builtins/template.node.car +0 -0
- package/dist/builtins/template.web-app.car +0 -0
- package/dist/bundled-skills.d.ts +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +67 -21
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +4 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +17 -2
- package/dist/config.js.map +1 -1
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +7 -3
- package/dist/doctor.js.map +1 -1
- package/dist/get.d.ts.map +1 -1
- package/dist/get.js +1 -1
- package/dist/get.js.map +1 -1
- package/dist/skills.d.ts +1 -1
- package/dist/state.d.ts +20 -0
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +87 -3
- package/dist/state.js.map +1 -1
- package/dist/swarm.d.ts +68 -0
- package/dist/swarm.d.ts.map +1 -1
- package/dist/swarm.js +288 -5
- package/dist/swarm.js.map +1 -1
- package/package.json +2 -2
- package/src/authoring.ts +58 -1
- package/src/cli.ts +92 -33
- package/src/config.ts +20 -2
- package/src/doctor.ts +12 -2
- package/src/get.ts +2 -1
- package/src/state.ts +117 -2
- package/src/swarm.ts +353 -12
package/src/swarm.ts
CHANGED
|
@@ -57,7 +57,13 @@ import {
|
|
|
57
57
|
type Identity,
|
|
58
58
|
} from "./identity.js";
|
|
59
59
|
import { nodeError } from "./authoring.js";
|
|
60
|
-
import {
|
|
60
|
+
import {
|
|
61
|
+
LOCAL_SWARM_ALIAS,
|
|
62
|
+
LOCAL_SWARM_URL,
|
|
63
|
+
isLocalSwarm,
|
|
64
|
+
isReservedLocalHost,
|
|
65
|
+
swarmUrl as canonicalSwarmUrl,
|
|
66
|
+
} from "./config.js";
|
|
61
67
|
import {
|
|
62
68
|
bundleJson,
|
|
63
69
|
contentCar,
|
|
@@ -99,6 +105,7 @@ import {
|
|
|
99
105
|
createAssociation,
|
|
100
106
|
exactCid,
|
|
101
107
|
type Association,
|
|
108
|
+
type LocalSwarmRecord,
|
|
102
109
|
type SwarmProjection,
|
|
103
110
|
} from "./state.js";
|
|
104
111
|
import {
|
|
@@ -477,12 +484,185 @@ async function saveLocal(
|
|
|
477
484
|
membership,
|
|
478
485
|
);
|
|
479
486
|
}
|
|
487
|
+
export const LOCAL_SWARM_HOLD_OWNER = "local-swarm-head";
|
|
488
|
+
const LOCAL_SWARM_NAME = "Local";
|
|
489
|
+
const LOCAL_SWARM_DESCRIPTION = "Built-in single-machine Swarm";
|
|
490
|
+
const LOCAL_SWARM_ORG: Organization = {
|
|
491
|
+
v: 3,
|
|
492
|
+
scopeId: "0000000000000000",
|
|
493
|
+
owner: "local",
|
|
494
|
+
name: LOCAL_SWARM_NAME,
|
|
495
|
+
description: LOCAL_SWARM_DESCRIPTION,
|
|
496
|
+
headId: "0000000000000000",
|
|
497
|
+
epoch: 1,
|
|
498
|
+
bootstrap: [],
|
|
499
|
+
members: [],
|
|
500
|
+
};
|
|
501
|
+
|
|
502
|
+
function rejectLocalSwarm(url: string, action: string): void {
|
|
503
|
+
if (isLocalSwarm(url) || isReservedLocalHost(url)) {
|
|
504
|
+
throw new HostError(
|
|
505
|
+
`The built-in "${LOCAL_SWARM_ALIAS}" Swarm is a single-machine Swarm and does not support ${action}.`,
|
|
506
|
+
);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
async function ensureLocalSwarm(
|
|
511
|
+
context: SwarmContext,
|
|
512
|
+
): Promise<LocalSwarmRecord> {
|
|
513
|
+
const existing = withState(context, (state) => state.localSwarmHead());
|
|
514
|
+
if (existing) return existing;
|
|
515
|
+
|
|
516
|
+
const names: Record<string, CID> = {};
|
|
517
|
+
for (const selector of seedTemplateNames) {
|
|
518
|
+
const template = await seedTemplateSource(selector);
|
|
519
|
+
for (const [cid, data] of template.blocks)
|
|
520
|
+
await context.store.put(CID.parse(cid), data);
|
|
521
|
+
names[`ipab/templates/${selector}`] = CID.parse(template.cid);
|
|
522
|
+
}
|
|
523
|
+
const skill = await seedSkillSource();
|
|
524
|
+
for (const [cid, data] of skill.blocks)
|
|
525
|
+
await context.store.put(CID.parse(cid), data);
|
|
526
|
+
names["ipab/skills/ipab"] = CID.parse(skill.cid);
|
|
527
|
+
|
|
528
|
+
let currentRoot = CID.parse(
|
|
529
|
+
await writeV7RootBundle(
|
|
530
|
+
context.store,
|
|
531
|
+
{
|
|
532
|
+
templatePath: "ipab/templates",
|
|
533
|
+
registryPath: "ipab/registry",
|
|
534
|
+
skillPath: "ipab/skills",
|
|
535
|
+
},
|
|
536
|
+
LOCAL_SWARM_URL,
|
|
537
|
+
),
|
|
538
|
+
);
|
|
539
|
+
for (const [path, targetCid] of Object.entries(names)) {
|
|
540
|
+
currentRoot = (
|
|
541
|
+
await setUnixfsPath(context.store, currentRoot, path, targetCid)
|
|
542
|
+
).newRootCid;
|
|
543
|
+
}
|
|
544
|
+
const root = currentRoot.toString();
|
|
545
|
+
const valCid = await valueCid({ root });
|
|
546
|
+
const now = new Date().toISOString();
|
|
547
|
+
|
|
548
|
+
if (context.store.supportsRetention) {
|
|
549
|
+
await context.store.retain(LOCAL_SWARM_HOLD_OWNER, [root]);
|
|
550
|
+
await context.store.confirmRetained(LOCAL_SWARM_HOLD_OWNER, [root]);
|
|
551
|
+
}
|
|
552
|
+
const { record, inserted } = withState(context, (state) =>
|
|
553
|
+
state.initLocalSwarmHead({
|
|
554
|
+
headCid: root,
|
|
555
|
+
valueCid: valCid,
|
|
556
|
+
createdAt: now,
|
|
557
|
+
updatedAt: now,
|
|
558
|
+
}),
|
|
559
|
+
);
|
|
560
|
+
if (context.store.supportsRetention) {
|
|
561
|
+
if (!inserted && record.headCid !== root) {
|
|
562
|
+
await context.store.retain(LOCAL_SWARM_HOLD_OWNER, [record.headCid]);
|
|
563
|
+
await context.store.confirmRetained(LOCAL_SWARM_HOLD_OWNER, [
|
|
564
|
+
record.headCid,
|
|
565
|
+
]);
|
|
566
|
+
}
|
|
567
|
+
await context.store.reconcile(LOCAL_SWARM_HOLD_OWNER, [record.headCid]);
|
|
568
|
+
}
|
|
569
|
+
return record;
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
async function readLocalSwarmHeader(
|
|
573
|
+
context: SwarmContext,
|
|
574
|
+
): Promise<SwarmHeader> {
|
|
575
|
+
const record = await ensureLocalSwarm(context);
|
|
576
|
+
const content = await readHeaderSnapshot(
|
|
577
|
+
context.store,
|
|
578
|
+
record.headCid,
|
|
579
|
+
LOCAL_SWARM_URL,
|
|
580
|
+
);
|
|
581
|
+
const head: Variable & { root: string; etag: string } = {
|
|
582
|
+
value: { root: record.headCid },
|
|
583
|
+
cid: record.valueCid,
|
|
584
|
+
root: record.headCid,
|
|
585
|
+
etag: `"${record.valueCid}"`,
|
|
586
|
+
};
|
|
587
|
+
const header: SwarmHeader = {
|
|
588
|
+
head,
|
|
589
|
+
...content,
|
|
590
|
+
config: LOCAL_SWARM_ORG,
|
|
591
|
+
source: "cache",
|
|
592
|
+
verifiedAt: record.updatedAt,
|
|
593
|
+
localSourceReady: true,
|
|
594
|
+
};
|
|
595
|
+
await refreshNamePins(context, LOCAL_SWARM_URL, header);
|
|
596
|
+
return header;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
function localSwarmPointer(context: SwarmContext): BoundHead {
|
|
600
|
+
return {
|
|
601
|
+
read: async () => {
|
|
602
|
+
const record = await ensureLocalSwarm(context);
|
|
603
|
+
return {
|
|
604
|
+
value: { root: record.headCid },
|
|
605
|
+
cid: record.valueCid,
|
|
606
|
+
root: record.headCid,
|
|
607
|
+
etag: `"${record.valueCid}"`,
|
|
608
|
+
};
|
|
609
|
+
},
|
|
610
|
+
write: async (root, expectedCid) => {
|
|
611
|
+
const valCid = await valueCid({ root });
|
|
612
|
+
const now = new Date().toISOString();
|
|
613
|
+
if (context.store.supportsRetention) {
|
|
614
|
+
await context.store.retain(LOCAL_SWARM_HOLD_OWNER, [root]);
|
|
615
|
+
await context.store.confirmRetained(LOCAL_SWARM_HOLD_OWNER, [root]);
|
|
616
|
+
}
|
|
617
|
+
const swapped = withState(context, (state) =>
|
|
618
|
+
state.compareAndSwapLocalSwarmHead(expectedCid, {
|
|
619
|
+
headCid: root,
|
|
620
|
+
valueCid: valCid,
|
|
621
|
+
updatedAt: now,
|
|
622
|
+
}),
|
|
623
|
+
);
|
|
624
|
+
if (!swapped) {
|
|
625
|
+
const current = withState(context, (state) => state.localSwarmHead());
|
|
626
|
+
if (context.store.supportsRetention && current) {
|
|
627
|
+
await context.store
|
|
628
|
+
.reconcile(LOCAL_SWARM_HOLD_OWNER, [current.headCid])
|
|
629
|
+
.catch(() => {});
|
|
630
|
+
}
|
|
631
|
+
throw new ScopeApiError(
|
|
632
|
+
412,
|
|
633
|
+
"cas_conflict",
|
|
634
|
+
"Local Swarm HEAD changed concurrently; retry against the latest snapshot.",
|
|
635
|
+
undefined,
|
|
636
|
+
);
|
|
637
|
+
}
|
|
638
|
+
if (context.store.supportsRetention) {
|
|
639
|
+
await context.store.reconcile(LOCAL_SWARM_HOLD_OWNER, [root]);
|
|
640
|
+
}
|
|
641
|
+
return {
|
|
642
|
+
value: { root },
|
|
643
|
+
cid: valCid,
|
|
644
|
+
};
|
|
645
|
+
},
|
|
646
|
+
writeWithReceipt: () =>
|
|
647
|
+
Promise.reject(
|
|
648
|
+
new HostError(
|
|
649
|
+
`The built-in "${LOCAL_SWARM_ALIAS}" Swarm is a single-machine Swarm and does not support Pivot receipt writes.`,
|
|
650
|
+
),
|
|
651
|
+
),
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
|
|
480
655
|
function client(
|
|
481
656
|
context: SwarmContext,
|
|
482
657
|
service: string,
|
|
483
658
|
identity?: Identity,
|
|
484
659
|
secret?: MembershipSecret,
|
|
485
660
|
): ScopeClient {
|
|
661
|
+
if (isReservedLocalHost(service)) {
|
|
662
|
+
throw new HostError(
|
|
663
|
+
`Refusing network request to reserved .invalid host (${service}) for the built-in "${LOCAL_SWARM_ALIAS}" Swarm.`,
|
|
664
|
+
);
|
|
665
|
+
}
|
|
486
666
|
return new ScopeClient({
|
|
487
667
|
service,
|
|
488
668
|
...(identity
|
|
@@ -930,6 +1110,36 @@ export async function swarmMembers(
|
|
|
930
1110
|
url: string,
|
|
931
1111
|
refresh = false,
|
|
932
1112
|
) {
|
|
1113
|
+
if (isLocalSwarm(url)) {
|
|
1114
|
+
const headRecord = withState(context, (state) => state.localSwarmHead());
|
|
1115
|
+
return {
|
|
1116
|
+
mode: "local" as const,
|
|
1117
|
+
configUrl: LOCAL_SWARM_URL,
|
|
1118
|
+
members: [
|
|
1119
|
+
{
|
|
1120
|
+
publicKey: "local",
|
|
1121
|
+
role: "owner",
|
|
1122
|
+
name: "Local user",
|
|
1123
|
+
description: "Single-machine built-in Swarm user",
|
|
1124
|
+
pivot: false,
|
|
1125
|
+
localStatus: null,
|
|
1126
|
+
peerId: "",
|
|
1127
|
+
updatedAt: headRecord?.updatedAt ?? "",
|
|
1128
|
+
},
|
|
1129
|
+
],
|
|
1130
|
+
cache: {
|
|
1131
|
+
source: "cache" as const,
|
|
1132
|
+
freshness: "current" as const,
|
|
1133
|
+
updatedAt: headRecord?.updatedAt ?? new Date().toISOString(),
|
|
1134
|
+
},
|
|
1135
|
+
local: {
|
|
1136
|
+
status: "unavailable" as const,
|
|
1137
|
+
updatedAt: null,
|
|
1138
|
+
verifiedAt: null,
|
|
1139
|
+
error: null,
|
|
1140
|
+
},
|
|
1141
|
+
};
|
|
1142
|
+
}
|
|
933
1143
|
const { config, directory, cache } = await inspection(context, url, refresh);
|
|
934
1144
|
const observations = await localObservations(context, url, config);
|
|
935
1145
|
const members = directory.map(({ member, profile }) => {
|
|
@@ -965,6 +1175,7 @@ export async function swarmNetworking(
|
|
|
965
1175
|
config: Organization,
|
|
966
1176
|
directory?: Awaited<ReturnType<typeof memberDirectory>>,
|
|
967
1177
|
) {
|
|
1178
|
+
rejectLocalSwarm(url, "swarm networking");
|
|
968
1179
|
directory ??= (await inspection(context, url)).directory;
|
|
969
1180
|
const { account, local } = await localObservations(context, url, config);
|
|
970
1181
|
const saved = local.snapshot?.connections;
|
|
@@ -1071,6 +1282,66 @@ export async function inspectSwarmStatus(
|
|
|
1071
1282
|
url: string,
|
|
1072
1283
|
refresh = false,
|
|
1073
1284
|
) {
|
|
1285
|
+
if (isLocalSwarm(url)) {
|
|
1286
|
+
const header = await readLocalSwarmHeader(context);
|
|
1287
|
+
const meta = await swarmMeta(context, header);
|
|
1288
|
+
const walked = await walkUnixfsNames(
|
|
1289
|
+
context.store,
|
|
1290
|
+
CID.parse(header.stateCid),
|
|
1291
|
+
{
|
|
1292
|
+
skipRootFiles: v7RootSkipFiles(header.snapshot),
|
|
1293
|
+
stopAtBundle: true,
|
|
1294
|
+
},
|
|
1295
|
+
);
|
|
1296
|
+
const templatePrefix = `${meta.templatePath}/`;
|
|
1297
|
+
const skillPrefix = meta.skillPath ? `${meta.skillPath}/` : undefined;
|
|
1298
|
+
const registryPrefix = `${meta.registryPath}/`;
|
|
1299
|
+
let templates = 0;
|
|
1300
|
+
let skills = 0;
|
|
1301
|
+
let registrations = 0;
|
|
1302
|
+
for (const entry of walked.entries) {
|
|
1303
|
+
if (entry.name.startsWith(templatePrefix)) templates++;
|
|
1304
|
+
else if (skillPrefix && entry.name.startsWith(skillPrefix)) skills++;
|
|
1305
|
+
else if (entry.name.startsWith(registryPrefix)) registrations++;
|
|
1306
|
+
}
|
|
1307
|
+
return {
|
|
1308
|
+
mode: "local" as const,
|
|
1309
|
+
configUrl: LOCAL_SWARM_URL,
|
|
1310
|
+
config: LOCAL_SWARM_ORG,
|
|
1311
|
+
head: header.head,
|
|
1312
|
+
lastWriter: null,
|
|
1313
|
+
cache: {
|
|
1314
|
+
source: "cache" as const,
|
|
1315
|
+
freshness: "current" as const,
|
|
1316
|
+
updatedAt: header.verifiedAt,
|
|
1317
|
+
},
|
|
1318
|
+
state: {
|
|
1319
|
+
status: "available" as const,
|
|
1320
|
+
error: null,
|
|
1321
|
+
},
|
|
1322
|
+
local: {
|
|
1323
|
+
names: walked.entries.length,
|
|
1324
|
+
templates,
|
|
1325
|
+
skills,
|
|
1326
|
+
registrations,
|
|
1327
|
+
},
|
|
1328
|
+
networking: {
|
|
1329
|
+
daemon: {
|
|
1330
|
+
status: "unavailable" as const,
|
|
1331
|
+
updatedAt: null,
|
|
1332
|
+
verifiedAt: null,
|
|
1333
|
+
error: null,
|
|
1334
|
+
},
|
|
1335
|
+
connections: {
|
|
1336
|
+
observedAt: null,
|
|
1337
|
+
error: null,
|
|
1338
|
+
peers: [],
|
|
1339
|
+
freshness: "unavailable" as const,
|
|
1340
|
+
},
|
|
1341
|
+
pivots: [],
|
|
1342
|
+
},
|
|
1343
|
+
};
|
|
1344
|
+
}
|
|
1074
1345
|
const { config, directory, head, cache } = await inspection(
|
|
1075
1346
|
context,
|
|
1076
1347
|
url,
|
|
@@ -1316,6 +1587,7 @@ async function fetchConfig(
|
|
|
1316
1587
|
configUrl: string,
|
|
1317
1588
|
signal?: AbortSignal,
|
|
1318
1589
|
): Promise<{ config: Organization; variable: Variable }> {
|
|
1590
|
+
rejectLocalSwarm(configUrl, "remote configuration fetch");
|
|
1319
1591
|
const c = coordinates(configUrl),
|
|
1320
1592
|
api = client(context, c.service);
|
|
1321
1593
|
const options = signal ? { signal } : {};
|
|
@@ -1535,6 +1807,7 @@ async function privateSource(
|
|
|
1535
1807
|
signal?: AbortSignal,
|
|
1536
1808
|
candidates?: PivotCandidates,
|
|
1537
1809
|
) {
|
|
1810
|
+
rejectLocalSwarm(record.configUrl, "private Kubo networking");
|
|
1538
1811
|
const config = record.config!,
|
|
1539
1812
|
secret = record.secret!;
|
|
1540
1813
|
const identity = await contextIdentity(context);
|
|
@@ -2405,6 +2678,7 @@ async function approvedMembership(
|
|
|
2405
2678
|
configUrl: string,
|
|
2406
2679
|
signal?: AbortSignal,
|
|
2407
2680
|
) {
|
|
2681
|
+
rejectLocalSwarm(configUrl, "remote membership");
|
|
2408
2682
|
const record = await localForRead(context, configUrl);
|
|
2409
2683
|
const { config } = await fetchConfig(context, configUrl, signal);
|
|
2410
2684
|
if (config.owner !== record.owner)
|
|
@@ -2503,6 +2777,7 @@ async function readyMembership(
|
|
|
2503
2777
|
context: SwarmContext,
|
|
2504
2778
|
configUrl: string,
|
|
2505
2779
|
): Promise<LocalMembership> {
|
|
2780
|
+
rejectLocalSwarm(configUrl, "remote membership");
|
|
2506
2781
|
const record = await localForRead(context, configUrl);
|
|
2507
2782
|
if (!record.config || !record.secret) return refresh(context, configUrl);
|
|
2508
2783
|
if (
|
|
@@ -2545,6 +2820,7 @@ export async function pointer(
|
|
|
2545
2820
|
context: SwarmContext,
|
|
2546
2821
|
configUrl: string,
|
|
2547
2822
|
): Promise<BoundHead> {
|
|
2823
|
+
if (isLocalSwarm(configUrl)) return localSwarmPointer(context);
|
|
2548
2824
|
return boundPointer(
|
|
2549
2825
|
context,
|
|
2550
2826
|
configUrl,
|
|
@@ -2622,6 +2898,10 @@ async function writeNamesHead(
|
|
|
2622
2898
|
root: string,
|
|
2623
2899
|
cid: string,
|
|
2624
2900
|
): Promise<void> {
|
|
2901
|
+
if (isLocalSwarm(url)) {
|
|
2902
|
+
await head.write(root, cid, uniqueId());
|
|
2903
|
+
return;
|
|
2904
|
+
}
|
|
2625
2905
|
const lock = await privateDirectory(
|
|
2626
2906
|
await directory(context),
|
|
2627
2907
|
`state-pin-${createHash("sha256").update(url).digest("hex")}`,
|
|
@@ -2642,7 +2922,7 @@ async function writeNamesHead(
|
|
|
2642
2922
|
return;
|
|
2643
2923
|
}
|
|
2644
2924
|
const idempotencyKey = uniqueId();
|
|
2645
|
-
let receipt: ScopeWriteReceipt;
|
|
2925
|
+
let receipt: ScopeWriteReceipt | null;
|
|
2646
2926
|
try {
|
|
2647
2927
|
receipt = await requestPivotWriteReceipt(
|
|
2648
2928
|
context,
|
|
@@ -2659,6 +2939,10 @@ async function writeNamesHead(
|
|
|
2659
2939
|
"publication",
|
|
2660
2940
|
);
|
|
2661
2941
|
}
|
|
2942
|
+
if (receipt === null) {
|
|
2943
|
+
await head.write(root, cid, idempotencyKey);
|
|
2944
|
+
return;
|
|
2945
|
+
}
|
|
2662
2946
|
await head.writeWithReceipt(receipt);
|
|
2663
2947
|
});
|
|
2664
2948
|
}
|
|
@@ -2669,7 +2953,7 @@ async function requestPivotWriteReceipt(
|
|
|
2669
2953
|
root: string,
|
|
2670
2954
|
ifCid: string,
|
|
2671
2955
|
idempotencyKey: string,
|
|
2672
|
-
): Promise<ScopeWriteReceipt> {
|
|
2956
|
+
): Promise<ScopeWriteReceipt | null> {
|
|
2673
2957
|
const record = await approvedMembership(context, url);
|
|
2674
2958
|
const config = record.config!;
|
|
2675
2959
|
const identity = await contextIdentity(context);
|
|
@@ -2684,10 +2968,21 @@ async function requestPivotWriteReceipt(
|
|
|
2684
2968
|
const remote = pivots.filter(
|
|
2685
2969
|
({ member }) => member.publicKey !== record.account,
|
|
2686
2970
|
);
|
|
2687
|
-
if (!remote.length)
|
|
2971
|
+
if (!remote.length) {
|
|
2972
|
+
if (
|
|
2973
|
+
members.length === 1 &&
|
|
2974
|
+
members[0]!.member.publicKey === record.account &&
|
|
2975
|
+
record.account === config.owner
|
|
2976
|
+
) {
|
|
2977
|
+
context.diagnostic?.(
|
|
2978
|
+
`[${url}] Solo self-Pivot Swarm detected; publishing ${root} directly without remote Pivot receipt.`,
|
|
2979
|
+
);
|
|
2980
|
+
return null;
|
|
2981
|
+
}
|
|
2688
2982
|
throw new HostError(
|
|
2689
2983
|
"Publication requires an independent Pivot node. Declare another member with swarm profile --pivot true; HEAD was not changed.",
|
|
2690
2984
|
);
|
|
2985
|
+
}
|
|
2691
2986
|
const authorized = remote.filter(
|
|
2692
2987
|
({ member }) =>
|
|
2693
2988
|
member.publicKey === config.owner ||
|
|
@@ -2773,6 +3068,7 @@ export async function handlePivotReceiptRequest(
|
|
|
2773
3068
|
input: unknown,
|
|
2774
3069
|
signal: AbortSignal,
|
|
2775
3070
|
): Promise<ScopeWriteReceipt> {
|
|
3071
|
+
rejectLocalSwarm(url, "Pivot receipt RPC");
|
|
2776
3072
|
const request = parsePivotReceiptRequest(input);
|
|
2777
3073
|
const record = await approvedMembership(context, url, signal);
|
|
2778
3074
|
const config = record.config!;
|
|
@@ -2932,6 +3228,7 @@ export async function syncPivotPublications(
|
|
|
2932
3228
|
url: string,
|
|
2933
3229
|
signal: AbortSignal,
|
|
2934
3230
|
): Promise<void> {
|
|
3231
|
+
rejectLocalSwarm(url, "Pivot publication sync");
|
|
2935
3232
|
if (context.pivot === false) return;
|
|
2936
3233
|
const record = await approvedMembership(context, url, signal);
|
|
2937
3234
|
const config = record.config!;
|
|
@@ -3528,6 +3825,7 @@ export async function sharedSwarmStatus(
|
|
|
3528
3825
|
context: SwarmContext,
|
|
3529
3826
|
configUrl: string,
|
|
3530
3827
|
): Promise<SwarmHeader> {
|
|
3828
|
+
if (isLocalSwarm(configUrl)) return readLocalSwarmHeader(context);
|
|
3531
3829
|
const { config } = await fetchConfig(context, configUrl);
|
|
3532
3830
|
const c = coordinates(configUrl);
|
|
3533
3831
|
const head = headValue(
|
|
@@ -3596,6 +3894,7 @@ async function readSwarmHeader(
|
|
|
3596
3894
|
mode: "active" | "local-first" = "active",
|
|
3597
3895
|
): Promise<SwarmHeader> {
|
|
3598
3896
|
canonicalSwarmUrl(configUrl);
|
|
3897
|
+
if (isLocalSwarm(configUrl)) return readLocalSwarmHeader(context);
|
|
3599
3898
|
let record =
|
|
3600
3899
|
mode === "local-first"
|
|
3601
3900
|
? await approvedMembership(context, configUrl)
|
|
@@ -3820,6 +4119,8 @@ function headerProjection(header: SwarmHeader): SwarmProjection {
|
|
|
3820
4119
|
return header.projection;
|
|
3821
4120
|
}
|
|
3822
4121
|
async function localHeader(context: SwarmContext, url: string) {
|
|
4122
|
+
if (isLocalSwarm(url))
|
|
4123
|
+
return { header: await readLocalSwarmHeader(context), account: "local" };
|
|
3823
4124
|
if (context.forceRefresh) return;
|
|
3824
4125
|
canonicalSwarmUrl(url);
|
|
3825
4126
|
const record = await localForRead(context, url);
|
|
@@ -3875,6 +4176,7 @@ async function lazyPrivateSource(
|
|
|
3875
4176
|
account: string,
|
|
3876
4177
|
basis: Organization,
|
|
3877
4178
|
) {
|
|
4179
|
+
rejectLocalSwarm(url, "private Kubo networking");
|
|
3878
4180
|
const finishPrevious = context.finishRead;
|
|
3879
4181
|
delete context.finishRead;
|
|
3880
4182
|
await finishPrevious?.();
|
|
@@ -3956,6 +4258,10 @@ export async function createSwarm(
|
|
|
3956
4258
|
addresses?: string[];
|
|
3957
4259
|
} = {},
|
|
3958
4260
|
): Promise<string> {
|
|
4261
|
+
if (options.alias === LOCAL_SWARM_ALIAS)
|
|
4262
|
+
throw new HostError(
|
|
4263
|
+
`Swarm alias "${LOCAL_SWARM_ALIAS}" is reserved for the built-in local Swarm.`,
|
|
4264
|
+
);
|
|
3959
4265
|
if (
|
|
3960
4266
|
(options.properties?.name.length ?? 0) > 256 ||
|
|
3961
4267
|
(options.properties?.description.length ?? 0) > 2048 ||
|
|
@@ -4244,6 +4550,7 @@ export async function exportRequest(
|
|
|
4244
4550
|
url: string,
|
|
4245
4551
|
output: string,
|
|
4246
4552
|
): Promise<string> {
|
|
4553
|
+
rejectLocalSwarm(url, "swarm export");
|
|
4247
4554
|
const record = await local(context, canonicalSwarmUrl(url));
|
|
4248
4555
|
if (!record.request) throw new HostError("Owner membership has no Request.");
|
|
4249
4556
|
const handle = await open(output, "wx", 0o600);
|
|
@@ -4267,6 +4574,7 @@ export async function requestMembership(
|
|
|
4267
4574
|
request: MembershipRequest;
|
|
4268
4575
|
file?: string;
|
|
4269
4576
|
}> {
|
|
4577
|
+
rejectLocalSwarm(url, "swarm request");
|
|
4270
4578
|
if ("name" in options)
|
|
4271
4579
|
throw new HostError(
|
|
4272
4580
|
"Set your account-wide name with ipab profile --name NAME; membership requests no longer embed display names.",
|
|
@@ -4531,6 +4839,7 @@ export async function approveMembership(
|
|
|
4531
4839
|
? await verifiedRequest(input)
|
|
4532
4840
|
: await verifyRequest(input),
|
|
4533
4841
|
url = request.configUrl;
|
|
4842
|
+
rejectLocalSwarm(url, "swarm approve");
|
|
4534
4843
|
const dir = await directory(context);
|
|
4535
4844
|
return withPrivateLock(dir, async () => {
|
|
4536
4845
|
const { identity, record } = await ownerCheck(context, url);
|
|
@@ -4789,6 +5098,7 @@ export async function grantPivotAuthority(
|
|
|
4789
5098
|
url: string,
|
|
4790
5099
|
memberPublicKey: string,
|
|
4791
5100
|
): Promise<{ configUrl: string; member: string; headId: string }> {
|
|
5101
|
+
rejectLocalSwarm(url, "swarm pivot grant");
|
|
4792
5102
|
if (!isCanonicalPublicKey(memberPublicKey))
|
|
4793
5103
|
throw new HostError("Invalid member public key.");
|
|
4794
5104
|
const dir = await directory(context);
|
|
@@ -4891,6 +5201,7 @@ export async function updateSwarm(
|
|
|
4891
5201
|
url: string,
|
|
4892
5202
|
changes: { name?: string; description?: string },
|
|
4893
5203
|
) {
|
|
5204
|
+
rejectLocalSwarm(url, "swarm update");
|
|
4894
5205
|
if (
|
|
4895
5206
|
(changes.name?.length ?? 0) > 256 ||
|
|
4896
5207
|
(changes.description?.length ?? 0) > 2048
|
|
@@ -4923,6 +5234,7 @@ export async function updateProfile(
|
|
|
4923
5234
|
url: string,
|
|
4924
5235
|
changes: { addresses?: string[]; pivot?: boolean },
|
|
4925
5236
|
): Promise<Profile> {
|
|
5237
|
+
rejectLocalSwarm(url, "swarm profile");
|
|
4926
5238
|
if ("name" in changes || "description" in changes)
|
|
4927
5239
|
throw new HostError(
|
|
4928
5240
|
"Use ipab profile --name NAME --description TEXT for personal data; swarm profile configures network addresses only.",
|
|
@@ -5027,6 +5339,7 @@ export async function removeMember(
|
|
|
5027
5339
|
url: string,
|
|
5028
5340
|
member: string,
|
|
5029
5341
|
): Promise<void> {
|
|
5342
|
+
rejectLocalSwarm(url, "swarm exclude");
|
|
5030
5343
|
const dir = await directory(context);
|
|
5031
5344
|
await withPrivateLock(dir, async () => {
|
|
5032
5345
|
const { identity, record: membership } = await ownerCheck(context, url);
|
|
@@ -5053,6 +5366,7 @@ export async function resumeRemoval(
|
|
|
5053
5366
|
context: SwarmContext,
|
|
5054
5367
|
url: string,
|
|
5055
5368
|
): Promise<void> {
|
|
5369
|
+
rejectLocalSwarm(url, "swarm resume");
|
|
5056
5370
|
const dir = await directory(context);
|
|
5057
5371
|
return withPrivateLock(dir, async () => {
|
|
5058
5372
|
const identity = await contextIdentity(context);
|
|
@@ -5428,7 +5742,7 @@ export async function resolveReference(
|
|
|
5428
5742
|
}
|
|
5429
5743
|
};
|
|
5430
5744
|
let link = await target();
|
|
5431
|
-
if (!link && header.source === "cache") {
|
|
5745
|
+
if (!link && header.source === "cache" && !isLocalSwarm(selected)) {
|
|
5432
5746
|
header = await swarmHeader(context, selected, true);
|
|
5433
5747
|
link = await target();
|
|
5434
5748
|
}
|
|
@@ -5440,7 +5754,7 @@ export async function resolveReference(
|
|
|
5440
5754
|
targetCid = link;
|
|
5441
5755
|
source = { configUrl: selected, header };
|
|
5442
5756
|
} else {
|
|
5443
|
-
if (swarm) await readyMembership(context, swarm);
|
|
5757
|
+
if (swarm && !isLocalSwarm(swarm)) await readyMembership(context, swarm);
|
|
5444
5758
|
targetCid = local(reference);
|
|
5445
5759
|
}
|
|
5446
5760
|
try {
|
|
@@ -5525,6 +5839,7 @@ export async function pinNameSubscription(
|
|
|
5525
5839
|
} catch (cause) {
|
|
5526
5840
|
if (!selected || !missingContent(cause)) throw cause;
|
|
5527
5841
|
const swarm = withState(context, (state) => state.resolveSwarm(selected));
|
|
5842
|
+
if (isLocalSwarm(swarm)) throw cause;
|
|
5528
5843
|
await readyMembership(context, swarm);
|
|
5529
5844
|
roots = [
|
|
5530
5845
|
...(await currentDependencies(context.store, canonical.reference)),
|
|
@@ -5885,12 +6200,36 @@ export async function searchNames(
|
|
|
5885
6200
|
"local-first",
|
|
5886
6201
|
));
|
|
5887
6202
|
if (isV7Snapshot(header.snapshot)) {
|
|
5888
|
-
|
|
5889
|
-
|
|
5890
|
-
|
|
5891
|
-
|
|
5892
|
-
|
|
5893
|
-
|
|
6203
|
+
let response: SearchApiResponse;
|
|
6204
|
+
if (isLocalSwarm(swarm.cid)) {
|
|
6205
|
+
await withStateAsync(context, async (state) => {
|
|
6206
|
+
if (
|
|
6207
|
+
state.searchIndexState(LOCAL_SWARM_URL)?.headCid !==
|
|
6208
|
+
header.head.root
|
|
6209
|
+
) {
|
|
6210
|
+
await indexV7UnixfsSwarm(
|
|
6211
|
+
state,
|
|
6212
|
+
context.store,
|
|
6213
|
+
LOCAL_SWARM_URL,
|
|
6214
|
+
header.head.root,
|
|
6215
|
+
{ skipRootFiles: v7RootSkipFiles(header.snapshot) },
|
|
6216
|
+
);
|
|
6217
|
+
}
|
|
6218
|
+
});
|
|
6219
|
+
const localResponse = withState(context, (state) =>
|
|
6220
|
+
queryLocalSearchIndex(state, LOCAL_SWARM_URL, validated),
|
|
6221
|
+
);
|
|
6222
|
+
if (!localResponse)
|
|
6223
|
+
throw new HostError("Local Swarm search index is unavailable.");
|
|
6224
|
+
response = localResponse;
|
|
6225
|
+
} else {
|
|
6226
|
+
response = await searchV7ViaPivot(
|
|
6227
|
+
context,
|
|
6228
|
+
swarm.cid,
|
|
6229
|
+
header,
|
|
6230
|
+
validated,
|
|
6231
|
+
);
|
|
6232
|
+
}
|
|
5894
6233
|
searched.push({
|
|
5895
6234
|
configUrl: swarm.cid,
|
|
5896
6235
|
source: header.source,
|
|
@@ -6543,6 +6882,7 @@ async function prepareV7PathSet(
|
|
|
6543
6882
|
name,
|
|
6544
6883
|
targetCid,
|
|
6545
6884
|
);
|
|
6885
|
+
if (isLocalSwarm(configUrl)) return newRootCid.toString();
|
|
6546
6886
|
const recursiveRoots = [...new Set(roots)];
|
|
6547
6887
|
const retainedRecursive = [...new Set(retainedRoots ?? roots)];
|
|
6548
6888
|
await provideShallowContent(context.store, {
|
|
@@ -6571,6 +6911,7 @@ async function prepareV7PathDelete(
|
|
|
6571
6911
|
CID.parse(current.stateBundle!.cid),
|
|
6572
6912
|
name,
|
|
6573
6913
|
);
|
|
6914
|
+
if (isLocalSwarm(configUrl)) return newRootCid.toString();
|
|
6574
6915
|
await provideShallowContent(context.store, {
|
|
6575
6916
|
directBlocks: createdDirCids,
|
|
6576
6917
|
recursiveRoots: [],
|