n8n/packages/editor-ui/src/utils/externalHooks.ts
Alex Grozav 9c94050deb
feat: Replace Vue.extend with defineComponent in editor-ui (no-changelog) (#6033)
* refactor: replace Vue.extend with defineComponent in editor-ui

* fix: change $externalHooks extractions from mixins

* fix: refactor externalHooks mixin
2023-04-21 18:51:08 +03:00

19 lines
494 B
TypeScript

import type { IDataObject } from 'n8n-workflow';
import type { Store } from 'pinia';
export async function runExternalHook(eventName: string, store: Store, metadata?: IDataObject) {
if (!window.n8nExternalHooks) {
return;
}
const [resource, operator] = eventName.split('.');
if (window.n8nExternalHooks[resource]?.[operator]) {
const hookMethods = window.n8nExternalHooks[resource][operator];
for (const hookMethod of hookMethods) {
await hookMethod(store, metadata);
}
}
}