2021-09-11 01:15:36 -07:00
|
|
|
<template>
|
2023-01-27 00:05:43 -08:00
|
|
|
<div :class="$style.container" data-test-id="node-credentials-config-container">
|
2021-09-11 01:15:36 -07:00
|
|
|
<banner
|
|
|
|
v-show="showValidationWarning"
|
|
|
|
theme="danger"
|
2022-12-21 07:42:07 -08:00
|
|
|
:message="
|
|
|
|
$locale.baseText(
|
|
|
|
`credentialEdit.credentialConfig.pleaseCheckTheErrorsBelow${
|
|
|
|
credentialPermissions.isOwner ? '' : '.sharee'
|
|
|
|
}`,
|
|
|
|
{ interpolate: { owner: credentialOwnerName } },
|
|
|
|
)
|
|
|
|
"
|
2021-09-11 01:15:36 -07:00
|
|
|
/>
|
|
|
|
|
|
|
|
<banner
|
|
|
|
v-if="authError && !showValidationWarning"
|
|
|
|
theme="danger"
|
2022-12-14 01:04:10 -08:00
|
|
|
:message="
|
|
|
|
$locale.baseText(
|
|
|
|
`credentialEdit.credentialConfig.couldntConnectWithTheseSettings${
|
2022-12-21 07:42:07 -08:00
|
|
|
credentialPermissions.isOwner ? '' : '.sharee'
|
2022-12-14 01:04:10 -08:00
|
|
|
}`,
|
|
|
|
{ interpolate: { owner: credentialOwnerName } },
|
|
|
|
)
|
|
|
|
"
|
2021-09-11 01:15:36 -07:00
|
|
|
:details="authError"
|
2021-12-15 04:16:53 -08:00
|
|
|
:buttonLabel="$locale.baseText('credentialEdit.credentialConfig.retry')"
|
2021-09-11 01:15:36 -07:00
|
|
|
buttonLoadingLabel="Retrying"
|
2021-12-15 04:16:53 -08:00
|
|
|
:buttonTitle="$locale.baseText('credentialEdit.credentialConfig.retryCredentialTest')"
|
2021-09-11 01:15:36 -07:00
|
|
|
:buttonLoading="isRetesting"
|
|
|
|
@click="$emit('retest')"
|
|
|
|
/>
|
|
|
|
|
|
|
|
<banner
|
|
|
|
v-show="showOAuthSuccessBanner && !showValidationWarning"
|
|
|
|
theme="success"
|
2021-12-15 04:16:53 -08:00
|
|
|
:message="$locale.baseText('credentialEdit.credentialConfig.accountConnected')"
|
|
|
|
:buttonLabel="$locale.baseText('credentialEdit.credentialConfig.reconnect')"
|
|
|
|
:buttonTitle="$locale.baseText('credentialEdit.credentialConfig.reconnectOAuth2Credential')"
|
2021-09-11 01:15:36 -07:00
|
|
|
@click="$emit('oauth')"
|
2023-01-25 06:25:11 -08:00
|
|
|
>
|
|
|
|
<template #button>
|
|
|
|
<p
|
|
|
|
v-text="`${$locale.baseText('credentialEdit.credentialConfig.reconnect')}:`"
|
|
|
|
:class="$style.googleReconnectLabel"
|
|
|
|
/>
|
|
|
|
<GoogleAuthButton v-if="isGoogleOAuthType" @click="$emit('oauth')" />
|
|
|
|
</template>
|
|
|
|
</banner>
|
2021-09-11 01:15:36 -07:00
|
|
|
|
|
|
|
<banner
|
|
|
|
v-show="testedSuccessfully && !showValidationWarning"
|
|
|
|
theme="success"
|
2021-12-15 04:16:53 -08:00
|
|
|
:message="$locale.baseText('credentialEdit.credentialConfig.connectionTestedSuccessfully')"
|
|
|
|
:buttonLabel="$locale.baseText('credentialEdit.credentialConfig.retry')"
|
|
|
|
:buttonLoadingLabel="$locale.baseText('credentialEdit.credentialConfig.retrying')"
|
|
|
|
:buttonTitle="$locale.baseText('credentialEdit.credentialConfig.retryCredentialTest')"
|
2021-09-11 01:15:36 -07:00
|
|
|
:buttonLoading="isRetesting"
|
|
|
|
@click="$emit('retest')"
|
|
|
|
/>
|
|
|
|
|
2022-09-21 01:20:29 -07:00
|
|
|
<template v-if="credentialPermissions.updateConnection">
|
|
|
|
<n8n-notice v-if="documentationUrl && credentialProperties.length" theme="warning">
|
|
|
|
{{ $locale.baseText('credentialEdit.credentialConfig.needHelpFillingOutTheseFields') }}
|
|
|
|
<span class="ml-4xs">
|
|
|
|
<n8n-link :to="documentationUrl" size="small" bold @click="onDocumentationUrlClick">
|
|
|
|
{{ $locale.baseText('credentialEdit.credentialConfig.openDocs') }}
|
|
|
|
</n8n-link>
|
|
|
|
</span>
|
|
|
|
</n8n-notice>
|
|
|
|
|
2023-01-27 00:05:43 -08:00
|
|
|
<AuthTypeSelector
|
|
|
|
v-if="showAuthTypeSelector && isNewCredential"
|
|
|
|
:credentialType="credentialType"
|
|
|
|
@authTypeChanged="onAuthTypeChange"
|
|
|
|
/>
|
|
|
|
|
2022-09-21 01:20:29 -07:00
|
|
|
<CopyInput
|
|
|
|
v-if="isOAuthType && credentialProperties.length"
|
|
|
|
:label="$locale.baseText('credentialEdit.credentialConfig.oAuthRedirectUrl')"
|
|
|
|
:value="oAuthCallbackUrl"
|
|
|
|
:copyButtonText="$locale.baseText('credentialEdit.credentialConfig.clickToCopy')"
|
2022-12-14 01:04:10 -08:00
|
|
|
:hint="
|
|
|
|
$locale.baseText('credentialEdit.credentialConfig.subtitle', { interpolate: { appName } })
|
|
|
|
"
|
|
|
|
:toastTitle="
|
|
|
|
$locale.baseText('credentialEdit.credentialConfig.redirectUrlCopiedToClipboard')
|
|
|
|
"
|
2022-09-21 01:20:29 -07:00
|
|
|
/>
|
|
|
|
</template>
|
2022-12-14 01:04:10 -08:00
|
|
|
<enterprise-edition v-else :features="[EnterpriseEditionFeature.Sharing]">
|
2022-09-21 01:20:29 -07:00
|
|
|
<div class="ph-no-capture">
|
|
|
|
<n8n-info-tip :bold="false">
|
2022-12-14 01:04:10 -08:00
|
|
|
{{
|
|
|
|
$locale.baseText('credentialEdit.credentialEdit.info.sharee', {
|
|
|
|
interpolate: { credentialOwnerName },
|
|
|
|
})
|
|
|
|
}}
|
2022-09-21 01:20:29 -07:00
|
|
|
</n8n-info-tip>
|
|
|
|
</div>
|
|
|
|
</enterprise-edition>
|
2021-09-11 01:15:36 -07:00
|
|
|
|
|
|
|
<CredentialInputs
|
2022-09-21 01:20:29 -07:00
|
|
|
v-if="credentialType && credentialPermissions.updateConnection"
|
2021-09-11 01:15:36 -07:00
|
|
|
:credentialData="credentialData"
|
|
|
|
:credentialProperties="credentialProperties"
|
|
|
|
:documentationUrl="documentationUrl"
|
|
|
|
:showValidationWarnings="showValidationWarning"
|
|
|
|
@change="onDataChange"
|
|
|
|
/>
|
|
|
|
|
|
|
|
<OauthButton
|
2022-12-14 01:04:10 -08:00
|
|
|
v-if="
|
|
|
|
isOAuthType &&
|
|
|
|
requiredPropertiesFilled &&
|
|
|
|
!isOAuthConnected &&
|
|
|
|
credentialPermissions.isOwner
|
|
|
|
"
|
2021-09-11 01:15:36 -07:00
|
|
|
:isGoogleOAuthType="isGoogleOAuthType"
|
|
|
|
@click="$emit('oauth')"
|
|
|
|
/>
|
2022-09-21 01:20:29 -07:00
|
|
|
|
2023-01-27 00:05:43 -08:00
|
|
|
<n8n-text v-if="isMissingCredentials" color="text-base" size="medium">
|
2022-09-21 01:20:29 -07:00
|
|
|
{{ $locale.baseText('credentialEdit.credentialConfig.missingCredentialType') }}
|
|
|
|
</n8n-text>
|
2021-09-11 01:15:36 -07:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2023-01-27 00:05:43 -08:00
|
|
|
import { ICredentialType, INodeTypeDescription } from 'n8n-workflow';
|
2022-11-23 04:41:53 -08:00
|
|
|
import { getAppNameFromCredType, isCommunityPackageName } from '@/utils';
|
2021-09-11 01:15:36 -07:00
|
|
|
|
|
|
|
import Banner from '../Banner.vue';
|
|
|
|
import CopyInput from '../CopyInput.vue';
|
|
|
|
import CredentialInputs from './CredentialInputs.vue';
|
|
|
|
import OauthButton from './OauthButton.vue';
|
2022-11-23 04:41:53 -08:00
|
|
|
import { restApi } from '@/mixins/restApi';
|
2022-01-07 13:02:21 -08:00
|
|
|
import { addCredentialTranslation } from '@/plugins/i18n';
|
2021-11-10 10:41:40 -08:00
|
|
|
import mixins from 'vue-typed-mixins';
|
2022-12-22 08:01:29 -08:00
|
|
|
import { BUILTIN_CREDENTIALS_DOCS_URL, DOCS_DOMAIN, EnterpriseEditionFeature } from '@/constants';
|
2022-12-14 01:04:10 -08:00
|
|
|
import { IPermissions } from '@/permissions';
|
2022-11-04 06:04:31 -07:00
|
|
|
import { mapStores } from 'pinia';
|
|
|
|
import { useUIStore } from '@/stores/ui';
|
|
|
|
import { useWorkflowsStore } from '@/stores/workflows';
|
|
|
|
import { useRootStore } from '@/stores/n8nRootStore';
|
|
|
|
import { useNDVStore } from '@/stores/ndv';
|
2022-11-09 01:01:50 -08:00
|
|
|
import { useCredentialsStore } from '@/stores/credentials';
|
2023-01-27 00:05:43 -08:00
|
|
|
import { useNodeTypesStore } from '@/stores/nodeTypes';
|
|
|
|
import { ICredentialsResponse, IUpdateInformation, NodeAuthenticationOption } from '@/Interface';
|
|
|
|
import ParameterInputFull from '@/components/ParameterInputFull.vue';
|
|
|
|
import AuthTypeSelector from '@/components/CredentialEdit/AuthTypeSelector.vue';
|
2023-01-25 06:25:11 -08:00
|
|
|
import GoogleAuthButton from './GoogleAuthButton.vue';
|
2021-09-11 01:15:36 -07:00
|
|
|
|
2021-12-07 07:14:40 -08:00
|
|
|
export default mixins(restApi).extend({
|
2021-09-11 01:15:36 -07:00
|
|
|
name: 'CredentialConfig',
|
|
|
|
components: {
|
2023-01-27 00:05:43 -08:00
|
|
|
AuthTypeSelector,
|
2021-09-11 01:15:36 -07:00
|
|
|
Banner,
|
|
|
|
CopyInput,
|
|
|
|
CredentialInputs,
|
|
|
|
OauthButton,
|
2023-01-27 00:05:43 -08:00
|
|
|
ParameterInputFull,
|
2023-01-25 06:25:11 -08:00
|
|
|
GoogleAuthButton,
|
2021-09-11 01:15:36 -07:00
|
|
|
},
|
|
|
|
props: {
|
|
|
|
credentialType: {
|
2021-11-15 02:19:43 -08:00
|
|
|
type: Object,
|
2021-09-11 01:15:36 -07:00
|
|
|
},
|
|
|
|
credentialProperties: {
|
|
|
|
type: Array,
|
|
|
|
},
|
|
|
|
parentTypes: {
|
|
|
|
type: Array,
|
|
|
|
},
|
2022-12-14 01:04:10 -08:00
|
|
|
credentialData: {},
|
2022-09-21 01:20:29 -07:00
|
|
|
credentialId: {
|
2023-01-02 08:42:32 -08:00
|
|
|
type: String,
|
2022-09-21 01:20:29 -07:00
|
|
|
default: '',
|
|
|
|
},
|
2021-09-11 01:15:36 -07:00
|
|
|
showValidationWarning: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
authError: {
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
testedSuccessfully: {
|
|
|
|
type: Boolean,
|
|
|
|
},
|
|
|
|
isOAuthType: {
|
|
|
|
type: Boolean,
|
|
|
|
},
|
|
|
|
isOAuthConnected: {
|
|
|
|
type: Boolean,
|
|
|
|
},
|
|
|
|
isRetesting: {
|
|
|
|
type: Boolean,
|
|
|
|
},
|
2022-09-21 01:20:29 -07:00
|
|
|
credentialPermissions: {
|
|
|
|
type: Object,
|
|
|
|
default: (): IPermissions => ({}),
|
|
|
|
},
|
2021-09-11 01:15:36 -07:00
|
|
|
requiredPropertiesFilled: {
|
|
|
|
type: Boolean,
|
|
|
|
},
|
2023-01-27 00:05:43 -08:00
|
|
|
mode: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
showAuthTypeSelector: {
|
|
|
|
type: Boolean,
|
|
|
|
},
|
2021-09-11 01:15:36 -07:00
|
|
|
},
|
2022-09-21 01:20:29 -07:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
EnterpriseEditionFeature,
|
|
|
|
};
|
|
|
|
},
|
2021-11-15 02:19:43 -08:00
|
|
|
async beforeMount() {
|
2022-11-04 06:04:31 -07:00
|
|
|
if (this.rootStore.defaultLocale === 'en') return;
|
2022-01-07 13:02:21 -08:00
|
|
|
|
2022-11-04 06:04:31 -07:00
|
|
|
this.uiStore.activeCredentialType = this.credentialType.name;
|
2022-01-07 13:02:21 -08:00
|
|
|
|
|
|
|
const key = `n8n-nodes-base.credentials.${this.credentialType.name}`;
|
|
|
|
|
|
|
|
if (this.$locale.exists(key)) return;
|
|
|
|
|
|
|
|
const credTranslation = await this.restApi().getCredentialTranslation(this.credentialType.name);
|
|
|
|
|
|
|
|
addCredentialTranslation(
|
|
|
|
{ [this.credentialType.name]: credTranslation },
|
2022-11-04 06:04:31 -07:00
|
|
|
this.rootStore.defaultLocale,
|
2022-01-07 13:02:21 -08:00
|
|
|
);
|
2021-11-15 02:19:43 -08:00
|
|
|
},
|
2021-09-11 01:15:36 -07:00
|
|
|
computed: {
|
2023-01-27 00:05:43 -08:00
|
|
|
...mapStores(
|
|
|
|
useCredentialsStore,
|
|
|
|
useNDVStore,
|
|
|
|
useNodeTypesStore,
|
|
|
|
useRootStore,
|
|
|
|
useUIStore,
|
|
|
|
useWorkflowsStore,
|
|
|
|
),
|
|
|
|
activeNodeType(): INodeTypeDescription | null {
|
|
|
|
const activeNode = this.ndvStore.activeNode;
|
|
|
|
|
|
|
|
if (activeNode) {
|
|
|
|
return this.nodeTypesStore.getNodeType(activeNode.type, activeNode.typeVersion);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
2021-09-11 01:15:36 -07:00
|
|
|
appName(): string {
|
|
|
|
if (!this.credentialType) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2022-12-14 01:04:10 -08:00
|
|
|
const appName = getAppNameFromCredType((this.credentialType as ICredentialType).displayName);
|
2021-09-11 01:15:36 -07:00
|
|
|
|
2022-12-14 01:04:10 -08:00
|
|
|
return (
|
|
|
|
appName ||
|
|
|
|
this.$locale.baseText('credentialEdit.credentialConfig.theServiceYouReConnectingTo')
|
|
|
|
);
|
2021-09-11 01:15:36 -07:00
|
|
|
},
|
|
|
|
credentialTypeName(): string {
|
|
|
|
return (this.credentialType as ICredentialType).name;
|
|
|
|
},
|
2022-09-21 01:20:29 -07:00
|
|
|
credentialOwnerName(): string {
|
2022-12-12 01:53:22 -08:00
|
|
|
return this.credentialsStore.getCredentialOwnerName(`${this.credentialId}`);
|
2022-09-21 01:20:29 -07:00
|
|
|
},
|
2021-09-11 01:15:36 -07:00
|
|
|
documentationUrl(): string {
|
|
|
|
const type = this.credentialType as ICredentialType;
|
2022-11-04 06:04:31 -07:00
|
|
|
const activeNode = this.ndvStore.activeNode;
|
2022-07-21 03:50:34 -07:00
|
|
|
const isCommunityNode = activeNode ? isCommunityPackageName(activeNode.type) : false;
|
2021-09-11 01:15:36 -07:00
|
|
|
|
2022-12-22 08:01:29 -08:00
|
|
|
const documentationUrl = type && type.documentationUrl;
|
|
|
|
|
|
|
|
if (!documentationUrl) {
|
2021-09-11 01:15:36 -07:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2022-12-22 08:01:29 -08:00
|
|
|
let url: URL;
|
|
|
|
if (documentationUrl.startsWith('https://') || documentationUrl.startsWith('http://')) {
|
|
|
|
url = new URL(documentationUrl);
|
|
|
|
if (url.hostname !== DOCS_DOMAIN) return documentationUrl;
|
|
|
|
} else {
|
|
|
|
// Don't show documentation link for community nodes if the URL is not an absolute path
|
|
|
|
if (isCommunityNode) return '';
|
|
|
|
else url = new URL(`${BUILTIN_CREDENTIALS_DOCS_URL}${documentationUrl}/`);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (url.hostname === DOCS_DOMAIN) {
|
|
|
|
url.searchParams.set('utm_source', 'n8n_app');
|
|
|
|
url.searchParams.set('utm_medium', 'left_nav_menu');
|
|
|
|
url.searchParams.set('utm_campaign', 'create_new_credentials_modal');
|
2021-09-11 01:15:36 -07:00
|
|
|
}
|
|
|
|
|
2022-12-22 08:01:29 -08:00
|
|
|
return url.href;
|
2021-09-11 01:15:36 -07:00
|
|
|
},
|
|
|
|
isGoogleOAuthType(): boolean {
|
2022-12-14 01:04:10 -08:00
|
|
|
return (
|
|
|
|
this.credentialTypeName === 'googleOAuth2Api' ||
|
|
|
|
this.parentTypes.includes('googleOAuth2Api')
|
|
|
|
);
|
2021-09-11 01:15:36 -07:00
|
|
|
},
|
|
|
|
oAuthCallbackUrl(): string {
|
|
|
|
const oauthType =
|
2022-12-14 01:04:10 -08:00
|
|
|
this.credentialTypeName === 'oAuth2Api' || this.parentTypes.includes('oAuth2Api')
|
2021-09-11 01:15:36 -07:00
|
|
|
? 'oauth2'
|
|
|
|
: 'oauth1';
|
2022-11-04 06:04:31 -07:00
|
|
|
return this.rootStore.oauthCallbackUrls[oauthType as keyof {}];
|
2021-09-11 01:15:36 -07:00
|
|
|
},
|
|
|
|
showOAuthSuccessBanner(): boolean {
|
2022-12-14 01:04:10 -08:00
|
|
|
return (
|
|
|
|
this.isOAuthType &&
|
|
|
|
this.requiredPropertiesFilled &&
|
|
|
|
this.isOAuthConnected &&
|
|
|
|
!this.authError
|
|
|
|
);
|
2021-09-11 01:15:36 -07:00
|
|
|
},
|
2023-01-27 00:05:43 -08:00
|
|
|
isMissingCredentials(): boolean {
|
|
|
|
return this.credentialType === null;
|
|
|
|
},
|
|
|
|
isNewCredential(): boolean {
|
|
|
|
return this.mode === 'new' && !this.credentialId;
|
|
|
|
},
|
2021-09-11 01:15:36 -07:00
|
|
|
},
|
|
|
|
methods: {
|
2023-01-27 00:05:43 -08:00
|
|
|
getCredentialOptions(type: string): ICredentialsResponse[] {
|
|
|
|
return this.credentialsStore.allUsableCredentialsByType[type];
|
|
|
|
},
|
2022-12-14 01:04:10 -08:00
|
|
|
onDataChange(event: { name: string; value: string | number | boolean | Date | null }): void {
|
2021-09-11 01:15:36 -07:00
|
|
|
this.$emit('change', event);
|
|
|
|
},
|
2022-12-14 01:04:10 -08:00
|
|
|
onDocumentationUrlClick(): void {
|
2021-10-18 20:57:49 -07:00
|
|
|
this.$telemetry.track('User clicked credential modal docs link', {
|
|
|
|
docs_link: this.documentationUrl,
|
|
|
|
credential_type: this.credentialTypeName,
|
|
|
|
source: 'modal',
|
2022-11-04 06:04:31 -07:00
|
|
|
workflow_id: this.workflowsStore.workflowId,
|
2021-10-18 20:57:49 -07:00
|
|
|
});
|
|
|
|
},
|
2023-01-27 00:05:43 -08:00
|
|
|
onAuthTypeChange(newType: string): void {
|
|
|
|
this.$emit('authTypeChanged', newType);
|
|
|
|
},
|
2021-09-11 01:15:36 -07:00
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
showOAuthSuccessBanner(newValue, oldValue) {
|
|
|
|
if (newValue && !oldValue) {
|
|
|
|
this.$emit('scrollToTop');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" module>
|
|
|
|
.container {
|
2022-08-30 02:10:17 -07:00
|
|
|
--notice-margin: 0;
|
2021-09-11 01:15:36 -07:00
|
|
|
> * {
|
|
|
|
margin-bottom: var(--spacing-l);
|
|
|
|
}
|
|
|
|
}
|
2023-01-25 06:25:11 -08:00
|
|
|
.googleReconnectLabel {
|
|
|
|
margin-right: var(--spacing-3xs);
|
|
|
|
}
|
2021-09-11 01:15:36 -07:00
|
|
|
</style>
|