@wellesley/ws 1.0.442 → 1.0.444

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.mjs +3 -3
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import{useEffect as m,useRef as B,useState as G}from"https://cdn.jsdelivr.net/npm/react@18.2.0/+esm";import{useDispatch as $,useSelector as O}from"https://cdn.jsdelivr.net/npm/react-redux@9.1.0/+esm";import{createAction as Y,createSlice as Q}from"https://cdn.jsdelivr.net/npm/@reduxjs/toolkit@2.2.1/+esm";import{rootReducer as re}from"https://cdn.jsdelivr.net/npm/@wellesley/store@1.0.459";const ie=e=>{if("object"!=typeof e||null===e)return!1;let t=e;for(;null!==Object.getPrototypeOf(t);)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t||null===Object.getPrototypeOf(e)},oe=e=>ie(e)&&"type"in e&&"string"==typeof e.type,c=e=>{const t=t=>({type:e,payload:t});return t.toString=()=>`${e}`,t.type=e,t.match=t=>oe(t)&&t.type===e,t};c("remoteReady"),c("reselectUser"),c("requestLogin"),c("requestLogout"),c("setConfirmLeavePage"),c("requestChangePath");const ce=c("wsSubscribe"),ae=c("wsUnSubscribe");c("hostStoreConnect"),c("remoteLogin"),c("remoteLogout");const J=c("wsOnMessage");c("setRouterPath"),c("setDeviceType"),c("setUserError"),c("setUserIsError"),c("setUserPending"),c("setUserSuccess"),c("setUserData"),c("updateAccountData"),c("updateUser"),c("addNotification"),c("markNotification"),c("setNotificationsError"),c("setNotificationsList"),c("setNotificationsPending"),c("setNotificationsTotalCount"),c("setNotificationsUnreadCount"),c("resetNotificationsState"),c("undoNotification"),c("setInstanceInfo"),c("setInstanceInfoPending"),c("setInstanceInfoError"),c("setPlatformSettings"),c("setProfileSettings"),c("setGroupData"),c("setGroupLoading"),c("showGroupBasicInfo"),Y("requestMicroFrontendFetch"),Y("sendMicroFrontendFetchResponse");const g={messages:[],subscribers:[],unsubscribers:[]},E=Q({name:"ws",initialState:g,reducers:{reset:e=>{e.messages=g.messages,e.subscribers=g.subscribers,e.unsubscribers=g.unsubscribers},cleanMessages:e=>{e.messages=g.messages},onUnsubscribe:(e,{payload:t})=>{e.subscribers=e.subscribers.filter((e=>e.id!==t)),e.unsubscribers=e.unsubscribers.filter((e=>e.id!==t))}},extraReducers:e=>{e.addCase(ce,((e,{payload:t})=>{!e.subscribers.find((e=>e.id===t.id))&&e.subscribers.push(t)})).addCase(ae,((e,{payload:t})=>{const n=e.subscribers.find((e=>e.id===t));n&&e.unsubscribers.push(n)})).addCase(J,((e,{payload:t})=>{e.messages=[t,...e.messages.slice(0,100)]}))},selectors:{selectMessages:e=>e.messages,selectSubscribers:e=>e.subscribers,selectUnSubscribers:e=>e.unsubscribers,selectLastUpdateFor:(e,t)=>{var n;return null==(n=e.messages)?void 0:n.find((({topic:e})=>t.startsWith("feed:my")?e.startsWith(t):e===t))}}}).injectInto(re),b="8.48.0",d=globalThis;function T(e,t,n){const s=d,r=s.__SENTRY__=s.__SENTRY__||{},o=r[b]=r[b]||{};return o[e]||(o[e]=t())}const V=typeof __SENTRY_DEBUG__>"u"||__SENTRY_DEBUG__,ue="Sentry Logger ",D=["debug","info","warn","error","log","assert","trace"],R={};function le(e){if(!("console"in d))return e();const t=d.console,n={},s=Object.keys(R);s.forEach((e=>{const s=R[e];n[e]=t[e],t[e]=s}));try{return e()}finally{s.forEach((e=>{t[e]=n[e]}))}}function he(){let e=!1;const t={enable:()=>{e=!0},disable:()=>{e=!1},isEnabled:()=>e};return V?D.forEach((n=>{t[n]=(...t)=>{e&&le((()=>{d.console[n](`${ue}[${n}]:`,...t)}))}})):D.forEach((e=>{t[e]=()=>{}})),t}const w=T("logger",he);function P(){return N(d),d}function N(e){const t=e.__SENTRY__=e.__SENTRY__||{};return t.version=t.version||b,t[b]=t[b]||{}}const de=Object.prototype.toString;function fe(e,t){return de.call(e)===`[object ${t}]`}function pe(e){return fe(e,"Object")}function _e(e){return!(!e||!e.then||"function"!=typeof e.then)}function ge(e,t,n){try{Object.defineProperty(e,t,{value:n,writable:!0,configurable:!0})}catch{V&&w.log(`Failed to add non-enumerable property "${t}" to object`,e)}}const K=1e3;function H(){return Date.now()/K}function be(){const{performance:e}=d;if(!e||!e.now)return H;const t=Date.now()-e.now(),n=null==e.timeOrigin?t:e.timeOrigin;return()=>(n+e.now())/K}const me=be();function p(){const e=d,t=e.crypto||e.msCrypto;let n=()=>16*Math.random();try{if(t&&t.randomUUID)return t.randomUUID().replace(/-/g,"");t&&t.getRandomValues&&(n=()=>{const e=new Uint8Array(1);return t.getRandomValues(e),e[0]})}catch{}return"10000000100040008000100000000000".replace(/[018]/g,(e=>(e^(15&n())>>e/4).toString(16)))}function ye(e,t={}){if(t.user&&(!e.ipAddress&&t.user.ip_address&&(e.ipAddress=t.user.ip_address),!e.did&&!t.did&&(e.did=t.user.id||t.user.email||t.user.username)),e.timestamp=t.timestamp||me(),t.abnormal_mechanism&&(e.abnormal_mechanism=t.abnormal_mechanism),t.ignoreDuration&&(e.ignoreDuration=t.ignoreDuration),t.sid&&(e.sid=32===t.sid.length?t.sid:p()),void 0!==t.init&&(e.init=t.init),!e.did&&t.did&&(e.did=`${t.did}`),"number"==typeof t.started&&(e.started=t.started),e.ignoreDuration)e.duration=void 0;else if("number"==typeof t.duration)e.duration=t.duration;else{const t=e.timestamp-e.started;e.duration=t>=0?t:0}t.release&&(e.release=t.release),t.environment&&(e.environment=t.environment),!e.ipAddress&&t.ipAddress&&(e.ipAddress=t.ipAddress),!e.userAgent&&t.userAgent&&(e.userAgent=t.userAgent),"number"==typeof t.errors&&(e.errors=t.errors),t.status&&(e.status=t.status)}function A(){return p()}function U(){return p().substring(16)}function X(e,t,n=2){if(!t||"object"!=typeof t||n<=0)return t;if(e&&t&&0===Object.keys(t).length)return e;const s={...e};for(const e in t)Object.prototype.hasOwnProperty.call(t,e)&&(s[e]=X(s[e],t[e],n-1));return s}(()=>{const{performance:e}=d;if(!e||!e.now)return;const t=36e5,n=e.now(),s=Date.now(),r=e.timeOrigin?Math.abs(e.timeOrigin+n-s):t,o=r<t,i=e.timing&&e.timing.navigationStart,c="number"==typeof i?Math.abs(i+n-s):t;(o||c<t)&&(r<=c&&e.timeOrigin)})();const L="_sentrySpan";function M(e,t){t?ge(e,L,t):delete e[L]}function F(e){return e[L]}const Se=100;class I{constructor(){this._notifyingListeners=!1,this._scopeListeners=[],this._eventProcessors=[],this._breadcrumbs=[],this._attachments=[],this._user={},this._tags={},this._extra={},this._contexts={},this._sdkProcessingMetadata={},this._propagationContext={traceId:A(),spanId:U()}}clone(){const e=new I;return e._breadcrumbs=[...this._breadcrumbs],e._tags={...this._tags},e._extra={...this._extra},e._contexts={...this._contexts},this._contexts.flags&&(e._contexts.flags={values:[...this._contexts.flags.values]}),e._user=this._user,e._level=this._level,e._session=this._session,e._transactionName=this._transactionName,e._fingerprint=this._fingerprint,e._eventProcessors=[...this._eventProcessors],e._requestSession=this._requestSession,e._attachments=[...this._attachments],e._sdkProcessingMetadata={...this._sdkProcessingMetadata},e._propagationContext={...this._propagationContext},e._client=this._client,e._lastEventId=this._lastEventId,M(e,F(this)),e}setClient(e){this._client=e}setLastEventId(e){this._lastEventId=e}getClient(){return this._client}lastEventId(){return this._lastEventId}addScopeListener(e){this._scopeListeners.push(e)}addEventProcessor(e){return this._eventProcessors.push(e),this}setUser(e){return this._user=e||{email:void 0,id:void 0,ip_address:void 0,username:void 0},this._session&&ye(this._session,{user:e}),this._notifyScopeListeners(),this}getUser(){return this._user}getRequestSession(){return this._requestSession}setRequestSession(e){return this._requestSession=e,this}setTags(e){return this._tags={...this._tags,...e},this._notifyScopeListeners(),this}setTag(e,t){return this._tags={...this._tags,[e]:t},this._notifyScopeListeners(),this}setExtras(e){return this._extra={...this._extra,...e},this._notifyScopeListeners(),this}setExtra(e,t){return this._extra={...this._extra,[e]:t},this._notifyScopeListeners(),this}setFingerprint(e){return this._fingerprint=e,this._notifyScopeListeners(),this}setLevel(e){return this._level=e,this._notifyScopeListeners(),this}setTransactionName(e){return this._transactionName=e,this._notifyScopeListeners(),this}setContext(e,t){return null===t?delete this._contexts[e]:this._contexts[e]=t,this._notifyScopeListeners(),this}setSession(e){return e?this._session=e:delete this._session,this._notifyScopeListeners(),this}getSession(){return this._session}update(e){if(!e)return this;const t="function"==typeof e?e(this):e,[n,s]=t instanceof y?[t.getScopeData(),t.getRequestSession()]:pe(t)?[e,e.requestSession]:[],{tags:r,extra:o,user:i,contexts:c,level:a,fingerprint:u=[],propagationContext:h}=n||{};return this._tags={...this._tags,...r},this._extra={...this._extra,...o},this._contexts={...this._contexts,...c},i&&Object.keys(i).length&&(this._user=i),a&&(this._level=a),u.length&&(this._fingerprint=u),h&&(this._propagationContext=h),s&&(this._requestSession=s),this}clear(){return this._breadcrumbs=[],this._tags={},this._extra={},this._user={},this._contexts={},this._level=void 0,this._transactionName=void 0,this._fingerprint=void 0,this._requestSession=void 0,this._session=void 0,M(this,void 0),this._attachments=[],this.setPropagationContext({traceId:A()}),this._notifyScopeListeners(),this}addBreadcrumb(e,t){const n="number"==typeof t?t:Se;if(n<=0)return this;const s={timestamp:H(),...e},r=this._breadcrumbs;return r.push(s),this._breadcrumbs=r.length>n?r.slice(-n):r,this._notifyScopeListeners(),this}getLastBreadcrumb(){return this._breadcrumbs[this._breadcrumbs.length-1]}clearBreadcrumbs(){return this._breadcrumbs=[],this._notifyScopeListeners(),this}addAttachment(e){return this._attachments.push(e),this}clearAttachments(){return this._attachments=[],this}getScopeData(){return{breadcrumbs:this._breadcrumbs,attachments:this._attachments,contexts:this._contexts,tags:this._tags,extra:this._extra,user:this._user,level:this._level,fingerprint:this._fingerprint||[],eventProcessors:this._eventProcessors,propagationContext:this._propagationContext,sdkProcessingMetadata:this._sdkProcessingMetadata,transactionName:this._transactionName,span:F(this)}}setSDKProcessingMetadata(e){return this._sdkProcessingMetadata=X(this._sdkProcessingMetadata,e,2),this}setPropagationContext(e){return this._propagationContext={spanId:U(),...e},this}getPropagationContext(){return this._propagationContext}captureException(e,t){const n=t&&t.event_id?t.event_id:p();if(!this._client)return w.warn("No client configured on scope - will not capture exception!"),n;const s=new Error("Sentry syntheticException");return this._client.captureException(e,{originalException:e,syntheticException:s,...t,event_id:n},this),n}captureMessage(e,t,n){const s=n&&n.event_id?n.event_id:p();if(!this._client)return w.warn("No client configured on scope - will not capture message!"),s;const r=new Error(e);return this._client.captureMessage(e,t,{originalException:e,syntheticException:r,...n,event_id:s},this),s}captureEvent(e,t){const n=t&&t.event_id?t.event_id:p();return this._client?(this._client.captureEvent(e,{...t,event_id:n},this),n):(w.warn("No client configured on scope - will not capture event!"),n)}_notifyScopeListeners(){this._notifyingListeners||(this._notifyingListeners=!0,this._scopeListeners.forEach((e=>{e(this)})),this._notifyingListeners=!1)}}const y=I;function ve(){return T("defaultCurrentScope",(()=>new y))}function we(){return T("defaultIsolationScope",(()=>new y))}class Ee{constructor(e,t){let n,s;n=e||new y,s=t||new y,this._stack=[{scope:n}],this._isolationScope=s}withScope(e){const t=this._pushScope();let n;try{n=e(t)}catch(e){throw this._popScope(),e}return _e(n)?n.then((e=>(this._popScope(),e)),(e=>{throw this._popScope(),e})):(this._popScope(),n)}getClient(){return this.getStackTop().client}getScope(){return this.getStackTop().scope}getIsolationScope(){return this._isolationScope}getStackTop(){return this._stack[this._stack.length-1]}_pushScope(){const e=this.getScope().clone();return this._stack.push({client:this.getClient(),scope:e}),e}_popScope(){return!(this._stack.length<=1)&&!!this._stack.pop()}}function _(){const e=N(P());return e.stack=e.stack||new Ee(ve(),we())}function Le(e){return _().withScope(e)}function Ce(e,t){const n=_();return n.withScope((()=>(n.getStackTop().scope=e,t(e))))}function j(e){return _().withScope((()=>e(_().getIsolationScope())))}function Oe(){return{withIsolationScope:j,withScope:Le,withSetScope:Ce,withSetIsolationScope:(e,t)=>j(t),getCurrentScope:()=>_().getScope(),getIsolationScope:()=>_().getIsolationScope()}}function z(e){const t=N(e);return t.acs?t.acs:Oe()}function Z(){return z(P()).getCurrentScope()}function Te(){return z(P()).getIsolationScope()}function Pe(e,t){return Z().captureException(e,void 0)}function Ne(e,t){const n={captureContext:t};return Z().captureMessage(e,void 0,n)}function Ie(e,t){Te().setExtra(e,t)}const xe=(...e)=>{let t="";for(const n of e){if(n instanceof Error){const e=n;return Ie("exceptionMessage",t),void Pe(e)}if("object"!=typeof n)t+=n;else try{t+=" "+JSON.stringify(n)}catch{t+=" "+n}}Ne(t)},ke=()=>"object"!=typeof window,W=["debug","info","warn","error"],De=(e,t)=>{const n=W.indexOf(e);return W.indexOf(t)>=n},v=(e,t,n,...s)=>{De(t,e)&&console.log(`[${e}] ${n}`,...s)},Re=()=>null==window?void 0:window.localStorage.getItem("logger_lvl"),Ae=(e=(ke()?"info":Re()||"warn"))=>{let t=e;return{debug:(e,...n)=>v("debug",t,e,...n),info:(e,...n)=>v("info",t,e,...n),warn:(e,...n)=>v("warn",t,e,...n),error:(e,...n)=>(xe(e,...n),v("error",t,e,...n)),setLevel:e=>{t=e},getLevel:()=>t}},h=Ae(),ee=e=>[...new Set(e.flatMap((e=>e.topics)))],Ue=({isReady:e,socket:t,serverSubscriptions:n})=>{const s=$(),r=O(E.selectors.selectUnSubscribers);m((()=>{var o;if(e&&t){const e=ee(r);if(0===e.length)return;try{t.send(JSON.stringify({type:"UNSUBSCRIBE",topics:e})),n.current=null==(o=n.current)?void 0:o.filter((e=>!r.find((t=>t.id===e.id)))),h.debug("WebSocket unsubscribed from: ",e)}catch(e){h.error("WebSocket error when send: ",e)}}r.forEach((e=>{s(E.actions.onUnsubscribe(e.id))}))}),[r,t,e])},Me=({isReady:e,socket:t,serverSubscriptions:n})=>{const s=O(E.selectors.selectSubscribers);m((()=>{var r;if(e){h.debug("WebSocket subscribers list: ",s);const e=s.filter((e=>{var t;return!(null!=(t=n.current)&&t.includes(e))})),o=ee(e);if(o.length>0)try{null==t||t.send(JSON.stringify({type:"SUBSCRIBE",topics:o})),null==(r=n.current)||r.push(...e),h.debug("WebSocket subscribed to: ",o)}catch(e){h.error("WebSocket error when send: ",e)}}}),[e,s])},Fe=e=>{switch(e.code){case 1e3:return"Normal closure, meaning that the purpose for which the connection was established has been fulfilled.";case 1001:return"An endpoint is 'going away', such as a server going down or a browser having navigated away from a page.";case 1002:return"An endpoint is terminating the connection due to a protocol error.";case 1003:return"An endpoint is terminating the connection because it has received a type of data it cannot accept (e.g., an endpoint that understands only text data MAY send this if it receives a binary message).";case 1004:return"Reserved. The specific meaning might be defined in the future.";case 1005:return"No status code was actually present.";case 1006:return"The connection was closed abnormally, e.g., without sending or receiving a Close control frame.";case 1007:return"An endpoint is terminating the connection because it has received data within a message that was not consistent with the type of the message (e.g., non-UTF-8 data within a text message).";case 1008:return"An endpoint is terminating the connection because it has received a message that 'violates its policy'. This reason is given either if there is no other suitable reason, or if there is a need to hide specific details about the policy.";case 1009:return"An endpoint is terminating the connection because it has received a message that is too big for it to process.";case 1010:return`An endpoint (client) is terminating the connection because it has expected the server to negotiate one or more extension, but the server didn't return them in the response message of the WebSocket handshake. Specifically, the extensions that are needed are: ${e.reason}`;case 1011:return"A server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request.";case 1015:return"The connection was closed due to a failure to perform a TLS handshake (e.g., the server certificate can't be verified).";default:return"Unknown reason."}},je=({onReady:e,socket:t,serverSubscriptions:n})=>{const s=$();m((()=>{t&&(t.onopen=()=>{n.current=[],e(!0),h.info("Connected to WebSocket server")},t.onmessage=e=>{h.debug("WebSocket receive message: ",JSON.parse(e.data));try{s(J({...JSON.parse(e.data),date:(new Date).toISOString()}))}catch(e){h.error("WebSocket:onmessage:parse: ",e)}},t.onclose=t=>{e(!1),h.info("Disconnected from WebSocket server:",Fe(t))},t.onerror=t=>{e(!1),h.error("WebSocket error:",t)})}),[t])};
1
+ import{useEffect as v,useRef as J,useState as Y}from"https://cdn.jsdelivr.net/npm/react@18.2.0/+esm";import{useDispatch as Q,useSelector as N}from"https://cdn.jsdelivr.net/npm/react-redux@9.1.0/+esm";import{createAction as K,createSlice as V}from"https://cdn.jsdelivr.net/npm/@reduxjs/toolkit@2.2.1/+esm";import{rootReducer as ue}from"https://cdn.jsdelivr.net/npm/@wellesley/store@1.0.461";const le=e=>{if("object"!=typeof e||null===e)return!1;let t=e;for(;null!==Object.getPrototypeOf(t);)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t||null===Object.getPrototypeOf(e)},he=e=>le(e)&&"type"in e&&"string"==typeof e.type,c=e=>{const t=t=>({type:e,payload:t});return t.toString=()=>`${e}`,t.type=e,t.match=t=>he(t)&&t.type===e,t};c("remoteReady"),c("reselectUser"),c("requestLogin"),c("requestLogout"),c("setConfirmLeavePage"),c("requestChangePath");const de=c("wsSubscribe"),fe=c("wsUnSubscribe");c("hostStoreConnect"),c("remoteLogin"),c("remoteLogout");const X=c("wsOnMessage");c("setRouterPath"),c("setDeviceType"),c("setUserError"),c("setUserIsError"),c("setUserPending"),c("setUserSuccess"),c("setUserData"),c("updateAccountData"),c("updateUser"),c("addNotification"),c("markNotification"),c("setNotificationsError"),c("setNotificationsList"),c("setNotificationsPending"),c("setNotificationsTotalCount"),c("setNotificationsUnreadCount"),c("resetNotificationsState"),c("undoNotification"),c("setInstanceInfo"),c("setInstanceInfoPending"),c("setInstanceInfoError"),c("setPlatformSettings"),c("setProfileSettings"),c("setGroupData"),c("setGroupLoading"),c("showGroupBasicInfo"),K("requestMicroFrontendFetch"),K("sendMicroFrontendFetchResponse");const y={messages:[],subscribers:[],unsubscribers:[]},O=V({name:"ws",initialState:y,reducers:{reset:e=>{e.messages=y.messages,e.subscribers=y.subscribers,e.unsubscribers=y.unsubscribers},cleanMessages:e=>{e.messages=y.messages},onUnsubscribe:(e,{payload:t})=>{e.subscribers=e.subscribers.filter((e=>e.id!==t)),e.unsubscribers=e.unsubscribers.filter((e=>e.id!==t))}},extraReducers:e=>{e.addCase(de,((e,{payload:t})=>{!e.subscribers.find((e=>e.id===t.id))&&e.subscribers.push(t)})).addCase(fe,((e,{payload:t})=>{const n=e.subscribers.find((e=>e.id===t));n&&e.unsubscribers.push(n)})).addCase(X,((e,{payload:t})=>{e.messages=[t,...e.messages.slice(0,100)]}))},selectors:{selectMessages:e=>e.messages,selectSubscribers:e=>e.subscribers,selectUnSubscribers:e=>e.unsubscribers,selectLastUpdateFor:(e,t)=>{var n;return null==(n=e.messages)?void 0:n.find((({topic:e})=>t.startsWith("feed:my")||t.startsWith("events:feed")?e.startsWith(t):e===t))}}}).injectInto(ue),S="8.48.0",f=globalThis;function I(e,t,n){const s=f,r=s.__SENTRY__=s.__SENTRY__||{},o=r[S]=r[S]||{};return o[e]||(o[e]=t())}const H=typeof __SENTRY_DEBUG__>"u"||__SENTRY_DEBUG__,pe="Sentry Logger ",U=["debug","info","warn","error","log","assert","trace"],M={};function _e(e){if(!("console"in f))return e();const t=f.console,n={},s=Object.keys(M);s.forEach((e=>{const s=M[e];n[e]=t[e],t[e]=s}));try{return e()}finally{s.forEach((e=>{t[e]=n[e]}))}}function ge(){let e=!1;const t={enable:()=>{e=!0},disable:()=>{e=!1},isEnabled:()=>e};return H?U.forEach((n=>{t[n]=(...t)=>{e&&_e((()=>{f.console[n](`${pe}[${n}]:`,...t)}))}})):U.forEach((e=>{t[e]=()=>{}})),t}const L=I("logger",ge);function k(){return x(f),f}function x(e){const t=e.__SENTRY__=e.__SENTRY__||{};return t.version=t.version||S,t[S]=t[S]||{}}const me=Object.prototype.toString;function be(e,t){return me.call(e)===`[object ${t}]`}function ye(e){return be(e,"Object")}function Se(e){return!(!e||!e.then||"function"!=typeof e.then)}function ve(e,t,n){try{Object.defineProperty(e,t,{value:n,writable:!0,configurable:!0})}catch{H&&L.log(`Failed to add non-enumerable property "${t}" to object`,e)}}const z=1e3;function Z(){return Date.now()/z}function we(){const{performance:e}=f;if(!e||!e.now)return Z;const t=Date.now()-e.now(),n=null==e.timeOrigin?t:e.timeOrigin;return()=>(n+e.now())/z}const Ee=we();function g(){const e=f,t=e.crypto||e.msCrypto;let n=()=>16*Math.random();try{if(t&&t.randomUUID)return t.randomUUID().replace(/-/g,"");t&&t.getRandomValues&&(n=()=>{const e=new Uint8Array(1);return t.getRandomValues(e),e[0]})}catch{}return"10000000100040008000100000000000".replace(/[018]/g,(e=>(e^(15&n())>>e/4).toString(16)))}function Le(e,t={}){if(t.user&&(!e.ipAddress&&t.user.ip_address&&(e.ipAddress=t.user.ip_address),!e.did&&!t.did&&(e.did=t.user.id||t.user.email||t.user.username)),e.timestamp=t.timestamp||Ee(),t.abnormal_mechanism&&(e.abnormal_mechanism=t.abnormal_mechanism),t.ignoreDuration&&(e.ignoreDuration=t.ignoreDuration),t.sid&&(e.sid=32===t.sid.length?t.sid:g()),void 0!==t.init&&(e.init=t.init),!e.did&&t.did&&(e.did=`${t.did}`),"number"==typeof t.started&&(e.started=t.started),e.ignoreDuration)e.duration=void 0;else if("number"==typeof t.duration)e.duration=t.duration;else{const t=e.timestamp-e.started;e.duration=t>=0?t:0}t.release&&(e.release=t.release),t.environment&&(e.environment=t.environment),!e.ipAddress&&t.ipAddress&&(e.ipAddress=t.ipAddress),!e.userAgent&&t.userAgent&&(e.userAgent=t.userAgent),"number"==typeof t.errors&&(e.errors=t.errors),t.status&&(e.status=t.status)}function F(){return g()}function W(){return g().substring(16)}function ee(e,t,n=2){if(!t||"object"!=typeof t||n<=0)return t;if(e&&t&&0===Object.keys(t).length)return e;const s={...e};for(const e in t)Object.prototype.hasOwnProperty.call(t,e)&&(s[e]=ee(s[e],t[e],n-1));return s}(()=>{const{performance:e}=f;if(!e||!e.now)return;const t=36e5,n=e.now(),s=Date.now(),r=e.timeOrigin?Math.abs(e.timeOrigin+n-s):t,o=r<t,i=e.timing&&e.timing.navigationStart,c="number"==typeof i?Math.abs(i+n-s):t;(o||c<t)&&(r<=c&&e.timeOrigin)})();const T="_sentrySpan";function j(e,t){t?ve(e,T,t):delete e[T]}function $(e){return e[T]}const Ce=100;class R{constructor(){this._notifyingListeners=!1,this._scopeListeners=[],this._eventProcessors=[],this._breadcrumbs=[],this._attachments=[],this._user={},this._tags={},this._extra={},this._contexts={},this._sdkProcessingMetadata={},this._propagationContext={traceId:F(),spanId:W()}}clone(){const e=new R;return e._breadcrumbs=[...this._breadcrumbs],e._tags={...this._tags},e._extra={...this._extra},e._contexts={...this._contexts},this._contexts.flags&&(e._contexts.flags={values:[...this._contexts.flags.values]}),e._user=this._user,e._level=this._level,e._session=this._session,e._transactionName=this._transactionName,e._fingerprint=this._fingerprint,e._eventProcessors=[...this._eventProcessors],e._requestSession=this._requestSession,e._attachments=[...this._attachments],e._sdkProcessingMetadata={...this._sdkProcessingMetadata},e._propagationContext={...this._propagationContext},e._client=this._client,e._lastEventId=this._lastEventId,j(e,$(this)),e}setClient(e){this._client=e}setLastEventId(e){this._lastEventId=e}getClient(){return this._client}lastEventId(){return this._lastEventId}addScopeListener(e){this._scopeListeners.push(e)}addEventProcessor(e){return this._eventProcessors.push(e),this}setUser(e){return this._user=e||{email:void 0,id:void 0,ip_address:void 0,username:void 0},this._session&&Le(this._session,{user:e}),this._notifyScopeListeners(),this}getUser(){return this._user}getRequestSession(){return this._requestSession}setRequestSession(e){return this._requestSession=e,this}setTags(e){return this._tags={...this._tags,...e},this._notifyScopeListeners(),this}setTag(e,t){return this._tags={...this._tags,[e]:t},this._notifyScopeListeners(),this}setExtras(e){return this._extra={...this._extra,...e},this._notifyScopeListeners(),this}setExtra(e,t){return this._extra={...this._extra,[e]:t},this._notifyScopeListeners(),this}setFingerprint(e){return this._fingerprint=e,this._notifyScopeListeners(),this}setLevel(e){return this._level=e,this._notifyScopeListeners(),this}setTransactionName(e){return this._transactionName=e,this._notifyScopeListeners(),this}setContext(e,t){return null===t?delete this._contexts[e]:this._contexts[e]=t,this._notifyScopeListeners(),this}setSession(e){return e?this._session=e:delete this._session,this._notifyScopeListeners(),this}getSession(){return this._session}update(e){if(!e)return this;const t="function"==typeof e?e(this):e,[n,s]=t instanceof w?[t.getScopeData(),t.getRequestSession()]:ye(t)?[e,e.requestSession]:[],{tags:r,extra:o,user:i,contexts:c,level:a,fingerprint:u=[],propagationContext:l}=n||{};return this._tags={...this._tags,...r},this._extra={...this._extra,...o},this._contexts={...this._contexts,...c},i&&Object.keys(i).length&&(this._user=i),a&&(this._level=a),u.length&&(this._fingerprint=u),l&&(this._propagationContext=l),s&&(this._requestSession=s),this}clear(){return this._breadcrumbs=[],this._tags={},this._extra={},this._user={},this._contexts={},this._level=void 0,this._transactionName=void 0,this._fingerprint=void 0,this._requestSession=void 0,this._session=void 0,j(this,void 0),this._attachments=[],this.setPropagationContext({traceId:F()}),this._notifyScopeListeners(),this}addBreadcrumb(e,t){const n="number"==typeof t?t:Ce;if(n<=0)return this;const s={timestamp:Z(),...e},r=this._breadcrumbs;return r.push(s),this._breadcrumbs=r.length>n?r.slice(-n):r,this._notifyScopeListeners(),this}getLastBreadcrumb(){return this._breadcrumbs[this._breadcrumbs.length-1]}clearBreadcrumbs(){return this._breadcrumbs=[],this._notifyScopeListeners(),this}addAttachment(e){return this._attachments.push(e),this}clearAttachments(){return this._attachments=[],this}getScopeData(){return{breadcrumbs:this._breadcrumbs,attachments:this._attachments,contexts:this._contexts,tags:this._tags,extra:this._extra,user:this._user,level:this._level,fingerprint:this._fingerprint||[],eventProcessors:this._eventProcessors,propagationContext:this._propagationContext,sdkProcessingMetadata:this._sdkProcessingMetadata,transactionName:this._transactionName,span:$(this)}}setSDKProcessingMetadata(e){return this._sdkProcessingMetadata=ee(this._sdkProcessingMetadata,e,2),this}setPropagationContext(e){return this._propagationContext={spanId:W(),...e},this}getPropagationContext(){return this._propagationContext}captureException(e,t){const n=t&&t.event_id?t.event_id:g();if(!this._client)return L.warn("No client configured on scope - will not capture exception!"),n;const s=new Error("Sentry syntheticException");return this._client.captureException(e,{originalException:e,syntheticException:s,...t,event_id:n},this),n}captureMessage(e,t,n){const s=n&&n.event_id?n.event_id:g();if(!this._client)return L.warn("No client configured on scope - will not capture message!"),s;const r=new Error(e);return this._client.captureMessage(e,t,{originalException:e,syntheticException:r,...n,event_id:s},this),s}captureEvent(e,t){const n=t&&t.event_id?t.event_id:g();return this._client?(this._client.captureEvent(e,{...t,event_id:n},this),n):(L.warn("No client configured on scope - will not capture event!"),n)}_notifyScopeListeners(){this._notifyingListeners||(this._notifyingListeners=!0,this._scopeListeners.forEach((e=>{e(this)})),this._notifyingListeners=!1)}}const w=R;function Oe(){return I("defaultCurrentScope",(()=>new w))}function Te(){return I("defaultIsolationScope",(()=>new w))}class Pe{constructor(e,t){let n,s;n=e||new w,s=t||new w,this._stack=[{scope:n}],this._isolationScope=s}withScope(e){const t=this._pushScope();let n;try{n=e(t)}catch(e){throw this._popScope(),e}return Se(n)?n.then((e=>(this._popScope(),e)),(e=>{throw this._popScope(),e})):(this._popScope(),n)}getClient(){return this.getStackTop().client}getScope(){return this.getStackTop().scope}getIsolationScope(){return this._isolationScope}getStackTop(){return this._stack[this._stack.length-1]}_pushScope(){const e=this.getScope().clone();return this._stack.push({client:this.getClient(),scope:e}),e}_popScope(){return!(this._stack.length<=1)&&!!this._stack.pop()}}function m(){const e=x(k());return e.stack=e.stack||new Pe(Oe(),Te())}function Ne(e){return m().withScope(e)}function Ie(e,t){const n=m();return n.withScope((()=>(n.getStackTop().scope=e,t(e))))}function q(e){return m().withScope((()=>e(m().getIsolationScope())))}function ke(){return{withIsolationScope:q,withScope:Ne,withSetScope:Ie,withSetIsolationScope:(e,t)=>q(t),getCurrentScope:()=>m().getScope(),getIsolationScope:()=>m().getIsolationScope()}}function te(e){const t=x(e);return t.acs?t.acs:ke()}function ne(){return te(k()).getCurrentScope()}function xe(){return te(k()).getIsolationScope()}function Re(e,t){return ne().captureException(e,void 0)}function De(e,t){const n={captureContext:t};return ne().captureMessage(e,void 0,n)}function Ae(e,t){xe().setExtra(e,t)}const Ue=(...e)=>{let t="";for(const n of e){if(n instanceof Error){const e=n;return Ae("exceptionMessage",t),void Re(e)}if("object"!=typeof n)t+=n;else try{t+=" "+JSON.stringify(n)}catch{t+=" "+n}}De(t)},Me=()=>"object"!=typeof window,Fe="wlsy",se=()=>{try{return window.localStorage}catch(e){console.warn("Error getting window.localStorage storage",e)}},We=()=>{const e=new Set,t=se();if(!t)return[];for(let n=0;n<(null==t?void 0:t.length);n+=1){const s=null==t?void 0:t.key(n);"string"==typeof s&&e.add(s)}return Array.from(e)},re=e=>{const t=`${Fe}${e?`:${e}`:""}`,n=e=>`${t}:${e}`,s=()=>We().filter((e=>e.startsWith(`${t}:`))),r=e=>e.slice(t.length+1),o=se(),i=e=>{try{return null==o?void 0:o.getItem(n(e))}catch{return null}},c=(e,t)=>{try{null==o||o.setItem(n(e),String(t))}catch{return}};return{getItem:i,setItem:c,removeItem:e=>{try{null==o||o.removeItem(n(e))}catch{return}},clear:()=>{try{s().forEach((e=>null==o?void 0:o.removeItem(e)))}catch{return}},keys:()=>s().map(r),has:e=>null!==i(e),getJSON:e=>{const t=i(e);if(null==t)return null;try{return JSON.parse(t)}catch{return null}},setJSON:(e,t)=>{try{c(e,JSON.stringify(t))}catch{return}}}},B=["debug","info","warn","error"],je=(e,t)=>{const n=B.indexOf(e);return B.indexOf(t)>=n},E=(e,t,n,...s)=>{je(t,e)&&console.log(`[${e}] ${n}`,...s)},$e=()=>re().getItem("logger_lvl"),qe=(e=(Me()?"info":$e()||"warn"))=>{let t=e;return{debug:(e,...n)=>E("debug",t,e,...n),info:(e,...n)=>E("info",t,e,...n),warn:(e,...n)=>E("warn",t,e,...n),error:(e,...n)=>(Ue(e,...n),E("error",t,e,...n)),setLevel:e=>{t=e},getLevel:()=>t}},d=qe(),ie=e=>[...new Set(e.flatMap((e=>e.topics)))],Be=({isReady:e,socket:t,serverSubscriptions:n})=>{const s=Q(),r=N(O.selectors.selectUnSubscribers);v((()=>{var o;if(e&&t){const e=ie(r);if(0===e.length)return;try{t.send(JSON.stringify({type:"UNSUBSCRIBE",topics:e})),n.current=null==(o=n.current)?void 0:o.filter((e=>!r.find((t=>t.id===e.id)))),d.debug("WebSocket unsubscribed from: ",e)}catch(e){d.error("WebSocket error when send: ",e)}}r.forEach((e=>{s(O.actions.onUnsubscribe(e.id))}))}),[r,t,e])},Ge=({isReady:e,socket:t,serverSubscriptions:n})=>{const s=N(O.selectors.selectSubscribers);v((()=>{var r;if(e){d.debug("WebSocket subscribers list: ",s);const e=s.filter((e=>{var t;return!(null!=(t=n.current)&&t.includes(e))})),o=ie(e);if(o.length>0)try{null==t||t.send(JSON.stringify({type:"SUBSCRIBE",topics:o})),null==(r=n.current)||r.push(...e),d.debug("WebSocket subscribed to: ",o)}catch(e){d.error("WebSocket error when send: ",e)}}}),[e,s])},Je=e=>{switch(e.code){case 1e3:return"Normal closure, meaning that the purpose for which the connection was established has been fulfilled.";case 1001:return"An endpoint is 'going away', such as a server going down or a browser having navigated away from a page.";case 1002:return"An endpoint is terminating the connection due to a protocol error.";case 1003:return"An endpoint is terminating the connection because it has received a type of data it cannot accept (e.g., an endpoint that understands only text data MAY send this if it receives a binary message).";case 1004:return"Reserved. The specific meaning might be defined in the future.";case 1005:return"No status code was actually present.";case 1006:return"The connection was closed abnormally, e.g., without sending or receiving a Close control frame.";case 1007:return"An endpoint is terminating the connection because it has received data within a message that was not consistent with the type of the message (e.g., non-UTF-8 data within a text message).";case 1008:return"An endpoint is terminating the connection because it has received a message that 'violates its policy'. This reason is given either if there is no other suitable reason, or if there is a need to hide specific details about the policy.";case 1009:return"An endpoint is terminating the connection because it has received a message that is too big for it to process.";case 1010:return`An endpoint (client) is terminating the connection because it has expected the server to negotiate one or more extension, but the server didn't return them in the response message of the WebSocket handshake. Specifically, the extensions that are needed are: ${e.reason}`;case 1011:return"A server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request.";case 1015:return"The connection was closed due to a failure to perform a TLS handshake (e.g., the server certificate can't be verified).";default:return"Unknown reason."}},Ye=({onReady:e,socket:t,serverSubscriptions:n})=>{const s=Q();v((()=>{t&&(t.onopen=()=>{n.current=[],e(!0),d.info("Connected to WebSocket server")},t.onmessage=e=>{d.debug("WebSocket receive message: ",JSON.parse(e.data));try{s(X({...JSON.parse(e.data),date:(new Date).toISOString()}))}catch(e){d.error("WebSocket:onmessage:parse: ",e)}},t.onclose=t=>{e(!1),d.info("Disconnected from WebSocket server:",Je(t))},t.onerror=t=>{e(!1),d.error("WebSocket error:",t)})}),[t])};
2
2
  /*! *****************************************************************************
3
3
  Copyright (c) Microsoft Corporation. All rights reserved.
4
4
  Licensed under the Apache License, Version 2.0 (the "License"); you may not use
@@ -12,10 +12,10 @@ MERCHANTABLITY OR NON-INFRINGEMENT.
12
12
 
13
13
  See the Apache Version 2.0 License for specific language governing permissions
14
14
  and limitations under the License.
15
- ***************************************************************************** */var C=function(e,t){return(C=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};function te(e,t){function n(){this.constructor=e}C(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function We(e){var t="function"==typeof Symbol&&e[Symbol.iterator],n=0;return t?t.call(e):{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}}}function qe(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var s,r,o=n.call(e),i=[];try{for(;(void 0===t||t-- >0)&&!(s=o.next()).done;)i.push(s.value)}catch(e){r={error:e}}finally{try{s&&!s.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}return i}function Be(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(qe(arguments[t]));return e}var ne=function(){return function(e,t){this.target=t,this.type=e}}(),Ge=function(e){function t(t,n){var s=e.call(this,"error",n)||this;return s.message=t.message,s.error=t,s}return te(t,e),t}(ne),$e=function(e){function t(t,n,s){void 0===t&&(t=1e3),void 0===n&&(n="");var r=e.call(this,"close",s)||this;return r.wasClean=!0,r.code=t,r.reason=n,r}return te(t,e),t}(ne),Ye=function(){if(typeof WebSocket<"u")return WebSocket},Qe=function(e){return typeof e<"u"&&!!e&&2===e.CLOSING},f={maxReconnectionDelay:1e4,minReconnectionDelay:1e3+4e3*Math.random(),minUptime:5e3,reconnectionDelayGrowFactor:1.3,connectionTimeout:4e3,maxRetries:1/0,maxEnqueuedMessages:1/0,startClosed:!1,debug:!1},Je=function(){function e(e,t,n){var s=this;void 0===n&&(n={}),this._listeners={error:[],message:[],open:[],close:[]},this._retryCount=-1,this._shouldReconnect=!0,this._connectLock=!1,this._binaryType="blob",this._closeCalled=!1,this._messageQueue=[],this.onclose=null,this.onerror=null,this.onmessage=null,this.onopen=null,this._handleOpen=function(e){s._debug("open event");var t=s._options.minUptime,n=void 0===t?f.minUptime:t;clearTimeout(s._connectTimeout),s._uptimeTimeout=setTimeout((function(){return s._acceptOpen()}),n),s._ws.binaryType=s._binaryType,s._messageQueue.forEach((function(e){return s._ws.send(e)})),s._messageQueue=[],s.onopen&&s.onopen(e),s._listeners.open.forEach((function(t){return s._callEventListener(e,t)}))},this._handleMessage=function(e){s._debug("message event"),s.onmessage&&s.onmessage(e),s._listeners.message.forEach((function(t){return s._callEventListener(e,t)}))},this._handleError=function(e){s._debug("error event",e.message),s._disconnect(void 0,"TIMEOUT"===e.message?"timeout":void 0),s.onerror&&s.onerror(e),s._debug("exec error listeners"),s._listeners.error.forEach((function(t){return s._callEventListener(e,t)})),s._connect()},this._handleClose=function(e){s._debug("close event"),s._clearTimeouts(),s._shouldReconnect&&s._connect(),s.onclose&&s.onclose(e),s._listeners.close.forEach((function(t){return s._callEventListener(e,t)}))},this._url=e,this._protocols=t,this._options=n,this._options.startClosed&&(this._shouldReconnect=!1),this._connect()}return Object.defineProperty(e,"CONNECTING",{get:function(){return 0},enumerable:!0,configurable:!0}),Object.defineProperty(e,"OPEN",{get:function(){return 1},enumerable:!0,configurable:!0}),Object.defineProperty(e,"CLOSING",{get:function(){return 2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"CLOSED",{get:function(){return 3},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"CONNECTING",{get:function(){return e.CONNECTING},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"OPEN",{get:function(){return e.OPEN},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"CLOSING",{get:function(){return e.CLOSING},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"CLOSED",{get:function(){return e.CLOSED},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"binaryType",{get:function(){return this._ws?this._ws.binaryType:this._binaryType},set:function(e){this._binaryType=e,this._ws&&(this._ws.binaryType=e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"retryCount",{get:function(){return Math.max(this._retryCount,0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bufferedAmount",{get:function(){return this._messageQueue.reduce((function(e,t){return"string"==typeof t?e+=t.length:t instanceof Blob?e+=t.size:e+=t.byteLength,e}),0)+(this._ws?this._ws.bufferedAmount:0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"extensions",{get:function(){return this._ws?this._ws.extensions:""},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"protocol",{get:function(){return this._ws?this._ws.protocol:""},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"readyState",{get:function(){return this._ws?this._ws.readyState:this._options.startClosed?e.CLOSED:e.CONNECTING},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"url",{get:function(){return this._ws?this._ws.url:""},enumerable:!0,configurable:!0}),e.prototype.close=function(e,t){void 0===e&&(e=1e3),this._closeCalled=!0,this._shouldReconnect=!1,this._clearTimeouts(),this._ws?this._ws.readyState!==this.CLOSED?this._ws.close(e,t):this._debug("close: already closed"):this._debug("close enqueued: no ws instance")},e.prototype.reconnect=function(e,t){this._shouldReconnect=!0,this._closeCalled=!1,this._retryCount=-1,this._ws&&this._ws.readyState!==this.CLOSED?(this._disconnect(e,t),this._connect()):this._connect()},e.prototype.send=function(e){if(this._ws&&this._ws.readyState===this.OPEN)this._debug("send",e),this._ws.send(e);else{var t=this._options.maxEnqueuedMessages,n=void 0===t?f.maxEnqueuedMessages:t;this._messageQueue.length<n&&(this._debug("enqueue",e),this._messageQueue.push(e))}},e.prototype.addEventListener=function(e,t){this._listeners[e]&&this._listeners[e].push(t)},e.prototype.dispatchEvent=function(e){var t,n,s=this._listeners[e.type];if(s)try{for(var r=We(s),o=r.next();!o.done;o=r.next()){var i=o.value;this._callEventListener(e,i)}}catch(e){t={error:e}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(t)throw t.error}}return!0},e.prototype.removeEventListener=function(e,t){this._listeners[e]&&(this._listeners[e]=this._listeners[e].filter((function(e){return e!==t})))},e.prototype._debug=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._options.debug&&console.log.apply(console,Be(["RWS>"],e))},e.prototype._getNextDelay=function(){var e=this._options,t=e.reconnectionDelayGrowFactor,n=void 0===t?f.reconnectionDelayGrowFactor:t,s=e.minReconnectionDelay,r=void 0===s?f.minReconnectionDelay:s,o=e.maxReconnectionDelay,i=void 0===o?f.maxReconnectionDelay:o,c=0;return this._retryCount>0&&((c=r*Math.pow(n,this._retryCount-1))>i&&(c=i)),this._debug("next delay",c),c},e.prototype._wait=function(){var e=this;return new Promise((function(t){setTimeout(t,e._getNextDelay())}))},e.prototype._getNextUrl=function(e){if("string"==typeof e)return Promise.resolve(e);if("function"==typeof e){var t=e();if("string"==typeof t)return Promise.resolve(t);if(t.then)return t}throw Error("Invalid URL")},e.prototype._connect=function(){var e=this;if(!this._connectLock&&this._shouldReconnect){this._connectLock=!0;var t=this._options,n=t.maxRetries,s=void 0===n?f.maxRetries:n,r=t.connectionTimeout,o=void 0===r?f.connectionTimeout:r,i=t.WebSocket,c=void 0===i?Ye():i;if(this._retryCount>=s)return void this._debug("max retries reached",this._retryCount,">=",s);if(this._retryCount++,this._debug("connect",this._retryCount),this._removeListeners(),!Qe(c))throw Error("No valid WebSocket class provided");this._wait().then((function(){return e._getNextUrl(e._url)})).then((function(t){e._closeCalled||(e._debug("connect",{url:t,protocols:e._protocols}),e._ws=e._protocols?new c(t,e._protocols):new c(t),e._ws.binaryType=e._binaryType,e._connectLock=!1,e._addListeners(),e._connectTimeout=setTimeout((function(){return e._handleTimeout()}),o))}))}},e.prototype._handleTimeout=function(){this._debug("timeout event"),this._handleError(new Ge(Error("TIMEOUT"),this))},e.prototype._disconnect=function(e,t){if(void 0===e&&(e=1e3),this._clearTimeouts(),this._ws){this._removeListeners();try{this._ws.close(e,t),this._handleClose(new $e(e,t,this))}catch{}}},e.prototype._acceptOpen=function(){this._debug("accept open"),this._retryCount=0},e.prototype._callEventListener=function(e,t){"handleEvent"in t?t.handleEvent(e):t(e)},e.prototype._removeListeners=function(){this._ws&&(this._debug("removeListeners"),this._ws.removeEventListener("open",this._handleOpen),this._ws.removeEventListener("close",this._handleClose),this._ws.removeEventListener("message",this._handleMessage),this._ws.removeEventListener("error",this._handleError))},e.prototype._addListeners=function(){this._ws&&(this._debug("addListeners"),this._ws.addEventListener("open",this._handleOpen),this._ws.addEventListener("close",this._handleClose),this._ws.addEventListener("message",this._handleMessage),this._ws.addEventListener("error",this._handleError))},e.prototype._clearTimeouts=function(){clearTimeout(this._connectTimeout),clearTimeout(this._uptimeTimeout)},e}();
15
+ ***************************************************************************** */var P=function(e,t){return(P=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};function oe(e,t){function n(){this.constructor=e}P(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function Qe(e){var t="function"==typeof Symbol&&e[Symbol.iterator],n=0;return t?t.call(e):{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}}}function Ke(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var s,r,o=n.call(e),i=[];try{for(;(void 0===t||t-- >0)&&!(s=o.next()).done;)i.push(s.value)}catch(e){r={error:e}}finally{try{s&&!s.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}return i}function Ve(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(Ke(arguments[t]));return e}var ce=function(){return function(e,t){this.target=t,this.type=e}}(),Xe=function(e){function t(t,n){var s=e.call(this,"error",n)||this;return s.message=t.message,s.error=t,s}return oe(t,e),t}(ce),He=function(e){function t(t,n,s){void 0===t&&(t=1e3),void 0===n&&(n="");var r=e.call(this,"close",s)||this;return r.wasClean=!0,r.code=t,r.reason=n,r}return oe(t,e),t}(ce),ze=function(){if(typeof WebSocket<"u")return WebSocket},Ze=function(e){return typeof e<"u"&&!!e&&2===e.CLOSING},_={maxReconnectionDelay:1e4,minReconnectionDelay:1e3+4e3*Math.random(),minUptime:5e3,reconnectionDelayGrowFactor:1.3,connectionTimeout:4e3,maxRetries:1/0,maxEnqueuedMessages:1/0,startClosed:!1,debug:!1},et=function(){function e(e,t,n){var s=this;void 0===n&&(n={}),this._listeners={error:[],message:[],open:[],close:[]},this._retryCount=-1,this._shouldReconnect=!0,this._connectLock=!1,this._binaryType="blob",this._closeCalled=!1,this._messageQueue=[],this.onclose=null,this.onerror=null,this.onmessage=null,this.onopen=null,this._handleOpen=function(e){s._debug("open event");var t=s._options.minUptime,n=void 0===t?_.minUptime:t;clearTimeout(s._connectTimeout),s._uptimeTimeout=setTimeout((function(){return s._acceptOpen()}),n),s._ws.binaryType=s._binaryType,s._messageQueue.forEach((function(e){return s._ws.send(e)})),s._messageQueue=[],s.onopen&&s.onopen(e),s._listeners.open.forEach((function(t){return s._callEventListener(e,t)}))},this._handleMessage=function(e){s._debug("message event"),s.onmessage&&s.onmessage(e),s._listeners.message.forEach((function(t){return s._callEventListener(e,t)}))},this._handleError=function(e){s._debug("error event",e.message),s._disconnect(void 0,"TIMEOUT"===e.message?"timeout":void 0),s.onerror&&s.onerror(e),s._debug("exec error listeners"),s._listeners.error.forEach((function(t){return s._callEventListener(e,t)})),s._connect()},this._handleClose=function(e){s._debug("close event"),s._clearTimeouts(),s._shouldReconnect&&s._connect(),s.onclose&&s.onclose(e),s._listeners.close.forEach((function(t){return s._callEventListener(e,t)}))},this._url=e,this._protocols=t,this._options=n,this._options.startClosed&&(this._shouldReconnect=!1),this._connect()}return Object.defineProperty(e,"CONNECTING",{get:function(){return 0},enumerable:!0,configurable:!0}),Object.defineProperty(e,"OPEN",{get:function(){return 1},enumerable:!0,configurable:!0}),Object.defineProperty(e,"CLOSING",{get:function(){return 2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"CLOSED",{get:function(){return 3},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"CONNECTING",{get:function(){return e.CONNECTING},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"OPEN",{get:function(){return e.OPEN},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"CLOSING",{get:function(){return e.CLOSING},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"CLOSED",{get:function(){return e.CLOSED},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"binaryType",{get:function(){return this._ws?this._ws.binaryType:this._binaryType},set:function(e){this._binaryType=e,this._ws&&(this._ws.binaryType=e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"retryCount",{get:function(){return Math.max(this._retryCount,0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bufferedAmount",{get:function(){return this._messageQueue.reduce((function(e,t){return"string"==typeof t?e+=t.length:t instanceof Blob?e+=t.size:e+=t.byteLength,e}),0)+(this._ws?this._ws.bufferedAmount:0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"extensions",{get:function(){return this._ws?this._ws.extensions:""},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"protocol",{get:function(){return this._ws?this._ws.protocol:""},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"readyState",{get:function(){return this._ws?this._ws.readyState:this._options.startClosed?e.CLOSED:e.CONNECTING},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"url",{get:function(){return this._ws?this._ws.url:""},enumerable:!0,configurable:!0}),e.prototype.close=function(e,t){void 0===e&&(e=1e3),this._closeCalled=!0,this._shouldReconnect=!1,this._clearTimeouts(),this._ws?this._ws.readyState!==this.CLOSED?this._ws.close(e,t):this._debug("close: already closed"):this._debug("close enqueued: no ws instance")},e.prototype.reconnect=function(e,t){this._shouldReconnect=!0,this._closeCalled=!1,this._retryCount=-1,this._ws&&this._ws.readyState!==this.CLOSED?(this._disconnect(e,t),this._connect()):this._connect()},e.prototype.send=function(e){if(this._ws&&this._ws.readyState===this.OPEN)this._debug("send",e),this._ws.send(e);else{var t=this._options.maxEnqueuedMessages,n=void 0===t?_.maxEnqueuedMessages:t;this._messageQueue.length<n&&(this._debug("enqueue",e),this._messageQueue.push(e))}},e.prototype.addEventListener=function(e,t){this._listeners[e]&&this._listeners[e].push(t)},e.prototype.dispatchEvent=function(e){var t,n,s=this._listeners[e.type];if(s)try{for(var r=Qe(s),o=r.next();!o.done;o=r.next()){var i=o.value;this._callEventListener(e,i)}}catch(e){t={error:e}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(t)throw t.error}}return!0},e.prototype.removeEventListener=function(e,t){this._listeners[e]&&(this._listeners[e]=this._listeners[e].filter((function(e){return e!==t})))},e.prototype._debug=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._options.debug&&console.log.apply(console,Ve(["RWS>"],e))},e.prototype._getNextDelay=function(){var e=this._options,t=e.reconnectionDelayGrowFactor,n=void 0===t?_.reconnectionDelayGrowFactor:t,s=e.minReconnectionDelay,r=void 0===s?_.minReconnectionDelay:s,o=e.maxReconnectionDelay,i=void 0===o?_.maxReconnectionDelay:o,c=0;return this._retryCount>0&&((c=r*Math.pow(n,this._retryCount-1))>i&&(c=i)),this._debug("next delay",c),c},e.prototype._wait=function(){var e=this;return new Promise((function(t){setTimeout(t,e._getNextDelay())}))},e.prototype._getNextUrl=function(e){if("string"==typeof e)return Promise.resolve(e);if("function"==typeof e){var t=e();if("string"==typeof t)return Promise.resolve(t);if(t.then)return t}throw Error("Invalid URL")},e.prototype._connect=function(){var e=this;if(!this._connectLock&&this._shouldReconnect){this._connectLock=!0;var t=this._options,n=t.maxRetries,s=void 0===n?_.maxRetries:n,r=t.connectionTimeout,o=void 0===r?_.connectionTimeout:r,i=t.WebSocket,c=void 0===i?ze():i;if(this._retryCount>=s)return void this._debug("max retries reached",this._retryCount,">=",s);if(this._retryCount++,this._debug("connect",this._retryCount),this._removeListeners(),!Ze(c))throw Error("No valid WebSocket class provided");this._wait().then((function(){return e._getNextUrl(e._url)})).then((function(t){e._closeCalled||(e._debug("connect",{url:t,protocols:e._protocols}),e._ws=e._protocols?new c(t,e._protocols):new c(t),e._ws.binaryType=e._binaryType,e._connectLock=!1,e._addListeners(),e._connectTimeout=setTimeout((function(){return e._handleTimeout()}),o))}))}},e.prototype._handleTimeout=function(){this._debug("timeout event"),this._handleError(new Xe(Error("TIMEOUT"),this))},e.prototype._disconnect=function(e,t){if(void 0===e&&(e=1e3),this._clearTimeouts(),this._ws){this._removeListeners();try{this._ws.close(e,t),this._handleClose(new He(e,t,this))}catch{}}},e.prototype._acceptOpen=function(){this._debug("accept open"),this._retryCount=0},e.prototype._callEventListener=function(e,t){"handleEvent"in t?t.handleEvent(e):t(e)},e.prototype._removeListeners=function(){this._ws&&(this._debug("removeListeners"),this._ws.removeEventListener("open",this._handleOpen),this._ws.removeEventListener("close",this._handleClose),this._ws.removeEventListener("message",this._handleMessage),this._ws.removeEventListener("error",this._handleError))},e.prototype._addListeners=function(){this._ws&&(this._debug("addListeners"),this._ws.addEventListener("open",this._handleOpen),this._ws.addEventListener("close",this._handleClose),this._ws.addEventListener("message",this._handleMessage),this._ws.addEventListener("error",this._handleError))},e.prototype._clearTimeouts=function(){clearTimeout(this._connectTimeout),clearTimeout(this._uptimeTimeout)},e}();
16
16
  /*!
17
17
  * Reconnecting WebSocket
18
18
  * by Pedro Ladaria <pedro.ladaria@gmail.com>
19
19
  * https://github.com/pladaria/reconnecting-websocket
20
20
  * License MIT
21
- */const x="auth_token",se=()=>localStorage.getItem(x)||void 0,Ve=e=>localStorage.setItem(x,e),Ke=()=>localStorage.removeItem(x),He=()=>!!se(),Xe={getToken:se,setToken:Ve,removeToken:Ke,hasToken:He},q={forgotPasswordStep:"request",forgotPasswordFields:null,signupStep:"rules",signupFields:null,token:null,newEmail:null,isPending:!!Xe.getToken(),isAuthenticated:!1},ze=Q({name:"auth",initialState:q,reducers:{login:(e,t)=>{e.isAuthenticated=!0,e.token=t.payload||null,e.isPending=!1},logout:()=>({...q,isPending:!1}),setNewEmail:(e,t)=>{e.newEmail=t.payload},setForgotPasswordStep:(e,t)=>{e.forgotPasswordStep=t.payload},updateForgotPasswordFields:(e,t)=>{e.forgotPasswordFields={...e.forgotPasswordFields,...t.payload}},resetForgotPasswordFields:e=>{e.forgotPasswordFields=null},setSignupStep:(e,t)=>{e.signupStep=t.payload},updateSignupFields:(e,t)=>{e.signupFields={...e.signupFields,...t.payload}},resetSignupFields:e=>{e.signupFields=null},setPending:(e,t)=>{e.isPending=t.payload}},selectors:{selectToken:e=>e.token,selectNewEmail:e=>e.newEmail,selectForgotPasswordStep:e=>e.forgotPasswordStep,selectForgotPasswordFields:e=>e.forgotPasswordFields,selectSignupStep:e=>e.signupStep,selectSignupFields:e=>e.signupFields,selectPending:e=>e.isPending,selectIsAuthenticated:e=>e.isAuthenticated}}),Ze=({onReady:e})=>{const t=O(ze.selectors.selectToken),n=B(null),[s,r]=G(null);n.current=s;const o=()=>{var t,s,r;if((null==(t=n.current)?void 0:t.readyState)===(null==(s=n.current)?void 0:s.OPEN))try{e(!1),null==(r=n.current)||r.close()}catch(e){h.error("WebSocket error when close: ",e)}};return m((()=>()=>o()),[]),m((()=>((()=>{const e=location.hostname,n=new Je(`wss://${e}/api/v1/streaming${t?`?access_token=${t}`:""}`);r(n)})(),()=>o())),[t]),{socket:s}},rt=()=>{const[e,t]=G(!1),{socket:n}=Ze({onReady:t}),s=B([]);je({onReady:t,socket:n,serverSubscriptions:s}),Me({isReady:e,socket:n,serverSubscriptions:s}),Ue({isReady:e,socket:n,serverSubscriptions:s})},it=(e,t)=>Object.keys(t).reduce(((e,n)=>e.replace(`$${n}`,t[n])),e);export{it as fillTopic,rt as useWebSocket,E as wsSlice};
21
+ */const D="auth_token",A=re("user"),ae=()=>A.getItem(D)||void 0,tt=e=>A.setItem(D,e),nt=()=>A.removeItem(D),st=()=>!!ae(),rt={getToken:ae,setToken:tt,removeToken:nt,hasToken:st},G={forgotPasswordStep:"request",forgotPasswordFields:null,signupStep:"rules",signupFields:null,token:null,newEmail:null,isPending:!!rt.getToken(),isAuthenticated:!1},it=V({name:"auth",initialState:G,reducers:{login:(e,t)=>{e.isAuthenticated=!0,e.token=t.payload||null,e.isPending=!1},logout:()=>({...G,isPending:!1}),setNewEmail:(e,t)=>{e.newEmail=t.payload},setForgotPasswordStep:(e,t)=>{e.forgotPasswordStep=t.payload},updateForgotPasswordFields:(e,t)=>{e.forgotPasswordFields={...e.forgotPasswordFields,...t.payload}},resetForgotPasswordFields:e=>{e.forgotPasswordFields=null},setSignupStep:(e,t)=>{e.signupStep=t.payload},updateSignupFields:(e,t)=>{e.signupFields={...e.signupFields,...t.payload}},resetSignupFields:e=>{e.signupFields=null},setPending:(e,t)=>{e.isPending=t.payload}},selectors:{selectToken:e=>e.token,selectNewEmail:e=>e.newEmail,selectForgotPasswordStep:e=>e.forgotPasswordStep,selectForgotPasswordFields:e=>e.forgotPasswordFields,selectSignupStep:e=>e.signupStep,selectSignupFields:e=>e.signupFields,selectPending:e=>e.isPending,selectIsAuthenticated:e=>e.isAuthenticated}}),ot=({onReady:e})=>{const t=N(it.selectors.selectToken),n=J(null),[s,r]=Y(null);n.current=s;const o=()=>{var t,s,r;if((null==(t=n.current)?void 0:t.readyState)===(null==(s=n.current)?void 0:s.OPEN))try{e(!1),null==(r=n.current)||r.close()}catch(e){d.error("WebSocket error when close: ",e)}};return v((()=>()=>o()),[]),v((()=>((()=>{const e=location.hostname,n=new et(`wss://${e}/api/v1/streaming${t?`?access_token=${t}`:""}`);r(n)})(),()=>o())),[t]),{socket:s}},ft=()=>{const[e,t]=Y(!1),{socket:n}=ot({onReady:t}),s=J([]);Ye({onReady:t,socket:n,serverSubscriptions:s}),Ge({isReady:e,socket:n,serverSubscriptions:s}),Be({isReady:e,socket:n,serverSubscriptions:s})},pt=(e,t)=>Object.keys(t).reduce(((e,n)=>e.replace(`$${n}`,t[n])),e);export{pt as fillTopic,ft as useWebSocket,O as wsSlice};
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.442",
2
+ "version": "1.0.444",
3
3
  "name": "@wellesley/ws",
4
4
  "license": "UNLICENSED",
5
5
  "main": "index.mjs",