mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-13 21:01:21 +08:00
Init API Keys docs updates.
<!-- ELLIPSIS_HIDDEN -->
----
> [!IMPORTANT]
> Add documentation and API handlers for creating and managing user and
team API keys.
>
> - **API Handlers**:
> - Updated `createApiKeyHandlers` in `handlers.tsx` to include metadata
for API key creation and validation.
> - `create` and `check` handlers now have descriptions, summaries, and
tags for API keys.
> - **Documentation**:
> - Added `api-keys.mdx` to explain API key creation, management, and
usage for users and teams.
> - Updated `docs-template.yml` to include API Keys in the navigation.
> - Added `sdk/types/api-key.mdx` for detailed API key type definitions
and usage.
> - Updated `sdk/types/team.mdx` and `sdk/types/user.mdx` to include API
key functions for teams and users.
>
> <sup>This description was created by </sup>[<img alt="Ellipsis"
src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=stack-auth%2Fstack-auth&utm_source=github&utm_medium=referral)<sup>
for 369b06e7a4. You can
[customize](https://app.ellipsis.dev/stack-auth/settings/summaries) this
summary. It will automatically update as commits are pushed.</sup>
<!-- ELLIPSIS_HIDDEN -->
---------
Co-authored-by: Konsti Wohlwend <n2d4xc@gmail.com>
52 lines
2.4 KiB
TypeScript
52 lines
2.4 KiB
TypeScript
import { parseOpenAPI, parseWebhookOpenAPI } from '@/lib/openapi';
|
|
import { isSmartRouteHandler } from '@/route-handlers/smart-route-handler';
|
|
import { webhookEvents } from '@stackframe/stack-shared/dist/interface/webhooks';
|
|
import { writeFileSyncIfChanged } from '@stackframe/stack-shared/dist/utils/fs';
|
|
import { HTTP_METHODS } from '@stackframe/stack-shared/dist/utils/http';
|
|
import { typedKeys } from '@stackframe/stack-shared/dist/utils/objects';
|
|
import { glob } from 'glob';
|
|
import path from 'path';
|
|
import yaml from 'yaml';
|
|
|
|
async function main() {
|
|
console.log("Started docs schema generator");
|
|
|
|
for (const audience of ['client', 'server', 'admin'] as const) {
|
|
const filePathPrefix = path.resolve(process.platform === "win32" ? "apps/src/app/api/latest" : "src/app/api/latest");
|
|
const importPathPrefix = "@/app/api/latest";
|
|
const filePaths = [...await glob(filePathPrefix + "/**/route.{js,jsx,ts,tsx}")];
|
|
|
|
const openApiSchemaObject = parseOpenAPI({
|
|
endpoints: new Map(await Promise.all(filePaths.map(async (filePath) => {
|
|
if (!filePath.startsWith(filePathPrefix)) {
|
|
throw new Error(`Invalid file path: ${filePath}`);
|
|
}
|
|
const suffix = filePath.slice(filePathPrefix.length);
|
|
const midfix = suffix.slice(0, suffix.lastIndexOf("/route."));
|
|
const importPath = `${importPathPrefix}${suffix}`;
|
|
const urlPath = midfix.replaceAll("[", "{").replaceAll("]", "}").replaceAll(/\/\(.*\)/g, "");
|
|
const myModule = require(importPath);
|
|
const handlersByMethod = new Map(
|
|
typedKeys(HTTP_METHODS).map(method => [method, myModule[method]] as const)
|
|
.filter(([_, handler]) => isSmartRouteHandler(handler))
|
|
);
|
|
return [urlPath, handlersByMethod] as const;
|
|
}))),
|
|
audience,
|
|
});
|
|
const openAPISchema = yaml.stringify(openApiSchemaObject);
|
|
writeFileSyncIfChanged(`../mcp-server/openapi/${audience}.json`, JSON.stringify(openApiSchemaObject, null, 2));
|
|
writeFileSyncIfChanged(`../../docs/fern/openapi/${audience}.yaml`, openAPISchema);
|
|
|
|
const webhookOpenAPISchema = yaml.stringify(parseWebhookOpenAPI({
|
|
webhooks: webhookEvents,
|
|
}));
|
|
writeFileSyncIfChanged(`../../docs/fern/openapi/webhooks.yaml`, webhookOpenAPISchema);
|
|
}
|
|
console.log("Successfully updated docs schemas");
|
|
}
|
|
main().catch((...args) => {
|
|
console.error(`ERROR! Could not update OpenAPI schema`, ...args);
|
|
process.exit(1);
|
|
});
|