API Reference

Complete API documentation for @seanblock/form-builder components, hooks, and types.

FormBuilderV3

Main component for rendering forms.

Props

PropTypeRequiredDescription
configFormConfig✅ YesForm configuration object
contextDynamicContext✅ YesInitial context/data
additionalBlocksRecord<string, BlockComponent>NoCustom block components
secretContextSecretContextNo🔒 Encrypted secrets (tokens, passwords)
encryptionKeystringNo🔒 Key for decrypting secretContext
customFunctionsRecord<string, CustomFunction>NoCustom function implementations
showDebugbooleanNoShow debug panel
enableClientEncryptionbooleanNo🔒 Enable client-side encryption (default: true)
auditLoggingAuditLoggerNo🔒 Custom audit logger for security events

Usage

import FormBuilderV3, { encryptValue } from '@seanblock/form-builder';

// Basic usage
<FormBuilderV3 
  config={formConfig} 
  context={initialContext}
  additionalBlocks={customBlocks}
  showDebug={true}
/>

// With encrypted secrets (recommended for production)
const encryptionKey = process.env.FORM_ENCRYPTION_KEY!;
const secretContext = {
  apiToken: encryptValue('your-token', encryptionKey),
  apiKey: encryptValue('your-key', encryptionKey),
};

<FormBuilderV3 
  config={formConfig} 
  context={initialContext}
  secretContext={secretContext}
  encryptionKey={encryptionKey}
  additionalBlocks={customBlocks}
  customFunctions={customFunctions}
/>

useFormBuilder Hook

Access form state and methods in custom blocks.

Return Value

PropertyTypeDescription
contextDynamicContextCurrent form data
updateContextValue(path, value) => voidUpdate form data at path
executeAction(action) => Promise<void>Execute single action
executeActions(actions[]) => Promise<void>Execute multiple actions
currentPagestringCurrent page ID
setCurrentPage(pageId) => voidNavigate to page
invalidListstring[]List of invalid field IDs
errorsError[]General errors
isLoadingbooleanAPI loading state
configFormConfigForm configuration
importedBlocksRecord<string, Component>Registered blocks

Usage

import { useFormBuilder } from '@seanblock/form-builder';

function CustomBlock() {
  const {
    context,
    updateContextValue,
    executeActions,
    currentPage,
    isLoading
  } = useFormBuilder();

  // Use the hook values...
}

Types

FormConfig

interface FormConfig {
  id: string;
  type: "form";
  metadata?: {
    formName?: string;
    [key: string]: any;
  };
  initialPage: string;
  context: DynamicContext;
  services?: Record<string, ServiceDefinition>;
  blocks?: Block[];
  pages: Record<string, Block>;
}

Block

interface Block {
  id: string;
  blockType: string;
  className?: string;
  style?: React.CSSProperties;
  metadata?: Record<string, any>;
  displayConditions?: Condition[];
  blocks?: Block[];
  actions?: Action[];
  validations?: ValidateRule[];
}

Action Types

type Action =
  | { type: "goToPage"; target: string }
  | { type: "callApi"; service: string; then?: Action[]; else?: Action[] }
  | { type: "assignContext"; assign: Record<string, any> }
  | { type: "assignSecret"; assign: Record<string, any>; encrypt?: boolean } // 🔒 New
  | { type: "validate"; targets: string[] }
  | { type: "validateCurrentPage"; then?: Action[]; else?: Action[] }
  | { type: "conditional"; conditions: Condition[]; then: Action[]; else?: Action[] }
  | { type: "toast"; message: string; variant?: string };

🔒 New in v0.1.1: The assignSecret action allows you to update encrypted secrets. Set encrypt: true to automatically encrypt values before storing.

Validation Rules

interface ValidateRule {
  rule: "charMinLength" | "charMaxLength" | "exact" | "pattern" | "isValid";
  value?: any;
  message: string;
}

Available Standard Blocks

Block TypeCategoryDescription
PageBlockLayoutPage container
PageHeaderBlockLayoutPage header
PageContentBlockLayoutPage content
PageFooterBlockLayoutPage footer
CardBlockLayoutContent card
RowBlockLayoutHorizontal layout
SidebarBlockLayoutSidebar container
HeaderBlockContentHeading text
ParagraphBlockContentParagraph text
LinkBlockContentHyperlink
ButtonBlockActionButton with actions