@buoy-gg/license 7.0.46 → 7.0.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/lib/web/chunks/LicenseManager-7D2GGBCB.mjs +0 -1
- package/lib/web/chunks/LicenseManager-AEFCYYMQ.mjs +0 -1
- package/lib/web/chunks/LicenseManager-HPGEBROD.mjs +0 -1
- package/lib/web/chunks/LicenseManager-IDGPK6OM.mjs +0 -1
- package/lib/web/chunks/LicenseManager-JHLFWSUD.mjs +0 -1
- package/lib/web/chunks/LicenseManager-KDM6XEPI.mjs +0 -1
- package/lib/web/chunks/LicenseManager-Q3JTVOGK.mjs +0 -1
- package/lib/web/chunks/LicenseManager-RXOJAIDG.mjs +0 -1
- package/lib/web/chunks/LicenseManager-UHFOJRQ6.mjs +0 -1
- package/lib/web/chunks/LicenseManager-VWEJJHBH.mjs +0 -1
- package/lib/web/chunks/LicenseManager-XSLQCKDC.mjs +0 -1
- package/lib/web/chunks/LicenseManager-YI5LR3AY.mjs +0 -1
- package/lib/web/chunks/chunk-CMYC3OJ3.mjs +0 -73
- package/lib/web/chunks/chunk-CVVUFZAQ.mjs +0 -73
- package/lib/web/chunks/chunk-GRUXDUJG.mjs +0 -68
- package/lib/web/chunks/chunk-JPTOVVON.mjs +0 -73
- package/lib/web/chunks/chunk-JVWYYKXV.mjs +0 -73
- package/lib/web/chunks/chunk-KQ3HUCUX.mjs +0 -73
- package/lib/web/chunks/chunk-LHMH746X.mjs +0 -73
- package/lib/web/chunks/chunk-OPWF6JR6.mjs +0 -68
- package/lib/web/chunks/chunk-TVOTAEQX.mjs +0 -68
- package/lib/web/chunks/chunk-XOY6D2WL.mjs +0 -73
- package/lib/web/chunks/chunk-YEGY5MDO.mjs +0 -73
- package/lib/web/chunks/chunk-ZSTLYSNF.mjs +0 -68
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use client";var d=process.env.NODE_ENV!=="production";typeof window<"u"&&typeof globalThis.global>"u"&&(globalThis.global=globalThis);var x=new Map,_e={async getItem(e){try{return localStorage.getItem(e)??x.get(e)??null}catch{return x.get(e)??null}},async setItem(e,t){x.set(e,t);try{localStorage.setItem(e,t)}catch{}},async removeItem(e){x.delete(e);try{localStorage.removeItem(e)}catch{}}};async function g(){return _e}var L={accountId:"b0eba0e8-e904-4906-b644-38f9aab57bed",productId:"bf67cb43-eeef-40ca-b308-e6e1b22c0eaa",apiUrl:"https://buoy.gg/api/license"},Ee="3b546fc717a62683f3236c70167899a271bee3ffc04df6ec1eea60a394a2f1e9",ke="36abba0267f7f379d992a5b6df641daab4190bcc9e639e36f1378e3c1ac52746",I={free:"394e3351-1249-4f73-807a-703408604c0e",solo:"fa5d3c8f-5379-40f1-b63e-ab8a974b2f28",business:"690c2212-8e54-426f-b4b4-002ee1c0ae2b"},R=720*60*60*1e3,be=1440*60*1e3,M="buoy-gg-license",O="buoy-gg-device-fingerprint",xe=3600*1e3,Le=[5*1e3,20*1e3,60*1e3,300*1e3,900*1e3],Ie=60*1e3,W=3600*1e3,Re=1440*60*1e3,Ne=50,Pe=R,V="buoy-gg-license-hold";function h(){let e=globalThis.__buoyRealNow;return typeof e=="function"?e():Date.now()}var{apiUrl:q}=L,T=class extends Error{constructor(e,t,i=null){super(e);this.isTransient=true;this.name="LicenseTransportError",this.status=t,this.retryAfterMs=i}};function Ce(e){let t=e?.status;return t===429||t===402}function Se(e,t,i){return e.status===402?t:e.retryAfterMs??i}function Ke(e){let t=s=>{try{return e.headers?.get?.(s)??null}catch{return null}},i=t("Retry-After");if(i){let s=Number(i);if(Number.isFinite(s)&&s>=0)return s*1e3;let n=Date.parse(i);if(Number.isFinite(n))return Math.max(0,n-h())}let r=Number(t("X-RateLimit-Reset"));return Number.isFinite(r)&&r>0?Math.max(0,r*1e3-h()):null}function Z(e){return e instanceof T||e instanceof TypeError?true:typeof e=="object"&&e!==null&&e.isTransient===true}async function Me(e){try{return(await e.json()).errors?.[0]?.detail||`HTTP ${e.status}`}catch{return`HTTP ${e.status}`}}function Q(){return{"Content-Type":"application/vnd.api+json",Accept:"application/vnd.api+json"}}async function Oe(e,t){let i=`${q}/validate`,r={meta:{key:e}},s;try{s=await fetch(i,{signal:t,method:"POST",headers:Q(),body:JSON.stringify(r)})}catch(n){throw new T(n instanceof Error?n.message:"Network request failed",null)}if(!s.ok)throw new T(await Me(s),s.status,s.status===429?Ke(s):null);try{let n=await s.json();if(!n||typeof n!="object"||typeof n.meta?.valid!="boolean"||typeof n.meta?.code!="string"||!n.meta.code)throw new Error("Missing license verdict");return n}catch{throw new T("License server returned an unreadable response",s.status)}}async function Ve(e){let t=typeof AbortController=="function"?new AbortController:null,i;try{return await Promise.race([Oe(e,t?.signal),new Promise((r,s)=>{i=setTimeout(()=>{s(new T("License verification timed out. Please retry.",null)),t?.abort()},15e3)})])}finally{i&&clearTimeout(i)}}function De(e){if(!e.data)return false;let t=e.data.relationships?.product?.data?.id;return t&&t!==L.productId?false:e.meta.valid&&e.meta.code==="VALID"?true:["OVERDUE","NO_MACHINE","NO_MACHINES","TOO_MANY_MACHINES","TOO_MANY_CORES","TOO_MANY_PROCESSES","FINGERPRINT_SCOPE_MISMATCH","HEARTBEAT_NOT_STARTED","HEARTBEAT_DEAD"].includes(e.meta.code)}function Ue(e){let t=e.data?.relationships?.machines?.meta?.count;return typeof t=="number"&&Number.isFinite(t)?t:0}async function ee(e,t,i,r,s){let n=`${q}/machines`,c=await fetch(n,{method:"POST",headers:Q(),body:JSON.stringify({licenseId:e,licenseKey:t,fingerprint:i,name:r,metadata:s||{}})});if(!c.ok){let o=await c.json(),a=o.errors?.[0]?.code;if(a==="FINGERPRINT_TAKEN")throw new Error("FINGERPRINT_TAKEN");if(a==="MACHINE_LIMIT_EXCEEDED")throw new Error("MACHINE_LIMIT_EXCEEDED");let l=o.errors?.[0]?.detail||`HTTP ${c.status}`;throw new Error(l)}return c.json()}function Fe(e){let{meta:t,data:i}=e;return{valid:t.valid,code:t.code,detail:t.detail,metadata:i?.attributes?.metadata}}function $e(e){return["NOT_FOUND","SUSPENDED","EXPIRED","BANNED","PRODUCT_SCOPE_MISMATCH"].includes(e)}function D(){return typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}function U(){if(typeof d<"u")return d;try{if(typeof navigator<"u"&&/electron/i.test(navigator.userAgent))return true}catch{}return typeof process<"u"&&process.env.NODE_ENV!=="production"}function te(){if(typeof navigator>"u")return"unknown";let e=navigator.userAgent.toLowerCase(),t=navigator.platform?.toLowerCase()||"";return e.includes("electron")?t.includes("mac")||e.includes("mac")?"electron-macos":t.includes("win")||e.includes("win")?"electron-windows":t.includes("linux")||e.includes("linux")?"electron-linux":"electron":t.includes("mac")||e.includes("mac")?"macos":t.includes("win")||e.includes("win")?"windows":t.includes("linux")||e.includes("linux")?"linux":/iphone|ipad|ipod/.test(e)?"ios-web":e.includes("android")?"android-web":"web"}function He(){if(typeof navigator>"u")return"unknown";let e=navigator.userAgent,t=e.match(/Mac OS X ([\d_.]+)/);if(t)return t[1].replace(/_/g,".");let i=e.match(/Windows NT ([\d.]+)/);return i?{"10.0":"10/11","6.3":"8.1","6.2":"8","6.1":"7"}[i[1]]||i[1]:e.includes("Linux")?"Linux":"unknown"}function ie(){if(typeof navigator>"u")return{name:"unknown",version:"unknown"};let e=navigator.userAgent,t=e.match(/Electron\/([\d.]+)/);if(t)return{name:"Electron",version:t[1]};let i=e.match(/Chrome\/([\d.]+)/);if(i&&!e.includes("Edg"))return{name:"Chrome",version:i[1]};let r=e.match(/Edg\/([\d.]+)/);if(r)return{name:"Edge",version:r[1]};let s=e.match(/Firefox\/([\d.]+)/);if(s)return{name:"Firefox",version:s[1]};let n=e.match(/Version\/([\d.]+).*Safari/);return n?{name:"Safari",version:n[1]}:{name:"unknown",version:"unknown"}}function re(){let e={platform:te(),osVersion:He(),isSimulator:"false"},t=ie();e.browser=t.name,e.browserVersion=t.version,typeof window<"u"&&window.screen&&(e.screenResolution=`${window.screen.width}x${window.screen.height}`),typeof navigator<"u"&&navigator.language&&(e.language=navigator.language);try{e.timezone=Intl.DateTimeFormat().resolvedOptions().timeZone}catch{}return e}function F(){let e=te(),t=ie();if(e.startsWith("electron")){let i=e.replace("electron-","").replace("electron","Desktop");return`${i.charAt(0).toUpperCase()+i.slice(1)} App`}return t.name!=="unknown"?`${t.name} Browser`:"Web Browser"}var je=["v1"],Be="buoy.gg/pro:9f3c1d7a4b2e:license-cache";function se(e,t){let i=t>>>0;for(let r=0;r<e.length;r++)i^=e.charCodeAt(r),i=Math.imul(i,16777619)>>>0;return i>>>0}function ze(e,t){let i=[t,e.licenseKey,e.licenseId,e.isPro?"1":"0",e.expiresAt??"",String(e.cachedAt)];return t!=="v1"&&i.push(e.tier??""),i.push(Be),i.join("\0")}function ne(e,t){let i=ze(e,t),r=se(i,2166136261),s=se(i,2135587861);return`${t}.${r.toString(16)}${s.toString(16)}`}function ae(e){return ne(e,"v2")}function oe(e){return{...e,sig:ae(e)}}function A(e){return!e||typeof e.sig!="string"||e.sig.length===0?false:e.sig===ae(e)?true:je.some(t=>e.sig.startsWith(`${t}.`)&&e.sig===ne(e,t))}import Ge from"tweetnacl";var Ye=1,Je=1,Xe="buoy-free-token-v1:",We=22,qe=64,le=/^BUOY1-([A-Z2-7]+)-([A-Z2-7]+)$/;function ce(e){return le.test(e.trim().toUpperCase())}var Ze="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";function he(e){let t=[],i=0,r=0;for(let s of e){let n=Ze.indexOf(s);if(n===-1)return null;r=r<<5|n,i+=5,i>=8&&(t.push(r>>>i-8&255),i-=8)}return new Uint8Array(t)}function Qe(e){let t=e.trim().toLowerCase(),i=new Uint8Array(t.length/2);for(let r=0;r<i.length;r+=1)i[r]=parseInt(t.slice(r*2,r*2+2),16);return i}function et(e){let t="";for(let i of e)t+=i.toString(16).padStart(2,"0");return t}function tt(e){if(typeof TextEncoder<"u")return new TextEncoder().encode(e);let t=new Uint8Array(e.length);for(let i=0;i<e.length;i+=1)t[i]=e.charCodeAt(i)&255;return t}function it(e,t){let i=new Uint8Array(e.length+t.length);return i.set(e,0),i.set(t,e.length),i}function rt(e){return it(tt(Xe),e)}var st=Ee;function nt(e,t=st){let i=le.exec(e.trim().toUpperCase());if(!i)return null;let r=he(i[1]),s=he(i[2]);if(!r||!s||r.length!==We||s.length!==qe||r[0]!==Ye||r[1]!==Je)return null;try{if(!Ge.sign.detached.verify(rt(r),s,Qe(t)))return null}catch{return null}return{tier:"free",issuedAt:((r[2]<<24>>>0)+(r[3]<<16)+(r[4]<<8)+r[5])*1e3,accountHash:et(r.slice(6,22))}}function at(e){let t=e.relationships?.policy?.data?.id;return t===I.free?"free":t===I.solo||t===I.business?"pro":e.attributes?.metadata?.plan==="free"?"free":"pro"}function ot(e){if(!e)return false;let t=e.relationships?.product?.data?.id;if(t)return t===L.productId;let i=e.relationships?.policy?.data?.id;return Object.values(I).some(r=>r===i)}function ue(e,t=h()){let i=e.verifiedAt!==null&&Number.isFinite(e.verifiedAt)&&e.verifiedAt<=t?e.verifiedAt+R:null;return e.initialized&&e.key&&e.tierSource!=="none"&&i!==null&&t<i?{status:"admitted",reason:null,validUntil:i}:i!==null&&t>=i?{status:"locked",reason:"verification_expired",validUntil:i}:!e.initialized||e.validating?{status:"initializing",reason:"checking",validUntil:i}:{status:"locked",reason:i!==null&&t>=i?"verification_expired":"account_required",validUntil:i}}function lt(e){if(typeof window>"u"||typeof window.addEventListener!="function")return()=>{};let t=()=>{document.hidden||e()};return window.addEventListener("focus",e),document.addEventListener("visibilitychange",t),()=>{window.removeEventListener("focus",e),document.removeEventListener("visibilitychange",t)}}import ct from"tweetnacl";var de="buoys1",ht="buoy-session-v1:",fe=1,$=60,ut=64,dt=["free","pro","business"],y="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";function H(e){let t="",i=0;for(;i+2<e.length;i+=3){let s=e[i]<<16|e[i+1]<<8|e[i+2];t+=y[s>>>18&63]+y[s>>>12&63]+y[s>>>6&63]+y[s&63]}let r=e.length-i;if(r===1){let s=e[i]<<16;t+=y[s>>>18&63]+y[s>>>12&63]}else if(r===2){let s=e[i]<<16|e[i+1]<<8;t+=y[s>>>18&63]+y[s>>>12&63]+y[s>>>6&63]}return t}function pe(e){if(!/^[A-Za-z0-9_-]*$/.test(e)||e.length%4===1)return null;let t=[],i=0,r=0;for(let s of e)r=r<<6|y.indexOf(s),i+=6,i>=8&&(t.push(r>>>i-8&255),i-=8);return new Uint8Array(t)}function ft(e){if(typeof TextEncoder<"u")return new TextEncoder().encode(e);let t=unescape(encodeURIComponent(e)),i=new Uint8Array(t.length);for(let r=0;r<t.length;r+=1)i[r]=t.charCodeAt(r);return i}function pt(e){try{if(typeof TextDecoder<"u")return new TextDecoder("utf-8",{fatal:true}).decode(e);let t="";for(let i of e)t+=String.fromCharCode(i);return decodeURIComponent(escape(t))}catch{return null}}function mt(e){let t=e.trim().toLowerCase(),i=new Uint8Array(t.length/2);for(let r=0;r<i.length;r+=1)i[r]=parseInt(t.slice(r*2,r*2+2),16);return i}function yt(e){return ft(ht+e)}function _(e,t=256){return typeof e=="string"&&e.length>0&&e.length<=t}function me(e){return typeof e=="number"&&Number.isInteger(e)&&e>0}function gt(e){if(!e||typeof e!="object"||Array.isArray(e))return null;let t=e;return!_(t.sid)||!_(t.sub)||!_(t.aud,512)||t.team!==null&&!_(t.team)||!dt.includes(t.tier)||t.role!==void 0&&!_(t.role,64)||t.tools!==void 0&&(!Array.isArray(t.tools)||t.tools.length>256||!t.tools.every(i=>_(i,64)))||!me(t.iat)||!me(t.exp)||t.exp<=t.iat?null:{v:fe,sid:t.sid,sub:t.sub,team:t.team,tier:t.tier,...t.role!==void 0?{role:t.role}:{},...t.tools!==void 0?{tools:[...t.tools]}:{},aud:t.aud,iat:t.iat,exp:t.exp}}var wt=ke;function ye(e){return e.startsWith(`${de}.`)}function j(e,t){let i=t.publicKeyHex??wt;if(!i)return{ok:false,reason:"no-key"};let r=typeof e=="string"?e.split("."):[];if(r.length!==3||r[0]!==de)return{ok:false,reason:"malformed"};let[,s,n]=r,c=pe(s),o=pe(n);if(!c||!o||o.length!==ut)return{ok:false,reason:"malformed"};try{if(!ct.sign.detached.verify(yt(s),o,mt(i)))return{ok:false,reason:"signature"}}catch{return{ok:false,reason:"signature"}}let a=pt(c),l;try{l=a===null?null:JSON.parse(a)}catch{return{ok:false,reason:"malformed"}}if(!l||typeof l!="object"||l.v!==fe)return{ok:false,reason:l&&typeof l=="object"?"version":"malformed"};let u=gt(l);if(!u)return{ok:false,reason:"claims"};if(u.aud!==t.audience)return{ok:false,reason:"audience"};if(t.ignoreTime)return{ok:true,claims:u};let f=Math.floor((t.nowMs??h())/1e3);return f>=u.exp+$?{ok:false,reason:"expired"}:u.iat>f+$?{ok:false,reason:"not-yet-valid"}:{ok:true,claims:u}}var vt="@buoy/session:",N=10080*60*1e3,ge=360*60*1e3,Tt=300*1e3,At=15e3,_t="https://buoy.gg",Et="buoy:signin",kt=600*1e3,p=class extends Error{constructor(e,t){super(t);this.code=e;this.name="SessionError"}};function bt(){let e=globalThis;return{fetch:(t,i)=>fetch(t,i),storage:g,now:h,random:t=>{let i=new Uint8Array(t);if(!e.crypto?.getRandomValues)throw new p("not_configured","This platform has no secure random source.");return e.crypto.getRandomValues(i)},sha256:async t=>{if(!e.crypto?.subtle)throw new p("not_configured","Sign-in needs a secure page (https or localhost).");return new Uint8Array(await e.crypto.subtle.digest("SHA-256",t))},openPopup:()=>{if(!e.window?.open)return null;let t=480,i=640,r=Math.max(0,(e.window.screenX??0)+((e.window.outerWidth??t)-t)/2),s=Math.max(0,(e.window.screenY??0)+((e.window.outerHeight??i)-i)/2);return e.window.open("about:blank","buoy-signin",`popup,width=${t},height=${i},left=${r},top=${s}`)},onMessage:t=>{if(!e.window?.addEventListener)return()=>{};let i=r=>t({origin:r.origin,data:r.data});return e.window.addEventListener("message",i),()=>e.window?.removeEventListener("message",i)},withLock:(t,i)=>e.navigator?.locks?e.navigator.locks.request(t,i):i(),watch:t=>{let i=e.window;if(!i?.addEventListener)return()=>{};let r=n=>t.storage(n.key),s=()=>{i.document?.visibilityState!=="hidden"&&t.wake()};return i.addEventListener("storage",r),i.addEventListener("online",t.wake),i.document?.addEventListener?.("visibilitychange",s),()=>{i.removeEventListener("storage",r),i.removeEventListener("online",t.wake),i.document?.removeEventListener?.("visibilitychange",s)}},setTimer:(t,i)=>setTimeout(t,Math.min(i,2147483647)),clearTimer:t=>clearTimeout(t)}}function xt(){let e=globalThis.location;if(!(!e?.origin||!/^https?:$/.test(e.protocol??"")))return e.origin}var Lt=class{constructor(e){this.signinOrigin=_t;this.current=null;this.claims=null;this.listeners=new Set;this.timer=null;this.refreshing=null;this.loaded=null;this.unwatch=null;this.limitTimer=null;this.epoch=0;this.deps=e??bt(),this.audience=xt()}get origin(){return this.signinOrigin}configure(e){e.audience!==void 0&&(this.audience=e.audience),e.signinOrigin!==void 0&&(this.signinOrigin=e.signinOrigin.replace(/\/$/,"")),this.reset()}__setDeps(e){this.deps=e,this.reset()}reset(){this.unwatch?.(),this.unwatch=null,this.epoch+=1,this.limitTimer!==null&&this.deps.clearTimer(this.limitTimer),this.limitTimer=null,this.timer!==null&&this.deps.clearTimer(this.timer),this.timer=null,this.current=null,this.claims=null,this.loaded=null,this.refreshing=null}get storageKey(){return vt+(this.audience??"")}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}notify(){for(let e of[...this.listeners])try{e()}catch(t){console.warn("[Buoy] sign-in listener error:",t)}}getAccessToken(){let e=this.getStatus();return e.state==="active"&&!e.grace?this.current?.accessToken??null:null}getStatus(){let e=this.claims;if(!e)return{state:"signed_out"};let t=e.exp*1e3,i=this.deps.now();return i<(e.iat-$)*1e3?{state:"signed_out"}:i<t?{state:"active",claims:e,grace:false,validUntil:t}:i<t+N?{state:"active",claims:e,grace:true,validUntil:t+N}:{state:"signed_out"}}load(){return this.loaded||(this.loaded=this.loadOnce()),this.loaded}async loadOnce(){if(!this.audience)return;this.unwatch??(this.unwatch=this.deps.watch?.({storage:t=>{(t===null||t===this.storageKey)&&this.sync()},wake:()=>{this.claims&&this.refresh()}})??null);let e=await this.read();e&&this.adopt(e)&&(this.notify(),this.schedule())}async sync(){if(!this.audience)return;let e=await this.read();if(!e){this.current&&this.clearLocal();return}e.refreshToken!==this.current?.refreshToken&&this.adopt(e)&&(this.notify(),this.schedule())}async read(){try{let e=await(await this.deps.storage()).getItem(this.storageKey);if(!e)return null;let t=JSON.parse(e);return t?.v===1&&typeof t.accessToken=="string"&&typeof t.refreshToken=="string"?t:null}catch{return null}}async write(e){let t=await this.deps.storage();e?await t.setItem(this.storageKey,JSON.stringify(e)):await t.removeItem(this.storageKey)}adopt(e){if(!this.audience)return false;let t=j(e.accessToken,{audience:this.audience,ignoreTime:true,publicKeyHex:this.deps.publicKeyHex}),i=t.ok?t.claims:null;return i?(this.current=e,this.claims=i,true):false}armLimit(){if(this.limitTimer!==null&&this.deps.clearTimer(this.limitTimer),this.limitTimer=null,!this.claims)return;let e=this.claims.exp*1e3,t=this.deps.now(),i=t<e?e:t<e+N?e+N:null;i!==null&&(this.limitTimer=this.deps.setTimer(()=>{this.limitTimer=null,this.notify(),this.armLimit()},i-t))}call(e,t){return new Promise((i,r)=>{let s=this.deps.setTimer(()=>r(new Error("timeout")),At);this.deps.fetch(e,t).then(n=>{this.deps.clearTimer(s),i(n)},n=>{this.deps.clearTimer(s),r(n)})})}schedule(){if(this.armLimit(),this.timer!==null&&this.deps.clearTimer(this.timer),this.timer=null,!this.claims)return;let e=this.claims.exp*1e3-ge-this.deps.now();this.timer=this.deps.setTimer(()=>{this.timer=null,this.refresh()},Math.max(0,e))}refresh(e=false){return this.refreshing||(this.refreshing=this.deps.withLock(this.lockName,()=>this.refreshLocked(e)).catch(()=>this.retryLater()).finally(()=>{this.refreshing=null})),this.refreshing}get lockName(){return`buoy-session:${this.audience??""}`}async refreshLocked(e){let t=this.epoch,i=await this.read();if(!i){this.current&&this.clearLocal();return}if(i.refreshToken!==this.current?.refreshToken&&this.adopt(i)){this.notify(),this.schedule();return}if(!this.claims)return;if(!e&&this.claims.exp*1e3-this.deps.now()>ge){this.schedule();return}let r,s;try{let n=await this.call(`${this.signinOrigin}/api/auth/refresh`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refresh_token:i.refreshToken,audience:this.audience})});r=n.status,s=await n.json().catch(()=>null)}catch{this.retryLater();return}if(t===this.epoch){if(r===200&&s&&typeof s.access_token=="string"&&typeof s.refresh_token=="string"){let n={v:1,accessToken:s.access_token,refreshToken:s.refresh_token};if(this.adopt(n)){await this.write(n),this.notify(),this.schedule();return}}if(r===400||r===401||r===403){await this.write(null),this.clearLocal();return}this.retryLater()}}retryLater(){this.armLimit(),this.timer!==null&&this.deps.clearTimer(this.timer),this.timer=this.deps.setTimer(()=>{this.timer=null,this.refresh(true)},Tt),this.notify()}clearLocal(){this.timer!==null&&this.deps.clearTimer(this.timer),this.timer=null,this.limitTimer!==null&&this.deps.clearTimer(this.limitTimer),this.limitTimer=null,this.current=null,this.claims=null,this.notify()}async signIn(){if(!this.audience)throw new p("not_configured","Sign-in needs a web page or a configured app id.");let e=this.deps.openPopup();if(!e)throw new p("popup_blocked","The browser blocked the sign-in window. Allow pop-ups for this site and try again.");try{return await this.signInWith((t,i)=>new Promise((r,s)=>{e.location.href=t;let n=this.deps.now(),c=null,o=u=>{c!==null&&this.deps.clearTimer(c),a(),u()},a=this.deps.onMessage(u=>{if(u.origin!==this.signinOrigin)return;let f=u.data;!f||f.type!==Et||f.state!==i||(typeof f.code=="string"?o(()=>r(f.code)):o(()=>s(new p("access_denied","Sign-in was cancelled."))))}),l=()=>{if(e.closed)return o(()=>s(new p("popup_closed","The sign-in window was closed.")));if(this.deps.now()-n>kt)return o(()=>s(new p("timeout","Sign-in took too long.")));c=this.deps.setTimer(l,500)};c=this.deps.setTimer(l,500)}))}finally{try{e.closed||e.close()}catch{}}}async signInWith(e){let t=this.audience;if(!t)throw new p("not_configured","Sign-in needs a web page or a configured app id.");let i=H(this.deps.random(32)),r=H(this.deps.random(16)),s=H(await this.deps.sha256(new TextEncoder().encode(i))),n=`${this.signinOrigin}/auth/authorize?audience=${encodeURIComponent(t)}&code_challenge=${s}&code_challenge_method=S256&state=${r}`,c=await e(n,r),o;try{o=await this.call(`${this.signinOrigin}/api/auth/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:c,code_verifier:i,audience:t})})}catch{throw new p("network","Buoy could not be reached. Check your connection and try again.")}let a=await o.json().catch(()=>null);if(o.status!==200||!a||typeof a.access_token!="string"||typeof a.refresh_token!="string"){let u=a&&typeof a.error_description=="string"?a.error_description:"Buoy did not accept this sign-in.";throw new p(o.status===503?"unavailable":"rejected",u)}let l={v:1,accessToken:a.access_token,refreshToken:a.refresh_token};if(this.epoch+=1,!this.adopt(l))throw new p("rejected","Buoy sent a sign-in this app could not check.");return await this.write(l),await this.load(),this.notify(),this.schedule(),this.getStatus()}async signOut(){this.epoch+=1;let e=this.current;this.clearLocal();let t=e;try{await this.deps.withLock(this.lockName,async()=>{t=await this.read()??e,await this.write(null)})}catch{await this.write(null).catch(()=>{})}if(t)try{await this.call(`${this.signinOrigin}/api/auth/revoke`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refresh_token:t.refreshToken})})}catch{}}},E=new Lt;var It="bsk1_",Rt="service",Nt=15e3;function B(e){return e.startsWith(It)}function we(e){let t=e.trim();return B(t)||ye(t)?t:t.toUpperCase()}async function Pt(e,t){let i=t.fetch??((a,l)=>fetch(a,l)),r=typeof AbortController<"u"?new AbortController:void 0,s=setTimeout(()=>r?.abort(),Nt),n,c;try{let a=await i(`${t.origin.replace(/\/$/,"")}/api/auth/service-token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:e}),signal:r?.signal});n=a.status,c=await a.json().catch(()=>null)}catch{return{ok:false,reason:"network",detail:"Buoy could not be reached to check the bot key."}}finally{clearTimeout(s)}if(n>=500||n===429)return{ok:false,reason:"network",detail:"Buoy is busy. The bot key will be checked again soon."};if(n!==200||typeof c?.access_token!="string")return{ok:false,reason:"rejected",detail:typeof c?.error_description=="string"?c.error_description:"This bot key was not accepted."};let o=j(c.access_token,{audience:Rt,nowMs:h(),publicKeyHex:t.publicKeyHex});return o.ok?{ok:true,claims:o.claims}:{ok:false,reason:"rejected",detail:"Buoy sent a token this app could not check."}}var Ct="dev";function ve(e){return ye(e)}function St(e,t=h()){let i=j(e,{audience:Ct,ignoreTime:true});return i.ok?t>=i.claims.exp*1e3?{ok:false,reason:"expired",message:"Your dev token ran out. Run `npx buoy login` again."}:{ok:true,claims:i.claims}:{ok:false,reason:"invalid",message:"This dev token is not valid. Run `npx buoy login` again."}}var Kt="This is a dev token. It only works in dev builds. A live build turns on Buoy with Sign in with Buoy.";async function w(e,t){let i;try{return await Promise.race([e,new Promise(r=>{i=setTimeout(()=>r(t),15e3)})])}finally{i&&clearTimeout(i)}}function k(e){return e.tier==="pro"||e.tier==="free"?e.tier:e.isPro?"pro":"free"}var Mt=class{constructor(){this.state={isInitialized:false,isValidating:false,isPro:false,tier:"free",tierSource:"none",licenseKey:null,error:null,errorKind:null,expiresAt:null};this.listeners=new Set;this.revalidationTimer=null;this.cachedLicense=null;this.fingerprintPromise=null;this.initPromise=null;this.generation=0;this.persistence=Promise.resolve();this.verifiedAt=null;this.expiryTimer=null;this.removeForegroundListener=null;this.sessionUnsubscribe=null;this.retryTimer=null;this.retryAttempt=0;this.deviceRegistrationCallback=null;this.pendingRegistration=null}async initialize(){if(this.initPromise)return this.initPromise;if(!this.state.isInitialized)return this.initPromise=this._doInitialize(),this.initPromise}async _doInitialize(){if(this.state.isInitialized)return;let e=this.generation;this.sessionUnsubscribe||(this.sessionUnsubscribe=E.subscribe(()=>this.emit({type:"validated",isPro:this.isPro()}))),await w(E.load().catch(()=>{}),void 0);try{let t=await w(this.loadCachedLicense(),null);if(e!==this.generation){this.state.isInitialized=true,this.emit({type:"initialized",isPro:this.state.isPro}),this.startRevalidationTimer();return}if(t&&(this.configuredKey===void 0||t.licenseKey===this.configuredKey)){let i=A(t);this.cachedLicense=t,this.state.licenseKey=t.licenseKey,i&&this.isCacheValid(t)?this.applyTier(k(t)):this.lock(),this.state.expiresAt=t.expiresAt?new Date(t.expiresAt):null,i&&this.isCacheValid(t)&&this.setVerifiedAt(t.cachedAt),this.configuredKey===void 0&&t.licenseKey&&!(i&&this.isCacheValid(t)&&this.isCacheFresh(t))&&this.validateInBackground(t.licenseKey)}this.state.isInitialized=true,this.emit({type:"initialized",isPro:this.state.isPro}),this.startRevalidationTimer()}catch(t){console.warn("[React Buoy] License initialization failed:",t),this.state.isInitialized=true,this.emit({type:"initialized",isPro:false})}}async configure(e){if(e===void 0)return await this.initialize(),this.hasAccountAccess();let t=we(e),i=++this.generation;return this.cancelRetry(),this.configuredKey=t||null,this.state.licenseKey!==this.configuredKey&&this.lock(),this.state.licenseKey=this.configuredKey,this.state.isValidating=!!t,this.emit({type:"validating",isPro:this.isPro()}),await this.initialize(),i!==this.generation?false:t?this.setLicenseKey(t):(await this.clearLicense(),false)}async setLicenseKey(e,t){if(!e||e.trim().length===0)return this.state.error="License key is required",this.state.errorKind="verdict",false;let i=we(e),r=++this.generation;if(this.cancelRetry(),t?.isRetry||(this.retryAttempt=0),this.state.licenseKey!==i&&this.lock(),this.state.licenseKey=i,this.state.isValidating=true,this.state.error=null,this.state.errorKind=null,this.emit({type:"validating",isPro:this.isPro()}),ce(i))return this.admitToken(i,r);if(B(i))return this.admitServiceKey(i,r);if(ve(i))return this.admitDevToken(i);if(!this.cachedLicense){let a=await w(this.loadCachedLicense(),null);if(r!==this.generation)return false;a?.licenseKey===i&&(this.cachedLicense=a,A(a)&&this.isCacheValid(a)&&(this.applyTier(k(a)),this.state.expiresAt=a.expiresAt?new Date(a.expiresAt):null,this.setVerifiedAt(a.cachedAt),this.emit({type:"validating",isPro:this.isPro()})))}let s=this.cachedLicense;if(!t?.force&&s&&s.valid&&s.licenseKey===i&&s.fingerprint&&A(s)&&this.isCacheValid(s)&&this.isCacheFresh(s))return this.applyTier(k(s)),this.state.licenseKey=i,this.state.isValidating=false,this.state.error=null,this.state.errorKind=null,this.state.expiresAt=s.expiresAt?new Date(s.expiresAt):null,this.setVerifiedAt(s.cachedAt),this.emit({type:"validated",isPro:this.state.isPro}),true;let n=await w(this.loadHold(),null);if(r!==this.generation)return false;let c=(n?.backoffUntil??0)-h();if(c>0)return this.standDown(i,r,"License server is rate limited; retrying later.",c);if(!t?.force&&n?.key===i&&n.verdictAt!==void 0&&h()-n.verdictAt>=0&&h()-n.verdictAt<Re)return this.lock(),this.state.isValidating=false,this.state.error=n.detail||"License could not be verified",this.state.errorKind="verdict",this.emit({type:"error",isPro:false,error:this.state.error}),false;let o;try{o=await Ve(i)}catch(a){let l=a instanceof Error?a.message:"Validation failed";if(r!==this.generation)return false;if(Z(a)){if(Ce(a)){let u=Math.min(Se(a,W,Ie)*2**this.retryAttempt,W);return this.retryAttempt+=1,await this.saveHold({...this.hold,backoffUntil:h()+u}),r!==this.generation?false:this.standDown(i,r,l,u)}return this.state.isValidating=false,this.cachedLicense&&this.cachedLicense.licenseKey===i&&A(this.cachedLicense)&&this.isCacheValid(this.cachedLicense)?(this.applyTier(k(this.cachedLicense)),this.state.error=null,this.state.errorKind=null,this.state.expiresAt=this.cachedLicense.expiresAt?new Date(this.cachedLicense.expiresAt):null,this.setVerifiedAt(this.cachedLicense.cachedAt),this.keyTier()!=="pro"&&this.scheduleRetry(i),this.emit({type:"validated",isPro:this.state.isPro}),true):(this.state.error=l,this.state.errorKind="transport",this.scheduleRetry(i),this.emit({type:"error",isPro:this.state.isPro,error:l}),false)}return this.state.isValidating=false,this.state.error=l,this.state.errorKind="verdict",this.emit({type:"error",isPro:false,error:l}),false}try{if(r!==this.generation)return false;let a=Fe(o),l=o.data?.relationships?.product?.data?.id;if((!l||l===L.productId)&&a.code==="EXPIRED"&&(ot(o.data)||this.cachedLicense?.licenseKey===i&&A(this.cachedLicense)&&this.isCacheValid(this.cachedLicense))){let K=h(),X=await this.saveCache({licenseKey:i,licenseId:o.data?.id??"",valid:true,isPro:false,tier:"free",expiresAt:null,cachedAt:K,lastValidatedAt:K,fingerprint:this.cachedLicense?.licenseKey===i?this.cachedLicense.fingerprint:void 0},r);return r!==this.generation||!X?false:(this.cachedLicense=X,this.applyTier("free"),this.state.isValidating=false,this.state.expiresAt=null,this.setVerifiedAt(K),this.emit({type:"validated",isPro:false}),true)}if($e(a.code)||!De(o))return this.lock(),this.state.isValidating=false,this.state.error=a.detail||"License could not be verified",this.state.errorKind="verdict",this.emit({type:"error",isPro:false,error:this.state.error}),await this.clearCachedLicense(),await this.saveHold({key:i,code:a.code,detail:this.state.error,verdictAt:h()}),false;if(!o.data)return this.lock(),this.state.isValidating=false,this.state.error=a.detail||"License not found",this.state.errorKind="verdict",this.emit({type:"error",isPro:false,error:this.state.error}),await this.clearCachedLicense(),false;let u=at(o.data),f=o.data.id,P=h(),z=Ue(o)>=Ne,G=U(),Te=G&&!z,Ae=u==="free"&&(z||!G),v=this.cachedLicense?.fingerprint,b=this.cachedLicense?.deviceName,Y=false;if(!v){if(v=await w(this.getOrCreateDeviceFingerprint(),D()),r!==this.generation)return false;b=F(),Y=Te}let C=false;Y&&(this.deviceRegistrationCallback?(this.pendingRegistration={licenseId:f,licenseKey:i,fingerprint:v},this.deviceRegistrationCallback({fingerprint:v,defaultName:b}),C=true):this.registerDeviceAsync(f,i,v,b));let S={licenseKey:i,licenseId:f,valid:true,isPro:u==="pro",tier:u,expiresAt:o.data.attributes.expiry??null,cachedAt:P,lastValidatedAt:P,fingerprint:C?void 0:v,deviceName:C?void 0:b,quiet:Ae||void 0},J=await this.saveCache(S,r);return r!==this.generation||!J||(this.cachedLicense=J,this.applyTier(u),this.state.isValidating=false,this.state.expiresAt=S.expiresAt?new Date(S.expiresAt):null,this.setVerifiedAt(P),this.hold&&await this.saveHold(null),r!==this.generation)?false:(this.retryAttempt=0,this.emit({type:"validated",isPro:this.state.isPro}),true)}catch(a){let l=a instanceof Error?a.message:"Validation failed";return r!==this.generation||(this.state.isValidating=false,this.state.error=l,this.state.errorKind="verdict",this.emit({type:"error",isPro:false,error:l})),false}}scheduleRetry(e){this.cancelRetry();let t=Le[this.retryAttempt];if(t===void 0)return;this.retryAttempt+=1;let i=this.generation;this.retryTimer=setTimeout(()=>{this.retryTimer=null,i===this.generation&&(this.state.isValidating||this.setLicenseKey(e,{force:true,isRetry:true}))},t),typeof d<"u"&&d&&(globalThis.__LICENSE_MANAGER_RETRY_TIMER__=this.retryTimer)}async admitServiceKey(e,t){let i=await Pt(e,{origin:E.origin});if(t!==this.generation)return false;if(!i.ok)return this.lock(),this.state.isValidating=false,this.state.error=i.detail,this.state.errorKind=i.reason==="network"?"transport":"verdict",this.emit({type:"error",isPro:false,error:i.detail}),i.reason==="network"&&this.scheduleRetry(e),false;let r=i.claims.exp*1e3;return this.applyTier(i.claims.tier==="free"?"free":"pro"),this.state.isValidating=false,this.state.expiresAt=new Date(r),this.setVerifiedAt(h()),this.retryAttempt=0,this.scheduleRetryIn(e,Math.max(6e4,r-3600*1e3-h())),this.emit({type:"validated",isPro:this.isPro()}),true}admitDevToken(e){let t=St(e);if(!t.ok||!U()){let r=t.ok?Kt:t.message;return this.lock(),this.state.isValidating=false,this.state.error=r,this.state.errorKind="verdict",this.emit({type:"error",isPro:false,error:r}),false}let i=h();return this.applyTier(t.claims.tier==="free"?"free":"pro"),this.state.isValidating=false,this.state.expiresAt=new Date(t.claims.exp*1e3),this.setVerifiedAt(Math.min(i,t.claims.iat*1e3)),this.retryAttempt=0,this.emit({type:"validated",isPro:this.isPro()}),true}async admitToken(e,t){let i=nt(e);if(t!==this.generation)return false;if(!i)return this.lock(),this.state.isValidating=false,this.state.error="This key is not valid. Check that it was copied completely.",this.state.errorKind="verdict",this.emit({type:"error",isPro:false,error:this.state.error}),await this.clearCachedLicense(),false;let r=h(),s=this.cachedLicense?.fingerprint??await w(this.getOrCreateDeviceFingerprint(),D());if(t!==this.generation)return false;let n=await this.saveCache({licenseKey:e,licenseId:`token:${i.accountHash}`,valid:true,isPro:false,tier:"free",expiresAt:null,cachedAt:r,lastValidatedAt:r,fingerprint:s,deviceName:this.cachedLicense?.deviceName??F(),quiet:true},t);return t!==this.generation||!n?false:(this.cachedLicense=n,this.applyTier("free"),this.state.isValidating=false,this.state.expiresAt=null,this.setVerifiedAt(r),this.retryAttempt=0,this.emit({type:"validated",isPro:false}),true)}standDown(e,t,i,r){if(t!==this.generation)return false;this.state.isValidating=false;let s=this.cachedLicense;return s&&s.licenseKey===e&&A(s)&&this.isCacheValid(s)?(this.applyTier(k(s)),this.state.error=null,this.state.errorKind=null,this.state.expiresAt=s.expiresAt?new Date(s.expiresAt):null,this.setVerifiedAt(s.cachedAt),this.keyTier()!=="pro"&&this.scheduleRetryIn(e,r),this.emit({type:"validated",isPro:this.state.isPro}),true):(this.state.error=i,this.state.errorKind="transport",this.scheduleRetryIn(e,r),this.emit({type:"error",isPro:this.state.isPro,error:i}),false)}scheduleRetryIn(e,t){this.cancelRetry();let i=this.generation;this.retryTimer=setTimeout(()=>{this.retryTimer=null,i===this.generation&&(this.state.isValidating||this.setLicenseKey(e,{force:true,isRetry:true}))},Math.max(1,Math.min(t,2147483647))),typeof d<"u"&&d&&(m.__LICENSE_MANAGER_RETRY_TIMER__=this.retryTimer)}cancelRetry(){this.retryTimer&&(clearTimeout(this.retryTimer),this.retryTimer=null)}async clearLicense(){this.generation+=1,this.cancelRetry(),this.retryAttempt=0,this.configuredKey=null,this.state.licenseKey=null,this.lock(),this.state.expiresAt=null,this.state.error=null,this.state.errorKind=null,this.cachedLicense=null,this.pendingRegistration=null,this.state.isValidating=false,this.emit({type:"deactivated",isPro:false}),await this.clearCachedLicense(),this.hold?.verdictAt!==void 0&&await this.saveHold(this.hold.backoffUntil?{backoffUntil:this.hold.backoffUntil}:null)}applyTier(e){this.state.tier=e,this.state.tierSource="key",this.state.isPro=e==="pro"}lock(){this.state.tier="free",this.state.tierSource="none",this.state.isPro=false,this.verifiedAt=null,this.expiryTimer&&clearTimeout(this.expiryTimer),this.expiryTimer=null}getTier(){return this.credential().tier}credential(){let e=this.keyTier(),t=this.sessionTier();return t!==null&&(!this.hasKeyAccess()||t==="pro"&&e!=="pro")?{source:"session",tier:t}:{source:this.state.tierSource,tier:e}}keyTier(){return!this.hasKeyAccess()||this.state.expiresAt&&h()>=this.state.expiresAt.getTime()?"free":this.state.tier}sessionTier(){let e=E.getStatus();return e.state!=="active"?null:e.claims.tier==="free"?"free":"pro"}isPro(){return this.getTier()==="pro"}hasEntitlement(e){return this.isPro()}getState(){let{source:e,tier:t}=this.credential();return{...this.state,tier:t,tierSource:e,isPro:t==="pro",access:this.getAccountAccess()}}getAccountAccess(){let e=this.getKeyAccess();if(e.status==="admitted")return e;let t=E.getStatus();return t.state==="active"?{status:"admitted",reason:null,validUntil:t.validUntil}:e}getKeyAccess(){return ue({initialized:this.state.isInitialized,validating:this.state.isValidating,key:this.state.licenseKey,tierSource:this.state.tierSource,verifiedAt:this.verifiedAt})}hasAccountAccess(){return this.getAccountAccess().status==="admitted"}hasKeyAccess(){return this.getKeyAccess().status==="admitted"}setVerifiedAt(e){this.verifiedAt=e,this.expiryTimer&&clearTimeout(this.expiryTimer);let t=e+R,i=this.state.expiresAt?.getTime(),r=(i&&i>h()?Math.min(t,i):t)-h();this.expiryTimer=setTimeout(()=>{this.expiryTimer=null,this.verifiedAt===e&&(this.emit({type:"validated",isPro:this.isPro()}),h()<t&&this.setVerifiedAt(e))},Math.max(1,Math.min(r,2147483647))),typeof d<"u"&&d&&(m.__LICENSE_MANAGER_EXPIRY_TIMER__=this.expiryTimer)}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}onDeviceRegistrationNeeded(e){return this.deviceRegistrationCallback=e,()=>{this.deviceRegistrationCallback=null}}async completeDeviceRegistration(e){if(!this.pendingRegistration){console.warn("[Buoy] No pending device registration");return}let{licenseId:t,licenseKey:i,fingerprint:r}=this.pendingRegistration,s=this.generation,n=e.trim()||F(),c=re();try{await ee(t,i,r,n,c)}catch(o){let a=o instanceof Error?o.message:String(o);if(!(a==="FINGERPRINT_TAKEN"||a==="MACHINE_LIMIT_EXCEEDED"))throw console.warn("[Buoy] Device registration failed:",a),o}if(s===this.generation){if(this.cachedLicense?.licenseKey===i){let o=await this.saveCache({...this.cachedLicense,fingerprint:r,deviceName:n},s);if(s!==this.generation)return;o&&(this.cachedLicense=o)}this.pendingRegistration=null}}emit(e){[...this.listeners].forEach(t=>{try{t(e)}catch(i){console.warn("[React Buoy] License listener error:",i)}})}isCacheValid(e){let t=h()-e.cachedAt;return!(!e.valid||!Number.isFinite(e.cachedAt)||t<0||t>=R)}isCacheFresh(e){let t=this.isQuiet(e)?Pe:xe;return h()-(e.lastValidatedAt??0)<t}isQuiet(e){return e.quiet!==void 0?e.quiet:k(e)==="free"&&!U()}async loadHold(){if(this.hold!==void 0)return this.hold;try{let e=await(await g()).getItem(V),t=e?JSON.parse(e):null;this.hold=t&&typeof t=="object"?t:null}catch{this.hold=null}return this.hold}async saveHold(e){this.hold=e;try{let t=await g();e?await t.setItem(V,JSON.stringify(e)):await t.removeItem(V)}catch{}}async persistCache(e){let t=oe(e);return await(await g()).setItem(M,JSON.stringify(t)),t}saveCache(e,t){let i=this.persistence.catch(()=>{}).then(async()=>{if(t!==this.generation)return null;let r=await this.persistCache(e);return t===this.generation?r:null});return this.persistence=i,w(i,oe(e))}async loadCachedLicense(){try{await this.persistence.catch(()=>{});let e=await(await g()).getItem(M);return e?JSON.parse(e):null}catch(e){return console.warn("[Buoy] Error loading cached license:",e),null}}getOrCreateDeviceFingerprint(){return this.fingerprintPromise||(this.fingerprintPromise=(async()=>{let e=await g(),t=await e.getItem(O);if(t)return t;let i=this.cachedLicense?.fingerprint||D();return await e.setItem(O,i),i})()),this.fingerprintPromise}async clearCachedLicense(){this.cachedLicense=null;let e=this.persistence.catch(()=>{}).then(async()=>{await(await g()).removeItem(M)});this.persistence=e,await w(e.catch(()=>{}),void 0)}registerDeviceAsync(e,t,i,r){let s=re();ee(e,t,i,r,s).catch(n=>{n.message!=="FINGERPRINT_TAKEN"&&n.message!=="MACHINE_LIMIT_EXCEEDED"&&console.warn("[Buoy] Device registration failed (non-blocking):",n.message)})}validateInBackground(e){this.setLicenseKey(e,{force:true,isRetry:true})}refreshAccess(){this.emit({type:"validated",isPro:this.isPro()})}startRevalidationTimer(){this.removeForegroundListener||(this.removeForegroundListener=lt(()=>this.refreshAccess()),typeof d<"u"&&d&&(m.__LICENSE_MANAGER_FOREGROUND_OFF__=this.removeForegroundListener)),this.revalidationTimer&&clearInterval(this.revalidationTimer),this.revalidationTimer=setInterval(()=>{if(!this.state.licenseKey||this.state.isValidating)return;let e=this.cachedLicense;e&&e.licenseKey===this.state.licenseKey&&this.isCacheFresh(e)||this.validateInBackground(this.state.licenseKey)},be),typeof d<"u"&&d&&(globalThis.__LICENSE_MANAGER_TIMER__=this.revalidationTimer)}stopRevalidationTimer(){this.removeForegroundListener?.(),this.removeForegroundListener=null,this.expiryTimer&&clearTimeout(this.expiryTimer),this.expiryTimer=null,this.revalidationTimer&&(clearInterval(this.revalidationTimer),this.revalidationTimer=null),this.cancelRetry()}async forceReregister(){this.cachedLicense&&(this.cachedLicense.fingerprint=void 0,this.cachedLicense.deviceName=void 0),this.fingerprintPromise=null,await this.clearCachedLicense();try{await(await g()).removeItem(O)}catch{}}},Ot=new Mt,m=globalThis;typeof d<"u"&&d&&(m.__LICENSE_MANAGER_FOREGROUND_OFF__?.(),m.__LICENSE_MANAGER_FOREGROUND_OFF__=void 0,m.__LICENSE_MANAGER_EXPIRY_TIMER__&&clearTimeout(m.__LICENSE_MANAGER_EXPIRY_TIMER__),m.__LICENSE_MANAGER_TIMER__&&clearInterval(m.__LICENSE_MANAGER_TIMER__),m.__LICENSE_MANAGER_RETRY_TIMER__&&(clearTimeout(m.__LICENSE_MANAGER_RETRY_TIMER__),m.__LICENSE_MANAGER_RETRY_TIMER__=void 0));export{h as a,T as b,Z as c,ce as d,ue as e,p as f,E as g,B as h,ve as i,Ot as j};/*!
|
|
2
|
-
* PROPRIETARY — Buoy Pro license enforcement. NOT open source.
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) Buoy. All rights reserved. Licensed under the Buoy EULA
|
|
5
|
-
* (https://buoy.gg/terms), not an OSS license.
|
|
6
|
-
*
|
|
7
|
-
* This file configures the technological measure that controls access to paid
|
|
8
|
-
* Buoy Pro features. Modifying, patching, aliasing, stubbing, or otherwise
|
|
9
|
-
* altering it — including repointing `apiUrl` at a stand-in license server — so
|
|
10
|
-
* that Pro features unlock without a valid license is a breach of the EULA and,
|
|
11
|
-
* in the United States, circumvention of an access control under 17 U.S.C.
|
|
12
|
-
* § 1201, which applies whether or not any code is copied.
|
|
13
|
-
*
|
|
14
|
-
* Pro is $9/mo, and is free every weekend for anyone holding a key —
|
|
15
|
-
* including a free one (`npx buoy login`). Buy a key at
|
|
16
|
-
* https://buoy.gg or use it free on Saturday and Sunday.
|
|
17
|
-
*//*!
|
|
18
|
-
* PROPRIETARY — Buoy Pro license enforcement. NOT open source.
|
|
19
|
-
*
|
|
20
|
-
* Copyright (c) Buoy. All rights reserved. Licensed under the Buoy EULA
|
|
21
|
-
* (https://buoy.gg/terms), not an OSS license.
|
|
22
|
-
*
|
|
23
|
-
* This file is part of the technological measure that controls access to paid
|
|
24
|
-
* Buoy Pro features. Modifying, patching, aliasing, stubbing, or otherwise
|
|
25
|
-
* altering it so that Pro features unlock without a valid license is a breach
|
|
26
|
-
* of the EULA and, in the United States, circumvention of an access control
|
|
27
|
-
* under 17 U.S.C. § 1201 — which applies whether or not any code is copied.
|
|
28
|
-
*
|
|
29
|
-
* Pro is $9/mo, and is free every weekend for anyone holding a key —
|
|
30
|
-
* including a free one (`npx buoy login`). Buy a key at
|
|
31
|
-
* https://buoy.gg or use it free on Saturday and Sunday.
|
|
32
|
-
*//*!
|
|
33
|
-
* PROPRIETARY — Buoy Pro license enforcement. NOT open source.
|
|
34
|
-
*
|
|
35
|
-
* Copyright (c) Buoy. All rights reserved. Licensed under the Buoy EULA
|
|
36
|
-
* (https://buoy.gg/terms), not an OSS license.
|
|
37
|
-
*//*!
|
|
38
|
-
* PROPRIETARY — Buoy Pro license enforcement. NOT open source.
|
|
39
|
-
*
|
|
40
|
-
* Copyright (c) Buoy. All rights reserved. Licensed under the Buoy EULA
|
|
41
|
-
* (https://buoy.gg/terms), not an OSS license.
|
|
42
|
-
*
|
|
43
|
-
* This file is part of the technological measure that controls access to paid
|
|
44
|
-
* Buoy Pro features: it decides which tier a validated key grants. Modifying,
|
|
45
|
-
* patching, aliasing, stubbing, or otherwise altering it so that Pro features
|
|
46
|
-
* unlock without a valid license is a breach of the EULA and, in the United
|
|
47
|
-
* States, circumvention of an access control under 17 U.S.C. § 1201 — which
|
|
48
|
-
* applies whether or not any code is copied.
|
|
49
|
-
*
|
|
50
|
-
* Pro is $9/mo, and is free every weekend for anyone holding a key —
|
|
51
|
-
* including a free one (`npx buoy login`). Buy a key at
|
|
52
|
-
* https://buoy.gg or use it free on Saturday and Sunday.
|
|
53
|
-
*//*!
|
|
54
|
-
* PROPRIETARY — Buoy license enforcement. NOT open source.
|
|
55
|
-
*
|
|
56
|
-
* Copyright (c) Buoy. All rights reserved. Licensed under the Buoy EULA
|
|
57
|
-
* (https://buoy.gg/terms), not an OSS license.
|
|
58
|
-
*//*!
|
|
59
|
-
* PROPRIETARY — Buoy Pro license enforcement. NOT open source.
|
|
60
|
-
*
|
|
61
|
-
* Copyright (c) Buoy. All rights reserved. Licensed under the Buoy EULA
|
|
62
|
-
* (https://buoy.gg/terms), not an OSS license.
|
|
63
|
-
*
|
|
64
|
-
* This file is the technological measure that controls access to paid Buoy Pro
|
|
65
|
-
* features. Modifying, patching, aliasing, stubbing, or otherwise altering it
|
|
66
|
-
* so that Pro features unlock without a valid license is a breach of the EULA
|
|
67
|
-
* and, in the United States, circumvention of an access control under
|
|
68
|
-
* 17 U.S.C. § 1201 — which applies whether or not any code is copied.
|
|
69
|
-
*
|
|
70
|
-
* Pro is $9/mo, and is free every weekend for anyone holding a key —
|
|
71
|
-
* including a free one (`npx buoy login`). Buy a key at
|
|
72
|
-
* https://buoy.gg or use it free on Saturday and Sunday.
|
|
73
|
-
*/
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use client";var d=process.env.NODE_ENV!=="production";typeof window<"u"&&typeof globalThis.global>"u"&&(globalThis.global=globalThis);var L=new Map,ve={async getItem(e){try{return localStorage.getItem(e)??L.get(e)??null}catch{return L.get(e)??null}},async setItem(e,t){L.set(e,t);try{localStorage.setItem(e,t)}catch{}},async removeItem(e){L.delete(e);try{localStorage.removeItem(e)}catch{}}};async function g(){return ve}var x={accountId:"b0eba0e8-e904-4906-b644-38f9aab57bed",productId:"bf67cb43-eeef-40ca-b308-e6e1b22c0eaa",apiUrl:"https://buoy.gg/api/license"},Te="3b546fc717a62683f3236c70167899a271bee3ffc04df6ec1eea60a394a2f1e9",Ae="",I={free:"394e3351-1249-4f73-807a-703408604c0e",solo:"fa5d3c8f-5379-40f1-b63e-ab8a974b2f28",business:"690c2212-8e54-426f-b4b4-002ee1c0ae2b"},R=720*60*60*1e3,_e=1440*60*1e3,O="buoy-gg-license",M="buoy-gg-device-fingerprint",Ee=3600*1e3,be=[5*1e3,20*1e3,60*1e3,300*1e3,900*1e3],ke=60*1e3,Y=3600*1e3,Le=1440*60*1e3,xe=50,Ie=R,V="buoy-gg-license-hold";function h(){let e=globalThis.__buoyRealNow;return typeof e=="function"?e():Date.now()}var{apiUrl:X}=x,T=class extends Error{constructor(e,t,i=null){super(e);this.isTransient=true;this.name="LicenseTransportError",this.status=t,this.retryAfterMs=i}};function Re(e){let t=e?.status;return t===429||t===402}function Ne(e,t,i){return e.status===402?t:e.retryAfterMs??i}function Ce(e){let t=s=>{try{return e.headers?.get?.(s)??null}catch{return null}},i=t("Retry-After");if(i){let s=Number(i);if(Number.isFinite(s)&&s>=0)return s*1e3;let n=Date.parse(i);if(Number.isFinite(n))return Math.max(0,n-h())}let r=Number(t("X-RateLimit-Reset"));return Number.isFinite(r)&&r>0?Math.max(0,r*1e3-h()):null}function W(e){return e instanceof T||e instanceof TypeError?true:typeof e=="object"&&e!==null&&e.isTransient===true}async function Pe(e){try{return(await e.json()).errors?.[0]?.detail||`HTTP ${e.status}`}catch{return`HTTP ${e.status}`}}function q(){return{"Content-Type":"application/vnd.api+json",Accept:"application/vnd.api+json"}}async function Se(e,t){let i=`${X}/validate`,r={meta:{key:e}},s;try{s=await fetch(i,{signal:t,method:"POST",headers:q(),body:JSON.stringify(r)})}catch(n){throw new T(n instanceof Error?n.message:"Network request failed",null)}if(!s.ok)throw new T(await Pe(s),s.status,s.status===429?Ce(s):null);try{let n=await s.json();if(!n||typeof n!="object"||typeof n.meta?.valid!="boolean"||typeof n.meta?.code!="string"||!n.meta.code)throw new Error("Missing license verdict");return n}catch{throw new T("License server returned an unreadable response",s.status)}}async function Ke(e){let t=typeof AbortController=="function"?new AbortController:null,i;try{return await Promise.race([Se(e,t?.signal),new Promise((r,s)=>{i=setTimeout(()=>{s(new T("License verification timed out. Please retry.",null)),t?.abort()},15e3)})])}finally{i&&clearTimeout(i)}}function Oe(e){if(!e.data)return false;let t=e.data.relationships?.product?.data?.id;return t&&t!==x.productId?false:e.meta.valid&&e.meta.code==="VALID"?true:["OVERDUE","NO_MACHINE","NO_MACHINES","TOO_MANY_MACHINES","TOO_MANY_CORES","TOO_MANY_PROCESSES","FINGERPRINT_SCOPE_MISMATCH","HEARTBEAT_NOT_STARTED","HEARTBEAT_DEAD"].includes(e.meta.code)}function Me(e){let t=e.data?.relationships?.machines?.meta?.count;return typeof t=="number"&&Number.isFinite(t)?t:0}async function Z(e,t,i,r,s){let n=`${X}/machines`,c=await fetch(n,{method:"POST",headers:q(),body:JSON.stringify({licenseId:e,licenseKey:t,fingerprint:i,name:r,metadata:s||{}})});if(!c.ok){let o=await c.json(),a=o.errors?.[0]?.code;if(a==="FINGERPRINT_TAKEN")throw new Error("FINGERPRINT_TAKEN");if(a==="MACHINE_LIMIT_EXCEEDED")throw new Error("MACHINE_LIMIT_EXCEEDED");let l=o.errors?.[0]?.detail||`HTTP ${c.status}`;throw new Error(l)}return c.json()}function Ve(e){let{meta:t,data:i}=e;return{valid:t.valid,code:t.code,detail:t.detail,metadata:i?.attributes?.metadata}}function De(e){return["NOT_FOUND","SUSPENDED","EXPIRED","BANNED","PRODUCT_SCOPE_MISMATCH"].includes(e)}function D(){return typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}function Q(){if(typeof d<"u")return d;try{if(typeof navigator<"u"&&/electron/i.test(navigator.userAgent))return true}catch{}return typeof process<"u"&&process.env.NODE_ENV!=="production"}function ee(){if(typeof navigator>"u")return"unknown";let e=navigator.userAgent.toLowerCase(),t=navigator.platform?.toLowerCase()||"";return e.includes("electron")?t.includes("mac")||e.includes("mac")?"electron-macos":t.includes("win")||e.includes("win")?"electron-windows":t.includes("linux")||e.includes("linux")?"electron-linux":"electron":t.includes("mac")||e.includes("mac")?"macos":t.includes("win")||e.includes("win")?"windows":t.includes("linux")||e.includes("linux")?"linux":/iphone|ipad|ipod/.test(e)?"ios-web":e.includes("android")?"android-web":"web"}function Ue(){if(typeof navigator>"u")return"unknown";let e=navigator.userAgent,t=e.match(/Mac OS X ([\d_.]+)/);if(t)return t[1].replace(/_/g,".");let i=e.match(/Windows NT ([\d.]+)/);return i?{"10.0":"10/11","6.3":"8.1","6.2":"8","6.1":"7"}[i[1]]||i[1]:e.includes("Linux")?"Linux":"unknown"}function te(){if(typeof navigator>"u")return{name:"unknown",version:"unknown"};let e=navigator.userAgent,t=e.match(/Electron\/([\d.]+)/);if(t)return{name:"Electron",version:t[1]};let i=e.match(/Chrome\/([\d.]+)/);if(i&&!e.includes("Edg"))return{name:"Chrome",version:i[1]};let r=e.match(/Edg\/([\d.]+)/);if(r)return{name:"Edge",version:r[1]};let s=e.match(/Firefox\/([\d.]+)/);if(s)return{name:"Firefox",version:s[1]};let n=e.match(/Version\/([\d.]+).*Safari/);return n?{name:"Safari",version:n[1]}:{name:"unknown",version:"unknown"}}function ie(){let e={platform:ee(),osVersion:Ue(),isSimulator:"false"},t=te();e.browser=t.name,e.browserVersion=t.version,typeof window<"u"&&window.screen&&(e.screenResolution=`${window.screen.width}x${window.screen.height}`),typeof navigator<"u"&&navigator.language&&(e.language=navigator.language);try{e.timezone=Intl.DateTimeFormat().resolvedOptions().timeZone}catch{}return e}function U(){let e=ee(),t=te();if(e.startsWith("electron")){let i=e.replace("electron-","").replace("electron","Desktop");return`${i.charAt(0).toUpperCase()+i.slice(1)} App`}return t.name!=="unknown"?`${t.name} Browser`:"Web Browser"}var Fe=["v1"],He="buoy.gg/pro:9f3c1d7a4b2e:license-cache";function re(e,t){let i=t>>>0;for(let r=0;r<e.length;r++)i^=e.charCodeAt(r),i=Math.imul(i,16777619)>>>0;return i>>>0}function $e(e,t){let i=[t,e.licenseKey,e.licenseId,e.isPro?"1":"0",e.expiresAt??"",String(e.cachedAt)];return t!=="v1"&&i.push(e.tier??""),i.push(He),i.join("\0")}function se(e,t){let i=$e(e,t),r=re(i,2166136261),s=re(i,2135587861);return`${t}.${r.toString(16)}${s.toString(16)}`}function ne(e){return se(e,"v2")}function ae(e){return{...e,sig:ne(e)}}function A(e){return!e||typeof e.sig!="string"||e.sig.length===0?false:e.sig===ne(e)?true:Fe.some(t=>e.sig.startsWith(`${t}.`)&&e.sig===se(e,t))}import je from"tweetnacl";var ze=1,Be=1,Ge="buoy-free-token-v1:",Je=22,Ye=64,oe=/^BUOY1-([A-Z2-7]+)-([A-Z2-7]+)$/;function le(e){return oe.test(e.trim().toUpperCase())}var Xe="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";function ce(e){let t=[],i=0,r=0;for(let s of e){let n=Xe.indexOf(s);if(n===-1)return null;r=r<<5|n,i+=5,i>=8&&(t.push(r>>>i-8&255),i-=8)}return new Uint8Array(t)}function We(e){let t=e.trim().toLowerCase(),i=new Uint8Array(t.length/2);for(let r=0;r<i.length;r+=1)i[r]=parseInt(t.slice(r*2,r*2+2),16);return i}function qe(e){let t="";for(let i of e)t+=i.toString(16).padStart(2,"0");return t}function Ze(e){if(typeof TextEncoder<"u")return new TextEncoder().encode(e);let t=new Uint8Array(e.length);for(let i=0;i<e.length;i+=1)t[i]=e.charCodeAt(i)&255;return t}function Qe(e,t){let i=new Uint8Array(e.length+t.length);return i.set(e,0),i.set(t,e.length),i}function et(e){return Qe(Ze(Ge),e)}var tt=Te;function it(e,t=tt){let i=oe.exec(e.trim().toUpperCase());if(!i)return null;let r=ce(i[1]),s=ce(i[2]);if(!r||!s||r.length!==Je||s.length!==Ye||r[0]!==ze||r[1]!==Be)return null;try{if(!je.sign.detached.verify(et(r),s,We(t)))return null}catch{return null}return{tier:"free",issuedAt:((r[2]<<24>>>0)+(r[3]<<16)+(r[4]<<8)+r[5])*1e3,accountHash:qe(r.slice(6,22))}}function rt(e){let t=e.relationships?.policy?.data?.id;return t===I.free?"free":t===I.solo||t===I.business?"pro":e.attributes?.metadata?.plan==="free"?"free":"pro"}function st(e){if(!e)return false;let t=e.relationships?.product?.data?.id;if(t)return t===x.productId;let i=e.relationships?.policy?.data?.id;return Object.values(I).some(r=>r===i)}function he(e,t=h()){let i=e.verifiedAt!==null&&Number.isFinite(e.verifiedAt)&&e.verifiedAt<=t?e.verifiedAt+R:null;return e.initialized&&e.key&&e.tierSource!=="none"&&i!==null&&t<i?{status:"admitted",reason:null,validUntil:i}:i!==null&&t>=i?{status:"locked",reason:"verification_expired",validUntil:i}:!e.initialized||e.validating?{status:"initializing",reason:"checking",validUntil:i}:{status:"locked",reason:i!==null&&t>=i?"verification_expired":"account_required",validUntil:i}}function nt(e){if(typeof window>"u"||typeof window.addEventListener!="function")return()=>{};let t=()=>{document.hidden||e()};return window.addEventListener("focus",e),document.addEventListener("visibilitychange",t),()=>{window.removeEventListener("focus",e),document.removeEventListener("visibilitychange",t)}}import at from"tweetnacl";var ot="buoys1",lt="buoy-session-v1:",ue=1,F=60,ct=64,ht=["free","pro","business"],m="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";function H(e){let t="",i=0;for(;i+2<e.length;i+=3){let s=e[i]<<16|e[i+1]<<8|e[i+2];t+=m[s>>>18&63]+m[s>>>12&63]+m[s>>>6&63]+m[s&63]}let r=e.length-i;if(r===1){let s=e[i]<<16;t+=m[s>>>18&63]+m[s>>>12&63]}else if(r===2){let s=e[i]<<16|e[i+1]<<8;t+=m[s>>>18&63]+m[s>>>12&63]+m[s>>>6&63]}return t}function de(e){if(!/^[A-Za-z0-9_-]*$/.test(e)||e.length%4===1)return null;let t=[],i=0,r=0;for(let s of e)r=r<<6|m.indexOf(s),i+=6,i>=8&&(t.push(r>>>i-8&255),i-=8);return new Uint8Array(t)}function ut(e){if(typeof TextEncoder<"u")return new TextEncoder().encode(e);let t=unescape(encodeURIComponent(e)),i=new Uint8Array(t.length);for(let r=0;r<t.length;r+=1)i[r]=t.charCodeAt(r);return i}function dt(e){try{if(typeof TextDecoder<"u")return new TextDecoder("utf-8",{fatal:true}).decode(e);let t="";for(let i of e)t+=String.fromCharCode(i);return decodeURIComponent(escape(t))}catch{return null}}function ft(e){let t=e.trim().toLowerCase(),i=new Uint8Array(t.length/2);for(let r=0;r<i.length;r+=1)i[r]=parseInt(t.slice(r*2,r*2+2),16);return i}function pt(e){return ut(lt+e)}function _(e,t=256){return typeof e=="string"&&e.length>0&&e.length<=t}function fe(e){return typeof e=="number"&&Number.isInteger(e)&&e>0}function yt(e){if(!e||typeof e!="object"||Array.isArray(e))return null;let t=e;return!_(t.sid)||!_(t.sub)||!_(t.aud,512)||t.team!==null&&!_(t.team)||!ht.includes(t.tier)||t.role!==void 0&&!_(t.role,64)||t.tools!==void 0&&(!Array.isArray(t.tools)||t.tools.length>256||!t.tools.every(i=>_(i,64)))||!fe(t.iat)||!fe(t.exp)||t.exp<=t.iat?null:{v:ue,sid:t.sid,sub:t.sub,team:t.team,tier:t.tier,...t.role!==void 0?{role:t.role}:{},...t.tools!==void 0?{tools:[...t.tools]}:{},aud:t.aud,iat:t.iat,exp:t.exp}}var mt=Ae;function pe(e,t){let i=t.publicKeyHex??mt;if(!i)return{ok:false,reason:"no-key"};let r=typeof e=="string"?e.split("."):[];if(r.length!==3||r[0]!==ot)return{ok:false,reason:"malformed"};let[,s,n]=r,c=de(s),o=de(n);if(!c||!o||o.length!==ct)return{ok:false,reason:"malformed"};try{if(!at.sign.detached.verify(pt(s),o,ft(i)))return{ok:false,reason:"signature"}}catch{return{ok:false,reason:"signature"}}let a=dt(c),l;try{l=a===null?null:JSON.parse(a)}catch{return{ok:false,reason:"malformed"}}if(!l||typeof l!="object"||l.v!==ue)return{ok:false,reason:l&&typeof l=="object"?"version":"malformed"};let u=yt(l);if(!u)return{ok:false,reason:"claims"};if(u.aud!==t.audience)return{ok:false,reason:"audience"};if(t.ignoreTime)return{ok:true,claims:u};let f=Math.floor((t.nowMs??h())/1e3);return f>=u.exp+F?{ok:false,reason:"expired"}:u.iat>f+F?{ok:false,reason:"not-yet-valid"}:{ok:true,claims:u}}var gt="@buoy/session:",N=10080*60*1e3,ye=360*60*1e3,wt=300*1e3,vt=15e3,Tt="https://buoy.gg",At="buoy:signin",_t=600*1e3,p=class extends Error{constructor(e,t){super(t);this.code=e;this.name="SessionError"}};function Et(){let e=globalThis;return{fetch:(t,i)=>fetch(t,i),storage:g,now:h,random:t=>{let i=new Uint8Array(t);if(!e.crypto?.getRandomValues)throw new p("not_configured","This platform has no secure random source.");return e.crypto.getRandomValues(i)},sha256:async t=>{if(!e.crypto?.subtle)throw new p("not_configured","Sign-in needs a secure page (https or localhost).");return new Uint8Array(await e.crypto.subtle.digest("SHA-256",t))},openPopup:()=>{if(!e.window?.open)return null;let t=480,i=640,r=Math.max(0,(e.window.screenX??0)+((e.window.outerWidth??t)-t)/2),s=Math.max(0,(e.window.screenY??0)+((e.window.outerHeight??i)-i)/2);return e.window.open("about:blank","buoy-signin",`popup,width=${t},height=${i},left=${r},top=${s}`)},onMessage:t=>{if(!e.window?.addEventListener)return()=>{};let i=r=>t({origin:r.origin,data:r.data});return e.window.addEventListener("message",i),()=>e.window?.removeEventListener("message",i)},withLock:(t,i)=>e.navigator?.locks?e.navigator.locks.request(t,i):i(),watch:t=>{let i=e.window;if(!i?.addEventListener)return()=>{};let r=n=>t.storage(n.key),s=()=>{i.document?.visibilityState!=="hidden"&&t.wake()};return i.addEventListener("storage",r),i.addEventListener("online",t.wake),i.document?.addEventListener?.("visibilitychange",s),()=>{i.removeEventListener("storage",r),i.removeEventListener("online",t.wake),i.document?.removeEventListener?.("visibilitychange",s)}},setTimer:(t,i)=>setTimeout(t,Math.min(i,2147483647)),clearTimer:t=>clearTimeout(t)}}function bt(){let e=globalThis.location;if(!(!e?.origin||!/^https?:$/.test(e.protocol??"")))return e.origin}var kt=class{constructor(e){this.signinOrigin=Tt;this.current=null;this.claims=null;this.listeners=new Set;this.timer=null;this.refreshing=null;this.loaded=null;this.unwatch=null;this.limitTimer=null;this.epoch=0;this.deps=e??Et(),this.audience=bt()}get origin(){return this.signinOrigin}configure(e){e.audience!==void 0&&(this.audience=e.audience),e.signinOrigin!==void 0&&(this.signinOrigin=e.signinOrigin.replace(/\/$/,"")),this.reset()}__setDeps(e){this.deps=e,this.reset()}reset(){this.unwatch?.(),this.unwatch=null,this.epoch+=1,this.limitTimer!==null&&this.deps.clearTimer(this.limitTimer),this.limitTimer=null,this.timer!==null&&this.deps.clearTimer(this.timer),this.timer=null,this.current=null,this.claims=null,this.loaded=null,this.refreshing=null}get storageKey(){return gt+(this.audience??"")}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}notify(){for(let e of[...this.listeners])try{e()}catch(t){console.warn("[Buoy] sign-in listener error:",t)}}getStatus(){let e=this.claims;if(!e)return{state:"signed_out"};let t=e.exp*1e3,i=this.deps.now();return i<(e.iat-F)*1e3?{state:"signed_out"}:i<t?{state:"active",claims:e,grace:false,validUntil:t}:i<t+N?{state:"active",claims:e,grace:true,validUntil:t+N}:{state:"signed_out"}}load(){return this.loaded||(this.loaded=this.loadOnce()),this.loaded}async loadOnce(){if(!this.audience)return;this.unwatch??(this.unwatch=this.deps.watch?.({storage:t=>{(t===null||t===this.storageKey)&&this.sync()},wake:()=>{this.claims&&this.refresh()}})??null);let e=await this.read();e&&this.adopt(e)&&(this.notify(),this.schedule())}async sync(){if(!this.audience)return;let e=await this.read();if(!e){this.current&&this.clearLocal();return}e.refreshToken!==this.current?.refreshToken&&this.adopt(e)&&(this.notify(),this.schedule())}async read(){try{let e=await(await this.deps.storage()).getItem(this.storageKey);if(!e)return null;let t=JSON.parse(e);return t?.v===1&&typeof t.accessToken=="string"&&typeof t.refreshToken=="string"?t:null}catch{return null}}async write(e){let t=await this.deps.storage();e?await t.setItem(this.storageKey,JSON.stringify(e)):await t.removeItem(this.storageKey)}adopt(e){if(!this.audience)return false;let t=pe(e.accessToken,{audience:this.audience,ignoreTime:true,publicKeyHex:this.deps.publicKeyHex}),i=t.ok?t.claims:null;return i?(this.current=e,this.claims=i,true):false}armLimit(){if(this.limitTimer!==null&&this.deps.clearTimer(this.limitTimer),this.limitTimer=null,!this.claims)return;let e=this.claims.exp*1e3,t=this.deps.now(),i=t<e?e:t<e+N?e+N:null;i!==null&&(this.limitTimer=this.deps.setTimer(()=>{this.limitTimer=null,this.notify(),this.armLimit()},i-t))}call(e,t){return new Promise((i,r)=>{let s=this.deps.setTimer(()=>r(new Error("timeout")),vt);this.deps.fetch(e,t).then(n=>{this.deps.clearTimer(s),i(n)},n=>{this.deps.clearTimer(s),r(n)})})}schedule(){if(this.armLimit(),this.timer!==null&&this.deps.clearTimer(this.timer),this.timer=null,!this.claims)return;let e=this.claims.exp*1e3-ye-this.deps.now();this.timer=this.deps.setTimer(()=>{this.timer=null,this.refresh()},Math.max(0,e))}refresh(e=false){return this.refreshing||(this.refreshing=this.deps.withLock(this.lockName,()=>this.refreshLocked(e)).catch(()=>this.retryLater()).finally(()=>{this.refreshing=null})),this.refreshing}get lockName(){return`buoy-session:${this.audience??""}`}async refreshLocked(e){let t=this.epoch,i=await this.read();if(!i){this.current&&this.clearLocal();return}if(i.refreshToken!==this.current?.refreshToken&&this.adopt(i)){this.notify(),this.schedule();return}if(!this.claims)return;if(!e&&this.claims.exp*1e3-this.deps.now()>ye){this.schedule();return}let r,s;try{let n=await this.call(`${this.signinOrigin}/api/auth/refresh`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refresh_token:i.refreshToken,audience:this.audience})});r=n.status,s=await n.json().catch(()=>null)}catch{this.retryLater();return}if(t===this.epoch){if(r===200&&s&&typeof s.access_token=="string"&&typeof s.refresh_token=="string"){let n={v:1,accessToken:s.access_token,refreshToken:s.refresh_token};if(this.adopt(n)){await this.write(n),this.notify(),this.schedule();return}}if(r===400||r===401||r===403){await this.write(null),this.clearLocal();return}this.retryLater()}}retryLater(){this.armLimit(),this.timer!==null&&this.deps.clearTimer(this.timer),this.timer=this.deps.setTimer(()=>{this.timer=null,this.refresh(true)},wt),this.notify()}clearLocal(){this.timer!==null&&this.deps.clearTimer(this.timer),this.timer=null,this.limitTimer!==null&&this.deps.clearTimer(this.limitTimer),this.limitTimer=null,this.current=null,this.claims=null,this.notify()}async signIn(){if(!this.audience)throw new p("not_configured","Sign-in needs a web page or a configured app id.");let e=this.deps.openPopup();if(!e)throw new p("popup_blocked","The browser blocked the sign-in window. Allow pop-ups for this site and try again.");try{return await this.signInWith((t,i)=>new Promise((r,s)=>{e.location.href=t;let n=this.deps.now(),c=null,o=u=>{c!==null&&this.deps.clearTimer(c),a(),u()},a=this.deps.onMessage(u=>{if(u.origin!==this.signinOrigin)return;let f=u.data;!f||f.type!==At||f.state!==i||(typeof f.code=="string"?o(()=>r(f.code)):o(()=>s(new p("access_denied","Sign-in was cancelled."))))}),l=()=>{if(e.closed)return o(()=>s(new p("popup_closed","The sign-in window was closed.")));if(this.deps.now()-n>_t)return o(()=>s(new p("timeout","Sign-in took too long.")));c=this.deps.setTimer(l,500)};c=this.deps.setTimer(l,500)}))}finally{try{e.closed||e.close()}catch{}}}async signInWith(e){let t=this.audience;if(!t)throw new p("not_configured","Sign-in needs a web page or a configured app id.");let i=H(this.deps.random(32)),r=H(this.deps.random(16)),s=H(await this.deps.sha256(new TextEncoder().encode(i))),n=`${this.signinOrigin}/auth/authorize?audience=${encodeURIComponent(t)}&code_challenge=${s}&code_challenge_method=S256&state=${r}`,c=await e(n,r),o;try{o=await this.call(`${this.signinOrigin}/api/auth/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:c,code_verifier:i,audience:t})})}catch{throw new p("network","Buoy could not be reached. Check your connection and try again.")}let a=await o.json().catch(()=>null);if(o.status!==200||!a||typeof a.access_token!="string"||typeof a.refresh_token!="string"){let u=a&&typeof a.error_description=="string"?a.error_description:"Buoy did not accept this sign-in.";throw new p(o.status===503?"unavailable":"rejected",u)}let l={v:1,accessToken:a.access_token,refreshToken:a.refresh_token};if(this.epoch+=1,!this.adopt(l))throw new p("rejected","Buoy sent a sign-in this app could not check.");return await this.write(l),await this.load(),this.notify(),this.schedule(),this.getStatus()}async signOut(){this.epoch+=1;let e=this.current;this.clearLocal();let t=e;try{await this.deps.withLock(this.lockName,async()=>{t=await this.read()??e,await this.write(null)})}catch{await this.write(null).catch(()=>{})}if(t)try{await this.call(`${this.signinOrigin}/api/auth/revoke`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refresh_token:t.refreshToken})})}catch{}}},E=new kt;var Lt="bsk1_",xt="service",It=15e3;function $(e){return e.startsWith(Lt)}function me(e){let t=e.trim();return $(t)?t:t.toUpperCase()}async function Rt(e,t){let i=t.fetch??((a,l)=>fetch(a,l)),r=typeof AbortController<"u"?new AbortController:void 0,s=setTimeout(()=>r?.abort(),It),n,c;try{let a=await i(`${t.origin.replace(/\/$/,"")}/api/auth/service-token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:e}),signal:r?.signal});n=a.status,c=await a.json().catch(()=>null)}catch{return{ok:false,reason:"network",detail:"Buoy could not be reached to check the bot key."}}finally{clearTimeout(s)}if(n>=500||n===429)return{ok:false,reason:"network",detail:"Buoy is busy. The bot key will be checked again soon."};if(n!==200||typeof c?.access_token!="string")return{ok:false,reason:"rejected",detail:typeof c?.error_description=="string"?c.error_description:"This bot key was not accepted."};let o=pe(c.access_token,{audience:xt,nowMs:h(),publicKeyHex:t.publicKeyHex});return o.ok?{ok:true,claims:o.claims}:{ok:false,reason:"rejected",detail:"Buoy sent a token this app could not check."}}async function w(e,t){let i;try{return await Promise.race([e,new Promise(r=>{i=setTimeout(()=>r(t),15e3)})])}finally{i&&clearTimeout(i)}}function b(e){return e.tier==="pro"||e.tier==="free"?e.tier:e.isPro?"pro":"free"}var Nt=class{constructor(){this.state={isInitialized:false,isValidating:false,isPro:false,tier:"free",tierSource:"none",licenseKey:null,error:null,errorKind:null,expiresAt:null};this.listeners=new Set;this.revalidationTimer=null;this.cachedLicense=null;this.fingerprintPromise=null;this.initPromise=null;this.generation=0;this.persistence=Promise.resolve();this.verifiedAt=null;this.expiryTimer=null;this.removeForegroundListener=null;this.sessionUnsubscribe=null;this.retryTimer=null;this.retryAttempt=0;this.deviceRegistrationCallback=null;this.pendingRegistration=null}async initialize(){if(this.initPromise)return this.initPromise;if(!this.state.isInitialized)return this.initPromise=this._doInitialize(),this.initPromise}async _doInitialize(){if(this.state.isInitialized)return;let e=this.generation;this.sessionUnsubscribe||(this.sessionUnsubscribe=E.subscribe(()=>this.emit({type:"validated",isPro:this.isPro()}))),await w(E.load().catch(()=>{}),void 0);try{let t=await w(this.loadCachedLicense(),null);if(e!==this.generation){this.state.isInitialized=true,this.emit({type:"initialized",isPro:this.state.isPro}),this.startRevalidationTimer();return}if(t&&(this.configuredKey===void 0||t.licenseKey===this.configuredKey)){let i=A(t);this.cachedLicense=t,this.state.licenseKey=t.licenseKey,i&&this.isCacheValid(t)?this.applyTier(b(t)):this.lock(),this.state.expiresAt=t.expiresAt?new Date(t.expiresAt):null,i&&this.isCacheValid(t)&&this.setVerifiedAt(t.cachedAt),this.configuredKey===void 0&&t.licenseKey&&!(i&&this.isCacheValid(t)&&this.isCacheFresh(t))&&this.validateInBackground(t.licenseKey)}this.state.isInitialized=true,this.emit({type:"initialized",isPro:this.state.isPro}),this.startRevalidationTimer()}catch(t){console.warn("[React Buoy] License initialization failed:",t),this.state.isInitialized=true,this.emit({type:"initialized",isPro:false})}}async configure(e){if(e===void 0)return await this.initialize(),this.hasAccountAccess();let t=me(e),i=++this.generation;return this.cancelRetry(),this.configuredKey=t||null,this.state.licenseKey!==this.configuredKey&&this.lock(),this.state.licenseKey=this.configuredKey,this.state.isValidating=!!t,this.emit({type:"validating",isPro:this.isPro()}),await this.initialize(),i!==this.generation?false:t?this.setLicenseKey(t):(await this.clearLicense(),false)}async setLicenseKey(e,t){if(!e||e.trim().length===0)return this.state.error="License key is required",this.state.errorKind="verdict",false;let i=me(e),r=++this.generation;if(this.cancelRetry(),t?.isRetry||(this.retryAttempt=0),this.state.licenseKey!==i&&this.lock(),this.state.licenseKey=i,this.state.isValidating=true,this.state.error=null,this.state.errorKind=null,this.emit({type:"validating",isPro:this.isPro()}),le(i))return this.admitToken(i,r);if($(i))return this.admitServiceKey(i,r);if(!this.cachedLicense){let a=await w(this.loadCachedLicense(),null);if(r!==this.generation)return false;a?.licenseKey===i&&(this.cachedLicense=a,A(a)&&this.isCacheValid(a)&&(this.applyTier(b(a)),this.state.expiresAt=a.expiresAt?new Date(a.expiresAt):null,this.setVerifiedAt(a.cachedAt),this.emit({type:"validating",isPro:this.isPro()})))}let s=this.cachedLicense;if(!t?.force&&s&&s.valid&&s.licenseKey===i&&s.fingerprint&&A(s)&&this.isCacheValid(s)&&this.isCacheFresh(s))return this.applyTier(b(s)),this.state.licenseKey=i,this.state.isValidating=false,this.state.error=null,this.state.errorKind=null,this.state.expiresAt=s.expiresAt?new Date(s.expiresAt):null,this.setVerifiedAt(s.cachedAt),this.emit({type:"validated",isPro:this.state.isPro}),true;let n=await w(this.loadHold(),null);if(r!==this.generation)return false;let c=(n?.backoffUntil??0)-h();if(c>0)return this.standDown(i,r,"License server is rate limited; retrying later.",c);if(!t?.force&&n?.key===i&&n.verdictAt!==void 0&&h()-n.verdictAt>=0&&h()-n.verdictAt<Le)return this.lock(),this.state.isValidating=false,this.state.error=n.detail||"License could not be verified",this.state.errorKind="verdict",this.emit({type:"error",isPro:false,error:this.state.error}),false;let o;try{o=await Ke(i)}catch(a){let l=a instanceof Error?a.message:"Validation failed";if(r!==this.generation)return false;if(W(a)){if(Re(a)){let u=Math.min(Ne(a,Y,ke)*2**this.retryAttempt,Y);return this.retryAttempt+=1,await this.saveHold({...this.hold,backoffUntil:h()+u}),r!==this.generation?false:this.standDown(i,r,l,u)}return this.state.isValidating=false,this.cachedLicense&&this.cachedLicense.licenseKey===i&&A(this.cachedLicense)&&this.isCacheValid(this.cachedLicense)?(this.applyTier(b(this.cachedLicense)),this.state.error=null,this.state.errorKind=null,this.state.expiresAt=this.cachedLicense.expiresAt?new Date(this.cachedLicense.expiresAt):null,this.setVerifiedAt(this.cachedLicense.cachedAt),this.keyTier()!=="pro"&&this.scheduleRetry(i),this.emit({type:"validated",isPro:this.state.isPro}),true):(this.state.error=l,this.state.errorKind="transport",this.scheduleRetry(i),this.emit({type:"error",isPro:this.state.isPro,error:l}),false)}return this.state.isValidating=false,this.state.error=l,this.state.errorKind="verdict",this.emit({type:"error",isPro:false,error:l}),false}try{if(r!==this.generation)return false;let a=Ve(o),l=o.data?.relationships?.product?.data?.id;if((!l||l===x.productId)&&a.code==="EXPIRED"&&(st(o.data)||this.cachedLicense?.licenseKey===i&&A(this.cachedLicense)&&this.isCacheValid(this.cachedLicense))){let K=h(),J=await this.saveCache({licenseKey:i,licenseId:o.data?.id??"",valid:true,isPro:false,tier:"free",expiresAt:null,cachedAt:K,lastValidatedAt:K,fingerprint:this.cachedLicense?.licenseKey===i?this.cachedLicense.fingerprint:void 0},r);return r!==this.generation||!J?false:(this.cachedLicense=J,this.applyTier("free"),this.state.isValidating=false,this.state.expiresAt=null,this.setVerifiedAt(K),this.emit({type:"validated",isPro:false}),true)}if(De(a.code)||!Oe(o))return this.lock(),this.state.isValidating=false,this.state.error=a.detail||"License could not be verified",this.state.errorKind="verdict",this.emit({type:"error",isPro:false,error:this.state.error}),await this.clearCachedLicense(),await this.saveHold({key:i,code:a.code,detail:this.state.error,verdictAt:h()}),false;if(!o.data)return this.lock(),this.state.isValidating=false,this.state.error=a.detail||"License not found",this.state.errorKind="verdict",this.emit({type:"error",isPro:false,error:this.state.error}),await this.clearCachedLicense(),false;let u=rt(o.data),f=o.data.id,C=h(),j=Me(o)>=xe,z=Q(),ge=z&&!j,we=u==="free"&&(j||!z),v=this.cachedLicense?.fingerprint,k=this.cachedLicense?.deviceName,B=false;if(!v){if(v=await w(this.getOrCreateDeviceFingerprint(),D()),r!==this.generation)return false;k=U(),B=ge}let P=false;B&&(this.deviceRegistrationCallback?(this.pendingRegistration={licenseId:f,licenseKey:i,fingerprint:v},this.deviceRegistrationCallback({fingerprint:v,defaultName:k}),P=true):this.registerDeviceAsync(f,i,v,k));let S={licenseKey:i,licenseId:f,valid:true,isPro:u==="pro",tier:u,expiresAt:o.data.attributes.expiry??null,cachedAt:C,lastValidatedAt:C,fingerprint:P?void 0:v,deviceName:P?void 0:k,quiet:we||void 0},G=await this.saveCache(S,r);return r!==this.generation||!G||(this.cachedLicense=G,this.applyTier(u),this.state.isValidating=false,this.state.expiresAt=S.expiresAt?new Date(S.expiresAt):null,this.setVerifiedAt(C),this.hold&&await this.saveHold(null),r!==this.generation)?false:(this.retryAttempt=0,this.emit({type:"validated",isPro:this.state.isPro}),true)}catch(a){let l=a instanceof Error?a.message:"Validation failed";return r!==this.generation||(this.state.isValidating=false,this.state.error=l,this.state.errorKind="verdict",this.emit({type:"error",isPro:false,error:l})),false}}scheduleRetry(e){this.cancelRetry();let t=be[this.retryAttempt];if(t===void 0)return;this.retryAttempt+=1;let i=this.generation;this.retryTimer=setTimeout(()=>{this.retryTimer=null,i===this.generation&&(this.state.isValidating||this.setLicenseKey(e,{force:true,isRetry:true}))},t),typeof d<"u"&&d&&(globalThis.__LICENSE_MANAGER_RETRY_TIMER__=this.retryTimer)}async admitServiceKey(e,t){let i=await Rt(e,{origin:E.origin});if(t!==this.generation)return false;if(!i.ok)return this.lock(),this.state.isValidating=false,this.state.error=i.detail,this.state.errorKind=i.reason==="network"?"transport":"verdict",this.emit({type:"error",isPro:false,error:i.detail}),i.reason==="network"&&this.scheduleRetry(e),false;let r=i.claims.exp*1e3;return this.applyTier(i.claims.tier==="free"?"free":"pro"),this.state.isValidating=false,this.state.expiresAt=new Date(r),this.setVerifiedAt(h()),this.retryAttempt=0,this.scheduleRetryIn(e,Math.max(6e4,r-3600*1e3-h())),this.emit({type:"validated",isPro:this.isPro()}),true}async admitToken(e,t){let i=it(e);if(t!==this.generation)return false;if(!i)return this.lock(),this.state.isValidating=false,this.state.error="This key is not valid. Check that it was copied completely.",this.state.errorKind="verdict",this.emit({type:"error",isPro:false,error:this.state.error}),await this.clearCachedLicense(),false;let r=h(),s=this.cachedLicense?.fingerprint??await w(this.getOrCreateDeviceFingerprint(),D());if(t!==this.generation)return false;let n=await this.saveCache({licenseKey:e,licenseId:`token:${i.accountHash}`,valid:true,isPro:false,tier:"free",expiresAt:null,cachedAt:r,lastValidatedAt:r,fingerprint:s,deviceName:this.cachedLicense?.deviceName??U(),quiet:true},t);return t!==this.generation||!n?false:(this.cachedLicense=n,this.applyTier("free"),this.state.isValidating=false,this.state.expiresAt=null,this.setVerifiedAt(r),this.retryAttempt=0,this.emit({type:"validated",isPro:false}),true)}standDown(e,t,i,r){if(t!==this.generation)return false;this.state.isValidating=false;let s=this.cachedLicense;return s&&s.licenseKey===e&&A(s)&&this.isCacheValid(s)?(this.applyTier(b(s)),this.state.error=null,this.state.errorKind=null,this.state.expiresAt=s.expiresAt?new Date(s.expiresAt):null,this.setVerifiedAt(s.cachedAt),this.keyTier()!=="pro"&&this.scheduleRetryIn(e,r),this.emit({type:"validated",isPro:this.state.isPro}),true):(this.state.error=i,this.state.errorKind="transport",this.scheduleRetryIn(e,r),this.emit({type:"error",isPro:this.state.isPro,error:i}),false)}scheduleRetryIn(e,t){this.cancelRetry();let i=this.generation;this.retryTimer=setTimeout(()=>{this.retryTimer=null,i===this.generation&&(this.state.isValidating||this.setLicenseKey(e,{force:true,isRetry:true}))},Math.max(1,Math.min(t,2147483647))),typeof d<"u"&&d&&(y.__LICENSE_MANAGER_RETRY_TIMER__=this.retryTimer)}cancelRetry(){this.retryTimer&&(clearTimeout(this.retryTimer),this.retryTimer=null)}async clearLicense(){this.generation+=1,this.cancelRetry(),this.retryAttempt=0,this.configuredKey=null,this.state.licenseKey=null,this.lock(),this.state.expiresAt=null,this.state.error=null,this.state.errorKind=null,this.cachedLicense=null,this.pendingRegistration=null,this.state.isValidating=false,this.emit({type:"deactivated",isPro:false}),await this.clearCachedLicense(),this.hold?.verdictAt!==void 0&&await this.saveHold(this.hold.backoffUntil?{backoffUntil:this.hold.backoffUntil}:null)}applyTier(e){this.state.tier=e,this.state.tierSource="key",this.state.isPro=e==="pro"}lock(){this.state.tier="free",this.state.tierSource="none",this.state.isPro=false,this.verifiedAt=null,this.expiryTimer&&clearTimeout(this.expiryTimer),this.expiryTimer=null}getTier(){return this.credential().tier}credential(){let e=this.keyTier(),t=this.sessionTier();return t!==null&&(!this.hasKeyAccess()||t==="pro"&&e!=="pro")?{source:"session",tier:t}:{source:this.state.tierSource,tier:e}}keyTier(){return!this.hasKeyAccess()||this.state.expiresAt&&h()>=this.state.expiresAt.getTime()?"free":this.state.tier}sessionTier(){let e=E.getStatus();return e.state!=="active"?null:e.claims.tier==="free"?"free":"pro"}isPro(){return this.getTier()==="pro"}hasEntitlement(e){return this.isPro()}getState(){let{source:e,tier:t}=this.credential();return{...this.state,tier:t,tierSource:e,isPro:t==="pro",access:this.getAccountAccess()}}getAccountAccess(){let e=this.getKeyAccess();if(e.status==="admitted")return e;let t=E.getStatus();return t.state==="active"?{status:"admitted",reason:null,validUntil:t.validUntil}:e}getKeyAccess(){return he({initialized:this.state.isInitialized,validating:this.state.isValidating,key:this.state.licenseKey,tierSource:this.state.tierSource,verifiedAt:this.verifiedAt})}hasAccountAccess(){return this.getAccountAccess().status==="admitted"}hasKeyAccess(){return this.getKeyAccess().status==="admitted"}setVerifiedAt(e){this.verifiedAt=e,this.expiryTimer&&clearTimeout(this.expiryTimer);let t=e+R,i=this.state.expiresAt?.getTime(),r=(i&&i>h()?Math.min(t,i):t)-h();this.expiryTimer=setTimeout(()=>{this.expiryTimer=null,this.verifiedAt===e&&(this.emit({type:"validated",isPro:this.isPro()}),h()<t&&this.setVerifiedAt(e))},Math.max(1,Math.min(r,2147483647))),typeof d<"u"&&d&&(y.__LICENSE_MANAGER_EXPIRY_TIMER__=this.expiryTimer)}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}onDeviceRegistrationNeeded(e){return this.deviceRegistrationCallback=e,()=>{this.deviceRegistrationCallback=null}}async completeDeviceRegistration(e){if(!this.pendingRegistration){console.warn("[Buoy] No pending device registration");return}let{licenseId:t,licenseKey:i,fingerprint:r}=this.pendingRegistration,s=this.generation,n=e.trim()||U(),c=ie();try{await Z(t,i,r,n,c)}catch(o){let a=o instanceof Error?o.message:String(o);if(!(a==="FINGERPRINT_TAKEN"||a==="MACHINE_LIMIT_EXCEEDED"))throw console.warn("[Buoy] Device registration failed:",a),o}if(s===this.generation){if(this.cachedLicense?.licenseKey===i){let o=await this.saveCache({...this.cachedLicense,fingerprint:r,deviceName:n},s);if(s!==this.generation)return;o&&(this.cachedLicense=o)}this.pendingRegistration=null}}emit(e){[...this.listeners].forEach(t=>{try{t(e)}catch(i){console.warn("[React Buoy] License listener error:",i)}})}isCacheValid(e){let t=h()-e.cachedAt;return!(!e.valid||!Number.isFinite(e.cachedAt)||t<0||t>=R)}isCacheFresh(e){let t=this.isQuiet(e)?Ie:Ee;return h()-(e.lastValidatedAt??0)<t}isQuiet(e){return e.quiet!==void 0?e.quiet:b(e)==="free"&&!Q()}async loadHold(){if(this.hold!==void 0)return this.hold;try{let e=await(await g()).getItem(V),t=e?JSON.parse(e):null;this.hold=t&&typeof t=="object"?t:null}catch{this.hold=null}return this.hold}async saveHold(e){this.hold=e;try{let t=await g();e?await t.setItem(V,JSON.stringify(e)):await t.removeItem(V)}catch{}}async persistCache(e){let t=ae(e);return await(await g()).setItem(O,JSON.stringify(t)),t}saveCache(e,t){let i=this.persistence.catch(()=>{}).then(async()=>{if(t!==this.generation)return null;let r=await this.persistCache(e);return t===this.generation?r:null});return this.persistence=i,w(i,ae(e))}async loadCachedLicense(){try{await this.persistence.catch(()=>{});let e=await(await g()).getItem(O);return e?JSON.parse(e):null}catch(e){return console.warn("[Buoy] Error loading cached license:",e),null}}getOrCreateDeviceFingerprint(){return this.fingerprintPromise||(this.fingerprintPromise=(async()=>{let e=await g(),t=await e.getItem(M);if(t)return t;let i=this.cachedLicense?.fingerprint||D();return await e.setItem(M,i),i})()),this.fingerprintPromise}async clearCachedLicense(){this.cachedLicense=null;let e=this.persistence.catch(()=>{}).then(async()=>{await(await g()).removeItem(O)});this.persistence=e,await w(e.catch(()=>{}),void 0)}registerDeviceAsync(e,t,i,r){let s=ie();Z(e,t,i,r,s).catch(n=>{n.message!=="FINGERPRINT_TAKEN"&&n.message!=="MACHINE_LIMIT_EXCEEDED"&&console.warn("[Buoy] Device registration failed (non-blocking):",n.message)})}validateInBackground(e){this.setLicenseKey(e,{force:true,isRetry:true})}refreshAccess(){this.emit({type:"validated",isPro:this.isPro()})}startRevalidationTimer(){this.removeForegroundListener||(this.removeForegroundListener=nt(()=>this.refreshAccess()),typeof d<"u"&&d&&(y.__LICENSE_MANAGER_FOREGROUND_OFF__=this.removeForegroundListener)),this.revalidationTimer&&clearInterval(this.revalidationTimer),this.revalidationTimer=setInterval(()=>{if(!this.state.licenseKey||this.state.isValidating)return;let e=this.cachedLicense;e&&e.licenseKey===this.state.licenseKey&&this.isCacheFresh(e)||this.validateInBackground(this.state.licenseKey)},_e),typeof d<"u"&&d&&(globalThis.__LICENSE_MANAGER_TIMER__=this.revalidationTimer)}stopRevalidationTimer(){this.removeForegroundListener?.(),this.removeForegroundListener=null,this.expiryTimer&&clearTimeout(this.expiryTimer),this.expiryTimer=null,this.revalidationTimer&&(clearInterval(this.revalidationTimer),this.revalidationTimer=null),this.cancelRetry()}async forceReregister(){this.cachedLicense&&(this.cachedLicense.fingerprint=void 0,this.cachedLicense.deviceName=void 0),this.fingerprintPromise=null,await this.clearCachedLicense();try{await(await g()).removeItem(M)}catch{}}},Ct=new Nt,y=globalThis;typeof d<"u"&&d&&(y.__LICENSE_MANAGER_FOREGROUND_OFF__?.(),y.__LICENSE_MANAGER_FOREGROUND_OFF__=void 0,y.__LICENSE_MANAGER_EXPIRY_TIMER__&&clearTimeout(y.__LICENSE_MANAGER_EXPIRY_TIMER__),y.__LICENSE_MANAGER_TIMER__&&clearInterval(y.__LICENSE_MANAGER_TIMER__),y.__LICENSE_MANAGER_RETRY_TIMER__&&(clearTimeout(y.__LICENSE_MANAGER_RETRY_TIMER__),y.__LICENSE_MANAGER_RETRY_TIMER__=void 0));export{h as a,T as b,W as c,le as d,he as e,p as f,E as g,$ as h,Ct as i};/*!
|
|
2
|
-
* PROPRIETARY — Buoy Pro license enforcement. NOT open source.
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) Buoy. All rights reserved. Licensed under the Buoy EULA
|
|
5
|
-
* (https://buoy.gg/terms), not an OSS license.
|
|
6
|
-
*
|
|
7
|
-
* This file configures the technological measure that controls access to paid
|
|
8
|
-
* Buoy Pro features. Modifying, patching, aliasing, stubbing, or otherwise
|
|
9
|
-
* altering it — including repointing `apiUrl` at a stand-in license server — so
|
|
10
|
-
* that Pro features unlock without a valid license is a breach of the EULA and,
|
|
11
|
-
* in the United States, circumvention of an access control under 17 U.S.C.
|
|
12
|
-
* § 1201, which applies whether or not any code is copied.
|
|
13
|
-
*
|
|
14
|
-
* Pro is $9/mo, and is free every weekend for anyone holding a key —
|
|
15
|
-
* including a free one (`npx buoy login`). Buy a key at
|
|
16
|
-
* https://buoy.gg or use it free on Saturday and Sunday.
|
|
17
|
-
*//*!
|
|
18
|
-
* PROPRIETARY — Buoy Pro license enforcement. NOT open source.
|
|
19
|
-
*
|
|
20
|
-
* Copyright (c) Buoy. All rights reserved. Licensed under the Buoy EULA
|
|
21
|
-
* (https://buoy.gg/terms), not an OSS license.
|
|
22
|
-
*
|
|
23
|
-
* This file is part of the technological measure that controls access to paid
|
|
24
|
-
* Buoy Pro features. Modifying, patching, aliasing, stubbing, or otherwise
|
|
25
|
-
* altering it so that Pro features unlock without a valid license is a breach
|
|
26
|
-
* of the EULA and, in the United States, circumvention of an access control
|
|
27
|
-
* under 17 U.S.C. § 1201 — which applies whether or not any code is copied.
|
|
28
|
-
*
|
|
29
|
-
* Pro is $9/mo, and is free every weekend for anyone holding a key —
|
|
30
|
-
* including a free one (`npx buoy login`). Buy a key at
|
|
31
|
-
* https://buoy.gg or use it free on Saturday and Sunday.
|
|
32
|
-
*//*!
|
|
33
|
-
* PROPRIETARY — Buoy Pro license enforcement. NOT open source.
|
|
34
|
-
*
|
|
35
|
-
* Copyright (c) Buoy. All rights reserved. Licensed under the Buoy EULA
|
|
36
|
-
* (https://buoy.gg/terms), not an OSS license.
|
|
37
|
-
*//*!
|
|
38
|
-
* PROPRIETARY — Buoy Pro license enforcement. NOT open source.
|
|
39
|
-
*
|
|
40
|
-
* Copyright (c) Buoy. All rights reserved. Licensed under the Buoy EULA
|
|
41
|
-
* (https://buoy.gg/terms), not an OSS license.
|
|
42
|
-
*
|
|
43
|
-
* This file is part of the technological measure that controls access to paid
|
|
44
|
-
* Buoy Pro features: it decides which tier a validated key grants. Modifying,
|
|
45
|
-
* patching, aliasing, stubbing, or otherwise altering it so that Pro features
|
|
46
|
-
* unlock without a valid license is a breach of the EULA and, in the United
|
|
47
|
-
* States, circumvention of an access control under 17 U.S.C. § 1201 — which
|
|
48
|
-
* applies whether or not any code is copied.
|
|
49
|
-
*
|
|
50
|
-
* Pro is $9/mo, and is free every weekend for anyone holding a key —
|
|
51
|
-
* including a free one (`npx buoy login`). Buy a key at
|
|
52
|
-
* https://buoy.gg or use it free on Saturday and Sunday.
|
|
53
|
-
*//*!
|
|
54
|
-
* PROPRIETARY — Buoy license enforcement. NOT open source.
|
|
55
|
-
*
|
|
56
|
-
* Copyright (c) Buoy. All rights reserved. Licensed under the Buoy EULA
|
|
57
|
-
* (https://buoy.gg/terms), not an OSS license.
|
|
58
|
-
*//*!
|
|
59
|
-
* PROPRIETARY — Buoy Pro license enforcement. NOT open source.
|
|
60
|
-
*
|
|
61
|
-
* Copyright (c) Buoy. All rights reserved. Licensed under the Buoy EULA
|
|
62
|
-
* (https://buoy.gg/terms), not an OSS license.
|
|
63
|
-
*
|
|
64
|
-
* This file is the technological measure that controls access to paid Buoy Pro
|
|
65
|
-
* features. Modifying, patching, aliasing, stubbing, or otherwise altering it
|
|
66
|
-
* so that Pro features unlock without a valid license is a breach of the EULA
|
|
67
|
-
* and, in the United States, circumvention of an access control under
|
|
68
|
-
* 17 U.S.C. § 1201 — which applies whether or not any code is copied.
|
|
69
|
-
*
|
|
70
|
-
* Pro is $9/mo, and is free every weekend for anyone holding a key —
|
|
71
|
-
* including a free one (`npx buoy login`). Buy a key at
|
|
72
|
-
* https://buoy.gg or use it free on Saturday and Sunday.
|
|
73
|
-
*/
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use client";var d=process.env.NODE_ENV!=="production";typeof window<"u"&&typeof globalThis.global>"u"&&(globalThis.global=globalThis);var x=new Map,ye={async getItem(e){try{return localStorage.getItem(e)??x.get(e)??null}catch{return x.get(e)??null}},async setItem(e,t){x.set(e,t);try{localStorage.setItem(e,t)}catch{}},async removeItem(e){x.delete(e);try{localStorage.removeItem(e)}catch{}}};async function m(){return ye}var L={accountId:"b0eba0e8-e904-4906-b644-38f9aab57bed",productId:"bf67cb43-eeef-40ca-b308-e6e1b22c0eaa",apiUrl:"https://buoy.gg/api/license"},me="3b546fc717a62683f3236c70167899a271bee3ffc04df6ec1eea60a394a2f1e9",we="",R={free:"394e3351-1249-4f73-807a-703408604c0e",solo:"fa5d3c8f-5379-40f1-b63e-ab8a974b2f28",business:"690c2212-8e54-426f-b4b4-002ee1c0ae2b"},k=720*60*60*1e3,ve=1440*60*1e3,K="buoy-gg-license",M="buoy-gg-device-fingerprint",Ae=3600*1e3,Te=[5*1e3,20*1e3,60*1e3,300*1e3,900*1e3],_e=60*1e3,j=3600*1e3,Ee=1440*60*1e3,be=50,Ie=k,O="buoy-gg-license-hold";function h(){let e=globalThis.__buoyRealNow;return typeof e=="function"?e():Date.now()}var{apiUrl:B}=L,A=class extends Error{constructor(e,t,i=null){super(e);this.isTransient=true;this.name="LicenseTransportError",this.status=t,this.retryAfterMs=i}};function xe(e){let t=e?.status;return t===429||t===402}function Le(e,t,i){return e.status===402?t:e.retryAfterMs??i}function Re(e){let t=s=>{try{return e.headers?.get?.(s)??null}catch{return null}},i=t("Retry-After");if(i){let s=Number(i);if(Number.isFinite(s)&&s>=0)return s*1e3;let a=Date.parse(i);if(Number.isFinite(a))return Math.max(0,a-h())}let r=Number(t("X-RateLimit-Reset"));return Number.isFinite(r)&&r>0?Math.max(0,r*1e3-h()):null}function Y(e){return e instanceof A||e instanceof TypeError?true:typeof e=="object"&&e!==null&&e.isTransient===true}async function ke(e){try{return(await e.json()).errors?.[0]?.detail||`HTTP ${e.status}`}catch{return`HTTP ${e.status}`}}function J(){return{"Content-Type":"application/vnd.api+json",Accept:"application/vnd.api+json"}}async function Ne(e,t){let i=`${B}/validate`,r={meta:{key:e}},s;try{s=await fetch(i,{signal:t,method:"POST",headers:J(),body:JSON.stringify(r)})}catch(a){throw new A(a instanceof Error?a.message:"Network request failed",null)}if(!s.ok)throw new A(await ke(s),s.status,s.status===429?Re(s):null);try{let a=await s.json();if(!a||typeof a!="object"||typeof a.meta?.valid!="boolean"||typeof a.meta?.code!="string"||!a.meta.code)throw new Error("Missing license verdict");return a}catch{throw new A("License server returned an unreadable response",s.status)}}async function Ce(e){let t=typeof AbortController=="function"?new AbortController:null,i;try{return await Promise.race([Ne(e,t?.signal),new Promise((r,s)=>{i=setTimeout(()=>{s(new A("License verification timed out. Please retry.",null)),t?.abort()},15e3)})])}finally{i&&clearTimeout(i)}}function Pe(e){if(!e.data)return false;let t=e.data.relationships?.product?.data?.id;return t&&t!==L.productId?false:e.meta.valid&&e.meta.code==="VALID"?true:["OVERDUE","NO_MACHINE","NO_MACHINES","TOO_MANY_MACHINES","TOO_MANY_CORES","TOO_MANY_PROCESSES","FINGERPRINT_SCOPE_MISMATCH","HEARTBEAT_NOT_STARTED","HEARTBEAT_DEAD"].includes(e.meta.code)}function Se(e){let t=e.data?.relationships?.machines?.meta?.count;return typeof t=="number"&&Number.isFinite(t)?t:0}async function X(e,t,i,r,s){let a=`${B}/machines`,u=await fetch(a,{method:"POST",headers:J(),body:JSON.stringify({licenseId:e,licenseKey:t,fingerprint:i,name:r,metadata:s||{}})});if(!u.ok){let o=await u.json(),n=o.errors?.[0]?.code;if(n==="FINGERPRINT_TAKEN")throw new Error("FINGERPRINT_TAKEN");if(n==="MACHINE_LIMIT_EXCEEDED")throw new Error("MACHINE_LIMIT_EXCEEDED");let l=o.errors?.[0]?.detail||`HTTP ${u.status}`;throw new Error(l)}return u.json()}function Ke(e){let{meta:t,data:i}=e;return{valid:t.valid,code:t.code,detail:t.detail,metadata:i?.attributes?.metadata}}function Me(e){return["NOT_FOUND","SUSPENDED","EXPIRED","BANNED","PRODUCT_SCOPE_MISMATCH"].includes(e)}function V(){return typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}function q(){if(typeof d<"u")return d;try{if(typeof navigator<"u"&&/electron/i.test(navigator.userAgent))return true}catch{}return typeof process<"u"&&process.env.NODE_ENV!=="production"}function W(){if(typeof navigator>"u")return"unknown";let e=navigator.userAgent.toLowerCase(),t=navigator.platform?.toLowerCase()||"";return e.includes("electron")?t.includes("mac")||e.includes("mac")?"electron-macos":t.includes("win")||e.includes("win")?"electron-windows":t.includes("linux")||e.includes("linux")?"electron-linux":"electron":t.includes("mac")||e.includes("mac")?"macos":t.includes("win")||e.includes("win")?"windows":t.includes("linux")||e.includes("linux")?"linux":/iphone|ipad|ipod/.test(e)?"ios-web":e.includes("android")?"android-web":"web"}function Oe(){if(typeof navigator>"u")return"unknown";let e=navigator.userAgent,t=e.match(/Mac OS X ([\d_.]+)/);if(t)return t[1].replace(/_/g,".");let i=e.match(/Windows NT ([\d.]+)/);return i?{"10.0":"10/11","6.3":"8.1","6.2":"8","6.1":"7"}[i[1]]||i[1]:e.includes("Linux")?"Linux":"unknown"}function Z(){if(typeof navigator>"u")return{name:"unknown",version:"unknown"};let e=navigator.userAgent,t=e.match(/Electron\/([\d.]+)/);if(t)return{name:"Electron",version:t[1]};let i=e.match(/Chrome\/([\d.]+)/);if(i&&!e.includes("Edg"))return{name:"Chrome",version:i[1]};let r=e.match(/Edg\/([\d.]+)/);if(r)return{name:"Edge",version:r[1]};let s=e.match(/Firefox\/([\d.]+)/);if(s)return{name:"Firefox",version:s[1]};let a=e.match(/Version\/([\d.]+).*Safari/);return a?{name:"Safari",version:a[1]}:{name:"unknown",version:"unknown"}}function Q(){let e={platform:W(),osVersion:Oe(),isSimulator:"false"},t=Z();e.browser=t.name,e.browserVersion=t.version,typeof window<"u"&&window.screen&&(e.screenResolution=`${window.screen.width}x${window.screen.height}`),typeof navigator<"u"&&navigator.language&&(e.language=navigator.language);try{e.timezone=Intl.DateTimeFormat().resolvedOptions().timeZone}catch{}return e}function D(){let e=W(),t=Z();if(e.startsWith("electron")){let i=e.replace("electron-","").replace("electron","Desktop");return`${i.charAt(0).toUpperCase()+i.slice(1)} App`}return t.name!=="unknown"?`${t.name} Browser`:"Web Browser"}var Ve=["v1"],De="buoy.gg/pro:9f3c1d7a4b2e:license-cache";function ee(e,t){let i=t>>>0;for(let r=0;r<e.length;r++)i^=e.charCodeAt(r),i=Math.imul(i,16777619)>>>0;return i>>>0}function Ue(e,t){let i=[t,e.licenseKey,e.licenseId,e.isPro?"1":"0",e.expiresAt??"",String(e.cachedAt)];return t!=="v1"&&i.push(e.tier??""),i.push(De),i.join("\0")}function te(e,t){let i=Ue(e,t),r=ee(i,2166136261),s=ee(i,2135587861);return`${t}.${r.toString(16)}${s.toString(16)}`}function ie(e){return te(e,"v2")}function re(e){return{...e,sig:ie(e)}}function T(e){return!e||typeof e.sig!="string"||e.sig.length===0?false:e.sig===ie(e)?true:Ve.some(t=>e.sig.startsWith(`${t}.`)&&e.sig===te(e,t))}import Fe from"tweetnacl";var He=1,$e=1,ze="buoy-free-token-v1:",Ge=22,je=64,se=/^BUOY1-([A-Z2-7]+)-([A-Z2-7]+)$/;function ne(e){return se.test(e.trim().toUpperCase())}var Be="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";function ae(e){let t=[],i=0,r=0;for(let s of e){let a=Be.indexOf(s);if(a===-1)return null;r=r<<5|a,i+=5,i>=8&&(t.push(r>>>i-8&255),i-=8)}return new Uint8Array(t)}function Ye(e){let t=e.trim().toLowerCase(),i=new Uint8Array(t.length/2);for(let r=0;r<i.length;r+=1)i[r]=parseInt(t.slice(r*2,r*2+2),16);return i}function Je(e){let t="";for(let i of e)t+=i.toString(16).padStart(2,"0");return t}function Xe(e){if(typeof TextEncoder<"u")return new TextEncoder().encode(e);let t=new Uint8Array(e.length);for(let i=0;i<e.length;i+=1)t[i]=e.charCodeAt(i)&255;return t}function qe(e,t){let i=new Uint8Array(e.length+t.length);return i.set(e,0),i.set(t,e.length),i}function We(e){return qe(Xe(ze),e)}var Ze=me;function Qe(e,t=Ze){let i=se.exec(e.trim().toUpperCase());if(!i)return null;let r=ae(i[1]),s=ae(i[2]);if(!r||!s||r.length!==Ge||s.length!==je||r[0]!==He||r[1]!==$e)return null;try{if(!Fe.sign.detached.verify(We(r),s,Ye(t)))return null}catch{return null}return{tier:"free",issuedAt:((r[2]<<24>>>0)+(r[3]<<16)+(r[4]<<8)+r[5])*1e3,accountHash:Je(r.slice(6,22))}}function et(e){let t=e.relationships?.policy?.data?.id;return t===R.free?"free":t===R.solo||t===R.business?"pro":e.attributes?.metadata?.plan==="free"?"free":"pro"}function tt(e){if(!e)return false;let t=e.relationships?.product?.data?.id;if(t)return t===L.productId;let i=e.relationships?.policy?.data?.id;return Object.values(R).some(r=>r===i)}function oe(e,t=h()){let i=e.verifiedAt!==null&&Number.isFinite(e.verifiedAt)&&e.verifiedAt<=t?e.verifiedAt+k:null;return e.initialized&&e.key&&e.tierSource!=="none"&&i!==null&&t<i?{status:"admitted",reason:null,validUntil:i}:i!==null&&t>=i?{status:"locked",reason:"verification_expired",validUntil:i}:!e.initialized||e.validating?{status:"initializing",reason:"checking",validUntil:i}:{status:"locked",reason:i!==null&&t>=i?"verification_expired":"account_required",validUntil:i}}function it(e){if(typeof window>"u"||typeof window.addEventListener!="function")return()=>{};let t=()=>{document.hidden||e()};return window.addEventListener("focus",e),document.addEventListener("visibilitychange",t),()=>{window.removeEventListener("focus",e),document.removeEventListener("visibilitychange",t)}}import rt from"tweetnacl";var st="buoys1",nt="buoy-session-v1:",le=1,ce=60,at=64,ot=["free","pro","business"],y="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";function U(e){let t="",i=0;for(;i+2<e.length;i+=3){let s=e[i]<<16|e[i+1]<<8|e[i+2];t+=y[s>>>18&63]+y[s>>>12&63]+y[s>>>6&63]+y[s&63]}let r=e.length-i;if(r===1){let s=e[i]<<16;t+=y[s>>>18&63]+y[s>>>12&63]}else if(r===2){let s=e[i]<<16|e[i+1]<<8;t+=y[s>>>18&63]+y[s>>>12&63]+y[s>>>6&63]}return t}function he(e){if(!/^[A-Za-z0-9_-]*$/.test(e)||e.length%4===1)return null;let t=[],i=0,r=0;for(let s of e)r=r<<6|y.indexOf(s),i+=6,i>=8&&(t.push(r>>>i-8&255),i-=8);return new Uint8Array(t)}function lt(e){if(typeof TextEncoder<"u")return new TextEncoder().encode(e);let t=unescape(encodeURIComponent(e)),i=new Uint8Array(t.length);for(let r=0;r<t.length;r+=1)i[r]=t.charCodeAt(r);return i}function ct(e){try{if(typeof TextDecoder<"u")return new TextDecoder("utf-8",{fatal:true}).decode(e);let t="";for(let i of e)t+=String.fromCharCode(i);return decodeURIComponent(escape(t))}catch{return null}}function ht(e){let t=e.trim().toLowerCase(),i=new Uint8Array(t.length/2);for(let r=0;r<i.length;r+=1)i[r]=parseInt(t.slice(r*2,r*2+2),16);return i}function ut(e){return lt(nt+e)}function _(e,t=256){return typeof e=="string"&&e.length>0&&e.length<=t}function ue(e){return typeof e=="number"&&Number.isInteger(e)&&e>0}function dt(e){if(!e||typeof e!="object"||Array.isArray(e))return null;let t=e;return!_(t.sid)||!_(t.sub)||!_(t.aud,512)||t.team!==null&&!_(t.team)||!ot.includes(t.tier)||t.role!==void 0&&!_(t.role,64)||t.tools!==void 0&&(!Array.isArray(t.tools)||t.tools.length>256||!t.tools.every(i=>_(i,64)))||!ue(t.iat)||!ue(t.exp)||t.exp<=t.iat?null:{v:le,sid:t.sid,sub:t.sub,team:t.team,tier:t.tier,...t.role!==void 0?{role:t.role}:{},...t.tools!==void 0?{tools:[...t.tools]}:{},aud:t.aud,iat:t.iat,exp:t.exp}}var ft=we;function pt(e,t){let i=t.publicKeyHex??ft;if(!i)return{ok:false,reason:"no-key"};let r=typeof e=="string"?e.split("."):[];if(r.length!==3||r[0]!==st)return{ok:false,reason:"malformed"};let[,s,a]=r,u=he(s),o=he(a);if(!u||!o||o.length!==at)return{ok:false,reason:"malformed"};try{if(!rt.sign.detached.verify(ut(s),o,ht(i)))return{ok:false,reason:"signature"}}catch{return{ok:false,reason:"signature"}}let n=ct(u),l;try{l=n===null?null:JSON.parse(n)}catch{return{ok:false,reason:"malformed"}}if(!l||typeof l!="object"||l.v!==le)return{ok:false,reason:l&&typeof l=="object"?"version":"malformed"};let c=dt(l);if(!c)return{ok:false,reason:"claims"};if(c.aud!==t.audience)return{ok:false,reason:"audience"};if(t.ignoreTime)return{ok:true,claims:c};let f=Math.floor((t.nowMs??h())/1e3);return f>=c.exp+ce?{ok:false,reason:"expired"}:c.iat>f+ce?{ok:false,reason:"not-yet-valid"}:{ok:true,claims:c}}var gt="@buoy/session:",de=10080*60*1e3,fe=360*60*1e3,yt=300*1e3,mt="https://buoy.gg",wt="buoy:signin",vt=600*1e3,p=class extends Error{constructor(e,t){super(t);this.code=e;this.name="SessionError"}};function At(){let e=globalThis;return{fetch:(t,i)=>fetch(t,i),storage:m,now:h,random:t=>{let i=new Uint8Array(t);if(!e.crypto?.getRandomValues)throw new p("not_configured","This platform has no secure random source.");return e.crypto.getRandomValues(i)},sha256:async t=>{if(!e.crypto?.subtle)throw new p("not_configured","Sign-in needs a secure page (https or localhost).");return new Uint8Array(await e.crypto.subtle.digest("SHA-256",t))},openPopup:()=>{if(!e.window?.open)return null;let t=480,i=640,r=Math.max(0,(e.window.screenX??0)+((e.window.outerWidth??t)-t)/2),s=Math.max(0,(e.window.screenY??0)+((e.window.outerHeight??i)-i)/2);return e.window.open("about:blank","buoy-signin",`popup,width=${t},height=${i},left=${r},top=${s}`)},onMessage:t=>{if(!e.window?.addEventListener)return()=>{};let i=r=>t({origin:r.origin,data:r.data});return e.window.addEventListener("message",i),()=>e.window?.removeEventListener("message",i)},withLock:(t,i)=>e.navigator?.locks?e.navigator.locks.request(t,i):i(),setTimer:(t,i)=>setTimeout(t,Math.min(i,2147483647)),clearTimer:t=>clearTimeout(t)}}function Tt(){let e=globalThis.location;if(!(!e?.origin||!/^https?:$/.test(e.protocol??"")))return e.origin}var _t=class{constructor(e){this.signinOrigin=mt;this.current=null;this.claims=null;this.listeners=new Set;this.timer=null;this.refreshing=null;this.loaded=null;this.deps=e??At(),this.audience=Tt()}configure(e){e.audience!==void 0&&(this.audience=e.audience),e.signinOrigin!==void 0&&(this.signinOrigin=e.signinOrigin.replace(/\/$/,"")),this.reset()}__setDeps(e){this.deps=e,this.reset()}reset(){this.timer!==null&&this.deps.clearTimer(this.timer),this.timer=null,this.current=null,this.claims=null,this.loaded=null,this.refreshing=null}get storageKey(){return gt+(this.audience??"")}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}notify(){for(let e of[...this.listeners])try{e()}catch(t){console.warn("[Buoy] sign-in listener error:",t)}}getStatus(){let e=this.claims;if(!e)return{state:"signed_out"};let t=e.exp*1e3,i=this.deps.now();return i<t?{state:"active",claims:e,grace:false,validUntil:t}:i<t+de?{state:"active",claims:e,grace:true,validUntil:t+de}:{state:"signed_out"}}load(){return this.loaded||(this.loaded=this.loadOnce()),this.loaded}async loadOnce(){if(!this.audience)return;let e=await this.read();e&&this.adopt(e)&&(this.notify(),this.schedule())}async sync(){if(!this.audience)return;let e=await this.read();if(!e){this.current&&this.clearLocal();return}e.refreshToken!==this.current?.refreshToken&&this.adopt(e)&&(this.notify(),this.schedule())}async read(){try{let e=await(await this.deps.storage()).getItem(this.storageKey);if(!e)return null;let t=JSON.parse(e);return t?.v===1&&typeof t.accessToken=="string"&&typeof t.refreshToken=="string"?t:null}catch{return null}}async write(e){let t=await this.deps.storage();e?await t.setItem(this.storageKey,JSON.stringify(e)):await t.removeItem(this.storageKey)}adopt(e){if(!this.audience)return false;let t=pt(e.accessToken,{audience:this.audience,ignoreTime:true,publicKeyHex:this.deps.publicKeyHex}),i=t.ok?t.claims:null;return i?(this.current=e,this.claims=i,true):false}schedule(){if(this.timer!==null&&this.deps.clearTimer(this.timer),this.timer=null,!this.claims)return;let e=this.claims.exp*1e3-fe-this.deps.now();this.timer=this.deps.setTimer(()=>{this.timer=null,this.refresh()},Math.max(0,e))}refresh(e=false){return this.refreshing||(this.refreshing=this.deps.withLock(`buoy-session:${this.audience??""}`,()=>this.refreshLocked(e)).catch(()=>{}).finally(()=>{this.refreshing=null})),this.refreshing}async refreshLocked(e){let t=await this.read();if(!t){this.current&&this.clearLocal();return}if(t.refreshToken!==this.current?.refreshToken&&this.adopt(t)){this.notify(),this.schedule();return}if(!this.claims)return;if(!e&&this.claims.exp*1e3-this.deps.now()>fe){this.schedule();return}let i,r;try{let s=await this.deps.fetch(`${this.signinOrigin}/api/auth/refresh`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refresh_token:t.refreshToken,audience:this.audience})});i=s.status,r=await s.json().catch(()=>null)}catch{this.retryLater();return}if(i===200&&r&&typeof r.access_token=="string"&&typeof r.refresh_token=="string"){let s={v:1,accessToken:r.access_token,refreshToken:r.refresh_token};if(this.adopt(s)){await this.write(s),this.notify(),this.schedule();return}}if(i===400||i===401||i===403){await this.write(null),this.clearLocal();return}this.retryLater()}retryLater(){this.timer!==null&&this.deps.clearTimer(this.timer),this.timer=this.deps.setTimer(()=>{this.timer=null,this.refresh(true)},yt),this.notify()}clearLocal(){this.timer!==null&&this.deps.clearTimer(this.timer),this.timer=null,this.current=null,this.claims=null,this.notify()}async signIn(){if(!this.audience)throw new p("not_configured","Sign-in needs a web page or a configured app id.");let e=this.deps.openPopup();if(!e)throw new p("popup_blocked","The browser blocked the sign-in window. Allow pop-ups for this site and try again.");try{return await this.signInWith((t,i)=>new Promise((r,s)=>{e.location.href=t;let a=this.deps.now(),u=null,o=c=>{u!==null&&this.deps.clearTimer(u),n(),c()},n=this.deps.onMessage(c=>{if(c.origin!==this.signinOrigin)return;let f=c.data;!f||f.type!==wt||f.state!==i||(typeof f.code=="string"?o(()=>r(f.code)):o(()=>s(new p("access_denied","Sign-in was cancelled."))))}),l=()=>{if(e.closed)return o(()=>s(new p("popup_closed","The sign-in window was closed.")));if(this.deps.now()-a>vt)return o(()=>s(new p("timeout","Sign-in took too long.")));u=this.deps.setTimer(l,500)};u=this.deps.setTimer(l,500)}))}finally{try{e.closed||e.close()}catch{}}}async signInWith(e){let t=this.audience;if(!t)throw new p("not_configured","Sign-in needs a web page or a configured app id.");let i=U(this.deps.random(32)),r=U(this.deps.random(16)),s=U(await this.deps.sha256(new TextEncoder().encode(i))),a=`${this.signinOrigin}/auth/authorize?audience=${encodeURIComponent(t)}&code_challenge=${s}&code_challenge_method=S256&state=${r}`,u=await e(a,r),o;try{o=await this.deps.fetch(`${this.signinOrigin}/api/auth/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:u,code_verifier:i,audience:t})})}catch{throw new p("network","Buoy could not be reached. Check your connection and try again.")}let n=await o.json().catch(()=>null);if(o.status!==200||!n||typeof n.access_token!="string"||typeof n.refresh_token!="string"){let c=n&&typeof n.error_description=="string"?n.error_description:"Buoy did not accept this sign-in.";throw new p(o.status===503?"unavailable":"rejected",c)}let l={v:1,accessToken:n.access_token,refreshToken:n.refresh_token};if(!this.adopt(l))throw new p("rejected","Buoy sent a sign-in this app could not check.");return await this.write(l),this.loaded=Promise.resolve(),this.notify(),this.schedule(),this.getStatus()}async signOut(){let e=this.current??await this.read();if(await this.write(null),this.clearLocal(),!!e)try{await this.deps.fetch(`${this.signinOrigin}/api/auth/revoke`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refresh_token:e.refreshToken})})}catch{}}},b=new _t;async function w(e,t){let i;try{return await Promise.race([e,new Promise(r=>{i=setTimeout(()=>r(t),15e3)})])}finally{i&&clearTimeout(i)}}function E(e){return e.tier==="pro"||e.tier==="free"?e.tier:e.isPro?"pro":"free"}var Et=class{constructor(){this.state={isInitialized:false,isValidating:false,isPro:false,tier:"free",tierSource:"none",licenseKey:null,error:null,errorKind:null,expiresAt:null};this.listeners=new Set;this.revalidationTimer=null;this.cachedLicense=null;this.fingerprintPromise=null;this.initPromise=null;this.generation=0;this.persistence=Promise.resolve();this.verifiedAt=null;this.expiryTimer=null;this.removeForegroundListener=null;this.sessionUnsubscribe=null;this.retryTimer=null;this.retryAttempt=0;this.deviceRegistrationCallback=null;this.pendingRegistration=null}async initialize(){if(this.initPromise)return this.initPromise;if(!this.state.isInitialized)return this.initPromise=this._doInitialize(),this.initPromise}async _doInitialize(){if(this.state.isInitialized)return;let e=this.generation;this.sessionUnsubscribe||(this.sessionUnsubscribe=b.subscribe(()=>this.emit({type:"validated",isPro:this.isPro()}))),await w(b.load().catch(()=>{}),void 0);try{let t=await w(this.loadCachedLicense(),null);if(e!==this.generation){this.state.isInitialized=true,this.emit({type:"initialized",isPro:this.state.isPro}),this.startRevalidationTimer();return}if(t&&(this.configuredKey===void 0||t.licenseKey===this.configuredKey)){let i=T(t);this.cachedLicense=t,this.state.licenseKey=t.licenseKey,i&&this.isCacheValid(t)?this.applyTier(E(t)):this.lock(),this.state.expiresAt=t.expiresAt?new Date(t.expiresAt):null,i&&this.isCacheValid(t)&&this.setVerifiedAt(t.cachedAt),this.configuredKey===void 0&&t.licenseKey&&!(i&&this.isCacheValid(t)&&this.isCacheFresh(t))&&this.validateInBackground(t.licenseKey)}this.state.isInitialized=true,this.emit({type:"initialized",isPro:this.state.isPro}),this.startRevalidationTimer()}catch(t){console.warn("[React Buoy] License initialization failed:",t),this.state.isInitialized=true,this.emit({type:"initialized",isPro:false})}}async configure(e){if(e===void 0)return await this.initialize(),this.hasAccountAccess();let t=e.trim().toUpperCase(),i=++this.generation;return this.cancelRetry(),this.configuredKey=t||null,this.state.licenseKey!==this.configuredKey&&this.lock(),this.state.licenseKey=this.configuredKey,this.state.isValidating=!!t,this.emit({type:"validating",isPro:this.isPro()}),await this.initialize(),i!==this.generation?false:t?this.setLicenseKey(t):(await this.clearLicense(),false)}async setLicenseKey(e,t){if(!e||e.trim().length===0)return this.state.error="License key is required",this.state.errorKind="verdict",false;let i=e.trim().toUpperCase(),r=++this.generation;if(this.cancelRetry(),t?.isRetry||(this.retryAttempt=0),this.state.licenseKey!==i&&this.lock(),this.state.licenseKey=i,this.state.isValidating=true,this.state.error=null,this.state.errorKind=null,this.emit({type:"validating",isPro:this.isPro()}),ne(i))return this.admitToken(i,r);if(!this.cachedLicense){let n=await w(this.loadCachedLicense(),null);if(r!==this.generation)return false;n?.licenseKey===i&&(this.cachedLicense=n,T(n)&&this.isCacheValid(n)&&(this.applyTier(E(n)),this.state.expiresAt=n.expiresAt?new Date(n.expiresAt):null,this.setVerifiedAt(n.cachedAt),this.emit({type:"validating",isPro:this.isPro()})))}let s=this.cachedLicense;if(!t?.force&&s&&s.valid&&s.licenseKey===i&&s.fingerprint&&T(s)&&this.isCacheValid(s)&&this.isCacheFresh(s))return this.applyTier(E(s)),this.state.licenseKey=i,this.state.isValidating=false,this.state.error=null,this.state.errorKind=null,this.state.expiresAt=s.expiresAt?new Date(s.expiresAt):null,this.setVerifiedAt(s.cachedAt),this.emit({type:"validated",isPro:this.state.isPro}),true;let a=await w(this.loadHold(),null);if(r!==this.generation)return false;let u=(a?.backoffUntil??0)-h();if(u>0)return this.standDown(i,r,"License server is rate limited; retrying later.",u);if(!t?.force&&a?.key===i&&a.verdictAt!==void 0&&h()-a.verdictAt>=0&&h()-a.verdictAt<Ee)return this.lock(),this.state.isValidating=false,this.state.error=a.detail||"License could not be verified",this.state.errorKind="verdict",this.emit({type:"error",isPro:false,error:this.state.error}),false;let o;try{o=await Ce(i)}catch(n){let l=n instanceof Error?n.message:"Validation failed";if(r!==this.generation)return false;if(Y(n)){if(xe(n)){let c=Math.min(Le(n,j,_e)*2**this.retryAttempt,j);return this.retryAttempt+=1,await this.saveHold({...this.hold,backoffUntil:h()+c}),r!==this.generation?false:this.standDown(i,r,l,c)}return this.state.isValidating=false,this.cachedLicense&&this.cachedLicense.licenseKey===i&&T(this.cachedLicense)&&this.isCacheValid(this.cachedLicense)?(this.applyTier(E(this.cachedLicense)),this.state.error=null,this.state.errorKind=null,this.state.expiresAt=this.cachedLicense.expiresAt?new Date(this.cachedLicense.expiresAt):null,this.setVerifiedAt(this.cachedLicense.cachedAt),this.keyTier()!=="pro"&&this.scheduleRetry(i),this.emit({type:"validated",isPro:this.state.isPro}),true):(this.state.error=l,this.state.errorKind="transport",this.scheduleRetry(i),this.emit({type:"error",isPro:this.state.isPro,error:l}),false)}return this.state.isValidating=false,this.state.error=l,this.state.errorKind="verdict",this.emit({type:"error",isPro:false,error:l}),false}try{if(r!==this.generation)return false;let n=Ke(o),l=o.data?.relationships?.product?.data?.id;if((!l||l===L.productId)&&n.code==="EXPIRED"&&(tt(o.data)||this.cachedLicense?.licenseKey===i&&T(this.cachedLicense)&&this.isCacheValid(this.cachedLicense))){let S=h(),G=await this.saveCache({licenseKey:i,licenseId:o.data?.id??"",valid:true,isPro:false,tier:"free",expiresAt:null,cachedAt:S,lastValidatedAt:S,fingerprint:this.cachedLicense?.licenseKey===i?this.cachedLicense.fingerprint:void 0},r);return r!==this.generation||!G?false:(this.cachedLicense=G,this.applyTier("free"),this.state.isValidating=false,this.state.expiresAt=null,this.setVerifiedAt(S),this.emit({type:"validated",isPro:false}),true)}if(Me(n.code)||!Pe(o))return this.lock(),this.state.isValidating=false,this.state.error=n.detail||"License could not be verified",this.state.errorKind="verdict",this.emit({type:"error",isPro:false,error:this.state.error}),await this.clearCachedLicense(),await this.saveHold({key:i,code:n.code,detail:this.state.error,verdictAt:h()}),false;if(!o.data)return this.lock(),this.state.isValidating=false,this.state.error=n.detail||"License not found",this.state.errorKind="verdict",this.emit({type:"error",isPro:false,error:this.state.error}),await this.clearCachedLicense(),false;let c=et(o.data),f=o.data.id,N=h(),F=Se(o)>=be,H=q(),pe=H&&!F,ge=c==="free"&&(F||!H),v=this.cachedLicense?.fingerprint,I=this.cachedLicense?.deviceName,$=false;if(!v){if(v=await w(this.getOrCreateDeviceFingerprint(),V()),r!==this.generation)return false;I=D(),$=pe}let C=false;$&&(this.deviceRegistrationCallback?(this.pendingRegistration={licenseId:f,licenseKey:i,fingerprint:v},this.deviceRegistrationCallback({fingerprint:v,defaultName:I}),C=true):this.registerDeviceAsync(f,i,v,I));let P={licenseKey:i,licenseId:f,valid:true,isPro:c==="pro",tier:c,expiresAt:o.data.attributes.expiry??null,cachedAt:N,lastValidatedAt:N,fingerprint:C?void 0:v,deviceName:C?void 0:I,quiet:ge||void 0},z=await this.saveCache(P,r);return r!==this.generation||!z||(this.cachedLicense=z,this.applyTier(c),this.state.isValidating=false,this.state.expiresAt=P.expiresAt?new Date(P.expiresAt):null,this.setVerifiedAt(N),this.hold&&await this.saveHold(null),r!==this.generation)?false:(this.retryAttempt=0,this.emit({type:"validated",isPro:this.state.isPro}),true)}catch(n){let l=n instanceof Error?n.message:"Validation failed";return r!==this.generation||(this.state.isValidating=false,this.state.error=l,this.state.errorKind="verdict",this.emit({type:"error",isPro:false,error:l})),false}}scheduleRetry(e){this.cancelRetry();let t=Te[this.retryAttempt];if(t===void 0)return;this.retryAttempt+=1;let i=this.generation;this.retryTimer=setTimeout(()=>{this.retryTimer=null,i===this.generation&&(this.state.isValidating||this.setLicenseKey(e,{force:true,isRetry:true}))},t),typeof d<"u"&&d&&(globalThis.__LICENSE_MANAGER_RETRY_TIMER__=this.retryTimer)}async admitToken(e,t){let i=Qe(e);if(t!==this.generation)return false;if(!i)return this.lock(),this.state.isValidating=false,this.state.error="This key is not valid. Check that it was copied completely.",this.state.errorKind="verdict",this.emit({type:"error",isPro:false,error:this.state.error}),await this.clearCachedLicense(),false;let r=h(),s=this.cachedLicense?.fingerprint??await w(this.getOrCreateDeviceFingerprint(),V());if(t!==this.generation)return false;let a=await this.saveCache({licenseKey:e,licenseId:`token:${i.accountHash}`,valid:true,isPro:false,tier:"free",expiresAt:null,cachedAt:r,lastValidatedAt:r,fingerprint:s,deviceName:this.cachedLicense?.deviceName??D(),quiet:true},t);return t!==this.generation||!a?false:(this.cachedLicense=a,this.applyTier("free"),this.state.isValidating=false,this.state.expiresAt=null,this.setVerifiedAt(r),this.retryAttempt=0,this.emit({type:"validated",isPro:false}),true)}standDown(e,t,i,r){if(t!==this.generation)return false;this.state.isValidating=false;let s=this.cachedLicense;return s&&s.licenseKey===e&&T(s)&&this.isCacheValid(s)?(this.applyTier(E(s)),this.state.error=null,this.state.errorKind=null,this.state.expiresAt=s.expiresAt?new Date(s.expiresAt):null,this.setVerifiedAt(s.cachedAt),this.keyTier()!=="pro"&&this.scheduleRetryIn(e,r),this.emit({type:"validated",isPro:this.state.isPro}),true):(this.state.error=i,this.state.errorKind="transport",this.scheduleRetryIn(e,r),this.emit({type:"error",isPro:this.state.isPro,error:i}),false)}scheduleRetryIn(e,t){this.cancelRetry();let i=this.generation;this.retryTimer=setTimeout(()=>{this.retryTimer=null,i===this.generation&&(this.state.isValidating||this.setLicenseKey(e,{force:true,isRetry:true}))},Math.max(1,Math.min(t,2147483647))),typeof d<"u"&&d&&(g.__LICENSE_MANAGER_RETRY_TIMER__=this.retryTimer)}cancelRetry(){this.retryTimer&&(clearTimeout(this.retryTimer),this.retryTimer=null)}async clearLicense(){this.generation+=1,this.cancelRetry(),this.retryAttempt=0,this.configuredKey=null,this.state.licenseKey=null,this.lock(),this.state.expiresAt=null,this.state.error=null,this.state.errorKind=null,this.cachedLicense=null,this.pendingRegistration=null,this.state.isValidating=false,this.emit({type:"deactivated",isPro:false}),await this.clearCachedLicense(),this.hold?.verdictAt!==void 0&&await this.saveHold(this.hold.backoffUntil?{backoffUntil:this.hold.backoffUntil}:null)}applyTier(e){this.state.tier=e,this.state.tierSource="key",this.state.isPro=e==="pro"}lock(){this.state.tier="free",this.state.tierSource="none",this.state.isPro=false,this.verifiedAt=null,this.expiryTimer&&clearTimeout(this.expiryTimer),this.expiryTimer=null}getTier(){let e=this.keyTier();return e==="pro"?"pro":this.sessionTier()??e}keyTier(){return!this.hasKeyAccess()||this.state.expiresAt&&h()>=this.state.expiresAt.getTime()?"free":this.state.tier}sessionTier(){let e=b.getStatus();return e.state!=="active"?null:e.claims.tier==="free"?"free":"pro"}isPro(){return this.getTier()==="pro"}hasEntitlement(e){return this.isPro()}getState(){let e=this.getAccountAccess(),t=this.getTier(),i=this.keyTier(),r=this.sessionTier(),s=r!==null&&i!=="pro"&&(r==="pro"||!this.hasKeyAccess())?"session":this.state.tierSource;return{...this.state,tier:t,tierSource:s,isPro:t==="pro",access:e}}getAccountAccess(){let e=this.getKeyAccess();if(e.status==="admitted")return e;let t=b.getStatus();return t.state==="active"?{status:"admitted",reason:null,validUntil:t.validUntil}:e}getKeyAccess(){return oe({initialized:this.state.isInitialized,validating:this.state.isValidating,key:this.state.licenseKey,tierSource:this.state.tierSource,verifiedAt:this.verifiedAt})}hasAccountAccess(){return this.getAccountAccess().status==="admitted"}hasKeyAccess(){return this.getKeyAccess().status==="admitted"}setVerifiedAt(e){this.verifiedAt=e,this.expiryTimer&&clearTimeout(this.expiryTimer);let t=e+k,i=this.state.expiresAt?.getTime(),r=(i&&i>h()?Math.min(t,i):t)-h();this.expiryTimer=setTimeout(()=>{this.expiryTimer=null,this.verifiedAt===e&&(this.emit({type:"validated",isPro:this.isPro()}),h()<t&&this.setVerifiedAt(e))},Math.max(1,Math.min(r,2147483647))),typeof d<"u"&&d&&(g.__LICENSE_MANAGER_EXPIRY_TIMER__=this.expiryTimer)}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}onDeviceRegistrationNeeded(e){return this.deviceRegistrationCallback=e,()=>{this.deviceRegistrationCallback=null}}async completeDeviceRegistration(e){if(!this.pendingRegistration){console.warn("[Buoy] No pending device registration");return}let{licenseId:t,licenseKey:i,fingerprint:r}=this.pendingRegistration,s=this.generation,a=e.trim()||D(),u=Q();try{await X(t,i,r,a,u)}catch(o){let n=o instanceof Error?o.message:String(o);if(!(n==="FINGERPRINT_TAKEN"||n==="MACHINE_LIMIT_EXCEEDED"))throw console.warn("[Buoy] Device registration failed:",n),o}if(s===this.generation){if(this.cachedLicense?.licenseKey===i){let o=await this.saveCache({...this.cachedLicense,fingerprint:r,deviceName:a},s);if(s!==this.generation)return;o&&(this.cachedLicense=o)}this.pendingRegistration=null}}emit(e){[...this.listeners].forEach(t=>{try{t(e)}catch(i){console.warn("[React Buoy] License listener error:",i)}})}isCacheValid(e){let t=h()-e.cachedAt;return!(!e.valid||!Number.isFinite(e.cachedAt)||t<0||t>=k)}isCacheFresh(e){let t=this.isQuiet(e)?Ie:Ae;return h()-(e.lastValidatedAt??0)<t}isQuiet(e){return e.quiet!==void 0?e.quiet:E(e)==="free"&&!q()}async loadHold(){if(this.hold!==void 0)return this.hold;try{let e=await(await m()).getItem(O),t=e?JSON.parse(e):null;this.hold=t&&typeof t=="object"?t:null}catch{this.hold=null}return this.hold}async saveHold(e){this.hold=e;try{let t=await m();e?await t.setItem(O,JSON.stringify(e)):await t.removeItem(O)}catch{}}async persistCache(e){let t=re(e);return await(await m()).setItem(K,JSON.stringify(t)),t}saveCache(e,t){let i=this.persistence.catch(()=>{}).then(async()=>{if(t!==this.generation)return null;let r=await this.persistCache(e);return t===this.generation?r:null});return this.persistence=i,w(i,re(e))}async loadCachedLicense(){try{await this.persistence.catch(()=>{});let e=await(await m()).getItem(K);return e?JSON.parse(e):null}catch(e){return console.warn("[Buoy] Error loading cached license:",e),null}}getOrCreateDeviceFingerprint(){return this.fingerprintPromise||(this.fingerprintPromise=(async()=>{let e=await m(),t=await e.getItem(M);if(t)return t;let i=this.cachedLicense?.fingerprint||V();return await e.setItem(M,i),i})()),this.fingerprintPromise}async clearCachedLicense(){this.cachedLicense=null;let e=this.persistence.catch(()=>{}).then(async()=>{await(await m()).removeItem(K)});this.persistence=e,await w(e.catch(()=>{}),void 0)}registerDeviceAsync(e,t,i,r){let s=Q();X(e,t,i,r,s).catch(a=>{a.message!=="FINGERPRINT_TAKEN"&&a.message!=="MACHINE_LIMIT_EXCEEDED"&&console.warn("[Buoy] Device registration failed (non-blocking):",a.message)})}validateInBackground(e){this.setLicenseKey(e,{force:true,isRetry:true})}refreshAccess(){this.emit({type:"validated",isPro:this.isPro()})}startRevalidationTimer(){this.removeForegroundListener||(this.removeForegroundListener=it(()=>this.refreshAccess()),typeof d<"u"&&d&&(g.__LICENSE_MANAGER_FOREGROUND_OFF__=this.removeForegroundListener)),this.revalidationTimer&&clearInterval(this.revalidationTimer),this.revalidationTimer=setInterval(()=>{if(!this.state.licenseKey||this.state.isValidating)return;let e=this.cachedLicense;e&&e.licenseKey===this.state.licenseKey&&this.isCacheFresh(e)||this.validateInBackground(this.state.licenseKey)},ve),typeof d<"u"&&d&&(globalThis.__LICENSE_MANAGER_TIMER__=this.revalidationTimer)}stopRevalidationTimer(){this.removeForegroundListener?.(),this.removeForegroundListener=null,this.expiryTimer&&clearTimeout(this.expiryTimer),this.expiryTimer=null,this.revalidationTimer&&(clearInterval(this.revalidationTimer),this.revalidationTimer=null),this.cancelRetry()}async forceReregister(){this.cachedLicense&&(this.cachedLicense.fingerprint=void 0,this.cachedLicense.deviceName=void 0),this.fingerprintPromise=null,await this.clearCachedLicense();try{await(await m()).removeItem(M)}catch{}}},bt=new Et,g=globalThis;typeof d<"u"&&d&&(g.__LICENSE_MANAGER_FOREGROUND_OFF__?.(),g.__LICENSE_MANAGER_FOREGROUND_OFF__=void 0,g.__LICENSE_MANAGER_EXPIRY_TIMER__&&clearTimeout(g.__LICENSE_MANAGER_EXPIRY_TIMER__),g.__LICENSE_MANAGER_TIMER__&&clearInterval(g.__LICENSE_MANAGER_TIMER__),g.__LICENSE_MANAGER_RETRY_TIMER__&&(clearTimeout(g.__LICENSE_MANAGER_RETRY_TIMER__),g.__LICENSE_MANAGER_RETRY_TIMER__=void 0));export{h as a,A as b,Y as c,ne as d,oe as e,p as f,b as g,bt as h};/*!
|
|
2
|
-
* PROPRIETARY — Buoy Pro license enforcement. NOT open source.
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) Buoy. All rights reserved. Licensed under the Buoy EULA
|
|
5
|
-
* (https://buoy.gg/terms), not an OSS license.
|
|
6
|
-
*
|
|
7
|
-
* This file configures the technological measure that controls access to paid
|
|
8
|
-
* Buoy Pro features. Modifying, patching, aliasing, stubbing, or otherwise
|
|
9
|
-
* altering it — including repointing `apiUrl` at a stand-in license server — so
|
|
10
|
-
* that Pro features unlock without a valid license is a breach of the EULA and,
|
|
11
|
-
* in the United States, circumvention of an access control under 17 U.S.C.
|
|
12
|
-
* § 1201, which applies whether or not any code is copied.
|
|
13
|
-
*
|
|
14
|
-
* Pro is $9/mo, and is free every weekend for anyone holding a key —
|
|
15
|
-
* including a free one (`npx buoy login`). Buy a key at
|
|
16
|
-
* https://buoy.gg or use it free on Saturday and Sunday.
|
|
17
|
-
*//*!
|
|
18
|
-
* PROPRIETARY — Buoy Pro license enforcement. NOT open source.
|
|
19
|
-
*
|
|
20
|
-
* Copyright (c) Buoy. All rights reserved. Licensed under the Buoy EULA
|
|
21
|
-
* (https://buoy.gg/terms), not an OSS license.
|
|
22
|
-
*
|
|
23
|
-
* This file is part of the technological measure that controls access to paid
|
|
24
|
-
* Buoy Pro features. Modifying, patching, aliasing, stubbing, or otherwise
|
|
25
|
-
* altering it so that Pro features unlock without a valid license is a breach
|
|
26
|
-
* of the EULA and, in the United States, circumvention of an access control
|
|
27
|
-
* under 17 U.S.C. § 1201 — which applies whether or not any code is copied.
|
|
28
|
-
*
|
|
29
|
-
* Pro is $9/mo, and is free every weekend for anyone holding a key —
|
|
30
|
-
* including a free one (`npx buoy login`). Buy a key at
|
|
31
|
-
* https://buoy.gg or use it free on Saturday and Sunday.
|
|
32
|
-
*//*!
|
|
33
|
-
* PROPRIETARY — Buoy Pro license enforcement. NOT open source.
|
|
34
|
-
*
|
|
35
|
-
* Copyright (c) Buoy. All rights reserved. Licensed under the Buoy EULA
|
|
36
|
-
* (https://buoy.gg/terms), not an OSS license.
|
|
37
|
-
*//*!
|
|
38
|
-
* PROPRIETARY — Buoy Pro license enforcement. NOT open source.
|
|
39
|
-
*
|
|
40
|
-
* Copyright (c) Buoy. All rights reserved. Licensed under the Buoy EULA
|
|
41
|
-
* (https://buoy.gg/terms), not an OSS license.
|
|
42
|
-
*
|
|
43
|
-
* This file is part of the technological measure that controls access to paid
|
|
44
|
-
* Buoy Pro features: it decides which tier a validated key grants. Modifying,
|
|
45
|
-
* patching, aliasing, stubbing, or otherwise altering it so that Pro features
|
|
46
|
-
* unlock without a valid license is a breach of the EULA and, in the United
|
|
47
|
-
* States, circumvention of an access control under 17 U.S.C. § 1201 — which
|
|
48
|
-
* applies whether or not any code is copied.
|
|
49
|
-
*
|
|
50
|
-
* Pro is $9/mo, and is free every weekend for anyone holding a key —
|
|
51
|
-
* including a free one (`npx buoy login`). Buy a key at
|
|
52
|
-
* https://buoy.gg or use it free on Saturday and Sunday.
|
|
53
|
-
*//*!
|
|
54
|
-
* PROPRIETARY — Buoy license enforcement. NOT open source.
|
|
55
|
-
*
|
|
56
|
-
* Copyright (c) Buoy. All rights reserved. Licensed under the Buoy EULA
|
|
57
|
-
* (https://buoy.gg/terms), not an OSS license.
|
|
58
|
-
*//*!
|
|
59
|
-
* PROPRIETARY — Buoy Pro license enforcement. NOT open source.
|
|
60
|
-
*
|
|
61
|
-
* Copyright (c) Buoy. All rights reserved. Licensed under the Buoy EULA
|
|
62
|
-
* (https://buoy.gg/terms), not an OSS license.
|
|
63
|
-
*
|
|
64
|
-
* This file is the technological measure that controls access to paid Buoy Pro
|
|
65
|
-
* features. Modifying, patching, aliasing, stubbing, or otherwise altering it
|
|
66
|
-
* so that Pro features unlock without a valid license is a breach of the EULA
|
|
67
|
-
* and, in the United States, circumvention of an access control under
|
|
68
|
-
* 17 U.S.C. § 1201 — which applies whether or not any code is copied.
|
|
69
|
-
*
|
|
70
|
-
* Pro is $9/mo, and is free every weekend for anyone holding a key —
|
|
71
|
-
* including a free one (`npx buoy login`). Buy a key at
|
|
72
|
-
* https://buoy.gg or use it free on Saturday and Sunday.
|
|
73
|
-
*/
|