Skip to content

Commit 9aca26d

Browse files
committed
fix: stricter validation/reorder analysis steps
1 parent a61185e commit 9aca26d

2 files changed

Lines changed: 39 additions & 36 deletions

File tree

background/src/index.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,26 @@ function parseRecord(record: Airtable.Record<Airtable.FieldSet>) {
5656
let data: any;
5757
try {
5858
data = websiteJson ? JSON.parse(websiteJson) : {};
59-
60-
if (websiteActive) {
61-
if (data.version !== VERSION) {
62-
data = { error: "Your JSON is outdated. Please update it!" };
63-
} else {
64-
const validationErrors = validateSatelliteContent(data);
65-
if (validationErrors.length > 0) {
66-
console.error(`Validation errors for slug ${slug}: ${validationErrors.join(', ')}`);
67-
data = { error: `Invalid JSON structure: ${validationErrors.join(', ')}` };
68-
}
69-
}
70-
}
7159
} catch (error) {
7260
console.error(`Error parsing JSON for slug ${slug}: ${error}`);
7361
data = { error: "Error parsing JSON. Make sure the JSON is valid!" };
7462
}
7563

64+
if (websiteActive && !data.error) {
65+
try {
66+
const validationErrors = validateSatelliteContent(data);
67+
if (validationErrors.length > 0) {
68+
console.error(`Validation errors for slug ${slug}: ${validationErrors.join(', ')}`);
69+
data = { error: `Invalid JSON structure: ${validationErrors.join(', ')}` };
70+
} else if (data.version !== VERSION) {
71+
data = { error: "Your JSON is outdated. Please update it!" };
72+
}
73+
} catch (error) {
74+
console.error(`Unexpected validation error for slug ${slug}: ${error}`);
75+
data = { error: "Unexpected error during validation." };
76+
}
77+
}
78+
7679
if (status === 'Canceled') {
7780
data.cancelled = true;
7881
}

background/src/satellite.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const SatelliteContentSchema = z.object({
1616
ctaSecondarySuffix: z.string(),
1717
videoLabel: z.string().optional(),
1818
mapLabel: z.string(),
19-
}),
19+
}).strict(),
2020
nav: z.record(z.string(), z.string()),
2121
steps: z.object({
2222
stepLabel: z.string().optional(),
@@ -25,7 +25,7 @@ export const SatelliteContentSchema = z.object({
2525
step3: z.string(),
2626
step4: z.string(),
2727
guideButton: z.string(),
28-
}),
28+
}).strict(),
2929
letter: z.object({
3030
greeting: z.string(),
3131
paragraph1: z.string(),
@@ -34,16 +34,16 @@ export const SatelliteContentSchema = z.object({
3434
paragraph4: z.string(),
3535
closing: z.string(),
3636
signature: z.string(),
37-
}),
37+
}).strict(),
3838
schedule: z.object({
3939
title: z.string(),
40-
}),
40+
}).strict(),
4141
sponsors: z.object({
4242
title: z.string(),
43-
}),
43+
}).strict(),
4444
signatures: z.object({
4545
title: z.string(),
46-
}),
46+
}).strict(),
4747
footer: z.object({
4848
tagline: z.string(),
4949
copyright: z.string(),
@@ -52,35 +52,35 @@ export const SatelliteContentSchema = z.object({
5252
links: z.array(z.object({
5353
text: z.string(),
5454
href: z.string(),
55-
})),
56-
}),
57-
}),
55+
}).strict()),
56+
}).strict(),
57+
}).strict(),
5858
event: z.object({
5959
city: z.string(),
6060
date: z.string(),
6161
venue: z.object({
6262
name: z.string(),
6363
link: z.string(),
64-
}),
64+
}).strict(),
6565
schedule: z.object({
6666
days: z.array(z.object({
6767
date: z.string(),
6868
items: z.array(z.object({
6969
time: z.string(),
7070
activity: z.string(),
71-
})),
72-
})),
73-
}),
71+
}).strict()),
72+
}).strict()),
73+
}).strict(),
7474
sponsors: z.object({
7575
cards: z.array(z.object({
7676
sponsor: z.string(),
7777
logo: z.string(),
7878
link: z.string(),
79-
})),
80-
}),
79+
}).strict()),
80+
}).strict(),
8181
signatures: z.union([
8282
z.literal(false),
83-
z.object({ img: z.string() }),
83+
z.object({ img: z.string() }).strict(),
8484
]).optional(),
8585
faq: z.object({
8686
title: z.string(),
@@ -89,26 +89,26 @@ export const SatelliteContentSchema = z.object({
8989
questions: z.array(z.object({
9090
question: z.string(),
9191
answer: z.string(),
92-
})),
92+
}).strict()),
9393
buttonText: z.string(),
9494
buttonLink: z.string().optional()
95-
}),
95+
}).strict(),
9696
organizer: z.object({
9797
title: z.string(),
9898
questions: z.array(z.object({
9999
question: z.string(),
100100
answer: z.string(),
101-
})),
101+
}).strict()),
102102
buttonText: z.string(),
103103
buttonLink: z.string().optional()
104-
}).optional(),
105-
}),
104+
}).strict().optional(),
105+
}).strict(),
106106
contactUs: z.object({
107107
email: z.string().optional(),
108108
instagram: z.string().optional(),
109109
linkedin: z.string().optional(),
110-
}).optional(),
111-
}),
112-
});
110+
}).strict().optional(),
111+
}).strict(),
112+
}).strict();
113113

114114
export type SatelliteContent = z.infer<typeof SatelliteContentSchema>;

0 commit comments

Comments
 (0)