@aws-sdk/util-endpoints 3.186.0 → 3.188.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 (33) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist-cjs/resolveEndpoint.js +13 -2
  3. package/dist-es/lib/aws/isVirtualHostableS3Bucket.js +4 -17
  4. package/dist-es/lib/aws/parseArn.js +7 -8
  5. package/dist-es/lib/aws/partition.js +22 -44
  6. package/dist-es/lib/booleanEquals.js +1 -1
  7. package/dist-es/lib/getAttr.js +9 -11
  8. package/dist-es/lib/getAttrPathList.js +17 -29
  9. package/dist-es/lib/isIpAddress.js +2 -4
  10. package/dist-es/lib/isSet.js +1 -1
  11. package/dist-es/lib/isValidHostLabel.js +6 -19
  12. package/dist-es/lib/not.js +1 -1
  13. package/dist-es/lib/parseURL.js +14 -15
  14. package/dist-es/lib/stringEquals.js +1 -1
  15. package/dist-es/lib/substring.js +1 -1
  16. package/dist-es/lib/uriEncode.js +1 -3
  17. package/dist-es/resolveEndpoint.js +23 -47
  18. package/dist-es/types/EndpointError.js +5 -10
  19. package/dist-es/utils/callFunction.js +3 -7
  20. package/dist-es/utils/evaluateCondition.js +7 -6
  21. package/dist-es/utils/evaluateConditions.js +14 -21
  22. package/dist-es/utils/evaluateEndpointRule.js +17 -11
  23. package/dist-es/utils/evaluateErrorRule.js +7 -5
  24. package/dist-es/utils/evaluateExpression.js +2 -2
  25. package/dist-es/utils/evaluateRules.js +17 -29
  26. package/dist-es/utils/evaluateTemplate.js +19 -20
  27. package/dist-es/utils/evaluateTreeRule.js +7 -5
  28. package/dist-es/utils/getEndpointHeaders.js +10 -14
  29. package/dist-es/utils/getEndpointProperties.js +4 -8
  30. package/dist-es/utils/getEndpointProperty.js +4 -4
  31. package/dist-es/utils/getEndpointUrl.js +4 -4
  32. package/dist-es/utils/getReferenceValue.js +5 -4
  33. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
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.188.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.187.0...v3.188.0) (2022-10-13)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **endpoint:** misc endpoints 2.0 fixes for s3 ([#4031](https://github.com/aws/aws-sdk-js-v3/issues/4031)) ([f8926a5](https://github.com/aws/aws-sdk-js-v3/commit/f8926a56cf9a25c2e6a5c91089543094e32d5c4b))
12
+
13
+
14
+
15
+
16
+
6
17
  # [3.186.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.185.0...v3.186.0) (2022-10-06)
7
18
 
8
19
  **Note:** Version bump only for package @aws-sdk/util-endpoints
@@ -4,7 +4,7 @@ exports.resolveEndpoint = void 0;
4
4
  const types_1 = require("./types");
5
5
  const utils_1 = require("./utils");
6
6
  const resolveEndpoint = (ruleSetObject, options) => {
7
- var _a;
7
+ var _a, _b;
8
8
  const { endpointParams, logger } = options;
9
9
  const { parameters, rules } = ruleSetObject;
10
10
  const paramsWithDefault = Object.entries(parameters)
@@ -23,6 +23,17 @@ const resolveEndpoint = (ruleSetObject, options) => {
23
23
  throw new types_1.EndpointError(`Missing required parameter: '${requiredParam}'`);
24
24
  }
25
25
  }
26
- return (0, utils_1.evaluateRules)(rules, { endpointParams, logger, referenceRecord: {} });
26
+ const endpoint = (0, utils_1.evaluateRules)(rules, { endpointParams, logger, referenceRecord: {} });
27
+ if ((_b = options.endpointParams) === null || _b === void 0 ? void 0 : _b.Endpoint) {
28
+ try {
29
+ const givenEndpoint = new URL(options.endpointParams.Endpoint);
30
+ const { protocol, port } = givenEndpoint;
31
+ endpoint.url.protocol = protocol;
32
+ endpoint.url.port = port;
33
+ }
34
+ catch (e) {
35
+ }
36
+ }
37
+ return endpoint;
27
38
  };
28
39
  exports.resolveEndpoint = resolveEndpoint;
@@ -1,25 +1,12 @@
1
- import { __values } from "tslib";
2
1
  import { isIpAddress } from "../isIpAddress";
3
2
  import { isValidHostLabel } from "../isValidHostLabel";
4
- export var isVirtualHostableS3Bucket = function (value, allowSubDomains) {
5
- var e_1, _a;
6
- if (allowSubDomains === void 0) { allowSubDomains = false; }
3
+ export const isVirtualHostableS3Bucket = (value, allowSubDomains = false) => {
7
4
  if (allowSubDomains) {
8
- try {
9
- for (var _b = __values(value.split(".")), _c = _b.next(); !_c.done; _c = _b.next()) {
10
- var label = _c.value;
11
- if (!isVirtualHostableS3Bucket(label)) {
12
- return false;
13
- }
5
+ for (const label of value.split(".")) {
6
+ if (!isVirtualHostableS3Bucket(label)) {
7
+ return false;
14
8
  }
15
9
  }
16
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
17
- finally {
18
- try {
19
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
20
- }
21
- finally { if (e_1) throw e_1.error; }
22
- }
23
10
  return true;
24
11
  }
25
12
  if (!isValidHostLabel(value)) {
@@ -1,16 +1,15 @@
1
- import { __read } from "tslib";
2
- export var parseArn = function (value) {
3
- var segments = value.split(":");
1
+ export const parseArn = (value) => {
2
+ const segments = value.split(":");
4
3
  if (segments.length < 6)
5
4
  return null;
6
- var _a = __read(segments), arn = _a[0], partition = _a[1], service = _a[2], region = _a[3], accountId = _a[4], resourceId = _a.slice(5);
5
+ const [arn, partition, service, region, accountId, ...resourceId] = segments;
7
6
  if (arn !== "arn" || partition === "" || service === "" || resourceId[0] === "")
8
7
  return null;
9
8
  return {
10
- partition: partition,
11
- service: service,
12
- region: region,
13
- accountId: accountId,
9
+ partition,
10
+ service,
11
+ region,
12
+ accountId,
14
13
  resourceId: resourceId[0].includes("/") ? resourceId[0].split("/") : resourceId,
15
14
  };
16
15
  };
@@ -1,55 +1,33 @@
1
- import { __assign, __read, __values } from "tslib";
2
1
  import { partitions } from "./partitions.json";
3
- var DEFAULT_PARTITION = partitions.find(function (partition) { return partition.id === "aws"; });
4
- export var partition = function (value) {
5
- var e_1, _a, e_2, _b, e_3, _c;
6
- try {
7
- for (var partitions_1 = __values(partitions), partitions_1_1 = partitions_1.next(); !partitions_1_1.done; partitions_1_1 = partitions_1.next()) {
8
- var partition_1 = partitions_1_1.value;
9
- var id = partition_1.id, regions = partition_1.regions, outputs = partition_1.outputs;
10
- try {
11
- for (var _d = (e_2 = void 0, __values(Object.entries(regions))), _e = _d.next(); !_e.done; _e = _d.next()) {
12
- var _f = __read(_e.value, 2), region = _f[0], regionData = _f[1];
13
- if (region === value) {
14
- return __assign(__assign({ name: id }, outputs), regionData);
15
- }
16
- }
17
- }
18
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
19
- finally {
20
- try {
21
- if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
22
- }
23
- finally { if (e_2) throw e_2.error; }
24
- }
25
- }
26
- }
27
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
28
- finally {
29
- try {
30
- if (partitions_1_1 && !partitions_1_1.done && (_a = partitions_1.return)) _a.call(partitions_1);
31
- }
32
- finally { if (e_1) throw e_1.error; }
33
- }
34
- try {
35
- for (var partitions_2 = __values(partitions), partitions_2_1 = partitions_2.next(); !partitions_2_1.done; partitions_2_1 = partitions_2.next()) {
36
- var partition_2 = partitions_2_1.value;
37
- var id = partition_2.id, regionRegex = partition_2.regionRegex, outputs = partition_2.outputs;
38
- if (new RegExp(regionRegex).test(value)) {
39
- return __assign({ name: id }, outputs);
2
+ const DEFAULT_PARTITION = partitions.find((partition) => partition.id === "aws");
3
+ export const partition = (value) => {
4
+ for (const partition of partitions) {
5
+ const { id, regions, outputs } = partition;
6
+ for (const [region, regionData] of Object.entries(regions)) {
7
+ if (region === value) {
8
+ return {
9
+ name: id,
10
+ ...outputs,
11
+ ...regionData,
12
+ };
40
13
  }
41
14
  }
42
15
  }
43
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
44
- finally {
45
- try {
46
- if (partitions_2_1 && !partitions_2_1.done && (_c = partitions_2.return)) _c.call(partitions_2);
16
+ for (const partition of partitions) {
17
+ const { id, regionRegex, outputs } = partition;
18
+ if (new RegExp(regionRegex).test(value)) {
19
+ return {
20
+ name: id,
21
+ ...outputs,
22
+ };
47
23
  }
48
- finally { if (e_3) throw e_3.error; }
49
24
  }
50
25
  if (!DEFAULT_PARTITION) {
51
26
  throw new Error("Provided region was not found in the partition array or regex," +
52
27
  " and default partition with id 'aws' doesn't exist.");
53
28
  }
54
- return __assign({ name: DEFAULT_PARTITION.id }, DEFAULT_PARTITION.outputs);
29
+ return {
30
+ name: DEFAULT_PARTITION.id,
31
+ ...DEFAULT_PARTITION.outputs,
32
+ };
55
33
  };
@@ -1 +1 @@
1
- export var booleanEquals = function (value1, value2) { return value1 === value2; };
1
+ export const booleanEquals = (value1, value2) => value1 === value2;
@@ -1,13 +1,11 @@
1
1
  import { EndpointError } from "../types";
2
2
  import { getAttrPathList } from "./getAttrPathList";
3
- export var getAttr = function (value, path) {
4
- return getAttrPathList(path).reduce(function (acc, index) {
5
- if (typeof acc !== "object") {
6
- throw new EndpointError("Index '".concat(index, "' in '").concat(path, "' not found in '").concat(JSON.stringify(value), "'"));
7
- }
8
- else if (Array.isArray(acc)) {
9
- return acc[parseInt(index)];
10
- }
11
- return acc[index];
12
- }, value);
13
- };
3
+ export const getAttr = (value, path) => getAttrPathList(path).reduce((acc, index) => {
4
+ if (typeof acc !== "object") {
5
+ throw new EndpointError(`Index '${index}' in '${path}' not found in '${JSON.stringify(value)}'`);
6
+ }
7
+ else if (Array.isArray(acc)) {
8
+ return acc[parseInt(index)];
9
+ }
10
+ return acc[index];
11
+ }, value);
@@ -1,37 +1,25 @@
1
- import { __values } from "tslib";
2
1
  import { EndpointError } from "../types";
3
- export var getAttrPathList = function (path) {
4
- var e_1, _a;
5
- var parts = path.split(".");
6
- var pathList = [];
7
- try {
8
- for (var parts_1 = __values(parts), parts_1_1 = parts_1.next(); !parts_1_1.done; parts_1_1 = parts_1.next()) {
9
- var part = parts_1_1.value;
10
- var squareBracketIndex = part.indexOf("[");
11
- if (squareBracketIndex !== -1) {
12
- if (part.indexOf("]") !== part.length - 1) {
13
- throw new EndpointError("Path: '".concat(path, "' does not end with ']'"));
14
- }
15
- var arrayIndex = part.slice(squareBracketIndex + 1, -1);
16
- if (Number.isNaN(parseInt(arrayIndex))) {
17
- throw new EndpointError("Invalid array index: '".concat(arrayIndex, "' in path: '").concat(path, "'"));
18
- }
19
- if (squareBracketIndex !== 0) {
20
- pathList.push(part.slice(0, squareBracketIndex));
21
- }
22
- pathList.push(arrayIndex);
2
+ export const getAttrPathList = (path) => {
3
+ const parts = path.split(".");
4
+ const pathList = [];
5
+ for (const part of parts) {
6
+ const squareBracketIndex = part.indexOf("[");
7
+ if (squareBracketIndex !== -1) {
8
+ if (part.indexOf("]") !== part.length - 1) {
9
+ throw new EndpointError(`Path: '${path}' does not end with ']'`);
23
10
  }
24
- else {
25
- pathList.push(part);
11
+ const arrayIndex = part.slice(squareBracketIndex + 1, -1);
12
+ if (Number.isNaN(parseInt(arrayIndex))) {
13
+ throw new EndpointError(`Invalid array index: '${arrayIndex}' in path: '${path}'`);
26
14
  }
15
+ if (squareBracketIndex !== 0) {
16
+ pathList.push(part.slice(0, squareBracketIndex));
17
+ }
18
+ pathList.push(arrayIndex);
27
19
  }
28
- }
29
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
30
- finally {
31
- try {
32
- if (parts_1_1 && !parts_1_1.done && (_a = parts_1.return)) _a.call(parts_1);
20
+ else {
21
+ pathList.push(part);
33
22
  }
34
- finally { if (e_1) throw e_1.error; }
35
23
  }
36
24
  return pathList;
37
25
  };
@@ -1,4 +1,2 @@
1
- var IP_V4_REGEX = new RegExp("^(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}$");
2
- export var isIpAddress = function (value) {
3
- return IP_V4_REGEX.test(value) || (value.startsWith("[") && value.endsWith("]"));
4
- };
1
+ const IP_V4_REGEX = new RegExp(`^(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}$`);
2
+ export const isIpAddress = (value) => IP_V4_REGEX.test(value) || (value.startsWith("[") && value.endsWith("]"));
@@ -1 +1 @@
1
- export var isSet = function (value) { return value != null; };
1
+ export const isSet = (value) => value != null;
@@ -1,26 +1,13 @@
1
- import { __values } from "tslib";
2
- var VALID_HOST_LABEL_REGEX = new RegExp("^(?!.*-$)(?!-)[a-zA-Z0-9-]{1,63}$");
3
- export var isValidHostLabel = function (value, allowSubDomains) {
4
- var e_1, _a;
5
- if (allowSubDomains === void 0) { allowSubDomains = false; }
1
+ const VALID_HOST_LABEL_REGEX = new RegExp(`^(?!.*-$)(?!-)[a-zA-Z0-9-]{1,63}$`);
2
+ export const isValidHostLabel = (value, allowSubDomains = false) => {
6
3
  if (!allowSubDomains) {
7
4
  return VALID_HOST_LABEL_REGEX.test(value);
8
5
  }
9
- var labels = value.split(".");
10
- try {
11
- for (var labels_1 = __values(labels), labels_1_1 = labels_1.next(); !labels_1_1.done; labels_1_1 = labels_1.next()) {
12
- var label = labels_1_1.value;
13
- if (!isValidHostLabel(label)) {
14
- return false;
15
- }
6
+ const labels = value.split(".");
7
+ for (const label of labels) {
8
+ if (!isValidHostLabel(label)) {
9
+ return false;
16
10
  }
17
11
  }
18
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
19
- finally {
20
- try {
21
- if (labels_1_1 && !labels_1_1.done && (_a = labels_1.return)) _a.call(labels_1);
22
- }
23
- finally { if (e_1) throw e_1.error; }
24
- }
25
12
  return true;
26
13
  };
@@ -1 +1 @@
1
- export var not = function (value) { return !value; };
1
+ export const not = (value) => !value;
@@ -1,12 +1,11 @@
1
- var _a;
2
1
  import { EndpointURLScheme } from "@aws-sdk/types";
3
2
  import { isIpAddress } from "./isIpAddress";
4
- var DEFAULT_PORTS = (_a = {},
5
- _a[EndpointURLScheme.HTTP] = 80,
6
- _a[EndpointURLScheme.HTTPS] = 443,
7
- _a);
8
- export var parseURL = function (value) {
9
- var whatwgURL = (function () {
3
+ const DEFAULT_PORTS = {
4
+ [EndpointURLScheme.HTTP]: 80,
5
+ [EndpointURLScheme.HTTPS]: 443,
6
+ };
7
+ export const parseURL = (value) => {
8
+ const whatwgURL = (() => {
10
9
  try {
11
10
  return new URL(value);
12
11
  }
@@ -17,21 +16,21 @@ export var parseURL = function (value) {
17
16
  if (!whatwgURL) {
18
17
  return null;
19
18
  }
20
- var host = whatwgURL.host, hostname = whatwgURL.hostname, pathname = whatwgURL.pathname, protocol = whatwgURL.protocol, search = whatwgURL.search;
19
+ const { host, hostname, pathname, protocol, search } = whatwgURL;
21
20
  if (search) {
22
21
  return null;
23
22
  }
24
- var scheme = protocol.slice(0, -1);
23
+ const scheme = protocol.slice(0, -1);
25
24
  if (!Object.values(EndpointURLScheme).includes(scheme)) {
26
25
  return null;
27
26
  }
28
- var isIp = isIpAddress(hostname);
29
- var authority = "".concat(host).concat(value.includes("".concat(host, ":").concat(DEFAULT_PORTS[scheme])) ? ":".concat(DEFAULT_PORTS[scheme]) : "");
27
+ const isIp = isIpAddress(hostname);
28
+ const authority = `${host}${value.includes(`${host}:${DEFAULT_PORTS[scheme]}`) ? `:${DEFAULT_PORTS[scheme]}` : ``}`;
30
29
  return {
31
- scheme: scheme,
32
- authority: authority,
30
+ scheme,
31
+ authority,
33
32
  path: pathname,
34
- normalizedPath: pathname.endsWith("/") ? pathname : "".concat(pathname, "/"),
35
- isIp: isIp,
33
+ normalizedPath: pathname.endsWith("/") ? pathname : `${pathname}/`,
34
+ isIp,
36
35
  };
37
36
  };
@@ -1 +1 @@
1
- export var stringEquals = function (value1, value2) { return value1 === value2; };
1
+ export const stringEquals = (value1, value2) => value1 === value2;
@@ -1,4 +1,4 @@
1
- export var substring = function (input, start, stop, reverse) {
1
+ export const substring = (input, start, stop, reverse) => {
2
2
  if (start >= stop || input.length < stop) {
3
3
  return null;
4
4
  }
@@ -1,3 +1 @@
1
- export var uriEncode = function (value) {
2
- return encodeURIComponent(value).replace(/[!*'()]/g, function (c) { return "%".concat(c.charCodeAt(0).toString(16).toUpperCase()); });
3
- };
1
+ export const uriEncode = (value) => encodeURIComponent(value).replace(/[!*'()]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`);
@@ -1,58 +1,34 @@
1
- import { __read, __values } from "tslib";
2
1
  import { EndpointError } from "./types";
3
2
  import { evaluateRules } from "./utils";
4
- export var resolveEndpoint = function (ruleSetObject, options) {
5
- var e_1, _a, e_2, _b;
6
- var _c;
7
- var endpointParams = options.endpointParams, logger = options.logger;
8
- var parameters = ruleSetObject.parameters, rules = ruleSetObject.rules;
9
- var paramsWithDefault = Object.entries(parameters)
10
- .filter(function (_a) {
11
- var _b = __read(_a, 2), v = _b[1];
12
- return v.default != null;
13
- })
14
- .map(function (_a) {
15
- var _b = __read(_a, 2), k = _b[0], v = _b[1];
16
- return [k, v.default];
17
- });
3
+ export const resolveEndpoint = (ruleSetObject, options) => {
4
+ const { endpointParams, logger } = options;
5
+ const { parameters, rules } = ruleSetObject;
6
+ const paramsWithDefault = Object.entries(parameters)
7
+ .filter(([, v]) => v.default != null)
8
+ .map(([k, v]) => [k, v.default]);
18
9
  if (paramsWithDefault.length > 0) {
19
- try {
20
- for (var paramsWithDefault_1 = __values(paramsWithDefault), paramsWithDefault_1_1 = paramsWithDefault_1.next(); !paramsWithDefault_1_1.done; paramsWithDefault_1_1 = paramsWithDefault_1.next()) {
21
- var _d = __read(paramsWithDefault_1_1.value, 2), paramKey = _d[0], paramDefaultValue = _d[1];
22
- endpointParams[paramKey] = (_c = endpointParams[paramKey]) !== null && _c !== void 0 ? _c : paramDefaultValue;
23
- }
24
- }
25
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
26
- finally {
27
- try {
28
- if (paramsWithDefault_1_1 && !paramsWithDefault_1_1.done && (_a = paramsWithDefault_1.return)) _a.call(paramsWithDefault_1);
29
- }
30
- finally { if (e_1) throw e_1.error; }
10
+ for (const [paramKey, paramDefaultValue] of paramsWithDefault) {
11
+ endpointParams[paramKey] = endpointParams[paramKey] ?? paramDefaultValue;
31
12
  }
32
13
  }
33
- var requiredParams = Object.entries(parameters)
34
- .filter(function (_a) {
35
- var _b = __read(_a, 2), v = _b[1];
36
- return v.required;
37
- })
38
- .map(function (_a) {
39
- var _b = __read(_a, 1), k = _b[0];
40
- return k;
41
- });
42
- try {
43
- for (var requiredParams_1 = __values(requiredParams), requiredParams_1_1 = requiredParams_1.next(); !requiredParams_1_1.done; requiredParams_1_1 = requiredParams_1.next()) {
44
- var requiredParam = requiredParams_1_1.value;
45
- if (endpointParams[requiredParam] == null) {
46
- throw new EndpointError("Missing required parameter: '".concat(requiredParam, "'"));
47
- }
14
+ const requiredParams = Object.entries(parameters)
15
+ .filter(([, v]) => v.required)
16
+ .map(([k]) => k);
17
+ for (const requiredParam of requiredParams) {
18
+ if (endpointParams[requiredParam] == null) {
19
+ throw new EndpointError(`Missing required parameter: '${requiredParam}'`);
48
20
  }
49
21
  }
50
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
51
- finally {
22
+ const endpoint = evaluateRules(rules, { endpointParams, logger, referenceRecord: {} });
23
+ if (options.endpointParams?.Endpoint) {
52
24
  try {
53
- if (requiredParams_1_1 && !requiredParams_1_1.done && (_b = requiredParams_1.return)) _b.call(requiredParams_1);
25
+ const givenEndpoint = new URL(options.endpointParams.Endpoint);
26
+ const { protocol, port } = givenEndpoint;
27
+ endpoint.url.protocol = protocol;
28
+ endpoint.url.port = port;
29
+ }
30
+ catch (e) {
54
31
  }
55
- finally { if (e_2) throw e_2.error; }
56
32
  }
57
- return evaluateRules(rules, { endpointParams: endpointParams, logger: logger, referenceRecord: {} });
33
+ return endpoint;
58
34
  };
@@ -1,11 +1,6 @@
1
- import { __extends } from "tslib";
2
- var EndpointError = (function (_super) {
3
- __extends(EndpointError, _super);
4
- function EndpointError(message) {
5
- var _this = _super.call(this, message) || this;
6
- _this.name = "EndpointError";
7
- return _this;
1
+ export class EndpointError extends Error {
2
+ constructor(message) {
3
+ super(message);
4
+ this.name = "EndpointError";
8
5
  }
9
- return EndpointError;
10
- }(Error));
11
- export { EndpointError };
6
+ }
@@ -1,10 +1,6 @@
1
- import { __read, __spreadArray } from "tslib";
2
1
  import * as lib from "../lib";
3
2
  import { evaluateExpression } from "./evaluateExpression";
4
- export var callFunction = function (_a, options) {
5
- var fn = _a.fn, argv = _a.argv;
6
- var evaluatedArgs = argv.map(function (arg) {
7
- return ["boolean", "number"].includes(typeof arg) ? arg : evaluateExpression(arg, "arg", options);
8
- });
9
- return fn.split(".").reduce(function (acc, key) { return acc[key]; }, lib).apply(void 0, __spreadArray([], __read(evaluatedArgs), false));
3
+ export const callFunction = ({ fn, argv }, options) => {
4
+ const evaluatedArgs = argv.map((arg) => ["boolean", "number"].includes(typeof arg) ? arg : evaluateExpression(arg, "arg", options));
5
+ return fn.split(".").reduce((acc, key) => acc[key], lib)(...evaluatedArgs);
10
6
  };
@@ -1,11 +1,12 @@
1
- import { __assign, __rest } from "tslib";
2
1
  import { EndpointError } from "../types";
3
2
  import { callFunction } from "./callFunction";
4
- export var evaluateCondition = function (_a, options) {
5
- var assign = _a.assign, fnArgs = __rest(_a, ["assign"]);
3
+ export const evaluateCondition = ({ assign, ...fnArgs }, options) => {
6
4
  if (assign && assign in options.referenceRecord) {
7
- throw new EndpointError("'".concat(assign, "' is already defined in Reference Record."));
5
+ throw new EndpointError(`'${assign}' is already defined in Reference Record.`);
8
6
  }
9
- var value = callFunction(fnArgs, options);
10
- return __assign({ result: value === "" ? true : !!value }, (assign != null && { toAssign: { name: assign, value: value } }));
7
+ const value = callFunction(fnArgs, options);
8
+ return {
9
+ result: value === "" ? true : !!value,
10
+ ...(assign != null && { toAssign: { name: assign, value } }),
11
+ };
11
12
  };
@@ -1,27 +1,20 @@
1
- import { __assign, __values } from "tslib";
2
1
  import { evaluateCondition } from "./evaluateCondition";
3
- export var evaluateConditions = function (conditions, options) {
4
- var e_1, _a;
5
- if (conditions === void 0) { conditions = []; }
6
- var conditionsReferenceRecord = {};
7
- try {
8
- for (var conditions_1 = __values(conditions), conditions_1_1 = conditions_1.next(); !conditions_1_1.done; conditions_1_1 = conditions_1.next()) {
9
- var condition = conditions_1_1.value;
10
- var _b = evaluateCondition(condition, __assign(__assign({}, options), { referenceRecord: __assign(__assign({}, options.referenceRecord), conditionsReferenceRecord) })), result = _b.result, toAssign = _b.toAssign;
11
- if (!result) {
12
- return { result: result };
13
- }
14
- if (toAssign) {
15
- conditionsReferenceRecord[toAssign.name] = toAssign.value;
16
- }
2
+ export const evaluateConditions = (conditions = [], options) => {
3
+ const conditionsReferenceRecord = {};
4
+ for (const condition of conditions) {
5
+ const { result, toAssign } = evaluateCondition(condition, {
6
+ ...options,
7
+ referenceRecord: {
8
+ ...options.referenceRecord,
9
+ ...conditionsReferenceRecord,
10
+ },
11
+ });
12
+ if (!result) {
13
+ return { result };
17
14
  }
18
- }
19
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
20
- finally {
21
- try {
22
- if (conditions_1_1 && !conditions_1_1.done && (_a = conditions_1.return)) _a.call(conditions_1);
15
+ if (toAssign) {
16
+ conditionsReferenceRecord[toAssign.name] = toAssign.value;
23
17
  }
24
- finally { if (e_1) throw e_1.error; }
25
18
  }
26
19
  return { result: true, referenceRecord: conditionsReferenceRecord };
27
20
  };
@@ -1,19 +1,25 @@
1
- import { __assign } from "tslib";
2
1
  import { evaluateConditions } from "./evaluateConditions";
3
2
  import { getEndpointHeaders } from "./getEndpointHeaders";
4
3
  import { getEndpointProperties } from "./getEndpointProperties";
5
4
  import { getEndpointUrl } from "./getEndpointUrl";
6
- export var evaluateEndpointRule = function (endpointRule, options) {
7
- var conditions = endpointRule.conditions, endpoint = endpointRule.endpoint;
8
- var _a = evaluateConditions(conditions, options), result = _a.result, referenceRecord = _a.referenceRecord;
5
+ export const evaluateEndpointRule = (endpointRule, options) => {
6
+ const { conditions, endpoint } = endpointRule;
7
+ const { result, referenceRecord } = evaluateConditions(conditions, options);
9
8
  if (!result) {
10
9
  return;
11
10
  }
12
- var endpointRuleOptions = __assign(__assign({}, options), { referenceRecord: __assign(__assign({}, options.referenceRecord), referenceRecord) });
13
- var url = endpoint.url, properties = endpoint.properties, headers = endpoint.headers;
14
- return __assign(__assign(__assign({}, (headers != undefined && {
15
- headers: getEndpointHeaders(headers, endpointRuleOptions),
16
- })), (properties != undefined && {
17
- properties: getEndpointProperties(properties, endpointRuleOptions),
18
- })), { url: getEndpointUrl(url, endpointRuleOptions) });
11
+ const endpointRuleOptions = {
12
+ ...options,
13
+ referenceRecord: { ...options.referenceRecord, ...referenceRecord },
14
+ };
15
+ const { url, properties, headers } = endpoint;
16
+ return {
17
+ ...(headers != undefined && {
18
+ headers: getEndpointHeaders(headers, endpointRuleOptions),
19
+ }),
20
+ ...(properties != undefined && {
21
+ properties: getEndpointProperties(properties, endpointRuleOptions),
22
+ }),
23
+ url: getEndpointUrl(url, endpointRuleOptions),
24
+ };
19
25
  };
@@ -1,12 +1,14 @@
1
- import { __assign } from "tslib";
2
1
  import { EndpointError } from "../types";
3
2
  import { evaluateConditions } from "./evaluateConditions";
4
3
  import { evaluateExpression } from "./evaluateExpression";
5
- export var evaluateErrorRule = function (errorRule, options) {
6
- var conditions = errorRule.conditions, error = errorRule.error;
7
- var _a = evaluateConditions(conditions, options), result = _a.result, referenceRecord = _a.referenceRecord;
4
+ export const evaluateErrorRule = (errorRule, options) => {
5
+ const { conditions, error } = errorRule;
6
+ const { result, referenceRecord } = evaluateConditions(conditions, options);
8
7
  if (!result) {
9
8
  return;
10
9
  }
11
- throw new EndpointError(evaluateExpression(error, "Error", __assign(__assign({}, options), { referenceRecord: __assign(__assign({}, options.referenceRecord), referenceRecord) })));
10
+ throw new EndpointError(evaluateExpression(error, "Error", {
11
+ ...options,
12
+ referenceRecord: { ...options.referenceRecord, ...referenceRecord },
13
+ }));
12
14
  };
@@ -2,7 +2,7 @@ import { EndpointError } from "../types";
2
2
  import { callFunction } from "./callFunction";
3
3
  import { evaluateTemplate } from "./evaluateTemplate";
4
4
  import { getReferenceValue } from "./getReferenceValue";
5
- export var evaluateExpression = function (obj, keyName, options) {
5
+ export const evaluateExpression = (obj, keyName, options) => {
6
6
  if (typeof obj === "string") {
7
7
  return evaluateTemplate(obj, options);
8
8
  }
@@ -12,5 +12,5 @@ export var evaluateExpression = function (obj, keyName, options) {
12
12
  else if (obj["ref"]) {
13
13
  return getReferenceValue(obj, options);
14
14
  }
15
- throw new EndpointError("'".concat(keyName, "': ").concat(String(obj), " is not a string, function or reference."));
15
+ throw new EndpointError(`'${keyName}': ${String(obj)} is not a string, function or reference.`);
16
16
  };
@@ -1,39 +1,27 @@
1
- import { __values } from "tslib";
2
1
  import { EndpointError } from "../types";
3
2
  import { evaluateEndpointRule } from "./evaluateEndpointRule";
4
3
  import { evaluateErrorRule } from "./evaluateErrorRule";
5
4
  import { evaluateTreeRule } from "./evaluateTreeRule";
6
- export var evaluateRules = function (rules, options) {
7
- var e_1, _a;
8
- try {
9
- for (var rules_1 = __values(rules), rules_1_1 = rules_1.next(); !rules_1_1.done; rules_1_1 = rules_1.next()) {
10
- var rule = rules_1_1.value;
11
- if (rule.type === "endpoint") {
12
- var endpointOrUndefined = evaluateEndpointRule(rule, options);
13
- if (endpointOrUndefined) {
14
- return endpointOrUndefined;
15
- }
5
+ export const evaluateRules = (rules, options) => {
6
+ for (const rule of rules) {
7
+ if (rule.type === "endpoint") {
8
+ const endpointOrUndefined = evaluateEndpointRule(rule, options);
9
+ if (endpointOrUndefined) {
10
+ return endpointOrUndefined;
16
11
  }
17
- else if (rule.type === "error") {
18
- evaluateErrorRule(rule, options);
19
- }
20
- else if (rule.type === "tree") {
21
- var endpointOrUndefined = evaluateTreeRule(rule, options);
22
- if (endpointOrUndefined) {
23
- return endpointOrUndefined;
24
- }
25
- }
26
- else {
27
- throw new EndpointError("Unknown endpoint rule: ".concat(rule));
12
+ }
13
+ else if (rule.type === "error") {
14
+ evaluateErrorRule(rule, options);
15
+ }
16
+ else if (rule.type === "tree") {
17
+ const endpointOrUndefined = evaluateTreeRule(rule, options);
18
+ if (endpointOrUndefined) {
19
+ return endpointOrUndefined;
28
20
  }
29
21
  }
30
- }
31
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
32
- finally {
33
- try {
34
- if (rules_1_1 && !rules_1_1.done && (_a = rules_1.return)) _a.call(rules_1);
22
+ else {
23
+ throw new EndpointError(`Unknown endpoint rule: ${rule}`);
35
24
  }
36
- finally { if (e_1) throw e_1.error; }
37
25
  }
38
- throw new EndpointError("Rules evaluation failed");
26
+ throw new EndpointError(`Rules evaluation failed`);
39
27
  };
@@ -1,25 +1,24 @@
1
- import { __assign, __read, __spreadArray } from "tslib";
2
1
  import { getAttr } from "../lib";
3
- var ATTR_SHORTHAND_REGEX = new RegExp("\\${([\\w]+)#([\\w]+)}", "g");
4
- export var evaluateTemplate = function (template, options) {
5
- var templateToEvaluate = template
6
- .replace(new RegExp("{([^{}]+)}", "g"), "${$1}")
7
- .replace(new RegExp("{\\${([^{}]+)}}", "g"), "{$1}");
8
- var templateContext = __assign(__assign({}, options.endpointParams), options.referenceRecord);
9
- var attrShortHandList = templateToEvaluate.match(ATTR_SHORTHAND_REGEX) || [];
10
- var attrShortHandMap = attrShortHandList.reduce(function (acc, attrShortHand) {
11
- var indexOfHash = attrShortHand.indexOf("#");
12
- var refName = attrShortHand.substring(2, indexOfHash);
13
- var attrName = attrShortHand.substring(indexOfHash + 1, attrShortHand.length - 1);
2
+ const ATTR_SHORTHAND_REGEX = new RegExp("\\${([\\w]+)#([\\w]+)}", "g");
3
+ export const evaluateTemplate = (template, options) => {
4
+ const templateToEvaluate = template
5
+ .replace(new RegExp(`\{([^{}]+)\}`, "g"), "${$1}")
6
+ .replace(new RegExp(`\{\\$\{([^{}]+)\}\}`, "g"), "{$1}");
7
+ const templateContext = {
8
+ ...options.endpointParams,
9
+ ...options.referenceRecord,
10
+ };
11
+ const attrShortHandList = templateToEvaluate.match(ATTR_SHORTHAND_REGEX) || [];
12
+ const attrShortHandMap = attrShortHandList.reduce((acc, attrShortHand) => {
13
+ const indexOfHash = attrShortHand.indexOf("#");
14
+ const refName = attrShortHand.substring(2, indexOfHash);
15
+ const attrName = attrShortHand.substring(indexOfHash + 1, attrShortHand.length - 1);
14
16
  acc[attrShortHand] = getAttr(templateContext[refName], attrName);
15
17
  return acc;
16
18
  }, {});
17
- var templateWithAttr = Object.entries(attrShortHandMap).reduce(function (acc, _a) {
18
- var _b = __read(_a, 2), shortHand = _b[0], value = _b[1];
19
- return acc.replace(shortHand, value);
20
- }, templateToEvaluate);
21
- var templateContextNames = Object.keys(templateContext);
22
- var templateContextValues = Object.values(templateContext);
23
- var templateWithTildeEscaped = templateWithAttr.replace(/\`/g, "\\`");
24
- return new (Function.bind.apply(Function, __spreadArray(__spreadArray([void 0], __read(templateContextNames), false), ["return `".concat(templateWithTildeEscaped, "`")], false)))().apply(void 0, __spreadArray([], __read(templateContextValues), false));
19
+ const templateWithAttr = Object.entries(attrShortHandMap).reduce((acc, [shortHand, value]) => acc.replace(shortHand, value), templateToEvaluate);
20
+ const templateContextNames = Object.keys(templateContext);
21
+ const templateContextValues = Object.values(templateContext);
22
+ const templateWithTildeEscaped = templateWithAttr.replace(/\`/g, "\\`");
23
+ return new Function(...templateContextNames, `return \`${templateWithTildeEscaped}\``)(...templateContextValues);
25
24
  };
@@ -1,11 +1,13 @@
1
- import { __assign } from "tslib";
2
1
  import { evaluateConditions } from "./evaluateConditions";
3
2
  import { evaluateRules } from "./evaluateRules";
4
- export var evaluateTreeRule = function (treeRule, options) {
5
- var conditions = treeRule.conditions, rules = treeRule.rules;
6
- var _a = evaluateConditions(conditions, options), result = _a.result, referenceRecord = _a.referenceRecord;
3
+ export const evaluateTreeRule = (treeRule, options) => {
4
+ const { conditions, rules } = treeRule;
5
+ const { result, referenceRecord } = evaluateConditions(conditions, options);
7
6
  if (!result) {
8
7
  return;
9
8
  }
10
- return evaluateRules(rules, __assign(__assign({}, options), { referenceRecord: __assign(__assign({}, options.referenceRecord), referenceRecord) }));
9
+ return evaluateRules(rules, {
10
+ ...options,
11
+ referenceRecord: { ...options.referenceRecord, ...referenceRecord },
12
+ });
11
13
  };
@@ -1,16 +1,12 @@
1
- import { __assign, __read } from "tslib";
2
1
  import { EndpointError } from "../types";
3
2
  import { evaluateExpression } from "./evaluateExpression";
4
- export var getEndpointHeaders = function (headers, options) {
5
- return Object.entries(headers).reduce(function (acc, _a) {
6
- var _b;
7
- var _c = __read(_a, 2), headerKey = _c[0], headerVal = _c[1];
8
- return (__assign(__assign({}, acc), (_b = {}, _b[headerKey] = headerVal.map(function (headerValEntry) {
9
- var processedExpr = evaluateExpression(headerValEntry, "Header value entry", options);
10
- if (typeof processedExpr !== "string") {
11
- throw new EndpointError("Header '".concat(headerKey, "' value '").concat(processedExpr, "' is not a string"));
12
- }
13
- return processedExpr;
14
- }), _b)));
15
- }, {});
16
- };
3
+ export const getEndpointHeaders = (headers, options) => Object.entries(headers).reduce((acc, [headerKey, headerVal]) => ({
4
+ ...acc,
5
+ [headerKey]: headerVal.map((headerValEntry) => {
6
+ const processedExpr = evaluateExpression(headerValEntry, "Header value entry", options);
7
+ if (typeof processedExpr !== "string") {
8
+ throw new EndpointError(`Header '${headerKey}' value '${processedExpr}' is not a string`);
9
+ }
10
+ return processedExpr;
11
+ }),
12
+ }), {});
@@ -1,9 +1,5 @@
1
- import { __assign, __read } from "tslib";
2
1
  import { getEndpointProperty } from "./getEndpointProperty";
3
- export var getEndpointProperties = function (properties, options) {
4
- return Object.entries(properties).reduce(function (acc, _a) {
5
- var _b;
6
- var _c = __read(_a, 2), propertyKey = _c[0], propertyVal = _c[1];
7
- return (__assign(__assign({}, acc), (_b = {}, _b[propertyKey] = getEndpointProperty(propertyVal, options), _b)));
8
- }, {});
9
- };
2
+ export const getEndpointProperties = (properties, options) => Object.entries(properties).reduce((acc, [propertyKey, propertyVal]) => ({
3
+ ...acc,
4
+ [propertyKey]: getEndpointProperty(propertyVal, options),
5
+ }), {});
@@ -1,21 +1,21 @@
1
1
  import { EndpointError } from "../types";
2
2
  import { evaluateTemplate } from "./evaluateTemplate";
3
3
  import { getEndpointProperties } from "./getEndpointProperties";
4
- export var getEndpointProperty = function (property, options) {
4
+ export const getEndpointProperty = (property, options) => {
5
5
  if (Array.isArray(property)) {
6
- return property.map(function (propertyEntry) { return getEndpointProperty(propertyEntry, options); });
6
+ return property.map((propertyEntry) => getEndpointProperty(propertyEntry, options));
7
7
  }
8
8
  switch (typeof property) {
9
9
  case "string":
10
10
  return evaluateTemplate(property, options);
11
11
  case "object":
12
12
  if (property === null) {
13
- throw new EndpointError("Unexpected endpoint property: ".concat(property));
13
+ throw new EndpointError(`Unexpected endpoint property: ${property}`);
14
14
  }
15
15
  return getEndpointProperties(property, options);
16
16
  case "boolean":
17
17
  return property;
18
18
  default:
19
- throw new EndpointError("Unexpected endpoint property type: ".concat(typeof property));
19
+ throw new EndpointError(`Unexpected endpoint property type: ${typeof property}`);
20
20
  }
21
21
  };
@@ -1,15 +1,15 @@
1
1
  import { EndpointError } from "../types";
2
2
  import { evaluateExpression } from "./evaluateExpression";
3
- export var getEndpointUrl = function (endpointUrl, options) {
4
- var expression = evaluateExpression(endpointUrl, "Endpoint URL", options);
3
+ export const getEndpointUrl = (endpointUrl, options) => {
4
+ const expression = evaluateExpression(endpointUrl, "Endpoint URL", options);
5
5
  if (typeof expression === "string") {
6
6
  try {
7
7
  return new URL(expression);
8
8
  }
9
9
  catch (error) {
10
- console.error("Failed to construct URL with ".concat(expression), error);
10
+ console.error(`Failed to construct URL with ${expression}`, error);
11
11
  throw error;
12
12
  }
13
13
  }
14
- throw new EndpointError("Endpoint URL must be a string, got ".concat(typeof expression));
14
+ throw new EndpointError(`Endpoint URL must be a string, got ${typeof expression}`);
15
15
  };
@@ -1,6 +1,7 @@
1
- import { __assign } from "tslib";
2
- export var getReferenceValue = function (_a, options) {
3
- var ref = _a.ref;
4
- var referenceRecord = __assign(__assign({}, options.endpointParams), options.referenceRecord);
1
+ export const getReferenceValue = ({ ref }, options) => {
2
+ const referenceRecord = {
3
+ ...options.endpointParams,
4
+ ...options.referenceRecord,
5
+ };
5
6
  return referenceRecord[ref];
6
7
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/util-endpoints",
3
- "version": "3.186.0",
3
+ "version": "3.188.0",
4
4
  "description": "Utilities to help with endpoint resolution",
5
5
  "main": "./dist-cjs/index.js",
6
6
  "module": "./dist-es/index.js",
@@ -21,7 +21,7 @@
21
21
  },
22
22
  "license": "Apache-2.0",
23
23
  "dependencies": {
24
- "@aws-sdk/types": "3.186.0",
24
+ "@aws-sdk/types": "3.188.0",
25
25
  "tslib": "^2.3.1"
26
26
  },
27
27
  "engines": {