@dvsa/cvs-feature-flags 1.0.0 → 1.1.0-canary.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/feature-flags.d.ts +1 -1
- package/feature-flags.js +27 -8
- package/package.json +1 -1
- package/profiles/vta.d.ts +1 -1
- package/profiles/vta.js +2 -2
- package/profiles/vtm.d.ts +1 -1
- package/profiles/vtm.js +2 -2
- package/profiles/vtx.d.ts +1 -1
- package/profiles/vtx.js +2 -2
package/feature-flags.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { FeatureFlagsClientName } from './';
|
|
2
|
-
export declare const getFeatureFlags: <T>(clientName: FeatureFlagsClientName) => Promise<T>;
|
|
2
|
+
export declare const getFeatureFlags: <T>(clientName: FeatureFlagsClientName, email?: string) => Promise<T>;
|
package/feature-flags.js
CHANGED
|
@@ -3,20 +3,39 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getFeatureFlags = void 0;
|
|
4
4
|
const appconfig_1 = require("@aws-lambda-powertools/parameters/appconfig");
|
|
5
5
|
const config_1 = require("./config");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
function hasEmails(flag) {
|
|
7
|
+
return typeof flag === 'object' && flag !== null && Array.isArray(flag.emails);
|
|
8
|
+
}
|
|
9
|
+
function resolveVariants(config, email) {
|
|
10
|
+
const resolved = {};
|
|
11
|
+
for (const [key, value] of Object.entries(config)) {
|
|
12
|
+
if (!hasEmails(value)) {
|
|
13
|
+
resolved[key] = value;
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
const { emails, ...flagValues } = value;
|
|
17
|
+
const normalisedEmail = email?.toLowerCase();
|
|
18
|
+
const isTargeted = normalisedEmail && emails.map((e) => e.toLowerCase()).includes(normalisedEmail);
|
|
19
|
+
if (isTargeted) {
|
|
20
|
+
resolved[key] = flagValues;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return resolved;
|
|
24
|
+
}
|
|
9
25
|
class FeatureFlagsClient {
|
|
10
|
-
async get(clientName) {
|
|
11
|
-
const
|
|
26
|
+
async get(clientName, email) {
|
|
27
|
+
const config = await (0, appconfig_1.getAppConfig)(`${clientName}-profile`, {
|
|
12
28
|
...config_1.defaultFeatureFlagConfig,
|
|
13
29
|
transform: 'json',
|
|
14
30
|
});
|
|
15
|
-
|
|
31
|
+
if (!email) {
|
|
32
|
+
return config;
|
|
33
|
+
}
|
|
34
|
+
return resolveVariants(config, email);
|
|
16
35
|
}
|
|
17
36
|
}
|
|
18
|
-
const getFeatureFlags = async (clientName) => {
|
|
37
|
+
const getFeatureFlags = async (clientName, email) => {
|
|
19
38
|
const client = new FeatureFlagsClient();
|
|
20
|
-
return await client.get(clientName);
|
|
39
|
+
return await client.get(clientName, email);
|
|
21
40
|
};
|
|
22
41
|
exports.getFeatureFlags = getFeatureFlags;
|
package/package.json
CHANGED
package/profiles/vta.d.ts
CHANGED
package/profiles/vta.js
CHANGED
|
@@ -15,8 +15,8 @@ const defaultFeatureFlags = {
|
|
|
15
15
|
enabled: false,
|
|
16
16
|
},
|
|
17
17
|
};
|
|
18
|
-
const getProfile = async () => {
|
|
19
|
-
const flags = await (0, feature_flags_1.getFeatureFlags)(__1.FeatureFlagsClientName.VTA);
|
|
18
|
+
const getProfile = async (email) => {
|
|
19
|
+
const flags = await (0, feature_flags_1.getFeatureFlags)(__1.FeatureFlagsClientName.VTA, email);
|
|
20
20
|
return (0, lodash_merge_1.default)(defaultFeatureFlags, flags);
|
|
21
21
|
};
|
|
22
22
|
exports.getProfile = getProfile;
|
package/profiles/vtm.d.ts
CHANGED
package/profiles/vtm.js
CHANGED
|
@@ -8,8 +8,8 @@ const lodash_merge_1 = __importDefault(require("lodash.merge"));
|
|
|
8
8
|
const __1 = require("..");
|
|
9
9
|
const feature_flags_1 = require("../feature-flags");
|
|
10
10
|
const defaultFeatureFlags = {};
|
|
11
|
-
const getProfile = async () => {
|
|
12
|
-
const flags = await (0, feature_flags_1.getFeatureFlags)(__1.FeatureFlagsClientName.VTM);
|
|
11
|
+
const getProfile = async (email) => {
|
|
12
|
+
const flags = await (0, feature_flags_1.getFeatureFlags)(__1.FeatureFlagsClientName.VTM, email);
|
|
13
13
|
return (0, lodash_merge_1.default)(defaultFeatureFlags, flags);
|
|
14
14
|
};
|
|
15
15
|
exports.getProfile = getProfile;
|
package/profiles/vtx.d.ts
CHANGED
package/profiles/vtx.js
CHANGED
|
@@ -80,8 +80,8 @@ const defaultFeatureFlags = {
|
|
|
80
80
|
reporting: false,
|
|
81
81
|
},
|
|
82
82
|
};
|
|
83
|
-
const getProfile = async () => {
|
|
84
|
-
const flags = await (0, feature_flags_1.getFeatureFlags)(__1.FeatureFlagsClientName.VTX);
|
|
83
|
+
const getProfile = async (email) => {
|
|
84
|
+
const flags = await (0, feature_flags_1.getFeatureFlags)(__1.FeatureFlagsClientName.VTX, email);
|
|
85
85
|
return (0, lodash_merge_1.default)(defaultFeatureFlags, flags);
|
|
86
86
|
};
|
|
87
87
|
exports.getProfile = getProfile;
|