Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rest/nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"scripts": {
"dev": "tsx watch src/index.ts",
"build": "tsc",
"test": "tsx --test test/*.test.ts",
"start": "node dist/index.js",
"generate:models": "bash scripts/generate_models.sh"
},
Expand Down
64 changes: 51 additions & 13 deletions rest/nodejs/src/api/discovery.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
import { type Context } from "hono";
import { type UcpDiscoveryProfile } from "../models";

type DiscoveryCapability = {
version: string;
spec: string;
schema: string;
extends?: string;
};

type DiscoveryServiceBinding = {
version: string;
spec: string;
schema: string;
transport: "rest";
endpoint: string;
};

type UcpDiscoveryMetadata = {
version: string;
services: Record<string, DiscoveryServiceBinding[]>;
capabilities: Record<string, DiscoveryCapability[]>;
};

/**
* Service for handling UCP discovery requests.
Expand All @@ -24,62 +44,76 @@ export class DiscoveryService {
* @returns A JSON response containing the merchant profile.
*/
getMerchantProfile = (c: Context) => {
const discoveryProfile: UcpDiscoveryProfile = {
ucp: {
version: this.ucpVersion,
services: {
"dev.ucp.shopping": {
const ucp = {
version: this.ucpVersion,
services: {
"dev.ucp.shopping": [
{
version: this.ucpVersion,
spec: "https://ucp.dev/2026-01-23/specification/shopping",
rest: {
schema:
"https://ucp.dev/2026-01-23/services/shopping/openapi.json",
endpoint: "http://localhost:3000",
},
transport: "rest",
schema: "https://ucp.dev/2026-01-23/services/shopping/openapi.json",
endpoint: "http://localhost:3000",
},
},
capabilities: [
],
},
capabilities: {
"dev.ucp.shopping.checkout": [
{
version: this.ucpVersion,
spec: "https://ucp.dev/2026-01-23/specification/shopping/checkout",
schema: "https://ucp.dev/2026-01-23/schemas/shopping/checkout.json",
},
],
"dev.ucp.shopping.order": [
{
version: this.ucpVersion,
spec: "https://ucp.dev/2026-01-23/specification/shopping/order",
schema: "https://ucp.dev/2026-01-23/schemas/shopping/order.json",
},
],
"dev.ucp.shopping.refund": [
{
version: this.ucpVersion,
spec: "https://ucp.dev/2026-01-23/specification/shopping/refund",
schema: "https://ucp.dev/2026-01-23/schemas/shopping/refund.json",
extends: "dev.ucp.shopping.order",
},
],
"dev.ucp.shopping.return": [
{
version: this.ucpVersion,
spec: "https://ucp.dev/2026-01-23/specification/shopping/return",
schema: "https://ucp.dev/2026-01-23/schemas/shopping/return.json",
extends: "dev.ucp.shopping.order",
},
],
"dev.ucp.shopping.dispute": [
{
version: this.ucpVersion,
spec: "https://ucp.dev/2026-01-23/specification/shopping/dispute",
schema: "https://ucp.dev/2026-01-23/schemas/shopping/dispute.json",
extends: "dev.ucp.shopping.order",
},
],
"dev.ucp.shopping.discount": [
{
version: this.ucpVersion,
spec: "https://ucp.dev/2026-01-23/specification/shopping/discount",
schema: "https://ucp.dev/2026-01-23/schemas/shopping/discount.json",
extends: "dev.ucp.shopping.checkout",
},
],
"dev.ucp.shopping.fulfillment": [
{
version: this.ucpVersion,
spec: "https://ucp.dev/2026-01-23/specification/shopping/fulfillment",
schema:
"https://ucp.dev/2026-01-23/schemas/shopping/fulfillment.json",
extends: "dev.ucp.shopping.checkout",
},
],
"dev.ucp.shopping.buyer_consent": [
{
version: this.ucpVersion,
spec: "https://ucp.dev/2026-01-23/specification/shopping/buyer_consent",
Expand All @@ -89,6 +123,10 @@ export class DiscoveryService {
},
],
},
} satisfies UcpDiscoveryMetadata;

const discoveryProfile = {
ucp,
payment: {
handlers: [
{
Expand Down
48 changes: 48 additions & 0 deletions rest/nodejs/test/discovery.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import assert from "node:assert/strict";
import { test } from "node:test";

import { Hono } from "hono";

import { DiscoveryService } from "../src/api/discovery";

type DiscoveryResponse = {
ucp: {
services: Record<string, Array<{ endpoint: string; transport: string }>>;
capabilities: Record<string, Array<{ version: string }>>;
};
};

test("merchant profile uses schema-compliant discovery registries", async () => {
const app = new Hono();
const discoveryService = new DiscoveryService();
app.get("/.well-known/ucp", discoveryService.getMerchantProfile);

const response = await app.request("/.well-known/ucp");
const body = (await response.json()) as DiscoveryResponse;

assert.equal(response.status, 200);

const shoppingServices = body.ucp.services["dev.ucp.shopping"];
assert.ok(Array.isArray(shoppingServices));
assert.equal(shoppingServices.length, 1);
assert.equal(shoppingServices[0]?.transport, "rest");
assert.equal(shoppingServices[0]?.endpoint, "http://localhost:3000");

assert.equal(Array.isArray(body.ucp.capabilities), false);
assert.deepEqual(Object.keys(body.ucp.capabilities).sort(), [
"dev.ucp.shopping.buyer_consent",
"dev.ucp.shopping.checkout",
"dev.ucp.shopping.discount",
"dev.ucp.shopping.dispute",
"dev.ucp.shopping.fulfillment",
"dev.ucp.shopping.order",
"dev.ucp.shopping.refund",
"dev.ucp.shopping.return",
]);

for (const [name, declarations] of Object.entries(body.ucp.capabilities)) {
assert.ok(Array.isArray(declarations), `${name} must be an array`);
assert.equal(declarations.length, 1);
assert.equal(declarations[0]?.version, discoveryService.ucpVersion);
}
});
Loading