@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.
@@ -1,2 +1,11 @@
1
1
  import { FeatureFlagsClientName } from './';
2
- export declare const getFeatureFlags: <T>(clientName: FeatureFlagsClientName) => Promise<T>;
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 featureFlags = await (0, appconfig_1.getAppConfig)(`${clientName}-profile`, {
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
- return featureFlags;
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dvsa/cvs-feature-flags",
3
- "version": "1.0.0",
3
+ "version": "1.1.0-canary.0",
4
4
  "description": "Common package to be used in CVS to manage feature flags",
5
5
  "author": "DVSA",
6
6
  "license": "ISC",
package/profiles/vta.d.ts CHANGED
@@ -7,5 +7,5 @@ declare const defaultFeatureFlags: {
7
7
  };
8
8
  };
9
9
  export type FeatureFlags = typeof defaultFeatureFlags;
10
- export declare const getProfile: () => Promise<FeatureFlags>;
10
+ export declare const getProfile: (email?: string) => Promise<FeatureFlags>;
11
11
  export {};
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
@@ -1,4 +1,4 @@
1
1
  declare const defaultFeatureFlags: {};
2
2
  export type FeatureFlags = typeof defaultFeatureFlags;
3
- export declare const getProfile: () => Promise<{}>;
3
+ export declare const getProfile: (email?: string) => Promise<{}>;
4
4
  export {};
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
@@ -71,5 +71,5 @@ declare const defaultFeatureFlags: {
71
71
  };
72
72
  };
73
73
  export type FeatureFlags = typeof defaultFeatureFlags;
74
- export declare const getProfile: () => Promise<FeatureFlags>;
74
+ export declare const getProfile: (email?: string) => Promise<FeatureFlags>;
75
75
  export {};
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;