Source: Router/events/controller.js

// @ts-check
/**
 * Event replay controller.
 * @import {ExpressRequestAuthorized, ExpressResponse} from '../../types.js'
 */

import { sendOk, sendErrorFrom } from '../../utils/apiEnvelope.js';
import * as service from './service.js';

/**
 * @swagger
 * /api/kpe20/events:
 *   get:
 *     summary: Replay events (bootstrap and catch-up)
 *     description: |
 *       Documented service access to eventLog for the rights-sync bot. Events
 *       are strictly ordered by an opaque monotonic cursor. Live and replay
 *       events share the same envelope.
 *     tags:
 *       - Events
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: query
 *         name: organization
 *         required: true
 *         schema:
 *           type: string
 *         description: Organization UID
 *       - in: query
 *         name: after
 *         required: false
 *         schema:
 *           type: string
 *         description: Opaque cursor returned by a previous page
 *       - in: query
 *         name: limit
 *         required: false
 *         schema:
 *           type: integer
 *           minimum: 1
 *           maximum: 1000
 *         description: Page size (default 100)
 *     responses:
 *       200:
 *         description: Event page
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                 result:
 *                   type: object
 *                   properties:
 *                     events:
 *                       type: array
 *                       items:
 *                         type: object
 *                         properties:
 *                           schema_version:
 *                             type: integer
 *                           cursor:
 *                             type: string
 *                           event_key:
 *                             type: string
 *                           payload:
 *                             type: object
 *                     next_cursor:
 *                       type: string
 *                     has_more:
 *                       type: boolean
 *                     high_watermark:
 *                       type: string
 *                 request_id:
 *                   type: string
 *                 schema_version:
 *                   type: integer
 *       400:
 *         description: Invalid organization, cursor or limit
 *       410:
 *         description: Cursor older than the retained event history
 */
/**
 * GET /events?organization=<uid>&after=<cursor>&limit=<n>
 * @param {ExpressRequestAuthorized} req
 * @param {ExpressResponse} res
 */
export const getEvents = async (req, res) => {
    try {
        const result = await service.replayEvents(req);
        sendOk(res, result.result);
    } catch (e) {
        sendErrorFrom(res, e);
    }
};