UNPKG

@microsoft/teams-js

Version:

Microsoft Client SDK for building app for Microsoft hosts

2 lines (1 loc) 1.75 kB
import{GlobalVars as e}from"./globalVars.js";import{getLogger as t,getApiVersionTag as n}from"./telemetry.js";const s=t("nestedAppAuthUtils"),r=s.extend("tryPolyfillWithNestedAppAuthBridge"),o="v2";function i(t,s,i){var p;const u=r;if(e.isFramelessWindow)return void u("Cannot polyfill nestedAppAuthBridge as current window is frameless");if(!s)return void u("Cannot polyfill nestedAppAuthBridge as current window does not exist");if(s.parent!==s.top)return void u("Default NAA bridge injection not supported in nested iframe. Use standalone NAA bridge instead.");const a=(()=>{try{return JSON.parse(t)}catch(e){return null}})();if(!a||!(null===(p=a.supports)||void 0===p?void 0:p.nestedAppAuth))return void u("Cannot polyfill nestedAppAuthBridge as current hub does not support nested app auth");const l=s;if(l.nestedAppAuthBridge)return void u("nestedAppAuthBridge already exists on current window, skipping polyfill");const A=function(e,t){const s=d;if(!e)return s("nestedAppAuthBridge cannot be created as current window does not exist"),null;const{onMessage:r,sendPostMessage:i}=t,p=e=>t=>r(t,e);return{addEventListener:(t,n)=>{"message"===t?e.addEventListener(t,p(n)):s(`Event ${t} is not supported by nestedAppAuthBridge`)},postMessage:e=>{const t=(()=>{try{return JSON.parse(e)}catch(e){return null}})();if(!t||"object"!=typeof t||"NestedAppAuthRequest"!==t.messageType)return void s("Unrecognized data format received by app, message being ignored. Message: %o",e);const r=n(o,"nestedAppAuth.execute");i(e,r)},removeEventListener:(t,n)=>{e.removeEventListener(t,p(n))}}}(l,i);A&&(l.nestedAppAuthBridge=A)}const d=s.extend("createNestedAppAuthBridge");export{o as nestedAppAuthTelemetryVersionNumber,i as tryPolyfillWithNestedAppAuthBridge};