@jolibox/sdk 1.1.4-beta.1 → 1.1.4-beta.11

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.
@@ -3,24 +3,29 @@
3
3
  "packages/sdk/.rush/temp/shrinkwrap-deps.json": "2dae37e4e0434d977846f6598de8fbcb9919efc5",
4
4
  "packages/sdk/.eslintrc.js": "c11c589d14fe58bf4d37d259d8323b193bab6092",
5
5
  "packages/sdk/README.md": "5660cd88848b7a5428394cc34d881a35dd402188",
6
- "packages/sdk/package.json": "756b84976306471c206279636d233f7ad64e5871",
7
- "packages/sdk/src/api/__tests__/canIUse.test.ts": "27fbe5050ac2e95d6643ff5fec335ba4d22ceb93",
8
- "packages/sdk/src/api/can-i-use.ts": "c6f9e896d05a63eabd754ab01d90711186eb8959",
9
- "packages/sdk/src/api/get-system-info.ts": "20eed7f356c629708452bb6f61cc05774f054070",
10
- "packages/sdk/src/api/index.ts": "d7390d30c9207b1450e018898a21cc458f6e613e",
11
- "packages/sdk/src/errors.ts": "1e74d62516994468d8f402d3ad2de999d3b0bb86",
12
- "packages/sdk/src/index.ts": "aab8ffff507dc63da0257e41460dd33b22dca7fd",
13
- "packages/sdk/src/loader/h5.ts": "76be98a2ec6c1fc2ad585772b22042b4f41dbd64",
14
- "packages/sdk/src/loader/index.ts": "9410ac6ccfa67ae44e6a6cb02f90a333da8f87c9",
15
- "packages/sdk/src/loader/native.ts": "ae1261a36a77a215e9d01b3aaed49e5bab0afb06",
6
+ "packages/sdk/esbuild.config.js": "7eacca35e51bf3e2face4112b3cfa76777e7c0d5",
7
+ "packages/sdk/package.json": "3cc2f6c061510653e789c1aebd19bfe4de00657a",
8
+ "packages/sdk/src/api/__tests__/canIUse.test.ts": "300e4de3768f9510e956050d326d4977bc621f34",
9
+ "packages/sdk/src/api/can-i-use.ts": "4fd7efe21419d39e535584d7ab8e6a3c4e186877",
10
+ "packages/sdk/src/api/get-system-info.ts": "c73be9f62c7055093effadaf6c48c54d6f383542",
11
+ "packages/sdk/src/api/index.ts": "3b4493aba6d4d842031040be7ce72607009e0665",
12
+ "packages/sdk/src/api/login.ts": "747c923c87175b467c17e303a14210bf0ab7a1cb",
13
+ "packages/sdk/src/events.ts": "37cd254da847a1ebd6de894813379b4378a694b9",
14
+ "packages/sdk/src/index.ts": "a772c24e370f183dba0c5346004f41dac6cb6807",
15
+ "packages/sdk/src/loader/h5.ts": "d28b611500754d30e2fcf4aaa55389a80dc02bd9",
16
+ "packages/sdk/src/loader/index.ts": "2fd698718dd7bad9fda8fa5a5f54d4d7bd209cb3",
17
+ "packages/sdk/src/loader/native.ts": "b250d460509f67b4544e5ca4d5f35f8dd20373c4",
16
18
  "packages/sdk/src/loader/version.ts": "8b584cf9c97198b6b6d1f728cc49f56260d7c02e",
17
19
  "packages/sdk/src/sdks/ads.ts": "d12ffe12be857f216a59a742f54395e31888adb5",
18
- "packages/sdk/src/sdks/keyboard.ts": "145d1c073ca6b0a3486f79979dd5430d8f4e553c",
19
- "packages/sdk/src/sdks/lifecycle.ts": "d8f8dda41aec99c0c2cbf385c37df7e2c5fd69b5",
20
+ "packages/sdk/src/sdks/keyboard.ts": "65301960c4d8f59d5944ae4c55cb45133ad40277",
21
+ "packages/sdk/src/sdks/lifecycle.ts": "8dad9d986cb43da7aeadf6f8af3cce37d6c37e6d",
20
22
  "packages/sdk/src/sdks/runtime.ts": "de05c8f898b3f5848c83e5c088fb720bd8217d99",
21
- "packages/sdk/src/sdks/sdk.ts": "f2eb4647da7fe88933b06d9908b215b7a6de3ca9",
23
+ "packages/sdk/src/sdks/sdk.ts": "7ced43ddee5f0208ceaec5f8311f586d3ca5a13d",
22
24
  "packages/sdk/src/sdks/storage.ts": "e04fca273b640f2e1dfcc70f23eaa537145c3f36",
25
+ "packages/sdk/src/sdks/task.ts": "07f5296dd999470d8d378487fd6f2a39a3f3d8ed",
23
26
  "packages/sdk/src/utils/can-i-use.ts": "10993f013cf26c07b60fe60fb7b458bbd6847244",
27
+ "packages/sdk/src/utils/env.ts": "d2e3db934d24a3b687de1f2df04fed7a5467e161",
28
+ "packages/sdk/src/utils/event-tracker.ts": "fde5019dad1331b0131225e613457b4cf4a227df",
24
29
  "packages/sdk/src/utils/report.ts": "d928d7456a5ba829216c41ea5b66afff6627c6be",
25
30
  "packages/sdk/tsconfig.json": "0ecd9cf2b93d09e0376a098b5b662820bafcf7eb"
26
31
  },
@@ -1,3 +1,2 @@
1
- export declare function getSystemInfo(): Promise<import("@jolibox/types").StandardResponse<import("@jolibox/types").ISystemInfo>>;
2
1
  export declare function getSystemInfoSync(): import("@jolibox/types").StandardResponse<import("@jolibox/types").ISystemInfo>;
3
2
  export declare function env(): import("@jolibox/types").StandardResponse<Omit<Omit<import("@jolibox/types").Env, "hostUserInfo">, "schema">>;
@@ -1,2 +1,3 @@
1
1
  export * from './get-system-info';
2
2
  export * from './can-i-use';
3
+ export * from './login';
@@ -0,0 +1,7 @@
1
+ export declare function login(): Promise<import("@jolibox/types").StandardResponse<{
2
+ isLogin: boolean;
3
+ token?: string;
4
+ }>>;
5
+ export declare function checkSession(): Promise<import("@jolibox/types").StandardResponse<{
6
+ isLogin: boolean;
7
+ }>>;
@@ -1,2 +1,5 @@
1
1
  import { BaseError } from '@jolibox/common';
2
+ export declare const timeline: {
3
+ startTime: number;
4
+ };
2
5
  export declare const reportError: (event: PromiseRejectionEvent | ErrorEvent | BaseError) => void;
package/dist/index.cjs.js CHANGED
@@ -1 +1 @@
1
- "use strict";var N=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var Ae=Object.getOwnPropertyNames;var Le=Object.prototype.hasOwnProperty;var we=(e,t)=>{for(var r in t)N(e,r,{get:t[r],enumerable:!0})},Ce=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Ae(t))!Le.call(e,s)&&s!==r&&N(e,s,{get:()=>t[s],enumerable:!(n=Ue(t,s))||n.enumerable});return e};var Te=e=>Ce(N({},"__esModule",{value:!0}),e);var tt={};we(tt,{JoliboxSDK:()=>Q});module.exports=Te(tt);var Y=Object.defineProperty,De=Object.getOwnPropertyDescriptor,Oe=(e,t)=>{for(var r in t)Y(e,r,{get:t[r],enumerable:!0})},X=(e,t,r,n)=>{for(var s=n>1?void 0:n?De(t,r):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(s=(n?i(t,r,s):i(s))||s);return n&&s&&Y(t,r,s),s};function Ne(e){return new Promise(t=>{setTimeout(()=>{t()},e)})}function j(e){return typeof e=="string"}function q(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&!(e instanceof RegExp)&&!(e instanceof Date)}function Ke(e){return typeof e>"u"}function Pe(e){return Ke(e)||e===null}function Me(e){return typeof e=="function"}function Z(e){let t=e,r=null,n=function(...s){return r||(r=new t(...s)),r};return n.prototype=t.prototype,n}var ke=(e=>(e[e.DEVELOPER_FILE_NOT_FOUND=0]="DEVELOPER_FILE_NOT_FOUND",e[e.INTERNAL_IOS_CAN_NOT_FOUND_PKG=1]="INTERNAL_IOS_CAN_NOT_FOUND_PKG",e[e.USER_IOS_LOAD_TIMEOUT=2]="USER_IOS_LOAD_TIMEOUT",e[e.INTERNAL_IOS_PKG_LOAD_ERROR=3]="INTERNAL_IOS_PKG_LOAD_ERROR",e[e.INTERNAL_IOS_PKG_PARSE_FAIL=4]="INTERNAL_IOS_PKG_PARSE_FAIL",e[e.USER_IOS_GET_EMPTY_DATA=5]="USER_IOS_GET_EMPTY_DATA",e[e.USER_ANDROID_GET_PKG_FAIL=6]="USER_ANDROID_GET_PKG_FAIL",e[e.DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE=7]="DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE",e))(ke||{}),je=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}},ee=class extends je{constructor(){super(...arguments),this.kind="INTERNAL_ERROR"}};var te=class extends ee{constructor(){super(...arguments),this.name="INTERNAL_JS_MODULE_FETCH_ERROR",this.priority="P0"}},y=class extends ee{constructor(){super(...arguments),this.name="INTERNAL_JS_MODULE_EVAL_ERROR",this.priority="P0"}};function R(e){return(...t)=>{(globalThis.VConsole?.[e]??globalThis.console[e])(...t)}}var Je={log:R("log"),warn:R("warn"),info:R("info"),error:R("error"),debug:R("debug")};Object.assign(globalThis,{logger:Je});var re=Symbol.for("Jolibox.canIUseMap"),Fe={};globalThis[re]=Fe;var ne={get config(){return globalThis[re]}};function J(e,t,r){let n=0;if(e!==t){let s=e.split("."),o=t.split("."),i=Math.max(s.length,o.length);for(let l=0;l<i;l++){let _=parseInt(s[l],10)||0,c=parseInt(o[l],10)||0;if(_>c){n=1;break}else if(_<c){n=-1;break}}}if(!r)return n;switch(r){case">":return n>0;case"<":return n<0;case"=":return n===0;case">=":return n>=0;case"<=":return n<=0;default:return!1}}var a=class U{static{this.Undefined=new U(void 0)}constructor(t){this.element=t,this.next=U.Undefined,this.prev=U.Undefined}},Be=class{constructor(){this._first=a.Undefined,this._last=a.Undefined,this._size=0}get size(){return this._size}isEmpty(){return this._first===a.Undefined}clear(){let e=this._first;for(;e!==a.Undefined;){let t=e.next;e.prev=a.Undefined,e.next=a.Undefined,e=t}this._first=a.Undefined,this._last=a.Undefined,this._size=0}unshift(e){return this._insert(e,!1)}push(e){return this._insert(e,!0)}_insert(e,t){let r=new a(e);if(this._first===a.Undefined)this._first=r,this._last=r;else if(t){let s=this._last;this._last=r,r.prev=s,s.next=r}else{let s=this._first;this._first=r,r.next=s,s.prev=r}this._size+=1;let n=!1;return()=>{n||(n=!0,this._remove(r))}}shift(){if(this._first!==a.Undefined){let e=this._first.element;return this._remove(this._first),e}}pop(){if(this._last!==a.Undefined){let e=this._last.element;return this._remove(this._last),e}}_remove(e){if(e.prev!==a.Undefined&&e.next!==a.Undefined){let t=e.prev;t.next=e.next,e.next.prev=t}else e.prev===a.Undefined&&e.next===a.Undefined?(this._first=a.Undefined,this._last=a.Undefined):e.next===a.Undefined?(this._last=this._last.prev,this._last.next=a.Undefined):e.prev===a.Undefined&&(this._first=this._first.next,this._first.prev=a.Undefined);this._size-=1}*[Symbol.iterator](){let e=this._first;for(;e!==a.Undefined;)yield e.element,e=e.next}},Ve=0,I=class{constructor(e){this.value=e,this.id=Ve++}},v=class{constructor(e){this.options=e,this._size=0}dispose(e){this._disposed||(this._disposed=!0,this._listeners&&(e?(this._listeners instanceof I&&(this._listeners=[this._listeners]),this._listeners=this._listeners.filter(t=>t?.value===e)):(this._listeners=void 0,this._size=0)),this.options?.onDidRemoveLastListener?.())}get event(){return this._event??=(e,t)=>{if(this._disposed)return()=>{console.info("[Jolibox SDK] Emitter is _disposed")};t&&(e=e.bind(t));let r=new I(e);this._listeners?this._listeners instanceof I?this._listeners=[this._listeners,r]:this._listeners.push(r):(this.options?.onWillAddFirstListener?.(this),this._listeners=r,this.options?.onDidFirstListener?.(this)),this.options?.onDidAddListener?.(this),this._size++},this._event}_deliver(e,t){if(!e)return;let r=this.options?.onListenerError||Error.constructor;if(!r){e.value(t);return}try{e.value(t)}catch(n){r(n)}}fire(e){this._listeners&&(this._listeners instanceof I?this._deliver(this._listeners,e):this._listeners.forEach(t=>this._deliver(t,e)))}hasListeners(){return this._size>0}},F=class{constructor(){this.listeners=new Map,this.listerHandlerMap=new WeakMap,this.cachedEventQueue=new Map}on(e,t){let r=this.listeners.get(e)??new v,n=o=>t(...o.args);this.listerHandlerMap.set(t,n),r.event(n),this.listeners.set(e,r);let s=this.cachedEventQueue.get(e);if(s)for(;s.size>0;)r.fire({event:e,...s.shift()})}off(e,t){let r=this.listeners.get(e);if(r){let n=this.listerHandlerMap.get(t);r.dispose(n)}}emit(e,...t){let r=this.listeners.get(e);if(r)r.fire({event:e,args:t});else{let n=this.cachedEventQueue.get(e);n||(n=new Be,this.cachedEventQueue.set(e,n)),n.push({args:t})}}},M={};Oe(M,{None:()=>Ge,filter:()=>He,once:()=>se,toPromise:()=>$e});var Ge=()=>{console.log("[Jolibox SDK] None Event")};function $e(e){return new Promise(t=>se(e)(t))}function se(e){return(t,r=null)=>{let n=!1;return e(s=>{if(!n)return n=!0,t.call(r,s)},null)}}function He(e,t){return(r=>{let n,s={onWillAddFirstListener(){n=r(o.fire,o)}},o=new v(s);return o.event})((r,n=null)=>e(s=>t(s)&&r.call(n,s),null))}var K=Symbol.for("Jolibox.hostEmitter"),ze=()=>{let e=new F;return globalThis[K]||(globalThis[K]={on:e.on.bind(e),off:e.off.bind(e),emit:e.emit.bind(e)}),globalThis[K]},oe=ze();function We(e,t){let r=Math.min(e.length,t.length);for(let n=0;n<r;n++)Qe(e[n],t[n])}function Qe(e,t){if(j(t)){if(typeof e!==t)throw new Error(`argument does not match constraint: typeof ${t}`)}else if(Me(t)){try{if(e instanceof t)return}catch{}if(!Pe(e)&&e.constructor===t||t.length===1&&t.call(void 0,e)===!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 A=class{constructor(){this._commands=new Map,this._onDidRegisterCommand=new v,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 r=[];for(let s of e.metadata.args)r.push(s.constraint);let n=e.handler;e.handler=function(...s){return We(s,r),n(...s)}}let{id:t}=e;this._commands.get(t)&&console.info(`[Jolibox SDK] duplicated command is registered ${t}`),this._commands.set(t,e),this._onDidRegisterCommand.fire(t)}getCommand(e){return this._commands.get(e)}getCommands(){let e=new Map;for(let t of this._commands.keys()){let r=this.getCommand(t);r&&e.set(t,r)}return e}};A=X([Z],A);var k=class{constructor(){this._onWillExecuteCommand=new v,this.onWillExecuteCommand=this._onWillExecuteCommand.event,this._onDidExecuteCommand=new v,this.onDidExecuteCommand=this._onDidExecuteCommand.event,this.registry=new A,this._starActivation=null}_activateStar(){return this._starActivation||(this._starActivation=Ne(3e4)),this._starActivation}async executeCommand(e,...t){return this.registry.getCommand(e)?this._tryExecuteCommand(e,t):(await Promise.all([Promise.race([this._activateStar(),M.toPromise(M.filter(this.registry.onDidRegisterCommand,r=>r===e))])]),this._tryExecuteCommand(e,t))}executeCommandThowErr(e,...t){if(!this.registry.getCommand(e))throw new Error(`command '${e}' not found`);let r=this.registry.getCommand(e);this._onWillExecuteCommand.fire({commandId:e,args:t});let n=this.invokeFunction(r.handler,...t);return this._onDidExecuteCommand.fire({commandId:e,args:t}),n}_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 n=this.invokeFunction(r.handler,...t);return this._onDidExecuteCommand.fire({commandId:e,args:t}),Promise.resolve(n)}catch(n){return Promise.reject(n)}}invokeFunction(e,...t){let r=!1;try{return e(...t)}finally{r=!0}}};k=X([Z],k);var P=Symbol.for("Jolibox.commands");function h(){if(globalThis[P])return globalThis[P];let e=new A,t=new k,r={registerCommand(n,s,o){e.registerCommand({id:n,handler:s,metadata:o})},executeCommand(n,...s){return t.executeCommand(n,...s)},excuteCommandSync(n,...s){return t.executeCommandThowErr(n,...s)}};return globalThis[P]=r,r}document.addEventListener("DOMContentLoaded",()=>oe.emit("onDocumentReady"));var ie=h(),B=e=>{ie.executeCommand("ReportSDK.traceSystem",{event:"global_js_error",info:{err:JSON.stringify(e)}}).catch(t=>{console.error(`Fallback report: ${t} ${JSON.stringify(e)}`)})},g=B;window.addEventListener("unhandledrejection",B.bind(void 0));window.addEventListener("error",B.bind(void 0));window.onerror=(e,t,r,n,s)=>{ie.executeCommand("ReportSDK.traceSystem",{event:"global_js_error",info:{err:JSON.stringify({message:e,source:t,lineno:r,colno:n,error:s})}}).catch(o=>{console.error(`Fallback report: ${o} ${JSON.stringify(e)}`)})};var V=e=>{let t=e.split("-")[1];t&&(e=e.replace(`-${t}`,""));let r=e.split("+")[1];r&&(e=e.replace(`+${r}`,""));let n=e.split(".").slice(0,3),[s,o,i]=[n[0]??"0",n[1]??"0",n[2]??"0"];return{major:s,minor:o,patch:i,prerelease:t,build:r}},S=e=>parseInt(V(e).major,10),b=(e,t)=>{let{major:r,minor:n,patch:s}=V(e),{major:o,minor:i,patch:l}=V(t);return r!==o?r>o?1:-1:n!==i?n>i?1:-1:s!==l?s>l?1:-1:0};var ae=h(),L=(e,t)=>{ae.executeCommand("ReportSDK.traceSystem",{event:e,info:t})},E=(e,t,r)=>{ae.executeCommand("ReportSDK.traceSystemTimeline",{event:e,duration:t,extra:r})};var le="jolibox-sdk-loadermeta",x=JSON.parse(localStorage.getItem(le)??"{}"),G=Date.now(),ce=(e,t)=>e>t&&Math.abs(e-t)/(1e3*60*60*24)>=7,me=e=>!/^(Failed to fetch version|Couldn't find the requested file)/.test(e);async function Ye(){let e="https://stg-api.jolibox.com/api/fe-configs/js-sdk/version_metadata";try{let t=await fetch(e,{method:"GET",headers:{"Content-Type":"application/json"}}),{implement_version:r,bootstrap_version:n}=await t.json(),s={...x,timestamp:G};if(n){let{bootstrap_version:o}=x;if(!(o&&b(o,n))){let i=await(await fetch($(n))).text();me(i)&&(s={...s,bootstrap_version:n,bootstrap_script:i})}}if(r){let{implement_version:o}=x;if(!(o&&b(o,r))){let i=await(await fetch(H(r))).text();me(i)&&(s={...s,implement_version:r,implement_script:i})}}localStorage.setItem(le,JSON.stringify(s))}catch(t){console.warn("Failed to fetch loader metadata: ",t)}}var de=e=>{let{currentMajorVersion:t,currentVersion:r,bootstrapUrl:n,implementUrl:s}=e;function o(){let{bootstrap_version:c,bootstrap_script:p,timestamp:d}=x;if(c&&p&&d&&!ce(G,d)&&S(c)==t&&b(c,r)>0)return{script:p,type:"localscript"};try{let m=new XMLHttpRequest;return m.open("GET",n,!1),m.send(),{script:m.responseText,type:"fetch_from_cdn"}}catch(m){g(new te(`Bootstrap module faile to fetch ${m}`))}}function i(){let c=Date.now();L("js_sdk_begin",{t:c});let{script:p,type:d}=o()??{};if(p){let m=document.createElement("script");m.type="text/javascript",m.innerHTML=p,document.head.appendChild(m),E("bootstrapModuleLoaded",Date.now()-c,{type:d})}}function l(c){(async d=>{try{let m=new Blob([d],{type:"application/javascript"}),f=URL.createObjectURL(m),Ie=await import(f);return URL.revokeObjectURL(f),Ie}catch(m){g(new y(`implement module evaluate error in h5:${m} `))}})(c)}function _(){let c=Date.now(),{implement_script:p,implement_version:d,timestamp:m}=x;if(p&&d&&m&&!ce(G,m)&&S(d)==t&&b(d,r)>0){l(p),E("implementModuleLoaded",Date.now()-c,{type:"loadscript"});return}let f=document.createElement("script");f.type="module",f.crossOrigin="anonymous",f.src=s,f.onload=()=>{E("bootstrapModuleLoaded",Date.now()-c,{type:"fetch_from_cdn"})},document.head.appendChild(f)}return()=>{try{i(),_(),Ye()}catch(c){g(new y(`module evaluate error: ${c}`))}}};var ue=(e,t)=>{let r=s=>{let o=e({path:s});if(!o)throw`module ${s} load failed ${o}`;return o};function n(s){(async i=>{try{let l=new Blob([i],{type:"application/javascript"}),_=URL.createObjectURL(l),c=await import(_);return URL.revokeObjectURL(_),c}catch(l){g(new y(`implement module evaluate error in native:${l} `))}})(s)}return()=>{try{let s=Date.now();L("js_sdk_begin",{t:s});let o=r(t.bootstrapUrl),i=document.createElement("script");i.type="text/javascript",i.innerHTML=o,document.head.appendChild(i),E("implementModuleLoaded",Date.now()-s,{type:"native"});let l=r(t.implementUrl);n(l),E("bootstrapModuleLoaded",Date.now()-s,{type:"native"})}catch(s){console.error(`native load script error: ${s}`),g(new y(`module load failed ${s}`))}}};var Xe="1.0.0",he=Xe,z=S(he),_e=window.webkit?e=>window.prompt("loadScript",JSON.stringify(e)):void 0,qe=typeof _e<"u",$=e=>`http://cdn.jsdelivr.net/npm/@jolibox/bootstrap@${e}/dist/index.js`,H=e=>`http://cdn.jsdelivr.net/npm/@jolibox/implementation@${e}/dist/index.js`,pe=$(z),fe=H(z);function Ze(){qe?ue(_e,{bootstrapUrl:pe,implementUrl:fe})():de({bootstrapUrl:pe,implementUrl:fe,currentMajorVersion:z,currentVersion:he})()}Ze();var W=h();async function ge(){return await W.executeCommand("API.getSystemInfo")}function Ee(){return W.excuteCommandSync("API.getSystemInfoSync")}function ye(){return W.excuteCommandSync("API.env")}function Re(e,t){return ne.config[e]?.[t]}function ve(e,t,r){let n=Array.isArray(t)?t:t.replace(/\[(\d+)\]/g,".$1").split("."),s=e;for(let o of n)if(s&&(typeof s=="object"||Array.isArray(s)))s=s[o];else return r;return s===void 0?r:s}var be="1.0.0";function w(e){let r=ye().data?.deviceInfo?.platform;if(!r)return!1;let[n,...s]=e.split(":"),o=Re(r=="h5"?r:"native",n);if(!o)return!1;let i=o.version;return typeof i!="string"||J(be,i,"<")?!1:s.length===0?!0:Se(o,s)||Se(o.properties,s)}function Se(e,t){if(!e)return!1;let r=ve(e,t);return r?q(r)?!0:j(r)?J(be,r,">="):!1:!1}var xe=window.JoliboxRuntime;var u=class{constructor(){this.commands=h();this._emitter=new F}addEventListener(t,r){this._emitter.on(t,(...n)=>r(n[0]))}triggerEvent(t,r){this._emitter.emit(t,r)}canUse(t){return w(t)}};var et="LifecycleSDK.onReady",C=class extends u{constructor(){super()}onReady(t){let r=n=>{t.call(this,n),this.triggerEvent(et,n)};this.commands.executeCommand("LifecycleSDK.onReady",r.bind(this))}exitGame(t){this.commands.executeCommand("LifecycleSDK.exitGame",t.onBeforeExit)}onGameHide(t){this.commands.executeCommand("LifecycleSDK.onGameHide",t.bind(this))}onGameShow(t){this.commands.executeCommand("LifecycleSDK.onGameShow",t.bind(this))}};var T=class extends u{async getItem(t){return await this.commands.executeCommand("StorageSDK.getItem",t)}async setItem(t,r){if(t.length>128)return{code:"PARAMETER_ERROR",message:"[SDK] cloud storage setItem error: length of key should be less than 128"};let n=typeof r=="string"?r:String(r);return t.length+n.length>1024?{code:"PARAMETER_ERROR",message:"[SDK] cloud storage setItem error: length of key and value should be less than 1024"}:await this.commands.executeCommand("StorageSDK.setItem",t,r)}async removeItem(t){return this.commands.executeCommand("StorageSDK.removeItem",t)}async clear(){return this.commands.executeCommand("StorageSDK.clear")}};var D=class extends u{constructor(){super();this.init=r=>{this.commands.executeCommand("AdsSDK.init",r)};this.adConfig=r=>{this.commands.executeCommand("AdsSDK.adConfig",r)};this.adBreak=r=>{this.commands.executeCommand("AdsSDK.adBreak",r)};this.adUnit=r=>{this.commands.executeCommand("AdsSDK.adUnit",r)}}};var O=class extends u{showKeyboard(t){if(!this.canUse("keyboard.showKeyboard"))return{code:"FAILURE",message:"[Jolibox SDK] keyboard.showKeyboard is not supported in this platform"};this.commands.executeCommand("KeyboardSDK.showKeyboard",t)}updateKeyboard(t){if(!this.canUse("keyboard.updateKeyboard"))return{code:"FAILURE",message:"[Jolibox SDK] keyboard.updateKeyboard is not supported in this platform"};this.commands.executeCommand("KeyboardSDK.updateKeyboard",t)}hideKeyboard(){if(!this.canUse("keyboard.hideKeyboard"))return{code:"FAILURE",message:"[Jolibox SDK] keyboard.hideKeyboard is not supported in this platform"};this.commands.executeCommand("KeyboardSDK.hideKeyboard")}};var Q=class{constructor(){this.runtime=new xe;this.ads=new D;this.lifecycle=new C;this.storage=new T;this.keyboard=new O;this.getSystemInfo=ge.bind(this);this.getSystemInfoSync=Ee.bind(this);this.canIUse=w.bind(this)}};
1
+ "use strict";var B=Object.defineProperty;var Ve=Object.getOwnPropertyDescriptor;var $e=Object.getOwnPropertyNames;var Ge=Object.prototype.hasOwnProperty;var He=(e,t)=>{for(var r in t)B(e,r,{get:t[r],enumerable:!0})},We=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of $e(t))!Ge.call(e,s)&&s!==r&&B(e,s,{get:()=>t[s],enumerable:!(n=Ve(t,s))||n.enumerable});return e};var ze=e=>We(B({},"__esModule",{value:!0}),e);var jt={};He(jt,{JoliboxSDK:()=>F});module.exports=ze(jt);var se=Object.defineProperty,Ye=Object.getOwnPropertyDescriptor,Qe=(e,t)=>{for(var r in t)se(e,r,{get:t[r],enumerable:!0})},oe=(e,t,r,n)=>{for(var s=n>1?void 0:n?Ye(t,r):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(s=(n?i(t,r,s):i(s))||s);return n&&s&&se(t,r,s),s};function Xe(e){return new Promise(t=>{setTimeout(()=>{t()},e)})}function W(e){return typeof e=="string"}function ie(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&!(e instanceof RegExp)&&!(e instanceof Date)}function qe(e){return typeof e>"u"}function Ze(e){return qe(e)||e===null}function et(e){return typeof e=="function"}function ae(e){let t=e,r=null,n=function(...s){return r||(r=new t(...s)),r};return n.prototype=t.prototype,n}var tt=(e=>(e[e.DEVELOPER_FILE_NOT_FOUND=0]="DEVELOPER_FILE_NOT_FOUND",e[e.INTERNAL_IOS_CAN_NOT_FOUND_PKG=1]="INTERNAL_IOS_CAN_NOT_FOUND_PKG",e[e.USER_IOS_LOAD_TIMEOUT=2]="USER_IOS_LOAD_TIMEOUT",e[e.INTERNAL_IOS_PKG_LOAD_ERROR=3]="INTERNAL_IOS_PKG_LOAD_ERROR",e[e.INTERNAL_IOS_PKG_PARSE_FAIL=4]="INTERNAL_IOS_PKG_PARSE_FAIL",e[e.USER_IOS_GET_EMPTY_DATA=5]="USER_IOS_GET_EMPTY_DATA",e[e.USER_ANDROID_GET_PKG_FAIL=6]="USER_ANDROID_GET_PKG_FAIL",e[e.DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE=7]="DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE",e))(tt||{}),rt=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}},ce=class extends rt{constructor(){super(...arguments),this.kind="INTERNAL_ERROR"}};var le=class extends ce{constructor(){super(...arguments),this.name="INTERNAL_JS_MODULE_FETCH_ERROR",this.priority="P0"}},S=class extends ce{constructor(){super(...arguments),this.name="INTERNAL_JS_MODULE_EVAL_ERROR",this.priority="P0"}};function x(e){return(...t)=>{(globalThis.VConsole?.[e]??globalThis.console[e])(...t)}}var nt={log:x("log"),warn:x("warn"),info:x("info"),error:x("error"),debug:x("debug")};Object.assign(globalThis,{logger:nt});var me=Symbol.for("Jolibox.canIUseMap"),st={};globalThis[me]=st;var de={get config(){return globalThis[me]}};function z(e,t,r){let n=0;if(e!==t){let s=e.split("."),o=t.split("."),i=Math.max(s.length,o.length);for(let a=0;a<i;a++){let g=parseInt(s[a],10)||0,l=parseInt(o[a],10)||0;if(g>l){n=1;break}else if(g<l){n=-1;break}}}if(!r)return n;switch(r){case">":return n>0;case"<":return n<0;case"=":return n===0;case">=":return n>=0;case"<=":return n<=0;default:return!1}}var Y=(e=>(e[e.System=1e3]="System",e[e.ErrorTrace=1001]="ErrorTrace",e[e.UserDefined=1002]="UserDefined",e))(Y||{}),k=(e=>(e.MiniGame="mini-game",e.MiniDrama="mini-drama",e.App="app",e.WebSDK="web-sdk",e.AppSDK="app-sdk",e))(k||{}),ot=(e=>(e[e.App=0]="App",e[e.H5=1]="H5",e[e.Weapp=2]="Weapp",e[e.Alipay=3]="Alipay",e[e.Gcash=4]="Gcash",e[e.Dana=5]="Dana",e[e.Umma=6]="Umma",e[e.WebSDK=1e3]="WebSDK",e[e.AppSDK=1001]="AppSDK",e[e.Other=9999]="Other",e))(ot||{}),ne=["name","params"],it=["name","type","location","target","extra","timestamp","userId"],at=["platform","os","appVersion","appId","model","brand","uuid","jsSdkVersion","extra"];function U(e,t){return t.map(r=>{if(r==="params"&&e[r]){let n=e[r];return Object.keys(n).reduce((s,o)=>(s[o]=String(n[o]),s),{})}return e[r]})}function ct(e){let t=e.location?U(e.location,ne):null,r=e.target?U(e.target,ne):null;return U({...e,location:t,target:r},it)}function ue(e){let t=e.events.map(n=>ct(n)),r=U(e.device,at);return[e.protocolVersion,t,r,e.project]}var lt=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)});var w={isiOS:navigator.userAgent.includes("iPhone")||navigator.userAgent.includes("iPod")||navigator.userAgent.includes("iPad")||navigator.userAgent.includes("iPhone OS"),iosVersion:()=>{let e=navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/);return[parseInt(e[1],10),parseInt(e[2],10),parseInt(e[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")},mt=()=>w.isiOS?"iOS":w.isAndroid?"Android":w.isMac?"Mac":w.isFacebook?"Facebook":"PC",dt="device_id",ut="advertising_id",pe=e=>(localStorage.getItem(e)||localStorage.setItem(e,lt()),localStorage.getItem(e)),pt=()=>pe(dt),ft=()=>pe(ut),ht=e=>e.charAt(0).toUpperCase()+e.slice(1),gt=()=>{let e=new URLSearchParams(window.location.search);return ht(e.get("utm_source")??"")||"JoliboxSDK"},fe=e=>{let t="JoliboxWebSDK",r=mt(),n=navigator.language,s=pt(),o=ft();return`${t} (${gt()}${r}; UnknownModel; UnknownSystemVersion; ${n}) uuid/${s} adid/${o} version/${e||""}`},c=class D{static{this.Undefined=new D(void 0)}constructor(t){this.element=t,this.next=D.Undefined,this.prev=D.Undefined}},Et=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 s=this._last;this._last=r,r.prev=s,s.next=r}else{let s=this._first;this._first=r,r.next=s,s.prev=r}this._size+=1;let n=!1;return()=>{n||(n=!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}},_t=0,A=class{constructor(e){this.value=e,this.id=_t++}},v=class{constructor(e){this.options=e,this._size=0}dispose(e){this._disposed||(this._disposed=!0,this._listeners&&(e?(this._listeners instanceof A&&(this._listeners=[this._listeners]),this._listeners=this._listeners.filter(t=>t?.value===e)):(this._listeners=void 0,this._size=0)),this.options?.onDidRemoveLastListener?.())}get event(){return this._event??=(e,t)=>{if(this._disposed)return()=>{console.info("[Jolibox SDK] Emitter is _disposed")};t&&(e=e.bind(t));let r=new A(e);this._listeners?this._listeners instanceof A?this._listeners=[this._listeners,r]:this._listeners.push(r):(this.options?.onWillAddFirstListener?.(this),this._listeners=r,this.options?.onDidFirstListener?.(this)),this.options?.onDidAddListener?.(this),this._size++},this._event}_deliver(e,t){if(!e)return;let r=this.options?.onListenerError||Error.constructor;if(!r){e.value(t);return}try{e.value(t)}catch(n){r(n)}}fire(e){this._listeners&&(this._listeners instanceof A?this._deliver(this._listeners,e):this._listeners.forEach(t=>this._deliver(t,e)))}hasListeners(){return this._size>0}},Q=class{constructor(){this.listeners=new Map,this.listerHandlerMap=new WeakMap,this.cachedEventQueue=new Map}on(e,t){let r=this.listeners.get(e)??new v,n=o=>t(...o.args);this.listerHandlerMap.set(t,n),r.event(n),this.listeners.set(e,r);let s=this.cachedEventQueue.get(e);if(s)for(;s.size>0;)r.fire({event:e,...s.shift()})}off(e,t){let r=this.listeners.get(e);if(r){let n=this.listerHandlerMap.get(t);r.dispose(n)}}emit(e,...t){let r=this.listeners.get(e);if(r)r.fire({event:e,args:t});else{let n=this.cachedEventQueue.get(e);n||(n=new Et,this.cachedEventQueue.set(e,n)),n.push({args:t})}}},G={};Qe(G,{None:()=>yt,filter:()=>xt,once:()=>he,toPromise:()=>St});var yt=()=>{console.log("[Jolibox SDK] None Event")};function St(e){return new Promise(t=>he(e)(t))}function he(e){return(t,r=null)=>{let n=!1;return e(s=>{if(!n)return n=!0,t.call(r,s)},null)}}function xt(e,t){return(r=>{let n,s={onWillAddFirstListener(){n=r(o.fire,o)}},o=new v(s);return o.event})((r,n=null)=>e(s=>t(s)&&r.call(n,s),null))}var V=Symbol.for("Jolibox.hostEmitter"),vt=()=>{let e=new Q;return globalThis[V]||(globalThis[V]={on:e.on.bind(e),off:e.off.bind(e),emit:e.emit.bind(e)}),globalThis[V]},ge=vt();function bt(e,t){let r=Math.min(e.length,t.length);for(let n=0;n<r;n++)Rt(e[n],t[n])}function Rt(e,t){if(W(t)){if(typeof e!==t)throw new Error(`argument does not match constraint: typeof ${t}`)}else if(et(t)){try{if(e instanceof t)return}catch{}if(!Ze(e)&&e.constructor===t||t.length===1&&t.call(void 0,e)===!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 L=class{constructor(){this._commands=new Map,this._onDidRegisterCommand=new v,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 r=[];for(let s of e.metadata.args)r.push(s.constraint);let n=e.handler;e.handler=function(...s){return bt(s,r),n(...s)}}let{id:t}=e;this._commands.get(t)&&console.info(`[Jolibox SDK] duplicated command is registered ${t}`),this._commands.set(t,e),this._onDidRegisterCommand.fire(t)}getCommand(e){return this._commands.get(e)}getCommands(){let e=new Map;for(let t of this._commands.keys()){let r=this.getCommand(t);r&&e.set(t,r)}return e}};L=oe([ae],L);var H=class{constructor(){this._onWillExecuteCommand=new v,this.onWillExecuteCommand=this._onWillExecuteCommand.event,this._onDidExecuteCommand=new v,this.onDidExecuteCommand=this._onDidExecuteCommand.event,this.registry=new L,this._starActivation=null}_activateStar(){return this._starActivation||(this._starActivation=Xe(3e4)),this._starActivation}async executeCommand(e,...t){return this.registry.getCommand(e)?this._tryExecuteCommand(e,t):(await Promise.all([Promise.race([this._activateStar(),G.toPromise(G.filter(this.registry.onDidRegisterCommand,r=>r===e))])]),this._tryExecuteCommand(e,t))}executeCommandThowErr(e,...t){if(!this.registry.getCommand(e))throw new Error(`command '${e}' not found`);let r=this.registry.getCommand(e);this._onWillExecuteCommand.fire({commandId:e,args:t});let n=this.invokeFunction(r.handler,...t);return this._onDidExecuteCommand.fire({commandId:e,args:t}),n}_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 n=this.invokeFunction(r.handler,...t);return this._onDidExecuteCommand.fire({commandId:e,args:t}),Promise.resolve(n)}catch(n){return Promise.reject(n)}}invokeFunction(e,...t){let r=!1;try{return e(...t)}finally{r=!0}}};H=oe([ae],H);var $=Symbol.for("Jolibox.commands");function p(){if(globalThis[$])return globalThis[$];let e=new L,t=new H,r={registerCommand(n,s,o){e.registerCommand({id:n,handler:s,metadata:o})},executeCommand(n,...s){return t.executeCommand(n,...s)},excuteCommandSync(n,...s){return t.executeCommandThowErr(n,...s)}};return globalThis[$]=r,r}var C=new URLSearchParams(window.location.search).get("joliboxEnv")==="staging";function It(){let e=new URLSearchParams(window.location.search),t={};return e.forEach((r,n)=>{t[n]=r}),{name:"GamePage",params:t}}function Tt(){return{platform:1e3,os:"h5",appVersion:"1.1.4-beta.11",appId:"1",model:"UnknownModel",brand:"UnknownBrand",uuid:"1",jsSdkVersion:"1.1.4-beta.11",extra:{}}}var Ee={default:{test:"https://stg-collect.jolibox.com",prod:"https://collect.jolibox.com"},"oss.jolibox.com":{test:"https://stg-collect.jolibox.com",prod:"https://collect.jolibox.com"},"oss.pico-game.com":{test:"https://stg-collect.pico-game.com",prod:"https://collect.pico-game.com"}},wt=()=>{let e=Ee[window.location.host]??Ee.default;return C?e.test:e.prod},At=wt(),_e=e=>{let t=new AbortController;return setTimeout(()=>t.abort(),e),t.signal};AbortSignal.timeout??=_e;var Ut=()=>new URLSearchParams(window.location.search).get("joliSource")??null,Dt=Ut(),Lt=async e=>{let r=`${At}/report`,n=fe("1.1.4-beta.11"),s=Dt,o={"Content-Type":"application/json"};return n&&(o["x-user-agent"]=n),s&&(o["x-joli-source"]=s),await fetch(r,{method:"POST",headers:o,body:JSON.stringify(e),signal:_e(5e3)})};async function X(e,t,r){let n={name:e,type:Y.ErrorTrace,location:It(),target:null,extra:t,timestamp:Date.now(),userId:null},s=Tt(),a=ue({protocolVersion:"1.0.0",events:[n],device:s,project:r});Lt(a)}document.addEventListener("DOMContentLoaded",()=>ge.emit("onDocumentReady",b.startTime));var kt=()=>{let e=0;return{set startTime(t){e=t},get startTime(){return e}}},b=kt(),ye=p(),q=e=>{ye.executeCommand("ReportSDK.traceSystem",{event:"globalJsError",info:{err:JSON.stringify(e)}}).catch(t=>{console.error(`Fallback report: ${t} ${JSON.stringify(e)}`),X("globalJsError",{err:JSON.stringify({message:t.message,source:t.source,lineno:t.lineno,colno:t.colno,error:t.error})},k.WebSDK)})},E=q;window.addEventListener("unhandledrejection",q.bind(void 0));window.addEventListener("error",q.bind(void 0));window.onerror=(e,t,r,n,s)=>{ye.executeCommand("ReportSDK.traceSystem",{event:"globalJsError",info:{err:JSON.stringify({message:e,source:t,lineno:r,colno:n,error:s})}}).catch(o=>{X("globalJsError",{err:JSON.stringify({message:e,source:t,lineno:r,colno:n,error:s})},k.WebSDK)})};var Z=e=>{let t=e.split("-")[1];t&&(e=e.replace(`-${t}`,""));let r=e.split("+")[1];r&&(e=e.replace(`+${r}`,""));let n=e.split(".").slice(0,3),[s,o,i]=[n[0]??"0",n[1]??"0",n[2]??"0"];return{major:s,minor:o,patch:i,prerelease:t,build:r}},R=e=>parseInt(Z(e).major,10),I=(e,t)=>{let{major:r,minor:n,patch:s}=Z(e),{major:o,minor:i,patch:a}=Z(t);return r!==o?r>o?1:-1:n!==i?n>i?1:-1:s!==a?s>a?1:-1:0};var Se=p(),P=(e,t)=>{Se.executeCommand("ReportSDK.traceSystem",{event:e,info:t})},_=(e,t,r)=>{Se.executeCommand("ReportSDK.traceSystemTimeline",{event:e,duration:t,extra:r})};var be="jolibox-sdk-loadermeta",T=JSON.parse(localStorage.getItem(be)??"{}"),ee=Date.now(),xe=(e,t)=>e>t&&Math.abs(e-t)/(1e3*60*60*24)>=7,ve=e=>!/^(Failed to fetch version|Couldn't find the requested file)/.test(e);async function Ct(){let t=`${C?"https://stg-api.jolibox.com":"https://api.jolibox.com"}/api/fe-configs/js-sdk/version_metadata`;try{let r=await fetch(t,{method:"GET",headers:{"Content-Type":"application/json"}}),{implement_version:n,bootstrap_version:s}=await r.json(),o={...T,timestamp:ee};if(s){let{bootstrap_version:i}=T;if(!(i&&I(i,s)>=0)){let a=await(await fetch(te(s))).text();ve(a)&&(o={...o,bootstrap_version:s,bootstrap_script:a})}}if(n){let{implement_version:i}=T;if(!(i&&I(i,n)>=0)){let a=await(await fetch(re(n))).text();ve(a)&&(o={...o,implement_version:n,implement_script:a})}}localStorage.setItem(be,JSON.stringify(o))}catch(r){console.warn("Failed to fetch loader metadata: ",r)}}var Re=e=>{let{currentMajorVersion:t,currentVersion:r,bootstrapUrl:n,implementUrl:s}=e;function o(){let{bootstrap_version:l,bootstrap_script:f,timestamp:u}=T;if(l&&f&&u&&!xe(ee,u)&&R(l)==t&&I(l,r)>=0)return{script:f,type:"localscript"};try{let m=new XMLHttpRequest;return m.open("GET",n,!1),m.send(),{script:m.responseText,type:"fetch_from_cdn"}}catch(m){E(new le(`Bootstrap module faile to fetch ${m}`))}}function i(){let l=Date.now();P("jsSdkBegin",{t:l}),b.startTime=l;let{script:f,type:u}=o()??{};if(f){let m=document.createElement("script");m.type="text/javascript",m.innerHTML=f,document.head.appendChild(m),_("bootstrapModuleLoaded",Date.now()-l,{type:u})}}function a(l){(async u=>{try{let m=new Blob([u],{type:"application/javascript"}),h=URL.createObjectURL(m),Be=await import(h);return URL.revokeObjectURL(h),Be}catch(m){E(new S(`implement module evaluate error in h5:${m} `))}})(l)}function g(){let l=Date.now(),{implement_script:f,implement_version:u,timestamp:m}=T;if(f&&u&&m&&!xe(ee,m)&&R(u)==t&&I(u,r)>=0){a(f),_("implementModuleLoaded",Date.now()-l,{type:"loadscript"});return}let h=document.createElement("script");h.type="module",h.crossOrigin="anonymous",h.src=s,h.onload=()=>{_("bootstrapModuleLoaded",Date.now()-l,{type:"fetch_from_cdn"})},document.head.appendChild(h)}return()=>{try{i(),g(),Ct()}catch(l){E(new S(`module evaluate error: ${l}`))}}};var Ie=(e,t)=>{let r=s=>{let o=e({path:s});if(!o)throw`module ${s} load failed ${o}`;return o};function n(s){(async i=>{try{let a=new Blob([i],{type:"application/javascript"}),g=URL.createObjectURL(a),l=await import(g);return URL.revokeObjectURL(g),l}catch(a){E(new S(`implement module evaluate error in native:${a} `))}})(s)}return()=>{try{let s=Date.now();P("jsSdkBegin",{t:s}),b.startTime=s;let o=r(t.bootstrapUrl),i=document.createElement("script");i.type="text/javascript",i.innerHTML=o,document.head.appendChild(i),_("implementModuleLoaded",Date.now()-s,{type:"native"});let a=r(t.implementUrl);n(a),_("bootstrapModuleLoaded",Date.now()-s,{type:"native"})}catch(s){console.error(`native load script error: ${s}`),E(new S(`module load failed ${s}`))}}};var Pt="1.1.4-beta.11",O=Pt,Ae=R(O),Ue=window.webkit||window.JoliAndroidSDKBridge?e=>{let t=window.prompt("invoke",JSON.stringify({event:"loadScriptSync",paramsString:JSON.stringify(e)}));if(t){let{data:r}=JSON.parse(t);return r}}:void 0,Ot=typeof Ue<"u",te=e=>`https://cdn.jsdelivr.net/npm/@jolibox/bootstrap@${e}/dist/index.js`,re=e=>`https://cdn.jsdelivr.net/npm/@jolibox/implement@${e}/dist/index.js`,Kt=e=>/^\d+\.\d+\.\d+$/.test(e),De=Kt(O)?Ae:O,Te=te(De),we=re(De);function Mt(){Ot?Ie(Ue,{bootstrapUrl:Te,implementUrl:we})():Re({bootstrapUrl:Te,implementUrl:we,currentMajorVersion:Ae,currentVersion:O})()}Mt();var Le=p();function ke(){return Le.excuteCommandSync("API.getSystemInfoSync")}function Ce(){return Le.excuteCommandSync("API.env")}function Pe(e,t){return de.config[e]?.[t]}function Oe(e,t,r){let n=Array.isArray(t)?t:t.replace(/\[(\d+)\]/g,".$1").split("."),s=e;for(let o of n)if(s&&(typeof s=="object"||Array.isArray(s)))s=s[o];else return r;return s===void 0?r:s}var Me="1.1.4-beta.11";function y(e){let r=Ce().data?.deviceInfo?.platform;if(!r)return!1;let[n,...s]=e.split(":"),o=Pe(r=="h5"?r:"native",n);if(!o)return!1;let i=o.version;return typeof i!="string"||z(Me,i,"<")?!1:s.length===0?!0:Ke(o,s)||Ke(o.properties,s)}function Ke(e,t){if(!e)return!1;let r=Oe(e,t);return r?ie(r)?!0:W(r)?z(Me,r,">="):!1:!1}var Ne=p();async function je(){return y("login")?await Ne.executeCommand("API.login"):{code:"FAILURE",message:"[Jolibox SDK]login is not supported in this platform"}}async function Je(){return y("checkSession")?await Ne.executeCommand("API.checkSession"):{code:"FAILURE",message:"[Jolibox SDK]checkSession is not supported in this platform"}}var Fe=window.JoliboxRuntime;var d=class{constructor(){this.commands=p();this._emitter=new Q}addEventListener(t,r){this._emitter.on(t,(...n)=>r(n[0]))}triggerEvent(t,r){this._emitter.emit(t,r)}canUse(t){return y(t)}canIUseIfThrow(t){if(!this.canUse(t))return{code:"FAILURE",message:`[Jolibox SDK] ${t} is not supported in this platform`}}};var Nt="LifecycleSDK.onReady",K=class extends d{constructor(){super()}onReady(t){let r=n=>{t.call(this,n),this.triggerEvent(Nt,n)};this.commands.executeCommand("LifecycleSDK.onReady",r.bind(this))}exit(t){let r=this.canIUseIfThrow("lifeCycle.exit");if(r)return r;this.commands.executeCommand("LifecycleSDK.exit",t.onBeforeExit)}onJoliboxHide(t){this.commands.executeCommand("LifecycleSDK.onJoliboxHide",t.bind(this))}onJoliboxShow(t){this.commands.executeCommand("LifecycleSDK.onJoliboxShow",t.bind(this))}};var M=class extends d{async getItem(t){return await this.commands.executeCommand("StorageSDK.getItem",t)}async setItem(t,r){if(t.length>128)return{code:"PARAMETER_ERROR",message:"[SDK] cloud storage setItem error: length of key should be less than 128"};let n=typeof r=="string"?r:String(r);return t.length+n.length>1024?{code:"PARAMETER_ERROR",message:"[SDK] cloud storage setItem error: length of key and value should be less than 1024"}:await this.commands.executeCommand("StorageSDK.setItem",t,r)}async removeItem(t){return this.commands.executeCommand("StorageSDK.removeItem",t)}async clear(){return this.commands.executeCommand("StorageSDK.clear")}};var N=class extends d{constructor(){super();this.init=r=>{this.commands.executeCommand("AdsSDK.init",r)};this.adConfig=r=>{this.commands.executeCommand("AdsSDK.adConfig",r)};this.adBreak=r=>{this.commands.executeCommand("AdsSDK.adBreak",r)};this.adUnit=r=>{this.commands.executeCommand("AdsSDK.adUnit",r)}}};var j=class extends d{showKeyboard(t){let r=this.canIUseIfThrow("keyboard.showKeyboard");if(r)return r;this.commands.executeCommand("KeyboardSDK.showKeyboard",t)}updateKeyboard(t){let r=this.canIUseIfThrow("keyboard.updateKeyboard");if(r)return r;this.commands.executeCommand("KeyboardSDK.updateKeyboard",{value:t})}hideKeyboard(){let t=this.canIUseIfThrow("keyboard.hideKeyboard");if(t)return t;this.commands.executeCommand("KeyboardSDK.hideKeyboard")}};var J=class extends d{async onLevelFinished(t,r,n){let s=this.canIUseIfThrow("TaskTrackerSDK.onLevelFinished");return s?Promise.resolve(s):await this.commands.executeCommand("TaskTrackerSDK.levelFinished",t,{result:r,duration:n})}async onTaskFinished(t,r){let n=this.canIUseIfThrow("TaskTrackerSDK.onTaskFinished");return n||await this.commands.executeCommand("TaskTrackerSDK.taskFinished",t,{duration:r})}async onTaskEvent(t,r){let n=this.canIUseIfThrow("TaskTrackerSDK.onTaskEvent");return n||await this.commands.executeCommand("TaskTrackerSDK.taskEvent",t,r)}async onLevelUpgrade(t,r){let n=this.canIUseIfThrow("TaskTrackerSDK.onLevelUpgrade");return n||await this.commands.executeCommand("TaskTrackerSDK.levelUpgrade",t,r)}async onHistoryUserLevel(t){let r=this.canIUseIfThrow("TaskTrackerSDK.onHistoryUserLevel");return r||await this.commands.executeCommand("TaskTrackerSDK.historyUserLevel",t)}async onHistoryUserScore(t){let r=this.canIUseIfThrow("TaskTrackerSDK.onHistoryUserScore");return r||await this.commands.executeCommand("TaskTrackerSDK.historyUserScore",t)}};var F=class{constructor(){this.jssdkVersion="1.1.4-beta.11";this.runtime=new Fe;this.ads=new N;this.lifecycle=new K;this.storage=new M;this.keyboard=new j;this.task=new J;this.getSystemInfoSync=ke.bind(this);this.canIUse=y.bind(this);this.login=je.bind(this);this.checkSession=Je.bind(this)}};window.JoliboxSDK=F;
package/dist/index.d.ts CHANGED
@@ -2,23 +2,32 @@
2
2
  /**
3
3
  * global error catch
4
4
  */
5
- import './errors';
5
+ import './events';
6
6
  import './loader';
7
7
  /**
8
8
  * @public Jolibox JS SDK Entry
9
9
  */
10
- import { getSystemInfo, getSystemInfoSync, canIUse } from './api';
10
+ import { getSystemInfoSync, canIUse, login, checkSession } from './api';
11
11
  import { LifecycleSDK } from './sdks/lifecycle';
12
12
  import { StorageSDK } from './sdks/storage';
13
13
  import { JoliboxAds } from './sdks/ads';
14
14
  import { KeyboardSDK } from './sdks/keyboard';
15
+ import { TaskTrackerSDK } from './sdks/task';
16
+ declare global {
17
+ interface Window {
18
+ JoliboxSDK: typeof JoliboxSDK;
19
+ }
20
+ }
15
21
  export declare class JoliboxSDK {
22
+ readonly jssdkVersion = "__JOLIBOX_LOCAL_SDK_VERSION__";
16
23
  readonly runtime: any;
17
24
  readonly ads: JoliboxAds;
18
25
  readonly lifecycle: LifecycleSDK;
19
26
  readonly storage: StorageSDK;
20
27
  readonly keyboard: KeyboardSDK;
21
- getSystemInfo: typeof getSystemInfo;
28
+ readonly task: TaskTrackerSDK;
22
29
  getSystemInfoSync: typeof getSystemInfoSync;
23
30
  canIUse: typeof canIUse;
31
+ login: typeof login;
32
+ checkSession: typeof checkSession;
24
33
  }
@@ -0,0 +1 @@
1
+ var ne=Object.defineProperty,Be=Object.getOwnPropertyDescriptor,Ve=(e,t)=>{for(var r in t)ne(e,r,{get:t[r],enumerable:!0})},se=(e,t,r,n)=>{for(var s=n>1?void 0:n?Be(t,r):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(s=(n?i(t,r,s):i(s))||s);return n&&s&&ne(t,r,s),s};function $e(e){return new Promise(t=>{setTimeout(()=>{t()},e)})}function G(e){return typeof e=="string"}function oe(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&!(e instanceof RegExp)&&!(e instanceof Date)}function Ge(e){return typeof e>"u"}function He(e){return Ge(e)||e===null}function We(e){return typeof e=="function"}function ie(e){let t=e,r=null,n=function(...s){return r||(r=new t(...s)),r};return n.prototype=t.prototype,n}var ze=(e=>(e[e.DEVELOPER_FILE_NOT_FOUND=0]="DEVELOPER_FILE_NOT_FOUND",e[e.INTERNAL_IOS_CAN_NOT_FOUND_PKG=1]="INTERNAL_IOS_CAN_NOT_FOUND_PKG",e[e.USER_IOS_LOAD_TIMEOUT=2]="USER_IOS_LOAD_TIMEOUT",e[e.INTERNAL_IOS_PKG_LOAD_ERROR=3]="INTERNAL_IOS_PKG_LOAD_ERROR",e[e.INTERNAL_IOS_PKG_PARSE_FAIL=4]="INTERNAL_IOS_PKG_PARSE_FAIL",e[e.USER_IOS_GET_EMPTY_DATA=5]="USER_IOS_GET_EMPTY_DATA",e[e.USER_ANDROID_GET_PKG_FAIL=6]="USER_ANDROID_GET_PKG_FAIL",e[e.DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE=7]="DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE",e))(ze||{}),Ye=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}},ae=class extends Ye{constructor(){super(...arguments),this.kind="INTERNAL_ERROR"}};var ce=class extends ae{constructor(){super(...arguments),this.name="INTERNAL_JS_MODULE_FETCH_ERROR",this.priority="P0"}},S=class extends ae{constructor(){super(...arguments),this.name="INTERNAL_JS_MODULE_EVAL_ERROR",this.priority="P0"}};function x(e){return(...t)=>{(globalThis.VConsole?.[e]??globalThis.console[e])(...t)}}var Qe={log:x("log"),warn:x("warn"),info:x("info"),error:x("error"),debug:x("debug")};Object.assign(globalThis,{logger:Qe});var le=Symbol.for("Jolibox.canIUseMap"),Xe={};globalThis[le]=Xe;var me={get config(){return globalThis[le]}};function H(e,t,r){let n=0;if(e!==t){let s=e.split("."),o=t.split("."),i=Math.max(s.length,o.length);for(let a=0;a<i;a++){let g=parseInt(s[a],10)||0,l=parseInt(o[a],10)||0;if(g>l){n=1;break}else if(g<l){n=-1;break}}}if(!r)return n;switch(r){case">":return n>0;case"<":return n<0;case"=":return n===0;case">=":return n>=0;case"<=":return n<=0;default:return!1}}var W=(e=>(e[e.System=1e3]="System",e[e.ErrorTrace=1001]="ErrorTrace",e[e.UserDefined=1002]="UserDefined",e))(W||{}),k=(e=>(e.MiniGame="mini-game",e.MiniDrama="mini-drama",e.App="app",e.WebSDK="web-sdk",e.AppSDK="app-sdk",e))(k||{}),qe=(e=>(e[e.App=0]="App",e[e.H5=1]="H5",e[e.Weapp=2]="Weapp",e[e.Alipay=3]="Alipay",e[e.Gcash=4]="Gcash",e[e.Dana=5]="Dana",e[e.Umma=6]="Umma",e[e.WebSDK=1e3]="WebSDK",e[e.AppSDK=1001]="AppSDK",e[e.Other=9999]="Other",e))(qe||{}),re=["name","params"],Ze=["name","type","location","target","extra","timestamp","userId"],et=["platform","os","appVersion","appId","model","brand","uuid","jsSdkVersion","extra"];function U(e,t){return t.map(r=>{if(r==="params"&&e[r]){let n=e[r];return Object.keys(n).reduce((s,o)=>(s[o]=String(n[o]),s),{})}return e[r]})}function tt(e){let t=e.location?U(e.location,re):null,r=e.target?U(e.target,re):null;return U({...e,location:t,target:r},Ze)}function de(e){let t=e.events.map(n=>tt(n)),r=U(e.device,et);return[e.protocolVersion,t,r,e.project]}var rt=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)});var w={isiOS:navigator.userAgent.includes("iPhone")||navigator.userAgent.includes("iPod")||navigator.userAgent.includes("iPad")||navigator.userAgent.includes("iPhone OS"),iosVersion:()=>{let e=navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/);return[parseInt(e[1],10),parseInt(e[2],10),parseInt(e[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")},nt=()=>w.isiOS?"iOS":w.isAndroid?"Android":w.isMac?"Mac":w.isFacebook?"Facebook":"PC",st="device_id",ot="advertising_id",ue=e=>(localStorage.getItem(e)||localStorage.setItem(e,rt()),localStorage.getItem(e)),it=()=>ue(st),at=()=>ue(ot),ct=e=>e.charAt(0).toUpperCase()+e.slice(1),lt=()=>{let e=new URLSearchParams(window.location.search);return ct(e.get("utm_source")??"")||"JoliboxSDK"},pe=e=>{let t="JoliboxWebSDK",r=nt(),n=navigator.language,s=it(),o=at();return`${t} (${lt()}${r}; UnknownModel; UnknownSystemVersion; ${n}) uuid/${s} adid/${o} version/${e||""}`},c=class D{static{this.Undefined=new D(void 0)}constructor(t){this.element=t,this.next=D.Undefined,this.prev=D.Undefined}},mt=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 s=this._last;this._last=r,r.prev=s,s.next=r}else{let s=this._first;this._first=r,r.next=s,s.prev=r}this._size+=1;let n=!1;return()=>{n||(n=!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}},dt=0,A=class{constructor(e){this.value=e,this.id=dt++}},v=class{constructor(e){this.options=e,this._size=0}dispose(e){this._disposed||(this._disposed=!0,this._listeners&&(e?(this._listeners instanceof A&&(this._listeners=[this._listeners]),this._listeners=this._listeners.filter(t=>t?.value===e)):(this._listeners=void 0,this._size=0)),this.options?.onDidRemoveLastListener?.())}get event(){return this._event??=(e,t)=>{if(this._disposed)return()=>{console.info("[Jolibox SDK] Emitter is _disposed")};t&&(e=e.bind(t));let r=new A(e);this._listeners?this._listeners instanceof A?this._listeners=[this._listeners,r]:this._listeners.push(r):(this.options?.onWillAddFirstListener?.(this),this._listeners=r,this.options?.onDidFirstListener?.(this)),this.options?.onDidAddListener?.(this),this._size++},this._event}_deliver(e,t){if(!e)return;let r=this.options?.onListenerError||Error.constructor;if(!r){e.value(t);return}try{e.value(t)}catch(n){r(n)}}fire(e){this._listeners&&(this._listeners instanceof A?this._deliver(this._listeners,e):this._listeners.forEach(t=>this._deliver(t,e)))}hasListeners(){return this._size>0}},z=class{constructor(){this.listeners=new Map,this.listerHandlerMap=new WeakMap,this.cachedEventQueue=new Map}on(e,t){let r=this.listeners.get(e)??new v,n=o=>t(...o.args);this.listerHandlerMap.set(t,n),r.event(n),this.listeners.set(e,r);let s=this.cachedEventQueue.get(e);if(s)for(;s.size>0;)r.fire({event:e,...s.shift()})}off(e,t){let r=this.listeners.get(e);if(r){let n=this.listerHandlerMap.get(t);r.dispose(n)}}emit(e,...t){let r=this.listeners.get(e);if(r)r.fire({event:e,args:t});else{let n=this.cachedEventQueue.get(e);n||(n=new mt,this.cachedEventQueue.set(e,n)),n.push({args:t})}}},V={};Ve(V,{None:()=>ut,filter:()=>ft,once:()=>fe,toPromise:()=>pt});var ut=()=>{console.log("[Jolibox SDK] None Event")};function pt(e){return new Promise(t=>fe(e)(t))}function fe(e){return(t,r=null)=>{let n=!1;return e(s=>{if(!n)return n=!0,t.call(r,s)},null)}}function ft(e,t){return(r=>{let n,s={onWillAddFirstListener(){n=r(o.fire,o)}},o=new v(s);return o.event})((r,n=null)=>e(s=>t(s)&&r.call(n,s),null))}var F=Symbol.for("Jolibox.hostEmitter"),ht=()=>{let e=new z;return globalThis[F]||(globalThis[F]={on:e.on.bind(e),off:e.off.bind(e),emit:e.emit.bind(e)}),globalThis[F]},he=ht();function gt(e,t){let r=Math.min(e.length,t.length);for(let n=0;n<r;n++)Et(e[n],t[n])}function Et(e,t){if(G(t)){if(typeof e!==t)throw new Error(`argument does not match constraint: typeof ${t}`)}else if(We(t)){try{if(e instanceof t)return}catch{}if(!He(e)&&e.constructor===t||t.length===1&&t.call(void 0,e)===!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 L=class{constructor(){this._commands=new Map,this._onDidRegisterCommand=new v,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 r=[];for(let s of e.metadata.args)r.push(s.constraint);let n=e.handler;e.handler=function(...s){return gt(s,r),n(...s)}}let{id:t}=e;this._commands.get(t)&&console.info(`[Jolibox SDK] duplicated command is registered ${t}`),this._commands.set(t,e),this._onDidRegisterCommand.fire(t)}getCommand(e){return this._commands.get(e)}getCommands(){let e=new Map;for(let t of this._commands.keys()){let r=this.getCommand(t);r&&e.set(t,r)}return e}};L=se([ie],L);var $=class{constructor(){this._onWillExecuteCommand=new v,this.onWillExecuteCommand=this._onWillExecuteCommand.event,this._onDidExecuteCommand=new v,this.onDidExecuteCommand=this._onDidExecuteCommand.event,this.registry=new L,this._starActivation=null}_activateStar(){return this._starActivation||(this._starActivation=$e(3e4)),this._starActivation}async executeCommand(e,...t){return this.registry.getCommand(e)?this._tryExecuteCommand(e,t):(await Promise.all([Promise.race([this._activateStar(),V.toPromise(V.filter(this.registry.onDidRegisterCommand,r=>r===e))])]),this._tryExecuteCommand(e,t))}executeCommandThowErr(e,...t){if(!this.registry.getCommand(e))throw new Error(`command '${e}' not found`);let r=this.registry.getCommand(e);this._onWillExecuteCommand.fire({commandId:e,args:t});let n=this.invokeFunction(r.handler,...t);return this._onDidExecuteCommand.fire({commandId:e,args:t}),n}_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 n=this.invokeFunction(r.handler,...t);return this._onDidExecuteCommand.fire({commandId:e,args:t}),Promise.resolve(n)}catch(n){return Promise.reject(n)}}invokeFunction(e,...t){let r=!1;try{return e(...t)}finally{r=!0}}};$=se([ie],$);var B=Symbol.for("Jolibox.commands");function p(){if(globalThis[B])return globalThis[B];let e=new L,t=new $,r={registerCommand(n,s,o){e.registerCommand({id:n,handler:s,metadata:o})},executeCommand(n,...s){return t.executeCommand(n,...s)},excuteCommandSync(n,...s){return t.executeCommandThowErr(n,...s)}};return globalThis[B]=r,r}var C=new URLSearchParams(window.location.search).get("joliboxEnv")==="staging";function _t(){let e=new URLSearchParams(window.location.search),t={};return e.forEach((r,n)=>{t[n]=r}),{name:"GamePage",params:t}}function yt(){return{platform:1e3,os:"h5",appVersion:"1.1.4-beta.11",appId:"1",model:"UnknownModel",brand:"UnknownBrand",uuid:"1",jsSdkVersion:"1.1.4-beta.11",extra:{}}}var ge={default:{test:"https://stg-collect.jolibox.com",prod:"https://collect.jolibox.com"},"oss.jolibox.com":{test:"https://stg-collect.jolibox.com",prod:"https://collect.jolibox.com"},"oss.pico-game.com":{test:"https://stg-collect.pico-game.com",prod:"https://collect.pico-game.com"}},St=()=>{let e=ge[window.location.host]??ge.default;return C?e.test:e.prod},xt=St(),Ee=e=>{let t=new AbortController;return setTimeout(()=>t.abort(),e),t.signal};AbortSignal.timeout??=Ee;var vt=()=>new URLSearchParams(window.location.search).get("joliSource")??null,bt=vt(),Rt=async e=>{let r=`${xt}/report`,n=pe("1.1.4-beta.11"),s=bt,o={"Content-Type":"application/json"};return n&&(o["x-user-agent"]=n),s&&(o["x-joli-source"]=s),await fetch(r,{method:"POST",headers:o,body:JSON.stringify(e),signal:Ee(5e3)})};async function Y(e,t,r){let n={name:e,type:W.ErrorTrace,location:_t(),target:null,extra:t,timestamp:Date.now(),userId:null},s=yt(),a=de({protocolVersion:"1.0.0",events:[n],device:s,project:r});Rt(a)}document.addEventListener("DOMContentLoaded",()=>he.emit("onDocumentReady",b.startTime));var It=()=>{let e=0;return{set startTime(t){e=t},get startTime(){return e}}},b=It(),_e=p(),Q=e=>{_e.executeCommand("ReportSDK.traceSystem",{event:"globalJsError",info:{err:JSON.stringify(e)}}).catch(t=>{console.error(`Fallback report: ${t} ${JSON.stringify(e)}`),Y("globalJsError",{err:JSON.stringify({message:t.message,source:t.source,lineno:t.lineno,colno:t.colno,error:t.error})},k.WebSDK)})},E=Q;window.addEventListener("unhandledrejection",Q.bind(void 0));window.addEventListener("error",Q.bind(void 0));window.onerror=(e,t,r,n,s)=>{_e.executeCommand("ReportSDK.traceSystem",{event:"globalJsError",info:{err:JSON.stringify({message:e,source:t,lineno:r,colno:n,error:s})}}).catch(o=>{Y("globalJsError",{err:JSON.stringify({message:e,source:t,lineno:r,colno:n,error:s})},k.WebSDK)})};var X=e=>{let t=e.split("-")[1];t&&(e=e.replace(`-${t}`,""));let r=e.split("+")[1];r&&(e=e.replace(`+${r}`,""));let n=e.split(".").slice(0,3),[s,o,i]=[n[0]??"0",n[1]??"0",n[2]??"0"];return{major:s,minor:o,patch:i,prerelease:t,build:r}},R=e=>parseInt(X(e).major,10),I=(e,t)=>{let{major:r,minor:n,patch:s}=X(e),{major:o,minor:i,patch:a}=X(t);return r!==o?r>o?1:-1:n!==i?n>i?1:-1:s!==a?s>a?1:-1:0};var ye=p(),P=(e,t)=>{ye.executeCommand("ReportSDK.traceSystem",{event:e,info:t})},_=(e,t,r)=>{ye.executeCommand("ReportSDK.traceSystemTimeline",{event:e,duration:t,extra:r})};var ve="jolibox-sdk-loadermeta",T=JSON.parse(localStorage.getItem(ve)??"{}"),q=Date.now(),Se=(e,t)=>e>t&&Math.abs(e-t)/(1e3*60*60*24)>=7,xe=e=>!/^(Failed to fetch version|Couldn't find the requested file)/.test(e);async function Tt(){let t=`${C?"https://stg-api.jolibox.com":"https://api.jolibox.com"}/api/fe-configs/js-sdk/version_metadata`;try{let r=await fetch(t,{method:"GET",headers:{"Content-Type":"application/json"}}),{implement_version:n,bootstrap_version:s}=await r.json(),o={...T,timestamp:q};if(s){let{bootstrap_version:i}=T;if(!(i&&I(i,s)>=0)){let a=await(await fetch(Z(s))).text();xe(a)&&(o={...o,bootstrap_version:s,bootstrap_script:a})}}if(n){let{implement_version:i}=T;if(!(i&&I(i,n)>=0)){let a=await(await fetch(ee(n))).text();xe(a)&&(o={...o,implement_version:n,implement_script:a})}}localStorage.setItem(ve,JSON.stringify(o))}catch(r){console.warn("Failed to fetch loader metadata: ",r)}}var be=e=>{let{currentMajorVersion:t,currentVersion:r,bootstrapUrl:n,implementUrl:s}=e;function o(){let{bootstrap_version:l,bootstrap_script:f,timestamp:u}=T;if(l&&f&&u&&!Se(q,u)&&R(l)==t&&I(l,r)>=0)return{script:f,type:"localscript"};try{let m=new XMLHttpRequest;return m.open("GET",n,!1),m.send(),{script:m.responseText,type:"fetch_from_cdn"}}catch(m){E(new ce(`Bootstrap module faile to fetch ${m}`))}}function i(){let l=Date.now();P("jsSdkBegin",{t:l}),b.startTime=l;let{script:f,type:u}=o()??{};if(f){let m=document.createElement("script");m.type="text/javascript",m.innerHTML=f,document.head.appendChild(m),_("bootstrapModuleLoaded",Date.now()-l,{type:u})}}function a(l){(async u=>{try{let m=new Blob([u],{type:"application/javascript"}),h=URL.createObjectURL(m),Fe=await import(h);return URL.revokeObjectURL(h),Fe}catch(m){E(new S(`implement module evaluate error in h5:${m} `))}})(l)}function g(){let l=Date.now(),{implement_script:f,implement_version:u,timestamp:m}=T;if(f&&u&&m&&!Se(q,m)&&R(u)==t&&I(u,r)>=0){a(f),_("implementModuleLoaded",Date.now()-l,{type:"loadscript"});return}let h=document.createElement("script");h.type="module",h.crossOrigin="anonymous",h.src=s,h.onload=()=>{_("bootstrapModuleLoaded",Date.now()-l,{type:"fetch_from_cdn"})},document.head.appendChild(h)}return()=>{try{i(),g(),Tt()}catch(l){E(new S(`module evaluate error: ${l}`))}}};var Re=(e,t)=>{let r=s=>{let o=e({path:s});if(!o)throw`module ${s} load failed ${o}`;return o};function n(s){(async i=>{try{let a=new Blob([i],{type:"application/javascript"}),g=URL.createObjectURL(a),l=await import(g);return URL.revokeObjectURL(g),l}catch(a){E(new S(`implement module evaluate error in native:${a} `))}})(s)}return()=>{try{let s=Date.now();P("jsSdkBegin",{t:s}),b.startTime=s;let o=r(t.bootstrapUrl),i=document.createElement("script");i.type="text/javascript",i.innerHTML=o,document.head.appendChild(i),_("implementModuleLoaded",Date.now()-s,{type:"native"});let a=r(t.implementUrl);n(a),_("bootstrapModuleLoaded",Date.now()-s,{type:"native"})}catch(s){console.error(`native load script error: ${s}`),E(new S(`module load failed ${s}`))}}};var wt="1.1.4-beta.11",O=wt,we=R(O),Ae=window.webkit||window.JoliAndroidSDKBridge?e=>{let t=window.prompt("invoke",JSON.stringify({event:"loadScriptSync",paramsString:JSON.stringify(e)}));if(t){let{data:r}=JSON.parse(t);return r}}:void 0,At=typeof Ae<"u",Z=e=>`https://cdn.jsdelivr.net/npm/@jolibox/bootstrap@${e}/dist/index.js`,ee=e=>`https://cdn.jsdelivr.net/npm/@jolibox/implement@${e}/dist/index.js`,Ut=e=>/^\d+\.\d+\.\d+$/.test(e),Ue=Ut(O)?we:O,Ie=Z(Ue),Te=ee(Ue);function Dt(){At?Re(Ae,{bootstrapUrl:Ie,implementUrl:Te})():be({bootstrapUrl:Ie,implementUrl:Te,currentMajorVersion:we,currentVersion:O})()}Dt();var De=p();function Le(){return De.excuteCommandSync("API.getSystemInfoSync")}function ke(){return De.excuteCommandSync("API.env")}function Ce(e,t){return me.config[e]?.[t]}function Pe(e,t,r){let n=Array.isArray(t)?t:t.replace(/\[(\d+)\]/g,".$1").split("."),s=e;for(let o of n)if(s&&(typeof s=="object"||Array.isArray(s)))s=s[o];else return r;return s===void 0?r:s}var Ke="1.1.4-beta.11";function y(e){let r=ke().data?.deviceInfo?.platform;if(!r)return!1;let[n,...s]=e.split(":"),o=Ce(r=="h5"?r:"native",n);if(!o)return!1;let i=o.version;return typeof i!="string"||H(Ke,i,"<")?!1:s.length===0?!0:Oe(o,s)||Oe(o.properties,s)}function Oe(e,t){if(!e)return!1;let r=Pe(e,t);return r?oe(r)?!0:G(r)?H(Ke,r,">="):!1:!1}var Me=p();async function Ne(){return y("login")?await Me.executeCommand("API.login"):{code:"FAILURE",message:"[Jolibox SDK]login is not supported in this platform"}}async function je(){return y("checkSession")?await Me.executeCommand("API.checkSession"):{code:"FAILURE",message:"[Jolibox SDK]checkSession is not supported in this platform"}}var Je=window.JoliboxRuntime;var d=class{constructor(){this.commands=p();this._emitter=new z}addEventListener(t,r){this._emitter.on(t,(...n)=>r(n[0]))}triggerEvent(t,r){this._emitter.emit(t,r)}canUse(t){return y(t)}canIUseIfThrow(t){if(!this.canUse(t))return{code:"FAILURE",message:`[Jolibox SDK] ${t} is not supported in this platform`}}};var Lt="LifecycleSDK.onReady",K=class extends d{constructor(){super()}onReady(t){let r=n=>{t.call(this,n),this.triggerEvent(Lt,n)};this.commands.executeCommand("LifecycleSDK.onReady",r.bind(this))}exit(t){let r=this.canIUseIfThrow("lifeCycle.exit");if(r)return r;this.commands.executeCommand("LifecycleSDK.exit",t.onBeforeExit)}onJoliboxHide(t){this.commands.executeCommand("LifecycleSDK.onJoliboxHide",t.bind(this))}onJoliboxShow(t){this.commands.executeCommand("LifecycleSDK.onJoliboxShow",t.bind(this))}};var M=class extends d{async getItem(t){return await this.commands.executeCommand("StorageSDK.getItem",t)}async setItem(t,r){if(t.length>128)return{code:"PARAMETER_ERROR",message:"[SDK] cloud storage setItem error: length of key should be less than 128"};let n=typeof r=="string"?r:String(r);return t.length+n.length>1024?{code:"PARAMETER_ERROR",message:"[SDK] cloud storage setItem error: length of key and value should be less than 1024"}:await this.commands.executeCommand("StorageSDK.setItem",t,r)}async removeItem(t){return this.commands.executeCommand("StorageSDK.removeItem",t)}async clear(){return this.commands.executeCommand("StorageSDK.clear")}};var N=class extends d{constructor(){super();this.init=r=>{this.commands.executeCommand("AdsSDK.init",r)};this.adConfig=r=>{this.commands.executeCommand("AdsSDK.adConfig",r)};this.adBreak=r=>{this.commands.executeCommand("AdsSDK.adBreak",r)};this.adUnit=r=>{this.commands.executeCommand("AdsSDK.adUnit",r)}}};var j=class extends d{showKeyboard(t){let r=this.canIUseIfThrow("keyboard.showKeyboard");if(r)return r;this.commands.executeCommand("KeyboardSDK.showKeyboard",t)}updateKeyboard(t){let r=this.canIUseIfThrow("keyboard.updateKeyboard");if(r)return r;this.commands.executeCommand("KeyboardSDK.updateKeyboard",{value:t})}hideKeyboard(){let t=this.canIUseIfThrow("keyboard.hideKeyboard");if(t)return t;this.commands.executeCommand("KeyboardSDK.hideKeyboard")}};var J=class extends d{async onLevelFinished(t,r,n){let s=this.canIUseIfThrow("TaskTrackerSDK.onLevelFinished");return s?Promise.resolve(s):await this.commands.executeCommand("TaskTrackerSDK.levelFinished",t,{result:r,duration:n})}async onTaskFinished(t,r){let n=this.canIUseIfThrow("TaskTrackerSDK.onTaskFinished");return n||await this.commands.executeCommand("TaskTrackerSDK.taskFinished",t,{duration:r})}async onTaskEvent(t,r){let n=this.canIUseIfThrow("TaskTrackerSDK.onTaskEvent");return n||await this.commands.executeCommand("TaskTrackerSDK.taskEvent",t,r)}async onLevelUpgrade(t,r){let n=this.canIUseIfThrow("TaskTrackerSDK.onLevelUpgrade");return n||await this.commands.executeCommand("TaskTrackerSDK.levelUpgrade",t,r)}async onHistoryUserLevel(t){let r=this.canIUseIfThrow("TaskTrackerSDK.onHistoryUserLevel");return r||await this.commands.executeCommand("TaskTrackerSDK.historyUserLevel",t)}async onHistoryUserScore(t){let r=this.canIUseIfThrow("TaskTrackerSDK.onHistoryUserScore");return r||await this.commands.executeCommand("TaskTrackerSDK.historyUserScore",t)}};var te=class{constructor(){this.jssdkVersion="1.1.4-beta.11";this.runtime=new Je;this.ads=new N;this.lifecycle=new K;this.storage=new M;this.keyboard=new j;this.task=new J;this.getSystemInfoSync=Le.bind(this);this.canIUse=y.bind(this);this.login=Ne.bind(this);this.checkSession=je.bind(this)}};window.JoliboxSDK=te;export{te as JoliboxSDK};
@@ -1 +1 @@
1
- "use strict";(()=>{var W=Object.defineProperty,Ie=Object.getOwnPropertyDescriptor,Ue=(e,t)=>{for(var r in t)W(e,r,{get:t[r],enumerable:!0})},Q=(e,t,r,n)=>{for(var s=n>1?void 0:n?Ie(t,r):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(s=(n?i(t,r,s):i(s))||s);return n&&s&&W(t,r,s),s};function Ae(e){return new Promise(t=>{setTimeout(()=>{t()},e)})}function k(e){return typeof e=="string"}function Y(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&!(e instanceof RegExp)&&!(e instanceof Date)}function Le(e){return typeof e>"u"}function we(e){return Le(e)||e===null}function Ce(e){return typeof e=="function"}function X(e){let t=e,r=null,n=function(...s){return r||(r=new t(...s)),r};return n.prototype=t.prototype,n}var Te=(e=>(e[e.DEVELOPER_FILE_NOT_FOUND=0]="DEVELOPER_FILE_NOT_FOUND",e[e.INTERNAL_IOS_CAN_NOT_FOUND_PKG=1]="INTERNAL_IOS_CAN_NOT_FOUND_PKG",e[e.USER_IOS_LOAD_TIMEOUT=2]="USER_IOS_LOAD_TIMEOUT",e[e.INTERNAL_IOS_PKG_LOAD_ERROR=3]="INTERNAL_IOS_PKG_LOAD_ERROR",e[e.INTERNAL_IOS_PKG_PARSE_FAIL=4]="INTERNAL_IOS_PKG_PARSE_FAIL",e[e.USER_IOS_GET_EMPTY_DATA=5]="USER_IOS_GET_EMPTY_DATA",e[e.USER_ANDROID_GET_PKG_FAIL=6]="USER_ANDROID_GET_PKG_FAIL",e[e.DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE=7]="DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE",e))(Te||{}),De=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}},q=class extends De{constructor(){super(...arguments),this.kind="INTERNAL_ERROR"}};var Z=class extends q{constructor(){super(...arguments),this.name="INTERNAL_JS_MODULE_FETCH_ERROR",this.priority="P0"}},y=class extends q{constructor(){super(...arguments),this.name="INTERNAL_JS_MODULE_EVAL_ERROR",this.priority="P0"}};function R(e){return(...t)=>{(globalThis.VConsole?.[e]??globalThis.console[e])(...t)}}var Oe={log:R("log"),warn:R("warn"),info:R("info"),error:R("error"),debug:R("debug")};Object.assign(globalThis,{logger:Oe});var ee=Symbol.for("Jolibox.canIUseMap"),Ne={};globalThis[ee]=Ne;var te={get config(){return globalThis[ee]}};function j(e,t,r){let n=0;if(e!==t){let s=e.split("."),o=t.split("."),i=Math.max(s.length,o.length);for(let l=0;l<i;l++){let _=parseInt(s[l],10)||0,c=parseInt(o[l],10)||0;if(_>c){n=1;break}else if(_<c){n=-1;break}}}if(!r)return n;switch(r){case">":return n>0;case"<":return n<0;case"=":return n===0;case">=":return n>=0;case"<=":return n<=0;default:return!1}}var a=class U{static{this.Undefined=new U(void 0)}constructor(t){this.element=t,this.next=U.Undefined,this.prev=U.Undefined}},Ke=class{constructor(){this._first=a.Undefined,this._last=a.Undefined,this._size=0}get size(){return this._size}isEmpty(){return this._first===a.Undefined}clear(){let e=this._first;for(;e!==a.Undefined;){let t=e.next;e.prev=a.Undefined,e.next=a.Undefined,e=t}this._first=a.Undefined,this._last=a.Undefined,this._size=0}unshift(e){return this._insert(e,!1)}push(e){return this._insert(e,!0)}_insert(e,t){let r=new a(e);if(this._first===a.Undefined)this._first=r,this._last=r;else if(t){let s=this._last;this._last=r,r.prev=s,s.next=r}else{let s=this._first;this._first=r,r.next=s,s.prev=r}this._size+=1;let n=!1;return()=>{n||(n=!0,this._remove(r))}}shift(){if(this._first!==a.Undefined){let e=this._first.element;return this._remove(this._first),e}}pop(){if(this._last!==a.Undefined){let e=this._last.element;return this._remove(this._last),e}}_remove(e){if(e.prev!==a.Undefined&&e.next!==a.Undefined){let t=e.prev;t.next=e.next,e.next.prev=t}else e.prev===a.Undefined&&e.next===a.Undefined?(this._first=a.Undefined,this._last=a.Undefined):e.next===a.Undefined?(this._last=this._last.prev,this._last.next=a.Undefined):e.prev===a.Undefined&&(this._first=this._first.next,this._first.prev=a.Undefined);this._size-=1}*[Symbol.iterator](){let e=this._first;for(;e!==a.Undefined;)yield e.element,e=e.next}},Pe=0,I=class{constructor(e){this.value=e,this.id=Pe++}},v=class{constructor(e){this.options=e,this._size=0}dispose(e){this._disposed||(this._disposed=!0,this._listeners&&(e?(this._listeners instanceof I&&(this._listeners=[this._listeners]),this._listeners=this._listeners.filter(t=>t?.value===e)):(this._listeners=void 0,this._size=0)),this.options?.onDidRemoveLastListener?.())}get event(){return this._event??=(e,t)=>{if(this._disposed)return()=>{console.info("[Jolibox SDK] Emitter is _disposed")};t&&(e=e.bind(t));let r=new I(e);this._listeners?this._listeners instanceof I?this._listeners=[this._listeners,r]:this._listeners.push(r):(this.options?.onWillAddFirstListener?.(this),this._listeners=r,this.options?.onDidFirstListener?.(this)),this.options?.onDidAddListener?.(this),this._size++},this._event}_deliver(e,t){if(!e)return;let r=this.options?.onListenerError||Error.constructor;if(!r){e.value(t);return}try{e.value(t)}catch(n){r(n)}}fire(e){this._listeners&&(this._listeners instanceof I?this._deliver(this._listeners,e):this._listeners.forEach(t=>this._deliver(t,e)))}hasListeners(){return this._size>0}},J=class{constructor(){this.listeners=new Map,this.listerHandlerMap=new WeakMap,this.cachedEventQueue=new Map}on(e,t){let r=this.listeners.get(e)??new v,n=o=>t(...o.args);this.listerHandlerMap.set(t,n),r.event(n),this.listeners.set(e,r);let s=this.cachedEventQueue.get(e);if(s)for(;s.size>0;)r.fire({event:e,...s.shift()})}off(e,t){let r=this.listeners.get(e);if(r){let n=this.listerHandlerMap.get(t);r.dispose(n)}}emit(e,...t){let r=this.listeners.get(e);if(r)r.fire({event:e,args:t});else{let n=this.cachedEventQueue.get(e);n||(n=new Ke,this.cachedEventQueue.set(e,n)),n.push({args:t})}}},P={};Ue(P,{None:()=>Me,filter:()=>je,once:()=>re,toPromise:()=>ke});var Me=()=>{console.log("[Jolibox SDK] None Event")};function ke(e){return new Promise(t=>re(e)(t))}function re(e){return(t,r=null)=>{let n=!1;return e(s=>{if(!n)return n=!0,t.call(r,s)},null)}}function je(e,t){return(r=>{let n,s={onWillAddFirstListener(){n=r(o.fire,o)}},o=new v(s);return o.event})((r,n=null)=>e(s=>t(s)&&r.call(n,s),null))}var N=Symbol.for("Jolibox.hostEmitter"),Je=()=>{let e=new J;return globalThis[N]||(globalThis[N]={on:e.on.bind(e),off:e.off.bind(e),emit:e.emit.bind(e)}),globalThis[N]},ne=Je();function Fe(e,t){let r=Math.min(e.length,t.length);for(let n=0;n<r;n++)Be(e[n],t[n])}function Be(e,t){if(k(t)){if(typeof e!==t)throw new Error(`argument does not match constraint: typeof ${t}`)}else if(Ce(t)){try{if(e instanceof t)return}catch{}if(!we(e)&&e.constructor===t||t.length===1&&t.call(void 0,e)===!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 A=class{constructor(){this._commands=new Map,this._onDidRegisterCommand=new v,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 r=[];for(let s of e.metadata.args)r.push(s.constraint);let n=e.handler;e.handler=function(...s){return Fe(s,r),n(...s)}}let{id:t}=e;this._commands.get(t)&&console.info(`[Jolibox SDK] duplicated command is registered ${t}`),this._commands.set(t,e),this._onDidRegisterCommand.fire(t)}getCommand(e){return this._commands.get(e)}getCommands(){let e=new Map;for(let t of this._commands.keys()){let r=this.getCommand(t);r&&e.set(t,r)}return e}};A=Q([X],A);var M=class{constructor(){this._onWillExecuteCommand=new v,this.onWillExecuteCommand=this._onWillExecuteCommand.event,this._onDidExecuteCommand=new v,this.onDidExecuteCommand=this._onDidExecuteCommand.event,this.registry=new A,this._starActivation=null}_activateStar(){return this._starActivation||(this._starActivation=Ae(3e4)),this._starActivation}async executeCommand(e,...t){return this.registry.getCommand(e)?this._tryExecuteCommand(e,t):(await Promise.all([Promise.race([this._activateStar(),P.toPromise(P.filter(this.registry.onDidRegisterCommand,r=>r===e))])]),this._tryExecuteCommand(e,t))}executeCommandThowErr(e,...t){if(!this.registry.getCommand(e))throw new Error(`command '${e}' not found`);let r=this.registry.getCommand(e);this._onWillExecuteCommand.fire({commandId:e,args:t});let n=this.invokeFunction(r.handler,...t);return this._onDidExecuteCommand.fire({commandId:e,args:t}),n}_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 n=this.invokeFunction(r.handler,...t);return this._onDidExecuteCommand.fire({commandId:e,args:t}),Promise.resolve(n)}catch(n){return Promise.reject(n)}}invokeFunction(e,...t){let r=!1;try{return e(...t)}finally{r=!0}}};M=Q([X],M);var K=Symbol.for("Jolibox.commands");function h(){if(globalThis[K])return globalThis[K];let e=new A,t=new M,r={registerCommand(n,s,o){e.registerCommand({id:n,handler:s,metadata:o})},executeCommand(n,...s){return t.executeCommand(n,...s)},excuteCommandSync(n,...s){return t.executeCommandThowErr(n,...s)}};return globalThis[K]=r,r}document.addEventListener("DOMContentLoaded",()=>ne.emit("onDocumentReady"));var se=h(),F=e=>{se.executeCommand("ReportSDK.traceSystem",{event:"global_js_error",info:{err:JSON.stringify(e)}}).catch(t=>{console.error(`Fallback report: ${t} ${JSON.stringify(e)}`)})},g=F;window.addEventListener("unhandledrejection",F.bind(void 0));window.addEventListener("error",F.bind(void 0));window.onerror=(e,t,r,n,s)=>{se.executeCommand("ReportSDK.traceSystem",{event:"global_js_error",info:{err:JSON.stringify({message:e,source:t,lineno:r,colno:n,error:s})}}).catch(o=>{console.error(`Fallback report: ${o} ${JSON.stringify(e)}`)})};var B=e=>{let t=e.split("-")[1];t&&(e=e.replace(`-${t}`,""));let r=e.split("+")[1];r&&(e=e.replace(`+${r}`,""));let n=e.split(".").slice(0,3),[s,o,i]=[n[0]??"0",n[1]??"0",n[2]??"0"];return{major:s,minor:o,patch:i,prerelease:t,build:r}},S=e=>parseInt(B(e).major,10),b=(e,t)=>{let{major:r,minor:n,patch:s}=B(e),{major:o,minor:i,patch:l}=B(t);return r!==o?r>o?1:-1:n!==i?n>i?1:-1:s!==l?s>l?1:-1:0};var oe=h(),L=(e,t)=>{oe.executeCommand("ReportSDK.traceSystem",{event:e,info:t})},E=(e,t,r)=>{oe.executeCommand("ReportSDK.traceSystemTimeline",{event:e,duration:t,extra:r})};var ce="jolibox-sdk-loadermeta",x=JSON.parse(localStorage.getItem(ce)??"{}"),V=Date.now(),ie=(e,t)=>e>t&&Math.abs(e-t)/(1e3*60*60*24)>=7,ae=e=>!/^(Failed to fetch version|Couldn't find the requested file)/.test(e);async function Ve(){let e="https://stg-api.jolibox.com/api/fe-configs/js-sdk/version_metadata";try{let t=await fetch(e,{method:"GET",headers:{"Content-Type":"application/json"}}),{implement_version:r,bootstrap_version:n}=await t.json(),s={...x,timestamp:V};if(n){let{bootstrap_version:o}=x;if(!(o&&b(o,n))){let i=await(await fetch(G(n))).text();ae(i)&&(s={...s,bootstrap_version:n,bootstrap_script:i})}}if(r){let{implement_version:o}=x;if(!(o&&b(o,r))){let i=await(await fetch($(r))).text();ae(i)&&(s={...s,implement_version:r,implement_script:i})}}localStorage.setItem(ce,JSON.stringify(s))}catch(t){console.warn("Failed to fetch loader metadata: ",t)}}var me=e=>{let{currentMajorVersion:t,currentVersion:r,bootstrapUrl:n,implementUrl:s}=e;function o(){let{bootstrap_version:c,bootstrap_script:p,timestamp:d}=x;if(c&&p&&d&&!ie(V,d)&&S(c)==t&&b(c,r)>0)return{script:p,type:"localscript"};try{let m=new XMLHttpRequest;return m.open("GET",n,!1),m.send(),{script:m.responseText,type:"fetch_from_cdn"}}catch(m){g(new Z(`Bootstrap module faile to fetch ${m}`))}}function i(){let c=Date.now();L("js_sdk_begin",{t:c});let{script:p,type:d}=o()??{};if(p){let m=document.createElement("script");m.type="text/javascript",m.innerHTML=p,document.head.appendChild(m),E("bootstrapModuleLoaded",Date.now()-c,{type:d})}}function l(c){(async d=>{try{let m=new Blob([d],{type:"application/javascript"}),f=URL.createObjectURL(m),xe=await import(f);return URL.revokeObjectURL(f),xe}catch(m){g(new y(`implement module evaluate error in h5:${m} `))}})(c)}function _(){let c=Date.now(),{implement_script:p,implement_version:d,timestamp:m}=x;if(p&&d&&m&&!ie(V,m)&&S(d)==t&&b(d,r)>0){l(p),E("implementModuleLoaded",Date.now()-c,{type:"loadscript"});return}let f=document.createElement("script");f.type="module",f.crossOrigin="anonymous",f.src=s,f.onload=()=>{E("bootstrapModuleLoaded",Date.now()-c,{type:"fetch_from_cdn"})},document.head.appendChild(f)}return()=>{try{i(),_(),Ve()}catch(c){g(new y(`module evaluate error: ${c}`))}}};var le=(e,t)=>{let r=s=>{let o=e({path:s});if(!o)throw`module ${s} load failed ${o}`;return o};function n(s){(async i=>{try{let l=new Blob([i],{type:"application/javascript"}),_=URL.createObjectURL(l),c=await import(_);return URL.revokeObjectURL(_),c}catch(l){g(new y(`implement module evaluate error in native:${l} `))}})(s)}return()=>{try{let s=Date.now();L("js_sdk_begin",{t:s});let o=r(t.bootstrapUrl),i=document.createElement("script");i.type="text/javascript",i.innerHTML=o,document.head.appendChild(i),E("implementModuleLoaded",Date.now()-s,{type:"native"});let l=r(t.implementUrl);n(l),E("bootstrapModuleLoaded",Date.now()-s,{type:"native"})}catch(s){console.error(`native load script error: ${s}`),g(new y(`module load failed ${s}`))}}};var Ge="1.0.0",pe=Ge,H=S(pe),fe=window.webkit?e=>window.prompt("loadScript",JSON.stringify(e)):void 0,$e=typeof fe<"u",G=e=>`http://cdn.jsdelivr.net/npm/@jolibox/bootstrap@${e}/dist/index.js`,$=e=>`http://cdn.jsdelivr.net/npm/@jolibox/implementation@${e}/dist/index.js`,de=G(H),ue=$(H);function He(){$e?le(fe,{bootstrapUrl:de,implementUrl:ue})():me({bootstrapUrl:de,implementUrl:ue,currentMajorVersion:H,currentVersion:pe})()}He();var z=h();async function he(){return await z.executeCommand("API.getSystemInfo")}function _e(){return z.excuteCommandSync("API.getSystemInfoSync")}function ge(){return z.excuteCommandSync("API.env")}function Ee(e,t){return te.config[e]?.[t]}function ye(e,t,r){let n=Array.isArray(t)?t:t.replace(/\[(\d+)\]/g,".$1").split("."),s=e;for(let o of n)if(s&&(typeof s=="object"||Array.isArray(s)))s=s[o];else return r;return s===void 0?r:s}var ve="1.0.0";function w(e){let r=ge().data?.deviceInfo?.platform;if(!r)return!1;let[n,...s]=e.split(":"),o=Ee(r=="h5"?r:"native",n);if(!o)return!1;let i=o.version;return typeof i!="string"||j(ve,i,"<")?!1:s.length===0?!0:Re(o,s)||Re(o.properties,s)}function Re(e,t){if(!e)return!1;let r=ye(e,t);return r?Y(r)?!0:k(r)?j(ve,r,">="):!1:!1}var Se=window.JoliboxRuntime;var u=class{constructor(){this.commands=h();this._emitter=new J}addEventListener(t,r){this._emitter.on(t,(...n)=>r(n[0]))}triggerEvent(t,r){this._emitter.emit(t,r)}canUse(t){return w(t)}};var ze="LifecycleSDK.onReady",C=class extends u{constructor(){super()}onReady(t){let r=n=>{t.call(this,n),this.triggerEvent(ze,n)};this.commands.executeCommand("LifecycleSDK.onReady",r.bind(this))}exitGame(t){this.commands.executeCommand("LifecycleSDK.exitGame",t.onBeforeExit)}onGameHide(t){this.commands.executeCommand("LifecycleSDK.onGameHide",t.bind(this))}onGameShow(t){this.commands.executeCommand("LifecycleSDK.onGameShow",t.bind(this))}};var T=class extends u{async getItem(t){return await this.commands.executeCommand("StorageSDK.getItem",t)}async setItem(t,r){if(t.length>128)return{code:"PARAMETER_ERROR",message:"[SDK] cloud storage setItem error: length of key should be less than 128"};let n=typeof r=="string"?r:String(r);return t.length+n.length>1024?{code:"PARAMETER_ERROR",message:"[SDK] cloud storage setItem error: length of key and value should be less than 1024"}:await this.commands.executeCommand("StorageSDK.setItem",t,r)}async removeItem(t){return this.commands.executeCommand("StorageSDK.removeItem",t)}async clear(){return this.commands.executeCommand("StorageSDK.clear")}};var D=class extends u{constructor(){super();this.init=r=>{this.commands.executeCommand("AdsSDK.init",r)};this.adConfig=r=>{this.commands.executeCommand("AdsSDK.adConfig",r)};this.adBreak=r=>{this.commands.executeCommand("AdsSDK.adBreak",r)};this.adUnit=r=>{this.commands.executeCommand("AdsSDK.adUnit",r)}}};var O=class extends u{showKeyboard(t){if(!this.canUse("keyboard.showKeyboard"))return{code:"FAILURE",message:"[Jolibox SDK] keyboard.showKeyboard is not supported in this platform"};this.commands.executeCommand("KeyboardSDK.showKeyboard",t)}updateKeyboard(t){if(!this.canUse("keyboard.updateKeyboard"))return{code:"FAILURE",message:"[Jolibox SDK] keyboard.updateKeyboard is not supported in this platform"};this.commands.executeCommand("KeyboardSDK.updateKeyboard",t)}hideKeyboard(){if(!this.canUse("keyboard.hideKeyboard"))return{code:"FAILURE",message:"[Jolibox SDK] keyboard.hideKeyboard is not supported in this platform"};this.commands.executeCommand("KeyboardSDK.hideKeyboard")}};var be=class{constructor(){this.runtime=new Se;this.ads=new D;this.lifecycle=new C;this.storage=new T;this.keyboard=new O;this.getSystemInfo=he.bind(this);this.getSystemInfoSync=_e.bind(this);this.canIUse=w.bind(this)}};})();
1
+ "use strict";(()=>{var ne=Object.defineProperty,Be=Object.getOwnPropertyDescriptor,Ve=(e,t)=>{for(var r in t)ne(e,r,{get:t[r],enumerable:!0})},se=(e,t,r,n)=>{for(var s=n>1?void 0:n?Be(t,r):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(s=(n?i(t,r,s):i(s))||s);return n&&s&&ne(t,r,s),s};function $e(e){return new Promise(t=>{setTimeout(()=>{t()},e)})}function G(e){return typeof e=="string"}function oe(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&!(e instanceof RegExp)&&!(e instanceof Date)}function Ge(e){return typeof e>"u"}function He(e){return Ge(e)||e===null}function We(e){return typeof e=="function"}function ie(e){let t=e,r=null,n=function(...s){return r||(r=new t(...s)),r};return n.prototype=t.prototype,n}var ze=(e=>(e[e.DEVELOPER_FILE_NOT_FOUND=0]="DEVELOPER_FILE_NOT_FOUND",e[e.INTERNAL_IOS_CAN_NOT_FOUND_PKG=1]="INTERNAL_IOS_CAN_NOT_FOUND_PKG",e[e.USER_IOS_LOAD_TIMEOUT=2]="USER_IOS_LOAD_TIMEOUT",e[e.INTERNAL_IOS_PKG_LOAD_ERROR=3]="INTERNAL_IOS_PKG_LOAD_ERROR",e[e.INTERNAL_IOS_PKG_PARSE_FAIL=4]="INTERNAL_IOS_PKG_PARSE_FAIL",e[e.USER_IOS_GET_EMPTY_DATA=5]="USER_IOS_GET_EMPTY_DATA",e[e.USER_ANDROID_GET_PKG_FAIL=6]="USER_ANDROID_GET_PKG_FAIL",e[e.DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE=7]="DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE",e))(ze||{}),Ye=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}},ae=class extends Ye{constructor(){super(...arguments),this.kind="INTERNAL_ERROR"}};var ce=class extends ae{constructor(){super(...arguments),this.name="INTERNAL_JS_MODULE_FETCH_ERROR",this.priority="P0"}},S=class extends ae{constructor(){super(...arguments),this.name="INTERNAL_JS_MODULE_EVAL_ERROR",this.priority="P0"}};function x(e){return(...t)=>{(globalThis.VConsole?.[e]??globalThis.console[e])(...t)}}var Qe={log:x("log"),warn:x("warn"),info:x("info"),error:x("error"),debug:x("debug")};Object.assign(globalThis,{logger:Qe});var le=Symbol.for("Jolibox.canIUseMap"),Xe={};globalThis[le]=Xe;var me={get config(){return globalThis[le]}};function H(e,t,r){let n=0;if(e!==t){let s=e.split("."),o=t.split("."),i=Math.max(s.length,o.length);for(let a=0;a<i;a++){let g=parseInt(s[a],10)||0,l=parseInt(o[a],10)||0;if(g>l){n=1;break}else if(g<l){n=-1;break}}}if(!r)return n;switch(r){case">":return n>0;case"<":return n<0;case"=":return n===0;case">=":return n>=0;case"<=":return n<=0;default:return!1}}var W=(e=>(e[e.System=1e3]="System",e[e.ErrorTrace=1001]="ErrorTrace",e[e.UserDefined=1002]="UserDefined",e))(W||{}),k=(e=>(e.MiniGame="mini-game",e.MiniDrama="mini-drama",e.App="app",e.WebSDK="web-sdk",e.AppSDK="app-sdk",e))(k||{}),qe=(e=>(e[e.App=0]="App",e[e.H5=1]="H5",e[e.Weapp=2]="Weapp",e[e.Alipay=3]="Alipay",e[e.Gcash=4]="Gcash",e[e.Dana=5]="Dana",e[e.Umma=6]="Umma",e[e.WebSDK=1e3]="WebSDK",e[e.AppSDK=1001]="AppSDK",e[e.Other=9999]="Other",e))(qe||{}),re=["name","params"],Ze=["name","type","location","target","extra","timestamp","userId"],et=["platform","os","appVersion","appId","model","brand","uuid","jsSdkVersion","extra"];function U(e,t){return t.map(r=>{if(r==="params"&&e[r]){let n=e[r];return Object.keys(n).reduce((s,o)=>(s[o]=String(n[o]),s),{})}return e[r]})}function tt(e){let t=e.location?U(e.location,re):null,r=e.target?U(e.target,re):null;return U({...e,location:t,target:r},Ze)}function de(e){let t=e.events.map(n=>tt(n)),r=U(e.device,et);return[e.protocolVersion,t,r,e.project]}var rt=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)});var w={isiOS:navigator.userAgent.includes("iPhone")||navigator.userAgent.includes("iPod")||navigator.userAgent.includes("iPad")||navigator.userAgent.includes("iPhone OS"),iosVersion:()=>{let e=navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/);return[parseInt(e[1],10),parseInt(e[2],10),parseInt(e[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")},nt=()=>w.isiOS?"iOS":w.isAndroid?"Android":w.isMac?"Mac":w.isFacebook?"Facebook":"PC",st="device_id",ot="advertising_id",ue=e=>(localStorage.getItem(e)||localStorage.setItem(e,rt()),localStorage.getItem(e)),it=()=>ue(st),at=()=>ue(ot),ct=e=>e.charAt(0).toUpperCase()+e.slice(1),lt=()=>{let e=new URLSearchParams(window.location.search);return ct(e.get("utm_source")??"")||"JoliboxSDK"},pe=e=>{let t="JoliboxWebSDK",r=nt(),n=navigator.language,s=it(),o=at();return`${t} (${lt()}${r}; UnknownModel; UnknownSystemVersion; ${n}) uuid/${s} adid/${o} version/${e||""}`},c=class D{static{this.Undefined=new D(void 0)}constructor(t){this.element=t,this.next=D.Undefined,this.prev=D.Undefined}},mt=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 s=this._last;this._last=r,r.prev=s,s.next=r}else{let s=this._first;this._first=r,r.next=s,s.prev=r}this._size+=1;let n=!1;return()=>{n||(n=!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}},dt=0,A=class{constructor(e){this.value=e,this.id=dt++}},v=class{constructor(e){this.options=e,this._size=0}dispose(e){this._disposed||(this._disposed=!0,this._listeners&&(e?(this._listeners instanceof A&&(this._listeners=[this._listeners]),this._listeners=this._listeners.filter(t=>t?.value===e)):(this._listeners=void 0,this._size=0)),this.options?.onDidRemoveLastListener?.())}get event(){return this._event??=(e,t)=>{if(this._disposed)return()=>{console.info("[Jolibox SDK] Emitter is _disposed")};t&&(e=e.bind(t));let r=new A(e);this._listeners?this._listeners instanceof A?this._listeners=[this._listeners,r]:this._listeners.push(r):(this.options?.onWillAddFirstListener?.(this),this._listeners=r,this.options?.onDidFirstListener?.(this)),this.options?.onDidAddListener?.(this),this._size++},this._event}_deliver(e,t){if(!e)return;let r=this.options?.onListenerError||Error.constructor;if(!r){e.value(t);return}try{e.value(t)}catch(n){r(n)}}fire(e){this._listeners&&(this._listeners instanceof A?this._deliver(this._listeners,e):this._listeners.forEach(t=>this._deliver(t,e)))}hasListeners(){return this._size>0}},z=class{constructor(){this.listeners=new Map,this.listerHandlerMap=new WeakMap,this.cachedEventQueue=new Map}on(e,t){let r=this.listeners.get(e)??new v,n=o=>t(...o.args);this.listerHandlerMap.set(t,n),r.event(n),this.listeners.set(e,r);let s=this.cachedEventQueue.get(e);if(s)for(;s.size>0;)r.fire({event:e,...s.shift()})}off(e,t){let r=this.listeners.get(e);if(r){let n=this.listerHandlerMap.get(t);r.dispose(n)}}emit(e,...t){let r=this.listeners.get(e);if(r)r.fire({event:e,args:t});else{let n=this.cachedEventQueue.get(e);n||(n=new mt,this.cachedEventQueue.set(e,n)),n.push({args:t})}}},V={};Ve(V,{None:()=>ut,filter:()=>ft,once:()=>fe,toPromise:()=>pt});var ut=()=>{console.log("[Jolibox SDK] None Event")};function pt(e){return new Promise(t=>fe(e)(t))}function fe(e){return(t,r=null)=>{let n=!1;return e(s=>{if(!n)return n=!0,t.call(r,s)},null)}}function ft(e,t){return(r=>{let n,s={onWillAddFirstListener(){n=r(o.fire,o)}},o=new v(s);return o.event})((r,n=null)=>e(s=>t(s)&&r.call(n,s),null))}var F=Symbol.for("Jolibox.hostEmitter"),ht=()=>{let e=new z;return globalThis[F]||(globalThis[F]={on:e.on.bind(e),off:e.off.bind(e),emit:e.emit.bind(e)}),globalThis[F]},he=ht();function gt(e,t){let r=Math.min(e.length,t.length);for(let n=0;n<r;n++)Et(e[n],t[n])}function Et(e,t){if(G(t)){if(typeof e!==t)throw new Error(`argument does not match constraint: typeof ${t}`)}else if(We(t)){try{if(e instanceof t)return}catch{}if(!He(e)&&e.constructor===t||t.length===1&&t.call(void 0,e)===!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 L=class{constructor(){this._commands=new Map,this._onDidRegisterCommand=new v,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 r=[];for(let s of e.metadata.args)r.push(s.constraint);let n=e.handler;e.handler=function(...s){return gt(s,r),n(...s)}}let{id:t}=e;this._commands.get(t)&&console.info(`[Jolibox SDK] duplicated command is registered ${t}`),this._commands.set(t,e),this._onDidRegisterCommand.fire(t)}getCommand(e){return this._commands.get(e)}getCommands(){let e=new Map;for(let t of this._commands.keys()){let r=this.getCommand(t);r&&e.set(t,r)}return e}};L=se([ie],L);var $=class{constructor(){this._onWillExecuteCommand=new v,this.onWillExecuteCommand=this._onWillExecuteCommand.event,this._onDidExecuteCommand=new v,this.onDidExecuteCommand=this._onDidExecuteCommand.event,this.registry=new L,this._starActivation=null}_activateStar(){return this._starActivation||(this._starActivation=$e(3e4)),this._starActivation}async executeCommand(e,...t){return this.registry.getCommand(e)?this._tryExecuteCommand(e,t):(await Promise.all([Promise.race([this._activateStar(),V.toPromise(V.filter(this.registry.onDidRegisterCommand,r=>r===e))])]),this._tryExecuteCommand(e,t))}executeCommandThowErr(e,...t){if(!this.registry.getCommand(e))throw new Error(`command '${e}' not found`);let r=this.registry.getCommand(e);this._onWillExecuteCommand.fire({commandId:e,args:t});let n=this.invokeFunction(r.handler,...t);return this._onDidExecuteCommand.fire({commandId:e,args:t}),n}_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 n=this.invokeFunction(r.handler,...t);return this._onDidExecuteCommand.fire({commandId:e,args:t}),Promise.resolve(n)}catch(n){return Promise.reject(n)}}invokeFunction(e,...t){let r=!1;try{return e(...t)}finally{r=!0}}};$=se([ie],$);var B=Symbol.for("Jolibox.commands");function p(){if(globalThis[B])return globalThis[B];let e=new L,t=new $,r={registerCommand(n,s,o){e.registerCommand({id:n,handler:s,metadata:o})},executeCommand(n,...s){return t.executeCommand(n,...s)},excuteCommandSync(n,...s){return t.executeCommandThowErr(n,...s)}};return globalThis[B]=r,r}var C=new URLSearchParams(window.location.search).get("joliboxEnv")==="staging";function _t(){let e=new URLSearchParams(window.location.search),t={};return e.forEach((r,n)=>{t[n]=r}),{name:"GamePage",params:t}}function yt(){return{platform:1e3,os:"h5",appVersion:"1.1.4-beta.11",appId:"1",model:"UnknownModel",brand:"UnknownBrand",uuid:"1",jsSdkVersion:"1.1.4-beta.11",extra:{}}}var ge={default:{test:"https://stg-collect.jolibox.com",prod:"https://collect.jolibox.com"},"oss.jolibox.com":{test:"https://stg-collect.jolibox.com",prod:"https://collect.jolibox.com"},"oss.pico-game.com":{test:"https://stg-collect.pico-game.com",prod:"https://collect.pico-game.com"}},St=()=>{let e=ge[window.location.host]??ge.default;return C?e.test:e.prod},xt=St(),Ee=e=>{let t=new AbortController;return setTimeout(()=>t.abort(),e),t.signal};AbortSignal.timeout??=Ee;var vt=()=>new URLSearchParams(window.location.search).get("joliSource")??null,bt=vt(),Rt=async e=>{let r=`${xt}/report`,n=pe("1.1.4-beta.11"),s=bt,o={"Content-Type":"application/json"};return n&&(o["x-user-agent"]=n),s&&(o["x-joli-source"]=s),await fetch(r,{method:"POST",headers:o,body:JSON.stringify(e),signal:Ee(5e3)})};async function Y(e,t,r){let n={name:e,type:W.ErrorTrace,location:_t(),target:null,extra:t,timestamp:Date.now(),userId:null},s=yt(),a=de({protocolVersion:"1.0.0",events:[n],device:s,project:r});Rt(a)}document.addEventListener("DOMContentLoaded",()=>he.emit("onDocumentReady",b.startTime));var It=()=>{let e=0;return{set startTime(t){e=t},get startTime(){return e}}},b=It(),_e=p(),Q=e=>{_e.executeCommand("ReportSDK.traceSystem",{event:"globalJsError",info:{err:JSON.stringify(e)}}).catch(t=>{console.error(`Fallback report: ${t} ${JSON.stringify(e)}`),Y("globalJsError",{err:JSON.stringify({message:t.message,source:t.source,lineno:t.lineno,colno:t.colno,error:t.error})},k.WebSDK)})},E=Q;window.addEventListener("unhandledrejection",Q.bind(void 0));window.addEventListener("error",Q.bind(void 0));window.onerror=(e,t,r,n,s)=>{_e.executeCommand("ReportSDK.traceSystem",{event:"globalJsError",info:{err:JSON.stringify({message:e,source:t,lineno:r,colno:n,error:s})}}).catch(o=>{Y("globalJsError",{err:JSON.stringify({message:e,source:t,lineno:r,colno:n,error:s})},k.WebSDK)})};var X=e=>{let t=e.split("-")[1];t&&(e=e.replace(`-${t}`,""));let r=e.split("+")[1];r&&(e=e.replace(`+${r}`,""));let n=e.split(".").slice(0,3),[s,o,i]=[n[0]??"0",n[1]??"0",n[2]??"0"];return{major:s,minor:o,patch:i,prerelease:t,build:r}},R=e=>parseInt(X(e).major,10),I=(e,t)=>{let{major:r,minor:n,patch:s}=X(e),{major:o,minor:i,patch:a}=X(t);return r!==o?r>o?1:-1:n!==i?n>i?1:-1:s!==a?s>a?1:-1:0};var ye=p(),P=(e,t)=>{ye.executeCommand("ReportSDK.traceSystem",{event:e,info:t})},_=(e,t,r)=>{ye.executeCommand("ReportSDK.traceSystemTimeline",{event:e,duration:t,extra:r})};var ve="jolibox-sdk-loadermeta",T=JSON.parse(localStorage.getItem(ve)??"{}"),q=Date.now(),Se=(e,t)=>e>t&&Math.abs(e-t)/(1e3*60*60*24)>=7,xe=e=>!/^(Failed to fetch version|Couldn't find the requested file)/.test(e);async function Tt(){let t=`${C?"https://stg-api.jolibox.com":"https://api.jolibox.com"}/api/fe-configs/js-sdk/version_metadata`;try{let r=await fetch(t,{method:"GET",headers:{"Content-Type":"application/json"}}),{implement_version:n,bootstrap_version:s}=await r.json(),o={...T,timestamp:q};if(s){let{bootstrap_version:i}=T;if(!(i&&I(i,s)>=0)){let a=await(await fetch(Z(s))).text();xe(a)&&(o={...o,bootstrap_version:s,bootstrap_script:a})}}if(n){let{implement_version:i}=T;if(!(i&&I(i,n)>=0)){let a=await(await fetch(ee(n))).text();xe(a)&&(o={...o,implement_version:n,implement_script:a})}}localStorage.setItem(ve,JSON.stringify(o))}catch(r){console.warn("Failed to fetch loader metadata: ",r)}}var be=e=>{let{currentMajorVersion:t,currentVersion:r,bootstrapUrl:n,implementUrl:s}=e;function o(){let{bootstrap_version:l,bootstrap_script:f,timestamp:u}=T;if(l&&f&&u&&!Se(q,u)&&R(l)==t&&I(l,r)>=0)return{script:f,type:"localscript"};try{let m=new XMLHttpRequest;return m.open("GET",n,!1),m.send(),{script:m.responseText,type:"fetch_from_cdn"}}catch(m){E(new ce(`Bootstrap module faile to fetch ${m}`))}}function i(){let l=Date.now();P("jsSdkBegin",{t:l}),b.startTime=l;let{script:f,type:u}=o()??{};if(f){let m=document.createElement("script");m.type="text/javascript",m.innerHTML=f,document.head.appendChild(m),_("bootstrapModuleLoaded",Date.now()-l,{type:u})}}function a(l){(async u=>{try{let m=new Blob([u],{type:"application/javascript"}),h=URL.createObjectURL(m),Fe=await import(h);return URL.revokeObjectURL(h),Fe}catch(m){E(new S(`implement module evaluate error in h5:${m} `))}})(l)}function g(){let l=Date.now(),{implement_script:f,implement_version:u,timestamp:m}=T;if(f&&u&&m&&!Se(q,m)&&R(u)==t&&I(u,r)>=0){a(f),_("implementModuleLoaded",Date.now()-l,{type:"loadscript"});return}let h=document.createElement("script");h.type="module",h.crossOrigin="anonymous",h.src=s,h.onload=()=>{_("bootstrapModuleLoaded",Date.now()-l,{type:"fetch_from_cdn"})},document.head.appendChild(h)}return()=>{try{i(),g(),Tt()}catch(l){E(new S(`module evaluate error: ${l}`))}}};var Re=(e,t)=>{let r=s=>{let o=e({path:s});if(!o)throw`module ${s} load failed ${o}`;return o};function n(s){(async i=>{try{let a=new Blob([i],{type:"application/javascript"}),g=URL.createObjectURL(a),l=await import(g);return URL.revokeObjectURL(g),l}catch(a){E(new S(`implement module evaluate error in native:${a} `))}})(s)}return()=>{try{let s=Date.now();P("jsSdkBegin",{t:s}),b.startTime=s;let o=r(t.bootstrapUrl),i=document.createElement("script");i.type="text/javascript",i.innerHTML=o,document.head.appendChild(i),_("implementModuleLoaded",Date.now()-s,{type:"native"});let a=r(t.implementUrl);n(a),_("bootstrapModuleLoaded",Date.now()-s,{type:"native"})}catch(s){console.error(`native load script error: ${s}`),E(new S(`module load failed ${s}`))}}};var wt="1.1.4-beta.11",O=wt,we=R(O),Ae=window.webkit||window.JoliAndroidSDKBridge?e=>{let t=window.prompt("invoke",JSON.stringify({event:"loadScriptSync",paramsString:JSON.stringify(e)}));if(t){let{data:r}=JSON.parse(t);return r}}:void 0,At=typeof Ae<"u",Z=e=>`https://cdn.jsdelivr.net/npm/@jolibox/bootstrap@${e}/dist/index.js`,ee=e=>`https://cdn.jsdelivr.net/npm/@jolibox/implement@${e}/dist/index.js`,Ut=e=>/^\d+\.\d+\.\d+$/.test(e),Ue=Ut(O)?we:O,Ie=Z(Ue),Te=ee(Ue);function Dt(){At?Re(Ae,{bootstrapUrl:Ie,implementUrl:Te})():be({bootstrapUrl:Ie,implementUrl:Te,currentMajorVersion:we,currentVersion:O})()}Dt();var De=p();function Le(){return De.excuteCommandSync("API.getSystemInfoSync")}function ke(){return De.excuteCommandSync("API.env")}function Ce(e,t){return me.config[e]?.[t]}function Pe(e,t,r){let n=Array.isArray(t)?t:t.replace(/\[(\d+)\]/g,".$1").split("."),s=e;for(let o of n)if(s&&(typeof s=="object"||Array.isArray(s)))s=s[o];else return r;return s===void 0?r:s}var Ke="1.1.4-beta.11";function y(e){let r=ke().data?.deviceInfo?.platform;if(!r)return!1;let[n,...s]=e.split(":"),o=Ce(r=="h5"?r:"native",n);if(!o)return!1;let i=o.version;return typeof i!="string"||H(Ke,i,"<")?!1:s.length===0?!0:Oe(o,s)||Oe(o.properties,s)}function Oe(e,t){if(!e)return!1;let r=Pe(e,t);return r?oe(r)?!0:G(r)?H(Ke,r,">="):!1:!1}var Me=p();async function Ne(){return y("login")?await Me.executeCommand("API.login"):{code:"FAILURE",message:"[Jolibox SDK]login is not supported in this platform"}}async function je(){return y("checkSession")?await Me.executeCommand("API.checkSession"):{code:"FAILURE",message:"[Jolibox SDK]checkSession is not supported in this platform"}}var Je=window.JoliboxRuntime;var d=class{constructor(){this.commands=p();this._emitter=new z}addEventListener(t,r){this._emitter.on(t,(...n)=>r(n[0]))}triggerEvent(t,r){this._emitter.emit(t,r)}canUse(t){return y(t)}canIUseIfThrow(t){if(!this.canUse(t))return{code:"FAILURE",message:`[Jolibox SDK] ${t} is not supported in this platform`}}};var Lt="LifecycleSDK.onReady",K=class extends d{constructor(){super()}onReady(t){let r=n=>{t.call(this,n),this.triggerEvent(Lt,n)};this.commands.executeCommand("LifecycleSDK.onReady",r.bind(this))}exit(t){let r=this.canIUseIfThrow("lifeCycle.exit");if(r)return r;this.commands.executeCommand("LifecycleSDK.exit",t.onBeforeExit)}onJoliboxHide(t){this.commands.executeCommand("LifecycleSDK.onJoliboxHide",t.bind(this))}onJoliboxShow(t){this.commands.executeCommand("LifecycleSDK.onJoliboxShow",t.bind(this))}};var M=class extends d{async getItem(t){return await this.commands.executeCommand("StorageSDK.getItem",t)}async setItem(t,r){if(t.length>128)return{code:"PARAMETER_ERROR",message:"[SDK] cloud storage setItem error: length of key should be less than 128"};let n=typeof r=="string"?r:String(r);return t.length+n.length>1024?{code:"PARAMETER_ERROR",message:"[SDK] cloud storage setItem error: length of key and value should be less than 1024"}:await this.commands.executeCommand("StorageSDK.setItem",t,r)}async removeItem(t){return this.commands.executeCommand("StorageSDK.removeItem",t)}async clear(){return this.commands.executeCommand("StorageSDK.clear")}};var N=class extends d{constructor(){super();this.init=r=>{this.commands.executeCommand("AdsSDK.init",r)};this.adConfig=r=>{this.commands.executeCommand("AdsSDK.adConfig",r)};this.adBreak=r=>{this.commands.executeCommand("AdsSDK.adBreak",r)};this.adUnit=r=>{this.commands.executeCommand("AdsSDK.adUnit",r)}}};var j=class extends d{showKeyboard(t){let r=this.canIUseIfThrow("keyboard.showKeyboard");if(r)return r;this.commands.executeCommand("KeyboardSDK.showKeyboard",t)}updateKeyboard(t){let r=this.canIUseIfThrow("keyboard.updateKeyboard");if(r)return r;this.commands.executeCommand("KeyboardSDK.updateKeyboard",{value:t})}hideKeyboard(){let t=this.canIUseIfThrow("keyboard.hideKeyboard");if(t)return t;this.commands.executeCommand("KeyboardSDK.hideKeyboard")}};var J=class extends d{async onLevelFinished(t,r,n){let s=this.canIUseIfThrow("TaskTrackerSDK.onLevelFinished");return s?Promise.resolve(s):await this.commands.executeCommand("TaskTrackerSDK.levelFinished",t,{result:r,duration:n})}async onTaskFinished(t,r){let n=this.canIUseIfThrow("TaskTrackerSDK.onTaskFinished");return n||await this.commands.executeCommand("TaskTrackerSDK.taskFinished",t,{duration:r})}async onTaskEvent(t,r){let n=this.canIUseIfThrow("TaskTrackerSDK.onTaskEvent");return n||await this.commands.executeCommand("TaskTrackerSDK.taskEvent",t,r)}async onLevelUpgrade(t,r){let n=this.canIUseIfThrow("TaskTrackerSDK.onLevelUpgrade");return n||await this.commands.executeCommand("TaskTrackerSDK.levelUpgrade",t,r)}async onHistoryUserLevel(t){let r=this.canIUseIfThrow("TaskTrackerSDK.onHistoryUserLevel");return r||await this.commands.executeCommand("TaskTrackerSDK.historyUserLevel",t)}async onHistoryUserScore(t){let r=this.canIUseIfThrow("TaskTrackerSDK.onHistoryUserScore");return r||await this.commands.executeCommand("TaskTrackerSDK.historyUserScore",t)}};var te=class{constructor(){this.jssdkVersion="1.1.4-beta.11";this.runtime=new Je;this.ads=new N;this.lifecycle=new K;this.storage=new M;this.keyboard=new j;this.task=new J;this.getSystemInfoSync=Le.bind(this);this.canIUse=y.bind(this);this.login=Ne.bind(this);this.checkSession=je.bind(this)}};window.JoliboxSDK=te;})();
@@ -5,6 +5,7 @@
5
5
  */
6
6
  declare global {
7
7
  interface Window {
8
+ JoliAndroidSDKBridge?: unknown;
8
9
  webkit?: unknown;
9
10
  }
10
11
  }
@@ -7,10 +7,13 @@ interface LifecycleSDKEventMap extends BaseSDKEventMap {
7
7
  export declare class LifecycleSDK extends BaseSDK<LifecycleSDKEventMap> implements Lifecycle {
8
8
  constructor();
9
9
  onReady(callback: (info?: Env['hostUserInfo']) => void): void;
10
- exitGame(params: {
10
+ exit(params: {
11
11
  onBeforeExit: () => void;
12
- }): void;
13
- onGameHide(params: () => void): void;
14
- onGameShow(params: () => void): void;
12
+ }): {
13
+ code: import("@jolibox/types").ResponseType;
14
+ message: string;
15
+ } | undefined;
16
+ onJoliboxHide(params: () => void): void;
17
+ onJoliboxShow(params: () => void): void;
15
18
  }
16
19
  export {};
@@ -1,4 +1,5 @@
1
1
  import { EventEmitter } from '@jolibox/common';
2
+ import { ResponseType } from '@jolibox/types';
2
3
  export interface BaseSDKEventMap {
3
4
  _baseSDKMarker?: never;
4
5
  }
@@ -8,4 +9,8 @@ export declare abstract class BaseSDK<T = BaseSDKEventMap> {
8
9
  addEventListener<K extends keyof T & string>(event: K, callback: (data: T[K]) => void): void;
9
10
  triggerEvent<K extends keyof T & string>(event: K, params: T[K]): void;
10
11
  canUse(command: string): boolean;
12
+ canIUseIfThrow(command: string): {
13
+ code: ResponseType;
14
+ message: string;
15
+ } | undefined;
11
16
  }
@@ -0,0 +1,25 @@
1
+ import { BaseSDK } from './sdk';
2
+ import { TaskTracker, TaskResponse } from '@jolibox/types';
3
+ export declare class TaskTrackerSDK extends BaseSDK implements TaskTracker {
4
+ onLevelFinished(levelId: string | number, result: boolean, duration: number): Promise<TaskResponse>;
5
+ onTaskFinished(taskId: string | number, duration: number): Promise<TaskResponse>;
6
+ onTaskEvent(taskId: string | number, params: {
7
+ tools?: {
8
+ id: string | number;
9
+ name: string;
10
+ count?: number;
11
+ description?: string;
12
+ price?: {
13
+ amount: number;
14
+ unit: string;
15
+ };
16
+ }[];
17
+ awards?: {
18
+ id: string | number;
19
+ name: string;
20
+ }[];
21
+ }): Promise<TaskResponse>;
22
+ onLevelUpgrade(levelId: string | number, name: string): Promise<TaskResponse>;
23
+ onHistoryUserLevel(level: number): Promise<TaskResponse>;
24
+ onHistoryUserScore(score: number): Promise<TaskResponse>;
25
+ }
@@ -0,0 +1 @@
1
+ export declare const testMode: boolean;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 兜底上报
3
+ */
4
+ import { EProject } from '@jolibox/common';
5
+ export declare function trackError(eventName: string, errorData: Record<string, string>, project: EProject): Promise<void>;
@@ -0,0 +1,65 @@
1
+ const esbuild = require('esbuild');
2
+ const fs = require('fs');
3
+
4
+ function versionPlugin(version) {
5
+ return {
6
+ name: 'version',
7
+ setup(build) {
8
+ build.onLoad({ filter: /\.[jt]sx?$/ }, async (args) => {
9
+ const contents = await fs.promises.readFile(args.path, 'utf8');
10
+ return {
11
+ contents: contents.replace(/__JOLIBOX_LOCAL_SDK_VERSION__/g, version),
12
+ loader: args.path.endsWith('tsx') ? 'tsx' : 'ts'
13
+ };
14
+ });
15
+ }
16
+ };
17
+ }
18
+
19
+ function parseArgs() {
20
+ const args = process.argv.slice(2);
21
+ const options = {
22
+ format: 'iife', // 默认值
23
+ };
24
+
25
+ for (let i = 0; i < args.length; i++) {
26
+ const arg = args[i];
27
+ const [argKey, argVal] = arg.split('=');
28
+ if (argKey === '--format' || argKey === '-f') {
29
+ if (['esm', 'cjs', 'iife'].includes(argVal)) {
30
+ options.format = argVal;
31
+ }
32
+ i++;
33
+ }
34
+ }
35
+
36
+ return options;
37
+ }
38
+
39
+ const options = parseArgs();
40
+
41
+ function build(format) {
42
+ return esbuild.build({
43
+ entryPoints: ['src/index.ts'],
44
+ bundle: true,
45
+ outfile: `dist/index.${format}.js`,
46
+ format: format,
47
+ minify: true,
48
+ loader: {
49
+ '.ts': 'ts',
50
+ '.tsx': 'tsx',
51
+ '.js': 'jsx'
52
+ },
53
+ plugins: [versionPlugin(process.env.BUILD_VERSION || '1.0.0')],
54
+ });
55
+ }
56
+
57
+ (async ()=>{
58
+ try{
59
+ await build(options.format);
60
+ }catch(e) {
61
+ console.error(e);
62
+ process.exit(1);
63
+ }
64
+ })()
65
+
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@jolibox/sdk",
3
3
  "description": "This project is common Jolibox JS-SDk interfere",
4
- "version": "1.1.4-beta.1",
4
+ "version": "1.1.4-beta.11",
5
5
  "main": "dist/index.cjs.js",
6
- "module": "dist/index.es.js",
6
+ "module": "dist/index.esm.js",
7
7
  "typings": "dist/index.d.ts",
8
8
  "license": "MIT",
9
9
  "dependencies": {
10
- "@jolibox/common": "1.1.4-beta.1",
11
- "@jolibox/types": "1.1.4-beta.1"
10
+ "@jolibox/common": "1.1.4-beta.11",
11
+ "@jolibox/types": "1.1.4-beta.11"
12
12
  },
13
13
  "devDependencies": {
14
14
  "typescript": "5.7.3",
@@ -20,9 +20,9 @@
20
20
  "scripts": {
21
21
  "clean": "rimraf ./dist",
22
22
  "build": "npm run clean && npm run build:cjs && npm run build:esm && npm run build:iife && tsc",
23
- "build:cjs": "esbuild ./src/index.ts --log-level=error --format=cjs --outfile=./dist/index.cjs.js --bundle --minify",
24
- "build:esm": "esbuild ./src/index.ts --log-level=error --format=esm --outfile=./dist/index.es.js --bundle --minify",
25
- "build:iife": "esbuild ./src/index.ts --log-level=error --format=iife --outfile=./dist/index.iife.js --bundle --minify",
23
+ "build:cjs": "BUILD_VERSION=$(node -p \"require('./package.json').version\") node esbuild.config.js --format=cjs",
24
+ "build:esm": "BUILD_VERSION=$(node -p \"require('./package.json').version\") node esbuild.config.js --format=esm",
25
+ "build:iife": "BUILD_VERSION=$(node -p \"require('./package.json').version\") node esbuild.config.js --format=iife",
26
26
  "dev": "tsc --watch",
27
27
  "test": "jest"
28
28
  },
package/sdk.build.log CHANGED
@@ -1,17 +1,17 @@
1
1
  Invoking: npm run clean && npm run build:cjs && npm run build:esm && npm run build:iife && tsc
2
2
 
3
- > @jolibox/sdk@1.1.4-beta.1 clean
3
+ > @jolibox/sdk@1.1.4-beta.11 clean
4
4
  > rimraf ./dist
5
5
 
6
6
 
7
- > @jolibox/sdk@1.1.4-beta.1 build:cjs
8
- > esbuild ./src/index.ts --log-level=error --format=cjs --outfile=./dist/index.cjs.js --bundle --minify
7
+ > @jolibox/sdk@1.1.4-beta.11 build:cjs
8
+ > BUILD_VERSION=$(node -p "require('./package.json').version") node esbuild.config.js --format=cjs
9
9
 
10
10
 
11
- > @jolibox/sdk@1.1.4-beta.1 build:esm
12
- > esbuild ./src/index.ts --log-level=error --format=esm --outfile=./dist/index.es.js --bundle --minify
11
+ > @jolibox/sdk@1.1.4-beta.11 build:esm
12
+ > BUILD_VERSION=$(node -p "require('./package.json').version") node esbuild.config.js --format=esm
13
13
 
14
14
 
15
- > @jolibox/sdk@1.1.4-beta.1 build:iife
16
- > esbuild ./src/index.ts --log-level=error --format=iife --outfile=./dist/index.iife.js --bundle --minify
15
+ > @jolibox/sdk@1.1.4-beta.11 build:iife
16
+ > BUILD_VERSION=$(node -p "require('./package.json').version") node esbuild.config.js --format=iife
17
17