Skip to content

Commit 7b89930

Browse files
committed
improve params schema
1 parent 813894d commit 7b89930

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

apps/radar/src/types/radar.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ import { z } from 'zod'
66
import type { ASNListParams } from 'cloudflare/resources/radar/entities/asns.mjs'
77
import type { TrafficAnomalyGetParams } from 'cloudflare/resources/radar/traffic-anomalies.mjs'
88

9-
export const AsnParam = z.number().positive()
9+
export const AsnParam = z
10+
.number()
11+
.positive()
12+
.describe('Autonomous System Number (ASN), must be a positive number.')
1013

11-
export const IpParam = z.string().ip()
14+
export const IpParam = z.string().ip().describe('IPv4 or IPv6 address in standard notation.')
1215

1316
export const DateRangeParam: z.ZodType<TrafficAnomalyGetParams['dateRange']> = z
1417
.string()
@@ -17,11 +20,19 @@ export const DateRangeParam: z.ZodType<TrafficAnomalyGetParams['dateRange']> = z
1720
/^((([1-9]|[1-9][0-9]|[1-2][0-9][0-9]|3[0-5][0-9]|36[0-4])[d](control)?)|(([1-9]|[1-4][0-9]|5[0-2])[w](control)?))$/,
1821
'Invalid Date Range'
1922
)
23+
.describe(
24+
"Date range string in the format of 'Xd' or 'Xw', where X is a number of days (1–364) or weeks (1–52), optionally suffixed with 'control'."
25+
)
2026

21-
//TODO use ".describe("...")"
27+
export const DateStartParam: z.ZodType<TrafficAnomalyGetParams['dateStart']> = z
28+
.string()
29+
.datetime()
30+
.describe('Start date in ISO 8601 format (e.g., 2023-04-01T00:00:00Z).')
2231

23-
export const DateStartParam: z.ZodType<TrafficAnomalyGetParams['dateStart']> = z.string().datetime()
24-
export const DateEndParam: z.ZodType<TrafficAnomalyGetParams['dateEnd']> = z.string().datetime()
32+
export const DateEndParam: z.ZodType<TrafficAnomalyGetParams['dateEnd']> = z
33+
.string()
34+
.datetime()
35+
.describe('End date in ISO 8601 format (e.g., 2023-04-30T23:59:59Z).')
2536

2637
export const SingleLocationParam: z.ZodType<ASNListParams['location']> = z
2738
.string()
@@ -30,7 +41,9 @@ export const SingleLocationParam: z.ZodType<ASNListParams['location']> = z
3041
'Invalid location code. Must be a valid alpha-2 location code (two letters, case insensitive).',
3142
})
3243
.optional()
44+
.describe('Optional alpha-2 country code (e.g., "US", "DE").')
3345

3446
export const AsOrderByParam: z.ZodType<ASNListParams['orderBy']> = z
3547
.enum(['ASN', 'POPULATION'])
3648
.optional()
49+
.describe('Optional order by parameter: "ASN" or "POPULATION".')

apps/radar/src/types/url-scanner.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@
33
*/
44
import { z } from 'zod'
55

6-
export const UrlParam = z.string().url()
6+
export const UrlParam = z
7+
.string()
8+
.url()
9+
.describe('A valid URL including protocol (e.g., "https://example.com").')

0 commit comments

Comments
 (0)