Skip to content

Commit 0de968e

Browse files
committed
chore(credential-providers): unavailable browser credential providers throw at runtime
1 parent 3a82d4c commit 0de968e

File tree

3 files changed

+43
-6
lines changed

3 files changed

+43
-6
lines changed

packages/credential-providers/README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,7 @@ See [`fromSSO()`](#fromsso) fro more information
505505

506506
## `fromEnv()`
507507

508-
- Not available in browser & native apps unless your code or bundler populates the
509-
`process.env` global object.
508+
- Not available in browser & native apps
510509

511510
```javascript
512511
import { fromEnv } from "@aws-sdk/credential-providers"; // ES6 import

packages/credential-providers/src/fromEnv.ts

-3
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,5 @@ import { AwsCredentialIdentityProvider } from "@smithy/types";
2424
* credentials: fromEnv(),
2525
* });
2626
* ```
27-
*
28-
* To use this in non-Node.js environments such as a browser, your code or
29-
* build system must populate the `process.env` global object.
3027
*/
3128
export const fromEnv = (init?: FromEnvInit): AwsCredentialIdentityProvider => _fromEnv(init);

packages/credential-providers/src/index.browser.ts

+42-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,47 @@ export * from "./fromCognitoIdentity";
22
export * from "./fromCognitoIdentityPool";
33
export { fromHttp } from "@aws-sdk/credential-provider-http";
44
export type { FromHttpOptions, HttpProviderCredentials } from "@aws-sdk/credential-provider-http";
5-
export * from "./fromEnv";
65
export * from "./fromTemporaryCredentials";
76
export * from "./fromWebToken";
7+
8+
export const fromContainerMetadata = async () => {
9+
notAvailable("fromContainerMetadata");
10+
};
11+
12+
export const fromEnv = async () => {
13+
notAvailable("fromEnv");
14+
};
15+
16+
export const fromIni = async () => {
17+
notAvailable("fromIni");
18+
};
19+
20+
export const fromInstanceMetadata = async () => {
21+
notAvailable("fromInstanceMetadata");
22+
};
23+
24+
export const fromNodeProviderChain = async () => {
25+
notAvailable("fromNodeProviderChain");
26+
};
27+
28+
export const fromProcess = async () => {
29+
notAvailable("fromProcess");
30+
};
31+
32+
export const fromSSO = async () => {
33+
notAvailable("fromSSO");
34+
};
35+
36+
export const fromTokenFile = async () => {
37+
notAvailable("fromTokenFile");
38+
};
39+
40+
/**
41+
* @internal
42+
*/
43+
const notAvailable = (name: string): never => {
44+
throw new Error(
45+
`${name} is not available in the browser mode or similar environment.
46+
See https://www.npmjs.com/package/@aws-sdk/credential-providers for usage.`
47+
);
48+
};

0 commit comments

Comments
 (0)