mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-13 16:14:07 -08:00
5ca2148c7e
* ⚡ Adjust `format` script * 🔥 Remove exemption for `editor-ui` * 🎨 Prettify * 👕 Fix lint
43 lines
1 KiB
TypeScript
43 lines
1 KiB
TypeScript
import { IExternalHooks } from '@/Interface';
|
|
import { useWebhooksStore } from '@/stores/webhooks';
|
|
import { IDataObject } from 'n8n-workflow';
|
|
import { Store } from 'pinia';
|
|
import Vue from 'vue';
|
|
|
|
declare global {
|
|
interface Window {
|
|
n8nExternalHooks?: Record<
|
|
string,
|
|
Record<string, Array<(store: Store, metadata?: IDataObject) => Promise<void>>>
|
|
>;
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
|
|
export const externalHooks = Vue.extend({
|
|
methods: {
|
|
$externalHooks(): IExternalHooks {
|
|
return {
|
|
run: async (eventName: string, metadata?: IDataObject): Promise<void> => {
|
|
await runExternalHook.call(this, eventName, useWebhooksStore(), metadata);
|
|
},
|
|
};
|
|
},
|
|
},
|
|
});
|