@commercetools-frontend/application-config 27.9.1 → 27.9.2
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 +60 -68
- package/dist/commercetools-frontend-application-config.cjs.prod.js +60 -68
- package/dist/commercetools-frontend-application-config.esm.js +58 -67
- package/dist/{formatters-3e1c755e.cjs.dev.js → formatters-4515015b.cjs.prod.js} +10 -13
- package/dist/{formatters-e218c305.esm.js → formatters-5629a23b.esm.js} +10 -12
- package/dist/{formatters-89609c66.cjs.prod.js → formatters-5a68b5ac.cjs.dev.js} +10 -13
- package/package.json +3 -3
- package/ssr/dist/commercetools-frontend-application-config-ssr.cjs.dev.js +1 -2
- package/ssr/dist/commercetools-frontend-application-config-ssr.cjs.prod.js +1 -2
- package/ssr/dist/commercetools-frontend-application-config-ssr.esm.js +1 -2
|
@@ -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 _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
16
15
|
var _URL = require('@babel/runtime-corejs3/core-js-stable/url');
|
|
16
|
+
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
17
17
|
var fs$1 = require('node:fs');
|
|
18
18
|
var path = require('node:path');
|
|
19
19
|
var omitEmpty = require('omit-empty-es');
|
|
@@ -36,7 +36,8 @@ var _trimInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/insta
|
|
|
36
36
|
var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
|
|
37
37
|
var path$1 = require('path');
|
|
38
38
|
var _reduceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
|
|
39
|
-
var
|
|
39
|
+
var _bindInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/bind');
|
|
40
|
+
var formatters = require('./formatters-5a68b5ac.cjs.dev.js');
|
|
40
41
|
var _Set = require('@babel/runtime-corejs3/core-js-stable/set');
|
|
41
42
|
var _Array$isArray = require('@babel/runtime-corejs3/core-js-stable/array/is-array');
|
|
42
43
|
var Ajv = require('ajv');
|
|
@@ -58,8 +59,8 @@ var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_O
|
|
|
58
59
|
var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
|
|
59
60
|
var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
|
|
60
61
|
var _includesInstanceProperty__default = /*#__PURE__*/_interopDefault(_includesInstanceProperty);
|
|
61
|
-
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
62
62
|
var _URL__default = /*#__PURE__*/_interopDefault(_URL);
|
|
63
|
+
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
63
64
|
var fs__default$1 = /*#__PURE__*/_interopDefault(fs$1);
|
|
64
65
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
65
66
|
var omitEmpty__default = /*#__PURE__*/_interopDefault(omitEmpty);
|
|
@@ -72,6 +73,7 @@ var _trimInstanceProperty__default = /*#__PURE__*/_interopDefault(_trimInstanceP
|
|
|
72
73
|
var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
|
|
73
74
|
var path__default$1 = /*#__PURE__*/_interopDefault(path$1);
|
|
74
75
|
var _reduceInstanceProperty__default = /*#__PURE__*/_interopDefault(_reduceInstanceProperty);
|
|
76
|
+
var _bindInstanceProperty__default = /*#__PURE__*/_interopDefault(_bindInstanceProperty);
|
|
75
77
|
var _Set__default = /*#__PURE__*/_interopDefault(_Set);
|
|
76
78
|
var _Array$isArray__default = /*#__PURE__*/_interopDefault(_Array$isArray);
|
|
77
79
|
var Ajv__default = /*#__PURE__*/_interopDefault(Ajv);
|
|
@@ -148,11 +150,10 @@ const isDynamicAwaitSupported = () => {
|
|
|
148
150
|
const isEsmModule = async cwd => {
|
|
149
151
|
const packagePath = path__default["default"].join(cwd, 'package.json');
|
|
150
152
|
try {
|
|
151
|
-
var _JSON$parse;
|
|
152
153
|
const packageJSON = await fs__default["default"].readFile(packagePath, {
|
|
153
154
|
encoding: 'utf-8'
|
|
154
155
|
});
|
|
155
|
-
return
|
|
156
|
+
return JSON.parse(packageJSON)?.type === 'module';
|
|
156
157
|
} catch (error) {
|
|
157
158
|
return false;
|
|
158
159
|
}
|
|
@@ -172,7 +173,7 @@ const createExplorerFor = async configFileName => {
|
|
|
172
173
|
const loaders = isDynamicAwaitSupported() || (await isEsmModule(process.cwd())) ? cosmiconfig.defaultLoaders : cosmiconfig.defaultLoadersSync;
|
|
173
174
|
return cosmiconfig.cosmiconfig(configFileName, {
|
|
174
175
|
searchStrategy: 'project',
|
|
175
|
-
searchPlaces: [
|
|
176
|
+
searchPlaces: [`${configFileName}.js`, `${configFileName}.cjs`, `${configFileName}.mjs`, `${configFileName}.ts`],
|
|
176
177
|
loaders: {
|
|
177
178
|
'.js': loaders['.js'],
|
|
178
179
|
'.cjs': loaders['.cjs'],
|
|
@@ -187,9 +188,9 @@ const getConfigPath = async () => {
|
|
|
187
188
|
const customApplicationConfigFile = await customApplicationExplorer.search();
|
|
188
189
|
const customViewConfigFile = await customViewExplorer.search();
|
|
189
190
|
if (!customApplicationConfigFile && !customViewConfigFile) {
|
|
190
|
-
throw new Error(
|
|
191
|
+
throw new Error(`Missing or invalid configuration file.`);
|
|
191
192
|
}
|
|
192
|
-
return
|
|
193
|
+
return customApplicationConfigFile?.filepath || customViewConfigFile?.filepath;
|
|
193
194
|
};
|
|
194
195
|
const loadConfig = async applicationPath => {
|
|
195
196
|
const customApplicationExplorer = await createExplorerFor('custom-application-config');
|
|
@@ -197,10 +198,10 @@ const loadConfig = async applicationPath => {
|
|
|
197
198
|
const customApplicationConfigFile = await customApplicationExplorer.search(applicationPath);
|
|
198
199
|
const customViewConfigFile = await customViewExplorer.search(applicationPath);
|
|
199
200
|
if ((!customApplicationConfigFile || !customApplicationConfigFile.config) && (!customViewConfigFile || !customViewConfigFile.config)) {
|
|
200
|
-
throw new MissingOrInvalidConfigError(
|
|
201
|
+
throw new MissingOrInvalidConfigError(`Missing or invalid configuration file.`);
|
|
201
202
|
}
|
|
202
203
|
if (customApplicationConfigFile && customViewConfigFile) {
|
|
203
|
-
throw new MissingOrInvalidConfigError(
|
|
204
|
+
throw new MissingOrInvalidConfigError(`Found configuration files for both Custom Application and Custom View. Please remove one of them.`);
|
|
204
205
|
}
|
|
205
206
|
return customViewConfigFile || customApplicationConfigFile;
|
|
206
207
|
};
|
|
@@ -234,15 +235,14 @@ Boolean(valueOfEnvConfig.match(variableSyntax));
|
|
|
234
235
|
const isEnvVariablePlaceholder = valueOfPlaceholder => Boolean(valueOfPlaceholder.match(envRefSyntax));
|
|
235
236
|
const isIntlVariablePlaceholder = valueOfPlaceholder => Boolean(valueOfPlaceholder.match(intlRefSyntax));
|
|
236
237
|
const isFilePathVariablePlaceholder = valueOfPlaceholder => Boolean(valueOfPlaceholder.match(filePathRefSyntax));
|
|
237
|
-
const isStructuredJson = message =>
|
|
238
|
+
const isStructuredJson = message => message?.string !== undefined;
|
|
238
239
|
const substituteEnvVariablePlaceholder = (valueOfPlaceholder, matchedString, valueOfEnvConfig, loadingOptions) => {
|
|
239
240
|
const _valueOfPlaceholder$s = valueOfPlaceholder.split(':'),
|
|
240
241
|
_valueOfPlaceholder$s2 = _slicedToArray(_valueOfPlaceholder$s, 2),
|
|
241
242
|
requestedEnvVar = _valueOfPlaceholder$s2[1];
|
|
242
243
|
const hasEnvField = loadingOptions.processEnv.hasOwnProperty(requestedEnvVar);
|
|
243
244
|
if (!hasEnvField) {
|
|
244
|
-
|
|
245
|
-
throw new Error(_concatInstanceProperty__default["default"](_context = "Missing environment variable '".concat(requestedEnvVar, "' specified in config as 'env:")).call(_context, requestedEnvVar, "'."));
|
|
245
|
+
throw new Error(`Missing environment variable '${requestedEnvVar}' specified in config as 'env:${requestedEnvVar}'.`);
|
|
246
246
|
}
|
|
247
247
|
return valueOfEnvConfig.replace(new RegExp(escapeRegExp(matchedString), 'g'), loadingOptions.processEnv[requestedEnvVar]);
|
|
248
248
|
};
|
|
@@ -251,14 +251,13 @@ const substituteIntlVariablePlaceholder = (valueOfPlaceholder, matchedString, va
|
|
|
251
251
|
_valueOfPlaceholder$s4 = _slicedToArray(_valueOfPlaceholder$s3, 3),
|
|
252
252
|
locale = _valueOfPlaceholder$s4[1],
|
|
253
253
|
requestedIntlMessageId = _valueOfPlaceholder$s4[2];
|
|
254
|
-
const translationsFilePath = require.resolve(
|
|
255
|
-
paths: [
|
|
254
|
+
const translationsFilePath = require.resolve(`./i18n/data/${locale}.json`, {
|
|
255
|
+
paths: [`${loadingOptions.applicationPath}/src`, loadingOptions.applicationPath]
|
|
256
256
|
});
|
|
257
257
|
const translations = require(translationsFilePath);
|
|
258
258
|
const hasIntlMessage = translations.hasOwnProperty(requestedIntlMessageId);
|
|
259
259
|
if (!hasIntlMessage) {
|
|
260
|
-
|
|
261
|
-
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, "'."));
|
|
260
|
+
throw new Error(`Missing message key '${requestedIntlMessageId}' specified in config as 'intl:${locale}:${requestedIntlMessageId}'.`);
|
|
262
261
|
}
|
|
263
262
|
const translation = translations[requestedIntlMessageId];
|
|
264
263
|
const translationValue = isStructuredJson(translation) ? translation.string : translation;
|
|
@@ -284,7 +283,7 @@ const substituteFilePathVariablePlaceholder = (valueOfPlaceholder, matchedString
|
|
|
284
283
|
// to /etc/passwd).
|
|
285
284
|
const normalizedSpecifier = path__default$1["default"].posix.normalize(filePathOrModule);
|
|
286
285
|
if (_startsWithInstanceProperty__default["default"](normalizedSpecifier).call(normalizedSpecifier, '..')) {
|
|
287
|
-
throw new Error(
|
|
286
|
+
throw new Error(`Path traversal in module specifiers is not allowed: ${filePathOrModule}`);
|
|
288
287
|
}
|
|
289
288
|
}
|
|
290
289
|
const resolvedPath = require.resolve(filePathOrModule, {
|
|
@@ -319,7 +318,7 @@ const substituteFilePathVariablePlaceholder = (valueOfPlaceholder, matchedString
|
|
|
319
318
|
// Use path.relative() to avoid string prefix vulnerabilities (e.g., "/app" vs "/app-evil")
|
|
320
319
|
const isSafePath = !_startsWithInstanceProperty__default["default"](relativePath).call(relativePath, '..') && !path__default$1["default"].isAbsolute(relativePath);
|
|
321
320
|
if (!isSafePath) {
|
|
322
|
-
throw new Error(
|
|
321
|
+
throw new Error(`Access to files outside workspace directory is not allowed: ${filePathOrModule}`);
|
|
323
322
|
}
|
|
324
323
|
}
|
|
325
324
|
const content = fs__default$1["default"].readFileSync(normalizedPath, {
|
|
@@ -1021,13 +1020,12 @@ const printErrors = errors => {
|
|
|
1021
1020
|
return 'No errors';
|
|
1022
1021
|
}
|
|
1023
1022
|
return _mapInstanceProperty__default["default"](errors).call(errors, error => {
|
|
1024
|
-
|
|
1025
|
-
const baseMessage = _concatInstanceProperty__default["default"](_context = "".concat(error.instancePath, " ")).call(_context, error.message);
|
|
1023
|
+
const baseMessage = `${error.instancePath} ${error.message}`;
|
|
1026
1024
|
switch (error.keyword) {
|
|
1027
1025
|
case 'additionalProperties':
|
|
1028
|
-
return
|
|
1026
|
+
return `${baseMessage}: ${error.params.additionalProperty}`;
|
|
1029
1027
|
case 'enum':
|
|
1030
|
-
return
|
|
1028
|
+
return `${baseMessage}: ${error.params.allowedValues.toString()}`;
|
|
1031
1029
|
default:
|
|
1032
1030
|
return baseMessage;
|
|
1033
1031
|
}
|
|
@@ -1040,8 +1038,7 @@ const validateConfig = (configType, config) => {
|
|
|
1040
1038
|
} else if (configType === LOADED_CONFIG_TYPES.CUSTOM_VIEW) {
|
|
1041
1039
|
validation = validateCustomViewConfig;
|
|
1042
1040
|
} else {
|
|
1043
|
-
|
|
1044
|
-
throw new Error(_concatInstanceProperty__default["default"](_context4 = "Invalid config type \"".concat(configType, "\", expected ")).call(_context4, _Object$keys__default["default"](LOADED_CONFIG_TYPES).toString()));
|
|
1041
|
+
throw new Error(`Invalid config type "${configType}", expected ${_Object$keys__default["default"](LOADED_CONFIG_TYPES).toString()}`);
|
|
1045
1042
|
}
|
|
1046
1043
|
const isValid = validation(config);
|
|
1047
1044
|
if (!isValid) {
|
|
@@ -1054,9 +1051,9 @@ const validateEntryPointUriPath = config => {
|
|
|
1054
1051
|
}
|
|
1055
1052
|
};
|
|
1056
1053
|
const validateSubmenuLinks = config => {
|
|
1057
|
-
var
|
|
1054
|
+
var _context;
|
|
1058
1055
|
const uriPathSet = new _Set__default["default"]();
|
|
1059
|
-
_forEachInstanceProperty__default["default"](
|
|
1056
|
+
_forEachInstanceProperty__default["default"](_context = config.submenuLinks).call(_context, _ref => {
|
|
1060
1057
|
let uriPath = _ref.uriPath;
|
|
1061
1058
|
if (uriPathSet.has(uriPath)) {
|
|
1062
1059
|
throw new Error('Duplicate URI path. Every submenu link must have a unique URI path value');
|
|
@@ -1065,64 +1062,63 @@ const validateSubmenuLinks = config => {
|
|
|
1065
1062
|
});
|
|
1066
1063
|
};
|
|
1067
1064
|
const validateAdditionalOAuthScopes = config => {
|
|
1068
|
-
var
|
|
1065
|
+
var _context2, _context3;
|
|
1069
1066
|
const additionalPermissionNames = new _Set__default["default"]();
|
|
1070
|
-
(
|
|
1067
|
+
((_context2 = config.additionalOAuthScopes) == null ? void 0 : _bindInstanceProperty__default["default"](_context3 = Function.call).call(_context3, _forEachInstanceProperty__default["default"](_context2), _context2))?.(_ref2 => {
|
|
1071
1068
|
let name = _ref2.name,
|
|
1072
1069
|
view = _ref2.view,
|
|
1073
1070
|
manage = _ref2.manage;
|
|
1074
1071
|
if ((_Array$isArray__default["default"](view) && view.length === 0 || !view) && (_Array$isArray__default["default"](manage) && manage.length === 0 || !manage)) {
|
|
1075
|
-
throw new Error(
|
|
1072
|
+
throw new Error(`At least one OAuth Scope for permission group name "${name}" is required`);
|
|
1076
1073
|
} else if (additionalPermissionNames.has(name)) {
|
|
1077
|
-
throw new Error(
|
|
1074
|
+
throw new Error(`Duplicate additional permission group name "${name}". Every additional permission must have a unique name`);
|
|
1078
1075
|
}
|
|
1079
1076
|
if (!name.match(constants.PERMISSION_GROUP_NAME_REGEX)) {
|
|
1080
|
-
throw new Error(
|
|
1077
|
+
throw new Error(`Additional permission group name "${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`);
|
|
1081
1078
|
}
|
|
1082
1079
|
additionalPermissionNames.add(name);
|
|
1083
1080
|
});
|
|
1084
1081
|
};
|
|
1085
1082
|
|
|
1086
1083
|
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; }
|
|
1087
|
-
function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var
|
|
1084
|
+
function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var _context6, _context7; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context6 = ownKeys$1(Object(t), !0)).call(_context6, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context7 = ownKeys$1(Object(t))).call(_context7, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
1088
1085
|
|
|
1089
1086
|
// The `uriPath` of each submenu link is supposed to be defined relative
|
|
1090
1087
|
// to the `entryPointUriPath`. Computing the full path is done internally to keep
|
|
1091
1088
|
// the configuration simple.
|
|
1092
1089
|
const computeUriPath = (uriPath, entryPointUriPath) => {
|
|
1093
|
-
var _context;
|
|
1094
1090
|
// In case the `uriPath` is only `/`, it means that the link is supposed to be
|
|
1095
1091
|
// treated the same as the main application path. In this case, the return value
|
|
1096
1092
|
// should not contain any unnecessary trailing slash and therefore we use the `entryPointUriPath`.
|
|
1097
1093
|
if (uriPath === '/') return entryPointUriPath;
|
|
1098
1094
|
// In case the `uriPath` is already configured including the `entryPointUriPath`,
|
|
1099
1095
|
// we return the `uriPath` as-is.
|
|
1100
|
-
if (_startsWithInstanceProperty__default["default"](uriPath).call(uriPath,
|
|
1096
|
+
if (_startsWithInstanceProperty__default["default"](uriPath).call(uriPath, `${entryPointUriPath}/`)) return uriPath;
|
|
1101
1097
|
// Return the full path including the `entryPointUriPath` as a prefix.
|
|
1102
|
-
return
|
|
1098
|
+
return `${entryPointUriPath}/${uriPath}`;
|
|
1103
1099
|
};
|
|
1104
1100
|
const getPermissions = appConfig => {
|
|
1105
|
-
var _context2,
|
|
1106
|
-
const additionalResourceAccessKeyToOauthScopeMap = _reduceInstanceProperty__default["default"](
|
|
1101
|
+
var _context, _context2, _context3, _context4;
|
|
1102
|
+
const additionalResourceAccessKeyToOauthScopeMap = _reduceInstanceProperty__default["default"](_context = appConfig.additionalOAuthScopes || []).call(_context, (previousOauthScope, _ref) => {
|
|
1107
1103
|
let name = _ref.name,
|
|
1108
1104
|
view = _ref.view,
|
|
1109
1105
|
manage = _ref.manage;
|
|
1110
1106
|
const formattedResourceKey = formatters.formatEntryPointUriPathToResourceAccessKey(name);
|
|
1111
1107
|
return _objectSpread$1(_objectSpread$1({}, previousOauthScope), {}, {
|
|
1112
|
-
[
|
|
1113
|
-
[
|
|
1108
|
+
[`view${formattedResourceKey}`]: view,
|
|
1109
|
+
[`manage${formattedResourceKey}`]: manage
|
|
1114
1110
|
});
|
|
1115
1111
|
}, {});
|
|
1116
|
-
const additionalPermissionNames = ((
|
|
1112
|
+
const additionalPermissionNames = ((_context2 = appConfig.additionalOAuthScopes) == null ? void 0 : _bindInstanceProperty__default["default"](_context3 = Function.call).call(_context3, _mapInstanceProperty__default["default"](_context2), _context2))?.(_ref2 => {
|
|
1117
1113
|
let name = _ref2.name;
|
|
1118
1114
|
return name;
|
|
1119
|
-
})
|
|
1115
|
+
}) || [];
|
|
1120
1116
|
const permissionKeys = formatters.entryPointUriPathToResourceAccesses(appConfig.entryPointUriPath ||
|
|
1121
1117
|
// In case the `entryPointUriPath` is not defined it is because the
|
|
1122
1118
|
// configuration is for a custom view. In this case we use the
|
|
1123
1119
|
// default entry point uri path.
|
|
1124
1120
|
constants.CUSTOM_VIEW_HOST_ENTRY_POINT_URI_PATH, additionalPermissionNames);
|
|
1125
|
-
const additionalPermissions = _mapInstanceProperty__default["default"](
|
|
1121
|
+
const additionalPermissions = _mapInstanceProperty__default["default"](_context4 = _Object$keys__default["default"](additionalResourceAccessKeyToOauthScopeMap)).call(_context4, additionalResourceAccessKey => ({
|
|
1126
1122
|
name: permissionKeys[additionalResourceAccessKey],
|
|
1127
1123
|
oAuthScopes: additionalResourceAccessKeyToOauthScopeMap[additionalResourceAccessKey]
|
|
1128
1124
|
}));
|
|
@@ -1135,7 +1131,7 @@ const getPermissions = appConfig => {
|
|
|
1135
1131
|
}, ...additionalPermissions];
|
|
1136
1132
|
};
|
|
1137
1133
|
function transformCustomApplicationConfigToData(appConfig) {
|
|
1138
|
-
var
|
|
1134
|
+
var _context5;
|
|
1139
1135
|
validateEntryPointUriPath(appConfig);
|
|
1140
1136
|
validateSubmenuLinks(appConfig);
|
|
1141
1137
|
validateAdditionalOAuthScopes(appConfig);
|
|
@@ -1148,7 +1144,7 @@ function transformCustomApplicationConfigToData(appConfig) {
|
|
|
1148
1144
|
permissions: getPermissions(appConfig),
|
|
1149
1145
|
icon: appConfig.icon,
|
|
1150
1146
|
mainMenuLink: appConfig.mainMenuLink,
|
|
1151
|
-
submenuLinks: _mapInstanceProperty__default["default"](
|
|
1147
|
+
submenuLinks: _mapInstanceProperty__default["default"](_context5 = appConfig.submenuLinks).call(_context5, submenuLink => _objectSpread$1(_objectSpread$1({}, submenuLink), {}, {
|
|
1152
1148
|
uriPath: computeUriPath(submenuLink.uriPath, appConfig.entryPointUriPath)
|
|
1153
1149
|
}))
|
|
1154
1150
|
};
|
|
@@ -1173,12 +1169,11 @@ function transformConfigurationToData(configType, configuration) {
|
|
|
1173
1169
|
} else if (configType === LOADED_CONFIG_TYPES.CUSTOM_VIEW) {
|
|
1174
1170
|
return transformCustomViewConfigToData(configuration);
|
|
1175
1171
|
} else {
|
|
1176
|
-
throw new Error(
|
|
1172
|
+
throw new Error(`Invalid config type: ${configType}`);
|
|
1177
1173
|
}
|
|
1178
1174
|
}
|
|
1179
1175
|
|
|
1180
1176
|
const mapCloudIdentifierToApiUrl = key => {
|
|
1181
|
-
var _context;
|
|
1182
1177
|
switch (key) {
|
|
1183
1178
|
case CLOUD_IDENTIFIERS.GCP_AU:
|
|
1184
1179
|
return MC_API_URLS[CLOUD_IDENTIFIERS.GCP_AU];
|
|
@@ -1195,7 +1190,7 @@ const mapCloudIdentifierToApiUrl = key => {
|
|
|
1195
1190
|
default:
|
|
1196
1191
|
// We would probably never get to this point, as the JSON schema validation
|
|
1197
1192
|
// kicks in before.
|
|
1198
|
-
throw new Error(
|
|
1193
|
+
throw new Error(`Unknown cloud identifier "${key}". Supported values: ${_Object$values__default["default"](CLOUD_IDENTIFIERS).toString()}`);
|
|
1199
1194
|
}
|
|
1200
1195
|
};
|
|
1201
1196
|
const getUniqueValues = function () {
|
|
@@ -1219,10 +1214,10 @@ const getOrThrow = (fn, errorMessage) => {
|
|
|
1219
1214
|
};
|
|
1220
1215
|
|
|
1221
1216
|
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; }
|
|
1222
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var
|
|
1217
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context2, _context3; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context2 = ownKeys(Object(t), !0)).call(_context2, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context3 = ownKeys(Object(t))).call(_context3, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
1223
1218
|
// TODO: make it configurable.
|
|
1224
1219
|
const developmentPort = 3001;
|
|
1225
|
-
const developmentAppUrl =
|
|
1220
|
+
const developmentAppUrl = `http://localhost:${developmentPort}`;
|
|
1226
1221
|
const getLoadedConfigurationType = configFileName => {
|
|
1227
1222
|
if (_includesInstanceProperty__default["default"](configFileName).call(configFileName, 'custom-view-config')) {
|
|
1228
1223
|
return LOADED_CONFIG_TYPES.CUSTOM_VIEW;
|
|
@@ -1238,7 +1233,6 @@ const omitDevConfigIfEmpty = devConfig => {
|
|
|
1238
1233
|
};
|
|
1239
1234
|
const isCustomViewData = data => data.entryPointUriPath === undefined;
|
|
1240
1235
|
const getRuntimeEnvironmentConfigForDevelopment = _ref => {
|
|
1241
|
-
var _appConfig$env$develo;
|
|
1242
1236
|
let isProd = _ref.isProd,
|
|
1243
1237
|
configurationData = _ref.configurationData,
|
|
1244
1238
|
mcApiUrl = _ref.mcApiUrl,
|
|
@@ -1255,7 +1249,7 @@ const getRuntimeEnvironmentConfigForDevelopment = _ref => {
|
|
|
1255
1249
|
initialProjectKey:
|
|
1256
1250
|
// For the `account` application, we should unset the projectKey.
|
|
1257
1251
|
entryPointUriPath === 'account' ? undefined : appConfig.env.development.initialProjectKey
|
|
1258
|
-
},
|
|
1252
|
+
}, appConfig.env.development?.teamId && _objectSpread({
|
|
1259
1253
|
teamId: appConfig.env.development.teamId
|
|
1260
1254
|
}, isCustomViewData(configurationData) ? {
|
|
1261
1255
|
customViewId: configurationData.id
|
|
@@ -1263,12 +1257,11 @@ const getRuntimeEnvironmentConfigForDevelopment = _ref => {
|
|
|
1263
1257
|
applicationId: configurationData.id
|
|
1264
1258
|
})), {}, {
|
|
1265
1259
|
oAuthScopes: appConfig.oAuthScopes,
|
|
1266
|
-
additionalOAuthScopes: appConfig
|
|
1260
|
+
additionalOAuthScopes: appConfig?.additionalOAuthScopes
|
|
1267
1261
|
}));
|
|
1268
1262
|
if (isCustomViewData(configurationData)) {
|
|
1269
|
-
var _context;
|
|
1270
1263
|
const hostUriPath = appConfig.env.development.hostUriPath;
|
|
1271
|
-
const defaultHostUriPath = oidcConfig.initialProjectKey ?
|
|
1264
|
+
const defaultHostUriPath = oidcConfig.initialProjectKey ? `/${oidcConfig.initialProjectKey}/${entryPointUriPath}` : `/${entryPointUriPath}`;
|
|
1272
1265
|
const hostUrl = new _URL__default["default"](hostUriPath || defaultHostUriPath, developmentAppUrl);
|
|
1273
1266
|
return omitDevConfigIfEmpty({
|
|
1274
1267
|
oidc: oidcConfig,
|
|
@@ -1290,7 +1283,6 @@ const getRuntimeEnvironmentConfigForDevelopment = _ref => {
|
|
|
1290
1283
|
});
|
|
1291
1284
|
};
|
|
1292
1285
|
const getRuntimeEnvironmentConfig = _ref2 => {
|
|
1293
|
-
var _context2;
|
|
1294
1286
|
let isProd = _ref2.isProd,
|
|
1295
1287
|
configurationData = _ref2.configurationData,
|
|
1296
1288
|
additionalAppEnv = _ref2.additionalAppEnv,
|
|
@@ -1309,7 +1301,7 @@ const getRuntimeEnvironmentConfig = _ref2 => {
|
|
|
1309
1301
|
// In development, we prefix the entry point with the "__local" prefix.
|
|
1310
1302
|
// This is important to determine to which URL the MC should redirect to
|
|
1311
1303
|
// after successful login.
|
|
1312
|
-
const applicationIdentifier = isProd ?
|
|
1304
|
+
const applicationIdentifier = isProd ? `${configurationData.id}:${entryPointUriPath}` : `__local:${entryPointUriPath}`;
|
|
1313
1305
|
const developmentConfig = getRuntimeEnvironmentConfigForDevelopment({
|
|
1314
1306
|
isProd,
|
|
1315
1307
|
configurationData,
|
|
@@ -1341,7 +1333,7 @@ const getRuntimeEnvironmentConfig = _ref2 => {
|
|
|
1341
1333
|
// again will result in returning the cached value.
|
|
1342
1334
|
let cachedConfig;
|
|
1343
1335
|
const processConfig = async function () {
|
|
1344
|
-
var
|
|
1336
|
+
var _context;
|
|
1345
1337
|
let _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
1346
1338
|
_ref3$disableCache = _ref3.disableCache,
|
|
1347
1339
|
disableCache = _ref3$disableCache === void 0 ? false : _ref3$disableCache,
|
|
@@ -1360,22 +1352,22 @@ const processConfig = async function () {
|
|
|
1360
1352
|
processEnv
|
|
1361
1353
|
});
|
|
1362
1354
|
const configurationData = transformConfigurationToData(configType, appConfig);
|
|
1363
|
-
const appEnvKey =
|
|
1355
|
+
const appEnvKey = processEnv.MC_APP_ENV ?? processEnv.NODE_ENV ?? 'development';
|
|
1364
1356
|
const isProd = getIsProd(processEnv);
|
|
1365
|
-
const additionalAppEnv =
|
|
1366
|
-
const revision =
|
|
1357
|
+
const additionalAppEnv = appConfig.additionalEnv ?? {};
|
|
1358
|
+
const revision = additionalAppEnv.revision ?? '';
|
|
1367
1359
|
|
|
1368
1360
|
// Parse all the supported URLs, which gets implicitly validated
|
|
1369
1361
|
|
|
1370
1362
|
const envAppUrl = isProd ? configurationData.url : developmentAppUrl;
|
|
1371
|
-
const appUrl = getOrThrow(() => new _URL__default["default"](envAppUrl),
|
|
1363
|
+
const appUrl = getOrThrow(() => new _URL__default["default"](envAppUrl), `Invalid application URL: "${envAppUrl}"`);
|
|
1372
1364
|
|
|
1373
1365
|
// Use `||` instead of `??` to include empty string values.
|
|
1374
1366
|
const envCdnUrl = isProd ? appConfig.env.production.cdnUrl || appUrl.href : developmentAppUrl;
|
|
1375
|
-
const cdnUrl = getOrThrow(() => new _URL__default["default"](envCdnUrl),
|
|
1367
|
+
const cdnUrl = getOrThrow(() => new _URL__default["default"](envCdnUrl), `Invalid application CDN URL: "${envCdnUrl}"`);
|
|
1376
1368
|
const mcApiUrl = getOrThrow(() => new _URL__default["default"](
|
|
1377
1369
|
// Use `||` instead of `??` to include empty string values.
|
|
1378
|
-
appConfig.mcApiUrl || mapCloudIdentifierToApiUrl(appConfig.cloudIdentifier)),
|
|
1370
|
+
appConfig.mcApiUrl || mapCloudIdentifierToApiUrl(appConfig.cloudIdentifier)), `Invalid MC API URL: "${appConfig.mcApiUrl}"`);
|
|
1379
1371
|
cachedConfig = {
|
|
1380
1372
|
data: configurationData,
|
|
1381
1373
|
env: getRuntimeEnvironmentConfig({
|
|
@@ -1390,16 +1382,16 @@ const processConfig = async function () {
|
|
|
1390
1382
|
revision
|
|
1391
1383
|
}),
|
|
1392
1384
|
headers: _objectSpread(_objectSpread({}, appConfig.headers), {}, {
|
|
1393
|
-
csp: _objectSpread(_objectSpread({},
|
|
1385
|
+
csp: _objectSpread(_objectSpread({}, appConfig.headers?.csp), {}, {
|
|
1394
1386
|
// We need to make sure the URL we use in these CSP headers have a slash in the end,
|
|
1395
1387
|
// otherwise it might create an invalid value when application/CDN URL points to a
|
|
1396
1388
|
// non-root directory (ex: https://www.my-domain.com/app). This is a valid URL but from
|
|
1397
1389
|
// the CSP point of view, it will say only the file `app` can be used as a source, so
|
|
1398
1390
|
// any other file from that domain will be forbidden. Using the slash (ex: https://www.my-domain.com/app/)
|
|
1399
1391
|
// at the end it's like using a wildcard so anything 'below' `app` will be allowed.
|
|
1400
|
-
'connect-src': getUniqueValues(
|
|
1401
|
-
'script-src': getUniqueValues(
|
|
1402
|
-
'style-src': getUniqueValues(
|
|
1392
|
+
'connect-src': getUniqueValues(appConfig.headers?.csp?.['connect-src'], _concatInstanceProperty__default["default"](_context = [mcApiUrl.origin]).call(_context, isProd ? [`${trimTrailingSlash(appUrl.href)}/`, `${trimTrailingSlash(cdnUrl.href)}/`] : [])),
|
|
1393
|
+
'script-src': getUniqueValues(appConfig.headers?.csp?.['script-src'], isProd ? [`${trimTrailingSlash(appUrl.href)}/`, `${trimTrailingSlash(cdnUrl.href)}/`] : []),
|
|
1394
|
+
'style-src': getUniqueValues(appConfig.headers?.csp?.['style-src'], isProd ? [`${trimTrailingSlash(appUrl.href)}/`, `${trimTrailingSlash(cdnUrl.href)}/`] : [])
|
|
1403
1395
|
})
|
|
1404
1396
|
})
|
|
1405
1397
|
};
|