@jolibox/common 1.1.18-beta.4 → 1.1.18

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