@commercetools-frontend/application-config 22.2.0 → 22.3.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 +58 -127
- package/dist/commercetools-frontend-application-config.cjs.prod.js +58 -127
- package/dist/commercetools-frontend-application-config.esm.js +58 -127
- package/dist/{formatters-a0d40c36.esm.js → formatters-3609951b.esm.js} +13 -22
- package/dist/{formatters-a6cf66a7.cjs.dev.js → formatters-4f8eba33.cjs.prod.js} +13 -22
- package/dist/{formatters-b42c3866.cjs.prod.js → formatters-c6356c75.cjs.dev.js} +13 -22
- package/package.json +24 -10
- package/scripts/load-js-module.js +0 -0
- package/ssr/dist/commercetools-frontend-application-config-ssr.cjs.dev.js +1 -1
- package/ssr/dist/commercetools-frontend-application-config-ssr.cjs.prod.js +1 -1
- package/ssr/dist/commercetools-frontend-application-config-ssr.esm.js +1 -1
|
@@ -32,7 +32,7 @@ var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/string
|
|
|
32
32
|
var _startsWithInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/starts-with');
|
|
33
33
|
var _reduceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
|
|
34
34
|
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
|
|
35
|
-
var formatters = require('./formatters-
|
|
35
|
+
var formatters = require('./formatters-c6356c75.cjs.dev.js');
|
|
36
36
|
var _Set = require('@babel/runtime-corejs3/core-js-stable/set');
|
|
37
37
|
var _Array$isArray = require('@babel/runtime-corejs3/core-js-stable/array/is-array');
|
|
38
38
|
var Ajv = require('ajv');
|
|
@@ -74,28 +74,19 @@ var uniq__default = /*#__PURE__*/_interopDefault(uniq);
|
|
|
74
74
|
var createDOMPurify__default = /*#__PURE__*/_interopDefault(createDOMPurify);
|
|
75
75
|
|
|
76
76
|
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); }; }
|
|
77
|
-
|
|
78
77
|
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; } }
|
|
79
|
-
|
|
80
78
|
let MissingOrInvalidConfigError = /*#__PURE__*/function (_Error) {
|
|
81
79
|
_inherits(MissingOrInvalidConfigError, _Error);
|
|
82
|
-
|
|
83
80
|
var _super = _createSuper(MissingOrInvalidConfigError);
|
|
84
|
-
|
|
85
81
|
function MissingOrInvalidConfigError(message) {
|
|
86
82
|
var _this;
|
|
87
|
-
|
|
88
83
|
_classCallCheck(this, MissingOrInvalidConfigError);
|
|
89
|
-
|
|
90
84
|
_this = _super.call(this, message);
|
|
91
|
-
|
|
92
85
|
_Object$defineProperty__default["default"](_assertThisInitialized(_this), 'name', {
|
|
93
86
|
value: 'MissingOrInvalidConfigError'
|
|
94
87
|
});
|
|
95
|
-
|
|
96
88
|
return _this;
|
|
97
89
|
}
|
|
98
|
-
|
|
99
90
|
return _createClass(MissingOrInvalidConfigError);
|
|
100
91
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
101
92
|
|
|
@@ -103,30 +94,27 @@ let MissingOrInvalidConfigError = /*#__PURE__*/function (_Error) {
|
|
|
103
94
|
// for instance in respect to both source files and dist files.
|
|
104
95
|
const findPackageRootPath = dir => {
|
|
105
96
|
const packageJsonPath = path__default["default"].join(dir, 'package.json');
|
|
106
|
-
|
|
107
97
|
if (fs__default["default"].existsSync(packageJsonPath)) {
|
|
108
98
|
return dir;
|
|
109
99
|
}
|
|
110
|
-
|
|
111
100
|
const parentDir = path__default["default"].join(dir, '..');
|
|
112
101
|
return findPackageRootPath(parentDir);
|
|
113
102
|
};
|
|
114
|
-
|
|
115
103
|
const loadJsModule = filePath => {
|
|
116
|
-
const packageRootPath = findPackageRootPath(
|
|
117
|
-
|
|
104
|
+
const packageRootPath = findPackageRootPath(
|
|
105
|
+
// Start from the parent folder
|
|
106
|
+
path__default["default"].join(__dirname, '..'));
|
|
107
|
+
// Load the JS module using a child process. This is primarly to avoid
|
|
118
108
|
// unwanted behaviors using `@babel/register` in the main process.
|
|
119
109
|
// The loader script does the actual `require` of the given `filePath`
|
|
120
110
|
// and uses `@babel/register` to correctly parse and execute the file.
|
|
121
111
|
// The "required module output" is then written into `stdout` and parsed
|
|
122
112
|
// as JSON.
|
|
123
|
-
|
|
124
113
|
const output = child_process.execFileSync('node', [path__default["default"].join(packageRootPath, 'scripts/load-js-module.js'), filePath], {
|
|
125
114
|
encoding: 'utf8'
|
|
126
115
|
});
|
|
127
116
|
return JSON.parse(output);
|
|
128
117
|
};
|
|
129
|
-
|
|
130
118
|
const moduleName = 'custom-application-config';
|
|
131
119
|
const explorer = cosmiconfig.cosmiconfigSync(moduleName, {
|
|
132
120
|
// Restrict the supported file formats / names
|
|
@@ -141,24 +129,21 @@ const explorer = cosmiconfig.cosmiconfigSync(moduleName, {
|
|
|
141
129
|
});
|
|
142
130
|
const getConfigPath = () => {
|
|
143
131
|
const configFile = explorer.search();
|
|
144
|
-
|
|
145
132
|
if (!configFile) {
|
|
146
133
|
throw new Error("Missing or invalid Custom Application configuration file.");
|
|
147
134
|
}
|
|
148
|
-
|
|
149
135
|
return configFile.filepath;
|
|
150
136
|
};
|
|
151
|
-
|
|
152
137
|
const loadConfig = applicationPath => {
|
|
153
138
|
const configFile = explorer.search(applicationPath);
|
|
154
|
-
|
|
155
139
|
if (!configFile || !configFile.config) {
|
|
156
140
|
throw new MissingOrInvalidConfigError("Missing or invalid Custom Application configuration file.");
|
|
157
141
|
}
|
|
158
|
-
|
|
159
142
|
return configFile.config;
|
|
160
143
|
};
|
|
161
144
|
|
|
145
|
+
// Transifex's Structured JSON format.
|
|
146
|
+
// https://help.transifex.com/en/articles/6220899-structured-json
|
|
162
147
|
/**
|
|
163
148
|
* NOTE:
|
|
164
149
|
* Allows variable placeholders. Supported types are:
|
|
@@ -170,70 +155,52 @@ const variableSyntax = /\${([ ~:\w.'",\-/()@]+?)}/g;
|
|
|
170
155
|
const envRefSyntax = /^env:/g;
|
|
171
156
|
const intlRefSyntax = /^intl:/g;
|
|
172
157
|
const filePathRefSyntax = /^path:/g;
|
|
173
|
-
|
|
174
|
-
|
|
158
|
+
const hasVariablePlaceholder = valueOfEnvConfig => typeof valueOfEnvConfig === 'string' &&
|
|
159
|
+
// Using `{regex}.test()` might cause false positives if called multiple
|
|
175
160
|
// times on a global regular expression:
|
|
176
161
|
// See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test
|
|
177
162
|
// As with exec() (or in combination with it), test() called multiple times
|
|
178
163
|
// on the same global regular expression instance will advance past the previous match.
|
|
179
164
|
Boolean(valueOfEnvConfig.match(variableSyntax));
|
|
180
|
-
|
|
181
165
|
const isEnvVariablePlaceholder = valueOfPlaceholder => Boolean(valueOfPlaceholder.match(envRefSyntax));
|
|
182
|
-
|
|
183
166
|
const isIntlVariablePlaceholder = valueOfPlaceholder => Boolean(valueOfPlaceholder.match(intlRefSyntax));
|
|
184
|
-
|
|
185
167
|
const isFilePathVariablePlaceholder = valueOfPlaceholder => Boolean(valueOfPlaceholder.match(filePathRefSyntax));
|
|
186
|
-
|
|
187
168
|
const isStructuredJson = message => (message === null || message === void 0 ? void 0 : message.string) !== undefined;
|
|
188
|
-
|
|
189
169
|
const substituteEnvVariablePlaceholder = (valueOfPlaceholder, matchedString, valueOfEnvConfig, loadingOptions) => {
|
|
190
170
|
const _valueOfPlaceholder$s = valueOfPlaceholder.split(':'),
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
171
|
+
_valueOfPlaceholder$s2 = _slicedToArray(_valueOfPlaceholder$s, 2),
|
|
172
|
+
requestedEnvVar = _valueOfPlaceholder$s2[1];
|
|
194
173
|
const hasEnvField = loadingOptions.processEnv.hasOwnProperty(requestedEnvVar);
|
|
195
|
-
|
|
196
174
|
if (!hasEnvField) {
|
|
197
175
|
var _context;
|
|
198
|
-
|
|
199
176
|
throw new Error(_concatInstanceProperty__default["default"](_context = "Missing environment variable '".concat(requestedEnvVar, "' specified in config as 'env:")).call(_context, requestedEnvVar, "'."));
|
|
200
177
|
}
|
|
201
|
-
|
|
202
178
|
const escapedMatchedString = matchedString.replace(/[${}:]/g, '\\$&');
|
|
203
179
|
return valueOfEnvConfig.replace(new RegExp("(".concat(escapedMatchedString, ")+"), 'g'), loadingOptions.processEnv[requestedEnvVar]);
|
|
204
180
|
};
|
|
205
|
-
|
|
206
181
|
const substituteIntlVariablePlaceholder = (valueOfPlaceholder, matchedString, valueOfEnvConfig, loadingOptions) => {
|
|
207
182
|
const _valueOfPlaceholder$s3 = valueOfPlaceholder.split(':'),
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
183
|
+
_valueOfPlaceholder$s4 = _slicedToArray(_valueOfPlaceholder$s3, 3),
|
|
184
|
+
locale = _valueOfPlaceholder$s4[1],
|
|
185
|
+
requestedIntlMessageId = _valueOfPlaceholder$s4[2];
|
|
212
186
|
const translationsFilePath = require.resolve("./i18n/data/".concat(locale, ".json"), {
|
|
213
187
|
paths: ["".concat(loadingOptions.applicationPath, "/src"), loadingOptions.applicationPath]
|
|
214
188
|
});
|
|
215
|
-
|
|
216
189
|
const translations = require(translationsFilePath);
|
|
217
|
-
|
|
218
190
|
const hasIntlMessage = translations.hasOwnProperty(requestedIntlMessageId);
|
|
219
|
-
|
|
220
191
|
if (!hasIntlMessage) {
|
|
221
192
|
var _context2, _context3;
|
|
222
|
-
|
|
223
193
|
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, "'."));
|
|
224
194
|
}
|
|
225
|
-
|
|
226
195
|
const translation = translations[requestedIntlMessageId];
|
|
227
196
|
const translationValue = isStructuredJson(translation) ? translation.string : translation;
|
|
228
197
|
const escapedMatchedString = matchedString.replace(/[${}:]/g, '\\$&');
|
|
229
198
|
return valueOfEnvConfig.replace(new RegExp("(".concat(escapedMatchedString, ")+"), 'g'), translationValue);
|
|
230
199
|
};
|
|
231
|
-
|
|
232
200
|
const substituteFilePathVariablePlaceholder = (valueOfPlaceholder, matchedString, valueOfEnvConfig, loadingOptions) => {
|
|
233
201
|
const _valueOfPlaceholder$s5 = valueOfPlaceholder.split(':'),
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
202
|
+
_valueOfPlaceholder$s6 = _slicedToArray(_valueOfPlaceholder$s5, 2),
|
|
203
|
+
filePathOrModule = _valueOfPlaceholder$s6[1];
|
|
237
204
|
const content = fs__default["default"].readFileSync(require.resolve(filePathOrModule, {
|
|
238
205
|
// Relative paths should be resolved from the application folder.
|
|
239
206
|
paths: [loadingOptions.applicationPath]
|
|
@@ -243,20 +210,15 @@ const substituteFilePathVariablePlaceholder = (valueOfPlaceholder, matchedString
|
|
|
243
210
|
const escapedMatchedString = matchedString.replace(/[${}:]/g, '\\$&');
|
|
244
211
|
return valueOfEnvConfig.replace(new RegExp("(".concat(escapedMatchedString, ")+"), 'g'), content);
|
|
245
212
|
};
|
|
246
|
-
|
|
247
213
|
const getValueOfPlaceholder = valueWithPlaceholder => valueWithPlaceholder.replace(variableSyntax, (_match, varName) => _trimInstanceProperty__default["default"](varName).call(varName)).replace(/\s/g, '');
|
|
248
|
-
|
|
249
214
|
const substituteVariablePlaceholders = (config, loadingOptions) => JSON.parse(_JSON$stringify__default["default"](config), (_key, value) => {
|
|
250
215
|
// Only strings are allowed
|
|
251
216
|
let substitutedValue = value;
|
|
252
|
-
|
|
253
217
|
if (hasVariablePlaceholder(substitutedValue)) {
|
|
254
218
|
const matchResult = substitutedValue.match(variableSyntax);
|
|
255
|
-
|
|
256
219
|
if (matchResult) {
|
|
257
220
|
_forEachInstanceProperty__default["default"](matchResult).call(matchResult, matchedString => {
|
|
258
221
|
const valueOfPlaceholder = getValueOfPlaceholder(matchedString);
|
|
259
|
-
|
|
260
222
|
if (isEnvVariablePlaceholder(valueOfPlaceholder)) {
|
|
261
223
|
substitutedValue = substituteEnvVariablePlaceholder(valueOfPlaceholder, matchedString, substitutedValue, loadingOptions);
|
|
262
224
|
} else if (isIntlVariablePlaceholder(valueOfPlaceholder)) {
|
|
@@ -267,7 +229,6 @@ const substituteVariablePlaceholders = (config, loadingOptions) => JSON.parse(_J
|
|
|
267
229
|
});
|
|
268
230
|
}
|
|
269
231
|
}
|
|
270
|
-
|
|
271
232
|
return substitutedValue;
|
|
272
233
|
});
|
|
273
234
|
|
|
@@ -629,10 +590,10 @@ var schemaJson = {
|
|
|
629
590
|
* non-consecutive underscores and hyphens. Leading and trailing underscore and hyphens are also not allowed.
|
|
630
591
|
*/
|
|
631
592
|
const ENTRY_POINT_URI_PATH_REGEX = /^[^-_#]([0-9a-z]|[-_](?![-_])){0,62}[^-_#]$/g;
|
|
593
|
+
|
|
632
594
|
/**
|
|
633
595
|
* The permission group name may be between 2 and 64 characters and only contain alphanumeric lowercase characters and non-consecutive hyphens. Leading and trailing hyphens are also not allowed.
|
|
634
596
|
*/
|
|
635
|
-
|
|
636
597
|
const PERMISSION_GROUP_NAME_REGEX = /^[^-#]([a-z]|[-](?![-])){0,62}[^-#]$/g;
|
|
637
598
|
const CLOUD_IDENTIFIERS = {
|
|
638
599
|
GCP_AU: 'gcp-au',
|
|
@@ -654,33 +615,25 @@ const ajv = new Ajv__default["default"]({
|
|
|
654
615
|
useDefaults: true
|
|
655
616
|
});
|
|
656
617
|
const validate = ajv.compile(schemaJson);
|
|
657
|
-
|
|
658
618
|
const printErrors = errors => {
|
|
659
619
|
if (!errors) {
|
|
660
620
|
return 'No errors';
|
|
661
621
|
}
|
|
662
|
-
|
|
663
622
|
return _mapInstanceProperty__default["default"](errors).call(errors, error => {
|
|
664
623
|
var _context, _context2, _context3;
|
|
665
|
-
|
|
666
624
|
const baseMessage = _concatInstanceProperty__default["default"](_context = "".concat(error.instancePath, " ")).call(_context, error.message);
|
|
667
|
-
|
|
668
625
|
switch (error.keyword) {
|
|
669
626
|
case 'additionalProperties':
|
|
670
627
|
return _concatInstanceProperty__default["default"](_context2 = "".concat(baseMessage, ": ")).call(_context2, error.params.additionalProperty);
|
|
671
|
-
|
|
672
628
|
case 'enum':
|
|
673
629
|
return _concatInstanceProperty__default["default"](_context3 = "".concat(baseMessage, ": ")).call(_context3, error.params.allowedValues.toString());
|
|
674
|
-
|
|
675
630
|
default:
|
|
676
631
|
return baseMessage;
|
|
677
632
|
}
|
|
678
633
|
}).join('\n');
|
|
679
634
|
};
|
|
680
|
-
|
|
681
635
|
const validateConfig = config => {
|
|
682
636
|
const valid = validate(config);
|
|
683
|
-
|
|
684
637
|
if (!valid) {
|
|
685
638
|
throw new Error(printErrors(validate.errors));
|
|
686
639
|
}
|
|
@@ -692,87 +645,73 @@ const validateEntryPointUriPath = config => {
|
|
|
692
645
|
};
|
|
693
646
|
const validateSubmenuLinks = config => {
|
|
694
647
|
var _context4;
|
|
695
|
-
|
|
696
648
|
const uriPathSet = new _Set__default["default"]();
|
|
697
|
-
|
|
698
649
|
_forEachInstanceProperty__default["default"](_context4 = config.submenuLinks).call(_context4, _ref => {
|
|
699
650
|
let uriPath = _ref.uriPath;
|
|
700
|
-
|
|
701
651
|
if (uriPathSet.has(uriPath)) {
|
|
702
652
|
throw new Error('Duplicate URI path. Every submenu link must have a unique URI path value');
|
|
703
653
|
}
|
|
704
|
-
|
|
705
654
|
uriPathSet.add(uriPath);
|
|
706
655
|
});
|
|
707
656
|
};
|
|
708
657
|
const validateAdditionalOAuthScopes = config => {
|
|
709
658
|
var _config$additionalOAu;
|
|
710
|
-
|
|
711
659
|
const additionalPermissionNames = new _Set__default["default"]();
|
|
712
660
|
(_config$additionalOAu = config.additionalOAuthScopes) === null || _config$additionalOAu === void 0 ? void 0 : _forEachInstanceProperty__default["default"](_config$additionalOAu).call(_config$additionalOAu, _ref2 => {
|
|
713
661
|
let name = _ref2.name,
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
662
|
+
view = _ref2.view,
|
|
663
|
+
manage = _ref2.manage;
|
|
717
664
|
if ((_Array$isArray__default["default"](view) && view.length === 0 || !view) && (_Array$isArray__default["default"](manage) && manage.length === 0 || !manage)) {
|
|
718
665
|
throw new Error("At least one OAuth Scope for permission group name \"".concat(name, "\" is required"));
|
|
719
666
|
} else if (additionalPermissionNames.has(name)) {
|
|
720
667
|
throw new Error("Duplicate additional permission group name \"".concat(name, "\". Every additional permission must have a unique name"));
|
|
721
668
|
}
|
|
722
|
-
|
|
723
669
|
if (!name.match(PERMISSION_GROUP_NAME_REGEX)) {
|
|
724
670
|
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"));
|
|
725
671
|
}
|
|
726
|
-
|
|
727
672
|
additionalPermissionNames.add(name);
|
|
728
673
|
});
|
|
729
674
|
};
|
|
730
675
|
|
|
731
676
|
function ownKeys$1(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); 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; }
|
|
732
|
-
|
|
733
677
|
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var _context5, _context6; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context5 = ownKeys$1(Object(source), !0)).call(_context5, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context6 = ownKeys$1(Object(source))).call(_context6, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
|
|
678
|
+
|
|
679
|
+
// The `uriPath` of each submenu link is supposed to be defined relative
|
|
734
680
|
// to the `entryPointUriPath`. Computing the full path is done internally to keep
|
|
735
681
|
// the configuration simple.
|
|
736
|
-
|
|
737
682
|
const computeUriPath = (uriPath, entryPointUriPath) => {
|
|
738
683
|
var _context;
|
|
739
|
-
|
|
740
684
|
// In case the `uriPath` is only `/`, it means that the link is supposed to be
|
|
741
685
|
// treated the same as the main application path. In this case, the return value
|
|
742
686
|
// should not contain any unnecessary trailing slash and therefore we use the `entryPointUriPath`.
|
|
743
|
-
if (uriPath === '/') return entryPointUriPath;
|
|
687
|
+
if (uriPath === '/') return entryPointUriPath;
|
|
688
|
+
// In case the `uriPath` is already configured including the `entryPointUriPath`,
|
|
744
689
|
// we return the `uriPath` as-is.
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
690
|
+
if (_startsWithInstanceProperty__default["default"](uriPath).call(uriPath, "".concat(entryPointUriPath, "/"))) return uriPath;
|
|
691
|
+
// Return the full path including the `entryPointUriPath` as a prefix.
|
|
748
692
|
return _concatInstanceProperty__default["default"](_context = "".concat(entryPointUriPath, "/")).call(_context, uriPath);
|
|
749
693
|
};
|
|
750
|
-
|
|
751
694
|
const getPermissions = appConfig => {
|
|
752
695
|
var _context2, _appConfig$additional, _context3;
|
|
753
|
-
|
|
754
696
|
const additionalResourceAccessKeyToOauthScopeMap = _reduceInstanceProperty__default["default"](_context2 = appConfig.additionalOAuthScopes || []).call(_context2, (previousOauthScope, _ref) => {
|
|
755
697
|
let name = _ref.name,
|
|
756
|
-
|
|
757
|
-
|
|
698
|
+
view = _ref.view,
|
|
699
|
+
manage = _ref.manage;
|
|
758
700
|
const formattedResourceKey = formatters.formatEntryPointUriPathToResourceAccessKey(name);
|
|
759
701
|
return _objectSpread$1(_objectSpread$1({}, previousOauthScope), {}, {
|
|
760
702
|
["view".concat(formattedResourceKey)]: view,
|
|
761
703
|
["manage".concat(formattedResourceKey)]: manage
|
|
762
704
|
});
|
|
763
705
|
}, {});
|
|
764
|
-
|
|
765
706
|
const additionalPermissionNames = ((_appConfig$additional = appConfig.additionalOAuthScopes) === null || _appConfig$additional === void 0 ? void 0 : _mapInstanceProperty__default["default"](_appConfig$additional).call(_appConfig$additional, _ref2 => {
|
|
766
707
|
let name = _ref2.name;
|
|
767
708
|
return name;
|
|
768
709
|
})) || [];
|
|
769
710
|
const permissionKeys = formatters.entryPointUriPathToResourceAccesses(appConfig.entryPointUriPath, additionalPermissionNames);
|
|
770
|
-
|
|
771
711
|
const additionalPermissions = _mapInstanceProperty__default["default"](_context3 = _Object$keys__default["default"](additionalResourceAccessKeyToOauthScopeMap)).call(_context3, additionalResourceAccessKey => ({
|
|
772
712
|
name: permissionKeys[additionalResourceAccessKey],
|
|
773
713
|
oAuthScopes: additionalResourceAccessKeyToOauthScopeMap[additionalResourceAccessKey]
|
|
774
714
|
}));
|
|
775
|
-
|
|
776
715
|
return [{
|
|
777
716
|
name: permissionKeys.view,
|
|
778
717
|
oAuthScopes: appConfig.oAuthScopes.view
|
|
@@ -781,10 +720,8 @@ const getPermissions = appConfig => {
|
|
|
781
720
|
oAuthScopes: appConfig.oAuthScopes.manage
|
|
782
721
|
}, ...additionalPermissions];
|
|
783
722
|
};
|
|
784
|
-
|
|
785
723
|
function transformCustomApplicationConfigToData(appConfig) {
|
|
786
724
|
var _context4;
|
|
787
|
-
|
|
788
725
|
validateEntryPointUriPath(appConfig);
|
|
789
726
|
validateSubmenuLinks(appConfig);
|
|
790
727
|
validateAdditionalOAuthScopes(appConfig);
|
|
@@ -805,44 +742,35 @@ function transformCustomApplicationConfigToData(appConfig) {
|
|
|
805
742
|
|
|
806
743
|
const mapCloudIdentifierToApiUrl = key => {
|
|
807
744
|
var _context;
|
|
808
|
-
|
|
809
745
|
switch (key) {
|
|
810
746
|
case CLOUD_IDENTIFIERS.GCP_AU:
|
|
811
747
|
return MC_API_URLS.GCP_AU;
|
|
812
|
-
|
|
813
748
|
case CLOUD_IDENTIFIERS.GCP_EU:
|
|
814
749
|
return MC_API_URLS.GCP_EU;
|
|
815
|
-
|
|
816
750
|
case CLOUD_IDENTIFIERS.GCP_US:
|
|
817
751
|
return MC_API_URLS.GCP_US;
|
|
818
|
-
|
|
819
752
|
case CLOUD_IDENTIFIERS.AWS_FRA:
|
|
820
753
|
return MC_API_URLS.AWS_FRA;
|
|
821
|
-
|
|
822
754
|
case CLOUD_IDENTIFIERS.AWS_OHIO:
|
|
823
755
|
return MC_API_URLS.AWS_OHIO;
|
|
824
|
-
|
|
825
756
|
default:
|
|
826
757
|
// We would probably never get to this point, as the JSON schema validation
|
|
827
758
|
// kicks in before.
|
|
828
759
|
throw new Error(_concatInstanceProperty__default["default"](_context = "Unknown cloud identifier \"".concat(key, "\". Supported values: ")).call(_context, _Object$values__default["default"](CLOUD_IDENTIFIERS).toString()));
|
|
829
760
|
}
|
|
830
761
|
};
|
|
831
|
-
|
|
832
762
|
const getUniqueValues = function () {
|
|
833
763
|
let initialValues = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
834
764
|
let additionalValues = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
835
765
|
return uniq__default["default"]([...initialValues, ...additionalValues]);
|
|
836
766
|
};
|
|
837
|
-
|
|
838
767
|
const nonProductionEnvironment = ['development', 'test'];
|
|
839
|
-
|
|
840
|
-
|
|
768
|
+
const getIsProd = env =>
|
|
769
|
+
// TL;DR: in case the `MC_APP_ENV` is defined, we consider that it's
|
|
841
770
|
// a production environment unless it's one of `development` or `test`.
|
|
842
771
|
// This allows to use for example the `staging` value, which from the
|
|
843
772
|
// application perspective is still considered a production environment.
|
|
844
773
|
env.MC_APP_ENV ? !_includesInstanceProperty__default["default"](nonProductionEnvironment).call(nonProductionEnvironment, env.MC_APP_ENV) : env.NODE_ENV === 'production';
|
|
845
|
-
|
|
846
774
|
const getOrThrow = (fn, errorMessage) => {
|
|
847
775
|
try {
|
|
848
776
|
return fn();
|
|
@@ -852,35 +780,30 @@ const getOrThrow = (fn, errorMessage) => {
|
|
|
852
780
|
};
|
|
853
781
|
|
|
854
782
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); 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; }
|
|
855
|
-
|
|
856
783
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context3, _context4; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context3 = ownKeys(Object(source), !0)).call(_context3, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _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; }
|
|
857
784
|
// TODO: make it configurable.
|
|
858
785
|
const developmentPort = 3001;
|
|
859
786
|
const developmentAppUrl = "http://localhost:".concat(developmentPort);
|
|
860
|
-
|
|
861
787
|
const trimTrailingSlash = value => value.replace(/\/$/, '');
|
|
862
|
-
|
|
863
788
|
const omitDevConfigIfEmpty = devConfig => {
|
|
864
|
-
if (
|
|
789
|
+
if (
|
|
790
|
+
// @ts-expect-error: the `accountLinks` is not explicitly typed as it's only used by the account app.
|
|
865
791
|
devConfig !== null && devConfig !== void 0 && devConfig.accountLinks || devConfig !== null && devConfig !== void 0 && devConfig.menuLinks || devConfig !== null && devConfig !== void 0 && devConfig.oidc) return devConfig;
|
|
866
792
|
return undefined;
|
|
867
|
-
};
|
|
868
|
-
// again will result in returning the cached value.
|
|
869
|
-
|
|
793
|
+
};
|
|
870
794
|
|
|
795
|
+
// Keep a reference to the config so that requiring the module
|
|
796
|
+
// again will result in returning the cached value.
|
|
871
797
|
let cachedConfig;
|
|
872
|
-
|
|
873
798
|
const processConfig = function () {
|
|
874
799
|
var _ref2, _processEnv$MC_APP_EN, _appConfig$additional, _ref3, _context, _appConfig$env$develo, _appConfig$headers, _appConfig$headers2, _appConfig$headers2$c, _context2, _appConfig$headers3, _appConfig$headers3$c, _appConfig$headers4, _appConfig$headers4$c;
|
|
875
|
-
|
|
876
800
|
let _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
801
|
+
_ref$disableCache = _ref.disableCache,
|
|
802
|
+
disableCache = _ref$disableCache === void 0 ? false : _ref$disableCache,
|
|
803
|
+
_ref$processEnv = _ref.processEnv,
|
|
804
|
+
processEnv = _ref$processEnv === void 0 ? process.env : _ref$processEnv,
|
|
805
|
+
_ref$applicationPath = _ref.applicationPath,
|
|
806
|
+
applicationPath = _ref$applicationPath === void 0 ? fs__default["default"].realpathSync(process.cwd()) : _ref$applicationPath;
|
|
884
807
|
if (cachedConfig && !disableCache) return cachedConfig;
|
|
885
808
|
const rawConfig = loadConfig(applicationPath);
|
|
886
809
|
validateConfig(rawConfig);
|
|
@@ -892,26 +815,33 @@ const processConfig = function () {
|
|
|
892
815
|
const 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';
|
|
893
816
|
const isProd = getIsProd(processEnv);
|
|
894
817
|
const additionalAppEnv = (_appConfig$additional = appConfig.additionalEnv) !== null && _appConfig$additional !== void 0 ? _appConfig$additional : {};
|
|
895
|
-
const revision = (_ref3 = additionalAppEnv.revision) !== null && _ref3 !== void 0 ? _ref3 : '';
|
|
818
|
+
const revision = (_ref3 = additionalAppEnv.revision) !== null && _ref3 !== void 0 ? _ref3 : '';
|
|
819
|
+
|
|
820
|
+
// Parse all the supported URLs, which gets implicitly validated
|
|
896
821
|
|
|
897
822
|
const envAppUrl = isProd ? customApplicationData.url : developmentAppUrl;
|
|
898
|
-
const appUrl = getOrThrow(() => new _URL__default["default"](envAppUrl), "Invalid application URL: \"".concat(envAppUrl, "\""));
|
|
823
|
+
const appUrl = getOrThrow(() => new _URL__default["default"](envAppUrl), "Invalid application URL: \"".concat(envAppUrl, "\""));
|
|
899
824
|
|
|
825
|
+
// Use `||` instead of `??` to include empty string values.
|
|
900
826
|
const envCdnUrl = isProd ? appConfig.env.production.cdnUrl || appUrl.href : developmentAppUrl;
|
|
901
827
|
const cdnUrl = getOrThrow(() => new _URL__default["default"](envCdnUrl), "Invalid application CDN URL: \"".concat(envCdnUrl, "\""));
|
|
902
|
-
const mcApiUrl = getOrThrow(() => new _URL__default["default"](
|
|
903
|
-
|
|
828
|
+
const mcApiUrl = getOrThrow(() => new _URL__default["default"](
|
|
829
|
+
// Use `||` instead of `??` to include empty string values.
|
|
830
|
+
appConfig.mcApiUrl || mapCloudIdentifierToApiUrl(appConfig.cloudIdentifier)), "Invalid MC API URL: \"".concat(appConfig.mcApiUrl, "\""));
|
|
831
|
+
|
|
832
|
+
// The real application ID is only used in production.
|
|
904
833
|
// In development, we prefix the entry point with the "__local" prefix.
|
|
905
834
|
// This is important to determine to which URL the MC should redirect to
|
|
906
835
|
// after successful login.
|
|
907
|
-
|
|
908
836
|
const applicationId = isProd ? _concatInstanceProperty__default["default"](_context = "".concat(customApplicationData.id, ":")).call(_context, customApplicationData.entryPointUriPath) : "__local:".concat(customApplicationData.entryPointUriPath);
|
|
909
837
|
const developmentConfig = isProd ? undefined : omitDevConfigIfEmpty({
|
|
910
838
|
oidc: omitEmpty__default["default"]({
|
|
911
|
-
authorizeUrl: [
|
|
839
|
+
authorizeUrl: [
|
|
840
|
+
// In case the MC API url points to localhost, we need to point
|
|
912
841
|
// to a local running dev login page to handle the workflow properly.
|
|
913
842
|
mcApiUrl.hostname === 'localhost' ? mcApiUrl.origin.replace(mcApiUrl.port, String(developmentPort)) : mcApiUrl.origin.replace('mc-api', 'mc'), '/login/authorize'].join(''),
|
|
914
|
-
initialProjectKey:
|
|
843
|
+
initialProjectKey:
|
|
844
|
+
// For the `account` application, we should unset the projectKey.
|
|
915
845
|
customApplicationData.entryPointUriPath === 'account' ? undefined : appConfig.env.development.initialProjectKey,
|
|
916
846
|
teamId: (_appConfig$env$develo = appConfig.env.development) === null || _appConfig$env$develo === void 0 ? void 0 : _appConfig$env$develo.teamId,
|
|
917
847
|
oAuthScopes: appConfig.oAuthScopes,
|
|
@@ -959,8 +889,8 @@ const processConfig = function () {
|
|
|
959
889
|
return cachedConfig;
|
|
960
890
|
};
|
|
961
891
|
|
|
962
|
-
const jsdom = new jsdom$1.JSDOM('');
|
|
963
|
-
|
|
892
|
+
const jsdom = new jsdom$1.JSDOM('');
|
|
893
|
+
// @ts-expect-error: jsdom returns DOMWindow, which doesn't match Window dompurify expects
|
|
964
894
|
const DOMPurify = createDOMPurify__default["default"](jsdom.window);
|
|
965
895
|
function sanitizeSvg(data) {
|
|
966
896
|
return DOMPurify.sanitize(data, {
|
|
@@ -968,7 +898,8 @@ function sanitizeSvg(data) {
|
|
|
968
898
|
svg: true
|
|
969
899
|
},
|
|
970
900
|
RETURN_DOM: true,
|
|
971
|
-
FORBID_ATTR: [
|
|
901
|
+
FORBID_ATTR: [
|
|
902
|
+
// To avoid injection by using `style="filter:url(\"data:image/svg+xml,<svg`
|
|
972
903
|
'style']
|
|
973
904
|
}).innerHTML;
|
|
974
905
|
}
|