@buoy-gg/license 7.0.43 → 7.0.44

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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.subscribeForeground=subscribeForeground;var _reactNative=require("react-native");function subscribeForeground(e){const r=_reactNative.AppState?.addEventListener("change",t=>{if(t==="active")e()});return()=>r?.remove()}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.subscribeForeground=subscribeForeground;var _reactNative=require("react-native");function countOwn(r){const t=globalThis;const e=t.__buoyOwnDeviceListeners??={};e.appStateDidChange=Math.max(0,(e.appStateDidChange??0)+r)}function subscribeForeground(r){const t=_reactNative.DeviceEventEmitter?.addListener("appStateDidChange",e=>{if(e&&!e.__buoySynthetic&&e.app_state==="active")r()});if(!t)return()=>{};countOwn(1);return()=>{t.remove();countOwn(-1)}}
@@ -1 +1 @@
1
- "use strict";import{AppState as i}from"react-native";export function subscribeForeground(e){const t=i?.addEventListener("change",r=>{if(r==="active")e()});return()=>t?.remove()}
1
+ "use strict";import{DeviceEventEmitter as a}from"react-native";function n(i){const t=globalThis;const e=t.__buoyOwnDeviceListeners??={};e.appStateDidChange=Math.max(0,(e.appStateDidChange??0)+i)}export function subscribeForeground(i){const t=a?.addListener("appStateDidChange",e=>{if(e&&!e.__buoySynthetic&&e.app_state==="active")i()});if(!t)return()=>{};n(1);return()=>{t.remove();n(-1)}}
@@ -1,3 +1,8 @@
1
- /** The native host wakes timers on resume; also recheck before rendering tools. */
1
+ /**
2
+ * The native host wakes timers on resume; also recheck before rendering tools.
3
+ * Listens to the raw event so @buoy-gg/lifecycle's simulated returns (payloads
4
+ * marked `__buoySynthetic`) don't trigger a recheck. Same rule as shared's
5
+ * subscribeRealAppState, which this package sits below.
6
+ */
2
7
  export declare function subscribeForeground(refresh: () => void): () => void;
3
8
  //# sourceMappingURL=foreground.d.ts.map
@@ -1,3 +1,8 @@
1
- /** The native host wakes timers on resume; also recheck before rendering tools. */
1
+ /**
2
+ * The native host wakes timers on resume; also recheck before rendering tools.
3
+ * Listens to the raw event so @buoy-gg/lifecycle's simulated returns (payloads
4
+ * marked `__buoySynthetic`) don't trigger a recheck. Same rule as shared's
5
+ * subscribeRealAppState, which this package sits below.
6
+ */
2
7
  export declare function subscribeForeground(refresh: () => void): () => void;
3
8
  //# sourceMappingURL=foreground.d.ts.map
@@ -0,0 +1 @@
1
+ "use client";import{LicenseManager as e}from"./chunk-OPWF6JR6.mjs";export{e as LicenseManager};
@@ -0,0 +1 @@
1
+ "use client";import{e}from"./chunk-GRUXDUJG.mjs";export{e as LicenseManager};
@@ -0,0 +1 @@
1
+ "use client";import{LicenseManager as e}from"./chunk-TVOTAEQX.mjs";export{e as LicenseManager};
@@ -0,0 +1,68 @@
1
+ "use client";var o=process.env.NODE_ENV!=="production";typeof window<"u"&&typeof globalThis.global>"u"&&(globalThis.global=globalThis);var w=new Map,se={async getItem(e){try{return localStorage.getItem(e)??w.get(e)??null}catch{return w.get(e)??null}},async setItem(e,t){w.set(e,t);try{localStorage.setItem(e,t)}catch{}},async removeItem(e){w.delete(e);try{localStorage.removeItem(e)}catch{}}};async function f(){return se}var E={accountId:"b0eba0e8-e904-4906-b644-38f9aab57bed",productId:"bf67cb43-eeef-40ca-b308-e6e1b22c0eaa",apiUrl:"https://buoy.gg/api/license"},ne="3b546fc717a62683f3236c70167899a271bee3ffc04df6ec1eea60a394a2f1e9",_={free:"394e3351-1249-4f73-807a-703408604c0e",solo:"fa5d3c8f-5379-40f1-b63e-ab8a974b2f28",business:"690c2212-8e54-426f-b4b4-002ee1c0ae2b"},T=720*60*60*1e3,ae=1440*60*1e3,C="buoy-gg-license",P="buoy-gg-device-fingerprint",le=3600*1e3,oe=[5*1e3,20*1e3,60*1e3,300*1e3,900*1e3],ce=60*1e3,F=3600*1e3,he=1440*60*1e3,de=50,ue=T,b="buoy-gg-license-hold";var{apiUrl:U}=E,g=class extends Error{constructor(e,t,i=null){super(e);this.isTransient=true;this.name="LicenseTransportError",this.status=t,this.retryAfterMs=i}};function fe(e){let t=e?.status;return t===429||t===402}function ye(e,t,i){return e.status===402?t:e.retryAfterMs??i}function pe(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-Date.now())}let r=Number(t("X-RateLimit-Reset"));return Number.isFinite(r)&&r>0?Math.max(0,r*1e3-Date.now()):null}function H(e){return e instanceof g||e instanceof TypeError?true:typeof e=="object"&&e!==null&&e.isTransient===true}async function ge(e){try{return(await e.json()).errors?.[0]?.detail||`HTTP ${e.status}`}catch{return`HTTP ${e.status}`}}function G(){return{"Content-Type":"application/vnd.api+json",Accept:"application/vnd.api+json"}}async function me(e,t){let i=`${U}/validate`,r={meta:{key:e}},s;try{s=await fetch(i,{signal:t,method:"POST",headers:G(),body:JSON.stringify(r)})}catch(n){throw new g(n instanceof Error?n.message:"Network request failed",null)}if(!s.ok)throw new g(await ge(s),s.status,s.status===429?pe(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 g("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([me(e,t?.signal),new Promise((r,s)=>{i=setTimeout(()=>{s(new g("License verification timed out. Please retry.",null)),t?.abort()},15e3)})])}finally{i&&clearTimeout(i)}}function Ae(e){if(!e.data)return false;let t=e.data.relationships?.product?.data?.id;return t&&t!==E.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 we(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=`${U}/machines`,d=await fetch(n,{method:"POST",headers:G(),body:JSON.stringify({licenseId:e,licenseKey:t,fingerprint:i,name:r,metadata:s||{}})});if(!d.ok){let l=await d.json(),a=l.errors?.[0]?.code;if(a==="FINGERPRINT_TAKEN")throw new Error("FINGERPRINT_TAKEN");if(a==="MACHINE_LIMIT_EXCEEDED")throw new Error("MACHINE_LIMIT_EXCEEDED");let c=l.errors?.[0]?.detail||`HTTP ${d.status}`;throw new Error(c)}return d.json()}function Ee(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 B(){if(typeof o<"u")return o;try{if(typeof navigator<"u"&&/electron/i.test(navigator.userAgent))return true}catch{}return typeof process<"u"&&process.env.NODE_ENV!=="production"}function $(){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 Te(){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 Y(){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 X(){let e={platform:$(),osVersion:Te(),isSimulator:"false"},t=Y();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 K(){let e=$(),t=Y();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 Ie=["v1"],Re="buoy.gg/pro:9f3c1d7a4b2e:license-cache";function j(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 Le(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(Re),i.join("\0")}function q(e,t){let i=Le(e,t),r=j(i,2166136261),s=j(i,2135587861);return`${t}.${r.toString(16)}${s.toString(16)}`}function J(e){return q(e,"v2")}function W(e){return{...e,sig:J(e)}}function m(e){return!e||typeof e.sig!="string"||e.sig.length===0?false:e.sig===J(e)?true:Ie.some(t=>e.sig.startsWith(`${t}.`)&&e.sig===q(e,t))}import xe from"tweetnacl";var Ne=1,Ce=1,Pe="buoy-free-token-v1:",be=22,De=64,Z=/^BUOY1-([A-Z2-7]+)-([A-Z2-7]+)$/;function Q(e){return Z.test(e.trim().toUpperCase())}var Ke="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";function ee(e){let t=[],i=0,r=0;for(let s of e){let n=Ke.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 Me(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 Se(e){let t="";for(let i of e)t+=i.toString(16).padStart(2,"0");return t}function Ve(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 ke(e,t){let i=new Uint8Array(e.length+t.length);return i.set(e,0),i.set(t,e.length),i}function Oe(e){return ke(Ve(Pe),e)}var Fe=ne;function Ue(e,t=Fe){let i=Z.exec(e.trim().toUpperCase());if(!i)return null;let r=ee(i[1]),s=ee(i[2]);if(!r||!s||r.length!==be||s.length!==De||r[0]!==Ne||r[1]!==Ce)return null;try{if(!xe.sign.detached.verify(Oe(r),s,Me(t)))return null}catch{return null}return{tier:"free",issuedAt:((r[2]<<24>>>0)+(r[3]<<16)+(r[4]<<8)+r[5])*1e3,accountHash:Se(r.slice(6,22))}}function He(e){let t=e.relationships?.policy?.data?.id;return t===_.free?"free":t===_.solo||t===_.business?"pro":e.attributes?.metadata?.plan==="free"?"free":"pro"}function Ge(e){if(!e)return false;let t=e.relationships?.product?.data?.id;if(t)return t===E.productId;let i=e.relationships?.policy?.data?.id;return Object.values(_).some(r=>r===i)}function te(e,t=Date.now()){let i=e.verifiedAt!==null&&Number.isFinite(e.verifiedAt)&&e.verifiedAt<=t?e.verifiedAt+T: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 ze(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)}}async function y(e,t){let i;try{return await Promise.race([e,new Promise(r=>{i=setTimeout(()=>r(t),15e3)})])}finally{i&&clearTimeout(i)}}function v(e){return e.tier==="pro"||e.tier==="free"?e.tier:e.isPro?"pro":"free"}var Be=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.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;try{let t=await y(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=m(t);this.cachedLicense=t,this.state.licenseKey=t.licenseKey,i&&this.isCacheValid(t)?this.applyTier(v(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()}),Q(i))return this.admitToken(i,r);if(!this.cachedLicense){let a=await y(this.loadCachedLicense(),null);if(r!==this.generation)return false;a?.licenseKey===i&&(this.cachedLicense=a,m(a)&&this.isCacheValid(a)&&(this.applyTier(v(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&&m(s)&&this.isCacheValid(s)&&this.isCacheFresh(s))return this.applyTier(v(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 y(this.loadHold(),null);if(r!==this.generation)return false;let d=(n?.backoffUntil??0)-Date.now();if(d>0)return this.standDown(i,r,"License server is rate limited; retrying later.",d);if(!t?.force&&n?.key===i&&n.verdictAt!==void 0&&Date.now()-n.verdictAt>=0&&Date.now()-n.verdictAt<he)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 l;try{l=await ve(i)}catch(a){let c=a instanceof Error?a.message:"Validation failed";if(r!==this.generation)return false;if(H(a)){if(fe(a)){let u=Math.min(ye(a,F,ce)*2**this.retryAttempt,F);return this.retryAttempt+=1,await this.saveHold({...this.hold,backoffUntil:Date.now()+u}),r!==this.generation?false:this.standDown(i,r,c,u)}return this.state.isValidating=false,this.cachedLicense&&this.cachedLicense.licenseKey===i&&m(this.cachedLicense)&&this.isCacheValid(this.cachedLicense)?(this.applyTier(v(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.isPro()||this.scheduleRetry(i),this.emit({type:"validated",isPro:this.state.isPro}),true):(this.state.error=c,this.state.errorKind="transport",this.scheduleRetry(i),this.emit({type:"error",isPro:this.state.isPro,error:c}),false)}return this.state.isValidating=false,this.state.error=c,this.state.errorKind="verdict",this.emit({type:"error",isPro:false,error:c}),false}try{if(r!==this.generation)return false;let a=Ee(l),c=l.data?.relationships?.product?.data?.id;if((!c||c===E.productId)&&a.code==="EXPIRED"&&(Ge(l.data)||this.cachedLicense?.licenseKey===i&&m(this.cachedLicense)&&this.isCacheValid(this.cachedLicense))){let N=Date.now(),O=await this.saveCache({licenseKey:i,licenseId:l.data?.id??"",valid:true,isPro:false,tier:"free",expiresAt:null,cachedAt:N,lastValidatedAt:N,fingerprint:this.cachedLicense?.licenseKey===i?this.cachedLicense.fingerprint:void 0},r);return r!==this.generation||!O?false:(this.cachedLicense=O,this.applyTier("free"),this.state.isValidating=false,this.state.expiresAt=null,this.setVerifiedAt(N),this.emit({type:"validated",isPro:false}),true)}if(_e(a.code)||!Ae(l))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:Date.now()}),false;if(!l.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=He(l.data),I=l.data.id,R=Date.now(),M=we(l)>=de,S=B(),ie=S&&!M,re=u==="free"&&(M||!S),p=this.cachedLicense?.fingerprint,A=this.cachedLicense?.deviceName,V=false;if(!p){if(p=await y(this.getOrCreateDeviceFingerprint(),D()),r!==this.generation)return false;A=K(),V=ie}let L=false;V&&(this.deviceRegistrationCallback?(this.pendingRegistration={licenseId:I,licenseKey:i,fingerprint:p},this.deviceRegistrationCallback({fingerprint:p,defaultName:A}),L=true):this.registerDeviceAsync(I,i,p,A));let x={licenseKey:i,licenseId:I,valid:true,isPro:u==="pro",tier:u,expiresAt:l.data.attributes.expiry??null,cachedAt:R,lastValidatedAt:R,fingerprint:L?void 0:p,deviceName:L?void 0:A,quiet:re||void 0},k=await this.saveCache(x,r);return r!==this.generation||!k||(this.cachedLicense=k,this.applyTier(u),this.state.isValidating=false,this.state.expiresAt=x.expiresAt?new Date(x.expiresAt):null,this.setVerifiedAt(R),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 c=a instanceof Error?a.message:"Validation failed";return r!==this.generation||(this.state.isValidating=false,this.state.error=c,this.state.errorKind="verdict",this.emit({type:"error",isPro:false,error:c})),false}}scheduleRetry(e){this.cancelRetry();let t=oe[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 o<"u"&&o&&(globalThis.__LICENSE_MANAGER_RETRY_TIMER__=this.retryTimer)}async admitToken(e,t){let i=Ue(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=Date.now(),s=this.cachedLicense?.fingerprint??await y(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??K(),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&&m(s)&&this.isCacheValid(s)?(this.applyTier(v(s)),this.state.error=null,this.state.errorKind=null,this.state.expiresAt=s.expiresAt?new Date(s.expiresAt):null,this.setVerifiedAt(s.cachedAt),this.isPro()||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 o<"u"&&o&&(h.__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.hasAccountAccess()||this.state.expiresAt&&Date.now()>=this.state.expiresAt.getTime()?"free":this.state.tier}isPro(){return this.getTier()==="pro"}hasEntitlement(e){return this.isPro()}getState(){let e=this.getAccountAccess(),t=this.getTier();return{...this.state,tier:t,isPro:t==="pro",access:e}}getAccountAccess(){return te({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"}setVerifiedAt(e){this.verifiedAt=e,this.expiryTimer&&clearTimeout(this.expiryTimer);let t=e+T,i=this.state.expiresAt?.getTime(),r=(i&&i>Date.now()?Math.min(t,i):t)-Date.now();this.expiryTimer=setTimeout(()=>{this.expiryTimer=null,this.verifiedAt===e&&(this.emit({type:"validated",isPro:this.isPro()}),Date.now()<t&&this.setVerifiedAt(e))},Math.max(1,Math.min(r,2147483647))),typeof o<"u"&&o&&(h.__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()||K(),d=X();try{await z(t,i,r,n,d)}catch(l){let a=l instanceof Error?l.message:String(l);if(!(a==="FINGERPRINT_TAKEN"||a==="MACHINE_LIMIT_EXCEEDED"))throw console.warn("[Buoy] Device registration failed:",a),l}if(s===this.generation){if(this.cachedLicense?.licenseKey===i){let l=await this.saveCache({...this.cachedLicense,fingerprint:r,deviceName:n},s);if(s!==this.generation)return;l&&(this.cachedLicense=l)}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=Date.now()-e.cachedAt;return!(!e.valid||!Number.isFinite(e.cachedAt)||t<0||t>=T)}isCacheFresh(e){let t=this.isQuiet(e)?ue:le;return Date.now()-(e.lastValidatedAt??0)<t}isQuiet(e){return e.quiet!==void 0?e.quiet:v(e)==="free"&&!B()}async loadHold(){if(this.hold!==void 0)return this.hold;try{let e=await(await f()).getItem(b),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 f();e?await t.setItem(b,JSON.stringify(e)):await t.removeItem(b)}catch{}}async persistCache(e){let t=W(e);return await(await f()).setItem(C,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,y(i,W(e))}async loadCachedLicense(){try{await this.persistence.catch(()=>{});let e=await(await f()).getItem(C);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 f(),t=await e.getItem(P);if(t)return t;let i=this.cachedLicense?.fingerprint||D();return await e.setItem(P,i),i})()),this.fingerprintPromise}async clearCachedLicense(){this.cachedLicense=null;let e=this.persistence.catch(()=>{}).then(async()=>{await(await f()).removeItem(C)});this.persistence=e,await y(e.catch(()=>{}),void 0)}registerDeviceAsync(e,t,i,r){let s=X();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=ze(()=>this.refreshAccess()),typeof o<"u"&&o&&(h.__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)},ae),typeof o<"u"&&o&&(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 f()).removeItem(P)}catch{}}},$e=new Be,h=globalThis;typeof o<"u"&&o&&(h.__LICENSE_MANAGER_FOREGROUND_OFF__?.(),h.__LICENSE_MANAGER_FOREGROUND_OFF__=void 0,h.__LICENSE_MANAGER_EXPIRY_TIMER__&&clearTimeout(h.__LICENSE_MANAGER_EXPIRY_TIMER__),h.__LICENSE_MANAGER_TIMER__&&clearInterval(h.__LICENSE_MANAGER_TIMER__),h.__LICENSE_MANAGER_RETRY_TIMER__&&(clearTimeout(h.__LICENSE_MANAGER_RETRY_TIMER__),h.__LICENSE_MANAGER_RETRY_TIMER__=void 0));export{g as a,H as b,Q as c,te as d,$e as e};/*!
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 Pro 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
+ * This file is the technological measure that controls access to paid Buoy Pro
60
+ * features. Modifying, patching, aliasing, stubbing, or otherwise altering it
61
+ * so that Pro features unlock without a valid license is a breach of the EULA
62
+ * and, in the United States, circumvention of an access control under
63
+ * 17 U.S.C. § 1201 — which applies whether or not any code is copied.
64
+ *
65
+ * Pro is $9/mo, and is free every weekend for anyone holding a key —
66
+ * including a free one (`npx buoy login`). Buy a key at
67
+ * https://buoy.gg or use it free on Saturday and Sunday.
68
+ */
@@ -0,0 +1,68 @@
1
+ "use client";var c=process.env.NODE_ENV!=="production";var w=new Map;var se={async getItem(e){try{return localStorage.getItem(e)??w.get(e)??null}catch{return w.get(e)??null}},async setItem(e,t){w.set(e,t);try{localStorage.setItem(e,t)}catch{}},async removeItem(e){w.delete(e);try{localStorage.removeItem(e)}catch{}}};async function f(){return se}var E={accountId:"b0eba0e8-e904-4906-b644-38f9aab57bed",productId:"bf67cb43-eeef-40ca-b308-e6e1b22c0eaa",apiUrl:"https://buoy.gg/api/license"};var ne="3b546fc717a62683f3236c70167899a271bee3ffc04df6ec1eea60a394a2f1e9";var _={free:"394e3351-1249-4f73-807a-703408604c0e",solo:"fa5d3c8f-5379-40f1-b63e-ab8a974b2f28",business:"690c2212-8e54-426f-b4b4-002ee1c0ae2b"};var T=30*24*60*60*1e3;var ae=24*60*60*1e3;var C="buoy-gg-license";var P="buoy-gg-device-fingerprint";var oe=60*60*1e3;var ce=[5*1e3,20*1e3,60*1e3,5*60*1e3,15*60*1e3];var le=60*1e3;var F=60*60*1e3;var he=24*60*60*1e3;var ue=50;var de=T;var b="buoy-gg-license-hold";var{apiUrl:U}=E;var m=class extends Error{constructor(e,t,i=null){super(e);this.isTransient=true;this.name="LicenseTransportError";this.status=t;this.retryAfterMs=i}};function fe(e){const t=e?.status;return t===429||t===402}function ye(e,t,i){if(e.status===402)return t;return e.retryAfterMs??i}function pe(e){const t=s=>{try{return e.headers?.get?.(s)??null}catch{return null}};const i=t("Retry-After");if(i){const s=Number(i);if(Number.isFinite(s)&&s>=0)return s*1e3;const n=Date.parse(i);if(Number.isFinite(n))return Math.max(0,n-Date.now())}const r=Number(t("X-RateLimit-Reset"));if(Number.isFinite(r)&&r>0)return Math.max(0,r*1e3-Date.now());return null}function H(e){if(e instanceof m)return true;if(e instanceof TypeError)return true;return typeof e==="object"&&e!==null&&e.isTransient===true}async function me(e){try{const t=await e.json();return t.errors?.[0]?.detail||`HTTP ${e.status}`}catch{return`HTTP ${e.status}`}}function G(){return{"Content-Type":"application/vnd.api+json",Accept:"application/vnd.api+json"}}async function ge(e,t){const i=`${U}/validate`;const r={meta:{key:e}};let s;try{s=await fetch(i,{signal:t,method:"POST",headers:G(),body:JSON.stringify(r)})}catch(n){throw new m(n instanceof Error?n.message:"Network request failed",null)}if(!s.ok){throw new m(await me(s),s.status,s.status===429?pe(s):null)}try{const 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 m("License server returned an unreadable response",s.status)}}async function ve(e){const t=typeof AbortController==="function"?new AbortController:null;let i;try{return await Promise.race([ge(e,t?.signal),new Promise((r,s)=>{i=setTimeout(()=>{s(new m("License verification timed out. Please retry.",null));t?.abort()},15e3)})])}finally{if(i)clearTimeout(i)}}function Ae(e){if(!e.data)return false;const t=e.data.relationships?.product?.data?.id;if(t&&t!==E.productId)return false;if(e.meta.valid&&e.meta.code==="VALID")return true;return["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 we(e){const t=e.data?.relationships?.machines?.meta?.count;return typeof t==="number"&&Number.isFinite(t)?t:0}async function z(e,t,i,r,s){const n=`${U}/machines`;const u=await fetch(n,{method:"POST",headers:G(),body:JSON.stringify({licenseId:e,licenseKey:t,fingerprint:i,name:r,metadata:s||{}})});if(!u.ok){const o=await u.json();const 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")}const l=o.errors?.[0]?.detail||`HTTP ${u.status}`;throw new Error(l)}return u.json()}function Ee(e){const{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(){if(typeof crypto!=="undefined"&&crypto.randomUUID){return crypto.randomUUID()}return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=Math.random()*16|0;const i=e==="x"?t:t&3|8;return i.toString(16)})}function B(){if(typeof c!=="undefined")return c;try{if(typeof navigator!=="undefined"&&/electron/i.test(navigator.userAgent))return true}catch{}return typeof process!=="undefined"&&process.env.NODE_ENV!=="production"}function $(){if(typeof navigator==="undefined"){return"unknown"}const e=navigator.userAgent.toLowerCase();const t=navigator.platform?.toLowerCase()||"";if(e.includes("electron")){if(t.includes("mac")||e.includes("mac")){return"electron-macos"}if(t.includes("win")||e.includes("win")){return"electron-windows"}if(t.includes("linux")||e.includes("linux")){return"electron-linux"}return"electron"}if(t.includes("mac")||e.includes("mac")){return"macos"}if(t.includes("win")||e.includes("win")){return"windows"}if(t.includes("linux")||e.includes("linux")){return"linux"}if(/iphone|ipad|ipod/.test(e)){return"ios-web"}if(e.includes("android")){return"android-web"}return"web"}function Te(){if(typeof navigator==="undefined"){return"unknown"}const e=navigator.userAgent;const t=e.match(/Mac OS X ([\d_.]+)/);if(t){return t[1].replace(/_/g,".")}const i=e.match(/Windows NT ([\d.]+)/);if(i){const r={"10.0":"10/11","6.3":"8.1","6.2":"8","6.1":"7"};return r[i[1]]||i[1]}if(e.includes("Linux")){return"Linux"}return"unknown"}function Y(){if(typeof navigator==="undefined"){return{name:"unknown",version:"unknown"}}const e=navigator.userAgent;const t=e.match(/Electron\/([\d.]+)/);if(t){return{name:"Electron",version:t[1]}}const i=e.match(/Chrome\/([\d.]+)/);if(i&&!e.includes("Edg")){return{name:"Chrome",version:i[1]}}const r=e.match(/Edg\/([\d.]+)/);if(r){return{name:"Edge",version:r[1]}}const s=e.match(/Firefox\/([\d.]+)/);if(s){return{name:"Firefox",version:s[1]}}const n=e.match(/Version\/([\d.]+).*Safari/);if(n){return{name:"Safari",version:n[1]}}return{name:"unknown",version:"unknown"}}function j(){const e={platform:$(),osVersion:Te(),isSimulator:"false"};const t=Y();e.browser=t.name;e.browserVersion=t.version;if(typeof window!=="undefined"&&window.screen){e.screenResolution=`${window.screen.width}x${window.screen.height}`}if(typeof navigator!=="undefined"&&navigator.language){e.language=navigator.language}try{e.timezone=Intl.DateTimeFormat().resolvedOptions().timeZone}catch{}return e}function K(){const e=$();const t=Y();if(e.startsWith("electron")){const i=e.replace("electron-","").replace("electron","Desktop");return`${i.charAt(0).toUpperCase()+i.slice(1)} App`}if(t.name!=="unknown"){return`${t.name} Browser`}return"Web Browser"}var Ie="v2";var Re=["v1"];var Le="buoy.gg/pro:9f3c1d7a4b2e:license-cache";var xe="\0";function X(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 Ne(e,t){const i=[t,e.licenseKey,e.licenseId,e.isPro?"1":"0",e.expiresAt??"",String(e.cachedAt)];if(t!=="v1"){i.push(e.tier??"")}i.push(Le);return i.join(xe)}function q(e,t){const i=Ne(e,t);const r=X(i,2166136261);const s=X(i,2135587861);return`${t}.${r.toString(16)}${s.toString(16)}`}function J(e){return q(e,Ie)}function W(e){return{...e,sig:J(e)}}function g(e){if(!e||typeof e.sig!=="string"||e.sig.length===0){return false}if(e.sig===J(e))return true;return Re.some(t=>e.sig.startsWith(`${t}.`)&&e.sig===q(e,t))}import Ce from"tweetnacl";var Pe=1;var be=1;var De="buoy-free-token-v1:";var Ke=22;var Me=64;var Z=/^BUOY1-([A-Z2-7]+)-([A-Z2-7]+)$/;function Q(e){return Z.test(e.trim().toUpperCase())}var Se="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";function ee(e){const t=[];let i=0;let r=0;for(const s of e){const n=Se.indexOf(s);if(n===-1)return null;r=r<<5|n;i+=5;if(i>=8){t.push(r>>>i-8&255);i-=8}}return new Uint8Array(t)}function Ve(e){const t=e.trim().toLowerCase();const 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 ke(e){let t="";for(const i of e)t+=i.toString(16).padStart(2,"0");return t}function Oe(e){if(typeof TextEncoder!=="undefined")return new TextEncoder().encode(e);const t=new Uint8Array(e.length);for(let i=0;i<e.length;i+=1)t[i]=e.charCodeAt(i)&255;return t}function Fe(e,t){const i=new Uint8Array(e.length+t.length);i.set(e,0);i.set(t,e.length);return i}function Ue(e){return Fe(Oe(De),e)}var He=ne;function Ge(e,t=He){const i=Z.exec(e.trim().toUpperCase());if(!i)return null;const r=ee(i[1]);const s=ee(i[2]);if(!r||!s)return null;if(r.length!==Ke||s.length!==Me)return null;if(r[0]!==Pe||r[1]!==be)return null;try{if(!Ce.sign.detached.verify(Ue(r),s,Ve(t)))return null}catch{return null}const n=(r[2]<<24>>>0)+(r[3]<<16)+(r[4]<<8)+r[5];return{tier:"free",issuedAt:n*1e3,accountHash:ke(r.slice(6,22))}}function ze(e){const t=e.relationships?.policy?.data?.id;if(t===_.free)return"free";if(t===_.solo||t===_.business){return"pro"}const i=e.attributes?.metadata?.plan;if(i==="free")return"free";return"pro"}function Be(e){if(!e)return false;const t=e.relationships?.product?.data?.id;if(t)return t===E.productId;const i=e.relationships?.policy?.data?.id;return Object.values(_).some(r=>r===i)}function te(e,t=Date.now()){const i=e.verifiedAt!==null&&Number.isFinite(e.verifiedAt)&&e.verifiedAt<=t?e.verifiedAt+T:null;if(e.initialized&&e.key&&e.tierSource!=="none"&&i!==null&&t<i){return{status:"admitted",reason:null,validUntil:i}}if(i!==null&&t>=i){return{status:"locked",reason:"verification_expired",validUntil:i}}if(!e.initialized||e.validating){return{status:"initializing",reason:"checking",validUntil:i}}return{status:"locked",reason:i!==null&&t>=i?"verification_expired":"account_required",validUntil:i}}function $e(e){if(typeof window==="undefined"||typeof window.addEventListener!=="function")return()=>{};const t=()=>{if(!document.hidden)e()};window.addEventListener("focus",e);document.addEventListener("visibilitychange",t);return()=>{window.removeEventListener("focus",e);document.removeEventListener("visibilitychange",t)}}async function y(e,t){let i;try{return await Promise.race([e,new Promise(r=>{i=setTimeout(()=>r(t),15e3)})])}finally{if(i)clearTimeout(i)}}function v(e){if(e.tier==="pro"||e.tier==="free")return e.tier;return e.isPro?"pro":"free"}var Ye=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.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();return this.initPromise}async _doInitialize(){if(this.state.isInitialized)return;const e=this.generation;try{const t=await y(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)){const i=g(t);this.cachedLicense=t;this.state.licenseKey=t.licenseKey;if(i&&this.isCacheValid(t))this.applyTier(v(t));else this.lock();this.state.expiresAt=t.expiresAt?new Date(t.expiresAt):null;if(i&&this.isCacheValid(t))this.setVerifiedAt(t.cachedAt);if(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){await this.initialize();return this.hasAccountAccess()}const t=e.trim().toUpperCase();const i=++this.generation;this.cancelRetry();this.configuredKey=t||null;if(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();if(i!==this.generation)return false;if(!t){await this.clearLicense();return false}return this.setLicenseKey(t)}async setLicenseKey(e,t){if(!e||e.trim().length===0){this.state.error="License key is required";this.state.errorKind="verdict";return false}const i=e.trim().toUpperCase();const r=++this.generation;this.cancelRetry();if(!t?.isRetry)this.retryAttempt=0;if(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()});if(Q(i))return this.admitToken(i,r);if(!this.cachedLicense){const a=await y(this.loadCachedLicense(),null);if(r!==this.generation)return false;if(a?.licenseKey===i){this.cachedLicense=a;if(g(a)&&this.isCacheValid(a)){this.applyTier(v(a));this.state.expiresAt=a.expiresAt?new Date(a.expiresAt):null;this.setVerifiedAt(a.cachedAt);this.emit({type:"validating",isPro:this.isPro()})}}}const s=this.cachedLicense;if(!t?.force&&s&&s.valid&&s.licenseKey===i&&s.fingerprint&&g(s)&&this.isCacheValid(s)&&this.isCacheFresh(s)){this.applyTier(v(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});return true}const n=await y(this.loadHold(),null);if(r!==this.generation)return false;const u=(n?.backoffUntil??0)-Date.now();if(u>0){return this.standDown(i,r,"License server is rate limited; retrying later.",u)}if(!t?.force&&n?.key===i&&n.verdictAt!==void 0&&Date.now()-n.verdictAt>=0&&Date.now()-n.verdictAt<he){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});return false}let o;try{o=await ve(i)}catch(a){const l=a instanceof Error?a.message:"Validation failed";if(r!==this.generation)return false;if(H(a)){if(fe(a)){const d=Math.min(ye(a,F,le)*2**this.retryAttempt,F);this.retryAttempt+=1;await this.saveHold({...this.hold,backoffUntil:Date.now()+d});if(r!==this.generation)return false;return this.standDown(i,r,l,d)}this.state.isValidating=false;if(this.cachedLicense&&this.cachedLicense.licenseKey===i&&g(this.cachedLicense)&&this.isCacheValid(this.cachedLicense)){this.applyTier(v(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);if(!this.isPro())this.scheduleRetry(i);this.emit({type:"validated",isPro:this.state.isPro});return true}this.state.error=l;this.state.errorKind="transport";this.scheduleRetry(i);this.emit({type:"error",isPro:this.state.isPro,error:l});return false}this.state.isValidating=false;this.state.error=l;this.state.errorKind="verdict";this.emit({type:"error",isPro:false,error:l});return false}try{if(r!==this.generation)return false;const a=Ee(o);const l=o.data?.relationships?.product?.data?.id;if((!l||l===E.productId)&&a.code==="EXPIRED"&&(Be(o.data)||this.cachedLicense?.licenseKey===i&&g(this.cachedLicense)&&this.isCacheValid(this.cachedLicense))){const N=Date.now();const O=await this.saveCache({licenseKey:i,licenseId:o.data?.id??"",valid:true,isPro:false,tier:"free",expiresAt:null,cachedAt:N,lastValidatedAt:N,fingerprint:this.cachedLicense?.licenseKey===i?this.cachedLicense.fingerprint:void 0},r);if(r!==this.generation||!O)return false;this.cachedLicense=O;this.applyTier("free");this.state.isValidating=false;this.state.expiresAt=null;this.setVerifiedAt(N);this.emit({type:"validated",isPro:false});return true}if(_e(a.code)||!Ae(o)){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:Date.now()});return false}if(!o.data){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();return false}const d=ze(o.data);const I=o.data.id;const R=Date.now();const M=we(o)>=ue;const S=B();const ie=S&&!M;const re=d==="free"&&(M||!S);let p=this.cachedLicense?.fingerprint;let A=this.cachedLicense?.deviceName;let V=false;if(!p){p=await y(this.getOrCreateDeviceFingerprint(),D());if(r!==this.generation)return false;A=K();V=ie}let L=false;if(V){if(this.deviceRegistrationCallback){this.pendingRegistration={licenseId:I,licenseKey:i,fingerprint:p};this.deviceRegistrationCallback({fingerprint:p,defaultName:A});L=true}else{this.registerDeviceAsync(I,i,p,A)}}const x={licenseKey:i,licenseId:I,valid:true,isPro:d==="pro",tier:d,expiresAt:o.data.attributes.expiry??null,cachedAt:R,lastValidatedAt:R,fingerprint:L?void 0:p,deviceName:L?void 0:A,quiet:re||void 0};const k=await this.saveCache(x,r);if(r!==this.generation||!k)return false;this.cachedLicense=k;this.applyTier(d);this.state.isValidating=false;this.state.expiresAt=x.expiresAt?new Date(x.expiresAt):null;this.setVerifiedAt(R);if(this.hold)await this.saveHold(null);if(r!==this.generation)return false;this.retryAttempt=0;this.emit({type:"validated",isPro:this.state.isPro});return true}catch(a){const l=a instanceof Error?a.message:"Validation failed";if(r!==this.generation)return false;this.state.isValidating=false;this.state.error=l;this.state.errorKind="verdict";this.emit({type:"error",isPro:false,error:l});return false}}scheduleRetry(e){this.cancelRetry();const t=ce[this.retryAttempt];if(t===void 0)return;this.retryAttempt+=1;const i=this.generation;this.retryTimer=setTimeout(()=>{this.retryTimer=null;if(i!==this.generation)return;if(this.state.isValidating)return;void this.setLicenseKey(e,{force:true,isRetry:true})},t);if(typeof c!=="undefined"&&c){globalThis.__LICENSE_MANAGER_RETRY_TIMER__=this.retryTimer}}async admitToken(e,t){const i=Ge(e);if(t!==this.generation)return false;if(!i){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();return false}const r=Date.now();const s=this.cachedLicense?.fingerprint??await y(this.getOrCreateDeviceFingerprint(),D());if(t!==this.generation)return false;const 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??K(),quiet:true},t);if(t!==this.generation||!n)return 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});return true}standDown(e,t,i,r){if(t!==this.generation)return false;this.state.isValidating=false;const s=this.cachedLicense;if(s&&s.licenseKey===e&&g(s)&&this.isCacheValid(s)){this.applyTier(v(s));this.state.error=null;this.state.errorKind=null;this.state.expiresAt=s.expiresAt?new Date(s.expiresAt):null;this.setVerifiedAt(s.cachedAt);if(!this.isPro())this.scheduleRetryIn(e,r);this.emit({type:"validated",isPro:this.state.isPro});return true}this.state.error=i;this.state.errorKind="transport";this.scheduleRetryIn(e,r);this.emit({type:"error",isPro:this.state.isPro,error:i});return false}scheduleRetryIn(e,t){this.cancelRetry();const i=this.generation;this.retryTimer=setTimeout(()=>{this.retryTimer=null;if(i!==this.generation)return;if(this.state.isValidating)return;void this.setLicenseKey(e,{force:true,isRetry:true})},Math.max(1,Math.min(t,2147483647)));if(typeof c!=="undefined"&&c)h.__LICENSE_MANAGER_RETRY_TIMER__=this.retryTimer}cancelRetry(){if(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();if(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;if(this.expiryTimer)clearTimeout(this.expiryTimer);this.expiryTimer=null}getTier(){if(!this.hasAccountAccess())return"free";if(this.state.expiresAt&&Date.now()>=this.state.expiresAt.getTime())return"free";return this.state.tier}isPro(){return this.getTier()==="pro"}hasEntitlement(e){return this.isPro()}getState(){const e=this.getAccountAccess();const t=this.getTier();return{...this.state,tier:t,isPro:t==="pro",access:e}}getAccountAccess(){return te({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"}setVerifiedAt(e){this.verifiedAt=e;if(this.expiryTimer)clearTimeout(this.expiryTimer);const t=e+T;const i=this.state.expiresAt?.getTime();const r=i&&i>Date.now()?Math.min(t,i):t;const s=r-Date.now();this.expiryTimer=setTimeout(()=>{this.expiryTimer=null;if(this.verifiedAt!==e)return;this.emit({type:"validated",isPro:this.isPro()});if(Date.now()<t)this.setVerifiedAt(e)},Math.max(1,Math.min(s,2147483647)));if(typeof c!=="undefined"&&c)h.__LICENSE_MANAGER_EXPIRY_TIMER__=this.expiryTimer}subscribe(e){this.listeners.add(e);return()=>this.listeners.delete(e)}onDeviceRegistrationNeeded(e){this.deviceRegistrationCallback=e;return()=>{this.deviceRegistrationCallback=null}}async completeDeviceRegistration(e){if(!this.pendingRegistration){console.warn("[Buoy] No pending device registration");return}const{licenseId:t,licenseKey:i,fingerprint:r}=this.pendingRegistration;const s=this.generation;const n=e.trim()||K();const u=j();try{await z(t,i,r,n,u)}catch(o){const a=o instanceof Error?o.message:String(o);if(a==="FINGERPRINT_TAKEN"||a==="MACHINE_LIMIT_EXCEEDED"){}else{console.warn("[Buoy] Device registration failed:",a);throw o}}if(s!==this.generation)return;if(this.cachedLicense?.licenseKey===i){const o=await this.saveCache({...this.cachedLicense,fingerprint:r,deviceName:n},s);if(s!==this.generation)return;if(o)this.cachedLicense=o}this.pendingRegistration=null}emit(e){const t=[...this.listeners];t.forEach(i=>{try{i(e)}catch(r){console.warn("[React Buoy] License listener error:",r)}})}isCacheValid(e){const t=Date.now();const i=t-e.cachedAt;if(!e.valid||!Number.isFinite(e.cachedAt)||i<0||i>=T){return false}return true}isCacheFresh(e){const t=this.isQuiet(e)?de:oe;return Date.now()-(e.lastValidatedAt??0)<t}isQuiet(e){if(e.quiet!==void 0)return e.quiet;return v(e)==="free"&&!B()}async loadHold(){if(this.hold!==void 0)return this.hold;try{const e=await f();const t=await e.getItem(b);const i=t?JSON.parse(t):null;this.hold=i&&typeof i==="object"?i:null}catch{this.hold=null}return this.hold}async saveHold(e){this.hold=e;try{const t=await f();if(e)await t.setItem(b,JSON.stringify(e));else await t.removeItem(b)}catch{}}async persistCache(e){const t=W(e);const i=await f();await i.setItem(C,JSON.stringify(t));return t}saveCache(e,t){const i=this.persistence.catch(()=>{}).then(async()=>{if(t!==this.generation)return null;const r=await this.persistCache(e);return t===this.generation?r:null});this.persistence=i;return y(i,W(e))}async loadCachedLicense(){try{await this.persistence.catch(()=>{});const e=await f();const t=await e.getItem(C);if(!t)return null;const i=JSON.parse(t);return i}catch(e){console.warn("[Buoy] Error loading cached license:",e);return null}}getOrCreateDeviceFingerprint(){if(!this.fingerprintPromise){this.fingerprintPromise=(async()=>{const e=await f();const t=await e.getItem(P);if(t)return t;const i=this.cachedLicense?.fingerprint||D();await e.setItem(P,i);return i})()}return this.fingerprintPromise}async clearCachedLicense(){this.cachedLicense=null;const e=this.persistence.catch(()=>{}).then(async()=>{const t=await f();await t.removeItem(C)});this.persistence=e;await y(e.catch(()=>{}),void 0)}registerDeviceAsync(e,t,i,r){const s=j();z(e,t,i,r,s).catch(n=>{if(n.message!=="FINGERPRINT_TAKEN"&&n.message!=="MACHINE_LIMIT_EXCEEDED"){console.warn("[Buoy] Device registration failed (non-blocking):",n.message)}})}validateInBackground(e){void this.setLicenseKey(e,{force:true,isRetry:true})}refreshAccess(){this.emit({type:"validated",isPro:this.isPro()})}startRevalidationTimer(){if(!this.removeForegroundListener){this.removeForegroundListener=$e(()=>this.refreshAccess());if(typeof c!=="undefined"&&c)h.__LICENSE_MANAGER_FOREGROUND_OFF__=this.removeForegroundListener}if(this.revalidationTimer){clearInterval(this.revalidationTimer)}this.revalidationTimer=setInterval(()=>{if(!this.state.licenseKey||this.state.isValidating)return;const e=this.cachedLicense;if(e&&e.licenseKey===this.state.licenseKey&&this.isCacheFresh(e))return;this.validateInBackground(this.state.licenseKey)},ae);if(typeof c!=="undefined"&&c){globalThis.__LICENSE_MANAGER_TIMER__=this.revalidationTimer}}stopRevalidationTimer(){this.removeForegroundListener?.();this.removeForegroundListener=null;if(this.expiryTimer)clearTimeout(this.expiryTimer);this.expiryTimer=null;if(this.revalidationTimer){clearInterval(this.revalidationTimer);this.revalidationTimer=null}this.cancelRetry()}async forceReregister(){if(this.cachedLicense){this.cachedLicense.fingerprint=void 0;this.cachedLicense.deviceName=void 0}this.fingerprintPromise=null;await this.clearCachedLicense();try{const e=await f();await e.removeItem(P)}catch{}}};var je=new Ye;var h=globalThis;if(typeof c!=="undefined"&&c){h.__LICENSE_MANAGER_FOREGROUND_OFF__?.();h.__LICENSE_MANAGER_FOREGROUND_OFF__=void 0;if(h.__LICENSE_MANAGER_EXPIRY_TIMER__)clearTimeout(h.__LICENSE_MANAGER_EXPIRY_TIMER__);if(h.__LICENSE_MANAGER_TIMER__){clearInterval(h.__LICENSE_MANAGER_TIMER__)}if(h.__LICENSE_MANAGER_RETRY_TIMER__){clearTimeout(h.__LICENSE_MANAGER_RETRY_TIMER__);h.__LICENSE_MANAGER_RETRY_TIMER__=void 0}}export{m as LicenseTransportError,H as isTransientLicenseError,Q as isBuoyToken,te as resolveAccountAccess,je as LicenseManager};/*!
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 Pro 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
+ * This file is the technological measure that controls access to paid Buoy Pro
60
+ * features. Modifying, patching, aliasing, stubbing, or otherwise altering it
61
+ * so that Pro features unlock without a valid license is a breach of the EULA
62
+ * and, in the United States, circumvention of an access control under
63
+ * 17 U.S.C. § 1201 — which applies whether or not any code is copied.
64
+ *
65
+ * Pro is $9/mo, and is free every weekend for anyone holding a key —
66
+ * including a free one (`npx buoy login`). Buy a key at
67
+ * https://buoy.gg or use it free on Saturday and Sunday.
68
+ */
@@ -0,0 +1,68 @@
1
+ "use client";var c=process.env.NODE_ENV!=="production";if(typeof window!=="undefined"&&typeof globalThis.global==="undefined"){globalThis.global=globalThis}var w=new Map;var se={async getItem(e){try{return localStorage.getItem(e)??w.get(e)??null}catch{return w.get(e)??null}},async setItem(e,t){w.set(e,t);try{localStorage.setItem(e,t)}catch{}},async removeItem(e){w.delete(e);try{localStorage.removeItem(e)}catch{}}};async function f(){return se}var E={accountId:"b0eba0e8-e904-4906-b644-38f9aab57bed",productId:"bf67cb43-eeef-40ca-b308-e6e1b22c0eaa",apiUrl:"https://buoy.gg/api/license"};var ne="3b546fc717a62683f3236c70167899a271bee3ffc04df6ec1eea60a394a2f1e9";var T={free:"394e3351-1249-4f73-807a-703408604c0e",solo:"fa5d3c8f-5379-40f1-b63e-ab8a974b2f28",business:"690c2212-8e54-426f-b4b4-002ee1c0ae2b"};var _=30*24*60*60*1e3;var ae=24*60*60*1e3;var C="buoy-gg-license";var P="buoy-gg-device-fingerprint";var oe=60*60*1e3;var ce=[5*1e3,20*1e3,60*1e3,5*60*1e3,15*60*1e3];var le=60*1e3;var F=60*60*1e3;var he=24*60*60*1e3;var ue=50;var de=_;var b="buoy-gg-license-hold";var{apiUrl:U}=E;var g=class extends Error{constructor(e,t,i=null){super(e);this.isTransient=true;this.name="LicenseTransportError";this.status=t;this.retryAfterMs=i}};function fe(e){const t=e?.status;return t===429||t===402}function ye(e,t,i){if(e.status===402)return t;return e.retryAfterMs??i}function pe(e){const t=s=>{try{return e.headers?.get?.(s)??null}catch{return null}};const i=t("Retry-After");if(i){const s=Number(i);if(Number.isFinite(s)&&s>=0)return s*1e3;const n=Date.parse(i);if(Number.isFinite(n))return Math.max(0,n-Date.now())}const r=Number(t("X-RateLimit-Reset"));if(Number.isFinite(r)&&r>0)return Math.max(0,r*1e3-Date.now());return null}function H(e){if(e instanceof g)return true;if(e instanceof TypeError)return true;return typeof e==="object"&&e!==null&&e.isTransient===true}async function ge(e){try{const t=await e.json();return t.errors?.[0]?.detail||`HTTP ${e.status}`}catch{return`HTTP ${e.status}`}}function G(){return{"Content-Type":"application/vnd.api+json",Accept:"application/vnd.api+json"}}async function me(e,t){const i=`${U}/validate`;const r={meta:{key:e}};let s;try{s=await fetch(i,{signal:t,method:"POST",headers:G(),body:JSON.stringify(r)})}catch(n){throw new g(n instanceof Error?n.message:"Network request failed",null)}if(!s.ok){throw new g(await ge(s),s.status,s.status===429?pe(s):null)}try{const 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 g("License server returned an unreadable response",s.status)}}async function ve(e){const t=typeof AbortController==="function"?new AbortController:null;let i;try{return await Promise.race([me(e,t?.signal),new Promise((r,s)=>{i=setTimeout(()=>{s(new g("License verification timed out. Please retry.",null));t?.abort()},15e3)})])}finally{if(i)clearTimeout(i)}}function Ae(e){if(!e.data)return false;const t=e.data.relationships?.product?.data?.id;if(t&&t!==E.productId)return false;if(e.meta.valid&&e.meta.code==="VALID")return true;return["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 we(e){const t=e.data?.relationships?.machines?.meta?.count;return typeof t==="number"&&Number.isFinite(t)?t:0}async function z(e,t,i,r,s){const n=`${U}/machines`;const u=await fetch(n,{method:"POST",headers:G(),body:JSON.stringify({licenseId:e,licenseKey:t,fingerprint:i,name:r,metadata:s||{}})});if(!u.ok){const o=await u.json();const 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")}const l=o.errors?.[0]?.detail||`HTTP ${u.status}`;throw new Error(l)}return u.json()}function Ee(e){const{meta:t,data:i}=e;return{valid:t.valid,code:t.code,detail:t.detail,metadata:i?.attributes?.metadata}}function Te(e){return["NOT_FOUND","SUSPENDED","EXPIRED","BANNED","PRODUCT_SCOPE_MISMATCH"].includes(e)}function D(){if(typeof crypto!=="undefined"&&crypto.randomUUID){return crypto.randomUUID()}return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=Math.random()*16|0;const i=e==="x"?t:t&3|8;return i.toString(16)})}function B(){if(typeof c!=="undefined")return c;try{if(typeof navigator!=="undefined"&&/electron/i.test(navigator.userAgent))return true}catch{}return typeof process!=="undefined"&&process.env.NODE_ENV!=="production"}function $(){if(typeof navigator==="undefined"){return"unknown"}const e=navigator.userAgent.toLowerCase();const t=navigator.platform?.toLowerCase()||"";if(e.includes("electron")){if(t.includes("mac")||e.includes("mac")){return"electron-macos"}if(t.includes("win")||e.includes("win")){return"electron-windows"}if(t.includes("linux")||e.includes("linux")){return"electron-linux"}return"electron"}if(t.includes("mac")||e.includes("mac")){return"macos"}if(t.includes("win")||e.includes("win")){return"windows"}if(t.includes("linux")||e.includes("linux")){return"linux"}if(/iphone|ipad|ipod/.test(e)){return"ios-web"}if(e.includes("android")){return"android-web"}return"web"}function _e(){if(typeof navigator==="undefined"){return"unknown"}const e=navigator.userAgent;const t=e.match(/Mac OS X ([\d_.]+)/);if(t){return t[1].replace(/_/g,".")}const i=e.match(/Windows NT ([\d.]+)/);if(i){const r={"10.0":"10/11","6.3":"8.1","6.2":"8","6.1":"7"};return r[i[1]]||i[1]}if(e.includes("Linux")){return"Linux"}return"unknown"}function Y(){if(typeof navigator==="undefined"){return{name:"unknown",version:"unknown"}}const e=navigator.userAgent;const t=e.match(/Electron\/([\d.]+)/);if(t){return{name:"Electron",version:t[1]}}const i=e.match(/Chrome\/([\d.]+)/);if(i&&!e.includes("Edg")){return{name:"Chrome",version:i[1]}}const r=e.match(/Edg\/([\d.]+)/);if(r){return{name:"Edge",version:r[1]}}const s=e.match(/Firefox\/([\d.]+)/);if(s){return{name:"Firefox",version:s[1]}}const n=e.match(/Version\/([\d.]+).*Safari/);if(n){return{name:"Safari",version:n[1]}}return{name:"unknown",version:"unknown"}}function j(){const e={platform:$(),osVersion:_e(),isSimulator:"false"};const t=Y();e.browser=t.name;e.browserVersion=t.version;if(typeof window!=="undefined"&&window.screen){e.screenResolution=`${window.screen.width}x${window.screen.height}`}if(typeof navigator!=="undefined"&&navigator.language){e.language=navigator.language}try{e.timezone=Intl.DateTimeFormat().resolvedOptions().timeZone}catch{}return e}function K(){const e=$();const t=Y();if(e.startsWith("electron")){const i=e.replace("electron-","").replace("electron","Desktop");return`${i.charAt(0).toUpperCase()+i.slice(1)} App`}if(t.name!=="unknown"){return`${t.name} Browser`}return"Web Browser"}var Ie="v2";var Re=["v1"];var Le="buoy.gg/pro:9f3c1d7a4b2e:license-cache";var xe="\0";function X(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 Ne(e,t){const i=[t,e.licenseKey,e.licenseId,e.isPro?"1":"0",e.expiresAt??"",String(e.cachedAt)];if(t!=="v1"){i.push(e.tier??"")}i.push(Le);return i.join(xe)}function q(e,t){const i=Ne(e,t);const r=X(i,2166136261);const s=X(i,2135587861);return`${t}.${r.toString(16)}${s.toString(16)}`}function J(e){return q(e,Ie)}function W(e){return{...e,sig:J(e)}}function m(e){if(!e||typeof e.sig!=="string"||e.sig.length===0){return false}if(e.sig===J(e))return true;return Re.some(t=>e.sig.startsWith(`${t}.`)&&e.sig===q(e,t))}import Ce from"tweetnacl";var Pe=1;var be=1;var De="buoy-free-token-v1:";var Ke=22;var Me=64;var Z=/^BUOY1-([A-Z2-7]+)-([A-Z2-7]+)$/;function Q(e){return Z.test(e.trim().toUpperCase())}var Se="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";function ee(e){const t=[];let i=0;let r=0;for(const s of e){const n=Se.indexOf(s);if(n===-1)return null;r=r<<5|n;i+=5;if(i>=8){t.push(r>>>i-8&255);i-=8}}return new Uint8Array(t)}function Ve(e){const t=e.trim().toLowerCase();const 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 ke(e){let t="";for(const i of e)t+=i.toString(16).padStart(2,"0");return t}function Oe(e){if(typeof TextEncoder!=="undefined")return new TextEncoder().encode(e);const t=new Uint8Array(e.length);for(let i=0;i<e.length;i+=1)t[i]=e.charCodeAt(i)&255;return t}function Fe(e,t){const i=new Uint8Array(e.length+t.length);i.set(e,0);i.set(t,e.length);return i}function Ue(e){return Fe(Oe(De),e)}var He=ne;function Ge(e,t=He){const i=Z.exec(e.trim().toUpperCase());if(!i)return null;const r=ee(i[1]);const s=ee(i[2]);if(!r||!s)return null;if(r.length!==Ke||s.length!==Me)return null;if(r[0]!==Pe||r[1]!==be)return null;try{if(!Ce.sign.detached.verify(Ue(r),s,Ve(t)))return null}catch{return null}const n=(r[2]<<24>>>0)+(r[3]<<16)+(r[4]<<8)+r[5];return{tier:"free",issuedAt:n*1e3,accountHash:ke(r.slice(6,22))}}function ze(e){const t=e.relationships?.policy?.data?.id;if(t===T.free)return"free";if(t===T.solo||t===T.business){return"pro"}const i=e.attributes?.metadata?.plan;if(i==="free")return"free";return"pro"}function Be(e){if(!e)return false;const t=e.relationships?.product?.data?.id;if(t)return t===E.productId;const i=e.relationships?.policy?.data?.id;return Object.values(T).some(r=>r===i)}function te(e,t=Date.now()){const i=e.verifiedAt!==null&&Number.isFinite(e.verifiedAt)&&e.verifiedAt<=t?e.verifiedAt+_:null;if(e.initialized&&e.key&&e.tierSource!=="none"&&i!==null&&t<i){return{status:"admitted",reason:null,validUntil:i}}if(i!==null&&t>=i){return{status:"locked",reason:"verification_expired",validUntil:i}}if(!e.initialized||e.validating){return{status:"initializing",reason:"checking",validUntil:i}}return{status:"locked",reason:i!==null&&t>=i?"verification_expired":"account_required",validUntil:i}}function $e(e){if(typeof window==="undefined"||typeof window.addEventListener!=="function")return()=>{};const t=()=>{if(!document.hidden)e()};window.addEventListener("focus",e);document.addEventListener("visibilitychange",t);return()=>{window.removeEventListener("focus",e);document.removeEventListener("visibilitychange",t)}}async function y(e,t){let i;try{return await Promise.race([e,new Promise(r=>{i=setTimeout(()=>r(t),15e3)})])}finally{if(i)clearTimeout(i)}}function v(e){if(e.tier==="pro"||e.tier==="free")return e.tier;return e.isPro?"pro":"free"}var Ye=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.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();return this.initPromise}async _doInitialize(){if(this.state.isInitialized)return;const e=this.generation;try{const t=await y(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)){const i=m(t);this.cachedLicense=t;this.state.licenseKey=t.licenseKey;if(i&&this.isCacheValid(t))this.applyTier(v(t));else this.lock();this.state.expiresAt=t.expiresAt?new Date(t.expiresAt):null;if(i&&this.isCacheValid(t))this.setVerifiedAt(t.cachedAt);if(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){await this.initialize();return this.hasAccountAccess()}const t=e.trim().toUpperCase();const i=++this.generation;this.cancelRetry();this.configuredKey=t||null;if(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();if(i!==this.generation)return false;if(!t){await this.clearLicense();return false}return this.setLicenseKey(t)}async setLicenseKey(e,t){if(!e||e.trim().length===0){this.state.error="License key is required";this.state.errorKind="verdict";return false}const i=e.trim().toUpperCase();const r=++this.generation;this.cancelRetry();if(!t?.isRetry)this.retryAttempt=0;if(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()});if(Q(i))return this.admitToken(i,r);if(!this.cachedLicense){const a=await y(this.loadCachedLicense(),null);if(r!==this.generation)return false;if(a?.licenseKey===i){this.cachedLicense=a;if(m(a)&&this.isCacheValid(a)){this.applyTier(v(a));this.state.expiresAt=a.expiresAt?new Date(a.expiresAt):null;this.setVerifiedAt(a.cachedAt);this.emit({type:"validating",isPro:this.isPro()})}}}const s=this.cachedLicense;if(!t?.force&&s&&s.valid&&s.licenseKey===i&&s.fingerprint&&m(s)&&this.isCacheValid(s)&&this.isCacheFresh(s)){this.applyTier(v(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});return true}const n=await y(this.loadHold(),null);if(r!==this.generation)return false;const u=(n?.backoffUntil??0)-Date.now();if(u>0){return this.standDown(i,r,"License server is rate limited; retrying later.",u)}if(!t?.force&&n?.key===i&&n.verdictAt!==void 0&&Date.now()-n.verdictAt>=0&&Date.now()-n.verdictAt<he){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});return false}let o;try{o=await ve(i)}catch(a){const l=a instanceof Error?a.message:"Validation failed";if(r!==this.generation)return false;if(H(a)){if(fe(a)){const d=Math.min(ye(a,F,le)*2**this.retryAttempt,F);this.retryAttempt+=1;await this.saveHold({...this.hold,backoffUntil:Date.now()+d});if(r!==this.generation)return false;return this.standDown(i,r,l,d)}this.state.isValidating=false;if(this.cachedLicense&&this.cachedLicense.licenseKey===i&&m(this.cachedLicense)&&this.isCacheValid(this.cachedLicense)){this.applyTier(v(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);if(!this.isPro())this.scheduleRetry(i);this.emit({type:"validated",isPro:this.state.isPro});return true}this.state.error=l;this.state.errorKind="transport";this.scheduleRetry(i);this.emit({type:"error",isPro:this.state.isPro,error:l});return false}this.state.isValidating=false;this.state.error=l;this.state.errorKind="verdict";this.emit({type:"error",isPro:false,error:l});return false}try{if(r!==this.generation)return false;const a=Ee(o);const l=o.data?.relationships?.product?.data?.id;if((!l||l===E.productId)&&a.code==="EXPIRED"&&(Be(o.data)||this.cachedLicense?.licenseKey===i&&m(this.cachedLicense)&&this.isCacheValid(this.cachedLicense))){const N=Date.now();const O=await this.saveCache({licenseKey:i,licenseId:o.data?.id??"",valid:true,isPro:false,tier:"free",expiresAt:null,cachedAt:N,lastValidatedAt:N,fingerprint:this.cachedLicense?.licenseKey===i?this.cachedLicense.fingerprint:void 0},r);if(r!==this.generation||!O)return false;this.cachedLicense=O;this.applyTier("free");this.state.isValidating=false;this.state.expiresAt=null;this.setVerifiedAt(N);this.emit({type:"validated",isPro:false});return true}if(Te(a.code)||!Ae(o)){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:Date.now()});return false}if(!o.data){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();return false}const d=ze(o.data);const I=o.data.id;const R=Date.now();const M=we(o)>=ue;const S=B();const ie=S&&!M;const re=d==="free"&&(M||!S);let p=this.cachedLicense?.fingerprint;let A=this.cachedLicense?.deviceName;let V=false;if(!p){p=await y(this.getOrCreateDeviceFingerprint(),D());if(r!==this.generation)return false;A=K();V=ie}let L=false;if(V){if(this.deviceRegistrationCallback){this.pendingRegistration={licenseId:I,licenseKey:i,fingerprint:p};this.deviceRegistrationCallback({fingerprint:p,defaultName:A});L=true}else{this.registerDeviceAsync(I,i,p,A)}}const x={licenseKey:i,licenseId:I,valid:true,isPro:d==="pro",tier:d,expiresAt:o.data.attributes.expiry??null,cachedAt:R,lastValidatedAt:R,fingerprint:L?void 0:p,deviceName:L?void 0:A,quiet:re||void 0};const k=await this.saveCache(x,r);if(r!==this.generation||!k)return false;this.cachedLicense=k;this.applyTier(d);this.state.isValidating=false;this.state.expiresAt=x.expiresAt?new Date(x.expiresAt):null;this.setVerifiedAt(R);if(this.hold)await this.saveHold(null);if(r!==this.generation)return false;this.retryAttempt=0;this.emit({type:"validated",isPro:this.state.isPro});return true}catch(a){const l=a instanceof Error?a.message:"Validation failed";if(r!==this.generation)return false;this.state.isValidating=false;this.state.error=l;this.state.errorKind="verdict";this.emit({type:"error",isPro:false,error:l});return false}}scheduleRetry(e){this.cancelRetry();const t=ce[this.retryAttempt];if(t===void 0)return;this.retryAttempt+=1;const i=this.generation;this.retryTimer=setTimeout(()=>{this.retryTimer=null;if(i!==this.generation)return;if(this.state.isValidating)return;void this.setLicenseKey(e,{force:true,isRetry:true})},t);if(typeof c!=="undefined"&&c){globalThis.__LICENSE_MANAGER_RETRY_TIMER__=this.retryTimer}}async admitToken(e,t){const i=Ge(e);if(t!==this.generation)return false;if(!i){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();return false}const r=Date.now();const s=this.cachedLicense?.fingerprint??await y(this.getOrCreateDeviceFingerprint(),D());if(t!==this.generation)return false;const 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??K(),quiet:true},t);if(t!==this.generation||!n)return 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});return true}standDown(e,t,i,r){if(t!==this.generation)return false;this.state.isValidating=false;const s=this.cachedLicense;if(s&&s.licenseKey===e&&m(s)&&this.isCacheValid(s)){this.applyTier(v(s));this.state.error=null;this.state.errorKind=null;this.state.expiresAt=s.expiresAt?new Date(s.expiresAt):null;this.setVerifiedAt(s.cachedAt);if(!this.isPro())this.scheduleRetryIn(e,r);this.emit({type:"validated",isPro:this.state.isPro});return true}this.state.error=i;this.state.errorKind="transport";this.scheduleRetryIn(e,r);this.emit({type:"error",isPro:this.state.isPro,error:i});return false}scheduleRetryIn(e,t){this.cancelRetry();const i=this.generation;this.retryTimer=setTimeout(()=>{this.retryTimer=null;if(i!==this.generation)return;if(this.state.isValidating)return;void this.setLicenseKey(e,{force:true,isRetry:true})},Math.max(1,Math.min(t,2147483647)));if(typeof c!=="undefined"&&c)h.__LICENSE_MANAGER_RETRY_TIMER__=this.retryTimer}cancelRetry(){if(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();if(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;if(this.expiryTimer)clearTimeout(this.expiryTimer);this.expiryTimer=null}getTier(){if(!this.hasAccountAccess())return"free";if(this.state.expiresAt&&Date.now()>=this.state.expiresAt.getTime())return"free";return this.state.tier}isPro(){return this.getTier()==="pro"}hasEntitlement(e){return this.isPro()}getState(){const e=this.getAccountAccess();const t=this.getTier();return{...this.state,tier:t,isPro:t==="pro",access:e}}getAccountAccess(){return te({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"}setVerifiedAt(e){this.verifiedAt=e;if(this.expiryTimer)clearTimeout(this.expiryTimer);const t=e+_;const i=this.state.expiresAt?.getTime();const r=i&&i>Date.now()?Math.min(t,i):t;const s=r-Date.now();this.expiryTimer=setTimeout(()=>{this.expiryTimer=null;if(this.verifiedAt!==e)return;this.emit({type:"validated",isPro:this.isPro()});if(Date.now()<t)this.setVerifiedAt(e)},Math.max(1,Math.min(s,2147483647)));if(typeof c!=="undefined"&&c)h.__LICENSE_MANAGER_EXPIRY_TIMER__=this.expiryTimer}subscribe(e){this.listeners.add(e);return()=>this.listeners.delete(e)}onDeviceRegistrationNeeded(e){this.deviceRegistrationCallback=e;return()=>{this.deviceRegistrationCallback=null}}async completeDeviceRegistration(e){if(!this.pendingRegistration){console.warn("[Buoy] No pending device registration");return}const{licenseId:t,licenseKey:i,fingerprint:r}=this.pendingRegistration;const s=this.generation;const n=e.trim()||K();const u=j();try{await z(t,i,r,n,u)}catch(o){const a=o instanceof Error?o.message:String(o);if(a==="FINGERPRINT_TAKEN"||a==="MACHINE_LIMIT_EXCEEDED"){}else{console.warn("[Buoy] Device registration failed:",a);throw o}}if(s!==this.generation)return;if(this.cachedLicense?.licenseKey===i){const o=await this.saveCache({...this.cachedLicense,fingerprint:r,deviceName:n},s);if(s!==this.generation)return;if(o)this.cachedLicense=o}this.pendingRegistration=null}emit(e){const t=[...this.listeners];t.forEach(i=>{try{i(e)}catch(r){console.warn("[React Buoy] License listener error:",r)}})}isCacheValid(e){const t=Date.now();const i=t-e.cachedAt;if(!e.valid||!Number.isFinite(e.cachedAt)||i<0||i>=_){return false}return true}isCacheFresh(e){const t=this.isQuiet(e)?de:oe;return Date.now()-(e.lastValidatedAt??0)<t}isQuiet(e){if(e.quiet!==void 0)return e.quiet;return v(e)==="free"&&!B()}async loadHold(){if(this.hold!==void 0)return this.hold;try{const e=await f();const t=await e.getItem(b);const i=t?JSON.parse(t):null;this.hold=i&&typeof i==="object"?i:null}catch{this.hold=null}return this.hold}async saveHold(e){this.hold=e;try{const t=await f();if(e)await t.setItem(b,JSON.stringify(e));else await t.removeItem(b)}catch{}}async persistCache(e){const t=W(e);const i=await f();await i.setItem(C,JSON.stringify(t));return t}saveCache(e,t){const i=this.persistence.catch(()=>{}).then(async()=>{if(t!==this.generation)return null;const r=await this.persistCache(e);return t===this.generation?r:null});this.persistence=i;return y(i,W(e))}async loadCachedLicense(){try{await this.persistence.catch(()=>{});const e=await f();const t=await e.getItem(C);if(!t)return null;const i=JSON.parse(t);return i}catch(e){console.warn("[Buoy] Error loading cached license:",e);return null}}getOrCreateDeviceFingerprint(){if(!this.fingerprintPromise){this.fingerprintPromise=(async()=>{const e=await f();const t=await e.getItem(P);if(t)return t;const i=this.cachedLicense?.fingerprint||D();await e.setItem(P,i);return i})()}return this.fingerprintPromise}async clearCachedLicense(){this.cachedLicense=null;const e=this.persistence.catch(()=>{}).then(async()=>{const t=await f();await t.removeItem(C)});this.persistence=e;await y(e.catch(()=>{}),void 0)}registerDeviceAsync(e,t,i,r){const s=j();z(e,t,i,r,s).catch(n=>{if(n.message!=="FINGERPRINT_TAKEN"&&n.message!=="MACHINE_LIMIT_EXCEEDED"){console.warn("[Buoy] Device registration failed (non-blocking):",n.message)}})}validateInBackground(e){void this.setLicenseKey(e,{force:true,isRetry:true})}refreshAccess(){this.emit({type:"validated",isPro:this.isPro()})}startRevalidationTimer(){if(!this.removeForegroundListener){this.removeForegroundListener=$e(()=>this.refreshAccess());if(typeof c!=="undefined"&&c)h.__LICENSE_MANAGER_FOREGROUND_OFF__=this.removeForegroundListener}if(this.revalidationTimer){clearInterval(this.revalidationTimer)}this.revalidationTimer=setInterval(()=>{if(!this.state.licenseKey||this.state.isValidating)return;const e=this.cachedLicense;if(e&&e.licenseKey===this.state.licenseKey&&this.isCacheFresh(e))return;this.validateInBackground(this.state.licenseKey)},ae);if(typeof c!=="undefined"&&c){globalThis.__LICENSE_MANAGER_TIMER__=this.revalidationTimer}}stopRevalidationTimer(){this.removeForegroundListener?.();this.removeForegroundListener=null;if(this.expiryTimer)clearTimeout(this.expiryTimer);this.expiryTimer=null;if(this.revalidationTimer){clearInterval(this.revalidationTimer);this.revalidationTimer=null}this.cancelRetry()}async forceReregister(){if(this.cachedLicense){this.cachedLicense.fingerprint=void 0;this.cachedLicense.deviceName=void 0}this.fingerprintPromise=null;await this.clearCachedLicense();try{const e=await f();await e.removeItem(P)}catch{}}};var je=new Ye;var h=globalThis;if(typeof c!=="undefined"&&c){h.__LICENSE_MANAGER_FOREGROUND_OFF__?.();h.__LICENSE_MANAGER_FOREGROUND_OFF__=void 0;if(h.__LICENSE_MANAGER_EXPIRY_TIMER__)clearTimeout(h.__LICENSE_MANAGER_EXPIRY_TIMER__);if(h.__LICENSE_MANAGER_TIMER__){clearInterval(h.__LICENSE_MANAGER_TIMER__)}if(h.__LICENSE_MANAGER_RETRY_TIMER__){clearTimeout(h.__LICENSE_MANAGER_RETRY_TIMER__);h.__LICENSE_MANAGER_RETRY_TIMER__=void 0}}export{g as LicenseTransportError,H as isTransientLicenseError,Q as isBuoyToken,te as resolveAccountAccess,je as LicenseManager};/*!
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 Pro 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
+ * This file is the technological measure that controls access to paid Buoy Pro
60
+ * features. Modifying, patching, aliasing, stubbing, or otherwise altering it
61
+ * so that Pro features unlock without a valid license is a breach of the EULA
62
+ * and, in the United States, circumvention of an access control under
63
+ * 17 U.S.C. § 1201 — which applies whether or not any code is copied.
64
+ *
65
+ * Pro is $9/mo, and is free every weekend for anyone holding a key —
66
+ * including a free one (`npx buoy login`). Buy a key at
67
+ * https://buoy.gg or use it free on Saturday and Sunday.
68
+ */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@buoy-gg/license",
3
- "version": "7.0.43",
3
+ "version": "7.0.44",
4
4
  "description": "License validation for React Buoy Pro features",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "main": "lib/commonjs/index.js",