'use strict';

var U7VZULNU_cjs = require('./U7VZULNU.cjs');

// ../../node_modules/.pnpm/@smithy+property-provider@4.0.5/node_modules/@smithy/property-provider/dist-es/ProviderError.js
U7VZULNU_cjs.init_cjs_shims();
var ProviderError = class _ProviderError extends Error {
  static {
    U7VZULNU_cjs.__name(this, "ProviderError");
  }
  constructor(message, options = true) {
    let logger;
    let tryNextLink = true;
    if (typeof options === "boolean") {
      logger = void 0;
      tryNextLink = options;
    } else if (options != null && typeof options === "object") {
      logger = options.logger;
      tryNextLink = options.tryNextLink ?? true;
    }
    super(message);
    this.name = "ProviderError";
    this.tryNextLink = tryNextLink;
    Object.setPrototypeOf(this, _ProviderError.prototype);
    logger?.debug?.(`@smithy/property-provider ${tryNextLink ? "->" : "(!)"} ${message}`);
  }
  static from(error, options = true) {
    return Object.assign(new this(error.message, options), error);
  }
};

// ../../node_modules/.pnpm/@smithy+property-provider@4.0.5/node_modules/@smithy/property-provider/dist-es/CredentialsProviderError.js
U7VZULNU_cjs.init_cjs_shims();
var CredentialsProviderError = class _CredentialsProviderError extends ProviderError {
  static {
    U7VZULNU_cjs.__name(this, "CredentialsProviderError");
  }
  constructor(message, options = true) {
    super(message, options);
    this.name = "CredentialsProviderError";
    Object.setPrototypeOf(this, _CredentialsProviderError.prototype);
  }
};

// ../../node_modules/.pnpm/@smithy+property-provider@4.0.5/node_modules/@smithy/property-provider/dist-es/index.js
U7VZULNU_cjs.init_cjs_shims();

// ../../node_modules/.pnpm/@smithy+property-provider@4.0.5/node_modules/@smithy/property-provider/dist-es/TokenProviderError.js
U7VZULNU_cjs.init_cjs_shims();
var TokenProviderError = class _TokenProviderError extends ProviderError {
  static {
    U7VZULNU_cjs.__name(this, "TokenProviderError");
  }
  constructor(message, options = true) {
    super(message, options);
    this.name = "TokenProviderError";
    Object.setPrototypeOf(this, _TokenProviderError.prototype);
  }
};

// ../../node_modules/.pnpm/@smithy+property-provider@4.0.5/node_modules/@smithy/property-provider/dist-es/chain.js
U7VZULNU_cjs.init_cjs_shims();
var chain = /* @__PURE__ */ U7VZULNU_cjs.__name((...providers) => async () => {
  if (providers.length === 0) {
    throw new ProviderError("No providers in chain");
  }
  let lastProviderError;
  for (const provider of providers) {
    try {
      const credentials = await provider();
      return credentials;
    } catch (err) {
      lastProviderError = err;
      if (err?.tryNextLink) {
        continue;
      }
      throw err;
    }
  }
  throw lastProviderError;
}, "chain");

// ../../node_modules/.pnpm/@smithy+property-provider@4.0.5/node_modules/@smithy/property-provider/dist-es/fromStatic.js
U7VZULNU_cjs.init_cjs_shims();
var fromStatic = /* @__PURE__ */ U7VZULNU_cjs.__name((staticValue) => () => Promise.resolve(staticValue), "fromStatic");

// ../../node_modules/.pnpm/@smithy+property-provider@4.0.5/node_modules/@smithy/property-provider/dist-es/memoize.js
U7VZULNU_cjs.init_cjs_shims();
var memoize = /* @__PURE__ */ U7VZULNU_cjs.__name((provider, isExpired, requiresRefresh) => {
  let resolved;
  let pending;
  let hasResult;
  let isConstant = false;
  const coalesceProvider = /* @__PURE__ */ U7VZULNU_cjs.__name(async () => {
    if (!pending) {
      pending = provider();
    }
    try {
      resolved = await pending;
      hasResult = true;
      isConstant = false;
    } finally {
      pending = void 0;
    }
    return resolved;
  }, "coalesceProvider");
  if (isExpired === void 0) {
    return async (options) => {
      if (!hasResult || options?.forceRefresh) {
        resolved = await coalesceProvider();
      }
      return resolved;
    };
  }
  return async (options) => {
    if (!hasResult || options?.forceRefresh) {
      resolved = await coalesceProvider();
    }
    if (isConstant) {
      return resolved;
    }
    if (requiresRefresh && !requiresRefresh(resolved)) {
      isConstant = true;
      return resolved;
    }
    if (isExpired(resolved)) {
      await coalesceProvider();
      return resolved;
    }
    return resolved;
  };
}, "memoize");

exports.CredentialsProviderError = CredentialsProviderError;
exports.ProviderError = ProviderError;
exports.TokenProviderError = TokenProviderError;
exports.chain = chain;
exports.fromStatic = fromStatic;
exports.memoize = memoize;
//# sourceMappingURL=JGLHYXTW.cjs.map
//# sourceMappingURL=JGLHYXTW.cjs.map