@insforge/cli 0.1.8 → 0.1.10
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 +170 -21
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
|
-
import {
|
|
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
|
-
|
|
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
|
|
1621
|
+
const confirm7 = await clack7.confirm({
|
|
1609
1622
|
message: `Delete bucket "${name}" and all its objects? This cannot be undone.`
|
|
1610
1623
|
});
|
|
1611
|
-
if (!
|
|
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
|
|
2465
|
+
const confirm7 = await clack11.confirm({
|
|
2453
2466
|
message: `Delete secret "${key}"? This cannot be undone.`
|
|
2454
2467
|
});
|
|
2455
|
-
if (!
|
|
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
|
|
2647
|
+
const confirm7 = await clack12.confirm({
|
|
2635
2648
|
message: `Delete schedule "${id}"? This cannot be undone.`
|
|
2636
2649
|
});
|
|
2637
|
-
if (!
|
|
2650
|
+
if (!confirm7 || clack12.isCancel(confirm7)) {
|
|
2638
2651
|
process.exit(0);
|
|
2639
2652
|
}
|
|
2640
2653
|
}
|
|
@@ -2732,6 +2745,89 @@ function registerLogsCommand(program2) {
|
|
|
2732
2745
|
});
|
|
2733
2746
|
}
|
|
2734
2747
|
|
|
2748
|
+
// src/commands/metadata.ts
|
|
2749
|
+
function registerMetadataCommand(program2) {
|
|
2750
|
+
program2.command("metadata").description("Show backend metadata (auth, database, buckets, edge functions, realtime, AI models)").action(async (_opts, cmd) => {
|
|
2751
|
+
const { json } = getRootOpts(cmd);
|
|
2752
|
+
try {
|
|
2753
|
+
await requireAuth();
|
|
2754
|
+
const res = await ossFetch("/api/metadata");
|
|
2755
|
+
const data = await res.json();
|
|
2756
|
+
if (json) {
|
|
2757
|
+
outputJson(data);
|
|
2758
|
+
return;
|
|
2759
|
+
}
|
|
2760
|
+
console.log("\n Auth");
|
|
2761
|
+
console.log(` OAuth Providers: ${data.auth.oAuthProviders.length ? data.auth.oAuthProviders.join(", ") : "(none)"}`);
|
|
2762
|
+
console.log(` Email Verification: ${data.auth.requireEmailVerification ? "Yes" : "No"}`);
|
|
2763
|
+
console.log(` Password Policy:`);
|
|
2764
|
+
console.log(` Min Length: ${data.auth.passwordMinLength}, requireLowercase: ${data.auth.requireLowercase}, requireNumber: ${data.auth.requireNumber}, requireSpecialChar: ${data.auth.requireSpecialChar}, requireUppercase: ${data.auth.requireUppercase}`);
|
|
2765
|
+
console.log(` Verify Email Method: ${data.auth.verifyEmailMethod}`);
|
|
2766
|
+
console.log(` Reset Password Method: ${data.auth.resetPasswordMethod}`);
|
|
2767
|
+
console.log("\n Database");
|
|
2768
|
+
console.log(` Size: ${formatSize2(data.database.totalSizeInGB)}`);
|
|
2769
|
+
if (data.database.tables.length) {
|
|
2770
|
+
outputTable(
|
|
2771
|
+
["Table", "Records"],
|
|
2772
|
+
data.database.tables.map((t) => [t.tableName, String(t.recordCount)])
|
|
2773
|
+
);
|
|
2774
|
+
} else {
|
|
2775
|
+
console.log(" No tables.");
|
|
2776
|
+
}
|
|
2777
|
+
console.log("\n Storage");
|
|
2778
|
+
console.log(` Size: ${formatSize2(data.storage.totalSizeInGB)}`);
|
|
2779
|
+
if (data.storage.buckets.length) {
|
|
2780
|
+
outputTable(
|
|
2781
|
+
["Bucket", "Public", "Objects"],
|
|
2782
|
+
data.storage.buckets.map((b) => [b.name, b.public ? "Yes" : "No", String(b.objectCount ?? "-")])
|
|
2783
|
+
);
|
|
2784
|
+
} else {
|
|
2785
|
+
console.log(" No buckets.");
|
|
2786
|
+
}
|
|
2787
|
+
console.log("\n Functions");
|
|
2788
|
+
if (data.functions.length) {
|
|
2789
|
+
outputTable(
|
|
2790
|
+
["Slug", "Name", "Status", "Description"],
|
|
2791
|
+
data.functions.map((f) => [f.slug, f.name, f.status, f.description || "-"])
|
|
2792
|
+
);
|
|
2793
|
+
} else {
|
|
2794
|
+
console.log(" No functions deployed.");
|
|
2795
|
+
}
|
|
2796
|
+
if (data.aiIntegration?.models?.length) {
|
|
2797
|
+
console.log("\n AI Models");
|
|
2798
|
+
outputTable(
|
|
2799
|
+
["Model", "Input", "Output"],
|
|
2800
|
+
data.aiIntegration.models.map((m) => [
|
|
2801
|
+
m.modelId,
|
|
2802
|
+
m.inputModality.join(", "),
|
|
2803
|
+
m.outputModality.join(", ")
|
|
2804
|
+
])
|
|
2805
|
+
);
|
|
2806
|
+
}
|
|
2807
|
+
if (data.realtime?.channels && Array.isArray(data.realtime.channels) && data.realtime.channels.length) {
|
|
2808
|
+
console.log(`
|
|
2809
|
+
Realtime: ${data.realtime.channels.length} channel(s)`);
|
|
2810
|
+
outputTable(
|
|
2811
|
+
["Id", "Pattern", "Webhook URLs", "Enabled", "Description"],
|
|
2812
|
+
data.realtime.channels.map((c) => [c.id, c.pattern, c.webhookUrls?.join(", ") || "-", c.enabled ? "Yes" : "No", c.description || "-"])
|
|
2813
|
+
);
|
|
2814
|
+
}
|
|
2815
|
+
if (data.version) {
|
|
2816
|
+
console.log(`
|
|
2817
|
+
Version: ${data.version}`);
|
|
2818
|
+
}
|
|
2819
|
+
console.log("");
|
|
2820
|
+
} catch (err) {
|
|
2821
|
+
handleError(err, json);
|
|
2822
|
+
}
|
|
2823
|
+
});
|
|
2824
|
+
}
|
|
2825
|
+
function formatSize2(gb) {
|
|
2826
|
+
if (gb < 1e-3) return `${(gb * 1024 * 1024).toFixed(1)} KB`;
|
|
2827
|
+
if (gb < 1) return `${(gb * 1024).toFixed(2)} MB`;
|
|
2828
|
+
return `${gb.toFixed(2)} GB`;
|
|
2829
|
+
}
|
|
2830
|
+
|
|
2735
2831
|
// src/index.ts
|
|
2736
2832
|
var __dirname = dirname(fileURLToPath(import.meta.url));
|
|
2737
2833
|
var pkg = JSON.parse(readFileSync6(join6(__dirname, "../package.json"), "utf-8"));
|
|
@@ -2743,15 +2839,6 @@ var INSFORGE_LOGO = `
|
|
|
2743
2839
|
\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
2840
|
\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
2841
|
`;
|
|
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
2842
|
var program = new Command();
|
|
2756
2843
|
program.name("insforge").description("InsForge CLI - Command line tool for InsForge platform").version(pkg.version);
|
|
2757
2844
|
program.option("--json", "Output in JSON format").option("--api-url <url>", "Override Platform API URL").option("-y, --yes", "Skip confirmation prompts");
|
|
@@ -2806,6 +2893,7 @@ registerSecretsAddCommand(secretsCmd);
|
|
|
2806
2893
|
registerSecretsUpdateCommand(secretsCmd);
|
|
2807
2894
|
registerSecretsDeleteCommand(secretsCmd);
|
|
2808
2895
|
registerLogsCommand(program);
|
|
2896
|
+
registerMetadataCommand(program);
|
|
2809
2897
|
var schedulesCmd = program.command("schedules").description("Manage scheduled tasks (cron jobs)");
|
|
2810
2898
|
registerSchedulesListCommand(schedulesCmd);
|
|
2811
2899
|
registerSchedulesGetCommand(schedulesCmd);
|
|
@@ -2813,5 +2901,66 @@ registerSchedulesCreateCommand(schedulesCmd);
|
|
|
2813
2901
|
registerSchedulesUpdateCommand(schedulesCmd);
|
|
2814
2902
|
registerSchedulesDeleteCommand(schedulesCmd);
|
|
2815
2903
|
registerSchedulesLogsCommand(schedulesCmd);
|
|
2816
|
-
|
|
2904
|
+
if (process.argv.length <= 2 && process.stdout.isTTY) {
|
|
2905
|
+
await showInteractiveMenu();
|
|
2906
|
+
} else {
|
|
2907
|
+
program.parse();
|
|
2908
|
+
}
|
|
2909
|
+
async function showInteractiveMenu() {
|
|
2910
|
+
let isLoggedIn = false;
|
|
2911
|
+
let isLinked = false;
|
|
2912
|
+
try {
|
|
2913
|
+
isLoggedIn = !!getCredentials()?.access_token;
|
|
2914
|
+
} catch {
|
|
2915
|
+
}
|
|
2916
|
+
try {
|
|
2917
|
+
isLinked = !!getProjectConfig()?.project_id;
|
|
2918
|
+
} catch {
|
|
2919
|
+
}
|
|
2920
|
+
console.log(INSFORGE_LOGO);
|
|
2921
|
+
clack13.intro(`InsForge CLI v${pkg.version}`);
|
|
2922
|
+
const options = [];
|
|
2923
|
+
if (!isLoggedIn) {
|
|
2924
|
+
options.push({ value: "login", label: "Log in to InsForge" });
|
|
2925
|
+
}
|
|
2926
|
+
options.push(
|
|
2927
|
+
{ value: "create", label: "Create a new project", hint: isLoggedIn ? void 0 : "requires login" },
|
|
2928
|
+
{ value: "link", label: "Link an existing project", hint: isLoggedIn ? void 0 : "requires login" }
|
|
2929
|
+
);
|
|
2930
|
+
if (isLinked) {
|
|
2931
|
+
options.push({ value: "deploy", label: "Deploy your project" });
|
|
2932
|
+
}
|
|
2933
|
+
options.push(
|
|
2934
|
+
{ value: "docs", label: "View documentation" },
|
|
2935
|
+
{ value: "help", label: "Show all commands" }
|
|
2936
|
+
);
|
|
2937
|
+
const action = await clack13.select({
|
|
2938
|
+
message: "What would you like to do?",
|
|
2939
|
+
options
|
|
2940
|
+
});
|
|
2941
|
+
if (clack13.isCancel(action)) {
|
|
2942
|
+
clack13.cancel("Bye!");
|
|
2943
|
+
process.exit(0);
|
|
2944
|
+
}
|
|
2945
|
+
switch (action) {
|
|
2946
|
+
case "login":
|
|
2947
|
+
await program.parseAsync(["node", "insforge", "login"]);
|
|
2948
|
+
break;
|
|
2949
|
+
case "create":
|
|
2950
|
+
await program.parseAsync(["node", "insforge", "create"]);
|
|
2951
|
+
break;
|
|
2952
|
+
case "link":
|
|
2953
|
+
await program.parseAsync(["node", "insforge", "link"]);
|
|
2954
|
+
break;
|
|
2955
|
+
case "deploy":
|
|
2956
|
+
await program.parseAsync(["node", "insforge", "deployments", "deploy"]);
|
|
2957
|
+
break;
|
|
2958
|
+
case "docs":
|
|
2959
|
+
await program.parseAsync(["node", "insforge", "docs"]);
|
|
2960
|
+
break;
|
|
2961
|
+
case "help":
|
|
2962
|
+
program.help();
|
|
2963
|
+
break;
|
|
2964
|
+
}
|
|
2965
|
+
}
|
|
2817
2966
|
//# sourceMappingURL=index.js.map
|