@jolibox/common 1.1.25 → 1.1.26

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 I=Object.defineProperty,Ue=Object.defineProperties,ge=Object.getOwnPropertyDescriptor,De=Object.getOwnPropertyDescriptors,Fe=Object.getOwnPropertyNames,pe=Object.getOwnPropertySymbols;var ye=Object.prototype.hasOwnProperty,Ve=Object.prototype.propertyIsEnumerable;var fe=(n,e,t)=>e in n?I(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,x=(n,e)=>{for(var t in e||(e={}))ye.call(e,t)&&fe(n,t,e[t]);if(pe)for(var t of pe(e))Ve.call(e,t)&&fe(n,t,e[t]);return n},L=(n,e)=>Ue(n,De(e));var Te=(n,e)=>{for(var t in e)I(n,t,{get:e[t],enumerable:!0})},je=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Fe(e))!ye.call(n,o)&&o!==t&&I(n,o,{get:()=>e[o],enumerable:!(r=ge(e,o))||r.enumerable});return n};var He=n=>je(I({},"__esModule",{value:!0}),n),P=(n,e,t,r)=>{for(var o=r>1?void 0:r?ge(e,t):e,i=n.length-1,a;i>=0;i--)(a=n[i])&&(o=(r?a(e,t,o):a(o))||o);return r&&o&&I(e,t,o),o};var S=(n,e,t)=>new Promise((r,o)=>{var i=s=>{try{l(t.next(s))}catch(m){o(m)}},a=s=>{try{l(t.throw(s))}catch(m){o(m)}},l=s=>s.done?r(s.value):Promise.resolve(s.value).then(i,a);l((t=t.apply(n,e)).next())});var An={};Te(An,{ADVERTISING_ID:()=>Ne,APIError:()=>ne,BaseError:()=>E,DEVICE_ID:()=>we,Deferred:()=>V,EPlatform:()=>Ie,EProject:()=>be,EventEmitter:()=>R,EventType:()=>ve,EventUtils:()=>T,InternalApplyNativeError:()=>Q,InternalBufferError:()=>Y,InternalContextError:()=>Z,InternalError:()=>u,InternalGlobalJSError:()=>ee,InternalInvokeMethodError:()=>q,InternalInvokeNativeError:()=>W,InternalJSCoreNotFoundError:()=>X,InternalJSModuleEvalError:()=>B,InternalJSModuleFetchError:()=>$,InternalMetricReportError:()=>te,InternalReporterError:()=>re,InternalSchemaParseError:()=>z,LoadScriptCode:()=>he,Singleton:()=>A,UserCustomError:()=>C,UserError:()=>f,UserFetchError:()=>J,UserFunctionEvalError:()=>G,UserGlobalError:()=>K,UserValidateError:()=>H,canIUseConfig:()=>an,compareVersion:()=>ln,createCommands:()=>In,createRunTaskQueue:()=>ze,debounce:()=>tn,get:()=>dn,getAdvertisingId:()=>Le,getDeviceId:()=>Oe,getOriginalLocalStorage:()=>ae,getPlatform:()=>Ce,getStorage:()=>de,getUtmSource:()=>Pe,hostEmitter:()=>Rn,isArray:()=>We,isBoolean:()=>Xe,isDefined:()=>Ye,isFunction:()=>U,isIterable:()=>qe,isNative:()=>Ae,isNumber:()=>Qe,isObject:()=>_e,isPromiseLike:()=>Ze,isString:()=>k,isStringArray:()=>$e,isTypedArray:()=>Be,isUndefined:()=>xe,isUndefinedOrNull:()=>M,isValidUUIDV4:()=>fn,logger:()=>oe,mergeArray:()=>nn,mergeWith:()=>en,microTask:()=>Ge,platform:()=>N,promisifyAPI:()=>Je,serializeEventPackage:()=>pn,sleep:()=>Ke,timeout:()=>j,uuidv4:()=>se,validateConstraint:()=>ke,validateConstraints:()=>ce,wrapUserFunction:()=>on,xUserAgent:()=>yn});module.exports=He(An);if(typeof window!="undefined"&&!window.AbortController){let n=function(){this.signal=new e};n.prototype.abort=function(){this.signal._aborted=!0,typeof this.signal.onabort=="function"&&this.signal.onabort(new Event("abort"));let t=new Event("abort");this.signal.dispatchEvent(t)};let e=function(){this._aborted=!1,this.aborted=!1,this.onabort=null,this._eventListeners={}};Object.defineProperty(e.prototype,"aborted",{get:function(){return this._aborted}}),e.prototype.addEventListener=function(t,r){this._eventListeners[t]||(this._eventListeners[t]=[]),this._eventListeners[t].push(r)},e.prototype.removeEventListener=function(t,r){if(!this._eventListeners[t])return;let o=this._eventListeners[t].indexOf(r);o!==-1&&this._eventListeners[t].splice(o,1)},e.prototype.dispatchEvent=function(t){if(this._eventListeners[t.type])for(let r of this._eventListeners[t.type])r.call(this,t)},window.AbortController=n,window.AbortSignal=e}function j(n){return new Promise(e=>{setTimeout(()=>{e()},n)})}function Ke(n){return new Promise(e=>setTimeout(e,n))}function Je(n){return e=>new Promise((t,r)=>{n(L(x({},e),{success:t,fail(o){let i=new Error(o.errMsg);r(i)}}))})}function Ge(n){if(n)Promise.resolve().then(n);else return Promise.resolve()}var V=class{constructor(){this.state="pending";this.promise=new Promise((e,t)=>{this.resolve=r=>{this.state==="pending"&&(this.state="fulfilled",e(r))},this.reject=r=>{this.state==="pending"&&(this.state="rejected",t(r))}})}};function ze(){let n=[],e=!1,t=()=>S(this,null,function*(){let r=n.shift();if(r){e=!0;try{yield r()}finally{e=!1,t()}}});return r=>{n.push(r),e||t()}}function k(n){return typeof n=="string"}function $e(n){return Array.isArray(n)&&n.every(e=>k(e))}function _e(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)&&!(n instanceof RegExp)&&!(n instanceof Date)}function Be(n){let e=Object.getPrototypeOf(Uint8Array);return typeof n=="object"&&n instanceof e}function We(n){return typeof n=="object"&&Array.isArray(n)}function Qe(n){return typeof n=="number"&&!isNaN(n)}function qe(n){return!!n&&typeof n[Symbol.iterator]=="function"}function Xe(n){return n===!0||n===!1}function xe(n){return typeof n=="undefined"}function Ye(n){return!M(n)}function M(n){return xe(n)||n===null}function U(n){return typeof n=="function"}function Ze(n){return _e(n)&&U(n.then)}function A(n){let e=n,t=null,r=function(...o){return t||(t=new e(...o)),t};return r.prototype=e.prototype,r}function en(n,e,t){if(typeof t!="function")throw new Error("[Jolibox SDK]Customizer must be a function");function r(o,i){for(let a in i)if(Object.prototype.hasOwnProperty.call(i,a)){let l=o[a],s=i[a],m=t(l,s,a,o,i);m!==void 0?o[a]=m:Ee(s)&&Ee(l)?o[a]=r(x({},l),s):Array.isArray(s)&&Array.isArray(l)?o[a]=[...l,...s]:o[a]=s}return o}return r(n,e)}function Ee(n){return n&&typeof n=="object"&&n.constructor===Object}function nn(n,e){if(Array.isArray(n))return n.concat(e)}function tn(n,e,t={}){let r=null,o,i,a,{leading:l=!1,trailing:s=!0}=t,m=()=>(a=n.apply(i,o),o=void 0,i=void 0,a),d=function(..._){o=_,i=this;let b=l&&!r;if(r&&clearTimeout(r),r=setTimeout(()=>{r=null,s&&!b&&m()},e),b)return m()};return d.cancel=()=>{r&&clearTimeout(r),r=null,o=i=void 0},d.flush=()=>{if(r)return clearTimeout(r),r=null,m()},d}var he=(s=>(s[s.DEVELOPER_FILE_NOT_FOUND=0]="DEVELOPER_FILE_NOT_FOUND",s[s.INTERNAL_IOS_CAN_NOT_FOUND_PKG=1]="INTERNAL_IOS_CAN_NOT_FOUND_PKG",s[s.USER_IOS_LOAD_TIMEOUT=2]="USER_IOS_LOAD_TIMEOUT",s[s.INTERNAL_IOS_PKG_LOAD_ERROR=3]="INTERNAL_IOS_PKG_LOAD_ERROR",s[s.INTERNAL_IOS_PKG_PARSE_FAIL=4]="INTERNAL_IOS_PKG_PARSE_FAIL",s[s.USER_IOS_GET_EMPTY_DATA=5]="USER_IOS_GET_EMPTY_DATA",s[s.USER_ANDROID_GET_PKG_FAIL=6]="USER_ANDROID_GET_PKG_FAIL",s[s.DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE=7]="DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE",s))(he||{}),E=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}},u=class extends E{constructor(){super(...arguments);this.kind="INTERNAL_ERROR"}},f=class extends E{constructor(){super(...arguments);this.kind="USER_ERROR"}},H=class extends f{constructor(){super(...arguments);this.name="USER_VALIDATE_ERROR"}},K=class extends f{constructor(){super(...arguments);this.name="USER_GLOBAL_ERROR";this.priority="P1"}},C=class extends f{constructor(t,r,o){super(t);this.message=t;this.errNo=r;this.name="USER_CUSTOM_ERROR";this.errMsg=t,o&&(this.extra=Object.assign({},this.extra,o))}},J=class extends f{constructor(t,r,o){super(t);this.message=t;this.errNo=r;this.name="USER_FETCH_ERROR";this.errMsg=t,o&&(this.extra=Object.assign({},this.extra,o))}},G=class extends f{constructor(){super(...arguments);this.name="USER_CALLBACK_ERROR"}},z=class extends u{constructor(){super(...arguments);this.name="INTERNAL_SCHEMA_PARSE_ERROR";this.priority="P0"}},$=class extends u{constructor(){super(...arguments);this.name="INTERNAL_JS_MODULE_FETCH_ERROR";this.priority="P0"}},B=class extends u{constructor(){super(...arguments);this.name="INTERNAL_JS_MODULE_EVAL_ERROR";this.priority="P0"}},W=class extends u{constructor(){super(...arguments);this.name="INTERNAL_INVOKE_NATIVE_ERROR"}},Q=class extends u{constructor(t,r,o,i){super(t);this.errNo=r;this.name="INTERNAL_APPLY_NATIVE_ERROR";this.errorType=o,this.errorCode=i}},q=class extends u{constructor(){super(...arguments);this.name="INTERNAL_INVOKE_METHOD_ERROR"}},X=class extends u{constructor(){super(...arguments);this.name="INTERNAL_JSCORE_ERROR";this.priority="P0"}},Y=class extends u{constructor(){super(...arguments);this.name="INTERNAL_BUFFER_ERROR"}},Z=class extends u{constructor(t,r){super(t);this.message=t;this.name="INTERNAL_CONTEXT_ERROR";this.property=r}},ee=class extends u{constructor(){super(...arguments);this.name="INTERNAL_GLOBAL_JS_ERROR";this.priority="P1"}},ne=class extends E{constructor(t,r,o,i,a){super(t);this.message=t;this.code=r;this.kind="API_ERROR";this.name="API_ERROR";o&&(this.errorType=o),i!==void 0&&(this.stack=i),a&&(this.priority=a)}toJSON(){return{message:this.message,stack:this.stack,name:this.name,code:this.code,errorType:this.errorType}}},te=class extends u{constructor(){super(...arguments);this.name="INTERNAL_METRIC_REPORT_ERROR"}},re=class extends u{constructor(){super(...arguments);this.name="INTERNAL_REPORTER_ERROR"}};function rn(n,e){return(...t)=>e(n,...t)}function on(n){return e=>rn(e,function(t,...r){if(typeof t=="function")try{return t.apply(this,r)}catch(o){n(new C(`${o}`))}})}function w(n){return(...e)=>{var r,o;((o=(r=globalThis.VConsole)==null?void 0:r[n])!=null?o:globalThis.console[n])(...e)}}var oe={log:w("log"),warn:w("warn"),info:w("info"),error:w("error"),debug:w("debug")};Object.assign(globalThis,{logger:oe});var ie=Symbol.for("Jolibox.canIUseMap"),sn={};globalThis[ie]||(globalThis[ie]=sn);var an={get config(){return globalThis[ie]}};function dn(n,e,t){let r=n;for(let o of e)if(r&&typeof r=="object")r=r[o];else return t;return r===void 0?t:r}function ln(n,e,t){let r=0;if(n!==e){let o=n.split("."),i=e.split("."),a=Math.max(o.length,i.length);for(let l=0;l<a;l++){let s=parseInt(o[l],10)||0,m=parseInt(i[l],10)||0;if(s>m){r=1;break}else if(s<m){r=-1;break}}}if(!t)return r;switch(t){case">":return r>0;case"<":return r<0;case"=":return r===0;case">=":return r>=0;case"<=":return r<=0;default:return!1}}var ve=(r=>(r[r.System=1e3]="System",r[r.ErrorTrace=1001]="ErrorTrace",r[r.UserDefined=1002]="UserDefined",r))(ve||{}),be=(i=>(i.MiniGame="mini-game",i.MiniDrama="mini-drama",i.App="app",i.WebSDK="web-sdk",i.AppSDK="app-sdk",i))(be||{}),Ie=(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))(Ie||{}),Re=["name","params"],cn=["name","type","location","target","extra","timestamp","userId"],mn=["platform","os","appVersion","appId","model","brand","uuid","jsSdkVersion","extra"];function D(n,e){return e.map(t=>{if(t==="params"&&n[t]){let r=n[t];return Object.keys(r).reduce((o,i)=>(o[i]=String(r[i]),o),{})}return n[t]})}function un(n){let e=n.location?D(n.location,Re):null,t=n.target?D(n.target,Re):null;return D(L(x({},n),{location:e,target:t}),cn)}function pn(n){let e=n.events.map(r=>un(r)),t=D(n.device,mn);return[n.protocolVersion,e,t,n.project]}var se=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,n=>{let e=Math.random()*16|0;return(n==="x"?e:e&3|8).toString(16)}),fn=n=>/^[\da-f]{8}-[\da-f]{4}-4[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i.test(n);function ae(){try{if(window.__joliboxLocalStorage__)return window.__joliboxLocalStorage__;let n=Object.getOwnPropertyDescriptor(window,"localStorage");if(n&&n.get){let r=n.get.call(window);return window.__joliboxLocalStorage__=r,r}if(n=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(window),"localStorage"),n&&n.get)return n.get.call(window);let e=Window.prototype,t=Object.getOwnPropertyDescriptor(e,"localStorage");if(t&&t.get){let r=t.get.call(window);return window.__joliboxLocalStorage__=r,r}return localStorage}catch(n){return console.warn("Failed to get original localStorage, fallback to default implementation",n),localStorage}}ae();var Ae=()=>!!(navigator.userAgent||"").includes("JoliboxPlatformSDK"),N={isiOS:navigator.userAgent.includes("iPhone")||navigator.userAgent.includes("iPod")||navigator.userAgent.includes("iPad")||navigator.userAgent.includes("iPhone OS"),iosVersion:()=>{let n=navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/);return[parseInt(n[1],10),parseInt(n[2],10),parseInt(n[3]||"0",10)]},isAndroid:navigator.userAgent.includes("Android"),isMac:navigator.userAgent.includes("Mac"),isFacebook:navigator.userAgent.includes("FB_IAB"),isPC:!navigator.userAgent.includes("iPhone")&&!navigator.userAgent.includes("Android")},Ce=()=>N.isiOS?"iOS":N.isAndroid?"Android":N.isMac?"Mac":N.isFacebook?"Facebook":"PC",we="device_id",Ne="advertising_id",de=n=>(window.__joliboxLocalStorage__.getItem(n)||window.__joliboxLocalStorage__.setItem(n,se()),window.__joliboxLocalStorage__.getItem(n)),Oe=()=>{let e=new URLSearchParams(window.location.search).get("deviceId");return e||de(we)},Le=()=>{let e=new URLSearchParams(window.location.search).get("advertisingId");return e||de(Ne)},gn=n=>n.charAt(0).toUpperCase()+n.slice(1),Pe=()=>{var e;let n=new URLSearchParams(window.location.search);return gn((e=n.get("utm_source"))!=null?e:"")||"JoliboxSDK"},yn=n=>{if(Ae())return window.navigator.userAgent;let e="JoliboxWebSDK",t=Ce(),r=navigator.language,o=Oe(),i=Le();return`${e} (${Pe()}${t}; UnknownModel; UnknownSystemVersion; ${r}) uuid/${o} adid/${i} version/${n||""}`};var h=class h{constructor(e){this.element=e,this.next=h.Undefined,this.prev=h.Undefined}};h.Undefined=new h(void 0);var c=h,F=class{constructor(){this._first=c.Undefined;this._last=c.Undefined;this._size=0}get size(){return this._size}isEmpty(){return this._first===c.Undefined}clear(){let e=this._first;for(;e!==c.Undefined;){let t=e.next;e.prev=c.Undefined,e.next=c.Undefined,e=t}this._first=c.Undefined,this._last=c.Undefined,this._size=0}unshift(e){return this._insert(e,!1)}push(e){return this._insert(e,!0)}_insert(e,t){let r=new c(e);if(this._first===c.Undefined)this._first=r,this._last=r;else if(t){let i=this._last;this._last=r,r.prev=i,i.next=r}else{let i=this._first;this._first=r,r.next=i,i.prev=r}this._size+=1;let o=!1;return()=>{o||(o=!0,this._remove(r))}}shift(){if(this._first!==c.Undefined){let e=this._first.element;return this._remove(this._first),e}}pop(){if(this._last!==c.Undefined){let e=this._last.element;return this._remove(this._last),e}}_remove(e){if(e.prev!==c.Undefined&&e.next!==c.Undefined){let t=e.prev;t.next=e.next,e.next.prev=t}else e.prev===c.Undefined&&e.next===c.Undefined?(this._first=c.Undefined,this._last=c.Undefined):e.next===c.Undefined?(this._last=this._last.prev,this._last.next=c.Undefined):e.prev===c.Undefined&&(this._first=this._first.next,this._first.prev=c.Undefined);this._size-=1}*[Symbol.iterator](){let e=this._first;for(;e!==c.Undefined;)yield e.element,e=e.next}};var Tn=0,y=class{constructor(e){this.value=e;this.id=Tn++}},p=class{constructor(e){this.options=e;this._size=0}dispose(e){var t,r;this._disposed||(this._disposed=!0,this._listeners&&(e?(this._listeners instanceof y&&(this._listeners=[this._listeners]),this._listeners=this._listeners.filter(o=>(o==null?void 0:o.value)===e)):(this._listeners=void 0,this._size=0)),(r=(t=this.options)==null?void 0:t.onDidRemoveLastListener)==null||r.call(t))}get event(){var e;return(e=this._event)!=null||(this._event=(t,r)=>{var i,a,l,s,m,d;if(this._disposed)return()=>{console.info("[Jolibox SDK] Emitter is _disposed")};r&&(t=t.bind(r));let o=new y(t);return this._listeners?this._listeners instanceof y?this._listeners=[this._listeners,o]:this._listeners.push(o):((a=(i=this.options)==null?void 0:i.onWillAddFirstListener)==null||a.call(i,this),this._listeners=o,(s=(l=this.options)==null?void 0:l.onDidFirstListener)==null||s.call(l,this)),(d=(m=this.options)==null?void 0:m.onDidAddListener)==null||d.call(m,this),this._size++,()=>{var _,b,O,me;if(!this._disposed){if(this._listeners instanceof y)this._listeners.id===o.id&&(this._listeners=void 0,this._size=0,(b=(_=this.options)==null?void 0:_.onDidRemoveLastListener)==null||b.call(_));else if(this._listeners){let ue=this._listeners.indexOf(o);ue>=0&&(this._listeners.splice(ue,1),this._size--,this._size===0&&((me=(O=this.options)==null?void 0:O.onDidRemoveLastListener)==null||me.call(O)))}}}}),this._event}_deliver(e,t){var o;if(!e)return;let r=((o=this.options)==null?void 0:o.onListenerError)||Error.constructor;if(!r){e.value(t);return}try{e.value(t)}catch(i){r(i)}}fire(e){this._listeners&&(this._listeners instanceof y?this._deliver(this._listeners,e):this._listeners.forEach(t=>this._deliver(t,e)))}hasListeners(){return this._size>0}},R=class{constructor(){this.listeners=new Map;this.listerHandlerMap=new WeakMap;this.cachedEventQueue=new Map}on(e,t,r=!0){var s;let o=(s=this.listeners.get(e))!=null?s:new p,i=m=>t(...m.args),a=o.event(i);this.listerHandlerMap.set(t,{handler:i,dispose:a}),this.listeners.set(e,o);let l=this.cachedEventQueue.get(e);if(l&&r)for(let m of l)t(...m.args)}flushCachedEvent(e){e?this.cachedEventQueue.delete(e):this.cachedEventQueue.clear()}off(e,t){let r=this.listerHandlerMap.get(t);r&&(r.dispose(),this.listerHandlerMap.delete(t))}emit(e,...t){let r=this.listeners.get(e),o=this.cachedEventQueue.get(e);o||(o=new F,this.cachedEventQueue.set(e,o)),o.push({args:t}),r&&r.fire({event:e,args:t})}once(e,t){let r=(...o)=>{t(...o),this.off(e,r)};this.on(e,r,!1)}};var T={};Te(T,{None:()=>_n,filter:()=>En,once:()=>Se,toPromise:()=>xn});var _n=()=>(console.log("[Jolibox SDK] None Event"),()=>{console.log("[Jolibox SDK] None Event dispose")});function xn(n){return new Promise(e=>Se(n)(e))}function Se(n){return(e,t=null)=>{let r=!1;return n(i=>{if(!r)return r=!0,e.call(t,i)},null)}}function En(n,e){return(r=>{let o,i={onWillAddFirstListener(){o=r(a.fire,a)}},a=new p(i);return a.event})((r,o=null)=>n(i=>e(i)&&r.call(o,i),null))}var le=Symbol.for("Jolibox.hostEmitter"),hn=()=>{let n=new R;return globalThis[le]||(globalThis[le]={on:n.on.bind(n),off:n.off.bind(n),emit:n.emit.bind(n),once:n.once.bind(n)}),globalThis[le]},Rn=hn();function ce(n,e){let t=Math.min(n.length,e.length);for(let r=0;r<t;r++)ke(n[r],e[r])}function ke(n,e){if(k(e)){if(typeof n!==e)throw new Error(`argument does not match constraint: typeof ${e}`)}else if(U(e)){try{if(n instanceof e)return}catch(t){}if(!M(n)&&n.constructor===e||e.length===1&&e.call(void 0,n)===!0)return;throw new Error("[Jolibox SDK]argument does not match one of these constraints: arg instanceof constraint, arg.constructor === constraint, nor constraint(arg) === true")}}var g=class{constructor(){this._commands=new Map;this._onDidRegisterCommand=new p;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 a of e.metadata.args)o.push(a.constraint);let i=e.handler;e.handler=function(...a){return ce(a,o),i(...a)}}let{id:t}=e;this._commands.get(t)&&console.info(`[Jolibox SDK] duplicated command is registered ${t}`),this._commands.set(t,e),this._onDidRegisterCommand.fire(t)}getCommand(e){return this._commands.get(e)}getCommands(){let e=new Map;for(let t of this._commands.keys()){let r=this.getCommand(t);r&&e.set(t,r)}return e}};g=P([A],g);var v=class{constructor(){this._onWillExecuteCommand=new p;this.onWillExecuteCommand=this._onWillExecuteCommand.event;this._onDidExecuteCommand=new p;this.onDidExecuteCommand=this._onDidExecuteCommand.event;this.registry=new g;this._starActivation=null}_activateStar(){return this._starActivation||(this._starActivation=j(3e4)),this._starActivation}executeCommand(e,...t){return S(this,null,function*(){return this.registry.getCommand(e)?this._tryExecuteCommand(e,t):(yield Promise.all([Promise.race([this._activateStar(),T.toPromise(T.filter(this.registry.onDidRegisterCommand,o=>o===e))])]),this._tryExecuteCommand(e,t))})}executeCommandThowErr(e,...t){if(!!!this.registry.getCommand(e))throw new Error(`command '${e}' not found`);let o=this.registry.getCommand(e);this._onWillExecuteCommand.fire({commandId:e,args:t});let i=this.invokeFunction(o.handler,...t);return this._onDidExecuteCommand.fire({commandId:e,args:t}),i}_tryExecuteCommand(e,t){let r=this.registry.getCommand(e);if(!r)return Promise.reject(new Error(`command '${e}' not found`));try{this._onWillExecuteCommand.fire({commandId:e,args:t});let o=this.invokeFunction(r.handler,...t);return this._onDidExecuteCommand.fire({commandId:e,args:t}),Promise.resolve(o)}catch(o){return Promise.reject(o)}}invokeFunction(e,...t){let r=!1;try{return e(...t)}finally{r=!0}}};v=P([A],v);var Me=Symbol.for("Jolibox.commands");function vn(){return typeof globalThis!="undefined"?globalThis[Me]:void 0}function bn(n){typeof globalThis!="undefined"&&(globalThis[Me]=n)}function In(){let n=vn();if(n)return n;let e=new g,t=new v,r={registerCommand(o,i,a){e.registerCommand({id:o,handler:i,metadata:a})},executeCommand(o,...i){return t.executeCommand(o,...i)},excuteCommandSync(o,...i){return t.executeCommandThowErr(o,...i)}};return bn(r),r}
1
+ "use strict";var I=Object.defineProperty,Fe=Object.defineProperties,Ee=Object.getOwnPropertyDescriptor,Ve=Object.getOwnPropertyDescriptors,je=Object.getOwnPropertyNames,ge=Object.getOwnPropertySymbols;var Te=Object.prototype.hasOwnProperty,He=Object.prototype.propertyIsEnumerable;var ye=(n,e,t)=>e in n?I(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,_=(n,e)=>{for(var t in e||(e={}))Te.call(e,t)&&ye(n,t,e[t]);if(ge)for(var t of ge(e))He.call(e,t)&&ye(n,t,e[t]);return n},P=(n,e)=>Fe(n,Ve(e));var _e=(n,e)=>{for(var t in e)I(n,t,{get:e[t],enumerable:!0})},Ke=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of je(e))!Te.call(n,o)&&o!==t&&I(n,o,{get:()=>e[o],enumerable:!(r=Ee(e,o))||r.enumerable});return n};var Je=n=>Ke(I({},"__esModule",{value:!0}),n),L=(n,e,t,r)=>{for(var o=r>1?void 0:r?Ee(e,t):e,i=n.length-1,a;i>=0;i--)(a=n[i])&&(o=(r?a(e,t,o):a(o))||o);return r&&o&&I(e,t,o),o};var S=(n,e,t)=>new Promise((r,o)=>{var i=s=>{try{l(t.next(s))}catch(m){o(m)}},a=s=>{try{l(t.throw(s))}catch(m){o(m)}},l=s=>s.done?r(s.value):Promise.resolve(s.value).then(i,a);l((t=t.apply(n,e)).next())});var Cn={};_e(Cn,{ADVERTISING_ID:()=>Pe,APIError:()=>re,BaseError:()=>x,DEVICE_ID:()=>Oe,Deferred:()=>V,EPlatform:()=>we,EProject:()=>Ae,EventEmitter:()=>R,EventType:()=>Ie,EventUtils:()=>E,InternalApplyNativeError:()=>q,InternalBufferError:()=>ee,InternalContextError:()=>ne,InternalError:()=>u,InternalGlobalJSError:()=>te,InternalInvokeMethodError:()=>X,InternalInvokeNativeError:()=>Q,InternalJSCoreNotFoundError:()=>Z,InternalJSModuleEvalError:()=>W,InternalJSModuleFetchError:()=>B,InternalMetricReportError:()=>oe,InternalPaymentError:()=>Y,InternalReporterError:()=>ie,InternalSchemaParseError:()=>$,LoadScriptCode:()=>ve,Singleton:()=>A,UserCustomError:()=>w,UserError:()=>f,UserFetchError:()=>J,UserFunctionEvalError:()=>z,UserGlobalError:()=>K,UserPaymentError:()=>G,UserValidateError:()=>H,canIUseConfig:()=>ln,compareVersion:()=>mn,createCommands:()=>wn,createRunTaskQueue:()=>Be,debounce:()=>on,get:()=>cn,getAdvertisingId:()=>Se,getDeviceId:()=>Le,getOriginalLocalStorage:()=>le,getPlatform:()=>Ne,getStorage:()=>ce,getUtmSource:()=>ke,hostEmitter:()=>bn,isArray:()=>Ye,isBoolean:()=>Ze,isDefined:()=>en,isFunction:()=>U,isIterable:()=>Xe,isNative:()=>Ce,isNumber:()=>qe,isObject:()=>xe,isPromiseLike:()=>nn,isString:()=>k,isStringArray:()=>We,isTypedArray:()=>Qe,isUndefined:()=>he,isUndefinedOrNull:()=>M,isValidUUIDV4:()=>yn,logger:()=>se,mergeArray:()=>rn,mergeWith:()=>tn,microTask:()=>$e,platform:()=>N,promisifyAPI:()=>ze,serializeEventPackage:()=>gn,sleep:()=>Ge,timeout:()=>j,uuidv4:()=>de,validateConstraint:()=>Ue,validateConstraints:()=>ue,wrapUserFunction:()=>an,xUserAgent:()=>Tn});module.exports=Je(Cn);if(typeof window!="undefined"&&!window.AbortController){let n=function(){this.signal=new e};n.prototype.abort=function(){this.signal._aborted=!0,typeof this.signal.onabort=="function"&&this.signal.onabort(new Event("abort"));let t=new Event("abort");this.signal.dispatchEvent(t)};let e=function(){this._aborted=!1,this.aborted=!1,this.onabort=null,this._eventListeners={}};Object.defineProperty(e.prototype,"aborted",{get:function(){return this._aborted}}),e.prototype.addEventListener=function(t,r){this._eventListeners[t]||(this._eventListeners[t]=[]),this._eventListeners[t].push(r)},e.prototype.removeEventListener=function(t,r){if(!this._eventListeners[t])return;let o=this._eventListeners[t].indexOf(r);o!==-1&&this._eventListeners[t].splice(o,1)},e.prototype.dispatchEvent=function(t){if(this._eventListeners[t.type])for(let r of this._eventListeners[t.type])r.call(this,t)},window.AbortController=n,window.AbortSignal=e}function j(n){return new Promise(e=>{setTimeout(()=>{e()},n)})}function Ge(n){return new Promise(e=>setTimeout(e,n))}function ze(n){return e=>new Promise((t,r)=>{n(P(_({},e),{success:t,fail(o){let i=new Error(o.errMsg);r(i)}}))})}function $e(n){if(n)Promise.resolve().then(n);else return Promise.resolve()}var V=class{constructor(){this.state="pending";this.promise=new Promise((e,t)=>{this.resolve=r=>{this.state==="pending"&&(this.state="fulfilled",e(r))},this.reject=r=>{this.state==="pending"&&(this.state="rejected",t(r))}})}};function Be(){let n=[],e=!1,t=()=>S(this,null,function*(){let r=n.shift();if(r){e=!0;try{yield r()}finally{e=!1,t()}}});return r=>{n.push(r),e||t()}}function k(n){return typeof n=="string"}function We(n){return Array.isArray(n)&&n.every(e=>k(e))}function xe(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)&&!(n instanceof RegExp)&&!(n instanceof Date)}function Qe(n){let e=Object.getPrototypeOf(Uint8Array);return typeof n=="object"&&n instanceof e}function Ye(n){return typeof n=="object"&&Array.isArray(n)}function qe(n){return typeof n=="number"&&!isNaN(n)}function Xe(n){return!!n&&typeof n[Symbol.iterator]=="function"}function Ze(n){return n===!0||n===!1}function he(n){return typeof n=="undefined"}function en(n){return!M(n)}function M(n){return he(n)||n===null}function U(n){return typeof n=="function"}function nn(n){return xe(n)&&U(n.then)}function A(n){let e=n,t=null,r=function(...o){return t||(t=new e(...o)),t};return r.prototype=e.prototype,r}function tn(n,e,t){if(typeof t!="function")throw new Error("[Jolibox SDK]Customizer must be a function");function r(o,i){for(let a in i)if(Object.prototype.hasOwnProperty.call(i,a)){let l=o[a],s=i[a],m=t(l,s,a,o,i);m!==void 0?o[a]=m:Re(s)&&Re(l)?o[a]=r(_({},l),s):Array.isArray(s)&&Array.isArray(l)?o[a]=[...l,...s]:o[a]=s}return o}return r(n,e)}function Re(n){return n&&typeof n=="object"&&n.constructor===Object}function rn(n,e){if(Array.isArray(n))return n.concat(e)}function on(n,e,t={}){let r=null,o,i,a,{leading:l=!1,trailing:s=!0}=t,m=()=>(a=n.apply(i,o),o=void 0,i=void 0,a),d=function(...T){o=T,i=this;let b=l&&!r;if(r&&clearTimeout(r),r=setTimeout(()=>{r=null,s&&!b&&m()},e),b)return m()};return d.cancel=()=>{r&&clearTimeout(r),r=null,o=i=void 0},d.flush=()=>{if(r)return clearTimeout(r),r=null,m()},d}var ve=(s=>(s[s.DEVELOPER_FILE_NOT_FOUND=0]="DEVELOPER_FILE_NOT_FOUND",s[s.INTERNAL_IOS_CAN_NOT_FOUND_PKG=1]="INTERNAL_IOS_CAN_NOT_FOUND_PKG",s[s.USER_IOS_LOAD_TIMEOUT=2]="USER_IOS_LOAD_TIMEOUT",s[s.INTERNAL_IOS_PKG_LOAD_ERROR=3]="INTERNAL_IOS_PKG_LOAD_ERROR",s[s.INTERNAL_IOS_PKG_PARSE_FAIL=4]="INTERNAL_IOS_PKG_PARSE_FAIL",s[s.USER_IOS_GET_EMPTY_DATA=5]="USER_IOS_GET_EMPTY_DATA",s[s.USER_ANDROID_GET_PKG_FAIL=6]="USER_ANDROID_GET_PKG_FAIL",s[s.DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE=7]="DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE",s))(ve||{}),x=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}},u=class extends x{constructor(){super(...arguments);this.kind="INTERNAL_ERROR"}},f=class extends x{constructor(){super(...arguments);this.kind="USER_ERROR"}},H=class extends f{constructor(){super(...arguments);this.name="USER_VALIDATE_ERROR"}},K=class extends f{constructor(){super(...arguments);this.name="USER_GLOBAL_ERROR";this.priority="P1"}},w=class extends f{constructor(t,r,o){super(t);this.message=t;this.errNo=r;this.name="USER_CUSTOM_ERROR";this.errMsg=t,o&&(this.extra=Object.assign({},this.extra,o))}},J=class extends f{constructor(t,r,o){super(t);this.message=t;this.errNo=r;this.name="USER_FETCH_ERROR";this.errMsg=t,o&&(this.extra=Object.assign({},this.extra,o))}},G=class extends f{constructor(t,r,o){super(t);this.message=t;this.errNo=r;this.name="USER_PAYMENT_ERROR";this.errMsg=t,o&&(this.extra=Object.assign({},this.extra,o))}},z=class extends f{constructor(){super(...arguments);this.name="USER_CALLBACK_ERROR"}},$=class extends u{constructor(){super(...arguments);this.name="INTERNAL_SCHEMA_PARSE_ERROR";this.priority="P0"}},B=class extends u{constructor(){super(...arguments);this.name="INTERNAL_JS_MODULE_FETCH_ERROR";this.priority="P0"}},W=class extends u{constructor(){super(...arguments);this.name="INTERNAL_JS_MODULE_EVAL_ERROR";this.priority="P0"}},Q=class extends u{constructor(){super(...arguments);this.name="INTERNAL_INVOKE_NATIVE_ERROR"}},Y=class extends u{constructor(t,r,o){super(t);this.message=t;this.errNo=r;this.name="INTERNAL_PAYMENT_ERROR";this.priority="P0";this.errMsg=t,o&&(this.extra=Object.assign({},this.extra,o))}},q=class extends u{constructor(t,r,o,i){super(t);this.errNo=r;this.name="INTERNAL_APPLY_NATIVE_ERROR";this.errorType=o,this.errorCode=i}},X=class extends u{constructor(){super(...arguments);this.name="INTERNAL_INVOKE_METHOD_ERROR"}},Z=class extends u{constructor(){super(...arguments);this.name="INTERNAL_JSCORE_ERROR";this.priority="P0"}},ee=class extends u{constructor(){super(...arguments);this.name="INTERNAL_BUFFER_ERROR"}},ne=class extends u{constructor(t,r){super(t);this.message=t;this.name="INTERNAL_CONTEXT_ERROR";this.property=r}},te=class extends u{constructor(){super(...arguments);this.name="INTERNAL_GLOBAL_JS_ERROR";this.priority="P1"}},re=class extends x{constructor(t,r,o,i,a){super(t);this.message=t;this.code=r;this.kind="API_ERROR";this.name="API_ERROR";o&&(this.errorType=o),i!==void 0&&(this.stack=i),a&&(this.priority=a)}toJSON(){return{message:this.message,stack:this.stack,name:this.name,code:this.code,errorType:this.errorType}}},oe=class extends u{constructor(){super(...arguments);this.name="INTERNAL_METRIC_REPORT_ERROR"}},ie=class extends u{constructor(){super(...arguments);this.name="INTERNAL_REPORTER_ERROR"}};function sn(n,e){return(...t)=>e(n,...t)}function an(n){return e=>sn(e,function(t,...r){if(typeof t=="function")try{return t.apply(this,r)}catch(o){n(new w(`${o}`))}})}function C(n){return(...e)=>{var r,o;((o=(r=globalThis.VConsole)==null?void 0:r[n])!=null?o:globalThis.console[n])(...e)}}var se={log:C("log"),warn:C("warn"),info:C("info"),error:C("error"),debug:C("debug")};Object.assign(globalThis,{logger:se});var ae=Symbol.for("Jolibox.canIUseMap"),dn={};globalThis[ae]||(globalThis[ae]=dn);var ln={get config(){return globalThis[ae]}};function cn(n,e,t){let r=n;for(let o of e)if(r&&typeof r=="object")r=r[o];else return t;return r===void 0?t:r}function mn(n,e,t){let r=0;if(n!==e){let o=n.split("."),i=e.split("."),a=Math.max(o.length,i.length);for(let l=0;l<a;l++){let s=parseInt(o[l],10)||0,m=parseInt(i[l],10)||0;if(s>m){r=1;break}else if(s<m){r=-1;break}}}if(!t)return r;switch(t){case">":return r>0;case"<":return r<0;case"=":return r===0;case">=":return r>=0;case"<=":return r<=0;default:return!1}}var Ie=(r=>(r[r.System=1e3]="System",r[r.ErrorTrace=1001]="ErrorTrace",r[r.UserDefined=1002]="UserDefined",r))(Ie||{}),Ae=(i=>(i.MiniGame="mini-game",i.MiniDrama="mini-drama",i.App="app",i.WebSDK="web-sdk",i.AppSDK="app-sdk",i))(Ae||{}),we=(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))(we||{}),be=["name","params"],un=["name","type","location","target","extra","timestamp","userId"],pn=["platform","os","appVersion","appId","model","brand","uuid","jsSdkVersion","extra"];function D(n,e){return e.map(t=>{if(t==="params"&&n[t]){let r=n[t];return Object.keys(r).reduce((o,i)=>(o[i]=String(r[i]),o),{})}return n[t]})}function fn(n){let e=n.location?D(n.location,be):null,t=n.target?D(n.target,be):null;return D(P(_({},n),{location:e,target:t}),un)}function gn(n){let e=n.events.map(r=>fn(r)),t=D(n.device,pn);return[n.protocolVersion,e,t,n.project]}var de=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,n=>{let e=Math.random()*16|0;return(n==="x"?e:e&3|8).toString(16)}),yn=n=>/^[\da-f]{8}-[\da-f]{4}-4[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i.test(n);function le(){try{if(window.__joliboxLocalStorage__)return window.__joliboxLocalStorage__;let n=Object.getOwnPropertyDescriptor(window,"localStorage");if(n&&n.get){let r=n.get.call(window);return window.__joliboxLocalStorage__=r,r}if(n=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(window),"localStorage"),n&&n.get)return n.get.call(window);let e=Window.prototype,t=Object.getOwnPropertyDescriptor(e,"localStorage");if(t&&t.get){let r=t.get.call(window);return window.__joliboxLocalStorage__=r,r}return localStorage}catch(n){return console.warn("Failed to get original localStorage, fallback to default implementation",n),localStorage}}le();var Ce=()=>!!(navigator.userAgent||"").includes("JoliboxPlatformSDK"),N={isiOS:navigator.userAgent.includes("iPhone")||navigator.userAgent.includes("iPod")||navigator.userAgent.includes("iPad")||navigator.userAgent.includes("iPhone OS"),iosVersion:()=>{let n=navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/);return[parseInt(n[1],10),parseInt(n[2],10),parseInt(n[3]||"0",10)]},isAndroid:navigator.userAgent.includes("Android"),isMac:navigator.userAgent.includes("Mac"),isFacebook:navigator.userAgent.includes("FB_IAB"),isPC:!navigator.userAgent.includes("iPhone")&&!navigator.userAgent.includes("Android")},Ne=()=>N.isiOS?"iOS":N.isAndroid?"Android":N.isMac?"Mac":N.isFacebook?"Facebook":"PC",Oe="device_id",Pe="advertising_id",ce=n=>(window.__joliboxLocalStorage__.getItem(n)||window.__joliboxLocalStorage__.setItem(n,de()),window.__joliboxLocalStorage__.getItem(n)),Le=()=>{let e=new URLSearchParams(window.location.search).get("deviceId");return e||ce(Oe)},Se=()=>{let e=new URLSearchParams(window.location.search).get("advertisingId");return e||ce(Pe)},En=n=>n.charAt(0).toUpperCase()+n.slice(1),ke=()=>{var e;let n=new URLSearchParams(window.location.search);return En((e=n.get("utm_source"))!=null?e:"")||"JoliboxSDK"},Tn=n=>{if(Ce())return window.navigator.userAgent;let e="JoliboxWebSDK",t=Ne(),r=navigator.language,o=Le(),i=Se();return`${e} (${ke()}${t}; UnknownModel; UnknownSystemVersion; ${r}) uuid/${o} adid/${i} version/${n||""}`};var h=class h{constructor(e){this.element=e,this.next=h.Undefined,this.prev=h.Undefined}};h.Undefined=new h(void 0);var c=h,F=class{constructor(){this._first=c.Undefined;this._last=c.Undefined;this._size=0}get size(){return this._size}isEmpty(){return this._first===c.Undefined}clear(){let e=this._first;for(;e!==c.Undefined;){let t=e.next;e.prev=c.Undefined,e.next=c.Undefined,e=t}this._first=c.Undefined,this._last=c.Undefined,this._size=0}unshift(e){return this._insert(e,!1)}push(e){return this._insert(e,!0)}_insert(e,t){let r=new c(e);if(this._first===c.Undefined)this._first=r,this._last=r;else if(t){let i=this._last;this._last=r,r.prev=i,i.next=r}else{let i=this._first;this._first=r,r.next=i,i.prev=r}this._size+=1;let o=!1;return()=>{o||(o=!0,this._remove(r))}}shift(){if(this._first!==c.Undefined){let e=this._first.element;return this._remove(this._first),e}}pop(){if(this._last!==c.Undefined){let e=this._last.element;return this._remove(this._last),e}}_remove(e){if(e.prev!==c.Undefined&&e.next!==c.Undefined){let t=e.prev;t.next=e.next,e.next.prev=t}else e.prev===c.Undefined&&e.next===c.Undefined?(this._first=c.Undefined,this._last=c.Undefined):e.next===c.Undefined?(this._last=this._last.prev,this._last.next=c.Undefined):e.prev===c.Undefined&&(this._first=this._first.next,this._first.prev=c.Undefined);this._size-=1}*[Symbol.iterator](){let e=this._first;for(;e!==c.Undefined;)yield e.element,e=e.next}};var _n=0,y=class{constructor(e){this.value=e;this.id=_n++}},p=class{constructor(e){this.options=e;this._size=0}dispose(e){var t,r;this._disposed||(this._disposed=!0,this._listeners&&(e?(this._listeners instanceof y&&(this._listeners=[this._listeners]),this._listeners=this._listeners.filter(o=>(o==null?void 0:o.value)===e)):(this._listeners=void 0,this._size=0)),(r=(t=this.options)==null?void 0:t.onDidRemoveLastListener)==null||r.call(t))}get event(){var e;return(e=this._event)!=null||(this._event=(t,r)=>{var i,a,l,s,m,d;if(this._disposed)return()=>{console.info("[Jolibox SDK] Emitter is _disposed")};r&&(t=t.bind(r));let o=new y(t);return this._listeners?this._listeners instanceof y?this._listeners=[this._listeners,o]:this._listeners.push(o):((a=(i=this.options)==null?void 0:i.onWillAddFirstListener)==null||a.call(i,this),this._listeners=o,(s=(l=this.options)==null?void 0:l.onDidFirstListener)==null||s.call(l,this)),(d=(m=this.options)==null?void 0:m.onDidAddListener)==null||d.call(m,this),this._size++,()=>{var T,b,O,pe;if(!this._disposed){if(this._listeners instanceof y)this._listeners.id===o.id&&(this._listeners=void 0,this._size=0,(b=(T=this.options)==null?void 0:T.onDidRemoveLastListener)==null||b.call(T));else if(this._listeners){let fe=this._listeners.indexOf(o);fe>=0&&(this._listeners.splice(fe,1),this._size--,this._size===0&&((pe=(O=this.options)==null?void 0:O.onDidRemoveLastListener)==null||pe.call(O)))}}}}),this._event}_deliver(e,t){var o;if(!e)return;let r=((o=this.options)==null?void 0:o.onListenerError)||Error.constructor;if(!r){e.value(t);return}try{e.value(t)}catch(i){r(i)}}fire(e){this._listeners&&(this._listeners instanceof y?this._deliver(this._listeners,e):this._listeners.forEach(t=>this._deliver(t,e)))}hasListeners(){return this._size>0}},R=class{constructor(){this.listeners=new Map;this.listerHandlerMap=new WeakMap;this.cachedEventQueue=new Map}on(e,t,r=!0){var s;let o=(s=this.listeners.get(e))!=null?s:new p,i=m=>t(...m.args),a=o.event(i);this.listerHandlerMap.set(t,{handler:i,dispose:a}),this.listeners.set(e,o);let l=this.cachedEventQueue.get(e);if(l&&r)for(let m of l)t(...m.args)}flushCachedEvent(e){e?this.cachedEventQueue.delete(e):this.cachedEventQueue.clear()}off(e,t){let r=this.listerHandlerMap.get(t);r&&(r.dispose(),this.listerHandlerMap.delete(t))}emit(e,...t){let r=this.listeners.get(e),o=this.cachedEventQueue.get(e);o||(o=new F,this.cachedEventQueue.set(e,o)),o.push({args:t}),r&&r.fire({event:e,args:t})}once(e,t){let r=(...o)=>{t(...o),this.off(e,r)};this.on(e,r,!1)}};var E={};_e(E,{None:()=>xn,filter:()=>Rn,once:()=>Me,toPromise:()=>hn});var xn=()=>(console.log("[Jolibox SDK] None Event"),()=>{console.log("[Jolibox SDK] None Event dispose")});function hn(n){return new Promise(e=>Me(n)(e))}function Me(n){return(e,t=null)=>{let r=!1;return n(i=>{if(!r)return r=!0,e.call(t,i)},null)}}function Rn(n,e){return(r=>{let o,i={onWillAddFirstListener(){o=r(a.fire,a)}},a=new p(i);return a.event})((r,o=null)=>n(i=>e(i)&&r.call(o,i),null))}var me=Symbol.for("Jolibox.hostEmitter"),vn=()=>{let n=new R;return globalThis[me]||(globalThis[me]={on:n.on.bind(n),off:n.off.bind(n),emit:n.emit.bind(n),once:n.once.bind(n)}),globalThis[me]},bn=vn();function ue(n,e){let t=Math.min(n.length,e.length);for(let r=0;r<t;r++)Ue(n[r],e[r])}function Ue(n,e){if(k(e)){if(typeof n!==e)throw new Error(`argument does not match constraint: typeof ${e}`)}else if(U(e)){try{if(n instanceof e)return}catch(t){}if(!M(n)&&n.constructor===e||e.length===1&&e.call(void 0,n)===!0)return;throw new Error("[Jolibox SDK]argument does not match one of these constraints: arg instanceof constraint, arg.constructor === constraint, nor constraint(arg) === true")}}var g=class{constructor(){this._commands=new Map;this._onDidRegisterCommand=new p;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 a of e.metadata.args)o.push(a.constraint);let i=e.handler;e.handler=function(...a){return ue(a,o),i(...a)}}let{id:t}=e;this._commands.get(t)&&console.info(`[Jolibox SDK] duplicated command is registered ${t}`),this._commands.set(t,e),this._onDidRegisterCommand.fire(t)}getCommand(e){return this._commands.get(e)}getCommands(){let e=new Map;for(let t of this._commands.keys()){let r=this.getCommand(t);r&&e.set(t,r)}return e}};g=L([A],g);var v=class{constructor(){this._onWillExecuteCommand=new p;this.onWillExecuteCommand=this._onWillExecuteCommand.event;this._onDidExecuteCommand=new p;this.onDidExecuteCommand=this._onDidExecuteCommand.event;this.registry=new g;this._starActivation=null}_activateStar(){return this._starActivation||(this._starActivation=j(3e4)),this._starActivation}executeCommand(e,...t){return S(this,null,function*(){return this.registry.getCommand(e)?this._tryExecuteCommand(e,t):(yield Promise.all([Promise.race([this._activateStar(),E.toPromise(E.filter(this.registry.onDidRegisterCommand,o=>o===e))])]),this._tryExecuteCommand(e,t))})}executeCommandThowErr(e,...t){if(!!!this.registry.getCommand(e))throw new Error(`command '${e}' not found`);let o=this.registry.getCommand(e);this._onWillExecuteCommand.fire({commandId:e,args:t});let i=this.invokeFunction(o.handler,...t);return this._onDidExecuteCommand.fire({commandId:e,args:t}),i}_tryExecuteCommand(e,t){let r=this.registry.getCommand(e);if(!r)return Promise.reject(new Error(`command '${e}' not found`));try{this._onWillExecuteCommand.fire({commandId:e,args:t});let o=this.invokeFunction(r.handler,...t);return this._onDidExecuteCommand.fire({commandId:e,args:t}),Promise.resolve(o)}catch(o){return Promise.reject(o)}}invokeFunction(e,...t){let r=!1;try{return e(...t)}finally{r=!0}}};v=L([A],v);var De=Symbol.for("Jolibox.commands");function In(){return typeof globalThis!="undefined"?globalThis[De]:void 0}function An(n){typeof globalThis!="undefined"&&(globalThis[De]=n)}function wn(){let n=In();if(n)return n;let e=new g,t=new v,r={registerCommand(o,i,a){e.registerCommand({id:o,handler:i,metadata:a})},executeCommand(o,...i){return t.executeCommand(o,...i)},excuteCommandSync(o,...i){return t.executeCommandThowErr(o,...i)}};return An(r),r}
package/dist/index.es.js CHANGED
@@ -1 +1 @@
1
- var M=Object.defineProperty,xe=Object.defineProperties,Ee=Object.getOwnPropertyDescriptor,he=Object.getOwnPropertyDescriptors;var J=Object.getOwnPropertySymbols;var Re=Object.prototype.hasOwnProperty,ve=Object.prototype.propertyIsEnumerable;var G=(n,e,t)=>e in n?M(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,_=(n,e)=>{for(var t in e||(e={}))Re.call(e,t)&&G(n,t,e[t]);if(J)for(var t of J(e))ve.call(e,t)&&G(n,t,e[t]);return n},C=(n,e)=>xe(n,he(e));var be=(n,e)=>{for(var t in e)M(n,t,{get:e[t],enumerable:!0})};var w=(n,e,t,r)=>{for(var o=r>1?void 0:r?Ee(e,t):e,i=n.length-1,a;i>=0;i--)(a=n[i])&&(o=(r?a(e,t,o):a(o))||o);return r&&o&&M(e,t,o),o};var N=(n,e,t)=>new Promise((r,o)=>{var i=s=>{try{l(t.next(s))}catch(m){o(m)}},a=s=>{try{l(t.throw(s))}catch(m){o(m)}},l=s=>s.done?r(s.value):Promise.resolve(s.value).then(i,a);l((t=t.apply(n,e)).next())});if(typeof window!="undefined"&&!window.AbortController){let n=function(){this.signal=new e};n.prototype.abort=function(){this.signal._aborted=!0,typeof this.signal.onabort=="function"&&this.signal.onabort(new Event("abort"));let t=new Event("abort");this.signal.dispatchEvent(t)};let e=function(){this._aborted=!1,this.aborted=!1,this.onabort=null,this._eventListeners={}};Object.defineProperty(e.prototype,"aborted",{get:function(){return this._aborted}}),e.prototype.addEventListener=function(t,r){this._eventListeners[t]||(this._eventListeners[t]=[]),this._eventListeners[t].push(r)},e.prototype.removeEventListener=function(t,r){if(!this._eventListeners[t])return;let o=this._eventListeners[t].indexOf(r);o!==-1&&this._eventListeners[t].splice(o,1)},e.prototype.dispatchEvent=function(t){if(this._eventListeners[t.type])for(let r of this._eventListeners[t.type])r.call(this,t)},window.AbortController=n,window.AbortSignal=e}function $(n){return new Promise(e=>{setTimeout(()=>{e()},n)})}function Ze(n){return new Promise(e=>setTimeout(e,n))}function en(n){return e=>new Promise((t,r)=>{n(C(_({},e),{success:t,fail(o){let i=new Error(o.errMsg);r(i)}}))})}function nn(n){if(n)Promise.resolve().then(n);else return Promise.resolve()}var z=class{constructor(){this.state="pending";this.promise=new Promise((e,t)=>{this.resolve=r=>{this.state==="pending"&&(this.state="fulfilled",e(r))},this.reject=r=>{this.state==="pending"&&(this.state="rejected",t(r))}})}};function tn(){let n=[],e=!1,t=()=>N(this,null,function*(){let r=n.shift();if(r){e=!0;try{yield r()}finally{e=!1,t()}}});return r=>{n.push(r),e||t()}}function U(n){return typeof n=="string"}function an(n){return Array.isArray(n)&&n.every(e=>U(e))}function Ie(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)&&!(n instanceof RegExp)&&!(n instanceof Date)}function dn(n){let e=Object.getPrototypeOf(Uint8Array);return typeof n=="object"&&n instanceof e}function ln(n){return typeof n=="object"&&Array.isArray(n)}function cn(n){return typeof n=="number"&&!isNaN(n)}function mn(n){return!!n&&typeof n[Symbol.iterator]=="function"}function un(n){return n===!0||n===!1}function Ae(n){return typeof n=="undefined"}function pn(n){return!D(n)}function D(n){return Ae(n)||n===null}function F(n){return typeof n=="function"}function fn(n){return Ie(n)&&F(n.then)}function O(n){let e=n,t=null,r=function(...o){return t||(t=new e(...o)),t};return r.prototype=e.prototype,r}function xn(n,e,t){if(typeof t!="function")throw new Error("[Jolibox SDK]Customizer must be a function");function r(o,i){for(let a in i)if(Object.prototype.hasOwnProperty.call(i,a)){let l=o[a],s=i[a],m=t(l,s,a,o,i);m!==void 0?o[a]=m:B(s)&&B(l)?o[a]=r(_({},l),s):Array.isArray(s)&&Array.isArray(l)?o[a]=[...l,...s]:o[a]=s}return o}return r(n,e)}function B(n){return n&&typeof n=="object"&&n.constructor===Object}function En(n,e){if(Array.isArray(n))return n.concat(e)}function bn(n,e,t={}){let r=null,o,i,a,{leading:l=!1,trailing:s=!0}=t,m=()=>(a=n.apply(i,o),o=void 0,i=void 0,a),d=function(...T){o=T,i=this;let R=l&&!r;if(r&&clearTimeout(r),r=setTimeout(()=>{r=null,s&&!R&&m()},e),R)return m()};return d.cancel=()=>{r&&clearTimeout(r),r=null,o=i=void 0},d.flush=()=>{if(r)return clearTimeout(r),r=null,m()},d}var Ce=(s=>(s[s.DEVELOPER_FILE_NOT_FOUND=0]="DEVELOPER_FILE_NOT_FOUND",s[s.INTERNAL_IOS_CAN_NOT_FOUND_PKG=1]="INTERNAL_IOS_CAN_NOT_FOUND_PKG",s[s.USER_IOS_LOAD_TIMEOUT=2]="USER_IOS_LOAD_TIMEOUT",s[s.INTERNAL_IOS_PKG_LOAD_ERROR=3]="INTERNAL_IOS_PKG_LOAD_ERROR",s[s.INTERNAL_IOS_PKG_PARSE_FAIL=4]="INTERNAL_IOS_PKG_PARSE_FAIL",s[s.USER_IOS_GET_EMPTY_DATA=5]="USER_IOS_GET_EMPTY_DATA",s[s.USER_ANDROID_GET_PKG_FAIL=6]="USER_ANDROID_GET_PKG_FAIL",s[s.DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE=7]="DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE",s))(Ce||{}),v=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}},u=class extends v{constructor(){super(...arguments);this.kind="INTERNAL_ERROR"}},g=class extends v{constructor(){super(...arguments);this.kind="USER_ERROR"}},W=class extends g{constructor(){super(...arguments);this.name="USER_VALIDATE_ERROR"}},Q=class extends g{constructor(){super(...arguments);this.name="USER_GLOBAL_ERROR";this.priority="P1"}},L=class extends g{constructor(t,r,o){super(t);this.message=t;this.errNo=r;this.name="USER_CUSTOM_ERROR";this.errMsg=t,o&&(this.extra=Object.assign({},this.extra,o))}},q=class extends g{constructor(t,r,o){super(t);this.message=t;this.errNo=r;this.name="USER_FETCH_ERROR";this.errMsg=t,o&&(this.extra=Object.assign({},this.extra,o))}},X=class extends g{constructor(){super(...arguments);this.name="USER_CALLBACK_ERROR"}},Y=class extends u{constructor(){super(...arguments);this.name="INTERNAL_SCHEMA_PARSE_ERROR";this.priority="P0"}},Z=class extends u{constructor(){super(...arguments);this.name="INTERNAL_JS_MODULE_FETCH_ERROR";this.priority="P0"}},ee=class extends u{constructor(){super(...arguments);this.name="INTERNAL_JS_MODULE_EVAL_ERROR";this.priority="P0"}},ne=class extends u{constructor(){super(...arguments);this.name="INTERNAL_INVOKE_NATIVE_ERROR"}},te=class extends u{constructor(t,r,o,i){super(t);this.errNo=r;this.name="INTERNAL_APPLY_NATIVE_ERROR";this.errorType=o,this.errorCode=i}},re=class extends u{constructor(){super(...arguments);this.name="INTERNAL_INVOKE_METHOD_ERROR"}},oe=class extends u{constructor(){super(...arguments);this.name="INTERNAL_JSCORE_ERROR";this.priority="P0"}},ie=class extends u{constructor(){super(...arguments);this.name="INTERNAL_BUFFER_ERROR"}},se=class extends u{constructor(t,r){super(t);this.message=t;this.name="INTERNAL_CONTEXT_ERROR";this.property=r}},ae=class extends u{constructor(){super(...arguments);this.name="INTERNAL_GLOBAL_JS_ERROR";this.priority="P1"}},de=class extends v{constructor(t,r,o,i,a){super(t);this.message=t;this.code=r;this.kind="API_ERROR";this.name="API_ERROR";o&&(this.errorType=o),i!==void 0&&(this.stack=i),a&&(this.priority=a)}toJSON(){return{message:this.message,stack:this.stack,name:this.name,code:this.code,errorType:this.errorType}}},le=class extends u{constructor(){super(...arguments);this.name="INTERNAL_METRIC_REPORT_ERROR"}},ce=class extends u{constructor(){super(...arguments);this.name="INTERNAL_REPORTER_ERROR"}};function we(n,e){return(...t)=>e(n,...t)}function Ln(n){return e=>we(e,function(t,...r){if(typeof t=="function")try{return t.apply(this,r)}catch(o){n(new L(`${o}`))}})}function b(n){return(...e)=>{var r,o;((o=(r=globalThis.VConsole)==null?void 0:r[n])!=null?o:globalThis.console[n])(...e)}}var me={log:b("log"),warn:b("warn"),info:b("info"),error:b("error"),debug:b("debug")};Object.assign(globalThis,{logger:me});var V=Symbol.for("Jolibox.canIUseMap"),Ne={};globalThis[V]||(globalThis[V]=Ne);var jn={get config(){return globalThis[V]}};function Hn(n,e,t){let r=n;for(let o of e)if(r&&typeof r=="object")r=r[o];else return t;return r===void 0?t:r}function Gn(n,e,t){let r=0;if(n!==e){let o=n.split("."),i=e.split("."),a=Math.max(o.length,i.length);for(let l=0;l<a;l++){let s=parseInt(o[l],10)||0,m=parseInt(i[l],10)||0;if(s>m){r=1;break}else if(s<m){r=-1;break}}}if(!t)return r;switch(t){case">":return r>0;case"<":return r<0;case"=":return r===0;case">=":return r>=0;case"<=":return r<=0;default:return!1}}var Oe=(r=>(r[r.System=1e3]="System",r[r.ErrorTrace=1001]="ErrorTrace",r[r.UserDefined=1002]="UserDefined",r))(Oe||{}),Le=(i=>(i.MiniGame="mini-game",i.MiniDrama="mini-drama",i.App="app",i.WebSDK="web-sdk",i.AppSDK="app-sdk",i))(Le||{}),Pe=(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))(Pe||{}),ue=["name","params"],Se=["name","type","location","target","extra","timestamp","userId"],ke=["platform","os","appVersion","appId","model","brand","uuid","jsSdkVersion","extra"];function P(n,e){return e.map(t=>{if(t==="params"&&n[t]){let r=n[t];return Object.keys(r).reduce((o,i)=>(o[i]=String(r[i]),o),{})}return n[t]})}function Me(n){let e=n.location?P(n.location,ue):null,t=n.target?P(n.target,ue):null;return P(C(_({},n),{location:e,target:t}),Se)}function Bn(n){let e=n.events.map(r=>Me(r)),t=P(n.device,ke);return[n.protocolVersion,e,t,n.project]}var pe=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,n=>{let e=Math.random()*16|0;return(n==="x"?e:e&3|8).toString(16)}),Xn=n=>/^[\da-f]{8}-[\da-f]{4}-4[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i.test(n);function fe(){try{if(window.__joliboxLocalStorage__)return window.__joliboxLocalStorage__;let n=Object.getOwnPropertyDescriptor(window,"localStorage");if(n&&n.get){let r=n.get.call(window);return window.__joliboxLocalStorage__=r,r}if(n=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(window),"localStorage"),n&&n.get)return n.get.call(window);let e=Window.prototype,t=Object.getOwnPropertyDescriptor(e,"localStorage");if(t&&t.get){let r=t.get.call(window);return window.__joliboxLocalStorage__=r,r}return localStorage}catch(n){return console.warn("Failed to get original localStorage, fallback to default implementation",n),localStorage}}fe();var Ue=()=>!!(navigator.userAgent||"").includes("JoliboxPlatformSDK"),S={isiOS:navigator.userAgent.includes("iPhone")||navigator.userAgent.includes("iPod")||navigator.userAgent.includes("iPad")||navigator.userAgent.includes("iPhone OS"),iosVersion:()=>{let n=navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/);return[parseInt(n[1],10),parseInt(n[2],10),parseInt(n[3]||"0",10)]},isAndroid:navigator.userAgent.includes("Android"),isMac:navigator.userAgent.includes("Mac"),isFacebook:navigator.userAgent.includes("FB_IAB"),isPC:!navigator.userAgent.includes("iPhone")&&!navigator.userAgent.includes("Android")},De=()=>S.isiOS?"iOS":S.isAndroid?"Android":S.isMac?"Mac":S.isFacebook?"Facebook":"PC",Fe="device_id",Ve="advertising_id",ge=n=>(window.__joliboxLocalStorage__.getItem(n)||window.__joliboxLocalStorage__.setItem(n,pe()),window.__joliboxLocalStorage__.getItem(n)),je=()=>{let e=new URLSearchParams(window.location.search).get("deviceId");return e||ge(Fe)},He=()=>{let e=new URLSearchParams(window.location.search).get("advertisingId");return e||ge(Ve)},Ke=n=>n.charAt(0).toUpperCase()+n.slice(1),Je=()=>{var e;let n=new URLSearchParams(window.location.search);return Ke((e=n.get("utm_source"))!=null?e:"")||"JoliboxSDK"},ot=n=>{if(Ue())return window.navigator.userAgent;let e="JoliboxWebSDK",t=De(),r=navigator.language,o=je(),i=He();return`${e} (${Je()}${t}; UnknownModel; UnknownSystemVersion; ${r}) uuid/${o} adid/${i} version/${n||""}`};var x=class x{constructor(e){this.element=e,this.next=x.Undefined,this.prev=x.Undefined}};x.Undefined=new x(void 0);var c=x,k=class{constructor(){this._first=c.Undefined;this._last=c.Undefined;this._size=0}get size(){return this._size}isEmpty(){return this._first===c.Undefined}clear(){let e=this._first;for(;e!==c.Undefined;){let t=e.next;e.prev=c.Undefined,e.next=c.Undefined,e=t}this._first=c.Undefined,this._last=c.Undefined,this._size=0}unshift(e){return this._insert(e,!1)}push(e){return this._insert(e,!0)}_insert(e,t){let r=new c(e);if(this._first===c.Undefined)this._first=r,this._last=r;else if(t){let i=this._last;this._last=r,r.prev=i,i.next=r}else{let i=this._first;this._first=r,r.next=i,i.prev=r}this._size+=1;let o=!1;return()=>{o||(o=!0,this._remove(r))}}shift(){if(this._first!==c.Undefined){let e=this._first.element;return this._remove(this._first),e}}pop(){if(this._last!==c.Undefined){let e=this._last.element;return this._remove(this._last),e}}_remove(e){if(e.prev!==c.Undefined&&e.next!==c.Undefined){let t=e.prev;t.next=e.next,e.next.prev=t}else e.prev===c.Undefined&&e.next===c.Undefined?(this._first=c.Undefined,this._last=c.Undefined):e.next===c.Undefined?(this._last=this._last.prev,this._last.next=c.Undefined):e.prev===c.Undefined&&(this._first=this._first.next,this._first.prev=c.Undefined);this._size-=1}*[Symbol.iterator](){let e=this._first;for(;e!==c.Undefined;)yield e.element,e=e.next}};var Ge=0,y=class{constructor(e){this.value=e;this.id=Ge++}},p=class{constructor(e){this.options=e;this._size=0}dispose(e){var t,r;this._disposed||(this._disposed=!0,this._listeners&&(e?(this._listeners instanceof y&&(this._listeners=[this._listeners]),this._listeners=this._listeners.filter(o=>(o==null?void 0:o.value)===e)):(this._listeners=void 0,this._size=0)),(r=(t=this.options)==null?void 0:t.onDidRemoveLastListener)==null||r.call(t))}get event(){var e;return(e=this._event)!=null||(this._event=(t,r)=>{var i,a,l,s,m,d;if(this._disposed)return()=>{console.info("[Jolibox SDK] Emitter is _disposed")};r&&(t=t.bind(r));let o=new y(t);return this._listeners?this._listeners instanceof y?this._listeners=[this._listeners,o]:this._listeners.push(o):((a=(i=this.options)==null?void 0:i.onWillAddFirstListener)==null||a.call(i,this),this._listeners=o,(s=(l=this.options)==null?void 0:l.onDidFirstListener)==null||s.call(l,this)),(d=(m=this.options)==null?void 0:m.onDidAddListener)==null||d.call(m,this),this._size++,()=>{var T,R,A,H;if(!this._disposed){if(this._listeners instanceof y)this._listeners.id===o.id&&(this._listeners=void 0,this._size=0,(R=(T=this.options)==null?void 0:T.onDidRemoveLastListener)==null||R.call(T));else if(this._listeners){let K=this._listeners.indexOf(o);K>=0&&(this._listeners.splice(K,1),this._size--,this._size===0&&((H=(A=this.options)==null?void 0:A.onDidRemoveLastListener)==null||H.call(A)))}}}}),this._event}_deliver(e,t){var o;if(!e)return;let r=((o=this.options)==null?void 0:o.onListenerError)||Error.constructor;if(!r){e.value(t);return}try{e.value(t)}catch(i){r(i)}}fire(e){this._listeners&&(this._listeners instanceof y?this._deliver(this._listeners,e):this._listeners.forEach(t=>this._deliver(t,e)))}hasListeners(){return this._size>0}},I=class{constructor(){this.listeners=new Map;this.listerHandlerMap=new WeakMap;this.cachedEventQueue=new Map}on(e,t,r=!0){var s;let o=(s=this.listeners.get(e))!=null?s:new p,i=m=>t(...m.args),a=o.event(i);this.listerHandlerMap.set(t,{handler:i,dispose:a}),this.listeners.set(e,o);let l=this.cachedEventQueue.get(e);if(l&&r)for(let m of l)t(...m.args)}flushCachedEvent(e){e?this.cachedEventQueue.delete(e):this.cachedEventQueue.clear()}off(e,t){let r=this.listerHandlerMap.get(t);r&&(r.dispose(),this.listerHandlerMap.delete(t))}emit(e,...t){let r=this.listeners.get(e),o=this.cachedEventQueue.get(e);o||(o=new k,this.cachedEventQueue.set(e,o)),o.push({args:t}),r&&r.fire({event:e,args:t})}once(e,t){let r=(...o)=>{t(...o),this.off(e,r)};this.on(e,r,!1)}};var E={};be(E,{None:()=>ze,filter:()=>Be,once:()=>ye,toPromise:()=>$e});var ze=()=>(console.log("[Jolibox SDK] None Event"),()=>{console.log("[Jolibox SDK] None Event dispose")});function $e(n){return new Promise(e=>ye(n)(e))}function ye(n){return(e,t=null)=>{let r=!1;return n(i=>{if(!r)return r=!0,e.call(t,i)},null)}}function Be(n,e){return(r=>{let o,i={onWillAddFirstListener(){o=r(a.fire,a)}},a=new p(i);return a.event})((r,o=null)=>n(i=>e(i)&&r.call(o,i),null))}var j=Symbol.for("Jolibox.hostEmitter"),We=()=>{let n=new I;return globalThis[j]||(globalThis[j]={on:n.on.bind(n),off:n.off.bind(n),emit:n.emit.bind(n),once:n.once.bind(n)}),globalThis[j]},St=We();function Te(n,e){let t=Math.min(n.length,e.length);for(let r=0;r<t;r++)Qe(n[r],e[r])}function Qe(n,e){if(U(e)){if(typeof n!==e)throw new Error(`argument does not match constraint: typeof ${e}`)}else if(F(e)){try{if(n instanceof e)return}catch(t){}if(!D(n)&&n.constructor===e||e.length===1&&e.call(void 0,n)===!0)return;throw new Error("[Jolibox SDK]argument does not match one of these constraints: arg instanceof constraint, arg.constructor === constraint, nor constraint(arg) === true")}}var f=class{constructor(){this._commands=new Map;this._onDidRegisterCommand=new p;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 a of e.metadata.args)o.push(a.constraint);let i=e.handler;e.handler=function(...a){return Te(a,o),i(...a)}}let{id:t}=e;this._commands.get(t)&&console.info(`[Jolibox SDK] duplicated command is registered ${t}`),this._commands.set(t,e),this._onDidRegisterCommand.fire(t)}getCommand(e){return this._commands.get(e)}getCommands(){let e=new Map;for(let t of this._commands.keys()){let r=this.getCommand(t);r&&e.set(t,r)}return e}};f=w([O],f);var h=class{constructor(){this._onWillExecuteCommand=new p;this.onWillExecuteCommand=this._onWillExecuteCommand.event;this._onDidExecuteCommand=new p;this.onDidExecuteCommand=this._onDidExecuteCommand.event;this.registry=new f;this._starActivation=null}_activateStar(){return this._starActivation||(this._starActivation=$(3e4)),this._starActivation}executeCommand(e,...t){return N(this,null,function*(){return this.registry.getCommand(e)?this._tryExecuteCommand(e,t):(yield Promise.all([Promise.race([this._activateStar(),E.toPromise(E.filter(this.registry.onDidRegisterCommand,o=>o===e))])]),this._tryExecuteCommand(e,t))})}executeCommandThowErr(e,...t){if(!!!this.registry.getCommand(e))throw new Error(`command '${e}' not found`);let o=this.registry.getCommand(e);this._onWillExecuteCommand.fire({commandId:e,args:t});let i=this.invokeFunction(o.handler,...t);return this._onDidExecuteCommand.fire({commandId:e,args:t}),i}_tryExecuteCommand(e,t){let r=this.registry.getCommand(e);if(!r)return Promise.reject(new Error(`command '${e}' not found`));try{this._onWillExecuteCommand.fire({commandId:e,args:t});let o=this.invokeFunction(r.handler,...t);return this._onDidExecuteCommand.fire({commandId:e,args:t}),Promise.resolve(o)}catch(o){return Promise.reject(o)}}invokeFunction(e,...t){let r=!1;try{return e(...t)}finally{r=!0}}};h=w([O],h);var _e=Symbol.for("Jolibox.commands");function qe(){return typeof globalThis!="undefined"?globalThis[_e]:void 0}function Xe(n){typeof globalThis!="undefined"&&(globalThis[_e]=n)}function dr(){let n=qe();if(n)return n;let e=new f,t=new h,r={registerCommand(o,i,a){e.registerCommand({id:o,handler:i,metadata:a})},executeCommand(o,...i){return t.executeCommand(o,...i)},excuteCommandSync(o,...i){return t.executeCommandThowErr(o,...i)}};return Xe(r),r}export{Ve as ADVERTISING_ID,de as APIError,v as BaseError,Fe as DEVICE_ID,z as Deferred,Pe as EPlatform,Le as EProject,I as EventEmitter,Oe as EventType,E as EventUtils,te as InternalApplyNativeError,ie as InternalBufferError,se as InternalContextError,u as InternalError,ae as InternalGlobalJSError,re as InternalInvokeMethodError,ne as InternalInvokeNativeError,oe as InternalJSCoreNotFoundError,ee as InternalJSModuleEvalError,Z as InternalJSModuleFetchError,le as InternalMetricReportError,ce as InternalReporterError,Y as InternalSchemaParseError,Ce as LoadScriptCode,O as Singleton,L as UserCustomError,g as UserError,q as UserFetchError,X as UserFunctionEvalError,Q as UserGlobalError,W as UserValidateError,jn as canIUseConfig,Gn as compareVersion,dr as createCommands,tn as createRunTaskQueue,bn as debounce,Hn as get,He as getAdvertisingId,je as getDeviceId,fe as getOriginalLocalStorage,De as getPlatform,ge as getStorage,Je as getUtmSource,St as hostEmitter,ln as isArray,un as isBoolean,pn as isDefined,F as isFunction,mn as isIterable,Ue as isNative,cn as isNumber,Ie as isObject,fn as isPromiseLike,U as isString,an as isStringArray,dn as isTypedArray,Ae as isUndefined,D as isUndefinedOrNull,Xn as isValidUUIDV4,me as logger,En as mergeArray,xn as mergeWith,nn as microTask,S as platform,en as promisifyAPI,Bn as serializeEventPackage,Ze as sleep,$ as timeout,pe as uuidv4,Qe as validateConstraint,Te as validateConstraints,Ln as wrapUserFunction,ot as xUserAgent};
1
+ var M=Object.defineProperty,he=Object.defineProperties,Re=Object.getOwnPropertyDescriptor,ve=Object.getOwnPropertyDescriptors;var J=Object.getOwnPropertySymbols;var be=Object.prototype.hasOwnProperty,Ie=Object.prototype.propertyIsEnumerable;var G=(n,e,t)=>e in n?M(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,T=(n,e)=>{for(var t in e||(e={}))be.call(e,t)&&G(n,t,e[t]);if(J)for(var t of J(e))Ie.call(e,t)&&G(n,t,e[t]);return n},w=(n,e)=>he(n,ve(e));var Ae=(n,e)=>{for(var t in e)M(n,t,{get:e[t],enumerable:!0})};var C=(n,e,t,r)=>{for(var o=r>1?void 0:r?Re(e,t):e,i=n.length-1,a;i>=0;i--)(a=n[i])&&(o=(r?a(e,t,o):a(o))||o);return r&&o&&M(e,t,o),o};var N=(n,e,t)=>new Promise((r,o)=>{var i=s=>{try{l(t.next(s))}catch(m){o(m)}},a=s=>{try{l(t.throw(s))}catch(m){o(m)}},l=s=>s.done?r(s.value):Promise.resolve(s.value).then(i,a);l((t=t.apply(n,e)).next())});if(typeof window!="undefined"&&!window.AbortController){let n=function(){this.signal=new e};n.prototype.abort=function(){this.signal._aborted=!0,typeof this.signal.onabort=="function"&&this.signal.onabort(new Event("abort"));let t=new Event("abort");this.signal.dispatchEvent(t)};let e=function(){this._aborted=!1,this.aborted=!1,this.onabort=null,this._eventListeners={}};Object.defineProperty(e.prototype,"aborted",{get:function(){return this._aborted}}),e.prototype.addEventListener=function(t,r){this._eventListeners[t]||(this._eventListeners[t]=[]),this._eventListeners[t].push(r)},e.prototype.removeEventListener=function(t,r){if(!this._eventListeners[t])return;let o=this._eventListeners[t].indexOf(r);o!==-1&&this._eventListeners[t].splice(o,1)},e.prototype.dispatchEvent=function(t){if(this._eventListeners[t.type])for(let r of this._eventListeners[t.type])r.call(this,t)},window.AbortController=n,window.AbortSignal=e}function $(n){return new Promise(e=>{setTimeout(()=>{e()},n)})}function nn(n){return new Promise(e=>setTimeout(e,n))}function tn(n){return e=>new Promise((t,r)=>{n(w(T({},e),{success:t,fail(o){let i=new Error(o.errMsg);r(i)}}))})}function rn(n){if(n)Promise.resolve().then(n);else return Promise.resolve()}var z=class{constructor(){this.state="pending";this.promise=new Promise((e,t)=>{this.resolve=r=>{this.state==="pending"&&(this.state="fulfilled",e(r))},this.reject=r=>{this.state==="pending"&&(this.state="rejected",t(r))}})}};function on(){let n=[],e=!1,t=()=>N(this,null,function*(){let r=n.shift();if(r){e=!0;try{yield r()}finally{e=!1,t()}}});return r=>{n.push(r),e||t()}}function U(n){return typeof n=="string"}function ln(n){return Array.isArray(n)&&n.every(e=>U(e))}function we(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)&&!(n instanceof RegExp)&&!(n instanceof Date)}function cn(n){let e=Object.getPrototypeOf(Uint8Array);return typeof n=="object"&&n instanceof e}function mn(n){return typeof n=="object"&&Array.isArray(n)}function un(n){return typeof n=="number"&&!isNaN(n)}function pn(n){return!!n&&typeof n[Symbol.iterator]=="function"}function fn(n){return n===!0||n===!1}function Ce(n){return typeof n=="undefined"}function gn(n){return!D(n)}function D(n){return Ce(n)||n===null}function F(n){return typeof n=="function"}function yn(n){return we(n)&&F(n.then)}function O(n){let e=n,t=null,r=function(...o){return t||(t=new e(...o)),t};return r.prototype=e.prototype,r}function hn(n,e,t){if(typeof t!="function")throw new Error("[Jolibox SDK]Customizer must be a function");function r(o,i){for(let a in i)if(Object.prototype.hasOwnProperty.call(i,a)){let l=o[a],s=i[a],m=t(l,s,a,o,i);m!==void 0?o[a]=m:B(s)&&B(l)?o[a]=r(T({},l),s):Array.isArray(s)&&Array.isArray(l)?o[a]=[...l,...s]:o[a]=s}return o}return r(n,e)}function B(n){return n&&typeof n=="object"&&n.constructor===Object}function Rn(n,e){if(Array.isArray(n))return n.concat(e)}function An(n,e,t={}){let r=null,o,i,a,{leading:l=!1,trailing:s=!0}=t,m=()=>(a=n.apply(i,o),o=void 0,i=void 0,a),d=function(...E){o=E,i=this;let R=l&&!r;if(r&&clearTimeout(r),r=setTimeout(()=>{r=null,s&&!R&&m()},e),R)return m()};return d.cancel=()=>{r&&clearTimeout(r),r=null,o=i=void 0},d.flush=()=>{if(r)return clearTimeout(r),r=null,m()},d}var Ne=(s=>(s[s.DEVELOPER_FILE_NOT_FOUND=0]="DEVELOPER_FILE_NOT_FOUND",s[s.INTERNAL_IOS_CAN_NOT_FOUND_PKG=1]="INTERNAL_IOS_CAN_NOT_FOUND_PKG",s[s.USER_IOS_LOAD_TIMEOUT=2]="USER_IOS_LOAD_TIMEOUT",s[s.INTERNAL_IOS_PKG_LOAD_ERROR=3]="INTERNAL_IOS_PKG_LOAD_ERROR",s[s.INTERNAL_IOS_PKG_PARSE_FAIL=4]="INTERNAL_IOS_PKG_PARSE_FAIL",s[s.USER_IOS_GET_EMPTY_DATA=5]="USER_IOS_GET_EMPTY_DATA",s[s.USER_ANDROID_GET_PKG_FAIL=6]="USER_ANDROID_GET_PKG_FAIL",s[s.DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE=7]="DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE",s))(Ne||{}),v=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}},u=class extends v{constructor(){super(...arguments);this.kind="INTERNAL_ERROR"}},f=class extends v{constructor(){super(...arguments);this.kind="USER_ERROR"}},W=class extends f{constructor(){super(...arguments);this.name="USER_VALIDATE_ERROR"}},Q=class extends f{constructor(){super(...arguments);this.name="USER_GLOBAL_ERROR";this.priority="P1"}},P=class extends f{constructor(t,r,o){super(t);this.message=t;this.errNo=r;this.name="USER_CUSTOM_ERROR";this.errMsg=t,o&&(this.extra=Object.assign({},this.extra,o))}},Y=class extends f{constructor(t,r,o){super(t);this.message=t;this.errNo=r;this.name="USER_FETCH_ERROR";this.errMsg=t,o&&(this.extra=Object.assign({},this.extra,o))}},q=class extends f{constructor(t,r,o){super(t);this.message=t;this.errNo=r;this.name="USER_PAYMENT_ERROR";this.errMsg=t,o&&(this.extra=Object.assign({},this.extra,o))}},X=class extends f{constructor(){super(...arguments);this.name="USER_CALLBACK_ERROR"}},Z=class extends u{constructor(){super(...arguments);this.name="INTERNAL_SCHEMA_PARSE_ERROR";this.priority="P0"}},ee=class extends u{constructor(){super(...arguments);this.name="INTERNAL_JS_MODULE_FETCH_ERROR";this.priority="P0"}},ne=class extends u{constructor(){super(...arguments);this.name="INTERNAL_JS_MODULE_EVAL_ERROR";this.priority="P0"}},te=class extends u{constructor(){super(...arguments);this.name="INTERNAL_INVOKE_NATIVE_ERROR"}},re=class extends u{constructor(t,r,o){super(t);this.message=t;this.errNo=r;this.name="INTERNAL_PAYMENT_ERROR";this.priority="P0";this.errMsg=t,o&&(this.extra=Object.assign({},this.extra,o))}},oe=class extends u{constructor(t,r,o,i){super(t);this.errNo=r;this.name="INTERNAL_APPLY_NATIVE_ERROR";this.errorType=o,this.errorCode=i}},ie=class extends u{constructor(){super(...arguments);this.name="INTERNAL_INVOKE_METHOD_ERROR"}},se=class extends u{constructor(){super(...arguments);this.name="INTERNAL_JSCORE_ERROR";this.priority="P0"}},ae=class extends u{constructor(){super(...arguments);this.name="INTERNAL_BUFFER_ERROR"}},de=class extends u{constructor(t,r){super(t);this.message=t;this.name="INTERNAL_CONTEXT_ERROR";this.property=r}},le=class extends u{constructor(){super(...arguments);this.name="INTERNAL_GLOBAL_JS_ERROR";this.priority="P1"}},ce=class extends v{constructor(t,r,o,i,a){super(t);this.message=t;this.code=r;this.kind="API_ERROR";this.name="API_ERROR";o&&(this.errorType=o),i!==void 0&&(this.stack=i),a&&(this.priority=a)}toJSON(){return{message:this.message,stack:this.stack,name:this.name,code:this.code,errorType:this.errorType}}},me=class extends u{constructor(){super(...arguments);this.name="INTERNAL_METRIC_REPORT_ERROR"}},ue=class extends u{constructor(){super(...arguments);this.name="INTERNAL_REPORTER_ERROR"}};function Oe(n,e){return(...t)=>e(n,...t)}function Sn(n){return e=>Oe(e,function(t,...r){if(typeof t=="function")try{return t.apply(this,r)}catch(o){n(new P(`${o}`))}})}function b(n){return(...e)=>{var r,o;((o=(r=globalThis.VConsole)==null?void 0:r[n])!=null?o:globalThis.console[n])(...e)}}var pe={log:b("log"),warn:b("warn"),info:b("info"),error:b("error"),debug:b("debug")};Object.assign(globalThis,{logger:pe});var V=Symbol.for("Jolibox.canIUseMap"),Pe={};globalThis[V]||(globalThis[V]=Pe);var Kn={get config(){return globalThis[V]}};function Jn(n,e,t){let r=n;for(let o of e)if(r&&typeof r=="object")r=r[o];else return t;return r===void 0?t:r}function $n(n,e,t){let r=0;if(n!==e){let o=n.split("."),i=e.split("."),a=Math.max(o.length,i.length);for(let l=0;l<a;l++){let s=parseInt(o[l],10)||0,m=parseInt(i[l],10)||0;if(s>m){r=1;break}else if(s<m){r=-1;break}}}if(!t)return r;switch(t){case">":return r>0;case"<":return r<0;case"=":return r===0;case">=":return r>=0;case"<=":return r<=0;default:return!1}}var Le=(r=>(r[r.System=1e3]="System",r[r.ErrorTrace=1001]="ErrorTrace",r[r.UserDefined=1002]="UserDefined",r))(Le||{}),Se=(i=>(i.MiniGame="mini-game",i.MiniDrama="mini-drama",i.App="app",i.WebSDK="web-sdk",i.AppSDK="app-sdk",i))(Se||{}),ke=(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))(ke||{}),fe=["name","params"],Me=["name","type","location","target","extra","timestamp","userId"],Ue=["platform","os","appVersion","appId","model","brand","uuid","jsSdkVersion","extra"];function L(n,e){return e.map(t=>{if(t==="params"&&n[t]){let r=n[t];return Object.keys(r).reduce((o,i)=>(o[i]=String(r[i]),o),{})}return n[t]})}function De(n){let e=n.location?L(n.location,fe):null,t=n.target?L(n.target,fe):null;return L(w(T({},n),{location:e,target:t}),Me)}function Qn(n){let e=n.events.map(r=>De(r)),t=L(n.device,Ue);return[n.protocolVersion,e,t,n.project]}var ge=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,n=>{let e=Math.random()*16|0;return(n==="x"?e:e&3|8).toString(16)}),Zn=n=>/^[\da-f]{8}-[\da-f]{4}-4[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i.test(n);function ye(){try{if(window.__joliboxLocalStorage__)return window.__joliboxLocalStorage__;let n=Object.getOwnPropertyDescriptor(window,"localStorage");if(n&&n.get){let r=n.get.call(window);return window.__joliboxLocalStorage__=r,r}if(n=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(window),"localStorage"),n&&n.get)return n.get.call(window);let e=Window.prototype,t=Object.getOwnPropertyDescriptor(e,"localStorage");if(t&&t.get){let r=t.get.call(window);return window.__joliboxLocalStorage__=r,r}return localStorage}catch(n){return console.warn("Failed to get original localStorage, fallback to default implementation",n),localStorage}}ye();var Fe=()=>!!(navigator.userAgent||"").includes("JoliboxPlatformSDK"),S={isiOS:navigator.userAgent.includes("iPhone")||navigator.userAgent.includes("iPod")||navigator.userAgent.includes("iPad")||navigator.userAgent.includes("iPhone OS"),iosVersion:()=>{let n=navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/);return[parseInt(n[1],10),parseInt(n[2],10),parseInt(n[3]||"0",10)]},isAndroid:navigator.userAgent.includes("Android"),isMac:navigator.userAgent.includes("Mac"),isFacebook:navigator.userAgent.includes("FB_IAB"),isPC:!navigator.userAgent.includes("iPhone")&&!navigator.userAgent.includes("Android")},Ve=()=>S.isiOS?"iOS":S.isAndroid?"Android":S.isMac?"Mac":S.isFacebook?"Facebook":"PC",je="device_id",He="advertising_id",Ee=n=>(window.__joliboxLocalStorage__.getItem(n)||window.__joliboxLocalStorage__.setItem(n,ge()),window.__joliboxLocalStorage__.getItem(n)),Ke=()=>{let e=new URLSearchParams(window.location.search).get("deviceId");return e||Ee(je)},Je=()=>{let e=new URLSearchParams(window.location.search).get("advertisingId");return e||Ee(He)},Ge=n=>n.charAt(0).toUpperCase()+n.slice(1),ze=()=>{var e;let n=new URLSearchParams(window.location.search);return Ge((e=n.get("utm_source"))!=null?e:"")||"JoliboxSDK"},st=n=>{if(Fe())return window.navigator.userAgent;let e="JoliboxWebSDK",t=Ve(),r=navigator.language,o=Ke(),i=Je();return`${e} (${ze()}${t}; UnknownModel; UnknownSystemVersion; ${r}) uuid/${o} adid/${i} version/${n||""}`};var _=class _{constructor(e){this.element=e,this.next=_.Undefined,this.prev=_.Undefined}};_.Undefined=new _(void 0);var c=_,k=class{constructor(){this._first=c.Undefined;this._last=c.Undefined;this._size=0}get size(){return this._size}isEmpty(){return this._first===c.Undefined}clear(){let e=this._first;for(;e!==c.Undefined;){let t=e.next;e.prev=c.Undefined,e.next=c.Undefined,e=t}this._first=c.Undefined,this._last=c.Undefined,this._size=0}unshift(e){return this._insert(e,!1)}push(e){return this._insert(e,!0)}_insert(e,t){let r=new c(e);if(this._first===c.Undefined)this._first=r,this._last=r;else if(t){let i=this._last;this._last=r,r.prev=i,i.next=r}else{let i=this._first;this._first=r,r.next=i,i.prev=r}this._size+=1;let o=!1;return()=>{o||(o=!0,this._remove(r))}}shift(){if(this._first!==c.Undefined){let e=this._first.element;return this._remove(this._first),e}}pop(){if(this._last!==c.Undefined){let e=this._last.element;return this._remove(this._last),e}}_remove(e){if(e.prev!==c.Undefined&&e.next!==c.Undefined){let t=e.prev;t.next=e.next,e.next.prev=t}else e.prev===c.Undefined&&e.next===c.Undefined?(this._first=c.Undefined,this._last=c.Undefined):e.next===c.Undefined?(this._last=this._last.prev,this._last.next=c.Undefined):e.prev===c.Undefined&&(this._first=this._first.next,this._first.prev=c.Undefined);this._size-=1}*[Symbol.iterator](){let e=this._first;for(;e!==c.Undefined;)yield e.element,e=e.next}};var $e=0,y=class{constructor(e){this.value=e;this.id=$e++}},p=class{constructor(e){this.options=e;this._size=0}dispose(e){var t,r;this._disposed||(this._disposed=!0,this._listeners&&(e?(this._listeners instanceof y&&(this._listeners=[this._listeners]),this._listeners=this._listeners.filter(o=>(o==null?void 0:o.value)===e)):(this._listeners=void 0,this._size=0)),(r=(t=this.options)==null?void 0:t.onDidRemoveLastListener)==null||r.call(t))}get event(){var e;return(e=this._event)!=null||(this._event=(t,r)=>{var i,a,l,s,m,d;if(this._disposed)return()=>{console.info("[Jolibox SDK] Emitter is _disposed")};r&&(t=t.bind(r));let o=new y(t);return this._listeners?this._listeners instanceof y?this._listeners=[this._listeners,o]:this._listeners.push(o):((a=(i=this.options)==null?void 0:i.onWillAddFirstListener)==null||a.call(i,this),this._listeners=o,(s=(l=this.options)==null?void 0:l.onDidFirstListener)==null||s.call(l,this)),(d=(m=this.options)==null?void 0:m.onDidAddListener)==null||d.call(m,this),this._size++,()=>{var E,R,A,H;if(!this._disposed){if(this._listeners instanceof y)this._listeners.id===o.id&&(this._listeners=void 0,this._size=0,(R=(E=this.options)==null?void 0:E.onDidRemoveLastListener)==null||R.call(E));else if(this._listeners){let K=this._listeners.indexOf(o);K>=0&&(this._listeners.splice(K,1),this._size--,this._size===0&&((H=(A=this.options)==null?void 0:A.onDidRemoveLastListener)==null||H.call(A)))}}}}),this._event}_deliver(e,t){var o;if(!e)return;let r=((o=this.options)==null?void 0:o.onListenerError)||Error.constructor;if(!r){e.value(t);return}try{e.value(t)}catch(i){r(i)}}fire(e){this._listeners&&(this._listeners instanceof y?this._deliver(this._listeners,e):this._listeners.forEach(t=>this._deliver(t,e)))}hasListeners(){return this._size>0}},I=class{constructor(){this.listeners=new Map;this.listerHandlerMap=new WeakMap;this.cachedEventQueue=new Map}on(e,t,r=!0){var s;let o=(s=this.listeners.get(e))!=null?s:new p,i=m=>t(...m.args),a=o.event(i);this.listerHandlerMap.set(t,{handler:i,dispose:a}),this.listeners.set(e,o);let l=this.cachedEventQueue.get(e);if(l&&r)for(let m of l)t(...m.args)}flushCachedEvent(e){e?this.cachedEventQueue.delete(e):this.cachedEventQueue.clear()}off(e,t){let r=this.listerHandlerMap.get(t);r&&(r.dispose(),this.listerHandlerMap.delete(t))}emit(e,...t){let r=this.listeners.get(e),o=this.cachedEventQueue.get(e);o||(o=new k,this.cachedEventQueue.set(e,o)),o.push({args:t}),r&&r.fire({event:e,args:t})}once(e,t){let r=(...o)=>{t(...o),this.off(e,r)};this.on(e,r,!1)}};var x={};Ae(x,{None:()=>Be,filter:()=>Qe,once:()=>Te,toPromise:()=>We});var Be=()=>(console.log("[Jolibox SDK] None Event"),()=>{console.log("[Jolibox SDK] None Event dispose")});function We(n){return new Promise(e=>Te(n)(e))}function Te(n){return(e,t=null)=>{let r=!1;return n(i=>{if(!r)return r=!0,e.call(t,i)},null)}}function Qe(n,e){return(r=>{let o,i={onWillAddFirstListener(){o=r(a.fire,a)}},a=new p(i);return a.event})((r,o=null)=>n(i=>e(i)&&r.call(o,i),null))}var j=Symbol.for("Jolibox.hostEmitter"),Ye=()=>{let n=new I;return globalThis[j]||(globalThis[j]={on:n.on.bind(n),off:n.off.bind(n),emit:n.emit.bind(n),once:n.once.bind(n)}),globalThis[j]},Mt=Ye();function _e(n,e){let t=Math.min(n.length,e.length);for(let r=0;r<t;r++)qe(n[r],e[r])}function qe(n,e){if(U(e)){if(typeof n!==e)throw new Error(`argument does not match constraint: typeof ${e}`)}else if(F(e)){try{if(n instanceof e)return}catch(t){}if(!D(n)&&n.constructor===e||e.length===1&&e.call(void 0,n)===!0)return;throw new Error("[Jolibox SDK]argument does not match one of these constraints: arg instanceof constraint, arg.constructor === constraint, nor constraint(arg) === true")}}var g=class{constructor(){this._commands=new Map;this._onDidRegisterCommand=new p;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 a of e.metadata.args)o.push(a.constraint);let i=e.handler;e.handler=function(...a){return _e(a,o),i(...a)}}let{id:t}=e;this._commands.get(t)&&console.info(`[Jolibox SDK] duplicated command is registered ${t}`),this._commands.set(t,e),this._onDidRegisterCommand.fire(t)}getCommand(e){return this._commands.get(e)}getCommands(){let e=new Map;for(let t of this._commands.keys()){let r=this.getCommand(t);r&&e.set(t,r)}return e}};g=C([O],g);var h=class{constructor(){this._onWillExecuteCommand=new p;this.onWillExecuteCommand=this._onWillExecuteCommand.event;this._onDidExecuteCommand=new p;this.onDidExecuteCommand=this._onDidExecuteCommand.event;this.registry=new g;this._starActivation=null}_activateStar(){return this._starActivation||(this._starActivation=$(3e4)),this._starActivation}executeCommand(e,...t){return N(this,null,function*(){return this.registry.getCommand(e)?this._tryExecuteCommand(e,t):(yield Promise.all([Promise.race([this._activateStar(),x.toPromise(x.filter(this.registry.onDidRegisterCommand,o=>o===e))])]),this._tryExecuteCommand(e,t))})}executeCommandThowErr(e,...t){if(!!!this.registry.getCommand(e))throw new Error(`command '${e}' not found`);let o=this.registry.getCommand(e);this._onWillExecuteCommand.fire({commandId:e,args:t});let i=this.invokeFunction(o.handler,...t);return this._onDidExecuteCommand.fire({commandId:e,args:t}),i}_tryExecuteCommand(e,t){let r=this.registry.getCommand(e);if(!r)return Promise.reject(new Error(`command '${e}' not found`));try{this._onWillExecuteCommand.fire({commandId:e,args:t});let o=this.invokeFunction(r.handler,...t);return this._onDidExecuteCommand.fire({commandId:e,args:t}),Promise.resolve(o)}catch(o){return Promise.reject(o)}}invokeFunction(e,...t){let r=!1;try{return e(...t)}finally{r=!0}}};h=C([O],h);var xe=Symbol.for("Jolibox.commands");function Xe(){return typeof globalThis!="undefined"?globalThis[xe]:void 0}function Ze(n){typeof globalThis!="undefined"&&(globalThis[xe]=n)}function cr(){let n=Xe();if(n)return n;let e=new g,t=new h,r={registerCommand(o,i,a){e.registerCommand({id:o,handler:i,metadata:a})},executeCommand(o,...i){return t.executeCommand(o,...i)},excuteCommandSync(o,...i){return t.executeCommandThowErr(o,...i)}};return Ze(r),r}export{He as ADVERTISING_ID,ce as APIError,v as BaseError,je as DEVICE_ID,z as Deferred,ke as EPlatform,Se as EProject,I as EventEmitter,Le as EventType,x as EventUtils,oe as InternalApplyNativeError,ae as InternalBufferError,de as InternalContextError,u as InternalError,le as InternalGlobalJSError,ie as InternalInvokeMethodError,te as InternalInvokeNativeError,se as InternalJSCoreNotFoundError,ne as InternalJSModuleEvalError,ee as InternalJSModuleFetchError,me as InternalMetricReportError,re as InternalPaymentError,ue as InternalReporterError,Z as InternalSchemaParseError,Ne as LoadScriptCode,O as Singleton,P as UserCustomError,f as UserError,Y as UserFetchError,X as UserFunctionEvalError,Q as UserGlobalError,q as UserPaymentError,W as UserValidateError,Kn as canIUseConfig,$n as compareVersion,cr as createCommands,on as createRunTaskQueue,An as debounce,Jn as get,Je as getAdvertisingId,Ke as getDeviceId,ye as getOriginalLocalStorage,Ve as getPlatform,Ee as getStorage,ze as getUtmSource,Mt as hostEmitter,mn as isArray,fn as isBoolean,gn as isDefined,F as isFunction,pn as isIterable,Fe as isNative,un as isNumber,we as isObject,yn as isPromiseLike,U as isString,ln as isStringArray,cn as isTypedArray,Ce as isUndefined,D as isUndefinedOrNull,Zn as isValidUUIDV4,pe as logger,Rn as mergeArray,hn as mergeWith,rn as microTask,S as platform,tn as promisifyAPI,Qn as serializeEventPackage,nn as sleep,$ as timeout,ge as uuidv4,qe as validateConstraint,_e as validateConstraints,Sn as wrapUserFunction,st as xUserAgent};
@@ -1,13 +1,15 @@
1
1
  type InternalLifeCycleErrorName = 'INTERNAL_GAME_LAUNCH_ERROR';
2
2
  type InternalAPIErrorName = 'INTERNAL_API_ERROR';
3
3
  type InternalMetricErrorName = 'INTERNAL_METRIC_REPORT_ERROR';
4
+ type UserPaymentErrorName = 'USER_PAYMENT_ERROR';
4
5
  type InternalReporterErrorName = 'INTERNAL_REPORTER_ERROR';
5
6
  type InternalUtilErrorName = 'INTERNAL_BUFFER_ERROR' | 'INTERNAL_SCHEMA_PARSE_ERROR';
6
7
  type InternalGlobalJSErrorName = 'INTERNAL_GLOBAL_JS_ERROR';
8
+ type InternalPaymentErrorName = 'INTERNAL_PAYMENT_ERROR';
7
9
  type InternalInjectErrorName = 'INTERNAL_CONTEXT_ERROR' | 'INTERNAL_JSCORE_ERROR' | 'INTERNAL_JS_MODULE_FETCH_ERROR' | 'INTERNAL_JS_MODULE_EVAL_ERROR';
8
10
  type InternalBridgeErrorName = 'INTERNAL_INVOKE_NATIVE_ERROR' | 'INTERNAL_APPLY_NATIVE_ERROR' | 'INTERNAL_INVOKE_METHOD_ERROR';
9
11
  type UserErrorName = 'USER_VALIDATE_ERROR' | 'USER_GLOBAL_ERROR' | 'USER_FETCH_ERROR' | 'API_ERROR' | 'USER_CALLBACK_ERROR' | 'USER_CUSTOM_ERROR';
10
- export type ErrorName = InternalLifeCycleErrorName | InternalInjectErrorName | InternalAPIErrorName | InternalBridgeErrorName | InternalUtilErrorName | InternalReporterErrorName | UserErrorName | InternalMetricErrorName | InternalGlobalJSErrorName;
12
+ export type ErrorName = InternalLifeCycleErrorName | InternalInjectErrorName | InternalAPIErrorName | InternalBridgeErrorName | InternalUtilErrorName | InternalReporterErrorName | InternalPaymentErrorName | UserPaymentErrorName | UserErrorName | InternalMetricErrorName | InternalGlobalJSErrorName;
11
13
  export type ErrorKind = 'INTERNAL_ERROR' | 'USER_ERROR' | 'API_ERROR';
12
14
  export type ErrorEnv = 'native' | 'h5';
13
15
  export type LoadScriptError = BaseError & {
@@ -69,6 +71,18 @@ export declare class UserFetchError extends UserError {
69
71
  [key: string]: unknown;
70
72
  });
71
73
  }
74
+ export declare class UserPaymentError extends UserError {
75
+ readonly message: string;
76
+ readonly errNo?: number | undefined;
77
+ readonly name = "USER_PAYMENT_ERROR";
78
+ errMsg: string;
79
+ extra?: {
80
+ [key: string]: unknown;
81
+ };
82
+ constructor(message: string, errNo?: number | undefined, extra?: {
83
+ [key: string]: unknown;
84
+ });
85
+ }
72
86
  export declare class UserFunctionEvalError extends UserError {
73
87
  readonly name = "USER_CALLBACK_ERROR";
74
88
  }
@@ -87,6 +101,19 @@ export declare class InternalJSModuleEvalError extends InternalError {
87
101
  export declare class InternalInvokeNativeError extends InternalError {
88
102
  readonly name = "INTERNAL_INVOKE_NATIVE_ERROR";
89
103
  }
104
+ export declare class InternalPaymentError extends InternalError {
105
+ readonly message: string;
106
+ readonly errNo?: number | undefined;
107
+ readonly name = "INTERNAL_PAYMENT_ERROR";
108
+ readonly priority = "P0";
109
+ errMsg: string;
110
+ extra?: {
111
+ [key: string]: unknown;
112
+ };
113
+ constructor(message: string, errNo?: number | undefined, extra?: {
114
+ [key: string]: unknown;
115
+ });
116
+ }
90
117
  export declare class InternalApplyNativeError extends InternalError {
91
118
  readonly errNo?: number | undefined;
92
119
  readonly name = "INTERNAL_APPLY_NATIVE_ERROR";
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.1.25",
4
+ "version": "1.1.26",
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.1.25"
14
+ "@jolibox/types": "1.1.26"
15
15
  },
16
16
  "devDependencies": {
17
17
  "typescript": "5.7.3",