@jolibox/common 1.2.5-beta.3 → 1.2.5

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/dist/index.cjs.js CHANGED
@@ -1 +1 @@
1
- "use strict";var S=Object.defineProperty,Ge=Object.defineProperties,ve=Object.getOwnPropertyDescriptor,Je=Object.getOwnPropertyDescriptors,ze=Object.getOwnPropertyNames,xe=Object.getOwnPropertySymbols;var Ee=Object.prototype.hasOwnProperty,We=Object.prototype.propertyIsEnumerable;var _e=(t,e,n)=>e in t?S(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,T=(t,e)=>{for(var n in e||(e={}))Ee.call(e,n)&&_e(t,n,e[n]);if(xe)for(var n of xe(e))We.call(e,n)&&_e(t,n,e[n]);return t},L=(t,e)=>Ge(t,Je(e));var Ce=(t,e)=>{for(var n in e)S(t,n,{get:e[n],enumerable:!0})},Be=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ze(e))!Ee.call(t,o)&&o!==n&&S(t,o,{get:()=>e[o],enumerable:!(r=ve(e,o))||r.enumerable});return t};var Qe=t=>Be(S({},"__esModule",{value:!0}),t),q=(t,e,n,r)=>{for(var o=r>1?void 0:r?ve(e,n):e,s=t.length-1,i;s>=0;s--)(i=t[s])&&(o=(r?i(e,n,o):i(o))||o);return r&&o&&S(e,n,o),o};var h=(t,e,n)=>new Promise((r,o)=>{var s=a=>{try{c(n.next(a))}catch(u){o(u)}},i=a=>{try{c(n.throw(a))}catch(u){o(u)}},c=a=>a.done?r(a.value):Promise.resolve(a.value).then(s,i);c((n=n.apply(t,e)).next())});var Ft={};Ce(Ft,{ADVERTISING_ID:()=>qe,APIError:()=>ae,BaseError:()=>b,DEVICE_ID:()=>Le,Deferred:()=>H,EPlatform:()=>De,EProject:()=>Oe,EventEmitter:()=>I,EventType:()=>Se,EventUtils:()=>v,InternalApplyNativeError:()=>te,InternalBufferError:()=>oe,InternalContextError:()=>se,InternalError:()=>p,InternalGlobalJSError:()=>ie,InternalInvokeMethodError:()=>ne,InternalInvokeNativeError:()=>Z,InternalJSCoreNotFoundError:()=>re,InternalJSModuleEvalError:()=>X,InternalJSModuleFetchError:()=>Y,InternalMetricReportError:()=>ce,InternalPaymentError:()=>ee,InternalReporterError:()=>le,InternalSchemaParseError:()=>Q,LoadScriptCode:()=>Ie,RequestCacheService:()=>ge,Singleton:()=>O,UserCustomError:()=>D,UserError:()=>y,UserFetchError:()=>z,UserFunctionEvalError:()=>B,UserGlobalError:()=>J,UserPaymentError:()=>W,UserValidateError:()=>G,canIUseConfig:()=>ht,canIUseConfigNative:()=>yt,compareVersion:()=>Tt,createCommands:()=>Vt,createRunTaskQueue:()=>et,debounce:()=>ut,get:()=>gt,getAdvertisingId:()=>Ue,getApiDomain:()=>Fe,getApiHost:()=>wt,getCollectDomain:()=>$e,getCollectHost:()=>St,getDeviceId:()=>Me,getH5ApiHost:()=>It,getH5Domain:()=>Nt,getOriginalLocalStorage:()=>fe,getPlatform:()=>ke,getStorage:()=>he,getUtmSource:()=>Ve,hostEmitter:()=>qt,isArray:()=>rt,isBoolean:()=>it,isDefined:()=>at,isFunction:()=>V,isIterable:()=>st,isNative:()=>Pe,isNumber:()=>ot,isObject:()=>be,isPromiseLike:()=>ct,isString:()=>M,isStringArray:()=>tt,isTypedArray:()=>nt,isUndefined:()=>Ae,isUndefinedOrNull:()=>U,isValidUUIDV4:()=>Ct,logger:()=>de,mergeArray:()=>dt,mergeWith:()=>lt,microTask:()=>Ze,platform:()=>k,promisifyAPI:()=>Xe,serializeEventPackage:()=>Et,sleep:()=>Ye,timeout:()=>K,uuidv4:()=>pe,validateConstraint:()=>He,validateConstraints:()=>ye,wrapUserFunction:()=>pt,xUserAgent:()=>At});module.exports=Qe(Ft);if(typeof window!="undefined"&&!window.AbortController){let t=function(){this.signal=new e};t.prototype.abort=function(){this.signal._aborted=!0,typeof this.signal.onabort=="function"&&this.signal.onabort(new Event("abort"));let n=new Event("abort");this.signal.dispatchEvent(n)};let e=function(){this._aborted=!1,this.aborted=!1,this.onabort=null,this._eventListeners={}};Object.defineProperty(e.prototype,"aborted",{get:function(){return this._aborted}}),e.prototype.addEventListener=function(n,r){this._eventListeners[n]||(this._eventListeners[n]=[]),this._eventListeners[n].push(r)},e.prototype.removeEventListener=function(n,r){if(!this._eventListeners[n])return;let o=this._eventListeners[n].indexOf(r);o!==-1&&this._eventListeners[n].splice(o,1)},e.prototype.dispatchEvent=function(n){if(this._eventListeners[n.type])for(let r of this._eventListeners[n.type])r.call(this,n)},window.AbortController=t,window.AbortSignal=e}function K(t){return new Promise(e=>{setTimeout(()=>{e()},t)})}function Ye(t){return new Promise(e=>setTimeout(e,t))}function Xe(t){return e=>new Promise((n,r)=>{t(L(T({},e),{success:n,fail(o){let s=new Error(o.errMsg);r(s)}}))})}function Ze(t){if(t)Promise.resolve().then(t);else return Promise.resolve()}var H=class{constructor(){this.state="pending";this.promise=new Promise((e,n)=>{this.resolve=r=>{this.state==="pending"&&(this.state="fulfilled",e(r))},this.reject=r=>{this.state==="pending"&&(this.state="rejected",n(r))}})}};function et(){let t=[],e=!1,n=()=>h(this,null,function*(){let r=t.shift();if(r){e=!0;try{yield r()}finally{e=!1,n()}}});return r=>{t.push(r),e||n()}}function M(t){return typeof t=="string"}function tt(t){return Array.isArray(t)&&t.every(e=>M(e))}function be(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)&&!(t instanceof RegExp)&&!(t instanceof Date)}function nt(t){let e=Object.getPrototypeOf(Uint8Array);return typeof t=="object"&&t instanceof e}function rt(t){return typeof t=="object"&&Array.isArray(t)}function ot(t){return typeof t=="number"&&!isNaN(t)}function st(t){return!!t&&typeof t[Symbol.iterator]=="function"}function it(t){return t===!0||t===!1}function Ae(t){return typeof t=="undefined"}function at(t){return!U(t)}function U(t){return Ae(t)||t===null}function V(t){return typeof t=="function"}function ct(t){return be(t)&&V(t.then)}function O(t){let e=t,n=null,r=function(...o){return n||(n=new e(...o)),n};return r.prototype=e.prototype,r}function lt(t,e,n){if(typeof n!="function")throw new Error("[Jolibox SDK]Customizer must be a function");function r(o,s){for(let i in s)if(Object.prototype.hasOwnProperty.call(s,i)){let c=o[i],a=s[i],u=n(c,a,i,o,s);u!==void 0?o[i]=u:we(a)&&we(c)?o[i]=r(T({},c),a):Array.isArray(a)&&Array.isArray(c)?o[i]=[...c,...a]:o[i]=a}return o}return r(t,e)}function we(t){return t&&typeof t=="object"&&t.constructor===Object}function dt(t,e){if(Array.isArray(t))return t.concat(e)}function ut(t,e,n={}){let r=null,o,s,i,{leading:c=!1,trailing:a=!0}=n,u=()=>(i=t.apply(s,o),o=void 0,s=void 0,i),d=function(...R){o=R,s=this;let f=c&&!r;if(r&&clearTimeout(r),r=setTimeout(()=>{r=null,a&&!f&&u()},e),f)return u()};return d.cancel=()=>{r&&clearTimeout(r),r=null,o=s=void 0},d.flush=()=>{if(r)return clearTimeout(r),r=null,u()},d}var Ie=(a=>(a[a.DEVELOPER_FILE_NOT_FOUND=0]="DEVELOPER_FILE_NOT_FOUND",a[a.INTERNAL_IOS_CAN_NOT_FOUND_PKG=1]="INTERNAL_IOS_CAN_NOT_FOUND_PKG",a[a.USER_IOS_LOAD_TIMEOUT=2]="USER_IOS_LOAD_TIMEOUT",a[a.INTERNAL_IOS_PKG_LOAD_ERROR=3]="INTERNAL_IOS_PKG_LOAD_ERROR",a[a.INTERNAL_IOS_PKG_PARSE_FAIL=4]="INTERNAL_IOS_PKG_PARSE_FAIL",a[a.USER_IOS_GET_EMPTY_DATA=5]="USER_IOS_GET_EMPTY_DATA",a[a.USER_ANDROID_GET_PKG_FAIL=6]="USER_ANDROID_GET_PKG_FAIL",a[a.DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE=7]="DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE",a))(Ie||{}),b=class extends Error{constructor(e){if(typeof e=="string"){super(e),this.priority="P1";return}super(e.message),this.priority="P1",this.stack=e.stack,this.raw=e}},p=class extends b{constructor(){super(...arguments);this.kind="INTERNAL_ERROR"}},y=class extends b{constructor(){super(...arguments);this.kind="USER_ERROR"}},G=class extends y{constructor(){super(...arguments);this.name="USER_VALIDATE_ERROR"}},J=class extends y{constructor(){super(...arguments);this.name="USER_GLOBAL_ERROR";this.priority="P1"}},D=class extends y{constructor(n,r,o){super(n);this.message=n;this.errNo=r;this.name="USER_CUSTOM_ERROR";this.errMsg=n,o&&(this.extra=Object.assign({},this.extra,o))}},z=class extends y{constructor(n,r,o){super(n);this.message=n;this.errNo=r;this.name="USER_FETCH_ERROR";this.errMsg=n,o&&(this.extra=Object.assign({},this.extra,o))}},W=class extends y{constructor(n,r,o){super(n);this.message=n;this.errNo=r;this.name="USER_PAYMENT_ERROR";this.errMsg=n,o&&(this.extra=Object.assign({},this.extra,o))}},B=class extends y{constructor(){super(...arguments);this.name="USER_CALLBACK_ERROR"}},Q=class extends p{constructor(){super(...arguments);this.name="INTERNAL_SCHEMA_PARSE_ERROR";this.priority="P0"}},Y=class extends p{constructor(){super(...arguments);this.name="INTERNAL_JS_MODULE_FETCH_ERROR";this.priority="P0"}},X=class extends p{constructor(){super(...arguments);this.name="INTERNAL_JS_MODULE_EVAL_ERROR";this.priority="P0"}},Z=class extends p{constructor(){super(...arguments);this.name="INTERNAL_INVOKE_NATIVE_ERROR"}},ee=class extends p{constructor(n,r,o){super(n);this.message=n;this.errNo=r;this.name="INTERNAL_PAYMENT_ERROR";this.priority="P0";this.errMsg=n,o&&(this.extra=Object.assign({},this.extra,o))}},te=class extends p{constructor(n,r,o,s){super(n);this.errNo=r;this.name="INTERNAL_APPLY_NATIVE_ERROR";this.errorType=o,this.errorCode=s}},ne=class extends p{constructor(){super(...arguments);this.name="INTERNAL_INVOKE_METHOD_ERROR"}},re=class extends p{constructor(){super(...arguments);this.name="INTERNAL_JSCORE_ERROR";this.priority="P0"}},oe=class extends p{constructor(){super(...arguments);this.name="INTERNAL_BUFFER_ERROR"}},se=class extends p{constructor(n,r){super(n);this.message=n;this.name="INTERNAL_CONTEXT_ERROR";this.property=r}},ie=class extends p{constructor(){super(...arguments);this.name="INTERNAL_GLOBAL_JS_ERROR";this.priority="P1"}},ae=class extends b{constructor(n,r,o,s,i){super(n);this.message=n;this.code=r;this.kind="API_ERROR";this.name="API_ERROR";o&&(this.errorType=o),s!==void 0&&(this.stack=s),i&&(this.priority=i)}toJSON(){return{message:this.message,stack:this.stack,name:this.name,code:this.code,errorType:this.errorType}}},ce=class extends p{constructor(){super(...arguments);this.name="INTERNAL_METRIC_REPORT_ERROR"}},le=class extends p{constructor(){super(...arguments);this.name="INTERNAL_REPORTER_ERROR"}};function mt(t,e){return(...n)=>e(t,...n)}function pt(t){return e=>mt(e,function(n,...r){if(typeof n=="function")try{return n.apply(this,r)}catch(o){t(new D(`${o}`))}})}function P(t){return(...e)=>{var r,o;((o=(r=globalThis.VConsole)==null?void 0:r[t])!=null?o:globalThis.console[t])(...e)}}var de={log:P("log"),warn:P("warn"),info:P("info"),error:P("error"),debug:P("debug")};Object.assign(globalThis,{logger:de});var ue=Symbol.for("Jolibox.canIUseMap"),ft={};globalThis[ue]||(globalThis[ue]=ft);var ht={get config(){return globalThis[ue]}};function gt(t,e,n){let r=t;for(let o of e)if(r&&typeof r=="object")r=r[o];else return n;return r===void 0?n:r}var me=Symbol.for("Jolibox.canIUseMap.native"),Rt={};globalThis[me]||(globalThis[me]=Rt);var yt={get config(){return globalThis[me]}};function Tt(t,e,n){let r=0;if(t!==e){let o=t.split("."),s=e.split("."),i=Math.max(o.length,s.length);for(let c=0;c<i;c++){let a=parseInt(o[c],10)||0,u=parseInt(s[c],10)||0;if(a>u){r=1;break}else if(a<u){r=-1;break}}}if(!n)return r;switch(n){case">":return r>0;case"<":return r<0;case"=":return r===0;case">=":return r>=0;case"<=":return r<=0;default:return!1}}var Se=(l=>(l[l.Other=0]="Other",l[l.Route=1]="Route",l[l.Click=2]="Click",l[l.View=3]="View",l[l.Expose=4]="Expose",l[l.Swipe=5]="Swipe",l[l.Input=6]="Input",l[l.Select=7]="Select",l[l.SwitchOn=8]="SwitchOn",l[l.SwitchOff=9]="SwitchOff",l[l.Submit=10]="Submit",l[l.Scroll=11]="Scroll",l[l.Hide=12]="Hide",l[l.System=1e3]="System",l[l.ErrorTrace=1001]="ErrorTrace",l[l.UserDefined=1002]="UserDefined",l))(Se||{}),Oe=(s=>(s.MiniGame="mini-game",s.MiniDrama="mini-drama",s.App="app",s.WebSDK="web-sdk",s.AppSDK="app-sdk",s))(Oe||{}),De=(d=>(d[d.App=0]="App",d[d.H5=1]="H5",d[d.Weapp=2]="Weapp",d[d.Alipay=3]="Alipay",d[d.Gcash=4]="Gcash",d[d.Dana=5]="Dana",d[d.Umma=6]="Umma",d[d.WebSDK=1e3]="WebSDK",d[d.AppSDK=1001]="AppSDK",d[d.Other=9999]="Other",d))(De||{}),Ne=["name","params"],xt=["name","type","location","target","extra","timestamp","userId"],_t=["platform","os","appVersion","appId","model","brand","uuid","jsSdkVersion","extra"];function F(t,e){return e.map(n=>{if(n==="params"&&t[n]){let r=t[n];return Object.keys(r).reduce((o,s)=>(o[s]=String(r[s]),o),{})}return t[n]})}function vt(t){let e=t.location?F(t.location,Ne):null,n=t.target?F(t.target,Ne):null;return F(L(T({},t),{location:e,target:n}),xt)}function Et(t){let e=t.events.map(r=>vt(r)),n=F(t.device,_t);return[t.protocolVersion,e,n,t.project]}var pe=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{let e=Math.random()*16|0;return(t==="x"?e:e&3|8).toString(16)}),Ct=t=>/^[\da-f]{8}-[\da-f]{4}-4[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i.test(t);function fe(){if(typeof window=="undefined")return{getItem:()=>null,setItem:()=>{},removeItem:()=>{},clear:()=>{},length:0,key:()=>null};try{if(window.__joliboxLocalStorage__)return window.__joliboxLocalStorage__;let t=Object.getOwnPropertyDescriptor(window,"localStorage");if(t&&t.get){let r=t.get.call(window);return window.__joliboxLocalStorage__=r,r}if(t=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(window),"localStorage"),t&&t.get)return t.get.call(window);let e=Window.prototype,n=Object.getOwnPropertyDescriptor(e,"localStorage");if(n&&n.get){let r=n.get.call(window);return window.__joliboxLocalStorage__=r,r}return localStorage}catch(t){return console.warn("Failed to get original localStorage, fallback to default implementation",t),localStorage}}fe();var A=typeof window=="undefined",Pe=()=>!A&&!!(navigator.userAgent||"").includes("JoliboxPlatformSDK"),k={isiOS:!A&&(navigator.userAgent.includes("iPhone")||navigator.userAgent.includes("iPod")||navigator.userAgent.includes("iPad")||navigator.userAgent.includes("iPhone OS")),iosVersion:()=>{let t=navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/);return[parseInt(t[1],10),parseInt(t[2],10),parseInt(t[3]||"0",10)]},isAndroid:!A&&navigator.userAgent.includes("Android"),isMac:!A&&navigator.userAgent.includes("Mac"),isFacebook:!A&&navigator.userAgent.includes("FB_IAB"),isPC:!A&&!navigator.userAgent.includes("iPhone")&&!navigator.userAgent.includes("Android")},ke=()=>k.isiOS?"iOS":k.isAndroid?"Android":k.isMac?"Mac":k.isFacebook?"Facebook":"PC",Le="device_id",qe="advertising_id",he=t=>(window.__joliboxLocalStorage__.getItem(t)||window.__joliboxLocalStorage__.setItem(t,pe()),window.__joliboxLocalStorage__.getItem(t)),Me=()=>{let e=new URLSearchParams(window.location.search).get("deviceId");return e||he(Le)},Ue=()=>{let e=new URLSearchParams(window.location.search).get("advertisingId");return e||he(qe)},bt=t=>t.charAt(0).toUpperCase()+t.slice(1),Ve=()=>{var e;let t=new URLSearchParams(window.location.search);return bt((e=t.get("utm_source"))!=null?e:"")||"JoliboxSDK"},At=t=>{if(Pe())return window.navigator.userAgent;let e="JoliboxWebSDK",n=ke(),r=navigator.language,o=Me(),s=Ue();return`${e} (${Ve()}${n}; UnknownModel; UnknownSystemVersion; ${r}) uuid/${o} adid/${s} version/${t||""}`};function $(t,e,n){let r=window.location.hostname,o=r.split("."),s=n?e:t;if(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(r))return`${s}.jolibox.com`;if(o.length>=2){let c=o.slice(-2).join(".");if(c==="jolibox.com"||c==="pico-game.com"||c==="joyslite.com")return`${s}.${c}`}return`${s}.jolibox.com`}function Fe(t){return $("app","stg-app",t)}function wt(t){return`https://${Fe(t)}`}function It(t){return`https://${$("api","stg-api",t)}`}function Nt(t){return $("api","stg-api",t)}function $e(t){return $("collect","stg-collect",t)}function St(t){return`https://${$e(t)}`}var ge=class{constructor(e,n={}){this.requestAdapter=e;this.cache=new Map;this.pendingRequests=new Map;this.requestSequence=0;this.cacheSequences=new Map;this.config=T({duration:10*60*1e3,timeout:3e3,keyGenerator:(r,o)=>r,consistencyChecker:()=>!0},n)}request(e,n){return h(this,null,function*(){let r=this.config.keyGenerator(e,n),o=this.pendingRequests.get(r);if(o)return console.log(`[RequestCacheService] Reusing pending request for ${e}`),o;let s=this.requestInternal(e,n),i=this.createTimeoutPromise(),c=Promise.race([s,i]).catch(a=>h(this,null,function*(){if(a.message.includes("timeout")){let u=this.getValidCachedData(r);if(u)return console.warn(`[RequestCacheService] Request timeout, falling back to cache for ${e}`),this.requestAdapter.processCachedData?this.requestAdapter.processCachedData(u):u}throw a}));this.pendingRequests.set(r,c),s.then(a=>{console.log(`[RequestCacheService] Background request completed successfully for ${e}`)}).catch(a=>{console.warn(`[RequestCacheService] Background request failed for ${e}:`,a)});try{return yield c}finally{this.pendingRequests.delete(r)}})}requestInternal(e,n){return h(this,null,function*(){var a,u,d,R;let r=this.config.keyGenerator(e,n),o=++this.requestSequence,s=this.getValidCachedData(r);if(console.log("[RequestCacheService] requestInternal start",e,"cached:",s),s){if(this.requestAdapter.extractRealTimeData&&this.requestAdapter.mergeData)try{let f=yield this.requestAdapter.execute(e,n),E=this.requestAdapter.extractRealTimeData(f),C=(u=(a=this.requestAdapter).extractCacheableData)==null?void 0:u.call(a,f);return C&&!this.config.consistencyChecker(s,C)?(console.log(`[RequestCacheService] Cache invalidated due to data change for ${e}`),this.setCachedDataWithSequence(r,C,o),f):this.requestAdapter.mergeData(s,E)}catch(f){return console.warn(`[RequestCacheService] Failed to fetch real-time data, using cache only for ${e}:`,f),this.requestAdapter.processCachedData?this.requestAdapter.processCachedData(s):s}return console.log(`[RequestCacheService] use cache for ${e}`),this.requestAdapter.processCachedData?this.requestAdapter.processCachedData(s):s}console.log(`[RequestCacheService] Cache miss, fetching fresh data for ${e} (sequence: ${o})`);let i=yield this.requestAdapter.execute(e,n),c=(R=(d=this.requestAdapter).extractCacheableData)==null?void 0:R.call(d,i);return c&&this.setCachedDataWithSequence(r,c,o),i})}createTimeoutPromise(){return new Promise((e,n)=>{setTimeout(()=>{n(new Error(`[RequestCacheService] Request timeout after ${this.config.timeout/1e3} seconds`))},this.config.timeout)})}getValidCachedData(e){let n=this.cache.get(e);return n?Date.now()>n.expiresAt?(this.cache.delete(e),null):n.data:null}setCachedDataWithSequence(e,n,r,o){let s=this.cache.get(e);if(s&&s.sequence>r){console.log(`[RequestCacheService] Ignoring stale cache update for ${e} (current: ${s.sequence}, incoming: ${r})`);return}let i=Date.now();this.cache.set(e,{data:JSON.parse(JSON.stringify(n)),timestamp:i,expiresAt:i+this.config.duration,key:e,sequence:r,metadata:o}),this.cacheSequences.set(e,r),console.log(`[RequestCacheService] Updated cache for ${e} with sequence ${r}`)}refreshCache(e,n){return h(this,null,function*(){let r=this.config.keyGenerator(e,n);return this.cache.delete(r),this.request(e,n)})}forceRequest(e,n){return h(this,null,function*(){var c,a;let r=this.config.keyGenerator(e,n),o=++this.requestSequence;console.log(`[RequestCacheService] Force request for ${e} (sequence: ${o})`);let s=yield this.requestAdapter.execute(e,n),i=(a=(c=this.requestAdapter).extractCacheableData)==null?void 0:a.call(c,s);return i&&(this.setCachedDataWithSequence(r,i,o),console.log(`[RequestCacheService] Force updated cache for ${e}`)),s})}warmupCache(e,n){return h(this,null,function*(){let r=this.config.keyGenerator(e,n);if(this.pendingRequests.has(r)){console.log(`[RequestCacheService] Skipping warmup for ${e} - request in progress`);return}if(this.hasValidCache(r)){console.log(`[RequestCacheService] Skipping warmup for ${e} - valid cache exists`);return}try{console.log(`[RequestCacheService] Warming up cache for ${e}`),yield this.forceRequest(e,n)}catch(o){console.warn(`[RequestCacheService] Cache warmup failed for ${e}:`,o)}})}clearCache(e){e?(this.cache.delete(e),this.cacheSequences.delete(e),this.pendingRequests.delete(e),console.log(`[RequestCacheService] Cleared cache for ${e}`)):(this.cache.clear(),this.cacheSequences.clear(),this.pendingRequests.clear(),this.requestSequence=0,console.log("[RequestCacheService] Cleared all cache"))}clearExpiredCache(){let e=Date.now();for(let[n,r]of this.cache)e>r.expiresAt&&(this.cache.delete(n),this.cacheSequences.delete(n));console.log("[RequestCacheService] Cleared expired cache entries")}getCacheStats(){let e=Date.now(),n=0,r=0;for(let o of this.cache.values())e>o.expiresAt?r++:n++;return{cacheCount:this.cache.size,validCount:n,expiredCount:r,pendingRequestCount:this.pendingRequests.size}}getCacheKeys(){return Array.from(this.cache.keys())}hasValidCache(e){let n=this.cache.get(e);return n?Date.now()<=n.expiresAt:!1}getPendingRequestKeys(){return Array.from(this.pendingRequests.keys())}hasPendingRequest(e){return this.pendingRequests.has(e)}getCacheSequence(e){return this.cacheSequences.get(e)}};var w=class w{constructor(e){this.element=e,this.next=w.Undefined,this.prev=w.Undefined}};w.Undefined=new w(void 0);var m=w,j=class{constructor(){this._first=m.Undefined;this._last=m.Undefined;this._size=0}get size(){return this._size}isEmpty(){return this._first===m.Undefined}clear(){let e=this._first;for(;e!==m.Undefined;){let n=e.next;e.prev=m.Undefined,e.next=m.Undefined,e=n}this._first=m.Undefined,this._last=m.Undefined,this._size=0}unshift(e){return this._insert(e,!1)}push(e){return this._insert(e,!0)}_insert(e,n){let r=new m(e);if(this._first===m.Undefined)this._first=r,this._last=r;else if(n){let s=this._last;this._last=r,r.prev=s,s.next=r}else{let s=this._first;this._first=r,r.next=s,s.prev=r}this._size+=1;let o=!1;return()=>{o||(o=!0,this._remove(r))}}shift(){if(this._first!==m.Undefined){let e=this._first.element;return this._remove(this._first),e}}pop(){if(this._last!==m.Undefined){let e=this._last.element;return this._remove(this._last),e}}_remove(e){if(e.prev!==m.Undefined&&e.next!==m.Undefined){let n=e.prev;n.next=e.next,e.next.prev=n}else e.prev===m.Undefined&&e.next===m.Undefined?(this._first=m.Undefined,this._last=m.Undefined):e.next===m.Undefined?(this._last=this._last.prev,this._last.next=m.Undefined):e.prev===m.Undefined&&(this._first=this._first.next,this._first.prev=m.Undefined);this._size-=1}*[Symbol.iterator](){let e=this._first;for(;e!==m.Undefined;)yield e.element,e=e.next}};var Ot=0,_=class{constructor(e){this.value=e;this.id=Ot++}},g=class{constructor(e){this.options=e;this._size=0}dispose(e){var n,r;this._disposed||(this._disposed=!0,this._listeners&&(e?(this._listeners instanceof _&&(this._listeners=[this._listeners]),this._listeners=this._listeners.filter(o=>(o==null?void 0:o.value)===e)):(this._listeners=void 0,this._size=0)),(r=(n=this.options)==null?void 0:n.onDidRemoveLastListener)==null||r.call(n))}get event(){var e;return(e=this._event)!=null||(this._event=(n,r)=>{var s,i,c,a,u,d;if(this._disposed)return()=>{console.info("[Jolibox SDK] Emitter is _disposed")};r&&(n=n.bind(r));let o=new _(n);return this._listeners?this._listeners instanceof _?this._listeners=[this._listeners,o]:this._listeners.push(o):((i=(s=this.options)==null?void 0:s.onWillAddFirstListener)==null||i.call(s,this),this._listeners=o,(a=(c=this.options)==null?void 0:c.onDidFirstListener)==null||a.call(c,this)),(d=(u=this.options)==null?void 0:u.onDidAddListener)==null||d.call(u,this),this._size++,()=>{var R,f,E,C;if(!this._disposed){if(this._listeners instanceof _)this._listeners.id===o.id&&(this._listeners=void 0,this._size=0,(f=(R=this.options)==null?void 0:R.onDidRemoveLastListener)==null||f.call(R));else if(this._listeners){let Te=this._listeners.indexOf(o);Te>=0&&(this._listeners.splice(Te,1),this._size--,this._size===0&&((C=(E=this.options)==null?void 0:E.onDidRemoveLastListener)==null||C.call(E)))}}}}),this._event}_deliver(e,n){var o;if(!e)return;let r=((o=this.options)==null?void 0:o.onListenerError)||Error.constructor;if(!r){e.value(n);return}try{e.value(n)}catch(s){r(s)}}fire(e){this._listeners&&(this._listeners instanceof _?this._deliver(this._listeners,e):this._listeners.forEach(n=>this._deliver(n,e)))}hasListeners(){return this._size>0}},I=class{constructor(){this.listeners=new Map;this.listerHandlerMap=new WeakMap;this.cachedEventQueue=new Map}on(e,n,r=!0){var a;let o=(a=this.listeners.get(e))!=null?a:new g,s=u=>n(...u.args),i=o.event(s);this.listerHandlerMap.set(n,{handler:s,dispose:i}),this.listeners.set(e,o);let c=this.cachedEventQueue.get(e);if(c&&r)for(let u of c)n(...u.args)}flushCachedEvent(e){e?this.cachedEventQueue.delete(e):this.cachedEventQueue.clear()}off(e,n){let r=this.listerHandlerMap.get(n);r&&(r.dispose(),this.listerHandlerMap.delete(n))}emit(e,...n){let r=this.listeners.get(e),o=this.cachedEventQueue.get(e);o||(o=new j,this.cachedEventQueue.set(e,o)),o.push({args:n}),r&&r.fire({event:e,args:n})}once(e,n){let r=(...o)=>{n(...o),this.off(e,r)};this.on(e,r,!1)}};var v={};Ce(v,{None:()=>Dt,filter:()=>kt,once:()=>je,toPromise:()=>Pt});var Dt=()=>(console.log("[Jolibox SDK] None Event"),()=>{console.log("[Jolibox SDK] None Event dispose")});function Pt(t){return new Promise(e=>je(t)(e))}function je(t){return(e,n=null)=>{let r=!1;return t(s=>{if(!r)return r=!0,e.call(n,s)},null)}}function kt(t,e){return(r=>{let o,s={onWillAddFirstListener(){o=r(i.fire,i)}},i=new g(s);return i.event})((r,o=null)=>t(s=>e(s)&&r.call(o,s),null))}var Re=Symbol.for("Jolibox.hostEmitter"),Lt=()=>{let t=new I;return globalThis[Re]||(globalThis[Re]={on:t.on.bind(t),off:t.off.bind(t),emit:t.emit.bind(t),once:t.once.bind(t)}),globalThis[Re]},qt=Lt();function ye(t,e){let n=Math.min(t.length,e.length);for(let r=0;r<n;r++)He(t[r],e[r])}function He(t,e){if(M(e)){if(typeof t!==e)throw new Error(`argument does not match constraint: typeof ${e}`)}else if(V(e)){try{if(t instanceof e)return}catch(n){}if(!U(t)&&t.constructor===e||e.length===1&&e.call(void 0,t)===!0)return;throw new Error("[Jolibox SDK]argument does not match one of these constraints: arg instanceof constraint, arg.constructor === constraint, nor constraint(arg) === true")}}var x=class{constructor(){this._commands=new Map;this._onDidRegisterCommand=new g;this.onDidRegisterCommand=this._onDidRegisterCommand.event;console.log("[Jolibox SDK] command registry")}registerCommand(e){if(!e)throw new Error("invalid command");if(e.metadata&&Array.isArray(e.metadata.args)){let o=[];for(let i of e.metadata.args)o.push(i.constraint);let s=e.handler;e.handler=function(...i){return ye(i,o),s(...i)}}let{id:n}=e;this._commands.get(n)&&console.info(`[Jolibox SDK] duplicated command is registered ${n}`),this._commands.set(n,e),this._onDidRegisterCommand.fire(n)}getCommand(e){return this._commands.get(e)}getCommands(){let e=new Map;for(let n of this._commands.keys()){let r=this.getCommand(n);r&&e.set(n,r)}return e}};x=q([O],x);var N=class{constructor(){this._onWillExecuteCommand=new g;this.onWillExecuteCommand=this._onWillExecuteCommand.event;this._onDidExecuteCommand=new g;this.onDidExecuteCommand=this._onDidExecuteCommand.event;this.registry=new x;this._starActivation=null}_activateStar(){return this._starActivation||(this._starActivation=K(3e4)),this._starActivation}executeCommand(e,...n){return h(this,null,function*(){return this.registry.getCommand(e)?this._tryExecuteCommand(e,n):(yield Promise.all([Promise.race([this._activateStar(),v.toPromise(v.filter(this.registry.onDidRegisterCommand,o=>o===e))])]),this._tryExecuteCommand(e,n))})}executeCommandThowErr(e,...n){if(!!!this.registry.getCommand(e))throw new Error(`command '${e}' not found`);let o=this.registry.getCommand(e);this._onWillExecuteCommand.fire({commandId:e,args:n});let s=this.invokeFunction(o.handler,...n);return this._onDidExecuteCommand.fire({commandId:e,args:n}),s}_tryExecuteCommand(e,n){let r=this.registry.getCommand(e);if(!r)return Promise.reject(new Error(`command '${e}' not found`));try{this._onWillExecuteCommand.fire({commandId:e,args:n});let o=this.invokeFunction(r.handler,...n);return this._onDidExecuteCommand.fire({commandId:e,args:n}),Promise.resolve(o)}catch(o){return Promise.reject(o)}}invokeFunction(e,...n){let r=!1;try{return e(...n)}finally{r=!0}}};N=q([O],N);var Ke=Symbol.for("Jolibox.commands");function Mt(){return typeof globalThis!="undefined"?globalThis[Ke]:void 0}function Ut(t){typeof globalThis!="undefined"&&(globalThis[Ke]=t)}function Vt(t=!1){let e=Mt();if(!t&&e)return e;let n=new x,r=new N,o={registerCommand(s,i,c){n.registerCommand({id:s,handler:i,metadata:c})},executeCommand(s,...i){return r.executeCommand(s,...i)},excuteCommandSync(s,...i){return r.executeCommandThowErr(s,...i)}};return Ut(o),o}
1
+ "use strict";var C=Object.defineProperty,Ge=Object.defineProperties,Re=Object.getOwnPropertyDescriptor,Je=Object.getOwnPropertyDescriptors,ze=Object.getOwnPropertyNames,_e=Object.getOwnPropertySymbols;var Te=Object.prototype.hasOwnProperty,Be=Object.prototype.propertyIsEnumerable;var Ee=(n,e,t)=>e in n?C(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,E=(n,e)=>{for(var t in e||(e={}))Te.call(e,t)&&Ee(n,t,e[t]);if(_e)for(var t of _e(e))Be.call(e,t)&&Ee(n,t,e[t]);return n},L=(n,e)=>Ge(n,Je(e));var ve=(n,e)=>{for(var t in e)C(n,t,{get:e[t],enumerable:!0})},We=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ze(e))!Te.call(n,o)&&o!==t&&C(n,o,{get:()=>e[o],enumerable:!(r=Re(e,o))||r.enumerable});return n};var Qe=n=>We(C({},"__esModule",{value:!0}),n),k=(n,e,t,r)=>{for(var o=r>1?void 0:r?Re(e,t):e,i=n.length-1,s;i>=0;i--)(s=n[i])&&(o=(r?s(e,t,o):s(o))||o);return r&&o&&C(e,t,o),o};var M=(n,e,t)=>new Promise((r,o)=>{var i=a=>{try{d(t.next(a))}catch(u){o(u)}},s=a=>{try{d(t.throw(a))}catch(u){o(u)}},d=a=>a.done?r(a.value):Promise.resolve(a.value).then(i,s);d((t=t.apply(n,e)).next())});var jn={};ve(jn,{ADVERTISING_ID:()=>Me,APIError:()=>se,BaseError:()=>R,DEVICE_ID:()=>ke,Deferred:()=>$,EPlatform:()=>Pe,EProject:()=>Oe,EventEmitter:()=>b,EventType:()=>Ne,EventUtils:()=>h,InternalApplyNativeError:()=>ee,InternalBufferError:()=>re,InternalContextError:()=>oe,InternalError:()=>p,InternalGlobalJSError:()=>ie,InternalInvokeMethodError:()=>ne,InternalInvokeNativeError:()=>X,InternalJSCoreNotFoundError:()=>te,InternalJSModuleEvalError:()=>q,InternalJSModuleFetchError:()=>Y,InternalMetricReportError:()=>ae,InternalPaymentError:()=>Z,InternalReporterError:()=>de,InternalSchemaParseError:()=>Q,LoadScriptCode:()=>Ce,Singleton:()=>w,UserCustomError:()=>N,UserError:()=>g,UserFetchError:()=>z,UserFunctionEvalError:()=>W,UserGlobalError:()=>J,UserPaymentError:()=>B,UserValidateError:()=>G,canIUseConfig:()=>gn,canIUseConfigNative:()=>hn,compareVersion:()=>_n,createCommands:()=>Fn,createRunTaskQueue:()=>Ze,debounce:()=>mn,get:()=>yn,getAdvertisingId:()=>De,getApiDomain:()=>Fe,getApiHost:()=>Cn,getCollectDomain:()=>je,getCollectHost:()=>On,getDeviceId:()=>Ue,getH5ApiHost:()=>wn,getH5Domain:()=>Nn,getOriginalLocalStorage:()=>pe,getPlatform:()=>Le,getStorage:()=>fe,getUtmSource:()=>Ve,hostEmitter:()=>Un,isArray:()=>tn,isBoolean:()=>sn,isDefined:()=>an,isFunction:()=>V,isIterable:()=>on,isNative:()=>Se,isNumber:()=>rn,isObject:()=>be,isPromiseLike:()=>dn,isString:()=>U,isStringArray:()=>en,isTypedArray:()=>nn,isUndefined:()=>Ie,isUndefinedOrNull:()=>D,isValidUUIDV4:()=>bn,logger:()=>le,mergeArray:()=>cn,mergeWith:()=>ln,microTask:()=>Xe,platform:()=>P,promisifyAPI:()=>qe,serializeEventPackage:()=>vn,sleep:()=>Ye,timeout:()=>K,uuidv4:()=>ue,validateConstraint:()=>$e,validateConstraints:()=>ye,wrapUserFunction:()=>pn,xUserAgent:()=>An});module.exports=Qe(jn);if(typeof window!="undefined"&&!window.AbortController){let n=function(){this.signal=new e};n.prototype.abort=function(){this.signal._aborted=!0,typeof this.signal.onabort=="function"&&this.signal.onabort(new Event("abort"));let t=new Event("abort");this.signal.dispatchEvent(t)};let e=function(){this._aborted=!1,this.aborted=!1,this.onabort=null,this._eventListeners={}};Object.defineProperty(e.prototype,"aborted",{get:function(){return this._aborted}}),e.prototype.addEventListener=function(t,r){this._eventListeners[t]||(this._eventListeners[t]=[]),this._eventListeners[t].push(r)},e.prototype.removeEventListener=function(t,r){if(!this._eventListeners[t])return;let o=this._eventListeners[t].indexOf(r);o!==-1&&this._eventListeners[t].splice(o,1)},e.prototype.dispatchEvent=function(t){if(this._eventListeners[t.type])for(let r of this._eventListeners[t.type])r.call(this,t)},window.AbortController=n,window.AbortSignal=e}function K(n){return new Promise(e=>{setTimeout(()=>{e()},n)})}function Ye(n){return new Promise(e=>setTimeout(e,n))}function qe(n){return e=>new Promise((t,r)=>{n(L(E({},e),{success:t,fail(o){let i=new Error(o.errMsg);r(i)}}))})}function Xe(n){if(n)Promise.resolve().then(n);else return Promise.resolve()}var $=class{constructor(){this.state="pending";this.promise=new Promise((e,t)=>{this.resolve=r=>{this.state==="pending"&&(this.state="fulfilled",e(r))},this.reject=r=>{this.state==="pending"&&(this.state="rejected",t(r))}})}};function Ze(){let n=[],e=!1,t=()=>M(this,null,function*(){let r=n.shift();if(r){e=!0;try{yield r()}finally{e=!1,t()}}});return r=>{n.push(r),e||t()}}function U(n){return typeof n=="string"}function en(n){return Array.isArray(n)&&n.every(e=>U(e))}function be(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)&&!(n instanceof RegExp)&&!(n instanceof Date)}function nn(n){let e=Object.getPrototypeOf(Uint8Array);return typeof n=="object"&&n instanceof e}function tn(n){return typeof n=="object"&&Array.isArray(n)}function rn(n){return typeof n=="number"&&!isNaN(n)}function on(n){return!!n&&typeof n[Symbol.iterator]=="function"}function sn(n){return n===!0||n===!1}function Ie(n){return typeof n=="undefined"}function an(n){return!D(n)}function D(n){return Ie(n)||n===null}function V(n){return typeof n=="function"}function dn(n){return be(n)&&V(n.then)}function w(n){let e=n,t=null,r=function(...o){return t||(t=new e(...o)),t};return r.prototype=e.prototype,r}function ln(n,e,t){if(typeof t!="function")throw new Error("[Jolibox SDK]Customizer must be a function");function r(o,i){for(let s in i)if(Object.prototype.hasOwnProperty.call(i,s)){let d=o[s],a=i[s],u=t(d,a,s,o,i);u!==void 0?o[s]=u:Ae(a)&&Ae(d)?o[s]=r(E({},d),a):Array.isArray(a)&&Array.isArray(d)?o[s]=[...d,...a]:o[s]=a}return o}return r(n,e)}function Ae(n){return n&&typeof n=="object"&&n.constructor===Object}function cn(n,e){if(Array.isArray(n))return n.concat(e)}function mn(n,e,t={}){let r=null,o,i,s,{leading:d=!1,trailing:a=!0}=t,u=()=>(s=n.apply(i,o),o=void 0,i=void 0,s),c=function(..._){o=_,i=this;let A=d&&!r;if(r&&clearTimeout(r),r=setTimeout(()=>{r=null,a&&!A&&u()},e),A)return u()};return c.cancel=()=>{r&&clearTimeout(r),r=null,o=i=void 0},c.flush=()=>{if(r)return clearTimeout(r),r=null,u()},c}var Ce=(a=>(a[a.DEVELOPER_FILE_NOT_FOUND=0]="DEVELOPER_FILE_NOT_FOUND",a[a.INTERNAL_IOS_CAN_NOT_FOUND_PKG=1]="INTERNAL_IOS_CAN_NOT_FOUND_PKG",a[a.USER_IOS_LOAD_TIMEOUT=2]="USER_IOS_LOAD_TIMEOUT",a[a.INTERNAL_IOS_PKG_LOAD_ERROR=3]="INTERNAL_IOS_PKG_LOAD_ERROR",a[a.INTERNAL_IOS_PKG_PARSE_FAIL=4]="INTERNAL_IOS_PKG_PARSE_FAIL",a[a.USER_IOS_GET_EMPTY_DATA=5]="USER_IOS_GET_EMPTY_DATA",a[a.USER_ANDROID_GET_PKG_FAIL=6]="USER_ANDROID_GET_PKG_FAIL",a[a.DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE=7]="DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE",a))(Ce||{}),R=class extends Error{constructor(e){if(typeof e=="string"){super(e),this.priority="P1";return}super(e.message),this.priority="P1",this.stack=e.stack,this.raw=e}},p=class extends R{constructor(){super(...arguments);this.kind="INTERNAL_ERROR"}},g=class extends R{constructor(){super(...arguments);this.kind="USER_ERROR"}},G=class extends g{constructor(){super(...arguments);this.name="USER_VALIDATE_ERROR"}},J=class extends g{constructor(){super(...arguments);this.name="USER_GLOBAL_ERROR";this.priority="P1"}},N=class extends g{constructor(t,r,o){super(t);this.message=t;this.errNo=r;this.name="USER_CUSTOM_ERROR";this.errMsg=t,o&&(this.extra=Object.assign({},this.extra,o))}},z=class extends g{constructor(t,r,o){super(t);this.message=t;this.errNo=r;this.name="USER_FETCH_ERROR";this.errMsg=t,o&&(this.extra=Object.assign({},this.extra,o))}},B=class extends g{constructor(t,r,o){super(t);this.message=t;this.errNo=r;this.name="USER_PAYMENT_ERROR";this.errMsg=t,o&&(this.extra=Object.assign({},this.extra,o))}},W=class extends g{constructor(){super(...arguments);this.name="USER_CALLBACK_ERROR"}},Q=class extends p{constructor(){super(...arguments);this.name="INTERNAL_SCHEMA_PARSE_ERROR";this.priority="P0"}},Y=class extends p{constructor(){super(...arguments);this.name="INTERNAL_JS_MODULE_FETCH_ERROR";this.priority="P0"}},q=class extends p{constructor(){super(...arguments);this.name="INTERNAL_JS_MODULE_EVAL_ERROR";this.priority="P0"}},X=class extends p{constructor(){super(...arguments);this.name="INTERNAL_INVOKE_NATIVE_ERROR"}},Z=class extends p{constructor(t,r,o){super(t);this.message=t;this.errNo=r;this.name="INTERNAL_PAYMENT_ERROR";this.priority="P0";this.errMsg=t,o&&(this.extra=Object.assign({},this.extra,o))}},ee=class extends p{constructor(t,r,o,i){super(t);this.errNo=r;this.name="INTERNAL_APPLY_NATIVE_ERROR";this.errorType=o,this.errorCode=i}},ne=class extends p{constructor(){super(...arguments);this.name="INTERNAL_INVOKE_METHOD_ERROR"}},te=class extends p{constructor(){super(...arguments);this.name="INTERNAL_JSCORE_ERROR";this.priority="P0"}},re=class extends p{constructor(){super(...arguments);this.name="INTERNAL_BUFFER_ERROR"}},oe=class extends p{constructor(t,r){super(t);this.message=t;this.name="INTERNAL_CONTEXT_ERROR";this.property=r}},ie=class extends p{constructor(){super(...arguments);this.name="INTERNAL_GLOBAL_JS_ERROR";this.priority="P1"}},se=class extends R{constructor(t,r,o,i,s){super(t);this.message=t;this.code=r;this.kind="API_ERROR";this.name="API_ERROR";o&&(this.errorType=o),i!==void 0&&(this.stack=i),s&&(this.priority=s)}toJSON(){return{message:this.message,stack:this.stack,name:this.name,code:this.code,errorType:this.errorType}}},ae=class extends p{constructor(){super(...arguments);this.name="INTERNAL_METRIC_REPORT_ERROR"}},de=class extends p{constructor(){super(...arguments);this.name="INTERNAL_REPORTER_ERROR"}};function un(n,e){return(...t)=>e(n,...t)}function pn(n){return e=>un(e,function(t,...r){if(typeof t=="function")try{return t.apply(this,r)}catch(o){n(new N(`${o}`))}})}function O(n){return(...e)=>{var r,o;((o=(r=globalThis.VConsole)==null?void 0:r[n])!=null?o:globalThis.console[n])(...e)}}var le={log:O("log"),warn:O("warn"),info:O("info"),error:O("error"),debug:O("debug")};Object.assign(globalThis,{logger:le});var ce=Symbol.for("Jolibox.canIUseMap"),fn={};globalThis[ce]||(globalThis[ce]=fn);var gn={get config(){return globalThis[ce]}};function yn(n,e,t){let r=n;for(let o of e)if(r&&typeof r=="object")r=r[o];else return t;return r===void 0?t:r}var me=Symbol.for("Jolibox.canIUseMap.native"),xn={};globalThis[me]||(globalThis[me]=xn);var hn={get config(){return globalThis[me]}};function _n(n,e,t){let r=0;if(n!==e){let o=n.split("."),i=e.split("."),s=Math.max(o.length,i.length);for(let d=0;d<s;d++){let a=parseInt(o[d],10)||0,u=parseInt(i[d],10)||0;if(a>u){r=1;break}else if(a<u){r=-1;break}}}if(!t)return r;switch(t){case">":return r>0;case"<":return r<0;case"=":return r===0;case">=":return r>=0;case"<=":return r<=0;default:return!1}}var Ne=(l=>(l[l.Other=0]="Other",l[l.Route=1]="Route",l[l.Click=2]="Click",l[l.View=3]="View",l[l.Expose=4]="Expose",l[l.Swipe=5]="Swipe",l[l.Input=6]="Input",l[l.Select=7]="Select",l[l.SwitchOn=8]="SwitchOn",l[l.SwitchOff=9]="SwitchOff",l[l.Submit=10]="Submit",l[l.Scroll=11]="Scroll",l[l.Hide=12]="Hide",l[l.System=1e3]="System",l[l.ErrorTrace=1001]="ErrorTrace",l[l.UserDefined=1002]="UserDefined",l))(Ne||{}),Oe=(i=>(i.MiniGame="mini-game",i.MiniDrama="mini-drama",i.App="app",i.WebSDK="web-sdk",i.AppSDK="app-sdk",i))(Oe||{}),Pe=(c=>(c[c.App=0]="App",c[c.H5=1]="H5",c[c.Weapp=2]="Weapp",c[c.Alipay=3]="Alipay",c[c.Gcash=4]="Gcash",c[c.Dana=5]="Dana",c[c.Umma=6]="Umma",c[c.WebSDK=1e3]="WebSDK",c[c.AppSDK=1001]="AppSDK",c[c.Other=9999]="Other",c))(Pe||{}),we=["name","params"],En=["name","type","location","target","extra","timestamp","userId"],Rn=["platform","os","appVersion","appId","model","brand","uuid","jsSdkVersion","extra"];function F(n,e){return e.map(t=>{if(t==="params"&&n[t]){let r=n[t];return Object.keys(r).reduce((o,i)=>(o[i]=String(r[i]),o),{})}return n[t]})}function Tn(n){let e=n.location?F(n.location,we):null,t=n.target?F(n.target,we):null;return F(L(E({},n),{location:e,target:t}),En)}function vn(n){let e=n.events.map(r=>Tn(r)),t=F(n.device,Rn);return[n.protocolVersion,e,t,n.project]}var ue=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,n=>{let e=Math.random()*16|0;return(n==="x"?e:e&3|8).toString(16)}),bn=n=>/^[\da-f]{8}-[\da-f]{4}-4[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i.test(n);function pe(){if(typeof window=="undefined")return{getItem:()=>null,setItem:()=>{},removeItem:()=>{},clear:()=>{},length:0,key:()=>null};try{if(window.__joliboxLocalStorage__)return window.__joliboxLocalStorage__;let n=Object.getOwnPropertyDescriptor(window,"localStorage");if(n&&n.get){let r=n.get.call(window);return window.__joliboxLocalStorage__=r,r}if(n=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(window),"localStorage"),n&&n.get)return n.get.call(window);let e=Window.prototype,t=Object.getOwnPropertyDescriptor(e,"localStorage");if(t&&t.get){let r=t.get.call(window);return window.__joliboxLocalStorage__=r,r}return localStorage}catch(n){return console.warn("Failed to get original localStorage, fallback to default implementation",n),localStorage}}pe();var T=typeof window=="undefined",Se=()=>!T&&!!(navigator.userAgent||"").includes("JoliboxPlatformSDK"),P={isiOS:!T&&(navigator.userAgent.includes("iPhone")||navigator.userAgent.includes("iPod")||navigator.userAgent.includes("iPad")||navigator.userAgent.includes("iPhone OS")),iosVersion:()=>{let n=navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/);return[parseInt(n[1],10),parseInt(n[2],10),parseInt(n[3]||"0",10)]},isAndroid:!T&&navigator.userAgent.includes("Android"),isMac:!T&&navigator.userAgent.includes("Mac"),isFacebook:!T&&navigator.userAgent.includes("FB_IAB"),isPC:!T&&!navigator.userAgent.includes("iPhone")&&!navigator.userAgent.includes("Android")},Le=()=>P.isiOS?"iOS":P.isAndroid?"Android":P.isMac?"Mac":P.isFacebook?"Facebook":"PC",ke="device_id",Me="advertising_id",fe=n=>(window.__joliboxLocalStorage__.getItem(n)||window.__joliboxLocalStorage__.setItem(n,ue()),window.__joliboxLocalStorage__.getItem(n)),Ue=()=>{let e=new URLSearchParams(window.location.search).get("deviceId");return e||fe(ke)},De=()=>{let e=new URLSearchParams(window.location.search).get("advertisingId");return e||fe(Me)},In=n=>n.charAt(0).toUpperCase()+n.slice(1),Ve=()=>{var e;let n=new URLSearchParams(window.location.search);return In((e=n.get("utm_source"))!=null?e:"")||"JoliboxSDK"},An=n=>{if(Se())return window.navigator.userAgent;let e="JoliboxWebSDK",t=Le(),r=navigator.language,o=Ue(),i=De();return`${e} (${Ve()}${t}; UnknownModel; UnknownSystemVersion; ${r}) uuid/${o} adid/${i} version/${n||""}`};function j(n,e,t){let r=window.location.hostname,o=r.split("."),i=t?e:n;if(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(r))return`${i}.jolibox.com`;if(o.length>=2){let d=o.slice(-2).join(".");if(d==="jolibox.com"||d==="pico-game.com"||d==="joyslite.com")return`${i}.${d}`}return`${i}.jolibox.com`}function Fe(n){return j("app","stg-app",n)}function Cn(n){return`https://${Fe(n)}`}function wn(n){return`https://${j("api","stg-api",n)}`}function Nn(n){return j("api","stg-api",n)}function je(n){return j("collect","stg-collect",n)}function On(n){return`https://${je(n)}`}var v=class v{constructor(e){this.element=e,this.next=v.Undefined,this.prev=v.Undefined}};v.Undefined=new v(void 0);var m=v,H=class{constructor(){this._first=m.Undefined;this._last=m.Undefined;this._size=0}get size(){return this._size}isEmpty(){return this._first===m.Undefined}clear(){let e=this._first;for(;e!==m.Undefined;){let t=e.next;e.prev=m.Undefined,e.next=m.Undefined,e=t}this._first=m.Undefined,this._last=m.Undefined,this._size=0}unshift(e){return this._insert(e,!1)}push(e){return this._insert(e,!0)}_insert(e,t){let r=new m(e);if(this._first===m.Undefined)this._first=r,this._last=r;else if(t){let i=this._last;this._last=r,r.prev=i,i.next=r}else{let i=this._first;this._first=r,r.next=i,i.prev=r}this._size+=1;let o=!1;return()=>{o||(o=!0,this._remove(r))}}shift(){if(this._first!==m.Undefined){let e=this._first.element;return this._remove(this._first),e}}pop(){if(this._last!==m.Undefined){let e=this._last.element;return this._remove(this._last),e}}_remove(e){if(e.prev!==m.Undefined&&e.next!==m.Undefined){let t=e.prev;t.next=e.next,e.next.prev=t}else e.prev===m.Undefined&&e.next===m.Undefined?(this._first=m.Undefined,this._last=m.Undefined):e.next===m.Undefined?(this._last=this._last.prev,this._last.next=m.Undefined):e.prev===m.Undefined&&(this._first=this._first.next,this._first.prev=m.Undefined);this._size-=1}*[Symbol.iterator](){let e=this._first;for(;e!==m.Undefined;)yield e.element,e=e.next}};var Pn=0,x=class{constructor(e){this.value=e;this.id=Pn++}},f=class{constructor(e){this.options=e;this._size=0}dispose(e){var t,r;this._disposed||(this._disposed=!0,this._listeners&&(e?(this._listeners instanceof x&&(this._listeners=[this._listeners]),this._listeners=this._listeners.filter(o=>(o==null?void 0:o.value)===e)):(this._listeners=void 0,this._size=0)),(r=(t=this.options)==null?void 0:t.onDidRemoveLastListener)==null||r.call(t))}get event(){var e;return(e=this._event)!=null||(this._event=(t,r)=>{var i,s,d,a,u,c;if(this._disposed)return()=>{console.info("[Jolibox SDK] Emitter is _disposed")};r&&(t=t.bind(r));let o=new x(t);return this._listeners?this._listeners instanceof x?this._listeners=[this._listeners,o]:this._listeners.push(o):((s=(i=this.options)==null?void 0:i.onWillAddFirstListener)==null||s.call(i,this),this._listeners=o,(a=(d=this.options)==null?void 0:d.onDidFirstListener)==null||a.call(d,this)),(c=(u=this.options)==null?void 0:u.onDidAddListener)==null||c.call(u,this),this._size++,()=>{var _,A,S,xe;if(!this._disposed){if(this._listeners instanceof x)this._listeners.id===o.id&&(this._listeners=void 0,this._size=0,(A=(_=this.options)==null?void 0:_.onDidRemoveLastListener)==null||A.call(_));else if(this._listeners){let he=this._listeners.indexOf(o);he>=0&&(this._listeners.splice(he,1),this._size--,this._size===0&&((xe=(S=this.options)==null?void 0:S.onDidRemoveLastListener)==null||xe.call(S)))}}}}),this._event}_deliver(e,t){var o;if(!e)return;let r=((o=this.options)==null?void 0:o.onListenerError)||Error.constructor;if(!r){e.value(t);return}try{e.value(t)}catch(i){r(i)}}fire(e){this._listeners&&(this._listeners instanceof x?this._deliver(this._listeners,e):this._listeners.forEach(t=>this._deliver(t,e)))}hasListeners(){return this._size>0}},b=class{constructor(){this.listeners=new Map;this.listerHandlerMap=new WeakMap;this.cachedEventQueue=new Map}on(e,t,r=!0){var a;let o=(a=this.listeners.get(e))!=null?a:new f,i=u=>t(...u.args),s=o.event(i);this.listerHandlerMap.set(t,{handler:i,dispose:s}),this.listeners.set(e,o);let d=this.cachedEventQueue.get(e);if(d&&r)for(let u of d)t(...u.args)}flushCachedEvent(e){e?this.cachedEventQueue.delete(e):this.cachedEventQueue.clear()}off(e,t){let r=this.listerHandlerMap.get(t);r&&(r.dispose(),this.listerHandlerMap.delete(t))}emit(e,...t){let r=this.listeners.get(e),o=this.cachedEventQueue.get(e);o||(o=new H,this.cachedEventQueue.set(e,o)),o.push({args:t}),r&&r.fire({event:e,args:t})}once(e,t){let r=(...o)=>{t(...o),this.off(e,r)};this.on(e,r,!1)}};var h={};ve(h,{None:()=>Sn,filter:()=>kn,once:()=>He,toPromise:()=>Ln});var Sn=()=>(console.log("[Jolibox SDK] None Event"),()=>{console.log("[Jolibox SDK] None Event dispose")});function Ln(n){return new Promise(e=>He(n)(e))}function He(n){return(e,t=null)=>{let r=!1;return n(i=>{if(!r)return r=!0,e.call(t,i)},null)}}function kn(n,e){return(r=>{let o,i={onWillAddFirstListener(){o=r(s.fire,s)}},s=new f(i);return s.event})((r,o=null)=>n(i=>e(i)&&r.call(o,i),null))}var ge=Symbol.for("Jolibox.hostEmitter"),Mn=()=>{let n=new b;return globalThis[ge]||(globalThis[ge]={on:n.on.bind(n),off:n.off.bind(n),emit:n.emit.bind(n),once:n.once.bind(n)}),globalThis[ge]},Un=Mn();function ye(n,e){let t=Math.min(n.length,e.length);for(let r=0;r<t;r++)$e(n[r],e[r])}function $e(n,e){if(U(e)){if(typeof n!==e)throw new Error(`argument does not match constraint: typeof ${e}`)}else if(V(e)){try{if(n instanceof e)return}catch(t){}if(!D(n)&&n.constructor===e||e.length===1&&e.call(void 0,n)===!0)return;throw new Error("[Jolibox SDK]argument does not match one of these constraints: arg instanceof constraint, arg.constructor === constraint, nor constraint(arg) === true")}}var y=class{constructor(){this._commands=new Map;this._onDidRegisterCommand=new f;this.onDidRegisterCommand=this._onDidRegisterCommand.event;console.log("[Jolibox SDK] command registry")}registerCommand(e){if(!e)throw new Error("invalid command");if(e.metadata&&Array.isArray(e.metadata.args)){let o=[];for(let s of e.metadata.args)o.push(s.constraint);let i=e.handler;e.handler=function(...s){return ye(s,o),i(...s)}}let{id:t}=e;this._commands.get(t)&&console.info(`[Jolibox SDK] duplicated command is registered ${t}`),this._commands.set(t,e),this._onDidRegisterCommand.fire(t)}getCommand(e){return this._commands.get(e)}getCommands(){let e=new Map;for(let t of this._commands.keys()){let r=this.getCommand(t);r&&e.set(t,r)}return e}};y=k([w],y);var I=class{constructor(){this._onWillExecuteCommand=new f;this.onWillExecuteCommand=this._onWillExecuteCommand.event;this._onDidExecuteCommand=new f;this.onDidExecuteCommand=this._onDidExecuteCommand.event;this.registry=new y;this._starActivation=null}_activateStar(){return this._starActivation||(this._starActivation=K(3e4)),this._starActivation}executeCommand(e,...t){return M(this,null,function*(){return this.registry.getCommand(e)?this._tryExecuteCommand(e,t):(yield Promise.all([Promise.race([this._activateStar(),h.toPromise(h.filter(this.registry.onDidRegisterCommand,o=>o===e))])]),this._tryExecuteCommand(e,t))})}executeCommandThowErr(e,...t){if(!!!this.registry.getCommand(e))throw new Error(`command '${e}' not found`);let o=this.registry.getCommand(e);this._onWillExecuteCommand.fire({commandId:e,args:t});let i=this.invokeFunction(o.handler,...t);return this._onDidExecuteCommand.fire({commandId:e,args:t}),i}_tryExecuteCommand(e,t){let r=this.registry.getCommand(e);if(!r)return Promise.reject(new Error(`command '${e}' not found`));try{this._onWillExecuteCommand.fire({commandId:e,args:t});let o=this.invokeFunction(r.handler,...t);return this._onDidExecuteCommand.fire({commandId:e,args:t}),Promise.resolve(o)}catch(o){return Promise.reject(o)}}invokeFunction(e,...t){let r=!1;try{return e(...t)}finally{r=!0}}};I=k([w],I);var Ke=Symbol.for("Jolibox.commands");function Dn(){return typeof globalThis!="undefined"?globalThis[Ke]:void 0}function Vn(n){typeof globalThis!="undefined"&&(globalThis[Ke]=n)}function Fn(n=!1){let e=Dn();if(!n&&e)return e;let t=new y,r=new I,o={registerCommand(i,s,d){t.registerCommand({id:i,handler:s,metadata:d})},executeCommand(i,...s){return r.executeCommand(i,...s)},excuteCommandSync(i,...s){return r.executeCommandThowErr(i,...s)}};return Vn(o),o}
package/dist/index.es.js CHANGED
@@ -1 +1 @@
1
- var V=Object.defineProperty,Ae=Object.defineProperties,we=Object.getOwnPropertyDescriptor,Ie=Object.getOwnPropertyDescriptors;var z=Object.getOwnPropertySymbols;var Ne=Object.prototype.hasOwnProperty,Se=Object.prototype.propertyIsEnumerable;var W=(t,e,n)=>e in t?V(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,y=(t,e)=>{for(var n in e||(e={}))Ne.call(e,n)&&W(t,n,e[n]);if(z)for(var n of z(e))Se.call(e,n)&&W(t,n,e[n]);return t},O=(t,e)=>Ae(t,Ie(e));var Oe=(t,e)=>{for(var n in e)V(t,n,{get:e[n],enumerable:!0})};var D=(t,e,n,r)=>{for(var o=r>1?void 0:r?we(e,n):e,s=t.length-1,i;s>=0;s--)(i=t[s])&&(o=(r?i(e,n,o):i(o))||o);return r&&o&&V(e,n,o),o};var h=(t,e,n)=>new Promise((r,o)=>{var s=a=>{try{c(n.next(a))}catch(u){o(u)}},i=a=>{try{c(n.throw(a))}catch(u){o(u)}},c=a=>a.done?r(a.value):Promise.resolve(a.value).then(s,i);c((n=n.apply(t,e)).next())});if(typeof window!="undefined"&&!window.AbortController){let t=function(){this.signal=new e};t.prototype.abort=function(){this.signal._aborted=!0,typeof this.signal.onabort=="function"&&this.signal.onabort(new Event("abort"));let n=new Event("abort");this.signal.dispatchEvent(n)};let e=function(){this._aborted=!1,this.aborted=!1,this.onabort=null,this._eventListeners={}};Object.defineProperty(e.prototype,"aborted",{get:function(){return this._aborted}}),e.prototype.addEventListener=function(n,r){this._eventListeners[n]||(this._eventListeners[n]=[]),this._eventListeners[n].push(r)},e.prototype.removeEventListener=function(n,r){if(!this._eventListeners[n])return;let o=this._eventListeners[n].indexOf(r);o!==-1&&this._eventListeners[n].splice(o,1)},e.prototype.dispatchEvent=function(n){if(this._eventListeners[n.type])for(let r of this._eventListeners[n.type])r.call(this,n)},window.AbortController=t,window.AbortSignal=e}function Q(t){return new Promise(e=>{setTimeout(()=>{e()},t)})}function lt(t){return new Promise(e=>setTimeout(e,t))}function dt(t){return e=>new Promise((n,r)=>{t(O(y({},e),{success:n,fail(o){let s=new Error(o.errMsg);r(s)}}))})}function ut(t){if(t)Promise.resolve().then(t);else return Promise.resolve()}var B=class{constructor(){this.state="pending";this.promise=new Promise((e,n)=>{this.resolve=r=>{this.state==="pending"&&(this.state="fulfilled",e(r))},this.reject=r=>{this.state==="pending"&&(this.state="rejected",n(r))}})}};function mt(){let t=[],e=!1,n=()=>h(this,null,function*(){let r=t.shift();if(r){e=!0;try{yield r()}finally{e=!1,n()}}});return r=>{t.push(r),e||n()}}function F(t){return typeof t=="string"}function gt(t){return Array.isArray(t)&&t.every(e=>F(e))}function De(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)&&!(t instanceof RegExp)&&!(t instanceof Date)}function Rt(t){let e=Object.getPrototypeOf(Uint8Array);return typeof t=="object"&&t instanceof e}function yt(t){return typeof t=="object"&&Array.isArray(t)}function Tt(t){return typeof t=="number"&&!isNaN(t)}function xt(t){return!!t&&typeof t[Symbol.iterator]=="function"}function _t(t){return t===!0||t===!1}function Pe(t){return typeof t=="undefined"}function vt(t){return!$(t)}function $(t){return Pe(t)||t===null}function j(t){return typeof t=="function"}function Et(t){return De(t)&&j(t.then)}function P(t){let e=t,n=null,r=function(...o){return n||(n=new e(...o)),n};return r.prototype=e.prototype,r}function It(t,e,n){if(typeof n!="function")throw new Error("[Jolibox SDK]Customizer must be a function");function r(o,s){for(let i in s)if(Object.prototype.hasOwnProperty.call(s,i)){let c=o[i],a=s[i],u=n(c,a,i,o,s);u!==void 0?o[i]=u:Y(a)&&Y(c)?o[i]=r(y({},c),a):Array.isArray(a)&&Array.isArray(c)?o[i]=[...c,...a]:o[i]=a}return o}return r(t,e)}function Y(t){return t&&typeof t=="object"&&t.constructor===Object}function Nt(t,e){if(Array.isArray(t))return t.concat(e)}function Pt(t,e,n={}){let r=null,o,s,i,{leading:c=!1,trailing:a=!0}=n,u=()=>(i=t.apply(s,o),o=void 0,s=void 0,i),d=function(...R){o=R,s=this;let f=c&&!r;if(r&&clearTimeout(r),r=setTimeout(()=>{r=null,a&&!f&&u()},e),f)return u()};return d.cancel=()=>{r&&clearTimeout(r),r=null,o=s=void 0},d.flush=()=>{if(r)return clearTimeout(r),r=null,u()},d}var ke=(a=>(a[a.DEVELOPER_FILE_NOT_FOUND=0]="DEVELOPER_FILE_NOT_FOUND",a[a.INTERNAL_IOS_CAN_NOT_FOUND_PKG=1]="INTERNAL_IOS_CAN_NOT_FOUND_PKG",a[a.USER_IOS_LOAD_TIMEOUT=2]="USER_IOS_LOAD_TIMEOUT",a[a.INTERNAL_IOS_PKG_LOAD_ERROR=3]="INTERNAL_IOS_PKG_LOAD_ERROR",a[a.INTERNAL_IOS_PKG_PARSE_FAIL=4]="INTERNAL_IOS_PKG_PARSE_FAIL",a[a.USER_IOS_GET_EMPTY_DATA=5]="USER_IOS_GET_EMPTY_DATA",a[a.USER_ANDROID_GET_PKG_FAIL=6]="USER_ANDROID_GET_PKG_FAIL",a[a.DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE=7]="DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE",a))(ke||{}),I=class extends Error{constructor(e){if(typeof e=="string"){super(e),this.priority="P1";return}super(e.message),this.priority="P1",this.stack=e.stack,this.raw=e}},p=class extends I{constructor(){super(...arguments);this.kind="INTERNAL_ERROR"}},T=class extends I{constructor(){super(...arguments);this.kind="USER_ERROR"}},X=class extends T{constructor(){super(...arguments);this.name="USER_VALIDATE_ERROR"}},Z=class extends T{constructor(){super(...arguments);this.name="USER_GLOBAL_ERROR";this.priority="P1"}},k=class extends T{constructor(n,r,o){super(n);this.message=n;this.errNo=r;this.name="USER_CUSTOM_ERROR";this.errMsg=n,o&&(this.extra=Object.assign({},this.extra,o))}},ee=class extends T{constructor(n,r,o){super(n);this.message=n;this.errNo=r;this.name="USER_FETCH_ERROR";this.errMsg=n,o&&(this.extra=Object.assign({},this.extra,o))}},te=class extends T{constructor(n,r,o){super(n);this.message=n;this.errNo=r;this.name="USER_PAYMENT_ERROR";this.errMsg=n,o&&(this.extra=Object.assign({},this.extra,o))}},ne=class extends T{constructor(){super(...arguments);this.name="USER_CALLBACK_ERROR"}},re=class extends p{constructor(){super(...arguments);this.name="INTERNAL_SCHEMA_PARSE_ERROR";this.priority="P0"}},oe=class extends p{constructor(){super(...arguments);this.name="INTERNAL_JS_MODULE_FETCH_ERROR";this.priority="P0"}},se=class extends p{constructor(){super(...arguments);this.name="INTERNAL_JS_MODULE_EVAL_ERROR";this.priority="P0"}},ie=class extends p{constructor(){super(...arguments);this.name="INTERNAL_INVOKE_NATIVE_ERROR"}},ae=class extends p{constructor(n,r,o){super(n);this.message=n;this.errNo=r;this.name="INTERNAL_PAYMENT_ERROR";this.priority="P0";this.errMsg=n,o&&(this.extra=Object.assign({},this.extra,o))}},ce=class extends p{constructor(n,r,o,s){super(n);this.errNo=r;this.name="INTERNAL_APPLY_NATIVE_ERROR";this.errorType=o,this.errorCode=s}},le=class extends p{constructor(){super(...arguments);this.name="INTERNAL_INVOKE_METHOD_ERROR"}},de=class extends p{constructor(){super(...arguments);this.name="INTERNAL_JSCORE_ERROR";this.priority="P0"}},ue=class extends p{constructor(){super(...arguments);this.name="INTERNAL_BUFFER_ERROR"}},me=class extends p{constructor(n,r){super(n);this.message=n;this.name="INTERNAL_CONTEXT_ERROR";this.property=r}},pe=class extends p{constructor(){super(...arguments);this.name="INTERNAL_GLOBAL_JS_ERROR";this.priority="P1"}},fe=class extends I{constructor(n,r,o,s,i){super(n);this.message=n;this.code=r;this.kind="API_ERROR";this.name="API_ERROR";o&&(this.errorType=o),s!==void 0&&(this.stack=s),i&&(this.priority=i)}toJSON(){return{message:this.message,stack:this.stack,name:this.name,code:this.code,errorType:this.errorType}}},he=class extends p{constructor(){super(...arguments);this.name="INTERNAL_METRIC_REPORT_ERROR"}},ge=class extends p{constructor(){super(...arguments);this.name="INTERNAL_REPORTER_ERROR"}};function Le(t,e){return(...n)=>e(t,...n)}function Ft(t){return e=>Le(e,function(n,...r){if(typeof n=="function")try{return n.apply(this,r)}catch(o){t(new k(`${o}`))}})}function N(t){return(...e)=>{var r,o;((o=(r=globalThis.VConsole)==null?void 0:r[t])!=null?o:globalThis.console[t])(...e)}}var Re={log:N("log"),warn:N("warn"),info:N("info"),error:N("error"),debug:N("debug")};Object.assign(globalThis,{logger:Re});var H=Symbol.for("Jolibox.canIUseMap"),qe={};globalThis[H]||(globalThis[H]=qe);var Bt={get config(){return globalThis[H]}};function Qt(t,e,n){let r=t;for(let o of e)if(r&&typeof r=="object")r=r[o];else return n;return r===void 0?n:r}var K=Symbol.for("Jolibox.canIUseMap.native"),Me={};globalThis[K]||(globalThis[K]=Me);var Yt={get config(){return globalThis[K]}};function en(t,e,n){let r=0;if(t!==e){let o=t.split("."),s=e.split("."),i=Math.max(o.length,s.length);for(let c=0;c<i;c++){let a=parseInt(o[c],10)||0,u=parseInt(s[c],10)||0;if(a>u){r=1;break}else if(a<u){r=-1;break}}}if(!n)return r;switch(n){case">":return r>0;case"<":return r<0;case"=":return r===0;case">=":return r>=0;case"<=":return r<=0;default:return!1}}var Ue=(l=>(l[l.Other=0]="Other",l[l.Route=1]="Route",l[l.Click=2]="Click",l[l.View=3]="View",l[l.Expose=4]="Expose",l[l.Swipe=5]="Swipe",l[l.Input=6]="Input",l[l.Select=7]="Select",l[l.SwitchOn=8]="SwitchOn",l[l.SwitchOff=9]="SwitchOff",l[l.Submit=10]="Submit",l[l.Scroll=11]="Scroll",l[l.Hide=12]="Hide",l[l.System=1e3]="System",l[l.ErrorTrace=1001]="ErrorTrace",l[l.UserDefined=1002]="UserDefined",l))(Ue||{}),Ve=(s=>(s.MiniGame="mini-game",s.MiniDrama="mini-drama",s.App="app",s.WebSDK="web-sdk",s.AppSDK="app-sdk",s))(Ve||{}),Fe=(d=>(d[d.App=0]="App",d[d.H5=1]="H5",d[d.Weapp=2]="Weapp",d[d.Alipay=3]="Alipay",d[d.Gcash=4]="Gcash",d[d.Dana=5]="Dana",d[d.Umma=6]="Umma",d[d.WebSDK=1e3]="WebSDK",d[d.AppSDK=1001]="AppSDK",d[d.Other=9999]="Other",d))(Fe||{}),ye=["name","params"],$e=["name","type","location","target","extra","timestamp","userId"],je=["platform","os","appVersion","appId","model","brand","uuid","jsSdkVersion","extra"];function L(t,e){return e.map(n=>{if(n==="params"&&t[n]){let r=t[n];return Object.keys(r).reduce((o,s)=>(o[s]=String(r[s]),o),{})}return t[n]})}function He(t){let e=t.location?L(t.location,ye):null,n=t.target?L(t.target,ye):null;return L(O(y({},t),{location:e,target:n}),$e)}function rn(t){let e=t.events.map(r=>He(r)),n=L(t.device,je);return[t.protocolVersion,e,n,t.project]}var Te=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{let e=Math.random()*16|0;return(t==="x"?e:e&3|8).toString(16)}),cn=t=>/^[\da-f]{8}-[\da-f]{4}-4[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i.test(t);function xe(){if(typeof window=="undefined")return{getItem:()=>null,setItem:()=>{},removeItem:()=>{},clear:()=>{},length:0,key:()=>null};try{if(window.__joliboxLocalStorage__)return window.__joliboxLocalStorage__;let t=Object.getOwnPropertyDescriptor(window,"localStorage");if(t&&t.get){let r=t.get.call(window);return window.__joliboxLocalStorage__=r,r}if(t=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(window),"localStorage"),t&&t.get)return t.get.call(window);let e=Window.prototype,n=Object.getOwnPropertyDescriptor(e,"localStorage");if(n&&n.get){let r=n.get.call(window);return window.__joliboxLocalStorage__=r,r}return localStorage}catch(t){return console.warn("Failed to get original localStorage, fallback to default implementation",t),localStorage}}xe();var C=typeof window=="undefined",Ke=()=>!C&&!!(navigator.userAgent||"").includes("JoliboxPlatformSDK"),q={isiOS:!C&&(navigator.userAgent.includes("iPhone")||navigator.userAgent.includes("iPod")||navigator.userAgent.includes("iPad")||navigator.userAgent.includes("iPhone OS")),iosVersion:()=>{let t=navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/);return[parseInt(t[1],10),parseInt(t[2],10),parseInt(t[3]||"0",10)]},isAndroid:!C&&navigator.userAgent.includes("Android"),isMac:!C&&navigator.userAgent.includes("Mac"),isFacebook:!C&&navigator.userAgent.includes("FB_IAB"),isPC:!C&&!navigator.userAgent.includes("iPhone")&&!navigator.userAgent.includes("Android")},Ge=()=>q.isiOS?"iOS":q.isAndroid?"Android":q.isMac?"Mac":q.isFacebook?"Facebook":"PC",Je="device_id",ze="advertising_id",_e=t=>(window.__joliboxLocalStorage__.getItem(t)||window.__joliboxLocalStorage__.setItem(t,Te()),window.__joliboxLocalStorage__.getItem(t)),We=()=>{let e=new URLSearchParams(window.location.search).get("deviceId");return e||_e(Je)},Be=()=>{let e=new URLSearchParams(window.location.search).get("advertisingId");return e||_e(ze)},Qe=t=>t.charAt(0).toUpperCase()+t.slice(1),Ye=()=>{var e;let t=new URLSearchParams(window.location.search);return Qe((e=t.get("utm_source"))!=null?e:"")||"JoliboxSDK"},hn=t=>{if(Ke())return window.navigator.userAgent;let e="JoliboxWebSDK",n=Ge(),r=navigator.language,o=We(),s=Be();return`${e} (${Ye()}${n}; UnknownModel; UnknownSystemVersion; ${r}) uuid/${o} adid/${s} version/${t||""}`};function M(t,e,n){let r=window.location.hostname,o=r.split("."),s=n?e:t;if(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(r))return`${s}.jolibox.com`;if(o.length>=2){let c=o.slice(-2).join(".");if(c==="jolibox.com"||c==="pico-game.com"||c==="joyslite.com")return`${s}.${c}`}return`${s}.jolibox.com`}function Xe(t){return M("app","stg-app",t)}function yn(t){return`https://${Xe(t)}`}function Tn(t){return`https://${M("api","stg-api",t)}`}function xn(t){return M("api","stg-api",t)}function Ze(t){return M("collect","stg-collect",t)}function _n(t){return`https://${Ze(t)}`}var ve=class{constructor(e,n={}){this.requestAdapter=e;this.cache=new Map;this.pendingRequests=new Map;this.requestSequence=0;this.cacheSequences=new Map;this.config=y({duration:10*60*1e3,timeout:3e3,keyGenerator:(r,o)=>r,consistencyChecker:()=>!0},n)}request(e,n){return h(this,null,function*(){let r=this.config.keyGenerator(e,n),o=this.pendingRequests.get(r);if(o)return console.log(`[RequestCacheService] Reusing pending request for ${e}`),o;let s=this.requestInternal(e,n),i=this.createTimeoutPromise(),c=Promise.race([s,i]).catch(a=>h(this,null,function*(){if(a.message.includes("timeout")){let u=this.getValidCachedData(r);if(u)return console.warn(`[RequestCacheService] Request timeout, falling back to cache for ${e}`),this.requestAdapter.processCachedData?this.requestAdapter.processCachedData(u):u}throw a}));this.pendingRequests.set(r,c),s.then(a=>{console.log(`[RequestCacheService] Background request completed successfully for ${e}`)}).catch(a=>{console.warn(`[RequestCacheService] Background request failed for ${e}:`,a)});try{return yield c}finally{this.pendingRequests.delete(r)}})}requestInternal(e,n){return h(this,null,function*(){var a,u,d,R;let r=this.config.keyGenerator(e,n),o=++this.requestSequence,s=this.getValidCachedData(r);if(console.log("[RequestCacheService] requestInternal start",e,"cached:",s),s){if(this.requestAdapter.extractRealTimeData&&this.requestAdapter.mergeData)try{let f=yield this.requestAdapter.execute(e,n),v=this.requestAdapter.extractRealTimeData(f),E=(u=(a=this.requestAdapter).extractCacheableData)==null?void 0:u.call(a,f);return E&&!this.config.consistencyChecker(s,E)?(console.log(`[RequestCacheService] Cache invalidated due to data change for ${e}`),this.setCachedDataWithSequence(r,E,o),f):this.requestAdapter.mergeData(s,v)}catch(f){return console.warn(`[RequestCacheService] Failed to fetch real-time data, using cache only for ${e}:`,f),this.requestAdapter.processCachedData?this.requestAdapter.processCachedData(s):s}return console.log(`[RequestCacheService] use cache for ${e}`),this.requestAdapter.processCachedData?this.requestAdapter.processCachedData(s):s}console.log(`[RequestCacheService] Cache miss, fetching fresh data for ${e} (sequence: ${o})`);let i=yield this.requestAdapter.execute(e,n),c=(R=(d=this.requestAdapter).extractCacheableData)==null?void 0:R.call(d,i);return c&&this.setCachedDataWithSequence(r,c,o),i})}createTimeoutPromise(){return new Promise((e,n)=>{setTimeout(()=>{n(new Error(`[RequestCacheService] Request timeout after ${this.config.timeout/1e3} seconds`))},this.config.timeout)})}getValidCachedData(e){let n=this.cache.get(e);return n?Date.now()>n.expiresAt?(this.cache.delete(e),null):n.data:null}setCachedDataWithSequence(e,n,r,o){let s=this.cache.get(e);if(s&&s.sequence>r){console.log(`[RequestCacheService] Ignoring stale cache update for ${e} (current: ${s.sequence}, incoming: ${r})`);return}let i=Date.now();this.cache.set(e,{data:JSON.parse(JSON.stringify(n)),timestamp:i,expiresAt:i+this.config.duration,key:e,sequence:r,metadata:o}),this.cacheSequences.set(e,r),console.log(`[RequestCacheService] Updated cache for ${e} with sequence ${r}`)}refreshCache(e,n){return h(this,null,function*(){let r=this.config.keyGenerator(e,n);return this.cache.delete(r),this.request(e,n)})}forceRequest(e,n){return h(this,null,function*(){var c,a;let r=this.config.keyGenerator(e,n),o=++this.requestSequence;console.log(`[RequestCacheService] Force request for ${e} (sequence: ${o})`);let s=yield this.requestAdapter.execute(e,n),i=(a=(c=this.requestAdapter).extractCacheableData)==null?void 0:a.call(c,s);return i&&(this.setCachedDataWithSequence(r,i,o),console.log(`[RequestCacheService] Force updated cache for ${e}`)),s})}warmupCache(e,n){return h(this,null,function*(){let r=this.config.keyGenerator(e,n);if(this.pendingRequests.has(r)){console.log(`[RequestCacheService] Skipping warmup for ${e} - request in progress`);return}if(this.hasValidCache(r)){console.log(`[RequestCacheService] Skipping warmup for ${e} - valid cache exists`);return}try{console.log(`[RequestCacheService] Warming up cache for ${e}`),yield this.forceRequest(e,n)}catch(o){console.warn(`[RequestCacheService] Cache warmup failed for ${e}:`,o)}})}clearCache(e){e?(this.cache.delete(e),this.cacheSequences.delete(e),this.pendingRequests.delete(e),console.log(`[RequestCacheService] Cleared cache for ${e}`)):(this.cache.clear(),this.cacheSequences.clear(),this.pendingRequests.clear(),this.requestSequence=0,console.log("[RequestCacheService] Cleared all cache"))}clearExpiredCache(){let e=Date.now();for(let[n,r]of this.cache)e>r.expiresAt&&(this.cache.delete(n),this.cacheSequences.delete(n));console.log("[RequestCacheService] Cleared expired cache entries")}getCacheStats(){let e=Date.now(),n=0,r=0;for(let o of this.cache.values())e>o.expiresAt?r++:n++;return{cacheCount:this.cache.size,validCount:n,expiredCount:r,pendingRequestCount:this.pendingRequests.size}}getCacheKeys(){return Array.from(this.cache.keys())}hasValidCache(e){let n=this.cache.get(e);return n?Date.now()<=n.expiresAt:!1}getPendingRequestKeys(){return Array.from(this.pendingRequests.keys())}hasPendingRequest(e){return this.pendingRequests.has(e)}getCacheSequence(e){return this.cacheSequences.get(e)}};var b=class b{constructor(e){this.element=e,this.next=b.Undefined,this.prev=b.Undefined}};b.Undefined=new b(void 0);var m=b,U=class{constructor(){this._first=m.Undefined;this._last=m.Undefined;this._size=0}get size(){return this._size}isEmpty(){return this._first===m.Undefined}clear(){let e=this._first;for(;e!==m.Undefined;){let n=e.next;e.prev=m.Undefined,e.next=m.Undefined,e=n}this._first=m.Undefined,this._last=m.Undefined,this._size=0}unshift(e){return this._insert(e,!1)}push(e){return this._insert(e,!0)}_insert(e,n){let r=new m(e);if(this._first===m.Undefined)this._first=r,this._last=r;else if(n){let s=this._last;this._last=r,r.prev=s,s.next=r}else{let s=this._first;this._first=r,r.next=s,s.prev=r}this._size+=1;let o=!1;return()=>{o||(o=!0,this._remove(r))}}shift(){if(this._first!==m.Undefined){let e=this._first.element;return this._remove(this._first),e}}pop(){if(this._last!==m.Undefined){let e=this._last.element;return this._remove(this._last),e}}_remove(e){if(e.prev!==m.Undefined&&e.next!==m.Undefined){let n=e.prev;n.next=e.next,e.next.prev=n}else e.prev===m.Undefined&&e.next===m.Undefined?(this._first=m.Undefined,this._last=m.Undefined):e.next===m.Undefined?(this._last=this._last.prev,this._last.next=m.Undefined):e.prev===m.Undefined&&(this._first=this._first.next,this._first.prev=m.Undefined);this._size-=1}*[Symbol.iterator](){let e=this._first;for(;e!==m.Undefined;)yield e.element,e=e.next}};var et=0,_=class{constructor(e){this.value=e;this.id=et++}},g=class{constructor(e){this.options=e;this._size=0}dispose(e){var n,r;this._disposed||(this._disposed=!0,this._listeners&&(e?(this._listeners instanceof _&&(this._listeners=[this._listeners]),this._listeners=this._listeners.filter(o=>(o==null?void 0:o.value)===e)):(this._listeners=void 0,this._size=0)),(r=(n=this.options)==null?void 0:n.onDidRemoveLastListener)==null||r.call(n))}get event(){var e;return(e=this._event)!=null||(this._event=(n,r)=>{var s,i,c,a,u,d;if(this._disposed)return()=>{console.info("[Jolibox SDK] Emitter is _disposed")};r&&(n=n.bind(r));let o=new _(n);return this._listeners?this._listeners instanceof _?this._listeners=[this._listeners,o]:this._listeners.push(o):((i=(s=this.options)==null?void 0:s.onWillAddFirstListener)==null||i.call(s,this),this._listeners=o,(a=(c=this.options)==null?void 0:c.onDidFirstListener)==null||a.call(c,this)),(d=(u=this.options)==null?void 0:u.onDidAddListener)==null||d.call(u,this),this._size++,()=>{var R,f,v,E;if(!this._disposed){if(this._listeners instanceof _)this._listeners.id===o.id&&(this._listeners=void 0,this._size=0,(f=(R=this.options)==null?void 0:R.onDidRemoveLastListener)==null||f.call(R));else if(this._listeners){let J=this._listeners.indexOf(o);J>=0&&(this._listeners.splice(J,1),this._size--,this._size===0&&((E=(v=this.options)==null?void 0:v.onDidRemoveLastListener)==null||E.call(v)))}}}}),this._event}_deliver(e,n){var o;if(!e)return;let r=((o=this.options)==null?void 0:o.onListenerError)||Error.constructor;if(!r){e.value(n);return}try{e.value(n)}catch(s){r(s)}}fire(e){this._listeners&&(this._listeners instanceof _?this._deliver(this._listeners,e):this._listeners.forEach(n=>this._deliver(n,e)))}hasListeners(){return this._size>0}},S=class{constructor(){this.listeners=new Map;this.listerHandlerMap=new WeakMap;this.cachedEventQueue=new Map}on(e,n,r=!0){var a;let o=(a=this.listeners.get(e))!=null?a:new g,s=u=>n(...u.args),i=o.event(s);this.listerHandlerMap.set(n,{handler:s,dispose:i}),this.listeners.set(e,o);let c=this.cachedEventQueue.get(e);if(c&&r)for(let u of c)n(...u.args)}flushCachedEvent(e){e?this.cachedEventQueue.delete(e):this.cachedEventQueue.clear()}off(e,n){let r=this.listerHandlerMap.get(n);r&&(r.dispose(),this.listerHandlerMap.delete(n))}emit(e,...n){let r=this.listeners.get(e),o=this.cachedEventQueue.get(e);o||(o=new U,this.cachedEventQueue.set(e,o)),o.push({args:n}),r&&r.fire({event:e,args:n})}once(e,n){let r=(...o)=>{n(...o),this.off(e,r)};this.on(e,r,!1)}};var A={};Oe(A,{None:()=>tt,filter:()=>rt,once:()=>Ee,toPromise:()=>nt});var tt=()=>(console.log("[Jolibox SDK] None Event"),()=>{console.log("[Jolibox SDK] None Event dispose")});function nt(t){return new Promise(e=>Ee(t)(e))}function Ee(t){return(e,n=null)=>{let r=!1;return t(s=>{if(!r)return r=!0,e.call(n,s)},null)}}function rt(t,e){return(r=>{let o,s={onWillAddFirstListener(){o=r(i.fire,i)}},i=new g(s);return i.event})((r,o=null)=>t(s=>e(s)&&r.call(o,s),null))}var G=Symbol.for("Jolibox.hostEmitter"),ot=()=>{let t=new S;return globalThis[G]||(globalThis[G]={on:t.on.bind(t),off:t.off.bind(t),emit:t.emit.bind(t),once:t.once.bind(t)}),globalThis[G]},tr=ot();function Ce(t,e){let n=Math.min(t.length,e.length);for(let r=0;r<n;r++)st(t[r],e[r])}function st(t,e){if(F(e)){if(typeof t!==e)throw new Error(`argument does not match constraint: typeof ${e}`)}else if(j(e)){try{if(t instanceof e)return}catch(n){}if(!$(t)&&t.constructor===e||e.length===1&&e.call(void 0,t)===!0)return;throw new Error("[Jolibox SDK]argument does not match one of these constraints: arg instanceof constraint, arg.constructor === constraint, nor constraint(arg) === true")}}var x=class{constructor(){this._commands=new Map;this._onDidRegisterCommand=new g;this.onDidRegisterCommand=this._onDidRegisterCommand.event;console.log("[Jolibox SDK] command registry")}registerCommand(e){if(!e)throw new Error("invalid command");if(e.metadata&&Array.isArray(e.metadata.args)){let o=[];for(let i of e.metadata.args)o.push(i.constraint);let s=e.handler;e.handler=function(...i){return Ce(i,o),s(...i)}}let{id:n}=e;this._commands.get(n)&&console.info(`[Jolibox SDK] duplicated command is registered ${n}`),this._commands.set(n,e),this._onDidRegisterCommand.fire(n)}getCommand(e){return this._commands.get(e)}getCommands(){let e=new Map;for(let n of this._commands.keys()){let r=this.getCommand(n);r&&e.set(n,r)}return e}};x=D([P],x);var w=class{constructor(){this._onWillExecuteCommand=new g;this.onWillExecuteCommand=this._onWillExecuteCommand.event;this._onDidExecuteCommand=new g;this.onDidExecuteCommand=this._onDidExecuteCommand.event;this.registry=new x;this._starActivation=null}_activateStar(){return this._starActivation||(this._starActivation=Q(3e4)),this._starActivation}executeCommand(e,...n){return h(this,null,function*(){return this.registry.getCommand(e)?this._tryExecuteCommand(e,n):(yield Promise.all([Promise.race([this._activateStar(),A.toPromise(A.filter(this.registry.onDidRegisterCommand,o=>o===e))])]),this._tryExecuteCommand(e,n))})}executeCommandThowErr(e,...n){if(!!!this.registry.getCommand(e))throw new Error(`command '${e}' not found`);let o=this.registry.getCommand(e);this._onWillExecuteCommand.fire({commandId:e,args:n});let s=this.invokeFunction(o.handler,...n);return this._onDidExecuteCommand.fire({commandId:e,args:n}),s}_tryExecuteCommand(e,n){let r=this.registry.getCommand(e);if(!r)return Promise.reject(new Error(`command '${e}' not found`));try{this._onWillExecuteCommand.fire({commandId:e,args:n});let o=this.invokeFunction(r.handler,...n);return this._onDidExecuteCommand.fire({commandId:e,args:n}),Promise.resolve(o)}catch(o){return Promise.reject(o)}}invokeFunction(e,...n){let r=!1;try{return e(...n)}finally{r=!0}}};w=D([P],w);var be=Symbol.for("Jolibox.commands");function it(){return typeof globalThis!="undefined"?globalThis[be]:void 0}function at(t){typeof globalThis!="undefined"&&(globalThis[be]=t)}function Sr(t=!1){let e=it();if(!t&&e)return e;let n=new x,r=new w,o={registerCommand(s,i,c){n.registerCommand({id:s,handler:i,metadata:c})},executeCommand(s,...i){return r.executeCommand(s,...i)},excuteCommandSync(s,...i){return r.executeCommandThowErr(s,...i)}};return at(o),o}export{ze as ADVERTISING_ID,fe as APIError,I as BaseError,Je as DEVICE_ID,B as Deferred,Fe as EPlatform,Ve as EProject,S as EventEmitter,Ue as EventType,A as EventUtils,ce as InternalApplyNativeError,ue as InternalBufferError,me as InternalContextError,p as InternalError,pe as InternalGlobalJSError,le as InternalInvokeMethodError,ie as InternalInvokeNativeError,de as InternalJSCoreNotFoundError,se as InternalJSModuleEvalError,oe as InternalJSModuleFetchError,he as InternalMetricReportError,ae as InternalPaymentError,ge as InternalReporterError,re as InternalSchemaParseError,ke as LoadScriptCode,ve as RequestCacheService,P as Singleton,k as UserCustomError,T as UserError,ee as UserFetchError,ne as UserFunctionEvalError,Z as UserGlobalError,te as UserPaymentError,X as UserValidateError,Bt as canIUseConfig,Yt as canIUseConfigNative,en as compareVersion,Sr as createCommands,mt as createRunTaskQueue,Pt as debounce,Qt as get,Be as getAdvertisingId,Xe as getApiDomain,yn as getApiHost,Ze as getCollectDomain,_n as getCollectHost,We as getDeviceId,Tn as getH5ApiHost,xn as getH5Domain,xe as getOriginalLocalStorage,Ge as getPlatform,_e as getStorage,Ye as getUtmSource,tr as hostEmitter,yt as isArray,_t as isBoolean,vt as isDefined,j as isFunction,xt as isIterable,Ke as isNative,Tt as isNumber,De as isObject,Et as isPromiseLike,F as isString,gt as isStringArray,Rt as isTypedArray,Pe as isUndefined,$ as isUndefinedOrNull,cn as isValidUUIDV4,Re as logger,Nt as mergeArray,It as mergeWith,ut as microTask,q as platform,dt as promisifyAPI,rn as serializeEventPackage,lt as sleep,Q as timeout,Te as uuidv4,st as validateConstraint,Ce as validateConstraints,Ft as wrapUserFunction,hn as xUserAgent};
1
+ var V=Object.defineProperty,Ie=Object.defineProperties,Ae=Object.getOwnPropertyDescriptor,Ce=Object.getOwnPropertyDescriptors;var B=Object.getOwnPropertySymbols;var we=Object.prototype.hasOwnProperty,Ne=Object.prototype.propertyIsEnumerable;var W=(n,e,t)=>e in n?V(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,_=(n,e)=>{for(var t in e||(e={}))we.call(e,t)&&W(n,t,e[t]);if(B)for(var t of B(e))Ne.call(e,t)&&W(n,t,e[t]);return n},N=(n,e)=>Ie(n,Ce(e));var Oe=(n,e)=>{for(var t in e)V(n,t,{get:e[t],enumerable:!0})};var O=(n,e,t,r)=>{for(var o=r>1?void 0:r?Ae(e,t):e,i=n.length-1,s;i>=0;i--)(s=n[i])&&(o=(r?s(e,t,o):s(o))||o);return r&&o&&V(e,t,o),o};var P=(n,e,t)=>new Promise((r,o)=>{var i=a=>{try{d(t.next(a))}catch(u){o(u)}},s=a=>{try{d(t.throw(a))}catch(u){o(u)}},d=a=>a.done?r(a.value):Promise.resolve(a.value).then(i,s);d((t=t.apply(n,e)).next())});if(typeof window!="undefined"&&!window.AbortController){let n=function(){this.signal=new e};n.prototype.abort=function(){this.signal._aborted=!0,typeof this.signal.onabort=="function"&&this.signal.onabort(new Event("abort"));let t=new Event("abort");this.signal.dispatchEvent(t)};let e=function(){this._aborted=!1,this.aborted=!1,this.onabort=null,this._eventListeners={}};Object.defineProperty(e.prototype,"aborted",{get:function(){return this._aborted}}),e.prototype.addEventListener=function(t,r){this._eventListeners[t]||(this._eventListeners[t]=[]),this._eventListeners[t].push(r)},e.prototype.removeEventListener=function(t,r){if(!this._eventListeners[t])return;let o=this._eventListeners[t].indexOf(r);o!==-1&&this._eventListeners[t].splice(o,1)},e.prototype.dispatchEvent=function(t){if(this._eventListeners[t.type])for(let r of this._eventListeners[t.type])r.call(this,t)},window.AbortController=n,window.AbortSignal=e}function Y(n){return new Promise(e=>{setTimeout(()=>{e()},n)})}function ln(n){return new Promise(e=>setTimeout(e,n))}function cn(n){return e=>new Promise((t,r)=>{n(N(_({},e),{success:t,fail(o){let i=new Error(o.errMsg);r(i)}}))})}function mn(n){if(n)Promise.resolve().then(n);else return Promise.resolve()}var Q=class{constructor(){this.state="pending";this.promise=new Promise((e,t)=>{this.resolve=r=>{this.state==="pending"&&(this.state="fulfilled",e(r))},this.reject=r=>{this.state==="pending"&&(this.state="rejected",t(r))}})}};function un(){let n=[],e=!1,t=()=>P(this,null,function*(){let r=n.shift();if(r){e=!0;try{yield r()}finally{e=!1,t()}}});return r=>{n.push(r),e||t()}}function F(n){return typeof n=="string"}function yn(n){return Array.isArray(n)&&n.every(e=>F(e))}function Pe(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)&&!(n instanceof RegExp)&&!(n instanceof Date)}function xn(n){let e=Object.getPrototypeOf(Uint8Array);return typeof n=="object"&&n instanceof e}function hn(n){return typeof n=="object"&&Array.isArray(n)}function _n(n){return typeof n=="number"&&!isNaN(n)}function En(n){return!!n&&typeof n[Symbol.iterator]=="function"}function Rn(n){return n===!0||n===!1}function Se(n){return typeof n=="undefined"}function Tn(n){return!j(n)}function j(n){return Se(n)||n===null}function H(n){return typeof n=="function"}function vn(n){return Pe(n)&&H(n.then)}function S(n){let e=n,t=null,r=function(...o){return t||(t=new e(...o)),t};return r.prototype=e.prototype,r}function wn(n,e,t){if(typeof t!="function")throw new Error("[Jolibox SDK]Customizer must be a function");function r(o,i){for(let s in i)if(Object.prototype.hasOwnProperty.call(i,s)){let d=o[s],a=i[s],u=t(d,a,s,o,i);u!==void 0?o[s]=u:q(a)&&q(d)?o[s]=r(_({},d),a):Array.isArray(a)&&Array.isArray(d)?o[s]=[...d,...a]:o[s]=a}return o}return r(n,e)}function q(n){return n&&typeof n=="object"&&n.constructor===Object}function Nn(n,e){if(Array.isArray(n))return n.concat(e)}function Ln(n,e,t={}){let r=null,o,i,s,{leading:d=!1,trailing:a=!0}=t,u=()=>(s=n.apply(i,o),o=void 0,i=void 0,s),c=function(...h){o=h,i=this;let b=d&&!r;if(r&&clearTimeout(r),r=setTimeout(()=>{r=null,a&&!b&&u()},e),b)return u()};return c.cancel=()=>{r&&clearTimeout(r),r=null,o=i=void 0},c.flush=()=>{if(r)return clearTimeout(r),r=null,u()},c}var Le=(a=>(a[a.DEVELOPER_FILE_NOT_FOUND=0]="DEVELOPER_FILE_NOT_FOUND",a[a.INTERNAL_IOS_CAN_NOT_FOUND_PKG=1]="INTERNAL_IOS_CAN_NOT_FOUND_PKG",a[a.USER_IOS_LOAD_TIMEOUT=2]="USER_IOS_LOAD_TIMEOUT",a[a.INTERNAL_IOS_PKG_LOAD_ERROR=3]="INTERNAL_IOS_PKG_LOAD_ERROR",a[a.INTERNAL_IOS_PKG_PARSE_FAIL=4]="INTERNAL_IOS_PKG_PARSE_FAIL",a[a.USER_IOS_GET_EMPTY_DATA=5]="USER_IOS_GET_EMPTY_DATA",a[a.USER_ANDROID_GET_PKG_FAIL=6]="USER_ANDROID_GET_PKG_FAIL",a[a.DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE=7]="DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE",a))(Le||{}),I=class extends Error{constructor(e){if(typeof e=="string"){super(e),this.priority="P1";return}super(e.message),this.priority="P1",this.stack=e.stack,this.raw=e}},p=class extends I{constructor(){super(...arguments);this.kind="INTERNAL_ERROR"}},g=class extends I{constructor(){super(...arguments);this.kind="USER_ERROR"}},X=class extends g{constructor(){super(...arguments);this.name="USER_VALIDATE_ERROR"}},Z=class extends g{constructor(){super(...arguments);this.name="USER_GLOBAL_ERROR";this.priority="P1"}},L=class extends g{constructor(t,r,o){super(t);this.message=t;this.errNo=r;this.name="USER_CUSTOM_ERROR";this.errMsg=t,o&&(this.extra=Object.assign({},this.extra,o))}},ee=class extends g{constructor(t,r,o){super(t);this.message=t;this.errNo=r;this.name="USER_FETCH_ERROR";this.errMsg=t,o&&(this.extra=Object.assign({},this.extra,o))}},ne=class extends g{constructor(t,r,o){super(t);this.message=t;this.errNo=r;this.name="USER_PAYMENT_ERROR";this.errMsg=t,o&&(this.extra=Object.assign({},this.extra,o))}},te=class extends g{constructor(){super(...arguments);this.name="USER_CALLBACK_ERROR"}},re=class extends p{constructor(){super(...arguments);this.name="INTERNAL_SCHEMA_PARSE_ERROR";this.priority="P0"}},oe=class extends p{constructor(){super(...arguments);this.name="INTERNAL_JS_MODULE_FETCH_ERROR";this.priority="P0"}},ie=class extends p{constructor(){super(...arguments);this.name="INTERNAL_JS_MODULE_EVAL_ERROR";this.priority="P0"}},se=class extends p{constructor(){super(...arguments);this.name="INTERNAL_INVOKE_NATIVE_ERROR"}},ae=class extends p{constructor(t,r,o){super(t);this.message=t;this.errNo=r;this.name="INTERNAL_PAYMENT_ERROR";this.priority="P0";this.errMsg=t,o&&(this.extra=Object.assign({},this.extra,o))}},de=class extends p{constructor(t,r,o,i){super(t);this.errNo=r;this.name="INTERNAL_APPLY_NATIVE_ERROR";this.errorType=o,this.errorCode=i}},le=class extends p{constructor(){super(...arguments);this.name="INTERNAL_INVOKE_METHOD_ERROR"}},ce=class extends p{constructor(){super(...arguments);this.name="INTERNAL_JSCORE_ERROR";this.priority="P0"}},me=class extends p{constructor(){super(...arguments);this.name="INTERNAL_BUFFER_ERROR"}},ue=class extends p{constructor(t,r){super(t);this.message=t;this.name="INTERNAL_CONTEXT_ERROR";this.property=r}},pe=class extends p{constructor(){super(...arguments);this.name="INTERNAL_GLOBAL_JS_ERROR";this.priority="P1"}},fe=class extends I{constructor(t,r,o,i,s){super(t);this.message=t;this.code=r;this.kind="API_ERROR";this.name="API_ERROR";o&&(this.errorType=o),i!==void 0&&(this.stack=i),s&&(this.priority=s)}toJSON(){return{message:this.message,stack:this.stack,name:this.name,code:this.code,errorType:this.errorType}}},ge=class extends p{constructor(){super(...arguments);this.name="INTERNAL_METRIC_REPORT_ERROR"}},ye=class extends p{constructor(){super(...arguments);this.name="INTERNAL_REPORTER_ERROR"}};function ke(n,e){return(...t)=>e(n,...t)}function jn(n){return e=>ke(e,function(t,...r){if(typeof t=="function")try{return t.apply(this,r)}catch(o){n(new L(`${o}`))}})}function A(n){return(...e)=>{var r,o;((o=(r=globalThis.VConsole)==null?void 0:r[n])!=null?o:globalThis.console[n])(...e)}}var xe={log:A("log"),warn:A("warn"),info:A("info"),error:A("error"),debug:A("debug")};Object.assign(globalThis,{logger:xe});var $=Symbol.for("Jolibox.canIUseMap"),Me={};globalThis[$]||(globalThis[$]=Me);var Qn={get config(){return globalThis[$]}};function Yn(n,e,t){let r=n;for(let o of e)if(r&&typeof r=="object")r=r[o];else return t;return r===void 0?t:r}var K=Symbol.for("Jolibox.canIUseMap.native"),Ue={};globalThis[K]||(globalThis[K]=Ue);var qn={get config(){return globalThis[K]}};function et(n,e,t){let r=0;if(n!==e){let o=n.split("."),i=e.split("."),s=Math.max(o.length,i.length);for(let d=0;d<s;d++){let a=parseInt(o[d],10)||0,u=parseInt(i[d],10)||0;if(a>u){r=1;break}else if(a<u){r=-1;break}}}if(!t)return r;switch(t){case">":return r>0;case"<":return r<0;case"=":return r===0;case">=":return r>=0;case"<=":return r<=0;default:return!1}}var De=(l=>(l[l.Other=0]="Other",l[l.Route=1]="Route",l[l.Click=2]="Click",l[l.View=3]="View",l[l.Expose=4]="Expose",l[l.Swipe=5]="Swipe",l[l.Input=6]="Input",l[l.Select=7]="Select",l[l.SwitchOn=8]="SwitchOn",l[l.SwitchOff=9]="SwitchOff",l[l.Submit=10]="Submit",l[l.Scroll=11]="Scroll",l[l.Hide=12]="Hide",l[l.System=1e3]="System",l[l.ErrorTrace=1001]="ErrorTrace",l[l.UserDefined=1002]="UserDefined",l))(De||{}),Ve=(i=>(i.MiniGame="mini-game",i.MiniDrama="mini-drama",i.App="app",i.WebSDK="web-sdk",i.AppSDK="app-sdk",i))(Ve||{}),Fe=(c=>(c[c.App=0]="App",c[c.H5=1]="H5",c[c.Weapp=2]="Weapp",c[c.Alipay=3]="Alipay",c[c.Gcash=4]="Gcash",c[c.Dana=5]="Dana",c[c.Umma=6]="Umma",c[c.WebSDK=1e3]="WebSDK",c[c.AppSDK=1001]="AppSDK",c[c.Other=9999]="Other",c))(Fe||{}),he=["name","params"],je=["name","type","location","target","extra","timestamp","userId"],He=["platform","os","appVersion","appId","model","brand","uuid","jsSdkVersion","extra"];function k(n,e){return e.map(t=>{if(t==="params"&&n[t]){let r=n[t];return Object.keys(r).reduce((o,i)=>(o[i]=String(r[i]),o),{})}return n[t]})}function $e(n){let e=n.location?k(n.location,he):null,t=n.target?k(n.target,he):null;return k(N(_({},n),{location:e,target:t}),je)}function rt(n){let e=n.events.map(r=>$e(r)),t=k(n.device,He);return[n.protocolVersion,e,t,n.project]}var _e=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,n=>{let e=Math.random()*16|0;return(n==="x"?e:e&3|8).toString(16)}),at=n=>/^[\da-f]{8}-[\da-f]{4}-4[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i.test(n);function Ee(){if(typeof window=="undefined")return{getItem:()=>null,setItem:()=>{},removeItem:()=>{},clear:()=>{},length:0,key:()=>null};try{if(window.__joliboxLocalStorage__)return window.__joliboxLocalStorage__;let n=Object.getOwnPropertyDescriptor(window,"localStorage");if(n&&n.get){let r=n.get.call(window);return window.__joliboxLocalStorage__=r,r}if(n=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(window),"localStorage"),n&&n.get)return n.get.call(window);let e=Window.prototype,t=Object.getOwnPropertyDescriptor(e,"localStorage");if(t&&t.get){let r=t.get.call(window);return window.__joliboxLocalStorage__=r,r}return localStorage}catch(n){return console.warn("Failed to get original localStorage, fallback to default implementation",n),localStorage}}Ee();var E=typeof window=="undefined",Ke=()=>!E&&!!(navigator.userAgent||"").includes("JoliboxPlatformSDK"),M={isiOS:!E&&(navigator.userAgent.includes("iPhone")||navigator.userAgent.includes("iPod")||navigator.userAgent.includes("iPad")||navigator.userAgent.includes("iPhone OS")),iosVersion:()=>{let n=navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/);return[parseInt(n[1],10),parseInt(n[2],10),parseInt(n[3]||"0",10)]},isAndroid:!E&&navigator.userAgent.includes("Android"),isMac:!E&&navigator.userAgent.includes("Mac"),isFacebook:!E&&navigator.userAgent.includes("FB_IAB"),isPC:!E&&!navigator.userAgent.includes("iPhone")&&!navigator.userAgent.includes("Android")},Ge=()=>M.isiOS?"iOS":M.isAndroid?"Android":M.isMac?"Mac":M.isFacebook?"Facebook":"PC",Je="device_id",ze="advertising_id",Re=n=>(window.__joliboxLocalStorage__.getItem(n)||window.__joliboxLocalStorage__.setItem(n,_e()),window.__joliboxLocalStorage__.getItem(n)),Be=()=>{let e=new URLSearchParams(window.location.search).get("deviceId");return e||Re(Je)},We=()=>{let e=new URLSearchParams(window.location.search).get("advertisingId");return e||Re(ze)},Qe=n=>n.charAt(0).toUpperCase()+n.slice(1),Ye=()=>{var e;let n=new URLSearchParams(window.location.search);return Qe((e=n.get("utm_source"))!=null?e:"")||"JoliboxSDK"},ft=n=>{if(Ke())return window.navigator.userAgent;let e="JoliboxWebSDK",t=Ge(),r=navigator.language,o=Be(),i=We();return`${e} (${Ye()}${t}; UnknownModel; UnknownSystemVersion; ${r}) uuid/${o} adid/${i} version/${n||""}`};function U(n,e,t){let r=window.location.hostname,o=r.split("."),i=t?e:n;if(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(r))return`${i}.jolibox.com`;if(o.length>=2){let d=o.slice(-2).join(".");if(d==="jolibox.com"||d==="pico-game.com"||d==="joyslite.com")return`${i}.${d}`}return`${i}.jolibox.com`}function qe(n){return U("app","stg-app",n)}function xt(n){return`https://${qe(n)}`}function ht(n){return`https://${U("api","stg-api",n)}`}function _t(n){return U("api","stg-api",n)}function Xe(n){return U("collect","stg-collect",n)}function Et(n){return`https://${Xe(n)}`}var R=class R{constructor(e){this.element=e,this.next=R.Undefined,this.prev=R.Undefined}};R.Undefined=new R(void 0);var m=R,D=class{constructor(){this._first=m.Undefined;this._last=m.Undefined;this._size=0}get size(){return this._size}isEmpty(){return this._first===m.Undefined}clear(){let e=this._first;for(;e!==m.Undefined;){let t=e.next;e.prev=m.Undefined,e.next=m.Undefined,e=t}this._first=m.Undefined,this._last=m.Undefined,this._size=0}unshift(e){return this._insert(e,!1)}push(e){return this._insert(e,!0)}_insert(e,t){let r=new m(e);if(this._first===m.Undefined)this._first=r,this._last=r;else if(t){let i=this._last;this._last=r,r.prev=i,i.next=r}else{let i=this._first;this._first=r,r.next=i,i.prev=r}this._size+=1;let o=!1;return()=>{o||(o=!0,this._remove(r))}}shift(){if(this._first!==m.Undefined){let e=this._first.element;return this._remove(this._first),e}}pop(){if(this._last!==m.Undefined){let e=this._last.element;return this._remove(this._last),e}}_remove(e){if(e.prev!==m.Undefined&&e.next!==m.Undefined){let t=e.prev;t.next=e.next,e.next.prev=t}else e.prev===m.Undefined&&e.next===m.Undefined?(this._first=m.Undefined,this._last=m.Undefined):e.next===m.Undefined?(this._last=this._last.prev,this._last.next=m.Undefined):e.prev===m.Undefined&&(this._first=this._first.next,this._first.prev=m.Undefined);this._size-=1}*[Symbol.iterator](){let e=this._first;for(;e!==m.Undefined;)yield e.element,e=e.next}};var Ze=0,x=class{constructor(e){this.value=e;this.id=Ze++}},f=class{constructor(e){this.options=e;this._size=0}dispose(e){var t,r;this._disposed||(this._disposed=!0,this._listeners&&(e?(this._listeners instanceof x&&(this._listeners=[this._listeners]),this._listeners=this._listeners.filter(o=>(o==null?void 0:o.value)===e)):(this._listeners=void 0,this._size=0)),(r=(t=this.options)==null?void 0:t.onDidRemoveLastListener)==null||r.call(t))}get event(){var e;return(e=this._event)!=null||(this._event=(t,r)=>{var i,s,d,a,u,c;if(this._disposed)return()=>{console.info("[Jolibox SDK] Emitter is _disposed")};r&&(t=t.bind(r));let o=new x(t);return this._listeners?this._listeners instanceof x?this._listeners=[this._listeners,o]:this._listeners.push(o):((s=(i=this.options)==null?void 0:i.onWillAddFirstListener)==null||s.call(i,this),this._listeners=o,(a=(d=this.options)==null?void 0:d.onDidFirstListener)==null||a.call(d,this)),(c=(u=this.options)==null?void 0:u.onDidAddListener)==null||c.call(u,this),this._size++,()=>{var h,b,w,J;if(!this._disposed){if(this._listeners instanceof x)this._listeners.id===o.id&&(this._listeners=void 0,this._size=0,(b=(h=this.options)==null?void 0:h.onDidRemoveLastListener)==null||b.call(h));else if(this._listeners){let z=this._listeners.indexOf(o);z>=0&&(this._listeners.splice(z,1),this._size--,this._size===0&&((J=(w=this.options)==null?void 0:w.onDidRemoveLastListener)==null||J.call(w)))}}}}),this._event}_deliver(e,t){var o;if(!e)return;let r=((o=this.options)==null?void 0:o.onListenerError)||Error.constructor;if(!r){e.value(t);return}try{e.value(t)}catch(i){r(i)}}fire(e){this._listeners&&(this._listeners instanceof x?this._deliver(this._listeners,e):this._listeners.forEach(t=>this._deliver(t,e)))}hasListeners(){return this._size>0}},C=class{constructor(){this.listeners=new Map;this.listerHandlerMap=new WeakMap;this.cachedEventQueue=new Map}on(e,t,r=!0){var a;let o=(a=this.listeners.get(e))!=null?a:new f,i=u=>t(...u.args),s=o.event(i);this.listerHandlerMap.set(t,{handler:i,dispose:s}),this.listeners.set(e,o);let d=this.cachedEventQueue.get(e);if(d&&r)for(let u of d)t(...u.args)}flushCachedEvent(e){e?this.cachedEventQueue.delete(e):this.cachedEventQueue.clear()}off(e,t){let r=this.listerHandlerMap.get(t);r&&(r.dispose(),this.listerHandlerMap.delete(t))}emit(e,...t){let r=this.listeners.get(e),o=this.cachedEventQueue.get(e);o||(o=new D,this.cachedEventQueue.set(e,o)),o.push({args:t}),r&&r.fire({event:e,args:t})}once(e,t){let r=(...o)=>{t(...o),this.off(e,r)};this.on(e,r,!1)}};var T={};Oe(T,{None:()=>en,filter:()=>tn,once:()=>Te,toPromise:()=>nn});var en=()=>(console.log("[Jolibox SDK] None Event"),()=>{console.log("[Jolibox SDK] None Event dispose")});function nn(n){return new Promise(e=>Te(n)(e))}function Te(n){return(e,t=null)=>{let r=!1;return n(i=>{if(!r)return r=!0,e.call(t,i)},null)}}function tn(n,e){return(r=>{let o,i={onWillAddFirstListener(){o=r(s.fire,s)}},s=new f(i);return s.event})((r,o=null)=>n(i=>e(i)&&r.call(o,i),null))}var G=Symbol.for("Jolibox.hostEmitter"),rn=()=>{let n=new C;return globalThis[G]||(globalThis[G]={on:n.on.bind(n),off:n.off.bind(n),emit:n.emit.bind(n),once:n.once.bind(n)}),globalThis[G]},Yt=rn();function ve(n,e){let t=Math.min(n.length,e.length);for(let r=0;r<t;r++)on(n[r],e[r])}function on(n,e){if(F(e)){if(typeof n!==e)throw new Error(`argument does not match constraint: typeof ${e}`)}else if(H(e)){try{if(n instanceof e)return}catch(t){}if(!j(n)&&n.constructor===e||e.length===1&&e.call(void 0,n)===!0)return;throw new Error("[Jolibox SDK]argument does not match one of these constraints: arg instanceof constraint, arg.constructor === constraint, nor constraint(arg) === true")}}var y=class{constructor(){this._commands=new Map;this._onDidRegisterCommand=new f;this.onDidRegisterCommand=this._onDidRegisterCommand.event;console.log("[Jolibox SDK] command registry")}registerCommand(e){if(!e)throw new Error("invalid command");if(e.metadata&&Array.isArray(e.metadata.args)){let o=[];for(let s of e.metadata.args)o.push(s.constraint);let i=e.handler;e.handler=function(...s){return ve(s,o),i(...s)}}let{id:t}=e;this._commands.get(t)&&console.info(`[Jolibox SDK] duplicated command is registered ${t}`),this._commands.set(t,e),this._onDidRegisterCommand.fire(t)}getCommand(e){return this._commands.get(e)}getCommands(){let e=new Map;for(let t of this._commands.keys()){let r=this.getCommand(t);r&&e.set(t,r)}return e}};y=O([S],y);var v=class{constructor(){this._onWillExecuteCommand=new f;this.onWillExecuteCommand=this._onWillExecuteCommand.event;this._onDidExecuteCommand=new f;this.onDidExecuteCommand=this._onDidExecuteCommand.event;this.registry=new y;this._starActivation=null}_activateStar(){return this._starActivation||(this._starActivation=Y(3e4)),this._starActivation}executeCommand(e,...t){return P(this,null,function*(){return this.registry.getCommand(e)?this._tryExecuteCommand(e,t):(yield Promise.all([Promise.race([this._activateStar(),T.toPromise(T.filter(this.registry.onDidRegisterCommand,o=>o===e))])]),this._tryExecuteCommand(e,t))})}executeCommandThowErr(e,...t){if(!!!this.registry.getCommand(e))throw new Error(`command '${e}' not found`);let o=this.registry.getCommand(e);this._onWillExecuteCommand.fire({commandId:e,args:t});let i=this.invokeFunction(o.handler,...t);return this._onDidExecuteCommand.fire({commandId:e,args:t}),i}_tryExecuteCommand(e,t){let r=this.registry.getCommand(e);if(!r)return Promise.reject(new Error(`command '${e}' not found`));try{this._onWillExecuteCommand.fire({commandId:e,args:t});let o=this.invokeFunction(r.handler,...t);return this._onDidExecuteCommand.fire({commandId:e,args:t}),Promise.resolve(o)}catch(o){return Promise.reject(o)}}invokeFunction(e,...t){let r=!1;try{return e(...t)}finally{r=!0}}};v=O([S],v);var be=Symbol.for("Jolibox.commands");function sn(){return typeof globalThis!="undefined"?globalThis[be]:void 0}function an(n){typeof globalThis!="undefined"&&(globalThis[be]=n)}function Ir(n=!1){let e=sn();if(!n&&e)return e;let t=new y,r=new v,o={registerCommand(i,s,d){t.registerCommand({id:i,handler:s,metadata:d})},executeCommand(i,...s){return r.executeCommand(i,...s)},excuteCommandSync(i,...s){return r.executeCommandThowErr(i,...s)}};return an(o),o}export{ze as ADVERTISING_ID,fe as APIError,I as BaseError,Je as DEVICE_ID,Q as Deferred,Fe as EPlatform,Ve as EProject,C as EventEmitter,De as EventType,T as EventUtils,de as InternalApplyNativeError,me as InternalBufferError,ue as InternalContextError,p as InternalError,pe as InternalGlobalJSError,le as InternalInvokeMethodError,se as InternalInvokeNativeError,ce as InternalJSCoreNotFoundError,ie as InternalJSModuleEvalError,oe as InternalJSModuleFetchError,ge as InternalMetricReportError,ae as InternalPaymentError,ye as InternalReporterError,re as InternalSchemaParseError,Le as LoadScriptCode,S as Singleton,L as UserCustomError,g as UserError,ee as UserFetchError,te as UserFunctionEvalError,Z as UserGlobalError,ne as UserPaymentError,X as UserValidateError,Qn as canIUseConfig,qn as canIUseConfigNative,et as compareVersion,Ir as createCommands,un as createRunTaskQueue,Ln as debounce,Yn as get,We as getAdvertisingId,qe as getApiDomain,xt as getApiHost,Xe as getCollectDomain,Et as getCollectHost,Be as getDeviceId,ht as getH5ApiHost,_t as getH5Domain,Ee as getOriginalLocalStorage,Ge as getPlatform,Re as getStorage,Ye as getUtmSource,Yt as hostEmitter,hn as isArray,Rn as isBoolean,Tn as isDefined,H as isFunction,En as isIterable,Ke as isNative,_n as isNumber,Pe as isObject,vn as isPromiseLike,F as isString,yn as isStringArray,xn as isTypedArray,Se as isUndefined,j as isUndefinedOrNull,at as isValidUUIDV4,xe as logger,Nn as mergeArray,wn as mergeWith,mn as microTask,M as platform,cn as promisifyAPI,rt as serializeEventPackage,ln as sleep,Y as timeout,_e as uuidv4,on as validateConstraint,ve as validateConstraints,jn as wrapUserFunction,ft as xUserAgent};
@@ -13,4 +13,3 @@ export * from './uuid';
13
13
  export * from './xua';
14
14
  export * from './local-storage';
15
15
  export * from './host';
16
- export * from './cache/request-cache-service';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jolibox/common",
3
3
  "description": "This project is common utils for both sdk & implementation",
4
- "version": "1.2.5-beta.3",
4
+ "version": "1.2.5",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.es.js",
7
7
  "types": "dist/index.d.ts",
@@ -11,14 +11,14 @@
11
11
  "README.md"
12
12
  ],
13
13
  "dependencies": {
14
- "@jolibox/types": "1.2.5-beta.3"
14
+ "@jolibox/types": "1.2.5"
15
15
  },
16
16
  "devDependencies": {
17
17
  "typescript": "5.7.3",
18
18
  "@types/jest": "28.1.1",
19
19
  "rimraf": "6.0.1",
20
20
  "esbuild": "0.24.2",
21
- "@jolibox/eslint-config": "1.0.1-beta.11",
21
+ "@jolibox/eslint-config": "1.0.0",
22
22
  "@babel/core": "7.23.3"
23
23
  },
24
24
  "scripts": {
@@ -1,111 +0,0 @@
1
- /**
2
- * 通用请求缓存服务基类
3
- * 支持部分数据缓存,部分数据实时获取的混合模式
4
- */
5
- export interface CacheConfig<TCacheData, TServerData> {
6
- /** 缓存持续时间,默认10分钟 */
7
- duration?: number;
8
- /** 请求超时时间,默认3秒 */
9
- timeout?: number;
10
- /** 缓存键生成函数 */
11
- keyGenerator?: <TRequest>(endpoint: string, params?: TRequest) => string;
12
- /** 数据一致性校验函数 */
13
- consistencyChecker?: (cached: TCacheData, serverData: TServerData) => boolean;
14
- }
15
- export interface CacheEntry<T> {
16
- data: T;
17
- timestamp: number;
18
- expiresAt: number;
19
- key: string;
20
- sequence: number;
21
- metadata?: Record<string, unknown>;
22
- }
23
- export interface CacheStats {
24
- cacheCount: number;
25
- validCount: number;
26
- expiredCount: number;
27
- }
28
- export interface RequestAdapter<TRequest, TResponse, TCacheData, TRealTimeData> {
29
- /** 执行实际的网络请求 */
30
- execute(endpoint: string, options?: TRequest): Promise<TResponse>;
31
- /** 从响应中提取需要缓存的部分(不变数据) */
32
- extractCacheableData?(response: TResponse): TCacheData;
33
- /** 从响应中提取实时数据部分(变化数据) */
34
- extractRealTimeData?(response: TResponse): TRealTimeData;
35
- /** 合并缓存数据和实时数据 */
36
- mergeData?(cached: TCacheData, realTime: TRealTimeData): TResponse;
37
- /** 处理纯缓存场景的数据,当没有新的网络请求时 */
38
- processCachedData?(cached: TCacheData): TResponse;
39
- }
40
- export declare abstract class RequestCacheService<TRequest, TResponse, TCacheData, TRealTimeData> {
41
- protected requestAdapter: RequestAdapter<TRequest, TResponse, TCacheData, TRealTimeData>;
42
- private cache;
43
- private readonly config;
44
- private pendingRequests;
45
- private requestSequence;
46
- private cacheSequences;
47
- constructor(requestAdapter: RequestAdapter<TRequest, TResponse, TCacheData, TRealTimeData>, config?: Partial<CacheConfig<TCacheData, TCacheData>>);
48
- /**
49
- * 带缓存的请求方法 - 缓存优先 + 实时数据混合模式 + 请求去重
50
- */
51
- request(endpoint: string, options?: TRequest): Promise<TResponse>;
52
- private requestInternal;
53
- /**
54
- * timeout
55
- */
56
- private createTimeoutPromise;
57
- /**
58
- * get valid cached data
59
- */
60
- private getValidCachedData;
61
- /**
62
- * 设置缓存数据 (带序列号检查)
63
- */
64
- private setCachedDataWithSequence;
65
- /**
66
- * refresh cache
67
- */
68
- refreshCache(endpoint: string, options?: TRequest): Promise<TResponse>;
69
- /**
70
- * force request and update cache
71
- */
72
- forceRequest(endpoint: string, options?: TRequest): Promise<TResponse>;
73
- /**
74
- * warmup cache - 避免与正在进行的请求冲突
75
- */
76
- warmupCache(endpoint: string, options?: TRequest): Promise<void>;
77
- /**
78
- * clear cache with target key
79
- */
80
- clearCache(key?: string): void;
81
- /**
82
- * clear expired cache
83
- */
84
- clearExpiredCache(): void;
85
- /**
86
- * get cache stats
87
- */
88
- getCacheStats(): CacheStats & {
89
- pendingRequestCount: number;
90
- };
91
- /**
92
- * get all cache keys
93
- */
94
- getCacheKeys(): string[];
95
- /**
96
- * check if the target key has valid cache
97
- */
98
- hasValidCache(key: string): boolean;
99
- /**
100
- * get pending request keys for debugging
101
- */
102
- getPendingRequestKeys(): string[];
103
- /**
104
- * check if a request is currently pending
105
- */
106
- hasPendingRequest(key: string): boolean;
107
- /**
108
- * get cache sequence for a specific key
109
- */
110
- getCacheSequence(key: string): number | undefined;
111
- }