@buoy-gg/license 7.0.24 → 7.0.25
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/LicenseManager.js +1 -1
- package/lib/commonjs/config.js +1 -1
- package/lib/module/LicenseManager.js +1 -1
- package/lib/module/config.js +1 -1
- package/lib/typescript/commonjs/LicenseManager.d.ts +13 -0
- package/lib/typescript/commonjs/LicenseManager.d.ts.map +1 -1
- package/lib/typescript/commonjs/config.d.ts +1 -1
- package/lib/typescript/commonjs/config.d.ts.map +1 -1
- package/lib/typescript/module/LicenseManager.d.ts +13 -0
- package/lib/typescript/module/LicenseManager.d.ts.map +1 -1
- package/lib/typescript/module/config.d.ts +1 -1
- package/lib/typescript/module/config.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -12,4 +12,4 @@
|
|
|
12
12
|
*
|
|
13
13
|
* Pro is $9/mo, and is free for everyone every weekend. Buy a key at
|
|
14
14
|
* https://buoy.gg or use it free on Saturday and Sunday.
|
|
15
|
-
*/const LICENSE_STORAGE_DIR="buoy-license";let _FileSystem=null;let _licenseStorage=null;const _memoryStore=new Map;function loadFileSystem(){if(_FileSystem)return _FileSystem;try{const a=require("expo-file-system/legacy");_FileSystem=a?.default||a;if(_FileSystem?.documentDirectory){return _FileSystem}_FileSystem=null}catch{}try{const a=require("expo-file-system");_FileSystem=a?.default||a;if(_FileSystem?.documentDirectory){return _FileSystem}_FileSystem=null}catch{}return null}function getLicenseStorageDir(){const a=loadFileSystem();if(!a?.documentDirectory)return null;return`${a.documentDirectory}${LICENSE_STORAGE_DIR}/`}function getLicenseFilePath(a){const e=getLicenseStorageDir();if(!e)return null;return`${e}${encodeURIComponent(a)}.json`}async function getLicenseStorage(){if(_licenseStorage)return _licenseStorage;const a=loadFileSystem();if(a?.documentDirectory){_licenseStorage={async getItem(e){const t=getLicenseFilePath(e);if(!t)return null;try{const i=await a.getInfoAsync(t);if(!i.exists)return null;return await a.readAsStringAsync(t)}catch{return null}},async setItem(e,t){const i=getLicenseStorageDir();const s=getLicenseFilePath(e);if(!i||!s)return;try{const r=await a.getInfoAsync(i);if(!r.exists){await a.makeDirectoryAsync(i,{intermediates:true})}await a.writeAsStringAsync(s,t)}catch(r){console.warn("[Buoy] License storage write failed:",r)}},async removeItem(e){const t=getLicenseFilePath(e);if(!t)return;try{await a.deleteAsync(t,{idempotent:true})}catch{}}}}else{_licenseStorage={async getItem(e){return _memoryStore.get(e)??null},async setItem(e,t){_memoryStore.set(e,t)},async removeItem(e){_memoryStore.delete(e)}}}return _licenseStorage}function tierOfCache(a){if(a.tier)return a.tier;return a.isPro?"pro":"anonymous"}class LicenseManagerImpl{state={isInitialized:false,isValidating:false,isPro:false,tier:"anonymous",tierSource:"none",licenseKey:null,error:null,expiresAt:null};listeners=new Set;revalidationTimer=null;cachedLicense=null;initPromise=null;deviceRegistrationCallback=null;pendingRegistration=null;async initialize(){if(this.initPromise)return this.initPromise;if(this.state.isInitialized)return;this.initPromise=this._doInitialize();return this.initPromise}async _doInitialize(){if(this.state.isInitialized)return;try{const e=await this.loadCachedLicense();if(e){const t=(0,_cacheSignature.verifyCacheSignature)(e);this.cachedLicense=e;this.state.licenseKey=e.licenseKey;this.applyTier(t&&this.isCacheValid(e)?tierOfCache(e):"anonymous");this.state.expiresAt=e.expiresAt?new Date(e.expiresAt):null;if(e.licenseKey){this.validateInBackground(e.licenseKey)}}this.state.isInitialized=true;this.emit({type:"initialized",isPro:this.state.isPro});this.startRevalidationTimer()}catch(e){console.warn("[React Buoy] License initialization failed:",e);this.state.isInitialized=true;this.emit({type:"initialized",isPro:false})}}async setLicenseKey(e){if(!e||e.trim().length===0){this.state.error="License key is required";return false}const t=e.trim().toUpperCase();this.state.licenseKey=t;this.state.isValidating=true;this.state.error=null;this.emit({type:"validating",isPro:this.state.isPro});try{const
|
|
15
|
+
*/const LICENSE_STORAGE_DIR="buoy-license";let _FileSystem=null;let _licenseStorage=null;const _memoryStore=new Map;function loadFileSystem(){if(_FileSystem)return _FileSystem;try{const a=require("expo-file-system/legacy");_FileSystem=a?.default||a;if(_FileSystem?.documentDirectory){return _FileSystem}_FileSystem=null}catch{}try{const a=require("expo-file-system");_FileSystem=a?.default||a;if(_FileSystem?.documentDirectory){return _FileSystem}_FileSystem=null}catch{}return null}function getLicenseStorageDir(){const a=loadFileSystem();if(!a?.documentDirectory)return null;return`${a.documentDirectory}${LICENSE_STORAGE_DIR}/`}function getLicenseFilePath(a){const e=getLicenseStorageDir();if(!e)return null;return`${e}${encodeURIComponent(a)}.json`}async function getLicenseStorage(){if(_licenseStorage)return _licenseStorage;const a=loadFileSystem();if(a?.documentDirectory){_licenseStorage={async getItem(e){const t=getLicenseFilePath(e);if(!t)return null;try{const i=await a.getInfoAsync(t);if(!i.exists)return null;return await a.readAsStringAsync(t)}catch{return null}},async setItem(e,t){const i=getLicenseStorageDir();const s=getLicenseFilePath(e);if(!i||!s)return;try{const r=await a.getInfoAsync(i);if(!r.exists){await a.makeDirectoryAsync(i,{intermediates:true})}await a.writeAsStringAsync(s,t)}catch(r){console.warn("[Buoy] License storage write failed:",r)}},async removeItem(e){const t=getLicenseFilePath(e);if(!t)return;try{await a.deleteAsync(t,{idempotent:true})}catch{}}}}else{_licenseStorage={async getItem(e){return _memoryStore.get(e)??null},async setItem(e,t){_memoryStore.set(e,t)},async removeItem(e){_memoryStore.delete(e)}}}return _licenseStorage}function tierOfCache(a){if(a.tier)return a.tier;return a.isPro?"pro":"anonymous"}class LicenseManagerImpl{state={isInitialized:false,isValidating:false,isPro:false,tier:"anonymous",tierSource:"none",licenseKey:null,error:null,expiresAt:null};listeners=new Set;revalidationTimer=null;cachedLicense=null;initPromise=null;generation=0;deviceRegistrationCallback=null;pendingRegistration=null;async initialize(){if(this.initPromise)return this.initPromise;if(this.state.isInitialized)return;this.initPromise=this._doInitialize();return this.initPromise}async _doInitialize(){if(this.state.isInitialized)return;try{const e=await this.loadCachedLicense();if(e){const t=(0,_cacheSignature.verifyCacheSignature)(e);this.cachedLicense=e;this.state.licenseKey=e.licenseKey;this.applyTier(t&&this.isCacheValid(e)?tierOfCache(e):"anonymous");this.state.expiresAt=e.expiresAt?new Date(e.expiresAt):null;if(e.licenseKey){this.validateInBackground(e.licenseKey)}}this.state.isInitialized=true;this.emit({type:"initialized",isPro:this.state.isPro});this.startRevalidationTimer()}catch(e){console.warn("[React Buoy] License initialization failed:",e);this.state.isInitialized=true;this.emit({type:"initialized",isPro:false})}}async setLicenseKey(e){if(!e||e.trim().length===0){this.state.error="License key is required";return false}const t=e.trim().toUpperCase();this.generation+=1;const i=this.generation;this.state.licenseKey=t;this.state.isValidating=true;this.state.error=null;this.emit({type:"validating",isPro:this.state.isPro});try{const s=await(0,_api.validateLicense)(t);if(i!==this.generation)return false;const r=(0,_api.parseValidationResult)(s);if((0,_api.isFatalLicenseError)(r.code)){this.applyTier((0,_tier.tierAfterFatalError)(r.code));this.state.isValidating=false;this.state.error=r.detail;await this.clearCachedLicense();this.emit({type:"error",isPro:false,error:r.detail});return false}if(!s.data){this.state.isValidating=false;this.state.error=r.detail||"License not found";await this.clearCachedLicense();this.emit({type:"error",isPro:false,error:this.state.error});return false}const n=(0,_tier.resolveTier)(s.data);this.applyTier(n);this.state.isValidating=false;this.state.expiresAt=s.data.attributes.expiry?new Date(s.data.attributes.expiry):null;const c=s.data.id;const o=Date.now();let l=this.cachedLicense?.fingerprint;let d=this.cachedLicense?.deviceName;let u=false;if(!l){l=(0,_fingerprint.generateUUID)();d=(0,_fingerprint.getDefaultDeviceName)();u=true}let h=false;if(u){if(this.deviceRegistrationCallback){this.pendingRegistration={licenseId:c,licenseKey:t,fingerprint:l};this.deviceRegistrationCallback({fingerprint:l,defaultName:d});h=true}else{this.registerDeviceAsync(c,t,l,d)}}const f={licenseKey:t,licenseId:c,valid:true,isPro:n==="pro",tier:n,expiresAt:s.data.attributes.expiry??null,cachedAt:o,lastValidatedAt:o,fingerprint:h?void 0:l,deviceName:h?void 0:d};this.cachedLicense=await this.persistCache(f);this.emit({type:"validated",isPro:this.state.isPro});return true}catch(s){const r=s instanceof Error?s.message:"Validation failed";if(i!==this.generation)return false;if(this.isNetworkError(s)&&this.cachedLicense&&this.isCacheValid(this.cachedLicense)){this.applyTier(tierOfCache(this.cachedLicense));this.state.isValidating=false;this.emit({type:"validated",isPro:this.state.isPro});return true}this.state.isValidating=false;this.state.error=r;this.emit({type:"error",isPro:false,error:r});return false}}isNetworkError(e){if(e instanceof TypeError){return true}if(e instanceof Error){const t=e.message.toLowerCase();return t.includes("network")||t.includes("fetch")||t.includes("timeout")||t.includes("connection")||t.includes("offline")||t.includes("failed to fetch")}return false}async clearLicense(){this.generation+=1;this.state.licenseKey=null;this.applyTier("anonymous");this.state.expiresAt=null;this.state.error=null;this.cachedLicense=null;await this.clearCachedLicense();this.emit({type:"deactivated",isPro:false})}applyTier(e){this.state.tier=e;this.state.tierSource=e==="anonymous"?"none":"key";this.state.isPro=e==="pro"}getTier(){return this.state.tier}isPro(){return this.state.tier==="pro"}hasEntitlement(e){if(e==="PRO"){return this.state.isPro}return this.state.isPro}getState(){return{...this.state}}subscribe(e){this.listeners.add(e);return()=>this.listeners.delete(e)}onDeviceRegistrationNeeded(e){this.deviceRegistrationCallback=e;return()=>{this.deviceRegistrationCallback=null}}async completeDeviceRegistration(e){if(!this.pendingRegistration){console.warn("[Buoy] No pending device registration");return}const{licenseId:t,licenseKey:i,fingerprint:s}=this.pendingRegistration;const r=e.trim()||(0,_fingerprint.getDefaultDeviceName)();const n=(0,_fingerprint.getDeviceMetadata)();try{await(0,_api.activateMachine)(t,i,s,r,n)}catch(c){const o=c instanceof Error?c.message:String(c);if(o==="FINGERPRINT_TAKEN"||o==="MACHINE_LIMIT_EXCEEDED"){}else{console.warn("[Buoy] Device registration failed:",o);throw c}}if(this.cachedLicense){this.cachedLicense.fingerprint=s;this.cachedLicense.deviceName=r;this.cachedLicense=await this.persistCache(this.cachedLicense)}this.pendingRegistration=null}emit(e){const t=[...this.listeners];t.forEach(i=>{try{i(e)}catch(s){console.warn("[React Buoy] License listener error:",s)}})}isCacheValid(e){const t=Date.now();const i=t-e.cachedAt;if(i>_config.LICENSE_CACHE_DURATION){return false}if(e.expiresAt){const s=new Date(e.expiresAt).getTime();if(t>s){return false}}return true}async persistCache(e){const t=(0,_cacheSignature.signCache)(e);const i=await getLicenseStorage();await i.setItem(_config.LICENSE_STORAGE_KEY,JSON.stringify(t));return t}async loadCachedLicense(){try{const e=await getLicenseStorage();const t=await e.getItem(_config.LICENSE_STORAGE_KEY);if(!t)return null;const i=JSON.parse(t);return i}catch(e){console.warn("[Buoy] Error loading cached license:",e);return null}}async clearCachedLicense(){this.cachedLicense=null;try{const e=await getLicenseStorage();await e.removeItem(_config.LICENSE_STORAGE_KEY)}catch{}}registerDeviceAsync(e,t,i,s){const r=(0,_fingerprint.getDeviceMetadata)();(0,_api.activateMachine)(e,t,i,s,r).catch(n=>{if(n.message!=="FINGERPRINT_TAKEN"&&n.message!=="MACHINE_LIMIT_EXCEEDED"){console.warn("[Buoy] Device registration failed (non-blocking):",n.message)}})}validateInBackground(e){const t=this.generation;(0,_api.validateLicense)(e).then(async i=>{if(t!==this.generation)return;const s=(0,_api.parseValidationResult)(i);if(s.valid&&i.data){const r=(0,_tier.resolveTier)(i.data);this.applyTier(r);const n=Date.now();this.cachedLicense=await this.persistCache({...this.cachedLicense??{},licenseKey:e,licenseId:i.data.id,valid:true,isPro:r==="pro",tier:r,expiresAt:i.data.attributes.expiry??null,cachedAt:n,lastValidatedAt:n});this.state.expiresAt=i.data.attributes.expiry?new Date(i.data.attributes.expiry):null;this.emit({type:"validated",isPro:this.state.isPro})}else if((0,_api.isFatalLicenseError)(s.code)){console.warn("[React Buoy] Background validation: license is invalid -",s.code);this.applyTier((0,_tier.tierAfterFatalError)(s.code));await this.clearCachedLicense();this.emit({type:"deactivated",isPro:false})}}).catch(i=>{console.warn("[React Buoy] Background validation failed:",i)})}startRevalidationTimer(){if(this.revalidationTimer){clearInterval(this.revalidationTimer)}this.revalidationTimer=setInterval(()=>{if(this.state.licenseKey&&!this.state.isValidating){this.validateInBackground(this.state.licenseKey)}},_config.LICENSE_REVALIDATION_INTERVAL);if(__DEV__){global.__LICENSE_MANAGER_TIMER__=this.revalidationTimer}}stopRevalidationTimer(){if(this.revalidationTimer){clearInterval(this.revalidationTimer);this.revalidationTimer=null}}async forceReregister(){if(this.cachedLicense){this.cachedLicense.fingerprint=void 0;this.cachedLicense.deviceName=void 0}await this.clearCachedLicense()}}const LicenseManager=exports.LicenseManager=new LicenseManagerImpl;if(__DEV__){if(global.__LICENSE_MANAGER_TIMER__){clearInterval(global.__LICENSE_MANAGER_TIMER__)}}
|
package/lib/commonjs/config.js
CHANGED
|
@@ -13,4 +13,4 @@
|
|
|
13
13
|
*
|
|
14
14
|
* Pro is $9/mo, and is free for everyone every weekend. Buy a key at
|
|
15
15
|
* https://buoy.gg or use it free on Saturday and Sunday.
|
|
16
|
-
*/const KEYGEN_CONFIG=exports.KEYGEN_CONFIG={accountId:"b0eba0e8-e904-4906-b644-38f9aab57bed",productId:"bf67cb43-eeef-40ca-b308-e6e1b22c0eaa",productToken:"prod-4467c14b75b715e91884945cd3e69705846ccbce7dd5e380236a1ab3bc03139fv3",apiUrl:"https://api.keygen.sh/v1/accounts"};const KEYGEN_POLICIES=exports.KEYGEN_POLICIES={free:"394e3351-1249-4f73-807a-703408604c0e",solo:"fa5d3c8f-5379-40f1-b63e-ab8a974b2f28",business:"690c2212-8e54-426f-b4b4-002ee1c0ae2b"};const LICENSE_CACHE_DURATION=exports.LICENSE_CACHE_DURATION=30*24*60*60*1e3;const LICENSE_REVALIDATION_INTERVAL=exports.LICENSE_REVALIDATION_INTERVAL=24*60*60*1e3;const LICENSE_STORAGE_KEY=exports.LICENSE_STORAGE_KEY="buoy-gg-license";const ANONYMOUS_TIER_ENABLED=exports.ANONYMOUS_TIER_ENABLED=
|
|
16
|
+
*/const KEYGEN_CONFIG=exports.KEYGEN_CONFIG={accountId:"b0eba0e8-e904-4906-b644-38f9aab57bed",productId:"bf67cb43-eeef-40ca-b308-e6e1b22c0eaa",productToken:"prod-4467c14b75b715e91884945cd3e69705846ccbce7dd5e380236a1ab3bc03139fv3",apiUrl:"https://api.keygen.sh/v1/accounts"};const KEYGEN_POLICIES=exports.KEYGEN_POLICIES={free:"394e3351-1249-4f73-807a-703408604c0e",solo:"fa5d3c8f-5379-40f1-b63e-ab8a974b2f28",business:"690c2212-8e54-426f-b4b4-002ee1c0ae2b"};const LICENSE_CACHE_DURATION=exports.LICENSE_CACHE_DURATION=30*24*60*60*1e3;const LICENSE_REVALIDATION_INTERVAL=exports.LICENSE_REVALIDATION_INTERVAL=24*60*60*1e3;const LICENSE_STORAGE_KEY=exports.LICENSE_STORAGE_KEY="buoy-gg-license";const ANONYMOUS_TIER_ENABLED=exports.ANONYMOUS_TIER_ENABLED=true;
|
|
@@ -12,4 +12,4 @@
|
|
|
12
12
|
*
|
|
13
13
|
* Pro is $9/mo, and is free for everyone every weekend. Buy a key at
|
|
14
14
|
* https://buoy.gg or use it free on Saturday and Sunday.
|
|
15
|
-
*/const
|
|
15
|
+
*/const S="buoy-license";let c=null;let h=null;const y=new Map;function v(){if(c)return c;try{const a=require("expo-file-system/legacy");c=a?.default||a;if(c?.documentDirectory){return c}c=null}catch{}try{const a=require("expo-file-system");c=a?.default||a;if(c?.documentDirectory){return c}c=null}catch{}return null}function L(){const a=v();if(!a?.documentDirectory)return null;return`${a.documentDirectory}${S}/`}function g(a){const e=L();if(!e)return null;return`${e}${encodeURIComponent(a)}.json`}async function m(){if(h)return h;const a=v();if(a?.documentDirectory){h={async getItem(e){const t=g(e);if(!t)return null;try{const i=await a.getInfoAsync(t);if(!i.exists)return null;return await a.readAsStringAsync(t)}catch{return null}},async setItem(e,t){const i=L();const s=g(e);if(!i||!s)return;try{const r=await a.getInfoAsync(i);if(!r.exists){await a.makeDirectoryAsync(i,{intermediates:true})}await a.writeAsStringAsync(s,t)}catch(r){console.warn("[Buoy] License storage write failed:",r)}},async removeItem(e){const t=g(e);if(!t)return;try{await a.deleteAsync(t,{idempotent:true})}catch{}}}}else{h={async getItem(e){return y.get(e)??null},async setItem(e,t){y.set(e,t)},async removeItem(e){y.delete(e)}}}return h}import{LICENSE_STORAGE_KEY as p,LICENSE_CACHE_DURATION as x,LICENSE_REVALIDATION_INTERVAL as V}from"./config.js";import{validateLicense as E,activateMachine as w,parseValidationResult as A,isFatalLicenseError as _}from"./api.js";import{generateUUID as b,getDeviceMetadata as C,getDefaultDeviceName as R}from"./fingerprint";import{signCache as k,verifyCacheSignature as M}from"./cacheSignature.js";import{resolveTier as T,tierAfterFatalError as P}from"./tier.js";function D(a){if(a.tier)return a.tier;return a.isPro?"pro":"anonymous"}class B{state={isInitialized:false,isValidating:false,isPro:false,tier:"anonymous",tierSource:"none",licenseKey:null,error:null,expiresAt:null};listeners=new Set;revalidationTimer=null;cachedLicense=null;initPromise=null;generation=0;deviceRegistrationCallback=null;pendingRegistration=null;async initialize(){if(this.initPromise)return this.initPromise;if(this.state.isInitialized)return;this.initPromise=this._doInitialize();return this.initPromise}async _doInitialize(){if(this.state.isInitialized)return;try{const e=await this.loadCachedLicense();if(e){const t=M(e);this.cachedLicense=e;this.state.licenseKey=e.licenseKey;this.applyTier(t&&this.isCacheValid(e)?D(e):"anonymous");this.state.expiresAt=e.expiresAt?new Date(e.expiresAt):null;if(e.licenseKey){this.validateInBackground(e.licenseKey)}}this.state.isInitialized=true;this.emit({type:"initialized",isPro:this.state.isPro});this.startRevalidationTimer()}catch(e){console.warn("[React Buoy] License initialization failed:",e);this.state.isInitialized=true;this.emit({type:"initialized",isPro:false})}}async setLicenseKey(e){if(!e||e.trim().length===0){this.state.error="License key is required";return false}const t=e.trim().toUpperCase();this.generation+=1;const i=this.generation;this.state.licenseKey=t;this.state.isValidating=true;this.state.error=null;this.emit({type:"validating",isPro:this.state.isPro});try{const s=await E(t);if(i!==this.generation)return false;const r=A(s);if(_(r.code)){this.applyTier(P(r.code));this.state.isValidating=false;this.state.error=r.detail;await this.clearCachedLicense();this.emit({type:"error",isPro:false,error:r.detail});return false}if(!s.data){this.state.isValidating=false;this.state.error=r.detail||"License not found";await this.clearCachedLicense();this.emit({type:"error",isPro:false,error:this.state.error});return false}const n=T(s.data);this.applyTier(n);this.state.isValidating=false;this.state.expiresAt=s.data.attributes.expiry?new Date(s.data.attributes.expiry):null;const o=s.data.id;const l=Date.now();let d=this.cachedLicense?.fingerprint;let u=this.cachedLicense?.deviceName;let I=false;if(!d){d=b();u=R();I=true}let f=false;if(I){if(this.deviceRegistrationCallback){this.pendingRegistration={licenseId:o,licenseKey:t,fingerprint:d};this.deviceRegistrationCallback({fingerprint:d,defaultName:u});f=true}else{this.registerDeviceAsync(o,t,d,u)}}const N={licenseKey:t,licenseId:o,valid:true,isPro:n==="pro",tier:n,expiresAt:s.data.attributes.expiry??null,cachedAt:l,lastValidatedAt:l,fingerprint:f?void 0:d,deviceName:f?void 0:u};this.cachedLicense=await this.persistCache(N);this.emit({type:"validated",isPro:this.state.isPro});return true}catch(s){const r=s instanceof Error?s.message:"Validation failed";if(i!==this.generation)return false;if(this.isNetworkError(s)&&this.cachedLicense&&this.isCacheValid(this.cachedLicense)){this.applyTier(D(this.cachedLicense));this.state.isValidating=false;this.emit({type:"validated",isPro:this.state.isPro});return true}this.state.isValidating=false;this.state.error=r;this.emit({type:"error",isPro:false,error:r});return false}}isNetworkError(e){if(e instanceof TypeError){return true}if(e instanceof Error){const t=e.message.toLowerCase();return t.includes("network")||t.includes("fetch")||t.includes("timeout")||t.includes("connection")||t.includes("offline")||t.includes("failed to fetch")}return false}async clearLicense(){this.generation+=1;this.state.licenseKey=null;this.applyTier("anonymous");this.state.expiresAt=null;this.state.error=null;this.cachedLicense=null;await this.clearCachedLicense();this.emit({type:"deactivated",isPro:false})}applyTier(e){this.state.tier=e;this.state.tierSource=e==="anonymous"?"none":"key";this.state.isPro=e==="pro"}getTier(){return this.state.tier}isPro(){return this.state.tier==="pro"}hasEntitlement(e){if(e==="PRO"){return this.state.isPro}return this.state.isPro}getState(){return{...this.state}}subscribe(e){this.listeners.add(e);return()=>this.listeners.delete(e)}onDeviceRegistrationNeeded(e){this.deviceRegistrationCallback=e;return()=>{this.deviceRegistrationCallback=null}}async completeDeviceRegistration(e){if(!this.pendingRegistration){console.warn("[Buoy] No pending device registration");return}const{licenseId:t,licenseKey:i,fingerprint:s}=this.pendingRegistration;const r=e.trim()||R();const n=C();try{await w(t,i,s,r,n)}catch(o){const l=o instanceof Error?o.message:String(o);if(l==="FINGERPRINT_TAKEN"||l==="MACHINE_LIMIT_EXCEEDED"){}else{console.warn("[Buoy] Device registration failed:",l);throw o}}if(this.cachedLicense){this.cachedLicense.fingerprint=s;this.cachedLicense.deviceName=r;this.cachedLicense=await this.persistCache(this.cachedLicense)}this.pendingRegistration=null}emit(e){const t=[...this.listeners];t.forEach(i=>{try{i(e)}catch(s){console.warn("[React Buoy] License listener error:",s)}})}isCacheValid(e){const t=Date.now();const i=t-e.cachedAt;if(i>x){return false}if(e.expiresAt){const s=new Date(e.expiresAt).getTime();if(t>s){return false}}return true}async persistCache(e){const t=k(e);const i=await m();await i.setItem(p,JSON.stringify(t));return t}async loadCachedLicense(){try{const e=await m();const t=await e.getItem(p);if(!t)return null;const i=JSON.parse(t);return i}catch(e){console.warn("[Buoy] Error loading cached license:",e);return null}}async clearCachedLicense(){this.cachedLicense=null;try{const e=await m();await e.removeItem(p)}catch{}}registerDeviceAsync(e,t,i,s){const r=C();w(e,t,i,s,r).catch(n=>{if(n.message!=="FINGERPRINT_TAKEN"&&n.message!=="MACHINE_LIMIT_EXCEEDED"){console.warn("[Buoy] Device registration failed (non-blocking):",n.message)}})}validateInBackground(e){const t=this.generation;E(e).then(async i=>{if(t!==this.generation)return;const s=A(i);if(s.valid&&i.data){const r=T(i.data);this.applyTier(r);const n=Date.now();this.cachedLicense=await this.persistCache({...this.cachedLicense??{},licenseKey:e,licenseId:i.data.id,valid:true,isPro:r==="pro",tier:r,expiresAt:i.data.attributes.expiry??null,cachedAt:n,lastValidatedAt:n});this.state.expiresAt=i.data.attributes.expiry?new Date(i.data.attributes.expiry):null;this.emit({type:"validated",isPro:this.state.isPro})}else if(_(s.code)){console.warn("[React Buoy] Background validation: license is invalid -",s.code);this.applyTier(P(s.code));await this.clearCachedLicense();this.emit({type:"deactivated",isPro:false})}}).catch(i=>{console.warn("[React Buoy] Background validation failed:",i)})}startRevalidationTimer(){if(this.revalidationTimer){clearInterval(this.revalidationTimer)}this.revalidationTimer=setInterval(()=>{if(this.state.licenseKey&&!this.state.isValidating){this.validateInBackground(this.state.licenseKey)}},V);if(__DEV__){global.__LICENSE_MANAGER_TIMER__=this.revalidationTimer}}stopRevalidationTimer(){if(this.revalidationTimer){clearInterval(this.revalidationTimer);this.revalidationTimer=null}}async forceReregister(){if(this.cachedLicense){this.cachedLicense.fingerprint=void 0;this.cachedLicense.deviceName=void 0}await this.clearCachedLicense()}}export const LicenseManager=new B;if(__DEV__){if(global.__LICENSE_MANAGER_TIMER__){clearInterval(global.__LICENSE_MANAGER_TIMER__)}}
|
package/lib/module/config.js
CHANGED
|
@@ -13,4 +13,4 @@
|
|
|
13
13
|
*
|
|
14
14
|
* Pro is $9/mo, and is free for everyone every weekend. Buy a key at
|
|
15
15
|
* https://buoy.gg or use it free on Saturday and Sunday.
|
|
16
|
-
*/export const KEYGEN_CONFIG={accountId:"b0eba0e8-e904-4906-b644-38f9aab57bed",productId:"bf67cb43-eeef-40ca-b308-e6e1b22c0eaa",productToken:"prod-4467c14b75b715e91884945cd3e69705846ccbce7dd5e380236a1ab3bc03139fv3",apiUrl:"https://api.keygen.sh/v1/accounts"};export const KEYGEN_POLICIES={free:"394e3351-1249-4f73-807a-703408604c0e",solo:"fa5d3c8f-5379-40f1-b63e-ab8a974b2f28",business:"690c2212-8e54-426f-b4b4-002ee1c0ae2b"};export const LICENSE_CACHE_DURATION=30*24*60*60*1e3;export const LICENSE_REVALIDATION_INTERVAL=24*60*60*1e3;export const LICENSE_STORAGE_KEY="buoy-gg-license";export const ANONYMOUS_TIER_ENABLED=
|
|
16
|
+
*/export const KEYGEN_CONFIG={accountId:"b0eba0e8-e904-4906-b644-38f9aab57bed",productId:"bf67cb43-eeef-40ca-b308-e6e1b22c0eaa",productToken:"prod-4467c14b75b715e91884945cd3e69705846ccbce7dd5e380236a1ab3bc03139fv3",apiUrl:"https://api.keygen.sh/v1/accounts"};export const KEYGEN_POLICIES={free:"394e3351-1249-4f73-807a-703408604c0e",solo:"fa5d3c8f-5379-40f1-b63e-ab8a974b2f28",business:"690c2212-8e54-426f-b4b4-002ee1c0ae2b"};export const LICENSE_CACHE_DURATION=30*24*60*60*1e3;export const LICENSE_REVALIDATION_INTERVAL=24*60*60*1e3;export const LICENSE_STORAGE_KEY="buoy-gg-license";export const ANONYMOUS_TIER_ENABLED=true;
|
|
@@ -27,6 +27,19 @@ declare class LicenseManagerImpl {
|
|
|
27
27
|
private revalidationTimer;
|
|
28
28
|
private cachedLicense;
|
|
29
29
|
private initPromise;
|
|
30
|
+
/**
|
|
31
|
+
* Bumped whenever the license is deliberately changed or cleared.
|
|
32
|
+
*
|
|
33
|
+
* `initialize()` kicks off a background revalidation of the cached key and
|
|
34
|
+
* does NOT await it, so a `clearLicense()` that lands in between would be
|
|
35
|
+
* silently undone: the in-flight response re-applies the old tier and
|
|
36
|
+
* re-persists the cache blob that was just deleted. Removing a key would
|
|
37
|
+
* then appear to do nothing — Pro comes straight back a moment later.
|
|
38
|
+
*
|
|
39
|
+
* Background work captures this value when it starts and drops its result if
|
|
40
|
+
* it no longer matches.
|
|
41
|
+
*/
|
|
42
|
+
private generation;
|
|
30
43
|
private deviceRegistrationCallback;
|
|
31
44
|
private pendingRegistration;
|
|
32
45
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LicenseManager.d.ts","sourceRoot":"","sources":["../../../src/LicenseManager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;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YACW,aAAa;IA4C3B;;;;;;OAMG;IACG,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IA6IzD;;OAEG;IACH,OAAO,CAAC,cAAc;IAkBtB;;OAEG;IACG,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAanC;;;;;OAKG;IACH,OAAO,CAAC,SAAS;IAQjB;;OAEG;IACH,OAAO,IAAI,QAAQ;IAInB;;OAEG;IACH,KAAK,IAAI,OAAO;IAIhB;;OAEG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAOrC;;OAEG;IACH,QAAQ,IAAI,QAAQ,CAAC,YAAY,CAAC;IAIlC;;OAEG;IACH,SAAS,CAAC,QAAQ,EAAE,eAAe,GAAG,MAAM,IAAI;IAKhD;;;;;OAKG;IACH,0BAA0B,CAAC,QAAQ,EAAE,0BAA0B,GAAG,MAAM,IAAI;IAO5E;;;OAGG;IACG,0BAA0B,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAoCnE,OAAO,CAAC,IAAI;IAYZ,OAAO,CAAC,YAAY;IAkBpB;;;;OAIG;YACW,YAAY;YAOZ,iBAAiB;YAcjB,kBAAkB;IAWhC;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAiB3B,OAAO,CAAC,oBAAoB;IAmD5B,OAAO,CAAC,sBAAsB;IAmB9B;;OAEG;IACH,qBAAqB,IAAI,IAAI;IAO7B;;;OAGG;IACG,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;CAOvC;AAGD,eAAO,MAAM,cAAc,oBAA2B,CAAC"}
|
|
@@ -70,5 +70,5 @@ export declare const LICENSE_STORAGE_KEY = "buoy-gg-license";
|
|
|
70
70
|
* grace period, so a user who wakes up with less needs a twenty-second way out
|
|
71
71
|
* — and the CLI only exists for them once @buoy-gg/core ships with its bin.
|
|
72
72
|
*/
|
|
73
|
-
export declare const ANONYMOUS_TIER_ENABLED =
|
|
73
|
+
export declare const ANONYMOUS_TIER_ENABLED = true;
|
|
74
74
|
//# sourceMappingURL=config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH;;GAEG;AAEH,eAAO,MAAM,aAAa;;IAExB;;;;;;;;OAQG;;;;CAMK,CAAC;AAEX;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe;IAC1B,iEAAiE;;IAEjE,qEAAqE;;IAErE,oDAAoD;;CAE5C,CAAC;AAGX,eAAO,MAAM,sBAAsB,QAA2B,CAAC;AAI/D,eAAO,MAAM,6BAA6B,QAAsB,CAAC;AAIjE,eAAO,MAAM,mBAAmB,oBAAoB,CAAC;AAErD;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,sBAAsB,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH;;GAEG;AAEH,eAAO,MAAM,aAAa;;IAExB;;;;;;;;OAQG;;;;CAMK,CAAC;AAEX;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe;IAC1B,iEAAiE;;IAEjE,qEAAqE;;IAErE,oDAAoD;;CAE5C,CAAC;AAGX,eAAO,MAAM,sBAAsB,QAA2B,CAAC;AAI/D,eAAO,MAAM,6BAA6B,QAAsB,CAAC;AAIjE,eAAO,MAAM,mBAAmB,oBAAoB,CAAC;AAErD;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,sBAAsB,OAAO,CAAC"}
|
|
@@ -27,6 +27,19 @@ declare class LicenseManagerImpl {
|
|
|
27
27
|
private revalidationTimer;
|
|
28
28
|
private cachedLicense;
|
|
29
29
|
private initPromise;
|
|
30
|
+
/**
|
|
31
|
+
* Bumped whenever the license is deliberately changed or cleared.
|
|
32
|
+
*
|
|
33
|
+
* `initialize()` kicks off a background revalidation of the cached key and
|
|
34
|
+
* does NOT await it, so a `clearLicense()` that lands in between would be
|
|
35
|
+
* silently undone: the in-flight response re-applies the old tier and
|
|
36
|
+
* re-persists the cache blob that was just deleted. Removing a key would
|
|
37
|
+
* then appear to do nothing — Pro comes straight back a moment later.
|
|
38
|
+
*
|
|
39
|
+
* Background work captures this value when it starts and drops its result if
|
|
40
|
+
* it no longer matches.
|
|
41
|
+
*/
|
|
42
|
+
private generation;
|
|
30
43
|
private deviceRegistrationCallback;
|
|
31
44
|
private pendingRegistration;
|
|
32
45
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LicenseManager.d.ts","sourceRoot":"","sources":["../../../src/LicenseManager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AA8KH,OAAO,KAAK,EACV,QAAQ,EAER,YAAY,EAEZ,eAAe,EAChB,MAAM,SAAS,CAAC;AAEjB,kDAAkD;AAClD,MAAM,WAAW,sBAAsB;IACrC,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,mDAAmD;AACnD,MAAM,MAAM,0BAA0B,GAAG,CAAC,IAAI,EAAE,sBAAsB,KAAK,IAAI,CAAC;AAsBhF,cAAM,kBAAkB;IACtB,OAAO,CAAC,KAAK,CASX;IAEF,OAAO,CAAC,SAAS,CAAmC;IACpD,OAAO,CAAC,iBAAiB,CAA+C;IACxE,OAAO,CAAC,aAAa,CAA8B;IAGnD,OAAO,CAAC,WAAW,CAA8B;
|
|
1
|
+
{"version":3,"file":"LicenseManager.d.ts","sourceRoot":"","sources":["../../../src/LicenseManager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AA8KH,OAAO,KAAK,EACV,QAAQ,EAER,YAAY,EAEZ,eAAe,EAChB,MAAM,SAAS,CAAC;AAEjB,kDAAkD;AAClD,MAAM,WAAW,sBAAsB;IACrC,WAAW,EAAE,MAAM,CAAC;IACpB,W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,iBAAiB;YAcjB,kBAAkB;IAWhC;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAiB3B,OAAO,CAAC,oBAAoB;IAmD5B,OAAO,CAAC,sBAAsB;IAmB9B;;OAEG;IACH,qBAAqB,IAAI,IAAI;IAO7B;;;OAGG;IACG,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;CAOvC;AAGD,eAAO,MAAM,cAAc,oBAA2B,CAAC"}
|
|
@@ -70,5 +70,5 @@ export declare const LICENSE_STORAGE_KEY = "buoy-gg-license";
|
|
|
70
70
|
* grace period, so a user who wakes up with less needs a twenty-second way out
|
|
71
71
|
* — and the CLI only exists for them once @buoy-gg/core ships with its bin.
|
|
72
72
|
*/
|
|
73
|
-
export declare const ANONYMOUS_TIER_ENABLED =
|
|
73
|
+
export declare const ANONYMOUS_TIER_ENABLED = true;
|
|
74
74
|
//# sourceMappingURL=config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH;;GAEG;AAEH,eAAO,MAAM,aAAa;;IAExB;;;;;;;;OAQG;;;;CAMK,CAAC;AAEX;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe;IAC1B,iEAAiE;;IAEjE,qEAAqE;;IAErE,oDAAoD;;CAE5C,CAAC;AAGX,eAAO,MAAM,sBAAsB,QAA2B,CAAC;AAI/D,eAAO,MAAM,6BAA6B,QAAsB,CAAC;AAIjE,eAAO,MAAM,mBAAmB,oBAAoB,CAAC;AAErD;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,sBAAsB,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH;;GAEG;AAEH,eAAO,MAAM,aAAa;;IAExB;;;;;;;;OAQG;;;;CAMK,CAAC;AAEX;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe;IAC1B,iEAAiE;;IAEjE,qEAAqE;;IAErE,oDAAoD;;CAE5C,CAAC;AAGX,eAAO,MAAM,sBAAsB,QAA2B,CAAC;AAI/D,eAAO,MAAM,6BAA6B,QAAsB,CAAC;AAIjE,eAAO,MAAM,mBAAmB,oBAAoB,CAAC;AAErD;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,sBAAsB,OAAO,CAAC"}
|