feat(api): migrate GET /api/instagram/comments

Closed
AR
7mo ago
+326-0

Migrates the legacy Express GET /api/instagram/comments endpoint into mono/api as a flat Next.js route. Validator owns auth via validateAuthContext; handler returns { runId, datasetId } for wire parity with the legacy ApifyScraperResult. Webhook URL stays pointed at chat.recoupable.com/api/apify per the migration plan.

Test plan

  • 401 on Vercel preview without auth
  • 400 on Vercel preview without postUrls
  • 200 on Vercel preview with valid postUrls (returns runId + datasetId)
  • Unit tests (handler + validator) green

Summary by cubic

Migrated the legacy Express GET /api/instagram/comments to a flat Next.js route. Preserves the response shape ({ runId, datasetId}) and keeps the webhook target at chat.recoupable.com/api/apify, while adding validation, auth, and safer errors.

  • New Features
    • Route: GET /api/instagram/comments with CORS preflight, dynamic: "force-dynamic", maxDuration = 30 (uses next/server).
    • Validation: supports postUrls (repeatable), resultsLimit (default 10000), isNewestComments, webhooks (base64 JSON array); 400 on invalid input.
    • Auth: validateAuthContext enforces API key; 401 on failure.
    • Scraping: starts Instagram Comments actor via apify-client; returns runId and datasetId; masks internal errors.
    • Tests: unit tests for handler and validator using vitest.