n8n-editor-ui
Version:
Workflow Editor UI for n8n
2 lines • 7.06 kB
JavaScript
(function(){try{var e=typeof window<`u`?window:typeof global<`u`?global:typeof globalThis<`u`?globalThis:typeof self<`u`?self:{};e.SENTRY_RELEASE={id:`n8n@2.16.1`}}catch{}})();try{(function(){var e=typeof window<`u`?window:typeof global<`u`?global:typeof globalThis<`u`?globalThis:typeof self<`u`?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]=`fe339bfd-daf8-4542-8179-76f05a2b9520`,e._sentryDebugIdIdentifier=`sentry-dbid-fe339bfd-daf8-4542-8179-76f05a2b9520`)})()}catch{}import{Ft as e,I as t,S as n,q as r}from"./vue.runtime.esm-bundler-C3C09Zii.js";import{at as i}from"./core-Bz5WjPxS.js";import{d as a}from"./get-BjzKP_3k.js";import{Ln as o,Pn as s,ai as c,fr as l,it as u,js as d,s as f,t as p}from"./users.store-xP93bV7X.js";import{vi as m,yi as h}from"./constants-DuQbSl-q.js";import{c as g,t as _}from"./useRootStore-XEREVjMN.js";import{t as v}from"./settings.store-CAFiYCMH.js";function y(){let t=u(),n=c(),r=f(),a=s(),o=i(),d=l(),p=e(null),g=e(null);function _(e,n=new Set){if(n.has(e))return[];n.add(e);let r=t.getCredentialTypeByName(e);if(r?.extends===void 0)return[];let i=[];for(let e of r.extends)i.push(e),i.push(..._(e,n));return i}function v(e){let t=_(e);return e===`oAuth2Api`||e===`oAuth1Api`||t.includes(`oAuth2Api`)||t.includes(`oAuth1Api`)}function y(e){let t=_(e);return e===`googleOAuth2Api`||t.includes(`googleOAuth2Api`)}function b(e){if(!v(e))return!1;let n=t.getCredentialTypeByName(e);if(!n||n.__skipManagedCreation)return!1;let r=n.__overwrittenProperties??[];return r.length===0?!1:n.properties.filter(e=>e.type!==`hidden`&&e.type!==`notice`&&!r.includes(e.name)).every(e=>e.required!==!0||e.type!==`string`&&e.type!==`number`)}async function x(e){let n=_(e.type);try{if(e.type===`oAuth2Api`||n.includes(`oAuth2Api`))return h(await t.oAuth2Authorize(e));if(e.type===`oAuth1Api`||n.includes(`oAuth1Api`))return h(await t.oAuth1Authorize(e))}catch(e){return a.showError(e,o.baseText(`credentialEdit.credentialEdit.showError.generateAuthorizationUrl.title`)),m(`api-error`)}return m(`no-url`)}function S(e){try{let t=new URL(e);return[`http:`,`https:`].includes(t.protocol)}catch{return!1}}function C(){a.showError(Error(o.baseText(`credentialEdit.credentialEdit.showError.invalidOAuthUrl.message`)),o.baseText(`credentialEdit.credentialEdit.showError.invalidOAuthUrl.title`))}function w(e,t){let n=window.open(e,`OAuth Authorization`,`scrollbars=no,resizable=yes,status=no,titlebar=no,location=no,toolbar=no,menubar=no,width=500,height=700`);return t?.addEventListener(`abort`,()=>{n?.close()}),n}async function T(e,t){return await new Promise(n=>{let r=new BroadcastChannel(`oauth-callback`),i=!1,s=e=>{i||(i=!0,r.close(),n(e))};t?.addEventListener(`abort`,()=>{s(!1)}),r.addEventListener(`message`,t=>{e.close(),t.data===`success`?(a.showMessage({title:o.baseText(`nodeCredentials.oauth.accountConnected`),type:`success`}),s(!0)):(a.showMessage({title:o.baseText(`nodeCredentials.oauth.accountConnectionFailed`),type:`error`}),s(!1))})})}async function E(e,t){let n=await x(e);if(!n.ok)return n.error===`no-url`&&C(),!1;if(!S(n.result))return C(),!1;let r=w(n.result,t);return r?await T(r,t):(C(),!1)}async function D(e,i){let s=t.getCredentialTypeByName(e);if(!s)return null;let c;try{c=await t.createNewCredential({id:``,name:s.displayName,type:e,data:{allowedHttpRequestDomains:`none`}},n.currentProject?.id,void 0,{skipStoreUpdate:!0}),d.track(`User created credentials`,{credential_type:c.type,credential_id:c.id,workflow_id:r.workflowId})}catch(e){return a.showError(e,o.baseText(`nodeCredentials.showMessage.title`)),null}let l=new AbortController;p.value=l,g.value=c.id;let u=await E(c,l.signal);p.value=null,g.value=null;let f={credential_type:e,workflow_id:r.workflowId??null,credential_id:c.id,is_complete:!0,is_new:!0,is_valid:u,uses_external_secrets:!1};return i&&(f.node_type=i),d.track(`User saved credentials`,f),u?(t.upsertCredential(c),c):(t.deleteCredential({id:c.id}),null)}function O(){p.value&&p.value.abort(),g.value&&t.deleteCredential({id:g.value})}return{getParentTypes:_,isOAuthCredentialType:v,isGoogleOAuthType:y,hasManagedOAuthCredentials:b,authorize:E,createAndAuthorize:D,cancelAuthorize:O}}async function b(e,{quickConnectType:t}){return await g(e,`POST`,`/quick-connect`,{quickConnectType:t})}function x(){let f=v(),m=l(),h=o(),g=s(),x=i(),S=u(),C=c(),w=_(),T=p(),E=e(!1),{isOAuthCredentialType:D,createAndAuthorize:O,cancelAuthorize:k}=y(),A=[],j=n(()=>{let e=new Map;for(let t of f.moduleSettings[`quick-connect`]?.options??[])e.set(t.credentialType,t);return e}),M=n(()=>{let e=new Map;for(let t of f.moduleSettings[`quick-connect`]?.options??[])e.has(t.packageName)||e.set(t.packageName,t);return e});function N(e,t){if(j.value.size===0)return;let n=j.value.get(e);if(!n)return;let r=t.split(`.`)[0];return n.packageName.split(`.`)[0]===r?n:void 0}function P(e){if(M.value.size!==0)return M.value.get(e)}function F(e){if(j.value.size!==0)for(let t of e){let e=j.value.get(t);if(e)return e}}async function I(e){let{ConnectPopup:t}=await a(async()=>{let{ConnectPopup:e}=await import(`./dist-pi8y4l-u.js`);return{ConnectPopup:e}},[]);return await new Promise(n=>{let r=t({onConnect:({key:e})=>n({apiKey:e}),onCancel:()=>n(null),integrationId:String(e.config.integrationId)});r.open(),A.push(()=>r.cleanup())})}async function L(e){return E.value=!0,await b(w.restApiContext,e)}async function R(e){switch(e.quickConnectType){case`pinecone`:return await I(e);case`firecrawl`:return await L(e);default:throw Error(`Quick connect for type ${e.quickConnectType} is not implemented`)}}function z(){A.splice(0,A.length).forEach(e=>{try{e()}catch{}})}r(z);function B(e){let t=T.currentUser;return t?[`email`,`firstName`,`fullName`,`lastName`].reduce((e,n)=>e.replaceAll(`{user.${n}}`,t[n]??``),e):e}async function V(e){z();let{credentialTypeName:n,nodeType:r,source:i}=e;if(m.track(`User clicked quick connect button`,{source:i,credential_type:n,node_type:r}),D(n))return await O(n,r);let a=N(n,r);if(a){let r=S.getCredentialTypeByName(n);if(!r)return null;try{if(a.consentText&&await h.confirm(t(`span`,{innerHTML:d(B(a.consentText))}),x.baseText(`nodeCredentials.quickConnect.connectTo`,{interpolate:{provider:e.serviceName}}),{customClass:`wide`,confirmButtonText:x.baseText(`nodeCredentials.quickConnect.consent.confirm`),cancelButtonText:x.baseText(`nodeCredentials.quickConnect.consent.cancel`),confirmationCheckboxMessage:a.consentCheckbox?t(`span`,{innerHTML:d(a.consentCheckbox)}):void 0})!==`confirm`)return null;let i=await R(a);return i?await S.createNewCredential({id:``,name:r.displayName,type:n,data:{...i,allowedHttpRequestDomains:`none`}},C.currentProject?.id):null}catch(e){return g.showError(e,x.baseText(`credentialEdit.credentialEdit.showError.createCredential.title`)),null}finally{E.value=!1,z()}}return null}return{loading:E,getQuickConnectOption:N,getQuickConnectOptionByPackageName:P,getQuickConnectOptionByCredentialTypes:F,connect:V,cancelConnect:k}}export{y as n,x as t};
//# sourceMappingURL=useQuickConnect-BzxUKzfb.js.map