Socket
Socket
Sign inDemoInstall

@aws-sdk/util-endpoints

Package Overview
Dependencies
Maintainers
5
Versions
114
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aws-sdk/util-endpoints - npm Package Compare versions

Comparing version 3.182.0 to 3.183.0

8

CHANGELOG.md

@@ -6,2 +6,10 @@ # Change Log

# [3.183.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.182.0...v3.183.0) (2022-10-03)
**Note:** Version bump only for package @aws-sdk/util-endpoints
# [3.182.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.181.0...v3.182.0) (2022-09-30)

@@ -8,0 +16,0 @@

21

dist-es/lib/aws/isVirtualHostableS3Bucket.js

@@ -1,23 +0,10 @@

import { __values } from "tslib";
import { isIpAddress } from "../isIpAddress";
import { isValidHostLabel } from "../isValidHostLabel";
export var isVirtualHostableS3Bucket = function (value, allowSubDomains) {
var e_1, _a;
if (allowSubDomains === void 0) { allowSubDomains = false; }
export const isVirtualHostableS3Bucket = (value, allowSubDomains = false) => {
if (allowSubDomains) {
try {
for (var _b = __values(value.split(".")), _c = _b.next(); !_c.done; _c = _b.next()) {
var label = _c.value;
if (!isVirtualHostableS3Bucket(label)) {
return false;
}
for (const label of value.split(".")) {
if (!isVirtualHostableS3Bucket(label)) {
return false;
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
return true;

@@ -24,0 +11,0 @@ }

@@ -1,16 +0,15 @@

import { __read } from "tslib";
export var parseArn = function (value) {
var segments = value.split(":");
export const parseArn = (value) => {
const segments = value.split(":");
if (segments.length < 6)
return null;
var _a = __read(segments), arn = _a[0], partition = _a[1], service = _a[2], region = _a[3], accountId = _a[4], resourceId = _a.slice(5);
const [arn, partition, service, region, accountId, ...resourceId] = segments;
if (arn !== "arn" || partition === "" || service === "" || resourceId[0] === "")
return null;
return {
partition: partition,
service: service,
region: region,
accountId: accountId,
partition,
service,
region,
accountId,
resourceId: resourceId[0].includes("/") ? resourceId[0].split("/") : resourceId,
};
};

@@ -1,50 +0,25 @@

import { __assign, __read, __values } from "tslib";
import { partitions } from "./partitions.json";
var DEFAULT_PARTITION = partitions.find(function (partition) { return partition.id === "aws"; });
export var partition = function (value) {
var e_1, _a, e_2, _b, e_3, _c;
try {
for (var partitions_1 = __values(partitions), partitions_1_1 = partitions_1.next(); !partitions_1_1.done; partitions_1_1 = partitions_1.next()) {
var partition_1 = partitions_1_1.value;
var id = partition_1.id, regions = partition_1.regions, outputs = partition_1.outputs;
try {
for (var _d = (e_2 = void 0, __values(Object.entries(regions))), _e = _d.next(); !_e.done; _e = _d.next()) {
var _f = __read(_e.value, 2), region = _f[0], regionData = _f[1];
if (region === value) {
return __assign(__assign({ name: id }, outputs), regionData);
}
}
const DEFAULT_PARTITION = partitions.find((partition) => partition.id === "aws");
export const partition = (value) => {
for (const partition of partitions) {
const { id, regions, outputs } = partition;
for (const [region, regionData] of Object.entries(regions)) {
if (region === value) {
return {
name: id,
...outputs,
...regionData,
};
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
}
finally { if (e_2) throw e_2.error; }
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (partitions_1_1 && !partitions_1_1.done && (_a = partitions_1.return)) _a.call(partitions_1);
for (const partition of partitions) {
const { id, regionRegex, outputs } = partition;
if (new RegExp(regionRegex).test(value)) {
return {
name: id,
...outputs,
};
}
finally { if (e_1) throw e_1.error; }
}
try {
for (var partitions_2 = __values(partitions), partitions_2_1 = partitions_2.next(); !partitions_2_1.done; partitions_2_1 = partitions_2.next()) {
var partition_2 = partitions_2_1.value;
var id = partition_2.id, regionRegex = partition_2.regionRegex, outputs = partition_2.outputs;
if (new RegExp(regionRegex).test(value)) {
return __assign({ name: id }, outputs);
}
}
}
catch (e_3_1) { e_3 = { error: e_3_1 }; }
finally {
try {
if (partitions_2_1 && !partitions_2_1.done && (_c = partitions_2.return)) _c.call(partitions_2);
}
finally { if (e_3) throw e_3.error; }
}
if (!DEFAULT_PARTITION) {

@@ -54,3 +29,6 @@ throw new Error("Provided region was not found in the partition array or regex," +

}
return __assign({ name: DEFAULT_PARTITION.id }, DEFAULT_PARTITION.outputs);
return {
name: DEFAULT_PARTITION.id,
...DEFAULT_PARTITION.outputs,
};
};

@@ -1,1 +0,1 @@

export var booleanEquals = function (value1, value2) { return value1 === value2; };
export const booleanEquals = (value1, value2) => value1 === value2;
import { EndpointError } from "../types";
import { getAttrPathList } from "./getAttrPathList";
export var getAttr = function (value, path) {
return getAttrPathList(path).reduce(function (acc, index) {
if (typeof acc !== "object") {
throw new EndpointError("Index '".concat(index, "' in '").concat(path, "' not found in '").concat(JSON.stringify(value), "'"));
}
else if (Array.isArray(acc)) {
return acc[parseInt(index)];
}
return acc[index];
}, value);
};
export const getAttr = (value, path) => getAttrPathList(path).reduce((acc, index) => {
if (typeof acc !== "object") {
throw new EndpointError(`Index '${index}' in '${path}' not found in '${JSON.stringify(value)}'`);
}
else if (Array.isArray(acc)) {
return acc[parseInt(index)];
}
return acc[index];
}, value);

@@ -1,37 +0,25 @@

import { __values } from "tslib";
import { EndpointError } from "../types";
export var getAttrPathList = function (path) {
var e_1, _a;
var parts = path.split(".");
var pathList = [];
try {
for (var parts_1 = __values(parts), parts_1_1 = parts_1.next(); !parts_1_1.done; parts_1_1 = parts_1.next()) {
var part = parts_1_1.value;
var squareBracketIndex = part.indexOf("[");
if (squareBracketIndex !== -1) {
if (part.indexOf("]") !== part.length - 1) {
throw new EndpointError("Path: '".concat(path, "' does not end with ']'"));
}
var arrayIndex = part.slice(squareBracketIndex + 1, -1);
if (Number.isNaN(parseInt(arrayIndex))) {
throw new EndpointError("Invalid array index: '".concat(arrayIndex, "' in path: '").concat(path, "'"));
}
if (squareBracketIndex !== 0) {
pathList.push(part.slice(0, squareBracketIndex));
}
pathList.push(arrayIndex);
export 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 EndpointError(`Path: '${path}' does not end with ']'`);
}
else {
pathList.push(part);
const arrayIndex = part.slice(squareBracketIndex + 1, -1);
if (Number.isNaN(parseInt(arrayIndex))) {
throw new EndpointError(`Invalid array index: '${arrayIndex}' in path: '${path}'`);
}
if (squareBracketIndex !== 0) {
pathList.push(part.slice(0, squareBracketIndex));
}
pathList.push(arrayIndex);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (parts_1_1 && !parts_1_1.done && (_a = parts_1.return)) _a.call(parts_1);
else {
pathList.push(part);
}
finally { if (e_1) throw e_1.error; }
}
return pathList;
};

@@ -1,4 +0,2 @@

var IP_V4_REGEX = new RegExp("^(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}$");
export var isIpAddress = function (value) {
return IP_V4_REGEX.test(value) || (value.startsWith("[") && value.endsWith("]"));
};
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}$`);
export const isIpAddress = (value) => IP_V4_REGEX.test(value) || (value.startsWith("[") && value.endsWith("]"));

@@ -1,1 +0,1 @@

export var isSet = function (value) { return value != null; };
export const isSet = (value) => value != null;

@@ -1,26 +0,13 @@

import { __values } from "tslib";
var VALID_HOST_LABEL_REGEX = new RegExp("^(?!.*-$)(?!-)[a-zA-Z0-9-]{1,63}$");
export var isValidHostLabel = function (value, allowSubDomains) {
var e_1, _a;
if (allowSubDomains === void 0) { allowSubDomains = false; }
const VALID_HOST_LABEL_REGEX = new RegExp(`^(?!.*-$)(?!-)[a-zA-Z0-9-]{1,63}$`);
export const isValidHostLabel = (value, allowSubDomains = false) => {
if (!allowSubDomains) {
return VALID_HOST_LABEL_REGEX.test(value);
}
var labels = value.split(".");
try {
for (var labels_1 = __values(labels), labels_1_1 = labels_1.next(); !labels_1_1.done; labels_1_1 = labels_1.next()) {
var label = labels_1_1.value;
if (!isValidHostLabel(label)) {
return false;
}
const labels = value.split(".");
for (const label of labels) {
if (!isValidHostLabel(label)) {
return false;
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (labels_1_1 && !labels_1_1.done && (_a = labels_1.return)) _a.call(labels_1);
}
finally { if (e_1) throw e_1.error; }
}
return true;
};

@@ -1,1 +0,1 @@

export var not = function (value) { return !value; };
export const not = (value) => !value;

@@ -1,10 +0,9 @@

var _a;
import { EndpointURLScheme } from "@aws-sdk/types";
import { isIpAddress } from "./isIpAddress";
var DEFAULT_PORTS = (_a = {},
_a[EndpointURLScheme.HTTP] = 80,
_a[EndpointURLScheme.HTTPS] = 443,
_a);
export var parseURL = function (value) {
var whatwgURL = (function () {
const DEFAULT_PORTS = {
[EndpointURLScheme.HTTP]: 80,
[EndpointURLScheme.HTTPS]: 443,
};
export const parseURL = (value) => {
const whatwgURL = (() => {
try {

@@ -20,19 +19,19 @@ return new URL(value);

}
var host = whatwgURL.host, hostname = whatwgURL.hostname, pathname = whatwgURL.pathname, protocol = whatwgURL.protocol, search = whatwgURL.search;
const { host, hostname, pathname, protocol, search } = whatwgURL;
if (search) {
return null;
}
var scheme = protocol.slice(0, -1);
const scheme = protocol.slice(0, -1);
if (!Object.values(EndpointURLScheme).includes(scheme)) {
return null;
}
var isIp = isIpAddress(hostname);
var authority = "".concat(host).concat(value.includes("".concat(host, ":").concat(DEFAULT_PORTS[scheme])) ? ":".concat(DEFAULT_PORTS[scheme]) : "");
const isIp = isIpAddress(hostname);
const authority = `${host}${value.includes(`${host}:${DEFAULT_PORTS[scheme]}`) ? `:${DEFAULT_PORTS[scheme]}` : ``}`;
return {
scheme: scheme,
authority: authority,
scheme,
authority,
path: pathname,
normalizedPath: pathname.endsWith("/") ? pathname : "".concat(pathname, "/"),
isIp: isIp,
normalizedPath: pathname.endsWith("/") ? pathname : `${pathname}/`,
isIp,
};
};

@@ -1,1 +0,1 @@

export var stringEquals = function (value1, value2) { return value1 === value2; };
export const stringEquals = (value1, value2) => value1 === value2;

@@ -1,2 +0,2 @@

export var substring = function (input, start, stop, reverse) {
export const substring = (input, start, stop, reverse) => {
if (start >= stop || input.length < stop) {

@@ -3,0 +3,0 @@ return null;

@@ -1,3 +0,1 @@

export var uriEncode = function (value) {
return encodeURIComponent(value).replace(/[!*'()]/g, function (c) { return "%".concat(c.charCodeAt(0).toString(16).toUpperCase()); });
};
export const uriEncode = (value) => encodeURIComponent(value).replace(/[!*'()]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`);

@@ -1,58 +0,23 @@

import { __read, __values } from "tslib";
import { EndpointError } from "./types";
import { evaluateRules } from "./utils";
export var resolveEndpoint = function (ruleSetObject, options) {
var e_1, _a, e_2, _b;
var _c;
var endpointParams = options.endpointParams, logger = options.logger;
var parameters = ruleSetObject.parameters, rules = ruleSetObject.rules;
var paramsWithDefault = Object.entries(parameters)
.filter(function (_a) {
var _b = __read(_a, 2), v = _b[1];
return v.default != null;
})
.map(function (_a) {
var _b = __read(_a, 2), k = _b[0], v = _b[1];
return [k, v.default];
});
export const resolveEndpoint = (ruleSetObject, options) => {
const { endpointParams, logger } = options;
const { parameters, rules } = ruleSetObject;
const paramsWithDefault = Object.entries(parameters)
.filter(([, v]) => v.default != null)
.map(([k, v]) => [k, v.default]);
if (paramsWithDefault.length > 0) {
try {
for (var paramsWithDefault_1 = __values(paramsWithDefault), paramsWithDefault_1_1 = paramsWithDefault_1.next(); !paramsWithDefault_1_1.done; paramsWithDefault_1_1 = paramsWithDefault_1.next()) {
var _d = __read(paramsWithDefault_1_1.value, 2), paramKey = _d[0], paramDefaultValue = _d[1];
endpointParams[paramKey] = (_c = endpointParams[paramKey]) !== null && _c !== void 0 ? _c : paramDefaultValue;
}
for (const [paramKey, paramDefaultValue] of paramsWithDefault) {
endpointParams[paramKey] = endpointParams[paramKey] ?? paramDefaultValue;
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (paramsWithDefault_1_1 && !paramsWithDefault_1_1.done && (_a = paramsWithDefault_1.return)) _a.call(paramsWithDefault_1);
}
finally { if (e_1) throw e_1.error; }
}
}
var requiredParams = Object.entries(parameters)
.filter(function (_a) {
var _b = __read(_a, 2), v = _b[1];
return v.required;
})
.map(function (_a) {
var _b = __read(_a, 1), k = _b[0];
return k;
});
try {
for (var requiredParams_1 = __values(requiredParams), requiredParams_1_1 = requiredParams_1.next(); !requiredParams_1_1.done; requiredParams_1_1 = requiredParams_1.next()) {
var requiredParam = requiredParams_1_1.value;
if (endpointParams[requiredParam] == null) {
throw new EndpointError("Missing required parameter: '".concat(requiredParam, "'"));
}
const requiredParams = Object.entries(parameters)
.filter(([, v]) => v.required)
.map(([k]) => k);
for (const requiredParam of requiredParams) {
if (endpointParams[requiredParam] == null) {
throw new EndpointError(`Missing required parameter: '${requiredParam}'`);
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (requiredParams_1_1 && !requiredParams_1_1.done && (_b = requiredParams_1.return)) _b.call(requiredParams_1);
}
finally { if (e_2) throw e_2.error; }
}
return evaluateRules(rules, { endpointParams: endpointParams, logger: logger, referenceRecord: {} });
return evaluateRules(rules, { endpointParams, logger, referenceRecord: {} });
};

@@ -1,11 +0,6 @@

import { __extends } from "tslib";
var EndpointError = (function (_super) {
__extends(EndpointError, _super);
function EndpointError(message) {
var _this = _super.call(this, message) || this;
_this.name = "EndpointError";
return _this;
export class EndpointError extends Error {
constructor(message) {
super(message);
this.name = "EndpointError";
}
return EndpointError;
}(Error));
export { EndpointError };
}

@@ -1,10 +0,6 @@

import { __read, __spreadArray } from "tslib";
import * as lib from "../lib";
import { evaluateExpression } from "./evaluateExpression";
export var callFunction = function (_a, options) {
var fn = _a.fn, argv = _a.argv;
var evaluatedArgs = argv.map(function (arg) {
return ["boolean", "number"].includes(typeof arg) ? arg : evaluateExpression(arg, "arg", options);
});
return fn.split(".").reduce(function (acc, key) { return acc[key]; }, lib).apply(void 0, __spreadArray([], __read(evaluatedArgs), false));
export const callFunction = ({ fn, argv }, options) => {
const evaluatedArgs = argv.map((arg) => ["boolean", "number"].includes(typeof arg) ? arg : evaluateExpression(arg, "arg", options));
return fn.split(".").reduce((acc, key) => acc[key], lib)(...evaluatedArgs);
};

@@ -1,11 +0,12 @@

import { __assign, __rest } from "tslib";
import { EndpointError } from "../types";
import { callFunction } from "./callFunction";
export var evaluateCondition = function (_a, options) {
var assign = _a.assign, fnArgs = __rest(_a, ["assign"]);
export const evaluateCondition = ({ assign, ...fnArgs }, options) => {
if (assign && assign in options.referenceRecord) {
throw new EndpointError("'".concat(assign, "' is already defined in Reference Record."));
throw new EndpointError(`'${assign}' is already defined in Reference Record.`);
}
var value = callFunction(fnArgs, options);
return __assign({ result: value === "" ? true : !!value }, (assign != null && { toAssign: { name: assign, value: value } }));
const value = callFunction(fnArgs, options);
return {
result: value === "" ? true : !!value,
...(assign != null && { toAssign: { name: assign, value } }),
};
};

@@ -1,27 +0,20 @@

import { __assign, __values } from "tslib";
import { evaluateCondition } from "./evaluateCondition";
export var evaluateConditions = function (conditions, options) {
var e_1, _a;
if (conditions === void 0) { conditions = []; }
var conditionsReferenceRecord = {};
try {
for (var conditions_1 = __values(conditions), conditions_1_1 = conditions_1.next(); !conditions_1_1.done; conditions_1_1 = conditions_1.next()) {
var condition = conditions_1_1.value;
var _b = evaluateCondition(condition, __assign(__assign({}, options), { referenceRecord: __assign(__assign({}, options.referenceRecord), conditionsReferenceRecord) })), result = _b.result, toAssign = _b.toAssign;
if (!result) {
return { result: result };
}
if (toAssign) {
conditionsReferenceRecord[toAssign.name] = toAssign.value;
}
export const evaluateConditions = (conditions = [], options) => {
const conditionsReferenceRecord = {};
for (const condition of conditions) {
const { result, toAssign } = evaluateCondition(condition, {
...options,
referenceRecord: {
...options.referenceRecord,
...conditionsReferenceRecord,
},
});
if (!result) {
return { result };
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (conditions_1_1 && !conditions_1_1.done && (_a = conditions_1.return)) _a.call(conditions_1);
if (toAssign) {
conditionsReferenceRecord[toAssign.name] = toAssign.value;
}
finally { if (e_1) throw e_1.error; }
}
return { result: true, referenceRecord: conditionsReferenceRecord };
};

@@ -1,2 +0,1 @@

import { __assign } from "tslib";
import { evaluateConditions } from "./evaluateConditions";

@@ -6,15 +5,22 @@ import { getEndpointHeaders } from "./getEndpointHeaders";

import { getEndpointUrl } from "./getEndpointUrl";
export var evaluateEndpointRule = function (endpointRule, options) {
var conditions = endpointRule.conditions, endpoint = endpointRule.endpoint;
var _a = evaluateConditions(conditions, options), result = _a.result, referenceRecord = _a.referenceRecord;
export const evaluateEndpointRule = (endpointRule, options) => {
const { conditions, endpoint } = endpointRule;
const { result, referenceRecord } = evaluateConditions(conditions, options);
if (!result) {
return;
}
var endpointRuleOptions = __assign(__assign({}, options), { referenceRecord: __assign(__assign({}, options.referenceRecord), referenceRecord) });
var url = endpoint.url, properties = endpoint.properties, headers = endpoint.headers;
return __assign(__assign(__assign({}, (headers != undefined && {
headers: getEndpointHeaders(headers, endpointRuleOptions),
})), (properties != undefined && {
properties: getEndpointProperties(properties, endpointRuleOptions),
})), { url: getEndpointUrl(url, endpointRuleOptions) });
const endpointRuleOptions = {
...options,
referenceRecord: { ...options.referenceRecord, ...referenceRecord },
};
const { url, properties, headers } = endpoint;
return {
...(headers != undefined && {
headers: getEndpointHeaders(headers, endpointRuleOptions),
}),
...(properties != undefined && {
properties: getEndpointProperties(properties, endpointRuleOptions),
}),
url: getEndpointUrl(url, endpointRuleOptions),
};
};

@@ -1,12 +0,14 @@

import { __assign } from "tslib";
import { EndpointError } from "../types";
import { evaluateConditions } from "./evaluateConditions";
import { evaluateExpression } from "./evaluateExpression";
export var evaluateErrorRule = function (errorRule, options) {
var conditions = errorRule.conditions, error = errorRule.error;
var _a = evaluateConditions(conditions, options), result = _a.result, referenceRecord = _a.referenceRecord;
export const evaluateErrorRule = (errorRule, options) => {
const { conditions, error } = errorRule;
const { result, referenceRecord } = evaluateConditions(conditions, options);
if (!result) {
return;
}
throw new EndpointError(evaluateExpression(error, "Error", __assign(__assign({}, options), { referenceRecord: __assign(__assign({}, options.referenceRecord), referenceRecord) })));
throw new EndpointError(evaluateExpression(error, "Error", {
...options,
referenceRecord: { ...options.referenceRecord, ...referenceRecord },
}));
};

@@ -5,3 +5,3 @@ import { EndpointError } from "../types";

import { getReferenceValue } from "./getReferenceValue";
export var evaluateExpression = function (obj, keyName, options) {
export const evaluateExpression = (obj, keyName, options) => {
if (typeof obj === "string") {

@@ -16,3 +16,3 @@ return evaluateTemplate(obj, options);

}
throw new EndpointError("'".concat(keyName, "': ").concat(String(obj), " is not a string, function or reference."));
throw new EndpointError(`'${keyName}': ${String(obj)} is not a string, function or reference.`);
};

@@ -1,2 +0,1 @@

import { __values } from "tslib";
import { EndpointError } from "../types";

@@ -6,35 +5,24 @@ import { evaluateEndpointRule } from "./evaluateEndpointRule";

import { evaluateTreeRule } from "./evaluateTreeRule";
export var evaluateRules = function (rules, options) {
var e_1, _a;
try {
for (var rules_1 = __values(rules), rules_1_1 = rules_1.next(); !rules_1_1.done; rules_1_1 = rules_1.next()) {
var rule = rules_1_1.value;
if (rule.type === "endpoint") {
var endpointOrUndefined = evaluateEndpointRule(rule, options);
if (endpointOrUndefined) {
return endpointOrUndefined;
}
export const evaluateRules = (rules, options) => {
for (const rule of rules) {
if (rule.type === "endpoint") {
const endpointOrUndefined = evaluateEndpointRule(rule, options);
if (endpointOrUndefined) {
return endpointOrUndefined;
}
else if (rule.type === "error") {
evaluateErrorRule(rule, options);
}
else if (rule.type === "error") {
evaluateErrorRule(rule, options);
}
else if (rule.type === "tree") {
const endpointOrUndefined = evaluateTreeRule(rule, options);
if (endpointOrUndefined) {
return endpointOrUndefined;
}
else if (rule.type === "tree") {
var endpointOrUndefined = evaluateTreeRule(rule, options);
if (endpointOrUndefined) {
return endpointOrUndefined;
}
}
else {
throw new EndpointError("Unknown endpoint rule: ".concat(rule));
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (rules_1_1 && !rules_1_1.done && (_a = rules_1.return)) _a.call(rules_1);
else {
throw new EndpointError(`Unknown endpoint rule: ${rule}`);
}
finally { if (e_1) throw e_1.error; }
}
throw new EndpointError("Rules evaluation failed");
throw new EndpointError(`Rules evaluation failed`);
};

@@ -1,25 +0,24 @@

import { __assign, __read, __spreadArray } from "tslib";
import { getAttr } from "../lib";
var ATTR_SHORTHAND_REGEX = new RegExp("\\${([\\w]+)#([\\w]+)}", "g");
export var evaluateTemplate = function (template, options) {
var templateToEvaluate = template
.replace(new RegExp("{([^{}]+)}", "g"), "${$1}")
.replace(new RegExp("{\\${([^{}]+)}}", "g"), "{$1}");
var templateContext = __assign(__assign({}, options.endpointParams), options.referenceRecord);
var attrShortHandList = templateToEvaluate.match(ATTR_SHORTHAND_REGEX) || [];
var attrShortHandMap = attrShortHandList.reduce(function (acc, attrShortHand) {
var indexOfHash = attrShortHand.indexOf("#");
var refName = attrShortHand.substring(2, indexOfHash);
var attrName = attrShortHand.substring(indexOfHash + 1, attrShortHand.length - 1);
const ATTR_SHORTHAND_REGEX = new RegExp("\\${([\\w]+)#([\\w]+)}", "g");
export const evaluateTemplate = (template, options) => {
const templateToEvaluate = template
.replace(new RegExp(`\{([^{}]+)\}`, "g"), "${$1}")
.replace(new RegExp(`\{\\$\{([^{}]+)\}\}`, "g"), "{$1}");
const templateContext = {
...options.endpointParams,
...options.referenceRecord,
};
const attrShortHandList = templateToEvaluate.match(ATTR_SHORTHAND_REGEX) || [];
const attrShortHandMap = attrShortHandList.reduce((acc, attrShortHand) => {
const indexOfHash = attrShortHand.indexOf("#");
const refName = attrShortHand.substring(2, indexOfHash);
const attrName = attrShortHand.substring(indexOfHash + 1, attrShortHand.length - 1);
acc[attrShortHand] = getAttr(templateContext[refName], attrName);
return acc;
}, {});
var templateWithAttr = Object.entries(attrShortHandMap).reduce(function (acc, _a) {
var _b = __read(_a, 2), shortHand = _b[0], value = _b[1];
return acc.replace(shortHand, value);
}, templateToEvaluate);
var templateContextNames = Object.keys(templateContext);
var templateContextValues = Object.values(templateContext);
var templateWithTildeEscaped = templateWithAttr.replace(/\`/g, "\\`");
return new (Function.bind.apply(Function, __spreadArray(__spreadArray([void 0], __read(templateContextNames), false), ["return `".concat(templateWithTildeEscaped, "`")], false)))().apply(void 0, __spreadArray([], __read(templateContextValues), false));
const templateWithAttr = Object.entries(attrShortHandMap).reduce((acc, [shortHand, value]) => acc.replace(shortHand, value), templateToEvaluate);
const templateContextNames = Object.keys(templateContext);
const templateContextValues = Object.values(templateContext);
const templateWithTildeEscaped = templateWithAttr.replace(/\`/g, "\\`");
return new Function(...templateContextNames, `return \`${templateWithTildeEscaped}\``)(...templateContextValues);
};

@@ -1,11 +0,13 @@

import { __assign } from "tslib";
import { evaluateConditions } from "./evaluateConditions";
import { evaluateRules } from "./evaluateRules";
export var evaluateTreeRule = function (treeRule, options) {
var conditions = treeRule.conditions, rules = treeRule.rules;
var _a = evaluateConditions(conditions, options), result = _a.result, referenceRecord = _a.referenceRecord;
export const evaluateTreeRule = (treeRule, options) => {
const { conditions, rules } = treeRule;
const { result, referenceRecord } = evaluateConditions(conditions, options);
if (!result) {
return;
}
return evaluateRules(rules, __assign(__assign({}, options), { referenceRecord: __assign(__assign({}, options.referenceRecord), referenceRecord) }));
return evaluateRules(rules, {
...options,
referenceRecord: { ...options.referenceRecord, ...referenceRecord },
});
};

@@ -1,16 +0,12 @@

import { __assign, __read } from "tslib";
import { EndpointError } from "../types";
import { evaluateExpression } from "./evaluateExpression";
export var getEndpointHeaders = function (headers, options) {
return Object.entries(headers).reduce(function (acc, _a) {
var _b;
var _c = __read(_a, 2), headerKey = _c[0], headerVal = _c[1];
return (__assign(__assign({}, acc), (_b = {}, _b[headerKey] = headerVal.map(function (headerValEntry) {
var processedExpr = evaluateExpression(headerValEntry, "Header value entry", options);
if (typeof processedExpr !== "string") {
throw new EndpointError("Header '".concat(headerKey, "' value '").concat(processedExpr, "' is not a string"));
}
return processedExpr;
}), _b)));
}, {});
};
export const getEndpointHeaders = (headers, options) => Object.entries(headers).reduce((acc, [headerKey, headerVal]) => ({
...acc,
[headerKey]: headerVal.map((headerValEntry) => {
const processedExpr = evaluateExpression(headerValEntry, "Header value entry", options);
if (typeof processedExpr !== "string") {
throw new EndpointError(`Header '${headerKey}' value '${processedExpr}' is not a string`);
}
return processedExpr;
}),
}), {});

@@ -1,9 +0,5 @@

import { __assign, __read } from "tslib";
import { getEndpointProperty } from "./getEndpointProperty";
export var getEndpointProperties = function (properties, options) {
return Object.entries(properties).reduce(function (acc, _a) {
var _b;
var _c = __read(_a, 2), propertyKey = _c[0], propertyVal = _c[1];
return (__assign(__assign({}, acc), (_b = {}, _b[propertyKey] = getEndpointProperty(propertyVal, options), _b)));
}, {});
};
export const getEndpointProperties = (properties, options) => Object.entries(properties).reduce((acc, [propertyKey, propertyVal]) => ({
...acc,
[propertyKey]: getEndpointProperty(propertyVal, options),
}), {});
import { EndpointError } from "../types";
import { evaluateTemplate } from "./evaluateTemplate";
import { getEndpointProperties } from "./getEndpointProperties";
export var getEndpointProperty = function (property, options) {
export const getEndpointProperty = (property, options) => {
if (Array.isArray(property)) {
return property.map(function (propertyEntry) { return getEndpointProperty(propertyEntry, options); });
return property.map((propertyEntry) => getEndpointProperty(propertyEntry, options));
}

@@ -13,3 +13,3 @@ switch (typeof property) {

if (property === null) {
throw new EndpointError("Unexpected endpoint property: ".concat(property));
throw new EndpointError(`Unexpected endpoint property: ${property}`);
}

@@ -20,4 +20,4 @@ return getEndpointProperties(property, options);

default:
throw new EndpointError("Unexpected endpoint property type: ".concat(typeof property));
throw new EndpointError(`Unexpected endpoint property type: ${typeof property}`);
}
};
import { EndpointError } from "../types";
import { evaluateExpression } from "./evaluateExpression";
export var getEndpointUrl = function (endpointUrl, options) {
var expression = evaluateExpression(endpointUrl, "Endpoint URL", options);
export const getEndpointUrl = (endpointUrl, options) => {
const expression = evaluateExpression(endpointUrl, "Endpoint URL", options);
if (typeof expression === "string") {

@@ -10,7 +10,7 @@ try {

catch (error) {
console.error("Failed to construct URL with ".concat(expression), error);
console.error(`Failed to construct URL with ${expression}`, error);
throw error;
}
}
throw new EndpointError("Endpoint URL must be a string, got ".concat(typeof expression));
throw new EndpointError(`Endpoint URL must be a string, got ${typeof expression}`);
};

@@ -1,6 +0,7 @@

import { __assign } from "tslib";
export var getReferenceValue = function (_a, options) {
var ref = _a.ref;
var referenceRecord = __assign(__assign({}, options.endpointParams), options.referenceRecord);
export const getReferenceValue = ({ ref }, options) => {
const referenceRecord = {
...options.endpointParams,
...options.referenceRecord,
};
return referenceRecord[ref];
};
{
"name": "@aws-sdk/util-endpoints",
"version": "3.182.0",
"version": "3.183.0",
"description": "Utilities to help with endpoint resolution",

@@ -24,3 +24,3 @@ "main": "./dist-cjs/index.js",

"dependencies": {
"@aws-sdk/types": "3.178.0",
"@aws-sdk/types": "3.183.0",
"tslib": "^2.3.1"

@@ -27,0 +27,0 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc