stack/apps/backend/src/app/api/latest/route.ts
Konsti Wohlwend bae04178cc
Some checks failed
all-good: Did all the other checks pass? / all-good (push) Has been cancelled
Ensure Prisma migrations are in sync with the schema / check_prisma_migrations (22.x) (push) Has been cancelled
Docker Emulator Test / docker (push) Has been cancelled
Docker Server Build and Push / Docker Build and Push Server (push) Has been cancelled
Docker Server Test / docker (push) Has been cancelled
Runs E2E API Tests / build (22.x) (push) Has been cancelled
Lint & build / lint_and_build (latest) (push) Has been cancelled
Preview Docs / run (push) Has been cancelled
Dev Environment Test / restart-dev-and-test (push) Has been cancelled
Run setup tests / setup-tests (push) Has been cancelled
TOC Generator / TOC Generator (push) Has been cancelled
Endpoints branching (#659)
Co-authored-by: Zai Shi <zaishi00@outlook.com>
Co-authored-by: moritz <moritsch@student.ethz.ch>
2025-04-30 15:39:47 -07:00

54 lines
2.3 KiB
TypeScript

import { createSmartRouteHandler } from "@/route-handlers/smart-route-handler";
import { adaptSchema, projectIdSchema, yupNumber, yupObject, yupString, yupTuple } from "@stackframe/stack-shared/dist/schema-fields";
import { deindent, typedCapitalize } from "@stackframe/stack-shared/dist/utils/strings";
export const GET = createSmartRouteHandler({
metadata: {
summary: "/api/v1",
description: "Returns a human-readable message with some useful information about the API.",
tags: [],
},
request: yupObject({
auth: yupObject({
type: adaptSchema,
user: adaptSchema,
project: adaptSchema,
}).nullable(),
query: yupObject({
// No query parameters
// empty object means that it will fail if query parameters are given regardless
}),
headers: yupObject({
// we list all automatically parsed headers here so the documentation shows them
"X-Stack-Project-Id": yupTuple([projectIdSchema]),
"X-Stack-Branch-Id": yupTuple([projectIdSchema]).optional(),
"X-Stack-Access-Type": yupTuple([yupString().oneOf(["client", "server", "admin"])]),
"X-Stack-Access-Token": yupTuple([yupString()]),
"X-Stack-Refresh-Token": yupTuple([yupString()]),
"X-Stack-Publishable-Client-Key": yupTuple([yupString()]),
"X-Stack-Secret-Server-Key": yupTuple([yupString()]),
"X-Stack-Super-Secret-Admin-Key": yupTuple([yupString()]),
}),
method: yupString().oneOf(["GET"]).defined(),
}),
response: yupObject({
statusCode: yupNumber().oneOf([200]).defined(),
bodyType: yupString().oneOf(["text"]).defined(),
body: yupString().defined().meta({ openapiField: { exampleValue: "Welcome to the Stack API endpoint! Please refer to the documentation at https://docs.stack-auth.com/\n\nAuthentication: None" } }),
}),
handler: async (req) => {
return {
statusCode: 200,
bodyType: "text",
body: deindent`
Welcome to the Stack API endpoint! Please refer to the documentation at https://docs.stack-auth.com.
Authentication: ${!req.auth ? "None" : typedCapitalize(req.auth.type) + "\n" + deindent`
${" "}Project: ${req.auth.project.id}
${" "}User: ${req.auth.user ? req.auth.user.primary_email ?? req.auth.user.id : "None"}
`}
`,
};
},
});