@insforge/cli 0.1.10 → 0.1.12

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
@@ -710,6 +710,44 @@ async function installSkills(json) {
710
710
  } catch {
711
711
  }
712
712
  }
713
+ async function reportCliUsage(toolName, success, maxRetries = 1) {
714
+ let config;
715
+ try {
716
+ config = getProjectConfig();
717
+ } catch {
718
+ return;
719
+ }
720
+ if (!config) return;
721
+ const payload = JSON.stringify({
722
+ tool_name: toolName,
723
+ success,
724
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
725
+ });
726
+ for (let attempt = 0; attempt < maxRetries; attempt++) {
727
+ try {
728
+ const controller = new AbortController();
729
+ const timer = setTimeout(() => controller.abort(), 3e3);
730
+ try {
731
+ const res = await fetch(`${config.oss_host}/api/usage/mcp`, {
732
+ method: "POST",
733
+ headers: {
734
+ "Content-Type": "application/json",
735
+ "x-api-key": config.api_key
736
+ },
737
+ body: payload,
738
+ signal: controller.signal
739
+ });
740
+ if (res.status < 500) return;
741
+ } finally {
742
+ clearTimeout(timer);
743
+ }
744
+ } catch {
745
+ }
746
+ if (attempt < maxRetries - 1) {
747
+ await new Promise((r) => setTimeout(r, 5e3));
748
+ }
749
+ }
750
+ }
713
751
 
714
752
  // src/commands/projects/link.ts
715
753
  function buildOssHost(appkey, region) {
@@ -781,7 +819,9 @@ function registerProjectLinkCommand(program2) {
781
819
  outputSuccess(`Linked to project "${project.name}" (${project.appkey}.${project.region})`);
782
820
  }
783
821
  await installSkills(json);
822
+ await reportCliUsage("cli.link", true, 6);
784
823
  } catch (err) {
824
+ await reportCliUsage("cli.link", false);
785
825
  handleError(err, json);
786
826
  }
787
827
  });
@@ -845,7 +885,9 @@ function registerDbCommands(dbCmd2) {
845
885
  }
846
886
  }
847
887
  }
888
+ await reportCliUsage("cli.db.query", true);
848
889
  } catch (err) {
890
+ await reportCliUsage("cli.db.query", false);
849
891
  handleError(err, json);
850
892
  }
851
893
  });
@@ -871,26 +913,15 @@ function registerDbTablesCommand(dbCmd2) {
871
913
  tables.map((t) => [t])
872
914
  );
873
915
  }
916
+ await reportCliUsage("cli.db.tables", true);
874
917
  } catch (err) {
918
+ await reportCliUsage("cli.db.tables", false);
875
919
  handleError(err, json);
876
920
  }
877
921
  });
878
922
  }
879
923
 
880
924
  // src/commands/db/functions.ts
881
- function str(val) {
882
- if (val === null || val === void 0) return "-";
883
- if (Array.isArray(val)) return val.join(", ");
884
- return String(val);
885
- }
886
- function extractArray(raw) {
887
- if (Array.isArray(raw)) return raw;
888
- if (raw && typeof raw === "object") {
889
- const arr = Object.values(raw).find(Array.isArray);
890
- if (arr) return arr;
891
- }
892
- return [];
893
- }
894
925
  function registerDbFunctionsCommand(dbCmd2) {
895
926
  dbCmd2.command("functions").description("List all database functions").action(async (_opts, cmd) => {
896
927
  const { json } = getRootOpts(cmd);
@@ -898,7 +929,7 @@ function registerDbFunctionsCommand(dbCmd2) {
898
929
  await requireAuth();
899
930
  const res = await ossFetch("/api/database/functions");
900
931
  const raw = await res.json();
901
- const functions = extractArray(raw);
932
+ const functions = Array.isArray(raw) ? raw : raw.functions ?? [];
902
933
  if (json) {
903
934
  outputJson(raw);
904
935
  } else {
@@ -907,30 +938,19 @@ function registerDbFunctionsCommand(dbCmd2) {
907
938
  return;
908
939
  }
909
940
  outputTable(
910
- ["Name", "Schema", "Language", "Return Type", "Arguments"],
911
- functions.map((f) => [str(f.name), str(f.schema), str(f.language), str(f.returnType), str(f.arguments)])
941
+ ["Name", "Definition", "Kind"],
942
+ functions.map((f) => [f.functionName, f.functionDef, f.kind])
912
943
  );
913
944
  }
945
+ await reportCliUsage("cli.db.functions", true);
914
946
  } catch (err) {
947
+ await reportCliUsage("cli.db.functions", false);
915
948
  handleError(err, json);
916
949
  }
917
950
  });
918
951
  }
919
952
 
920
953
  // src/commands/db/indexes.ts
921
- function str2(val) {
922
- if (val === null || val === void 0) return "-";
923
- if (Array.isArray(val)) return val.join(", ");
924
- return String(val);
925
- }
926
- function extractArray2(raw) {
927
- if (Array.isArray(raw)) return raw;
928
- if (raw && typeof raw === "object") {
929
- const arr = Object.values(raw).find(Array.isArray);
930
- if (arr) return arr;
931
- }
932
- return [];
933
- }
934
954
  function registerDbIndexesCommand(dbCmd2) {
935
955
  dbCmd2.command("indexes").description("List all database indexes").action(async (_opts, cmd) => {
936
956
  const { json } = getRootOpts(cmd);
@@ -938,7 +958,7 @@ function registerDbIndexesCommand(dbCmd2) {
938
958
  await requireAuth();
939
959
  const res = await ossFetch("/api/database/indexes");
940
960
  const raw = await res.json();
941
- const indexes = extractArray2(raw);
961
+ const indexes = Array.isArray(raw) ? raw : raw.indexes ?? [];
942
962
  if (json) {
943
963
  outputJson(raw);
944
964
  } else {
@@ -949,34 +969,23 @@ function registerDbIndexesCommand(dbCmd2) {
949
969
  outputTable(
950
970
  ["Table", "Index Name", "Definition", "Unique", "Primary"],
951
971
  indexes.map((i) => [
952
- str2(i.tableName),
953
- str2(i.indexName),
954
- str2(i.indexDef),
972
+ i.tableName,
973
+ i.indexName,
974
+ i.indexDef,
955
975
  i.isUnique ? "Yes" : "No",
956
976
  i.isPrimary ? "Yes" : "No"
957
977
  ])
958
978
  );
959
979
  }
980
+ await reportCliUsage("cli.db.indexes", true);
960
981
  } catch (err) {
982
+ await reportCliUsage("cli.db.indexes", false);
961
983
  handleError(err, json);
962
984
  }
963
985
  });
964
986
  }
965
987
 
966
988
  // src/commands/db/policies.ts
967
- function str3(val) {
968
- if (val === null || val === void 0) return "-";
969
- if (Array.isArray(val)) return val.join(", ");
970
- return String(val);
971
- }
972
- function extractArray3(raw) {
973
- if (Array.isArray(raw)) return raw;
974
- if (raw && typeof raw === "object") {
975
- const arr = Object.values(raw).find(Array.isArray);
976
- if (arr) return arr;
977
- }
978
- return [];
979
- }
980
989
  function registerDbPoliciesCommand(dbCmd2) {
981
990
  dbCmd2.command("policies").description("List all RLS policies").action(async (_opts, cmd) => {
982
991
  const { json } = getRootOpts(cmd);
@@ -984,7 +993,7 @@ function registerDbPoliciesCommand(dbCmd2) {
984
993
  await requireAuth();
985
994
  const res = await ossFetch("/api/database/policies");
986
995
  const raw = await res.json();
987
- const policies = extractArray3(raw);
996
+ const policies = Array.isArray(raw) ? raw : raw.policies ?? [];
988
997
  if (json) {
989
998
  outputJson(raw);
990
999
  } else {
@@ -995,35 +1004,24 @@ function registerDbPoliciesCommand(dbCmd2) {
995
1004
  outputTable(
996
1005
  ["Table", "Policy Name", "Command", "Roles", "Qual", "With Check"],
997
1006
  policies.map((p) => [
998
- str3(p.tableName),
999
- str3(p.policyName),
1000
- str3(p.cmd),
1001
- str3(p.roles),
1002
- str3(p.qual),
1003
- str3(p.withCheck)
1007
+ String(p.tableName ?? "-"),
1008
+ String(p.policyName ?? "-"),
1009
+ String(p.cmd ?? "-"),
1010
+ Array.isArray(p.roles) ? p.roles.join(", ") : String(p.roles ?? "-"),
1011
+ String(p.qual ?? "-"),
1012
+ String(p.withCheck ?? "-")
1004
1013
  ])
1005
1014
  );
1006
1015
  }
1016
+ await reportCliUsage("cli.db.policies", true);
1007
1017
  } catch (err) {
1018
+ await reportCliUsage("cli.db.policies", false);
1008
1019
  handleError(err, json);
1009
1020
  }
1010
1021
  });
1011
1022
  }
1012
1023
 
1013
1024
  // src/commands/db/triggers.ts
1014
- function str4(val) {
1015
- if (val === null || val === void 0) return "-";
1016
- if (Array.isArray(val)) return val.join(", ");
1017
- return String(val);
1018
- }
1019
- function extractArray4(raw) {
1020
- if (Array.isArray(raw)) return raw;
1021
- if (raw && typeof raw === "object") {
1022
- const arr = Object.values(raw).find(Array.isArray);
1023
- if (arr) return arr;
1024
- }
1025
- return [];
1026
- }
1027
1025
  function registerDbTriggersCommand(dbCmd2) {
1028
1026
  dbCmd2.command("triggers").description("List all database triggers").action(async (_opts, cmd) => {
1029
1027
  const { json } = getRootOpts(cmd);
@@ -1031,7 +1029,7 @@ function registerDbTriggersCommand(dbCmd2) {
1031
1029
  await requireAuth();
1032
1030
  const res = await ossFetch("/api/database/triggers");
1033
1031
  const raw = await res.json();
1034
- const triggers = extractArray4(raw);
1032
+ const triggers = Array.isArray(raw) ? raw : raw.triggers ?? [];
1035
1033
  if (json) {
1036
1034
  outputJson(raw);
1037
1035
  } else {
@@ -1040,18 +1038,21 @@ function registerDbTriggersCommand(dbCmd2) {
1040
1038
  return;
1041
1039
  }
1042
1040
  outputTable(
1043
- ["Name", "Table", "Timing", "Events", "Function", "Enabled"],
1041
+ ["Name", "Table", "Timing", "Events", "ActionOrientation", "ActionCondition", "ActionStatement"],
1044
1042
  triggers.map((t) => [
1045
- str4(t.name),
1046
- str4(t.tableName),
1047
- str4(t.timing),
1048
- str4(t.events),
1049
- str4(t.functionName),
1050
- t.enabled ? "Yes" : "No"
1043
+ t.triggerName,
1044
+ t.tableName,
1045
+ t.actionTiming,
1046
+ t.eventManipulation,
1047
+ t.actionOrientation,
1048
+ t.actionCondition ?? "-",
1049
+ t.actionStatement
1051
1050
  ])
1052
1051
  );
1053
1052
  }
1053
+ await reportCliUsage("cli.db.triggers", true);
1054
1054
  } catch (err) {
1055
+ await reportCliUsage("cli.db.triggers", false);
1055
1056
  handleError(err, json);
1056
1057
  }
1057
1058
  });
@@ -1074,6 +1075,7 @@ function registerDbRpcCommand(dbCmd2) {
1074
1075
  } else {
1075
1076
  console.log(JSON.stringify(result, null, 2));
1076
1077
  }
1078
+ await reportCliUsage("cli.db.rpc", true);
1077
1079
  } catch (err) {
1078
1080
  handleError(err, json);
1079
1081
  }
@@ -1329,10 +1331,10 @@ function registerFunctionsCommands(functionsCmd2) {
1329
1331
  try {
1330
1332
  await requireAuth();
1331
1333
  const res = await ossFetch("/api/functions");
1332
- const data = await res.json();
1333
- const functions = data.functions ?? [];
1334
+ const raw = await res.json();
1335
+ const functions = Array.isArray(raw) ? raw : raw && typeof raw === "object" && "functions" in raw ? raw.functions ?? [] : [];
1334
1336
  if (json) {
1335
- outputJson(functions);
1337
+ outputJson(raw);
1336
1338
  } else {
1337
1339
  if (functions.length === 0) {
1338
1340
  console.log("No functions found.");
@@ -1344,11 +1346,13 @@ function registerFunctionsCommands(functionsCmd2) {
1344
1346
  f.slug,
1345
1347
  f.name ?? "-",
1346
1348
  f.status ?? "-",
1347
- f.created_at ? new Date(f.created_at).toLocaleString() : "-"
1349
+ f.createdAt ? new Date(f.createdAt).toLocaleString() : "-"
1348
1350
  ])
1349
1351
  );
1350
1352
  }
1353
+ await reportCliUsage("cli.functions.list", true);
1351
1354
  } catch (err) {
1355
+ await reportCliUsage("cli.functions.list", false);
1352
1356
  handleError(err, json);
1353
1357
  }
1354
1358
  });
@@ -1395,7 +1399,9 @@ Specify --file <path> or create ${join3("insforge", "functions", slug, "index.ts
1395
1399
  } else {
1396
1400
  outputSuccess(`Function "${slug}" ${exists ? "updated" : "created"} successfully.`);
1397
1401
  }
1402
+ await reportCliUsage("cli.functions.deploy", true);
1398
1403
  } catch (err) {
1404
+ await reportCliUsage("cli.functions.deploy", false);
1399
1405
  handleError(err, json);
1400
1406
  }
1401
1407
  });
@@ -1482,15 +1488,7 @@ function registerStorageBucketsCommand(storageCmd2) {
1482
1488
  await requireAuth();
1483
1489
  const res = await ossFetch("/api/storage/buckets");
1484
1490
  const raw = await res.json();
1485
- let buckets;
1486
- if (Array.isArray(raw)) {
1487
- buckets = raw;
1488
- } else if (raw && typeof raw === "object" && "buckets" in raw && Array.isArray(raw.buckets)) {
1489
- buckets = raw.buckets;
1490
- } else {
1491
- const arr = raw && typeof raw === "object" ? Object.values(raw).find(Array.isArray) : null;
1492
- buckets = arr ?? [];
1493
- }
1491
+ const buckets = Array.isArray(raw) ? raw : raw && typeof raw === "object" && "buckets" in raw ? raw.buckets ?? [] : [];
1494
1492
  if (json) {
1495
1493
  outputJson(raw);
1496
1494
  } else {
@@ -1499,11 +1497,13 @@ function registerStorageBucketsCommand(storageCmd2) {
1499
1497
  return;
1500
1498
  }
1501
1499
  outputTable(
1502
- ["Bucket Name"],
1503
- buckets.map((b) => [typeof b === "string" ? b : JSON.stringify(b)])
1500
+ ["Bucket Name", "Public"],
1501
+ buckets.map((b) => [b.name, b.public ? "Yes" : "No"])
1504
1502
  );
1505
1503
  }
1504
+ await reportCliUsage("cli.storage.buckets", true);
1506
1505
  } catch (err) {
1506
+ await reportCliUsage("cli.storage.buckets", false);
1507
1507
  handleError(err, json);
1508
1508
  }
1509
1509
  });
@@ -1604,7 +1604,9 @@ function registerStorageCreateBucketCommand(storageCmd2) {
1604
1604
  } else {
1605
1605
  outputSuccess(`Bucket "${name}" created (${isPublic ? "public" : "private"}).`);
1606
1606
  }
1607
+ await reportCliUsage("cli.storage.create-bucket", true);
1607
1608
  } catch (err) {
1609
+ await reportCliUsage("cli.storage.create-bucket", false);
1608
1610
  handleError(err, json);
1609
1611
  }
1610
1612
  });
@@ -1689,7 +1691,9 @@ function registerStorageListObjectsCommand(storageCmd2) {
1689
1691
  ])
1690
1692
  );
1691
1693
  }
1694
+ await reportCliUsage("cli.storage.list-objects", true);
1692
1695
  } catch (err) {
1696
+ await reportCliUsage("cli.storage.list-objects", false);
1693
1697
  handleError(err, json);
1694
1698
  }
1695
1699
  });
@@ -1852,7 +1856,9 @@ function registerDeploymentsDeployCommand(deploymentsCmd2) {
1852
1856
  clack8.log.info(`Check status with: insforge deployments status ${result.deploymentId}`);
1853
1857
  }
1854
1858
  }
1859
+ await reportCliUsage("cli.deployments.deploy", true);
1855
1860
  } catch (err) {
1861
+ await reportCliUsage("cli.deployments.deploy", false);
1856
1862
  handleError(err, json);
1857
1863
  }
1858
1864
  });
@@ -1964,6 +1970,7 @@ function registerCreateCommand(program2) {
1964
1970
  await downloadTemplate(template, projectConfig, projectName, json, apiUrl);
1965
1971
  }
1966
1972
  await installSkills(json);
1973
+ await reportCliUsage("cli.create", true, 6);
1967
1974
  if (hasTemplate) {
1968
1975
  const installSpinner = !json ? clack9.spinner() : null;
1969
1976
  installSpinner?.start("Installing dependencies...");
@@ -2179,14 +2186,7 @@ function registerDeploymentsListCommand(deploymentsCmd2) {
2179
2186
  if (!getProjectConfig()) throw new ProjectNotLinkedError();
2180
2187
  const res = await ossFetch(`/api/deployments?limit=${opts.limit}&offset=${opts.offset}`);
2181
2188
  const raw = await res.json();
2182
- let deployments;
2183
- if (Array.isArray(raw)) {
2184
- deployments = raw;
2185
- } else if (raw && typeof raw === "object" && "data" in raw && Array.isArray(raw.data)) {
2186
- deployments = raw.data;
2187
- } else {
2188
- deployments = [];
2189
- }
2189
+ const deployments = Array.isArray(raw) ? raw : raw && typeof raw === "object" && "data" in raw ? raw.data ?? [] : [];
2190
2190
  if (json) {
2191
2191
  outputJson(raw);
2192
2192
  } else {
@@ -2197,15 +2197,17 @@ function registerDeploymentsListCommand(deploymentsCmd2) {
2197
2197
  outputTable(
2198
2198
  ["ID", "Status", "Provider", "URL", "Created"],
2199
2199
  deployments.map((d) => [
2200
- String(d.id ?? "-"),
2201
- String(d.status ?? "-"),
2202
- String(d.provider ?? "-"),
2203
- String(d.deploymentUrl ?? d.url ?? "-"),
2204
- d.createdAt ?? d.created_at ? new Date(String(d.createdAt ?? d.created_at)).toLocaleString() : "-"
2200
+ d.id,
2201
+ d.status,
2202
+ d.provider,
2203
+ d.url ?? "-",
2204
+ new Date(d.createdAt).toLocaleString()
2205
2205
  ])
2206
2206
  );
2207
2207
  }
2208
+ await reportCliUsage("cli.deployments.list", true);
2208
2209
  } catch (err) {
2210
+ await reportCliUsage("cli.deployments.list", false);
2209
2211
  handleError(err, json);
2210
2212
  }
2211
2213
  });
@@ -2290,6 +2292,7 @@ Examples:
2290
2292
  const { json } = getRootOpts(cmd);
2291
2293
  try {
2292
2294
  await requireAuth();
2295
+ await reportCliUsage("cli.docs", true);
2293
2296
  if (!feature) {
2294
2297
  await listDocs(json);
2295
2298
  return;
@@ -2374,7 +2377,9 @@ function registerSecretsListCommand(secretsCmd2) {
2374
2377
  })
2375
2378
  );
2376
2379
  }
2380
+ await reportCliUsage("cli.secrets.list", true);
2377
2381
  } catch (err) {
2382
+ await reportCliUsage("cli.secrets.list", false);
2378
2383
  handleError(err, json);
2379
2384
  }
2380
2385
  });
@@ -2388,10 +2393,11 @@ function registerSecretsGetCommand(secretsCmd2) {
2388
2393
  await requireAuth();
2389
2394
  const res = await ossFetch(`/api/secrets/${encodeURIComponent(key)}`);
2390
2395
  const data = await res.json();
2396
+ const secret = data;
2391
2397
  if (json) {
2392
2398
  outputJson(data);
2393
2399
  } else {
2394
- console.log(`${data.key} = ${data.value}`);
2400
+ console.log(`${secret.key} = ${secret.value}`);
2395
2401
  }
2396
2402
  } catch (err) {
2397
2403
  handleError(err, json);
@@ -2418,7 +2424,9 @@ function registerSecretsAddCommand(secretsCmd2) {
2418
2424
  } else {
2419
2425
  outputSuccess(data.message ?? `Secret ${key} created.`);
2420
2426
  }
2427
+ await reportCliUsage("cli.secrets.add", true);
2421
2428
  } catch (err) {
2429
+ await reportCliUsage("cli.secrets.add", false);
2422
2430
  handleError(err, json);
2423
2431
  }
2424
2432
  });
@@ -2492,7 +2500,7 @@ function registerSchedulesListCommand(schedulesCmd2) {
2492
2500
  await requireAuth();
2493
2501
  const res = await ossFetch("/api/schedules");
2494
2502
  const data = await res.json();
2495
- const schedules = Array.isArray(data) ? data : data.schedules ?? [];
2503
+ const schedules = data;
2496
2504
  if (json) {
2497
2505
  outputJson(schedules);
2498
2506
  } else {
@@ -2513,7 +2521,9 @@ function registerSchedulesListCommand(schedulesCmd2) {
2513
2521
  ])
2514
2522
  );
2515
2523
  }
2524
+ await reportCliUsage("cli.schedules.list", true);
2516
2525
  } catch (err) {
2526
+ await reportCliUsage("cli.schedules.list", false);
2517
2527
  handleError(err, json);
2518
2528
  }
2519
2529
  });
@@ -2585,7 +2595,9 @@ function registerSchedulesCreateCommand(schedulesCmd2) {
2585
2595
  } else {
2586
2596
  outputSuccess(`Schedule "${opts.name}" created (ID: ${data.id ?? "unknown"}).`);
2587
2597
  }
2598
+ await reportCliUsage("cli.schedules.create", true);
2588
2599
  } catch (err) {
2600
+ await reportCliUsage("cli.schedules.create", false);
2589
2601
  handleError(err, json);
2590
2602
  }
2591
2603
  });
@@ -2817,7 +2829,9 @@ function registerMetadataCommand(program2) {
2817
2829
  Version: ${data.version}`);
2818
2830
  }
2819
2831
  console.log("");
2832
+ await reportCliUsage("cli.metadata", true);
2820
2833
  } catch (err) {
2834
+ await reportCliUsage("cli.metadata", false);
2821
2835
  handleError(err, json);
2822
2836
  }
2823
2837
  });