fix: Prevent workflow breaking when credential type is unknown (#6923)
This commit is contained in:
@@ -1,4 +1,12 @@
|
||||
import type { INodeUi, IUsedCredential } from '../Interface';
|
||||
import type {
|
||||
INodeUi,
|
||||
IUsedCredential,
|
||||
ICredentialMap,
|
||||
ICredentialsDecryptedResponse,
|
||||
ICredentialsResponse,
|
||||
ICredentialsState,
|
||||
ICredentialTypeMap,
|
||||
} from '../Interface';
|
||||
import {
|
||||
createNewCredential,
|
||||
deleteCredential,
|
||||
@@ -15,19 +23,11 @@ import { setCredentialSharedWith } from '@/api/credentials.ee';
|
||||
import { makeRestApiRequest } from '@/utils/apiUtils';
|
||||
import { getAppNameFromCredType } from '@/utils/nodeTypesUtils';
|
||||
import { EnterpriseEditionFeature, STORES } from '@/constants';
|
||||
import type {
|
||||
ICredentialMap,
|
||||
ICredentialsDecryptedResponse,
|
||||
ICredentialsResponse,
|
||||
ICredentialsState,
|
||||
ICredentialTypeMap,
|
||||
} from '@/Interface';
|
||||
import { i18n } from '@/plugins/i18n';
|
||||
import type {
|
||||
ICredentialsDecrypted,
|
||||
ICredentialType,
|
||||
INodeCredentialTestResult,
|
||||
INodeProperties,
|
||||
INodeTypeDescription,
|
||||
IUser,
|
||||
} from 'n8n-workflow';
|
||||
@@ -77,7 +77,7 @@ export const useCredentialsStore = defineStore(STORES.CREDENTIALS, {
|
||||
return (node: INodeUi): ICredentialsResponse[] => {
|
||||
let credentials: ICredentialsResponse[] = [];
|
||||
const nodeType = useNodeTypesStore().getNodeType(node.type, node.typeVersion);
|
||||
if (nodeType && nodeType.credentials) {
|
||||
if (nodeType?.credentials) {
|
||||
nodeType.credentials.forEach((cred) => {
|
||||
credentials = credentials.concat(this.allUsableCredentialsByType[cred.name]);
|
||||
});
|
||||
@@ -106,7 +106,7 @@ export const useCredentialsStore = defineStore(STORES.CREDENTIALS, {
|
||||
);
|
||||
},
|
||||
getCredentialTypeByName() {
|
||||
return (type: string): ICredentialType => this.credentialTypes[type];
|
||||
return (type: string): ICredentialType | undefined => this.credentialTypes[type];
|
||||
},
|
||||
getCredentialById() {
|
||||
return (id: string): ICredentialsResponse => this.credentials[id];
|
||||
@@ -149,9 +149,10 @@ export const useCredentialsStore = defineStore(STORES.CREDENTIALS, {
|
||||
},
|
||||
getScopesByCredentialType() {
|
||||
return (credentialTypeName: string) => {
|
||||
const credentialType = this.getCredentialTypeByName(credentialTypeName) as {
|
||||
properties: INodeProperties[];
|
||||
};
|
||||
const credentialType = this.getCredentialTypeByName(credentialTypeName);
|
||||
if (!credentialType) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const scopeProperty = credentialType.properties.find((p) => p.name === 'scope');
|
||||
|
||||
@@ -232,7 +233,7 @@ export const useCredentialsStore = defineStore(STORES.CREDENTIALS, {
|
||||
// enable oauth event to track change between modals
|
||||
},
|
||||
async fetchCredentialTypes(forceFetch: boolean): Promise<void> {
|
||||
if (this.allCredentialTypes.length > 0 && forceFetch !== true) {
|
||||
if (this.allCredentialTypes.length > 0 && !forceFetch) {
|
||||
return;
|
||||
}
|
||||
const rootStore = useRootStore();
|
||||
@@ -337,8 +338,8 @@ export const useCredentialsStore = defineStore(STORES.CREDENTIALS, {
|
||||
const { credentialTypeName } = params;
|
||||
let newName = DEFAULT_CREDENTIAL_NAME;
|
||||
if (!TYPES_WITH_DEFAULT_NAME.includes(credentialTypeName)) {
|
||||
const { displayName } = this.getCredentialTypeByName(credentialTypeName);
|
||||
newName = getAppNameFromCredType(displayName);
|
||||
const cred = this.getCredentialTypeByName(credentialTypeName);
|
||||
newName = cred ? getAppNameFromCredType(cred.displayName) : '';
|
||||
newName =
|
||||
newName.length > 0
|
||||
? `${newName} ${DEFAULT_CREDENTIAL_POSTFIX}`
|
||||
|
||||
Reference in New Issue
Block a user