@corsair-dev/cli 0.1.23 → 0.1.24

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
@@ -1915,14 +1915,14 @@ function writeAuthState(sessionId, state) {
1915
1915
  fs3.writeFileSync(authStateFile(sessionId), JSON.stringify(state));
1916
1916
  }
1917
1917
  function pollAuthState(sessionId, timeoutMs) {
1918
- return new Promise((resolve, reject) => {
1918
+ return new Promise((resolve2, reject) => {
1919
1919
  const file = authStateFile(sessionId);
1920
1920
  const start = Date.now();
1921
1921
  const interval = setInterval(() => {
1922
1922
  try {
1923
1923
  const state = JSON.parse(fs3.readFileSync(file, "utf8"));
1924
1924
  clearInterval(interval);
1925
- resolve(state);
1925
+ resolve2(state);
1926
1926
  } catch {
1927
1927
  if (Date.now() - start > timeoutMs) {
1928
1928
  clearInterval(interval);
@@ -1947,21 +1947,21 @@ function getCustomAccountFields(plugin, authType) {
1947
1947
  return authConfig?.[authType]?.account ?? [];
1948
1948
  }
1949
1949
  function findFreePort() {
1950
- return new Promise((resolve, reject) => {
1950
+ return new Promise((resolve2, reject) => {
1951
1951
  const server = net.createServer();
1952
1952
  server.listen(0, "127.0.0.1", () => {
1953
1953
  const address = server.address();
1954
1954
  const port = typeof address === "object" && address ? address.port : 0;
1955
1955
  server.close((err) => {
1956
1956
  if (err) reject(err);
1957
- else resolve(port);
1957
+ else resolve2(port);
1958
1958
  });
1959
1959
  });
1960
1960
  server.on("error", reject);
1961
1961
  });
1962
1962
  }
1963
1963
  function waitForOAuthCode(port) {
1964
- return new Promise((resolve, reject) => {
1964
+ return new Promise((resolve2, reject) => {
1965
1965
  const server = http.createServer((req, res) => {
1966
1966
  const url = new URL(req.url ?? "/", `http://localhost:${port}`);
1967
1967
  const code = url.searchParams.get("code");
@@ -1981,7 +1981,7 @@ function waitForOAuthCode(port) {
1981
1981
  "<html><body><h2>Authorization successful!</h2><p>You can close this tab and return to the terminal.</p></body></html>"
1982
1982
  );
1983
1983
  server.close();
1984
- resolve(code);
1984
+ resolve2(code);
1985
1985
  } else {
1986
1986
  res.writeHead(400, { "Content-Type": "text/html" });
1987
1987
  res.end(
@@ -2486,7 +2486,7 @@ import { fileURLToPath } from "url";
2486
2486
  import { Command } from "commander";
2487
2487
 
2488
2488
  // package.json
2489
- var version = "0.1.23";
2489
+ var version = "0.1.24";
2490
2490
 
2491
2491
  // src/utils/subscription.ts
2492
2492
  async function runWebhookSubscription(cwd, pluginId) {
@@ -2639,6 +2639,219 @@ var AuthCommand = class extends BaseCommand {
2639
2639
  }
2640
2640
  };
2641
2641
 
2642
+ // src/lib/cloud/client.ts
2643
+ var LOOPBACK_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]", "::1"]);
2644
+ function assertSecureCloudUrl(url) {
2645
+ let parsed;
2646
+ try {
2647
+ parsed = new URL(url);
2648
+ } catch {
2649
+ throw new Error(`Corsair Cloud URL is not a valid URL: "${url}"`);
2650
+ }
2651
+ if (parsed.search || parsed.hash) {
2652
+ throw new Error(
2653
+ `Corsair Cloud URL must not contain a query or fragment (got "${url}").`
2654
+ );
2655
+ }
2656
+ if (parsed.protocol === "https:") return;
2657
+ if (parsed.protocol === "http:" && LOOPBACK_HOSTS.has(parsed.hostname)) {
2658
+ return;
2659
+ }
2660
+ throw new Error(
2661
+ `Corsair Cloud URL must use https:// (got "${url}") \u2014 http:// is only allowed for localhost/127.0.0.1.`
2662
+ );
2663
+ }
2664
+ function cloudUrlFromKey(key) {
2665
+ if (!key.startsWith("ck_cloud_")) return null;
2666
+ const rest = key.slice("ck_cloud_".length);
2667
+ const sep = rest.indexOf(".");
2668
+ if (sep <= 0) return null;
2669
+ const slug = rest.slice(0, sep);
2670
+ if (!/^[a-z0-9]+$/.test(slug)) return null;
2671
+ return `https://api.corsair.cloud/${slug}/api/corsair`;
2672
+ }
2673
+ function resolveCloudConfig(options) {
2674
+ const key = (options.key || process.env.CORSAIR_CLOUD_KEY || "").trim();
2675
+ if (!key) {
2676
+ throw new Error(
2677
+ "Corsair Cloud key required \u2014 pass --key or set CORSAIR_CLOUD_KEY."
2678
+ );
2679
+ }
2680
+ const url = (options.url || process.env.CORSAIR_CLOUD_URL || cloudUrlFromKey(key) || "").trim().replace(/\/+$/, "");
2681
+ if (!url) {
2682
+ throw new Error(
2683
+ "Corsair Cloud URL required \u2014 pass a ck_cloud_<slug>.<secret> key, or --url / CORSAIR_CLOUD_URL."
2684
+ );
2685
+ }
2686
+ assertSecureCloudUrl(url);
2687
+ return { url, key };
2688
+ }
2689
+ async function fetchCloudOpTree(config) {
2690
+ const res = await fetch(`${config.url}/call`, {
2691
+ headers: { authorization: `Bearer ${config.key}` }
2692
+ });
2693
+ if (!res.ok) {
2694
+ throw new Error(
2695
+ `Corsair Cloud discovery failed: ${res.status} ${res.statusText}`
2696
+ );
2697
+ }
2698
+ const body = await res.json();
2699
+ return body.plugins ?? {};
2700
+ }
2701
+
2702
+ // src/lib/cloud/op-tree.ts
2703
+ function makeNode() {
2704
+ return { call: false, children: /* @__PURE__ */ Object.create(null) };
2705
+ }
2706
+ function insertOp(root, op) {
2707
+ const parts = op.split(".");
2708
+ let children = root;
2709
+ parts.forEach((part, i) => {
2710
+ const node = children[part] ??= makeNode();
2711
+ if (i === parts.length - 1) {
2712
+ node.call = true;
2713
+ } else {
2714
+ children = node.children;
2715
+ }
2716
+ });
2717
+ }
2718
+ function buildOpTree(ops) {
2719
+ const root = /* @__PURE__ */ Object.create(null);
2720
+ for (const op of ops) insertOp(root, op);
2721
+ return root;
2722
+ }
2723
+ function renderFields(tree, indent) {
2724
+ return Object.entries(tree).map(([key, node]) => {
2725
+ const name = JSON.stringify(key);
2726
+ const hasChildren = Object.keys(node.children).length > 0;
2727
+ if (node.call && !hasChildren) {
2728
+ return `${indent}${name}(args?: any): Promise<any>;`;
2729
+ }
2730
+ const body = `{
2731
+ ${renderFields(node.children, `${indent} `)}
2732
+ ${indent}}`;
2733
+ if (!node.call) return `${indent}${name}: ${body};`;
2734
+ return `${indent}${name}: ((args?: any) => Promise<any>) & ${body};`;
2735
+ }).join("\n");
2736
+ }
2737
+ function formatOpTree(pluginsOps) {
2738
+ return Object.entries(pluginsOps).map(
2739
+ ([plugin, ops]) => `${plugin}
2740
+ ${ops.map((op) => ` ${op}`).join("\n")}`
2741
+ ).join("\n");
2742
+ }
2743
+ function buildCloudDeclaration(pluginsOps, moduleSpecifier) {
2744
+ const pluginFields = Object.entries(pluginsOps).map(([plugin, ops]) => {
2745
+ const tree = buildOpTree(ops);
2746
+ return ` ${JSON.stringify(plugin)}: {
2747
+ ${renderFields(tree, " ")}
2748
+ };`;
2749
+ }).join("\n");
2750
+ return [
2751
+ `import "${moduleSpecifier}";`,
2752
+ `declare module "${moduleSpecifier}" {`,
2753
+ " interface CorsairCloudRegistry {",
2754
+ ...pluginFields ? [pluginFields] : [],
2755
+ " }",
2756
+ "}",
2757
+ ""
2758
+ ].join("\n");
2759
+ }
2760
+
2761
+ // src/commands/cloud/list.command.ts
2762
+ var CloudListCommand = class extends BaseCommand {
2763
+ getName() {
2764
+ return "list";
2765
+ }
2766
+ getDescription() {
2767
+ return "List every op a Corsair Cloud project exposes";
2768
+ }
2769
+ getOptions() {
2770
+ return [
2771
+ {
2772
+ short: "-u",
2773
+ long: "--url <url>",
2774
+ description: "Corsair Cloud base URL"
2775
+ },
2776
+ {
2777
+ short: "-k",
2778
+ long: "--key <key>",
2779
+ description: "Corsair Cloud project key"
2780
+ }
2781
+ ];
2782
+ }
2783
+ async action({ options }) {
2784
+ const config = resolveCloudConfig(options);
2785
+ const tree = await fetchCloudOpTree(config);
2786
+ console.log(formatOpTree(tree));
2787
+ }
2788
+ };
2789
+
2790
+ // src/commands/cloud/pull.command.ts
2791
+ import { writeFileSync as writeFileSync2 } from "fs";
2792
+ import { resolve } from "path";
2793
+ var REGISTRY_MODULE_SPECIFIER = "corsair";
2794
+ var CloudPullCommand = class extends BaseCommand {
2795
+ getName() {
2796
+ return "pull";
2797
+ }
2798
+ getDescription() {
2799
+ return "Generate corsair-env.d.ts typing CorsairCloudRegistry from a Corsair Cloud project";
2800
+ }
2801
+ getOptions() {
2802
+ return [
2803
+ {
2804
+ short: "-u",
2805
+ long: "--url <url>",
2806
+ description: "Corsair Cloud base URL"
2807
+ },
2808
+ {
2809
+ short: "-k",
2810
+ long: "--key <key>",
2811
+ description: "Corsair Cloud project key"
2812
+ },
2813
+ {
2814
+ short: "-o",
2815
+ long: "--out <path>",
2816
+ description: "Output path",
2817
+ defaultValue: "corsair-env.d.ts"
2818
+ }
2819
+ ];
2820
+ }
2821
+ async action({ options }) {
2822
+ const config = resolveCloudConfig(options);
2823
+ const tree = await fetchCloudOpTree(config);
2824
+ const declaration = buildCloudDeclaration(tree, REGISTRY_MODULE_SPECIFIER);
2825
+ const outPath = resolve(process.cwd(), options.out ?? "corsair-env.d.ts");
2826
+ writeFileSync2(outPath, declaration);
2827
+ const pluginCount = Object.keys(tree).length;
2828
+ const opCount = Object.values(tree).reduce(
2829
+ (sum, ops) => sum + ops.length,
2830
+ 0
2831
+ );
2832
+ console.log(
2833
+ `[#corsair]: Wrote ${outPath} (${pluginCount} plugins, ${opCount} ops).`
2834
+ );
2835
+ }
2836
+ };
2837
+
2838
+ // src/commands/cloud.command.ts
2839
+ var CloudCommand = class extends BaseCommand {
2840
+ getName() {
2841
+ return "cloud";
2842
+ }
2843
+ getDescription() {
2844
+ return "Corsair Cloud: discover and type a hosted project (list, pull)";
2845
+ }
2846
+ getSubCommands() {
2847
+ return [new CloudListCommand(), new CloudPullCommand()];
2848
+ }
2849
+ async action({}) {
2850
+ console.error("[#corsair]: Usage: corsair cloud <list|pull>");
2851
+ process.exit(1);
2852
+ }
2853
+ };
2854
+
2642
2855
  // src/commands/http.command.ts
2643
2856
  import { CORSAIR_TUNNEL_PATH } from "corsair/hub";
2644
2857
  import { runTunnel } from "corsair/hub/tunnel/run-tunnel";
@@ -2733,10 +2946,10 @@ var HttpCommand = class extends BaseCommand {
2733
2946
  process.exit(1);
2734
2947
  }
2735
2948
  }
2736
- await new Promise((resolve) => {
2949
+ await new Promise((resolve2) => {
2737
2950
  const shutdown = () => {
2738
2951
  stop();
2739
- resolve();
2952
+ resolve2();
2740
2953
  };
2741
2954
  process.once("SIGINT", shutdown);
2742
2955
  process.once("SIGTERM", shutdown);
@@ -3148,8 +3361,8 @@ var StudioCommand = class extends BaseCommand {
3148
3361
  throw error;
3149
3362
  }
3150
3363
  await startStudio({ cwd, port, open: options.open });
3151
- await new Promise((resolve) => {
3152
- const shutdown = () => resolve();
3364
+ await new Promise((resolve2) => {
3365
+ const shutdown = () => resolve2();
3153
3366
  process.once("SIGINT", shutdown);
3154
3367
  process.once("SIGTERM", shutdown);
3155
3368
  });
@@ -3309,7 +3522,8 @@ function createProgram() {
3309
3522
  new SchemaCommand(),
3310
3523
  new ScriptCommand(),
3311
3524
  new StudioCommand(),
3312
- new HttpCommand()
3525
+ new HttpCommand(),
3526
+ new CloudCommand()
3313
3527
  ];
3314
3528
  COMMANDS.forEach((command) => {
3315
3529
  command.prepare(program);
@@ -0,0 +1,9 @@
1
+ import type { CommandActionData, CommandOption } from '../../index.types';
2
+ import BaseCommand from '../base.command';
3
+ export default class CloudListCommand extends BaseCommand {
4
+ getName(): string;
5
+ getDescription(): string;
6
+ getOptions(): CommandOption[];
7
+ action({ options }: CommandActionData): Promise<void>;
8
+ }
9
+ //# sourceMappingURL=list.command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list.command.d.ts","sourceRoot":"","sources":["../../../../src/commands/cloud/list.command.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAG1E,OAAO,WAAW,MAAM,iBAAiB,CAAC;AAE1C,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,WAAW;IACxD,OAAO,IAAI,MAAM;IAIjB,cAAc,IAAI,MAAM;IAIxB,UAAU,IAAI,aAAa,EAAE;IAevB,MAAM,CAAC,EAAE,OAAO,EAAE,EAAE,iBAAiB;CAK3C"}
@@ -0,0 +1,9 @@
1
+ import type { CommandActionData, CommandOption } from '../../index.types';
2
+ import BaseCommand from '../base.command';
3
+ export default class CloudPullCommand extends BaseCommand {
4
+ getName(): string;
5
+ getDescription(): string;
6
+ getOptions(): CommandOption[];
7
+ action({ options }: CommandActionData): Promise<void>;
8
+ }
9
+ //# sourceMappingURL=pull.command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pull.command.d.ts","sourceRoot":"","sources":["../../../../src/commands/cloud/pull.command.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAG1E,OAAO,WAAW,MAAM,iBAAiB,CAAC;AAI1C,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,WAAW;IACxD,OAAO,IAAI,MAAM;IAIjB,cAAc,IAAI,MAAM;IAIxB,UAAU,IAAI,aAAa,EAAE;IAqBvB,MAAM,CAAC,EAAE,OAAO,EAAE,EAAE,iBAAiB;CAiB3C"}
@@ -0,0 +1,9 @@
1
+ import type { CommandActionData } from '../index.types';
2
+ import BaseCommand from './base.command';
3
+ export default class CloudCommand extends BaseCommand {
4
+ getName(): string;
5
+ getDescription(): string;
6
+ getSubCommands(): BaseCommand[];
7
+ action({}: CommandActionData): Promise<void>;
8
+ }
9
+ //# sourceMappingURL=cloud.command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloud.command.d.ts","sourceRoot":"","sources":["../../../src/commands/cloud.command.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,WAAW,MAAM,gBAAgB,CAAC;AAIzC,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,WAAW;IACpD,OAAO,IAAI,MAAM;IAIjB,cAAc,IAAI,MAAM;IAIxB,cAAc,IAAI,WAAW,EAAE;IAIzB,MAAM,CAAC,EAAE,EAAE,iBAAiB;CAIlC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAepC,OAAO,EACN,qBAAqB,EACrB,kBAAkB,EAClB,MAAM,0BAA0B,CAAC;AAGlC,iBAAS,aAAa,IAAI,OAAO,CA0BhC;AA8BD,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAgBpC,OAAO,EACN,qBAAqB,EACrB,kBAAkB,EAClB,MAAM,0BAA0B,CAAC;AAGlC,iBAAS,aAAa,IAAI,OAAO,CA2BhC;AA8BD,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,CAAC"}
@@ -0,0 +1,13 @@
1
+ export interface CloudConfig {
2
+ url: string;
3
+ key: string;
4
+ }
5
+ export interface CloudOpTree {
6
+ [plugin: string]: string[];
7
+ }
8
+ export declare function resolveCloudConfig(options: {
9
+ url?: string;
10
+ key?: string;
11
+ }): CloudConfig;
12
+ export declare function fetchCloudOpTree(config: CloudConfig): Promise<CloudOpTree>;
13
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../src/lib/cloud/client.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,WAAW;IAC3B,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAC3B;AA0CD,wBAAgB,kBAAkB,CAAC,OAAO,EAAE;IAC3C,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;CACb,GAAG,WAAW,CAsBd;AAED,wBAAsB,gBAAgB,CACrC,MAAM,EAAE,WAAW,GACjB,OAAO,CAAC,WAAW,CAAC,CAWtB"}
@@ -0,0 +1,5 @@
1
+ /** Op-tree → a human-readable listing: plugin, then its ops indented. */
2
+ export declare function formatOpTree(pluginsOps: Record<string, string[]>): string;
3
+ /** Op-tree → `.d.ts` text merging CorsairCloudRegistry via declaration merging. */
4
+ export declare function buildCloudDeclaration(pluginsOps: Record<string, string[]>, moduleSpecifier: string): string;
5
+ //# sourceMappingURL=op-tree.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"op-tree.d.ts","sourceRoot":"","sources":["../../../../src/lib/cloud/op-tree.ts"],"names":[],"mappings":"AA8CA,yEAAyE;AACzE,wBAAgB,YAAY,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,MAAM,CAMzE;AAED,mFAAmF;AACnF,wBAAgB,qBAAqB,CACpC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,EACpC,eAAe,EAAE,MAAM,GACrB,MAAM,CAgBR"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@corsair-dev/cli",
3
- "version": "0.1.23",
3
+ "version": "0.1.24",
4
4
  "description": "Command-line tool for Corsair, the open-source integration layer. Scaffold a project, add integrations, and run your app.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -24,7 +24,7 @@
24
24
  "c12": "^3.3.3",
25
25
  "commander": "^14.0.3",
26
26
  "zod": "^4.1.13",
27
- "corsair": "0.1.133"
27
+ "corsair": "0.1.137"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/jest": "^29.5.14",