@suronai/sdk 0.1.40 → 0.1.42
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/package.json +1 -1
- package/src/vault.js +24 -1
package/package.json
CHANGED
package/src/vault.js
CHANGED
|
@@ -3,7 +3,25 @@ import { join } from "path";
|
|
|
3
3
|
import { SuronConfigError, SuronAppNotFoundError, SuronRateLimitError, SuronDeniedError, SuronTimeoutError } from "./errors.js";
|
|
4
4
|
import { parseEnv } from "./decrypt.js";
|
|
5
5
|
|
|
6
|
-
const BASE_URL = "https://suron.vercel.app";
|
|
6
|
+
const BASE_URL = process.env.SURON_API_URL ?? "https://suron.vercel.app/api";
|
|
7
|
+
|
|
8
|
+
function isLocalMode(options) {
|
|
9
|
+
return (
|
|
10
|
+
options.local === true ||
|
|
11
|
+
process.env.SURON_LOCAL === "true" ||
|
|
12
|
+
process.argv.includes("--local")
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function shouldAutoLocal(configPath) {
|
|
17
|
+
return !existsSync(join(configPath, ".suron.json"));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function loadLocalEnv(configPath) {
|
|
21
|
+
const envPath = join(configPath, ".env");
|
|
22
|
+
if (!existsSync(envPath)) throw new SuronConfigError(`.env not found in ${configPath}`);
|
|
23
|
+
parseEnv(readFileSync(envPath, "utf-8"));
|
|
24
|
+
}
|
|
7
25
|
|
|
8
26
|
function readSuronJson(dir) {
|
|
9
27
|
const path = join(dir, ".suron.json");
|
|
@@ -76,6 +94,11 @@ export async function vault(options = {}) {
|
|
|
76
94
|
pollInterval = 3_000,
|
|
77
95
|
} = options;
|
|
78
96
|
|
|
97
|
+
if (isLocalMode(options) || shouldAutoLocal(configPath)) {
|
|
98
|
+
loadLocalEnv(configPath);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
79
102
|
const { app_id, version } = readSuronJson(configPath);
|
|
80
103
|
const request_id = await requestAccess(app_id);
|
|
81
104
|
await pollUntilApproved(request_id, timeout, pollInterval);
|