@oodarun/cli 0.1.2 → 0.1.3

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/cli.js +51 -2
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -763,6 +763,54 @@ function getAccessToken() {
763
763
  if (process.env.OODA_ACCESS_TOKEN) return process.env.OODA_ACCESS_TOKEN;
764
764
  return readAuthData().accessToken || null;
765
765
  }
766
+ function decodeJwtExp(token) {
767
+ try {
768
+ const payload = JSON.parse(
769
+ Buffer.from(token.split(".")[1], "base64url").toString()
770
+ );
771
+ return typeof payload.exp === "number" ? payload.exp : null;
772
+ } catch {
773
+ return null;
774
+ }
775
+ }
776
+ var _refreshInFlight = null;
777
+ async function ensureFreshAccessToken() {
778
+ if (process.env.OODA_ACCESS_TOKEN) return process.env.OODA_ACCESS_TOKEN;
779
+ const data = readAuthData();
780
+ if (!data.accessToken || !data.refreshToken) return data.accessToken || null;
781
+ const exp = decodeJwtExp(data.accessToken);
782
+ const now = Math.floor(Date.now() / 1e3);
783
+ if (exp && exp - now > 300) return data.accessToken;
784
+ if (_refreshInFlight) return _refreshInFlight;
785
+ _refreshInFlight = refreshAccessToken(data.refreshToken, data.orgId || "").finally(
786
+ () => {
787
+ _refreshInFlight = null;
788
+ }
789
+ );
790
+ return _refreshInFlight;
791
+ }
792
+ async function refreshAccessToken(refreshToken, orgId) {
793
+ try {
794
+ const doFetch = globalThis.__originalFetch ?? globalThis.fetch;
795
+ const res = await doFetch(
796
+ `${ORG_API_BASE}/auth/refresh`,
797
+ {
798
+ method: "POST",
799
+ headers: { "Content-Type": "application/json" },
800
+ body: JSON.stringify({ refreshToken })
801
+ }
802
+ );
803
+ if (!res.ok) return null;
804
+ const body = await res.json();
805
+ const data = readAuthData();
806
+ data.accessToken = body.accessToken;
807
+ data.refreshToken = body.refreshToken;
808
+ writeAuthData(data);
809
+ return body.accessToken;
810
+ } catch {
811
+ return null;
812
+ }
813
+ }
766
814
  function saveJwtTokens(accessToken, refreshToken, userId, orgId) {
767
815
  const data = readAuthData();
768
816
  data.accessToken = accessToken;
@@ -1081,13 +1129,14 @@ function patchFetchForOrg(orgId) {
1081
1129
  if (_orgPatchApplied) return;
1082
1130
  _orgPatchApplied = true;
1083
1131
  const originalFetch = globalThis.fetch;
1132
+ globalThis.__originalFetch = originalFetch;
1084
1133
  globalThis.fetch = (async (input, init) => {
1085
1134
  const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
1086
1135
  const method = init?.method ?? (input instanceof Request ? input.method : void 0);
1087
1136
  const rewritten = rewriteOrgUrl(url, orgId, method);
1088
1137
  if (rewritten) {
1089
1138
  const headers = new Headers(init?.headers || {});
1090
- const jwt = getAccessToken();
1139
+ const jwt = await ensureFreshAccessToken() ?? getAccessToken();
1091
1140
  if (jwt) {
1092
1141
  headers.set("Authorization", `Bearer ${jwt}`);
1093
1142
  }
@@ -5258,7 +5307,7 @@ async function deployFromGitHubFlow(target, apiToken, claudeToken) {
5258
5307
  }
5259
5308
 
5260
5309
  // src/cli/index.ts
5261
- var CLI_VERSION = "0.1.2";
5310
+ var CLI_VERSION = "0.1.3";
5262
5311
  function formatMutationError(result) {
5263
5312
  const parts = [];
5264
5313
  if (result.status !== void 0) parts.push(String(result.status));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oodarun/cli",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Launch Claude Code on cloud dev environments",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",