Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fts feature modeling with custom scopes requires a user callback with corresponding cdsrc configuration #51

Closed
rlindner81 opened this issue Mar 7, 2024 · 1 comment · Fixed by #55

Comments

@rlindner81
Copy link
Contributor

rlindner81 commented Mar 7, 2024

If someone wants to use the /fts/* feature toggles with a non-implicit modeling, e.g., with some custom scopes. For example: a companyId that is derived from the req going into the middleware.

Then

  • the user would need to configure their callback in the cds configuration for the plugin
    {
    "cds": {
      "featureToggles": {
        "configFile": "./srv/feature/toggles.yaml",
        "ftsScopeCallback": "./srv/feature/ftsScope.js"
      }
    }
  • and need to implement the callback
// context is the cds context
// req is the middleware request, which is also on the cds context, so maybe take it from there for consistency?
// key you get the fts key, in case you want to model and use different scopes for different fts toggles
module.exports = (context, key) => {
  const companyId = ...; // your code here
  return {
    user: context?.user?.id,
    tenant: context?.tenant,
    companyId,
  }
};
@rlindner81
Copy link
Contributor Author

Use context.http.req to access the initial http request from CAP's context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant