@ipab/cli 0.1.0-rc.5 → 0.1.0-rc.7
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 +128 -22
- package/dist/app-authoring.d.ts +5 -0
- package/dist/app-authoring.d.ts.map +1 -1
- package/dist/app-authoring.js +4 -1
- package/dist/app-authoring.js.map +1 -1
- package/dist/app-templates.d.ts +0 -1
- package/dist/app-templates.d.ts.map +1 -1
- package/dist/app-templates.js +6 -45
- package/dist/app-templates.js.map +1 -1
- package/dist/builtins/skill.ipab.car +0 -0
- 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/builtins.d.ts.map +1 -1
- package/dist/builtins.js +1 -39
- package/dist/builtins.js.map +1 -1
- package/dist/cli.d.ts +4 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +934 -336
- package/dist/cli.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 +4 -3
- package/dist/content-provider.js.map +1 -1
- package/dist/context.d.ts +16 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +20 -10
- package/dist/context.js.map +1 -1
- package/dist/doctor.d.ts +29 -0
- package/dist/doctor.d.ts.map +1 -0
- package/dist/doctor.js +576 -0
- package/dist/doctor.js.map +1 -0
- package/dist/identity.d.ts +1 -1
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +9 -9
- package/dist/identity.js.map +1 -1
- package/dist/ipc.d.ts +2 -2
- package/dist/ipc.d.ts.map +1 -1
- package/dist/ipc.js +44 -12
- package/dist/ipc.js.map +1 -1
- package/dist/kubo-install.d.ts +18 -1
- package/dist/kubo-install.d.ts.map +1 -1
- package/dist/kubo-install.js +424 -61
- package/dist/kubo-install.js.map +1 -1
- package/dist/kubo-release.d.ts +19 -0
- package/dist/kubo-release.d.ts.map +1 -1
- package/dist/kubo-release.js +164 -0
- package/dist/kubo-release.js.map +1 -1
- package/dist/kubo.d.ts +1 -0
- package/dist/kubo.d.ts.map +1 -1
- package/dist/kubo.js +102 -96
- package/dist/kubo.js.map +1 -1
- package/dist/pins.d.ts +15 -17
- package/dist/pins.d.ts.map +1 -1
- package/dist/pins.js +144 -106
- package/dist/pins.js.map +1 -1
- package/dist/publish-source.d.ts +3 -0
- package/dist/publish-source.d.ts.map +1 -0
- package/dist/publish-source.js +85 -0
- package/dist/publish-source.js.map +1 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +6 -5
- package/dist/runtime.js.map +1 -1
- package/dist/skill-definition.d.ts +6 -0
- package/dist/skill-definition.d.ts.map +1 -0
- package/dist/skill-definition.js +38 -0
- package/dist/skill-definition.js.map +1 -0
- package/dist/skill-source.d.ts +5 -0
- package/dist/skill-source.d.ts.map +1 -0
- package/dist/skill-source.js +12 -0
- package/dist/skill-source.js.map +1 -0
- package/dist/skills.d.ts +84 -0
- package/dist/skills.d.ts.map +1 -0
- package/dist/skills.js +736 -0
- package/dist/skills.js.map +1 -0
- package/dist/space.d.ts +15 -2
- package/dist/space.d.ts.map +1 -1
- package/dist/space.js +153 -3
- package/dist/space.js.map +1 -1
- package/dist/state-storage-windows.js +1 -1
- package/dist/state-storage.d.ts +3 -1
- package/dist/state-storage.d.ts.map +1 -1
- package/dist/state-storage.js +38 -7
- package/dist/state-storage.js.map +1 -1
- package/dist/state.d.ts +40 -6
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +208 -82
- package/dist/state.js.map +1 -1
- package/dist/swarm-envelope.d.ts +1 -0
- package/dist/swarm-envelope.d.ts.map +1 -1
- package/dist/swarm-envelope.js +12 -0
- package/dist/swarm-envelope.js.map +1 -1
- package/dist/swarm-files.d.ts +1 -1
- package/dist/swarm-files.d.ts.map +1 -1
- package/dist/swarm-files.js +2 -2
- package/dist/swarm-files.js.map +1 -1
- package/dist/swarm-meta.d.ts +17 -0
- package/dist/swarm-meta.d.ts.map +1 -0
- package/dist/swarm-meta.js +96 -0
- package/dist/swarm-meta.js.map +1 -0
- package/dist/swarm.d.ts +117 -8
- package/dist/swarm.d.ts.map +1 -1
- package/dist/swarm.js +1275 -131
- package/dist/swarm.js.map +1 -1
- package/dist/template-paths.d.ts +7 -0
- package/dist/template-paths.d.ts.map +1 -0
- package/dist/template-paths.js +23 -0
- package/dist/template-paths.js.map +1 -0
- package/dist/template-presentation.d.ts +20 -0
- package/dist/template-presentation.d.ts.map +1 -0
- package/dist/template-presentation.js +133 -0
- package/dist/template-presentation.js.map +1 -0
- package/dist/template-source.d.ts +2 -1
- package/dist/template-source.d.ts.map +1 -1
- package/dist/template-source.js +7 -1
- package/dist/template-source.js.map +1 -1
- package/dist/templates.d.ts +11 -0
- package/dist/templates.d.ts.map +1 -0
- package/dist/templates.js +53 -0
- package/dist/templates.js.map +1 -0
- package/package.json +7 -6
- package/src/app-authoring.ts +18 -2
- package/src/app-templates.ts +8 -72
- package/src/builtins.ts +2 -48
- package/src/cli.ts +1154 -387
- package/src/content-provider.ts +4 -2
- package/src/context.ts +45 -10
- package/src/doctor.ts +902 -0
- package/src/identity.ts +10 -10
- package/src/ipc.ts +63 -10
- package/src/kubo-install.ts +562 -78
- package/src/kubo-release.ts +213 -0
- package/src/kubo.ts +134 -106
- package/src/pins.ts +188 -126
- package/src/publish-source.ts +103 -0
- package/src/runtime.ts +6 -5
- package/src/skill-definition.ts +53 -0
- package/src/skill-source.ts +15 -0
- package/src/skills.ts +1005 -0
- package/src/space.ts +214 -5
- package/src/state-storage-windows.ts +1 -1
- package/src/state-storage.ts +53 -7
- package/src/state.ts +357 -98
- package/src/swarm-envelope.ts +14 -0
- package/src/swarm-files.ts +2 -1
- package/src/swarm-meta.ts +109 -0
- package/src/swarm.ts +1877 -175
- package/src/template-paths.ts +43 -0
- package/src/template-presentation.ts +151 -0
- package/src/template-source.ts +9 -2
- package/src/templates.ts +77 -0
- package/dist/setup.d.ts +0 -8
- package/dist/setup.d.ts.map +0 -1
- package/dist/setup.js +0 -27
- package/dist/setup.js.map +0 -1
- package/src/setup.ts +0 -34
package/src/identity.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { homedir } from "node:os";
|
|
|
3
3
|
import { join, resolve } from "node:path";
|
|
4
4
|
import {
|
|
5
5
|
protectAccountOnly,
|
|
6
|
-
requireAccountOnly,
|
|
7
6
|
requireAccountOnlyMany,
|
|
8
7
|
} from "@ipab/bundle/pointer/protected-files";
|
|
9
8
|
import {
|
|
@@ -26,7 +25,6 @@ export async function protectedPath(
|
|
|
26
25
|
directory = false,
|
|
27
26
|
): Promise<void> {
|
|
28
27
|
await regularPath(path, directory);
|
|
29
|
-
await requireAccountOnly(path);
|
|
30
28
|
}
|
|
31
29
|
|
|
32
30
|
export interface ProtectedPath {
|
|
@@ -39,7 +37,6 @@ export async function protectedPaths(
|
|
|
39
37
|
): Promise<void> {
|
|
40
38
|
for (const entry of paths)
|
|
41
39
|
await regularPath(entry.path, entry.directory ?? false);
|
|
42
|
-
await requireAccountOnlyMany(paths.map((entry) => entry.path));
|
|
43
40
|
}
|
|
44
41
|
|
|
45
42
|
async function regularPath(path: string, directory: boolean): Promise<void> {
|
|
@@ -66,14 +63,15 @@ export async function readIdentityFile(path: string): Promise<Identity> {
|
|
|
66
63
|
return decodeIdentityFile(path);
|
|
67
64
|
}
|
|
68
65
|
async function decodeIdentityFile(path: string): Promise<Identity> {
|
|
66
|
+
const stat = await lstat(path);
|
|
67
|
+
if (stat.size > 16 * 1024)
|
|
68
|
+
throw new HostError(
|
|
69
|
+
"Invalid credential encoding. Restore the existing protected key file.",
|
|
70
|
+
);
|
|
71
|
+
const text = await readFile(path, "utf8");
|
|
69
72
|
let value: Record<string, unknown>;
|
|
70
73
|
try {
|
|
71
|
-
|
|
72
|
-
if (stat.size > 16 * 1024) throw new Error("oversized");
|
|
73
|
-
value = object(
|
|
74
|
-
JSON.parse(await readFile(path, "utf8")) as unknown,
|
|
75
|
-
"identity",
|
|
76
|
-
);
|
|
74
|
+
value = object(JSON.parse(text) as unknown, "identity");
|
|
77
75
|
} catch {
|
|
78
76
|
throw new HostError(
|
|
79
77
|
"Invalid credential encoding. Restore the existing protected key file.",
|
|
@@ -102,6 +100,7 @@ async function decodeIdentityFile(path: string): Promise<Identity> {
|
|
|
102
100
|
export async function accountIdentity(
|
|
103
101
|
env: NodeJS.ProcessEnv,
|
|
104
102
|
initialize = false,
|
|
103
|
+
verifyPermissions = false,
|
|
105
104
|
): Promise<Identity> {
|
|
106
105
|
const home = resolve(env.HOME ?? env.USERPROFILE ?? homedir());
|
|
107
106
|
const parent = join(home, ".ipab");
|
|
@@ -141,6 +140,7 @@ export async function accountIdentity(
|
|
|
141
140
|
await regularPath(parent, true);
|
|
142
141
|
await regularPath(directory, true);
|
|
143
142
|
await regularPath(file, false);
|
|
144
|
-
|
|
143
|
+
if (verifyPermissions)
|
|
144
|
+
await requireAccountOnlyMany([parent, directory, file]);
|
|
145
145
|
return decodeIdentityFile(file);
|
|
146
146
|
}
|
package/src/ipc.ts
CHANGED
|
@@ -4,7 +4,12 @@ import { openBundle } from "@ipab/bundle";
|
|
|
4
4
|
import { CID } from "multiformats/cid";
|
|
5
5
|
import { HostError, message, object } from "./errors.js";
|
|
6
6
|
import { requestFrame, type BundleInspection, type Reply } from "./context.js";
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
CHUNK_BYTES,
|
|
9
|
+
deriveBundle,
|
|
10
|
+
type OutputSpace,
|
|
11
|
+
relativePath,
|
|
12
|
+
} from "./space.js";
|
|
8
13
|
import type { Ownership } from "./history.js";
|
|
9
14
|
|
|
10
15
|
class ByteQueue implements AsyncIterable<Uint8Array> {
|
|
@@ -76,14 +81,12 @@ export class ContextServer {
|
|
|
76
81
|
readonly output: OutputSpace,
|
|
77
82
|
readonly fatal: (error: Error) => void,
|
|
78
83
|
readonly appCid: string,
|
|
79
|
-
readonly resolvePin: (name: string) => string | undefined = () => {
|
|
80
|
-
throw new HostError("Pin lookup is unavailable in this context.");
|
|
81
|
-
},
|
|
82
84
|
readonly resolveBundleReference?: (
|
|
83
85
|
reference: string,
|
|
84
86
|
signal: AbortSignal,
|
|
85
87
|
swarm?: string,
|
|
86
88
|
) => Promise<Pick<BundleInspection, "cid" | "targetCid" | "swarm">>,
|
|
89
|
+
readonly supportedTypes?: ReadonlySet<string>,
|
|
87
90
|
) {
|
|
88
91
|
child.on("message", this.receive);
|
|
89
92
|
}
|
|
@@ -125,8 +128,14 @@ export class ContextServer {
|
|
|
125
128
|
if (controller.signal.aborted) {
|
|
126
129
|
if (frame.operation === "read")
|
|
127
130
|
await this.cancelRead(Number(result), controller.signal.reason);
|
|
128
|
-
if (
|
|
131
|
+
if (
|
|
132
|
+
["link", "beginOpenSession", "cancelOpenSession"].includes(
|
|
133
|
+
frame.operation,
|
|
134
|
+
)
|
|
135
|
+
)
|
|
129
136
|
this.output.fail(controller.signal.reason);
|
|
137
|
+
if (frame.operation === "submitBundleResult")
|
|
138
|
+
this.output.discardBundleResult();
|
|
130
139
|
controller.signal.throwIfAborted();
|
|
131
140
|
}
|
|
132
141
|
return result;
|
|
@@ -162,6 +171,55 @@ export class ContextServer {
|
|
|
162
171
|
): Promise<unknown> {
|
|
163
172
|
signal.throwIfAborted();
|
|
164
173
|
if (operation === "identity") return this.appCid;
|
|
174
|
+
if (operation === "deriveBundle") {
|
|
175
|
+
const data = object(args, "Bundle derivation request");
|
|
176
|
+
if (typeof data.inputCid !== "string")
|
|
177
|
+
throw new HostError("Bundle derivation requires an exact input CID.");
|
|
178
|
+
return deriveBundle(
|
|
179
|
+
data.inputCid,
|
|
180
|
+
data.replacements,
|
|
181
|
+
this.store,
|
|
182
|
+
this.owner,
|
|
183
|
+
signal,
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
if (
|
|
187
|
+
["beginOpenSession", "submitBundleResult", "cancelOpenSession"].includes(
|
|
188
|
+
operation,
|
|
189
|
+
)
|
|
190
|
+
) {
|
|
191
|
+
let validSubmission = false;
|
|
192
|
+
try {
|
|
193
|
+
if (operation === "cancelOpenSession") this.output.cancelOpenSession();
|
|
194
|
+
else {
|
|
195
|
+
const data = object(args, "Bundle result request");
|
|
196
|
+
const cid =
|
|
197
|
+
operation === "beginOpenSession" ? data.inputCid : data.cid;
|
|
198
|
+
if (typeof cid !== "string") {
|
|
199
|
+
const error = new HostError("Bundle result requires an exact CID.");
|
|
200
|
+
this.output.fail(error);
|
|
201
|
+
throw error;
|
|
202
|
+
}
|
|
203
|
+
if (operation === "beginOpenSession")
|
|
204
|
+
await this.output.beginOpenSession(
|
|
205
|
+
cid,
|
|
206
|
+
signal,
|
|
207
|
+
this.supportedTypes,
|
|
208
|
+
data.supportedTypes,
|
|
209
|
+
);
|
|
210
|
+
else {
|
|
211
|
+
validSubmission = true;
|
|
212
|
+
await this.output.submitBundleResult(cid, signal);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
signal.throwIfAborted();
|
|
216
|
+
return null;
|
|
217
|
+
} catch (error) {
|
|
218
|
+
if (!validSubmission) this.output.fail(error);
|
|
219
|
+
else if (signal.aborted) this.output.discardBundleResult();
|
|
220
|
+
throw error;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
165
223
|
if (operation === "inspectBundle") {
|
|
166
224
|
const request = object(args, "Bundle inspection request");
|
|
167
225
|
if (
|
|
@@ -205,11 +263,6 @@ export class ContextServer {
|
|
|
205
263
|
throw new HostError("Bundle inspection exceeds 1 MiB.");
|
|
206
264
|
return result;
|
|
207
265
|
}
|
|
208
|
-
if (operation === "resolvePin") {
|
|
209
|
-
if (typeof args !== "string" || !args || args.length > 256)
|
|
210
|
-
throw new HostError("Pin name must contain 1..256 characters.");
|
|
211
|
-
return this.resolvePin(args) ?? null;
|
|
212
|
-
}
|
|
213
266
|
if (operation === "read") {
|
|
214
267
|
if (this.reads.size + this.writes.size + this.openingReads >= 32)
|
|
215
268
|
throw new HostError("Context stream capacity exceeded.");
|