@bragduck/cli 2.29.2 → 2.30.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/README.md +138 -300
- package/dist/bin/bragduck.js +168 -579
- package/dist/bin/bragduck.js.map +1 -1
- package/dist/index.js +85 -83
- package/dist/index.js.map +1 -1
- package/package.json +3 -12
package/dist/index.js
CHANGED
|
@@ -9,11 +9,11 @@ var __export = (target, all) => {
|
|
|
9
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
// node_modules/tsup/assets/esm_shims.js
|
|
12
|
+
// ../../node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.6_tsx@4.21.0_typescript@5.9.3_yaml@2.8.2/node_modules/tsup/assets/esm_shims.js
|
|
13
13
|
import path from "path";
|
|
14
14
|
import { fileURLToPath } from "url";
|
|
15
15
|
var init_esm_shims = __esm({
|
|
16
|
-
"node_modules/tsup/assets/esm_shims.js"() {
|
|
16
|
+
"../../node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.6_tsx@4.21.0_typescript@5.9.3_yaml@2.8.2/node_modules/tsup/assets/esm_shims.js"() {
|
|
17
17
|
"use strict";
|
|
18
18
|
}
|
|
19
19
|
});
|
|
@@ -46,7 +46,7 @@ var init_constants = __esm({
|
|
|
46
46
|
TIMEOUT_MS: 12e4,
|
|
47
47
|
// 2 minutes
|
|
48
48
|
MIN_PORT: 8e3,
|
|
49
|
-
MAX_PORT:
|
|
49
|
+
MAX_PORT: 8004
|
|
50
50
|
};
|
|
51
51
|
API_ENDPOINTS = {
|
|
52
52
|
AUTH: {
|
|
@@ -729,92 +729,95 @@ async function findAvailablePort() {
|
|
|
729
729
|
async function startOAuthCallbackServer(expectedState) {
|
|
730
730
|
const port = await findAvailablePort();
|
|
731
731
|
const timeout = OAUTH_CONFIG.TIMEOUT_MS;
|
|
732
|
-
|
|
732
|
+
const callbackUrl = `http://127.0.0.1:${port}${OAUTH_CONFIG.CALLBACK_PATH}`;
|
|
733
|
+
return new Promise((resolveHandle, rejectHandle) => {
|
|
733
734
|
let server = null;
|
|
734
735
|
let timeoutId = null;
|
|
735
|
-
const
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
if (server) {
|
|
740
|
-
if (typeof server.closeAllConnections === "function") {
|
|
741
|
-
server.closeAllConnections();
|
|
742
|
-
}
|
|
743
|
-
server.close(() => {
|
|
744
|
-
logger.debug("OAuth server closed");
|
|
745
|
-
});
|
|
746
|
-
server.unref();
|
|
747
|
-
}
|
|
748
|
-
};
|
|
749
|
-
const handleRequest = (req, res) => {
|
|
750
|
-
const parsedUrl = parse(req.url || "", true);
|
|
751
|
-
logger.debug(`OAuth callback received: ${req.url}`);
|
|
752
|
-
if (parsedUrl.pathname === OAUTH_CONFIG.CALLBACK_PATH) {
|
|
753
|
-
const { code, state, error, error_description } = parsedUrl.query;
|
|
754
|
-
if (error) {
|
|
755
|
-
const errorMsg = error_description || error;
|
|
756
|
-
logger.debug(`OAuth error: ${errorMsg}`);
|
|
757
|
-
res.writeHead(400, { "Content-Type": "text/html" });
|
|
758
|
-
res.end(ERROR_HTML(String(errorMsg)));
|
|
759
|
-
cleanup();
|
|
760
|
-
reject(new OAuthError(`OAuth error: ${errorMsg}`));
|
|
761
|
-
return;
|
|
736
|
+
const resultPromise = new Promise((resolveResult, rejectResult) => {
|
|
737
|
+
const cleanup = () => {
|
|
738
|
+
if (timeoutId) {
|
|
739
|
+
globalThis.clearTimeout(timeoutId);
|
|
762
740
|
}
|
|
763
|
-
if (
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
741
|
+
if (server) {
|
|
742
|
+
if (typeof server.closeAllConnections === "function") {
|
|
743
|
+
server.closeAllConnections();
|
|
744
|
+
}
|
|
745
|
+
server.close(() => {
|
|
746
|
+
logger.debug("OAuth server closed");
|
|
747
|
+
});
|
|
748
|
+
server.unref();
|
|
771
749
|
}
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
750
|
+
};
|
|
751
|
+
const handleRequest = (req, res) => {
|
|
752
|
+
const parsedUrl = parse(req.url || "", true);
|
|
753
|
+
logger.debug(`OAuth callback received: ${req.url}`);
|
|
754
|
+
if (parsedUrl.pathname === OAUTH_CONFIG.CALLBACK_PATH) {
|
|
755
|
+
const { code, state, error, error_description } = parsedUrl.query;
|
|
756
|
+
if (error) {
|
|
757
|
+
const errorMsg = error_description || error;
|
|
758
|
+
logger.debug(`OAuth error: ${errorMsg}`);
|
|
759
|
+
res.writeHead(400, { "Content-Type": "text/html" });
|
|
760
|
+
res.end(ERROR_HTML(String(errorMsg)));
|
|
761
|
+
cleanup();
|
|
762
|
+
rejectResult(new OAuthError(`OAuth error: ${errorMsg}`));
|
|
763
|
+
return;
|
|
764
|
+
}
|
|
765
|
+
if (!code || !state) {
|
|
766
|
+
const errorMsg = "Missing code or state parameter";
|
|
767
|
+
logger.debug(errorMsg);
|
|
768
|
+
res.writeHead(400, { "Content-Type": "text/html" });
|
|
769
|
+
res.end(ERROR_HTML(errorMsg));
|
|
770
|
+
cleanup();
|
|
771
|
+
rejectResult(new OAuthError(errorMsg));
|
|
772
|
+
return;
|
|
773
|
+
}
|
|
774
|
+
if (state !== expectedState) {
|
|
775
|
+
const errorMsg = "Invalid state parameter (possible CSRF attack)";
|
|
776
|
+
logger.debug(errorMsg);
|
|
777
|
+
res.writeHead(400, { "Content-Type": "text/html" });
|
|
778
|
+
res.end(ERROR_HTML(errorMsg));
|
|
779
|
+
cleanup();
|
|
780
|
+
rejectResult(new OAuthError(errorMsg));
|
|
781
|
+
return;
|
|
782
|
+
}
|
|
783
|
+
res.writeHead(200, { "Content-Type": "text/html" });
|
|
784
|
+
res.end(SUCCESS_HTML);
|
|
785
|
+
globalThis.setTimeout(() => {
|
|
786
|
+
cleanup();
|
|
787
|
+
resolveResult({
|
|
788
|
+
code: String(code),
|
|
789
|
+
state: String(state),
|
|
790
|
+
port
|
|
791
|
+
});
|
|
792
|
+
}, 100);
|
|
779
793
|
return;
|
|
780
794
|
}
|
|
781
|
-
res.writeHead(
|
|
782
|
-
res.end(
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
`OAuth callback server listening on http://127.0.0.1:${port}${OAUTH_CONFIG.CALLBACK_PATH}`
|
|
805
|
-
);
|
|
795
|
+
res.writeHead(404, { "Content-Type": "text/plain" });
|
|
796
|
+
res.end("Not Found");
|
|
797
|
+
};
|
|
798
|
+
server = createServer(handleRequest);
|
|
799
|
+
server.on("error", (error) => {
|
|
800
|
+
logger.debug(`OAuth server error: ${error.message}`);
|
|
801
|
+
cleanup();
|
|
802
|
+
rejectResult(new OAuthError(`OAuth server error: ${error.message}`));
|
|
803
|
+
rejectHandle(new OAuthError(`OAuth server error: ${error.message}`));
|
|
804
|
+
});
|
|
805
|
+
server.listen(port, "127.0.0.1", () => {
|
|
806
|
+
logger.debug(
|
|
807
|
+
`OAuth callback server listening on http://127.0.0.1:${port}${OAUTH_CONFIG.CALLBACK_PATH}`
|
|
808
|
+
);
|
|
809
|
+
resolveHandle({ callbackUrl, resultPromise });
|
|
810
|
+
});
|
|
811
|
+
timeoutId = globalThis.setTimeout(() => {
|
|
812
|
+
logger.debug("OAuth callback timeout");
|
|
813
|
+
cleanup();
|
|
814
|
+
rejectResult(
|
|
815
|
+
new OAuthError("Authentication timeout - no callback received within 2 minutes")
|
|
816
|
+
);
|
|
817
|
+
}, timeout);
|
|
806
818
|
});
|
|
807
|
-
timeoutId = globalThis.setTimeout(() => {
|
|
808
|
-
logger.debug("OAuth callback timeout");
|
|
809
|
-
cleanup();
|
|
810
|
-
reject(new OAuthError("Authentication timeout - no callback received within 2 minutes"));
|
|
811
|
-
}, timeout);
|
|
812
819
|
});
|
|
813
820
|
}
|
|
814
|
-
async function getCallbackUrl() {
|
|
815
|
-
const port = await findAvailablePort();
|
|
816
|
-
return `http://127.0.0.1:${port}${OAUTH_CONFIG.CALLBACK_PATH}`;
|
|
817
|
-
}
|
|
818
821
|
var SUCCESS_HTML, ERROR_HTML;
|
|
819
822
|
var init_oauth_server = __esm({
|
|
820
823
|
"src/utils/oauth-server.ts"() {
|
|
@@ -1077,7 +1080,7 @@ var init_auth_service = __esm({
|
|
|
1077
1080
|
async login() {
|
|
1078
1081
|
logger.debug("Starting OAuth login flow");
|
|
1079
1082
|
const state = this.generateState();
|
|
1080
|
-
const callbackUrl = await
|
|
1083
|
+
const { callbackUrl, resultPromise } = await startOAuthCallbackServer(state);
|
|
1081
1084
|
storageService.setOAuthState({
|
|
1082
1085
|
state,
|
|
1083
1086
|
createdAt: Date.now()
|
|
@@ -1086,7 +1089,6 @@ var init_auth_service = __esm({
|
|
|
1086
1089
|
logger.debug(`Callback URL: ${callbackUrl}`);
|
|
1087
1090
|
const authUrl = await this.buildAuthUrl(state, callbackUrl);
|
|
1088
1091
|
logger.debug(`Authorization URL: ${authUrl}`);
|
|
1089
|
-
const serverPromise = startOAuthCallbackServer(state);
|
|
1090
1092
|
try {
|
|
1091
1093
|
await openBrowser(authUrl);
|
|
1092
1094
|
} catch {
|
|
@@ -1096,7 +1098,7 @@ var init_auth_service = __esm({
|
|
|
1096
1098
|
}
|
|
1097
1099
|
let callbackResult;
|
|
1098
1100
|
try {
|
|
1099
|
-
callbackResult = await
|
|
1101
|
+
callbackResult = await resultPromise;
|
|
1100
1102
|
} catch (error) {
|
|
1101
1103
|
storageService.deleteOAuthState();
|
|
1102
1104
|
throw error;
|