@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.
- package/CHANGELOG.md +11 -0
- package/dist-cjs/resolveEndpoint.js +13 -2
- package/dist-es/lib/aws/isVirtualHostableS3Bucket.js +4 -17
- package/dist-es/lib/aws/parseArn.js +7 -8
- package/dist-es/lib/aws/partition.js +22 -44
- package/dist-es/lib/booleanEquals.js +1 -1
- package/dist-es/lib/getAttr.js +9 -11
- package/dist-es/lib/getAttrPathList.js +17 -29
- package/dist-es/lib/isIpAddress.js +2 -4
- package/dist-es/lib/isSet.js +1 -1
- package/dist-es/lib/isValidHostLabel.js +6 -19
- package/dist-es/lib/not.js +1 -1
- package/dist-es/lib/parseURL.js +14 -15
- package/dist-es/lib/stringEquals.js +1 -1
- package/dist-es/lib/substring.js +1 -1
- package/dist-es/lib/uriEncode.js +1 -3
- package/dist-es/resolveEndpoint.js +23 -47
- package/dist-es/types/EndpointError.js +5 -10
- package/dist-es/utils/callFunction.js +3 -7
- package/dist-es/utils/evaluateCondition.js +7 -6
- package/dist-es/utils/evaluateConditions.js +14 -21
- package/dist-es/utils/evaluateEndpointRule.js +17 -11
- package/dist-es/utils/evaluateErrorRule.js +7 -5
- package/dist-es/utils/evaluateExpression.js +2 -2
- package/dist-es/utils/evaluateRules.js +17 -29
- package/dist-es/utils/evaluateTemplate.js +19 -20
- package/dist-es/utils/evaluateTreeRule.js +7 -5
- package/dist-es/utils/getEndpointHeaders.js +10 -14
- package/dist-es/utils/getEndpointProperties.js +4 -8
- package/dist-es/utils/getEndpointProperty.js +4 -4
- package/dist-es/utils/getEndpointUrl.js +4 -4
- package/dist-es/utils/getReferenceValue.js +5 -4
- 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
|
-
|
|
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
|
|
5
|
-
var e_1, _a;
|
|
6
|
-
if (allowSubDomains === void 0) { allowSubDomains = false; }
|
|
3
|
+
export const isVirtualHostableS3Bucket = (value, allowSubDomains = false) => {
|
|
7
4
|
if (allowSubDomains) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
2
|
-
|
|
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
|
-
|
|
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
|
|
11
|
-
service
|
|
12
|
-
region
|
|
13
|
-
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
|
-
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
for (
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
|
29
|
+
return {
|
|
30
|
+
name: DEFAULT_PARTITION.id,
|
|
31
|
+
...DEFAULT_PARTITION.outputs,
|
|
32
|
+
};
|
|
55
33
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export const booleanEquals = (value1, value2) => value1 === value2;
|
package/dist-es/lib/getAttr.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { EndpointError } from "../types";
|
|
2
2
|
import { getAttrPathList } from "./getAttrPathList";
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
25
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2
|
-
export
|
|
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("]"));
|
package/dist-es/lib/isSet.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export const isSet = (value) => value != null;
|
|
@@ -1,26 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
};
|
package/dist-es/lib/not.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export const not = (value) => !value;
|
package/dist-es/lib/parseURL.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
var _a;
|
|
2
1
|
import { EndpointURLScheme } from "@aws-sdk/types";
|
|
3
2
|
import { isIpAddress } from "./isIpAddress";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export
|
|
9
|
-
|
|
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
|
-
|
|
19
|
+
const { host, hostname, pathname, protocol, search } = whatwgURL;
|
|
21
20
|
if (search) {
|
|
22
21
|
return null;
|
|
23
22
|
}
|
|
24
|
-
|
|
23
|
+
const scheme = protocol.slice(0, -1);
|
|
25
24
|
if (!Object.values(EndpointURLScheme).includes(scheme)) {
|
|
26
25
|
return null;
|
|
27
26
|
}
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
const isIp = isIpAddress(hostname);
|
|
28
|
+
const authority = `${host}${value.includes(`${host}:${DEFAULT_PORTS[scheme]}`) ? `:${DEFAULT_PORTS[scheme]}` : ``}`;
|
|
30
29
|
return {
|
|
31
|
-
scheme
|
|
32
|
-
authority
|
|
30
|
+
scheme,
|
|
31
|
+
authority,
|
|
33
32
|
path: pathname,
|
|
34
|
-
normalizedPath: pathname.endsWith("/") ? pathname :
|
|
35
|
-
isIp
|
|
33
|
+
normalizedPath: pathname.endsWith("/") ? pathname : `${pathname}/`,
|
|
34
|
+
isIp,
|
|
36
35
|
};
|
|
37
36
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export const stringEquals = (value1, value2) => value1 === value2;
|
package/dist-es/lib/substring.js
CHANGED
package/dist-es/lib/uriEncode.js
CHANGED
|
@@ -1,3 +1 @@
|
|
|
1
|
-
export
|
|
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
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
20
|
-
|
|
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
|
-
|
|
34
|
-
.filter(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
51
|
-
|
|
22
|
+
const endpoint = evaluateRules(rules, { endpointParams, logger, referenceRecord: {} });
|
|
23
|
+
if (options.endpointParams?.Endpoint) {
|
|
52
24
|
try {
|
|
53
|
-
|
|
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
|
|
33
|
+
return endpoint;
|
|
58
34
|
};
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
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
|
|
5
|
-
|
|
6
|
-
|
|
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
|
|
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(
|
|
5
|
+
throw new EndpointError(`'${assign}' is already defined in Reference Record.`);
|
|
8
6
|
}
|
|
9
|
-
|
|
10
|
-
return
|
|
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
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
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
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
|
6
|
-
|
|
7
|
-
|
|
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",
|
|
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
|
|
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(
|
|
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
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
.replace(new RegExp(
|
|
7
|
-
.replace(new RegExp(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
|
5
|
-
|
|
6
|
-
|
|
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,
|
|
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
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
|
4
|
+
export const getEndpointProperty = (property, options) => {
|
|
5
5
|
if (Array.isArray(property)) {
|
|
6
|
-
return property.map(
|
|
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(
|
|
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(
|
|
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
|
|
4
|
-
|
|
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(
|
|
10
|
+
console.error(`Failed to construct URL with ${expression}`, error);
|
|
11
11
|
throw error;
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
throw new EndpointError(
|
|
14
|
+
throw new EndpointError(`Endpoint URL must be a string, got ${typeof expression}`);
|
|
15
15
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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.
|
|
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.
|
|
24
|
+
"@aws-sdk/types": "3.188.0",
|
|
25
25
|
"tslib": "^2.3.1"
|
|
26
26
|
},
|
|
27
27
|
"engines": {
|