@commercetools-frontend/application-config 20.10.4 → 20.10.6
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.
|
@@ -59,9 +59,9 @@ var uniq__default = /*#__PURE__*/_interopDefault(uniq);
|
|
|
59
59
|
var _trimInstanceProperty__default = /*#__PURE__*/_interopDefault(_trimInstanceProperty);
|
|
60
60
|
var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
|
|
61
61
|
|
|
62
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = _Reflect$construct__default[
|
|
62
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = _Reflect$construct__default["default"](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
63
63
|
|
|
64
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct__default[
|
|
64
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct__default["default"]) return false; if (_Reflect$construct__default["default"].sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct__default["default"](Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
65
65
|
|
|
66
66
|
var MissingOrInvalidConfigError = /*#__PURE__*/function (_Error) {
|
|
67
67
|
_inherits(MissingOrInvalidConfigError, _Error);
|
|
@@ -75,7 +75,7 @@ var MissingOrInvalidConfigError = /*#__PURE__*/function (_Error) {
|
|
|
75
75
|
|
|
76
76
|
_this = _super.call(this, message);
|
|
77
77
|
|
|
78
|
-
_Object$defineProperty__default[
|
|
78
|
+
_Object$defineProperty__default["default"](_assertThisInitialized(_this), 'name', {
|
|
79
79
|
value: 'MissingOrInvalidConfigError'
|
|
80
80
|
});
|
|
81
81
|
|
|
@@ -88,26 +88,26 @@ var MissingOrInvalidConfigError = /*#__PURE__*/function (_Error) {
|
|
|
88
88
|
// for instance in respect to both source files and dist files.
|
|
89
89
|
|
|
90
90
|
var findPackageRootPath = function findPackageRootPath(dir) {
|
|
91
|
-
var packageJsonPath = path__default[
|
|
91
|
+
var packageJsonPath = path__default["default"].join(dir, 'package.json');
|
|
92
92
|
|
|
93
|
-
if (fs__default[
|
|
93
|
+
if (fs__default["default"].existsSync(packageJsonPath)) {
|
|
94
94
|
return dir;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
var parentDir = path__default[
|
|
97
|
+
var parentDir = path__default["default"].join(dir, '..');
|
|
98
98
|
return findPackageRootPath(parentDir);
|
|
99
99
|
};
|
|
100
100
|
|
|
101
101
|
var loadJsModule = function loadJsModule(filePath) {
|
|
102
102
|
var packageRootPath = findPackageRootPath( // Start from the parent folder
|
|
103
|
-
path__default[
|
|
103
|
+
path__default["default"].join(__dirname, '..')); // Load the JS module using a child process. This is primarly to avoid
|
|
104
104
|
// unwanted behaviors using `@babel/register` in the main process.
|
|
105
105
|
// The loader script does the actual `require` of the given `filePath`
|
|
106
106
|
// and uses `@babel/register` to correctly parse and execute the file.
|
|
107
107
|
// The "required module output" is then written into `stdout` and parsed
|
|
108
108
|
// as JSON.
|
|
109
109
|
|
|
110
|
-
var output = child_process.execFileSync(path__default[
|
|
110
|
+
var output = child_process.execFileSync(path__default["default"].join(packageRootPath, 'scripts/load-js-module.js'), [filePath], {
|
|
111
111
|
encoding: 'utf8'
|
|
112
112
|
});
|
|
113
113
|
return JSON.parse(output);
|
|
@@ -457,7 +457,7 @@ var schemaJson = {
|
|
|
457
457
|
]
|
|
458
458
|
};
|
|
459
459
|
|
|
460
|
-
var ajv = new Ajv__default[
|
|
460
|
+
var ajv = new Ajv__default["default"]({
|
|
461
461
|
strict: true,
|
|
462
462
|
useDefaults: true
|
|
463
463
|
});
|
|
@@ -468,17 +468,17 @@ var printErrors = function printErrors(errors) {
|
|
|
468
468
|
return 'No errors';
|
|
469
469
|
}
|
|
470
470
|
|
|
471
|
-
return _mapInstanceProperty__default[
|
|
471
|
+
return _mapInstanceProperty__default["default"](errors).call(errors, function (error) {
|
|
472
472
|
var _context, _context2, _context3;
|
|
473
473
|
|
|
474
|
-
var baseMessage = _concatInstanceProperty__default[
|
|
474
|
+
var baseMessage = _concatInstanceProperty__default["default"](_context = "".concat(error.instancePath, " ")).call(_context, error.message);
|
|
475
475
|
|
|
476
476
|
switch (error.keyword) {
|
|
477
477
|
case 'additionalProperties':
|
|
478
|
-
return _concatInstanceProperty__default[
|
|
478
|
+
return _concatInstanceProperty__default["default"](_context2 = "".concat(baseMessage, ": ")).call(_context2, error.params.additionalProperty);
|
|
479
479
|
|
|
480
480
|
case 'enum':
|
|
481
|
-
return _concatInstanceProperty__default[
|
|
481
|
+
return _concatInstanceProperty__default["default"](_context3 = "".concat(baseMessage, ": ")).call(_context3, error.params.allowedValues.toString());
|
|
482
482
|
|
|
483
483
|
default:
|
|
484
484
|
return baseMessage;
|
|
@@ -531,7 +531,7 @@ var mapCloudIdentifierToApiUrl = function mapCloudIdentifierToApiUrl(key) {
|
|
|
531
531
|
default:
|
|
532
532
|
// We would probably never get to this point, as the JSON schema validation
|
|
533
533
|
// kicks in before.
|
|
534
|
-
throw new Error(_concatInstanceProperty__default[
|
|
534
|
+
throw new Error(_concatInstanceProperty__default["default"](_context = "Unknown cloud identifier \"".concat(key, "\". Supported values: ")).call(_context, _Object$values__default["default"](CLOUD_IDENTIFIERS).toString()));
|
|
535
535
|
}
|
|
536
536
|
};
|
|
537
537
|
|
|
@@ -540,7 +540,7 @@ var getUniqueValues = function getUniqueValues() {
|
|
|
540
540
|
|
|
541
541
|
var initialValues = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
542
542
|
var additionalValues = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
543
|
-
return uniq__default[
|
|
543
|
+
return uniq__default["default"](_concatInstanceProperty__default["default"](_context2 = []).call(_context2, _toConsumableArray(initialValues), _toConsumableArray(additionalValues)));
|
|
544
544
|
};
|
|
545
545
|
|
|
546
546
|
var nonProductionEnvironment = ['development', 'test'];
|
|
@@ -550,7 +550,7 @@ var getIsProd = function getIsProd(env) {
|
|
|
550
550
|
// a production environment unless it's one of `development` or `test`.
|
|
551
551
|
// This allows to use for example the `staging` value, which from the
|
|
552
552
|
// application perspective is still considered a production environment.
|
|
553
|
-
env.MC_APP_ENV ? !_includesInstanceProperty__default[
|
|
553
|
+
env.MC_APP_ENV ? !_includesInstanceProperty__default["default"](nonProductionEnvironment).call(nonProductionEnvironment, env.MC_APP_ENV) : env.NODE_ENV === 'production'
|
|
554
554
|
);
|
|
555
555
|
};
|
|
556
556
|
|
|
@@ -605,7 +605,7 @@ var substituteEnvVariablePlaceholder = function substituteEnvVariablePlaceholder
|
|
|
605
605
|
if (!hasEnvField) {
|
|
606
606
|
var _context;
|
|
607
607
|
|
|
608
|
-
throw new Error(_concatInstanceProperty__default[
|
|
608
|
+
throw new Error(_concatInstanceProperty__default["default"](_context = "Missing environment variable '".concat(requestedEnvVar, "' specified in config as 'env:")).call(_context, requestedEnvVar, "'."));
|
|
609
609
|
}
|
|
610
610
|
|
|
611
611
|
var escapedMatchedString = matchedString.replace(/[${}:]/g, '\\$&');
|
|
@@ -629,7 +629,7 @@ var substituteIntlVariablePlaceholder = function substituteIntlVariablePlacehold
|
|
|
629
629
|
if (!hasIntlMessage) {
|
|
630
630
|
var _context2, _context3;
|
|
631
631
|
|
|
632
|
-
throw new Error(_concatInstanceProperty__default[
|
|
632
|
+
throw new Error(_concatInstanceProperty__default["default"](_context2 = _concatInstanceProperty__default["default"](_context3 = "Missing message key '".concat(requestedIntlMessageId, "' specified in config as 'intl:")).call(_context3, locale, ":")).call(_context2, requestedIntlMessageId, "'."));
|
|
633
633
|
}
|
|
634
634
|
|
|
635
635
|
var escapedMatchedString = matchedString.replace(/[${}:]/g, '\\$&');
|
|
@@ -641,7 +641,7 @@ var substituteFilePathVariablePlaceholder = function substituteFilePathVariableP
|
|
|
641
641
|
_valueOfPlaceholder$s6 = _slicedToArray(_valueOfPlaceholder$s5, 2),
|
|
642
642
|
filePathOrModule = _valueOfPlaceholder$s6[1];
|
|
643
643
|
|
|
644
|
-
var content = fs__default[
|
|
644
|
+
var content = fs__default["default"].readFileSync(require.resolve(filePathOrModule, {
|
|
645
645
|
// Relative paths should be resolved from the application folder.
|
|
646
646
|
paths: [meta.applicationPath]
|
|
647
647
|
}), {
|
|
@@ -653,12 +653,12 @@ var substituteFilePathVariablePlaceholder = function substituteFilePathVariableP
|
|
|
653
653
|
|
|
654
654
|
var getValueOfPlaceholder = function getValueOfPlaceholder(valueWithPlaceholder) {
|
|
655
655
|
return valueWithPlaceholder.replace(variableSyntax, function (_match, varName) {
|
|
656
|
-
return _trimInstanceProperty__default[
|
|
656
|
+
return _trimInstanceProperty__default["default"](varName).call(varName);
|
|
657
657
|
}).replace(/\s/g, '');
|
|
658
658
|
};
|
|
659
659
|
|
|
660
660
|
var substituteVariablePlaceholders = function substituteVariablePlaceholders(config, meta) {
|
|
661
|
-
return JSON.parse(_JSON$stringify__default[
|
|
661
|
+
return JSON.parse(_JSON$stringify__default["default"](config), function (_key, value) {
|
|
662
662
|
// Only strings are allowed
|
|
663
663
|
var substitutedValue = value;
|
|
664
664
|
|
|
@@ -666,7 +666,7 @@ var substituteVariablePlaceholders = function substituteVariablePlaceholders(con
|
|
|
666
666
|
var matchResult = substitutedValue.match(variableSyntax);
|
|
667
667
|
|
|
668
668
|
if (matchResult) {
|
|
669
|
-
_forEachInstanceProperty__default[
|
|
669
|
+
_forEachInstanceProperty__default["default"](matchResult).call(matchResult, function (matchedString) {
|
|
670
670
|
var valueOfPlaceholder = getValueOfPlaceholder(matchedString);
|
|
671
671
|
|
|
672
672
|
if (isEnvVariablePlaceholder(valueOfPlaceholder)) {
|
|
@@ -684,9 +684,9 @@ var substituteVariablePlaceholders = function substituteVariablePlaceholders(con
|
|
|
684
684
|
});
|
|
685
685
|
};
|
|
686
686
|
|
|
687
|
-
function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default[
|
|
687
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); if (enumerableOnly) { symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
688
688
|
|
|
689
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context3; _forEachInstanceProperty__default[
|
|
689
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context3; _forEachInstanceProperty__default["default"](_context3 = ownKeys(Object(source), true)).call(_context3, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors__default["default"]) { _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)); } else { var _context4; _forEachInstanceProperty__default["default"](_context4 = ownKeys(Object(source))).call(_context4, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } } return target; }
|
|
690
690
|
// TODO: make it configurable.
|
|
691
691
|
var developmentPort = 3001;
|
|
692
692
|
var developmentAppUrl = "http://localhost:".concat(developmentPort);
|
|
@@ -710,7 +710,7 @@ var processConfig = function processConfig() {
|
|
|
710
710
|
_ref$processEnv = _ref.processEnv,
|
|
711
711
|
processEnv = _ref$processEnv === void 0 ? process.env : _ref$processEnv,
|
|
712
712
|
_ref$applicationPath = _ref.applicationPath,
|
|
713
|
-
applicationPath = _ref$applicationPath === void 0 ? fs__default[
|
|
713
|
+
applicationPath = _ref$applicationPath === void 0 ? fs__default["default"].realpathSync(process.cwd()) : _ref$applicationPath;
|
|
714
714
|
|
|
715
715
|
if (cachedConfig && !disableCache) return cachedConfig;
|
|
716
716
|
var appEnvKey = (_ref2 = (_processEnv$MC_APP_EN = processEnv.MC_APP_ENV) !== null && _processEnv$MC_APP_EN !== void 0 ? _processEnv$MC_APP_EN : processEnv.NODE_ENV) !== null && _ref2 !== void 0 ? _ref2 : 'development';
|
|
@@ -729,15 +729,15 @@ var processConfig = function processConfig() {
|
|
|
729
729
|
|
|
730
730
|
var envAppUrl = isProd ? appConfig.env.production.url : developmentAppUrl;
|
|
731
731
|
var appUrl = getOrThrow(function () {
|
|
732
|
-
return new _URL__default[
|
|
732
|
+
return new _URL__default["default"](envAppUrl);
|
|
733
733
|
}, "Invalid application URL: \"".concat(envAppUrl, "\"")); // Use `||` instead of `??` to include empty string values.
|
|
734
734
|
|
|
735
735
|
var envCdnUrl = isProd ? appConfig.env.production.cdnUrl || appUrl.href : developmentAppUrl;
|
|
736
736
|
var cdnUrl = getOrThrow(function () {
|
|
737
|
-
return new _URL__default[
|
|
737
|
+
return new _URL__default["default"](envCdnUrl);
|
|
738
738
|
}, "Invalid application CDN URL: \"".concat(envCdnUrl, "\""));
|
|
739
739
|
var mcApiUrl = getOrThrow(function () {
|
|
740
|
-
return new _URL__default[
|
|
740
|
+
return new _URL__default["default"]( // Use `||` instead of `??` to include empty string values.
|
|
741
741
|
appConfig.mcApiUrl || mapCloudIdentifierToApiUrl(appConfig.cloudIdentifier));
|
|
742
742
|
}, "Invalid MC API URL: \"".concat(appConfig.mcApiUrl, "\"")); // The real application ID is only used in production.
|
|
743
743
|
// In development, we prefix the entry point with the "__local" prefix.
|
|
@@ -751,7 +751,7 @@ var processConfig = function processConfig() {
|
|
|
751
751
|
if (appConfig.env.production.applicationId) {
|
|
752
752
|
var _context;
|
|
753
753
|
|
|
754
|
-
applicationId = _concatInstanceProperty__default[
|
|
754
|
+
applicationId = _concatInstanceProperty__default["default"](_context = "".concat(appConfig.env.production.applicationId, ":")).call(_context, appConfig.entryPointUriPath);
|
|
755
755
|
} else {
|
|
756
756
|
// As long as we don't require the application ID in production, we should
|
|
757
757
|
// fall back to unset the value.
|
|
@@ -760,7 +760,7 @@ var processConfig = function processConfig() {
|
|
|
760
760
|
}
|
|
761
761
|
|
|
762
762
|
var developmentConfig = isProd ? undefined : omitDevConfigIfEmpty({
|
|
763
|
-
oidc: isOidcForDevelopmentEnabled ? omitEmpty__default[
|
|
763
|
+
oidc: isOidcForDevelopmentEnabled ? omitEmpty__default["default"]({
|
|
764
764
|
authorizeUrl: [// In case the MC API url points to localhost, we need to point
|
|
765
765
|
// to a local running dev login page to handle the workflow properly.
|
|
766
766
|
mcApiUrl.hostname === 'localhost' ? mcApiUrl.origin.replace(mcApiUrl.port, String(developmentPort)) : mcApiUrl.origin.replace('mc-api', 'mc'), '/login/authorize'].join(''),
|
|
@@ -773,7 +773,7 @@ var processConfig = function processConfig() {
|
|
|
773
773
|
accountLinks: appConfig.accountLinks
|
|
774
774
|
});
|
|
775
775
|
cachedConfig = {
|
|
776
|
-
env: _objectSpread(_objectSpread(_objectSpread({}, omitEmpty__default[
|
|
776
|
+
env: _objectSpread(_objectSpread(_objectSpread({}, omitEmpty__default["default"](additionalAppEnv)), {}, {
|
|
777
777
|
// TODO: how else should we provide the app identifier?
|
|
778
778
|
applicationId: applicationId,
|
|
779
779
|
applicationName: appConfig.name,
|
|
@@ -791,7 +791,7 @@ var processConfig = function processConfig() {
|
|
|
791
791
|
}),
|
|
792
792
|
headers: _objectSpread(_objectSpread({}, appConfig.headers), {}, {
|
|
793
793
|
csp: _objectSpread(_objectSpread({}, (_appConfig$headers = appConfig.headers) === null || _appConfig$headers === void 0 ? void 0 : _appConfig$headers.csp), {}, {
|
|
794
|
-
'connect-src': getUniqueValues((_appConfig$headers2 = appConfig.headers) === null || _appConfig$headers2 === void 0 ? void 0 : _appConfig$headers2.csp['connect-src'], _concatInstanceProperty__default[
|
|
794
|
+
'connect-src': getUniqueValues((_appConfig$headers2 = appConfig.headers) === null || _appConfig$headers2 === void 0 ? void 0 : _appConfig$headers2.csp['connect-src'], _concatInstanceProperty__default["default"](_context2 = [mcApiUrl.origin]).call(_context2, isProd ? [appUrl.href] : [])),
|
|
795
795
|
'script-src': getUniqueValues((_appConfig$headers3 = appConfig.headers) === null || _appConfig$headers3 === void 0 ? void 0 : _appConfig$headers3.csp['script-src'], isProd ? [appUrl.href, cdnUrl.href] : []),
|
|
796
796
|
'style-src': getUniqueValues((_appConfig$headers4 = appConfig.headers) === null || _appConfig$headers4 === void 0 ? void 0 : _appConfig$headers4.csp['style-src'], isProd ? [appUrl.href, cdnUrl.href] : [])
|
|
797
797
|
})
|
|
@@ -59,9 +59,9 @@ var uniq__default = /*#__PURE__*/_interopDefault(uniq);
|
|
|
59
59
|
var _trimInstanceProperty__default = /*#__PURE__*/_interopDefault(_trimInstanceProperty);
|
|
60
60
|
var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
|
|
61
61
|
|
|
62
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = _Reflect$construct__default[
|
|
62
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = _Reflect$construct__default["default"](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
63
63
|
|
|
64
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct__default[
|
|
64
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct__default["default"]) return false; if (_Reflect$construct__default["default"].sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct__default["default"](Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
65
65
|
|
|
66
66
|
var MissingOrInvalidConfigError = /*#__PURE__*/function (_Error) {
|
|
67
67
|
_inherits(MissingOrInvalidConfigError, _Error);
|
|
@@ -75,7 +75,7 @@ var MissingOrInvalidConfigError = /*#__PURE__*/function (_Error) {
|
|
|
75
75
|
|
|
76
76
|
_this = _super.call(this, message);
|
|
77
77
|
|
|
78
|
-
_Object$defineProperty__default[
|
|
78
|
+
_Object$defineProperty__default["default"](_assertThisInitialized(_this), 'name', {
|
|
79
79
|
value: 'MissingOrInvalidConfigError'
|
|
80
80
|
});
|
|
81
81
|
|
|
@@ -88,26 +88,26 @@ var MissingOrInvalidConfigError = /*#__PURE__*/function (_Error) {
|
|
|
88
88
|
// for instance in respect to both source files and dist files.
|
|
89
89
|
|
|
90
90
|
var findPackageRootPath = function findPackageRootPath(dir) {
|
|
91
|
-
var packageJsonPath = path__default[
|
|
91
|
+
var packageJsonPath = path__default["default"].join(dir, 'package.json');
|
|
92
92
|
|
|
93
|
-
if (fs__default[
|
|
93
|
+
if (fs__default["default"].existsSync(packageJsonPath)) {
|
|
94
94
|
return dir;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
var parentDir = path__default[
|
|
97
|
+
var parentDir = path__default["default"].join(dir, '..');
|
|
98
98
|
return findPackageRootPath(parentDir);
|
|
99
99
|
};
|
|
100
100
|
|
|
101
101
|
var loadJsModule = function loadJsModule(filePath) {
|
|
102
102
|
var packageRootPath = findPackageRootPath( // Start from the parent folder
|
|
103
|
-
path__default[
|
|
103
|
+
path__default["default"].join(__dirname, '..')); // Load the JS module using a child process. This is primarly to avoid
|
|
104
104
|
// unwanted behaviors using `@babel/register` in the main process.
|
|
105
105
|
// The loader script does the actual `require` of the given `filePath`
|
|
106
106
|
// and uses `@babel/register` to correctly parse and execute the file.
|
|
107
107
|
// The "required module output" is then written into `stdout` and parsed
|
|
108
108
|
// as JSON.
|
|
109
109
|
|
|
110
|
-
var output = child_process.execFileSync(path__default[
|
|
110
|
+
var output = child_process.execFileSync(path__default["default"].join(packageRootPath, 'scripts/load-js-module.js'), [filePath], {
|
|
111
111
|
encoding: 'utf8'
|
|
112
112
|
});
|
|
113
113
|
return JSON.parse(output);
|
|
@@ -457,7 +457,7 @@ var schemaJson = {
|
|
|
457
457
|
]
|
|
458
458
|
};
|
|
459
459
|
|
|
460
|
-
var ajv = new Ajv__default[
|
|
460
|
+
var ajv = new Ajv__default["default"]({
|
|
461
461
|
strict: true,
|
|
462
462
|
useDefaults: true
|
|
463
463
|
});
|
|
@@ -468,17 +468,17 @@ var printErrors = function printErrors(errors) {
|
|
|
468
468
|
return 'No errors';
|
|
469
469
|
}
|
|
470
470
|
|
|
471
|
-
return _mapInstanceProperty__default[
|
|
471
|
+
return _mapInstanceProperty__default["default"](errors).call(errors, function (error) {
|
|
472
472
|
var _context, _context2, _context3;
|
|
473
473
|
|
|
474
|
-
var baseMessage = _concatInstanceProperty__default[
|
|
474
|
+
var baseMessage = _concatInstanceProperty__default["default"](_context = "".concat(error.instancePath, " ")).call(_context, error.message);
|
|
475
475
|
|
|
476
476
|
switch (error.keyword) {
|
|
477
477
|
case 'additionalProperties':
|
|
478
|
-
return _concatInstanceProperty__default[
|
|
478
|
+
return _concatInstanceProperty__default["default"](_context2 = "".concat(baseMessage, ": ")).call(_context2, error.params.additionalProperty);
|
|
479
479
|
|
|
480
480
|
case 'enum':
|
|
481
|
-
return _concatInstanceProperty__default[
|
|
481
|
+
return _concatInstanceProperty__default["default"](_context3 = "".concat(baseMessage, ": ")).call(_context3, error.params.allowedValues.toString());
|
|
482
482
|
|
|
483
483
|
default:
|
|
484
484
|
return baseMessage;
|
|
@@ -531,7 +531,7 @@ var mapCloudIdentifierToApiUrl = function mapCloudIdentifierToApiUrl(key) {
|
|
|
531
531
|
default:
|
|
532
532
|
// We would probably never get to this point, as the JSON schema validation
|
|
533
533
|
// kicks in before.
|
|
534
|
-
throw new Error(_concatInstanceProperty__default[
|
|
534
|
+
throw new Error(_concatInstanceProperty__default["default"](_context = "Unknown cloud identifier \"".concat(key, "\". Supported values: ")).call(_context, _Object$values__default["default"](CLOUD_IDENTIFIERS).toString()));
|
|
535
535
|
}
|
|
536
536
|
};
|
|
537
537
|
|
|
@@ -540,7 +540,7 @@ var getUniqueValues = function getUniqueValues() {
|
|
|
540
540
|
|
|
541
541
|
var initialValues = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
542
542
|
var additionalValues = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
543
|
-
return uniq__default[
|
|
543
|
+
return uniq__default["default"](_concatInstanceProperty__default["default"](_context2 = []).call(_context2, _toConsumableArray(initialValues), _toConsumableArray(additionalValues)));
|
|
544
544
|
};
|
|
545
545
|
|
|
546
546
|
var nonProductionEnvironment = ['development', 'test'];
|
|
@@ -550,7 +550,7 @@ var getIsProd = function getIsProd(env) {
|
|
|
550
550
|
// a production environment unless it's one of `development` or `test`.
|
|
551
551
|
// This allows to use for example the `staging` value, which from the
|
|
552
552
|
// application perspective is still considered a production environment.
|
|
553
|
-
env.MC_APP_ENV ? !_includesInstanceProperty__default[
|
|
553
|
+
env.MC_APP_ENV ? !_includesInstanceProperty__default["default"](nonProductionEnvironment).call(nonProductionEnvironment, env.MC_APP_ENV) : env.NODE_ENV === 'production'
|
|
554
554
|
);
|
|
555
555
|
};
|
|
556
556
|
|
|
@@ -605,7 +605,7 @@ var substituteEnvVariablePlaceholder = function substituteEnvVariablePlaceholder
|
|
|
605
605
|
if (!hasEnvField) {
|
|
606
606
|
var _context;
|
|
607
607
|
|
|
608
|
-
throw new Error(_concatInstanceProperty__default[
|
|
608
|
+
throw new Error(_concatInstanceProperty__default["default"](_context = "Missing environment variable '".concat(requestedEnvVar, "' specified in config as 'env:")).call(_context, requestedEnvVar, "'."));
|
|
609
609
|
}
|
|
610
610
|
|
|
611
611
|
var escapedMatchedString = matchedString.replace(/[${}:]/g, '\\$&');
|
|
@@ -629,7 +629,7 @@ var substituteIntlVariablePlaceholder = function substituteIntlVariablePlacehold
|
|
|
629
629
|
if (!hasIntlMessage) {
|
|
630
630
|
var _context2, _context3;
|
|
631
631
|
|
|
632
|
-
throw new Error(_concatInstanceProperty__default[
|
|
632
|
+
throw new Error(_concatInstanceProperty__default["default"](_context2 = _concatInstanceProperty__default["default"](_context3 = "Missing message key '".concat(requestedIntlMessageId, "' specified in config as 'intl:")).call(_context3, locale, ":")).call(_context2, requestedIntlMessageId, "'."));
|
|
633
633
|
}
|
|
634
634
|
|
|
635
635
|
var escapedMatchedString = matchedString.replace(/[${}:]/g, '\\$&');
|
|
@@ -641,7 +641,7 @@ var substituteFilePathVariablePlaceholder = function substituteFilePathVariableP
|
|
|
641
641
|
_valueOfPlaceholder$s6 = _slicedToArray(_valueOfPlaceholder$s5, 2),
|
|
642
642
|
filePathOrModule = _valueOfPlaceholder$s6[1];
|
|
643
643
|
|
|
644
|
-
var content = fs__default[
|
|
644
|
+
var content = fs__default["default"].readFileSync(require.resolve(filePathOrModule, {
|
|
645
645
|
// Relative paths should be resolved from the application folder.
|
|
646
646
|
paths: [meta.applicationPath]
|
|
647
647
|
}), {
|
|
@@ -653,12 +653,12 @@ var substituteFilePathVariablePlaceholder = function substituteFilePathVariableP
|
|
|
653
653
|
|
|
654
654
|
var getValueOfPlaceholder = function getValueOfPlaceholder(valueWithPlaceholder) {
|
|
655
655
|
return valueWithPlaceholder.replace(variableSyntax, function (_match, varName) {
|
|
656
|
-
return _trimInstanceProperty__default[
|
|
656
|
+
return _trimInstanceProperty__default["default"](varName).call(varName);
|
|
657
657
|
}).replace(/\s/g, '');
|
|
658
658
|
};
|
|
659
659
|
|
|
660
660
|
var substituteVariablePlaceholders = function substituteVariablePlaceholders(config, meta) {
|
|
661
|
-
return JSON.parse(_JSON$stringify__default[
|
|
661
|
+
return JSON.parse(_JSON$stringify__default["default"](config), function (_key, value) {
|
|
662
662
|
// Only strings are allowed
|
|
663
663
|
var substitutedValue = value;
|
|
664
664
|
|
|
@@ -666,7 +666,7 @@ var substituteVariablePlaceholders = function substituteVariablePlaceholders(con
|
|
|
666
666
|
var matchResult = substitutedValue.match(variableSyntax);
|
|
667
667
|
|
|
668
668
|
if (matchResult) {
|
|
669
|
-
_forEachInstanceProperty__default[
|
|
669
|
+
_forEachInstanceProperty__default["default"](matchResult).call(matchResult, function (matchedString) {
|
|
670
670
|
var valueOfPlaceholder = getValueOfPlaceholder(matchedString);
|
|
671
671
|
|
|
672
672
|
if (isEnvVariablePlaceholder(valueOfPlaceholder)) {
|
|
@@ -684,9 +684,9 @@ var substituteVariablePlaceholders = function substituteVariablePlaceholders(con
|
|
|
684
684
|
});
|
|
685
685
|
};
|
|
686
686
|
|
|
687
|
-
function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default[
|
|
687
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); if (enumerableOnly) { symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
688
688
|
|
|
689
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context3; _forEachInstanceProperty__default[
|
|
689
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context3; _forEachInstanceProperty__default["default"](_context3 = ownKeys(Object(source), true)).call(_context3, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors__default["default"]) { _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)); } else { var _context4; _forEachInstanceProperty__default["default"](_context4 = ownKeys(Object(source))).call(_context4, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } } return target; }
|
|
690
690
|
// TODO: make it configurable.
|
|
691
691
|
var developmentPort = 3001;
|
|
692
692
|
var developmentAppUrl = "http://localhost:".concat(developmentPort);
|
|
@@ -710,7 +710,7 @@ var processConfig = function processConfig() {
|
|
|
710
710
|
_ref$processEnv = _ref.processEnv,
|
|
711
711
|
processEnv = _ref$processEnv === void 0 ? process.env : _ref$processEnv,
|
|
712
712
|
_ref$applicationPath = _ref.applicationPath,
|
|
713
|
-
applicationPath = _ref$applicationPath === void 0 ? fs__default[
|
|
713
|
+
applicationPath = _ref$applicationPath === void 0 ? fs__default["default"].realpathSync(process.cwd()) : _ref$applicationPath;
|
|
714
714
|
|
|
715
715
|
if (cachedConfig && !disableCache) return cachedConfig;
|
|
716
716
|
var appEnvKey = (_ref2 = (_processEnv$MC_APP_EN = processEnv.MC_APP_ENV) !== null && _processEnv$MC_APP_EN !== void 0 ? _processEnv$MC_APP_EN : processEnv.NODE_ENV) !== null && _ref2 !== void 0 ? _ref2 : 'development';
|
|
@@ -729,15 +729,15 @@ var processConfig = function processConfig() {
|
|
|
729
729
|
|
|
730
730
|
var envAppUrl = isProd ? appConfig.env.production.url : developmentAppUrl;
|
|
731
731
|
var appUrl = getOrThrow(function () {
|
|
732
|
-
return new _URL__default[
|
|
732
|
+
return new _URL__default["default"](envAppUrl);
|
|
733
733
|
}, "Invalid application URL: \"".concat(envAppUrl, "\"")); // Use `||` instead of `??` to include empty string values.
|
|
734
734
|
|
|
735
735
|
var envCdnUrl = isProd ? appConfig.env.production.cdnUrl || appUrl.href : developmentAppUrl;
|
|
736
736
|
var cdnUrl = getOrThrow(function () {
|
|
737
|
-
return new _URL__default[
|
|
737
|
+
return new _URL__default["default"](envCdnUrl);
|
|
738
738
|
}, "Invalid application CDN URL: \"".concat(envCdnUrl, "\""));
|
|
739
739
|
var mcApiUrl = getOrThrow(function () {
|
|
740
|
-
return new _URL__default[
|
|
740
|
+
return new _URL__default["default"]( // Use `||` instead of `??` to include empty string values.
|
|
741
741
|
appConfig.mcApiUrl || mapCloudIdentifierToApiUrl(appConfig.cloudIdentifier));
|
|
742
742
|
}, "Invalid MC API URL: \"".concat(appConfig.mcApiUrl, "\"")); // The real application ID is only used in production.
|
|
743
743
|
// In development, we prefix the entry point with the "__local" prefix.
|
|
@@ -751,7 +751,7 @@ var processConfig = function processConfig() {
|
|
|
751
751
|
if (appConfig.env.production.applicationId) {
|
|
752
752
|
var _context;
|
|
753
753
|
|
|
754
|
-
applicationId = _concatInstanceProperty__default[
|
|
754
|
+
applicationId = _concatInstanceProperty__default["default"](_context = "".concat(appConfig.env.production.applicationId, ":")).call(_context, appConfig.entryPointUriPath);
|
|
755
755
|
} else {
|
|
756
756
|
// As long as we don't require the application ID in production, we should
|
|
757
757
|
// fall back to unset the value.
|
|
@@ -760,7 +760,7 @@ var processConfig = function processConfig() {
|
|
|
760
760
|
}
|
|
761
761
|
|
|
762
762
|
var developmentConfig = isProd ? undefined : omitDevConfigIfEmpty({
|
|
763
|
-
oidc: isOidcForDevelopmentEnabled ? omitEmpty__default[
|
|
763
|
+
oidc: isOidcForDevelopmentEnabled ? omitEmpty__default["default"]({
|
|
764
764
|
authorizeUrl: [// In case the MC API url points to localhost, we need to point
|
|
765
765
|
// to a local running dev login page to handle the workflow properly.
|
|
766
766
|
mcApiUrl.hostname === 'localhost' ? mcApiUrl.origin.replace(mcApiUrl.port, String(developmentPort)) : mcApiUrl.origin.replace('mc-api', 'mc'), '/login/authorize'].join(''),
|
|
@@ -773,7 +773,7 @@ var processConfig = function processConfig() {
|
|
|
773
773
|
accountLinks: appConfig.accountLinks
|
|
774
774
|
});
|
|
775
775
|
cachedConfig = {
|
|
776
|
-
env: _objectSpread(_objectSpread(_objectSpread({}, omitEmpty__default[
|
|
776
|
+
env: _objectSpread(_objectSpread(_objectSpread({}, omitEmpty__default["default"](additionalAppEnv)), {}, {
|
|
777
777
|
// TODO: how else should we provide the app identifier?
|
|
778
778
|
applicationId: applicationId,
|
|
779
779
|
applicationName: appConfig.name,
|
|
@@ -791,7 +791,7 @@ var processConfig = function processConfig() {
|
|
|
791
791
|
}),
|
|
792
792
|
headers: _objectSpread(_objectSpread({}, appConfig.headers), {}, {
|
|
793
793
|
csp: _objectSpread(_objectSpread({}, (_appConfig$headers = appConfig.headers) === null || _appConfig$headers === void 0 ? void 0 : _appConfig$headers.csp), {}, {
|
|
794
|
-
'connect-src': getUniqueValues((_appConfig$headers2 = appConfig.headers) === null || _appConfig$headers2 === void 0 ? void 0 : _appConfig$headers2.csp['connect-src'], _concatInstanceProperty__default[
|
|
794
|
+
'connect-src': getUniqueValues((_appConfig$headers2 = appConfig.headers) === null || _appConfig$headers2 === void 0 ? void 0 : _appConfig$headers2.csp['connect-src'], _concatInstanceProperty__default["default"](_context2 = [mcApiUrl.origin]).call(_context2, isProd ? [appUrl.href] : [])),
|
|
795
795
|
'script-src': getUniqueValues((_appConfig$headers3 = appConfig.headers) === null || _appConfig$headers3 === void 0 ? void 0 : _appConfig$headers3.csp['script-src'], isProd ? [appUrl.href, cdnUrl.href] : []),
|
|
796
796
|
'style-src': getUniqueValues((_appConfig$headers4 = appConfig.headers) === null || _appConfig$headers4 === void 0 ? void 0 : _appConfig$headers4.csp['style-src'], isProd ? [appUrl.href, cdnUrl.href] : [])
|
|
797
797
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools-frontend/application-config",
|
|
3
|
-
"version": "20.10.
|
|
3
|
+
"version": "20.10.6",
|
|
4
4
|
"description": "Configuration utilities for building Custom Applications",
|
|
5
5
|
"bugs": "https://github.com/commercetools/merchant-center-application-kit/issues",
|
|
6
6
|
"repository": {
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
"homepage": "https://docs.commercetools.com/custom-applications",
|
|
12
12
|
"keywords": ["javascript", "frontend", "react", "toolkit", "config"],
|
|
13
13
|
"license": "MIT",
|
|
14
|
-
"private": false,
|
|
15
14
|
"publishConfig": {
|
|
16
15
|
"access": "public"
|
|
17
16
|
},
|
|
@@ -26,15 +25,13 @@
|
|
|
26
25
|
"README.md"
|
|
27
26
|
],
|
|
28
27
|
"scripts": {
|
|
29
|
-
"prepare": "./../../scripts/version.js replace",
|
|
30
|
-
"prebuild": "yarn build:schema",
|
|
31
28
|
"build:schema": "json2ts schema.json src/schema.ts --style.singleQuote --bannerComment '/* eslint-disable prettier/prettier */\n// This file was automatically generated by json-schema-to-typescript.\n// DO NOT MODIFY IT BY HAND. Instead, modify the source schema.json file.'"
|
|
32
29
|
},
|
|
33
30
|
"dependencies": {
|
|
34
31
|
"@babel/register": "7.15.3",
|
|
35
32
|
"@babel/runtime": "7.15.4",
|
|
36
33
|
"@babel/runtime-corejs3": "7.15.4",
|
|
37
|
-
"@commercetools-frontend/babel-preset-mc-app": "20.10.
|
|
34
|
+
"@commercetools-frontend/babel-preset-mc-app": "20.10.6",
|
|
38
35
|
"ajv": "8.6.3",
|
|
39
36
|
"core-js": "3.19.0",
|
|
40
37
|
"cosmiconfig": "7.0.1",
|