UNPKG

@arrowhealth/bridge-sdk

Version:

Bridge SDK provides web applications the ability to integrate with the Bridge Platform.

4 lines (3 loc) 7.19 kB
/* Bridge SDK provided by Arrow Health 2021-present. All rights reserved. */ !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).bridge={})}(this,(function(e){"use strict";const n="bridge::",t=!(!window.opener||window.opener===window),o=!t&&window.parent!==window,i=(window.name+"").includes("bridge_"),u={CAPTURE_USER_EVENTS:n+"capture_user_events",CLEAR_CACHE:n+"clear_cache",CLOSE_APP:n+"close_app",DISABLE_TILE:n+"disable_tile",ENABLE_TILE:n+"enable_tile",GET_AUTH_STATUS:n+"get_auth_status",GET_AUTH_USER:n+"get_auth_user",GET_ORG:n+"get_org",GET_PAGE:n+"get_page",GET_PAGE_DETAILS:n+"get_page_details",GET_PATIENT_INFO:n+"get_patient",GET_PLATFORM:n+"get_platform",GET_USER_SESSION:n+"get_user_session",HIDE_TILE:n+"hide_tile",LOGIN:n+"login",LOGOUT:n+"logout",OPEN_APP:n+"open_app",PROXY_READY:n+"proxy_ready",PUSH_NOTIFICATION:n+"push_notification",RELEASE_USER_EVENTS:n+"release_user_events",SET_AUTH_STATUS:n+"set_auth_status",SET_AUTH_USER:n+"set_auth_user",SET_BADGE_COUNT:n+"set_badge_count",SET_ORG:n+"set_org",SET_PATIENT_INFO:n+"set_patient",SHOW_TILE:n+"show_tile"};var r;function a(e,n,t,o){return new(t||(t=Promise))((function(i,u){function r(e){try{s(o.next(e))}catch(e){u(e)}}function a(e){try{s(o.throw(e))}catch(e){u(e)}}function s(e){var n;e.done?i(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(r,a)}s((o=o.apply(e,n||[])).next())}))}e.PlatformKind=void 0,(r=e.PlatformKind||(e.PlatformKind={})).Other="Other",r.Athena="Athena",r.eCW="eCW","function"==typeof SuppressedError&&SuppressedError;const s="BRIDGE_EVENT",E=(e,n,t)=>{e&&e.postMessage?e.postMessage(JSON.stringify({data:t,event:n,eventType:s}),"*"):console.warn('[ BRIDGE SDK ] :: emitToChild is missing required "win" param')},_=(e,n)=>{let t=window.parent;window.opener&&(t=window.opener),window!==t?window.name?t.postMessage(JSON.stringify({appId:window.name,data:n,event:e,eventType:s}),"*"):console.warn("No app id assigned. Cannot post request."):console.warn("Cannot post message to self. No parent window found.")},T=(e,n)=>{const t=e=>{n(e.detail||{})};return window.addEventListener(e,t),()=>window.removeEventListener(e,t)};window.addEventListener("message",(e=>{let n;try{"string"==typeof e.data&&(n=JSON.parse(e.data),n.win=e.source,n.eventType===s&&window.dispatchEvent(new CustomEvent(n.event,{detail:n})))}catch(e){}}),!1);var d=Object.freeze({__proto__:null,clearCache:function(){_(u.CLEAR_CACHE)},getOrg:function(){return new Promise((e=>{i||e(null);const n=T(u.GET_ORG,(({data:t})=>{n(),e(t)}));_(u.GET_ORG)}))},getRuntimeDetails:function(){return new Promise((e=>{i||e(null);const n=T(u.GET_PAGE_DETAILS,(({data:t})=>{n(),e(t)}));_(u.GET_PAGE_DETAILS)}))},getUserSession:function(){return new Promise((e=>{i||e(null);const n=T(u.GET_USER_SESSION,(({data:t})=>{n(),e(t)}));_(u.GET_USER_SESSION)}))},login:function(e,n,t){return new Promise((o=>{i||o(null);const r=T(u.LOGIN,(({data:e})=>{r(),o(e)}));_(u.LOGIN,{realm:e,user:n,pw:t})}))},logout:function(){return new Promise((e=>{i||e(null);const n=T(u.LOGOUT,(()=>{n(),e()}));_(u.LOGOUT)}))},openApp:function(){_(u.OPEN_APP)},setAuthUser:function(e){_(u.SET_AUTH_USER,e)},setOrg:function(e){_(u.SET_ORG,e)}});var p=Object.freeze({__proto__:null,onCaptureUserEventsRequest:function(e){return T(u.CAPTURE_USER_EVENTS,(n=>{e(n.appId)}))},onClearCacheRequest:function(e){return T(u.CLEAR_CACHE,(n=>{e(n.appId)}))},onCloseAppRequest:function(e){return T(u.CLOSE_APP,(n=>{e(n.appId)}))},onDisableTileRequest:function(e){return T(u.DISABLE_TILE,(n=>{e(n.appId)}))},onEnableTileRequest:function(e){return T(u.ENABLE_TILE,(n=>{e(n.appId)}))},onGetAuthStatusRequest:function(e){return T(u.GET_AUTH_STATUS,(n=>{e(n.appId,(e=>{E(n.win,n.event,e)}),n.data)}))},onGetAuthUserRequest:function(e){return T(u.GET_AUTH_USER,(n=>{e(n.appId,(e=>{E(n.win,n.event,e)}))}))},onGetOrgRequest:function(e){return T(u.GET_ORG,(n=>{e(n.appId,(e=>{E(n.win,n.event,e)}))}))},onGetPageRequest:function(e){return T(u.GET_PAGE,(n=>{var t;e(n.appId,!!(null===(t=n.data)||void 0===t?void 0:t.deep),(e=>{E(n.win,n.event,e)}))}))},onGetPatientRequest:function(e){return T(u.GET_PATIENT_INFO,(n=>{e(n.appId,(e=>{E(n.win,n.event,e)}))}))},onGetPlatformRequest:function(e){return T(u.GET_PLATFORM,(n=>{e(n.appId,(e=>{E(n.win,n.event,e)}))}))},onGetRuntimeDetailsRequest:function(e){return T(u.GET_PAGE_DETAILS,(n=>{e(n.appId,(e=>{E(n.win,n.event,e)}))}))},onGetUserSessionRequest:function(e){return T(u.GET_USER_SESSION,(n=>{e(n.appId,(e=>{E(n.win,n.event,e)}))}))},onHideTileRequest:function(e){return T(u.HIDE_TILE,(n=>{e(n.appId)}))},onLoginRequest:function(e){return T(u.LOGIN,(n=>{e(n.appId,n.data.realm,n.data.user,n.data.pw,(e=>{E(n.win,n.event,e)}))}))},onLogoutRequest:function(e){return T(u.LOGOUT,(n=>{e(n.appId,(()=>E(n.win,n.event)))}))},onOpenAppRequest:function(e){return T(u.OPEN_APP,(n=>{e(n.appId)}))},onProxyReady:function(e){return T(u.PROXY_READY,(n=>{e(n.appId)}))},onPushNotificationRequest:function(e){return T(u.PUSH_NOTIFICATION,(n=>{e(n.appId,n.data)}))},onReleaseUserEventsRequest:function(e){return T(u.RELEASE_USER_EVENTS,(n=>{e(n.appId)}))},onSetAuthStatusRequest:function(e){return T(u.SET_AUTH_STATUS,(n=>{e(n.appId,n.data)}))},onSetAuthUserRequest:function(e){return T(u.SET_AUTH_USER,(n=>{e(n.appId,n.data)}))},onSetBadgeCountRequest:function(e){return T(u.SET_BADGE_COUNT,(n=>{const t=n.data;e(n.appId,t||0)}))},onSetOrgRequest:function(e){return T(u.SET_ORG,(n=>{e(n.appId,n.data)}))},onShowTileRequest:function(e){return T(u.SHOW_TILE,(n=>{e(n.appId)}))},setPatient:function(e,n){E(e,u.SET_PATIENT_INFO,n)}});const c=t,S=o,f=i;e.$=p,e.$$=d,e.captureUserEvents=function(){_(u.CAPTURE_USER_EVENTS)},e.closeApp=function(){_(u.CLOSE_APP)},e.disableTile=function(){_(u.DISABLE_TILE)},e.enableTile=function(){_(u.ENABLE_TILE)},e.getAuthStatus=function(){return new Promise((e=>{i||e(null);const n=T(u.GET_AUTH_STATUS,(({data:t})=>{n(),e(t||"ready")}));_(u.GET_AUTH_STATUS)}))},e.getAuthUser=function(){return new Promise((e=>{i||e(null);const n=T(u.GET_AUTH_USER,(({data:t})=>{n(),e(t)}));_(u.GET_AUTH_USER)}))},e.getPage=function(e=!1){return new Promise((n=>{i||n(null);const t=T(u.GET_PAGE,(({data:e})=>{t(),n(e)}));_(u.GET_PAGE,{deep:e})}))},e.getPatient=function(){return a(this,void 0,void 0,(function*(){return new Promise((e=>{i||e(null);const n=T(u.GET_PATIENT_INFO,(({data:t})=>{n(),e(t)}));_(u.GET_PATIENT_INFO)}))}))},e.getPlatform=function(){return a(this,void 0,void 0,(function*(){return new Promise((e=>{i||e(null);const n=T(u.GET_PLATFORM,(({data:t})=>{n(),e(t)}));_(u.GET_PLATFORM)}))}))},e.hideTile=function(){_(u.HIDE_TILE)},e.inBridge=f,e.inIframe=S,e.inPopout=c,e.onPatientChanged=function(e){return T(u.SET_PATIENT_INFO,(n=>e(n.data)))},e.pushNotification=function(e){_(u.PUSH_NOTIFICATION,e)},e.releaseUserEvents=function(){_(u.RELEASE_USER_EVENTS)},e.setAuthStatus=function(e){_(u.SET_AUTH_STATUS,e)},e.setBadgeCount=function(e=0){_(u.SET_BADGE_COUNT,e)},e.showTile=function(){_(u.SHOW_TILE)},e.version="2.7.1"})); //# sourceMappingURL=bridge.min.js.map