@disposabl/cli 2.0.0 → 2.1.0
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 +2 -0
- package/dist/index.js +45 -11
- package/dist/verify-metadata.mjs +64 -0
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -39,4 +39,6 @@ The command exits unsuccessfully while manual cleanup is pending. Rerun the same
|
|
|
39
39
|
|
|
40
40
|
When configured for a published release, Disposabl collects the command category, outcome, package version, operating system and package-manager category. A random ID stored in `~/.config/disposabl/telemetry.json` connects anonymous usage to the Disposabl user ID after login. Logout and account changes reset that ID. Prompts, arguments, paths, error messages, credentials and email addresses are not collected. Set `DO_NOT_TRACK=1` or `DISPOSABL_TELEMETRY_DISABLED=1` to opt out. Local source, development, CI and E2E runs do not send events. This is separate from a generated app's analytics.
|
|
41
41
|
|
|
42
|
+
Failed commands also send a fixed, coarse error-tracking event with no exception message or stack trace.
|
|
43
|
+
|
|
42
44
|
Release builds must supply the central public PostHog project token in `DISPOSABL_CLI_POSTHOG_PROJECT_TOKEN` and its ingestion host in `DISPOSABL_CLI_POSTHOG_HOST` (US or EU PostHog ingestion origin) at build time. The build embeds these public values and rejects a release without them. Set `DISPOSABL_CLI_TELEMETRY_REQUIRED=1` to enforce the same check on a development-version qualification build. Development builds without this configuration remain inert. Do not use a personal API key or an app owner's project token. Configure the central PostHog project to disable IP data capture.
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// auth.ts
|
|
4
4
|
import { lock } from "proper-lockfile";
|
|
5
5
|
// package.json
|
|
6
|
-
var version = "2.
|
|
6
|
+
var version = "2.1.0";
|
|
7
7
|
var package_default = {
|
|
8
8
|
name: "@disposabl/cli",
|
|
9
9
|
version,
|
|
@@ -27,7 +27,8 @@ var package_default = {
|
|
|
27
27
|
build: "bun build.ts",
|
|
28
28
|
typecheck: "bun check",
|
|
29
29
|
lint: "bun check",
|
|
30
|
-
release: "semantic-release"
|
|
30
|
+
release: "semantic-release",
|
|
31
|
+
prepack: "node dist/verify-metadata.mjs"
|
|
31
32
|
},
|
|
32
33
|
dependencies: {
|
|
33
34
|
"@modelcontextprotocol/sdk": "1.32.2",
|
|
@@ -44,7 +45,7 @@ var package_default = {
|
|
|
44
45
|
},
|
|
45
46
|
repository: {
|
|
46
47
|
type: "git",
|
|
47
|
-
url: "https://
|
|
48
|
+
url: "git+https://github.com/disposabl-dev/create-disposabl-app.git",
|
|
48
49
|
directory: "packages/cli"
|
|
49
50
|
}
|
|
50
51
|
};
|
|
@@ -321,10 +322,13 @@ Sign in to Expo if needed and choose Delete project. Then rerun this command to
|
|
|
321
322
|
openUrl(url.href);
|
|
322
323
|
}
|
|
323
324
|
|
|
325
|
+
// commands.ts
|
|
326
|
+
import { CommanderError } from "commander";
|
|
327
|
+
|
|
324
328
|
// telemetry.ts
|
|
325
329
|
import { createHash as createHash2, randomUUID } from "node:crypto";
|
|
326
330
|
import { realpathSync } from "node:fs";
|
|
327
|
-
import { mkdir as mkdir2, readFile as readFile2, rm as rm2, writeFile as writeFile2 } from "node:fs/promises";
|
|
331
|
+
import { mkdir as mkdir2, open, readFile as readFile2, rm as rm2, writeFile as writeFile2 } from "node:fs/promises";
|
|
328
332
|
import { homedir as homedir2 } from "node:os";
|
|
329
333
|
import { dirname, join as join2 } from "node:path";
|
|
330
334
|
import { lock as lock2 } from "proper-lockfile";
|
|
@@ -390,6 +394,18 @@ async function send(config, event, distinctId, properties) {
|
|
|
390
394
|
});
|
|
391
395
|
return response.ok;
|
|
392
396
|
}
|
|
397
|
+
async function firstExecution(path, product, version) {
|
|
398
|
+
try {
|
|
399
|
+
const directory = join2(dirname(path), "activations");
|
|
400
|
+
await mkdir2(directory, { recursive: true, mode: 448 });
|
|
401
|
+
const name = createHash2("sha256").update(`${product}:${version}`).digest("hex");
|
|
402
|
+
const file = await open(join2(directory, name), "wx", 384);
|
|
403
|
+
await file.close();
|
|
404
|
+
return true;
|
|
405
|
+
} catch {
|
|
406
|
+
return false;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
393
409
|
async function capture(version, product, command, outcome, path) {
|
|
394
410
|
const config = telemetryConfig(version);
|
|
395
411
|
if (!config)
|
|
@@ -411,15 +427,29 @@ async function capture(version, product, command, outcome, path) {
|
|
|
411
427
|
"other",
|
|
412
428
|
"create"
|
|
413
429
|
];
|
|
414
|
-
|
|
430
|
+
const distinctId = current.userId ?? current.anonymousId;
|
|
431
|
+
const activation = outcome === "started" && await firstExecution(path, product, version);
|
|
432
|
+
const properties = {
|
|
415
433
|
product,
|
|
416
434
|
command: allowed.includes(command) ? command : "other",
|
|
417
435
|
outcome,
|
|
418
436
|
version,
|
|
437
|
+
...activation ? { first_execution: true } : {},
|
|
419
438
|
invocation: process.env.npm_command === "exec" ? "npx" : /^(npm|pnpm|yarn|bun)\//.exec(process.env.npm_config_user_agent ?? "")?.[1] ?? "direct",
|
|
420
439
|
platform: ["darwin", "linux", "win32"].includes(process.platform) ? process.platform : "other",
|
|
421
440
|
...!current.userId ? { $process_person_profile: false } : {}
|
|
422
|
-
}
|
|
441
|
+
};
|
|
442
|
+
const pending = [send(config, "cli_command", distinctId, properties)];
|
|
443
|
+
if (outcome === "failure") {
|
|
444
|
+
pending.push(send(config, "$exception", distinctId, {
|
|
445
|
+
...properties,
|
|
446
|
+
$exception_list: [
|
|
447
|
+
{ type: "CommandFailure", value: "Command failed" }
|
|
448
|
+
],
|
|
449
|
+
$exception_fingerprint: `disposabl-${product}-${properties.command}`
|
|
450
|
+
}));
|
|
451
|
+
}
|
|
452
|
+
await Promise.allSettled(pending);
|
|
423
453
|
} catch {}
|
|
424
454
|
}
|
|
425
455
|
async function prepareLogin(path) {
|
|
@@ -899,6 +929,7 @@ function formatPreview(preview) {
|
|
|
899
929
|
// commands.ts
|
|
900
930
|
async function runCli(argv = process.argv, serviceOrigin = process.env.DISPOSABL_API_ORIGIN || SERVICE_ORIGIN) {
|
|
901
931
|
const program = createProgram(serviceOrigin, true);
|
|
932
|
+
program.exitOverride();
|
|
902
933
|
const origin = () => apiUrl(serviceOrigin);
|
|
903
934
|
async function main() {
|
|
904
935
|
if (needsContract(program, argv, serviceOrigin)) {
|
|
@@ -1013,18 +1044,21 @@ Waiting for connections. Press Ctrl+C to keep your files and finish later.`);
|
|
|
1013
1044
|
}
|
|
1014
1045
|
await program.parseAsync(argv);
|
|
1015
1046
|
}
|
|
1016
|
-
const command = argv[2] ?? "help";
|
|
1047
|
+
const command = ["--version", "-V"].includes(argv[2] ?? "") ? "version" : ["--help", "-h"].includes(argv[2] ?? "") ? "help" : argv[2] ?? "help";
|
|
1017
1048
|
const central = serviceOrigin === SERVICE_ORIGIN;
|
|
1018
|
-
|
|
1019
|
-
await capture(version, "cli", command, "started", telemetryStatePath());
|
|
1049
|
+
const started = central ? capture(version, "cli", command, "started", telemetryStatePath()) : undefined;
|
|
1020
1050
|
try {
|
|
1021
1051
|
await main();
|
|
1052
|
+
await started;
|
|
1022
1053
|
if (central)
|
|
1023
1054
|
await capture(version, "cli", command, "success", telemetryStatePath());
|
|
1024
1055
|
} catch (error) {
|
|
1056
|
+
await started;
|
|
1057
|
+
const success = error instanceof CommanderError && error.exitCode === 0;
|
|
1025
1058
|
if (central)
|
|
1026
|
-
await capture(version, "cli", command, "failure", telemetryStatePath());
|
|
1027
|
-
|
|
1059
|
+
await capture(version, "cli", command, success ? "success" : "failure", telemetryStatePath());
|
|
1060
|
+
if (!success)
|
|
1061
|
+
throw error;
|
|
1028
1062
|
}
|
|
1029
1063
|
}
|
|
1030
1064
|
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { readFileSync, realpathSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
4
|
+
|
|
5
|
+
// Package metadata must never publish authenticated or signed URLs.
|
|
6
|
+
export function verifyMetadata(manifest) {
|
|
7
|
+
function inspect(value, field) {
|
|
8
|
+
if (typeof value === "string") {
|
|
9
|
+
const candidate = value
|
|
10
|
+
.trim()
|
|
11
|
+
.replace(/[\u0000-\u0020]/g, "")
|
|
12
|
+
.replace(/^git\+/i, "");
|
|
13
|
+
if (
|
|
14
|
+
/^[a-z][a-z\d+.-]*:/i.test(candidate) ||
|
|
15
|
+
/^[\\/]{2}/.test(candidate)
|
|
16
|
+
) {
|
|
17
|
+
let url;
|
|
18
|
+
try {
|
|
19
|
+
url = new URL(
|
|
20
|
+
candidate,
|
|
21
|
+
/^[\\/]{2}/.test(candidate)
|
|
22
|
+
? "https://metadata.invalid"
|
|
23
|
+
: undefined,
|
|
24
|
+
);
|
|
25
|
+
} catch {
|
|
26
|
+
throw new Error(`Invalid URL in package metadata: ${field}`);
|
|
27
|
+
}
|
|
28
|
+
if (url.username || url.password || url.search || url.hash)
|
|
29
|
+
throw new Error(`Unsafe URL in package metadata: ${field}`);
|
|
30
|
+
} else if (/^[^/]+@[^/]+:/.test(candidate)) {
|
|
31
|
+
throw new Error(`Unsafe URL in package metadata: ${field}`);
|
|
32
|
+
}
|
|
33
|
+
} else if (Array.isArray(value)) {
|
|
34
|
+
value.forEach((item) => inspect(item, field));
|
|
35
|
+
} else if (value && typeof value === "object") {
|
|
36
|
+
for (const item of Object.values(value)) inspect(item, field);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
for (const field of [
|
|
40
|
+
"repository",
|
|
41
|
+
"homepage",
|
|
42
|
+
"bugs",
|
|
43
|
+
"funding",
|
|
44
|
+
"author",
|
|
45
|
+
"contributors",
|
|
46
|
+
"maintainers",
|
|
47
|
+
"publishConfig",
|
|
48
|
+
])
|
|
49
|
+
inspect(manifest[field], field);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (
|
|
53
|
+
process.argv[1] &&
|
|
54
|
+
import.meta.url === pathToFileURL(realpathSync(resolve(process.argv[1]))).href
|
|
55
|
+
)
|
|
56
|
+
try {
|
|
57
|
+
verifyMetadata(
|
|
58
|
+
JSON.parse(readFileSync(process.argv[2] ?? "package.json", "utf8")),
|
|
59
|
+
);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
if (error instanceof SyntaxError)
|
|
62
|
+
throw new Error("Invalid package metadata JSON");
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@disposabl/cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Command-line access to your Disposabl app",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
"build": "bun build.ts",
|
|
22
22
|
"typecheck": "bun check",
|
|
23
23
|
"lint": "bun check",
|
|
24
|
-
"release": "semantic-release"
|
|
24
|
+
"release": "semantic-release",
|
|
25
|
+
"prepack": "node dist/verify-metadata.mjs"
|
|
25
26
|
},
|
|
26
27
|
"dependencies": {
|
|
27
28
|
"@modelcontextprotocol/sdk": "1.32.2",
|
|
@@ -38,7 +39,7 @@
|
|
|
38
39
|
},
|
|
39
40
|
"repository": {
|
|
40
41
|
"type": "git",
|
|
41
|
-
"url": "https://
|
|
42
|
+
"url": "git+https://github.com/disposabl-dev/create-disposabl-app.git",
|
|
42
43
|
"directory": "packages/cli"
|
|
43
44
|
}
|
|
44
45
|
}
|