@insforge/cli 0.1.19 → 0.1.20

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
@@ -5,7 +5,7 @@ import { readFileSync as readFileSync6 } from "fs";
5
5
  import { join as join6, dirname } from "path";
6
6
  import { fileURLToPath } from "url";
7
7
  import { Command } from "commander";
8
- import * as clack13 from "@clack/prompts";
8
+ import * as clack14 from "@clack/prompts";
9
9
 
10
10
  // src/lib/config.ts
11
11
  import { existsSync, mkdirSync, readFileSync, writeFileSync, unlinkSync } from "fs";
@@ -1399,23 +1399,42 @@ Specify --file <path> or create ${join3("insforge", "functions", slug, "index.ts
1399
1399
  } catch {
1400
1400
  exists = false;
1401
1401
  }
1402
+ let res;
1402
1403
  if (exists) {
1403
- await ossFetch(`/api/functions/${encodeURIComponent(slug)}`, {
1404
+ res = await ossFetch(`/api/functions/${encodeURIComponent(slug)}`, {
1404
1405
  method: "PUT",
1405
1406
  body: JSON.stringify({ name, description, code })
1406
1407
  });
1407
1408
  } else {
1408
- await ossFetch("/api/functions", {
1409
+ res = await ossFetch("/api/functions", {
1409
1410
  method: "POST",
1410
1411
  body: JSON.stringify({ slug, name, description, code })
1411
1412
  });
1412
1413
  }
1414
+ const result = await res.json();
1415
+ const deployFailed = result.deployment?.status === "failed";
1413
1416
  if (json) {
1414
- outputJson({ success: true, slug, action: exists ? "updated" : "created" });
1417
+ outputJson(result);
1415
1418
  } else {
1416
- outputSuccess(`Function "${slug}" ${exists ? "updated" : "created"} successfully.`);
1419
+ const action = exists ? "updation" : "creation";
1420
+ const resultStatus = result.success ? "success" : "failed";
1421
+ outputSuccess(`Function "${result.function.slug}" ${action} ${resultStatus}.`);
1422
+ if (result.deployment) {
1423
+ if (result.deployment.status === "success") {
1424
+ console.log(` Deployment: ${result.deployment.status}${result.deployment.url ? ` \u2192 ${result.deployment.url}` : ""}`);
1425
+ } else {
1426
+ console.log(` Deployment: ${result.deployment.status}`);
1427
+ if (result.deployment.buildLogs?.length) {
1428
+ console.log(" Build logs:");
1429
+ for (const line of result.deployment.buildLogs) {
1430
+ console.log(` ${line}`);
1431
+ }
1432
+ }
1433
+ }
1434
+ }
1417
1435
  }
1418
- await reportCliUsage("cli.functions.deploy", true);
1436
+ await reportCliUsage("cli.functions.deploy", !deployFailed);
1437
+ if (deployFailed) process.exit(1);
1419
1438
  } catch (err) {
1420
1439
  await reportCliUsage("cli.functions.deploy", false);
1421
1440
  handleError(err, json);
@@ -1496,6 +1515,43 @@ function registerFunctionsCodeCommand(functionsCmd2) {
1496
1515
  });
1497
1516
  }
1498
1517
 
1518
+ // src/commands/functions/delete.ts
1519
+ import * as clack7 from "@clack/prompts";
1520
+ function registerFunctionsDeleteCommand(functionsCmd2) {
1521
+ functionsCmd2.command("delete <slug>").description("Delete an edge function").action(async (slug, _opts, cmd) => {
1522
+ const { json, yes } = getRootOpts(cmd);
1523
+ try {
1524
+ await requireAuth();
1525
+ if (!yes && !json) {
1526
+ const confirmed = await clack7.confirm({
1527
+ message: `Delete function "${slug}"? This cannot be undone.`
1528
+ });
1529
+ if (clack7.isCancel(confirmed) || !confirmed) {
1530
+ clack7.log.info("Cancelled.");
1531
+ return;
1532
+ }
1533
+ }
1534
+ const res = await ossFetch(`/api/functions/${encodeURIComponent(slug)}`, {
1535
+ method: "DELETE"
1536
+ });
1537
+ const result = await res.json();
1538
+ if (json) {
1539
+ outputJson(result);
1540
+ } else {
1541
+ if (result.success) {
1542
+ outputSuccess(`Function "${slug}" deleted successfully.`);
1543
+ } else {
1544
+ outputSuccess(`Failed to delete function "${slug}".`);
1545
+ }
1546
+ }
1547
+ await reportCliUsage("cli.functions.delete", true);
1548
+ } catch (err) {
1549
+ await reportCliUsage("cli.functions.delete", false);
1550
+ handleError(err, json);
1551
+ }
1552
+ });
1553
+ }
1554
+
1499
1555
  // src/commands/storage/buckets.ts
1500
1556
  function registerStorageBucketsCommand(storageCmd2) {
1501
1557
  storageCmd2.command("buckets").description("List all storage buckets").action(async (_opts, cmd) => {
@@ -1629,17 +1685,17 @@ function registerStorageCreateBucketCommand(storageCmd2) {
1629
1685
  }
1630
1686
 
1631
1687
  // src/commands/storage/delete-bucket.ts
1632
- import * as clack7 from "@clack/prompts";
1688
+ import * as clack8 from "@clack/prompts";
1633
1689
  function registerStorageDeleteBucketCommand(storageCmd2) {
1634
1690
  storageCmd2.command("delete-bucket <name>").description("Delete a storage bucket and all its objects").action(async (name, _opts, cmd) => {
1635
1691
  const { json, yes } = getRootOpts(cmd);
1636
1692
  try {
1637
1693
  await requireAuth();
1638
1694
  if (!yes && !json) {
1639
- const confirm7 = await clack7.confirm({
1695
+ const confirm8 = await clack8.confirm({
1640
1696
  message: `Delete bucket "${name}" and all its objects? This cannot be undone.`
1641
1697
  });
1642
- if (!confirm7 || clack7.isCancel(confirm7)) {
1698
+ if (!confirm8 || clack8.isCancel(confirm8)) {
1643
1699
  process.exit(0);
1644
1700
  }
1645
1701
  }
@@ -1721,12 +1777,12 @@ import { tmpdir } from "os";
1721
1777
  import { promisify as promisify2 } from "util";
1722
1778
  import * as fs2 from "fs/promises";
1723
1779
  import * as path2 from "path";
1724
- import * as clack9 from "@clack/prompts";
1780
+ import * as clack10 from "@clack/prompts";
1725
1781
 
1726
1782
  // src/commands/deployments/deploy.ts
1727
1783
  import * as path from "path";
1728
1784
  import * as fs from "fs/promises";
1729
- import * as clack8 from "@clack/prompts";
1785
+ import * as clack9 from "@clack/prompts";
1730
1786
  import archiver from "archiver";
1731
1787
  var POLL_INTERVAL_MS = 5e3;
1732
1788
  var POLL_TIMEOUT_MS = 12e4;
@@ -1830,7 +1886,7 @@ function registerDeploymentsDeployCommand(deploymentsCmd2) {
1830
1886
  if (!stats?.isDirectory()) {
1831
1887
  throw new CLIError(`"${sourceDir}" is not a valid directory.`);
1832
1888
  }
1833
- const s = !json ? clack8.spinner() : null;
1889
+ const s = !json ? clack9.spinner() : null;
1834
1890
  const startBody = {};
1835
1891
  if (opts.env) {
1836
1892
  try {
@@ -1858,18 +1914,18 @@ function registerDeploymentsDeployCommand(deploymentsCmd2) {
1858
1914
  outputJson(result.deployment);
1859
1915
  } else {
1860
1916
  if (result.liveUrl) {
1861
- clack8.log.success(`Live at: ${result.liveUrl}`);
1917
+ clack9.log.success(`Live at: ${result.liveUrl}`);
1862
1918
  }
1863
- clack8.log.info(`Deployment ID: ${result.deploymentId}`);
1919
+ clack9.log.info(`Deployment ID: ${result.deploymentId}`);
1864
1920
  }
1865
1921
  } else {
1866
1922
  s?.stop("Deployment is still building");
1867
1923
  if (json) {
1868
1924
  outputJson({ id: result.deploymentId, status: result.deployment?.status ?? "building", timedOut: true });
1869
1925
  } else {
1870
- clack8.log.info(`Deployment ID: ${result.deploymentId}`);
1871
- clack8.log.warn("Deployment did not finish within 2 minutes.");
1872
- clack8.log.info(`Check status with: insforge deployments status ${result.deploymentId}`);
1926
+ clack9.log.info(`Deployment ID: ${result.deploymentId}`);
1927
+ clack9.log.warn("Deployment did not finish within 2 minutes.");
1928
+ clack9.log.info(`Check status with: insforge deployments status ${result.deploymentId}`);
1873
1929
  }
1874
1930
  }
1875
1931
  await reportCliUsage("cli.deployments.deploy", true);
@@ -1913,7 +1969,7 @@ function registerCreateCommand(program2) {
1913
1969
  try {
1914
1970
  await requireAuth(apiUrl);
1915
1971
  if (!json) {
1916
- clack9.intro("Create a new InsForge project");
1972
+ clack10.intro("Create a new InsForge project");
1917
1973
  }
1918
1974
  let orgId = opts.orgId;
1919
1975
  if (!orgId) {
@@ -1924,14 +1980,14 @@ function registerCreateCommand(program2) {
1924
1980
  if (json) {
1925
1981
  throw new CLIError("Specify --org-id in JSON mode.");
1926
1982
  }
1927
- const selected = await clack9.select({
1983
+ const selected = await clack10.select({
1928
1984
  message: "Select an organization:",
1929
1985
  options: orgs.map((o) => ({
1930
1986
  value: o.id,
1931
1987
  label: o.name
1932
1988
  }))
1933
1989
  });
1934
- if (clack9.isCancel(selected)) process.exit(0);
1990
+ if (clack10.isCancel(selected)) process.exit(0);
1935
1991
  orgId = selected;
1936
1992
  }
1937
1993
  const globalConfig = getGlobalConfig();
@@ -1940,11 +1996,11 @@ function registerCreateCommand(program2) {
1940
1996
  let projectName = opts.name;
1941
1997
  if (!projectName) {
1942
1998
  if (json) throw new CLIError("--name is required in JSON mode.");
1943
- const name = await clack9.text({
1999
+ const name = await clack10.text({
1944
2000
  message: "Project name:",
1945
2001
  validate: (v) => v.length >= 2 ? void 0 : "Name must be at least 2 characters"
1946
2002
  });
1947
- if (clack9.isCancel(name)) process.exit(0);
2003
+ if (clack10.isCancel(name)) process.exit(0);
1948
2004
  projectName = name;
1949
2005
  }
1950
2006
  let template = opts.template;
@@ -1952,7 +2008,7 @@ function registerCreateCommand(program2) {
1952
2008
  if (json) {
1953
2009
  template = "empty";
1954
2010
  } else {
1955
- const selected = await clack9.select({
2011
+ const selected = await clack10.select({
1956
2012
  message: "Choose a starter template:",
1957
2013
  options: [
1958
2014
  { value: "react", label: "Web app template with React" },
@@ -1960,11 +2016,11 @@ function registerCreateCommand(program2) {
1960
2016
  { value: "empty", label: "Empty project" }
1961
2017
  ]
1962
2018
  });
1963
- if (clack9.isCancel(selected)) process.exit(0);
2019
+ if (clack10.isCancel(selected)) process.exit(0);
1964
2020
  template = selected;
1965
2021
  }
1966
2022
  }
1967
- const s = !json ? clack9.spinner() : null;
2023
+ const s = !json ? clack10.spinner() : null;
1968
2024
  s?.start("Creating project...");
1969
2025
  const project = await createProject(orgId, projectName, opts.region, apiUrl);
1970
2026
  s?.message("Waiting for project to become active...");
@@ -1989,7 +2045,7 @@ function registerCreateCommand(program2) {
1989
2045
  await installSkills(json);
1990
2046
  await reportCliUsage("cli.create", true, 6);
1991
2047
  if (hasTemplate) {
1992
- const installSpinner = !json ? clack9.spinner() : null;
2048
+ const installSpinner = !json ? clack10.spinner() : null;
1993
2049
  installSpinner?.start("Installing dependencies...");
1994
2050
  try {
1995
2051
  await execAsync2("npm install", { cwd: process.cwd(), maxBuffer: 10 * 1024 * 1024 });
@@ -1997,19 +2053,19 @@ function registerCreateCommand(program2) {
1997
2053
  } catch (err) {
1998
2054
  installSpinner?.stop("Failed to install dependencies");
1999
2055
  if (!json) {
2000
- clack9.log.warn(`npm install failed: ${err.message}`);
2001
- clack9.log.info("Run `npm install` manually to install dependencies.");
2056
+ clack10.log.warn(`npm install failed: ${err.message}`);
2057
+ clack10.log.info("Run `npm install` manually to install dependencies.");
2002
2058
  }
2003
2059
  }
2004
2060
  }
2005
2061
  let liveUrl = null;
2006
2062
  if (hasTemplate && !json) {
2007
- const shouldDeploy = await clack9.confirm({
2063
+ const shouldDeploy = await clack10.confirm({
2008
2064
  message: "Would you like to deploy now?"
2009
2065
  });
2010
- if (!clack9.isCancel(shouldDeploy) && shouldDeploy) {
2066
+ if (!clack10.isCancel(shouldDeploy) && shouldDeploy) {
2011
2067
  try {
2012
- const deploySpinner = clack9.spinner();
2068
+ const deploySpinner = clack10.spinner();
2013
2069
  const result = await deployProject({
2014
2070
  sourceDir: process.cwd(),
2015
2071
  spinner: deploySpinner
@@ -2019,12 +2075,12 @@ function registerCreateCommand(program2) {
2019
2075
  liveUrl = result.liveUrl;
2020
2076
  } else {
2021
2077
  deploySpinner.stop("Deployment is still building");
2022
- clack9.log.info(`Deployment ID: ${result.deploymentId}`);
2023
- clack9.log.warn("Deployment did not finish within 2 minutes.");
2024
- clack9.log.info(`Check status with: insforge deployments status ${result.deploymentId}`);
2078
+ clack10.log.info(`Deployment ID: ${result.deploymentId}`);
2079
+ clack10.log.warn("Deployment did not finish within 2 minutes.");
2080
+ clack10.log.info(`Check status with: insforge deployments status ${result.deploymentId}`);
2025
2081
  }
2026
2082
  } catch (err) {
2027
- clack9.log.warn(`Deploy failed: ${err.message}`);
2083
+ clack10.log.warn(`Deploy failed: ${err.message}`);
2028
2084
  }
2029
2085
  }
2030
2086
  }
@@ -2040,11 +2096,11 @@ function registerCreateCommand(program2) {
2040
2096
  }
2041
2097
  });
2042
2098
  } else {
2043
- clack9.log.step(`Dashboard: ${dashboardUrl}`);
2099
+ clack10.log.step(`Dashboard: ${dashboardUrl}`);
2044
2100
  if (liveUrl) {
2045
- clack9.log.success(`Live site: ${liveUrl}`);
2101
+ clack10.log.success(`Live site: ${liveUrl}`);
2046
2102
  }
2047
- clack9.outro("Done!");
2103
+ clack10.outro("Done!");
2048
2104
  }
2049
2105
  } catch (err) {
2050
2106
  handleError(err, json);
@@ -2052,7 +2108,7 @@ function registerCreateCommand(program2) {
2052
2108
  });
2053
2109
  }
2054
2110
  async function downloadTemplate(framework, projectConfig, projectName, json, _apiUrl) {
2055
- const s = !json ? clack9.spinner() : null;
2111
+ const s = !json ? clack10.spinner() : null;
2056
2112
  s?.start("Downloading template...");
2057
2113
  try {
2058
2114
  const anonKey = await getAnonKey();
@@ -2083,8 +2139,8 @@ async function downloadTemplate(framework, projectConfig, projectName, json, _ap
2083
2139
  } catch (err) {
2084
2140
  s?.stop("Template download failed");
2085
2141
  if (!json) {
2086
- clack9.log.warn(`Failed to download template: ${err.message}`);
2087
- clack9.log.info("You can manually set up the template later.");
2142
+ clack10.log.warn(`Failed to download template: ${err.message}`);
2143
+ clack10.log.info("You can manually set up the template later.");
2088
2144
  }
2089
2145
  }
2090
2146
  }
@@ -2267,7 +2323,7 @@ function registerDeploymentsStatusCommand(deploymentsCmd2) {
2267
2323
  }
2268
2324
 
2269
2325
  // src/commands/deployments/cancel.ts
2270
- import * as clack10 from "@clack/prompts";
2326
+ import * as clack11 from "@clack/prompts";
2271
2327
  function registerDeploymentsCancelCommand(deploymentsCmd2) {
2272
2328
  deploymentsCmd2.command("cancel <id>").description("Cancel a deployment").action(async (id, _opts, cmd) => {
2273
2329
  const { json, yes } = getRootOpts(cmd);
@@ -2275,10 +2331,10 @@ function registerDeploymentsCancelCommand(deploymentsCmd2) {
2275
2331
  await requireAuth();
2276
2332
  if (!getProjectConfig()) throw new ProjectNotLinkedError();
2277
2333
  if (!yes && !json) {
2278
- const confirmed = await clack10.confirm({
2334
+ const confirmed = await clack11.confirm({
2279
2335
  message: `Cancel deployment ${id}?`
2280
2336
  });
2281
- if (clack10.isCancel(confirmed) || !confirmed) process.exit(0);
2337
+ if (clack11.isCancel(confirmed) || !confirmed) process.exit(0);
2282
2338
  }
2283
2339
  const res = await ossFetch(`/api/deployments/${id}/cancel`, { method: "POST" });
2284
2340
  const result = await res.json();
@@ -2481,17 +2537,17 @@ function registerSecretsUpdateCommand(secretsCmd2) {
2481
2537
  }
2482
2538
 
2483
2539
  // src/commands/secrets/delete.ts
2484
- import * as clack11 from "@clack/prompts";
2540
+ import * as clack12 from "@clack/prompts";
2485
2541
  function registerSecretsDeleteCommand(secretsCmd2) {
2486
2542
  secretsCmd2.command("delete <key>").description("Delete a secret").action(async (key, _opts, cmd) => {
2487
2543
  const { json, yes } = getRootOpts(cmd);
2488
2544
  try {
2489
2545
  await requireAuth();
2490
2546
  if (!yes && !json) {
2491
- const confirm7 = await clack11.confirm({
2547
+ const confirm8 = await clack12.confirm({
2492
2548
  message: `Delete secret "${key}"? This cannot be undone.`
2493
2549
  });
2494
- if (!confirm7 || clack11.isCancel(confirm7)) {
2550
+ if (!confirm8 || clack12.isCancel(confirm8)) {
2495
2551
  process.exit(0);
2496
2552
  }
2497
2553
  }
@@ -2667,17 +2723,17 @@ function registerSchedulesUpdateCommand(schedulesCmd2) {
2667
2723
  }
2668
2724
 
2669
2725
  // src/commands/schedules/delete.ts
2670
- import * as clack12 from "@clack/prompts";
2726
+ import * as clack13 from "@clack/prompts";
2671
2727
  function registerSchedulesDeleteCommand(schedulesCmd2) {
2672
2728
  schedulesCmd2.command("delete <id>").description("Delete a schedule").action(async (id, _opts, cmd) => {
2673
2729
  const { json, yes } = getRootOpts(cmd);
2674
2730
  try {
2675
2731
  await requireAuth();
2676
2732
  if (!yes && !json) {
2677
- const confirm7 = await clack12.confirm({
2733
+ const confirm8 = await clack13.confirm({
2678
2734
  message: `Delete schedule "${id}"? This cannot be undone.`
2679
2735
  });
2680
- if (!confirm7 || clack12.isCancel(confirm7)) {
2736
+ if (!confirm8 || clack13.isCancel(confirm8)) {
2681
2737
  process.exit(0);
2682
2738
  }
2683
2739
  }
@@ -2906,6 +2962,7 @@ registerFunctionsCommands(functionsCmd);
2906
2962
  registerFunctionsCodeCommand(functionsCmd);
2907
2963
  registerFunctionsDeployCommand(functionsCmd);
2908
2964
  registerFunctionsInvokeCommand(functionsCmd);
2965
+ registerFunctionsDeleteCommand(functionsCmd);
2909
2966
  var storageCmd = program.command("storage").description("Manage storage");
2910
2967
  registerStorageBucketsCommand(storageCmd);
2911
2968
  registerStorageCreateBucketCommand(storageCmd);
@@ -2950,7 +3007,7 @@ async function showInteractiveMenu() {
2950
3007
  } catch {
2951
3008
  }
2952
3009
  console.log(INSFORGE_LOGO);
2953
- clack13.intro(`InsForge CLI v${pkg.version}`);
3010
+ clack14.intro(`InsForge CLI v${pkg.version}`);
2954
3011
  const options = [];
2955
3012
  if (!isLoggedIn) {
2956
3013
  options.push({ value: "login", label: "Log in to InsForge" });
@@ -2966,12 +3023,12 @@ async function showInteractiveMenu() {
2966
3023
  { value: "docs", label: "View documentation" },
2967
3024
  { value: "help", label: "Show all commands" }
2968
3025
  );
2969
- const action = await clack13.select({
3026
+ const action = await clack14.select({
2970
3027
  message: "What would you like to do?",
2971
3028
  options
2972
3029
  });
2973
- if (clack13.isCancel(action)) {
2974
- clack13.cancel("Bye!");
3030
+ if (clack14.isCancel(action)) {
3031
+ clack14.cancel("Bye!");
2975
3032
  process.exit(0);
2976
3033
  }
2977
3034
  switch (action) {