@buoy-gg/license 7.0.56 → 7.0.57
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/capacitorBridge.js +1 -0
- package/lib/commonjs/capacitorHost.js +1 -0
- package/lib/commonjs/device-info.web.js +1 -1
- package/lib/commonjs/index.js +2 -2
- package/lib/commonjs/index.web.js +2 -2
- package/lib/commonjs/storage.js +1 -1
- package/lib/module/capacitorBridge.js +1 -0
- package/lib/module/capacitorHost.js +1 -0
- package/lib/module/device-info.web.js +1 -1
- package/lib/module/index.js +1 -1
- package/lib/module/index.web.js +1 -1
- package/lib/module/storage.js +1 -1
- package/lib/typescript/commonjs/capacitorBridge.d.ts +130 -0
- package/lib/typescript/commonjs/capacitorHost.d.ts +50 -0
- package/lib/typescript/commonjs/index.d.ts +4 -0
- package/lib/typescript/commonjs/index.web.d.ts +4 -0
- package/lib/typescript/module/capacitorBridge.d.ts +130 -0
- package/lib/typescript/module/capacitorHost.d.ts +50 -0
- package/lib/typescript/module/index.d.ts +4 -0
- package/lib/typescript/module/index.web.d.ts +4 -0
- package/lib/web/capacitor.mjs +1 -0
- package/lib/web/chunks/LicenseManager-X7ZLSRCH.mjs +1 -0
- package/lib/web/chunks/chunk-3JAIQNSD.mjs +73 -0
- package/lib/web/chunks/chunk-J7MW3NXU.mjs +1 -0
- package/lib/web/chunks/chunk-UPTHA45A.mjs +1 -0
- package/lib/web/index.mjs +1 -1
- package/package.json +19 -1
- package/lib/web/chunks/LicenseManager-GJQ6MGWU.mjs +0 -1
- package/lib/web/chunks/chunk-FPGC7BWV.mjs +0 -73
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.callCapacitorAsApp=callCapacitorAsApp;exports.callCapacitorNative=callCapacitorNative;exports.callCapacitorNativeCallback=callCapacitorNativeCallback;exports.capacitorListenerCount=capacitorListenerCount;exports.capacitorPlugin=capacitorPlugin;exports.clearCapacitorCalls=clearCapacitorCalls;exports.colorSchemeQueryValue=colorSchemeQueryValue;exports.emitCapacitorEvent=emitCapacitorEvent;exports.getCapacitorAppHost=getCapacitorAppHost;exports.getCapacitorCalls=getCapacitorCalls;exports.getColorSchemeQueries=getColorSchemeQueries;exports.hasCapacitorPlugin=hasCapacitorPlugin;exports.installCapacitorBridge=installCapacitorBridge;exports.interceptCapacitor=interceptCapacitor;exports.isCapacitorBridgeInstalled=isCapacitorBridgeInstalled;exports.listenCapacitorNative=listenCapacitorNative;exports.loadCapacitorAppHost=loadCapacitorAppHost;exports.makeCapacitorCallbackId=makeCapacitorCallbackId;exports.subscribeCapacitorCalls=subscribeCapacitorCalls;var _capacitorHost=require("./capacitorHost.js");const STATE_KEY="__BUOY_CAPACITOR_BRIDGE__";const LOG_LIMIT=300;function capacitor(){const e=globalThis.Capacitor;return e&&typeof e==="object"?e:null}function state(){const e=globalThis;let t=e[STATE_KEY];if(!t||t.version!==1){t={version:1,originalPromise:null,originalCallback:null,wrappedPromise:null,wrappedCallback:null,interceptors:[],listeners:new Map,log:[],subscribers:new Set,seq:0,fakeIds:0};e[STATE_KEY]=t}return t}function realNow(){const e=globalThis.__buoyRealNow;return typeof e==="function"?e():Date.now()}function asOptions(e){return e&&typeof e==="object"?e:{}}function notify(e){for(const t of Array.from(e.subscribers)){try{t()}catch{}}}function record(e,t){const r={seq:++e.seq,...t};e.log.push(r);if(e.log.length>LOG_LIMIT)e.log.splice(0,e.log.length-LOG_LIMIT);notify(e);return r}function matching(e,t,r){return e.interceptors.filter(n=>(n.plugin==="*"||n.plugin===t.plugin)&&(!n.methods||n.methods.includes(t.method))&&typeof n[r]==="function").map((n,o)=>({interceptor:n,index:o})).sort((n,o)=>(o.interceptor.order??0)-(n.interceptor.order??0)||n.index-o.index).map(n=>n.interceptor)}function listenerKey(e,t){return`${e}:${String(t)}`}function makeCapacitorCallbackId(){return`buoy-${++state().fakeIds}`}function installCapacitorBridge(e={}){if(!(0,_capacitorHost.isCapacitorNative)())return false;const t=capacitor();if(!t||typeof t.nativePromise!=="function"||typeof t.nativeCallback!=="function")return false;const r=state();if(r.wrappedPromise&&t.nativePromise===r.wrappedPromise&&t.nativeCallback===r.wrappedCallback)return true;if(t.DEBUG!==true&&e.release!==true)return false;r.originalPromise=t.nativePromise;r.originalCallback=t.nativeCallback;const n=r.originalPromise;const o=r.originalCallback;const i=(a,s,C,v)=>{const f={plugin:a,method:s,options:asOptions(C)};const g=matching(r,f,"promise");const c=d=>{if(d>=g.length){v();if(s==="removeAllListeners"){for(const b of Array.from(r.listeners.keys()))if(b.startsWith(`${a}:`))r.listeners.delete(b)}return n.call(t,a,s,C)}try{return Promise.resolve(g[d].promise(f,()=>c(d+1)))}catch(b){return Promise.reject(b)}};return c(0)};r.runPromise=i;const l=(a,s,C)=>{const v=record(r,{plugin:a,method:s,kind:"promise",options:asOptions(C),start:realNow()});let f=false;const g=i(a,s,C,()=>{f=true});g.then(c=>{Object.assign(v,{end:realNow(),ok:true,result:c,answeredByBuoy:!f});notify(r)},c=>{Object.assign(v,{end:realNow(),ok:false,error:c,answeredByBuoy:!f});notify(r)});return g};const p=(a,s,C,v)=>{let f=C;let g=v;if(typeof f==="function"){g=f;f=null}const c={plugin:a,method:s,options:asOptions(f)};const d=record(r,{plugin:a,method:s,kind:"callback",options:c.options,start:realNow(),events:0});let b=false;const k=matching(r,c,"callback");const P=(m,u)=>{if(m>=k.length){b=true;return o.call(t,a,s,f,u)}return k[m].callback(c,u,h=>P(m+1,h))};const _=s==="addListener";const w=(m,u)=>{d.events=(d.events??0)+1;if(!_&&d.end===void 0){d.end=realNow();d.ok=!u;if(u)d.error=u;else d.result=m;notify(r)}else{const h=realNow();record(r,{plugin:a,method:_?String(c.options.eventName??"event"):s,kind:"event",options:{},start:h,end:h,ok:!u,...u?{error:u}:{result:m}})}g?.(m,u)};const y=P(0,w);d.answeredByBuoy=!b;if(s==="addListener"&&y!=null&&typeof g==="function"){const m=listenerKey(a,c.options.eventName);let u=r.listeners.get(m);if(!u)r.listeners.set(m,u=new Map);u.set(String(y),g)}else if(s==="removeListener"){r.listeners.get(listenerKey(a,c.options.eventName))?.delete(String(c.options.callbackId))}return y};t.nativePromise=l;t.nativeCallback=p;r.wrappedPromise=l;r.wrappedCallback=p;trackColorSchemeQueries();return true}const SCHEME_QUERY=/^\s*\(\s*prefers-color-scheme\s*:\s*(dark|light)\s*\)\s*$/i;const SCHEME_KEY="__BUOY_COLOR_SCHEME_QUERIES__";function colorSchemeQueryValue(e){const t=SCHEME_QUERY.exec(e);return t?t[1].toLowerCase():null}function trackColorSchemeQueries(){const e=globalThis;const t=globalThis.WeakRef;if(e[SCHEME_KEY]||typeof e.matchMedia!=="function"||!t)return;const r=[];e[SCHEME_KEY]=r;const n=e.matchMedia;e.matchMedia=function o(i){const l=n.call(this??globalThis,i);if(l&&colorSchemeQueryValue(String(i))){for(let p=r.length-1;p>=0;p--)if(!r[p].deref())r.splice(p,1);r.push(new t(l))}return l}}function getColorSchemeQueries(){const e=globalThis[SCHEME_KEY];if(!e)return[];return e.map(t=>t.deref()).filter(t=>!!t)}function isCapacitorBridgeInstalled(){const e=capacitor();const t=state();return Boolean(t.wrappedPromise&&e?.nativePromise===t.wrappedPromise)}function interceptCapacitor(e){const t=state();t.interceptors.push(e);return()=>{const r=t.interceptors.indexOf(e);if(r>=0)t.interceptors.splice(r,1)}}function emitCapacitorEvent(e,t,r){const n=state().listeners.get(listenerKey(e,t));if(!n)return 0;let o=0;for(const i of Array.from(n.values())){try{i(r);o++}catch(l){globalThis.console?.error(l)}}return o}function capacitorListenerCount(e,t){return state().listeners.get(listenerKey(e,t))?.size??0}function pluginHeader(e){return capacitor()?.PluginHeaders?.find(t=>t.name===e)}function hasCapacitorPlugin(e){if(!(0,_capacitorHost.isCapacitorNative)())return false;try{return Boolean(pluginHeader(e))||capacitor()?.isPluginAvailable?.(e)===true}catch{return false}}function originals(){const e=capacitor();const t=state();return{cap:e,promise:t.originalPromise??e?.nativePromise??null,callback:t.originalCallback??e?.nativeCallback??null}}function callCapacitorNative(e,t,r={}){const{cap:n,promise:o}=originals();if(!n||!o)return Promise.reject(new Error("Capacitor bridge unavailable"));return o.call(n,e,t,r)}function callCapacitorAsApp(e,t,r={}){const n=state().runPromise;if(n&&isCapacitorBridgeInstalled())return n(e,t,r,()=>{});return callCapacitorNative(e,t,r)}function callCapacitorNativeCallback(e,t,r,n){const{cap:o,callback:i}=originals();if(!o||!i)return null;return i.call(o,e,t,r,n)}function listenCapacitorNative(e,t,r){const{cap:n,promise:o,callback:i}=originals();if(!n||!i)return Promise.reject(new Error("Capacitor bridge unavailable"));const l=i.call(n,e,"addListener",{eventName:t},a=>r(a));const p=async()=>{if(l==null)return;const a={eventName:t,callbackId:l};const s=pluginHeader(e)?.methods?.find(C=>C.name==="removeListener")?.rtype;if(s==="promise"&&o)await o.call(n,e,"removeListener",a);else i.call(n,e,"removeListener",a,()=>{})};return Promise.resolve({remove:p})}function getCapacitorCalls(){return state().log}function clearCapacitorCalls(){const e=state();e.log.length=0;notify(e)}function subscribeCapacitorCalls(e){const t=state();t.subscribers.add(e);return()=>{t.subscribers.delete(e)}}const NOT_METHODS=new Set(["then","catch","finally","$$typeof","toJSON","constructor"]);function capacitorPlugin(e){if(!hasCapacitorPlugin(e))return null;return new Proxy({},{get(t,r){if(typeof r!=="string"||NOT_METHODS.has(r))return void 0;if(r==="addListener"){return(n,o)=>listenCapacitorNative(e,n,o)}return n=>callCapacitorNative(e,r,n??{})}})}const HOST_KEY="__BUOY_CAPACITOR_HOST__";function loadCapacitorAppHost(){if(!(0,_capacitorHost.isCapacitorNative)())return Promise.resolve(null);const e=globalThis;const t=e[HOST_KEY];if(t)return t;const r=i=>typeof i==="string"&&i?i:null;const n=async i=>{if(!hasCapacitorPlugin(i))return{};try{return await callCapacitorNative(i,"getInfo")??{}}catch{return{}}};const o=Promise.all([n("App"),n("Device")]).then(([i,l])=>{const p={isSimulator:typeof l.isVirtual==="boolean"?l.isVirtual:null,deviceName:r(l.name),bundleId:r(i.id),appName:r(i.name)};e[`${HOST_KEY}_value`]=p;return p});e[HOST_KEY]=o;return o}function getCapacitorAppHost(){return globalThis[`${HOST_KEY}_value`]??null}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.capacitorDebug=capacitorDebug;exports.capacitorPlatform=capacitorPlatform;exports.isCapacitorNative=isCapacitorNative;exports.resolveDevBuild=resolveDevBuild;function capacitorGlobal(){const t=globalThis.Capacitor;return t&&typeof t==="object"?t:null}function isCapacitorNative(){try{return capacitorGlobal()?.isNativePlatform?.()===true}catch{return false}}function capacitorPlatform(){if(!isCapacitorNative())return null;try{const t=capacitorGlobal()?.getPlatform?.();return t==="ios"||t==="android"?t:null}catch{return null}}function capacitorDebug(){if(!isCapacitorNative())return null;return capacitorGlobal()?.DEBUG===true}function resolveDevBuild(t){return capacitorDebug()??t}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.generateUUID=generateUUID;exports.getDefaultDeviceName=getDefaultDeviceName;exports.getDeviceMetadata=getDeviceMetadata;exports.isDevBundle=isDevBundle;exports.isSimulator=isSimulator;function generateUUID(){if(typeof crypto!=="undefined"&&crypto.randomUUID){return crypto.randomUUID()}return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const n=Math.random()*16|0;const r=e==="x"?n:n&3|8;return r.toString(16)})}function isDevBundle(){if(typeof __DEV__!=="undefined")return __DEV__;try{if(typeof navigator!=="undefined"&&/electron/i.test(navigator.userAgent))return true}catch{}return typeof process!=="undefined"&&process.env?.NODE_ENV!=="production"}function isSimulator(){return false}function detectPlatform(){if(typeof navigator==="undefined"){return"unknown"}const e=navigator.userAgent.toLowerCase();const n=navigator.platform?.toLowerCase()||"";if(e.includes("electron")){if(n.includes("mac")||e.includes("mac")){return"electron-macos"}if(n.includes("win")||e.includes("win")){return"electron-windows"}if(n.includes("linux")||e.includes("linux")){return"electron-linux"}return"electron"}if(n.includes("mac")||e.includes("mac")){return"macos"}if(n.includes("win")||e.includes("win")){return"windows"}if(n.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 getOSVersion(){if(typeof navigator==="undefined"){return"unknown"}const e=navigator.userAgent;const n=e.match(/Mac OS X ([\d_.]+)/);if(n){return n[1].replace(/_/g,".")}const r=e.match(/Windows NT ([\d.]+)/);if(r){const t={"10.0":"10/11","6.3":"8.1","6.2":"8","6.1":"7"};return t[r[1]]||r[1]}if(e.includes("Linux")){return"Linux"}return"unknown"}function getBrowserInfo(){if(typeof navigator==="undefined"){return{name:"unknown",version:"unknown"}}const e=navigator.userAgent;const n=e.match(/Electron\/([\d.]+)/);if(n){return{name:"Electron",version:n[1]}}const r=e.match(/Chrome\/([\d.]+)/);if(r&&!e.includes("Edg")){return{name:"Chrome",version:r[1]}}const t=e.match(/Edg\/([\d.]+)/);if(t){return{name:"Edge",version:t[1]}}const o=e.match(/Firefox\/([\d.]+)/);if(o){return{name:"Firefox",version:o[1]}}const i=e.match(/Version\/([\d.]+).*Safari/);if(i){return{name:"Safari",version:i[1]}}return{name:"unknown",version:"unknown"}}function getDeviceMetadata(){const e={platform:detectPlatform(),osVersion:getOSVersion(),isSimulator:"false"};const n=getBrowserInfo();e.browser=n.name;e.browserVersion=n.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 getDefaultDeviceName(){const e=detectPlatform();const n=getBrowserInfo();if(e.startsWith("electron")){const r=e.replace("electron-","").replace("electron","Desktop");return`${r.charAt(0).toUpperCase()+r.slice(1)} App`}if(n.name!=="unknown"){return`${n.name} Browser`}return"Web Browser"}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.generateUUID=generateUUID;exports.getDefaultDeviceName=getDefaultDeviceName;exports.getDeviceMetadata=getDeviceMetadata;exports.isDevBundle=isDevBundle;exports.isSimulator=isSimulator;var _capacitorHost=require("./capacitorHost.js");function generateUUID(){if(typeof crypto!=="undefined"&&crypto.randomUUID){return crypto.randomUUID()}return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const n=Math.random()*16|0;const r=e==="x"?n:n&3|8;return r.toString(16)})}function isDevBundle(){const e=(0,_capacitorHost.capacitorDebug)();if(e!==null)return e;if(typeof __DEV__!=="undefined")return __DEV__;try{if(typeof navigator!=="undefined"&&/electron/i.test(navigator.userAgent))return true}catch{}return typeof process!=="undefined"&&process.env?.NODE_ENV!=="production"}function isSimulator(){return false}function detectPlatform(){if(typeof navigator==="undefined"){return"unknown"}const e=navigator.userAgent.toLowerCase();const n=navigator.platform?.toLowerCase()||"";if(e.includes("electron")){if(n.includes("mac")||e.includes("mac")){return"electron-macos"}if(n.includes("win")||e.includes("win")){return"electron-windows"}if(n.includes("linux")||e.includes("linux")){return"electron-linux"}return"electron"}if(n.includes("mac")||e.includes("mac")){return"macos"}if(n.includes("win")||e.includes("win")){return"windows"}if(n.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 getOSVersion(){if(typeof navigator==="undefined"){return"unknown"}const e=navigator.userAgent;const n=e.match(/Mac OS X ([\d_.]+)/);if(n){return n[1].replace(/_/g,".")}const r=e.match(/Windows NT ([\d.]+)/);if(r){const t={"10.0":"10/11","6.3":"8.1","6.2":"8","6.1":"7"};return t[r[1]]||r[1]}if(e.includes("Linux")){return"Linux"}return"unknown"}function getBrowserInfo(){if(typeof navigator==="undefined"){return{name:"unknown",version:"unknown"}}const e=navigator.userAgent;const n=e.match(/Electron\/([\d.]+)/);if(n){return{name:"Electron",version:n[1]}}const r=e.match(/Chrome\/([\d.]+)/);if(r&&!e.includes("Edg")){return{name:"Chrome",version:r[1]}}const t=e.match(/Edg\/([\d.]+)/);if(t){return{name:"Edge",version:t[1]}}const o=e.match(/Firefox\/([\d.]+)/);if(o){return{name:"Firefox",version:o[1]}}const i=e.match(/Version\/([\d.]+).*Safari/);if(i){return{name:"Safari",version:i[1]}}return{name:"unknown",version:"unknown"}}function getDeviceMetadata(){const e={platform:detectPlatform(),osVersion:getOSVersion(),isSimulator:"false"};const n=getBrowserInfo();e.browser=n.name;e.browserVersion=n.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 getDefaultDeviceName(){const e=detectPlatform();const n=getBrowserInfo();if(e.startsWith("electron")){const r=e.replace("electron-","").replace("electron","Desktop");return`${r.charAt(0).toUpperCase()+r.slice(1)} App`}if(n.name!=="unknown"){return`${n.name} Browser`}return"Web Browser"}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"DeviceRegistrationModal",{enumerable:true,get:function(){return _DeviceRegistrationModal.DeviceRegistrationModal}});Object.defineProperty(exports,"LicenseManager",{enumerable:true,get:function(){return _LicenseManager.LicenseManager}});Object.defineProperty(exports,"LicenseTransportError",{enumerable:true,get:function(){return _api.LicenseTransportError}});Object.defineProperty(exports,"SessionError",{enumerable:true,get:function(){return _sessionManager.SessionError}});Object.defineProperty(exports,"SessionManager",{enumerable:true,get:function(){return _sessionManager.SessionManager}});Object.defineProperty(exports,"getSyncCredential",{enumerable:true,get:function(){return _syncCredential.getSyncCredential}});exports.hasEntitlement=hasEntitlement;Object.defineProperty(exports,"isBuoyToken",{enumerable:true,get:function(){return _freeToken.isBuoyToken}});Object.defineProperty(exports,"isDevToken",{enumerable:true,get:function(){return _devToken.isDevToken}});exports.isPro=isPro;Object.defineProperty(exports,"isServiceKey",{enumerable:true,get:function(){return _serviceKey.isServiceKey}});Object.defineProperty(exports,"isTransientLicenseError",{enumerable:true,get:function(){return _api.isTransientLicenseError}});Object.defineProperty(exports,"isWeekendFreePro",{enumerable:true,get:function(){return _weekendPro.isWeekendFreePro}});Object.defineProperty(exports,"normalizeLicenseKey",{enumerable:true,get:function(){return _serviceKey.normalizeLicenseKey}});Object.defineProperty(exports,"resolveAccountAccess",{enumerable:true,get:function(){return _accountAccess.resolveAccountAccess}});Object.defineProperty(exports,"sameLicenseKey",{enumerable:true,get:function(){return _serviceKey.sameLicenseKey}});exports.setLicenseKey=setLicenseKey;Object.defineProperty(exports,"useAccountAccess",{enumerable:true,get:function(){return _hooks.useAccountAccess}});Object.defineProperty(exports,"useBuoySession",{enumerable:true,get:function(){return _hooks.useBuoySession}});Object.defineProperty(exports,"useFeatureAccess",{enumerable:true,get:function(){return _hooks.useFeatureAccess}});Object.defineProperty(exports,"useIsPro",{enumerable:true,get:function(){return _hooks.useIsPro}});Object.defineProperty(exports,"useLicense",{enumerable:true,get:function(){return _hooks.useLicense}});Object.defineProperty(exports,"useProAccess",{enumerable:true,get:function(){return _hooks.useProAccess}});Object.defineProperty(exports,"useTier",{enumerable:true,get:function(){return _hooks.useTier}});Object.defineProperty(exports,"useWeekendFreePro",{enumerable:true,get:function(){return _weekendPro.useWeekendFreePro}});var _LicenseManager=require("./LicenseManager.js");var _DeviceRegistrationModal=require("./DeviceRegistrationModal.js");var _hooks=require("./hooks.js");var _accountAccess=require("./accountAccess.js");var _api=require("./api.js");var _sessionManager=require("./sessionManager.js");var _serviceKey=require("./serviceKey.js");var _devToken=require("./devToken.js");var _syncCredential=require("./syncCredential.js");var _freeToken=require("./freeToken.js");var _weekendPro=require("./weekendPro.js");function _interopRequireWildcard(r,
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"DeviceRegistrationModal",{enumerable:true,get:function(){return _DeviceRegistrationModal.DeviceRegistrationModal}});Object.defineProperty(exports,"LicenseManager",{enumerable:true,get:function(){return _LicenseManager.LicenseManager}});Object.defineProperty(exports,"LicenseTransportError",{enumerable:true,get:function(){return _api.LicenseTransportError}});Object.defineProperty(exports,"SessionError",{enumerable:true,get:function(){return _sessionManager.SessionError}});Object.defineProperty(exports,"SessionManager",{enumerable:true,get:function(){return _sessionManager.SessionManager}});Object.defineProperty(exports,"callCapacitorAsApp",{enumerable:true,get:function(){return _capacitorBridge.callCapacitorAsApp}});Object.defineProperty(exports,"callCapacitorNative",{enumerable:true,get:function(){return _capacitorBridge.callCapacitorNative}});Object.defineProperty(exports,"callCapacitorNativeCallback",{enumerable:true,get:function(){return _capacitorBridge.callCapacitorNativeCallback}});Object.defineProperty(exports,"capacitorDebug",{enumerable:true,get:function(){return _capacitorHost.capacitorDebug}});Object.defineProperty(exports,"capacitorListenerCount",{enumerable:true,get:function(){return _capacitorBridge.capacitorListenerCount}});Object.defineProperty(exports,"capacitorPlatform",{enumerable:true,get:function(){return _capacitorHost.capacitorPlatform}});Object.defineProperty(exports,"capacitorPlugin",{enumerable:true,get:function(){return _capacitorBridge.capacitorPlugin}});Object.defineProperty(exports,"clearCapacitorCalls",{enumerable:true,get:function(){return _capacitorBridge.clearCapacitorCalls}});Object.defineProperty(exports,"colorSchemeQueryValue",{enumerable:true,get:function(){return _capacitorBridge.colorSchemeQueryValue}});Object.defineProperty(exports,"emitCapacitorEvent",{enumerable:true,get:function(){return _capacitorBridge.emitCapacitorEvent}});Object.defineProperty(exports,"getCapacitorAppHost",{enumerable:true,get:function(){return _capacitorBridge.getCapacitorAppHost}});Object.defineProperty(exports,"getCapacitorCalls",{enumerable:true,get:function(){return _capacitorBridge.getCapacitorCalls}});Object.defineProperty(exports,"getColorSchemeQueries",{enumerable:true,get:function(){return _capacitorBridge.getColorSchemeQueries}});Object.defineProperty(exports,"getSyncCredential",{enumerable:true,get:function(){return _syncCredential.getSyncCredential}});Object.defineProperty(exports,"hasCapacitorPlugin",{enumerable:true,get:function(){return _capacitorBridge.hasCapacitorPlugin}});exports.hasEntitlement=hasEntitlement;Object.defineProperty(exports,"installCapacitorBridge",{enumerable:true,get:function(){return _capacitorBridge.installCapacitorBridge}});Object.defineProperty(exports,"interceptCapacitor",{enumerable:true,get:function(){return _capacitorBridge.interceptCapacitor}});Object.defineProperty(exports,"isBuoyToken",{enumerable:true,get:function(){return _freeToken.isBuoyToken}});Object.defineProperty(exports,"isCapacitorBridgeInstalled",{enumerable:true,get:function(){return _capacitorBridge.isCapacitorBridgeInstalled}});Object.defineProperty(exports,"isCapacitorNative",{enumerable:true,get:function(){return _capacitorHost.isCapacitorNative}});Object.defineProperty(exports,"isDevToken",{enumerable:true,get:function(){return _devToken.isDevToken}});exports.isPro=isPro;Object.defineProperty(exports,"isServiceKey",{enumerable:true,get:function(){return _serviceKey.isServiceKey}});Object.defineProperty(exports,"isTransientLicenseError",{enumerable:true,get:function(){return _api.isTransientLicenseError}});Object.defineProperty(exports,"isWeekendFreePro",{enumerable:true,get:function(){return _weekendPro.isWeekendFreePro}});Object.defineProperty(exports,"listenCapacitorNative",{enumerable:true,get:function(){return _capacitorBridge.listenCapacitorNative}});Object.defineProperty(exports,"loadCapacitorAppHost",{enumerable:true,get:function(){return _capacitorBridge.loadCapacitorAppHost}});Object.defineProperty(exports,"makeCapacitorCallbackId",{enumerable:true,get:function(){return _capacitorBridge.makeCapacitorCallbackId}});Object.defineProperty(exports,"normalizeLicenseKey",{enumerable:true,get:function(){return _serviceKey.normalizeLicenseKey}});Object.defineProperty(exports,"resolveAccountAccess",{enumerable:true,get:function(){return _accountAccess.resolveAccountAccess}});Object.defineProperty(exports,"resolveDevBuild",{enumerable:true,get:function(){return _capacitorHost.resolveDevBuild}});Object.defineProperty(exports,"sameLicenseKey",{enumerable:true,get:function(){return _serviceKey.sameLicenseKey}});exports.setLicenseKey=setLicenseKey;Object.defineProperty(exports,"subscribeCapacitorCalls",{enumerable:true,get:function(){return _capacitorBridge.subscribeCapacitorCalls}});Object.defineProperty(exports,"useAccountAccess",{enumerable:true,get:function(){return _hooks.useAccountAccess}});Object.defineProperty(exports,"useBuoySession",{enumerable:true,get:function(){return _hooks.useBuoySession}});Object.defineProperty(exports,"useFeatureAccess",{enumerable:true,get:function(){return _hooks.useFeatureAccess}});Object.defineProperty(exports,"useIsPro",{enumerable:true,get:function(){return _hooks.useIsPro}});Object.defineProperty(exports,"useLicense",{enumerable:true,get:function(){return _hooks.useLicense}});Object.defineProperty(exports,"useProAccess",{enumerable:true,get:function(){return _hooks.useProAccess}});Object.defineProperty(exports,"useTier",{enumerable:true,get:function(){return _hooks.useTier}});Object.defineProperty(exports,"useWeekendFreePro",{enumerable:true,get:function(){return _weekendPro.useWeekendFreePro}});var _LicenseManager=require("./LicenseManager.js");var _DeviceRegistrationModal=require("./DeviceRegistrationModal.js");var _hooks=require("./hooks.js");var _accountAccess=require("./accountAccess.js");var _api=require("./api.js");var _sessionManager=require("./sessionManager.js");var _serviceKey=require("./serviceKey.js");var _capacitorHost=require("./capacitorHost.js");var _capacitorBridge=require("./capacitorBridge.js");var _devToken=require("./devToken.js");var _syncCredential=require("./syncCredential.js");var _freeToken=require("./freeToken.js");var _weekendPro=require("./weekendPro.js");function _interopRequireWildcard(r,t){if("function"==typeof WeakMap)var u=new WeakMap,s=new WeakMap;return(_interopRequireWildcard=function(e,c){if(!c&&e&&e.__esModule)return e;var n,a,i={__proto__:null,default:e};if(null===e||"object"!=typeof e&&"function"!=typeof e)return i;if(n=c?s:u){if(n.has(e))return n.get(e);n.set(e,i)}for(const o in e)"default"!==o&&{}.hasOwnProperty.call(e,o)&&((a=(n=Object.defineProperty)&&Object.getOwnPropertyDescriptor(e,o))&&(a.get||a.set)?n(i,o,a):i[o]=e[o]);return i})(r,t)}/*!
|
|
2
2
|
* PROPRIETARY — Buoy Pro license enforcement. NOT open source.
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Buoy. All rights reserved. Licensed under the Buoy EULA
|
|
@@ -15,4 +15,4 @@
|
|
|
15
15
|
* Pro is $9/mo, and is free every weekend for anyone holding a key —
|
|
16
16
|
* including a free one (`npx buoy login`). Buy a key at
|
|
17
17
|
* https://buoy.gg or use it free on Saturday and Sunday.
|
|
18
|
-
*/async function setLicenseKey(r){const{LicenseManager:
|
|
18
|
+
*/async function setLicenseKey(r){const{LicenseManager:t}=await Promise.resolve().then(()=>_interopRequireWildcard(require("./LicenseManager")));await t.initialize();return t.setLicenseKey(r)}function weekendPassActive(){const{isWeekendFreePro:r,weekendPassAppliesTo:t}=require("./weekendPro");const{LicenseManager:u}=require("./LicenseManager");return t(u.hasAccountAccess(),r())}function isPro(){const{LicenseManager:r}=require("./LicenseManager");if(r.isPro())return true;return weekendPassActive()}function hasEntitlement(r){const{LicenseManager:t}=require("./LicenseManager");if(t.hasEntitlement(r))return true;return weekendPassActive()}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"LicenseManager",{enumerable:true,get:function(){return _LicenseManager.LicenseManager}});Object.defineProperty(exports,"LicenseTransportError",{enumerable:true,get:function(){return _api.LicenseTransportError}});Object.defineProperty(exports,"SessionError",{enumerable:true,get:function(){return _sessionManager.SessionError}});Object.defineProperty(exports,"SessionManager",{enumerable:true,get:function(){return _sessionManager.SessionManager}});Object.defineProperty(exports,"getSyncCredential",{enumerable:true,get:function(){return _syncCredential.getSyncCredential}});exports.hasEntitlement=hasEntitlement;Object.defineProperty(exports,"isBuoyToken",{enumerable:true,get:function(){return _freeToken.isBuoyToken}});Object.defineProperty(exports,"isDevToken",{enumerable:true,get:function(){return _devToken.isDevToken}});exports.isPro=isPro;Object.defineProperty(exports,"isServiceKey",{enumerable:true,get:function(){return _serviceKey.isServiceKey}});Object.defineProperty(exports,"isTransientLicenseError",{enumerable:true,get:function(){return _api.isTransientLicenseError}});Object.defineProperty(exports,"isWeekendFreePro",{enumerable:true,get:function(){return _weekendPro.isWeekendFreePro}});Object.defineProperty(exports,"normalizeLicenseKey",{enumerable:true,get:function(){return _serviceKey.normalizeLicenseKey}});Object.defineProperty(exports,"resolveAccountAccess",{enumerable:true,get:function(){return _accountAccess.resolveAccountAccess}});Object.defineProperty(exports,"sameLicenseKey",{enumerable:true,get:function(){return _serviceKey.sameLicenseKey}});exports.setLicenseKey=setLicenseKey;Object.defineProperty(exports,"useAccountAccess",{enumerable:true,get:function(){return _hooks.useAccountAccess}});Object.defineProperty(exports,"useBuoySession",{enumerable:true,get:function(){return _hooks.useBuoySession}});Object.defineProperty(exports,"useFeatureAccess",{enumerable:true,get:function(){return _hooks.useFeatureAccess}});Object.defineProperty(exports,"useIsPro",{enumerable:true,get:function(){return _hooks.useIsPro}});Object.defineProperty(exports,"useLicense",{enumerable:true,get:function(){return _hooks.useLicense}});Object.defineProperty(exports,"useProAccess",{enumerable:true,get:function(){return _hooks.useProAccess}});Object.defineProperty(exports,"useTier",{enumerable:true,get:function(){return _hooks.useTier}});Object.defineProperty(exports,"useWeekendFreePro",{enumerable:true,get:function(){return _weekendPro.useWeekendFreePro}});var _LicenseManager=require("./LicenseManager.js");var _weekendPro=require("./weekendPro.js");var _hooks=require("./hooks.js");var _accountAccess=require("./accountAccess.js");var _api=require("./api.js");var _sessionManager=require("./sessionManager.js");var _serviceKey=require("./serviceKey.js");var _devToken=require("./devToken.js");var _syncCredential=require("./syncCredential.js");var _freeToken=require("./freeToken.js");function _interopRequireWildcard(
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"LicenseManager",{enumerable:true,get:function(){return _LicenseManager.LicenseManager}});Object.defineProperty(exports,"LicenseTransportError",{enumerable:true,get:function(){return _api.LicenseTransportError}});Object.defineProperty(exports,"SessionError",{enumerable:true,get:function(){return _sessionManager.SessionError}});Object.defineProperty(exports,"SessionManager",{enumerable:true,get:function(){return _sessionManager.SessionManager}});Object.defineProperty(exports,"callCapacitorAsApp",{enumerable:true,get:function(){return _capacitorBridge.callCapacitorAsApp}});Object.defineProperty(exports,"callCapacitorNative",{enumerable:true,get:function(){return _capacitorBridge.callCapacitorNative}});Object.defineProperty(exports,"callCapacitorNativeCallback",{enumerable:true,get:function(){return _capacitorBridge.callCapacitorNativeCallback}});Object.defineProperty(exports,"capacitorDebug",{enumerable:true,get:function(){return _capacitorHost.capacitorDebug}});Object.defineProperty(exports,"capacitorListenerCount",{enumerable:true,get:function(){return _capacitorBridge.capacitorListenerCount}});Object.defineProperty(exports,"capacitorPlatform",{enumerable:true,get:function(){return _capacitorHost.capacitorPlatform}});Object.defineProperty(exports,"capacitorPlugin",{enumerable:true,get:function(){return _capacitorBridge.capacitorPlugin}});Object.defineProperty(exports,"clearCapacitorCalls",{enumerable:true,get:function(){return _capacitorBridge.clearCapacitorCalls}});Object.defineProperty(exports,"colorSchemeQueryValue",{enumerable:true,get:function(){return _capacitorBridge.colorSchemeQueryValue}});Object.defineProperty(exports,"emitCapacitorEvent",{enumerable:true,get:function(){return _capacitorBridge.emitCapacitorEvent}});Object.defineProperty(exports,"getCapacitorAppHost",{enumerable:true,get:function(){return _capacitorBridge.getCapacitorAppHost}});Object.defineProperty(exports,"getCapacitorCalls",{enumerable:true,get:function(){return _capacitorBridge.getCapacitorCalls}});Object.defineProperty(exports,"getColorSchemeQueries",{enumerable:true,get:function(){return _capacitorBridge.getColorSchemeQueries}});Object.defineProperty(exports,"getSyncCredential",{enumerable:true,get:function(){return _syncCredential.getSyncCredential}});Object.defineProperty(exports,"hasCapacitorPlugin",{enumerable:true,get:function(){return _capacitorBridge.hasCapacitorPlugin}});exports.hasEntitlement=hasEntitlement;Object.defineProperty(exports,"installCapacitorBridge",{enumerable:true,get:function(){return _capacitorBridge.installCapacitorBridge}});Object.defineProperty(exports,"interceptCapacitor",{enumerable:true,get:function(){return _capacitorBridge.interceptCapacitor}});Object.defineProperty(exports,"isBuoyToken",{enumerable:true,get:function(){return _freeToken.isBuoyToken}});Object.defineProperty(exports,"isCapacitorBridgeInstalled",{enumerable:true,get:function(){return _capacitorBridge.isCapacitorBridgeInstalled}});Object.defineProperty(exports,"isCapacitorNative",{enumerable:true,get:function(){return _capacitorHost.isCapacitorNative}});Object.defineProperty(exports,"isDevToken",{enumerable:true,get:function(){return _devToken.isDevToken}});exports.isPro=isPro;Object.defineProperty(exports,"isServiceKey",{enumerable:true,get:function(){return _serviceKey.isServiceKey}});Object.defineProperty(exports,"isTransientLicenseError",{enumerable:true,get:function(){return _api.isTransientLicenseError}});Object.defineProperty(exports,"isWeekendFreePro",{enumerable:true,get:function(){return _weekendPro.isWeekendFreePro}});Object.defineProperty(exports,"listenCapacitorNative",{enumerable:true,get:function(){return _capacitorBridge.listenCapacitorNative}});Object.defineProperty(exports,"loadCapacitorAppHost",{enumerable:true,get:function(){return _capacitorBridge.loadCapacitorAppHost}});Object.defineProperty(exports,"makeCapacitorCallbackId",{enumerable:true,get:function(){return _capacitorBridge.makeCapacitorCallbackId}});Object.defineProperty(exports,"normalizeLicenseKey",{enumerable:true,get:function(){return _serviceKey.normalizeLicenseKey}});Object.defineProperty(exports,"resolveAccountAccess",{enumerable:true,get:function(){return _accountAccess.resolveAccountAccess}});Object.defineProperty(exports,"resolveDevBuild",{enumerable:true,get:function(){return _capacitorHost.resolveDevBuild}});Object.defineProperty(exports,"sameLicenseKey",{enumerable:true,get:function(){return _serviceKey.sameLicenseKey}});exports.setLicenseKey=setLicenseKey;Object.defineProperty(exports,"subscribeCapacitorCalls",{enumerable:true,get:function(){return _capacitorBridge.subscribeCapacitorCalls}});Object.defineProperty(exports,"useAccountAccess",{enumerable:true,get:function(){return _hooks.useAccountAccess}});Object.defineProperty(exports,"useBuoySession",{enumerable:true,get:function(){return _hooks.useBuoySession}});Object.defineProperty(exports,"useFeatureAccess",{enumerable:true,get:function(){return _hooks.useFeatureAccess}});Object.defineProperty(exports,"useIsPro",{enumerable:true,get:function(){return _hooks.useIsPro}});Object.defineProperty(exports,"useLicense",{enumerable:true,get:function(){return _hooks.useLicense}});Object.defineProperty(exports,"useProAccess",{enumerable:true,get:function(){return _hooks.useProAccess}});Object.defineProperty(exports,"useTier",{enumerable:true,get:function(){return _hooks.useTier}});Object.defineProperty(exports,"useWeekendFreePro",{enumerable:true,get:function(){return _weekendPro.useWeekendFreePro}});var _LicenseManager=require("./LicenseManager.js");var _weekendPro=require("./weekendPro.js");var _hooks=require("./hooks.js");var _accountAccess=require("./accountAccess.js");var _api=require("./api.js");var _sessionManager=require("./sessionManager.js");var _serviceKey=require("./serviceKey.js");var _capacitorHost=require("./capacitorHost.js");var _capacitorBridge=require("./capacitorBridge.js");var _devToken=require("./devToken.js");var _syncCredential=require("./syncCredential.js");var _freeToken=require("./freeToken.js");function _interopRequireWildcard(n,i){if("function"==typeof WeakMap)var c=new WeakMap,s=new WeakMap;return(_interopRequireWildcard=function(e,a){if(!a&&e&&e.__esModule)return e;var r,u,o={__proto__:null,default:e};if(null===e||"object"!=typeof e&&"function"!=typeof e)return o;if(r=a?s:c){if(r.has(e))return r.get(e);r.set(e,o)}for(const t in e)"default"!==t&&{}.hasOwnProperty.call(e,t)&&((u=(r=Object.defineProperty)&&Object.getOwnPropertyDescriptor(e,t))&&(u.get||u.set)?r(o,t,u):o[t]=e[t]);return o})(n,i)}/*!
|
|
2
2
|
* PROPRIETARY — Buoy Pro license enforcement. NOT open source.
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Buoy. All rights reserved. Licensed under the Buoy EULA
|
|
@@ -15,4 +15,4 @@
|
|
|
15
15
|
* Pro is $9/mo, and is free every weekend for anyone holding a key —
|
|
16
16
|
* including a free one (`npx buoy login`). Buy a key at
|
|
17
17
|
* https://buoy.gg or use it free on Saturday and Sunday.
|
|
18
|
-
*/async function setLicenseKey(
|
|
18
|
+
*/async function setLicenseKey(n){const{LicenseManager:i}=await Promise.resolve().then(()=>_interopRequireWildcard(require("./LicenseManager")));await i.initialize();return i.setLicenseKey(n)}function weekendPassActive(){return(0,_weekendPro.weekendPassAppliesTo)(_LicenseManager.LicenseManager.hasAccountAccess(),(0,_weekendPro.isWeekendFreePro)())}function isPro(){if(_LicenseManager.LicenseManager.isPro())return true;return weekendPassActive()}function hasEntitlement(n){if(_LicenseManager.LicenseManager.hasEntitlement(n))return true;return weekendPassActive()}
|
package/lib/commonjs/storage.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.getLicenseStorage=getLicenseStorage;const LICENSE_STORAGE_DIR="buoy-license";let _FileSystem=null;let _licenseStorage=null;const _memoryStore=new Map;function loadFileSystem(){if(_FileSystem)return _FileSystem;try{const e=require("expo-file-system/legacy");_FileSystem=e?.default||e;if(_FileSystem?.documentDirectory){return _FileSystem}_FileSystem=null}catch{}try{const e=require("expo-file-system");_FileSystem=e?.default||e;if(_FileSystem?.documentDirectory){return _FileSystem}_FileSystem=null}catch{}return null}function getLicenseStorageDir(){const e=loadFileSystem();if(!e?.documentDirectory)return null;return`${e.documentDirectory}${LICENSE_STORAGE_DIR}/`}function getLicenseFilePath(e){const
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.getLicenseStorage=getLicenseStorage;const LICENSE_STORAGE_DIR="buoy-license";let _FileSystem=null;let _licenseStorage=null;const _memoryStore=new Map;function loadFileSystem(){if(_FileSystem)return _FileSystem;try{const e=require("expo-file-system/legacy");_FileSystem=e?.default||e;if(_FileSystem?.documentDirectory){return _FileSystem}_FileSystem=null}catch{}try{const e=require("expo-file-system");_FileSystem=e?.default||e;if(_FileSystem?.documentDirectory){return _FileSystem}_FileSystem=null}catch{}return null}function getLicenseStorageDir(){const e=loadFileSystem();if(!e?.documentDirectory)return null;return`${e.documentDirectory}${LICENSE_STORAGE_DIR}/`}function getLicenseFilePath(e){const n=getLicenseStorageDir();if(!n)return null;return`${n}${encodeURIComponent(e)}.json`}function loadAsyncStorage(){if(!hasAsyncStorageNative())return null;try{const e=require("@react-native-async-storage/async-storage");const n=e?.default||e;if(typeof n?.getItem==="function"&&typeof n.setItem==="function"&&typeof n.removeItem==="function"){return n}}catch{}return null}function hasAsyncStorageNative(){let e;try{e=require("react-native")}catch{return true}if(!e?.Platform||e.Platform.OS==="web")return true;try{return["RNCAsyncStorage","RNC_AsyncSQLiteDBStorage","PlatformLocalStorage","AsyncSQLiteDBStorage","AsyncLocalStorage"].some(n=>!!e.TurboModuleRegistry?.get?.(n)||!!e.NativeModules?.[n])}catch{return false}}function hasLocalStorage(){try{return typeof localStorage!=="undefined"&&!!localStorage}catch{return false}}async function getLicenseStorage(){if(_licenseStorage)return _licenseStorage;const e=loadFileSystem();let n=null;if(e?.documentDirectory){_licenseStorage={async getItem(t){const r=getLicenseFilePath(t);if(!r)return null;try{const c=await e.getInfoAsync(r);if(!c.exists)return null;return await e.readAsStringAsync(r)}catch{return null}},async setItem(t,r){const c=getLicenseStorageDir();const o=getLicenseFilePath(t);if(!c||!o)return;try{const a=await e.getInfoAsync(c);if(!a.exists){await e.makeDirectoryAsync(c,{intermediates:true})}await e.writeAsStringAsync(o,r)}catch(a){console.warn("[Buoy] License storage write failed:",a)}},async removeItem(t){const r=getLicenseFilePath(t);if(!r)return;try{await e.deleteAsync(r,{idempotent:true})}catch{}}}}else if(n=loadAsyncStorage()){const t=n;_licenseStorage={async getItem(r){try{return await t.getItem(r)}catch{return null}},async setItem(r,c){try{await t.setItem(r,c)}catch(o){console.warn("[Buoy] License storage write failed:",o)}},async removeItem(r){try{await t.removeItem(r)}catch{}}}}else if(hasLocalStorage()){_licenseStorage={async getItem(t){try{return localStorage.getItem(t)}catch{return null}},async setItem(t,r){try{localStorage.setItem(t,r)}catch{}},async removeItem(t){try{localStorage.removeItem(t)}catch{}}}}else{_licenseStorage={async getItem(t){return _memoryStore.get(t)??null},async setItem(t,r){_memoryStore.set(t,r)},async removeItem(t){_memoryStore.delete(t)}}}return _licenseStorage}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";import{isCapacitorNative as A}from"./capacitorHost.js";const $="__BUOY_CAPACITOR_BRIDGE__";const j=300;function k(){const e=globalThis.Capacitor;return e&&typeof e==="object"?e:null}function d(){const e=globalThis;let t=e[$];if(!t||t.version!==1){t={version:1,originalPromise:null,originalCallback:null,wrappedPromise:null,wrappedCallback:null,interceptors:[],listeners:new Map,log:[],subscribers:new Set,seq:0,fakeIds:0};e[$]=t}return t}function y(){const e=globalThis.__buoyRealNow;return typeof e==="function"?e():Date.now()}function S(e){return e&&typeof e==="object"?e:{}}function P(e){for(const t of Array.from(e.subscribers)){try{t()}catch{}}}function N(e,t){const n={seq:++e.seq,...t};e.log.push(n);if(e.log.length>j)e.log.splice(0,e.log.length-j);P(e);return n}function R(e,t,n){return e.interceptors.filter(r=>(r.plugin==="*"||r.plugin===t.plugin)&&(!r.methods||r.methods.includes(t.method))&&typeof r[n]==="function").map((r,o)=>({interceptor:r,index:o})).sort((r,o)=>(o.interceptor.order??0)-(r.interceptor.order??0)||r.index-o.index).map(r=>r.interceptor)}function x(e,t){return`${e}:${String(t)}`}export function makeCapacitorCallbackId(){return`buoy-${++d().fakeIds}`}export function installCapacitorBridge(e={}){if(!A())return false;const t=k();if(!t||typeof t.nativePromise!=="function"||typeof t.nativeCallback!=="function")return false;const n=d();if(n.wrappedPromise&&t.nativePromise===n.wrappedPromise&&t.nativeCallback===n.wrappedCallback)return true;if(t.DEBUG!==true&&e.release!==true)return false;n.originalPromise=t.nativePromise;n.originalCallback=t.nativeCallback;const r=n.originalPromise;const o=n.originalCallback;const i=(s,l,h,C)=>{const f={plugin:s,method:l,options:S(h)};const g=R(n,f,"promise");const c=m=>{if(m>=g.length){C();if(l==="removeAllListeners"){for(const v of Array.from(n.listeners.keys()))if(v.startsWith(`${s}:`))n.listeners.delete(v)}return r.call(t,s,l,h)}try{return Promise.resolve(g[m].promise(f,()=>c(m+1)))}catch(v){return Promise.reject(v)}};return c(0)};n.runPromise=i;const a=(s,l,h)=>{const C=N(n,{plugin:s,method:l,kind:"promise",options:S(h),start:y()});let f=false;const g=i(s,l,h,()=>{f=true});g.then(c=>{Object.assign(C,{end:y(),ok:true,result:c,answeredByBuoy:!f});P(n)},c=>{Object.assign(C,{end:y(),ok:false,error:c,answeredByBuoy:!f});P(n)});return g};const p=(s,l,h,C)=>{let f=h;let g=C;if(typeof f==="function"){g=f;f=null}const c={plugin:s,method:l,options:S(f)};const m=N(n,{plugin:s,method:l,kind:"callback",options:c.options,start:y(),events:0});let v=false;const L=R(n,c,"callback");const O=(b,u)=>{if(b>=L.length){v=true;return o.call(t,s,l,f,u)}return L[b].callback(c,u,w=>O(b+1,w))};const E=l==="addListener";const H=(b,u)=>{m.events=(m.events??0)+1;if(!E&&m.end===void 0){m.end=y();m.ok=!u;if(u)m.error=u;else m.result=b;P(n)}else{const w=y();N(n,{plugin:s,method:E?String(c.options.eventName??"event"):l,kind:"event",options:{},start:w,end:w,ok:!u,...u?{error:u}:{result:b}})}g?.(b,u)};const B=O(0,H);m.answeredByBuoy=!v;if(l==="addListener"&&B!=null&&typeof g==="function"){const b=x(s,c.options.eventName);let u=n.listeners.get(b);if(!u)n.listeners.set(b,u=new Map);u.set(String(B),g)}else if(l==="removeListener"){n.listeners.get(x(s,c.options.eventName))?.delete(String(c.options.callbackId))}return B};t.nativePromise=a;t.nativeCallback=p;n.wrappedPromise=a;n.wrappedCallback=p;D();return true}const U=/^\s*\(\s*prefers-color-scheme\s*:\s*(dark|light)\s*\)\s*$/i;const T="__BUOY_COLOR_SCHEME_QUERIES__";export function colorSchemeQueryValue(e){const t=U.exec(e);return t?t[1].toLowerCase():null}function D(){const e=globalThis;const t=globalThis.WeakRef;if(e[T]||typeof e.matchMedia!=="function"||!t)return;const n=[];e[T]=n;const r=e.matchMedia;e.matchMedia=function o(i){const a=r.call(this??globalThis,i);if(a&&colorSchemeQueryValue(String(i))){for(let p=n.length-1;p>=0;p--)if(!n[p].deref())n.splice(p,1);n.push(new t(a))}return a}}export function getColorSchemeQueries(){const e=globalThis[T];if(!e)return[];return e.map(t=>t.deref()).filter(t=>!!t)}export function isCapacitorBridgeInstalled(){const e=k();const t=d();return Boolean(t.wrappedPromise&&e?.nativePromise===t.wrappedPromise)}export function interceptCapacitor(e){const t=d();t.interceptors.push(e);return()=>{const n=t.interceptors.indexOf(e);if(n>=0)t.interceptors.splice(n,1)}}export function emitCapacitorEvent(e,t,n){const r=d().listeners.get(x(e,t));if(!r)return 0;let o=0;for(const i of Array.from(r.values())){try{i(n);o++}catch(a){globalThis.console?.error(a)}}return o}export function capacitorListenerCount(e,t){return d().listeners.get(x(e,t))?.size??0}function M(e){return k()?.PluginHeaders?.find(t=>t.name===e)}export function hasCapacitorPlugin(e){if(!A())return false;try{return Boolean(M(e))||k()?.isPluginAvailable?.(e)===true}catch{return false}}function I(){const e=k();const t=d();return{cap:e,promise:t.originalPromise??e?.nativePromise??null,callback:t.originalCallback??e?.nativeCallback??null}}export function callCapacitorNative(e,t,n={}){const{cap:r,promise:o}=I();if(!r||!o)return Promise.reject(new Error("Capacitor bridge unavailable"));return o.call(r,e,t,n)}export function callCapacitorAsApp(e,t,n={}){const r=d().runPromise;if(r&&isCapacitorBridgeInstalled())return r(e,t,n,()=>{});return callCapacitorNative(e,t,n)}export function callCapacitorNativeCallback(e,t,n,r){const{cap:o,callback:i}=I();if(!o||!i)return null;return i.call(o,e,t,n,r)}export function listenCapacitorNative(e,t,n){const{cap:r,promise:o,callback:i}=I();if(!r||!i)return Promise.reject(new Error("Capacitor bridge unavailable"));const a=i.call(r,e,"addListener",{eventName:t},s=>n(s));const p=async()=>{if(a==null)return;const s={eventName:t,callbackId:a};const l=M(e)?.methods?.find(h=>h.name==="removeListener")?.rtype;if(l==="promise"&&o)await o.call(r,e,"removeListener",s);else i.call(r,e,"removeListener",s,()=>{})};return Promise.resolve({remove:p})}export function getCapacitorCalls(){return d().log}export function clearCapacitorCalls(){const e=d();e.log.length=0;P(e)}export function subscribeCapacitorCalls(e){const t=d();t.subscribers.add(e);return()=>{t.subscribers.delete(e)}}const Y=new Set(["then","catch","finally","$$typeof","toJSON","constructor"]);export function capacitorPlugin(e){if(!hasCapacitorPlugin(e))return null;return new Proxy({},{get(t,n){if(typeof n!=="string"||Y.has(n))return void 0;if(n==="addListener"){return(r,o)=>listenCapacitorNative(e,r,o)}return r=>callCapacitorNative(e,n,r??{})}})}const _="__BUOY_CAPACITOR_HOST__";export function loadCapacitorAppHost(){if(!A())return Promise.resolve(null);const e=globalThis;const t=e[_];if(t)return t;const n=i=>typeof i==="string"&&i?i:null;const r=async i=>{if(!hasCapacitorPlugin(i))return{};try{return await callCapacitorNative(i,"getInfo")??{}}catch{return{}}};const o=Promise.all([r("App"),r("Device")]).then(([i,a])=>{const p={isSimulator:typeof a.isVirtual==="boolean"?a.isVirtual:null,deviceName:n(a.name),bundleId:n(i.id),appName:n(i.name)};e[`${_}_value`]=p;return p});e[_]=o;return o}export function getCapacitorAppHost(){return globalThis[`${_}_value`]??null}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";function r(){const t=globalThis.Capacitor;return t&&typeof t==="object"?t:null}export function isCapacitorNative(){try{return r()?.isNativePlatform?.()===true}catch{return false}}export function capacitorPlatform(){if(!isCapacitorNative())return null;try{const t=r()?.getPlatform?.();return t==="ios"||t==="android"?t:null}catch{return null}}export function capacitorDebug(){if(!isCapacitorNative())return null;return r()?.DEBUG===true}export function resolveDevBuild(t){return capacitorDebug()??t}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";export function generateUUID(){if(typeof crypto!=="undefined"&&crypto.randomUUID){return crypto.randomUUID()}return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,n=>{const e=Math.random()*16|0;const r=n==="x"?e:e&3|8;return r.toString(16)})}export function isDevBundle(){if(typeof __DEV__!=="undefined")return __DEV__;try{if(typeof navigator!=="undefined"&&/electron/i.test(navigator.userAgent))return true}catch{}return typeof process!=="undefined"&&process.env?.NODE_ENV!=="production"}export function isSimulator(){return false}function u(){if(typeof navigator==="undefined"){return"unknown"}const n=navigator.userAgent.toLowerCase();const e=navigator.platform?.toLowerCase()||"";if(n.includes("electron")){if(e.includes("mac")||n.includes("mac")){return"electron-macos"}if(e.includes("win")||n.includes("win")){return"electron-windows"}if(e.includes("linux")||n.includes("linux")){return"electron-linux"}return"electron"}if(e.includes("mac")||n.includes("mac")){return"macos"}if(e.includes("win")||n.includes("win")){return"windows"}if(e.includes("linux")||n.includes("linux")){return"linux"}if(/iphone|ipad|ipod/.test(n)){return"ios-web"}if(n.includes("android")){return"android-web"}return"web"}function
|
|
1
|
+
"use strict";import{capacitorDebug as a}from"./capacitorHost.js";export function generateUUID(){if(typeof crypto!=="undefined"&&crypto.randomUUID){return crypto.randomUUID()}return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,n=>{const e=Math.random()*16|0;const r=n==="x"?e:e&3|8;return r.toString(16)})}export function isDevBundle(){const n=a();if(n!==null)return n;if(typeof __DEV__!=="undefined")return __DEV__;try{if(typeof navigator!=="undefined"&&/electron/i.test(navigator.userAgent))return true}catch{}return typeof process!=="undefined"&&process.env?.NODE_ENV!=="production"}export function isSimulator(){return false}function u(){if(typeof navigator==="undefined"){return"unknown"}const n=navigator.userAgent.toLowerCase();const e=navigator.platform?.toLowerCase()||"";if(n.includes("electron")){if(e.includes("mac")||n.includes("mac")){return"electron-macos"}if(e.includes("win")||n.includes("win")){return"electron-windows"}if(e.includes("linux")||n.includes("linux")){return"electron-linux"}return"electron"}if(e.includes("mac")||n.includes("mac")){return"macos"}if(e.includes("win")||n.includes("win")){return"windows"}if(e.includes("linux")||n.includes("linux")){return"linux"}if(/iphone|ipad|ipod/.test(n)){return"ios-web"}if(n.includes("android")){return"android-web"}return"web"}function s(){if(typeof navigator==="undefined"){return"unknown"}const n=navigator.userAgent;const e=n.match(/Mac OS X ([\d_.]+)/);if(e){return e[1].replace(/_/g,".")}const r=n.match(/Windows NT ([\d.]+)/);if(r){const t={"10.0":"10/11","6.3":"8.1","6.2":"8","6.1":"7"};return t[r[1]]||r[1]}if(n.includes("Linux")){return"Linux"}return"unknown"}function c(){if(typeof navigator==="undefined"){return{name:"unknown",version:"unknown"}}const n=navigator.userAgent;const e=n.match(/Electron\/([\d.]+)/);if(e){return{name:"Electron",version:e[1]}}const r=n.match(/Chrome\/([\d.]+)/);if(r&&!n.includes("Edg")){return{name:"Chrome",version:r[1]}}const t=n.match(/Edg\/([\d.]+)/);if(t){return{name:"Edge",version:t[1]}}const o=n.match(/Firefox\/([\d.]+)/);if(o){return{name:"Firefox",version:o[1]}}const i=n.match(/Version\/([\d.]+).*Safari/);if(i){return{name:"Safari",version:i[1]}}return{name:"unknown",version:"unknown"}}export function getDeviceMetadata(){const n={platform:u(),osVersion:s(),isSimulator:"false"};const e=c();n.browser=e.name;n.browserVersion=e.version;if(typeof window!=="undefined"&&window.screen){n.screenResolution=`${window.screen.width}x${window.screen.height}`}if(typeof navigator!=="undefined"&&navigator.language){n.language=navigator.language}try{n.timezone=Intl.DateTimeFormat().resolvedOptions().timeZone}catch{}return n}export function getDefaultDeviceName(){const n=u();const e=c();if(n.startsWith("electron")){const r=n.replace("electron-","").replace("electron","Desktop");return`${r.charAt(0).toUpperCase()+r.slice(1)} App`}if(e.name!=="unknown"){return`${e.name} Browser`}return"Web Browser"}
|
package/lib/module/index.js
CHANGED
|
@@ -15,4 +15,4 @@
|
|
|
15
15
|
* Pro is $9/mo, and is free every weekend for anyone holding a key —
|
|
16
16
|
* including a free one (`npx buoy login`). Buy a key at
|
|
17
17
|
* https://buoy.gg or use it free on Saturday and Sunday.
|
|
18
|
-
*/export{LicenseManager}from"./LicenseManager.js";export{DeviceRegistrationModal}from"./DeviceRegistrationModal.js";export{useLicense,useFeatureAccess,useIsPro,useProAccess,useTier}from"./hooks.js";export{useAccountAccess}from"./hooks.js";export{resolveAccountAccess}from"./accountAccess.js";export{LicenseTransportError,isTransientLicenseError}from"./api.js";export{SessionManager,SessionError}from"./sessionManager.js";export{useBuoySession}from"./hooks.js";export{isServiceKey,normalizeLicenseKey,sameLicenseKey}from"./serviceKey.js";export{isDevToken}from"./devToken.js";export{getSyncCredential}from"./syncCredential.js";export{isBuoyToken}from"./freeToken.js";export{isWeekendFreePro,useWeekendFreePro}from"./weekendPro.js";export async function setLicenseKey(e){const{LicenseManager:r}=await import("./LicenseManager");await r.initialize();return r.setLicenseKey(e)}function
|
|
18
|
+
*/export{LicenseManager}from"./LicenseManager.js";export{DeviceRegistrationModal}from"./DeviceRegistrationModal.js";export{useLicense,useFeatureAccess,useIsPro,useProAccess,useTier}from"./hooks.js";export{useAccountAccess}from"./hooks.js";export{resolveAccountAccess}from"./accountAccess.js";export{LicenseTransportError,isTransientLicenseError}from"./api.js";export{SessionManager,SessionError}from"./sessionManager.js";export{useBuoySession}from"./hooks.js";export{isServiceKey,normalizeLicenseKey,sameLicenseKey}from"./serviceKey.js";export{isCapacitorNative,capacitorPlatform,capacitorDebug,resolveDevBuild}from"./capacitorHost.js";export{installCapacitorBridge,isCapacitorBridgeInstalled,interceptCapacitor,emitCapacitorEvent,capacitorListenerCount,hasCapacitorPlugin,capacitorPlugin,callCapacitorNative,callCapacitorAsApp,callCapacitorNativeCallback,listenCapacitorNative,makeCapacitorCallbackId,getCapacitorCalls,clearCapacitorCalls,subscribeCapacitorCalls,loadCapacitorAppHost,getCapacitorAppHost,colorSchemeQueryValue,getColorSchemeQueries}from"./capacitorBridge.js";export{isDevToken}from"./devToken.js";export{getSyncCredential}from"./syncCredential.js";export{isBuoyToken}from"./freeToken.js";export{isWeekendFreePro,useWeekendFreePro}from"./weekendPro.js";export async function setLicenseKey(e){const{LicenseManager:r}=await import("./LicenseManager");await r.initialize();return r.setLicenseKey(e)}function o(){const{isWeekendFreePro:e,weekendPassAppliesTo:r}=require("./weekendPro");const{LicenseManager:a}=require("./LicenseManager");return r(a.hasAccountAccess(),e())}export function isPro(){const{LicenseManager:e}=require("./LicenseManager");if(e.isPro())return true;return o()}export function hasEntitlement(e){const{LicenseManager:r}=require("./LicenseManager");if(r.hasEntitlement(e))return true;return o()}
|
package/lib/module/index.web.js
CHANGED
|
@@ -15,4 +15,4 @@
|
|
|
15
15
|
* Pro is $9/mo, and is free every weekend for anyone holding a key —
|
|
16
16
|
* including a free one (`npx buoy login`). Buy a key at
|
|
17
17
|
* https://buoy.gg or use it free on Saturday and Sunday.
|
|
18
|
-
*/import{LicenseManager as r}from"./LicenseManager.js";import{isWeekendFreePro as
|
|
18
|
+
*/import{LicenseManager as r}from"./LicenseManager.js";import{isWeekendFreePro as a,weekendPassAppliesTo as i}from"./weekendPro.js";export{LicenseManager}from"./LicenseManager.js";export{useLicense,useFeatureAccess,useIsPro,useProAccess,useTier}from"./hooks.js";export{useAccountAccess}from"./hooks.js";export{resolveAccountAccess}from"./accountAccess.js";export{LicenseTransportError,isTransientLicenseError}from"./api.js";export{SessionManager,SessionError}from"./sessionManager.js";export{useBuoySession}from"./hooks.js";export{isServiceKey,normalizeLicenseKey,sameLicenseKey}from"./serviceKey.js";export{isCapacitorNative,capacitorPlatform,capacitorDebug,resolveDevBuild}from"./capacitorHost.js";export{installCapacitorBridge,isCapacitorBridgeInstalled,interceptCapacitor,emitCapacitorEvent,capacitorListenerCount,hasCapacitorPlugin,capacitorPlugin,callCapacitorNative,callCapacitorAsApp,callCapacitorNativeCallback,listenCapacitorNative,makeCapacitorCallbackId,getCapacitorCalls,clearCapacitorCalls,subscribeCapacitorCalls,loadCapacitorAppHost,getCapacitorAppHost,colorSchemeQueryValue,getColorSchemeQueries}from"./capacitorBridge.js";export{isDevToken}from"./devToken.js";export{getSyncCredential}from"./syncCredential.js";export{isBuoyToken}from"./freeToken.js";export{isWeekendFreePro,useWeekendFreePro}from"./weekendPro.js";export async function setLicenseKey(e){const{LicenseManager:o}=await import("./LicenseManager");await o.initialize();return o.setLicenseKey(e)}function t(){return i(r.hasAccountAccess(),a())}export function isPro(){if(r.isPro())return true;return t()}export function hasEntitlement(e){if(r.hasEntitlement(e))return true;return t()}
|
package/lib/module/storage.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const m="buoy-license";let c=null;let a=null;const i=new Map;function y(){if(c)return c;try{const t=require("expo-file-system/legacy");c=t?.default||t;if(c?.documentDirectory){return c}c=null}catch{}try{const t=require("expo-file-system");c=t?.default||t;if(c?.documentDirectory){return c}c=null}catch{}return null}function f(){const t=y();if(!t?.documentDirectory)return null;return`${t.documentDirectory}${m}/`}function l(t){const
|
|
1
|
+
"use strict";const m="buoy-license";let c=null;let a=null;const i=new Map;function y(){if(c)return c;try{const t=require("expo-file-system/legacy");c=t?.default||t;if(c?.documentDirectory){return c}c=null}catch{}try{const t=require("expo-file-system");c=t?.default||t;if(c?.documentDirectory){return c}c=null}catch{}return null}function f(){const t=y();if(!t?.documentDirectory)return null;return`${t.documentDirectory}${m}/`}function l(t){const n=f();if(!n)return null;return`${n}${encodeURIComponent(t)}.json`}function g(){if(!I())return null;try{const t=require("@react-native-async-storage/async-storage");const n=t?.default||t;if(typeof n?.getItem==="function"&&typeof n.setItem==="function"&&typeof n.removeItem==="function"){return n}}catch{}return null}function I(){let t;try{t=require("react-native")}catch{return true}if(!t?.Platform||t.Platform.OS==="web")return true;try{return["RNCAsyncStorage","RNC_AsyncSQLiteDBStorage","PlatformLocalStorage","AsyncSQLiteDBStorage","AsyncLocalStorage"].some(n=>!!t.TurboModuleRegistry?.get?.(n)||!!t.NativeModules?.[n])}catch{return false}}function d(){try{return typeof localStorage!=="undefined"&&!!localStorage}catch{return false}}export async function getLicenseStorage(){if(a)return a;const t=y();let n=null;if(t?.documentDirectory){a={async getItem(e){const r=l(e);if(!r)return null;try{const o=await t.getInfoAsync(r);if(!o.exists)return null;return await t.readAsStringAsync(r)}catch{return null}},async setItem(e,r){const o=f();const s=l(e);if(!o||!s)return;try{const u=await t.getInfoAsync(o);if(!u.exists){await t.makeDirectoryAsync(o,{intermediates:true})}await t.writeAsStringAsync(s,r)}catch(u){console.warn("[Buoy] License storage write failed:",u)}},async removeItem(e){const r=l(e);if(!r)return;try{await t.deleteAsync(r,{idempotent:true})}catch{}}}}else if(n=g()){const e=n;a={async getItem(r){try{return await e.getItem(r)}catch{return null}},async setItem(r,o){try{await e.setItem(r,o)}catch(s){console.warn("[Buoy] License storage write failed:",s)}},async removeItem(r){try{await e.removeItem(r)}catch{}}}}else if(d()){a={async getItem(e){try{return localStorage.getItem(e)}catch{return null}},async setItem(e,r){try{localStorage.setItem(e,r)}catch{}},async removeItem(e){try{localStorage.removeItem(e)}catch{}}}}else{a={async getItem(e){return i.get(e)??null},async setItem(e,r){i.set(e,r)},async removeItem(e){i.delete(e)}}}return a}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
export type CapacitorCallback = (data: unknown, error?: unknown) => void;
|
|
2
|
+
export interface CapacitorCall {
|
|
3
|
+
plugin: string;
|
|
4
|
+
method: string;
|
|
5
|
+
options: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
export interface CapacitorInterceptor {
|
|
8
|
+
/** Plugin id (`"Geolocation"`), or `"*"` for every plugin. */
|
|
9
|
+
plugin: string;
|
|
10
|
+
/** Only these methods; every method when left out. */
|
|
11
|
+
methods?: string[];
|
|
12
|
+
/**
|
|
13
|
+
* Higher runs first (outermost); ties run in the order added. Permission
|
|
14
|
+
* checks use a high order so they wrap tools that answer calls.
|
|
15
|
+
*/
|
|
16
|
+
order?: number;
|
|
17
|
+
/** A one-answer call. Return `next()` to pass it on, or your own value (or promise) to answer it. */
|
|
18
|
+
promise?: (call: CapacitorCall, next: () => Promise<unknown>) => unknown;
|
|
19
|
+
/**
|
|
20
|
+
* A many-answer call. Return `next(callback)` to pass it on (wrap the
|
|
21
|
+
* callback to see or change answers), or answer it yourself and return
|
|
22
|
+
* your own id from `makeCapacitorCallbackId()`.
|
|
23
|
+
*/
|
|
24
|
+
callback?: (call: CapacitorCall, callback: CapacitorCallback, next: (callback: CapacitorCallback) => string | null) => string | null;
|
|
25
|
+
}
|
|
26
|
+
export interface CapacitorCallRecord {
|
|
27
|
+
seq: number;
|
|
28
|
+
plugin: string;
|
|
29
|
+
method: string;
|
|
30
|
+
/**
|
|
31
|
+
* "promise" and "callback" are the app's calls. "event" is one answer a
|
|
32
|
+
* plugin sent later: an event to an `addListener` callback (method is the
|
|
33
|
+
* event name), or a watch's later updates.
|
|
34
|
+
*/
|
|
35
|
+
kind: "promise" | "callback" | "event";
|
|
36
|
+
options: Record<string, unknown>;
|
|
37
|
+
/** Real `Date.now()` when the app made the call. */
|
|
38
|
+
start: number;
|
|
39
|
+
/** When the (first) answer arrived. */
|
|
40
|
+
end?: number;
|
|
41
|
+
ok?: boolean;
|
|
42
|
+
result?: unknown;
|
|
43
|
+
error?: unknown;
|
|
44
|
+
/** Callback calls: how many answers/events arrived so far. */
|
|
45
|
+
events?: number;
|
|
46
|
+
/** A Buoy interceptor answered instead of native code. */
|
|
47
|
+
answeredByBuoy?: boolean;
|
|
48
|
+
}
|
|
49
|
+
/** A callback id for a call a Buoy interceptor answers itself. */
|
|
50
|
+
export declare function makeCapacitorCallbackId(): string;
|
|
51
|
+
/**
|
|
52
|
+
* Wrap the bridge once. True when the hook is (now) in place. Safe to call
|
|
53
|
+
* from several places; later calls return the same answer.
|
|
54
|
+
*/
|
|
55
|
+
export declare function installCapacitorBridge(options?: {
|
|
56
|
+
release?: boolean;
|
|
57
|
+
}): boolean;
|
|
58
|
+
/** "dark" or "light" for a plain `(prefers-color-scheme: …)` query, else null. */
|
|
59
|
+
export declare function colorSchemeQueryValue(media: string): "dark" | "light" | null;
|
|
60
|
+
/** The live plain color scheme queries the page has made since the hook installed. */
|
|
61
|
+
export declare function getColorSchemeQueries(): object[];
|
|
62
|
+
export declare function isCapacitorBridgeInstalled(): boolean;
|
|
63
|
+
/** Add an interceptor. Earlier ones run first (outermost). Returns a remover. */
|
|
64
|
+
export declare function interceptCapacitor(interceptor: CapacitorInterceptor): () => void;
|
|
65
|
+
/**
|
|
66
|
+
* Send an event to the app's own listeners for `plugin`/`eventName`, the way
|
|
67
|
+
* native code would. Returns how many listeners got it. Buoy's own listeners
|
|
68
|
+
* (from `listenCapacitorNative`) don't get it.
|
|
69
|
+
*/
|
|
70
|
+
export declare function emitCapacitorEvent(plugin: string, eventName: string, data: unknown): number;
|
|
71
|
+
/** How many app listeners the hook has seen for `plugin`/`eventName`. */
|
|
72
|
+
export declare function capacitorListenerCount(plugin: string, eventName: string): number;
|
|
73
|
+
/** True when the app ships the native side of `plugin`. */
|
|
74
|
+
export declare function hasCapacitorPlugin(plugin: string): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Buoy's own plugin call: skips every interceptor and the call log, so it
|
|
77
|
+
* reads the real answer (the real location, the real stored value).
|
|
78
|
+
*/
|
|
79
|
+
export declare function callCapacitorNative<T = unknown>(plugin: string, method: string, options?: Record<string, unknown>): Promise<T>;
|
|
80
|
+
/**
|
|
81
|
+
* A Buoy call that should see what the app would see: it runs through the
|
|
82
|
+
* interceptors (another tool's override applies) but stays out of the call
|
|
83
|
+
* log. Without the hook it goes straight to native.
|
|
84
|
+
*/
|
|
85
|
+
export declare function callCapacitorAsApp<T = unknown>(plugin: string, method: string, options?: Record<string, unknown>): Promise<T>;
|
|
86
|
+
/**
|
|
87
|
+
* Buoy's own many-answer call (a native watch Buoy starts for the app):
|
|
88
|
+
* skips interceptors and the log. Returns native's callback id.
|
|
89
|
+
*/
|
|
90
|
+
export declare function callCapacitorNativeCallback(plugin: string, method: string, options: Record<string, unknown>, callback: CapacitorCallback): string | null;
|
|
91
|
+
/**
|
|
92
|
+
* Buoy's own event listener: skips interceptors, the log and
|
|
93
|
+
* `emitCapacitorEvent`. Resolves with a remover.
|
|
94
|
+
*/
|
|
95
|
+
export declare function listenCapacitorNative(plugin: string, eventName: string, listener: (data: unknown) => void): Promise<{
|
|
96
|
+
remove: () => Promise<void>;
|
|
97
|
+
}>;
|
|
98
|
+
/** The recent plugin calls, oldest first. */
|
|
99
|
+
export declare function getCapacitorCalls(): readonly CapacitorCallRecord[];
|
|
100
|
+
export declare function clearCapacitorCalls(): void;
|
|
101
|
+
/** Called after every new call and every answer. Returns an unsubscribe. */
|
|
102
|
+
export declare function subscribeCapacitorCalls(onChange: () => void): () => void;
|
|
103
|
+
/**
|
|
104
|
+
* A plugin object for Buoy's own calls, or null when the app doesn't ship that
|
|
105
|
+
* plugin. A thin stand-in over `callCapacitorNative`/`listenCapacitorNative`,
|
|
106
|
+
* so Buoy's calls skip interceptors and the call log. It never calls
|
|
107
|
+
* `registerPlugin`, which would make the app's own registration warn
|
|
108
|
+
* "already registered".
|
|
109
|
+
*/
|
|
110
|
+
export declare function capacitorPlugin<T = unknown>(name: string): T | null;
|
|
111
|
+
export interface CapacitorAppHost {
|
|
112
|
+
/** Simulator or emulator (`Device.getInfo().isVirtual`), null when unknown. */
|
|
113
|
+
isSimulator: boolean | null;
|
|
114
|
+
/** The device's name (`Device.getInfo().name`); a simulator's own name on iOS. */
|
|
115
|
+
deviceName: string | null;
|
|
116
|
+
/** The app's bundle id / package name (`App.getInfo().id`). */
|
|
117
|
+
bundleId: string | null;
|
|
118
|
+
/** The app's display name (`App.getInfo().name`). */
|
|
119
|
+
appName: string | null;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Where the app runs, read once from the App and Device plugins (when the app
|
|
123
|
+
* ships them) and cached. Host-side tools need it: MCP's `real: true`
|
|
124
|
+
* lifecycle events and `system_permission`, and Desktop's simulator push
|
|
125
|
+
* sender, all address the app by bundle id on a named simulator.
|
|
126
|
+
*/
|
|
127
|
+
export declare function loadCapacitorAppHost(): Promise<CapacitorAppHost | null>;
|
|
128
|
+
/** The cached host once `loadCapacitorAppHost` has finished, else null. */
|
|
129
|
+
export declare function getCapacitorAppHost(): CapacitorAppHost | null;
|
|
130
|
+
//# sourceMappingURL=capacitorBridge.d.ts.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capacitor host detection.
|
|
3
|
+
*
|
|
4
|
+
* A Capacitor app runs Buoy's web build inside a native WebView. Several
|
|
5
|
+
* things the web lane decides from the page (dev vs release, platform, where
|
|
6
|
+
* the dev machine is) are wrong there, because the page is a bundled
|
|
7
|
+
* `vite build` served from `capacitor://localhost` or `https://localhost`.
|
|
8
|
+
* The native shell knows the real answers and exposes them on
|
|
9
|
+
* `window.Capacitor`, which every Capacitor app has whether or not it imports
|
|
10
|
+
* `@capacitor/core`.
|
|
11
|
+
*
|
|
12
|
+
* This module only READS that global. It adds no dependency, and on React
|
|
13
|
+
* Native or a plain browser every function reports "not Capacitor".
|
|
14
|
+
*
|
|
15
|
+
* Lives in `@buoy-gg/license` because license is the one package every other
|
|
16
|
+
* Buoy package already depends on (license needs it too, for its own
|
|
17
|
+
* dev-bundle check).
|
|
18
|
+
*/
|
|
19
|
+
/** The part of `window.Capacitor` Buoy reads. Present since Capacitor 3; verified on 7.6.9. */
|
|
20
|
+
export interface CapacitorGlobal {
|
|
21
|
+
getPlatform?: () => string;
|
|
22
|
+
isNativePlatform?: () => boolean;
|
|
23
|
+
isPluginAvailable?: (name: string) => boolean;
|
|
24
|
+
registerPlugin?: (name: string) => unknown;
|
|
25
|
+
/**
|
|
26
|
+
* Set by the native shell: iOS from `#if DEBUG` (or `CAPACITOR_DEBUG` in
|
|
27
|
+
* Info.plist), Android from the app's `FLAG_DEBUGGABLE`.
|
|
28
|
+
*/
|
|
29
|
+
DEBUG?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export type CapacitorPlatform = "ios" | "android";
|
|
32
|
+
/** True only inside a Capacitor native shell (not Capacitor's web fallback). */
|
|
33
|
+
export declare function isCapacitorNative(): boolean;
|
|
34
|
+
/** `"ios"` / `"android"` inside a Capacitor native shell, otherwise null. */
|
|
35
|
+
export declare function capacitorPlatform(): CapacitorPlatform | null;
|
|
36
|
+
/**
|
|
37
|
+
* Whether the native shell is a debug build, or null outside Capacitor.
|
|
38
|
+
*
|
|
39
|
+
* This is the Capacitor equivalent of React Native's `__DEV__`. It wins over
|
|
40
|
+
* the bundle's own flags in both directions: Capacitor apps usually ship a
|
|
41
|
+
* production `vite build` even to a debug run, and an app can also force
|
|
42
|
+
* `__DEV__` on in a bundle that ends up in a release build.
|
|
43
|
+
*/
|
|
44
|
+
export declare function capacitorDebug(): boolean | null;
|
|
45
|
+
/**
|
|
46
|
+
* Dev vs release for a bundle: the Capacitor shell's debug flag when there is
|
|
47
|
+
* one, otherwise the bundle's own flag (`__DEV__` / `NODE_ENV`).
|
|
48
|
+
*/
|
|
49
|
+
export declare function resolveDevBuild(bundleDev: boolean): boolean;
|
|
50
|
+
//# sourceMappingURL=capacitorHost.d.ts.map
|
|
@@ -38,6 +38,10 @@ export type { SessionStatus, SessionErrorCode, SessionConfig, CodePrompt } from
|
|
|
38
38
|
export type { SessionClaims, SessionTier } from "./sessionToken";
|
|
39
39
|
export { useBuoySession } from "./hooks";
|
|
40
40
|
export { isServiceKey, normalizeLicenseKey, sameLicenseKey } from "./serviceKey";
|
|
41
|
+
export { isCapacitorNative, capacitorPlatform, capacitorDebug, resolveDevBuild } from "./capacitorHost";
|
|
42
|
+
export { installCapacitorBridge, isCapacitorBridgeInstalled, interceptCapacitor, emitCapacitorEvent, capacitorListenerCount, hasCapacitorPlugin, capacitorPlugin, callCapacitorNative, callCapacitorAsApp, callCapacitorNativeCallback, listenCapacitorNative, makeCapacitorCallbackId, getCapacitorCalls, clearCapacitorCalls, subscribeCapacitorCalls, loadCapacitorAppHost, getCapacitorAppHost, colorSchemeQueryValue, getColorSchemeQueries, } from "./capacitorBridge";
|
|
43
|
+
export type { CapacitorCall, CapacitorCallback, CapacitorInterceptor, CapacitorCallRecord, CapacitorAppHost } from "./capacitorBridge";
|
|
44
|
+
export type { CapacitorGlobal, CapacitorPlatform } from "./capacitorHost";
|
|
41
45
|
export { isDevToken } from "./devToken";
|
|
42
46
|
export { getSyncCredential } from "./syncCredential";
|
|
43
47
|
export { isBuoyToken } from "./freeToken";
|
|
@@ -27,6 +27,10 @@ export type { SessionStatus, SessionErrorCode, SessionConfig, CodePrompt } from
|
|
|
27
27
|
export type { SessionClaims, SessionTier } from "./sessionToken";
|
|
28
28
|
export { useBuoySession } from "./hooks";
|
|
29
29
|
export { isServiceKey, normalizeLicenseKey, sameLicenseKey } from "./serviceKey";
|
|
30
|
+
export { isCapacitorNative, capacitorPlatform, capacitorDebug, resolveDevBuild } from "./capacitorHost";
|
|
31
|
+
export { installCapacitorBridge, isCapacitorBridgeInstalled, interceptCapacitor, emitCapacitorEvent, capacitorListenerCount, hasCapacitorPlugin, capacitorPlugin, callCapacitorNative, callCapacitorAsApp, callCapacitorNativeCallback, listenCapacitorNative, makeCapacitorCallbackId, getCapacitorCalls, clearCapacitorCalls, subscribeCapacitorCalls, loadCapacitorAppHost, getCapacitorAppHost, colorSchemeQueryValue, getColorSchemeQueries, } from "./capacitorBridge";
|
|
32
|
+
export type { CapacitorCall, CapacitorCallback, CapacitorInterceptor, CapacitorCallRecord, CapacitorAppHost } from "./capacitorBridge";
|
|
33
|
+
export type { CapacitorGlobal, CapacitorPlatform } from "./capacitorHost";
|
|
30
34
|
export { isDevToken } from "./devToken";
|
|
31
35
|
export { getSyncCredential } from "./syncCredential";
|
|
32
36
|
export { isBuoyToken } from "./freeToken";
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
export type CapacitorCallback = (data: unknown, error?: unknown) => void;
|
|
2
|
+
export interface CapacitorCall {
|
|
3
|
+
plugin: string;
|
|
4
|
+
method: string;
|
|
5
|
+
options: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
export interface CapacitorInterceptor {
|
|
8
|
+
/** Plugin id (`"Geolocation"`), or `"*"` for every plugin. */
|
|
9
|
+
plugin: string;
|
|
10
|
+
/** Only these methods; every method when left out. */
|
|
11
|
+
methods?: string[];
|
|
12
|
+
/**
|
|
13
|
+
* Higher runs first (outermost); ties run in the order added. Permission
|
|
14
|
+
* checks use a high order so they wrap tools that answer calls.
|
|
15
|
+
*/
|
|
16
|
+
order?: number;
|
|
17
|
+
/** A one-answer call. Return `next()` to pass it on, or your own value (or promise) to answer it. */
|
|
18
|
+
promise?: (call: CapacitorCall, next: () => Promise<unknown>) => unknown;
|
|
19
|
+
/**
|
|
20
|
+
* A many-answer call. Return `next(callback)` to pass it on (wrap the
|
|
21
|
+
* callback to see or change answers), or answer it yourself and return
|
|
22
|
+
* your own id from `makeCapacitorCallbackId()`.
|
|
23
|
+
*/
|
|
24
|
+
callback?: (call: CapacitorCall, callback: CapacitorCallback, next: (callback: CapacitorCallback) => string | null) => string | null;
|
|
25
|
+
}
|
|
26
|
+
export interface CapacitorCallRecord {
|
|
27
|
+
seq: number;
|
|
28
|
+
plugin: string;
|
|
29
|
+
method: string;
|
|
30
|
+
/**
|
|
31
|
+
* "promise" and "callback" are the app's calls. "event" is one answer a
|
|
32
|
+
* plugin sent later: an event to an `addListener` callback (method is the
|
|
33
|
+
* event name), or a watch's later updates.
|
|
34
|
+
*/
|
|
35
|
+
kind: "promise" | "callback" | "event";
|
|
36
|
+
options: Record<string, unknown>;
|
|
37
|
+
/** Real `Date.now()` when the app made the call. */
|
|
38
|
+
start: number;
|
|
39
|
+
/** When the (first) answer arrived. */
|
|
40
|
+
end?: number;
|
|
41
|
+
ok?: boolean;
|
|
42
|
+
result?: unknown;
|
|
43
|
+
error?: unknown;
|
|
44
|
+
/** Callback calls: how many answers/events arrived so far. */
|
|
45
|
+
events?: number;
|
|
46
|
+
/** A Buoy interceptor answered instead of native code. */
|
|
47
|
+
answeredByBuoy?: boolean;
|
|
48
|
+
}
|
|
49
|
+
/** A callback id for a call a Buoy interceptor answers itself. */
|
|
50
|
+
export declare function makeCapacitorCallbackId(): string;
|
|
51
|
+
/**
|
|
52
|
+
* Wrap the bridge once. True when the hook is (now) in place. Safe to call
|
|
53
|
+
* from several places; later calls return the same answer.
|
|
54
|
+
*/
|
|
55
|
+
export declare function installCapacitorBridge(options?: {
|
|
56
|
+
release?: boolean;
|
|
57
|
+
}): boolean;
|
|
58
|
+
/** "dark" or "light" for a plain `(prefers-color-scheme: …)` query, else null. */
|
|
59
|
+
export declare function colorSchemeQueryValue(media: string): "dark" | "light" | null;
|
|
60
|
+
/** The live plain color scheme queries the page has made since the hook installed. */
|
|
61
|
+
export declare function getColorSchemeQueries(): object[];
|
|
62
|
+
export declare function isCapacitorBridgeInstalled(): boolean;
|
|
63
|
+
/** Add an interceptor. Earlier ones run first (outermost). Returns a remover. */
|
|
64
|
+
export declare function interceptCapacitor(interceptor: CapacitorInterceptor): () => void;
|
|
65
|
+
/**
|
|
66
|
+
* Send an event to the app's own listeners for `plugin`/`eventName`, the way
|
|
67
|
+
* native code would. Returns how many listeners got it. Buoy's own listeners
|
|
68
|
+
* (from `listenCapacitorNative`) don't get it.
|
|
69
|
+
*/
|
|
70
|
+
export declare function emitCapacitorEvent(plugin: string, eventName: string, data: unknown): number;
|
|
71
|
+
/** How many app listeners the hook has seen for `plugin`/`eventName`. */
|
|
72
|
+
export declare function capacitorListenerCount(plugin: string, eventName: string): number;
|
|
73
|
+
/** True when the app ships the native side of `plugin`. */
|
|
74
|
+
export declare function hasCapacitorPlugin(plugin: string): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Buoy's own plugin call: skips every interceptor and the call log, so it
|
|
77
|
+
* reads the real answer (the real location, the real stored value).
|
|
78
|
+
*/
|
|
79
|
+
export declare function callCapacitorNative<T = unknown>(plugin: string, method: string, options?: Record<string, unknown>): Promise<T>;
|
|
80
|
+
/**
|
|
81
|
+
* A Buoy call that should see what the app would see: it runs through the
|
|
82
|
+
* interceptors (another tool's override applies) but stays out of the call
|
|
83
|
+
* log. Without the hook it goes straight to native.
|
|
84
|
+
*/
|
|
85
|
+
export declare function callCapacitorAsApp<T = unknown>(plugin: string, method: string, options?: Record<string, unknown>): Promise<T>;
|
|
86
|
+
/**
|
|
87
|
+
* Buoy's own many-answer call (a native watch Buoy starts for the app):
|
|
88
|
+
* skips interceptors and the log. Returns native's callback id.
|
|
89
|
+
*/
|
|
90
|
+
export declare function callCapacitorNativeCallback(plugin: string, method: string, options: Record<string, unknown>, callback: CapacitorCallback): string | null;
|
|
91
|
+
/**
|
|
92
|
+
* Buoy's own event listener: skips interceptors, the log and
|
|
93
|
+
* `emitCapacitorEvent`. Resolves with a remover.
|
|
94
|
+
*/
|
|
95
|
+
export declare function listenCapacitorNative(plugin: string, eventName: string, listener: (data: unknown) => void): Promise<{
|
|
96
|
+
remove: () => Promise<void>;
|
|
97
|
+
}>;
|
|
98
|
+
/** The recent plugin calls, oldest first. */
|
|
99
|
+
export declare function getCapacitorCalls(): readonly CapacitorCallRecord[];
|
|
100
|
+
export declare function clearCapacitorCalls(): void;
|
|
101
|
+
/** Called after every new call and every answer. Returns an unsubscribe. */
|
|
102
|
+
export declare function subscribeCapacitorCalls(onChange: () => void): () => void;
|
|
103
|
+
/**
|
|
104
|
+
* A plugin object for Buoy's own calls, or null when the app doesn't ship that
|
|
105
|
+
* plugin. A thin stand-in over `callCapacitorNative`/`listenCapacitorNative`,
|
|
106
|
+
* so Buoy's calls skip interceptors and the call log. It never calls
|
|
107
|
+
* `registerPlugin`, which would make the app's own registration warn
|
|
108
|
+
* "already registered".
|
|
109
|
+
*/
|
|
110
|
+
export declare function capacitorPlugin<T = unknown>(name: string): T | null;
|
|
111
|
+
export interface CapacitorAppHost {
|
|
112
|
+
/** Simulator or emulator (`Device.getInfo().isVirtual`), null when unknown. */
|
|
113
|
+
isSimulator: boolean | null;
|
|
114
|
+
/** The device's name (`Device.getInfo().name`); a simulator's own name on iOS. */
|
|
115
|
+
deviceName: string | null;
|
|
116
|
+
/** The app's bundle id / package name (`App.getInfo().id`). */
|
|
117
|
+
bundleId: string | null;
|
|
118
|
+
/** The app's display name (`App.getInfo().name`). */
|
|
119
|
+
appName: string | null;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Where the app runs, read once from the App and Device plugins (when the app
|
|
123
|
+
* ships them) and cached. Host-side tools need it: MCP's `real: true`
|
|
124
|
+
* lifecycle events and `system_permission`, and Desktop's simulator push
|
|
125
|
+
* sender, all address the app by bundle id on a named simulator.
|
|
126
|
+
*/
|
|
127
|
+
export declare function loadCapacitorAppHost(): Promise<CapacitorAppHost | null>;
|
|
128
|
+
/** The cached host once `loadCapacitorAppHost` has finished, else null. */
|
|
129
|
+
export declare function getCapacitorAppHost(): CapacitorAppHost | null;
|
|
130
|
+
//# sourceMappingURL=capacitorBridge.d.ts.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capacitor host detection.
|
|
3
|
+
*
|
|
4
|
+
* A Capacitor app runs Buoy's web build inside a native WebView. Several
|
|
5
|
+
* things the web lane decides from the page (dev vs release, platform, where
|
|
6
|
+
* the dev machine is) are wrong there, because the page is a bundled
|
|
7
|
+
* `vite build` served from `capacitor://localhost` or `https://localhost`.
|
|
8
|
+
* The native shell knows the real answers and exposes them on
|
|
9
|
+
* `window.Capacitor`, which every Capacitor app has whether or not it imports
|
|
10
|
+
* `@capacitor/core`.
|
|
11
|
+
*
|
|
12
|
+
* This module only READS that global. It adds no dependency, and on React
|
|
13
|
+
* Native or a plain browser every function reports "not Capacitor".
|
|
14
|
+
*
|
|
15
|
+
* Lives in `@buoy-gg/license` because license is the one package every other
|
|
16
|
+
* Buoy package already depends on (license needs it too, for its own
|
|
17
|
+
* dev-bundle check).
|
|
18
|
+
*/
|
|
19
|
+
/** The part of `window.Capacitor` Buoy reads. Present since Capacitor 3; verified on 7.6.9. */
|
|
20
|
+
export interface CapacitorGlobal {
|
|
21
|
+
getPlatform?: () => string;
|
|
22
|
+
isNativePlatform?: () => boolean;
|
|
23
|
+
isPluginAvailable?: (name: string) => boolean;
|
|
24
|
+
registerPlugin?: (name: string) => unknown;
|
|
25
|
+
/**
|
|
26
|
+
* Set by the native shell: iOS from `#if DEBUG` (or `CAPACITOR_DEBUG` in
|
|
27
|
+
* Info.plist), Android from the app's `FLAG_DEBUGGABLE`.
|
|
28
|
+
*/
|
|
29
|
+
DEBUG?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export type CapacitorPlatform = "ios" | "android";
|
|
32
|
+
/** True only inside a Capacitor native shell (not Capacitor's web fallback). */
|
|
33
|
+
export declare function isCapacitorNative(): boolean;
|
|
34
|
+
/** `"ios"` / `"android"` inside a Capacitor native shell, otherwise null. */
|
|
35
|
+
export declare function capacitorPlatform(): CapacitorPlatform | null;
|
|
36
|
+
/**
|
|
37
|
+
* Whether the native shell is a debug build, or null outside Capacitor.
|
|
38
|
+
*
|
|
39
|
+
* This is the Capacitor equivalent of React Native's `__DEV__`. It wins over
|
|
40
|
+
* the bundle's own flags in both directions: Capacitor apps usually ship a
|
|
41
|
+
* production `vite build` even to a debug run, and an app can also force
|
|
42
|
+
* `__DEV__` on in a bundle that ends up in a release build.
|
|
43
|
+
*/
|
|
44
|
+
export declare function capacitorDebug(): boolean | null;
|
|
45
|
+
/**
|
|
46
|
+
* Dev vs release for a bundle: the Capacitor shell's debug flag when there is
|
|
47
|
+
* one, otherwise the bundle's own flag (`__DEV__` / `NODE_ENV`).
|
|
48
|
+
*/
|
|
49
|
+
export declare function resolveDevBuild(bundleDev: boolean): boolean;
|
|
50
|
+
//# sourceMappingURL=capacitorHost.d.ts.map
|
|
@@ -38,6 +38,10 @@ export type { SessionStatus, SessionErrorCode, SessionConfig, CodePrompt } from
|
|
|
38
38
|
export type { SessionClaims, SessionTier } from "./sessionToken";
|
|
39
39
|
export { useBuoySession } from "./hooks";
|
|
40
40
|
export { isServiceKey, normalizeLicenseKey, sameLicenseKey } from "./serviceKey";
|
|
41
|
+
export { isCapacitorNative, capacitorPlatform, capacitorDebug, resolveDevBuild } from "./capacitorHost";
|
|
42
|
+
export { installCapacitorBridge, isCapacitorBridgeInstalled, interceptCapacitor, emitCapacitorEvent, capacitorListenerCount, hasCapacitorPlugin, capacitorPlugin, callCapacitorNative, callCapacitorAsApp, callCapacitorNativeCallback, listenCapacitorNative, makeCapacitorCallbackId, getCapacitorCalls, clearCapacitorCalls, subscribeCapacitorCalls, loadCapacitorAppHost, getCapacitorAppHost, colorSchemeQueryValue, getColorSchemeQueries, } from "./capacitorBridge";
|
|
43
|
+
export type { CapacitorCall, CapacitorCallback, CapacitorInterceptor, CapacitorCallRecord, CapacitorAppHost } from "./capacitorBridge";
|
|
44
|
+
export type { CapacitorGlobal, CapacitorPlatform } from "./capacitorHost";
|
|
41
45
|
export { isDevToken } from "./devToken";
|
|
42
46
|
export { getSyncCredential } from "./syncCredential";
|
|
43
47
|
export { isBuoyToken } from "./freeToken";
|
|
@@ -27,6 +27,10 @@ export type { SessionStatus, SessionErrorCode, SessionConfig, CodePrompt } from
|
|
|
27
27
|
export type { SessionClaims, SessionTier } from "./sessionToken";
|
|
28
28
|
export { useBuoySession } from "./hooks";
|
|
29
29
|
export { isServiceKey, normalizeLicenseKey, sameLicenseKey } from "./serviceKey";
|
|
30
|
+
export { isCapacitorNative, capacitorPlatform, capacitorDebug, resolveDevBuild } from "./capacitorHost";
|
|
31
|
+
export { installCapacitorBridge, isCapacitorBridgeInstalled, interceptCapacitor, emitCapacitorEvent, capacitorListenerCount, hasCapacitorPlugin, capacitorPlugin, callCapacitorNative, callCapacitorAsApp, callCapacitorNativeCallback, listenCapacitorNative, makeCapacitorCallbackId, getCapacitorCalls, clearCapacitorCalls, subscribeCapacitorCalls, loadCapacitorAppHost, getCapacitorAppHost, colorSchemeQueryValue, getColorSchemeQueries, } from "./capacitorBridge";
|
|
32
|
+
export type { CapacitorCall, CapacitorCallback, CapacitorInterceptor, CapacitorCallRecord, CapacitorAppHost } from "./capacitorBridge";
|
|
33
|
+
export type { CapacitorGlobal, CapacitorPlatform } from "./capacitorHost";
|
|
30
34
|
export { isDevToken } from "./devToken";
|
|
31
35
|
export { getSyncCredential } from "./syncCredential";
|
|
32
36
|
export { isBuoyToken } from "./freeToken";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";import{a,b as t,c as i,d as s,e as c,f as r,g as e,h as l,i as o,j as p,k as C,l as n,m as g,n as m,o as u,p as d,q as b,r as h,s as k}from"./chunks/chunk-UPTHA45A.mjs";import"./chunks/chunk-J7MW3NXU.mjs";export{C as callCapacitorAsApp,p as callCapacitorNative,n as callCapacitorNativeCallback,l as capacitorListenerCount,b as capacitorPlugin,u as clearCapacitorCalls,i as colorSchemeQueryValue,e as emitCapacitorEvent,k as getCapacitorAppHost,m as getCapacitorCalls,s as getColorSchemeQueries,o as hasCapacitorPlugin,t as installCapacitorBridge,r as interceptCapacitor,c as isCapacitorBridgeInstalled,g as listenCapacitorNative,h as loadCapacitorAppHost,a as makeCapacitorCallbackId,d as subscribeCapacitorCalls};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";import{m as e}from"./chunk-3JAIQNSD.mjs";import"./chunk-J7MW3NXU.mjs";export{e as LicenseManager};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use client";import{a as p,d as ke}from"./chunk-J7MW3NXU.mjs";var L=new Map,Ee={async getItem(e){try{return localStorage.getItem(e)??L.get(e)??null}catch{return L.get(e)??null}},async setItem(e,t){L.set(e,t);try{localStorage.setItem(e,t)}catch{}},async removeItem(e){L.delete(e);try{localStorage.removeItem(e)}catch{}}};async function y(){return Ee}var I={accountId:"b0eba0e8-e904-4906-b644-38f9aab57bed",productId:"bf67cb43-eeef-40ca-b308-e6e1b22c0eaa",apiUrl:"https://buoy.gg/api/license"},be="3b546fc717a62683f3236c70167899a271bee3ffc04df6ec1eea60a394a2f1e9",xe="36abba0267f7f379d992a5b6df641daab4190bcc9e639e36f1378e3c1ac52746",R={free:"394e3351-1249-4f73-807a-703408604c0e",solo:"fa5d3c8f-5379-40f1-b63e-ab8a974b2f28",business:"690c2212-8e54-426f-b4b4-002ee1c0ae2b"},N=720*60*60*1e3,Le=1440*60*1e3,M="buoy-gg-license",V="buoy-gg-device-fingerprint",Ie=3600*1e3,Re=[5*1e3,20*1e3,60*1e3,300*1e3,900*1e3],Ne=60*1e3,q=3600*1e3,Ce=1440*60*1e3,Pe=50,Se=N,D="buoy-gg-license-hold";function h(){let e=globalThis.__buoyRealNow;return typeof e=="function"?e():Date.now()}var{apiUrl:Z}=I,T=class extends Error{constructor(e,t,i=null){super(e);this.isTransient=true;this.name="LicenseTransportError",this.status=t,this.retryAfterMs=i}};function Ke(e){let t=e?.status;return t===429||t===402}function Oe(e,t,i){return e.status===402?t:e.retryAfterMs??i}function Me(e){let t=s=>{try{return e.headers?.get?.(s)??null}catch{return null}},i=t("Retry-After");if(i){let s=Number(i);if(Number.isFinite(s)&&s>=0)return s*1e3;let n=Date.parse(i);if(Number.isFinite(n))return Math.max(0,n-h())}let r=Number(t("X-RateLimit-Reset"));return Number.isFinite(r)&&r>0?Math.max(0,r*1e3-h()):null}function Q(e){return e instanceof T||e instanceof TypeError?true:typeof e=="object"&&e!==null&&e.isTransient===true}async function Ve(e){try{return(await e.json()).errors?.[0]?.detail||`HTTP ${e.status}`}catch{return`HTTP ${e.status}`}}function ee(){return{"Content-Type":"application/vnd.api+json",Accept:"application/vnd.api+json"}}async function De(e,t){let i=`${Z}/validate`,r={meta:{key:e}},s;try{s=await fetch(i,{signal:t,method:"POST",headers:ee(),body:JSON.stringify(r)})}catch(n){throw new T(n instanceof Error?n.message:"Network request failed",null)}if(!s.ok)throw new T(await Ve(s),s.status,s.status===429?Me(s):null);try{let n=await s.json();if(!n||typeof n!="object"||typeof n.meta?.valid!="boolean"||typeof n.meta?.code!="string"||!n.meta.code)throw new Error("Missing license verdict");return n}catch{throw new T("License server returned an unreadable response",s.status)}}async function Ue(e){let t=typeof AbortController=="function"?new AbortController:null,i;try{return await Promise.race([De(e,t?.signal),new Promise((r,s)=>{i=setTimeout(()=>{s(new T("License verification timed out. Please retry.",null)),t?.abort()},15e3)})])}finally{i&&clearTimeout(i)}}function Fe(e){if(!e.data)return false;let t=e.data.relationships?.product?.data?.id;return t&&t!==I.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 $e(e){let t=e.data?.relationships?.machines?.meta?.count;return typeof t=="number"&&Number.isFinite(t)?t:0}async function te(e,t,i,r,s){let n=`${Z}/machines`,c=await fetch(n,{method:"POST",headers:ee(),body:JSON.stringify({licenseId:e,licenseKey:t,fingerprint:i,name:r,metadata:s||{}})});if(!c.ok){let o=await c.json(),a=o.errors?.[0]?.code;if(a==="FINGERPRINT_TAKEN")throw new Error("FINGERPRINT_TAKEN");if(a==="MACHINE_LIMIT_EXCEEDED")throw new Error("MACHINE_LIMIT_EXCEEDED");let l=o.errors?.[0]?.detail||`HTTP ${c.status}`;throw new Error(l)}return c.json()}function je(e){let{meta:t,data:i}=e;return{valid:t.valid,code:t.code,detail:t.detail,metadata:i?.attributes?.metadata}}function He(e){return["NOT_FOUND","SUSPENDED","EXPIRED","BANNED","PRODUCT_SCOPE_MISMATCH"].includes(e)}function U(){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 F(){let e=ke();if(e!==null)return e;if(typeof p<"u")return p;try{if(typeof navigator<"u"&&/electron/i.test(navigator.userAgent))return true}catch{}return typeof process<"u"&&process.env.NODE_ENV!=="production"}function ie(){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 Be(){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 re(){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 se(){let e={platform:ie(),osVersion:Be(),isSimulator:"false"},t=re();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 $(){let e=ie(),t=re();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 ze=["v1"],Ge="buoy.gg/pro:9f3c1d7a4b2e:license-cache";function ne(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 Je(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(Ge),i.join("\0")}function ae(e,t){let i=Je(e,t),r=ne(i,2166136261),s=ne(i,2135587861);return`${t}.${r.toString(16)}${s.toString(16)}`}function oe(e){return ae(e,"v2")}function le(e){return{...e,sig:oe(e)}}function A(e){return!e||typeof e.sig!="string"||e.sig.length===0?false:e.sig===oe(e)?true:ze.some(t=>e.sig.startsWith(`${t}.`)&&e.sig===ae(e,t))}import Ye from"tweetnacl";var Xe=1,We=1,qe="buoy-free-token-v1:",Ze=22,Qe=64,ce=/^BUOY1-([A-Z2-7]+)-([A-Z2-7]+)$/;function he(e){return ce.test(e.trim().toUpperCase())}var et="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";function ue(e){let t=[],i=0,r=0;for(let s of e){let n=et.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 tt(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 it(e){let t="";for(let i of e)t+=i.toString(16).padStart(2,"0");return t}function rt(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 st(e,t){let i=new Uint8Array(e.length+t.length);return i.set(e,0),i.set(t,e.length),i}function nt(e){return st(rt(qe),e)}var at=be;function ot(e,t=at){let i=ce.exec(e.trim().toUpperCase());if(!i)return null;let r=ue(i[1]),s=ue(i[2]);if(!r||!s||r.length!==Ze||s.length!==Qe||r[0]!==Xe||r[1]!==We)return null;try{if(!Ye.sign.detached.verify(nt(r),s,tt(t)))return null}catch{return null}return{tier:"free",issuedAt:((r[2]<<24>>>0)+(r[3]<<16)+(r[4]<<8)+r[5])*1e3,accountHash:it(r.slice(6,22))}}function lt(e){let t=e.relationships?.policy?.data?.id;return t===R.free?"free":t===R.solo||t===R.business?"pro":e.attributes?.metadata?.plan==="free"?"free":"pro"}function ct(e){if(!e)return false;let t=e.relationships?.product?.data?.id;if(t)return t===I.productId;let i=e.relationships?.policy?.data?.id;return Object.values(R).some(r=>r===i)}function de(e,t=h()){let i=e.verifiedAt!==null&&Number.isFinite(e.verifiedAt)&&e.verifiedAt<=t?e.verifiedAt+N: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 ht(e){if(typeof window>"u"||typeof window.addEventListener!="function")return()=>{};let t=()=>{document.hidden||e()};return window.addEventListener("focus",e),document.addEventListener("visibilitychange",t),()=>{window.removeEventListener("focus",e),document.removeEventListener("visibilitychange",t)}}import ut from"tweetnacl";var fe="buoys1",dt="buoy-session-v1:",pe=1,j=60,ft=64,pt=["free","pro","business"],g="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";function H(e){let t="",i=0;for(;i+2<e.length;i+=3){let s=e[i]<<16|e[i+1]<<8|e[i+2];t+=g[s>>>18&63]+g[s>>>12&63]+g[s>>>6&63]+g[s&63]}let r=e.length-i;if(r===1){let s=e[i]<<16;t+=g[s>>>18&63]+g[s>>>12&63]}else if(r===2){let s=e[i]<<16|e[i+1]<<8;t+=g[s>>>18&63]+g[s>>>12&63]+g[s>>>6&63]}return t}function me(e){if(!/^[A-Za-z0-9_-]*$/.test(e)||e.length%4===1)return null;let t=[],i=0,r=0;for(let s of e)r=r<<6|g.indexOf(s),i+=6,i>=8&&(t.push(r>>>i-8&255),i-=8);return new Uint8Array(t)}function mt(e){if(typeof TextEncoder<"u")return new TextEncoder().encode(e);let t=unescape(encodeURIComponent(e)),i=new Uint8Array(t.length);for(let r=0;r<t.length;r+=1)i[r]=t.charCodeAt(r);return i}function gt(e){try{if(typeof TextDecoder<"u")return new TextDecoder("utf-8",{fatal:true}).decode(e);let t="";for(let i of e)t+=String.fromCharCode(i);return decodeURIComponent(escape(t))}catch{return null}}function yt(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 wt(e){return mt(dt+e)}function _(e,t=256){return typeof e=="string"&&e.length>0&&e.length<=t}function ge(e){return typeof e=="number"&&Number.isInteger(e)&&e>0}function vt(e){if(!e||typeof e!="object"||Array.isArray(e))return null;let t=e;return!_(t.sid)||!_(t.sub)||!_(t.aud,512)||t.team!==null&&!_(t.team)||!pt.includes(t.tier)||t.role!==void 0&&!_(t.role,64)||t.tools!==void 0&&(!Array.isArray(t.tools)||t.tools.length>256||!t.tools.every(i=>_(i,64)))||!ge(t.iat)||!ge(t.exp)||t.exp<=t.iat?null:{v:pe,sid:t.sid,sub:t.sub,team:t.team,tier:t.tier,...t.role!==void 0?{role:t.role}:{},...t.tools!==void 0?{tools:[...t.tools]}:{},aud:t.aud,iat:t.iat,exp:t.exp}}var Tt=xe;function ye(e){return e.startsWith(`${fe}.`)}function B(e,t){let i=t.publicKeyHex??Tt;if(!i)return{ok:false,reason:"no-key"};let r=typeof e=="string"?e.split("."):[];if(r.length!==3||r[0]!==fe)return{ok:false,reason:"malformed"};let[,s,n]=r,c=me(s),o=me(n);if(!c||!o||o.length!==ft)return{ok:false,reason:"malformed"};try{if(!ut.sign.detached.verify(wt(s),o,yt(i)))return{ok:false,reason:"signature"}}catch{return{ok:false,reason:"signature"}}let a=gt(c),l;try{l=a===null?null:JSON.parse(a)}catch{return{ok:false,reason:"malformed"}}if(!l||typeof l!="object"||l.v!==pe)return{ok:false,reason:l&&typeof l=="object"?"version":"malformed"};let u=vt(l);if(!u)return{ok:false,reason:"claims"};if(u.aud!==t.audience)return{ok:false,reason:"audience"};if(t.ignoreTime)return{ok:true,claims:u};let f=Math.floor((t.nowMs??h())/1e3);return f>=u.exp+j?{ok:false,reason:"expired"}:u.iat>f+j?{ok:false,reason:"not-yet-valid"}:{ok:true,claims:u}}var At="@buoy/session:",C=10080*60*1e3,we=360*60*1e3,_t=300*1e3,kt=15e3,Et="https://buoy.gg",bt="buoy:signin",xt=600*1e3,d=class extends Error{constructor(e,t){super(t);this.code=e;this.name="SessionError"}};function Lt(){let e=globalThis;return{fetch:(t,i)=>fetch(t,i),storage:y,now:h,random:t=>{let i=new Uint8Array(t);if(!e.crypto?.getRandomValues)throw new d("not_configured","This platform has no secure random source.");return e.crypto.getRandomValues(i)},sha256:async t=>{if(!e.crypto?.subtle)throw new d("not_configured","Sign-in needs a secure page (https or localhost).");return new Uint8Array(await e.crypto.subtle.digest("SHA-256",t))},openPopup:()=>{if(!e.window?.open)return null;let t=480,i=640,r=Math.max(0,(e.window.screenX??0)+((e.window.outerWidth??t)-t)/2),s=Math.max(0,(e.window.screenY??0)+((e.window.outerHeight??i)-i)/2);return e.window.open("about:blank","buoy-signin",`popup,width=${t},height=${i},left=${r},top=${s}`)},onMessage:t=>{if(!e.window?.addEventListener)return()=>{};let i=r=>t({origin:r.origin,data:r.data});return e.window.addEventListener("message",i),()=>e.window?.removeEventListener("message",i)},withLock:(t,i)=>e.navigator?.locks?e.navigator.locks.request(t,i):i(),watch:t=>{let i=e.window;if(!i?.addEventListener)return()=>{};let r=n=>t.storage(n.key),s=()=>{i.document?.visibilityState!=="hidden"&&t.wake()};return i.addEventListener("storage",r),i.addEventListener("online",t.wake),i.document?.addEventListener?.("visibilitychange",s),()=>{i.removeEventListener("storage",r),i.removeEventListener("online",t.wake),i.document?.removeEventListener?.("visibilitychange",s)}},setTimer:(t,i)=>setTimeout(t,Math.min(i,2147483647)),clearTimer:t=>clearTimeout(t)}}function It(){let e=globalThis.location;if(!(!e?.origin||!/^https?:$/.test(e.protocol??"")))return e.origin}var Rt=class{constructor(e){this.signinOrigin=Et;this.current=null;this.claims=null;this.listeners=new Set;this.timer=null;this.refreshing=null;this.loaded=null;this.unwatch=null;this.limitTimer=null;this.epoch=0;this.deps=e??Lt(),this.audience=It()}get origin(){return this.signinOrigin}configure(e){e.audience!==void 0&&(this.audience=e.audience),e.signinOrigin!==void 0&&(this.signinOrigin=e.signinOrigin.replace(/\/$/,"")),this.reset()}__setDeps(e){this.deps=e,this.reset()}reset(){this.unwatch?.(),this.unwatch=null,this.epoch+=1,this.limitTimer!==null&&this.deps.clearTimer(this.limitTimer),this.limitTimer=null,this.timer!==null&&this.deps.clearTimer(this.timer),this.timer=null,this.current=null,this.claims=null,this.loaded=null,this.refreshing=null}get storageKey(){return At+(this.audience??"")}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}notify(){for(let e of[...this.listeners])try{e()}catch(t){console.warn("[Buoy] sign-in listener error:",t)}}getAccessToken(){let e=this.getStatus();return e.state==="active"&&!e.grace?this.current?.accessToken??null:null}getStatus(){let e=this.claims;if(!e)return{state:"signed_out"};let t=e.exp*1e3,i=this.deps.now();return i<(e.iat-j)*1e3?{state:"signed_out"}:i<t?{state:"active",claims:e,grace:false,validUntil:t}:i<t+C?{state:"active",claims:e,grace:true,validUntil:t+C}:{state:"signed_out"}}load(){return this.loaded||(this.loaded=this.loadOnce()),this.loaded}async loadOnce(){if(!this.audience)return;this.unwatch??(this.unwatch=this.deps.watch?.({storage:t=>{(t===null||t===this.storageKey)&&this.sync()},wake:()=>{this.claims&&this.refresh()}})??null);let e=await this.read();e&&this.adopt(e)&&(this.notify(),this.schedule())}async sync(){if(!this.audience)return;let e=await this.read();if(!e){this.current&&this.clearLocal();return}e.refreshToken!==this.current?.refreshToken&&this.adopt(e)&&(this.notify(),this.schedule())}async read(){try{let e=await(await this.deps.storage()).getItem(this.storageKey);if(!e)return null;let t=JSON.parse(e);return t?.v===1&&typeof t.accessToken=="string"&&typeof t.refreshToken=="string"?t:null}catch{return null}}async write(e){let t=await this.deps.storage();e?await t.setItem(this.storageKey,JSON.stringify(e)):await t.removeItem(this.storageKey)}adopt(e){if(!this.audience)return false;let t=B(e.accessToken,{audience:this.audience,ignoreTime:true,publicKeyHex:this.deps.publicKeyHex}),i=t.ok?t.claims:null;return i?(this.current=e,this.claims=i,true):false}armLimit(){if(this.limitTimer!==null&&this.deps.clearTimer(this.limitTimer),this.limitTimer=null,!this.claims)return;let e=this.claims.exp*1e3,t=this.deps.now(),i=t<e?e:t<e+C?e+C:null;i!==null&&(this.limitTimer=this.deps.setTimer(()=>{this.limitTimer=null,this.notify(),this.armLimit()},i-t))}call(e,t){return new Promise((i,r)=>{let s=this.deps.setTimer(()=>r(new Error("timeout")),kt);this.deps.fetch(e,t).then(n=>{this.deps.clearTimer(s),i(n)},n=>{this.deps.clearTimer(s),r(n)})})}schedule(){if(this.armLimit(),this.timer!==null&&this.deps.clearTimer(this.timer),this.timer=null,!this.claims)return;let e=this.claims.exp*1e3-we-this.deps.now();this.timer=this.deps.setTimer(()=>{this.timer=null,this.refresh()},Math.max(0,e))}refresh(e=false){return this.refreshing||(this.refreshing=this.deps.withLock(this.lockName,()=>this.refreshLocked(e)).catch(()=>this.retryLater()).finally(()=>{this.refreshing=null})),this.refreshing}get lockName(){return`buoy-session:${this.audience??""}`}async refreshLocked(e){let t=this.epoch,i=await this.read();if(!i){this.current&&this.clearLocal();return}if(i.refreshToken!==this.current?.refreshToken&&this.adopt(i)){this.notify(),this.schedule();return}if(!this.claims)return;if(!e&&this.claims.exp*1e3-this.deps.now()>we){this.schedule();return}let r,s;try{let n=await this.call(`${this.signinOrigin}/api/auth/refresh`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refresh_token:i.refreshToken,audience:this.audience})});r=n.status,s=await n.json().catch(()=>null)}catch{this.retryLater();return}if(t===this.epoch){if(r===200&&s&&typeof s.access_token=="string"&&typeof s.refresh_token=="string"){let n={v:1,accessToken:s.access_token,refreshToken:s.refresh_token};if(this.adopt(n)){await this.write(n),this.notify(),this.schedule();return}}if(r===400||r===401||r===403){await this.write(null),this.clearLocal();return}this.retryLater()}}retryLater(){this.armLimit(),this.timer!==null&&this.deps.clearTimer(this.timer),this.timer=this.deps.setTimer(()=>{this.timer=null,this.refresh(true)},_t),this.notify()}clearLocal(){this.timer!==null&&this.deps.clearTimer(this.timer),this.timer=null,this.limitTimer!==null&&this.deps.clearTimer(this.limitTimer),this.limitTimer=null,this.current=null,this.claims=null,this.notify()}async signIn(){if(!this.audience)throw new d("not_configured","Sign-in needs a web page or a configured app id.");let e=this.deps.openPopup();if(!e)throw new d("popup_blocked","The browser blocked the sign-in window. Allow pop-ups for this site and try again.");try{return await this.signInWith((t,i)=>new Promise((r,s)=>{e.location.href=t;let n=this.deps.now(),c=null,o=u=>{c!==null&&this.deps.clearTimer(c),a(),u()},a=this.deps.onMessage(u=>{if(u.origin!==this.signinOrigin)return;let f=u.data;!f||f.type!==bt||f.state!==i||(typeof f.code=="string"?o(()=>r(f.code)):o(()=>s(new d("access_denied","Sign-in was cancelled."))))}),l=()=>{if(e.closed)return o(()=>s(new d("popup_closed","The sign-in window was closed.")));if(this.deps.now()-n>xt)return o(()=>s(new d("timeout","Sign-in took too long.")));c=this.deps.setTimer(l,500)};c=this.deps.setTimer(l,500)}))}finally{try{e.closed||e.close()}catch{}}}async signInWith(e){let t=this.audience;if(!t)throw new d("not_configured","Sign-in needs a web page or a configured app id.");let i=H(this.deps.random(32)),r=H(this.deps.random(16)),s=H(await this.deps.sha256(new TextEncoder().encode(i))),n=`${this.signinOrigin}/auth/authorize?audience=${encodeURIComponent(t)}&code_challenge=${s}&code_challenge_method=S256&state=${r}`,c=await e(n,r),o;try{o=await this.call(`${this.signinOrigin}/api/auth/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:c,code_verifier:i,audience:t})})}catch{throw new d("network","Buoy could not be reached. Check your connection and try again.")}let a=await o.json().catch(()=>null);if(o.status!==200||!a||typeof a.access_token!="string"||typeof a.refresh_token!="string"){let l=a&&typeof a.error_description=="string"?a.error_description:"Buoy did not accept this sign-in.";throw new d(o.status===503?"unavailable":"rejected",l)}return this.finishSignIn(a.access_token,a.refresh_token)}async finishSignIn(e,t){let i={v:1,accessToken:e,refreshToken:t};if(this.epoch+=1,!this.adopt(i))throw new d("rejected","Buoy sent a sign-in this app could not check.");return await this.write(i),await this.load(),this.notify(),this.schedule(),this.getStatus()}async signInWithCode(e,t={}){let i=this.audience;if(!i)throw new d("not_configured","Sign-in with a code needs this app's id (app:com.example.app).");let r=(a,l)=>this.call(`${this.signinOrigin}/api/auth/device/${a}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)}),s;try{s=await r("start",{audience:i})}catch{throw new d("network","Buoy could not be reached. Check your connection and try again.")}let n=await s.json().catch(()=>null);if(s.status!==200||!n||typeof n.device_code!="string"||typeof n.user_code!="string"||typeof n.verification_uri!="string"||typeof n.verification_uri_complete!="string"){let a=n&&typeof n.error_description=="string"?n.error_description:"Buoy could not start a sign-in.";throw new d(s.status===503?"unavailable":"rejected",a)}let c=this.deps.now()+(Number(n.expires_in)||600)*1e3,o=Math.max(5,Number(n.interval)||5)*1e3;for(e({userCode:n.user_code,verificationUri:n.verification_uri,verificationUriComplete:n.verification_uri_complete,expiresAt:c});;){if(await this.wait(o,t.signal),this.deps.now()>c)throw new d("timeout","The code ran out. Start again for a new one.");let a;try{a=await r("poll",{device_code:n.device_code})}catch{continue}let l=await a.json().catch(()=>null);if(a.status===200&&l&&typeof l.access_token=="string"&&typeof l.refresh_token=="string")return this.finishSignIn(l.access_token,l.refresh_token);let u=l&&typeof l.error=="string"?l.error:"";if(u==="authorization_pending"||a.status>=500)continue;if(u==="slow_down"||a.status===429){o+=5e3;continue}if(u==="access_denied")throw new d("access_denied","The sign-in was turned down on buoy.gg.");if(u==="expired_token")throw new d("timeout","The code ran out. Start again for a new one.");let f=l&&typeof l.error_description=="string"?l.error_description:"Buoy did not accept this sign-in.";throw new d("rejected",f)}}wait(e,t){return new Promise((i,r)=>{let s=()=>new d("access_denied","Sign-in was cancelled.");if(t?.aborted)return r(s());let n=()=>{this.deps.clearTimer(c),r(s())},c=this.deps.setTimer(()=>{t?.removeEventListener?.("abort",n),i()},e);t?.addEventListener?.("abort",n)})}async signOut(){this.epoch+=1;let e=this.current;this.clearLocal();let t=e;try{await this.deps.withLock(this.lockName,async()=>{t=await this.read()??e,await this.write(null)})}catch{await this.write(null).catch(()=>{})}if(t)try{await this.call(`${this.signinOrigin}/api/auth/revoke`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refresh_token:t.refreshToken})})}catch{}}},k=new Rt;var Nt="bsk1_",Ct="service",Pt=15e3;function z(e){return e.startsWith(Nt)}function b(e){let t=e.trim();return z(t)||ye(t)?t:t.toUpperCase()}function St(e,t){return b(e??"")===b(t??"")}async function Kt(e,t){let i=t.fetch??((a,l)=>fetch(a,l)),r=typeof AbortController<"u"?new AbortController:void 0,s=setTimeout(()=>r?.abort(),Pt),n,c;try{let a=await i(`${t.origin.replace(/\/$/,"")}/api/auth/service-token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:e}),signal:r?.signal});n=a.status,c=await a.json().catch(()=>null)}catch{return{ok:false,reason:"network",detail:"Buoy could not be reached to check the bot key."}}finally{clearTimeout(s)}if(n>=500||n===429)return{ok:false,reason:"network",detail:"Buoy is busy. The bot key will be checked again soon."};if(n!==200||typeof c?.access_token!="string")return{ok:false,reason:"rejected",detail:typeof c?.error_description=="string"?c.error_description:"This bot key was not accepted."};let o=B(c.access_token,{audience:Ct,nowMs:h(),publicKeyHex:t.publicKeyHex});return o.ok?{ok:true,claims:o.claims}:{ok:false,reason:"rejected",detail:"Buoy sent a token this app could not check."}}var Ot="dev";function ve(e){return ye(e)}function Te(e,t=h()){let i=B(e,{audience:Ot,ignoreTime:true});return i.ok?t>=i.claims.exp*1e3?{ok:false,reason:"expired",message:"Your dev token ran out. Run `npx buoy login` again."}:{ok:true,claims:i.claims}:{ok:false,reason:"invalid",message:"This dev token is not valid. Run `npx buoy login` again."}}var Mt="This is a dev token. It only works in dev builds. A live build turns on Buoy with Sign in with Buoy.";async function w(e,t){let i;try{return await Promise.race([e,new Promise(r=>{i=setTimeout(()=>r(t),15e3)})])}finally{i&&clearTimeout(i)}}function E(e){return e.tier==="pro"||e.tier==="free"?e.tier:e.isPro?"pro":"free"}var Vt=class{constructor(){this.state={isInitialized:false,isValidating:false,isPro:false,tier:"free",tierSource:"none",licenseKey:null,error:null,errorKind:null,expiresAt:null};this.listeners=new Set;this.revalidationTimer=null;this.cachedLicense=null;this.fingerprintPromise=null;this.initPromise=null;this.generation=0;this.persistence=Promise.resolve();this.verifiedAt=null;this.expiryTimer=null;this.removeForegroundListener=null;this.sessionUnsubscribe=null;this.retryTimer=null;this.retryAttempt=0;this.deviceRegistrationCallback=null;this.pendingRegistration=null}async initialize(){if(this.initPromise)return this.initPromise;if(!this.state.isInitialized)return this.initPromise=this._doInitialize(),this.initPromise}async _doInitialize(){if(this.state.isInitialized)return;let e=this.generation;this.sessionUnsubscribe||(this.sessionUnsubscribe=k.subscribe(()=>this.emit({type:"validated",isPro:this.isPro()}))),await w(k.load().catch(()=>{}),void 0);try{let t=await w(this.loadCachedLicense(),null);if(e!==this.generation){this.state.isInitialized=true,this.emit({type:"initialized",isPro:this.state.isPro}),this.startRevalidationTimer();return}if(t&&(this.configuredKey===void 0||t.licenseKey===this.configuredKey)){let i=A(t);this.cachedLicense=t,this.state.licenseKey=t.licenseKey,i&&this.isCacheValid(t)?this.applyTier(E(t)):this.lock(),this.state.expiresAt=t.expiresAt?new Date(t.expiresAt):null,i&&this.isCacheValid(t)&&this.setVerifiedAt(t.cachedAt),this.configuredKey===void 0&&t.licenseKey&&!(i&&this.isCacheValid(t)&&this.isCacheFresh(t))&&this.validateInBackground(t.licenseKey)}this.state.isInitialized=true,this.emit({type:"initialized",isPro:this.state.isPro}),this.startRevalidationTimer()}catch(t){console.warn("[React Buoy] License initialization failed:",t),this.state.isInitialized=true,this.emit({type:"initialized",isPro:false})}}async configure(e){if(e===void 0)return await this.initialize(),this.hasAccountAccess();let t=b(e),i=++this.generation;return this.cancelRetry(),this.configuredKey=t||null,this.state.licenseKey!==this.configuredKey&&this.lock(),this.state.licenseKey=this.configuredKey,this.state.isValidating=!!t,this.emit({type:"validating",isPro:this.isPro()}),await this.initialize(),i!==this.generation?false:t?this.setLicenseKey(t):(await this.clearLicense(),false)}async setLicenseKey(e,t){if(!e||e.trim().length===0)return this.state.error="License key is required",this.state.errorKind="verdict",false;let i=b(e),r=++this.generation;if(this.cancelRetry(),t?.isRetry||(this.retryAttempt=0),this.state.licenseKey!==i&&this.lock(),this.state.licenseKey=i,this.state.isValidating=true,this.state.error=null,this.state.errorKind=null,this.emit({type:"validating",isPro:this.isPro()}),he(i))return this.admitToken(i,r);if(z(i))return this.admitServiceKey(i,r);if(ve(i))return this.admitDevToken(i);if(!this.cachedLicense){let a=await w(this.loadCachedLicense(),null);if(r!==this.generation)return false;a?.licenseKey===i&&(this.cachedLicense=a,A(a)&&this.isCacheValid(a)&&(this.applyTier(E(a)),this.state.expiresAt=a.expiresAt?new Date(a.expiresAt):null,this.setVerifiedAt(a.cachedAt),this.emit({type:"validating",isPro:this.isPro()})))}let s=this.cachedLicense;if(!t?.force&&s&&s.valid&&s.licenseKey===i&&s.fingerprint&&A(s)&&this.isCacheValid(s)&&this.isCacheFresh(s))return this.applyTier(E(s)),this.state.licenseKey=i,this.state.isValidating=false,this.state.error=null,this.state.errorKind=null,this.state.expiresAt=s.expiresAt?new Date(s.expiresAt):null,this.setVerifiedAt(s.cachedAt),this.emit({type:"validated",isPro:this.state.isPro}),true;let n=await w(this.loadHold(),null);if(r!==this.generation)return false;let c=(n?.backoffUntil??0)-h();if(c>0)return this.standDown(i,r,"License server is rate limited; retrying later.",c);if(!t?.force&&n?.key===i&&n.verdictAt!==void 0&&h()-n.verdictAt>=0&&h()-n.verdictAt<Ce)return this.lock(),this.state.isValidating=false,this.state.error=n.detail||"License could not be verified",this.state.errorKind="verdict",this.emit({type:"error",isPro:false,error:this.state.error}),false;let o;try{o=await Ue(i)}catch(a){let l=a instanceof Error?a.message:"Validation failed";if(r!==this.generation)return false;if(Q(a)){if(Ke(a)){let u=Math.min(Oe(a,q,Ne)*2**this.retryAttempt,q);return this.retryAttempt+=1,await this.saveHold({...this.hold,backoffUntil:h()+u}),r!==this.generation?false:this.standDown(i,r,l,u)}return this.state.isValidating=false,this.cachedLicense&&this.cachedLicense.licenseKey===i&&A(this.cachedLicense)&&this.isCacheValid(this.cachedLicense)?(this.applyTier(E(this.cachedLicense)),this.state.error=null,this.state.errorKind=null,this.state.expiresAt=this.cachedLicense.expiresAt?new Date(this.cachedLicense.expiresAt):null,this.setVerifiedAt(this.cachedLicense.cachedAt),this.keyTier()!=="pro"&&this.scheduleRetry(i),this.emit({type:"validated",isPro:this.state.isPro}),true):(this.state.error=l,this.state.errorKind="transport",this.scheduleRetry(i),this.emit({type:"error",isPro:this.state.isPro,error:l}),false)}return this.state.isValidating=false,this.state.error=l,this.state.errorKind="verdict",this.emit({type:"error",isPro:false,error:l}),false}try{if(r!==this.generation)return false;let a=je(o),l=o.data?.relationships?.product?.data?.id;if((!l||l===I.productId)&&a.code==="EXPIRED"&&(ct(o.data)||this.cachedLicense?.licenseKey===i&&A(this.cachedLicense)&&this.isCacheValid(this.cachedLicense))){let O=h(),W=await this.saveCache({licenseKey:i,licenseId:o.data?.id??"",valid:true,isPro:false,tier:"free",expiresAt:null,cachedAt:O,lastValidatedAt:O,fingerprint:this.cachedLicense?.licenseKey===i?this.cachedLicense.fingerprint:void 0},r);return r!==this.generation||!W?false:(this.cachedLicense=W,this.applyTier("free"),this.state.isValidating=false,this.state.expiresAt=null,this.setVerifiedAt(O),this.emit({type:"validated",isPro:false}),true)}if(He(a.code)||!Fe(o))return this.lock(),this.state.isValidating=false,this.state.error=a.detail||"License could not be verified",this.state.errorKind="verdict",this.emit({type:"error",isPro:false,error:this.state.error}),await this.clearCachedLicense(),await this.saveHold({key:i,code:a.code,detail:this.state.error,verdictAt:h()}),false;if(!o.data)return this.lock(),this.state.isValidating=false,this.state.error=a.detail||"License not found",this.state.errorKind="verdict",this.emit({type:"error",isPro:false,error:this.state.error}),await this.clearCachedLicense(),false;let u=lt(o.data),f=o.data.id,P=h(),G=$e(o)>=Pe,J=F(),Ae=J&&!G,_e=u==="free"&&(G||!J),v=this.cachedLicense?.fingerprint,x=this.cachedLicense?.deviceName,Y=false;if(!v){if(v=await w(this.getOrCreateDeviceFingerprint(),U()),r!==this.generation)return false;x=$(),Y=Ae}let S=false;Y&&(this.deviceRegistrationCallback?(this.pendingRegistration={licenseId:f,licenseKey:i,fingerprint:v},this.deviceRegistrationCallback({fingerprint:v,defaultName:x}),S=true):this.registerDeviceAsync(f,i,v,x));let K={licenseKey:i,licenseId:f,valid:true,isPro:u==="pro",tier:u,expiresAt:o.data.attributes.expiry??null,cachedAt:P,lastValidatedAt:P,fingerprint:S?void 0:v,deviceName:S?void 0:x,quiet:_e||void 0},X=await this.saveCache(K,r);return r!==this.generation||!X||(this.cachedLicense=X,this.applyTier(u),this.state.isValidating=false,this.state.expiresAt=K.expiresAt?new Date(K.expiresAt):null,this.setVerifiedAt(P),this.hold&&await this.saveHold(null),r!==this.generation)?false:(this.retryAttempt=0,this.emit({type:"validated",isPro:this.state.isPro}),true)}catch(a){let l=a instanceof Error?a.message:"Validation failed";return r!==this.generation||(this.state.isValidating=false,this.state.error=l,this.state.errorKind="verdict",this.emit({type:"error",isPro:false,error:l})),false}}scheduleRetry(e){this.cancelRetry();let t=Re[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 p<"u"&&p&&(globalThis.__LICENSE_MANAGER_RETRY_TIMER__=this.retryTimer)}async admitServiceKey(e,t){let i=await Kt(e,{origin:k.origin});if(t!==this.generation)return false;if(!i.ok)return this.lock(),this.state.isValidating=false,this.state.error=i.detail,this.state.errorKind=i.reason==="network"?"transport":"verdict",this.emit({type:"error",isPro:false,error:i.detail}),i.reason==="network"&&this.scheduleRetry(e),false;let r=i.claims.exp*1e3;return this.applyTier(i.claims.tier==="free"?"free":"pro"),this.state.isValidating=false,this.state.expiresAt=new Date(r),this.setVerifiedAt(h()),this.retryAttempt=0,this.scheduleRetryIn(e,Math.max(6e4,r-3600*1e3-h())),this.emit({type:"validated",isPro:this.isPro()}),true}admitDevToken(e){let t=Te(e);if(!t.ok||!F()){let r=t.ok?Mt:t.message;return this.lock(),this.state.isValidating=false,this.state.error=r,this.state.errorKind="verdict",this.emit({type:"error",isPro:false,error:r}),false}let i=h();return this.applyTier(t.claims.tier==="free"?"free":"pro"),this.state.isValidating=false,this.state.expiresAt=new Date(t.claims.exp*1e3),this.setVerifiedAt(Math.min(i,t.claims.iat*1e3)),this.retryAttempt=0,this.emit({type:"validated",isPro:this.isPro()}),true}async admitToken(e,t){let i=ot(e);if(t!==this.generation)return false;if(!i)return this.lock(),this.state.isValidating=false,this.state.error="This key is not valid. Check that it was copied completely.",this.state.errorKind="verdict",this.emit({type:"error",isPro:false,error:this.state.error}),await this.clearCachedLicense(),false;let r=h(),s=this.cachedLicense?.fingerprint??await w(this.getOrCreateDeviceFingerprint(),U());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??$(),quiet:true},t);return t!==this.generation||!n?false:(this.cachedLicense=n,this.applyTier("free"),this.state.isValidating=false,this.state.expiresAt=null,this.setVerifiedAt(r),this.retryAttempt=0,this.emit({type:"validated",isPro:false}),true)}standDown(e,t,i,r){if(t!==this.generation)return false;this.state.isValidating=false;let s=this.cachedLicense;return s&&s.licenseKey===e&&A(s)&&this.isCacheValid(s)?(this.applyTier(E(s)),this.state.error=null,this.state.errorKind=null,this.state.expiresAt=s.expiresAt?new Date(s.expiresAt):null,this.setVerifiedAt(s.cachedAt),this.keyTier()!=="pro"&&this.scheduleRetryIn(e,r),this.emit({type:"validated",isPro:this.state.isPro}),true):(this.state.error=i,this.state.errorKind="transport",this.scheduleRetryIn(e,r),this.emit({type:"error",isPro:this.state.isPro,error:i}),false)}scheduleRetryIn(e,t){this.cancelRetry();let i=this.generation;this.retryTimer=setTimeout(()=>{this.retryTimer=null,i===this.generation&&(this.state.isValidating||this.setLicenseKey(e,{force:true,isRetry:true}))},Math.max(1,Math.min(t,2147483647))),typeof p<"u"&&p&&(m.__LICENSE_MANAGER_RETRY_TIMER__=this.retryTimer)}cancelRetry(){this.retryTimer&&(clearTimeout(this.retryTimer),this.retryTimer=null)}async clearLicense(){this.generation+=1,this.cancelRetry(),this.retryAttempt=0,this.configuredKey=null,this.state.licenseKey=null,this.lock(),this.state.expiresAt=null,this.state.error=null,this.state.errorKind=null,this.cachedLicense=null,this.pendingRegistration=null,this.state.isValidating=false,this.emit({type:"deactivated",isPro:false}),await this.clearCachedLicense(),this.hold?.verdictAt!==void 0&&await this.saveHold(this.hold.backoffUntil?{backoffUntil:this.hold.backoffUntil}:null)}applyTier(e){this.state.tier=e,this.state.tierSource="key",this.state.isPro=e==="pro"}lock(){this.state.tier="free",this.state.tierSource="none",this.state.isPro=false,this.verifiedAt=null,this.expiryTimer&&clearTimeout(this.expiryTimer),this.expiryTimer=null}getTier(){return this.credential().tier}credential(){let e=this.keyTier(),t=this.sessionTier();return t!==null&&(!this.hasKeyAccess()||t==="pro"&&e!=="pro")?{source:"session",tier:t}:{source:this.state.tierSource,tier:e}}keyTier(){return!this.hasKeyAccess()||this.state.expiresAt&&h()>=this.state.expiresAt.getTime()?"free":this.state.tier}sessionTier(){let e=k.getStatus();return e.state!=="active"?null:e.claims.tier==="free"?"free":"pro"}isPro(){return this.getTier()==="pro"}hasEntitlement(e){return this.isPro()}getState(){let{source:e,tier:t}=this.credential();return{...this.state,tier:t,tierSource:e,isPro:t==="pro",access:this.getAccountAccess()}}getAccountAccess(){let e=this.getKeyAccess();if(e.status==="admitted")return e;let t=k.getStatus();return t.state==="active"?{status:"admitted",reason:null,validUntil:t.validUntil}:e}getKeyAccess(){return de({initialized:this.state.isInitialized,validating:this.state.isValidating,key:this.state.licenseKey,tierSource:this.state.tierSource,verifiedAt:this.verifiedAt})}hasAccountAccess(){return this.getAccountAccess().status==="admitted"}hasKeyAccess(){return this.getKeyAccess().status==="admitted"}setVerifiedAt(e){this.verifiedAt=e,this.expiryTimer&&clearTimeout(this.expiryTimer);let t=e+N,i=this.state.expiresAt?.getTime(),r=(i&&i>h()?Math.min(t,i):t)-h();this.expiryTimer=setTimeout(()=>{this.expiryTimer=null,this.verifiedAt===e&&(this.emit({type:"validated",isPro:this.isPro()}),h()<t&&this.setVerifiedAt(e))},Math.max(1,Math.min(r,2147483647))),typeof p<"u"&&p&&(m.__LICENSE_MANAGER_EXPIRY_TIMER__=this.expiryTimer)}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}onDeviceRegistrationNeeded(e){return this.deviceRegistrationCallback=e,()=>{this.deviceRegistrationCallback=null}}async completeDeviceRegistration(e){if(!this.pendingRegistration){console.warn("[Buoy] No pending device registration");return}let{licenseId:t,licenseKey:i,fingerprint:r}=this.pendingRegistration,s=this.generation,n=e.trim()||$(),c=se();try{await te(t,i,r,n,c)}catch(o){let a=o instanceof Error?o.message:String(o);if(!(a==="FINGERPRINT_TAKEN"||a==="MACHINE_LIMIT_EXCEEDED"))throw console.warn("[Buoy] Device registration failed:",a),o}if(s===this.generation){if(this.cachedLicense?.licenseKey===i){let o=await this.saveCache({...this.cachedLicense,fingerprint:r,deviceName:n},s);if(s!==this.generation)return;o&&(this.cachedLicense=o)}this.pendingRegistration=null}}emit(e){[...this.listeners].forEach(t=>{try{t(e)}catch(i){console.warn("[React Buoy] License listener error:",i)}})}isCacheValid(e){let t=h()-e.cachedAt;return!(!e.valid||!Number.isFinite(e.cachedAt)||t<0||t>=N)}isCacheFresh(e){let t=this.isQuiet(e)?Se:Ie;return h()-(e.lastValidatedAt??0)<t}isQuiet(e){return e.quiet!==void 0?e.quiet:E(e)==="free"&&!F()}async loadHold(){if(this.hold!==void 0)return this.hold;try{let e=await(await y()).getItem(D),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 y();e?await t.setItem(D,JSON.stringify(e)):await t.removeItem(D)}catch{}}async persistCache(e){let t=le(e);return await(await y()).setItem(M,JSON.stringify(t)),t}saveCache(e,t){let i=this.persistence.catch(()=>{}).then(async()=>{if(t!==this.generation)return null;let r=await this.persistCache(e);return t===this.generation?r:null});return this.persistence=i,w(i,le(e))}async loadCachedLicense(){try{await this.persistence.catch(()=>{});let e=await(await y()).getItem(M);return e?JSON.parse(e):null}catch(e){return console.warn("[Buoy] Error loading cached license:",e),null}}getOrCreateDeviceFingerprint(){return this.fingerprintPromise||(this.fingerprintPromise=(async()=>{let e=await y(),t=await e.getItem(V);if(t)return t;let i=this.cachedLicense?.fingerprint||U();return await e.setItem(V,i),i})()),this.fingerprintPromise}async clearCachedLicense(){this.cachedLicense=null;let e=this.persistence.catch(()=>{}).then(async()=>{await(await y()).removeItem(M)});this.persistence=e,await w(e.catch(()=>{}),void 0)}registerDeviceAsync(e,t,i,r){let s=se();te(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=ht(()=>this.refreshAccess()),typeof p<"u"&&p&&(m.__LICENSE_MANAGER_FOREGROUND_OFF__=this.removeForegroundListener)),this.revalidationTimer&&clearInterval(this.revalidationTimer),this.revalidationTimer=setInterval(()=>{if(!this.state.licenseKey||this.state.isValidating)return;let e=this.cachedLicense;e&&e.licenseKey===this.state.licenseKey&&this.isCacheFresh(e)||this.validateInBackground(this.state.licenseKey)},Le),typeof p<"u"&&p&&(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 y()).removeItem(V)}catch{}}},Dt=new Vt,m=globalThis;typeof p<"u"&&p&&(m.__LICENSE_MANAGER_FOREGROUND_OFF__?.(),m.__LICENSE_MANAGER_FOREGROUND_OFF__=void 0,m.__LICENSE_MANAGER_EXPIRY_TIMER__&&clearTimeout(m.__LICENSE_MANAGER_EXPIRY_TIMER__),m.__LICENSE_MANAGER_TIMER__&&clearInterval(m.__LICENSE_MANAGER_TIMER__),m.__LICENSE_MANAGER_RETRY_TIMER__&&(clearTimeout(m.__LICENSE_MANAGER_RETRY_TIMER__),m.__LICENSE_MANAGER_RETRY_TIMER__=void 0));export{h as a,T as b,Q as c,he as d,de as e,d as f,k as g,z as h,b as i,St as j,ve as k,Te as l,Dt as m};/*!
|
|
2
|
+
* PROPRIETARY — Buoy Pro license enforcement. NOT open source.
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) Buoy. All rights reserved. Licensed under the Buoy EULA
|
|
5
|
+
* (https://buoy.gg/terms), not an OSS license.
|
|
6
|
+
*
|
|
7
|
+
* This file configures the technological measure that controls access to paid
|
|
8
|
+
* Buoy Pro features. Modifying, patching, aliasing, stubbing, or otherwise
|
|
9
|
+
* altering it — including repointing `apiUrl` at a stand-in license server — so
|
|
10
|
+
* that Pro features unlock without a valid license is a breach of the EULA and,
|
|
11
|
+
* in the United States, circumvention of an access control under 17 U.S.C.
|
|
12
|
+
* § 1201, which applies whether or not any code is copied.
|
|
13
|
+
*
|
|
14
|
+
* Pro is $9/mo, and is free every weekend for anyone holding a key —
|
|
15
|
+
* including a free one (`npx buoy login`). Buy a key at
|
|
16
|
+
* https://buoy.gg or use it free on Saturday and Sunday.
|
|
17
|
+
*//*!
|
|
18
|
+
* PROPRIETARY — Buoy Pro license enforcement. NOT open source.
|
|
19
|
+
*
|
|
20
|
+
* Copyright (c) Buoy. All rights reserved. Licensed under the Buoy EULA
|
|
21
|
+
* (https://buoy.gg/terms), not an OSS license.
|
|
22
|
+
*
|
|
23
|
+
* This file is part of the technological measure that controls access to paid
|
|
24
|
+
* Buoy Pro features. Modifying, patching, aliasing, stubbing, or otherwise
|
|
25
|
+
* altering it so that Pro features unlock without a valid license is a breach
|
|
26
|
+
* of the EULA and, in the United States, circumvention of an access control
|
|
27
|
+
* under 17 U.S.C. § 1201 — which applies whether or not any code is copied.
|
|
28
|
+
*
|
|
29
|
+
* Pro is $9/mo, and is free every weekend for anyone holding a key —
|
|
30
|
+
* including a free one (`npx buoy login`). Buy a key at
|
|
31
|
+
* https://buoy.gg or use it free on Saturday and Sunday.
|
|
32
|
+
*//*!
|
|
33
|
+
* PROPRIETARY — Buoy Pro license enforcement. NOT open source.
|
|
34
|
+
*
|
|
35
|
+
* Copyright (c) Buoy. All rights reserved. Licensed under the Buoy EULA
|
|
36
|
+
* (https://buoy.gg/terms), not an OSS license.
|
|
37
|
+
*//*!
|
|
38
|
+
* PROPRIETARY — Buoy Pro license enforcement. NOT open source.
|
|
39
|
+
*
|
|
40
|
+
* Copyright (c) Buoy. All rights reserved. Licensed under the Buoy EULA
|
|
41
|
+
* (https://buoy.gg/terms), not an OSS license.
|
|
42
|
+
*
|
|
43
|
+
* This file is part of the technological measure that controls access to paid
|
|
44
|
+
* Buoy Pro features: it decides which tier a validated key grants. Modifying,
|
|
45
|
+
* patching, aliasing, stubbing, or otherwise altering it so that Pro features
|
|
46
|
+
* unlock without a valid license is a breach of the EULA and, in the United
|
|
47
|
+
* States, circumvention of an access control under 17 U.S.C. § 1201 — which
|
|
48
|
+
* applies whether or not any code is copied.
|
|
49
|
+
*
|
|
50
|
+
* Pro is $9/mo, and is free every weekend for anyone holding a key —
|
|
51
|
+
* including a free one (`npx buoy login`). Buy a key at
|
|
52
|
+
* https://buoy.gg or use it free on Saturday and Sunday.
|
|
53
|
+
*//*!
|
|
54
|
+
* PROPRIETARY — Buoy license enforcement. NOT open source.
|
|
55
|
+
*
|
|
56
|
+
* Copyright (c) Buoy. All rights reserved. Licensed under the Buoy EULA
|
|
57
|
+
* (https://buoy.gg/terms), not an OSS license.
|
|
58
|
+
*//*!
|
|
59
|
+
* PROPRIETARY — Buoy Pro license enforcement. NOT open source.
|
|
60
|
+
*
|
|
61
|
+
* Copyright (c) Buoy. All rights reserved. Licensed under the Buoy EULA
|
|
62
|
+
* (https://buoy.gg/terms), not an OSS license.
|
|
63
|
+
*
|
|
64
|
+
* This file is the technological measure that controls access to paid Buoy Pro
|
|
65
|
+
* features. Modifying, patching, aliasing, stubbing, or otherwise altering it
|
|
66
|
+
* so that Pro features unlock without a valid license is a breach of the EULA
|
|
67
|
+
* and, in the United States, circumvention of an access control under
|
|
68
|
+
* 17 U.S.C. § 1201 — which applies whether or not any code is copied.
|
|
69
|
+
*
|
|
70
|
+
* Pro is $9/mo, and is free every weekend for anyone holding a key —
|
|
71
|
+
* including a free one (`npx buoy login`). Buy a key at
|
|
72
|
+
* https://buoy.gg or use it free on Saturday and Sunday.
|
|
73
|
+
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";var l=(()=>{try{let t=globalThis.Capacitor;if(t&&typeof t.isNativePlatform=="function"&&t.isNativePlatform())return t.DEBUG===true}catch{}return process.env.NODE_ENV!=="production"})();typeof window<"u"&&typeof globalThis.global>"u"&&(globalThis.global=globalThis);function r(){let t=globalThis.Capacitor;return t&&typeof t=="object"?t:null}function o(){try{return r()?.isNativePlatform?.()===true}catch{return false}}function a(){if(!o())return null;try{let t=r()?.getPlatform?.();return t==="ios"||t==="android"?t:null}catch{return null}}function n(){return o()?r()?.DEBUG===true:null}function e(t){return n()??t}export{l as a,o as b,a as c,n as d,e};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";import{b as B}from"./chunk-J7MW3NXU.mjs";var R="__BUOY_CAPACITOR_BRIDGE__",M=300;function P(){let e=globalThis.Capacitor;return e&&typeof e=="object"?e:null}function d(){let e=globalThis,t=e[R];return(!t||t.version!==1)&&(t={version:1,originalPromise:null,originalCallback:null,wrappedPromise:null,wrappedCallback:null,interceptors:[],listeners:new Map,log:[],subscribers:new Set,seq:0,fakeIds:0},e[R]=t),t}function y(){let e=globalThis.__buoyRealNow;return typeof e=="function"?e():Date.now()}function L(e){return e&&typeof e=="object"?e:{}}function w(e){for(let t of Array.from(e.subscribers))try{t()}catch{}}function A(e,t){let r={seq:++e.seq,...t};return e.log.push(r),e.log.length>M&&e.log.splice(0,e.log.length-M),w(e),r}function U(e,t,r){return e.interceptors.filter(n=>(n.plugin==="*"||n.plugin===t.plugin)&&(!n.methods||n.methods.includes(t.method))&&typeof n[r]=="function").map((n,i)=>({interceptor:n,index:i})).sort((n,i)=>(i.interceptor.order??0)-(n.interceptor.order??0)||n.index-i.index).map(n=>n.interceptor)}function C(e,t){return`${e}:${String(t)}`}function G(){return`buoy-${++d().fakeIds}`}function W(e={}){if(!B())return false;let t=P();if(!t||typeof t.nativePromise!="function"||typeof t.nativeCallback!="function")return false;let r=d();if(r.wrappedPromise&&t.nativePromise===r.wrappedPromise&&t.nativeCallback===r.wrappedCallback)return true;if(t.DEBUG!==true&&e.release!==true)return false;r.originalPromise=t.nativePromise,r.originalCallback=t.nativeCallback;let n=r.originalPromise,i=r.originalCallback,l=(o,s,h,k)=>{let p={plugin:o,method:s,options:L(h)},m=U(r,p,"promise"),u=f=>{if(f>=m.length){if(k(),s==="removeAllListeners")for(let v of Array.from(r.listeners.keys()))v.startsWith(`${o}:`)&&r.listeners.delete(v);return n.call(t,o,s,h)}try{return Promise.resolve(m[f].promise(p,()=>u(f+1)))}catch(v){return Promise.reject(v)}};return u(0)};r.runPromise=l;let a=(o,s,h)=>{let k=A(r,{plugin:o,method:s,kind:"promise",options:L(h),start:y()}),p=false,m=l(o,s,h,()=>{p=true});return m.then(u=>{Object.assign(k,{end:y(),ok:true,result:u,answeredByBuoy:!p}),w(r)},u=>{Object.assign(k,{end:y(),ok:false,error:u,answeredByBuoy:!p}),w(r)}),m},b=(o,s,h,k)=>{let p=h,m=k;typeof p=="function"&&(m=p,p=null);let u={plugin:o,method:s,options:L(p)},f=A(r,{plugin:o,method:s,kind:"callback",options:u.options,start:y(),events:0}),v=false,j=U(r,u,"callback"),E=(g,c)=>g>=j.length?(v=true,i.call(t,o,s,p,c)):j[g].callback(u,c,_=>E(g+1,_)),x=s==="addListener",S=E(0,(g,c)=>{if(f.events=(f.events??0)+1,!x&&f.end===void 0)f.end=y(),f.ok=!c,c?f.error=c:f.result=g,w(r);else{let _=y();A(r,{plugin:o,method:x?String(u.options.eventName??"event"):s,kind:"event",options:{},start:_,end:_,ok:!c,...c?{error:c}:{result:g}})}m?.(g,c)});if(f.answeredByBuoy=!v,s==="addListener"&&S!=null&&typeof m=="function"){let g=C(o,u.options.eventName),c=r.listeners.get(g);c||r.listeners.set(g,c=new Map),c.set(String(S),m)}else s==="removeListener"&&r.listeners.get(C(o,u.options.eventName))?.delete(String(u.options.callbackId));return S};return t.nativePromise=a,t.nativeCallback=b,r.wrappedPromise=a,r.wrappedCallback=b,Q(),true}var J=/^\s*\(\s*prefers-color-scheme\s*:\s*(dark|light)\s*\)\s*$/i,I="__BUOY_COLOR_SCHEME_QUERIES__";function q(e){let t=J.exec(e);return t?t[1].toLowerCase():null}function Q(){let e=globalThis,t=globalThis.WeakRef;if(e[I]||typeof e.matchMedia!="function"||!t)return;let r=[];e[I]=r;let n=e.matchMedia;e.matchMedia=function(i){let l=n.call(this??globalThis,i);if(l&&q(String(i))){for(let a=r.length-1;a>=0;a--)r[a].deref()||r.splice(a,1);r.push(new t(l))}return l}}function V(){let e=globalThis[I];return e?e.map(t=>t.deref()).filter(t=>!!t):[]}function D(){let e=P(),t=d();return!!(t.wrappedPromise&&e?.nativePromise===t.wrappedPromise)}function z(e){let t=d();return t.interceptors.push(e),()=>{let r=t.interceptors.indexOf(e);r>=0&&t.interceptors.splice(r,1)}}function F(e,t,r){let n=d().listeners.get(C(e,t));if(!n)return 0;let i=0;for(let l of Array.from(n.values()))try{l(r),i++}catch(a){globalThis.console?.error(a)}return i}function X(e,t){return d().listeners.get(C(e,t))?.size??0}function H(e){return P()?.PluginHeaders?.find(t=>t.name===e)}function N(e){if(!B())return false;try{return!!H(e)||P()?.isPluginAvailable?.(e)===true}catch{return false}}function $(){let e=P(),t=d();return{cap:e,promise:t.originalPromise??e?.nativePromise??null,callback:t.originalCallback??e?.nativeCallback??null}}function T(e,t,r={}){let{cap:n,promise:i}=$();return!n||!i?Promise.reject(new Error("Capacitor bridge unavailable")):i.call(n,e,t,r)}function Z(e,t,r={}){let n=d().runPromise;return n&&D()?n(e,t,r,()=>{}):T(e,t,r)}function K(e,t,r,n){let{cap:i,callback:l}=$();return!i||!l?null:l.call(i,e,t,r,n)}function Y(e,t,r){let{cap:n,promise:i,callback:l}=$();if(!n||!l)return Promise.reject(new Error("Capacitor bridge unavailable"));let a=l.call(n,e,"addListener",{eventName:t},o=>r(o)),b=async()=>{if(a==null)return;let o={eventName:t,callbackId:a};H(e)?.methods?.find(s=>s.name==="removeListener")?.rtype==="promise"&&i?await i.call(n,e,"removeListener",o):l.call(n,e,"removeListener",o,()=>{})};return Promise.resolve({remove:b})}function ee(){return d().log}function te(){let e=d();e.log.length=0,w(e)}function re(e){let t=d();return t.subscribers.add(e),()=>{t.subscribers.delete(e)}}var ne=new Set(["then","catch","finally","$$typeof","toJSON","constructor"]);function ie(e){return N(e)?new Proxy({},{get(t,r){if(!(typeof r!="string"||ne.has(r)))return r==="addListener"?(n,i)=>Y(e,n,i):n=>T(e,r,n??{})}}):null}var O="__BUOY_CAPACITOR_HOST__";function le(){if(!B())return Promise.resolve(null);let e=globalThis,t=e[O];if(t)return t;let r=l=>typeof l=="string"&&l?l:null,n=async l=>{if(!N(l))return{};try{return await T(l,"getInfo")??{}}catch{return{}}},i=Promise.all([n("App"),n("Device")]).then(([l,a])=>{let b={isSimulator:typeof a.isVirtual=="boolean"?a.isVirtual:null,deviceName:r(a.name),bundleId:r(l.id),appName:r(l.name)};return e[`${O}_value`]=b,b});return e[O]=i,i}function oe(){return globalThis[`${O}_value`]??null}export{G as a,W as b,q as c,V as d,D as e,z as f,F as g,X as h,N as i,T as j,Z as k,K as l,Y as m,ee as n,te as o,re as p,ie as q,le as r,oe as s};
|
package/lib/web/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use client";import{a as
|
|
1
|
+
"use client";import{a as k,b as S,c as y,d as A,e as L,f as b,g as P,h as v,i as h,j as I,k as E,l as K,m as z,n as w,o as T,p as B,q as D,r as F,s as N}from"./chunks/chunk-UPTHA45A.mjs";import{a as M,b as W,c as j,d as H,e as O,f as Q,g as n,h as V,i as q,j as x,k as f,l as G,m as t}from"./chunks/chunk-3JAIQNSD.mjs";import{b as J,c as R,d as U,e as X}from"./chunks/chunk-J7MW3NXU.mjs";import{useEffect as Y,useState as Z}from"react";function l(s=new Date(M())){let e=s.getDay();return e===0||e===6}function p(){let[s,e]=Z(()=>l());return Y(()=>{let r=setInterval(()=>{let a=l();e(i=>i===a?i:a)},6e4);return()=>clearInterval(r)},[]),s}function g(s,e){return e&&s}import{useState as d,useEffect as C,useCallback as u}from"react";function c(){let[s,e]=d(t.getState());C(()=>{let i=t.subscribe(o=>{e(t.getState())});return t.initialize().then(()=>{e(t.getState())}),i},[]);let r=u(async i=>{let o=await t.setLicenseKey(i,{force:true});return e(t.getState()),o},[]),a=u(async()=>{await t.clearLicense(),e(t.getState())},[]);return{...s,setLicenseKey:r,clearLicense:a}}function _(){return c().access}function $(){let{tier:s,isInitialized:e}=c();return e?s:"free"}function ee(s){let{isPro:e,isInitialized:r,isValidating:a}=c();return{hasAccess:e,isPro:e,isLoading:!r||a}}function se(){let{isPro:s,isInitialized:e,access:r}=c(),a=g(r.status==="admitted",p());return e&&s||a}function ae(){let{isPro:s,isInitialized:e,access:r}=c(),a=e&&s,i=g(r.status==="admitted",p())&&!a;return{isPro:a||i,isLicensed:a,isWeekendFree:i,reason:a?"licensed":i?"weekend":null}}function te(){let[s,e]=d(()=>n.getStatus());C(()=>{let i=()=>e(n.getStatus()),o=n.subscribe(i);return n.load().then(i,i),o},[]);let r=u(()=>n.signIn(),[]),a=u(()=>n.signOut(),[]);return{status:s,signIn:r,signOut:a}}function ie(){let s=n.getAccessToken();if(s)return{token:s,origin:n.origin};let e=t.getState().licenseKey;return e&&f(e)&&t.hasAccountAccess()&&G(e).ok?{token:e,origin:n.origin}:null}async function re(s){let{LicenseManager:e}=await import("./chunks/LicenseManager-X7ZLSRCH.mjs");return await e.initialize(),e.setLicenseKey(s)}function m(){return g(t.hasAccountAccess(),l())}function ne(){return t.isPro()?true:m()}function ce(s){return t.hasEntitlement(s)?true:m()}export{t as LicenseManager,W as LicenseTransportError,Q as SessionError,n as SessionManager,E as callCapacitorAsApp,I as callCapacitorNative,K as callCapacitorNativeCallback,U as capacitorDebug,v as capacitorListenerCount,R as capacitorPlatform,D as capacitorPlugin,T as clearCapacitorCalls,y as colorSchemeQueryValue,P as emitCapacitorEvent,N as getCapacitorAppHost,w as getCapacitorCalls,A as getColorSchemeQueries,ie as getSyncCredential,h as hasCapacitorPlugin,ce as hasEntitlement,S as installCapacitorBridge,b as interceptCapacitor,H as isBuoyToken,L as isCapacitorBridgeInstalled,J as isCapacitorNative,f as isDevToken,ne as isPro,V as isServiceKey,j as isTransientLicenseError,l as isWeekendFreePro,z as listenCapacitorNative,F as loadCapacitorAppHost,k as makeCapacitorCallbackId,q as normalizeLicenseKey,O as resolveAccountAccess,X as resolveDevBuild,x as sameLicenseKey,re as setLicenseKey,B as subscribeCapacitorCalls,_ as useAccountAccess,te as useBuoySession,ee as useFeatureAccess,se as useIsPro,c as useLicense,ae as useProAccess,$ as useTier,p as useWeekendFreePro};/*!
|
|
2
2
|
* PROPRIETARY — Buoy Pro license enforcement. NOT open source.
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Buoy. All rights reserved. Licensed under the Buoy EULA
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@buoy-gg/license",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.57",
|
|
4
4
|
"description": "License validation for React Buoy Pro features",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"main": "lib/commonjs/index.js",
|
|
@@ -35,9 +35,27 @@
|
|
|
35
35
|
"default": "./lib/commonjs/headless.js"
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
|
+
"./capacitor": {
|
|
39
|
+
"browser": {
|
|
40
|
+
"types": "./lib/typescript/module/capacitorBridge.d.ts",
|
|
41
|
+
"default": "./lib/web/capacitor.mjs"
|
|
42
|
+
},
|
|
43
|
+
"import": {
|
|
44
|
+
"types": "./lib/typescript/module/capacitorBridge.d.ts",
|
|
45
|
+
"default": "./lib/module/capacitorBridge.js"
|
|
46
|
+
},
|
|
47
|
+
"require": {
|
|
48
|
+
"types": "./lib/typescript/commonjs/capacitorBridge.d.ts",
|
|
49
|
+
"default": "./lib/commonjs/capacitorBridge.js"
|
|
50
|
+
}
|
|
51
|
+
},
|
|
38
52
|
"./web": {
|
|
39
53
|
"types": "./lib/typescript/module/index.web.d.ts",
|
|
40
54
|
"default": "./lib/web/index.mjs"
|
|
55
|
+
},
|
|
56
|
+
"./web/capacitor": {
|
|
57
|
+
"types": "./lib/typescript/module/capacitorBridge.d.ts",
|
|
58
|
+
"default": "./lib/web/capacitor.mjs"
|
|
41
59
|
}
|
|
42
60
|
},
|
|
43
61
|
"files": [
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use client";import{m as e}from"./chunk-FPGC7BWV.mjs";export{e as LicenseManager};
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use client";var p=process.env.NODE_ENV!=="production";typeof window<"u"&&typeof globalThis.global>"u"&&(globalThis.global=globalThis);var L=new Map,Ee={async getItem(e){try{return localStorage.getItem(e)??L.get(e)??null}catch{return L.get(e)??null}},async setItem(e,t){L.set(e,t);try{localStorage.setItem(e,t)}catch{}},async removeItem(e){L.delete(e);try{localStorage.removeItem(e)}catch{}}};async function y(){return Ee}var I={accountId:"b0eba0e8-e904-4906-b644-38f9aab57bed",productId:"bf67cb43-eeef-40ca-b308-e6e1b22c0eaa",apiUrl:"https://buoy.gg/api/license"},ke="3b546fc717a62683f3236c70167899a271bee3ffc04df6ec1eea60a394a2f1e9",be="36abba0267f7f379d992a5b6df641daab4190bcc9e639e36f1378e3c1ac52746",R={free:"394e3351-1249-4f73-807a-703408604c0e",solo:"fa5d3c8f-5379-40f1-b63e-ab8a974b2f28",business:"690c2212-8e54-426f-b4b4-002ee1c0ae2b"},N=720*60*60*1e3,xe=1440*60*1e3,M="buoy-gg-license",V="buoy-gg-device-fingerprint",Le=3600*1e3,Ie=[5*1e3,20*1e3,60*1e3,300*1e3,900*1e3],Re=60*1e3,q=3600*1e3,Ne=1440*60*1e3,Ce=50,Pe=N,D="buoy-gg-license-hold";function h(){let e=globalThis.__buoyRealNow;return typeof e=="function"?e():Date.now()}var{apiUrl:Z}=I,T=class extends Error{constructor(e,t,i=null){super(e);this.isTransient=true;this.name="LicenseTransportError",this.status=t,this.retryAfterMs=i}};function Se(e){let t=e?.status;return t===429||t===402}function Ke(e,t,i){return e.status===402?t:e.retryAfterMs??i}function Oe(e){let t=s=>{try{return e.headers?.get?.(s)??null}catch{return null}},i=t("Retry-After");if(i){let s=Number(i);if(Number.isFinite(s)&&s>=0)return s*1e3;let n=Date.parse(i);if(Number.isFinite(n))return Math.max(0,n-h())}let r=Number(t("X-RateLimit-Reset"));return Number.isFinite(r)&&r>0?Math.max(0,r*1e3-h()):null}function Q(e){return e instanceof T||e instanceof TypeError?true:typeof e=="object"&&e!==null&&e.isTransient===true}async function Me(e){try{return(await e.json()).errors?.[0]?.detail||`HTTP ${e.status}`}catch{return`HTTP ${e.status}`}}function ee(){return{"Content-Type":"application/vnd.api+json",Accept:"application/vnd.api+json"}}async function Ve(e,t){let i=`${Z}/validate`,r={meta:{key:e}},s;try{s=await fetch(i,{signal:t,method:"POST",headers:ee(),body:JSON.stringify(r)})}catch(n){throw new T(n instanceof Error?n.message:"Network request failed",null)}if(!s.ok)throw new T(await Me(s),s.status,s.status===429?Oe(s):null);try{let n=await s.json();if(!n||typeof n!="object"||typeof n.meta?.valid!="boolean"||typeof n.meta?.code!="string"||!n.meta.code)throw new Error("Missing license verdict");return n}catch{throw new T("License server returned an unreadable response",s.status)}}async function De(e){let t=typeof AbortController=="function"?new AbortController:null,i;try{return await Promise.race([Ve(e,t?.signal),new Promise((r,s)=>{i=setTimeout(()=>{s(new T("License verification timed out. Please retry.",null)),t?.abort()},15e3)})])}finally{i&&clearTimeout(i)}}function Ue(e){if(!e.data)return false;let t=e.data.relationships?.product?.data?.id;return t&&t!==I.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 Fe(e){let t=e.data?.relationships?.machines?.meta?.count;return typeof t=="number"&&Number.isFinite(t)?t:0}async function te(e,t,i,r,s){let n=`${Z}/machines`,c=await fetch(n,{method:"POST",headers:ee(),body:JSON.stringify({licenseId:e,licenseKey:t,fingerprint:i,name:r,metadata:s||{}})});if(!c.ok){let o=await c.json(),a=o.errors?.[0]?.code;if(a==="FINGERPRINT_TAKEN")throw new Error("FINGERPRINT_TAKEN");if(a==="MACHINE_LIMIT_EXCEEDED")throw new Error("MACHINE_LIMIT_EXCEEDED");let l=o.errors?.[0]?.detail||`HTTP ${c.status}`;throw new Error(l)}return c.json()}function $e(e){let{meta:t,data:i}=e;return{valid:t.valid,code:t.code,detail:t.detail,metadata:i?.attributes?.metadata}}function je(e){return["NOT_FOUND","SUSPENDED","EXPIRED","BANNED","PRODUCT_SCOPE_MISMATCH"].includes(e)}function U(){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 F(){if(typeof p<"u")return p;try{if(typeof navigator<"u"&&/electron/i.test(navigator.userAgent))return true}catch{}return typeof process<"u"&&process.env.NODE_ENV!=="production"}function ie(){if(typeof navigator>"u")return"unknown";let e=navigator.userAgent.toLowerCase(),t=navigator.platform?.toLowerCase()||"";return e.includes("electron")?t.includes("mac")||e.includes("mac")?"electron-macos":t.includes("win")||e.includes("win")?"electron-windows":t.includes("linux")||e.includes("linux")?"electron-linux":"electron":t.includes("mac")||e.includes("mac")?"macos":t.includes("win")||e.includes("win")?"windows":t.includes("linux")||e.includes("linux")?"linux":/iphone|ipad|ipod/.test(e)?"ios-web":e.includes("android")?"android-web":"web"}function He(){if(typeof navigator>"u")return"unknown";let e=navigator.userAgent,t=e.match(/Mac OS X ([\d_.]+)/);if(t)return t[1].replace(/_/g,".");let i=e.match(/Windows NT ([\d.]+)/);return i?{"10.0":"10/11","6.3":"8.1","6.2":"8","6.1":"7"}[i[1]]||i[1]:e.includes("Linux")?"Linux":"unknown"}function re(){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 se(){let e={platform:ie(),osVersion:He(),isSimulator:"false"},t=re();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 $(){let e=ie(),t=re();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 Be=["v1"],ze="buoy.gg/pro:9f3c1d7a4b2e:license-cache";function ne(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 Ge(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(ze),i.join("\0")}function ae(e,t){let i=Ge(e,t),r=ne(i,2166136261),s=ne(i,2135587861);return`${t}.${r.toString(16)}${s.toString(16)}`}function oe(e){return ae(e,"v2")}function le(e){return{...e,sig:oe(e)}}function A(e){return!e||typeof e.sig!="string"||e.sig.length===0?false:e.sig===oe(e)?true:Be.some(t=>e.sig.startsWith(`${t}.`)&&e.sig===ae(e,t))}import Je from"tweetnacl";var Ye=1,Xe=1,We="buoy-free-token-v1:",qe=22,Ze=64,ce=/^BUOY1-([A-Z2-7]+)-([A-Z2-7]+)$/;function he(e){return ce.test(e.trim().toUpperCase())}var Qe="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";function ue(e){let t=[],i=0,r=0;for(let s of e){let n=Qe.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 et(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 tt(e){let t="";for(let i of e)t+=i.toString(16).padStart(2,"0");return t}function it(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 rt(e,t){let i=new Uint8Array(e.length+t.length);return i.set(e,0),i.set(t,e.length),i}function st(e){return rt(it(We),e)}var nt=ke;function at(e,t=nt){let i=ce.exec(e.trim().toUpperCase());if(!i)return null;let r=ue(i[1]),s=ue(i[2]);if(!r||!s||r.length!==qe||s.length!==Ze||r[0]!==Ye||r[1]!==Xe)return null;try{if(!Je.sign.detached.verify(st(r),s,et(t)))return null}catch{return null}return{tier:"free",issuedAt:((r[2]<<24>>>0)+(r[3]<<16)+(r[4]<<8)+r[5])*1e3,accountHash:tt(r.slice(6,22))}}function ot(e){let t=e.relationships?.policy?.data?.id;return t===R.free?"free":t===R.solo||t===R.business?"pro":e.attributes?.metadata?.plan==="free"?"free":"pro"}function lt(e){if(!e)return false;let t=e.relationships?.product?.data?.id;if(t)return t===I.productId;let i=e.relationships?.policy?.data?.id;return Object.values(R).some(r=>r===i)}function de(e,t=h()){let i=e.verifiedAt!==null&&Number.isFinite(e.verifiedAt)&&e.verifiedAt<=t?e.verifiedAt+N: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 ct(e){if(typeof window>"u"||typeof window.addEventListener!="function")return()=>{};let t=()=>{document.hidden||e()};return window.addEventListener("focus",e),document.addEventListener("visibilitychange",t),()=>{window.removeEventListener("focus",e),document.removeEventListener("visibilitychange",t)}}import ht from"tweetnacl";var fe="buoys1",ut="buoy-session-v1:",pe=1,j=60,dt=64,ft=["free","pro","business"],m="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";function H(e){let t="",i=0;for(;i+2<e.length;i+=3){let s=e[i]<<16|e[i+1]<<8|e[i+2];t+=m[s>>>18&63]+m[s>>>12&63]+m[s>>>6&63]+m[s&63]}let r=e.length-i;if(r===1){let s=e[i]<<16;t+=m[s>>>18&63]+m[s>>>12&63]}else if(r===2){let s=e[i]<<16|e[i+1]<<8;t+=m[s>>>18&63]+m[s>>>12&63]+m[s>>>6&63]}return t}function ge(e){if(!/^[A-Za-z0-9_-]*$/.test(e)||e.length%4===1)return null;let t=[],i=0,r=0;for(let s of e)r=r<<6|m.indexOf(s),i+=6,i>=8&&(t.push(r>>>i-8&255),i-=8);return new Uint8Array(t)}function pt(e){if(typeof TextEncoder<"u")return new TextEncoder().encode(e);let t=unescape(encodeURIComponent(e)),i=new Uint8Array(t.length);for(let r=0;r<t.length;r+=1)i[r]=t.charCodeAt(r);return i}function gt(e){try{if(typeof TextDecoder<"u")return new TextDecoder("utf-8",{fatal:true}).decode(e);let t="";for(let i of e)t+=String.fromCharCode(i);return decodeURIComponent(escape(t))}catch{return null}}function mt(e){let t=e.trim().toLowerCase(),i=new Uint8Array(t.length/2);for(let r=0;r<i.length;r+=1)i[r]=parseInt(t.slice(r*2,r*2+2),16);return i}function yt(e){return pt(ut+e)}function _(e,t=256){return typeof e=="string"&&e.length>0&&e.length<=t}function me(e){return typeof e=="number"&&Number.isInteger(e)&&e>0}function wt(e){if(!e||typeof e!="object"||Array.isArray(e))return null;let t=e;return!_(t.sid)||!_(t.sub)||!_(t.aud,512)||t.team!==null&&!_(t.team)||!ft.includes(t.tier)||t.role!==void 0&&!_(t.role,64)||t.tools!==void 0&&(!Array.isArray(t.tools)||t.tools.length>256||!t.tools.every(i=>_(i,64)))||!me(t.iat)||!me(t.exp)||t.exp<=t.iat?null:{v:pe,sid:t.sid,sub:t.sub,team:t.team,tier:t.tier,...t.role!==void 0?{role:t.role}:{},...t.tools!==void 0?{tools:[...t.tools]}:{},aud:t.aud,iat:t.iat,exp:t.exp}}var vt=be;function ye(e){return e.startsWith(`${fe}.`)}function B(e,t){let i=t.publicKeyHex??vt;if(!i)return{ok:false,reason:"no-key"};let r=typeof e=="string"?e.split("."):[];if(r.length!==3||r[0]!==fe)return{ok:false,reason:"malformed"};let[,s,n]=r,c=ge(s),o=ge(n);if(!c||!o||o.length!==dt)return{ok:false,reason:"malformed"};try{if(!ht.sign.detached.verify(yt(s),o,mt(i)))return{ok:false,reason:"signature"}}catch{return{ok:false,reason:"signature"}}let a=gt(c),l;try{l=a===null?null:JSON.parse(a)}catch{return{ok:false,reason:"malformed"}}if(!l||typeof l!="object"||l.v!==pe)return{ok:false,reason:l&&typeof l=="object"?"version":"malformed"};let u=wt(l);if(!u)return{ok:false,reason:"claims"};if(u.aud!==t.audience)return{ok:false,reason:"audience"};if(t.ignoreTime)return{ok:true,claims:u};let f=Math.floor((t.nowMs??h())/1e3);return f>=u.exp+j?{ok:false,reason:"expired"}:u.iat>f+j?{ok:false,reason:"not-yet-valid"}:{ok:true,claims:u}}var Tt="@buoy/session:",C=10080*60*1e3,we=360*60*1e3,At=300*1e3,_t=15e3,Et="https://buoy.gg",kt="buoy:signin",bt=600*1e3,d=class extends Error{constructor(e,t){super(t);this.code=e;this.name="SessionError"}};function xt(){let e=globalThis;return{fetch:(t,i)=>fetch(t,i),storage:y,now:h,random:t=>{let i=new Uint8Array(t);if(!e.crypto?.getRandomValues)throw new d("not_configured","This platform has no secure random source.");return e.crypto.getRandomValues(i)},sha256:async t=>{if(!e.crypto?.subtle)throw new d("not_configured","Sign-in needs a secure page (https or localhost).");return new Uint8Array(await e.crypto.subtle.digest("SHA-256",t))},openPopup:()=>{if(!e.window?.open)return null;let t=480,i=640,r=Math.max(0,(e.window.screenX??0)+((e.window.outerWidth??t)-t)/2),s=Math.max(0,(e.window.screenY??0)+((e.window.outerHeight??i)-i)/2);return e.window.open("about:blank","buoy-signin",`popup,width=${t},height=${i},left=${r},top=${s}`)},onMessage:t=>{if(!e.window?.addEventListener)return()=>{};let i=r=>t({origin:r.origin,data:r.data});return e.window.addEventListener("message",i),()=>e.window?.removeEventListener("message",i)},withLock:(t,i)=>e.navigator?.locks?e.navigator.locks.request(t,i):i(),watch:t=>{let i=e.window;if(!i?.addEventListener)return()=>{};let r=n=>t.storage(n.key),s=()=>{i.document?.visibilityState!=="hidden"&&t.wake()};return i.addEventListener("storage",r),i.addEventListener("online",t.wake),i.document?.addEventListener?.("visibilitychange",s),()=>{i.removeEventListener("storage",r),i.removeEventListener("online",t.wake),i.document?.removeEventListener?.("visibilitychange",s)}},setTimer:(t,i)=>setTimeout(t,Math.min(i,2147483647)),clearTimer:t=>clearTimeout(t)}}function Lt(){let e=globalThis.location;if(!(!e?.origin||!/^https?:$/.test(e.protocol??"")))return e.origin}var It=class{constructor(e){this.signinOrigin=Et;this.current=null;this.claims=null;this.listeners=new Set;this.timer=null;this.refreshing=null;this.loaded=null;this.unwatch=null;this.limitTimer=null;this.epoch=0;this.deps=e??xt(),this.audience=Lt()}get origin(){return this.signinOrigin}configure(e){e.audience!==void 0&&(this.audience=e.audience),e.signinOrigin!==void 0&&(this.signinOrigin=e.signinOrigin.replace(/\/$/,"")),this.reset()}__setDeps(e){this.deps=e,this.reset()}reset(){this.unwatch?.(),this.unwatch=null,this.epoch+=1,this.limitTimer!==null&&this.deps.clearTimer(this.limitTimer),this.limitTimer=null,this.timer!==null&&this.deps.clearTimer(this.timer),this.timer=null,this.current=null,this.claims=null,this.loaded=null,this.refreshing=null}get storageKey(){return Tt+(this.audience??"")}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}notify(){for(let e of[...this.listeners])try{e()}catch(t){console.warn("[Buoy] sign-in listener error:",t)}}getAccessToken(){let e=this.getStatus();return e.state==="active"&&!e.grace?this.current?.accessToken??null:null}getStatus(){let e=this.claims;if(!e)return{state:"signed_out"};let t=e.exp*1e3,i=this.deps.now();return i<(e.iat-j)*1e3?{state:"signed_out"}:i<t?{state:"active",claims:e,grace:false,validUntil:t}:i<t+C?{state:"active",claims:e,grace:true,validUntil:t+C}:{state:"signed_out"}}load(){return this.loaded||(this.loaded=this.loadOnce()),this.loaded}async loadOnce(){if(!this.audience)return;this.unwatch??(this.unwatch=this.deps.watch?.({storage:t=>{(t===null||t===this.storageKey)&&this.sync()},wake:()=>{this.claims&&this.refresh()}})??null);let e=await this.read();e&&this.adopt(e)&&(this.notify(),this.schedule())}async sync(){if(!this.audience)return;let e=await this.read();if(!e){this.current&&this.clearLocal();return}e.refreshToken!==this.current?.refreshToken&&this.adopt(e)&&(this.notify(),this.schedule())}async read(){try{let e=await(await this.deps.storage()).getItem(this.storageKey);if(!e)return null;let t=JSON.parse(e);return t?.v===1&&typeof t.accessToken=="string"&&typeof t.refreshToken=="string"?t:null}catch{return null}}async write(e){let t=await this.deps.storage();e?await t.setItem(this.storageKey,JSON.stringify(e)):await t.removeItem(this.storageKey)}adopt(e){if(!this.audience)return false;let t=B(e.accessToken,{audience:this.audience,ignoreTime:true,publicKeyHex:this.deps.publicKeyHex}),i=t.ok?t.claims:null;return i?(this.current=e,this.claims=i,true):false}armLimit(){if(this.limitTimer!==null&&this.deps.clearTimer(this.limitTimer),this.limitTimer=null,!this.claims)return;let e=this.claims.exp*1e3,t=this.deps.now(),i=t<e?e:t<e+C?e+C:null;i!==null&&(this.limitTimer=this.deps.setTimer(()=>{this.limitTimer=null,this.notify(),this.armLimit()},i-t))}call(e,t){return new Promise((i,r)=>{let s=this.deps.setTimer(()=>r(new Error("timeout")),_t);this.deps.fetch(e,t).then(n=>{this.deps.clearTimer(s),i(n)},n=>{this.deps.clearTimer(s),r(n)})})}schedule(){if(this.armLimit(),this.timer!==null&&this.deps.clearTimer(this.timer),this.timer=null,!this.claims)return;let e=this.claims.exp*1e3-we-this.deps.now();this.timer=this.deps.setTimer(()=>{this.timer=null,this.refresh()},Math.max(0,e))}refresh(e=false){return this.refreshing||(this.refreshing=this.deps.withLock(this.lockName,()=>this.refreshLocked(e)).catch(()=>this.retryLater()).finally(()=>{this.refreshing=null})),this.refreshing}get lockName(){return`buoy-session:${this.audience??""}`}async refreshLocked(e){let t=this.epoch,i=await this.read();if(!i){this.current&&this.clearLocal();return}if(i.refreshToken!==this.current?.refreshToken&&this.adopt(i)){this.notify(),this.schedule();return}if(!this.claims)return;if(!e&&this.claims.exp*1e3-this.deps.now()>we){this.schedule();return}let r,s;try{let n=await this.call(`${this.signinOrigin}/api/auth/refresh`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refresh_token:i.refreshToken,audience:this.audience})});r=n.status,s=await n.json().catch(()=>null)}catch{this.retryLater();return}if(t===this.epoch){if(r===200&&s&&typeof s.access_token=="string"&&typeof s.refresh_token=="string"){let n={v:1,accessToken:s.access_token,refreshToken:s.refresh_token};if(this.adopt(n)){await this.write(n),this.notify(),this.schedule();return}}if(r===400||r===401||r===403){await this.write(null),this.clearLocal();return}this.retryLater()}}retryLater(){this.armLimit(),this.timer!==null&&this.deps.clearTimer(this.timer),this.timer=this.deps.setTimer(()=>{this.timer=null,this.refresh(true)},At),this.notify()}clearLocal(){this.timer!==null&&this.deps.clearTimer(this.timer),this.timer=null,this.limitTimer!==null&&this.deps.clearTimer(this.limitTimer),this.limitTimer=null,this.current=null,this.claims=null,this.notify()}async signIn(){if(!this.audience)throw new d("not_configured","Sign-in needs a web page or a configured app id.");let e=this.deps.openPopup();if(!e)throw new d("popup_blocked","The browser blocked the sign-in window. Allow pop-ups for this site and try again.");try{return await this.signInWith((t,i)=>new Promise((r,s)=>{e.location.href=t;let n=this.deps.now(),c=null,o=u=>{c!==null&&this.deps.clearTimer(c),a(),u()},a=this.deps.onMessage(u=>{if(u.origin!==this.signinOrigin)return;let f=u.data;!f||f.type!==kt||f.state!==i||(typeof f.code=="string"?o(()=>r(f.code)):o(()=>s(new d("access_denied","Sign-in was cancelled."))))}),l=()=>{if(e.closed)return o(()=>s(new d("popup_closed","The sign-in window was closed.")));if(this.deps.now()-n>bt)return o(()=>s(new d("timeout","Sign-in took too long.")));c=this.deps.setTimer(l,500)};c=this.deps.setTimer(l,500)}))}finally{try{e.closed||e.close()}catch{}}}async signInWith(e){let t=this.audience;if(!t)throw new d("not_configured","Sign-in needs a web page or a configured app id.");let i=H(this.deps.random(32)),r=H(this.deps.random(16)),s=H(await this.deps.sha256(new TextEncoder().encode(i))),n=`${this.signinOrigin}/auth/authorize?audience=${encodeURIComponent(t)}&code_challenge=${s}&code_challenge_method=S256&state=${r}`,c=await e(n,r),o;try{o=await this.call(`${this.signinOrigin}/api/auth/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:c,code_verifier:i,audience:t})})}catch{throw new d("network","Buoy could not be reached. Check your connection and try again.")}let a=await o.json().catch(()=>null);if(o.status!==200||!a||typeof a.access_token!="string"||typeof a.refresh_token!="string"){let l=a&&typeof a.error_description=="string"?a.error_description:"Buoy did not accept this sign-in.";throw new d(o.status===503?"unavailable":"rejected",l)}return this.finishSignIn(a.access_token,a.refresh_token)}async finishSignIn(e,t){let i={v:1,accessToken:e,refreshToken:t};if(this.epoch+=1,!this.adopt(i))throw new d("rejected","Buoy sent a sign-in this app could not check.");return await this.write(i),await this.load(),this.notify(),this.schedule(),this.getStatus()}async signInWithCode(e,t={}){let i=this.audience;if(!i)throw new d("not_configured","Sign-in with a code needs this app's id (app:com.example.app).");let r=(a,l)=>this.call(`${this.signinOrigin}/api/auth/device/${a}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)}),s;try{s=await r("start",{audience:i})}catch{throw new d("network","Buoy could not be reached. Check your connection and try again.")}let n=await s.json().catch(()=>null);if(s.status!==200||!n||typeof n.device_code!="string"||typeof n.user_code!="string"||typeof n.verification_uri!="string"||typeof n.verification_uri_complete!="string"){let a=n&&typeof n.error_description=="string"?n.error_description:"Buoy could not start a sign-in.";throw new d(s.status===503?"unavailable":"rejected",a)}let c=this.deps.now()+(Number(n.expires_in)||600)*1e3,o=Math.max(5,Number(n.interval)||5)*1e3;for(e({userCode:n.user_code,verificationUri:n.verification_uri,verificationUriComplete:n.verification_uri_complete,expiresAt:c});;){if(await this.wait(o,t.signal),this.deps.now()>c)throw new d("timeout","The code ran out. Start again for a new one.");let a;try{a=await r("poll",{device_code:n.device_code})}catch{continue}let l=await a.json().catch(()=>null);if(a.status===200&&l&&typeof l.access_token=="string"&&typeof l.refresh_token=="string")return this.finishSignIn(l.access_token,l.refresh_token);let u=l&&typeof l.error=="string"?l.error:"";if(u==="authorization_pending"||a.status>=500)continue;if(u==="slow_down"||a.status===429){o+=5e3;continue}if(u==="access_denied")throw new d("access_denied","The sign-in was turned down on buoy.gg.");if(u==="expired_token")throw new d("timeout","The code ran out. Start again for a new one.");let f=l&&typeof l.error_description=="string"?l.error_description:"Buoy did not accept this sign-in.";throw new d("rejected",f)}}wait(e,t){return new Promise((i,r)=>{let s=()=>new d("access_denied","Sign-in was cancelled.");if(t?.aborted)return r(s());let n=()=>{this.deps.clearTimer(c),r(s())},c=this.deps.setTimer(()=>{t?.removeEventListener?.("abort",n),i()},e);t?.addEventListener?.("abort",n)})}async signOut(){this.epoch+=1;let e=this.current;this.clearLocal();let t=e;try{await this.deps.withLock(this.lockName,async()=>{t=await this.read()??e,await this.write(null)})}catch{await this.write(null).catch(()=>{})}if(t)try{await this.call(`${this.signinOrigin}/api/auth/revoke`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refresh_token:t.refreshToken})})}catch{}}},E=new It;var Rt="bsk1_",Nt="service",Ct=15e3;function z(e){return e.startsWith(Rt)}function b(e){let t=e.trim();return z(t)||ye(t)?t:t.toUpperCase()}function Pt(e,t){return b(e??"")===b(t??"")}async function St(e,t){let i=t.fetch??((a,l)=>fetch(a,l)),r=typeof AbortController<"u"?new AbortController:void 0,s=setTimeout(()=>r?.abort(),Ct),n,c;try{let a=await i(`${t.origin.replace(/\/$/,"")}/api/auth/service-token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:e}),signal:r?.signal});n=a.status,c=await a.json().catch(()=>null)}catch{return{ok:false,reason:"network",detail:"Buoy could not be reached to check the bot key."}}finally{clearTimeout(s)}if(n>=500||n===429)return{ok:false,reason:"network",detail:"Buoy is busy. The bot key will be checked again soon."};if(n!==200||typeof c?.access_token!="string")return{ok:false,reason:"rejected",detail:typeof c?.error_description=="string"?c.error_description:"This bot key was not accepted."};let o=B(c.access_token,{audience:Nt,nowMs:h(),publicKeyHex:t.publicKeyHex});return o.ok?{ok:true,claims:o.claims}:{ok:false,reason:"rejected",detail:"Buoy sent a token this app could not check."}}var Kt="dev";function ve(e){return ye(e)}function Te(e,t=h()){let i=B(e,{audience:Kt,ignoreTime:true});return i.ok?t>=i.claims.exp*1e3?{ok:false,reason:"expired",message:"Your dev token ran out. Run `npx buoy login` again."}:{ok:true,claims:i.claims}:{ok:false,reason:"invalid",message:"This dev token is not valid. Run `npx buoy login` again."}}var Ot="This is a dev token. It only works in dev builds. A live build turns on Buoy with Sign in with Buoy.";async function w(e,t){let i;try{return await Promise.race([e,new Promise(r=>{i=setTimeout(()=>r(t),15e3)})])}finally{i&&clearTimeout(i)}}function k(e){return e.tier==="pro"||e.tier==="free"?e.tier:e.isPro?"pro":"free"}var Mt=class{constructor(){this.state={isInitialized:false,isValidating:false,isPro:false,tier:"free",tierSource:"none",licenseKey:null,error:null,errorKind:null,expiresAt:null};this.listeners=new Set;this.revalidationTimer=null;this.cachedLicense=null;this.fingerprintPromise=null;this.initPromise=null;this.generation=0;this.persistence=Promise.resolve();this.verifiedAt=null;this.expiryTimer=null;this.removeForegroundListener=null;this.sessionUnsubscribe=null;this.retryTimer=null;this.retryAttempt=0;this.deviceRegistrationCallback=null;this.pendingRegistration=null}async initialize(){if(this.initPromise)return this.initPromise;if(!this.state.isInitialized)return this.initPromise=this._doInitialize(),this.initPromise}async _doInitialize(){if(this.state.isInitialized)return;let e=this.generation;this.sessionUnsubscribe||(this.sessionUnsubscribe=E.subscribe(()=>this.emit({type:"validated",isPro:this.isPro()}))),await w(E.load().catch(()=>{}),void 0);try{let t=await w(this.loadCachedLicense(),null);if(e!==this.generation){this.state.isInitialized=true,this.emit({type:"initialized",isPro:this.state.isPro}),this.startRevalidationTimer();return}if(t&&(this.configuredKey===void 0||t.licenseKey===this.configuredKey)){let i=A(t);this.cachedLicense=t,this.state.licenseKey=t.licenseKey,i&&this.isCacheValid(t)?this.applyTier(k(t)):this.lock(),this.state.expiresAt=t.expiresAt?new Date(t.expiresAt):null,i&&this.isCacheValid(t)&&this.setVerifiedAt(t.cachedAt),this.configuredKey===void 0&&t.licenseKey&&!(i&&this.isCacheValid(t)&&this.isCacheFresh(t))&&this.validateInBackground(t.licenseKey)}this.state.isInitialized=true,this.emit({type:"initialized",isPro:this.state.isPro}),this.startRevalidationTimer()}catch(t){console.warn("[React Buoy] License initialization failed:",t),this.state.isInitialized=true,this.emit({type:"initialized",isPro:false})}}async configure(e){if(e===void 0)return await this.initialize(),this.hasAccountAccess();let t=b(e),i=++this.generation;return this.cancelRetry(),this.configuredKey=t||null,this.state.licenseKey!==this.configuredKey&&this.lock(),this.state.licenseKey=this.configuredKey,this.state.isValidating=!!t,this.emit({type:"validating",isPro:this.isPro()}),await this.initialize(),i!==this.generation?false:t?this.setLicenseKey(t):(await this.clearLicense(),false)}async setLicenseKey(e,t){if(!e||e.trim().length===0)return this.state.error="License key is required",this.state.errorKind="verdict",false;let i=b(e),r=++this.generation;if(this.cancelRetry(),t?.isRetry||(this.retryAttempt=0),this.state.licenseKey!==i&&this.lock(),this.state.licenseKey=i,this.state.isValidating=true,this.state.error=null,this.state.errorKind=null,this.emit({type:"validating",isPro:this.isPro()}),he(i))return this.admitToken(i,r);if(z(i))return this.admitServiceKey(i,r);if(ve(i))return this.admitDevToken(i);if(!this.cachedLicense){let a=await w(this.loadCachedLicense(),null);if(r!==this.generation)return false;a?.licenseKey===i&&(this.cachedLicense=a,A(a)&&this.isCacheValid(a)&&(this.applyTier(k(a)),this.state.expiresAt=a.expiresAt?new Date(a.expiresAt):null,this.setVerifiedAt(a.cachedAt),this.emit({type:"validating",isPro:this.isPro()})))}let s=this.cachedLicense;if(!t?.force&&s&&s.valid&&s.licenseKey===i&&s.fingerprint&&A(s)&&this.isCacheValid(s)&&this.isCacheFresh(s))return this.applyTier(k(s)),this.state.licenseKey=i,this.state.isValidating=false,this.state.error=null,this.state.errorKind=null,this.state.expiresAt=s.expiresAt?new Date(s.expiresAt):null,this.setVerifiedAt(s.cachedAt),this.emit({type:"validated",isPro:this.state.isPro}),true;let n=await w(this.loadHold(),null);if(r!==this.generation)return false;let c=(n?.backoffUntil??0)-h();if(c>0)return this.standDown(i,r,"License server is rate limited; retrying later.",c);if(!t?.force&&n?.key===i&&n.verdictAt!==void 0&&h()-n.verdictAt>=0&&h()-n.verdictAt<Ne)return this.lock(),this.state.isValidating=false,this.state.error=n.detail||"License could not be verified",this.state.errorKind="verdict",this.emit({type:"error",isPro:false,error:this.state.error}),false;let o;try{o=await De(i)}catch(a){let l=a instanceof Error?a.message:"Validation failed";if(r!==this.generation)return false;if(Q(a)){if(Se(a)){let u=Math.min(Ke(a,q,Re)*2**this.retryAttempt,q);return this.retryAttempt+=1,await this.saveHold({...this.hold,backoffUntil:h()+u}),r!==this.generation?false:this.standDown(i,r,l,u)}return this.state.isValidating=false,this.cachedLicense&&this.cachedLicense.licenseKey===i&&A(this.cachedLicense)&&this.isCacheValid(this.cachedLicense)?(this.applyTier(k(this.cachedLicense)),this.state.error=null,this.state.errorKind=null,this.state.expiresAt=this.cachedLicense.expiresAt?new Date(this.cachedLicense.expiresAt):null,this.setVerifiedAt(this.cachedLicense.cachedAt),this.keyTier()!=="pro"&&this.scheduleRetry(i),this.emit({type:"validated",isPro:this.state.isPro}),true):(this.state.error=l,this.state.errorKind="transport",this.scheduleRetry(i),this.emit({type:"error",isPro:this.state.isPro,error:l}),false)}return this.state.isValidating=false,this.state.error=l,this.state.errorKind="verdict",this.emit({type:"error",isPro:false,error:l}),false}try{if(r!==this.generation)return false;let a=$e(o),l=o.data?.relationships?.product?.data?.id;if((!l||l===I.productId)&&a.code==="EXPIRED"&&(lt(o.data)||this.cachedLicense?.licenseKey===i&&A(this.cachedLicense)&&this.isCacheValid(this.cachedLicense))){let O=h(),W=await this.saveCache({licenseKey:i,licenseId:o.data?.id??"",valid:true,isPro:false,tier:"free",expiresAt:null,cachedAt:O,lastValidatedAt:O,fingerprint:this.cachedLicense?.licenseKey===i?this.cachedLicense.fingerprint:void 0},r);return r!==this.generation||!W?false:(this.cachedLicense=W,this.applyTier("free"),this.state.isValidating=false,this.state.expiresAt=null,this.setVerifiedAt(O),this.emit({type:"validated",isPro:false}),true)}if(je(a.code)||!Ue(o))return this.lock(),this.state.isValidating=false,this.state.error=a.detail||"License could not be verified",this.state.errorKind="verdict",this.emit({type:"error",isPro:false,error:this.state.error}),await this.clearCachedLicense(),await this.saveHold({key:i,code:a.code,detail:this.state.error,verdictAt:h()}),false;if(!o.data)return this.lock(),this.state.isValidating=false,this.state.error=a.detail||"License not found",this.state.errorKind="verdict",this.emit({type:"error",isPro:false,error:this.state.error}),await this.clearCachedLicense(),false;let u=ot(o.data),f=o.data.id,P=h(),G=Fe(o)>=Ce,J=F(),Ae=J&&!G,_e=u==="free"&&(G||!J),v=this.cachedLicense?.fingerprint,x=this.cachedLicense?.deviceName,Y=false;if(!v){if(v=await w(this.getOrCreateDeviceFingerprint(),U()),r!==this.generation)return false;x=$(),Y=Ae}let S=false;Y&&(this.deviceRegistrationCallback?(this.pendingRegistration={licenseId:f,licenseKey:i,fingerprint:v},this.deviceRegistrationCallback({fingerprint:v,defaultName:x}),S=true):this.registerDeviceAsync(f,i,v,x));let K={licenseKey:i,licenseId:f,valid:true,isPro:u==="pro",tier:u,expiresAt:o.data.attributes.expiry??null,cachedAt:P,lastValidatedAt:P,fingerprint:S?void 0:v,deviceName:S?void 0:x,quiet:_e||void 0},X=await this.saveCache(K,r);return r!==this.generation||!X||(this.cachedLicense=X,this.applyTier(u),this.state.isValidating=false,this.state.expiresAt=K.expiresAt?new Date(K.expiresAt):null,this.setVerifiedAt(P),this.hold&&await this.saveHold(null),r!==this.generation)?false:(this.retryAttempt=0,this.emit({type:"validated",isPro:this.state.isPro}),true)}catch(a){let l=a instanceof Error?a.message:"Validation failed";return r!==this.generation||(this.state.isValidating=false,this.state.error=l,this.state.errorKind="verdict",this.emit({type:"error",isPro:false,error:l})),false}}scheduleRetry(e){this.cancelRetry();let t=Ie[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 p<"u"&&p&&(globalThis.__LICENSE_MANAGER_RETRY_TIMER__=this.retryTimer)}async admitServiceKey(e,t){let i=await St(e,{origin:E.origin});if(t!==this.generation)return false;if(!i.ok)return this.lock(),this.state.isValidating=false,this.state.error=i.detail,this.state.errorKind=i.reason==="network"?"transport":"verdict",this.emit({type:"error",isPro:false,error:i.detail}),i.reason==="network"&&this.scheduleRetry(e),false;let r=i.claims.exp*1e3;return this.applyTier(i.claims.tier==="free"?"free":"pro"),this.state.isValidating=false,this.state.expiresAt=new Date(r),this.setVerifiedAt(h()),this.retryAttempt=0,this.scheduleRetryIn(e,Math.max(6e4,r-3600*1e3-h())),this.emit({type:"validated",isPro:this.isPro()}),true}admitDevToken(e){let t=Te(e);if(!t.ok||!F()){let r=t.ok?Ot:t.message;return this.lock(),this.state.isValidating=false,this.state.error=r,this.state.errorKind="verdict",this.emit({type:"error",isPro:false,error:r}),false}let i=h();return this.applyTier(t.claims.tier==="free"?"free":"pro"),this.state.isValidating=false,this.state.expiresAt=new Date(t.claims.exp*1e3),this.setVerifiedAt(Math.min(i,t.claims.iat*1e3)),this.retryAttempt=0,this.emit({type:"validated",isPro:this.isPro()}),true}async admitToken(e,t){let i=at(e);if(t!==this.generation)return false;if(!i)return this.lock(),this.state.isValidating=false,this.state.error="This key is not valid. Check that it was copied completely.",this.state.errorKind="verdict",this.emit({type:"error",isPro:false,error:this.state.error}),await this.clearCachedLicense(),false;let r=h(),s=this.cachedLicense?.fingerprint??await w(this.getOrCreateDeviceFingerprint(),U());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??$(),quiet:true},t);return t!==this.generation||!n?false:(this.cachedLicense=n,this.applyTier("free"),this.state.isValidating=false,this.state.expiresAt=null,this.setVerifiedAt(r),this.retryAttempt=0,this.emit({type:"validated",isPro:false}),true)}standDown(e,t,i,r){if(t!==this.generation)return false;this.state.isValidating=false;let s=this.cachedLicense;return s&&s.licenseKey===e&&A(s)&&this.isCacheValid(s)?(this.applyTier(k(s)),this.state.error=null,this.state.errorKind=null,this.state.expiresAt=s.expiresAt?new Date(s.expiresAt):null,this.setVerifiedAt(s.cachedAt),this.keyTier()!=="pro"&&this.scheduleRetryIn(e,r),this.emit({type:"validated",isPro:this.state.isPro}),true):(this.state.error=i,this.state.errorKind="transport",this.scheduleRetryIn(e,r),this.emit({type:"error",isPro:this.state.isPro,error:i}),false)}scheduleRetryIn(e,t){this.cancelRetry();let i=this.generation;this.retryTimer=setTimeout(()=>{this.retryTimer=null,i===this.generation&&(this.state.isValidating||this.setLicenseKey(e,{force:true,isRetry:true}))},Math.max(1,Math.min(t,2147483647))),typeof p<"u"&&p&&(g.__LICENSE_MANAGER_RETRY_TIMER__=this.retryTimer)}cancelRetry(){this.retryTimer&&(clearTimeout(this.retryTimer),this.retryTimer=null)}async clearLicense(){this.generation+=1,this.cancelRetry(),this.retryAttempt=0,this.configuredKey=null,this.state.licenseKey=null,this.lock(),this.state.expiresAt=null,this.state.error=null,this.state.errorKind=null,this.cachedLicense=null,this.pendingRegistration=null,this.state.isValidating=false,this.emit({type:"deactivated",isPro:false}),await this.clearCachedLicense(),this.hold?.verdictAt!==void 0&&await this.saveHold(this.hold.backoffUntil?{backoffUntil:this.hold.backoffUntil}:null)}applyTier(e){this.state.tier=e,this.state.tierSource="key",this.state.isPro=e==="pro"}lock(){this.state.tier="free",this.state.tierSource="none",this.state.isPro=false,this.verifiedAt=null,this.expiryTimer&&clearTimeout(this.expiryTimer),this.expiryTimer=null}getTier(){return this.credential().tier}credential(){let e=this.keyTier(),t=this.sessionTier();return t!==null&&(!this.hasKeyAccess()||t==="pro"&&e!=="pro")?{source:"session",tier:t}:{source:this.state.tierSource,tier:e}}keyTier(){return!this.hasKeyAccess()||this.state.expiresAt&&h()>=this.state.expiresAt.getTime()?"free":this.state.tier}sessionTier(){let e=E.getStatus();return e.state!=="active"?null:e.claims.tier==="free"?"free":"pro"}isPro(){return this.getTier()==="pro"}hasEntitlement(e){return this.isPro()}getState(){let{source:e,tier:t}=this.credential();return{...this.state,tier:t,tierSource:e,isPro:t==="pro",access:this.getAccountAccess()}}getAccountAccess(){let e=this.getKeyAccess();if(e.status==="admitted")return e;let t=E.getStatus();return t.state==="active"?{status:"admitted",reason:null,validUntil:t.validUntil}:e}getKeyAccess(){return de({initialized:this.state.isInitialized,validating:this.state.isValidating,key:this.state.licenseKey,tierSource:this.state.tierSource,verifiedAt:this.verifiedAt})}hasAccountAccess(){return this.getAccountAccess().status==="admitted"}hasKeyAccess(){return this.getKeyAccess().status==="admitted"}setVerifiedAt(e){this.verifiedAt=e,this.expiryTimer&&clearTimeout(this.expiryTimer);let t=e+N,i=this.state.expiresAt?.getTime(),r=(i&&i>h()?Math.min(t,i):t)-h();this.expiryTimer=setTimeout(()=>{this.expiryTimer=null,this.verifiedAt===e&&(this.emit({type:"validated",isPro:this.isPro()}),h()<t&&this.setVerifiedAt(e))},Math.max(1,Math.min(r,2147483647))),typeof p<"u"&&p&&(g.__LICENSE_MANAGER_EXPIRY_TIMER__=this.expiryTimer)}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}onDeviceRegistrationNeeded(e){return this.deviceRegistrationCallback=e,()=>{this.deviceRegistrationCallback=null}}async completeDeviceRegistration(e){if(!this.pendingRegistration){console.warn("[Buoy] No pending device registration");return}let{licenseId:t,licenseKey:i,fingerprint:r}=this.pendingRegistration,s=this.generation,n=e.trim()||$(),c=se();try{await te(t,i,r,n,c)}catch(o){let a=o instanceof Error?o.message:String(o);if(!(a==="FINGERPRINT_TAKEN"||a==="MACHINE_LIMIT_EXCEEDED"))throw console.warn("[Buoy] Device registration failed:",a),o}if(s===this.generation){if(this.cachedLicense?.licenseKey===i){let o=await this.saveCache({...this.cachedLicense,fingerprint:r,deviceName:n},s);if(s!==this.generation)return;o&&(this.cachedLicense=o)}this.pendingRegistration=null}}emit(e){[...this.listeners].forEach(t=>{try{t(e)}catch(i){console.warn("[React Buoy] License listener error:",i)}})}isCacheValid(e){let t=h()-e.cachedAt;return!(!e.valid||!Number.isFinite(e.cachedAt)||t<0||t>=N)}isCacheFresh(e){let t=this.isQuiet(e)?Pe:Le;return h()-(e.lastValidatedAt??0)<t}isQuiet(e){return e.quiet!==void 0?e.quiet:k(e)==="free"&&!F()}async loadHold(){if(this.hold!==void 0)return this.hold;try{let e=await(await y()).getItem(D),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 y();e?await t.setItem(D,JSON.stringify(e)):await t.removeItem(D)}catch{}}async persistCache(e){let t=le(e);return await(await y()).setItem(M,JSON.stringify(t)),t}saveCache(e,t){let i=this.persistence.catch(()=>{}).then(async()=>{if(t!==this.generation)return null;let r=await this.persistCache(e);return t===this.generation?r:null});return this.persistence=i,w(i,le(e))}async loadCachedLicense(){try{await this.persistence.catch(()=>{});let e=await(await y()).getItem(M);return e?JSON.parse(e):null}catch(e){return console.warn("[Buoy] Error loading cached license:",e),null}}getOrCreateDeviceFingerprint(){return this.fingerprintPromise||(this.fingerprintPromise=(async()=>{let e=await y(),t=await e.getItem(V);if(t)return t;let i=this.cachedLicense?.fingerprint||U();return await e.setItem(V,i),i})()),this.fingerprintPromise}async clearCachedLicense(){this.cachedLicense=null;let e=this.persistence.catch(()=>{}).then(async()=>{await(await y()).removeItem(M)});this.persistence=e,await w(e.catch(()=>{}),void 0)}registerDeviceAsync(e,t,i,r){let s=se();te(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=ct(()=>this.refreshAccess()),typeof p<"u"&&p&&(g.__LICENSE_MANAGER_FOREGROUND_OFF__=this.removeForegroundListener)),this.revalidationTimer&&clearInterval(this.revalidationTimer),this.revalidationTimer=setInterval(()=>{if(!this.state.licenseKey||this.state.isValidating)return;let e=this.cachedLicense;e&&e.licenseKey===this.state.licenseKey&&this.isCacheFresh(e)||this.validateInBackground(this.state.licenseKey)},xe),typeof p<"u"&&p&&(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 y()).removeItem(V)}catch{}}},Vt=new Mt,g=globalThis;typeof p<"u"&&p&&(g.__LICENSE_MANAGER_FOREGROUND_OFF__?.(),g.__LICENSE_MANAGER_FOREGROUND_OFF__=void 0,g.__LICENSE_MANAGER_EXPIRY_TIMER__&&clearTimeout(g.__LICENSE_MANAGER_EXPIRY_TIMER__),g.__LICENSE_MANAGER_TIMER__&&clearInterval(g.__LICENSE_MANAGER_TIMER__),g.__LICENSE_MANAGER_RETRY_TIMER__&&(clearTimeout(g.__LICENSE_MANAGER_RETRY_TIMER__),g.__LICENSE_MANAGER_RETRY_TIMER__=void 0));export{h as a,T as b,Q as c,he as d,de as e,d as f,E as g,z as h,b as i,Pt as j,ve as k,Te as l,Vt as m};/*!
|
|
2
|
-
* PROPRIETARY — Buoy Pro license enforcement. NOT open source.
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) Buoy. All rights reserved. Licensed under the Buoy EULA
|
|
5
|
-
* (https://buoy.gg/terms), not an OSS license.
|
|
6
|
-
*
|
|
7
|
-
* This file configures the technological measure that controls access to paid
|
|
8
|
-
* Buoy Pro features. Modifying, patching, aliasing, stubbing, or otherwise
|
|
9
|
-
* altering it — including repointing `apiUrl` at a stand-in license server — so
|
|
10
|
-
* that Pro features unlock without a valid license is a breach of the EULA and,
|
|
11
|
-
* in the United States, circumvention of an access control under 17 U.S.C.
|
|
12
|
-
* § 1201, which applies whether or not any code is copied.
|
|
13
|
-
*
|
|
14
|
-
* Pro is $9/mo, and is free every weekend for anyone holding a key —
|
|
15
|
-
* including a free one (`npx buoy login`). Buy a key at
|
|
16
|
-
* https://buoy.gg or use it free on Saturday and Sunday.
|
|
17
|
-
*//*!
|
|
18
|
-
* PROPRIETARY — Buoy Pro license enforcement. NOT open source.
|
|
19
|
-
*
|
|
20
|
-
* Copyright (c) Buoy. All rights reserved. Licensed under the Buoy EULA
|
|
21
|
-
* (https://buoy.gg/terms), not an OSS license.
|
|
22
|
-
*
|
|
23
|
-
* This file is part of the technological measure that controls access to paid
|
|
24
|
-
* Buoy Pro features. Modifying, patching, aliasing, stubbing, or otherwise
|
|
25
|
-
* altering it so that Pro features unlock without a valid license is a breach
|
|
26
|
-
* of the EULA and, in the United States, circumvention of an access control
|
|
27
|
-
* under 17 U.S.C. § 1201 — which applies whether or not any code is copied.
|
|
28
|
-
*
|
|
29
|
-
* Pro is $9/mo, and is free every weekend for anyone holding a key —
|
|
30
|
-
* including a free one (`npx buoy login`). Buy a key at
|
|
31
|
-
* https://buoy.gg or use it free on Saturday and Sunday.
|
|
32
|
-
*//*!
|
|
33
|
-
* PROPRIETARY — Buoy Pro license enforcement. NOT open source.
|
|
34
|
-
*
|
|
35
|
-
* Copyright (c) Buoy. All rights reserved. Licensed under the Buoy EULA
|
|
36
|
-
* (https://buoy.gg/terms), not an OSS license.
|
|
37
|
-
*//*!
|
|
38
|
-
* PROPRIETARY — Buoy Pro license enforcement. NOT open source.
|
|
39
|
-
*
|
|
40
|
-
* Copyright (c) Buoy. All rights reserved. Licensed under the Buoy EULA
|
|
41
|
-
* (https://buoy.gg/terms), not an OSS license.
|
|
42
|
-
*
|
|
43
|
-
* This file is part of the technological measure that controls access to paid
|
|
44
|
-
* Buoy Pro features: it decides which tier a validated key grants. Modifying,
|
|
45
|
-
* patching, aliasing, stubbing, or otherwise altering it so that Pro features
|
|
46
|
-
* unlock without a valid license is a breach of the EULA and, in the United
|
|
47
|
-
* States, circumvention of an access control under 17 U.S.C. § 1201 — which
|
|
48
|
-
* applies whether or not any code is copied.
|
|
49
|
-
*
|
|
50
|
-
* Pro is $9/mo, and is free every weekend for anyone holding a key —
|
|
51
|
-
* including a free one (`npx buoy login`). Buy a key at
|
|
52
|
-
* https://buoy.gg or use it free on Saturday and Sunday.
|
|
53
|
-
*//*!
|
|
54
|
-
* PROPRIETARY — Buoy license enforcement. NOT open source.
|
|
55
|
-
*
|
|
56
|
-
* Copyright (c) Buoy. All rights reserved. Licensed under the Buoy EULA
|
|
57
|
-
* (https://buoy.gg/terms), not an OSS license.
|
|
58
|
-
*//*!
|
|
59
|
-
* PROPRIETARY — Buoy Pro license enforcement. NOT open source.
|
|
60
|
-
*
|
|
61
|
-
* Copyright (c) Buoy. All rights reserved. Licensed under the Buoy EULA
|
|
62
|
-
* (https://buoy.gg/terms), not an OSS license.
|
|
63
|
-
*
|
|
64
|
-
* This file is the technological measure that controls access to paid Buoy Pro
|
|
65
|
-
* features. Modifying, patching, aliasing, stubbing, or otherwise altering it
|
|
66
|
-
* so that Pro features unlock without a valid license is a breach of the EULA
|
|
67
|
-
* and, in the United States, circumvention of an access control under
|
|
68
|
-
* 17 U.S.C. § 1201 — which applies whether or not any code is copied.
|
|
69
|
-
*
|
|
70
|
-
* Pro is $9/mo, and is free every weekend for anyone holding a key —
|
|
71
|
-
* including a free one (`npx buoy login`). Buy a key at
|
|
72
|
-
* https://buoy.gg or use it free on Saturday and Sunday.
|
|
73
|
-
*/
|