@nmakarov/cli-toolkit 0.32.0 → 0.33.0

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/dist/index.js CHANGED
@@ -4032,6 +4032,7 @@ var Aws = class _Aws {
4032
4032
  secretAccessKey: config2.secretAccessKey,
4033
4033
  ...config2.sessionToken ? { sessionToken: config2.sessionToken } : {}
4034
4034
  } : void 0;
4035
+ this.hasExplicitCredentials = !!this._credentials;
4035
4036
  process.env.AWS_SDK_JS_NODE_VERSION_SUPPORT_WARNING_DISABLED ??= "true";
4036
4037
  this._clients = {};
4037
4038
  }
@@ -4054,6 +4055,66 @@ var Aws = class _Aws {
4054
4055
  getRegion() {
4055
4056
  return this.region;
4056
4057
  }
4058
+ // ── credentials ─────────────────────────────────────────────────────────────
4059
+ /**
4060
+ * Are any credentials available *before* hitting AWS? Returns
4061
+ * { ok, source } — explicit keys, or a resolvable default chain (profile/SSO/
4062
+ * instance role). { ok:false } means there's nothing to even try with.
4063
+ * Note: "ok" only means creds were *found*, not that AWS will accept them.
4064
+ */
4065
+ async checkCredentials() {
4066
+ if (this.hasExplicitCredentials) {
4067
+ return { ok: true, source: "explicit keys (env/.env/CLI)" };
4068
+ }
4069
+ try {
4070
+ const provider = this._sts().config.credentials;
4071
+ const resolved = typeof provider === "function" ? await provider() : provider;
4072
+ if (resolved?.accessKeyId) {
4073
+ return { ok: true, source: "default credential chain (profile/SSO/role)" };
4074
+ }
4075
+ } catch {
4076
+ }
4077
+ return { ok: false };
4078
+ }
4079
+ /** True for "bad/missing credentials" style errors (vs. real failures). */
4080
+ static isAuthError(err) {
4081
+ const name = err?.name || err?.Code || err?.__type || "";
4082
+ return [
4083
+ "CredentialsProviderError",
4084
+ "InvalidClientTokenId",
4085
+ "UnrecognizedClientException",
4086
+ "AuthFailure",
4087
+ "AccessDenied",
4088
+ "AccessDeniedException",
4089
+ "ExpiredToken",
4090
+ "ExpiredTokenException",
4091
+ "SignatureDoesNotMatch",
4092
+ "MissingAuthenticationToken"
4093
+ ].includes(name);
4094
+ }
4095
+ /** Short, precise instructions for getting AWS credentials into .env. */
4096
+ static credentialsHelp(region = DEFAULT_REGION) {
4097
+ return [
4098
+ "No usable AWS credentials were found (or AWS rejected them).",
4099
+ "",
4100
+ "Put a read-only access key in the project's .env:",
4101
+ "",
4102
+ " AWS_ACCESS_KEY_ID=AKIA...",
4103
+ " AWS_SECRET_ACCESS_KEY=...",
4104
+ ` AWS_REGION=${region} # optional (default ${DEFAULT_REGION})`,
4105
+ "",
4106
+ "Get a key from the AWS console (~2 min):",
4107
+ " 1. IAM \u2192 Users \u2192 create or pick a user (console sign-in not needed).",
4108
+ ' 2. Attach a policy \u2014 "ReadOnlyAccess" (AWS managed) is enough for discovery.',
4109
+ ' 3. The user \u2192 "Security credentials" \u2192 "Create access key" \u2192 "CLI".',
4110
+ " 4. Copy the Access key ID + Secret access key (the secret shows only once).",
4111
+ " 5. Paste both into .env, then re-run.",
4112
+ " Direct link: https://console.aws.amazon.com/iam/home#/users",
4113
+ "",
4114
+ "Prefer a named profile or an EC2 instance role? Re-run with AWS_PROFILE=<name>",
4115
+ "set (or on the instance) and credentials resolve automatically."
4116
+ ].join("\n");
4117
+ }
4057
4118
  // ── identity ──────────────────────────────────────────────────────────────
4058
4119
  /** { account, arn, userId } — confirm which account/identity the keys belong to. */
4059
4120
  async whoAmI() {