Skip to content

Commit 867aa8e

Browse files
authored
chore(deps): update zod to v4 (#429)
1 parent 00602a5 commit 867aa8e

File tree

12 files changed

+83
-80
lines changed

12 files changed

+83
-80
lines changed

api/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"license": "ISC",
1515
"description": "",
1616
"dependencies": {
17-
"@hono/zod-validator": "^0.7.3",
17+
"@hono/zod-validator": "^0.7.5",
1818
"@interledger/open-payments": "^7.1.3",
1919
"@noble/ed25519": "^3.0.0",
2020
"@paralleldrive/cuid2": "^2.2.2",
@@ -24,7 +24,7 @@
2424
"hono": "^4.9.8",
2525
"http-message-signatures": "^1.0.4",
2626
"httpbis-digest-headers": "^1.0.0",
27-
"zod": "^3.25.76"
27+
"zod": "^4.1.13"
2828
},
2929
"types": "./src/types.ts",
3030
"devDependencies": {

api/src/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ app.onError((error, c) => {
4646
message: 'Validation failed',
4747
code: 'VALIDATION_ERROR',
4848
details: {
49-
issues: error.errors.map((err) => ({
49+
issues: error.issues.map((err) => ({
5050
path: err.path.join('.'),
5151
message: err.message,
5252
code: err.code

api/src/routes/get-config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { zValidator } from '@hono/zod-validator'
22
import { HTTPException } from 'hono/http-exception'
3-
import { z } from 'zod'
3+
import z from 'zod'
44
import { ConfigStorageService } from '@shared/config-storage-service'
55
import { AWS_PREFIX } from '@shared/defines'
66
import { PRESET_IDS, TOOLS } from '@shared/types'
@@ -26,7 +26,7 @@ app.get(
2626
zValidator(
2727
'query',
2828
z.object({
29-
wa: z.string().url(),
29+
wa: z.url(),
3030
preset: z.enum(PRESET_IDS)
3131
})
3232
),

api/src/routes/probabilistic-revshare.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { HTTPException } from 'hono/http-exception'
22
import { zValidator } from '@hono/zod-validator'
3-
import { z } from 'zod'
3+
import z from 'zod'
44
import type { ContentfulStatusCode } from 'hono/utils/http-status'
55
import type { WalletAddress } from '@interledger/open-payments'
66
import { decode, pickWeightedRandom } from '@shared/probabilistic-revenue-share'
@@ -14,7 +14,7 @@ app.get(
1414
zValidator(
1515
'param',
1616
z.object({
17-
payload: z.string().base64url().max(50_000).min(20)
17+
payload: z.base64url().max(50_000).min(20)
1818
})
1919
),
2020
async ({ req, json }) => {

api/src/schemas/payment.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import * as z from 'zod/v4'
1+
import z from 'zod'
22

33
export const PaymentQuoteSchema = z.object({
4-
senderWalletAddress: z.string().url('Invalid sender wallet address'),
5-
receiverWalletAddress: z.string().url('Invalid receiver wallet address'),
4+
senderWalletAddress: z.url('Invalid sender wallet address'),
5+
receiverWalletAddress: z.url('Invalid receiver wallet address'),
66
amount: z.number().positive('Amount must be positive'),
77
note: z.string().optional()
88
})
@@ -35,11 +35,11 @@ export const PaymentFinalizeSchema = z.object({
3535
walletAddress: WalletAddressSchema,
3636
pendingGrant: z.object({
3737
interact: z.object({
38-
redirect: z.string().url(),
38+
redirect: z.url(),
3939
finish: z.string()
4040
}),
4141
continue: z.object({
42-
uri: z.string().url(),
42+
uri: z.url(),
4343
access_token: z.object({
4444
value: z.string()
4545
}),
@@ -48,18 +48,18 @@ export const PaymentFinalizeSchema = z.object({
4848
}),
4949
quote: z.object({
5050
id: z.string(),
51-
walletAddress: z.string().url('Invalid wallet address'),
52-
receiver: z.string().url(),
51+
walletAddress: z.url('Invalid wallet address'),
52+
receiver: z.url(),
5353
receiveAmount: AmountSchema,
5454
debitAmount: AmountSchema,
5555
method: z.literal('ilp'),
56-
createdAt: z.string().datetime(),
57-
expiresAt: z.string().datetime().optional()
56+
createdAt: z.iso.datetime(),
57+
expiresAt: z.iso.datetime().optional()
5858
}),
5959
incomingPaymentGrant: z.object({
6060
access_token: z.object({
6161
value: z.string(),
62-
manage: z.string().url(),
62+
manage: z.url(),
6363
expires_in: z.number().int(),
6464
access: z.array(
6565
z.object({
@@ -73,7 +73,7 @@ export const PaymentFinalizeSchema = z.object({
7373
access_token: z.object({
7474
value: z.string()
7575
}),
76-
uri: z.string().url(),
76+
uri: z.url(),
7777
wait: z.number().int().optional()
7878
})
7979
}),

api/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type {
44
PaymentQuoteSchema,
55
WalletAddressParamSchema
66
} from './schemas/payment.js'
7-
import type { z } from 'zod/v4'
7+
import type z from 'zod'
88

99
export type PaymentStatusSuccess = {
1010
paymentId: string

frontend/app/lib/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { z } from 'zod'
1+
import type z from 'zod'
22
import type {
33
createBannerSchema,
44
createButtonSchema,
@@ -37,7 +37,7 @@ export type SanitizedFields = Pick<
3737
>
3838

3939
export type JSONError<T extends z.ZodTypeAny> = {
40-
errors: z.typeToFlattenedError<z.infer<T>>
40+
errors: z.ZodFlattenedError<z.infer<T>>
4141
}
4242

4343
// eslint-disable-next-line @typescript-eslint/no-explicit-any

frontend/app/utils/validate.client.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
import { z } from 'zod'
1+
import z from 'zod'
22
import {
33
bannerFieldsSchema,
44
buttonFieldsSchema,
55
widgetFieldsSchema
66
} from './validate.shared'
77
import type { ElementConfigType } from '@shared/types'
88

9-
export const elementConfigStorageSchema = z
10-
.object({
11-
versionName: z.string(),
12-
tag: z.string().optional(),
13-
// can be undefined initially
14-
walletAddress: z.string().optional()
15-
})
16-
.merge(buttonFieldsSchema)
17-
.merge(bannerFieldsSchema)
18-
.merge(widgetFieldsSchema)
9+
export const elementConfigStorageSchema = z.object({
10+
versionName: z.string(),
11+
tag: z.string().optional(),
12+
// can be undefined initially
13+
walletAddress: z.string().optional(),
14+
...buttonFieldsSchema.shape,
15+
...bannerFieldsSchema.shape,
16+
...widgetFieldsSchema.shape
17+
})
1918

2019
/**
2120
* Validates configurations from localStorage.

frontend/app/utils/validate.server.ts

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { z } from 'zod'
1+
import z from 'zod'
22
import {
33
checkHrefFormat,
44
getWalletAddress,
@@ -29,7 +29,7 @@ export const walletSchema = z.object({
2929
await getWalletAddress(updatedUrl)
3030
} catch (e) {
3131
ctx.addIssue({
32-
code: z.ZodIssueCode.custom,
32+
code: 'custom',
3333
message:
3434
e instanceof WalletAddressFormatError
3535
? e.message
@@ -48,29 +48,26 @@ export const fullConfigSchema = z.object({
4848
fullconfig: z.string().min(1, { message: 'Unknown error' })
4949
})
5050

51-
export const createButtonSchema = z
52-
.object({
53-
elementType: z.literal('button')
54-
})
55-
.merge(buttonFieldsSchema)
56-
.merge(walletSchema)
57-
.merge(versionSchema)
51+
export const createButtonSchema = z.object({
52+
elementType: z.literal('button'),
53+
...buttonFieldsSchema.shape,
54+
...walletSchema.shape,
55+
...versionSchema.shape
56+
})
5857

59-
export const createBannerSchema = z
60-
.object({
61-
elementType: z.literal('banner')
62-
})
63-
.merge(bannerFieldsSchema)
64-
.merge(walletSchema)
65-
.merge(versionSchema)
58+
export const createBannerSchema = z.object({
59+
elementType: z.literal('banner'),
60+
...bannerFieldsSchema.shape,
61+
...walletSchema.shape,
62+
...versionSchema.shape
63+
})
6664

67-
export const createWidgetSchema = z
68-
.object({
69-
elementType: z.literal('widget')
70-
})
71-
.merge(widgetFieldsSchema)
72-
.merge(walletSchema)
73-
.merge(versionSchema)
65+
export const createWidgetSchema = z.object({
66+
elementType: z.literal('widget'),
67+
...widgetFieldsSchema.shape,
68+
...walletSchema.shape,
69+
...versionSchema.shape
70+
})
7471

7572
export const getElementSchema = (type: string) => {
7673
switch (type) {
@@ -95,7 +92,10 @@ export const validateForm = async (
9592
if (intent === 'import' || intent === 'delete') {
9693
result = await walletSchema.safeParseAsync(formData)
9794
} else if (intent === 'newversion') {
98-
const newVersionSchema = versionSchema.merge(walletSchema)
95+
const newVersionSchema = z.object({
96+
...versionSchema.shape,
97+
...walletSchema.shape
98+
})
9999
result = await newVersionSchema.safeParseAsync(formData)
100100
} else {
101101
let currentSchema
@@ -111,9 +111,13 @@ export const validateForm = async (
111111
default:
112112
currentSchema = createBannerSchema
113113
}
114-
result = await currentSchema
115-
.merge(fullConfigSchema)
116-
.safeParseAsync(Object.assign(formData, { ...{ elementType } }))
114+
const mergedSchema = z.object({
115+
...currentSchema.shape,
116+
...fullConfigSchema.shape
117+
})
118+
result = await mergedSchema.safeParseAsync(
119+
Object.assign(formData, { ...{ elementType } })
120+
)
117121
}
118122
/* eslint-disable @typescript-eslint/no-explicit-any */
119123
const payload = result.data as unknown as any

frontend/app/utils/validate.shared.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { z } from 'zod'
1+
import z from 'zod'
22
import {
33
CORNER_OPTION,
44
BANNER_POSITION,
@@ -23,7 +23,7 @@ const widgetFontSizeError = {
2323
export const buttonFieldsSchema = z.object({
2424
buttonFontName: z.string().min(1, { message: 'Choose a font' }),
2525
buttonText: z.string().min(1, { message: 'Button label cannot be empty' }),
26-
buttonBorder: z.nativeEnum(CORNER_OPTION),
26+
buttonBorder: z.enum(CORNER_OPTION),
2727
buttonTextColor: z.string().min(6),
2828
buttonBackgroundColor: z.string().min(6),
2929
buttonDescriptionText: z.string().optional()
@@ -48,10 +48,10 @@ export const bannerFieldsSchema = z.object({
4848
bannerDescriptionVisible: z.coerce.boolean().optional(),
4949
bannerTextColor: z.string().min(6),
5050
bannerBackgroundColor: z.string().min(6),
51-
bannerSlideAnimation: z.nativeEnum(SLIDE_ANIMATION),
51+
bannerSlideAnimation: z.enum(SLIDE_ANIMATION),
5252
bannerThumbnail: z.string().optional(),
53-
bannerPosition: z.nativeEnum(BANNER_POSITION),
54-
bannerBorder: z.nativeEnum(CORNER_OPTION)
53+
bannerPosition: z.enum(BANNER_POSITION),
54+
bannerBorder: z.enum(CORNER_OPTION)
5555
})
5656

5757
export const widgetFieldsSchema = z.object({
@@ -71,14 +71,14 @@ export const widgetFieldsSchema = z.object({
7171
})
7272
.optional(),
7373
widgetDescriptionVisible: z.coerce.boolean().optional(),
74-
widgetPosition: z.nativeEnum(WIDGET_POSITION),
74+
widgetPosition: z.enum(WIDGET_POSITION),
7575
widgetDonateAmount: z.coerce
7676
.number()
7777
.min(0, { message: 'Donate amount must be positive' }),
7878
widgetButtonText: z
7979
.string()
8080
.min(1, { message: 'Button text cannot be empty' }),
81-
widgetButtonBorder: z.nativeEnum(CORNER_OPTION),
81+
widgetButtonBorder: z.enum(CORNER_OPTION),
8282
widgetButtonBackgroundColor: z.string().min(1),
8383
widgetButtonTextColor: z.string().min(1),
8484
widgetTextColor: z.string().min(1),

0 commit comments

Comments
 (0)