@teamscala/service-boot 0.23.529 → 0.23.530

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/package.json CHANGED
@@ -5,6 +5,7 @@
5
5
  "edit": "edit src/ — dependencies and exports derive from imports; everything else preserved"
6
6
  },
7
7
  "dependencies": {
8
+ "@orpc/openapi": "*",
8
9
  "@orpc/server": "*",
9
10
  "@teamscala/agreement-generation": "*",
10
11
  "@teamscala/auth": "*",
@@ -290,5 +291,5 @@
290
291
  "repository": "https://github.com/teamgbg/service-boot",
291
292
  "sideEffects": false,
292
293
  "type": "module",
293
- "version": "0.23.529"
294
+ "version": "0.23.530"
294
295
  }
@@ -89,6 +89,10 @@ export async function mountOrpcRouter(
89
89
  const handler = new RPCHandler(router as never, {
90
90
  interceptors: [procedureErrorReportInterceptor()] as never,
91
91
  });
92
+ const { OpenAPIHandler } = await import("@orpc/openapi/fetch");
93
+ const openApiHandler = new OpenAPIHandler(router as never, {
94
+ interceptors: [procedureErrorReportInterceptor()] as never,
95
+ });
92
96
 
93
97
  const { getPrisma: getConfiguredPrisma } = await import(
94
98
  "@teamscala/orpc/configure"
@@ -146,6 +150,21 @@ export async function mountOrpcRouter(
146
150
  }
147
151
 
148
152
  const resolveUser = async (headers: Headers) => {
153
+ if (
154
+ openApiContractAuthorised({
155
+ authorization: headers.get("authorization"),
156
+ key: process.env.SCALA_DEV_KEY,
157
+ forwardedProto: headers.get("x-forwarded-proto"),
158
+ forwardedFor: headers.get("x-forwarded-for"),
159
+ })
160
+ ) {
161
+ return {
162
+ id: "service",
163
+ role: "super_admin" as const,
164
+ isSuperAdmin: true,
165
+ organisationId: null,
166
+ };
167
+ }
149
168
  if (isLocalhostRequest(headers)) {
150
169
  return {
151
170
  id: "localhost",
@@ -196,6 +215,21 @@ export async function mountOrpcRouter(
196
215
  },
197
216
  );
198
217
 
218
+ app.all(
219
+ "/api/openapi/*",
220
+ bodyLimit({
221
+ maxSize: 10 * 1024 * 1024,
222
+ onError: (c) => c.json({ error: "Request body too large" }, 413),
223
+ }),
224
+ async (c) => {
225
+ const result = await openApiHandler.handle(c.req.raw, {
226
+ prefix: "/api/openapi",
227
+ context: { prisma: getConfiguredPrisma(), db8, headers: c.req.raw.headers, resolveUser },
228
+ });
229
+ return result.matched ? result.response : c.notFound();
230
+ },
231
+ );
232
+
199
233
  app.get("/api/rpc/openapi.json", async (c) => {
200
234
  const header = (name: string) => c.req.header(name) ?? null;
201
235
  if (
@@ -17,7 +17,7 @@ export function openApiContractOptions(
17
17
  title: `${serviceSlug} oRPC procedures`,
18
18
  servers: [
19
19
  {
20
- url: `${forwardedProto || FALLBACK_PROTO}://${host || FALLBACK_HOST}/api/rpc`,
20
+ url: `${forwardedProto || FALLBACK_PROTO}://${host || FALLBACK_HOST}/api/openapi`,
21
21
  },
22
22
  ],
23
23
  };