@aws-sdk/middleware-endpoint-discovery 3.901.0 → 3.910.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/dist-cjs/index.js +170 -211
- package/package.json +5 -5
package/dist-cjs/index.js
CHANGED
|
@@ -1,229 +1,188 @@
|
|
|
1
|
-
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
'use strict';
|
|
20
2
|
|
|
21
|
-
|
|
22
|
-
var
|
|
23
|
-
__export(index_exports, {
|
|
24
|
-
NODE_ENDPOINT_DISCOVERY_CONFIG_OPTIONS: () => NODE_ENDPOINT_DISCOVERY_CONFIG_OPTIONS,
|
|
25
|
-
endpointDiscoveryMiddlewareOptions: () => endpointDiscoveryMiddlewareOptions,
|
|
26
|
-
getEndpointDiscoveryOptionalPlugin: () => getEndpointDiscoveryOptionalPlugin,
|
|
27
|
-
getEndpointDiscoveryPlugin: () => getEndpointDiscoveryPlugin,
|
|
28
|
-
getEndpointDiscoveryRequiredPlugin: () => getEndpointDiscoveryRequiredPlugin,
|
|
29
|
-
resolveEndpointDiscoveryConfig: () => resolveEndpointDiscoveryConfig
|
|
30
|
-
});
|
|
31
|
-
module.exports = __toCommonJS(index_exports);
|
|
3
|
+
var protocolHttp = require('@smithy/protocol-http');
|
|
4
|
+
var endpointCache = require('@aws-sdk/endpoint-cache');
|
|
32
5
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
6
|
+
const ENV_ENDPOINT_DISCOVERY = ["AWS_ENABLE_ENDPOINT_DISCOVERY", "AWS_ENDPOINT_DISCOVERY_ENABLED"];
|
|
7
|
+
const CONFIG_ENDPOINT_DISCOVERY = "endpoint_discovery_enabled";
|
|
8
|
+
const isFalsy = (value) => ["false", "0"].indexOf(value) >= 0;
|
|
9
|
+
const NODE_ENDPOINT_DISCOVERY_CONFIG_OPTIONS = {
|
|
10
|
+
environmentVariableSelector: (env) => {
|
|
11
|
+
for (let i = 0; i < ENV_ENDPOINT_DISCOVERY.length; i++) {
|
|
12
|
+
const envKey = ENV_ENDPOINT_DISCOVERY[i];
|
|
13
|
+
if (envKey in env) {
|
|
14
|
+
const value = env[envKey];
|
|
15
|
+
if (value === "") {
|
|
16
|
+
throw Error(`Environment variable ${envKey} can't be empty of undefined, got "${value}"`);
|
|
17
|
+
}
|
|
18
|
+
return !isFalsy(value);
|
|
19
|
+
}
|
|
45
20
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
}, "configFileSelector"),
|
|
59
|
-
default: void 0
|
|
21
|
+
},
|
|
22
|
+
configFileSelector: (profile) => {
|
|
23
|
+
if (CONFIG_ENDPOINT_DISCOVERY in profile) {
|
|
24
|
+
const value = profile[CONFIG_ENDPOINT_DISCOVERY];
|
|
25
|
+
if (value === undefined) {
|
|
26
|
+
throw Error(`Shared config entry ${CONFIG_ENDPOINT_DISCOVERY} can't be undefined, got "${value}"`);
|
|
27
|
+
}
|
|
28
|
+
return !isFalsy(value);
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
default: undefined,
|
|
60
32
|
};
|
|
61
33
|
|
|
62
|
-
|
|
63
|
-
|
|
34
|
+
const getCacheKey = async (commandName, config, options) => {
|
|
35
|
+
const { accessKeyId } = await config.credentials();
|
|
36
|
+
const { identifiers } = options;
|
|
37
|
+
return JSON.stringify({
|
|
38
|
+
...(accessKeyId && { accessKeyId }),
|
|
39
|
+
...(identifiers && {
|
|
40
|
+
commandName,
|
|
41
|
+
identifiers: Object.entries(identifiers)
|
|
42
|
+
.sort()
|
|
43
|
+
.reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {}),
|
|
44
|
+
}),
|
|
45
|
+
});
|
|
46
|
+
};
|
|
64
47
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
48
|
+
const requestQueue = {};
|
|
49
|
+
const updateDiscoveredEndpointInCache = async (config, options) => new Promise((resolve, reject) => {
|
|
50
|
+
const { endpointCache } = config;
|
|
51
|
+
const { cacheKey, commandName, identifiers } = options;
|
|
52
|
+
const endpoints = endpointCache.get(cacheKey);
|
|
53
|
+
if (endpoints && endpoints.length === 1 && endpoints[0].Address === "") {
|
|
54
|
+
if (options.isDiscoveredEndpointRequired) {
|
|
55
|
+
if (!requestQueue[cacheKey])
|
|
56
|
+
requestQueue[cacheKey] = [];
|
|
57
|
+
requestQueue[cacheKey].push({ resolve, reject });
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
resolve();
|
|
61
|
+
}
|
|
74
62
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
// src/updateDiscoveredEndpointInCache.ts
|
|
79
|
-
var requestQueue = {};
|
|
80
|
-
var updateDiscoveredEndpointInCache = /* @__PURE__ */ __name(async (config, options) => new Promise((resolve, reject) => {
|
|
81
|
-
const { endpointCache } = config;
|
|
82
|
-
const { cacheKey, commandName, identifiers } = options;
|
|
83
|
-
const endpoints = endpointCache.get(cacheKey);
|
|
84
|
-
if (endpoints && endpoints.length === 1 && endpoints[0].Address === "") {
|
|
85
|
-
if (options.isDiscoveredEndpointRequired) {
|
|
86
|
-
if (!requestQueue[cacheKey]) requestQueue[cacheKey] = [];
|
|
87
|
-
requestQueue[cacheKey].push({ resolve, reject });
|
|
88
|
-
} else {
|
|
89
|
-
resolve();
|
|
63
|
+
else if (endpoints && endpoints.length > 0) {
|
|
64
|
+
resolve();
|
|
90
65
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
Operation: commandName.slice(0, -7),
|
|
98
|
-
// strip "Command"
|
|
99
|
-
Identifiers: identifiers
|
|
100
|
-
});
|
|
101
|
-
const handler = command.resolveMiddleware(options.clientStack, config, options.options);
|
|
102
|
-
handler(command).then((result) => {
|
|
103
|
-
endpointCache.set(cacheKey, result.output.Endpoints);
|
|
104
|
-
if (requestQueue[cacheKey]) {
|
|
105
|
-
requestQueue[cacheKey].forEach(({ resolve: resolve2 }) => {
|
|
106
|
-
resolve2();
|
|
66
|
+
else {
|
|
67
|
+
const placeholderEndpoints = [{ Address: "", CachePeriodInMinutes: 1 }];
|
|
68
|
+
endpointCache.set(cacheKey, placeholderEndpoints);
|
|
69
|
+
const command = new options.endpointDiscoveryCommandCtor({
|
|
70
|
+
Operation: commandName.slice(0, -7),
|
|
71
|
+
Identifiers: identifiers,
|
|
107
72
|
});
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
73
|
+
const handler = command.resolveMiddleware(options.clientStack, config, options.options);
|
|
74
|
+
handler(command)
|
|
75
|
+
.then((result) => {
|
|
76
|
+
endpointCache.set(cacheKey, result.output.Endpoints);
|
|
77
|
+
if (requestQueue[cacheKey]) {
|
|
78
|
+
requestQueue[cacheKey].forEach(({ resolve }) => {
|
|
79
|
+
resolve();
|
|
80
|
+
});
|
|
81
|
+
delete requestQueue[cacheKey];
|
|
82
|
+
}
|
|
83
|
+
resolve();
|
|
84
|
+
})
|
|
85
|
+
.catch((error) => {
|
|
86
|
+
endpointCache.delete(cacheKey);
|
|
87
|
+
const errorToThrow = Object.assign(new Error(`The operation to discover endpoint failed.` +
|
|
88
|
+
` Please retry, or provide a custom endpoint and disable endpoint discovery to proceed.`), { reason: error });
|
|
89
|
+
if (requestQueue[cacheKey]) {
|
|
90
|
+
requestQueue[cacheKey].forEach(({ reject }) => {
|
|
91
|
+
reject(errorToThrow);
|
|
92
|
+
});
|
|
93
|
+
delete requestQueue[cacheKey];
|
|
94
|
+
}
|
|
95
|
+
if (options.isDiscoveredEndpointRequired) {
|
|
96
|
+
reject(errorToThrow);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
endpointCache.set(cacheKey, placeholderEndpoints);
|
|
100
|
+
resolve();
|
|
101
|
+
}
|
|
122
102
|
});
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
if (options.isDiscoveredEndpointRequired) {
|
|
126
|
-
reject(errorToThrow);
|
|
127
|
-
} else {
|
|
128
|
-
endpointCache.set(cacheKey, placeholderEndpoints);
|
|
129
|
-
resolve();
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
}), "updateDiscoveredEndpointInCache");
|
|
103
|
+
}
|
|
104
|
+
});
|
|
134
105
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
106
|
+
const endpointDiscoveryMiddleware = (config, middlewareConfig) => (next, context) => async (args) => {
|
|
107
|
+
if (config.isCustomEndpoint) {
|
|
108
|
+
if (config.isClientEndpointDiscoveryEnabled) {
|
|
109
|
+
throw new Error(`Custom endpoint is supplied; endpointDiscoveryEnabled must not be true.`);
|
|
110
|
+
}
|
|
111
|
+
return next(args);
|
|
140
112
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
113
|
+
const { endpointDiscoveryCommandCtor } = config;
|
|
114
|
+
const { isDiscoveredEndpointRequired, identifiers } = middlewareConfig;
|
|
115
|
+
const clientName = context.clientName;
|
|
116
|
+
const commandName = context.commandName;
|
|
117
|
+
const isEndpointDiscoveryEnabled = await config.endpointDiscoveryEnabled();
|
|
118
|
+
const cacheKey = await getCacheKey(commandName, config, { identifiers });
|
|
119
|
+
if (isDiscoveredEndpointRequired) {
|
|
120
|
+
if (isEndpointDiscoveryEnabled === false) {
|
|
121
|
+
throw new Error(`Endpoint Discovery is disabled but ${commandName} on ${clientName} requires it.` +
|
|
122
|
+
` Please check your configurations.`);
|
|
123
|
+
}
|
|
124
|
+
await updateDiscoveredEndpointInCache(config, {
|
|
125
|
+
...middlewareConfig,
|
|
126
|
+
commandName,
|
|
127
|
+
cacheKey,
|
|
128
|
+
endpointDiscoveryCommandCtor,
|
|
129
|
+
});
|
|
154
130
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
updateDiscoveredEndpointInCache(config, {
|
|
163
|
-
...middlewareConfig,
|
|
164
|
-
commandName,
|
|
165
|
-
cacheKey,
|
|
166
|
-
endpointDiscoveryCommandCtor
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
const { request } = args;
|
|
170
|
-
if (cacheKey && import_protocol_http.HttpRequest.isInstance(request)) {
|
|
171
|
-
const endpoint = config.endpointCache.getEndpoint(cacheKey);
|
|
172
|
-
if (endpoint) {
|
|
173
|
-
request.hostname = endpoint;
|
|
131
|
+
else if (isEndpointDiscoveryEnabled) {
|
|
132
|
+
updateDiscoveredEndpointInCache(config, {
|
|
133
|
+
...middlewareConfig,
|
|
134
|
+
commandName,
|
|
135
|
+
cacheKey,
|
|
136
|
+
endpointDiscoveryCommandCtor,
|
|
137
|
+
});
|
|
174
138
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
tags: ["ENDPOINT_DISCOVERY"],
|
|
184
|
-
override: true
|
|
139
|
+
const { request } = args;
|
|
140
|
+
if (cacheKey && protocolHttp.HttpRequest.isInstance(request)) {
|
|
141
|
+
const endpoint = config.endpointCache.getEndpoint(cacheKey);
|
|
142
|
+
if (endpoint) {
|
|
143
|
+
request.hostname = endpoint;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return next(args);
|
|
185
147
|
};
|
|
186
|
-
var getEndpointDiscoveryPlugin = /* @__PURE__ */ __name((pluginConfig, middlewareConfig) => ({
|
|
187
|
-
applyToStack: /* @__PURE__ */ __name((commandStack) => {
|
|
188
|
-
commandStack.add(endpointDiscoveryMiddleware(pluginConfig, middlewareConfig), endpointDiscoveryMiddlewareOptions);
|
|
189
|
-
}, "applyToStack")
|
|
190
|
-
}), "getEndpointDiscoveryPlugin");
|
|
191
|
-
var getEndpointDiscoveryRequiredPlugin = /* @__PURE__ */ __name((pluginConfig, middlewareConfig) => ({
|
|
192
|
-
applyToStack: /* @__PURE__ */ __name((commandStack) => {
|
|
193
|
-
commandStack.add(
|
|
194
|
-
endpointDiscoveryMiddleware(pluginConfig, { ...middlewareConfig, isDiscoveredEndpointRequired: true }),
|
|
195
|
-
endpointDiscoveryMiddlewareOptions
|
|
196
|
-
);
|
|
197
|
-
}, "applyToStack")
|
|
198
|
-
}), "getEndpointDiscoveryRequiredPlugin");
|
|
199
|
-
var getEndpointDiscoveryOptionalPlugin = /* @__PURE__ */ __name((pluginConfig, middlewareConfig) => ({
|
|
200
|
-
applyToStack: /* @__PURE__ */ __name((commandStack) => {
|
|
201
|
-
commandStack.add(
|
|
202
|
-
endpointDiscoveryMiddleware(pluginConfig, { ...middlewareConfig, isDiscoveredEndpointRequired: false }),
|
|
203
|
-
endpointDiscoveryMiddlewareOptions
|
|
204
|
-
);
|
|
205
|
-
}, "applyToStack")
|
|
206
|
-
}), "getEndpointDiscoveryOptionalPlugin");
|
|
207
|
-
|
|
208
|
-
// src/resolveEndpointDiscoveryConfig.ts
|
|
209
|
-
var import_endpoint_cache = require("@aws-sdk/endpoint-cache");
|
|
210
|
-
var resolveEndpointDiscoveryConfig = /* @__PURE__ */ __name((input, { endpointDiscoveryCommandCtor }) => {
|
|
211
|
-
const { endpointCacheSize, endpointDiscoveryEnabled, endpointDiscoveryEnabledProvider } = input;
|
|
212
|
-
return Object.assign(input, {
|
|
213
|
-
endpointDiscoveryCommandCtor,
|
|
214
|
-
endpointCache: new import_endpoint_cache.EndpointCache(endpointCacheSize ?? 1e3),
|
|
215
|
-
endpointDiscoveryEnabled: endpointDiscoveryEnabled !== void 0 ? () => Promise.resolve(endpointDiscoveryEnabled) : endpointDiscoveryEnabledProvider,
|
|
216
|
-
isClientEndpointDiscoveryEnabled: endpointDiscoveryEnabled !== void 0
|
|
217
|
-
});
|
|
218
|
-
}, "resolveEndpointDiscoveryConfig");
|
|
219
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
220
148
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
149
|
+
const endpointDiscoveryMiddlewareOptions = {
|
|
150
|
+
name: "endpointDiscoveryMiddleware",
|
|
151
|
+
step: "build",
|
|
152
|
+
tags: ["ENDPOINT_DISCOVERY"],
|
|
153
|
+
override: true,
|
|
154
|
+
};
|
|
155
|
+
const getEndpointDiscoveryPlugin = (pluginConfig, middlewareConfig) => ({
|
|
156
|
+
applyToStack: (commandStack) => {
|
|
157
|
+
commandStack.add(endpointDiscoveryMiddleware(pluginConfig, middlewareConfig), endpointDiscoveryMiddlewareOptions);
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
const getEndpointDiscoveryRequiredPlugin = (pluginConfig, middlewareConfig) => ({
|
|
161
|
+
applyToStack: (commandStack) => {
|
|
162
|
+
commandStack.add(endpointDiscoveryMiddleware(pluginConfig, { ...middlewareConfig, isDiscoveredEndpointRequired: true }), endpointDiscoveryMiddlewareOptions);
|
|
163
|
+
},
|
|
228
164
|
});
|
|
165
|
+
const getEndpointDiscoveryOptionalPlugin = (pluginConfig, middlewareConfig) => ({
|
|
166
|
+
applyToStack: (commandStack) => {
|
|
167
|
+
commandStack.add(endpointDiscoveryMiddleware(pluginConfig, { ...middlewareConfig, isDiscoveredEndpointRequired: false }), endpointDiscoveryMiddlewareOptions);
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
const resolveEndpointDiscoveryConfig = (input, { endpointDiscoveryCommandCtor }) => {
|
|
172
|
+
const { endpointCacheSize, endpointDiscoveryEnabled, endpointDiscoveryEnabledProvider } = input;
|
|
173
|
+
return Object.assign(input, {
|
|
174
|
+
endpointDiscoveryCommandCtor,
|
|
175
|
+
endpointCache: new endpointCache.EndpointCache(endpointCacheSize ?? 1000),
|
|
176
|
+
endpointDiscoveryEnabled: endpointDiscoveryEnabled !== undefined
|
|
177
|
+
? () => Promise.resolve(endpointDiscoveryEnabled)
|
|
178
|
+
: endpointDiscoveryEnabledProvider,
|
|
179
|
+
isClientEndpointDiscoveryEnabled: endpointDiscoveryEnabled !== undefined,
|
|
180
|
+
});
|
|
181
|
+
};
|
|
229
182
|
|
|
183
|
+
exports.NODE_ENDPOINT_DISCOVERY_CONFIG_OPTIONS = NODE_ENDPOINT_DISCOVERY_CONFIG_OPTIONS;
|
|
184
|
+
exports.endpointDiscoveryMiddlewareOptions = endpointDiscoveryMiddlewareOptions;
|
|
185
|
+
exports.getEndpointDiscoveryOptionalPlugin = getEndpointDiscoveryOptionalPlugin;
|
|
186
|
+
exports.getEndpointDiscoveryPlugin = getEndpointDiscoveryPlugin;
|
|
187
|
+
exports.getEndpointDiscoveryRequiredPlugin = getEndpointDiscoveryRequiredPlugin;
|
|
188
|
+
exports.resolveEndpointDiscoveryConfig = resolveEndpointDiscoveryConfig;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-sdk/middleware-endpoint-discovery",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.910.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
|
|
6
6
|
"build:cjs": "node ../../scripts/compilation/inline middleware-endpoint-discovery",
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@aws-sdk/endpoint-cache": "3.893.0",
|
|
36
|
-
"@aws-sdk/types": "3.
|
|
37
|
-
"@smithy/node-config-provider": "^4.3.
|
|
38
|
-
"@smithy/protocol-http": "^5.3.
|
|
39
|
-
"@smithy/types": "^4.
|
|
36
|
+
"@aws-sdk/types": "3.910.0",
|
|
37
|
+
"@smithy/node-config-provider": "^4.3.2",
|
|
38
|
+
"@smithy/protocol-http": "^5.3.2",
|
|
39
|
+
"@smithy/types": "^4.7.1",
|
|
40
40
|
"tslib": "^2.6.2"
|
|
41
41
|
},
|
|
42
42
|
"engines": {
|