UNPKG

@novu/framework

Version:

The Code-First Notifications Workflow SDK.

429 lines (403 loc) 18.3 kB
import { P as PostActionEnum } from '../health-check.types-C4vZDz5x.js'; export { b as CancelEventTriggerResponse, c as ChannelPreference, C as ClientOptions, d as CodeResult, a as CronExpression, D as DiscoverOutput, e as DiscoverProviderOutput, f as DiscoverStepOutput, g as DiscoverWorkflowOutput, h as Event, i as EventTriggerParams, j as EventTriggerResponse, k as EventTriggerResult, l as Execute, E as ExecuteInput, m as ExecuteOutput, n as ExecuteOutputMetadata, o as ExecuteOutputOptions, G as GetActionEnum, H as HealthCheck, S as SeverityLevelEnum, p as State, q as StepType, W as Workflow, r as WorkflowChannelEnum, s as WorkflowOptions, t as WorkflowPreference, u as WorkflowPreferences } from '../health-check.types-C4vZDz5x.js'; export { h as ActionStep, A as ActionStepEnum, f as Awaitable, i as ChannelStep, e as ChannelStepEnum, j as ChatOutput, k as ChatOutputUnvalidated, l as ChatResult, b as ConditionalPartial, a as ContextPayload, C as ContextResolved, m as ContextValue, n as CustomStep, D as DeepPartial, o as DeepRequired, q as DelayDynamicOutput, r as DelayDynamicOutputUnvalidated, s as DelayOutput, t as DelayOutputUnvalidated, u as DelayRegularOutput, v as DelayRegularOutputUnvalidated, w as DelayResult, x as DelayTimedOutput, y as DelayTimedOutputUnvalidated, z as DigestOutput, B as DigestOutputUnvalidated, F as DigestRegularOutput, G as DigestRegularOutputUnvalidated, H as DigestResult, I as DigestTimedOutput, J as DigestTimedOutputUnvalidated, E as Either, K as EmailOutput, L as EmailOutputUnvalidated, M as EmailResult, N as InAppOutput, O as InAppOutputUnvalidated, Q as InAppResult, R as Indexable, T as JobStatusEnum, U as PickOptional, V as PickOptionalKeys, X as PickRequired, P as PickRequiredKeys, d as Prettify, Y as PushOutput, Z as PushOutputUnvalidated, _ as PushResult, $ as Skip, a0 as SmsOutput, a1 as SmsOutputUnvalidated, a2 as SmsResult, c as Step, a3 as StepContext, g as StepOptions, a4 as StepOutput, S as Subscriber, a5 as ThrottleOutput, a6 as ThrottleOutputUnvalidated, a7 as ThrottleResult, a8 as actionStepSchemas, a9 as channelStepSchemas } from '../subscriber.types-CfRj4acH.js'; import { Filter, LiquidOptions, Liquid } from 'liquidjs'; export { a as FromSchema, F as FromSchemaUnvalidated, J as JsonSchema, S as Schema, Z as ZodSchema, b as ZodSchemaMinimal } from '../base.schema.types-BApIn9jr.js'; export { S as SupportedFrameworkName } from '../server.types-BRWsA1CA.js'; export { a as ValidateFunction, V as ValidateResult, b as ValidationError, c as Validator } from '../validator.types-BIQli_m1.js'; import 'json-schema-to-ts'; import 'zod'; import 'ajv'; declare enum NovuApiEndpointsEnum { SYNC = "/v1/bridge/sync", DIFF = "/v1/bridge/diff" } declare const SIGNATURE_TIMESTAMP_TOLERANCE_MINUTES = 5; declare const SIGNATURE_TIMESTAMP_TOLERANCE: number; declare enum ErrorCodeEnum { BRIDGE_ERROR = "BridgeError", EXECUTION_EVENT_CONTROL_INVALID_ERROR = "ExecutionEventControlInvalidError", EXECUTION_EVENT_PAYLOAD_INVALID_ERROR = "ExecutionEventPayloadInvalidError", EXECUTION_PROVIDER_OUTPUT_INVALID_ERROR = "ExecutionProviderOutputInvalidError", EXECUTION_STATE_CONTROL_INVALID_ERROR = "ExecutionStateControlInvalidError", EXECUTION_STATE_CORRUPT_ERROR = "ExecutionStateCorruptError", EXECUTION_STATE_OUTPUT_INVALID_ERROR = "ExecutionStateOutputInvalidError", EXECUTION_STATE_RESULT_INVALID_ERROR = "ExecutionStateResultInvalidError", INVALID_ACTION_ERROR = "InvalidActionError", METHOD_NOT_ALLOWED_ERROR = "MethodNotAllowedError", MISSING_DEPENDENCY_ERROR = "MissingDependencyError", MISSING_SECRET_KEY_ERROR = "MissingSecretKeyError", PROVIDER_EXECUTION_FAILED_ERROR = "ProviderExecutionFailedError", PROVIDER_NOT_FOUND_ERROR = "ProviderNotFoundError", SIGNATURE_EXPIRED_ERROR = "SignatureExpiredError", SIGNATURE_INVALID_ERROR = "SignatureInvalidError", SIGNATURE_MISMATCH_ERROR = "SignatureMismatchError", SIGNATURE_NOT_FOUND_ERROR = "SignatureNotFoundError", SIGNATURE_VERSION_INVALID_ERROR = "SignatureVersionInvalidError", SIGNING_KEY_NOT_FOUND_ERROR = "SigningKeyNotFoundError", STEP_ALREADY_EXISTS_ERROR = "StepAlreadyExistsError", STEP_CONTROL_COMPILATION_FAILED_ERROR = "StepControlCompilationFailedError", STEP_EXECUTION_FAILED_ERROR = "StepExecutionFailedError", STEP_NOT_FOUND_ERROR = "StepNotFoundError", WORKFLOW_ALREADY_EXISTS_ERROR = "WorkflowAlreadyExistsError", WORKFLOW_NOT_FOUND_ERROR = "WorkflowNotFoundError", WORKFLOW_PAYLOAD_INVALID_ERROR = "WorkflowPayloadInvalidError" } declare enum HttpHeaderKeysEnum { NOVU_SIGNATURE = "novu-signature", NOVU_ANONYMOUS = "novu-anonymous", NOVU_FRAMEWORK_SDK = "novu-framework-sdk", NOVU_FRAMEWORK_SERVER = "novu-framework-server", NOVU_FRAMEWORK_VERSION = "novu-framework-version", USER_AGENT = "user-agent", CONTENT_TYPE = "content-type", ACCESS_CONTROL_ALLOW_ORIGIN = "access-control-allow-origin", ACCESS_CONTROL_ALLOW_METHODS = "access-control-allow-methods", ACCESS_CONTROL_ALLOW_HEADERS = "access-control-allow-headers", ACCESS_CONTROL_MAX_AGE = "access-control-max-age", ACCESS_CONTROL_ALLOW_PRIVATE_NETWORK = "access-control-allow-private-network" } declare enum HttpMethodEnum { POST = "POST", GET = "GET", OPTIONS = "OPTIONS" } declare enum HttpQueryKeysEnum { WORKFLOW_ID = "workflowId", STEP_ID = "stepId", ACTION = "action", SOURCE = "source" } declare enum HttpStatusEnum { CONTINUE = 100, SWITCHING_PROTOCOLS = 101, PROCESSING = 102, EARLYHINTS = 103, OK = 200, CREATED = 201, ACCEPTED = 202, NON_AUTHORITATIVE_INFORMATION = 203, NO_CONTENT = 204, RESET_CONTENT = 205, PARTIAL_CONTENT = 206, AMBIGUOUS = 300, MOVED_PERMANENTLY = 301, FOUND = 302, SEE_OTHER = 303, NOT_MODIFIED = 304, TEMPORARY_REDIRECT = 307, PERMANENT_REDIRECT = 308, BAD_REQUEST = 400, UNAUTHORIZED = 401, PAYMENT_REQUIRED = 402, FORBIDDEN = 403, NOT_FOUND = 404, METHOD_NOT_ALLOWED = 405, NOT_ACCEPTABLE = 406, PROXY_AUTHENTICATION_REQUIRED = 407, REQUEST_TIMEOUT = 408, CONFLICT = 409, GONE = 410, LENGTH_REQUIRED = 411, PRECONDITION_FAILED = 412, PAYLOAD_TOO_LARGE = 413, URI_TOO_LONG = 414, UNSUPPORTED_MEDIA_TYPE = 415, REQUESTED_RANGE_NOT_SATISFIABLE = 416, EXPECTATION_FAILED = 417, I_AM_A_TEAPOT = 418, MISDIRECTED = 421, UNPROCESSABLE_ENTITY = 422, FAILED_DEPENDENCY = 424, PRECONDITION_REQUIRED = 428, TOO_MANY_REQUESTS = 429, INTERNAL_SERVER_ERROR = 500, NOT_IMPLEMENTED = 501, BAD_GATEWAY = 502, SERVICE_UNAVAILABLE = 503, GATEWAY_TIMEOUT = 504, HTTP_VERSION_NOT_SUPPORTED = 505 } declare enum ResourceEnum { WORKFLOW = "workflow", PROVIDER = "provider", STEP = "step" } /** * Check if the object is a native error. * * This method relies on `Object.prototype.toString()` behavior. It is possible to obtain * an incorrect result when the object argument has a non `Error`-suffixed `name` property. * * @param object - The object to check. * @returns `true` if the object is a native error, `false` otherwise. */ declare const isNativeError: (object: unknown) => object is Error; /** * Base error class. */ declare abstract class FrameworkError extends Error { /** * HTTP status code. */ abstract readonly statusCode: HttpStatusEnum; /** * Additional data that can be used to provide more information about the error. */ data?: unknown; /** * The error code, which is used to identify the error type. */ abstract readonly code: ErrorCodeEnum; } declare abstract class NotFoundError extends FrameworkError { statusCode: HttpStatusEnum; } declare abstract class BadRequestError extends FrameworkError { statusCode: HttpStatusEnum; } declare abstract class UnauthorizedError extends FrameworkError { statusCode: HttpStatusEnum; } declare abstract class ServerError extends FrameworkError { data: { /** * The stack trace of the error. */ stack: string; }; constructor(message: string, { cause }?: Partial<{ cause: unknown; }>); } declare abstract class ConflictError extends FrameworkError { statusCode: HttpStatusEnum; } declare abstract class ForbiddenError extends FrameworkError { statusCode: HttpStatusEnum; } /** * A `BridgeError` is an unexpected error that occurs within the Bridge application. * * This error is used to wrap unknown errors that occur within the Bridge application, * such as errors due to unsupported runtime environments. */ declare class BridgeError extends ServerError { statusCode: HttpStatusEnum; code: ErrorCodeEnum; constructor(cause: unknown); } declare class ExecutionStateCorruptError extends BadRequestError { code: ErrorCodeEnum; constructor(workflowId: string, stepId: string); } declare class ExecutionEventPayloadInvalidError extends BadRequestError { code: ErrorCodeEnum; constructor(workflowId: string, data: unknown); } declare class ExecutionEventControlsInvalidError extends BadRequestError { code: ErrorCodeEnum; constructor(workflowId: string, data: unknown); } declare class ExecutionStateControlsInvalidError extends BadRequestError { code: ErrorCodeEnum; constructor(workflowId: string, stepId: string, data: unknown); } declare class ExecutionStateOutputInvalidError extends BadRequestError { code: ErrorCodeEnum; constructor(workflowId: string, stepId: string, data: unknown); } declare class ExecutionStateResultInvalidError extends BadRequestError { code: ErrorCodeEnum; constructor(workflowId: string, stepId: string, data: unknown); } declare class StepControlCompilationFailedError extends BadRequestError { code: ErrorCodeEnum; constructor(workflowId: string, stepId: string, data: unknown); } declare class ExecutionProviderOutputInvalidError extends BadRequestError { code: ErrorCodeEnum; constructor(workflowId: string, stepId: string, providerId: string, data: unknown); } declare class WorkflowPayloadInvalidError extends BadRequestError { code: ErrorCodeEnum; constructor(workflowId: string, data: unknown); } declare class PlatformError extends Error { /** * HTTP status code. */ statusCode: HttpStatusEnum; /** * Additional data that can be used to provide more information about the error. */ data: unknown; code: ErrorCodeEnum; constructor(statusCode: HttpStatusEnum, code: string, message: string); } /** * Check if the error is a `FrameworkError`. * * A `FrameworkError` is an error thrown by the Framework. * * @param error - The error to check. * @returns `true` if the error is a `FrameworkError`, `false` otherwise. */ declare const isFrameworkError: (error: unknown) => error is FrameworkError; declare class MethodNotAllowedError extends FrameworkError { code: ErrorCodeEnum; statusCode: HttpStatusEnum; message: string; } declare class InvalidActionError extends BadRequestError { code: ErrorCodeEnum; constructor(action: string, allowedActions: Object); } declare class MissingSecretKeyError extends BadRequestError { code: ErrorCodeEnum; constructor(); } declare abstract class ResourceConflictError extends ConflictError { constructor(resource: ResourceEnum, id: string); } declare abstract class ResourceNotFoundError extends NotFoundError { constructor(resource: ResourceEnum, id: string); } declare abstract class ResourceExecutionFailed extends ServerError { statusCode: HttpStatusEnum; constructor(resource: ResourceEnum, id: string, action: PostActionEnum, cause: unknown); } declare class ProviderNotFoundError extends ResourceNotFoundError { code: ErrorCodeEnum; constructor(id: string); } declare class ProviderExecutionFailedError extends ResourceExecutionFailed { code: ErrorCodeEnum; constructor(id: string, action: PostActionEnum, cause: unknown); } declare class SignatureMismatchError extends UnauthorizedError { code: ErrorCodeEnum; constructor(); } declare class SignatureNotFoundError extends UnauthorizedError { code: ErrorCodeEnum; constructor(); } declare class SignatureInvalidError extends UnauthorizedError { code: ErrorCodeEnum; constructor(); } declare class SignatureExpiredError extends UnauthorizedError { code: ErrorCodeEnum; constructor(); } declare class SigningKeyNotFoundError extends UnauthorizedError { code: ErrorCodeEnum; constructor(); } declare class SignatureVersionInvalidError extends UnauthorizedError { code: ErrorCodeEnum; constructor(); } declare class StepNotFoundError extends ResourceNotFoundError { code: ErrorCodeEnum; constructor(id: string); } declare class StepAlreadyExistsError extends ResourceConflictError { code: ErrorCodeEnum; constructor(id: string); } declare class StepExecutionFailedError extends ResourceExecutionFailed { code: ErrorCodeEnum; constructor(id: string, action: PostActionEnum, cause: unknown); } declare class WorkflowNotFoundError extends ResourceNotFoundError { code: ErrorCodeEnum; constructor(id: string); } declare class WorkflowAlreadyExistsError extends ResourceConflictError { code: ErrorCodeEnum; constructor(id: string); } /** * Format a list of items for digest notifications with configurable behavior * Default formatting: * - 1 item: "John" * - 2 items: "John and Josh" * - 3 items: "John, Josh and Sarah" * - 4+ items: "John, Josh and 2 others" * * @param array The array of items to format * @param maxNames Maximum names to show before using "others" * @param keyPath Path to extract from objects (e.g., "name" or "profile.name") * @param separator Custom separator between names (default: ", ") * @returns Formatted string * * Examples: * {{ actors | digest }} => "John, Josh and 2 others" * {{ actors | digest: 2 }} => "John, Josh and 3 others" * {{ users | digest: 2, "name" }} => For array of {name: string} * {{ users | digest: 2, "profile.name", "•" }} => "John • Josh and 3 others" */ declare function digest(array: unknown, maxNames?: number, keyPath?: string, separator?: string): string; /** * Creates a pluralized string based on the count of the item. * Example: * - 0, "event" -> "" * - 1, "event" -> 1 event * - 2, "event" -> 2 events * - 1, "event", "", false -> event * - 2, "event", "", false -> events * * @param item The item to pluralize * @param singular The singular form of the word * @param plural The plural form of the word * @param showCount Whether to include the count in the output (default: true) */ declare function pluralize(item: unknown, singular?: string, plural?: string, showCount?: 'true' | 'false'): string; type LiquidFilterIssue = { message: string; begin: number; end: number; value: string; }; /** * Format a list of items for digest notifications with configurable behavior * Default formatting: * - 1 item: "John" * - 2 items: "John and Josh" * - 3 items: "John, Josh, and Sarah" * - 4+ items: "John, Josh, and 2 others" * * @param array The array of items to format * @param keyPath Path to the property to extract from objects (e.g., "name" or "profile.name") * @param limit Maximum number of words to show before the "overflowSuffix" * @param overflowSuffix The word to use for the items above the limit, e.g. "other" * @param wordsConnector The separator between words (default: ", ") * @param twoWordsConnector The separator for 2 words (default: " and ") * @param lastWordConnector The separator for 3+ words (default: ", and ") * @returns Formatted string, for example: "John, Josh and 2 others" */ declare function toSentence(array: unknown, keyPath?: string, limit?: number, overflowSuffix?: string, wordsConnector?: string, twoWordsConnector?: string, lastWordConnector?: string): string; /** * Validate the arguments for the toSentence filter * @param options Options for validation. Can include requireKeyPath to make keyPath required. * @param args The arguments for the toSentence filter * @returns An array of issues with the validation errors */ declare function toSentenceArgsValidator(options?: { requireKeyPath?: boolean; }, ...args: Filter['args']): LiquidFilterIssue[]; type FilterValidators = { [key: string]: (...args: any[]) => LiquidFilterIssue[]; }; declare const FILTER_VALIDATORS: FilterValidators; /** * Creates a configured Liquid instance with Novu's default settings. * * @param options - LiquidJS options. Note: By default, this uses a custom outputEscape function * that escapes special JSON characters. If you need different escaping behavior (e.g., for HTML * rendering), you can override the outputEscape function in the options. */ declare function createLiquidEngine(options?: LiquidOptions): Liquid; export { BadRequestError, BridgeError, ConflictError, ErrorCodeEnum, ExecutionEventControlsInvalidError, ExecutionEventPayloadInvalidError, ExecutionProviderOutputInvalidError, ExecutionStateControlsInvalidError, ExecutionStateCorruptError, ExecutionStateOutputInvalidError, ExecutionStateResultInvalidError, FILTER_VALIDATORS, ForbiddenError, FrameworkError, HttpHeaderKeysEnum, HttpMethodEnum, HttpQueryKeysEnum, HttpStatusEnum, InvalidActionError, type LiquidFilterIssue, MethodNotAllowedError, MissingSecretKeyError, NotFoundError, NovuApiEndpointsEnum, PlatformError, PostActionEnum, ProviderExecutionFailedError, ProviderNotFoundError, ResourceConflictError, ResourceEnum, ResourceExecutionFailed, ResourceNotFoundError, SIGNATURE_TIMESTAMP_TOLERANCE, SIGNATURE_TIMESTAMP_TOLERANCE_MINUTES, ServerError, SignatureExpiredError, SignatureInvalidError, SignatureMismatchError, SignatureNotFoundError, SignatureVersionInvalidError, SigningKeyNotFoundError, StepAlreadyExistsError, StepControlCompilationFailedError, StepExecutionFailedError, StepNotFoundError, UnauthorizedError, WorkflowAlreadyExistsError, WorkflowNotFoundError, WorkflowPayloadInvalidError, createLiquidEngine, digest, isFrameworkError, isNativeError, pluralize, toSentence, toSentenceArgsValidator };