@commercetools-frontend/application-config 21.2.1 → 21.3.3

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.
@@ -24,13 +24,16 @@ 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
26
  import Ajv from 'ajv';
27
+ import _slicedToArray from '@babel/runtime-corejs3/helpers/esm/slicedToArray';
28
+ import _trimInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/trim';
29
+ import _JSON$stringify from '@babel/runtime-corejs3/core-js-stable/json/stringify';
27
30
  import _toConsumableArray from '@babel/runtime-corejs3/helpers/esm/toConsumableArray';
28
31
  import _Object$values from '@babel/runtime-corejs3/core-js-stable/object/values';
29
32
  import _includesInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/includes';
30
33
  import uniq from 'lodash/uniq';
31
- import _slicedToArray from '@babel/runtime-corejs3/helpers/esm/slicedToArray';
32
- import _trimInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/trim';
33
- import _JSON$stringify from '@babel/runtime-corejs3/core-js-stable/json/stringify';
34
+ import _startsWithInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/starts-with';
35
+ import { e as entryPointUriPathToResourceAccesses } from './formatters-62af6993.esm.js';
36
+ import 'lodash/upperFirst';
34
37
 
35
38
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = _Reflect$construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
36
39
 
@@ -98,6 +101,15 @@ var explorer = cosmiconfigSync(moduleName, {
98
101
  '.ts': loadJsModule
99
102
  }
100
103
  });
104
+ var getConfigPath = function getConfigPath() {
105
+ var configFile = explorer.search();
106
+
107
+ if (!configFile) {
108
+ throw new Error("Missing or invalid Custom Application configuration file.");
109
+ }
110
+
111
+ return configFile.filepath;
112
+ };
101
113
 
102
114
  var loadConfig = function loadConfig(applicationPath) {
103
115
  var configFile = explorer.search(applicationPath);
@@ -484,74 +496,6 @@ var validateConfig = function validateConfig(config) {
484
496
  }
485
497
  };
486
498
 
487
- var CLOUD_IDENTIFIERS = {
488
- GCP_AU: 'gcp-au',
489
- GCP_EU: 'gcp-eu',
490
- GCP_US: 'gcp-us',
491
- AWS_FRA: 'aws-fra',
492
- AWS_OHIO: 'aws-ohio'
493
- };
494
- var MC_API_URLS = {
495
- GCP_AU: 'https://mc-api.australia-southeast1.gcp.commercetools.com',
496
- GCP_EU: 'https://mc-api.europe-west1.gcp.commercetools.com',
497
- GCP_US: 'https://mc-api.us-central1.gcp.commercetools.com',
498
- AWS_FRA: 'https://mc-api.eu-central-1.aws.commercetools.com',
499
- AWS_OHIO: 'https://mc-api.us-east-2.aws.commercetools.com'
500
- };
501
-
502
- var mapCloudIdentifierToApiUrl = function mapCloudIdentifierToApiUrl(key) {
503
- var _context;
504
-
505
- switch (key) {
506
- case CLOUD_IDENTIFIERS.GCP_AU:
507
- return MC_API_URLS.GCP_AU;
508
-
509
- case CLOUD_IDENTIFIERS.GCP_EU:
510
- return MC_API_URLS.GCP_EU;
511
-
512
- case CLOUD_IDENTIFIERS.GCP_US:
513
- return MC_API_URLS.GCP_US;
514
-
515
- case CLOUD_IDENTIFIERS.AWS_FRA:
516
- return MC_API_URLS.AWS_FRA;
517
-
518
- case CLOUD_IDENTIFIERS.AWS_OHIO:
519
- return MC_API_URLS.AWS_OHIO;
520
-
521
- default:
522
- // We would probably never get to this point, as the JSON schema validation
523
- // kicks in before.
524
- throw new Error(_concatInstanceProperty(_context = "Unknown cloud identifier \"".concat(key, "\". Supported values: ")).call(_context, _Object$values(CLOUD_IDENTIFIERS).toString()));
525
- }
526
- };
527
-
528
- var getUniqueValues = function getUniqueValues() {
529
- var _context2;
530
-
531
- var initialValues = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
532
- var additionalValues = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
533
- return uniq(_concatInstanceProperty(_context2 = []).call(_context2, _toConsumableArray(initialValues), _toConsumableArray(additionalValues)));
534
- };
535
-
536
- var nonProductionEnvironment = ['development', 'test'];
537
-
538
- var getIsProd = function getIsProd(env) {
539
- return (// TL;DR: in case the `MC_APP_ENV` is defined, we consider that it's
540
- // a production environment unless it's one of `development` or `test`.
541
- // This allows to use for example the `staging` value, which from the
542
- // application perspective is still considered a production environment.
543
- env.MC_APP_ENV ? !_includesInstanceProperty(nonProductionEnvironment).call(nonProductionEnvironment, env.MC_APP_ENV) : env.NODE_ENV === 'production'
544
- );
545
- };
546
-
547
- var getOrThrow = function getOrThrow(fn, errorMessage) {
548
- try {
549
- return fn();
550
- } catch (error) {
551
- throw new Error(errorMessage);
552
- }
553
- };
554
-
555
499
  /**
556
500
  * NOTE:
557
501
  * Allows variable placeholders. Supported types are:
@@ -585,12 +529,12 @@ var isFilePathVariablePlaceholder = function isFilePathVariablePlaceholder(value
585
529
  return Boolean(valueOfPlaceholder.match(filePathRefSyntax));
586
530
  };
587
531
 
588
- var substituteEnvVariablePlaceholder = function substituteEnvVariablePlaceholder(valueOfPlaceholder, matchedString, valueOfEnvConfig, meta) {
532
+ var substituteEnvVariablePlaceholder = function substituteEnvVariablePlaceholder(valueOfPlaceholder, matchedString, valueOfEnvConfig, loadingOptions) {
589
533
  var _valueOfPlaceholder$s = valueOfPlaceholder.split(':'),
590
534
  _valueOfPlaceholder$s2 = _slicedToArray(_valueOfPlaceholder$s, 2),
591
535
  requestedEnvVar = _valueOfPlaceholder$s2[1];
592
536
 
593
- var hasEnvField = meta.processEnv.hasOwnProperty(requestedEnvVar);
537
+ var hasEnvField = loadingOptions.processEnv.hasOwnProperty(requestedEnvVar);
594
538
 
595
539
  if (!hasEnvField) {
596
540
  var _context;
@@ -599,17 +543,17 @@ var substituteEnvVariablePlaceholder = function substituteEnvVariablePlaceholder
599
543
  }
600
544
 
601
545
  var escapedMatchedString = matchedString.replace(/[${}:]/g, '\\$&');
602
- return valueOfEnvConfig.replace(new RegExp("(".concat(escapedMatchedString, ")+"), 'g'), meta.processEnv[requestedEnvVar]);
546
+ return valueOfEnvConfig.replace(new RegExp("(".concat(escapedMatchedString, ")+"), 'g'), loadingOptions.processEnv[requestedEnvVar]);
603
547
  };
604
548
 
605
- var substituteIntlVariablePlaceholder = function substituteIntlVariablePlaceholder(valueOfPlaceholder, matchedString, valueOfEnvConfig, meta) {
549
+ var substituteIntlVariablePlaceholder = function substituteIntlVariablePlaceholder(valueOfPlaceholder, matchedString, valueOfEnvConfig, loadingOptions) {
606
550
  var _valueOfPlaceholder$s3 = valueOfPlaceholder.split(':'),
607
551
  _valueOfPlaceholder$s4 = _slicedToArray(_valueOfPlaceholder$s3, 3),
608
552
  locale = _valueOfPlaceholder$s4[1],
609
553
  requestedIntlMessageId = _valueOfPlaceholder$s4[2];
610
554
 
611
555
  var translationsFilePath = require.resolve("./i18n/data/".concat(locale, ".json"), {
612
- paths: ["".concat(meta.applicationPath, "/src"), meta.applicationPath]
556
+ paths: ["".concat(loadingOptions.applicationPath, "/src"), loadingOptions.applicationPath]
613
557
  });
614
558
 
615
559
  var translations = require(translationsFilePath);
@@ -626,14 +570,14 @@ var substituteIntlVariablePlaceholder = function substituteIntlVariablePlacehold
626
570
  return valueOfEnvConfig.replace(new RegExp("(".concat(escapedMatchedString, ")+"), 'g'), translations[requestedIntlMessageId]);
627
571
  };
628
572
 
629
- var substituteFilePathVariablePlaceholder = function substituteFilePathVariablePlaceholder(valueOfPlaceholder, matchedString, valueOfEnvConfig, meta) {
573
+ var substituteFilePathVariablePlaceholder = function substituteFilePathVariablePlaceholder(valueOfPlaceholder, matchedString, valueOfEnvConfig, loadingOptions) {
630
574
  var _valueOfPlaceholder$s5 = valueOfPlaceholder.split(':'),
631
575
  _valueOfPlaceholder$s6 = _slicedToArray(_valueOfPlaceholder$s5, 2),
632
576
  filePathOrModule = _valueOfPlaceholder$s6[1];
633
577
 
634
578
  var content = fs.readFileSync(require.resolve(filePathOrModule, {
635
579
  // Relative paths should be resolved from the application folder.
636
- paths: [meta.applicationPath]
580
+ paths: [loadingOptions.applicationPath]
637
581
  }), {
638
582
  encoding: 'utf-8'
639
583
  });
@@ -647,7 +591,7 @@ var getValueOfPlaceholder = function getValueOfPlaceholder(valueWithPlaceholder)
647
591
  }).replace(/\s/g, '');
648
592
  };
649
593
 
650
- var substituteVariablePlaceholders = function substituteVariablePlaceholders(config, meta) {
594
+ var substituteVariablePlaceholders = function substituteVariablePlaceholders(config, loadingOptions) {
651
595
  return JSON.parse(_JSON$stringify(config), function (_key, value) {
652
596
  // Only strings are allowed
653
597
  var substitutedValue = value;
@@ -660,11 +604,11 @@ var substituteVariablePlaceholders = function substituteVariablePlaceholders(con
660
604
  var valueOfPlaceholder = getValueOfPlaceholder(matchedString);
661
605
 
662
606
  if (isEnvVariablePlaceholder(valueOfPlaceholder)) {
663
- substitutedValue = substituteEnvVariablePlaceholder(valueOfPlaceholder, matchedString, substitutedValue, meta);
607
+ substitutedValue = substituteEnvVariablePlaceholder(valueOfPlaceholder, matchedString, substitutedValue, loadingOptions);
664
608
  } else if (isIntlVariablePlaceholder(valueOfPlaceholder)) {
665
- substitutedValue = substituteIntlVariablePlaceholder(valueOfPlaceholder, matchedString, substitutedValue, meta);
609
+ substitutedValue = substituteIntlVariablePlaceholder(valueOfPlaceholder, matchedString, substitutedValue, loadingOptions);
666
610
  } else if (isFilePathVariablePlaceholder(valueOfPlaceholder)) {
667
- substitutedValue = substituteFilePathVariablePlaceholder(valueOfPlaceholder, matchedString, substitutedValue, meta);
611
+ substitutedValue = substituteFilePathVariablePlaceholder(valueOfPlaceholder, matchedString, substitutedValue, loadingOptions);
668
612
  }
669
613
  });
670
614
  }
@@ -674,6 +618,121 @@ var substituteVariablePlaceholders = function substituteVariablePlaceholders(con
674
618
  });
675
619
  };
676
620
 
621
+ var CLOUD_IDENTIFIERS = {
622
+ GCP_AU: 'gcp-au',
623
+ GCP_EU: 'gcp-eu',
624
+ GCP_US: 'gcp-us',
625
+ AWS_FRA: 'aws-fra',
626
+ AWS_OHIO: 'aws-ohio'
627
+ };
628
+ var MC_API_URLS = {
629
+ GCP_AU: 'https://mc-api.australia-southeast1.gcp.commercetools.com',
630
+ GCP_EU: 'https://mc-api.europe-west1.gcp.commercetools.com',
631
+ GCP_US: 'https://mc-api.us-central1.gcp.commercetools.com',
632
+ AWS_FRA: 'https://mc-api.eu-central-1.aws.commercetools.com',
633
+ AWS_OHIO: 'https://mc-api.us-east-2.aws.commercetools.com'
634
+ };
635
+
636
+ var mapCloudIdentifierToApiUrl = function mapCloudIdentifierToApiUrl(key) {
637
+ var _context;
638
+
639
+ switch (key) {
640
+ case CLOUD_IDENTIFIERS.GCP_AU:
641
+ return MC_API_URLS.GCP_AU;
642
+
643
+ case CLOUD_IDENTIFIERS.GCP_EU:
644
+ return MC_API_URLS.GCP_EU;
645
+
646
+ case CLOUD_IDENTIFIERS.GCP_US:
647
+ return MC_API_URLS.GCP_US;
648
+
649
+ case CLOUD_IDENTIFIERS.AWS_FRA:
650
+ return MC_API_URLS.AWS_FRA;
651
+
652
+ case CLOUD_IDENTIFIERS.AWS_OHIO:
653
+ return MC_API_URLS.AWS_OHIO;
654
+
655
+ default:
656
+ // We would probably never get to this point, as the JSON schema validation
657
+ // kicks in before.
658
+ throw new Error(_concatInstanceProperty(_context = "Unknown cloud identifier \"".concat(key, "\". Supported values: ")).call(_context, _Object$values(CLOUD_IDENTIFIERS).toString()));
659
+ }
660
+ };
661
+
662
+ var getUniqueValues = function getUniqueValues() {
663
+ var _context2;
664
+
665
+ var initialValues = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
666
+ var additionalValues = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
667
+ return uniq(_concatInstanceProperty(_context2 = []).call(_context2, _toConsumableArray(initialValues), _toConsumableArray(additionalValues)));
668
+ };
669
+
670
+ var nonProductionEnvironment = ['development', 'test'];
671
+
672
+ var getIsProd = function getIsProd(env) {
673
+ return (// TL;DR: in case the `MC_APP_ENV` is defined, we consider that it's
674
+ // a production environment unless it's one of `development` or `test`.
675
+ // This allows to use for example the `staging` value, which from the
676
+ // application perspective is still considered a production environment.
677
+ env.MC_APP_ENV ? !_includesInstanceProperty(nonProductionEnvironment).call(nonProductionEnvironment, env.MC_APP_ENV) : env.NODE_ENV === 'production'
678
+ );
679
+ };
680
+
681
+ var getOrThrow = function getOrThrow(fn, errorMessage) {
682
+ try {
683
+ return fn();
684
+ } catch (error) {
685
+ throw new Error(errorMessage);
686
+ }
687
+ };
688
+
689
+ 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; }
690
+
691
+ 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; }
692
+ // to the `entryPointUriPath`. Computing the full path is done internally to keep
693
+ // the configuration simple.
694
+
695
+ var computeUriPath = function computeUriPath(uriPath, entryPointUriPath) {
696
+ var _context;
697
+
698
+ // In case the `uriPath` is only `/`, it means that the link is supposed to be
699
+ // treated the same as the main application path. In this case, the return value
700
+ // should not contain any unnecessary trailing slash and therefore we use the `entryPointUriPath`.
701
+ if (uriPath === '/') return entryPointUriPath; // In case the `uriPath` is already configured including the `entryPointUriPath`,
702
+ // we return the `uriPath` as-is.
703
+
704
+ if (_startsWithInstanceProperty(uriPath).call(uriPath, "".concat(entryPointUriPath, "/"))) return uriPath; // Return the full path including the `entryPointUriPath` as a prefix.
705
+
706
+ return _concatInstanceProperty(_context = "".concat(entryPointUriPath, "/")).call(_context, uriPath);
707
+ };
708
+
709
+ function transformCustomApplicationConfigToData(appConfig) {
710
+ var _context2;
711
+
712
+ var permissionKeys = entryPointUriPathToResourceAccesses(appConfig.entryPointUriPath);
713
+ return {
714
+ id: appConfig.env.production.applicationId,
715
+ name: appConfig.name,
716
+ description: appConfig.description,
717
+ entryPointUriPath: appConfig.entryPointUriPath,
718
+ url: appConfig.env.production.url,
719
+ permissions: [{
720
+ name: permissionKeys.view,
721
+ oAuthScopes: appConfig.oAuthScopes.view
722
+ }, {
723
+ name: permissionKeys.manage,
724
+ oAuthScopes: appConfig.oAuthScopes.manage
725
+ }],
726
+ icon: appConfig.icon,
727
+ mainMenuLink: appConfig.mainMenuLink,
728
+ submenuLinks: _mapInstanceProperty(_context2 = appConfig.submenuLinks).call(_context2, function (submenuLink) {
729
+ return _objectSpread$1(_objectSpread$1({}, submenuLink), {}, {
730
+ uriPath: computeUriPath(submenuLink.uriPath, appConfig.entryPointUriPath)
731
+ });
732
+ })
733
+ };
734
+ }
735
+
677
736
  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; }
678
737
 
679
738
  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; }
@@ -703,19 +762,19 @@ var processConfig = function processConfig() {
703
762
  applicationPath = _ref$applicationPath === void 0 ? fs.realpathSync(process.cwd()) : _ref$applicationPath;
704
763
 
705
764
  if (cachedConfig && !disableCache) return cachedConfig;
765
+ var rawConfig = loadConfig(applicationPath);
766
+ validateConfig(rawConfig);
767
+ var appConfig = substituteVariablePlaceholders(rawConfig, {
768
+ applicationPath: applicationPath,
769
+ processEnv: processEnv
770
+ });
771
+ var customApplicationData = transformCustomApplicationConfigToData(appConfig);
706
772
  var 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';
707
773
  var isProd = getIsProd(processEnv);
708
- var loadedAppConfig = loadConfig(applicationPath);
709
- validateConfig(loadedAppConfig);
710
- var validatedLoadedAppConfig = loadedAppConfig;
711
- var appConfig = substituteVariablePlaceholders(validatedLoadedAppConfig, {
712
- processEnv: processEnv,
713
- applicationPath: applicationPath
714
- });
715
774
  var additionalAppEnv = (_appConfig$additional = appConfig.additionalEnv) !== null && _appConfig$additional !== void 0 ? _appConfig$additional : {};
716
775
  var revision = (_ref3 = additionalAppEnv.revision) !== null && _ref3 !== void 0 ? _ref3 : ''; // Parse all the supported URLs, which gets implicitly validated
717
776
 
718
- var envAppUrl = isProd ? appConfig.env.production.url : developmentAppUrl;
777
+ var envAppUrl = isProd ? customApplicationData.url : developmentAppUrl;
719
778
  var appUrl = getOrThrow(function () {
720
779
  return new _URL(envAppUrl);
721
780
  }, "Invalid application URL: \"".concat(envAppUrl, "\"")); // Use `||` instead of `??` to include empty string values.
@@ -732,30 +791,31 @@ var processConfig = function processConfig() {
732
791
  // This is important to determine to which URL the MC should redirect to
733
792
  // after successful login.
734
793
 
735
- var applicationId = isProd ? _concatInstanceProperty(_context = "".concat(appConfig.env.production.applicationId, ":")).call(_context, appConfig.entryPointUriPath) : "__local:".concat(appConfig.entryPointUriPath);
794
+ var applicationId = isProd ? _concatInstanceProperty(_context = "".concat(customApplicationData.id, ":")).call(_context, customApplicationData.entryPointUriPath) : "__local:".concat(customApplicationData.entryPointUriPath);
736
795
  var developmentConfig = isProd ? undefined : omitDevConfigIfEmpty({
737
796
  oidc: omitEmpty({
738
797
  authorizeUrl: [// In case the MC API url points to localhost, we need to point
739
798
  // to a local running dev login page to handle the workflow properly.
740
799
  mcApiUrl.hostname === 'localhost' ? mcApiUrl.origin.replace(mcApiUrl.port, String(developmentPort)) : mcApiUrl.origin.replace('mc-api', 'mc'), '/login/authorize'].join(''),
741
800
  initialProjectKey: // For the `account` application, we should unset the projectKey.
742
- appConfig.entryPointUriPath === 'account' ? undefined : appConfig.env.development.initialProjectKey,
801
+ customApplicationData.entryPointUriPath === 'account' ? undefined : appConfig.env.development.initialProjectKey,
743
802
  teamId: (_appConfig$env$develo = appConfig.env.development) === null || _appConfig$env$develo === void 0 ? void 0 : _appConfig$env$develo.teamId,
744
803
  oAuthScopes: appConfig.oAuthScopes
745
804
  }),
746
805
  menuLinks: _objectSpread(_objectSpread({
747
- icon: appConfig.icon
748
- }, appConfig.mainMenuLink), {}, {
749
- submenuLinks: appConfig.submenuLinks
806
+ icon: customApplicationData.icon
807
+ }, customApplicationData.mainMenuLink), {}, {
808
+ submenuLinks: customApplicationData.submenuLinks
750
809
  }),
751
810
  // @ts-expect-error: the `accountLinks` is not explicitly typed as it's only used by the account app.
752
811
  accountLinks: appConfig.accountLinks
753
812
  });
754
813
  cachedConfig = {
814
+ data: customApplicationData,
755
815
  env: _objectSpread(_objectSpread(_objectSpread({}, omitEmpty(additionalAppEnv)), {}, {
756
816
  applicationId: applicationId,
757
- applicationName: appConfig.name,
758
- entryPointUriPath: appConfig.entryPointUriPath
817
+ applicationName: customApplicationData.name,
818
+ entryPointUriPath: customApplicationData.entryPointUriPath
759
819
  }, isProd || !developmentConfig ? {} : {
760
820
  __DEVELOPMENT__: developmentConfig
761
821
  }), {}, {
@@ -778,4 +838,4 @@ var processConfig = function processConfig() {
778
838
  return cachedConfig;
779
839
  };
780
840
 
781
- export { MissingOrInvalidConfigError, processConfig };
841
+ export { MissingOrInvalidConfigError, getConfigPath, processConfig };
@@ -0,0 +1,8 @@
1
+ export declare const entryPointUriPathToResourceAccesses: (entryPointUriPath: string) => {
2
+ view: string;
3
+ manage: string;
4
+ };
5
+ export declare const entryPointUriPathToPermissionKeys: (entryPointUriPath: string) => {
6
+ View: string;
7
+ Manage: string;
8
+ };
@@ -1,3 +1,4 @@
1
1
  export { default as processConfig } from './process-config';
2
+ export { getConfigPath } from './load-config';
2
3
  export * from './errors';
3
4
  export * from './types';
@@ -1,3 +1,4 @@
1
1
  import type { JSONSchemaForCustomApplicationConfigurationFiles } from './schema';
2
+ export declare const getConfigPath: () => string;
2
3
  declare const loadConfig: (applicationPath: string) => JSONSchemaForCustomApplicationConfigurationFiles;
3
4
  export default loadConfig;
@@ -1,11 +1,6 @@
1
- /// <reference types="node" />
2
- import type { JSONSchemaForCustomApplicationConfigurationFiles } from './schema';
3
- import type { ApplicationRuntimeConfig } from './types';
4
- declare type ProcessConfigOptions = {
1
+ import type { ApplicationRuntimeConfig, LoadingConfigOptions } from './types';
2
+ declare type ProcessConfigOptions = Partial<LoadingConfigOptions> & {
5
3
  disableCache?: boolean;
6
- processEnv?: NodeJS.ProcessEnv;
7
- applicationPath?: string;
8
- configJson?: JSONSchemaForCustomApplicationConfigurationFiles | undefined;
9
4
  };
10
5
  declare const processConfig: ({ disableCache, processEnv, applicationPath, }?: ProcessConfigOptions) => ApplicationRuntimeConfig;
11
6
  export default processConfig;
@@ -0,0 +1 @@
1
+ export * from './formatters';
@@ -1,7 +1,3 @@
1
- /// <reference types="node" />
2
- declare type Meta = {
3
- processEnv: NodeJS.ProcessEnv;
4
- applicationPath: string;
5
- };
6
- declare const substituteVariablePlaceholders: <T>(config: T, meta: Meta) => T;
1
+ import type { LoadingConfigOptions } from './types';
2
+ declare const substituteVariablePlaceholders: <T>(config: T, loadingOptions: LoadingConfigOptions) => T;
7
3
  export default substituteVariablePlaceholders;
@@ -0,0 +1,4 @@
1
+ import type { JSONSchemaForCustomApplicationConfigurationFiles } from './schema';
2
+ import type { CustomApplicationData } from './types';
3
+ declare function transformCustomApplicationConfigToData(appConfig: JSONSchemaForCustomApplicationConfigurationFiles): CustomApplicationData;
4
+ export { transformCustomApplicationConfigToData };
@@ -1,9 +1,46 @@
1
+ /// <reference types="node" />
1
2
  import type { ApplicationWindow } from '@commercetools-frontend/constants';
2
3
  import type { JSONSchemaForCustomApplicationConfigurationFiles } from './schema';
3
4
  import { CLOUD_IDENTIFIERS } from './constants';
4
5
  export declare type ConfigOptions = JSONSchemaForCustomApplicationConfigurationFiles;
5
6
  export declare type CloudIdentifier = typeof CLOUD_IDENTIFIERS[keyof typeof CLOUD_IDENTIFIERS];
7
+ declare type LocalizedFieldData = {
8
+ locale: string;
9
+ value: string;
10
+ };
11
+ declare type CustomApplicationPermissionData = {
12
+ name: string;
13
+ oAuthScopes: string[];
14
+ };
15
+ declare type CustomApplicationMenuLinkData = {
16
+ defaultLabel: string;
17
+ labelAllLocales: LocalizedFieldData[];
18
+ permissions: string[];
19
+ };
20
+ declare type CustomApplicationSubmenuLinkData = {
21
+ uriPath: string;
22
+ defaultLabel: string;
23
+ labelAllLocales: LocalizedFieldData[];
24
+ permissions: string[];
25
+ };
26
+ export declare type CustomApplicationData = {
27
+ id: string;
28
+ entryPointUriPath: string;
29
+ name: string;
30
+ description?: string;
31
+ url: string;
32
+ icon: string;
33
+ permissions: CustomApplicationPermissionData[];
34
+ mainMenuLink: CustomApplicationMenuLinkData;
35
+ submenuLinks: CustomApplicationSubmenuLinkData[];
36
+ };
6
37
  export declare type ApplicationRuntimeConfig = {
38
+ data: CustomApplicationData;
7
39
  env: ApplicationWindow['app'];
8
40
  headers: JSONSchemaForCustomApplicationConfigurationFiles['headers'];
9
41
  };
42
+ export declare type LoadingConfigOptions = {
43
+ processEnv: NodeJS.ProcessEnv;
44
+ applicationPath: string;
45
+ };
46
+ export {};
@@ -0,0 +1,56 @@
1
+ 'use strict';
2
+
3
+ var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
4
+ var upperFirst = require('lodash/upperFirst');
5
+
6
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
7
+
8
+ var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
9
+ var upperFirst__default = /*#__PURE__*/_interopDefault(upperFirst);
10
+
11
+ // removing special characters except underscore.
12
+ // It makes the first character of the string and the next character after a special character an uppercase.
13
+ // It replaces hyphen(-) with a forward slash(/) if the hyphen(-) is followed by a number.
14
+ // Examples:
15
+ // input: foo-bar result: FooBar
16
+ // input: foo_bar result: Foo_Bar
17
+ // input: foo-1bar result: Foo/1bar
18
+
19
+ var formatEntryPointUriPathToResourceAccessKey = function formatEntryPointUriPathToResourceAccessKey(entryPointUriPath) {
20
+ var _context, _context2;
21
+
22
+ return _mapInstanceProperty__default["default"](_context = _mapInstanceProperty__default["default"](_context2 = entryPointUriPath //Splits the string by underscore.
23
+ .split('_') // Uppercase the first character of each word split.
24
+ ).call(_context2, function (word) {
25
+ return upperFirst__default["default"](word);
26
+ }) // Join the words by an underscore.
27
+ .join('_') // Each word is split by a hyphen.
28
+ .split('-')).call(_context, function (word, i) {
29
+ // Regex below checking if the character is numeric.
30
+ // If the word after the hyphen is numeric, replace the hyphen with a forward slash.
31
+ // If not, omit the hyphen and uppercase the first character
32
+ if (i > 0 && /^-?\d+$/.test(word[0])) {
33
+ return '/' + word;
34
+ }
35
+
36
+ return upperFirst__default["default"](word);
37
+ }).join('');
38
+ };
39
+
40
+ var entryPointUriPathToResourceAccesses = function entryPointUriPathToResourceAccesses(entryPointUriPath) {
41
+ var convertedEntryPointUriPath = formatEntryPointUriPathToResourceAccessKey(entryPointUriPath);
42
+ return {
43
+ view: "view".concat(convertedEntryPointUriPath),
44
+ manage: "manage".concat(convertedEntryPointUriPath)
45
+ };
46
+ };
47
+ var entryPointUriPathToPermissionKeys = function entryPointUriPathToPermissionKeys(entryPointUriPath) {
48
+ var resourceAccesses = entryPointUriPathToResourceAccesses(entryPointUriPath);
49
+ return {
50
+ View: upperFirst__default["default"](resourceAccesses.view),
51
+ Manage: upperFirst__default["default"](resourceAccesses.manage)
52
+ };
53
+ };
54
+
55
+ exports.entryPointUriPathToPermissionKeys = entryPointUriPathToPermissionKeys;
56
+ exports.entryPointUriPathToResourceAccesses = entryPointUriPathToResourceAccesses;
@@ -0,0 +1,56 @@
1
+ 'use strict';
2
+
3
+ var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
4
+ var upperFirst = require('lodash/upperFirst');
5
+
6
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
7
+
8
+ var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
9
+ var upperFirst__default = /*#__PURE__*/_interopDefault(upperFirst);
10
+
11
+ // removing special characters except underscore.
12
+ // It makes the first character of the string and the next character after a special character an uppercase.
13
+ // It replaces hyphen(-) with a forward slash(/) if the hyphen(-) is followed by a number.
14
+ // Examples:
15
+ // input: foo-bar result: FooBar
16
+ // input: foo_bar result: Foo_Bar
17
+ // input: foo-1bar result: Foo/1bar
18
+
19
+ var formatEntryPointUriPathToResourceAccessKey = function formatEntryPointUriPathToResourceAccessKey(entryPointUriPath) {
20
+ var _context, _context2;
21
+
22
+ return _mapInstanceProperty__default["default"](_context = _mapInstanceProperty__default["default"](_context2 = entryPointUriPath //Splits the string by underscore.
23
+ .split('_') // Uppercase the first character of each word split.
24
+ ).call(_context2, function (word) {
25
+ return upperFirst__default["default"](word);
26
+ }) // Join the words by an underscore.
27
+ .join('_') // Each word is split by a hyphen.
28
+ .split('-')).call(_context, function (word, i) {
29
+ // Regex below checking if the character is numeric.
30
+ // If the word after the hyphen is numeric, replace the hyphen with a forward slash.
31
+ // If not, omit the hyphen and uppercase the first character
32
+ if (i > 0 && /^-?\d+$/.test(word[0])) {
33
+ return '/' + word;
34
+ }
35
+
36
+ return upperFirst__default["default"](word);
37
+ }).join('');
38
+ };
39
+
40
+ var entryPointUriPathToResourceAccesses = function entryPointUriPathToResourceAccesses(entryPointUriPath) {
41
+ var convertedEntryPointUriPath = formatEntryPointUriPathToResourceAccessKey(entryPointUriPath);
42
+ return {
43
+ view: "view".concat(convertedEntryPointUriPath),
44
+ manage: "manage".concat(convertedEntryPointUriPath)
45
+ };
46
+ };
47
+ var entryPointUriPathToPermissionKeys = function entryPointUriPathToPermissionKeys(entryPointUriPath) {
48
+ var resourceAccesses = entryPointUriPathToResourceAccesses(entryPointUriPath);
49
+ return {
50
+ View: upperFirst__default["default"](resourceAccesses.view),
51
+ Manage: upperFirst__default["default"](resourceAccesses.manage)
52
+ };
53
+ };
54
+
55
+ exports.entryPointUriPathToPermissionKeys = entryPointUriPathToPermissionKeys;
56
+ exports.entryPointUriPathToResourceAccesses = entryPointUriPathToResourceAccesses;
@@ -0,0 +1,48 @@
1
+ import _mapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/map';
2
+ import upperFirst from 'lodash/upperFirst';
3
+
4
+ // removing special characters except underscore.
5
+ // It makes the first character of the string and the next character after a special character an uppercase.
6
+ // It replaces hyphen(-) with a forward slash(/) if the hyphen(-) is followed by a number.
7
+ // Examples:
8
+ // input: foo-bar result: FooBar
9
+ // input: foo_bar result: Foo_Bar
10
+ // input: foo-1bar result: Foo/1bar
11
+
12
+ var formatEntryPointUriPathToResourceAccessKey = function formatEntryPointUriPathToResourceAccessKey(entryPointUriPath) {
13
+ var _context, _context2;
14
+
15
+ return _mapInstanceProperty(_context = _mapInstanceProperty(_context2 = entryPointUriPath //Splits the string by underscore.
16
+ .split('_') // Uppercase the first character of each word split.
17
+ ).call(_context2, function (word) {
18
+ return upperFirst(word);
19
+ }) // Join the words by an underscore.
20
+ .join('_') // Each word is split by a hyphen.
21
+ .split('-')).call(_context, function (word, i) {
22
+ // Regex below checking if the character is numeric.
23
+ // If the word after the hyphen is numeric, replace the hyphen with a forward slash.
24
+ // If not, omit the hyphen and uppercase the first character
25
+ if (i > 0 && /^-?\d+$/.test(word[0])) {
26
+ return '/' + word;
27
+ }
28
+
29
+ return upperFirst(word);
30
+ }).join('');
31
+ };
32
+
33
+ var entryPointUriPathToResourceAccesses = function entryPointUriPathToResourceAccesses(entryPointUriPath) {
34
+ var convertedEntryPointUriPath = formatEntryPointUriPathToResourceAccessKey(entryPointUriPath);
35
+ return {
36
+ view: "view".concat(convertedEntryPointUriPath),
37
+ manage: "manage".concat(convertedEntryPointUriPath)
38
+ };
39
+ };
40
+ var entryPointUriPathToPermissionKeys = function entryPointUriPathToPermissionKeys(entryPointUriPath) {
41
+ var resourceAccesses = entryPointUriPathToResourceAccesses(entryPointUriPath);
42
+ return {
43
+ View: upperFirst(resourceAccesses.view),
44
+ Manage: upperFirst(resourceAccesses.manage)
45
+ };
46
+ };
47
+
48
+ export { entryPointUriPathToPermissionKeys as a, entryPointUriPathToResourceAccesses as e };