@smithy/property-provider 2.0.4 → 2.0.6

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-cjs/chain.js CHANGED
@@ -2,18 +2,24 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.chain = void 0;
4
4
  const ProviderError_1 = require("./ProviderError");
5
- function chain(...providers) {
6
- return () => {
7
- let promise = Promise.reject(new ProviderError_1.ProviderError("No providers in chain"));
8
- for (const provider of providers) {
9
- promise = promise.catch((err) => {
10
- if (err === null || err === void 0 ? void 0 : err.tryNextLink) {
11
- return provider();
12
- }
13
- throw err;
14
- });
5
+ const chain = (...providers) => async () => {
6
+ if (providers.length === 0) {
7
+ throw new ProviderError_1.ProviderError("No providers in chain");
8
+ }
9
+ let lastProviderError;
10
+ for (const provider of providers) {
11
+ try {
12
+ const credentials = await provider();
13
+ return credentials;
15
14
  }
16
- return promise;
17
- };
18
- }
15
+ catch (err) {
16
+ lastProviderError = err;
17
+ if (err === null || err === void 0 ? void 0 : err.tryNextLink) {
18
+ continue;
19
+ }
20
+ throw err;
21
+ }
22
+ }
23
+ throw lastProviderError;
24
+ };
19
25
  exports.chain = chain;
package/dist-es/chain.js CHANGED
@@ -1,15 +1,21 @@
1
1
  import { ProviderError } from "./ProviderError";
2
- export function chain(...providers) {
3
- return () => {
4
- let promise = Promise.reject(new ProviderError("No providers in chain"));
5
- for (const provider of providers) {
6
- promise = promise.catch((err) => {
7
- if (err?.tryNextLink) {
8
- return provider();
9
- }
10
- throw err;
11
- });
2
+ export const chain = (...providers) => async () => {
3
+ if (providers.length === 0) {
4
+ throw new ProviderError("No providers in chain");
5
+ }
6
+ let lastProviderError;
7
+ for (const provider of providers) {
8
+ try {
9
+ const credentials = await provider();
10
+ return credentials;
12
11
  }
13
- return promise;
14
- };
15
- }
12
+ catch (err) {
13
+ lastProviderError = err;
14
+ if (err?.tryNextLink) {
15
+ continue;
16
+ }
17
+ throw err;
18
+ }
19
+ }
20
+ throw lastProviderError;
21
+ };
@@ -10,4 +10,4 @@ import { Provider } from "@smithy/types";
10
10
  * If no providers were received or no provider resolves successfully, the
11
11
  * returned promise will be rejected.
12
12
  */
13
- export declare function chain<T>(...providers: Array<Provider<T>>): Provider<T>;
13
+ export declare const chain: <T>(...providers: Provider<T>[]) => Provider<T>;
@@ -10,4 +10,4 @@ import { Provider } from "@smithy/types";
10
10
  * If no providers were received or no provider resolves successfully, the
11
11
  * returned promise will be rejected.
12
12
  */
13
- export declare function chain<T>(...providers: Array<Provider<T>>): Provider<T>;
13
+ export declare const chain: <T>(...providers: Provider<T>[]) => Provider<T>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smithy/property-provider",
3
- "version": "2.0.4",
3
+ "version": "2.0.6",
4
4
  "scripts": {
5
5
  "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types && yarn build:types:downlevel'",
6
6
  "build:cjs": "tsc -p tsconfig.cjs.json",
@@ -22,7 +22,7 @@
22
22
  },
23
23
  "license": "Apache-2.0",
24
24
  "dependencies": {
25
- "@smithy/types": "^2.2.1",
25
+ "@smithy/types": "^2.2.2",
26
26
  "tslib": "^2.5.0"
27
27
  },
28
28
  "engines": {