@buoy-gg/license 7.0.40 → 7.0.41

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.
@@ -0,0 +1,7 @@
1
+ "use client";
2
+ import {
3
+ LicenseManager
4
+ } from "./chunk-OPWF6JR6.mjs";
5
+ export {
6
+ LicenseManager
7
+ };
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ import{e as a}from"./chunk-GRUXDUJG.mjs";export{a as LicenseManager};
@@ -0,0 +1,7 @@
1
+ "use client";
2
+ import {
3
+ LicenseManager
4
+ } from "./chunk-TVOTAEQX.mjs";
5
+ export {
6
+ LicenseManager
7
+ };
@@ -0,0 +1,74 @@
1
+ "use client";
2
+ var o=process.env.NODE_ENV!=="production";typeof window<"u"&&typeof globalThis.global>"u"&&(globalThis.global=globalThis);var N=new Map,Le={async getItem(i){try{return localStorage.getItem(i)??N.get(i)??null}catch{return N.get(i)??null}},async setItem(i,e){N.set(i,e);try{localStorage.setItem(i,e)}catch{}},async removeItem(i){N.delete(i);try{localStorage.removeItem(i)}catch{}}};async function h(){return Le}var p={accountId:"b0eba0e8-e904-4906-b644-38f9aab57bed",productId:"bf67cb43-eeef-40ca-b308-e6e1b22c0eaa",apiUrl:"https://buoy.gg/api/license"},$="3b546fc717a62683f3236c70167899a271bee3ffc04df6ec1eea60a394a2f1e9",T={free:"394e3351-1249-4f73-807a-703408604c0e",solo:"fa5d3c8f-5379-40f1-b63e-ab8a974b2f28",business:"690c2212-8e54-426f-b4b4-002ee1c0ae2b"},v=720*60*60*1e3,X=1440*60*1e3,C="buoy-gg-license",w="buoy-gg-device-fingerprint",j=3600*1e3,q=[5*1e3,20*1e3,60*1e3,300*1e3,900*1e3],W=60*1e3,V=3600*1e3,J=1440*60*1e3,Q=50,Z=v,b="buoy-gg-license-hold";var{apiUrl:ee}=p,m=class extends Error{constructor(t,r,n=null){super(t);this.isTransient=!0;this.name="LicenseTransportError",this.status=r,this.retryAfterMs=n}};function te(i){let e=i?.status;return e===429||e===402}function ie(i,e,t){return i.status===402?e:i.retryAfterMs??t}function Ne(i){let e=n=>{try{return i.headers?.get?.(n)??null}catch{return null}},t=e("Retry-After");if(t){let n=Number(t);if(Number.isFinite(n)&&n>=0)return n*1e3;let s=Date.parse(t);if(Number.isFinite(s))return Math.max(0,s-Date.now())}let r=Number(e("X-RateLimit-Reset"));return Number.isFinite(r)&&r>0?Math.max(0,r*1e3-Date.now()):null}function re(i){return i instanceof m||i instanceof TypeError?!0:typeof i=="object"&&i!==null&&i.isTransient===!0}async function Ce(i){try{return(await i.json()).errors?.[0]?.detail||`HTTP ${i.status}`}catch{return`HTTP ${i.status}`}}function ne(){return{"Content-Type":"application/vnd.api+json",Accept:"application/vnd.api+json"}}async function we(i,e){let t=`${ee}/validate`,r={meta:{key:i}},n;try{n=await fetch(t,{signal:e,method:"POST",headers:ne(),body:JSON.stringify(r)})}catch(s){throw new m(s instanceof Error?s.message:"Network request failed",null)}if(!n.ok)throw new m(await Ce(n),n.status,n.status===429?Ne(n):null);try{let s=await n.json();if(!s||typeof s!="object"||typeof s.meta?.valid!="boolean"||typeof s.meta?.code!="string"||!s.meta.code)throw new Error("Missing license verdict");return s}catch{throw new m("License server returned an unreadable response",n.status)}}async function se(i){let e=typeof AbortController=="function"?new AbortController:null,t;try{return await Promise.race([we(i,e?.signal),new Promise((r,n)=>{t=setTimeout(()=>{n(new m("License verification timed out. Please retry.",null)),e?.abort()},15e3)})])}finally{t&&clearTimeout(t)}}function ae(i){if(!i.data)return!1;let e=i.data.relationships?.product?.data?.id;return e&&e!==p.productId?!1:i.meta.valid&&i.meta.code==="VALID"?!0:["OVERDUE","NO_MACHINE","NO_MACHINES","TOO_MANY_MACHINES","TOO_MANY_CORES","TOO_MANY_PROCESSES","FINGERPRINT_SCOPE_MISMATCH","HEARTBEAT_NOT_STARTED","HEARTBEAT_DEAD"].includes(i.meta.code)}function oe(i){let e=i.data?.relationships?.machines?.meta?.count;return typeof e=="number"&&Number.isFinite(e)?e:0}async function F(i,e,t,r,n){let s=`${ee}/machines`,l=await fetch(s,{method:"POST",headers:ne(),body:JSON.stringify({licenseId:i,licenseKey:e,fingerprint:t,name:r,metadata:n||{}})});if(!l.ok){let f=await l.json(),c=f.errors?.[0]?.code;if(c==="FINGERPRINT_TAKEN")throw new Error("FINGERPRINT_TAKEN");if(c==="MACHINE_LIMIT_EXCEEDED")throw new Error("MACHINE_LIMIT_EXCEEDED");let a=f.errors?.[0]?.detail||`HTTP ${l.status}`;throw new Error(a)}return l.json()}function ce(i){let{meta:e,data:t}=i;return{valid:e.valid,code:e.code,detail:e.detail,metadata:t?.attributes?.metadata}}function le(i){return["NOT_FOUND","SUSPENDED","EXPIRED","BANNED","PRODUCT_SCOPE_MISMATCH"].includes(i)}function R(){return typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,i=>{let e=Math.random()*16|0;return(i==="x"?e:e&3|8).toString(16)})}function x(){if(typeof o<"u")return o;try{if(typeof navigator<"u"&&/electron/i.test(navigator.userAgent))return!0}catch{}return typeof process<"u"&&process.env.NODE_ENV!=="production"}function ue(){if(typeof navigator>"u")return"unknown";let i=navigator.userAgent.toLowerCase(),e=navigator.platform?.toLowerCase()||"";return i.includes("electron")?e.includes("mac")||i.includes("mac")?"electron-macos":e.includes("win")||i.includes("win")?"electron-windows":e.includes("linux")||i.includes("linux")?"electron-linux":"electron":e.includes("mac")||i.includes("mac")?"macos":e.includes("win")||i.includes("win")?"windows":e.includes("linux")||i.includes("linux")?"linux":/iphone|ipad|ipod/.test(i)?"ios-web":i.includes("android")?"android-web":"web"}function be(){if(typeof navigator>"u")return"unknown";let i=navigator.userAgent,e=i.match(/Mac OS X ([\d_.]+)/);if(e)return e[1].replace(/_/g,".");let t=i.match(/Windows NT ([\d.]+)/);return t?{"10.0":"10/11","6.3":"8.1","6.2":"8","6.1":"7"}[t[1]]||t[1]:i.includes("Linux")?"Linux":"unknown"}function de(){if(typeof navigator>"u")return{name:"unknown",version:"unknown"};let i=navigator.userAgent,e=i.match(/Electron\/([\d.]+)/);if(e)return{name:"Electron",version:e[1]};let t=i.match(/Chrome\/([\d.]+)/);if(t&&!i.includes("Edg"))return{name:"Chrome",version:t[1]};let r=i.match(/Edg\/([\d.]+)/);if(r)return{name:"Edge",version:r[1]};let n=i.match(/Firefox\/([\d.]+)/);if(n)return{name:"Firefox",version:n[1]};let s=i.match(/Version\/([\d.]+).*Safari/);return s?{name:"Safari",version:s[1]}:{name:"unknown",version:"unknown"}}function S(){let i={platform:ue(),osVersion:be(),isSimulator:"false"},e=de();i.browser=e.name,i.browserVersion=e.version,typeof window<"u"&&window.screen&&(i.screenResolution=`${window.screen.width}x${window.screen.height}`),typeof navigator<"u"&&navigator.language&&(i.language=navigator.language);try{i.timezone=Intl.DateTimeFormat().resolvedOptions().timeZone}catch{}return i}function I(){let i=ue(),e=de();if(i.startsWith("electron")){let t=i.replace("electron-","").replace("electron","Desktop");return`${t.charAt(0).toUpperCase()+t.slice(1)} App`}return e.name!=="unknown"?`${e.name} Browser`:"Web Browser"}var xe=["v1"],Se="buoy.gg/pro:9f3c1d7a4b2e:license-cache";function he(i,e){let t=e>>>0;for(let r=0;r<i.length;r++)t^=i.charCodeAt(r),t=Math.imul(t,16777619)>>>0;return t>>>0}function Pe(i,e){let t=[e,i.licenseKey,i.licenseId,i.isPro?"1":"0",i.expiresAt??"",String(i.cachedAt)];return e!=="v1"&&t.push(i.tier??""),t.push(Se),t.join("\0")}function fe(i,e){let t=Pe(i,e),r=he(t,2166136261),n=he(t,2135587861);return`${e}.${r.toString(16)}${n.toString(16)}`}function ge(i){return fe(i,"v2")}function k(i){return{...i,sig:ge(i)}}function y(i){return!i||typeof i.sig!="string"||i.sig.length===0?!1:i.sig===ge(i)?!0:xe.some(e=>i.sig.startsWith(`${e}.`)&&i.sig===fe(i,e))}import De from"tweetnacl";var Ke=1,Oe=1,Me="buoy-free-token-v1:",Ve=22,Fe=64,me=/^BUOY1-([A-Z2-7]+)-([A-Z2-7]+)$/;function ye(i){return me.test(i.trim().toUpperCase())}var ke="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";function pe(i){let e=[],t=0,r=0;for(let n of i){let s=ke.indexOf(n);if(s===-1)return null;r=r<<5|s,t+=5,t>=8&&(e.push(r>>>t-8&255),t-=8)}return new Uint8Array(e)}function Ue(i){let e=i.trim().toLowerCase(),t=new Uint8Array(e.length/2);for(let r=0;r<t.length;r+=1)t[r]=parseInt(e.slice(r*2,r*2+2),16);return t}function Ge(i){let e="";for(let t of i)e+=t.toString(16).padStart(2,"0");return e}function He(i){if(typeof TextEncoder<"u")return new TextEncoder().encode(i);let e=new Uint8Array(i.length);for(let t=0;t<i.length;t+=1)e[t]=i.charCodeAt(t)&255;return e}function Be(i,e){let t=new Uint8Array(i.length+e.length);return t.set(i,0),t.set(e,i.length),t}function Ye(i){return Be(He(Me),i)}var ze=$;function Ee(i,e=ze){let t=me.exec(i.trim().toUpperCase());if(!t)return null;let r=pe(t[1]),n=pe(t[2]);if(!r||!n||r.length!==Ve||n.length!==Fe||r[0]!==Ke||r[1]!==Oe)return null;try{if(!De.sign.detached.verify(Ye(r),n,Ue(e)))return null}catch{return null}return{tier:"free",issuedAt:((r[2]<<24>>>0)+(r[3]<<16)+(r[4]<<8)+r[5])*1e3,accountHash:Ge(r.slice(6,22))}}function _e(i){let e=i.relationships?.policy?.data?.id;return e===T.free?"free":e===T.solo||e===T.business?"pro":i.attributes?.metadata?.plan==="free"?"free":"pro"}function ve(i){if(!i)return!1;let e=i.relationships?.product?.data?.id;if(e)return e===p.productId;let t=i.relationships?.policy?.data?.id;return Object.values(T).some(r=>r===t)}function Ae(i,e=Date.now()){let t=i.verifiedAt!==null&&Number.isFinite(i.verifiedAt)&&i.verifiedAt<=e?i.verifiedAt+v:null;return i.initialized&&i.key&&i.tierSource!=="none"&&t!==null&&e<t?{status:"admitted",reason:null,validUntil:t}:t!==null&&e>=t?{status:"locked",reason:"verification_expired",validUntil:t}:!i.initialized||i.validating?{status:"initializing",reason:"checking",validUntil:t}:{status:"locked",reason:t!==null&&e>=t?"verification_expired":"account_required",validUntil:t}}function Te(i){if(typeof window>"u"||typeof window.addEventListener!="function")return()=>{};let e=()=>{document.hidden||i()};return window.addEventListener("focus",i),document.addEventListener("visibilitychange",e),()=>{window.removeEventListener("focus",i),document.removeEventListener("visibilitychange",e)}}async function E(i,e){let t;try{return await Promise.race([i,new Promise(r=>{t=setTimeout(()=>r(e),15e3)})])}finally{t&&clearTimeout(t)}}function A(i){return i.tier==="pro"||i.tier==="free"?i.tier:i.isPro?"pro":"free"}var U=class{constructor(){this.state={isInitialized:!1,isValidating:!1,isPro:!1,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 E(this.loadCachedLicense(),null);if(e!==this.generation){this.state.isInitialized=!0,this.emit({type:"initialized",isPro:this.state.isPro}),this.startRevalidationTimer();return}if(t&&(this.configuredKey===void 0||t.licenseKey===this.configuredKey)){let r=y(t);this.cachedLicense=t,this.state.licenseKey=t.licenseKey,r&&this.isCacheValid(t)?this.applyTier(A(t)):this.lock(),this.state.expiresAt=t.expiresAt?new Date(t.expiresAt):null,r&&this.isCacheValid(t)&&this.setVerifiedAt(t.cachedAt),this.configuredKey===void 0&&t.licenseKey&&!(r&&this.isCacheValid(t)&&this.isCacheFresh(t))&&this.validateInBackground(t.licenseKey)}this.state.isInitialized=!0,this.emit({type:"initialized",isPro:this.state.isPro}),this.startRevalidationTimer()}catch(t){console.warn("[React Buoy] License initialization failed:",t),this.state.isInitialized=!0,this.emit({type:"initialized",isPro:!1})}}async configure(e){if(e===void 0)return await this.initialize(),this.hasAccountAccess();let t=e.trim().toUpperCase(),r=++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(),r!==this.generation?!1:t?this.setLicenseKey(t):(await this.clearLicense(),!1)}async setLicenseKey(e,t){if(!e||e.trim().length===0)return this.state.error="License key is required",this.state.errorKind="verdict",!1;let r=e.trim().toUpperCase(),n=++this.generation;if(this.cancelRetry(),t?.isRetry||(this.retryAttempt=0),this.state.licenseKey!==r&&this.lock(),this.state.licenseKey=r,this.state.isValidating=!0,this.state.error=null,this.state.errorKind=null,this.emit({type:"validating",isPro:this.isPro()}),ye(r))return this.admitToken(r,n);if(!this.cachedLicense){let a=await E(this.loadCachedLicense(),null);if(n!==this.generation)return!1;a?.licenseKey===r&&(this.cachedLicense=a,y(a)&&this.isCacheValid(a)&&(this.applyTier(A(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===r&&s.fingerprint&&y(s)&&this.isCacheValid(s)&&this.isCacheFresh(s))return this.applyTier(A(s)),this.state.licenseKey=r,this.state.isValidating=!1,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}),!0;let l=await E(this.loadHold(),null);if(n!==this.generation)return!1;let f=(l?.backoffUntil??0)-Date.now();if(f>0)return this.standDown(r,n,"License server is rate limited; retrying later.",f);if(!t?.force&&l?.key===r&&l.verdictAt!==void 0&&Date.now()-l.verdictAt>=0&&Date.now()-l.verdictAt<J)return this.lock(),this.state.isValidating=!1,this.state.error=l.detail||"License could not be verified",this.state.errorKind="verdict",this.emit({type:"error",isPro:!1,error:this.state.error}),!1;let c;try{c=await se(r)}catch(a){let d=a instanceof Error?a.message:"Validation failed";if(n!==this.generation)return!1;if(re(a)){if(te(a)){let g=Math.min(ie(a,V,W)*2**this.retryAttempt,V);return this.retryAttempt+=1,await this.saveHold({...this.hold,backoffUntil:Date.now()+g}),n!==this.generation?!1:this.standDown(r,n,d,g)}return this.state.isValidating=!1,this.cachedLicense&&this.cachedLicense.licenseKey===r&&y(this.cachedLicense)&&this.isCacheValid(this.cachedLicense)?(this.applyTier(A(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(r),this.emit({type:"validated",isPro:this.state.isPro}),!0):(this.state.error=d,this.state.errorKind="transport",this.scheduleRetry(r),this.emit({type:"error",isPro:this.state.isPro,error:d}),!1)}return this.state.isValidating=!1,this.state.error=d,this.state.errorKind="verdict",this.emit({type:"error",isPro:!1,error:d}),!1}try{if(n!==this.generation)return!1;let a=ce(c),d=c.data?.relationships?.product?.data?.id;if((!d||d===p.productId)&&a.code==="EXPIRED"&&(ve(c.data)||this.cachedLicense?.licenseKey===r&&y(this.cachedLicense)&&this.isCacheValid(this.cachedLicense))){let M=Date.now(),z=await this.saveCache({licenseKey:r,licenseId:c.data?.id??"",valid:!0,isPro:!1,tier:"free",expiresAt:null,cachedAt:M,lastValidatedAt:M,fingerprint:this.cachedLicense?.licenseKey===r?this.cachedLicense.fingerprint:void 0},n);return n!==this.generation||!z?!1:(this.cachedLicense=z,this.applyTier("free"),this.state.isValidating=!1,this.state.expiresAt=null,this.setVerifiedAt(M),this.emit({type:"validated",isPro:!1}),!0)}if(le(a.code)||!ae(c))return this.lock(),this.state.isValidating=!1,this.state.error=a.detail||"License could not be verified",this.state.errorKind="verdict",this.emit({type:"error",isPro:!1,error:this.state.error}),await this.clearCachedLicense(),await this.saveHold({key:r,code:a.code,detail:this.state.error,verdictAt:Date.now()}),!1;if(!c.data)return this.lock(),this.state.isValidating=!1,this.state.error=a.detail||"License not found",this.state.errorKind="verdict",this.emit({type:"error",isPro:!1,error:this.state.error}),await this.clearCachedLicense(),!1;let g=_e(c.data),P=c.data.id,D=Date.now(),G=oe(c)>=Q,H=x(),Re=H&&!G,Ie=g==="free"&&(G||!H),_=this.cachedLicense?.fingerprint,L=this.cachedLicense?.deviceName,B=!1;if(!_){if(_=await E(this.getOrCreateDeviceFingerprint(),R()),n!==this.generation)return!1;L=I(),B=Re}let K=!1;B&&(this.deviceRegistrationCallback?(this.pendingRegistration={licenseId:P,licenseKey:r,fingerprint:_},this.deviceRegistrationCallback({fingerprint:_,defaultName:L}),K=!0):this.registerDeviceAsync(P,r,_,L));let O={licenseKey:r,licenseId:P,valid:!0,isPro:g==="pro",tier:g,expiresAt:c.data.attributes.expiry??null,cachedAt:D,lastValidatedAt:D,fingerprint:K?void 0:_,deviceName:K?void 0:L,quiet:Ie||void 0},Y=await this.saveCache(O,n);return n!==this.generation||!Y||(this.cachedLicense=Y,this.applyTier(g),this.state.isValidating=!1,this.state.expiresAt=O.expiresAt?new Date(O.expiresAt):null,this.setVerifiedAt(D),this.hold&&await this.saveHold(null),n!==this.generation)?!1:(this.retryAttempt=0,this.emit({type:"validated",isPro:this.state.isPro}),!0)}catch(a){let d=a instanceof Error?a.message:"Validation failed";return n!==this.generation||(this.state.isValidating=!1,this.state.error=d,this.state.errorKind="verdict",this.emit({type:"error",isPro:!1,error:d})),!1}}scheduleRetry(e){this.cancelRetry();let t=q[this.retryAttempt];if(t===void 0)return;this.retryAttempt+=1;let r=this.generation;this.retryTimer=setTimeout(()=>{this.retryTimer=null,r===this.generation&&(this.state.isValidating||this.setLicenseKey(e,{force:!0,isRetry:!0}))},t),typeof o<"u"&&o&&(globalThis.__LICENSE_MANAGER_RETRY_TIMER__=this.retryTimer)}async admitToken(e,t){let r=Ee(e);if(t!==this.generation)return!1;if(!r)return this.lock(),this.state.isValidating=!1,this.state.error="This key is not valid. Check that it was copied completely.",this.state.errorKind="verdict",this.emit({type:"error",isPro:!1,error:this.state.error}),await this.clearCachedLicense(),!1;let n=Date.now(),s=this.cachedLicense?.fingerprint??await E(this.getOrCreateDeviceFingerprint(),R());if(t!==this.generation)return!1;let l=await this.saveCache({licenseKey:e,licenseId:`token:${r.accountHash}`,valid:!0,isPro:!1,tier:"free",expiresAt:null,cachedAt:n,lastValidatedAt:n,fingerprint:s,deviceName:this.cachedLicense?.deviceName??I(),quiet:!0},t);return t!==this.generation||!l?!1:(this.cachedLicense=l,this.applyTier("free"),this.state.isValidating=!1,this.state.expiresAt=null,this.setVerifiedAt(n),this.retryAttempt=0,this.emit({type:"validated",isPro:!1}),!0)}standDown(e,t,r,n){if(t!==this.generation)return!1;this.state.isValidating=!1;let s=this.cachedLicense;return s&&s.licenseKey===e&&y(s)&&this.isCacheValid(s)?(this.applyTier(A(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,n),this.emit({type:"validated",isPro:this.state.isPro}),!0):(this.state.error=r,this.state.errorKind="transport",this.scheduleRetryIn(e,n),this.emit({type:"error",isPro:this.state.isPro,error:r}),!1)}scheduleRetryIn(e,t){this.cancelRetry();let r=this.generation;this.retryTimer=setTimeout(()=>{this.retryTimer=null,r===this.generation&&(this.state.isValidating||this.setLicenseKey(e,{force:!0,isRetry:!0}))},Math.max(1,Math.min(t,2147483647))),typeof o<"u"&&o&&(u.__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=!1,this.emit({type:"deactivated",isPro:!1}),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=!1,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 Ae({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+v,r=this.state.expiresAt?.getTime(),s=(r&&r>Date.now()?Math.min(t,r):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(s,2147483647))),typeof o<"u"&&o&&(u.__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:r,fingerprint:n}=this.pendingRegistration,s=this.generation,l=e.trim()||I(),f=S();try{await F(t,r,n,l,f)}catch(c){let a=c instanceof Error?c.message:String(c);if(!(a==="FINGERPRINT_TAKEN"||a==="MACHINE_LIMIT_EXCEEDED"))throw console.warn("[Buoy] Device registration failed:",a),c}if(s===this.generation){if(this.cachedLicense?.licenseKey===r){let c=await this.saveCache({...this.cachedLicense,fingerprint:n,deviceName:l},s);if(s!==this.generation)return;c&&(this.cachedLicense=c)}this.pendingRegistration=null}}emit(e){[...this.listeners].forEach(r=>{try{r(e)}catch(n){console.warn("[React Buoy] License listener error:",n)}})}isCacheValid(e){let r=Date.now()-e.cachedAt;return!(!e.valid||!Number.isFinite(e.cachedAt)||r<0||r>=v)}isCacheFresh(e){let t=this.isQuiet(e)?Z:j;return Date.now()-(e.lastValidatedAt??0)<t}isQuiet(e){return e.quiet!==void 0?e.quiet:A(e)==="free"&&!x()}async loadHold(){if(this.hold!==void 0)return this.hold;try{let t=await(await h()).getItem(b),r=t?JSON.parse(t):null;this.hold=r&&typeof r=="object"?r:null}catch{this.hold=null}return this.hold}async saveHold(e){this.hold=e;try{let t=await h();e?await t.setItem(b,JSON.stringify(e)):await t.removeItem(b)}catch{}}async persistCache(e){let t=k(e);return await(await h()).setItem(C,JSON.stringify(t)),t}saveCache(e,t){let r=this.persistence.catch(()=>{}).then(async()=>{if(t!==this.generation)return null;let n=await this.persistCache(e);return t===this.generation?n:null});return this.persistence=r,E(r,k(e))}async loadCachedLicense(){try{await this.persistence.catch(()=>{});let t=await(await h()).getItem(C);return t?JSON.parse(t):null}catch(e){return console.warn("[Buoy] Error loading cached license:",e),null}}getOrCreateDeviceFingerprint(){return this.fingerprintPromise||(this.fingerprintPromise=(async()=>{let e=await h(),t=await e.getItem(w);if(t)return t;let r=this.cachedLicense?.fingerprint||R();return await e.setItem(w,r),r})()),this.fingerprintPromise}async clearCachedLicense(){this.cachedLicense=null;let e=this.persistence.catch(()=>{}).then(async()=>{await(await h()).removeItem(C)});this.persistence=e,await E(e.catch(()=>{}),void 0)}registerDeviceAsync(e,t,r,n){let s=S();F(e,t,r,n,s).catch(l=>{l.message!=="FINGERPRINT_TAKEN"&&l.message!=="MACHINE_LIMIT_EXCEEDED"&&console.warn("[Buoy] Device registration failed (non-blocking):",l.message)})}validateInBackground(e){this.setLicenseKey(e,{force:!0,isRetry:!0})}refreshAccess(){this.emit({type:"validated",isPro:this.isPro()})}startRevalidationTimer(){this.removeForegroundListener||(this.removeForegroundListener=Te(()=>this.refreshAccess()),typeof o<"u"&&o&&(u.__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)},X),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 h()).removeItem(w)}catch{}}},bt=new U,u=globalThis;typeof o<"u"&&o&&(u.__LICENSE_MANAGER_FOREGROUND_OFF__?.(),u.__LICENSE_MANAGER_FOREGROUND_OFF__=void 0,u.__LICENSE_MANAGER_EXPIRY_TIMER__&&clearTimeout(u.__LICENSE_MANAGER_EXPIRY_TIMER__),u.__LICENSE_MANAGER_TIMER__&&clearInterval(u.__LICENSE_MANAGER_TIMER__),u.__LICENSE_MANAGER_RETRY_TIMER__&&(clearTimeout(u.__LICENSE_MANAGER_RETRY_TIMER__),u.__LICENSE_MANAGER_RETRY_TIMER__=void 0));export{m as a,re as b,ye as c,Ae as d,bt as e};
3
+ /*!
4
+ * PROPRIETARY — Buoy Pro license enforcement. NOT open source.
5
+ *
6
+ * Copyright (c) Buoy. All rights reserved. Licensed under the Buoy EULA
7
+ * (https://buoy.gg/terms), not an OSS license.
8
+ *
9
+ * This file configures the technological measure that controls access to paid
10
+ * Buoy Pro features. Modifying, patching, aliasing, stubbing, or otherwise
11
+ * altering it — including repointing `apiUrl` at a stand-in license server — so
12
+ * that Pro features unlock without a valid license is a breach of the EULA and,
13
+ * in the United States, circumvention of an access control under 17 U.S.C.
14
+ * § 1201, which applies whether or not any code is copied.
15
+ *
16
+ * Pro is $9/mo, and is free every weekend for anyone holding a key —
17
+ * including a free one (`npx buoy login`). Buy a key at
18
+ * https://buoy.gg or use it free on Saturday and Sunday.
19
+ */
20
+ /*!
21
+ * PROPRIETARY — Buoy Pro license enforcement. NOT open source.
22
+ *
23
+ * Copyright (c) Buoy. All rights reserved. Licensed under the Buoy EULA
24
+ * (https://buoy.gg/terms), not an OSS license.
25
+ *
26
+ * This file is part of the technological measure that controls access to paid
27
+ * Buoy Pro features. Modifying, patching, aliasing, stubbing, or otherwise
28
+ * altering it so that Pro features unlock without a valid license is a breach
29
+ * of the EULA and, in the United States, circumvention of an access control
30
+ * under 17 U.S.C. § 1201 — which applies whether or not any code is copied.
31
+ *
32
+ * Pro is $9/mo, and is free every weekend for anyone holding a key —
33
+ * including a free one (`npx buoy login`). Buy a key at
34
+ * https://buoy.gg or use it free on Saturday and Sunday.
35
+ */
36
+ /*!
37
+ * PROPRIETARY — Buoy Pro license enforcement. NOT open source.
38
+ *
39
+ * Copyright (c) Buoy. All rights reserved. Licensed under the Buoy EULA
40
+ * (https://buoy.gg/terms), not an OSS license.
41
+ */
42
+ /*!
43
+ * PROPRIETARY — Buoy Pro license enforcement. NOT open source.
44
+ *
45
+ * Copyright (c) Buoy. All rights reserved. Licensed under the Buoy EULA
46
+ * (https://buoy.gg/terms), not an OSS license.
47
+ *
48
+ * This file is part of the technological measure that controls access to paid
49
+ * Buoy Pro features: it decides which tier a validated key grants. Modifying,
50
+ * patching, aliasing, stubbing, or otherwise altering it so that Pro features
51
+ * unlock without a valid license is a breach of the EULA and, in the United
52
+ * States, circumvention of an access control under 17 U.S.C. § 1201 — which
53
+ * applies whether or not any code is copied.
54
+ *
55
+ * Pro is $9/mo, and is free every weekend for anyone holding a key —
56
+ * including a free one (`npx buoy login`). Buy a key at
57
+ * https://buoy.gg or use it free on Saturday and Sunday.
58
+ */
59
+ /*!
60
+ * PROPRIETARY — Buoy Pro license enforcement. NOT open source.
61
+ *
62
+ * Copyright (c) Buoy. All rights reserved. Licensed under the Buoy EULA
63
+ * (https://buoy.gg/terms), not an OSS license.
64
+ *
65
+ * This file is the technological measure that controls access to paid Buoy Pro
66
+ * features. Modifying, patching, aliasing, stubbing, or otherwise altering it
67
+ * so that Pro features unlock without a valid license is a breach of the EULA
68
+ * and, in the United States, circumvention of an access control under
69
+ * 17 U.S.C. § 1201 — which applies whether or not any code is copied.
70
+ *
71
+ * Pro is $9/mo, and is free every weekend for anyone holding a key —
72
+ * including a free one (`npx buoy login`). Buy a key at
73
+ * https://buoy.gg or use it free on Saturday and Sunday.
74
+ */