UNPKG

@prismatic-io/embedded

Version:

Embed Prismatic's integration marketplace and workflow designer within your existing application.

144 lines 25.5 kB
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.prismatic={}))})(this,function(e){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var t=Object.create,n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,a=Object.getPrototypeOf,o=Object.prototype.hasOwnProperty,s=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),c=(e,t)=>{let r={};for(var i in e)n(r,i,{get:e[i],enumerable:!0});return t||n(r,Symbol.toStringTag,{value:`Module`}),r},l=(e,t,a,s)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var c=i(t),l=0,u=c.length,d;l<u;l++)d=c[l],!o.call(e,d)&&d!==a&&n(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(s=r(t,d))||s.enumerable});return e},u=(e,r,i)=>(i=e==null?{}:t(a(e)),l(r||!e||!e.__esModule?n(i,`default`,{value:e,enumerable:!0}):i,e));let d={filters:{},initComplete:!1,jwt:``,embeddedDesignerEnabled:!1,prismaticUrl:`https://app.prismatic.io`,screenConfiguration:void 0,theme:void 0,fontConfiguration:void 0,translation:void 0},f=new Set(Object.keys(d)),p=e=>f.has(e),m=(e,t,n)=>{e[t]=n},h=new class{constructor(e){this.state=null,this.defaultState=e}getInitialState(){return JSON.parse(JSON.stringify(this.defaultState))}getStateCopy(){return this.state?JSON.parse(JSON.stringify(this.state)):this.getInitialState()}setState(e){this.state=e}}(d),g=e=>{if(!h.getStateCopy().initComplete)throw Error(`Expected init to be called before calling ${e}`);if(!h.getStateCopy().jwt&&e!==`authenticate`)throw Error(`Expected authenticate to be called before calling ${e}`)};var ee=u(s(((e,t)=>{var n=200,r=`__lodash_hash_undefined__`,i=800,a=16,o=9007199254740991,s=`[object Arguments]`,c=`[object Array]`,l=`[object AsyncFunction]`,u=`[object Boolean]`,d=`[object Date]`,f=`[object Error]`,p=`[object Function]`,m=`[object GeneratorFunction]`,h=`[object Map]`,g=`[object Number]`,ee=`[object Null]`,te=`[object Object]`,_=`[object Proxy]`,v=`[object RegExp]`,ne=`[object Set]`,re=`[object String]`,ie=`[object Undefined]`,y=`[object WeakMap]`,ae=`[object ArrayBuffer]`,oe=`[object DataView]`,b=`[object Float32Array]`,x=`[object Float64Array]`,se=`[object Int8Array]`,ce=`[object Int16Array]`,le=`[object Int32Array]`,S=`[object Uint8Array]`,C=`[object Uint8ClampedArray]`,w=`[object Uint16Array]`,ue=`[object Uint32Array]`,T=/[\\^$.*+?()[\]{}|]/g,de=/^\[object .+?Constructor\]$/,fe=/^(?:0|[1-9]\d*)$/,E={};E[b]=E[x]=E[se]=E[ce]=E[le]=E[S]=E[C]=E[w]=E[ue]=!0,E[s]=E[c]=E[ae]=E[u]=E[oe]=E[d]=E[f]=E[p]=E[h]=E[g]=E[te]=E[v]=E[ne]=E[re]=E[y]=!1;var pe=typeof global==`object`&&global&&global.Object===Object&&global,me=typeof self==`object`&&self&&self.Object===Object&&self,D=pe||me||Function(`return this`)(),he=typeof e==`object`&&e&&!e.nodeType&&e,O=he&&typeof t==`object`&&t&&!t.nodeType&&t,k=O&&O.exports===he,A=k&&pe.process,j=function(){try{return O&&O.require&&O.require(`util`).types||A&&A.binding&&A.binding(`util`)}catch{}}(),M=j&&j.isTypedArray;function ge(e,t,n){switch(n.length){case 0:return e.call(t);case 1:return e.call(t,n[0]);case 2:return e.call(t,n[0],n[1]);case 3:return e.call(t,n[0],n[1],n[2])}return e.apply(t,n)}function _e(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}function ve(e){return function(t){return e(t)}}function ye(e,t){return e?.[t]}function be(e,t){return function(n){return e(t(n))}}var N=Array.prototype,xe=Function.prototype,P=Object.prototype,F=D[`__core-js_shared__`],I=xe.toString,L=P.hasOwnProperty,R=function(){var e=/[^.]+$/.exec(F&&F.keys&&F.keys.IE_PROTO||``);return e?`Symbol(src)_1.`+e:``}(),z=P.toString,Se=I.call(Object),Ce=RegExp(`^`+I.call(L).replace(T,`\\$&`).replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,`$1.*?`)+`$`),B=k?D.Buffer:void 0,V=D.Symbol,H=D.Uint8Array,U=B?B.allocUnsafe:void 0,W=be(Object.getPrototypeOf,Object),we=Object.create,Te=P.propertyIsEnumerable,Ee=N.splice,G=V?V.toStringTag:void 0,K=function(){try{var e=xt(Object,`defineProperty`);return e({},``,{}),e}catch{}}(),De=B?B.isBuffer:void 0,Oe=Math.max,ke=Date.now,Ae=xt(D,`Map`),q=xt(Object,`create`),je=function(){function e(){}return function(t){if(!Q(t))return{};if(we)return we(t);e.prototype=t;var n=new e;return e.prototype=void 0,n}}();function J(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function Me(){this.__data__=q?q(null):{},this.size=0}function Ne(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=+!!t,t}function Pe(e){var t=this.__data__;if(q){var n=t[e];return n===r?void 0:n}return L.call(t,e)?t[e]:void 0}function Fe(e){var t=this.__data__;return q?t[e]!==void 0:L.call(t,e)}function Ie(e,t){var n=this.__data__;return this.size+=+!this.has(e),n[e]=q&&t===void 0?r:t,this}J.prototype.clear=Me,J.prototype.delete=Ne,J.prototype.get=Pe,J.prototype.has=Fe,J.prototype.set=Ie;function Y(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function Le(){this.__data__=[],this.size=0}function Re(e){var t=this.__data__,n=tt(t,e);return n<0?!1:(n==t.length-1?t.pop():Ee.call(t,n,1),--this.size,!0)}function ze(e){var t=this.__data__,n=tt(t,e);return n<0?void 0:t[n][1]}function Be(e){return tt(this.__data__,e)>-1}function Ve(e,t){var n=this.__data__,r=tt(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this}Y.prototype.clear=Le,Y.prototype.delete=Re,Y.prototype.get=ze,Y.prototype.has=Be,Y.prototype.set=Ve;function X(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function He(){this.size=0,this.__data__={hash:new J,map:new(Ae||Y),string:new J}}function Ue(e){var t=bt(this,e).delete(e);return this.size-=+!!t,t}function We(e){return bt(this,e).get(e)}function Ge(e){return bt(this,e).has(e)}function Ke(e,t){var n=bt(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this}X.prototype.clear=He,X.prototype.delete=Ue,X.prototype.get=We,X.prototype.has=Ge,X.prototype.set=Ke;function Z(e){var t=this.__data__=new Y(e);this.size=t.size}function qe(){this.__data__=new Y,this.size=0}function Je(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n}function Ye(e){return this.__data__.get(e)}function Xe(e){return this.__data__.has(e)}function Ze(e,t){var r=this.__data__;if(r instanceof Y){var i=r.__data__;if(!Ae||i.length<n-1)return i.push([e,t]),this.size=++r.size,this;r=this.__data__=new X(i)}return r.set(e,t),this.size=r.size,this}Z.prototype.clear=qe,Z.prototype.delete=Je,Z.prototype.get=Ye,Z.prototype.has=Xe,Z.prototype.set=Ze;function Qe(e,t){var n=Rt(e),r=!n&&Lt(e),i=!n&&!r&&Vt(e),a=!n&&!r&&!i&&Gt(e),o=n||r||i||a,s=o?_e(e.length,String):[],c=s.length;for(var l in e)(t||L.call(e,l))&&!(o&&(l==`length`||i&&(l==`offset`||l==`parent`)||a&&(l==`buffer`||l==`byteLength`||l==`byteOffset`)||wt(l,c)))&&s.push(l);return s}function $e(e,t,n){(n!==void 0&&!It(e[t],n)||n===void 0&&!(t in e))&&nt(e,t,n)}function et(e,t,n){var r=e[t];(!(L.call(e,t)&&It(r,n))||n===void 0&&!(t in e))&&nt(e,t,n)}function tt(e,t){for(var n=e.length;n--;)if(It(e[n][0],t))return n;return-1}function nt(e,t,n){t==`__proto__`&&K?K(e,t,{configurable:!0,enumerable:!0,value:n,writable:!0}):e[t]=n}var rt=yt();function it(e){return e==null?e===void 0?ie:ee:G&&G in Object(e)?St(e):At(e)}function at(e){return $(e)&&it(e)==s}function ot(e){return!Q(e)||Dt(e)?!1:(Ht(e)?Ce:de).test(Ft(e))}function st(e){return $(e)&&Ut(e.length)&&!!E[it(e)]}function ct(e){if(!Q(e))return kt(e);var t=Ot(e),n=[];for(var r in e)r==`constructor`&&(t||!L.call(e,r))||n.push(r);return n}function lt(e,t,n,r,i){e!==t&&rt(t,function(a,o){if(i||=new Z,Q(a))ut(e,t,o,n,lt,r,i);else{var s=r?r(Mt(e,o),a,o+``,e,t,i):void 0;s===void 0&&(s=a),$e(e,o,s)}},qt)}function ut(e,t,n,r,i,a,o){var s=Mt(e,n),c=Mt(t,n),l=o.get(c);if(l){$e(e,n,l);return}var u=a?a(s,c,n+``,e,t,o):void 0,d=u===void 0;if(d){var f=Rt(c),p=!f&&Vt(c),m=!f&&!p&&Gt(c);u=c,f||p||m?Rt(s)?u=s:Bt(s)?u=gt(s):p?(d=!1,u=pt(c,!0)):m?(d=!1,u=ht(c,!0)):u=[]:Wt(c)||Lt(c)?(u=s,Lt(s)?u=Kt(s):(!Q(s)||Ht(s))&&(u=Ct(c))):d=!1}d&&(o.set(c,u),i(u,c,r,a,o),o.delete(c)),$e(e,n,u)}function dt(e,t){return Nt(jt(e,t,Xt),e+``)}var ft=K?function(e,t){return K(e,`toString`,{configurable:!0,enumerable:!1,value:Yt(t),writable:!0})}:Xt;function pt(e,t){if(t)return e.slice();var n=e.length,r=U?U(n):new e.constructor(n);return e.copy(r),r}function mt(e){var t=new e.constructor(e.byteLength);return new H(t).set(new H(e)),t}function ht(e,t){var n=t?mt(e.buffer):e.buffer;return new e.constructor(n,e.byteOffset,e.length)}function gt(e,t){var n=-1,r=e.length;for(t||=Array(r);++n<r;)t[n]=e[n];return t}function _t(e,t,n,r){var i=!n;n||={};for(var a=-1,o=t.length;++a<o;){var s=t[a],c=r?r(n[s],e[s],s,n,e):void 0;c===void 0&&(c=e[s]),i?nt(n,s,c):et(n,s,c)}return n}function vt(e){return dt(function(t,n){var r=-1,i=n.length,a=i>1?n[i-1]:void 0,o=i>2?n[2]:void 0;for(a=e.length>3&&typeof a==`function`?(i--,a):void 0,o&&Tt(n[0],n[1],o)&&(a=i<3?void 0:a,i=1),t=Object(t);++r<i;){var s=n[r];s&&e(t,s,r,a)}return t})}function yt(e){return function(t,n,r){for(var i=-1,a=Object(t),o=r(t),s=o.length;s--;){var c=o[e?s:++i];if(n(a[c],c,a)===!1)break}return t}}function bt(e,t){var n=e.__data__;return Et(t)?n[typeof t==`string`?`string`:`hash`]:n.map}function xt(e,t){var n=ye(e,t);return ot(n)?n:void 0}function St(e){var t=L.call(e,G),n=e[G];try{e[G]=void 0;var r=!0}catch{}var i=z.call(e);return r&&(t?e[G]=n:delete e[G]),i}function Ct(e){return typeof e.constructor==`function`&&!Ot(e)?je(W(e)):{}}function wt(e,t){var n=typeof e;return t??=o,!!t&&(n==`number`||n!=`symbol`&&fe.test(e))&&e>-1&&e%1==0&&e<t}function Tt(e,t,n){if(!Q(n))return!1;var r=typeof t;return(r==`number`?zt(n)&&wt(t,n.length):r==`string`&&t in n)?It(n[t],e):!1}function Et(e){var t=typeof e;return t==`string`||t==`number`||t==`symbol`||t==`boolean`?e!==`__proto__`:e===null}function Dt(e){return!!R&&R in e}function Ot(e){var t=e&&e.constructor;return e===(typeof t==`function`&&t.prototype||P)}function kt(e){var t=[];if(e!=null)for(var n in Object(e))t.push(n);return t}function At(e){return z.call(e)}function jt(e,t,n){return t=Oe(t===void 0?e.length-1:t,0),function(){for(var r=arguments,i=-1,a=Oe(r.length-t,0),o=Array(a);++i<a;)o[i]=r[t+i];i=-1;for(var s=Array(t+1);++i<t;)s[i]=r[i];return s[t]=n(o),ge(e,this,s)}}function Mt(e,t){if(!(t===`constructor`&&typeof e[t]==`function`)&&t!=`__proto__`)return e[t]}var Nt=Pt(ft);function Pt(e){var t=0,n=0;return function(){var r=ke(),o=a-(r-n);if(n=r,o>0){if(++t>=i)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}function Ft(e){if(e!=null){try{return I.call(e)}catch{}try{return e+``}catch{}}return``}function It(e,t){return e===t||e!==e&&t!==t}var Lt=at(function(){return arguments}())?at:function(e){return $(e)&&L.call(e,`callee`)&&!Te.call(e,`callee`)},Rt=Array.isArray;function zt(e){return e!=null&&Ut(e.length)&&!Ht(e)}function Bt(e){return $(e)&&zt(e)}var Vt=De||Zt;function Ht(e){if(!Q(e))return!1;var t=it(e);return t==p||t==m||t==l||t==_}function Ut(e){return typeof e==`number`&&e>-1&&e%1==0&&e<=o}function Q(e){var t=typeof e;return e!=null&&(t==`object`||t==`function`)}function $(e){return typeof e==`object`&&!!e}function Wt(e){if(!$(e)||it(e)!=te)return!1;var t=W(e);if(t===null)return!0;var n=L.call(t,`constructor`)&&t.constructor;return typeof n==`function`&&n instanceof n&&I.call(n)==Se}var Gt=M?ve(M):st;function Kt(e){return _t(e,qt(e))}function qt(e){return zt(e)?Qe(e,!0):ct(e)}var Jt=vt(function(e,t,n){lt(e,t,n)});function Yt(e){return function(){return e}}function Xt(e){return e}function Zt(){return!1}t.exports=Jt}))());function te(e){var t=[];if(e.length===0)return``;if(typeof e[0]!=`string`)throw TypeError(`Url must be a string. Received `+e[0]);e[0].match(/^[^/:]+:\/*$/)&&e.length>1&&(e[0]=e.shift()+e[0]),e[0].match(/^file:\/\/\//)?e[0]=e[0].replace(/^([^/:]+):\/*/,`$1:///`):e[0]=e[0].replace(/^([^/:]+):\/*/,`$1://`);for(var n=0;n<e.length;n++){var r=e[n];if(typeof r!=`string`)throw TypeError(`Url must be a string. Received `+r);r!==``&&(n>0&&(r=r.replace(/^[\/]+/,``)),r=n<e.length-1?r.replace(/[\/]+$/,``):r.replace(/[\/]+$/,`/`),t.push(r))}var i=t.join(`/`);i=i.replace(/\/(\?|&|#[^!])/g,`$1`);var a=i.split(`?`);return i=a.shift()+(a.length>0?`?`:``)+a.join(`&`),i}function _(){return te(typeof arguments[0]==`object`?arguments[0]:[].slice.call(arguments))}let v=e=>e.usePopover===!0,ne=function(e){return e.INSTANCE_CONFIGURATION_CANCELED=`INSTANCE_CONFIGURATION_CANCELED`,e.INSTANCE_CONFIGURATION_CLOSED=`INSTANCE_CONFIGURATION_CLOSED`,e.INSTANCE_CONFIGURATION_LOADED=`INSTANCE_CONFIGURATION_LOADED`,e.INSTANCE_CONFIGURATION_PAGE_LOADED=`INSTANCE_CONFIGURATION_PAGE_LOADED`,e.INSTANCE_CONFIGURATION_OPENED=`INSTANCE_CONFIGURATION_OPENED`,e.INSTANCE_CREATED=`INSTANCE_CREATED`,e.INSTANCE_DELETED=`INSTANCE_DELETED`,e.INSTANCE_DEPLOYED=`INSTANCE_DEPLOYED`,e.MARKETPLACE_CLOSED=`MARKETPLACE_CLOSED`,e.POPOVER_CLOSE_REQUESTED=`POPOVER_CLOSE_REQUESTED`,e.POPOVER_CLOSED=`POPOVER_CLOSED`,e.SET_CONFIG_VAR=`SET_CONFIG_VAR`,e.SET_FILTERS=`SET_FILTERS`,e.SET_SCREEN_CONFIGURATION=`SET_SCREEN_CONFIGURATION`,e.SET_TOKEN=`SET_TOKEN`,e.SET_TRANSLATION=`SET_TRANSLATION`,e.SET_VERSION=`SET_VERSION`,e.USER_CONFIGURATION_CLOSED=`USER_CONFIGURATION_CLOSED`,e.USER_CONFIGURATION_DELETED=`USER_CONFIGURATION_DELETED`,e.USER_CONFIGURATION_DEPLOYED=`USER_CONFIGURATION_DEPLOYED`,e.USER_CONFIGURATION_LOADED=`USER_CONFIGURATION_LOADED`,e.USER_CONFIGURATION_PAGE_LOADED=`USER_CONFIGURATION_PAGE_LOADED`,e.USER_CONFIGURATION_OPENED=`USER_CONFIGURATION_OPENED`,e.WORKFLOW_ENABLED=`WORKFLOW_ENABLED`,e.WORKFLOW_DELETED=`WORKFLOW_DELETED`,e.WORKFLOW_DISABLED=`WORKFLOW_DISABLED`,e}({}),re=()=>document.querySelector(ue),ie=()=>{re()?.classList.add(T)},y=()=>{let e=E(`${C} > iframe`);me(e)&&(e.contentWindow?.postMessage({event:`MARKETPLACE_CLOSED`},`*`),window.postMessage({event:`POPOVER_CLOSED`},`*`),re()?.classList.remove(T))},ae=e=>Array.from(document.getElementsByTagName(`iframe`)).find(t=>t.contentWindow===e.source),oe=e=>`iframe`in e,b=e=>{let t=oe(e)?e.iframe:pe(e.selector);me(t)&&t.contentWindow?.postMessage(e.event,`*`)},x=`pio__embedded`,se=`pio__iframe`,ce=`pio__iframe-preload`,le=`pio__styles`,S=`pio__iframeContainer`,C=`#${x} .${S}`,w=`pio__overlay`,ue=`#${x} > .${w}`,T=`${w}--is_visible`,de=`pio__popover`,fe=`pio__closeBtn`,E=e=>document.querySelector(e),pe=e=>document.querySelector(`${e||C} > iframe`),me=e=>!!(e&&e.tagName===`IFRAME`),D=(e,t,n)=>{!v(t)&&!t.selector&&console.error(`Could not find display selector.`);let r=E(v(t)?C:t.selector);if(!r)return;let i=h.getStateCopy();t&&Object.entries(t).forEach(([e,t])=>{if(p(e)){let n=i[e];m(i,e,n instanceof Object?(0,ee.default)(n,t):t)}});let a=new URLSearchParams({...n,embed:`true`});i.theme&&a.set(`theme`,i.theme),i.screenConfiguration?.initializing&&a.set(`initializing`,JSON.stringify(i.screenConfiguration.initializing)),i.fontConfiguration&&a.set(`fontConfiguration`,JSON.stringify(i.fontConfiguration)),r.innerHTML=` <iframe id="${se}" src="${`${_(i.prismaticUrl,e)}?${a}`}" height="100%" width="100%" frameBorder="0" allow="clipboard-read; clipboard-write" ></iframe> `;let o=r.querySelector(`iframe`);if(o){let e=new AbortController;he(e),window.addEventListener(`message`,e=>{e.data?.event===`PRISMATIC_INITIALIZED`?(b({iframe:o,event:{event:`SET_TOKEN`,data:i.jwt}}),b({iframe:o,event:{event:`SET_VERSION`,data:`4.12.1`}}),b({iframe:o,event:{event:`SET_TRANSLATION`,data:i.translation}}),b({iframe:o,event:{event:`SET_SCREEN_CONFIGURATION`,data:v(t)?{...i.screenConfiguration??{},isInPopover:!0}:i.screenConfiguration}}),b({iframe:o,event:{event:`SET_FILTERS`,data:i.filters}})):e.data?.event===`POPOVER_CLOSE_REQUESTED`&&y()},{signal:e.signal}),t?.autoFocusIframe!==!1&&o.addEventListener(`mouseenter`,()=>{o.focus()},{signal:e.signal})}v(t)&&ie()},he=e=>{new MutationObserver((t,n)=>{for(let r of t)if(r.type===`childList`){let t=Array.from(r.removedNodes);for(let r of t)r.nodeType===Node.ELEMENT_NODE&&(r.tagName===`IFRAME`&&r.id===`pio__iframe`||r.querySelector(`iframe#pio__iframe`)!==null)&&(e.abort(),n.disconnect())}}).observe(document.body,{attributes:!1,childList:!0,subtree:!0})},O=({...e})=>{if(g(`configureInstance`),k(e)){let{instanceId:t,skipRedirectOnRemove:n,...r}=e;return D(`/find-integration-marketplace/`,r,{instanceId:t,...n?{skipRedirectOnRemove:`true`}:{}})}if(A(e)){let{integrationId:t,skipRedirectOnRemove:n,...r}=e;return D(`/find-integration-marketplace/`,r,{integrationId:t,...n?{skipRedirectOnRemove:`true`}:{}})}if(j(e)){let{integrationName:t,skipRedirectOnRemove:n,...r}=e;D(`/find-integration-marketplace/`,r,{integrationName:t,...n?{skipRedirectOnRemove:`true`}:{}})}},k=e=>!!(`instanceId`in e&&e.instanceId),A=e=>!!(`integrationId`in e&&e.integrationId),j=e=>!!(`integrationName`in e&&e.integrationName),M=async({query:e,variables:t})=>{g(`authenticate`);let{jwt:n,prismaticUrl:r}=h.getStateCopy();return await(await fetch(_(r,`api`),{method:`POST`,headers:{"Content-Type":`application/json`,Accept:`application/json`,Authorization:`Bearer ${n}`},body:JSON.stringify({query:e,variables:t})})).json()},ge=`The authenticate method expects an object containing a token and additional optional configuration.`,_e=[`token`],ve=async e=>{if(g(`authenticate`),!e)throw Error(ge);let t=new Set(Object.keys(e));if(!_e.every(e=>t.has(e)))throw Error(ge);let{token:n}=e,r=document.getElementById(se),i=h.getStateCopy();i.jwt!==n&&r&&b({iframe:r,event:{event:`SET_TOKEN`,data:n}});let a=e.prismaticUrl??i.prismaticUrl,o=await fetch(_(a,`embedded`,`authenticate`),{headers:{Authorization:`Bearer ${n}`},method:`post`});if(!o.ok){let e=await o.text();throw Error(e?`Authentication failed. Server sent back: ${e}`:`Authentication failed. Please check that your customer and organization information are correct, and that the token you provided is not expired.`)}i.jwt=n,h.setState(i),i.embeddedDesignerEnabled=(await M({query:`{ authenticatedUser { customer { allowEmbeddedDesigner } } }`})).data.authenticatedUser.customer.allowEmbeddedDesigner,h.setState(i)};async function ye(e,t){return g(`createWorkflow`),M({query:` mutation createWorkflow($name: String!, $contextStableKey: String, $contextData: String, $externalId: String) { importWorkflow(input: { name: $name contextStableKey: $contextStableKey contextData: $contextData externalId: $externalId }) { workflow { id } errors { field messages } } } `,variables:{name:t.name,contextStableKey:e,contextData:JSON.stringify(t.contextData),externalId:t.externalId}})}let be=`<style id="${le}"> .${w} { backdrop-filter: blur(10px); background: rgb(119 119 119 / 29%); bottom: 0; display: block; left: 0; opacity: 0; position: fixed; right: 0; top: 0; transition: all 0.3s ease-in; visibility: hidden; z-index: 9999; } .${w}.${T} { opacity: 1; visibility: visible; } .${de} { background: #fff; border-radius: 4px; bottom: 0; height: 80vh; left: 0; margin: auto; overflow: hidden; position: absolute; right: 0; top: 0; width: 80vw; } .${fe} { all: unset; cursor: pointer; position: absolute; right: 1.5em; top: 1.3em; } .${S} { height: 100% } </style>`,N,xe=()=>{N?.abort(),N=void 0},P={filters:{marketplace:{includeActiveIntegrations:!0},integrations:{},components:{}},screenConfiguration:{configurationWizard:{},instance:{},marketplace:{},initializing:{}},skipPreload:!1,theme:`LIGHT`,fontConfiguration:void 0,translation:{}},F=e=>{let t=(0,ee.default)({},P,e),n=h.getInitialState();if(t&&Object.entries(t).forEach(([e,t])=>{p(e)&&m(n,e,t)}),n.initComplete=!0,h.setState(n),document.getElementById(`pio__embedded`))return;!document.getElementById(`pio__iframe-preload`)&&!t.skipPreload&&document.body.insertAdjacentHTML(`beforeend`,`<iframe id="${ce}" src="${n.prismaticUrl}/embedded" style="visibility: hidden; display: none;" height="0" width="0" />`),document.head.insertAdjacentHTML(`beforeend`,be);let r=document.createElement(`div`);r.id=x,r.innerHTML=` <div class="${w}"> <div class="${de}"> <button class="${fe}" aria-label="close popover" data-close>✕</button> <div class="${S}"></div> </div> </div> `,document.body.appendChild(r);let i=document.querySelector(`#${x} .${fe}`),a=document.querySelector(ue);N=new AbortController;let{signal:o}=N;a?.addEventListener(`click`,e=>{e.target===e.currentTarget&&y()},{signal:o}),i?.addEventListener(`click`,()=>y(),{signal:o}),document.addEventListener(`keyup`,e=>{e.key===`Escape`&&document.querySelector(`.${T}`)&&y()},{signal:o})},I=()=>{document.getElementById(x)?.remove(),document.getElementById(ce)?.remove(),document.getElementById(le)?.remove(),xe(),h.setState(h.getInitialState())},L=({instanceId:e,selector:t,theme:n,screenConfiguration:r,onCancel:i,onSuccess:a,onDelete:o})=>{if(g(`editInstanceConfiguration`),D(`/configure-instance/${e}/`,{selector:t,...n?{theme:n}:{},screenConfiguration:{...r,configurationWizard:{...r?.configurationWizard,isInModal:!0}}},{reconfigure:`true`}),!i&&!a&&!o)return;let s=new AbortController;return window.addEventListener(`message`,e=>{switch(e.data?.event){case`INSTANCE_DEPLOYED`:a?.(),s.abort();break;case`INSTANCE_DELETED`:o?.(),s.abort();break;case`INSTANCE_CONFIGURATION_CANCELED`:i?.(),s.abort();break}},{signal:s.signal}),()=>s.abort()},R=async e=>(g(`queryWorkflows`),M({query:` query queryWorkflows( $cursor: String $searchTerm: String $descriptionSearch: String $categorySearch: String $labelSearch: String $contextStableKey: String $externalId: String $first: Int $sortBy: [IntegrationVariantOrder] ) { workflows: integrationVariants( after: $cursor name_Icontains: $searchTerm description_Icontains: $descriptionSearch category: $categorySearch labels_Icontains: $labelSearch contextStableKey: $contextStableKey externalId: $externalId exclude: [INTEGRATION] first: $first sortBy: $sortBy ) { nodes { ... on Workflow { id name versionNumber description externalId updatedAt lastExecutedAt createdAt category labels customer { id name } instance { enabled } deployedVersion { id } } } pageInfo { hasNextPage endCursor } totalCount } } `,variables:e})),z=({configVars:e,...t})=>{b({...t,event:{event:`SET_CONFIG_VAR`,data:e}})},Se=({componentId:e,...t})=>{g(`showComponent`),D(`/components/${e}/`,t,{})},Ce=e=>{g(`showComponents`),D(`/components/`,e,{})},B=e=>{g(`showConnections`),D(`/customer-connections/`,e,{})},V=(e={usePopover:!0})=>{g(`showDashboard`),D(`/dashboard/`,e,{})},H=e=>{let{embeddedDesignerEnabled:t}=h.getStateCopy();if(!t)throw Error(`Embedded designer must be enabled for this customer in order to call ${e}`)},U=({integrationId:e,...t})=>{g(`showDesigner`),H(`showDesigner`),D(`/integrations/${e}/`,t,{})},W=e=>{g(`showIntegrations`),H(`showIntegrations`),D(`/integrations/`,e,{})},we=e=>{g(`showLogs`),D(`/logs/`,e,{})},Te=(e={usePopover:!0})=>{g(`showMarketplace`),D(`/integration-marketplace/`,e,{})},Ee=({workflowId:e,onDelete:t,...n})=>{if(g(`showWorkflowBuilder`),D(`/builder/${e}/`,n,{}),t){let e=new AbortController;return window.addEventListener(`message`,e=>{e.data?.event===`WORKFLOW_DELETED`&&t()},{signal:e.signal}),()=>e.abort()}},G=e=>{g(`showWorkflows`),D(`/workflows/`,e,{})},K=function(e){return e.and=`and`,e.or=`or`,e}({}),De=function(e){return e.equal=`equal`,e.notEqual=`notEqual`,e.in=`in`,e.notIn=`notIn`,e.startsWith=`startsWith`,e.doesNotStartWith=`doesNotStartWith`,e.endsWith=`endsWith`,e.doesNotEndWith=`doesNotEndWith`,e}({});var Oe=c({BooleanOperator:()=>K,EMBEDDED_DEFAULTS:()=>P,PrismaticMessageEvent:()=>ne,TermOperator:()=>De,authenticate:()=>ve,closePopover:()=>y,configureInstance:()=>O,createWorkflow:()=>ye,dispose:()=>I,editInstanceConfiguration:()=>L,getMessageIframe:()=>ae,graphqlRequest:()=>M,init:()=>F,isConfigureInstanceWithInstanceId:()=>k,isConfigureInstanceWithIntegrationId:()=>A,isConfigureInstanceWithIntegrationName:()=>j,queryWorkflows:()=>R,setConfigVars:()=>z,showComponent:()=>Se,showComponents:()=>Ce,showConnections:()=>B,showDashboard:()=>V,showDesigner:()=>U,showIntegrations:()=>W,showLogs:()=>we,showMarketplace:()=>Te,showWorkflow:()=>Ee,showWorkflows:()=>G});e.BooleanOperator=K,e.EMBEDDED_DEFAULTS=P,e.PrismaticMessageEvent=ne,e.TermOperator=De,e.authenticate=ve,e.closePopover=y,e.configureInstance=O,e.createWorkflow=ye,e.default=Oe,e.dispose=I,e.editInstanceConfiguration=L,e.getMessageIframe=ae,e.graphqlRequest=M,e.init=F,e.isConfigureInstanceWithInstanceId=k,e.isConfigureInstanceWithIntegrationId=A,e.isConfigureInstanceWithIntegrationName=j,e.queryWorkflows=R,e.setConfigVars=z,e.showComponent=Se,e.showComponents=Ce,e.showConnections=B,e.showDashboard=V,e.showDesigner=U,e.showIntegrations=W,e.showLogs=we,e.showMarketplace=Te,e.showWorkflow=Ee,e.showWorkflows=G}); //# sourceMappingURL=index.umd.js.map