@insforge/cli 0.1.8 → 0.1.9

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
@@ -1,13 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/index.ts
4
- import { existsSync as existsSync5, mkdirSync as mkdirSync2, readFileSync as readFileSync6 } from "fs";
4
+ 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
-
9
- // src/commands/login.ts
10
- import * as clack3 from "@clack/prompts";
8
+ import * as clack13 from "@clack/prompts";
11
9
 
12
10
  // src/lib/config.ts
13
11
  import { existsSync, mkdirSync, readFileSync, writeFileSync, unlinkSync } from "fs";
@@ -86,6 +84,9 @@ function getAccessToken() {
86
84
  return process.env.INSFORGE_ACCESS_TOKEN ?? getCredentials()?.access_token ?? null;
87
85
  }
88
86
 
87
+ // src/commands/login.ts
88
+ import * as clack3 from "@clack/prompts";
89
+
89
90
  // src/lib/errors.ts
90
91
  var CLIError = class extends Error {
91
92
  constructor(message, exitCode = 1, code) {
@@ -317,7 +318,19 @@ async function requireAuth(apiUrl) {
317
318
  const creds = getCredentials();
318
319
  if (creds && creds.access_token) return creds;
319
320
  clack2.log.info("You need to log in to continue.");
320
- return await performOAuthLogin(apiUrl);
321
+ for (; ; ) {
322
+ try {
323
+ return await performOAuthLogin(apiUrl);
324
+ } catch (err) {
325
+ if (!process.stdout.isTTY) throw err;
326
+ const msg = err instanceof Error ? err.message : "Unknown error";
327
+ clack2.log.error(`Login failed: ${msg}`);
328
+ const retry = await clack2.confirm({ message: "Would you like to try again?" });
329
+ if (clack2.isCancel(retry) || !retry) {
330
+ throw new AuthError("Authentication required. Run `insforge login` to authenticate.");
331
+ }
332
+ }
333
+ }
321
334
  }
322
335
  async function refreshAccessToken(apiUrl) {
323
336
  const creds = getCredentials();
@@ -1605,10 +1618,10 @@ function registerStorageDeleteBucketCommand(storageCmd2) {
1605
1618
  try {
1606
1619
  await requireAuth();
1607
1620
  if (!yes && !json) {
1608
- const confirm6 = await clack7.confirm({
1621
+ const confirm7 = await clack7.confirm({
1609
1622
  message: `Delete bucket "${name}" and all its objects? This cannot be undone.`
1610
1623
  });
1611
- if (!confirm6 || clack7.isCancel(confirm6)) {
1624
+ if (!confirm7 || clack7.isCancel(confirm7)) {
1612
1625
  process.exit(0);
1613
1626
  }
1614
1627
  }
@@ -2449,10 +2462,10 @@ function registerSecretsDeleteCommand(secretsCmd2) {
2449
2462
  try {
2450
2463
  await requireAuth();
2451
2464
  if (!yes && !json) {
2452
- const confirm6 = await clack11.confirm({
2465
+ const confirm7 = await clack11.confirm({
2453
2466
  message: `Delete secret "${key}"? This cannot be undone.`
2454
2467
  });
2455
- if (!confirm6 || clack11.isCancel(confirm6)) {
2468
+ if (!confirm7 || clack11.isCancel(confirm7)) {
2456
2469
  process.exit(0);
2457
2470
  }
2458
2471
  }
@@ -2631,10 +2644,10 @@ function registerSchedulesDeleteCommand(schedulesCmd2) {
2631
2644
  try {
2632
2645
  await requireAuth();
2633
2646
  if (!yes && !json) {
2634
- const confirm6 = await clack12.confirm({
2647
+ const confirm7 = await clack12.confirm({
2635
2648
  message: `Delete schedule "${id}"? This cannot be undone.`
2636
2649
  });
2637
- if (!confirm6 || clack12.isCancel(confirm6)) {
2650
+ if (!confirm7 || clack12.isCancel(confirm7)) {
2638
2651
  process.exit(0);
2639
2652
  }
2640
2653
  }
@@ -2743,15 +2756,6 @@ var INSFORGE_LOGO = `
2743
2756
  \u2588\u2588\u2551\u2588\u2588\u2551 \u255A\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2551 \u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2551 \u2588\u2588\u2551\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557
2744
2757
  \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u2550\u2550\u255D\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D
2745
2758
  `;
2746
- function showLogoOnFirstRun() {
2747
- if (process.argv.includes("--json")) return;
2748
- const localDir = join6(process.cwd(), ".insforge");
2749
- if (existsSync5(localDir)) return;
2750
- console.log(INSFORGE_LOGO);
2751
- console.log(" Welcome to InsForge CLI! Run `insforge login` to get started.\n");
2752
- mkdirSync2(localDir, { recursive: true });
2753
- }
2754
- showLogoOnFirstRun();
2755
2759
  var program = new Command();
2756
2760
  program.name("insforge").description("InsForge CLI - Command line tool for InsForge platform").version(pkg.version);
2757
2761
  program.option("--json", "Output in JSON format").option("--api-url <url>", "Override Platform API URL").option("-y, --yes", "Skip confirmation prompts");
@@ -2813,5 +2817,66 @@ registerSchedulesCreateCommand(schedulesCmd);
2813
2817
  registerSchedulesUpdateCommand(schedulesCmd);
2814
2818
  registerSchedulesDeleteCommand(schedulesCmd);
2815
2819
  registerSchedulesLogsCommand(schedulesCmd);
2816
- program.parse();
2820
+ if (process.argv.length <= 2 && process.stdout.isTTY) {
2821
+ await showInteractiveMenu();
2822
+ } else {
2823
+ program.parse();
2824
+ }
2825
+ async function showInteractiveMenu() {
2826
+ let isLoggedIn = false;
2827
+ let isLinked = false;
2828
+ try {
2829
+ isLoggedIn = !!getCredentials()?.access_token;
2830
+ } catch {
2831
+ }
2832
+ try {
2833
+ isLinked = !!getProjectConfig()?.project_id;
2834
+ } catch {
2835
+ }
2836
+ console.log(INSFORGE_LOGO);
2837
+ clack13.intro(`InsForge CLI v${pkg.version}`);
2838
+ const options = [];
2839
+ if (!isLoggedIn) {
2840
+ options.push({ value: "login", label: "Log in to InsForge" });
2841
+ }
2842
+ options.push(
2843
+ { value: "create", label: "Create a new project", hint: isLoggedIn ? void 0 : "requires login" },
2844
+ { value: "link", label: "Link an existing project", hint: isLoggedIn ? void 0 : "requires login" }
2845
+ );
2846
+ if (isLinked) {
2847
+ options.push({ value: "deploy", label: "Deploy your project" });
2848
+ }
2849
+ options.push(
2850
+ { value: "docs", label: "View documentation" },
2851
+ { value: "help", label: "Show all commands" }
2852
+ );
2853
+ const action = await clack13.select({
2854
+ message: "What would you like to do?",
2855
+ options
2856
+ });
2857
+ if (clack13.isCancel(action)) {
2858
+ clack13.cancel("Bye!");
2859
+ process.exit(0);
2860
+ }
2861
+ switch (action) {
2862
+ case "login":
2863
+ await program.parseAsync(["node", "insforge", "login"]);
2864
+ break;
2865
+ case "create":
2866
+ await program.parseAsync(["node", "insforge", "create"]);
2867
+ break;
2868
+ case "link":
2869
+ await program.parseAsync(["node", "insforge", "link"]);
2870
+ break;
2871
+ case "deploy":
2872
+ await program.parseAsync(["node", "insforge", "deployments", "deploy"]);
2873
+ break;
2874
+ case "docs":
2875
+ await program.parseAsync(["node", "insforge", "docs"]);
2876
+ break;
2877
+ case "help":
2878
+ program.help();
2879
+ break;
2880
+ }
2881
+ }
2817
2882
  //# sourceMappingURL=index.js.map