npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cds-feature-toggle

v0.0.6

Published

support feature toggle pattern for SAP CAP

Downloads

15

Readme

cds feature toggle

support feature toggle pattern for SAP CAP cds

node-test npm codecov license

Quick Overview

// all event/entity/action/function require 'class-service' feature
@cds.features.required : ['class-service'] 
service ClassService {

  // annotate the entity built-in events
  @cds.features : [
    {
      on       : 'DELETE',
      required : 'feat-student-delete' // generally, maybe we dis-allowed user to delete entry
    }
    // other event will skip feature check
  ]
  entity Students               as projection on training.Student;

  // or simply require feature for all events/action/function under the entity
  @cds.features.required: 'feat-teacher-management'
  entity Teachers  as projection on training.Teacher;

  // enabled by default
  // if 'metricV2' or 'metricV3' is enabled, 
  // will prefer to trigger the redirect action
  @cds.features.redirect.target : [metricV2]
  action metric() returns MetricResponse;

  // enabled when request context has the feature 'feature-metrics-v2'
  @cds.features.required         : 'feature-metrics-v2'
  action metricV2() returns MetricResponse;


}

Setup

you need to enable the cds-feature-toggle by cds-hyper-app-service extension config

npm i -S cds-hyper-app-service cds-feature-toggle
{
  "cds": {
    "requires": {
      "app-service": {
        "impl": "cds-hyper-app-service",
        "exts": [
          "builtIn",
          {
            "impl": "cds-feature-toggle",
            "providers": [
              {
                "impl": "CDSRequestProvider",
                "header": "x-cds-features"
              }
            ]
          }
        ]
      }
    }
  }
}

Providers

cds-feature-toggle provided a very simple provider which named CDSRequestProvider, it will extract http header x-cds-features as feature labels.

export class CDSRequestProvider implements FeatureProvider {
  #headerName = HEADER_X_CDS_FEATURES_NAME;
  /**
   * extract http header as (enabled) feature list for current request
   * 
   * @param options.featureHeaderName default is `x-cds-features`
   */
  constructor(options: { featureHeaderName?: string }) {
    if (typeof options?.featureHeaderName === "string") {
      this.#headerName = options?.featureHeaderName;
    }
  }
  public getFeatures(context: DetermineContext) {
    // TODO: add signature verify
    return Promise.resolve(context?.request?.get?.(this.#headerName)?.split(",") ?? []);
  }
}

you can easily implement a feature provider by yourself, read feature from redis or database, it depends on you.

TODO

  • [x] support redirect for bounded action/function
  • [x] support @cds.features.required on full entity
  • [x] built-in provider interface
    • [x] cds request header provider
    • [x] dummy provider for test
  • [ ] support cds-nats KV

Limitation

  • the default no handler behavior for action/function will be little difference

CHANGELOG

LICENSE