Skip to content

Commit 1b4c879

Browse files
matticbotrenovate-botXavier Lozano Carrerasclaude
authored
Update dependency zod to v4 [SECURITY] (#54072)
* Update dependency zod to v4 [SECURITY] * Fix type errors from the zod 4 upgrade Zod 4's ZodSchema/ZodType infer `unknown` where Zod 3 inferred `any`, and z.record() now requires a key schema. --------- Co-authored-by: Renovate Bot <bot@renovateapp.com> Co-authored-by: Xavier Lozano Carreras <xavier.lozano.carreras@automattic.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent b27f23c commit 1b4c879

15 files changed

Lines changed: 58 additions & 42 deletions

File tree

‎pnpm-lock.yaml‎

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pnpm-workspace.yaml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ minimumReleaseAgeExclude:
3838
- '@wordpress/*'
3939
- 'gridicons'
4040
- 'wpcom-proxy-request'
41+
# Renovate security update: zod@4.6.6
42+
- zod@4.6.6
4143

4244
trustPolicy: no-downgrade
4345
trustPolicyExclude:
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: changed
3+
4+
Update package dependencies.

‎projects/js-packages/boost-score-api/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
},
3232
"dependencies": {
3333
"@wordpress/i18n": "6.30.0",
34-
"zod": "3.25.76"
34+
"zod": "4.6.6"
3535
},
3636
"devDependencies": {
3737
"@jest/globals": "30.5.2",
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: changed
3+
4+
Update package dependencies.

‎projects/js-packages/react-data-sync-client/package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@
3636
},
3737
"peerDependencies": {
3838
"react": "^18.0.0 || ^19.0.0",
39-
"zod": "^3.0.0"
39+
"zod": "^4.6.6"
4040
},
4141
"devDependencies": {
4242
"@typescript/native-preview": "7.0.0-dev.20260707.2",
4343
"jest": "30.5.2",
4444
"react": "19.3.0",
4545
"react-dom": "^19.3.0",
46-
"zod": "3.25.76"
46+
"zod": "4.6.6"
4747
}
4848
}

‎projects/js-packages/react-data-sync-client/src/DataSync.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { z } from 'zod';
22
import { DataSyncError } from './DataSyncError';
3-
import type { JSONSchema, ParsedValue } from './types';
3+
import type { AnySchema, JSONSchema, ParsedValue } from './types';
44

55
export type RequestParams = string | JSONSchema;
66
type RequestMethods = 'GET' | 'POST' | 'DELETE';
@@ -19,7 +19,7 @@ type GetRequestParams = Record< string, string | number | null | Array< string |
1919
*
2020
* Note: The keys are converted to be snake_case in Objects, but kebab-case in URLs.
2121
*/
22-
export class DataSync< Schema extends z.ZodSchema, Value extends z.infer< Schema > > {
22+
export class DataSync< Schema extends AnySchema, Value extends z.infer< Schema > > {
2323
/**
2424
* WordPress REST API Endpoint configuration.
2525
* @param wpDatasyncUrl - For example: http://localhost/wp-json/jetpack-favorites
@@ -133,7 +133,7 @@ export class DataSync< Schema extends z.ZodSchema, Value extends z.infer< Schema
133133
* @param valueSchema - The Zod schema to validate the value against.
134134
* @returns The parsed value.
135135
*/
136-
private getWindowValue< V extends z.ZodSchema >(
136+
private getWindowValue< V extends AnySchema >(
137137
valueName: string,
138138
valueSchema: V
139139
): ParsedValue< V > {
@@ -417,7 +417,7 @@ export class DataSync< Schema extends z.ZodSchema, Value extends z.infer< Schema
417417
* @param value - The value to send to the endpoint.
418418
* @returns A direct response from the endpoint.
419419
*/
420-
public ACTION = async < T extends RequestParams, R extends z.ZodSchema >(
420+
public ACTION = async < T extends RequestParams, R extends AnySchema >(
421421
name: string,
422422
value: T,
423423
schema: R

‎projects/js-packages/react-data-sync-client/src/DataSyncHooks.ts‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { createElement, useCallback, useEffect, useState } from 'react';
1212
import { z } from 'zod';
1313
import { DataSync } from './DataSync';
1414
import { DataSyncError } from './DataSyncError';
15+
import type { AnySchema } from './types';
1516
import type { ReactNode } from 'react';
1617

1718
/**
@@ -38,14 +39,14 @@ export function DataSyncProvider( props: { children: ReactNode } ) {
3839
*/
3940
type DataSyncMutation< Value > = Omit< UseMutationOptions< Value >, 'mutationKey' >;
4041
type DataSyncQuery< Value > = Omit< UseQueryOptions< Value >, 'queryKey' >;
41-
type DataSyncConfig< Schema extends z.ZodSchema, Value extends z.infer< Schema > > = {
42+
type DataSyncConfig< Schema extends AnySchema, Value extends z.infer< Schema > > = {
4243
query?: DataSyncQuery< Value >;
4344
mutation?: DataSyncMutation< Value >;
4445
};
4546
/**
4647
* This is what `useDataSync` returns
4748
*/
48-
type DataSyncHook< Schema extends z.ZodSchema, Value extends z.infer< Schema > > = [
49+
type DataSyncHook< Schema extends AnySchema, Value extends z.infer< Schema > > = [
4950
UseQueryResult< Value >,
5051
UseMutationResult< Value, DataSyncError | Error, Value >,
5152
];
@@ -77,7 +78,7 @@ function buildQueryKey( key: string, params: Record< string, string | number > )
7778
* @see https://tanstack.com/query/v5/docs/react/reference/useMutation
7879
*/
7980
export function useDataSync<
80-
Schema extends z.ZodSchema,
81+
Schema extends AnySchema,
8182
Value extends z.infer< Schema >,
8283
Key extends string,
8384
>(
@@ -205,10 +206,10 @@ export function useDataSync<
205206
* Use React Query mutations to dispatch custom DataSync Actions.
206207
*/
207208
export type DataSyncActionConfig<
208-
ActionRequestSchema extends z.ZodSchema,
209+
ActionRequestSchema extends AnySchema,
209210
ActionRequestData extends z.infer< ActionRequestSchema >,
210-
StateSchema extends z.ZodSchema,
211-
ActionSchema extends z.ZodSchema,
211+
StateSchema extends AnySchema,
212+
ActionSchema extends AnySchema,
212213
ActionResult extends z.infer< ActionSchema >,
213214
CurrentState extends z.infer< StateSchema >,
214215
> = {
@@ -274,9 +275,9 @@ export type DataSyncActionConfig<
274275
params?: Record< string, string | number >;
275276
};
276277
export function useDataSyncAction<
277-
StateSchema extends z.ZodSchema,
278-
ActionSchema extends z.ZodSchema,
279-
ActionRequestSchema extends z.ZodSchema,
278+
StateSchema extends AnySchema,
279+
ActionSchema extends AnySchema,
280+
ActionRequestSchema extends AnySchema,
280281
ActionRequestData extends z.infer< ActionRequestSchema >,
281282
ActionResult extends z.infer< ActionSchema >,
282283
CurrentState extends z.infer< StateSchema >,
@@ -368,7 +369,7 @@ type SubsetMutation< T > = {
368369
};
369370

370371
export function useDataSyncSubset<
371-
Schema extends z.ZodSchema,
372+
Schema extends AnySchema,
372373
Value extends z.infer< Schema >,
373374
K extends keyof Value,
374375
>( hook: DataSyncHook< Schema, Value >, key: K ): [ Value[ K ], SubsetMutation< Value[ K ] > ] {

‎projects/js-packages/react-data-sync-client/src/types.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import { z } from 'zod';
22

3+
// Zod 4's `ZodType` infers `unknown`; DataSync's generics rely on Zod 3's `any`.
4+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
5+
export type AnySchema = z.ZodType< any >;
6+
37
/**
48
* A syncable value with a nonce that's parsed by Zod.
59
*/
6-
export type ParsedValue< T extends z.ZodSchema > = {
10+
export type ParsedValue< T extends AnySchema > = {
711
value: z.infer< T >;
812
nonce: string;
913
};
@@ -28,6 +32,6 @@ type Literal = z.infer< typeof literalSchema >;
2832
type Json = Literal | { [ key: string ]: Json } | Json[];
2933

3034
export const jsonSchema: z.ZodType< Json > = z.lazy( () =>
31-
z.union( [ literalSchema, z.array( jsonSchema ), z.record( jsonSchema ) ] )
35+
z.union( [ literalSchema, z.array( jsonSchema ), z.record( z.string(), jsonSchema ) ] )
3236
);
3337
export type JSONSchema = z.infer< typeof jsonSchema >;

‎projects/plugins/boost/app/assets/src/js/features/critical-css/lib/stores/critical-css-state-types.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const CriticalCssErrorType = z.union( [
3131
export const CriticalCssErrorDetailsSchema = z.object( {
3232
url: z.coerce.string(),
3333
message: z.coerce.string(),
34-
meta: z.record( JSONSchema ).catch( {} ),
34+
meta: z.record( z.string(), JSONSchema ).catch( {} ),
3535
type: CriticalCssErrorType.catch( 'UnknownError' ),
3636
} );
3737

0 commit comments

Comments
 (0)