@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.
Files changed (2) hide show
  1. package/dist/dust.js +21 -4
  2. 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 token = url.searchParams.get("token");
599
- if (token) {
615
+ const code = url.searchParams.get("code");
616
+ if (code) {
600
617
  cleanup();
601
- resolve(token);
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 token", { status: 400 });
621
+ return new Response("Missing code", { status: 400 });
605
622
  }
606
623
  return new Response("Not found", { status: 404 });
607
624
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joshski/dust",
3
- "version": "0.1.35",
3
+ "version": "0.1.36",
4
4
  "description": "Flow state for AI coding agents",
5
5
  "type": "module",
6
6
  "bin": {