@topolo/cli 0.9.2 → 0.9.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/index.js +51 -45
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -2942,52 +2942,58 @@ async function refreshCredentialIfNeeded(environment = selectedEnvironment(), op
2942
2942
  if (process.env[`${prefix}_API_KEY`] || process.env[`${prefix}_ACCESS_TOKEN`] || environment === "production" && process.env.TOPOLO_API_KEY || environment === "production" && process.env.TOPOLO_ACCESS_TOKEN) {
2943
2943
  return resolveCredential(environment);
2944
2944
  }
2945
- const config = await readConfig();
2946
- const profile = profileForEnvironment(config, environment);
2947
- const cred = profile.credential;
2948
- if (!cred || cred.kind !== "access_token") return cred ?? null;
2949
- if (!cred.refreshToken || !profile.oauthClientId) return cred;
2950
- const now = Math.floor(Date.now() / 1e3);
2951
- if (!options.force && cred.expiresAt && cred.expiresAt - REFRESH_SKEW_SECONDS > now) return cred;
2952
- const serviceUrls = resolveServiceUrls(profile.serviceUrls, environment);
2953
- if (environment === "local" && !serviceUrls?.auth) {
2954
- throw new TopoloSdkError2(
2955
- "environment_service_url_required",
2956
- "Local Topolo credential refresh requires an explicit local Auth service origin."
2957
- );
2958
- }
2959
- try {
2960
- const oauth = new TopoloOAuth2({
2961
- serviceUrls
2962
- });
2963
- const tokens = await oauth.refreshToken({
2964
- clientId: profile.oauthClientId,
2965
- refreshToken: cred.refreshToken
2966
- });
2967
- const refreshed = {
2968
- kind: "access_token",
2969
- accessToken: tokens.access_token,
2970
- ...tokens.refresh_token ? { refreshToken: tokens.refresh_token } : { refreshToken: cred.refreshToken },
2971
- expiresAt: Math.floor(Date.now() / 1e3) + tokens.expires_in
2972
- };
2973
- const activeContext = profile.activeContext;
2974
- const activeEntry = activeContext ? profile.contexts?.[activeContext] : void 0;
2975
- const updated = activeContext && activeEntry ? writeProfileConfig(config, environment, {
2976
- credential: refreshed,
2977
- contexts: {
2978
- ...profile.contexts ?? {},
2979
- [activeContext]: {
2980
- ...activeEntry,
2981
- credential: refreshed,
2982
- oauthClientId: activeEntry.oauthClientId ?? profile.oauthClientId
2945
+ const observed = profileForEnvironment(await readConfig(), environment).credential;
2946
+ return withConfigWriteLock(async () => {
2947
+ const config = await readConfig();
2948
+ const profile = profileForEnvironment(config, environment);
2949
+ const cred = profile.credential;
2950
+ if (!cred || cred.kind !== "access_token") return cred ?? null;
2951
+ if (!cred.refreshToken || !profile.oauthClientId) return cred;
2952
+ if (options.force && observed?.kind === "access_token" && observed.accessToken !== cred.accessToken) {
2953
+ return cred;
2954
+ }
2955
+ const now = Math.floor(Date.now() / 1e3);
2956
+ if (!options.force && cred.expiresAt && cred.expiresAt - REFRESH_SKEW_SECONDS > now) return cred;
2957
+ const serviceUrls = resolveServiceUrls(profile.serviceUrls, environment);
2958
+ if (environment === "local" && !serviceUrls?.auth) {
2959
+ throw new TopoloSdkError2(
2960
+ "environment_service_url_required",
2961
+ "Local Topolo credential refresh requires an explicit local Auth service origin."
2962
+ );
2963
+ }
2964
+ try {
2965
+ const oauth = new TopoloOAuth2({
2966
+ serviceUrls
2967
+ });
2968
+ const tokens = await oauth.refreshToken({
2969
+ clientId: profile.oauthClientId,
2970
+ refreshToken: cred.refreshToken
2971
+ });
2972
+ const refreshed = {
2973
+ kind: "access_token",
2974
+ accessToken: tokens.access_token,
2975
+ ...tokens.refresh_token ? { refreshToken: tokens.refresh_token } : { refreshToken: cred.refreshToken },
2976
+ expiresAt: Math.floor(Date.now() / 1e3) + tokens.expires_in
2977
+ };
2978
+ const activeContext = profile.activeContext;
2979
+ const activeEntry = activeContext ? profile.contexts?.[activeContext] : void 0;
2980
+ const updated = activeContext && activeEntry ? writeProfileConfig(config, environment, {
2981
+ credential: refreshed,
2982
+ contexts: {
2983
+ ...profile.contexts ?? {},
2984
+ [activeContext]: {
2985
+ ...activeEntry,
2986
+ credential: refreshed,
2987
+ oauthClientId: activeEntry.oauthClientId ?? profile.oauthClientId
2988
+ }
2983
2989
  }
2984
- }
2985
- }) : environment === "production" && !config.profiles?.production ? { ...config, credential: refreshed } : writeProfileConfig(config, environment, { credential: refreshed });
2986
- await writeConfig(updated);
2987
- return refreshed;
2988
- } catch {
2989
- return cred;
2990
- }
2990
+ }) : environment === "production" && !config.profiles?.production ? { ...config, credential: refreshed } : writeProfileConfig(config, environment, { credential: refreshed });
2991
+ await writeConfig(updated);
2992
+ return refreshed;
2993
+ } catch {
2994
+ return cred;
2995
+ }
2996
+ });
2991
2997
  }
2992
2998
  async function refreshContextCredentialIfNeeded(environment, key, options = {}) {
2993
2999
  return withConfigWriteLock(async () => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@topolo/cli",
3
- "version": "0.9.2",
4
- "topoloPublishedVersion": "0.9.2",
3
+ "version": "0.9.3",
4
+ "topoloPublishedVersion": "0.9.3",
5
5
  "description": "Public command-line interface for Topolo customer organizations, developers, and agents.",
6
6
  "license": "UNLICENSED",
7
7
  "author": "Topolo",
@@ -25,8 +25,8 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "@modelcontextprotocol/sdk": "^1.0.0",
28
- "@topolo/mcp": "0.11.9",
29
- "@topolo/sdk": "0.11.9",
28
+ "@topolo/mcp": "0.11.10",
29
+ "@topolo/sdk": "0.11.10",
30
30
  "commander": "^12.1.0"
31
31
  },
32
32
  "devDependencies": {