feat: change the settings through a config.json file#9
feat: change the settings through a config.json file#9marcos-cereijo-pexip wants to merge 6 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR moves the plugin's hardcoded set_clock payload into an external public/config.json file, so deployments can customize clock behavior without rebuilding. It also adds a guard intended to avoid overriding an already-configured clock and documents the new config schema.
Changes:
- Fetch
config.jsonat runtime and use it as theset_clockpayload, with a newConfigTypeScript interface. - Call
get_clockfirst to check current state before issuingset_clock. - Document the configuration schema in the README and add example
public/config.json; minortsconfigandvite.configcleanup.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/index.ts | Loads config.json, queries get_clock, conditionally posts set_clock with fetched config. |
| src/types.ts | New Config interface describing the clock configuration shape. |
| public/config.json | Default config (type: time, UTC suffix) shipped with the plugin. |
| README.md | Documents the new configuration file, fields, and example. |
| tsconfig.json | Switches moduleResolution to bundler and adds an include list. |
| vite.config.ts | Removes a large commented-out block from the manifest definition. |
Comments suppressed due to low confidence (1)
src/types.ts:6
- The
datefield inConfigis typed as the literal date format string ('dd/mm/yyyy' | 'mm/dd/yyyy'), which is descriptive but the namedatesuggests an actual date value rather than a format specifier. Consider renaming todateFormat(ordate_formatif matching the backend) for clarity.
date?: 'dd/mm/yyyy' | 'mm/dd/yyyy'
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
43b90f1 to
8057555
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 7 changed files in this pull request and generated 6 comments.
Comments suppressed due to low confidence (1)
src/validateConfig.ts:71
buildConfigincludes optional fields whenever they're valid in isolation, regardless of whether they apply to the chosentype. For example, a config withtype: "elapsed"plus adatefield, ortype: "time"plus astarting_value, will pass validation and these irrelevant fields will be forwarded in the payload toset_clock. Consider only including type-specific fields when they apply (e.g.,starting_valueonly whentype === 'remaining',dateonly whentype === 'time'), and/or warning on unexpected fields, so the runtime payload matches the documented schema.
const buildConfig = (
obj: Record<string, unknown>,
type: Config['type']
): Config => ({
type,
...(isValidStartingValue(obj.starting_value) && {
starting_value: obj.starting_value
}),
...(typeof obj.prefix === 'string' && { prefix: obj.prefix }),
...(typeof obj.suffix === 'string' && { suffix: obj.suffix }),
...(isValidDateFormat(obj.date) && { date: obj.date })
})
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 7 changed files in this pull request and generated 5 comments.
Comments suppressed due to low confidence (1)
src/validateConfig.ts:63
- When
typeis"time"and the user omitsdate, validation succeeds andbuildConfigproduces a payload with nodatefield. The previous hard-coded behavior always sentdate: 'dd/mm/yyyy'. This is a silent behavior change that depends on whatever default the backend applies. Consider either makingdaterequired fortype: 'time'or applying an explicit default inbuildConfigso the behavior is predictable.
if (
type === 'time' &&
obj.date !== undefined &&
!isValidDateFormat(obj.date)
) {
logError(`"date" must be one of ${VALID_DATE_FORMATS.join(', ')}`)
return false
}
warnIgnoredFields(type, obj)
return true
Closes #8