Skip to content

Commit 2d20f69

Browse files
committed
chore(config-resolver): refactor EndpointsConfig for non AWS services
This reverts an earlier change to EndpointsConfig.ts and instead provides the new functionality in separate NonAwsEndpointsConfig.ts. This will be used as a separate plugin for endpoint resolution in non AWS clients.
1 parent 092d239 commit 2d20f69

File tree

3 files changed

+48
-6
lines changed

3 files changed

+48
-6
lines changed

packages/config-resolver/src/EndpointsConfig.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ export interface EndpointsInputConfig {
1313
}
1414

1515
interface PreviouslyResolved {
16-
regionInfoProvider?: RegionInfoProvider;
16+
regionInfoProvider: RegionInfoProvider;
1717
urlParser: UrlParser;
18-
region?: Provider<string>;
18+
region: Provider<string>;
1919
}
2020

2121
export interface EndpointsResolvedConfig extends Required<EndpointsInputConfig> {
@@ -45,10 +45,6 @@ const normalizeEndpoint = (input: EndpointsInputConfig & PreviouslyResolved): Pr
4545
};
4646

4747
const getEndPointFromRegion = async (input: EndpointsInputConfig & PreviouslyResolved) => {
48-
if (input.region === undefined || input.regionInfoProvider === undefined) {
49-
throw new Error("No endpoint specified and region is not defined");
50-
}
51-
5248
const { tls = true } = input;
5349
const region = await input.region();
5450

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// TODO: Create a .spec.ts for this
2+
import { Endpoint, Provider, UrlParser } from "@aws-sdk/types";
3+
4+
export interface NonAwsEndpointsInputConfig {
5+
/**
6+
* The fully qualified endpoint of the webservice.
7+
*/
8+
endpoint: string | Endpoint | Provider<Endpoint>;
9+
10+
/**
11+
* Whether TLS is enabled for requests.
12+
*/
13+
tls?: boolean;
14+
}
15+
16+
interface PreviouslyResolved {
17+
urlParser: UrlParser;
18+
}
19+
20+
export interface NonAwsEndpointsResolvedConfig extends Required<NonAwsEndpointsInputConfig> {
21+
endpoint: Provider<Endpoint>;
22+
isCustomEndpoint: boolean; // TODO: Can this be removed or some other logic depends on this?
23+
}
24+
25+
export const resolveNonAwsEndpointsConfig = <T>(
26+
input: T & NonAwsEndpointsInputConfig & PreviouslyResolved
27+
): T & NonAwsEndpointsResolvedConfig => ({
28+
...input,
29+
tls: input.tls ?? true,
30+
endpoint: normalizeEndpoint(input),
31+
isCustomEndpoint: true,
32+
});
33+
34+
// TODO: can this be shared with EndpointsConfig.ts
35+
const normalizeEndpoint = (input: NonAwsEndpointsInputConfig & PreviouslyResolved): Provider<Endpoint> => {
36+
const { endpoint, urlParser } = input;
37+
if (typeof endpoint === "string") {
38+
const promisified = Promise.resolve(urlParser(endpoint));
39+
return () => promisified;
40+
} else if (typeof endpoint === "object") {
41+
const promisified = Promise.resolve(endpoint);
42+
return () => promisified;
43+
}
44+
return endpoint;
45+
};

packages/config-resolver/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from "./EndpointsConfig";
2+
export * from "./NonAwsEndpointsConfig";
23
export * from "./RegionConfig";

0 commit comments

Comments
 (0)