Skip to content

Add support for scheduled feature flags with activeFrom and activeUntil#8

Merged
nicokempe merged 10 commits into
mainfrom
feat/scheduled-flags
May 23, 2025
Merged

Add support for scheduled feature flags with activeFrom and activeUntil#8
nicokempe merged 10 commits into
mainfrom
feat/scheduled-flags

Conversation

@nicokempe
Copy link
Copy Markdown
Owner

✅ PR Checklist

Please ensure the following before submitting your PR:

  • My commit message follows Conventional Commits
  • I’ve tested the changes and confirmed they work as expected
  • I’ve updated any relevant documentation
  • I’ve added tests (if applicable)

🔗 Linked Issue

No issue created

📖 Description

This PR introduces support for time-based scheduled feature flags using activeFrom and activeUntil:

  • Feature flags can now be objects, not just strings
  • Flags are only active if the current date is within the specified timeframe
  • This works across:
    • the useFeatureFlag() composable
    • the v-feature directive
    • the isFeatureEnabled() server utility
  • Updated types to support FeatureFlagInput (string | { name, activeFrom, activeUntil })
  • Improved logic in directive and composable to handle mixed flag inputs
  • Added full example support in the Playground

🚨 Breaking Changes

  • Yes
  • No

🧪 Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 🧹 Code style / formatting
  • 🔨 Refactoring (no functional changes)
  • 🧰 Tooling / CI
  • 📝 Docs update
  • 🧪 Tests
  • 💡 Other (please describe):

🧩 Additional Context

Nothing

nicokempe added 9 commits May 23, 2025 21:13
…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
@nicokempe nicokempe requested a review from Copilot May 23, 2025 19:26
@nicokempe nicokempe self-assigned this May 23, 2025
@nicokempe nicokempe added 📚 documentation improvements or additions to documentation ✨ enhancement new feature or enhancement labels May 23, 2025
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread src/runtime/server/isFeatureEnabled.ts Outdated
import type { H3Event } from 'h3'
import type { FeatureFlag } from '../../../types/feature-flags'

const isFlagActiveNow = (flag: FeatureFlag): boolean => {
Copy link

Copilot AI May 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function 'isFlagActiveNow' is repeated in multiple files. Consider consolidating it into a shared utility module to reduce duplication and improve maintainability.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in bbb2df3

@nicokempe nicokempe requested a review from Copilot May 23, 2025 19:32
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 =>

@nicokempe nicokempe merged commit fc1049b into main May 23, 2025
7 checks passed
@nicokempe nicokempe deleted the feat/scheduled-flags branch May 23, 2025 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📚 documentation improvements or additions to documentation ✨ enhancement new feature or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants