@commercetools-frontend/application-config 20.12.0 → 21.0.0-rc.1

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.
@@ -19,6 +19,7 @@ var path = require('path');
19
19
  var child_process = require('child_process');
20
20
  var cosmiconfig = require('cosmiconfig');
21
21
  var _Reflect$construct = require('@babel/runtime-corejs3/core-js-stable/reflect/construct');
22
+ var _createClass = require('@babel/runtime-corejs3/helpers/createClass');
22
23
  var _classCallCheck = require('@babel/runtime-corejs3/helpers/classCallCheck');
23
24
  var _assertThisInitialized = require('@babel/runtime-corejs3/helpers/assertThisInitialized');
24
25
  var _inherits = require('@babel/runtime-corejs3/helpers/inherits');
@@ -82,7 +83,7 @@ var MissingOrInvalidConfigError = /*#__PURE__*/function (_Error) {
82
83
  return _this;
83
84
  }
84
85
 
85
- return MissingOrInvalidConfigError;
86
+ return _createClass(MissingOrInvalidConfigError);
86
87
  }( /*#__PURE__*/_wrapNativeSuper(Error));
87
88
 
88
89
  // for instance in respect to both source files and dist files.
@@ -160,8 +161,9 @@ var schemaJson = {
160
161
  type: "string"
161
162
  },
162
163
  entryPointUriPath: {
163
- description: "The unique route path of the Custom Application. This is the identifier that the Merchant Center Proxy uses to match the HTTP request and to forward it to the Custom Application URL. This value also needs to be used in the application client side routes. The value must be the same as the `navbarMenu.uriPath` in the `menu.json` and the application route path when registering the Custom Application. For example, if the Custom Application should be served at the route `/:projectKey/avengers`, the `entryPointUriPath` must be set to `avengers` and the same for the application routes.",
164
- type: "string"
164
+ description: "The unique route path of the Custom Application. This is the identifier that the Merchant Center Proxy uses to match the HTTP request and to forward it to the Custom Application URL (https://docs.commercetools.com/custom-applications/api-reference/application-config).",
165
+ type: "string",
166
+ pattern: "^[^\\-_]([0-9a-z]|[\\-_](?![\\-_])){2,64}[^\\-_]$"
165
167
  },
166
168
  cloudIdentifier: {
167
169
  description: "The cloud identifier where the Custom Application is running. This value is used to derive the Merchant Center API URL. Alternatively you can use the `mcApiUrl` property.",
@@ -192,6 +194,8 @@ var schemaJson = {
192
194
  view: {
193
195
  description: "The list of view-only OAuth Scopes (https://docs.commercetools.com/api/scopes).",
194
196
  type: "array",
197
+ "default": [
198
+ ],
195
199
  items: {
196
200
  type: "string",
197
201
  pattern: "view_(.*)"
@@ -201,6 +205,8 @@ var schemaJson = {
201
205
  manage: {
202
206
  description: "The list of manage-only OAuth Scopes (https://docs.commercetools.com/api/scopes).",
203
207
  type: "array",
208
+ "default": [
209
+ ],
204
210
  items: {
205
211
  type: "string",
206
212
  pattern: "manage_(.*)"
@@ -231,7 +237,10 @@ var schemaJson = {
231
237
  type: "string"
232
238
  }
233
239
  },
234
- additionalProperties: false
240
+ additionalProperties: false,
241
+ required: [
242
+ "initialProjectKey"
243
+ ]
235
244
  },
236
245
  production: {
237
246
  description: "Configuration for production only",
@@ -252,12 +261,14 @@ var schemaJson = {
252
261
  },
253
262
  additionalProperties: false,
254
263
  required: [
264
+ "applicationId",
255
265
  "url"
256
266
  ]
257
267
  }
258
268
  },
259
269
  additionalProperties: false,
260
270
  required: [
271
+ "development",
261
272
  "production"
262
273
  ]
263
274
  },
@@ -317,19 +328,16 @@ var schemaJson = {
317
328
  uniqueItems: true
318
329
  }
319
330
  },
320
- additionalProperties: false,
321
- required: [
322
- "csp"
323
- ]
331
+ additionalProperties: false
324
332
  },
325
- menuLinks: {
326
- description: "Configuration for the menu links on the left-side navbar.",
333
+ icon: {
334
+ description: "The SVG icon that represents this application. Pass the raw SVG string or a path to an SVG file, for example a relative path `${path:./app.svg}`, or a path from a module `${path:@commercetools-frontend/assets/application-icons/rocket.svg}`.",
335
+ type: "string"
336
+ },
337
+ mainMenuLink: {
338
+ description: "Configuration for the main menu link on the left-side navbar.",
327
339
  type: "object",
328
340
  properties: {
329
- icon: {
330
- description: "The SVG icon that represents this application. Pass the raw SVG string or a path to an SVG file, for example a relative path `${path:./app.svg}`, or a path from a module `${path:@commercetools-frontend/assets/application-icons/04.Rocket.svg}`.",
331
- type: "string"
332
- },
333
341
  defaultLabel: {
334
342
  description: "A default label to be rendered if there is no matching localized label for the user locale.",
335
343
  type: "string"
@@ -366,89 +374,87 @@ var schemaJson = {
366
374
  }
367
375
  },
368
376
  permissions: {
369
- description: "Set the visibility of the menu link. Users must have at least one permission to see the Custom Application in the Merchant Center menu.",
377
+ description: "Set the visibility of the menu link. Permission values are derived from the `entryPointUriPath`. Users must have at least one permission to see the Custom Application in the Merchant Center menu.",
370
378
  type: "array",
371
379
  "default": [
372
380
  ],
373
381
  items: {
374
382
  type: "string"
375
383
  }
376
- },
377
- submenuLinks: {
378
- description: "Configuration for the submenu links on the left-side navbar.",
379
- "default": [
380
- ],
381
- type: "array",
382
- items: {
383
- type: "object",
384
- properties: {
385
- uriPath: {
386
- description: "Route path relative to the entry point URI path of the Custom Application.",
387
- type: "string"
388
- },
389
- defaultLabel: {
390
- description: "A default label to be rendered if there is no matching localized label for the user locale.",
391
- type: "string"
392
- },
393
- labelAllLocales: {
394
- description: "Localized label based on the application locales available from the user profile.",
395
- type: "array",
396
- "default": [
397
- ],
398
- items: {
399
- type: "object",
400
- properties: {
401
- locale: {
402
- type: "string",
403
- "enum": [
404
- "en",
405
- "de",
406
- "es",
407
- "fr-FR",
408
- "zh-CN",
409
- "ja"
410
- ]
411
- },
412
- value: {
413
- description: "A label for the specific locale or a reference to a translated message. For example `${intl:en:Menu.Avengers}` which looks for the message key `Menu.Avengers` in the `src/i18n/data/en.json`",
414
- type: "string"
415
- }
416
- },
417
- additionalProperties: false,
418
- required: [
419
- "locale",
420
- "value"
421
- ]
422
- }
423
- },
424
- permissions: {
425
- description: "Set the visibility of the menu link. Users must have at least one permission to see the Custom Application in the Merchant Center menu.",
426
- type: "array",
427
- "default": [
428
- ],
429
- items: {
430
- type: "string"
431
- }
432
- }
433
- },
434
- additionalProperties: true,
435
- required: [
436
- "uriPath",
437
- "defaultLabel",
438
- "labelAllLocales",
439
- "permissions"
440
- ]
441
- }
442
384
  }
443
385
  },
444
386
  additionalProperties: true,
445
387
  required: [
446
- "icon",
447
388
  "defaultLabel",
448
389
  "labelAllLocales",
449
- "permissions",
450
- "submenuLinks"
390
+ "permissions"
451
391
  ]
392
+ },
393
+ submenuLinks: {
394
+ description: "Configuration for the submenu links on the left-side navbar.",
395
+ "default": [
396
+ ],
397
+ type: "array",
398
+ items: {
399
+ type: "object",
400
+ properties: {
401
+ uriPath: {
402
+ description: "Route path relative to the entry point URI path of the Custom Application.",
403
+ type: "string"
404
+ },
405
+ defaultLabel: {
406
+ description: "A default label to be rendered if there is no matching localized label for the user locale.",
407
+ type: "string"
408
+ },
409
+ labelAllLocales: {
410
+ description: "Localized label based on the application locales available from the user profile.",
411
+ type: "array",
412
+ "default": [
413
+ ],
414
+ items: {
415
+ type: "object",
416
+ properties: {
417
+ locale: {
418
+ type: "string",
419
+ "enum": [
420
+ "en",
421
+ "de",
422
+ "es",
423
+ "fr-FR",
424
+ "zh-CN",
425
+ "ja"
426
+ ]
427
+ },
428
+ value: {
429
+ description: "A label for the specific locale or a reference to a translated message. For example `${intl:en:Menu.Avengers}` which looks for the message key `Menu.Avengers` in the `src/i18n/data/en.json`",
430
+ type: "string"
431
+ }
432
+ },
433
+ additionalProperties: false,
434
+ required: [
435
+ "locale",
436
+ "value"
437
+ ]
438
+ }
439
+ },
440
+ permissions: {
441
+ description: "Set the visibility of the menu link. Permission values are derived from the `entryPointUriPath`. Users must have at least one permission to see the Custom Application in the Merchant Center menu.",
442
+ type: "array",
443
+ "default": [
444
+ ],
445
+ items: {
446
+ type: "string"
447
+ }
448
+ }
449
+ },
450
+ additionalProperties: true,
451
+ required: [
452
+ "uriPath",
453
+ "defaultLabel",
454
+ "labelAllLocales",
455
+ "permissions"
456
+ ]
457
+ }
452
458
  }
453
459
  },
454
460
  additionalProperties: true,
@@ -456,7 +462,11 @@ var schemaJson = {
456
462
  "name",
457
463
  "entryPointUriPath",
458
464
  "cloudIdentifier",
459
- "env"
465
+ "env",
466
+ "oAuthScopes",
467
+ "icon",
468
+ "mainMenuLink",
469
+ "submenuLinks"
460
470
  ]
461
471
  };
462
472
 
@@ -570,7 +580,7 @@ var getOrThrow = function getOrThrow(fn, errorMessage) {
570
580
  * Allows variable placeholders. Supported types are:
571
581
  * - `env`: For example `${env:MC_API_URL}`.
572
582
  * - `intl`: For example `${intl:en:Menu.title}`.
573
- * - `path`: For example `${path:./app.svg}`, or `${path:@commercetools-frontend/assets/application-icons/04.Rocket.svg}`.
583
+ * - `path`: For example `${path:./app.svg}`, or `${path:@commercetools-frontend/assets/application-icons/rocket.svg}`.
574
584
  */
575
585
  var variableSyntax = /\${([ ~:\w.'",\-/()@]+?)}/g;
576
586
  var envRefSyntax = /^env:/g;
@@ -687,9 +697,9 @@ var substituteVariablePlaceholders = function substituteVariablePlaceholders(con
687
697
  });
688
698
  };
689
699
 
690
- function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); if (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; }
700
+ function ownKeys(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; }
691
701
 
692
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context3; _forEachInstanceProperty__default["default"](_context3 = ownKeys(Object(source), true)).call(_context3, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors__default["default"]) { _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)); } else { var _context4; _forEachInstanceProperty__default["default"](_context4 = ownKeys(Object(source))).call(_context4, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } } return target; }
702
+ function _objectSpread(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(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(Object(source))).call(_context4, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
693
703
  // TODO: make it configurable.
694
704
  var developmentPort = 3001;
695
705
  var developmentAppUrl = "http://localhost:".concat(developmentPort);
@@ -705,7 +715,7 @@ var omitDevConfigIfEmpty = function omitDevConfigIfEmpty(devConfig) {
705
715
  var cachedConfig;
706
716
 
707
717
  var processConfig = function processConfig() {
708
- var _ref2, _processEnv$MC_APP_EN, _appConfig$additional, _ref3, _appConfig$env$develo, _appConfig$env$develo2, _appConfig$headers, _appConfig$headers2, _context2, _appConfig$headers3, _appConfig$headers4;
718
+ var _ref2, _processEnv$MC_APP_EN, _appConfig$additional, _ref3, _context, _appConfig$env$develo, _appConfig$headers, _appConfig$headers2, _appConfig$headers2$c, _context2, _appConfig$headers3, _appConfig$headers3$c, _appConfig$headers4, _appConfig$headers4$c;
709
719
 
710
720
  var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
711
721
  _ref$disableCache = _ref.disableCache,
@@ -726,9 +736,7 @@ var processConfig = function processConfig() {
726
736
  applicationPath: applicationPath
727
737
  });
728
738
  var additionalAppEnv = (_appConfig$additional = appConfig.additionalEnv) !== null && _appConfig$additional !== void 0 ? _appConfig$additional : {};
729
- var revision = (_ref3 = additionalAppEnv.revision) !== null && _ref3 !== void 0 ? _ref3 : ''; // Feature flags
730
-
731
- var isOidcForDevelopmentEnabled = Boolean(JSON.parse(processEnv.ENABLE_OIDC_FOR_DEVELOPMENT || 'false')); // Parse all the supported URLs, which gets implicitly validated
739
+ var revision = (_ref3 = additionalAppEnv.revision) !== null && _ref3 !== void 0 ? _ref3 : ''; // Parse all the supported URLs, which gets implicitly validated
732
740
 
733
741
  var envAppUrl = isProd ? appConfig.env.production.url : developmentAppUrl;
734
742
  var appUrl = getOrThrow(function () {
@@ -747,37 +755,26 @@ var processConfig = function processConfig() {
747
755
  // This is important to determine to which URL the MC should redirect to
748
756
  // after successful login.
749
757
 
750
- var applicationId = isOidcForDevelopmentEnabled ? "__local:".concat(appConfig.entryPointUriPath) : undefined;
751
-
752
- if (isProd) {
753
- // TODO: decide if we do require the application ID or not.
754
- if (appConfig.env.production.applicationId) {
755
- var _context;
756
-
757
- applicationId = _concatInstanceProperty__default["default"](_context = "".concat(appConfig.env.production.applicationId, ":")).call(_context, appConfig.entryPointUriPath);
758
- } else {
759
- // As long as we don't require the application ID in production, we should
760
- // fall back to unset the value.
761
- applicationId = undefined;
762
- }
763
- }
764
-
758
+ var applicationId = isProd ? _concatInstanceProperty__default["default"](_context = "".concat(appConfig.env.production.applicationId, ":")).call(_context, appConfig.entryPointUriPath) : "__local:".concat(appConfig.entryPointUriPath);
765
759
  var developmentConfig = isProd ? undefined : omitDevConfigIfEmpty({
766
- oidc: isOidcForDevelopmentEnabled ? omitEmpty__default["default"]({
760
+ oidc: omitEmpty__default["default"]({
767
761
  authorizeUrl: [// In case the MC API url points to localhost, we need to point
768
762
  // to a local running dev login page to handle the workflow properly.
769
763
  mcApiUrl.hostname === 'localhost' ? mcApiUrl.origin.replace(mcApiUrl.port, String(developmentPort)) : mcApiUrl.origin.replace('mc-api', 'mc'), '/login/authorize'].join(''),
770
- initialProjectKey: (_appConfig$env$develo = appConfig.env.development) === null || _appConfig$env$develo === void 0 ? void 0 : _appConfig$env$develo.initialProjectKey,
771
- teamId: (_appConfig$env$develo2 = appConfig.env.development) === null || _appConfig$env$develo2 === void 0 ? void 0 : _appConfig$env$develo2.teamId,
764
+ initialProjectKey: appConfig.env.development.initialProjectKey,
765
+ teamId: (_appConfig$env$develo = appConfig.env.development) === null || _appConfig$env$develo === void 0 ? void 0 : _appConfig$env$develo.teamId,
772
766
  oAuthScopes: appConfig.oAuthScopes
773
- }) : undefined,
774
- menuLinks: appConfig.menuLinks,
767
+ }),
768
+ menuLinks: _objectSpread(_objectSpread({
769
+ icon: appConfig.icon
770
+ }, appConfig.mainMenuLink), {}, {
771
+ submenuLinks: appConfig.submenuLinks
772
+ }),
775
773
  // @ts-expect-error: the `accountLinks` is not explicitly typed as it's only used by the account app.
776
774
  accountLinks: appConfig.accountLinks
777
775
  });
778
776
  cachedConfig = {
779
777
  env: _objectSpread(_objectSpread(_objectSpread({}, omitEmpty__default["default"](additionalAppEnv)), {}, {
780
- // TODO: how else should we provide the app identifier?
781
778
  applicationId: applicationId,
782
779
  applicationName: appConfig.name,
783
780
  entryPointUriPath: appConfig.entryPointUriPath
@@ -794,9 +791,9 @@ var processConfig = function processConfig() {
794
791
  }),
795
792
  headers: _objectSpread(_objectSpread({}, appConfig.headers), {}, {
796
793
  csp: _objectSpread(_objectSpread({}, (_appConfig$headers = appConfig.headers) === null || _appConfig$headers === void 0 ? void 0 : _appConfig$headers.csp), {}, {
797
- 'connect-src': getUniqueValues((_appConfig$headers2 = appConfig.headers) === null || _appConfig$headers2 === void 0 ? void 0 : _appConfig$headers2.csp['connect-src'], _concatInstanceProperty__default["default"](_context2 = [mcApiUrl.origin]).call(_context2, isProd ? [appUrl.href] : [])),
798
- 'script-src': getUniqueValues((_appConfig$headers3 = appConfig.headers) === null || _appConfig$headers3 === void 0 ? void 0 : _appConfig$headers3.csp['script-src'], isProd ? [appUrl.href, cdnUrl.href] : []),
799
- 'style-src': getUniqueValues((_appConfig$headers4 = appConfig.headers) === null || _appConfig$headers4 === void 0 ? void 0 : _appConfig$headers4.csp['style-src'], isProd ? [appUrl.href, cdnUrl.href] : [])
794
+ 'connect-src': getUniqueValues((_appConfig$headers2 = appConfig.headers) === null || _appConfig$headers2 === void 0 ? void 0 : (_appConfig$headers2$c = _appConfig$headers2.csp) === null || _appConfig$headers2$c === void 0 ? void 0 : _appConfig$headers2$c['connect-src'], _concatInstanceProperty__default["default"](_context2 = [mcApiUrl.origin]).call(_context2, isProd ? [appUrl.href] : [])),
795
+ 'script-src': getUniqueValues((_appConfig$headers3 = appConfig.headers) === null || _appConfig$headers3 === void 0 ? void 0 : (_appConfig$headers3$c = _appConfig$headers3.csp) === null || _appConfig$headers3$c === void 0 ? void 0 : _appConfig$headers3$c['script-src'], isProd ? [appUrl.href, cdnUrl.href] : []),
796
+ 'style-src': getUniqueValues((_appConfig$headers4 = appConfig.headers) === null || _appConfig$headers4 === void 0 ? void 0 : (_appConfig$headers4$c = _appConfig$headers4.csp) === null || _appConfig$headers4$c === void 0 ? void 0 : _appConfig$headers4$c['style-src'], isProd ? [appUrl.href, cdnUrl.href] : [])
800
797
  })
801
798
  })
802
799
  };