{"version":3,"file":"ContextService.mjs","names":["ContextService","out: Record<string, any>"],"sources":["../../src/services/ContextService.ts"],"sourcesContent":["import { injectable } from '@credo-ts/core'\n\ntype LoaderResult = { contextUrl: null; documentUrl: string; document: any }\n\n@injectable()\nexport class ContextService {\n  private cache = new Map<string, any>()\n  private allowNetwork = true\n\n  public addCached(url: string, document: any) {\n    this.cache.set(url, document)\n  }\n\n  public setAllowNetwork(allow: boolean) {\n    this.allowNetwork = allow\n  }\n\n  public getDocumentLoader() {\n    const self = this\n    return async function documentLoader(url: string): Promise<LoaderResult> {\n      if (self.cache.has(url)) {\n        return { contextUrl: null, documentUrl: url, document: self.cache.get(url) }\n      }\n      if (!self.allowNetwork) throw new Error(`Context not cached: ${url}`)\n      // pin to https and specific hosts by default; allow did:web document resolution via https\n      const allowed = url.startsWith('https://www.w3.org/') || url.startsWith('https://purl.imsglobal.org/') || url.startsWith('https://w3id.org/') || url.startsWith('https://')\n      if (!allowed) throw new Error(`Blocked remote context: ${url}`)\n      const res = await fetch(url)\n      if (!res.ok) throw new Error(`Failed to fetch context ${url}: ${res.status}`)\n      const json = await res.json()\n      self.cache.set(url, json)\n      return { contextUrl: null, documentUrl: url, document: json }\n    }\n  }\n\n  // Export cached contexts for external runners (testing)\n  public exportCache(): Record<string, any> {\n    const out: Record<string, any> = {}\n    for (const [k, v] of this.cache.entries()) out[k] = v\n    return out\n  }\n}\n\n"],"mappings":";;;;;AAKO,2BAAMA,iBAAe;;OAClB,wBAAQ,IAAI,KAAkB;OAC9B,eAAe;;CAEvB,AAAO,UAAU,KAAa,UAAe;AAC3C,OAAK,MAAM,IAAI,KAAK,SAAS;;CAG/B,AAAO,gBAAgB,OAAgB;AACrC,OAAK,eAAe;;CAGtB,AAAO,oBAAoB;EACzB,MAAM,OAAO;AACb,SAAO,eAAe,eAAe,KAAoC;AACvE,OAAI,KAAK,MAAM,IAAI,IAAI,CACrB,QAAO;IAAE,YAAY;IAAM,aAAa;IAAK,UAAU,KAAK,MAAM,IAAI,IAAI;IAAE;AAE9E,OAAI,CAAC,KAAK,aAAc,OAAM,IAAI,MAAM,uBAAuB,MAAM;AAGrE,OAAI,EADY,IAAI,WAAW,sBAAsB,IAAI,IAAI,WAAW,8BAA8B,IAAI,IAAI,WAAW,oBAAoB,IAAI,IAAI,WAAW,WAAW,EAC7J,OAAM,IAAI,MAAM,2BAA2B,MAAM;GAC/D,MAAM,MAAM,MAAM,MAAM,IAAI;AAC5B,OAAI,CAAC,IAAI,GAAI,OAAM,IAAI,MAAM,2BAA2B,IAAI,IAAI,IAAI,SAAS;GAC7E,MAAM,OAAO,MAAM,IAAI,MAAM;AAC7B,QAAK,MAAM,IAAI,KAAK,KAAK;AACzB,UAAO;IAAE,YAAY;IAAM,aAAa;IAAK,UAAU;IAAM;;;CAKjE,AAAO,cAAmC;EACxC,MAAMC,MAA2B,EAAE;AACnC,OAAK,MAAM,CAAC,GAAG,MAAM,KAAK,MAAM,SAAS,CAAE,KAAI,KAAK;AACpD,SAAO;;;6BAnCV,YAAY"}