UNPKG

@prismatic-io/embedded

Version:

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

144 lines 25.6 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||!o.call(e,`default`)?n(i,`default`,{value:e,enumerable:!0}):i,e));let d={agent:void 0,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=`__lodash_hash_undefined__`,r=9007199254740991,i=`[object Arguments]`,a=`[object Array]`,o=`[object Boolean]`,s=`[object Date]`,c=`[object Error]`,l=`[object Function]`,u=`[object Map]`,d=`[object Number]`,f=`[object Object]`,p=`[object RegExp]`,m=`[object Set]`,h=`[object String]`,g=`[object WeakMap]`,ee=`[object ArrayBuffer]`,te=`[object DataView]`,_=`[object Float32Array]`,v=`[object Float64Array]`,ne=`[object Int8Array]`,re=`[object Int16Array]`,ie=`[object Int32Array]`,y=`[object Uint8Array]`,ae=`[object Uint8ClampedArray]`,oe=`[object Uint16Array]`,b=`[object Uint32Array]`,x=/[\\^$.*+?()[\]{}|]/g,se=/^\[object .+?Constructor\]$/,ce=/^(?:0|[1-9]\d*)$/,S={};S[_]=S[v]=S[ne]=S[re]=S[ie]=S[y]=S[ae]=S[oe]=S[b]=!0,S[i]=S[a]=S[ee]=S[o]=S[te]=S[s]=S[c]=S[l]=S[u]=S[d]=S[f]=S[p]=S[m]=S[h]=S[g]=!1;var C=typeof global==`object`&&global&&global.Object===Object&&global,le=typeof self==`object`&&self&&self.Object===Object&&self,w=C||le||Function(`return this`)(),ue=typeof e==`object`&&e&&!e.nodeType&&e,T=ue&&typeof t==`object`&&t&&!t.nodeType&&t,de=T&&T.exports===ue,E=de&&C.process,D=function(){try{return T&&T.require&&T.require(`util`).types||E&&E.binding&&E.binding(`util`)}catch{}}(),fe=D&&D.isTypedArray;function pe(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 O(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}function me(e){return function(t){return e(t)}}function he(e,t){return e?.[t]}function k(e,t){return function(n){return e(t(n))}}var ge=Array.prototype,_e=Function.prototype,A=Object.prototype,j=w[`__core-js_shared__`],M=_e.toString,N=A.hasOwnProperty,P=function(){var e=/[^.]+$/.exec(j&&j.keys&&j.keys.IE_PROTO||``);return e?`Symbol(src)_1.`+e:``}(),ve=A.toString,F=M.call(Object),ye=RegExp(`^`+M.call(N).replace(x,`\\$&`).replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,`$1.*?`)+`$`),I=de?w.Buffer:void 0,L=w.Symbol,R=w.Uint8Array,z=I?I.allocUnsafe:void 0,B=k(Object.getPrototypeOf,Object),V=Object.create,be=A.propertyIsEnumerable,xe=ge.splice,H=L?L.toStringTag:void 0,U=function(){try{var e=pt(Object,`defineProperty`);return e({},``,{}),e}catch{}}(),Se=I?I.isBuffer:void 0,W=Math.max,Ce=Date.now,G=pt(w,`Map`),K=pt(Object,`create`),we=function(){function e(){}return function(t){if(!Q(t))return{};if(V)return V(t);e.prototype=t;var n=new e;return e.prototype=void 0,n}}();function q(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 Te(){this.__data__=K?K(null):{},this.size=0}function Ee(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=+!!t,t}function De(e){var t=this.__data__;if(K){var r=t[e];return r===n?void 0:r}return N.call(t,e)?t[e]:void 0}function Oe(e){var t=this.__data__;return K?t[e]!==void 0:N.call(t,e)}function ke(e,t){var r=this.__data__;return this.size+=+!this.has(e),r[e]=K&&t===void 0?n:t,this}q.prototype.clear=Te,q.prototype.delete=Ee,q.prototype.get=De,q.prototype.has=Oe,q.prototype.set=ke;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 Ae(){this.__data__=[],this.size=0}function je(e){var t=this.__data__,n=Je(t,e);return n<0?!1:(n==t.length-1?t.pop():xe.call(t,n,1),--this.size,!0)}function Me(e){var t=this.__data__,n=Je(t,e);return n<0?void 0:t[n][1]}function Ne(e){return Je(this.__data__,e)>-1}function Pe(e,t){var n=this.__data__,r=Je(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this}J.prototype.clear=Ae,J.prototype.delete=je,J.prototype.get=Me,J.prototype.has=Ne,J.prototype.set=Pe;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 Fe(){this.size=0,this.__data__={hash:new q,map:new(G||J),string:new q}}function Ie(e){var t=ft(this,e).delete(e);return this.size-=+!!t,t}function Le(e){return ft(this,e).get(e)}function Re(e){return ft(this,e).has(e)}function ze(e,t){var n=ft(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this}Y.prototype.clear=Fe,Y.prototype.delete=Ie,Y.prototype.get=Le,Y.prototype.has=Re,Y.prototype.set=ze;function X(e){var t=this.__data__=new J(e);this.size=t.size}function Be(){this.__data__=new J,this.size=0}function Ve(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n}function He(e){return this.__data__.get(e)}function Ue(e){return this.__data__.has(e)}function We(e,t){var n=this.__data__;if(n instanceof J){var r=n.__data__;if(!G||r.length<199)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new Y(r)}return n.set(e,t),this.size=n.size,this}X.prototype.clear=Be,X.prototype.delete=Ve,X.prototype.get=He,X.prototype.has=Ue,X.prototype.set=We;function Ge(e,t){var n=At(e),r=!n&&kt(e),i=!n&&!r&&Nt(e),a=!n&&!r&&!i&&Lt(e),o=n||r||i||a,s=o?O(e.length,String):[],c=s.length;for(var l in e)(t||N.call(e,l))&&!(o&&(l==`length`||i&&(l==`offset`||l==`parent`)||a&&(l==`buffer`||l==`byteLength`||l==`byteOffset`)||gt(l,c)))&&s.push(l);return s}function Ke(e,t,n){(n!==void 0&&!Ot(e[t],n)||n===void 0&&!(t in e))&&Ye(e,t,n)}function qe(e,t,n){var r=e[t];(!(N.call(e,t)&&Ot(r,n))||n===void 0&&!(t in e))&&Ye(e,t,n)}function Je(e,t){for(var n=e.length;n--;)if(Ot(e[n][0],t))return n;return-1}function Ye(e,t,n){t==`__proto__`&&U?U(e,t,{configurable:!0,enumerable:!0,value:n,writable:!0}):e[t]=n}var Xe=dt();function Z(e){return e==null?e===void 0?`[object Undefined]`:`[object Null]`:H&&H in Object(e)?mt(e):St(e)}function Ze(e){return $(e)&&Z(e)==i}function Qe(e){return!Q(e)||yt(e)?!1:(Pt(e)?ye:se).test(Dt(e))}function $e(e){return $(e)&&Ft(e.length)&&!!S[Z(e)]}function et(e){if(!Q(e))return xt(e);var t=bt(e),n=[];for(var r in e)r==`constructor`&&(t||!N.call(e,r))||n.push(r);return n}function tt(e,t,n,r,i){e!==t&&Xe(t,function(a,o){if(i||=new X,Q(a))nt(e,t,o,n,tt,r,i);else{var s=r?r(wt(e,o),a,o+``,e,t,i):void 0;s===void 0&&(s=a),Ke(e,o,s)}},zt)}function nt(e,t,n,r,i,a,o){var s=wt(e,n),c=wt(t,n),l=o.get(c);if(l){Ke(e,n,l);return}var u=a?a(s,c,n+``,e,t,o):void 0,d=u===void 0;if(d){var f=At(c),p=!f&&Nt(c),m=!f&&!p&&Lt(c);u=c,f||p||m?At(s)?u=s:Mt(s)?u=ct(s):p?(d=!1,u=at(c,!0)):m?(d=!1,u=st(c,!0)):u=[]:It(c)||kt(c)?(u=s,kt(s)?u=Rt(s):(!Q(s)||Pt(s))&&(u=ht(c))):d=!1}d&&(o.set(c,u),i(u,c,r,a,o),o.delete(c)),Ke(e,n,u)}function rt(e,t){return Tt(Ct(e,t,Ht),e+``)}var it=U?function(e,t){return U(e,`toString`,{configurable:!0,enumerable:!1,value:Vt(t),writable:!0})}:Ht;function at(e,t){if(t)return e.slice();var n=e.length,r=z?z(n):new e.constructor(n);return e.copy(r),r}function ot(e){var t=new e.constructor(e.byteLength);return new R(t).set(new R(e)),t}function st(e,t){var n=t?ot(e.buffer):e.buffer;return new e.constructor(n,e.byteOffset,e.length)}function ct(e,t){var n=-1,r=e.length;for(t||=Array(r);++n<r;)t[n]=e[n];return t}function lt(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?Ye(n,s,c):qe(n,s,c)}return n}function ut(e){return rt(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&&_t(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 dt(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 ft(e,t){var n=e.__data__;return vt(t)?n[typeof t==`string`?`string`:`hash`]:n.map}function pt(e,t){var n=he(e,t);return Qe(n)?n:void 0}function mt(e){var t=N.call(e,H),n=e[H];try{e[H]=void 0;var r=!0}catch{}var i=ve.call(e);return r&&(t?e[H]=n:delete e[H]),i}function ht(e){return typeof e.constructor==`function`&&!bt(e)?we(B(e)):{}}function gt(e,t){var n=typeof e;return t??=r,!!t&&(n==`number`||n!=`symbol`&&ce.test(e))&&e>-1&&e%1==0&&e<t}function _t(e,t,n){if(!Q(n))return!1;var r=typeof t;return(r==`number`?jt(n)&&gt(t,n.length):r==`string`&&t in n)?Ot(n[t],e):!1}function vt(e){var t=typeof e;return t==`string`||t==`number`||t==`symbol`||t==`boolean`?e!==`__proto__`:e===null}function yt(e){return!!P&&P in e}function bt(e){var t=e&&e.constructor;return e===(typeof t==`function`&&t.prototype||A)}function xt(e){var t=[];if(e!=null)for(var n in Object(e))t.push(n);return t}function St(e){return ve.call(e)}function Ct(e,t,n){return t=W(t===void 0?e.length-1:t,0),function(){for(var r=arguments,i=-1,a=W(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),pe(e,this,s)}}function wt(e,t){if((t!==`constructor`||typeof e[t]!=`function`)&&t!=`__proto__`)return e[t]}var Tt=Et(it);function Et(e){var t=0,n=0;return function(){var r=Ce(),i=16-(r-n);if(n=r,i>0){if(++t>=800)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}function Dt(e){if(e!=null){try{return M.call(e)}catch{}try{return e+``}catch{}}return``}function Ot(e,t){return e===t||e!==e&&t!==t}var kt=Ze(function(){return arguments}())?Ze:function(e){return $(e)&&N.call(e,`callee`)&&!be.call(e,`callee`)},At=Array.isArray;function jt(e){return e!=null&&Ft(e.length)&&!Pt(e)}function Mt(e){return $(e)&&jt(e)}var Nt=Se||Ut;function Pt(e){if(!Q(e))return!1;var t=Z(e);return t==l||t==`[object GeneratorFunction]`||t==`[object AsyncFunction]`||t==`[object Proxy]`}function Ft(e){return typeof e==`number`&&e>-1&&e%1==0&&e<=r}function Q(e){var t=typeof e;return e!=null&&(t==`object`||t==`function`)}function $(e){return typeof e==`object`&&!!e}function It(e){if(!$(e)||Z(e)!=f)return!1;var t=B(e);if(t===null)return!0;var n=N.call(t,`constructor`)&&t.constructor;return typeof n==`function`&&n instanceof n&&M.call(n)==F}var Lt=fe?me(fe):$e;function Rt(e){return lt(e,zt(e))}function zt(e){return jt(e)?Ge(e,!0):et(e)}var Bt=ut(function(e,t,n){tt(e,t,n)});function Vt(e){return function(){return e}}function Ht(e){return e}function Ut(){return!1}t.exports=Bt}))());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]=e[0].match(/^file:\/\/\//)?e[0].replace(/^([^/:]+):\/*/,`$1:///`):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_AGENT_CONTEXT=`SET_AGENT_CONTEXT`,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=D(`${le} > iframe`);pe(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:fe(e.selector);pe(t)&&t.contentWindow?.postMessage(e.event,`*`)},x=`pio__embedded`,se=`pio__iframe`,ce=`pio__iframe-preload`,S=`pio__styles`,C=`pio__iframeContainer`,le=`#${x} .${C}`,w=`pio__overlay`,ue=`#${x} > .${w}`,T=`${w}--is_visible`,de=`pio__popover`,E=`pio__closeBtn`,D=e=>document.querySelector(e),fe=e=>document.querySelector(`${e||le} > iframe`),pe=e=>!!(e&&e.tagName===`IFRAME`),O=(e,t,n)=>{!v(t)&&!t.selector&&console.error(`Could not find display selector.`);let r=D(v(t)?le:t.selector);if(!r)return;let i=h.getStateCopy();t&&Object.entries(t).forEach(([e,t])=>{if(p(e)){let n=i[e],r=n instanceof Object?(0,ee.default)(n,t):t;m(i,e,r)}});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));let o=`${_(i.prismaticUrl,e)}?${a}`;r.innerHTML=` <iframe id="${se}" src="${o}" height="100%" width="100%" frameBorder="0" allow="clipboard-read; clipboard-write" ></iframe> `;let s=r.querySelector(`iframe`);if(s){let e=new AbortController;me(e),window.addEventListener(`message`,e=>{if(e.data?.event===`PRISMATIC_INITIALIZED`){b({iframe:s,event:{event:`SET_TOKEN`,data:i.jwt}}),b({iframe:s,event:{event:`SET_VERSION`,data:`4.13.0`}}),b({iframe:s,event:{event:`SET_TRANSLATION`,data:i.translation}});let e=v(t)?{...i.screenConfiguration??{},isInPopover:!0}:i.screenConfiguration;b({iframe:s,event:{event:`SET_SCREEN_CONFIGURATION`,data:e}}),b({iframe:s,event:{event:`SET_FILTERS`,data:i.filters}}),b({iframe:s,event:{event:`SET_AGENT_CONTEXT`,data:i.agent?.context}})}else e.data?.event===`POPOVER_CLOSE_REQUESTED`&&y()},{signal:e.signal}),t?.autoFocusIframe!==!1&&s.addEventListener(`mouseenter`,()=>{s.focus()},{signal:e.signal})}v(t)&&ie()},me=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})},he=({...e})=>{if(g(`configureInstance`),k(e)){let{instanceId:t,skipRedirectOnRemove:n,...r}=e;return O(`/find-integration-marketplace/`,r,{instanceId:t,...n?{skipRedirectOnRemove:`true`}:{}})}if(ge(e)){let{integrationId:t,skipRedirectOnRemove:n,...r}=e;return O(`/find-integration-marketplace/`,r,{integrationId:t,...n?{skipRedirectOnRemove:`true`}:{}})}if(_e(e)){let{integrationName:t,skipRedirectOnRemove:n,...r}=e;O(`/find-integration-marketplace/`,r,{integrationName:t,...n?{skipRedirectOnRemove:`true`}:{}})}},k=e=>!!(`instanceId`in e&&e.instanceId),ge=e=>!!(`integrationId`in e&&e.integrationId),_e=e=>!!(`integrationName`in e&&e.integrationName),A=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()},j=`The authenticate method expects an object containing a token and additional optional configuration.`,M=[`token`],N=async e=>{if(g(`authenticate`),!e)throw Error(j);let t=new Set(Object.keys(e));if(!M.every(e=>t.has(e)))throw Error(j);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 A({query:`{ authenticatedUser { customer { allowEmbeddedDesigner } } }`})).data.authenticatedUser.customer.allowEmbeddedDesigner,h.setState(i)};async function P(e,t){return g(`createWorkflow`),A({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 ve=`<style id="${S}"> .${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; } .${E} { all: unset; cursor: pointer; position: absolute; right: 1.5em; top: 1.3em; } .${C} { height: 100% } </style>`,F,ye=()=>{F?.abort(),F=void 0},I={filters:{marketplace:{includeActiveIntegrations:!0},integrations:{},components:{}},screenConfiguration:{configurationWizard:{},instance:{},marketplace:{},initializing:{}},skipPreload:!1,theme:`LIGHT`,fontConfiguration:void 0,translation:{}},L=e=>{let t=(0,ee.default)({},I,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`,ve);let r=document.createElement(`div`);r.id=x,r.innerHTML=` <div class="${w}"> <div class="${de}"> <button class="${E}" aria-label="close popover" data-close>✕</button> <div class="${C}"></div> </div> </div> `,document.body.appendChild(r);let i=document.querySelector(`#${x} .${E}`),a=document.querySelector(ue);F=new AbortController;let{signal:o}=F;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})},R=()=>{document.getElementById(x)?.remove(),document.getElementById(ce)?.remove(),document.getElementById(S)?.remove(),ye(),h.setState(h.getInitialState())},z=({instanceId:e,selector:t,theme:n,screenConfiguration:r,onCancel:i,onSuccess:a,onDelete:o})=>{if(g(`editInstanceConfiguration`),O(`/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()}},{signal:s.signal}),()=>s.abort()},B=async e=>(g(`queryWorkflows`),A({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})),V=({configVars:e,...t})=>{b({...t,event:{event:`SET_CONFIG_VAR`,data:e}})},be=({componentId:e,...t})=>{g(`showComponent`),O(`/components/${e}/`,t,{})},xe=e=>{g(`showComponents`),O(`/components/`,e,{})},H=e=>{g(`showConnections`),O(`/customer-connections/`,e,{})},U=(e={usePopover:!0})=>{g(`showDashboard`),O(`/dashboard/`,e,{})},Se=e=>{let{embeddedDesignerEnabled:t}=h.getStateCopy();if(!t)throw Error(`Embedded designer must be enabled for this customer in order to call ${e}`)},W=({integrationId:e,...t})=>{g(`showDesigner`),Se(`showDesigner`),O(`/integrations/${e}/`,t,{})},Ce=e=>{g(`showIntegrations`),Se(`showIntegrations`),O(`/integrations/`,e,{})},G=e=>{g(`showLogs`),O(`/logs/`,e,{})},K=(e={usePopover:!0})=>{g(`showMarketplace`),O(`/integration-marketplace/`,e,{})},we=({workflowId:e,onDelete:t,...n})=>{if(g(`showWorkflowBuilder`),O(`/builder/${e}/`,n,{}),t){let e=new AbortController;return window.addEventListener(`message`,e=>{e.data?.event===`WORKFLOW_DELETED`&&t()},{signal:e.signal}),()=>e.abort()}},q=e=>{g(`showWorkflows`),O(`/workflows/`,e,{})},Te=function(e){return e.and=`and`,e.or=`or`,e}({}),Ee=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 De=c({BooleanOperator:()=>Te,EMBEDDED_DEFAULTS:()=>I,PrismaticMessageEvent:()=>ne,TermOperator:()=>Ee,authenticate:()=>N,closePopover:()=>y,configureInstance:()=>he,createWorkflow:()=>P,dispose:()=>R,editInstanceConfiguration:()=>z,getMessageIframe:()=>ae,graphqlRequest:()=>A,init:()=>L,isConfigureInstanceWithInstanceId:()=>k,isConfigureInstanceWithIntegrationId:()=>ge,isConfigureInstanceWithIntegrationName:()=>_e,queryWorkflows:()=>B,setConfigVars:()=>V,showComponent:()=>be,showComponents:()=>xe,showConnections:()=>H,showDashboard:()=>U,showDesigner:()=>W,showIntegrations:()=>Ce,showLogs:()=>G,showMarketplace:()=>K,showWorkflow:()=>we,showWorkflows:()=>q});e.BooleanOperator=Te,e.EMBEDDED_DEFAULTS=I,e.PrismaticMessageEvent=ne,e.TermOperator=Ee,e.authenticate=N,e.closePopover=y,e.configureInstance=he,e.createWorkflow=P,e.default=De,e.dispose=R,e.editInstanceConfiguration=z,e.getMessageIframe=ae,e.graphqlRequest=A,e.init=L,e.isConfigureInstanceWithInstanceId=k,e.isConfigureInstanceWithIntegrationId=ge,e.isConfigureInstanceWithIntegrationName=_e,e.queryWorkflows=B,e.setConfigVars=V,e.showComponent=be,e.showComponents=xe,e.showConnections=H,e.showDashboard=U,e.showDesigner=W,e.showIntegrations=Ce,e.showLogs=G,e.showMarketplace=K,e.showWorkflow=we,e.showWorkflows=q}); //# sourceMappingURL=index.umd.js.map