@commercetools-frontend/application-config 24.10.0 → 24.12.0
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.
- package/dist/commercetools-frontend-application-config.cjs.dev.js +69 -58
- package/dist/commercetools-frontend-application-config.cjs.prod.js +69 -58
- package/dist/commercetools-frontend-application-config.esm.js +68 -57
- package/dist/{formatters-7f327585.cjs.prod.js → formatters-2a857809.cjs.prod.js} +13 -10
- package/dist/{formatters-882eafa8.esm.js → formatters-80a6c235.esm.js} +12 -10
- package/dist/{formatters-a76b45b9.cjs.dev.js → formatters-a09672cf.cjs.dev.js} +13 -10
- package/package.json +3 -3
- package/ssr/dist/commercetools-frontend-application-config-ssr.cjs.dev.js +2 -1
- package/ssr/dist/commercetools-frontend-application-config-ssr.cjs.prod.js +2 -1
- package/ssr/dist/commercetools-frontend-application-config-ssr.esm.js +2 -1
|
@@ -12,8 +12,8 @@ var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/ob
|
|
|
12
12
|
var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
|
|
13
13
|
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
14
14
|
var _includesInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/includes');
|
|
15
|
-
var _URL = require('@babel/runtime-corejs3/core-js-stable/url');
|
|
16
15
|
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
16
|
+
var _URL = require('@babel/runtime-corejs3/core-js-stable/url');
|
|
17
17
|
var fs$1 = require('node:fs');
|
|
18
18
|
var path = require('node:path');
|
|
19
19
|
var omitEmpty = require('omit-empty-es');
|
|
@@ -35,7 +35,7 @@ var _trimInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/insta
|
|
|
35
35
|
var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
|
|
36
36
|
var _startsWithInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/starts-with');
|
|
37
37
|
var _reduceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
|
|
38
|
-
var formatters = require('./formatters-
|
|
38
|
+
var formatters = require('./formatters-a09672cf.cjs.dev.js');
|
|
39
39
|
var _Set = require('@babel/runtime-corejs3/core-js-stable/set');
|
|
40
40
|
var _Array$isArray = require('@babel/runtime-corejs3/core-js-stable/array/is-array');
|
|
41
41
|
var Ajv = require('ajv');
|
|
@@ -57,8 +57,8 @@ var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_O
|
|
|
57
57
|
var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
|
|
58
58
|
var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
|
|
59
59
|
var _includesInstanceProperty__default = /*#__PURE__*/_interopDefault(_includesInstanceProperty);
|
|
60
|
-
var _URL__default = /*#__PURE__*/_interopDefault(_URL);
|
|
61
60
|
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
61
|
+
var _URL__default = /*#__PURE__*/_interopDefault(_URL);
|
|
62
62
|
var fs__default$1 = /*#__PURE__*/_interopDefault(fs$1);
|
|
63
63
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
64
64
|
var omitEmpty__default = /*#__PURE__*/_interopDefault(omitEmpty);
|
|
@@ -146,10 +146,11 @@ const isDynamicAwaitSupported = () => {
|
|
|
146
146
|
const isEsmModule = async cwd => {
|
|
147
147
|
const packagePath = path__default["default"].join(cwd, 'package.json');
|
|
148
148
|
try {
|
|
149
|
+
var _JSON$parse;
|
|
149
150
|
const packageJSON = await fs__default["default"].readFile(packagePath, {
|
|
150
151
|
encoding: 'utf-8'
|
|
151
152
|
});
|
|
152
|
-
return JSON.parse(packageJSON)
|
|
153
|
+
return ((_JSON$parse = JSON.parse(packageJSON)) === null || _JSON$parse === void 0 ? void 0 : _JSON$parse.type) === 'module';
|
|
153
154
|
} catch (error) {
|
|
154
155
|
return false;
|
|
155
156
|
}
|
|
@@ -169,7 +170,7 @@ const createExplorerFor = async configFileName => {
|
|
|
169
170
|
const loaders = isDynamicAwaitSupported() || (await isEsmModule(process.cwd())) ? cosmiconfig.defaultLoaders : cosmiconfig.defaultLoadersSync;
|
|
170
171
|
return cosmiconfig.cosmiconfig(configFileName, {
|
|
171
172
|
searchStrategy: 'project',
|
|
172
|
-
searchPlaces: [
|
|
173
|
+
searchPlaces: ["".concat(configFileName, ".js"), "".concat(configFileName, ".cjs"), "".concat(configFileName, ".mjs"), "".concat(configFileName, ".ts")],
|
|
173
174
|
loaders: {
|
|
174
175
|
'.js': loaders['.js'],
|
|
175
176
|
'.cjs': loaders['.cjs'],
|
|
@@ -184,9 +185,9 @@ const getConfigPath = async () => {
|
|
|
184
185
|
const customApplicationConfigFile = await customApplicationExplorer.search();
|
|
185
186
|
const customViewConfigFile = await customViewExplorer.search();
|
|
186
187
|
if (!customApplicationConfigFile && !customViewConfigFile) {
|
|
187
|
-
throw new Error(
|
|
188
|
+
throw new Error("Missing or invalid configuration file.");
|
|
188
189
|
}
|
|
189
|
-
return customApplicationConfigFile
|
|
190
|
+
return (customApplicationConfigFile === null || customApplicationConfigFile === void 0 ? void 0 : customApplicationConfigFile.filepath) || (customViewConfigFile === null || customViewConfigFile === void 0 ? void 0 : customViewConfigFile.filepath);
|
|
190
191
|
};
|
|
191
192
|
const loadConfig = async applicationPath => {
|
|
192
193
|
const customApplicationExplorer = await createExplorerFor('custom-application-config');
|
|
@@ -194,10 +195,10 @@ const loadConfig = async applicationPath => {
|
|
|
194
195
|
const customApplicationConfigFile = await customApplicationExplorer.search(applicationPath);
|
|
195
196
|
const customViewConfigFile = await customViewExplorer.search(applicationPath);
|
|
196
197
|
if ((!customApplicationConfigFile || !customApplicationConfigFile.config) && (!customViewConfigFile || !customViewConfigFile.config)) {
|
|
197
|
-
throw new MissingOrInvalidConfigError(
|
|
198
|
+
throw new MissingOrInvalidConfigError("Missing or invalid configuration file.");
|
|
198
199
|
}
|
|
199
200
|
if (customApplicationConfigFile && customViewConfigFile) {
|
|
200
|
-
throw new MissingOrInvalidConfigError(
|
|
201
|
+
throw new MissingOrInvalidConfigError("Found configuration files for both Custom Application and Custom View. Please remove one of them.");
|
|
201
202
|
}
|
|
202
203
|
return customViewConfigFile || customApplicationConfigFile;
|
|
203
204
|
};
|
|
@@ -226,35 +227,37 @@ Boolean(valueOfEnvConfig.match(variableSyntax));
|
|
|
226
227
|
const isEnvVariablePlaceholder = valueOfPlaceholder => Boolean(valueOfPlaceholder.match(envRefSyntax));
|
|
227
228
|
const isIntlVariablePlaceholder = valueOfPlaceholder => Boolean(valueOfPlaceholder.match(intlRefSyntax));
|
|
228
229
|
const isFilePathVariablePlaceholder = valueOfPlaceholder => Boolean(valueOfPlaceholder.match(filePathRefSyntax));
|
|
229
|
-
const isStructuredJson = message => message
|
|
230
|
+
const isStructuredJson = message => (message === null || message === void 0 ? void 0 : message.string) !== undefined;
|
|
230
231
|
const substituteEnvVariablePlaceholder = (valueOfPlaceholder, matchedString, valueOfEnvConfig, loadingOptions) => {
|
|
231
232
|
const _valueOfPlaceholder$s = valueOfPlaceholder.split(':'),
|
|
232
233
|
_valueOfPlaceholder$s2 = _slicedToArray(_valueOfPlaceholder$s, 2),
|
|
233
234
|
requestedEnvVar = _valueOfPlaceholder$s2[1];
|
|
234
235
|
const hasEnvField = loadingOptions.processEnv.hasOwnProperty(requestedEnvVar);
|
|
235
236
|
if (!hasEnvField) {
|
|
236
|
-
|
|
237
|
+
var _context;
|
|
238
|
+
throw new Error(_concatInstanceProperty__default["default"](_context = "Missing environment variable '".concat(requestedEnvVar, "' specified in config as 'env:")).call(_context, requestedEnvVar, "'."));
|
|
237
239
|
}
|
|
238
240
|
const escapedMatchedString = matchedString.replace(/[${}:]/g, '\\$&');
|
|
239
|
-
return valueOfEnvConfig.replace(new RegExp(
|
|
241
|
+
return valueOfEnvConfig.replace(new RegExp("(".concat(escapedMatchedString, ")+"), 'g'), loadingOptions.processEnv[requestedEnvVar]);
|
|
240
242
|
};
|
|
241
243
|
const substituteIntlVariablePlaceholder = (valueOfPlaceholder, matchedString, valueOfEnvConfig, loadingOptions) => {
|
|
242
244
|
const _valueOfPlaceholder$s3 = valueOfPlaceholder.split(':'),
|
|
243
245
|
_valueOfPlaceholder$s4 = _slicedToArray(_valueOfPlaceholder$s3, 3),
|
|
244
246
|
locale = _valueOfPlaceholder$s4[1],
|
|
245
247
|
requestedIntlMessageId = _valueOfPlaceholder$s4[2];
|
|
246
|
-
const translationsFilePath = require.resolve(
|
|
247
|
-
paths: [
|
|
248
|
+
const translationsFilePath = require.resolve("./i18n/data/".concat(locale, ".json"), {
|
|
249
|
+
paths: ["".concat(loadingOptions.applicationPath, "/src"), loadingOptions.applicationPath]
|
|
248
250
|
});
|
|
249
251
|
const translations = require(translationsFilePath);
|
|
250
252
|
const hasIntlMessage = translations.hasOwnProperty(requestedIntlMessageId);
|
|
251
253
|
if (!hasIntlMessage) {
|
|
252
|
-
|
|
254
|
+
var _context2, _context3;
|
|
255
|
+
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, "'."));
|
|
253
256
|
}
|
|
254
257
|
const translation = translations[requestedIntlMessageId];
|
|
255
258
|
const translationValue = isStructuredJson(translation) ? translation.string : translation;
|
|
256
259
|
const escapedMatchedString = matchedString.replace(/[${}:]/g, '\\$&');
|
|
257
|
-
return valueOfEnvConfig.replace(new RegExp(
|
|
260
|
+
return valueOfEnvConfig.replace(new RegExp("(".concat(escapedMatchedString, ")+"), 'g'), translationValue);
|
|
258
261
|
};
|
|
259
262
|
const substituteFilePathVariablePlaceholder = (valueOfPlaceholder, matchedString, valueOfEnvConfig, loadingOptions) => {
|
|
260
263
|
const _valueOfPlaceholder$s5 = valueOfPlaceholder.split(':'),
|
|
@@ -267,7 +270,7 @@ const substituteFilePathVariablePlaceholder = (valueOfPlaceholder, matchedString
|
|
|
267
270
|
encoding: 'utf-8'
|
|
268
271
|
});
|
|
269
272
|
const escapedMatchedString = matchedString.replace(/[${}:]/g, '\\$&');
|
|
270
|
-
return valueOfEnvConfig.replace(new RegExp(
|
|
273
|
+
return valueOfEnvConfig.replace(new RegExp("(".concat(escapedMatchedString, ")+"), 'g'), content);
|
|
271
274
|
};
|
|
272
275
|
const getValueOfPlaceholder = valueWithPlaceholder => valueWithPlaceholder.replace(variableSyntax, (_match, varName) => _trimInstanceProperty__default["default"](varName).call(varName)).replace(/\s/g, '');
|
|
273
276
|
const substituteVariablePlaceholders = (config, loadingOptions) => JSON.parse(_JSON$stringify__default["default"](config), (_key, value) => {
|
|
@@ -960,12 +963,13 @@ const printErrors = errors => {
|
|
|
960
963
|
return 'No errors';
|
|
961
964
|
}
|
|
962
965
|
return _mapInstanceProperty__default["default"](errors).call(errors, error => {
|
|
963
|
-
|
|
966
|
+
var _context, _context2, _context3;
|
|
967
|
+
const baseMessage = _concatInstanceProperty__default["default"](_context = "".concat(error.instancePath, " ")).call(_context, error.message);
|
|
964
968
|
switch (error.keyword) {
|
|
965
969
|
case 'additionalProperties':
|
|
966
|
-
return
|
|
970
|
+
return _concatInstanceProperty__default["default"](_context2 = "".concat(baseMessage, ": ")).call(_context2, error.params.additionalProperty);
|
|
967
971
|
case 'enum':
|
|
968
|
-
return
|
|
972
|
+
return _concatInstanceProperty__default["default"](_context3 = "".concat(baseMessage, ": ")).call(_context3, error.params.allowedValues.toString());
|
|
969
973
|
default:
|
|
970
974
|
return baseMessage;
|
|
971
975
|
}
|
|
@@ -978,7 +982,8 @@ const validateConfig = (configType, config) => {
|
|
|
978
982
|
} else if (configType === LOADED_CONFIG_TYPES.CUSTOM_VIEW) {
|
|
979
983
|
validation = validateCustomViewConfig;
|
|
980
984
|
} else {
|
|
981
|
-
|
|
985
|
+
var _context4;
|
|
986
|
+
throw new Error(_concatInstanceProperty__default["default"](_context4 = "Invalid config type \"".concat(configType, "\", expected ")).call(_context4, _Object$keys__default["default"](LOADED_CONFIG_TYPES).toString()));
|
|
982
987
|
}
|
|
983
988
|
const isValid = validation(config);
|
|
984
989
|
if (!isValid) {
|
|
@@ -991,9 +996,9 @@ const validateEntryPointUriPath = config => {
|
|
|
991
996
|
}
|
|
992
997
|
};
|
|
993
998
|
const validateSubmenuLinks = config => {
|
|
994
|
-
var
|
|
999
|
+
var _context5;
|
|
995
1000
|
const uriPathSet = new _Set__default["default"]();
|
|
996
|
-
_forEachInstanceProperty__default["default"](
|
|
1001
|
+
_forEachInstanceProperty__default["default"](_context5 = config.submenuLinks).call(_context5, _ref => {
|
|
997
1002
|
let uriPath = _ref.uriPath;
|
|
998
1003
|
if (uriPathSet.has(uriPath)) {
|
|
999
1004
|
throw new Error('Duplicate URI path. Every submenu link must have a unique URI path value');
|
|
@@ -1002,62 +1007,64 @@ const validateSubmenuLinks = config => {
|
|
|
1002
1007
|
});
|
|
1003
1008
|
};
|
|
1004
1009
|
const validateAdditionalOAuthScopes = config => {
|
|
1010
|
+
var _config$additionalOAu;
|
|
1005
1011
|
const additionalPermissionNames = new _Set__default["default"]();
|
|
1006
|
-
config.additionalOAuthScopes
|
|
1012
|
+
(_config$additionalOAu = config.additionalOAuthScopes) === null || _config$additionalOAu === void 0 || _forEachInstanceProperty__default["default"](_config$additionalOAu).call(_config$additionalOAu, _ref2 => {
|
|
1007
1013
|
let name = _ref2.name,
|
|
1008
1014
|
view = _ref2.view,
|
|
1009
1015
|
manage = _ref2.manage;
|
|
1010
1016
|
if ((_Array$isArray__default["default"](view) && view.length === 0 || !view) && (_Array$isArray__default["default"](manage) && manage.length === 0 || !manage)) {
|
|
1011
|
-
throw new Error(
|
|
1017
|
+
throw new Error("At least one OAuth Scope for permission group name \"".concat(name, "\" is required"));
|
|
1012
1018
|
} else if (additionalPermissionNames.has(name)) {
|
|
1013
|
-
throw new Error(
|
|
1019
|
+
throw new Error("Duplicate additional permission group name \"".concat(name, "\". Every additional permission must have a unique name"));
|
|
1014
1020
|
}
|
|
1015
1021
|
if (!name.match(constants.PERMISSION_GROUP_NAME_REGEX)) {
|
|
1016
|
-
throw new Error(
|
|
1022
|
+
throw new Error("Additional permission group name \"".concat(name, "\" is invalid. The value may be between 2 and 64 characters and only contain alphabetic lowercase characters and non-consecutive hyphens. Leading and trailing hyphens are also not allowed"));
|
|
1017
1023
|
}
|
|
1018
1024
|
additionalPermissionNames.add(name);
|
|
1019
1025
|
});
|
|
1020
1026
|
};
|
|
1021
1027
|
|
|
1022
1028
|
function ownKeys$1(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
1023
|
-
function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var
|
|
1029
|
+
function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var _context5, _context6; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context5 = ownKeys$1(Object(t), !0)).call(_context5, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context6 = ownKeys$1(Object(t))).call(_context6, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
1024
1030
|
|
|
1025
1031
|
// The `uriPath` of each submenu link is supposed to be defined relative
|
|
1026
1032
|
// to the `entryPointUriPath`. Computing the full path is done internally to keep
|
|
1027
1033
|
// the configuration simple.
|
|
1028
1034
|
const computeUriPath = (uriPath, entryPointUriPath) => {
|
|
1035
|
+
var _context;
|
|
1029
1036
|
// In case the `uriPath` is only `/`, it means that the link is supposed to be
|
|
1030
1037
|
// treated the same as the main application path. In this case, the return value
|
|
1031
1038
|
// should not contain any unnecessary trailing slash and therefore we use the `entryPointUriPath`.
|
|
1032
1039
|
if (uriPath === '/') return entryPointUriPath;
|
|
1033
1040
|
// In case the `uriPath` is already configured including the `entryPointUriPath`,
|
|
1034
1041
|
// we return the `uriPath` as-is.
|
|
1035
|
-
if (_startsWithInstanceProperty__default["default"](uriPath).call(uriPath,
|
|
1042
|
+
if (_startsWithInstanceProperty__default["default"](uriPath).call(uriPath, "".concat(entryPointUriPath, "/"))) return uriPath;
|
|
1036
1043
|
// Return the full path including the `entryPointUriPath` as a prefix.
|
|
1037
|
-
return
|
|
1044
|
+
return _concatInstanceProperty__default["default"](_context = "".concat(entryPointUriPath, "/")).call(_context, uriPath);
|
|
1038
1045
|
};
|
|
1039
1046
|
const getPermissions = appConfig => {
|
|
1040
|
-
var
|
|
1041
|
-
const additionalResourceAccessKeyToOauthScopeMap = _reduceInstanceProperty__default["default"](
|
|
1047
|
+
var _context2, _appConfig$additional, _context3;
|
|
1048
|
+
const additionalResourceAccessKeyToOauthScopeMap = _reduceInstanceProperty__default["default"](_context2 = appConfig.additionalOAuthScopes || []).call(_context2, (previousOauthScope, _ref) => {
|
|
1042
1049
|
let name = _ref.name,
|
|
1043
1050
|
view = _ref.view,
|
|
1044
1051
|
manage = _ref.manage;
|
|
1045
1052
|
const formattedResourceKey = formatters.formatEntryPointUriPathToResourceAccessKey(name);
|
|
1046
1053
|
return _objectSpread$1(_objectSpread$1({}, previousOauthScope), {}, {
|
|
1047
|
-
[
|
|
1048
|
-
[
|
|
1054
|
+
["view".concat(formattedResourceKey)]: view,
|
|
1055
|
+
["manage".concat(formattedResourceKey)]: manage
|
|
1049
1056
|
});
|
|
1050
1057
|
}, {});
|
|
1051
|
-
const additionalPermissionNames = appConfig.additionalOAuthScopes
|
|
1058
|
+
const additionalPermissionNames = ((_appConfig$additional = appConfig.additionalOAuthScopes) === null || _appConfig$additional === void 0 ? void 0 : _mapInstanceProperty__default["default"](_appConfig$additional).call(_appConfig$additional, _ref2 => {
|
|
1052
1059
|
let name = _ref2.name;
|
|
1053
1060
|
return name;
|
|
1054
|
-
}) || [];
|
|
1061
|
+
})) || [];
|
|
1055
1062
|
const permissionKeys = formatters.entryPointUriPathToResourceAccesses(appConfig.entryPointUriPath ||
|
|
1056
1063
|
// In case the `entryPointUriPath` is not defined it is because the
|
|
1057
1064
|
// configuration is for a custom view. In this case we use the
|
|
1058
1065
|
// default entry point uri path.
|
|
1059
1066
|
constants.CUSTOM_VIEW_HOST_ENTRY_POINT_URI_PATH, additionalPermissionNames);
|
|
1060
|
-
const additionalPermissions = _mapInstanceProperty__default["default"](
|
|
1067
|
+
const additionalPermissions = _mapInstanceProperty__default["default"](_context3 = _Object$keys__default["default"](additionalResourceAccessKeyToOauthScopeMap)).call(_context3, additionalResourceAccessKey => ({
|
|
1061
1068
|
name: permissionKeys[additionalResourceAccessKey],
|
|
1062
1069
|
oAuthScopes: additionalResourceAccessKeyToOauthScopeMap[additionalResourceAccessKey]
|
|
1063
1070
|
}));
|
|
@@ -1070,7 +1077,7 @@ const getPermissions = appConfig => {
|
|
|
1070
1077
|
}, ...additionalPermissions];
|
|
1071
1078
|
};
|
|
1072
1079
|
function transformCustomApplicationConfigToData(appConfig) {
|
|
1073
|
-
var
|
|
1080
|
+
var _context4;
|
|
1074
1081
|
validateEntryPointUriPath(appConfig);
|
|
1075
1082
|
validateSubmenuLinks(appConfig);
|
|
1076
1083
|
validateAdditionalOAuthScopes(appConfig);
|
|
@@ -1083,7 +1090,7 @@ function transformCustomApplicationConfigToData(appConfig) {
|
|
|
1083
1090
|
permissions: getPermissions(appConfig),
|
|
1084
1091
|
icon: appConfig.icon,
|
|
1085
1092
|
mainMenuLink: appConfig.mainMenuLink,
|
|
1086
|
-
submenuLinks: _mapInstanceProperty__default["default"](
|
|
1093
|
+
submenuLinks: _mapInstanceProperty__default["default"](_context4 = appConfig.submenuLinks).call(_context4, submenuLink => _objectSpread$1(_objectSpread$1({}, submenuLink), {}, {
|
|
1087
1094
|
uriPath: computeUriPath(submenuLink.uriPath, appConfig.entryPointUriPath)
|
|
1088
1095
|
}))
|
|
1089
1096
|
};
|
|
@@ -1108,11 +1115,12 @@ function transformConfigurationToData(configType, configuration) {
|
|
|
1108
1115
|
} else if (configType === LOADED_CONFIG_TYPES.CUSTOM_VIEW) {
|
|
1109
1116
|
return transformCustomViewConfigToData(configuration);
|
|
1110
1117
|
} else {
|
|
1111
|
-
throw new Error(
|
|
1118
|
+
throw new Error("Invalid config type: ".concat(configType));
|
|
1112
1119
|
}
|
|
1113
1120
|
}
|
|
1114
1121
|
|
|
1115
1122
|
const mapCloudIdentifierToApiUrl = key => {
|
|
1123
|
+
var _context;
|
|
1116
1124
|
switch (key) {
|
|
1117
1125
|
case CLOUD_IDENTIFIERS.GCP_AU:
|
|
1118
1126
|
return MC_API_URLS[CLOUD_IDENTIFIERS.GCP_AU];
|
|
@@ -1129,7 +1137,7 @@ const mapCloudIdentifierToApiUrl = key => {
|
|
|
1129
1137
|
default:
|
|
1130
1138
|
// We would probably never get to this point, as the JSON schema validation
|
|
1131
1139
|
// kicks in before.
|
|
1132
|
-
throw new Error(
|
|
1140
|
+
throw new Error(_concatInstanceProperty__default["default"](_context = "Unknown cloud identifier \"".concat(key, "\". Supported values: ")).call(_context, _Object$values__default["default"](CLOUD_IDENTIFIERS).toString()));
|
|
1133
1141
|
}
|
|
1134
1142
|
};
|
|
1135
1143
|
const getUniqueValues = function () {
|
|
@@ -1153,10 +1161,10 @@ const getOrThrow = (fn, errorMessage) => {
|
|
|
1153
1161
|
};
|
|
1154
1162
|
|
|
1155
1163
|
function ownKeys(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
1156
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var
|
|
1164
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context4, _context5; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context4 = ownKeys(Object(t), !0)).call(_context4, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context5 = ownKeys(Object(t))).call(_context5, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
1157
1165
|
// TODO: make it configurable.
|
|
1158
1166
|
const developmentPort = 3001;
|
|
1159
|
-
const developmentAppUrl =
|
|
1167
|
+
const developmentAppUrl = "http://localhost:".concat(developmentPort);
|
|
1160
1168
|
const getLoadedConfigurationType = configFileName => {
|
|
1161
1169
|
if (_includesInstanceProperty__default["default"](configFileName).call(configFileName, 'custom-view-config')) {
|
|
1162
1170
|
return LOADED_CONFIG_TYPES.CUSTOM_VIEW;
|
|
@@ -1172,6 +1180,7 @@ const omitDevConfigIfEmpty = devConfig => {
|
|
|
1172
1180
|
};
|
|
1173
1181
|
const isCustomViewData = data => data.entryPointUriPath === undefined;
|
|
1174
1182
|
const getRuntimeEnvironmentConfigForDevelopment = _ref => {
|
|
1183
|
+
var _appConfig$env$develo;
|
|
1175
1184
|
let isProd = _ref.isProd,
|
|
1176
1185
|
configurationData = _ref.configurationData,
|
|
1177
1186
|
mcApiUrl = _ref.mcApiUrl,
|
|
@@ -1188,7 +1197,7 @@ const getRuntimeEnvironmentConfigForDevelopment = _ref => {
|
|
|
1188
1197
|
initialProjectKey:
|
|
1189
1198
|
// For the `account` application, we should unset the projectKey.
|
|
1190
1199
|
entryPointUriPath === 'account' ? undefined : appConfig.env.development.initialProjectKey
|
|
1191
|
-
}, appConfig.env.development
|
|
1200
|
+
}, ((_appConfig$env$develo = appConfig.env.development) === null || _appConfig$env$develo === void 0 ? void 0 : _appConfig$env$develo.teamId) && _objectSpread({
|
|
1192
1201
|
teamId: appConfig.env.development.teamId
|
|
1193
1202
|
}, isCustomViewData(configurationData) ? {
|
|
1194
1203
|
customViewId: configurationData.id
|
|
@@ -1196,11 +1205,12 @@ const getRuntimeEnvironmentConfigForDevelopment = _ref => {
|
|
|
1196
1205
|
applicationId: configurationData.id
|
|
1197
1206
|
})), {}, {
|
|
1198
1207
|
oAuthScopes: appConfig.oAuthScopes,
|
|
1199
|
-
additionalOAuthScopes: appConfig
|
|
1208
|
+
additionalOAuthScopes: appConfig === null || appConfig === void 0 ? void 0 : appConfig.additionalOAuthScopes
|
|
1200
1209
|
}));
|
|
1201
1210
|
if (isCustomViewData(configurationData)) {
|
|
1211
|
+
var _context;
|
|
1202
1212
|
const hostUriPath = appConfig.env.development.hostUriPath;
|
|
1203
|
-
const defaultHostUriPath = oidcConfig.initialProjectKey ?
|
|
1213
|
+
const defaultHostUriPath = oidcConfig.initialProjectKey ? _concatInstanceProperty__default["default"](_context = "/".concat(oidcConfig.initialProjectKey, "/")).call(_context, entryPointUriPath) : "/".concat(entryPointUriPath);
|
|
1204
1214
|
const hostUrl = new _URL__default["default"](hostUriPath || defaultHostUriPath, developmentAppUrl);
|
|
1205
1215
|
return omitDevConfigIfEmpty({
|
|
1206
1216
|
oidc: oidcConfig,
|
|
@@ -1222,6 +1232,7 @@ const getRuntimeEnvironmentConfigForDevelopment = _ref => {
|
|
|
1222
1232
|
});
|
|
1223
1233
|
};
|
|
1224
1234
|
const getRuntimeEnvironmentConfig = _ref2 => {
|
|
1235
|
+
var _context2;
|
|
1225
1236
|
let isProd = _ref2.isProd,
|
|
1226
1237
|
configurationData = _ref2.configurationData,
|
|
1227
1238
|
additionalAppEnv = _ref2.additionalAppEnv,
|
|
@@ -1240,7 +1251,7 @@ const getRuntimeEnvironmentConfig = _ref2 => {
|
|
|
1240
1251
|
// In development, we prefix the entry point with the "__local" prefix.
|
|
1241
1252
|
// This is important to determine to which URL the MC should redirect to
|
|
1242
1253
|
// after successful login.
|
|
1243
|
-
const applicationIdentifier = isProd ?
|
|
1254
|
+
const applicationIdentifier = isProd ? _concatInstanceProperty__default["default"](_context2 = "".concat(configurationData.id, ":")).call(_context2, entryPointUriPath) : "__local:".concat(entryPointUriPath);
|
|
1244
1255
|
const developmentConfig = getRuntimeEnvironmentConfigForDevelopment({
|
|
1245
1256
|
isProd,
|
|
1246
1257
|
configurationData,
|
|
@@ -1272,7 +1283,7 @@ const getRuntimeEnvironmentConfig = _ref2 => {
|
|
|
1272
1283
|
// again will result in returning the cached value.
|
|
1273
1284
|
let cachedConfig;
|
|
1274
1285
|
const processConfig = async function () {
|
|
1275
|
-
var
|
|
1286
|
+
var _ref4, _processEnv$MC_APP_EN, _appConfig$additional, _ref5, _appConfig$headers, _appConfig$headers2, _context3, _appConfig$headers3, _appConfig$headers4;
|
|
1276
1287
|
let _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
1277
1288
|
_ref3$disableCache = _ref3.disableCache,
|
|
1278
1289
|
disableCache = _ref3$disableCache === void 0 ? false : _ref3$disableCache,
|
|
@@ -1291,22 +1302,22 @@ const processConfig = async function () {
|
|
|
1291
1302
|
processEnv
|
|
1292
1303
|
});
|
|
1293
1304
|
const configurationData = transformConfigurationToData(configType, appConfig);
|
|
1294
|
-
const appEnvKey = processEnv.MC_APP_ENV
|
|
1305
|
+
const appEnvKey = (_ref4 = (_processEnv$MC_APP_EN = processEnv.MC_APP_ENV) !== null && _processEnv$MC_APP_EN !== void 0 ? _processEnv$MC_APP_EN : processEnv.NODE_ENV) !== null && _ref4 !== void 0 ? _ref4 : 'development';
|
|
1295
1306
|
const isProd = getIsProd(processEnv);
|
|
1296
|
-
const additionalAppEnv = appConfig.additionalEnv
|
|
1297
|
-
const revision = additionalAppEnv.revision
|
|
1307
|
+
const additionalAppEnv = (_appConfig$additional = appConfig.additionalEnv) !== null && _appConfig$additional !== void 0 ? _appConfig$additional : {};
|
|
1308
|
+
const revision = (_ref5 = additionalAppEnv.revision) !== null && _ref5 !== void 0 ? _ref5 : '';
|
|
1298
1309
|
|
|
1299
1310
|
// Parse all the supported URLs, which gets implicitly validated
|
|
1300
1311
|
|
|
1301
1312
|
const envAppUrl = isProd ? configurationData.url : developmentAppUrl;
|
|
1302
|
-
const appUrl = getOrThrow(() => new _URL__default["default"](envAppUrl),
|
|
1313
|
+
const appUrl = getOrThrow(() => new _URL__default["default"](envAppUrl), "Invalid application URL: \"".concat(envAppUrl, "\""));
|
|
1303
1314
|
|
|
1304
1315
|
// Use `||` instead of `??` to include empty string values.
|
|
1305
1316
|
const envCdnUrl = isProd ? appConfig.env.production.cdnUrl || appUrl.href : developmentAppUrl;
|
|
1306
|
-
const cdnUrl = getOrThrow(() => new _URL__default["default"](envCdnUrl),
|
|
1317
|
+
const cdnUrl = getOrThrow(() => new _URL__default["default"](envCdnUrl), "Invalid application CDN URL: \"".concat(envCdnUrl, "\""));
|
|
1307
1318
|
const mcApiUrl = getOrThrow(() => new _URL__default["default"](
|
|
1308
1319
|
// Use `||` instead of `??` to include empty string values.
|
|
1309
|
-
appConfig.mcApiUrl || mapCloudIdentifierToApiUrl(appConfig.cloudIdentifier)),
|
|
1320
|
+
appConfig.mcApiUrl || mapCloudIdentifierToApiUrl(appConfig.cloudIdentifier)), "Invalid MC API URL: \"".concat(appConfig.mcApiUrl, "\""));
|
|
1310
1321
|
cachedConfig = {
|
|
1311
1322
|
data: configurationData,
|
|
1312
1323
|
env: getRuntimeEnvironmentConfig({
|
|
@@ -1321,16 +1332,16 @@ const processConfig = async function () {
|
|
|
1321
1332
|
revision
|
|
1322
1333
|
}),
|
|
1323
1334
|
headers: _objectSpread(_objectSpread({}, appConfig.headers), {}, {
|
|
1324
|
-
csp: _objectSpread(_objectSpread({}, appConfig.headers
|
|
1335
|
+
csp: _objectSpread(_objectSpread({}, (_appConfig$headers = appConfig.headers) === null || _appConfig$headers === void 0 ? void 0 : _appConfig$headers.csp), {}, {
|
|
1325
1336
|
// We need to make sure the URL we use in these CSP headers have a slash in the end,
|
|
1326
1337
|
// otherwise it might create an invalid value when application/CDN URL points to a
|
|
1327
1338
|
// non-root directory (ex: https://www.my-domain.com/app). This is a valid URL but from
|
|
1328
1339
|
// the CSP point of view, it will say only the file `app` can be used as a source, so
|
|
1329
1340
|
// any other file from that domain will be forbidden. Using the slash (ex: https://www.my-domain.com/app/)
|
|
1330
1341
|
// at the end it's like using a wildcard so anything 'below' `app` will be allowed.
|
|
1331
|
-
'connect-src': getUniqueValues(appConfig.headers
|
|
1332
|
-
'script-src': getUniqueValues(appConfig.headers
|
|
1333
|
-
'style-src': getUniqueValues(appConfig.headers
|
|
1342
|
+
'connect-src': getUniqueValues((_appConfig$headers2 = appConfig.headers) === null || _appConfig$headers2 === void 0 || (_appConfig$headers2 = _appConfig$headers2.csp) === null || _appConfig$headers2 === void 0 ? void 0 : _appConfig$headers2['connect-src'], _concatInstanceProperty__default["default"](_context3 = [mcApiUrl.origin]).call(_context3, isProd ? ["".concat(trimTrailingSlash(appUrl.href), "/"), "".concat(trimTrailingSlash(cdnUrl.href), "/")] : [])),
|
|
1343
|
+
'script-src': getUniqueValues((_appConfig$headers3 = appConfig.headers) === null || _appConfig$headers3 === void 0 || (_appConfig$headers3 = _appConfig$headers3.csp) === null || _appConfig$headers3 === void 0 ? void 0 : _appConfig$headers3['script-src'], isProd ? ["".concat(trimTrailingSlash(appUrl.href), "/"), "".concat(trimTrailingSlash(cdnUrl.href), "/")] : []),
|
|
1344
|
+
'style-src': getUniqueValues((_appConfig$headers4 = appConfig.headers) === null || _appConfig$headers4 === void 0 || (_appConfig$headers4 = _appConfig$headers4.csp) === null || _appConfig$headers4 === void 0 ? void 0 : _appConfig$headers4['style-src'], isProd ? ["".concat(trimTrailingSlash(appUrl.href), "/"), "".concat(trimTrailingSlash(cdnUrl.href), "/")] : [])
|
|
1334
1345
|
})
|
|
1335
1346
|
})
|
|
1336
1347
|
};
|