@commercetools-frontend/application-config 21.20.5 → 21.21.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.
- package/dist/commercetools-frontend-application-config.cjs.dev.js +121 -20
- package/dist/commercetools-frontend-application-config.cjs.prod.js +121 -20
- package/dist/commercetools-frontend-application-config.esm.js +119 -21
- package/dist/declarations/src/constants.d.ts +1 -0
- package/dist/declarations/src/formatters.d.ts +3 -1
- package/dist/declarations/src/schema.d.ts +5 -3
- package/dist/declarations/src/validations.d.ts +1 -0
- package/dist/{formatters-3cfe4466.cjs.dev.js → formatters-88de943a.cjs.prod.js} +2 -0
- package/dist/{formatters-0d13ed2a.esm.js → formatters-cf2cd8ed.esm.js} +1 -1
- package/dist/{formatters-80d55e3e.cjs.prod.js → formatters-d2c7b577.cjs.dev.js} +2 -0
- package/package.json +2 -2
- package/schema.json +37 -4
- package/ssr/dist/commercetools-frontend-application-config-ssr.cjs.dev.js +3 -1
- package/ssr/dist/commercetools-frontend-application-config-ssr.cjs.prod.js +3 -1
- package/ssr/dist/commercetools-frontend-application-config-ssr.esm.js +1 -1
|
@@ -28,6 +28,7 @@ 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
30
|
var _Set = require('@babel/runtime-corejs3/core-js-stable/set');
|
|
31
|
+
var _Array$isArray = require('@babel/runtime-corejs3/core-js-stable/array/is-array');
|
|
31
32
|
var Ajv = require('ajv');
|
|
32
33
|
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
33
34
|
var _trimInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/trim');
|
|
@@ -37,10 +38,10 @@ var _Object$values = require('@babel/runtime-corejs3/core-js-stable/object/value
|
|
|
37
38
|
var _includesInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/includes');
|
|
38
39
|
var uniq = require('lodash/uniq');
|
|
39
40
|
var _startsWithInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/starts-with');
|
|
40
|
-
var
|
|
41
|
+
var _reduceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
|
|
42
|
+
var formatters = require('./formatters-d2c7b577.cjs.dev.js');
|
|
41
43
|
var createDOMPurify = require('dompurify');
|
|
42
44
|
var jsdom$1 = require('jsdom');
|
|
43
|
-
require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
|
|
44
45
|
require('@babel/runtime-corejs3/core-js-stable/object/entries');
|
|
45
46
|
require('lodash/upperFirst');
|
|
46
47
|
|
|
@@ -62,6 +63,7 @@ var path__default = /*#__PURE__*/_interopDefault(path);
|
|
|
62
63
|
var _Reflect$construct__default = /*#__PURE__*/_interopDefault(_Reflect$construct);
|
|
63
64
|
var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
|
|
64
65
|
var _Set__default = /*#__PURE__*/_interopDefault(_Set);
|
|
66
|
+
var _Array$isArray__default = /*#__PURE__*/_interopDefault(_Array$isArray);
|
|
65
67
|
var Ajv__default = /*#__PURE__*/_interopDefault(Ajv);
|
|
66
68
|
var _trimInstanceProperty__default = /*#__PURE__*/_interopDefault(_trimInstanceProperty);
|
|
67
69
|
var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
|
|
@@ -69,6 +71,7 @@ var _Object$values__default = /*#__PURE__*/_interopDefault(_Object$values);
|
|
|
69
71
|
var _includesInstanceProperty__default = /*#__PURE__*/_interopDefault(_includesInstanceProperty);
|
|
70
72
|
var uniq__default = /*#__PURE__*/_interopDefault(uniq);
|
|
71
73
|
var _startsWithInstanceProperty__default = /*#__PURE__*/_interopDefault(_startsWithInstanceProperty);
|
|
74
|
+
var _reduceInstanceProperty__default = /*#__PURE__*/_interopDefault(_reduceInstanceProperty);
|
|
72
75
|
var createDOMPurify__default = /*#__PURE__*/_interopDefault(createDOMPurify);
|
|
73
76
|
|
|
74
77
|
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); }; }
|
|
@@ -225,6 +228,50 @@ var schemaJson = {
|
|
|
225
228
|
"manage"
|
|
226
229
|
]
|
|
227
230
|
},
|
|
231
|
+
additionalOAuthScopes: {
|
|
232
|
+
description: "See https://docs.commercetools.com/custom-applications/api-reference/application-config#additionaloauthscopes",
|
|
233
|
+
type: "array",
|
|
234
|
+
"default": [
|
|
235
|
+
],
|
|
236
|
+
uniqueItems: true,
|
|
237
|
+
items: {
|
|
238
|
+
type: "object",
|
|
239
|
+
properties: {
|
|
240
|
+
name: {
|
|
241
|
+
description: "See https://docs.commercetools.com/custom-applications/api-reference/application-config#additionaloauthscopesname",
|
|
242
|
+
type: "string"
|
|
243
|
+
},
|
|
244
|
+
view: {
|
|
245
|
+
description: "See https://docs.commercetools.com/custom-applications/api-reference/application-config#additionaloauthscopesview",
|
|
246
|
+
type: "array",
|
|
247
|
+
"default": [
|
|
248
|
+
],
|
|
249
|
+
items: {
|
|
250
|
+
type: "string",
|
|
251
|
+
pattern: "view_(.*)"
|
|
252
|
+
},
|
|
253
|
+
uniqueItems: true
|
|
254
|
+
},
|
|
255
|
+
manage: {
|
|
256
|
+
description: "See https://docs.commercetools.com/custom-applications/api-reference/application-config#additionaloauthscopesmanage",
|
|
257
|
+
type: "array",
|
|
258
|
+
"default": [
|
|
259
|
+
],
|
|
260
|
+
items: {
|
|
261
|
+
type: "string",
|
|
262
|
+
pattern: "manage_(.*)"
|
|
263
|
+
},
|
|
264
|
+
uniqueItems: true
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
additionalProperties: false,
|
|
268
|
+
required: [
|
|
269
|
+
"name",
|
|
270
|
+
"view",
|
|
271
|
+
"manage"
|
|
272
|
+
]
|
|
273
|
+
}
|
|
274
|
+
},
|
|
228
275
|
env: {
|
|
229
276
|
description: "See https://docs.commercetools.com/custom-applications/api-reference/application-config#env",
|
|
230
277
|
type: "object",
|
|
@@ -310,10 +357,6 @@ var schemaJson = {
|
|
|
310
357
|
"connect-src"
|
|
311
358
|
]
|
|
312
359
|
},
|
|
313
|
-
featurePolicies: {
|
|
314
|
-
description: "See https://docs.commercetools.com/custom-applications/api-reference/application-config#headersfeaturepolicies",
|
|
315
|
-
type: "object"
|
|
316
|
-
},
|
|
317
360
|
permissionsPolicies: {
|
|
318
361
|
description: "See https://docs.commercetools.com/custom-applications/api-reference/application-config#headerspermissionspolicies",
|
|
319
362
|
type: "object"
|
|
@@ -471,10 +514,15 @@ var schemaJson = {
|
|
|
471
514
|
};
|
|
472
515
|
|
|
473
516
|
/**
|
|
474
|
-
* The entryPointUriPath may be between 2 and 64 characters and only contain
|
|
517
|
+
* The entryPointUriPath may be between 2 and 64 characters and only contain alphabetic lowercase characters,
|
|
475
518
|
* non-consecutive underscores and hyphens. Leading and trailing underscore and hyphens are also not allowed.
|
|
476
519
|
*/
|
|
477
520
|
var ENTRY_POINT_URI_PATH_REGEX = /^[^-_#]([0-9a-z]|[-_](?![-_])){0,62}[^-_#]$/g;
|
|
521
|
+
/**
|
|
522
|
+
* The permission group name may be between 2 and 64 characters and only contain alphanumeric lowercase characters and non-consecutive hyphens. Leading and trailing hyphens are also not allowed.
|
|
523
|
+
*/
|
|
524
|
+
|
|
525
|
+
var PERMISSION_GROUP_NAME_REGEX = /^[^-#]([a-z]|[-](?![-])){0,62}[^-#]$/g;
|
|
478
526
|
var CLOUD_IDENTIFIERS = {
|
|
479
527
|
GCP_AU: 'gcp-au',
|
|
480
528
|
GCP_EU: 'gcp-eu',
|
|
@@ -528,7 +576,7 @@ var validateConfig = function validateConfig(config) {
|
|
|
528
576
|
};
|
|
529
577
|
var validateEntryPointUriPath = function validateEntryPointUriPath(config) {
|
|
530
578
|
if (!config.entryPointUriPath.match(ENTRY_POINT_URI_PATH_REGEX)) {
|
|
531
|
-
throw new Error('Invalid "entryPointUriPath". The value may be between 2 and 64 characters and only contain alphanumeric lowercase characters, non-consecutive underscores and hyphens. Leading and trailing
|
|
579
|
+
throw new Error('Invalid "entryPointUriPath". The value may be between 2 and 64 characters and only contain alphanumeric lowercase characters, non-consecutive underscores and hyphens. Leading and trailing underscores and hyphens are also not allowed.');
|
|
532
580
|
}
|
|
533
581
|
};
|
|
534
582
|
var validateSubmenuLinks = function validateSubmenuLinks(config) {
|
|
@@ -546,6 +594,28 @@ var validateSubmenuLinks = function validateSubmenuLinks(config) {
|
|
|
546
594
|
uriPathSet.add(uriPath);
|
|
547
595
|
});
|
|
548
596
|
};
|
|
597
|
+
var validateAdditionalOAuthScopes = function validateAdditionalOAuthScopes(config) {
|
|
598
|
+
var _config$additionalOAu;
|
|
599
|
+
|
|
600
|
+
var additionalPermissionNames = new _Set__default["default"]();
|
|
601
|
+
(_config$additionalOAu = config.additionalOAuthScopes) === null || _config$additionalOAu === void 0 ? void 0 : _forEachInstanceProperty__default["default"](_config$additionalOAu).call(_config$additionalOAu, function (_ref2) {
|
|
602
|
+
var name = _ref2.name,
|
|
603
|
+
view = _ref2.view,
|
|
604
|
+
manage = _ref2.manage;
|
|
605
|
+
|
|
606
|
+
if ((_Array$isArray__default["default"](view) && view.length === 0 || !view) && (_Array$isArray__default["default"](manage) && manage.length === 0 || !manage)) {
|
|
607
|
+
throw new Error("At least one OAuth Scope for permission group name \"".concat(name, "\" is required"));
|
|
608
|
+
} else if (additionalPermissionNames.has(name)) {
|
|
609
|
+
throw new Error("Duplicate additional permission group name \"".concat(name, "\". Every additional permission must have a unique name"));
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
if (!name.match(PERMISSION_GROUP_NAME_REGEX)) {
|
|
613
|
+
throw new Error("Additional permission group name \"".concat(name, "\" is invalid. The value may be between 2 and 64 characters and only contain alphabetic lowercase characters and non-consecutive hyphens. Leading and trailing hyphens are also not allowed"));
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
additionalPermissionNames.add(name);
|
|
617
|
+
});
|
|
618
|
+
};
|
|
549
619
|
|
|
550
620
|
/**
|
|
551
621
|
* NOTE:
|
|
@@ -724,7 +794,7 @@ var getOrThrow = function getOrThrow(fn, errorMessage) {
|
|
|
724
794
|
|
|
725
795
|
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; }
|
|
726
796
|
|
|
727
|
-
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var
|
|
797
|
+
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var _context6, _context7; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context6 = ownKeys$1(Object(source), !0)).call(_context6, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context7 = ownKeys$1(Object(source))).call(_context7, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
|
|
728
798
|
// to the `entryPointUriPath`. Computing the full path is done internally to keep
|
|
729
799
|
// the configuration simple.
|
|
730
800
|
|
|
@@ -742,28 +812,57 @@ var computeUriPath = function computeUriPath(uriPath, entryPointUriPath) {
|
|
|
742
812
|
return _concatInstanceProperty__default["default"](_context = "".concat(entryPointUriPath, "/")).call(_context, uriPath);
|
|
743
813
|
};
|
|
744
814
|
|
|
815
|
+
var getPermissions = function getPermissions(appConfig) {
|
|
816
|
+
var _context2, _appConfig$additional, _context3, _context4;
|
|
817
|
+
|
|
818
|
+
var additionalResourceAccessKeyToOauthScopeMap = _reduceInstanceProperty__default["default"](_context2 = appConfig.additionalOAuthScopes || []).call(_context2, function (previousOauthScope, _ref) {
|
|
819
|
+
var _objectSpread2;
|
|
820
|
+
|
|
821
|
+
var name = _ref.name,
|
|
822
|
+
view = _ref.view,
|
|
823
|
+
manage = _ref.manage;
|
|
824
|
+
var formattedResourceKey = formatters.formatEntryPointUriPathToResourceAccessKey(name);
|
|
825
|
+
return _objectSpread$1(_objectSpread$1({}, previousOauthScope), {}, (_objectSpread2 = {}, _defineProperty(_objectSpread2, "view".concat(formattedResourceKey), view), _defineProperty(_objectSpread2, "manage".concat(formattedResourceKey), manage), _objectSpread2));
|
|
826
|
+
}, {});
|
|
827
|
+
|
|
828
|
+
var additionalPermissionNames = ((_appConfig$additional = appConfig.additionalOAuthScopes) === null || _appConfig$additional === void 0 ? void 0 : _mapInstanceProperty__default["default"](_appConfig$additional).call(_appConfig$additional, function (_ref2) {
|
|
829
|
+
var name = _ref2.name;
|
|
830
|
+
return name;
|
|
831
|
+
})) || [];
|
|
832
|
+
var permissionKeys = formatters.entryPointUriPathToResourceAccesses(appConfig.entryPointUriPath, additionalPermissionNames);
|
|
833
|
+
|
|
834
|
+
var additionalPermissions = _mapInstanceProperty__default["default"](_context3 = _Object$keys__default["default"](additionalResourceAccessKeyToOauthScopeMap)).call(_context3, function (additionalResourceAccessKey) {
|
|
835
|
+
return {
|
|
836
|
+
name: permissionKeys[additionalResourceAccessKey],
|
|
837
|
+
oAuthScopes: additionalResourceAccessKeyToOauthScopeMap[additionalResourceAccessKey]
|
|
838
|
+
};
|
|
839
|
+
});
|
|
840
|
+
|
|
841
|
+
return _concatInstanceProperty__default["default"](_context4 = [{
|
|
842
|
+
name: permissionKeys.view,
|
|
843
|
+
oAuthScopes: appConfig.oAuthScopes.view
|
|
844
|
+
}, {
|
|
845
|
+
name: permissionKeys.manage,
|
|
846
|
+
oAuthScopes: appConfig.oAuthScopes.manage
|
|
847
|
+
}]).call(_context4, _toConsumableArray(additionalPermissions));
|
|
848
|
+
};
|
|
849
|
+
|
|
745
850
|
function transformCustomApplicationConfigToData(appConfig) {
|
|
746
|
-
var
|
|
851
|
+
var _context5;
|
|
747
852
|
|
|
748
853
|
validateEntryPointUriPath(appConfig);
|
|
749
854
|
validateSubmenuLinks(appConfig);
|
|
750
|
-
|
|
855
|
+
validateAdditionalOAuthScopes(appConfig);
|
|
751
856
|
return {
|
|
752
857
|
id: appConfig.env.production.applicationId,
|
|
753
858
|
name: appConfig.name,
|
|
754
859
|
description: appConfig.description,
|
|
755
860
|
entryPointUriPath: appConfig.entryPointUriPath,
|
|
756
861
|
url: appConfig.env.production.url,
|
|
757
|
-
permissions:
|
|
758
|
-
name: permissionKeys.view,
|
|
759
|
-
oAuthScopes: appConfig.oAuthScopes.view
|
|
760
|
-
}, {
|
|
761
|
-
name: permissionKeys.manage,
|
|
762
|
-
oAuthScopes: appConfig.oAuthScopes.manage
|
|
763
|
-
}],
|
|
862
|
+
permissions: getPermissions(appConfig),
|
|
764
863
|
icon: appConfig.icon,
|
|
765
864
|
mainMenuLink: appConfig.mainMenuLink,
|
|
766
|
-
submenuLinks: _mapInstanceProperty__default["default"](
|
|
865
|
+
submenuLinks: _mapInstanceProperty__default["default"](_context5 = appConfig.submenuLinks).call(_context5, function (submenuLink) {
|
|
767
866
|
return _objectSpread$1(_objectSpread$1({}, submenuLink), {}, {
|
|
768
867
|
uriPath: computeUriPath(submenuLink.uriPath, appConfig.entryPointUriPath)
|
|
769
868
|
});
|
|
@@ -842,7 +941,8 @@ var processConfig = function processConfig() {
|
|
|
842
941
|
initialProjectKey: // For the `account` application, we should unset the projectKey.
|
|
843
942
|
customApplicationData.entryPointUriPath === 'account' ? undefined : appConfig.env.development.initialProjectKey,
|
|
844
943
|
teamId: (_appConfig$env$develo = appConfig.env.development) === null || _appConfig$env$develo === void 0 ? void 0 : _appConfig$env$develo.teamId,
|
|
845
|
-
oAuthScopes: appConfig.oAuthScopes
|
|
944
|
+
oAuthScopes: appConfig.oAuthScopes,
|
|
945
|
+
additionalOAuthScopes: appConfig === null || appConfig === void 0 ? void 0 : appConfig.additionalOAuthScopes
|
|
846
946
|
}),
|
|
847
947
|
menuLinks: _objectSpread(_objectSpread({
|
|
848
948
|
icon: customApplicationData.icon
|
|
@@ -904,6 +1004,7 @@ exports.CLOUD_IDENTIFIERS = CLOUD_IDENTIFIERS;
|
|
|
904
1004
|
exports.ENTRY_POINT_URI_PATH_REGEX = ENTRY_POINT_URI_PATH_REGEX;
|
|
905
1005
|
exports.MC_API_URLS = MC_API_URLS;
|
|
906
1006
|
exports.MissingOrInvalidConfigError = MissingOrInvalidConfigError;
|
|
1007
|
+
exports.PERMISSION_GROUP_NAME_REGEX = PERMISSION_GROUP_NAME_REGEX;
|
|
907
1008
|
exports.getConfigPath = getConfigPath;
|
|
908
1009
|
exports.processConfig = processConfig;
|
|
909
1010
|
exports.sanitizeSvg = sanitizeSvg;
|
|
@@ -28,6 +28,7 @@ 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
30
|
var _Set = require('@babel/runtime-corejs3/core-js-stable/set');
|
|
31
|
+
var _Array$isArray = require('@babel/runtime-corejs3/core-js-stable/array/is-array');
|
|
31
32
|
var Ajv = require('ajv');
|
|
32
33
|
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
33
34
|
var _trimInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/trim');
|
|
@@ -37,10 +38,10 @@ var _Object$values = require('@babel/runtime-corejs3/core-js-stable/object/value
|
|
|
37
38
|
var _includesInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/includes');
|
|
38
39
|
var uniq = require('lodash/uniq');
|
|
39
40
|
var _startsWithInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/starts-with');
|
|
40
|
-
var
|
|
41
|
+
var _reduceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
|
|
42
|
+
var formatters = require('./formatters-88de943a.cjs.prod.js');
|
|
41
43
|
var createDOMPurify = require('dompurify');
|
|
42
44
|
var jsdom$1 = require('jsdom');
|
|
43
|
-
require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
|
|
44
45
|
require('@babel/runtime-corejs3/core-js-stable/object/entries');
|
|
45
46
|
require('lodash/upperFirst');
|
|
46
47
|
|
|
@@ -62,6 +63,7 @@ var path__default = /*#__PURE__*/_interopDefault(path);
|
|
|
62
63
|
var _Reflect$construct__default = /*#__PURE__*/_interopDefault(_Reflect$construct);
|
|
63
64
|
var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
|
|
64
65
|
var _Set__default = /*#__PURE__*/_interopDefault(_Set);
|
|
66
|
+
var _Array$isArray__default = /*#__PURE__*/_interopDefault(_Array$isArray);
|
|
65
67
|
var Ajv__default = /*#__PURE__*/_interopDefault(Ajv);
|
|
66
68
|
var _trimInstanceProperty__default = /*#__PURE__*/_interopDefault(_trimInstanceProperty);
|
|
67
69
|
var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
|
|
@@ -69,6 +71,7 @@ var _Object$values__default = /*#__PURE__*/_interopDefault(_Object$values);
|
|
|
69
71
|
var _includesInstanceProperty__default = /*#__PURE__*/_interopDefault(_includesInstanceProperty);
|
|
70
72
|
var uniq__default = /*#__PURE__*/_interopDefault(uniq);
|
|
71
73
|
var _startsWithInstanceProperty__default = /*#__PURE__*/_interopDefault(_startsWithInstanceProperty);
|
|
74
|
+
var _reduceInstanceProperty__default = /*#__PURE__*/_interopDefault(_reduceInstanceProperty);
|
|
72
75
|
var createDOMPurify__default = /*#__PURE__*/_interopDefault(createDOMPurify);
|
|
73
76
|
|
|
74
77
|
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); }; }
|
|
@@ -225,6 +228,50 @@ var schemaJson = {
|
|
|
225
228
|
"manage"
|
|
226
229
|
]
|
|
227
230
|
},
|
|
231
|
+
additionalOAuthScopes: {
|
|
232
|
+
description: "See https://docs.commercetools.com/custom-applications/api-reference/application-config#additionaloauthscopes",
|
|
233
|
+
type: "array",
|
|
234
|
+
"default": [
|
|
235
|
+
],
|
|
236
|
+
uniqueItems: true,
|
|
237
|
+
items: {
|
|
238
|
+
type: "object",
|
|
239
|
+
properties: {
|
|
240
|
+
name: {
|
|
241
|
+
description: "See https://docs.commercetools.com/custom-applications/api-reference/application-config#additionaloauthscopesname",
|
|
242
|
+
type: "string"
|
|
243
|
+
},
|
|
244
|
+
view: {
|
|
245
|
+
description: "See https://docs.commercetools.com/custom-applications/api-reference/application-config#additionaloauthscopesview",
|
|
246
|
+
type: "array",
|
|
247
|
+
"default": [
|
|
248
|
+
],
|
|
249
|
+
items: {
|
|
250
|
+
type: "string",
|
|
251
|
+
pattern: "view_(.*)"
|
|
252
|
+
},
|
|
253
|
+
uniqueItems: true
|
|
254
|
+
},
|
|
255
|
+
manage: {
|
|
256
|
+
description: "See https://docs.commercetools.com/custom-applications/api-reference/application-config#additionaloauthscopesmanage",
|
|
257
|
+
type: "array",
|
|
258
|
+
"default": [
|
|
259
|
+
],
|
|
260
|
+
items: {
|
|
261
|
+
type: "string",
|
|
262
|
+
pattern: "manage_(.*)"
|
|
263
|
+
},
|
|
264
|
+
uniqueItems: true
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
additionalProperties: false,
|
|
268
|
+
required: [
|
|
269
|
+
"name",
|
|
270
|
+
"view",
|
|
271
|
+
"manage"
|
|
272
|
+
]
|
|
273
|
+
}
|
|
274
|
+
},
|
|
228
275
|
env: {
|
|
229
276
|
description: "See https://docs.commercetools.com/custom-applications/api-reference/application-config#env",
|
|
230
277
|
type: "object",
|
|
@@ -310,10 +357,6 @@ var schemaJson = {
|
|
|
310
357
|
"connect-src"
|
|
311
358
|
]
|
|
312
359
|
},
|
|
313
|
-
featurePolicies: {
|
|
314
|
-
description: "See https://docs.commercetools.com/custom-applications/api-reference/application-config#headersfeaturepolicies",
|
|
315
|
-
type: "object"
|
|
316
|
-
},
|
|
317
360
|
permissionsPolicies: {
|
|
318
361
|
description: "See https://docs.commercetools.com/custom-applications/api-reference/application-config#headerspermissionspolicies",
|
|
319
362
|
type: "object"
|
|
@@ -471,10 +514,15 @@ var schemaJson = {
|
|
|
471
514
|
};
|
|
472
515
|
|
|
473
516
|
/**
|
|
474
|
-
* The entryPointUriPath may be between 2 and 64 characters and only contain
|
|
517
|
+
* The entryPointUriPath may be between 2 and 64 characters and only contain alphabetic lowercase characters,
|
|
475
518
|
* non-consecutive underscores and hyphens. Leading and trailing underscore and hyphens are also not allowed.
|
|
476
519
|
*/
|
|
477
520
|
var ENTRY_POINT_URI_PATH_REGEX = /^[^-_#]([0-9a-z]|[-_](?![-_])){0,62}[^-_#]$/g;
|
|
521
|
+
/**
|
|
522
|
+
* The permission group name may be between 2 and 64 characters and only contain alphanumeric lowercase characters and non-consecutive hyphens. Leading and trailing hyphens are also not allowed.
|
|
523
|
+
*/
|
|
524
|
+
|
|
525
|
+
var PERMISSION_GROUP_NAME_REGEX = /^[^-#]([a-z]|[-](?![-])){0,62}[^-#]$/g;
|
|
478
526
|
var CLOUD_IDENTIFIERS = {
|
|
479
527
|
GCP_AU: 'gcp-au',
|
|
480
528
|
GCP_EU: 'gcp-eu',
|
|
@@ -528,7 +576,7 @@ var validateConfig = function validateConfig(config) {
|
|
|
528
576
|
};
|
|
529
577
|
var validateEntryPointUriPath = function validateEntryPointUriPath(config) {
|
|
530
578
|
if (!config.entryPointUriPath.match(ENTRY_POINT_URI_PATH_REGEX)) {
|
|
531
|
-
throw new Error('Invalid "entryPointUriPath". The value may be between 2 and 64 characters and only contain alphanumeric lowercase characters, non-consecutive underscores and hyphens. Leading and trailing
|
|
579
|
+
throw new Error('Invalid "entryPointUriPath". The value may be between 2 and 64 characters and only contain alphanumeric lowercase characters, non-consecutive underscores and hyphens. Leading and trailing underscores and hyphens are also not allowed.');
|
|
532
580
|
}
|
|
533
581
|
};
|
|
534
582
|
var validateSubmenuLinks = function validateSubmenuLinks(config) {
|
|
@@ -546,6 +594,28 @@ var validateSubmenuLinks = function validateSubmenuLinks(config) {
|
|
|
546
594
|
uriPathSet.add(uriPath);
|
|
547
595
|
});
|
|
548
596
|
};
|
|
597
|
+
var validateAdditionalOAuthScopes = function validateAdditionalOAuthScopes(config) {
|
|
598
|
+
var _config$additionalOAu;
|
|
599
|
+
|
|
600
|
+
var additionalPermissionNames = new _Set__default["default"]();
|
|
601
|
+
(_config$additionalOAu = config.additionalOAuthScopes) === null || _config$additionalOAu === void 0 ? void 0 : _forEachInstanceProperty__default["default"](_config$additionalOAu).call(_config$additionalOAu, function (_ref2) {
|
|
602
|
+
var name = _ref2.name,
|
|
603
|
+
view = _ref2.view,
|
|
604
|
+
manage = _ref2.manage;
|
|
605
|
+
|
|
606
|
+
if ((_Array$isArray__default["default"](view) && view.length === 0 || !view) && (_Array$isArray__default["default"](manage) && manage.length === 0 || !manage)) {
|
|
607
|
+
throw new Error("At least one OAuth Scope for permission group name \"".concat(name, "\" is required"));
|
|
608
|
+
} else if (additionalPermissionNames.has(name)) {
|
|
609
|
+
throw new Error("Duplicate additional permission group name \"".concat(name, "\". Every additional permission must have a unique name"));
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
if (!name.match(PERMISSION_GROUP_NAME_REGEX)) {
|
|
613
|
+
throw new Error("Additional permission group name \"".concat(name, "\" is invalid. The value may be between 2 and 64 characters and only contain alphabetic lowercase characters and non-consecutive hyphens. Leading and trailing hyphens are also not allowed"));
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
additionalPermissionNames.add(name);
|
|
617
|
+
});
|
|
618
|
+
};
|
|
549
619
|
|
|
550
620
|
/**
|
|
551
621
|
* NOTE:
|
|
@@ -724,7 +794,7 @@ var getOrThrow = function getOrThrow(fn, errorMessage) {
|
|
|
724
794
|
|
|
725
795
|
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; }
|
|
726
796
|
|
|
727
|
-
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var
|
|
797
|
+
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var _context6, _context7; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context6 = ownKeys$1(Object(source), !0)).call(_context6, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context7 = ownKeys$1(Object(source))).call(_context7, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
|
|
728
798
|
// to the `entryPointUriPath`. Computing the full path is done internally to keep
|
|
729
799
|
// the configuration simple.
|
|
730
800
|
|
|
@@ -742,28 +812,57 @@ var computeUriPath = function computeUriPath(uriPath, entryPointUriPath) {
|
|
|
742
812
|
return _concatInstanceProperty__default["default"](_context = "".concat(entryPointUriPath, "/")).call(_context, uriPath);
|
|
743
813
|
};
|
|
744
814
|
|
|
815
|
+
var getPermissions = function getPermissions(appConfig) {
|
|
816
|
+
var _context2, _appConfig$additional, _context3, _context4;
|
|
817
|
+
|
|
818
|
+
var additionalResourceAccessKeyToOauthScopeMap = _reduceInstanceProperty__default["default"](_context2 = appConfig.additionalOAuthScopes || []).call(_context2, function (previousOauthScope, _ref) {
|
|
819
|
+
var _objectSpread2;
|
|
820
|
+
|
|
821
|
+
var name = _ref.name,
|
|
822
|
+
view = _ref.view,
|
|
823
|
+
manage = _ref.manage;
|
|
824
|
+
var formattedResourceKey = formatters.formatEntryPointUriPathToResourceAccessKey(name);
|
|
825
|
+
return _objectSpread$1(_objectSpread$1({}, previousOauthScope), {}, (_objectSpread2 = {}, _defineProperty(_objectSpread2, "view".concat(formattedResourceKey), view), _defineProperty(_objectSpread2, "manage".concat(formattedResourceKey), manage), _objectSpread2));
|
|
826
|
+
}, {});
|
|
827
|
+
|
|
828
|
+
var additionalPermissionNames = ((_appConfig$additional = appConfig.additionalOAuthScopes) === null || _appConfig$additional === void 0 ? void 0 : _mapInstanceProperty__default["default"](_appConfig$additional).call(_appConfig$additional, function (_ref2) {
|
|
829
|
+
var name = _ref2.name;
|
|
830
|
+
return name;
|
|
831
|
+
})) || [];
|
|
832
|
+
var permissionKeys = formatters.entryPointUriPathToResourceAccesses(appConfig.entryPointUriPath, additionalPermissionNames);
|
|
833
|
+
|
|
834
|
+
var additionalPermissions = _mapInstanceProperty__default["default"](_context3 = _Object$keys__default["default"](additionalResourceAccessKeyToOauthScopeMap)).call(_context3, function (additionalResourceAccessKey) {
|
|
835
|
+
return {
|
|
836
|
+
name: permissionKeys[additionalResourceAccessKey],
|
|
837
|
+
oAuthScopes: additionalResourceAccessKeyToOauthScopeMap[additionalResourceAccessKey]
|
|
838
|
+
};
|
|
839
|
+
});
|
|
840
|
+
|
|
841
|
+
return _concatInstanceProperty__default["default"](_context4 = [{
|
|
842
|
+
name: permissionKeys.view,
|
|
843
|
+
oAuthScopes: appConfig.oAuthScopes.view
|
|
844
|
+
}, {
|
|
845
|
+
name: permissionKeys.manage,
|
|
846
|
+
oAuthScopes: appConfig.oAuthScopes.manage
|
|
847
|
+
}]).call(_context4, _toConsumableArray(additionalPermissions));
|
|
848
|
+
};
|
|
849
|
+
|
|
745
850
|
function transformCustomApplicationConfigToData(appConfig) {
|
|
746
|
-
var
|
|
851
|
+
var _context5;
|
|
747
852
|
|
|
748
853
|
validateEntryPointUriPath(appConfig);
|
|
749
854
|
validateSubmenuLinks(appConfig);
|
|
750
|
-
|
|
855
|
+
validateAdditionalOAuthScopes(appConfig);
|
|
751
856
|
return {
|
|
752
857
|
id: appConfig.env.production.applicationId,
|
|
753
858
|
name: appConfig.name,
|
|
754
859
|
description: appConfig.description,
|
|
755
860
|
entryPointUriPath: appConfig.entryPointUriPath,
|
|
756
861
|
url: appConfig.env.production.url,
|
|
757
|
-
permissions:
|
|
758
|
-
name: permissionKeys.view,
|
|
759
|
-
oAuthScopes: appConfig.oAuthScopes.view
|
|
760
|
-
}, {
|
|
761
|
-
name: permissionKeys.manage,
|
|
762
|
-
oAuthScopes: appConfig.oAuthScopes.manage
|
|
763
|
-
}],
|
|
862
|
+
permissions: getPermissions(appConfig),
|
|
764
863
|
icon: appConfig.icon,
|
|
765
864
|
mainMenuLink: appConfig.mainMenuLink,
|
|
766
|
-
submenuLinks: _mapInstanceProperty__default["default"](
|
|
865
|
+
submenuLinks: _mapInstanceProperty__default["default"](_context5 = appConfig.submenuLinks).call(_context5, function (submenuLink) {
|
|
767
866
|
return _objectSpread$1(_objectSpread$1({}, submenuLink), {}, {
|
|
768
867
|
uriPath: computeUriPath(submenuLink.uriPath, appConfig.entryPointUriPath)
|
|
769
868
|
});
|
|
@@ -842,7 +941,8 @@ var processConfig = function processConfig() {
|
|
|
842
941
|
initialProjectKey: // For the `account` application, we should unset the projectKey.
|
|
843
942
|
customApplicationData.entryPointUriPath === 'account' ? undefined : appConfig.env.development.initialProjectKey,
|
|
844
943
|
teamId: (_appConfig$env$develo = appConfig.env.development) === null || _appConfig$env$develo === void 0 ? void 0 : _appConfig$env$develo.teamId,
|
|
845
|
-
oAuthScopes: appConfig.oAuthScopes
|
|
944
|
+
oAuthScopes: appConfig.oAuthScopes,
|
|
945
|
+
additionalOAuthScopes: appConfig === null || appConfig === void 0 ? void 0 : appConfig.additionalOAuthScopes
|
|
846
946
|
}),
|
|
847
947
|
menuLinks: _objectSpread(_objectSpread({
|
|
848
948
|
icon: customApplicationData.icon
|
|
@@ -904,6 +1004,7 @@ exports.CLOUD_IDENTIFIERS = CLOUD_IDENTIFIERS;
|
|
|
904
1004
|
exports.ENTRY_POINT_URI_PATH_REGEX = ENTRY_POINT_URI_PATH_REGEX;
|
|
905
1005
|
exports.MC_API_URLS = MC_API_URLS;
|
|
906
1006
|
exports.MissingOrInvalidConfigError = MissingOrInvalidConfigError;
|
|
1007
|
+
exports.PERMISSION_GROUP_NAME_REGEX = PERMISSION_GROUP_NAME_REGEX;
|
|
907
1008
|
exports.getConfigPath = getConfigPath;
|
|
908
1009
|
exports.processConfig = processConfig;
|
|
909
1010
|
exports.sanitizeSvg = sanitizeSvg;
|
|
@@ -24,6 +24,7 @@ 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 _Set from '@babel/runtime-corejs3/core-js-stable/set';
|
|
27
|
+
import _Array$isArray from '@babel/runtime-corejs3/core-js-stable/array/is-array';
|
|
27
28
|
import Ajv from 'ajv';
|
|
28
29
|
import _slicedToArray from '@babel/runtime-corejs3/helpers/esm/slicedToArray';
|
|
29
30
|
import _trimInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/trim';
|
|
@@ -33,10 +34,10 @@ import _Object$values from '@babel/runtime-corejs3/core-js-stable/object/values'
|
|
|
33
34
|
import _includesInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/includes';
|
|
34
35
|
import uniq from 'lodash/uniq';
|
|
35
36
|
import _startsWithInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/starts-with';
|
|
36
|
-
import
|
|
37
|
+
import _reduceInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/reduce';
|
|
38
|
+
import { f as formatEntryPointUriPathToResourceAccessKey, e as entryPointUriPathToResourceAccesses } from './formatters-cf2cd8ed.esm.js';
|
|
37
39
|
import createDOMPurify from 'dompurify';
|
|
38
40
|
import { JSDOM } from 'jsdom';
|
|
39
|
-
import '@babel/runtime-corejs3/core-js-stable/instance/reduce';
|
|
40
41
|
import '@babel/runtime-corejs3/core-js-stable/object/entries';
|
|
41
42
|
import 'lodash/upperFirst';
|
|
42
43
|
|
|
@@ -194,6 +195,50 @@ var schemaJson = {
|
|
|
194
195
|
"manage"
|
|
195
196
|
]
|
|
196
197
|
},
|
|
198
|
+
additionalOAuthScopes: {
|
|
199
|
+
description: "See https://docs.commercetools.com/custom-applications/api-reference/application-config#additionaloauthscopes",
|
|
200
|
+
type: "array",
|
|
201
|
+
"default": [
|
|
202
|
+
],
|
|
203
|
+
uniqueItems: true,
|
|
204
|
+
items: {
|
|
205
|
+
type: "object",
|
|
206
|
+
properties: {
|
|
207
|
+
name: {
|
|
208
|
+
description: "See https://docs.commercetools.com/custom-applications/api-reference/application-config#additionaloauthscopesname",
|
|
209
|
+
type: "string"
|
|
210
|
+
},
|
|
211
|
+
view: {
|
|
212
|
+
description: "See https://docs.commercetools.com/custom-applications/api-reference/application-config#additionaloauthscopesview",
|
|
213
|
+
type: "array",
|
|
214
|
+
"default": [
|
|
215
|
+
],
|
|
216
|
+
items: {
|
|
217
|
+
type: "string",
|
|
218
|
+
pattern: "view_(.*)"
|
|
219
|
+
},
|
|
220
|
+
uniqueItems: true
|
|
221
|
+
},
|
|
222
|
+
manage: {
|
|
223
|
+
description: "See https://docs.commercetools.com/custom-applications/api-reference/application-config#additionaloauthscopesmanage",
|
|
224
|
+
type: "array",
|
|
225
|
+
"default": [
|
|
226
|
+
],
|
|
227
|
+
items: {
|
|
228
|
+
type: "string",
|
|
229
|
+
pattern: "manage_(.*)"
|
|
230
|
+
},
|
|
231
|
+
uniqueItems: true
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
additionalProperties: false,
|
|
235
|
+
required: [
|
|
236
|
+
"name",
|
|
237
|
+
"view",
|
|
238
|
+
"manage"
|
|
239
|
+
]
|
|
240
|
+
}
|
|
241
|
+
},
|
|
197
242
|
env: {
|
|
198
243
|
description: "See https://docs.commercetools.com/custom-applications/api-reference/application-config#env",
|
|
199
244
|
type: "object",
|
|
@@ -279,10 +324,6 @@ var schemaJson = {
|
|
|
279
324
|
"connect-src"
|
|
280
325
|
]
|
|
281
326
|
},
|
|
282
|
-
featurePolicies: {
|
|
283
|
-
description: "See https://docs.commercetools.com/custom-applications/api-reference/application-config#headersfeaturepolicies",
|
|
284
|
-
type: "object"
|
|
285
|
-
},
|
|
286
327
|
permissionsPolicies: {
|
|
287
328
|
description: "See https://docs.commercetools.com/custom-applications/api-reference/application-config#headerspermissionspolicies",
|
|
288
329
|
type: "object"
|
|
@@ -440,10 +481,15 @@ var schemaJson = {
|
|
|
440
481
|
};
|
|
441
482
|
|
|
442
483
|
/**
|
|
443
|
-
* The entryPointUriPath may be between 2 and 64 characters and only contain
|
|
484
|
+
* The entryPointUriPath may be between 2 and 64 characters and only contain alphabetic lowercase characters,
|
|
444
485
|
* non-consecutive underscores and hyphens. Leading and trailing underscore and hyphens are also not allowed.
|
|
445
486
|
*/
|
|
446
487
|
var ENTRY_POINT_URI_PATH_REGEX = /^[^-_#]([0-9a-z]|[-_](?![-_])){0,62}[^-_#]$/g;
|
|
488
|
+
/**
|
|
489
|
+
* The permission group name may be between 2 and 64 characters and only contain alphanumeric lowercase characters and non-consecutive hyphens. Leading and trailing hyphens are also not allowed.
|
|
490
|
+
*/
|
|
491
|
+
|
|
492
|
+
var PERMISSION_GROUP_NAME_REGEX = /^[^-#]([a-z]|[-](?![-])){0,62}[^-#]$/g;
|
|
447
493
|
var CLOUD_IDENTIFIERS = {
|
|
448
494
|
GCP_AU: 'gcp-au',
|
|
449
495
|
GCP_EU: 'gcp-eu',
|
|
@@ -497,7 +543,7 @@ var validateConfig = function validateConfig(config) {
|
|
|
497
543
|
};
|
|
498
544
|
var validateEntryPointUriPath = function validateEntryPointUriPath(config) {
|
|
499
545
|
if (!config.entryPointUriPath.match(ENTRY_POINT_URI_PATH_REGEX)) {
|
|
500
|
-
throw new Error('Invalid "entryPointUriPath". The value may be between 2 and 64 characters and only contain alphanumeric lowercase characters, non-consecutive underscores and hyphens. Leading and trailing
|
|
546
|
+
throw new Error('Invalid "entryPointUriPath". The value may be between 2 and 64 characters and only contain alphanumeric lowercase characters, non-consecutive underscores and hyphens. Leading and trailing underscores and hyphens are also not allowed.');
|
|
501
547
|
}
|
|
502
548
|
};
|
|
503
549
|
var validateSubmenuLinks = function validateSubmenuLinks(config) {
|
|
@@ -515,6 +561,28 @@ var validateSubmenuLinks = function validateSubmenuLinks(config) {
|
|
|
515
561
|
uriPathSet.add(uriPath);
|
|
516
562
|
});
|
|
517
563
|
};
|
|
564
|
+
var validateAdditionalOAuthScopes = function validateAdditionalOAuthScopes(config) {
|
|
565
|
+
var _config$additionalOAu;
|
|
566
|
+
|
|
567
|
+
var additionalPermissionNames = new _Set();
|
|
568
|
+
(_config$additionalOAu = config.additionalOAuthScopes) === null || _config$additionalOAu === void 0 ? void 0 : _forEachInstanceProperty(_config$additionalOAu).call(_config$additionalOAu, function (_ref2) {
|
|
569
|
+
var name = _ref2.name,
|
|
570
|
+
view = _ref2.view,
|
|
571
|
+
manage = _ref2.manage;
|
|
572
|
+
|
|
573
|
+
if ((_Array$isArray(view) && view.length === 0 || !view) && (_Array$isArray(manage) && manage.length === 0 || !manage)) {
|
|
574
|
+
throw new Error("At least one OAuth Scope for permission group name \"".concat(name, "\" is required"));
|
|
575
|
+
} else if (additionalPermissionNames.has(name)) {
|
|
576
|
+
throw new Error("Duplicate additional permission group name \"".concat(name, "\". Every additional permission must have a unique name"));
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
if (!name.match(PERMISSION_GROUP_NAME_REGEX)) {
|
|
580
|
+
throw new Error("Additional permission group name \"".concat(name, "\" is invalid. The value may be between 2 and 64 characters and only contain alphabetic lowercase characters and non-consecutive hyphens. Leading and trailing hyphens are also not allowed"));
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
additionalPermissionNames.add(name);
|
|
584
|
+
});
|
|
585
|
+
};
|
|
518
586
|
|
|
519
587
|
/**
|
|
520
588
|
* NOTE:
|
|
@@ -693,7 +761,7 @@ var getOrThrow = function getOrThrow(fn, errorMessage) {
|
|
|
693
761
|
|
|
694
762
|
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; }
|
|
695
763
|
|
|
696
|
-
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var
|
|
764
|
+
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var _context6, _context7; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context6 = ownKeys$1(Object(source), !0)).call(_context6, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context7 = ownKeys$1(Object(source))).call(_context7, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
697
765
|
// to the `entryPointUriPath`. Computing the full path is done internally to keep
|
|
698
766
|
// the configuration simple.
|
|
699
767
|
|
|
@@ -711,28 +779,57 @@ var computeUriPath = function computeUriPath(uriPath, entryPointUriPath) {
|
|
|
711
779
|
return _concatInstanceProperty(_context = "".concat(entryPointUriPath, "/")).call(_context, uriPath);
|
|
712
780
|
};
|
|
713
781
|
|
|
782
|
+
var getPermissions = function getPermissions(appConfig) {
|
|
783
|
+
var _context2, _appConfig$additional, _context3, _context4;
|
|
784
|
+
|
|
785
|
+
var additionalResourceAccessKeyToOauthScopeMap = _reduceInstanceProperty(_context2 = appConfig.additionalOAuthScopes || []).call(_context2, function (previousOauthScope, _ref) {
|
|
786
|
+
var _objectSpread2;
|
|
787
|
+
|
|
788
|
+
var name = _ref.name,
|
|
789
|
+
view = _ref.view,
|
|
790
|
+
manage = _ref.manage;
|
|
791
|
+
var formattedResourceKey = formatEntryPointUriPathToResourceAccessKey(name);
|
|
792
|
+
return _objectSpread$1(_objectSpread$1({}, previousOauthScope), {}, (_objectSpread2 = {}, _defineProperty(_objectSpread2, "view".concat(formattedResourceKey), view), _defineProperty(_objectSpread2, "manage".concat(formattedResourceKey), manage), _objectSpread2));
|
|
793
|
+
}, {});
|
|
794
|
+
|
|
795
|
+
var additionalPermissionNames = ((_appConfig$additional = appConfig.additionalOAuthScopes) === null || _appConfig$additional === void 0 ? void 0 : _mapInstanceProperty(_appConfig$additional).call(_appConfig$additional, function (_ref2) {
|
|
796
|
+
var name = _ref2.name;
|
|
797
|
+
return name;
|
|
798
|
+
})) || [];
|
|
799
|
+
var permissionKeys = entryPointUriPathToResourceAccesses(appConfig.entryPointUriPath, additionalPermissionNames);
|
|
800
|
+
|
|
801
|
+
var additionalPermissions = _mapInstanceProperty(_context3 = _Object$keys(additionalResourceAccessKeyToOauthScopeMap)).call(_context3, function (additionalResourceAccessKey) {
|
|
802
|
+
return {
|
|
803
|
+
name: permissionKeys[additionalResourceAccessKey],
|
|
804
|
+
oAuthScopes: additionalResourceAccessKeyToOauthScopeMap[additionalResourceAccessKey]
|
|
805
|
+
};
|
|
806
|
+
});
|
|
807
|
+
|
|
808
|
+
return _concatInstanceProperty(_context4 = [{
|
|
809
|
+
name: permissionKeys.view,
|
|
810
|
+
oAuthScopes: appConfig.oAuthScopes.view
|
|
811
|
+
}, {
|
|
812
|
+
name: permissionKeys.manage,
|
|
813
|
+
oAuthScopes: appConfig.oAuthScopes.manage
|
|
814
|
+
}]).call(_context4, _toConsumableArray(additionalPermissions));
|
|
815
|
+
};
|
|
816
|
+
|
|
714
817
|
function transformCustomApplicationConfigToData(appConfig) {
|
|
715
|
-
var
|
|
818
|
+
var _context5;
|
|
716
819
|
|
|
717
820
|
validateEntryPointUriPath(appConfig);
|
|
718
821
|
validateSubmenuLinks(appConfig);
|
|
719
|
-
|
|
822
|
+
validateAdditionalOAuthScopes(appConfig);
|
|
720
823
|
return {
|
|
721
824
|
id: appConfig.env.production.applicationId,
|
|
722
825
|
name: appConfig.name,
|
|
723
826
|
description: appConfig.description,
|
|
724
827
|
entryPointUriPath: appConfig.entryPointUriPath,
|
|
725
828
|
url: appConfig.env.production.url,
|
|
726
|
-
permissions:
|
|
727
|
-
name: permissionKeys.view,
|
|
728
|
-
oAuthScopes: appConfig.oAuthScopes.view
|
|
729
|
-
}, {
|
|
730
|
-
name: permissionKeys.manage,
|
|
731
|
-
oAuthScopes: appConfig.oAuthScopes.manage
|
|
732
|
-
}],
|
|
829
|
+
permissions: getPermissions(appConfig),
|
|
733
830
|
icon: appConfig.icon,
|
|
734
831
|
mainMenuLink: appConfig.mainMenuLink,
|
|
735
|
-
submenuLinks: _mapInstanceProperty(
|
|
832
|
+
submenuLinks: _mapInstanceProperty(_context5 = appConfig.submenuLinks).call(_context5, function (submenuLink) {
|
|
736
833
|
return _objectSpread$1(_objectSpread$1({}, submenuLink), {}, {
|
|
737
834
|
uriPath: computeUriPath(submenuLink.uriPath, appConfig.entryPointUriPath)
|
|
738
835
|
});
|
|
@@ -811,7 +908,8 @@ var processConfig = function processConfig() {
|
|
|
811
908
|
initialProjectKey: // For the `account` application, we should unset the projectKey.
|
|
812
909
|
customApplicationData.entryPointUriPath === 'account' ? undefined : appConfig.env.development.initialProjectKey,
|
|
813
910
|
teamId: (_appConfig$env$develo = appConfig.env.development) === null || _appConfig$env$develo === void 0 ? void 0 : _appConfig$env$develo.teamId,
|
|
814
|
-
oAuthScopes: appConfig.oAuthScopes
|
|
911
|
+
oAuthScopes: appConfig.oAuthScopes,
|
|
912
|
+
additionalOAuthScopes: appConfig === null || appConfig === void 0 ? void 0 : appConfig.additionalOAuthScopes
|
|
815
913
|
}),
|
|
816
914
|
menuLinks: _objectSpread(_objectSpread({
|
|
817
915
|
icon: customApplicationData.icon
|
|
@@ -869,4 +967,4 @@ function sanitizeSvg(data) {
|
|
|
869
967
|
}).innerHTML;
|
|
870
968
|
}
|
|
871
969
|
|
|
872
|
-
export { CLOUD_IDENTIFIERS, ENTRY_POINT_URI_PATH_REGEX, MC_API_URLS, MissingOrInvalidConfigError, getConfigPath, processConfig, sanitizeSvg };
|
|
970
|
+
export { CLOUD_IDENTIFIERS, ENTRY_POINT_URI_PATH_REGEX, MC_API_URLS, MissingOrInvalidConfigError, PERMISSION_GROUP_NAME_REGEX, getConfigPath, processConfig, sanitizeSvg };
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { CamelCase } from './types';
|
|
2
2
|
declare type TImplicitCustomApplicationResourceAccesses<PermissionGroupName extends string = ''> = Record<`view` | `manage` | `view${Capitalize<CamelCase<PermissionGroupName>>}` | `manage${Capitalize<CamelCase<PermissionGroupName>>}`, string>;
|
|
3
3
|
declare type TImplicitCustomApplicationPermissionKeys<PermissionGroupName extends string = ''> = Record<`View` | `Manage` | `View${Capitalize<CamelCase<PermissionGroupName>>}` | `Manage${Capitalize<CamelCase<PermissionGroupName>>}`, string>;
|
|
4
|
+
declare const formatEntryPointUriPathToResourceAccessKey: (entryPointUriPath: string) => string;
|
|
5
|
+
declare const formatPermissionGroupNameToResourceAccessKey: (permissionGroupName: string) => string;
|
|
4
6
|
declare function entryPointUriPathToResourceAccesses(entryPointUriPath: string): TImplicitCustomApplicationResourceAccesses<''>;
|
|
5
7
|
declare function entryPointUriPathToResourceAccesses<PermissionGroupName extends string>(entryPointUriPath: string, permissionGroupNames: PermissionGroupName[]): TImplicitCustomApplicationResourceAccesses<PermissionGroupName>;
|
|
6
8
|
declare function entryPointUriPathToPermissionKeys(entryPointUriPath: string): TImplicitCustomApplicationPermissionKeys<''>;
|
|
7
9
|
declare function entryPointUriPathToPermissionKeys<PermissionGroupName extends string>(entryPointUriPath: string, permissionGroupNames: PermissionGroupName[]): TImplicitCustomApplicationPermissionKeys<PermissionGroupName>;
|
|
8
|
-
export { entryPointUriPathToResourceAccesses, entryPointUriPathToPermissionKeys, };
|
|
10
|
+
export { entryPointUriPathToResourceAccesses, entryPointUriPathToPermissionKeys, formatEntryPointUriPathToResourceAccessKey, formatPermissionGroupNameToResourceAccessKey, };
|
|
@@ -9,6 +9,11 @@ export interface JSONSchemaForCustomApplicationConfigurationFiles {
|
|
|
9
9
|
view: string[];
|
|
10
10
|
manage: string[];
|
|
11
11
|
};
|
|
12
|
+
additionalOAuthScopes?: {
|
|
13
|
+
name: string;
|
|
14
|
+
view: string[];
|
|
15
|
+
manage: string[];
|
|
16
|
+
}[];
|
|
12
17
|
env: {
|
|
13
18
|
development: {
|
|
14
19
|
initialProjectKey: string;
|
|
@@ -32,9 +37,6 @@ export interface JSONSchemaForCustomApplicationConfigurationFiles {
|
|
|
32
37
|
'style-src'?: CspDirective;
|
|
33
38
|
'frame-src'?: CspDirective;
|
|
34
39
|
};
|
|
35
|
-
featurePolicies?: {
|
|
36
|
-
[k: string]: unknown;
|
|
37
|
-
};
|
|
38
40
|
permissionsPolicies?: {
|
|
39
41
|
[k: string]: unknown;
|
|
40
42
|
};
|
|
@@ -2,3 +2,4 @@ import type { JSONSchemaForCustomApplicationConfigurationFiles } from './schema'
|
|
|
2
2
|
export declare const validateConfig: (config: JSONSchemaForCustomApplicationConfigurationFiles) => void;
|
|
3
3
|
export declare const validateEntryPointUriPath: (config: JSONSchemaForCustomApplicationConfigurationFiles) => void;
|
|
4
4
|
export declare const validateSubmenuLinks: (config: JSONSchemaForCustomApplicationConfigurationFiles) => void;
|
|
5
|
+
export declare const validateAdditionalOAuthScopes: (config: JSONSchemaForCustomApplicationConfigurationFiles) => void;
|
|
@@ -117,3 +117,5 @@ function entryPointUriPathToPermissionKeys(entryPointUriPath, permissionGroupNam
|
|
|
117
117
|
|
|
118
118
|
exports.entryPointUriPathToPermissionKeys = entryPointUriPathToPermissionKeys;
|
|
119
119
|
exports.entryPointUriPathToResourceAccesses = entryPointUriPathToResourceAccesses;
|
|
120
|
+
exports.formatEntryPointUriPathToResourceAccessKey = formatEntryPointUriPathToResourceAccessKey;
|
|
121
|
+
exports.formatPermissionGroupNameToResourceAccessKey = formatPermissionGroupNameToResourceAccessKey;
|
|
@@ -97,4 +97,4 @@ function entryPointUriPathToPermissionKeys(entryPointUriPath, permissionGroupNam
|
|
|
97
97
|
}, {});
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
export { entryPointUriPathToPermissionKeys as a, entryPointUriPathToResourceAccesses as e };
|
|
100
|
+
export { entryPointUriPathToPermissionKeys as a, formatPermissionGroupNameToResourceAccessKey as b, entryPointUriPathToResourceAccesses as e, formatEntryPointUriPathToResourceAccessKey as f };
|
|
@@ -117,3 +117,5 @@ function entryPointUriPathToPermissionKeys(entryPointUriPath, permissionGroupNam
|
|
|
117
117
|
|
|
118
118
|
exports.entryPointUriPathToPermissionKeys = entryPointUriPathToPermissionKeys;
|
|
119
119
|
exports.entryPointUriPathToResourceAccesses = entryPointUriPathToResourceAccesses;
|
|
120
|
+
exports.formatEntryPointUriPathToResourceAccessKey = formatEntryPointUriPathToResourceAccessKey;
|
|
121
|
+
exports.formatPermissionGroupNameToResourceAccessKey = formatPermissionGroupNameToResourceAccessKey;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools-frontend/application-config",
|
|
3
|
-
"version": "21.
|
|
3
|
+
"version": "21.21.1",
|
|
4
4
|
"description": "Configuration utilities for building Custom Applications",
|
|
5
5
|
"bugs": "https://github.com/commercetools/merchant-center-application-kit/issues",
|
|
6
6
|
"repository": {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"@babel/register": "^7.18.9",
|
|
38
38
|
"@babel/runtime": "^7.19.0",
|
|
39
39
|
"@babel/runtime-corejs3": "^7.19.0",
|
|
40
|
-
"@commercetools-frontend/babel-preset-mc-app": "
|
|
40
|
+
"@commercetools-frontend/babel-preset-mc-app": "workspace:*",
|
|
41
41
|
"ajv": "8.11.0",
|
|
42
42
|
"core-js": "^3.25.1",
|
|
43
43
|
"cosmiconfig": "7.0.1",
|
package/schema.json
CHANGED
|
@@ -61,6 +61,43 @@
|
|
|
61
61
|
"additionalProperties": false,
|
|
62
62
|
"required": ["view", "manage"]
|
|
63
63
|
},
|
|
64
|
+
"additionalOAuthScopes": {
|
|
65
|
+
"description": "See https://docs.commercetools.com/custom-applications/api-reference/application-config#additionaloauthscopes",
|
|
66
|
+
"type": "array",
|
|
67
|
+
"default": [],
|
|
68
|
+
"uniqueItems": true,
|
|
69
|
+
"items": {
|
|
70
|
+
"type": "object",
|
|
71
|
+
"properties": {
|
|
72
|
+
"name": {
|
|
73
|
+
"description": "See https://docs.commercetools.com/custom-applications/api-reference/application-config#additionaloauthscopesname",
|
|
74
|
+
"type": "string"
|
|
75
|
+
},
|
|
76
|
+
"view": {
|
|
77
|
+
"description": "See https://docs.commercetools.com/custom-applications/api-reference/application-config#additionaloauthscopesview",
|
|
78
|
+
"type": "array",
|
|
79
|
+
"default": [],
|
|
80
|
+
"items": {
|
|
81
|
+
"type": "string",
|
|
82
|
+
"pattern": "view_(.*)"
|
|
83
|
+
},
|
|
84
|
+
"uniqueItems": true
|
|
85
|
+
},
|
|
86
|
+
"manage": {
|
|
87
|
+
"description": "See https://docs.commercetools.com/custom-applications/api-reference/application-config#additionaloauthscopesmanage",
|
|
88
|
+
"type": "array",
|
|
89
|
+
"default": [],
|
|
90
|
+
"items": {
|
|
91
|
+
"type": "string",
|
|
92
|
+
"pattern": "manage_(.*)"
|
|
93
|
+
},
|
|
94
|
+
"uniqueItems": true
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
"additionalProperties": false,
|
|
98
|
+
"required": ["name", "view", "manage"]
|
|
99
|
+
}
|
|
100
|
+
},
|
|
64
101
|
"env": {
|
|
65
102
|
"description": "See https://docs.commercetools.com/custom-applications/api-reference/application-config#env",
|
|
66
103
|
"type": "object",
|
|
@@ -136,10 +173,6 @@
|
|
|
136
173
|
"additionalProperties": false,
|
|
137
174
|
"required": ["connect-src"]
|
|
138
175
|
},
|
|
139
|
-
"featurePolicies": {
|
|
140
|
-
"description": "See https://docs.commercetools.com/custom-applications/api-reference/application-config#headersfeaturepolicies",
|
|
141
|
-
"type": "object"
|
|
142
|
-
},
|
|
143
176
|
"permissionsPolicies": {
|
|
144
177
|
"description": "See https://docs.commercetools.com/custom-applications/api-reference/application-config#headerspermissionspolicies",
|
|
145
178
|
"type": "object"
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var formatters = require('../../dist/formatters-
|
|
5
|
+
var formatters = require('../../dist/formatters-d2c7b577.cjs.dev.js');
|
|
6
6
|
require('@babel/runtime-corejs3/core-js-stable/object/keys');
|
|
7
7
|
require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
|
|
8
8
|
require('@babel/runtime-corejs3/core-js-stable/instance/filter');
|
|
@@ -23,3 +23,5 @@ require('lodash/upperFirst');
|
|
|
23
23
|
|
|
24
24
|
exports.entryPointUriPathToPermissionKeys = formatters.entryPointUriPathToPermissionKeys;
|
|
25
25
|
exports.entryPointUriPathToResourceAccesses = formatters.entryPointUriPathToResourceAccesses;
|
|
26
|
+
exports.formatEntryPointUriPathToResourceAccessKey = formatters.formatEntryPointUriPathToResourceAccessKey;
|
|
27
|
+
exports.formatPermissionGroupNameToResourceAccessKey = formatters.formatPermissionGroupNameToResourceAccessKey;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var formatters = require('../../dist/formatters-
|
|
5
|
+
var formatters = require('../../dist/formatters-88de943a.cjs.prod.js');
|
|
6
6
|
require('@babel/runtime-corejs3/core-js-stable/object/keys');
|
|
7
7
|
require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
|
|
8
8
|
require('@babel/runtime-corejs3/core-js-stable/instance/filter');
|
|
@@ -23,3 +23,5 @@ require('lodash/upperFirst');
|
|
|
23
23
|
|
|
24
24
|
exports.entryPointUriPathToPermissionKeys = formatters.entryPointUriPathToPermissionKeys;
|
|
25
25
|
exports.entryPointUriPathToResourceAccesses = formatters.entryPointUriPathToResourceAccesses;
|
|
26
|
+
exports.formatEntryPointUriPathToResourceAccessKey = formatters.formatEntryPointUriPathToResourceAccessKey;
|
|
27
|
+
exports.formatPermissionGroupNameToResourceAccessKey = formatters.formatPermissionGroupNameToResourceAccessKey;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { a as entryPointUriPathToPermissionKeys, e as entryPointUriPathToResourceAccesses } from '../../dist/formatters-
|
|
1
|
+
export { a as entryPointUriPathToPermissionKeys, e as entryPointUriPathToResourceAccesses, f as formatEntryPointUriPathToResourceAccessKey, b as formatPermissionGroupNameToResourceAccessKey } from '../../dist/formatters-cf2cd8ed.esm.js';
|
|
2
2
|
import '@babel/runtime-corejs3/core-js-stable/object/keys';
|
|
3
3
|
import '@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols';
|
|
4
4
|
import '@babel/runtime-corejs3/core-js-stable/instance/filter';
|