@aws-sdk/util-endpoints 3.159.0 → 3.167.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 +24 -0
- package/dist-cjs/index.js +2 -1
- package/dist-cjs/lib/getAttr.js +2 -2
- package/dist-cjs/lib/getAttrPathList.js +3 -3
- package/dist-cjs/resolveEndpoint.js +28 -0
- package/dist-cjs/{EndpointError.js → types/EndpointError.js} +0 -0
- package/dist-cjs/types/EndpointRuleObject.js +2 -0
- package/dist-cjs/types/ErrorRuleObject.js +2 -0
- package/dist-cjs/types/RuleSetObject.js +2 -0
- package/dist-cjs/types/TreeRuleObject.js +2 -0
- package/dist-cjs/types/index.js +9 -0
- package/dist-cjs/types/shared.js +2 -0
- package/dist-cjs/utils/callFunction.js +11 -0
- package/dist-cjs/utils/evaluateCondition.js +16 -0
- package/dist-cjs/utils/evaluateConditions.js +24 -0
- package/dist-cjs/utils/evaluateEndpointRule.js +29 -0
- package/dist-cjs/utils/evaluateErrorRule.js +18 -0
- package/dist-cjs/utils/evaluateExpression.js +20 -0
- package/dist-cjs/utils/evaluateRules.js +31 -0
- package/dist-cjs/utils/evaluateTemplate.js +27 -0
- package/dist-cjs/utils/evaluateTreeRule.js +17 -0
- package/dist-cjs/utils/getEndpointHeaders.js +16 -0
- package/dist-cjs/utils/getEndpointProperties.js +9 -0
- package/dist-cjs/utils/getEndpointProperty.js +25 -0
- package/dist-cjs/utils/getEndpointUrl.js +13 -0
- package/dist-cjs/utils/getReferenceValue.js +15 -0
- package/dist-cjs/utils/index.js +4 -0
- package/dist-es/index.js +2 -1
- package/dist-es/lib/getAttr.js +1 -1
- package/dist-es/lib/getAttrPathList.js +1 -1
- package/dist-es/resolveEndpoint.js +58 -0
- package/dist-es/{EndpointError.js → types/EndpointError.js} +0 -0
- package/dist-es/types/EndpointRuleObject.js +1 -0
- package/dist-es/types/ErrorRuleObject.js +1 -0
- package/dist-es/types/RuleSetObject.js +1 -0
- package/dist-es/types/TreeRuleObject.js +1 -0
- package/dist-es/types/index.js +6 -0
- package/dist-es/types/shared.js +1 -0
- package/dist-es/utils/callFunction.js +8 -0
- package/dist-es/utils/evaluateCondition.js +11 -0
- package/dist-es/utils/evaluateConditions.js +27 -0
- package/dist-es/utils/evaluateEndpointRule.js +19 -0
- package/dist-es/utils/evaluateErrorRule.js +12 -0
- package/dist-es/utils/evaluateExpression.js +16 -0
- package/dist-es/utils/evaluateRules.js +39 -0
- package/dist-es/utils/evaluateTemplate.js +24 -0
- package/dist-es/utils/evaluateTreeRule.js +11 -0
- package/dist-es/utils/getEndpointHeaders.js +16 -0
- package/dist-es/utils/getEndpointProperties.js +9 -0
- package/dist-es/utils/getEndpointProperty.js +21 -0
- package/dist-es/utils/getEndpointUrl.js +9 -0
- package/dist-es/utils/getReferenceValue.js +10 -0
- package/dist-es/utils/index.js +1 -0
- package/dist-types/index.d.ts +2 -1
- package/dist-types/resolveEndpoint.d.ts +6 -0
- package/dist-types/ts3.4/index.d.ts +2 -1
- package/dist-types/ts3.4/resolveEndpoint.d.ts +4 -0
- package/dist-types/ts3.4/{EndpointError.d.ts → types/EndpointError.d.ts} +0 -0
- package/dist-types/ts3.4/types/EndpointRuleObject.d.ts +15 -0
- package/dist-types/ts3.4/types/ErrorRuleObject.d.ts +7 -0
- package/dist-types/ts3.4/types/RuleSetObject.d.ts +18 -0
- package/dist-types/ts3.4/types/TreeRuleObject.d.ts +10 -0
- package/dist-types/ts3.4/types/index.d.ts +6 -0
- package/dist-types/ts3.4/types/shared.d.ts +25 -0
- package/dist-types/ts3.4/utils/callFunction.d.ts +2 -0
- package/dist-types/ts3.4/utils/evaluateCondition.d.ts +8 -0
- package/dist-types/ts3.4/utils/evaluateConditions.d.ts +8 -0
- package/dist-types/ts3.4/utils/evaluateEndpointRule.d.ts +3 -0
- package/dist-types/ts3.4/utils/evaluateErrorRule.d.ts +2 -0
- package/dist-types/ts3.4/utils/evaluateExpression.d.ts +2 -0
- package/dist-types/ts3.4/utils/evaluateRules.d.ts +3 -0
- package/dist-types/ts3.4/utils/evaluateTemplate.d.ts +2 -0
- package/dist-types/ts3.4/utils/evaluateTreeRule.d.ts +3 -0
- package/dist-types/ts3.4/utils/getEndpointHeaders.d.ts +2 -0
- package/dist-types/ts3.4/utils/getEndpointProperties.d.ts +2 -0
- package/dist-types/ts3.4/utils/getEndpointProperty.d.ts +3 -0
- package/dist-types/ts3.4/utils/getEndpointUrl.d.ts +2 -0
- package/dist-types/ts3.4/utils/getReferenceValue.d.ts +2 -0
- package/dist-types/ts3.4/utils/index.d.ts +1 -0
- package/dist-types/{EndpointError.d.ts → types/EndpointError.d.ts} +0 -0
- package/dist-types/types/EndpointRuleObject.d.ts +15 -0
- package/dist-types/types/ErrorRuleObject.d.ts +7 -0
- package/dist-types/types/RuleSetObject.d.ts +18 -0
- package/dist-types/types/TreeRuleObject.d.ts +10 -0
- package/dist-types/types/index.d.ts +6 -0
- package/dist-types/types/shared.d.ts +25 -0
- package/dist-types/utils/callFunction.d.ts +2 -0
- package/dist-types/utils/evaluateCondition.d.ts +8 -0
- package/dist-types/utils/evaluateConditions.d.ts +8 -0
- package/dist-types/utils/evaluateEndpointRule.d.ts +3 -0
- package/dist-types/utils/evaluateErrorRule.d.ts +2 -0
- package/dist-types/utils/evaluateExpression.d.ts +2 -0
- package/dist-types/utils/evaluateRules.d.ts +3 -0
- package/dist-types/utils/evaluateTemplate.d.ts +2 -0
- package/dist-types/utils/evaluateTreeRule.d.ts +3 -0
- package/dist-types/utils/getEndpointHeaders.d.ts +2 -0
- package/dist-types/utils/getEndpointProperties.d.ts +2 -0
- package/dist-types/utils/getEndpointProperty.d.ts +3 -0
- package/dist-types/utils/getEndpointUrl.d.ts +2 -0
- package/dist-types/utils/getReferenceValue.d.ts +2 -0
- package/dist-types/utils/index.d.ts +1 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,30 @@
|
|
|
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.167.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.166.0...v3.167.0) (2022-09-08)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @aws-sdk/util-endpoints
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# [3.162.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.161.0...v3.162.0) (2022-08-31)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @aws-sdk/util-endpoints
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# [3.160.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.159.0...v3.160.0) (2022-08-29)
|
|
23
|
+
|
|
24
|
+
**Note:** Version bump only for package @aws-sdk/util-endpoints
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
6
30
|
# [3.159.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.158.0...v3.159.0) (2022-08-26)
|
|
7
31
|
|
|
8
32
|
|
package/dist-cjs/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./
|
|
4
|
+
tslib_1.__exportStar(require("./resolveEndpoint"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./types"), exports);
|
package/dist-cjs/lib/getAttr.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getAttr = void 0;
|
|
4
|
-
const
|
|
4
|
+
const types_1 = require("../types");
|
|
5
5
|
const getAttrPathList_1 = require("./getAttrPathList");
|
|
6
6
|
const getAttr = (value, path) => (0, getAttrPathList_1.getAttrPathList)(path).reduce((acc, index) => {
|
|
7
7
|
if (typeof acc !== "object") {
|
|
8
|
-
throw new
|
|
8
|
+
throw new types_1.EndpointError(`Index '${index}' in '${path}' not found in '${JSON.stringify(value)}'`);
|
|
9
9
|
}
|
|
10
10
|
else if (Array.isArray(acc)) {
|
|
11
11
|
return acc[parseInt(index)];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getAttrPathList = void 0;
|
|
4
|
-
const
|
|
4
|
+
const types_1 = require("../types");
|
|
5
5
|
const getAttrPathList = (path) => {
|
|
6
6
|
const parts = path.split(".");
|
|
7
7
|
const pathList = [];
|
|
@@ -9,11 +9,11 @@ const getAttrPathList = (path) => {
|
|
|
9
9
|
const squareBracketIndex = part.indexOf("[");
|
|
10
10
|
if (squareBracketIndex !== -1) {
|
|
11
11
|
if (part.indexOf("]") !== part.length - 1) {
|
|
12
|
-
throw new
|
|
12
|
+
throw new types_1.EndpointError(`Path: '${path}' does not end with ']'`);
|
|
13
13
|
}
|
|
14
14
|
const arrayIndex = part.slice(squareBracketIndex + 1, -1);
|
|
15
15
|
if (Number.isNaN(parseInt(arrayIndex))) {
|
|
16
|
-
throw new
|
|
16
|
+
throw new types_1.EndpointError(`Invalid array index: '${arrayIndex}' in path: '${path}'`);
|
|
17
17
|
}
|
|
18
18
|
if (squareBracketIndex !== 0) {
|
|
19
19
|
pathList.push(part.slice(0, squareBracketIndex));
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveEndpoint = void 0;
|
|
4
|
+
const types_1 = require("./types");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
const resolveEndpoint = (ruleSetObject, options) => {
|
|
7
|
+
var _a;
|
|
8
|
+
const { endpointParams, logger } = options;
|
|
9
|
+
const { parameters, rules } = ruleSetObject;
|
|
10
|
+
const requiredParams = Object.entries(parameters)
|
|
11
|
+
.filter(([, v]) => v.required)
|
|
12
|
+
.map(([k]) => k);
|
|
13
|
+
for (const requiredParam of requiredParams) {
|
|
14
|
+
if (endpointParams[requiredParam] == null) {
|
|
15
|
+
throw new types_1.EndpointError(`Missing required parameter: '${requiredParam}'`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const paramsWithDefault = Object.entries(parameters)
|
|
19
|
+
.filter(([, v]) => v.default != null)
|
|
20
|
+
.map(([k, v]) => [k, v.default]);
|
|
21
|
+
if (paramsWithDefault.length > 0) {
|
|
22
|
+
for (const [paramKey, paramDefaultValue] of paramsWithDefault) {
|
|
23
|
+
endpointParams[paramKey] = (_a = endpointParams[paramKey]) !== null && _a !== void 0 ? _a : paramDefaultValue;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return (0, utils_1.evaluateRules)(rules, { endpointParams, logger, referenceRecord: {} });
|
|
27
|
+
};
|
|
28
|
+
exports.resolveEndpoint = resolveEndpoint;
|
|
File without changes
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./EndpointError"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./EndpointRuleObject"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./ErrorRuleObject"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./RuleSetObject"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./TreeRuleObject"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./shared"), exports);
|
|
@@ -0,0 +1,11 @@
|
|
|
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 argvArray = argv.map((arg) => (typeof arg === "boolean" ? arg : (0, evaluateExpression_1.evaluateExpression)(arg, "arg", options)));
|
|
9
|
+
return lib[fn](...argvArray);
|
|
10
|
+
};
|
|
11
|
+
exports.callFunction = callFunction;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.evaluateCondition = void 0;
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
const callFunction_1 = require("./callFunction");
|
|
6
|
+
const evaluateCondition = ({ assign, ...fnArgs }, options) => {
|
|
7
|
+
if (assign && assign in options.referenceRecord) {
|
|
8
|
+
throw new types_1.EndpointError(`'${assign}' is already defined in Reference Record.`);
|
|
9
|
+
}
|
|
10
|
+
const value = (0, callFunction_1.callFunction)(fnArgs, options);
|
|
11
|
+
return {
|
|
12
|
+
result: !!value,
|
|
13
|
+
...(assign != null && { toAssign: { name: assign, value } }),
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
exports.evaluateCondition = evaluateCondition;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.evaluateConditions = void 0;
|
|
4
|
+
const evaluateCondition_1 = require("./evaluateCondition");
|
|
5
|
+
const evaluateConditions = (conditions = [], options) => {
|
|
6
|
+
const conditionsReferenceRecord = {};
|
|
7
|
+
for (const condition of conditions) {
|
|
8
|
+
const { result, toAssign } = (0, evaluateCondition_1.evaluateCondition)(condition, {
|
|
9
|
+
...options,
|
|
10
|
+
referenceRecord: {
|
|
11
|
+
...options.referenceRecord,
|
|
12
|
+
...conditionsReferenceRecord,
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
if (!result) {
|
|
16
|
+
return { result };
|
|
17
|
+
}
|
|
18
|
+
if (toAssign) {
|
|
19
|
+
conditionsReferenceRecord[toAssign.name] = toAssign.value;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return { result: true, referenceRecord: conditionsReferenceRecord };
|
|
23
|
+
};
|
|
24
|
+
exports.evaluateConditions = evaluateConditions;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.evaluateEndpointRule = void 0;
|
|
4
|
+
const evaluateConditions_1 = require("./evaluateConditions");
|
|
5
|
+
const getEndpointHeaders_1 = require("./getEndpointHeaders");
|
|
6
|
+
const getEndpointProperties_1 = require("./getEndpointProperties");
|
|
7
|
+
const getEndpointUrl_1 = require("./getEndpointUrl");
|
|
8
|
+
const evaluateEndpointRule = (endpointRule, options) => {
|
|
9
|
+
const { conditions, endpoint } = endpointRule;
|
|
10
|
+
const { result, referenceRecord } = (0, evaluateConditions_1.evaluateConditions)(conditions, options);
|
|
11
|
+
if (!result) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const endpointRuleOptions = {
|
|
15
|
+
...options,
|
|
16
|
+
referenceRecord: { ...options.referenceRecord, ...referenceRecord },
|
|
17
|
+
};
|
|
18
|
+
const { url, properties, headers } = endpoint;
|
|
19
|
+
return {
|
|
20
|
+
...(headers != undefined && {
|
|
21
|
+
headers: (0, getEndpointHeaders_1.getEndpointHeaders)(headers, endpointRuleOptions),
|
|
22
|
+
}),
|
|
23
|
+
...(properties != undefined && {
|
|
24
|
+
properties: (0, getEndpointProperties_1.getEndpointProperties)(properties, endpointRuleOptions),
|
|
25
|
+
}),
|
|
26
|
+
url: (0, getEndpointUrl_1.getEndpointUrl)(url, endpointRuleOptions),
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
exports.evaluateEndpointRule = evaluateEndpointRule;
|
|
@@ -0,0 +1,18 @@
|
|
|
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;
|
|
@@ -0,0 +1,20 @@
|
|
|
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;
|
|
@@ -0,0 +1,31 @@
|
|
|
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;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.evaluateTemplate = void 0;
|
|
4
|
+
const lib_1 = require("../lib");
|
|
5
|
+
const ATTR_SHORTHAND_REGEX = new RegExp("\\${([\\w]+)#([\\w]+)}", "g");
|
|
6
|
+
const evaluateTemplate = (template, options) => {
|
|
7
|
+
const templateToEvaluate = template
|
|
8
|
+
.replace(new RegExp(`\{([^{}]+)\}`, "g"), "${$1}")
|
|
9
|
+
.replace(new RegExp(`\{\\$\{([^{}]+)\}\}`, "g"), "{$1}");
|
|
10
|
+
const templateContext = {
|
|
11
|
+
...options.endpointParams,
|
|
12
|
+
...options.referenceRecord,
|
|
13
|
+
};
|
|
14
|
+
const attrShortHandList = templateToEvaluate.match(ATTR_SHORTHAND_REGEX) || [];
|
|
15
|
+
const attrShortHandMap = attrShortHandList.reduce((acc, attrShortHand) => {
|
|
16
|
+
const indexOfHash = attrShortHand.indexOf("#");
|
|
17
|
+
const refName = attrShortHand.substring(2, indexOfHash);
|
|
18
|
+
const attrName = attrShortHand.substring(indexOfHash + 1, attrShortHand.length - 1);
|
|
19
|
+
acc[attrShortHand] = (0, lib_1.getAttr)(templateContext[refName], attrName);
|
|
20
|
+
return acc;
|
|
21
|
+
}, {});
|
|
22
|
+
const templateWithAttr = Object.entries(attrShortHandMap).reduce((acc, [shortHand, value]) => acc.replace(shortHand, value), templateToEvaluate);
|
|
23
|
+
const templateContextNames = Object.keys(templateContext);
|
|
24
|
+
const templateContextValues = Object.values(templateContext);
|
|
25
|
+
return new Function(...templateContextNames, `return \`${templateWithAttr}\``)(...templateContextValues);
|
|
26
|
+
};
|
|
27
|
+
exports.evaluateTemplate = evaluateTemplate;
|
|
@@ -0,0 +1,17 @@
|
|
|
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;
|
|
@@ -0,0 +1,16 @@
|
|
|
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;
|
|
@@ -0,0 +1,9 @@
|
|
|
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;
|
|
@@ -0,0 +1,25 @@
|
|
|
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;
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
return new URL(expression);
|
|
10
|
+
}
|
|
11
|
+
throw new types_1.EndpointError(`Endpoint URL must be a string, got ${typeof expression}`);
|
|
12
|
+
};
|
|
13
|
+
exports.getEndpointUrl = getEndpointUrl;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getReferenceValue = void 0;
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
const getReferenceValue = ({ ref }, options) => {
|
|
6
|
+
const referenceRecord = {
|
|
7
|
+
...options.endpointParams,
|
|
8
|
+
...options.referenceRecord,
|
|
9
|
+
};
|
|
10
|
+
if (referenceRecord[ref] == undefined) {
|
|
11
|
+
throw new types_1.EndpointError(`Reference '${ref}' not defined`);
|
|
12
|
+
}
|
|
13
|
+
return referenceRecord[ref];
|
|
14
|
+
};
|
|
15
|
+
exports.getReferenceValue = getReferenceValue;
|
package/dist-es/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from "./
|
|
1
|
+
export * from "./resolveEndpoint";
|
|
2
|
+
export * from "./types";
|
package/dist-es/lib/getAttr.js
CHANGED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { __read, __values } from "tslib";
|
|
2
|
+
import { EndpointError } from "./types";
|
|
3
|
+
import { evaluateRules } from "./utils";
|
|
4
|
+
export var resolveEndpoint = function (ruleSetObject, options) {
|
|
5
|
+
var e_1, _a, e_2, _b;
|
|
6
|
+
var _c;
|
|
7
|
+
var endpointParams = options.endpointParams, logger = options.logger;
|
|
8
|
+
var parameters = ruleSetObject.parameters, rules = ruleSetObject.rules;
|
|
9
|
+
var requiredParams = Object.entries(parameters)
|
|
10
|
+
.filter(function (_a) {
|
|
11
|
+
var _b = __read(_a, 2), v = _b[1];
|
|
12
|
+
return v.required;
|
|
13
|
+
})
|
|
14
|
+
.map(function (_a) {
|
|
15
|
+
var _b = __read(_a, 1), k = _b[0];
|
|
16
|
+
return k;
|
|
17
|
+
});
|
|
18
|
+
try {
|
|
19
|
+
for (var requiredParams_1 = __values(requiredParams), requiredParams_1_1 = requiredParams_1.next(); !requiredParams_1_1.done; requiredParams_1_1 = requiredParams_1.next()) {
|
|
20
|
+
var requiredParam = requiredParams_1_1.value;
|
|
21
|
+
if (endpointParams[requiredParam] == null) {
|
|
22
|
+
throw new EndpointError("Missing required parameter: '".concat(requiredParam, "'"));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
27
|
+
finally {
|
|
28
|
+
try {
|
|
29
|
+
if (requiredParams_1_1 && !requiredParams_1_1.done && (_a = requiredParams_1.return)) _a.call(requiredParams_1);
|
|
30
|
+
}
|
|
31
|
+
finally { if (e_1) throw e_1.error; }
|
|
32
|
+
}
|
|
33
|
+
var paramsWithDefault = Object.entries(parameters)
|
|
34
|
+
.filter(function (_a) {
|
|
35
|
+
var _b = __read(_a, 2), v = _b[1];
|
|
36
|
+
return v.default != null;
|
|
37
|
+
})
|
|
38
|
+
.map(function (_a) {
|
|
39
|
+
var _b = __read(_a, 2), k = _b[0], v = _b[1];
|
|
40
|
+
return [k, v.default];
|
|
41
|
+
});
|
|
42
|
+
if (paramsWithDefault.length > 0) {
|
|
43
|
+
try {
|
|
44
|
+
for (var paramsWithDefault_1 = __values(paramsWithDefault), paramsWithDefault_1_1 = paramsWithDefault_1.next(); !paramsWithDefault_1_1.done; paramsWithDefault_1_1 = paramsWithDefault_1.next()) {
|
|
45
|
+
var _d = __read(paramsWithDefault_1_1.value, 2), paramKey = _d[0], paramDefaultValue = _d[1];
|
|
46
|
+
endpointParams[paramKey] = (_c = endpointParams[paramKey]) !== null && _c !== void 0 ? _c : paramDefaultValue;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
50
|
+
finally {
|
|
51
|
+
try {
|
|
52
|
+
if (paramsWithDefault_1_1 && !paramsWithDefault_1_1.done && (_b = paramsWithDefault_1.return)) _b.call(paramsWithDefault_1);
|
|
53
|
+
}
|
|
54
|
+
finally { if (e_2) throw e_2.error; }
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return evaluateRules(rules, { endpointParams: endpointParams, logger: logger, referenceRecord: {} });
|
|
58
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { __read, __spreadArray } from "tslib";
|
|
2
|
+
import * as lib from "../lib";
|
|
3
|
+
import { evaluateExpression } from "./evaluateExpression";
|
|
4
|
+
export var callFunction = function (_a, options) {
|
|
5
|
+
var fn = _a.fn, argv = _a.argv;
|
|
6
|
+
var argvArray = argv.map(function (arg) { return (typeof arg === "boolean" ? arg : evaluateExpression(arg, "arg", options)); });
|
|
7
|
+
return lib[fn].apply(lib, __spreadArray([], __read(argvArray), false));
|
|
8
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { __assign, __rest } from "tslib";
|
|
2
|
+
import { EndpointError } from "../types";
|
|
3
|
+
import { callFunction } from "./callFunction";
|
|
4
|
+
export var evaluateCondition = function (_a, options) {
|
|
5
|
+
var assign = _a.assign, fnArgs = __rest(_a, ["assign"]);
|
|
6
|
+
if (assign && assign in options.referenceRecord) {
|
|
7
|
+
throw new EndpointError("'".concat(assign, "' is already defined in Reference Record."));
|
|
8
|
+
}
|
|
9
|
+
var value = callFunction(fnArgs, options);
|
|
10
|
+
return __assign({ result: !!value }, (assign != null && { toAssign: { name: assign, value: value } }));
|
|
11
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { __assign, __values } from "tslib";
|
|
2
|
+
import { evaluateCondition } from "./evaluateCondition";
|
|
3
|
+
export var evaluateConditions = function (conditions, options) {
|
|
4
|
+
var e_1, _a;
|
|
5
|
+
if (conditions === void 0) { conditions = []; }
|
|
6
|
+
var conditionsReferenceRecord = {};
|
|
7
|
+
try {
|
|
8
|
+
for (var conditions_1 = __values(conditions), conditions_1_1 = conditions_1.next(); !conditions_1_1.done; conditions_1_1 = conditions_1.next()) {
|
|
9
|
+
var condition = conditions_1_1.value;
|
|
10
|
+
var _b = evaluateCondition(condition, __assign(__assign({}, options), { referenceRecord: __assign(__assign({}, options.referenceRecord), conditionsReferenceRecord) })), result = _b.result, toAssign = _b.toAssign;
|
|
11
|
+
if (!result) {
|
|
12
|
+
return { result: result };
|
|
13
|
+
}
|
|
14
|
+
if (toAssign) {
|
|
15
|
+
conditionsReferenceRecord[toAssign.name] = toAssign.value;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
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);
|
|
23
|
+
}
|
|
24
|
+
finally { if (e_1) throw e_1.error; }
|
|
25
|
+
}
|
|
26
|
+
return { result: true, referenceRecord: conditionsReferenceRecord };
|
|
27
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { __assign } from "tslib";
|
|
2
|
+
import { evaluateConditions } from "./evaluateConditions";
|
|
3
|
+
import { getEndpointHeaders } from "./getEndpointHeaders";
|
|
4
|
+
import { getEndpointProperties } from "./getEndpointProperties";
|
|
5
|
+
import { getEndpointUrl } from "./getEndpointUrl";
|
|
6
|
+
export var evaluateEndpointRule = function (endpointRule, options) {
|
|
7
|
+
var conditions = endpointRule.conditions, endpoint = endpointRule.endpoint;
|
|
8
|
+
var _a = evaluateConditions(conditions, options), result = _a.result, referenceRecord = _a.referenceRecord;
|
|
9
|
+
if (!result) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
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) });
|
|
19
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { __assign } from "tslib";
|
|
2
|
+
import { EndpointError } from "../types";
|
|
3
|
+
import { evaluateConditions } from "./evaluateConditions";
|
|
4
|
+
import { evaluateExpression } from "./evaluateExpression";
|
|
5
|
+
export var evaluateErrorRule = function (errorRule, options) {
|
|
6
|
+
var conditions = errorRule.conditions, error = errorRule.error;
|
|
7
|
+
var _a = evaluateConditions(conditions, options), result = _a.result, referenceRecord = _a.referenceRecord;
|
|
8
|
+
if (!result) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
throw new EndpointError(evaluateExpression(error, "Error", __assign(__assign({}, options), { referenceRecord: __assign(__assign({}, options.referenceRecord), referenceRecord) })));
|
|
12
|
+
};
|