@forge/bridge
5.14.0-next.45.14.0-next.5
out/featureFlags/featureFlags.js~
out/featureFlags/featureFlags.jsModified+17−39
Index: package/out/featureFlags/featureFlags.js
===================================================================
--- package/out/featureFlags/featureFlags.js
+++ package/out/featureFlags/featureFlags.js
@@ -1,65 +1,43 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
-exports.ForgeFeatureFlags = void 0;
-const js_client_1 = require("@statsig/js-client");
-const dataAdapter_1 = require("./dataAdapter");
-const types_1 = require("../types");
+exports.FeatureFlags = void 0;
+const evaluator_1 = require("./evaluator");
const featureFlagEvents_1 = require("./featureFlagEvents");
-class ForgeFeatureFlags {
+const initFeatureFlags_1 = require("./initFeatureFlags");
+const types_1 = require("./types");
+class FeatureFlags {
constructor() {
this.initialized = false;
- this.client = null;
- this.dataAdapter = null;
this.eventProps = {};
- this.CLIENT_KEY = 'client-forge-internal-key';
}
- async initialize(user, config = {}) {
- var _a;
+ async initialize(user, config = { environment: 'development' }) {
if (this.isInitialized()) {
return;
}
- this.dataAdapter = new dataAdapter_1.ForgeDataAdapter();
- const options = {
- environment: { tier: config.environment || 'development' },
- disableEvaluationMemoization: false,
- loggingEnabled: js_client_1.LoggingEnabledOption.disabled,
- logLevel: js_client_1.LogLevel.None,
- dataAdapter: this.dataAdapter
- };
- this.eventProps.environment = (_a = options.environment) === null || _a === void 0 ? void 0 : _a.tier;
- this.client = new js_client_1.StatsigClient(this.CLIENT_KEY, this.convertUser(user), options);
- await this.client.initializeAsync();
+ this.eventProps.environment = config.environment;
+ const result = await (0, initFeatureFlags_1.initFeatureFlags)({ user, config });
this.initialized = true;
+ this.evaluator = new evaluator_1.Evaluator(result);
}
- checkFlag(flagName) {
- if (!this.isInitialized() || !this.client) {
+ checkFlag(flagName, defaultValue = false) {
+ if (!this.isInitialized() || !this.evaluator) {
this.sendCheckFlagEvent(flagName, false);
- throw new Error('ForgeFeatureFlags not initialized. Call initialize() first.');
+ throw new Error('FeatureFlags not initialized. Call initialize() first.');
}
this.sendCheckFlagEvent(flagName, true);
- return this.client.checkGate(flagName, { disableExposureLog: true });
+ return this.evaluator.checkFlag(flagName, defaultValue);
}
- async shutdown() {
- if (!this.isInitialized() || !this.client) {
+ shutdown() {
+ if (!this.isInitialized()) {
return;
}
- await this.client.shutdown();
- if (this.dataAdapter) {
- await this.dataAdapter.shutdown();
- }
this.initialized = false;
+ this.evaluator.shutDown();
}
isInitialized() {
return this.initialized;
}
- convertUser(user) {
- return {
- userID: user.userId,
- custom: { ...(user.custom || {}), ...(user.attributes || {}) },
- customIDs: user.identifiers || {}
- };
- }
sendCheckFlagEvent(flagName, success) {
const props = {
type: types_1.FeatureFlagEventType.CHECKFLAG,
properties: {
@@ -71,5 +49,5 @@
};
void (0, featureFlagEvents_1.trackFeatureFlagEvent)(props);
}
}
-exports.ForgeFeatureFlags = ForgeFeatureFlags;
+exports.FeatureFlags = FeatureFlags;