First pricing implementation (#27)

* first implementation of elasticity demand computation

* chor: fixing test :(

* feature: rudemantary defintition of pricing pipeline

* chor: fixing cross product missing data

* add warning

* feature: e2e pricing pipeline with inference
This commit is contained in:
Daniel Alves Rösel
2025-11-27 18:25:27 +01:00
committed by GitHub
parent 8b76d24ade
commit c432c45343
8 changed files with 829 additions and 39 deletions

View File

@@ -13,17 +13,6 @@ export async function GET(req: NextRequest) {
const experimentId = searchParams.get('experimentId');
const storeMode = process.env.NEXT_PUBLIC_STORE_MODE || 'shop';
// log in dev
if (process.env.NODE_ENV === 'development') {
console.log('[pricing-api]', {
productId,
sessionId,
experimentId,
storeMode,
timestamp: new Date().toISOString(),
});
}
if (!productId) {
return NextResponse.json(
{ error: 'productId is required' },
@@ -34,11 +23,46 @@ export async function GET(req: NextRequest) {
// stub: call external pricing provider (random for now)
const basePrice = 100 + Math.random() * 900; // 100-1000 range
const price = Math.round(basePrice * 100) / 100;
const timestamp = new Date().toISOString();
// log price to kafka for elasticity computation
if (sessionId) {
const backendUrl = process.env.BACKEND_URL || 'http://localhost:5000';
try {
await fetch(`${backendUrl}/api/kafka/price-log`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
productId,
price,
sessionId,
experimentId: experimentId || undefined,
storeMode,
ts: timestamp,
}),
});
} catch (err) {
console.error('[price-log-error]', err);
// don't fail the pricing request if logging fails
}
}
// log in dev
if (process.env.NODE_ENV === 'development') {
console.log('[pricing-api]', {
productId,
sessionId,
experimentId,
storeMode,
price,
timestamp,
});
}
const response: PricingResponse = {
price,
currency: 'EUR',
cachedAt: new Date().toISOString(),
cachedAt: timestamp,
};
return NextResponse.json(response);