-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into kbn-179458-es-secondary-auth
- Loading branch information
Showing
156 changed files
with
2,893 additions
and
1,637 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,7 +84,7 @@ | |
"**/@types/node": "20.10.5", | ||
"**/@typescript-eslint/utils": "5.62.0", | ||
"**/chokidar": "^3.5.3", | ||
"**/d3-scale/**/d3-color": "npm:@elastic/[email protected]", | ||
"**/d3-scale/**/d3-color": "npm:@elastic/kibana-[email protected]", | ||
"**/globule/minimatch": "^3.1.2", | ||
"**/hoist-non-react-statics": "^3.3.2", | ||
"**/isomorphic-fetch/node-fetch": "^2.6.7", | ||
|
@@ -692,6 +692,7 @@ | |
"@kbn/resizable-layout": "link:packages/kbn-resizable-layout", | ||
"@kbn/resizable-layout-examples-plugin": "link:examples/resizable_layout_examples", | ||
"@kbn/resolver-test-plugin": "link:x-pack/test/plugin_functional/plugins/resolver_test", | ||
"@kbn/response-ops-feature-flag-service": "link:packages/response-ops/feature_flag_service", | ||
"@kbn/response-stream-plugin": "link:examples/response_stream", | ||
"@kbn/rison": "link:packages/kbn-rison", | ||
"@kbn/rollup-plugin": "link:x-pack/plugins/rollup", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# @kbn/response-ops-feature-flags | ||
|
||
This packages exposes a feature flag service that is used in the ResponseOps plugins and packages to handle feature flags. | ||
|
||
## Usage | ||
|
||
### Create feature flag service | ||
|
||
``` | ||
const featureFlagService = createFeatureFlagService(['test.myFeature', 'test.myFeature.subFeature']); // TS will infer the types automatically | ||
``` | ||
|
||
or | ||
|
||
``` | ||
type FeatureFlagValues = 'test.myFeature' | 'test.myOtherFeature' | ||
const featureFlagService = createFeatureFlagService<FeatureFlagValues>(['test.myFeature']); | ||
``` | ||
|
||
### Checking the existence of a feature flag | ||
``` | ||
const featureFlagService = createFeatureFlagService(['test.myFeature', 'test.myFeature.subFeature']); | ||
if (featureFlagService.isFeatureFlagSet('test.myFeature')) { | ||
// my feature code | ||
} | ||
``` |
29 changes: 29 additions & 0 deletions
29
packages/response-ops/feature_flag_service/feature_flag_service.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { createFeatureFlagService } from './feature_flag_service'; | ||
|
||
type FeatureFlagValues = 'test.myFeature' | 'test.myOtherFeature'; | ||
|
||
describe('FeatureFlagService', () => { | ||
it('returns true if the feature exists', () => { | ||
const featureFlagService = createFeatureFlagService(['test.myFeature']); | ||
expect(featureFlagService.isFeatureFlagSet('test.myFeature')).toBe(true); | ||
}); | ||
|
||
it('returns false if the feature does not exist', () => { | ||
const featureFlagService = createFeatureFlagService(['test.myFeature']); | ||
// @ts-expect-error: foo is not part of the valid feature flags | ||
expect(featureFlagService.isFeatureFlagSet('foo')).toBe(false); | ||
}); | ||
|
||
it('returns true if the feature exists (as typed)', () => { | ||
const featureFlagService = createFeatureFlagService<FeatureFlagValues>(['test.myFeature']); | ||
expect(featureFlagService.isFeatureFlagSet('test.myFeature')).toBe(true); | ||
}); | ||
}); |
25 changes: 25 additions & 0 deletions
25
packages/response-ops/feature_flag_service/feature_flag_service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
class FeatureFlag<T extends string = string> { | ||
private readonly featureFlags = new Set<T>(); | ||
|
||
constructor(featureFlags: T[]) { | ||
featureFlags.forEach((featureFlag) => this.featureFlags.add(featureFlag)); | ||
} | ||
|
||
public isFeatureFlagSet(featureFlag: T): boolean { | ||
return this.featureFlags.has(featureFlag); | ||
} | ||
} | ||
|
||
export const createFeatureFlagService = <T extends string>(featureFlags: T[]) => { | ||
return new FeatureFlag<typeof featureFlags[number]>(featureFlags); | ||
}; | ||
|
||
export type FeatureFlagService<T extends string = string> = InstanceType<typeof FeatureFlag<T>>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export { createFeatureFlagService } from './feature_flag_service'; | ||
export type { FeatureFlagService } from './feature_flag_service'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
module.exports = { | ||
preset: '@kbn/test/jest_node', | ||
rootDir: '../../..', | ||
roots: ['<rootDir>/packages/response-ops/feature_flag_service'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"type": "shared-common", | ||
"id": "@kbn/response-ops-feature-flag-service", | ||
"owner": "@elastic/response-ops" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "@kbn/response-ops-feature-flag-service", | ||
"private": true, | ||
"version": "1.0.0", | ||
"license": "SSPL-1.0 OR Elastic License 2.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"extends": "../../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"outDir": "target/types", | ||
"types": [ | ||
"jest", | ||
"node" | ||
] | ||
}, | ||
"include": [ | ||
"**/*.ts", | ||
], | ||
"exclude": [ | ||
"target/**/*" | ||
], | ||
"kbn_references": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.