feat: Rewrite Front End cloud and posthog hooks using TypeScript (no-changelog) (#5491)

This commit is contained in:
Alex Grozav
2023-11-13 15:10:42 +02:00
committed by GitHub
parent 3dfabc37d8
commit a262c450f7
41 changed files with 1439 additions and 131 deletions

View File

@@ -1,16 +1,36 @@
import type { IExternalHooks } from '@/Interface';
import type { IDataObject } from 'n8n-workflow';
import { useWebhooksStore } from '@/stores/webhooks.store';
import type { PartialDeep } from 'type-fest';
import type { ExternalHooks, ExternalHooksGenericContext } from '@/types';
import { defineComponent } from 'vue';
import { runExternalHook } from '@/utils';
export function extendExternalHooks(hooksExtension: PartialDeep<ExternalHooks>) {
if (typeof window.n8nExternalHooks === 'undefined') {
window.n8nExternalHooks = {};
}
for (const resource of Object.keys(hooksExtension) as Array<keyof ExternalHooks>) {
if (typeof window.n8nExternalHooks[resource] === 'undefined') {
window.n8nExternalHooks[resource] = {};
}
const extensionContext = hooksExtension[resource] as ExternalHooksGenericContext;
const context = window.n8nExternalHooks[resource] as ExternalHooksGenericContext;
for (const operator of Object.keys(extensionContext)) {
if (typeof context[operator] === 'undefined') {
context[operator] = [];
}
context[operator].push(...extensionContext[operator]);
}
}
}
export const externalHooks = defineComponent({
methods: {
$externalHooks(): IExternalHooks {
return {
run: async (eventName: string, metadata?: IDataObject): Promise<void> => {
await runExternalHook.call(this, eventName, useWebhooksStore(), metadata);
},
run: runExternalHook,
};
},
},