@commercetools-frontend/application-config 21.23.10 → 21.24.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 +259 -286
- package/dist/commercetools-frontend-application-config.cjs.prod.js +259 -286
- package/dist/commercetools-frontend-application-config.esm.js +255 -282
- package/dist/declarations/src/types.d.ts +1 -1
- package/dist/{formatters-cf2cd8ed.esm.js → formatters-a0d40c36.esm.js} +18 -13
- package/dist/{formatters-88de943a.cjs.prod.js → formatters-a6cf66a7.cjs.dev.js} +18 -13
- package/dist/{formatters-d2c7b577.cjs.dev.js → formatters-b42c3866.cjs.prod.js} +18 -13
- package/package.json +3 -3
- 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
|
@@ -11,8 +11,8 @@ import _Object$defineProperties from '@babel/runtime-corejs3/core-js-stable/obje
|
|
|
11
11
|
import _Object$defineProperty from '@babel/runtime-corejs3/core-js-stable/object/define-property';
|
|
12
12
|
import fs from 'fs';
|
|
13
13
|
import omitEmpty from 'omit-empty-es';
|
|
14
|
-
import path from 'path';
|
|
15
14
|
import { execFileSync } from 'child_process';
|
|
15
|
+
import path from 'path';
|
|
16
16
|
import { cosmiconfigSync, defaultLoaders } from 'cosmiconfig';
|
|
17
17
|
import _Reflect$construct from '@babel/runtime-corejs3/core-js-stable/reflect/construct';
|
|
18
18
|
import _createClass from '@babel/runtime-corejs3/helpers/esm/createClass';
|
|
@@ -22,20 +22,19 @@ import _inherits from '@babel/runtime-corejs3/helpers/esm/inherits';
|
|
|
22
22
|
import _possibleConstructorReturn from '@babel/runtime-corejs3/helpers/esm/possibleConstructorReturn';
|
|
23
23
|
import _getPrototypeOf from '@babel/runtime-corejs3/helpers/esm/getPrototypeOf';
|
|
24
24
|
import _wrapNativeSuper from '@babel/runtime-corejs3/helpers/esm/wrapNativeSuper';
|
|
25
|
+
import _slicedToArray from '@babel/runtime-corejs3/helpers/esm/slicedToArray';
|
|
26
|
+
import _trimInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/trim';
|
|
27
|
+
import _JSON$stringify from '@babel/runtime-corejs3/core-js-stable/json/stringify';
|
|
28
|
+
import _startsWithInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/starts-with';
|
|
29
|
+
import _reduceInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/reduce';
|
|
25
30
|
import _mapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/map';
|
|
31
|
+
import { f as formatEntryPointUriPathToResourceAccessKey, e as entryPointUriPathToResourceAccesses } from './formatters-a0d40c36.esm.js';
|
|
26
32
|
import _Set from '@babel/runtime-corejs3/core-js-stable/set';
|
|
27
33
|
import _Array$isArray from '@babel/runtime-corejs3/core-js-stable/array/is-array';
|
|
28
34
|
import Ajv from 'ajv';
|
|
29
|
-
import _slicedToArray from '@babel/runtime-corejs3/helpers/esm/slicedToArray';
|
|
30
|
-
import _trimInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/trim';
|
|
31
|
-
import _JSON$stringify from '@babel/runtime-corejs3/core-js-stable/json/stringify';
|
|
32
|
-
import _toConsumableArray from '@babel/runtime-corejs3/helpers/esm/toConsumableArray';
|
|
33
35
|
import _Object$values from '@babel/runtime-corejs3/core-js-stable/object/values';
|
|
34
36
|
import _includesInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/includes';
|
|
35
37
|
import uniq from 'lodash/uniq';
|
|
36
|
-
import _startsWithInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/starts-with';
|
|
37
|
-
import _reduceInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/reduce';
|
|
38
|
-
import { f as formatEntryPointUriPathToResourceAccessKey, e as entryPointUriPathToResourceAccesses } from './formatters-cf2cd8ed.esm.js';
|
|
39
38
|
import createDOMPurify from 'dompurify';
|
|
40
39
|
import { JSDOM } from 'jsdom';
|
|
41
40
|
import '@babel/runtime-corejs3/core-js-stable/object/entries';
|
|
@@ -45,7 +44,7 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflec
|
|
|
45
44
|
|
|
46
45
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct) return false; if (_Reflect$construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
47
46
|
|
|
48
|
-
|
|
47
|
+
let MissingOrInvalidConfigError = /*#__PURE__*/function (_Error) {
|
|
49
48
|
_inherits(MissingOrInvalidConfigError, _Error);
|
|
50
49
|
|
|
51
50
|
var _super = _createSuper(MissingOrInvalidConfigError);
|
|
@@ -67,21 +66,21 @@ var MissingOrInvalidConfigError = /*#__PURE__*/function (_Error) {
|
|
|
67
66
|
return _createClass(MissingOrInvalidConfigError);
|
|
68
67
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
69
68
|
|
|
69
|
+
// Helper function to find the package root path from the current location,
|
|
70
70
|
// for instance in respect to both source files and dist files.
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
var packageJsonPath = path.join(dir, 'package.json');
|
|
71
|
+
const findPackageRootPath = dir => {
|
|
72
|
+
const packageJsonPath = path.join(dir, 'package.json');
|
|
74
73
|
|
|
75
74
|
if (fs.existsSync(packageJsonPath)) {
|
|
76
75
|
return dir;
|
|
77
76
|
}
|
|
78
77
|
|
|
79
|
-
|
|
78
|
+
const parentDir = path.join(dir, '..');
|
|
80
79
|
return findPackageRootPath(parentDir);
|
|
81
80
|
};
|
|
82
81
|
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
const loadJsModule = filePath => {
|
|
83
|
+
const packageRootPath = findPackageRootPath( // Start from the parent folder
|
|
85
84
|
path.join(__dirname, '..')); // Load the JS module using a child process. This is primarly to avoid
|
|
86
85
|
// unwanted behaviors using `@babel/register` in the main process.
|
|
87
86
|
// The loader script does the actual `require` of the given `filePath`
|
|
@@ -89,14 +88,14 @@ var loadJsModule = function loadJsModule(filePath) {
|
|
|
89
88
|
// The "required module output" is then written into `stdout` and parsed
|
|
90
89
|
// as JSON.
|
|
91
90
|
|
|
92
|
-
|
|
91
|
+
const output = execFileSync('node', [path.join(packageRootPath, 'scripts/load-js-module.js'), filePath], {
|
|
93
92
|
encoding: 'utf8'
|
|
94
93
|
});
|
|
95
94
|
return JSON.parse(output);
|
|
96
95
|
};
|
|
97
96
|
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
const moduleName = 'custom-application-config';
|
|
98
|
+
const explorer = cosmiconfigSync(moduleName, {
|
|
100
99
|
// Restrict the supported file formats / names
|
|
101
100
|
searchPlaces: [".".concat(moduleName, "rc"), ".".concat(moduleName, ".json"), ".".concat(moduleName, ".js"), ".".concat(moduleName, ".cjs"), ".".concat(moduleName, ".mjs"), ".".concat(moduleName, ".ts"), "".concat(moduleName, ".json"), "".concat(moduleName, ".js"), "".concat(moduleName, ".cjs"), "".concat(moduleName, ".mjs"), "".concat(moduleName, ".ts")],
|
|
102
101
|
loaders: {
|
|
@@ -107,8 +106,8 @@ var explorer = cosmiconfigSync(moduleName, {
|
|
|
107
106
|
'.ts': loadJsModule
|
|
108
107
|
}
|
|
109
108
|
});
|
|
110
|
-
|
|
111
|
-
|
|
109
|
+
const getConfigPath = () => {
|
|
110
|
+
const configFile = explorer.search();
|
|
112
111
|
|
|
113
112
|
if (!configFile) {
|
|
114
113
|
throw new Error("Missing or invalid Custom Application configuration file.");
|
|
@@ -117,8 +116,8 @@ var getConfigPath = function getConfigPath() {
|
|
|
117
116
|
return configFile.filepath;
|
|
118
117
|
};
|
|
119
118
|
|
|
120
|
-
|
|
121
|
-
|
|
119
|
+
const loadConfig = applicationPath => {
|
|
120
|
+
const configFile = explorer.search(applicationPath);
|
|
122
121
|
|
|
123
122
|
if (!configFile || !configFile.config) {
|
|
124
123
|
throw new MissingOrInvalidConfigError("Missing or invalid Custom Application configuration file.");
|
|
@@ -127,6 +126,118 @@ var loadConfig = function loadConfig(applicationPath) {
|
|
|
127
126
|
return configFile.config;
|
|
128
127
|
};
|
|
129
128
|
|
|
129
|
+
/**
|
|
130
|
+
* NOTE:
|
|
131
|
+
* Allows variable placeholders. Supported types are:
|
|
132
|
+
* - `env`: For example `${env:MC_API_URL}`.
|
|
133
|
+
* - `intl`: For example `${intl:en:Menu.title}`.
|
|
134
|
+
* - `path`: For example `${path:./app.svg}`, or `${path:@commercetools-frontend/assets/application-icons/rocket.svg}`.
|
|
135
|
+
*/
|
|
136
|
+
const variableSyntax = /\${([ ~:\w.'",\-/()@]+?)}/g;
|
|
137
|
+
const envRefSyntax = /^env:/g;
|
|
138
|
+
const intlRefSyntax = /^intl:/g;
|
|
139
|
+
const filePathRefSyntax = /^path:/g;
|
|
140
|
+
|
|
141
|
+
const hasVariablePlaceholder = valueOfEnvConfig => typeof valueOfEnvConfig === 'string' && // Using `{regex}.test()` might cause false positives if called multiple
|
|
142
|
+
// times on a global regular expression:
|
|
143
|
+
// See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test
|
|
144
|
+
// As with exec() (or in combination with it), test() called multiple times
|
|
145
|
+
// on the same global regular expression instance will advance past the previous match.
|
|
146
|
+
Boolean(valueOfEnvConfig.match(variableSyntax));
|
|
147
|
+
|
|
148
|
+
const isEnvVariablePlaceholder = valueOfPlaceholder => Boolean(valueOfPlaceholder.match(envRefSyntax));
|
|
149
|
+
|
|
150
|
+
const isIntlVariablePlaceholder = valueOfPlaceholder => Boolean(valueOfPlaceholder.match(intlRefSyntax));
|
|
151
|
+
|
|
152
|
+
const isFilePathVariablePlaceholder = valueOfPlaceholder => Boolean(valueOfPlaceholder.match(filePathRefSyntax));
|
|
153
|
+
|
|
154
|
+
const isStructuredJson = message => (message === null || message === void 0 ? void 0 : message.string) !== undefined;
|
|
155
|
+
|
|
156
|
+
const substituteEnvVariablePlaceholder = (valueOfPlaceholder, matchedString, valueOfEnvConfig, loadingOptions) => {
|
|
157
|
+
const _valueOfPlaceholder$s = valueOfPlaceholder.split(':'),
|
|
158
|
+
_valueOfPlaceholder$s2 = _slicedToArray(_valueOfPlaceholder$s, 2),
|
|
159
|
+
requestedEnvVar = _valueOfPlaceholder$s2[1];
|
|
160
|
+
|
|
161
|
+
const hasEnvField = loadingOptions.processEnv.hasOwnProperty(requestedEnvVar);
|
|
162
|
+
|
|
163
|
+
if (!hasEnvField) {
|
|
164
|
+
var _context;
|
|
165
|
+
|
|
166
|
+
throw new Error(_concatInstanceProperty(_context = "Missing environment variable '".concat(requestedEnvVar, "' specified in config as 'env:")).call(_context, requestedEnvVar, "'."));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const escapedMatchedString = matchedString.replace(/[${}:]/g, '\\$&');
|
|
170
|
+
return valueOfEnvConfig.replace(new RegExp("(".concat(escapedMatchedString, ")+"), 'g'), loadingOptions.processEnv[requestedEnvVar]);
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
const substituteIntlVariablePlaceholder = (valueOfPlaceholder, matchedString, valueOfEnvConfig, loadingOptions) => {
|
|
174
|
+
const _valueOfPlaceholder$s3 = valueOfPlaceholder.split(':'),
|
|
175
|
+
_valueOfPlaceholder$s4 = _slicedToArray(_valueOfPlaceholder$s3, 3),
|
|
176
|
+
locale = _valueOfPlaceholder$s4[1],
|
|
177
|
+
requestedIntlMessageId = _valueOfPlaceholder$s4[2];
|
|
178
|
+
|
|
179
|
+
const translationsFilePath = require.resolve("./i18n/data/".concat(locale, ".json"), {
|
|
180
|
+
paths: ["".concat(loadingOptions.applicationPath, "/src"), loadingOptions.applicationPath]
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
const translations = require(translationsFilePath);
|
|
184
|
+
|
|
185
|
+
const hasIntlMessage = translations.hasOwnProperty(requestedIntlMessageId);
|
|
186
|
+
|
|
187
|
+
if (!hasIntlMessage) {
|
|
188
|
+
var _context2, _context3;
|
|
189
|
+
|
|
190
|
+
throw new Error(_concatInstanceProperty(_context2 = _concatInstanceProperty(_context3 = "Missing message key '".concat(requestedIntlMessageId, "' specified in config as 'intl:")).call(_context3, locale, ":")).call(_context2, requestedIntlMessageId, "'."));
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const translation = translations[requestedIntlMessageId];
|
|
194
|
+
const translationValue = isStructuredJson(translation) ? translation.string : translation;
|
|
195
|
+
const escapedMatchedString = matchedString.replace(/[${}:]/g, '\\$&');
|
|
196
|
+
return valueOfEnvConfig.replace(new RegExp("(".concat(escapedMatchedString, ")+"), 'g'), translationValue);
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
const substituteFilePathVariablePlaceholder = (valueOfPlaceholder, matchedString, valueOfEnvConfig, loadingOptions) => {
|
|
200
|
+
const _valueOfPlaceholder$s5 = valueOfPlaceholder.split(':'),
|
|
201
|
+
_valueOfPlaceholder$s6 = _slicedToArray(_valueOfPlaceholder$s5, 2),
|
|
202
|
+
filePathOrModule = _valueOfPlaceholder$s6[1];
|
|
203
|
+
|
|
204
|
+
const content = fs.readFileSync(require.resolve(filePathOrModule, {
|
|
205
|
+
// Relative paths should be resolved from the application folder.
|
|
206
|
+
paths: [loadingOptions.applicationPath]
|
|
207
|
+
}), {
|
|
208
|
+
encoding: 'utf-8'
|
|
209
|
+
});
|
|
210
|
+
const escapedMatchedString = matchedString.replace(/[${}:]/g, '\\$&');
|
|
211
|
+
return valueOfEnvConfig.replace(new RegExp("(".concat(escapedMatchedString, ")+"), 'g'), content);
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
const getValueOfPlaceholder = valueWithPlaceholder => valueWithPlaceholder.replace(variableSyntax, (_match, varName) => _trimInstanceProperty(varName).call(varName)).replace(/\s/g, '');
|
|
215
|
+
|
|
216
|
+
const substituteVariablePlaceholders = (config, loadingOptions) => JSON.parse(_JSON$stringify(config), (_key, value) => {
|
|
217
|
+
// Only strings are allowed
|
|
218
|
+
let substitutedValue = value;
|
|
219
|
+
|
|
220
|
+
if (hasVariablePlaceholder(substitutedValue)) {
|
|
221
|
+
const matchResult = substitutedValue.match(variableSyntax);
|
|
222
|
+
|
|
223
|
+
if (matchResult) {
|
|
224
|
+
_forEachInstanceProperty(matchResult).call(matchResult, matchedString => {
|
|
225
|
+
const valueOfPlaceholder = getValueOfPlaceholder(matchedString);
|
|
226
|
+
|
|
227
|
+
if (isEnvVariablePlaceholder(valueOfPlaceholder)) {
|
|
228
|
+
substitutedValue = substituteEnvVariablePlaceholder(valueOfPlaceholder, matchedString, substitutedValue, loadingOptions);
|
|
229
|
+
} else if (isIntlVariablePlaceholder(valueOfPlaceholder)) {
|
|
230
|
+
substitutedValue = substituteIntlVariablePlaceholder(valueOfPlaceholder, matchedString, substitutedValue, loadingOptions);
|
|
231
|
+
} else if (isFilePathVariablePlaceholder(valueOfPlaceholder)) {
|
|
232
|
+
substitutedValue = substituteFilePathVariablePlaceholder(valueOfPlaceholder, matchedString, substitutedValue, loadingOptions);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return substitutedValue;
|
|
239
|
+
});
|
|
240
|
+
|
|
130
241
|
var schemaJson = {
|
|
131
242
|
$schema: "http://json-schema.org/draft-07/schema",
|
|
132
243
|
$id: "https://docs.commercetools.com/custom-applications/schema.json",
|
|
@@ -484,20 +595,20 @@ var schemaJson = {
|
|
|
484
595
|
* The entryPointUriPath may be between 2 and 64 characters and only contain alphabetic lowercase characters,
|
|
485
596
|
* non-consecutive underscores and hyphens. Leading and trailing underscore and hyphens are also not allowed.
|
|
486
597
|
*/
|
|
487
|
-
|
|
598
|
+
const ENTRY_POINT_URI_PATH_REGEX = /^[^-_#]([0-9a-z]|[-_](?![-_])){0,62}[^-_#]$/g;
|
|
488
599
|
/**
|
|
489
600
|
* 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.
|
|
490
601
|
*/
|
|
491
602
|
|
|
492
|
-
|
|
493
|
-
|
|
603
|
+
const PERMISSION_GROUP_NAME_REGEX = /^[^-#]([a-z]|[-](?![-])){0,62}[^-#]$/g;
|
|
604
|
+
const CLOUD_IDENTIFIERS = {
|
|
494
605
|
GCP_AU: 'gcp-au',
|
|
495
606
|
GCP_EU: 'gcp-eu',
|
|
496
607
|
GCP_US: 'gcp-us',
|
|
497
608
|
AWS_FRA: 'aws-fra',
|
|
498
609
|
AWS_OHIO: 'aws-ohio'
|
|
499
610
|
};
|
|
500
|
-
|
|
611
|
+
const MC_API_URLS = {
|
|
501
612
|
GCP_AU: 'https://mc-api.australia-southeast1.gcp.commercetools.com',
|
|
502
613
|
GCP_EU: 'https://mc-api.europe-west1.gcp.commercetools.com',
|
|
503
614
|
GCP_US: 'https://mc-api.us-central1.gcp.commercetools.com',
|
|
@@ -505,21 +616,21 @@ var MC_API_URLS = {
|
|
|
505
616
|
AWS_OHIO: 'https://mc-api.us-east-2.aws.commercetools.com'
|
|
506
617
|
};
|
|
507
618
|
|
|
508
|
-
|
|
619
|
+
const ajv = new Ajv({
|
|
509
620
|
strict: true,
|
|
510
621
|
useDefaults: true
|
|
511
622
|
});
|
|
512
|
-
|
|
623
|
+
const validate = ajv.compile(schemaJson);
|
|
513
624
|
|
|
514
|
-
|
|
625
|
+
const printErrors = errors => {
|
|
515
626
|
if (!errors) {
|
|
516
627
|
return 'No errors';
|
|
517
628
|
}
|
|
518
629
|
|
|
519
|
-
return _mapInstanceProperty(errors).call(errors,
|
|
630
|
+
return _mapInstanceProperty(errors).call(errors, error => {
|
|
520
631
|
var _context, _context2, _context3;
|
|
521
632
|
|
|
522
|
-
|
|
633
|
+
const baseMessage = _concatInstanceProperty(_context = "".concat(error.instancePath, " ")).call(_context, error.message);
|
|
523
634
|
|
|
524
635
|
switch (error.keyword) {
|
|
525
636
|
case 'additionalProperties':
|
|
@@ -534,25 +645,25 @@ var printErrors = function printErrors(errors) {
|
|
|
534
645
|
}).join('\n');
|
|
535
646
|
};
|
|
536
647
|
|
|
537
|
-
|
|
538
|
-
|
|
648
|
+
const validateConfig = config => {
|
|
649
|
+
const valid = validate(config);
|
|
539
650
|
|
|
540
651
|
if (!valid) {
|
|
541
652
|
throw new Error(printErrors(validate.errors));
|
|
542
653
|
}
|
|
543
654
|
};
|
|
544
|
-
|
|
655
|
+
const validateEntryPointUriPath = config => {
|
|
545
656
|
if (!config.entryPointUriPath.match(ENTRY_POINT_URI_PATH_REGEX)) {
|
|
546
657
|
throw new Error('Invalid "entryPointUriPath". The value may be between 2 and 64 characters and only contain alphanumeric lowercase characters, non-consecutive underscores and hyphens. Leading and trailing underscores and hyphens are also not allowed.');
|
|
547
658
|
}
|
|
548
659
|
};
|
|
549
|
-
|
|
660
|
+
const validateSubmenuLinks = config => {
|
|
550
661
|
var _context4;
|
|
551
662
|
|
|
552
|
-
|
|
663
|
+
const uriPathSet = new _Set();
|
|
553
664
|
|
|
554
|
-
_forEachInstanceProperty(_context4 = config.submenuLinks).call(_context4,
|
|
555
|
-
|
|
665
|
+
_forEachInstanceProperty(_context4 = config.submenuLinks).call(_context4, _ref => {
|
|
666
|
+
let uriPath = _ref.uriPath;
|
|
556
667
|
|
|
557
668
|
if (uriPathSet.has(uriPath)) {
|
|
558
669
|
throw new Error('Duplicate URI path. Every submenu link must have a unique URI path value');
|
|
@@ -561,12 +672,12 @@ var validateSubmenuLinks = function validateSubmenuLinks(config) {
|
|
|
561
672
|
uriPathSet.add(uriPath);
|
|
562
673
|
});
|
|
563
674
|
};
|
|
564
|
-
|
|
675
|
+
const validateAdditionalOAuthScopes = config => {
|
|
565
676
|
var _config$additionalOAu;
|
|
566
677
|
|
|
567
|
-
|
|
568
|
-
(_config$additionalOAu = config.additionalOAuthScopes) === null || _config$additionalOAu === void 0 ? void 0 : _forEachInstanceProperty(_config$additionalOAu).call(_config$additionalOAu,
|
|
569
|
-
|
|
678
|
+
const additionalPermissionNames = new _Set();
|
|
679
|
+
(_config$additionalOAu = config.additionalOAuthScopes) === null || _config$additionalOAu === void 0 ? void 0 : _forEachInstanceProperty(_config$additionalOAu).call(_config$additionalOAu, _ref2 => {
|
|
680
|
+
let name = _ref2.name,
|
|
570
681
|
view = _ref2.view,
|
|
571
682
|
manage = _ref2.manage;
|
|
572
683
|
|
|
@@ -584,188 +695,13 @@ var validateAdditionalOAuthScopes = function validateAdditionalOAuthScopes(confi
|
|
|
584
695
|
});
|
|
585
696
|
};
|
|
586
697
|
|
|
587
|
-
/**
|
|
588
|
-
* NOTE:
|
|
589
|
-
* Allows variable placeholders. Supported types are:
|
|
590
|
-
* - `env`: For example `${env:MC_API_URL}`.
|
|
591
|
-
* - `intl`: For example `${intl:en:Menu.title}`.
|
|
592
|
-
* - `path`: For example `${path:./app.svg}`, or `${path:@commercetools-frontend/assets/application-icons/rocket.svg}`.
|
|
593
|
-
*/
|
|
594
|
-
var variableSyntax = /\${([ ~:\w.'",\-/()@]+?)}/g;
|
|
595
|
-
var envRefSyntax = /^env:/g;
|
|
596
|
-
var intlRefSyntax = /^intl:/g;
|
|
597
|
-
var filePathRefSyntax = /^path:/g;
|
|
598
|
-
|
|
599
|
-
var hasVariablePlaceholder = function hasVariablePlaceholder(valueOfEnvConfig) {
|
|
600
|
-
return typeof valueOfEnvConfig === 'string' && // Using `{regex}.test()` might cause false positives if called multiple
|
|
601
|
-
// times on a global regular expression:
|
|
602
|
-
// See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test
|
|
603
|
-
// As with exec() (or in combination with it), test() called multiple times
|
|
604
|
-
// on the same global regular expression instance will advance past the previous match.
|
|
605
|
-
Boolean(valueOfEnvConfig.match(variableSyntax));
|
|
606
|
-
};
|
|
607
|
-
|
|
608
|
-
var isEnvVariablePlaceholder = function isEnvVariablePlaceholder(valueOfPlaceholder) {
|
|
609
|
-
return Boolean(valueOfPlaceholder.match(envRefSyntax));
|
|
610
|
-
};
|
|
611
|
-
|
|
612
|
-
var isIntlVariablePlaceholder = function isIntlVariablePlaceholder(valueOfPlaceholder) {
|
|
613
|
-
return Boolean(valueOfPlaceholder.match(intlRefSyntax));
|
|
614
|
-
};
|
|
615
|
-
|
|
616
|
-
var isFilePathVariablePlaceholder = function isFilePathVariablePlaceholder(valueOfPlaceholder) {
|
|
617
|
-
return Boolean(valueOfPlaceholder.match(filePathRefSyntax));
|
|
618
|
-
};
|
|
619
|
-
|
|
620
|
-
var substituteEnvVariablePlaceholder = function substituteEnvVariablePlaceholder(valueOfPlaceholder, matchedString, valueOfEnvConfig, loadingOptions) {
|
|
621
|
-
var _valueOfPlaceholder$s = valueOfPlaceholder.split(':'),
|
|
622
|
-
_valueOfPlaceholder$s2 = _slicedToArray(_valueOfPlaceholder$s, 2),
|
|
623
|
-
requestedEnvVar = _valueOfPlaceholder$s2[1];
|
|
624
|
-
|
|
625
|
-
var hasEnvField = loadingOptions.processEnv.hasOwnProperty(requestedEnvVar);
|
|
626
|
-
|
|
627
|
-
if (!hasEnvField) {
|
|
628
|
-
var _context;
|
|
629
|
-
|
|
630
|
-
throw new Error(_concatInstanceProperty(_context = "Missing environment variable '".concat(requestedEnvVar, "' specified in config as 'env:")).call(_context, requestedEnvVar, "'."));
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
var escapedMatchedString = matchedString.replace(/[${}:]/g, '\\$&');
|
|
634
|
-
return valueOfEnvConfig.replace(new RegExp("(".concat(escapedMatchedString, ")+"), 'g'), loadingOptions.processEnv[requestedEnvVar]);
|
|
635
|
-
};
|
|
636
|
-
|
|
637
|
-
var substituteIntlVariablePlaceholder = function substituteIntlVariablePlaceholder(valueOfPlaceholder, matchedString, valueOfEnvConfig, loadingOptions) {
|
|
638
|
-
var _valueOfPlaceholder$s3 = valueOfPlaceholder.split(':'),
|
|
639
|
-
_valueOfPlaceholder$s4 = _slicedToArray(_valueOfPlaceholder$s3, 3),
|
|
640
|
-
locale = _valueOfPlaceholder$s4[1],
|
|
641
|
-
requestedIntlMessageId = _valueOfPlaceholder$s4[2];
|
|
642
|
-
|
|
643
|
-
var translationsFilePath = require.resolve("./i18n/data/".concat(locale, ".json"), {
|
|
644
|
-
paths: ["".concat(loadingOptions.applicationPath, "/src"), loadingOptions.applicationPath]
|
|
645
|
-
});
|
|
646
|
-
|
|
647
|
-
var translations = require(translationsFilePath);
|
|
648
|
-
|
|
649
|
-
var hasIntlMessage = translations.hasOwnProperty(requestedIntlMessageId);
|
|
650
|
-
|
|
651
|
-
if (!hasIntlMessage) {
|
|
652
|
-
var _context2, _context3;
|
|
653
|
-
|
|
654
|
-
throw new Error(_concatInstanceProperty(_context2 = _concatInstanceProperty(_context3 = "Missing message key '".concat(requestedIntlMessageId, "' specified in config as 'intl:")).call(_context3, locale, ":")).call(_context2, requestedIntlMessageId, "'."));
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
var escapedMatchedString = matchedString.replace(/[${}:]/g, '\\$&');
|
|
658
|
-
return valueOfEnvConfig.replace(new RegExp("(".concat(escapedMatchedString, ")+"), 'g'), translations[requestedIntlMessageId]);
|
|
659
|
-
};
|
|
660
|
-
|
|
661
|
-
var substituteFilePathVariablePlaceholder = function substituteFilePathVariablePlaceholder(valueOfPlaceholder, matchedString, valueOfEnvConfig, loadingOptions) {
|
|
662
|
-
var _valueOfPlaceholder$s5 = valueOfPlaceholder.split(':'),
|
|
663
|
-
_valueOfPlaceholder$s6 = _slicedToArray(_valueOfPlaceholder$s5, 2),
|
|
664
|
-
filePathOrModule = _valueOfPlaceholder$s6[1];
|
|
665
|
-
|
|
666
|
-
var content = fs.readFileSync(require.resolve(filePathOrModule, {
|
|
667
|
-
// Relative paths should be resolved from the application folder.
|
|
668
|
-
paths: [loadingOptions.applicationPath]
|
|
669
|
-
}), {
|
|
670
|
-
encoding: 'utf-8'
|
|
671
|
-
});
|
|
672
|
-
var escapedMatchedString = matchedString.replace(/[${}:]/g, '\\$&');
|
|
673
|
-
return valueOfEnvConfig.replace(new RegExp("(".concat(escapedMatchedString, ")+"), 'g'), content);
|
|
674
|
-
};
|
|
675
|
-
|
|
676
|
-
var getValueOfPlaceholder = function getValueOfPlaceholder(valueWithPlaceholder) {
|
|
677
|
-
return valueWithPlaceholder.replace(variableSyntax, function (_match, varName) {
|
|
678
|
-
return _trimInstanceProperty(varName).call(varName);
|
|
679
|
-
}).replace(/\s/g, '');
|
|
680
|
-
};
|
|
681
|
-
|
|
682
|
-
var substituteVariablePlaceholders = function substituteVariablePlaceholders(config, loadingOptions) {
|
|
683
|
-
return JSON.parse(_JSON$stringify(config), function (_key, value) {
|
|
684
|
-
// Only strings are allowed
|
|
685
|
-
var substitutedValue = value;
|
|
686
|
-
|
|
687
|
-
if (hasVariablePlaceholder(substitutedValue)) {
|
|
688
|
-
var matchResult = substitutedValue.match(variableSyntax);
|
|
689
|
-
|
|
690
|
-
if (matchResult) {
|
|
691
|
-
_forEachInstanceProperty(matchResult).call(matchResult, function (matchedString) {
|
|
692
|
-
var valueOfPlaceholder = getValueOfPlaceholder(matchedString);
|
|
693
|
-
|
|
694
|
-
if (isEnvVariablePlaceholder(valueOfPlaceholder)) {
|
|
695
|
-
substitutedValue = substituteEnvVariablePlaceholder(valueOfPlaceholder, matchedString, substitutedValue, loadingOptions);
|
|
696
|
-
} else if (isIntlVariablePlaceholder(valueOfPlaceholder)) {
|
|
697
|
-
substitutedValue = substituteIntlVariablePlaceholder(valueOfPlaceholder, matchedString, substitutedValue, loadingOptions);
|
|
698
|
-
} else if (isFilePathVariablePlaceholder(valueOfPlaceholder)) {
|
|
699
|
-
substitutedValue = substituteFilePathVariablePlaceholder(valueOfPlaceholder, matchedString, substitutedValue, loadingOptions);
|
|
700
|
-
}
|
|
701
|
-
});
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
return substitutedValue;
|
|
706
|
-
});
|
|
707
|
-
};
|
|
708
|
-
|
|
709
|
-
var mapCloudIdentifierToApiUrl = function mapCloudIdentifierToApiUrl(key) {
|
|
710
|
-
var _context;
|
|
711
|
-
|
|
712
|
-
switch (key) {
|
|
713
|
-
case CLOUD_IDENTIFIERS.GCP_AU:
|
|
714
|
-
return MC_API_URLS.GCP_AU;
|
|
715
|
-
|
|
716
|
-
case CLOUD_IDENTIFIERS.GCP_EU:
|
|
717
|
-
return MC_API_URLS.GCP_EU;
|
|
718
|
-
|
|
719
|
-
case CLOUD_IDENTIFIERS.GCP_US:
|
|
720
|
-
return MC_API_URLS.GCP_US;
|
|
721
|
-
|
|
722
|
-
case CLOUD_IDENTIFIERS.AWS_FRA:
|
|
723
|
-
return MC_API_URLS.AWS_FRA;
|
|
724
|
-
|
|
725
|
-
case CLOUD_IDENTIFIERS.AWS_OHIO:
|
|
726
|
-
return MC_API_URLS.AWS_OHIO;
|
|
727
|
-
|
|
728
|
-
default:
|
|
729
|
-
// We would probably never get to this point, as the JSON schema validation
|
|
730
|
-
// kicks in before.
|
|
731
|
-
throw new Error(_concatInstanceProperty(_context = "Unknown cloud identifier \"".concat(key, "\". Supported values: ")).call(_context, _Object$values(CLOUD_IDENTIFIERS).toString()));
|
|
732
|
-
}
|
|
733
|
-
};
|
|
734
|
-
|
|
735
|
-
var getUniqueValues = function getUniqueValues() {
|
|
736
|
-
var _context2;
|
|
737
|
-
|
|
738
|
-
var initialValues = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
739
|
-
var additionalValues = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
740
|
-
return uniq(_concatInstanceProperty(_context2 = []).call(_context2, _toConsumableArray(initialValues), _toConsumableArray(additionalValues)));
|
|
741
|
-
};
|
|
742
|
-
|
|
743
|
-
var nonProductionEnvironment = ['development', 'test'];
|
|
744
|
-
|
|
745
|
-
var getIsProd = function getIsProd(env) {
|
|
746
|
-
return (// TL;DR: in case the `MC_APP_ENV` is defined, we consider that it's
|
|
747
|
-
// a production environment unless it's one of `development` or `test`.
|
|
748
|
-
// This allows to use for example the `staging` value, which from the
|
|
749
|
-
// application perspective is still considered a production environment.
|
|
750
|
-
env.MC_APP_ENV ? !_includesInstanceProperty(nonProductionEnvironment).call(nonProductionEnvironment, env.MC_APP_ENV) : env.NODE_ENV === 'production'
|
|
751
|
-
);
|
|
752
|
-
};
|
|
753
|
-
|
|
754
|
-
var getOrThrow = function getOrThrow(fn, errorMessage) {
|
|
755
|
-
try {
|
|
756
|
-
return fn();
|
|
757
|
-
} catch (error) {
|
|
758
|
-
throw new Error(errorMessage);
|
|
759
|
-
}
|
|
760
|
-
};
|
|
761
|
-
|
|
762
698
|
function ownKeys$1(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
763
699
|
|
|
764
|
-
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var
|
|
700
|
+
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(_context5 = ownKeys$1(Object(source), !0)).call(_context5, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context6 = ownKeys$1(Object(source))).call(_context6, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
765
701
|
// to the `entryPointUriPath`. Computing the full path is done internally to keep
|
|
766
702
|
// the configuration simple.
|
|
767
703
|
|
|
768
|
-
|
|
704
|
+
const computeUriPath = (uriPath, entryPointUriPath) => {
|
|
769
705
|
var _context;
|
|
770
706
|
|
|
771
707
|
// In case the `uriPath` is only `/`, it means that the link is supposed to be
|
|
@@ -779,43 +715,42 @@ var computeUriPath = function computeUriPath(uriPath, entryPointUriPath) {
|
|
|
779
715
|
return _concatInstanceProperty(_context = "".concat(entryPointUriPath, "/")).call(_context, uriPath);
|
|
780
716
|
};
|
|
781
717
|
|
|
782
|
-
|
|
783
|
-
var _context2, _appConfig$additional, _context3
|
|
784
|
-
|
|
785
|
-
var additionalResourceAccessKeyToOauthScopeMap = _reduceInstanceProperty(_context2 = appConfig.additionalOAuthScopes || []).call(_context2, function (previousOauthScope, _ref) {
|
|
786
|
-
var _objectSpread2;
|
|
718
|
+
const getPermissions = appConfig => {
|
|
719
|
+
var _context2, _appConfig$additional, _context3;
|
|
787
720
|
|
|
788
|
-
|
|
721
|
+
const additionalResourceAccessKeyToOauthScopeMap = _reduceInstanceProperty(_context2 = appConfig.additionalOAuthScopes || []).call(_context2, (previousOauthScope, _ref) => {
|
|
722
|
+
let name = _ref.name,
|
|
789
723
|
view = _ref.view,
|
|
790
724
|
manage = _ref.manage;
|
|
791
|
-
|
|
792
|
-
return _objectSpread$1(_objectSpread$1({}, previousOauthScope), {},
|
|
725
|
+
const formattedResourceKey = formatEntryPointUriPathToResourceAccessKey(name);
|
|
726
|
+
return _objectSpread$1(_objectSpread$1({}, previousOauthScope), {}, {
|
|
727
|
+
["view".concat(formattedResourceKey)]: view,
|
|
728
|
+
["manage".concat(formattedResourceKey)]: manage
|
|
729
|
+
});
|
|
793
730
|
}, {});
|
|
794
731
|
|
|
795
|
-
|
|
796
|
-
|
|
732
|
+
const additionalPermissionNames = ((_appConfig$additional = appConfig.additionalOAuthScopes) === null || _appConfig$additional === void 0 ? void 0 : _mapInstanceProperty(_appConfig$additional).call(_appConfig$additional, _ref2 => {
|
|
733
|
+
let name = _ref2.name;
|
|
797
734
|
return name;
|
|
798
735
|
})) || [];
|
|
799
|
-
|
|
736
|
+
const permissionKeys = entryPointUriPathToResourceAccesses(appConfig.entryPointUriPath, additionalPermissionNames);
|
|
800
737
|
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
};
|
|
806
|
-
});
|
|
738
|
+
const additionalPermissions = _mapInstanceProperty(_context3 = _Object$keys(additionalResourceAccessKeyToOauthScopeMap)).call(_context3, additionalResourceAccessKey => ({
|
|
739
|
+
name: permissionKeys[additionalResourceAccessKey],
|
|
740
|
+
oAuthScopes: additionalResourceAccessKeyToOauthScopeMap[additionalResourceAccessKey]
|
|
741
|
+
}));
|
|
807
742
|
|
|
808
|
-
return
|
|
743
|
+
return [{
|
|
809
744
|
name: permissionKeys.view,
|
|
810
745
|
oAuthScopes: appConfig.oAuthScopes.view
|
|
811
746
|
}, {
|
|
812
747
|
name: permissionKeys.manage,
|
|
813
748
|
oAuthScopes: appConfig.oAuthScopes.manage
|
|
814
|
-
}
|
|
749
|
+
}, ...additionalPermissions];
|
|
815
750
|
};
|
|
816
751
|
|
|
817
752
|
function transformCustomApplicationConfigToData(appConfig) {
|
|
818
|
-
var
|
|
753
|
+
var _context4;
|
|
819
754
|
|
|
820
755
|
validateEntryPointUriPath(appConfig);
|
|
821
756
|
validateSubmenuLinks(appConfig);
|
|
@@ -829,26 +764,70 @@ function transformCustomApplicationConfigToData(appConfig) {
|
|
|
829
764
|
permissions: getPermissions(appConfig),
|
|
830
765
|
icon: appConfig.icon,
|
|
831
766
|
mainMenuLink: appConfig.mainMenuLink,
|
|
832
|
-
submenuLinks: _mapInstanceProperty(
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
});
|
|
836
|
-
})
|
|
767
|
+
submenuLinks: _mapInstanceProperty(_context4 = appConfig.submenuLinks).call(_context4, submenuLink => _objectSpread$1(_objectSpread$1({}, submenuLink), {}, {
|
|
768
|
+
uriPath: computeUriPath(submenuLink.uriPath, appConfig.entryPointUriPath)
|
|
769
|
+
}))
|
|
837
770
|
};
|
|
838
771
|
}
|
|
839
772
|
|
|
773
|
+
const mapCloudIdentifierToApiUrl = key => {
|
|
774
|
+
var _context;
|
|
775
|
+
|
|
776
|
+
switch (key) {
|
|
777
|
+
case CLOUD_IDENTIFIERS.GCP_AU:
|
|
778
|
+
return MC_API_URLS.GCP_AU;
|
|
779
|
+
|
|
780
|
+
case CLOUD_IDENTIFIERS.GCP_EU:
|
|
781
|
+
return MC_API_URLS.GCP_EU;
|
|
782
|
+
|
|
783
|
+
case CLOUD_IDENTIFIERS.GCP_US:
|
|
784
|
+
return MC_API_URLS.GCP_US;
|
|
785
|
+
|
|
786
|
+
case CLOUD_IDENTIFIERS.AWS_FRA:
|
|
787
|
+
return MC_API_URLS.AWS_FRA;
|
|
788
|
+
|
|
789
|
+
case CLOUD_IDENTIFIERS.AWS_OHIO:
|
|
790
|
+
return MC_API_URLS.AWS_OHIO;
|
|
791
|
+
|
|
792
|
+
default:
|
|
793
|
+
// We would probably never get to this point, as the JSON schema validation
|
|
794
|
+
// kicks in before.
|
|
795
|
+
throw new Error(_concatInstanceProperty(_context = "Unknown cloud identifier \"".concat(key, "\". Supported values: ")).call(_context, _Object$values(CLOUD_IDENTIFIERS).toString()));
|
|
796
|
+
}
|
|
797
|
+
};
|
|
798
|
+
|
|
799
|
+
const getUniqueValues = function () {
|
|
800
|
+
let initialValues = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
801
|
+
let additionalValues = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
802
|
+
return uniq([...initialValues, ...additionalValues]);
|
|
803
|
+
};
|
|
804
|
+
|
|
805
|
+
const nonProductionEnvironment = ['development', 'test'];
|
|
806
|
+
|
|
807
|
+
const getIsProd = env => // TL;DR: in case the `MC_APP_ENV` is defined, we consider that it's
|
|
808
|
+
// a production environment unless it's one of `development` or `test`.
|
|
809
|
+
// This allows to use for example the `staging` value, which from the
|
|
810
|
+
// application perspective is still considered a production environment.
|
|
811
|
+
env.MC_APP_ENV ? !_includesInstanceProperty(nonProductionEnvironment).call(nonProductionEnvironment, env.MC_APP_ENV) : env.NODE_ENV === 'production';
|
|
812
|
+
|
|
813
|
+
const getOrThrow = (fn, errorMessage) => {
|
|
814
|
+
try {
|
|
815
|
+
return fn();
|
|
816
|
+
} catch (error) {
|
|
817
|
+
throw new Error(errorMessage);
|
|
818
|
+
}
|
|
819
|
+
};
|
|
820
|
+
|
|
840
821
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
841
822
|
|
|
842
823
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context3, _context4; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context3 = ownKeys(Object(source), !0)).call(_context3, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context4 = ownKeys(Object(source))).call(_context4, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
843
824
|
// TODO: make it configurable.
|
|
844
|
-
|
|
845
|
-
|
|
825
|
+
const developmentPort = 3001;
|
|
826
|
+
const developmentAppUrl = "http://localhost:".concat(developmentPort);
|
|
846
827
|
|
|
847
|
-
|
|
848
|
-
return value.replace(/\/$/, '');
|
|
849
|
-
};
|
|
828
|
+
const trimTrailingSlash = value => value.replace(/\/$/, '');
|
|
850
829
|
|
|
851
|
-
|
|
830
|
+
const omitDevConfigIfEmpty = devConfig => {
|
|
852
831
|
if ( // @ts-expect-error: the `accountLinks` is not explicitly typed as it's only used by the account app.
|
|
853
832
|
devConfig !== null && devConfig !== void 0 && devConfig.accountLinks || devConfig !== null && devConfig !== void 0 && devConfig.menuLinks || devConfig !== null && devConfig !== void 0 && devConfig.oidc) return devConfig;
|
|
854
833
|
return undefined;
|
|
@@ -856,12 +835,12 @@ var omitDevConfigIfEmpty = function omitDevConfigIfEmpty(devConfig) {
|
|
|
856
835
|
// again will result in returning the cached value.
|
|
857
836
|
|
|
858
837
|
|
|
859
|
-
|
|
838
|
+
let cachedConfig;
|
|
860
839
|
|
|
861
|
-
|
|
840
|
+
const processConfig = function () {
|
|
862
841
|
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;
|
|
863
842
|
|
|
864
|
-
|
|
843
|
+
let _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
865
844
|
_ref$disableCache = _ref.disableCache,
|
|
866
845
|
disableCache = _ref$disableCache === void 0 ? false : _ref$disableCache,
|
|
867
846
|
_ref$processEnv = _ref.processEnv,
|
|
@@ -870,37 +849,31 @@ var processConfig = function processConfig() {
|
|
|
870
849
|
applicationPath = _ref$applicationPath === void 0 ? fs.realpathSync(process.cwd()) : _ref$applicationPath;
|
|
871
850
|
|
|
872
851
|
if (cachedConfig && !disableCache) return cachedConfig;
|
|
873
|
-
|
|
852
|
+
const rawConfig = loadConfig(applicationPath);
|
|
874
853
|
validateConfig(rawConfig);
|
|
875
|
-
|
|
876
|
-
applicationPath
|
|
877
|
-
processEnv
|
|
854
|
+
const appConfig = substituteVariablePlaceholders(rawConfig, {
|
|
855
|
+
applicationPath,
|
|
856
|
+
processEnv
|
|
878
857
|
});
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
return new _URL(envCdnUrl);
|
|
893
|
-
}, "Invalid application CDN URL: \"".concat(envCdnUrl, "\""));
|
|
894
|
-
var mcApiUrl = getOrThrow(function () {
|
|
895
|
-
return new _URL( // Use `||` instead of `??` to include empty string values.
|
|
896
|
-
appConfig.mcApiUrl || mapCloudIdentifierToApiUrl(appConfig.cloudIdentifier));
|
|
897
|
-
}, "Invalid MC API URL: \"".concat(appConfig.mcApiUrl, "\"")); // The real application ID is only used in production.
|
|
858
|
+
const customApplicationData = transformCustomApplicationConfigToData(appConfig);
|
|
859
|
+
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';
|
|
860
|
+
const isProd = getIsProd(processEnv);
|
|
861
|
+
const additionalAppEnv = (_appConfig$additional = appConfig.additionalEnv) !== null && _appConfig$additional !== void 0 ? _appConfig$additional : {};
|
|
862
|
+
const revision = (_ref3 = additionalAppEnv.revision) !== null && _ref3 !== void 0 ? _ref3 : ''; // Parse all the supported URLs, which gets implicitly validated
|
|
863
|
+
|
|
864
|
+
const envAppUrl = isProd ? customApplicationData.url : developmentAppUrl;
|
|
865
|
+
const appUrl = getOrThrow(() => new _URL(envAppUrl), "Invalid application URL: \"".concat(envAppUrl, "\"")); // Use `||` instead of `??` to include empty string values.
|
|
866
|
+
|
|
867
|
+
const envCdnUrl = isProd ? appConfig.env.production.cdnUrl || appUrl.href : developmentAppUrl;
|
|
868
|
+
const cdnUrl = getOrThrow(() => new _URL(envCdnUrl), "Invalid application CDN URL: \"".concat(envCdnUrl, "\""));
|
|
869
|
+
const mcApiUrl = getOrThrow(() => new _URL( // Use `||` instead of `??` to include empty string values.
|
|
870
|
+
appConfig.mcApiUrl || mapCloudIdentifierToApiUrl(appConfig.cloudIdentifier)), "Invalid MC API URL: \"".concat(appConfig.mcApiUrl, "\"")); // The real application ID is only used in production.
|
|
898
871
|
// In development, we prefix the entry point with the "__local" prefix.
|
|
899
872
|
// This is important to determine to which URL the MC should redirect to
|
|
900
873
|
// after successful login.
|
|
901
874
|
|
|
902
|
-
|
|
903
|
-
|
|
875
|
+
const applicationId = isProd ? _concatInstanceProperty(_context = "".concat(customApplicationData.id, ":")).call(_context, customApplicationData.entryPointUriPath) : "__local:".concat(customApplicationData.entryPointUriPath);
|
|
876
|
+
const developmentConfig = isProd ? undefined : omitDevConfigIfEmpty({
|
|
904
877
|
oidc: omitEmpty({
|
|
905
878
|
authorizeUrl: [// In case the MC API url points to localhost, we need to point
|
|
906
879
|
// to a local running dev login page to handle the workflow properly.
|
|
@@ -922,7 +895,7 @@ var processConfig = function processConfig() {
|
|
|
922
895
|
cachedConfig = {
|
|
923
896
|
data: customApplicationData,
|
|
924
897
|
env: _objectSpread(_objectSpread(_objectSpread({}, omitEmpty(additionalAppEnv)), {}, {
|
|
925
|
-
applicationId
|
|
898
|
+
applicationId,
|
|
926
899
|
applicationName: customApplicationData.name,
|
|
927
900
|
entryPointUriPath: customApplicationData.entryPointUriPath
|
|
928
901
|
}, isProd || !developmentConfig ? {} : {
|
|
@@ -933,7 +906,7 @@ var processConfig = function processConfig() {
|
|
|
933
906
|
frontendHost: appUrl.host,
|
|
934
907
|
location: appConfig.cloudIdentifier,
|
|
935
908
|
mcApiUrl: mcApiUrl.origin,
|
|
936
|
-
revision
|
|
909
|
+
revision,
|
|
937
910
|
servedByProxy: isProd
|
|
938
911
|
}),
|
|
939
912
|
headers: _objectSpread(_objectSpread({}, appConfig.headers), {}, {
|
|
@@ -953,9 +926,9 @@ var processConfig = function processConfig() {
|
|
|
953
926
|
return cachedConfig;
|
|
954
927
|
};
|
|
955
928
|
|
|
956
|
-
|
|
929
|
+
const jsdom = new JSDOM(''); // @ts-expect-error: jsdom returns DOMWindow, which doesn't match Window dompurify expects
|
|
957
930
|
|
|
958
|
-
|
|
931
|
+
const DOMPurify = createDOMPurify(jsdom.window);
|
|
959
932
|
function sanitizeSvg(data) {
|
|
960
933
|
return DOMPurify.sanitize(data, {
|
|
961
934
|
USE_PROFILES: {
|