( req: NextRequest, )
| 71 | }; |
| 72 | |
| 73 | const handleMarkdownRequest = async ( |
| 74 | req: NextRequest, |
| 75 | ): Promise<NextResponse> => { |
| 76 | const deviceId = req.cookies.get('da2')?.value ?? generateTrackingId(); |
| 77 | const wall = await evaluateAgentSignupWall(deviceId); |
| 78 | const { allocation } = wall; |
| 79 | if (allocation) { |
| 80 | after(async () => { |
| 81 | await trackAgentSignupWallAllocation(deviceId, allocation); |
| 82 | }); |
| 83 | } |
| 84 | if (!wall.enabled) { |
| 85 | return getMarkdownResponse(req); |
| 86 | } |
| 87 | |
| 88 | const hasToken = await hasValidAgentMarkdownToken( |
| 89 | req.headers.get('authorization'), |
| 90 | ); |
| 91 | if (hasToken) { |
| 92 | return getMarkdownResponse(req); |
| 93 | } |
| 94 | |
| 95 | return new NextResponse(getAgentSignupRequiredBody(), { |
| 96 | status: 401, |
| 97 | headers: { |
| 98 | 'cache-control': 'private, no-store', |
| 99 | 'content-type': 'text/markdown; charset=utf-8', |
| 100 | }, |
| 101 | }); |
| 102 | }; |
| 103 | |
| 104 | const isMarkdownRequest = (req: NextRequest): boolean => { |
| 105 | const { pathname } = req.nextUrl; |
no test coverage detected