@jolibox/native-bridge 1.1.29-beta.1 → 1.1.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/types/native-method-map.d.ts +33 -7
- package/dist/utils/__tests__/can-i-use.test.d.ts +1 -0
- package/dist/utils/can-i-use.d.ts +9 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/registered/payment.d.ts +1 -0
- package/package.json +3 -3
- package/src/types/native-method-map.d.ts +33 -7
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var De=Object.defineProperty,Ue=Object.defineProperties;var Le=Object.getOwnPropertyDescriptors;var I=Object.getOwnPropertySymbols;var ne=Object.prototype.hasOwnProperty,ie=Object.prototype.propertyIsEnumerable;var te=(e,r,t)=>r in e?De(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,h=(e,r)=>{for(var t in r||(r={}))ne.call(r,t)&&te(e,t,r[t]);if(I)for(var t of I(r))ie.call(r,t)&&te(e,t,r[t]);return e},se=(e,r)=>Ue(e,Le(r));var oe=(e,r)=>{var t={};for(var n in e)ne.call(e,n)&&r.indexOf(n)<0&&(t[n]=e[n]);if(e!=null&&I)for(var n of I(e))r.indexOf(n)<0&&ie.call(e,n)&&(t[n]=e[n]);return t};var S=(e,r,t)=>new Promise((n,i)=>{var s=c=>{try{o(t.next(c))}catch(l){i(l)}},a=c=>{try{o(t.throw(c))}catch(l){i(l)}},o=c=>c.done?n(c.value):Promise.resolve(c.value).then(s,a);o((t=t.apply(e,r)).next())});function Je(e){return!!(e!=null&&e.__nativeBuffers__)}var Be=e=>{let r=atob(e),t=r.length,n=new Uint8Array(t);for(let i=0;i<t;i++)n[i]=r.charCodeAt(i);return n.buffer};function T(e){if(typeof e=="string")try{e=JSON.parse(e)}catch(t){return{}}if(typeof e!="object"||e===null)return{};if(!Je(e))return e;let r=e.__nativeBuffers__;if(delete e.__nativeBuffers__,r)for(let t=0;t<r.length;t++){let n=r[t];if(n){let i;n.value?i=n.value:n.base64&&(i=Be(n.base64)),typeof i!="undefined"&&i instanceof ArrayBuffer&&(e[n.key]=i)}}return e}var Fe=e=>{let r="",t=new Uint8Array(e),n=t.byteLength;for(let i=0;i<n;i++)r+=String.fromCharCode(t[i]);return btoa(r)};function ae(e={},r=!1){let t=e,n=[];for(let[i,s]of Object.entries(t))if(s!==void 0&&s instanceof ArrayBuffer&&s.byteLength!==void 0){let a=r?{value:s,key:i}:{base64:Fe(s),key:i};n.push(a),delete t[i]}return n.length>0&&(t.__nativeBuffers__=n),t}var ue=Object.defineProperty;var je=Object.getOwnPropertyDescriptor;var He=(e,r)=>{for(var t in r)ue(e,t,{get:r[t],enumerable:!0})},de=(e,r,t,n)=>{for(var i=n>1?void 0:n?je(r,t):r,s=e.length-1,a;s>=0;s--)(a=e[s])&&(i=(n?a(r,t,i):a(i))||i);return n&&i&&ue(r,t,i),i},Ke=(e,r,t)=>new Promise((n,i)=>{var s=c=>{try{o(t.next(c))}catch(l){i(l)}},a=c=>{try{o(t.throw(c))}catch(l){i(l)}},o=c=>c.done?n(c.value):Promise.resolve(c.value).then(s,a);o((t=t.apply(e,r)).next())});if(typeof window!="undefined"&&!window.AbortController){let e=function(){this.signal=new r};e.prototype.abort=function(){this.signal._aborted=!0,typeof this.signal.onabort=="function"&&this.signal.onabort(new Event("abort"));let t=new Event("abort");this.signal.dispatchEvent(t)};let r=function(){this._aborted=!1,this.aborted=!1,this.onabort=null,this._eventListeners={}};Object.defineProperty(r.prototype,"aborted",{get:function(){return this._aborted}}),r.prototype.addEventListener=function(t,n){this._eventListeners[t]||(this._eventListeners[t]=[]),this._eventListeners[t].push(n)},r.prototype.removeEventListener=function(t,n){if(!this._eventListeners[t])return;let i=this._eventListeners[t].indexOf(n);i!==-1&&this._eventListeners[t].splice(i,1)},r.prototype.dispatchEvent=function(t){if(this._eventListeners[t.type])for(let n of this._eventListeners[t.type])n.call(this,t)},window.AbortController=e,window.AbortSignal=r}function Ve(e){return new Promise(r=>{setTimeout(()=>{r()},e)})}var me=class{constructor(){this.state="pending",this.promise=new Promise((e,r)=>{this.resolve=t=>{this.state==="pending"&&(this.state="fulfilled",e(t))},this.reject=t=>{this.state==="pending"&&(this.state="rejected",r(t))}})}};function z(e){return typeof e=="string"}function _(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&!(e instanceof RegExp)&&!(e instanceof Date)}function Ge(e){return typeof e=="undefined"}function $e(e){return Ge(e)||e===null}function ge(e){return typeof e=="function"}function pe(e){return _(e)&&ge(e.then)}function fe(e){let r=e,t=null,n=function(...i){return t||(t=new r(...i)),t};return n.prototype=r.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||{}),We=class extends Error{constructor(e){if(typeof e=="string"){super(e),this.priority="P1";return}super(e.message),this.priority="P1",this.stack=e.stack,this.raw=e}},P=class extends We{constructor(){super(...arguments),this.kind="INTERNAL_ERROR"}};var he=class extends P{constructor(){super(...arguments),this.name="INTERNAL_INVOKE_NATIVE_ERROR"}};var ve=class extends P{constructor(e,r,t,n){super(e),this.errNo=r,this.name="INTERNAL_APPLY_NATIVE_ERROR",this.errorType=t,this.errorCode=n}};var be=class extends P{constructor(){super(...arguments),this.name="INTERNAL_JSCORE_ERROR",this.priority="P0"}};var C=class extends P{constructor(){super(...arguments),this.name="INTERNAL_METRIC_REPORT_ERROR"}};function w(e){return(...r)=>{var t,n;((n=(t=globalThis.VConsole)==null?void 0:t[e])!=null?n:globalThis.console[e])(...r)}}var D={log:w("log"),warn:w("warn"),info:w("info"),error:w("error"),debug:w("debug")};Object.assign(globalThis,{logger:D});var ce=Symbol.for("Jolibox.canIUseMap"),Ye={};globalThis[ce]||(globalThis[ce]=Ye);var Qe=(e=>(e[e.System=1e3]="System",e[e.ErrorTrace=1001]="ErrorTrace",e[e.UserDefined=1002]="UserDefined",e))(Qe||{}),qe=(e=>(e.MiniGame="mini-game",e.MiniDrama="mini-drama",e.App="app",e.WebSDK="web-sdk",e.AppSDK="app-sdk",e))(qe||{}),Xe=(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))(Xe||{});function Ze(){try{if(window.__joliboxLocalStorage__)return window.__joliboxLocalStorage__;let e=Object.getOwnPropertyDescriptor(window,"localStorage");if(e&&e.get){let n=e.get.call(window);return window.__joliboxLocalStorage__=n,n}if(e=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(window),"localStorage"),e&&e.get)return e.get.call(window);let r=Window.prototype,t=Object.getOwnPropertyDescriptor(r,"localStorage");if(t&&t.get){let n=t.get.call(window);return window.__joliboxLocalStorage__=n,n}return localStorage}catch(e){return console.warn("Failed to get original localStorage, fallback to default implementation",e),localStorage}}Ze();var ye=()=>!!(navigator.userAgent||"").includes("JoliboxPlatformSDK"),vr={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")};var K=class V{constructor(r){this.element=r,this.next=V.Undefined,this.prev=V.Undefined}};K.Undefined=new K(void 0);var d=K,er=class{constructor(){this._first=d.Undefined,this._last=d.Undefined,this._size=0}get size(){return this._size}isEmpty(){return this._first===d.Undefined}clear(){let e=this._first;for(;e!==d.Undefined;){let r=e.next;e.prev=d.Undefined,e.next=d.Undefined,e=r}this._first=d.Undefined,this._last=d.Undefined,this._size=0}unshift(e){return this._insert(e,!1)}push(e){return this._insert(e,!0)}_insert(e,r){let t=new d(e);if(this._first===d.Undefined)this._first=t,this._last=t;else if(r){let i=this._last;this._last=t,t.prev=i,i.next=t}else{let i=this._first;this._first=t,t.next=i,i.prev=t}this._size+=1;let n=!1;return()=>{n||(n=!0,this._remove(t))}}shift(){if(this._first!==d.Undefined){let e=this._first.element;return this._remove(this._first),e}}pop(){if(this._last!==d.Undefined){let e=this._last.element;return this._remove(this._last),e}}_remove(e){if(e.prev!==d.Undefined&&e.next!==d.Undefined){let r=e.prev;r.next=e.next,e.next.prev=r}else e.prev===d.Undefined&&e.next===d.Undefined?(this._first=d.Undefined,this._last=d.Undefined):e.next===d.Undefined?(this._last=this._last.prev,this._last.next=d.Undefined):e.prev===d.Undefined&&(this._first=this._first.next,this._first.prev=d.Undefined);this._size-=1}*[Symbol.iterator](){let e=this._first;for(;e!==d.Undefined;)yield e.element,e=e.next}},rr=0,O=class{constructor(e){this.value=e,this.id=rr++}},k=class{constructor(e){this.options=e,this._size=0}dispose(e){var r,t;this._disposed||(this._disposed=!0,this._listeners&&(e?(this._listeners instanceof O&&(this._listeners=[this._listeners]),this._listeners=this._listeners.filter(n=>(n==null?void 0:n.value)===e)):(this._listeners=void 0,this._size=0)),(t=(r=this.options)==null?void 0:r.onDidRemoveLastListener)==null||t.call(r))}get event(){var e;return(e=this._event)!=null||(this._event=(r,t)=>{var n,i,s,a,o,c;if(this._disposed)return()=>{console.info("[Jolibox SDK] Emitter is _disposed")};t&&(r=r.bind(t));let l=new O(r);return this._listeners?this._listeners instanceof O?this._listeners=[this._listeners,l]:this._listeners.push(l):((i=(n=this.options)==null?void 0:n.onWillAddFirstListener)==null||i.call(n,this),this._listeners=l,(a=(s=this.options)==null?void 0:s.onDidFirstListener)==null||a.call(s,this)),(c=(o=this.options)==null?void 0:o.onDidAddListener)==null||c.call(o,this),this._size++,()=>{var u,m,g,f;if(!this._disposed){if(this._listeners instanceof O)this._listeners.id===l.id&&(this._listeners=void 0,this._size=0,(m=(u=this.options)==null?void 0:u.onDidRemoveLastListener)==null||m.call(u));else if(this._listeners){let y=this._listeners.indexOf(l);y>=0&&(this._listeners.splice(y,1),this._size--,this._size===0&&((f=(g=this.options)==null?void 0:g.onDidRemoveLastListener)==null||f.call(g)))}}}}),this._event}_deliver(e,r){var t;if(!e)return;let n=((t=this.options)==null?void 0:t.onListenerError)||Error.constructor;if(!n){e.value(r);return}try{e.value(r)}catch(i){n(i)}}fire(e){this._listeners&&(this._listeners instanceof O?this._deliver(this._listeners,e):this._listeners.forEach(r=>this._deliver(r,e)))}hasListeners(){return this._size>0}},U=class{constructor(){this.listeners=new Map,this.listerHandlerMap=new WeakMap,this.cachedEventQueue=new Map}on(e,r,t=!0){var n;let i=(n=this.listeners.get(e))!=null?n:new k,s=c=>r(...c.args),a=i.event(s);this.listerHandlerMap.set(r,{handler:s,dispose:a}),this.listeners.set(e,i);let o=this.cachedEventQueue.get(e);if(o&&t)for(let c of o)r(...c.args)}flushCachedEvent(e){e?this.cachedEventQueue.delete(e):this.cachedEventQueue.clear()}off(e,r){let t=this.listerHandlerMap.get(r);t&&(t.dispose(),this.listerHandlerMap.delete(r))}emit(e,...r){let t=this.listeners.get(e),n=this.cachedEventQueue.get(e);n||(n=new er,this.cachedEventQueue.set(e,n)),n.push({args:r}),t&&t.fire({event:e,args:r})}once(e,r){let t=(...n)=>{r(...n),this.off(e,t)};this.on(e,t,!1)}},G={};He(G,{None:()=>tr,filter:()=>ir,once:()=>_e,toPromise:()=>nr});var tr=()=>(console.log("[Jolibox SDK] None Event"),()=>{console.log("[Jolibox SDK] None Event dispose")});function nr(e){return new Promise(r=>_e(e)(r))}function _e(e){return(r,t=null)=>{let n=!1;return e(i=>{if(!n)return n=!0,r.call(t,i)},null)}}function ir(e,r){return(t=>{let n,i={onWillAddFirstListener(){n=t(s.fire,s)}},s=new k(i);return s.event})((t,n=null)=>e(i=>r(i)&&t.call(n,i),null))}var H=Symbol.for("Jolibox.hostEmitter"),sr=()=>{let e=new U;return globalThis[H]||(globalThis[H]={on:e.on.bind(e),off:e.off.bind(e),emit:e.emit.bind(e),once:e.once.bind(e)}),globalThis[H]},br=sr();function or(e,r){let t=Math.min(e.length,r.length);for(let n=0;n<t;n++)ar(e[n],r[n])}function ar(e,r){if(z(r)){if(typeof e!==r)throw new Error(`argument does not match constraint: typeof ${r}`)}else if(ge(r)){try{if(e instanceof r)return}catch(t){}if(!$e(e)&&e.constructor===r||r.length===1&&r.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 $=class{constructor(){this._commands=new Map,this._onDidRegisterCommand=new k,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 t=[];for(let i of e.metadata.args)t.push(i.constraint);let n=e.handler;e.handler=function(...i){return or(i,t),n(...i)}}let{id:r}=e;this._commands.get(r)&&console.info(`[Jolibox SDK] duplicated command is registered ${r}`),this._commands.set(r,e),this._onDidRegisterCommand.fire(r)}getCommand(e){return this._commands.get(e)}getCommands(){let e=new Map;for(let r of this._commands.keys()){let t=this.getCommand(r);t&&e.set(r,t)}return e}};$=de([fe],$);var le=class{constructor(){this._onWillExecuteCommand=new k,this.onWillExecuteCommand=this._onWillExecuteCommand.event,this._onDidExecuteCommand=new k,this.onDidExecuteCommand=this._onDidExecuteCommand.event,this.registry=new $,this._starActivation=null}_activateStar(){return this._starActivation||(this._starActivation=Ve(3e4)),this._starActivation}executeCommand(e,...r){return Ke(this,null,function*(){return this.registry.getCommand(e)?this._tryExecuteCommand(e,r):(yield Promise.all([Promise.race([this._activateStar(),G.toPromise(G.filter(this.registry.onDidRegisterCommand,t=>t===e))])]),this._tryExecuteCommand(e,r))})}executeCommandThowErr(e,...r){if(!this.registry.getCommand(e))throw new Error(`command '${e}' not found`);let t=this.registry.getCommand(e);this._onWillExecuteCommand.fire({commandId:e,args:r});let n=this.invokeFunction(t.handler,...r);return this._onDidExecuteCommand.fire({commandId:e,args:r}),n}_tryExecuteCommand(e,r){let t=this.registry.getCommand(e);if(!t)return Promise.reject(new Error(`command '${e}' not found`));try{this._onWillExecuteCommand.fire({commandId:e,args:r});let n=this.invokeFunction(t.handler,...r);return this._onDidExecuteCommand.fire({commandId:e,args:r}),Promise.resolve(n)}catch(n){return Promise.reject(n)}}invokeFunction(e,...r){let t=!1;try{return e(...r)}finally{t=!0}}};le=de([fe],le);var yr=Symbol.for("Jolibox.commands");function A(e,r){return`[${e}]:${r}`}var Ee=()=>ye();var E="custom_event_";var Ne=[],Se=[],Re=["env","createRequestTask","login"],L="__batch_event__";var cr=e=>e==="pv"?e:"default",N=class{constructor(r){this.interval=30;this.lastReportTime=0;this.cache={};let{reporter:t,interval:n=30,eventName:i,tagNameOrder:s,metricName:a,type:o}=r;this.reporter=t,this.interval=n,this.eventName=i,this.tagNameOrder=s,this.metricName=a,this.type=cr(o)}report(r){this.type==="pv"?this.addPVPoint(r):this.addPoint(r),this.tryReport(!1)}flush(){this.tryReport(!0)}tryReport(r){if(Object.keys(this.cache).length){if(r){this.reporter(this.processPoints(this.cache)),this.clearPoints();return}this.lastReportTime=this.lastReportTime||Date.now(),Date.now()-this.lastReportTime>=this.interval*1e3&&(this.reporter(this.processPoints(this.cache)),this.clearPoints(),this.lastReportTime=Date.now())}}addPoint(r){let t=(n,i,s,a)=>{let o=i.shift();if(o){let c=a[o];n[c]||(n[c]={}),t(n[c],i,s,a)}else n[s]||(n[s]=[]),n[s].push(a[s])};t(this.cache,[...this.tagNameOrder],this.metricName,r)}addPVPoint(r){let t=(i,s,a,o)=>{let c=s.shift();if(!c&&_(o))throw new C(`report value failed to match tagNameOrder, ${JSON.stringify(n)}`);if(c){let l=[];if(_(o))l.push(...Object.keys(o));else if(z(o)){if(s.length>0)throw new C(`report value failed to match tagNameOrder, ${JSON.stringify(n)}`);l.push(o)}else throw new C(`expected metric value to be a string, but got a(n) ${typeof o}, ${JSON.stringify(n)}`);l.forEach(u=>{i[u]||(i[u]={});let m=_(o)?o[u]:o;t(i[u],[...s],a,m)})}else i[a]?i[a]++:i[a]=1},n={point:r,metricName:this.metricName,tagNameOrder:this.tagNameOrder};t(this.cache,[...this.tagNameOrder],this.metricName,r)}processPoints(r){return{eventName:this.eventName,tagNameOrder:this.tagNameOrder,metricName:this.metricName,metricAggregateType:this.type==="pv"?"itoa":"arr",data:r}}clearPoints(){this.cache={}}},xe=!1,W,Y,Q;function Te(e,r){xe||(W=new N({eventName:"jolibox_invoke",tagNameOrder:["status","method","errNo","errMsg","isForeground"],metricName:"duration",reporter(i){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:i}),-1)}}),Y=new N({eventName:"jolibox_invoke_js2native",tagNameOrder:["status","method","isForeground"],metricName:"duration",reporter(i){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:i}),-1)}}),Q=new N({eventName:"jolibox_invoke_native2js",tagNameOrder:["status","method","isForeground"],metricName:"duration",reporter(i){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:i}),-1)}}),r("onJoliboxEnterBackground",()=>{W.flush(),Y.flush(),Q.flush()}),xe=!0);function t(i){var R,x;let{method:s,args:a,startTime:o,isForeground:c,errMsg:l=`${s}:fail no errMsg`,errNo:u=0,__timing:m={receiveJSInvoke:0,invokeCallback:0}}=i,{receiveJSInvoke:g,invokeCallback:f}=m,y=(x=(R=l.match(/\S:(\S+)\s?/))==null?void 0:R[1])!=null?x:"fail";W.report({status:y,method:n(s,a),errNo:`${u}`,errMsg:l,isForeground:c,duration:Date.now()-o}),o&&g&&f&&(Y.report({status:y,method:s,isForeground:c,duration:Number((g-o).toFixed(3))}),Q.report({status:y,method:s,isForeground:c,duration:Number((Date.now()-f).toFixed(3))}))}function n(i,s){return(i==="callHostMethod"||i==="callHostMethodSync")&&s!=null&&s.method?`${i}-${s.method}`:i}return t}var q=[],lr=!1,X=Symbol.for("Jolibox.invokeResolverInstance"),ur=new Map;globalThis[X]||(globalThis[X]=ur);var dr={get resolveMap(){return globalThis[X]}};function Oe(e,r){let t=0,n=!0,i=dr.resolveMap,s=Te(e,r);r("onJoliboxEnterBackground",()=>{n=!1}),r("onJoliboxEnterForeground",()=>{n=!0,q.forEach(g=>S(this,[g],function*({method:l,args:u,resolve:m}){let f=yield o(l,u);m(f)})),q.length=0});let a=(l,u)=>{let m=i.get(Number(l));if(!m)return;let g=T(u);m(g),i.delete(Number(l))},o=(l,u)=>{var ee,re;let m=Date.now(),g=`${n}`;t+=1;let f=new me;if(i.set(t,f.resolve),!n&&Se.includes(l))return new Promise(b=>{q.push({method:l,args:u,resolve:b})});let R=se(h({},{method:l,startTime:m,args:u,isForeground:g}),{invokeType:"js-bridge"}),x=!lr&&Ne.includes(l),F=ae(u,x),j=x?F:JSON.stringify(F),p;if(l.endsWith("Sync")||Re.includes(l)?p=(ee=e.call)==null?void 0:ee.call(e,l,F,t):typeof j=="string"?p=e.invoke(l,j,t):p=(re=e.call)==null?void 0:re.call(e,l,j,t),p){try{typeof p=="string"&&(p=JSON.parse(p)),p=T(p)}catch(b){D.error(b)}return i.delete(t),p.errorCode&&(p.errorCode=A(l,p.errorCode)),s(h(h({},R),p)),p}return l.endsWith("Sync")&&i.delete(t),f.promise.then(b=>(b.errorCode&&(b.errorCode=A(l,b.errorCode)),s(h(h({},R),b)),b))};return{invokeNative:o,applyNative:(l,u)=>{let m=o(l,u);return pe(m)?m.then(g=>we(l,g)):we(l,m)},invokeHandler:a}}function we(e,r){if(!_(r)){D.warn(`[Jolibox SDK]${e} no response value`);return}let o=r,{errMsg:t,errNo:n,errorType:i,errorCode:s}=o,a=oe(o,["errMsg","errNo","errorType","errorCode"]);if(t&&t!==`${e}:ok`)throw new ve(t,n,i,s);return a}var J=Symbol.for("Jolibox.subscribeInstance");function ke(e){if(globalThis[J])return globalThis[J];let r=new U,t=new U,n=new N({eventName:"jolibox_publish",tagNameOrder:["type","event"],metricName:"duration",reporter(i){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:i}),-1)}});return r.on("onJoliboxEnterBackground",()=>{n.flush()}),globalThis[J]={onNative:r.on.bind(r),offNative:r.off.bind(r),subscribe:t.on.bind(t),unsubscribe:t.off.bind(t),subscribeHandler(i,s,a){let o=T(s),c;if(o.__extra){c=o.params;let{type:l,startTime:u}=o.__extra;n.report({type:l,event:i,duration:Date.now()-u})}else c=o;if(i===L){c.forEach(u=>{let[m,g]=u;try{t.emit(m.slice(E.length),g,a)}catch(f){}});return}if(i.startsWith(E)){t.emit(i.slice(E.length),c,a);return}r.emit(i,c,a)}},globalThis[J]}function Ae(e){let r=new Map,t;return(i,s,a,o)=>{if(o){let l=a?[a]:"*";e.publish(`${E}${i}`,s,l);return}t||(t=Promise.resolve().then(()=>{r.forEach((l,u)=>{try{let m=u?[u]:"*";e.publish(L,l,m)}catch(m){}}),t=void 0,r.clear()}));let c=r.get(a);c||(c=[],r.set(a,c)),c.push([`${E}${i}`,s])}}function Z(e){let{subscribeHandler:r,onNative:t,offNative:n,subscribe:i,unsubscribe:s}=ke(e),{invokeNative:a,invokeHandler:o,applyNative:c}=Oe(e,t),l=Ae(e);return{invokeHandler:o,subscribeHandler:r,applyNative:c,invokeNative:a,onNative:t,offNative:n,publish:l,subscribe:i,unsubscribe:s}}function B(e,r){return{params:e,__extra:{startTime:Date.now(),type:r}}}var M,v={trigger(){},exit(){return Promise.resolve(!1)},backPress(){return Promise.resolve(!1)},onReady(e){v.trigger=e},onDoExit(e){v.exit=e},onDoBackPress(e){v.backPress=e}},Me=e=>{let r=window.prompt("invoke",JSON.stringify({event:"envSync",paramsString:JSON.stringify({})}));if(!r)e.onError(new he("native env failed"));else{let{data:t}=JSON.parse(r);return t!=null?t:void 0}};if(window.webkit){let e=window.webkit.messageHandlers,r=(i="")=>{v.trigger(),e.onDocumentReady.postMessage({path:i})},t=i=>S(void 0,null,function*(){let s=yield v.exit();e.doExit.postMessage({uuid:i,shouldInterrupt:s})});M={onDocumentReady:r,doExit:t,invoke(i,s,a){e.invoke.postMessage({event:i,paramsString:s,callbackId:a})},publish(i,s,a){let o=B(s,"joliboxJSCore");window.prompt("publish",JSON.stringify({event:i,paramsString:JSON.stringify(o),webviewIds:a}))},call(i,s,a){let o=window.prompt("invoke",JSON.stringify({event:i,paramsString:JSON.stringify(s),callbackId:a}));if(o)return JSON.parse(o)}};let n={onDocumentReady:r,env:Me,doExit:t};globalThis.joliboxJSCore=h({},n)}if(window.JoliAndroidSDKBridge){let i,e=window.JoliAndroidSDKBridge,r=(s="")=>{v.trigger(),e.onDocumentReady(JSON.stringify({path:s}))},t=s=>S(void 0,null,function*(){let a=yield v.exit();e.doExit(JSON.stringify({uuid:s,shouldInterrupt:a}))});M={onDocumentReady:r,invoke(s,a,o){e.invoke(JSON.stringify({event:s,paramsString:a,callbackId:o}))},doExit:t,publish(s,a,o){let c=B(a,"joliboxJSCore");e.publish({event:s,paramsString:JSON.stringify(c),webviewIds:o})},call(s,a,o){let c=window.prompt("invoke",JSON.stringify({event:s,paramsString:JSON.stringify(a),callbackId:o}));if(c)return JSON.parse(c)},doBackPress(s){return S(this,null,function*(){let a=yield v.backPress();e.doBackPress(JSON.stringify({uuid:s,shouldInterrupt:a}))})}};let n={onDocumentReady:r,env:Me,doExit:t};globalThis.joliboxJSCore=h({},n)}var Pe=M;if(!Pe&&Ee())throw new be("No joliboxJScore is found, native bridge not found.");var mr=h({},Pe),Ce=Z(mr),{invokeHandler:Ie}=Ce,{applyNative:Rt,invokeNative:xt,onNative:gr,offNative:Tt,subscribeHandler:pr,publish:wt,subscribe:Ot,unsubscribe:kt}=Ce,At=(e,r)=>{gr(e,(...t)=>{var n;(n=t[0])!=null&&n.errorCode&&(t[0].errorCode=A(e,t[0].errorCode)),r(...t)})};globalThis.joliboxJSBridge={callHandler:Ie,invokeHandler:Ie,subscribeHandler:pr};export{v as RuntimeLoader,Rt as applyNative,xt as invokeNative,Tt as offNative,gr as onNative,At as onNativeWithError,wt as publish,Ot as subscribe,pr as subscribeHandler,kt as unsubscribe};
|
|
1
|
+
var Fe=Object.defineProperty,je=Object.defineProperties;var He=Object.getOwnPropertyDescriptors;var P=Object.getOwnPropertySymbols;var ae=Object.prototype.hasOwnProperty,ce=Object.prototype.propertyIsEnumerable;var oe=(e,r,t)=>r in e?Fe(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,f=(e,r)=>{for(var t in r||(r={}))ae.call(r,t)&&oe(e,t,r[t]);if(P)for(var t of P(r))ce.call(r,t)&&oe(e,t,r[t]);return e},le=(e,r)=>je(e,He(r));var ue=(e,r)=>{var t={};for(var n in e)ae.call(e,n)&&r.indexOf(n)<0&&(t[n]=e[n]);if(e!=null&&P)for(var n of P(e))r.indexOf(n)<0&&ce.call(e,n)&&(t[n]=e[n]);return t};var S=(e,r,t)=>new Promise((n,i)=>{var s=c=>{try{a(t.next(c))}catch(l){i(l)}},o=c=>{try{a(t.throw(c))}catch(l){i(l)}},a=c=>c.done?n(c.value):Promise.resolve(c.value).then(s,o);a((t=t.apply(e,r)).next())});function Ve(e){return!!(e!=null&&e.__nativeBuffers__)}var Ge=e=>{let r=atob(e),t=r.length,n=new Uint8Array(t);for(let i=0;i<t;i++)n[i]=r.charCodeAt(i);return n.buffer};function O(e){if(typeof e=="string")try{e=JSON.parse(e)}catch(t){return{}}if(typeof e!="object"||e===null)return{};if(!Ve(e))return e;let r=e.__nativeBuffers__;if(delete e.__nativeBuffers__,r)for(let t=0;t<r.length;t++){let n=r[t];if(n){let i;n.value?i=n.value:n.base64&&(i=Ge(n.base64)),typeof i!="undefined"&&i instanceof ArrayBuffer&&(e[n.key]=i)}}return e}var Ke=e=>{let r="",t=new Uint8Array(e),n=t.byteLength;for(let i=0;i<n;i++)r+=String.fromCharCode(t[i]);return btoa(r)};function de(e={},r=!1){let t=e,n=[];for(let[i,s]of Object.entries(t))if(s!==void 0&&s instanceof ArrayBuffer&&s.byteLength!==void 0){let o=r?{value:s,key:i}:{base64:Ke(s),key:i};n.push(o),delete t[i]}return n.length>0&&(t.__nativeBuffers__=n),t}var pe=Object.defineProperty;var $e=Object.getOwnPropertyDescriptor;var ze=(e,r)=>{for(var t in r)pe(e,t,{get:r[t],enumerable:!0})},fe=(e,r,t,n)=>{for(var i=n>1?void 0:n?$e(r,t):r,s=e.length-1,o;s>=0;s--)(o=e[s])&&(i=(n?o(r,t,i):o(i))||i);return n&&i&&pe(r,t,i),i},We=(e,r,t)=>new Promise((n,i)=>{var s=c=>{try{a(t.next(c))}catch(l){i(l)}},o=c=>{try{a(t.throw(c))}catch(l){i(l)}},a=c=>c.done?n(c.value):Promise.resolve(c.value).then(s,o);a((t=t.apply(e,r)).next())});if(typeof window!="undefined"&&!window.AbortController){let e=function(){this.signal=new r};e.prototype.abort=function(){this.signal._aborted=!0,typeof this.signal.onabort=="function"&&this.signal.onabort(new Event("abort"));let t=new Event("abort");this.signal.dispatchEvent(t)};let r=function(){this._aborted=!1,this.aborted=!1,this.onabort=null,this._eventListeners={}};Object.defineProperty(r.prototype,"aborted",{get:function(){return this._aborted}}),r.prototype.addEventListener=function(t,n){this._eventListeners[t]||(this._eventListeners[t]=[]),this._eventListeners[t].push(n)},r.prototype.removeEventListener=function(t,n){if(!this._eventListeners[t])return;let i=this._eventListeners[t].indexOf(n);i!==-1&&this._eventListeners[t].splice(i,1)},r.prototype.dispatchEvent=function(t){if(this._eventListeners[t.type])for(let n of this._eventListeners[t.type])n.call(this,t)},window.AbortController=e,window.AbortSignal=r}function qe(e){return new Promise(r=>{setTimeout(()=>{r()},e)})}var he=class{constructor(){this.state="pending",this.promise=new Promise((e,r)=>{this.resolve=t=>{this.state==="pending"&&(this.state="fulfilled",e(t))},this.reject=t=>{this.state==="pending"&&(this.state="rejected",r(t))}})}};function q(e){return typeof e=="string"}function y(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&!(e instanceof RegExp)&&!(e instanceof Date)}function Y(e){return typeof e=="number"&&!isNaN(e)}function Ye(e){return typeof e=="undefined"}function Qe(e){return Ye(e)||e===null}function ve(e){return typeof e=="function"}function be(e){return y(e)&&ve(e.then)}function ye(e){let r=e,t=null,n=function(...i){return t||(t=new r(...i)),t};return n.prototype=r.prototype,n}var Xe=(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))(Xe||{}),Ze=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}},C=class extends Ze{constructor(){super(...arguments),this.kind="INTERNAL_ERROR"}};var _e=class extends C{constructor(){super(...arguments),this.name="INTERNAL_INVOKE_NATIVE_ERROR"}};var Ne=class extends C{constructor(e,r,t,n){super(e),this.errNo=r,this.name="INTERNAL_APPLY_NATIVE_ERROR",this.errorType=t,this.errorCode=n}};var Ee=class extends C{constructor(){super(...arguments),this.name="INTERNAL_JSCORE_ERROR",this.priority="P0"}};var D=class extends C{constructor(){super(...arguments),this.name="INTERNAL_METRIC_REPORT_ERROR"}};function w(e){return(...r)=>{var t,n;((n=(t=globalThis.VConsole)==null?void 0:t[e])!=null?n:globalThis.console[e])(...r)}}var R={log:w("log"),warn:w("warn"),info:w("info"),error:w("error"),debug:w("debug")};Object.assign(globalThis,{logger:R});var ge=Symbol.for("Jolibox.canIUseMap"),er={};globalThis[ge]||(globalThis[ge]=er);function Se(e,r,t){let n=e;for(let i of r)if(n&&typeof n=="object")n=n[i];else return t;return n===void 0?t:n}var G=Symbol.for("Jolibox.canIUseMap.native"),rr={};globalThis[G]||(globalThis[G]=rr);var U={get config(){return globalThis[G]}};var tr=(e=>(e[e.System=1e3]="System",e[e.ErrorTrace=1001]="ErrorTrace",e[e.UserDefined=1002]="UserDefined",e))(tr||{}),nr=(e=>(e.MiniGame="mini-game",e.MiniDrama="mini-drama",e.App="app",e.WebSDK="web-sdk",e.AppSDK="app-sdk",e))(nr||{}),ir=(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))(ir||{});function sr(){try{if(window.__joliboxLocalStorage__)return window.__joliboxLocalStorage__;let e=Object.getOwnPropertyDescriptor(window,"localStorage");if(e&&e.get){let n=e.get.call(window);return window.__joliboxLocalStorage__=n,n}if(e=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(window),"localStorage"),e&&e.get)return e.get.call(window);let r=Window.prototype,t=Object.getOwnPropertyDescriptor(r,"localStorage");if(t&&t.get){let n=t.get.call(window);return window.__joliboxLocalStorage__=n,n}return localStorage}catch(e){return console.warn("Failed to get original localStorage, fallback to default implementation",e),localStorage}}sr();var Re=()=>!!(navigator.userAgent||"").includes("JoliboxPlatformSDK"),Rr={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")};var K=class ${constructor(r){this.element=r,this.next=$.Undefined,this.prev=$.Undefined}};K.Undefined=new K(void 0);var d=K,or=class{constructor(){this._first=d.Undefined,this._last=d.Undefined,this._size=0}get size(){return this._size}isEmpty(){return this._first===d.Undefined}clear(){let e=this._first;for(;e!==d.Undefined;){let r=e.next;e.prev=d.Undefined,e.next=d.Undefined,e=r}this._first=d.Undefined,this._last=d.Undefined,this._size=0}unshift(e){return this._insert(e,!1)}push(e){return this._insert(e,!0)}_insert(e,r){let t=new d(e);if(this._first===d.Undefined)this._first=t,this._last=t;else if(r){let i=this._last;this._last=t,t.prev=i,i.next=t}else{let i=this._first;this._first=t,t.next=i,i.prev=t}this._size+=1;let n=!1;return()=>{n||(n=!0,this._remove(t))}}shift(){if(this._first!==d.Undefined){let e=this._first.element;return this._remove(this._first),e}}pop(){if(this._last!==d.Undefined){let e=this._last.element;return this._remove(this._last),e}}_remove(e){if(e.prev!==d.Undefined&&e.next!==d.Undefined){let r=e.prev;r.next=e.next,e.next.prev=r}else e.prev===d.Undefined&&e.next===d.Undefined?(this._first=d.Undefined,this._last=d.Undefined):e.next===d.Undefined?(this._last=this._last.prev,this._last.next=d.Undefined):e.prev===d.Undefined&&(this._first=this._first.next,this._first.prev=d.Undefined);this._size-=1}*[Symbol.iterator](){let e=this._first;for(;e!==d.Undefined;)yield e.element,e=e.next}},ar=0,I=class{constructor(e){this.value=e,this.id=ar++}},k=class{constructor(e){this.options=e,this._size=0}dispose(e){var r,t;this._disposed||(this._disposed=!0,this._listeners&&(e?(this._listeners instanceof I&&(this._listeners=[this._listeners]),this._listeners=this._listeners.filter(n=>(n==null?void 0:n.value)===e)):(this._listeners=void 0,this._size=0)),(t=(r=this.options)==null?void 0:r.onDidRemoveLastListener)==null||t.call(r))}get event(){var e;return(e=this._event)!=null||(this._event=(r,t)=>{var n,i,s,o,a,c;if(this._disposed)return()=>{console.info("[Jolibox SDK] Emitter is _disposed")};t&&(r=r.bind(t));let l=new I(r);return this._listeners?this._listeners instanceof I?this._listeners=[this._listeners,l]:this._listeners.push(l):((i=(n=this.options)==null?void 0:n.onWillAddFirstListener)==null||i.call(n,this),this._listeners=l,(o=(s=this.options)==null?void 0:s.onDidFirstListener)==null||o.call(s,this)),(c=(a=this.options)==null?void 0:a.onDidAddListener)==null||c.call(a,this),this._size++,()=>{var u,g,m,h;if(!this._disposed){if(this._listeners instanceof I)this._listeners.id===l.id&&(this._listeners=void 0,this._size=0,(g=(u=this.options)==null?void 0:u.onDidRemoveLastListener)==null||g.call(u));else if(this._listeners){let _=this._listeners.indexOf(l);_>=0&&(this._listeners.splice(_,1),this._size--,this._size===0&&((h=(m=this.options)==null?void 0:m.onDidRemoveLastListener)==null||h.call(m)))}}}}),this._event}_deliver(e,r){var t;if(!e)return;let n=((t=this.options)==null?void 0:t.onListenerError)||Error.constructor;if(!n){e.value(r);return}try{e.value(r)}catch(i){n(i)}}fire(e){this._listeners&&(this._listeners instanceof I?this._deliver(this._listeners,e):this._listeners.forEach(r=>this._deliver(r,e)))}hasListeners(){return this._size>0}},L=class{constructor(){this.listeners=new Map,this.listerHandlerMap=new WeakMap,this.cachedEventQueue=new Map}on(e,r,t=!0){var n;let i=(n=this.listeners.get(e))!=null?n:new k,s=c=>r(...c.args),o=i.event(s);this.listerHandlerMap.set(r,{handler:s,dispose:o}),this.listeners.set(e,i);let a=this.cachedEventQueue.get(e);if(a&&t)for(let c of a)r(...c.args)}flushCachedEvent(e){e?this.cachedEventQueue.delete(e):this.cachedEventQueue.clear()}off(e,r){let t=this.listerHandlerMap.get(r);t&&(t.dispose(),this.listerHandlerMap.delete(r))}emit(e,...r){let t=this.listeners.get(e),n=this.cachedEventQueue.get(e);n||(n=new or,this.cachedEventQueue.set(e,n)),n.push({args:r}),t&&t.fire({event:e,args:r})}once(e,r){let t=(...n)=>{r(...n),this.off(e,t)};this.on(e,t,!1)}},z={};ze(z,{None:()=>cr,filter:()=>ur,once:()=>xe,toPromise:()=>lr});var cr=()=>(console.log("[Jolibox SDK] None Event"),()=>{console.log("[Jolibox SDK] None Event dispose")});function lr(e){return new Promise(r=>xe(e)(r))}function xe(e){return(r,t=null)=>{let n=!1;return e(i=>{if(!n)return n=!0,r.call(t,i)},null)}}function ur(e,r){return(t=>{let n,i={onWillAddFirstListener(){n=t(s.fire,s)}},s=new k(i);return s.event})((t,n=null)=>e(i=>r(i)&&t.call(n,i),null))}var V=Symbol.for("Jolibox.hostEmitter"),dr=()=>{let e=new L;return globalThis[V]||(globalThis[V]={on:e.on.bind(e),off:e.off.bind(e),emit:e.emit.bind(e),once:e.once.bind(e)}),globalThis[V]},xr=dr();function gr(e,r){let t=Math.min(e.length,r.length);for(let n=0;n<t;n++)mr(e[n],r[n])}function mr(e,r){if(q(r)){if(typeof e!==r)throw new Error(`argument does not match constraint: typeof ${r}`)}else if(ve(r)){try{if(e instanceof r)return}catch(t){}if(!Qe(e)&&e.constructor===r||r.length===1&&r.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 W=class{constructor(){this._commands=new Map,this._onDidRegisterCommand=new k,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 t=[];for(let i of e.metadata.args)t.push(i.constraint);let n=e.handler;e.handler=function(...i){return gr(i,t),n(...i)}}let{id:r}=e;this._commands.get(r)&&console.info(`[Jolibox SDK] duplicated command is registered ${r}`),this._commands.set(r,e),this._onDidRegisterCommand.fire(r)}getCommand(e){return this._commands.get(e)}getCommands(){let e=new Map;for(let r of this._commands.keys()){let t=this.getCommand(r);t&&e.set(r,t)}return e}};W=fe([ye],W);var me=class{constructor(){this._onWillExecuteCommand=new k,this.onWillExecuteCommand=this._onWillExecuteCommand.event,this._onDidExecuteCommand=new k,this.onDidExecuteCommand=this._onDidExecuteCommand.event,this.registry=new W,this._starActivation=null}_activateStar(){return this._starActivation||(this._starActivation=qe(3e4)),this._starActivation}executeCommand(e,...r){return We(this,null,function*(){return this.registry.getCommand(e)?this._tryExecuteCommand(e,r):(yield Promise.all([Promise.race([this._activateStar(),z.toPromise(z.filter(this.registry.onDidRegisterCommand,t=>t===e))])]),this._tryExecuteCommand(e,r))})}executeCommandThowErr(e,...r){if(!this.registry.getCommand(e))throw new Error(`command '${e}' not found`);let t=this.registry.getCommand(e);this._onWillExecuteCommand.fire({commandId:e,args:r});let n=this.invokeFunction(t.handler,...r);return this._onDidExecuteCommand.fire({commandId:e,args:r}),n}_tryExecuteCommand(e,r){let t=this.registry.getCommand(e);if(!t)return Promise.reject(new Error(`command '${e}' not found`));try{this._onWillExecuteCommand.fire({commandId:e,args:r});let n=this.invokeFunction(t.handler,...r);return this._onDidExecuteCommand.fire({commandId:e,args:r}),Promise.resolve(n)}catch(n){return Promise.reject(n)}}invokeFunction(e,...r){let t=!1;try{return e(...r)}finally{t=!0}}};me=fe([ye],me);var Tr=Symbol.for("Jolibox.commands");Q("requestPaymentSync",{version:1e6,properties:{paymentBody:{appStoreProductId:102e4}}});Q("requestProductDetailsAsync",{version:102e4});function Q(e,r){if(U.config[e]){R.warn(`[can i use] ${e} already registered`);return}U.config[e]=f({},r)}var pr=e=>{function r(n){let[i,...s]=n.split(":");if(!i)return!1;let o=U.config[i];if(!o)return!1;let a=o.version;if(typeof a!="number")return!1;let c=e();return typeof c!="number"||c<a?!1:s.length===0?!0:t(o,s,c)||t(o.properties,s,c)}function t(n,i,s){if(!n)return!1;let o=Se(n,i);if(!o)return!1;if(y(o)){let a=o.version;return Y(a)?typeof s=="number"&&s>=a:!0}return Y(o)?typeof s=="number"&&s>=o:o===!0}return{canIUseNative:r}};function A(e,r){return`[${e}]:${r}`}var Te=()=>Re();var N="custom_event_";var Oe=[],we=[],Ie=["env","createRequestTask","login"],J="__batch_event__";var fr=e=>e==="pv"?e:"default",E=class{constructor(r){this.interval=30;this.lastReportTime=0;this.cache={};let{reporter:t,interval:n=30,eventName:i,tagNameOrder:s,metricName:o,type:a}=r;this.reporter=t,this.interval=n,this.eventName=i,this.tagNameOrder=s,this.metricName=o,this.type=fr(a)}report(r){this.type==="pv"?this.addPVPoint(r):this.addPoint(r),this.tryReport(!1)}flush(){this.tryReport(!0)}tryReport(r){if(Object.keys(this.cache).length){if(r){this.reporter(this.processPoints(this.cache)),this.clearPoints();return}this.lastReportTime=this.lastReportTime||Date.now(),Date.now()-this.lastReportTime>=this.interval*1e3&&(this.reporter(this.processPoints(this.cache)),this.clearPoints(),this.lastReportTime=Date.now())}}addPoint(r){let t=(n,i,s,o)=>{let a=i.shift();if(a){let c=o[a];n[c]||(n[c]={}),t(n[c],i,s,o)}else n[s]||(n[s]=[]),n[s].push(o[s])};t(this.cache,[...this.tagNameOrder],this.metricName,r)}addPVPoint(r){let t=(i,s,o,a)=>{let c=s.shift();if(!c&&y(a))throw new D(`report value failed to match tagNameOrder, ${JSON.stringify(n)}`);if(c){let l=[];if(y(a))l.push(...Object.keys(a));else if(q(a)){if(s.length>0)throw new D(`report value failed to match tagNameOrder, ${JSON.stringify(n)}`);l.push(a)}else throw new D(`expected metric value to be a string, but got a(n) ${typeof a}, ${JSON.stringify(n)}`);l.forEach(u=>{i[u]||(i[u]={});let g=y(a)?a[u]:a;t(i[u],[...s],o,g)})}else i[o]?i[o]++:i[o]=1},n={point:r,metricName:this.metricName,tagNameOrder:this.tagNameOrder};t(this.cache,[...this.tagNameOrder],this.metricName,r)}processPoints(r){return{eventName:this.eventName,tagNameOrder:this.tagNameOrder,metricName:this.metricName,metricAggregateType:this.type==="pv"?"itoa":"arr",data:r}}clearPoints(){this.cache={}}},ke=!1,X,Z,ee;function Ae(e,r){ke||(X=new E({eventName:"jolibox_invoke",tagNameOrder:["status","method","errNo","errMsg","isForeground"],metricName:"duration",reporter(i){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:i}),-1)}}),Z=new E({eventName:"jolibox_invoke_js2native",tagNameOrder:["status","method","isForeground"],metricName:"duration",reporter(i){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:i}),-1)}}),ee=new E({eventName:"jolibox_invoke_native2js",tagNameOrder:["status","method","isForeground"],metricName:"duration",reporter(i){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:i}),-1)}}),r("onJoliboxEnterBackground",()=>{X.flush(),Z.flush(),ee.flush()}),ke=!0);function t(i){var x,T;let{method:s,args:o,startTime:a,isForeground:c,errMsg:l=`${s}:fail no errMsg`,errNo:u=0,__timing:g={receiveJSInvoke:0,invokeCallback:0}}=i,{receiveJSInvoke:m,invokeCallback:h}=g,_=(T=(x=l.match(/\S:(\S+)\s?/))==null?void 0:x[1])!=null?T:"fail";X.report({status:_,method:n(s,o),errNo:`${u}`,errMsg:l,isForeground:c,duration:Date.now()-a}),a&&m&&h&&(Z.report({status:_,method:s,isForeground:c,duration:Number((m-a).toFixed(3))}),ee.report({status:_,method:s,isForeground:c,duration:Number((Date.now()-h).toFixed(3))}))}function n(i,s){return(i==="callHostMethod"||i==="callHostMethodSync")&&s!=null&&s.method?`${i}-${s.method}`:i}return t}var re=[],hr=!1,te=Symbol.for("Jolibox.invokeResolverInstance"),vr=new Map;globalThis[te]||(globalThis[te]=vr);var br={get resolveMap(){return globalThis[te]}};function Pe(e,r){let t=0,n=!0,i=br.resolveMap,s=Ae(e,r);r("onJoliboxEnterBackground",()=>{n=!1}),r("onJoliboxEnterForeground",()=>{n=!0,re.forEach(m=>S(this,[m],function*({method:l,args:u,resolve:g}){let h=yield a(l,u);g(h)})),re.length=0});let o=(l,u)=>{let g=i.get(Number(l));if(!g)return;let m=O(u);g(m),i.delete(Number(l))},a=(l,u)=>{var ie,se;let g=Date.now(),m=`${n}`;t+=1;let h=new he;if(i.set(t,h.resolve),!n&&we.includes(l))return new Promise(b=>{re.push({method:l,args:u,resolve:b})});let x=le(f({},{method:l,startTime:g,args:u,isForeground:m}),{invokeType:"js-bridge"}),T=!hr&&Oe.includes(l),j=de(u,T),H=T?j:JSON.stringify(j),p;if(l.endsWith("Sync")||Ie.includes(l)?p=(ie=e.call)==null?void 0:ie.call(e,l,j,t):typeof H=="string"?p=e.invoke(l,H,t):p=(se=e.call)==null?void 0:se.call(e,l,H,t),p){try{typeof p=="string"&&(p=JSON.parse(p)),p=O(p)}catch(b){R.error(b)}return i.delete(t),p.errorCode&&(p.errorCode=A(l,p.errorCode)),s(f(f({},x),p)),p}return l.endsWith("Sync")&&i.delete(t),h.promise.then(b=>(b.errorCode&&(b.errorCode=A(l,b.errorCode)),s(f(f({},x),b)),b))};return{invokeNative:a,applyNative:(l,u)=>{let g=a(l,u);return be(g)?g.then(m=>Me(l,m)):Me(l,g)},invokeHandler:o}}function Me(e,r){if(!y(r)){R.warn(`[Jolibox SDK]${e} no response value`);return}let a=r,{errMsg:t,errNo:n,errorType:i,errorCode:s}=a,o=ue(a,["errMsg","errNo","errorType","errorCode"]);if(t&&t!==`${e}:ok`)throw new Ne(t,n,i,s);return o}var B=Symbol.for("Jolibox.subscribeInstance");function Ce(e){if(globalThis[B])return globalThis[B];let r=new L,t=new L,n=new E({eventName:"jolibox_publish",tagNameOrder:["type","event"],metricName:"duration",reporter(i){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:i}),-1)}});return r.on("onJoliboxEnterBackground",()=>{n.flush()}),globalThis[B]={onNative:r.on.bind(r),offNative:r.off.bind(r),subscribe:t.on.bind(t),unsubscribe:t.off.bind(t),subscribeHandler(i,s,o){let a=O(s),c;if(a.__extra){c=a.params;let{type:l,startTime:u}=a.__extra;n.report({type:l,event:i,duration:Date.now()-u})}else c=a;if(i===J){c.forEach(u=>{let[g,m]=u;try{t.emit(g.slice(N.length),m,o)}catch(h){}});return}if(i.startsWith(N)){t.emit(i.slice(N.length),c,o);return}r.emit(i,c,o)}},globalThis[B]}function De(e){let r=new Map,t;return(i,s,o,a)=>{if(a){let l=o?[o]:"*";e.publish(`${N}${i}`,s,l);return}t||(t=Promise.resolve().then(()=>{r.forEach((l,u)=>{try{let g=u?[u]:"*";e.publish(J,l,g)}catch(g){}}),t=void 0,r.clear()}));let c=r.get(o);c||(c=[],r.set(o,c)),c.push([`${N}${i}`,s])}}function ne(e){let{subscribeHandler:r,onNative:t,offNative:n,subscribe:i,unsubscribe:s}=Ce(e),{invokeNative:o,invokeHandler:a,applyNative:c}=Pe(e,t),l=De(e);return{invokeHandler:a,subscribeHandler:r,applyNative:c,invokeNative:o,onNative:t,offNative:n,publish:l,subscribe:i,unsubscribe:s}}function F(e,r){return{params:e,__extra:{startTime:Date.now(),type:r}}}var M,v={trigger(){},exit(){return Promise.resolve(!1)},backPress(){return Promise.resolve(!1)},onReady(e){v.trigger=e},onDoExit(e){v.exit=e},onDoBackPress(e){v.backPress=e}},Ue=e=>{let r=window.prompt("invoke",JSON.stringify({event:"envSync",paramsString:JSON.stringify({})}));if(!r)e.onError(new _e("native env failed"));else{let{data:t}=JSON.parse(r);return t!=null?t:void 0}};if(window.webkit){let e=window.webkit.messageHandlers,r=(i="")=>{v.trigger(),e.onDocumentReady.postMessage({path:i})},t=i=>S(void 0,null,function*(){let s=yield v.exit();e.doExit.postMessage({uuid:i,shouldInterrupt:s})});M={onDocumentReady:r,doExit:t,invoke(i,s,o){e.invoke.postMessage({event:i,paramsString:s,callbackId:o})},publish(i,s,o){let a=F(s,"joliboxJSCore");window.prompt("publish",JSON.stringify({event:i,paramsString:JSON.stringify(a),webviewIds:o}))},call(i,s,o){let a=window.prompt("invoke",JSON.stringify({event:i,paramsString:JSON.stringify(s),callbackId:o}));if(a)return JSON.parse(a)}};let n={onDocumentReady:r,env:Ue,doExit:t};globalThis.joliboxJSCore=f({},n)}if(window.JoliAndroidSDKBridge){let i,e=window.JoliAndroidSDKBridge,r=(s="")=>{v.trigger(),e.onDocumentReady(JSON.stringify({path:s}))},t=s=>S(void 0,null,function*(){let o=yield v.exit();e.doExit(JSON.stringify({uuid:s,shouldInterrupt:o}))});M={onDocumentReady:r,invoke(s,o,a){e.invoke(JSON.stringify({event:s,paramsString:o,callbackId:a}))},doExit:t,publish(s,o,a){let c=F(o,"joliboxJSCore");e.publish({event:s,paramsString:JSON.stringify(c),webviewIds:a})},call(s,o,a){let c=window.prompt("invoke",JSON.stringify({event:s,paramsString:JSON.stringify(o),callbackId:a}));if(c)return JSON.parse(c)},doBackPress(s){return S(this,null,function*(){let o=yield v.backPress();e.doBackPress(JSON.stringify({uuid:s,shouldInterrupt:o}))})}};let n={onDocumentReady:r,env:Ue,doExit:t};globalThis.joliboxJSCore=f({},n)}var Je=M;if(!Je&&Te())throw new Ee("No joliboxJScore is found, native bridge not found.");var yr=f({},Je),Be=ne(yr),{invokeHandler:Le}=Be,{applyNative:Jt,invokeNative:Bt,onNative:_r,offNative:Ft,subscribeHandler:Nr,publish:jt,subscribe:Ht,unsubscribe:Vt}=Be,Gt=(e,r)=>{_r(e,(...t)=>{var n;(n=t[0])!=null&&n.errorCode&&(t[0].errorCode=A(e,t[0].errorCode)),r(...t)})};globalThis.joliboxJSBridge={callHandler:Le,invokeHandler:Le,subscribeHandler:Nr};export{v as RuntimeLoader,Jt as applyNative,Bt as invokeNative,Ft as offNative,_r as onNative,Gt as onNativeWithError,jt as publish,pr as registerCanIUseContext,Ht as subscribe,Nr as subscribeHandler,Vt as unsubscribe};
|
|
@@ -337,16 +337,18 @@ declare global {
|
|
|
337
337
|
};
|
|
338
338
|
|
|
339
339
|
requestPaymentSync: (params: {
|
|
340
|
-
orderId
|
|
340
|
+
orderId?: string; // 订单Id
|
|
341
341
|
paymentBody: {
|
|
342
342
|
//for TUNETALK
|
|
343
|
-
paymentRequestId
|
|
344
|
-
partnerOpenUserId
|
|
345
|
-
paymentAmount
|
|
346
|
-
paymentCurrency
|
|
347
|
-
bizExtra
|
|
343
|
+
paymentRequestId?: string;
|
|
344
|
+
partnerOpenUserId?: string;
|
|
345
|
+
paymentAmount?: string;
|
|
346
|
+
paymentCurrency?: string;
|
|
347
|
+
bizExtra?: {
|
|
348
348
|
dramaCover: string;
|
|
349
349
|
};
|
|
350
|
+
appStoreProductId?: string;
|
|
351
|
+
appAccountToken?: string;
|
|
350
352
|
};
|
|
351
353
|
redirectUrl?: string; // 支付完成后落地页url
|
|
352
354
|
}) => {
|
|
@@ -358,6 +360,19 @@ declare global {
|
|
|
358
360
|
};
|
|
359
361
|
};
|
|
360
362
|
|
|
363
|
+
requestProductDetailsAsync: (params: { appStoreProductIds: string[] }) => Promise<{
|
|
364
|
+
errMsg: string;
|
|
365
|
+
errNo?: number;
|
|
366
|
+
data: {
|
|
367
|
+
[appStoreProductId: string]: {
|
|
368
|
+
productId: string;
|
|
369
|
+
title: string;
|
|
370
|
+
price: string;
|
|
371
|
+
priceCurrencyCode: number;
|
|
372
|
+
};
|
|
373
|
+
};
|
|
374
|
+
}>;
|
|
375
|
+
|
|
361
376
|
callHostMethodSync: (params: { method: string; params: any }) => {
|
|
362
377
|
errMsg: string;
|
|
363
378
|
errNo?: number;
|
|
@@ -421,8 +436,19 @@ declare global {
|
|
|
421
436
|
onPaymentStateChange: [
|
|
422
437
|
{
|
|
423
438
|
orderUUID: string;
|
|
424
|
-
status:
|
|
439
|
+
status:
|
|
440
|
+
| 'SUCCESS'
|
|
441
|
+
| 'FAIL_NOT_LOGIN'
|
|
442
|
+
| 'FAIL_PAYING'
|
|
443
|
+
| 'FAIL_PRODUCT_EMPTY'
|
|
444
|
+
| 'FAIL_GET_PRODUCT_INFO'
|
|
445
|
+
| 'FAIL_LAUNCH_BILLING'
|
|
446
|
+
| 'FAIL_TRANSACTION'
|
|
447
|
+
| 'FAIL_VERIFY'
|
|
448
|
+
| 'TRANSACTION_PENDING'
|
|
449
|
+
| 'FAILED';
|
|
425
450
|
totalAmount: string;
|
|
451
|
+
orderResponse?: any;
|
|
426
452
|
}
|
|
427
453
|
];
|
|
428
454
|
onBeforeBackPress: [
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* can-i-use for native jsb
|
|
3
|
+
*/
|
|
4
|
+
import { NativeCanIUseInfo } from '@jolibox/common';
|
|
5
|
+
import './registered/payment';
|
|
6
|
+
export declare function registerCanIUseNative(name: keyof jsb.service.NativeMethodMap, config: NativeCanIUseInfo): void;
|
|
7
|
+
export declare const registerCanIUseContext: (nativeSDKVersionCodeGetter: () => number | undefined) => {
|
|
8
|
+
canIUseNative: (schema: string) => boolean;
|
|
9
|
+
};
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jolibox/native-bridge",
|
|
3
3
|
"description": "This project is Jolibox JS-SDk bridge for Native",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.30",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
7
7
|
"license": "MIT",
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
],
|
|
12
12
|
"types": "./dist/index.d.ts",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@jolibox/common": "1.1.
|
|
15
|
-
"@jolibox/types": "1.1.
|
|
14
|
+
"@jolibox/common": "1.1.30",
|
|
15
|
+
"@jolibox/types": "1.1.30"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"typescript": "5.7.3",
|
|
@@ -337,16 +337,18 @@ declare global {
|
|
|
337
337
|
};
|
|
338
338
|
|
|
339
339
|
requestPaymentSync: (params: {
|
|
340
|
-
orderId
|
|
340
|
+
orderId?: string; // 订单Id
|
|
341
341
|
paymentBody: {
|
|
342
342
|
//for TUNETALK
|
|
343
|
-
paymentRequestId
|
|
344
|
-
partnerOpenUserId
|
|
345
|
-
paymentAmount
|
|
346
|
-
paymentCurrency
|
|
347
|
-
bizExtra
|
|
343
|
+
paymentRequestId?: string;
|
|
344
|
+
partnerOpenUserId?: string;
|
|
345
|
+
paymentAmount?: string;
|
|
346
|
+
paymentCurrency?: string;
|
|
347
|
+
bizExtra?: {
|
|
348
348
|
dramaCover: string;
|
|
349
349
|
};
|
|
350
|
+
appStoreProductId?: string;
|
|
351
|
+
appAccountToken?: string;
|
|
350
352
|
};
|
|
351
353
|
redirectUrl?: string; // 支付完成后落地页url
|
|
352
354
|
}) => {
|
|
@@ -358,6 +360,19 @@ declare global {
|
|
|
358
360
|
};
|
|
359
361
|
};
|
|
360
362
|
|
|
363
|
+
requestProductDetailsAsync: (params: { appStoreProductIds: string[] }) => Promise<{
|
|
364
|
+
errMsg: string;
|
|
365
|
+
errNo?: number;
|
|
366
|
+
data: {
|
|
367
|
+
[appStoreProductId: string]: {
|
|
368
|
+
productId: string;
|
|
369
|
+
title: string;
|
|
370
|
+
price: string;
|
|
371
|
+
priceCurrencyCode: number;
|
|
372
|
+
};
|
|
373
|
+
};
|
|
374
|
+
}>;
|
|
375
|
+
|
|
361
376
|
callHostMethodSync: (params: { method: string; params: any }) => {
|
|
362
377
|
errMsg: string;
|
|
363
378
|
errNo?: number;
|
|
@@ -421,8 +436,19 @@ declare global {
|
|
|
421
436
|
onPaymentStateChange: [
|
|
422
437
|
{
|
|
423
438
|
orderUUID: string;
|
|
424
|
-
status:
|
|
439
|
+
status:
|
|
440
|
+
| 'SUCCESS'
|
|
441
|
+
| 'FAIL_NOT_LOGIN'
|
|
442
|
+
| 'FAIL_PAYING'
|
|
443
|
+
| 'FAIL_PRODUCT_EMPTY'
|
|
444
|
+
| 'FAIL_GET_PRODUCT_INFO'
|
|
445
|
+
| 'FAIL_LAUNCH_BILLING'
|
|
446
|
+
| 'FAIL_TRANSACTION'
|
|
447
|
+
| 'FAIL_VERIFY'
|
|
448
|
+
| 'TRANSACTION_PENDING'
|
|
449
|
+
| 'FAILED';
|
|
425
450
|
totalAmount: string;
|
|
451
|
+
orderResponse?: any;
|
|
426
452
|
}
|
|
427
453
|
];
|
|
428
454
|
onBeforeBackPress: [
|