@joshski/dust 0.1.35 → 0.1.36
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/dust.js +21 -4
- package/package.json +1 -1
package/dist/dust.js
CHANGED
|
@@ -578,7 +578,24 @@ async function clearToken(fileSystem, homeDir) {
|
|
|
578
578
|
await fileSystem.writeFile(path, "{}");
|
|
579
579
|
} catch {}
|
|
580
580
|
}
|
|
581
|
+
async function defaultExchangeCode(code) {
|
|
582
|
+
const host = getDustbucketHost();
|
|
583
|
+
const response = await fetch(`${host}/auth/cli/exchange`, {
|
|
584
|
+
method: "POST",
|
|
585
|
+
headers: { "Content-Type": "application/json" },
|
|
586
|
+
body: JSON.stringify({ code })
|
|
587
|
+
});
|
|
588
|
+
if (!response.ok) {
|
|
589
|
+
throw new Error(`Token exchange failed: ${response.status}`);
|
|
590
|
+
}
|
|
591
|
+
const body = await response.json();
|
|
592
|
+
if (typeof body.token !== "string") {
|
|
593
|
+
throw new Error("Invalid token exchange response");
|
|
594
|
+
}
|
|
595
|
+
return body.token;
|
|
596
|
+
}
|
|
581
597
|
async function authenticate(authDeps) {
|
|
598
|
+
const exchange = authDeps.exchangeCode ?? defaultExchangeCode;
|
|
582
599
|
return new Promise((resolve, reject) => {
|
|
583
600
|
let timer = null;
|
|
584
601
|
let serverHandle = null;
|
|
@@ -595,13 +612,13 @@ async function authenticate(authDeps) {
|
|
|
595
612
|
const handler = (request) => {
|
|
596
613
|
const url = new URL(request.url);
|
|
597
614
|
if (url.pathname === "/callback") {
|
|
598
|
-
const
|
|
599
|
-
if (
|
|
615
|
+
const code = url.searchParams.get("code");
|
|
616
|
+
if (code) {
|
|
600
617
|
cleanup();
|
|
601
|
-
|
|
618
|
+
exchange(code).then(resolve, reject);
|
|
602
619
|
return new Response("<html><body><p>Authentication successful! You can close this tab.</p></body></html>", { headers: { "Content-Type": "text/html" } });
|
|
603
620
|
}
|
|
604
|
-
return new Response("Missing
|
|
621
|
+
return new Response("Missing code", { status: 400 });
|
|
605
622
|
}
|
|
606
623
|
return new Response("Not found", { status: 404 });
|
|
607
624
|
};
|