UNPKG

@prismatic-io/embedded

Version:

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

144 lines • 27.1 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,t.exports),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=/* @__PURE__ */ u((/* @__PURE__ */ 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]`,ne=`[object Float32Array]`,re=`[object Float64Array]`,ie=`[object Int8Array]`,ae=`[object Int16Array]`,_=`[object Int32Array]`,v=`[object Uint8Array]`,oe=`[object Uint8ClampedArray]`,se=`[object Uint16Array]`,ce=`[object Uint32Array]`,y=/[\\^$.*+?()[\]{}|]/g,le=/^\[object .+?Constructor\]$/,ue=/^(?:0|[1-9]\d*)$/,b={};b[ne]=b[re]=b[ie]=b[ae]=b[_]=b[v]=b[oe]=b[se]=b[ce]=!0,b[i]=b[a]=b[ee]=b[o]=b[te]=b[s]=b[c]=b[l]=b[u]=b[d]=b[f]=b[p]=b[m]=b[h]=b[g]=!1;var x=typeof global==`object`&&global&&global.Object===Object&&global,de=typeof self==`object`&&self&&self.Object===Object&&self,S=x||de||Function(`return this`)(),C=typeof e==`object`&&e&&!e.nodeType&&e,w=C&&typeof t==`object`&&t&&!t.nodeType&&t,T=w&&w.exports===C,E=T&&x.process,D=function(){try{return w&&w.require&&w.require(`util`).types||E&&E.binding&&E.binding(`util`)}catch{}}(),O=D&&D.isTypedArray;function fe(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 k(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}function pe(e){return function(t){return e(t)}}function me(e,t){return e?.[t]}function he(e,t){return function(n){return e(t(n))}}var A=Array.prototype,ge=Function.prototype,j=Object.prototype,M=S[`__core-js_shared__`],N=ge.toString,P=j.hasOwnProperty,F=function(){var e=/[^.]+$/.exec(M&&M.keys&&M.keys.IE_PROTO||``);return e?`Symbol(src)_1.`+e:``}(),I=j.toString,_e=N.call(Object),ve=RegExp(`^`+N.call(P).replace(y,`\\$&`).replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,`$1.*?`)+`$`),L=T?S.Buffer:void 0,ye=S.Symbol,R=S.Uint8Array,be=L?L.allocUnsafe:void 0,z=he(Object.getPrototypeOf,Object),B=Object.create,xe=j.propertyIsEnumerable,Se=A.splice,V=ye?ye.toStringTag:void 0,H=function(){try{var e=pt(Object,`defineProperty`);return e({},``,{}),e}catch{}}(),Ce=L?L.isBuffer:void 0,U=Math.max,we=Date.now,W=pt(S,`Map`),G=pt(Object,`create`),Te=function(){function e(){}return function(t){if(!Q(t))return{};if(B)return B(t);e.prototype=t;var n=new e;return e.prototype=void 0,n}}();function K(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 Ee(){this.__data__=G?G(null):{},this.size=0}function De(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=+!!t,t}function Oe(e){var t=this.__data__;if(G){var r=t[e];return r===n?void 0:r}return P.call(t,e)?t[e]:void 0}function ke(e){var t=this.__data__;return G?t[e]!==void 0:P.call(t,e)}function Ae(e,t){var r=this.__data__;return this.size+=+!this.has(e),r[e]=G&&t===void 0?n:t,this}K.prototype.clear=Ee,K.prototype.delete=De,K.prototype.get=Oe,K.prototype.has=ke,K.prototype.set=Ae;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 je(){this.__data__=[],this.size=0}function Me(e){var t=this.__data__,n=X(t,e);return n<0?!1:(n==t.length-1?t.pop():Se.call(t,n,1),--this.size,!0)}function Ne(e){var t=this.__data__,n=X(t,e);return n<0?void 0:t[n][1]}function Pe(e){return X(this.__data__,e)>-1}function Fe(e,t){var n=this.__data__,r=X(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this}q.prototype.clear=je,q.prototype.delete=Me,q.prototype.get=Ne,q.prototype.has=Pe,q.prototype.set=Fe;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 Ie(){this.size=0,this.__data__={hash:new K,map:new(W||q),string:new K}}function Le(e){var t=ft(this,e).delete(e);return this.size-=+!!t,t}function Re(e){return ft(this,e).get(e)}function ze(e){return ft(this,e).has(e)}function Be(e,t){var n=ft(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this}J.prototype.clear=Ie,J.prototype.delete=Le,J.prototype.get=Re,J.prototype.has=ze,J.prototype.set=Be;function Y(e){var t=this.__data__=new q(e);this.size=t.size}function Ve(){this.__data__=new q,this.size=0}function He(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n}function Ue(e){return this.__data__.get(e)}function We(e){return this.__data__.has(e)}function Ge(e,t){var n=this.__data__;if(n instanceof q){var r=n.__data__;if(!W||r.length<199)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new J(r)}return n.set(e,t),this.size=n.size,this}Y.prototype.clear=Ve,Y.prototype.delete=He,Y.prototype.get=Ue,Y.prototype.has=We,Y.prototype.set=Ge;function Ke(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?k(e.length,String):[],c=s.length;for(var l in e)(t||P.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 qe(e,t,n){(n!==void 0&&!Ot(e[t],n)||n===void 0&&!(t in e))&&Ye(e,t,n)}function Je(e,t,n){var r=e[t];(!(P.call(e,t)&&Ot(r,n))||n===void 0&&!(t in e))&&Ye(e,t,n)}function X(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__`&&H?H(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]`:V&&V 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)?ve:le).test(Dt(e))}function $e(e){return $(e)&&Ft(e.length)&&!!b[Z(e)]}function et(e){if(!Q(e))return xt(e);var t=bt(e),n=[];for(var r in e)(r!=`constructor`||!t&&P.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 Y,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),qe(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)qe(e,n,l);else{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)),qe(e,n,u)}}function rt(e,t){return Tt(Ct(e,t,Ht),e+``)}var it=H?function(e,t){return H(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=be?be(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):Je(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=me(e,t);return Qe(n)?n:void 0}function mt(e){var t=P.call(e,V),n=e[V];try{e[V]=void 0;var r=!0}catch{}var i=I.call(e);return r&&(t?e[V]=n:delete e[V]),i}function ht(e){return typeof e.constructor==`function`&&!bt(e)?Te(z(e)):{}}function gt(e,t){var n=typeof e;return t??=r,!!t&&(n==`number`||n!=`symbol`&&ue.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!!F&&F in e}function bt(e){var t=e&&e.constructor;return e===(typeof t==`function`&&t.prototype||j)}function xt(e){var t=[];if(e!=null)for(var n in Object(e))t.push(n);return t}function St(e){return I.call(e)}function Ct(e,t,n){return t=U(t===void 0?e.length-1:t,0),function(){for(var r=arguments,i=-1,a=U(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),fe(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=we(),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 N.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)&&P.call(e,`callee`)&&!xe.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=Ce||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=z(e);if(t===null)return!0;var n=P.call(t,`constructor`)&&t.constructor;return typeof n==`function`&&n instanceof n&&N.call(n)==_e}var Lt=O?pe(O):$e;function Rt(e){return lt(e,zt(e))}function zt(e){return jt(e)?Ke(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})))());let te=`[^/:\\d][^/:]*`,ne=RegExp(`^`+te+`:/*$`),re=RegExp(`^(`+te+`):/*`),ie=/^[^/:]+:\d+(?:[/?#]|$)/;function ae(e){let t=[],n=[];if(e=e.filter(e=>e!==``),e.length===0)return``;if(typeof e[0]!=`string`)throw TypeError(`Url must be a string. Received `+e[0]);let r=ie.test(e[0]);ne.test(e[0])&&e.length>1&&(e[0]=e.shift()+e[0]),e[0]===`/`&&e.length>1&&(e[0]=e.shift()+e[0]),e[0].match(/^file:\/\/\//)?e[0]=e[0].replace(re,`$1:///`):!r&&!e[0].match(/^\[.*:.*\]/)&&(e[0]=e[0].replace(re,`$1://`));let i=!1,a=!1,o=!1;for(let r=0;r<e.length;r++){let s=e[r];if(typeof s!=`string`)throw TypeError(`Url must be a string. Received `+s);let c=s.search(/[?&#]/);!a&&c!==-1&&(o=c===0?i:s[c-1]===`/`,a=!0);let l=s.startsWith(`/`),u=s.endsWith(`/`);r>0&&(s=s.replace(/^[\/]+/,``)),s=r<e.length-1?s.replace(/[\/]+$/,``):s.replace(/[\/]+$/,`/`),s===``?i||=l:(t.push(s),n.push(l||i),i=u)}let s=``;for(let e=0;e<t.length;e++){let r=t[e];if(e===0){s+=r;continue}let i=t[e-1];i&&i.endsWith(`?`)?s+=r:i.endsWith(`#`)?s+=(n[e]?`/`:``)+r:s+=`/`+r}let c=s.search(/[?&#]/);s=s.replace(/\/(\?|&|#[^!])/g,(e,t,n)=>o&&n>0&&n+1===c?e:t);let l=s.indexOf(`#`),u=l===-1?s:s.slice(0,l),d=l===-1?``:s.slice(l+1),[f,...p]=u.split(/(?:\?|&)+/),m=p.filter(Boolean);return s=f+(m.length>0?`?`:``)+m.join(`&`)+(d&&d.length>0?`#`+d:``),s}function _(...e){return ae(Array.from(Array.isArray(e[0])?e[0]:e))}let v=e=>e.usePopover===!0,oe=/* @__PURE__ */ 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}({}),se=()=>document.querySelector(D),ce=()=>{se()?.classList.add(O)},y=()=>{let e=pe(`${T} > iframe`);he(e)&&(e.contentWindow?.postMessage({event:`MARKETPLACE_CLOSED`},`*`),window.postMessage({event:`POPOVER_CLOSED`},`*`),se()?.classList.remove(O))},le=e=>Array.from(document.getElementsByTagName(`iframe`)).find(t=>t.contentWindow===e.source),ue=e=>`iframe`in e,b=e=>{let t=ue(e)?e.iframe:me(e.selector);he(t)&&t.contentWindow?.postMessage(e.event,`*`)},x=`pio__embedded`,de=`pio__iframe`,S=`pio__iframe-preload`,C=`pio__styles`,w=`pio__iframeContainer`,T=`#${x} .${w}`,E=`pio__overlay`,D=`#${x} > .${E}`,O=`${E}--is_visible`,fe=`pio__popover`,k=`pio__closeBtn`,pe=e=>document.querySelector(e),me=e=>document.querySelector(`${e||`#pio__embedded .pio__iframeContainer`} > iframe`),he=e=>!!(e&&e.tagName===`IFRAME`),A=(e,t,n)=>{!v(t)&&!t.selector&&console.error(`Could not find display selector.`);let r=pe(v(t)?T: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="${de}" 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;ge(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.14.1`}}),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)&&ce()},ge=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})},j=({...e})=>{if(g(`configureInstance`),M(e)){let{instanceId:t,skipRedirectOnRemove:n,...r}=e;return A(`/find-integration-marketplace/`,r,{instanceId:t,...n?{skipRedirectOnRemove:`true`}:{}})}if(N(e)){let{integrationId:t,skipRedirectOnRemove:n,...r}=e;return A(`/find-integration-marketplace/`,r,{integrationId:t,...n?{skipRedirectOnRemove:`true`}:{}})}if(P(e)){let{integrationName:t,skipRedirectOnRemove:n,...r}=e;A(`/find-integration-marketplace/`,r,{integrationName:t,...n?{skipRedirectOnRemove:`true`}:{}})}},M=e=>!!(`instanceId`in e&&e.instanceId),N=e=>!!(`integrationId`in e&&e.integrationId),P=e=>!!(`integrationName`in e&&e.integrationName),F=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()},I=`The authenticate method expects an object containing a token and additional optional configuration.`,_e=[`token`],ve=async e=>{if(g(`authenticate`),!e)throw Error(I);let t=new Set(Object.keys(e));if(!_e.every(e=>t.has(e)))throw Error(I);let{token:n}=e,r=document.getElementById(de),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 F({query:`{ authenticatedUser { customer { allowEmbeddedDesigner } } }`})).data.authenticatedUser.customer.allowEmbeddedDesigner,h.setState(i)};async function L(e,t){return g(`createWorkflow`),F({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 ye=`<style id="${C}"> .${E} { 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; } .${E}.${O} { opacity: 1; visibility: visible; } .${fe} { background: #fff; border-radius: 4px; bottom: 0; height: 80vh; left: 0; margin: auto; overflow: hidden; position: absolute; right: 0; top: 0; width: 80vw; } .${k} { all: unset; cursor: pointer; position: absolute; right: 1.5em; top: 1.3em; } .${w} { height: 100% } </style>`,R,be=()=>{R?.abort(),R=void 0},z={filters:{marketplace:{includeActiveIntegrations:!0},integrations:{},components:{}},screenConfiguration:{configurationWizard:{},instance:{},marketplace:{},initializing:{}},skipPreload:!1,theme:`LIGHT`,fontConfiguration:void 0,translation:{}},B=e=>{let t=(0,ee.default)({},z,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="${S}" src="${n.prismaticUrl}/embedded" style="visibility: hidden; display: none;" height="0" width="0" />`),document.head.insertAdjacentHTML(`beforeend`,ye);let r=document.createElement(`div`);r.id=x,r.innerHTML=` <div class="${E}"> <div class="${fe}"> <button class="${k}" aria-label="close popover" data-close>✕</button> <div class="${w}"></div> </div> </div> `,document.body.appendChild(r);let i=document.querySelector(`#${x} .${k}`),a=document.querySelector(D);R=new AbortController;let{signal:o}=R;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(`.pio__overlay--is_visible`)&&y()},{signal:o})},xe=()=>{document.getElementById(x)?.remove(),document.getElementById(S)?.remove(),document.getElementById(C)?.remove(),be(),h.setState(h.getInitialState())},Se=({instanceId:e,selector:t,theme:n,screenConfiguration:r,onCancel:i,onSuccess:a,onDelete:o})=>{if(g(`editInstanceConfiguration`),A(`/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()},V=({instanceId:e,selector:t,theme:n,screenConfiguration:r,onCancel:i,onSuccess:a,onDelete:o})=>{if(g(`editUserLevelConfiguration`),A(`/configure-instance/${e}/`,{selector:t,...n?{theme:n}:{},screenConfiguration:{...r,configurationWizard:{...r?.configurationWizard,isInModal:!0}}},{reconfigure:`true`,userLevelConfigured:`true`}),!i&&!a&&!o)return;let s=new AbortController;return window.addEventListener(`message`,e=>{switch(e.data?.event){case`USER_CONFIGURATION_DEPLOYED`:a?.(),s.abort();break;case`USER_CONFIGURATION_DELETED`:o?.(),s.abort();break;case`INSTANCE_CONFIGURATION_CANCELED`:i?.(),s.abort()}},{signal:s.signal}),()=>s.abort()},H=async e=>(g(`queryWorkflows`),F({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})),Ce=({configVars:e,...t})=>{b({...t,event:{event:`SET_CONFIG_VAR`,data:e}})},U=({componentId:e,...t})=>{g(`showComponent`),A(`/components/${e}/`,t,{})},we=e=>{g(`showComponents`),A(`/components/`,e,{})},W=e=>{g(`showConnections`),A(`/customer-connections/`,e,{})},G=(e={usePopover:!0})=>{g(`showDashboard`),A(`/dashboard/`,e,{})},Te=e=>{let{embeddedDesignerEnabled:t}=h.getStateCopy();if(!t)throw Error(`Embedded designer must be enabled for this customer in order to call ${e}`)},K=({integrationId:e,...t})=>{g(`showDesigner`),Te(`showDesigner`),A(`/integrations/${e}/`,t,{})},Ee=e=>{g(`showIntegrations`),Te(`showIntegrations`),A(`/integrations/`,e,{})},De=e=>{g(`showLogs`),A(`/logs/`,e,{})},Oe=(e={usePopover:!0})=>{g(`showMarketplace`),A(`/integration-marketplace/`,e,{})},ke=({workflowId:e,onDelete:t,...n})=>{if(g(`showWorkflowBuilder`),A(`/builder/${e}/`,n,{}),t){let e=new AbortController;return window.addEventListener(`message`,e=>{e.data?.event===`WORKFLOW_DELETED`&&t()},{signal:e.signal}),()=>e.abort()}},Ae=e=>{g(`showWorkflows`),A(`/workflows/`,e,{})},q=/* @__PURE__ */ function(e){return e.and=`and`,e.or=`or`,e}({}),je=/* @__PURE__ */ 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 Me=/* @__PURE__ */ c({BooleanOperator:()=>q,EMBEDDED_DEFAULTS:()=>z,PrismaticMessageEvent:()=>oe,TermOperator:()=>je,authenticate:()=>ve,closePopover:()=>y,configureInstance:()=>j,createWorkflow:()=>L,dispose:()=>xe,editInstanceConfiguration:()=>Se,editUserLevelConfiguration:()=>V,getMessageIframe:()=>le,graphqlRequest:()=>F,init:()=>B,isConfigureInstanceWithInstanceId:()=>M,isConfigureInstanceWithIntegrationId:()=>N,isConfigureInstanceWithIntegrationName:()=>P,queryWorkflows:()=>H,setConfigVars:()=>Ce,showComponent:()=>U,showComponents:()=>we,showConnections:()=>W,showDashboard:()=>G,showDesigner:()=>K,showIntegrations:()=>Ee,showLogs:()=>De,showMarketplace:()=>Oe,showWorkflow:()=>ke,showWorkflows:()=>Ae});e.BooleanOperator=q,e.EMBEDDED_DEFAULTS=z,e.PrismaticMessageEvent=oe,e.TermOperator=je,e.authenticate=ve,e.closePopover=y,e.configureInstance=j,e.createWorkflow=L,e.default=Me,e.dispose=xe,e.editInstanceConfiguration=Se,e.editUserLevelConfiguration=V,e.getMessageIframe=le,e.graphqlRequest=F,e.init=B,e.isConfigureInstanceWithInstanceId=M,e.isConfigureInstanceWithIntegrationId=N,e.isConfigureInstanceWithIntegrationName=P,e.queryWorkflows=H,e.setConfigVars=Ce,e.showComponent=U,e.showComponents=we,e.showConnections=W,e.showDashboard=G,e.showDesigner=K,e.showIntegrations=Ee,e.showLogs=De,e.showMarketplace=Oe,e.showWorkflow=ke,e.showWorkflows=Ae}); //# sourceMappingURL=index.umd.js.map