@jolibox/common 1.1.49 → 1.1.50

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