2023-08-14 05:55:38 -07:00
|
|
|
import type {
|
|
|
|
INodeUi,
|
|
|
|
IUsedCredential,
|
|
|
|
ICredentialMap,
|
|
|
|
ICredentialsDecryptedResponse,
|
|
|
|
ICredentialsResponse,
|
|
|
|
ICredentialsState,
|
|
|
|
ICredentialTypeMap,
|
2023-11-28 03:15:08 -08:00
|
|
|
} from '@/Interface';
|
2022-11-15 04:25:04 -08:00
|
|
|
import {
|
|
|
|
createNewCredential,
|
|
|
|
deleteCredential,
|
|
|
|
getAllCredentials,
|
|
|
|
getCredentialData,
|
|
|
|
getCredentialsNewName,
|
|
|
|
getCredentialTypes,
|
|
|
|
oAuth1CredentialAuthorize,
|
|
|
|
oAuth2CredentialAuthorize,
|
|
|
|
testCredential,
|
|
|
|
updateCredential,
|
|
|
|
} from '@/api/credentials';
|
2022-11-09 01:01:50 -08:00
|
|
|
import { setCredentialSharedWith } from '@/api/credentials.ee';
|
2023-05-10 08:10:03 -07:00
|
|
|
import { makeRestApiRequest } from '@/utils/apiUtils';
|
|
|
|
import { getAppNameFromCredType } from '@/utils/nodeTypesUtils';
|
2022-11-09 01:01:50 -08:00
|
|
|
import { EnterpriseEditionFeature, STORES } from '@/constants';
|
|
|
|
import { i18n } from '@/plugins/i18n';
|
2023-04-24 03:18:24 -07:00
|
|
|
import type {
|
2022-11-09 01:01:50 -08:00
|
|
|
ICredentialsDecrypted,
|
|
|
|
ICredentialType,
|
|
|
|
INodeCredentialTestResult,
|
|
|
|
INodeTypeDescription,
|
|
|
|
IUser,
|
|
|
|
} from 'n8n-workflow';
|
|
|
|
import { defineStore } from 'pinia';
|
2023-05-05 01:41:54 -07:00
|
|
|
import { useRootStore } from './n8nRoot.store';
|
|
|
|
import { useNodeTypesStore } from './nodeTypes.store';
|
|
|
|
import { useSettingsStore } from './settings.store';
|
|
|
|
import { useUsersStore } from './users.store';
|
2022-11-09 01:01:50 -08:00
|
|
|
|
|
|
|
const DEFAULT_CREDENTIAL_NAME = 'Unnamed credential';
|
|
|
|
const DEFAULT_CREDENTIAL_POSTFIX = 'account';
|
|
|
|
const TYPES_WITH_DEFAULT_NAME = ['httpBasicAuth', 'oAuth2Api', 'httpDigestAuth', 'oAuth1Api'];
|
|
|
|
|
2023-11-27 06:30:28 -08:00
|
|
|
export type CredentialsStore = ReturnType<typeof useCredentialsStore>;
|
|
|
|
|
2022-11-09 01:01:50 -08:00
|
|
|
export const useCredentialsStore = defineStore(STORES.CREDENTIALS, {
|
|
|
|
state: (): ICredentialsState => ({
|
|
|
|
credentialTypes: {},
|
|
|
|
credentials: {},
|
|
|
|
}),
|
|
|
|
getters: {
|
|
|
|
credentialTypesById(): Record<ICredentialType['name'], ICredentialType> {
|
|
|
|
return this.credentialTypes;
|
|
|
|
},
|
|
|
|
allCredentialTypes(): ICredentialType[] {
|
|
|
|
return Object.values(this.credentialTypes).sort((a, b) =>
|
|
|
|
a.displayName.localeCompare(b.displayName),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
allCredentials(): ICredentialsResponse[] {
|
|
|
|
return Object.values(this.credentials).sort((a, b) => a.name.localeCompare(b.name));
|
|
|
|
},
|
|
|
|
allCredentialsByType(): { [type: string]: ICredentialsResponse[] } {
|
|
|
|
const credentials = this.allCredentials;
|
|
|
|
const types = this.allCredentialTypes;
|
|
|
|
|
|
|
|
return types.reduce(
|
|
|
|
(accu: { [type: string]: ICredentialsResponse[] }, type: ICredentialType) => {
|
|
|
|
accu[type.name] = credentials.filter(
|
|
|
|
(cred: ICredentialsResponse) => cred.type === type.name,
|
|
|
|
);
|
|
|
|
|
|
|
|
return accu;
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
);
|
|
|
|
},
|
2023-01-27 00:05:43 -08:00
|
|
|
allUsableCredentialsForNode() {
|
|
|
|
return (node: INodeUi): ICredentialsResponse[] => {
|
|
|
|
let credentials: ICredentialsResponse[] = [];
|
|
|
|
const nodeType = useNodeTypesStore().getNodeType(node.type, node.typeVersion);
|
2023-08-14 05:55:38 -07:00
|
|
|
if (nodeType?.credentials) {
|
2023-01-27 00:05:43 -08:00
|
|
|
nodeType.credentials.forEach((cred) => {
|
|
|
|
credentials = credentials.concat(this.allUsableCredentialsByType[cred.name]);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return credentials.sort((a, b) => {
|
|
|
|
const aDate = new Date(a.updatedAt);
|
|
|
|
const bDate = new Date(b.updatedAt);
|
|
|
|
return aDate.getTime() - bDate.getTime();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
},
|
2022-12-23 07:32:06 -08:00
|
|
|
allUsableCredentialsByType(): { [type: string]: ICredentialsResponse[] } {
|
|
|
|
const credentials = this.allCredentials;
|
|
|
|
const types = this.allCredentialTypes;
|
|
|
|
const usersStore = useUsersStore();
|
|
|
|
|
|
|
|
return types.reduce(
|
|
|
|
(accu: { [type: string]: ICredentialsResponse[] }, type: ICredentialType) => {
|
|
|
|
accu[type.name] = credentials.filter((cred: ICredentialsResponse) => {
|
|
|
|
return cred.type === type.name && usersStore.isResourceAccessible(cred);
|
|
|
|
});
|
|
|
|
|
|
|
|
return accu;
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
);
|
|
|
|
},
|
2022-11-09 01:01:50 -08:00
|
|
|
getCredentialTypeByName() {
|
2023-08-14 05:55:38 -07:00
|
|
|
return (type: string): ICredentialType | undefined => this.credentialTypes[type];
|
2022-11-09 01:01:50 -08:00
|
|
|
},
|
|
|
|
getCredentialById() {
|
|
|
|
return (id: string): ICredentialsResponse => this.credentials[id];
|
|
|
|
},
|
|
|
|
getCredentialByIdAndType() {
|
|
|
|
return (id: string, type: string): ICredentialsResponse | undefined => {
|
|
|
|
const credential = this.credentials[id];
|
|
|
|
return !credential || credential.type !== type ? undefined : credential;
|
|
|
|
};
|
|
|
|
},
|
|
|
|
getCredentialsByType() {
|
|
|
|
return (credentialType: string): ICredentialsResponse[] => {
|
|
|
|
return this.allCredentialsByType[credentialType] || [];
|
2022-12-23 07:32:06 -08:00
|
|
|
};
|
|
|
|
},
|
|
|
|
getUsableCredentialByType() {
|
|
|
|
return (credentialType: string): ICredentialsResponse[] => {
|
|
|
|
return this.allUsableCredentialsByType[credentialType] || [];
|
2022-11-09 01:01:50 -08:00
|
|
|
};
|
|
|
|
},
|
|
|
|
getNodesWithAccess() {
|
|
|
|
return (credentialTypeName: string) => {
|
|
|
|
const nodeTypesStore = useNodeTypesStore();
|
2023-11-28 05:14:22 -08:00
|
|
|
const allNodeTypes: INodeTypeDescription[] = nodeTypesStore.allNodeTypes;
|
2022-11-09 01:01:50 -08:00
|
|
|
|
2023-11-28 05:14:22 -08:00
|
|
|
return allNodeTypes.filter((nodeType: INodeTypeDescription) => {
|
2022-11-09 01:01:50 -08:00
|
|
|
if (!nodeType.credentials) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const credentialTypeDescription of nodeType.credentials) {
|
|
|
|
if (credentialTypeDescription.name === credentialTypeName) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
},
|
|
|
|
getScopesByCredentialType() {
|
|
|
|
return (credentialTypeName: string) => {
|
2023-08-14 05:55:38 -07:00
|
|
|
const credentialType = this.getCredentialTypeByName(credentialTypeName);
|
|
|
|
if (!credentialType) {
|
|
|
|
return [];
|
|
|
|
}
|
2022-11-09 01:01:50 -08:00
|
|
|
|
|
|
|
const scopeProperty = credentialType.properties.find((p) => p.name === 'scope');
|
|
|
|
|
|
|
|
if (
|
|
|
|
!scopeProperty ||
|
|
|
|
!scopeProperty.default ||
|
|
|
|
typeof scopeProperty.default !== 'string' ||
|
|
|
|
scopeProperty.default === ''
|
|
|
|
) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
let { default: scopeDefault } = scopeProperty;
|
|
|
|
|
|
|
|
// disregard expressions for display
|
|
|
|
scopeDefault = scopeDefault.replace(/^=/, '').replace(/\{\{.*\}\}/, '');
|
|
|
|
|
|
|
|
if (/ /.test(scopeDefault)) return scopeDefault.split(' ');
|
|
|
|
|
|
|
|
if (/,/.test(scopeDefault)) return scopeDefault.split(',');
|
|
|
|
|
|
|
|
return [scopeDefault];
|
|
|
|
};
|
|
|
|
},
|
|
|
|
getCredentialOwnerName() {
|
2023-02-14 06:13:22 -08:00
|
|
|
return (credential: ICredentialsResponse | IUsedCredential | undefined): string => {
|
|
|
|
return credential?.ownedBy?.firstName
|
2022-11-09 01:01:50 -08:00
|
|
|
? `${credential.ownedBy.firstName} ${credential.ownedBy.lastName} (${credential.ownedBy.email})`
|
|
|
|
: i18n.baseText('credentialEdit.credentialSharing.info.sharee.fallback');
|
|
|
|
};
|
|
|
|
},
|
2023-02-14 06:13:22 -08:00
|
|
|
getCredentialOwnerNameById() {
|
|
|
|
return (credentialId: string): string => {
|
|
|
|
const credential = this.getCredentialById(credentialId);
|
|
|
|
|
|
|
|
return this.getCredentialOwnerName(credential);
|
|
|
|
};
|
|
|
|
},
|
2023-11-13 03:11:16 -08:00
|
|
|
httpOnlyCredentialTypes(): ICredentialType[] {
|
|
|
|
return this.allCredentialTypes.filter((credentialType) => credentialType.httpRequestNode);
|
|
|
|
},
|
2022-11-09 01:01:50 -08:00
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
setCredentialTypes(credentialTypes: ICredentialType[]): void {
|
|
|
|
this.credentialTypes = credentialTypes.reduce(
|
|
|
|
(accu: ICredentialTypeMap, cred: ICredentialType) => {
|
|
|
|
accu[cred.name] = cred;
|
|
|
|
|
|
|
|
return accu;
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
setCredentials(credentials: ICredentialsResponse[]): void {
|
|
|
|
this.credentials = credentials.reduce((accu: ICredentialMap, cred: ICredentialsResponse) => {
|
|
|
|
if (cred.id) {
|
|
|
|
accu[cred.id] = cred;
|
|
|
|
}
|
|
|
|
return accu;
|
|
|
|
}, {});
|
|
|
|
},
|
2022-11-15 04:25:04 -08:00
|
|
|
addCredentials(credentials: ICredentialsResponse[]): void {
|
|
|
|
credentials.forEach((cred: ICredentialsResponse) => {
|
2022-11-09 01:01:50 -08:00
|
|
|
if (cred.id) {
|
2022-11-15 04:25:04 -08:00
|
|
|
this.credentials[cred.id] = { ...this.credentials[cred.id], ...cred };
|
2022-11-09 01:01:50 -08:00
|
|
|
}
|
2022-11-15 04:25:04 -08:00
|
|
|
});
|
2022-11-09 01:01:50 -08:00
|
|
|
},
|
|
|
|
upsertCredential(credential: ICredentialsResponse): void {
|
|
|
|
if (credential.id) {
|
2023-06-15 05:30:05 -07:00
|
|
|
this.credentials = {
|
|
|
|
...this.credentials,
|
|
|
|
[credential.id]: {
|
|
|
|
...this.credentials[credential.id],
|
|
|
|
...credential,
|
|
|
|
},
|
|
|
|
};
|
2022-11-09 01:01:50 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
enableOAuthCredential(credential: ICredentialsResponse): void {
|
|
|
|
// enable oauth event to track change between modals
|
|
|
|
},
|
|
|
|
async fetchCredentialTypes(forceFetch: boolean): Promise<void> {
|
2023-08-14 05:55:38 -07:00
|
|
|
if (this.allCredentialTypes.length > 0 && !forceFetch) {
|
2022-11-09 01:01:50 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
const rootStore = useRootStore();
|
2022-11-23 07:20:28 -08:00
|
|
|
const credentialTypes = await getCredentialTypes(rootStore.getBaseUrl);
|
2022-11-09 01:01:50 -08:00
|
|
|
this.setCredentialTypes(credentialTypes);
|
|
|
|
},
|
|
|
|
async fetchAllCredentials(): Promise<ICredentialsResponse[]> {
|
|
|
|
const rootStore = useRootStore();
|
|
|
|
const credentials = await getAllCredentials(rootStore.getRestApiContext);
|
|
|
|
this.setCredentials(credentials);
|
|
|
|
return credentials;
|
|
|
|
},
|
|
|
|
async getCredentialData({
|
|
|
|
id,
|
|
|
|
}: {
|
|
|
|
id: string;
|
|
|
|
}): Promise<ICredentialsResponse | ICredentialsDecryptedResponse | undefined> {
|
|
|
|
const rootStore = useRootStore();
|
2023-05-10 08:10:03 -07:00
|
|
|
return getCredentialData(rootStore.getRestApiContext, id);
|
2022-11-09 01:01:50 -08:00
|
|
|
},
|
|
|
|
async createNewCredential(data: ICredentialsDecrypted): Promise<ICredentialsResponse> {
|
|
|
|
const rootStore = useRootStore();
|
|
|
|
const settingsStore = useSettingsStore();
|
|
|
|
const credential = await createNewCredential(rootStore.getRestApiContext, data);
|
|
|
|
|
|
|
|
if (settingsStore.isEnterpriseFeatureEnabled(EnterpriseEditionFeature.Sharing)) {
|
|
|
|
this.upsertCredential(credential);
|
|
|
|
|
|
|
|
if (data.ownedBy) {
|
|
|
|
this.setCredentialOwnedBy({
|
|
|
|
credentialId: credential.id,
|
|
|
|
ownedBy: data.ownedBy,
|
|
|
|
});
|
|
|
|
|
|
|
|
const usersStore = useUsersStore();
|
|
|
|
if (data.sharedWith && data.ownedBy.id === usersStore.currentUserId) {
|
2023-05-10 08:10:03 -07:00
|
|
|
await this.setCredentialSharedWith({
|
2022-11-09 01:01:50 -08:00
|
|
|
credentialId: credential.id,
|
|
|
|
sharedWith: data.sharedWith,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.upsertCredential(credential);
|
|
|
|
}
|
|
|
|
return credential;
|
|
|
|
},
|
|
|
|
async updateCredential(params: {
|
|
|
|
data: ICredentialsDecrypted;
|
|
|
|
id: string;
|
|
|
|
}): Promise<ICredentialsResponse> {
|
|
|
|
const { id, data } = params;
|
|
|
|
const rootStore = useRootStore();
|
|
|
|
const settingsStore = useSettingsStore();
|
|
|
|
const credential = await updateCredential(rootStore.getRestApiContext, id, data);
|
|
|
|
|
|
|
|
if (settingsStore.isEnterpriseFeatureEnabled(EnterpriseEditionFeature.Sharing)) {
|
|
|
|
this.upsertCredential(credential);
|
|
|
|
|
|
|
|
if (data.ownedBy) {
|
|
|
|
this.setCredentialOwnedBy({
|
|
|
|
credentialId: credential.id,
|
|
|
|
ownedBy: data.ownedBy,
|
|
|
|
});
|
|
|
|
|
|
|
|
const usersStore = useUsersStore();
|
|
|
|
if (data.sharedWith && data.ownedBy.id === usersStore.currentUserId) {
|
2023-05-10 08:10:03 -07:00
|
|
|
await this.setCredentialSharedWith({
|
2022-11-09 01:01:50 -08:00
|
|
|
credentialId: credential.id,
|
|
|
|
sharedWith: data.sharedWith,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.upsertCredential(credential);
|
|
|
|
}
|
|
|
|
|
|
|
|
return credential;
|
|
|
|
},
|
2022-11-17 06:22:46 -08:00
|
|
|
async deleteCredential({ id }: { id: string }) {
|
2022-11-09 01:01:50 -08:00
|
|
|
const rootStore = useRootStore();
|
|
|
|
const deleted = await deleteCredential(rootStore.getRestApiContext, id);
|
|
|
|
if (deleted) {
|
2023-06-15 08:27:35 -07:00
|
|
|
const { [id]: deletedCredential, ...rest } = this.credentials;
|
|
|
|
this.credentials = rest;
|
2022-11-09 01:01:50 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
async oAuth2Authorize(data: ICredentialsResponse): Promise<string> {
|
|
|
|
const rootStore = useRootStore();
|
|
|
|
return oAuth2CredentialAuthorize(rootStore.getRestApiContext, data);
|
|
|
|
},
|
|
|
|
async oAuth1Authorize(data: ICredentialsResponse): Promise<string> {
|
|
|
|
const rootStore = useRootStore();
|
|
|
|
return oAuth1CredentialAuthorize(rootStore.getRestApiContext, data);
|
|
|
|
},
|
|
|
|
async testCredential(data: ICredentialsDecrypted): Promise<INodeCredentialTestResult> {
|
|
|
|
const rootStore = useRootStore();
|
|
|
|
return testCredential(rootStore.getRestApiContext, { credentials: data });
|
|
|
|
},
|
|
|
|
async getNewCredentialName(params: { credentialTypeName: string }): Promise<string> {
|
|
|
|
try {
|
|
|
|
const { credentialTypeName } = params;
|
|
|
|
let newName = DEFAULT_CREDENTIAL_NAME;
|
|
|
|
if (!TYPES_WITH_DEFAULT_NAME.includes(credentialTypeName)) {
|
2023-08-14 05:55:38 -07:00
|
|
|
const cred = this.getCredentialTypeByName(credentialTypeName);
|
|
|
|
newName = cred ? getAppNameFromCredType(cred.displayName) : '';
|
2022-11-09 01:01:50 -08:00
|
|
|
newName =
|
|
|
|
newName.length > 0
|
|
|
|
? `${newName} ${DEFAULT_CREDENTIAL_POSTFIX}`
|
|
|
|
: DEFAULT_CREDENTIAL_NAME;
|
|
|
|
}
|
|
|
|
const rootStore = useRootStore();
|
|
|
|
const res = await getCredentialsNewName(rootStore.getRestApiContext, newName);
|
|
|
|
return res.name;
|
|
|
|
} catch (e) {
|
|
|
|
return DEFAULT_CREDENTIAL_NAME;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// Enterprise edition actions
|
2022-11-17 06:22:46 -08:00
|
|
|
setCredentialOwnedBy(payload: { credentialId: string; ownedBy: Partial<IUser> }) {
|
2023-06-15 05:30:05 -07:00
|
|
|
this.credentials[payload.credentialId] = {
|
|
|
|
...this.credentials[payload.credentialId],
|
|
|
|
ownedBy: payload.ownedBy,
|
|
|
|
};
|
2022-11-09 01:01:50 -08:00
|
|
|
},
|
2022-11-17 06:22:46 -08:00
|
|
|
async setCredentialSharedWith(payload: { sharedWith: IUser[]; credentialId: string }) {
|
2022-11-09 01:01:50 -08:00
|
|
|
if (useSettingsStore().isEnterpriseFeatureEnabled(EnterpriseEditionFeature.Sharing)) {
|
|
|
|
await setCredentialSharedWith(useRootStore().getRestApiContext, payload.credentialId, {
|
|
|
|
shareWithIds: payload.sharedWith.map((sharee) => sharee.id),
|
|
|
|
});
|
2023-06-15 05:30:05 -07:00
|
|
|
|
|
|
|
this.credentials[payload.credentialId] = {
|
|
|
|
...this.credentials[payload.credentialId],
|
|
|
|
sharedWith: payload.sharedWith,
|
|
|
|
};
|
2022-11-09 01:01:50 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
addCredentialSharee(payload: { credentialId: string; sharee: Partial<IUser> }): void {
|
2023-06-15 05:30:05 -07:00
|
|
|
this.credentials[payload.credentialId] = {
|
|
|
|
...this.credentials[payload.credentialId],
|
|
|
|
sharedWith: (this.credentials[payload.credentialId].sharedWith || []).concat([
|
|
|
|
payload.sharee,
|
|
|
|
]),
|
|
|
|
};
|
2022-11-09 01:01:50 -08:00
|
|
|
},
|
|
|
|
removeCredentialSharee(payload: { credentialId: string; sharee: Partial<IUser> }): void {
|
2023-06-15 05:30:05 -07:00
|
|
|
this.credentials[payload.credentialId] = {
|
|
|
|
...this.credentials[payload.credentialId],
|
|
|
|
sharedWith: (this.credentials[payload.credentialId].sharedWith || []).filter(
|
2022-11-09 01:01:50 -08:00
|
|
|
(sharee) => sharee.id !== payload.sharee.id,
|
|
|
|
),
|
2023-06-15 05:30:05 -07:00
|
|
|
};
|
2022-11-09 01:01:50 -08:00
|
|
|
},
|
2023-04-24 01:50:49 -07:00
|
|
|
|
|
|
|
async getCredentialTranslation(credentialType: string): Promise<object> {
|
|
|
|
const rootStore = useRootStore();
|
2023-05-10 08:10:03 -07:00
|
|
|
return makeRestApiRequest(rootStore.getRestApiContext, 'GET', '/credential-translation', {
|
|
|
|
credentialType,
|
|
|
|
});
|
2023-04-24 01:50:49 -07:00
|
|
|
},
|
2022-11-09 01:01:50 -08:00
|
|
|
},
|
|
|
|
});
|
2023-11-27 06:30:28 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function for listening to credential changes in the store
|
|
|
|
*/
|
|
|
|
export const listenForCredentialChanges = (opts: {
|
|
|
|
store: CredentialsStore;
|
|
|
|
onCredentialCreated?: (credential: ICredentialsResponse) => void;
|
|
|
|
onCredentialUpdated?: (credential: ICredentialsResponse) => void;
|
|
|
|
onCredentialDeleted?: (credentialId: string) => void;
|
|
|
|
}): void => {
|
|
|
|
const { store, onCredentialCreated, onCredentialDeleted, onCredentialUpdated } = opts;
|
|
|
|
const listeningForActions = ['createNewCredential', 'updateCredential', 'deleteCredential'];
|
|
|
|
|
|
|
|
store.$onAction((result) => {
|
|
|
|
const { name, after, args } = result;
|
|
|
|
after(async (returnValue) => {
|
|
|
|
if (!listeningForActions.includes(name)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (name) {
|
|
|
|
case 'createNewCredential':
|
|
|
|
const createdCredential = returnValue as ICredentialsResponse;
|
|
|
|
onCredentialCreated?.(createdCredential);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'updateCredential':
|
|
|
|
const updatedCredential = returnValue as ICredentialsResponse;
|
|
|
|
onCredentialUpdated?.(updatedCredential);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'deleteCredential':
|
|
|
|
const credentialId = args[0].id;
|
|
|
|
onCredentialDeleted?.(credentialId);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|