Liferay.Loader.define("@liferay/client-extension-web@1.0.22/remote_protocol/bridge",["module","exports","require","frontend-js-web"],(function(e,t,r){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(){window.addEventListener("message",u)},t.VERSION=t.REMOTE_APP_PROTOCOL=void 0;var o=r("frontend-js-web");function n(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,o)}return r}function s(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?n(Object(r),!0).forEach((function(t){a(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):n(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}const e=new Map,d=new Set,f={UNKNOWN:-100,ALREADY_REGISTERED:-101},y="com.liferay.client.extension.protocol";t.REMOTE_APP_PROTOCOL=y;const D=0;t.VERSION=D;const g={};function i(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function c(e,t){if(p(e,t)&&"string"==typeof e[t])return e[t]}function p(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function l(e,t){e.postMessage(s(s({},t),{},{protocol:y,role:"host",version:D}),"*")}function u(t){const{data:r,source:n}=t;if(r&&c(r,"protocol")===y&&"client"===c(r,"role")&&0===function(e,t){if(p(e,t)&&"number"==typeof e[t])return e[t]}(r,"version")){const t=c(r,"appID");if(e.has(n)&&e.get(n)!==t){const e="Attempted to use new UUID ".concat(t," with application that is already registered");return void l(n,{appID:t,code:f.ALREADY_REGISTERED,kind:"error",message:e})}const p=c(r,"command");switch(p){case"fetch":{const{requestID:e}=r;let s=r.resource;s.startsWith("/o/")&&(s=window.location.origin+s);if(new URL(s).origin!==window.location.origin)return void l(n,{appID:t,error:new Error("Invalid resource: Resource must come from permitted origin."),kind:"fetch:reject",requestID:e});const a=r.init,{body:i}=a;if(null==i?void 0:i.__FORM_DATA__){const e=new FormData;Object.entries(i.__FORM_DATA__).forEach((([t,r])=>{e.append(t,r)})),a.body=e}(0,o.fetch)(s,a).then((r=>{g[e]=r,l(n,{appID:t,headers:Array.from(r.headers.entries()),kind:"fetch:resolve",ok:r.ok,redirected:r.redirected,requestID:e,status:r.status,statusText:r.statusText,type:r.type,url:r.url})})).catch((r=>{l(n,{appID:t,error:r,kind:"fetch:reject",requestID:e})}))}break;case"fetch:response:blob":{var s;const{requestID:e}=r;null===(s=g[e])||void 0===s||s.blob().then((r=>{l(n,{appID:t,blob:r,kind:"fetch:response:blob:resolve",requestID:e})})).catch((r=>{l(n,{appID:t,error:r,kind:"fetch:response:blob:reject",requestID:e})}))}break;case"fetch:response:json":{var a;const{requestID:e}=r;null===(a=g[e])||void 0===a||a.json().then((r=>{l(n,{appID:t,json:r,kind:"fetch:response:json:resolve",requestID:e})})).catch((r=>{l(n,{appID:t,error:r,kind:"fetch:response:json:reject",requestID:e})}))}break;case"fetch:response:text":{var u;const{requestID:e}=r;null===(u=g[e])||void 0===u||u.text().then((r=>{l(n,{appID:t,kind:"fetch:response:text:resolve",requestID:e,text:r})})).catch((r=>{l(n,{appID:t,error:r,kind:"fetch:response:text:reject",requestID:e})}))}break;case"get":{const e=c(r,"property"),{requestID:o}=r;let s;"companyId"===e?s=Liferay.ThemeDisplay.getCompanyId():"css"===e?s=Liferay.ThemeDisplay.getCDNBaseURL()+Liferay.ThemeDisplay.getPathThemeRoot()+"/css/clay.css":"defaultLanguageId"===e?s=Liferay.ThemeDisplay.getDefaultLanguageId():"isControlPanel"===e?s=Liferay.ThemeDisplay.isControlPanel():"isSignedIn"===e?s=Liferay.ThemeDisplay.isSignedIn():"languageId"===e?s=Liferay.ThemeDisplay.getLanguageId():"siteGroupId"===e?s=Liferay.ThemeDisplay.getSiteGroupId():"userId"===e?s=Liferay.ThemeDisplay.getUserId():"userName"===e&&(s=Liferay.ThemeDisplay.getUserName()),l(n,void 0!==s?{appID:t,kind:"get:resolve",property:e,requestID:o,value:s}:{appID:t,error:"Unsupported property ".concat(e),kind:"get:reject",property:e,requestID:o})}break;case"navigate":{const e=c(r,"url");e&&(0,o.navigate)(e)}break;case"openToast":{const e=c(r,"type")||"info",t=c(r,"message");t&&(0,o.openToast)({message:i(t),type:i(e)})}break;case"register":{const t=c(r,"appID");if(t)if(d.has(t)){"Attempted to register already registered UUID ".concat(t)}else e.set(n,t),d.add(t),l(n,{appID:t,kind:"registered"})}break;case"unregister":e.has(n)&&d.has(t)&&(e.delete(n),d.delete(t));break;default:"Unexpected command: ".concat(p)}}}}}));
//# sourceMappingURL=bridge.js.map