@dvsa/cvs-feature-flags 1.0.0 → 1.1.0-canary.0
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 +10 -1
- package/feature-flags.js +20 -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,11 @@
|
|
|
1
1
|
import { FeatureFlagsClientName } from './';
|
|
2
|
-
export
|
|
2
|
+
export interface Variant {
|
|
3
|
+
enabled: boolean;
|
|
4
|
+
emails: string[];
|
|
5
|
+
overrides: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
export interface VariantResult {
|
|
8
|
+
variant: string | null;
|
|
9
|
+
flags: Record<string, unknown>;
|
|
10
|
+
}
|
|
11
|
+
export declare const getFeatureFlags: <T>(clientName: FeatureFlagsClientName, email?: string) => Promise<T>;
|
package/feature-flags.js
CHANGED
|
@@ -1,22 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.getFeatureFlags = void 0;
|
|
4
7
|
const appconfig_1 = require("@aws-lambda-powertools/parameters/appconfig");
|
|
8
|
+
const lodash_merge_1 = __importDefault(require("lodash.merge"));
|
|
5
9
|
const config_1 = require("./config");
|
|
6
|
-
// When instantiating the feature flags, we should be scoping this and caching it to the invocation instance.
|
|
7
|
-
// Each invocation of a lambda will get new feature flags, and that should not change throughout the lambda lifecycle.
|
|
8
|
-
// However, we don't want to cache them across invocations (ie outside the handler).
|
|
9
10
|
class FeatureFlagsClient {
|
|
10
|
-
async get(clientName) {
|
|
11
|
-
const
|
|
11
|
+
async get(clientName, email) {
|
|
12
|
+
const config = await (0, appconfig_1.getAppConfig)(`${clientName}-profile`, {
|
|
12
13
|
...config_1.defaultFeatureFlagConfig,
|
|
13
14
|
transform: 'json',
|
|
14
15
|
});
|
|
15
|
-
|
|
16
|
+
const { variants, ...flags } = config;
|
|
17
|
+
console.log('config', { config, email, flags, variants });
|
|
18
|
+
if (!email || !variants) {
|
|
19
|
+
return flags;
|
|
20
|
+
}
|
|
21
|
+
const matchedVariant = Object.values(variants).find((v) => v.enabled && v.emails.map((e) => e.toLowerCase()).includes(email.toLowerCase()));
|
|
22
|
+
console.log('matchedVariant', { matchedVariant });
|
|
23
|
+
if (!matchedVariant) {
|
|
24
|
+
return flags;
|
|
25
|
+
}
|
|
26
|
+
console.log('merged', (0, lodash_merge_1.default)({}, flags, matchedVariant.overrides));
|
|
27
|
+
return (0, lodash_merge_1.default)({}, flags, matchedVariant.overrides);
|
|
16
28
|
}
|
|
17
29
|
}
|
|
18
|
-
const getFeatureFlags = async (clientName) => {
|
|
30
|
+
const getFeatureFlags = async (clientName, email) => {
|
|
19
31
|
const client = new FeatureFlagsClient();
|
|
20
|
-
return await client.get(clientName);
|
|
32
|
+
return await client.get(clientName, email);
|
|
21
33
|
};
|
|
22
34
|
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;
|