@quikcommit/cli 6.0.0 → 7.0.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/index.js +52 -19
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -41,7 +41,7 @@ var init_types = __esm({
|
|
|
41
41
|
});
|
|
42
42
|
|
|
43
43
|
// ../shared/dist/constants.js
|
|
44
|
-
var CONFIG_DIR, CREDENTIALS_FILE, CONFIG_FILE, DEFAULT_API_URL, MAX_PR_CURRENT_BRANCH_CHARS,
|
|
44
|
+
var CONFIG_DIR, CREDENTIALS_FILE, CONFIG_FILE, DEFAULT_API_URL, MAX_PR_CURRENT_BRANCH_CHARS, DEVICE_FLOW_TIMEOUT;
|
|
45
45
|
var init_constants = __esm({
|
|
46
46
|
"../shared/dist/constants.js"() {
|
|
47
47
|
"use strict";
|
|
@@ -50,7 +50,6 @@ var init_constants = __esm({
|
|
|
50
50
|
CONFIG_FILE = "config.json";
|
|
51
51
|
DEFAULT_API_URL = "https://api.quikcommit.dev";
|
|
52
52
|
MAX_PR_CURRENT_BRANCH_CHARS = 256;
|
|
53
|
-
DEVICE_POLL_INTERVAL = 1e3;
|
|
54
53
|
DEVICE_FLOW_TIMEOUT = 6e5;
|
|
55
54
|
}
|
|
56
55
|
});
|
|
@@ -8065,23 +8064,25 @@ function openBrowser(url) {
|
|
|
8065
8064
|
return false;
|
|
8066
8065
|
}
|
|
8067
8066
|
async function runLogin() {
|
|
8068
|
-
const
|
|
8067
|
+
const codeRes = await fetch(`${API_URL}/api/auth/device/code`, {
|
|
8069
8068
|
method: "POST",
|
|
8070
8069
|
headers: { "Content-Type": "application/json" },
|
|
8071
|
-
body: JSON.stringify({})
|
|
8070
|
+
body: JSON.stringify({ client_id: CLIENT_ID })
|
|
8072
8071
|
});
|
|
8073
|
-
if (!
|
|
8074
|
-
const err = await
|
|
8072
|
+
if (!codeRes.ok) {
|
|
8073
|
+
const err = await codeRes.json().catch(() => ({ error: codeRes.statusText }));
|
|
8075
8074
|
throw new Error(err.error ?? "Failed to start device flow");
|
|
8076
8075
|
}
|
|
8077
|
-
const
|
|
8078
|
-
const
|
|
8079
|
-
if (!
|
|
8080
|
-
throw new Error("Server did not return
|
|
8076
|
+
const codeData = await codeRes.json();
|
|
8077
|
+
const { device_code, user_code, verification_uri_complete, interval = 5 } = codeData;
|
|
8078
|
+
if (!device_code || !user_code) {
|
|
8079
|
+
throw new Error("Server did not return device codes");
|
|
8081
8080
|
}
|
|
8082
8081
|
console.log("Opening browser to sign in...");
|
|
8083
8082
|
console.log("");
|
|
8084
|
-
|
|
8083
|
+
console.log(` Your code: ${user_code}`);
|
|
8084
|
+
console.log("");
|
|
8085
|
+
const authUrl = verification_uri_complete ?? `${DASHBOARD_URL}/device?user_code=${encodeURIComponent(user_code)}`;
|
|
8085
8086
|
const opened = openBrowser(authUrl);
|
|
8086
8087
|
if (!opened) {
|
|
8087
8088
|
console.log("Could not open browser. Please visit:");
|
|
@@ -8095,23 +8096,54 @@ async function runLogin() {
|
|
|
8095
8096
|
`\r${SPINNER_FRAMES[frame++ % SPINNER_FRAMES.length]} Waiting for authorization... (${elapsed}s)`
|
|
8096
8097
|
);
|
|
8097
8098
|
}, 80);
|
|
8099
|
+
let pollingInterval = interval * 1e3;
|
|
8098
8100
|
const startTime = Date.now();
|
|
8099
8101
|
try {
|
|
8100
8102
|
while (Date.now() - startTime < DEVICE_FLOW_TIMEOUT) {
|
|
8103
|
+
await new Promise((r) => setTimeout(r, pollingInterval));
|
|
8101
8104
|
try {
|
|
8102
|
-
const
|
|
8103
|
-
|
|
8104
|
-
|
|
8105
|
-
|
|
8106
|
-
|
|
8107
|
-
|
|
8105
|
+
const tokenRes = await fetch(`${API_URL}/api/auth/device/token`, {
|
|
8106
|
+
method: "POST",
|
|
8107
|
+
headers: { "Content-Type": "application/json" },
|
|
8108
|
+
body: JSON.stringify({
|
|
8109
|
+
grant_type: "urn:ietf:params:oauth:grant-type:device_code",
|
|
8110
|
+
device_code,
|
|
8111
|
+
client_id: CLIENT_ID
|
|
8112
|
+
})
|
|
8113
|
+
});
|
|
8114
|
+
const tokenData = await tokenRes.json();
|
|
8115
|
+
if (tokenData.access_token) {
|
|
8116
|
+
saveApiKey(tokenData.access_token);
|
|
8108
8117
|
process.stderr.write("\r\x1B[2K");
|
|
8109
8118
|
console.log("Successfully logged in!");
|
|
8110
8119
|
return;
|
|
8111
8120
|
}
|
|
8121
|
+
if (tokenData.error) {
|
|
8122
|
+
switch (tokenData.error) {
|
|
8123
|
+
case "authorization_pending":
|
|
8124
|
+
break;
|
|
8125
|
+
// continue polling
|
|
8126
|
+
case "slow_down":
|
|
8127
|
+
pollingInterval += 5e3;
|
|
8128
|
+
break;
|
|
8129
|
+
case "access_denied":
|
|
8130
|
+
process.stderr.write("\r\x1B[2K");
|
|
8131
|
+
console.error("Authorization was denied.");
|
|
8132
|
+
process.exit(1);
|
|
8133
|
+
break;
|
|
8134
|
+
case "expired_token":
|
|
8135
|
+
process.stderr.write("\r\x1B[2K");
|
|
8136
|
+
console.error("Device code expired. Please try again.");
|
|
8137
|
+
process.exit(1);
|
|
8138
|
+
break;
|
|
8139
|
+
default:
|
|
8140
|
+
process.stderr.write("\r\x1B[2K");
|
|
8141
|
+
console.error(`Error: ${tokenData.error_description ?? tokenData.error}`);
|
|
8142
|
+
process.exit(1);
|
|
8143
|
+
}
|
|
8144
|
+
}
|
|
8112
8145
|
} catch {
|
|
8113
8146
|
}
|
|
8114
|
-
await new Promise((r) => setTimeout(r, DEVICE_POLL_INTERVAL));
|
|
8115
8147
|
}
|
|
8116
8148
|
process.stderr.write("\r\x1B[2K");
|
|
8117
8149
|
console.error("Login timed out. Please try again.");
|
|
@@ -8120,7 +8152,7 @@ async function runLogin() {
|
|
|
8120
8152
|
clearInterval(spinner);
|
|
8121
8153
|
}
|
|
8122
8154
|
}
|
|
8123
|
-
var import_child_process4, import_os3, API_URL, DASHBOARD_URL, SPINNER_FRAMES;
|
|
8155
|
+
var import_child_process4, import_os3, API_URL, DASHBOARD_URL, CLIENT_ID, SPINNER_FRAMES;
|
|
8124
8156
|
var init_login = __esm({
|
|
8125
8157
|
"src/commands/login.ts"() {
|
|
8126
8158
|
"use strict";
|
|
@@ -8130,6 +8162,7 @@ var init_login = __esm({
|
|
|
8130
8162
|
init_dist();
|
|
8131
8163
|
API_URL = process.env.QC_API_URL ?? DEFAULT_API_URL;
|
|
8132
8164
|
DASHBOARD_URL = "https://app.quikcommit.dev";
|
|
8165
|
+
CLIENT_ID = "qc-cli";
|
|
8133
8166
|
SPINNER_FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
8134
8167
|
}
|
|
8135
8168
|
});
|