n8n-editor-ui
Version:
Workflow Editor UI for n8n
2 lines • 7.04 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.13.4`}}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]=`2c4260b2-0a6a-4534-8ebb-d905c8639138`,e._sentryDebugIdIdentifier=`sentry-dbid-2c4260b2-0a6a-4534-8ebb-d905c8639138`)})()}catch{}import{Ft as e,I as t,S as n,q as r}from"./vue.runtime.esm-bundler-D9KLAxvJ.js";import{bt as i}from"./_MapCache-CUJwh2qp.js";import{na as a}from"./src-wni2AGA3.js";import{As as o,Ft as s,Tr as c,at as l,en as u,jr as d,pl as f,s as p,t as m}from"./users.store-BHWXXawf.js";import{Fi as h,Ii as g,Ps as _}from"./constants-CIP7tKq1.js";import{d as v,r as y}from"./_baseOrderBy-CaKruttV.js";function b(){let t=l(),n=s(),r=p(),a=c(),o=i(),d=u(),f=e(null),m=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 g(await t.oAuth2Authorize(e));if(e.type===`oAuth1Api`||n.includes(`oAuth1Api`))return g(await t.oAuth1Authorize(e))}catch(e){return a.showError(e,o.baseText(`credentialEdit.credentialEdit.showError.generateAuthorizationUrl.title`)),h(`api-error`)}return h(`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;f.value=l,m.value=c.id;let u=await E(c,l.signal);f.value=null,m.value=null;let p={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&&(p.node_type=i),d.track(`User saved credentials`,p),u?(t.upsertCredential(c),c):(t.deleteCredential({id:c.id}),null)}function O(){f.value&&f.value.abort(),m.value&&t.deleteCredential({id:m.value})}return{getParentTypes:_,isOAuthCredentialType:v,isGoogleOAuthType:y,hasManagedOAuthCredentials:b,authorize:E,createAndAuthorize:D,cancelAuthorize:O}}async function x(e,{quickConnectType:t}){return await v(e,`POST`,`/quick-connect`,{quickConnectType:t})}function S(){let p=o(),h=u(),g=d(),_=c(),v=i(),S=l(),C=s(),w=y(),T=m(),E=e(!1),{isOAuthCredentialType:D,createAndAuthorize:O,cancelAuthorize:k}=b(),A=[],j=n(()=>{let e=new Map;for(let t of p.moduleSettings[`quick-connect`]?.options??[])e.set(t.credentialType,t);return e}),M=n(()=>{let e=new Map;for(let t of p.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-QrCgEID4.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 x(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(h.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 g.confirm(t(`span`,{innerHTML:f(B(a.consentText))}),v.baseText(`nodeCredentials.quickConnect.connectTo`,{interpolate:{provider:e.serviceName}}),{customClass:`wide`,confirmButtonText:v.baseText(`nodeCredentials.quickConnect.consent.confirm`),cancelButtonText:v.baseText(`nodeCredentials.quickConnect.consent.cancel`),confirmationCheckboxMessage:a.consentCheckbox?t(`span`,{innerHTML:f(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 _.showError(e,v.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{b as n,S as t};
//# sourceMappingURL=useQuickConnect-CGSObYV3.js.map