@aws-sdk/middleware-endpoint-discovery 3.32.0 → 3.36.0
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/CHANGELOG.md +38 -0
- package/dist-cjs/configurations.js +30 -0
- package/dist-cjs/endpointDiscoveryMiddleware.js +48 -0
- package/dist-cjs/getCacheKey.js +17 -0
- package/dist-cjs/getEndpointDiscoveryPlugin.js +28 -0
- package/dist-cjs/index.js +6 -0
- package/dist-cjs/resolveEndpointDiscoveryConfig.js +17 -0
- package/dist-cjs/updateDiscoveredEndpointInCache.js +64 -0
- package/dist-es/configurations.js +27 -0
- package/dist-es/endpointDiscoveryMiddleware.js +54 -0
- package/dist-es/getCacheKey.js +22 -0
- package/dist-es/getEndpointDiscoveryPlugin.js +23 -0
- package/{dist/types/index.d.ts → dist-es/index.js} +0 -0
- package/dist-es/resolveEndpointDiscoveryConfig.js +9 -0
- package/dist-es/updateDiscoveredEndpointInCache.js +67 -0
- package/{dist/types → dist-types}/configurations.d.ts +0 -0
- package/{dist/types → dist-types}/endpointDiscoveryMiddleware.d.ts +0 -0
- package/{dist/types → dist-types}/getCacheKey.d.ts +0 -0
- package/{dist/types → dist-types}/getEndpointDiscoveryPlugin.d.ts +0 -0
- package/{src/index.ts → dist-types/index.d.ts} +0 -0
- package/{dist/types → dist-types}/resolveEndpointDiscoveryConfig.d.ts +0 -0
- package/{dist/types → dist-types}/ts3.4/configurations.d.ts +0 -0
- package/{dist/types → dist-types}/ts3.4/endpointDiscoveryMiddleware.d.ts +0 -0
- package/{dist/types → dist-types}/ts3.4/getCacheKey.d.ts +0 -0
- package/{dist/types → dist-types}/ts3.4/getEndpointDiscoveryPlugin.d.ts +0 -0
- package/{dist/types → dist-types}/ts3.4/index.d.ts +0 -0
- package/{dist/types → dist-types}/ts3.4/resolveEndpointDiscoveryConfig.d.ts +0 -0
- package/{dist/types → dist-types}/ts3.4/updateDiscoveredEndpointInCache.d.ts +0 -0
- package/{dist/types → dist-types}/updateDiscoveredEndpointInCache.d.ts +0 -0
- package/package.json +17 -13
- package/dist/cjs/configurations.js +0 -32
- package/dist/cjs/endpointDiscoveryMiddleware.js +0 -55
- package/dist/cjs/getCacheKey.js +0 -21
- package/dist/cjs/getEndpointDiscoveryPlugin.js +0 -35
- package/dist/cjs/index.js +0 -7
- package/dist/cjs/resolveEndpointDiscoveryConfig.js +0 -18
- package/dist/cjs/updateDiscoveredEndpointInCache.js +0 -74
- package/dist/es/configurations.js +0 -29
- package/dist/es/endpointDiscoveryMiddleware.js +0 -63
- package/dist/es/getCacheKey.js +0 -26
- package/dist/es/getEndpointDiscoveryPlugin.js +0 -30
- package/dist/es/index.js +0 -4
- package/dist/es/resolveEndpointDiscoveryConfig.js +0 -10
- package/dist/es/updateDiscoveredEndpointInCache.js +0 -77
- package/dist/tsconfig.cjs.tsbuildinfo +0 -1
- package/dist/tsconfig.es.tsbuildinfo +0 -1
- package/jest.config.js +0 -5
- package/src/configurations.spec.ts +0 -85
- package/src/configurations.ts +0 -32
- package/src/endpointDiscoveryMiddleware.spec.ts +0 -145
- package/src/endpointDiscoveryMiddleware.ts +0 -72
- package/src/getCacheKey.spec.ts +0 -32
- package/src/getCacheKey.ts +0 -24
- package/src/getEndpointDiscoveryPlugin.spec.ts +0 -32
- package/src/getEndpointDiscoveryPlugin.ts +0 -57
- package/src/resolveEndpointDiscoveryConfig.spec.ts +0 -63
- package/src/resolveEndpointDiscoveryConfig.ts +0 -73
- package/src/updateDiscoveredEndpointInCache.spec.ts +0 -172
- package/src/updateDiscoveredEndpointInCache.ts +0 -88
- package/tsconfig.cjs.json +0 -10
- package/tsconfig.es.json +0 -11
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { EndpointCache } from "@aws-sdk/endpoint-cache";
|
|
2
|
-
|
|
3
|
-
import { resolveEndpointDiscoveryConfig } from "./resolveEndpointDiscoveryConfig";
|
|
4
|
-
|
|
5
|
-
jest.mock("@aws-sdk/endpoint-cache");
|
|
6
|
-
|
|
7
|
-
describe(resolveEndpointDiscoveryConfig.name, () => {
|
|
8
|
-
const endpointDiscoveryCommandCtor = jest.fn();
|
|
9
|
-
const mockInput = {
|
|
10
|
-
isCustomEndpoint: false,
|
|
11
|
-
credentials: jest.fn(),
|
|
12
|
-
endpointDiscoveryEnabledProvider: jest.fn(),
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
afterEach(() => {
|
|
16
|
-
jest.clearAllMocks();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it("assigns endpointDiscoveryCommandCtor in resolvedConfig", () => {
|
|
20
|
-
const resolvedConfig = resolveEndpointDiscoveryConfig(mockInput, { endpointDiscoveryCommandCtor });
|
|
21
|
-
expect(resolvedConfig.endpointDiscoveryCommandCtor).toStrictEqual(endpointDiscoveryCommandCtor);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
describe("endpointCache", () => {
|
|
25
|
-
it("creates cache of size endpointCacheSize if passed", () => {
|
|
26
|
-
const endpointCacheSize = 100;
|
|
27
|
-
resolveEndpointDiscoveryConfig(
|
|
28
|
-
{
|
|
29
|
-
...mockInput,
|
|
30
|
-
endpointCacheSize,
|
|
31
|
-
},
|
|
32
|
-
{ endpointDiscoveryCommandCtor }
|
|
33
|
-
);
|
|
34
|
-
expect(EndpointCache).toBeCalledWith(endpointCacheSize);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it("creates cache of size 1000 if endpointCacheSize not passed", () => {
|
|
38
|
-
resolveEndpointDiscoveryConfig(mockInput, { endpointDiscoveryCommandCtor });
|
|
39
|
-
expect(EndpointCache).toBeCalledWith(1000);
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
describe("endpointDiscoveryEnabled", () => {
|
|
44
|
-
it.each<boolean>([false, true])(`sets to value passed in the config: %s`, (endpointDiscoveryEnabled) => {
|
|
45
|
-
const resolvedConfig = resolveEndpointDiscoveryConfig(
|
|
46
|
-
{
|
|
47
|
-
...mockInput,
|
|
48
|
-
endpointDiscoveryEnabled,
|
|
49
|
-
},
|
|
50
|
-
{ endpointDiscoveryCommandCtor }
|
|
51
|
-
);
|
|
52
|
-
expect(resolvedConfig.endpointDiscoveryEnabled()).resolves.toBe(endpointDiscoveryEnabled);
|
|
53
|
-
expect(mockInput.endpointDiscoveryEnabledProvider).not.toHaveBeenCalled();
|
|
54
|
-
expect(resolvedConfig.isClientEndpointDiscoveryEnabled).toStrictEqual(true);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it(`sets to endpointDiscoveryEnabledProvider if value is not passed`, () => {
|
|
58
|
-
const resolvedConfig = resolveEndpointDiscoveryConfig(mockInput, { endpointDiscoveryCommandCtor });
|
|
59
|
-
expect(resolvedConfig.endpointDiscoveryEnabled).toBe(mockInput.endpointDiscoveryEnabledProvider);
|
|
60
|
-
expect(resolvedConfig.isClientEndpointDiscoveryEnabled).toStrictEqual(false);
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
});
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { EndpointCache } from "@aws-sdk/endpoint-cache";
|
|
2
|
-
import { Credentials, Provider } from "@aws-sdk/types";
|
|
3
|
-
|
|
4
|
-
export interface EndpointDiscoveryInputConfig {}
|
|
5
|
-
|
|
6
|
-
export interface PreviouslyResolved {
|
|
7
|
-
isCustomEndpoint: boolean;
|
|
8
|
-
credentials: Provider<Credentials>;
|
|
9
|
-
endpointDiscoveryEnabledProvider: Provider<boolean | undefined>;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface EndpointDiscoveryInputConfig {
|
|
13
|
-
/**
|
|
14
|
-
* The size of the client cache storing endpoints from endpoint discovery operations.
|
|
15
|
-
* Defaults to 1000.
|
|
16
|
-
*/
|
|
17
|
-
endpointCacheSize?: number;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Whether to call operations with endpoints given by service dynamically.
|
|
21
|
-
* Setting this config to `true` will enable endpoint discovery for all applicable operations.
|
|
22
|
-
* Setting it to `false` will explicitly disable endpoint discovery even though operations that
|
|
23
|
-
* require endpoint discovery will presumably fail. Leaving it to undefined means SDK only do
|
|
24
|
-
* endpoint discovery when it's required. Defaults to `undefined`.
|
|
25
|
-
*/
|
|
26
|
-
endpointDiscoveryEnabled?: boolean | undefined;
|
|
27
|
-
}
|
|
28
|
-
export interface EndpointDiscoveryResolvedConfig {
|
|
29
|
-
/**
|
|
30
|
-
* LRU Cache which stores endpoints from endpoint discovery operations.
|
|
31
|
-
* The size is either provided by {@link EndpointDiscoveryInputConfig.endpointCacheSize}.
|
|
32
|
-
*/
|
|
33
|
-
endpointCache: EndpointCache;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* The constructor of the Command used for discovering endpoints.
|
|
37
|
-
* @internal
|
|
38
|
-
*/
|
|
39
|
-
endpointDiscoveryCommandCtor: new (comandConfig: any) => any;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Resolved value for input config {@link EndpointDiscoveryInputConfig.endpointDiscoveryEnabled}.
|
|
43
|
-
*/
|
|
44
|
-
endpointDiscoveryEnabled: Provider<boolean | undefined>;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Stores whether endpoint discovery configuration is set locally by passing
|
|
48
|
-
* {@link EndpointDiscoveryInputConfig.endpointDiscoveryEnabled} during client creation.
|
|
49
|
-
* @internal
|
|
50
|
-
*/
|
|
51
|
-
isClientEndpointDiscoveryEnabled: boolean;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export interface EndpointDiscoveryConfigOptions {
|
|
55
|
-
/**
|
|
56
|
-
* The constructor of the Command used for discovering endpoints.
|
|
57
|
-
*/
|
|
58
|
-
endpointDiscoveryCommandCtor: new (comandConfig: any) => any;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export const resolveEndpointDiscoveryConfig = <T>(
|
|
62
|
-
input: T & PreviouslyResolved & EndpointDiscoveryInputConfig,
|
|
63
|
-
{ endpointDiscoveryCommandCtor }: EndpointDiscoveryConfigOptions
|
|
64
|
-
): T & EndpointDiscoveryResolvedConfig => ({
|
|
65
|
-
...input,
|
|
66
|
-
endpointDiscoveryCommandCtor,
|
|
67
|
-
endpointCache: new EndpointCache(input.endpointCacheSize ?? 1000),
|
|
68
|
-
endpointDiscoveryEnabled:
|
|
69
|
-
input.endpointDiscoveryEnabled !== undefined
|
|
70
|
-
? () => Promise.resolve(input.endpointDiscoveryEnabled)
|
|
71
|
-
: input.endpointDiscoveryEnabledProvider,
|
|
72
|
-
isClientEndpointDiscoveryEnabled: input.endpointDiscoveryEnabled !== undefined,
|
|
73
|
-
});
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import { updateDiscoveredEndpointInCache } from "./updateDiscoveredEndpointInCache";
|
|
2
|
-
|
|
3
|
-
describe(updateDiscoveredEndpointInCache.name, () => {
|
|
4
|
-
const cacheKey = "cacheKey";
|
|
5
|
-
const mockGet = jest.fn();
|
|
6
|
-
const mockSet = jest.fn();
|
|
7
|
-
const mockDelete = jest.fn();
|
|
8
|
-
|
|
9
|
-
const mockHandler = jest.fn();
|
|
10
|
-
const mockResolveMiddleware = jest.fn().mockReturnValue(mockHandler);
|
|
11
|
-
|
|
12
|
-
const mockEndpoints = [{ Address: "mockAddress", CachePeriodInMinutes: 2 }];
|
|
13
|
-
const placeholderEndpoints = [{ Address: "", CachePeriodInMinutes: 1 }];
|
|
14
|
-
|
|
15
|
-
const config = {
|
|
16
|
-
endpointCache: { get: mockGet, set: mockSet, delete: mockDelete },
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const options = {
|
|
20
|
-
cacheKey,
|
|
21
|
-
commandName: "ExampleCommand",
|
|
22
|
-
endpointDiscoveryCommandCtor: jest.fn().mockReturnValue({ resolveMiddleware: mockResolveMiddleware }),
|
|
23
|
-
isDiscoveredEndpointRequired: false,
|
|
24
|
-
identifiers: { key: "value" },
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
beforeEach(() => {
|
|
28
|
-
mockGet.mockReturnValue(mockEndpoints);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
afterEach(() => {
|
|
32
|
-
jest.clearAllMocks();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it(`returns if endpoints are present in cacheKey`, async () => {
|
|
36
|
-
// @ts-ignore
|
|
37
|
-
await updateDiscoveredEndpointInCache(config, options);
|
|
38
|
-
expect(mockGet).toHaveBeenCalledWith(cacheKey);
|
|
39
|
-
expect(mockSet).not.toHaveBeenCalled();
|
|
40
|
-
expect(mockDelete).not.toHaveBeenCalled();
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
describe("calls endpointDiscoveryCommandCtor", () => {
|
|
44
|
-
beforeEach(() => {
|
|
45
|
-
mockGet.mockReturnValue(undefined);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
const verifyCallsOnCacheUndefined = () => {
|
|
49
|
-
expect(mockGet).toHaveBeenCalledTimes(1);
|
|
50
|
-
|
|
51
|
-
expect(options.endpointDiscoveryCommandCtor).toHaveBeenCalledWith({
|
|
52
|
-
Operation: options.commandName.substr(0, options.commandName.length - 7),
|
|
53
|
-
Identifiers: options.identifiers,
|
|
54
|
-
});
|
|
55
|
-
expect(mockHandler).toHaveBeenCalledTimes(1);
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
it("on successful call: updates cache", async () => {
|
|
59
|
-
mockHandler.mockResolvedValueOnce({ output: { Endpoints: mockEndpoints } });
|
|
60
|
-
|
|
61
|
-
// @ts-ignore
|
|
62
|
-
await updateDiscoveredEndpointInCache(config, options);
|
|
63
|
-
|
|
64
|
-
verifyCallsOnCacheUndefined();
|
|
65
|
-
expect(mockDelete).not.toHaveBeenCalled();
|
|
66
|
-
expect(mockSet).toHaveBeenCalledTimes(2);
|
|
67
|
-
expect(mockSet).toHaveBeenNthCalledWith(1, cacheKey, placeholderEndpoints);
|
|
68
|
-
expect(mockSet).toHaveBeenNthCalledWith(2, cacheKey, mockEndpoints);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it("calls endpointDiscoveryCommandCtor command just once in case of parallel calls", async () => {
|
|
72
|
-
mockHandler.mockResolvedValueOnce({ output: { Endpoints: mockEndpoints } });
|
|
73
|
-
// First call returns undefined, while other ones return placeholder endpoints a call is in progress
|
|
74
|
-
mockGet
|
|
75
|
-
.mockReturnValueOnce(undefined)
|
|
76
|
-
.mockReturnValueOnce(placeholderEndpoints)
|
|
77
|
-
.mockReturnValueOnce(placeholderEndpoints);
|
|
78
|
-
|
|
79
|
-
await Promise.all([
|
|
80
|
-
// @ts-ignore
|
|
81
|
-
updateDiscoveredEndpointInCache(config, options),
|
|
82
|
-
// @ts-ignore
|
|
83
|
-
updateDiscoveredEndpointInCache(config, options),
|
|
84
|
-
// @ts-ignore
|
|
85
|
-
updateDiscoveredEndpointInCache(config, options),
|
|
86
|
-
]);
|
|
87
|
-
|
|
88
|
-
expect(mockGet).toHaveBeenCalledTimes(3);
|
|
89
|
-
|
|
90
|
-
expect(options.endpointDiscoveryCommandCtor).toHaveBeenCalledWith({
|
|
91
|
-
Operation: options.commandName.substr(0, options.commandName.length - 7),
|
|
92
|
-
Identifiers: options.identifiers,
|
|
93
|
-
});
|
|
94
|
-
expect(mockHandler).toHaveBeenCalledTimes(1);
|
|
95
|
-
|
|
96
|
-
expect(mockDelete).not.toHaveBeenCalled();
|
|
97
|
-
expect(mockSet).toHaveBeenCalledTimes(2);
|
|
98
|
-
expect(mockSet).toHaveBeenNthCalledWith(1, cacheKey, placeholderEndpoints);
|
|
99
|
-
expect(mockSet).toHaveBeenNthCalledWith(2, cacheKey, mockEndpoints);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
describe("on error", () => {
|
|
103
|
-
it(`throws if isDiscoveredEndpointRequired=true`, async () => {
|
|
104
|
-
const error = new Error("rejected");
|
|
105
|
-
mockHandler.mockRejectedValueOnce(error);
|
|
106
|
-
|
|
107
|
-
try {
|
|
108
|
-
// @ts-ignore
|
|
109
|
-
await updateDiscoveredEndpointInCache(config, { ...options, isDiscoveredEndpointRequired: true });
|
|
110
|
-
fail("updateDiscoveredEndpointInCache should throw");
|
|
111
|
-
} catch (error) {
|
|
112
|
-
expect(error).toEqual(
|
|
113
|
-
Object.assign(
|
|
114
|
-
new Error(
|
|
115
|
-
`The operation to discover endpoint failed.` +
|
|
116
|
-
` Please retry, or provide a custom endpoint and disable endpoint discovery to proceed.`
|
|
117
|
-
),
|
|
118
|
-
{ reason: error }
|
|
119
|
-
)
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
verifyCallsOnCacheUndefined();
|
|
123
|
-
expect(mockDelete).not.toHaveBeenCalled();
|
|
124
|
-
expect(mockSet).toHaveBeenCalledTimes(1);
|
|
125
|
-
expect(mockSet).toHaveBeenCalledWith(cacheKey, placeholderEndpoints);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it(`sets placeholder enpoint if isDiscoveredEndpointRequired=false`, async () => {
|
|
129
|
-
const error = new Error("rejected");
|
|
130
|
-
mockHandler.mockRejectedValueOnce(error);
|
|
131
|
-
|
|
132
|
-
// @ts-ignore
|
|
133
|
-
await updateDiscoveredEndpointInCache(config, options);
|
|
134
|
-
|
|
135
|
-
verifyCallsOnCacheUndefined();
|
|
136
|
-
expect(mockDelete).not.toHaveBeenCalled();
|
|
137
|
-
expect(mockSet).toHaveBeenCalledTimes(2);
|
|
138
|
-
expect(mockSet).toHaveBeenNthCalledWith(1, cacheKey, placeholderEndpoints);
|
|
139
|
-
expect(mockSet).toHaveBeenNthCalledWith(2, cacheKey, placeholderEndpoints);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
describe(`deletes cacheKey in case of`, () => {
|
|
143
|
-
const verifyCallsOnCacheKeyDelete = () => {
|
|
144
|
-
expect(mockDelete).toHaveBeenCalledWith(cacheKey);
|
|
145
|
-
expect(mockSet).toHaveBeenCalledTimes(2);
|
|
146
|
-
expect(mockSet).toHaveBeenNthCalledWith(1, cacheKey, placeholderEndpoints);
|
|
147
|
-
expect(mockSet).toHaveBeenNthCalledWith(2, cacheKey, placeholderEndpoints);
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
it(`InvalidEndpointException`, async () => {
|
|
151
|
-
const error = Object.assign(new Error("Invalid endpoint!"), { name: "InvalidEndpointException" });
|
|
152
|
-
mockHandler.mockRejectedValueOnce(error);
|
|
153
|
-
|
|
154
|
-
// @ts-ignore
|
|
155
|
-
await updateDiscoveredEndpointInCache(config, options);
|
|
156
|
-
verifyCallsOnCacheUndefined();
|
|
157
|
-
verifyCallsOnCacheKeyDelete();
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
it(`Status code: 421`, async () => {
|
|
161
|
-
const error = Object.assign(new Error("Invalid endpoint!"), { $metadata: { httpStatusCode: 421 } });
|
|
162
|
-
mockHandler.mockRejectedValueOnce(error);
|
|
163
|
-
|
|
164
|
-
// @ts-ignore
|
|
165
|
-
await updateDiscoveredEndpointInCache(config, options);
|
|
166
|
-
verifyCallsOnCacheUndefined();
|
|
167
|
-
verifyCallsOnCacheKeyDelete();
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
});
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { EndpointDiscoveryMiddlewareConfig } from "./getEndpointDiscoveryPlugin";
|
|
2
|
-
import { EndpointDiscoveryResolvedConfig, PreviouslyResolved } from "./resolveEndpointDiscoveryConfig";
|
|
3
|
-
|
|
4
|
-
export interface UpdateDiscoveredEndpointInCacheOptions extends EndpointDiscoveryMiddlewareConfig {
|
|
5
|
-
cacheKey: string;
|
|
6
|
-
commandName: string;
|
|
7
|
-
endpointDiscoveryCommandCtor: new (comandConfig: any) => any;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const requestQueue: { [key: string]: { resolve: Function; reject: Function }[] } = {};
|
|
11
|
-
|
|
12
|
-
export const updateDiscoveredEndpointInCache = async (
|
|
13
|
-
config: EndpointDiscoveryResolvedConfig & PreviouslyResolved,
|
|
14
|
-
options: UpdateDiscoveredEndpointInCacheOptions
|
|
15
|
-
) =>
|
|
16
|
-
new Promise<void>((resolve, reject) => {
|
|
17
|
-
const { endpointCache } = config;
|
|
18
|
-
const { cacheKey, commandName, identifiers } = options;
|
|
19
|
-
|
|
20
|
-
const endpoints = endpointCache.get(cacheKey);
|
|
21
|
-
|
|
22
|
-
if (endpoints && endpoints.length === 1 && endpoints[0].Address === "") {
|
|
23
|
-
// Endpoint operation already in-flight.
|
|
24
|
-
// Add request to request queue only if discovered endpoint is required.
|
|
25
|
-
if (options.isDiscoveredEndpointRequired) {
|
|
26
|
-
if (!requestQueue[cacheKey]) requestQueue[cacheKey] = [];
|
|
27
|
-
requestQueue[cacheKey].push({ resolve, reject });
|
|
28
|
-
} else {
|
|
29
|
-
resolve();
|
|
30
|
-
}
|
|
31
|
-
} else if (endpoints && endpoints.length > 0) {
|
|
32
|
-
// Endpoint record is present in cache.
|
|
33
|
-
resolve();
|
|
34
|
-
} else {
|
|
35
|
-
// put in a placeholder for endpoints already requested, prevent
|
|
36
|
-
// too much in-flight calls.
|
|
37
|
-
const placeholderEndpoints = [{ Address: "", CachePeriodInMinutes: 1 }];
|
|
38
|
-
endpointCache.set(cacheKey, placeholderEndpoints);
|
|
39
|
-
|
|
40
|
-
const command = new options.endpointDiscoveryCommandCtor({
|
|
41
|
-
Operation: commandName.substr(0, commandName.length - 7), // strip "Command"
|
|
42
|
-
Identifiers: identifiers,
|
|
43
|
-
});
|
|
44
|
-
const handler = command.resolveMiddleware(options.clientStack, config, options.options);
|
|
45
|
-
handler(command)
|
|
46
|
-
.then((result: any) => {
|
|
47
|
-
endpointCache.set(cacheKey, result.output.Endpoints);
|
|
48
|
-
if (requestQueue[cacheKey]) {
|
|
49
|
-
requestQueue[cacheKey].forEach(({ resolve }) => {
|
|
50
|
-
resolve();
|
|
51
|
-
});
|
|
52
|
-
delete requestQueue[cacheKey];
|
|
53
|
-
}
|
|
54
|
-
resolve();
|
|
55
|
-
})
|
|
56
|
-
.catch((error: any) => {
|
|
57
|
-
if (error.name === "InvalidEndpointException" || error.$metadata?.httpStatusCode === 421) {
|
|
58
|
-
// Endpoint is invalid, delete the cache entry.
|
|
59
|
-
endpointCache.delete(cacheKey);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const errorToThrow = Object.assign(
|
|
63
|
-
new Error(
|
|
64
|
-
`The operation to discover endpoint failed.` +
|
|
65
|
-
` Please retry, or provide a custom endpoint and disable endpoint discovery to proceed.`
|
|
66
|
-
),
|
|
67
|
-
{ reason: error }
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
//fail all the pending requests in batch
|
|
71
|
-
if (requestQueue[cacheKey]) {
|
|
72
|
-
requestQueue[cacheKey].forEach(({ reject }) => {
|
|
73
|
-
reject(errorToThrow);
|
|
74
|
-
});
|
|
75
|
-
delete requestQueue[cacheKey];
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (options.isDiscoveredEndpointRequired) {
|
|
79
|
-
reject(errorToThrow);
|
|
80
|
-
} else {
|
|
81
|
-
// Endpoint Discovery is optional. No error needs to be thrown.
|
|
82
|
-
// Set placeHolder endpoint to disable refresh for one minute.
|
|
83
|
-
endpointCache.set(cacheKey, placeholderEndpoints);
|
|
84
|
-
resolve();
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
});
|
package/tsconfig.cjs.json
DELETED
package/tsconfig.es.json
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"lib": ["es5", "es2015.promise", "es2015.collection", "es2015.iterable", "es2015.symbol.wellknown"],
|
|
4
|
-
"declarationDir": "./dist/types",
|
|
5
|
-
"rootDir": "./src",
|
|
6
|
-
"outDir": "./dist/es",
|
|
7
|
-
"baseUrl": "."
|
|
8
|
-
},
|
|
9
|
-
"extends": "../../tsconfig.es.json",
|
|
10
|
-
"include": ["src/"]
|
|
11
|
-
}
|