@ipab/cli 0.1.0-rc.2 → 0.1.0-rc.4
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 +40 -13
- package/dist/app-authoring.d.ts.map +1 -1
- package/dist/app-authoring.js +11 -2
- package/dist/app-authoring.js.map +1 -1
- package/dist/app-definition.d.ts +52 -57
- package/dist/app-definition.d.ts.map +1 -1
- package/dist/app-definition.js +33 -38
- package/dist/app-definition.js.map +1 -1
- package/dist/app-templates.d.ts.map +1 -1
- package/dist/app-templates.js +2 -1
- package/dist/app-templates.js.map +1 -1
- package/dist/assembly.d.ts.map +1 -1
- package/dist/assembly.js +3 -4
- package/dist/assembly.js.map +1 -1
- package/dist/authoring.d.ts +3 -7
- package/dist/authoring.d.ts.map +1 -1
- package/dist/authoring.js +22 -12
- package/dist/authoring.js.map +1 -1
- package/dist/builtins/skill.ipab.car +0 -0
- package/dist/builtins/template.node.car +0 -0
- package/dist/builtins/template.web-app.car +0 -0
- package/dist/builtins.d.ts.map +1 -1
- package/dist/builtins.js +18 -2
- package/dist/builtins.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +367 -124
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +2 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +29 -16
- package/dist/config.js.map +1 -1
- package/dist/content-provider.d.ts +1 -1
- package/dist/content-provider.d.ts.map +1 -1
- package/dist/content-provider.js +5 -2
- package/dist/content-provider.js.map +1 -1
- package/dist/get.d.ts.map +1 -1
- package/dist/get.js +34 -15
- package/dist/get.js.map +1 -1
- package/dist/identity.d.ts +5 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +5 -0
- package/dist/identity.js.map +1 -1
- package/dist/kubo.d.ts +40 -0
- package/dist/kubo.d.ts.map +1 -0
- package/dist/kubo.js +555 -0
- package/dist/kubo.js.map +1 -0
- package/dist/pins.d.ts +3 -3
- package/dist/pins.js +1 -1
- package/dist/pins.js.map +1 -1
- package/dist/setup.d.ts +7 -0
- package/dist/setup.d.ts.map +1 -0
- package/dist/setup.js +22 -0
- package/dist/setup.js.map +1 -0
- package/dist/source-bundle.d.ts +3 -8
- package/dist/source-bundle.d.ts.map +1 -1
- package/dist/source-bundle.js +16 -11
- package/dist/source-bundle.js.map +1 -1
- package/dist/space.d.ts.map +1 -1
- package/dist/space.js +2 -2
- package/dist/space.js.map +1 -1
- package/dist/state.d.ts +7 -5
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +17 -14
- package/dist/state.js.map +1 -1
- package/dist/swarm-envelope.d.ts +36 -0
- package/dist/swarm-envelope.d.ts.map +1 -0
- package/dist/swarm-envelope.js +145 -0
- package/dist/swarm-envelope.js.map +1 -0
- package/dist/swarm-files.d.ts +6 -0
- package/dist/swarm-files.d.ts.map +1 -0
- package/dist/swarm-files.js +107 -0
- package/dist/swarm-files.js.map +1 -0
- package/dist/swarm.d.ts +120 -58
- package/dist/swarm.d.ts.map +1 -1
- package/dist/swarm.js +1065 -548
- package/dist/swarm.js.map +1 -1
- package/dist/template-definition.d.ts +47 -52
- package/dist/template-definition.d.ts.map +1 -1
- package/dist/template-definition.js +36 -41
- package/dist/template-definition.js.map +1 -1
- package/dist/template-source.d.ts +2 -0
- package/dist/template-source.d.ts.map +1 -1
- package/dist/template-source.js +4 -3
- package/dist/template-source.js.map +1 -1
- package/package.json +3 -3
- package/src/app-authoring.ts +22 -5
- package/src/app-definition.ts +33 -39
- package/src/app-templates.ts +9 -1
- package/src/assembly.ts +7 -4
- package/src/authoring.ts +31 -14
- package/src/builtins.ts +23 -2
- package/src/cli.ts +427 -147
- package/src/config.ts +32 -19
- package/src/content-provider.ts +5 -4
- package/src/get.ts +37 -15
- package/src/identity.ts +13 -0
- package/src/kubo.ts +732 -0
- package/src/pins.ts +1 -1
- package/src/setup.ts +21 -0
- package/src/source-bundle.ts +25 -12
- package/src/space.ts +2 -5
- package/src/state.ts +24 -15
- package/src/swarm-envelope.ts +255 -0
- package/src/swarm-files.ts +116 -0
- package/src/swarm.ts +1728 -836
- package/src/template-definition.ts +36 -41
- package/src/template-source.ts +10 -3
package/src/config.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { homedir } from "node:os";
|
|
2
|
-
import { CID } from "multiformats/cid";
|
|
3
2
|
import { join, resolve } from "node:path";
|
|
4
3
|
import { readContentConfiguration } from "@ipab/ipfs-store/node";
|
|
5
4
|
import type { StoreConfiguration } from "@ipab/ipfs-store";
|
|
@@ -7,8 +6,7 @@ import { HostError, object, syntax } from "./errors.js";
|
|
|
7
6
|
|
|
8
7
|
export type ConfigKey =
|
|
9
8
|
| "swarm.default"
|
|
10
|
-
| "swarm.
|
|
11
|
-
| "swarm.provider"
|
|
9
|
+
| "swarm.listen"
|
|
12
10
|
| "swarm.cacheTtl"
|
|
13
11
|
| "swarm.forceRefresh"
|
|
14
12
|
| "store.gateway"
|
|
@@ -33,8 +31,7 @@ export interface ConfigItem {
|
|
|
33
31
|
}
|
|
34
32
|
export const defaults: Record<ConfigKey, ConfigValue> = {
|
|
35
33
|
"swarm.default": null,
|
|
36
|
-
"swarm.
|
|
37
|
-
"swarm.provider": "http://127.0.0.1:5001",
|
|
34
|
+
"swarm.listen": "lan",
|
|
38
35
|
"swarm.cacheTtl": 300,
|
|
39
36
|
"swarm.forceRefresh": false,
|
|
40
37
|
"store.gateway": null,
|
|
@@ -46,8 +43,7 @@ export const defaults: Record<ConfigKey, ConfigValue> = {
|
|
|
46
43
|
"bundle.outputDir": "dist",
|
|
47
44
|
};
|
|
48
45
|
const environments: Partial<Record<ConfigKey, string>> = {
|
|
49
|
-
"swarm.
|
|
50
|
-
"swarm.provider": "IPAB_SWARM_PROVIDER",
|
|
46
|
+
"swarm.listen": "IPAB_SWARM_LISTEN",
|
|
51
47
|
"swarm.cacheTtl": "IPAB_SWARM_CACHE_TTL",
|
|
52
48
|
"swarm.forceRefresh": "IPAB_SWARM_FORCE_REFRESH",
|
|
53
49
|
"store.gateway": "IPAB_STORE_GATEWAY",
|
|
@@ -128,7 +124,9 @@ export function parseValue(
|
|
|
128
124
|
): ConfigValue {
|
|
129
125
|
if (text && typeof value === "string") {
|
|
130
126
|
if (key.startsWith("swarm.") && value === "default")
|
|
131
|
-
return key === "swarm.cacheTtl" ||
|
|
127
|
+
return key === "swarm.cacheTtl" ||
|
|
128
|
+
key === "swarm.forceRefresh" ||
|
|
129
|
+
key === "swarm.listen"
|
|
132
130
|
? defaults[key]
|
|
133
131
|
: null;
|
|
134
132
|
if (key === "history.enabled" || key === "swarm.forceRefresh") {
|
|
@@ -182,19 +180,14 @@ export function parseValue(
|
|
|
182
180
|
if (typeof value === "boolean") return value;
|
|
183
181
|
syntax("swarm.forceRefresh requires true or false.");
|
|
184
182
|
}
|
|
183
|
+
if (key === "swarm.listen") {
|
|
184
|
+
if (value === "lan" || value === "loopback") return value;
|
|
185
|
+
syntax("swarm.listen requires lan or loopback.");
|
|
186
|
+
}
|
|
185
187
|
if (key.startsWith("swarm.") && value === null) return null;
|
|
186
188
|
if (key === "swarm.default" && typeof value === "string") {
|
|
187
|
-
|
|
188
|
-
return CID.parse(value).toV1().toString();
|
|
189
|
-
} catch {
|
|
190
|
-
syntax("swarm.default requires an exact Swarm Bundle CID.");
|
|
191
|
-
}
|
|
189
|
+
return swarmUrl(value);
|
|
192
190
|
}
|
|
193
|
-
if (
|
|
194
|
-
(key === "swarm.service" || key === "swarm.provider") &&
|
|
195
|
-
typeof value === "string"
|
|
196
|
-
)
|
|
197
|
-
return publicUrl(value);
|
|
198
191
|
if (key === "store.gateway" && value === null) return null;
|
|
199
192
|
if (
|
|
200
193
|
key === "bundle.outputDir" &&
|
|
@@ -230,6 +223,26 @@ export function parseValue(
|
|
|
230
223
|
);
|
|
231
224
|
}
|
|
232
225
|
|
|
226
|
+
export function swarmUrl(value: string): string {
|
|
227
|
+
try {
|
|
228
|
+
const url = new URL(value);
|
|
229
|
+
pointerService(url.origin);
|
|
230
|
+
if (
|
|
231
|
+
url.username ||
|
|
232
|
+
url.password ||
|
|
233
|
+
url.search ||
|
|
234
|
+
url.hash ||
|
|
235
|
+
url.toString() !== value ||
|
|
236
|
+
!/^\/v1\/[a-f0-9]{16}\/[a-f0-9]{16}$/.test(url.pathname)
|
|
237
|
+
)
|
|
238
|
+
throw new Error();
|
|
239
|
+
return value;
|
|
240
|
+
} catch {
|
|
241
|
+
return syntax(
|
|
242
|
+
"Swarm requires an exact /v1/{scope}/{variable} configuration URL; old CID protocol is unsupported.",
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
233
246
|
export function validateUserConfig(
|
|
234
247
|
value: unknown,
|
|
235
248
|
): Partial<Record<ConfigKey, ConfigValue>> {
|
|
@@ -283,7 +296,7 @@ export function effectiveConfig(
|
|
|
283
296
|
): ConfigItem[] {
|
|
284
297
|
if (env.IPAB_SWARM !== undefined)
|
|
285
298
|
syntax(
|
|
286
|
-
"IPAB_SWARM is no longer supported. Remove it and use --swarm
|
|
299
|
+
"IPAB_SWARM is no longer supported. Remove it and use --swarm URL_OR_ALIAS or ipab swarm use URL_OR_ALIAS.",
|
|
287
300
|
);
|
|
288
301
|
if (env.IPAB_STORE_RPC !== undefined)
|
|
289
302
|
syntax(
|
package/src/content-provider.ts
CHANGED
|
@@ -59,6 +59,7 @@ export async function provideContent(
|
|
|
59
59
|
roots: readonly string[],
|
|
60
60
|
endpoint: string,
|
|
61
61
|
fetcher: typeof fetch = fetch,
|
|
62
|
+
authorizationToken?: string,
|
|
62
63
|
): Promise<void> {
|
|
63
64
|
const url = new URL(publicUrl(endpoint));
|
|
64
65
|
if (
|
|
@@ -78,6 +79,9 @@ export async function provideContent(
|
|
|
78
79
|
`${url.toString().replace(/\/$/, "")}/api/v0/dag/import?pin-roots=true`,
|
|
79
80
|
{
|
|
80
81
|
method: "POST",
|
|
82
|
+
...(authorizationToken
|
|
83
|
+
? { headers: { authorization: `Bearer ${authorizationToken}` } }
|
|
84
|
+
: {}),
|
|
81
85
|
body: data,
|
|
82
86
|
redirect: "error",
|
|
83
87
|
signal: AbortSignal.timeout(30_000),
|
|
@@ -113,10 +117,7 @@ export async function bundleJson(store: IpfsStore, root: string) {
|
|
|
113
117
|
});
|
|
114
118
|
const value: unknown = JSON.parse(
|
|
115
119
|
new TextDecoder("utf-8", { fatal: true }).decode(
|
|
116
|
-
await bytes(
|
|
117
|
-
await bundle.readFile(bundle.manifest.entry.path),
|
|
118
|
-
1024 * 1024,
|
|
119
|
-
),
|
|
120
|
+
await bytes(await bundle.readFile(bundle.manifest.entry), 1024 * 1024),
|
|
120
121
|
),
|
|
121
122
|
);
|
|
122
123
|
return { bundle, value };
|
package/src/get.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { dirname, resolve } from "node:path";
|
|
2
|
-
import { lstat } from "node:fs/promises";
|
|
1
|
+
import { dirname, join, resolve } from "node:path";
|
|
2
|
+
import { lstat, mkdtemp, realpath, rmdir } from "node:fs/promises";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
3
4
|
import { openBundle, bundleLimits } from "@ipab/bundle";
|
|
4
5
|
import { CID } from "multiformats/cid";
|
|
5
6
|
import type { IpfsStore } from "@ipab/ipfs-store";
|
|
@@ -10,7 +11,7 @@ import { HostError } from "./errors.js";
|
|
|
10
11
|
export async function getBundle(
|
|
11
12
|
store: IpfsStore,
|
|
12
13
|
cid: string,
|
|
13
|
-
output
|
|
14
|
+
output?: string,
|
|
14
15
|
): Promise<string> {
|
|
15
16
|
await openBundle(CID.parse(cid), {
|
|
16
17
|
resolveCid: (cid) => store.block.get(cid.toString()),
|
|
@@ -51,18 +52,39 @@ export async function getBundle(
|
|
|
51
52
|
}
|
|
52
53
|
};
|
|
53
54
|
await visit(CID.parse(cid), "", 0);
|
|
54
|
-
const directory =
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
|
|
55
|
+
const directory =
|
|
56
|
+
output === undefined
|
|
57
|
+
? await mkdtemp(join(await realpath(tmpdir()), "ipab-get-"))
|
|
58
|
+
: resolve(output);
|
|
59
|
+
try {
|
|
60
|
+
for (let current = directory; ; current = dirname(current)) {
|
|
61
|
+
try {
|
|
62
|
+
const stat = await lstat(current);
|
|
63
|
+
if (stat.isSymbolicLink() || !stat.isDirectory())
|
|
64
|
+
throw new HostError(
|
|
65
|
+
"Download destination must not cross a symlink or file.",
|
|
66
|
+
);
|
|
67
|
+
} catch (cause) {
|
|
68
|
+
if (!nodeError(cause, "ENOENT")) throw cause;
|
|
69
|
+
}
|
|
70
|
+
if (dirname(current) === current) break;
|
|
71
|
+
}
|
|
72
|
+
return await scaffoldFiles(directory, files);
|
|
73
|
+
} catch (cause) {
|
|
74
|
+
const failures: unknown[] = [cause];
|
|
75
|
+
if (output === undefined) {
|
|
76
|
+
try {
|
|
77
|
+
await rmdir(directory);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
failures.push(error);
|
|
80
|
+
}
|
|
64
81
|
}
|
|
65
|
-
if (
|
|
82
|
+
if (failures.length > 1)
|
|
83
|
+
throw new AggregateError(
|
|
84
|
+
failures,
|
|
85
|
+
"Download failed and temporary directory cleanup also failed.",
|
|
86
|
+
{ cause },
|
|
87
|
+
);
|
|
88
|
+
throw cause;
|
|
66
89
|
}
|
|
67
|
-
return scaffoldFiles(directory, files);
|
|
68
90
|
}
|
package/src/identity.ts
CHANGED
|
@@ -29,6 +29,19 @@ export async function protectedPath(
|
|
|
29
29
|
await requireAccountOnly(path);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
export interface ProtectedPath {
|
|
33
|
+
path: string;
|
|
34
|
+
directory?: boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export async function protectedPaths(
|
|
38
|
+
paths: readonly ProtectedPath[],
|
|
39
|
+
): Promise<void> {
|
|
40
|
+
for (const entry of paths)
|
|
41
|
+
await regularPath(entry.path, entry.directory ?? false);
|
|
42
|
+
await requireAccountOnlyMany(paths.map((entry) => entry.path));
|
|
43
|
+
}
|
|
44
|
+
|
|
32
45
|
async function regularPath(path: string, directory: boolean): Promise<void> {
|
|
33
46
|
const stat = await lstat(path);
|
|
34
47
|
if (
|