@aws-sdk/middleware-endpoint-discovery 3.171.0 → 3.183.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 CHANGED
@@ -3,6 +3,25 @@
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.183.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.182.0...v3.183.0) (2022-10-03)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **endpoint-discovery:** delete failed cache entry in blocking operations ([#4011](https://github.com/aws/aws-sdk-js-v3/issues/4011)) ([c96ac94](https://github.com/aws/aws-sdk-js-v3/commit/c96ac9418a22687b867077e7d72b5d353d37778c))
12
+
13
+
14
+
15
+
16
+
17
+ # [3.178.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.177.0...v3.178.0) (2022-09-23)
18
+
19
+ **Note:** Version bump only for package @aws-sdk/middleware-endpoint-discovery
20
+
21
+
22
+
23
+
24
+
6
25
  # [3.171.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.170.0...v3.171.0) (2022-09-14)
7
26
 
8
27
  **Note:** Version bump only for package @aws-sdk/middleware-endpoint-discovery
@@ -39,10 +39,7 @@ const updateDiscoveredEndpointInCache = async (config, options) => new Promise((
39
39
  resolve();
40
40
  })
41
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
- }
42
+ endpointCache.delete(cacheKey);
46
43
  const errorToThrow = Object.assign(new Error(`The operation to discover endpoint failed.` +
47
44
  ` Please retry, or provide a custom endpoint and disable endpoint discovery to proceed.`), { reason: error });
48
45
  if (requestQueue[cacheKey]) {
@@ -1,24 +1,24 @@
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];
1
+ const ENV_ENDPOINT_DISCOVERY = ["AWS_ENABLE_ENDPOINT_DISCOVERY", "AWS_ENDPOINT_DISCOVERY_ENABLED"];
2
+ const CONFIG_ENDPOINT_DISCOVERY = "endpoint_discovery_enabled";
3
+ const isFalsy = (value) => ["false", "0"].indexOf(value) >= 0;
4
+ export const NODE_ENDPOINT_DISCOVERY_CONFIG_OPTIONS = {
5
+ environmentVariableSelector: (env) => {
6
+ for (let i = 0; i < ENV_ENDPOINT_DISCOVERY.length; i++) {
7
+ const envKey = ENV_ENDPOINT_DISCOVERY[i];
8
8
  if (envKey in env) {
9
- var value = env[envKey];
9
+ const value = env[envKey];
10
10
  if (value === "") {
11
- throw Error("Environment variable ".concat(envKey, " can't be empty of undefined, got \"").concat(value, "\""));
11
+ throw Error(`Environment variable ${envKey} can't be empty of undefined, got "${value}"`);
12
12
  }
13
13
  return !isFalsy(value);
14
14
  }
15
15
  }
16
16
  },
17
- configFileSelector: function (profile) {
17
+ configFileSelector: (profile) => {
18
18
  if (CONFIG_ENDPOINT_DISCOVERY in profile) {
19
- var value = profile[CONFIG_ENDPOINT_DISCOVERY];
19
+ const value = profile[CONFIG_ENDPOINT_DISCOVERY];
20
20
  if (value === undefined) {
21
- throw Error("Shared config entry ".concat(CONFIG_ENDPOINT_DISCOVERY, " can't be undefined, got \"").concat(value, "\""));
21
+ throw Error(`Shared config entry ${CONFIG_ENDPOINT_DISCOVERY} can't be undefined, got "${value}"`);
22
22
  }
23
23
  return !isFalsy(value);
24
24
  }
@@ -1,54 +1,44 @@
1
- import { __assign, __awaiter, __generator } from "tslib";
2
1
  import { HttpRequest } from "@aws-sdk/protocol-http";
3
2
  import { getCacheKey } from "./getCacheKey";
4
3
  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 ".concat(commandName, " on ").concat(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
- };
4
+ export const endpointDiscoveryMiddleware = (config, middlewareConfig) => (next, context) => async (args) => {
5
+ if (config.isCustomEndpoint) {
6
+ if (config.isClientEndpointDiscoveryEnabled) {
7
+ throw new Error(`Custom endpoint is supplied; endpointDiscoveryEnabled must not be true.`);
8
+ }
9
+ return next(args);
10
+ }
11
+ const { endpointDiscoveryCommandCtor } = config;
12
+ const { isDiscoveredEndpointRequired, identifiers } = middlewareConfig;
13
+ const { clientName, commandName } = context;
14
+ const isEndpointDiscoveryEnabled = await config.endpointDiscoveryEnabled();
15
+ const cacheKey = await getCacheKey(commandName, config, { identifiers });
16
+ if (isDiscoveredEndpointRequired) {
17
+ if (isEndpointDiscoveryEnabled === false) {
18
+ throw new Error(`Endpoint Discovery is disabled but ${commandName} on ${clientName} requires it.` +
19
+ ` Please check your configurations.`);
20
+ }
21
+ await updateDiscoveredEndpointInCache(config, {
22
+ ...middlewareConfig,
23
+ commandName,
24
+ cacheKey,
25
+ endpointDiscoveryCommandCtor,
26
+ });
27
+ }
28
+ else if (isEndpointDiscoveryEnabled) {
29
+ updateDiscoveredEndpointInCache(config, {
30
+ ...middlewareConfig,
31
+ commandName,
32
+ cacheKey,
33
+ endpointDiscoveryCommandCtor,
34
+ });
35
+ }
36
+ const { request } = args;
37
+ if (cacheKey && HttpRequest.isInstance(request)) {
38
+ const endpoint = config.endpointCache.getEndpoint(cacheKey);
39
+ if (endpoint) {
40
+ request.hostname = endpoint;
41
+ }
42
+ }
43
+ return next(args);
54
44
  };
@@ -1,22 +1,13 @@
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
- }
1
+ export const getCacheKey = async (commandName, config, options) => {
2
+ const { accessKeyId } = await config.credentials();
3
+ const { identifiers } = options;
4
+ return JSON.stringify({
5
+ ...(accessKeyId && { accessKeyId }),
6
+ ...(identifiers && {
7
+ commandName,
8
+ identifiers: Object.entries(identifiers)
9
+ .sort()
10
+ .reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {}),
11
+ }),
21
12
  });
22
- }); };
13
+ };
@@ -1,23 +1,22 @@
1
- import { __assign } from "tslib";
2
1
  import { endpointDiscoveryMiddleware } from "./endpointDiscoveryMiddleware";
3
- export var endpointDiscoveryMiddlewareOptions = {
2
+ export const endpointDiscoveryMiddlewareOptions = {
4
3
  name: "endpointDiscoveryMiddleware",
5
4
  step: "build",
6
5
  tags: ["ENDPOINT_DISCOVERY"],
7
6
  override: true,
8
7
  };
9
- export var getEndpointDiscoveryPlugin = function (pluginConfig, middlewareConfig) { return ({
10
- applyToStack: function (commandStack) {
8
+ export const getEndpointDiscoveryPlugin = (pluginConfig, middlewareConfig) => ({
9
+ applyToStack: (commandStack) => {
11
10
  commandStack.add(endpointDiscoveryMiddleware(pluginConfig, middlewareConfig), endpointDiscoveryMiddlewareOptions);
12
11
  },
13
- }); };
14
- export var getEndpointDiscoveryRequiredPlugin = function (pluginConfig, middlewareConfig) { return ({
15
- applyToStack: function (commandStack) {
16
- commandStack.add(endpointDiscoveryMiddleware(pluginConfig, __assign(__assign({}, middlewareConfig), { isDiscoveredEndpointRequired: true })), endpointDiscoveryMiddlewareOptions);
12
+ });
13
+ export const getEndpointDiscoveryRequiredPlugin = (pluginConfig, middlewareConfig) => ({
14
+ applyToStack: (commandStack) => {
15
+ commandStack.add(endpointDiscoveryMiddleware(pluginConfig, { ...middlewareConfig, isDiscoveredEndpointRequired: true }), endpointDiscoveryMiddlewareOptions);
17
16
  },
18
- }); };
19
- export var getEndpointDiscoveryOptionalPlugin = function (pluginConfig, middlewareConfig) { return ({
20
- applyToStack: function (commandStack) {
21
- commandStack.add(endpointDiscoveryMiddleware(pluginConfig, __assign(__assign({}, middlewareConfig), { isDiscoveredEndpointRequired: false })), endpointDiscoveryMiddlewareOptions);
17
+ });
18
+ export const getEndpointDiscoveryOptionalPlugin = (pluginConfig, middlewareConfig) => ({
19
+ applyToStack: (commandStack) => {
20
+ commandStack.add(endpointDiscoveryMiddleware(pluginConfig, { ...middlewareConfig, isDiscoveredEndpointRequired: false }), endpointDiscoveryMiddlewareOptions);
22
21
  },
23
- }); };
22
+ });
@@ -1,9 +1,10 @@
1
- import { __assign } from "tslib";
2
1
  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
- };
2
+ export const resolveEndpointDiscoveryConfig = (input, { endpointDiscoveryCommandCtor }) => ({
3
+ ...input,
4
+ endpointDiscoveryCommandCtor,
5
+ endpointCache: new EndpointCache(input.endpointCacheSize ?? 1000),
6
+ endpointDiscoveryEnabled: input.endpointDiscoveryEnabled !== undefined
7
+ ? () => Promise.resolve(input.endpointDiscoveryEnabled)
8
+ : input.endpointDiscoveryEnabledProvider,
9
+ isClientEndpointDiscoveryEnabled: input.endpointDiscoveryEnabled !== undefined,
10
+ });
@@ -1,67 +1,57 @@
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) {
1
+ const requestQueue = {};
2
+ export const updateDiscoveredEndpointInCache = async (config, options) => new Promise((resolve, reject) => {
3
+ const { endpointCache } = config;
4
+ const { cacheKey, commandName, identifiers } = options;
5
+ const endpoints = endpointCache.get(cacheKey);
6
+ if (endpoints && endpoints.length === 1 && endpoints[0].Address === "") {
7
+ if (options.isDiscoveredEndpointRequired) {
8
+ if (!requestQueue[cacheKey])
9
+ requestQueue[cacheKey] = [];
10
+ requestQueue[cacheKey].push({ resolve, reject });
11
+ }
12
+ else {
13
+ resolve();
14
+ }
15
+ }
16
+ else if (endpoints && endpoints.length > 0) {
17
+ resolve();
18
+ }
19
+ else {
20
+ const placeholderEndpoints = [{ Address: "", CachePeriodInMinutes: 1 }];
21
+ endpointCache.set(cacheKey, placeholderEndpoints);
22
+ const command = new options.endpointDiscoveryCommandCtor({
23
+ Operation: commandName.slice(0, -7),
24
+ Identifiers: identifiers,
25
+ });
26
+ const handler = command.resolveMiddleware(options.clientStack, config, options.options);
27
+ handler(command)
28
+ .then((result) => {
29
+ endpointCache.set(cacheKey, result.output.Endpoints);
30
+ if (requestQueue[cacheKey]) {
31
+ requestQueue[cacheKey].forEach(({ resolve }) => {
20
32
  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.slice(0, -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
- }); };
33
+ });
34
+ delete requestQueue[cacheKey];
35
+ }
36
+ resolve();
37
+ })
38
+ .catch((error) => {
39
+ endpointCache.delete(cacheKey);
40
+ const errorToThrow = Object.assign(new Error(`The operation to discover endpoint failed.` +
41
+ ` Please retry, or provide a custom endpoint and disable endpoint discovery to proceed.`), { reason: error });
42
+ if (requestQueue[cacheKey]) {
43
+ requestQueue[cacheKey].forEach(({ reject }) => {
44
+ reject(errorToThrow);
45
+ });
46
+ delete requestQueue[cacheKey];
47
+ }
48
+ if (options.isDiscoveredEndpointRequired) {
49
+ reject(errorToThrow);
50
+ }
51
+ else {
52
+ endpointCache.set(cacheKey, placeholderEndpoints);
53
+ resolve();
54
+ }
55
+ });
56
+ }
57
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/middleware-endpoint-discovery",
3
- "version": "3.171.0",
3
+ "version": "3.183.0",
4
4
  "scripts": {
5
5
  "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
6
6
  "build:cjs": "tsc -p tsconfig.cjs.json",
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "license": "Apache-2.0",
22
22
  "devDependencies": {
23
- "@aws-sdk/node-config-provider": "3.171.0",
23
+ "@aws-sdk/node-config-provider": "3.183.0",
24
24
  "@tsconfig/recommended": "1.0.1",
25
25
  "concurrently": "7.0.0",
26
26
  "downlevel-dts": "0.10.1",
@@ -29,10 +29,10 @@
29
29
  "typescript": "~4.6.2"
30
30
  },
31
31
  "dependencies": {
32
- "@aws-sdk/config-resolver": "3.171.0",
33
- "@aws-sdk/endpoint-cache": "3.170.0",
34
- "@aws-sdk/protocol-http": "3.171.0",
35
- "@aws-sdk/types": "3.171.0",
32
+ "@aws-sdk/config-resolver": "3.183.0",
33
+ "@aws-sdk/endpoint-cache": "3.183.0",
34
+ "@aws-sdk/protocol-http": "3.183.0",
35
+ "@aws-sdk/types": "3.183.0",
36
36
  "tslib": "^2.3.1"
37
37
  },
38
38
  "engines": {