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.0 to 1.9.1

dist/types/index.d.ts

2

dist/cjs/index.min.js

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

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

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

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

@@ -8,6 +8,5 @@ "license": "MIT",

"module": "dist/esm/index.min.js",
"types": "types/index.d.ts",
"types": "dist/types/index.d.ts",
"files": [
"dist",
"types"
"dist"
],

@@ -17,3 +16,3 @@ "homepage": "https://www.pagespy.org/",

"type": "git",
"url": "https://github.com/HuolalaTech/page-spy"
"url": "git+https://github.com/HuolalaTech/page-spy.git"
},

@@ -36,13 +35,13 @@ "keywords": [

"@babel/runtime": "^7.13.0",
"@huolala-tech/page-spy-types": "^1.9.0"
"@huolala-tech/page-spy-base": "^1.0.0",
"@huolala-tech/page-spy-mp-base": "^1.0.0",
"@huolala-tech/page-spy-types": "^1.9.1"
},
"devDependencies": {
"@babel/core": "^7.14.0",
"@babel/plugin-transform-runtime": "^7.23.6",
"@babel/preset-env": "^7.14.1",
"@babel/preset-typescript": "^7.13.0",
"@rollup/plugin-alias": "^4.0.3",
"@huolala-tech/eval5": "^0.0.1",
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-image": "^2.1.1",
"@rollup/plugin-json": "^6.0.0",

@@ -52,9 +51,5 @@ "@rollup/plugin-node-resolve": "^15.0.1",

"@rollup/plugin-terser": "^0.4.4",
"autoprefixer": "^10.3.4",
"core-js": "3",
"less": "^4.1.1",
"postcss": "^8.4.21",
"rollup": "^3.10.0",
"rollup-plugin-delete": "^2.0.0",
"rollup-plugin-postcss": "^4.0.1",
"rollup-plugin-typescript2": "^0.34.1"

@@ -77,3 +72,3 @@ },

},
"gitHead": "2649c52819a354410fd3f0ee65e53fa1790a829c"
"gitHead": "a1cf9f3afaf2f298526cf34958d5fb61d2e14491"
}

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