@jolibox/common 1.2.7 → 1.2.9-beta.9

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 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:()=>de,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:()=>le,mergeArray:()=>lt,mergeWith:()=>dt,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 dt(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 lt(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),l=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 l.cancel=()=>{r&&clearTimeout(r),r=null,o=s=void 0},l.flush=()=>{if(r)return clearTimeout(r),r=null,u()},l}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"}},de=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 le={log:P("log"),warn:P("warn"),info:P("info"),error:P("error"),debug:P("debug")};Object.assign(globalThis,{logger:le});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=(d=>(d[d.Other=0]="Other",d[d.Route=1]="Route",d[d.Click=2]="Click",d[d.View=3]="View",d[d.Expose=4]="Expose",d[d.Swipe=5]="Swipe",d[d.Input=6]="Input",d[d.Select=7]="Select",d[d.SwitchOn=8]="SwitchOn",d[d.SwitchOff=9]="SwitchOff",d[d.Submit=10]="Submit",d[d.Scroll=11]="Scroll",d[d.Hide=12]="Hide",d[d.System=1e3]="System",d[d.ErrorTrace=1001]="ErrorTrace",d[d.UserDefined=1002]="UserDefined",d))(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=(l=>(l[l.App=0]="App",l[l.H5=1]="H5",l[l.Weapp=2]="Weapp",l[l.Alipay=3]="Alipay",l[l.Gcash=4]="Gcash",l[l.Dana=5]="Dana",l[l.Umma=6]="Umma",l[l.WebSDK=1e3]="WebSDK",l[l.AppSDK=1001]="AppSDK",l[l.Other=9999]="Other",l))(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,l,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=(l=this.requestAdapter).extractCacheableData)==null?void 0:R.call(l,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,l;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)),(l=(u=this.options)==null?void 0:u.onDidAddListener)==null||l.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}
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,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 dt(t){return new Promise(e=>setTimeout(e,t))}function lt(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),l=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 l.cancel=()=>{r&&clearTimeout(r),r=null,o=s=void 0},l.flush=()=>{if(r)return clearTimeout(r),r=null,u()},l}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}},de=class extends p{constructor(){super(...arguments);this.name="INTERNAL_INVOKE_METHOD_ERROR"}},le=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=(d=>(d[d.Other=0]="Other",d[d.Route=1]="Route",d[d.Click=2]="Click",d[d.View=3]="View",d[d.Expose=4]="Expose",d[d.Swipe=5]="Swipe",d[d.Input=6]="Input",d[d.Select=7]="Select",d[d.SwitchOn=8]="SwitchOn",d[d.SwitchOff=9]="SwitchOff",d[d.Submit=10]="Submit",d[d.Scroll=11]="Scroll",d[d.Hide=12]="Hide",d[d.System=1e3]="System",d[d.ErrorTrace=1001]="ErrorTrace",d[d.UserDefined=1002]="UserDefined",d))(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=(l=>(l[l.App=0]="App",l[l.H5=1]="H5",l[l.Weapp=2]="Weapp",l[l.Alipay=3]="Alipay",l[l.Gcash=4]="Gcash",l[l.Dana=5]="Dana",l[l.Umma=6]="Umma",l[l.WebSDK=1e3]="WebSDK",l[l.AppSDK=1001]="AppSDK",l[l.Other=9999]="Other",l))(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,l,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=(l=this.requestAdapter).extractCacheableData)==null?void 0:R.call(l,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,l;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)),(l=(u=this.options)==null?void 0:u.onDidAddListener)==null||l.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,de as InternalInvokeMethodError,ie as InternalInvokeNativeError,le 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,lt as promisifyAPI,rn as serializeEventPackage,dt as sleep,Q as timeout,Te as uuidv4,st as validateConstraint,Ce as validateConstraints,Ft as wrapUserFunction,hn as xUserAgent};
@@ -29,7 +29,11 @@ export interface NativeCanIUseInfo {
29
29
  version: VersionCode;
30
30
  return?: NativeVersionCode | string;
31
31
  properties?: NativeVersionCode;
32
- platforms?: string[];
32
+ platforms?: {
33
+ ios?: VersionCode | false;
34
+ android?: VersionCode | false;
35
+ h5?: VersionCode | false;
36
+ };
33
37
  }
34
38
  type GlobalCanIUseMapNative = Record<string, NativeCanIUseInfo>;
35
39
  export declare const canIUseConfigNative: {
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.7",
4
+ "version": "1.2.9-beta.9",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.es.js",
7
7
  "types": "dist/index.d.ts",
@@ -11,7 +11,7 @@
11
11
  "README.md"
12
12
  ],
13
13
  "dependencies": {
14
- "@jolibox/types": "1.2.7"
14
+ "@jolibox/types": "1.2.9-beta.9"
15
15
  },
16
16
  "devDependencies": {
17
17
  "typescript": "5.7.3",