Skip to content

Commit bcda3fd

Browse files
stefanovernaclaude
andcommitted
Add poster_time to file/gallery field value types
The CMA returns (and accepts) a `poster_time` metadata key on file and gallery field values for video assets — the float second into the video used to generate the thumbnail. The hand-written field value types didn't include it, so it was missing from `FileFieldValue`, `FileFieldValueInRequest`, and (via re-export) the gallery equivalents. - Add `poster_time` to `FileFieldValue` (`number | null`) and `FileFieldValueInRequest` (`number | null`, optional). - Require `poster_time` in the `isFileFieldValue` response type guard, matching the existing `focal_point` check. - Surface `poster_time` in `inspectItem` for file and gallery items. Gallery types derive from the file types, so they pick this up for free. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 791bf3e commit bcda3fd

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

packages/cma-client/__tests__/inspectItem.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,13 +398,15 @@ describe('inspectItem', () => {
398398
title: 'English file title',
399399
custom_data: {},
400400
focal_point: null,
401+
poster_time: null,
401402
},
402403
it: {
403404
upload_id: 'italian-file-id',
404405
alt: 'Testo alternativo italiano',
405406
title: 'Titolo file italiano',
406407
custom_data: { locale: 'it' },
407408
focal_point: { x: 0.6, y: 0.4 },
409+
poster_time: null,
408410
},
409411
},
410412

packages/cma-client/src/fieldTypes/file.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ import type { RequiredAltTitleValidator } from './validators/required_alt_title.
1717
* which contain file uploads with optional metadata like alt text, title, custom data, and focal points.
1818
*
1919
* The challenge we're solving:
20-
* - DatoCMS File fields can have optional metadata fields (alt, title, custom_data, focal_point)
20+
* - DatoCMS File fields can have optional metadata fields (alt, title, custom_data, focal_point, poster_time)
2121
* - For API requests, all these fields are optional and can be omitted
2222
* - For API responses, DatoCMS provides default values for missing fields:
2323
* - alt: null
2424
* - title: null
2525
* - custom_data: {}
2626
* - focal_point: null
27+
* - poster_time: null
2728
* - This creates a need for different type variants for the same conceptual data structure
2829
*
2930
* This module provides separate types for:
@@ -52,6 +53,7 @@ export type FileFieldValue = {
5253
x: number;
5354
y: number;
5455
} | null;
56+
poster_time: number | null;
5557
} | null;
5658

5759
/**
@@ -75,6 +77,7 @@ export type FileFieldValueInRequest = {
7577
x: number;
7678
y: number;
7779
} | null;
80+
poster_time?: number | null;
7881
} | null;
7982

8083
/**
@@ -95,7 +98,8 @@ export function isFileFieldValue(value: unknown): value is FileFieldValue {
9598
'alt' in value &&
9699
'title' in value &&
97100
'custom_data' in value &&
98-
'focal_point' in value
101+
'focal_point' in value &&
102+
'poster_time' in value
99103
);
100104
}
101105

packages/cma-client/src/utilities/inspectItem.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,10 @@ function fileInspectionTreeNodes(
387387
nodes.push({ label: `focal_point: x=${x}% y=${y}%` });
388388
}
389389

390+
if (typeof value.poster_time === 'number') {
391+
nodes.push({ label: `poster_time: ${value.poster_time}s` });
392+
}
393+
390394
return nodes;
391395
}
392396

@@ -432,6 +436,10 @@ function galleryInspectionTreeNodes(
432436
nodes.push({ label: `focal_point: x=${x}% y=${y}%` });
433437
}
434438

439+
if (typeof item.poster_time === 'number') {
440+
nodes.push({ label: `poster_time: ${item.poster_time}s` });
441+
}
442+
435443
return {
436444
label: `[${index}]`,
437445
nodes: nodes,

0 commit comments

Comments
 (0)