@based/opts
Advanced tools
Comparing version 0.7.4 to 1.0.0
@@ -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 |
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
Yes
2659
3
8
+ Added@based/fetch@2.0.3(transitive)
+ Added@saulx/hash@3.0.0(transitive)
+ Added@saulx/utils@4.3.2(transitive)
+ Addeddata-uri-to-buffer@4.0.1(transitive)
+ Addedfetch-blob@3.2.0(transitive)
+ Addedformdata-polyfill@4.0.10(transitive)
+ Addednode-domexception@1.0.0(transitive)
+ Addednode-fetch@3.3.2(transitive)
+ Addedweb-streams-polyfill@3.3.3(transitive)
- Removed@based/fetch@1.0.5(transitive)
- Removed@saulx/hash@2.0.0(transitive)
- Removed@saulx/utils@3.5.3(transitive)
- Removedcross-fetch@3.1.8(transitive)
- Removedis-plain-obj@3.0.0(transitive)
- Removednode-fetch@2.7.0(transitive)
- Removedtr46@0.0.3(transitive)
- Removedwebidl-conversions@3.0.1(transitive)
- Removedwhatwg-url@5.0.0(transitive)
Updated@based/fetch@^2.0.1
Updated@saulx/hash@^3.0.0
Updated@saulx/utils@^4.0.4