@ipab/cli 0.1.0-rc.2 → 0.1.0-rc.3
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 +35 -14
- 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 +306 -116
- 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 +19 -15
- 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/kubo.d.ts +38 -0
- package/dist/kubo.d.ts.map +1 -0
- package/dist/kubo.js +528 -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 +4 -4
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +11 -12
- 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 +5 -0
- package/dist/swarm-files.d.ts.map +1 -0
- package/dist/swarm-files.js +94 -0
- package/dist/swarm-files.js.map +1 -0
- package/dist/swarm.d.ts +117 -57
- package/dist/swarm.d.ts.map +1 -1
- package/dist/swarm.js +1033 -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 +362 -139
- package/src/config.ts +22 -18
- package/src/content-provider.ts +5 -4
- package/src/get.ts +37 -15
- package/src/kubo.ts +691 -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 +14 -13
- package/src/swarm-envelope.ts +255 -0
- package/src/swarm-files.ts +100 -0
- package/src/swarm.ts +1676 -837
- 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,6 @@ import { HostError, object, syntax } from "./errors.js";
|
|
|
7
6
|
|
|
8
7
|
export type ConfigKey =
|
|
9
8
|
| "swarm.default"
|
|
10
|
-
| "swarm.service"
|
|
11
|
-
| "swarm.provider"
|
|
12
9
|
| "swarm.cacheTtl"
|
|
13
10
|
| "swarm.forceRefresh"
|
|
14
11
|
| "store.gateway"
|
|
@@ -33,8 +30,6 @@ export interface ConfigItem {
|
|
|
33
30
|
}
|
|
34
31
|
export const defaults: Record<ConfigKey, ConfigValue> = {
|
|
35
32
|
"swarm.default": null,
|
|
36
|
-
"swarm.service": null,
|
|
37
|
-
"swarm.provider": "http://127.0.0.1:5001",
|
|
38
33
|
"swarm.cacheTtl": 300,
|
|
39
34
|
"swarm.forceRefresh": false,
|
|
40
35
|
"store.gateway": null,
|
|
@@ -46,8 +41,6 @@ export const defaults: Record<ConfigKey, ConfigValue> = {
|
|
|
46
41
|
"bundle.outputDir": "dist",
|
|
47
42
|
};
|
|
48
43
|
const environments: Partial<Record<ConfigKey, string>> = {
|
|
49
|
-
"swarm.service": "IPAB_SWARM_SERVICE",
|
|
50
|
-
"swarm.provider": "IPAB_SWARM_PROVIDER",
|
|
51
44
|
"swarm.cacheTtl": "IPAB_SWARM_CACHE_TTL",
|
|
52
45
|
"swarm.forceRefresh": "IPAB_SWARM_FORCE_REFRESH",
|
|
53
46
|
"store.gateway": "IPAB_STORE_GATEWAY",
|
|
@@ -184,17 +177,8 @@ export function parseValue(
|
|
|
184
177
|
}
|
|
185
178
|
if (key.startsWith("swarm.") && value === null) return null;
|
|
186
179
|
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
|
-
}
|
|
180
|
+
return swarmUrl(value);
|
|
192
181
|
}
|
|
193
|
-
if (
|
|
194
|
-
(key === "swarm.service" || key === "swarm.provider") &&
|
|
195
|
-
typeof value === "string"
|
|
196
|
-
)
|
|
197
|
-
return publicUrl(value);
|
|
198
182
|
if (key === "store.gateway" && value === null) return null;
|
|
199
183
|
if (
|
|
200
184
|
key === "bundle.outputDir" &&
|
|
@@ -230,6 +214,26 @@ export function parseValue(
|
|
|
230
214
|
);
|
|
231
215
|
}
|
|
232
216
|
|
|
217
|
+
export function swarmUrl(value: string): string {
|
|
218
|
+
try {
|
|
219
|
+
const url = new URL(value);
|
|
220
|
+
pointerService(url.origin);
|
|
221
|
+
if (
|
|
222
|
+
url.username ||
|
|
223
|
+
url.password ||
|
|
224
|
+
url.search ||
|
|
225
|
+
url.hash ||
|
|
226
|
+
url.toString() !== value ||
|
|
227
|
+
!/^\/v1\/[A-Za-z0-9_-]{43}\/[A-Za-z0-9_-]{43}$/.test(url.pathname)
|
|
228
|
+
)
|
|
229
|
+
throw new Error();
|
|
230
|
+
return value;
|
|
231
|
+
} catch {
|
|
232
|
+
return syntax(
|
|
233
|
+
"Swarm requires an exact /v1/{scope}/{variable} configuration URL; old CID protocol is unsupported.",
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
233
237
|
export function validateUserConfig(
|
|
234
238
|
value: unknown,
|
|
235
239
|
): Partial<Record<ConfigKey, ConfigValue>> {
|
|
@@ -283,7 +287,7 @@ export function effectiveConfig(
|
|
|
283
287
|
): ConfigItem[] {
|
|
284
288
|
if (env.IPAB_SWARM !== undefined)
|
|
285
289
|
syntax(
|
|
286
|
-
"IPAB_SWARM is no longer supported. Remove it and use --swarm
|
|
290
|
+
"IPAB_SWARM is no longer supported. Remove it and use --swarm URL_OR_ALIAS or ipab swarm use URL_OR_ALIAS.",
|
|
287
291
|
);
|
|
288
292
|
if (env.IPAB_STORE_RPC !== undefined)
|
|
289
293
|
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
|
}
|