Skip to content

Universal-Commerce-Protocol/js-sdk

UCP JavaScript SDK

Official JavaScript library for the Universal Commerce Protocol (UCP).

Overview

This repository contains the JavaScript SDK for the Universal Commerce Protocol (UCP). It provides TypeScript types and Zod schemas for UCP models, making it easy to build UCP-compliant applications in JavaScript and TypeScript.

UCP Version Compatibility

Each version of the JavaScript SDK is generated against a specific version of the UCP schema:

SDK Version UCP Schema Version
0.4.x 2026-04-08
0.1.1 2026-01-23
0.1.0 2026-01-11

Installation

To install the SDK in your project, run:

npm install @ucp-js/sdk

Usage

The SDK provides Zod schemas and TypeScript types for UCP models. You can use Zod to validate incoming data or ensure your outgoing data matches the specification.

TypeScript / ES Modules

import { CheckoutResponseSchema, CheckoutResponse } from "@ucp-js/sdk";

// Validate data against UCP schemas
const parseResult = CheckoutResponseSchema.safeParse(checkoutData);

if (parseResult.success) {
  const checkout: CheckoutResponse = parseResult.data;
  console.log(checkout.status); // "incomplete" | "ready_for_complete" | ...
  console.log(checkout.currency); // ISO 4217 currency code
} else {
  console.error(parseResult.error);
}

CommonJS

const { CheckoutResponseSchema } = require("@ucp-js/sdk");

const parseResult = CheckoutResponseSchema.safeParse(checkoutData);
if (parseResult.success) {
  const checkout = parseResult.data;
  // ...
}

Development

Prerequisites

This project uses npm for package management and typescript for building.

Generating Models

The models are automatically generated from the JSON schemas in the UCP Specification.

To regenerate the models, you first need a local copy of the UCP specification. If you don't have one, you can clone it via:

git clone https://github.com/Universal-Commerce-Protocol/ucp.git

Then, run npm run generate pointing to the spec folder of the cloned repository, e.g.:

npm run generate -- ucp/spec

Building

To build the project for both CommonJS and ESM:

npm run build

Contributing

We welcome community contributions. See our Contribution Guide for details.

License

UCP is an open-source project under the Apache License 2.0.

About

The official JavaScript SDK for UCP

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors