@wellesley/host-remote 1.0.146 → 1.0.148

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 +1 @@
1
- import{logErrorToSentry as rt}from"https://cdn.jsdelivr.net/npm/@wellesley/sentry@next";import{subscribeAfter as V}from"https://cdn.jsdelivr.net/npm/@wellesley/redux-subscribe-action@next";import{useRef as g,useCallback as w,useEffect as p,memo as $,useState as q}from"https://cdn.jsdelivr.net/npm/react@18.2.0/+esm";import{getStore as h,createStore as at}from"https://cdn.jsdelivr.net/npm/@wellesley/store@next";import{api as ct,handleBasicResponse as i}from"https://cdn.jsdelivr.net/npm/@wellesley/openapi@next";import{createSlice as it,createAction as H}from"https://cdn.jsdelivr.net/npm/@reduxjs/toolkit@2.2.1/+esm";import{toast as B}from"https://cdn.jsdelivr.net/npm/react-toastify@10.0.5/+esm";import{getErrorMsg as lt}from"https://cdn.jsdelivr.net/npm/@wellesley/error-kit@next";import{useDispatch as b,useSelector as u}from"https://cdn.jsdelivr.net/npm/react-redux@9.1.0/+esm";import{routerSlice as d}from"https://cdn.jsdelivr.net/npm/@wellesley/router@next";import{useLocation as W,useBlocker as ut,useNavigate as j}from"https://cdn.jsdelivr.net/npm/react-router-dom@6.22.2/+esm";import{handleLogin as dt,handleLogout as pt}from"https://cdn.jsdelivr.net/npm/@wellesley/auth@next";const gt=()=>"object"!=typeof window,Q=["debug","info","warn","error"],ht=(e,t)=>{const s=Q.indexOf(e);return Q.indexOf(t)>=s},y=(e,t,s,...r)=>{ht(t,e)&&console.log(`[${e}] ${s}`,...r)},ft=()=>null==window?void 0:window.localStorage.getItem("logger_lvl"),yt=(e=!gt()&&ft()||"warn")=>{let t=e;return{debug:(e,...s)=>y("debug",t,e,...s),info:(e,...s)=>y("info",t,e,...s),warn:(e,...s)=>y("warn",t,e,...s),error:(e,...s)=>(rt(e,...s),y("error",t,e,...s)),setLevel:e=>{t=e},getLevel:()=>t}},v=yt(),C="staticState",m={path:"",baseUrl:"",search:""},mt=e=>{if(!e)return m;try{return JSON.parse(decodeURIComponent(e))||m}catch(e){return v.error("Error parsing static state",e),m}},x=()=>new URLSearchParams(window.location.search).get(C),wt=({path:e,baseUrl:t,search:s}={})=>{const{pathname:r,origin:n,search:o}=window.location;return`${C}=${encodeURIComponent(JSON.stringify({path:e||r,baseUrl:t||n,search:s||o}))}`},St=()=>{const e=x();return e&&localStorage.setItem(C,e),G()},G=()=>{try{const e=localStorage.getItem(C)||x();return mt(e)}catch(e){return v.error("Error parsing static state",e),m}},Pt={create:wt,init:St,get:G},k=({onMessage:e,whitelist:t})=>{const s=s=>{const r=s.origin!==window.location.origin,n=s.data&&"object"==typeof s.data&&"type"in s.data,o=t.some((({type:e})=>e===s.data.type||"*"===e));r&&n&&o&&e(s.data)};return window.addEventListener("message",s),()=>{window.removeEventListener("message",s)}},At=e=>{try{const{type:t,payload:s}=e,r={type:t};return void 0!==s&&(r.payload=JSON.parse(JSON.stringify(s))),r}catch(t){return v.warn(`Could not serialize action type: ${e.type}`,t),{type:e.type,payload:`[Non-serializable payload for action: ${e.type}]`}}},E=({action:e,windowElement:t,whitelist:s})=>{if(t)try{const{type:r}=e;if(!s.some((({type:e})=>e===r||"*"===e)))return;const n=At(e);t.postMessage(n,"*")}catch(e){v.error("Failed to process or send message:",e)}},F="auth_token",z=()=>localStorage.getItem(F)||void 0,bt=e=>localStorage.setItem(F,e),vt=()=>localStorage.removeItem(F),Ct=()=>!!z(),S={getToken:z,setToken:bt,removeToken:vt,hasToken:Ct},M={forgotPasswordStep:"request",forgotPasswordFields:null,signupStep:"rules",signupFields:null,token:null,newEmail:null,isPending:!!S.getToken(),isAuthenticated:!1},D=it({name:"auth",initialState:M,reducers:{login:(e,t)=>{e.isAuthenticated=!0,e.token=t.payload||null,e.isPending=!1},logout:()=>({...M,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}}),Lt=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)},Nt=e=>Lt(e)&&"type"in e&&"string"==typeof e.type,r=e=>{const t=t=>({type:e,payload:t});return t.toString=()=>`${e}`,t.type=e,t.match=t=>Nt(t)&&t.type===e,t},P=r("remoteReady"),J=r("reselectUser"),U=r("requestLogin"),K=r("requestLogout"),X=r("setConfirmLeavePage"),I=r("requestChangePath"),Rt=r("wsSubscribe"),kt=r("wsUnSubscribe"),A=r("hostStoreConnect"),Y=r("remoteLogin"),Z=r("remoteLogout"),Et=r("wsOnMessage"),tt=r("setRouterPath"),Ft=r("setDeviceType"),Ut=r("setUserError"),It=r("setUserIsError"),Ot=r("setUserPending"),Tt=r("setUserSuccess"),_t=r("setUserData"),et=r("updateAccountData"),Vt=r("updateUser"),Qt=r("addNotification"),Mt=r("markNotification"),Dt=r("setNotificationsError"),$t=r("setNotificationsList"),qt=r("setNotificationsPending"),Ht=r("setNotificationsTotalCount"),Bt=r("setNotificationsUnreadCount"),Wt=r("resetNotificationsState"),jt=r("undoNotification"),xt=r("setInstanceInfo"),Gt=r("setInstanceInfoPending"),zt=r("setInstanceInfoError"),Jt=r("setPlatformSettings"),Kt=r("setProfileSettings"),Xt=r("setGroupData"),Yt=r("setGroupLoading"),Zt=r("showGroupBasicInfo");H("requestMicroFrontendFetch"),H("sendMicroFrontendFetchResponse");const L=async(e,t,s)=>{try{e(D.actions.setPending(!0));const{data:r}=await t,n="sessionKey"in r?r.sessionKey:r.token.sessionKey;return S.setToken(n),e(U(n)),null==s||s(),t}catch(t){e(D.actions.setPending(!1)),B.error(lt(t))}},te=ct.enhanceEndpoints({endpoints:{getApiV1Rules:{async onQueryStarted(e,{queryFulfilled:t}){await i(t)}},postApiV1AccountsPasswordRecover:{async onQueryStarted(e,{queryFulfilled:t}){await i(t)}},postApiV1AccountsPasswordRecoverCheckCode:{async onQueryStarted(e,{queryFulfilled:t}){await i(t)}},postApiV1AccountsPasswordRecoverChange:{async onQueryStarted(e,{queryFulfilled:t}){await i(t)}},postApiV1AccountsPasswordChangeConfirm:{async onQueryStarted(e,{queryFulfilled:t}){await i(t)}},putApiV1AccountsPasswordChangeResendCode:{async onQueryStarted(e,{queryFulfilled:t}){await i(t)}},postApiV1AccountsPasswordChangeRequest:{async onQueryStarted(e,{queryFulfilled:t}){await i(t)}},putApiV1AccountsEmailChangeResendCode:{async onQueryStarted(e,{queryFulfilled:t}){await i(t)}},putApiV1AccountsResendEmailByHash:{async onQueryStarted(e,{queryFulfilled:t}){await i(t)}},postApiV1AccountsEmailChangeRequest:{async onQueryStarted(e,{queryFulfilled:t}){await i(t)}},postApiV1AccountsEmailChangeConfirm:{async onQueryStarted(e,{queryFulfilled:t}){await i(t)}},postApiV1AccountsConfirmEmail:{async onQueryStarted(e,{queryFulfilled:t}){await i(t)}},postApiV1AccountsCheckCaptcha:{async onQueryStarted(e,{queryFulfilled:t}){await i(t)}},postApiV1AccountsFinishCreating:{async onQueryStarted(e,{dispatch:t,queryFulfilled:s}){await L(t,s,(()=>{B.success("User registered successfully")}))}},postApiV1AccountsAuthenticateEmail:{invalidatesTags:["Secure"],async onQueryStarted(e,{dispatch:t,queryFulfilled:s}){await L(t,s)}},postApiV1AccountsSignup:{invalidatesTags:["Secure"]},postApiV1AccountsUserReselectUser:{async onQueryStarted({userId:e},{dispatch:t,queryFulfilled:s}){await L(t,s),e&&t(et({selectedUserId:e}))}}}}),st={[J.type]:e=>h().dispatch(te.endpoints.postApiV1AccountsUserReselectUser.initiate(e)),[U.type]:e=>S.setToken(e),[K.type]:()=>S.removeToken()},ee=e=>Object.keys(st).includes(e.type),ot=e=>ee(e)?st[e.type](e.payload):null,nt=({sendWhitelist:e,receiveWhitelist:t,onMessage:s})=>{const r=g((()=>{})),n=g((()=>{}));return w((o=>{o&&(r.current(),n.current(),r.current=V((t=>{ot(t),E({action:t,windowElement:o,whitelist:e})})),n.current=k({onMessage:e=>{s?s(e):h().dispatch(e)},whitelist:t}))}),[e,t,s,V])},O=[I,Rt,kt,P,J,U,K,X],T=[Y,Z,A,Et,tt,Ft,Ut,It,Ot,Tt,_t,et,Vt,Qt,Mt,Dt,$t,qt,Ht,Bt,Wt,jt,xt,Gt,zt,Jt,Kt,Xt,Yt,Zt];if(T.some((e=>O.some((t=>(null==t?void 0:t.toString())===(null==e?void 0:e.toString()))))))throw new Error("Output action is duplicated with input action");const se=()=>{const e=h().getState();return e.openapi&&(e.openapi=void 0),e.auth&&(e.auth={...e.auth,token:null}),e},Ne=e=>{const t=nt({sendWhitelist:T,receiveWhitelist:O,onMessage:e=>{ot(e)||h().dispatch(e)}}),s=w((()=>{var t;const s=A(se());E({action:s,windowElement:(null==(t=e.current)?void 0:t.contentWindow)??null,whitelist:[s]})}),[e]),r=w((()=>{var r;t((null==(r=e.current)?void 0:r.contentWindow)??null),s()}),[t,e,s]);p((()=>{const e=k({onMessage:e=>{e.type===P.type&&r()},whitelist:[P]});return()=>e()}),[r])},_=()=>{const e=W();return e.pathname+e.search},oe=({lastLocationPathRef:e})=>{const t=b(),s=_(),r=u(d.selectors.selectPath),n=u(d.selectors.selectTransitionPath);p((()=>{s!==e.current&&(e.current=s,s!==r&&s!==n&&t(I(s)))}),[r,n,s])},ne=({canShowMessage:e,message:t="Are you sure you want to leave?"})=>{const s=b(),r=u(d.selectors.selectPath),n=e=>(e.preventDefault(),e.returnValue=t,t);p((()=>(window.onbeforeunload=e?n:null,()=>{window.onbeforeunload=null})),[e,t]);const o=ut(e),a="blocked"===o.state;p((()=>{a&&(confirm(t)?(o.proceed(),s(X(null))):(o.reset(),s(I(r))))}),[a])},re=()=>{const e=b(),t=u(d.selectors.selectPath),s=_();return{setPath:({transitionPath:r})=>{r&&s===r&&t!==r&&e(tt(r))}}},ae=()=>{const e=j(),t=W(),s=b(),r=g(""),n=u(d.selectors.selectPath),o=u(d.selectors.selectTransitionPath),{setPath:a}=re(),{shouldBlock:i,message:l}=u(d.selectors.selectConfirmLeavePage)||{};ne({canShowMessage:!!i,message:l}),oe({lastLocationPathRef:r}),p((()=>{a({transitionPath:o})}),[t,n,o,s]),p((()=>{o&&o!==r.current&&(r.current=o,e(o,{replace:!1}))}),[o,e])},ce=$((()=>(ae(),null)));ce.displayName="HostRouteObserver";const ie=e=>{const t=g(e),[s,r]=q(null);return p((()=>{const e=k({onMessage:e=>{var s;if(e.type===A.type){const n=at(e.payload);r(n),null==(s=t.current)||s.call(t,n)}},whitelist:[A]}),s=P();return E({action:s,windowElement:window.parent,whitelist:[s]}),()=>e()}),[]),{store:s}},N={[Y.type]:()=>dt(),[Z.type]:()=>pt()},le=e=>Object.keys(N).includes(e.type),ue=e=>le(e)&&e.type in N?N[e.type]():null,{path:R,search:de}=Pt.init();R&&window.history.replaceState({},"",`${R}${de||""}`);const Re=()=>{const[e,t]=q(null),s=nt({sendWhitelist:O,receiveWhitelist:T,onMessage:e=>{ue(e)||h().dispatch(e)}}),r=w((e=>{t(e),s(window.parent)}),[s]);return ie(r),{store:e,path:R}},pe=()=>{const e=j(),t=g(""),s=_(),r=u(d.selectors.selectPath);p((()=>{r&&r!==t.current&&(t.current=r,s!==r&&e(r,{replace:!0}))}),[r,e,s])},ge=$((()=>(pe(),null)));ge.displayName="RemoteRouteObserver";export{ce as HostRouteObserver,ge as RemoteRouteObserver,ot as callHostApiAction,ue as callRemoteApiAction,k as listenMessage,se as prepareState,E as sendMessage,Pt as staticState,Ne as useHostStoreConnect,ie as usePreloadedStore,Re as useRemoteStoreConnect};
1
+ import{logErrorToSentry as rt}from"https://cdn.jsdelivr.net/npm/@wellesley/sentry@1.0.172";import{subscribeAfter as V}from"https://cdn.jsdelivr.net/npm/@wellesley/redux-subscribe-action@1.0.50";import{useRef as g,useCallback as w,useEffect as p,memo as $,useState as q}from"https://cdn.jsdelivr.net/npm/react@18.2.0/+esm";import{getStore as h,createStore as at}from"https://cdn.jsdelivr.net/npm/@wellesley/store@1.0.305";import{api as ct,handleBasicResponse as i}from"https://cdn.jsdelivr.net/npm/@wellesley/openapi@1.0.306";import{createSlice as it,createAction as H}from"https://cdn.jsdelivr.net/npm/@reduxjs/toolkit@2.2.1/+esm";import{toast as B}from"https://cdn.jsdelivr.net/npm/react-toastify@10.0.5/+esm";import{getErrorMsg as lt}from"https://cdn.jsdelivr.net/npm/@wellesley/error-kit@1.0.157";import{useDispatch as b,useSelector as u}from"https://cdn.jsdelivr.net/npm/react-redux@9.1.0/+esm";import{routerSlice as d}from"https://cdn.jsdelivr.net/npm/@wellesley/router@1.0.234";import{useLocation as W,useBlocker as ut,useNavigate as j}from"https://cdn.jsdelivr.net/npm/react-router-dom@6.22.2/+esm";import{handleLogin as dt,handleLogout as pt}from"https://cdn.jsdelivr.net/npm/@wellesley/auth@1.0.362";const gt=()=>"object"!=typeof window,Q=["debug","info","warn","error"],ht=(e,t)=>{const s=Q.indexOf(e);return Q.indexOf(t)>=s},y=(e,t,s,...r)=>{ht(t,e)&&console.log(`[${e}] ${s}`,...r)},ft=()=>null==window?void 0:window.localStorage.getItem("logger_lvl"),yt=(e=!gt()&&ft()||"warn")=>{let t=e;return{debug:(e,...s)=>y("debug",t,e,...s),info:(e,...s)=>y("info",t,e,...s),warn:(e,...s)=>y("warn",t,e,...s),error:(e,...s)=>(rt(e,...s),y("error",t,e,...s)),setLevel:e=>{t=e},getLevel:()=>t}},v=yt(),C="staticState",m={path:"",baseUrl:"",search:""},mt=e=>{if(!e)return m;try{return JSON.parse(decodeURIComponent(e))||m}catch(e){return v.error("Error parsing static state",e),m}},x=()=>new URLSearchParams(window.location.search).get(C),wt=({path:e,baseUrl:t,search:s}={})=>{const{pathname:r,origin:o,search:n}=window.location;return`${C}=${encodeURIComponent(JSON.stringify({path:e||r,baseUrl:t||o,search:s||n}))}`},St=()=>{const e=x();return e&&localStorage.setItem(C,e),G()},G=()=>{try{const e=localStorage.getItem(C)||x();return mt(e)}catch(e){return v.error("Error parsing static state",e),m}},Pt={create:wt,init:St,get:G},k=({onMessage:e,whitelist:t})=>{const s=s=>{const r=s.origin!==window.location.origin,o=s.data&&"object"==typeof s.data&&"type"in s.data,n=t.some((({type:e})=>e===s.data.type||"*"===e));r&&o&&n&&e(s.data)};return window.addEventListener("message",s),()=>{window.removeEventListener("message",s)}},At=e=>{try{const{type:t,payload:s}=e,r={type:t};return void 0!==s&&(r.payload=JSON.parse(JSON.stringify(s))),r}catch(t){return v.warn(`Could not serialize action type: ${e.type}`,t),{type:e.type,payload:`[Non-serializable payload for action: ${e.type}]`}}},E=({action:e,windowElement:t,whitelist:s})=>{if(t)try{const{type:r}=e;if(!s.some((({type:e})=>e===r||"*"===e)))return;const o=At(e);t.postMessage(o,"*")}catch(e){v.error("Failed to process or send message:",e)}},F="auth_token",z=()=>localStorage.getItem(F)||void 0,bt=e=>localStorage.setItem(F,e),vt=()=>localStorage.removeItem(F),Ct=()=>!!z(),S={getToken:z,setToken:bt,removeToken:vt,hasToken:Ct},M={forgotPasswordStep:"request",forgotPasswordFields:null,signupStep:"rules",signupFields:null,token:null,newEmail:null,isPending:!!S.getToken(),isAuthenticated:!1},D=it({name:"auth",initialState:M,reducers:{login:(e,t)=>{e.isAuthenticated=!0,e.token=t.payload||null,e.isPending=!1},logout:()=>({...M,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}}),Lt=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)},Nt=e=>Lt(e)&&"type"in e&&"string"==typeof e.type,r=e=>{const t=t=>({type:e,payload:t});return t.toString=()=>`${e}`,t.type=e,t.match=t=>Nt(t)&&t.type===e,t},P=r("remoteReady"),J=r("reselectUser"),U=r("requestLogin"),K=r("requestLogout"),X=r("setConfirmLeavePage"),I=r("requestChangePath"),Rt=r("wsSubscribe"),kt=r("wsUnSubscribe"),A=r("hostStoreConnect"),Y=r("remoteLogin"),Z=r("remoteLogout"),Et=r("wsOnMessage"),tt=r("setRouterPath"),Ft=r("setDeviceType"),Ut=r("setUserError"),It=r("setUserIsError"),Ot=r("setUserPending"),Tt=r("setUserSuccess"),_t=r("setUserData"),et=r("updateAccountData"),Vt=r("updateUser"),Qt=r("addNotification"),Mt=r("markNotification"),Dt=r("setNotificationsError"),$t=r("setNotificationsList"),qt=r("setNotificationsPending"),Ht=r("setNotificationsTotalCount"),Bt=r("setNotificationsUnreadCount"),Wt=r("resetNotificationsState"),jt=r("undoNotification"),xt=r("setInstanceInfo"),Gt=r("setInstanceInfoPending"),zt=r("setInstanceInfoError"),Jt=r("setPlatformSettings"),Kt=r("setProfileSettings"),Xt=r("setGroupData"),Yt=r("setGroupLoading"),Zt=r("showGroupBasicInfo");H("requestMicroFrontendFetch"),H("sendMicroFrontendFetchResponse");const L=async(e,t,s)=>{try{e(D.actions.setPending(!0));const{data:r}=await t,o="sessionKey"in r?r.sessionKey:r.token.sessionKey;return S.setToken(o),e(U(o)),null==s||s(),t}catch(t){e(D.actions.setPending(!1)),B.error(lt(t))}},te=ct.enhanceEndpoints({endpoints:{getApiV1Rules:{async onQueryStarted(e,{queryFulfilled:t}){await i(t)}},postApiV1AccountsPasswordRecover:{async onQueryStarted(e,{queryFulfilled:t}){await i(t)}},postApiV1AccountsPasswordRecoverCheckCode:{async onQueryStarted(e,{queryFulfilled:t}){await i(t)}},postApiV1AccountsPasswordRecoverChange:{async onQueryStarted(e,{queryFulfilled:t}){await i(t)}},postApiV1AccountsPasswordChangeConfirm:{async onQueryStarted(e,{queryFulfilled:t}){await i(t)}},putApiV1AccountsPasswordChangeResendCode:{async onQueryStarted(e,{queryFulfilled:t}){await i(t)}},postApiV1AccountsPasswordChangeRequest:{async onQueryStarted(e,{queryFulfilled:t}){await i(t)}},putApiV1AccountsEmailChangeResendCode:{async onQueryStarted(e,{queryFulfilled:t}){await i(t)}},putApiV1AccountsResendEmailByHash:{async onQueryStarted(e,{queryFulfilled:t}){await i(t)}},postApiV1AccountsEmailChangeRequest:{async onQueryStarted(e,{queryFulfilled:t}){await i(t)}},postApiV1AccountsEmailChangeConfirm:{async onQueryStarted(e,{queryFulfilled:t}){await i(t)}},postApiV1AccountsConfirmEmail:{async onQueryStarted(e,{queryFulfilled:t}){await i(t)}},postApiV1AccountsCheckCaptcha:{async onQueryStarted(e,{queryFulfilled:t}){await i(t)}},postApiV1AccountsFinishCreating:{async onQueryStarted(e,{dispatch:t,queryFulfilled:s}){await L(t,s,(()=>{B.success("User registered successfully")}))}},postApiV1AccountsAuthenticateEmail:{invalidatesTags:["Secure"],async onQueryStarted(e,{dispatch:t,queryFulfilled:s}){await L(t,s)}},postApiV1AccountsSignup:{invalidatesTags:["Secure"]},postApiV1AccountsUserReselectUser:{async onQueryStarted({userId:e},{dispatch:t,queryFulfilled:s}){await L(t,s),e&&t(et({selectedUserId:e}))}}}}),st={[J.type]:e=>h().dispatch(te.endpoints.postApiV1AccountsUserReselectUser.initiate(e)),[U.type]:e=>S.setToken(e),[K.type]:()=>S.removeToken()},ee=e=>Object.keys(st).includes(e.type),ot=e=>ee(e)?st[e.type](e.payload):null,nt=({sendWhitelist:e,receiveWhitelist:t,onMessage:s})=>{const r=g((()=>{})),o=g((()=>{}));return w((n=>{n&&(r.current(),o.current(),r.current=V((t=>{ot(t),E({action:t,windowElement:n,whitelist:e})})),o.current=k({onMessage:e=>{s?s(e):h().dispatch(e)},whitelist:t}))}),[e,t,s,V])},O=[I,Rt,kt,P,J,U,K,X],T=[Y,Z,A,Et,tt,Ft,Ut,It,Ot,Tt,_t,et,Vt,Qt,Mt,Dt,$t,qt,Ht,Bt,Wt,jt,xt,Gt,zt,Jt,Kt,Xt,Yt,Zt];if(T.some((e=>O.some((t=>(null==t?void 0:t.toString())===(null==e?void 0:e.toString()))))))throw new Error("Output action is duplicated with input action");const se=()=>{const e=structuredClone(h().getState());return e.openapi&&(e.openapi=void 0),e.auth&&(e.auth={...e.auth,token:null}),e},Ne=e=>{const t=nt({sendWhitelist:T,receiveWhitelist:O,onMessage:e=>{ot(e)||h().dispatch(e)}}),s=w((()=>{var t;const s=A(se());E({action:s,windowElement:(null==(t=e.current)?void 0:t.contentWindow)??null,whitelist:[s]})}),[e]),r=w((()=>{var r;t((null==(r=e.current)?void 0:r.contentWindow)??null),s()}),[t,e,s]);p((()=>{const e=k({onMessage:e=>{e.type===P.type&&r()},whitelist:[P]});return()=>e()}),[r])},_=()=>{const e=W();return e.pathname+e.search},oe=({lastLocationPathRef:e})=>{const t=b(),s=_(),r=u(d.selectors.selectPath),o=u(d.selectors.selectTransitionPath);p((()=>{s!==e.current&&(e.current=s,s!==r&&s!==o&&t(I(s)))}),[r,o,s])},ne=({canShowMessage:e,message:t="Are you sure you want to leave?"})=>{const s=b(),r=u(d.selectors.selectPath),o=e=>(e.preventDefault(),e.returnValue=t,t);p((()=>(window.onbeforeunload=e?o:null,()=>{window.onbeforeunload=null})),[e,t]);const n=ut(e),a="blocked"===n.state;p((()=>{a&&(confirm(t)?(n.proceed(),s(X(null))):(n.reset(),s(I(r))))}),[a])},re=()=>{const e=b(),t=u(d.selectors.selectPath),s=_();return{setPath:({transitionPath:r})=>{r&&s===r&&t!==r&&e(tt(r))}}},ae=()=>{const e=j(),t=W(),s=b(),r=g(""),o=u(d.selectors.selectPath),n=u(d.selectors.selectTransitionPath),{setPath:a}=re(),{shouldBlock:i,message:l}=u(d.selectors.selectConfirmLeavePage)||{};ne({canShowMessage:!!i,message:l}),oe({lastLocationPathRef:r}),p((()=>{a({transitionPath:n})}),[t,o,n,s]),p((()=>{n&&n!==r.current&&(r.current=n,e(n,{replace:!1}))}),[n,e])},ce=$((()=>(ae(),null)));ce.displayName="HostRouteObserver";const ie=e=>{const t=g(e),[s,r]=q(null);return p((()=>{const e=k({onMessage:e=>{var s;if(e.type===A.type){const o=at(e.payload);r(o),null==(s=t.current)||s.call(t,o)}},whitelist:[A]}),s=P();return E({action:s,windowElement:window.parent,whitelist:[s]}),()=>e()}),[]),{store:s}},N={[Y.type]:()=>dt(),[Z.type]:()=>pt()},le=e=>Object.keys(N).includes(e.type),ue=e=>le(e)&&e.type in N?N[e.type]():null,{path:R,search:de}=Pt.init();R&&window.history.replaceState({},"",`${R}${de||""}`);const Re=()=>{const[e,t]=q(null),s=nt({sendWhitelist:O,receiveWhitelist:T,onMessage:e=>{ue(e)||h().dispatch(e)}}),r=w((e=>{t(e),s(window.parent)}),[s]);return ie(r),{store:e,path:R}},pe=()=>{const e=j(),t=g(""),s=_(),r=u(d.selectors.selectPath);p((()=>{r&&r!==t.current&&(t.current=r,s!==r&&e(r,{replace:!0}))}),[r,e,s])},ge=$((()=>(pe(),null)));ge.displayName="RemoteRouteObserver";export{ce as HostRouteObserver,ge as RemoteRouteObserver,ot as callHostApiAction,ue as callRemoteApiAction,k as listenMessage,se as prepareState,E as sendMessage,Pt as staticState,Ne as useHostStoreConnect,ie as usePreloadedStore,Re as useRemoteStoreConnect};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wellesley/host-remote",
3
- "version": "1.0.146",
3
+ "version": "1.0.148",
4
4
  "license": "UNLICENSED",
5
5
  "main": "index.mjs",
6
6
  "files": [