working rss feed to nostr publish
This commit is contained in:
+4
@@ -0,0 +1,4 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.debugId = void 0;
|
||||
exports.debugId = "endpoints";
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const tslib_1 = require("tslib");
|
||||
tslib_1.__exportStar(require("./debugId"), exports);
|
||||
tslib_1.__exportStar(require("./toDebugString"), exports);
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.toDebugString = void 0;
|
||||
function toDebugString(input) {
|
||||
if (typeof input !== "object" || input == null) {
|
||||
return input;
|
||||
}
|
||||
if ("ref" in input) {
|
||||
return `$${toDebugString(input.ref)}`;
|
||||
}
|
||||
if ("fn" in input) {
|
||||
return `${input.fn}(${(input.argv || []).map(toDebugString).join(", ")})`;
|
||||
}
|
||||
return JSON.stringify(input, null, 2);
|
||||
}
|
||||
exports.toDebugString = toDebugString;
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getEndpointUrlConfig = void 0;
|
||||
const ENV_ENDPOINT_URL = "AWS_ENDPOINT_URL";
|
||||
const CONFIG_ENDPOINT_URL = "endpoint_url";
|
||||
const getEndpointUrlConfig = (serviceId) => ({
|
||||
environmentVariableSelector: (env) => {
|
||||
const serviceEndpointUrlSections = [ENV_ENDPOINT_URL, ...serviceId.split(" ").map((w) => w.toUpperCase())];
|
||||
const serviceEndpointUrl = env[serviceEndpointUrlSections.join("_")];
|
||||
if (serviceEndpointUrl)
|
||||
return serviceEndpointUrl;
|
||||
const endpointUrl = env[ENV_ENDPOINT_URL];
|
||||
if (endpointUrl)
|
||||
return endpointUrl;
|
||||
return undefined;
|
||||
},
|
||||
configFileSelector: (profile) => {
|
||||
const endpointUrl = profile[CONFIG_ENDPOINT_URL];
|
||||
if (endpointUrl)
|
||||
return endpointUrl;
|
||||
return undefined;
|
||||
},
|
||||
default: undefined,
|
||||
});
|
||||
exports.getEndpointUrlConfig = getEndpointUrlConfig;
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const tslib_1 = require("tslib");
|
||||
tslib_1.__exportStar(require("./lib/isIpAddress"), exports);
|
||||
tslib_1.__exportStar(require("./lib/isValidHostLabel"), exports);
|
||||
tslib_1.__exportStar(require("./utils/customEndpointFunctions"), exports);
|
||||
tslib_1.__exportStar(require("./resolveEndpoint"), exports);
|
||||
tslib_1.__exportStar(require("./types"), exports);
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.booleanEquals = void 0;
|
||||
const booleanEquals = (value1, value2) => value1 === value2;
|
||||
exports.booleanEquals = booleanEquals;
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getAttr = void 0;
|
||||
const types_1 = require("../types");
|
||||
const getAttrPathList_1 = require("./getAttrPathList");
|
||||
const getAttr = (value, path) => (0, getAttrPathList_1.getAttrPathList)(path).reduce((acc, index) => {
|
||||
if (typeof acc !== "object") {
|
||||
throw new types_1.EndpointError(`Index '${index}' in '${path}' not found in '${JSON.stringify(value)}'`);
|
||||
}
|
||||
else if (Array.isArray(acc)) {
|
||||
return acc[parseInt(index)];
|
||||
}
|
||||
return acc[index];
|
||||
}, value);
|
||||
exports.getAttr = getAttr;
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getAttrPathList = void 0;
|
||||
const types_1 = require("../types");
|
||||
const getAttrPathList = (path) => {
|
||||
const parts = path.split(".");
|
||||
const pathList = [];
|
||||
for (const part of parts) {
|
||||
const squareBracketIndex = part.indexOf("[");
|
||||
if (squareBracketIndex !== -1) {
|
||||
if (part.indexOf("]") !== part.length - 1) {
|
||||
throw new types_1.EndpointError(`Path: '${path}' does not end with ']'`);
|
||||
}
|
||||
const arrayIndex = part.slice(squareBracketIndex + 1, -1);
|
||||
if (Number.isNaN(parseInt(arrayIndex))) {
|
||||
throw new types_1.EndpointError(`Invalid array index: '${arrayIndex}' in path: '${path}'`);
|
||||
}
|
||||
if (squareBracketIndex !== 0) {
|
||||
pathList.push(part.slice(0, squareBracketIndex));
|
||||
}
|
||||
pathList.push(arrayIndex);
|
||||
}
|
||||
else {
|
||||
pathList.push(part);
|
||||
}
|
||||
}
|
||||
return pathList;
|
||||
};
|
||||
exports.getAttrPathList = getAttrPathList;
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const tslib_1 = require("tslib");
|
||||
tslib_1.__exportStar(require("./booleanEquals"), exports);
|
||||
tslib_1.__exportStar(require("./getAttr"), exports);
|
||||
tslib_1.__exportStar(require("./isSet"), exports);
|
||||
tslib_1.__exportStar(require("./isValidHostLabel"), exports);
|
||||
tslib_1.__exportStar(require("./not"), exports);
|
||||
tslib_1.__exportStar(require("./parseURL"), exports);
|
||||
tslib_1.__exportStar(require("./stringEquals"), exports);
|
||||
tslib_1.__exportStar(require("./substring"), exports);
|
||||
tslib_1.__exportStar(require("./uriEncode"), exports);
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isIpAddress = void 0;
|
||||
const IP_V4_REGEX = new RegExp(`^(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}$`);
|
||||
const isIpAddress = (value) => IP_V4_REGEX.test(value) || (value.startsWith("[") && value.endsWith("]"));
|
||||
exports.isIpAddress = isIpAddress;
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isSet = void 0;
|
||||
const isSet = (value) => value != null;
|
||||
exports.isSet = isSet;
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isValidHostLabel = void 0;
|
||||
const VALID_HOST_LABEL_REGEX = new RegExp(`^(?!.*-$)(?!-)[a-zA-Z0-9-]{1,63}$`);
|
||||
const isValidHostLabel = (value, allowSubDomains = false) => {
|
||||
if (!allowSubDomains) {
|
||||
return VALID_HOST_LABEL_REGEX.test(value);
|
||||
}
|
||||
const labels = value.split(".");
|
||||
for (const label of labels) {
|
||||
if (!(0, exports.isValidHostLabel)(label)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
exports.isValidHostLabel = isValidHostLabel;
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.not = void 0;
|
||||
const not = (value) => !value;
|
||||
exports.not = not;
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.parseURL = void 0;
|
||||
const types_1 = require("@smithy/types");
|
||||
const isIpAddress_1 = require("./isIpAddress");
|
||||
const DEFAULT_PORTS = {
|
||||
[types_1.EndpointURLScheme.HTTP]: 80,
|
||||
[types_1.EndpointURLScheme.HTTPS]: 443,
|
||||
};
|
||||
const parseURL = (value) => {
|
||||
const whatwgURL = (() => {
|
||||
try {
|
||||
if (value instanceof URL) {
|
||||
return value;
|
||||
}
|
||||
if (typeof value === "object" && "hostname" in value) {
|
||||
const { hostname, port, protocol = "", path = "", query = {} } = value;
|
||||
const url = new URL(`${protocol}//${hostname}${port ? `:${port}` : ""}${path}`);
|
||||
url.search = Object.entries(query)
|
||||
.map(([k, v]) => `${k}=${v}`)
|
||||
.join("&");
|
||||
return url;
|
||||
}
|
||||
return new URL(value);
|
||||
}
|
||||
catch (error) {
|
||||
return null;
|
||||
}
|
||||
})();
|
||||
if (!whatwgURL) {
|
||||
console.error(`Unable to parse ${JSON.stringify(value)} as a whatwg URL.`);
|
||||
return null;
|
||||
}
|
||||
const urlString = whatwgURL.href;
|
||||
const { host, hostname, pathname, protocol, search } = whatwgURL;
|
||||
if (search) {
|
||||
return null;
|
||||
}
|
||||
const scheme = protocol.slice(0, -1);
|
||||
if (!Object.values(types_1.EndpointURLScheme).includes(scheme)) {
|
||||
return null;
|
||||
}
|
||||
const isIp = (0, isIpAddress_1.isIpAddress)(hostname);
|
||||
const inputContainsDefaultPort = urlString.includes(`${host}:${DEFAULT_PORTS[scheme]}`) ||
|
||||
(typeof value === "string" && value.includes(`${host}:${DEFAULT_PORTS[scheme]}`));
|
||||
const authority = `${host}${inputContainsDefaultPort ? `:${DEFAULT_PORTS[scheme]}` : ``}`;
|
||||
return {
|
||||
scheme,
|
||||
authority,
|
||||
path: pathname,
|
||||
normalizedPath: pathname.endsWith("/") ? pathname : `${pathname}/`,
|
||||
isIp,
|
||||
};
|
||||
};
|
||||
exports.parseURL = parseURL;
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.stringEquals = void 0;
|
||||
const stringEquals = (value1, value2) => value1 === value2;
|
||||
exports.stringEquals = stringEquals;
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.substring = void 0;
|
||||
const substring = (input, start, stop, reverse) => {
|
||||
if (start >= stop || input.length < stop) {
|
||||
return null;
|
||||
}
|
||||
if (!reverse) {
|
||||
return input.substring(start, stop);
|
||||
}
|
||||
return input.substring(input.length - stop, input.length - start);
|
||||
};
|
||||
exports.substring = substring;
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.uriEncode = void 0;
|
||||
const uriEncode = (value) => encodeURIComponent(value).replace(/[!*'()]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`);
|
||||
exports.uriEncode = uriEncode;
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.resolveEndpoint = void 0;
|
||||
const debug_1 = require("./debug");
|
||||
const types_1 = require("./types");
|
||||
const utils_1 = require("./utils");
|
||||
const resolveEndpoint = (ruleSetObject, options) => {
|
||||
var _a, _b, _c, _d, _e, _f;
|
||||
const { endpointParams, logger } = options;
|
||||
const { parameters, rules } = ruleSetObject;
|
||||
(_b = (_a = options.logger) === null || _a === void 0 ? void 0 : _a.debug) === null || _b === void 0 ? void 0 : _b.call(_a, `${debug_1.debugId} Initial EndpointParams: ${(0, debug_1.toDebugString)(endpointParams)}`);
|
||||
const paramsWithDefault = Object.entries(parameters)
|
||||
.filter(([, v]) => v.default != null)
|
||||
.map(([k, v]) => [k, v.default]);
|
||||
if (paramsWithDefault.length > 0) {
|
||||
for (const [paramKey, paramDefaultValue] of paramsWithDefault) {
|
||||
endpointParams[paramKey] = (_c = endpointParams[paramKey]) !== null && _c !== void 0 ? _c : paramDefaultValue;
|
||||
}
|
||||
}
|
||||
const requiredParams = Object.entries(parameters)
|
||||
.filter(([, v]) => v.required)
|
||||
.map(([k]) => k);
|
||||
for (const requiredParam of requiredParams) {
|
||||
if (endpointParams[requiredParam] == null) {
|
||||
throw new types_1.EndpointError(`Missing required parameter: '${requiredParam}'`);
|
||||
}
|
||||
}
|
||||
const endpoint = (0, utils_1.evaluateRules)(rules, { endpointParams, logger, referenceRecord: {} });
|
||||
if ((_d = options.endpointParams) === null || _d === void 0 ? void 0 : _d.Endpoint) {
|
||||
try {
|
||||
const givenEndpoint = new URL(options.endpointParams.Endpoint);
|
||||
const { protocol, port } = givenEndpoint;
|
||||
endpoint.url.protocol = protocol;
|
||||
endpoint.url.port = port;
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
}
|
||||
(_f = (_e = options.logger) === null || _e === void 0 ? void 0 : _e.debug) === null || _f === void 0 ? void 0 : _f.call(_e, `${debug_1.debugId} Resolved endpoint: ${(0, debug_1.toDebugString)(endpoint)}`);
|
||||
return endpoint;
|
||||
};
|
||||
exports.resolveEndpoint = resolveEndpoint;
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.EndpointError = void 0;
|
||||
class EndpointError extends Error {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = "EndpointError";
|
||||
}
|
||||
}
|
||||
exports.EndpointError = EndpointError;
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const tslib_1 = require("tslib");
|
||||
tslib_1.__exportStar(require("./EndpointError"), exports);
|
||||
tslib_1.__exportStar(require("./EndpointFunctions"), exports);
|
||||
tslib_1.__exportStar(require("./EndpointRuleObject"), exports);
|
||||
tslib_1.__exportStar(require("./ErrorRuleObject"), exports);
|
||||
tslib_1.__exportStar(require("./RuleSetObject"), exports);
|
||||
tslib_1.__exportStar(require("./TreeRuleObject"), exports);
|
||||
tslib_1.__exportStar(require("./shared"), exports);
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.callFunction = void 0;
|
||||
const customEndpointFunctions_1 = require("./customEndpointFunctions");
|
||||
const endpointFunctions_1 = require("./endpointFunctions");
|
||||
const evaluateExpression_1 = require("./evaluateExpression");
|
||||
const callFunction = ({ fn, argv }, options) => {
|
||||
const evaluatedArgs = argv.map((arg) => ["boolean", "number"].includes(typeof arg) ? arg : (0, evaluateExpression_1.evaluateExpression)(arg, "arg", options));
|
||||
const fnSegments = fn.split(".");
|
||||
if (fnSegments[0] in customEndpointFunctions_1.customEndpointFunctions && fnSegments[1] != null) {
|
||||
return customEndpointFunctions_1.customEndpointFunctions[fnSegments[0]][fnSegments[1]](...evaluatedArgs);
|
||||
}
|
||||
return endpointFunctions_1.endpointFunctions[fn](...evaluatedArgs);
|
||||
};
|
||||
exports.callFunction = callFunction;
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.customEndpointFunctions = void 0;
|
||||
exports.customEndpointFunctions = {};
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.endpointFunctions = void 0;
|
||||
const lib_1 = require("../lib");
|
||||
exports.endpointFunctions = {
|
||||
booleanEquals: lib_1.booleanEquals,
|
||||
getAttr: lib_1.getAttr,
|
||||
isSet: lib_1.isSet,
|
||||
isValidHostLabel: lib_1.isValidHostLabel,
|
||||
not: lib_1.not,
|
||||
parseURL: lib_1.parseURL,
|
||||
stringEquals: lib_1.stringEquals,
|
||||
substring: lib_1.substring,
|
||||
uriEncode: lib_1.uriEncode,
|
||||
};
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.evaluateCondition = void 0;
|
||||
const debug_1 = require("../debug");
|
||||
const types_1 = require("../types");
|
||||
const callFunction_1 = require("./callFunction");
|
||||
const evaluateCondition = ({ assign, ...fnArgs }, options) => {
|
||||
var _a, _b;
|
||||
if (assign && assign in options.referenceRecord) {
|
||||
throw new types_1.EndpointError(`'${assign}' is already defined in Reference Record.`);
|
||||
}
|
||||
const value = (0, callFunction_1.callFunction)(fnArgs, options);
|
||||
(_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)}`);
|
||||
return {
|
||||
result: value === "" ? true : !!value,
|
||||
...(assign != null && { toAssign: { name: assign, value } }),
|
||||
};
|
||||
};
|
||||
exports.evaluateCondition = evaluateCondition;
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.evaluateConditions = void 0;
|
||||
const debug_1 = require("../debug");
|
||||
const evaluateCondition_1 = require("./evaluateCondition");
|
||||
const evaluateConditions = (conditions = [], options) => {
|
||||
var _a, _b;
|
||||
const conditionsReferenceRecord = {};
|
||||
for (const condition of conditions) {
|
||||
const { result, toAssign } = (0, evaluateCondition_1.evaluateCondition)(condition, {
|
||||
...options,
|
||||
referenceRecord: {
|
||||
...options.referenceRecord,
|
||||
...conditionsReferenceRecord,
|
||||
},
|
||||
});
|
||||
if (!result) {
|
||||
return { result };
|
||||
}
|
||||
if (toAssign) {
|
||||
conditionsReferenceRecord[toAssign.name] = toAssign.value;
|
||||
(_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)}`);
|
||||
}
|
||||
}
|
||||
return { result: true, referenceRecord: conditionsReferenceRecord };
|
||||
};
|
||||
exports.evaluateConditions = evaluateConditions;
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.evaluateEndpointRule = void 0;
|
||||
const debug_1 = require("../debug");
|
||||
const evaluateConditions_1 = require("./evaluateConditions");
|
||||
const getEndpointHeaders_1 = require("./getEndpointHeaders");
|
||||
const getEndpointProperties_1 = require("./getEndpointProperties");
|
||||
const getEndpointUrl_1 = require("./getEndpointUrl");
|
||||
const evaluateEndpointRule = (endpointRule, options) => {
|
||||
var _a, _b;
|
||||
const { conditions, endpoint } = endpointRule;
|
||||
const { result, referenceRecord } = (0, evaluateConditions_1.evaluateConditions)(conditions, options);
|
||||
if (!result) {
|
||||
return;
|
||||
}
|
||||
const endpointRuleOptions = {
|
||||
...options,
|
||||
referenceRecord: { ...options.referenceRecord, ...referenceRecord },
|
||||
};
|
||||
const { url, properties, headers } = endpoint;
|
||||
(_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)}`);
|
||||
return {
|
||||
...(headers != undefined && {
|
||||
headers: (0, getEndpointHeaders_1.getEndpointHeaders)(headers, endpointRuleOptions),
|
||||
}),
|
||||
...(properties != undefined && {
|
||||
properties: (0, getEndpointProperties_1.getEndpointProperties)(properties, endpointRuleOptions),
|
||||
}),
|
||||
url: (0, getEndpointUrl_1.getEndpointUrl)(url, endpointRuleOptions),
|
||||
};
|
||||
};
|
||||
exports.evaluateEndpointRule = evaluateEndpointRule;
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.evaluateErrorRule = void 0;
|
||||
const types_1 = require("../types");
|
||||
const evaluateConditions_1 = require("./evaluateConditions");
|
||||
const evaluateExpression_1 = require("./evaluateExpression");
|
||||
const evaluateErrorRule = (errorRule, options) => {
|
||||
const { conditions, error } = errorRule;
|
||||
const { result, referenceRecord } = (0, evaluateConditions_1.evaluateConditions)(conditions, options);
|
||||
if (!result) {
|
||||
return;
|
||||
}
|
||||
throw new types_1.EndpointError((0, evaluateExpression_1.evaluateExpression)(error, "Error", {
|
||||
...options,
|
||||
referenceRecord: { ...options.referenceRecord, ...referenceRecord },
|
||||
}));
|
||||
};
|
||||
exports.evaluateErrorRule = evaluateErrorRule;
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.evaluateExpression = void 0;
|
||||
const types_1 = require("../types");
|
||||
const callFunction_1 = require("./callFunction");
|
||||
const evaluateTemplate_1 = require("./evaluateTemplate");
|
||||
const getReferenceValue_1 = require("./getReferenceValue");
|
||||
const evaluateExpression = (obj, keyName, options) => {
|
||||
if (typeof obj === "string") {
|
||||
return (0, evaluateTemplate_1.evaluateTemplate)(obj, options);
|
||||
}
|
||||
else if (obj["fn"]) {
|
||||
return (0, callFunction_1.callFunction)(obj, options);
|
||||
}
|
||||
else if (obj["ref"]) {
|
||||
return (0, getReferenceValue_1.getReferenceValue)(obj, options);
|
||||
}
|
||||
throw new types_1.EndpointError(`'${keyName}': ${String(obj)} is not a string, function or reference.`);
|
||||
};
|
||||
exports.evaluateExpression = evaluateExpression;
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.evaluateRules = void 0;
|
||||
const types_1 = require("../types");
|
||||
const evaluateEndpointRule_1 = require("./evaluateEndpointRule");
|
||||
const evaluateErrorRule_1 = require("./evaluateErrorRule");
|
||||
const evaluateTreeRule_1 = require("./evaluateTreeRule");
|
||||
const evaluateRules = (rules, options) => {
|
||||
for (const rule of rules) {
|
||||
if (rule.type === "endpoint") {
|
||||
const endpointOrUndefined = (0, evaluateEndpointRule_1.evaluateEndpointRule)(rule, options);
|
||||
if (endpointOrUndefined) {
|
||||
return endpointOrUndefined;
|
||||
}
|
||||
}
|
||||
else if (rule.type === "error") {
|
||||
(0, evaluateErrorRule_1.evaluateErrorRule)(rule, options);
|
||||
}
|
||||
else if (rule.type === "tree") {
|
||||
const endpointOrUndefined = (0, evaluateTreeRule_1.evaluateTreeRule)(rule, options);
|
||||
if (endpointOrUndefined) {
|
||||
return endpointOrUndefined;
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new types_1.EndpointError(`Unknown endpoint rule: ${rule}`);
|
||||
}
|
||||
}
|
||||
throw new types_1.EndpointError(`Rules evaluation failed`);
|
||||
};
|
||||
exports.evaluateRules = evaluateRules;
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.evaluateTemplate = void 0;
|
||||
const lib_1 = require("../lib");
|
||||
const evaluateTemplate = (template, options) => {
|
||||
const evaluatedTemplateArr = [];
|
||||
const templateContext = {
|
||||
...options.endpointParams,
|
||||
...options.referenceRecord,
|
||||
};
|
||||
let currentIndex = 0;
|
||||
while (currentIndex < template.length) {
|
||||
const openingBraceIndex = template.indexOf("{", currentIndex);
|
||||
if (openingBraceIndex === -1) {
|
||||
evaluatedTemplateArr.push(template.slice(currentIndex));
|
||||
break;
|
||||
}
|
||||
evaluatedTemplateArr.push(template.slice(currentIndex, openingBraceIndex));
|
||||
const closingBraceIndex = template.indexOf("}", openingBraceIndex);
|
||||
if (closingBraceIndex === -1) {
|
||||
evaluatedTemplateArr.push(template.slice(openingBraceIndex));
|
||||
break;
|
||||
}
|
||||
if (template[openingBraceIndex + 1] === "{" && template[closingBraceIndex + 1] === "}") {
|
||||
evaluatedTemplateArr.push(template.slice(openingBraceIndex + 1, closingBraceIndex));
|
||||
currentIndex = closingBraceIndex + 2;
|
||||
}
|
||||
const parameterName = template.substring(openingBraceIndex + 1, closingBraceIndex);
|
||||
if (parameterName.includes("#")) {
|
||||
const [refName, attrName] = parameterName.split("#");
|
||||
evaluatedTemplateArr.push((0, lib_1.getAttr)(templateContext[refName], attrName));
|
||||
}
|
||||
else {
|
||||
evaluatedTemplateArr.push(templateContext[parameterName]);
|
||||
}
|
||||
currentIndex = closingBraceIndex + 1;
|
||||
}
|
||||
return evaluatedTemplateArr.join("");
|
||||
};
|
||||
exports.evaluateTemplate = evaluateTemplate;
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.evaluateTreeRule = void 0;
|
||||
const evaluateConditions_1 = require("./evaluateConditions");
|
||||
const evaluateRules_1 = require("./evaluateRules");
|
||||
const evaluateTreeRule = (treeRule, options) => {
|
||||
const { conditions, rules } = treeRule;
|
||||
const { result, referenceRecord } = (0, evaluateConditions_1.evaluateConditions)(conditions, options);
|
||||
if (!result) {
|
||||
return;
|
||||
}
|
||||
return (0, evaluateRules_1.evaluateRules)(rules, {
|
||||
...options,
|
||||
referenceRecord: { ...options.referenceRecord, ...referenceRecord },
|
||||
});
|
||||
};
|
||||
exports.evaluateTreeRule = evaluateTreeRule;
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getEndpointHeaders = void 0;
|
||||
const types_1 = require("../types");
|
||||
const evaluateExpression_1 = require("./evaluateExpression");
|
||||
const getEndpointHeaders = (headers, options) => Object.entries(headers).reduce((acc, [headerKey, headerVal]) => ({
|
||||
...acc,
|
||||
[headerKey]: headerVal.map((headerValEntry) => {
|
||||
const processedExpr = (0, evaluateExpression_1.evaluateExpression)(headerValEntry, "Header value entry", options);
|
||||
if (typeof processedExpr !== "string") {
|
||||
throw new types_1.EndpointError(`Header '${headerKey}' value '${processedExpr}' is not a string`);
|
||||
}
|
||||
return processedExpr;
|
||||
}),
|
||||
}), {});
|
||||
exports.getEndpointHeaders = getEndpointHeaders;
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getEndpointProperties = void 0;
|
||||
const getEndpointProperty_1 = require("./getEndpointProperty");
|
||||
const getEndpointProperties = (properties, options) => Object.entries(properties).reduce((acc, [propertyKey, propertyVal]) => ({
|
||||
...acc,
|
||||
[propertyKey]: (0, getEndpointProperty_1.getEndpointProperty)(propertyVal, options),
|
||||
}), {});
|
||||
exports.getEndpointProperties = getEndpointProperties;
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getEndpointProperty = void 0;
|
||||
const types_1 = require("../types");
|
||||
const evaluateTemplate_1 = require("./evaluateTemplate");
|
||||
const getEndpointProperties_1 = require("./getEndpointProperties");
|
||||
const getEndpointProperty = (property, options) => {
|
||||
if (Array.isArray(property)) {
|
||||
return property.map((propertyEntry) => (0, exports.getEndpointProperty)(propertyEntry, options));
|
||||
}
|
||||
switch (typeof property) {
|
||||
case "string":
|
||||
return (0, evaluateTemplate_1.evaluateTemplate)(property, options);
|
||||
case "object":
|
||||
if (property === null) {
|
||||
throw new types_1.EndpointError(`Unexpected endpoint property: ${property}`);
|
||||
}
|
||||
return (0, getEndpointProperties_1.getEndpointProperties)(property, options);
|
||||
case "boolean":
|
||||
return property;
|
||||
default:
|
||||
throw new types_1.EndpointError(`Unexpected endpoint property type: ${typeof property}`);
|
||||
}
|
||||
};
|
||||
exports.getEndpointProperty = getEndpointProperty;
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getEndpointUrl = void 0;
|
||||
const types_1 = require("../types");
|
||||
const evaluateExpression_1 = require("./evaluateExpression");
|
||||
const getEndpointUrl = (endpointUrl, options) => {
|
||||
const expression = (0, evaluateExpression_1.evaluateExpression)(endpointUrl, "Endpoint URL", options);
|
||||
if (typeof expression === "string") {
|
||||
try {
|
||||
return new URL(expression);
|
||||
}
|
||||
catch (error) {
|
||||
console.error(`Failed to construct URL with ${expression}`, error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
throw new types_1.EndpointError(`Endpoint URL must be a string, got ${typeof expression}`);
|
||||
};
|
||||
exports.getEndpointUrl = getEndpointUrl;
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getReferenceValue = void 0;
|
||||
const getReferenceValue = ({ ref }, options) => {
|
||||
const referenceRecord = {
|
||||
...options.endpointParams,
|
||||
...options.referenceRecord,
|
||||
};
|
||||
return referenceRecord[ref];
|
||||
};
|
||||
exports.getReferenceValue = getReferenceValue;
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const tslib_1 = require("tslib");
|
||||
tslib_1.__exportStar(require("./customEndpointFunctions"), exports);
|
||||
tslib_1.__exportStar(require("./evaluateRules"), exports);
|
||||
Reference in New Issue
Block a user