Skip to content

Commit b8ef7ad

Browse files
whoabuddyclaude
andauthored
feat: add Bazaar discovery metadata for x402 endpoints (#35)
* feat(bazaar): add TypeScript types for Bazaar extension Define interfaces for Coinbase x402 Bazaar discovery metadata: - BazaarInputHttp: HTTP method and parameter spec - BazaarOutputJson: Response example structure - BazaarInfo: Complete input/output info - BazaarSchema: JSON Schema validator - BazaarExtension: Full extension object - EndpointMetadata: Registry entry structure Implements Bazaar format natively rather than using @x402/extensions (which depends on EVM-focused @x402/core). Co-Authored-By: Claude <noreply@anthropic.com> * feat(bazaar): add complete endpoint metadata registry Create comprehensive discovery registry for all ~40 API endpoints: Hashing (6 endpoints): - SHA-256, SHA-512, SHA-512/256, Keccak-256, Hash160, RIPEMD-160 Stacks (6 endpoints): - Address conversion, Clarity decode, transaction decode - Profile lookup, message verification, SIP-018 verification Inference (4 endpoints): - OpenRouter models (free), OpenRouter chat (dynamic pricing) - Cloudflare models (free), Cloudflare chat (standard) Storage (21 endpoints): - KV store (4): set, get, list, delete - Paste service (3): create, get, delete - SQLite DB (3): query, execute, schema - Distributed locks (5): acquire, release, extend, status, list - Priority queues (5): push, pop, peek, status, clear - Vector memory (5): store, search, delete, list, clear Each entry includes: - HTTP method and path (with path parameters) - Request body/query param JSON schemas - Realistic output examples - Category and description Provides helper functions: - getEndpointMetadata(path): Pattern matching for parameterized paths - getEndpointsByCategory(category): Filter by category - REGISTRY_STATS: Count totals Co-Authored-By: Claude <noreply@anthropic.com> * feat(bazaar): add public API and helper functions Create src/bazaar/index.ts with: Exports: - All types from types.ts (BazaarExtension, EndpointMetadata, etc.) - Registry and utilities from registry.ts Helper Functions: - buildBazaarExtension(metadata): Constructs complete Bazaar extension with info (input/output spec) and schema (JSON Schema validator) - extractQueryParamsSchema(metadata): Get query param schema - extractBodySchema(metadata): Get request body schema The buildBazaarExtension helper will be used by the x402 middleware to inject discovery metadata into PaymentRequired responses. Co-Authored-By: Claude <noreply@anthropic.com> * feat(x402): inject Bazaar extensions into 402 responses Modify x402 middleware to include `extensions.bazaar` in PaymentRequired responses. The middleware now: 1. Looks up endpoint metadata from the Bazaar registry 2. Uses `buildBazaarExtension()` to construct discovery metadata 3. Injects the extension into the 402 response if metadata exists This enables facilitators to catalog API endpoints by reading the Bazaar discovery metadata directly from payment-required responses. Co-Authored-By: Claude <noreply@anthropic.com> * feat(schema): upgrade x402.json to v2 with Bazaar metadata Enhance the x402.json schema generator to emit v2 format with full Bazaar-compatible discovery metadata: - Upgrade x402Version from 1 to 2 - Import Bazaar registry and types - Add buildOutputSchema() helper to populate rich input/output metadata - Include full JSON schemas, query params, and realistic examples per endpoint - Maintain backward compatibility with existing ENDPOINT_REGISTRY structure The outputSchema now includes: - input.bodySchema: Full JSON Schema for request bodies - input.queryParams: Query parameter schemas - output.example: Realistic response examples from Bazaar registry - output.schema: Optional JSON Schema for responses This enables better endpoint discovery and integration with the Coinbase x402 Bazaar scanning layer. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor(bazaar): simplify discovery metadata and fix registry key collision Extract repeated tokenType query params and hash body schemas into shared constants, inline intermediate Bazaar types into BazaarExtension, remove unused helpers (extractQueryParamsSchema, extractBodySchema, REGISTRY_STATS, getEndpointsByCategory), hoist static JSON Schema to a module-level constant, fix Map key collision where endpoints sharing a path but differing by HTTP method silently overwrote each other, and normalize imports through the barrel module. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(bazaar): normalize resource paths and include schemas in extensions - Use {param} format for resource paths in x402.json (was :param) - Include bodySchema and outputSchema in Bazaar 402 extensions - Update BazaarExtension type to allow new fields Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 2c7b45b commit b8ef7ad

5 files changed

Lines changed: 1204 additions & 19 deletions

File tree

src/bazaar/index.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* Bazaar Extension - Public API
3+
*
4+
* Exports types, registry, and helper functions for Coinbase x402 Bazaar
5+
* discovery metadata integration.
6+
*/
7+
8+
// Re-export types
9+
export type { BazaarExtension, EndpointMetadata } from "./types";
10+
11+
// Re-export registry and utilities
12+
export { getEndpointMetadata } from "./registry";
13+
14+
import type { EndpointMetadata, BazaarExtension } from "./types";
15+
16+
/**
17+
* Static JSON Schema validator for the Bazaar info structure.
18+
* This schema validates the shape of the info object (input/output),
19+
* not the endpoint's data -- so it is the same for every endpoint.
20+
*/
21+
const BAZAAR_INFO_SCHEMA: BazaarExtension["bazaar"]["schema"] = {
22+
$schema: "https://json-schema.org/draft/2020-12/schema",
23+
type: "object",
24+
properties: {
25+
input: {
26+
type: "object",
27+
properties: {
28+
type: { type: "string", const: "http" },
29+
method: { type: "string", enum: ["GET", "POST", "PUT", "PATCH", "DELETE"] },
30+
queryParams: { type: "object" },
31+
bodyType: { type: "string", enum: ["json", "form", "text", "binary"] },
32+
},
33+
required: ["type", "method"],
34+
},
35+
output: {
36+
type: "object",
37+
properties: {
38+
type: { type: "string", const: "json" },
39+
example: { type: "object" },
40+
},
41+
required: ["type", "example"],
42+
},
43+
},
44+
required: ["input", "output"],
45+
};
46+
47+
/**
48+
* Build a complete Bazaar extension from endpoint metadata
49+
*/
50+
export function buildBazaarExtension(metadata: EndpointMetadata): BazaarExtension {
51+
return {
52+
bazaar: {
53+
info: {
54+
input: {
55+
type: "http",
56+
method: metadata.method,
57+
...(metadata.queryParams && { queryParams: metadata.queryParams }),
58+
...(metadata.bodyType && { bodyType: metadata.bodyType }),
59+
...(metadata.bodySchema && { bodySchema: metadata.bodySchema }),
60+
},
61+
output: {
62+
type: "json",
63+
example: metadata.outputExample,
64+
...(metadata.outputSchema && { schema: metadata.outputSchema }),
65+
},
66+
},
67+
schema: BAZAAR_INFO_SCHEMA,
68+
},
69+
};
70+
}

0 commit comments

Comments
 (0)