Add support for custom JS embeds in the App (#16650)

* add embed hook definitions

* inject embeds in the App html

* fixed typo

* removed unnecessary env parameter

* Added comment marking the custom embeds

* attempt to add test for createApp

* mock db in app test

* temporarily set log style to raw in test

* one more round

Co-authored-by: Azri Kahar <42867097+azrikahar@users.noreply.github.com>
This commit is contained in:
Brainslug
2022-12-18 02:14:30 +01:00
committed by GitHub
parent 1df81a0826
commit ca93f5cb1d
6 changed files with 244 additions and 3 deletions

View File

@@ -16,3 +16,4 @@ export type FilterHandler<T = unknown> = (
export type ActionHandler = (meta: Record<string, any>, context: EventContext) => void;
export type InitHandler = (meta: Record<string, any>) => void;
export type ScheduleHandler = () => void | Promise<void>;
export type EmbedHandler = () => string;

View File

@@ -1,4 +1,4 @@
import { ActionHandler, FilterHandler, InitHandler, ScheduleHandler } from './events';
import { ActionHandler, FilterHandler, InitHandler, ScheduleHandler, EmbedHandler } from './events';
import { ApiExtensionContext } from './extensions';
type HookExtensionContext = ApiExtensionContext & {
@@ -10,6 +10,7 @@ type RegisterFunctions = {
action: (event: string, handler: ActionHandler) => void;
init: (event: string, handler: InitHandler) => void;
schedule: (cron: string, handler: ScheduleHandler) => void;
embed: (position: 'head' | 'body', code: string | EmbedHandler) => void;
};
type HookConfigFunction = (register: RegisterFunctions, context: HookExtensionContext) => void;