@commercetools-frontend/application-config 21.1.2 → 21.3.2

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,15 @@ 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 { e as entryPointUriPathToResourceAccesses } from './formatters-62af6993.esm.js';
35
+ import 'lodash/upperFirst';
34
36
 
35
37
  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
38
 
@@ -98,6 +100,15 @@ var explorer = cosmiconfigSync(moduleName, {
98
100
  '.ts': loadJsModule
99
101
  }
100
102
  });
103
+ var getConfigPath = function getConfigPath() {
104
+ var configFile = explorer.search();
105
+
106
+ if (!configFile) {
107
+ throw new Error("Missing or invalid Custom Application configuration file.");
108
+ }
109
+
110
+ return configFile.filepath;
111
+ };
101
112
 
102
113
  var loadConfig = function loadConfig(applicationPath) {
103
114
  var configFile = explorer.search(applicationPath);
@@ -484,74 +495,6 @@ var validateConfig = function validateConfig(config) {
484
495
  }
485
496
  };
486
497
 
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
498
  /**
556
499
  * NOTE:
557
500
  * Allows variable placeholders. Supported types are:
@@ -585,12 +528,12 @@ var isFilePathVariablePlaceholder = function isFilePathVariablePlaceholder(value
585
528
  return Boolean(valueOfPlaceholder.match(filePathRefSyntax));
586
529
  };
587
530
 
588
- var substituteEnvVariablePlaceholder = function substituteEnvVariablePlaceholder(valueOfPlaceholder, matchedString, valueOfEnvConfig, meta) {
531
+ var substituteEnvVariablePlaceholder = function substituteEnvVariablePlaceholder(valueOfPlaceholder, matchedString, valueOfEnvConfig, loadingOptions) {
589
532
  var _valueOfPlaceholder$s = valueOfPlaceholder.split(':'),
590
533
  _valueOfPlaceholder$s2 = _slicedToArray(_valueOfPlaceholder$s, 2),
591
534
  requestedEnvVar = _valueOfPlaceholder$s2[1];
592
535
 
593
- var hasEnvField = meta.processEnv.hasOwnProperty(requestedEnvVar);
536
+ var hasEnvField = loadingOptions.processEnv.hasOwnProperty(requestedEnvVar);
594
537
 
595
538
  if (!hasEnvField) {
596
539
  var _context;
@@ -599,17 +542,17 @@ var substituteEnvVariablePlaceholder = function substituteEnvVariablePlaceholder
599
542
  }
600
543
 
601
544
  var escapedMatchedString = matchedString.replace(/[${}:]/g, '\\$&');
602
- return valueOfEnvConfig.replace(new RegExp("(".concat(escapedMatchedString, ")+"), 'g'), meta.processEnv[requestedEnvVar]);
545
+ return valueOfEnvConfig.replace(new RegExp("(".concat(escapedMatchedString, ")+"), 'g'), loadingOptions.processEnv[requestedEnvVar]);
603
546
  };
604
547
 
605
- var substituteIntlVariablePlaceholder = function substituteIntlVariablePlaceholder(valueOfPlaceholder, matchedString, valueOfEnvConfig, meta) {
548
+ var substituteIntlVariablePlaceholder = function substituteIntlVariablePlaceholder(valueOfPlaceholder, matchedString, valueOfEnvConfig, loadingOptions) {
606
549
  var _valueOfPlaceholder$s3 = valueOfPlaceholder.split(':'),
607
550
  _valueOfPlaceholder$s4 = _slicedToArray(_valueOfPlaceholder$s3, 3),
608
551
  locale = _valueOfPlaceholder$s4[1],
609
552
  requestedIntlMessageId = _valueOfPlaceholder$s4[2];
610
553
 
611
554
  var translationsFilePath = require.resolve("./i18n/data/".concat(locale, ".json"), {
612
- paths: ["".concat(meta.applicationPath, "/src"), meta.applicationPath]
555
+ paths: ["".concat(loadingOptions.applicationPath, "/src"), loadingOptions.applicationPath]
613
556
  });
614
557
 
615
558
  var translations = require(translationsFilePath);
@@ -626,14 +569,14 @@ var substituteIntlVariablePlaceholder = function substituteIntlVariablePlacehold
626
569
  return valueOfEnvConfig.replace(new RegExp("(".concat(escapedMatchedString, ")+"), 'g'), translations[requestedIntlMessageId]);
627
570
  };
628
571
 
629
- var substituteFilePathVariablePlaceholder = function substituteFilePathVariablePlaceholder(valueOfPlaceholder, matchedString, valueOfEnvConfig, meta) {
572
+ var substituteFilePathVariablePlaceholder = function substituteFilePathVariablePlaceholder(valueOfPlaceholder, matchedString, valueOfEnvConfig, loadingOptions) {
630
573
  var _valueOfPlaceholder$s5 = valueOfPlaceholder.split(':'),
631
574
  _valueOfPlaceholder$s6 = _slicedToArray(_valueOfPlaceholder$s5, 2),
632
575
  filePathOrModule = _valueOfPlaceholder$s6[1];
633
576
 
634
577
  var content = fs.readFileSync(require.resolve(filePathOrModule, {
635
578
  // Relative paths should be resolved from the application folder.
636
- paths: [meta.applicationPath]
579
+ paths: [loadingOptions.applicationPath]
637
580
  }), {
638
581
  encoding: 'utf-8'
639
582
  });
@@ -647,7 +590,7 @@ var getValueOfPlaceholder = function getValueOfPlaceholder(valueWithPlaceholder)
647
590
  }).replace(/\s/g, '');
648
591
  };
649
592
 
650
- var substituteVariablePlaceholders = function substituteVariablePlaceholders(config, meta) {
593
+ var substituteVariablePlaceholders = function substituteVariablePlaceholders(config, loadingOptions) {
651
594
  return JSON.parse(_JSON$stringify(config), function (_key, value) {
652
595
  // Only strings are allowed
653
596
  var substitutedValue = value;
@@ -660,11 +603,11 @@ var substituteVariablePlaceholders = function substituteVariablePlaceholders(con
660
603
  var valueOfPlaceholder = getValueOfPlaceholder(matchedString);
661
604
 
662
605
  if (isEnvVariablePlaceholder(valueOfPlaceholder)) {
663
- substitutedValue = substituteEnvVariablePlaceholder(valueOfPlaceholder, matchedString, substitutedValue, meta);
606
+ substitutedValue = substituteEnvVariablePlaceholder(valueOfPlaceholder, matchedString, substitutedValue, loadingOptions);
664
607
  } else if (isIntlVariablePlaceholder(valueOfPlaceholder)) {
665
- substitutedValue = substituteIntlVariablePlaceholder(valueOfPlaceholder, matchedString, substitutedValue, meta);
608
+ substitutedValue = substituteIntlVariablePlaceholder(valueOfPlaceholder, matchedString, substitutedValue, loadingOptions);
666
609
  } else if (isFilePathVariablePlaceholder(valueOfPlaceholder)) {
667
- substitutedValue = substituteFilePathVariablePlaceholder(valueOfPlaceholder, matchedString, substitutedValue, meta);
610
+ substitutedValue = substituteFilePathVariablePlaceholder(valueOfPlaceholder, matchedString, substitutedValue, loadingOptions);
668
611
  }
669
612
  });
670
613
  }
@@ -674,6 +617,95 @@ var substituteVariablePlaceholders = function substituteVariablePlaceholders(con
674
617
  });
675
618
  };
676
619
 
620
+ var CLOUD_IDENTIFIERS = {
621
+ GCP_AU: 'gcp-au',
622
+ GCP_EU: 'gcp-eu',
623
+ GCP_US: 'gcp-us',
624
+ AWS_FRA: 'aws-fra',
625
+ AWS_OHIO: 'aws-ohio'
626
+ };
627
+ var MC_API_URLS = {
628
+ GCP_AU: 'https://mc-api.australia-southeast1.gcp.commercetools.com',
629
+ GCP_EU: 'https://mc-api.europe-west1.gcp.commercetools.com',
630
+ GCP_US: 'https://mc-api.us-central1.gcp.commercetools.com',
631
+ AWS_FRA: 'https://mc-api.eu-central-1.aws.commercetools.com',
632
+ AWS_OHIO: 'https://mc-api.us-east-2.aws.commercetools.com'
633
+ };
634
+
635
+ var mapCloudIdentifierToApiUrl = function mapCloudIdentifierToApiUrl(key) {
636
+ var _context;
637
+
638
+ switch (key) {
639
+ case CLOUD_IDENTIFIERS.GCP_AU:
640
+ return MC_API_URLS.GCP_AU;
641
+
642
+ case CLOUD_IDENTIFIERS.GCP_EU:
643
+ return MC_API_URLS.GCP_EU;
644
+
645
+ case CLOUD_IDENTIFIERS.GCP_US:
646
+ return MC_API_URLS.GCP_US;
647
+
648
+ case CLOUD_IDENTIFIERS.AWS_FRA:
649
+ return MC_API_URLS.AWS_FRA;
650
+
651
+ case CLOUD_IDENTIFIERS.AWS_OHIO:
652
+ return MC_API_URLS.AWS_OHIO;
653
+
654
+ default:
655
+ // We would probably never get to this point, as the JSON schema validation
656
+ // kicks in before.
657
+ throw new Error(_concatInstanceProperty(_context = "Unknown cloud identifier \"".concat(key, "\". Supported values: ")).call(_context, _Object$values(CLOUD_IDENTIFIERS).toString()));
658
+ }
659
+ };
660
+
661
+ var getUniqueValues = function getUniqueValues() {
662
+ var _context2;
663
+
664
+ var initialValues = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
665
+ var additionalValues = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
666
+ return uniq(_concatInstanceProperty(_context2 = []).call(_context2, _toConsumableArray(initialValues), _toConsumableArray(additionalValues)));
667
+ };
668
+
669
+ var nonProductionEnvironment = ['development', 'test'];
670
+
671
+ var getIsProd = function getIsProd(env) {
672
+ return (// TL;DR: in case the `MC_APP_ENV` is defined, we consider that it's
673
+ // a production environment unless it's one of `development` or `test`.
674
+ // This allows to use for example the `staging` value, which from the
675
+ // application perspective is still considered a production environment.
676
+ env.MC_APP_ENV ? !_includesInstanceProperty(nonProductionEnvironment).call(nonProductionEnvironment, env.MC_APP_ENV) : env.NODE_ENV === 'production'
677
+ );
678
+ };
679
+
680
+ var getOrThrow = function getOrThrow(fn, errorMessage) {
681
+ try {
682
+ return fn();
683
+ } catch (error) {
684
+ throw new Error(errorMessage);
685
+ }
686
+ };
687
+
688
+ function transformCustomApplicationConfigToData(appConfig) {
689
+ var permissionKeys = entryPointUriPathToResourceAccesses(appConfig.entryPointUriPath);
690
+ return {
691
+ id: appConfig.env.production.applicationId,
692
+ name: appConfig.name,
693
+ description: appConfig.description,
694
+ entryPointUriPath: appConfig.entryPointUriPath,
695
+ url: appConfig.env.production.url,
696
+ permissions: [{
697
+ name: permissionKeys.view,
698
+ oAuthScopes: appConfig.oAuthScopes.view
699
+ }, {
700
+ name: permissionKeys.manage,
701
+ oAuthScopes: appConfig.oAuthScopes.manage
702
+ }],
703
+ icon: appConfig.icon,
704
+ mainMenuLink: appConfig.mainMenuLink,
705
+ submenuLinks: appConfig.submenuLinks
706
+ };
707
+ }
708
+
677
709
  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
710
 
679
711
  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 +735,19 @@ var processConfig = function processConfig() {
703
735
  applicationPath = _ref$applicationPath === void 0 ? fs.realpathSync(process.cwd()) : _ref$applicationPath;
704
736
 
705
737
  if (cachedConfig && !disableCache) return cachedConfig;
738
+ var rawConfig = loadConfig(applicationPath);
739
+ validateConfig(rawConfig);
740
+ var appConfig = substituteVariablePlaceholders(rawConfig, {
741
+ applicationPath: applicationPath,
742
+ processEnv: processEnv
743
+ });
744
+ var customApplicationData = transformCustomApplicationConfigToData(appConfig);
706
745
  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
746
  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
747
  var additionalAppEnv = (_appConfig$additional = appConfig.additionalEnv) !== null && _appConfig$additional !== void 0 ? _appConfig$additional : {};
716
748
  var revision = (_ref3 = additionalAppEnv.revision) !== null && _ref3 !== void 0 ? _ref3 : ''; // Parse all the supported URLs, which gets implicitly validated
717
749
 
718
- var envAppUrl = isProd ? appConfig.env.production.url : developmentAppUrl;
750
+ var envAppUrl = isProd ? customApplicationData.url : developmentAppUrl;
719
751
  var appUrl = getOrThrow(function () {
720
752
  return new _URL(envAppUrl);
721
753
  }, "Invalid application URL: \"".concat(envAppUrl, "\"")); // Use `||` instead of `??` to include empty string values.
@@ -732,30 +764,31 @@ var processConfig = function processConfig() {
732
764
  // This is important to determine to which URL the MC should redirect to
733
765
  // after successful login.
734
766
 
735
- var applicationId = isProd ? _concatInstanceProperty(_context = "".concat(appConfig.env.production.applicationId, ":")).call(_context, appConfig.entryPointUriPath) : "__local:".concat(appConfig.entryPointUriPath);
767
+ var applicationId = isProd ? _concatInstanceProperty(_context = "".concat(customApplicationData.id, ":")).call(_context, customApplicationData.entryPointUriPath) : "__local:".concat(customApplicationData.entryPointUriPath);
736
768
  var developmentConfig = isProd ? undefined : omitDevConfigIfEmpty({
737
769
  oidc: omitEmpty({
738
770
  authorizeUrl: [// In case the MC API url points to localhost, we need to point
739
771
  // to a local running dev login page to handle the workflow properly.
740
772
  mcApiUrl.hostname === 'localhost' ? mcApiUrl.origin.replace(mcApiUrl.port, String(developmentPort)) : mcApiUrl.origin.replace('mc-api', 'mc'), '/login/authorize'].join(''),
741
773
  initialProjectKey: // For the `account` application, we should unset the projectKey.
742
- appConfig.entryPointUriPath === 'account' ? undefined : appConfig.env.development.initialProjectKey,
774
+ customApplicationData.entryPointUriPath === 'account' ? undefined : appConfig.env.development.initialProjectKey,
743
775
  teamId: (_appConfig$env$develo = appConfig.env.development) === null || _appConfig$env$develo === void 0 ? void 0 : _appConfig$env$develo.teamId,
744
776
  oAuthScopes: appConfig.oAuthScopes
745
777
  }),
746
778
  menuLinks: _objectSpread(_objectSpread({
747
- icon: appConfig.icon
748
- }, appConfig.mainMenuLink), {}, {
749
- submenuLinks: appConfig.submenuLinks
779
+ icon: customApplicationData.icon
780
+ }, customApplicationData.mainMenuLink), {}, {
781
+ submenuLinks: customApplicationData.submenuLinks
750
782
  }),
751
783
  // @ts-expect-error: the `accountLinks` is not explicitly typed as it's only used by the account app.
752
784
  accountLinks: appConfig.accountLinks
753
785
  });
754
786
  cachedConfig = {
787
+ data: customApplicationData,
755
788
  env: _objectSpread(_objectSpread(_objectSpread({}, omitEmpty(additionalAppEnv)), {}, {
756
789
  applicationId: applicationId,
757
- applicationName: appConfig.name,
758
- entryPointUriPath: appConfig.entryPointUriPath
790
+ applicationName: customApplicationData.name,
791
+ entryPointUriPath: customApplicationData.entryPointUriPath
759
792
  }, isProd || !developmentConfig ? {} : {
760
793
  __DEVELOPMENT__: developmentConfig
761
794
  }), {}, {
@@ -778,4 +811,4 @@ var processConfig = function processConfig() {
778
811
  return cachedConfig;
779
812
  };
780
813
 
781
- export { MissingOrInvalidConfigError, processConfig };
814
+ 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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercetools-frontend/application-config",
3
- "version": "21.1.2",
3
+ "version": "21.3.2",
4
4
  "description": "Configuration utilities for building Custom Applications",
5
5
  "bugs": "https://github.com/commercetools/merchant-center-application-kit/issues",
6
6
  "repository": {
@@ -16,8 +16,12 @@
16
16
  },
17
17
  "main": "dist/commercetools-frontend-application-config.cjs.js",
18
18
  "module": "dist/commercetools-frontend-application-config.esm.js",
19
+ "preconstruct": {
20
+ "entrypoints": ["./index.ts", "./ssr.ts"]
21
+ },
19
22
  "files": [
20
23
  "dist",
24
+ "ssr",
21
25
  "scripts",
22
26
  "schema.json",
23
27
  "package.json",
@@ -28,12 +32,12 @@
28
32
  "build:schema": "json2ts schema.json src/schema.ts --style.singleQuote --bannerComment '/* eslint-disable prettier/prettier */\n// This file was automatically generated by json-schema-to-typescript.\n// DO NOT MODIFY IT BY HAND. Instead, modify the source schema.json file.'"
29
33
  },
30
34
  "dependencies": {
31
- "@babel/register": "^7.16.9",
32
- "@babel/runtime": "^7.16.7",
33
- "@babel/runtime-corejs3": "^7.16.8",
34
- "@commercetools-frontend/babel-preset-mc-app": "21.0.0",
35
- "ajv": "8.9.0",
36
- "core-js": "^3.20.3",
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",
39
+ "ajv": "8.11.0",
40
+ "core-js": "^3.21.1",
37
41
  "cosmiconfig": "7.0.1",
38
42
  "lodash": "4.17.21",
39
43
  "omit-empty-es": "1.1.3"