@schemavaults/openapi-operations 0.1.4
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/README.md +164 -0
- package/dist/adapters/nextjs.d.ts +20 -0
- package/dist/adapters/nextjs.js +24 -0
- package/dist/adapters/nextjs.js.map +1 -0
- package/dist/adapters/vercel.d.ts +13 -0
- package/dist/adapters/vercel.js +15 -0
- package/dist/adapters/vercel.js.map +1 -0
- package/dist/auth-scheme.d.ts +101 -0
- package/dist/auth-scheme.js +125 -0
- package/dist/auth-scheme.js.map +1 -0
- package/dist/http-method.d.ts +8 -0
- package/dist/http-method.js +24 -0
- package/dist/http-method.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/openapi/build-openapi-document.d.ts +27 -0
- package/dist/openapi/build-openapi-document.js +124 -0
- package/dist/openapi/build-openapi-document.js.map +1 -0
- package/dist/openapi/extensions.d.ts +26 -0
- package/dist/openapi/extensions.js +47 -0
- package/dist/openapi/extensions.js.map +1 -0
- package/dist/openapi/path-format.d.ts +7 -0
- package/dist/openapi/path-format.js +26 -0
- package/dist/openapi/path-format.js.map +1 -0
- package/dist/operation.d.ts +168 -0
- package/dist/operation.js +111 -0
- package/dist/operation.js.map +1 -0
- package/dist/runtime/create-operations-app.d.ts +40 -0
- package/dist/runtime/create-operations-app.js +92 -0
- package/dist/runtime/create-operations-app.js.map +1 -0
- package/dist/runtime/errors.d.ts +42 -0
- package/dist/runtime/errors.js +37 -0
- package/dist/runtime/errors.js.map +1 -0
- package/dist/runtime/index.d.ts +8 -0
- package/dist/runtime/index.js +5 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/resolve-auth.d.ts +21 -0
- package/dist/runtime/resolve-auth.js +95 -0
- package/dist/runtime/resolve-auth.js.map +1 -0
- package/dist/runtime/validate-request.d.ts +13 -0
- package/dist/runtime/validate-request.js +121 -0
- package/dist/runtime/validate-request.js.map +1 -0
- package/dist/zod-openapi.d.ts +13 -0
- package/dist/zod-openapi.js +15 -0
- package/dist/zod-openapi.js.map +1 -0
- package/package.json +78 -0
package/README.md
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# @schemavaults/openapi-operations
|
|
2
|
+
|
|
3
|
+
Define HTTP operations once — method, path, [zod](https://zod.dev) v4 request/response
|
|
4
|
+
schemas, and the auth scheme + permissions a caller needs — then:
|
|
5
|
+
|
|
6
|
+
- generate an **OpenAPI 3.1 document** from them
|
|
7
|
+
(via [`@asteasolutions/zod-to-openapi`](https://github.com/asteasolutions/zod-to-openapi)), and
|
|
8
|
+
- serve them as a **[Hono](https://hono.dev) app** on Vercel functions or Next.js
|
|
9
|
+
App Router route handlers, with request validation and auth enforcement built in.
|
|
10
|
+
|
|
11
|
+
The same definitions power the auth server and third-party resource servers; only the
|
|
12
|
+
credential *resolvers* differ per host. `@schemavaults/openapi-docs-ui` renders the
|
|
13
|
+
generated document (routes, permissions, auth details) as browsable docs.
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
bun add @schemavaults/openapi-operations
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Defining operations
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import {
|
|
25
|
+
z,
|
|
26
|
+
createOperationDefiner,
|
|
27
|
+
requireAuth,
|
|
28
|
+
publicAccess,
|
|
29
|
+
schemaVaultsAccessTokenBearerScheme,
|
|
30
|
+
} from "@schemavaults/openapi-operations";
|
|
31
|
+
|
|
32
|
+
// Bind the per-request context and resolved-user types once per app.
|
|
33
|
+
const defineOperation = createOperationDefiner<{ dbh: Kysely<AuthDatabase> }, UserData>();
|
|
34
|
+
|
|
35
|
+
const AppSchema = z
|
|
36
|
+
.object({ app_id: z.string().uuid(), name: z.string() })
|
|
37
|
+
.openapi("App"); // emitted under components.schemas.App
|
|
38
|
+
|
|
39
|
+
export const getApp = defineOperation({
|
|
40
|
+
method: "get",
|
|
41
|
+
path: "/api/apps/{app_id}", // OpenAPI style placeholders
|
|
42
|
+
summary: "Get an app",
|
|
43
|
+
tags: ["apps"],
|
|
44
|
+
auth: requireAuth({
|
|
45
|
+
schemes: [schemaVaultsAccessTokenBearerScheme],
|
|
46
|
+
routeGuard: "authenticated", // or "admin"
|
|
47
|
+
requiredScopes: ["email"], // token scope claim must include these
|
|
48
|
+
organization: { parameter: "organization_id", roles: ["owner", "admin"] }, // optional
|
|
49
|
+
}),
|
|
50
|
+
request: {
|
|
51
|
+
params: z.object({ app_id: z.string().uuid() }),
|
|
52
|
+
query: z.object({ include: z.union([z.string(), z.array(z.string())]).optional() }),
|
|
53
|
+
headers: z.object({ "x-trace": z.string().optional() }),
|
|
54
|
+
// body: { contentType: "application/json", schema: ... } (POST/PUT/PATCH/DELETE only)
|
|
55
|
+
},
|
|
56
|
+
responses: {
|
|
57
|
+
200: { description: "The app", schema: AppSchema },
|
|
58
|
+
404: { description: "Not found", schema: ErrorSchema },
|
|
59
|
+
},
|
|
60
|
+
handler: async (ctx) => {
|
|
61
|
+
// ctx.params / ctx.query / ctx.headers / ctx.body are validated & typed
|
|
62
|
+
// ctx.auth is the AuthPrincipal (null only on publicAccess() operations)
|
|
63
|
+
// ctx.context is whatever createOperationsApp({ context }) produced
|
|
64
|
+
const app = await ctx.context.dbh.selectFrom("APPS")...;
|
|
65
|
+
if (!app) return ctx.json(404, { success: false, message: "No such app" });
|
|
66
|
+
return ctx.json(200, app); // status + body are checked against `responses`
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
export const health = defineOperation({
|
|
71
|
+
method: "get",
|
|
72
|
+
path: "/api/health",
|
|
73
|
+
summary: "Liveness probe",
|
|
74
|
+
auth: publicAccess(),
|
|
75
|
+
responses: { 200: { description: "ok", schema: z.object({ ok: z.literal(true) }) } },
|
|
76
|
+
handler: (ctx) => ctx.json(200, { ok: true }),
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
`defineOperationGroup({ pathPrefix, tags, operations })` applies a shared prefix and tags.
|
|
81
|
+
Throw `new OperationError(status, { error, message })` from a handler to short-circuit.
|
|
82
|
+
|
|
83
|
+
### Auth schemes
|
|
84
|
+
|
|
85
|
+
An `AuthSchemeDefinition` is a named OpenAPI security scheme plus docs metadata. Built-ins:
|
|
86
|
+
|
|
87
|
+
| Export | Scheme |
|
|
88
|
+
| --- | --- |
|
|
89
|
+
| `schemaVaultsAccessTokenBearerScheme` | `Authorization: Bearer <access token>` |
|
|
90
|
+
| `schemaVaultsAccessTokenCookieScheme(cookieName)` | first-party access token cookie |
|
|
91
|
+
| `schemaVaultsRefreshTokenCookieScheme(cookieName)` | auth-server session cookie |
|
|
92
|
+
| `oidcClientSecretBasicScheme` / `oidcClientSecretPostScheme` | OAuth 2.0 client authentication |
|
|
93
|
+
| `apiKeyHeaderScheme(name, header)` | static API key |
|
|
94
|
+
| `defineAuthScheme({...})` | anything else |
|
|
95
|
+
|
|
96
|
+
Schemes describe *how* credentials are transported; verification is a per-host
|
|
97
|
+
`AuthResolver` (below). The OpenAPI document carries the standard `security`
|
|
98
|
+
requirement per operation and an `x-schemavaults-auth` extension with the route guard,
|
|
99
|
+
required scopes and organization role so docs can display them.
|
|
100
|
+
|
|
101
|
+
## Generating the OpenAPI document
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
import { buildOpenApiDocument } from "@schemavaults/openapi-operations";
|
|
105
|
+
|
|
106
|
+
export const openApiDocument = buildOpenApiDocument({
|
|
107
|
+
info: { title: "SchemaVaults Auth API", version: "1.0.0" },
|
|
108
|
+
servers: [{ url: "https://auth.schemavaults.com" }],
|
|
109
|
+
tags: [{ name: "apps", description: "Client applications" }],
|
|
110
|
+
operations: [getApp, health],
|
|
111
|
+
});
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Serving with Hono on Vercel / Next.js
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
import { createOperationsApp, toNextRouteHandlers } from "@schemavaults/openapi-operations";
|
|
118
|
+
|
|
119
|
+
const app = createOperationsApp<{ dbh: Kysely<AuthDatabase> }, UserData>({
|
|
120
|
+
operations: [getApp, health],
|
|
121
|
+
context: async () => ({ dbh: await getDbh() }),
|
|
122
|
+
authResolvers: {
|
|
123
|
+
// keyed by scheme name; return null when no credential for that scheme is present
|
|
124
|
+
"schemavaults-access-token": async (c) => {
|
|
125
|
+
const token = c.req.header("authorization")?.replace(/^Bearer /, "");
|
|
126
|
+
if (!token) return null;
|
|
127
|
+
const user = await verifyAccessToken(token); // throw OperationError(401, ...) if invalid
|
|
128
|
+
return {
|
|
129
|
+
scheme: "schemavaults-access-token",
|
|
130
|
+
user,
|
|
131
|
+
isAdmin: user.admin,
|
|
132
|
+
scope: user.scope ?? null,
|
|
133
|
+
getOrganizationRole: (orgId) => lookupMembershipRole(user.uid, orgId),
|
|
134
|
+
};
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
// Served at GET /openapi.json. Pass a function to build it per request,
|
|
138
|
+
// e.g. to set `servers` from the incoming Host / X-Forwarded-* headers.
|
|
139
|
+
openapi: { document: openApiDocument },
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// app/api/[[...route]]/route.ts
|
|
143
|
+
export const runtime = "nodejs";
|
|
144
|
+
export const { GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS } = toNextRouteHandlers(app);
|
|
145
|
+
|
|
146
|
+
// or a plain Vercel function: api/[[...route]].ts
|
|
147
|
+
export default toVercelHandler(app);
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Per request the app: resolves the context, tries each accepted scheme's resolver in
|
|
151
|
+
order (401 + `WWW-Authenticate` if none yields a principal), enforces the route guard
|
|
152
|
+
(403), required scopes (403 `insufficient_scope`), organization membership (403), then
|
|
153
|
+
validates params/query/headers/body (400 with zod issues, 415 on media type mismatch)
|
|
154
|
+
and finally calls the handler. Errors use the `{ success: false, error, message }`
|
|
155
|
+
envelope.
|
|
156
|
+
|
|
157
|
+
## Scripts
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
bun run build # tsc + tsc-alias → dist/
|
|
161
|
+
bun run test # bun test
|
|
162
|
+
bun run lint
|
|
163
|
+
bun run typecheck
|
|
164
|
+
```
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Hono } from "hono";
|
|
2
|
+
import { HTTP_METHODS, type HttpMethod } from "../http-method";
|
|
3
|
+
export type NextRouteHandler = (request: Request) => Response | Promise<Response>;
|
|
4
|
+
export type NextRouteHandlers<TMethods extends HttpMethod = HttpMethod> = {
|
|
5
|
+
readonly [M in TMethods as Uppercase<M>]: NextRouteHandler;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Next.js App Router route-handler exports for the operations app. Typical
|
|
9
|
+
* usage from a catch-all route so one Hono app serves every operation:
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* // app/api/[[...route]]/route.ts
|
|
13
|
+
* export const runtime = "nodejs";
|
|
14
|
+
* export const { GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS } = toNextRouteHandlers(app);
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* Pass `methods` to only export a subset (e.g. when a route file coexists
|
|
18
|
+
* with hand-written handlers for other methods).
|
|
19
|
+
*/
|
|
20
|
+
export declare function toNextRouteHandlers<const TMethods extends readonly HttpMethod[] = typeof HTTP_METHODS>(app: Hono, methods?: TMethods): NextRouteHandlers<TMethods[number]>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { handle } from "hono/vercel";
|
|
2
|
+
import { HTTP_METHODS } from "../http-method";
|
|
3
|
+
/**
|
|
4
|
+
* Next.js App Router route-handler exports for the operations app. Typical
|
|
5
|
+
* usage from a catch-all route so one Hono app serves every operation:
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* // app/api/[[...route]]/route.ts
|
|
9
|
+
* export const runtime = "nodejs";
|
|
10
|
+
* export const { GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS } = toNextRouteHandlers(app);
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* Pass `methods` to only export a subset (e.g. when a route file coexists
|
|
14
|
+
* with hand-written handlers for other methods).
|
|
15
|
+
*/
|
|
16
|
+
export function toNextRouteHandlers(app, methods = HTTP_METHODS) {
|
|
17
|
+
const handler = handle(app);
|
|
18
|
+
const handlers = {};
|
|
19
|
+
for (const method of methods) {
|
|
20
|
+
handlers[method.toUpperCase()] = handler;
|
|
21
|
+
}
|
|
22
|
+
return handlers;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=nextjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nextjs.js","sourceRoot":"","sources":["../../src/adapters/nextjs.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,YAAY,EAAmB,MAAM,gBAAgB,CAAC;AAQ/D;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,mBAAmB,CACjC,GAAS,EACT,UAAoB,YAAmC;IAEvD,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IAC5B,MAAM,QAAQ,GAAqC,EAAE,CAAC;IACtD,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,GAAG,OAAO,CAAC;IAC3C,CAAC;IACD,OAAO,QAA+C,CAAC;AACzD,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Hono } from "hono";
|
|
2
|
+
export type VercelFunctionHandler = (request: Request) => Response | Promise<Response>;
|
|
3
|
+
/**
|
|
4
|
+
* Wraps the operations app as a Vercel (Fluid / Node.js / Edge) function
|
|
5
|
+
* handler using Hono's Vercel adapter. Export it from a `api/*.ts` function
|
|
6
|
+
* file or a Next.js route handler:
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* // api/[[...route]].ts
|
|
10
|
+
* export default toVercelHandler(app);
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare function toVercelHandler(app: Hono): VercelFunctionHandler;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { handle } from "hono/vercel";
|
|
2
|
+
/**
|
|
3
|
+
* Wraps the operations app as a Vercel (Fluid / Node.js / Edge) function
|
|
4
|
+
* handler using Hono's Vercel adapter. Export it from a `api/*.ts` function
|
|
5
|
+
* file or a Next.js route handler:
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* // api/[[...route]].ts
|
|
9
|
+
* export default toVercelHandler(app);
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export function toVercelHandler(app) {
|
|
13
|
+
return handle(app);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=vercel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vercel.js","sourceRoot":"","sources":["../../src/adapters/vercel.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAIrC;;;;;;;;;GASG;AACH,MAAM,UAAU,eAAe,CAAC,GAAS;IACvC,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type { SecuritySchemeObject } from "openapi3-ts/oas31";
|
|
2
|
+
import type { OrganizationMembershipRoleType } from "@schemavaults/auth-common/organizations";
|
|
3
|
+
/**
|
|
4
|
+
* A named OpenAPI security scheme (`components.securitySchemes[name]`) plus
|
|
5
|
+
* the metadata the SchemaVaults docs UI uses to explain how to authenticate.
|
|
6
|
+
*
|
|
7
|
+
* The scheme only DESCRIBES how credentials are transported. Verifying them
|
|
8
|
+
* is the job of an {@link AuthResolver} registered with the Hono app under
|
|
9
|
+
* the same `name`, so the same operation definitions can run on the auth
|
|
10
|
+
* server (which can decrypt its own tokens) and on a third-party resource
|
|
11
|
+
* server (which verifies them against the auth server's JWKS).
|
|
12
|
+
*/
|
|
13
|
+
export interface AuthSchemeDefinition<TName extends string = string> {
|
|
14
|
+
/** Key under `components.securitySchemes` and in `security` requirements. */
|
|
15
|
+
readonly name: TName;
|
|
16
|
+
/** Human readable label for docs. */
|
|
17
|
+
readonly title: string;
|
|
18
|
+
/** Longer explanation for docs (where to get the credential, lifetime, ...). */
|
|
19
|
+
readonly description?: string;
|
|
20
|
+
/** The OpenAPI 3.1 security scheme object emitted into the document. */
|
|
21
|
+
readonly securityScheme: SecuritySchemeObject;
|
|
22
|
+
/**
|
|
23
|
+
* Value for the `WWW-Authenticate` header of a 401 produced when no
|
|
24
|
+
* credential for this scheme was presented (RFC 7235 §4.1). Optional;
|
|
25
|
+
* schemes without a challenge (cookies, api keys) omit it.
|
|
26
|
+
*/
|
|
27
|
+
readonly challenge?: string;
|
|
28
|
+
}
|
|
29
|
+
export declare function defineAuthScheme<const TName extends string>(definition: AuthSchemeDefinition<TName>): AuthSchemeDefinition<TName>;
|
|
30
|
+
/**
|
|
31
|
+
* Route guard levels mirroring `@schemavaults/auth-server-sdk`'s
|
|
32
|
+
* `withAuthenticatedApiRouteGuard` / `withAdminApiRouteGuard`.
|
|
33
|
+
*/
|
|
34
|
+
export declare const ROUTE_GUARD_TYPES: readonly ["authenticated", "admin"];
|
|
35
|
+
export type RouteGuardType = (typeof ROUTE_GUARD_TYPES)[number];
|
|
36
|
+
/**
|
|
37
|
+
* Membership requirement within the organization named by a path/query
|
|
38
|
+
* parameter of the operation. Mirrors `required_organization` +
|
|
39
|
+
* `custom_is_user_in_organization` on the server SDK route guard: platform
|
|
40
|
+
* administrators bypass the membership check unless `adminBypass` is false.
|
|
41
|
+
*/
|
|
42
|
+
export interface OrganizationRoleRequirement {
|
|
43
|
+
/** Name of the request parameter (path, then query) carrying the organization id. */
|
|
44
|
+
readonly parameter: string;
|
|
45
|
+
/** Accepted membership roles. Empty means "any member". */
|
|
46
|
+
readonly roles: readonly OrganizationMembershipRoleType[];
|
|
47
|
+
/** Whether platform admins satisfy the requirement without membership (default true). */
|
|
48
|
+
readonly adminBypass?: boolean;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* What a caller must present / be to invoke an operation. Represented in
|
|
52
|
+
* the OpenAPI document both as the standard `security` requirement list
|
|
53
|
+
* (one entry per accepted scheme, carrying the scopes) and as the
|
|
54
|
+
* `x-schemavaults-auth` vendor extension so docs can show the route guard
|
|
55
|
+
* and organization role in addition to the scopes.
|
|
56
|
+
*/
|
|
57
|
+
export interface AuthRequirements {
|
|
58
|
+
/** Schemes accepted for this operation (any one of them satisfies it). */
|
|
59
|
+
readonly schemes: readonly AuthSchemeDefinition[];
|
|
60
|
+
/** Who may call once authenticated. Defaults to "authenticated". */
|
|
61
|
+
readonly routeGuard?: RouteGuardType;
|
|
62
|
+
/**
|
|
63
|
+
* Scopes the presented token's `scope` claim must include. A token with no
|
|
64
|
+
* scope claim grants no scopes, so any non-empty list denies it (403).
|
|
65
|
+
* There is no admin bypass: scopes describe what the TOKEN was granted.
|
|
66
|
+
*/
|
|
67
|
+
readonly requiredScopes?: readonly string[];
|
|
68
|
+
/** Organization membership requirement resolved from a request parameter. */
|
|
69
|
+
readonly organization?: OrganizationRoleRequirement;
|
|
70
|
+
/** Free-form note for the docs ("only the app owner may ...", ...). */
|
|
71
|
+
readonly notes?: string;
|
|
72
|
+
}
|
|
73
|
+
export interface PublicOperationAuth {
|
|
74
|
+
readonly type: "public";
|
|
75
|
+
readonly notes?: string;
|
|
76
|
+
}
|
|
77
|
+
export interface RequiredOperationAuth extends AuthRequirements {
|
|
78
|
+
readonly type: "required";
|
|
79
|
+
}
|
|
80
|
+
export type OperationAuth = PublicOperationAuth | RequiredOperationAuth;
|
|
81
|
+
/** Marks an operation as callable without credentials. */
|
|
82
|
+
export declare function publicAccess(notes?: string): PublicOperationAuth;
|
|
83
|
+
/** Marks an operation as requiring one of the given schemes (+ extra checks). */
|
|
84
|
+
export declare function requireAuth(requirements: AuthRequirements): RequiredOperationAuth;
|
|
85
|
+
export declare function isPublicOperationAuth(auth: OperationAuth): auth is PublicOperationAuth;
|
|
86
|
+
/** `Authorization: Bearer <access token>` issued by the SchemaVaults auth server. */
|
|
87
|
+
export declare const schemaVaultsAccessTokenBearerScheme: AuthSchemeDefinition<"schemavaults-access-token">;
|
|
88
|
+
/**
|
|
89
|
+
* The first-party access-token cookie set by the auth server / resource
|
|
90
|
+
* server SDK (`AccessTokenCookieName(api_server_id)`). The cookie name is
|
|
91
|
+
* per API server, so the concrete name is filled in by the caller.
|
|
92
|
+
*/
|
|
93
|
+
export declare function schemaVaultsAccessTokenCookieScheme(cookieName: string): AuthSchemeDefinition<"schemavaults-access-token-cookie">;
|
|
94
|
+
/** The auth server's own refresh-token cookie (only meaningful ON the auth server). */
|
|
95
|
+
export declare function schemaVaultsRefreshTokenCookieScheme(cookieName: string): AuthSchemeDefinition<"schemavaults-refresh-token-cookie">;
|
|
96
|
+
/** OAuth 2.0 `client_secret_basic` client authentication (RFC 6749 §2.3.1). */
|
|
97
|
+
export declare const oidcClientSecretBasicScheme: AuthSchemeDefinition<"oidc-client-secret-basic">;
|
|
98
|
+
/** OAuth 2.0 `client_secret_post` client authentication (credentials in the form body). */
|
|
99
|
+
export declare const oidcClientSecretPostScheme: AuthSchemeDefinition<"oidc-client-secret-post">;
|
|
100
|
+
/** A static API key in a header (e.g. cron / internal automation). */
|
|
101
|
+
export declare function apiKeyHeaderScheme<const TName extends string>(name: TName, headerName: string, description?: string): AuthSchemeDefinition<TName>;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
export function defineAuthScheme(definition) {
|
|
2
|
+
if (typeof definition.name !== "string" || definition.name.length === 0) {
|
|
3
|
+
throw new TypeError("An auth scheme needs a non-empty name");
|
|
4
|
+
}
|
|
5
|
+
if (!/^[A-Za-z0-9._-]+$/.test(definition.name)) {
|
|
6
|
+
throw new TypeError(`Auth scheme name "${definition.name}" must match /^[A-Za-z0-9._-]+$/ (it becomes an OpenAPI component key)`);
|
|
7
|
+
}
|
|
8
|
+
return Object.freeze({ ...definition });
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Route guard levels mirroring `@schemavaults/auth-server-sdk`'s
|
|
12
|
+
* `withAuthenticatedApiRouteGuard` / `withAdminApiRouteGuard`.
|
|
13
|
+
*/
|
|
14
|
+
export const ROUTE_GUARD_TYPES = ["authenticated", "admin"];
|
|
15
|
+
/** Marks an operation as callable without credentials. */
|
|
16
|
+
export function publicAccess(notes) {
|
|
17
|
+
return notes === undefined ? { type: "public" } : { type: "public", notes };
|
|
18
|
+
}
|
|
19
|
+
/** Marks an operation as requiring one of the given schemes (+ extra checks). */
|
|
20
|
+
export function requireAuth(requirements) {
|
|
21
|
+
if (!Array.isArray(requirements.schemes) || requirements.schemes.length === 0) {
|
|
22
|
+
throw new TypeError("requireAuth() needs at least one auth scheme; use publicAccess() for open operations");
|
|
23
|
+
}
|
|
24
|
+
const names = new Set();
|
|
25
|
+
for (const scheme of requirements.schemes) {
|
|
26
|
+
if (names.has(scheme.name)) {
|
|
27
|
+
throw new TypeError(`Auth scheme "${scheme.name}" listed twice`);
|
|
28
|
+
}
|
|
29
|
+
names.add(scheme.name);
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
type: "required",
|
|
33
|
+
...requirements,
|
|
34
|
+
routeGuard: requirements.routeGuard ?? "authenticated",
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export function isPublicOperationAuth(auth) {
|
|
38
|
+
return auth.type === "public";
|
|
39
|
+
}
|
|
40
|
+
// ---------------------------------------------------------------------------
|
|
41
|
+
// Built-in SchemaVaults schemes
|
|
42
|
+
// ---------------------------------------------------------------------------
|
|
43
|
+
/** `Authorization: Bearer <access token>` issued by the SchemaVaults auth server. */
|
|
44
|
+
export const schemaVaultsAccessTokenBearerScheme = defineAuthScheme({
|
|
45
|
+
name: "schemavaults-access-token",
|
|
46
|
+
title: "SchemaVaults access token (Bearer)",
|
|
47
|
+
description: "An access token issued by the SchemaVaults auth server for this API server, sent as `Authorization: Bearer <token>`.",
|
|
48
|
+
securityScheme: {
|
|
49
|
+
type: "http",
|
|
50
|
+
scheme: "bearer",
|
|
51
|
+
bearerFormat: "JWT",
|
|
52
|
+
description: "Access token issued by the SchemaVaults auth server for this API server.",
|
|
53
|
+
},
|
|
54
|
+
challenge: 'Bearer realm="schemavaults"',
|
|
55
|
+
});
|
|
56
|
+
/**
|
|
57
|
+
* The first-party access-token cookie set by the auth server / resource
|
|
58
|
+
* server SDK (`AccessTokenCookieName(api_server_id)`). The cookie name is
|
|
59
|
+
* per API server, so the concrete name is filled in by the caller.
|
|
60
|
+
*/
|
|
61
|
+
export function schemaVaultsAccessTokenCookieScheme(cookieName) {
|
|
62
|
+
return defineAuthScheme({
|
|
63
|
+
name: "schemavaults-access-token-cookie",
|
|
64
|
+
title: "SchemaVaults access token (cookie)",
|
|
65
|
+
description: `The first-party HTTP-only access token cookie \`${cookieName}\` set after login.`,
|
|
66
|
+
securityScheme: {
|
|
67
|
+
type: "apiKey",
|
|
68
|
+
in: "cookie",
|
|
69
|
+
name: cookieName,
|
|
70
|
+
description: "First-party access token cookie set by the SchemaVaults auth flow.",
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/** The auth server's own refresh-token cookie (only meaningful ON the auth server). */
|
|
75
|
+
export function schemaVaultsRefreshTokenCookieScheme(cookieName) {
|
|
76
|
+
return defineAuthScheme({
|
|
77
|
+
name: "schemavaults-refresh-token-cookie",
|
|
78
|
+
title: "SchemaVaults session (refresh token cookie)",
|
|
79
|
+
description: `The auth server's HTTP-only refresh token cookie \`${cookieName}\`; only the auth server itself can resolve it.`,
|
|
80
|
+
securityScheme: {
|
|
81
|
+
type: "apiKey",
|
|
82
|
+
in: "cookie",
|
|
83
|
+
name: cookieName,
|
|
84
|
+
description: "Auth server session cookie.",
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/** OAuth 2.0 `client_secret_basic` client authentication (RFC 6749 §2.3.1). */
|
|
89
|
+
export const oidcClientSecretBasicScheme = defineAuthScheme({
|
|
90
|
+
name: "oidc-client-secret-basic",
|
|
91
|
+
title: "OAuth 2.0 client credentials (HTTP Basic)",
|
|
92
|
+
description: "Confidential client authentication: `Authorization: Basic base64(client_id:client_secret)` (client_secret_basic).",
|
|
93
|
+
securityScheme: {
|
|
94
|
+
type: "http",
|
|
95
|
+
scheme: "basic",
|
|
96
|
+
description: "client_secret_basic — RFC 6749 §2.3.1",
|
|
97
|
+
},
|
|
98
|
+
challenge: 'Basic realm="schemavaults"',
|
|
99
|
+
});
|
|
100
|
+
/** OAuth 2.0 `client_secret_post` client authentication (credentials in the form body). */
|
|
101
|
+
export const oidcClientSecretPostScheme = defineAuthScheme({
|
|
102
|
+
name: "oidc-client-secret-post",
|
|
103
|
+
title: "OAuth 2.0 client credentials (form body)",
|
|
104
|
+
description: "Confidential client authentication with `client_id` and `client_secret` in the `application/x-www-form-urlencoded` body (client_secret_post).",
|
|
105
|
+
securityScheme: {
|
|
106
|
+
type: "apiKey",
|
|
107
|
+
in: "header",
|
|
108
|
+
name: "X-SchemaVaults-Client-Secret-Post",
|
|
109
|
+
description: "Documentation placeholder: credentials travel in the form body as client_id/client_secret (client_secret_post, RFC 6749 §2.3.1).",
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
/** A static API key in a header (e.g. cron / internal automation). */
|
|
113
|
+
export function apiKeyHeaderScheme(name, headerName, description) {
|
|
114
|
+
return defineAuthScheme({
|
|
115
|
+
name,
|
|
116
|
+
title: `API key (${headerName})`,
|
|
117
|
+
description: description ?? `A pre-shared API key sent in the \`${headerName}\` header.`,
|
|
118
|
+
securityScheme: {
|
|
119
|
+
type: "apiKey",
|
|
120
|
+
in: "header",
|
|
121
|
+
name: headerName,
|
|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 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP methods an operation can be declared with. Lower-case to match the
|
|
3
|
+
* OpenAPI `paths` object keys; adapters upper-case them for routing.
|
|
4
|
+
*/
|
|
5
|
+
export declare const HTTP_METHODS: readonly ["get", "post", "put", "patch", "delete", "head", "options"];
|
|
6
|
+
export type HttpMethod = (typeof HTTP_METHODS)[number];
|
|
7
|
+
export declare function isHttpMethod(value: unknown): value is HttpMethod;
|
|
8
|
+
export declare const HTTP_METHODS_WITH_REQUEST_BODY: ReadonlySet<HttpMethod>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP methods an operation can be declared with. Lower-case to match the
|
|
3
|
+
* OpenAPI `paths` object keys; adapters upper-case them for routing.
|
|
4
|
+
*/
|
|
5
|
+
export const HTTP_METHODS = [
|
|
6
|
+
"get",
|
|
7
|
+
"post",
|
|
8
|
+
"put",
|
|
9
|
+
"patch",
|
|
10
|
+
"delete",
|
|
11
|
+
"head",
|
|
12
|
+
"options",
|
|
13
|
+
];
|
|
14
|
+
export function isHttpMethod(value) {
|
|
15
|
+
return (typeof value === "string" &&
|
|
16
|
+
HTTP_METHODS.includes(value));
|
|
17
|
+
}
|
|
18
|
+
export const HTTP_METHODS_WITH_REQUEST_BODY = new Set([
|
|
19
|
+
"post",
|
|
20
|
+
"put",
|
|
21
|
+
"patch",
|
|
22
|
+
"delete",
|
|
23
|
+
]);
|
|
24
|
+
//# sourceMappingURL=http-method.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-method.js","sourceRoot":"","sources":["../src/http-method.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,KAAK;IACL,MAAM;IACN,KAAK;IACL,OAAO;IACP,QAAQ;IACR,MAAM;IACN,SAAS;CACD,CAAC;AAIX,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACxB,YAAkC,CAAC,QAAQ,CAAC,KAAK,CAAC,CACpD,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,8BAA8B,GAA4B,IAAI,GAAG,CAAa;IACzF,MAAM;IACN,KAAK;IACL,OAAO;IACP,QAAQ;CACT,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export { z } from "./zod-openapi";
|
|
2
|
+
export type { ZodType, ZodObject } from "./zod-openapi";
|
|
3
|
+
export { HTTP_METHODS, HTTP_METHODS_WITH_REQUEST_BODY, isHttpMethod } from "./http-method";
|
|
4
|
+
export type { HttpMethod } from "./http-method";
|
|
5
|
+
export { defineAuthScheme, publicAccess, requireAuth, isPublicOperationAuth, ROUTE_GUARD_TYPES, schemaVaultsAccessTokenBearerScheme, schemaVaultsAccessTokenCookieScheme, schemaVaultsRefreshTokenCookieScheme, oidcClientSecretBasicScheme, oidcClientSecretPostScheme, apiKeyHeaderScheme, } from "./auth-scheme";
|
|
6
|
+
export type { AuthSchemeDefinition, AuthRequirements, OperationAuth, PublicOperationAuth, RequiredOperationAuth, OrganizationRoleRequirement, RouteGuardType, } from "./auth-scheme";
|
|
7
|
+
export { defineOperation, createOperationDefiner, defineOperationGroup, defaultOperationId, assertUniqueOperations, } from "./operation";
|
|
8
|
+
export type { AnyOperationDefinition, AuthPrincipal, EmptyResponseStatusOf, InferBody, InferParsed, OperationDefiner, OperationDefinition, OperationGroup, OperationHandlerContext, OperationHandlerResult, OperationInput, OperationRequestDefinition, RequestBodyContentType, RequestBodyDefinition, ResponseBodyOf, ResponseDefinition, ResponseStatusOf, ResponsesDefinition, } from "./operation";
|
|
9
|
+
export { buildOpenApiDocument, collectAuthSchemes, toRouteConfig, toSecuritySchemeComponent, } from "./openapi/build-openapi-document";
|
|
10
|
+
export type { BuildOpenApiDocumentOptions } from "./openapi/build-openapi-document";
|
|
11
|
+
export { SCHEMAVAULTS_AUTH_EXTENSION, SCHEMAVAULTS_SCHEME_TITLE_EXTENSION, SCHEMAVAULTS_SCHEME_CHALLENGE_EXTENSION, toSchemaVaultsAuthExtension, isSchemaVaultsAuthExtension, } from "./openapi/extensions";
|
|
12
|
+
export type { SchemaVaultsAuthExtension } from "./openapi/extensions";
|
|
13
|
+
export { extractPathParameterNames, openApiPathToHonoPath, honoPathToOpenApiPath, isOpenApiPath, } from "./openapi/path-format";
|
|
14
|
+
export * from "./runtime";
|
|
15
|
+
export type { Hono, Context as HonoContext } from "hono";
|
|
16
|
+
export { getCookie, getSignedCookie } from "hono/cookie";
|
|
17
|
+
export { toVercelHandler } from "./adapters/vercel";
|
|
18
|
+
export type { VercelFunctionHandler } from "./adapters/vercel";
|
|
19
|
+
export { toNextRouteHandlers } from "./adapters/nextjs";
|
|
20
|
+
export type { NextRouteHandler, NextRouteHandlers } from "./adapters/nextjs";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { z } from "./zod-openapi";
|
|
2
|
+
export { HTTP_METHODS, HTTP_METHODS_WITH_REQUEST_BODY, isHttpMethod } from "./http-method";
|
|
3
|
+
export { defineAuthScheme, publicAccess, requireAuth, isPublicOperationAuth, ROUTE_GUARD_TYPES, schemaVaultsAccessTokenBearerScheme, schemaVaultsAccessTokenCookieScheme, schemaVaultsRefreshTokenCookieScheme, oidcClientSecretBasicScheme, oidcClientSecretPostScheme, apiKeyHeaderScheme, } from "./auth-scheme";
|
|
4
|
+
export { defineOperation, createOperationDefiner, defineOperationGroup, defaultOperationId, assertUniqueOperations, } from "./operation";
|
|
5
|
+
export { buildOpenApiDocument, collectAuthSchemes, toRouteConfig, toSecuritySchemeComponent, } from "./openapi/build-openapi-document";
|
|
6
|
+
export { SCHEMAVAULTS_AUTH_EXTENSION, SCHEMAVAULTS_SCHEME_TITLE_EXTENSION, SCHEMAVAULTS_SCHEME_CHALLENGE_EXTENSION, toSchemaVaultsAuthExtension, isSchemaVaultsAuthExtension, } from "./openapi/extensions";
|
|
7
|
+
export { extractPathParameterNames, openApiPathToHonoPath, honoPathToOpenApiPath, isOpenApiPath, } from "./openapi/path-format";
|
|
8
|
+
export * from "./runtime";
|
|
9
|
+
export { getCookie, getSignedCookie } from "hono/cookie";
|
|
10
|
+
export { toVercelHandler } from "./adapters/vercel";
|
|
11
|
+
export { toNextRouteHandlers } from "./adapters/nextjs";
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAGlC,OAAO,EAAE,YAAY,EAAE,8BAA8B,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAG3F,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,qBAAqB,EACrB,iBAAiB,EACjB,mCAAmC,EACnC,mCAAmC,EACnC,oCAAoC,EACpC,2BAA2B,EAC3B,0BAA0B,EAC1B,kBAAkB,GACnB,MAAM,eAAe,CAAC;AAWvB,OAAO,EACL,eAAe,EACf,sBAAsB,EACtB,oBAAoB,EACpB,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,aAAa,CAAC;AAsBrB,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,aAAa,EACb,yBAAyB,GAC1B,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EACL,2BAA2B,EAC3B,mCAAmC,EACnC,uCAAuC,EACvC,2BAA2B,EAC3B,2BAA2B,GAC5B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,yBAAyB,EACzB,qBAAqB,EACrB,qBAAqB,EACrB,aAAa,GACd,MAAM,uBAAuB,CAAC;AAE/B,cAAc,WAAW,CAAC;AAI1B,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type RouteConfig } from "@asteasolutions/zod-to-openapi";
|
|
2
|
+
import type { ExternalDocumentationObject, InfoObject, OpenAPIObject, SecuritySchemeObject, ServerObject, TagObject } from "openapi3-ts/oas31";
|
|
3
|
+
import type { AuthSchemeDefinition } from "../auth-scheme";
|
|
4
|
+
import type { AnyOperationDefinition } from "../operation";
|
|
5
|
+
export interface BuildOpenApiDocumentOptions {
|
|
6
|
+
readonly info: InfoObject;
|
|
7
|
+
readonly operations: readonly AnyOperationDefinition[];
|
|
8
|
+
readonly servers?: readonly ServerObject[];
|
|
9
|
+
/** Tag descriptions; tags used by operations but not listed here are added bare. */
|
|
10
|
+
readonly tags?: readonly TagObject[];
|
|
11
|
+
readonly externalDocs?: ExternalDocumentationObject;
|
|
12
|
+
/** Schemes to document even when no operation references them. */
|
|
13
|
+
readonly additionalAuthSchemes?: readonly AuthSchemeDefinition[];
|
|
14
|
+
/** Document-level vendor extensions. */
|
|
15
|
+
readonly extensions?: Readonly<Record<`x-${string}`, unknown>>;
|
|
16
|
+
}
|
|
17
|
+
/** Every distinct auth scheme referenced by the operations (first definition wins per name). */
|
|
18
|
+
export declare function collectAuthSchemes(operations: readonly AnyOperationDefinition[], additional?: readonly AuthSchemeDefinition[]): AuthSchemeDefinition[];
|
|
19
|
+
export declare function toSecuritySchemeComponent(scheme: AuthSchemeDefinition): SecuritySchemeObject;
|
|
20
|
+
/** zod-to-openapi route config for one operation (also usable with `@hono/zod-openapi`). */
|
|
21
|
+
export declare function toRouteConfig(operation: AnyOperationDefinition): RouteConfig;
|
|
22
|
+
/**
|
|
23
|
+
* Builds an OpenAPI 3.1 document from operation definitions using
|
|
24
|
+
* `@asteasolutions/zod-to-openapi`. Zod schemas registered with
|
|
25
|
+
* `.openapi("RefId")` are emitted under `components.schemas`.
|
|
26
|
+
*/
|
|
27
|
+
export declare function buildOpenApiDocument(options: BuildOpenApiDocumentOptions): OpenAPIObject;
|