import { createAgentDoor } from "@agentdoor/core";
import { StripeBridge } from "@agentdoor/stripe";
import { BazaarIntegration } from "@agentdoor/bazaar";
import { RegistryClient } from "@agentdoor/registry";
import Stripe from "stripe";
// Initialize integrations
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);
const stripeBridge = new StripeBridge({
stripeSecretKey: process.env.STRIPE_SECRET_KEY!,
});
stripeBridge.setStripeClient(stripe);
const bazaar = new BazaarIntegration(
{ apiKey: process.env.BAZAAR_API_KEY },
bazaarClient
);
const registry = new RegistryClient("https://registry.agentdoor.dev", {
apiKey: process.env.REGISTRY_API_KEY
});
// Create AgentDoor instance
const door = createAgentDoor({
scopes: [
{ id: "data.read", description: "Read access", price: "$0.001/req" },
{ id: "data.write", description: "Write access", price: "$0.01/req" },
],
x402: {
network: "base",
currency: "USDC",
paymentAddress: process.env.X402_WALLET!,
},
storage: {
driver: "postgres",
url: process.env.DATABASE_URL,
},
// Integration callbacks
onAgentRegistered: async (agent) => {
console.log(`New agent: ${agent.id}`);
},
onX402PaymentReceived: async (payment) => {
// Record in Stripe
await stripeBridge.reconcilePayment({
agentId: payment.agentId,
amount: Math.round(payment.amount * 100),
currency: "usd",
scope: payment.scope,
x402TxHash: payment.txHash,
timestamp: new Date(),
});
},
});
// Publish to marketplace and registry
const discoveryDoc = JSON.parse(
await readFile("./public/.well-known/agentdoor.json", "utf-8")
);
await Promise.all([
bazaar.publishService("https://api.example.com", discoveryDoc),
registry.register({
url: "https://api.example.com",
discoveryEndpoint: "https://api.example.com/.well-known/agentdoor.json",
}),
]);
console.log("Service published to Bazaar and Registry");