EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
route.ts
Go to the documentation of this file.
1import { NextRequest, NextResponse } from 'next/server';
2import { fieldpineServerApi } from '@/lib/server/fieldpineApi';
3import { getRequestContext, validateApiAccess } from '@/lib/server/sessionUtils';
4
5/**
6 * Serial Items Endpoint (ELINK API)
7 * GET /api/v1/buck/serial-items
8 *
9 * Uses ELINK API (retailmax.elink.serialitem.list)
10 * Security: Retail stores can access this (ELINK only)
11 */
12export async function GET(request: NextRequest) {
13 try {
14 const context = await getRequestContext(request);
15 if (!context || !context.isAuthenticated) {
16 return NextResponse.json(
17 { error: 'Authentication required' },
18 { status: 401 }
19 );
20 }
21
22 const apiAccessValidation = validateApiAccess(context, 'elink');
23 if (!apiAccessValidation.valid) {
24 return NextResponse.json(
25 { error: apiAccessValidation.error, code: apiAccessValidation.errorCode },
26 { status: 403 }
27 );
28 }
29
30 const buckParams: Record<string, string> = {
31 '3': 'retailmax.elink.serialitem.list',
32 '99': Math.random().toString()
33 };
34
35 // Use store-specific URL for API calls
36 const result = await fieldpineServerApi.buckApiCall(buckParams, context.session.apiKey, context.store.url);
37
38 return NextResponse.json({
39 success: true,
40 data: result,
41 source: 'elink'
42 });
43
44 } catch (error: any) {
45 console.error('[Serial Items API] Error:', error);
46 return NextResponse.json(
47 { error: error.message || 'Failed to fetch serial items' },
48 { status: 500 }
49 );
50 }
51}