{"version":3,"file":"serviceDescription.mjs","names":[],"sources":["../../../src/http/endpoints/serviceDescription.ts"],"sourcesContent":["import type { Router, Response } from 'express'\nimport type { OpenBadgesHttpModuleConfig } from '../OpenBadgesHttpModuleConfig'\nimport type { ObRequest } from '../router'\n\nimport { sendJson, getRequestContext } from '../router'\n\nexport function configureServiceDescriptionEndpoint(router: Router, config: OpenBadgesHttpModuleConfig) {\n  router.get(config.discoveryPath, async (req: ObRequest, res: Response) => {\n    const { agentContext } = getRequestContext(req)\n\n    const base = new URL(config.baseUrl)\n    const authUrl = new URL(config.authorizePath, config.baseUrl).toString()\n    const tokenUrl = new URL(config.tokenPath, config.baseUrl).toString()\n    const registrationUrl = new URL(config.registrationPath, config.baseUrl).toString()\n\n    const response = {\n      openapi: '3.0.0',\n      info: {\n        title: 'Open Badges 3.0 / CLR 2.0 API',\n        version: '1.0.0',\n      },\n      servers: [{ url: `${base.origin}` }],\n      components: {\n        securitySchemes: {\n          OAuth2ACG: {\n            type: 'oauth2',\n            description: 'OAuth 2.0 Authorization Code Grant authorization',\n            'x-imssf-name': config.providerName ?? agentContext.config.label ?? 'Provider',\n            'x-imssf-privacyPolicyUrl': config.privacyPolicyUrl,\n            'x-imssf-termsOfServiceUrl': config.termsOfServiceUrl,\n            'x-imssf-registrationUrl': registrationUrl,\n            'x-oauth-revocationUrl': new URL(config.revokePath, config.baseUrl).toString(),\n            'x-oauth-introspectionUrl': new URL(config.introspectPath, config.baseUrl).toString(),\n            'x-oauth-jwksUrl': new URL(config.jwksPath, config.baseUrl).toString(),\n            flows: {\n              authorizationCode: {\n                authorizationUrl: authUrl,\n                tokenUrl: tokenUrl,\n                refreshUrl: tokenUrl,\n                scopes: {\n                  'https://purl.imsglobal.org/spec/ob/v3p0/scope/readonly': 'Read-only access to credentials and profile',\n                  'https://purl.imsglobal.org/spec/ob/v3p0/scope/replace': 'Write/update access to credentials and profile',\n                  'https://purl.imsglobal.org/spec/ob/v3p0/scope/delete': 'Delete access to credentials and profile',\n                  'https://purl.imsglobal.org/spec/clr/v2p0/scope/readonly': 'Read-only CLR scope',\n                  'https://purl.imsglobal.org/spec/clr/v2p0/scope/replace': 'Write/replace CLR scope',\n                },\n              },\n            },\n          },\n        },\n      },\n    }\n\n    sendJson(res, response)\n  })\n}\n"],"mappings":";;;aAIuD;AAEvD,SAAgB,oCAAoC,QAAgB,QAAoC;AACtG,QAAO,IAAI,OAAO,eAAe,OAAO,KAAgB,QAAkB;EACxE,MAAM,EAAE,iBAAiB,kBAAkB,IAAI;EAE/C,MAAM,OAAO,IAAI,IAAI,OAAO,QAAQ;EACpC,MAAM,UAAU,IAAI,IAAI,OAAO,eAAe,OAAO,QAAQ,CAAC,UAAU;EACxE,MAAM,WAAW,IAAI,IAAI,OAAO,WAAW,OAAO,QAAQ,CAAC,UAAU;EACrE,MAAM,kBAAkB,IAAI,IAAI,OAAO,kBAAkB,OAAO,QAAQ,CAAC,UAAU;AAwCnF,WAAS,KAtCQ;GACf,SAAS;GACT,MAAM;IACJ,OAAO;IACP,SAAS;IACV;GACD,SAAS,CAAC,EAAE,KAAK,GAAG,KAAK,UAAU,CAAC;GACpC,YAAY,EACV,iBAAiB,EACf,WAAW;IACT,MAAM;IACN,aAAa;IACb,gBAAgB,OAAO,gBAAgB,aAAa,OAAO,SAAS;IACpE,4BAA4B,OAAO;IACnC,6BAA6B,OAAO;IACpC,2BAA2B;IAC3B,yBAAyB,IAAI,IAAI,OAAO,YAAY,OAAO,QAAQ,CAAC,UAAU;IAC9E,4BAA4B,IAAI,IAAI,OAAO,gBAAgB,OAAO,QAAQ,CAAC,UAAU;IACrF,mBAAmB,IAAI,IAAI,OAAO,UAAU,OAAO,QAAQ,CAAC,UAAU;IACtE,OAAO,EACL,mBAAmB;KACjB,kBAAkB;KACR;KACV,YAAY;KACZ,QAAQ;MACN,0DAA0D;MAC1D,yDAAyD;MACzD,wDAAwD;MACxD,2DAA2D;MAC3D,0DAA0D;MAC3D;KACF,EACF;IACF,EACF,EACF;GACF,CAEsB;GACvB"}