@bstage-sdk/cli 0.1.0 → 0.2.0
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/{chunk-S6HGR2U3.js → chunk-FER3TEK7.js} +49 -17
- package/dist/index.js +1985 -196
- package/dist/vite/preset.js +1 -1
- package/package.json +6 -6
|
@@ -65,6 +65,11 @@ var DEFAULT_TRANSLATION_TIER = "inhouse";
|
|
|
65
65
|
var TRANSLATION_CDN_ORIGIN = "https://cdn.static.bstage.in";
|
|
66
66
|
var TRANSLATION_CDN_BASE_KEY = "static/i18n";
|
|
67
67
|
var TRANSLATION_CDN_BUCKET_PREFIX = "cdn.bstage.in/";
|
|
68
|
+
var PORTAL_HOSTS = {
|
|
69
|
+
real: "portal.bstage.in",
|
|
70
|
+
sandbox: "bstage-portal.sandbox.bstage.systems"
|
|
71
|
+
};
|
|
72
|
+
var PORTAL_HOST_ENV_KEY = "VITE_BSTAGE_PORTAL_HOST";
|
|
68
73
|
function getAuthHost(mode, phase, tenantId) {
|
|
69
74
|
if (mode === "admin") {
|
|
70
75
|
const fn2 = ADMIN_AUTH_HOSTS[phase];
|
|
@@ -513,11 +518,26 @@ function stripResponseCookies(headers, extraCookies) {
|
|
|
513
518
|
headers["set-cookie"] = cookies;
|
|
514
519
|
}
|
|
515
520
|
}
|
|
516
|
-
|
|
517
|
-
|
|
521
|
+
var MAX_REQUEST_BODY_BYTES = 10 * 1024 * 1024;
|
|
522
|
+
function collectBody(req, maxBytes = MAX_REQUEST_BODY_BYTES) {
|
|
523
|
+
return new Promise((resolve2, reject) => {
|
|
518
524
|
const chunks = [];
|
|
519
|
-
|
|
520
|
-
|
|
525
|
+
let total = 0;
|
|
526
|
+
let overflowed = false;
|
|
527
|
+
req.on("data", (c) => {
|
|
528
|
+
if (overflowed) return;
|
|
529
|
+
total += c.length;
|
|
530
|
+
if (total > maxBytes) {
|
|
531
|
+
overflowed = true;
|
|
532
|
+
chunks.length = 0;
|
|
533
|
+
reject(new Error(`Request body exceeds ${maxBytes} bytes`));
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
536
|
+
chunks.push(c);
|
|
537
|
+
});
|
|
538
|
+
req.on("end", () => {
|
|
539
|
+
if (!overflowed) resolve2(Buffer.concat(chunks));
|
|
540
|
+
});
|
|
521
541
|
});
|
|
522
542
|
}
|
|
523
543
|
|
|
@@ -568,7 +588,7 @@ var DEFAULT_PHASE = "sandbox";
|
|
|
568
588
|
function isPhase(value) {
|
|
569
589
|
return PHASES.includes(value);
|
|
570
590
|
}
|
|
571
|
-
function resolvePhase(explicit, cwd = process.cwd()) {
|
|
591
|
+
function resolvePhase(explicit, cwd = process.cwd(), env = process.env) {
|
|
572
592
|
if (explicit) {
|
|
573
593
|
if (!isPhase(explicit)) {
|
|
574
594
|
throw new Error(
|
|
@@ -578,7 +598,7 @@ function resolvePhase(explicit, cwd = process.cwd()) {
|
|
|
578
598
|
return { phase: explicit, source: "flag" };
|
|
579
599
|
}
|
|
580
600
|
const fileEnv = loadEnv3("development", cwd, "");
|
|
581
|
-
const fromEnv =
|
|
601
|
+
const fromEnv = env.VITE_BSTAGE_PHASE || fileEnv.VITE_BSTAGE_PHASE || "";
|
|
582
602
|
if (fromEnv) {
|
|
583
603
|
if (isPhase(fromEnv)) return { phase: fromEnv, source: "env" };
|
|
584
604
|
return { phase: DEFAULT_PHASE, source: "default", ignoredEnvValue: fromEnv };
|
|
@@ -1729,13 +1749,13 @@ async function refreshAccessToken(mode, phase, hosts, tenantId, accessToken, coo
|
|
|
1729
1749
|
headers,
|
|
1730
1750
|
body: Buffer.from(postBody)
|
|
1731
1751
|
});
|
|
1732
|
-
const
|
|
1733
|
-
const
|
|
1734
|
-
if (result.statusCode === 200 &&
|
|
1752
|
+
const json = JSON.parse(result.body.toString("utf-8"));
|
|
1753
|
+
const newToken = json.accessToken ?? json.data?.accessToken;
|
|
1754
|
+
if (result.statusCode === 200 && newToken) {
|
|
1735
1755
|
console.info(`[bstage] token refreshed (${mode})`);
|
|
1736
|
-
return
|
|
1756
|
+
return newToken;
|
|
1737
1757
|
}
|
|
1738
|
-
console.warn(
|
|
1758
|
+
console.warn(`[bstage] token refresh failed (mode=${mode}, status=${result.statusCode})`);
|
|
1739
1759
|
return null;
|
|
1740
1760
|
} catch {
|
|
1741
1761
|
return null;
|
|
@@ -1821,10 +1841,15 @@ function handleGatewayProxy(mode, phase, hosts, req, res) {
|
|
|
1821
1841
|
res.writeHead(result.statusCode, result.headers);
|
|
1822
1842
|
res.end(result.body);
|
|
1823
1843
|
} catch (err) {
|
|
1824
|
-
|
|
1844
|
+
console.error("[bstage] gateway proxy error:", err instanceof Error ? err.message : err);
|
|
1825
1845
|
res.writeHead(502, { "Content-Type": "application/json" });
|
|
1826
|
-
res.end(JSON.stringify({ message: "Gateway proxy error"
|
|
1846
|
+
res.end(JSON.stringify({ message: "Gateway proxy error" }));
|
|
1827
1847
|
}
|
|
1848
|
+
}).catch((err) => {
|
|
1849
|
+
console.error("[bstage] request body rejected:", err instanceof Error ? err.message : err);
|
|
1850
|
+
if (res.headersSent) return;
|
|
1851
|
+
res.writeHead(413, { "Content-Type": "application/json" });
|
|
1852
|
+
res.end(JSON.stringify({ message: "Request body too large" }));
|
|
1828
1853
|
});
|
|
1829
1854
|
}
|
|
1830
1855
|
function subpathOf(source) {
|
|
@@ -1895,18 +1920,22 @@ function handleAuthProxy(mode, phase, hosts, req, res) {
|
|
|
1895
1920
|
}
|
|
1896
1921
|
} else {
|
|
1897
1922
|
console.warn(
|
|
1898
|
-
`[bstage] auth proxy upstream non-2xx (mode=${mode}, status=${result.statusCode})
|
|
1899
|
-
textBody.slice(0, 500)
|
|
1923
|
+
`[bstage] auth proxy upstream non-2xx (mode=${mode}, status=${result.statusCode})`
|
|
1900
1924
|
);
|
|
1901
1925
|
}
|
|
1902
1926
|
stripResponseCookies(result.headers, extraCookies);
|
|
1903
1927
|
res.writeHead(result.statusCode, result.headers);
|
|
1904
1928
|
res.end(textBody);
|
|
1905
1929
|
} catch (err) {
|
|
1906
|
-
|
|
1930
|
+
console.error("[bstage] auth proxy error:", err instanceof Error ? err.message : err);
|
|
1907
1931
|
res.writeHead(502, { "Content-Type": "application/json" });
|
|
1908
|
-
res.end(JSON.stringify({ message: "Auth proxy error"
|
|
1932
|
+
res.end(JSON.stringify({ message: "Auth proxy error" }));
|
|
1909
1933
|
}
|
|
1934
|
+
}).catch((err) => {
|
|
1935
|
+
console.error("[bstage] request body rejected:", err instanceof Error ? err.message : err);
|
|
1936
|
+
if (res.headersSent) return;
|
|
1937
|
+
res.writeHead(413, { "Content-Type": "application/json" });
|
|
1938
|
+
res.end(JSON.stringify({ message: "Request body too large" }));
|
|
1910
1939
|
});
|
|
1911
1940
|
}
|
|
1912
1941
|
function bstageDevPlugin(options = {}) {
|
|
@@ -2063,11 +2092,14 @@ function createViteConfig(options = {}) {
|
|
|
2063
2092
|
|
|
2064
2093
|
export {
|
|
2065
2094
|
LOGIN_PATH,
|
|
2095
|
+
isPublicPhase,
|
|
2066
2096
|
TRANSLATION_LANGUAGES,
|
|
2067
2097
|
DEFAULT_TRANSLATION_TIER,
|
|
2068
2098
|
TRANSLATION_CDN_ORIGIN,
|
|
2069
2099
|
TRANSLATION_CDN_BASE_KEY,
|
|
2070
2100
|
TRANSLATION_CDN_BUCKET_PREFIX,
|
|
2101
|
+
PORTAL_HOSTS,
|
|
2102
|
+
PORTAL_HOST_ENV_KEY,
|
|
2071
2103
|
resolveProjectTarget,
|
|
2072
2104
|
resolvePhase,
|
|
2073
2105
|
describePhase,
|