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