2 * FD1 Customer Detail API Route
4 * GET /api/v1/fd1/customers/[id] - Get single customer by ID
7import { NextRequest, NextResponse } from 'next/server';
8import { getRequestContext } from '@/lib/server/sessionUtils';
9import { createFD1Client } from '@/lib/client/fd1Client';
11export async function GET(
13 { params }: { params: Promise<{ id: string }> }
16 const context = await getRequestContext(request);
18 if (!context?.session?.storeUrl) {
19 return NextResponse.json(
20 { success: false, error: 'Not authenticated' },
25 const { id } = await params;
26 const customerId = parseInt(id, 10);
28 if (isNaN(customerId)) {
29 return NextResponse.json(
30 { success: false, error: 'Invalid customer ID' },
36 const fd1Client = createFD1Client({
37 baseUrl: context.session.storeUrl!,
38 apiKey: context.session.apiKey,
43 const customer = await fd1Client.getCustomer(customerId);
46 return NextResponse.json(
47 { success: false, error: 'Customer not found' },
52 return NextResponse.json({
58 console.error('FD1 customer detail API error:', error);
59 return NextResponse.json(
62 error: error instanceof Error ? error.message : 'Failed to fetch customer',