@ipab/cli 0.1.0-rc.4 → 0.1.0-rc.6
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 +88 -16
- package/dist/app-templates.js +1 -1
- package/dist/app-templates.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/cli.d.ts +6 -2
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +656 -278
- package/dist/cli.js.map +1 -1
- package/dist/config-secret.d.ts +1 -1
- package/dist/config-secret.d.ts.map +1 -1
- package/dist/config-secret.js +2 -73
- package/dist/config-secret.js.map +1 -1
- package/dist/config.d.ts +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +12 -1
- 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 +4 -3
- package/dist/content-provider.js.map +1 -1
- package/dist/context-types.d.ts +12 -0
- package/dist/context-types.d.ts.map +1 -0
- package/dist/context-types.js +2 -0
- package/dist/context-types.js.map +1 -0
- package/dist/context.d.ts +6 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +24 -9
- 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 +3 -2
- package/dist/ipc.d.ts.map +1 -1
- package/dist/ipc.js +33 -9
- package/dist/ipc.js.map +1 -1
- package/dist/kubo-install.d.ts +26 -0
- package/dist/kubo-install.d.ts.map +1 -0
- package/dist/kubo-install.js +724 -0
- package/dist/kubo-install.js.map +1 -0
- package/dist/kubo-peering.d.ts +11 -0
- package/dist/kubo-peering.d.ts.map +1 -0
- package/dist/kubo-peering.js +93 -0
- package/dist/kubo-peering.js.map +1 -0
- package/dist/kubo-peers.d.ts +12 -0
- package/dist/kubo-peers.d.ts.map +1 -0
- package/dist/kubo-peers.js +118 -0
- package/dist/kubo-peers.js.map +1 -0
- package/dist/kubo-release.d.ts +22 -0
- package/dist/kubo-release.d.ts.map +1 -0
- package/dist/kubo-release.js +176 -0
- package/dist/kubo-release.js.map +1 -0
- package/dist/kubo.d.ts +12 -4
- package/dist/kubo.d.ts.map +1 -1
- package/dist/kubo.js +218 -259
- 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 +2 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +4 -2
- package/dist/runtime.js.map +1 -1
- package/dist/state-storage-windows.d.ts +2 -0
- package/dist/state-storage-windows.d.ts.map +1 -0
- package/dist/state-storage-windows.js +114 -0
- package/dist/state-storage-windows.js.map +1 -0
- package/dist/state-storage.d.ts +5 -0
- package/dist/state-storage.d.ts.map +1 -0
- package/dist/state-storage.js +330 -0
- package/dist/state-storage.js.map +1 -0
- package/dist/state.d.ts +42 -8
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +254 -98
- 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 +4 -1
- package/dist/swarm-files.js.map +1 -1
- package/dist/swarm.d.ts +70 -11
- package/dist/swarm.d.ts.map +1 -1
- package/dist/swarm.js +1033 -167
- package/dist/swarm.js.map +1 -1
- package/package.json +4 -4
- package/src/app-templates.ts +1 -1
- package/src/cli.ts +827 -356
- package/src/config-secret.ts +2 -84
- package/src/config.ts +14 -1
- package/src/content-provider.ts +4 -2
- package/src/context-types.ts +11 -0
- package/src/context.ts +39 -9
- package/src/doctor.ts +902 -0
- package/src/identity.ts +10 -10
- package/src/ipc.ts +49 -8
- package/src/kubo-install.ts +936 -0
- package/src/kubo-peering.ts +126 -0
- package/src/kubo-peers.ts +145 -0
- package/src/kubo-release.ts +230 -0
- package/src/kubo.ts +302 -336
- package/src/pins.ts +188 -126
- package/src/publish-source.ts +103 -0
- package/src/runtime.ts +10 -2
- package/src/state-storage-windows.ts +134 -0
- package/src/state-storage.ts +375 -0
- package/src/state.ts +410 -118
- package/src/swarm-envelope.ts +14 -0
- package/src/swarm-files.ts +4 -0
- package/src/swarm.ts +1482 -207
- package/dist/setup.d.ts +0 -7
- package/dist/setup.d.ts.map +0 -1
- package/dist/setup.js +0 -22
- package/dist/setup.js.map +0 -1
- package/src/setup.ts +0 -21
package/src/config-secret.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { HostError, syntax } from "./errors.js";
|
|
1
|
+
import { syntax } from "./errors.js";
|
|
2
|
+
export { verifyStateStorage as secureConfigurationStorage } from "./state-storage.js";
|
|
5
3
|
|
|
6
4
|
export async function readSecretStream(
|
|
7
5
|
input: AsyncIterable<string>,
|
|
@@ -14,83 +12,3 @@ export async function readSecretStream(
|
|
|
14
12
|
}
|
|
15
13
|
return text.trim();
|
|
16
14
|
}
|
|
17
|
-
|
|
18
|
-
function windowsAcl(paths: string[], protect: boolean): void {
|
|
19
|
-
const script = `
|
|
20
|
-
$ErrorActionPreference = 'Stop'
|
|
21
|
-
$sid = [System.Security.Principal.WindowsIdentity]::GetCurrent().User
|
|
22
|
-
foreach ($path in (ConvertFrom-Json $env:IPAB_CONFIG_PATHS)) {
|
|
23
|
-
$acl = Get-Acl -LiteralPath $path
|
|
24
|
-
if ($env:IPAB_CONFIG_PROTECT -eq 'true') {
|
|
25
|
-
if ((Get-Item -LiteralPath $path).PSIsContainer) {
|
|
26
|
-
$acl = New-Object System.Security.AccessControl.DirectorySecurity
|
|
27
|
-
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($sid, 'FullControl', 'ContainerInherit,ObjectInherit', 'None', 'Allow')
|
|
28
|
-
} else {
|
|
29
|
-
$acl = New-Object System.Security.AccessControl.FileSecurity
|
|
30
|
-
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($sid, 'FullControl', 'Allow')
|
|
31
|
-
}
|
|
32
|
-
$acl.SetAccessRuleProtection($true, $false)
|
|
33
|
-
$acl.AddAccessRule($rule)
|
|
34
|
-
if ((Get-Item -LiteralPath $path).PSIsContainer) {
|
|
35
|
-
[System.IO.Directory]::SetAccessControl($path, $acl)
|
|
36
|
-
} else {
|
|
37
|
-
[System.IO.File]::SetAccessControl($path, $acl)
|
|
38
|
-
}
|
|
39
|
-
} else {
|
|
40
|
-
foreach ($rule in $acl.GetAccessRules($true, $true, [System.Security.Principal.SecurityIdentifier])) {
|
|
41
|
-
if ($rule.AccessControlType -eq 'Allow' -and $rule.IdentityReference.Value -ne $sid.Value) {
|
|
42
|
-
throw 'Configuration storage must be account-only'
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}`;
|
|
47
|
-
execFileSync(
|
|
48
|
-
"powershell.exe",
|
|
49
|
-
[
|
|
50
|
-
"-NoProfile",
|
|
51
|
-
"-NonInteractive",
|
|
52
|
-
"-EncodedCommand",
|
|
53
|
-
Buffer.from(script, "utf16le").toString("base64"),
|
|
54
|
-
],
|
|
55
|
-
{
|
|
56
|
-
env: {
|
|
57
|
-
...Object.fromEntries(
|
|
58
|
-
Object.entries(process.env).filter(
|
|
59
|
-
([key]) => key.toLowerCase() !== "psmodulepath",
|
|
60
|
-
),
|
|
61
|
-
),
|
|
62
|
-
IPAB_CONFIG_PATHS: JSON.stringify(paths),
|
|
63
|
-
IPAB_CONFIG_PROTECT: String(protect),
|
|
64
|
-
},
|
|
65
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
66
|
-
},
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
export function secureConfigurationStorage(
|
|
70
|
-
directory: string,
|
|
71
|
-
protect: boolean,
|
|
72
|
-
): void {
|
|
73
|
-
try {
|
|
74
|
-
const paths = [
|
|
75
|
-
directory,
|
|
76
|
-
...["state.sqlite", "state.sqlite-wal", "state.sqlite-shm"].map((file) =>
|
|
77
|
-
join(directory, file),
|
|
78
|
-
),
|
|
79
|
-
].filter((path) => existsSync(path));
|
|
80
|
-
for (const path of paths) {
|
|
81
|
-
const stat = lstatSync(path);
|
|
82
|
-
if (stat.isSymbolicLink() || (!stat.isFile() && !stat.isDirectory()))
|
|
83
|
-
throw new Error();
|
|
84
|
-
if (process.platform !== "win32") {
|
|
85
|
-
if (stat.uid !== process.getuid?.()) throw new Error();
|
|
86
|
-
if (protect) chmodSync(path, stat.isDirectory() ? 0o700 : 0o600);
|
|
87
|
-
else if ((stat.mode & 0o077) !== 0) throw new Error();
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
if (process.platform === "win32") windowsAcl(paths, protect);
|
|
91
|
-
} catch {
|
|
92
|
-
throw new HostError(
|
|
93
|
-
"Pointer API key configuration requires account-only state storage permissions.",
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
}
|
package/src/config.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { homedir } from "node:os";
|
|
2
2
|
import { join, resolve } from "node:path";
|
|
3
|
+
import { CID } from "multiformats/cid";
|
|
3
4
|
import { readContentConfiguration } from "@ipab/ipfs-store/node";
|
|
4
5
|
import type { StoreConfiguration } from "@ipab/ipfs-store";
|
|
5
6
|
import { HostError, object, syntax } from "./errors.js";
|
|
@@ -223,6 +224,17 @@ export function parseValue(
|
|
|
223
224
|
);
|
|
224
225
|
}
|
|
225
226
|
|
|
227
|
+
export function rejectLegacySwarmCid(value: string): void {
|
|
228
|
+
try {
|
|
229
|
+
CID.parse(value);
|
|
230
|
+
} catch {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
throw new HostError(
|
|
234
|
+
"The old Swarm CID protocol is unsupported. Ask the Owner for the Swarm configuration URL.",
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
|
|
226
238
|
export function swarmUrl(value: string): string {
|
|
227
239
|
try {
|
|
228
240
|
const url = new URL(value);
|
|
@@ -238,8 +250,9 @@ export function swarmUrl(value: string): string {
|
|
|
238
250
|
throw new Error();
|
|
239
251
|
return value;
|
|
240
252
|
} catch {
|
|
253
|
+
rejectLegacySwarmCid(value);
|
|
241
254
|
return syntax(
|
|
242
|
-
"Swarm requires an exact /v1/{scope}/{variable} configuration URL
|
|
255
|
+
"Swarm requires an exact /v1/{scope}/{variable} configuration URL (HTTPS or HTTP loopback), with two 16-character lowercase hex IDs and no credentials, query or fragment.",
|
|
243
256
|
);
|
|
244
257
|
}
|
|
245
258
|
}
|
package/src/content-provider.ts
CHANGED
|
@@ -60,6 +60,7 @@ export async function provideContent(
|
|
|
60
60
|
endpoint: string,
|
|
61
61
|
fetcher: typeof fetch = fetch,
|
|
62
62
|
authorizationToken?: string,
|
|
63
|
+
retainedRoots: readonly string[] = roots,
|
|
63
64
|
): Promise<void> {
|
|
64
65
|
const url = new URL(publicUrl(endpoint));
|
|
65
66
|
if (
|
|
@@ -71,8 +72,9 @@ export async function provideContent(
|
|
|
71
72
|
);
|
|
72
73
|
const car = await contentCar(store, roots);
|
|
73
74
|
const owner = `publication:${roots[0]!}`;
|
|
74
|
-
store.registerOwner(owner,
|
|
75
|
-
await store.retain(owner,
|
|
75
|
+
store.registerOwner(owner, retainedRoots);
|
|
76
|
+
await store.retain(owner, retainedRoots);
|
|
77
|
+
await store.confirmRetained(owner, retainedRoots);
|
|
76
78
|
const data = new FormData();
|
|
77
79
|
data.append("file", new Blob([Uint8Array.from(car)]), "content.car");
|
|
78
80
|
const response = await fetcher(
|
package/src/context.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { HostError } from "./errors.js";
|
|
2
2
|
import { CHUNK_BYTES, relativePath } from "./space.js";
|
|
3
3
|
|
|
4
|
+
import type { BundleInspection } from "./context-types.js";
|
|
5
|
+
export type { BundleInspection } from "./context-types.js";
|
|
6
|
+
|
|
4
7
|
export interface AppContext {
|
|
5
8
|
readonly appCid: string;
|
|
6
|
-
|
|
9
|
+
inspectBundle(
|
|
10
|
+
reference: string,
|
|
11
|
+
options?: { signal?: AbortSignal; swarm?: string },
|
|
12
|
+
): Promise<BundleInspection>;
|
|
7
13
|
readFile(
|
|
8
14
|
rootCid: string,
|
|
9
15
|
path: string,
|
|
@@ -127,14 +133,38 @@ export function createContext(port: Port): {
|
|
|
127
133
|
}
|
|
128
134
|
};
|
|
129
135
|
const context: AppContext = {
|
|
130
|
-
async
|
|
131
|
-
if (!
|
|
132
|
-
throw new HostError(
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
136
|
+
async inspectBundle(reference, options = {}) {
|
|
137
|
+
if (!reference || reference.length > 2048)
|
|
138
|
+
throw new HostError(
|
|
139
|
+
"Bundle reference must contain 1..2048 characters.",
|
|
140
|
+
);
|
|
141
|
+
const result = await rpc(
|
|
142
|
+
"inspectBundle",
|
|
143
|
+
{
|
|
144
|
+
reference,
|
|
145
|
+
...(options.swarm ? { swarm: options.swarm } : {}),
|
|
146
|
+
},
|
|
147
|
+
options.signal,
|
|
148
|
+
);
|
|
149
|
+
if (!result || typeof result !== "object")
|
|
150
|
+
throw new HostError("Invalid Bundle inspection response.");
|
|
151
|
+
const data = result as Partial<BundleInspection>;
|
|
152
|
+
if (
|
|
153
|
+
![
|
|
154
|
+
"targetCid",
|
|
155
|
+
"cid",
|
|
156
|
+
"title",
|
|
157
|
+
"description",
|
|
158
|
+
"entry",
|
|
159
|
+
"contentType",
|
|
160
|
+
"schemaCid",
|
|
161
|
+
].every((key) => typeof Reflect.get(data, key) === "string") ||
|
|
162
|
+
!Array.isArray(data.files) ||
|
|
163
|
+
!data.files.every((path) => typeof path === "string") ||
|
|
164
|
+
(data.swarm !== undefined && typeof data.swarm !== "string")
|
|
165
|
+
)
|
|
166
|
+
throw new HostError("Invalid Bundle inspection response.");
|
|
167
|
+
return data as BundleInspection;
|
|
138
168
|
},
|
|
139
169
|
get appCid() {
|
|
140
170
|
if (!appCid)
|