@insforge/cli 0.1.84 → 0.1.85
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 +123 -48
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1172,7 +1172,7 @@ import * as clack5 from "@clack/prompts";
|
|
|
1172
1172
|
|
|
1173
1173
|
// src/lib/analytics.ts
|
|
1174
1174
|
import { PostHog } from "posthog-node";
|
|
1175
|
-
var POSTHOG_API_KEY = "
|
|
1175
|
+
var POSTHOG_API_KEY = "";
|
|
1176
1176
|
var POSTHOG_HOST = process.env.POSTHOG_HOST || "https://us.i.posthog.com";
|
|
1177
1177
|
var client = null;
|
|
1178
1178
|
function getClient() {
|
|
@@ -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
|
|
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
|
|
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
|
});
|
|
@@ -5192,11 +5228,9 @@ function registerDeploymentsListCommand(deploymentsCmd2) {
|
|
|
5192
5228
|
const deployments = Array.isArray(raw) ? raw : raw && typeof raw === "object" && "data" in raw ? raw.data ?? [] : [];
|
|
5193
5229
|
if (json) {
|
|
5194
5230
|
outputJson(raw);
|
|
5231
|
+
} else if (!deployments.length) {
|
|
5232
|
+
console.log("No deployments found.");
|
|
5195
5233
|
} else {
|
|
5196
|
-
if (!deployments.length) {
|
|
5197
|
-
console.log("No deployments found.");
|
|
5198
|
-
return;
|
|
5199
|
-
}
|
|
5200
5234
|
outputTable(
|
|
5201
5235
|
["ID", "Status", "Provider", "URL", "Created"],
|
|
5202
5236
|
deployments.map((d) => [
|
|
@@ -5208,9 +5242,9 @@ function registerDeploymentsListCommand(deploymentsCmd2) {
|
|
|
5208
5242
|
])
|
|
5209
5243
|
);
|
|
5210
5244
|
}
|
|
5211
|
-
await
|
|
5245
|
+
await trackDeploymentUsage("list", true);
|
|
5212
5246
|
} catch (err) {
|
|
5213
|
-
await
|
|
5247
|
+
await trackDeploymentUsage("list", false);
|
|
5214
5248
|
handleError(err, json);
|
|
5215
5249
|
}
|
|
5216
5250
|
});
|
|
@@ -5246,7 +5280,9 @@ function registerDeploymentsStatusCommand(deploymentsCmd2) {
|
|
|
5246
5280
|
]
|
|
5247
5281
|
);
|
|
5248
5282
|
}
|
|
5283
|
+
await trackDeploymentUsage("status", true, { sync: Boolean(opts.sync) });
|
|
5249
5284
|
} catch (err) {
|
|
5285
|
+
await trackDeploymentUsage("status", false, { sync: Boolean(opts.sync) });
|
|
5250
5286
|
handleError(err, json);
|
|
5251
5287
|
}
|
|
5252
5288
|
});
|
|
@@ -5272,7 +5308,9 @@ function registerDeploymentsCancelCommand(deploymentsCmd2) {
|
|
|
5272
5308
|
} else {
|
|
5273
5309
|
outputSuccess(`Deployment ${id} cancelled.`);
|
|
5274
5310
|
}
|
|
5311
|
+
await trackDeploymentUsage("cancel", true);
|
|
5275
5312
|
} catch (err) {
|
|
5313
|
+
await trackDeploymentUsage("cancel", false);
|
|
5276
5314
|
handleError(err, json);
|
|
5277
5315
|
}
|
|
5278
5316
|
});
|
|
@@ -5291,11 +5329,9 @@ function registerDeploymentsEnvVarsCommand(deploymentsCmd2) {
|
|
|
5291
5329
|
const envVars = data.envVars ?? [];
|
|
5292
5330
|
if (json) {
|
|
5293
5331
|
outputJson(data);
|
|
5332
|
+
} else if (!envVars.length) {
|
|
5333
|
+
console.log("No environment variables found.");
|
|
5294
5334
|
} else {
|
|
5295
|
-
if (!envVars.length) {
|
|
5296
|
-
console.log("No environment variables found.");
|
|
5297
|
-
return;
|
|
5298
|
-
}
|
|
5299
5335
|
outputTable(
|
|
5300
5336
|
["ID", "Key", "Type", "Updated At"],
|
|
5301
5337
|
envVars.map((v) => [
|
|
@@ -5306,9 +5342,9 @@ function registerDeploymentsEnvVarsCommand(deploymentsCmd2) {
|
|
|
5306
5342
|
])
|
|
5307
5343
|
);
|
|
5308
5344
|
}
|
|
5309
|
-
await
|
|
5345
|
+
await trackDeploymentUsage("env.list", true);
|
|
5310
5346
|
} catch (err) {
|
|
5311
|
-
await
|
|
5347
|
+
await trackDeploymentUsage("env.list", false);
|
|
5312
5348
|
handleError(err, json);
|
|
5313
5349
|
}
|
|
5314
5350
|
});
|
|
@@ -5327,9 +5363,9 @@ function registerDeploymentsEnvVarsCommand(deploymentsCmd2) {
|
|
|
5327
5363
|
} else {
|
|
5328
5364
|
outputSuccess(data.message);
|
|
5329
5365
|
}
|
|
5330
|
-
await
|
|
5366
|
+
await trackDeploymentUsage("env.set", true);
|
|
5331
5367
|
} catch (err) {
|
|
5332
|
-
await
|
|
5368
|
+
await trackDeploymentUsage("env.set", false);
|
|
5333
5369
|
handleError(err, json);
|
|
5334
5370
|
}
|
|
5335
5371
|
});
|
|
@@ -5347,9 +5383,9 @@ function registerDeploymentsEnvVarsCommand(deploymentsCmd2) {
|
|
|
5347
5383
|
} else {
|
|
5348
5384
|
outputSuccess(data.message);
|
|
5349
5385
|
}
|
|
5350
|
-
await
|
|
5386
|
+
await trackDeploymentUsage("env.delete", true);
|
|
5351
5387
|
} catch (err) {
|
|
5352
|
-
await
|
|
5388
|
+
await trackDeploymentUsage("env.delete", false);
|
|
5353
5389
|
handleError(err, json);
|
|
5354
5390
|
}
|
|
5355
5391
|
});
|
|
@@ -5819,14 +5855,17 @@ function registerComputeListCommand(computeCmd2) {
|
|
|
5819
5855
|
}
|
|
5820
5856
|
outputTable(
|
|
5821
5857
|
["Name", "Status", "Image", "CPU", "Memory", "Endpoint"],
|
|
5822
|
-
services.map((s) =>
|
|
5823
|
-
String(s.
|
|
5824
|
-
|
|
5825
|
-
|
|
5826
|
-
|
|
5827
|
-
|
|
5828
|
-
|
|
5829
|
-
|
|
5858
|
+
services.map((s) => {
|
|
5859
|
+
const endpoint = s.protocol === "tcp" && s.endpointUrl && s.port ? `${String(s.endpointUrl).replace(/^https?:\/\//, "")}:${s.port}` : String(s.endpointUrl ?? "-");
|
|
5860
|
+
return [
|
|
5861
|
+
String(s.name ?? "-"),
|
|
5862
|
+
String(s.status ?? "-"),
|
|
5863
|
+
String(s.imageUrl ?? "-"),
|
|
5864
|
+
String(s.cpu ?? "-"),
|
|
5865
|
+
s.memory ? `${s.memory}MB` : "-",
|
|
5866
|
+
endpoint
|
|
5867
|
+
];
|
|
5868
|
+
})
|
|
5830
5869
|
);
|
|
5831
5870
|
}
|
|
5832
5871
|
await reportCliUsage("cli.compute.list", true);
|
|
@@ -5848,14 +5887,16 @@ function registerComputeGetCommand(computeCmd2) {
|
|
|
5848
5887
|
if (json) {
|
|
5849
5888
|
outputJson(service);
|
|
5850
5889
|
} else {
|
|
5890
|
+
const endpoint = service.protocol === "tcp" && service.endpointUrl && service.port ? `${String(service.endpointUrl).replace(/^https?:\/\//, "")}:${service.port}` : service.endpointUrl ?? "n/a";
|
|
5851
5891
|
outputInfo(`Name: ${service.name}`);
|
|
5852
5892
|
outputInfo(`ID: ${service.id}`);
|
|
5853
5893
|
outputInfo(`Status: ${service.status}`);
|
|
5854
5894
|
outputInfo(`Image: ${service.imageUrl}`);
|
|
5895
|
+
outputInfo(`Protocol: ${service.protocol ?? "http"}`);
|
|
5855
5896
|
outputInfo(`CPU: ${service.cpu}`);
|
|
5856
5897
|
outputInfo(`Memory: ${service.memory}MB`);
|
|
5857
5898
|
outputInfo(`Region: ${service.region}`);
|
|
5858
|
-
outputInfo(`Endpoint: ${
|
|
5899
|
+
outputInfo(`Endpoint: ${endpoint}`);
|
|
5859
5900
|
outputInfo(`Created: ${service.createdAt}`);
|
|
5860
5901
|
}
|
|
5861
5902
|
await reportCliUsage("cli.compute.get", true);
|
|
@@ -6145,19 +6186,29 @@ function ensureFlyTomlStub(opts) {
|
|
|
6145
6186
|
return () => {
|
|
6146
6187
|
};
|
|
6147
6188
|
}
|
|
6148
|
-
const
|
|
6149
|
-
|
|
6150
|
-
|
|
6151
|
-
|
|
6152
|
-
|
|
6189
|
+
const serviceBlock = opts.protocol === "tcp" ? `[[services]]
|
|
6190
|
+
internal_port = ${opts.port}
|
|
6191
|
+
protocol = "tcp"
|
|
6192
|
+
auto_stop_machines = false
|
|
6193
|
+
auto_start_machines = true
|
|
6194
|
+
min_machines_running = 0
|
|
6153
6195
|
|
|
6154
|
-
[
|
|
6196
|
+
[[services.ports]]
|
|
6197
|
+
port = ${opts.port}
|
|
6198
|
+
` : `[http_service]
|
|
6155
6199
|
internal_port = ${opts.port}
|
|
6156
6200
|
force_https = true
|
|
6157
6201
|
auto_stop_machines = false
|
|
6158
6202
|
auto_start_machines = true
|
|
6159
6203
|
min_machines_running = 0
|
|
6160
6204
|
`;
|
|
6205
|
+
const stub = `# Auto-generated by @insforge/cli for compute deploy. Safe to delete.
|
|
6206
|
+
app = "${opts.appId}"
|
|
6207
|
+
primary_region = "${opts.region}"
|
|
6208
|
+
|
|
6209
|
+
[build]
|
|
6210
|
+
|
|
6211
|
+
` + serviceBlock;
|
|
6161
6212
|
writeFileSync7(path6, stub, "utf8");
|
|
6162
6213
|
return () => {
|
|
6163
6214
|
try {
|
|
@@ -6172,7 +6223,8 @@ function flyctlBuildAndPush(opts) {
|
|
|
6172
6223
|
dir: opts.dir,
|
|
6173
6224
|
appId: opts.appId,
|
|
6174
6225
|
region: opts.region,
|
|
6175
|
-
port: opts.port
|
|
6226
|
+
port: opts.port,
|
|
6227
|
+
protocol: opts.protocol
|
|
6176
6228
|
});
|
|
6177
6229
|
const child = spawn(
|
|
6178
6230
|
"flyctl",
|
|
@@ -6239,6 +6291,10 @@ function registerComputeDeployCommand(computeCmd2) {
|
|
|
6239
6291
|
).option("--memory <mb>", "Memory in MB", "512").option("--region <region>", "Fly.io region", "iad").option("--env <json>", "Env vars as JSON object").option(
|
|
6240
6292
|
"--env-file <path>",
|
|
6241
6293
|
"Path to a .env file (KEY=VALUE per line, #-comments + blank lines ok). Mutually exclusive with --env."
|
|
6294
|
+
).option(
|
|
6295
|
+
"--protocol <protocol>",
|
|
6296
|
+
'Edge protocol: "http" (default) or "tcp" (raw pass-through for Redis, etc.)',
|
|
6297
|
+
"http"
|
|
6242
6298
|
).action(async (dir, opts, cmd) => {
|
|
6243
6299
|
const { json } = getRootOpts(cmd);
|
|
6244
6300
|
try {
|
|
@@ -6255,6 +6311,9 @@ function registerComputeDeployCommand(computeCmd2) {
|
|
|
6255
6311
|
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
6256
6312
|
throw new CLIError(`Invalid --port: ${opts.port}`);
|
|
6257
6313
|
}
|
|
6314
|
+
if (opts.protocol !== "http" && opts.protocol !== "tcp") {
|
|
6315
|
+
throw new CLIError(`Invalid --protocol: ${opts.protocol} (expected "http" or "tcp")`);
|
|
6316
|
+
}
|
|
6258
6317
|
const memory = Number(opts.memory);
|
|
6259
6318
|
if (!Number.isInteger(memory) || memory <= 0) {
|
|
6260
6319
|
throw new CLIError(`Invalid --memory: ${opts.memory}`);
|
|
@@ -6294,6 +6353,7 @@ function registerComputeDeployCommand(computeCmd2) {
|
|
|
6294
6353
|
region: opts.region
|
|
6295
6354
|
};
|
|
6296
6355
|
if (envVars) baseBody.envVars = envVars;
|
|
6356
|
+
if (opts.protocol === "tcp") baseBody.protocol = "tcp";
|
|
6297
6357
|
if (!dir) {
|
|
6298
6358
|
const body = { ...baseBody, imageUrl: opts.image };
|
|
6299
6359
|
const listRes2 = await ossFetch("/api/compute/services");
|
|
@@ -6305,6 +6365,7 @@ function registerComputeDeployCommand(computeCmd2) {
|
|
|
6305
6365
|
if (!json) outputInfo(`Found existing service "${opts.name}", updating...`);
|
|
6306
6366
|
const updateBody2 = { ...body };
|
|
6307
6367
|
delete updateBody2.name;
|
|
6368
|
+
if (opts.protocol === "tcp") updateBody2.protocol = "tcp";
|
|
6308
6369
|
res = await ossFetch(`/api/compute/services/${encodeURIComponent(existing2.id)}`, {
|
|
6309
6370
|
method: "PATCH",
|
|
6310
6371
|
body: JSON.stringify(updateBody2)
|
|
@@ -6321,7 +6382,14 @@ function registerComputeDeployCommand(computeCmd2) {
|
|
|
6321
6382
|
} else {
|
|
6322
6383
|
const verb = existing2 ? "updated" : "deployed";
|
|
6323
6384
|
outputSuccess(`Service "${service2.name}" ${verb} [${service2.status}]`);
|
|
6324
|
-
if (service2.endpointUrl
|
|
6385
|
+
if (service2.endpointUrl && opts.protocol === "tcp") {
|
|
6386
|
+
const host = String(service2.endpointUrl).replace(/^https?:\/\//, "");
|
|
6387
|
+
console.log(` Endpoint: ${host}:${service2.port} (connect with <scheme>://${host}:${service2.port})`);
|
|
6388
|
+
console.log(` Note: TCP services are reachable from the public internet.`);
|
|
6389
|
+
console.log(` Configure auth on your container (e.g. redis --requirepass <secret>).`);
|
|
6390
|
+
} else if (service2.endpointUrl) {
|
|
6391
|
+
console.log(` Endpoint: ${service2.endpointUrl}`);
|
|
6392
|
+
}
|
|
6325
6393
|
if (service2.port !== void 0) console.log(` Port: ${service2.port} (container must listen on this port)`);
|
|
6326
6394
|
}
|
|
6327
6395
|
await reportCliUsage("cli.compute.deploy", true);
|
|
@@ -6379,7 +6447,8 @@ function registerComputeDeployCommand(computeCmd2) {
|
|
|
6379
6447
|
imageLabel,
|
|
6380
6448
|
token: tokenJson.token,
|
|
6381
6449
|
region: opts.region,
|
|
6382
|
-
port
|
|
6450
|
+
port,
|
|
6451
|
+
protocol: opts.protocol === "tcp" ? "tcp" : "http"
|
|
6383
6452
|
}));
|
|
6384
6453
|
} catch (buildErr) {
|
|
6385
6454
|
if (!existing) {
|
|
@@ -6407,6 +6476,7 @@ function registerComputeDeployCommand(computeCmd2) {
|
|
|
6407
6476
|
region: opts.region
|
|
6408
6477
|
};
|
|
6409
6478
|
if (envVars) updateBody.envVars = envVars;
|
|
6479
|
+
if (opts.protocol === "tcp") updateBody.protocol = "tcp";
|
|
6410
6480
|
const finalRes = await ossFetch(
|
|
6411
6481
|
`/api/compute/services/${encodeURIComponent(serviceId)}`,
|
|
6412
6482
|
{ method: "PATCH", body: JSON.stringify(updateBody) }
|
|
@@ -6417,7 +6487,14 @@ function registerComputeDeployCommand(computeCmd2) {
|
|
|
6417
6487
|
} else {
|
|
6418
6488
|
const verb = existing ? "updated" : "deployed";
|
|
6419
6489
|
outputSuccess(`Service "${service.name}" ${verb} [${service.status}]`);
|
|
6420
|
-
if (service.endpointUrl
|
|
6490
|
+
if (service.endpointUrl && opts.protocol === "tcp") {
|
|
6491
|
+
const host = String(service.endpointUrl).replace(/^https?:\/\//, "");
|
|
6492
|
+
console.log(` Endpoint: ${host}:${service.port} (connect with <scheme>://${host}:${service.port})`);
|
|
6493
|
+
console.log(` Note: TCP services are reachable from the public internet.`);
|
|
6494
|
+
console.log(` Configure auth on your container (e.g. redis --requirepass <secret>).`);
|
|
6495
|
+
} else if (service.endpointUrl) {
|
|
6496
|
+
console.log(` Endpoint: ${service.endpointUrl}`);
|
|
6497
|
+
}
|
|
6421
6498
|
if (service.port !== void 0) console.log(` Port: ${service.port} (container must listen on this port)`);
|
|
6422
6499
|
console.log(` Image: ${imageRef} (built remotely; no local image to clean up)`);
|
|
6423
6500
|
}
|
|
@@ -7108,7 +7185,7 @@ function registerDiagnoseCommands(diagnoseCmd2) {
|
|
|
7108
7185
|
const s = !json ? clack16.spinner() : null;
|
|
7109
7186
|
s?.start("Collecting diagnostic data...");
|
|
7110
7187
|
const data2 = await collectDiagnosticData(projectId, ossMode, apiUrl);
|
|
7111
|
-
const cliVersion = "0.1.
|
|
7188
|
+
const cliVersion = "0.1.85";
|
|
7112
7189
|
s?.stop("Data collected");
|
|
7113
7190
|
if (!json) {
|
|
7114
7191
|
console.log(`
|
|
@@ -7589,16 +7666,14 @@ function formatRecurring(interval, intervalCount) {
|
|
|
7589
7666
|
}
|
|
7590
7667
|
async function trackPaymentUsage(subcommand, success, properties = {}) {
|
|
7591
7668
|
try {
|
|
7592
|
-
|
|
7593
|
-
|
|
7594
|
-
|
|
7595
|
-
|
|
7596
|
-
|
|
7597
|
-
|
|
7598
|
-
});
|
|
7599
|
-
}
|
|
7600
|
-
} catch {
|
|
7669
|
+
const config = getProjectConfig();
|
|
7670
|
+
if (config) {
|
|
7671
|
+
trackPayments(subcommand, config, {
|
|
7672
|
+
success,
|
|
7673
|
+
...properties
|
|
7674
|
+
});
|
|
7601
7675
|
}
|
|
7676
|
+
} catch {
|
|
7602
7677
|
} finally {
|
|
7603
7678
|
await shutdownAnalytics();
|
|
7604
7679
|
}
|