@insforge/cli 0.1.84 → 0.1.86

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/dist/index.js CHANGED
@@ -1215,6 +1215,17 @@ function trackPayments(subcommand, config, properties) {
1215
1215
  ...properties
1216
1216
  });
1217
1217
  }
1218
+ function trackDeployments(subcommand, config, properties) {
1219
+ captureEvent(config.project_id, "cli_deployments_invoked", {
1220
+ subcommand,
1221
+ project_id: config.project_id,
1222
+ project_name: config.project_name,
1223
+ org_id: config.org_id,
1224
+ region: config.region,
1225
+ oss_mode: config.project_id === FAKE_PROJECT_ID,
1226
+ ...properties
1227
+ });
1228
+ }
1218
1229
  function trackPosthog(subcommand, config, properties) {
1219
1230
  captureEvent(config.project_id, "cli_posthog_invoked", {
1220
1231
  subcommand,
@@ -2358,6 +2369,24 @@ import { createReadStream } from "fs";
2358
2369
  import { createHash as createHash2 } from "crypto";
2359
2370
  import * as clack12 from "@clack/prompts";
2360
2371
  import archiver from "archiver";
2372
+
2373
+ // src/commands/deployments/utils.ts
2374
+ async function trackDeploymentUsage(subcommand, success, properties = {}) {
2375
+ try {
2376
+ const config = getProjectConfig();
2377
+ if (config) {
2378
+ trackDeployments(subcommand, config, {
2379
+ success,
2380
+ ...properties
2381
+ });
2382
+ }
2383
+ } catch {
2384
+ } finally {
2385
+ await shutdownAnalytics();
2386
+ }
2387
+ }
2388
+
2389
+ // src/commands/deployments/deploy.ts
2361
2390
  var POLL_INTERVAL_MS3 = 5e3;
2362
2391
  var POLL_TIMEOUT_MS3 = 3e5;
2363
2392
  var DIRECT_UPLOAD_CONCURRENCY = 8;
@@ -2707,9 +2736,16 @@ function registerDeploymentsDeployCommand(deploymentsCmd2) {
2707
2736
  clack12.log.info(`Check status with: npx @insforge/cli deployments status ${result.deploymentId}`);
2708
2737
  }
2709
2738
  }
2710
- await reportCliUsage("cli.deployments.deploy", true);
2739
+ await trackDeploymentUsage("deploy", true, {
2740
+ has_env: opts.env !== void 0,
2741
+ has_meta: opts.meta !== void 0,
2742
+ ready: result.isReady
2743
+ });
2711
2744
  } catch (err) {
2712
- await reportCliUsage("cli.deployments.deploy", false);
2745
+ await trackDeploymentUsage("deploy", false, {
2746
+ has_env: opts.env !== void 0,
2747
+ has_meta: opts.meta !== void 0
2748
+ });
2713
2749
  handleError(err, json);
2714
2750
  }
2715
2751
  });
@@ -2997,6 +3033,9 @@ Browse available templates: https://insforge.dev/templates`
2997
3033
  json
2998
3034
  );
2999
3035
  if (downloaded) {
3036
+ captureEvent(orgId, "marketplace_template_downloaded", {
3037
+ template: opts.marketplace
3038
+ });
3000
3039
  void reportMarketplaceDownload(opts.marketplace);
3001
3040
  }
3002
3041
  } else if (githubTemplates.includes(template)) {
@@ -5192,11 +5231,9 @@ function registerDeploymentsListCommand(deploymentsCmd2) {
5192
5231
  const deployments = Array.isArray(raw) ? raw : raw && typeof raw === "object" && "data" in raw ? raw.data ?? [] : [];
5193
5232
  if (json) {
5194
5233
  outputJson(raw);
5234
+ } else if (!deployments.length) {
5235
+ console.log("No deployments found.");
5195
5236
  } else {
5196
- if (!deployments.length) {
5197
- console.log("No deployments found.");
5198
- return;
5199
- }
5200
5237
  outputTable(
5201
5238
  ["ID", "Status", "Provider", "URL", "Created"],
5202
5239
  deployments.map((d) => [
@@ -5208,9 +5245,9 @@ function registerDeploymentsListCommand(deploymentsCmd2) {
5208
5245
  ])
5209
5246
  );
5210
5247
  }
5211
- await reportCliUsage("cli.deployments.list", true);
5248
+ await trackDeploymentUsage("list", true);
5212
5249
  } catch (err) {
5213
- await reportCliUsage("cli.deployments.list", false);
5250
+ await trackDeploymentUsage("list", false);
5214
5251
  handleError(err, json);
5215
5252
  }
5216
5253
  });
@@ -5246,7 +5283,9 @@ function registerDeploymentsStatusCommand(deploymentsCmd2) {
5246
5283
  ]
5247
5284
  );
5248
5285
  }
5286
+ await trackDeploymentUsage("status", true, { sync: Boolean(opts.sync) });
5249
5287
  } catch (err) {
5288
+ await trackDeploymentUsage("status", false, { sync: Boolean(opts.sync) });
5250
5289
  handleError(err, json);
5251
5290
  }
5252
5291
  });
@@ -5272,7 +5311,9 @@ function registerDeploymentsCancelCommand(deploymentsCmd2) {
5272
5311
  } else {
5273
5312
  outputSuccess(`Deployment ${id} cancelled.`);
5274
5313
  }
5314
+ await trackDeploymentUsage("cancel", true);
5275
5315
  } catch (err) {
5316
+ await trackDeploymentUsage("cancel", false);
5276
5317
  handleError(err, json);
5277
5318
  }
5278
5319
  });
@@ -5291,11 +5332,9 @@ function registerDeploymentsEnvVarsCommand(deploymentsCmd2) {
5291
5332
  const envVars = data.envVars ?? [];
5292
5333
  if (json) {
5293
5334
  outputJson(data);
5335
+ } else if (!envVars.length) {
5336
+ console.log("No environment variables found.");
5294
5337
  } else {
5295
- if (!envVars.length) {
5296
- console.log("No environment variables found.");
5297
- return;
5298
- }
5299
5338
  outputTable(
5300
5339
  ["ID", "Key", "Type", "Updated At"],
5301
5340
  envVars.map((v) => [
@@ -5306,9 +5345,9 @@ function registerDeploymentsEnvVarsCommand(deploymentsCmd2) {
5306
5345
  ])
5307
5346
  );
5308
5347
  }
5309
- await reportCliUsage("cli.deployments.env.list", true);
5348
+ await trackDeploymentUsage("env.list", true);
5310
5349
  } catch (err) {
5311
- await reportCliUsage("cli.deployments.env.list", false);
5350
+ await trackDeploymentUsage("env.list", false);
5312
5351
  handleError(err, json);
5313
5352
  }
5314
5353
  });
@@ -5327,9 +5366,9 @@ function registerDeploymentsEnvVarsCommand(deploymentsCmd2) {
5327
5366
  } else {
5328
5367
  outputSuccess(data.message);
5329
5368
  }
5330
- await reportCliUsage("cli.deployments.env.set", true);
5369
+ await trackDeploymentUsage("env.set", true);
5331
5370
  } catch (err) {
5332
- await reportCliUsage("cli.deployments.env.set", false);
5371
+ await trackDeploymentUsage("env.set", false);
5333
5372
  handleError(err, json);
5334
5373
  }
5335
5374
  });
@@ -5347,9 +5386,9 @@ function registerDeploymentsEnvVarsCommand(deploymentsCmd2) {
5347
5386
  } else {
5348
5387
  outputSuccess(data.message);
5349
5388
  }
5350
- await reportCliUsage("cli.deployments.env.delete", true);
5389
+ await trackDeploymentUsage("env.delete", true);
5351
5390
  } catch (err) {
5352
- await reportCliUsage("cli.deployments.env.delete", false);
5391
+ await trackDeploymentUsage("env.delete", false);
5353
5392
  handleError(err, json);
5354
5393
  }
5355
5394
  });
@@ -5819,14 +5858,17 @@ function registerComputeListCommand(computeCmd2) {
5819
5858
  }
5820
5859
  outputTable(
5821
5860
  ["Name", "Status", "Image", "CPU", "Memory", "Endpoint"],
5822
- services.map((s) => [
5823
- String(s.name ?? "-"),
5824
- String(s.status ?? "-"),
5825
- String(s.imageUrl ?? "-"),
5826
- String(s.cpu ?? "-"),
5827
- s.memory ? `${s.memory}MB` : "-",
5828
- String(s.endpointUrl ?? "-")
5829
- ])
5861
+ services.map((s) => {
5862
+ const endpoint = s.protocol === "tcp" && s.endpointUrl && s.port ? `${String(s.endpointUrl).replace(/^https?:\/\//, "")}:${s.port}` : String(s.endpointUrl ?? "-");
5863
+ return [
5864
+ String(s.name ?? "-"),
5865
+ String(s.status ?? "-"),
5866
+ String(s.imageUrl ?? "-"),
5867
+ String(s.cpu ?? "-"),
5868
+ s.memory ? `${s.memory}MB` : "-",
5869
+ endpoint
5870
+ ];
5871
+ })
5830
5872
  );
5831
5873
  }
5832
5874
  await reportCliUsage("cli.compute.list", true);
@@ -5848,14 +5890,16 @@ function registerComputeGetCommand(computeCmd2) {
5848
5890
  if (json) {
5849
5891
  outputJson(service);
5850
5892
  } else {
5893
+ const endpoint = service.protocol === "tcp" && service.endpointUrl && service.port ? `${String(service.endpointUrl).replace(/^https?:\/\//, "")}:${service.port}` : service.endpointUrl ?? "n/a";
5851
5894
  outputInfo(`Name: ${service.name}`);
5852
5895
  outputInfo(`ID: ${service.id}`);
5853
5896
  outputInfo(`Status: ${service.status}`);
5854
5897
  outputInfo(`Image: ${service.imageUrl}`);
5898
+ outputInfo(`Protocol: ${service.protocol ?? "http"}`);
5855
5899
  outputInfo(`CPU: ${service.cpu}`);
5856
5900
  outputInfo(`Memory: ${service.memory}MB`);
5857
5901
  outputInfo(`Region: ${service.region}`);
5858
- outputInfo(`Endpoint: ${service.endpointUrl ?? "n/a"}`);
5902
+ outputInfo(`Endpoint: ${endpoint}`);
5859
5903
  outputInfo(`Created: ${service.createdAt}`);
5860
5904
  }
5861
5905
  await reportCliUsage("cli.compute.get", true);
@@ -6145,19 +6189,29 @@ function ensureFlyTomlStub(opts) {
6145
6189
  return () => {
6146
6190
  };
6147
6191
  }
6148
- const stub = `# Auto-generated by @insforge/cli for compute deploy. Safe to delete.
6149
- app = "${opts.appId}"
6150
- primary_region = "${opts.region}"
6151
-
6152
- [build]
6192
+ const serviceBlock = opts.protocol === "tcp" ? `[[services]]
6193
+ internal_port = ${opts.port}
6194
+ protocol = "tcp"
6195
+ auto_stop_machines = false
6196
+ auto_start_machines = true
6197
+ min_machines_running = 0
6153
6198
 
6154
- [http_service]
6199
+ [[services.ports]]
6200
+ port = ${opts.port}
6201
+ ` : `[http_service]
6155
6202
  internal_port = ${opts.port}
6156
6203
  force_https = true
6157
6204
  auto_stop_machines = false
6158
6205
  auto_start_machines = true
6159
6206
  min_machines_running = 0
6160
6207
  `;
6208
+ const stub = `# Auto-generated by @insforge/cli for compute deploy. Safe to delete.
6209
+ app = "${opts.appId}"
6210
+ primary_region = "${opts.region}"
6211
+
6212
+ [build]
6213
+
6214
+ ` + serviceBlock;
6161
6215
  writeFileSync7(path6, stub, "utf8");
6162
6216
  return () => {
6163
6217
  try {
@@ -6172,7 +6226,8 @@ function flyctlBuildAndPush(opts) {
6172
6226
  dir: opts.dir,
6173
6227
  appId: opts.appId,
6174
6228
  region: opts.region,
6175
- port: opts.port
6229
+ port: opts.port,
6230
+ protocol: opts.protocol
6176
6231
  });
6177
6232
  const child = spawn(
6178
6233
  "flyctl",
@@ -6239,6 +6294,10 @@ function registerComputeDeployCommand(computeCmd2) {
6239
6294
  ).option("--memory <mb>", "Memory in MB", "512").option("--region <region>", "Fly.io region", "iad").option("--env <json>", "Env vars as JSON object").option(
6240
6295
  "--env-file <path>",
6241
6296
  "Path to a .env file (KEY=VALUE per line, #-comments + blank lines ok). Mutually exclusive with --env."
6297
+ ).option(
6298
+ "--protocol <protocol>",
6299
+ 'Edge protocol: "http" (default) or "tcp" (raw pass-through for Redis, etc.)',
6300
+ "http"
6242
6301
  ).action(async (dir, opts, cmd) => {
6243
6302
  const { json } = getRootOpts(cmd);
6244
6303
  try {
@@ -6255,6 +6314,9 @@ function registerComputeDeployCommand(computeCmd2) {
6255
6314
  if (!Number.isInteger(port) || port < 1 || port > 65535) {
6256
6315
  throw new CLIError(`Invalid --port: ${opts.port}`);
6257
6316
  }
6317
+ if (opts.protocol !== "http" && opts.protocol !== "tcp") {
6318
+ throw new CLIError(`Invalid --protocol: ${opts.protocol} (expected "http" or "tcp")`);
6319
+ }
6258
6320
  const memory = Number(opts.memory);
6259
6321
  if (!Number.isInteger(memory) || memory <= 0) {
6260
6322
  throw new CLIError(`Invalid --memory: ${opts.memory}`);
@@ -6294,6 +6356,7 @@ function registerComputeDeployCommand(computeCmd2) {
6294
6356
  region: opts.region
6295
6357
  };
6296
6358
  if (envVars) baseBody.envVars = envVars;
6359
+ if (opts.protocol === "tcp") baseBody.protocol = "tcp";
6297
6360
  if (!dir) {
6298
6361
  const body = { ...baseBody, imageUrl: opts.image };
6299
6362
  const listRes2 = await ossFetch("/api/compute/services");
@@ -6305,6 +6368,7 @@ function registerComputeDeployCommand(computeCmd2) {
6305
6368
  if (!json) outputInfo(`Found existing service "${opts.name}", updating...`);
6306
6369
  const updateBody2 = { ...body };
6307
6370
  delete updateBody2.name;
6371
+ if (opts.protocol === "tcp") updateBody2.protocol = "tcp";
6308
6372
  res = await ossFetch(`/api/compute/services/${encodeURIComponent(existing2.id)}`, {
6309
6373
  method: "PATCH",
6310
6374
  body: JSON.stringify(updateBody2)
@@ -6321,7 +6385,14 @@ function registerComputeDeployCommand(computeCmd2) {
6321
6385
  } else {
6322
6386
  const verb = existing2 ? "updated" : "deployed";
6323
6387
  outputSuccess(`Service "${service2.name}" ${verb} [${service2.status}]`);
6324
- if (service2.endpointUrl) console.log(` Endpoint: ${service2.endpointUrl}`);
6388
+ if (service2.endpointUrl && opts.protocol === "tcp") {
6389
+ const host = String(service2.endpointUrl).replace(/^https?:\/\//, "");
6390
+ console.log(` Endpoint: ${host}:${service2.port} (connect with <scheme>://${host}:${service2.port})`);
6391
+ console.log(` Note: TCP services are reachable from the public internet.`);
6392
+ console.log(` Configure auth on your container (e.g. redis --requirepass <secret>).`);
6393
+ } else if (service2.endpointUrl) {
6394
+ console.log(` Endpoint: ${service2.endpointUrl}`);
6395
+ }
6325
6396
  if (service2.port !== void 0) console.log(` Port: ${service2.port} (container must listen on this port)`);
6326
6397
  }
6327
6398
  await reportCliUsage("cli.compute.deploy", true);
@@ -6379,7 +6450,8 @@ function registerComputeDeployCommand(computeCmd2) {
6379
6450
  imageLabel,
6380
6451
  token: tokenJson.token,
6381
6452
  region: opts.region,
6382
- port
6453
+ port,
6454
+ protocol: opts.protocol === "tcp" ? "tcp" : "http"
6383
6455
  }));
6384
6456
  } catch (buildErr) {
6385
6457
  if (!existing) {
@@ -6407,6 +6479,7 @@ function registerComputeDeployCommand(computeCmd2) {
6407
6479
  region: opts.region
6408
6480
  };
6409
6481
  if (envVars) updateBody.envVars = envVars;
6482
+ if (opts.protocol === "tcp") updateBody.protocol = "tcp";
6410
6483
  const finalRes = await ossFetch(
6411
6484
  `/api/compute/services/${encodeURIComponent(serviceId)}`,
6412
6485
  { method: "PATCH", body: JSON.stringify(updateBody) }
@@ -6417,7 +6490,14 @@ function registerComputeDeployCommand(computeCmd2) {
6417
6490
  } else {
6418
6491
  const verb = existing ? "updated" : "deployed";
6419
6492
  outputSuccess(`Service "${service.name}" ${verb} [${service.status}]`);
6420
- if (service.endpointUrl) console.log(` Endpoint: ${service.endpointUrl}`);
6493
+ if (service.endpointUrl && opts.protocol === "tcp") {
6494
+ const host = String(service.endpointUrl).replace(/^https?:\/\//, "");
6495
+ console.log(` Endpoint: ${host}:${service.port} (connect with <scheme>://${host}:${service.port})`);
6496
+ console.log(` Note: TCP services are reachable from the public internet.`);
6497
+ console.log(` Configure auth on your container (e.g. redis --requirepass <secret>).`);
6498
+ } else if (service.endpointUrl) {
6499
+ console.log(` Endpoint: ${service.endpointUrl}`);
6500
+ }
6421
6501
  if (service.port !== void 0) console.log(` Port: ${service.port} (container must listen on this port)`);
6422
6502
  console.log(` Image: ${imageRef} (built remotely; no local image to clean up)`);
6423
6503
  }
@@ -7108,7 +7188,7 @@ function registerDiagnoseCommands(diagnoseCmd2) {
7108
7188
  const s = !json ? clack16.spinner() : null;
7109
7189
  s?.start("Collecting diagnostic data...");
7110
7190
  const data2 = await collectDiagnosticData(projectId, ossMode, apiUrl);
7111
- const cliVersion = "0.1.84";
7191
+ const cliVersion = "0.1.86";
7112
7192
  s?.stop("Data collected");
7113
7193
  if (!json) {
7114
7194
  console.log(`
@@ -7589,16 +7669,14 @@ function formatRecurring(interval, intervalCount) {
7589
7669
  }
7590
7670
  async function trackPaymentUsage(subcommand, success, properties = {}) {
7591
7671
  try {
7592
- try {
7593
- const config = getProjectConfig();
7594
- if (config) {
7595
- trackPayments(subcommand, config, {
7596
- success,
7597
- ...properties
7598
- });
7599
- }
7600
- } catch {
7672
+ const config = getProjectConfig();
7673
+ if (config) {
7674
+ trackPayments(subcommand, config, {
7675
+ success,
7676
+ ...properties
7677
+ });
7601
7678
  }
7679
+ } catch {
7602
7680
  } finally {
7603
7681
  await shutdownAnalytics();
7604
7682
  }