@solongate/proxy 0.4.0 → 0.4.2

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
@@ -8,7 +8,23 @@ var __esm = (fn, res) => function __init() {
8
8
  import { readFileSync, existsSync } from "fs";
9
9
  import { resolve } from "path";
10
10
  async function fetchCloudPolicy(apiKey, apiUrl, policyId) {
11
- const url = `${apiUrl}/api/v1/policies/${policyId ?? "default"}`;
11
+ let resolvedId = policyId;
12
+ if (!resolvedId) {
13
+ const listRes = await fetch(`${apiUrl}/api/v1/policies`, {
14
+ headers: { "Authorization": `Bearer ${apiKey}` }
15
+ });
16
+ if (!listRes.ok) {
17
+ const body = await listRes.text().catch(() => "");
18
+ throw new Error(`Failed to list policies from cloud (${listRes.status}): ${body}`);
19
+ }
20
+ const listData = await listRes.json();
21
+ const policies = listData.policies ?? [];
22
+ if (policies.length === 0) {
23
+ throw new Error("No policies found in cloud. Create one in the dashboard first.");
24
+ }
25
+ resolvedId = policies[0].id;
26
+ }
27
+ const url = `${apiUrl}/api/v1/policies/${resolvedId}`;
12
28
  const res = await fetch(url, {
13
29
  headers: { "Authorization": `Bearer ${apiKey}` }
14
30
  });
@@ -1833,7 +1849,29 @@ var init_create = __esm({
1833
1849
  var pull_push_exports = {};
1834
1850
  import { readFileSync as readFileSync5, writeFileSync as writeFileSync5, existsSync as existsSync6 } from "fs";
1835
1851
  import { resolve as resolve5 } from "path";
1852
+ function loadEnv() {
1853
+ if (process.env.SOLONGATE_API_KEY) return;
1854
+ const envPath = resolve5(".env");
1855
+ if (!existsSync6(envPath)) return;
1856
+ try {
1857
+ const content = readFileSync5(envPath, "utf-8");
1858
+ for (const line of content.split("\n")) {
1859
+ const trimmed = line.trim();
1860
+ if (!trimmed || trimmed.startsWith("#")) continue;
1861
+ const eq = trimmed.indexOf("=");
1862
+ if (eq === -1) continue;
1863
+ const key = trimmed.slice(0, eq).trim();
1864
+ const val = trimmed.slice(eq + 1).trim().replace(/^["']|["']$/g, "");
1865
+ if (key === "SOLONGATE_API_KEY") {
1866
+ process.env.SOLONGATE_API_KEY = val;
1867
+ return;
1868
+ }
1869
+ }
1870
+ } catch {
1871
+ }
1872
+ }
1836
1873
  function parseCliArgs() {
1874
+ loadEnv();
1837
1875
  const args = process.argv.slice(2);
1838
1876
  const command = args[0];
1839
1877
  let apiKey = process.env.SOLONGATE_API_KEY || "";
@@ -1858,10 +1896,12 @@ function parseCliArgs() {
1858
1896
  }
1859
1897
  }
1860
1898
  if (!apiKey) {
1861
- log5("ERROR: API key required.");
1899
+ log5("ERROR: API key not found.");
1900
+ log5("");
1901
+ log5("Set it in .env file:");
1902
+ log5(" SOLONGATE_API_KEY=sg_live_...");
1862
1903
  log5("");
1863
- log5("Usage:");
1864
- log5(` solongate-proxy ${command} --api-key sg_live_... --file policy.json`);
1904
+ log5("Or pass via environment:");
1865
1905
  log5(` SOLONGATE_API_KEY=sg_live_... solongate-proxy ${command}`);
1866
1906
  process.exit(1);
1867
1907
  }
@@ -1935,7 +1975,7 @@ async function main4() {
1935
1975
  await push(apiKey, file);
1936
1976
  } else {
1937
1977
  log5(`Unknown command: ${command}`);
1938
- log5("Usage: solongate-proxy pull|push --api-key sg_live_... --file policy.json");
1978
+ log5("Usage: solongate-proxy pull|push [--file policy.json]");
1939
1979
  process.exit(1);
1940
1980
  }
1941
1981
  } catch (err) {
package/dist/pull-push.js CHANGED
@@ -8,7 +8,23 @@ import { resolve as resolve2 } from "path";
8
8
  import { readFileSync, existsSync } from "fs";
9
9
  import { resolve } from "path";
10
10
  async function fetchCloudPolicy(apiKey, apiUrl, policyId) {
11
- const url = `${apiUrl}/api/v1/policies/${policyId ?? "default"}`;
11
+ let resolvedId = policyId;
12
+ if (!resolvedId) {
13
+ const listRes = await fetch(`${apiUrl}/api/v1/policies`, {
14
+ headers: { "Authorization": `Bearer ${apiKey}` }
15
+ });
16
+ if (!listRes.ok) {
17
+ const body = await listRes.text().catch(() => "");
18
+ throw new Error(`Failed to list policies from cloud (${listRes.status}): ${body}`);
19
+ }
20
+ const listData = await listRes.json();
21
+ const policies = listData.policies ?? [];
22
+ if (policies.length === 0) {
23
+ throw new Error("No policies found in cloud. Create one in the dashboard first.");
24
+ }
25
+ resolvedId = policies[0].id;
26
+ }
27
+ const url = `${apiUrl}/api/v1/policies/${resolvedId}`;
12
28
  const res = await fetch(url, {
13
29
  headers: { "Authorization": `Bearer ${apiKey}` }
14
30
  });
@@ -30,7 +46,29 @@ async function fetchCloudPolicy(apiKey, apiUrl, policyId) {
30
46
  // src/pull-push.ts
31
47
  var log = (...args) => process.stderr.write(`[SolonGate] ${args.map(String).join(" ")}
32
48
  `);
49
+ function loadEnv() {
50
+ if (process.env.SOLONGATE_API_KEY) return;
51
+ const envPath = resolve2(".env");
52
+ if (!existsSync2(envPath)) return;
53
+ try {
54
+ const content = readFileSync2(envPath, "utf-8");
55
+ for (const line of content.split("\n")) {
56
+ const trimmed = line.trim();
57
+ if (!trimmed || trimmed.startsWith("#")) continue;
58
+ const eq = trimmed.indexOf("=");
59
+ if (eq === -1) continue;
60
+ const key = trimmed.slice(0, eq).trim();
61
+ const val = trimmed.slice(eq + 1).trim().replace(/^["']|["']$/g, "");
62
+ if (key === "SOLONGATE_API_KEY") {
63
+ process.env.SOLONGATE_API_KEY = val;
64
+ return;
65
+ }
66
+ }
67
+ } catch {
68
+ }
69
+ }
33
70
  function parseCliArgs() {
71
+ loadEnv();
34
72
  const args = process.argv.slice(2);
35
73
  const command = args[0];
36
74
  let apiKey = process.env.SOLONGATE_API_KEY || "";
@@ -55,10 +93,12 @@ function parseCliArgs() {
55
93
  }
56
94
  }
57
95
  if (!apiKey) {
58
- log("ERROR: API key required.");
96
+ log("ERROR: API key not found.");
97
+ log("");
98
+ log("Set it in .env file:");
99
+ log(" SOLONGATE_API_KEY=sg_live_...");
59
100
  log("");
60
- log("Usage:");
61
- log(` solongate-proxy ${command} --api-key sg_live_... --file policy.json`);
101
+ log("Or pass via environment:");
62
102
  log(` SOLONGATE_API_KEY=sg_live_... solongate-proxy ${command}`);
63
103
  process.exit(1);
64
104
  }
@@ -132,7 +172,7 @@ async function main() {
132
172
  await push(apiKey, file);
133
173
  } else {
134
174
  log(`Unknown command: ${command}`);
135
- log("Usage: solongate-proxy pull|push --api-key sg_live_... --file policy.json");
175
+ log("Usage: solongate-proxy pull|push [--file policy.json]");
136
176
  process.exit(1);
137
177
  }
138
178
  } catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solongate/proxy",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "MCP security proxy — protect any MCP server with customizable policies, path/command constraints, rate limiting, and audit logging. Zero code changes required.",
5
5
  "type": "module",
6
6
  "bin": {