fix(supabase): refuse a last_modified_at a Date cannot read

The timestamp shape check lets an offset such as +99:99 through, which
Date.parse reads as NaN and the date formatter would throw on. The key
now also requires a readable date, so the case folds into unavailable.
Test added beside the existing refusal test; no assertion changed.
This commit is contained in:
bchanot committed 2026-11-16 17:54:54 +01:00
1 parent 72ec758278
commit 374e300895
2 files changed
+11 -1

No files matched your search

+5 -1
View File
@@ -387,7 +387,11 @@ const OfficialSheetAdminSummarySchema = z.object({
created_at: z.string(),
updated_at: z.string(),
/** The newest of the sheet's and its versions' `updated_at` (M9): what « dernière modification » sorts and shows. */
last_modified_at: z.string().datetime({ offset: true }),
last_modified_at: z
.string()
.datetime({ offset: true })
// The shape alone lets `+99:99` through, which a Date cannot read: fail closed here.
.refine((value) => !Number.isNaN(Date.parse(value))),
name: LocalizedSchema,
historical: z.boolean(),
working_copy: z.boolean(),
@@ -209,6 +209,12 @@ describe('sheet admin wrappers: answers', () => {
expect(await kindOf(listOfficialSheetsAdmin(answer([{ ...summary, last_modified_at: 'nope' }])))).toBe('unavailable')
})
it('refuses a last_modified_at the timestamp shape accepts but a Date cannot read', async () => {
const answer = (data: unknown) => stubClient({ rpc: { data } }).client
const unreadable = { ...summary, last_modified_at: '2026-11-09T11:06:00+99:99' }
expect(await kindOf(listOfficialSheetsAdmin(answer([unreadable])))).toBe('unavailable')
})
it('folds the server refusals into their kinds', async () => {
const refused = (message: string, code = '42501') =>
stubClient({ rpc: { error: { code, message }, status: 403 } }).client