switch-profile 0.2.1 → 0.2.2

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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [0.2.2](https://github.com/nicolasdao/switch-profile/compare/v0.2.1...v0.2.2) (2026-02-10)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * SSO profile credentials written as undefined by falling back to aws configure export-credentials ([7067eff](https://github.com/nicolasdao/switch-profile/commit/7067eff15d376a3dd902ee4a03f5db7cfa539918))
11
+
5
12
  ### [0.2.1](https://github.com/nicolasdao/switch-profile/compare/v0.2.0...v0.2.1) (2026-02-08)
6
13
 
7
14
  ## [0.2.0](https://github.com/nicolasdao/switch-profile/compare/v0.1.2...v0.2.0) (2026-02-08)
@@ -81,8 +81,10 @@ The main credential retrieval function. Behaves differently for SSO vs. standard
81
81
  **For SSO profiles** (when `ssoUrl` is provided):
82
82
 
83
83
  1. Calls `refreshSsoSession()` to ensure a valid SSO session exists.
84
- 2. Calls `getSsoCredentials()` to get temporary AWS credentials.
84
+ 2. Calls `getSsoCredentials()` to get temporary AWS credentials via the CLI cache.
85
85
  3. If credentials fail with "session associated with this profile has expired", forces a session refresh and retries.
86
+ 4. If `getSsoCredentials()` returns `null` (cache-based lookup failed), falls back to `aws configure export-credentials --profile <name> --format process` which directly outputs credentials as JSON.
87
+ 5. If both approaches fail, throws an error.
86
88
 
87
89
  **For standard profiles** (when `ssoUrl` is null):
88
90
 
@@ -284,6 +286,19 @@ User selects an SSO profile
284
286
  Search ~/.aws/cli/cache/*.json
285
287
  for matching credentials
286
288
  │
289
+ ├── Found → return credentials
290
+ │
291
+ └── Not found (null)
292
+ │
293
+ ▼
294
+ Fallback: aws configure export-credentials
295
+ --profile <name> --format process
296
+ (directly outputs credentials as JSON)
297
+ │
298
+ ├── Success → return credentials
299
+ │
300
+ └── Failure → throw error
301
+ │
287
302
  ▼
288
303
  Return { aws_access_key_id,
289
304
  aws_secret_access_key,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "switch-profile",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "main": "index.js",
5
5
  "bin": "index.js",
6
6
  "description": "NPX script that exposes terminal shortcut to easily switch between cloud configuration (aws, gcp).",
package/src/aws/index.js CHANGED
@@ -337,6 +337,26 @@ const getCredentials = (profile, ssoUrl) => catchErrors((async () => {
337
337
  throw wrapErrors(errMsg, ssoCredsErrors)
338
338
  }
339
339
 
340
+ if (!ssoCreds) {
341
+ try {
342
+ const data = await exec(`aws configure export-credentials --profile ${profile} --format process`)
343
+ const parsed = JSON.parse(data)
344
+ if (parsed.AccessKeyId && parsed.SecretAccessKey) {
345
+ ssoCreds = {
346
+ aws_access_key_id: parsed.AccessKeyId,
347
+ aws_secret_access_key: parsed.SecretAccessKey,
348
+ aws_session_token: parsed.SessionToken,
349
+ expiry_date: parsed.Expiration ? new Date(parsed.Expiration) : null
350
+ }
351
+ }
352
+ } catch(e) {
353
+ // Fallback also failed
354
+ }
355
+ }
356
+
357
+ if (!ssoCreds)
358
+ throw new Error(errMsg)
359
+
340
360
  return ssoCreds
341
361
  } else {
342
362
  const [errors, credsStr] = await getCredsFile()