@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.
Files changed (61) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/dist-cjs/configurations.js +30 -0
  3. package/dist-cjs/endpointDiscoveryMiddleware.js +48 -0
  4. package/dist-cjs/getCacheKey.js +17 -0
  5. package/dist-cjs/getEndpointDiscoveryPlugin.js +28 -0
  6. package/dist-cjs/index.js +6 -0
  7. package/dist-cjs/resolveEndpointDiscoveryConfig.js +17 -0
  8. package/dist-cjs/updateDiscoveredEndpointInCache.js +64 -0
  9. package/dist-es/configurations.js +27 -0
  10. package/dist-es/endpointDiscoveryMiddleware.js +54 -0
  11. package/dist-es/getCacheKey.js +22 -0
  12. package/dist-es/getEndpointDiscoveryPlugin.js +23 -0
  13. package/{dist/types/index.d.ts → dist-es/index.js} +0 -0
  14. package/dist-es/resolveEndpointDiscoveryConfig.js +9 -0
  15. package/dist-es/updateDiscoveredEndpointInCache.js +67 -0
  16. package/{dist/types → dist-types}/configurations.d.ts +0 -0
  17. package/{dist/types → dist-types}/endpointDiscoveryMiddleware.d.ts +0 -0
  18. package/{dist/types → dist-types}/getCacheKey.d.ts +0 -0
  19. package/{dist/types → dist-types}/getEndpointDiscoveryPlugin.d.ts +0 -0
  20. package/{src/index.ts → dist-types/index.d.ts} +0 -0
  21. package/{dist/types → dist-types}/resolveEndpointDiscoveryConfig.d.ts +0 -0
  22. package/{dist/types → dist-types}/ts3.4/configurations.d.ts +0 -0
  23. package/{dist/types → dist-types}/ts3.4/endpointDiscoveryMiddleware.d.ts +0 -0
  24. package/{dist/types → dist-types}/ts3.4/getCacheKey.d.ts +0 -0
  25. package/{dist/types → dist-types}/ts3.4/getEndpointDiscoveryPlugin.d.ts +0 -0
  26. package/{dist/types → dist-types}/ts3.4/index.d.ts +0 -0
  27. package/{dist/types → dist-types}/ts3.4/resolveEndpointDiscoveryConfig.d.ts +0 -0
  28. package/{dist/types → dist-types}/ts3.4/updateDiscoveredEndpointInCache.d.ts +0 -0
  29. package/{dist/types → dist-types}/updateDiscoveredEndpointInCache.d.ts +0 -0
  30. package/package.json +17 -13
  31. package/dist/cjs/configurations.js +0 -32
  32. package/dist/cjs/endpointDiscoveryMiddleware.js +0 -55
  33. package/dist/cjs/getCacheKey.js +0 -21
  34. package/dist/cjs/getEndpointDiscoveryPlugin.js +0 -35
  35. package/dist/cjs/index.js +0 -7
  36. package/dist/cjs/resolveEndpointDiscoveryConfig.js +0 -18
  37. package/dist/cjs/updateDiscoveredEndpointInCache.js +0 -74
  38. package/dist/es/configurations.js +0 -29
  39. package/dist/es/endpointDiscoveryMiddleware.js +0 -63
  40. package/dist/es/getCacheKey.js +0 -26
  41. package/dist/es/getEndpointDiscoveryPlugin.js +0 -30
  42. package/dist/es/index.js +0 -4
  43. package/dist/es/resolveEndpointDiscoveryConfig.js +0 -10
  44. package/dist/es/updateDiscoveredEndpointInCache.js +0 -77
  45. package/dist/tsconfig.cjs.tsbuildinfo +0 -1
  46. package/dist/tsconfig.es.tsbuildinfo +0 -1
  47. package/jest.config.js +0 -5
  48. package/src/configurations.spec.ts +0 -85
  49. package/src/configurations.ts +0 -32
  50. package/src/endpointDiscoveryMiddleware.spec.ts +0 -145
  51. package/src/endpointDiscoveryMiddleware.ts +0 -72
  52. package/src/getCacheKey.spec.ts +0 -32
  53. package/src/getCacheKey.ts +0 -24
  54. package/src/getEndpointDiscoveryPlugin.spec.ts +0 -32
  55. package/src/getEndpointDiscoveryPlugin.ts +0 -57
  56. package/src/resolveEndpointDiscoveryConfig.spec.ts +0 -63
  57. package/src/resolveEndpointDiscoveryConfig.ts +0 -73
  58. package/src/updateDiscoveredEndpointInCache.spec.ts +0 -172
  59. package/src/updateDiscoveredEndpointInCache.ts +0 -88
  60. package/tsconfig.cjs.json +0 -10
  61. package/tsconfig.es.json +0 -11
package/CHANGELOG.md CHANGED
@@ -3,6 +3,44 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [3.36.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.35.0...v3.36.0) (2021-10-08)
7
+
8
+
9
+ ### Features
10
+
11
+ * publish files in dist-* only ([#2873](https://github.com/aws/aws-sdk-js-v3/issues/2873)) ([53b4243](https://github.com/aws/aws-sdk-js-v3/commit/53b4243b066f25ff2412d5f0dea1036054b2df32))
12
+
13
+
14
+
15
+
16
+
17
+ # [3.35.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.34.0...v3.35.0) (2021-10-04)
18
+
19
+ **Note:** Version bump only for package @aws-sdk/middleware-endpoint-discovery
20
+
21
+
22
+
23
+
24
+
25
+ # [3.34.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.33.0...v3.34.0) (2021-09-24)
26
+
27
+
28
+ ### Features
29
+
30
+ * **non-clients:** remove comments from transpiled JS files ([#2813](https://github.com/aws/aws-sdk-js-v3/issues/2813)) ([e6fc7f3](https://github.com/aws/aws-sdk-js-v3/commit/e6fc7f3e0fa74785590ac19e7ed143c916bb9b6e))
31
+
32
+
33
+
34
+
35
+
36
+ # [3.33.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.32.0...v3.33.0) (2021-09-21)
37
+
38
+ **Note:** Version bump only for package @aws-sdk/middleware-endpoint-discovery
39
+
40
+
41
+
42
+
43
+
6
44
  # [3.32.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.31.0...v3.32.0) (2021-09-17)
7
45
 
8
46
  **Note:** Version bump only for package @aws-sdk/middleware-endpoint-discovery
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NODE_ENDPOINT_DISCOVERY_CONFIG_OPTIONS = void 0;
4
+ const ENV_ENDPOINT_DISCOVERY = ["AWS_ENABLE_ENDPOINT_DISCOVERY", "AWS_ENDPOINT_DISCOVERY_ENABLED"];
5
+ const CONFIG_ENDPOINT_DISCOVERY = "endpoint_discovery_enabled";
6
+ const isFalsy = (value) => ["false", "0"].indexOf(value) >= 0;
7
+ exports.NODE_ENDPOINT_DISCOVERY_CONFIG_OPTIONS = {
8
+ environmentVariableSelector: (env) => {
9
+ for (let i = 0; i < ENV_ENDPOINT_DISCOVERY.length; i++) {
10
+ const envKey = ENV_ENDPOINT_DISCOVERY[i];
11
+ if (envKey in env) {
12
+ const value = env[envKey];
13
+ if (value === "") {
14
+ throw Error(`Environment variable ${envKey} can't be empty of undefined, got "${value}"`);
15
+ }
16
+ return !isFalsy(value);
17
+ }
18
+ }
19
+ },
20
+ configFileSelector: (profile) => {
21
+ if (CONFIG_ENDPOINT_DISCOVERY in profile) {
22
+ const value = profile[CONFIG_ENDPOINT_DISCOVERY];
23
+ if (value === undefined) {
24
+ throw Error(`Shared config entry ${CONFIG_ENDPOINT_DISCOVERY} can't be undefined, got "${value}"`);
25
+ }
26
+ return !isFalsy(value);
27
+ }
28
+ },
29
+ default: undefined,
30
+ };
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.endpointDiscoveryMiddleware = void 0;
4
+ const protocol_http_1 = require("@aws-sdk/protocol-http");
5
+ const getCacheKey_1 = require("./getCacheKey");
6
+ const updateDiscoveredEndpointInCache_1 = require("./updateDiscoveredEndpointInCache");
7
+ const endpointDiscoveryMiddleware = (config, middlewareConfig) => (next, context) => async (args) => {
8
+ if (config.isCustomEndpoint) {
9
+ if (config.isClientEndpointDiscoveryEnabled) {
10
+ throw new Error(`Custom endpoint is supplied; endpointDiscoveryEnabled must not be true.`);
11
+ }
12
+ return next(args);
13
+ }
14
+ const { endpointDiscoveryCommandCtor } = config;
15
+ const { isDiscoveredEndpointRequired, identifiers } = middlewareConfig;
16
+ const { clientName, commandName } = context;
17
+ const isEndpointDiscoveryEnabled = await config.endpointDiscoveryEnabled();
18
+ const cacheKey = await getCacheKey_1.getCacheKey(commandName, config, { identifiers });
19
+ if (isDiscoveredEndpointRequired) {
20
+ if (isEndpointDiscoveryEnabled === false) {
21
+ throw new Error(`Endpoint Discovery is disabled but ${commandName} on ${clientName} requires it.` +
22
+ ` Please check your configurations.`);
23
+ }
24
+ await updateDiscoveredEndpointInCache_1.updateDiscoveredEndpointInCache(config, {
25
+ ...middlewareConfig,
26
+ commandName,
27
+ cacheKey,
28
+ endpointDiscoveryCommandCtor,
29
+ });
30
+ }
31
+ else if (isEndpointDiscoveryEnabled) {
32
+ updateDiscoveredEndpointInCache_1.updateDiscoveredEndpointInCache(config, {
33
+ ...middlewareConfig,
34
+ commandName,
35
+ cacheKey,
36
+ endpointDiscoveryCommandCtor,
37
+ });
38
+ }
39
+ const { request } = args;
40
+ if (cacheKey && protocol_http_1.HttpRequest.isInstance(request)) {
41
+ const endpoint = config.endpointCache.getEndpoint(cacheKey);
42
+ if (endpoint) {
43
+ request.hostname = endpoint;
44
+ }
45
+ }
46
+ return next(args);
47
+ };
48
+ exports.endpointDiscoveryMiddleware = endpointDiscoveryMiddleware;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCacheKey = void 0;
4
+ const getCacheKey = async (commandName, config, options) => {
5
+ const { accessKeyId } = await config.credentials();
6
+ const { identifiers } = options;
7
+ return JSON.stringify({
8
+ ...(accessKeyId && { accessKeyId }),
9
+ ...(identifiers && {
10
+ commandName,
11
+ identifiers: Object.entries(identifiers)
12
+ .sort()
13
+ .reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {}),
14
+ }),
15
+ });
16
+ };
17
+ exports.getCacheKey = getCacheKey;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEndpointDiscoveryOptionalPlugin = exports.getEndpointDiscoveryRequiredPlugin = exports.getEndpointDiscoveryPlugin = exports.endpointDiscoveryMiddlewareOptions = void 0;
4
+ const endpointDiscoveryMiddleware_1 = require("./endpointDiscoveryMiddleware");
5
+ exports.endpointDiscoveryMiddlewareOptions = {
6
+ name: "endpointDiscoveryMiddleware",
7
+ step: "build",
8
+ tags: ["ENDPOINT_DISCOVERY"],
9
+ override: true,
10
+ };
11
+ const getEndpointDiscoveryPlugin = (pluginConfig, middlewareConfig) => ({
12
+ applyToStack: (commandStack) => {
13
+ commandStack.add(endpointDiscoveryMiddleware_1.endpointDiscoveryMiddleware(pluginConfig, middlewareConfig), exports.endpointDiscoveryMiddlewareOptions);
14
+ },
15
+ });
16
+ exports.getEndpointDiscoveryPlugin = getEndpointDiscoveryPlugin;
17
+ const getEndpointDiscoveryRequiredPlugin = (pluginConfig, middlewareConfig) => ({
18
+ applyToStack: (commandStack) => {
19
+ commandStack.add(endpointDiscoveryMiddleware_1.endpointDiscoveryMiddleware(pluginConfig, { ...middlewareConfig, isDiscoveredEndpointRequired: true }), exports.endpointDiscoveryMiddlewareOptions);
20
+ },
21
+ });
22
+ exports.getEndpointDiscoveryRequiredPlugin = getEndpointDiscoveryRequiredPlugin;
23
+ const getEndpointDiscoveryOptionalPlugin = (pluginConfig, middlewareConfig) => ({
24
+ applyToStack: (commandStack) => {
25
+ commandStack.add(endpointDiscoveryMiddleware_1.endpointDiscoveryMiddleware(pluginConfig, { ...middlewareConfig, isDiscoveredEndpointRequired: false }), exports.endpointDiscoveryMiddlewareOptions);
26
+ },
27
+ });
28
+ exports.getEndpointDiscoveryOptionalPlugin = getEndpointDiscoveryOptionalPlugin;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./resolveEndpointDiscoveryConfig"), exports);
5
+ tslib_1.__exportStar(require("./getEndpointDiscoveryPlugin"), exports);
6
+ tslib_1.__exportStar(require("./configurations"), exports);
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveEndpointDiscoveryConfig = void 0;
4
+ const endpoint_cache_1 = require("@aws-sdk/endpoint-cache");
5
+ const resolveEndpointDiscoveryConfig = (input, { endpointDiscoveryCommandCtor }) => {
6
+ var _a;
7
+ return ({
8
+ ...input,
9
+ endpointDiscoveryCommandCtor,
10
+ endpointCache: new endpoint_cache_1.EndpointCache((_a = input.endpointCacheSize) !== null && _a !== void 0 ? _a : 1000),
11
+ endpointDiscoveryEnabled: input.endpointDiscoveryEnabled !== undefined
12
+ ? () => Promise.resolve(input.endpointDiscoveryEnabled)
13
+ : input.endpointDiscoveryEnabledProvider,
14
+ isClientEndpointDiscoveryEnabled: input.endpointDiscoveryEnabled !== undefined,
15
+ });
16
+ };
17
+ exports.resolveEndpointDiscoveryConfig = resolveEndpointDiscoveryConfig;
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateDiscoveredEndpointInCache = void 0;
4
+ const requestQueue = {};
5
+ const updateDiscoveredEndpointInCache = async (config, options) => new Promise((resolve, reject) => {
6
+ const { endpointCache } = config;
7
+ const { cacheKey, commandName, identifiers } = options;
8
+ const endpoints = endpointCache.get(cacheKey);
9
+ if (endpoints && endpoints.length === 1 && endpoints[0].Address === "") {
10
+ if (options.isDiscoveredEndpointRequired) {
11
+ if (!requestQueue[cacheKey])
12
+ requestQueue[cacheKey] = [];
13
+ requestQueue[cacheKey].push({ resolve, reject });
14
+ }
15
+ else {
16
+ resolve();
17
+ }
18
+ }
19
+ else if (endpoints && endpoints.length > 0) {
20
+ resolve();
21
+ }
22
+ else {
23
+ const placeholderEndpoints = [{ Address: "", CachePeriodInMinutes: 1 }];
24
+ endpointCache.set(cacheKey, placeholderEndpoints);
25
+ const command = new options.endpointDiscoveryCommandCtor({
26
+ Operation: commandName.substr(0, commandName.length - 7),
27
+ Identifiers: identifiers,
28
+ });
29
+ const handler = command.resolveMiddleware(options.clientStack, config, options.options);
30
+ handler(command)
31
+ .then((result) => {
32
+ endpointCache.set(cacheKey, result.output.Endpoints);
33
+ if (requestQueue[cacheKey]) {
34
+ requestQueue[cacheKey].forEach(({ resolve }) => {
35
+ resolve();
36
+ });
37
+ delete requestQueue[cacheKey];
38
+ }
39
+ resolve();
40
+ })
41
+ .catch((error) => {
42
+ var _a;
43
+ if (error.name === "InvalidEndpointException" || ((_a = error.$metadata) === null || _a === void 0 ? void 0 : _a.httpStatusCode) === 421) {
44
+ endpointCache.delete(cacheKey);
45
+ }
46
+ const errorToThrow = Object.assign(new Error(`The operation to discover endpoint failed.` +
47
+ ` Please retry, or provide a custom endpoint and disable endpoint discovery to proceed.`), { reason: error });
48
+ if (requestQueue[cacheKey]) {
49
+ requestQueue[cacheKey].forEach(({ reject }) => {
50
+ reject(errorToThrow);
51
+ });
52
+ delete requestQueue[cacheKey];
53
+ }
54
+ if (options.isDiscoveredEndpointRequired) {
55
+ reject(errorToThrow);
56
+ }
57
+ else {
58
+ endpointCache.set(cacheKey, placeholderEndpoints);
59
+ resolve();
60
+ }
61
+ });
62
+ }
63
+ });
64
+ exports.updateDiscoveredEndpointInCache = updateDiscoveredEndpointInCache;
@@ -0,0 +1,27 @@
1
+ var ENV_ENDPOINT_DISCOVERY = ["AWS_ENABLE_ENDPOINT_DISCOVERY", "AWS_ENDPOINT_DISCOVERY_ENABLED"];
2
+ var CONFIG_ENDPOINT_DISCOVERY = "endpoint_discovery_enabled";
3
+ var isFalsy = function (value) { return ["false", "0"].indexOf(value) >= 0; };
4
+ export var NODE_ENDPOINT_DISCOVERY_CONFIG_OPTIONS = {
5
+ environmentVariableSelector: function (env) {
6
+ for (var i = 0; i < ENV_ENDPOINT_DISCOVERY.length; i++) {
7
+ var envKey = ENV_ENDPOINT_DISCOVERY[i];
8
+ if (envKey in env) {
9
+ var value = env[envKey];
10
+ if (value === "") {
11
+ throw Error("Environment variable " + envKey + " can't be empty of undefined, got \"" + value + "\"");
12
+ }
13
+ return !isFalsy(value);
14
+ }
15
+ }
16
+ },
17
+ configFileSelector: function (profile) {
18
+ if (CONFIG_ENDPOINT_DISCOVERY in profile) {
19
+ var value = profile[CONFIG_ENDPOINT_DISCOVERY];
20
+ if (value === undefined) {
21
+ throw Error("Shared config entry " + CONFIG_ENDPOINT_DISCOVERY + " can't be undefined, got \"" + value + "\"");
22
+ }
23
+ return !isFalsy(value);
24
+ }
25
+ },
26
+ default: undefined,
27
+ };
@@ -0,0 +1,54 @@
1
+ import { __assign, __awaiter, __generator } from "tslib";
2
+ import { HttpRequest } from "@aws-sdk/protocol-http";
3
+ import { getCacheKey } from "./getCacheKey";
4
+ import { updateDiscoveredEndpointInCache } from "./updateDiscoveredEndpointInCache";
5
+ export var endpointDiscoveryMiddleware = function (config, middlewareConfig) {
6
+ return function (next, context) {
7
+ return function (args) { return __awaiter(void 0, void 0, void 0, function () {
8
+ var endpointDiscoveryCommandCtor, isDiscoveredEndpointRequired, identifiers, clientName, commandName, isEndpointDiscoveryEnabled, cacheKey, request, endpoint;
9
+ return __generator(this, function (_a) {
10
+ switch (_a.label) {
11
+ case 0:
12
+ if (config.isCustomEndpoint) {
13
+ if (config.isClientEndpointDiscoveryEnabled) {
14
+ throw new Error("Custom endpoint is supplied; endpointDiscoveryEnabled must not be true.");
15
+ }
16
+ return [2, next(args)];
17
+ }
18
+ endpointDiscoveryCommandCtor = config.endpointDiscoveryCommandCtor;
19
+ isDiscoveredEndpointRequired = middlewareConfig.isDiscoveredEndpointRequired, identifiers = middlewareConfig.identifiers;
20
+ clientName = context.clientName, commandName = context.commandName;
21
+ return [4, config.endpointDiscoveryEnabled()];
22
+ case 1:
23
+ isEndpointDiscoveryEnabled = _a.sent();
24
+ return [4, getCacheKey(commandName, config, { identifiers: identifiers })];
25
+ case 2:
26
+ cacheKey = _a.sent();
27
+ if (!isDiscoveredEndpointRequired) return [3, 4];
28
+ if (isEndpointDiscoveryEnabled === false) {
29
+ throw new Error("Endpoint Discovery is disabled but " + commandName + " on " + clientName + " requires it." +
30
+ " Please check your configurations.");
31
+ }
32
+ return [4, updateDiscoveredEndpointInCache(config, __assign(__assign({}, middlewareConfig), { commandName: commandName, cacheKey: cacheKey, endpointDiscoveryCommandCtor: endpointDiscoveryCommandCtor }))];
33
+ case 3:
34
+ _a.sent();
35
+ return [3, 5];
36
+ case 4:
37
+ if (isEndpointDiscoveryEnabled) {
38
+ updateDiscoveredEndpointInCache(config, __assign(__assign({}, middlewareConfig), { commandName: commandName, cacheKey: cacheKey, endpointDiscoveryCommandCtor: endpointDiscoveryCommandCtor }));
39
+ }
40
+ _a.label = 5;
41
+ case 5:
42
+ request = args.request;
43
+ if (cacheKey && HttpRequest.isInstance(request)) {
44
+ endpoint = config.endpointCache.getEndpoint(cacheKey);
45
+ if (endpoint) {
46
+ request.hostname = endpoint;
47
+ }
48
+ }
49
+ return [2, next(args)];
50
+ }
51
+ });
52
+ }); };
53
+ };
54
+ };
@@ -0,0 +1,22 @@
1
+ import { __assign, __awaiter, __generator, __read } from "tslib";
2
+ export var getCacheKey = function (commandName, config, options) { return __awaiter(void 0, void 0, void 0, function () {
3
+ var accessKeyId, identifiers;
4
+ return __generator(this, function (_a) {
5
+ switch (_a.label) {
6
+ case 0: return [4, config.credentials()];
7
+ case 1:
8
+ accessKeyId = (_a.sent()).accessKeyId;
9
+ identifiers = options.identifiers;
10
+ return [2, JSON.stringify(__assign(__assign({}, (accessKeyId && { accessKeyId: accessKeyId })), (identifiers && {
11
+ commandName: commandName,
12
+ identifiers: Object.entries(identifiers)
13
+ .sort()
14
+ .reduce(function (acc, _a) {
15
+ var _b;
16
+ var _c = __read(_a, 2), key = _c[0], value = _c[1];
17
+ return (__assign(__assign({}, acc), (_b = {}, _b[key] = value, _b)));
18
+ }, {}),
19
+ })))];
20
+ }
21
+ });
22
+ }); };
@@ -0,0 +1,23 @@
1
+ import { __assign } from "tslib";
2
+ import { endpointDiscoveryMiddleware } from "./endpointDiscoveryMiddleware";
3
+ export var endpointDiscoveryMiddlewareOptions = {
4
+ name: "endpointDiscoveryMiddleware",
5
+ step: "build",
6
+ tags: ["ENDPOINT_DISCOVERY"],
7
+ override: true,
8
+ };
9
+ export var getEndpointDiscoveryPlugin = function (pluginConfig, middlewareConfig) { return ({
10
+ applyToStack: function (commandStack) {
11
+ commandStack.add(endpointDiscoveryMiddleware(pluginConfig, middlewareConfig), endpointDiscoveryMiddlewareOptions);
12
+ },
13
+ }); };
14
+ export var getEndpointDiscoveryRequiredPlugin = function (pluginConfig, middlewareConfig) { return ({
15
+ applyToStack: function (commandStack) {
16
+ commandStack.add(endpointDiscoveryMiddleware(pluginConfig, __assign(__assign({}, middlewareConfig), { isDiscoveredEndpointRequired: true })), endpointDiscoveryMiddlewareOptions);
17
+ },
18
+ }); };
19
+ export var getEndpointDiscoveryOptionalPlugin = function (pluginConfig, middlewareConfig) { return ({
20
+ applyToStack: function (commandStack) {
21
+ commandStack.add(endpointDiscoveryMiddleware(pluginConfig, __assign(__assign({}, middlewareConfig), { isDiscoveredEndpointRequired: false })), endpointDiscoveryMiddlewareOptions);
22
+ },
23
+ }); };
File without changes
@@ -0,0 +1,9 @@
1
+ import { __assign } from "tslib";
2
+ import { EndpointCache } from "@aws-sdk/endpoint-cache";
3
+ export var resolveEndpointDiscoveryConfig = function (input, _a) {
4
+ var _b;
5
+ var endpointDiscoveryCommandCtor = _a.endpointDiscoveryCommandCtor;
6
+ return (__assign(__assign({}, input), { endpointDiscoveryCommandCtor: endpointDiscoveryCommandCtor, endpointCache: new EndpointCache((_b = input.endpointCacheSize) !== null && _b !== void 0 ? _b : 1000), endpointDiscoveryEnabled: input.endpointDiscoveryEnabled !== undefined
7
+ ? function () { return Promise.resolve(input.endpointDiscoveryEnabled); }
8
+ : input.endpointDiscoveryEnabledProvider, isClientEndpointDiscoveryEnabled: input.endpointDiscoveryEnabled !== undefined }));
9
+ };
@@ -0,0 +1,67 @@
1
+ import { __awaiter, __generator } from "tslib";
2
+ var requestQueue = {};
3
+ export var updateDiscoveredEndpointInCache = function (config, options) { return __awaiter(void 0, void 0, void 0, function () {
4
+ return __generator(this, function (_a) {
5
+ return [2, new Promise(function (resolve, reject) {
6
+ var endpointCache = config.endpointCache;
7
+ var cacheKey = options.cacheKey, commandName = options.commandName, identifiers = options.identifiers;
8
+ var endpoints = endpointCache.get(cacheKey);
9
+ if (endpoints && endpoints.length === 1 && endpoints[0].Address === "") {
10
+ if (options.isDiscoveredEndpointRequired) {
11
+ if (!requestQueue[cacheKey])
12
+ requestQueue[cacheKey] = [];
13
+ requestQueue[cacheKey].push({ resolve: resolve, reject: reject });
14
+ }
15
+ else {
16
+ resolve();
17
+ }
18
+ }
19
+ else if (endpoints && endpoints.length > 0) {
20
+ resolve();
21
+ }
22
+ else {
23
+ var placeholderEndpoints_1 = [{ Address: "", CachePeriodInMinutes: 1 }];
24
+ endpointCache.set(cacheKey, placeholderEndpoints_1);
25
+ var command = new options.endpointDiscoveryCommandCtor({
26
+ Operation: commandName.substr(0, commandName.length - 7),
27
+ Identifiers: identifiers,
28
+ });
29
+ var handler = command.resolveMiddleware(options.clientStack, config, options.options);
30
+ handler(command)
31
+ .then(function (result) {
32
+ endpointCache.set(cacheKey, result.output.Endpoints);
33
+ if (requestQueue[cacheKey]) {
34
+ requestQueue[cacheKey].forEach(function (_a) {
35
+ var resolve = _a.resolve;
36
+ resolve();
37
+ });
38
+ delete requestQueue[cacheKey];
39
+ }
40
+ resolve();
41
+ })
42
+ .catch(function (error) {
43
+ var _a;
44
+ if (error.name === "InvalidEndpointException" || ((_a = error.$metadata) === null || _a === void 0 ? void 0 : _a.httpStatusCode) === 421) {
45
+ endpointCache.delete(cacheKey);
46
+ }
47
+ var errorToThrow = Object.assign(new Error("The operation to discover endpoint failed." +
48
+ " Please retry, or provide a custom endpoint and disable endpoint discovery to proceed."), { reason: error });
49
+ if (requestQueue[cacheKey]) {
50
+ requestQueue[cacheKey].forEach(function (_a) {
51
+ var reject = _a.reject;
52
+ reject(errorToThrow);
53
+ });
54
+ delete requestQueue[cacheKey];
55
+ }
56
+ if (options.isDiscoveredEndpointRequired) {
57
+ reject(errorToThrow);
58
+ }
59
+ else {
60
+ endpointCache.set(cacheKey, placeholderEndpoints_1);
61
+ resolve();
62
+ }
63
+ });
64
+ }
65
+ })];
66
+ });
67
+ }); };
File without changes
File without changes
File without changes
File without changes
package/package.json CHANGED
@@ -1,32 +1,33 @@
1
1
  {
2
2
  "name": "@aws-sdk/middleware-endpoint-discovery",
3
- "version": "3.32.0",
3
+ "version": "3.36.0",
4
4
  "scripts": {
5
+ "build": "yarn build:cjs && yarn build:es && yarn build:types",
5
6
  "build:cjs": "tsc -p tsconfig.cjs.json",
6
7
  "build:es": "tsc -p tsconfig.es.json",
7
- "build": "yarn build:es && yarn build:cjs",
8
- "downlevel-dts": "downlevel-dts dist/types dist/types/ts3.4",
8
+ "build:types": "tsc -p tsconfig.types.json",
9
+ "downlevel-dts": "downlevel-dts dist-types dist-types/ts3.4",
9
10
  "test": "jest"
10
11
  },
11
- "main": "./dist/cjs/index.js",
12
- "module": "./dist/es/index.js",
13
- "types": "./dist/types/index.d.ts",
12
+ "main": "./dist-cjs/index.js",
13
+ "module": "./dist-es/index.js",
14
+ "types": "./dist-types/index.d.ts",
14
15
  "author": {
15
16
  "name": "AWS SDK for JavaScript Team",
16
17
  "url": "https://aws.amazon.com/javascript/"
17
18
  },
18
19
  "license": "Apache-2.0",
19
20
  "devDependencies": {
20
- "@aws-sdk/node-config-provider": "3.32.0",
21
+ "@aws-sdk/node-config-provider": "3.36.0",
21
22
  "@types/jest": "^26.0.4",
22
23
  "jest": "^26.1.0",
23
24
  "typescript": "~4.3.5"
24
25
  },
25
26
  "dependencies": {
26
- "@aws-sdk/config-resolver": "3.32.0",
27
- "@aws-sdk/endpoint-cache": "3.32.0",
28
- "@aws-sdk/protocol-http": "3.32.0",
29
- "@aws-sdk/types": "3.32.0",
27
+ "@aws-sdk/config-resolver": "3.36.0",
28
+ "@aws-sdk/endpoint-cache": "3.36.0",
29
+ "@aws-sdk/protocol-http": "3.36.0",
30
+ "@aws-sdk/types": "3.36.0",
30
31
  "tslib": "^2.3.0"
31
32
  },
32
33
  "engines": {
@@ -34,11 +35,14 @@
34
35
  },
35
36
  "typesVersions": {
36
37
  "<4.0": {
37
- "dist/types/*": [
38
- "dist/types/ts3.4/*"
38
+ "dist-types/*": [
39
+ "dist-types/ts3.4/*"
39
40
  ]
40
41
  }
41
42
  },
43
+ "files": [
44
+ "dist-*"
45
+ ],
42
46
  "homepage": "https://github.com/aws/aws-sdk-js-v3/tree/main/packages/middleware-endpoint-discovery",
43
47
  "repository": {
44
48
  "type": "git",
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NODE_ENDPOINT_DISCOVERY_CONFIG_OPTIONS = void 0;
4
- const ENV_ENDPOINT_DISCOVERY = ["AWS_ENABLE_ENDPOINT_DISCOVERY", "AWS_ENDPOINT_DISCOVERY_ENABLED"];
5
- const CONFIG_ENDPOINT_DISCOVERY = "endpoint_discovery_enabled";
6
- const isFalsy = (value) => ["false", "0"].indexOf(value) >= 0;
7
- exports.NODE_ENDPOINT_DISCOVERY_CONFIG_OPTIONS = {
8
- environmentVariableSelector: (env) => {
9
- for (let i = 0; i < ENV_ENDPOINT_DISCOVERY.length; i++) {
10
- const envKey = ENV_ENDPOINT_DISCOVERY[i];
11
- if (envKey in env) {
12
- const value = env[envKey];
13
- if (value === "") {
14
- throw Error(`Environment variable ${envKey} can't be empty of undefined, got "${value}"`);
15
- }
16
- // @ts-ignore Argument of type 'string | undefined' is not assignable to parameter of type 'string'
17
- return !isFalsy(value);
18
- }
19
- }
20
- },
21
- configFileSelector: (profile) => {
22
- if (CONFIG_ENDPOINT_DISCOVERY in profile) {
23
- const value = profile[CONFIG_ENDPOINT_DISCOVERY];
24
- if (value === undefined) {
25
- throw Error(`Shared config entry ${CONFIG_ENDPOINT_DISCOVERY} can't be undefined, got "${value}"`);
26
- }
27
- return !isFalsy(value);
28
- }
29
- },
30
- default: undefined,
31
- };
32
- //# sour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