npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

masumi-schema-validator-component

v1.2.0

Published

Job Input Schema Validator and Form Renderer for Masumi

Readme

Masumi Schema Validator Component

A React component library for validating and previewing job input schemas for the Masumi platform. This component provides a playground interface where you can write, validate, and preview how input schemas will render as forms.

Features

  • Schema Validation: Real-time validation of JSON schemas against the Masumi Job Input Schema specification
  • 🎨 Live Preview: See how your schema renders as a form in real-time
  • 📝 Monaco Editor: Syntax-highlighted JSON editor with error detection
  • 🔍 Detailed Error Messages: Clear validation errors with line numbers and helpful suggestions
  • 🌓 Dark Mode Support: Automatic theme detection and support
  • 📦 TypeScript: Fully typed with TypeScript definitions
  • 🎯 Multiple Schema Formats: Supports wrapped format, array format, and single schema format

Installation

npm install masumi-schema-validator-component

Peer Dependencies

This package requires the following peer dependencies:

  • react >= 18
  • react-dom >= 18
  • tailwindcss >= 3

Quick Start

import { SchemaPlayground } from 'masumi-schema-validator-component';

function App() {
  const examples = [
    {
      label: 'Simple Form',
      value: JSON.stringify([
        {
          id: 'name',
          type: 'text',
          name: 'Full Name',
          data: {
            placeholder: 'Enter your name'
          }
        }
      ])
    }
  ];

  return (
    <SchemaPlayground
      initialSchema="[]"
      examples={examples}
      onSchemaChange={(schema, isValid) => {
        console.log('Schema changed:', schema, 'Valid:', isValid);
      }}
    />
  );
}

Components

SchemaPlayground

The main component that provides a split-pane interface with a schema editor on the left and form preview on the right.

Props

interface SchemaPlaygroundProps {
  initialSchema?: string;           // Initial JSON schema string (default: '[]')
  examples?: Array<{                 // Array of example schemas to load
    label: string;
    value: string;
  }>;
  className?: string;               // Additional CSS classes
  onSchemaChange?: (                // Callback when schema changes
    schema: string,
    isValid: boolean
  ) => void;
}

Example

<SchemaPlayground
  initialSchema={mySchema}
  examples={[
    { label: 'Example 1', value: '[...]' },
    { label: 'Example 2', value: '[...]' }
  ]}
  onSchemaChange={(schema, isValid) => {
    if (isValid) {
      // Save valid schema
    }
  }}
/>

JobInputsFormRenderer

Renders a form based on validated job input schemas. This component is used internally by SchemaPlayground but can also be used standalone.

Props

interface JobInputsFormRendererProps {
  jobInputSchemas: JobInputSchemaType[];
  onFormDataChange?: (
    formData: Record<string, string | number | boolean | number[] | null>
  ) => void;
  disabled?: boolean;
  className?: string;
}

Example

import { JobInputsFormRenderer } from 'masumi-schema-validator-component';

<JobInputsFormRenderer
  jobInputSchemas={validatedSchemas}
  onFormDataChange={(data) => {
    console.log('Form data:', data);
  }}
/>

Schema Format

The component validates schemas according to the Masumi Job Input Schema specification. Schemas can be provided in three formats:

1. Wrapped Format

{
  "input_data": [
    {
      "id": "field1",
      "type": "text",
      "name": "Field 1"
    }
  ]
}

2. Array Format

[
  {
    "id": "field1",
    "type": "text",
    "name": "Field 1"
  }
]

3. Single Schema Format

{
  "id": "field1",
  "type": "text",
  "name": "Field 1"
}

Supported Input Types

  • text - Single-line text input
  • textarea - Multi-line text input
  • number - Number input
  • email - Email input with validation
  • password - Password input
  • tel - Telephone number input
  • url - URL input
  • date - Date picker
  • datetime-local - Date and time picker
  • time - Time picker
  • month - Month picker
  • week - Week picker
  • color - Color picker
  • range - Range slider
  • file - File upload
  • option - Select dropdown (single or multi-select)
  • checkbox - Checkbox input
  • radio - Radio button group
  • boolean - Boolean toggle
  • hidden - Hidden field
  • search - Search input
  • none - No input (display only)

Validations

Schemas can include validation rules:

{
  "id": "email",
  "type": "email",
  "name": "Email",
  "validations": [
    { "validation": "format", "value": "email" },
    { "validation": "min", "value": "5" },
    { "validation": "max", "value": "100" },
    { "validation": "optional" }
  ]
}

Supported Validation Types

  • min - Minimum length or value
  • max - Maximum length or value
  • format - Format validation (email, url, non-empty, integer)
  • optional - Makes the field optional
  • accept - File type acceptance (for file inputs)

Validation API

validateSchemaWithZod

Validates a JSON schema string and returns validation results.

import { validateSchemaWithZod } from 'masumi-schema-validator-component';

const result = validateSchemaWithZod(schemaString);

if (result.valid) {
  console.log('Valid schemas:', result.parsedSchemas);
} else {
  console.log('Errors:', result.errors);
  // Errors include line numbers and helpful messages
}

Return Type

interface ValidationResult {
  valid: boolean;
  errors: { message: string; line?: number }[];
  parsedSchemas?: JobInputSchemaType[];
}

Development

Setup

# Install dependencies
npm install

# Start development server
npm run dev

# Build library
npm run build

# Type check
npm run type-check

# Lint
npm run lint

Project Structure

src/
  components/
    SchemaPlayground.tsx      # Main playground component
    JobInputsFormRenderer.tsx # Form renderer component
    JobInputRenderer.tsx      # Individual input renderer
  lib/
    validation.ts              # Schema validation logic
    job-input-schema.ts        # Schema type definitions
  dev/
    main.tsx                  # Development app
    examples.ts               # Example schemas
    styles.css                # Global styles
  index.ts                    # Main exports

Styling

This component uses Tailwind CSS for styling. Make sure Tailwind CSS is configured in your project. The component includes its own minimal UI components but relies on Tailwind for styling.

Tailwind Configuration

Important: To ensure all styles (including dark mode variants) are properly generated, you must configure Tailwind to scan the component's TypeScript/JavaScript files. Add the following to your CSS file (e.g., global.css or app.css):

@import 'tailwindcss';

/* Ensure Tailwind scans external schema validator classes (including dark variants) */
@source "../node_modules/masumi-schema-validator-component/dist/index.mjs";
@source "../node_modules/masumi-schema-validator-component/dist/index.js";

This ensures that Tailwind generates all necessary utility classes used by the component, including dark mode variants like dark:bg-red-900/30, dark:text-red-200, etc.

TypeScript

Full TypeScript support is included. All components and functions are fully typed:

import type {
  JobInputSchemaType,
  ValidationResult,
  SchemaPlaygroundProps,
  JobInputsFormRendererProps
} from 'masumi-schema-validator-component';

License

See LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.