{"version":3,"file":"settings.mjs","names":[],"sources":["../../../../../../../src/astro/routes/api/admin/plugins/[id]/settings.ts"],"sourcesContent":["/**\n * Plugin settings endpoint (auto-generated settings UI)\n *\n * GET /_emdash/api/admin/plugins/:id/settings - Get schema + current values (secrets masked)\n * PUT /_emdash/api/admin/plugins/:id/settings - Update values\n */\n\nimport type { APIRoute } from \"astro\";\nimport { z } from \"zod\";\n\nimport { requirePerm } from \"#api/authorize.js\";\nimport { apiError } from \"#api/error.js\";\nimport {\n\tgetPluginSettingsSchema,\n\thandlePluginSettingsGet,\n\thandlePluginSettingsUpdate,\n} from \"#api/handlers/plugin-settings.js\";\nimport { unwrapResult } from \"#api/index.js\";\nimport { isParseError, parseBody } from \"#api/parse.js\";\n\nexport const prerender = false;\n\nconst updateBody = z.object({\n\tvalues: z.record(z.string(), z.unknown()),\n});\n\nexport const GET: APIRoute = async ({ params, locals }) => {\n\tconst { emdash, user } = locals;\n\tconst { id } = params;\n\n\tif (!emdash?.db) {\n\t\treturn apiError(\"NOT_CONFIGURED\", \"EmDash is not initialized\", 500);\n\t}\n\n\tconst denied = requirePerm(user, \"plugins:manage\");\n\tif (denied) return denied;\n\n\tif (!id) {\n\t\treturn apiError(\"INVALID_REQUEST\", \"Plugin ID required\", 400);\n\t}\n\n\tconst schema =\n\t\tgetPluginSettingsSchema(emdash.configuredPlugins, emdash.sandboxedPluginEntries, id) ??\n\t\temdash.getRuntimePluginSettingsSchema(id);\n\tif (schema === null) {\n\t\treturn apiError(\"NOT_FOUND\", `Plugin not found: ${id}`, 404);\n\t}\n\n\tconst result = await handlePluginSettingsGet(emdash.db, id, schema);\n\treturn unwrapResult(result);\n};\n\nexport const PUT: APIRoute = async ({ params, request, locals }) => {\n\tconst { emdash, user } = locals;\n\tconst { id } = params;\n\n\tif (!emdash?.db) {\n\t\treturn apiError(\"NOT_CONFIGURED\", \"EmDash is not initialized\", 500);\n\t}\n\n\tconst denied = requirePerm(user, \"plugins:manage\");\n\tif (denied) return denied;\n\n\tif (!id) {\n\t\treturn apiError(\"INVALID_REQUEST\", \"Plugin ID required\", 400);\n\t}\n\n\tconst schema =\n\t\tgetPluginSettingsSchema(emdash.configuredPlugins, emdash.sandboxedPluginEntries, id) ??\n\t\temdash.getRuntimePluginSettingsSchema(id);\n\tif (schema === null) {\n\t\treturn apiError(\"NOT_FOUND\", `Plugin not found: ${id}`, 404);\n\t}\n\n\tconst body = await parseBody(request, updateBody);\n\tif (isParseError(body)) return body;\n\n\tconst result = await handlePluginSettingsUpdate(emdash.db, id, schema, body.values);\n\treturn unwrapResult(result);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBA,MAAa,YAAY;AAEzB,MAAM,aAAa,EAAE,OAAO,EAC3B,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,SAAS,CAAC,EACzC,CAAC;AAEF,MAAa,MAAgB,OAAO,EAAE,QAAQ,aAAa;CAC1D,MAAM,EAAE,QAAQ,SAAS;CACzB,MAAM,EAAE,OAAO;AAEf,KAAI,CAAC,QAAQ,GACZ,QAAO,SAAS,kBAAkB,6BAA6B,IAAI;CAGpE,MAAM,SAAS,YAAY,MAAM,iBAAiB;AAClD,KAAI,OAAQ,QAAO;AAEnB,KAAI,CAAC,GACJ,QAAO,SAAS,mBAAmB,sBAAsB,IAAI;CAG9D,MAAM,SACL,wBAAwB,OAAO,mBAAmB,OAAO,wBAAwB,GAAG,IACpF,OAAO,+BAA+B,GAAG;AAC1C,KAAI,WAAW,KACd,QAAO,SAAS,aAAa,qBAAqB,MAAM,IAAI;AAI7D,QAAO,aADQ,MAAM,wBAAwB,OAAO,IAAI,IAAI,OAAO,CACxC;;AAG5B,MAAa,MAAgB,OAAO,EAAE,QAAQ,SAAS,aAAa;CACnE,MAAM,EAAE,QAAQ,SAAS;CACzB,MAAM,EAAE,OAAO;AAEf,KAAI,CAAC,QAAQ,GACZ,QAAO,SAAS,kBA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