xmcp 0.6.13 → 0.7.1

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.
Files changed (161) hide show
  1. package/dist/cli.js +8 -8
  2. package/dist/index.js +2 -2
  3. package/dist/runtime/adapter-express.js +2 -2
  4. package/dist/runtime/adapter-fastify.js +2 -2
  5. package/dist/runtime/adapter-nestjs.js +7 -7
  6. package/dist/runtime/adapter-nextjs.js +11 -11
  7. package/dist/runtime/http.js +3 -3
  8. package/dist/runtime/stdio.js +8 -8
  9. package/package.json +10 -11
  10. package/src/auth/api-key.ts +0 -120
  11. package/src/auth/jwt.ts +0 -52
  12. package/src/cli/commands/create/__tests__/create.test.ts +0 -99
  13. package/src/cli/commands/create/index.ts +0 -74
  14. package/src/cli/commands/create/templates/index.ts +0 -4
  15. package/src/cli/commands/create/templates/prompt.ts +0 -30
  16. package/src/cli/commands/create/templates/resource.ts +0 -20
  17. package/src/cli/commands/create/templates/tool.ts +0 -34
  18. package/src/cli/commands/create/templates/widget.ts +0 -33
  19. package/src/cli/utils/naming.ts +0 -39
  20. package/src/cli.ts +0 -125
  21. package/src/client/headers.ts +0 -61
  22. package/src/client/index.ts +0 -180
  23. package/src/client/types.ts +0 -122
  24. package/src/client/utils.ts +0 -133
  25. package/src/cloudflare.ts +0 -6
  26. package/src/compiler/build-telemetry.ts +0 -88
  27. package/src/compiler/client/component-compiler.ts +0 -250
  28. package/src/compiler/client/transpile.ts +0 -21
  29. package/src/compiler/compiler-context.ts +0 -61
  30. package/src/compiler/config/__tests__/config.test.ts +0 -459
  31. package/src/compiler/config/index.ts +0 -62
  32. package/src/compiler/config/injection.ts +0 -210
  33. package/src/compiler/config/schemas/bundler.ts +0 -12
  34. package/src/compiler/config/schemas/experimental/index.ts +0 -22
  35. package/src/compiler/config/schemas/index.ts +0 -20
  36. package/src/compiler/config/schemas/paths.ts +0 -35
  37. package/src/compiler/config/schemas/template.ts +0 -80
  38. package/src/compiler/config/schemas/transport/http.ts +0 -116
  39. package/src/compiler/config/schemas/transport/stdio.ts +0 -31
  40. package/src/compiler/config/schemas/typescript.ts +0 -26
  41. package/src/compiler/config/utils.ts +0 -168
  42. package/src/compiler/generate-env-code.ts +0 -5
  43. package/src/compiler/generate-import-code.ts +0 -187
  44. package/src/compiler/generate-tools-code.ts +0 -174
  45. package/src/compiler/get-bundler-config/get-entries.ts +0 -44
  46. package/src/compiler/get-bundler-config/get-externals.ts +0 -114
  47. package/src/compiler/get-bundler-config/get-injected-variables.ts +0 -46
  48. package/src/compiler/get-bundler-config/index.ts +0 -288
  49. package/src/compiler/get-bundler-config/plugins/index.ts +0 -140
  50. package/src/compiler/get-bundler-config/plugins/types/express.ts +0 -3
  51. package/src/compiler/get-bundler-config/plugins/types/fastify.ts +0 -4
  52. package/src/compiler/get-bundler-config/plugins/types/index.ts +0 -5
  53. package/src/compiler/get-bundler-config/plugins/types/nest.ts +0 -65
  54. package/src/compiler/get-bundler-config/plugins/types/next.ts +0 -52
  55. package/src/compiler/get-bundler-config/resolve-tsconfig-paths.ts +0 -51
  56. package/src/compiler/index.ts +0 -484
  57. package/src/compiler/on-first-build.ts +0 -54
  58. package/src/compiler/parse-xmcp-config.ts +0 -200
  59. package/src/compiler/start-http-server.ts +0 -42
  60. package/src/compiler/utils/__tests__/config-detection.test.ts +0 -307
  61. package/src/compiler/utils/__tests__/path-utils.test.ts +0 -137
  62. package/src/compiler/utils/config-detection.ts +0 -34
  63. package/src/compiler/utils/path-utils.ts +0 -22
  64. package/src/compiler/watcher-recovery.ts +0 -72
  65. package/src/host-bridge.ts +0 -36
  66. package/src/index.ts +0 -94
  67. package/src/platforms/build-cloudflare-output.ts +0 -116
  68. package/src/platforms/build-vercel-output.ts +0 -131
  69. package/src/plugins/index.ts +0 -1
  70. package/src/plugins/x402/index.ts +0 -24
  71. package/src/runtime/adapters/express/index.ts +0 -75
  72. package/src/runtime/adapters/fastify/__tests__/fastify.test.ts +0 -115
  73. package/src/runtime/adapters/fastify/index.ts +0 -78
  74. package/src/runtime/adapters/nestjs/index.ts +0 -16
  75. package/src/runtime/adapters/nestjs/xmcp.controller.ts +0 -34
  76. package/src/runtime/adapters/nestjs/xmcp.guard.ts +0 -101
  77. package/src/runtime/adapters/nestjs/xmcp.oauth.controller.ts +0 -36
  78. package/src/runtime/adapters/nestjs/xmcp.oauth.module.ts +0 -21
  79. package/src/runtime/adapters/nestjs/xmcp.oauth.service.ts +0 -36
  80. package/src/runtime/adapters/nestjs/xmcp.service.ts +0 -96
  81. package/src/runtime/adapters/nestjs/xmcp.utils.ts +0 -11
  82. package/src/runtime/adapters/nextjs/auth.ts +0 -265
  83. package/src/runtime/adapters/nextjs/handler/error-handler.ts +0 -67
  84. package/src/runtime/adapters/nextjs/handler/node-to-web-adapter.ts +0 -143
  85. package/src/runtime/adapters/nextjs/handler/request-converter.ts +0 -74
  86. package/src/runtime/adapters/nextjs/handler/server-lifecycle.ts +0 -69
  87. package/src/runtime/adapters/nextjs/index.ts +0 -82
  88. package/src/runtime/contexts/client-info-context.ts +0 -16
  89. package/src/runtime/contexts/http-request-context.ts +0 -21
  90. package/src/runtime/contexts/http-transport-context.ts +0 -18
  91. package/src/runtime/headers.ts +0 -42
  92. package/src/runtime/middlewares/utils.ts +0 -72
  93. package/src/runtime/platforms/cloudflare/cors.ts +0 -44
  94. package/src/runtime/platforms/cloudflare/middlewares/api-key.ts +0 -102
  95. package/src/runtime/platforms/cloudflare/middlewares/jwt.ts +0 -127
  96. package/src/runtime/platforms/cloudflare/types.ts +0 -23
  97. package/src/runtime/platforms/cloudflare/worker.ts +0 -270
  98. package/src/runtime/templates/home.ts +0 -746
  99. package/src/runtime/transports/http/base-streamable-http.ts +0 -46
  100. package/src/runtime/transports/http/cors/headers.ts +0 -58
  101. package/src/runtime/transports/http/cors/index.ts +0 -34
  102. package/src/runtime/transports/http/index.ts +0 -78
  103. package/src/runtime/transports/http/stateless-streamable-http.ts +0 -311
  104. package/src/runtime/transports/http/web-stateless-http.ts +0 -288
  105. package/src/runtime/transports/stdio/index.ts +0 -109
  106. package/src/runtime/utils/__tests__/client-info.test.ts +0 -146
  107. package/src/runtime/utils/__tests__/tool-extra.test.ts +0 -239
  108. package/src/runtime/utils/client-info.ts +0 -114
  109. package/src/runtime/utils/elicitation.ts +0 -396
  110. package/src/runtime/utils/ext-apps-registry.ts +0 -151
  111. package/src/runtime/utils/mcp-app-protocol.ts +0 -16
  112. package/src/runtime/utils/mcp-app-types.ts +0 -113
  113. package/src/runtime/utils/mcp-host-bridge.ts +0 -473
  114. package/src/runtime/utils/path-to-tool-name.ts +0 -69
  115. package/src/runtime/utils/prompt-loader.ts +0 -151
  116. package/src/runtime/utils/prompts.ts +0 -69
  117. package/src/runtime/utils/react/generate-html.ts +0 -69
  118. package/src/runtime/utils/react/index.ts +0 -6
  119. package/src/runtime/utils/request-tool-names.ts +0 -48
  120. package/src/runtime/utils/resource-loader.ts +0 -151
  121. package/src/runtime/utils/resources.ts +0 -331
  122. package/src/runtime/utils/server.ts +0 -107
  123. package/src/runtime/utils/tool-loader.ts +0 -149
  124. package/src/runtime/utils/tools.ts +0 -183
  125. package/src/runtime/utils/transformers/prompt.ts +0 -120
  126. package/src/runtime/utils/transformers/resource.ts +0 -196
  127. package/src/runtime/utils/transformers/tool.ts +0 -400
  128. package/src/runtime/utils/ui/__tests__/split-meta.test.ts +0 -803
  129. package/src/runtime/utils/ui/flatten-meta.ts +0 -44
  130. package/src/runtime/utils/ui/split-meta.ts +0 -78
  131. package/src/runtime/utils/utils/resource-uri-composer.ts +0 -204
  132. package/src/runtime/utils/validators/index.ts +0 -138
  133. package/src/telemetry/ci-info.ts +0 -6
  134. package/src/telemetry/debug.ts +0 -8
  135. package/src/telemetry/events/definitions.ts +0 -52
  136. package/src/telemetry/events/detached-flush.ts +0 -83
  137. package/src/telemetry/events/post-payload.ts +0 -141
  138. package/src/telemetry/events/tracker.ts +0 -281
  139. package/src/telemetry/index.ts +0 -7
  140. package/src/telemetry/metadata.ts +0 -49
  141. package/src/telemetry/project-id.ts +0 -35
  142. package/src/telemetry/storage.ts +0 -218
  143. package/src/types/adapter.d.ts +0 -5
  144. package/src/types/client-info.ts +0 -20
  145. package/src/types/declarations.ts +0 -37
  146. package/src/types/injected.d.ts +0 -62
  147. package/src/types/middleware.ts +0 -19
  148. package/src/types/prompt.ts +0 -6
  149. package/src/types/resource.ts +0 -15
  150. package/src/types/tool.ts +0 -192
  151. package/src/types/ui-meta.ts +0 -42
  152. package/src/utils/cli-icons.ts +0 -5
  153. package/src/utils/constants.ts +0 -31
  154. package/src/utils/context.ts +0 -105
  155. package/src/utils/detect-package-manager.ts +0 -46
  156. package/src/utils/file-watcher.ts +0 -66
  157. package/src/utils/fs-utils.ts +0 -16
  158. package/src/utils/path-validation.ts +0 -66
  159. package/src/utils/port-utils.ts +0 -43
  160. package/src/utils/spawn-process.ts +0 -49
  161. package/src/utils/subscribable.ts +0 -62
@@ -1,16 +0,0 @@
1
- import type { McpClientInfo } from "@/types/client-info";
2
- import { createContext } from "../../utils/context";
3
-
4
- export interface ClientInfoContext {
5
- clientInfo?: McpClientInfo;
6
- }
7
-
8
- export const clientInfoContext = createContext<ClientInfoContext>({
9
- name: "client-info-context",
10
- });
11
-
12
- export const setClientInfoContext = clientInfoContext.setContext;
13
-
14
- export const getClientInfoContext = clientInfoContext.getContext;
15
-
16
- export const clientInfoContextProvider = clientInfoContext.provider;
@@ -1,21 +0,0 @@
1
- import { createContext } from "../../utils/context";
2
- import type { McpClientInfo } from "@/types/client-info";
3
-
4
- // Headers type compatible with both Node.js IncomingHttpHeaders and Web API headers
5
- export type HttpHeaders = Record<string, string | string[] | undefined>;
6
-
7
- export interface HttpRequestContext {
8
- id: string;
9
- headers: HttpHeaders;
10
- clientInfo?: McpClientInfo;
11
- }
12
-
13
- export const httpRequestContext = createContext<HttpRequestContext>({
14
- name: "http-request-context",
15
- });
16
-
17
- export const setHttpRequestContext = httpRequestContext.setContext;
18
-
19
- export const getHttpRequestContext = httpRequestContext.getContext;
20
-
21
- export const httpRequestContextProvider = httpRequestContext.provider;
@@ -1,18 +0,0 @@
1
- import { ResolvedHttpConfig } from "@/compiler/config";
2
- import { createContext } from "../../utils/context";
3
-
4
- export interface HttpTransportContext {
5
- config: {
6
- http?: ResolvedHttpConfig;
7
- };
8
- }
9
-
10
- export const httpTransportContext = createContext<HttpTransportContext>({
11
- name: "http-transport-context",
12
- });
13
-
14
- export const setHttpTransportContext = httpTransportContext.setContext;
15
-
16
- export const getHttpTransportContext = httpTransportContext.getContext;
17
-
18
- export const httpTransportContextProvider = httpTransportContext.provider;
@@ -1,42 +0,0 @@
1
- import { getHttpRequestContext } from "./contexts/http-request-context";
2
-
3
- export const headers = () => {
4
- const currentHeaders = getHttpRequestContext().headers;
5
- const headerLookup = new Map<string, string>();
6
-
7
- for (const key of Object.keys(currentHeaders)) {
8
- const normalizedKey = key.toLowerCase();
9
-
10
- if (!headerLookup.has(normalizedKey)) {
11
- headerLookup.set(normalizedKey, key);
12
- }
13
- }
14
-
15
- const resolveHeaderKey = (prop: string): string => {
16
- return headerLookup.get(prop.toLowerCase()) ?? prop;
17
- };
18
-
19
- return new Proxy(currentHeaders, {
20
- get(target, prop, receiver) {
21
- if (typeof prop !== "string") {
22
- return Reflect.get(target, prop, receiver);
23
- }
24
-
25
- return Reflect.get(target, resolveHeaderKey(prop), receiver);
26
- },
27
- has(target, prop) {
28
- if (typeof prop !== "string") {
29
- return Reflect.has(target, prop);
30
- }
31
-
32
- return Reflect.has(target, resolveHeaderKey(prop));
33
- },
34
- getOwnPropertyDescriptor(target, prop) {
35
- if (typeof prop !== "string") {
36
- return Reflect.getOwnPropertyDescriptor(target, prop);
37
- }
38
-
39
- return Reflect.getOwnPropertyDescriptor(target, resolveHeaderKey(prop));
40
- },
41
- });
42
- };
@@ -1,72 +0,0 @@
1
- import { RequestHandlerAndRouter, Middleware } from "@/types/middleware";
2
- import { Router, type RequestHandler } from "express";
3
-
4
- export type Provider = {
5
- middleware?: RequestHandler;
6
- router?: Router;
7
- };
8
-
9
- export type ProvidersModel = Provider[];
10
-
11
- // assertion functions to get the type of the middleware and router
12
- function isRequestHandler(
13
- middleware: Middleware
14
- ): middleware is RequestHandler {
15
- return typeof middleware === "function";
16
- }
17
-
18
- function isRequestHandlerAndRouter(
19
- middleware: Middleware
20
- ): middleware is RequestHandlerAndRouter {
21
- return (
22
- typeof middleware === "object" &&
23
- middleware !== null &&
24
- "middleware" in middleware &&
25
- "router" in middleware &&
26
- typeof middleware.middleware === "function" &&
27
- isExpressRouter(middleware.router)
28
- );
29
- }
30
-
31
- function isExpressRouter(obj: any): obj is Router {
32
- return (
33
- typeof obj === "function" &&
34
- obj !== null &&
35
- typeof obj.use === "function" &&
36
- typeof obj.get === "function" &&
37
- typeof obj.post === "function" &&
38
- typeof obj.route === "function"
39
- );
40
- }
41
-
42
- // read from the array of providers (middlewares and/or routers) and split them into ordered items preserving sequence
43
- export function processProviders(
44
- defaultExport: Middleware | Middleware[]
45
- ): ProvidersModel {
46
- const providers: ProvidersModel = [];
47
-
48
- if (Array.isArray(defaultExport)) {
49
- for (const middleware of defaultExport) {
50
- if (isRequestHandler(middleware)) {
51
- providers.push({ middleware });
52
- } else if (isRequestHandlerAndRouter(middleware)) {
53
- providers.push({
54
- middleware: middleware.middleware,
55
- router: middleware.router,
56
- });
57
- }
58
- }
59
- } else {
60
- // if it's not an array return it as an array anyways
61
- if (isRequestHandler(defaultExport)) {
62
- providers.push({ middleware: defaultExport });
63
- } else if (isRequestHandlerAndRouter(defaultExport)) {
64
- providers.push({
65
- middleware: defaultExport.middleware,
66
- router: defaultExport.router,
67
- });
68
- }
69
- }
70
-
71
- return providers;
72
- }
@@ -1,44 +0,0 @@
1
- /**
2
- * CORS handling for Cloudflare Workers adapter.
3
- */
4
-
5
- import type { CorsConfig } from "@/compiler/config";
6
- import { buildCorsHeaders } from "@/runtime/transports/http/cors/headers";
7
-
8
- // CORS config - injected by compiler as combined object
9
- const corsConfig = HTTP_CORS_CONFIG as CorsConfig;
10
-
11
- /**
12
- * Add CORS headers to a Response
13
- */
14
- export function addCorsHeaders(
15
- response: Response,
16
- requestOrigin: string | null
17
- ): Response {
18
- const headers = new Headers(response.headers);
19
-
20
- const corsHeaders = buildCorsHeaders(corsConfig, requestOrigin);
21
- for (const [key, value] of Object.entries(corsHeaders)) {
22
- headers.set(key, value);
23
- }
24
-
25
- return new Response(response.body, {
26
- status: response.status,
27
- statusText: response.statusText,
28
- headers,
29
- });
30
- }
31
-
32
- /**
33
- * Handle CORS preflight requests
34
- */
35
- export function handleCorsPreflightRequest(
36
- requestOrigin: string | null
37
- ): Response {
38
- const headers = new Headers(buildCorsHeaders(corsConfig, requestOrigin));
39
-
40
- return new Response(null, {
41
- status: 204,
42
- headers,
43
- });
44
- }
@@ -1,102 +0,0 @@
1
- import { z } from "zod/v3";
2
- import type { WebMiddleware } from "@/types/middleware";
3
-
4
- const apiKeyAuthMiddlewareConfigSchema = z
5
- .object({
6
- apiKey: z.string().optional(),
7
- headerName: z.string().optional(),
8
- validateApiKey: z
9
- .function()
10
- .args(z.string())
11
- .returns(z.promise(z.boolean()))
12
- .optional(),
13
- })
14
- .strict()
15
- .refine(
16
- (config) =>
17
- config.apiKey !== undefined || config.validateApiKey !== undefined,
18
- {
19
- message: "Either 'apiKey' or 'validateApiKey' must be provided",
20
- }
21
- )
22
- .refine(
23
- (config) =>
24
- !(config.apiKey !== undefined && config.validateApiKey !== undefined),
25
- {
26
- message:
27
- "'apiKey' and 'validateApiKey' are mutually exclusive - provide only one",
28
- }
29
- );
30
-
31
- const errorMessage = "Unauthorized: Missing or invalid API key";
32
-
33
- type StaticApiKeyConfig = {
34
- /** The static API key to validate against */
35
- apiKey: string;
36
- /** Optional header name to read the API key from. Defaults to 'x-api-key' */
37
- headerName?: string;
38
- };
39
-
40
- type CustomValidationConfig = {
41
- /** Optional header name to read the API key from. Defaults to 'x-api-key' */
42
- headerName?: string;
43
- /** Custom validation function that receives the API key and returns a Promise<boolean> */
44
- validateApiKey: (key: string) => Promise<boolean>;
45
- };
46
-
47
- export function cloudflareApiKeyAuthMiddleware(
48
- config: StaticApiKeyConfig
49
- ): WebMiddleware;
50
-
51
- export function cloudflareApiKeyAuthMiddleware(
52
- config: CustomValidationConfig
53
- ): WebMiddleware;
54
-
55
- export function cloudflareApiKeyAuthMiddleware(
56
- config: StaticApiKeyConfig | CustomValidationConfig
57
- ): WebMiddleware {
58
- const response = apiKeyAuthMiddlewareConfigSchema.safeParse(config);
59
- if (!response.success) {
60
- const hasApiKey = "apiKey" in config;
61
- const hasValidateApiKey = "validateApiKey" in config;
62
-
63
- if (hasApiKey && hasValidateApiKey) {
64
- throw new Error(
65
- "'apiKey' and 'validateApiKey' are mutually exclusive - provide only one"
66
- );
67
- } else if (!hasApiKey && !hasValidateApiKey) {
68
- throw new Error("Either 'apiKey' or 'validateApiKey' must be provided");
69
- } else {
70
- throw new Error(`Invalid configuration: ${response.error.message}`);
71
- }
72
- }
73
-
74
- const headerName = config.headerName ?? "x-api-key";
75
- const apiKey = "apiKey" in config ? config.apiKey : undefined;
76
- const validateApiKey =
77
- "validateApiKey" in config ? config.validateApiKey : undefined;
78
-
79
- return async (request) => {
80
- const apiKeyHeader = request.headers.get(headerName);
81
- if (!apiKeyHeader) {
82
- return jsonUnauthorized(errorMessage);
83
- }
84
- if ("apiKey" in config && apiKeyHeader !== apiKey) {
85
- return jsonUnauthorized(errorMessage);
86
- }
87
- if (validateApiKey) {
88
- const isValid = await validateApiKey(apiKeyHeader);
89
- if (!isValid) {
90
- return jsonUnauthorized(errorMessage);
91
- }
92
- }
93
- return;
94
- };
95
- }
96
-
97
- function jsonUnauthorized(message: string): Response {
98
- return new Response(JSON.stringify({ error: message }), {
99
- status: 401,
100
- headers: { "Content-Type": "application/json" },
101
- });
102
- }
@@ -1,127 +0,0 @@
1
- import type { JWTPayload, JWTVerifyOptions } from "jose";
2
- import { decodeProtectedHeader, importJWK, importSPKI, importX509, jwtVerify } from "jose";
3
- import type { WebMiddleware } from "@/types/middleware";
4
-
5
- export type CloudflareJWTAuthMiddlewareConfig = {
6
- secret: string;
7
- algorithms?: string[];
8
- audience?: string | string[];
9
- issuer?: string;
10
- subject?: string;
11
- clockTolerance?: number | string;
12
- maxAge?: string | number;
13
- };
14
-
15
- export function cloudflareJwtAuthMiddleware(
16
- config: CloudflareJWTAuthMiddlewareConfig
17
- ): WebMiddleware {
18
- return async (request) => {
19
- const authHeader = request.headers.get("authorization");
20
- const token = extractBearerToken(authHeader);
21
- if (!token) {
22
- return jsonUnauthorized(
23
- "Unauthorized: Missing or malformed Authorization header"
24
- );
25
- }
26
-
27
- try {
28
- await verifyJwt(token, config);
29
- return;
30
- } catch {
31
- return jsonUnauthorized("Unauthorized: Invalid or expired token");
32
- }
33
- };
34
- }
35
-
36
- function extractBearerToken(authHeader: string | null | undefined): string | null {
37
- if (!authHeader) return null;
38
- const [scheme, token] = authHeader.split(" ");
39
- if (!scheme || !token || scheme.toLowerCase() !== "bearer") {
40
- return null;
41
- }
42
- return token.trim() || null;
43
- }
44
-
45
- function jsonUnauthorized(message: string): Response {
46
- return new Response(JSON.stringify({ error: message }), {
47
- status: 401,
48
- headers: { "Content-Type": "application/json" },
49
- });
50
- }
51
-
52
- async function verifyJwt(
53
- token: string,
54
- config: CloudflareJWTAuthMiddlewareConfig
55
- ): Promise<JWTPayload> {
56
- const { secret, ...verifyOptions } = config;
57
- const header = decodeProtectedHeader(token);
58
- const alg =
59
- verifyOptions.algorithms?.[0] ??
60
- (typeof header.alg === "string" ? header.alg : undefined);
61
-
62
- if (!alg) {
63
- throw new Error("Missing JWT algorithm");
64
- }
65
-
66
- const key = await resolveJoseKey(secret, alg);
67
- const joseOptions = mapJoseVerifyOptions(verifyOptions);
68
- const { payload } = await jwtVerify(token, key as any, joseOptions);
69
- return payload;
70
- }
71
-
72
- async function resolveJoseKey(
73
- secret: string,
74
- alg: string
75
- ): Promise<Uint8Array | unknown> {
76
- const trimmed = secret.trim();
77
-
78
- if (trimmed.startsWith("{")) {
79
- try {
80
- const jwk = JSON.parse(trimmed);
81
- return await importJWK(jwk, alg);
82
- } catch {
83
- return new TextEncoder().encode(secret);
84
- }
85
- }
86
-
87
- if (trimmed.includes("BEGIN CERTIFICATE")) {
88
- return await importX509(trimmed, alg);
89
- }
90
-
91
- if (trimmed.includes("BEGIN PUBLIC KEY")) {
92
- return await importSPKI(trimmed, alg);
93
- }
94
-
95
- return new TextEncoder().encode(secret);
96
- }
97
-
98
- function mapJoseVerifyOptions(
99
- verifyOptions: Omit<CloudflareJWTAuthMiddlewareConfig, "secret">
100
- ): JWTVerifyOptions {
101
- const joseOptions: JWTVerifyOptions = {};
102
-
103
- if (verifyOptions.algorithms) {
104
- joseOptions.algorithms = verifyOptions.algorithms;
105
- }
106
- if (verifyOptions.audience) {
107
- if (typeof verifyOptions.audience === "string") {
108
- joseOptions.audience = verifyOptions.audience;
109
- } else if (Array.isArray(verifyOptions.audience)) {
110
- joseOptions.audience = verifyOptions.audience;
111
- }
112
- }
113
- if (verifyOptions.issuer) {
114
- joseOptions.issuer = verifyOptions.issuer;
115
- }
116
- if (verifyOptions.subject) {
117
- joseOptions.subject = verifyOptions.subject;
118
- }
119
- if (verifyOptions.clockTolerance !== undefined) {
120
- joseOptions.clockTolerance = verifyOptions.clockTolerance;
121
- }
122
- if (verifyOptions.maxAge !== undefined) {
123
- joseOptions.maxTokenAge = verifyOptions.maxAge;
124
- }
125
-
126
- return joseOptions;
127
- }
@@ -1,23 +0,0 @@
1
- /**
2
- * Shared types for Cloudflare Workers adapter.
3
- * Placed here to avoid circular dependencies.
4
- */
5
-
6
- /**
7
- * Cloudflare Workers environment bindings.
8
- * Users can extend this with their own bindings.
9
- */
10
- export interface Env {
11
- /**
12
- * Additional user-defined bindings (KV, D1, etc.)
13
- */
14
- [key: string]: unknown;
15
- }
16
-
17
- /**
18
- * Cloudflare Workers ExecutionContext type
19
- */
20
- export interface ExecutionContext {
21
- waitUntil(promise: Promise<unknown>): void;
22
- passThroughOnException(): void;
23
- }