@wellesley/ws 1.0.813 → 1.0.814
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.
- package/index.mjs +1 -1
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{useEffect as v,useRef as Y,useState as Q}from"https://cdn.jsdelivr.net/npm/react@18.2.0/+esm";import{useDispatch as K,useSelector as k}from"https://cdn.jsdelivr.net/npm/react-redux@9.1.0/+esm";import{createAction as V,createSlice as H}from"https://cdn.jsdelivr.net/npm/@reduxjs/toolkit@2.2.1/+esm";import{rootReducer as fe}from"https://cdn.jsdelivr.net/npm/@wellesley/store@1.0.830";const pe=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)},_e=e=>pe(e)&&"type"in e&&"string"==typeof e.type,o=e=>{const t=t=>({type:e,payload:t});return t.toString=()=>`${e}`,t.type=e,t.match=t=>_e(t)&&t.type===e,t};o("remoteReady"),o("askLogin"),o("reselectUser"),o("requestLogout"),o("setConfirmLeavePage"),o("requestChangePath");const ge=o("wsSubscribe"),me=o("wsUnSubscribe");o("hostStoreConnect"),o("remoteLogin"),o("remoteLogout");const X=o("wsOnMessage");o("setRouterPath"),o("setDeviceType"),o("setDeviceWidth"),o("setUserError"),o("setUserIsError"),o("setUserPending"),o("setUserSuccess"),o("setUserData"),o("updateAccountData"),o("updateUser"),o("addNotification"),o("markNotification"),o("setNotificationsError"),o("setNotificationsList"),o("setNotificationsPending"),o("setNotificationsTotalCount"),o("setNotificationsUnreadCount"),o("acceptAllFollowRequests"),o("resetNotificationsState"),o("undoNotification"),o("setInstanceInfo"),o("setInstanceInfoPending"),o("setInstanceInfoError"),o("setPlatformSettings"),o("setProfileSettings"),o("setGroupData"),o("setGroupLoading"),o("requestLocalStorageGet"),o("requestLocalStorageSet"),o("requestLocalStorageRemove"),o("requestLocalStorageClear"),o("requestLocalStorageKeys"),o("requestLocalStorageHas"),o("sendLocalStorageResponse"),o("sendLocalStorageChanged");const 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 z=typeof __SENTRY_DEBUG__>"u"||__SENTRY_DEBUG__,be="Sentry Logger ",M=["debug","info","warn","error","log","assert","trace"],F={};function ye(e){if(!("console"in f))return e();const t=f.console,n={},s=Object.keys(F);s.forEach((e=>{const s=F[e];n[e]=t[e],t[e]=s}));try{return e()}finally{s.forEach((e=>{t[e]=n[e]}))}}function Se(){let e=!1;const t={enable:()=>{e=!0},disable:()=>{e=!1},isEnabled:()=>e};return z?M.forEach((n=>{t[n]=(...t)=>{e&&ye((()=>{f.console[n](`${be}[${n}]:`,...t)}))}})):M.forEach((e=>{t[e]=()=>{}})),t}const L=I("logger",Se);function x(){return A(f),f}function A(e){const t=e.__SENTRY__=e.__SENTRY__||{};return t.version=t.version||S,t[S]=t[S]||{}}const ve=Object.prototype.toString;function we(e,t){return ve.call(e)===`[object ${t}]`}function Ee(e){return we(e,"Object")}function Le(e){return!(!e||!e.then||"function"!=typeof e.then)}function Oe(e,t,n){try{Object.defineProperty(e,t,{value:n,writable:!0,configurable:!0})}catch{z&&L.log(`Failed to add non-enumerable property "${t}" to object`,e)}}const Z=1e3;function ee(){return Date.now()/Z}function Ce(){const{performance:e}=f;if(!e||!e.now)return ee;const t=Date.now()-e.now(),n=null==e.timeOrigin?t:e.timeOrigin;return()=>(n+e.now())/Z}const Te=Ce();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 Pe(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||Te(),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 W(){return g()}function $(){return g().substring(16)}function te(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]=te(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 q(e,t){t?Oe(e,T,t):delete e[T]}function j(e){return e[T]}const Ne=100;class D{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:W(),spanId:$()}}clone(){const e=new D;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,q(e,j(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&&Pe(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()]:Ee(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,q(this,void 0),this._attachments=[],this.setPropagationContext({traceId:W()}),this._notifyScopeListeners(),this}addBreadcrumb(e,t){const n="number"==typeof t?t:Ne;if(n<=0)return this;const s={timestamp:ee(),...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:j(this)}}setSDKProcessingMetadata(e){return this._sdkProcessingMetadata=te(this._sdkProcessingMetadata,e,2),this}setPropagationContext(e){return this._propagationContext={spanId:$(),...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=D;function ke(){return I("defaultCurrentScope",(()=>new w))}function Ie(){return I("defaultIsolationScope",(()=>new w))}class xe{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 Le(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=A(x());return e.stack=e.stack||new xe(ke(),Ie())}function Ae(e){return m().withScope(e)}function De(e,t){const n=m();return n.withScope((()=>(n.getStackTop().scope=e,t(e))))}function G(e){return m().withScope((()=>e(m().getIsolationScope())))}function Re(){return{withIsolationScope:G,withScope:Ae,withSetScope:De,withSetIsolationScope:(e,t)=>G(t),getCurrentScope:()=>m().getScope(),getIsolationScope:()=>m().getIsolationScope()}}function ne(e){const t=A(e);return t.acs?t.acs:Re()}function se(){return ne(x()).getCurrentScope()}function Ue(){return ne(x()).getIsolationScope()}function Me(e,t){return se().captureException(e,void 0)}function Fe(e,t){const n={captureContext:t};return se().captureMessage(e,void 0,n)}function We(e,t){Ue().setExtra(e,t)}const $e=(...e)=>{let t="";for(const n of e){if(n instanceof Error){const e=n;return We("exceptionMessage",t),void Me(e)}if("object"!=typeof n)t+=n;else try{t+=" "+JSON.stringify(n)}catch{t+=" "+n}}Fe(t)},O=()=>"object"!=typeof window,qe="wlsy",re=()=>{try{return window.localStorage}catch(e){console.warn("Error getting window.localStorage storage",e)}},je=()=>{const e=new Set,t=re();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)},Ge=e=>{const t=`${qe}`,n=e=>`${t}:${e}`,s=()=>je().filter((e=>e.startsWith(`${t}:`))),r=e=>e.slice(t.length+1),o=re(),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"],Be=(e,t)=>{const n=B.indexOf(e);return B.indexOf(t)>=n},E=(e,t,n,...s)=>{Be(t,e)&&console.log(`[${e}] ${n}`,...s)},Je=()=>Ge().getItem("logger_lvl"),Ye=(e=(O()?"info":Je()||"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)=>($e(e,...n),E("error",t,e,...n)),setLevel:e=>{t=e},getLevel:()=>t}},d=Ye();V("requestMicroFrontendFetch"),V("sendMicroFrontendFetchResponse");const y={messages:[],subscribers:[],unsubscribers:[]},P=H({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(ge,((e,{payload:t})=>{!e.subscribers.find((e=>e.id===t.id))&&e.subscribers.push(t)})).addCase(me,((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(fe),ie=e=>[...new Set(e.flatMap((e=>e.topics)))],Qe=({isReady:e,socket:t,serverSubscriptions:n})=>{const s=K(),r=k(P.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(P.actions.onUnsubscribe(e.id))}))}),[r,t,e])},Ke=({isReady:e,socket:t,serverSubscriptions:n})=>{const s=k(P.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])},Ve=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."}},He=({onReady:e,socket:t,serverSubscriptions:n})=>{const s=K();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:",Ve(t))},t.onerror=t=>{e(!1),d.error("WebSocket error:",t)})}),[t])};
|
|
1
|
+
import{useEffect as v,useRef as Y,useState as Q}from"https://cdn.jsdelivr.net/npm/react@18.2.0/+esm";import{useDispatch as K,useSelector as k}from"https://cdn.jsdelivr.net/npm/react-redux@9.1.0/+esm";import{createAction as V,createSlice as H}from"https://cdn.jsdelivr.net/npm/@reduxjs/toolkit@2.2.1/+esm";import{rootReducer as fe}from"https://cdn.jsdelivr.net/npm/@wellesley/store@1.0.831";const pe=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)},_e=e=>pe(e)&&"type"in e&&"string"==typeof e.type,o=e=>{const t=t=>({type:e,payload:t});return t.toString=()=>`${e}`,t.type=e,t.match=t=>_e(t)&&t.type===e,t};o("remoteReady"),o("askLogin"),o("reselectUser"),o("requestLogout"),o("setConfirmLeavePage"),o("requestChangePath");const ge=o("wsSubscribe"),me=o("wsUnSubscribe");o("hostStoreConnect"),o("remoteLogin"),o("remoteLogout");const X=o("wsOnMessage");o("setRouterPath"),o("setDeviceType"),o("setDeviceWidth"),o("setUserError"),o("setUserIsError"),o("setUserPending"),o("setUserSuccess"),o("setUserData"),o("updateAccountData"),o("updateUser"),o("addNotification"),o("markNotification"),o("setNotificationsError"),o("setNotificationsList"),o("setNotificationsPending"),o("setNotificationsTotalCount"),o("setNotificationsUnreadCount"),o("acceptAllFollowRequests"),o("resetNotificationsState"),o("undoNotification"),o("setInstanceInfo"),o("setInstanceInfoPending"),o("setInstanceInfoError"),o("setPlatformSettings"),o("setProfileSettings"),o("setGroupData"),o("setGroupLoading"),o("requestLocalStorageGet"),o("requestLocalStorageSet"),o("requestLocalStorageRemove"),o("requestLocalStorageClear"),o("requestLocalStorageKeys"),o("requestLocalStorageHas"),o("sendLocalStorageResponse"),o("sendLocalStorageChanged");const 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 z=typeof __SENTRY_DEBUG__>"u"||__SENTRY_DEBUG__,be="Sentry Logger ",M=["debug","info","warn","error","log","assert","trace"],F={};function ye(e){if(!("console"in f))return e();const t=f.console,n={},s=Object.keys(F);s.forEach((e=>{const s=F[e];n[e]=t[e],t[e]=s}));try{return e()}finally{s.forEach((e=>{t[e]=n[e]}))}}function Se(){let e=!1;const t={enable:()=>{e=!0},disable:()=>{e=!1},isEnabled:()=>e};return z?M.forEach((n=>{t[n]=(...t)=>{e&&ye((()=>{f.console[n](`${be}[${n}]:`,...t)}))}})):M.forEach((e=>{t[e]=()=>{}})),t}const L=I("logger",Se);function x(){return A(f),f}function A(e){const t=e.__SENTRY__=e.__SENTRY__||{};return t.version=t.version||S,t[S]=t[S]||{}}const ve=Object.prototype.toString;function we(e,t){return ve.call(e)===`[object ${t}]`}function Ee(e){return we(e,"Object")}function Le(e){return!(!e||!e.then||"function"!=typeof e.then)}function Oe(e,t,n){try{Object.defineProperty(e,t,{value:n,writable:!0,configurable:!0})}catch{z&&L.log(`Failed to add non-enumerable property "${t}" to object`,e)}}const Z=1e3;function ee(){return Date.now()/Z}function Ce(){const{performance:e}=f;if(!e||!e.now)return ee;const t=Date.now()-e.now(),n=null==e.timeOrigin?t:e.timeOrigin;return()=>(n+e.now())/Z}const Te=Ce();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 Pe(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||Te(),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 W(){return g()}function $(){return g().substring(16)}function te(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]=te(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 q(e,t){t?Oe(e,T,t):delete e[T]}function j(e){return e[T]}const Ne=100;class D{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:W(),spanId:$()}}clone(){const e=new D;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,q(e,j(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&&Pe(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()]:Ee(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,q(this,void 0),this._attachments=[],this.setPropagationContext({traceId:W()}),this._notifyScopeListeners(),this}addBreadcrumb(e,t){const n="number"==typeof t?t:Ne;if(n<=0)return this;const s={timestamp:ee(),...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:j(this)}}setSDKProcessingMetadata(e){return this._sdkProcessingMetadata=te(this._sdkProcessingMetadata,e,2),this}setPropagationContext(e){return this._propagationContext={spanId:$(),...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=D;function ke(){return I("defaultCurrentScope",(()=>new w))}function Ie(){return I("defaultIsolationScope",(()=>new w))}class xe{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 Le(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=A(x());return e.stack=e.stack||new xe(ke(),Ie())}function Ae(e){return m().withScope(e)}function De(e,t){const n=m();return n.withScope((()=>(n.getStackTop().scope=e,t(e))))}function G(e){return m().withScope((()=>e(m().getIsolationScope())))}function Re(){return{withIsolationScope:G,withScope:Ae,withSetScope:De,withSetIsolationScope:(e,t)=>G(t),getCurrentScope:()=>m().getScope(),getIsolationScope:()=>m().getIsolationScope()}}function ne(e){const t=A(e);return t.acs?t.acs:Re()}function se(){return ne(x()).getCurrentScope()}function Ue(){return ne(x()).getIsolationScope()}function Me(e,t){return se().captureException(e,void 0)}function Fe(e,t){const n={captureContext:t};return se().captureMessage(e,void 0,n)}function We(e,t){Ue().setExtra(e,t)}const $e=(...e)=>{let t="";for(const n of e){if(n instanceof Error){const e=n;return We("exceptionMessage",t),void Me(e)}if("object"!=typeof n)t+=n;else try{t+=" "+JSON.stringify(n)}catch{t+=" "+n}}Fe(t)},O=()=>"object"!=typeof window,qe="wlsy",re=()=>{try{return window.localStorage}catch(e){console.warn("Error getting window.localStorage storage",e)}},je=()=>{const e=new Set,t=re();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)},Ge=e=>{const t=`${qe}`,n=e=>`${t}:${e}`,s=()=>je().filter((e=>e.startsWith(`${t}:`))),r=e=>e.slice(t.length+1),o=re(),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"],Be=(e,t)=>{const n=B.indexOf(e);return B.indexOf(t)>=n},E=(e,t,n,...s)=>{Be(t,e)&&console.log(`[${e}] ${n}`,...s)},Je=()=>Ge().getItem("logger_lvl"),Ye=(e=(O()?"info":Je()||"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)=>($e(e,...n),E("error",t,e,...n)),setLevel:e=>{t=e},getLevel:()=>t}},d=Ye();V("requestMicroFrontendFetch"),V("sendMicroFrontendFetchResponse");const y={messages:[],subscribers:[],unsubscribers:[]},P=H({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(ge,((e,{payload:t})=>{!e.subscribers.find((e=>e.id===t.id))&&e.subscribers.push(t)})).addCase(me,((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(fe),ie=e=>[...new Set(e.flatMap((e=>e.topics)))],Qe=({isReady:e,socket:t,serverSubscriptions:n})=>{const s=K(),r=k(P.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(P.actions.onUnsubscribe(e.id))}))}),[r,t,e])},Ke=({isReady:e,socket:t,serverSubscriptions:n})=>{const s=k(P.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])},Ve=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."}},He=({onReady:e,socket:t,serverSubscriptions:n})=>{const s=K();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:",Ve(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