repowise 0.1.49 → 0.1.51

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.
@@ -259,6 +259,7 @@ async function getValidCredentials() {
259
259
  if (Date.now() > creds.expiresAt - 5 * 60 * 1e3) {
260
260
  try {
261
261
  const refreshed = await refreshTokens(creds.refreshToken);
262
+ refreshed.cognito = creds.cognito;
262
263
  await storeCredentials(refreshed);
263
264
  return refreshed;
264
265
  } catch {
@@ -288,6 +289,8 @@ Open this URL in your browser to authenticate:
288
289
  throw new Error("State mismatch \u2014 possible CSRF attack. Please try again.");
289
290
  }
290
291
  const credentials = await exchangeCodeForTokens(code, codeVerifier);
292
+ const { domain, clientId, region, customDomain } = getCognitoConfig();
293
+ credentials.cognito = { domain, clientId, region, customDomain };
291
294
  await storeCredentials(credentials);
292
295
  return credentials;
293
296
  }
@@ -2182,24 +2185,27 @@ var init_state = __esm({
2182
2185
  import { readFile as readFile8, writeFile as writeFile7, mkdir as mkdir7, chmod as chmod3 } from "fs/promises";
2183
2186
  import { homedir as homedir8 } from "os";
2184
2187
  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(), {
2188
+ function getTokenUrl2(creds) {
2189
+ const cognito = creds?.cognito;
2190
+ const domain = process.env["REPOWISE_COGNITO_DOMAIN"] ?? cognito?.domain ?? "auth-repowise-dev";
2191
+ const region = process.env["REPOWISE_COGNITO_REGION"] ?? cognito?.region ?? "us-east-1";
2192
+ const customDomain = cognito?.customDomain ?? false;
2193
+ return customDomain ? `https://${domain}/oauth2/token` : `https://${domain}.auth.${region}.amazoncognito.com/oauth2/token`;
2194
+ }
2195
+ function getClientId(creds) {
2196
+ return process.env["REPOWISE_COGNITO_CLIENT_ID"] ?? creds?.cognito?.clientId ?? "";
2197
+ }
2198
+ async function refreshTokens2(refreshToken, creds) {
2199
+ const clientId = getClientId(creds);
2200
+ if (!clientId) {
2201
+ throw new Error("No Cognito client ID available. Run `repowise login` first.");
2202
+ }
2203
+ const response = await fetch(getTokenUrl2(creds), {
2198
2204
  method: "POST",
2199
2205
  headers: { "Content-Type": "application/x-www-form-urlencoded" },
2200
2206
  body: new URLSearchParams({
2201
2207
  grant_type: "refresh_token",
2202
- client_id: getCognitoConfig2().clientId,
2208
+ client_id: clientId,
2203
2209
  refresh_token: refreshToken
2204
2210
  })
2205
2211
  });
@@ -2211,7 +2217,8 @@ async function refreshTokens2(refreshToken) {
2211
2217
  accessToken: data.access_token,
2212
2218
  refreshToken,
2213
2219
  idToken: data.id_token,
2214
- expiresAt: Date.now() + data.expires_in * 1e3
2220
+ expiresAt: Date.now() + data.expires_in * 1e3,
2221
+ cognito: creds.cognito
2215
2222
  };
2216
2223
  }
2217
2224
  async function getStoredCredentials2() {
@@ -2236,7 +2243,7 @@ async function getValidCredentials2() {
2236
2243
  return null;
2237
2244
  if (Date.now() > creds.expiresAt - 5 * 60 * 1e3) {
2238
2245
  try {
2239
- const refreshed = await refreshTokens2(creds.refreshToken);
2246
+ const refreshed = await refreshTokens2(creds.refreshToken, creds);
2240
2247
  await storeCredentials2(refreshed);
2241
2248
  return refreshed;
2242
2249
  } catch {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "repowise",
3
- "version": "0.1.49",
3
+ "version": "0.1.51",
4
4
  "type": "module",
5
5
  "description": "AI-optimized codebase context generator",
6
6
  "bin": {