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