@superinterface/server 1.0.24 → 1.0.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.next/BUILD_ID +1 -1
- package/.next/build-manifest.json +2 -2
- package/.next/cache/.tsbuildinfo +1 -1
- package/.next/cache/eslint/.cache_btwyo7 +1 -1
- package/.next/fallback-build-manifest.json +2 -2
- package/.next/server/app/_not-found.html +1 -1
- package/.next/server/app/_not-found.rsc +1 -1
- package/.next/server/app/api/api-keys/[apiKeyId]/route.js +1 -1
- package/.next/server/app/api/api-keys/[apiKeyId]/route.js.nft.json +1 -1
- package/.next/server/app/api/api-keys/route.js +1 -1
- package/.next/server/app/api/api-keys/route.js.nft.json +1 -1
- package/.next/server/app/api/assistants/[assistantId]/functions/[functionId]/route.js +1 -1
- package/.next/server/app/api/assistants/[assistantId]/functions/[functionId]/route.js.nft.json +1 -1
- package/.next/server/app/api/assistants/[assistantId]/functions/route.js +1 -1
- package/.next/server/app/api/assistants/[assistantId]/functions/route.js.nft.json +1 -1
- package/.next/server/app/api/assistants/[assistantId]/initial-messages/route.js +1 -1
- package/.next/server/app/api/assistants/[assistantId]/initial-messages/route.js.nft.json +1 -1
- package/.next/server/app/api/assistants/[assistantId]/mcp-servers/[mcpServerId]/route.js +1 -1
- package/.next/server/app/api/assistants/[assistantId]/mcp-servers/[mcpServerId]/route.js.nft.json +1 -1
- package/.next/server/app/api/assistants/[assistantId]/mcp-servers/route.js +1 -1
- package/.next/server/app/api/assistants/[assistantId]/mcp-servers/route.js.nft.json +1 -1
- package/.next/server/app/api/assistants/[assistantId]/route.js +1 -1
- package/.next/server/app/api/assistants/[assistantId]/route.js.nft.json +1 -1
- package/.next/server/app/api/assistants/route.js +1 -1
- package/.next/server/app/api/assistants/route.js.nft.json +1 -1
- package/.next/server/app/api/files/[fileId]/contents/route.js +1 -1
- package/.next/server/app/api/files/[fileId]/contents/route.js.nft.json +1 -1
- package/.next/server/app/api/files/route.js +1 -1
- package/.next/server/app/api/files/route.js.nft.json +1 -1
- package/.next/server/app/api/messages/route.js +1 -1
- package/.next/server/app/api/messages/route.js.nft.json +1 -1
- package/.next/server/app/api/providers/[modelProviderId]/assistants/route.js +1 -1
- package/.next/server/app/api/providers/[modelProviderId]/assistants/route.js.nft.json +1 -1
- package/.next/server/app/api/providers/[modelProviderId]/models/route.js +1 -1
- package/.next/server/app/api/providers/[modelProviderId]/models/route.js.nft.json +1 -1
- package/.next/server/app/api/providers/[modelProviderId]/route.js +1 -1
- package/.next/server/app/api/providers/[modelProviderId]/route.js.nft.json +1 -1
- package/.next/server/app/api/providers/route.js +1 -1
- package/.next/server/app/api/providers/route.js.nft.json +1 -1
- package/.next/server/app/api/tasks/[taskId]/route.js +1 -1
- package/.next/server/app/api/tasks/[taskId]/route.js.nft.json +1 -1
- package/.next/server/app/api/tasks/callback/route.js +1 -1
- package/.next/server/app/api/tasks/callback/route.js.nft.json +1 -1
- package/.next/server/app/api/tasks/route.js +1 -1
- package/.next/server/app/api/tasks/route.js.nft.json +1 -1
- package/.next/server/app/api/threads/runs/submit-client-tool-outputs/route.js +1 -1
- package/.next/server/app/api/threads/runs/submit-client-tool-outputs/route.js.nft.json +1 -1
- package/.next/server/app/api/workspaces/[workspaceId]/route.js +1 -1
- package/.next/server/app/api/workspaces/[workspaceId]/route.js.nft.json +1 -1
- package/.next/server/app/api/workspaces/route.js +1 -1
- package/.next/server/app/api/workspaces/route.js.nft.json +1 -1
- package/.next/server/app/index.html +1 -1
- package/.next/server/app/index.rsc +1 -1
- package/.next/server/chunks/[root-of-the-server]__0c1bc5ed._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__0c1bc5ed._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__25ee13bc._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__25ee13bc._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__2945c9e9._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__2945c9e9._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__29635e8e._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__29635e8e._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__315f084a._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__315f084a._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__40ab45eb._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__40ab45eb._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__441cee00._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__441cee00._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__464a4377._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__464a4377._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__47b17fad._.js +38 -0
- package/.next/server/chunks/[root-of-the-server]__47b17fad._.js.map +1 -0
- package/.next/server/chunks/[root-of-the-server]__4e536bc0._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__4e536bc0._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__583a7f1c._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__583a7f1c._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__5abf1160._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__5abf1160._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__5d09614a._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__5d09614a._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__62d958e7._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__62d958e7._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__676affb1._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__676affb1._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__83461316._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__83461316._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__9a611d42._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__9a611d42._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__a878c913._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__a878c913._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__b10ec83e._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__b10ec83e._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__c1629392._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__c1629392._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__eb816e13._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__eb816e13._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__f6f61507._.js +38 -0
- package/.next/server/chunks/[root-of-the-server]__f6f61507._.js.map +1 -0
- package/.next/server/chunks/c4f00_next_dist_esm_build_templates_app-route_cb746cf4.js +1 -1
- package/.next/server/chunks/c4f00_next_dist_esm_build_templates_app-route_cb746cf4.js.map +1 -1
- package/.next/server/chunks/c4f00_next_dist_esm_build_templates_app-route_f952d9ab.js +1 -1
- package/.next/server/chunks/c4f00_next_dist_esm_build_templates_app-route_f952d9ab.js.map +1 -1
- package/.next/server/functions-config-manifest.json +1 -8
- package/.next/server/pages/404.html +1 -1
- package/.next/server/pages/500.html +1 -1
- package/.next/trace +1 -1
- package/dist/app/api/api-keys/[apiKeyId]/buildRoute.d.ts +52 -0
- package/dist/app/api/api-keys/[apiKeyId]/buildRoute.d.ts.map +1 -0
- package/dist/app/api/api-keys/[apiKeyId]/buildRoute.js +121 -0
- package/dist/app/api/api-keys/[apiKeyId]/route.d.ts +10 -21
- package/dist/app/api/api-keys/[apiKeyId]/route.d.ts.map +1 -1
- package/dist/app/api/api-keys/[apiKeyId]/route.js +6 -125
- package/dist/app/api/api-keys/buildRoute.d.ts +32 -0
- package/dist/app/api/api-keys/buildRoute.d.ts.map +1 -0
- package/dist/app/api/api-keys/buildRoute.js +104 -0
- package/dist/app/api/api-keys/builders.d.ts +31 -0
- package/dist/app/api/api-keys/builders.d.ts.map +1 -0
- package/dist/app/api/api-keys/builders.js +109 -0
- package/dist/app/api/api-keys/route.d.ts +5 -13
- package/dist/app/api/api-keys/route.d.ts.map +1 -1
- package/dist/app/api/api-keys/route.js +8 -108
- package/dist/app/api/assistants/[assistantId]/buildRoute.d.ts +120 -0
- package/dist/app/api/assistants/[assistantId]/buildRoute.d.ts.map +1 -0
- package/dist/app/api/assistants/[assistantId]/buildRoute.js +226 -0
- package/dist/app/api/assistants/[assistantId]/functions/[functionId]/buildRoute.d.ts +167 -0
- package/dist/app/api/assistants/[assistantId]/functions/[functionId]/buildRoute.d.ts.map +1 -0
- package/dist/app/api/assistants/[assistantId]/functions/[functionId]/buildRoute.js +184 -0
- package/dist/app/api/assistants/[assistantId]/functions/[functionId]/route.d.ts +10 -21
- package/dist/app/api/assistants/[assistantId]/functions/[functionId]/route.d.ts.map +1 -1
- package/dist/app/api/assistants/[assistantId]/functions/[functionId]/route.js +6 -191
- package/dist/app/api/assistants/[assistantId]/functions/buildRoute.d.ts +114 -0
- package/dist/app/api/assistants/[assistantId]/functions/buildRoute.d.ts.map +1 -0
- package/dist/app/api/assistants/[assistantId]/functions/buildRoute.js +117 -0
- package/dist/app/api/assistants/[assistantId]/functions/route.d.ts +7 -15
- package/dist/app/api/assistants/[assistantId]/functions/route.d.ts.map +1 -1
- package/dist/app/api/assistants/[assistantId]/functions/route.js +5 -122
- package/dist/app/api/assistants/[assistantId]/initial-messages/buildRoute.d.ts +40 -0
- package/dist/app/api/assistants/[assistantId]/initial-messages/buildRoute.d.ts.map +1 -0
- package/dist/app/api/assistants/[assistantId]/initial-messages/buildRoute.js +85 -0
- package/dist/app/api/assistants/[assistantId]/initial-messages/route.d.ts +7 -15
- package/dist/app/api/assistants/[assistantId]/initial-messages/route.d.ts.map +1 -1
- package/dist/app/api/assistants/[assistantId]/initial-messages/route.js +5 -90
- package/dist/app/api/assistants/[assistantId]/mcp-servers/[mcpServerId]/buildRoute.d.ts +89 -0
- package/dist/app/api/assistants/[assistantId]/mcp-servers/[mcpServerId]/buildRoute.d.ts.map +1 -0
- package/dist/app/api/assistants/[assistantId]/mcp-servers/[mcpServerId]/buildRoute.js +167 -0
- package/dist/app/api/assistants/[assistantId]/mcp-servers/[mcpServerId]/route.d.ts +10 -21
- package/dist/app/api/assistants/[assistantId]/mcp-servers/[mcpServerId]/route.d.ts.map +1 -1
- package/dist/app/api/assistants/[assistantId]/mcp-servers/[mcpServerId]/route.js +6 -174
- package/dist/app/api/assistants/[assistantId]/mcp-servers/buildRoute.d.ts +62 -0
- package/dist/app/api/assistants/[assistantId]/mcp-servers/buildRoute.d.ts.map +1 -0
- package/dist/app/api/assistants/[assistantId]/mcp-servers/buildRoute.js +115 -0
- package/dist/app/api/assistants/[assistantId]/mcp-servers/route.d.ts +7 -15
- package/dist/app/api/assistants/[assistantId]/mcp-servers/route.d.ts.map +1 -1
- package/dist/app/api/assistants/[assistantId]/mcp-servers/route.js +5 -120
- package/dist/app/api/assistants/[assistantId]/route.d.ts +11 -22
- package/dist/app/api/assistants/[assistantId]/route.d.ts.map +1 -1
- package/dist/app/api/assistants/[assistantId]/route.js +6 -233
- package/dist/app/api/assistants/buildRoute.d.ts +121 -0
- package/dist/app/api/assistants/buildRoute.d.ts.map +1 -0
- package/dist/app/api/assistants/buildRoute.js +144 -0
- package/dist/app/api/assistants/route.d.ts +7 -13
- package/dist/app/api/assistants/route.d.ts.map +1 -1
- package/dist/app/api/assistants/route.js +6 -148
- package/dist/app/api/files/[fileId]/contents/buildRoute.d.ts +18 -0
- package/dist/app/api/files/[fileId]/contents/buildRoute.d.ts.map +1 -0
- package/dist/app/api/files/[fileId]/contents/buildRoute.js +81 -0
- package/dist/app/api/files/[fileId]/contents/route.d.ts +3 -13
- package/dist/app/api/files/[fileId]/contents/route.d.ts.map +1 -1
- package/dist/app/api/files/[fileId]/contents/route.js +4 -84
- package/dist/app/api/files/buildRoute.d.ts +14 -0
- package/dist/app/api/files/buildRoute.d.ts.map +1 -0
- package/dist/app/api/files/buildRoute.js +88 -0
- package/dist/app/api/files/route.d.ts +4 -10
- package/dist/app/api/files/route.d.ts.map +1 -1
- package/dist/app/api/files/route.js +4 -91
- package/dist/app/api/messages/buildRoute.d.ts +34 -0
- package/dist/app/api/messages/buildRoute.d.ts.map +1 -0
- package/dist/app/api/messages/buildRoute.js +607 -0
- package/dist/app/api/messages/lib/initialMessagesResponse.d.ts.map +1 -1
- package/dist/app/api/messages/lib/initialMessagesResponse.js +1 -1
- package/dist/app/api/messages/route.d.ts +10 -22
- package/dist/app/api/messages/route.d.ts.map +1 -1
- package/dist/app/api/messages/route.js +6 -612
- package/dist/app/api/providers/[modelProviderId]/assistants/buildRoute.d.ts +24 -0
- package/dist/app/api/providers/[modelProviderId]/assistants/buildRoute.d.ts.map +1 -0
- package/dist/app/api/providers/[modelProviderId]/assistants/buildRoute.js +43 -0
- package/dist/app/api/providers/[modelProviderId]/assistants/route.d.ts +4 -9
- package/dist/app/api/providers/[modelProviderId]/assistants/route.d.ts.map +1 -1
- package/dist/app/api/providers/[modelProviderId]/assistants/route.js +4 -46
- package/dist/app/api/providers/[modelProviderId]/buildRoute.d.ts +61 -0
- package/dist/app/api/providers/[modelProviderId]/buildRoute.d.ts.map +1 -0
- package/dist/app/api/providers/[modelProviderId]/buildRoute.js +134 -0
- package/dist/app/api/providers/[modelProviderId]/models/buildRoute.d.ts +19 -0
- package/dist/app/api/providers/[modelProviderId]/models/buildRoute.d.ts.map +1 -0
- package/dist/app/api/providers/[modelProviderId]/models/buildRoute.js +43 -0
- package/dist/app/api/providers/[modelProviderId]/models/route.d.ts +4 -9
- package/dist/app/api/providers/[modelProviderId]/models/route.d.ts.map +1 -1
- package/dist/app/api/providers/[modelProviderId]/models/route.js +4 -46
- package/dist/app/api/providers/[modelProviderId]/route.d.ts +10 -21
- package/dist/app/api/providers/[modelProviderId]/route.d.ts.map +1 -1
- package/dist/app/api/providers/[modelProviderId]/route.js +6 -141
- package/dist/app/api/providers/buildRoute.d.ts +38 -0
- package/dist/app/api/providers/buildRoute.d.ts.map +1 -0
- package/dist/app/api/providers/buildRoute.js +75 -0
- package/dist/app/api/providers/route.d.ts +5 -13
- package/dist/app/api/providers/route.d.ts.map +1 -1
- package/dist/app/api/providers/route.js +5 -80
- package/dist/app/api/tasks/[taskId]/buildRoute.d.ts +19 -0
- package/dist/app/api/tasks/[taskId]/buildRoute.d.ts.map +1 -0
- package/dist/app/api/tasks/[taskId]/buildRoute.js +125 -0
- package/dist/app/api/tasks/[taskId]/route.d.ts +7 -57
- package/dist/app/api/tasks/[taskId]/route.d.ts.map +1 -1
- package/dist/app/api/tasks/[taskId]/route.js +6 -144
- package/dist/app/api/tasks/buildRoute.d.ts +36 -0
- package/dist/app/api/tasks/buildRoute.d.ts.map +1 -0
- package/dist/app/api/tasks/buildRoute.js +85 -0
- package/dist/app/api/tasks/callback/buildRoute.d.ts +6 -0
- package/dist/app/api/tasks/callback/buildRoute.d.ts.map +1 -0
- package/dist/app/api/tasks/callback/buildRoute.js +244 -0
- package/dist/app/api/tasks/callback/route.d.ts +2 -1
- package/dist/app/api/tasks/callback/route.d.ts.map +1 -1
- package/dist/app/api/tasks/callback/route.js +4 -244
- package/dist/app/api/tasks/route.d.ts +5 -13
- package/dist/app/api/tasks/route.d.ts.map +1 -1
- package/dist/app/api/tasks/route.js +5 -90
- package/dist/app/api/threads/runs/submit-client-tool-outputs/buildRoute.d.ts +10 -0
- package/dist/app/api/threads/runs/submit-client-tool-outputs/buildRoute.d.ts.map +1 -0
- package/dist/app/api/threads/runs/submit-client-tool-outputs/buildRoute.js +36 -0
- package/dist/app/api/threads/runs/submit-client-tool-outputs/route.d.ts +2 -7
- package/dist/app/api/threads/runs/submit-client-tool-outputs/route.d.ts.map +1 -1
- package/dist/app/api/threads/runs/submit-client-tool-outputs/route.js +3 -37
- package/dist/app/api/workspaces/[workspaceId]/buildRoute.d.ts +16 -0
- package/dist/app/api/workspaces/[workspaceId]/buildRoute.d.ts.map +1 -0
- package/dist/app/api/workspaces/[workspaceId]/buildRoute.js +89 -0
- package/dist/app/api/workspaces/[workspaceId]/route.d.ts +5 -31
- package/dist/app/api/workspaces/[workspaceId]/route.d.ts.map +1 -1
- package/dist/app/api/workspaces/[workspaceId]/route.js +5 -89
- package/dist/app/api/workspaces/buildRoute.d.ts +42 -0
- package/dist/app/api/workspaces/buildRoute.d.ts.map +1 -0
- package/dist/app/api/workspaces/buildRoute.js +78 -0
- package/dist/app/api/workspaces/route.d.ts +7 -27
- package/dist/app/api/workspaces/route.d.ts.map +1 -1
- package/dist/app/api/workspaces/route.js +6 -82
- package/dist/lib/functions/functionSchema.d.ts +56 -56
- package/dist/lib/functions/handleFunction/getFunction.d.ts +4 -4
- package/dist/lib/mcpServers/mcpServerSchema.d.ts +20 -20
- package/dist/lib/prisma/index.d.ts +2 -5
- package/dist/lib/prisma/index.d.ts.map +1 -1
- package/dist/lib/prisma/index.js +5 -70
- package/package.json +2 -2
- package/.next/server/chunks/[root-of-the-server]__228bff78._.js +0 -38
- package/.next/server/chunks/[root-of-the-server]__228bff78._.js.map +0 -1
- package/.next/server/chunks/[root-of-the-server]__3307123c._.js +0 -38
- package/.next/server/chunks/[root-of-the-server]__3307123c._.js.map +0 -1
- package/.next/server/chunks/[root-of-the-server]__50c5f12c._.js +0 -38
- package/.next/server/chunks/[root-of-the-server]__50c5f12c._.js.map +0 -1
- package/.next/server/chunks/[root-of-the-server]__6b8ba839._.js +0 -38
- package/.next/server/chunks/[root-of-the-server]__6b8ba839._.js.map +0 -1
- package/.next/server/chunks/[root-of-the-server]__e7819e95._.js +0 -38
- package/.next/server/chunks/[root-of-the-server]__e7819e95._.js.map +0 -1
- package/.next/server/chunks/[root-of-the-server]__f0dfab03._.js +0 -38
- package/.next/server/chunks/[root-of-the-server]__f0dfab03._.js.map +0 -1
- package/.next/server/chunks/[root-of-the-server]__ff90af03._.js +0 -38
- package/.next/server/chunks/[root-of-the-server]__ff90af03._.js.map +0 -1
- /package/.next/static/{X1k4ISA6YteJsnJalPLxm → KhKDqyqUf75vkMRrXaWJf}/_buildManifest.js +0 -0
- /package/.next/static/{X1k4ISA6YteJsnJalPLxm → KhKDqyqUf75vkMRrXaWJf}/_clientMiddlewareManifest.json +0 -0
- /package/.next/static/{X1k4ISA6YteJsnJalPLxm → KhKDqyqUf75vkMRrXaWJf}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { NextResponse } from 'next/server';
|
|
2
|
+
import { ApiKeyType } from '@prisma/client';
|
|
3
|
+
import { headers } from 'next/headers';
|
|
4
|
+
import { cacheHeaders } from '../../../../lib/cache/cacheHeaders';
|
|
5
|
+
import { serializeApiKey } from '../../../../lib/apiKeys/serializeApiKey';
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { getApiKey } from '../../../../lib/apiKeys/getApiKey';
|
|
8
|
+
import { validate } from 'uuid';
|
|
9
|
+
const ensureValidApiKeyId = (apiKeyId) => {
|
|
10
|
+
if (!validate(apiKeyId)) {
|
|
11
|
+
return NextResponse.json({ error: 'Invalid api key id' }, { status: 400 });
|
|
12
|
+
}
|
|
13
|
+
return null;
|
|
14
|
+
};
|
|
15
|
+
export const buildGET = ({ prisma }) => async (_request, props) => {
|
|
16
|
+
const { apiKeyId } = await props.params;
|
|
17
|
+
const headersList = await headers();
|
|
18
|
+
const authorization = headersList.get('authorization');
|
|
19
|
+
if (!authorization) {
|
|
20
|
+
return NextResponse.json({ error: 'No authorization header found' }, { status: 400 });
|
|
21
|
+
}
|
|
22
|
+
const privateApiKey = await getApiKey({
|
|
23
|
+
type: ApiKeyType.PRIVATE,
|
|
24
|
+
authorization,
|
|
25
|
+
prisma,
|
|
26
|
+
});
|
|
27
|
+
if (!privateApiKey) {
|
|
28
|
+
return NextResponse.json({ error: 'Invalid api key' }, { status: 400 });
|
|
29
|
+
}
|
|
30
|
+
const validationError = ensureValidApiKeyId(apiKeyId);
|
|
31
|
+
if (validationError)
|
|
32
|
+
return validationError;
|
|
33
|
+
const apiKey = await prisma.apiKey.findFirst({
|
|
34
|
+
where: {
|
|
35
|
+
id: apiKeyId,
|
|
36
|
+
type: ApiKeyType.PUBLIC,
|
|
37
|
+
workspaceId: privateApiKey.workspaceId,
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
if (!apiKey) {
|
|
41
|
+
return NextResponse.json({ error: 'No api key found' }, { status: 400 });
|
|
42
|
+
}
|
|
43
|
+
return NextResponse.json({ apiKey: serializeApiKey({ apiKey }) }, { headers: cacheHeaders });
|
|
44
|
+
};
|
|
45
|
+
export const buildPATCH = ({ prisma }) => async (request, props) => {
|
|
46
|
+
const { apiKeyId } = await props.params;
|
|
47
|
+
const headersList = await headers();
|
|
48
|
+
const authorization = headersList.get('authorization');
|
|
49
|
+
if (!authorization) {
|
|
50
|
+
return NextResponse.json({ error: 'No authorization header found' }, { status: 400 });
|
|
51
|
+
}
|
|
52
|
+
const privateApiKey = await getApiKey({
|
|
53
|
+
authorization,
|
|
54
|
+
type: ApiKeyType.PRIVATE,
|
|
55
|
+
prisma,
|
|
56
|
+
});
|
|
57
|
+
if (!privateApiKey) {
|
|
58
|
+
return NextResponse.json({ error: 'Invalid api key' }, { status: 400 });
|
|
59
|
+
}
|
|
60
|
+
const validationError = ensureValidApiKeyId(apiKeyId);
|
|
61
|
+
if (validationError)
|
|
62
|
+
return validationError;
|
|
63
|
+
const body = await request.json().catch(() => null);
|
|
64
|
+
const schema = z.object({ name: z.string().min(1) });
|
|
65
|
+
const parsed = schema.safeParse(body);
|
|
66
|
+
if (!parsed.success) {
|
|
67
|
+
return NextResponse.json({ error: 'No name found' }, { status: 400 });
|
|
68
|
+
}
|
|
69
|
+
const { name } = parsed.data;
|
|
70
|
+
const existingApiKey = await prisma.apiKey.findFirst({
|
|
71
|
+
where: {
|
|
72
|
+
id: apiKeyId,
|
|
73
|
+
type: ApiKeyType.PUBLIC,
|
|
74
|
+
workspaceId: privateApiKey.workspaceId,
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
if (!existingApiKey) {
|
|
78
|
+
return NextResponse.json({ error: 'No api key found' }, { status: 400 });
|
|
79
|
+
}
|
|
80
|
+
const apiKey = await prisma.apiKey.update({
|
|
81
|
+
where: { id: apiKeyId },
|
|
82
|
+
data: { name },
|
|
83
|
+
});
|
|
84
|
+
return NextResponse.json({ apiKey: serializeApiKey({ apiKey }) }, { headers: cacheHeaders });
|
|
85
|
+
};
|
|
86
|
+
export const buildDELETE = ({ prisma }) => async (_request, props) => {
|
|
87
|
+
const { apiKeyId } = await props.params;
|
|
88
|
+
const headersList = await headers();
|
|
89
|
+
const authorization = headersList.get('authorization');
|
|
90
|
+
if (!authorization) {
|
|
91
|
+
return NextResponse.json({ error: 'No authorization header found' }, { status: 400 });
|
|
92
|
+
}
|
|
93
|
+
const privateApiKey = await getApiKey({
|
|
94
|
+
type: ApiKeyType.PRIVATE,
|
|
95
|
+
authorization,
|
|
96
|
+
prisma,
|
|
97
|
+
});
|
|
98
|
+
if (!privateApiKey) {
|
|
99
|
+
return NextResponse.json({ error: 'Invalid api key' }, { status: 400 });
|
|
100
|
+
}
|
|
101
|
+
const validationError = ensureValidApiKeyId(apiKeyId);
|
|
102
|
+
if (validationError)
|
|
103
|
+
return validationError;
|
|
104
|
+
const apiKey = await prisma.apiKey.findFirst({
|
|
105
|
+
where: {
|
|
106
|
+
id: apiKeyId,
|
|
107
|
+
type: ApiKeyType.PUBLIC,
|
|
108
|
+
workspaceId: privateApiKey.workspaceId,
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
if (!apiKey) {
|
|
112
|
+
return NextResponse.json({ error: 'No api key found' }, { status: 400 });
|
|
113
|
+
}
|
|
114
|
+
const deletedApiKey = await prisma.apiKey.delete({
|
|
115
|
+
where: { id: apiKey.id },
|
|
116
|
+
});
|
|
117
|
+
return NextResponse.json({ apiKey: serializeApiKey({ apiKey: deletedApiKey }) }, { headers: cacheHeaders });
|
|
118
|
+
};
|
|
119
|
+
export const buildOPTIONS = () => () => NextResponse.json({}, {
|
|
120
|
+
headers: cacheHeaders,
|
|
121
|
+
});
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
import { type PrismaClient } from '@prisma/client';
|
|
3
|
-
export declare const buildGET: ({ prisma: providedPrisma }?: {
|
|
4
|
-
prisma?: PrismaClient;
|
|
5
|
-
}) => (request: NextRequest, props: {
|
|
1
|
+
export declare const GET: (_request: import("next/server").NextRequest, props: {
|
|
6
2
|
params: Promise<{
|
|
7
3
|
apiKeyId: string;
|
|
8
4
|
}>;
|
|
9
|
-
}) => Promise<NextResponse<{
|
|
5
|
+
}) => Promise<import("next/server").NextResponse<{
|
|
10
6
|
error: string;
|
|
11
|
-
}> | NextResponse<{
|
|
7
|
+
}> | import("next/server").NextResponse<{
|
|
12
8
|
apiKey: {
|
|
13
9
|
id: string;
|
|
14
10
|
type: import("@prisma/client").$Enums.ApiKeyType;
|
|
@@ -18,16 +14,13 @@ export declare const buildGET: ({ prisma: providedPrisma }?: {
|
|
|
18
14
|
updatedAt: string;
|
|
19
15
|
};
|
|
20
16
|
}>>;
|
|
21
|
-
export declare const
|
|
22
|
-
export declare const buildPATCH: ({ prisma: providedPrisma }?: {
|
|
23
|
-
prisma?: PrismaClient;
|
|
24
|
-
}) => (request: NextRequest, props: {
|
|
17
|
+
export declare const PATCH: (request: import("next/server").NextRequest, props: {
|
|
25
18
|
params: Promise<{
|
|
26
19
|
apiKeyId: string;
|
|
27
20
|
}>;
|
|
28
|
-
}) => Promise<NextResponse<{
|
|
21
|
+
}) => Promise<import("next/server").NextResponse<{
|
|
29
22
|
error: string;
|
|
30
|
-
}> | NextResponse<{
|
|
23
|
+
}> | import("next/server").NextResponse<{
|
|
31
24
|
apiKey: {
|
|
32
25
|
id: string;
|
|
33
26
|
type: import("@prisma/client").$Enums.ApiKeyType;
|
|
@@ -37,16 +30,13 @@ export declare const buildPATCH: ({ prisma: providedPrisma }?: {
|
|
|
37
30
|
updatedAt: string;
|
|
38
31
|
};
|
|
39
32
|
}>>;
|
|
40
|
-
export declare const
|
|
41
|
-
export declare const buildDELETE: ({ prisma: providedPrisma }?: {
|
|
42
|
-
prisma?: PrismaClient;
|
|
43
|
-
}) => (request: NextRequest, props: {
|
|
33
|
+
export declare const DELETE: (_request: import("next/server").NextRequest, props: {
|
|
44
34
|
params: Promise<{
|
|
45
35
|
apiKeyId: string;
|
|
46
36
|
}>;
|
|
47
|
-
}) => Promise<NextResponse<{
|
|
37
|
+
}) => Promise<import("next/server").NextResponse<{
|
|
48
38
|
error: string;
|
|
49
|
-
}> | NextResponse<{
|
|
39
|
+
}> | import("next/server").NextResponse<{
|
|
50
40
|
apiKey: {
|
|
51
41
|
id: string;
|
|
52
42
|
type: import("@prisma/client").$Enums.ApiKeyType;
|
|
@@ -56,6 +46,5 @@ export declare const buildDELETE: ({ prisma: providedPrisma }?: {
|
|
|
56
46
|
updatedAt: string;
|
|
57
47
|
};
|
|
58
48
|
}>>;
|
|
59
|
-
export declare const
|
|
60
|
-
export declare const OPTIONS: () => NextResponse<{}>;
|
|
49
|
+
export declare const OPTIONS: () => import("next/server").NextResponse<{}>;
|
|
61
50
|
//# sourceMappingURL=route.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../../src/app/api/api-keys/[apiKeyId]/route.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../../src/app/api/api-keys/[apiKeyId]/route.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,GAAG;;;;;;;;;;;;;;;GAAuB,CAAA;AAEvC,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;GAAyB,CAAA;AAE3C,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;GAA0B,CAAA;AAE7C,eAAO,MAAM,OAAO,8CAAiB,CAAA"}
|
|
@@ -1,125 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import { z } from 'zod';
|
|
8
|
-
import { getApiKey } from '../../../../lib/apiKeys/getApiKey';
|
|
9
|
-
import { validate } from 'uuid';
|
|
10
|
-
export const buildGET = ({ prisma: providedPrisma } = {}) => async (request, props) => {
|
|
11
|
-
const prisma = resolvePrisma(providedPrisma);
|
|
12
|
-
const params = await props.params;
|
|
13
|
-
const { apiKeyId } = params;
|
|
14
|
-
const headersList = await headers();
|
|
15
|
-
const authorization = headersList.get('authorization');
|
|
16
|
-
if (!authorization) {
|
|
17
|
-
return NextResponse.json({ error: 'No authorization header found' }, { status: 400 });
|
|
18
|
-
}
|
|
19
|
-
const privateApiKey = await getApiKey({
|
|
20
|
-
type: ApiKeyType.PRIVATE,
|
|
21
|
-
authorization,
|
|
22
|
-
prisma,
|
|
23
|
-
});
|
|
24
|
-
if (!privateApiKey) {
|
|
25
|
-
return NextResponse.json({ error: 'Invalid api key' }, { status: 400 });
|
|
26
|
-
}
|
|
27
|
-
if (!validate(apiKeyId)) {
|
|
28
|
-
return NextResponse.json({ error: 'Invalid api key id' }, { status: 400 });
|
|
29
|
-
}
|
|
30
|
-
const apiKey = await prisma.apiKey.findFirst({
|
|
31
|
-
where: {
|
|
32
|
-
id: apiKeyId,
|
|
33
|
-
type: ApiKeyType.PUBLIC,
|
|
34
|
-
workspaceId: privateApiKey.workspaceId,
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
if (!apiKey) {
|
|
38
|
-
return NextResponse.json({ error: 'No api key found' }, { status: 400 });
|
|
39
|
-
}
|
|
40
|
-
return NextResponse.json({ apiKey: serializeApiKey({ apiKey }) }, { headers: cacheHeaders });
|
|
41
|
-
};
|
|
42
|
-
export const GET = ((...args) => buildGET()(...args));
|
|
43
|
-
export const buildPATCH = ({ prisma: providedPrisma } = {}) => async (request, props) => {
|
|
44
|
-
const prisma = resolvePrisma(providedPrisma);
|
|
45
|
-
const params = await props.params;
|
|
46
|
-
const { apiKeyId } = params;
|
|
47
|
-
const headersList = await headers();
|
|
48
|
-
const authorization = headersList.get('authorization');
|
|
49
|
-
if (!authorization) {
|
|
50
|
-
return NextResponse.json({ error: 'No authorization header found' }, { status: 400 });
|
|
51
|
-
}
|
|
52
|
-
const privateApiKey = await getApiKey({
|
|
53
|
-
authorization,
|
|
54
|
-
type: ApiKeyType.PRIVATE,
|
|
55
|
-
prisma,
|
|
56
|
-
});
|
|
57
|
-
if (!privateApiKey) {
|
|
58
|
-
return NextResponse.json({ error: 'Invalid api key' }, { status: 400 });
|
|
59
|
-
}
|
|
60
|
-
if (!validate(apiKeyId)) {
|
|
61
|
-
return NextResponse.json({ error: 'Invalid api key id' }, { status: 400 });
|
|
62
|
-
}
|
|
63
|
-
const body = await request.json().catch(() => null);
|
|
64
|
-
const schema = z.object({ name: z.string().min(1) });
|
|
65
|
-
const parsed = schema.safeParse(body);
|
|
66
|
-
if (!parsed.success) {
|
|
67
|
-
return NextResponse.json({ error: 'No name found' }, { status: 400 });
|
|
68
|
-
}
|
|
69
|
-
const { name } = parsed.data;
|
|
70
|
-
const existingApiKey = await prisma.apiKey.findFirst({
|
|
71
|
-
where: {
|
|
72
|
-
id: apiKeyId,
|
|
73
|
-
type: ApiKeyType.PUBLIC,
|
|
74
|
-
workspaceId: privateApiKey.workspaceId,
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
if (!existingApiKey) {
|
|
78
|
-
return NextResponse.json({ error: 'No api key found' }, { status: 400 });
|
|
79
|
-
}
|
|
80
|
-
const apiKey = await prisma.apiKey.update({
|
|
81
|
-
where: { id: apiKeyId },
|
|
82
|
-
data: { name },
|
|
83
|
-
});
|
|
84
|
-
return NextResponse.json({ apiKey: serializeApiKey({ apiKey }) }, { headers: cacheHeaders });
|
|
85
|
-
};
|
|
86
|
-
export const PATCH = ((...args) => buildPATCH()(...args));
|
|
87
|
-
export const buildDELETE = ({ prisma: providedPrisma } = {}) => async (request, props) => {
|
|
88
|
-
const prisma = resolvePrisma(providedPrisma);
|
|
89
|
-
const params = await props.params;
|
|
90
|
-
const { apiKeyId } = params;
|
|
91
|
-
const headersList = await headers();
|
|
92
|
-
const authorization = headersList.get('authorization');
|
|
93
|
-
if (!authorization) {
|
|
94
|
-
return NextResponse.json({ error: 'No authorization header found' }, { status: 400 });
|
|
95
|
-
}
|
|
96
|
-
const privateApiKey = await getApiKey({
|
|
97
|
-
type: ApiKeyType.PRIVATE,
|
|
98
|
-
authorization,
|
|
99
|
-
prisma,
|
|
100
|
-
});
|
|
101
|
-
if (!privateApiKey) {
|
|
102
|
-
return NextResponse.json({ error: 'Invalid api key' }, { status: 400 });
|
|
103
|
-
}
|
|
104
|
-
if (!validate(apiKeyId)) {
|
|
105
|
-
return NextResponse.json({ error: 'Invalid api key id' }, { status: 400 });
|
|
106
|
-
}
|
|
107
|
-
const apiKey = await prisma.apiKey.findFirst({
|
|
108
|
-
where: {
|
|
109
|
-
id: apiKeyId,
|
|
110
|
-
type: ApiKeyType.PUBLIC,
|
|
111
|
-
workspaceId: privateApiKey.workspaceId,
|
|
112
|
-
},
|
|
113
|
-
});
|
|
114
|
-
if (!apiKey) {
|
|
115
|
-
return NextResponse.json({ error: 'No api key found' }, { status: 400 });
|
|
116
|
-
}
|
|
117
|
-
const deletedApiKey = await prisma.apiKey.delete({
|
|
118
|
-
where: { id: apiKey.id },
|
|
119
|
-
});
|
|
120
|
-
return NextResponse.json({ apiKey: serializeApiKey({ apiKey: deletedApiKey }) }, { headers: cacheHeaders });
|
|
121
|
-
};
|
|
122
|
-
export const DELETE = ((...args) => buildDELETE()(...args));
|
|
123
|
-
export const OPTIONS = () => NextResponse.json({}, {
|
|
124
|
-
headers: cacheHeaders,
|
|
125
|
-
});
|
|
1
|
+
import { prisma } from '../../../../lib/prisma';
|
|
2
|
+
import { buildDELETE, buildGET, buildOPTIONS, buildPATCH, } from './buildRoute';
|
|
3
|
+
export const GET = buildGET({ prisma });
|
|
4
|
+
export const PATCH = buildPATCH({ prisma });
|
|
5
|
+
export const DELETE = buildDELETE({ prisma });
|
|
6
|
+
export const OPTIONS = buildOPTIONS();
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type PrismaClient } from '@prisma/client';
|
|
2
|
+
import { NextResponse } from 'next/server';
|
|
3
|
+
export declare const buildGET: ({ prisma }: {
|
|
4
|
+
prisma: PrismaClient;
|
|
5
|
+
}) => () => Promise<NextResponse<{
|
|
6
|
+
error: string;
|
|
7
|
+
}> | NextResponse<{
|
|
8
|
+
apiKeys: {
|
|
9
|
+
id: string;
|
|
10
|
+
type: import("@prisma/client").$Enums.ApiKeyType;
|
|
11
|
+
name: string;
|
|
12
|
+
value: string;
|
|
13
|
+
createdAt: string;
|
|
14
|
+
updatedAt: string;
|
|
15
|
+
}[];
|
|
16
|
+
}>>;
|
|
17
|
+
export declare const buildPOST: ({ prisma }: {
|
|
18
|
+
prisma: PrismaClient;
|
|
19
|
+
}) => (request: Request) => Promise<NextResponse<{
|
|
20
|
+
error: string;
|
|
21
|
+
}> | NextResponse<{
|
|
22
|
+
apiKey: {
|
|
23
|
+
id: string;
|
|
24
|
+
type: import("@prisma/client").$Enums.ApiKeyType;
|
|
25
|
+
name: string;
|
|
26
|
+
value: string;
|
|
27
|
+
createdAt: string;
|
|
28
|
+
updatedAt: string;
|
|
29
|
+
};
|
|
30
|
+
}>>;
|
|
31
|
+
export declare const buildOPTIONS: () => () => NextResponse<{}>;
|
|
32
|
+
//# sourceMappingURL=buildRoute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildRoute.d.ts","sourceRoot":"","sources":["../../../../src/app/api/api-keys/buildRoute.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAO1C,eAAO,MAAM,QAAQ,GAAI,YAAY;IAAE,MAAM,EAAE,YAAY,CAAA;CAAE;;;;;;;;;;;GAkC1D,CAAA;AAEH,eAAO,MAAM,SAAS,GAAI,YAAY;IAAE,MAAM,EAAE,YAAY,CAAA;CAAE,MACrD,SAAS,OAAO;;;;;;;;;;;GAmGtB,CAAA;AAEH,eAAO,MAAM,YAAY,8BAMtB,CAAA"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { headers } from 'next/headers';
|
|
2
|
+
import { ApiKeyType } from '@prisma/client';
|
|
3
|
+
import { NextResponse } from 'next/server';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { cacheHeaders } from '../../../lib/cache/cacheHeaders';
|
|
6
|
+
import { serializeApiKey } from '../../../lib/apiKeys/serializeApiKey';
|
|
7
|
+
import { getApiKey } from '../../../lib/apiKeys/getApiKey';
|
|
8
|
+
import { getOrganizationApiKey } from '../../../lib/organizationApiKeys/getOrganizationApiKey';
|
|
9
|
+
export const buildGET = ({ prisma }) => async () => {
|
|
10
|
+
const headersList = await headers();
|
|
11
|
+
const authorization = headersList.get('authorization');
|
|
12
|
+
if (!authorization) {
|
|
13
|
+
return NextResponse.json({ error: 'No authorization header found' }, { status: 400 });
|
|
14
|
+
}
|
|
15
|
+
const privateApiKey = await getApiKey({
|
|
16
|
+
type: ApiKeyType.PRIVATE,
|
|
17
|
+
authorization,
|
|
18
|
+
prisma,
|
|
19
|
+
});
|
|
20
|
+
if (!privateApiKey) {
|
|
21
|
+
return NextResponse.json({ error: 'Invalid api key' }, { status: 400 });
|
|
22
|
+
}
|
|
23
|
+
const apiKeys = await prisma.apiKey.findMany({
|
|
24
|
+
where: {
|
|
25
|
+
type: ApiKeyType.PUBLIC,
|
|
26
|
+
workspaceId: privateApiKey.workspaceId,
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
return NextResponse.json({
|
|
30
|
+
apiKeys: apiKeys.map((apiKey) => serializeApiKey({ apiKey })),
|
|
31
|
+
}, { headers: cacheHeaders });
|
|
32
|
+
};
|
|
33
|
+
export const buildPOST = ({ prisma }) => async (request) => {
|
|
34
|
+
const headersList = await headers();
|
|
35
|
+
const authorization = headersList.get('authorization');
|
|
36
|
+
if (!authorization) {
|
|
37
|
+
return NextResponse.json({ error: 'No authorization header found' }, { status: 400 });
|
|
38
|
+
}
|
|
39
|
+
const body = await request.json().catch(() => null);
|
|
40
|
+
const organizationApiKey = await getOrganizationApiKey({
|
|
41
|
+
authorization,
|
|
42
|
+
prisma,
|
|
43
|
+
});
|
|
44
|
+
if (organizationApiKey) {
|
|
45
|
+
const createSchemaOrganizationApiKey = z.object({
|
|
46
|
+
name: z.string().min(1).optional(),
|
|
47
|
+
type: z.nativeEnum(ApiKeyType),
|
|
48
|
+
workspaceId: z.string().min(1).optional(),
|
|
49
|
+
});
|
|
50
|
+
const parsedOrganizationApiKey = createSchemaOrganizationApiKey.safeParse(body);
|
|
51
|
+
if (!parsedOrganizationApiKey.success) {
|
|
52
|
+
return NextResponse.json({ error: 'Invalid body' }, { status: 400 });
|
|
53
|
+
}
|
|
54
|
+
const workspace = await prisma.workspace.findUnique({
|
|
55
|
+
where: {
|
|
56
|
+
id: parsedOrganizationApiKey.data.workspaceId,
|
|
57
|
+
organizationId: organizationApiKey.organizationId,
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
if (!workspace) {
|
|
61
|
+
return NextResponse.json({ error: 'Invalid workspace' }, { status: 400 });
|
|
62
|
+
}
|
|
63
|
+
const apiKey = await prisma.apiKey.create({
|
|
64
|
+
data: {
|
|
65
|
+
type: parsedOrganizationApiKey.data.type,
|
|
66
|
+
name: parsedOrganizationApiKey.data.name,
|
|
67
|
+
workspaceId: workspace.id,
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
return NextResponse.json({
|
|
71
|
+
apiKey: serializeApiKey({ apiKey }),
|
|
72
|
+
}, { headers: cacheHeaders });
|
|
73
|
+
}
|
|
74
|
+
const privateApiKey = await getApiKey({
|
|
75
|
+
type: ApiKeyType.PRIVATE,
|
|
76
|
+
authorization,
|
|
77
|
+
prisma,
|
|
78
|
+
});
|
|
79
|
+
if (!privateApiKey) {
|
|
80
|
+
return NextResponse.json({ error: 'Invalid api key' }, { status: 400 });
|
|
81
|
+
}
|
|
82
|
+
const createSchema = z.object({
|
|
83
|
+
name: z.string().min(1).optional(),
|
|
84
|
+
});
|
|
85
|
+
const parsed = createSchema.safeParse(body);
|
|
86
|
+
if (!parsed.success) {
|
|
87
|
+
return NextResponse.json({ error: 'Invalid body' }, { status: 400 });
|
|
88
|
+
}
|
|
89
|
+
const { name } = parsed.data;
|
|
90
|
+
const workspaceId = privateApiKey.workspaceId;
|
|
91
|
+
const apiKey = await prisma.apiKey.create({
|
|
92
|
+
data: {
|
|
93
|
+
type: ApiKeyType.PUBLIC,
|
|
94
|
+
name,
|
|
95
|
+
workspaceId,
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
return NextResponse.json({
|
|
99
|
+
apiKey: serializeApiKey({ apiKey }),
|
|
100
|
+
}, { headers: cacheHeaders });
|
|
101
|
+
};
|
|
102
|
+
export const buildOPTIONS = () => () => NextResponse.json({}, {
|
|
103
|
+
headers: cacheHeaders,
|
|
104
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type PrismaClient } from '@prisma/client';
|
|
2
|
+
import { NextResponse } from 'next/server';
|
|
3
|
+
export declare const buildGET: ({ prisma: providedPrisma }?: {
|
|
4
|
+
prisma?: PrismaClient;
|
|
5
|
+
}) => () => Promise<NextResponse<{
|
|
6
|
+
error: string;
|
|
7
|
+
}> | NextResponse<{
|
|
8
|
+
apiKeys: {
|
|
9
|
+
id: string;
|
|
10
|
+
type: import("@prisma/client").$Enums.ApiKeyType;
|
|
11
|
+
name: string;
|
|
12
|
+
value: string;
|
|
13
|
+
createdAt: string;
|
|
14
|
+
updatedAt: string;
|
|
15
|
+
}[];
|
|
16
|
+
}>>;
|
|
17
|
+
export declare const buildPOST: ({ prisma: providedPrisma }?: {
|
|
18
|
+
prisma?: PrismaClient;
|
|
19
|
+
}) => (request: Request) => Promise<NextResponse<{
|
|
20
|
+
error: string;
|
|
21
|
+
}> | NextResponse<{
|
|
22
|
+
apiKey: {
|
|
23
|
+
id: string;
|
|
24
|
+
type: import("@prisma/client").$Enums.ApiKeyType;
|
|
25
|
+
name: string;
|
|
26
|
+
value: string;
|
|
27
|
+
createdAt: string;
|
|
28
|
+
updatedAt: string;
|
|
29
|
+
};
|
|
30
|
+
}>>;
|
|
31
|
+
//# sourceMappingURL=builders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builders.d.ts","sourceRoot":"","sources":["../../../../src/app/api/api-keys/builders.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAU1C,eAAO,MAAM,QAAQ,GAClB,6BAA4B;IAAE,MAAM,CAAC,EAAE,YAAY,CAAA;CAAO;;;;;;;;;;;GAsC1D,CAAA;AAEH,eAAO,MAAM,SAAS,GACnB,6BAA4B;IAAE,MAAM,CAAC,EAAE,YAAY,CAAA;CAAO,MACpD,SAAS,OAAO;;;;;;;;;;;GAuGtB,CAAA"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { headers } from 'next/headers';
|
|
2
|
+
import { ApiKeyType } from '@prisma/client';
|
|
3
|
+
import { NextResponse } from 'next/server';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { cacheHeaders } from '../../../lib/cache/cacheHeaders';
|
|
6
|
+
import { serializeApiKey } from '../../../lib/apiKeys/serializeApiKey';
|
|
7
|
+
import { getApiKey } from '../../../lib/apiKeys/getApiKey';
|
|
8
|
+
import { getOrganizationApiKey } from '../../../lib/organizationApiKeys/getOrganizationApiKey';
|
|
9
|
+
// ✅ NO imports from @/lib/prisma here!
|
|
10
|
+
// resolvePrisma is loaded lazily only when the handler is called
|
|
11
|
+
export const buildGET = ({ prisma: providedPrisma } = {}) => async () => {
|
|
12
|
+
// ✅ Lazy import - only runs when handler is called, not at module evaluation
|
|
13
|
+
const { resolvePrisma } = await import('../../../lib/prisma');
|
|
14
|
+
const prisma = resolvePrisma(providedPrisma);
|
|
15
|
+
const headersList = await headers();
|
|
16
|
+
const authorization = headersList.get('authorization');
|
|
17
|
+
if (!authorization) {
|
|
18
|
+
return NextResponse.json({ error: 'No authorization header found' }, { status: 400 });
|
|
19
|
+
}
|
|
20
|
+
const privateApiKey = await getApiKey({
|
|
21
|
+
type: ApiKeyType.PRIVATE,
|
|
22
|
+
authorization,
|
|
23
|
+
prisma,
|
|
24
|
+
});
|
|
25
|
+
if (!privateApiKey) {
|
|
26
|
+
return NextResponse.json({ error: 'Invalid api key' }, { status: 400 });
|
|
27
|
+
}
|
|
28
|
+
const apiKeys = await prisma.apiKey.findMany({
|
|
29
|
+
where: {
|
|
30
|
+
type: ApiKeyType.PUBLIC,
|
|
31
|
+
workspaceId: privateApiKey.workspaceId,
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
return NextResponse.json({
|
|
35
|
+
apiKeys: apiKeys.map((apiKey) => serializeApiKey({ apiKey })),
|
|
36
|
+
}, { headers: cacheHeaders });
|
|
37
|
+
};
|
|
38
|
+
export const buildPOST = ({ prisma: providedPrisma } = {}) => async (request) => {
|
|
39
|
+
// ✅ Lazy import
|
|
40
|
+
const { resolvePrisma } = await import('../../../lib/prisma');
|
|
41
|
+
const prisma = resolvePrisma(providedPrisma);
|
|
42
|
+
const headersList = await headers();
|
|
43
|
+
const authorization = headersList.get('authorization');
|
|
44
|
+
if (!authorization) {
|
|
45
|
+
return NextResponse.json({ error: 'No authorization header found' }, { status: 400 });
|
|
46
|
+
}
|
|
47
|
+
const body = await request.json().catch(() => null);
|
|
48
|
+
const organizationApiKey = await getOrganizationApiKey({
|
|
49
|
+
authorization,
|
|
50
|
+
prisma,
|
|
51
|
+
});
|
|
52
|
+
if (organizationApiKey) {
|
|
53
|
+
const createSchemaOrganizationApiKey = z.object({
|
|
54
|
+
name: z.string().min(1).optional(),
|
|
55
|
+
type: z.nativeEnum(ApiKeyType),
|
|
56
|
+
workspaceId: z.string().min(1).optional(),
|
|
57
|
+
});
|
|
58
|
+
const parsedOrganizationApiKey = createSchemaOrganizationApiKey.safeParse(body);
|
|
59
|
+
if (!parsedOrganizationApiKey.success) {
|
|
60
|
+
return NextResponse.json({ error: 'Invalid body' }, { status: 400 });
|
|
61
|
+
}
|
|
62
|
+
const workspace = await prisma.workspace.findUnique({
|
|
63
|
+
where: {
|
|
64
|
+
id: parsedOrganizationApiKey.data.workspaceId,
|
|
65
|
+
organizationId: organizationApiKey.organizationId,
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
if (!workspace) {
|
|
69
|
+
return NextResponse.json({ error: 'Invalid workspace' }, { status: 400 });
|
|
70
|
+
}
|
|
71
|
+
const apiKey = await prisma.apiKey.create({
|
|
72
|
+
data: {
|
|
73
|
+
type: parsedOrganizationApiKey.data.type,
|
|
74
|
+
name: parsedOrganizationApiKey.data.name,
|
|
75
|
+
workspaceId: workspace.id,
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
return NextResponse.json({
|
|
79
|
+
apiKey: serializeApiKey({ apiKey }),
|
|
80
|
+
}, { headers: cacheHeaders });
|
|
81
|
+
}
|
|
82
|
+
const privateApiKey = await getApiKey({
|
|
83
|
+
type: ApiKeyType.PRIVATE,
|
|
84
|
+
authorization,
|
|
85
|
+
prisma,
|
|
86
|
+
});
|
|
87
|
+
if (!privateApiKey) {
|
|
88
|
+
return NextResponse.json({ error: 'Invalid api key' }, { status: 400 });
|
|
89
|
+
}
|
|
90
|
+
const createSchema = z.object({
|
|
91
|
+
name: z.string().min(1).optional(),
|
|
92
|
+
});
|
|
93
|
+
const parsed = createSchema.safeParse(body);
|
|
94
|
+
if (!parsed.success) {
|
|
95
|
+
return NextResponse.json({ error: 'Invalid body' }, { status: 400 });
|
|
96
|
+
}
|
|
97
|
+
const { name } = parsed.data;
|
|
98
|
+
const workspaceId = privateApiKey.workspaceId;
|
|
99
|
+
const apiKey = await prisma.apiKey.create({
|
|
100
|
+
data: {
|
|
101
|
+
type: ApiKeyType.PUBLIC,
|
|
102
|
+
name,
|
|
103
|
+
workspaceId,
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
return NextResponse.json({
|
|
107
|
+
apiKey: serializeApiKey({ apiKey }),
|
|
108
|
+
}, { headers: cacheHeaders });
|
|
109
|
+
};
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import { NextResponse } from 'next/server';
|
|
3
|
-
export declare const buildGET: ({ prisma: providedPrisma }?: {
|
|
4
|
-
prisma?: PrismaClient;
|
|
5
|
-
}) => () => Promise<NextResponse<{
|
|
1
|
+
export declare const GET: () => Promise<import("next/server").NextResponse<{
|
|
6
2
|
error: string;
|
|
7
|
-
}> | NextResponse<{
|
|
3
|
+
}> | import("next/server").NextResponse<{
|
|
8
4
|
apiKeys: {
|
|
9
5
|
id: string;
|
|
10
6
|
type: import("@prisma/client").$Enums.ApiKeyType;
|
|
@@ -14,12 +10,9 @@ export declare const buildGET: ({ prisma: providedPrisma }?: {
|
|
|
14
10
|
updatedAt: string;
|
|
15
11
|
}[];
|
|
16
12
|
}>>;
|
|
17
|
-
export declare const
|
|
18
|
-
export declare const buildPOST: ({ prisma: providedPrisma }?: {
|
|
19
|
-
prisma?: PrismaClient;
|
|
20
|
-
}) => (request: Request) => Promise<NextResponse<{
|
|
13
|
+
export declare const POST: (request: Request) => Promise<import("next/server").NextResponse<{
|
|
21
14
|
error: string;
|
|
22
|
-
}> | NextResponse<{
|
|
15
|
+
}> | import("next/server").NextResponse<{
|
|
23
16
|
apiKey: {
|
|
24
17
|
id: string;
|
|
25
18
|
type: import("@prisma/client").$Enums.ApiKeyType;
|
|
@@ -29,6 +22,5 @@ export declare const buildPOST: ({ prisma: providedPrisma }?: {
|
|
|
29
22
|
updatedAt: string;
|
|
30
23
|
};
|
|
31
24
|
}>>;
|
|
32
|
-
export declare const
|
|
33
|
-
export declare const OPTIONS: () => NextResponse<{}>;
|
|
25
|
+
export declare const OPTIONS: () => import("next/server").NextResponse<{}>;
|
|
34
26
|
//# sourceMappingURL=route.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../src/app/api/api-keys/route.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../src/app/api/api-keys/route.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,GAAG;;;;;;;;;;;GAEd,CAAA;AAEF,eAAO,MAAM,IAAI;;;;;;;;;;;GAEf,CAAA;AAEF,eAAO,MAAM,OAAO,8CAAiB,CAAA"}
|