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

@based/opts

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@based/opts - npm Package Compare versions

Comparing version 0.7.4 to 1.0.0

2

dist/index.js

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

var C=Object.create;var l=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,B=Object.prototype.hasOwnProperty;var P=(e,t)=>{for(var n in t)l(e,n,{get:t[n],enumerable:!0})},m=(e,t,n,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of O(t))!B.call(e,r)&&r!==n&&l(e,r,{get:()=>t[r],enumerable:!(s=w(t,r))||s.enumerable});return e};var M=(e,t,n)=>(n=e!=null?C(S(e)):{},m(t||!e||!e.__esModule?l(n,"default",{value:e,enumerable:!0}):n,e)),U=e=>m(l({},"__esModule",{value:!0}),e);var F={};P(F,{default:()=>q,genCache:()=>d,getServicePort:()=>u});module.exports=U(F);var p=M(require("@based/fetch")),c=require("@saulx/utils");var k=e=>{let t=5381,n=e.length;for(;n;)t=t*33^e.charCodeAt(--n);let s=t>>>0;for(;s>65535;)s=s/10;return Math.round(s)},u=(e,t,n,s,r="allServices",a=0)=>k(`${r}-${e}-${t}-${n}-${s}-${a}`);var b=require("@saulx/hash"),v=e=>e||"@based/env-hub",E={"@based/env-hub":0,"@based/env-admin-hub":1,"@based/admin-hub":2,"@based/machine-hub":3},d=e=>{let t=E[v(e.name)],n=Math.floor(Math.random()*1e4),s=t+""+n;return e.key?s+"/"+(e.optionalKey?e.key+"$":e.key):s},I=async(e,t,n)=>{try{let s=await(0,p.default)(`${e}/status/${d(t)}`,{headers:t.headers});if(s.ok){let r=s.headers.get("x-request-id");if(!r)return 1;let{decode:a}=(0,c.createEncoder)(R,r.slice(0,6).split("")),o=a(r.slice(6)).split(","),h=[];for(let i=0;i<Math.floor(o.length/2);i++)h.push([o[i],encodeURIComponent(o[o.length-1-i])]);let[f,x]=h[~~(Math.random()*h.length)];return n?`${/^https/.test(e)?"https":"http"}://${f}`:`${/^https/.test(e)?"wss":"ws"}://${f}/${x}`}else return!1}catch{return!1}},g=/^ws/,K=({cluster:e="production",org:t,project:n,env:s,name:r})=>{if(e==="local")return[`http://localhost:${u(t,n,s,v(r).includes("env-")?"@based/env-hub-discovery":"@based/hub-discovery","allServices")}`];let a="-status";return[`https://${(0,b.hashObjectIgnoreKeyOrder)({org:t,project:n,env:s,cluster:e}).toString(36)}${a}.based.dev`]},$=async(e,t=!1,n=0)=>{if(e.url){let r;return typeof e.url=="function"?r=await e.url():r=e.url,t&&r&&g.test(r)?r.replace(g,"http"):r}let s=e.discoveryUrls||K(e);for(let r=0;r<s.length;r++){let a=s[r],o=await Promise.race([I(a,e,t),(0,c.wait)(3e3)]);if(o===1||!o&&r===s.length-1)return await(0,c.wait)(Math.min(n*n*50+500,5e3)),$(e,t,++n);if(o)return o}},R=[",",".based.dev","localhost:","localhost","based.io","based.dev","@based","/env-hub","admin","hub","900","90","443","80",":","%","/","=","<","?","."],y=$;var q=async(e,t)=>y(e,t);0&&(module.exports={genCache,getServicePort});
import e from"@based/fetch";import{wait as t,createEncoder as r}from"@saulx/utils";import{hashObjectIgnoreKeyOrder as s}from"@saulx/hash";const a=(e,t,r,s,a="allServices",o=0)=>(e=>{let t=5381,r=e.length;for(;r;)t=33*t^e.charCodeAt(--r);let s=t>>>0;for(;s>65535;)s/=10;return Math.round(s)})(`${a}-${e}-${t}-${r}-${s}-${o}`),o=e=>e||"@based/env-hub",n=/^ws/,l={"@based/env-hub":0,"@based/env-admin-hub":1,"@based/admin-hub":2,"@based/machine-hub":3},h=e=>{const t=l[o(e.name)]+""+Math.floor(1e4*Math.random());return e.key?t+"/"+(e.optionalKey?e.key+"$":e.key):t},c=async(t,s,a)=>{try{const o=await e(`${t}/status/${h(s)}`,{headers:s.headers});if(o.ok){const e=o.headers.get("x-request-id");if(!e)return 1;const{decode:s}=r(u,e.slice(0,6).split("")),n=s(e.slice(6)).split(","),l=[];for(let e=0;e<Math.floor(n.length/2);e++)l.push([n[e],encodeURIComponent(n[n.length-1-e])]);const[h,c]=l[~~(Math.random()*l.length)],d=/^https/.test(t)?"s":"";return a?`http${d}://${h}`:`ws${d}://${h}/${c}`}return!1}catch(e){return!1}},d=async(e,r=!1,l=0)=>{if(e.url){let t;return t="function"==typeof e.url?await e.url():e.url,r&&t&&n.test(t)?t.replace(n,"http"):t}const h=e.discoveryUrls||(({cluster:e="production",org:t,project:r,env:n,name:l})=>"local"===e?[`http://localhost:${a(t,r,n,o(l).includes("env-")?"@based/env-hub-discovery":"@based/hub-discovery","allServices")}`]:[`https://${s({org:t,project:r,env:n,cluster:e}).toString(36)}-status.based.dev`])(e);for(let s=0;s<h.length;s++){const a=h[s],o=await Promise.race([c(a,e,r),t(3e3)]);if(1===o||!o&&s===h.length-1)return await t(Math.min(l*l*50+500,5e3)),d(e,r,++l);if(o)return o}},u=[",",".based.dev","localhost:","localhost","based.io","based.dev","@based","/env-hub","admin","hub","900","90","443","80",":","%","/","=","<","?","."];var i=d,b=async(e,t)=>i(e,t);export{b as default,h as genCache,a as getServicePort};
{
"name": "@based/opts",
"version": "0.7.4",
"version": "1.0.0",
"type": "module",
"main": "dist/index.js",

@@ -11,13 +12,14 @@ "source": "src/index.ts",

"watch": "npx tsc --watch",
"build-for-publish": "rm -rf ./dist/ & esbuild ./src/index.ts --bundle --minify --outdir=./dist/ --external:@saulx/utils --external:@based/fetch --external:@saulx/hash --platform=node"
"build-for-publish": "rm -rf ./dist && npm run build && microbundle -i ./dist/index.js -o ./dist2/index.js --no-pkg-main -f modern --sourcemap=false && rm -rf ./dist && mkdir ./dist && mv ./dist2/index.js ./dist/index.js && rm -rf ./dist2"
},
"dependencies": {
"@saulx/utils": "^3.4.2",
"@saulx/hash": "2.0.0",
"@based/fetch": "^1.0.5"
"@saulx/hash": "^3.0.0",
"@saulx/utils": "^4.0.4",
"@based/fetch": "^2.0.1"
},
"devDependencies": {
"ts-node": "^10.9.1",
"esbuild": "^0.17.19"
"microbundle": "^0.15.1",
"typescript": "^5.2.2",
"@saulx/tsconfig": "^1.0.6"
}
}

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

# @based/discovery
# @based/opts
Given hub discovery urls, it returns a list of available hubs
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