@commercetools-frontend/application-config 22.36.0-preview.0 → 22.37.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 +80 -89
- package/dist/commercetools-frontend-application-config.cjs.prod.js +80 -89
- package/dist/commercetools-frontend-application-config.esm.js +77 -88
- package/dist/declarations/src/constants.d.ts +7 -19
- package/dist/declarations/src/load-config.d.ts +5 -2
- package/dist/declarations/src/process-config.d.ts +1 -1
- package/package.json +5 -6
- package/scripts/load-js-module.js +0 -34
|
@@ -14,12 +14,16 @@ var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
|
14
14
|
var _includesInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/includes');
|
|
15
15
|
var _URL = require('@babel/runtime-corejs3/core-js-stable/url');
|
|
16
16
|
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
17
|
-
var fs = require('node:fs');
|
|
17
|
+
var fs$1 = require('node:fs');
|
|
18
18
|
var path = require('node:path');
|
|
19
19
|
var omitEmpty = require('omit-empty-es');
|
|
20
20
|
var constants = require('@commercetools-frontend/constants');
|
|
21
|
-
var
|
|
21
|
+
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
22
|
+
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
|
|
23
|
+
var _parseInt = require('@babel/runtime-corejs3/core-js-stable/parse-int');
|
|
24
|
+
var fs = require('node:fs/promises');
|
|
22
25
|
var cosmiconfig = require('cosmiconfig');
|
|
26
|
+
var cosmiconfigTypescriptLoader = require('cosmiconfig-typescript-loader');
|
|
23
27
|
var _Reflect$construct = require('@babel/runtime-corejs3/core-js-stable/reflect/construct');
|
|
24
28
|
var _createClass = require('@babel/runtime-corejs3/helpers/createClass');
|
|
25
29
|
var _classCallCheck = require('@babel/runtime-corejs3/helpers/classCallCheck');
|
|
@@ -28,12 +32,10 @@ var _inherits = require('@babel/runtime-corejs3/helpers/inherits');
|
|
|
28
32
|
var _possibleConstructorReturn = require('@babel/runtime-corejs3/helpers/possibleConstructorReturn');
|
|
29
33
|
var _getPrototypeOf = require('@babel/runtime-corejs3/helpers/getPrototypeOf');
|
|
30
34
|
var _wrapNativeSuper = require('@babel/runtime-corejs3/helpers/wrapNativeSuper');
|
|
31
|
-
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
32
35
|
var _trimInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/trim');
|
|
33
36
|
var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
|
|
34
37
|
var _startsWithInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/starts-with');
|
|
35
38
|
var _reduceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
|
|
36
|
-
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
|
|
37
39
|
var formatters = require('./formatters-a76b45b9.cjs.dev.js');
|
|
38
40
|
var _Set = require('@babel/runtime-corejs3/core-js-stable/set');
|
|
39
41
|
var _Array$isArray = require('@babel/runtime-corejs3/core-js-stable/array/is-array');
|
|
@@ -58,15 +60,17 @@ var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defin
|
|
|
58
60
|
var _includesInstanceProperty__default = /*#__PURE__*/_interopDefault(_includesInstanceProperty);
|
|
59
61
|
var _URL__default = /*#__PURE__*/_interopDefault(_URL);
|
|
60
62
|
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
61
|
-
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
63
|
+
var fs__default$1 = /*#__PURE__*/_interopDefault(fs$1);
|
|
62
64
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
63
65
|
var omitEmpty__default = /*#__PURE__*/_interopDefault(omitEmpty);
|
|
66
|
+
var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
|
|
67
|
+
var _parseInt__default = /*#__PURE__*/_interopDefault(_parseInt);
|
|
68
|
+
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
64
69
|
var _Reflect$construct__default = /*#__PURE__*/_interopDefault(_Reflect$construct);
|
|
65
70
|
var _trimInstanceProperty__default = /*#__PURE__*/_interopDefault(_trimInstanceProperty);
|
|
66
71
|
var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
|
|
67
72
|
var _startsWithInstanceProperty__default = /*#__PURE__*/_interopDefault(_startsWithInstanceProperty);
|
|
68
73
|
var _reduceInstanceProperty__default = /*#__PURE__*/_interopDefault(_reduceInstanceProperty);
|
|
69
|
-
var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
|
|
70
74
|
var _Set__default = /*#__PURE__*/_interopDefault(_Set);
|
|
71
75
|
var _Array$isArray__default = /*#__PURE__*/_interopDefault(_Array$isArray);
|
|
72
76
|
var Ajv__default = /*#__PURE__*/_interopDefault(Ajv);
|
|
@@ -87,34 +91,22 @@ const CLOUD_IDENTIFIERS = {
|
|
|
87
91
|
/**
|
|
88
92
|
* @deprecated: use `AWS_US` instead
|
|
89
93
|
*/
|
|
90
|
-
AWS_OHIO: 'aws-ohio'
|
|
91
|
-
/**
|
|
92
|
-
* @deprecated: not supported anymore
|
|
93
|
-
*/
|
|
94
|
-
AWS_CN: 'aws-cn',
|
|
95
|
-
AZURE_US: 'azure-us',
|
|
96
|
-
AZURE_EU: 'azure-eu'
|
|
94
|
+
AWS_OHIO: 'aws-ohio'
|
|
97
95
|
};
|
|
98
96
|
const MC_API_URLS = {
|
|
99
|
-
GCP_AU: 'https://mc-api.australia-southeast1.gcp.commercetools.com',
|
|
100
|
-
GCP_EU: 'https://mc-api.europe-west1.gcp.commercetools.com',
|
|
101
|
-
GCP_US: 'https://mc-api.us-central1.gcp.commercetools.com',
|
|
102
|
-
AWS_EU: 'https://mc-api.eu-central-1.aws.commercetools.com',
|
|
103
|
-
AWS_US: 'https://mc-api.us-east-2.aws.commercetools.com',
|
|
97
|
+
[CLOUD_IDENTIFIERS.GCP_AU]: 'https://mc-api.australia-southeast1.gcp.commercetools.com',
|
|
98
|
+
[CLOUD_IDENTIFIERS.GCP_EU]: 'https://mc-api.europe-west1.gcp.commercetools.com',
|
|
99
|
+
[CLOUD_IDENTIFIERS.GCP_US]: 'https://mc-api.us-central1.gcp.commercetools.com',
|
|
100
|
+
[CLOUD_IDENTIFIERS.AWS_EU]: 'https://mc-api.eu-central-1.aws.commercetools.com',
|
|
101
|
+
[CLOUD_IDENTIFIERS.AWS_US]: 'https://mc-api.us-east-2.aws.commercetools.com',
|
|
104
102
|
/**
|
|
105
103
|
* @deprecated: use `AWS_EU` instead
|
|
106
104
|
*/
|
|
107
|
-
AWS_FRA: 'https://mc-api.eu-central-1.aws.commercetools.com',
|
|
105
|
+
[CLOUD_IDENTIFIERS.AWS_FRA]: 'https://mc-api.eu-central-1.aws.commercetools.com',
|
|
108
106
|
/**
|
|
109
107
|
* @deprecated: use `AWS_US` instead
|
|
110
108
|
*/
|
|
111
|
-
AWS_OHIO: 'https://mc-api.us-east-2.aws.commercetools.com'
|
|
112
|
-
/**
|
|
113
|
-
* @deprecated: not supported anymore
|
|
114
|
-
*/
|
|
115
|
-
AWS_CN: 'https://mc-api.cn-northwest-1.aws.commercetools.cn',
|
|
116
|
-
AZURE_US: 'https://mc-api.eastus.azure.commercetools.com',
|
|
117
|
-
AZURE_EU: 'https://mc-api.germanywestcentral.azure.commercetools.com'
|
|
109
|
+
[CLOUD_IDENTIFIERS.AWS_OHIO]: 'https://mc-api.us-east-2.aws.commercetools.com'
|
|
118
110
|
};
|
|
119
111
|
const LOADED_CONFIG_TYPES = {
|
|
120
112
|
CUSTOM_APPLICATION: 'custom-application',
|
|
@@ -138,65 +130,71 @@ let MissingOrInvalidConfigError = /*#__PURE__*/function (_Error) {
|
|
|
138
130
|
return _createClass(MissingOrInvalidConfigError);
|
|
139
131
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
140
132
|
|
|
141
|
-
|
|
133
|
+
// See the following issues for more context, contributing to failing Jest tests:
|
|
134
|
+
// - Issue: https://github.com/nodejs/node/issues/40058
|
|
135
|
+
// - Resolution: https://github.com/nodejs/node/pull/48510 (Node v20.8.0)
|
|
136
|
+
// Copied from @commitlint/load/src/utils/load-config.ts
|
|
137
|
+
const isDynamicAwaitSupported = () => {
|
|
138
|
+
var _context;
|
|
139
|
+
const _process$version$repl = _mapInstanceProperty__default["default"](_context = process.version.replace('v', '').split('.')).call(_context, val => _parseInt__default["default"](val)),
|
|
140
|
+
_process$version$repl2 = _slicedToArray(_process$version$repl, 2),
|
|
141
|
+
major = _process$version$repl2[0],
|
|
142
|
+
minor = _process$version$repl2[1];
|
|
143
|
+
return major >= 20 && minor >= 8;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// Is the given directory set up to use ESM (ECMAScript Modules)?
|
|
147
|
+
// Copied from @commitlint/load/src/utils/load-config.ts
|
|
148
|
+
const isEsmModule = async cwd => {
|
|
149
|
+
const packagePath = path__default["default"].join(cwd, 'package.json');
|
|
142
150
|
try {
|
|
143
|
-
fs__default["default"].
|
|
144
|
-
|
|
151
|
+
const packageJSON = await fs__default["default"].readFile(packagePath, {
|
|
152
|
+
encoding: 'utf-8'
|
|
153
|
+
});
|
|
154
|
+
return JSON.parse(packageJSON)?.type === 'module';
|
|
145
155
|
} catch (error) {
|
|
146
156
|
return false;
|
|
147
157
|
}
|
|
148
|
-
}
|
|
149
|
-
// Helper function to find the package root path from the current location,
|
|
150
|
-
// for instance in respect to both source files and dist files.
|
|
151
|
-
const findPackageRootPath = dir => {
|
|
152
|
-
const packageJsonPath = path__default["default"].join(dir, 'package.json');
|
|
153
|
-
if (doesFileExist(packageJsonPath)) {
|
|
154
|
-
return dir;
|
|
155
|
-
}
|
|
156
|
-
const parentDir = path__default["default"].join(dir, '..');
|
|
157
|
-
return findPackageRootPath(parentDir);
|
|
158
158
|
};
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
return
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
return cosmiconfig.cosmiconfigSync(configFileName, {
|
|
176
|
-
// Restrict the supported file formats / names
|
|
177
|
-
searchPlaces: [`.${configFileName}rc`, `.${configFileName}.json`, `.${configFileName}.js`, `.${configFileName}.cjs`, `.${configFileName}.mjs`, `.${configFileName}.ts`, `${configFileName}.json`, `${configFileName}.js`, `${configFileName}.cjs`, `${configFileName}.mjs`, `${configFileName}.ts`],
|
|
159
|
+
const createExplorerFor = async configFileName => {
|
|
160
|
+
// Copied from @commitlint/load/src/utils/load-config.ts
|
|
161
|
+
let tsLoaderInstance;
|
|
162
|
+
const tsLoader = function () {
|
|
163
|
+
if (!tsLoaderInstance) {
|
|
164
|
+
tsLoaderInstance = cosmiconfigTypescriptLoader.TypeScriptLoader();
|
|
165
|
+
}
|
|
166
|
+
return tsLoaderInstance(...arguments);
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
// If dynamic await is supported (Node >= v20.8.0) or directory uses ESM, support
|
|
170
|
+
// async js/cjs loaders (dynamic import). Otherwise, use synchronous js/cjs loaders.
|
|
171
|
+
const loaders = isDynamicAwaitSupported() || (await isEsmModule(process.cwd())) ? cosmiconfig.defaultLoaders : cosmiconfig.defaultLoadersSync;
|
|
172
|
+
return cosmiconfig.cosmiconfig(configFileName, {
|
|
173
|
+
searchStrategy: 'project',
|
|
174
|
+
searchPlaces: [`${configFileName}.js`, `${configFileName}.cjs`, `${configFileName}.mjs`, `${configFileName}.ts`],
|
|
178
175
|
loaders: {
|
|
179
|
-
|
|
180
|
-
'.
|
|
181
|
-
'.
|
|
182
|
-
'.
|
|
183
|
-
'.ts': loadJsModule
|
|
176
|
+
'.js': loaders['.js'],
|
|
177
|
+
'.cjs': loaders['.cjs'],
|
|
178
|
+
'.mjs': tsLoader,
|
|
179
|
+
'.ts': tsLoader
|
|
184
180
|
}
|
|
185
181
|
});
|
|
186
182
|
};
|
|
187
|
-
const
|
|
188
|
-
const
|
|
189
|
-
const
|
|
190
|
-
const customApplicationConfigFile = customApplicationExplorer.search();
|
|
191
|
-
const customViewConfigFile = customViewExplorer.search();
|
|
183
|
+
const getConfigPath = async () => {
|
|
184
|
+
const customApplicationExplorer = await createExplorerFor('custom-application-config');
|
|
185
|
+
const customViewExplorer = await createExplorerFor('custom-view-config');
|
|
186
|
+
const customApplicationConfigFile = await customApplicationExplorer.search();
|
|
187
|
+
const customViewConfigFile = await customViewExplorer.search();
|
|
192
188
|
if (!customApplicationConfigFile && !customViewConfigFile) {
|
|
193
189
|
throw new Error(`Missing or invalid configuration file.`);
|
|
194
190
|
}
|
|
195
191
|
return customApplicationConfigFile?.filepath || customViewConfigFile?.filepath;
|
|
196
192
|
};
|
|
197
|
-
const loadConfig = applicationPath => {
|
|
198
|
-
const
|
|
199
|
-
const
|
|
193
|
+
const loadConfig = async applicationPath => {
|
|
194
|
+
const customApplicationExplorer = await createExplorerFor('custom-application-config');
|
|
195
|
+
const customViewExplorer = await createExplorerFor('custom-view-config');
|
|
196
|
+
const customApplicationConfigFile = await customApplicationExplorer.search(applicationPath);
|
|
197
|
+
const customViewConfigFile = await customViewExplorer.search(applicationPath);
|
|
200
198
|
if ((!customApplicationConfigFile || !customApplicationConfigFile.config) && (!customViewConfigFile || !customViewConfigFile.config)) {
|
|
201
199
|
throw new MissingOrInvalidConfigError(`Missing or invalid configuration file.`);
|
|
202
200
|
}
|
|
@@ -264,7 +262,7 @@ const substituteFilePathVariablePlaceholder = (valueOfPlaceholder, matchedString
|
|
|
264
262
|
const _valueOfPlaceholder$s5 = valueOfPlaceholder.split(':'),
|
|
265
263
|
_valueOfPlaceholder$s6 = _slicedToArray(_valueOfPlaceholder$s5, 2),
|
|
266
264
|
filePathOrModule = _valueOfPlaceholder$s6[1];
|
|
267
|
-
const content = fs__default["default"].readFileSync(require.resolve(filePathOrModule, {
|
|
265
|
+
const content = fs__default$1["default"].readFileSync(require.resolve(filePathOrModule, {
|
|
268
266
|
// Relative paths should be resolved from the application folder.
|
|
269
267
|
paths: [loadingOptions.applicationPath]
|
|
270
268
|
}), {
|
|
@@ -1099,24 +1097,17 @@ function transformConfigurationToData(configType, configuration) {
|
|
|
1099
1097
|
const mapCloudIdentifierToApiUrl = key => {
|
|
1100
1098
|
switch (key) {
|
|
1101
1099
|
case CLOUD_IDENTIFIERS.GCP_AU:
|
|
1102
|
-
return MC_API_URLS.GCP_AU;
|
|
1100
|
+
return MC_API_URLS[CLOUD_IDENTIFIERS.GCP_AU];
|
|
1103
1101
|
case CLOUD_IDENTIFIERS.GCP_EU:
|
|
1104
|
-
return MC_API_URLS.GCP_EU;
|
|
1102
|
+
return MC_API_URLS[CLOUD_IDENTIFIERS.GCP_EU];
|
|
1105
1103
|
case CLOUD_IDENTIFIERS.GCP_US:
|
|
1106
|
-
return MC_API_URLS.GCP_US;
|
|
1104
|
+
return MC_API_URLS[CLOUD_IDENTIFIERS.GCP_US];
|
|
1107
1105
|
case CLOUD_IDENTIFIERS.AWS_EU:
|
|
1108
1106
|
case CLOUD_IDENTIFIERS.AWS_FRA:
|
|
1109
|
-
return MC_API_URLS.AWS_EU;
|
|
1107
|
+
return MC_API_URLS[CLOUD_IDENTIFIERS.AWS_EU];
|
|
1110
1108
|
case CLOUD_IDENTIFIERS.AWS_US:
|
|
1111
1109
|
case CLOUD_IDENTIFIERS.AWS_OHIO:
|
|
1112
|
-
return MC_API_URLS.AWS_US;
|
|
1113
|
-
// TODO: remove it
|
|
1114
|
-
case CLOUD_IDENTIFIERS.AWS_CN:
|
|
1115
|
-
return MC_API_URLS.AWS_CN;
|
|
1116
|
-
case CLOUD_IDENTIFIERS.AZURE_US:
|
|
1117
|
-
return MC_API_URLS.AZURE_US;
|
|
1118
|
-
case CLOUD_IDENTIFIERS.AZURE_EU:
|
|
1119
|
-
return MC_API_URLS.AZURE_EU;
|
|
1110
|
+
return MC_API_URLS[CLOUD_IDENTIFIERS.AWS_US];
|
|
1120
1111
|
default:
|
|
1121
1112
|
// We would probably never get to this point, as the JSON schema validation
|
|
1122
1113
|
// kicks in before.
|
|
@@ -1260,7 +1251,7 @@ const getRuntimeEnvironmentConfig = _ref2 => {
|
|
|
1260
1251
|
// Keep a reference to the config so that requiring the module
|
|
1261
1252
|
// again will result in returning the cached value.
|
|
1262
1253
|
let cachedConfig;
|
|
1263
|
-
const processConfig = function () {
|
|
1254
|
+
const processConfig = async function () {
|
|
1264
1255
|
var _context;
|
|
1265
1256
|
let _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
1266
1257
|
_ref3$disableCache = _ref3.disableCache,
|
|
@@ -1268,11 +1259,11 @@ const processConfig = function () {
|
|
|
1268
1259
|
_ref3$processEnv = _ref3.processEnv,
|
|
1269
1260
|
processEnv = _ref3$processEnv === void 0 ? process.env : _ref3$processEnv,
|
|
1270
1261
|
_ref3$applicationPath = _ref3.applicationPath,
|
|
1271
|
-
applicationPath = _ref3$applicationPath === void 0 ? fs__default["default"].realpathSync(process.cwd()) : _ref3$applicationPath;
|
|
1262
|
+
applicationPath = _ref3$applicationPath === void 0 ? fs__default$1["default"].realpathSync(process.cwd()) : _ref3$applicationPath;
|
|
1272
1263
|
if (cachedConfig && !disableCache) return cachedConfig;
|
|
1273
|
-
const
|
|
1274
|
-
filepath =
|
|
1275
|
-
rawConfig =
|
|
1264
|
+
const _await$loadConfig = await loadConfig(applicationPath),
|
|
1265
|
+
filepath = _await$loadConfig.filepath,
|
|
1266
|
+
rawConfig = _await$loadConfig.config;
|
|
1276
1267
|
const configType = getLoadedConfigurationType(path.parse(filepath).name);
|
|
1277
1268
|
validateConfig(configType, rawConfig);
|
|
1278
1269
|
const appConfig = substituteVariablePlaceholders(rawConfig, {
|
|
@@ -14,12 +14,16 @@ var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
|
14
14
|
var _includesInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/includes');
|
|
15
15
|
var _URL = require('@babel/runtime-corejs3/core-js-stable/url');
|
|
16
16
|
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
17
|
-
var fs = require('node:fs');
|
|
17
|
+
var fs$1 = require('node:fs');
|
|
18
18
|
var path = require('node:path');
|
|
19
19
|
var omitEmpty = require('omit-empty-es');
|
|
20
20
|
var constants = require('@commercetools-frontend/constants');
|
|
21
|
-
var
|
|
21
|
+
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
22
|
+
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
|
|
23
|
+
var _parseInt = require('@babel/runtime-corejs3/core-js-stable/parse-int');
|
|
24
|
+
var fs = require('node:fs/promises');
|
|
22
25
|
var cosmiconfig = require('cosmiconfig');
|
|
26
|
+
var cosmiconfigTypescriptLoader = require('cosmiconfig-typescript-loader');
|
|
23
27
|
var _Reflect$construct = require('@babel/runtime-corejs3/core-js-stable/reflect/construct');
|
|
24
28
|
var _createClass = require('@babel/runtime-corejs3/helpers/createClass');
|
|
25
29
|
var _classCallCheck = require('@babel/runtime-corejs3/helpers/classCallCheck');
|
|
@@ -28,12 +32,10 @@ var _inherits = require('@babel/runtime-corejs3/helpers/inherits');
|
|
|
28
32
|
var _possibleConstructorReturn = require('@babel/runtime-corejs3/helpers/possibleConstructorReturn');
|
|
29
33
|
var _getPrototypeOf = require('@babel/runtime-corejs3/helpers/getPrototypeOf');
|
|
30
34
|
var _wrapNativeSuper = require('@babel/runtime-corejs3/helpers/wrapNativeSuper');
|
|
31
|
-
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
32
35
|
var _trimInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/trim');
|
|
33
36
|
var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
|
|
34
37
|
var _startsWithInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/starts-with');
|
|
35
38
|
var _reduceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
|
|
36
|
-
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
|
|
37
39
|
var formatters = require('./formatters-7f327585.cjs.prod.js');
|
|
38
40
|
var _Set = require('@babel/runtime-corejs3/core-js-stable/set');
|
|
39
41
|
var _Array$isArray = require('@babel/runtime-corejs3/core-js-stable/array/is-array');
|
|
@@ -58,15 +60,17 @@ var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defin
|
|
|
58
60
|
var _includesInstanceProperty__default = /*#__PURE__*/_interopDefault(_includesInstanceProperty);
|
|
59
61
|
var _URL__default = /*#__PURE__*/_interopDefault(_URL);
|
|
60
62
|
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
61
|
-
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
63
|
+
var fs__default$1 = /*#__PURE__*/_interopDefault(fs$1);
|
|
62
64
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
63
65
|
var omitEmpty__default = /*#__PURE__*/_interopDefault(omitEmpty);
|
|
66
|
+
var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
|
|
67
|
+
var _parseInt__default = /*#__PURE__*/_interopDefault(_parseInt);
|
|
68
|
+
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
64
69
|
var _Reflect$construct__default = /*#__PURE__*/_interopDefault(_Reflect$construct);
|
|
65
70
|
var _trimInstanceProperty__default = /*#__PURE__*/_interopDefault(_trimInstanceProperty);
|
|
66
71
|
var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
|
|
67
72
|
var _startsWithInstanceProperty__default = /*#__PURE__*/_interopDefault(_startsWithInstanceProperty);
|
|
68
73
|
var _reduceInstanceProperty__default = /*#__PURE__*/_interopDefault(_reduceInstanceProperty);
|
|
69
|
-
var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
|
|
70
74
|
var _Set__default = /*#__PURE__*/_interopDefault(_Set);
|
|
71
75
|
var _Array$isArray__default = /*#__PURE__*/_interopDefault(_Array$isArray);
|
|
72
76
|
var Ajv__default = /*#__PURE__*/_interopDefault(Ajv);
|
|
@@ -87,34 +91,22 @@ const CLOUD_IDENTIFIERS = {
|
|
|
87
91
|
/**
|
|
88
92
|
* @deprecated: use `AWS_US` instead
|
|
89
93
|
*/
|
|
90
|
-
AWS_OHIO: 'aws-ohio'
|
|
91
|
-
/**
|
|
92
|
-
* @deprecated: not supported anymore
|
|
93
|
-
*/
|
|
94
|
-
AWS_CN: 'aws-cn',
|
|
95
|
-
AZURE_US: 'azure-us',
|
|
96
|
-
AZURE_EU: 'azure-eu'
|
|
94
|
+
AWS_OHIO: 'aws-ohio'
|
|
97
95
|
};
|
|
98
96
|
const MC_API_URLS = {
|
|
99
|
-
GCP_AU: 'https://mc-api.australia-southeast1.gcp.commercetools.com',
|
|
100
|
-
GCP_EU: 'https://mc-api.europe-west1.gcp.commercetools.com',
|
|
101
|
-
GCP_US: 'https://mc-api.us-central1.gcp.commercetools.com',
|
|
102
|
-
AWS_EU: 'https://mc-api.eu-central-1.aws.commercetools.com',
|
|
103
|
-
AWS_US: 'https://mc-api.us-east-2.aws.commercetools.com',
|
|
97
|
+
[CLOUD_IDENTIFIERS.GCP_AU]: 'https://mc-api.australia-southeast1.gcp.commercetools.com',
|
|
98
|
+
[CLOUD_IDENTIFIERS.GCP_EU]: 'https://mc-api.europe-west1.gcp.commercetools.com',
|
|
99
|
+
[CLOUD_IDENTIFIERS.GCP_US]: 'https://mc-api.us-central1.gcp.commercetools.com',
|
|
100
|
+
[CLOUD_IDENTIFIERS.AWS_EU]: 'https://mc-api.eu-central-1.aws.commercetools.com',
|
|
101
|
+
[CLOUD_IDENTIFIERS.AWS_US]: 'https://mc-api.us-east-2.aws.commercetools.com',
|
|
104
102
|
/**
|
|
105
103
|
* @deprecated: use `AWS_EU` instead
|
|
106
104
|
*/
|
|
107
|
-
AWS_FRA: 'https://mc-api.eu-central-1.aws.commercetools.com',
|
|
105
|
+
[CLOUD_IDENTIFIERS.AWS_FRA]: 'https://mc-api.eu-central-1.aws.commercetools.com',
|
|
108
106
|
/**
|
|
109
107
|
* @deprecated: use `AWS_US` instead
|
|
110
108
|
*/
|
|
111
|
-
AWS_OHIO: 'https://mc-api.us-east-2.aws.commercetools.com'
|
|
112
|
-
/**
|
|
113
|
-
* @deprecated: not supported anymore
|
|
114
|
-
*/
|
|
115
|
-
AWS_CN: 'https://mc-api.cn-northwest-1.aws.commercetools.cn',
|
|
116
|
-
AZURE_US: 'https://mc-api.eastus.azure.commercetools.com',
|
|
117
|
-
AZURE_EU: 'https://mc-api.germanywestcentral.azure.commercetools.com'
|
|
109
|
+
[CLOUD_IDENTIFIERS.AWS_OHIO]: 'https://mc-api.us-east-2.aws.commercetools.com'
|
|
118
110
|
};
|
|
119
111
|
const LOADED_CONFIG_TYPES = {
|
|
120
112
|
CUSTOM_APPLICATION: 'custom-application',
|
|
@@ -138,65 +130,71 @@ let MissingOrInvalidConfigError = /*#__PURE__*/function (_Error) {
|
|
|
138
130
|
return _createClass(MissingOrInvalidConfigError);
|
|
139
131
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
140
132
|
|
|
141
|
-
|
|
133
|
+
// See the following issues for more context, contributing to failing Jest tests:
|
|
134
|
+
// - Issue: https://github.com/nodejs/node/issues/40058
|
|
135
|
+
// - Resolution: https://github.com/nodejs/node/pull/48510 (Node v20.8.0)
|
|
136
|
+
// Copied from @commitlint/load/src/utils/load-config.ts
|
|
137
|
+
const isDynamicAwaitSupported = () => {
|
|
138
|
+
var _context;
|
|
139
|
+
const _process$version$repl = _mapInstanceProperty__default["default"](_context = process.version.replace('v', '').split('.')).call(_context, val => _parseInt__default["default"](val)),
|
|
140
|
+
_process$version$repl2 = _slicedToArray(_process$version$repl, 2),
|
|
141
|
+
major = _process$version$repl2[0],
|
|
142
|
+
minor = _process$version$repl2[1];
|
|
143
|
+
return major >= 20 && minor >= 8;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// Is the given directory set up to use ESM (ECMAScript Modules)?
|
|
147
|
+
// Copied from @commitlint/load/src/utils/load-config.ts
|
|
148
|
+
const isEsmModule = async cwd => {
|
|
149
|
+
const packagePath = path__default["default"].join(cwd, 'package.json');
|
|
142
150
|
try {
|
|
143
|
-
fs__default["default"].
|
|
144
|
-
|
|
151
|
+
const packageJSON = await fs__default["default"].readFile(packagePath, {
|
|
152
|
+
encoding: 'utf-8'
|
|
153
|
+
});
|
|
154
|
+
return JSON.parse(packageJSON)?.type === 'module';
|
|
145
155
|
} catch (error) {
|
|
146
156
|
return false;
|
|
147
157
|
}
|
|
148
|
-
}
|
|
149
|
-
// Helper function to find the package root path from the current location,
|
|
150
|
-
// for instance in respect to both source files and dist files.
|
|
151
|
-
const findPackageRootPath = dir => {
|
|
152
|
-
const packageJsonPath = path__default["default"].join(dir, 'package.json');
|
|
153
|
-
if (doesFileExist(packageJsonPath)) {
|
|
154
|
-
return dir;
|
|
155
|
-
}
|
|
156
|
-
const parentDir = path__default["default"].join(dir, '..');
|
|
157
|
-
return findPackageRootPath(parentDir);
|
|
158
158
|
};
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
return
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
return cosmiconfig.cosmiconfigSync(configFileName, {
|
|
176
|
-
// Restrict the supported file formats / names
|
|
177
|
-
searchPlaces: [`.${configFileName}rc`, `.${configFileName}.json`, `.${configFileName}.js`, `.${configFileName}.cjs`, `.${configFileName}.mjs`, `.${configFileName}.ts`, `${configFileName}.json`, `${configFileName}.js`, `${configFileName}.cjs`, `${configFileName}.mjs`, `${configFileName}.ts`],
|
|
159
|
+
const createExplorerFor = async configFileName => {
|
|
160
|
+
// Copied from @commitlint/load/src/utils/load-config.ts
|
|
161
|
+
let tsLoaderInstance;
|
|
162
|
+
const tsLoader = function () {
|
|
163
|
+
if (!tsLoaderInstance) {
|
|
164
|
+
tsLoaderInstance = cosmiconfigTypescriptLoader.TypeScriptLoader();
|
|
165
|
+
}
|
|
166
|
+
return tsLoaderInstance(...arguments);
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
// If dynamic await is supported (Node >= v20.8.0) or directory uses ESM, support
|
|
170
|
+
// async js/cjs loaders (dynamic import). Otherwise, use synchronous js/cjs loaders.
|
|
171
|
+
const loaders = isDynamicAwaitSupported() || (await isEsmModule(process.cwd())) ? cosmiconfig.defaultLoaders : cosmiconfig.defaultLoadersSync;
|
|
172
|
+
return cosmiconfig.cosmiconfig(configFileName, {
|
|
173
|
+
searchStrategy: 'project',
|
|
174
|
+
searchPlaces: [`${configFileName}.js`, `${configFileName}.cjs`, `${configFileName}.mjs`, `${configFileName}.ts`],
|
|
178
175
|
loaders: {
|
|
179
|
-
|
|
180
|
-
'.
|
|
181
|
-
'.
|
|
182
|
-
'.
|
|
183
|
-
'.ts': loadJsModule
|
|
176
|
+
'.js': loaders['.js'],
|
|
177
|
+
'.cjs': loaders['.cjs'],
|
|
178
|
+
'.mjs': tsLoader,
|
|
179
|
+
'.ts': tsLoader
|
|
184
180
|
}
|
|
185
181
|
});
|
|
186
182
|
};
|
|
187
|
-
const
|
|
188
|
-
const
|
|
189
|
-
const
|
|
190
|
-
const customApplicationConfigFile = customApplicationExplorer.search();
|
|
191
|
-
const customViewConfigFile = customViewExplorer.search();
|
|
183
|
+
const getConfigPath = async () => {
|
|
184
|
+
const customApplicationExplorer = await createExplorerFor('custom-application-config');
|
|
185
|
+
const customViewExplorer = await createExplorerFor('custom-view-config');
|
|
186
|
+
const customApplicationConfigFile = await customApplicationExplorer.search();
|
|
187
|
+
const customViewConfigFile = await customViewExplorer.search();
|
|
192
188
|
if (!customApplicationConfigFile && !customViewConfigFile) {
|
|
193
189
|
throw new Error(`Missing or invalid configuration file.`);
|
|
194
190
|
}
|
|
195
191
|
return customApplicationConfigFile?.filepath || customViewConfigFile?.filepath;
|
|
196
192
|
};
|
|
197
|
-
const loadConfig = applicationPath => {
|
|
198
|
-
const
|
|
199
|
-
const
|
|
193
|
+
const loadConfig = async applicationPath => {
|
|
194
|
+
const customApplicationExplorer = await createExplorerFor('custom-application-config');
|
|
195
|
+
const customViewExplorer = await createExplorerFor('custom-view-config');
|
|
196
|
+
const customApplicationConfigFile = await customApplicationExplorer.search(applicationPath);
|
|
197
|
+
const customViewConfigFile = await customViewExplorer.search(applicationPath);
|
|
200
198
|
if ((!customApplicationConfigFile || !customApplicationConfigFile.config) && (!customViewConfigFile || !customViewConfigFile.config)) {
|
|
201
199
|
throw new MissingOrInvalidConfigError(`Missing or invalid configuration file.`);
|
|
202
200
|
}
|
|
@@ -264,7 +262,7 @@ const substituteFilePathVariablePlaceholder = (valueOfPlaceholder, matchedString
|
|
|
264
262
|
const _valueOfPlaceholder$s5 = valueOfPlaceholder.split(':'),
|
|
265
263
|
_valueOfPlaceholder$s6 = _slicedToArray(_valueOfPlaceholder$s5, 2),
|
|
266
264
|
filePathOrModule = _valueOfPlaceholder$s6[1];
|
|
267
|
-
const content = fs__default["default"].readFileSync(require.resolve(filePathOrModule, {
|
|
265
|
+
const content = fs__default$1["default"].readFileSync(require.resolve(filePathOrModule, {
|
|
268
266
|
// Relative paths should be resolved from the application folder.
|
|
269
267
|
paths: [loadingOptions.applicationPath]
|
|
270
268
|
}), {
|
|
@@ -1099,24 +1097,17 @@ function transformConfigurationToData(configType, configuration) {
|
|
|
1099
1097
|
const mapCloudIdentifierToApiUrl = key => {
|
|
1100
1098
|
switch (key) {
|
|
1101
1099
|
case CLOUD_IDENTIFIERS.GCP_AU:
|
|
1102
|
-
return MC_API_URLS.GCP_AU;
|
|
1100
|
+
return MC_API_URLS[CLOUD_IDENTIFIERS.GCP_AU];
|
|
1103
1101
|
case CLOUD_IDENTIFIERS.GCP_EU:
|
|
1104
|
-
return MC_API_URLS.GCP_EU;
|
|
1102
|
+
return MC_API_URLS[CLOUD_IDENTIFIERS.GCP_EU];
|
|
1105
1103
|
case CLOUD_IDENTIFIERS.GCP_US:
|
|
1106
|
-
return MC_API_URLS.GCP_US;
|
|
1104
|
+
return MC_API_URLS[CLOUD_IDENTIFIERS.GCP_US];
|
|
1107
1105
|
case CLOUD_IDENTIFIERS.AWS_EU:
|
|
1108
1106
|
case CLOUD_IDENTIFIERS.AWS_FRA:
|
|
1109
|
-
return MC_API_URLS.AWS_EU;
|
|
1107
|
+
return MC_API_URLS[CLOUD_IDENTIFIERS.AWS_EU];
|
|
1110
1108
|
case CLOUD_IDENTIFIERS.AWS_US:
|
|
1111
1109
|
case CLOUD_IDENTIFIERS.AWS_OHIO:
|
|
1112
|
-
return MC_API_URLS.AWS_US;
|
|
1113
|
-
// TODO: remove it
|
|
1114
|
-
case CLOUD_IDENTIFIERS.AWS_CN:
|
|
1115
|
-
return MC_API_URLS.AWS_CN;
|
|
1116
|
-
case CLOUD_IDENTIFIERS.AZURE_US:
|
|
1117
|
-
return MC_API_URLS.AZURE_US;
|
|
1118
|
-
case CLOUD_IDENTIFIERS.AZURE_EU:
|
|
1119
|
-
return MC_API_URLS.AZURE_EU;
|
|
1110
|
+
return MC_API_URLS[CLOUD_IDENTIFIERS.AWS_US];
|
|
1120
1111
|
default:
|
|
1121
1112
|
// We would probably never get to this point, as the JSON schema validation
|
|
1122
1113
|
// kicks in before.
|
|
@@ -1260,7 +1251,7 @@ const getRuntimeEnvironmentConfig = _ref2 => {
|
|
|
1260
1251
|
// Keep a reference to the config so that requiring the module
|
|
1261
1252
|
// again will result in returning the cached value.
|
|
1262
1253
|
let cachedConfig;
|
|
1263
|
-
const processConfig = function () {
|
|
1254
|
+
const processConfig = async function () {
|
|
1264
1255
|
var _context;
|
|
1265
1256
|
let _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
1266
1257
|
_ref3$disableCache = _ref3.disableCache,
|
|
@@ -1268,11 +1259,11 @@ const processConfig = function () {
|
|
|
1268
1259
|
_ref3$processEnv = _ref3.processEnv,
|
|
1269
1260
|
processEnv = _ref3$processEnv === void 0 ? process.env : _ref3$processEnv,
|
|
1270
1261
|
_ref3$applicationPath = _ref3.applicationPath,
|
|
1271
|
-
applicationPath = _ref3$applicationPath === void 0 ? fs__default["default"].realpathSync(process.cwd()) : _ref3$applicationPath;
|
|
1262
|
+
applicationPath = _ref3$applicationPath === void 0 ? fs__default$1["default"].realpathSync(process.cwd()) : _ref3$applicationPath;
|
|
1272
1263
|
if (cachedConfig && !disableCache) return cachedConfig;
|
|
1273
|
-
const
|
|
1274
|
-
filepath =
|
|
1275
|
-
rawConfig =
|
|
1264
|
+
const _await$loadConfig = await loadConfig(applicationPath),
|
|
1265
|
+
filepath = _await$loadConfig.filepath,
|
|
1266
|
+
rawConfig = _await$loadConfig.config;
|
|
1276
1267
|
const configType = getLoadedConfigurationType(path.parse(filepath).name);
|
|
1277
1268
|
validateConfig(configType, rawConfig);
|
|
1278
1269
|
const appConfig = substituteVariablePlaceholders(rawConfig, {
|
|
@@ -10,13 +10,17 @@ import _defineProperty from '@babel/runtime-corejs3/helpers/esm/defineProperty';
|
|
|
10
10
|
import _includesInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/includes';
|
|
11
11
|
import _URL from '@babel/runtime-corejs3/core-js-stable/url';
|
|
12
12
|
import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/concat';
|
|
13
|
-
import fs from 'node:fs';
|
|
13
|
+
import fs$1 from 'node:fs';
|
|
14
14
|
import path, { parse } from 'node:path';
|
|
15
15
|
import omitEmpty from 'omit-empty-es';
|
|
16
16
|
import { ENTRY_POINT_URI_PATH_REGEX, PERMISSION_GROUP_NAME_REGEX, CUSTOM_VIEW_HOST_ENTRY_POINT_URI_PATH } from '@commercetools-frontend/constants';
|
|
17
17
|
export { ENTRY_POINT_URI_PATH_REGEX, PERMISSION_GROUP_NAME_REGEX } from '@commercetools-frontend/constants';
|
|
18
|
-
import
|
|
19
|
-
import
|
|
18
|
+
import _slicedToArray from '@babel/runtime-corejs3/helpers/esm/slicedToArray';
|
|
19
|
+
import _mapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/map';
|
|
20
|
+
import _parseInt from '@babel/runtime-corejs3/core-js-stable/parse-int';
|
|
21
|
+
import fs from 'node:fs/promises';
|
|
22
|
+
import { defaultLoaders, defaultLoadersSync, cosmiconfig } from 'cosmiconfig';
|
|
23
|
+
import { TypeScriptLoader } from 'cosmiconfig-typescript-loader';
|
|
20
24
|
import _Reflect$construct from '@babel/runtime-corejs3/core-js-stable/reflect/construct';
|
|
21
25
|
import _createClass from '@babel/runtime-corejs3/helpers/esm/createClass';
|
|
22
26
|
import _classCallCheck from '@babel/runtime-corejs3/helpers/esm/classCallCheck';
|
|
@@ -25,12 +29,10 @@ import _inherits from '@babel/runtime-corejs3/helpers/esm/inherits';
|
|
|
25
29
|
import _possibleConstructorReturn from '@babel/runtime-corejs3/helpers/esm/possibleConstructorReturn';
|
|
26
30
|
import _getPrototypeOf from '@babel/runtime-corejs3/helpers/esm/getPrototypeOf';
|
|
27
31
|
import _wrapNativeSuper from '@babel/runtime-corejs3/helpers/esm/wrapNativeSuper';
|
|
28
|
-
import _slicedToArray from '@babel/runtime-corejs3/helpers/esm/slicedToArray';
|
|
29
32
|
import _trimInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/trim';
|
|
30
33
|
import _JSON$stringify from '@babel/runtime-corejs3/core-js-stable/json/stringify';
|
|
31
34
|
import _startsWithInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/starts-with';
|
|
32
35
|
import _reduceInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/reduce';
|
|
33
|
-
import _mapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/map';
|
|
34
36
|
import { f as formatEntryPointUriPathToResourceAccessKey, e as entryPointUriPathToResourceAccesses } from './formatters-882eafa8.esm.js';
|
|
35
37
|
import _Set from '@babel/runtime-corejs3/core-js-stable/set';
|
|
36
38
|
import _Array$isArray from '@babel/runtime-corejs3/core-js-stable/array/is-array';
|
|
@@ -55,34 +57,22 @@ const CLOUD_IDENTIFIERS = {
|
|
|
55
57
|
/**
|
|
56
58
|
* @deprecated: use `AWS_US` instead
|
|
57
59
|
*/
|
|
58
|
-
AWS_OHIO: 'aws-ohio'
|
|
59
|
-
/**
|
|
60
|
-
* @deprecated: not supported anymore
|
|
61
|
-
*/
|
|
62
|
-
AWS_CN: 'aws-cn',
|
|
63
|
-
AZURE_US: 'azure-us',
|
|
64
|
-
AZURE_EU: 'azure-eu'
|
|
60
|
+
AWS_OHIO: 'aws-ohio'
|
|
65
61
|
};
|
|
66
62
|
const MC_API_URLS = {
|
|
67
|
-
GCP_AU: 'https://mc-api.australia-southeast1.gcp.commercetools.com',
|
|
68
|
-
GCP_EU: 'https://mc-api.europe-west1.gcp.commercetools.com',
|
|
69
|
-
GCP_US: 'https://mc-api.us-central1.gcp.commercetools.com',
|
|
70
|
-
AWS_EU: 'https://mc-api.eu-central-1.aws.commercetools.com',
|
|
71
|
-
AWS_US: 'https://mc-api.us-east-2.aws.commercetools.com',
|
|
63
|
+
[CLOUD_IDENTIFIERS.GCP_AU]: 'https://mc-api.australia-southeast1.gcp.commercetools.com',
|
|
64
|
+
[CLOUD_IDENTIFIERS.GCP_EU]: 'https://mc-api.europe-west1.gcp.commercetools.com',
|
|
65
|
+
[CLOUD_IDENTIFIERS.GCP_US]: 'https://mc-api.us-central1.gcp.commercetools.com',
|
|
66
|
+
[CLOUD_IDENTIFIERS.AWS_EU]: 'https://mc-api.eu-central-1.aws.commercetools.com',
|
|
67
|
+
[CLOUD_IDENTIFIERS.AWS_US]: 'https://mc-api.us-east-2.aws.commercetools.com',
|
|
72
68
|
/**
|
|
73
69
|
* @deprecated: use `AWS_EU` instead
|
|
74
70
|
*/
|
|
75
|
-
AWS_FRA: 'https://mc-api.eu-central-1.aws.commercetools.com',
|
|
71
|
+
[CLOUD_IDENTIFIERS.AWS_FRA]: 'https://mc-api.eu-central-1.aws.commercetools.com',
|
|
76
72
|
/**
|
|
77
73
|
* @deprecated: use `AWS_US` instead
|
|
78
74
|
*/
|
|
79
|
-
AWS_OHIO: 'https://mc-api.us-east-2.aws.commercetools.com'
|
|
80
|
-
/**
|
|
81
|
-
* @deprecated: not supported anymore
|
|
82
|
-
*/
|
|
83
|
-
AWS_CN: 'https://mc-api.cn-northwest-1.aws.commercetools.cn',
|
|
84
|
-
AZURE_US: 'https://mc-api.eastus.azure.commercetools.com',
|
|
85
|
-
AZURE_EU: 'https://mc-api.germanywestcentral.azure.commercetools.com'
|
|
75
|
+
[CLOUD_IDENTIFIERS.AWS_OHIO]: 'https://mc-api.us-east-2.aws.commercetools.com'
|
|
86
76
|
};
|
|
87
77
|
const LOADED_CONFIG_TYPES = {
|
|
88
78
|
CUSTOM_APPLICATION: 'custom-application',
|
|
@@ -106,65 +96,71 @@ let MissingOrInvalidConfigError = /*#__PURE__*/function (_Error) {
|
|
|
106
96
|
return _createClass(MissingOrInvalidConfigError);
|
|
107
97
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
108
98
|
|
|
109
|
-
|
|
99
|
+
// See the following issues for more context, contributing to failing Jest tests:
|
|
100
|
+
// - Issue: https://github.com/nodejs/node/issues/40058
|
|
101
|
+
// - Resolution: https://github.com/nodejs/node/pull/48510 (Node v20.8.0)
|
|
102
|
+
// Copied from @commitlint/load/src/utils/load-config.ts
|
|
103
|
+
const isDynamicAwaitSupported = () => {
|
|
104
|
+
var _context;
|
|
105
|
+
const _process$version$repl = _mapInstanceProperty(_context = process.version.replace('v', '').split('.')).call(_context, val => _parseInt(val)),
|
|
106
|
+
_process$version$repl2 = _slicedToArray(_process$version$repl, 2),
|
|
107
|
+
major = _process$version$repl2[0],
|
|
108
|
+
minor = _process$version$repl2[1];
|
|
109
|
+
return major >= 20 && minor >= 8;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
// Is the given directory set up to use ESM (ECMAScript Modules)?
|
|
113
|
+
// Copied from @commitlint/load/src/utils/load-config.ts
|
|
114
|
+
const isEsmModule = async cwd => {
|
|
115
|
+
const packagePath = path.join(cwd, 'package.json');
|
|
110
116
|
try {
|
|
111
|
-
fs.
|
|
112
|
-
|
|
117
|
+
const packageJSON = await fs.readFile(packagePath, {
|
|
118
|
+
encoding: 'utf-8'
|
|
119
|
+
});
|
|
120
|
+
return JSON.parse(packageJSON)?.type === 'module';
|
|
113
121
|
} catch (error) {
|
|
114
122
|
return false;
|
|
115
123
|
}
|
|
116
|
-
}
|
|
117
|
-
// Helper function to find the package root path from the current location,
|
|
118
|
-
// for instance in respect to both source files and dist files.
|
|
119
|
-
const findPackageRootPath = dir => {
|
|
120
|
-
const packageJsonPath = path.join(dir, 'package.json');
|
|
121
|
-
if (doesFileExist(packageJsonPath)) {
|
|
122
|
-
return dir;
|
|
123
|
-
}
|
|
124
|
-
const parentDir = path.join(dir, '..');
|
|
125
|
-
return findPackageRootPath(parentDir);
|
|
126
124
|
};
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
return
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
return cosmiconfigSync(configFileName, {
|
|
144
|
-
// Restrict the supported file formats / names
|
|
145
|
-
searchPlaces: [`.${configFileName}rc`, `.${configFileName}.json`, `.${configFileName}.js`, `.${configFileName}.cjs`, `.${configFileName}.mjs`, `.${configFileName}.ts`, `${configFileName}.json`, `${configFileName}.js`, `${configFileName}.cjs`, `${configFileName}.mjs`, `${configFileName}.ts`],
|
|
125
|
+
const createExplorerFor = async configFileName => {
|
|
126
|
+
// Copied from @commitlint/load/src/utils/load-config.ts
|
|
127
|
+
let tsLoaderInstance;
|
|
128
|
+
const tsLoader = function () {
|
|
129
|
+
if (!tsLoaderInstance) {
|
|
130
|
+
tsLoaderInstance = TypeScriptLoader();
|
|
131
|
+
}
|
|
132
|
+
return tsLoaderInstance(...arguments);
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
// If dynamic await is supported (Node >= v20.8.0) or directory uses ESM, support
|
|
136
|
+
// async js/cjs loaders (dynamic import). Otherwise, use synchronous js/cjs loaders.
|
|
137
|
+
const loaders = isDynamicAwaitSupported() || (await isEsmModule(process.cwd())) ? defaultLoaders : defaultLoadersSync;
|
|
138
|
+
return cosmiconfig(configFileName, {
|
|
139
|
+
searchStrategy: 'project',
|
|
140
|
+
searchPlaces: [`${configFileName}.js`, `${configFileName}.cjs`, `${configFileName}.mjs`, `${configFileName}.ts`],
|
|
146
141
|
loaders: {
|
|
147
|
-
|
|
148
|
-
'.
|
|
149
|
-
'.
|
|
150
|
-
'.
|
|
151
|
-
'.ts': loadJsModule
|
|
142
|
+
'.js': loaders['.js'],
|
|
143
|
+
'.cjs': loaders['.cjs'],
|
|
144
|
+
'.mjs': tsLoader,
|
|
145
|
+
'.ts': tsLoader
|
|
152
146
|
}
|
|
153
147
|
});
|
|
154
148
|
};
|
|
155
|
-
const
|
|
156
|
-
const
|
|
157
|
-
const
|
|
158
|
-
const customApplicationConfigFile = customApplicationExplorer.search();
|
|
159
|
-
const customViewConfigFile = customViewExplorer.search();
|
|
149
|
+
const getConfigPath = async () => {
|
|
150
|
+
const customApplicationExplorer = await createExplorerFor('custom-application-config');
|
|
151
|
+
const customViewExplorer = await createExplorerFor('custom-view-config');
|
|
152
|
+
const customApplicationConfigFile = await customApplicationExplorer.search();
|
|
153
|
+
const customViewConfigFile = await customViewExplorer.search();
|
|
160
154
|
if (!customApplicationConfigFile && !customViewConfigFile) {
|
|
161
155
|
throw new Error(`Missing or invalid configuration file.`);
|
|
162
156
|
}
|
|
163
157
|
return customApplicationConfigFile?.filepath || customViewConfigFile?.filepath;
|
|
164
158
|
};
|
|
165
|
-
const loadConfig = applicationPath => {
|
|
166
|
-
const
|
|
167
|
-
const
|
|
159
|
+
const loadConfig = async applicationPath => {
|
|
160
|
+
const customApplicationExplorer = await createExplorerFor('custom-application-config');
|
|
161
|
+
const customViewExplorer = await createExplorerFor('custom-view-config');
|
|
162
|
+
const customApplicationConfigFile = await customApplicationExplorer.search(applicationPath);
|
|
163
|
+
const customViewConfigFile = await customViewExplorer.search(applicationPath);
|
|
168
164
|
if ((!customApplicationConfigFile || !customApplicationConfigFile.config) && (!customViewConfigFile || !customViewConfigFile.config)) {
|
|
169
165
|
throw new MissingOrInvalidConfigError(`Missing or invalid configuration file.`);
|
|
170
166
|
}
|
|
@@ -232,7 +228,7 @@ const substituteFilePathVariablePlaceholder = (valueOfPlaceholder, matchedString
|
|
|
232
228
|
const _valueOfPlaceholder$s5 = valueOfPlaceholder.split(':'),
|
|
233
229
|
_valueOfPlaceholder$s6 = _slicedToArray(_valueOfPlaceholder$s5, 2),
|
|
234
230
|
filePathOrModule = _valueOfPlaceholder$s6[1];
|
|
235
|
-
const content = fs.readFileSync(require.resolve(filePathOrModule, {
|
|
231
|
+
const content = fs$1.readFileSync(require.resolve(filePathOrModule, {
|
|
236
232
|
// Relative paths should be resolved from the application folder.
|
|
237
233
|
paths: [loadingOptions.applicationPath]
|
|
238
234
|
}), {
|
|
@@ -1067,24 +1063,17 @@ function transformConfigurationToData(configType, configuration) {
|
|
|
1067
1063
|
const mapCloudIdentifierToApiUrl = key => {
|
|
1068
1064
|
switch (key) {
|
|
1069
1065
|
case CLOUD_IDENTIFIERS.GCP_AU:
|
|
1070
|
-
return MC_API_URLS.GCP_AU;
|
|
1066
|
+
return MC_API_URLS[CLOUD_IDENTIFIERS.GCP_AU];
|
|
1071
1067
|
case CLOUD_IDENTIFIERS.GCP_EU:
|
|
1072
|
-
return MC_API_URLS.GCP_EU;
|
|
1068
|
+
return MC_API_URLS[CLOUD_IDENTIFIERS.GCP_EU];
|
|
1073
1069
|
case CLOUD_IDENTIFIERS.GCP_US:
|
|
1074
|
-
return MC_API_URLS.GCP_US;
|
|
1070
|
+
return MC_API_URLS[CLOUD_IDENTIFIERS.GCP_US];
|
|
1075
1071
|
case CLOUD_IDENTIFIERS.AWS_EU:
|
|
1076
1072
|
case CLOUD_IDENTIFIERS.AWS_FRA:
|
|
1077
|
-
return MC_API_URLS.AWS_EU;
|
|
1073
|
+
return MC_API_URLS[CLOUD_IDENTIFIERS.AWS_EU];
|
|
1078
1074
|
case CLOUD_IDENTIFIERS.AWS_US:
|
|
1079
1075
|
case CLOUD_IDENTIFIERS.AWS_OHIO:
|
|
1080
|
-
return MC_API_URLS.AWS_US;
|
|
1081
|
-
// TODO: remove it
|
|
1082
|
-
case CLOUD_IDENTIFIERS.AWS_CN:
|
|
1083
|
-
return MC_API_URLS.AWS_CN;
|
|
1084
|
-
case CLOUD_IDENTIFIERS.AZURE_US:
|
|
1085
|
-
return MC_API_URLS.AZURE_US;
|
|
1086
|
-
case CLOUD_IDENTIFIERS.AZURE_EU:
|
|
1087
|
-
return MC_API_URLS.AZURE_EU;
|
|
1076
|
+
return MC_API_URLS[CLOUD_IDENTIFIERS.AWS_US];
|
|
1088
1077
|
default:
|
|
1089
1078
|
// We would probably never get to this point, as the JSON schema validation
|
|
1090
1079
|
// kicks in before.
|
|
@@ -1228,7 +1217,7 @@ const getRuntimeEnvironmentConfig = _ref2 => {
|
|
|
1228
1217
|
// Keep a reference to the config so that requiring the module
|
|
1229
1218
|
// again will result in returning the cached value.
|
|
1230
1219
|
let cachedConfig;
|
|
1231
|
-
const processConfig = function () {
|
|
1220
|
+
const processConfig = async function () {
|
|
1232
1221
|
var _context;
|
|
1233
1222
|
let _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
1234
1223
|
_ref3$disableCache = _ref3.disableCache,
|
|
@@ -1236,11 +1225,11 @@ const processConfig = function () {
|
|
|
1236
1225
|
_ref3$processEnv = _ref3.processEnv,
|
|
1237
1226
|
processEnv = _ref3$processEnv === void 0 ? process.env : _ref3$processEnv,
|
|
1238
1227
|
_ref3$applicationPath = _ref3.applicationPath,
|
|
1239
|
-
applicationPath = _ref3$applicationPath === void 0 ? fs.realpathSync(process.cwd()) : _ref3$applicationPath;
|
|
1228
|
+
applicationPath = _ref3$applicationPath === void 0 ? fs$1.realpathSync(process.cwd()) : _ref3$applicationPath;
|
|
1240
1229
|
if (cachedConfig && !disableCache) return cachedConfig;
|
|
1241
|
-
const
|
|
1242
|
-
filepath =
|
|
1243
|
-
rawConfig =
|
|
1230
|
+
const _await$loadConfig = await loadConfig(applicationPath),
|
|
1231
|
+
filepath = _await$loadConfig.filepath,
|
|
1232
|
+
rawConfig = _await$loadConfig.config;
|
|
1244
1233
|
const configType = getLoadedConfigurationType(parse(filepath).name);
|
|
1245
1234
|
validateConfig(configType, rawConfig);
|
|
1246
1235
|
const appConfig = substituteVariablePlaceholders(rawConfig, {
|
|
@@ -12,33 +12,21 @@ export declare const CLOUD_IDENTIFIERS: {
|
|
|
12
12
|
* @deprecated: use `AWS_US` instead
|
|
13
13
|
*/
|
|
14
14
|
readonly AWS_OHIO: "aws-ohio";
|
|
15
|
-
/**
|
|
16
|
-
* @deprecated: not supported anymore
|
|
17
|
-
*/
|
|
18
|
-
readonly AWS_CN: "aws-cn";
|
|
19
|
-
readonly AZURE_US: "azure-us";
|
|
20
|
-
readonly AZURE_EU: "azure-eu";
|
|
21
15
|
};
|
|
22
16
|
export declare const MC_API_URLS: {
|
|
23
|
-
readonly
|
|
24
|
-
readonly
|
|
25
|
-
readonly
|
|
26
|
-
readonly
|
|
27
|
-
readonly
|
|
17
|
+
readonly "gcp-au": "https://mc-api.australia-southeast1.gcp.commercetools.com";
|
|
18
|
+
readonly "gcp-eu": "https://mc-api.europe-west1.gcp.commercetools.com";
|
|
19
|
+
readonly "gcp-us": "https://mc-api.us-central1.gcp.commercetools.com";
|
|
20
|
+
readonly "aws-eu": "https://mc-api.eu-central-1.aws.commercetools.com";
|
|
21
|
+
readonly "aws-us": "https://mc-api.us-east-2.aws.commercetools.com";
|
|
28
22
|
/**
|
|
29
23
|
* @deprecated: use `AWS_EU` instead
|
|
30
24
|
*/
|
|
31
|
-
readonly
|
|
25
|
+
readonly "aws-fra": "https://mc-api.eu-central-1.aws.commercetools.com";
|
|
32
26
|
/**
|
|
33
27
|
* @deprecated: use `AWS_US` instead
|
|
34
28
|
*/
|
|
35
|
-
readonly
|
|
36
|
-
/**
|
|
37
|
-
* @deprecated: not supported anymore
|
|
38
|
-
*/
|
|
39
|
-
readonly AWS_CN: "https://mc-api.cn-northwest-1.aws.commercetools.cn";
|
|
40
|
-
readonly AZURE_US: "https://mc-api.eastus.azure.commercetools.com";
|
|
41
|
-
readonly AZURE_EU: "https://mc-api.germanywestcentral.azure.commercetools.com";
|
|
29
|
+
readonly "aws-ohio": "https://mc-api.us-east-2.aws.commercetools.com";
|
|
42
30
|
};
|
|
43
31
|
export declare const LOADED_CONFIG_TYPES: {
|
|
44
32
|
readonly CUSTOM_APPLICATION: "custom-application";
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { JSONSchemaForCustomApplicationConfigurationFiles } from './schemas/generated/custom-application.schema';
|
|
2
2
|
import type { JSONSchemaForCustomViewConfigurationFiles } from './schemas/generated/custom-view.schema';
|
|
3
|
-
export declare const
|
|
4
|
-
declare const
|
|
3
|
+
export declare const isDynamicAwaitSupported: () => boolean;
|
|
4
|
+
export declare const isEsmModule: (cwd: string) => Promise<boolean>;
|
|
5
|
+
export declare const getConfigPath: () => Promise<string | undefined>;
|
|
6
|
+
export type TLoadConfigResult = {
|
|
5
7
|
filepath: string;
|
|
6
8
|
config: JSONSchemaForCustomApplicationConfigurationFiles | JSONSchemaForCustomViewConfigurationFiles;
|
|
7
9
|
};
|
|
10
|
+
declare const loadConfig: (applicationPath: string) => Promise<TLoadConfigResult>;
|
|
8
11
|
export default loadConfig;
|
|
@@ -2,5 +2,5 @@ import type { ApplicationRuntimeConfig, LoadingConfigOptions } from './types';
|
|
|
2
2
|
type ProcessConfigOptions = Partial<LoadingConfigOptions> & {
|
|
3
3
|
disableCache?: boolean;
|
|
4
4
|
};
|
|
5
|
-
declare const processConfig: ({ disableCache, processEnv, applicationPath, }?: ProcessConfigOptions) => ApplicationRuntimeConfig
|
|
5
|
+
declare const processConfig: ({ disableCache, processEnv, applicationPath, }?: ProcessConfigOptions) => Promise<ApplicationRuntimeConfig>;
|
|
6
6
|
export default processConfig;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools-frontend/application-config",
|
|
3
|
-
"version": "22.
|
|
3
|
+
"version": "22.37.0",
|
|
4
4
|
"description": "Configuration utilities for building Custom Applications",
|
|
5
5
|
"bugs": "https://github.com/commercetools/merchant-center-application-kit/issues",
|
|
6
6
|
"repository": {
|
|
@@ -45,14 +45,14 @@
|
|
|
45
45
|
"@babel/register": "^7.22.15",
|
|
46
46
|
"@babel/runtime": "^7.22.15",
|
|
47
47
|
"@babel/runtime-corejs3": "^7.22.15",
|
|
48
|
-
"@commercetools-frontend/
|
|
49
|
-
"@commercetools-frontend/constants": "22.36.0-preview.0",
|
|
48
|
+
"@commercetools-frontend/constants": "22.37.0",
|
|
50
49
|
"@types/dompurify": "^2.4.0",
|
|
51
50
|
"@types/lodash": "^4.14.198",
|
|
52
51
|
"@types/react": "^17.0.80",
|
|
53
52
|
"ajv": "8.16.0",
|
|
54
53
|
"core-js": "^3.32.2",
|
|
55
|
-
"cosmiconfig": "
|
|
54
|
+
"cosmiconfig": "9.0.0",
|
|
55
|
+
"cosmiconfig-typescript-loader": "6.1.0",
|
|
56
56
|
"dompurify": "^2.4.7",
|
|
57
57
|
"jsdom": "^21.1.2",
|
|
58
58
|
"lodash": "4.17.21",
|
|
@@ -61,8 +61,7 @@
|
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@types/jsdom": "^21.1.2",
|
|
63
63
|
"json-schema-to-typescript": "13.1.2",
|
|
64
|
-
"
|
|
65
|
-
"@commercetools-frontend/assets": "22.36.0-preview.0"
|
|
64
|
+
"@commercetools-frontend/assets": "22.37.0"
|
|
66
65
|
},
|
|
67
66
|
"engines": {
|
|
68
67
|
"node": "16.x || >=18.0.0"
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This script file is used to load and parse a JS module in a child process,
|
|
3
|
-
* to isolate the Babel configuration from the main program and avoid causing
|
|
4
|
-
* unnecessary issues.
|
|
5
|
-
*
|
|
6
|
-
* NOTE: keep this file as a `.js` file, as we want to be able to run this
|
|
7
|
-
* in any Node environment.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
// Ensure there is a babel/node environment variable set, otherwise the
|
|
11
|
-
// babel preset throws an error.
|
|
12
|
-
process.env.BABEL_ENV = 'development';
|
|
13
|
-
|
|
14
|
-
const get = require('lodash/get');
|
|
15
|
-
|
|
16
|
-
// Load JS modules using Babel, as we need to load
|
|
17
|
-
// the config synchronously with `require`, no `await import`.
|
|
18
|
-
require('@babel/register')({
|
|
19
|
-
babelrc: false,
|
|
20
|
-
extensions: ['.js', '.cjs', '.mjs', '.ts'],
|
|
21
|
-
presets: ['@commercetools-frontend/babel-preset-mc-app'],
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
// The file to `require` is passed as the main argument to this script file.
|
|
25
|
-
const [filePath] = process.argv.slice(2);
|
|
26
|
-
|
|
27
|
-
// Require the module. It's expected that the module exports the application config
|
|
28
|
-
const moduleExport = require(filePath);
|
|
29
|
-
|
|
30
|
-
// In case we are loading an ES module, we need to pick the `default` export.
|
|
31
|
-
const result = get(moduleExport, 'default', moduleExport);
|
|
32
|
-
|
|
33
|
-
// Write the application config to `stdout`so that the main program can read it.
|
|
34
|
-
process.stdout.write(JSON.stringify(result));
|