ucpjs-sdk
v0.1.0
Published
Universal Commerce Protocol SDK for TypeScript/JavaScript
Maintainers
Readme
ucpjs
TypeScript/JavaScript SDK for Universal Commerce Protocol (UCP).
Installation
# npm
npm install ucpjs
# yarn
yarn add ucpjs
# pnpm
pnpm add ucpjs
# bun
bun add ucpjsUsage
import {
CheckoutCreateRequestSchema,
CheckoutCreateRequest,
BuyerSchema,
Buyer
} from 'ucpjs'
// Type-safe object creation
const buyer: Buyer = {
first_name: "Ali",
last_name: "Yilmaz",
email: "[email protected]"
}
// Runtime validation with Zod
const validated = BuyerSchema.parse(buyer)
// Create checkout request
const checkout: CheckoutCreateRequest = {
currency: "TRY",
line_items: [{
item: { id: "product-1" },
quantity: 1
}],
payment: {}
}
// Validate before sending to API
CheckoutCreateRequestSchema.parse(checkout)Features
- TypeScript Types: Full type definitions for all UCP schemas
- Zod Schemas: Runtime validation with Zod
- Dual Format: ESM and CommonJS support
- Auto-generated: Schemas generated from official UCP JSON Schema definitions
Available Schemas
Key exports include:
| Schema | Description |
|--------|-------------|
| CheckoutCreateRequestSchema | Create checkout request |
| CheckoutUpdateRequestSchema | Update checkout request |
| CheckoutResponseSchema | Checkout response |
| OrderSchema | Order response |
| BuyerSchema | Buyer information |
| UcpDiscoveryProfileSchema | Discovery profile |
| FulfillmentResponseSchema | Fulfillment response |
All schemas export both the Zod schema (*Schema) and inferred TypeScript type.
Development
# Install dependencies
bun install
# Generate schemas from UCP spec
bun run generate
# Build
bun run buildLinks
License
Apache-2.0
