@jolibox/common 1.1.32 → 1.1.34

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,Fe=Object.defineProperties,Te=Object.getOwnPropertyDescriptor,je=Object.getOwnPropertyDescriptors,He=Object.getOwnPropertyNames,ye=Object.getOwnPropertySymbols;var xe=Object.prototype.hasOwnProperty,Ke=Object.prototype.propertyIsEnumerable;var Ee=(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={}))xe.call(e,t)&&Ee(n,t,e[t]);if(ye)for(var t of ye(e))Ke.call(e,t)&&Ee(n,t,e[t]);return n},P=(n,e)=>Fe(n,je(e));var _e=(n,e)=>{for(var t in e)I(n,t,{get:e[t],enumerable:!0})},Ge=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of He(e))!xe.call(n,o)&&o!==t&&I(n,o,{get:()=>e[o],enumerable:!(r=Te(e,o))||r.enumerable});return n};var Je=n=>Ge(I({},"__esModule",{value:!0}),n),L=(n,e,t,r)=>{for(var o=r>1?void 0:r?Te(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 Pn={};_e(Pn,{ADVERTISING_ID:()=>Le,APIError:()=>re,BaseError:()=>_,DEVICE_ID:()=>Pe,Deferred:()=>F,EPlatform:()=>Ne,EProject:()=>Ce,EventEmitter:()=>R,EventType:()=>Ae,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:()=>be,Singleton:()=>A,UserCustomError:()=>C,UserError:()=>f,UserFetchError:()=>G,UserFunctionEvalError:()=>z,UserGlobalError:()=>K,UserPaymentError:()=>J,UserValidateError:()=>H,canIUseConfig:()=>cn,canIUseConfigNative:()=>pn,compareVersion:()=>fn,createCommands:()=>On,createRunTaskQueue:()=>We,debounce:()=>sn,get:()=>mn,getAdvertisingId:()=>ke,getDeviceId:()=>Se,getOriginalLocalStorage:()=>ce,getPlatform:()=>Oe,getStorage:()=>me,getUtmSource:()=>Me,hostEmitter:()=>Cn,isArray:()=>qe,isBoolean:()=>en,isDefined:()=>nn,isFunction:()=>U,isIterable:()=>Ze,isNative:()=>we,isNumber:()=>Xe,isObject:()=>he,isPromiseLike:()=>tn,isString:()=>k,isStringArray:()=>Qe,isTypedArray:()=>Ye,isUndefined:()=>Re,isUndefinedOrNull:()=>M,isValidUUIDV4:()=>xn,logger:()=>se,mergeArray:()=>on,mergeWith:()=>rn,microTask:()=>Be,platform:()=>w,promisifyAPI:()=>$e,serializeEventPackage:()=>Tn,sleep:()=>ze,timeout:()=>j,uuidv4:()=>le,validateConstraint:()=>De,validateConstraints:()=>pe,wrapUserFunction:()=>dn,xUserAgent:()=>hn});module.exports=Je(Pn);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 ze(n){return new Promise(e=>setTimeout(e,n))}function $e(n){return e=>new Promise((t,r)=>{n(P(x({},e),{success:t,fail(o){let i=new Error(o.errMsg);r(i)}}))})}function Be(n){if(n)Promise.resolve().then(n);else return Promise.resolve()}var F=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 We(){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 Qe(n){return Array.isArray(n)&&n.every(e=>k(e))}function he(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)&&!(n instanceof RegExp)&&!(n instanceof Date)}function Ye(n){let e=Object.getPrototypeOf(Uint8Array);return typeof n=="object"&&n instanceof e}function qe(n){return typeof n=="object"&&Array.isArray(n)}function Xe(n){return typeof n=="number"&&!isNaN(n)}function Ze(n){return!!n&&typeof n[Symbol.iterator]=="function"}function en(n){return n===!0||n===!1}function Re(n){return typeof n=="undefined"}function nn(n){return!M(n)}function M(n){return Re(n)||n===null}function U(n){return typeof n=="function"}function tn(n){return he(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 rn(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:ve(s)&&ve(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 ve(n){return n&&typeof n=="object"&&n.constructor===Object}function on(n,e){if(Array.isArray(n))return n.concat(e)}function sn(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 be=(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))(be||{}),_=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 _{constructor(){super(...arguments);this.kind="INTERNAL_ERROR"}},f=class extends _{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))}},G=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))}},J=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 _{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 an(n,e){return(...t)=>e(n,...t)}function dn(n){return e=>an(e,function(t,...r){if(typeof t=="function")try{return t.apply(this,r)}catch(o){n(new C(`${o}`))}})}function N(n){return(...e)=>{var r,o;((o=(r=globalThis.VConsole)==null?void 0:r[n])!=null?o:globalThis.console[n])(...e)}}var se={log:N("log"),warn:N("warn"),info:N("info"),error:N("error"),debug:N("debug")};Object.assign(globalThis,{logger:se});var ae=Symbol.for("Jolibox.canIUseMap"),ln={};globalThis[ae]||(globalThis[ae]=ln);var cn={get config(){return globalThis[ae]}};function mn(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 de=Symbol.for("Jolibox.canIUseMap.native"),un={};globalThis[de]||(globalThis[de]=un);var pn={get config(){return globalThis[de]}};function fn(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 Ae=(r=>(r[r.System=1e3]="System",r[r.ErrorTrace=1001]="ErrorTrace",r[r.UserDefined=1002]="UserDefined",r))(Ae||{}),Ce=(i=>(i.MiniGame="mini-game",i.MiniDrama="mini-drama",i.App="app",i.WebSDK="web-sdk",i.AppSDK="app-sdk",i))(Ce||{}),Ne=(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))(Ne||{}),Ie=["name","params"],gn=["name","type","location","target","extra","timestamp","userId"],yn=["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 En(n){let e=n.location?D(n.location,Ie):null,t=n.target?D(n.target,Ie):null;return D(P(x({},n),{location:e,target:t}),gn)}function Tn(n){let e=n.events.map(r=>En(r)),t=D(n.device,yn);return[n.protocolVersion,e,t,n.project]}var le=()=>"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 ce(){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}}ce();var we=()=>!!(navigator.userAgent||"").includes("JoliboxPlatformSDK"),w={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")},Oe=()=>w.isiOS?"iOS":w.isAndroid?"Android":w.isMac?"Mac":w.isFacebook?"Facebook":"PC",Pe="device_id",Le="advertising_id",me=n=>(window.__joliboxLocalStorage__.getItem(n)||window.__joliboxLocalStorage__.setItem(n,le()),window.__joliboxLocalStorage__.getItem(n)),Se=()=>{let e=new URLSearchParams(window.location.search).get("deviceId");return e||me(Pe)},ke=()=>{let e=new URLSearchParams(window.location.search).get("advertisingId");return e||me(Le)},_n=n=>n.charAt(0).toUpperCase()+n.slice(1),Me=()=>{var e;let n=new URLSearchParams(window.location.search);return _n((e=n.get("utm_source"))!=null?e:"")||"JoliboxSDK"},hn=n=>{if(we())return window.navigator.userAgent;let e="JoliboxWebSDK",t=Oe(),r=navigator.language,o=Se(),i=ke();return`${e} (${Me()}${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,V=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 Rn=0,y=class{constructor(e){this.value=e;this.id=Rn++}},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,fe;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 ge=this._listeners.indexOf(o);ge>=0&&(this._listeners.splice(ge,1),this._size--,this._size===0&&((fe=(O=this.options)==null?void 0:O.onDidRemoveLastListener)==null||fe.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 V,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:()=>vn,filter:()=>In,once:()=>Ue,toPromise:()=>bn});var vn=()=>(console.log("[Jolibox SDK] None Event"),()=>{console.log("[Jolibox SDK] None Event dispose")});function bn(n){return new Promise(e=>Ue(n)(e))}function Ue(n){return(e,t=null)=>{let r=!1;return n(i=>{if(!r)return r=!0,e.call(t,i)},null)}}function In(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 ue=Symbol.for("Jolibox.hostEmitter"),An=()=>{let n=new R;return globalThis[ue]||(globalThis[ue]={on:n.on.bind(n),off:n.off.bind(n),emit:n.emit.bind(n),once:n.once.bind(n)}),globalThis[ue]},Cn=An();function pe(n,e){let t=Math.min(n.length,e.length);for(let r=0;r<t;r++)De(n[r],e[r])}function De(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 pe(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 Ve=Symbol.for("Jolibox.commands");function Nn(){return typeof globalThis!="undefined"?globalThis[Ve]:void 0}function wn(n){typeof globalThis!="undefined"&&(globalThis[Ve]=n)}function On(){let n=Nn();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 wn(r),r}
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,a;i>=0;i--)(a=n[i])&&(o=(r?a(e,t,o):a(o))||o);return r&&o&&C(e,t,o),o};var k=(n,e,t)=>new Promise((r,o)=>{var i=s=>{try{c(t.next(s))}catch(u){o(u)}},a=s=>{try{c(t.throw(s))}catch(u){o(u)}},c=s=>s.done?r(s.value):Promise.resolve(s.value).then(i,a);c((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 a in i)if(Object.prototype.hasOwnProperty.call(i,a)){let c=o[a],s=i[a],u=t(c,s,a,o,i);u!==void 0?o[a]=u:be(s)&&be(c)?o[a]=r(E({},c),s):Array.isArray(s)&&Array.isArray(c)?o[a]=[...c,...s]:o[a]=s}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,a,{leading:c=!1,trailing:s=!0}=t,u=()=>(a=n.apply(i,o),o=void 0,i=void 0,a),l=function(...h){o=h,i=this;let I=c&&!r;if(r&&clearTimeout(r),r=setTimeout(()=>{r=null,s&&!I&&u()},e),I)return u()};return l.cancel=()=>{r&&clearTimeout(r),r=null,o=i=void 0},l.flush=()=>{if(r)return clearTimeout(r),r=null,u()},l}var Ie=(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))(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,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}}},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("."),a=Math.max(o.length,i.length);for(let c=0;c<a;c++){let s=parseInt(o[c],10)||0,u=parseInt(i[c],10)||0;if(s>u){r=1;break}else if(s<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=(l=>(l[l.App=0]="App",l[l.H5=1]="H5",l[l.Weapp=2]="Weapp",l[l.Alipay=3]="Alipay",l[l.Gcash=4]="Gcash",l[l.Dana=5]="Dana",l[l.Umma=6]="Umma",l[l.WebSDK=1e3]="WebSDK",l[l.AppSDK=1001]="AppSDK",l[l.Other=9999]="Other",l))(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,a,c,s,u,l;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):((a=(i=this.options)==null?void 0:i.onWillAddFirstListener)==null||a.call(i,this),this._listeners=o,(s=(c=this.options)==null?void 0:c.onDidFirstListener)==null||s.call(c,this)),(l=(u=this.options)==null?void 0:u.onDidAddListener)==null||l.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 s;let o=(s=this.listeners.get(e))!=null?s:new f,i=u=>t(...u.args),a=o.event(i);this.listerHandlerMap.set(t,{handler:i,dispose:a}),this.listeners.set(e,o);let c=this.cachedEventQueue.get(e);if(c&&r)for(let u of c)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(a.fire,a)}},a=new f(i);return a.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 a of e.metadata.args)o.push(a.constraint);let i=e.handler;e.handler=function(...a){return fe(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}};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(){let n=wn();if(n)return n;let e=new y,t=new b,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 On(r),r}
package/dist/index.es.js CHANGED
@@ -1 +1 @@
1
- var M=Object.defineProperty,Re=Object.defineProperties,ve=Object.getOwnPropertyDescriptor,be=Object.getOwnPropertyDescriptors;var J=Object.getOwnPropertySymbols;var Ie=Object.prototype.hasOwnProperty,Ae=Object.prototype.propertyIsEnumerable;var z=(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={}))Ie.call(e,t)&&z(n,t,e[t]);if(J)for(var t of J(e))Ae.call(e,t)&&z(n,t,e[t]);return n},C=(n,e)=>Re(n,be(e));var Ce=(n,e)=>{for(var t in e)M(n,t,{get:e[t],enumerable:!0})};var N=(n,e,t,r)=>{for(var o=r>1?void 0:r?ve(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 w=(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 B(n){return new Promise(e=>{setTimeout(()=>{e()},n)})}function rn(n){return new Promise(e=>setTimeout(e,n))}function on(n){return e=>new Promise((t,r)=>{n(C(T({},e),{success:t,fail(o){let i=new Error(o.errMsg);r(i)}}))})}function sn(n){if(n)Promise.resolve().then(n);else return Promise.resolve()}var $=class{constructor(){this.state="pending";this.promise=new Promise((e,t)=>{this.resolve=r=>{this.state==="pending"&&(this.state="fulfilled",e(r))},this.reject=r=>{this.state==="pending"&&(this.state="rejected",t(r))}})}};function an(){let n=[],e=!1,t=()=>w(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 mn(n){return Array.isArray(n)&&n.every(e=>U(e))}function Ne(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)&&!(n instanceof RegExp)&&!(n instanceof Date)}function un(n){let e=Object.getPrototypeOf(Uint8Array);return typeof n=="object"&&n instanceof e}function pn(n){return typeof n=="object"&&Array.isArray(n)}function fn(n){return typeof n=="number"&&!isNaN(n)}function gn(n){return!!n&&typeof n[Symbol.iterator]=="function"}function yn(n){return n===!0||n===!1}function we(n){return typeof n=="undefined"}function En(n){return!D(n)}function D(n){return we(n)||n===null}function V(n){return typeof n=="function"}function Tn(n){return Ne(n)&&V(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 vn(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:W(s)&&W(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 W(n){return n&&typeof n=="object"&&n.constructor===Object}function bn(n,e){if(Array.isArray(n))return n.concat(e)}function Nn(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 Oe=(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))(Oe||{}),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"}},Q=class extends f{constructor(){super(...arguments);this.name="USER_VALIDATE_ERROR"}},Y=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))}},q=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))}},X=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"}},ee=class extends u{constructor(){super(...arguments);this.name="INTERNAL_SCHEMA_PARSE_ERROR";this.priority="P0"}},ne=class extends u{constructor(){super(...arguments);this.name="INTERNAL_JS_MODULE_FETCH_ERROR";this.priority="P0"}},te=class extends u{constructor(){super(...arguments);this.name="INTERNAL_JS_MODULE_EVAL_ERROR";this.priority="P0"}},re=class extends u{constructor(){super(...arguments);this.name="INTERNAL_INVOKE_NATIVE_ERROR"}},oe=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))}},ie=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}},se=class extends u{constructor(){super(...arguments);this.name="INTERNAL_INVOKE_METHOD_ERROR"}},ae=class extends u{constructor(){super(...arguments);this.name="INTERNAL_JSCORE_ERROR";this.priority="P0"}},de=class extends u{constructor(){super(...arguments);this.name="INTERNAL_BUFFER_ERROR"}},le=class extends u{constructor(t,r){super(t);this.message=t;this.name="INTERNAL_CONTEXT_ERROR";this.property=r}},ce=class extends u{constructor(){super(...arguments);this.name="INTERNAL_GLOBAL_JS_ERROR";this.priority="P1"}},me=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}}},ue=class extends u{constructor(){super(...arguments);this.name="INTERNAL_METRIC_REPORT_ERROR"}},pe=class extends u{constructor(){super(...arguments);this.name="INTERNAL_REPORTER_ERROR"}};function Pe(n,e){return(...t)=>e(n,...t)}function Mn(n){return e=>Pe(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 fe={log:b("log"),warn:b("warn"),info:b("info"),error:b("error"),debug:b("debug")};Object.assign(globalThis,{logger:fe});var F=Symbol.for("Jolibox.canIUseMap"),Le={};globalThis[F]||(globalThis[F]=Le);var Jn={get config(){return globalThis[F]}};function zn(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 j=Symbol.for("Jolibox.canIUseMap.native"),Se={};globalThis[j]||(globalThis[j]=Se);var $n={get config(){return globalThis[j]}};function Qn(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 ke=(r=>(r[r.System=1e3]="System",r[r.ErrorTrace=1001]="ErrorTrace",r[r.UserDefined=1002]="UserDefined",r))(ke||{}),Me=(i=>(i.MiniGame="mini-game",i.MiniDrama="mini-drama",i.App="app",i.WebSDK="web-sdk",i.AppSDK="app-sdk",i))(Me||{}),Ue=(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))(Ue||{}),ge=["name","params"],De=["name","type","location","target","extra","timestamp","userId"],Ve=["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 Fe(n){let e=n.location?L(n.location,ge):null,t=n.target?L(n.target,ge):null;return L(C(T({},n),{location:e,target:t}),De)}function Xn(n){let e=n.events.map(r=>Fe(r)),t=L(n.device,Ve);return[n.protocolVersion,e,t,n.project]}var ye=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,n=>{let e=Math.random()*16|0;return(n==="x"?e:e&3|8).toString(16)}),tt=n=>/^[\da-f]{8}-[\da-f]{4}-4[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i.test(n);function Ee(){try{if(window.__joliboxLocalStorage__)return window.__joliboxLocalStorage__;let n=Object.getOwnPropertyDescriptor(window,"localStorage");if(n&&n.get){let r=n.get.call(window);return window.__joliboxLocalStorage__=r,r}if(n=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(window),"localStorage"),n&&n.get)return n.get.call(window);let e=Window.prototype,t=Object.getOwnPropertyDescriptor(e,"localStorage");if(t&&t.get){let r=t.get.call(window);return window.__joliboxLocalStorage__=r,r}return localStorage}catch(n){return console.warn("Failed to get original localStorage, fallback to default implementation",n),localStorage}}Ee();var je=()=>!!(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")},He=()=>S.isiOS?"iOS":S.isAndroid?"Android":S.isMac?"Mac":S.isFacebook?"Facebook":"PC",Ke="device_id",Ge="advertising_id",Te=n=>(window.__joliboxLocalStorage__.getItem(n)||window.__joliboxLocalStorage__.setItem(n,ye()),window.__joliboxLocalStorage__.getItem(n)),Je=()=>{let e=new URLSearchParams(window.location.search).get("deviceId");return e||Te(Ke)},ze=()=>{let e=new URLSearchParams(window.location.search).get("advertisingId");return e||Te(Ge)},$e=n=>n.charAt(0).toUpperCase()+n.slice(1),Be=()=>{var e;let n=new URLSearchParams(window.location.search);return $e((e=n.get("utm_source"))!=null?e:"")||"JoliboxSDK"},lt=n=>{if(je())return window.navigator.userAgent;let e="JoliboxWebSDK",t=He(),r=navigator.language,o=Je(),i=ze();return`${e} (${Be()}${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 We=0,y=class{constructor(e){this.value=e;this.id=We++}},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,K;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 G=this._listeners.indexOf(o);G>=0&&(this._listeners.splice(G,1),this._size--,this._size===0&&((K=(A=this.options)==null?void 0:A.onDidRemoveLastListener)==null||K.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 _={};Ce(_,{None:()=>Qe,filter:()=>qe,once:()=>xe,toPromise:()=>Ye});var Qe=()=>(console.log("[Jolibox SDK] None Event"),()=>{console.log("[Jolibox SDK] None Event dispose")});function Ye(n){return new Promise(e=>xe(n)(e))}function xe(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 H=Symbol.for("Jolibox.hostEmitter"),Xe=()=>{let n=new I;return globalThis[H]||(globalThis[H]={on:n.on.bind(n),off:n.off.bind(n),emit:n.emit.bind(n),once:n.once.bind(n)}),globalThis[H]},Vt=Xe();function _e(n,e){let t=Math.min(n.length,e.length);for(let r=0;r<t;r++)Ze(n[r],e[r])}function Ze(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 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=N([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=B(3e4)),this._starActivation}executeCommand(e,...t){return w(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}}};h=N([O],h);var he=Symbol.for("Jolibox.commands");function en(){return typeof globalThis!="undefined"?globalThis[he]:void 0}function nn(n){typeof globalThis!="undefined"&&(globalThis[he]=n)}function pr(){let n=en();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 nn(r),r}export{Ge as ADVERTISING_ID,me as APIError,v as BaseError,Ke as DEVICE_ID,$ as Deferred,Ue as EPlatform,Me as EProject,I as EventEmitter,ke as EventType,_ as EventUtils,ie as InternalApplyNativeError,de as InternalBufferError,le as InternalContextError,u as InternalError,ce as InternalGlobalJSError,se as InternalInvokeMethodError,re as InternalInvokeNativeError,ae as InternalJSCoreNotFoundError,te as InternalJSModuleEvalError,ne as InternalJSModuleFetchError,ue as InternalMetricReportError,oe as InternalPaymentError,pe as InternalReporterError,ee as InternalSchemaParseError,Oe as LoadScriptCode,O as Singleton,P as UserCustomError,f as UserError,q as UserFetchError,Z as UserFunctionEvalError,Y as UserGlobalError,X as UserPaymentError,Q as UserValidateError,Jn as canIUseConfig,$n as canIUseConfigNative,Qn as compareVersion,pr as createCommands,an as createRunTaskQueue,Nn as debounce,zn as get,ze as getAdvertisingId,Je as getDeviceId,Ee as getOriginalLocalStorage,He as getPlatform,Te as getStorage,Be as getUtmSource,Vt as hostEmitter,pn as isArray,yn as isBoolean,En as isDefined,V as isFunction,gn as isIterable,je as isNative,fn as isNumber,Ne as isObject,Tn as isPromiseLike,U as isString,mn as isStringArray,un as isTypedArray,we as isUndefined,D as isUndefinedOrNull,tt as isValidUUIDV4,fe as logger,bn as mergeArray,vn as mergeWith,sn as microTask,S as platform,on as promisifyAPI,Xn as serializeEventPackage,rn as sleep,B as timeout,ye as uuidv4,Ze as validateConstraint,_e as validateConstraints,Mn as wrapUserFunction,lt as xUserAgent};
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,a;i>=0;i--)(a=n[i])&&(o=(r?a(e,t,o):a(o))||o);return r&&o&&U(e,t,o),o};var O=(n,e,t)=>new Promise((r,o)=>{var i=s=>{try{c(t.next(s))}catch(u){o(u)}},a=s=>{try{c(t.throw(s))}catch(u){o(u)}},c=s=>s.done?r(s.value):Promise.resolve(s.value).then(i,a);c((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 a in i)if(Object.prototype.hasOwnProperty.call(i,a)){let c=o[a],s=i[a],u=t(c,s,a,o,i);u!==void 0?o[a]=u:Q(s)&&Q(c)?o[a]=r(h({},c),s):Array.isArray(s)&&Array.isArray(c)?o[a]=[...c,...s]:o[a]=s}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,a,{leading:c=!1,trailing:s=!0}=t,u=()=>(a=n.apply(i,o),o=void 0,i=void 0,a),l=function(..._){o=_,i=this;let v=c&&!r;if(r&&clearTimeout(r),r=setTimeout(()=>{r=null,s&&!v&&u()},e),v)return u()};return l.cancel=()=>{r&&clearTimeout(r),r=null,o=i=void 0},l.flush=()=>{if(r)return clearTimeout(r),r=null,u()},l}var Pe=(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))(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,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}}},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("."),a=Math.max(o.length,i.length);for(let c=0;c<a;c++){let s=parseInt(o[c],10)||0,u=parseInt(i[c],10)||0;if(s>u){r=1;break}else if(s<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=(l=>(l[l.App=0]="App",l[l.H5=1]="H5",l[l.Weapp=2]="Weapp",l[l.Alipay=3]="Alipay",l[l.Gcash=4]="Gcash",l[l.Dana=5]="Dana",l[l.Umma=6]="Umma",l[l.WebSDK=1e3]="WebSDK",l[l.AppSDK=1001]="AppSDK",l[l.Other=9999]="Other",l))(De||{}),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,a,c,s,u,l;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):((a=(i=this.options)==null?void 0:i.onWillAddFirstListener)==null||a.call(i,this),this._listeners=o,(s=(c=this.options)==null?void 0:c.onDidFirstListener)==null||s.call(c,this)),(l=(u=this.options)==null?void 0:u.onDidAddListener)==null||l.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 s;let o=(s=this.listeners.get(e))!=null?s:new f,i=u=>t(...u.args),a=o.event(i);this.listerHandlerMap.set(t,{handler:i,dispose:a}),this.listeners.set(e,o);let c=this.cachedEventQueue.get(e);if(c&&r)for(let u of c)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(a.fire,a)}},a=new f(i);return a.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 a of e.metadata.args)o.push(a.constraint);let i=e.handler;e.handler=function(...a){return Re(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}};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(){let n=nn();if(n)return n;let e=new y,t=new T,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 tn(r),r}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,4 +1,17 @@
1
1
  export declare enum EventType {
2
+ Other = 0,// default
3
+ Route = 1,// event name must be "Route"
4
+ Click = 2,
5
+ View = 3,
6
+ Expose = 4,
7
+ Swipe = 5,
8
+ Input = 6,
9
+ Select = 7,
10
+ SwitchOn = 8,
11
+ SwitchOff = 9,
12
+ Submit = 10,
13
+ Scroll = 11,
14
+ Hide = 12,
2
15
  System = 1000,// used for web sdk
3
16
  ErrorTrace = 1001,// used for web sdk
4
17
  UserDefined = 1002
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.32",
4
+ "version": "1.1.34",
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.32"
14
+ "@jolibox/types": "1.1.34"
15
15
  },
16
16
  "devDependencies": {
17
17
  "typescript": "5.7.3",