🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
feature(api): add projects api (#569)
Max Deichmannd8902d0d96fd
diff --git a/fern/apis/server/definition/projects.yml b/fern/apis/server/definition/projects.ymlnew file mode 100644index 0000000000..08ba2227b7--- /dev/null+++ b/fern/apis/server/definition/projects.yml@@ -0,0 +1,22 @@+# yaml-language-server: $schema=https://raw.githubusercontent.com/fern-api/fern/main/fern.schema.json+imports:+ commons: ./commons.yml+ pagination: ./utils/pagination.yml+service:+ auth: true+ base-path: /api/public+ endpoints:+ get:+ method: GET+ path: /projects+ response: Projects++types:+ Projects:+ properties:+ data: list<Project>++ Project:+ properties:+ id: string+ name: stringdiff --git a/generated/openapi-server/openapi.yml b/generated/openapi-server/openapi.ymlindex d26af14ebf..74469ae84c 100644--- a/generated/openapi-server/openapi.yml+++ b/generated/openapi-server/openapi.yml@@ -592,6 +592,45 @@ paths:application/json:schema: {}security: *ref_0+ /api/public/projects:+ get:+ operationId: projects_get+ tags:+ - Projects+ parameters: []+ responses:+ '200':+ description: ''+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/Projects'+ '400':+ description: ''+ content:+ application/json:+ schema: {}+ '401':+ description: ''+ content:+ application/json:+ schema: {}+ '403':+ description: ''+ content:+ application/json:+ schema: {}+ '404':+ description: ''+ content:+ application/json:+ schema: {}+ '405':+ description: ''+ content:+ application/json:+ schema: {}+ security: *ref_0/api/public/scores:post:description: Add a score to the database, upserts on id@@ -1524,6 +1563,27 @@ components:required:- data- meta+ Projects:+ title: Projects+ type: object+ properties:+ data:+ type: array+ items:+ $ref: '#/components/schemas/Project'+ required:+ - data+ Project:+ title: Project+ type: object+ properties:+ id:+ type: string+ name:+ type: string+ required:+ - id+ - nameCreateScoreRequest:title: CreateScoreRequesttype: objectdiff --git a/generated/postman/collection.json b/generated/postman/collection.jsonindex a878cfc73e..6d9000e24a 100644--- a/generated/postman/collection.json+++ b/generated/postman/collection.json@@ -513,6 +513,38 @@}]},+ {+ "_type": "container",+ "description": null,+ "name": "Projects",+ "item": [+ {+ "_type": "endpoint",+ "name": "Get",+ "request": {+ "description": null,+ "url": {+ "raw": "{{baseUrl}}/api/public/projects",+ "host": [+ "{{baseUrl}}"+ ],+ "path": [+ "api",+ "public",+ "projects"+ ],+ "query": [],+ "variable": []+ },+ "header": [],+ "method": "GET",+ "auth": null,+ "body": null+ },+ "response": []+ }+ ]+ },{"_type": "container","description": null,diff --git a/src/pages/api/public/projects.ts b/src/pages/api/public/projects.tsnew file mode 100644index 0000000000..fb12aad94e--- /dev/null+++ b/src/pages/api/public/projects.ts@@ -0,0 +1,47 @@+import { verifyAuthHeaderAndReturnScope } from "@/src/features/public-api/server/apiAuth";+import { cors, runMiddleware } from "@/src/features/public-api/server/cors";+import { prisma } from "@/src/server/db";++import { type NextApiRequest, type NextApiResponse } from "next";++export default async function handler(+ req: NextApiRequest,+ res: NextApiResponse,+) {+ await runMiddleware(req, res, cors);++ // CHECK AUTH+ const authCheck = await verifyAuthHeaderAndReturnScope(+ req.headers.authorization,+ );+ if (!authCheck.validKey)+ return res.status(401).json({+ message: authCheck.error,+ });+ // END CHECK AUTH++ if (req.method === "GET") {+ try {+ const projects = await prisma.project.findMany({+ where: {+ id: authCheck.scope.projectId,+ },+ });++ return res.status(200).json({+ data: projects.map((project) => ({+ id: project.id,+ name: project.name,+ })),+ });+ } catch (error) {+ console.error(error);+ return res.status(500).json({ message: "Internal server error" });+ }+ } else {+ console.error(+ `Method not allowed for ${req.method} on /api/public/projects`,+ );+ return res.status(405).json({ message: "Method not allowed" });+ }+}