@commercetools-frontend/application-config 21.3.2 → 21.5.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.
@@ -27,6 +27,7 @@ var _possibleConstructorReturn = require('@babel/runtime-corejs3/helpers/possibl
27
27
  var _getPrototypeOf = require('@babel/runtime-corejs3/helpers/getPrototypeOf');
28
28
  var _wrapNativeSuper = require('@babel/runtime-corejs3/helpers/wrapNativeSuper');
29
29
  var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
30
+ var _Set = require('@babel/runtime-corejs3/core-js-stable/set');
30
31
  var Ajv = require('ajv');
31
32
  var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
32
33
  var _trimInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/trim');
@@ -35,6 +36,7 @@ var _toConsumableArray = require('@babel/runtime-corejs3/helpers/toConsumableArr
35
36
  var _Object$values = require('@babel/runtime-corejs3/core-js-stable/object/values');
36
37
  var _includesInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/includes');
37
38
  var uniq = require('lodash/uniq');
39
+ var _startsWithInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/starts-with');
38
40
  var formatters = require('./formatters-41584280.cjs.dev.js');
39
41
  require('lodash/upperFirst');
40
42
 
@@ -55,12 +57,14 @@ var omitEmpty__default = /*#__PURE__*/_interopDefault(omitEmpty);
55
57
  var path__default = /*#__PURE__*/_interopDefault(path);
56
58
  var _Reflect$construct__default = /*#__PURE__*/_interopDefault(_Reflect$construct);
57
59
  var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
60
+ var _Set__default = /*#__PURE__*/_interopDefault(_Set);
58
61
  var Ajv__default = /*#__PURE__*/_interopDefault(Ajv);
59
62
  var _trimInstanceProperty__default = /*#__PURE__*/_interopDefault(_trimInstanceProperty);
60
63
  var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
61
64
  var _Object$values__default = /*#__PURE__*/_interopDefault(_Object$values);
62
65
  var _includesInstanceProperty__default = /*#__PURE__*/_interopDefault(_includesInstanceProperty);
63
66
  var uniq__default = /*#__PURE__*/_interopDefault(uniq);
67
+ var _startsWithInstanceProperty__default = /*#__PURE__*/_interopDefault(_startsWithInstanceProperty);
64
68
 
65
69
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = _Reflect$construct__default["default"](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
66
70
 
@@ -522,6 +526,21 @@ var validateConfig = function validateConfig(config) {
522
526
  throw new Error(printErrors(validate.errors));
523
527
  }
524
528
  };
529
+ var validateSubmenuLinks = function validateSubmenuLinks(config) {
530
+ var _context4;
531
+
532
+ var uriPathSet = new _Set__default["default"]();
533
+
534
+ _forEachInstanceProperty__default["default"](_context4 = config.submenuLinks).call(_context4, function (_ref) {
535
+ var uriPath = _ref.uriPath;
536
+
537
+ if (uriPathSet.has(uriPath)) {
538
+ throw new Error('Duplicate URI path. Every submenu link must have a unique URI path value');
539
+ }
540
+
541
+ uriPathSet.add(uriPath);
542
+ });
543
+ };
525
544
 
526
545
  /**
527
546
  * NOTE:
@@ -713,8 +732,31 @@ var getOrThrow = function getOrThrow(fn, errorMessage) {
713
732
  }
714
733
  };
715
734
 
735
+ function ownKeys$1(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
736
+
737
+ function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var _context3, _context4; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context3 = ownKeys$1(Object(source), !0)).call(_context3, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context4 = ownKeys$1(Object(source))).call(_context4, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
738
+ // to the `entryPointUriPath`. Computing the full path is done internally to keep
739
+ // the configuration simple.
740
+
741
+ var computeUriPath = function computeUriPath(uriPath, entryPointUriPath) {
742
+ var _context;
743
+
744
+ // In case the `uriPath` is only `/`, it means that the link is supposed to be
745
+ // treated the same as the main application path. In this case, the return value
746
+ // should not contain any unnecessary trailing slash and therefore we use the `entryPointUriPath`.
747
+ if (uriPath === '/') return entryPointUriPath; // In case the `uriPath` is already configured including the `entryPointUriPath`,
748
+ // we return the `uriPath` as-is.
749
+
750
+ if (_startsWithInstanceProperty__default["default"](uriPath).call(uriPath, "".concat(entryPointUriPath, "/"))) return uriPath; // Return the full path including the `entryPointUriPath` as a prefix.
751
+
752
+ return _concatInstanceProperty__default["default"](_context = "".concat(entryPointUriPath, "/")).call(_context, uriPath);
753
+ };
754
+
716
755
  function transformCustomApplicationConfigToData(appConfig) {
756
+ var _context2;
757
+
717
758
  var permissionKeys = formatters.entryPointUriPathToResourceAccesses(appConfig.entryPointUriPath);
759
+ validateSubmenuLinks(appConfig);
718
760
  return {
719
761
  id: appConfig.env.production.applicationId,
720
762
  name: appConfig.name,
@@ -730,7 +772,11 @@ function transformCustomApplicationConfigToData(appConfig) {
730
772
  }],
731
773
  icon: appConfig.icon,
732
774
  mainMenuLink: appConfig.mainMenuLink,
733
- submenuLinks: appConfig.submenuLinks
775
+ submenuLinks: _mapInstanceProperty__default["default"](_context2 = appConfig.submenuLinks).call(_context2, function (submenuLink) {
776
+ return _objectSpread$1(_objectSpread$1({}, submenuLink), {}, {
777
+ uriPath: computeUriPath(submenuLink.uriPath, appConfig.entryPointUriPath)
778
+ });
779
+ })
734
780
  };
735
781
  }
736
782
 
@@ -27,6 +27,7 @@ var _possibleConstructorReturn = require('@babel/runtime-corejs3/helpers/possibl
27
27
  var _getPrototypeOf = require('@babel/runtime-corejs3/helpers/getPrototypeOf');
28
28
  var _wrapNativeSuper = require('@babel/runtime-corejs3/helpers/wrapNativeSuper');
29
29
  var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
30
+ var _Set = require('@babel/runtime-corejs3/core-js-stable/set');
30
31
  var Ajv = require('ajv');
31
32
  var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
32
33
  var _trimInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/trim');
@@ -35,6 +36,7 @@ var _toConsumableArray = require('@babel/runtime-corejs3/helpers/toConsumableArr
35
36
  var _Object$values = require('@babel/runtime-corejs3/core-js-stable/object/values');
36
37
  var _includesInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/includes');
37
38
  var uniq = require('lodash/uniq');
39
+ var _startsWithInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/starts-with');
38
40
  var formatters = require('./formatters-40251cfd.cjs.prod.js');
39
41
  require('lodash/upperFirst');
40
42
 
@@ -55,12 +57,14 @@ var omitEmpty__default = /*#__PURE__*/_interopDefault(omitEmpty);
55
57
  var path__default = /*#__PURE__*/_interopDefault(path);
56
58
  var _Reflect$construct__default = /*#__PURE__*/_interopDefault(_Reflect$construct);
57
59
  var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
60
+ var _Set__default = /*#__PURE__*/_interopDefault(_Set);
58
61
  var Ajv__default = /*#__PURE__*/_interopDefault(Ajv);
59
62
  var _trimInstanceProperty__default = /*#__PURE__*/_interopDefault(_trimInstanceProperty);
60
63
  var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
61
64
  var _Object$values__default = /*#__PURE__*/_interopDefault(_Object$values);
62
65
  var _includesInstanceProperty__default = /*#__PURE__*/_interopDefault(_includesInstanceProperty);
63
66
  var uniq__default = /*#__PURE__*/_interopDefault(uniq);
67
+ var _startsWithInstanceProperty__default = /*#__PURE__*/_interopDefault(_startsWithInstanceProperty);
64
68
 
65
69
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = _Reflect$construct__default["default"](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
66
70
 
@@ -522,6 +526,21 @@ var validateConfig = function validateConfig(config) {
522
526
  throw new Error(printErrors(validate.errors));
523
527
  }
524
528
  };
529
+ var validateSubmenuLinks = function validateSubmenuLinks(config) {
530
+ var _context4;
531
+
532
+ var uriPathSet = new _Set__default["default"]();
533
+
534
+ _forEachInstanceProperty__default["default"](_context4 = config.submenuLinks).call(_context4, function (_ref) {
535
+ var uriPath = _ref.uriPath;
536
+
537
+ if (uriPathSet.has(uriPath)) {
538
+ throw new Error('Duplicate URI path. Every submenu link must have a unique URI path value');
539
+ }
540
+
541
+ uriPathSet.add(uriPath);
542
+ });
543
+ };
525
544
 
526
545
  /**
527
546
  * NOTE:
@@ -713,8 +732,31 @@ var getOrThrow = function getOrThrow(fn, errorMessage) {
713
732
  }
714
733
  };
715
734
 
735
+ function ownKeys$1(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
736
+
737
+ function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var _context3, _context4; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context3 = ownKeys$1(Object(source), !0)).call(_context3, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context4 = ownKeys$1(Object(source))).call(_context4, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
738
+ // to the `entryPointUriPath`. Computing the full path is done internally to keep
739
+ // the configuration simple.
740
+
741
+ var computeUriPath = function computeUriPath(uriPath, entryPointUriPath) {
742
+ var _context;
743
+
744
+ // In case the `uriPath` is only `/`, it means that the link is supposed to be
745
+ // treated the same as the main application path. In this case, the return value
746
+ // should not contain any unnecessary trailing slash and therefore we use the `entryPointUriPath`.
747
+ if (uriPath === '/') return entryPointUriPath; // In case the `uriPath` is already configured including the `entryPointUriPath`,
748
+ // we return the `uriPath` as-is.
749
+
750
+ if (_startsWithInstanceProperty__default["default"](uriPath).call(uriPath, "".concat(entryPointUriPath, "/"))) return uriPath; // Return the full path including the `entryPointUriPath` as a prefix.
751
+
752
+ return _concatInstanceProperty__default["default"](_context = "".concat(entryPointUriPath, "/")).call(_context, uriPath);
753
+ };
754
+
716
755
  function transformCustomApplicationConfigToData(appConfig) {
756
+ var _context2;
757
+
717
758
  var permissionKeys = formatters.entryPointUriPathToResourceAccesses(appConfig.entryPointUriPath);
759
+ validateSubmenuLinks(appConfig);
718
760
  return {
719
761
  id: appConfig.env.production.applicationId,
720
762
  name: appConfig.name,
@@ -730,7 +772,11 @@ function transformCustomApplicationConfigToData(appConfig) {
730
772
  }],
731
773
  icon: appConfig.icon,
732
774
  mainMenuLink: appConfig.mainMenuLink,
733
- submenuLinks: appConfig.submenuLinks
775
+ submenuLinks: _mapInstanceProperty__default["default"](_context2 = appConfig.submenuLinks).call(_context2, function (submenuLink) {
776
+ return _objectSpread$1(_objectSpread$1({}, submenuLink), {}, {
777
+ uriPath: computeUriPath(submenuLink.uriPath, appConfig.entryPointUriPath)
778
+ });
779
+ })
734
780
  };
735
781
  }
736
782
 
@@ -23,6 +23,7 @@ import _possibleConstructorReturn from '@babel/runtime-corejs3/helpers/esm/possi
23
23
  import _getPrototypeOf from '@babel/runtime-corejs3/helpers/esm/getPrototypeOf';
24
24
  import _wrapNativeSuper from '@babel/runtime-corejs3/helpers/esm/wrapNativeSuper';
25
25
  import _mapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/map';
26
+ import _Set from '@babel/runtime-corejs3/core-js-stable/set';
26
27
  import Ajv from 'ajv';
27
28
  import _slicedToArray from '@babel/runtime-corejs3/helpers/esm/slicedToArray';
28
29
  import _trimInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/trim';
@@ -31,6 +32,7 @@ import _toConsumableArray from '@babel/runtime-corejs3/helpers/esm/toConsumableA
31
32
  import _Object$values from '@babel/runtime-corejs3/core-js-stable/object/values';
32
33
  import _includesInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/includes';
33
34
  import uniq from 'lodash/uniq';
35
+ import _startsWithInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/starts-with';
34
36
  import { e as entryPointUriPathToResourceAccesses } from './formatters-62af6993.esm.js';
35
37
  import 'lodash/upperFirst';
36
38
 
@@ -494,6 +496,21 @@ var validateConfig = function validateConfig(config) {
494
496
  throw new Error(printErrors(validate.errors));
495
497
  }
496
498
  };
499
+ var validateSubmenuLinks = function validateSubmenuLinks(config) {
500
+ var _context4;
501
+
502
+ var uriPathSet = new _Set();
503
+
504
+ _forEachInstanceProperty(_context4 = config.submenuLinks).call(_context4, function (_ref) {
505
+ var uriPath = _ref.uriPath;
506
+
507
+ if (uriPathSet.has(uriPath)) {
508
+ throw new Error('Duplicate URI path. Every submenu link must have a unique URI path value');
509
+ }
510
+
511
+ uriPathSet.add(uriPath);
512
+ });
513
+ };
497
514
 
498
515
  /**
499
516
  * NOTE:
@@ -685,8 +702,31 @@ var getOrThrow = function getOrThrow(fn, errorMessage) {
685
702
  }
686
703
  };
687
704
 
705
+ 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; }
706
+
707
+ function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var _context3, _context4; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context3 = ownKeys$1(Object(source), !0)).call(_context3, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context4 = ownKeys$1(Object(source))).call(_context4, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
708
+ // to the `entryPointUriPath`. Computing the full path is done internally to keep
709
+ // the configuration simple.
710
+
711
+ var computeUriPath = function computeUriPath(uriPath, entryPointUriPath) {
712
+ var _context;
713
+
714
+ // In case the `uriPath` is only `/`, it means that the link is supposed to be
715
+ // treated the same as the main application path. In this case, the return value
716
+ // should not contain any unnecessary trailing slash and therefore we use the `entryPointUriPath`.
717
+ if (uriPath === '/') return entryPointUriPath; // In case the `uriPath` is already configured including the `entryPointUriPath`,
718
+ // we return the `uriPath` as-is.
719
+
720
+ if (_startsWithInstanceProperty(uriPath).call(uriPath, "".concat(entryPointUriPath, "/"))) return uriPath; // Return the full path including the `entryPointUriPath` as a prefix.
721
+
722
+ return _concatInstanceProperty(_context = "".concat(entryPointUriPath, "/")).call(_context, uriPath);
723
+ };
724
+
688
725
  function transformCustomApplicationConfigToData(appConfig) {
726
+ var _context2;
727
+
689
728
  var permissionKeys = entryPointUriPathToResourceAccesses(appConfig.entryPointUriPath);
729
+ validateSubmenuLinks(appConfig);
690
730
  return {
691
731
  id: appConfig.env.production.applicationId,
692
732
  name: appConfig.name,
@@ -702,7 +742,11 @@ function transformCustomApplicationConfigToData(appConfig) {
702
742
  }],
703
743
  icon: appConfig.icon,
704
744
  mainMenuLink: appConfig.mainMenuLink,
705
- submenuLinks: appConfig.submenuLinks
745
+ submenuLinks: _mapInstanceProperty(_context2 = appConfig.submenuLinks).call(_context2, function (submenuLink) {
746
+ return _objectSpread$1(_objectSpread$1({}, submenuLink), {}, {
747
+ uriPath: computeUriPath(submenuLink.uriPath, appConfig.entryPointUriPath)
748
+ });
749
+ })
706
750
  };
707
751
  }
708
752
 
@@ -34,9 +34,9 @@ export declare type CustomApplicationData = {
34
34
  mainMenuLink: CustomApplicationMenuLinkData;
35
35
  submenuLinks: CustomApplicationSubmenuLinkData[];
36
36
  };
37
- export declare type ApplicationRuntimeConfig = {
37
+ export declare type ApplicationRuntimeConfig<AdditionalEnvironmentProperties extends {} = {}> = {
38
38
  data: CustomApplicationData;
39
- env: ApplicationWindow['app'];
39
+ env: AdditionalEnvironmentProperties & ApplicationWindow['app'];
40
40
  headers: JSONSchemaForCustomApplicationConfigurationFiles['headers'];
41
41
  };
42
42
  export declare type LoadingConfigOptions = {
@@ -0,0 +1,3 @@
1
+ import type { JSONSchemaForCustomApplicationConfigurationFiles } from './schema';
2
+ export declare const validateConfig: (config: JSONSchemaForCustomApplicationConfigurationFiles) => void;
3
+ export declare const validateSubmenuLinks: (config: JSONSchemaForCustomApplicationConfigurationFiles) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercetools-frontend/application-config",
3
- "version": "21.3.2",
3
+ "version": "21.5.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": {
@@ -33,9 +33,9 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@babel/register": "^7.17.7",
36
- "@babel/runtime": "^7.17.8",
37
- "@babel/runtime-corejs3": "^7.17.8",
38
- "@commercetools-frontend/babel-preset-mc-app": "21.3.2",
36
+ "@babel/runtime": "^7.17.9",
37
+ "@babel/runtime-corejs3": "^7.17.9",
38
+ "@commercetools-frontend/babel-preset-mc-app": "21.3.4",
39
39
  "ajv": "8.11.0",
40
40
  "core-js": "^3.21.1",
41
41
  "cosmiconfig": "7.0.1",
@@ -1,3 +0,0 @@
1
- import type { JSONSchemaForCustomApplicationConfigurationFiles } from './schema';
2
- declare const validateConfig: (config: JSONSchemaForCustomApplicationConfigurationFiles) => void;
3
- export default validateConfig;