Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@smithy/util-endpoints

Package Overview
Dependencies
Maintainers
2
Versions
26
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 2.0.5 to 2.1.0

dist-cjs/cache/EndpointCache.js

84

dist-cjs/index.js

@@ -23,2 +23,3 @@ var __defProp = Object.defineProperty;

__export(src_exports, {
EndpointCache: () => EndpointCache,
EndpointError: () => EndpointError,

@@ -32,2 +33,71 @@ customEndpointFunctions: () => customEndpointFunctions,

// src/cache/EndpointCache.ts
var _EndpointCache = class _EndpointCache {
/**
* @param [size] - desired average maximum capacity. A buffer of 10 additional keys will be allowed
* before keys are dropped.
* @param [params] - list of params to consider as part of the cache key.
*
* If the params list is not populated, no caching will happen.
* This may be out of order depending on how the object is created and arrives to this class.
*/
constructor({ size, params }) {
this.data = /* @__PURE__ */ new Map();
this.parameters = [];
this.capacity = size ?? 50;
if (params) {
this.parameters = params;
}
}
/**
* @param endpointParams - query for endpoint.
* @param resolver - provider of the value if not present.
* @returns endpoint corresponding to the query.
*/
get(endpointParams, resolver) {
const key = this.hash(endpointParams);
if (key === false) {
return resolver();
}
if (!this.data.has(key)) {
if (this.data.size > this.capacity + 10) {
const keys = this.data.keys();
let i = 0;
while (true) {
const { value, done } = keys.next();
this.data.delete(value);
if (done || ++i > 10) {
break;
}
}
}
this.data.set(key, resolver());
}
return this.data.get(key);
}
size() {
return this.data.size;
}
/**
* @returns cache key or false if not cachable.
*/
hash(endpointParams) {
let buffer = "";
const { parameters } = this;
if (parameters.length === 0) {
return false;
}
for (const param of parameters) {
const val = String(endpointParams[param] ?? "");
if (val.includes("|;")) {
return false;
}
buffer += val + "|;";
}
return buffer;
}
};
__name(_EndpointCache, "EndpointCache");
var EndpointCache = _EndpointCache;
// src/lib/isIpAddress.ts

@@ -448,3 +518,3 @@ var IP_V4_REGEX = new RegExp(

var resolveEndpoint = /* @__PURE__ */ __name((ruleSetObject, options) => {
var _a, _b, _c, _d, _e;
var _a, _b, _c, _d;
const { endpointParams, logger } = options;

@@ -466,12 +536,3 @@ const { parameters, rules } = ruleSetObject;

const endpoint = evaluateRules(rules, { endpointParams, logger, referenceRecord: {} });
if ((_c = options.endpointParams) == null ? void 0 : _c.Endpoint) {
try {
const givenEndpoint = new URL(options.endpointParams.Endpoint);
const { protocol, port } = givenEndpoint;
endpoint.url.protocol = protocol;
endpoint.url.port = port;
} catch (e) {
}
}
(_e = (_d = options.logger) == null ? void 0 : _d.debug) == null ? void 0 : _e.call(_d, `${debugId} Resolved endpoint: ${toDebugString(endpoint)}`);
(_d = (_c = options.logger) == null ? void 0 : _c.debug) == null ? void 0 : _d.call(_c, `${debugId} Resolved endpoint: ${toDebugString(endpoint)}`);
return endpoint;

@@ -482,2 +543,3 @@ }, "resolveEndpoint");

0 && (module.exports = {
EndpointCache,
isIpAddress,

@@ -484,0 +546,0 @@ isValidHostLabel,

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

export * from "./cache/EndpointCache";
export * from "./lib/isIpAddress";

@@ -2,0 +3,0 @@ export * from "./lib/isValidHostLabel";

10

dist-es/resolveEndpoint.js

@@ -25,14 +25,4 @@ import { debugId, toDebugString } from "./debug";

const endpoint = evaluateRules(rules, { endpointParams, logger, referenceRecord: {} });
if (options.endpointParams?.Endpoint) {
try {
const givenEndpoint = new URL(options.endpointParams.Endpoint);
const { protocol, port } = givenEndpoint;
endpoint.url.protocol = protocol;
endpoint.url.port = port;
}
catch (e) {
}
}
options.logger?.debug?.(`${debugId} Resolved endpoint: ${toDebugString(endpoint)}`);
return endpoint;
};

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

export * from "./cache/EndpointCache";
export * from "./lib/isIpAddress";

@@ -2,0 +3,0 @@ export * from "./lib/isValidHostLabel";

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

export * from "./cache/EndpointCache";
export * from "./lib/isIpAddress";

@@ -2,0 +3,0 @@ export * from "./lib/isValidHostLabel";

{
"name": "@smithy/util-endpoints",
"version": "2.0.5",
"version": "2.1.0",
"description": "Utilities to help with endpoint resolution.",

@@ -29,4 +29,4 @@ "main": "./dist-cjs/index.js",

"dependencies": {
"@smithy/node-config-provider": "^3.1.4",
"@smithy/types": "^3.3.0",
"@smithy/node-config-provider": "^3.1.5",
"@smithy/types": "^3.4.0",
"tslib": "^2.6.2"

@@ -33,0 +33,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