@microsoft/teams-js
Version:
Microsoft Client SDK for building app for Microsoft hosts
2 lines (1 loc) • 2.43 kB
JavaScript
import e from"../../../../../node_modules/.pnpm/uuid@9.0.1/node_modules/uuid/dist/esm-browser/v4.js";const t="1.0.1",n={onMessage:function(e,t){if(!e||!e.data||"object"!=typeof e.data||null===e.data)return void a("Invalid message format, ignoring. Message: %o",e);if(!function(e,t){if(t===o)try{return"https:"===new URL(t).protocol}catch(e){return d("Invalid message origin URL:",e),!1}return!1}(e.source,e.origin))return void a("Message source/origin not allowed, ignoring.");const{args:n}=e.data,[,r]=null!=n?n:[],i=(()=>{try{return JSON.parse(r)}catch(e){return d("Failed to parse response message:",e),null}})();if(!i||"NestedAppAuthResponse"!==i.messageType)return void a("Invalid response format, ignoring. Message: %o",e);t(r)}};let o=null,r=!1;function i(t,i,p=!1){if(r=p,!t)throw new Error("Cannot polyfill nestedAppAuthBridge as the current window does not exist");if(!i)throw new Error("Top origin is required to initialize the Nested App Auth Bridge");try{const e=new URL(i);if("https:"!==e.protocol)throw new Error(`Invalid top origin: ${i}. Only HTTPS origins are allowed.`);o=e.origin}catch(e){throw new Error(`Failed to initialize bridge: invalid top origin: ${i}`)}const u=t;if(u.nestedAppAuthBridge)return void a("Nested App Auth Bridge is already present");const g=function(t){const r=new WeakMap,{onMessage:i}=n,p=e=>t=>i(t,e);return{addEventListener:(e,n)=>{if("message"===e){const o=p(n);r.set(n,o),t.addEventListener(e,o)}else a(`Event ${e} is not supported by nestedAppAuthBridge`)},postMessage:n=>{if(!t.top)throw new Error("window.top is not available for posting messages");try{const r=JSON.parse(n);if("object"==typeof r&&"NestedAppAuthRequest"===r.messageType){const r=function(t){const n=Date.now();return{id:s(),uuid:e(),func:"nestedAppAuth.execute",timestamp:n,apiVersionTag:"v2_nestedAppAuth.execute",monotonicTimestamp:n,args:[],data:t}}(n);if(t===t.top||!o)return void d("Not in an embedded iframe; skipping postMessage.");t.top.postMessage(r,o)}}catch(e){return void d("Failed to parse message:",e,"Original message:",n)}},removeEventListener:(e,n)=>{const o=r.get(n);o&&(t.removeEventListener(e,o),r.delete(n))}}}(u);g&&(u.nestedAppAuthBridge=g)}function s(){return"undefined"!=typeof crypto&&crypto.randomUUID?crypto.randomUUID():Math.random().toString(36).substring(2,11)}function a(...e){r&&console.log(...e)}function d(...e){r&&console.error(...e)}export{i as initialize,t as version};