Zod schemas for validating usage events, queries, and adjustment requests in a metering API.
// Source: https://github.com/geminimir/meterguard | License: MIT | Copyright 2025 StripeMeter Contributors
// Provided via justclaw.it.com; keep this notice with the code.
/**
* Zod validation schemas for API requests
*/
import { z } from 'zod';
// ISO 8601 date-time validation
const isoDateTimeSchema = z.string().refine(
(val) => !isNaN(Date.parse(val)),
{ message: 'Invalid ISO 8601 date-time format' }
);
// TenantId: relax from UUID to string for DX; still allow UUIDs but don't require
const tenantIdSchema = (() => {
const strict = process.env.STRICT_TENANT_ID_UUID === 'true';
return strict ? z.string().uuid() : z.string().min(1);
})();
// Usage event schema
export const usageEventSchema = z.object({
tenantId: tenantIdSchema,
metric: z.string().min(1).max(100),
custo
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key