@frontegg/rest-api 3.0.83 → 3.0.84

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
- import { IFeatureFlagsAttributes } from "./interfaces";
1
+ import { FronteggFeatureFlags, IFeatureFlagsAttributes } from "./interfaces";
2
+ export declare class FeatureFlags {
3
+ private _flags;
4
+ private static _instances;
5
+ static getInstance(name?: string): any;
6
+ static set(featureFlags?: FronteggFeatureFlags, name?: string): FeatureFlags;
7
+ static getFeatureFlags(flags: string[]): boolean[];
8
+ get flags(): Required<FronteggFeatureFlags>["flags"];
9
+ set(featureFlags?: FronteggFeatureFlags): void;
10
+ }
2
11
  export declare function loadFeatureFlags(): Promise<IFeatureFlagsAttributes>;
@@ -1,5 +1,44 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
1
2
  import { urls } from "../constants";
2
3
  import { Get } from "../fetch";
4
+ const defaultFeatureFlags = {
5
+ flags: {}
6
+ };
7
+ export class FeatureFlags {
8
+ constructor() {
9
+ this._flags = defaultFeatureFlags.flags;
10
+ }
11
+
12
+ static getInstance(name = "default") {
13
+ return this._instances[name];
14
+ }
15
+
16
+ static set(featureFlags, name = "default") {
17
+ const featureFlagsInstance = new FeatureFlags();
18
+ featureFlagsInstance.set(featureFlags);
19
+ FeatureFlags._instances[name] = featureFlagsInstance;
20
+ return featureFlagsInstance;
21
+ }
22
+
23
+ static getFeatureFlags(flags) {
24
+ const featureFlagsInstance = this.getInstance();
25
+ return flags.map(flag => (featureFlagsInstance == null ? void 0 : featureFlagsInstance._flags[flag]) === "on");
26
+ }
27
+
28
+ get flags() {
29
+ var _this$flags;
30
+
31
+ return (_this$flags = this.flags) != null ? _this$flags : {};
32
+ }
33
+
34
+ set(featureFlags) {
35
+ var _defaultFeatureFlags$, _featureFlags$flags;
36
+
37
+ this._flags = _extends({}, (_defaultFeatureFlags$ = defaultFeatureFlags == null ? void 0 : defaultFeatureFlags.flags) != null ? _defaultFeatureFlags$ : {}, (_featureFlags$flags = featureFlags == null ? void 0 : featureFlags.flags) != null ? _featureFlags$flags : {});
38
+ }
39
+
40
+ }
41
+ FeatureFlags._instances = {};
3
42
  export async function loadFeatureFlags() {
4
43
  return Get(urls.featureFlags.v1);
5
44
  }
@@ -1,2 +1,5 @@
1
1
  export declare type IFeatureFlagsAttribute = 'on' | 'off';
2
2
  export declare type IFeatureFlagsAttributes = Record<string, IFeatureFlagsAttribute>;
3
+ export declare type FronteggFeatureFlags = {
4
+ flags?: IFeatureFlagsAttributes;
5
+ };
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v3.0.83
1
+ /** @license Frontegg v3.0.84
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
@@ -1,14 +1,61 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
3
5
  Object.defineProperty(exports, "__esModule", {
4
6
  value: true
5
7
  });
8
+ exports.FeatureFlags = void 0;
6
9
  exports.loadFeatureFlags = loadFeatureFlags;
7
10
 
11
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
12
+
8
13
  var _constants = require("../constants");
9
14
 
10
15
  var _fetch = require("../fetch");
11
16
 
17
+ const defaultFeatureFlags = {
18
+ flags: {}
19
+ };
20
+
21
+ class FeatureFlags {
22
+ constructor() {
23
+ this._flags = defaultFeatureFlags.flags;
24
+ }
25
+
26
+ static getInstance(name = "default") {
27
+ return this._instances[name];
28
+ }
29
+
30
+ static set(featureFlags, name = "default") {
31
+ const featureFlagsInstance = new FeatureFlags();
32
+ featureFlagsInstance.set(featureFlags);
33
+ FeatureFlags._instances[name] = featureFlagsInstance;
34
+ return featureFlagsInstance;
35
+ }
36
+
37
+ static getFeatureFlags(flags) {
38
+ const featureFlagsInstance = this.getInstance();
39
+ return flags.map(flag => (featureFlagsInstance == null ? void 0 : featureFlagsInstance._flags[flag]) === "on");
40
+ }
41
+
42
+ get flags() {
43
+ var _this$flags;
44
+
45
+ return (_this$flags = this.flags) != null ? _this$flags : {};
46
+ }
47
+
48
+ set(featureFlags) {
49
+ var _defaultFeatureFlags$, _featureFlags$flags;
50
+
51
+ this._flags = (0, _extends2.default)({}, (_defaultFeatureFlags$ = defaultFeatureFlags == null ? void 0 : defaultFeatureFlags.flags) != null ? _defaultFeatureFlags$ : {}, (_featureFlags$flags = featureFlags == null ? void 0 : featureFlags.flags) != null ? _featureFlags$flags : {});
52
+ }
53
+
54
+ }
55
+
56
+ exports.FeatureFlags = FeatureFlags;
57
+ FeatureFlags._instances = {};
58
+
12
59
  async function loadFeatureFlags() {
13
60
  return (0, _fetch.Get)(_constants.urls.featureFlags.v1);
14
61
  }
package/node/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v3.0.83
1
+ /** @license Frontegg v3.0.84
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frontegg/rest-api",
3
- "version": "3.0.83",
3
+ "version": "3.0.84",
4
4
  "main": "./node/index.js",
5
5
  "license": "MIT",
6
6
  "dependencies": {