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.1 to 1.9.2

2

dist/cjs/index.min.js

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

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

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

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

@@ -32,5 +32,4 @@ "license": "MIT",

"dependencies": {
"@babel/runtime": "^7.13.0",
"@huolala-tech/page-spy-base": "^1.0.0",
"@huolala-tech/page-spy-mp-base": "^1.0.0",
"@huolala-tech/page-spy-base": "^1.0.1",
"@huolala-tech/page-spy-mp-base": "^1.0.1",
"@huolala-tech/page-spy-types": "^1.9.1"

@@ -42,2 +41,3 @@ },

"@babel/preset-typescript": "^7.13.0",
"@babel/runtime": "^7.13.0",
"@huolala-tech/eval5": "^0.0.1",

@@ -70,3 +70,3 @@ "@rollup/plugin-babel": "^6.0.3",

},
"gitHead": "a1cf9f3afaf2f298526cf34958d5fb61d2e14491"
"gitHead": "0d37b04a99d11ceaa2673516f725ae667867eb45"
}

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