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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@zodforge/cloud

v1.0.0

Published

Official TypeScript client for ZodForge Cloud API - AI-powered Zod schema refinement

Readme

@zodforge/cloud

Official TypeScript SDK for ZodForge Cloud API - AI-powered Zod schema refinement.

Installation

npm install @zodforge/cloud zod

Quick Start

Method 1: Client Instance (Recommended)

import { ZodForgeClient } from '@zodforge/cloud';

const client = new ZodForgeClient({
  apiKey: 'zf_your_api_key_here'
});

const result = await client.refineSchema({
  schema: {
    code: 'z.object({ email: z.string() })',
    typeName: 'User',
    fields: { email: 'z.string()' }
  },
  samples: [
    { email: '[email protected]' },
    { email: '[email protected]' }
  ]
});

console.log(result.refinedSchema.code);
// z.object({ email: z.string().email().toLowerCase().trim() })

Method 2: Convenience Functions

import { refineSchema, setApiKey } from '@zodforge/cloud';

// Option 1: Set global API key
setApiKey('zf_your_api_key_here');
const result = await refineSchema({
  schema: { /* ... */ },
  samples: [ /* ... */ ]
});

// Option 2: Pass API key per request
const result = await refineSchema(
  {
    schema: { /* ... */ },
    samples: [ /* ... */ ]
  },
  { apiKey: 'zf_your_api_key_here' }
);

Features

🧠 Context Reasoning (Semantic Analysis)

The AI detects field relationships and suggests composite schemas:

const result = await client.refineSchema({
  schema: {
    code: 'z.object({ price: z.number(), currency: z.string() })',
    typeName: 'Product',
    fields: {
      price: 'z.number()',
      currency: 'z.string()'
    }
  },
  samples: [
    { price: 100, currency: 'USD' },
    { price: 50, currency: 'EUR' }
  ]
});

// Check semantic relationships
console.log(result.refinedSchema.relationships);
// [
//   {
//     fields: ['price', 'currency'],
//     pattern: 'monetary_value',
//     suggestion: 'Consider creating a Money type...',
//     confidence: 0.92
//   }
// ]

🔍 Enhanced Explainability

Every improvement includes full traceability:

result.refinedSchema.improvements.forEach(improvement => {
  console.log(`Field: ${improvement.field}`);
  console.log(`Change: ${improvement.before} → ${improvement.after}`);
  console.log(`Reason: ${improvement.reason}`);
  console.log(`Source: ${improvement.sourceSnippet}`);
  console.log(`Pattern: ${improvement.detectedPattern}`);
  console.log(`Rule: ${improvement.ruleApplied}`);
});

// Example output:
// Field: email
// Change: z.string() → z.string().email().toLowerCase().trim()
// Reason: Field contains email addresses, added validation
// Source: [email protected]
// Pattern: email_format
// Rule: RFC5322_email

⚡ Response Caching

Identical requests are cached for instant responses:

// First call: ~9 seconds (AI processing)
const result1 = await client.refineSchema(request);

// Second call: <1ms (cached)
const result2 = await client.refineSchema(request);

console.log(result2.cached); // true
console.log(result2.processingTime); // <1ms

API Reference

ZodForgeClient

class ZodForgeClient {
  constructor(options: {
    apiKey: string;
    baseUrl?: string;     // Default: https://api.zodforge.com
    timeout?: number;     // Default: 30000ms
    retries?: number;     // Default: 2
  });

  refineSchema(request: RefinementRequest): Promise<RefinementResponse>;
  getHealth(): Promise<HealthCheckResponse>;
  getUsage(): Promise<UsageStats>;
  setApiKey(apiKey: string): void;
  setBaseUrl(baseUrl: string): void;
}

Convenience Functions

// Refine schema
refineSchema(
  request: RefinementRequest,
  options?: { apiKey?: string; baseUrl?: string }
): Promise<RefinementResponse>

// Get health status
getHealth(
  options?: { apiKey?: string; baseUrl?: string }
): Promise<HealthCheckResponse>

// Get usage statistics
getUsage(
  options?: { apiKey?: string; baseUrl?: string }
): Promise<UsageStats>

// Set global API key
setApiKey(apiKey: string): void

Usage Dashboard

Check your API usage and limits:

const usage = await client.getUsage();

console.log(`Tier: ${usage.data.tier}`);
console.log(`Used: ${usage.data.currentPeriod.used} / ${usage.data.currentPeriod.limit}`);
console.log(`Remaining: ${usage.data.currentPeriod.remaining}`);
console.log(`Resets: ${usage.data.currentPeriod.resetDate}`);
console.log(`Success Rate: ${usage.data.lastWeek.successRate}%`);
console.log(`Avg Response Time: ${usage.data.lastWeek.avgProcessingTimeMs}ms`);

Advanced Options

AI Provider Selection

const result = await client.refineSchema({
  schema: { /* ... */ },
  samples: [ /* ... */ ],
  options: {
    provider: 'openai',      // 'openai' | 'anthropic' | 'auto'
    model: 'gpt-4-turbo-preview',
    temperature: 0.2
  }
});

Custom Base URL (Self-Hosted)

const client = new ZodForgeClient({
  apiKey: 'zf_...',
  baseUrl: 'http://localhost:3000'  // For local development
});

Error Handling

import { ZodForgeError } from '@zodforge/cloud';

try {
  const result = await client.refineSchema(request);
} catch (error) {
  if (error instanceof ZodForgeError) {
    console.error(`Status: ${error.statusCode}`);
    console.error(`Code: ${error.errorCode}`);
    console.error(`Message: ${error.message}`);
  }
}

Environment Variables

You can set your API key via environment variable:

export ZODFORGE_API_KEY=zf_your_api_key_here

Then use the SDK without passing the key:

import { refineSchema } from '@zodforge/cloud';

// API key loaded from ZODFORGE_API_KEY env var
const result = await refineSchema({
  schema: { /* ... */ },
  samples: [ /* ... */ ]
});

TypeScript Types

Full TypeScript support with comprehensive type definitions:

import type {
  RefinementRequest,
  RefinementResponse,
  RefinedSchema,
  FieldImprovement,
  FieldRelationship,
  UsageStats,
  HealthCheckResponse,
  ZodForgeError
} from '@zodforge/cloud';

Examples

Basic Email Validation

const result = await client.refineSchema({
  schema: {
    code: 'z.object({ email: z.string() })',
    typeName: 'User',
    fields: { email: 'z.string()' }
  },
  samples: [
    { email: '[email protected]' },
    { email: '[email protected]' }
  ]
});

// Result: z.object({ email: z.string().email().toLowerCase().trim() })

Geolocation Schema

const result = await client.refineSchema({
  schema: {
    code: 'z.object({ lat: z.number(), lng: z.number() })',
    typeName: 'Location',
    fields: {
      lat: 'z.number()',
      lng: 'z.number()'
    }
  },
  samples: [
    { lat: 51.5074, lng: -0.1278 },  // London
    { lat: 40.7128, lng: -74.0060 }  // New York
  ]
});

// Improvements:
// - lat: z.number().min(-90).max(90)
// - lng: z.number().min(-180).max(180)

// Relationships:
// - pattern: "geolocation"
// - suggestion: "Consider creating a Geolocation type..."

Links

License

MIT © merlin white