@jolibox/common 1.1.4-beta.8 → 1.1.4

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.
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.cjs.js CHANGED
@@ -1 +1 @@
1
- "use strict";var v=Object.defineProperty;var Z=Object.getOwnPropertyDescriptor;var me=Object.getOwnPropertyNames;var le=Object.prototype.hasOwnProperty;var ee=(n,e)=>{for(var r in e)v(n,r,{get:e[r],enumerable:!0})},ue=(n,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of me(e))!le.call(n,o)&&o!==r&&v(n,o,{get:()=>e[o],enumerable:!(t=Z(e,o))||t.enumerable});return n};var ce=n=>ue(v({},"__esModule",{value:!0}),n),C=(n,e,r,t)=>{for(var o=t>1?void 0:t?Z(e,r):e,i=n.length-1,s;i>=0;i--)(s=n[i])&&(o=(t?s(e,r,o):s(o))||o);return t&&o&&v(e,r,o),o};var je={};ee(je,{APIError:()=>G,BaseError:()=>E,Deferred:()=>P,EventEmitter:()=>T,EventUtils:()=>R,InternalApplyNativeError:()=>H,InternalBufferError:()=>J,InternalContextError:()=>z,InternalError:()=>m,InternalInvokeMethodError:()=>j,InternalInvokeNativeError:()=>V,InternalJSCoreNotFoundError:()=>K,InternalJSModuleEvalError:()=>F,InternalJSModuleFetchError:()=>D,InternalMetricReportError:()=>B,InternalReporterError:()=>W,InternalSchemaParseError:()=>S,LoadScriptCode:()=>oe,Singleton:()=>h,UserCustomError:()=>g,UserError:()=>p,UserFetchError:()=>M,UserFunctionEvalError:()=>U,UserGlobalError:()=>L,UserValidateError:()=>k,canIUseConfig:()=>we,compareVersion:()=>Le,createCommands:()=>He,createRunTaskQueue:()=>ye,debounce:()=>Ne,get:()=>ke,hostEmitter:()=>Ve,isArray:()=>_e,isBoolean:()=>xe,isDefined:()=>ve,isFunction:()=>N,isIterable:()=>ge,isNumber:()=>he,isObject:()=>ne,isPromiseLike:()=>Ce,isString:()=>I,isStringArray:()=>Te,isTypedArray:()=>Re,isUndefined:()=>te,isUndefinedOrNull:()=>b,logger:()=>$,mergeArray:()=>be,mergeWith:()=>Ie,microTask:()=>Ee,promisifyAPI:()=>fe,sleep:()=>pe,timeout:()=>w,validateConstraint:()=>ae,validateConstraints:()=>X,wrapUserFunction:()=>Oe});module.exports=ce(je);function w(n){return new Promise(e=>{setTimeout(()=>{e()},n)})}function pe(n){return new Promise(e=>setTimeout(e,n))}function fe(n){return e=>new Promise((r,t)=>{n({...e,success:r,fail(o){let i=new Error(o.errMsg);t(i)}})})}function Ee(n){if(n)Promise.resolve().then(n);else return Promise.resolve()}var P=class{constructor(){this.state="pending";this.promise=new Promise((e,r)=>{this.resolve=t=>{this.state==="pending"&&(this.state="fulfilled",e(t))},this.reject=t=>{this.state==="pending"&&(this.state="rejected",r(t))}})}};function ye(){let n=[],e=!1,r=async()=>{let t=n.shift();if(t){e=!0;try{await t()}finally{e=!1,r()}}};return t=>{n.push(t),e||r()}}function I(n){return typeof n=="string"}function Te(n){return Array.isArray(n)&&n.every(e=>I(e))}function ne(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)&&!(n instanceof RegExp)&&!(n instanceof Date)}function Re(n){let e=Object.getPrototypeOf(Uint8Array);return typeof n=="object"&&n instanceof e}function _e(n){return typeof n=="object"&&Array.isArray(n)}function he(n){return typeof n=="number"&&!isNaN(n)}function ge(n){return!!n&&typeof n[Symbol.iterator]=="function"}function xe(n){return n===!0||n===!1}function te(n){return typeof n>"u"}function ve(n){return!b(n)}function b(n){return te(n)||n===null}function N(n){return typeof n=="function"}function Ce(n){return ne(n)&&N(n.then)}function h(n){let e=n,r=null,t=function(...o){return r||(r=new e(...o)),r};return t.prototype=e.prototype,t}function Ie(n,e,r){if(typeof r!="function")throw new Error("[Jolibox SDK]Customizer must be a function");function t(o,i){for(let s in i)if(Object.prototype.hasOwnProperty.call(i,s)){let l=o[s],a=i[s],c=r(l,a,s,o,i);c!==void 0?o[s]=c:re(a)&&re(l)?o[s]=t({...l},a):Array.isArray(a)&&Array.isArray(l)?o[s]=[...l,...a]:o[s]=a}return o}return t(n,e)}function re(n){return n&&typeof n=="object"&&n.constructor===Object}function be(n,e){if(Array.isArray(n))return n.concat(e)}function Ne(n,e,r={}){let t=null,o,i,s,{leading:l=!1,trailing:a=!0}=r,c=()=>(s=n.apply(i,o),o=void 0,i=void 0,s),O=function(...de){o=de,i=this;let q=l&&!t;if(t&&clearTimeout(t),t=setTimeout(()=>{t=null,a&&!q&&c()},e),q)return c()};return O.cancel=()=>{t&&clearTimeout(t),t=null,o=i=void 0},O.flush=()=>{if(t)return clearTimeout(t),t=null,c()},O}var oe=(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))(oe||{}),E=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}},m=class extends E{constructor(){super(...arguments);this.kind="INTERNAL_ERROR"}},p=class extends E{constructor(){super(...arguments);this.kind="USER_ERROR"}},k=class extends p{constructor(){super(...arguments);this.name="USER_VALIDATE_ERROR"}},L=class extends p{constructor(){super(...arguments);this.name="USER_GLOBAL_ERROR";this.priority="P1"}},g=class extends p{constructor(r,t,o){super(r);this.message=r;this.errNo=t;this.name="USER_CUSTOM_ERROR";this.errMsg=r,o&&(this.extra=Object.assign({},this.extra,o))}},M=class extends p{constructor(r,t,o){super(r);this.message=r;this.errNo=t;this.name="USER_FETCH_ERROR";this.errMsg=r,o&&(this.extra=Object.assign({},this.extra,o))}},U=class extends p{constructor(){super(...arguments);this.name="USER_CALLBACK_ERROR"}},S=class extends m{constructor(){super(...arguments);this.name="INTERNAL_SCHEMA_PARSE_ERROR";this.priority="P0"}},D=class extends m{constructor(){super(...arguments);this.name="INTERNAL_JS_MODULE_FETCH_ERROR";this.priority="P0"}},F=class extends m{constructor(){super(...arguments);this.name="INTERNAL_JS_MODULE_EVAL_ERROR";this.priority="P0"}},V=class extends m{constructor(){super(...arguments);this.name="INTERNAL_INVOKE_NATIVE_ERROR"}},H=class extends m{constructor(r,t,o,i){super(r);this.errNo=t;this.name="INTERNAL_APPLY_NATIVE_ERROR";this.errorType=o,this.errorCode=i}},j=class extends m{constructor(){super(...arguments);this.name="INTERNAL_INVOKE_METHOD_ERROR"}},K=class extends m{constructor(){super(...arguments);this.name="INTERNAL_JSCORE_ERROR";this.priority="P0"}},J=class extends m{constructor(){super(...arguments);this.name="INTERNAL_BUFFER_ERROR"}},z=class extends m{constructor(r,t){super(r);this.message=r;this.name="INTERNAL_CONTEXT_ERROR";this.property=t}},G=class extends E{constructor(r,t,o,i,s){super(r);this.message=r;this.code=t;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}}},B=class extends m{constructor(){super(...arguments);this.name="INTERNAL_METRIC_REPORT_ERROR"}},W=class extends m{constructor(){super(...arguments);this.name="INTERNAL_REPORTER_ERROR"}};function Ae(n,e){return(...r)=>e(n,...r)}function Oe(n){return e=>Ae(e,function(r,...t){if(typeof r=="function")try{return r.apply(this,t)}catch(o){n(new g(`${o}`))}})}function x(n){return(...e)=>{(globalThis.VConsole?.[n]??globalThis.console[n])(...e)}}var $={log:x("log"),warn:x("warn"),info:x("info"),error:x("error"),debug:x("debug")};Object.assign(globalThis,{logger:$});var ie=Symbol.for("Jolibox.canIUseMap"),Pe={};globalThis[ie]=Pe;var we={get config(){return globalThis[ie]}};function ke(n,e,r){let t=n;for(let o of e)if(t&&typeof t=="object")t=t[o];else return r;return t===void 0?r:t}function Le(n,e,r){let t=0;if(n!==e){let o=n.split("."),i=e.split("."),s=Math.max(o.length,i.length);for(let l=0;l<s;l++){let a=parseInt(o[l],10)||0,c=parseInt(i[l],10)||0;if(a>c){t=1;break}else if(a<c){t=-1;break}}}if(!r)return t;switch(r){case">":return t>0;case"<":return t<0;case"=":return t===0;case">=":return t>=0;case"<=":return t<=0;default:return!1}}var d=class n{static{this.Undefined=new n(void 0)}constructor(e){this.element=e,this.next=n.Undefined,this.prev=n.Undefined}},A=class{constructor(){this._first=d.Undefined;this._last=d.Undefined;this._size=0}get size(){return this._size}isEmpty(){return this._first===d.Undefined}clear(){let e=this._first;for(;e!==d.Undefined;){let r=e.next;e.prev=d.Undefined,e.next=d.Undefined,e=r}this._first=d.Undefined,this._last=d.Undefined,this._size=0}unshift(e){return this._insert(e,!1)}push(e){return this._insert(e,!0)}_insert(e,r){let t=new d(e);if(this._first===d.Undefined)this._first=t,this._last=t;else if(r){let i=this._last;this._last=t,t.prev=i,i.next=t}else{let i=this._first;this._first=t,t.next=i,i.prev=t}this._size+=1;let o=!1;return()=>{o||(o=!0,this._remove(t))}}shift(){if(this._first!==d.Undefined){let e=this._first.element;return this._remove(this._first),e}}pop(){if(this._last!==d.Undefined){let e=this._last.element;return this._remove(this._last),e}}_remove(e){if(e.prev!==d.Undefined&&e.next!==d.Undefined){let r=e.prev;r.next=e.next,e.next.prev=r}else e.prev===d.Undefined&&e.next===d.Undefined?(this._first=d.Undefined,this._last=d.Undefined):e.next===d.Undefined?(this._last=this._last.prev,this._last.next=d.Undefined):e.prev===d.Undefined&&(this._first=this._first.next,this._first.prev=d.Undefined);this._size-=1}*[Symbol.iterator](){let e=this._first;for(;e!==d.Undefined;)yield e.element,e=e.next}};var Me=0,y=class{constructor(e){this.value=e;this.id=Me++}},u=class{constructor(e){this.options=e;this._size=0}dispose(e){this._disposed||(this._disposed=!0,this._listeners&&(e?(this._listeners instanceof y&&(this._listeners=[this._listeners]),this._listeners=this._listeners.filter(r=>r?.value===e)):(this._listeners=void 0,this._size=0)),this.options?.onDidRemoveLastListener?.())}get event(){return this._event??=(e,r)=>{if(this._disposed)return()=>{console.info("[Jolibox SDK] Emitter is _disposed")};r&&(e=e.bind(r));let t=new y(e);this._listeners?this._listeners instanceof y?this._listeners=[this._listeners,t]:this._listeners.push(t):(this.options?.onWillAddFirstListener?.(this),this._listeners=t,this.options?.onDidFirstListener?.(this)),this.options?.onDidAddListener?.(this),this._size++},this._event}_deliver(e,r){if(!e)return;let t=this.options?.onListenerError||Error.constructor;if(!t){e.value(r);return}try{e.value(r)}catch(o){t(o)}}fire(e){this._listeners&&(this._listeners instanceof y?this._deliver(this._listeners,e):this._listeners.forEach(r=>this._deliver(r,e)))}hasListeners(){return this._size>0}},T=class{constructor(){this.listeners=new Map;this.listerHandlerMap=new WeakMap;this.cachedEventQueue=new Map}on(e,r){let t=this.listeners.get(e)??new u,o=s=>r(...s.args);this.listerHandlerMap.set(r,o),t.event(o),this.listeners.set(e,t);let i=this.cachedEventQueue.get(e);if(i)for(;i.size>0;)t.fire({event:e,...i.shift()})}off(e,r){let t=this.listeners.get(e);if(t){let o=this.listerHandlerMap.get(r);t.dispose(o)}}emit(e,...r){let t=this.listeners.get(e);if(t)t.fire({event:e,args:r});else{let o=this.cachedEventQueue.get(e);o||(o=new A,this.cachedEventQueue.set(e,o)),o.push({args:r})}}};var R={};ee(R,{None:()=>Ue,filter:()=>De,once:()=>se,toPromise:()=>Se});var Ue=()=>{console.log("[Jolibox SDK] None Event")};function Se(n){return new Promise(e=>se(n)(e))}function se(n){return(e,r=null)=>{let t=!1;return n(i=>{if(!t)return t=!0,e.call(r,i)},null)}}function De(n,e){return(t=>{let o,i={onWillAddFirstListener(){o=t(s.fire,s)}},s=new u(i);return s.event})((t,o=null)=>n(i=>e(i)&&t.call(o,i),null))}var Q=Symbol.for("Jolibox.hostEmitter"),Fe=()=>{let n=new T;return globalThis[Q]||(globalThis[Q]={on:n.on.bind(n),off:n.off.bind(n),emit:n.emit.bind(n)}),globalThis[Q]},Ve=Fe();function X(n,e){let r=Math.min(n.length,e.length);for(let t=0;t<r;t++)ae(n[t],e[t])}function ae(n,e){if(I(e)){if(typeof n!==e)throw new Error(`argument does not match constraint: typeof ${e}`)}else if(N(e)){try{if(n instanceof e)return}catch{}if(!b(n)&&n.constructor===e||e.length===1&&e.call(void 0,n)===!0)return;throw new Error("[Jolibox SDK]argument does not match one of these constraints: arg instanceof constraint, arg.constructor === constraint, nor constraint(arg) === true")}}var f=class{constructor(){this._commands=new Map;this._onDidRegisterCommand=new u;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 X(s,o),i(...s)}}let{id:r}=e;this._commands.get(r)&&console.info(`[Jolibox SDK] duplicated command is registered ${r}`),this._commands.set(r,e),this._onDidRegisterCommand.fire(r)}getCommand(e){return this._commands.get(e)}getCommands(){let e=new Map;for(let r of this._commands.keys()){let t=this.getCommand(r);t&&e.set(r,t)}return e}};f=C([h],f);var _=class{constructor(){this._onWillExecuteCommand=new u;this.onWillExecuteCommand=this._onWillExecuteCommand.event;this._onDidExecuteCommand=new u;this.onDidExecuteCommand=this._onDidExecuteCommand.event;this.registry=new f;this._starActivation=null}_activateStar(){return this._starActivation||(this._starActivation=w(3e4)),this._starActivation}async executeCommand(e,...r){return this.registry.getCommand(e)?this._tryExecuteCommand(e,r):(await Promise.all([Promise.race([this._activateStar(),R.toPromise(R.filter(this.registry.onDidRegisterCommand,o=>o===e))])]),this._tryExecuteCommand(e,r))}executeCommandThowErr(e,...r){if(!!!this.registry.getCommand(e))throw new Error(`command '${e}' not found`);let o=this.registry.getCommand(e);this._onWillExecuteCommand.fire({commandId:e,args:r});let i=this.invokeFunction(o.handler,...r);return this._onDidExecuteCommand.fire({commandId:e,args:r}),i}_tryExecuteCommand(e,r){let t=this.registry.getCommand(e);if(!t)return Promise.reject(new Error(`command '${e}' not found`));try{this._onWillExecuteCommand.fire({commandId:e,args:r});let o=this.invokeFunction(t.handler,...r);return this._onDidExecuteCommand.fire({commandId:e,args:r}),Promise.resolve(o)}catch(o){return Promise.reject(o)}}invokeFunction(e,...r){let t=!1;try{return e(...r)}finally{t=!0}}};_=C([h],_);var Y=Symbol.for("Jolibox.commands");function He(){if(globalThis[Y])return globalThis[Y];let n=new f,e=new _,r={registerCommand(t,o,i){n.registerCommand({id:t,handler:o,metadata:i})},executeCommand(t,...o){return e.executeCommand(t,...o)},excuteCommandSync(t,...o){return e.executeCommandThowErr(t,...o)}};return globalThis[Y]=r,r}
1
+ "use strict";var A=Object.defineProperty;var oe=Object.getOwnPropertyDescriptor;var Ie=Object.getOwnPropertyNames;var Ae=Object.prototype.hasOwnProperty;var ie=(n,e)=>{for(var r in e)A(n,r,{get:e[r],enumerable:!0})},Ce=(n,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Ie(e))!Ae.call(n,o)&&o!==r&&A(n,o,{get:()=>e[o],enumerable:!(t=oe(e,o))||t.enumerable});return n};var be=n=>Ce(A({},"__esModule",{value:!0}),n),C=(n,e,r,t)=>{for(var o=t>1?void 0:t?oe(e,r):e,i=n.length-1,s;i>=0;i--)(s=n[i])&&(o=(t?s(e,r,o):s(o))||o);return t&&o&&A(e,r,o),o};var mn={};ie(mn,{ADVERTISING_ID:()=>Te,APIError:()=>W,BaseError:()=>g,DEVICE_ID:()=>ge,Deferred:()=>k,EPlatform:()=>fe,EProject:()=>pe,EventEmitter:()=>E,EventType:()=>ue,EventUtils:()=>x,InternalApplyNativeError:()=>j,InternalBufferError:()=>$,InternalContextError:()=>z,InternalError:()=>m,InternalGlobalJSError:()=>B,InternalInvokeMethodError:()=>G,InternalInvokeNativeError:()=>K,InternalJSCoreNotFoundError:()=>J,InternalJSModuleEvalError:()=>H,InternalJSModuleFetchError:()=>F,InternalMetricReportError:()=>Q,InternalReporterError:()=>X,InternalSchemaParseError:()=>V,LoadScriptCode:()=>le,Singleton:()=>_,UserCustomError:()=>h,UserError:()=>f,UserFetchError:()=>S,UserFunctionEvalError:()=>D,UserGlobalError:()=>L,UserValidateError:()=>U,canIUseConfig:()=>ze,compareVersion:()=>We,createCommands:()=>ln,createRunTaskQueue:()=>Pe,debounce:()=>je,get:()=>Be,getAdvertisingId:()=>xe,getDeviceId:()=>Ee,getPlatform:()=>ye,getStorage:()=>Z,getUtmSource:()=>Re,hostEmitter:()=>dn,isArray:()=>Ue,isBoolean:()=>De,isDefined:()=>Ve,isFunction:()=>O,isIterable:()=>Se,isNumber:()=>Le,isObject:()=>se,isPromiseLike:()=>Fe,isString:()=>b,isStringArray:()=>ke,isTypedArray:()=>Me,isUndefined:()=>ae,isUndefinedOrNull:()=>N,isValidUUIDV4:()=>Ze,logger:()=>Y,mergeArray:()=>Ke,mergeWith:()=>He,microTask:()=>we,platform:()=>I,promisifyAPI:()=>Oe,serializeEventPackage:()=>qe,sleep:()=>Ne,timeout:()=>M,uuidv4:()=>q,validateConstraint:()=>he,validateConstraints:()=>ne,wrapUserFunction:()=>Je,xUserAgent:()=>nn});module.exports=be(mn);function M(n){return new Promise(e=>{setTimeout(()=>{e()},n)})}function Ne(n){return new Promise(e=>setTimeout(e,n))}function Oe(n){return e=>new Promise((r,t)=>{n({...e,success:r,fail(o){let i=new Error(o.errMsg);t(i)}})})}function we(n){if(n)Promise.resolve().then(n);else return Promise.resolve()}var k=class{constructor(){this.state="pending";this.promise=new Promise((e,r)=>{this.resolve=t=>{this.state==="pending"&&(this.state="fulfilled",e(t))},this.reject=t=>{this.state==="pending"&&(this.state="rejected",r(t))}})}};function Pe(){let n=[],e=!1,r=async()=>{let t=n.shift();if(t){e=!0;try{await t()}finally{e=!1,r()}}};return t=>{n.push(t),e||r()}}function b(n){return typeof n=="string"}function ke(n){return Array.isArray(n)&&n.every(e=>b(e))}function se(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)&&!(n instanceof RegExp)&&!(n instanceof Date)}function Me(n){let e=Object.getPrototypeOf(Uint8Array);return typeof n=="object"&&n instanceof e}function Ue(n){return typeof n=="object"&&Array.isArray(n)}function Le(n){return typeof n=="number"&&!isNaN(n)}function Se(n){return!!n&&typeof n[Symbol.iterator]=="function"}function De(n){return n===!0||n===!1}function ae(n){return typeof n>"u"}function Ve(n){return!N(n)}function N(n){return ae(n)||n===null}function O(n){return typeof n=="function"}function Fe(n){return se(n)&&O(n.then)}function _(n){let e=n,r=null,t=function(...o){return r||(r=new e(...o)),r};return t.prototype=e.prototype,t}function He(n,e,r){if(typeof r!="function")throw new Error("[Jolibox SDK]Customizer must be a function");function t(o,i){for(let s in i)if(Object.prototype.hasOwnProperty.call(i,s)){let c=o[s],a=i[s],p=r(c,a,s,o,i);p!==void 0?o[s]=p:de(a)&&de(c)?o[s]=t({...c},a):Array.isArray(a)&&Array.isArray(c)?o[s]=[...c,...a]:o[s]=a}return o}return t(n,e)}function de(n){return n&&typeof n=="object"&&n.constructor===Object}function Ke(n,e){if(Array.isArray(n))return n.concat(e)}function je(n,e,r={}){let t=null,o,i,s,{leading:c=!1,trailing:a=!0}=r,p=()=>(s=n.apply(i,o),o=void 0,i=void 0,s),l=function(...ve){o=ve,i=this;let re=c&&!t;if(t&&clearTimeout(t),t=setTimeout(()=>{t=null,a&&!re&&p()},e),re)return p()};return l.cancel=()=>{t&&clearTimeout(t),t=null,o=i=void 0},l.flush=()=>{if(t)return clearTimeout(t),t=null,p()},l}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||{}),g=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}},m=class extends g{constructor(){super(...arguments);this.kind="INTERNAL_ERROR"}},f=class extends g{constructor(){super(...arguments);this.kind="USER_ERROR"}},U=class extends f{constructor(){super(...arguments);this.name="USER_VALIDATE_ERROR"}},L=class extends f{constructor(){super(...arguments);this.name="USER_GLOBAL_ERROR";this.priority="P1"}},h=class extends f{constructor(r,t,o){super(r);this.message=r;this.errNo=t;this.name="USER_CUSTOM_ERROR";this.errMsg=r,o&&(this.extra=Object.assign({},this.extra,o))}},S=class extends f{constructor(r,t,o){super(r);this.message=r;this.errNo=t;this.name="USER_FETCH_ERROR";this.errMsg=r,o&&(this.extra=Object.assign({},this.extra,o))}},D=class extends f{constructor(){super(...arguments);this.name="USER_CALLBACK_ERROR"}},V=class extends m{constructor(){super(...arguments);this.name="INTERNAL_SCHEMA_PARSE_ERROR";this.priority="P0"}},F=class extends m{constructor(){super(...arguments);this.name="INTERNAL_JS_MODULE_FETCH_ERROR";this.priority="P0"}},H=class extends m{constructor(){super(...arguments);this.name="INTERNAL_JS_MODULE_EVAL_ERROR";this.priority="P0"}},K=class extends m{constructor(){super(...arguments);this.name="INTERNAL_INVOKE_NATIVE_ERROR"}},j=class extends m{constructor(r,t,o,i){super(r);this.errNo=t;this.name="INTERNAL_APPLY_NATIVE_ERROR";this.errorType=o,this.errorCode=i}},G=class extends m{constructor(){super(...arguments);this.name="INTERNAL_INVOKE_METHOD_ERROR"}},J=class extends m{constructor(){super(...arguments);this.name="INTERNAL_JSCORE_ERROR";this.priority="P0"}},$=class extends m{constructor(){super(...arguments);this.name="INTERNAL_BUFFER_ERROR"}},z=class extends m{constructor(r,t){super(r);this.message=r;this.name="INTERNAL_CONTEXT_ERROR";this.property=t}},B=class extends m{constructor(){super(...arguments);this.name="INTERNAL_GLOBAL_JS_ERROR";this.priority="P1"}},W=class extends g{constructor(r,t,o,i,s){super(r);this.message=r;this.code=t;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}}},Q=class extends m{constructor(){super(...arguments);this.name="INTERNAL_METRIC_REPORT_ERROR"}},X=class extends m{constructor(){super(...arguments);this.name="INTERNAL_REPORTER_ERROR"}};function Ge(n,e){return(...r)=>e(n,...r)}function Je(n){return e=>Ge(e,function(r,...t){if(typeof r=="function")try{return r.apply(this,t)}catch(o){n(new h(`${o}`))}})}function v(n){return(...e)=>{(globalThis.VConsole?.[n]??globalThis.console[n])(...e)}}var Y={log:v("log"),warn:v("warn"),info:v("info"),error:v("error"),debug:v("debug")};Object.assign(globalThis,{logger:Y});var me=Symbol.for("Jolibox.canIUseMap"),$e={};globalThis[me]=$e;var ze={get config(){return globalThis[me]}};function Be(n,e,r){let t=n;for(let o of e)if(t&&typeof t=="object")t=t[o];else return r;return t===void 0?r:t}function We(n,e,r){let t=0;if(n!==e){let o=n.split("."),i=e.split("."),s=Math.max(o.length,i.length);for(let c=0;c<s;c++){let a=parseInt(o[c],10)||0,p=parseInt(i[c],10)||0;if(a>p){t=1;break}else if(a<p){t=-1;break}}}if(!r)return t;switch(r){case">":return t>0;case"<":return t<0;case"=":return t===0;case">=":return t>=0;case"<=":return t<=0;default:return!1}}var ue=(t=>(t[t.System=1e3]="System",t[t.ErrorTrace=1001]="ErrorTrace",t[t.UserDefined=1002]="UserDefined",t))(ue||{}),pe=(i=>(i.MiniGame="mini-game",i.MiniDrama="mini-drama",i.App="app",i.WebSDK="web-sdk",i.AppSDK="app-sdk",i))(pe||{}),fe=(l=>(l[l.App=0]="App",l[l.H5=1]="H5",l[l.Weapp=2]="Weapp",l[l.Alipay=3]="Alipay",l[l.Gcash=4]="Gcash",l[l.Dana=5]="Dana",l[l.Umma=6]="Umma",l[l.WebSDK=1e3]="WebSDK",l[l.AppSDK=1001]="AppSDK",l[l.Other=9999]="Other",l))(fe||{}),ce=["name","params"],Qe=["name","type","location","target","extra","timestamp","userId"],Xe=["platform","os","appVersion","appId","model","brand","uuid","jsSdkVersion","extra"];function w(n,e){return e.map(r=>{if(r==="params"&&n[r]){let t=n[r];return Object.keys(t).reduce((o,i)=>(o[i]=String(t[i]),o),{})}return n[r]})}function Ye(n){let e=n.location?w(n.location,ce):null,r=n.target?w(n.target,ce):null;return w({...n,location:e,target:r},Qe)}function qe(n){let e=n.events.map(t=>Ye(t)),r=w(n.device,Xe);return[n.protocolVersion,e,r,n.project]}var q=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,n=>{let e=Math.random()*16|0;return(n==="x"?e:e&3|8).toString(16)}),Ze=n=>/^[\da-f]{8}-[\da-f]{4}-4[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i.test(n);var I={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")},ye=()=>I.isiOS?"iOS":I.isAndroid?"Android":I.isMac?"Mac":I.isFacebook?"Facebook":"PC",ge="device_id",Te="advertising_id",Z=n=>(localStorage.getItem(n)||localStorage.setItem(n,q()),localStorage.getItem(n)),Ee=()=>Z(ge),xe=()=>Z(Te),en=n=>n.charAt(0).toUpperCase()+n.slice(1),Re=()=>{let n=new URLSearchParams(window.location.search);return en(n.get("utm_source")??"")||"JoliboxSDK"},nn=n=>{let e="JoliboxWebSDK",r=ye(),t=navigator.language,o=Ee(),i=xe();return`${e} (${Re()}${r}; UnknownModel; UnknownSystemVersion; ${t}) uuid/${o} adid/${i} version/${n||""}`};var d=class n{static{this.Undefined=new n(void 0)}constructor(e){this.element=e,this.next=n.Undefined,this.prev=n.Undefined}},P=class{constructor(){this._first=d.Undefined;this._last=d.Undefined;this._size=0}get size(){return this._size}isEmpty(){return this._first===d.Undefined}clear(){let e=this._first;for(;e!==d.Undefined;){let r=e.next;e.prev=d.Undefined,e.next=d.Undefined,e=r}this._first=d.Undefined,this._last=d.Undefined,this._size=0}unshift(e){return this._insert(e,!1)}push(e){return this._insert(e,!0)}_insert(e,r){let t=new d(e);if(this._first===d.Undefined)this._first=t,this._last=t;else if(r){let i=this._last;this._last=t,t.prev=i,i.next=t}else{let i=this._first;this._first=t,t.next=i,i.prev=t}this._size+=1;let o=!1;return()=>{o||(o=!0,this._remove(t))}}shift(){if(this._first!==d.Undefined){let e=this._first.element;return this._remove(this._first),e}}pop(){if(this._last!==d.Undefined){let e=this._last.element;return this._remove(this._last),e}}_remove(e){if(e.prev!==d.Undefined&&e.next!==d.Undefined){let r=e.prev;r.next=e.next,e.next.prev=r}else e.prev===d.Undefined&&e.next===d.Undefined?(this._first=d.Undefined,this._last=d.Undefined):e.next===d.Undefined?(this._last=this._last.prev,this._last.next=d.Undefined):e.prev===d.Undefined&&(this._first=this._first.next,this._first.prev=d.Undefined);this._size-=1}*[Symbol.iterator](){let e=this._first;for(;e!==d.Undefined;)yield e.element,e=e.next}};var tn=0,T=class{constructor(e){this.value=e;this.id=tn++}},u=class{constructor(e){this.options=e;this._size=0}dispose(e){this._disposed||(this._disposed=!0,this._listeners&&(e?(this._listeners instanceof T&&(this._listeners=[this._listeners]),this._listeners=this._listeners.filter(r=>r?.value===e)):(this._listeners=void 0,this._size=0)),this.options?.onDidRemoveLastListener?.())}get event(){return this._event??=(e,r)=>{if(this._disposed)return()=>{console.info("[Jolibox SDK] Emitter is _disposed")};r&&(e=e.bind(r));let t=new T(e);this._listeners?this._listeners instanceof T?this._listeners=[this._listeners,t]:this._listeners.push(t):(this.options?.onWillAddFirstListener?.(this),this._listeners=t,this.options?.onDidFirstListener?.(this)),this.options?.onDidAddListener?.(this),this._size++},this._event}_deliver(e,r){if(!e)return;let t=this.options?.onListenerError||Error.constructor;if(!t){e.value(r);return}try{e.value(r)}catch(o){t(o)}}fire(e){this._listeners&&(this._listeners instanceof T?this._deliver(this._listeners,e):this._listeners.forEach(r=>this._deliver(r,e)))}hasListeners(){return this._size>0}},E=class{constructor(){this.listeners=new Map;this.listerHandlerMap=new WeakMap;this.cachedEventQueue=new Map}on(e,r){let t=this.listeners.get(e)??new u,o=s=>r(...s.args);this.listerHandlerMap.set(r,o),t.event(o),this.listeners.set(e,t);let i=this.cachedEventQueue.get(e);if(i)for(;i.size>0;)t.fire({event:e,...i.shift()})}off(e,r){let t=this.listeners.get(e);if(t){let o=this.listerHandlerMap.get(r);t.dispose(o)}}emit(e,...r){let t=this.listeners.get(e);if(t)t.fire({event:e,args:r});else{let o=this.cachedEventQueue.get(e);o||(o=new P,this.cachedEventQueue.set(e,o)),o.push({args:r})}}};var x={};ie(x,{None:()=>rn,filter:()=>sn,once:()=>_e,toPromise:()=>on});var rn=()=>{console.log("[Jolibox SDK] None Event")};function on(n){return new Promise(e=>_e(n)(e))}function _e(n){return(e,r=null)=>{let t=!1;return n(i=>{if(!t)return t=!0,e.call(r,i)},null)}}function sn(n,e){return(t=>{let o,i={onWillAddFirstListener(){o=t(s.fire,s)}},s=new u(i);return s.event})((t,o=null)=>n(i=>e(i)&&t.call(o,i),null))}var ee=Symbol.for("Jolibox.hostEmitter"),an=()=>{let n=new E;return globalThis[ee]||(globalThis[ee]={on:n.on.bind(n),off:n.off.bind(n),emit:n.emit.bind(n)}),globalThis[ee]},dn=an();function ne(n,e){let r=Math.min(n.length,e.length);for(let t=0;t<r;t++)he(n[t],e[t])}function he(n,e){if(b(e)){if(typeof n!==e)throw new Error(`argument does not match constraint: typeof ${e}`)}else if(O(e)){try{if(n instanceof e)return}catch{}if(!N(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 u;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 ne(s,o),i(...s)}}let{id:r}=e;this._commands.get(r)&&console.info(`[Jolibox SDK] duplicated command is registered ${r}`),this._commands.set(r,e),this._onDidRegisterCommand.fire(r)}getCommand(e){return this._commands.get(e)}getCommands(){let e=new Map;for(let r of this._commands.keys()){let t=this.getCommand(r);t&&e.set(r,t)}return e}};y=C([_],y);var R=class{constructor(){this._onWillExecuteCommand=new u;this.onWillExecuteCommand=this._onWillExecuteCommand.event;this._onDidExecuteCommand=new u;this.onDidExecuteCommand=this._onDidExecuteCommand.event;this.registry=new y;this._starActivation=null}_activateStar(){return this._starActivation||(this._starActivation=M(3e4)),this._starActivation}async executeCommand(e,...r){return this.registry.getCommand(e)?this._tryExecuteCommand(e,r):(await Promise.all([Promise.race([this._activateStar(),x.toPromise(x.filter(this.registry.onDidRegisterCommand,o=>o===e))])]),this._tryExecuteCommand(e,r))}executeCommandThowErr(e,...r){if(!!!this.registry.getCommand(e))throw new Error(`command '${e}' not found`);let o=this.registry.getCommand(e);this._onWillExecuteCommand.fire({commandId:e,args:r});let i=this.invokeFunction(o.handler,...r);return this._onDidExecuteCommand.fire({commandId:e,args:r}),i}_tryExecuteCommand(e,r){let t=this.registry.getCommand(e);if(!t)return Promise.reject(new Error(`command '${e}' not found`));try{this._onWillExecuteCommand.fire({commandId:e,args:r});let o=this.invokeFunction(t.handler,...r);return this._onDidExecuteCommand.fire({commandId:e,args:r}),Promise.resolve(o)}catch(o){return Promise.reject(o)}}invokeFunction(e,...r){let t=!1;try{return e(...r)}finally{t=!0}}};R=C([_],R);var te=Symbol.for("Jolibox.commands");function ln(){if(globalThis[te])return globalThis[te];let n=new y,e=new R,r={registerCommand(t,o,i){n.registerCommand({id:t,handler:o,metadata:i})},executeCommand(t,...o){return e.executeCommand(t,...o)},excuteCommandSync(t,...o){return e.executeCommandThowErr(t,...o)}};return globalThis[te]=r,r}
package/dist/index.es.js CHANGED
@@ -1 +1 @@
1
- var k=Object.defineProperty;var re=Object.getOwnPropertyDescriptor;var oe=(n,e)=>{for(var r in e)k(n,r,{get:e[r],enumerable:!0})};var g=(n,e,r,t)=>{for(var o=t>1?void 0:t?re(e,r):e,i=n.length-1,s;i>=0;i--)(s=n[i])&&(o=(t?s(e,r,o):s(o))||o);return t&&o&&k(e,r,o),o};function M(n){return new Promise(e=>{setTimeout(()=>{e()},n)})}function Te(n){return new Promise(e=>setTimeout(e,n))}function Re(n){return e=>new Promise((r,t)=>{n({...e,success:r,fail(o){let i=new Error(o.errMsg);t(i)}})})}function _e(n){if(n)Promise.resolve().then(n);else return Promise.resolve()}var L=class{constructor(){this.state="pending";this.promise=new Promise((e,r)=>{this.resolve=t=>{this.state==="pending"&&(this.state="fulfilled",e(t))},this.reject=t=>{this.state==="pending"&&(this.state="rejected",r(t))}})}};function he(){let n=[],e=!1,r=async()=>{let t=n.shift();if(t){e=!0;try{await t()}finally{e=!1,r()}}};return t=>{n.push(t),e||r()}}function b(n){return typeof n=="string"}function xe(n){return Array.isArray(n)&&n.every(e=>b(e))}function ie(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)&&!(n instanceof RegExp)&&!(n instanceof Date)}function ve(n){let e=Object.getPrototypeOf(Uint8Array);return typeof n=="object"&&n instanceof e}function Ce(n){return typeof n=="object"&&Array.isArray(n)}function Ie(n){return typeof n=="number"&&!isNaN(n)}function be(n){return!!n&&typeof n[Symbol.iterator]=="function"}function Ne(n){return n===!0||n===!1}function se(n){return typeof n>"u"}function Ae(n){return!N(n)}function N(n){return se(n)||n===null}function A(n){return typeof n=="function"}function Oe(n){return ie(n)&&A(n.then)}function x(n){let e=n,r=null,t=function(...o){return r||(r=new e(...o)),r};return t.prototype=e.prototype,t}function ke(n,e,r){if(typeof r!="function")throw new Error("[Jolibox SDK]Customizer must be a function");function t(o,i){for(let s in i)if(Object.prototype.hasOwnProperty.call(i,s)){let l=o[s],a=i[s],c=r(l,a,s,o,i);c!==void 0?o[s]=c:U(a)&&U(l)?o[s]=t({...l},a):Array.isArray(a)&&Array.isArray(l)?o[s]=[...l,...a]:o[s]=a}return o}return t(n,e)}function U(n){return n&&typeof n=="object"&&n.constructor===Object}function Le(n,e){if(Array.isArray(n))return n.concat(e)}function Ue(n,e,r={}){let t=null,o,i,s,{leading:l=!1,trailing:a=!0}=r,c=()=>(s=n.apply(i,o),o=void 0,i=void 0,s),I=function(...te){o=te,i=this;let w=l&&!t;if(t&&clearTimeout(t),t=setTimeout(()=>{t=null,a&&!w&&c()},e),w)return c()};return I.cancel=()=>{t&&clearTimeout(t),t=null,o=i=void 0},I.flush=()=>{if(t)return clearTimeout(t),t=null,c()},I}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||{}),T=class extends Error{constructor(e){if(typeof e=="string"){super(e),this.priority="P1";return}super(e.message),this.priority="P1",this.stack=e.stack,this.raw=e}},m=class extends T{constructor(){super(...arguments);this.kind="INTERNAL_ERROR"}},f=class extends T{constructor(){super(...arguments);this.kind="USER_ERROR"}},S=class extends f{constructor(){super(...arguments);this.name="USER_VALIDATE_ERROR"}},D=class extends f{constructor(){super(...arguments);this.name="USER_GLOBAL_ERROR";this.priority="P1"}},v=class extends f{constructor(r,t,o){super(r);this.message=r;this.errNo=t;this.name="USER_CUSTOM_ERROR";this.errMsg=r,o&&(this.extra=Object.assign({},this.extra,o))}},F=class extends f{constructor(r,t,o){super(r);this.message=r;this.errNo=t;this.name="USER_FETCH_ERROR";this.errMsg=r,o&&(this.extra=Object.assign({},this.extra,o))}},V=class extends f{constructor(){super(...arguments);this.name="USER_CALLBACK_ERROR"}},H=class extends m{constructor(){super(...arguments);this.name="INTERNAL_SCHEMA_PARSE_ERROR";this.priority="P0"}},j=class extends m{constructor(){super(...arguments);this.name="INTERNAL_JS_MODULE_FETCH_ERROR";this.priority="P0"}},K=class extends m{constructor(){super(...arguments);this.name="INTERNAL_JS_MODULE_EVAL_ERROR";this.priority="P0"}},J=class extends m{constructor(){super(...arguments);this.name="INTERNAL_INVOKE_NATIVE_ERROR"}},z=class extends m{constructor(r,t,o,i){super(r);this.errNo=t;this.name="INTERNAL_APPLY_NATIVE_ERROR";this.errorType=o,this.errorCode=i}},G=class extends m{constructor(){super(...arguments);this.name="INTERNAL_INVOKE_METHOD_ERROR"}},B=class extends m{constructor(){super(...arguments);this.name="INTERNAL_JSCORE_ERROR";this.priority="P0"}},W=class extends m{constructor(){super(...arguments);this.name="INTERNAL_BUFFER_ERROR"}},$=class extends m{constructor(r,t){super(r);this.message=r;this.name="INTERNAL_CONTEXT_ERROR";this.property=t}},Q=class extends T{constructor(r,t,o,i,s){super(r);this.message=r;this.code=t;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}}},X=class extends m{constructor(){super(...arguments);this.name="INTERNAL_METRIC_REPORT_ERROR"}},Y=class extends m{constructor(){super(...arguments);this.name="INTERNAL_REPORTER_ERROR"}};function de(n,e){return(...r)=>e(n,...r)}function He(n){return e=>de(e,function(r,...t){if(typeof r=="function")try{return r.apply(this,t)}catch(o){n(new v(`${o}`))}})}function R(n){return(...e)=>{(globalThis.VConsole?.[n]??globalThis.console[n])(...e)}}var q={log:R("log"),warn:R("warn"),info:R("info"),error:R("error"),debug:R("debug")};Object.assign(globalThis,{logger:q});var Z=Symbol.for("Jolibox.canIUseMap"),me={};globalThis[Z]=me;var Be={get config(){return globalThis[Z]}};function We(n,e,r){let t=n;for(let o of e)if(t&&typeof t=="object")t=t[o];else return r;return t===void 0?r:t}function Qe(n,e,r){let t=0;if(n!==e){let o=n.split("."),i=e.split("."),s=Math.max(o.length,i.length);for(let l=0;l<s;l++){let a=parseInt(o[l],10)||0,c=parseInt(i[l],10)||0;if(a>c){t=1;break}else if(a<c){t=-1;break}}}if(!r)return t;switch(r){case">":return t>0;case"<":return t<0;case"=":return t===0;case">=":return t>=0;case"<=":return t<=0;default:return!1}}var d=class n{static{this.Undefined=new n(void 0)}constructor(e){this.element=e,this.next=n.Undefined,this.prev=n.Undefined}},C=class{constructor(){this._first=d.Undefined;this._last=d.Undefined;this._size=0}get size(){return this._size}isEmpty(){return this._first===d.Undefined}clear(){let e=this._first;for(;e!==d.Undefined;){let r=e.next;e.prev=d.Undefined,e.next=d.Undefined,e=r}this._first=d.Undefined,this._last=d.Undefined,this._size=0}unshift(e){return this._insert(e,!1)}push(e){return this._insert(e,!0)}_insert(e,r){let t=new d(e);if(this._first===d.Undefined)this._first=t,this._last=t;else if(r){let i=this._last;this._last=t,t.prev=i,i.next=t}else{let i=this._first;this._first=t,t.next=i,i.prev=t}this._size+=1;let o=!1;return()=>{o||(o=!0,this._remove(t))}}shift(){if(this._first!==d.Undefined){let e=this._first.element;return this._remove(this._first),e}}pop(){if(this._last!==d.Undefined){let e=this._last.element;return this._remove(this._last),e}}_remove(e){if(e.prev!==d.Undefined&&e.next!==d.Undefined){let r=e.prev;r.next=e.next,e.next.prev=r}else e.prev===d.Undefined&&e.next===d.Undefined?(this._first=d.Undefined,this._last=d.Undefined):e.next===d.Undefined?(this._last=this._last.prev,this._last.next=d.Undefined):e.prev===d.Undefined&&(this._first=this._first.next,this._first.prev=d.Undefined);this._size-=1}*[Symbol.iterator](){let e=this._first;for(;e!==d.Undefined;)yield e.element,e=e.next}};var le=0,E=class{constructor(e){this.value=e;this.id=le++}},u=class{constructor(e){this.options=e;this._size=0}dispose(e){this._disposed||(this._disposed=!0,this._listeners&&(e?(this._listeners instanceof E&&(this._listeners=[this._listeners]),this._listeners=this._listeners.filter(r=>r?.value===e)):(this._listeners=void 0,this._size=0)),this.options?.onDidRemoveLastListener?.())}get event(){return this._event??=(e,r)=>{if(this._disposed)return()=>{console.info("[Jolibox SDK] Emitter is _disposed")};r&&(e=e.bind(r));let t=new E(e);this._listeners?this._listeners instanceof E?this._listeners=[this._listeners,t]:this._listeners.push(t):(this.options?.onWillAddFirstListener?.(this),this._listeners=t,this.options?.onDidFirstListener?.(this)),this.options?.onDidAddListener?.(this),this._size++},this._event}_deliver(e,r){if(!e)return;let t=this.options?.onListenerError||Error.constructor;if(!t){e.value(r);return}try{e.value(r)}catch(o){t(o)}}fire(e){this._listeners&&(this._listeners instanceof E?this._deliver(this._listeners,e):this._listeners.forEach(r=>this._deliver(r,e)))}hasListeners(){return this._size>0}},_=class{constructor(){this.listeners=new Map;this.listerHandlerMap=new WeakMap;this.cachedEventQueue=new Map}on(e,r){let t=this.listeners.get(e)??new u,o=s=>r(...s.args);this.listerHandlerMap.set(r,o),t.event(o),this.listeners.set(e,t);let i=this.cachedEventQueue.get(e);if(i)for(;i.size>0;)t.fire({event:e,...i.shift()})}off(e,r){let t=this.listeners.get(e);if(t){let o=this.listerHandlerMap.get(r);t.dispose(o)}}emit(e,...r){let t=this.listeners.get(e);if(t)t.fire({event:e,args:r});else{let o=this.cachedEventQueue.get(e);o||(o=new C,this.cachedEventQueue.set(e,o)),o.push({args:r})}}};var h={};oe(h,{None:()=>ue,filter:()=>pe,once:()=>ee,toPromise:()=>ce});var ue=()=>{console.log("[Jolibox SDK] None Event")};function ce(n){return new Promise(e=>ee(n)(e))}function ee(n){return(e,r=null)=>{let t=!1;return n(i=>{if(!t)return t=!0,e.call(r,i)},null)}}function pe(n,e){return(t=>{let o,i={onWillAddFirstListener(){o=t(s.fire,s)}},s=new u(i);return s.event})((t,o=null)=>n(i=>e(i)&&t.call(o,i),null))}var O=Symbol.for("Jolibox.hostEmitter"),fe=()=>{let n=new _;return globalThis[O]||(globalThis[O]={on:n.on.bind(n),off:n.off.bind(n),emit:n.emit.bind(n)}),globalThis[O]},En=fe();function ne(n,e){let r=Math.min(n.length,e.length);for(let t=0;t<r;t++)Ee(n[t],e[t])}function Ee(n,e){if(b(e)){if(typeof n!==e)throw new Error(`argument does not match constraint: typeof ${e}`)}else if(A(e)){try{if(n instanceof e)return}catch{}if(!N(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 p=class{constructor(){this._commands=new Map;this._onDidRegisterCommand=new u;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 ne(s,o),i(...s)}}let{id:r}=e;this._commands.get(r)&&console.info(`[Jolibox SDK] duplicated command is registered ${r}`),this._commands.set(r,e),this._onDidRegisterCommand.fire(r)}getCommand(e){return this._commands.get(e)}getCommands(){let e=new Map;for(let r of this._commands.keys()){let t=this.getCommand(r);t&&e.set(r,t)}return e}};p=g([x],p);var y=class{constructor(){this._onWillExecuteCommand=new u;this.onWillExecuteCommand=this._onWillExecuteCommand.event;this._onDidExecuteCommand=new u;this.onDidExecuteCommand=this._onDidExecuteCommand.event;this.registry=new p;this._starActivation=null}_activateStar(){return this._starActivation||(this._starActivation=M(3e4)),this._starActivation}async executeCommand(e,...r){return this.registry.getCommand(e)?this._tryExecuteCommand(e,r):(await Promise.all([Promise.race([this._activateStar(),h.toPromise(h.filter(this.registry.onDidRegisterCommand,o=>o===e))])]),this._tryExecuteCommand(e,r))}executeCommandThowErr(e,...r){if(!!!this.registry.getCommand(e))throw new Error(`command '${e}' not found`);let o=this.registry.getCommand(e);this._onWillExecuteCommand.fire({commandId:e,args:r});let i=this.invokeFunction(o.handler,...r);return this._onDidExecuteCommand.fire({commandId:e,args:r}),i}_tryExecuteCommand(e,r){let t=this.registry.getCommand(e);if(!t)return Promise.reject(new Error(`command '${e}' not found`));try{this._onWillExecuteCommand.fire({commandId:e,args:r});let o=this.invokeFunction(t.handler,...r);return this._onDidExecuteCommand.fire({commandId:e,args:r}),Promise.resolve(o)}catch(o){return Promise.reject(o)}}invokeFunction(e,...r){let t=!1;try{return e(...r)}finally{t=!0}}};y=g([x],y);var P=Symbol.for("Jolibox.commands");function Vn(){if(globalThis[P])return globalThis[P];let n=new p,e=new y,r={registerCommand(t,o,i){n.registerCommand({id:t,handler:o,metadata:i})},executeCommand(t,...o){return e.executeCommand(t,...o)},excuteCommandSync(t,...o){return e.executeCommandThowErr(t,...o)}};return globalThis[P]=r,r}export{Q as APIError,T as BaseError,L as Deferred,_ as EventEmitter,h as EventUtils,z as InternalApplyNativeError,W as InternalBufferError,$ as InternalContextError,m as InternalError,G as InternalInvokeMethodError,J as InternalInvokeNativeError,B as InternalJSCoreNotFoundError,K as InternalJSModuleEvalError,j as InternalJSModuleFetchError,X as InternalMetricReportError,Y as InternalReporterError,H as InternalSchemaParseError,ae as LoadScriptCode,x as Singleton,v as UserCustomError,f as UserError,F as UserFetchError,V as UserFunctionEvalError,D as UserGlobalError,S as UserValidateError,Be as canIUseConfig,Qe as compareVersion,Vn as createCommands,he as createRunTaskQueue,Ue as debounce,We as get,En as hostEmitter,Ce as isArray,Ne as isBoolean,Ae as isDefined,A as isFunction,be as isIterable,Ie as isNumber,ie as isObject,Oe as isPromiseLike,b as isString,xe as isStringArray,ve as isTypedArray,se as isUndefined,N as isUndefinedOrNull,q as logger,Le as mergeArray,ke as mergeWith,_e as microTask,Re as promisifyAPI,Te as sleep,M as timeout,Ee as validateConstraint,ne as validateConstraints,He as wrapUserFunction};
1
+ var U=Object.defineProperty;var le=Object.getOwnPropertyDescriptor;var me=(n,e)=>{for(var r in e)U(n,r,{get:e[r],enumerable:!0})};var h=(n,e,r,t)=>{for(var o=t>1?void 0:t?le(e,r):e,i=n.length-1,s;i>=0;i--)(s=n[i])&&(o=(t?s(e,r,o):s(o))||o);return t&&o&&U(e,r,o),o};function S(n){return new Promise(e=>{setTimeout(()=>{e()},n)})}function Se(n){return new Promise(e=>setTimeout(e,n))}function De(n){return e=>new Promise((r,t)=>{n({...e,success:r,fail(o){let i=new Error(o.errMsg);t(i)}})})}function Ve(n){if(n)Promise.resolve().then(n);else return Promise.resolve()}var L=class{constructor(){this.state="pending";this.promise=new Promise((e,r)=>{this.resolve=t=>{this.state==="pending"&&(this.state="fulfilled",e(t))},this.reject=t=>{this.state==="pending"&&(this.state="rejected",r(t))}})}};function Fe(){let n=[],e=!1,r=async()=>{let t=n.shift();if(t){e=!0;try{await t()}finally{e=!1,r()}}};return t=>{n.push(t),e||r()}}function N(n){return typeof n=="string"}function Ke(n){return Array.isArray(n)&&n.every(e=>N(e))}function ce(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)&&!(n instanceof RegExp)&&!(n instanceof Date)}function je(n){let e=Object.getPrototypeOf(Uint8Array);return typeof n=="object"&&n instanceof e}function Ge(n){return typeof n=="object"&&Array.isArray(n)}function Je(n){return typeof n=="number"&&!isNaN(n)}function $e(n){return!!n&&typeof n[Symbol.iterator]=="function"}function ze(n){return n===!0||n===!1}function ue(n){return typeof n>"u"}function Be(n){return!O(n)}function O(n){return ue(n)||n===null}function w(n){return typeof n=="function"}function We(n){return ce(n)&&w(n.then)}function v(n){let e=n,r=null,t=function(...o){return r||(r=new e(...o)),r};return t.prototype=e.prototype,t}function Ye(n,e,r){if(typeof r!="function")throw new Error("[Jolibox SDK]Customizer must be a function");function t(o,i){for(let s in i)if(Object.prototype.hasOwnProperty.call(i,s)){let c=o[s],a=i[s],p=r(c,a,s,o,i);p!==void 0?o[s]=p:D(a)&&D(c)?o[s]=t({...c},a):Array.isArray(a)&&Array.isArray(c)?o[s]=[...c,...a]:o[s]=a}return o}return t(n,e)}function D(n){return n&&typeof n=="object"&&n.constructor===Object}function qe(n,e){if(Array.isArray(n))return n.concat(e)}function en(n,e,r={}){let t=null,o,i,s,{leading:c=!1,trailing:a=!0}=r,p=()=>(s=n.apply(i,o),o=void 0,i=void 0,s),l=function(...de){o=de,i=this;let M=c&&!t;if(t&&clearTimeout(t),t=setTimeout(()=>{t=null,a&&!M&&p()},e),M)return p()};return l.cancel=()=>{t&&clearTimeout(t),t=null,o=i=void 0},l.flush=()=>{if(t)return clearTimeout(t),t=null,p()},l}var pe=(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))(pe||{}),E=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}},m=class extends E{constructor(){super(...arguments);this.kind="INTERNAL_ERROR"}},y=class extends E{constructor(){super(...arguments);this.kind="USER_ERROR"}},V=class extends y{constructor(){super(...arguments);this.name="USER_VALIDATE_ERROR"}},F=class extends y{constructor(){super(...arguments);this.name="USER_GLOBAL_ERROR";this.priority="P1"}},I=class extends y{constructor(r,t,o){super(r);this.message=r;this.errNo=t;this.name="USER_CUSTOM_ERROR";this.errMsg=r,o&&(this.extra=Object.assign({},this.extra,o))}},H=class extends y{constructor(r,t,o){super(r);this.message=r;this.errNo=t;this.name="USER_FETCH_ERROR";this.errMsg=r,o&&(this.extra=Object.assign({},this.extra,o))}},K=class extends y{constructor(){super(...arguments);this.name="USER_CALLBACK_ERROR"}},j=class extends m{constructor(){super(...arguments);this.name="INTERNAL_SCHEMA_PARSE_ERROR";this.priority="P0"}},G=class extends m{constructor(){super(...arguments);this.name="INTERNAL_JS_MODULE_FETCH_ERROR";this.priority="P0"}},J=class extends m{constructor(){super(...arguments);this.name="INTERNAL_JS_MODULE_EVAL_ERROR";this.priority="P0"}},$=class extends m{constructor(){super(...arguments);this.name="INTERNAL_INVOKE_NATIVE_ERROR"}},z=class extends m{constructor(r,t,o,i){super(r);this.errNo=t;this.name="INTERNAL_APPLY_NATIVE_ERROR";this.errorType=o,this.errorCode=i}},B=class extends m{constructor(){super(...arguments);this.name="INTERNAL_INVOKE_METHOD_ERROR"}},W=class extends m{constructor(){super(...arguments);this.name="INTERNAL_JSCORE_ERROR";this.priority="P0"}},Q=class extends m{constructor(){super(...arguments);this.name="INTERNAL_BUFFER_ERROR"}},X=class extends m{constructor(r,t){super(r);this.message=r;this.name="INTERNAL_CONTEXT_ERROR";this.property=t}},Y=class extends m{constructor(){super(...arguments);this.name="INTERNAL_GLOBAL_JS_ERROR";this.priority="P1"}},q=class extends E{constructor(r,t,o,i,s){super(r);this.message=r;this.code=t;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}}},Z=class extends m{constructor(){super(...arguments);this.name="INTERNAL_METRIC_REPORT_ERROR"}},ee=class extends m{constructor(){super(...arguments);this.name="INTERNAL_REPORTER_ERROR"}};function fe(n,e){return(...r)=>e(n,...r)}function sn(n){return e=>fe(e,function(r,...t){if(typeof r=="function")try{return r.apply(this,t)}catch(o){n(new I(`${o}`))}})}function x(n){return(...e)=>{(globalThis.VConsole?.[n]??globalThis.console[n])(...e)}}var ne={log:x("log"),warn:x("warn"),info:x("info"),error:x("error"),debug:x("debug")};Object.assign(globalThis,{logger:ne});var te=Symbol.for("Jolibox.canIUseMap"),ye={};globalThis[te]=ye;var un={get config(){return globalThis[te]}};function pn(n,e,r){let t=n;for(let o of e)if(t&&typeof t=="object")t=t[o];else return r;return t===void 0?r:t}function yn(n,e,r){let t=0;if(n!==e){let o=n.split("."),i=e.split("."),s=Math.max(o.length,i.length);for(let c=0;c<s;c++){let a=parseInt(o[c],10)||0,p=parseInt(i[c],10)||0;if(a>p){t=1;break}else if(a<p){t=-1;break}}}if(!r)return t;switch(r){case">":return t>0;case"<":return t<0;case"=":return t===0;case">=":return t>=0;case"<=":return t<=0;default:return!1}}var ge=(t=>(t[t.System=1e3]="System",t[t.ErrorTrace=1001]="ErrorTrace",t[t.UserDefined=1002]="UserDefined",t))(ge||{}),Te=(i=>(i.MiniGame="mini-game",i.MiniDrama="mini-drama",i.App="app",i.WebSDK="web-sdk",i.AppSDK="app-sdk",i))(Te||{}),Ee=(l=>(l[l.App=0]="App",l[l.H5=1]="H5",l[l.Weapp=2]="Weapp",l[l.Alipay=3]="Alipay",l[l.Gcash=4]="Gcash",l[l.Dana=5]="Dana",l[l.Umma=6]="Umma",l[l.WebSDK=1e3]="WebSDK",l[l.AppSDK=1001]="AppSDK",l[l.Other=9999]="Other",l))(Ee||{}),re=["name","params"],xe=["name","type","location","target","extra","timestamp","userId"],Re=["platform","os","appVersion","appId","model","brand","uuid","jsSdkVersion","extra"];function A(n,e){return e.map(r=>{if(r==="params"&&n[r]){let t=n[r];return Object.keys(t).reduce((o,i)=>(o[i]=String(t[i]),o),{})}return n[r]})}function _e(n){let e=n.location?A(n.location,re):null,r=n.target?A(n.target,re):null;return A({...n,location:e,target:r},xe)}function Tn(n){let e=n.events.map(t=>_e(t)),r=A(n.device,Re);return[n.protocolVersion,e,r,n.project]}var oe=()=>"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);var C={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=()=>C.isiOS?"iOS":C.isAndroid?"Android":C.isMac?"Mac":C.isFacebook?"Facebook":"PC",ve="device_id",Ie="advertising_id",ie=n=>(localStorage.getItem(n)||localStorage.setItem(n,oe()),localStorage.getItem(n)),Ae=()=>ie(ve),Ce=()=>ie(Ie),be=n=>n.charAt(0).toUpperCase()+n.slice(1),Ne=()=>{let n=new URLSearchParams(window.location.search);return be(n.get("utm_source")??"")||"JoliboxSDK"},hn=n=>{let e="JoliboxWebSDK",r=he(),t=navigator.language,o=Ae(),i=Ce();return`${e} (${Ne()}${r}; UnknownModel; UnknownSystemVersion; ${t}) uuid/${o} adid/${i} version/${n||""}`};var d=class n{static{this.Undefined=new n(void 0)}constructor(e){this.element=e,this.next=n.Undefined,this.prev=n.Undefined}},b=class{constructor(){this._first=d.Undefined;this._last=d.Undefined;this._size=0}get size(){return this._size}isEmpty(){return this._first===d.Undefined}clear(){let e=this._first;for(;e!==d.Undefined;){let r=e.next;e.prev=d.Undefined,e.next=d.Undefined,e=r}this._first=d.Undefined,this._last=d.Undefined,this._size=0}unshift(e){return this._insert(e,!1)}push(e){return this._insert(e,!0)}_insert(e,r){let t=new d(e);if(this._first===d.Undefined)this._first=t,this._last=t;else if(r){let i=this._last;this._last=t,t.prev=i,i.next=t}else{let i=this._first;this._first=t,t.next=i,i.prev=t}this._size+=1;let o=!1;return()=>{o||(o=!0,this._remove(t))}}shift(){if(this._first!==d.Undefined){let e=this._first.element;return this._remove(this._first),e}}pop(){if(this._last!==d.Undefined){let e=this._last.element;return this._remove(this._last),e}}_remove(e){if(e.prev!==d.Undefined&&e.next!==d.Undefined){let r=e.prev;r.next=e.next,e.next.prev=r}else e.prev===d.Undefined&&e.next===d.Undefined?(this._first=d.Undefined,this._last=d.Undefined):e.next===d.Undefined?(this._last=this._last.prev,this._last.next=d.Undefined):e.prev===d.Undefined&&(this._first=this._first.next,this._first.prev=d.Undefined);this._size-=1}*[Symbol.iterator](){let e=this._first;for(;e!==d.Undefined;)yield e.element,e=e.next}};var Oe=0,g=class{constructor(e){this.value=e;this.id=Oe++}},u=class{constructor(e){this.options=e;this._size=0}dispose(e){this._disposed||(this._disposed=!0,this._listeners&&(e?(this._listeners instanceof g&&(this._listeners=[this._listeners]),this._listeners=this._listeners.filter(r=>r?.value===e)):(this._listeners=void 0,this._size=0)),this.options?.onDidRemoveLastListener?.())}get event(){return this._event??=(e,r)=>{if(this._disposed)return()=>{console.info("[Jolibox SDK] Emitter is _disposed")};r&&(e=e.bind(r));let t=new g(e);this._listeners?this._listeners instanceof g?this._listeners=[this._listeners,t]:this._listeners.push(t):(this.options?.onWillAddFirstListener?.(this),this._listeners=t,this.options?.onDidFirstListener?.(this)),this.options?.onDidAddListener?.(this),this._size++},this._event}_deliver(e,r){if(!e)return;let t=this.options?.onListenerError||Error.constructor;if(!t){e.value(r);return}try{e.value(r)}catch(o){t(o)}}fire(e){this._listeners&&(this._listeners instanceof g?this._deliver(this._listeners,e):this._listeners.forEach(r=>this._deliver(r,e)))}hasListeners(){return this._size>0}},R=class{constructor(){this.listeners=new Map;this.listerHandlerMap=new WeakMap;this.cachedEventQueue=new Map}on(e,r){let t=this.listeners.get(e)??new u,o=s=>r(...s.args);this.listerHandlerMap.set(r,o),t.event(o),this.listeners.set(e,t);let i=this.cachedEventQueue.get(e);if(i)for(;i.size>0;)t.fire({event:e,...i.shift()})}off(e,r){let t=this.listeners.get(e);if(t){let o=this.listerHandlerMap.get(r);t.dispose(o)}}emit(e,...r){let t=this.listeners.get(e);if(t)t.fire({event:e,args:r});else{let o=this.cachedEventQueue.get(e);o||(o=new b,this.cachedEventQueue.set(e,o)),o.push({args:r})}}};var _={};me(_,{None:()=>we,filter:()=>ke,once:()=>se,toPromise:()=>Pe});var we=()=>{console.log("[Jolibox SDK] None Event")};function Pe(n){return new Promise(e=>se(n)(e))}function se(n){return(e,r=null)=>{let t=!1;return n(i=>{if(!t)return t=!0,e.call(r,i)},null)}}function ke(n,e){return(t=>{let o,i={onWillAddFirstListener(){o=t(s.fire,s)}},s=new u(i);return s.event})((t,o=null)=>n(i=>e(i)&&t.call(o,i),null))}var P=Symbol.for("Jolibox.hostEmitter"),Me=()=>{let n=new R;return globalThis[P]||(globalThis[P]={on:n.on.bind(n),off:n.off.bind(n),emit:n.emit.bind(n)}),globalThis[P]},Jn=Me();function ae(n,e){let r=Math.min(n.length,e.length);for(let t=0;t<r;t++)Ue(n[t],e[t])}function Ue(n,e){if(N(e)){if(typeof n!==e)throw new Error(`argument does not match constraint: typeof ${e}`)}else if(w(e)){try{if(n instanceof e)return}catch{}if(!O(n)&&n.constructor===e||e.length===1&&e.call(void 0,n)===!0)return;throw new Error("[Jolibox SDK]argument does not match one of these constraints: arg instanceof constraint, arg.constructor === constraint, nor constraint(arg) === true")}}var f=class{constructor(){this._commands=new Map;this._onDidRegisterCommand=new u;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 ae(s,o),i(...s)}}let{id:r}=e;this._commands.get(r)&&console.info(`[Jolibox SDK] duplicated command is registered ${r}`),this._commands.set(r,e),this._onDidRegisterCommand.fire(r)}getCommand(e){return this._commands.get(e)}getCommands(){let e=new Map;for(let r of this._commands.keys()){let t=this.getCommand(r);t&&e.set(r,t)}return e}};f=h([v],f);var T=class{constructor(){this._onWillExecuteCommand=new u;this.onWillExecuteCommand=this._onWillExecuteCommand.event;this._onDidExecuteCommand=new u;this.onDidExecuteCommand=this._onDidExecuteCommand.event;this.registry=new f;this._starActivation=null}_activateStar(){return this._starActivation||(this._starActivation=S(3e4)),this._starActivation}async executeCommand(e,...r){return this.registry.getCommand(e)?this._tryExecuteCommand(e,r):(await Promise.all([Promise.race([this._activateStar(),_.toPromise(_.filter(this.registry.onDidRegisterCommand,o=>o===e))])]),this._tryExecuteCommand(e,r))}executeCommandThowErr(e,...r){if(!!!this.registry.getCommand(e))throw new Error(`command '${e}' not found`);let o=this.registry.getCommand(e);this._onWillExecuteCommand.fire({commandId:e,args:r});let i=this.invokeFunction(o.handler,...r);return this._onDidExecuteCommand.fire({commandId:e,args:r}),i}_tryExecuteCommand(e,r){let t=this.registry.getCommand(e);if(!t)return Promise.reject(new Error(`command '${e}' not found`));try{this._onWillExecuteCommand.fire({commandId:e,args:r});let o=this.invokeFunction(t.handler,...r);return this._onDidExecuteCommand.fire({commandId:e,args:r}),Promise.resolve(o)}catch(o){return Promise.reject(o)}}invokeFunction(e,...r){let t=!1;try{return e(...r)}finally{t=!0}}};T=h([v],T);var k=Symbol.for("Jolibox.commands");function ft(){if(globalThis[k])return globalThis[k];let n=new f,e=new T,r={registerCommand(t,o,i){n.registerCommand({id:t,handler:o,metadata:i})},executeCommand(t,...o){return e.executeCommand(t,...o)},excuteCommandSync(t,...o){return e.executeCommandThowErr(t,...o)}};return globalThis[k]=r,r}export{Ie as ADVERTISING_ID,q as APIError,E as BaseError,ve as DEVICE_ID,L as Deferred,Ee as EPlatform,Te as EProject,R as EventEmitter,ge as EventType,_ as EventUtils,z as InternalApplyNativeError,Q as InternalBufferError,X as InternalContextError,m as InternalError,Y as InternalGlobalJSError,B as InternalInvokeMethodError,$ as InternalInvokeNativeError,W as InternalJSCoreNotFoundError,J as InternalJSModuleEvalError,G as InternalJSModuleFetchError,Z as InternalMetricReportError,ee as InternalReporterError,j as InternalSchemaParseError,pe as LoadScriptCode,v as Singleton,I as UserCustomError,y as UserError,H as UserFetchError,K as UserFunctionEvalError,F as UserGlobalError,V as UserValidateError,un as canIUseConfig,yn as compareVersion,ft as createCommands,Fe as createRunTaskQueue,en as debounce,pn as get,Ce as getAdvertisingId,Ae as getDeviceId,he as getPlatform,ie as getStorage,Ne as getUtmSource,Jn as hostEmitter,Ge as isArray,ze as isBoolean,Be as isDefined,w as isFunction,$e as isIterable,Je as isNumber,ce as isObject,We as isPromiseLike,N as isString,Ke as isStringArray,je as isTypedArray,ue as isUndefined,O as isUndefinedOrNull,xn as isValidUUIDV4,ne as logger,qe as mergeArray,Ye as mergeWith,Ve as microTask,C as platform,De as promisifyAPI,Tn as serializeEventPackage,Se as sleep,S as timeout,oe as uuidv4,Ue as validateConstraint,ae as validateConstraints,sn as wrapUserFunction,hn as xUserAgent};
@@ -3,10 +3,11 @@ type InternalAPIErrorName = 'INTERNAL_API_ERROR';
3
3
  type InternalMetricErrorName = 'INTERNAL_METRIC_REPORT_ERROR';
4
4
  type InternalReporterErrorName = 'INTERNAL_REPORTER_ERROR';
5
5
  type InternalUtilErrorName = 'INTERNAL_BUFFER_ERROR' | 'INTERNAL_SCHEMA_PARSE_ERROR';
6
+ type InternalGlobalJSErrorName = 'INTERNAL_GLOBAL_JS_ERROR';
6
7
  type InternalInjectErrorName = 'INTERNAL_CONTEXT_ERROR' | 'INTERNAL_JSCORE_ERROR' | 'INTERNAL_JS_MODULE_FETCH_ERROR' | 'INTERNAL_JS_MODULE_EVAL_ERROR';
7
8
  type InternalBridgeErrorName = 'INTERNAL_INVOKE_NATIVE_ERROR' | 'INTERNAL_APPLY_NATIVE_ERROR' | 'INTERNAL_INVOKE_METHOD_ERROR';
8
9
  type UserErrorName = 'USER_VALIDATE_ERROR' | 'USER_GLOBAL_ERROR' | 'USER_FETCH_ERROR' | 'API_ERROR' | 'USER_CALLBACK_ERROR' | 'USER_CUSTOM_ERROR';
9
- export type ErrorName = InternalLifeCycleErrorName | InternalInjectErrorName | InternalAPIErrorName | InternalBridgeErrorName | InternalUtilErrorName | InternalReporterErrorName | UserErrorName | InternalMetricErrorName;
10
+ export type ErrorName = InternalLifeCycleErrorName | InternalInjectErrorName | InternalAPIErrorName | InternalBridgeErrorName | InternalUtilErrorName | InternalReporterErrorName | UserErrorName | InternalMetricErrorName | InternalGlobalJSErrorName;
10
11
  export type ErrorKind = 'INTERNAL_ERROR' | 'USER_ERROR' | 'API_ERROR';
11
12
  export type ErrorEnv = 'native' | 'h5';
12
13
  export type LoadScriptError = BaseError & {
@@ -109,6 +110,13 @@ export declare class InternalContextError extends InternalError {
109
110
  readonly property: string;
110
111
  constructor(message: string, property: string);
111
112
  }
113
+ /**
114
+ * window.onerror 上报的错误
115
+ */
116
+ export declare class InternalGlobalJSError extends InternalError {
117
+ readonly name = "INTERNAL_GLOBAL_JS_ERROR";
118
+ readonly priority = "P1";
119
+ }
112
120
  export declare class APIError extends BaseError {
113
121
  readonly message: string;
114
122
  readonly code: number;
@@ -0,0 +1,55 @@
1
+ export declare enum EventType {
2
+ System = 1000,// used for web sdk
3
+ ErrorTrace = 1001,// used for web sdk
4
+ UserDefined = 1002
5
+ }
6
+ export interface IPage {
7
+ name: string;
8
+ params: Record<string, string | boolean | number | null> | null;
9
+ }
10
+ export interface IEvent {
11
+ name: string;
12
+ type: EventType;
13
+ location: IPage | null;
14
+ target: IPage | null;
15
+ extra: Record<string, string | boolean | number | null> | null;
16
+ timestamp: number;
17
+ userId: string | null;
18
+ }
19
+ export declare enum EProject {
20
+ MiniGame = "mini-game",
21
+ MiniDrama = "mini-drama",
22
+ App = "app",
23
+ WebSDK = "web-sdk",
24
+ AppSDK = "app-sdk"
25
+ }
26
+ export declare enum EPlatform {
27
+ App = 0,
28
+ H5 = 1,
29
+ Weapp = 2,
30
+ Alipay = 3,
31
+ Gcash = 4,
32
+ Dana = 5,
33
+ Umma = 6,
34
+ WebSDK = 1000,
35
+ AppSDK = 1001,
36
+ Other = 9999
37
+ }
38
+ export interface IDevice {
39
+ platform: EPlatform;
40
+ os: string;
41
+ appVersion: string;
42
+ appId: string;
43
+ model: string;
44
+ brand: string;
45
+ uuid: string;
46
+ jsSdkVersion: string | null;
47
+ extra: Record<string, string | boolean | number | null> | null;
48
+ }
49
+ export interface IEventPackage {
50
+ protocolVersion: string;
51
+ events: IEvent[];
52
+ device: IDevice;
53
+ project: EProject;
54
+ }
55
+ export declare function serializeEventPackage(eventPackage: IEventPackage): any[];
@@ -8,3 +8,6 @@ export * from './wrap-func';
8
8
  export * from './logger';
9
9
  export * from './can-i-use';
10
10
  export * from './compare-version';
11
+ export * from './event-tracker';
12
+ export * from './uuid';
13
+ export * from './xua';
@@ -0,0 +1,2 @@
1
+ export declare const uuidv4: () => string;
2
+ export declare const isValidUUIDV4: (uuid: string) => boolean;
@@ -0,0 +1,16 @@
1
+ export declare const platform: {
2
+ isiOS: boolean;
3
+ iosVersion: () => number[];
4
+ isAndroid: boolean;
5
+ isMac: boolean;
6
+ isFacebook: boolean;
7
+ isPC: boolean;
8
+ };
9
+ export declare const getPlatform: () => "Android" | "Mac" | "iOS" | "Facebook" | "PC";
10
+ export declare const DEVICE_ID = "device_id";
11
+ export declare const ADVERTISING_ID = "advertising_id";
12
+ export declare const getStorage: (cookieKey: string) => string;
13
+ export declare const getDeviceId: () => string;
14
+ export declare const getAdvertisingId: () => string;
15
+ export declare const getUtmSource: () => string;
16
+ export declare const xUserAgent: (appVersion: string) => 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.1.4-beta.8",
4
+ "version": "1.1.4",
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.4-beta.8"
14
+ "@jolibox/types": "1.1.4"
15
15
  },
16
16
  "devDependencies": {
17
17
  "typescript": "5.7.3",