Add support for scheduled feature flags with activeFrom and activeUntil#8
Conversation
…nput with scheduled flags * Removes duplicated FeatureFlagsOptions * Aligns module input type with runtime config * Prepares module to support richer flag definitions
…om and activeUntil * Introduces FeatureFlagInput union * Defines scheduling structure for richer flag types * Unifies config typings across runtime and module
…ag listing * Adds isFlagActiveNow() logic * Adjusts isEnabled() to support both string and object-based flags * Updates listFlags() to return only currently active flags
* Applies isFlagActiveNow() to backend handler * Allows conditional logic in server/api based on scheduled flags
* Updates directive to check for object-based scheduled flags * Uses shared logic to determine visibility
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for time-based scheduled feature flags by allowing feature flags to be defined as objects with additional properties activeFrom and activeUntil. The changes update the server utility, Vue directive, and composable to properly evaluate a flag's active state based on the current date, and update module types and runtime configuration accordingly.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/runtime/server/isFeatureEnabled.ts | Updated to support object feature flags with active time evaluation |
| src/runtime/directives/v-feature.ts | Enhanced flag check in directive to account for scheduled flag objects |
| src/runtime/composables/useFeatureFlag.ts | Modified the flag listing and checking logic to handle mixed inputs |
| src/module.ts | Updated module configuration types and runtime config assignment |
| import type { H3Event } from 'h3' | ||
| import type { FeatureFlag } from '../../../types/feature-flags' | ||
|
|
||
| const isFlagActiveNow = (flag: FeatureFlag): boolean => { |
There was a problem hiding this comment.
The function 'isFlagActiveNow' is repeated in multiple files. Consider consolidating it into a shared utility module to reduce duplication and improve maintainability.
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for scheduled feature flags using activeFrom and activeUntil properties, ensuring that time-based constraints are taken into account when determining flag activation. Key changes include:
- Implementation of time-based flag evaluation in isFlagActiveNow.
- Updates in the composable (useFeatureFlag) and directive (v-feature) to support both string and object flag inputs.
- Adjustments throughout the module configuration and playground examples to demonstrate scheduled feature flags.
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/runtime/utils/isFlagActiveNow.ts | Added utility to check if a flag is active based on time. |
| src/runtime/server/isFeatureEnabled.ts | Updated server utility to support scheduled flags. |
| src/runtime/directives/v-feature.ts | Modified directive to properly evaluate scheduled flags. |
| src/runtime/composables/useFeatureFlag.ts | Revised composable to handle mixed flag inputs and time checks. |
| src/module.ts | Updated module configuration to reflect new flag types. |
| playground/pages/scheduled.vue | Added example page demonstrating scheduled feature flags. |
| playground/pages/index.vue | Updated playground to conditionally render a scheduled banner. |
| playground/nuxt.config.ts | Extended config with example scheduled flag objects. |
| README.md | Updated documentation to mention scheduling support. |
Comments suppressed due to low confidence (1)
src/runtime/composables/useFeatureFlag.ts:20
- [nitpick] Ensure the ordering of feature flags returned by listFlags (with active object flags first and string flags concatenated later) is intentional and clearly documented, as it may affect consumers relying on a specific order.
return flags.filter((flag): flag is FeatureFlag =>
✅ PR Checklist
Please ensure the following before submitting your PR:
🔗 Linked Issue
No issue created
📖 Description
This PR introduces support for time-based scheduled feature flags using
activeFromandactiveUntil:useFeatureFlag()composablev-featuredirectiveisFeatureEnabled()server utilityFeatureFlagInput(string | { name, activeFrom, activeUntil })🚨 Breaking Changes
🧪 Type of Change
🧩 Additional Context
Nothing