@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.
Files changed (128) hide show
  1. package/README.md +88 -16
  2. package/dist/app-templates.js +1 -1
  3. package/dist/app-templates.js.map +1 -1
  4. package/dist/builtins/skill.ipab.car +0 -0
  5. package/dist/builtins/template.node.car +0 -0
  6. package/dist/builtins/template.web-app.car +0 -0
  7. package/dist/cli.d.ts +6 -2
  8. package/dist/cli.d.ts.map +1 -1
  9. package/dist/cli.js +656 -278
  10. package/dist/cli.js.map +1 -1
  11. package/dist/config-secret.d.ts +1 -1
  12. package/dist/config-secret.d.ts.map +1 -1
  13. package/dist/config-secret.js +2 -73
  14. package/dist/config-secret.js.map +1 -1
  15. package/dist/config.d.ts +1 -0
  16. package/dist/config.d.ts.map +1 -1
  17. package/dist/config.js +12 -1
  18. package/dist/config.js.map +1 -1
  19. package/dist/content-provider.d.ts +1 -1
  20. package/dist/content-provider.d.ts.map +1 -1
  21. package/dist/content-provider.js +4 -3
  22. package/dist/content-provider.js.map +1 -1
  23. package/dist/context-types.d.ts +12 -0
  24. package/dist/context-types.d.ts.map +1 -0
  25. package/dist/context-types.js +2 -0
  26. package/dist/context-types.js.map +1 -0
  27. package/dist/context.d.ts +6 -1
  28. package/dist/context.d.ts.map +1 -1
  29. package/dist/context.js +24 -9
  30. package/dist/context.js.map +1 -1
  31. package/dist/doctor.d.ts +29 -0
  32. package/dist/doctor.d.ts.map +1 -0
  33. package/dist/doctor.js +576 -0
  34. package/dist/doctor.js.map +1 -0
  35. package/dist/identity.d.ts +1 -1
  36. package/dist/identity.d.ts.map +1 -1
  37. package/dist/identity.js +9 -9
  38. package/dist/identity.js.map +1 -1
  39. package/dist/ipc.d.ts +3 -2
  40. package/dist/ipc.d.ts.map +1 -1
  41. package/dist/ipc.js +33 -9
  42. package/dist/ipc.js.map +1 -1
  43. package/dist/kubo-install.d.ts +26 -0
  44. package/dist/kubo-install.d.ts.map +1 -0
  45. package/dist/kubo-install.js +724 -0
  46. package/dist/kubo-install.js.map +1 -0
  47. package/dist/kubo-peering.d.ts +11 -0
  48. package/dist/kubo-peering.d.ts.map +1 -0
  49. package/dist/kubo-peering.js +93 -0
  50. package/dist/kubo-peering.js.map +1 -0
  51. package/dist/kubo-peers.d.ts +12 -0
  52. package/dist/kubo-peers.d.ts.map +1 -0
  53. package/dist/kubo-peers.js +118 -0
  54. package/dist/kubo-peers.js.map +1 -0
  55. package/dist/kubo-release.d.ts +22 -0
  56. package/dist/kubo-release.d.ts.map +1 -0
  57. package/dist/kubo-release.js +176 -0
  58. package/dist/kubo-release.js.map +1 -0
  59. package/dist/kubo.d.ts +12 -4
  60. package/dist/kubo.d.ts.map +1 -1
  61. package/dist/kubo.js +218 -259
  62. package/dist/kubo.js.map +1 -1
  63. package/dist/pins.d.ts +15 -17
  64. package/dist/pins.d.ts.map +1 -1
  65. package/dist/pins.js +144 -106
  66. package/dist/pins.js.map +1 -1
  67. package/dist/publish-source.d.ts +3 -0
  68. package/dist/publish-source.d.ts.map +1 -0
  69. package/dist/publish-source.js +85 -0
  70. package/dist/publish-source.js.map +1 -0
  71. package/dist/runtime.d.ts +2 -0
  72. package/dist/runtime.d.ts.map +1 -1
  73. package/dist/runtime.js +4 -2
  74. package/dist/runtime.js.map +1 -1
  75. package/dist/state-storage-windows.d.ts +2 -0
  76. package/dist/state-storage-windows.d.ts.map +1 -0
  77. package/dist/state-storage-windows.js +114 -0
  78. package/dist/state-storage-windows.js.map +1 -0
  79. package/dist/state-storage.d.ts +5 -0
  80. package/dist/state-storage.d.ts.map +1 -0
  81. package/dist/state-storage.js +330 -0
  82. package/dist/state-storage.js.map +1 -0
  83. package/dist/state.d.ts +42 -8
  84. package/dist/state.d.ts.map +1 -1
  85. package/dist/state.js +254 -98
  86. package/dist/state.js.map +1 -1
  87. package/dist/swarm-envelope.d.ts +1 -0
  88. package/dist/swarm-envelope.d.ts.map +1 -1
  89. package/dist/swarm-envelope.js +12 -0
  90. package/dist/swarm-envelope.js.map +1 -1
  91. package/dist/swarm-files.d.ts +1 -1
  92. package/dist/swarm-files.d.ts.map +1 -1
  93. package/dist/swarm-files.js +4 -1
  94. package/dist/swarm-files.js.map +1 -1
  95. package/dist/swarm.d.ts +70 -11
  96. package/dist/swarm.d.ts.map +1 -1
  97. package/dist/swarm.js +1033 -167
  98. package/dist/swarm.js.map +1 -1
  99. package/package.json +4 -4
  100. package/src/app-templates.ts +1 -1
  101. package/src/cli.ts +827 -356
  102. package/src/config-secret.ts +2 -84
  103. package/src/config.ts +14 -1
  104. package/src/content-provider.ts +4 -2
  105. package/src/context-types.ts +11 -0
  106. package/src/context.ts +39 -9
  107. package/src/doctor.ts +902 -0
  108. package/src/identity.ts +10 -10
  109. package/src/ipc.ts +49 -8
  110. package/src/kubo-install.ts +936 -0
  111. package/src/kubo-peering.ts +126 -0
  112. package/src/kubo-peers.ts +145 -0
  113. package/src/kubo-release.ts +230 -0
  114. package/src/kubo.ts +302 -336
  115. package/src/pins.ts +188 -126
  116. package/src/publish-source.ts +103 -0
  117. package/src/runtime.ts +10 -2
  118. package/src/state-storage-windows.ts +134 -0
  119. package/src/state-storage.ts +375 -0
  120. package/src/state.ts +410 -118
  121. package/src/swarm-envelope.ts +14 -0
  122. package/src/swarm-files.ts +4 -0
  123. package/src/swarm.ts +1482 -207
  124. package/dist/setup.d.ts +0 -7
  125. package/dist/setup.d.ts.map +0 -1
  126. package/dist/setup.js +0 -22
  127. package/dist/setup.js.map +0 -1
  128. package/src/setup.ts +0 -21
@@ -1,7 +1,5 @@
1
- import { chmodSync, existsSync, lstatSync } from "node:fs";
2
- import { execFileSync } from "node:child_process";
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; old CID protocol is unsupported.",
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
  }
@@ -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, roots);
75
- await store.retain(owner, roots);
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(
@@ -0,0 +1,11 @@
1
+ export interface BundleInspection {
2
+ targetCid: string;
3
+ cid: string;
4
+ title: string;
5
+ description: string;
6
+ entry: string;
7
+ contentType: string;
8
+ schemaCid: string;
9
+ files: string[];
10
+ swarm?: string;
11
+ }
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
- resolvePin(name: string): Promise<string | undefined>;
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 resolvePin(name) {
131
- if (!name || name.length > 256)
132
- throw new HostError("Pin name must contain 1..256 characters.");
133
- const result = await rpc("resolvePin", name);
134
- if (result === null) return undefined;
135
- if (typeof result !== "string")
136
- throw new HostError("Invalid pin lookup response.");
137
- return result;
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)