@aws-sdk/util-endpoints 3.183.0 → 3.186.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 +8 -0
- package/dist-es/lib/aws/isVirtualHostableS3Bucket.js +17 -4
- package/dist-es/lib/aws/parseArn.js +8 -7
- package/dist-es/lib/aws/partition.js +44 -22
- package/dist-es/lib/booleanEquals.js +1 -1
- package/dist-es/lib/getAttr.js +11 -9
- package/dist-es/lib/getAttrPathList.js +29 -17
- package/dist-es/lib/isIpAddress.js +4 -2
- package/dist-es/lib/isSet.js +1 -1
- package/dist-es/lib/isValidHostLabel.js +19 -6
- package/dist-es/lib/not.js +1 -1
- package/dist-es/lib/parseURL.js +15 -14
- package/dist-es/lib/stringEquals.js +1 -1
- package/dist-es/lib/substring.js +1 -1
- package/dist-es/lib/uriEncode.js +3 -1
- package/dist-es/resolveEndpoint.js +50 -15
- package/dist-es/types/EndpointError.js +10 -5
- package/dist-es/utils/callFunction.js +7 -3
- package/dist-es/utils/evaluateCondition.js +6 -7
- package/dist-es/utils/evaluateConditions.js +21 -14
- package/dist-es/utils/evaluateEndpointRule.js +11 -17
- package/dist-es/utils/evaluateErrorRule.js +5 -7
- package/dist-es/utils/evaluateExpression.js +2 -2
- package/dist-es/utils/evaluateRules.js +29 -17
- package/dist-es/utils/evaluateTemplate.js +20 -19
- package/dist-es/utils/evaluateTreeRule.js +5 -7
- package/dist-es/utils/getEndpointHeaders.js +14 -10
- package/dist-es/utils/getEndpointProperties.js +8 -4
- package/dist-es/utils/getEndpointProperty.js +4 -4
- package/dist-es/utils/getEndpointUrl.js +4 -4
- package/dist-es/utils/getReferenceValue.js +4 -5
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
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.186.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.185.0...v3.186.0) (2022-10-06)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @aws-sdk/util-endpoints
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
# [3.183.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.182.0...v3.183.0) (2022-10-03)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @aws-sdk/util-endpoints
|
|
@@ -1,12 +1,25 @@
|
|
|
1
|
+
import { __values } from "tslib";
|
|
1
2
|
import { isIpAddress } from "../isIpAddress";
|
|
2
3
|
import { isValidHostLabel } from "../isValidHostLabel";
|
|
3
|
-
export
|
|
4
|
+
export var isVirtualHostableS3Bucket = function (value, allowSubDomains) {
|
|
5
|
+
var e_1, _a;
|
|
6
|
+
if (allowSubDomains === void 0) { allowSubDomains = false; }
|
|
4
7
|
if (allowSubDomains) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
+
}
|
|
8
14
|
}
|
|
9
15
|
}
|
|
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
|
+
}
|
|
10
23
|
return true;
|
|
11
24
|
}
|
|
12
25
|
if (!isValidHostLabel(value)) {
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { __read } from "tslib";
|
|
2
|
+
export var parseArn = function (value) {
|
|
3
|
+
var segments = value.split(":");
|
|
3
4
|
if (segments.length < 6)
|
|
4
5
|
return null;
|
|
5
|
-
|
|
6
|
+
var _a = __read(segments), arn = _a[0], partition = _a[1], service = _a[2], region = _a[3], accountId = _a[4], resourceId = _a.slice(5);
|
|
6
7
|
if (arn !== "arn" || partition === "" || service === "" || resourceId[0] === "")
|
|
7
8
|
return null;
|
|
8
9
|
return {
|
|
9
|
-
partition,
|
|
10
|
-
service,
|
|
11
|
-
region,
|
|
12
|
-
accountId,
|
|
10
|
+
partition: partition,
|
|
11
|
+
service: service,
|
|
12
|
+
region: region,
|
|
13
|
+
accountId: accountId,
|
|
13
14
|
resourceId: resourceId[0].includes("/") ? resourceId[0].split("/") : resourceId,
|
|
14
15
|
};
|
|
15
16
|
};
|
|
@@ -1,33 +1,55 @@
|
|
|
1
|
+
import { __assign, __read, __values } from "tslib";
|
|
1
2
|
import { partitions } from "./partitions.json";
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
for (
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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);
|
|
13
40
|
}
|
|
14
41
|
}
|
|
15
42
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return
|
|
20
|
-
name: id,
|
|
21
|
-
...outputs,
|
|
22
|
-
};
|
|
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);
|
|
23
47
|
}
|
|
48
|
+
finally { if (e_3) throw e_3.error; }
|
|
24
49
|
}
|
|
25
50
|
if (!DEFAULT_PARTITION) {
|
|
26
51
|
throw new Error("Provided region was not found in the partition array or regex," +
|
|
27
52
|
" and default partition with id 'aws' doesn't exist.");
|
|
28
53
|
}
|
|
29
|
-
return {
|
|
30
|
-
name: DEFAULT_PARTITION.id,
|
|
31
|
-
...DEFAULT_PARTITION.outputs,
|
|
32
|
-
};
|
|
54
|
+
return __assign({ name: DEFAULT_PARTITION.id }, DEFAULT_PARTITION.outputs);
|
|
33
55
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export var booleanEquals = function (value1, value2) { return value1 === value2; };
|
package/dist-es/lib/getAttr.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { EndpointError } from "../types";
|
|
2
2
|
import { getAttrPathList } from "./getAttrPathList";
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
+
};
|
|
@@ -1,25 +1,37 @@
|
|
|
1
|
+
import { __values } from "tslib";
|
|
1
2
|
import { EndpointError } from "../types";
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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);
|
|
10
23
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
throw new EndpointError(`Invalid array index: '${arrayIndex}' in path: '${path}'`);
|
|
24
|
+
else {
|
|
25
|
+
pathList.push(part);
|
|
14
26
|
}
|
|
15
|
-
if (squareBracketIndex !== 0) {
|
|
16
|
-
pathList.push(part.slice(0, squareBracketIndex));
|
|
17
|
-
}
|
|
18
|
-
pathList.push(arrayIndex);
|
|
19
27
|
}
|
|
20
|
-
|
|
21
|
-
|
|
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);
|
|
22
33
|
}
|
|
34
|
+
finally { if (e_1) throw e_1.error; }
|
|
23
35
|
}
|
|
24
36
|
return pathList;
|
|
25
37
|
};
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
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
|
+
};
|
package/dist-es/lib/isSet.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export var isSet = function (value) { return value != null; };
|
|
@@ -1,13 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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; }
|
|
3
6
|
if (!allowSubDomains) {
|
|
4
7
|
return VALID_HOST_LABEL_REGEX.test(value);
|
|
5
8
|
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
+
}
|
|
10
16
|
}
|
|
11
17
|
}
|
|
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
|
+
}
|
|
12
25
|
return true;
|
|
13
26
|
};
|
package/dist-es/lib/not.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export var not = function (value) { return !value; };
|
package/dist-es/lib/parseURL.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
var _a;
|
|
1
2
|
import { EndpointURLScheme } from "@aws-sdk/types";
|
|
2
3
|
import { isIpAddress } from "./isIpAddress";
|
|
3
|
-
|
|
4
|
-
[EndpointURLScheme.HTTP]
|
|
5
|
-
[EndpointURLScheme.HTTPS]
|
|
6
|
-
|
|
7
|
-
export
|
|
8
|
-
|
|
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 () {
|
|
9
10
|
try {
|
|
10
11
|
return new URL(value);
|
|
11
12
|
}
|
|
@@ -16,21 +17,21 @@ export const parseURL = (value) => {
|
|
|
16
17
|
if (!whatwgURL) {
|
|
17
18
|
return null;
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
+
var host = whatwgURL.host, hostname = whatwgURL.hostname, pathname = whatwgURL.pathname, protocol = whatwgURL.protocol, search = whatwgURL.search;
|
|
20
21
|
if (search) {
|
|
21
22
|
return null;
|
|
22
23
|
}
|
|
23
|
-
|
|
24
|
+
var scheme = protocol.slice(0, -1);
|
|
24
25
|
if (!Object.values(EndpointURLScheme).includes(scheme)) {
|
|
25
26
|
return null;
|
|
26
27
|
}
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
var isIp = isIpAddress(hostname);
|
|
29
|
+
var authority = "".concat(host).concat(value.includes("".concat(host, ":").concat(DEFAULT_PORTS[scheme])) ? ":".concat(DEFAULT_PORTS[scheme]) : "");
|
|
29
30
|
return {
|
|
30
|
-
scheme,
|
|
31
|
-
authority,
|
|
31
|
+
scheme: scheme,
|
|
32
|
+
authority: authority,
|
|
32
33
|
path: pathname,
|
|
33
|
-
normalizedPath: pathname.endsWith("/") ? pathname :
|
|
34
|
-
isIp,
|
|
34
|
+
normalizedPath: pathname.endsWith("/") ? pathname : "".concat(pathname, "/"),
|
|
35
|
+
isIp: isIp,
|
|
35
36
|
};
|
|
36
37
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export var stringEquals = function (value1, value2) { return value1 === value2; };
|
package/dist-es/lib/substring.js
CHANGED
package/dist-es/lib/uriEncode.js
CHANGED
|
@@ -1 +1,3 @@
|
|
|
1
|
-
export
|
|
1
|
+
export var uriEncode = function (value) {
|
|
2
|
+
return encodeURIComponent(value).replace(/[!*'()]/g, function (c) { return "%".concat(c.charCodeAt(0).toString(16).toUpperCase()); });
|
|
3
|
+
};
|
|
@@ -1,23 +1,58 @@
|
|
|
1
|
+
import { __read, __values } from "tslib";
|
|
1
2
|
import { EndpointError } from "./types";
|
|
2
3
|
import { evaluateRules } from "./utils";
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
+
});
|
|
9
18
|
if (paramsWithDefault.length > 0) {
|
|
10
|
-
|
|
11
|
-
|
|
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; }
|
|
31
|
+
}
|
|
32
|
+
}
|
|
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
|
+
}
|
|
12
48
|
}
|
|
13
49
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (endpointParams[requiredParam] == null) {
|
|
19
|
-
throw new EndpointError(`Missing required parameter: '${requiredParam}'`);
|
|
50
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
51
|
+
finally {
|
|
52
|
+
try {
|
|
53
|
+
if (requiredParams_1_1 && !requiredParams_1_1.done && (_b = requiredParams_1.return)) _b.call(requiredParams_1);
|
|
20
54
|
}
|
|
55
|
+
finally { if (e_2) throw e_2.error; }
|
|
21
56
|
}
|
|
22
|
-
return evaluateRules(rules, { endpointParams, logger, referenceRecord: {} });
|
|
57
|
+
return evaluateRules(rules, { endpointParams: endpointParams, logger: logger, referenceRecord: {} });
|
|
23
58
|
};
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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;
|
|
5
8
|
}
|
|
6
|
-
|
|
9
|
+
return EndpointError;
|
|
10
|
+
}(Error));
|
|
11
|
+
export { EndpointError };
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { __read, __spreadArray } from "tslib";
|
|
1
2
|
import * as lib from "../lib";
|
|
2
3
|
import { evaluateExpression } from "./evaluateExpression";
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
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));
|
|
6
10
|
};
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
+
import { __assign, __rest } from "tslib";
|
|
1
2
|
import { EndpointError } from "../types";
|
|
2
3
|
import { callFunction } from "./callFunction";
|
|
3
|
-
export
|
|
4
|
+
export var evaluateCondition = function (_a, options) {
|
|
5
|
+
var assign = _a.assign, fnArgs = __rest(_a, ["assign"]);
|
|
4
6
|
if (assign && assign in options.referenceRecord) {
|
|
5
|
-
throw new EndpointError(
|
|
7
|
+
throw new EndpointError("'".concat(assign, "' is already defined in Reference Record."));
|
|
6
8
|
}
|
|
7
|
-
|
|
8
|
-
return {
|
|
9
|
-
result: value === "" ? true : !!value,
|
|
10
|
-
...(assign != null && { toAssign: { name: assign, value } }),
|
|
11
|
-
};
|
|
9
|
+
var value = callFunction(fnArgs, options);
|
|
10
|
+
return __assign({ result: value === "" ? true : !!value }, (assign != null && { toAssign: { name: assign, value: value } }));
|
|
12
11
|
};
|
|
@@ -1,20 +1,27 @@
|
|
|
1
|
+
import { __assign, __values } from "tslib";
|
|
1
2
|
import { evaluateCondition } from "./evaluateCondition";
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
+
}
|
|
14
17
|
}
|
|
15
|
-
|
|
16
|
-
|
|
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);
|
|
17
23
|
}
|
|
24
|
+
finally { if (e_1) throw e_1.error; }
|
|
18
25
|
}
|
|
19
26
|
return { result: true, referenceRecord: conditionsReferenceRecord };
|
|
20
27
|
};
|
|
@@ -1,25 +1,19 @@
|
|
|
1
|
+
import { __assign } from "tslib";
|
|
1
2
|
import { evaluateConditions } from "./evaluateConditions";
|
|
2
3
|
import { getEndpointHeaders } from "./getEndpointHeaders";
|
|
3
4
|
import { getEndpointProperties } from "./getEndpointProperties";
|
|
4
5
|
import { getEndpointUrl } from "./getEndpointUrl";
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
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;
|
|
8
9
|
if (!result) {
|
|
9
10
|
return;
|
|
10
11
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
headers: getEndpointHeaders(headers, endpointRuleOptions),
|
|
19
|
-
}),
|
|
20
|
-
...(properties != undefined && {
|
|
21
|
-
properties: getEndpointProperties(properties, endpointRuleOptions),
|
|
22
|
-
}),
|
|
23
|
-
url: getEndpointUrl(url, endpointRuleOptions),
|
|
24
|
-
};
|
|
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) });
|
|
25
19
|
};
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
+
import { __assign } from "tslib";
|
|
1
2
|
import { EndpointError } from "../types";
|
|
2
3
|
import { evaluateConditions } from "./evaluateConditions";
|
|
3
4
|
import { evaluateExpression } from "./evaluateExpression";
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
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;
|
|
7
8
|
if (!result) {
|
|
8
9
|
return;
|
|
9
10
|
}
|
|
10
|
-
throw new EndpointError(evaluateExpression(error, "Error", {
|
|
11
|
-
...options,
|
|
12
|
-
referenceRecord: { ...options.referenceRecord, ...referenceRecord },
|
|
13
|
-
}));
|
|
11
|
+
throw new EndpointError(evaluateExpression(error, "Error", __assign(__assign({}, options), { referenceRecord: __assign(__assign({}, options.referenceRecord), referenceRecord) })));
|
|
14
12
|
};
|
|
@@ -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 var evaluateExpression = function (obj, keyName, options) {
|
|
6
6
|
if (typeof obj === "string") {
|
|
7
7
|
return evaluateTemplate(obj, options);
|
|
8
8
|
}
|
|
@@ -12,5 +12,5 @@ export const evaluateExpression = (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("'".concat(keyName, "': ").concat(String(obj), " is not a string, function or reference."));
|
|
16
16
|
};
|
|
@@ -1,27 +1,39 @@
|
|
|
1
|
+
import { __values } from "tslib";
|
|
1
2
|
import { EndpointError } from "../types";
|
|
2
3
|
import { evaluateEndpointRule } from "./evaluateEndpointRule";
|
|
3
4
|
import { evaluateErrorRule } from "./evaluateErrorRule";
|
|
4
5
|
import { evaluateTreeRule } from "./evaluateTreeRule";
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
+
}
|
|
11
16
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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));
|
|
20
28
|
}
|
|
21
29
|
}
|
|
22
|
-
|
|
23
|
-
|
|
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);
|
|
24
35
|
}
|
|
36
|
+
finally { if (e_1) throw e_1.error; }
|
|
25
37
|
}
|
|
26
|
-
throw new EndpointError(
|
|
38
|
+
throw new EndpointError("Rules evaluation failed");
|
|
27
39
|
};
|
|
@@ -1,24 +1,25 @@
|
|
|
1
|
+
import { __assign, __read, __spreadArray } from "tslib";
|
|
1
2
|
import { getAttr } from "../lib";
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
.replace(new RegExp(
|
|
6
|
-
.replace(new RegExp(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const indexOfHash = attrShortHand.indexOf("#");
|
|
14
|
-
const refName = attrShortHand.substring(2, indexOfHash);
|
|
15
|
-
const attrName = attrShortHand.substring(indexOfHash + 1, attrShortHand.length - 1);
|
|
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);
|
|
16
14
|
acc[attrShortHand] = getAttr(templateContext[refName], attrName);
|
|
17
15
|
return acc;
|
|
18
16
|
}, {});
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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));
|
|
24
25
|
};
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
+
import { __assign } from "tslib";
|
|
1
2
|
import { evaluateConditions } from "./evaluateConditions";
|
|
2
3
|
import { evaluateRules } from "./evaluateRules";
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
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;
|
|
6
7
|
if (!result) {
|
|
7
8
|
return;
|
|
8
9
|
}
|
|
9
|
-
return evaluateRules(rules, {
|
|
10
|
-
...options,
|
|
11
|
-
referenceRecord: { ...options.referenceRecord, ...referenceRecord },
|
|
12
|
-
});
|
|
10
|
+
return evaluateRules(rules, __assign(__assign({}, options), { referenceRecord: __assign(__assign({}, options.referenceRecord), referenceRecord) }));
|
|
13
11
|
};
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
+
import { __assign, __read } from "tslib";
|
|
1
2
|
import { EndpointError } from "../types";
|
|
2
3
|
import { evaluateExpression } from "./evaluateExpression";
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
+
};
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import { __assign, __read } from "tslib";
|
|
1
2
|
import { getEndpointProperty } from "./getEndpointProperty";
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
+
};
|
|
@@ -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 var getEndpointProperty = function (property, options) {
|
|
5
5
|
if (Array.isArray(property)) {
|
|
6
|
-
return property.map((propertyEntry)
|
|
6
|
+
return property.map(function (propertyEntry) { return 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: ".concat(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: ".concat(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 var getEndpointUrl = function (endpointUrl, options) {
|
|
4
|
+
var 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 ".concat(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 ".concat(typeof expression));
|
|
15
15
|
};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
};
|
|
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);
|
|
6
5
|
return referenceRecord[ref];
|
|
7
6
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-sdk/util-endpoints",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.186.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.186.0",
|
|
25
25
|
"tslib": "^2.3.1"
|
|
26
26
|
},
|
|
27
27
|
"engines": {
|