Spec & Runtime Contracts
@aircada/spec defines runtime Zod validation schemas and TypeScript engine contracts shared across storefronts, Studio, CLI, and AIR Engine.
Runtime Zod Schemas & Engine Contracts | Aircada Docs#
Resilient Storefront Ingress Validation
AirEcommerceContextSchema parses runtime storefront globals (window.__AIRCADA_ECOMMERCE_CONTEXT__) injected by Liquid, Next.js, or headless APIs. Non-throwing union fallbacks (z.union([Schema, z.record(z.string(), z.never())])) ensure partial or incomplete storefront payloads degrade cleanly instead of crashing the 3D session.
Mixed Numeric & GID Coercion
Shopify and headless platforms mix numeric IDs (12345) with GraphQL Global IDs (gid://shopify/Product/12345). EcommerceProductSchema and EcommerceVariantSchema normalize identifiers with z.union([z.string(), z.number()]). OptionsRegistrySetSchema preserves custom storefront metadata via .catchall() so downstream pricing and fulfillment fields are never stripped.
Decoupled Engine Operator Contracts
Generated interfaces (IOperator, TimerOperator, OnStartOperator, OpenLinkOperator, ISceneObject) separate inputs (callable methods) from outputs (typed AirEvent<T> subscriptions returning an unsubscribe teardown function). Always invoke the returned teardown function on unmount to prevent listener leaks across scene reloads.
| Symbol | Role | Notes |
|---|---|---|
| AirEcommerceContextSchema | Zod schema | Safe-parses window.AIRCADA_ECOMMERCE_CONTEXT without throwing. |
| EcommerceProductSchema / EcommerceVariantSchema | Zod schema | Accepts both numeric IDs and Shopify GraphQL GID strings. |
| OptionsRegistrySetSchema | Zod schema | Maps option sets to pricing deltas; preserves extra keys via catchall(). |
| IOperator / ISceneObject | TypeScript interface | Auto-generated contracts decoupling scripts from engine internals. |
| AirEvent<T>.listen(cb) | Subscription | Returns () => void unsubscribe callback for clean teardown. |
import { AirEcommerceContextSchema, type TimerOperator } from "@aircada/spec";
const parsed = AirEcommerceContextSchema.safeParse(window.__AIRCADA_ECOMMERCE_CONTEXT__);
if (parsed.success) {
console.log("Storefront context:", parsed.data);
}
export function bindTimer(timer: TimerOperator) {
const unsubscribe = timer.onComplete.listen(() => {
console.log("Timer completed");
});
return unsubscribe;
}