@jolibox/common 1.2.4 → 1.2.5
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 +1 -1
- package/dist/index.es.js +1 -1
- package/dist/utils/host.d.ts +2 -0
- package/package.json +2 -2
package/dist/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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{d(t.next(a))}catch(u){o(u)}},s=a=>{try{d(t.throw(a))}catch(u){o(u)}},d=a=>a.done?r(a.value):Promise.resolve(a.value).then(i,s);d((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 d=o[s],a=i[s],u=t(d,a,s,o,i);u!==void 0?o[s]=u:Ie(a)&&Ie(d)?o[s]=r(E({},d),a):Array.isArray(a)&&Array.isArray(d)?o[s]=[...d,...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:d=!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=d&&!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 d=0;d<s;d++){let a=parseInt(o[d],10)||0,u=parseInt(i[d],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=(l=>(l[l.Other=0]="Other",l[l.Route=1]="Route",l[l.Click=2]="Click",l[l.View=3]="View",l[l.Expose=4]="Expose",l[l.Swipe=5]="Swipe",l[l.Input=6]="Input",l[l.Select=7]="Select",l[l.SwitchOn=8]="SwitchOn",l[l.SwitchOff=9]="SwitchOff",l[l.Submit=10]="Submit",l[l.Scroll=11]="Scroll",l[l.Hide=12]="Hide",l[l.System=1e3]="System",l[l.ErrorTrace=1001]="ErrorTrace",l[l.UserDefined=1002]="UserDefined",l))(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 d=o.slice(-2).join(".");if(d==="jolibox.com"||d==="pico-game.com"||d==="joyslite.com")return`${i}.${d}`}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,d,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=(d=this.options)==null?void 0:d.onDidFirstListener)==null||a.call(d,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 d=this.cachedEventQueue.get(e);if(d&&r)for(let u of d)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,d){t.registerCommand({id:i,handler:s,metadata:d})},executeCommand(i,...s){return r.executeCommand(i,...s)},excuteCommandSync(i,...s){return r.executeCommandThowErr(i,...s)}};return Un(o),o}
|
|
1
|
+
"use strict";var C=Object.defineProperty,Ge=Object.defineProperties,Re=Object.getOwnPropertyDescriptor,Je=Object.getOwnPropertyDescriptors,ze=Object.getOwnPropertyNames,_e=Object.getOwnPropertySymbols;var Te=Object.prototype.hasOwnProperty,Be=Object.prototype.propertyIsEnumerable;var Ee=(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={}))Te.call(e,t)&&Ee(n,t,e[t]);if(_e)for(var t of _e(e))Be.call(e,t)&&Ee(n,t,e[t]);return n},L=(n,e)=>Ge(n,Je(e));var ve=(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))!Te.call(n,o)&&o!==t&&C(n,o,{get:()=>e[o],enumerable:!(r=Re(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?Re(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{d(t.next(a))}catch(u){o(u)}},s=a=>{try{d(t.throw(a))}catch(u){o(u)}},d=a=>a.done?r(a.value):Promise.resolve(a.value).then(i,s);d((t=t.apply(n,e)).next())});var jn={};ve(jn,{ADVERTISING_ID:()=>Me,APIError:()=>se,BaseError:()=>R,DEVICE_ID:()=>ke,Deferred:()=>$,EPlatform:()=>Pe,EProject:()=>Oe,EventEmitter:()=>b,EventType:()=>Ne,EventUtils:()=>h,InternalApplyNativeError:()=>ee,InternalBufferError:()=>re,InternalContextError:()=>oe,InternalError:()=>p,InternalGlobalJSError:()=>ie,InternalInvokeMethodError:()=>ne,InternalInvokeNativeError:()=>X,InternalJSCoreNotFoundError:()=>te,InternalJSModuleEvalError:()=>q,InternalJSModuleFetchError:()=>Y,InternalMetricReportError:()=>ae,InternalPaymentError:()=>Z,InternalReporterError:()=>de,InternalSchemaParseError:()=>Q,LoadScriptCode:()=>Ce,Singleton:()=>w,UserCustomError:()=>N,UserError:()=>g,UserFetchError:()=>z,UserFunctionEvalError:()=>W,UserGlobalError:()=>J,UserPaymentError:()=>B,UserValidateError:()=>G,canIUseConfig:()=>gn,canIUseConfigNative:()=>hn,compareVersion:()=>_n,createCommands:()=>Fn,createRunTaskQueue:()=>Ze,debounce:()=>mn,get:()=>yn,getAdvertisingId:()=>De,getApiDomain:()=>Fe,getApiHost:()=>Cn,getCollectDomain:()=>je,getCollectHost:()=>On,getDeviceId:()=>Ue,getH5ApiHost:()=>wn,getH5Domain:()=>Nn,getOriginalLocalStorage:()=>pe,getPlatform:()=>Le,getStorage:()=>fe,getUtmSource:()=>Ve,hostEmitter:()=>Un,isArray:()=>tn,isBoolean:()=>sn,isDefined:()=>an,isFunction:()=>V,isIterable:()=>on,isNative:()=>Se,isNumber:()=>rn,isObject:()=>be,isPromiseLike:()=>dn,isString:()=>U,isStringArray:()=>en,isTypedArray:()=>nn,isUndefined:()=>Ie,isUndefinedOrNull:()=>D,isValidUUIDV4:()=>bn,logger:()=>le,mergeArray:()=>cn,mergeWith:()=>ln,microTask:()=>Xe,platform:()=>P,promisifyAPI:()=>qe,serializeEventPackage:()=>vn,sleep:()=>Ye,timeout:()=>K,uuidv4:()=>ue,validateConstraint:()=>$e,validateConstraints:()=>ye,wrapUserFunction:()=>pn,xUserAgent:()=>An});module.exports=Qe(jn);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 $=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 be(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 Ie(n){return typeof n=="undefined"}function an(n){return!D(n)}function D(n){return Ie(n)||n===null}function V(n){return typeof n=="function"}function dn(n){return be(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 d=o[s],a=i[s],u=t(d,a,s,o,i);u!==void 0?o[s]=u:Ae(a)&&Ae(d)?o[s]=r(E({},d),a):Array.isArray(a)&&Array.isArray(d)?o[s]=[...d,...a]:o[s]=a}return o}return r(n,e)}function Ae(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:d=!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=d&&!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 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))}},B=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))}},W=class extends g{constructor(){super(...arguments);this.name="USER_CALLBACK_ERROR"}},Q=class extends p{constructor(){super(...arguments);this.name="INTERNAL_SCHEMA_PARSE_ERROR";this.priority="P0"}},Y=class extends p{constructor(){super(...arguments);this.name="INTERNAL_JS_MODULE_FETCH_ERROR";this.priority="P0"}},q=class extends p{constructor(){super(...arguments);this.name="INTERNAL_JS_MODULE_EVAL_ERROR";this.priority="P0"}},X=class extends p{constructor(){super(...arguments);this.name="INTERNAL_INVOKE_NATIVE_ERROR"}},Z=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))}},ee=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}},ne=class extends p{constructor(){super(...arguments);this.name="INTERNAL_INVOKE_METHOD_ERROR"}},te=class extends p{constructor(){super(...arguments);this.name="INTERNAL_JSCORE_ERROR";this.priority="P0"}},re=class extends p{constructor(){super(...arguments);this.name="INTERNAL_BUFFER_ERROR"}},oe=class extends p{constructor(t,r){super(t);this.message=t;this.name="INTERNAL_CONTEXT_ERROR";this.property=r}},ie=class extends p{constructor(){super(...arguments);this.name="INTERNAL_GLOBAL_JS_ERROR";this.priority="P1"}},se=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}}},ae=class extends p{constructor(){super(...arguments);this.name="INTERNAL_METRIC_REPORT_ERROR"}},de=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 le={log:O("log"),warn:O("warn"),info:O("info"),error:O("error"),debug:O("debug")};Object.assign(globalThis,{logger:le});var ce=Symbol.for("Jolibox.canIUseMap"),fn={};globalThis[ce]||(globalThis[ce]=fn);var gn={get config(){return globalThis[ce]}};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 me=Symbol.for("Jolibox.canIUseMap.native"),xn={};globalThis[me]||(globalThis[me]=xn);var hn={get config(){return globalThis[me]}};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 d=0;d<s;d++){let a=parseInt(o[d],10)||0,u=parseInt(i[d],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 Ne=(l=>(l[l.Other=0]="Other",l[l.Route=1]="Route",l[l.Click=2]="Click",l[l.View=3]="View",l[l.Expose=4]="Expose",l[l.Swipe=5]="Swipe",l[l.Input=6]="Input",l[l.Select=7]="Select",l[l.SwitchOn=8]="SwitchOn",l[l.SwitchOff=9]="SwitchOff",l[l.Submit=10]="Submit",l[l.Scroll=11]="Scroll",l[l.Hide=12]="Hide",l[l.System=1e3]="System",l[l.ErrorTrace=1001]="ErrorTrace",l[l.UserDefined=1002]="UserDefined",l))(Ne||{}),Oe=(i=>(i.MiniGame="mini-game",i.MiniDrama="mini-drama",i.App="app",i.WebSDK="web-sdk",i.AppSDK="app-sdk",i))(Oe||{}),Pe=(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))(Pe||{}),we=["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,we):null,t=n.target?F(n.target,we):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 ue=()=>"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 pe(){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}}pe();var T=typeof window=="undefined",Se=()=>!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")},Le=()=>P.isiOS?"iOS":P.isAndroid?"Android":P.isMac?"Mac":P.isFacebook?"Facebook":"PC",ke="device_id",Me="advertising_id",fe=n=>(window.__joliboxLocalStorage__.getItem(n)||window.__joliboxLocalStorage__.setItem(n,ue()),window.__joliboxLocalStorage__.getItem(n)),Ue=()=>{let e=new URLSearchParams(window.location.search).get("deviceId");return e||fe(ke)},De=()=>{let e=new URLSearchParams(window.location.search).get("advertisingId");return e||fe(Me)},In=n=>n.charAt(0).toUpperCase()+n.slice(1),Ve=()=>{var e;let n=new URLSearchParams(window.location.search);return In((e=n.get("utm_source"))!=null?e:"")||"JoliboxSDK"},An=n=>{if(Se())return window.navigator.userAgent;let e="JoliboxWebSDK",t=Le(),r=navigator.language,o=Ue(),i=De();return`${e} (${Ve()}${t}; UnknownModel; UnknownSystemVersion; ${r}) uuid/${o} adid/${i} version/${n||""}`};function j(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 d=o.slice(-2).join(".");if(d==="jolibox.com"||d==="pico-game.com"||d==="joyslite.com")return`${i}.${d}`}return`${i}.jolibox.com`}function Fe(n){return j("app","stg-app",n)}function Cn(n){return`https://${Fe(n)}`}function wn(n){return`https://${j("api","stg-api",n)}`}function Nn(n){return j("api","stg-api",n)}function je(n){return j("collect","stg-collect",n)}function On(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,H=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 Pn=0,x=class{constructor(e){this.value=e;this.id=Pn++}},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,d,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=(d=this.options)==null?void 0:d.onDidFirstListener)==null||a.call(d,this)),(c=(u=this.options)==null?void 0:u.onDidAddListener)==null||c.call(u,this),this._size++,()=>{var _,A,S,xe;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 he=this._listeners.indexOf(o);he>=0&&(this._listeners.splice(he,1),this._size--,this._size===0&&((xe=(S=this.options)==null?void 0:S.onDidRemoveLastListener)==null||xe.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 d=this.cachedEventQueue.get(e);if(d&&r)for(let u of d)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 H,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={};ve(h,{None:()=>Sn,filter:()=>kn,once:()=>He,toPromise:()=>Ln});var Sn=()=>(console.log("[Jolibox SDK] None Event"),()=>{console.log("[Jolibox SDK] None Event dispose")});function Ln(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 kn(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 ge=Symbol.for("Jolibox.hostEmitter"),Mn=()=>{let n=new b;return globalThis[ge]||(globalThis[ge]={on:n.on.bind(n),off:n.off.bind(n),emit:n.emit.bind(n),once:n.once.bind(n)}),globalThis[ge]},Un=Mn();function ye(n,e){let t=Math.min(n.length,e.length);for(let r=0;r<t;r++)$e(n[r],e[r])}function $e(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 ye(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 Ke=Symbol.for("Jolibox.commands");function Dn(){return typeof globalThis!="undefined"?globalThis[Ke]:void 0}function Vn(n){typeof globalThis!="undefined"&&(globalThis[Ke]=n)}function Fn(n=!1){let e=Dn();if(!n&&e)return e;let t=new y,r=new I,o={registerCommand(i,s,d){t.registerCommand({id:i,handler:s,metadata:d})},executeCommand(i,...s){return r.executeCommand(i,...s)},excuteCommandSync(i,...s){return r.executeCommandThowErr(i,...s)}};return Vn(o),o}
|
package/dist/index.es.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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{d(t.next(a))}catch(u){o(u)}},s=a=>{try{d(t.throw(a))}catch(u){o(u)}},d=a=>a.done?r(a.value):Promise.resolve(a.value).then(i,s);d((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 d=o[s],a=i[s],u=t(d,a,s,o,i);u!==void 0?o[s]=u:Y(a)&&Y(d)?o[s]=r(_({},d),a):Array.isArray(a)&&Array.isArray(d)?o[s]=[...d,...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:d=!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=d&&!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 d=0;d<s;d++){let a=parseInt(o[d],10)||0,u=parseInt(i[d],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=(l=>(l[l.Other=0]="Other",l[l.Route=1]="Route",l[l.Click=2]="Click",l[l.View=3]="View",l[l.Expose=4]="Expose",l[l.Swipe=5]="Swipe",l[l.Input=6]="Input",l[l.Select=7]="Select",l[l.SwitchOn=8]="SwitchOn",l[l.SwitchOff=9]="SwitchOff",l[l.Submit=10]="Submit",l[l.Scroll=11]="Scroll",l[l.Hide=12]="Hide",l[l.System=1e3]="System",l[l.ErrorTrace=1001]="ErrorTrace",l[l.UserDefined=1002]="UserDefined",l))(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 d=o.slice(-2).join(".");if(d==="jolibox.com"||d==="pico-game.com"||d==="joyslite.com")return`${i}.${d}`}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,d,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=(d=this.options)==null?void 0:d.onDidFirstListener)==null||a.call(d,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 d=this.cachedEventQueue.get(e);if(d&&r)for(let u of d)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,d){t.registerCommand({id:i,handler:s,metadata:d})},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};
|
|
1
|
+
var V=Object.defineProperty,Ie=Object.defineProperties,Ae=Object.getOwnPropertyDescriptor,Ce=Object.getOwnPropertyDescriptors;var B=Object.getOwnPropertySymbols;var we=Object.prototype.hasOwnProperty,Ne=Object.prototype.propertyIsEnumerable;var W=(n,e,t)=>e in n?V(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)&&W(n,t,e[t]);if(B)for(var t of B(e))Ne.call(e,t)&&W(n,t,e[t]);return n},N=(n,e)=>Ie(n,Ce(e));var Oe=(n,e)=>{for(var t in e)V(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&&V(e,t,o),o};var P=(n,e,t)=>new Promise((r,o)=>{var i=a=>{try{d(t.next(a))}catch(u){o(u)}},s=a=>{try{d(t.throw(a))}catch(u){o(u)}},d=a=>a.done?r(a.value):Promise.resolve(a.value).then(i,s);d((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 Y(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 Q=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 F(n){return typeof n=="string"}function yn(n){return Array.isArray(n)&&n.every(e=>F(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!j(n)}function j(n){return Se(n)||n===null}function H(n){return typeof n=="function"}function vn(n){return Pe(n)&&H(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 d=o[s],a=i[s],u=t(d,a,s,o,i);u!==void 0?o[s]=u:q(a)&&q(d)?o[s]=r(_({},d),a):Array.isArray(a)&&Array.isArray(d)?o[s]=[...d,...a]:o[s]=a}return o}return r(n,e)}function q(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:d=!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=d&&!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"}},X=class extends g{constructor(){super(...arguments);this.name="USER_VALIDATE_ERROR"}},Z=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))}},ee=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))}},ne=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))}},te=class extends g{constructor(){super(...arguments);this.name="USER_CALLBACK_ERROR"}},re=class extends p{constructor(){super(...arguments);this.name="INTERNAL_SCHEMA_PARSE_ERROR";this.priority="P0"}},oe=class extends p{constructor(){super(...arguments);this.name="INTERNAL_JS_MODULE_FETCH_ERROR";this.priority="P0"}},ie=class extends p{constructor(){super(...arguments);this.name="INTERNAL_JS_MODULE_EVAL_ERROR";this.priority="P0"}},se=class extends p{constructor(){super(...arguments);this.name="INTERNAL_INVOKE_NATIVE_ERROR"}},ae=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))}},de=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}},le=class extends p{constructor(){super(...arguments);this.name="INTERNAL_INVOKE_METHOD_ERROR"}},ce=class extends p{constructor(){super(...arguments);this.name="INTERNAL_JSCORE_ERROR";this.priority="P0"}},me=class extends p{constructor(){super(...arguments);this.name="INTERNAL_BUFFER_ERROR"}},ue=class extends p{constructor(t,r){super(t);this.message=t;this.name="INTERNAL_CONTEXT_ERROR";this.property=r}},pe=class extends p{constructor(){super(...arguments);this.name="INTERNAL_GLOBAL_JS_ERROR";this.priority="P1"}},fe=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}}},ge=class extends p{constructor(){super(...arguments);this.name="INTERNAL_METRIC_REPORT_ERROR"}},ye=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 xe={log:A("log"),warn:A("warn"),info:A("info"),error:A("error"),debug:A("debug")};Object.assign(globalThis,{logger:xe});var $=Symbol.for("Jolibox.canIUseMap"),Me={};globalThis[$]||(globalThis[$]=Me);var Qn={get config(){return globalThis[$]}};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 d=0;d<s;d++){let a=parseInt(o[d],10)||0,u=parseInt(i[d],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=(l=>(l[l.Other=0]="Other",l[l.Route=1]="Route",l[l.Click=2]="Click",l[l.View=3]="View",l[l.Expose=4]="Expose",l[l.Swipe=5]="Swipe",l[l.Input=6]="Input",l[l.Select=7]="Select",l[l.SwitchOn=8]="SwitchOn",l[l.SwitchOff=9]="SwitchOff",l[l.Submit=10]="Submit",l[l.Scroll=11]="Scroll",l[l.Hide=12]="Hide",l[l.System=1e3]="System",l[l.ErrorTrace=1001]="ErrorTrace",l[l.UserDefined=1002]="UserDefined",l))(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||{}),he=["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 $e(n){let e=n.location?k(n.location,he):null,t=n.target?k(n.target,he):null;return k(N(_({},n),{location:e,target:t}),je)}function rt(n){let e=n.events.map(r=>$e(r)),t=k(n.device,He);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)}),at=n=>/^[\da-f]{8}-[\da-f]{4}-4[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i.test(n);function Ee(){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}}Ee();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",Re=n=>(window.__joliboxLocalStorage__.getItem(n)||window.__joliboxLocalStorage__.setItem(n,_e()),window.__joliboxLocalStorage__.getItem(n)),Be=()=>{let e=new URLSearchParams(window.location.search).get("deviceId");return e||Re(Je)},We=()=>{let e=new URLSearchParams(window.location.search).get("advertisingId");return e||Re(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(Ke())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 U(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 d=o.slice(-2).join(".");if(d==="jolibox.com"||d==="pico-game.com"||d==="joyslite.com")return`${i}.${d}`}return`${i}.jolibox.com`}function qe(n){return U("app","stg-app",n)}function xt(n){return`https://${qe(n)}`}function ht(n){return`https://${U("api","stg-api",n)}`}function _t(n){return U("api","stg-api",n)}function Xe(n){return U("collect","stg-collect",n)}function Et(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,D=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,d,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=(d=this.options)==null?void 0:d.onDidFirstListener)==null||a.call(d,this)),(c=(u=this.options)==null?void 0:u.onDidAddListener)==null||c.call(u,this),this._size++,()=>{var h,b,w,J;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 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}},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 d=this.cachedEventQueue.get(e);if(d&&r)for(let u of d)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 D,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 G=Symbol.for("Jolibox.hostEmitter"),rn=()=>{let n=new C;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]},Yt=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(F(e)){if(typeof n!==e)throw new Error(`argument does not match constraint: typeof ${e}`)}else if(H(e)){try{if(n instanceof e)return}catch(t){}if(!j(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=Y(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 Ir(n=!1){let e=sn();if(!n&&e)return e;let t=new y,r=new v,o={registerCommand(i,s,d){t.registerCommand({id:i,handler:s,metadata:d})},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,fe as APIError,I as BaseError,Je as DEVICE_ID,Q as Deferred,Fe as EPlatform,Ve as EProject,C as EventEmitter,De as EventType,T as EventUtils,de as InternalApplyNativeError,me as InternalBufferError,ue as InternalContextError,p as InternalError,pe as InternalGlobalJSError,le as InternalInvokeMethodError,se as InternalInvokeNativeError,ce as InternalJSCoreNotFoundError,ie as InternalJSModuleEvalError,oe as InternalJSModuleFetchError,ge as InternalMetricReportError,ae as InternalPaymentError,ye as InternalReporterError,re as InternalSchemaParseError,Le as LoadScriptCode,S as Singleton,L as UserCustomError,g as UserError,ee as UserFetchError,te as UserFunctionEvalError,Z as UserGlobalError,ne as UserPaymentError,X as UserValidateError,Qn as canIUseConfig,qn as canIUseConfigNative,et as compareVersion,Ir as createCommands,un as createRunTaskQueue,Ln as debounce,Yn as get,We as getAdvertisingId,qe as getApiDomain,xt as getApiHost,Xe as getCollectDomain,Et as getCollectHost,Be as getDeviceId,ht as getH5ApiHost,_t as getH5Domain,Ee as getOriginalLocalStorage,Ge as getPlatform,Re as getStorage,Ye as getUtmSource,Yt as hostEmitter,hn as isArray,Rn as isBoolean,Tn as isDefined,H as isFunction,En as isIterable,Ke as isNative,_n as isNumber,Pe as isObject,vn as isPromiseLike,F as isString,yn as isStringArray,xn as isTypedArray,Se as isUndefined,j as isUndefinedOrNull,at as isValidUUIDV4,xe as logger,Nn as mergeArray,wn as mergeWith,mn as microTask,M as platform,cn as promisifyAPI,rt as serializeEventPackage,ln as sleep,Y as timeout,_e as uuidv4,on as validateConstraint,ve as validateConstraints,jn as wrapUserFunction,ft as xUserAgent};
|
package/dist/utils/host.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export declare function getApiDomain(staging?: boolean): string;
|
|
2
2
|
export declare function getApiHost(staging?: boolean): string;
|
|
3
|
+
export declare function getH5ApiHost(staging?: boolean): string;
|
|
4
|
+
export declare function getH5Domain(staging?: boolean): string;
|
|
3
5
|
export declare function getCollectDomain(staging?: boolean): string;
|
|
4
6
|
export declare function getCollectHost(staging?: boolean): string;
|
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.2.
|
|
4
|
+
"version": "1.2.5",
|
|
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.2.
|
|
14
|
+
"@jolibox/types": "1.2.5"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"typescript": "5.7.3",
|