🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@smithy/util-endpoints

Package Overview
Dependencies
Maintainers
3
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@smithy/util-endpoints - npm Package Compare versions

Comparing version
3.4.1
to
3.4.2
+65
-53
dist-cjs/index.js

@@ -321,13 +321,15 @@ 'use strict';

}
if (fn.includes(".")) {
const fnSegments = fn.split(".");
if (fnSegments[0] in customEndpointFunctions && fnSegments[1] != null) {
return customEndpointFunctions[fnSegments[0]][fnSegments[1]](...evaluatedArgs);
const namespaceSeparatorIndex = fn.indexOf(".");
if (namespaceSeparatorIndex !== -1) {
const namespaceFunctions = customEndpointFunctions[fn.slice(0, namespaceSeparatorIndex)];
const customFunction = namespaceFunctions?.[fn.slice(namespaceSeparatorIndex + 1)];
if (typeof customFunction === "function") {
return customFunction(...evaluatedArgs);
}
}
if (typeof endpointFunctions[fn] !== "function") {
throw new Error(`function ${fn} not loaded in endpointFunctions.`);
const callable = endpointFunctions[fn];
if (typeof callable === "function") {
return callable(...evaluatedArgs);
}
const callable = endpointFunctions[fn];
return callable(...evaluatedArgs);
throw new Error(`function ${fn} not loaded in endpointFunctions.`);
};

@@ -339,17 +341,18 @@ const group$2 = {

const evaluateCondition = ({ assign, ...fnArgs }, options) => {
const evaluateCondition = (condition, options) => {
const { assign } = condition;
if (assign && assign in options.referenceRecord) {
throw new EndpointError(`'${assign}' is already defined in Reference Record.`);
}
const value = callFunction(fnArgs, options);
options.logger?.debug?.(`${debugId} evaluateCondition: ${toDebugString(fnArgs)} = ${toDebugString(value)}`);
return {
result: value === "" ? true : !!value,
...(assign != null && { toAssign: { name: assign, value } }),
};
const value = callFunction(condition, options);
options.logger?.debug?.(`${debugId} evaluateCondition: ${toDebugString(condition)} = ${toDebugString(value)}`);
const result = value === "" ? true : !!value;
if (assign != null) {
return { result, toAssign: { name: assign, value } };
}
return { result };
};
const getEndpointHeaders = (headers, options) => Object.entries(headers ?? {}).reduce((acc, [headerKey, headerVal]) => ({
...acc,
[headerKey]: headerVal.map((headerValEntry) => {
const getEndpointHeaders = (headers, options) => Object.entries(headers ?? {}).reduce((acc, [headerKey, headerVal]) => {
acc[headerKey] = headerVal.map((headerValEntry) => {
const processedExpr = evaluateExpression(headerValEntry, "Header value entry", options);

@@ -360,9 +363,10 @@ if (typeof processedExpr !== "string") {

return processedExpr;
}),
}), {});
});
return acc;
}, {});
const getEndpointProperties = (properties, options) => Object.entries(properties).reduce((acc, [propertyKey, propertyVal]) => ({
...acc,
[propertyKey]: group$1.getEndpointProperty(propertyVal, options),
}), {});
const getEndpointProperties = (properties, options) => Object.entries(properties).reduce((acc, [propertyKey, propertyVal]) => {
acc[propertyKey] = group$1.getEndpointProperty(propertyVal, options);
return acc;
}, {});
const getEndpointProperty = (property, options) => {

@@ -444,10 +448,9 @@ if (Array.isArray(property)) {

const conditionsReferenceRecord = {};
const conditionOptions = {
...options,
referenceRecord: { ...options.referenceRecord },
};
let didAssign = false;
for (const condition of conditions) {
const { result, toAssign } = evaluateCondition(condition, {
...options,
referenceRecord: {
...options.referenceRecord,
...conditionsReferenceRecord,
},
});
const { result, toAssign } = evaluateCondition(condition, conditionOptions);
if (!result) {

@@ -457,7 +460,12 @@ return { result };

if (toAssign) {
didAssign = true;
conditionsReferenceRecord[toAssign.name] = toAssign.value;
conditionOptions.referenceRecord[toAssign.name] = toAssign.value;
options.logger?.debug?.(`${debugId} assign: ${toAssign.name} := ${toDebugString(toAssign.value)}`);
}
}
return { result: true, referenceRecord: conditionsReferenceRecord };
if (didAssign) {
return { result: true, referenceRecord: conditionsReferenceRecord };
}
return { result: true };
};

@@ -471,17 +479,18 @@

}
const endpointRuleOptions = {
...options,
referenceRecord: { ...options.referenceRecord, ...referenceRecord },
};
const endpointRuleOptions = referenceRecord
? {
...options,
referenceRecord: { ...options.referenceRecord, ...referenceRecord },
}
: options;
const { url, properties, headers } = endpoint;
options.logger?.debug?.(`${debugId} Resolving endpoint from template: ${toDebugString(endpoint)}`);
return {
...(headers != undefined && {
headers: getEndpointHeaders(headers, endpointRuleOptions),
}),
...(properties != undefined && {
properties: getEndpointProperties(properties, endpointRuleOptions),
}),
url: getEndpointUrl(url, endpointRuleOptions),
};
const endpointToReturn = { url: getEndpointUrl(url, endpointRuleOptions) };
if (headers != null) {
endpointToReturn.headers = getEndpointHeaders(headers, endpointRuleOptions);
}
if (properties != null) {
endpointToReturn.properties = getEndpointProperties(properties, endpointRuleOptions);
}
return endpointToReturn;
};

@@ -495,6 +504,9 @@

}
throw new EndpointError(evaluateExpression(error, "Error", {
...options,
referenceRecord: { ...options.referenceRecord, ...referenceRecord },
}));
const errorRuleOptions = referenceRecord
? {
...options,
referenceRecord: { ...options.referenceRecord, ...referenceRecord },
}
: options;
throw new EndpointError(evaluateExpression(error, "Error", errorRuleOptions));
};

@@ -531,6 +543,6 @@

}
return group.evaluateRules(rules, {
...options,
referenceRecord: { ...options.referenceRecord, ...referenceRecord },
});
const treeRuleOptions = referenceRecord
? { ...options, referenceRecord: { ...options.referenceRecord, ...referenceRecord } }
: options;
return group.evaluateRules(rules, treeRuleOptions);
};

@@ -537,0 +549,0 @@ const group = {

import { debugId, toDebugString } from "../debug";
import { EndpointError } from "../types";
import { callFunction } from "./callFunction";
export const evaluateCondition = ({ assign, ...fnArgs }, options) => {
export const evaluateCondition = (condition, options) => {
const { assign } = condition;
if (assign && assign in options.referenceRecord) {
throw new EndpointError(`'${assign}' is already defined in Reference Record.`);
}
const value = callFunction(fnArgs, options);
options.logger?.debug?.(`${debugId} evaluateCondition: ${toDebugString(fnArgs)} = ${toDebugString(value)}`);
return {
result: value === "" ? true : !!value,
...(assign != null && { toAssign: { name: assign, value } }),
};
const value = callFunction(condition, options);
options.logger?.debug?.(`${debugId} evaluateCondition: ${toDebugString(condition)} = ${toDebugString(value)}`);
const result = value === "" ? true : !!value;
if (assign != null) {
return { result, toAssign: { name: assign, value } };
}
return { result };
};

@@ -5,10 +5,9 @@ import { debugId, toDebugString } from "../debug";

const conditionsReferenceRecord = {};
const conditionOptions = {
...options,
referenceRecord: { ...options.referenceRecord },
};
let didAssign = false;
for (const condition of conditions) {
const { result, toAssign } = evaluateCondition(condition, {
...options,
referenceRecord: {
...options.referenceRecord,
...conditionsReferenceRecord,
},
});
const { result, toAssign } = evaluateCondition(condition, conditionOptions);
if (!result) {

@@ -18,7 +17,12 @@ return { result };

if (toAssign) {
didAssign = true;
conditionsReferenceRecord[toAssign.name] = toAssign.value;
conditionOptions.referenceRecord[toAssign.name] = toAssign.value;
options.logger?.debug?.(`${debugId} assign: ${toAssign.name} := ${toDebugString(toAssign.value)}`);
}
}
return { result: true, referenceRecord: conditionsReferenceRecord };
if (didAssign) {
return { result: true, referenceRecord: conditionsReferenceRecord };
}
return { result: true };
};

@@ -12,17 +12,18 @@ import { debugId, toDebugString } from "../debug";

}
const endpointRuleOptions = {
...options,
referenceRecord: { ...options.referenceRecord, ...referenceRecord },
};
const endpointRuleOptions = referenceRecord
? {
...options,
referenceRecord: { ...options.referenceRecord, ...referenceRecord },
}
: options;
const { url, properties, headers } = endpoint;
options.logger?.debug?.(`${debugId} Resolving endpoint from template: ${toDebugString(endpoint)}`);
return {
...(headers != undefined && {
headers: getEndpointHeaders(headers, endpointRuleOptions),
}),
...(properties != undefined && {
properties: getEndpointProperties(properties, endpointRuleOptions),
}),
url: getEndpointUrl(url, endpointRuleOptions),
};
const endpointToReturn = { url: getEndpointUrl(url, endpointRuleOptions) };
if (headers != null) {
endpointToReturn.headers = getEndpointHeaders(headers, endpointRuleOptions);
}
if (properties != null) {
endpointToReturn.properties = getEndpointProperties(properties, endpointRuleOptions);
}
return endpointToReturn;
};

@@ -10,6 +10,9 @@ import { EndpointError } from "../types";

}
throw new EndpointError(evaluateExpression(error, "Error", {
...options,
referenceRecord: { ...options.referenceRecord, ...referenceRecord },
}));
const errorRuleOptions = referenceRecord
? {
...options,
referenceRecord: { ...options.referenceRecord, ...referenceRecord },
}
: options;
throw new EndpointError(evaluateExpression(error, "Error", errorRuleOptions));
};

@@ -29,13 +29,15 @@ import { EndpointError } from "../types";

}
if (fn.includes(".")) {
const fnSegments = fn.split(".");
if (fnSegments[0] in customEndpointFunctions && fnSegments[1] != null) {
return customEndpointFunctions[fnSegments[0]][fnSegments[1]](...evaluatedArgs);
const namespaceSeparatorIndex = fn.indexOf(".");
if (namespaceSeparatorIndex !== -1) {
const namespaceFunctions = customEndpointFunctions[fn.slice(0, namespaceSeparatorIndex)];
const customFunction = namespaceFunctions?.[fn.slice(namespaceSeparatorIndex + 1)];
if (typeof customFunction === "function") {
return customFunction(...evaluatedArgs);
}
}
if (typeof endpointFunctions[fn] !== "function") {
throw new Error(`function ${fn} not loaded in endpointFunctions.`);
const callable = endpointFunctions[fn];
if (typeof callable === "function") {
return callable(...evaluatedArgs);
}
const callable = endpointFunctions[fn];
return callable(...evaluatedArgs);
throw new Error(`function ${fn} not loaded in endpointFunctions.`);
};

@@ -42,0 +44,0 @@ export const group = {

@@ -34,6 +34,6 @@ import { EndpointError } from "../types";

}
return group.evaluateRules(rules, {
...options,
referenceRecord: { ...options.referenceRecord, ...referenceRecord },
});
const treeRuleOptions = referenceRecord
? { ...options, referenceRecord: { ...options.referenceRecord, ...referenceRecord } }
: options;
return group.evaluateRules(rules, treeRuleOptions);
};

@@ -40,0 +40,0 @@ export const group = {

import { EndpointError } from "../types";
import { evaluateExpression } from "./evaluateExpression";
export const getEndpointHeaders = (headers, options) => Object.entries(headers ?? {}).reduce((acc, [headerKey, headerVal]) => ({
...acc,
[headerKey]: headerVal.map((headerValEntry) => {
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);

@@ -11,3 +10,4 @@ if (typeof processedExpr !== "string") {

return processedExpr;
}),
}), {});
});
return acc;
}, {});
import { EndpointError } from "../types";
import { evaluateTemplate } from "./evaluateTemplate";
export const getEndpointProperties = (properties, options) => Object.entries(properties).reduce((acc, [propertyKey, propertyVal]) => ({
...acc,
[propertyKey]: group.getEndpointProperty(propertyVal, options),
}), {});
export const getEndpointProperties = (properties, options) => Object.entries(properties).reduce((acc, [propertyKey, propertyVal]) => {
acc[propertyKey] = group.getEndpointProperty(propertyVal, options);
return acc;
}, {});
export const getEndpointProperty = (property, options) => {

@@ -8,0 +8,0 @@ if (Array.isArray(property)) {

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

import type { EndpointARN, EndpointPartition, Logger } from "@smithy/types";
import type { EndpointARN, EndpointPartition, EndpointURL, Logger } from "@smithy/types";
export type ReferenceObject = {

@@ -10,5 +10,5 @@ ref: string;

export type FunctionArgv = Array<Expression | boolean | number>;
export type FunctionReturn = string | boolean | number | EndpointARN | EndpointPartition | {
export type FunctionReturn = string | boolean | number | EndpointARN | EndpointPartition | EndpointURL | {
[key: string]: FunctionReturn;
} | null;
} | Array<FunctionReturn> | null;
export type ConditionObject = FunctionObject & {

@@ -15,0 +15,0 @@ assign?: string;

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

import { coalesce, ite, split } from "../lib";
export declare const endpointFunctions: {
booleanEquals: (value1: boolean, value2: boolean) => boolean;
coalesce: typeof coalesce;
getAttr: (value: import("../lib").GetAttrValue, path: string) => import("../lib").GetAttrValue;
isSet: (value: unknown) => value is {};
isValidHostLabel: (value: string, allowSubDomains?: boolean) => boolean;
ite: typeof ite;
not: (value: boolean) => boolean;
parseURL: (value: string | URL | import("@smithy/types").Endpoint) => import("@smithy/types").EndpointURL | null;
split: typeof split;
stringEquals: (value1: string, value2: string) => boolean;
substring: (input: string, start: number, stop: number, reverse: boolean) => string | null;
uriEncode: (value: string) => string;
};
import type { EndpointFunctions } from "../types";
export declare const endpointFunctions: EndpointFunctions;
import type { ConditionObject, EvaluateOptions } from "../types";
export declare const evaluateCondition: ({ assign, ...fnArgs }: ConditionObject, options: EvaluateOptions) => {
toAssign?: {
export declare const evaluateCondition: (condition: ConditionObject, options: EvaluateOptions) => {
result: boolean;
toAssign: {
name: string;
value: import("../types").FunctionReturn;
} | undefined;
};
} | {
result: boolean;
toAssign?: undefined;
};
import type { ConditionObject, EvaluateOptions, FunctionReturn } from "../types";
export declare const evaluateConditions: (conditions: ConditionObject[] | undefined, options: EvaluateOptions) => {
result: false;
referenceRecord?: undefined;
result: boolean;
referenceRecord: Record<string, FunctionReturn>;
} | {
result: boolean;
referenceRecord: Record<string, FunctionReturn>;
referenceRecord?: undefined;
};
import type { EndpointObjectHeaders, EvaluateOptions } from "../types";
export declare const getEndpointHeaders: (headers: EndpointObjectHeaders, options: EvaluateOptions) => {};
export declare const getEndpointHeaders: (headers: EndpointObjectHeaders, options: EvaluateOptions) => Record<string, string[]>;
import type { EndpointObjectProperty } from "@smithy/types";
import type { EndpointObjectProperties, EvaluateOptions } from "../types";
export declare const getEndpointProperties: (properties: EndpointObjectProperties, options: EvaluateOptions) => {};
export declare const getEndpointProperties: (properties: EndpointObjectProperties, options: EvaluateOptions) => Record<string, EndpointObjectProperty>;
export declare const getEndpointProperty: (property: EndpointObjectProperty, options: EvaluateOptions) => EndpointObjectProperty;
export declare const group: {
getEndpointProperty: (property: EndpointObjectProperty, options: EvaluateOptions) => EndpointObjectProperty;
getEndpointProperties: (properties: EndpointObjectProperties, options: EvaluateOptions) => {};
getEndpointProperties: (properties: EndpointObjectProperties, options: EvaluateOptions) => Record<string, EndpointObjectProperty>;
};
import type { EvaluateOptions, ReferenceObject } from "../types";
export declare const getReferenceValue: ({ ref }: ReferenceObject, options: EvaluateOptions) => string | number | boolean | import("@smithy/types").EndpointPartition | import("@smithy/types").EndpointARN | {
export declare const getReferenceValue: ({ ref }: ReferenceObject, options: EvaluateOptions) => string | number | boolean | import("@smithy/types").EndpointPartition | import("@smithy/types").EndpointARN | import("@smithy/types").EndpointURL | {
[key: string]: import("../types").FunctionReturn;
};
} | import("../types").FunctionReturn[];
{
"name": "@smithy/util-endpoints",
"version": "3.4.1",
"version": "3.4.2",
"description": "Utilities to help with endpoint resolution.",

@@ -5,0 +5,0 @@ "main": "./dist-cjs/index.js",