@kubb/plugin-client 5.7.0-canary.20261024T172532 → 5.7.0

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/dist/index.cjs CHANGED
@@ -454,7 +454,7 @@ var compatibility = {
454
454
  };
455
455
  //#endregion
456
456
  //#region package.json
457
- var version = "5.7.0-canary.20261024T172532";
457
+ var version = "5.7.0";
458
458
  //#endregion
459
459
  //#region ../../internals/client/src/builders/validatorOptions.ts
460
460
  /**
@@ -463,7 +463,7 @@ var version = "5.7.0-canary.20261024T172532";
463
463
  function isValidatorEnabled(validator) {
464
464
  if (!validator) return false;
465
465
  if (validator === "zod") return true;
466
- return Boolean(validator.request || validator.response);
466
+ return Boolean(validator.request || validator.params || validator.response);
467
467
  }
468
468
  /**
469
469
  * Returns `'zod'` when request body parsing is enabled, `null` otherwise. The string shorthand
@@ -474,6 +474,14 @@ function resolveRequestValidator(validator) {
474
474
  return validator.request ?? null;
475
475
  }
476
476
  /**
477
+ * Returns `'zod'` when path, query, and header params parsing is enabled, `null` otherwise. Only the
478
+ * object form `{ params: 'zod' }` enables it.
479
+ */
480
+ function resolveParamsValidator(validator) {
481
+ if (!validator || validator === "zod") return null;
482
+ return validator.params ?? null;
483
+ }
484
+ /**
477
485
  * Returns `'zod'` when response parsing is enabled, `null` otherwise. The string shorthand `'zod'`
478
486
  * maps to response parsing.
479
487
  */
@@ -492,36 +500,13 @@ function buildZodErrorParse(node, zodResolver) {
492
500
  return zodResolver.response.error?.(node) || null;
493
501
  }
494
502
  //#endregion
495
- //#region ../../internals/client/src/builders/validator.ts
496
- /**
497
- * Builds the validator-hook references for one operation. Request validation runs before the send;
498
- * response validation runs on the success body only. Returns `null` references when the matching
499
- * direction is disabled or the schema is absent.
500
- */
501
- function buildValidatorHooks({ node, validator, zodResolver }) {
502
- const hasRequestBody = Boolean(node.requestBody?.content?.[0]?.schema);
503
- const parsesResponse = zodResolver && resolveResponseValidator(validator) === "zod";
504
- const response = parsesResponse ? zodResolver.response.response(node) || null : null;
505
- const error = parsesResponse ? buildZodErrorParse(node, zodResolver) : null;
506
- const request = zodResolver && resolveRequestValidator(validator) === "zod" && hasRequestBody ? zodResolver.response.body(node) || null : null;
507
- return {
508
- request,
509
- response,
510
- error,
511
- importedZodNames: [
512
- response,
513
- error,
514
- request
515
- ].filter((name) => Boolean(name))
516
- };
517
- }
518
- //#endregion
519
503
  //#region ../../internals/client/src/builders/security.ts
520
504
  function serializeAuth(auth) {
521
505
  const parts = [`type: '${auth.type}'`];
522
506
  if (auth.scheme) parts.push(`scheme: '${auth.scheme}'`);
523
507
  if (auth.name) parts.push(`name: '${auth.name}'`);
524
508
  if (auth.in) parts.push(`in: '${auth.in}'`);
509
+ if (auth.scopes?.length) parts.push(`scopes: [${auth.scopes.map((scope) => `'${scope}'`).join(", ")}]`);
525
510
  return `{ ${parts.join(", ")} }`;
526
511
  }
527
512
  /**
@@ -564,11 +549,14 @@ function getOperationSecurity({ document, method, path }) {
564
549
  const definitions = document.components?.securitySchemes ?? {};
565
550
  const security = [];
566
551
  const seen = /* @__PURE__ */ new Set();
567
- for (const requirement of requirements) for (const schemeName of Object.keys(requirement)) {
552
+ for (const requirement of requirements) for (const [schemeName, scopes] of Object.entries(requirement)) {
568
553
  if (seen.has(schemeName)) continue;
569
554
  seen.add(schemeName);
570
555
  const auth = resolveSecurityScheme(definitions[schemeName]);
571
- if (auth) security.push(auth);
556
+ if (auth) security.push(scopes.length ? {
557
+ ...auth,
558
+ scopes
559
+ } : auth);
572
560
  }
573
561
  return security.length ? security : void 0;
574
562
  }
@@ -584,6 +572,49 @@ function buildSecurityMetadata({ security }) {
584
572
  return `[${security.map(serializeAuth).join(", ")}]`;
585
573
  }
586
574
  //#endregion
575
+ //#region ../../internals/client/src/builders/validator.ts
576
+ /**
577
+ * Builds the validator-hook references for one operation. Request body and params validation run before the send.
578
+ * Response validation runs on the success body only. Returns `null` references when the matching
579
+ * direction is disabled or the schema is absent.
580
+ */
581
+ function buildValidatorHooks({ node, validator, zodResolver }) {
582
+ const hasRequestBody = Boolean(node.requestBody?.content?.[0]?.schema);
583
+ const parsesResponse = zodResolver && resolveResponseValidator(validator) === "zod";
584
+ const response = parsesResponse ? zodResolver.response.response(node) || null : null;
585
+ const error = parsesResponse ? buildZodErrorParse(node, zodResolver) : null;
586
+ const request = zodResolver && resolveRequestValidator(validator) === "zod" && hasRequestBody ? zodResolver.response.body(node) || null : null;
587
+ const paramGroups = getOperationParameters(node);
588
+ const resolveParamsName = (kind, params) => zodResolver && resolveParamsValidator(validator) === "zod" && params.length > 0 ? zodResolver.param[kind](node, params[0]) : null;
589
+ const path = resolveParamsName("path", paramGroups.path);
590
+ const query = resolveParamsName("query", paramGroups.query);
591
+ const headers = resolveParamsName("headers", paramGroups.header);
592
+ const importedZodNames = [
593
+ response,
594
+ error,
595
+ request,
596
+ path,
597
+ query,
598
+ headers
599
+ ].filter((name) => Boolean(name));
600
+ return {
601
+ request,
602
+ path,
603
+ query,
604
+ headers: headers ? `toHeadersStandardSchema(${headers}, ${headers}.shape)` : null,
605
+ response,
606
+ error,
607
+ importedZodNames
608
+ };
609
+ }
610
+ /**
611
+ * Prints the `validator: { … }` entry of a call config from the hooks named in `keys`, or `null` when none is set.
612
+ */
613
+ function buildValidatorLiteral(hooks, keys) {
614
+ const entries = keys.flatMap((key) => hooks?.[key] ? [`${key}: ${hooks[key]}`] : []);
615
+ return entries.length ? `validator: { ${entries.join(", ")} }` : null;
616
+ }
617
+ //#endregion
587
618
  //#region ../../internals/client/src/builders/contentType.ts
588
619
  /**
589
620
  * Builds the `contentType` entry baked into the call config, or `null` for the JSON default.
@@ -788,12 +819,14 @@ function Operation({ name, node, types, zodResolver, validator, returnType, thro
788
819
  const eventStream = isEventStream(node);
789
820
  const responseType = getResponseType(node);
790
821
  const responseTypeLiteral = responseType ? `responseType: '${responseType}'` : null;
791
- const validatorEntries = [
792
- validators.request ? `request: ${validators.request}` : null,
793
- validators.response ? `response: ${validators.response}` : null,
794
- validators.error ? `error: ${validators.error}` : null
795
- ].filter(Boolean);
796
- const validatorLiteral = validatorEntries.length ? `validator: { ${validatorEntries.join(", ")} }` : null;
822
+ const validatorLiteral = buildValidatorLiteral(validators, [
823
+ "request",
824
+ "path",
825
+ "query",
826
+ "headers",
827
+ "response",
828
+ "error"
829
+ ]);
797
830
  const callConfig = `{ ${[
798
831
  `method: '${node.method.toUpperCase()}'`,
799
832
  `url: '${node.path}'`,
@@ -905,14 +938,15 @@ function createClientGenerator(name, resolveClientPath) {
905
938
  const { config, driver, resolver, root } = ctx;
906
939
  const { output, validator, returnType, throwOnErrorDefault, group } = ctx.options;
907
940
  const types = resolveOperationTypes(driver, ctx.plugin.name);
908
- const pluginZod = resolveResponseValidator(validator) === "zod" || resolveRequestValidator(validator) === "zod" ? driver.getPlugin(_kubb_plugin_zod.pluginZodName) : null;
941
+ const pluginZod = isValidatorEnabled(validator) ? driver.getPlugin(_kubb_plugin_zod.pluginZodName) : null;
909
942
  const zodResolver = pluginZod ? driver.getResolver(_kubb_plugin_zod.pluginZodName) : null;
910
943
  const importedTypeNames = [types.response.options(node), types.response.responses(node)];
911
- const importedZodNames = buildValidatorHooks({
944
+ const validatorHooks = buildValidatorHooks({
912
945
  node,
913
946
  validator,
914
947
  zodResolver
915
- }).importedZodNames;
948
+ });
949
+ const importedZodNames = validatorHooks.importedZodNames;
916
950
  const meta = {
917
951
  name: resolver.name(node.operationId),
918
952
  file: resolver.file({
@@ -944,6 +978,7 @@ function createClientGenerator(name, resolveClientPath) {
944
978
  const customClientPath = resolveClientPath?.(ctx.options, root);
945
979
  const clientPath = customClientPath ?? node_path.default.resolve(root, ".kubb/client.ts");
946
980
  const clientRoot = customClientPath === void 0 ? meta.file.path : void 0;
981
+ const standardSchemaPath = customClientPath ?? node_path.default.resolve(root, ".kubb/standardSchema.ts");
947
982
  const eventStream = isEventStream(node);
948
983
  const clientValueImports = (() => {
949
984
  if (eventStream) return ["client", "toEventStream"];
@@ -1008,6 +1043,11 @@ function createClientGenerator(name, resolveClientPath) {
1008
1043
  root: meta.file.path,
1009
1044
  path: meta.fileZod.path
1010
1045
  }),
1046
+ validatorHooks.headers && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1047
+ name: ["toHeadersStandardSchema"],
1048
+ root: clientRoot,
1049
+ path: standardSchemaPath
1050
+ }),
1011
1051
  /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(Operation, {
1012
1052
  name: meta.name,
1013
1053
  node,