{"version":3,"file":"index.mjs","names":[],"sources":["../../../../../../../src/astro/routes/api/admin/hooks/exclusive/index.ts"],"sourcesContent":["/**\n * Exclusive hooks list endpoint\n *\n * GET /_emdash/api/admin/hooks/exclusive\n *\n * Lists all exclusive hooks with their providers and current selections.\n * Requires admin role.\n */\n\nimport type { APIRoute } from \"astro\";\n\nimport { requirePerm } from \"#api/authorize.js\";\nimport { apiError, apiSuccess, handleError } from \"#api/error.js\";\nimport { OptionsRepository } from \"#db/repositories/options.js\";\n\nexport const prerender = false;\n\nexport const GET: APIRoute = async ({ locals }) => {\n\tconst { emdash, user } = locals;\n\n\tif (!emdash?.db) {\n\t\treturn apiError(\"NOT_CONFIGURED\", \"EmDash is not initialized\", 500);\n\t}\n\n\tconst denied = requirePerm(user, \"settings:manage\");\n\tif (denied) return denied;\n\n\ttry {\n\t\tconst pipeline = emdash.hooks;\n\t\tconst exclusiveHookNames = pipeline.getRegisteredExclusiveHooks();\n\t\tconst optionsRepo = new OptionsRepository(emdash.db);\n\n\t\tconst hooks = [];\n\t\tfor (const hookName of exclusiveHookNames) {\n\t\t\tconst providers = pipeline.getExclusiveHookProviders(hookName);\n\t\t\tconst selection = await optionsRepo.get<string>(`emdash:exclusive_hook:${hookName}`);\n\n\t\t\thooks.push({\n\t\t\t\thookName,\n\t\t\t\tproviders: providers.map((provider: { pluginId: string }) => ({\n\t\t\t\t\tpluginId: provider.pluginId,\n\t\t\t\t})),\n\t\t\t\tselectedPluginId: selection,\n\t\t\t});\n\t\t}\n\n\t\treturn apiSuccess({ items: hooks });\n\t} catch (error) {\n\t\treturn handleError(error, \"Failed to list exclusive hooks\", \"EXCLUSIVE_HOOKS_LIST_ERROR\");\n\t}\n};\n"],"mappings":";;;;;;;AAeA,MAAa,YAAY;AAEzB,MAAa,MAAgB,OAAO,EAAE,aAAa;CAClD,MAAM,EAAE,QAAQ,SAAS;AAEzB,KAAI,CAAC,QAAQ,GACZ,QAAO,SAAS,kBAAkB,6BAA6B,IAAI;CAGpE,MAAM,SAAS,YAAY,MAAM,kBAAkB;AACnD,KAAI,OAAQ,QAAO;AAEnB,KAAI;EACH,MAAM,WAAW,OAAO;EACxB,MAAM,qBAAqB,SAAS,6BAA6B;EACjE,MAAM,cAAc,IAAI,kBAAkB,OAAO,GAAG;EAEpD,MAAM,QAAQ,EAAE;AAChB,OAAK,MAAM,YAAY,oBAAoB;GAC1C,MAAM,YAAY,SAAS,0BAA0B,SAAS;GAC9D,MAAM,YAAY,MAAM,YAAY,IAAY,yBAAyB,WAAW;AAEpF,SAAM,KAAK;IACV;IACA,WAAW,UAAU,KAAK,cAAoC,EAC7D,UAAU,SAAS,UACnB,EAAE;IACH,kBAAkB;IAClB,CAAC;;AAGH,SAAO,WAAW,EAAE,OAAO,OAAO,CAAC;UAC3B,OAAO;AACf,SAAO,YAAY,OAAO,kCAAkC,6BAA6B"}