@q32/core 0.1.20 → 0.1.22
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 +10 -2
- package/dist/auth.d.ts +98 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +230 -0
- package/dist/auth.js.map +1 -0
- package/dist/hono.d.ts +22 -0
- package/dist/hono.d.ts.map +1 -0
- package/dist/hono.js +26 -0
- package/dist/hono.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/jobs.d.ts +394 -6
- package/dist/jobs.d.ts.map +1 -1
- package/dist/jobs.js +1134 -62
- package/dist/jobs.js.map +1 -1
- package/dist/react-router.d.ts +14 -0
- package/dist/react-router.d.ts.map +1 -0
- package/dist/react-router.js +30 -0
- package/dist/react-router.js.map +1 -0
- package/docs/evaluation.md +5 -4
- package/docs/jobs.md +49 -0
- package/package.json +13 -1
- package/src/auth.ts +338 -0
- package/src/hono.ts +54 -0
- package/src/index.ts +3 -0
- package/src/jobs.ts +1665 -71
- package/src/react-router.ts +53 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { AuthSystem, McpAuthService, McpAuthorizationParams } from "./auth.js";
|
|
2
|
+
import { HttpError, jsonResponse } from "./http.js";
|
|
3
|
+
import type { OAuthClientInformation } from "./oauth.js";
|
|
4
|
+
|
|
5
|
+
export type ReactRouterRequestArgs = {
|
|
6
|
+
request: Request;
|
|
7
|
+
params?: Record<string, string | undefined>;
|
|
8
|
+
context?: unknown;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export async function reactRouterAuthContext<TPrincipal, TSession>(
|
|
12
|
+
auth: AuthSystem<TPrincipal, TSession>,
|
|
13
|
+
args: ReactRouterRequestArgs,
|
|
14
|
+
) {
|
|
15
|
+
return auth.contextFromRequest(args.request);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function reactRouterRequirePrincipal<TPrincipal, TSession>(
|
|
19
|
+
auth: AuthSystem<TPrincipal, TSession>,
|
|
20
|
+
args: ReactRouterRequestArgs,
|
|
21
|
+
): Promise<TPrincipal> {
|
|
22
|
+
return auth.requirePrincipal(args.request);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function reactRouterJson(value: unknown, init: ResponseInit = {}): Response {
|
|
26
|
+
return jsonResponse(value, init);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function reactRouterRedirect(location: string, status = 302): Response {
|
|
30
|
+
return new Response(null, {
|
|
31
|
+
status,
|
|
32
|
+
headers: { location },
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function reactRouterError(error: unknown): Response {
|
|
37
|
+
if (error instanceof Response) return error;
|
|
38
|
+
if (error instanceof HttpError) {
|
|
39
|
+
return jsonResponse({ error: { code: error.code, message: error.message } }, { status: error.status });
|
|
40
|
+
}
|
|
41
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
42
|
+
return jsonResponse({ error: { code: "internal_error", message } }, { status: 500 });
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function reactRouterMcpAuthorize<TPrincipal, TSubject extends Record<string, string>>(
|
|
46
|
+
args: ReactRouterRequestArgs,
|
|
47
|
+
service: McpAuthService<TPrincipal, TSubject>,
|
|
48
|
+
client: OAuthClientInformation,
|
|
49
|
+
params: McpAuthorizationParams,
|
|
50
|
+
): Promise<Response> {
|
|
51
|
+
const result = await service.authorize(client, params, args.request);
|
|
52
|
+
return reactRouterRedirect(result.kind === "redirect" ? result.location : result.redirect, result.kind === "redirect" ? (result.status ?? 302) : 302);
|
|
53
|
+
}
|