{"version":3,"file":"auth.mjs","names":[],"sources":["../../../../../src/astro/routes/api/well-known/auth.ts"],"sourcesContent":["/**\n * GET /_emdash/.well-known/auth\n *\n * Auth discovery endpoint. Returns available auth mechanisms.\n * Public, unauthenticated. Used by CLI to determine how to authenticate.\n */\n\nimport type { APIRoute } from \"astro\";\n\nimport { getAuthMode } from \"#auth/mode.js\";\nimport { OptionsRepository } from \"#db/repositories/options.js\";\n\nexport const prerender = false;\n\nexport const GET: APIRoute = async ({ locals }) => {\n\tconst { emdash } = locals;\n\n\t// Build discovery response\n\tconst config = emdash?.config;\n\tconst authMode = config ? getAuthMode(config) : null;\n\n\tconst isExternal = authMode?.type === \"external\";\n\n\t// Try to read site name from DB options\n\tlet siteName = \"EmDash\";\n\tif (emdash?.db) {\n\t\ttry {\n\t\t\tconst options = new OptionsRepository(emdash.db);\n\t\t\tsiteName = (await options.get<string>(\"emdash:site_title\")) || \"EmDash\";\n\t\t} catch {\n\t\t\t// DB may not be initialized yet\n\t\t}\n\t}\n\n\tconst response: Record<string, unknown> = {\n\t\tinstance: {\n\t\t\tname: siteName,\n\t\t\tversion: \"0.1.0\",\n\t\t},\n\t\tauth: {\n\t\t\tmode: isExternal ? \"external\" : \"passkey\",\n\t\t\t...(isExternal && authMode.type === \"external\"\n\t\t\t\t? { external_provider: authMode.entrypoint }\n\t\t\t\t: {}),\n\t\t\tmethods: {\n\t\t\t\tdevice_flow: !isExternal\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tclient_id: \"emdash-cli\",\n\t\t\t\t\t\t\tdevice_authorization_endpoint: \"/_emdash/api/oauth/device/code\",\n\t\t\t\t\t\t\ttoken_endpoint: \"/_emdash/api/oauth/device/token\",\n\t\t\t\t\t\t}\n\t\t\t\t\t: undefined,\n\t\t\t\tauthorization_code: !isExternal\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tauthorization_endpoint: \"/_emdash/oauth/authorize\",\n\t\t\t\t\t\t\ttoken_endpoint: \"/_emdash/api/oauth/token\",\n\t\t\t\t\t\t}\n\t\t\t\t\t: undefined,\n\t\t\t\tapi_tokens: true,\n\t\t\t},\n\t\t},\n\t};\n\n\treturn Response.json(response, {\n\t\theaders: {\n\t\t\t\"Cache-Control\": \"no-store\",\n\t\t},\n\t});\n};\n"],"mappings":";;;;AAYA,MAAa,YAAY;AAEzB,MAAa,MAAgB,OAAO,EAAE,aAAa;CAClD,MAAM,EAAE,WAAW;CAGnB,MAAM,SAAS,QAAQ;CACvB,MAAM,WAAW,SAAS,YAAY,OAAO,GAAG;CAEhD,MAAM,aAAa,UAAU,SAAS;CAGtC,IAAI,WAAW;AACf,KAAI,QAAQ,GACX,KAAI;AAEH,aAAY,MADI,IAAI,kBAAkB,OAAO,GAAG,CACtB,IAAY,oBAAoB,IAAK;SACxD;CAKT,MAAM,WAAoC;EACzC,UAAU;GACT,MAAM;GACN,SAAS;GACT;EACD,MAAM;GACL,MAAM,aAAa,aAAa;GAChC,GAAI,cAAc,SAAS,SAAS,aACjC,EAAE,mBAAmB,SAAS,YAAY,GAC1C,EAAE;GACL,SAAS;IACR,aAAa,CAAC,aACX;KACA,WAAW;KACX,+BAA+B;KAC/B,gBAAgB;KAChB,GACA;IACH,oBAAoB,CAAC,aAClB;KACA,wBAAwB;KACxB,gBAAgB;KAChB,GACA;IACH,YAAY;IACZ;GACD;EACD;AAED,QAAO,SAAS,KAAK,UAAU,EAC9B,SAAS,EACR,iBAAiB,YACjB,EACD,CAAC"}