Skip to content

Commit 15c5d82

Browse files
authored
Merge pull request #1 from alexanderaagaard/main
Add featureConditions for targeting specific audience with featureFlags
2 parents c2060f1 + bce49b5 commit 15c5d82

File tree

8 files changed

+93
-33
lines changed

8 files changed

+93
-33
lines changed

dist/index.d.mts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,19 @@ type FlagOptionsType = {
88
type GetFeatureFlagType = (params: FlagOptionsType) => {
99
isFeatureEnabled: Ref<boolean>;
1010
featureDescription: Ref<string>;
11+
featureConditions: IConditions;
1112
};
1213
interface IFeatureFlagsManager {
1314
appConfigurationClient: AppConfigurationClientType;
1415
getFeatureFlag: GetFeatureFlagType;
1516
}
1617
type AppConfigurationClientType = AppConfigurationClient | null;
18+
interface IConditions {
19+
clientFilters?: {
20+
name: string;
21+
parameters?: Record<string, unknown>;
22+
}[];
23+
}
1724
declare const AppConfigurationPlugin: {
1825
install: (app: App, options: {
1926
connectionString?: string;

dist/index.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,19 @@ type FlagOptionsType = {
88
type GetFeatureFlagType = (params: FlagOptionsType) => {
99
isFeatureEnabled: Ref<boolean>;
1010
featureDescription: Ref<string>;
11+
featureConditions: IConditions;
1112
};
1213
interface IFeatureFlagsManager {
1314
appConfigurationClient: AppConfigurationClientType;
1415
getFeatureFlag: GetFeatureFlagType;
1516
}
1617
type AppConfigurationClientType = AppConfigurationClient | null;
18+
interface IConditions {
19+
clientFilters?: {
20+
name: string;
21+
parameters?: Record<string, unknown>;
22+
}[];
23+
}
1724
declare const AppConfigurationPlugin: {
1825
install: (app: App, options: {
1926
connectionString?: string;

dist/index.js

Lines changed: 23 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.mjs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
isFeatureFlag,
2727
parseFeatureFlag
2828
} from "@azure/app-configuration";
29-
import { inject, ref } from "vue";
29+
import { inject, reactive, ref } from "vue";
3030
var FeatureFlagsManagerKey = Symbol(
3131
"FeatureFlagsManager"
3232
);
@@ -45,14 +45,18 @@ var featureFlagsManager = (connectionString, cacheEnabled = true, flagsToPrefetc
4545
key: `${featureFlagPrefix}${name}`,
4646
label
4747
}).then((response) => {
48+
var _a;
4849
if (isFeatureFlag(response)) {
4950
const {
50-
value: { enabled, description = "" }
51+
value: { enabled, description = "", conditions }
5152
} = parseFeatureFlag(response);
5253
const cacheKey = `cache-${name}-${label != null ? label : "empty-label"}`;
5354
cache[cacheKey] = {
5455
isFeatureEnabled: ref(enabled),
55-
featureDescription: ref(description)
56+
featureDescription: ref(description),
57+
featureConditions: reactive({
58+
clientFilters: (_a = conditions.clientFilters) != null ? _a : []
59+
})
5660
};
5761
}
5862
}).catch((error) => {
@@ -73,24 +77,26 @@ var featureFlagsManager = (connectionString, cacheEnabled = true, flagsToPrefetc
7377
}
7478
const isFeatureEnabled = ref(false);
7579
const featureDescription = ref("");
80+
const featureConditions = reactive({});
7681
if (!appConfigurationClient) {
7782
if (cacheEnabled) {
78-
cache[cacheKey] = { isFeatureEnabled, featureDescription };
83+
cache[cacheKey] = { isFeatureEnabled, featureDescription, featureConditions };
7984
}
80-
return { isFeatureEnabled, featureDescription };
85+
return { isFeatureEnabled, featureDescription, featureConditions };
8186
}
8287
appConfigurationClient.getConfigurationSetting({
8388
key: `${featureFlagPrefix}${name}`,
8489
label
8590
}).then((response) => {
8691
if (isFeatureFlag(response)) {
8792
const {
88-
value: { enabled, description = "" }
93+
value: { enabled, description = "", conditions }
8994
} = parseFeatureFlag(response);
9095
isFeatureEnabled.value = enabled;
9196
featureDescription.value = description;
97+
Object.assign(conditions, featureConditions);
9298
if (cacheEnabled) {
93-
cache[cacheKey] = { isFeatureEnabled, featureDescription };
99+
cache[cacheKey] = { isFeatureEnabled, featureDescription, featureConditions };
94100
}
95101
}
96102
}).catch((error) => {
@@ -99,7 +105,7 @@ var featureFlagsManager = (connectionString, cacheEnabled = true, flagsToPrefetc
99105
error
100106
);
101107
});
102-
return { isFeatureEnabled, featureDescription };
108+
return { isFeatureEnabled, featureDescription, featureConditions };
103109
};
104110
return { getFeatureFlag, appConfigurationClient };
105111
};
@@ -116,19 +122,23 @@ var featureFlagsManagerAsync = (_0, ..._1) => __async(void 0, [_0, ..._1], funct
116122
}
117123
yield Promise.all(
118124
flags.map((_02) => __async(this, [_02], function* ({ name, label }) {
125+
var _a;
119126
try {
120127
const response = yield appConfigurationClient.getConfigurationSetting({
121128
key: `${featureFlagPrefix}${name}`,
122129
label
123130
});
124131
if (isFeatureFlag(response)) {
125132
const {
126-
value: { enabled, description = "" }
133+
value: { enabled, description = "", conditions }
127134
} = parseFeatureFlag(response);
128135
const cacheKey = `cache-${name}-${label != null ? label : "empty-label"}`;
129136
cache[cacheKey] = {
130137
isFeatureEnabled: ref(enabled),
131-
featureDescription: ref(description)
138+
featureDescription: ref(description),
139+
featureConditions: reactive({
140+
clientFilters: (_a = conditions.clientFilters) != null ? _a : []
141+
})
132142
};
133143
}
134144
} catch (error) {
@@ -149,7 +159,10 @@ var featureFlagsManagerAsync = (_0, ..._1) => __async(void 0, [_0, ..._1], funct
149159
}
150160
cache[cacheKey] = {
151161
isFeatureEnabled: ref(false),
152-
featureDescription: ref("")
162+
featureDescription: ref(""),
163+
featureConditions: reactive({
164+
clientFilters: []
165+
})
153166
};
154167
return cache[cacheKey];
155168
};

0 commit comments

Comments
 (0)