(req: VercelRequest, res: VercelResponse)
| 138 | } |
| 139 | |
| 140 | export default async function handler(req: VercelRequest, res: VercelResponse) { |
| 141 | const token = process.env.GITHUB_TOKEN; |
| 142 | |
| 143 | // ── GET — fetch all features ────────────────────────────────────────────── |
| 144 | if (req.method === "GET") { |
| 145 | if (!token) { |
| 146 | res.status(200).json(readLocalFeatures()); |
| 147 | return; |
| 148 | } |
| 149 | try { |
| 150 | const { features } = await readFeatures(token); |
| 151 | res.status(200).json(features); |
| 152 | } catch { |
| 153 | res.status(502).json({ error: "Failed to load features" }); |
| 154 | } |
| 155 | return; |
| 156 | } |
| 157 | |
| 158 | // ── POST — add a new feature ────────────────────────────────────────────── |
| 159 | if (req.method === "POST") { |
| 160 | if (!token) { |
| 161 | res.status(503).json({ error: "GitHub persistence is not configured" }); |
| 162 | return; |
| 163 | } |
| 164 | |
| 165 | const parseResult = featureInputSchema.safeParse(req.body); |
| 166 | if (!parseResult.success) { |
| 167 | res.status(400).json({ error: "Invalid feature data" }); |
| 168 | return; |
| 169 | } |
| 170 | |
| 171 | const { |
| 172 | nameEn, |
| 173 | nameRu, |
| 174 | descriptionEn, |
| 175 | descriptionRu, |
| 176 | major, |
| 177 | minor, |
| 178 | patch, |
| 179 | } = parseResult.data; |
| 180 | const version = `${major}.${minor}.${patch}`; |
| 181 | const feature: Feature = { |
| 182 | id: randomUUID(), |
| 183 | nameEn, |
| 184 | nameRu, |
| 185 | descriptionEn, |
| 186 | descriptionRu, |
| 187 | version, |
| 188 | status: "in-progress", |
| 189 | notes: "", |
| 190 | }; |
| 191 | |
| 192 | try { |
| 193 | const { sha, features } = await readFeatures(token); |
| 194 | await writeFeatures( |
| 195 | token, |
| 196 | [...features, feature], |
| 197 | sha, |
nothing calls this directly
no test coverage detected