Socket
Socket
Sign inDemoInstall

@huolala-tech/page-spy-alipay

Package Overview
Dependencies
Maintainers
0
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@huolala-tech/page-spy-alipay - npm Package Compare versions

Comparing version 1.9.7 to 1.9.8

2

dist/cjs/index.min.js

@@ -1,2 +0,2 @@

"use strict";function e(e,t,n,s){return new(n||(n=Promise))((function(o,r){function i(e){try{c(s.next(e))}catch(e){r(e)}}function a(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,a)}c((s=s.apply(e,t||[])).next())}))}function t(){return Math.random().toString(36).slice(2)}function n(e){return Object.prototype.toString.call(e)}function s(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function o(e){return"[object BigInt]"===n(e)}function r(e){return e instanceof Array}function i(e){return"object"==typeof e&&null!==e}function a(e){return!(!i(e)||"[object Object]"!==n(e))}"function"==typeof SuppressedError&&SuppressedError;const c=e=>"".concat(e),l=e=>({ok:!0,value:e});function u(e){return void 0===e?l(c(e)):null===e?l(e):function(e){return"number"==typeof e}(e)&&(e===-1/0||e===1/0||Number.isNaN(e))?l(c(e)):o(e)?l("".concat(e,"n")):"symbol"==typeof e||"function"==typeof e?l(c(e.toString())):e instanceof Error?l(c(e.stack)):e===Object.prototype?{value:null,ok:!1}:e instanceof Object||"object"==typeof e?{value:e,ok:!1}:l(e)}function h(e){return void 0===e?"undefined":null===e?"null":o(e)?"bigint":e instanceof Object?e instanceof Error?"error":"function"==typeof e?"function":"object":typeof e}const d=Object.assign({},console),g=["log","info","error","warn","debug"].reduce(((e,t)=>(e[t]=function(){for(var e=arguments.length,n=new Array(e),s=0;s<e;s++)n[s]=arguments[s];console[t]("[PageSpy] [".concat(t.toLocaleUpperCase(),"] "),...n)},e.unproxy[t]=function(){for(var e=arguments.length,n=new Array(e),s=0;s<e;s++)n[s]=arguments[s];d[t]("[PageSpy] [".concat(t.toLocaleUpperCase(),"] "),...n)},e)),{unproxy:{}});const p="message",f="broadcast",m="ping",y="updateRoomInfo";var S,v=Object.freeze({__proto__:null,BROADCAST:f,CLOSE:"close",CONNECT:"connect",ERROR:"error",JOIN:"join",LEAVE:"leave",MESSAGE:p,PING:m,PONG:"pong",UPDATE_ROOM_INFO:y});function b(e,n){let s=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];return{role:"client",type:e,data:Object.assign(Object.assign({},s&&{id:t()}),n)}}class O{constructor(e){this.id="",this.method="",this.url="",this.requestType="xhr",this.requestHeader=null,this.status=0,this.statusText="",this.readyState=0,this.responseReason=null,this.responseType="",this.responseHeader=null,this.startTime=0,this.endTime=0,this.costTime=0,this.postData=null,this.requestPayload=null,this.withCredentials=!1,this.id=e}}!function(e){e[e.UNSENT=0]="UNSENT",e[e.OPENED=1]="OPENED",e[e.HEADERS_RECEIVED=2]="HEADERS_RECEIVED",e[e.LOADING=3]="LOADING",e[e.DONE=4]="DONE"}(S||(S={}));class I{constructor(e){this.socketStore=e,this.reqMap=Object.create(null)}getRequestMap(){return this.reqMap}getRequest(e){return this.reqMap[e]}removeRequest(e){delete this.reqMap[e]}createRequest(e){return e?this.reqMap[e]?(g.warn("The request object has been in store, disallow duplicate create"),!1):(this.reqMap[e]=new O(e),!0):(g.warn('The "id" is required when init request object'),!1)}setRequest(e,t){return!(!e||!t)&&(this.reqMap[e]=t,!0)}sendRequestItem(e,t){var n;if(!1!==(null===(n=I.dataProcessor)||void 0===n?void 0:n.call(I,t)))try{this.reqMap[e]||(this.reqMap[e]=t);const n=b("network",Object.assign({},t),!1);this.socketStore.dispatchEvent("public-data",n),this.socketStore.broadcastMessage(n,t.readyState!==S.DONE),this.deferDeleteRequest(e)}catch(e){g.error(e.message)}}deferDeleteRequest(e){const t=this.getRequest(e);t&&t.readyState===S.DONE&&setTimeout((()=>{delete this.reqMap[e]}),3e3)}}class C{constructor(){this.store={},this.instanceStore={}}getStore(){return this.store}resetStore(){this.store={}}getInstanceStore(){return this.instanceStore}resetInstanceStore(){this.instanceStore={}}transformToAtom(e){let n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const{value:s,ok:o}=u(e),r=t();if(o)return{id:r,type:h(e),value:s};if(n)try{return{id:r,type:"json",value:JSON.stringify(e)}}catch(e){return{id:r,type:"json",value:null}}return this.add(e)}get(e){const n=this.store[e],o=this.instanceStore[e];if(!n)return null;const r={},i=Object.getOwnPropertyDescriptors(n);Object.keys(i).forEach((e=>{const n=i[e];s(n,"value")&&(n.value=this.transformToAtom(n.value)),r[e]=C.getAtomOverview({atomId:t(),instanceId:o,value:n})}));const a=this.addExtraProperty(e);return Object.assign(Object.assign({},r),a)}getOrigin(e){const t=this.store[e];return t||null}add(e){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";const o=t();let r=o;var a;i(a=e)&&s(a,"constructor")&&"function"==typeof a.constructor&&(r=n),this.store[o]=e,this.instanceStore[o]=r;const c=C.getSemanticValue(e);return C.getAtomOverview({atomId:o,value:c,instanceId:r})}static getAtomOverview(e){let{instanceId:n="",atomId:s,value:o}=e;return{id:t(),type:"atom",__atomId:s,instanceId:n,value:o}}static getSemanticValue(e){if(a(e))return"Object {...}";if(r(e))return"Array (".concat(e.length,")");return e.constructor.name}addExtraProperty(e){const t=this.store[e],n=this.instanceStore[e],s={};if((t instanceof String||t instanceof Number||t instanceof Boolean)&&(s["[[PrimitiveValue]]"]=this.transformToAtom(t.valueOf())),t instanceof Set){const e={};let n=0;for(const s of t)e[n++]=s;e.size=t.size,s["[[Entries]]"]=this.transformToAtom(e)}if(t instanceof Map){const e={};let n=0;for(const[s,o]of t.entries())e[n++]={key:s,value:o};e.size=t.size,s["[[Entries]]"]=this.transformToAtom(e)}var o;return(r(t)||(o=t,"function"==typeof NodeList&&"NodeList"===NodeList.name&&o instanceof NodeList||"function"==typeof HTMLCollection&&"HTMLCollection"===HTMLCollection.name&&o instanceof HTMLCollection))&&(s.length=this.transformToAtom(t.length)),null!==Object.getPrototypeOf(t)?s["[[Prototype]]"]=this.add(Object.getPrototypeOf(t),n):s.___proto___=this.transformToAtom(null),s}}const E=new C;class k{static makeClientInfoMsg(){return{sdk:k.info.sdk,isDevTools:k.info.isDevTools,ua:k.getName(),plugins:k.plugins}}static getName(){if(!k._name){const{ua:e,osType:t,osVersion:n,browserType:s,browserVersion:o}=k.info;k._name=e||"".concat(t,"/").concat(n," ").concat(s,"/").concat(o)}return k._name}}k.info={osType:"unknown",osVersion:"unknown",browserType:"unknown",browserVersion:"unknown",framework:"unknown",isDevTools:!1,sdk:"browser"},k.plugins=[];class T{defaultConfig(){return{}}constructor(){this.mergeConfig=e=>{const t=Object.entries(e).reduce(((e,t)=>{let[n,s]=t;return this.privateKeys.includes(n)||(e[n]=s),e}),{});return this.value=Object.assign(Object.assign({},this.defaultConfig()),t),this.value},this.value=this.defaultConfig()}get(){return this.value}set(e,t){this.value[e]=t}}const j="page-spy-room";var P;!function(e){e[e.CONNECTING=0]="CONNECTING",e[e.OPEN=1]="OPEN",e[e.CLOSING=2]="CLOSING",e[e.CLOSED=3]="CLOSED"}(P||(P={}));const w=2e3,R=Math.pow(1.5,4)*w;class N{constructor(){this.events={open:[],close:[],error:[],message:[]}}emit(e,t){this.events[e].forEach((e=>{e(t)})),"close"!==e&&"error"!==e||this.clearListeners()}onOpen(e){this.events.open.push(e)}onClose(e){this.events.close.push(e)}onError(e){this.events.error.push(e)}onMessage(e){this.events.message.push(e)}clearListeners(){Object.entries(this.events).forEach((e=>{let[,t]=e;t.splice(0)}))}}class q{getSocket(){return this.socketWrapper}updateRoomInfo(){if(this.getPageSpyConfig){const{project:e,title:t}=this.getPageSpyConfig(),n=k.getName();this.send({type:y,content:{info:{name:n,group:e,tags:{title:t,name:n,group:e}}}},!0)}}constructor(){this.socketUrl="",this.socketConnection=null,this.debuggerConnection=null,this.pingTimer=null,this.pongTimer=null,this.retryTimer=null,this.isOffline=!1,this.messageCapacity=0,this.messages=[],this.events={debug:[],refresh:[],"atom-detail":[],"atom-getter":[],"debugger-online":[],"database-pagination":[],"public-data":[],"harbor-clear":[]},this.retryInterval=w,this.connectable=!0,this.getPageSpyConfig=null,this.addListener("atom-detail",q.handleResolveAtom),this.addListener("atom-getter",q.handleAtomPropertyGetter),this.addListener("debugger-online",this.handleFlushBuffer)}init(t){return e(this,void 0,void 0,(function*(){var e,n,s,o,r;try{if(!t)throw Error("WebSocket url cannot be empty");this.socketWrapper.clearListeners(),this.socketWrapper.getState()===P.OPEN&&(yield new Promise((e=>{this.socketWrapper.onClose((()=>{this.socketWrapper.clearListeners(),e()})),this.socketWrapper.close()}))),null===(e=this.socketWrapper)||void 0===e||e.onOpen((()=>{this.connectOnline()})),null===(n=this.socketWrapper)||void 0===n||n.onMessage((e=>{this.handleMessage(e)})),null===(s=this.socketWrapper)||void 0===s||s.onClose((()=>{this.connectOffline()})),null===(o=this.socketWrapper)||void 0===o||o.onError((()=>{this.connectOffline()})),this.socketUrl=t,null===(r=this.socketWrapper)||void 0===r||r.init(t)}catch(e){g.error(e.message)}}))}addListener(e,t){this.events[e]||(this.events[e]=[]),this.events[e].push(t)}removeListener(e,t){const n=this.events[e]||[],s=n.indexOf(t);s>-1&&n.splice(s,1)}broadcastMessage(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const n=function(e){return{type:f,content:{data:e}}}(e);this.send(n,t)}close(){var e;this.connectable=!1,this.clearPing(),null===(e=this.socketWrapper)||void 0===e||e.close(),this.messages=[],Object.entries(this.events).forEach((e=>{let[t,n]=e;["atom-detail","atom-getter","debugger-online"].includes(t)||n.splice(0)}))}connectOnline(){this.retryInterval=w,this.updateRoomInfo(),this.ping()}connectOffline(){this.socketConnection=null,this.debuggerConnection=null,this.clearPing(),this.retryTimer&&clearTimeout(this.retryTimer),this.connectable&&(this.retryTimer=setTimeout((()=>{this.retryInterval<R&&(this.retryInterval*=1.5),this.retryTimer=null,this.tryReconnect()}),this.retryInterval))}tryReconnect(){this.init(this.socketUrl)}ping(){this.pingTimer&&clearTimeout(this.pingTimer),this.pongTimer&&clearTimeout(this.pongTimer),this.pingTimer=setTimeout((()=>{this.send({type:"ping",content:null}),this.pingTimer=null,this.pongTimer=setTimeout((()=>{this.connectOffline(),this.pongTimer=null}),5e3)}),5e3)}clearPing(){this.pingTimer&&(clearTimeout(this.pingTimer),this.pingTimer=null),this.pongTimer&&(clearTimeout(this.pongTimer),this.pongTimer=null)}handlePong(){clearTimeout(this.pongTimer),this.pongTimer=null,this.ping()}handleMessage(e){var t;q.messageFilters.length&&q.messageFilters.forEach((t=>{e=t(e)}));const{CONNECT:n,MESSAGE:s,ERROR:o,JOIN:r,PING:i,PONG:a,LEAVE:c,CLOSE:l,BROADCAST:u}=v,h=JSON.parse(e.data),{type:d}=h;switch(d){case n:const{selfConnection:e,roomConnections:i}=h.content;this.socketConnection=e,this.debuggerConnection=i.find((e=>"Debugger"===e.userId))||null;break;case r:case c:const{connection:a}=h.content;"Debugger"===a.userId&&(d===r?(this.debuggerConnection=a,this.sendClientInfo()):this.debuggerConnection=null);break;case s:const{data:u,from:g,to:p}=h.content;p.address===(null===(t=this.socketConnection)||void 0===t?void 0:t.address)&&this.dispatchEvent(u.type,{source:u,from:g,to:p});break;case l:case o:this.connectOffline()}this.handlePong()}dispatchEvent(e,t){var n;["public-data"].includes(e)?this.events["public-data"].forEach((e=>{e(t)})):null===(n=this.events[e])||void 0===n||n.forEach((e=>{e.call(this,t,(e=>{this.unicastMessage(e,t.from)}))}))}unicastMessage(e,t){const n=function(e,t,n){return{type:p,content:{data:e,from:t,to:n}}}(e,this.socketConnection,t);this.send(n)}handleFlushBuffer(e){const{latestId:t}=e.source.data,n=this.messages.findIndex((e=>e.content.data.data.id===t));this.messages.slice(n+1).forEach((t=>{const n={type:p,content:{data:t.content.data,from:this.socketConnection,to:e.from}};this.send(n,!0)}))}static handleResolveAtom(e,t){let{source:n}=e;const{type:s,data:o}=n;if("atom-detail"===s){const e=E.get(o)||{};t(b("atom-detail-".concat(o),e,!1))}}static handleAtomPropertyGetter(e,t){let{source:n}=e;var s,o;const{type:r,data:i}=n;if("atom-getter"===r){const{id:e,parentId:n,key:r,instanceId:a}=i,c=E.getOrigin(a),l=E.getOrigin(n);let u={};u=c&&l?null===(o=null===(s=Object.getOwnPropertyDescriptor(l,r))||void 0===s?void 0:s.get)||void 0===o?void 0:o.call(c):new Error("Getter computed failed");t(b("atom-getter-".concat(e),E.transformToAtom(u)))}}send(e){let n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];var s;if(this.checkIfSend(e))try{const n=e;n.createdAt=Date.now(),n.requestId=t();const o=function(e){const{ok:t,value:n}=u(e);return t?n:JSON.stringify(e,((e,t)=>u(t).value),2)}(n);null===(s=this.socketWrapper)||void 0===s||s.send(o)}catch(e){g.error("Incompatible: ".concat(e.message)),this.connectOffline()}this.checkIfCache(e,n)&&(0!==this.messageCapacity&&this.messages.length>=this.messageCapacity&&this.messages.shift(),this.messages.push(e))}checkIfSend(e){return this.socketWrapper.getState()===P.OPEN&&(!![y,m].includes(e.type)||!!this.debuggerConnection)}checkIfCache(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return!this.isOffline&&!t&&![p,m].includes(e.type)}sendClientInfo(){const e=k.makeClientInfoMsg();this.broadcastMessage({role:"client",type:"client-info",data:e},!0)}}q.messageFilters=[];const A=e=>{const t=[];return Object.entries(e).forEach((e=>{let[n,s]=e;t.push("".concat(n,"=").concat(s))})),t.join("&")};let D;const L=()=>{if(!D)throw Error("the mp sdk is not set");return D},M={setStorage:(e,t)=>null==D?void 0:D.setStorageSync(e,t),getStorage:e=>null==D?void 0:D.getStorageSync(e),removeStorage:e=>null==D?void 0:D.getStorageSync(e)};class U extends N{constructor(){super(...arguments),this.socketInstance=null,this.state=0}init(t){return e(this,void 0,void 0,(function*(){this.state=P.CONNECTING;const e=L(),n=e=>{this.state=P.CLOSED,this.emit("close",e)},s=e=>{this.state=P.OPEN,this.emit("open",e)},o=e=>{this.state=P.CLOSED,this.emit("error",e)},r=e=>{this.emit("message",e)};if(U.isSingleSocket)e.connectSocket({url:t}),e.onSocketClose(n),e.onSocketError(o),e.onSocketMessage(r),e.onSocketOpen(s);else{let i=e.connectSocket({url:t,multiple:!0,complete(){}});i instanceof Promise&&(i=yield i),i.onClose(n),i.onError(o),i.onOpen(s),i.onMessage(r),this.socketInstance=i}}))}send(e){var t;U.isSingleSocket?L().sendSocketMessage({data:e}):null===(t=this.socketInstance)||void 0===t||t.send({data:e})}close(){var e;U.isSingleSocket?L().closeSocket({}):null===(e=this.socketInstance)||void 0===e||e.close({}),this.state=P.CLOSED}getState(){return this.state}}U.isSingleSocket=!1;var x=new class extends q{constructor(){super(...arguments),this.socketWrapper=new U}onOffline(){M.removeStorage(j)}};class H{constructor(){this.name="ConsolePlugin",this.console={},this.proxyTypes=["log","info","error","warn","debug"],this.$pageSpyConfig=null}onInit(t){return e(this,arguments,void 0,(function(e){var t=this;let{config:n}=e;return function*(){H.hasInitd||(H.hasInitd=!0,t.$pageSpyConfig=n,t.init())}()}))}init(){const e=this;this.proxyTypes.forEach((t=>{this.console[t]=console[t]||console.log||(()=>{}),Object.defineProperty(console,t,{value(){const n=getCurrentPages().pop();let s="/";n&&(s=n.route,n.options&&Object.keys(n.options).length>0&&(s+="?"+A(n.options)));for(var o=arguments.length,r=new Array(o),i=0;i<o;i++)r[i]=arguments[i];e.printLog({logType:t,logs:r,url:s})},configurable:!0,enumerable:!0,writable:!0})}))}reset(){this.proxyTypes.forEach((e=>{const t=this.console[e];t&&(console[e]=t)}))}onReset(){this.reset(),H.hasInitd=!1}printLog(e){var t,n,s;if(e.logs&&e.logs.length){const o=null===(n=null===(t=this.$pageSpyConfig)||void 0===t?void 0:t.dataProcessor)||void 0===n?void 0:n.console;if(o){this.reset();const t=o(e);if(this.init(),!1===t)return}this.console[e.logType](...e.logs);const r=b("console",Object.assign(Object.assign({},e),{time:Date.now(),logs:e.logs.map((e=>E.transformToAtom(e,!1)))}));if(x.broadcastMessage(r),null===(s=this.$pageSpyConfig)||void 0===s?void 0:s.serializeData){const t=Object.assign(Object.assign({},r),{data:Object.assign(Object.assign({},r.data),{logs:e.logs.map((e=>E.transformToAtom(e,!0)))})});x.dispatchEvent("public-data",t)}else x.dispatchEvent("public-data",r)}}}H.hasInitd=!1;class F{constructor(){this.name="ErrorPlugin",this.$pageSpyConfig=null,this.errorHandler=this.errorHandler.bind(this),this.unhandledRejectionHandler=this.unhandledRejectionHandler.bind(this)}onInit(e){let{config:t}=e;F.hasInitd||(F.hasInitd=!0,this.$pageSpyConfig=t,this.onUncaughtError(),this.onUnhandledRejectionError())}onReset(){const e=L();e.canIUse("offError")&&e.offError(this.errorHandler),e.canIUse("offUnhandledRejection")&&e.offUnhandledRejection(this.unhandledRejectionHandler),F.hasInitd=!1}errorHandler(e){if(F.hasInitd)if(e.stack||e.message){const{message:t,stack:n}=e;this.sendMessage(n||t,(e=>{if("object"!=typeof e)return null;const{name:t,message:n,stack:s}=Object(e);return!1===[t,n,s].every(Boolean)?null:{name:t,message:n,stack:s}})(e))}else{const e="[PageSpy] An unknown error occurred and no message or stack trace available";this.sendMessage(e,null)}}unhandledRejectionHandler(e){F.hasInitd&&this.sendMessage("UnHandled Rejection",{name:"unhandledrejection",message:e.reason})}onUncaughtError(){const e=L();e.canIUse("onError")&&e.onError(this.errorHandler)}onUnhandledRejectionError(){const e=L();e.canIUse("onUnhandledRejection")&&e.onUnhandledRejection(this.unhandledRejectionHandler)}sendMessage(e,t){var n,s,o;const r={logType:"error",logs:[e],time:Date.now(),url:"wx:light-app",errorDetail:t};if(!1===(null===(o=null===(s=null===(n=this.$pageSpyConfig)||void 0===n?void 0:n.dataProcessor)||void 0===s?void 0:s.console)||void 0===o?void 0:o.call(s,r)))return;r.logs=r.logs.map((e=>E.transformToAtom(e)));const i=b("console",r);x.dispatchEvent("public-data",i),x.broadcastMessage(i)}}F.hasInitd=!1;class W extends I{constructor(){super(x)}}class _ extends W{constructor(){super(),this.request=null,this.initProxyHandler()}reset(){if(this.request){const e=L();Object.defineProperty(e,"request",{value:this.request})}}initProxyHandler(){const e=this,s=L(),o=s.request;o&&(this.request=o,Object.defineProperty(s,"request",{value(s){const r=t();e.createRequest(r);const i=e.getRequest(r);if(i){const t=s.method||"GET",{url:c}=s;i.requestHeader=[],i.url=c,i.method=t.toUpperCase(),i.requestType="mp-request",i.status=0,i.statusText="Pending",i.startTime=Date.now(),i.readyState=S.UNSENT,a(s.header)&&(i.requestHeader=Object.entries(s.header).map((e=>{let[t,n]=e;return[String(t),String(n)]}))),i.requestHeader.push(["Content-Type","application/json"]);const{data:l}=s;if(l)if("string"==typeof l)i.requestPayload=l;else if(l instanceof ArrayBuffer)i.requestPayload="[object ArrayBuffer]";else try{i.requestPayload=JSON.stringify(l)}catch(e){i.requestPayload=n(l)}e.sendRequestItem(r,i);const u=s.success,h=s.fail,d=s.complete,g=()=>{i.endTime=Date.now(),i.costTime=i.endTime-(i.startTime||i.endTime)};s.success=function(t){g(),i.status=(null==t?void 0:t.statusCode)||200,i.statusText="Done",i.responseHeader=[...Object.entries((null==t?void 0:t.header)||{})],i.readyState=S.HEADERS_RECEIVED,e.sendRequestItem(r,i);const n=function(e){const t=Object.keys(e),n={};for(let s=0;s<t.length;s++){const o=t[s];n[o.toLowerCase()]=e[o]}return n}((null==t?void 0:t.header)||{})["content-type"];switch(n&&(n.includes("application/json")&&(i.responseType="json"),(n.includes("text/html")||n.includes("text/plain"))&&(i.responseType="text")),i.responseType||(i.responseType="arraybuffer"),i.responseType){case"json":case"text":if("string"==typeof(null==t?void 0:t.data))try{i.response=JSON.parse(t.data)}catch(e){i.response=t.data,i.responseType="text"}else i.response=null==t?void 0:t.data;break;case"arraybuffer":i.response="[object ArrayBuffer]"}null==u||u(t)},s.fail=function(e){g(),null==h||h(e)},s.complete=function(t){i.readyState=S.DONE,e.sendRequestItem(r,i),null==d||d(t)};return o(s)}return g.warn("The request object is not found on request event"),null}}))}}class G{constructor(){this.name="NetworkPlugin",this.requestProxy=null}onInit(e){let{config:t}=e;G.hasInitd||(G.hasInitd=!0,I.dataProcessor=t.dataProcessor.network,this.requestProxy=new _)}onReset(){var e;null===(e=this.requestProxy)||void 0===e||e.reset(),G.hasInitd=!1}}G.hasInitd=!1;class V{constructor(){this.name="SystemPlugin",this.$pageSpyConfig=null}onInit(e){let{config:t}=e;V.hasInitd||(V.hasInitd=!0,this.$pageSpyConfig=t,x.addListener("refresh",((e,t)=>{let{source:n}=e;var s,o,r;const{data:i}=n;if("system"===i){const e=V.getSystemInfo();if(!1===(null===(r=null===(o=null===(s=this.$pageSpyConfig)||void 0===s?void 0:s.dataProcessor)||void 0===o?void 0:o.system)||void 0===r?void 0:r.call(o,e)))return;const n=b("system",e);x.dispatchEvent("public-data",n),t(n)}})))}onReset(){V.hasInitd=!1}static getSystemInfo(){return{system:{ua:k.getName()},features:{}}}}function $(e){const t=typeof e;let n=e;return"string"===t||"boolean"===t||"number"===t?n=String(e):"object"===t&&(n=e instanceof Date?e.toDateString():JSON.stringify(e)),n}V.hasInitd=!1;class B{constructor(){this.name="StoragePlugin",this.$pageSpyConfig=null}onInit(e){let{config:t}=e;B.hasInitd||(B.hasInitd=!0,this.$pageSpyConfig=t,this.initStorageProxy(),this.listenRefreshEvent())}onReset(){const e=L();Object.entries(B.originFunctions).forEach((t=>{let[n,s]=t;Object.defineProperty(e,n,{value:s})})),B.hasInitd=!1}sendRefresh(){const e=L();try{const t=e.getStorageInfoSync(),n={type:"mpStorage",action:"get",data:t.keys.map((e=>({name:e,value:$(M.getStorage(e))})))};this.sendStorageItem(n)}catch(e){}}listenRefreshEvent(){x.addListener("refresh",(t=>e(this,[t],void 0,(function(e){var t=this;let{source:n}=e;return function*(){const{data:e}=n;"mpStorage"===e&&t.sendRefresh()}()}))))}initStorageProxy(){const e=L();["setStorage","setStorageSync","removeStorage","removeStorageSync","clearStorage","clearStorageSync","batchSetStorageSync","batchSetStorage"].forEach((t=>{e[t]&&(B.originFunctions[t]=e[t])}));const t=this;Object.defineProperties(e,{setStorage:{value:e=>B.originFunctions.setStorage(Object.assign(Object.assign({},e),{success(n){var s;t.sendSetItem(e.key,e.data),null===(s=e.success)||void 0===s||s.call(e,n)}}))},setStorageSync:{value(e,n){try{let s;if("mp-alipay"!==k.info.browserType||k.info.framework&&"unknown"!==k.info.framework){const o=e;s=B.originFunctions.setStorageSync(o,n),t.sendSetItem(o,n)}else{const n=e;s=B.originFunctions.setStorageSync(n),t.sendSetItem(n.key,n.data)}return s}catch(t){throw g.error("Failed to set storage synchronously: ".concat(e)),t}}},removeStorage:{value:e=>B.originFunctions.removeStorage(Object.assign(Object.assign({},e),{success(n){var s;t.sendRemoveItem(e.key),null===(s=e.success)||void 0===s||s.call(e,n)}}))},removeStorageSync:{value(e){try{const n=B.originFunctions.removeStorageSync(e);return t.sendRemoveItem(n),n}catch(t){throw g.error("Failed to remove storage synchronously: ".concat(e)),t}}},clearStorage:{value:e=>B.originFunctions.clearStorage(Object.assign(Object.assign({},e),{success(n){var s;t.sendClearItem(),null===(s=e.success)||void 0===s||s.call(e,n)}}))},clearStorageSync:{value(){try{const e=B.originFunctions.clearStorageSync();return t.sendClearItem(),e}catch(e){throw g.error("Failed to clear storage synchronously"),e}}}}),e.canIUse("batchSetStorageSync")&&Object.defineProperty(e,"batchSetStorageSync",{value(e){try{const n=B.originFunctions.batchSetStorageSync(e);return e.forEach((e=>{t.sendSetItem(e.key,e.value)})),n}catch(t){throw g.error("Failed to batch set storage synchronously: ".concat(JSON.stringify(e.map((e=>e.key))))),t}}}),e.canIUse("batchSetStorage")&&Object.defineProperty(e,"batchSetStorage",{value:e=>B.originFunctions.batchSetStorage(Object.assign(Object.assign({},e),{success(n){var s;e.kvList.forEach((e=>{t.sendSetItem(e.key,e.value)})),null===(s=e.success)||void 0===s||s.call(e,n)}}))})}sendSetItem(e,t){this.sendStorageItem({type:"mpStorage",action:"set",name:e,value:$(t)})}sendRemoveItem(e){this.sendStorageItem({type:"mpStorage",action:"remove",name:e})}sendClearItem(){this.sendStorageItem({type:"mpStorage",action:"clear"})}sendStorageItem(e){var t,n,s;if(!1===(null===(s=null===(n=null===(t=this.$pageSpyConfig)||void 0===t?void 0:t.dataProcessor)||void 0===n?void 0:n.storage)||void 0===s?void 0:s.call(n,e)))return;const o=b("storage",e);x.dispatchEvent("public-data",o),x.broadcastMessage(o,!0)}}B.hasInitd=!1,B.originFunctions={};const J=e=>!1===e?["http://","ws://"]:["https://","wss://"];class z{constructor(e){if(this.config=e,!e.get().api)throw Error("The api base url cannot be empty")}get base(){return this.config.get().api}createRoom(){const{enableSSL:e,project:t,title:n,useSecret:s,secret:o}=this.config.get(),r=J(e),i=k.getName(),a=A({group:t,title:n,name:encodeURIComponent(i)});return(c=L().request,e=>new Promise(((t,n)=>{c(Object.assign(Object.assign({},e),{success(e){t(e)},fail(e){n(e)}}))})))({url:"".concat(r[0]).concat(this.base,"/api/v1/room/create?").concat(a),method:"POST",data:JSON.stringify({useSecret:s,secret:o})}).then((e=>{var t;const{name:n,address:s}=(null===(t=e.data)||void 0===t?void 0:t.data)||{};return{roomUrl:this.getRoomUrl(s),address:s,name:n}}),(e=>{throw Error("Request create room failed: ".concat(e.message))}));var c}getRoomUrl(e){const n=this.config.get(),s=J(n.enableSSL);return"".concat(s[1]).concat(this.base,"/api/v1/ws/room/join?").concat(A({address:e,name:"client:".concat(t()),userId:"Client",forceCreate:!0,useSecret:n.useSecret,secret:n.secret}))}}class K extends T{constructor(){super(...arguments),this.privateKeys=["secret"]}defaultConfig(){return{api:"",project:"default",title:"",enableSSL:null,disabledOnProd:!0,disabledPlugins:[],singletonSocket:!1,messageCapacity:1e3,useSecret:!1,secret:"",serializeData:!1,dataProcessor:{}}}}class Q{constructor(e){if(this.root=null,this.version="1.9.7",this.request=null,this.name="",this.address="",this.roomUrl="",this.socketStore=x,this.config=new K,this.cacheTimer=null,Q.instance)return g.warn("Cannot initialize PageSpy multiple times"),Q.instance;const t=this.config.mergeConfig(e);t.singletonSocket&&(U.isSingleSocket=!0);const n=L();if(n.canIUse("getAccountInfoSync")&&n.getAccountInfoSync){if("release"===n.getAccountInfoSync().miniProgram.envVersion&&!1!==t.disabledOnProd)return void g.warn("PageSpy is not allowed on release env of mini program")}Q.instance=this,this.request=new z(this.config),this.updateConfiguration(),this.triggerPlugins("onInit",{socketStore:x,config:t,atom:E}),k.plugins=Q.pluginsWithOrder.map((e=>e.name)),this.init()}updateConfiguration(){const{messageCapacity:e,useSecret:t}=this.config.get();if(!0===t){const e=M.getStorage(j),t=(null==e?void 0:e.secret)||function(){const e=Math.floor(1e6*Math.random());return String(e).padStart(6,"0")}();this.config.set("secret",t),g.log("Room Secret: ".concat(t))}x.connectable=!0,x.getPageSpyConfig=()=>this.config.get(),x.messageCapacity=e}init(){return e(this,void 0,void 0,(function*(){const e=L(),t=this.config.get(),n=M.getStorage(j);if(n&&"object"==typeof n){const{name:e,address:s,roomUrl:o,project:r}=n;t.project!==r?yield this.createNewConnection():(this.name=e,this.address=s,this.roomUrl=o,this.useOldConnection())}else yield this.createNewConnection();e.canIUse("onAppShow")&&e.onAppShow((()=>{const e=x.getSocket().getState();e!==P.CLOSED&&e!==P.CLOSING||this.useOldConnection()})),g.log("Plugins inited")}))}createNewConnection(){return e(this,void 0,void 0,(function*(){if(!this.request)return void g.error("Cannot get the Request");const e=yield this.request.createRoom();this.name=e.name,this.address=e.address,this.roomUrl=e.roomUrl,this.refreshRoomInfo(),x.init(e.roomUrl)}))}useOldConnection(){this.refreshRoomInfo(),x.init(this.roomUrl)}refreshRoomInfo(){this.saveSession(),this.cacheTimer=setInterval((()=>{x.getSocket().getState()===P.OPEN&&this.saveSession()}),15e3),g.log("Room ID: ".concat(this.address.slice(0,4)))}saveSession(){const{name:e,address:t,roomUrl:n,config:s}=this,{useSecret:o,secret:r,project:i}=s.get(),a={name:e,address:t,roomUrl:n,project:i,useSecret:o,secret:r};M.setStorage(j,a)}triggerPlugins(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),s=1;s<t;s++)n[s-1]=arguments[s];const{disabledPlugins:o}=this.config.get();Q.pluginsWithOrder.forEach((t=>{var s;r(o)&&o.length&&o.includes(t.name)||null===(s=t[e])||void 0===s||s.apply(t,n)}))}abort(){this.triggerPlugins("onReset"),x.close(),Q.instance=null}updateRoomInfo(e){if(!e)return;const{project:t,title:n}=e;t&&this.config.set("project",String(t)),n&&this.config.set("title",String(n)),x.updateRoomInfo()}static get pluginsWithOrder(){return[...Q.plugins.pre,...Q.plugins.normal,...Q.plugins.post]}static registerPlugin(e){if(!e)return;if("function"==typeof(t=e)&&void 0!==t.prototype)return void g.error("PageSpy.registerPlugin() expect to pass an instance, not a class");var t;if(!e.name)return void g.error("The ".concat(e.constructor.name,' plugin should provide a "name" property'));if(Q.pluginsWithOrder.some((t=>t.name===e.name)))return void g.error("The ".concat(e.name,' has registered. Consider the following reasons:\n - Duplicate register one same plugin;\n - Plugin\'s "name" conflict with others, you can print all registered plugins by "PageSpy.plugins";'));Q.plugins[e.enforce||"normal"].push(e)}}Q.instance=null,Q.plugins={pre:[],normal:[],post:[]};var X;[new H,new F,new G,new B,new V].forEach((e=>{Q.registerPlugin(e)})),X=my,D=X,M.getStorage=e=>{const t=my.getStorageSync({key:e});if(t.success)return t.data},M.setStorage=(e,t)=>my.setStorageSync({key:e,data:t}),M.removeStorage=e=>my.removeStorageSync({key:e});const Y=my.getSystemInfoSync();k.info.sdk="mp-alipay",k.info.osType=Y.platform.toLowerCase(),k.info.browserType="mp-alipay",k.info.osVersion=Y.system,k.info.browserVersion=Y.version,q.messageFilters.push((e=>e.data)),module.exports=Q;
"use strict";function e(e,t,n,s){return new(n||(n=Promise))((function(o,r){function i(e){try{c(s.next(e))}catch(e){r(e)}}function a(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,a)}c((s=s.apply(e,t||[])).next())}))}function t(){return Math.random().toString(36).slice(2)}function n(e){return Object.prototype.toString.call(e)}function s(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function o(e){return"[object BigInt]"===n(e)}function r(e){return e instanceof Array}function i(e){return"object"==typeof e&&null!==e}function a(e){return!(!i(e)||"[object Object]"!==n(e))}"function"==typeof SuppressedError&&SuppressedError;const c=e=>"".concat(e),l=e=>({ok:!0,value:e});function u(e){return void 0===e?l(c(e)):null===e?l(e):function(e){return"number"==typeof e}(e)&&(e===-1/0||e===1/0||Number.isNaN(e))?l(c(e)):o(e)?l("".concat(e,"n")):"symbol"==typeof e||"function"==typeof e?l(c(e.toString())):e instanceof Error?l(c(e.stack)):e===Object.prototype?{value:null,ok:!1}:e instanceof Object||"object"==typeof e?{value:e,ok:!1}:l(e)}function h(e){return void 0===e?"undefined":null===e?"null":o(e)?"bigint":e instanceof Object?e instanceof Error?"error":"function"==typeof e?"function":"object":typeof e}const d=Object.assign({},console),g=["log","info","error","warn","debug"].reduce(((e,t)=>(e[t]=function(){for(var e=arguments.length,n=new Array(e),s=0;s<e;s++)n[s]=arguments[s];console[t]("[PageSpy] [".concat(t.toLocaleUpperCase(),"] "),...n)},e.unproxy[t]=function(){for(var e=arguments.length,n=new Array(e),s=0;s<e;s++)n[s]=arguments[s];d[t]("[PageSpy] [".concat(t.toLocaleUpperCase(),"] "),...n)},e)),{unproxy:{}});const p="message",f="broadcast",m="ping",y="updateRoomInfo";var S,v=Object.freeze({__proto__:null,BROADCAST:f,CLOSE:"close",CONNECT:"connect",ERROR:"error",JOIN:"join",LEAVE:"leave",MESSAGE:p,PING:m,PONG:"pong",UPDATE_ROOM_INFO:y});function b(e,n){let s=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];return{role:"client",type:e,data:Object.assign(Object.assign({},s&&{id:t()}),n)}}class O{constructor(e){this.id="",this.method="",this.url="",this.requestType="xhr",this.requestHeader=null,this.status=0,this.statusText="",this.readyState=0,this.responseReason=null,this.responseType="",this.responseHeader=null,this.startTime=0,this.endTime=0,this.costTime=0,this.postData=null,this.requestPayload=null,this.withCredentials=!1,this.id=e}}!function(e){e[e.UNSENT=0]="UNSENT",e[e.OPENED=1]="OPENED",e[e.HEADERS_RECEIVED=2]="HEADERS_RECEIVED",e[e.LOADING=3]="LOADING",e[e.DONE=4]="DONE"}(S||(S={}));class I{constructor(e){this.socketStore=e,this.reqMap=Object.create(null)}getRequestMap(){return this.reqMap}getRequest(e){return this.reqMap[e]}removeRequest(e){delete this.reqMap[e]}createRequest(e){return e?this.reqMap[e]?(g.warn("The request object has been in store, disallow duplicate create"),!1):(this.reqMap[e]=new O(e),!0):(g.warn('The "id" is required when init request object'),!1)}setRequest(e,t){return!(!e||!t)&&(this.reqMap[e]=t,!0)}sendRequestItem(e,t){var n;if(!1!==(null===(n=I.dataProcessor)||void 0===n?void 0:n.call(I,t)))try{this.reqMap[e]||(this.reqMap[e]=t);const n=b("network",Object.assign({},t),!1);this.socketStore.dispatchEvent("public-data",n),this.socketStore.broadcastMessage(n,t.readyState!==S.DONE),this.deferDeleteRequest(e)}catch(e){g.error(e.message)}}deferDeleteRequest(e){const t=this.getRequest(e);t&&t.readyState===S.DONE&&setTimeout((()=>{delete this.reqMap[e]}),3e3)}}class C{constructor(){this.store={},this.instanceStore={}}getStore(){return this.store}resetStore(){this.store={}}getInstanceStore(){return this.instanceStore}resetInstanceStore(){this.instanceStore={}}transformToAtom(e){let n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const{value:s,ok:o}=u(e),r=t();if(o)return{id:r,type:h(e),value:s};if(n)try{return{id:r,type:"json",value:JSON.stringify(e)}}catch(e){return{id:r,type:"json",value:null}}return this.add(e)}get(e){const n=this.store[e],o=this.instanceStore[e];if(!n)return null;const r={},i=Object.getOwnPropertyDescriptors(n);Object.keys(i).forEach((e=>{const n=i[e];s(n,"value")&&(n.value=this.transformToAtom(n.value)),r[e]=C.getAtomOverview({atomId:t(),instanceId:o,value:n})}));const a=this.addExtraProperty(e);return Object.assign(Object.assign({},r),a)}getOrigin(e){const t=this.store[e];return t||null}add(e){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";const o=t();let r=o;var a;i(a=e)&&s(a,"constructor")&&"function"==typeof a.constructor&&(r=n),this.store[o]=e,this.instanceStore[o]=r;const c=C.getSemanticValue(e);return C.getAtomOverview({atomId:o,value:c,instanceId:r})}static getAtomOverview(e){let{instanceId:n="",atomId:s,value:o}=e;return{id:t(),type:"atom",__atomId:s,instanceId:n,value:o}}static getSemanticValue(e){if(a(e))return"Object {...}";if(r(e))return"Array (".concat(e.length,")");return e.constructor.name}addExtraProperty(e){const t=this.store[e],n=this.instanceStore[e],s={};if((t instanceof String||t instanceof Number||t instanceof Boolean)&&(s["[[PrimitiveValue]]"]=this.transformToAtom(t.valueOf())),t instanceof Set){const e={};let n=0;for(const s of t)e[n++]=s;e.size=t.size,s["[[Entries]]"]=this.transformToAtom(e)}if(t instanceof Map){const e={};let n=0;for(const[s,o]of t.entries())e[n++]={key:s,value:o};e.size=t.size,s["[[Entries]]"]=this.transformToAtom(e)}var o;return(r(t)||(o=t,"function"==typeof NodeList&&"NodeList"===NodeList.name&&o instanceof NodeList||"function"==typeof HTMLCollection&&"HTMLCollection"===HTMLCollection.name&&o instanceof HTMLCollection))&&(s.length=this.transformToAtom(t.length)),null!==Object.getPrototypeOf(t)?s["[[Prototype]]"]=this.add(Object.getPrototypeOf(t),n):s.___proto___=this.transformToAtom(null),s}}const E=new C;class k{static makeClientInfoMsg(){return{sdk:k.info.sdk,isDevTools:k.info.isDevTools,ua:k.getName(),plugins:k.plugins}}static getName(){if(!k._name){const{ua:e,osType:t,osVersion:n,browserType:s,browserVersion:o}=k.info;k._name=e||"".concat(t,"/").concat(n," ").concat(s,"/").concat(o)}return k._name}}k.info={osType:"unknown",osVersion:"unknown",browserType:"unknown",browserVersion:"unknown",framework:"unknown",isDevTools:!1,sdk:"browser"},k.plugins=[];class T{defaultConfig(){return{}}constructor(){this.mergeConfig=e=>{const t=Object.entries(e).reduce(((e,t)=>{let[n,s]=t;return this.privateKeys.includes(n)||(e[n]=s),e}),{});return this.value=Object.assign(Object.assign({},this.defaultConfig()),t),this.value},this.value=this.defaultConfig()}get(){return this.value}set(e,t){this.value[e]=t}}const j="page-spy-room";var P;!function(e){e[e.CONNECTING=0]="CONNECTING",e[e.OPEN=1]="OPEN",e[e.CLOSING=2]="CLOSING",e[e.CLOSED=3]="CLOSED"}(P||(P={}));const w=2e3,R=Math.pow(1.5,4)*w;class N{constructor(){this.events={open:[],close:[],error:[],message:[]}}emit(e,t){this.events[e].forEach((e=>{e(t)})),"close"!==e&&"error"!==e||this.clearListeners()}onOpen(e){this.events.open.push(e)}onClose(e){this.events.close.push(e)}onError(e){this.events.error.push(e)}onMessage(e){this.events.message.push(e)}clearListeners(){Object.entries(this.events).forEach((e=>{let[,t]=e;t.splice(0)}))}}class q{getSocket(){return this.socketWrapper}updateRoomInfo(){if(this.getPageSpyConfig){const{project:e,title:t}=this.getPageSpyConfig(),n=k.getName();this.send({type:y,content:{info:{name:n,group:e,tags:{title:t,name:n,group:e}}}},!0)}}constructor(){this.socketUrl="",this.socketConnection=null,this.debuggerConnection=null,this.pingTimer=null,this.pongTimer=null,this.retryTimer=null,this.isOffline=!1,this.messageCapacity=0,this.messages=[],this.events={debug:[],refresh:[],"atom-detail":[],"atom-getter":[],"debugger-online":[],"database-pagination":[],"public-data":[],"harbor-clear":[]},this.retryInterval=w,this.connectable=!0,this.getPageSpyConfig=null,this.addListener("atom-detail",q.handleResolveAtom),this.addListener("atom-getter",q.handleAtomPropertyGetter),this.addListener("debugger-online",this.handleFlushBuffer)}init(t){return e(this,void 0,void 0,(function*(){var e,n,s,o,r;try{if(!t)throw Error("WebSocket url cannot be empty");this.socketWrapper.clearListeners(),this.socketWrapper.getState()===P.OPEN&&(yield new Promise((e=>{this.socketWrapper.onClose((()=>{this.socketWrapper.clearListeners(),e()})),this.socketWrapper.close()}))),null===(e=this.socketWrapper)||void 0===e||e.onOpen((()=>{this.connectOnline()})),null===(n=this.socketWrapper)||void 0===n||n.onMessage((e=>{this.handleMessage(e)})),null===(s=this.socketWrapper)||void 0===s||s.onClose((()=>{this.connectOffline()})),null===(o=this.socketWrapper)||void 0===o||o.onError((()=>{this.connectOffline()})),this.socketUrl=t,null===(r=this.socketWrapper)||void 0===r||r.init(t)}catch(e){g.error(e.message)}}))}addListener(e,t){this.events[e]||(this.events[e]=[]),this.events[e].push(t)}removeListener(e,t){const n=this.events[e]||[],s=n.indexOf(t);s>-1&&n.splice(s,1)}broadcastMessage(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const n=function(e){return{type:f,content:{data:e}}}(e);this.send(n,t)}close(){var e;this.connectable=!1,this.clearPing(),null===(e=this.socketWrapper)||void 0===e||e.close(),this.messages=[],Object.entries(this.events).forEach((e=>{let[t,n]=e;["atom-detail","atom-getter","debugger-online"].includes(t)||n.splice(0)}))}connectOnline(){this.retryInterval=w,this.updateRoomInfo(),this.ping()}connectOffline(){this.socketConnection=null,this.debuggerConnection=null,this.clearPing(),this.retryTimer&&clearTimeout(this.retryTimer),this.connectable&&(this.retryTimer=setTimeout((()=>{this.retryInterval<R&&(this.retryInterval*=1.5),this.retryTimer=null,this.tryReconnect()}),this.retryInterval))}tryReconnect(){this.init(this.socketUrl)}ping(){this.pingTimer&&clearTimeout(this.pingTimer),this.pongTimer&&clearTimeout(this.pongTimer),this.pingTimer=setTimeout((()=>{this.send({type:"ping",content:null}),this.pingTimer=null,this.pongTimer=setTimeout((()=>{this.connectOffline(),this.pongTimer=null}),5e3)}),5e3)}clearPing(){this.pingTimer&&(clearTimeout(this.pingTimer),this.pingTimer=null),this.pongTimer&&(clearTimeout(this.pongTimer),this.pongTimer=null)}handlePong(){clearTimeout(this.pongTimer),this.pongTimer=null,this.ping()}handleMessage(e){var t;q.messageFilters.length&&q.messageFilters.forEach((t=>{e=t(e)}));const{CONNECT:n,MESSAGE:s,ERROR:o,JOIN:r,PING:i,PONG:a,LEAVE:c,CLOSE:l,BROADCAST:u}=v,h=JSON.parse(e.data),{type:d}=h;switch(d){case n:const{selfConnection:e,roomConnections:i}=h.content;this.socketConnection=e,this.debuggerConnection=i.find((e=>"Debugger"===e.userId))||null;break;case r:case c:const{connection:a}=h.content;"Debugger"===a.userId&&(d===r?(this.debuggerConnection=a,this.sendClientInfo()):this.debuggerConnection=null);break;case s:const{data:u,from:g,to:p}=h.content;p.address===(null===(t=this.socketConnection)||void 0===t?void 0:t.address)&&this.dispatchEvent(u.type,{source:u,from:g,to:p});break;case l:case o:this.connectOffline()}this.handlePong()}dispatchEvent(e,t){var n;["public-data"].includes(e)?this.events["public-data"].forEach((e=>{e(t)})):null===(n=this.events[e])||void 0===n||n.forEach((e=>{e.call(this,t,(e=>{this.unicastMessage(e,t.from)}))}))}unicastMessage(e,t){const n=function(e,t,n){return{type:p,content:{data:e,from:t,to:n}}}(e,this.socketConnection,t);this.send(n)}handleFlushBuffer(e){const{latestId:t}=e.source.data,n=this.messages.findIndex((e=>e.content.data.data.id===t));this.messages.slice(n+1).forEach((t=>{const n={type:p,content:{data:t.content.data,from:this.socketConnection,to:e.from}};this.send(n,!0)}))}static handleResolveAtom(e,t){let{source:n}=e;const{type:s,data:o}=n;if("atom-detail"===s){const e=E.get(o)||{};t(b("atom-detail-".concat(o),e,!1))}}static handleAtomPropertyGetter(e,t){let{source:n}=e;var s,o;const{type:r,data:i}=n;if("atom-getter"===r){const{id:e,parentId:n,key:r,instanceId:a}=i,c=E.getOrigin(a),l=E.getOrigin(n);let u={};u=c&&l?null===(o=null===(s=Object.getOwnPropertyDescriptor(l,r))||void 0===s?void 0:s.get)||void 0===o?void 0:o.call(c):new Error("Getter computed failed");t(b("atom-getter-".concat(e),E.transformToAtom(u)))}}send(e){let n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];var s;if(this.checkIfSend(e))try{const n=e;n.createdAt=Date.now(),n.requestId=t();const o=function(e){const{ok:t,value:n}=u(e);return t?n:JSON.stringify(e,((e,t)=>u(t).value),2)}(n);null===(s=this.socketWrapper)||void 0===s||s.send(o)}catch(e){g.error("Incompatible: ".concat(e.message)),this.connectOffline()}this.checkIfCache(e,n)&&(0!==this.messageCapacity&&this.messages.length>=this.messageCapacity&&this.messages.shift(),this.messages.push(e))}checkIfSend(e){return this.socketWrapper.getState()===P.OPEN&&(!![y,m].includes(e.type)||!!this.debuggerConnection)}checkIfCache(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return!this.isOffline&&!t&&![p,m].includes(e.type)}sendClientInfo(){const e=k.makeClientInfoMsg();this.broadcastMessage({role:"client",type:"client-info",data:e},!0)}}q.messageFilters=[];const D=e=>{const t=[];return Object.entries(e).forEach((e=>{let[n,s]=e;t.push("".concat(n,"=").concat(s))})),t.join("&")};let A;const L=()=>{if(!A)throw Error("the mp sdk is not set");return A},M={setStorage:(e,t)=>null==A?void 0:A.setStorageSync(e,t),getStorage:e=>null==A?void 0:A.getStorageSync(e),removeStorage:e=>null==A?void 0:A.getStorageSync(e)};class U extends N{constructor(){super(...arguments),this.socketInstance=null,this.state=0}init(t){return e(this,void 0,void 0,(function*(){this.state=P.CONNECTING;const e=L(),n=e=>{this.state=P.CLOSED,this.emit("close",e)},s=e=>{this.state=P.OPEN,this.emit("open",e)},o=e=>{this.state=P.CLOSED,this.emit("error",e)},r=e=>{this.emit("message",e)};if(U.isSingleSocket)e.connectSocket({url:t}),e.onSocketClose(n),e.onSocketError(o),e.onSocketMessage(r),e.onSocketOpen(s);else{let i=e.connectSocket({url:t,multiple:!0,complete(){}});i instanceof Promise&&(i=yield i),i.onClose(n),i.onError(o),i.onOpen(s),i.onMessage(r),this.socketInstance=i}}))}send(e){var t;U.isSingleSocket?L().sendSocketMessage({data:e}):null===(t=this.socketInstance)||void 0===t||t.send({data:e})}close(){var e;U.isSingleSocket?L().closeSocket({}):null===(e=this.socketInstance)||void 0===e||e.close({}),this.state=P.CLOSED}getState(){return this.state}}U.isSingleSocket=!1;var x=new class extends q{constructor(){super(...arguments),this.socketWrapper=new U}onOffline(){M.removeStorage(j)}};class H{constructor(){this.name="ConsolePlugin",this.console={},this.proxyTypes=["log","info","error","warn","debug"],this.$pageSpyConfig=null}onInit(t){return e(this,arguments,void 0,(function(e){var t=this;let{config:n}=e;return function*(){H.hasInitd||(H.hasInitd=!0,t.$pageSpyConfig=n,t.init())}()}))}init(){const e=this;this.proxyTypes.forEach((t=>{this.console[t]=console[t]||console.log||(()=>{}),Object.defineProperty(console,t,{value(){const n=getCurrentPages().pop();let s="/";n&&(s=n.route,n.options&&Object.keys(n.options).length>0&&(s+="?"+D(n.options)));for(var o=arguments.length,r=new Array(o),i=0;i<o;i++)r[i]=arguments[i];e.printLog({logType:t,logs:r,url:s})},configurable:!0,enumerable:!0,writable:!0})}))}reset(){this.proxyTypes.forEach((e=>{const t=this.console[e];t&&(console[e]=t)}))}onReset(){this.reset(),H.hasInitd=!1}printLog(e){var t,n,s;if(e.logs&&e.logs.length){const o=null===(n=null===(t=this.$pageSpyConfig)||void 0===t?void 0:t.dataProcessor)||void 0===n?void 0:n.console;if(o){this.reset();const t=o(e);if(this.init(),!1===t)return}this.console[e.logType](...e.logs);const r=b("console",Object.assign(Object.assign({},e),{time:Date.now(),logs:e.logs.map((e=>E.transformToAtom(e,!1)))}));if(x.broadcastMessage(r),null===(s=this.$pageSpyConfig)||void 0===s?void 0:s.serializeData){const t=Object.assign(Object.assign({},r),{data:Object.assign(Object.assign({},r.data),{logs:e.logs.map((e=>E.transformToAtom(e,!0)))})});x.dispatchEvent("public-data",t)}else x.dispatchEvent("public-data",r)}}}H.hasInitd=!1;class F{constructor(){this.name="ErrorPlugin",this.$pageSpyConfig=null,this.errorHandler=this.errorHandler.bind(this),this.unhandledRejectionHandler=this.unhandledRejectionHandler.bind(this)}onInit(e){let{config:t}=e;F.hasInitd||(F.hasInitd=!0,this.$pageSpyConfig=t,this.onUncaughtError(),this.onUnhandledRejectionError())}onReset(){const e=L();e.canIUse("offError")&&e.offError(this.errorHandler),e.canIUse("offUnhandledRejection")&&e.offUnhandledRejection(this.unhandledRejectionHandler),F.hasInitd=!1}errorHandler(e){if(F.hasInitd)if(e.stack||e.message){const{message:t,stack:n}=e;this.sendMessage(n||t,(e=>{if("object"!=typeof e)return null;const{name:t,message:n,stack:s}=Object(e);return!1===[t,n,s].every(Boolean)?null:{name:t,message:n,stack:s}})(e))}else{const e="[PageSpy] An unknown error occurred and no message or stack trace available";this.sendMessage(e,null)}}unhandledRejectionHandler(e){F.hasInitd&&this.sendMessage("UnHandled Rejection",{name:"unhandledrejection",message:e.reason})}onUncaughtError(){const e=L();e.canIUse("onError")&&e.onError(this.errorHandler)}onUnhandledRejectionError(){const e=L();e.canIUse("onUnhandledRejection")&&e.onUnhandledRejection(this.unhandledRejectionHandler)}sendMessage(e,t){var n,s,o;const r={logType:"error",logs:[e],time:Date.now(),url:"wx:light-app",errorDetail:t};if(!1===(null===(o=null===(s=null===(n=this.$pageSpyConfig)||void 0===n?void 0:n.dataProcessor)||void 0===s?void 0:s.console)||void 0===o?void 0:o.call(s,r)))return;r.logs=r.logs.map((e=>E.transformToAtom(e)));const i=b("console",r);x.dispatchEvent("public-data",i),x.broadcastMessage(i)}}F.hasInitd=!1;class W extends I{constructor(){super(x)}}class _ extends W{constructor(){super(),this.request=null,this.initProxyHandler()}reset(){if(this.request){const e=L();Object.defineProperty(e,"request",{value:this.request})}}initProxyHandler(){const e=this,s=L(),o=s.request;o&&(this.request=o,Object.defineProperty(s,"request",{value(s){const r=t();e.createRequest(r);const i=e.getRequest(r);if(i){const t=s.method||"GET",{url:c}=s;i.requestHeader=[],i.url=c,i.method=t.toUpperCase(),i.requestType="mp-request",i.status=0,i.statusText="Pending",i.startTime=Date.now(),i.readyState=S.UNSENT,a(s.header)&&(i.requestHeader=Object.entries(s.header).map((e=>{let[t,n]=e;return[String(t),String(n)]}))),i.requestHeader.push(["Content-Type","application/json"]);const{data:l}=s;if(l)if("string"==typeof l)i.requestPayload=l;else if(l instanceof ArrayBuffer)i.requestPayload="[object ArrayBuffer]";else try{i.requestPayload=JSON.stringify(l)}catch(e){i.requestPayload=n(l)}e.sendRequestItem(r,i);const u=s.success,h=s.fail,d=s.complete,g=()=>{i.endTime=Date.now(),i.costTime=i.endTime-(i.startTime||i.endTime)};s.success=function(t){g(),i.status=(null==t?void 0:t.statusCode)||200,i.statusText="Done",i.responseHeader=[...Object.entries((null==t?void 0:t.header)||{})],i.readyState=S.HEADERS_RECEIVED,e.sendRequestItem(r,i);const n=function(e){const t=Object.keys(e),n={};for(let s=0;s<t.length;s++){const o=t[s];n[o.toLowerCase()]=e[o]}return n}((null==t?void 0:t.header)||{})["content-type"];switch(n&&(n.includes("application/json")&&(i.responseType="json"),(n.includes("text/html")||n.includes("text/plain"))&&(i.responseType="text")),i.responseType||(i.responseType="arraybuffer"),i.responseType){case"json":case"text":if("string"==typeof(null==t?void 0:t.data))try{i.response=JSON.parse(t.data)}catch(e){i.response=t.data,i.responseType="text"}else i.response=null==t?void 0:t.data;break;case"arraybuffer":i.response="[object ArrayBuffer]"}null==u||u(t)},s.fail=function(e){g(),null==h||h(e)},s.complete=function(t){i.readyState=S.DONE,e.sendRequestItem(r,i),null==d||d(t)};return o(s)}return g.warn("The request object is not found on request event"),null}}))}}class G{constructor(){this.name="NetworkPlugin",this.requestProxy=null}onInit(e){let{config:t}=e;G.hasInitd||(G.hasInitd=!0,I.dataProcessor=t.dataProcessor.network,this.requestProxy=new _)}onReset(){var e;null===(e=this.requestProxy)||void 0===e||e.reset(),G.hasInitd=!1}}G.hasInitd=!1;class V{constructor(){this.name="SystemPlugin",this.$pageSpyConfig=null}onInit(e){let{config:t}=e;V.hasInitd||(V.hasInitd=!0,this.$pageSpyConfig=t,this.onceInitPublicData(),x.addListener("refresh",((e,t)=>{let{source:n}=e;const{data:s}=n;if("system"===s){const e=this.getSystemInfo();if(null===e)return;t(e)}})))}onceInitPublicData(){const e=this.getSystemInfo();null!==e&&x.dispatchEvent("public-data",e)}onReset(){V.hasInitd=!1}getSystemInfo(){var e,t,n;const s={system:{ua:k.getName()},features:{}};return!1===(null===(n=null===(t=null===(e=this.$pageSpyConfig)||void 0===e?void 0:e.dataProcessor)||void 0===t?void 0:t.system)||void 0===n?void 0:n.call(t,s))?null:b("system",s)}}function $(e){const t=typeof e;let n=e;return"string"===t||"boolean"===t||"number"===t?n=String(e):"object"===t&&(n=e instanceof Date?e.toDateString():JSON.stringify(e)),n}V.hasInitd=!1;class B{constructor(){this.name="StoragePlugin",this.$pageSpyConfig=null}onInit(e){let{config:t}=e;B.hasInitd||(B.hasInitd=!0,this.$pageSpyConfig=t,this.initStorageProxy(),this.listenRefreshEvent())}onReset(){const e=L();Object.entries(B.originFunctions).forEach((t=>{let[n,s]=t;Object.defineProperty(e,n,{value:s})})),B.hasInitd=!1}sendRefresh(){const e=L();try{const t=e.getStorageInfoSync(),n={type:"mpStorage",action:"get",data:t.keys.map((e=>({name:e,value:$(M.getStorage(e))})))};this.sendStorageItem(n)}catch(e){}}listenRefreshEvent(){x.addListener("refresh",(t=>e(this,[t],void 0,(function(e){var t=this;let{source:n}=e;return function*(){const{data:e}=n;"mpStorage"===e&&t.sendRefresh()}()}))))}initStorageProxy(){const e=L();["setStorage","setStorageSync","removeStorage","removeStorageSync","clearStorage","clearStorageSync","batchSetStorageSync","batchSetStorage"].forEach((t=>{e[t]&&(B.originFunctions[t]=e[t])}));const t=this;Object.defineProperties(e,{setStorage:{value:e=>B.originFunctions.setStorage(Object.assign(Object.assign({},e),{success(n){var s;t.sendSetItem(e.key,e.data),null===(s=e.success)||void 0===s||s.call(e,n)}}))},setStorageSync:{value(e,n){try{let s;if("mp-alipay"!==k.info.browserType||k.info.framework&&"unknown"!==k.info.framework){const o=e;s=B.originFunctions.setStorageSync(o,n),t.sendSetItem(o,n)}else{const n=e;s=B.originFunctions.setStorageSync(n),t.sendSetItem(n.key,n.data)}return s}catch(t){throw g.error("Failed to set storage synchronously: ".concat(e)),t}}},removeStorage:{value:e=>B.originFunctions.removeStorage(Object.assign(Object.assign({},e),{success(n){var s;t.sendRemoveItem(e.key),null===(s=e.success)||void 0===s||s.call(e,n)}}))},removeStorageSync:{value(e){try{const n=B.originFunctions.removeStorageSync(e);return t.sendRemoveItem(n),n}catch(t){throw g.error("Failed to remove storage synchronously: ".concat(e)),t}}},clearStorage:{value:e=>B.originFunctions.clearStorage(Object.assign(Object.assign({},e),{success(n){var s;t.sendClearItem(),null===(s=e.success)||void 0===s||s.call(e,n)}}))},clearStorageSync:{value(){try{const e=B.originFunctions.clearStorageSync();return t.sendClearItem(),e}catch(e){throw g.error("Failed to clear storage synchronously"),e}}}}),e.canIUse("batchSetStorageSync")&&Object.defineProperty(e,"batchSetStorageSync",{value(e){try{const n=B.originFunctions.batchSetStorageSync(e);return e.forEach((e=>{t.sendSetItem(e.key,e.value)})),n}catch(t){throw g.error("Failed to batch set storage synchronously: ".concat(JSON.stringify(e.map((e=>e.key))))),t}}}),e.canIUse("batchSetStorage")&&Object.defineProperty(e,"batchSetStorage",{value:e=>B.originFunctions.batchSetStorage(Object.assign(Object.assign({},e),{success(n){var s;e.kvList.forEach((e=>{t.sendSetItem(e.key,e.value)})),null===(s=e.success)||void 0===s||s.call(e,n)}}))})}sendSetItem(e,t){this.sendStorageItem({type:"mpStorage",action:"set",name:e,value:$(t)})}sendRemoveItem(e){this.sendStorageItem({type:"mpStorage",action:"remove",name:e})}sendClearItem(){this.sendStorageItem({type:"mpStorage",action:"clear"})}sendStorageItem(e){var t,n,s;if(!1===(null===(s=null===(n=null===(t=this.$pageSpyConfig)||void 0===t?void 0:t.dataProcessor)||void 0===n?void 0:n.storage)||void 0===s?void 0:s.call(n,e)))return;const o=b("storage",e);x.dispatchEvent("public-data",o),x.broadcastMessage(o,!0)}}B.hasInitd=!1,B.originFunctions={};const J=e=>!1===e?["http://","ws://"]:["https://","wss://"];class z{constructor(e){if(this.config=e,!e.get().api)throw Error("The api base url cannot be empty")}get base(){return this.config.get().api}createRoom(){const{enableSSL:e,project:t,title:n,useSecret:s,secret:o}=this.config.get(),r=J(e),i=k.getName(),a=D({group:t,title:n,name:encodeURIComponent(i)});return(c=L().request,e=>new Promise(((t,n)=>{c(Object.assign(Object.assign({},e),{success(e){t(e)},fail(e){n(e)}}))})))({url:"".concat(r[0]).concat(this.base,"/api/v1/room/create?").concat(a),method:"POST",data:JSON.stringify({useSecret:s,secret:o})}).then((e=>{var t;const{name:n,address:s}=(null===(t=e.data)||void 0===t?void 0:t.data)||{};return{roomUrl:this.getRoomUrl(s),address:s,name:n}}),(e=>{throw Error("Request create room failed: ".concat(e.message))}));var c}getRoomUrl(e){const n=this.config.get(),s=J(n.enableSSL);return"".concat(s[1]).concat(this.base,"/api/v1/ws/room/join?").concat(D({address:e,name:"client:".concat(t()),userId:"Client",forceCreate:!0,useSecret:n.useSecret,secret:n.secret}))}}class K extends T{constructor(){super(...arguments),this.privateKeys=["secret"]}defaultConfig(){return{api:"",project:"default",title:"",enableSSL:null,disabledOnProd:!0,disabledPlugins:[],singletonSocket:!1,messageCapacity:1e3,useSecret:!1,secret:"",serializeData:!1,dataProcessor:{}}}}class Q{constructor(e){if(this.root=null,this.version="1.9.8",this.request=null,this.name="",this.address="",this.roomUrl="",this.socketStore=x,this.config=new K,this.cacheTimer=null,Q.instance)return g.warn("Cannot initialize PageSpy multiple times"),Q.instance;const t=this.config.mergeConfig(e);t.singletonSocket&&(U.isSingleSocket=!0);const n=L();if(n.canIUse("getAccountInfoSync")&&n.getAccountInfoSync){if("release"===n.getAccountInfoSync().miniProgram.envVersion&&!1!==t.disabledOnProd)return void g.warn("PageSpy is not allowed on release env of mini program")}Q.instance=this,this.request=new z(this.config),this.updateConfiguration(),this.triggerPlugins("onInit",{socketStore:x,config:t,atom:E}),k.plugins=Q.pluginsWithOrder.map((e=>e.name)),this.init()}updateConfiguration(){const{messageCapacity:e,useSecret:t}=this.config.get();if(!0===t){const e=M.getStorage(j),t=(null==e?void 0:e.secret)||function(){const e=Math.floor(1e6*Math.random());return String(e).padStart(6,"0")}();this.config.set("secret",t),g.log("Room Secret: ".concat(t))}x.connectable=!0,x.getPageSpyConfig=()=>this.config.get(),x.messageCapacity=e}init(){return e(this,void 0,void 0,(function*(){const e=L(),t=this.config.get(),n=M.getStorage(j);if(n&&"object"==typeof n){const{name:e,address:s,roomUrl:o,project:r}=n;t.project!==r?yield this.createNewConnection():(this.name=e,this.address=s,this.roomUrl=o,this.useOldConnection())}else yield this.createNewConnection();e.canIUse("onAppShow")&&e.onAppShow((()=>{const e=x.getSocket().getState();e!==P.CLOSED&&e!==P.CLOSING||this.useOldConnection()})),g.log("Plugins inited")}))}createNewConnection(){return e(this,void 0,void 0,(function*(){if(!this.request)return void g.error("Cannot get the Request");const e=yield this.request.createRoom();this.name=e.name,this.address=e.address,this.roomUrl=e.roomUrl,this.refreshRoomInfo(),x.init(e.roomUrl)}))}useOldConnection(){this.refreshRoomInfo(),x.init(this.roomUrl)}refreshRoomInfo(){this.saveSession(),this.cacheTimer=setInterval((()=>{x.getSocket().getState()===P.OPEN&&this.saveSession()}),15e3),g.log("Room ID: ".concat(this.address.slice(0,4)))}saveSession(){const{name:e,address:t,roomUrl:n,config:s}=this,{useSecret:o,secret:r,project:i}=s.get(),a={name:e,address:t,roomUrl:n,project:i,useSecret:o,secret:r};M.setStorage(j,a)}triggerPlugins(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),s=1;s<t;s++)n[s-1]=arguments[s];const{disabledPlugins:o}=this.config.get();Q.pluginsWithOrder.forEach((t=>{var s;r(o)&&o.length&&o.includes(t.name)||null===(s=t[e])||void 0===s||s.apply(t,n)}))}abort(){this.triggerPlugins("onReset"),x.close(),Q.instance=null}updateRoomInfo(e){if(!e)return;const{project:t,title:n}=e;t&&this.config.set("project",String(t)),n&&this.config.set("title",String(n)),x.updateRoomInfo()}static get pluginsWithOrder(){return[...Q.plugins.pre,...Q.plugins.normal,...Q.plugins.post]}static registerPlugin(e){if(!e)return;if("function"==typeof(t=e)&&void 0!==t.prototype)return void g.error("PageSpy.registerPlugin() expect to pass an instance, not a class");var t;if(!e.name)return void g.error("The ".concat(e.constructor.name,' plugin should provide a "name" property'));if(Q.pluginsWithOrder.some((t=>t.name===e.name)))return void g.error("The ".concat(e.name,' has registered. Consider the following reasons:\n - Duplicate register one same plugin;\n - Plugin\'s "name" conflict with others, you can print all registered plugins by "PageSpy.plugins";'));Q.plugins[e.enforce||"normal"].push(e)}}Q.instance=null,Q.plugins={pre:[],normal:[],post:[]};var X;[new H,new F,new G,new B,new V].forEach((e=>{Q.registerPlugin(e)})),X=my,A=X,M.getStorage=e=>{const t=my.getStorageSync({key:e});if(t.success)return t.data},M.setStorage=(e,t)=>my.setStorageSync({key:e,data:t}),M.removeStorage=e=>my.removeStorageSync({key:e});const Y=my.getSystemInfoSync();k.info.sdk="mp-alipay",k.info.osType=Y.platform.toLowerCase(),k.info.browserType="mp-alipay",k.info.osVersion=Y.system,k.info.browserVersion=Y.version,q.messageFilters.push((e=>e.data)),module.exports=Q;
//# sourceMappingURL=index.min.js.map

@@ -1,2 +0,2 @@

function e(e,t,n,s){return new(n||(n=Promise))((function(o,r){function i(e){try{c(s.next(e))}catch(e){r(e)}}function a(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,a)}c((s=s.apply(e,t||[])).next())}))}function t(){return Math.random().toString(36).slice(2)}function n(e){return Object.prototype.toString.call(e)}function s(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function o(e){return"[object BigInt]"===n(e)}function r(e){return e instanceof Array}function i(e){return"object"==typeof e&&null!==e}function a(e){return!(!i(e)||"[object Object]"!==n(e))}"function"==typeof SuppressedError&&SuppressedError;const c=e=>"".concat(e),l=e=>({ok:!0,value:e});function u(e){return void 0===e?l(c(e)):null===e?l(e):function(e){return"number"==typeof e}(e)&&(e===-1/0||e===1/0||Number.isNaN(e))?l(c(e)):o(e)?l("".concat(e,"n")):"symbol"==typeof e||"function"==typeof e?l(c(e.toString())):e instanceof Error?l(c(e.stack)):e===Object.prototype?{value:null,ok:!1}:e instanceof Object||"object"==typeof e?{value:e,ok:!1}:l(e)}function h(e){return void 0===e?"undefined":null===e?"null":o(e)?"bigint":e instanceof Object?e instanceof Error?"error":"function"==typeof e?"function":"object":typeof e}const d=Object.assign({},console),g=["log","info","error","warn","debug"].reduce(((e,t)=>(e[t]=function(){for(var e=arguments.length,n=new Array(e),s=0;s<e;s++)n[s]=arguments[s];console[t]("[PageSpy] [".concat(t.toLocaleUpperCase(),"] "),...n)},e.unproxy[t]=function(){for(var e=arguments.length,n=new Array(e),s=0;s<e;s++)n[s]=arguments[s];d[t]("[PageSpy] [".concat(t.toLocaleUpperCase(),"] "),...n)},e)),{unproxy:{}});const p="message",f="broadcast",m="ping",y="updateRoomInfo";var S,v=Object.freeze({__proto__:null,BROADCAST:f,CLOSE:"close",CONNECT:"connect",ERROR:"error",JOIN:"join",LEAVE:"leave",MESSAGE:p,PING:m,PONG:"pong",UPDATE_ROOM_INFO:y});function b(e,n){let s=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];return{role:"client",type:e,data:Object.assign(Object.assign({},s&&{id:t()}),n)}}class O{constructor(e){this.id="",this.method="",this.url="",this.requestType="xhr",this.requestHeader=null,this.status=0,this.statusText="",this.readyState=0,this.responseReason=null,this.responseType="",this.responseHeader=null,this.startTime=0,this.endTime=0,this.costTime=0,this.postData=null,this.requestPayload=null,this.withCredentials=!1,this.id=e}}!function(e){e[e.UNSENT=0]="UNSENT",e[e.OPENED=1]="OPENED",e[e.HEADERS_RECEIVED=2]="HEADERS_RECEIVED",e[e.LOADING=3]="LOADING",e[e.DONE=4]="DONE"}(S||(S={}));class I{constructor(e){this.socketStore=e,this.reqMap=Object.create(null)}getRequestMap(){return this.reqMap}getRequest(e){return this.reqMap[e]}removeRequest(e){delete this.reqMap[e]}createRequest(e){return e?this.reqMap[e]?(g.warn("The request object has been in store, disallow duplicate create"),!1):(this.reqMap[e]=new O(e),!0):(g.warn('The "id" is required when init request object'),!1)}setRequest(e,t){return!(!e||!t)&&(this.reqMap[e]=t,!0)}sendRequestItem(e,t){var n;if(!1!==(null===(n=I.dataProcessor)||void 0===n?void 0:n.call(I,t)))try{this.reqMap[e]||(this.reqMap[e]=t);const n=b("network",Object.assign({},t),!1);this.socketStore.dispatchEvent("public-data",n),this.socketStore.broadcastMessage(n,t.readyState!==S.DONE),this.deferDeleteRequest(e)}catch(e){g.error(e.message)}}deferDeleteRequest(e){const t=this.getRequest(e);t&&t.readyState===S.DONE&&setTimeout((()=>{delete this.reqMap[e]}),3e3)}}class C{constructor(){this.store={},this.instanceStore={}}getStore(){return this.store}resetStore(){this.store={}}getInstanceStore(){return this.instanceStore}resetInstanceStore(){this.instanceStore={}}transformToAtom(e){let n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const{value:s,ok:o}=u(e),r=t();if(o)return{id:r,type:h(e),value:s};if(n)try{return{id:r,type:"json",value:JSON.stringify(e)}}catch(e){return{id:r,type:"json",value:null}}return this.add(e)}get(e){const n=this.store[e],o=this.instanceStore[e];if(!n)return null;const r={},i=Object.getOwnPropertyDescriptors(n);Object.keys(i).forEach((e=>{const n=i[e];s(n,"value")&&(n.value=this.transformToAtom(n.value)),r[e]=C.getAtomOverview({atomId:t(),instanceId:o,value:n})}));const a=this.addExtraProperty(e);return Object.assign(Object.assign({},r),a)}getOrigin(e){const t=this.store[e];return t||null}add(e){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";const o=t();let r=o;var a;i(a=e)&&s(a,"constructor")&&"function"==typeof a.constructor&&(r=n),this.store[o]=e,this.instanceStore[o]=r;const c=C.getSemanticValue(e);return C.getAtomOverview({atomId:o,value:c,instanceId:r})}static getAtomOverview(e){let{instanceId:n="",atomId:s,value:o}=e;return{id:t(),type:"atom",__atomId:s,instanceId:n,value:o}}static getSemanticValue(e){if(a(e))return"Object {...}";if(r(e))return"Array (".concat(e.length,")");return e.constructor.name}addExtraProperty(e){const t=this.store[e],n=this.instanceStore[e],s={};if((t instanceof String||t instanceof Number||t instanceof Boolean)&&(s["[[PrimitiveValue]]"]=this.transformToAtom(t.valueOf())),t instanceof Set){const e={};let n=0;for(const s of t)e[n++]=s;e.size=t.size,s["[[Entries]]"]=this.transformToAtom(e)}if(t instanceof Map){const e={};let n=0;for(const[s,o]of t.entries())e[n++]={key:s,value:o};e.size=t.size,s["[[Entries]]"]=this.transformToAtom(e)}var o;return(r(t)||(o=t,"function"==typeof NodeList&&"NodeList"===NodeList.name&&o instanceof NodeList||"function"==typeof HTMLCollection&&"HTMLCollection"===HTMLCollection.name&&o instanceof HTMLCollection))&&(s.length=this.transformToAtom(t.length)),null!==Object.getPrototypeOf(t)?s["[[Prototype]]"]=this.add(Object.getPrototypeOf(t),n):s.___proto___=this.transformToAtom(null),s}}const E=new C;class k{static makeClientInfoMsg(){return{sdk:k.info.sdk,isDevTools:k.info.isDevTools,ua:k.getName(),plugins:k.plugins}}static getName(){if(!k._name){const{ua:e,osType:t,osVersion:n,browserType:s,browserVersion:o}=k.info;k._name=e||"".concat(t,"/").concat(n," ").concat(s,"/").concat(o)}return k._name}}k.info={osType:"unknown",osVersion:"unknown",browserType:"unknown",browserVersion:"unknown",framework:"unknown",isDevTools:!1,sdk:"browser"},k.plugins=[];class T{defaultConfig(){return{}}constructor(){this.mergeConfig=e=>{const t=Object.entries(e).reduce(((e,t)=>{let[n,s]=t;return this.privateKeys.includes(n)||(e[n]=s),e}),{});return this.value=Object.assign(Object.assign({},this.defaultConfig()),t),this.value},this.value=this.defaultConfig()}get(){return this.value}set(e,t){this.value[e]=t}}const j="page-spy-room";var P;!function(e){e[e.CONNECTING=0]="CONNECTING",e[e.OPEN=1]="OPEN",e[e.CLOSING=2]="CLOSING",e[e.CLOSED=3]="CLOSED"}(P||(P={}));const w=2e3,R=Math.pow(1.5,4)*w;class N{constructor(){this.events={open:[],close:[],error:[],message:[]}}emit(e,t){this.events[e].forEach((e=>{e(t)})),"close"!==e&&"error"!==e||this.clearListeners()}onOpen(e){this.events.open.push(e)}onClose(e){this.events.close.push(e)}onError(e){this.events.error.push(e)}onMessage(e){this.events.message.push(e)}clearListeners(){Object.entries(this.events).forEach((e=>{let[,t]=e;t.splice(0)}))}}class q{getSocket(){return this.socketWrapper}updateRoomInfo(){if(this.getPageSpyConfig){const{project:e,title:t}=this.getPageSpyConfig(),n=k.getName();this.send({type:y,content:{info:{name:n,group:e,tags:{title:t,name:n,group:e}}}},!0)}}constructor(){this.socketUrl="",this.socketConnection=null,this.debuggerConnection=null,this.pingTimer=null,this.pongTimer=null,this.retryTimer=null,this.isOffline=!1,this.messageCapacity=0,this.messages=[],this.events={debug:[],refresh:[],"atom-detail":[],"atom-getter":[],"debugger-online":[],"database-pagination":[],"public-data":[],"harbor-clear":[]},this.retryInterval=w,this.connectable=!0,this.getPageSpyConfig=null,this.addListener("atom-detail",q.handleResolveAtom),this.addListener("atom-getter",q.handleAtomPropertyGetter),this.addListener("debugger-online",this.handleFlushBuffer)}init(t){return e(this,void 0,void 0,(function*(){var e,n,s,o,r;try{if(!t)throw Error("WebSocket url cannot be empty");this.socketWrapper.clearListeners(),this.socketWrapper.getState()===P.OPEN&&(yield new Promise((e=>{this.socketWrapper.onClose((()=>{this.socketWrapper.clearListeners(),e()})),this.socketWrapper.close()}))),null===(e=this.socketWrapper)||void 0===e||e.onOpen((()=>{this.connectOnline()})),null===(n=this.socketWrapper)||void 0===n||n.onMessage((e=>{this.handleMessage(e)})),null===(s=this.socketWrapper)||void 0===s||s.onClose((()=>{this.connectOffline()})),null===(o=this.socketWrapper)||void 0===o||o.onError((()=>{this.connectOffline()})),this.socketUrl=t,null===(r=this.socketWrapper)||void 0===r||r.init(t)}catch(e){g.error(e.message)}}))}addListener(e,t){this.events[e]||(this.events[e]=[]),this.events[e].push(t)}removeListener(e,t){const n=this.events[e]||[],s=n.indexOf(t);s>-1&&n.splice(s,1)}broadcastMessage(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const n=function(e){return{type:f,content:{data:e}}}(e);this.send(n,t)}close(){var e;this.connectable=!1,this.clearPing(),null===(e=this.socketWrapper)||void 0===e||e.close(),this.messages=[],Object.entries(this.events).forEach((e=>{let[t,n]=e;["atom-detail","atom-getter","debugger-online"].includes(t)||n.splice(0)}))}connectOnline(){this.retryInterval=w,this.updateRoomInfo(),this.ping()}connectOffline(){this.socketConnection=null,this.debuggerConnection=null,this.clearPing(),this.retryTimer&&clearTimeout(this.retryTimer),this.connectable&&(this.retryTimer=setTimeout((()=>{this.retryInterval<R&&(this.retryInterval*=1.5),this.retryTimer=null,this.tryReconnect()}),this.retryInterval))}tryReconnect(){this.init(this.socketUrl)}ping(){this.pingTimer&&clearTimeout(this.pingTimer),this.pongTimer&&clearTimeout(this.pongTimer),this.pingTimer=setTimeout((()=>{this.send({type:"ping",content:null}),this.pingTimer=null,this.pongTimer=setTimeout((()=>{this.connectOffline(),this.pongTimer=null}),5e3)}),5e3)}clearPing(){this.pingTimer&&(clearTimeout(this.pingTimer),this.pingTimer=null),this.pongTimer&&(clearTimeout(this.pongTimer),this.pongTimer=null)}handlePong(){clearTimeout(this.pongTimer),this.pongTimer=null,this.ping()}handleMessage(e){var t;q.messageFilters.length&&q.messageFilters.forEach((t=>{e=t(e)}));const{CONNECT:n,MESSAGE:s,ERROR:o,JOIN:r,PING:i,PONG:a,LEAVE:c,CLOSE:l,BROADCAST:u}=v,h=JSON.parse(e.data),{type:d}=h;switch(d){case n:const{selfConnection:e,roomConnections:i}=h.content;this.socketConnection=e,this.debuggerConnection=i.find((e=>"Debugger"===e.userId))||null;break;case r:case c:const{connection:a}=h.content;"Debugger"===a.userId&&(d===r?(this.debuggerConnection=a,this.sendClientInfo()):this.debuggerConnection=null);break;case s:const{data:u,from:g,to:p}=h.content;p.address===(null===(t=this.socketConnection)||void 0===t?void 0:t.address)&&this.dispatchEvent(u.type,{source:u,from:g,to:p});break;case l:case o:this.connectOffline()}this.handlePong()}dispatchEvent(e,t){var n;["public-data"].includes(e)?this.events["public-data"].forEach((e=>{e(t)})):null===(n=this.events[e])||void 0===n||n.forEach((e=>{e.call(this,t,(e=>{this.unicastMessage(e,t.from)}))}))}unicastMessage(e,t){const n=function(e,t,n){return{type:p,content:{data:e,from:t,to:n}}}(e,this.socketConnection,t);this.send(n)}handleFlushBuffer(e){const{latestId:t}=e.source.data,n=this.messages.findIndex((e=>e.content.data.data.id===t));this.messages.slice(n+1).forEach((t=>{const n={type:p,content:{data:t.content.data,from:this.socketConnection,to:e.from}};this.send(n,!0)}))}static handleResolveAtom(e,t){let{source:n}=e;const{type:s,data:o}=n;if("atom-detail"===s){const e=E.get(o)||{};t(b("atom-detail-".concat(o),e,!1))}}static handleAtomPropertyGetter(e,t){let{source:n}=e;var s,o;const{type:r,data:i}=n;if("atom-getter"===r){const{id:e,parentId:n,key:r,instanceId:a}=i,c=E.getOrigin(a),l=E.getOrigin(n);let u={};u=c&&l?null===(o=null===(s=Object.getOwnPropertyDescriptor(l,r))||void 0===s?void 0:s.get)||void 0===o?void 0:o.call(c):new Error("Getter computed failed");t(b("atom-getter-".concat(e),E.transformToAtom(u)))}}send(e){let n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];var s;if(this.checkIfSend(e))try{const n=e;n.createdAt=Date.now(),n.requestId=t();const o=function(e){const{ok:t,value:n}=u(e);return t?n:JSON.stringify(e,((e,t)=>u(t).value),2)}(n);null===(s=this.socketWrapper)||void 0===s||s.send(o)}catch(e){g.error("Incompatible: ".concat(e.message)),this.connectOffline()}this.checkIfCache(e,n)&&(0!==this.messageCapacity&&this.messages.length>=this.messageCapacity&&this.messages.shift(),this.messages.push(e))}checkIfSend(e){return this.socketWrapper.getState()===P.OPEN&&(!![y,m].includes(e.type)||!!this.debuggerConnection)}checkIfCache(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return!this.isOffline&&!t&&![p,m].includes(e.type)}sendClientInfo(){const e=k.makeClientInfoMsg();this.broadcastMessage({role:"client",type:"client-info",data:e},!0)}}q.messageFilters=[];const A=e=>{const t=[];return Object.entries(e).forEach((e=>{let[n,s]=e;t.push("".concat(n,"=").concat(s))})),t.join("&")};let D;const L=()=>{if(!D)throw Error("the mp sdk is not set");return D},M={setStorage:(e,t)=>null==D?void 0:D.setStorageSync(e,t),getStorage:e=>null==D?void 0:D.getStorageSync(e),removeStorage:e=>null==D?void 0:D.getStorageSync(e)};class U extends N{constructor(){super(...arguments),this.socketInstance=null,this.state=0}init(t){return e(this,void 0,void 0,(function*(){this.state=P.CONNECTING;const e=L(),n=e=>{this.state=P.CLOSED,this.emit("close",e)},s=e=>{this.state=P.OPEN,this.emit("open",e)},o=e=>{this.state=P.CLOSED,this.emit("error",e)},r=e=>{this.emit("message",e)};if(U.isSingleSocket)e.connectSocket({url:t}),e.onSocketClose(n),e.onSocketError(o),e.onSocketMessage(r),e.onSocketOpen(s);else{let i=e.connectSocket({url:t,multiple:!0,complete(){}});i instanceof Promise&&(i=yield i),i.onClose(n),i.onError(o),i.onOpen(s),i.onMessage(r),this.socketInstance=i}}))}send(e){var t;U.isSingleSocket?L().sendSocketMessage({data:e}):null===(t=this.socketInstance)||void 0===t||t.send({data:e})}close(){var e;U.isSingleSocket?L().closeSocket({}):null===(e=this.socketInstance)||void 0===e||e.close({}),this.state=P.CLOSED}getState(){return this.state}}U.isSingleSocket=!1;var x=new class extends q{constructor(){super(...arguments),this.socketWrapper=new U}onOffline(){M.removeStorage(j)}};class H{constructor(){this.name="ConsolePlugin",this.console={},this.proxyTypes=["log","info","error","warn","debug"],this.$pageSpyConfig=null}onInit(t){return e(this,arguments,void 0,(function(e){var t=this;let{config:n}=e;return function*(){H.hasInitd||(H.hasInitd=!0,t.$pageSpyConfig=n,t.init())}()}))}init(){const e=this;this.proxyTypes.forEach((t=>{this.console[t]=console[t]||console.log||(()=>{}),Object.defineProperty(console,t,{value(){const n=getCurrentPages().pop();let s="/";n&&(s=n.route,n.options&&Object.keys(n.options).length>0&&(s+="?"+A(n.options)));for(var o=arguments.length,r=new Array(o),i=0;i<o;i++)r[i]=arguments[i];e.printLog({logType:t,logs:r,url:s})},configurable:!0,enumerable:!0,writable:!0})}))}reset(){this.proxyTypes.forEach((e=>{const t=this.console[e];t&&(console[e]=t)}))}onReset(){this.reset(),H.hasInitd=!1}printLog(e){var t,n,s;if(e.logs&&e.logs.length){const o=null===(n=null===(t=this.$pageSpyConfig)||void 0===t?void 0:t.dataProcessor)||void 0===n?void 0:n.console;if(o){this.reset();const t=o(e);if(this.init(),!1===t)return}this.console[e.logType](...e.logs);const r=b("console",Object.assign(Object.assign({},e),{time:Date.now(),logs:e.logs.map((e=>E.transformToAtom(e,!1)))}));if(x.broadcastMessage(r),null===(s=this.$pageSpyConfig)||void 0===s?void 0:s.serializeData){const t=Object.assign(Object.assign({},r),{data:Object.assign(Object.assign({},r.data),{logs:e.logs.map((e=>E.transformToAtom(e,!0)))})});x.dispatchEvent("public-data",t)}else x.dispatchEvent("public-data",r)}}}H.hasInitd=!1;class F{constructor(){this.name="ErrorPlugin",this.$pageSpyConfig=null,this.errorHandler=this.errorHandler.bind(this),this.unhandledRejectionHandler=this.unhandledRejectionHandler.bind(this)}onInit(e){let{config:t}=e;F.hasInitd||(F.hasInitd=!0,this.$pageSpyConfig=t,this.onUncaughtError(),this.onUnhandledRejectionError())}onReset(){const e=L();e.canIUse("offError")&&e.offError(this.errorHandler),e.canIUse("offUnhandledRejection")&&e.offUnhandledRejection(this.unhandledRejectionHandler),F.hasInitd=!1}errorHandler(e){if(F.hasInitd)if(e.stack||e.message){const{message:t,stack:n}=e;this.sendMessage(n||t,(e=>{if("object"!=typeof e)return null;const{name:t,message:n,stack:s}=Object(e);return!1===[t,n,s].every(Boolean)?null:{name:t,message:n,stack:s}})(e))}else{const e="[PageSpy] An unknown error occurred and no message or stack trace available";this.sendMessage(e,null)}}unhandledRejectionHandler(e){F.hasInitd&&this.sendMessage("UnHandled Rejection",{name:"unhandledrejection",message:e.reason})}onUncaughtError(){const e=L();e.canIUse("onError")&&e.onError(this.errorHandler)}onUnhandledRejectionError(){const e=L();e.canIUse("onUnhandledRejection")&&e.onUnhandledRejection(this.unhandledRejectionHandler)}sendMessage(e,t){var n,s,o;const r={logType:"error",logs:[e],time:Date.now(),url:"wx:light-app",errorDetail:t};if(!1===(null===(o=null===(s=null===(n=this.$pageSpyConfig)||void 0===n?void 0:n.dataProcessor)||void 0===s?void 0:s.console)||void 0===o?void 0:o.call(s,r)))return;r.logs=r.logs.map((e=>E.transformToAtom(e)));const i=b("console",r);x.dispatchEvent("public-data",i),x.broadcastMessage(i)}}F.hasInitd=!1;class W extends I{constructor(){super(x)}}class _ extends W{constructor(){super(),this.request=null,this.initProxyHandler()}reset(){if(this.request){const e=L();Object.defineProperty(e,"request",{value:this.request})}}initProxyHandler(){const e=this,s=L(),o=s.request;o&&(this.request=o,Object.defineProperty(s,"request",{value(s){const r=t();e.createRequest(r);const i=e.getRequest(r);if(i){const t=s.method||"GET",{url:c}=s;i.requestHeader=[],i.url=c,i.method=t.toUpperCase(),i.requestType="mp-request",i.status=0,i.statusText="Pending",i.startTime=Date.now(),i.readyState=S.UNSENT,a(s.header)&&(i.requestHeader=Object.entries(s.header).map((e=>{let[t,n]=e;return[String(t),String(n)]}))),i.requestHeader.push(["Content-Type","application/json"]);const{data:l}=s;if(l)if("string"==typeof l)i.requestPayload=l;else if(l instanceof ArrayBuffer)i.requestPayload="[object ArrayBuffer]";else try{i.requestPayload=JSON.stringify(l)}catch(e){i.requestPayload=n(l)}e.sendRequestItem(r,i);const u=s.success,h=s.fail,d=s.complete,g=()=>{i.endTime=Date.now(),i.costTime=i.endTime-(i.startTime||i.endTime)};s.success=function(t){g(),i.status=(null==t?void 0:t.statusCode)||200,i.statusText="Done",i.responseHeader=[...Object.entries((null==t?void 0:t.header)||{})],i.readyState=S.HEADERS_RECEIVED,e.sendRequestItem(r,i);const n=function(e){const t=Object.keys(e),n={};for(let s=0;s<t.length;s++){const o=t[s];n[o.toLowerCase()]=e[o]}return n}((null==t?void 0:t.header)||{})["content-type"];switch(n&&(n.includes("application/json")&&(i.responseType="json"),(n.includes("text/html")||n.includes("text/plain"))&&(i.responseType="text")),i.responseType||(i.responseType="arraybuffer"),i.responseType){case"json":case"text":if("string"==typeof(null==t?void 0:t.data))try{i.response=JSON.parse(t.data)}catch(e){i.response=t.data,i.responseType="text"}else i.response=null==t?void 0:t.data;break;case"arraybuffer":i.response="[object ArrayBuffer]"}null==u||u(t)},s.fail=function(e){g(),null==h||h(e)},s.complete=function(t){i.readyState=S.DONE,e.sendRequestItem(r,i),null==d||d(t)};return o(s)}return g.warn("The request object is not found on request event"),null}}))}}class G{constructor(){this.name="NetworkPlugin",this.requestProxy=null}onInit(e){let{config:t}=e;G.hasInitd||(G.hasInitd=!0,I.dataProcessor=t.dataProcessor.network,this.requestProxy=new _)}onReset(){var e;null===(e=this.requestProxy)||void 0===e||e.reset(),G.hasInitd=!1}}G.hasInitd=!1;class V{constructor(){this.name="SystemPlugin",this.$pageSpyConfig=null}onInit(e){let{config:t}=e;V.hasInitd||(V.hasInitd=!0,this.$pageSpyConfig=t,x.addListener("refresh",((e,t)=>{let{source:n}=e;var s,o,r;const{data:i}=n;if("system"===i){const e=V.getSystemInfo();if(!1===(null===(r=null===(o=null===(s=this.$pageSpyConfig)||void 0===s?void 0:s.dataProcessor)||void 0===o?void 0:o.system)||void 0===r?void 0:r.call(o,e)))return;const n=b("system",e);x.dispatchEvent("public-data",n),t(n)}})))}onReset(){V.hasInitd=!1}static getSystemInfo(){return{system:{ua:k.getName()},features:{}}}}function $(e){const t=typeof e;let n=e;return"string"===t||"boolean"===t||"number"===t?n=String(e):"object"===t&&(n=e instanceof Date?e.toDateString():JSON.stringify(e)),n}V.hasInitd=!1;class B{constructor(){this.name="StoragePlugin",this.$pageSpyConfig=null}onInit(e){let{config:t}=e;B.hasInitd||(B.hasInitd=!0,this.$pageSpyConfig=t,this.initStorageProxy(),this.listenRefreshEvent())}onReset(){const e=L();Object.entries(B.originFunctions).forEach((t=>{let[n,s]=t;Object.defineProperty(e,n,{value:s})})),B.hasInitd=!1}sendRefresh(){const e=L();try{const t=e.getStorageInfoSync(),n={type:"mpStorage",action:"get",data:t.keys.map((e=>({name:e,value:$(M.getStorage(e))})))};this.sendStorageItem(n)}catch(e){}}listenRefreshEvent(){x.addListener("refresh",(t=>e(this,[t],void 0,(function(e){var t=this;let{source:n}=e;return function*(){const{data:e}=n;"mpStorage"===e&&t.sendRefresh()}()}))))}initStorageProxy(){const e=L();["setStorage","setStorageSync","removeStorage","removeStorageSync","clearStorage","clearStorageSync","batchSetStorageSync","batchSetStorage"].forEach((t=>{e[t]&&(B.originFunctions[t]=e[t])}));const t=this;Object.defineProperties(e,{setStorage:{value:e=>B.originFunctions.setStorage(Object.assign(Object.assign({},e),{success(n){var s;t.sendSetItem(e.key,e.data),null===(s=e.success)||void 0===s||s.call(e,n)}}))},setStorageSync:{value(e,n){try{let s;if("mp-alipay"!==k.info.browserType||k.info.framework&&"unknown"!==k.info.framework){const o=e;s=B.originFunctions.setStorageSync(o,n),t.sendSetItem(o,n)}else{const n=e;s=B.originFunctions.setStorageSync(n),t.sendSetItem(n.key,n.data)}return s}catch(t){throw g.error("Failed to set storage synchronously: ".concat(e)),t}}},removeStorage:{value:e=>B.originFunctions.removeStorage(Object.assign(Object.assign({},e),{success(n){var s;t.sendRemoveItem(e.key),null===(s=e.success)||void 0===s||s.call(e,n)}}))},removeStorageSync:{value(e){try{const n=B.originFunctions.removeStorageSync(e);return t.sendRemoveItem(n),n}catch(t){throw g.error("Failed to remove storage synchronously: ".concat(e)),t}}},clearStorage:{value:e=>B.originFunctions.clearStorage(Object.assign(Object.assign({},e),{success(n){var s;t.sendClearItem(),null===(s=e.success)||void 0===s||s.call(e,n)}}))},clearStorageSync:{value(){try{const e=B.originFunctions.clearStorageSync();return t.sendClearItem(),e}catch(e){throw g.error("Failed to clear storage synchronously"),e}}}}),e.canIUse("batchSetStorageSync")&&Object.defineProperty(e,"batchSetStorageSync",{value(e){try{const n=B.originFunctions.batchSetStorageSync(e);return e.forEach((e=>{t.sendSetItem(e.key,e.value)})),n}catch(t){throw g.error("Failed to batch set storage synchronously: ".concat(JSON.stringify(e.map((e=>e.key))))),t}}}),e.canIUse("batchSetStorage")&&Object.defineProperty(e,"batchSetStorage",{value:e=>B.originFunctions.batchSetStorage(Object.assign(Object.assign({},e),{success(n){var s;e.kvList.forEach((e=>{t.sendSetItem(e.key,e.value)})),null===(s=e.success)||void 0===s||s.call(e,n)}}))})}sendSetItem(e,t){this.sendStorageItem({type:"mpStorage",action:"set",name:e,value:$(t)})}sendRemoveItem(e){this.sendStorageItem({type:"mpStorage",action:"remove",name:e})}sendClearItem(){this.sendStorageItem({type:"mpStorage",action:"clear"})}sendStorageItem(e){var t,n,s;if(!1===(null===(s=null===(n=null===(t=this.$pageSpyConfig)||void 0===t?void 0:t.dataProcessor)||void 0===n?void 0:n.storage)||void 0===s?void 0:s.call(n,e)))return;const o=b("storage",e);x.dispatchEvent("public-data",o),x.broadcastMessage(o,!0)}}B.hasInitd=!1,B.originFunctions={};const J=e=>!1===e?["http://","ws://"]:["https://","wss://"];class z{constructor(e){if(this.config=e,!e.get().api)throw Error("The api base url cannot be empty")}get base(){return this.config.get().api}createRoom(){const{enableSSL:e,project:t,title:n,useSecret:s,secret:o}=this.config.get(),r=J(e),i=k.getName(),a=A({group:t,title:n,name:encodeURIComponent(i)});return(c=L().request,e=>new Promise(((t,n)=>{c(Object.assign(Object.assign({},e),{success(e){t(e)},fail(e){n(e)}}))})))({url:"".concat(r[0]).concat(this.base,"/api/v1/room/create?").concat(a),method:"POST",data:JSON.stringify({useSecret:s,secret:o})}).then((e=>{var t;const{name:n,address:s}=(null===(t=e.data)||void 0===t?void 0:t.data)||{};return{roomUrl:this.getRoomUrl(s),address:s,name:n}}),(e=>{throw Error("Request create room failed: ".concat(e.message))}));var c}getRoomUrl(e){const n=this.config.get(),s=J(n.enableSSL);return"".concat(s[1]).concat(this.base,"/api/v1/ws/room/join?").concat(A({address:e,name:"client:".concat(t()),userId:"Client",forceCreate:!0,useSecret:n.useSecret,secret:n.secret}))}}class K extends T{constructor(){super(...arguments),this.privateKeys=["secret"]}defaultConfig(){return{api:"",project:"default",title:"",enableSSL:null,disabledOnProd:!0,disabledPlugins:[],singletonSocket:!1,messageCapacity:1e3,useSecret:!1,secret:"",serializeData:!1,dataProcessor:{}}}}class Q{constructor(e){if(this.root=null,this.version="1.9.7",this.request=null,this.name="",this.address="",this.roomUrl="",this.socketStore=x,this.config=new K,this.cacheTimer=null,Q.instance)return g.warn("Cannot initialize PageSpy multiple times"),Q.instance;const t=this.config.mergeConfig(e);t.singletonSocket&&(U.isSingleSocket=!0);const n=L();if(n.canIUse("getAccountInfoSync")&&n.getAccountInfoSync){if("release"===n.getAccountInfoSync().miniProgram.envVersion&&!1!==t.disabledOnProd)return void g.warn("PageSpy is not allowed on release env of mini program")}Q.instance=this,this.request=new z(this.config),this.updateConfiguration(),this.triggerPlugins("onInit",{socketStore:x,config:t,atom:E}),k.plugins=Q.pluginsWithOrder.map((e=>e.name)),this.init()}updateConfiguration(){const{messageCapacity:e,useSecret:t}=this.config.get();if(!0===t){const e=M.getStorage(j),t=(null==e?void 0:e.secret)||function(){const e=Math.floor(1e6*Math.random());return String(e).padStart(6,"0")}();this.config.set("secret",t),g.log("Room Secret: ".concat(t))}x.connectable=!0,x.getPageSpyConfig=()=>this.config.get(),x.messageCapacity=e}init(){return e(this,void 0,void 0,(function*(){const e=L(),t=this.config.get(),n=M.getStorage(j);if(n&&"object"==typeof n){const{name:e,address:s,roomUrl:o,project:r}=n;t.project!==r?yield this.createNewConnection():(this.name=e,this.address=s,this.roomUrl=o,this.useOldConnection())}else yield this.createNewConnection();e.canIUse("onAppShow")&&e.onAppShow((()=>{const e=x.getSocket().getState();e!==P.CLOSED&&e!==P.CLOSING||this.useOldConnection()})),g.log("Plugins inited")}))}createNewConnection(){return e(this,void 0,void 0,(function*(){if(!this.request)return void g.error("Cannot get the Request");const e=yield this.request.createRoom();this.name=e.name,this.address=e.address,this.roomUrl=e.roomUrl,this.refreshRoomInfo(),x.init(e.roomUrl)}))}useOldConnection(){this.refreshRoomInfo(),x.init(this.roomUrl)}refreshRoomInfo(){this.saveSession(),this.cacheTimer=setInterval((()=>{x.getSocket().getState()===P.OPEN&&this.saveSession()}),15e3),g.log("Room ID: ".concat(this.address.slice(0,4)))}saveSession(){const{name:e,address:t,roomUrl:n,config:s}=this,{useSecret:o,secret:r,project:i}=s.get(),a={name:e,address:t,roomUrl:n,project:i,useSecret:o,secret:r};M.setStorage(j,a)}triggerPlugins(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),s=1;s<t;s++)n[s-1]=arguments[s];const{disabledPlugins:o}=this.config.get();Q.pluginsWithOrder.forEach((t=>{var s;r(o)&&o.length&&o.includes(t.name)||null===(s=t[e])||void 0===s||s.apply(t,n)}))}abort(){this.triggerPlugins("onReset"),x.close(),Q.instance=null}updateRoomInfo(e){if(!e)return;const{project:t,title:n}=e;t&&this.config.set("project",String(t)),n&&this.config.set("title",String(n)),x.updateRoomInfo()}static get pluginsWithOrder(){return[...Q.plugins.pre,...Q.plugins.normal,...Q.plugins.post]}static registerPlugin(e){if(!e)return;if("function"==typeof(t=e)&&void 0!==t.prototype)return void g.error("PageSpy.registerPlugin() expect to pass an instance, not a class");var t;if(!e.name)return void g.error("The ".concat(e.constructor.name,' plugin should provide a "name" property'));if(Q.pluginsWithOrder.some((t=>t.name===e.name)))return void g.error("The ".concat(e.name,' has registered. Consider the following reasons:\n - Duplicate register one same plugin;\n - Plugin\'s "name" conflict with others, you can print all registered plugins by "PageSpy.plugins";'));Q.plugins[e.enforce||"normal"].push(e)}}Q.instance=null,Q.plugins={pre:[],normal:[],post:[]};var X;[new H,new F,new G,new B,new V].forEach((e=>{Q.registerPlugin(e)})),X=my,D=X,M.getStorage=e=>{const t=my.getStorageSync({key:e});if(t.success)return t.data},M.setStorage=(e,t)=>my.setStorageSync({key:e,data:t}),M.removeStorage=e=>my.removeStorageSync({key:e});const Y=my.getSystemInfoSync();k.info.sdk="mp-alipay",k.info.osType=Y.platform.toLowerCase(),k.info.browserType="mp-alipay",k.info.osVersion=Y.system,k.info.browserVersion=Y.version,q.messageFilters.push((e=>e.data));export{Q as default};
function e(e,t,n,s){return new(n||(n=Promise))((function(o,r){function i(e){try{c(s.next(e))}catch(e){r(e)}}function a(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,a)}c((s=s.apply(e,t||[])).next())}))}function t(){return Math.random().toString(36).slice(2)}function n(e){return Object.prototype.toString.call(e)}function s(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function o(e){return"[object BigInt]"===n(e)}function r(e){return e instanceof Array}function i(e){return"object"==typeof e&&null!==e}function a(e){return!(!i(e)||"[object Object]"!==n(e))}"function"==typeof SuppressedError&&SuppressedError;const c=e=>"".concat(e),l=e=>({ok:!0,value:e});function u(e){return void 0===e?l(c(e)):null===e?l(e):function(e){return"number"==typeof e}(e)&&(e===-1/0||e===1/0||Number.isNaN(e))?l(c(e)):o(e)?l("".concat(e,"n")):"symbol"==typeof e||"function"==typeof e?l(c(e.toString())):e instanceof Error?l(c(e.stack)):e===Object.prototype?{value:null,ok:!1}:e instanceof Object||"object"==typeof e?{value:e,ok:!1}:l(e)}function h(e){return void 0===e?"undefined":null===e?"null":o(e)?"bigint":e instanceof Object?e instanceof Error?"error":"function"==typeof e?"function":"object":typeof e}const d=Object.assign({},console),g=["log","info","error","warn","debug"].reduce(((e,t)=>(e[t]=function(){for(var e=arguments.length,n=new Array(e),s=0;s<e;s++)n[s]=arguments[s];console[t]("[PageSpy] [".concat(t.toLocaleUpperCase(),"] "),...n)},e.unproxy[t]=function(){for(var e=arguments.length,n=new Array(e),s=0;s<e;s++)n[s]=arguments[s];d[t]("[PageSpy] [".concat(t.toLocaleUpperCase(),"] "),...n)},e)),{unproxy:{}});const p="message",f="broadcast",m="ping",y="updateRoomInfo";var S,v=Object.freeze({__proto__:null,BROADCAST:f,CLOSE:"close",CONNECT:"connect",ERROR:"error",JOIN:"join",LEAVE:"leave",MESSAGE:p,PING:m,PONG:"pong",UPDATE_ROOM_INFO:y});function b(e,n){let s=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];return{role:"client",type:e,data:Object.assign(Object.assign({},s&&{id:t()}),n)}}class O{constructor(e){this.id="",this.method="",this.url="",this.requestType="xhr",this.requestHeader=null,this.status=0,this.statusText="",this.readyState=0,this.responseReason=null,this.responseType="",this.responseHeader=null,this.startTime=0,this.endTime=0,this.costTime=0,this.postData=null,this.requestPayload=null,this.withCredentials=!1,this.id=e}}!function(e){e[e.UNSENT=0]="UNSENT",e[e.OPENED=1]="OPENED",e[e.HEADERS_RECEIVED=2]="HEADERS_RECEIVED",e[e.LOADING=3]="LOADING",e[e.DONE=4]="DONE"}(S||(S={}));class I{constructor(e){this.socketStore=e,this.reqMap=Object.create(null)}getRequestMap(){return this.reqMap}getRequest(e){return this.reqMap[e]}removeRequest(e){delete this.reqMap[e]}createRequest(e){return e?this.reqMap[e]?(g.warn("The request object has been in store, disallow duplicate create"),!1):(this.reqMap[e]=new O(e),!0):(g.warn('The "id" is required when init request object'),!1)}setRequest(e,t){return!(!e||!t)&&(this.reqMap[e]=t,!0)}sendRequestItem(e,t){var n;if(!1!==(null===(n=I.dataProcessor)||void 0===n?void 0:n.call(I,t)))try{this.reqMap[e]||(this.reqMap[e]=t);const n=b("network",Object.assign({},t),!1);this.socketStore.dispatchEvent("public-data",n),this.socketStore.broadcastMessage(n,t.readyState!==S.DONE),this.deferDeleteRequest(e)}catch(e){g.error(e.message)}}deferDeleteRequest(e){const t=this.getRequest(e);t&&t.readyState===S.DONE&&setTimeout((()=>{delete this.reqMap[e]}),3e3)}}class C{constructor(){this.store={},this.instanceStore={}}getStore(){return this.store}resetStore(){this.store={}}getInstanceStore(){return this.instanceStore}resetInstanceStore(){this.instanceStore={}}transformToAtom(e){let n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const{value:s,ok:o}=u(e),r=t();if(o)return{id:r,type:h(e),value:s};if(n)try{return{id:r,type:"json",value:JSON.stringify(e)}}catch(e){return{id:r,type:"json",value:null}}return this.add(e)}get(e){const n=this.store[e],o=this.instanceStore[e];if(!n)return null;const r={},i=Object.getOwnPropertyDescriptors(n);Object.keys(i).forEach((e=>{const n=i[e];s(n,"value")&&(n.value=this.transformToAtom(n.value)),r[e]=C.getAtomOverview({atomId:t(),instanceId:o,value:n})}));const a=this.addExtraProperty(e);return Object.assign(Object.assign({},r),a)}getOrigin(e){const t=this.store[e];return t||null}add(e){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";const o=t();let r=o;var a;i(a=e)&&s(a,"constructor")&&"function"==typeof a.constructor&&(r=n),this.store[o]=e,this.instanceStore[o]=r;const c=C.getSemanticValue(e);return C.getAtomOverview({atomId:o,value:c,instanceId:r})}static getAtomOverview(e){let{instanceId:n="",atomId:s,value:o}=e;return{id:t(),type:"atom",__atomId:s,instanceId:n,value:o}}static getSemanticValue(e){if(a(e))return"Object {...}";if(r(e))return"Array (".concat(e.length,")");return e.constructor.name}addExtraProperty(e){const t=this.store[e],n=this.instanceStore[e],s={};if((t instanceof String||t instanceof Number||t instanceof Boolean)&&(s["[[PrimitiveValue]]"]=this.transformToAtom(t.valueOf())),t instanceof Set){const e={};let n=0;for(const s of t)e[n++]=s;e.size=t.size,s["[[Entries]]"]=this.transformToAtom(e)}if(t instanceof Map){const e={};let n=0;for(const[s,o]of t.entries())e[n++]={key:s,value:o};e.size=t.size,s["[[Entries]]"]=this.transformToAtom(e)}var o;return(r(t)||(o=t,"function"==typeof NodeList&&"NodeList"===NodeList.name&&o instanceof NodeList||"function"==typeof HTMLCollection&&"HTMLCollection"===HTMLCollection.name&&o instanceof HTMLCollection))&&(s.length=this.transformToAtom(t.length)),null!==Object.getPrototypeOf(t)?s["[[Prototype]]"]=this.add(Object.getPrototypeOf(t),n):s.___proto___=this.transformToAtom(null),s}}const E=new C;class k{static makeClientInfoMsg(){return{sdk:k.info.sdk,isDevTools:k.info.isDevTools,ua:k.getName(),plugins:k.plugins}}static getName(){if(!k._name){const{ua:e,osType:t,osVersion:n,browserType:s,browserVersion:o}=k.info;k._name=e||"".concat(t,"/").concat(n," ").concat(s,"/").concat(o)}return k._name}}k.info={osType:"unknown",osVersion:"unknown",browserType:"unknown",browserVersion:"unknown",framework:"unknown",isDevTools:!1,sdk:"browser"},k.plugins=[];class T{defaultConfig(){return{}}constructor(){this.mergeConfig=e=>{const t=Object.entries(e).reduce(((e,t)=>{let[n,s]=t;return this.privateKeys.includes(n)||(e[n]=s),e}),{});return this.value=Object.assign(Object.assign({},this.defaultConfig()),t),this.value},this.value=this.defaultConfig()}get(){return this.value}set(e,t){this.value[e]=t}}const j="page-spy-room";var P;!function(e){e[e.CONNECTING=0]="CONNECTING",e[e.OPEN=1]="OPEN",e[e.CLOSING=2]="CLOSING",e[e.CLOSED=3]="CLOSED"}(P||(P={}));const w=2e3,R=Math.pow(1.5,4)*w;class N{constructor(){this.events={open:[],close:[],error:[],message:[]}}emit(e,t){this.events[e].forEach((e=>{e(t)})),"close"!==e&&"error"!==e||this.clearListeners()}onOpen(e){this.events.open.push(e)}onClose(e){this.events.close.push(e)}onError(e){this.events.error.push(e)}onMessage(e){this.events.message.push(e)}clearListeners(){Object.entries(this.events).forEach((e=>{let[,t]=e;t.splice(0)}))}}class q{getSocket(){return this.socketWrapper}updateRoomInfo(){if(this.getPageSpyConfig){const{project:e,title:t}=this.getPageSpyConfig(),n=k.getName();this.send({type:y,content:{info:{name:n,group:e,tags:{title:t,name:n,group:e}}}},!0)}}constructor(){this.socketUrl="",this.socketConnection=null,this.debuggerConnection=null,this.pingTimer=null,this.pongTimer=null,this.retryTimer=null,this.isOffline=!1,this.messageCapacity=0,this.messages=[],this.events={debug:[],refresh:[],"atom-detail":[],"atom-getter":[],"debugger-online":[],"database-pagination":[],"public-data":[],"harbor-clear":[]},this.retryInterval=w,this.connectable=!0,this.getPageSpyConfig=null,this.addListener("atom-detail",q.handleResolveAtom),this.addListener("atom-getter",q.handleAtomPropertyGetter),this.addListener("debugger-online",this.handleFlushBuffer)}init(t){return e(this,void 0,void 0,(function*(){var e,n,s,o,r;try{if(!t)throw Error("WebSocket url cannot be empty");this.socketWrapper.clearListeners(),this.socketWrapper.getState()===P.OPEN&&(yield new Promise((e=>{this.socketWrapper.onClose((()=>{this.socketWrapper.clearListeners(),e()})),this.socketWrapper.close()}))),null===(e=this.socketWrapper)||void 0===e||e.onOpen((()=>{this.connectOnline()})),null===(n=this.socketWrapper)||void 0===n||n.onMessage((e=>{this.handleMessage(e)})),null===(s=this.socketWrapper)||void 0===s||s.onClose((()=>{this.connectOffline()})),null===(o=this.socketWrapper)||void 0===o||o.onError((()=>{this.connectOffline()})),this.socketUrl=t,null===(r=this.socketWrapper)||void 0===r||r.init(t)}catch(e){g.error(e.message)}}))}addListener(e,t){this.events[e]||(this.events[e]=[]),this.events[e].push(t)}removeListener(e,t){const n=this.events[e]||[],s=n.indexOf(t);s>-1&&n.splice(s,1)}broadcastMessage(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const n=function(e){return{type:f,content:{data:e}}}(e);this.send(n,t)}close(){var e;this.connectable=!1,this.clearPing(),null===(e=this.socketWrapper)||void 0===e||e.close(),this.messages=[],Object.entries(this.events).forEach((e=>{let[t,n]=e;["atom-detail","atom-getter","debugger-online"].includes(t)||n.splice(0)}))}connectOnline(){this.retryInterval=w,this.updateRoomInfo(),this.ping()}connectOffline(){this.socketConnection=null,this.debuggerConnection=null,this.clearPing(),this.retryTimer&&clearTimeout(this.retryTimer),this.connectable&&(this.retryTimer=setTimeout((()=>{this.retryInterval<R&&(this.retryInterval*=1.5),this.retryTimer=null,this.tryReconnect()}),this.retryInterval))}tryReconnect(){this.init(this.socketUrl)}ping(){this.pingTimer&&clearTimeout(this.pingTimer),this.pongTimer&&clearTimeout(this.pongTimer),this.pingTimer=setTimeout((()=>{this.send({type:"ping",content:null}),this.pingTimer=null,this.pongTimer=setTimeout((()=>{this.connectOffline(),this.pongTimer=null}),5e3)}),5e3)}clearPing(){this.pingTimer&&(clearTimeout(this.pingTimer),this.pingTimer=null),this.pongTimer&&(clearTimeout(this.pongTimer),this.pongTimer=null)}handlePong(){clearTimeout(this.pongTimer),this.pongTimer=null,this.ping()}handleMessage(e){var t;q.messageFilters.length&&q.messageFilters.forEach((t=>{e=t(e)}));const{CONNECT:n,MESSAGE:s,ERROR:o,JOIN:r,PING:i,PONG:a,LEAVE:c,CLOSE:l,BROADCAST:u}=v,h=JSON.parse(e.data),{type:d}=h;switch(d){case n:const{selfConnection:e,roomConnections:i}=h.content;this.socketConnection=e,this.debuggerConnection=i.find((e=>"Debugger"===e.userId))||null;break;case r:case c:const{connection:a}=h.content;"Debugger"===a.userId&&(d===r?(this.debuggerConnection=a,this.sendClientInfo()):this.debuggerConnection=null);break;case s:const{data:u,from:g,to:p}=h.content;p.address===(null===(t=this.socketConnection)||void 0===t?void 0:t.address)&&this.dispatchEvent(u.type,{source:u,from:g,to:p});break;case l:case o:this.connectOffline()}this.handlePong()}dispatchEvent(e,t){var n;["public-data"].includes(e)?this.events["public-data"].forEach((e=>{e(t)})):null===(n=this.events[e])||void 0===n||n.forEach((e=>{e.call(this,t,(e=>{this.unicastMessage(e,t.from)}))}))}unicastMessage(e,t){const n=function(e,t,n){return{type:p,content:{data:e,from:t,to:n}}}(e,this.socketConnection,t);this.send(n)}handleFlushBuffer(e){const{latestId:t}=e.source.data,n=this.messages.findIndex((e=>e.content.data.data.id===t));this.messages.slice(n+1).forEach((t=>{const n={type:p,content:{data:t.content.data,from:this.socketConnection,to:e.from}};this.send(n,!0)}))}static handleResolveAtom(e,t){let{source:n}=e;const{type:s,data:o}=n;if("atom-detail"===s){const e=E.get(o)||{};t(b("atom-detail-".concat(o),e,!1))}}static handleAtomPropertyGetter(e,t){let{source:n}=e;var s,o;const{type:r,data:i}=n;if("atom-getter"===r){const{id:e,parentId:n,key:r,instanceId:a}=i,c=E.getOrigin(a),l=E.getOrigin(n);let u={};u=c&&l?null===(o=null===(s=Object.getOwnPropertyDescriptor(l,r))||void 0===s?void 0:s.get)||void 0===o?void 0:o.call(c):new Error("Getter computed failed");t(b("atom-getter-".concat(e),E.transformToAtom(u)))}}send(e){let n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];var s;if(this.checkIfSend(e))try{const n=e;n.createdAt=Date.now(),n.requestId=t();const o=function(e){const{ok:t,value:n}=u(e);return t?n:JSON.stringify(e,((e,t)=>u(t).value),2)}(n);null===(s=this.socketWrapper)||void 0===s||s.send(o)}catch(e){g.error("Incompatible: ".concat(e.message)),this.connectOffline()}this.checkIfCache(e,n)&&(0!==this.messageCapacity&&this.messages.length>=this.messageCapacity&&this.messages.shift(),this.messages.push(e))}checkIfSend(e){return this.socketWrapper.getState()===P.OPEN&&(!![y,m].includes(e.type)||!!this.debuggerConnection)}checkIfCache(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return!this.isOffline&&!t&&![p,m].includes(e.type)}sendClientInfo(){const e=k.makeClientInfoMsg();this.broadcastMessage({role:"client",type:"client-info",data:e},!0)}}q.messageFilters=[];const D=e=>{const t=[];return Object.entries(e).forEach((e=>{let[n,s]=e;t.push("".concat(n,"=").concat(s))})),t.join("&")};let A;const L=()=>{if(!A)throw Error("the mp sdk is not set");return A},M={setStorage:(e,t)=>null==A?void 0:A.setStorageSync(e,t),getStorage:e=>null==A?void 0:A.getStorageSync(e),removeStorage:e=>null==A?void 0:A.getStorageSync(e)};class U extends N{constructor(){super(...arguments),this.socketInstance=null,this.state=0}init(t){return e(this,void 0,void 0,(function*(){this.state=P.CONNECTING;const e=L(),n=e=>{this.state=P.CLOSED,this.emit("close",e)},s=e=>{this.state=P.OPEN,this.emit("open",e)},o=e=>{this.state=P.CLOSED,this.emit("error",e)},r=e=>{this.emit("message",e)};if(U.isSingleSocket)e.connectSocket({url:t}),e.onSocketClose(n),e.onSocketError(o),e.onSocketMessage(r),e.onSocketOpen(s);else{let i=e.connectSocket({url:t,multiple:!0,complete(){}});i instanceof Promise&&(i=yield i),i.onClose(n),i.onError(o),i.onOpen(s),i.onMessage(r),this.socketInstance=i}}))}send(e){var t;U.isSingleSocket?L().sendSocketMessage({data:e}):null===(t=this.socketInstance)||void 0===t||t.send({data:e})}close(){var e;U.isSingleSocket?L().closeSocket({}):null===(e=this.socketInstance)||void 0===e||e.close({}),this.state=P.CLOSED}getState(){return this.state}}U.isSingleSocket=!1;var x=new class extends q{constructor(){super(...arguments),this.socketWrapper=new U}onOffline(){M.removeStorage(j)}};class H{constructor(){this.name="ConsolePlugin",this.console={},this.proxyTypes=["log","info","error","warn","debug"],this.$pageSpyConfig=null}onInit(t){return e(this,arguments,void 0,(function(e){var t=this;let{config:n}=e;return function*(){H.hasInitd||(H.hasInitd=!0,t.$pageSpyConfig=n,t.init())}()}))}init(){const e=this;this.proxyTypes.forEach((t=>{this.console[t]=console[t]||console.log||(()=>{}),Object.defineProperty(console,t,{value(){const n=getCurrentPages().pop();let s="/";n&&(s=n.route,n.options&&Object.keys(n.options).length>0&&(s+="?"+D(n.options)));for(var o=arguments.length,r=new Array(o),i=0;i<o;i++)r[i]=arguments[i];e.printLog({logType:t,logs:r,url:s})},configurable:!0,enumerable:!0,writable:!0})}))}reset(){this.proxyTypes.forEach((e=>{const t=this.console[e];t&&(console[e]=t)}))}onReset(){this.reset(),H.hasInitd=!1}printLog(e){var t,n,s;if(e.logs&&e.logs.length){const o=null===(n=null===(t=this.$pageSpyConfig)||void 0===t?void 0:t.dataProcessor)||void 0===n?void 0:n.console;if(o){this.reset();const t=o(e);if(this.init(),!1===t)return}this.console[e.logType](...e.logs);const r=b("console",Object.assign(Object.assign({},e),{time:Date.now(),logs:e.logs.map((e=>E.transformToAtom(e,!1)))}));if(x.broadcastMessage(r),null===(s=this.$pageSpyConfig)||void 0===s?void 0:s.serializeData){const t=Object.assign(Object.assign({},r),{data:Object.assign(Object.assign({},r.data),{logs:e.logs.map((e=>E.transformToAtom(e,!0)))})});x.dispatchEvent("public-data",t)}else x.dispatchEvent("public-data",r)}}}H.hasInitd=!1;class F{constructor(){this.name="ErrorPlugin",this.$pageSpyConfig=null,this.errorHandler=this.errorHandler.bind(this),this.unhandledRejectionHandler=this.unhandledRejectionHandler.bind(this)}onInit(e){let{config:t}=e;F.hasInitd||(F.hasInitd=!0,this.$pageSpyConfig=t,this.onUncaughtError(),this.onUnhandledRejectionError())}onReset(){const e=L();e.canIUse("offError")&&e.offError(this.errorHandler),e.canIUse("offUnhandledRejection")&&e.offUnhandledRejection(this.unhandledRejectionHandler),F.hasInitd=!1}errorHandler(e){if(F.hasInitd)if(e.stack||e.message){const{message:t,stack:n}=e;this.sendMessage(n||t,(e=>{if("object"!=typeof e)return null;const{name:t,message:n,stack:s}=Object(e);return!1===[t,n,s].every(Boolean)?null:{name:t,message:n,stack:s}})(e))}else{const e="[PageSpy] An unknown error occurred and no message or stack trace available";this.sendMessage(e,null)}}unhandledRejectionHandler(e){F.hasInitd&&this.sendMessage("UnHandled Rejection",{name:"unhandledrejection",message:e.reason})}onUncaughtError(){const e=L();e.canIUse("onError")&&e.onError(this.errorHandler)}onUnhandledRejectionError(){const e=L();e.canIUse("onUnhandledRejection")&&e.onUnhandledRejection(this.unhandledRejectionHandler)}sendMessage(e,t){var n,s,o;const r={logType:"error",logs:[e],time:Date.now(),url:"wx:light-app",errorDetail:t};if(!1===(null===(o=null===(s=null===(n=this.$pageSpyConfig)||void 0===n?void 0:n.dataProcessor)||void 0===s?void 0:s.console)||void 0===o?void 0:o.call(s,r)))return;r.logs=r.logs.map((e=>E.transformToAtom(e)));const i=b("console",r);x.dispatchEvent("public-data",i),x.broadcastMessage(i)}}F.hasInitd=!1;class W extends I{constructor(){super(x)}}class _ extends W{constructor(){super(),this.request=null,this.initProxyHandler()}reset(){if(this.request){const e=L();Object.defineProperty(e,"request",{value:this.request})}}initProxyHandler(){const e=this,s=L(),o=s.request;o&&(this.request=o,Object.defineProperty(s,"request",{value(s){const r=t();e.createRequest(r);const i=e.getRequest(r);if(i){const t=s.method||"GET",{url:c}=s;i.requestHeader=[],i.url=c,i.method=t.toUpperCase(),i.requestType="mp-request",i.status=0,i.statusText="Pending",i.startTime=Date.now(),i.readyState=S.UNSENT,a(s.header)&&(i.requestHeader=Object.entries(s.header).map((e=>{let[t,n]=e;return[String(t),String(n)]}))),i.requestHeader.push(["Content-Type","application/json"]);const{data:l}=s;if(l)if("string"==typeof l)i.requestPayload=l;else if(l instanceof ArrayBuffer)i.requestPayload="[object ArrayBuffer]";else try{i.requestPayload=JSON.stringify(l)}catch(e){i.requestPayload=n(l)}e.sendRequestItem(r,i);const u=s.success,h=s.fail,d=s.complete,g=()=>{i.endTime=Date.now(),i.costTime=i.endTime-(i.startTime||i.endTime)};s.success=function(t){g(),i.status=(null==t?void 0:t.statusCode)||200,i.statusText="Done",i.responseHeader=[...Object.entries((null==t?void 0:t.header)||{})],i.readyState=S.HEADERS_RECEIVED,e.sendRequestItem(r,i);const n=function(e){const t=Object.keys(e),n={};for(let s=0;s<t.length;s++){const o=t[s];n[o.toLowerCase()]=e[o]}return n}((null==t?void 0:t.header)||{})["content-type"];switch(n&&(n.includes("application/json")&&(i.responseType="json"),(n.includes("text/html")||n.includes("text/plain"))&&(i.responseType="text")),i.responseType||(i.responseType="arraybuffer"),i.responseType){case"json":case"text":if("string"==typeof(null==t?void 0:t.data))try{i.response=JSON.parse(t.data)}catch(e){i.response=t.data,i.responseType="text"}else i.response=null==t?void 0:t.data;break;case"arraybuffer":i.response="[object ArrayBuffer]"}null==u||u(t)},s.fail=function(e){g(),null==h||h(e)},s.complete=function(t){i.readyState=S.DONE,e.sendRequestItem(r,i),null==d||d(t)};return o(s)}return g.warn("The request object is not found on request event"),null}}))}}class G{constructor(){this.name="NetworkPlugin",this.requestProxy=null}onInit(e){let{config:t}=e;G.hasInitd||(G.hasInitd=!0,I.dataProcessor=t.dataProcessor.network,this.requestProxy=new _)}onReset(){var e;null===(e=this.requestProxy)||void 0===e||e.reset(),G.hasInitd=!1}}G.hasInitd=!1;class V{constructor(){this.name="SystemPlugin",this.$pageSpyConfig=null}onInit(e){let{config:t}=e;V.hasInitd||(V.hasInitd=!0,this.$pageSpyConfig=t,this.onceInitPublicData(),x.addListener("refresh",((e,t)=>{let{source:n}=e;const{data:s}=n;if("system"===s){const e=this.getSystemInfo();if(null===e)return;t(e)}})))}onceInitPublicData(){const e=this.getSystemInfo();null!==e&&x.dispatchEvent("public-data",e)}onReset(){V.hasInitd=!1}getSystemInfo(){var e,t,n;const s={system:{ua:k.getName()},features:{}};return!1===(null===(n=null===(t=null===(e=this.$pageSpyConfig)||void 0===e?void 0:e.dataProcessor)||void 0===t?void 0:t.system)||void 0===n?void 0:n.call(t,s))?null:b("system",s)}}function $(e){const t=typeof e;let n=e;return"string"===t||"boolean"===t||"number"===t?n=String(e):"object"===t&&(n=e instanceof Date?e.toDateString():JSON.stringify(e)),n}V.hasInitd=!1;class B{constructor(){this.name="StoragePlugin",this.$pageSpyConfig=null}onInit(e){let{config:t}=e;B.hasInitd||(B.hasInitd=!0,this.$pageSpyConfig=t,this.initStorageProxy(),this.listenRefreshEvent())}onReset(){const e=L();Object.entries(B.originFunctions).forEach((t=>{let[n,s]=t;Object.defineProperty(e,n,{value:s})})),B.hasInitd=!1}sendRefresh(){const e=L();try{const t=e.getStorageInfoSync(),n={type:"mpStorage",action:"get",data:t.keys.map((e=>({name:e,value:$(M.getStorage(e))})))};this.sendStorageItem(n)}catch(e){}}listenRefreshEvent(){x.addListener("refresh",(t=>e(this,[t],void 0,(function(e){var t=this;let{source:n}=e;return function*(){const{data:e}=n;"mpStorage"===e&&t.sendRefresh()}()}))))}initStorageProxy(){const e=L();["setStorage","setStorageSync","removeStorage","removeStorageSync","clearStorage","clearStorageSync","batchSetStorageSync","batchSetStorage"].forEach((t=>{e[t]&&(B.originFunctions[t]=e[t])}));const t=this;Object.defineProperties(e,{setStorage:{value:e=>B.originFunctions.setStorage(Object.assign(Object.assign({},e),{success(n){var s;t.sendSetItem(e.key,e.data),null===(s=e.success)||void 0===s||s.call(e,n)}}))},setStorageSync:{value(e,n){try{let s;if("mp-alipay"!==k.info.browserType||k.info.framework&&"unknown"!==k.info.framework){const o=e;s=B.originFunctions.setStorageSync(o,n),t.sendSetItem(o,n)}else{const n=e;s=B.originFunctions.setStorageSync(n),t.sendSetItem(n.key,n.data)}return s}catch(t){throw g.error("Failed to set storage synchronously: ".concat(e)),t}}},removeStorage:{value:e=>B.originFunctions.removeStorage(Object.assign(Object.assign({},e),{success(n){var s;t.sendRemoveItem(e.key),null===(s=e.success)||void 0===s||s.call(e,n)}}))},removeStorageSync:{value(e){try{const n=B.originFunctions.removeStorageSync(e);return t.sendRemoveItem(n),n}catch(t){throw g.error("Failed to remove storage synchronously: ".concat(e)),t}}},clearStorage:{value:e=>B.originFunctions.clearStorage(Object.assign(Object.assign({},e),{success(n){var s;t.sendClearItem(),null===(s=e.success)||void 0===s||s.call(e,n)}}))},clearStorageSync:{value(){try{const e=B.originFunctions.clearStorageSync();return t.sendClearItem(),e}catch(e){throw g.error("Failed to clear storage synchronously"),e}}}}),e.canIUse("batchSetStorageSync")&&Object.defineProperty(e,"batchSetStorageSync",{value(e){try{const n=B.originFunctions.batchSetStorageSync(e);return e.forEach((e=>{t.sendSetItem(e.key,e.value)})),n}catch(t){throw g.error("Failed to batch set storage synchronously: ".concat(JSON.stringify(e.map((e=>e.key))))),t}}}),e.canIUse("batchSetStorage")&&Object.defineProperty(e,"batchSetStorage",{value:e=>B.originFunctions.batchSetStorage(Object.assign(Object.assign({},e),{success(n){var s;e.kvList.forEach((e=>{t.sendSetItem(e.key,e.value)})),null===(s=e.success)||void 0===s||s.call(e,n)}}))})}sendSetItem(e,t){this.sendStorageItem({type:"mpStorage",action:"set",name:e,value:$(t)})}sendRemoveItem(e){this.sendStorageItem({type:"mpStorage",action:"remove",name:e})}sendClearItem(){this.sendStorageItem({type:"mpStorage",action:"clear"})}sendStorageItem(e){var t,n,s;if(!1===(null===(s=null===(n=null===(t=this.$pageSpyConfig)||void 0===t?void 0:t.dataProcessor)||void 0===n?void 0:n.storage)||void 0===s?void 0:s.call(n,e)))return;const o=b("storage",e);x.dispatchEvent("public-data",o),x.broadcastMessage(o,!0)}}B.hasInitd=!1,B.originFunctions={};const J=e=>!1===e?["http://","ws://"]:["https://","wss://"];class z{constructor(e){if(this.config=e,!e.get().api)throw Error("The api base url cannot be empty")}get base(){return this.config.get().api}createRoom(){const{enableSSL:e,project:t,title:n,useSecret:s,secret:o}=this.config.get(),r=J(e),i=k.getName(),a=D({group:t,title:n,name:encodeURIComponent(i)});return(c=L().request,e=>new Promise(((t,n)=>{c(Object.assign(Object.assign({},e),{success(e){t(e)},fail(e){n(e)}}))})))({url:"".concat(r[0]).concat(this.base,"/api/v1/room/create?").concat(a),method:"POST",data:JSON.stringify({useSecret:s,secret:o})}).then((e=>{var t;const{name:n,address:s}=(null===(t=e.data)||void 0===t?void 0:t.data)||{};return{roomUrl:this.getRoomUrl(s),address:s,name:n}}),(e=>{throw Error("Request create room failed: ".concat(e.message))}));var c}getRoomUrl(e){const n=this.config.get(),s=J(n.enableSSL);return"".concat(s[1]).concat(this.base,"/api/v1/ws/room/join?").concat(D({address:e,name:"client:".concat(t()),userId:"Client",forceCreate:!0,useSecret:n.useSecret,secret:n.secret}))}}class K extends T{constructor(){super(...arguments),this.privateKeys=["secret"]}defaultConfig(){return{api:"",project:"default",title:"",enableSSL:null,disabledOnProd:!0,disabledPlugins:[],singletonSocket:!1,messageCapacity:1e3,useSecret:!1,secret:"",serializeData:!1,dataProcessor:{}}}}class Q{constructor(e){if(this.root=null,this.version="1.9.8",this.request=null,this.name="",this.address="",this.roomUrl="",this.socketStore=x,this.config=new K,this.cacheTimer=null,Q.instance)return g.warn("Cannot initialize PageSpy multiple times"),Q.instance;const t=this.config.mergeConfig(e);t.singletonSocket&&(U.isSingleSocket=!0);const n=L();if(n.canIUse("getAccountInfoSync")&&n.getAccountInfoSync){if("release"===n.getAccountInfoSync().miniProgram.envVersion&&!1!==t.disabledOnProd)return void g.warn("PageSpy is not allowed on release env of mini program")}Q.instance=this,this.request=new z(this.config),this.updateConfiguration(),this.triggerPlugins("onInit",{socketStore:x,config:t,atom:E}),k.plugins=Q.pluginsWithOrder.map((e=>e.name)),this.init()}updateConfiguration(){const{messageCapacity:e,useSecret:t}=this.config.get();if(!0===t){const e=M.getStorage(j),t=(null==e?void 0:e.secret)||function(){const e=Math.floor(1e6*Math.random());return String(e).padStart(6,"0")}();this.config.set("secret",t),g.log("Room Secret: ".concat(t))}x.connectable=!0,x.getPageSpyConfig=()=>this.config.get(),x.messageCapacity=e}init(){return e(this,void 0,void 0,(function*(){const e=L(),t=this.config.get(),n=M.getStorage(j);if(n&&"object"==typeof n){const{name:e,address:s,roomUrl:o,project:r}=n;t.project!==r?yield this.createNewConnection():(this.name=e,this.address=s,this.roomUrl=o,this.useOldConnection())}else yield this.createNewConnection();e.canIUse("onAppShow")&&e.onAppShow((()=>{const e=x.getSocket().getState();e!==P.CLOSED&&e!==P.CLOSING||this.useOldConnection()})),g.log("Plugins inited")}))}createNewConnection(){return e(this,void 0,void 0,(function*(){if(!this.request)return void g.error("Cannot get the Request");const e=yield this.request.createRoom();this.name=e.name,this.address=e.address,this.roomUrl=e.roomUrl,this.refreshRoomInfo(),x.init(e.roomUrl)}))}useOldConnection(){this.refreshRoomInfo(),x.init(this.roomUrl)}refreshRoomInfo(){this.saveSession(),this.cacheTimer=setInterval((()=>{x.getSocket().getState()===P.OPEN&&this.saveSession()}),15e3),g.log("Room ID: ".concat(this.address.slice(0,4)))}saveSession(){const{name:e,address:t,roomUrl:n,config:s}=this,{useSecret:o,secret:r,project:i}=s.get(),a={name:e,address:t,roomUrl:n,project:i,useSecret:o,secret:r};M.setStorage(j,a)}triggerPlugins(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),s=1;s<t;s++)n[s-1]=arguments[s];const{disabledPlugins:o}=this.config.get();Q.pluginsWithOrder.forEach((t=>{var s;r(o)&&o.length&&o.includes(t.name)||null===(s=t[e])||void 0===s||s.apply(t,n)}))}abort(){this.triggerPlugins("onReset"),x.close(),Q.instance=null}updateRoomInfo(e){if(!e)return;const{project:t,title:n}=e;t&&this.config.set("project",String(t)),n&&this.config.set("title",String(n)),x.updateRoomInfo()}static get pluginsWithOrder(){return[...Q.plugins.pre,...Q.plugins.normal,...Q.plugins.post]}static registerPlugin(e){if(!e)return;if("function"==typeof(t=e)&&void 0!==t.prototype)return void g.error("PageSpy.registerPlugin() expect to pass an instance, not a class");var t;if(!e.name)return void g.error("The ".concat(e.constructor.name,' plugin should provide a "name" property'));if(Q.pluginsWithOrder.some((t=>t.name===e.name)))return void g.error("The ".concat(e.name,' has registered. Consider the following reasons:\n - Duplicate register one same plugin;\n - Plugin\'s "name" conflict with others, you can print all registered plugins by "PageSpy.plugins";'));Q.plugins[e.enforce||"normal"].push(e)}}Q.instance=null,Q.plugins={pre:[],normal:[],post:[]};var X;[new H,new F,new G,new B,new V].forEach((e=>{Q.registerPlugin(e)})),X=my,A=X,M.getStorage=e=>{const t=my.getStorageSync({key:e});if(t.success)return t.data},M.setStorage=(e,t)=>my.setStorageSync({key:e,data:t}),M.removeStorage=e=>my.removeStorageSync({key:e});const Y=my.getSystemInfoSync();k.info.sdk="mp-alipay",k.info.osType=Y.platform.toLowerCase(),k.info.browserType="mp-alipay",k.info.osVersion=Y.system,k.info.browserVersion=Y.version,q.messageFilters.push((e=>e.data));export{Q as default};
//# sourceMappingURL=index.min.js.map
{
"name": "@huolala-tech/page-spy-alipay",
"version": "1.9.7",
"version": "1.9.8",
"description": "A developer tool for debugging alipay miniprogram",

@@ -33,3 +33,3 @@ "license": "MIT",

"@huolala-tech/page-spy-base": "^1.0.6",
"@huolala-tech/page-spy-mp-base": "^1.0.6",
"@huolala-tech/page-spy-mp-base": "^1.0.7",
"@huolala-tech/page-spy-types": "^1.9.6"

@@ -69,3 +69,3 @@ },

},
"gitHead": "789c4889df5bafdeb97e05a40b19d3af89b8b694"
"gitHead": "90c365ea5bd16a4ecefd885f9fee05ff87e3786e"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc