Skip to content

Offer builder

Creates a single Offer with validated currency metadata. The Offer builder injects @type, validates synchronously, and rejects unknown properties.

// Astro — shown first when Astro is selected
import { Offer } from '@unschema-graph/astro';
// Svelte 5
import { Offer } from '@unschema-graph/svelte';
// Core / Node.js
import { Offer } from '@unschema-graph/core';
import { OfferSchema } from '@unschema-graph/core';

The OfferSchema Zod schema is also exported for composition and advanced validation.

import {
OfferSchema,
type SchemaInput,
type SchemaOutput,
} from '@unschema-graph/core';
type OfferInput = SchemaInput<typeof OfferSchema>;
type OfferOutput = SchemaOutput<typeof OfferSchema, 'Offer'>;
Property Input type Required Default / constraints
@id string No —
price number | string Yes —
priceCurrency string Yes minimum length: 3; maximum length: 3
availability string No —
url string No —
priceValidUntil string | number | Date No non-empty
itemCondition string No —
seller string | Person | Organization | EntityReference No non-empty

The aliases above remain the exact authority for nested object types. The builder also accepts a validation configuration as its second argument and always returns @type: 'Offer'.

import { Offer } from '@unschema-graph/core';
const entity = Offer({
"price": 99,
"priceCurrency": "EUR",
"availability": "https://schema.org/InStock"
});
{
"@type": "Offer",
"price": 99,
"priceCurrency": "EUR",
"availability": "https://schema.org/InStock"
}
  • Passing an unknown property to the strict builder.
  • Using source data that is missing a required property.
  • Assuming valid Schema.org guarantees a search appearance.

Use Offer.safeParse(input) for external data. If Schema.org supports a property that is not modeled yet, validate the entity first and then use withAdditionalProperties(). Never pass invented properties to the strict builder.