UNPKG

@salesforce/core

Version:

Core libraries to interact with SFDX projects, orgs, and APIs.

108 lines 5.27 kB
"use strict"; /* * Copyright (c) 2021, salesforce.com, inc. * All rights reserved. * Licensed under the BSD 3-Clause license. * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ Object.defineProperty(exports, "__esModule", { value: true }); exports.ScratchOrgFeatureDeprecation = void 0; /** * Certain Org Features require a translation or should be deprecated. * Encapsulates feature mappings and deprecated features. */ const ts_types_1 = require("@salesforce/ts-types"); // Local const messages_1 = require("../messages"); ; const messages = new messages_1.Messages('@salesforce/core', 'scratchOrgFeatureDeprecation', new Map([["quantifiedFeatureWithoutQuantityWarning", "The feature %s will be deprecated in a future release. It's been replaced by %s:<value>, which requires you to specify a quantity."], ["mappedFeatureWarning", "The feature %s has been deprecated. It has been replaced with %s in this scratch org create request."], ["deprecatedFeatureWarning", "The feature %s has been deprecated. It has been removed from the list of requested features."]])); const FEATURE_TYPES = { // simpleFeatureMapping holds a set of direct replacement values for features. simpleFeatureMapping: { SALESWAVE: ['DEVELOPMENTWAVE'], SERVICEWAVE: ['DEVELOPMENTWAVE'], }, quantifiedFeatureMapping: {}, deprecatedFeatures: [ 'EXPANDEDSOURCETRACKING', 'LISTCUSTOMSETTINGCREATION', 'AppNavCapabilities', 'CMTRecordManagedDeletion', 'EditInSubtab', 'OldNewRecordFlowConsole', 'OldNewRecordFlowStd', 'DesktopLayoutStandardOff', 'SplitViewOnStandardOff', 'PopOutUtilities', ], }; class ScratchOrgFeatureDeprecation { featureTypes; // Allow override for testing. constructor(options = FEATURE_TYPES) { this.featureTypes = options; this.featureTypes.deprecatedFeatures = this.featureTypes.deprecatedFeatures.map((deprecatedFeature) => deprecatedFeature.toUpperCase()); // Make all of the keys in simpleFeatureMapping upper case. const sfm = {}; Object.keys(this.featureTypes.simpleFeatureMapping).forEach((key) => { sfm[key.toUpperCase()] = this.featureTypes.simpleFeatureMapping[key]; }); this.featureTypes.simpleFeatureMapping = sfm; } /** * Gets list of feature warnings that should be logged * * @param features The requested features. * @returns List of string feature warnings. */ getFeatureWarnings(features) { /* Get warning messages for deprecated features and feature mappings.*/ const featureWarningMessages = []; const requestedFeatures = ((0, ts_types_1.isString)(features) ? features : features.join(';')).toUpperCase(); /* If a public quantified feature is defined without a quantity, throw a warning.*/ Object.keys(this.featureTypes.quantifiedFeatureMapping).forEach((key) => { if (new RegExp(`${key};|${key},|${key}$`, 'i').test(requestedFeatures)) { featureWarningMessages.push(messages.getMessage('quantifiedFeatureWithoutQuantityWarning', [ key, this.featureTypes.quantifiedFeatureMapping[key], ])); } }); /* If a simply mapped feature is defined, log a warning.*/ Object.keys(this.featureTypes.simpleFeatureMapping).forEach((key) => { if (new RegExp(`${key};|${key},|${key}$`, 'i').test(requestedFeatures)) { const tokens = '[' + this.featureTypes.simpleFeatureMapping[key].map((v) => "'" + v + "'").join(',') + ']'; featureWarningMessages.push(messages.getMessage('mappedFeatureWarning', [key, tokens])); } }); /* If a deprecated feature is identified as deprecated, throw a warning.*/ this.featureTypes.deprecatedFeatures.forEach((deprecatedFeature) => { if (requestedFeatures.includes(deprecatedFeature)) { featureWarningMessages.push(messages.getMessage('deprecatedFeatureWarning', [deprecatedFeature])); } }); return featureWarningMessages; } /** * Removes all deprecated features for the organization. * * @param features List of features to filter * @returns feature array with proper mapping. */ filterDeprecatedFeatures(features) { return features.reduce((previousValue, currentValue) => { const feature = currentValue.toUpperCase(); if (this.featureTypes.deprecatedFeatures.includes(feature)) { return previousValue; } else if (this.featureTypes.simpleFeatureMapping[feature]) { /* If a simply mapped feature is specified, then perform the mapping. */ const simpleFeatureMapping = this.featureTypes.simpleFeatureMapping[feature]; return [...previousValue, ...simpleFeatureMapping]; } return [...previousValue, currentValue]; }, []); } } exports.ScratchOrgFeatureDeprecation = ScratchOrgFeatureDeprecation; //# sourceMappingURL=scratchOrgFeatureDeprecation.js.map