mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-14 08:34:07 -08:00
5059c57f4a
* ✨ Added `utils` module. Moved `canvasHelpers` and old `utils.ts` file to it * ✨ Moved rest of utils and helpers * ⚡ Fixing sytax errors * 🔨 Refactoring new utils files * 🔨 Organizing imports, adding comments and a bit more refactoring * ✔️ Fixing tests * 🔨 Moving mixins to `src`
42 lines
1 KiB
TypeScript
42 lines
1 KiB
TypeScript
import { IExternalHooks, IRootState } from '@/Interface';
|
|
import { store } from '@/store';
|
|
import { useWebhooksStore } from '@/stores/webhooks';
|
|
import { IDataObject } from 'n8n-workflow';
|
|
import { Store } from 'pinia';
|
|
import Vue from 'vue';
|
|
|
|
export async function runExternalHook(
|
|
eventName: string,
|
|
store: Store,
|
|
metadata?: IDataObject,
|
|
) {
|
|
// @ts-ignore
|
|
if (!window.n8nExternalHooks) {
|
|
return;
|
|
}
|
|
|
|
const [resource, operator] = eventName.split('.');
|
|
|
|
// @ts-ignore
|
|
if (window.n8nExternalHooks[resource] && window.n8nExternalHooks[resource][operator]) {
|
|
// @ts-ignore
|
|
const hookMethods = window.n8nExternalHooks[resource][operator];
|
|
|
|
for (const hookmethod of hookMethods) {
|
|
await hookmethod(store, metadata);
|
|
}
|
|
}
|
|
}
|
|
|
|
export const externalHooks = Vue.extend({
|
|
methods: {
|
|
$externalHooks(): IExternalHooks {
|
|
return {
|
|
run: async (eventName: string, metadata?: IDataObject): Promise<void> => {
|
|
await runExternalHook.call(this, eventName, useWebhooksStore(), metadata);
|
|
},
|
|
};
|
|
},
|
|
},
|
|
});
|