@wellesley/ws 1.0.681 → 1.0.682

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 +1 -1
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -1,4 +1,4 @@
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.698";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("askLogin"),c("reselectUser"),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("setDeviceWidth"),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"),K("requestMicroFrontendFetch"),K("sendMicroFrontendFetchResponse");const y={messages:[],subscribers:[],unsubscribers:[]},C=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 Oe=100;class A{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 A;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:Oe;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=A;function Ce(){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(Ce(),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 Ae(e,t){return ne().captureException(e,void 0)}function De(e,t){const n={captureContext:t};return ne().captureMessage(e,void 0,n)}function Re(e,t){xe().setExtra(e,t)}const Ue=(...e)=>{let t="";for(const n of e){if(n instanceof Error){const e=n;return Re("exceptionMessage",t),void Ae(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(C.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(C.actions.onUnsubscribe(e.id))}))}),[r,t,e])},Ge=({isReady:e,socket:t,serverSubscriptions:n})=>{const s=N(C.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])};
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.699";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("askLogin"),c("reselectUser"),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("setDeviceWidth"),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"),K("requestMicroFrontendFetch"),K("sendMicroFrontendFetchResponse");const y={messages:[],subscribers:[],unsubscribers:[]},C=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 Oe=100;class A{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 A;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:Oe;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=A;function Ce(){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(Ce(),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 Ae(e,t){return ne().captureException(e,void 0)}function De(e,t){const n={captureContext:t};return ne().captureMessage(e,void 0,n)}function Re(e,t){xe().setExtra(e,t)}const Ue=(...e)=>{let t="";for(const n of e){if(n instanceof Error){const e=n;return Re("exceptionMessage",t),void Ae(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(C.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(C.actions.onUnsubscribe(e.id))}))}),[r,t,e])},Ge=({isReady:e,socket:t,serverSubscriptions:n})=>{const s=N(C.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
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.681",
2
+ "version": "1.0.682",
3
3
  "name": "@wellesley/ws",
4
4
  "license": "UNLICENSED",
5
5
  "main": "index.mjs",