Skip to content

Zod Schema Reference (@oim-media/core) ​

The @oim-media/core package provides strict runtime validation schemas implemented in Zod. Every .oim and .ovm metadata stream must conform to these data definitions before reaching the render boundary.


1. Top-Level OIM Metadata Schema (OimMetadataSchema) ​

Defines the root dictionary structure of an interactive image container:

typescript
import { z } from "zod";

export const OimMetadataSchema = z.object({
  oim: z.string().optional(),
  version: z.string().optional(),
  min_player: z.string().max(16).optional(),
  media_type: z.enum(["image", "video"]).optional(),
  oim_id: z.string().max(128).optional(),
  image_hash: z.string().max(64).optional(), // SHA-256 hash of the baked image (Layer −1)
  reedit: z.enum(["public", "author_only", "sealed"]).optional(),  // Re-edit permission (1.23.0). Legacy `reedicion` (Spanish values) is still read until 2.0.0.
  immutable_lock: z.boolean().optional(),
  allowed_domains: z.array(z.string().max(253)).optional(),
  canvas: z.object({
    natural_width: z.number().positive(),
    natural_height: z.number().positive()
  }).optional(),
  capabilities: z.array(z.string()).optional(),
  slots: z.array(slotSchema),
  signature: z.string().optional(), // ECDSA P-256 Base64
  key_version: z.string().optional(),
  timestamp: z.string().datetime({ offset: true }).optional(),
}).passthrough();

2. Interactive Slot Schema (slotSchema) ​

Defines individual interactive layer elements:

typescript
export const slotSchema = z.object({
  id: z.string().min(1).max(128),
  type: z.enum([
    "text", "image", "lottie", "zone", "geo", "shape", "draw",
    "filter", "container", "group", "component", "mask", "svg", "pattern", "artistic-text"
  ]).optional(),
  name: z.string().max(256).optional(),
  align: z.enum(["left", "center", "right"]).optional(),
  position: z.tuple([z.number(), z.number()]).optional(), // [x_pct, y_pct]
  width_px: z.number().optional(),
  height_px: z.number().optional(),
  style: styleSchema.optional(),
  content: contentSchema.optional(),
  interaction: interactionSchema.optional(),
  tracking_data: z.array(trackingKeyframeSchema).optional(),
});

3. Style & Layout Schema (styleSchema) ​

Validates styling rules applied to slots:

typescript
export const styleSchema = z.object({
  width: z.string().optional(),
  height: z.string().optional(),
  maxWidth: z.string().optional(),
  fontSize: z.string().optional(),
  color: z.string().optional(),
  backgroundColor: z.string().optional(),
  borderRadius: z.string().optional(),
  opacity: z.number().min(0).max(1).optional(),
  transform: z.string().optional(),
  boxShadow: z.string().optional(),
  textShadow: z.string().optional(),
  filter: z.string().optional(),
  animation: z.union([z.string(), keyframeAnimationSchema]).optional(),
}).passthrough();

4. Multi-Language Content Schema (contentSchema) ​

Validates localized text and embedded media assets:

typescript
export const contentSchema = z.record(
  z.string(), // Language code: "en", "es", "fr", etc.
  z.string().max(10000000) // Up to 10MB for base64 inline assets
);

5. Temporal Video Tracking Keyframe Schema (trackingKeyframeSchema) ​

Validates 60 FPS spatial bounding box keyframes for .ovm video streams:

typescript
export const trackingKeyframeSchema = z.tuple([
  z.number().min(0), // t (time in seconds)
  z.number(), z.number(), // x1, y1
  z.number(), z.number(), // x2, y2
  z.number(), z.number(), // x3, y3
  z.number(), z.number(), // x4, y4
  z.number(), z.number()  // cx, cy (center)
]);