{"version":3,"file":"consent.mjs","names":[],"sources":["../../../src/http/endpoints/consent.ts"],"sourcesContent":["import type { Router, Response } from 'express'\nimport type { OpenBadgesHttpModule } from '../OpenBadgesHttpModule'\nimport type { ObRequest } from '../router'\n\nimport { getRequestContext, sendError, sendJson } from '../router'\nimport { OpenBadgesConsentRepository } from '../../repository/OpenBadgesConsentRepository'\n\nexport function configureConsentEndpoint(router: Router, module: OpenBadgesHttpModule) {\n  router.post(module.config.consentPath, async (req: ObRequest, res: Response) => {\n    const { agentContext } = getRequestContext(req)\n    const client_id = String(req.body?.client_id ?? '')\n    const subject = String(req.body?.subject ?? module.config.defaultSubjectId ?? '')\n    if (!client_id || !subject) return sendError(res, 400, 'invalid_request', 'client_id and subject are required')\n    const repo = agentContext.dependencyManager.resolve(OpenBadgesConsentRepository)\n    const existing = await repo.findByClientAndSubject(agentContext, client_id, subject)\n    if (existing) return sendJson(res, { ok: true, alreadyGranted: true })\n    await repo.save(agentContext, {\n      clientId: client_id,\n      subject,\n      grantedAt: new Date(),\n    } as any)\n    return sendJson(res, { ok: true })\n  })\n}\n\n"],"mappings":";;;;;;AAOA,SAAgB,yBAAyB,QAAgB,QAA8B;AACrF,QAAO,KAAK,OAAO,OAAO,aAAa,OAAO,KAAgB,QAAkB;EAC9E,MAAM,EAAE,iBAAiB,kBAAkB,IAAI;EAC/C,MAAM,YAAY,OAAO,IAAI,MAAM,aAAa,GAAG;EACnD,MAAM,UAAU,OAAO,IAAI,MAAM,WAAW,OAAO,OAAO,oBAAoB,GAAG;AACjF,MAAI,CAAC,aAAa,CAAC,QAAS,QAAO,UAAU,KAAK,KAAK,mBAAmB,qCAAqC;EAC/G,MAAM,OAAO,aAAa,kBAAkB,QAAQ,4BAA4B;AAEhF,MADiB,MAAM,KAAK,uBAAuB,cAAc,WAAW,QAAQ,CACtE,QAAO,SAAS,KAAK;GAAE,IAAI;GAAM,gBAAgB;GAAM,CAAC;AACtE,QAAM,KAAK,KAAK,cAAc;GAC5B,UAAU;GACV;GACA,2BAAW,IAAI,MAAM;GACtB,CAAQ;AACT,SAAO,SAAS,KAAK,EAAE,IAAI,MAAM,CAAC;GAClC;;;cAlB8D;mCACwB"}