@disposabl/cli 2.1.2 → 4.0.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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/dist/index.js +174 -15
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -37,7 +37,7 @@ The command exits unsuccessfully while manual cleanup is pending. Rerun the same
37
37
 
38
38
  ## Usage analytics
39
39
 
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.
40
+ Published Disposabl releases collect command category, outcome, package version, operating system and package-manager category. Requests to the Disposabl API also send operation timings and a trace ID to link CLI requests with backend timing and failure logs. A random ID stored in `~/.config/disposabl/telemetry.json` connects anonymous usage to a pseudonymous ID after login. Logout and account changes reset that ID. Prompts, arguments, paths, error messages, credentials and email addresses are excluded. Set `DO_NOT_TRACK=1` or `DISPOSABL_TELEMETRY_DISABLED=1` to opt out. Local source, development, CI and E2E runs do not send CLI telemetry. Generated apps use their own analytics configuration.
41
41
 
42
42
  Failed commands also send a fixed, coarse error-tracking event with no exception message or stack trace.
43
43
 
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.1.2";
6
+ var version = "4.0.0";
7
7
  var package_default = {
8
8
  name: "@disposabl/cli",
9
9
  version,
@@ -342,10 +342,13 @@ function telemetryConfig(version, entry = process.argv[1] ?? "") {
342
342
  const env = process.env;
343
343
  const host = "https://us.i.posthog.com";
344
344
  const token = "phc_AkMtHdssxpHojfRGD985EUbxkX2GuMSxKiULHaTT9TgM";
345
- if (!installedRelease(version, entry) || env.NODE_ENV === "test" || env.NODE_ENV === "development" || env.BUN_ENV === "test" || env.CI || env.E2E_TELEMETRY_DISABLED || ["1", "true"].includes(env.DO_NOT_TRACK?.toLowerCase() ?? "") || env.DISPOSABL_TELEMETRY_DISABLED === "1" || env.DISPOSABL_API_KEY || env.DISPOSABL_API_ORIGIN && env.DISPOSABL_API_ORIGIN !== "https://www.disposabl.dev" || !token?.startsWith("phc_") || !["https://us.i.posthog.com", "https://eu.i.posthog.com"].includes(host ?? ""))
345
+ if (!installedRelease(version, entry) || env.NODE_ENV === "test" || env.NODE_ENV === "development" || env.BUN_ENV === "test" || env.CI || env.E2E_TELEMETRY_DISABLED || telemetryOptedOut() || env.DISPOSABL_API_KEY || env.DISPOSABL_API_ORIGIN && env.DISPOSABL_API_ORIGIN !== "https://www.disposabl.dev" || !token?.startsWith("phc_") || !["https://us.i.posthog.com", "https://eu.i.posthog.com"].includes(host ?? ""))
346
346
  return null;
347
347
  return { token, host };
348
348
  }
349
+ function telemetryOptedOut() {
350
+ return ["1", "true"].includes(process.env.DO_NOT_TRACK?.toLowerCase() ?? "") || process.env.DISPOSABL_TELEMETRY_DISABLED === "1";
351
+ }
349
352
  var directory2 = () => join2(homedir2(), ".config", "disposabl");
350
353
  var telemetryStatePath = () => join2(directory2(), "telemetry.json");
351
354
  async function state(path) {
@@ -383,13 +386,18 @@ async function send(config, event, distinctId, properties) {
383
386
  const response = await fetch(`${config.host}/i/v0/e/`, {
384
387
  method: "POST",
385
388
  redirect: "error",
386
- signal: AbortSignal.timeout(500),
389
+ signal: AbortSignal.timeout(2000),
387
390
  headers: { "Content-Type": "application/json" },
388
391
  body: JSON.stringify({
389
392
  api_key: config.token,
390
393
  event,
391
394
  distinct_id: distinctId,
392
- properties: { ...properties, $geoip_disable: true, $ip: "0.0.0.0" }
395
+ properties: {
396
+ ...properties,
397
+ environment: "production",
398
+ $geoip_disable: true,
399
+ $ip: "0.0.0.0"
400
+ }
393
401
  })
394
402
  });
395
403
  return response.ok;
@@ -431,6 +439,7 @@ async function capture(version, product, command, outcome, path) {
431
439
  const activation = outcome === "started" && await firstExecution(path, product, version);
432
440
  const properties = {
433
441
  product,
442
+ source: product,
434
443
  command: allowed.includes(command) ? command : "other",
435
444
  outcome,
436
445
  version,
@@ -522,6 +531,121 @@ Add credits: ${data.paymentUrl}` : "";
522
531
 
523
532
  // client.ts
524
533
  import { Command } from "commander";
534
+
535
+ // ../disposabl-kit/lib/observability.ts
536
+ var traceparentPattern = /^00-([0-9a-f]{32})-([0-9a-f]{16})-01$/;
537
+ function parseTraceparent(value) {
538
+ const match = traceparentPattern.exec(value ?? "");
539
+ if (!match || /^0+$/.test(match[1]) || /^0+$/.test(match[2]))
540
+ return null;
541
+ return { traceId: match[1], parentSpanId: match[2] };
542
+ }
543
+ function startSpan(parent) {
544
+ const context = parseTraceparent(parent);
545
+ const traceId = context?.traceId ?? crypto.randomUUID().replaceAll("-", "");
546
+ const spanId = Array.from(crypto.getRandomValues(new Uint8Array(8)), (byte) => byte.toString(16).padStart(2, "0")).join("");
547
+ return {
548
+ traceId,
549
+ spanId,
550
+ parentSpanId: context?.parentSpanId,
551
+ traceparent: `00-${traceId}-${spanId}-01`
552
+ };
553
+ }
554
+ var attribute = (key, stringValue) => ({
555
+ key,
556
+ value: { stringValue }
557
+ });
558
+ var nanoseconds = (ms) => String(BigInt(Math.round(ms)) * 1000000n);
559
+ async function exportOperation(config, operation, timeout) {
560
+ const {
561
+ service,
562
+ name,
563
+ source,
564
+ startedAt,
565
+ endedAt,
566
+ failed,
567
+ distinctId,
568
+ span
569
+ } = operation;
570
+ const resource = {
571
+ attributes: [
572
+ attribute("service.name", service),
573
+ attribute("deployment.environment.name", "production")
574
+ ]
575
+ };
576
+ const attributes = [
577
+ attribute("disposabl.source", source),
578
+ attribute("disposabl.operation", name)
579
+ ];
580
+ const context = { traceId: span.traceId, spanId: span.spanId, attributes };
581
+ const send = (signal, data) => fetch(`${config.host}/i/v1/${signal}`, {
582
+ method: "POST",
583
+ redirect: "error",
584
+ signal: AbortSignal.timeout(timeout),
585
+ headers: {
586
+ Authorization: `Bearer ${config.token}`,
587
+ "Content-Type": "application/json"
588
+ },
589
+ body: JSON.stringify(data)
590
+ });
591
+ const endTime = nanoseconds(Math.max(startedAt, endedAt));
592
+ const pending = [
593
+ send("traces", {
594
+ resourceSpans: [
595
+ {
596
+ resource,
597
+ scopeSpans: [
598
+ {
599
+ spans: [
600
+ {
601
+ ...context,
602
+ attributes: distinctId ? [
603
+ ...attributes,
604
+ attribute("posthog.distinct_id", distinctId)
605
+ ] : attributes,
606
+ ...span.parentSpanId ? { parentSpanId: span.parentSpanId } : {},
607
+ name,
608
+ kind: service === "disposabl-cli" ? 3 : 2,
609
+ startTimeUnixNano: nanoseconds(startedAt),
610
+ endTimeUnixNano: endTime,
611
+ status: { code: failed ? 2 : 1 }
612
+ }
613
+ ]
614
+ }
615
+ ]
616
+ }
617
+ ]
618
+ })
619
+ ];
620
+ if (failed)
621
+ pending.push(send("logs", {
622
+ resourceLogs: [
623
+ {
624
+ resource,
625
+ scopeLogs: [
626
+ {
627
+ logRecords: [
628
+ {
629
+ ...context,
630
+ attributes: distinctId ? [
631
+ ...attributes,
632
+ attribute("posthogDistinctId", distinctId)
633
+ ] : attributes,
634
+ timeUnixNano: endTime,
635
+ severityNumber: 17,
636
+ severityText: "ERROR",
637
+ body: { stringValue: "Disposabl operation failed" }
638
+ }
639
+ ]
640
+ }
641
+ ]
642
+ }
643
+ ]
644
+ }));
645
+ await Promise.allSettled(pending);
646
+ }
647
+
648
+ // client.ts
525
649
  function createProgram(serviceOrigin, centralAnalytics = false, dependencies = {}) {
526
650
  const version = dependencies.version ?? package_default.version;
527
651
  const path = () => dependencies.telemetryPath ?? telemetryStatePath();
@@ -628,7 +752,8 @@ Disposabl collects limited CLI usage when configured. Set DO_NOT_TRACK=1 to opt
628
752
  const send = (token) => fetch(`${base}/api/users/current`, {
629
753
  headers: {
630
754
  Authorization: `Bearer ${token}`,
631
- "X-Disposabl-Source": "cli"
755
+ "X-Disposabl-Source": "cli",
756
+ ...telemetryOptedOut() && { DNT: "1" }
632
757
  },
633
758
  redirect: "error",
634
759
  signal: AbortSignal.timeout(30000)
@@ -717,20 +842,42 @@ function requestOperation(base, path, method, input, timeout = 30000) {
717
842
  if (method === "get")
718
843
  for (const [name, value] of Object.entries(input))
719
844
  target.searchParams.set(name, JSON.stringify(value));
720
- const send = async (refresh = false) => fetch(target, {
845
+ const send = async (traceparent, refresh = false) => fetch(target, {
721
846
  method: method.toUpperCase(),
722
847
  redirect: "error",
723
848
  signal: AbortSignal.timeout(timeout),
724
849
  headers: {
725
850
  Authorization: `Bearer ${await accessToken(base, refresh)}`,
726
851
  "Content-Type": "application/json",
727
- "X-Disposabl-Source": "cli"
852
+ "X-Disposabl-Source": "cli",
853
+ ...telemetryOptedOut() && { DNT: "1" },
854
+ ...traceparent && { traceparent }
728
855
  },
729
856
  body: method === "post" ? JSON.stringify(input) : undefined
730
857
  });
731
858
  return async () => {
732
- const response = await send();
733
- return response.status === 401 && !process.env.DISPOSABL_API_KEY ? send(true) : response;
859
+ const config = base === "https://www.disposabl.dev" && telemetryConfig(package_default.version);
860
+ const span = config && startSpan();
861
+ const startedAt = Date.now();
862
+ let failed = true;
863
+ try {
864
+ let response = await send(span ? span.traceparent : undefined);
865
+ if (response.status === 401 && !process.env.DISPOSABL_API_KEY)
866
+ response = await send(span ? span.traceparent : undefined, true);
867
+ failed = !response.ok;
868
+ return response;
869
+ } finally {
870
+ if (config && span)
871
+ await exportOperation(config, {
872
+ service: "disposabl-cli",
873
+ name: "cli_api_request",
874
+ source: "cli",
875
+ startedAt,
876
+ endedAt: Date.now(),
877
+ failed,
878
+ span
879
+ }, 500).catch(() => {});
880
+ }
734
881
  };
735
882
  }
736
883
  function needsContract(program, argv, origin) {
@@ -829,6 +976,10 @@ async function configureDevelopment(directory, value) {
829
976
  throw new Error("Development URLs do not match the deployment.");
830
977
  if (value.productionConvexSiteUrl && !/^https:\/\/[a-z0-9-]+\.convex\.site$/.test(value.productionConvexSiteUrl))
831
978
  throw new Error("Unexpected production Convex site URL.");
979
+ for (const url of [value.publicSiteUrl, value.productionSiteUrl]) {
980
+ if (url !== undefined && !/^https:\/\/[a-z0-9]+(?:[a-z0-9-]*[a-z0-9])?\.disposabl\.xyz$/.test(url))
981
+ throw new Error("Unexpected public site URL.");
982
+ }
832
983
  if (config.features?.includes("analytics") && !value.analytics)
833
984
  throw new Error("Analytics setup is incomplete. Connect PostHog and retry app setup.");
834
985
  if (value.analytics && (!Number.isSafeInteger(value.analytics.projectId) || !value.analytics.projectToken.startsWith("phc_") || !["https://us.i.posthog.com", "https://eu.i.posthog.com"].includes(value.analytics.host)))
@@ -867,7 +1018,9 @@ async function configureDevelopment(directory, value) {
867
1018
  if (ignored.status !== 0 || tracked.status !== 1)
868
1019
  throw new Error(`${file} must be untracked and ignored by Git.`);
869
1020
  }
870
- if (value.productionConvexSiteUrl || value.analytics || config.analytics) {
1021
+ if (value.productionConvexSiteUrl || value.productionSiteUrl || value.analytics || config.analytics) {
1022
+ if (value.productionSiteUrl)
1023
+ config.productionSiteUrl = value.productionSiteUrl;
871
1024
  if (value.productionConvexSiteUrl)
872
1025
  config.productionConvexSiteUrl = value.productionConvexSiteUrl;
873
1026
  if (config.features?.includes("analytics"))
@@ -886,16 +1039,17 @@ async function configureDevelopment(directory, value) {
886
1039
  await updateEnv(join4(root, files[0]), {
887
1040
  CONVEX_DEPLOY_KEY: value.deployKey,
888
1041
  CONVEX_URL: value.convexUrl,
889
- CONVEX_SITE_URL: value.convexSiteUrl
890
- }, ["CONVEX_DEPLOYMENT"]);
1042
+ CONVEX_SITE_URL: value.convexSiteUrl,
1043
+ ...value.publicSiteUrl ? { PUBLIC_SITE_URL: value.publicSiteUrl } : {}
1044
+ }, ["CONVEX_DEPLOYMENT", "PUBLIC_SITE_URL"]);
891
1045
  await updateEnv(join4(root, files[1]), {
892
1046
  VITE_CONVEX_URL: value.convexUrl,
893
- VITE_CONVEX_SITE_URL: value.convexSiteUrl
1047
+ VITE_CONVEX_SITE_URL: value.publicSiteUrl ?? value.convexSiteUrl
894
1048
  });
895
1049
  if (files[2])
896
1050
  await updateEnv(join4(root, files[2]), {
897
1051
  EXPO_PUBLIC_CONVEX_URL: value.convexUrl,
898
- EXPO_PUBLIC_CONVEX_SITE_URL: value.convexSiteUrl
1052
+ EXPO_PUBLIC_CONVEX_SITE_URL: value.publicSiteUrl ?? value.convexSiteUrl
899
1053
  });
900
1054
  }
901
1055
  function formatPreview(preview) {
@@ -1035,7 +1189,12 @@ Waiting for connections. Press Ctrl+C to keep your files and finish later.`);
1035
1189
  console.log(JSON.stringify(await configureRepository(base, options.appId, value), null, 2));
1036
1190
  } else if (tokenCreate && options.configure) {
1037
1191
  await configureDevelopment(options.configure, value);
1038
- const { deployKey: _secret, ...details } = value;
1192
+ const {
1193
+ deployKey: _secret,
1194
+ convexSiteUrl: _provider,
1195
+ productionConvexSiteUrl: _productionProvider,
1196
+ ...details
1197
+ } = value;
1039
1198
  console.log(JSON.stringify({ ...details, configured: true }, null, 2));
1040
1199
  } else if (previewGet && !options.json)
1041
1200
  console.log(formatPreview(value));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@disposabl/cli",
3
- "version": "2.1.2",
3
+ "version": "4.0.0",
4
4
  "type": "module",
5
5
  "description": "Command-line access to your Disposabl app",
6
6
  "license": "MIT",