{"version":3,"file":"profile.mjs","names":["e: any"],"sources":["../../../src/http/endpoints/profile.ts"],"sourcesContent":["import type { Router, Response } from 'express'\nimport type { OpenBadgesHttpModuleConfig } from '../OpenBadgesHttpModuleConfig'\nimport type { ObRequest } from '../router'\nimport type { OpenBadgesHttpModule } from '../OpenBadgesHttpModule'\n\nimport { bearerAuth, requireScopes } from '../middleware/auth'\nimport { getRequestContext, sendError, sendJson } from '../router'\nimport { OpenBadgesProfileRepository } from '../../repository/OpenBadgesProfileRepository'\nimport { OpenBadgesProfileRecord } from '../../repository/OpenBadgesProfileRecord'\n\nconst OB_READ = 'https://purl.imsglobal.org/spec/ob/v3p0/scope/readonly'\nconst OB_WRITE = 'https://purl.imsglobal.org/spec/ob/v3p0/scope/replace'\n\nexport function configureProfileEndpoints(router: Router, config: OpenBadgesHttpModuleConfig, module: OpenBadgesHttpModule) {\n  // GET profile by subject\n  router.get(config.profilePath, bearerAuth(module), requireScopes([OB_READ]), async (req: ObRequest, res: Response) => {\n    try {\n      const { agentContext } = getRequestContext(req)\n      const auth = (req.requestContext as any).auth\n      const repo = agentContext.dependencyManager.resolve(OpenBadgesProfileRepository)\n      try {\n        const rec = await repo.findByProfileId(agentContext, auth.subject)\n        if (!rec) return sendError(res, 404, 'not_found', 'Profile not found')\n        return sendJson(res, rec.profile)\n      } catch {\n        return sendError(res, 404, 'not_found', 'Profile not found')\n      }\n    } catch (e: any) {\n      return sendError(res, 500, 'server_error', e?.message || 'Unexpected error')\n    }\n  })\n\n  // PUT profile\n  router.put(config.profilePath, bearerAuth(module), requireScopes([OB_WRITE]), async (req: ObRequest, res: Response) => {\n    try {\n      const { agentContext } = getRequestContext(req)\n      const auth = (req.requestContext as any).auth\n      const repo = agentContext.dependencyManager.resolve(OpenBadgesProfileRepository)\n      const body = req.body\n      if (!body || typeof body !== 'object') return sendError(res, 400, 'invalid_request', 'Missing profile body')\n\n      try {\n        const existing = await repo.findByProfileId(agentContext, auth.subject)\n        if (existing) {\n          existing.profile = body\n          await repo.update(agentContext, existing)\n          return sendJson(res, { updated: true })\n        }\n      } catch {}\n\n      const rec = new OpenBadgesProfileRecord({ profileId: auth.subject, profile: body })\n      await repo.save(agentContext, rec)\n      return sendJson(res, { created: true }, 201)\n    } catch (e: any) {\n      return sendError(res, 500, 'server_error', e?.message || 'Unexpected error')\n    }\n  })\n}\n"],"mappings":";;;;;;aAMkE;AAIlE,MAAM,UAAU;AAChB,MAAM,WAAW;AAEjB,SAAgB,0BAA0B,QAAgB,QAAoC,QAA8B;AAE1H,QAAO,IAAI,OAAO,aAAa,WAAW,OAAO,EAAE,cAAc,CAAC,QAAQ,CAAC,EAAE,OAAO,KAAgB,QAAkB;AACpH,MAAI;GACF,MAAM,EAAE,iBAAiB,kBAAkB,IAAI;GAC/C,MAAM,OAAQ,IAAI,eAAuB;GACzC,MAAM,OAAO,aAAa,kBAAkB,QAAQ,4BAA4B;AAChF,OAAI;IACF,MAAM,MAAM,MAAM,KAAK,gBAAgB,cAAc,KAAK,QAAQ;AAClE,QAAI,CAAC,IAAK,QAAO,UAAU,KAAK,KAAK,aAAa,oBAAoB;AACtE,WAAO,SAAS,KAAK,IAAI,QAAQ;WAC3B;AACN,WAAO,UAAU,KAAK,KAAK,aAAa,oBAAoB;;WAEvDA,GAAQ;AACf,UAAO,UAAU,KAAK,KAAK,gBAAgB,GAAG,WAAW,mBAAmB;;GAE9E;AAGF,QAAO,IAAI,OAAO,aAAa,WAAW,OAAO,EAAE,cAAc,CAAC,SAAS,CAAC,EAAE,OAAO,KAAgB,QAAkB;AACrH,MAAI;GACF,MAAM,EAAE,iBAAiB,kBAAkB,IAAI;GAC/C,MAAM,OAAQ,IAAI,eAAuB;GACzC,MAAM,OAAO,aAAa,kBAAkB,QAAQ,4BAA4B;GAChF,MAAM,OAAO,IAAI;AACjB,OAAI,CAAC,QAAQ,OAAO,SAAS,SAAU,QAAO,UAAU,KAAK,KAAK,mBAAmB,uBAAuB;AAE5G,OAAI;IACF,MAAM,WAAW,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