x402-listing / tree / src/discovery.js ยท raw (this view has old GitHub links rewritten for the mirror; raw is byte-exact)
// Discovery documents for the listing service: /openapi.json and /.well-known/x402, built from the live tier config.
import { SERVICE_META } from './service-meta.js';
import { TIER_LIST, usd } from './tiers.js';
import { TERMS, TERMS_SHORT } from './terms.js';
import { LIMITS } from './validate.js';

export const LOGO_SVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="64" height="64" role="img" aria-label="YourAITools Listings"><rect width="64" height="64" rx="14" fill="#0f172a"/><rect x="13" y="14" width="38" height="36" rx="5" fill="none" stroke="#38bdf8" stroke-width="3"/><path d="M20 25h24M20 33h16M20 41h10" stroke="#38bdf8" stroke-width="3" stroke-linecap="round"/><path d="M44 36l2.4 4.9 5.4.8-3.9 3.8.9 5.4-4.8-2.5-4.8 2.5.9-5.4-3.9-3.8 5.4-.8z" fill="#facc15"/></svg>`;

export const SUBMISSION_SCHEMA = {
  type: 'object', required: ['tool_url', 'name', 'contact_email', 'category'], additionalProperties: true,
  properties: {
    tool_url: { type: 'string', format: 'uri', maxLength: LIMITS.url, description: 'Public https URL of the tool, API or its docs', example: 'https://example.com' },
    name: { type: 'string', minLength: 2, maxLength: LIMITS.name, example: 'Example Tool' },
    contact_email: { type: 'string', format: 'email', maxLength: LIMITS.email, description: 'Only used to contact you about this submission; never shown publicly', example: 'you@example.com' },
    category: { type: 'string', minLength: 2, maxLength: LIMITS.category, example: 'x402 API' },
    description: { type: 'string', maxLength: LIMITS.description, description: 'Optional: one or two sentences on what it does' },
    notes: { type: 'string', maxLength: LIMITS.notes, description: 'Optional: anything the reviewer should know (pricing, x402 endpoint, launch date)' },
  },
};
export const RECEIPT_SCHEMA = { type: 'object', properties: { ref: { type: 'string', pattern: '^LST-[0-9A-HJKMNP-TV-Z]{10}$' }, status: { type: 'string', enum: ['received'] }, tier: { type: 'string' }, review_by: { type: 'string', format: 'date-time' }, status_url: { type: 'string' }, payment: { type: 'object' }, terms: { type: 'string' } } };
export const STATUS_SCHEMA = { type: 'object', properties: { ref: { type: 'string' }, status: { type: 'string', enum: ['received', 'approved', 'rejected', 'refund_pending', 'refunded'] }, tier: { type: 'string' }, name: { type: 'string' }, tool_url: { type: 'string' }, category: { type: 'string' }, received_at: { type: 'string' }, review_by: { type: 'string' }, decided_at: { type: ['string', 'null'] }, featured_from: { type: 'string' }, featured_until: { type: 'string' }, payment: { type: ['object', 'null'] }, refund: { type: 'object' } } };

export function openapiDoc({ origin, network, payTo, asset }) {
  const paths = {};
  for (const t of TIER_LIST) {
    paths[t.path] = { post: {
      operationId: `listing_${t.id.replace('-', '_')}`, summary: `${t.label}: ${usd(t.amount)} USDC`, description: `${t.what} ${TERMS_SHORT}`, tags: ['paid'],
      'x-payment-info': { price: { mode: 'fixed', currency: 'USD', amount: usd(t.amount) }, protocols: [{ x402: {} }] },
      'x-x402': { scheme: 'exact', network, asset, payTo, amount: String(t.amount), assetSymbol: 'USDC', x402Versions: [2, 1] },
      requestBody: { required: true, content: { 'application/json': { schema: SUBMISSION_SCHEMA } } },
      responses: { 200: { description: 'Paid and settled: submission received', content: { 'application/json': { schema: RECEIPT_SCHEMA } } }, 400: { description: 'Invalid body (checked before payment, so no 402 and never charged)' }, 402: { description: 'Payment Required (x402 v2 terms in the PAYMENT-REQUIRED header, v1 terms in the body); returned for a valid body, an empty body or {}' }, 503: { description: 'Storage unavailable (never charged)' } },
    } };
  }
  paths['/v1/status/{ref}'] = { get: { operationId: 'listing_status', summary: 'Free: status of a paid submission (no email shown)', security: [], parameters: [{ name: 'ref', in: 'path', required: true, schema: { type: 'string', pattern: '^LST-[0-9A-HJKMNP-TV-Z]{10}$' } }], responses: { 200: { description: 'OK', content: { 'application/json': { schema: STATUS_SCHEMA } } }, 404: { description: 'Unknown ref' }, 429: { description: 'Rate limited' } } } };
  paths['/v1/tiers'] = { get: { operationId: 'listing_tiers', summary: 'Free: tiers, prices and terms', security: [], responses: { 200: { description: 'OK' } } } };
  return {
    openapi: '3.1.0',
    info: {
      title: SERVICE_META.serviceName, version: '0.1.0', 'x-guidance': `POST ${origin}/v1/fast-track (or /v1/launch, /v1/featured) with JSON {"tool_url","name","contact_email","category"} using any x402 client. An invalid body gets 400 before any payment; a valid one gets the 402 terms, then the paid retry returns {ref, status:"received", review_by}. Track it free at GET /v1/status/<ref>.`,
      contact: { email: 'hello@youraitools.co', url: 'https://youraitools.co' }, 'x-logo': { url: SERVICE_META.iconUrl },
      description: `Paid listing services for youraitools.co, a directory of AI tools and x402 APIs, paid in USDC over x402: fast-track review ($19), Launch bundle ($49) and Featured for 30 days ($29). A service, not an API tool. ${TERMS}`,
    },
    servers: [{ url: origin }],
    externalDocs: { description: 'Source and docs', url: 'https://agentgate-source.pages.dev/x402-listing/' },
    paths,
  };
}

export function wellKnownX402({ origin }) {
  return {
    version: 1,
    name: SERVICE_META.serviceName, category: SERVICE_META.category, categories: SERVICE_META.categories, tags: SERVICE_META.tags, iconUrl: SERVICE_META.iconUrl,
    resources: TIER_LIST.map((t) => `${origin}${t.path}`),
    instructions: `Paid listings on youraitools.co (AI tools directory). POST JSON {"tool_url","name","contact_email","category"} to /v1/fast-track ($19, review within 24h), /v1/launch ($49, fast-track + 30 days Featured + a newsletter line once there are subscribers) or /v1/featured ($29, 30 days Featured). Invalid bodies get 400 before payment. Paid in USDC on Base (eip155:8453) via x402 v2 (PAYMENT-SIGNATURE) or v1 (X-PAYMENT); only HTTP 200 results are settled. ${TERMS_SHORT} Status: GET /v1/status/<ref>. Docs: /openapi.json`,
    openapi: `${origin}/openapi.json`,
  };
}

agentgate-source: code mirror on Cloudflare Pages. All repos