Skip to content

Commit 916fef1

Browse files
committed
fix(middleware-endpoint): fix for resolving file/env endpoint
1 parent 437f58f commit 916fef1

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

.changeset/fifty-news-serve.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@smithy/middleware-endpoint": patch
3+
---
4+
5+
fix resolving file/env configured endpoint
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { describe, expect, test as it, vi } from "vitest";
2+
import { getEndpointFromInstructions } from "./getEndpointFromInstructions";
3+
4+
describe(getEndpointFromInstructions.name, () => {
5+
it("should set the isCustomEndpoint flag after resolving an externally configured endpoint", async () => {
6+
process.env.AWS_ENDPOINT_URL = "https://localhost";
7+
8+
const config = {
9+
serviceId: "service id",
10+
isCustomEndpoint: false,
11+
endpointProvider: vi.fn(),
12+
};
13+
14+
await getEndpointFromInstructions(
15+
{},
16+
{
17+
getEndpointParameterInstructions() {
18+
return {};
19+
},
20+
},
21+
config
22+
);
23+
24+
expect(config.isCustomEndpoint).toBe(true);
25+
});
26+
27+
it("should not use externally configured endpoint if code-level endpoint was set", async () => {
28+
process.env.AWS_ENDPOINT_URL = "https://localhost";
29+
30+
const config = {
31+
serviceId: "service id",
32+
isCustomEndpoint: true,
33+
endpointProvider: vi.fn().mockReturnValue(Symbol.for("endpoint")),
34+
};
35+
36+
const endpoint = await getEndpointFromInstructions(
37+
{},
38+
{
39+
getEndpointParameterInstructions() {
40+
return {};
41+
},
42+
},
43+
config
44+
);
45+
46+
expect(config.isCustomEndpoint).toBe(true);
47+
expect(endpoint).toBe(Symbol.for("endpoint"));
48+
});
49+
});

packages/middleware-endpoint/src/adaptors/getEndpointFromInstructions.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export type EndpointParameterInstructionsSupplier = Partial<{
3131
export const getEndpointFromInstructions = async <
3232
T extends EndpointParameters,
3333
CommandInput extends Record<string, unknown>,
34-
Config extends Record<string, unknown>,
34+
Config extends Record<string, unknown>
3535
>(
3636
commandInput: CommandInput,
3737
instructionsSupplier: EndpointParameterInstructionsSupplier,
@@ -52,6 +52,7 @@ export const getEndpointFromInstructions = async <
5252

5353
if (endpointFromConfig) {
5454
clientConfig.endpoint = () => Promise.resolve(toEndpointV1(endpointFromConfig!));
55+
clientConfig.isCustomEndpoint = true;
5556
}
5657
}
5758

@@ -71,7 +72,7 @@ export const getEndpointFromInstructions = async <
7172
export const resolveParams = async <
7273
T extends EndpointParameters,
7374
CommandInput extends Record<string, unknown>,
74-
Config extends Record<string, unknown>,
75+
Config extends Record<string, unknown>
7576
>(
7677
commandInput: CommandInput,
7778
instructionsSupplier: EndpointParameterInstructionsSupplier,

0 commit comments

Comments
 (0)