@vitemcp/server 1.9.11 → 1.9.13

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 (36) hide show
  1. package/README.md +15 -11
  2. package/dist/{OAuthProvider-B78zmLtB.d.cts → OAuthProvider-BDDi19HO.d.cts} +15 -3
  3. package/dist/{OAuthProvider-B78zmLtB.d.ts → OAuthProvider-BDDi19HO.d.ts} +15 -3
  4. package/dist/ViteMCP.cjs +4 -4
  5. package/dist/ViteMCP.d.cts +2 -2
  6. package/dist/ViteMCP.d.ts +2 -2
  7. package/dist/ViteMCP.js +3 -3
  8. package/dist/auth/index.cjs +2 -2
  9. package/dist/auth/index.d.cts +7 -2
  10. package/dist/auth/index.d.ts +7 -2
  11. package/dist/auth/index.js +1 -1
  12. package/dist/{chunk-KSEFUQF4.js → chunk-5XM67UD5.js} +35 -6
  13. package/dist/chunk-5XM67UD5.js.map +1 -0
  14. package/dist/{chunk-TYR2KJIV.js → chunk-JMDI672G.js} +44 -9
  15. package/dist/chunk-JMDI672G.js.map +1 -0
  16. package/dist/{chunk-C2VT2NXC.cjs → chunk-NCSND5TI.cjs} +8 -8
  17. package/dist/{chunk-C2VT2NXC.cjs.map → chunk-NCSND5TI.cjs.map} +1 -1
  18. package/dist/{chunk-IAT55CW3.js → chunk-QGWUABBC.js} +3 -3
  19. package/dist/{chunk-DURXYPPR.cjs → chunk-QPVEGWOL.cjs} +44 -9
  20. package/dist/chunk-QPVEGWOL.cjs.map +1 -0
  21. package/dist/{chunk-XGRRYN5Y.cjs → chunk-SKQK3QGJ.cjs} +35 -6
  22. package/dist/chunk-SKQK3QGJ.cjs.map +1 -0
  23. package/dist/edge/index.cjs +5 -5
  24. package/dist/edge/index.js +1 -1
  25. package/dist/openapi/index.cjs +103 -36
  26. package/dist/openapi/index.cjs.map +1 -1
  27. package/dist/openapi/index.d.cts +2 -2
  28. package/dist/openapi/index.d.ts +2 -2
  29. package/dist/openapi/index.js +86 -19
  30. package/dist/openapi/index.js.map +1 -1
  31. package/package.json +1 -1
  32. package/dist/chunk-DURXYPPR.cjs.map +0 -1
  33. package/dist/chunk-KSEFUQF4.js.map +0 -1
  34. package/dist/chunk-TYR2KJIV.js.map +0 -1
  35. package/dist/chunk-XGRRYN5Y.cjs.map +0 -1
  36. /package/dist/{chunk-IAT55CW3.js.map → chunk-QGWUABBC.js.map} +0 -0
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  withoutTrailingSlash
3
- } from "./chunk-KSEFUQF4.js";
3
+ } from "./chunk-5XM67UD5.js";
4
4
  import {
5
5
  formatBytes,
6
6
  ownKeysOnly,
7
7
  toSdkSchema,
8
8
  valibotToJsonSchema
9
- } from "./chunk-TYR2KJIV.js";
9
+ } from "./chunk-JMDI672G.js";
10
10
 
11
11
  // src/ViteMCP.ts
12
12
  import {
@@ -1688,4 +1688,4 @@ export {
1688
1688
  ServerState,
1689
1689
  ViteMCP
1690
1690
  };
1691
- //# sourceMappingURL=chunk-IAT55CW3.js.map
1691
+ //# sourceMappingURL=chunk-QGWUABBC.js.map
@@ -66,6 +66,11 @@ var isPlain = (value) => {
66
66
  };
67
67
 
68
68
  // src/toSdkSchema.ts
69
+ var SDK_TARGET = "draft-2020-12";
70
+ var LENIENT_OPTIONS = /* @__PURE__ */ new Map([
71
+ ["arktype", { fallback: (context) => context.base }],
72
+ ["zod", { unrepresentable: "any" }]
73
+ ]);
69
74
  var toSdkSchema = async (schema, io, convert) => {
70
75
  if (!schema) {
71
76
  return void 0;
@@ -74,16 +79,17 @@ var toSdkSchema = async (schema, io, convert) => {
74
79
  schema["~standard"]
75
80
  );
76
81
  if (standard.jsonSchema) {
77
- return { "~standard": standard };
82
+ const { json: json2, lenient } = nativeJsonSchema(
83
+ standard.jsonSchema,
84
+ standard.vendor,
85
+ io
86
+ );
87
+ assertDescribesArguments(json2, io);
88
+ return lenient ? advertising(standard, json2) : { "~standard": standard };
78
89
  }
79
90
  const json = await convert(schema, io);
80
- const advertised = io === "input" ? strictInputSchema(json) : json;
81
- return {
82
- "~standard": {
83
- ...standard,
84
- jsonSchema: { input: () => advertised, output: () => advertised }
85
- }
86
- };
91
+ assertDescribesArguments(json, io);
92
+ return advertising(standard, io === "input" ? strictInputSchema(json) : json);
87
93
  };
88
94
  var valibotToJsonSchema = async (schema, io) => {
89
95
  let converter;
@@ -99,6 +105,35 @@ var valibotToJsonSchema = async (schema, io) => {
99
105
  typeMode: io
100
106
  });
101
107
  };
108
+ var advertising = (standard, advertised) => ({
109
+ "~standard": {
110
+ ...standard,
111
+ jsonSchema: { input: () => advertised, output: () => advertised }
112
+ }
113
+ });
114
+ var assertDescribesArguments = (json, io) => {
115
+ if (io === "input" && json.type !== void 0 && json.type !== "object") {
116
+ throw new Error(
117
+ `A tool's arguments are an object, and this schema describes ${JSON.stringify(
118
+ json.type
119
+ )}. Wrap it in an object schema.`
120
+ );
121
+ }
122
+ };
123
+ var nativeJsonSchema = (native, vendor, io) => {
124
+ try {
125
+ return { json: native[io]({ target: SDK_TARGET }), lenient: false };
126
+ } catch (error) {
127
+ const libraryOptions = LENIENT_OPTIONS.get(vendor);
128
+ if (!libraryOptions) {
129
+ throw error;
130
+ }
131
+ return {
132
+ json: native[io]({ libraryOptions, target: SDK_TARGET }),
133
+ lenient: true
134
+ };
135
+ }
136
+ };
102
137
  var strictInputSchema = (schema) => ({
103
138
  ...schema,
104
139
  ...!(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(schema.allOf, () => ( schema.anyOf)), () => ( schema.oneOf)), () => ( schema.$ref))) && {
@@ -120,4 +155,4 @@ var strictInputSchema = (schema) => ({
120
155
 
121
156
 
122
157
  exports.formatBytes = formatBytes; exports.ownKeysOnly = ownKeysOnly; exports.toSdkSchema = toSdkSchema; exports.valibotToJsonSchema = valibotToJsonSchema;
123
- //# sourceMappingURL=chunk-DURXYPPR.cjs.map
158
+ //# sourceMappingURL=chunk-QPVEGWOL.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/server/server/dist/chunk-QPVEGWOL.cjs","../src/formatBytes.ts","../src/ownKeysOnly.ts","../src/toSdkSchema.ts"],"names":[],"mappings":"AAAA;ACCO,IAAM,YAAA,EAAc,CAAC,KAAA,EAAA,GAA0B;AACpD,EAAA,GAAA,CAAI,MAAA,GAAS,KAAA,EAAO,KAAA,GAAQ,MAAA,EAAA,CAAS,KAAA,EAAO,IAAA,EAAA,IAAU,CAAA,EAAG;AACvD,IAAA,OAAO,CAAA,EAAA;AACT,EAAA;AAEI,EAAA;AACK,IAAA;AACT,EAAA;AAEU,EAAA;AACZ;ADDY;AACA;AEMC;AACL,EAAA;AAEC,EAAA;AACE,IAAA;AACF,MAAA;AACH,MAAA;AACF,IAAA;AACD,EAAA;AACH;AAkBa;AAGR,EAAA;AACO,EAAA;AACF,IAAA;AACA,IAAA;AAED,IAAA;AACH,MAAA;AACF,IAAA;AAEO,IAAA;AACT,EAAA;AACF;AAQM;AAIC,EAAA;AACI,IAAA;AACT,EAAA;AAEM,EAAA;AAEF,EAAA;AACK,IAAA;AACT,EAAA;AAEM,EAAA;AAIC,EAAA;AAEP,EAAA;AACU,IAAA;AACV,EAAA;AAEO,EAAA;AACT;AAMM;AAKC,EAAA;AACH,IAAA;AACF,EAAA;AAES,EAAA;AAEL,EAAA;AACK,IAAA;AACT,EAAA;AAEA,EAAA;AACE,IAAA;AACF,EAAA;AACF;AAMM;AACA,EAAA;AACK,IAAA;AACT,EAAA;AAEM,EAAA;AAGJ,EAAA;AAEJ;AFjEY;AACA;AGvCN;AAWA;AACH,EAAA;AACS,EAAA;AACX;AA8BY;AAKN,EAAA;AACI,IAAA;AACT,EAAA;AAEM,EAAA;AAOF,IAAA;AACJ,EAAA;AAEI,EAAA;AACM,IAAA;AACN,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AAEA,IAAA;AAEO,IAAA;AACT,EAAA;AAEM,EAAA;AAEN,EAAA;AAEO,EAAA;AACT;AAgBa;AACP,EAAA;AAEA,EAAA;AACF,IAAA;AACM,EAAA;AACA,IAAA;AACJ,MAAA;AAEF,IAAA;AACF,EAAA;AAEO,EAAA;AACL,IAAA;AACA,IAAA;AACD,EAAA;AACH;AAGM;AAIJ,EAAA;AACK,IAAA;AACH,IAAA;AACF,EAAA;AACF;AAQM;AAIA,EAAA;AACI,IAAA;AACJ,MAAA;AACE,QAAA;AACD,MAAA;AACH,IAAA;AACF,EAAA;AACF;AAMM;AAKA,EAAA;AACK,IAAA;AACA,EAAA;AACD,IAAA;AAED,IAAA;AACG,MAAA;AACR,IAAA;AAEO,IAAA;AACC,MAAA;AACN,MAAA;AACF,IAAA;AACF,EAAA;AACF;AAeM;AACD,EAAA;AACG,EAAA;AACJ,IAAA;AAIF,EAAA;AACW,EAAA;AACT,IAAA;AACE,MAAA;AACE,QAAA;AACA,QAAA;AAGD,MAAA;AACH,IAAA;AACF,EAAA;AACF;AH9EY;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/server/server/dist/chunk-QPVEGWOL.cjs","sourcesContent":[null,"/** Renders a byte cap the way the error message should read (e.g. \"1 MiB\"). */\nexport const formatBytes = (bytes: number): string => {\n if (bytes >= 1024 * 1024 && bytes % (1024 * 1024) === 0) {\n return `${bytes / (1024 * 1024)} MiB`;\n }\n\n if (bytes >= 1024 && bytes % 1024 === 0) {\n return `${bytes / 1024} KiB`;\n }\n\n return `${bytes} bytes`;\n};\n","import type { StandardSchemaV1 } from \"@standard-schema/spec\";\n\n/**\n * Has `schema` validate by own keys only — see `withOwnKeysOnly` — by\n * replacing its `~standard` in place. The schema keeps its `shape`, which the\n * SDK reads to complete an argument, and its JSON Schema, which `prompts/list`\n * is built from.\n *\n * For the argument schemas `ViteMCP` and `EdgeViteMCP` build for their\n * prompts. A tool's schemas belong to whoever wrote the tool, so\n * `toSdkSchema` wraps them instead.\n *\n * An argument map the request left out validates as an empty one, as the SDK\n * already arranges for a tool's. `prompts/get` may omit `arguments`, and the\n * SDK validates the map as it was sent, so a prompt whose arguments are all\n * optional refused the request as \"expected object, received undefined\".\n */\nexport const ownKeysOnly = <S extends StandardSchemaV1>(schema: S): S => {\n const standard = withOwnKeysOnly(schema[\"~standard\"]);\n\n return Object.defineProperty(schema, \"~standard\", {\n value: {\n ...standard,\n validate: (value: unknown) => standard.validate(value ?? {}),\n },\n });\n};\n\n/**\n * `standard`, with a `validate` that sees only the keys an object has of its\n * own.\n *\n * Zod and Valibot look each key up with `in` and read it with `[]`, and both\n * walk the prototype chain, so a key that was left out reads as present when\n * `Object.prototype` has a member by that name. An optional argument called\n * `toString`, `constructor` or `valueOf`, at any depth, failed every request\n * that left it out, as \"expected string, received function\", and a required\n * one was reported as the wrong type instead of as missing. Validating a copy\n * whose objects have no prototype leaves the library nothing to inherit.\n *\n * A library that hands its input back, as ArkType and `jsonSchemaAdapter` do,\n * hands back the copy, so the copied objects get their prototype back before\n * the value goes on: `execute` still receives ordinary objects.\n */\nexport const withOwnKeysOnly = <P extends StandardSchemaV1.Props>(\n standard: P,\n): P => ({\n ...standard,\n validate: async (value: unknown) => {\n const copies = new Map<object, object>();\n const result = await standard.validate(withoutPrototypes(value, copies));\n\n if (!result.issues && copies.size > 0) {\n restorePrototypes(result.value, new Set(copies.values()), new Set());\n }\n\n return result;\n },\n});\n\n/**\n * `value`, with each plain object in it, at any depth, copied onto one without\n * a prototype, and each array copied to reach them. `copies` maps every\n * original to its copy, so one that occurs twice, or inside itself, is copied\n * once.\n */\nconst withoutPrototypes = (\n value: unknown,\n copies: Map<object, object>,\n): unknown => {\n if (!isPlain(value)) {\n return value;\n }\n\n const existing = copies.get(value);\n\n if (existing) {\n return existing;\n }\n\n const copy: Record<string, unknown> = Array.isArray(value)\n ? []\n : Object.create(null);\n\n copies.set(value, copy);\n\n for (const [key, item] of Object.entries(value)) {\n copy[key] = withoutPrototypes(item, copies);\n }\n\n return copy;\n};\n\n/**\n * Gives each object copy in `copies` that `value` holds, at any depth,\n * `Object.prototype` back.\n */\nconst restorePrototypes = (\n value: unknown,\n copies: Set<object>,\n seen: Set<object>,\n): void => {\n if (!isPlain(value) || seen.has(value)) {\n return;\n }\n\n seen.add(value);\n\n if (copies.has(value) && !Array.isArray(value)) {\n Object.setPrototypeOf(value, Object.prototype);\n }\n\n for (const item of Object.values(value)) {\n restorePrototypes(item, copies, seen);\n }\n};\n\n/**\n * An array, or an object made by a literal or without a prototype: what JSON\n * parses to, and the only kinds of object that are copied.\n */\nconst isPlain = (value: unknown): value is Record<string, unknown> => {\n if (typeof value !== \"object\" || value === null) {\n return false;\n }\n\n const prototype: unknown = Object.getPrototypeOf(value);\n\n return (\n Array.isArray(value) || prototype === Object.prototype || prototype === null\n );\n};\n","import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { JsonSchema } from \"xsschema\";\n\nimport { withOwnKeysOnly } from \"./ownKeysOnly.js\";\n\n/**\n * Turns a Standard Schema that carries no JSON Schema into one. Which\n * libraries that can be done for depends on the runtime, so each entry point\n * supplies its own.\n */\nexport type JsonSchemaConverter = (\n schema: StandardSchemaV1,\n io: \"input\" | \"output\",\n) => Promise<JsonSchema>;\n\n/**\n * `~standard.jsonSchema`, as Zod v4 and ArkType implement it. Declared here\n * because `@standard-schema/spec` 1.0 predates it.\n */\ntype NativeJsonSchema = Record<\n \"input\" | \"output\",\n (options: {\n libraryOptions?: Record<string, unknown>;\n target: string;\n }) => JsonSchema\n>;\n\n/** The draft the SDK asks a schema for when `tools/list` describes a tool. */\nconst SDK_TARGET = \"draft-2020-12\";\n\n/**\n * What a library is told so that it leaves open the parts of a schema JSON\n * Schema cannot say, rather than refuse the schema over them. Zod describes\n * such a part as `{}`. ArkType hands over what it had worked out before it\n * reached the part: `{}` for a `Date`, `{ type: \"string\" }` for a string under\n * a `narrow()`.\n *\n * A library not named here is left to refuse, and its tool is not served.\n */\nconst LENIENT_OPTIONS = new Map<string, Record<string, unknown>>([\n [\"arktype\", { fallback: (context: { base: JsonSchema }) => context.base }],\n [\"zod\", { unrepresentable: \"any\" }],\n]);\n\n/**\n * A tool's schema as the SDK registers it: one that validates by own keys only\n * (see `withOwnKeysOnly`) and carries a JSON Schema. The schema itself is left\n * as it was, since whoever wrote it may use it elsewhere.\n *\n * Zod v4 and ArkType emit JSON Schema natively, and theirs is kept; anything\n * else (Valibot, say) is converted, and the conversion is only what\n * `tools/list` advertises. Validation stays with the library the schema was\n * written in: the conversion drops what JSON Schema cannot say — a transform,\n * a `check()` — so validating against it instead would pass `execute`\n * arguments the schema never produced.\n *\n * A native schema is converted here too, once, the way the SDK will for\n * `tools/list`. The SDK converts every tool in the one handler, so a schema\n * its library refused to convert — a `z.date()`, a `z.bigint()`, an ArkType\n * `narrow()` — failed the list for every tool, though each could still be\n * called. One refused is asked for again with what JSON Schema cannot say left\n * open (see `LENIENT_OPTIONS`), which is what Valibot's converter is already\n * told, and that copy is advertised in place of the library's own.\n *\n * Converted inputs are closed with `strictInputSchema`. Outputs are left as\n * converted, since closing them would misdescribe results the schema allows.\n *\n * Shared by `ViteMCP` and `EdgeViteMCP`, so what a tool advertises does not\n * depend on which of them serves it. Rejects when `convert` does, when a\n * library refuses a schema even leniently, and for an input schema that does\n * not describe an object: each caller leaves that tool out and serves the rest.\n */\nexport const toSdkSchema = async (\n schema: unknown,\n io: \"input\" | \"output\",\n convert: JsonSchemaConverter,\n): Promise<unknown> => {\n if (!schema) {\n return undefined;\n }\n\n const standard = withOwnKeysOnly(\n (\n schema as {\n \"~standard\": {\n jsonSchema?: NativeJsonSchema;\n } & StandardSchemaV1.Props;\n }\n )[\"~standard\"],\n );\n\n if (standard.jsonSchema) {\n const { json, lenient } = nativeJsonSchema(\n standard.jsonSchema,\n standard.vendor,\n io,\n );\n\n assertDescribesArguments(json, io);\n\n return lenient ? advertising(standard, json) : { \"~standard\": standard };\n }\n\n const json = await convert(schema as StandardSchemaV1, io);\n\n assertDescribesArguments(json, io);\n\n return advertising(standard, io === \"input\" ? strictInputSchema(json) : json);\n};\n\n/**\n * JSON Schema for a Valibot schema, for advertising.\n *\n * Valibot's converter is called directly so it can be told to skip what JSON\n * Schema cannot express — a transform, a `check()` — rather than refuse the\n * whole schema. Valibot still validates, so the copy only has to describe what\n * a caller sends (`typeMode: \"input\"`, which stops at the first transform) or\n * receives (`\"output\"`).\n *\n * The `import()` has to stay inside the `try`. An edge bundle is built with\n * every import resolved ahead of time, and a bundler fails the build over one\n * it cannot resolve — unless it can see the failure is handled, in which case\n * a server that never touches Valibot builds without the converter installed.\n */\nexport const valibotToJsonSchema: JsonSchemaConverter = async (schema, io) => {\n let converter;\n\n try {\n converter = await import(\"@valibot/to-json-schema\");\n } catch {\n throw new Error(\n 'The \"@valibot/to-json-schema\" package is required to describe Valibot ' +\n \"schemas. Install it with: npm install @valibot/to-json-schema\",\n );\n }\n\n return converter.toJsonSchema(schema as never, {\n errorMode: \"ignore\",\n typeMode: io,\n }) as JsonSchema;\n};\n\n/** `standard`, carrying `advertised` as its JSON Schema, input and output. */\nconst advertising = <P extends StandardSchemaV1.Props>(\n standard: P,\n advertised: JsonSchema,\n) => ({\n \"~standard\": {\n ...standard,\n jsonSchema: { input: () => advertised, output: () => advertised },\n },\n});\n\n/**\n * Refuses an input schema that describes anything but an object. A tool's\n * arguments are always one, and the SDK will not list a schema that says\n * otherwise: `parameters: z.string()` failed `tools/list` for every tool, as an\n * unconvertible schema did.\n */\nconst assertDescribesArguments = (\n json: JsonSchema,\n io: \"input\" | \"output\",\n): void => {\n if (io === \"input\" && json.type !== undefined && json.type !== \"object\") {\n throw new Error(\n `A tool's arguments are an object, and this schema describes ${JSON.stringify(\n json.type,\n )}. Wrap it in an object schema.`,\n );\n }\n};\n\n/**\n * A schema's own JSON Schema, and whether it had to be asked for leniently.\n * Throws what the library does when it refuses the schema either way.\n */\nconst nativeJsonSchema = (\n native: NativeJsonSchema,\n vendor: string,\n io: \"input\" | \"output\",\n): { json: JsonSchema; lenient: boolean } => {\n try {\n return { json: native[io]({ target: SDK_TARGET }), lenient: false };\n } catch (error) {\n const libraryOptions = LENIENT_OPTIONS.get(vendor);\n\n if (!libraryOptions) {\n throw error;\n }\n\n return {\n json: native[io]({ libraryOptions, target: SDK_TARGET }),\n lenient: true,\n };\n }\n};\n\n/**\n * Closes an advertised input schema's objects to undeclared keys, except where\n * the schema describes those keys itself. A record's value schema, or an\n * object's rest schema, arrives as `additionalProperties`; replacing it with\n * `false` would tell clients the tool takes none of those keys, so a\n * `v.record()` argument could only ever be sent as `{}`.\n *\n * Nor is an object closed whose keys are declared elsewhere: in its `allOf`,\n * `anyOf` or `oneOf` branches — a `v.intersect()`, `v.union()` or\n * `v.variant()` — or behind a `$ref`, which is how a `v.lazy()` arrives.\n * `additionalProperties` sees only the `properties` beside it, so closing one\n * refused every key declared elsewhere, and every argument with them.\n */\nconst strictInputSchema = (schema: JsonSchema): JsonSchema => ({\n ...schema,\n ...(!(schema.allOf ?? schema.anyOf ?? schema.oneOf ?? schema.$ref) && {\n additionalProperties:\n typeof schema.additionalProperties === \"object\"\n ? schema.additionalProperties\n : false,\n }),\n ...(schema.properties && {\n properties: Object.fromEntries(\n Object.entries(schema.properties).map(([key, value]) => [\n key,\n typeof value === \"object\" && value.type === \"object\"\n ? strictInputSchema(value)\n : value,\n ]),\n ),\n }),\n});\n"]}
@@ -378,6 +378,7 @@ var clientCodeStorageSchema = _zod.z.object({
378
378
  codeChallengeMethod: _zod.z.string(),
379
379
  createdAt: storedDateSchema,
380
380
  expiresAt: storedDateSchema,
381
+ redirectUri: _zod.z.string().optional(),
381
382
  transactionId: _zod.z.string(),
382
383
  upstreamTokens: upstreamTokenSetStorageSchema,
383
384
  used: _zod.z.boolean().optional()
@@ -731,6 +732,11 @@ var ConsentManager = class {
731
732
  }
732
733
  /**
733
734
  * Generate HTML for consent screen
735
+ *
736
+ * The form posts to `consent`, relative to the page it is on, rather than to
737
+ * `/oauth/consent`. The page is served at `<basePath>/oauth/authorize` with
738
+ * the consent route beside it, so under a base path the rooted address was
739
+ * one no route answers, and Approve came back 404.
734
740
  */
735
741
  generateConsentScreen(data) {
736
742
  const { clientName, provider, scope, transactionId } = data;
@@ -918,7 +924,7 @@ var ConsentManager = class {
918
924
  </p>
919
925
  </div>
920
926
 
921
- <form method="POST" action="/oauth/consent">
927
+ <form method="POST" action="consent">
922
928
  <input type="hidden" name="transaction_id" value="${this.escapeHtml(transactionId)}">
923
929
  <div class="actions">
924
930
  <button type="submit" name="action" value="deny" class="deny">
@@ -1455,6 +1461,7 @@ var MemoryTokenStorage = (_class3 = class {
1455
1461
  var withoutTrailingSlash = (url) => url.replace(/\/+$/, "");
1456
1462
 
1457
1463
  // src/auth/OAuthProxy.ts
1464
+ var GITHUB_TOKEN_ENDPOINT = "https://github.com/login/oauth/access_token";
1458
1465
  var RESERVED_AUTHORIZATION_PARAMS = /* @__PURE__ */ new Set([
1459
1466
  "client_id",
1460
1467
  "code_challenge",
@@ -1650,6 +1657,12 @@ var OAuthProxy = (_class4 = class {
1650
1657
  "Authorization code was issued to another client"
1651
1658
  );
1652
1659
  }
1660
+ if (request2.redirect_uri && clientCode.redirectUri !== void 0 && request2.redirect_uri !== clientCode.redirectUri) {
1661
+ throw new OAuthProxyError(
1662
+ "invalid_grant",
1663
+ "redirect_uri does not match the authorization request"
1664
+ );
1665
+ }
1653
1666
  if (!authenticated && (!clientCode.codeChallenge || clientCode.codeChallengeMethod !== "S256")) {
1654
1667
  throw new OAuthProxyError(
1655
1668
  "invalid_grant",
@@ -1671,6 +1684,11 @@ var OAuthProxy = (_class4 = class {
1671
1684
  if (!valid) {
1672
1685
  throw new OAuthProxyError("invalid_grant", "Invalid PKCE verifier");
1673
1686
  }
1687
+ } else if (request2.code_verifier) {
1688
+ throw new OAuthProxyError(
1689
+ "invalid_request",
1690
+ "code_verifier provided without a code_challenge"
1691
+ );
1674
1692
  }
1675
1693
  if (this.config.enableTokenSwap && this.jwtIssuer) {
1676
1694
  return await this.issueSwappedTokens(
@@ -1681,7 +1699,7 @@ var OAuthProxy = (_class4 = class {
1681
1699
  } else {
1682
1700
  const response = {
1683
1701
  access_token: clientCode.upstreamTokens.accessToken,
1684
- expires_in: clientCode.upstreamTokens.expiresIn,
1702
+ expires_in: clientCode.upstreamTokens.expiresIn || 3600,
1685
1703
  token_type: clientCode.upstreamTokens.tokenType
1686
1704
  };
1687
1705
  if (clientCode.upstreamTokens.refreshToken) {
@@ -2083,7 +2101,10 @@ var OAuthProxy = (_class4 = class {
2083
2101
  const tokens = await this.parseTokenResponse(tokenResponse);
2084
2102
  return {
2085
2103
  accessToken: tokens.access_token,
2086
- expiresIn: tokens.expires_in || 3600,
2104
+ // 0 when the upstream did not say, so `accessTokenTtl` and the defaults
2105
+ // apply. An hour substituted here made every such token look as though
2106
+ // the upstream had set it, and neither was ever reached.
2107
+ expiresIn: _nullishCoalesce(tokens.expires_in, () => ( 0)),
2087
2108
  idToken: tokens.id_token,
2088
2109
  issuedAt: /* @__PURE__ */ new Date(),
2089
2110
  refreshExpiresIn: tokens.refresh_expires_in,
@@ -2175,6 +2196,7 @@ var OAuthProxy = (_class4 = class {
2175
2196
  expiresAt: new Date(
2176
2197
  Date.now() + (this.config.authorizationCodeTtl || 300) * 1e3
2177
2198
  ),
2199
+ redirectUri: transaction.clientCallbackUrl,
2178
2200
  transactionId: transaction.id,
2179
2201
  upstreamTokens
2180
2202
  };
@@ -2618,7 +2640,13 @@ var OAuthProxy = (_class4 = class {
2618
2640
  id_token: _zod.z.string().optional(),
2619
2641
  refresh_expires_in: _zod.z.coerce.number().int().positive().optional(),
2620
2642
  refresh_token: _zod.z.string().optional(),
2621
- scope: _zod.z.string().optional(),
2643
+ // GitHub lists the scopes it granted with commas, `read:user,user:email`,
2644
+ // which read as one scope that no check matched. RFC 6749 §3.3 separates
2645
+ // scopes with spaces and allows a comma inside one, so only GitHub's are
2646
+ // split.
2647
+ scope: _zod.z.string().transform(
2648
+ (scope) => this.config.upstreamTokenEndpoint === GITHUB_TOKEN_ENDPOINT ? scope.split(/[ ,]+/).filter(Boolean).join(" ") : scope
2649
+ ).optional(),
2622
2650
  token_type: _zod.z.string().optional()
2623
2651
  });
2624
2652
  if (contentType.includes("application/x-www-form-urlencoded")) {
@@ -2726,7 +2754,8 @@ var OAuthProxy = (_class4 = class {
2726
2754
  const tokens = await this.parseTokenResponse(tokenResponse);
2727
2755
  return {
2728
2756
  accessToken: tokens.access_token,
2729
- expiresIn: tokens.expires_in || 3600,
2757
+ // 0 when the upstream did not say, as on the code exchange.
2758
+ expiresIn: _nullishCoalesce(tokens.expires_in, () => ( 0)),
2730
2759
  idToken: tokens.id_token,
2731
2760
  issuedAt: /* @__PURE__ */ new Date(),
2732
2761
  refreshExpiresIn: tokens.refresh_expires_in,
@@ -3656,4 +3685,4 @@ Original error: ${error.message}`
3656
3685
 
3657
3686
 
3658
3687
  exports.withoutTrailingSlash = withoutTrailingSlash; exports.getAuthSession = getAuthSession; exports.requireAll = requireAll; exports.requireAny = requireAny; exports.requireAuth = requireAuth; exports.requireRole = requireRole; exports.requireScopes = requireScopes; exports.DEFAULT_ACCESS_TOKEN_TTL = DEFAULT_ACCESS_TOKEN_TTL; exports.DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH = DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH; exports.DEFAULT_REFRESH_TOKEN_TTL = DEFAULT_REFRESH_TOKEN_TTL; exports.DEFAULT_AUTHORIZATION_CODE_TTL = DEFAULT_AUTHORIZATION_CODE_TTL; exports.DEFAULT_TRANSACTION_TTL = DEFAULT_TRANSACTION_TTL; exports.ConsentManager = ConsentManager; exports.JWTIssuer = JWTIssuer; exports.PKCEUtils = PKCEUtils; exports.EncryptedTokenStorage = EncryptedTokenStorage; exports.MemoryTokenStorage = MemoryTokenStorage; exports.OAuthProxy = OAuthProxy; exports.OAuthProxyError = OAuthProxyError; exports.AuthProvider = AuthProvider; exports.AzureProvider = AzureProvider; exports.GitHubProvider = GitHubProvider; exports.GoogleProvider = GoogleProvider; exports.OAuthProvider = OAuthProvider; exports.DiskStore = DiskStore; exports.JWKSVerifier = JWKSVerifier;
3659
- //# sourceMappingURL=chunk-XGRRYN5Y.cjs.map
3688
+ //# sourceMappingURL=chunk-SKQK3QGJ.cjs.map