2021-09-11 01:15:36 -07:00
|
|
|
<template>
|
|
|
|
<div :class="$style.container">
|
|
|
|
<banner
|
|
|
|
v-show="showValidationWarning"
|
|
|
|
theme="danger"
|
2021-12-15 04:16:53 -08:00
|
|
|
:message="$locale.baseText('credentialEdit.credentialConfig.pleaseCheckTheErrorsBelow')"
|
2021-09-11 01:15:36 -07:00
|
|
|
/>
|
|
|
|
|
|
|
|
<banner
|
|
|
|
v-if="authError && !showValidationWarning"
|
|
|
|
theme="danger"
|
2021-12-15 04:16:53 -08:00
|
|
|
:message="$locale.baseText('credentialEdit.credentialConfig.couldntConnectWithTheseSettings')"
|
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')"
|
|
|
|
/>
|
|
|
|
|
|
|
|
<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>
|
|
|
|
|
|
|
|
<CopyInput
|
|
|
|
v-if="isOAuthType && credentialProperties.length"
|
|
|
|
:label="$locale.baseText('credentialEdit.credentialConfig.oAuthRedirectUrl')"
|
|
|
|
:value="oAuthCallbackUrl"
|
|
|
|
:copyButtonText="$locale.baseText('credentialEdit.credentialConfig.clickToCopy')"
|
|
|
|
:hint="$locale.baseText('credentialEdit.credentialConfig.subtitle', { interpolate: { appName } })"
|
|
|
|
:toastTitle="$locale.baseText('credentialEdit.credentialConfig.redirectUrlCopiedToClipboard')"
|
|
|
|
/>
|
|
|
|
</template>
|
|
|
|
<enterprise-edition
|
|
|
|
v-else
|
|
|
|
:features="[EnterpriseEditionFeature.Sharing]"
|
|
|
|
>
|
|
|
|
<div class="ph-no-capture">
|
|
|
|
<n8n-info-tip :bold="false">
|
|
|
|
{{ $locale.baseText('credentialEdit.credentialEdit.info.sharee', { interpolate: { credentialOwnerName } }) }}
|
|
|
|
</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-09-21 01:20:29 -07: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
|
|
|
|
|
|
|
<n8n-text v-if="!credentialType" color="text-base" size="medium">
|
|
|
|
{{ $locale.baseText('credentialEdit.credentialConfig.missingCredentialType') }}
|
|
|
|
</n8n-text>
|
2021-09-11 01:15:36 -07:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2022-08-30 02:10:17 -07:00
|
|
|
import { ICredentialType } from 'n8n-workflow';
|
2022-07-20 07:24:03 -07:00
|
|
|
import { getAppNameFromCredType, isCommunityPackageName } from '../helpers';
|
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';
|
2021-11-15 02:19:43 -08:00
|
|
|
import { restApi } from '@/components/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-09-29 03:33:16 -07:00
|
|
|
import { BUILTIN_CREDENTIALS_DOCS_URL, EnterpriseEditionFeature } from '@/constants';
|
|
|
|
import { IPermissions } from "@/permissions";
|
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: {
|
|
|
|
Banner,
|
|
|
|
CopyInput,
|
|
|
|
CredentialInputs,
|
|
|
|
OauthButton,
|
|
|
|
},
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
credentialData: {
|
|
|
|
},
|
2022-09-21 01:20:29 -07:00
|
|
|
credentialId: {
|
|
|
|
type: [String, Number],
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
},
|
2022-09-21 01:20:29 -07:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
EnterpriseEditionFeature,
|
|
|
|
};
|
|
|
|
},
|
2021-11-15 02:19:43 -08:00
|
|
|
async beforeMount() {
|
2022-01-07 13:02:21 -08:00
|
|
|
if (this.$store.getters.defaultLocale === 'en') return;
|
|
|
|
|
|
|
|
this.$store.commit('setActiveCredentialType', this.credentialType.name);
|
|
|
|
|
|
|
|
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 },
|
|
|
|
this.$store.getters.defaultLocale,
|
|
|
|
);
|
2021-11-15 02:19:43 -08:00
|
|
|
},
|
2021-09-11 01:15:36 -07:00
|
|
|
computed: {
|
|
|
|
appName(): string {
|
|
|
|
if (!this.credentialType) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
const appName = getAppNameFromCredType(
|
|
|
|
(this.credentialType as ICredentialType).displayName,
|
|
|
|
);
|
|
|
|
|
2021-12-15 04:16:53 -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 {
|
|
|
|
return this.$store.getters['credentials/getCredentialOwnerName'](this.credentialId);
|
|
|
|
},
|
2021-09-11 01:15:36 -07:00
|
|
|
documentationUrl(): string {
|
|
|
|
const type = this.credentialType as ICredentialType;
|
2022-10-24 02:35:03 -07:00
|
|
|
const activeNode = this.$store.getters['ndv/activeNode'];
|
2022-07-21 03:50:34 -07:00
|
|
|
const isCommunityNode = activeNode ? isCommunityPackageName(activeNode.type) : false;
|
2021-09-11 01:15:36 -07:00
|
|
|
|
|
|
|
if (!type || !type.documentationUrl) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type.documentationUrl.startsWith('https://') || type.documentationUrl.startsWith('http://')) {
|
|
|
|
return type.documentationUrl;
|
|
|
|
}
|
|
|
|
|
2022-09-29 03:33:16 -07:00
|
|
|
return isCommunityNode ?
|
2022-07-20 07:24:03 -07:00
|
|
|
'' : // Don't show documentation link for community nodes if the URL is not an absolute path
|
2022-09-29 03:33:16 -07:00
|
|
|
`${BUILTIN_CREDENTIALS_DOCS_URL}${type.documentationUrl}/?utm_source=n8n_app&utm_medium=left_nav_menu&utm_campaign=create_new_credentials_modal`;
|
2021-09-11 01:15:36 -07:00
|
|
|
},
|
|
|
|
isGoogleOAuthType(): boolean {
|
|
|
|
return this.credentialTypeName === 'googleOAuth2Api' || this.parentTypes.includes('googleOAuth2Api');
|
|
|
|
},
|
|
|
|
oAuthCallbackUrl(): string {
|
|
|
|
const oauthType =
|
|
|
|
this.credentialTypeName === 'oAuth2Api' ||
|
|
|
|
this.parentTypes.includes('oAuth2Api')
|
|
|
|
? 'oauth2'
|
|
|
|
: 'oauth1';
|
|
|
|
return this.$store.getters.oauthCallbackUrls[oauthType];
|
|
|
|
},
|
|
|
|
showOAuthSuccessBanner(): boolean {
|
|
|
|
return this.isOAuthType && this.requiredPropertiesFilled && this.isOAuthConnected && !this.authError;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
2021-10-18 20:57:49 -07:00
|
|
|
onDataChange (event: { name: string; value: string | number | boolean | Date | null }): void {
|
2021-09-11 01:15:36 -07:00
|
|
|
this.$emit('change', event);
|
|
|
|
},
|
2021-10-18 20:57:49 -07:00
|
|
|
onDocumentationUrlClick (): void {
|
|
|
|
this.$telemetry.track('User clicked credential modal docs link', {
|
|
|
|
docs_link: this.documentationUrl,
|
|
|
|
credential_type: this.credentialTypeName,
|
|
|
|
source: 'modal',
|
|
|
|
workflow_id: this.$store.getters.workflowId,
|
|
|
|
});
|
|
|
|
},
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
</style>
|