{"version":3,"file":"statusList.mjs","names":["e: any"],"sources":["../../../src/http/endpoints/statusList.ts"],"sourcesContent":["import type { Router, Response } from 'express'\nimport type { OpenBadgesHttpModuleConfig } from '../OpenBadgesHttpModuleConfig'\nimport type { OpenBadgesHttpModule } from '../OpenBadgesHttpModule'\nimport type { ObRequest } from '../router'\n\nimport { getRequestContext, sendError, sendJson } from '../router'\nimport { RevocationService } from '../../services/RevocationService'\nimport { ProofService } from '../../services/ProofService'\n\n/**\n * Configure the StatusList2021 endpoint\n *\n * GET /status-list/:id - Returns a signed StatusList2021Credential\n * POST /status-list/:id/status - Update status for a credential index (issuer only)\n */\nexport function configureStatusListEndpoint(\n  router: Router,\n  config: OpenBadgesHttpModuleConfig,\n  _module: OpenBadgesHttpModule\n) {\n  const basePath = config.statusListPath\n\n  // GET /status-list/:id - Return signed StatusList2021Credential\n  router.get(`${basePath}/:id`, async (req: ObRequest, res: Response) => {\n    try {\n      const { agentContext } = getRequestContext(req)\n      const listId = String(req.params.id)\n\n      const revocationService = agentContext.dependencyManager.resolve(RevocationService)\n      const proofService = agentContext.dependencyManager.resolve(ProofService)\n\n      // Get the status list record\n      const record = await revocationService.getStatusList(agentContext, listId)\n      if (!record) {\n        return sendError(res, 404, 'not_found', `Status list not found: ${listId}`)\n      }\n\n      // Build the unsigned StatusList2021Credential\n      const unsignedCredential = revocationService.buildStatusListCredential(record)\n\n      // Sign the credential\n      const verificationMethod = `${record.issuerDid}#key-1`\n      const signedCredential = await proofService.sign(agentContext, unsignedCredential, {\n        id: verificationMethod,\n        controller: record.issuerDid,\n      })\n\n      // Return with proper content type\n      return sendJson(res, signedCredential, 200, 'application/vc+ld+json')\n    } catch (e: any) {\n      try { getRequestContext(req).agentContext.config.logger.error('[OB][StatusList] GET error', { error: e?.message || String(e) }) } catch {}\n      return sendError(res, 500, 'server_error', e?.message || 'Unexpected error')\n    }\n  })\n\n  // POST /status-list/:id/status - Update status for an index (issuer operation)\n  router.post(`${basePath}/:id/status`, async (req: ObRequest, res: Response) => {\n    try {\n      const { agentContext } = getRequestContext(req)\n      const listId = String(req.params.id)\n      const { index, status } = req.body as { index?: number; status?: boolean }\n\n      if (typeof index !== 'number' || typeof status !== 'boolean') {\n        return sendError(res, 400, 'invalid_request', 'Missing required fields: index (number), status (boolean)')\n      }\n\n      const revocationService = agentContext.dependencyManager.resolve(RevocationService)\n\n      // Update the status\n      await revocationService.setStatus(agentContext, { listId, index, status })\n\n      return sendJson(res, { success: true, listId, index, status: status ? 'revoked' : 'active' })\n    } catch (e: any) {\n      try { getRequestContext(req).agentContext.config.logger.error('[OB][StatusList] POST error', { error: e?.message || String(e) }) } catch {}\n      if (e?.message?.includes('not found')) {\n        return sendError(res, 404, 'not_found', e.message)\n      }\n      return sendError(res, 500, 'server_error', e?.message || 'Unexpected error')\n    }\n  })\n\n  // POST /status-list - Create a new status list\n  router.post(basePath, async (req: ObRequest, res: Response) => {\n    try {\n      const { agentContext } = getRequestContext(req)\n      const { listId, issuerDid, purpose, capacity } = req.body as {\n        listId?: string\n        issuerDid?: string\n        purpose?: 'revocation' | 'suspension'\n        capacity?: number\n      }\n\n      if (!listId || !issuerDid) {\n        return sendError(res, 400, 'invalid_request', 'Missing required fields: listId, issuerDid')\n      }\n\n      const revocationService = agentContext.dependencyManager.resolve(RevocationService)\n\n      const record = await revocationService.createStatusList(agentContext, {\n        listId,\n        issuerDid,\n        purpose: purpose || 'revocation',\n        capacity,\n        baseUrl: config.baseUrl,\n      })\n\n      return sendJson(res, {\n        success: true,\n        listId: record.listId,\n        purpose: record.purpose,\n        capacity: record.capacity,\n        statusListCredentialUrl: `${config.baseUrl}${basePath}/${listId}`,\n      }, 201)\n    } catch (e: any) {\n      try { getRequestContext(req).agentContext.config.logger.error('[OB][StatusList] POST create error', { error: e?.message || String(e) }) } catch {}\n      return sendError(res, 500, 'server_error', e?.message || 'Unexpected error')\n    }\n  })\n}\n"],"mappings":";;;;;aAKkE;;;;;;;AAUlE,SAAgB,4BACd,QACA,QACA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