* bug fix
* bug fix
* remove doc file
* store fixes
* bug fix
* rollback deleted file
* fix test
* add url to token
* return all tokens not just active
* add url fix
* PR comment
* PR comment
* PR comment
* add the flag to the experimental options
* fix env var name
## What
This PR adds an extra layer of OpenAPI validation testing to what we already have. It also fixes any issues that make the new tests fail.
## Why
While the current OpenAPI validation takes care of _some_ things, there's also things it misses, as shown by #2055. By adding the OpenAPI Enforcer package, we should hopefully be able to catch more of these errors in the future. The enforcer _does_ flag the issue in #2055 as an error.
## How
By adding the OpenAPI Enforcer package and making whatever changes it picks up on.
By adding location headers to all our 201 endpoints. I also had to change some signatures on `create` store methods so that they actually return something (a lot of them just returned `void`).
## Discussion points
### Code changes
Some of the code changes may not be necessary or we may want to change more code to align with what changes have been done. It may be worth standardizing on a pattern for `*store.create` methods, so that they always return an identifier or the stored object, for instance.
### On relative URIs
The 201 location headers use relative URIs to point to the created resources. This seemed to be the easiest way to me, as we don't need to worry about figuring out what the absolute URL of the instance is (though we could probably just concat it to the request URI?). The algorithm for determining relative URIs is described in [RFC 3986 section 5](https://www.rfc-editor.org/rfc/rfc3986#section-5).
There's also some places where I'm not sure we _can_ provide accurate location url. I think they're supposed to point _directly at_ whatever the resource is, but for some resources (such as api tokens), you can only get it as part of a collection. From [RFC 9110 on the location field](https://httpwg.org/specs/rfc9110.html#field.location) (emphasis mine):
> the Location header field in a [201 (Created)](https://httpwg.org/specs/rfc9110.html#status.201) response is supposed to provide a URI that is **specific** to the created resource.
A link to a collection is not specific. I'm not sure what best to do about this.
### Inline comments
I've added a number of inline PR comments that I'd love to get some feedback on too. Have a look and let me know what you think!
### Unfinished business
I've added some juicy comments to some of the files here. They contain non-blocking issues that I'm tracking (via github issues). We should resolve them in the future, but right now they can stay as they are.
## Commits
* Feat: add openapi-enforcer + tests; fix _some_ issues
* Test: allow non-standard string formats
* validation: fix _some_ 201 created location header endpoints
* #1391: fix remaining 201 location headers missing
* Refactor: use the ajv options object instead of add* methods
* #1391: flag validation errors and warnings as test failures
* #1391: modify patch schema to specify either object or array
We don't provide many patch endpoints, so we _could_ create separate
patch operation objects for each one. I think that makes sense to do
as part of the larger cleanup. For now, I think it's worth to simply
turn it into one of these. While it's not entirely accurate, it's
better than what we had before.
* Refactor: make tests easier to read
* #1391: use enum for valid token types
This was previously only a description. This may seem like a breaking
change because OpenAPI would previously accept any string. However,
Joi also performs validation on this, so invalid values wouldn't work
previously either.
* #1391: Comment out default parameter values for now
This isn't the _right_ way, but it's the pragmatic solution. It's not
a big deal and this works as a stopgap solution.
* #1391: add todo note for api token schema fixes
* #1391: update snapshot
* Revert "#1391: modify patch schema to specify either object or array"
This reverts commit 0dd5d0faa1.
Turns out we need to allow much more than just objects and arrays.
I'll leave this as is for now.
* Chore(#1391): update comment explaining api token schema TODO
* #1391: modify some test code and add comment
* #1391: update tests and spec to allow 'any' type in schema
* Chore: remove comment
* #1391: add tests for context field stores
* #1391: add location header for public signup links
* #1391: fix query parameter description.
There was indeed a bug in the package, and this has been addressed
now, so we can go back to describing the params properly.
* Refactor(#1391): don't check for OpenAPI version in snapshot tests
remove the version from the received specification. The version
_is_ a required field, but having the version listed in automated
testing causes issues when trying to deploy new versions of the
API (due to mismatch between new tag versions etc). That's why we
remove it.
* #1391: test that the "semver" property is present
* #1391: test that the openapi version is valid semver
* Chore(#1391): comment formatting
* First version ready
* Final
* Refactor
* Update pat store
* Website revert
* Website revert
* Update
* Revert website
* Revert docs to main
* Revert docs to main
* Fix eslint
* Test
* Fix table name
* Fix(#1391): Expose API version even when not running via npm/yarn
## What
Expose the current Unleash version in the generated OpenAPI docs, even
when running via docker or other processes.
## Why
An OpenAPI spec without a version isn't valid. This causes some of our
generation tools (such as the one for documentation) to fail.
## How
By changing how we fetch the current version:
Previously, we used `process.env.npm_package_version!`. However, when
you're not running with yarn or npm, this is `undefined`. That causes
the version number to not be included when running tests and when
running using the official docker image.
Instead, we now use `version` from `lib/util/version`. This is the
same version as the one used by the UI config endpoint, so it should
be the same one as what the front end displays. To the best of my
knowledge, this _is_ the version of the API.
## Discussion
It _may_ be that I have misunderstood what the version represents, but
from what I can tell, it just exports what's listed as the version in
package.json.
The source code of the `lib/util/version` file is:
```ts
// export module version
require('pkginfo')(module, 'version');
const { version } = module.exports;
export default version;
module.exports = version;
```
* Refactor(#1391): rename imported variable for clarity
* PublicSignupTokens
* bug fix
* bug fixes and test
* bug fixes and test
* bug fixes and test
* Add feature flag
* tests
* tests
* Update 20220908093515-add-public-signup-tokens.js
Bug Fix
* task: use swc instead of ts-jest (#2042)
* Add a counter for total number of environments (#1964)
* add groupId to gradual rollout template (#2045)
* add groupId to gradual rollout template
* FMT
* Improve tabs UI on smaller devices (#2014)
* Improve tabs UI on smaller devices
* Improve tabs UI on smaller devices
* bug fix
* add proper scrollable tabs
* removed centered from Tabs (conflicts with scrollable)
* PR comments
* 4.15.0-beta.10
* Fix broken doc links (#2046)
## What
This PR fixes some broken links that have been hanging around in the
docs for what seems like a very long time.
## Why
As discovered by the link check in #1912, there are a fair few broken
links in the docs. Everyone hates broken links because it makes it
harder to understand what they were supposed to be pointing at.
## How
There are 3 types of links that have been fixed:
- Links that should have been internal but were absolute. E.g.
`https://docs.getunleash.io/path/article` that should have been
`./article.md`
- External links that have changed, such as Slack's API description
- GitHub links to files that either no longer exist or that have been
moved. These links generally pointed to `master`/`main`, meaning
they are subject to change. They have been replaced with permalinks
pointing to specific commits.
-----
* docs: fix slack api doc link
* docs: update links in migration guide
* docs: fix broken link to ancient feature schema validation
* docs: update links to v3 auth hooks
* docs: update broken link in the go sdk article
* Fix: use permalink for GitHub link
* docs: fix wrong google auth link
* 4.15.0
* 4.15.1
* docs: update link for symfony sdk (#2048)
The doc link appears to have pointed at an address that is no longer reachable. Instead, let's point to the equivalent GitHub link
Relates to and closes#2047
* docs: test broken links in website (#1912)
The action triggers manually as a first step to test this functionality. In the near future, we might schedule it
* Schedule link checker action (#2050)
Runs at 12:30 UTC on Mon, Tue, Wed, Thu and Fri
* fix: add env and project labels to feature updated metrics. (#2043)
* Revert workflow (#2051)
* update snapshot
* PR comments
* Added Events and tests
* Throw error if token not found
Co-authored-by: Christopher Kolstad <chriswk@getunleash.ai>
Co-authored-by: Thomas Heartman <thomas@getunleash.ai>
Co-authored-by: Gastón Fournier <gaston@getunleash.ai>
Co-authored-by: Ivar Conradi Østhus <ivarconr@gmail.com>
Co-authored-by: sjaanus <sellinjaanus@gmail.com>
* fix: varidate-edge-tokens-schema tokens type
This change fixes the description of the 'tokens' array of the
validate edge tokens schema.
The source of the error was a simple inverson of anyOf and items.
* fix: update snapshot
* feat: use unleash flags for embedded proxy
* feat: add a separate flag for the proxy frontend
* fix: setup unleash in dev
* fix: check flagResolver on each request
* fix: remove unleash client setup
* refactor: update frontend routes snapshot
* refactor: make batchMetrics flag dynamic
* fix: always check dynamic CORS origins config
* fix: make conditionalMiddleware work with the OpenAPI schema generation
Co-authored-by: olav <mail@olav.io>
* fix: remove unused exp flag
* fix: remove unused flag
* fix: add support for external flag resolver
* fix: rename flagsresolver to flagresolver
* fix: disable external flag resolver
* fix: refactor a bit
* fix: stop using unleash in server-dev
* fix: remove userGroups flag
* fix: revert bumping frontend
* refactor: remove unused API definition routes
* feat: embed proxy endpoints
* feat: check token metadata for alias if none is found
* fix: rename param
* feat: add test for retrieving token by alias
* fix: update schema
* fix: refactor to alias
* fix: refactor to null
* fix: update snapshot
* fix: update openapi snapshot
* fix: add check to getUserForToken
* refactor: add more token alias tests
* refactor: use timingSafeEqual for token comparisons
Co-authored-by: olav <mail@olav.io>
* refactor: batch feature metric inserts
* fix: use startOfHour when collapsing metrics
* refactor: avoid extra loop to sum yes/no values
* refactor: add experimental flag for batching metrics
* refactor: remove unused API definition routes
* feat: add support for proxy keys
* feat: support listening for any event
* feat: embed proxy endpoints
* refactor: add an experimental flag for the embedded proxy
* Docs: start experimenting with OpenAPI and docusaurus
* Docs: add docusaurus-theme-openapi-docs pkg
* Wip: current status
* Docs: Add 'docusaurus-plugin-api-docs'
* Move openapi into own sidebar; generate from localhost
* Chore: Update docusaurus plugin for OpenAPI
* Add website/yarn.lock to git
* Fix: fix CSS warning by using flex-end instead of end
* docs: make openapi generated code work again
* docs: make tags work properly with openapi sidebar
* Docs/chore: update OpenAPI tag scheme.
Add a whole bunch of new tags to make it easier to understand
available tags in OpenAPI.
* docs: point to new openapi docs from old api docs
* docs: typo
* Docs: link restructure
* docs: add operation indicators to openapi docs
* docs: change badge color for operations
* docs: update openapi-docs package
It now sorts tags the same as the schema
* docs: pluralize APIs in slug
* docs: update links to generated api docs
* docs: update openapi snapshot tests with new tags
* docs: conditionally load spec from localhost or from file
* docs: Remove changes relating to immediate switchover
* refactor: rename types; extract into separate file
* docs: fix api doc links
* Feat: return reasons why a feature evaluated to true or false
Note: this is very rough and just straight ripped from the nodejs
client. It will need a lot of work, but is a good place to start
* Feat: add suggested shape for new payload
* Chore: minor cleanup
* Wip: make server compile again
* Remove unused schema ref
* Export new schemas
* Chore: fix some tests to use sub property
* Fix: fix some tests
* Refactor: rename some variables, uncomment some stuff
* Add segments type to bootstrap options
* Add segments capability to offline feature evaluator
* Fix function calls after turning params into an option abject
* Feat: test strategy order, etc
* Feat: add test to check that all strats are returned correctly
* Feat: allow you to include strategy ids in clients
* Wip: hook up segments in the offline client.
Note: compared to regular clients, they still fail
* Feat: add segments validation
* Fix: fix test case invariant.
* Chore: revert to returning only `boolean` from strategies.
This _should_ make it work with custom strategies too 🤞
* Feat: make more properties of the returned feature required
* Wip: add some comments and unfinished tests for edge cases
* Feat: add `isEnabledInCurrentEnvironment` prop
* Feat: consider more strategy failure cases
* Feat: test that isenabledinenvironment matches expectations
* Feat: add unknown strategies
* Fix: fix property access typo
* Feat: add unknown strategy for fallback purposes
* Feat: test edge case: all unknown strategies
* Feat: add custom strategy to arbitrary
* Feat: test that features can be true, even if not enabled in env
* Chore: add some comments
* Wip: fix sdk tests
* Remove comments, improve test logging
* Feat: add descriptions and examples to playground feature schema
* Switch `examples` for `example`
* Update schemas with descriptions and examples
* Fix: update snapshot
* Fix: openapi example
* Fix: merge issues
* Fix: fix issue where feature evaluation state was wrong
* Chore: update openapi spec
* Fix: fix broken offline client tests
* Refactor: move schemas into separate files
* Refactor: remove "reason" for incomplete evaluation.
The only instances where evaluation is incomplete is when we don't
know what the strategy is.
* Refactor: move unleash node client into test and dev dependencies
* Wip: further removal of stuff
* Chore: remove a bunch of code that we don't use
* Chore: remove comment
* Chore: remove unused code
* Fix: fix some prettier errors
* Type parameters in strategies to avoid `any`
* Fix: remove commented out code
* Feat: make `id` required on playground strategies
* Chore: remove redundant type
* Fix: remove redundant if and fix fallback evaluation
* Refactor: reduce nesting and remove duplication
* Fix: remove unused helper function
* Refactor: type `parameters` as `unknown`
* Chore: remove redundant comment
* Refactor: move constraint code into a separate file
* Refactor: rename `unleash` -> `feature-evaluator`
* Rename class `Unleash` -> `FeatureEvaluator`
* Refactor: remove this.ready and sync logic from feature evaluator
* Refactor: remove unused code, rename config type
* Refactor: remove event emission from the Unleash client
* Remove unlistened-for events in feature evaluator
* Refactor: make offline client synchronous; remove code
* Fix: update openapi snapshot after adding required strategy ids
* Feat: change `strategies` format.
This commit changes the format of a playground feature's `strategies`
properties from a list of strategies to an object with properties
`result` and `data`. It looks a bit like this:
```ts
type Strategies = {
result: boolean | "unknown",
data: Strategy[]
}
```
The reason is that this allows us to avoid the breaking change that
was previously suggested in the PR:
`feature.isEnabled` used to be a straight boolean. Then, when we found
out we couldn't necessarily evaluate all strategies (custom strats are
hard!) we changed it to `boolean | 'unevaluated'`. However, this is
confusing on a few levels as the playground results are no longer the
same as the SDK would be, nor are they strictly boolean anymore.
This change reverts the `isEnabled` functionality to what it was
before (so it's always a mirror of what the SDK would show).
The equivalent of `feature.isEnabled === 'unevaluated'` now becomes
`feature.isEnabled && strategy.result === 'unknown'`.
* Fix: Fold long string descriptions over multiple lines.
* Fix: update snapshot after adding line breaks to descriptions
* Wip: fix openapi spec
* Feat: add openapi enforcer for enforcing the generated schema
* Chore: Allow the example keyword in params
* Feat: add validator tests and fix some errors
* Use @apidevtools/swagger-parser for schema validation
* Wip: refactor tests for updated schema name
* Feat: update request params creation method
* Feat: add query params to state
* Refactor: move mapping test into separate function
* Refactor: rename request-parameters -> query-parameters
* Refactor: expose only finished query parameters
* Wip: fixup param types
* Refactor: remove unused types
* Chore: rename and cleanup
* Chore: cleanup
* Fix: Update snapshot
* Fix: use ?? Instead of paramToBool to get defaults
* Wip: generate query param object type from openapi params list
* Wip: use generated types for export query params
* Revert "Fix: use ?? Instead of paramToBool to get defaults"
This reverts commit 842567500b.
Because we accept bools, strings, and numbers, this is the only way to
do it.
* Chore: update and pin json-schema-to-ts
* Fix: use `&` to merge types
* Update snapshot
* Chore: rename export-parameters-schema -> export-query-parameters
When it ends in `schema`, the tests expect it to be included in the
openapi index file.
* strategy sort order endpoint
Co-authored-by: Fredrik Strand Oseberg <fredrik.no@gmail.com>
* feat: add e2e test for happy path
* add tests to features strategies order
Co-authored-by: Fredrik Strand Oseberg <fredrik.no@gmail.com>
* feat: add tests for sort-order
* fix: update snapshot
* fix: lint
Co-authored-by: Fredrik Strand Oseberg <fredrik.no@gmail.com>
* Implement user grouping feature for permissions
Co-authored-by: Thomas Heartman <thomas@getunleash.ai>
Co-authored-by: Jaanus Sellin <sellinjaanus@gmail.com>
Co-authored-by: Nuno Góis <github@nunogois.com>
Co-authored-by: Thomas Heartman <thomas@getunleash.ai>
* Refactor: use the `ALL` constant for tests
* Fix: context is not passed to `getVariant` call
This commit fixes a bug wherein a toggle with variants would show as
enabled but without variants. This was because the `getVariant` call
didn't receive the provided context as an argument.
* Chore: add unleash-client dependency
* Feat: add openapi specs for basic sdk contexts and playground reqs
* Feat: add openapi spec for response
* Feat: add openAPI entry for playground endpoint
* Fix: remove required 'projects' property that doesn't exist
* Refactor: add test placeholders for playground api
* Chore: improve openAPI description for playground request
* Refactor: align example project names
* Fix: update openapi snapshot
* Fix: summary -> description; example -> examples
* Feat: add fast-check and stub out one test.
The test doesn't work yet.
* Feat: add test and generator for sdk context schema
* Feat: add generators and tests for all new schemas
* Feat: test that the same input is returned exactly
* Feat: add more tests and more schemas
* Refactor: clean up tests some
* Refactor: simplify url friendliness check
* Refactor: fix types for playground request schema generator
* Feat: add bad request test
* Fix: make parameters the correct shape in generator
* Feat: scaffold out tests for service and endpoint
Liberal use of @ts-expect-error
* Fix: update snapshot with new model
* Add missing appName
* wip: stub out some extra tests
* Feat: model strategies for testing
* Feat: model variant payloads better
* Refactor: input params for function
* Refactor: use email address for user id generation
* Chore: update comment
* Wip: start stubbing out e2e tests
* Refactor: move tests requiring db to e2e file
* Fix: make e2e tests run as expected
* Fix: make toggle generator test work as expected
* Fix: increase timeout for long-running e2e test
* Wip: map toggles test
* Wip: test movement and cleanup
* Refactor: remove `AllowedStrings` in favor of typeof X[number]
* Wip: add e2e tests for the service
* Wip: tests in progress
* Feat: return fuller variant value
* Wip: delete redundant test.
Both those tests were testing versions of the same thing, so let's
delete one of them
* Feat: update openAPI snapshot
* Feat: hook up the playground service
* Feat: fix test cases for e2e api
* Refactor: get rid of _one_ 'as unknown as x' cast
* Fix: wait for the client to be ready before we pass it back
* Fix: weights go to 1000!
* Fix: fix some test assertions, add one more test to be sure
* Wip: add some test parameters to hopefully avoid timeouts
* Fix: don't init the client if there are no toggles
If you don't provide it with any toggles to bootstrap, then the client
will never be ready. This avoids that.
This adds two ways around it because we'll probably get away with a
bit less computation if we don't even try to initialize it. However,
we also don't want anyone else to make this mistake.
* Chore: modify test params
* Feat: use the type system to avoid empty lists for initialization
* Refactor: make tests simpler
* Feat: test basic context values
* Feat: test dynamic context values
* Fix: make custom context field test more reliable
* Feat: use unique arrays for toggles
* Feat: make `appName` required in context
* Fix: sdk context schema arbitrary: make appName at least 1 char long
* Fix: add a minimum length on appName in the context schema
* Fix: fix tests that fail due to new requirements
* Fix: update a test: remove variant mapping testing
* Fix: fix remaining tests
* Feat: rename response.toggles -> response.features
* Refactor: avoid single-letter predicate variables
* Refactor: extract offlineclient into its own file
* Refactor: move arbitraries into separate file
* Refactor: move playground requests into util function
* Fix: remove duplicate declaration of urlFriendlyString
* Chore: update comment
* Refactor: align on arbitrary generator naming
* Feat: Export single strategy arbitrary
* Refactor: move openapi utils into /util directory
* Refactor: move utils test into `util` directory
* Refactor: don't expose standard responses tied to status codes
* Feat: update empty response description + make it const
* Chore: update snapshot with new response descriptions
* refactor: add schemas to user admin controller
* refactor: remove unused SessionService
* refactor: fix search query type confusion
* refactor: add schemas to user controller (#1693)
* refactor: add schemas to user controller
* refactor: fix getAllUserSplashes method name
* refactor: name and email should not be required on create
* refactor: only some user fields may be updated
* refactor: should not require any fields on user update (#1730)
* refactor: send 400 instead of 500 on missing username and email
* refactor: should not require any fields for user update
* refactor: note that earlier versions required name or email
* refactor: merge roleDescriptionSchema and roleSchema
* fix: Does not delete api_tokens on drop-Import
* feat: Cleans unused apiTokens on environment import
* refactor: Moves ALL_PROJECTS and ALL_ENVIRONMENTS to constants
* refactor: Renames migration 20220528143630 for a more precise name
* refactor: Removes unecessary console.log
* fix: Adds correct down-script for migration 20220528143630
* fix: apply query from checkProjectsCompatibility
* fix: require equal environments when moving toggles
* refactor: clean up project service tests
* refactor: add test for project compatibility check
* refactor: improve arraysHaveSameItems name
* feat: add OpenAPI validation to a few endpoints (2)
* refactor: use package version as the OpenAPI version
* refactor: keep the existing OpenAPI page for now
* refactor: add snapshots tests for the OpenAPI output
* refactor: validate Content-Type by default
* refactor: update vulnerable deps
* refactor: fix documentation URL to match schema
* refactor: improve external type declaration
* refactor: remove unused package resolutions
* refactor: try express-openapi fork
* Update package.json
* Update src/lib/services/openapi-service.ts
* Update src/lib/types/openapi.d.ts
* Update src/lib/types/openapi.d.ts
Co-authored-by: Ivar Conradi Østhus <ivarconr@gmail.com>
This adds support for multi project tokens to be created. Backward compatibility is handled at 3 different layers here:
- The API is made backwards compatible though a permissive data type that accepts either a project?: string or projects?: string[] property, validation is done through JOI here, which ensures that projects and project are not set together. In the case of neither, this defaults to the previous default of ALL_PROJECTS
- The service layer method to handle adding tokens has been made tolerant to either of the above case and has been deprecated, a new method supporting only the new structure of using projects has been added
- Existing compatibility for consumers of Unleash as a library should not be affected either, the ApiUser constructor is now tolerant to the the first input and will internally map to the new cleaned structure
* fix: reduce project overview query count to 2.
Previously we've been doing N+1 queries for projects, this now changes to doing one query for projects with feature counts, and then one query for membercounts for all projects and merging that with the first query.
* refactor: add an hoursBack query param to the raw metrics endpoint
* refactor: explicitly return undefined
* refactor: make parseHoursBackQueryParam non-static
* refactor: add test for hoursBack query param
* refactor: improve arg name
* refactor: add a 1 hour test case
* feat: add impression data column
* fix: add default value to impressionData
* fix: allow client api to return impressionData
* fix: add tests for impressionData
* fix: reset server-dev
* fix: add test for adding a toggle with impression data on a different project
* fix: update tests
* wip: environment for permissions
* fix: add migration for roles
* fix: connect environment with access service
* feat: add tests
* chore: Implement scaffolding for new rbac
* fix: add fake store
* feat: Add api endpoints for roles and permissions list
* feat: Add ability to provide permissions when creating a role and rename environmentName to name in the list permissions datastructure
* fix: Make project roles resolve correctly against new environments permissions structure
* fix: Patch migration to also populate permission names
* fix: Make permissions actually work with new environments
* fix: Add back to get permissions working for editor role
* fix: Removed ability to set role type through api during creation - it's now always custom
* feat: Return permissions on get role endpoint
* feat: Add in support for updating roles
* fix: Get a bunch of tests working and delete a few that make no sense anymore
* chore: A few small cleanups - remove logging and restore default on dev server config
* chore: Refactor role/access stores into more logical domains
* feat: Add in validation for roles
* feat: Patch db migration to handle old stucture
* fix: migration for project roles
* fix: patch a few broken tests
* fix: add permissions to editor
* fix: update test name
* fix: update user permission mapping
* fix: create new user
* fix: update root role test
* fix: update tests
* feat: Validation now works when updating a role
* fix: Add in very barebones down migration for rbac so that tests work
* fix: Improve responses from role resolution - getting a non existant role will throw a NotFound error
* fix: remove unused permissions
* fix: add test for connecting roles and deleting project
* fix: add test for adding a project member with a custom role
* fix: add test for changing user role
* fix: add guard for deleting role if the role is in use
* fix: alter migration
* chore: Minor code cleanups
* chore: Small code cleanups
* chore: More minor cleanups of code
* chore: Trim some dead code to make the linter happy
* feat: Schema validation for roles
* fix: setup permission for variant
* fix: remove unused import
* feat: Add cascading delete for role_permissions when deleting a role
* feat: add configuration option for disabling legacy api
* chore: update frontend to beta version
* 4.6.0-beta.0
* fix: export default project constant
* fix: update snapshot
* fix: module pattern ../../lib
* fix: move DEFAULT_PROJECT to types
* fix: remove debug logging
* fix: remove debug log state
* fix: Change permission descriptions
* fix: roles should have unique name
* fix: root roles should be connected to the default project
* fix: typo in role-schema.ts
* fix: Role permission empty string for non environment type
* feat: new permission for moving project
* fix: add event for changeProject
* fix: Removing a user from a project will now check to see if that project has an owner, rather than checking if any project has an owner
* fix: add tests for move project
* fix: Add in missing create/delete tag permissions
* fix: Removed duplicate impl caused by multiple good samaritans putting it back in!
* fix: Trim out add tag permissions, for now at least
* chore: Trim out new add and delete tag permissions - we're going with update feature instead
* chore: update frontend
* 4.6.0-beta.1
* feat: Prevent editing of built in roles
* fix: Patch an issue where permissions for variants/environments didn't match the front end
* fix: lint
Co-authored-by: Ivar Conradi Østhus <ivarconr@gmail.com>
Co-authored-by: Fredrik Oseberg <fredrik.no@gmail.com>
Adds support for initializing a fresh Unleash instance with predefined API tokens.
Co-authored-by: sighphyre <liquidwicked64@gmail.com>
Co-authored-by: Juraj Malenica <juraj.malenica@mindsmiths.com>
Co-authored-by: Ivar Conradi Østhus <ivarconr@gmail.com>
* fix: Update updateUser code to reject empty emails
This fixes an issue where the updateUser call would allow null email
addresses, then update the email to null and then raise an exception,
leaving the db in a state where no user could be resolved.
* fix: remove username/email requirement in user.ts
Co-authored-by: Ivar Conradi Østhus <ivarconr@gmail.com>
This triggers when we update or overwrite variants, and will include the
previous variants and the new variants.
Co-authored-by: Ivar Østhus <ivarconr@gmail.com>
* fix: sort variants on output
We found that for existing variants, the sorting by name wasn't applied, so the index in the patches were wrong. This PR adds the sort also when we're getting variants as part of the getFeature call, not just when we're getting the variants. This should make the UX consistent, and prevent our patches from hitting the wrong index in the variants array.
Co-authored-by: Youssef Khedher <khedher.youssef@hotmail.fr>
* task: Ban changes to variants through feature
After adding the new `/variants` endpoint for features we now have a way
to access control adding/modifying variants, so the /:featureName
endpoint should no longer allow editing/adding variants.
This removes variants as a known field from the featureMetadata schema
and tells joi to stripUnknown, thus making sure we never include
variants in the initial creation or future update calls.
For the old features v1 API we allow it to declare that it has already
validated the data coming with its own schema, so we should use the data
we get from it. Thus keeping the old v1 functionality intact
Co-authored-by: Simon Hornby <simon@getunleash.ai>
- Since the archived toggles are not visible in the health dashboard,
including them in the health rating calculation makes for some really
confusing dashboards. This PR makes sure we only include non-archived
toggles when calculating health.
Add a new .../:feature/variants API
This adds
- `GET /api/admin/projects/:projectId/features/:featureName/variants` which returns
```json
{ version: '1', variants: IVariant[] }
```
- `PATCH /api/admin/projects/:projectId/features/:featureName/variants` which accepts a json patch set and updates the feature's variants field and then returns
```json
{ version: '1', variants: IVariant[] }
```
- `PUT /api/admin/projects/:projectId/features/:featureName/variants`
which accepts a IVariant[] and overwrites the current variants list for the feature defined in :featureName and returns
```json
{ version: '1', variants: IVariant[] }
- This also makes sure the total weight of all variants is == 1000
- Validates that there is at least 1 'variable' variant if there are variants
- Validates that 'fix' variants total weight can't exceed 1000
- Adds tests for all these invariants.
Co-authored-by: Simon Hornby <simon@getunleash.ai>
* fix: prevent deadlock for batchinserting usage metrics
In client metrics v2 we utilize postgres to count the usage
across a few dimentions (featureName, app_name, environment).
It turns out that if the UPDATE values are not executed in a predictable
order we can end up in a deadlock scenario with postgresql.
In this fix we thus sort the metrics on the feature_name, app_name and
envrionment, to make sure they always are executed in a predictabel
order, and thus avoiding independent inserts colliding in to a deadlock
waiting for eachother.
* fix: tests cannot assume order
- In order for a feature toggle to be allowed to change project, the
target project must have the same enabled environments.
- If the feature toggle has an environment which is not in use that does
not exist in target project, this is ok.
Co-authored-by: Fredrik Strand Oseberg <fredrik.no@gmail.com>
Co-authored-by: Fredrik Strand Oseberg <fredrik.no@gmail.com>
Adds a new way of handling usage metrics where we push it directly to the database and performs aggregation on the fly. All metrics are aggregated in to buckets of hours. We will for now store metrics for the 48 hours with the following dimensions:
- featureName
- projectName
- envrionment
- yes (the actual count)
- no (the actual count)
* feat: add new more specific feature/environment events to addons
* Updated strategy change text
* Update all three addon messages for strategy
* Link to new features view for strategy change text
Co-authored-by: Ivar Conradi Østhus <ivarconr@gmail.com>
- Adds development and production environments.
- Connects default environment to all projects
- When creating a project connects the project to all enabled
environments
Our testing and internal validation has proven that
the :global: environment concept confuses people more
than the problems it solves. We have thus decided to
group all configuration that was created before the
environment concept was introduced in to the "default
environment. This would still make everything work
as before in addition to introducing the env concept.
Co-authored-by: Christopher Kolstad <chriswk@getunleash.ai>
* feat: add project and environment columns to events
* Added events for feature_strategy update
* fix duplicate test key for dbInit
* Fix argument list for toggleService calls in tests
- Adding, updating and renaming environments are meant to be
enterprise only features, as such, this PR moves these operations out
of this server
- We still keep sortOrder updating, toggling on/off and getting one,
getting all, so we can still work with environments in the OSS version
as well.
Co-authored-by: Christopher Kolstad <chriswk@getunleash.ai>
Co-authored-by: Christopher Kolstad <chriswk@getunleash.ai>
This allows frontend to support a toggle for admins wanting to create
users and passwords manually, without sending emails to users they
create.
Co-authored-by: Ivar Conradi Østhus <ivarconr@gmail.com>
Adds environment support
This PR adds environments as a first-class concept in Unleash.
It necessitated a full rewrite on how we connect feature <-> strategy, as well as a rethink on which levels environments makes sense.
This enables PUTs on strategy configurations for a feature, since all strategies now have ids.
This also updates export/import format. The importer handles both formats, but export is no longer possible in version 1 of the export format, only in version 2, with strategy configurations for a feature as a separate object.
Co-authored-by: Christopher Kolstad <chriswk@getunleash.ai>
Co-authored-by: Fredrik Oseberg <fredrik.no@gmail.com>
Co-authored-by: Ivar Conradi Østhus <ivarconr@gmail.com>
* feat: setup user feedback service
* fix: map rows
* feat: add tests
* wrap service calls in try catch
* fix: add test for retrieving feedback on user
* feat: add fake user feedback store
* fix: check ffor feedback id in controller
* feat: add test for bad request
* chore: expose an endpoint to really delete a toggle
- To provide a way to run end-to-end tests without cluttering
our demo instance with way too many feature-toggles, making this
endpoint available will allow end-to-end tests to clean up properly
after themselves
* chore: update changelog
* chore: update changelog
* feat: format asset paths and insert baseUri in html
* feat: add tests
* feat: pass dependencies to pre router hook
Co-authored-by: Ivar Conradi Østhus <ivarconr@gmail.com>