PackagePackagetypeA library you install and call yourself.See every one →What this type is →by a community orgby a community orgoriginPublished by a community organisation, so it outlives any one maintainer.See every one →

@cap-js-community/feature-toggle-library

Live-updatable feature toggles for CAP applications, backed by Redis.

Facts

Latestv1.3.6ReleasedLast pushLicenceApache-2.0

Where it sits

Lives in
Provides
Feature togglesCAPFeature togglescapabilityTurning behaviour on and off per tenant or per user at runtime, without redeploying, and knowing which toggles are live. System-level switches for delivered objects and runtime flags for unfinished features share the name.
Flavors
Node.jsfrom its runtime
Requires
RedisRedisoutside the atlasNamed as a dependency in its documentation.

Who is behind it

cap-js-communitycap-js-communityOrganisationMaintains this
In the atlas: maintains 10
@cap-js-community
maintainercorporateuserPersonContributes to this
In the atlas: contributes to 3
@corporateuser
Johannes VogelPersonContributes to this
In the atlas: contributes to 25
@johannes-vogel
Richard LindnerPersonContributes to this
In the atlas: contributes to 3
@rlindner81
3 contributors

What it declares

Every artifact

Type
Package
Origin
By a community org
Runtime
Node.js

As a package

Where it runs
Inside its host
Distributed through
npm

Connections3

@cap-js-community/feature-toggle-library connections@cap-js-community/feature-toggle-libraryPROVIDES→ provides1provides authoredFeature togglesNEEDS→ available via1available via derived Through: RedisRedis on SAP BTP, hyperscaler option→ needs1needs authoredRedis

Install

npm add @cap-js-community/feature-toggle-library

Derived from the package name. No recipe recorded; the README has the configuration.

Where it sits in your app

Download
Your CAP applicationdocumentedrequiresRedis, systemRedissystem@cap-js-community/feature-toggle-library, module@cap-js-community/fe…
SAPnot SAP's, or the project's owndocumented only

README

quoted from cap-js-community/feature-toggle-library under Apache-2.0, read
cap-js-community/feature-toggle-library/README.mdOn GitHub

SAP BTP Feature Toggle Library

npm version monthly downloads REUSE status Main CI

SAP BTP feature toggle library enables Node.js applications using the SAP Cloud Application Programming Model to maintain live-updatable feature toggles via Redis.

Getting Started (CAP Feature Toggles)

  • Set up project with @sap/cds.

  • Install library:

    npm install --save @cap-js-community/feature-toggle-library
  • For CAP Feature Toggles everything is configured automatically.

  • The library acts as a CDS-Plugin and registers a FeatureService, which can be used to check and update toggles.

  • For details see Example CAP Server.

Getting Started (Custom Configuration)

  • Same as previous section.

  • Write toggles.yaml configuration file:

    # info: check api priority; 0 means access is disabled
    /check/priority:
      type: number
      fallbackValue: 0
      validations:
        - scopes: [user, tenant]
        - regex: '^\d+$'
  • Add configuration path to package.json:

    {
      "cds": {
        "featureToggles": {
          "configFile": "./toggles.yaml"
        }
      }
    }
  • Write usage code in handlers:

    const toggles = require("@cap-js-community/feature-toggle-library");
    
    const priorityHandler = async (context) => {
      const user = context.user.id;
      const tenant = context.tenant;
      const value = toggles.getFeatureValue("/check/priority", { user, tenant });
      if (value <= 0) {
        return context.reject("blocked");
      } else if (value < 10) {
        return context.reply("welcome");
      } else {
        return context.reply("very welcome");
      }
    };

Features

  • Maintain feature toggle states consistently across multiple app instances.
  • Feature toggle changes are published from Redis to subscribed app instances with publish/subscribe pattern PUB/SUB.
  • Horizontal app scaling is supported and new app instances will start with the correct state, or fallback values, if they cannot connect to Redis.
  • Feature toggle values can be changed specifically for accessors with certain scopes, e.g., for specific tenants, users,...
  • Users can register change handler callbacks for specific toggles.
  • Users can register custom input validation callbacks for specific toggles.
  • Works as a CDS-Plugin and provides a REST service to read and manipulate toggles.

Peers

Documentation

Head over to our Documentation to learn more.

Support, Feedback, Contributing

This project is open to feature requests/suggestions, bug reports etc. via GitHub issues. Contribution and feedback are encouraged and always welcome. For more information about how to contribute, the project structure, as well as additional contribution information, see our Contribution Guidelines.

Code of Conduct

We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone. By participating in this project, you agree to abide by its Code of Conduct at all times.

Licensing

Copyright 2023 SAP SE or an SAP affiliate company and feature-toggle-library contributors. Please see our LICENSE for copyright and license information. Detailed information including third-party components and their licensing/copyright information is available via the REUSE tool.

Apache-2.0, read

History

Latest

v1.3.7

  1. v1.3.6

    Features 1, Changed 1

    Notes
    Changed
    • redis: migrate to @redis/client v6. Cluster read-modify-write now uses the built-in getNodeClientForKey() to obtain the node client owning a key's slot, replacing the manual slot calculation via cluster-key-slot (adopts fix for redis/node-redis#3194).
    Added
    • redis: add LOCAL_REDIS_CLUSTER integration mode, so cluster configuration is now detected locally as well.
  2. v1.3.5

    Changed 1

    Notes
    Changed
    • redis: expand tls handling to work with more cloud providers: SAP Cloud Infrastructure (SCI), Azure, GCP (contributed by @corporateuser)
  3. v1.3.4dated in the atlas

    Removed 1, Changed 1

    Notes
    Removed
    • cds-plugin: removed legacy plugin activation support for @sap/cds before v7.3.0.
    Changed
    • core: switch from semaphore to execution-control re-use module.
  4. v1.3.3

    Changed 1, Fixes 1

    Notes
    Changed
    • redis: migrate to @redis/client v5 with updated WATCH/MULTI/EXEC logic (fixes #114).
    Fixed
    • core: ignore mta blue-green deployment temporary appname suffixes -live and -idle (fixes #106).
  5. v1.3.2dated in the atlas

    Removed 1, Features 1, Changed 1

    Notes
    Changed
    • cds-plugin: rely on file neighborhood for service implementation resolution. This helps for scenarios where the server's model is shared with mtx/sidecar and a local implementation is not present.
    Removed
    • restrict to at least node v20.
    Added
    • enable voters for node v24.
  6. v1.3.1

    Features 1, Changed 1

    Notes
    Changed
    • core: compatability changes for cds v9.
    Added
    • more testing for usage with cds.
  7. v1.3.0

    Changed 4

    Notes

    ⚠️ This release is potentially disruptive. Initialize will throw for previously ignored problems with configuration correctness. The coalesce logic for using multiple configuration sources has changed. For details see Layered Configuration.

    Changed
    • core: initialization throws if mandatory configuration fallbackValue is undefined (missing) or null (always invalid).

    • core: initialization throws if mandatory configuration type is not in ["boolean", "number", "string"] (invalid).

    • core: initialization throws if its invoked more than once. previously subsequent calls and their options were ignored.

    • core: configuration reading and coalescing has changed:

      • up to v1.2.5, the order was runtime, files, auto, where the first occurrence is used for each toggle
      • from v1.3.0, the order is auto, files, runtime, where the last occurrence is used for each toggle
      • this enables overriding the configuration based on environmental factors, by mixing in dedicated config files
  8. v1.2.5

    Fixes 2

    Notes
    Fixed
    • core: if a ./default-env.json file was present and NODE_ENV !== "production", we had assumed that cf env variables VCAP_APPLCATION and VCAP_SERVICES are always present in the file. now this is more resilient.

    • core: [regression] initialize timing was noticeably slower, because the initial connection check was running with the default reconnect strategy that takes 2000ms. now the reconnect strategy is disabled for the initial connection check.

  9. v1.2.4

    Features 2, Changed 2

    Notes
    Changed
    • cds-plugin: change default service access role to internal-user (fixes #90).
    • redis: changed dependency from redis to @redis/client.
    Added
    • core: [undocumented] plugin-config/initialize support multiple configuration files.

    • redis: [undocumented] cds-config/initialize take redis credentials and client options for fine-tuning or as an alternative to VCAP_SERVICES (brought up by #92).

      the cds-config approach is consistent with the redis integration of other cap-js-community projects, see event-queue, websocket.

  10. v1.2.3

    Features 2, Fixes 2

    Notes
    Added
    • cds-plugin: added explicit implementation for FeatureService.
    • enable node v22 voters.
    Fixed
    • cds-plugin: allow feature toggles to initialize with no configured toggles.
    • use proper cds syntax to get service operations (by johannes-vogel).
  11. v1.2.2

    Changed 1, Fixes 1

    Notes
    Changed
    • the initialization log of the library will now show the unique name used. this name is used to derive both the redis storage key and pub/sub channel.
    Fixed
    • internal naming cleanup and consistency work.
  12. v1.2.1

    Features 1, Changed 1, Fixes 1

    Notes
    Changed
    • cds-plugin: service endpoint /rest/feature/redisRead will return server in-memory changes in NO_REDIS mode in order to be consistent with /rest/feature/redisUpdate.
    Added
    • cds-plugin: added cds.test() basic request/response tests for service.
    Fixed
    • cds-plugin: service endpoint /rest/feature/redisRead works without http errors in NO_REDIS mode.
  13. v1.2.0

    Features 2, Changed 2, Fixes 1

    Notes

    ⚠️ This release contains two minor breaking changes.

    Changed
    • The main class of the library is no longer explicitly exported. You can access it implicitly as constructor of the exported class instance.

      // before
      const { FeatureToggles } = require("@cap-js-community/feature-toggle-library");
      const myToggles = new FeatureToggles({ uniqueName: "snowflake" });
      
      // after
      const toggles = require("@cap-js-community/feature-toggle-library");
      const FeatureToggles = toggles.constructor;
      const myToggles = new FeatureToggles({ uniqueName: "snowflake" });
    • cds-plugin: rewrote /rest/feature/redisRead endpoint to show all Redis maintained toggle values, including those of toggles that are not configured. The endpoint no longer refreshes the server-local toggle state. Consequently, it will work with read access privileges, since it can no longer modify the server-local state (fixes #69).

    Added
    • added remoteOnly option for /rest/feature/redisUpdate endpoint and the changeFeatureValue() API. With this option, you can clean up Redis maintained values that are no longer configured (fixes #69).
    • cds-plugin: better detection of serve mode following changes in @sap/cds v8.2.3
    Fixed
    • multiple, even concurrent, calls of initializeFeatures() will only ever trigger one execution of the underlying initialization.
  14. v1.1.7

    Fixes 1

    Notes
    Fixed
    • setting a root value with the option { clearSubScopes: true } only deleted the root and scoped values, but did not set the new root value.
  15. v1.1.6

    Fixes 2

    Notes
    Fixed
    • cds-plugin: fix uniqueName configuration processing
    • more consistent scope preference order when 2 out of 4 scopes are set
  16. v1.1.5

    Changed 2, Fixes 2

    Notes
    Changed
    • fallback value null is no longer allowed (fixes #62).
    • change handlers no longer receive null as new values, they get the actual new value for the relevant scope instead (fixes #64).
    Fixed
    • cds-plugin: unify and fix syntax of context.error and context.reject for cds service.
    • change processing is more resilient. for redis message with multiple changes, if one change fails, then subsequent changes will still be processed.
  17. v1.1.4

    Features 2, Fixes 1

    Notes
    Added
    • docs: basic documentation for newest cds-plugin features.
    • cds-plugin: better access control (fixes #57).
    Fixed
    • redis: better integration mode, will not log a connection error if redis is not present.
  18. v1.1.2

    Features 3, Fixes 2

    Notes
    Added
    • cds-plugin: fts feature toggles are detected and configured automatically (fixes #50).
    • cds-plugin: allow custom scope map callback for fts feature toggles (fixes #51).
    • cds-plugin: can configure unique name, i.e. which apps store the same toggles in redis, as part of cds configuration.
    Fixed
    • cds-plugin: feature toggles will not initialize during cds build.
    • redis: proper usage of redis-client built-in reconnect capabilities.
  19. v1.1.1

    Changed 2

    Notes
    Changed
    • cds-service: always log update contents for traceability and improved logging for redis read and update errors.
    • docs: add getting started section (fixes #43).
  20. v1.1.0

    Changed 2

    Notes

    ⚠️ User action required! This release will be more disruptive than usual. We re-thought that main require API and made it much leaner. These changes should have happened in 1.0, sorry for the inconvenience.

    // before
    const {
      singleton: { getFeatureValue },
    } = require("@cap-js-community/feature-toggle-library");
    
    function someFunc() {
      getFeatureValue(key);
    }
    
    // after
    const toggles = require("@cap-js-community/feature-toggle-library");
    
    function someFunc() {
      toggles.getFeatureValue(key);
    }

    For details see https://cap-js-community.github.io/feature-toggle-library/usage/

    Changed
    • the library now exports only the singleton instance (fixes #39).
    • cds-plugin: the request header features are only respected in development environments (fixes #41).
  21. v1.0.0

    Removed 1, Features 2

    Notes

    We are releasing 1.0, after 2 years of continuous usage, testing, and small improvements.

    Removed
    • restrict to node v18+
    Added
    • act as Feature Vector Provider when used as a CDS-Plugin.
    • allow graceful shutdown by closing redis clients on cds shutdown event (fixes #34).
  22. v0.7.2

    Features 2, Changed 1

    Notes
    Added
    • support for redis cluster configurations.
    • enable setting maximal log level through env variable BTP_FEATURES_LOG_LEVEL. this can be used to silence the library during tests.
    Changed
    • implement new CDS-Plugin API, where plugins export a promise instead of an activate property and stay compatible for older cds versions.
  23. v0.7.1

    Fixes 1

    Notes
    Fixed
    • CDS-Plugin integration now works for projects that run cds build --production and only use the resulting csn.json at runtime.
  24. v0.7.0

    Features 3, Changed 2, Fixes 1

    Notes
    Added
    • new harmonized validation configuration for scope and regex checks, as well as external validation with user provided modules.

    • new (optional) CDS-Plugin integration. for details, see the new plugin and service documentation.

    • new logger implementation which replaces cf-nodejs-logging-support dependency. it has better cds integration (if present). for example, it will log correlation ids that are present in cds context via async local storage.

    Changed
    • allowedScopes: [xxx] configuration will now be ignored and needs to be replaced with validations: [{ scopes: [xxx] }].

    • validation: yyy configuration will now be ignored and needs to be replaced with validations: [{ regex: yyy }].

    Fixed
    • re-work pipelines to separate main branch and pr-voter status
  25. v0.6.9

    Features 1, Fixes 2

    Notes
    Added
    Fixed
    • better documentation regarding scoping and redis hash map persistence

    • more resilient handling of bad input for scopeMaps in all external APIs

  26. v0.6.8

    Features 1

    Notes
    Added
    • first public release on npmjs
  27. v0.6.7

    Features 1, Fixes 1

    Notes
    Added
    • added allowedScopes configuration, which validates that correct scope names are used for updates
    Fixed
    • separate rootValue from other scopedValues in getFeatureInfo and getFeaturesInfos APIs
  28. v0.6.6

    Features 1, Fixes 1

    Notes
    Added
    • added example-cap-server code, that acts both as an example integration code into existing cap projects and as a starting point for manual testing
    Fixed
    • first iteration towards updating documentation
  29. v0.6.5

    Fixes 1

    Notes
    Fixed
    • fix bug where scoped values were ignored if they are falsy
  30. v0.6.4

    Features 1

    Notes
    Added
    • simple migration for old sting-type state to hash-type persistence state
  31. v0.6.2

    Fixes 1

    Notes
    Fixed
    • fix redis transaction re-writes
  32. v0.6.1dated in the atlas

    Removed 1, Features 3, Fixes 2

    Notes
    Removed
    • remove API to read feature config and metadata getFeatureConfig and getFeatureConfigs. use getFeatureInfo and getFeaturesInfos instead
    Added
    • new option to add scope restrictions when reading or setting feature toggles

    • separate persistence on redis using HGET, HSET, so that individual toggle changes don't have to touch the state of all feature toggles. effectively we change the redis type for the persistence key from string to hash.

    • new API getFeatureInfo and getFeaturesInfos to get all config and state information in one call

    Fixed
    • rewrite to improve config handling internally

    • fix some problems with the logger in combination with verror

  33. v0.5.18

    Removed 1, Features 1, Fixes 3

    Notes
    Removed
    • restrict to node v16+
    Added
    • new interface to get main and subscriber client in redis wrapper
    Fixed
    • better coding and interface for LazyCache and ExpiringLazyCache

    • more and improved jsdocs

    • allow options to be passed in redis wrapper set implementation. see SET for details.

  34. v0.5.17

    Fixes 1

    Notes
    Fixed
    • make logging for warn level work properly
  35. v0.5.16

    Fixes 1

    Notes
    Fixed
    • re-work logging approach so structured logging will capture VError info
  36. v0.5.15

    Fixes 2

    Notes
    Fixed
    • update feature value is now exclusive under high concurrency (semaphore implementation by oklemenz2)

    • prettier and documentation work better together

  37. v0.5.14

    Features 1

    Notes
    Added
    • users can rely on always getting fallback value
  38. v0.5.13

    Features 2

    Notes
    Added
    • local integration tests

    • write own env implementation replacing @sap/xsenv dependency

  39. v0.5.12

    Fixes 1

    Notes
    Fixed
    • more fixes related to error event handling in local case after redis library v4 migration
  40. v0.5.11

    Removed 1, Fixes 1

    Notes
    Removed
    • restrict to node v12+
    Fixed
    • fix mainClient and subscriberClient reference handling in error case
  41. v0.5.10

    Fixes 1

    Notes
    Fixed
    • migrate redis dependency to v4
  42. v0.5.8

    Features 1

    Notes
    Added
    • allow to set singleton uniqueName via env variable BTP_FEATURES_UNIQUE_NAME
  43. v0.5.7

    Fixes 1

    Notes
    Fixed
    • fix readConfigFromFile for yaml case
  44. v0.5.6dated in the atlas

    Removed 1, Features 2, Fixes 2

    Notes
    Removed
    • config property enabled is discontinued, use active instead
    Added
    • new config property: active. if active is set to false, no changes of the feature toggle is allowed, but old value stays in place

    • new API to read feature config and metadata getFeatureConfig and getFeatureConfigs

    Fixed
    • change interface name readConfigFromFilepath to readConfigFromFile

    • change signature for FeatureValueChangeHandler to handler(newValue, oldValue)

  45. v0.5.5

    Fixes 1

    Notes
    Fixed
    • change external validators interface to allow reporting multiple errors
  46. v0.5.4

    Fixes 1

    Notes
    Fixed
    • change validator return interface to ValidationErrors for consistency
  47. v0.5.3

    Fixes 2

    Notes
    Fixed
    • make singleton more IDE friendly and ensure correctness with test

    • switch to artifactory registry

  48. v0.5.2

    Features 1, Fixes 3

    Notes
    Added
    • feature: external validation
    Fixed
    • readme update

    • handler name fallback for anonymous functions

    • inputValidation is now async to account for potentially async external validators

  49. v0.5.0

    Features 1

    Notes
    Added
    • Initial public release
126downloads per week, npm
Weekly downloads for @cap-js-community/feature-toggle-library26 complete calendar weeks from 2026-04-20 to 2026-10-18; the latest total is 126.20 Apr – 26 Apr: 8927 Apr – 3 May: 2024 May – 10 May: 23811 May – 17 May: 15818 May – 24 May: 10325 May – 31 May: 881 Jun – 7 Jun: 828 Jun – 14 Jun: 23415 Jun – 21 Jun: 13522 Jun – 28 Jun: 21629 Jun – 5 Jul: 1836 Jul – 12 Jul: 5813 Jul – 19 Jul: 23220 Jul – 26 Jul: 11827 Jul – 2 Aug: 773 Aug – 9 Aug: 7710 Aug – 16 Aug: 5917 Aug – 23 Aug: 3024 Aug – 30 Aug: 5031 Aug – 6 Sept: 797 Sept – 13 Sept: 6314 Sept – 20 Sept: 9221 Sept – 27 Sept: 4428 Sept – 4 Oct: 455 Oct – 11 Oct: 5512 Oct – 18 Oct: 126
Feature toggles
  1. SAP Feature Flags serviceBoolean and string flags read by applications at runtime
  2. com.sap.cds:cds-services-bomMaven bill of materials pinning CAP Java module versions
  3. @sap/cds-mtxsMultitenancy, tenant provisioning and extensibility for CAP
  4. cds-feature-toggleFeature-toggle pattern for CAP CDS

Details

Sources5
npm registrydiscovered herechecked
GitHub APIdiscovered here, cap-js-communitychecked
npm registry, @cap-js-community/feature-toggle-libraryversion, releases, installschecked
README.mdquoted, and what the entry declareschecked

Sources are graph entities: the same page may back several entries, and an unreachable source flags every row that rests on it.

Compatibility and provenance
runtimesnode
latestv1.3.6
first release
releases and cadence26, ~51d median
discovered vianpm registry, GitHub API · cap-js-community
first seen in the atlas
ecosystem and domaincap, operations-and-runtime
Contributors3

From the repository’s contributor list, .

History in the atlas1
  1. First seen.
For your agent
Ref
artifact:cap-js-community-feature-toggle-library
JSON
/artifacts/cap-js-community-feature-toggle-library.json
MCP
Connecting an agent