npm package diff
Package: @forge/cli-shared
Versions: 6.6.2-next.2 - 6.6.2-next.3
File: package/out/service/feature-flag-service.js
Index: package/out/service/feature-flag-service.js
===================================================================
--- package/out/service/feature-flag-service.js
+++ package/out/service/feature-flag-service.js
@@ -1,120 +0,0 @@
-"use strict";
-Object.defineProperty(exports, "__esModule", { value: true });
-exports.MockFeatureFlagReader = exports.FeatureFlagService = exports.cachedMethod = exports.FeatureFlagReader = void 0;
-const tslib_1 = require("tslib");
-const launchdarkly_node_client_sdk_1 = tslib_1.__importStar(require("launchdarkly-node-client-sdk"));
-const graphql_1 = require("../graphql");
-class FeatureFlagReader {
- async isAtlasProductSupported() {
- return (await this.readFlag('forge-cli-enable-atlas-product-support')) ?? false;
- }
- async isLogsV2ApiEnabled() {
- return (await this.readFlag('is-logs-v-2-api-enabled')) ?? true;
- }
-}
-exports.FeatureFlagReader = FeatureFlagReader;
-var CLIENT_SIDE_ID;
-(function (CLIENT_SIDE_ID) {
- CLIENT_SIDE_ID["DEV"] = "5d22bfb52c6a0707aac5be90";
- CLIENT_SIDE_ID["STG"] = "5d1eed1f47274b07674b9395";
- CLIENT_SIDE_ID["PROD"] = "5d1eecfe47274b07674b938f";
- CLIENT_SIDE_ID["FEDRAMP_MODERATE_STAGING"] = "";
- CLIENT_SIDE_ID["FEDRAMP_MODERATE_PROD"] = "";
-})(CLIENT_SIDE_ID || (CLIENT_SIDE_ID = {}));
-function cachedMethod(getter) {
- const cacheDict = new Map();
- return async function () {
- const cached = cacheDict.get(this);
- if (cached !== undefined) {
- return cached;
- }
- const value = await getter.call(this);
- cacheDict.set(this, value);
- return value;
- };
-}
-exports.cachedMethod = cachedMethod;
-class FeatureFlagService extends FeatureFlagReader {
- logger;
- cliDetails;
- credentialStore;
- appConfigReader;
- getEnvironmentFn;
- initializeLD;
- constructor(logger, cliDetails, credentialStore, appConfigReader, getEnvironmentFn = graphql_1.getEnvironmentConfig, initializeLD = launchdarkly_node_client_sdk_1.default.initialize) {
- super();
- this.logger = logger;
- this.cliDetails = cliDetails;
- this.credentialStore = credentialStore;
- this.appConfigReader = appConfigReader;
- this.getEnvironmentFn = getEnvironmentFn;
- this.initializeLD = initializeLD;
- }
- appID = cachedMethod(async () => {
- try {
- const config = await this.appConfigReader.readConfigSection();
- return config == 'missing' || config == 'invalid' ? null : config.id;
- }
- catch (e) {
- return null;
- }
- });
- context = cachedMethod(async () => {
- const context = {
- kind: 'user',
- anonymous: true,
- key: 'anonymous'
- };
- try {
- const { accountId } = await this.credentialStore.getCredentials();
- if (accountId) {
- context.key = accountId;
- }
- }
- catch { }
- const appID = await this.appID();
- if (appID) {
- context.appID = appID.split('/')[1];
- }
- if (this.cliDetails) {
- context.version = this.cliDetails.version;
- }
- return context;
- });
- client = cachedMethod(async () => {
- const clientSideID = this.getEnvironmentFn(CLIENT_SIDE_ID);
- const context = await this.context();
- const options = {
- logger: (0, launchdarkly_node_client_sdk_1.basicLogger)({ level: 'error' }),
- sendEvents: false
- };
- return this.initializeLD(clientSideID, context, options);
- });
- async readFlag(flag) {
- if ((0, graphql_1.isFedrampEnv)()) {
- this.logger.debug(`Feature flag ${flag} is not available in FedRAMP environments.`);
- return false;
- }
- try {
- const client = await this.client();
- await client.waitUntilReady();
- return client.variation(flag, null);
- }
- catch (e) {
- this.logger.error(new Error('Failed to read feature flags. Proceeding with defaults.'));
- return null;
- }
- }
-}
-exports.FeatureFlagService = FeatureFlagService;
-class MockFeatureFlagReader extends FeatureFlagReader {
- featureFlags;
- constructor(featureFlags = undefined) {
- super();
- this.featureFlags = featureFlags;
- }
- async readFlag(flag) {
- return this.featureFlags?.[flag] || null;
- }
-}
-exports.MockFeatureFlagReader = MockFeatureFlagReader;