@aws-sdk/util-endpoints 3.433.0 → 3.438.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/dist-cjs/aws.js +12 -0
- package/dist-cjs/index.js +1 -0
- package/dist-cjs/lib/aws/isVirtualHostableS3Bucket.js +2 -2
- package/dist-cjs/lib/isIpAddress.js +2 -3
- package/dist-cjs/resolveEndpoint.js +2 -39
- package/dist-cjs/types/EndpointError.js +2 -7
- package/dist-es/aws.js +10 -0
- package/dist-es/index.js +1 -0
- package/dist-es/lib/aws/isVirtualHostableS3Bucket.js +1 -1
- package/dist-es/lib/isIpAddress.js +1 -2
- package/dist-es/resolveEndpoint.js +1 -37
- package/dist-es/types/EndpointError.js +1 -6
- package/dist-types/aws.d.ts +1 -0
- package/dist-types/index.d.ts +1 -0
- package/dist-types/lib/aws/parseArn.d.ts +1 -1
- package/dist-types/lib/aws/partition.d.ts +1 -1
- package/dist-types/lib/isIpAddress.d.ts +1 -4
- package/dist-types/resolveEndpoint.d.ts +1 -6
- package/dist-types/ts3.4/aws.d.ts +1 -0
- package/dist-types/ts3.4/index.d.ts +1 -0
- package/dist-types/ts3.4/lib/aws/parseArn.d.ts +1 -1
- package/dist-types/ts3.4/lib/aws/partition.d.ts +1 -1
- package/dist-types/ts3.4/lib/isIpAddress.d.ts +1 -1
- package/dist-types/ts3.4/resolveEndpoint.d.ts +1 -6
- package/dist-types/ts3.4/types/EndpointError.d.ts +1 -3
- package/dist-types/ts3.4/types/EndpointRuleObject.d.ts +6 -15
- package/dist-types/ts3.4/types/ErrorRuleObject.d.ts +1 -7
- package/dist-types/ts3.4/types/RuleSetObject.d.ts +5 -19
- package/dist-types/ts3.4/types/TreeRuleObject.d.ts +1 -12
- package/dist-types/ts3.4/types/shared.d.ts +12 -29
- package/dist-types/types/EndpointError.d.ts +1 -3
- package/dist-types/types/EndpointRuleObject.d.ts +1 -15
- package/dist-types/types/ErrorRuleObject.d.ts +1 -7
- package/dist-types/types/RuleSetObject.d.ts +1 -19
- package/dist-types/types/TreeRuleObject.d.ts +1 -10
- package/dist-types/types/shared.d.ts +1 -25
- package/package.json +2 -1
- package/dist-cjs/debug/debugId.js +0 -4
- package/dist-cjs/debug/index.js +0 -5
- package/dist-cjs/debug/toDebugString.js +0 -16
- package/dist-cjs/lib/booleanEquals.js +0 -5
- package/dist-cjs/lib/getAttr.js +0 -15
- package/dist-cjs/lib/getAttrPathList.js +0 -29
- package/dist-cjs/lib/index.js +0 -14
- package/dist-cjs/lib/isSet.js +0 -5
- package/dist-cjs/lib/isValidHostLabel.js +0 -17
- package/dist-cjs/lib/not.js +0 -5
- package/dist-cjs/lib/parseURL.js +0 -55
- package/dist-cjs/lib/stringEquals.js +0 -5
- package/dist-cjs/lib/substring.js +0 -13
- package/dist-cjs/lib/uriEncode.js +0 -5
- package/dist-cjs/utils/callFunction.js +0 -11
- package/dist-cjs/utils/evaluateCondition.js +0 -19
- package/dist-cjs/utils/evaluateConditions.js +0 -27
- package/dist-cjs/utils/evaluateEndpointRule.js +0 -32
- package/dist-cjs/utils/evaluateErrorRule.js +0 -18
- package/dist-cjs/utils/evaluateExpression.js +0 -20
- package/dist-cjs/utils/evaluateRules.js +0 -31
- package/dist-cjs/utils/evaluateTemplate.js +0 -40
- package/dist-cjs/utils/evaluateTreeRule.js +0 -17
- package/dist-cjs/utils/getEndpointHeaders.js +0 -16
- package/dist-cjs/utils/getEndpointProperties.js +0 -9
- package/dist-cjs/utils/getEndpointProperty.js +0 -25
- package/dist-cjs/utils/getEndpointUrl.js +0 -19
- package/dist-cjs/utils/getReferenceValue.js +0 -11
- package/dist-cjs/utils/index.js +0 -4
- package/dist-es/debug/debugId.js +0 -1
- package/dist-es/debug/index.js +0 -2
- package/dist-es/debug/toDebugString.js +0 -12
- package/dist-es/lib/booleanEquals.js +0 -1
- package/dist-es/lib/getAttr.js +0 -11
- package/dist-es/lib/getAttrPathList.js +0 -25
- package/dist-es/lib/index.js +0 -10
- package/dist-es/lib/isSet.js +0 -1
- package/dist-es/lib/isValidHostLabel.js +0 -13
- package/dist-es/lib/not.js +0 -1
- package/dist-es/lib/parseURL.js +0 -51
- package/dist-es/lib/stringEquals.js +0 -1
- package/dist-es/lib/substring.js +0 -9
- package/dist-es/lib/uriEncode.js +0 -1
- package/dist-es/utils/callFunction.js +0 -6
- package/dist-es/utils/evaluateCondition.js +0 -14
- package/dist-es/utils/evaluateConditions.js +0 -22
- package/dist-es/utils/evaluateEndpointRule.js +0 -27
- package/dist-es/utils/evaluateErrorRule.js +0 -14
- package/dist-es/utils/evaluateExpression.js +0 -16
- package/dist-es/utils/evaluateRules.js +0 -27
- package/dist-es/utils/evaluateTemplate.js +0 -36
- package/dist-es/utils/evaluateTreeRule.js +0 -13
- package/dist-es/utils/getEndpointHeaders.js +0 -12
- package/dist-es/utils/getEndpointProperties.js +0 -5
- package/dist-es/utils/getEndpointProperty.js +0 -21
- package/dist-es/utils/getEndpointUrl.js +0 -15
- package/dist-es/utils/getReferenceValue.js +0 -7
- package/dist-es/utils/index.js +0 -1
- package/dist-types/debug/debugId.d.ts +0 -1
- package/dist-types/debug/index.d.ts +0 -2
- package/dist-types/debug/toDebugString.d.ts +0 -9
- package/dist-types/lib/booleanEquals.d.ts +0 -5
- package/dist-types/lib/getAttr.d.ts +0 -7
- package/dist-types/lib/getAttrPathList.d.ts +0 -4
- package/dist-types/lib/index.d.ts +0 -10
- package/dist-types/lib/isSet.d.ts +0 -5
- package/dist-types/lib/isValidHostLabel.d.ts +0 -7
- package/dist-types/lib/not.d.ts +0 -5
- package/dist-types/lib/parseURL.d.ts +0 -5
- package/dist-types/lib/stringEquals.d.ts +0 -5
- package/dist-types/lib/substring.d.ts +0 -7
- package/dist-types/lib/uriEncode.d.ts +0 -4
- package/dist-types/ts3.4/debug/debugId.d.ts +0 -1
- package/dist-types/ts3.4/debug/index.d.ts +0 -2
- package/dist-types/ts3.4/debug/toDebugString.d.ts +0 -9
- package/dist-types/ts3.4/lib/booleanEquals.d.ts +0 -4
- package/dist-types/ts3.4/lib/getAttr.d.ts +0 -11
- package/dist-types/ts3.4/lib/getAttrPathList.d.ts +0 -1
- package/dist-types/ts3.4/lib/index.d.ts +0 -11
- package/dist-types/ts3.4/lib/isSet.d.ts +0 -1
- package/dist-types/ts3.4/lib/isValidHostLabel.d.ts +0 -4
- package/dist-types/ts3.4/lib/not.d.ts +0 -1
- package/dist-types/ts3.4/lib/parseURL.d.ts +0 -4
- package/dist-types/ts3.4/lib/stringEquals.d.ts +0 -1
- package/dist-types/ts3.4/lib/substring.d.ts +0 -6
- package/dist-types/ts3.4/lib/uriEncode.d.ts +0 -1
- package/dist-types/ts3.4/utils/callFunction.d.ts +0 -5
- package/dist-types/ts3.4/utils/evaluateCondition.d.ts +0 -13
- package/dist-types/ts3.4/utils/evaluateConditions.d.ts +0 -13
- package/dist-types/ts3.4/utils/evaluateEndpointRule.d.ts +0 -6
- package/dist-types/ts3.4/utils/evaluateErrorRule.d.ts +0 -5
- package/dist-types/ts3.4/utils/evaluateExpression.d.ts +0 -6
- package/dist-types/ts3.4/utils/evaluateRules.d.ts +0 -6
- package/dist-types/ts3.4/utils/evaluateTemplate.d.ts +0 -5
- package/dist-types/ts3.4/utils/evaluateTreeRule.d.ts +0 -6
- package/dist-types/ts3.4/utils/getEndpointHeaders.d.ts +0 -5
- package/dist-types/ts3.4/utils/getEndpointProperties.d.ts +0 -5
- package/dist-types/ts3.4/utils/getEndpointProperty.d.ts +0 -6
- package/dist-types/ts3.4/utils/getEndpointUrl.d.ts +0 -5
- package/dist-types/ts3.4/utils/getReferenceValue.d.ts +0 -5
- package/dist-types/ts3.4/utils/index.d.ts +0 -1
- package/dist-types/utils/callFunction.d.ts +0 -2
- package/dist-types/utils/evaluateCondition.d.ts +0 -8
- package/dist-types/utils/evaluateConditions.d.ts +0 -8
- package/dist-types/utils/evaluateEndpointRule.d.ts +0 -3
- package/dist-types/utils/evaluateErrorRule.d.ts +0 -2
- package/dist-types/utils/evaluateExpression.d.ts +0 -2
- package/dist-types/utils/evaluateRules.d.ts +0 -3
- package/dist-types/utils/evaluateTemplate.d.ts +0 -2
- package/dist-types/utils/evaluateTreeRule.d.ts +0 -3
- package/dist-types/utils/getEndpointHeaders.d.ts +0 -2
- package/dist-types/utils/getEndpointProperties.d.ts +0 -2
- package/dist-types/utils/getEndpointProperty.d.ts +0 -3
- package/dist-types/utils/getEndpointUrl.d.ts +0 -2
- package/dist-types/utils/getReferenceValue.d.ts +0 -2
- package/dist-types/utils/index.d.ts +0 -1
package/dist-cjs/lib/parseURL.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseURL = void 0;
|
|
4
|
-
const types_1 = require("@aws-sdk/types");
|
|
5
|
-
const isIpAddress_1 = require("./isIpAddress");
|
|
6
|
-
const DEFAULT_PORTS = {
|
|
7
|
-
[types_1.EndpointURLScheme.HTTP]: 80,
|
|
8
|
-
[types_1.EndpointURLScheme.HTTPS]: 443,
|
|
9
|
-
};
|
|
10
|
-
const parseURL = (value) => {
|
|
11
|
-
const whatwgURL = (() => {
|
|
12
|
-
try {
|
|
13
|
-
if (value instanceof URL) {
|
|
14
|
-
return value;
|
|
15
|
-
}
|
|
16
|
-
if (typeof value === "object" && "hostname" in value) {
|
|
17
|
-
const { hostname, port, protocol = "", path = "", query = {} } = value;
|
|
18
|
-
const url = new URL(`${protocol}//${hostname}${port ? `:${port}` : ""}${path}`);
|
|
19
|
-
url.search = Object.entries(query)
|
|
20
|
-
.map(([k, v]) => `${k}=${v}`)
|
|
21
|
-
.join("&");
|
|
22
|
-
return url;
|
|
23
|
-
}
|
|
24
|
-
return new URL(value);
|
|
25
|
-
}
|
|
26
|
-
catch (error) {
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
})();
|
|
30
|
-
if (!whatwgURL) {
|
|
31
|
-
console.error(`Unable to parse ${JSON.stringify(value)} as a whatwg URL.`);
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
|
-
const urlString = whatwgURL.href;
|
|
35
|
-
const { host, hostname, pathname, protocol, search } = whatwgURL;
|
|
36
|
-
if (search) {
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
const scheme = protocol.slice(0, -1);
|
|
40
|
-
if (!Object.values(types_1.EndpointURLScheme).includes(scheme)) {
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
const isIp = (0, isIpAddress_1.isIpAddress)(hostname);
|
|
44
|
-
const inputContainsDefaultPort = urlString.includes(`${host}:${DEFAULT_PORTS[scheme]}`) ||
|
|
45
|
-
(typeof value === "string" && value.includes(`${host}:${DEFAULT_PORTS[scheme]}`));
|
|
46
|
-
const authority = `${host}${inputContainsDefaultPort ? `:${DEFAULT_PORTS[scheme]}` : ``}`;
|
|
47
|
-
return {
|
|
48
|
-
scheme,
|
|
49
|
-
authority,
|
|
50
|
-
path: pathname,
|
|
51
|
-
normalizedPath: pathname.endsWith("/") ? pathname : `${pathname}/`,
|
|
52
|
-
isIp,
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
exports.parseURL = parseURL;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.substring = void 0;
|
|
4
|
-
const substring = (input, start, stop, reverse) => {
|
|
5
|
-
if (start >= stop || input.length < stop) {
|
|
6
|
-
return null;
|
|
7
|
-
}
|
|
8
|
-
if (!reverse) {
|
|
9
|
-
return input.substring(start, stop);
|
|
10
|
-
}
|
|
11
|
-
return input.substring(input.length - stop, input.length - start);
|
|
12
|
-
};
|
|
13
|
-
exports.substring = substring;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.uriEncode = void 0;
|
|
4
|
-
const uriEncode = (value) => encodeURIComponent(value).replace(/[!*'()]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
5
|
-
exports.uriEncode = uriEncode;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.callFunction = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const lib = tslib_1.__importStar(require("../lib"));
|
|
6
|
-
const evaluateExpression_1 = require("./evaluateExpression");
|
|
7
|
-
const callFunction = ({ fn, argv }, options) => {
|
|
8
|
-
const evaluatedArgs = argv.map((arg) => ["boolean", "number"].includes(typeof arg) ? arg : (0, evaluateExpression_1.evaluateExpression)(arg, "arg", options));
|
|
9
|
-
return fn.split(".").reduce((acc, key) => acc[key], lib)(...evaluatedArgs);
|
|
10
|
-
};
|
|
11
|
-
exports.callFunction = callFunction;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.evaluateCondition = void 0;
|
|
4
|
-
const debug_1 = require("../debug");
|
|
5
|
-
const types_1 = require("../types");
|
|
6
|
-
const callFunction_1 = require("./callFunction");
|
|
7
|
-
const evaluateCondition = ({ assign, ...fnArgs }, options) => {
|
|
8
|
-
var _a, _b;
|
|
9
|
-
if (assign && assign in options.referenceRecord) {
|
|
10
|
-
throw new types_1.EndpointError(`'${assign}' is already defined in Reference Record.`);
|
|
11
|
-
}
|
|
12
|
-
const value = (0, callFunction_1.callFunction)(fnArgs, options);
|
|
13
|
-
(_b = (_a = options.logger) === null || _a === void 0 ? void 0 : _a.debug) === null || _b === void 0 ? void 0 : _b.call(_a, debug_1.debugId, `evaluateCondition: ${(0, debug_1.toDebugString)(fnArgs)} = ${(0, debug_1.toDebugString)(value)}`);
|
|
14
|
-
return {
|
|
15
|
-
result: value === "" ? true : !!value,
|
|
16
|
-
...(assign != null && { toAssign: { name: assign, value } }),
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
exports.evaluateCondition = evaluateCondition;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.evaluateConditions = void 0;
|
|
4
|
-
const debug_1 = require("../debug");
|
|
5
|
-
const evaluateCondition_1 = require("./evaluateCondition");
|
|
6
|
-
const evaluateConditions = (conditions = [], options) => {
|
|
7
|
-
var _a, _b;
|
|
8
|
-
const conditionsReferenceRecord = {};
|
|
9
|
-
for (const condition of conditions) {
|
|
10
|
-
const { result, toAssign } = (0, evaluateCondition_1.evaluateCondition)(condition, {
|
|
11
|
-
...options,
|
|
12
|
-
referenceRecord: {
|
|
13
|
-
...options.referenceRecord,
|
|
14
|
-
...conditionsReferenceRecord,
|
|
15
|
-
},
|
|
16
|
-
});
|
|
17
|
-
if (!result) {
|
|
18
|
-
return { result };
|
|
19
|
-
}
|
|
20
|
-
if (toAssign) {
|
|
21
|
-
conditionsReferenceRecord[toAssign.name] = toAssign.value;
|
|
22
|
-
(_b = (_a = options.logger) === null || _a === void 0 ? void 0 : _a.debug) === null || _b === void 0 ? void 0 : _b.call(_a, debug_1.debugId, `assign: ${toAssign.name} := ${(0, debug_1.toDebugString)(toAssign.value)}`);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return { result: true, referenceRecord: conditionsReferenceRecord };
|
|
26
|
-
};
|
|
27
|
-
exports.evaluateConditions = evaluateConditions;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.evaluateEndpointRule = void 0;
|
|
4
|
-
const debug_1 = require("../debug");
|
|
5
|
-
const evaluateConditions_1 = require("./evaluateConditions");
|
|
6
|
-
const getEndpointHeaders_1 = require("./getEndpointHeaders");
|
|
7
|
-
const getEndpointProperties_1 = require("./getEndpointProperties");
|
|
8
|
-
const getEndpointUrl_1 = require("./getEndpointUrl");
|
|
9
|
-
const evaluateEndpointRule = (endpointRule, options) => {
|
|
10
|
-
var _a, _b;
|
|
11
|
-
const { conditions, endpoint } = endpointRule;
|
|
12
|
-
const { result, referenceRecord } = (0, evaluateConditions_1.evaluateConditions)(conditions, options);
|
|
13
|
-
if (!result) {
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
const endpointRuleOptions = {
|
|
17
|
-
...options,
|
|
18
|
-
referenceRecord: { ...options.referenceRecord, ...referenceRecord },
|
|
19
|
-
};
|
|
20
|
-
const { url, properties, headers } = endpoint;
|
|
21
|
-
(_b = (_a = options.logger) === null || _a === void 0 ? void 0 : _a.debug) === null || _b === void 0 ? void 0 : _b.call(_a, debug_1.debugId, `Resolving endpoint from template: ${(0, debug_1.toDebugString)(endpoint)}`);
|
|
22
|
-
return {
|
|
23
|
-
...(headers != undefined && {
|
|
24
|
-
headers: (0, getEndpointHeaders_1.getEndpointHeaders)(headers, endpointRuleOptions),
|
|
25
|
-
}),
|
|
26
|
-
...(properties != undefined && {
|
|
27
|
-
properties: (0, getEndpointProperties_1.getEndpointProperties)(properties, endpointRuleOptions),
|
|
28
|
-
}),
|
|
29
|
-
url: (0, getEndpointUrl_1.getEndpointUrl)(url, endpointRuleOptions),
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
exports.evaluateEndpointRule = evaluateEndpointRule;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.evaluateErrorRule = void 0;
|
|
4
|
-
const types_1 = require("../types");
|
|
5
|
-
const evaluateConditions_1 = require("./evaluateConditions");
|
|
6
|
-
const evaluateExpression_1 = require("./evaluateExpression");
|
|
7
|
-
const evaluateErrorRule = (errorRule, options) => {
|
|
8
|
-
const { conditions, error } = errorRule;
|
|
9
|
-
const { result, referenceRecord } = (0, evaluateConditions_1.evaluateConditions)(conditions, options);
|
|
10
|
-
if (!result) {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
throw new types_1.EndpointError((0, evaluateExpression_1.evaluateExpression)(error, "Error", {
|
|
14
|
-
...options,
|
|
15
|
-
referenceRecord: { ...options.referenceRecord, ...referenceRecord },
|
|
16
|
-
}));
|
|
17
|
-
};
|
|
18
|
-
exports.evaluateErrorRule = evaluateErrorRule;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.evaluateExpression = void 0;
|
|
4
|
-
const types_1 = require("../types");
|
|
5
|
-
const callFunction_1 = require("./callFunction");
|
|
6
|
-
const evaluateTemplate_1 = require("./evaluateTemplate");
|
|
7
|
-
const getReferenceValue_1 = require("./getReferenceValue");
|
|
8
|
-
const evaluateExpression = (obj, keyName, options) => {
|
|
9
|
-
if (typeof obj === "string") {
|
|
10
|
-
return (0, evaluateTemplate_1.evaluateTemplate)(obj, options);
|
|
11
|
-
}
|
|
12
|
-
else if (obj["fn"]) {
|
|
13
|
-
return (0, callFunction_1.callFunction)(obj, options);
|
|
14
|
-
}
|
|
15
|
-
else if (obj["ref"]) {
|
|
16
|
-
return (0, getReferenceValue_1.getReferenceValue)(obj, options);
|
|
17
|
-
}
|
|
18
|
-
throw new types_1.EndpointError(`'${keyName}': ${String(obj)} is not a string, function or reference.`);
|
|
19
|
-
};
|
|
20
|
-
exports.evaluateExpression = evaluateExpression;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.evaluateRules = void 0;
|
|
4
|
-
const types_1 = require("../types");
|
|
5
|
-
const evaluateEndpointRule_1 = require("./evaluateEndpointRule");
|
|
6
|
-
const evaluateErrorRule_1 = require("./evaluateErrorRule");
|
|
7
|
-
const evaluateTreeRule_1 = require("./evaluateTreeRule");
|
|
8
|
-
const evaluateRules = (rules, options) => {
|
|
9
|
-
for (const rule of rules) {
|
|
10
|
-
if (rule.type === "endpoint") {
|
|
11
|
-
const endpointOrUndefined = (0, evaluateEndpointRule_1.evaluateEndpointRule)(rule, options);
|
|
12
|
-
if (endpointOrUndefined) {
|
|
13
|
-
return endpointOrUndefined;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
else if (rule.type === "error") {
|
|
17
|
-
(0, evaluateErrorRule_1.evaluateErrorRule)(rule, options);
|
|
18
|
-
}
|
|
19
|
-
else if (rule.type === "tree") {
|
|
20
|
-
const endpointOrUndefined = (0, evaluateTreeRule_1.evaluateTreeRule)(rule, options);
|
|
21
|
-
if (endpointOrUndefined) {
|
|
22
|
-
return endpointOrUndefined;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
throw new types_1.EndpointError(`Unknown endpoint rule: ${rule}`);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
throw new types_1.EndpointError(`Rules evaluation failed`);
|
|
30
|
-
};
|
|
31
|
-
exports.evaluateRules = evaluateRules;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.evaluateTemplate = void 0;
|
|
4
|
-
const lib_1 = require("../lib");
|
|
5
|
-
const evaluateTemplate = (template, options) => {
|
|
6
|
-
const evaluatedTemplateArr = [];
|
|
7
|
-
const templateContext = {
|
|
8
|
-
...options.endpointParams,
|
|
9
|
-
...options.referenceRecord,
|
|
10
|
-
};
|
|
11
|
-
let currentIndex = 0;
|
|
12
|
-
while (currentIndex < template.length) {
|
|
13
|
-
const openingBraceIndex = template.indexOf("{", currentIndex);
|
|
14
|
-
if (openingBraceIndex === -1) {
|
|
15
|
-
evaluatedTemplateArr.push(template.slice(currentIndex));
|
|
16
|
-
break;
|
|
17
|
-
}
|
|
18
|
-
evaluatedTemplateArr.push(template.slice(currentIndex, openingBraceIndex));
|
|
19
|
-
const closingBraceIndex = template.indexOf("}", openingBraceIndex);
|
|
20
|
-
if (closingBraceIndex === -1) {
|
|
21
|
-
evaluatedTemplateArr.push(template.slice(openingBraceIndex));
|
|
22
|
-
break;
|
|
23
|
-
}
|
|
24
|
-
if (template[openingBraceIndex + 1] === "{" && template[closingBraceIndex + 1] === "}") {
|
|
25
|
-
evaluatedTemplateArr.push(template.slice(openingBraceIndex + 1, closingBraceIndex));
|
|
26
|
-
currentIndex = closingBraceIndex + 2;
|
|
27
|
-
}
|
|
28
|
-
const parameterName = template.substring(openingBraceIndex + 1, closingBraceIndex);
|
|
29
|
-
if (parameterName.includes("#")) {
|
|
30
|
-
const [refName, attrName] = parameterName.split("#");
|
|
31
|
-
evaluatedTemplateArr.push((0, lib_1.getAttr)(templateContext[refName], attrName));
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
evaluatedTemplateArr.push(templateContext[parameterName]);
|
|
35
|
-
}
|
|
36
|
-
currentIndex = closingBraceIndex + 1;
|
|
37
|
-
}
|
|
38
|
-
return evaluatedTemplateArr.join("");
|
|
39
|
-
};
|
|
40
|
-
exports.evaluateTemplate = evaluateTemplate;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.evaluateTreeRule = void 0;
|
|
4
|
-
const evaluateConditions_1 = require("./evaluateConditions");
|
|
5
|
-
const evaluateRules_1 = require("./evaluateRules");
|
|
6
|
-
const evaluateTreeRule = (treeRule, options) => {
|
|
7
|
-
const { conditions, rules } = treeRule;
|
|
8
|
-
const { result, referenceRecord } = (0, evaluateConditions_1.evaluateConditions)(conditions, options);
|
|
9
|
-
if (!result) {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
return (0, evaluateRules_1.evaluateRules)(rules, {
|
|
13
|
-
...options,
|
|
14
|
-
referenceRecord: { ...options.referenceRecord, ...referenceRecord },
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
exports.evaluateTreeRule = evaluateTreeRule;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getEndpointHeaders = void 0;
|
|
4
|
-
const types_1 = require("../types");
|
|
5
|
-
const evaluateExpression_1 = require("./evaluateExpression");
|
|
6
|
-
const getEndpointHeaders = (headers, options) => Object.entries(headers).reduce((acc, [headerKey, headerVal]) => ({
|
|
7
|
-
...acc,
|
|
8
|
-
[headerKey]: headerVal.map((headerValEntry) => {
|
|
9
|
-
const processedExpr = (0, evaluateExpression_1.evaluateExpression)(headerValEntry, "Header value entry", options);
|
|
10
|
-
if (typeof processedExpr !== "string") {
|
|
11
|
-
throw new types_1.EndpointError(`Header '${headerKey}' value '${processedExpr}' is not a string`);
|
|
12
|
-
}
|
|
13
|
-
return processedExpr;
|
|
14
|
-
}),
|
|
15
|
-
}), {});
|
|
16
|
-
exports.getEndpointHeaders = getEndpointHeaders;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getEndpointProperties = void 0;
|
|
4
|
-
const getEndpointProperty_1 = require("./getEndpointProperty");
|
|
5
|
-
const getEndpointProperties = (properties, options) => Object.entries(properties).reduce((acc, [propertyKey, propertyVal]) => ({
|
|
6
|
-
...acc,
|
|
7
|
-
[propertyKey]: (0, getEndpointProperty_1.getEndpointProperty)(propertyVal, options),
|
|
8
|
-
}), {});
|
|
9
|
-
exports.getEndpointProperties = getEndpointProperties;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getEndpointProperty = void 0;
|
|
4
|
-
const types_1 = require("../types");
|
|
5
|
-
const evaluateTemplate_1 = require("./evaluateTemplate");
|
|
6
|
-
const getEndpointProperties_1 = require("./getEndpointProperties");
|
|
7
|
-
const getEndpointProperty = (property, options) => {
|
|
8
|
-
if (Array.isArray(property)) {
|
|
9
|
-
return property.map((propertyEntry) => (0, exports.getEndpointProperty)(propertyEntry, options));
|
|
10
|
-
}
|
|
11
|
-
switch (typeof property) {
|
|
12
|
-
case "string":
|
|
13
|
-
return (0, evaluateTemplate_1.evaluateTemplate)(property, options);
|
|
14
|
-
case "object":
|
|
15
|
-
if (property === null) {
|
|
16
|
-
throw new types_1.EndpointError(`Unexpected endpoint property: ${property}`);
|
|
17
|
-
}
|
|
18
|
-
return (0, getEndpointProperties_1.getEndpointProperties)(property, options);
|
|
19
|
-
case "boolean":
|
|
20
|
-
return property;
|
|
21
|
-
default:
|
|
22
|
-
throw new types_1.EndpointError(`Unexpected endpoint property type: ${typeof property}`);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
exports.getEndpointProperty = getEndpointProperty;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getEndpointUrl = void 0;
|
|
4
|
-
const types_1 = require("../types");
|
|
5
|
-
const evaluateExpression_1 = require("./evaluateExpression");
|
|
6
|
-
const getEndpointUrl = (endpointUrl, options) => {
|
|
7
|
-
const expression = (0, evaluateExpression_1.evaluateExpression)(endpointUrl, "Endpoint URL", options);
|
|
8
|
-
if (typeof expression === "string") {
|
|
9
|
-
try {
|
|
10
|
-
return new URL(expression);
|
|
11
|
-
}
|
|
12
|
-
catch (error) {
|
|
13
|
-
console.error(`Failed to construct URL with ${expression}`, error);
|
|
14
|
-
throw error;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
throw new types_1.EndpointError(`Endpoint URL must be a string, got ${typeof expression}`);
|
|
18
|
-
};
|
|
19
|
-
exports.getEndpointUrl = getEndpointUrl;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getReferenceValue = void 0;
|
|
4
|
-
const getReferenceValue = ({ ref }, options) => {
|
|
5
|
-
const referenceRecord = {
|
|
6
|
-
...options.endpointParams,
|
|
7
|
-
...options.referenceRecord,
|
|
8
|
-
};
|
|
9
|
-
return referenceRecord[ref];
|
|
10
|
-
};
|
|
11
|
-
exports.getReferenceValue = getReferenceValue;
|
package/dist-cjs/utils/index.js
DELETED
package/dist-es/debug/debugId.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const debugId = "endpoints";
|
package/dist-es/debug/index.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export function toDebugString(input) {
|
|
2
|
-
if (typeof input !== "object" || input == null) {
|
|
3
|
-
return input;
|
|
4
|
-
}
|
|
5
|
-
if ("ref" in input) {
|
|
6
|
-
return `$${toDebugString(input.ref)}`;
|
|
7
|
-
}
|
|
8
|
-
if ("fn" in input) {
|
|
9
|
-
return `${input.fn}(${(input.argv || []).map(toDebugString).join(", ")})`;
|
|
10
|
-
}
|
|
11
|
-
return JSON.stringify(input, null, 2);
|
|
12
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const booleanEquals = (value1, value2) => value1 === value2;
|
package/dist-es/lib/getAttr.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { EndpointError } from "../types";
|
|
2
|
-
import { getAttrPathList } from "./getAttrPathList";
|
|
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,25 +0,0 @@
|
|
|
1
|
-
import { EndpointError } from "../types";
|
|
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 ']'`);
|
|
10
|
-
}
|
|
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}'`);
|
|
14
|
-
}
|
|
15
|
-
if (squareBracketIndex !== 0) {
|
|
16
|
-
pathList.push(part.slice(0, squareBracketIndex));
|
|
17
|
-
}
|
|
18
|
-
pathList.push(arrayIndex);
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
pathList.push(part);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return pathList;
|
|
25
|
-
};
|
package/dist-es/lib/index.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export * as aws from "./aws";
|
|
2
|
-
export * from "./booleanEquals";
|
|
3
|
-
export * from "./getAttr";
|
|
4
|
-
export * from "./isSet";
|
|
5
|
-
export * from "./isValidHostLabel";
|
|
6
|
-
export * from "./not";
|
|
7
|
-
export * from "./parseURL";
|
|
8
|
-
export * from "./stringEquals";
|
|
9
|
-
export * from "./substring";
|
|
10
|
-
export * from "./uriEncode";
|
package/dist-es/lib/isSet.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const isSet = (value) => value != null;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
const VALID_HOST_LABEL_REGEX = new RegExp(`^(?!.*-$)(?!-)[a-zA-Z0-9-]{1,63}$`);
|
|
2
|
-
export const isValidHostLabel = (value, allowSubDomains = false) => {
|
|
3
|
-
if (!allowSubDomains) {
|
|
4
|
-
return VALID_HOST_LABEL_REGEX.test(value);
|
|
5
|
-
}
|
|
6
|
-
const labels = value.split(".");
|
|
7
|
-
for (const label of labels) {
|
|
8
|
-
if (!isValidHostLabel(label)) {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
return true;
|
|
13
|
-
};
|
package/dist-es/lib/not.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const not = (value) => !value;
|
package/dist-es/lib/parseURL.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { EndpointURLScheme } from "@aws-sdk/types";
|
|
2
|
-
import { isIpAddress } from "./isIpAddress";
|
|
3
|
-
const DEFAULT_PORTS = {
|
|
4
|
-
[EndpointURLScheme.HTTP]: 80,
|
|
5
|
-
[EndpointURLScheme.HTTPS]: 443,
|
|
6
|
-
};
|
|
7
|
-
export const parseURL = (value) => {
|
|
8
|
-
const whatwgURL = (() => {
|
|
9
|
-
try {
|
|
10
|
-
if (value instanceof URL) {
|
|
11
|
-
return value;
|
|
12
|
-
}
|
|
13
|
-
if (typeof value === "object" && "hostname" in value) {
|
|
14
|
-
const { hostname, port, protocol = "", path = "", query = {} } = value;
|
|
15
|
-
const url = new URL(`${protocol}//${hostname}${port ? `:${port}` : ""}${path}`);
|
|
16
|
-
url.search = Object.entries(query)
|
|
17
|
-
.map(([k, v]) => `${k}=${v}`)
|
|
18
|
-
.join("&");
|
|
19
|
-
return url;
|
|
20
|
-
}
|
|
21
|
-
return new URL(value);
|
|
22
|
-
}
|
|
23
|
-
catch (error) {
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
})();
|
|
27
|
-
if (!whatwgURL) {
|
|
28
|
-
console.error(`Unable to parse ${JSON.stringify(value)} as a whatwg URL.`);
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
const urlString = whatwgURL.href;
|
|
32
|
-
const { host, hostname, pathname, protocol, search } = whatwgURL;
|
|
33
|
-
if (search) {
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
const scheme = protocol.slice(0, -1);
|
|
37
|
-
if (!Object.values(EndpointURLScheme).includes(scheme)) {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
const isIp = isIpAddress(hostname);
|
|
41
|
-
const inputContainsDefaultPort = urlString.includes(`${host}:${DEFAULT_PORTS[scheme]}`) ||
|
|
42
|
-
(typeof value === "string" && value.includes(`${host}:${DEFAULT_PORTS[scheme]}`));
|
|
43
|
-
const authority = `${host}${inputContainsDefaultPort ? `:${DEFAULT_PORTS[scheme]}` : ``}`;
|
|
44
|
-
return {
|
|
45
|
-
scheme,
|
|
46
|
-
authority,
|
|
47
|
-
path: pathname,
|
|
48
|
-
normalizedPath: pathname.endsWith("/") ? pathname : `${pathname}/`,
|
|
49
|
-
isIp,
|
|
50
|
-
};
|
|
51
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const stringEquals = (value1, value2) => value1 === value2;
|
package/dist-es/lib/substring.js
DELETED
package/dist-es/lib/uriEncode.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const uriEncode = (value) => encodeURIComponent(value).replace(/[!*'()]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import * as lib from "../lib";
|
|
2
|
-
import { evaluateExpression } from "./evaluateExpression";
|
|
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);
|
|
6
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { debugId, toDebugString } from "../debug";
|
|
2
|
-
import { EndpointError } from "../types";
|
|
3
|
-
import { callFunction } from "./callFunction";
|
|
4
|
-
export const evaluateCondition = ({ assign, ...fnArgs }, options) => {
|
|
5
|
-
if (assign && assign in options.referenceRecord) {
|
|
6
|
-
throw new EndpointError(`'${assign}' is already defined in Reference Record.`);
|
|
7
|
-
}
|
|
8
|
-
const value = callFunction(fnArgs, options);
|
|
9
|
-
options.logger?.debug?.(debugId, `evaluateCondition: ${toDebugString(fnArgs)} = ${toDebugString(value)}`);
|
|
10
|
-
return {
|
|
11
|
-
result: value === "" ? true : !!value,
|
|
12
|
-
...(assign != null && { toAssign: { name: assign, value } }),
|
|
13
|
-
};
|
|
14
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { debugId, toDebugString } from "../debug";
|
|
2
|
-
import { evaluateCondition } from "./evaluateCondition";
|
|
3
|
-
export const evaluateConditions = (conditions = [], options) => {
|
|
4
|
-
const conditionsReferenceRecord = {};
|
|
5
|
-
for (const condition of conditions) {
|
|
6
|
-
const { result, toAssign } = evaluateCondition(condition, {
|
|
7
|
-
...options,
|
|
8
|
-
referenceRecord: {
|
|
9
|
-
...options.referenceRecord,
|
|
10
|
-
...conditionsReferenceRecord,
|
|
11
|
-
},
|
|
12
|
-
});
|
|
13
|
-
if (!result) {
|
|
14
|
-
return { result };
|
|
15
|
-
}
|
|
16
|
-
if (toAssign) {
|
|
17
|
-
conditionsReferenceRecord[toAssign.name] = toAssign.value;
|
|
18
|
-
options.logger?.debug?.(debugId, `assign: ${toAssign.name} := ${toDebugString(toAssign.value)}`);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return { result: true, referenceRecord: conditionsReferenceRecord };
|
|
22
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { debugId, toDebugString } from "../debug";
|
|
2
|
-
import { evaluateConditions } from "./evaluateConditions";
|
|
3
|
-
import { getEndpointHeaders } from "./getEndpointHeaders";
|
|
4
|
-
import { getEndpointProperties } from "./getEndpointProperties";
|
|
5
|
-
import { getEndpointUrl } from "./getEndpointUrl";
|
|
6
|
-
export const evaluateEndpointRule = (endpointRule, options) => {
|
|
7
|
-
const { conditions, endpoint } = endpointRule;
|
|
8
|
-
const { result, referenceRecord } = evaluateConditions(conditions, options);
|
|
9
|
-
if (!result) {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
const endpointRuleOptions = {
|
|
13
|
-
...options,
|
|
14
|
-
referenceRecord: { ...options.referenceRecord, ...referenceRecord },
|
|
15
|
-
};
|
|
16
|
-
const { url, properties, headers } = endpoint;
|
|
17
|
-
options.logger?.debug?.(debugId, `Resolving endpoint from template: ${toDebugString(endpoint)}`);
|
|
18
|
-
return {
|
|
19
|
-
...(headers != undefined && {
|
|
20
|
-
headers: getEndpointHeaders(headers, endpointRuleOptions),
|
|
21
|
-
}),
|
|
22
|
-
...(properties != undefined && {
|
|
23
|
-
properties: getEndpointProperties(properties, endpointRuleOptions),
|
|
24
|
-
}),
|
|
25
|
-
url: getEndpointUrl(url, endpointRuleOptions),
|
|
26
|
-
};
|
|
27
|
-
};
|