Skip to content

Commit 977e24f

Browse files
Merge pull request #52 from microsoft/zhiyuanliang/merge-main-to-preview
Merge main to preview
2 parents e546a47 + f892ce3 commit 977e24f

File tree

14 files changed

+337
-107
lines changed

14 files changed

+337
-107
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ types/
409409
*.tgz
410410

411411
# examples
412-
examples/package-lock.json
412+
examples/**/**/package-lock.json
413413

414414
# playwright test result
415415
test-results

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ The App Configuration JavaScript provider provides feature flags in as a `Map` o
2121
A builtin `ConfigurationMapFeatureFlagProvider` helps to load feature flags in this case.
2222

2323
```js
24-
const appConfig = load(connectionString, {featureFlagOptions}); // load feature flags from Azure App Configuration service
24+
const appConfig = await load(connectionString, {featureFlagOptions}); // load feature flags from Azure App Configuration service
2525
const featureProvider = new ConfigurationMapFeatureFlagProvider(appConfig);
2626
const featureManager = new FeatureManager(featureProvider);
2727
const isAlphaEnabled = await featureManager.isEnabled("Alpha");
@@ -42,7 +42,7 @@ Content of `sample.json`:
4242
{
4343
"id": "Alpha",
4444
"description": "",
45-
"enabled": "true",
45+
"enabled": true,
4646
"conditions": {
4747
"client_filters": []
4848
}

examples/console-app/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Examples for Microsoft Feature Management for JavaScript
2+
3+
These examples show how to use the Microsoft Feature Management in some common scenarios.
4+
5+
## Prerequisites
6+
7+
The examples are compatible with [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule).
8+
9+
Some examples use `@azure/app-configuration-provider` to load feature flags from the [Azure App Configuration](https://learn.microsoft.com/azure/azure-app-configuration/overview). Azure App Configuration provides a service to centrally manage application settings and feature flags.
10+
11+
## Setup & Run
12+
13+
1. Install the dependencies using `npm`:
14+
15+
``` bash
16+
npm install
17+
```
18+
19+
1. Run the examples:
20+
21+
``` bash
22+
node featureFlagSample.mjs
23+
```

examples/console-app/config.json

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"feature_management": {
3+
"feature_flags": [
4+
{
5+
"id": "FeatureX",
6+
"enabled": true
7+
},
8+
{
9+
"id": "FeatureY",
10+
"enabled": false
11+
},
12+
{
13+
"id": "FeatureFlagWithTimeWindowFilter",
14+
"enabled": true,
15+
"conditions": {
16+
"client_filters": [
17+
{
18+
"name": "Microsoft.TimeWindow",
19+
"parameters": {
20+
"Start": "Thu, 15 Aug 2024 00:00:00 GMT",
21+
"End": "Mon, 19 Aug 2024 00:00:00 GMT"
22+
}
23+
}
24+
]
25+
}
26+
},
27+
{
28+
"id": "FeatureFlagWithTargetingFilter",
29+
"enabled": true,
30+
"conditions": {
31+
"client_filters": [
32+
{
33+
"name": "Microsoft.Targeting",
34+
"parameters": {
35+
"Audience": {
36+
"Users": [
37+
"Jeff"
38+
],
39+
"Groups": [
40+
{
41+
"Name": "Admin",
42+
"RolloutPercentage": 100
43+
}
44+
],
45+
"DefaultRolloutPercentage": 40,
46+
"Exclusion": {
47+
"Users": [
48+
"Anne"
49+
],
50+
"Groups": [
51+
"Guest"
52+
]
53+
}
54+
}
55+
}
56+
}
57+
]
58+
}
59+
}
60+
]
61+
}
62+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
import fs from 'node:fs/promises';
5+
import { ConfigurationObjectFeatureFlagProvider, FeatureManager } from "@microsoft/feature-management";
6+
7+
const config = JSON.parse(await fs.readFile("config.json"));
8+
const featureProvider = new ConfigurationObjectFeatureFlagProvider(config);
9+
const featureManager = new FeatureManager(featureProvider);
10+
11+
console.log("FeatureX is:", await featureManager.isEnabled("FeatureX"));
12+
console.log("FeatureY is:", await featureManager.isEnabled("FeatureY"));
13+
14+
// Is true between 2024-8-15 ~ 2024-8-19
15+
console.log("Feature flag with Time WindoW Filter is:", await featureManager.isEnabled("FeatureFlagWithTimeWindowFilter"));
16+
17+
// Targeted by Users
18+
console.log("Feature flag with Targeting Filter is:", await featureManager.isEnabled("FeatureFlagWithTargetingFilter", {userId: "Jeff"}))
19+
// Excluded by Users
20+
console.log("Feature flag with Targeting Filter is:", await featureManager.isEnabled("FeatureFlagWithTargetingFilter", {userId: "Anne"}))
21+
// Targeted by Groups Admin
22+
console.log("Feature flag with Targeting Filter is:", await featureManager.isEnabled("FeatureFlagWithTargetingFilter", {userId: "Admin1", groups: ["Admin"]}))
23+
// Excluded by Groups Guest
24+
console.log("Feature flag with Targeting Filter is:", await featureManager.isEnabled("FeatureFlagWithTargetingFilter", {userId: "Guest1", groups: ["Guest"]}))
25+
26+
// Targeted by default rollout percentage
27+
console.log("Feature flag with Targeting Filter is:", await featureManager.isEnabled("FeatureFlagWithTargetingFilter", {userId: "Alicia"}))
28+
console.log("Feature flag with Targeting Filter is:", await featureManager.isEnabled("FeatureFlagWithTargetingFilter", {userId: "Susan"}))
29+
console.log("Feature flag with Targeting Filter is:", await featureManager.isEnabled("FeatureFlagWithTargetingFilter", {userId: "John"}))
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
import { load } from "@azure/app-configuration-provider";
5+
import { ConfigurationMapFeatureFlagProvider, FeatureManager } from "@microsoft/feature-management";
6+
7+
const connectionString = "<your-connection-string>";
8+
const appConfig = await load(connectionString, {
9+
featureFlagOptions: {
10+
enabled: true,
11+
selectors: [{
12+
keyFilter: "*"
13+
}],
14+
refresh: {
15+
enabled: true
16+
}
17+
}
18+
});
19+
20+
const featureProvider = new ConfigurationMapFeatureFlagProvider(appConfig);
21+
const featureManager = new FeatureManager(featureProvider);
22+
23+
console.log("Feature Beta is:", await featureManager.isEnabled("Beta"));

examples/console-app/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"dependencies": {
3+
"@azure/app-configuration-provider": "latest",
4+
"@microsoft/feature-management": "latest"
5+
}
6+
}

0 commit comments

Comments
 (0)