Skip to content

Commit de4daea

Browse files
Improved schemas sharing
1 parent 2f71375 commit de4daea

File tree

6 files changed

+50
-52
lines changed

6 files changed

+50
-52
lines changed

src/schemas/PassFieldContent.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import { z } from "zod";
22
import { Semantics } from "./Semantics.js";
3-
4-
const dateTimeSchema = z.iso.datetime({
5-
offset: true,
6-
local: true,
7-
});
3+
import { dateTimeSchema } from "./sharedSchemas.js";
84

95
export type PKDataDetectorType = z.infer<typeof PKDataDetectorType>;
106

src/schemas/SemanticTagType.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
import { z } from "zod";
2-
import { RGB_HEX_COLOR_REGEX } from "./regexps.js";
3-
4-
const dateTimeSchema = z.iso.datetime({
5-
offset: true,
6-
local: true,
7-
});
2+
import { dateTimeSchema, colorRgbHexSchema } from "./sharedSchemas.js";
83

94
/**
105
* These couple of structures are organized alphabetically,
@@ -123,7 +118,7 @@ export const Seat = z.object({
123118
* @iOSVersion 18
124119
* @passStyle eventTicket (new layout)
125120
*/
126-
seatSectionColor: z.string().check(z.regex(RGB_HEX_COLOR_REGEX)).optional(),
121+
seatSectionColor: colorRgbHexSchema.optional(),
127122
});
128123

129124
/**

src/schemas/UpcomingPassInformation.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { z } from "zod";
22
import { PassFieldContent } from "./PassFieldContent.js";
33
import { Semantics } from "./Semantics.js";
4-
import { URL_REGEX } from "./regexps.js";
4+
import { dateTimeSchema, httpAddressSchema } from "./sharedSchemas.js";
55

6-
const dateTimeSchema = z.iso.datetime({
7-
offset: true,
8-
local: true,
6+
const httpsAddressSchema = z.url({
7+
protocol: /^https$/,
98
});
109

1110
/**
@@ -19,7 +18,7 @@ const ImageURLEntry = z.object({
1918
SHA256: z.string(),
2019

2120
/** The URL that points to the image asset to be downloaded. This must be an https link. */
22-
URL: z.string().check(z.regex(URL_REGEX)),
21+
URL: httpsAddressSchema,
2322

2423
/** The scale of the image. If unspecified, defaults to 1. */
2524
scale: z.number().default(1).optional(),
@@ -89,7 +88,7 @@ const URLs = z.object({
8988
/**
9089
* A URL that links to your or the venue's accessibility content.
9190
*/
92-
accessibilityURL: z.string().check(z.regex(URL_REGEX)).optional(),
91+
accessibilityURL: httpAddressSchema.optional(),
9392

9493
/**
9594
* A URL that links to experiences that you can add on to your ticket
@@ -98,12 +97,12 @@ const URLs = z.object({
9897
* access the experience. For example, loaded value or upgrades for
9998
* an experience.
10099
*/
101-
addOnURL: z.string().check(z.regex(URL_REGEX)).optional(),
100+
addOnURL: httpAddressSchema.optional(),
102101

103102
/**
104103
* A URL that links out to the bag policy of the venue.
105104
*/
106-
bagPolicyURL: z.string().check(z.regex(URL_REGEX)).optional(),
105+
bagPolicyURL: httpAddressSchema.optional(),
107106

108107
/**
109108
* Joi's email schema validates email TLDs and only allows TLDs that are registered in the IANA Registry.
@@ -126,12 +125,12 @@ const URLs = z.object({
126125
/**
127126
* A URL that links the user to the website of the venue, event, or issuer.
128127
*/
129-
contactVenueWebsite: z.string().check(z.regex(URL_REGEX)).optional(),
128+
contactVenueWebsite: httpAddressSchema.optional(),
130129

131130
/**
132131
* A URL that links to content you have about getting to the venue.
133132
*/
134-
directionsInformationURL: z.string().check(z.regex(URL_REGEX)).optional(),
133+
directionsInformationURL: httpAddressSchema.optional(),
135134

136135
/**
137136
* A URL that links to order merchandise for the specific event.
@@ -145,43 +144,43 @@ const URLs = z.object({
145144
* This can be done through a pass update. For more information on updating a
146145
* pass, see Distributing and updating a pass.
147146
*/
148-
merchandiseURL: z.string().check(z.regex(URL_REGEX)).optional(),
147+
merchandiseURL: httpAddressSchema.optional(),
149148

150149
/**
151150
* A URL that links out to the food-ordering page for the venue.
152151
* This can be in-seat food delivery, pre-order for pickup at a vendor,
153152
* or other appropriate food-ordering service.
154153
*/
155-
orderFoodURL: z.string().check(z.regex(URL_REGEX)).optional(),
154+
orderFoodURL: httpAddressSchema.optional(),
156155

157156
/**
158157
* A URL that links to any information you have about parking.
159158
*/
160-
parkingInformationURL: z.string().check(z.regex(URL_REGEX)).optional(),
159+
parkingInformationURL: httpAddressSchema.optional(),
161160

162161
/**
163162
* A URL that links to your experience to buy or access prepaid parking
164163
* or general parking information.
165164
*/
166-
purchaseParkingURL: z.string().check(z.regex(URL_REGEX)).optional(),
165+
purchaseParkingURL: httpAddressSchema.optional(),
167166

168167
/**
169168
* A URL that launches the user into the issuer's flow for selling their
170169
* current ticket. Provide as deep a link as possible into the sale flow.
171170
*/
172-
sellURL: z.string().check(z.regex(URL_REGEX)).optional(),
171+
sellURL: httpAddressSchema.optional(),
173172

174173
/**
175174
* A URL that launches the user into the issuer's flow for transferring
176175
* the current ticket. Provide as deep a link as possible into the transfer flow.
177176
*/
178-
transferURL: z.string().check(z.regex(URL_REGEX)).optional(),
177+
transferURL: httpAddressSchema.optional(),
179178

180179
/**
181180
* A URL that links to documentation you have about public or private
182181
* transit to the venue.
183182
*/
184-
transitInformationURL: z.string().check(z.regex(URL_REGEX)).optional(),
183+
transitInformationURL: httpAddressSchema.optional(),
185184
});
186185

187186
/**

src/schemas/index.ts

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,11 @@ import { CertificatesSchema } from "./Certificates.js";
2222
import { UpcomingPassInformationEntry } from "./UpcomingPassInformation.js";
2323

2424
import * as Messages from "../messages.js";
25-
import { RGB_HEX_COLOR_REGEX } from "./regexps.js";
26-
27-
const httpAddressSchema = z.url({
28-
protocol: /^https?$/,
29-
});
30-
const dateTimeSchema = z.union([
31-
z.iso.datetime({
32-
offset: true,
33-
local: true,
34-
}),
35-
z.date(),
36-
]);
25+
import {
26+
colorRgbHexSchema,
27+
dateTimeSchema,
28+
httpAddressSchema,
29+
} from "./sharedSchemas.js";
3730

3831
/**
3932
* @iOSVersion 18
@@ -148,10 +141,10 @@ export type PassTypesProps = PassType;
148141
export type PassColors = z.infer<typeof PassColors>;
149142

150143
export const PassColors = z.object({
151-
backgroundColor: z.string().check(z.regex(RGB_HEX_COLOR_REGEX)).optional(),
152-
foregroundColor: z.string().check(z.regex(RGB_HEX_COLOR_REGEX)).optional(),
153-
labelColor: z.string().check(z.regex(RGB_HEX_COLOR_REGEX)).optional(),
154-
stripColor: z.string().check(z.regex(RGB_HEX_COLOR_REGEX)).optional(),
144+
backgroundColor: colorRgbHexSchema.optional(),
145+
foregroundColor: colorRgbHexSchema.optional(),
146+
labelColor: colorRgbHexSchema.optional(),
147+
stripColor: colorRgbHexSchema.optional(),
155148

156149
/**
157150
* @iOSVersion 18
@@ -164,10 +157,7 @@ export const PassColors = z.object({
164157
* to specify a different and specific color
165158
* for it.
166159
*/
167-
footerBackgroundColor: z
168-
.string()
169-
.check(z.regex(RGB_HEX_COLOR_REGEX))
170-
.optional(),
160+
footerBackgroundColor: colorRgbHexSchema.optional(),
171161

172162
/**
173163
* @iOSVersion 18

src/schemas/regexps.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/schemas/sharedSchemas.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import z from "zod";
2+
3+
export const httpAddressSchema = z.url({
4+
protocol: /^https?$/,
5+
});
6+
7+
export const dateTimeSchema = z.union([
8+
z.iso.datetime({
9+
offset: true,
10+
local: true,
11+
}),
12+
z.date(),
13+
]);
14+
15+
export const colorRgbHexSchema = z
16+
.string()
17+
.check(
18+
z.regex(
19+
/(?:\#[a-fA-F0-9]{3,6}|rgb\(\s*(?:[01]?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\s*,\s*(?:[01]?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\s*,\s*(?:[01]?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\s*\))/,
20+
),
21+
);

0 commit comments

Comments
 (0)