|
| 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 | +}; |
0 commit comments