@novu/framework
Version:
The Code-First Notifications Workflow SDK.
137 lines (132 loc) • 5.51 kB
TypeScript
import { h as ClientOptions, W as Workflow, H as HealthCheck, o as DiscoverOutput, u as Event, y as ExecuteOutput, g as CodeResult, r as EventTriggerParams, as as Awaitable, a as Schema, b as FromSchema, F as FromSchemaUnvalidated, aD as Execute, aH as WorkflowOptions } from './health-check.types-D_KcRiM_.js';
declare class Client {
private discoveredWorkflows;
private discoverWorkflowPromises;
private templateEngine;
secretKey: string;
apiUrl: string;
version: string;
strictAuthentication: boolean;
constructor(options?: ClientOptions);
private buildOptions;
/**
* Adds workflows to the client.
*
* A locking mechanism is used to ensure that duplicate workflows are not added.
*
* @param workflows - The workflows to add.
*/
addWorkflows(workflows: Array<Workflow>): Promise<void>;
private addWorkflow;
healthCheck(): HealthCheck;
private getWorkflow;
private getStep;
private getRegisteredWorkflows;
discover(): DiscoverOutput;
/**
* Mocks data based on the given schema.
* The `default` value in the schema is used as the base data.
* If no `default` value is provided, the data is generated using JSONSchemaFaker.
*
* @param schema
* @returns mocked data
*/
private mock;
private validate;
private throwInvalidProvider;
private throwInvalidStep;
private throwInvalidEvent;
private executeStepFactory;
private shouldSanitize;
private shouldSkip;
executeWorkflow(event: Event): Promise<ExecuteOutput>;
private createExecutionPayload;
private prettyPrintExecute;
private executeProviders;
private previewProvider;
private executeProvider;
private executeStep;
private compileControls;
/**
* Preprocesses standalone translation patterns.
* Transforms {{t.key}} to [T:key] placeholder (not Liquid syntax, passes through unchanged).
*/
private preprocessTranslationPatterns;
/**
* Preprocesses translation keys used as filter arguments.
* Transforms 't.key' to '[T:key]' placeholder (not Liquid syntax, passes through unchanged).
* Example: pluralize: 't.apple', 't.apples' → pluralize: '[T:apple]', '[T:apples]'
*/
private preprocessFilterTranslationArgs;
/**
* Post-processes placeholders back to translation markers after Liquid render.
* Transforms [T:key] back to {{t.key}} for the translation service.
*/
private postprocessTranslationMarkers;
/**
* Create the controls for a step, taking both the event controls and the default controls into account
*
* @param step The step to create the controls for
* @param event The event that triggered the step
* @returns The controls for the step
*/
private createStepControls;
private previewStep;
private constructStepForPreview;
private extractMockDataForPreviousSteps;
private previewRequiredStep;
private getStepState;
private getStepCode;
private getWorkflowCode;
getCode(workflowId: string, stepId?: string): CodeResult;
}
type ServeHandlerOptions = {
client?: Client;
workflows: Array<Workflow>;
};
type INovuRequestHandlerOptions<Input extends any[] = any[], Output = any> = ServeHandlerOptions & {
frameworkName: string;
client?: Client;
workflows: Array<Workflow>;
handler: Handler<Input, Output>;
};
type Handler<Input extends any[] = any[], Output = any> = (...args: Input) => HandlerResponse<Output>;
type HandlerResponse<Output = any> = {
body: () => Awaitable<any>;
headers: (key: string) => Awaitable<string | null | undefined>;
method: () => Awaitable<string>;
queryString?: (key: string, url: URL) => Awaitable<string | null | undefined>;
url: () => Awaitable<URL>;
transformResponse: (res: IActionResponse<string>) => Output;
};
type IActionResponse<TBody extends string = string> = {
status: number;
headers: Record<string, string>;
body: TBody;
};
declare class NovuRequestHandler<Input extends any[] = any[], Output = any> {
readonly frameworkName: string;
readonly handler: Handler<Input, Output>;
readonly client: Client;
private readonly hmacEnabled;
private readonly http;
private readonly workflows;
constructor(options: INovuRequestHandlerOptions<Input, Output>);
createHandler(): (...args: Input) => Promise<Output>;
private getStaticHeaders;
private createResponse;
private createError;
private handleAction;
private getPostActionMap;
triggerAction(triggerEvent: EventTriggerParams): () => Promise<IActionResponse<string>>;
private getGetActionMap;
private handlePostAction;
private handleGetAction;
private handleError;
private validateHmac;
}
/**
* Define a new notification workflow.
*/
declare function workflow<T_PayloadSchema extends Schema, T_ControlSchema extends Schema, T_PayloadValidated extends Record<string, unknown> = FromSchema<T_PayloadSchema>, T_PayloadUnvalidated extends Record<string, unknown> = FromSchemaUnvalidated<T_PayloadSchema>, T_Controls extends Record<string, unknown> = FromSchema<T_ControlSchema>>(workflowId: string, execute: Execute<T_PayloadValidated, T_Controls>, workflowOptions?: WorkflowOptions<T_PayloadSchema, T_ControlSchema>): Workflow<T_PayloadUnvalidated>;
export { Client as C, type INovuRequestHandlerOptions as I, NovuRequestHandler as N, type ServeHandlerOptions as S, workflow as w };