repowise 0.1.49 → 0.1.52

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.
@@ -73,6 +73,10 @@ import { readFile as readFile2, writeFile as writeFile2, mkdir as mkdir2, chmod,
73
73
  import http from "http";
74
74
  import { homedir as homedir2 } from "os";
75
75
  import { join as join2 } from "path";
76
+ function getCognitoConfigForStorage() {
77
+ const { domain, clientId, region, customDomain } = getCognitoConfig();
78
+ return { domain, clientId, region, customDomain };
79
+ }
76
80
  function getCognitoConfig() {
77
81
  const env = getEnvConfig();
78
82
  return {
@@ -259,6 +263,7 @@ async function getValidCredentials() {
259
263
  if (Date.now() > creds.expiresAt - 5 * 60 * 1e3) {
260
264
  try {
261
265
  const refreshed = await refreshTokens(creds.refreshToken);
266
+ refreshed.cognito = creds.cognito;
262
267
  await storeCredentials(refreshed);
263
268
  return refreshed;
264
269
  } catch {
@@ -288,6 +293,8 @@ Open this URL in your browser to authenticate:
288
293
  throw new Error("State mismatch \u2014 possible CSRF attack. Please try again.");
289
294
  }
290
295
  const credentials = await exchangeCodeForTokens(code, codeVerifier);
296
+ const { domain, clientId, region, customDomain } = getCognitoConfig();
297
+ credentials.cognito = { domain, clientId, region, customDomain };
291
298
  await storeCredentials(credentials);
292
299
  return credentials;
293
300
  }
@@ -1810,6 +1817,7 @@ Waiting for authentication...`);
1810
1817
  }
1811
1818
  spinner.start("Exchanging authorization code...");
1812
1819
  const credentials = await exchangeCodeForTokens(code, codeVerifier);
1820
+ credentials.cognito = getCognitoConfigForStorage();
1813
1821
  await storeCredentials(credentials);
1814
1822
  const { email } = decodeIdToken(credentials.idToken);
1815
1823
  spinner.succeed(chalk6.green(`Logged in as ${chalk6.bold(email)}`));
@@ -2182,24 +2190,27 @@ var init_state = __esm({
2182
2190
  import { readFile as readFile8, writeFile as writeFile7, mkdir as mkdir7, chmod as chmod3 } from "fs/promises";
2183
2191
  import { homedir as homedir8 } from "os";
2184
2192
  import { join as join11 } from "path";
2185
- function getCognitoConfig2() {
2186
- return {
2187
- domain: process.env["REPOWISE_COGNITO_DOMAIN"] ?? "auth-repowise-dev",
2188
- clientId: process.env["REPOWISE_COGNITO_CLIENT_ID"] ?? "",
2189
- region: process.env["REPOWISE_COGNITO_REGION"] ?? "us-east-1"
2190
- };
2191
- }
2192
- function getTokenUrl2() {
2193
- const { domain, region } = getCognitoConfig2();
2194
- return `https://${domain}.auth.${region}.amazoncognito.com/oauth2/token`;
2195
- }
2196
- async function refreshTokens2(refreshToken) {
2197
- const response = await fetch(getTokenUrl2(), {
2193
+ function getTokenUrl2(creds) {
2194
+ const cognito = creds?.cognito;
2195
+ const domain = process.env["REPOWISE_COGNITO_DOMAIN"] ?? cognito?.domain ?? "auth-repowise-dev";
2196
+ const region = process.env["REPOWISE_COGNITO_REGION"] ?? cognito?.region ?? "us-east-1";
2197
+ const customDomain = cognito?.customDomain ?? false;
2198
+ return customDomain ? `https://${domain}/oauth2/token` : `https://${domain}.auth.${region}.amazoncognito.com/oauth2/token`;
2199
+ }
2200
+ function getClientId(creds) {
2201
+ return process.env["REPOWISE_COGNITO_CLIENT_ID"] ?? creds?.cognito?.clientId ?? "";
2202
+ }
2203
+ async function refreshTokens2(refreshToken, creds) {
2204
+ const clientId = getClientId(creds);
2205
+ if (!clientId) {
2206
+ throw new Error("No Cognito client ID available. Run `repowise login` first.");
2207
+ }
2208
+ const response = await fetch(getTokenUrl2(creds), {
2198
2209
  method: "POST",
2199
2210
  headers: { "Content-Type": "application/x-www-form-urlencoded" },
2200
2211
  body: new URLSearchParams({
2201
2212
  grant_type: "refresh_token",
2202
- client_id: getCognitoConfig2().clientId,
2213
+ client_id: clientId,
2203
2214
  refresh_token: refreshToken
2204
2215
  })
2205
2216
  });
@@ -2211,7 +2222,8 @@ async function refreshTokens2(refreshToken) {
2211
2222
  accessToken: data.access_token,
2212
2223
  refreshToken,
2213
2224
  idToken: data.id_token,
2214
- expiresAt: Date.now() + data.expires_in * 1e3
2225
+ expiresAt: Date.now() + data.expires_in * 1e3,
2226
+ cognito: creds.cognito
2215
2227
  };
2216
2228
  }
2217
2229
  async function getStoredCredentials2() {
@@ -2236,7 +2248,7 @@ async function getValidCredentials2() {
2236
2248
  return null;
2237
2249
  if (Date.now() > creds.expiresAt - 5 * 60 * 1e3) {
2238
2250
  try {
2239
- const refreshed = await refreshTokens2(creds.refreshToken);
2251
+ const refreshed = await refreshTokens2(creds.refreshToken, creds);
2240
2252
  await storeCredentials2(refreshed);
2241
2253
  return refreshed;
2242
2254
  } catch {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "repowise",
3
- "version": "0.1.49",
3
+ "version": "0.1.52",
4
4
  "type": "module",
5
5
  "description": "AI-optimized codebase context generator",
6
6
  "bin": {