@commercetools-frontend/application-config 21.20.5 → 21.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commercetools-frontend-application-config.cjs.dev.js +121 -16
- package/dist/commercetools-frontend-application-config.cjs.prod.js +121 -16
- package/dist/commercetools-frontend-application-config.esm.js +119 -17
- 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 -0
- 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 -0
- 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",
|
|
@@ -471,10 +518,15 @@ var schemaJson = {
|
|
|
471
518
|
};
|
|
472
519
|
|
|
473
520
|
/**
|
|
474
|
-
* The entryPointUriPath may be between 2 and 64 characters and only contain
|
|
521
|
+
* The entryPointUriPath may be between 2 and 64 characters and only contain alphabetic lowercase characters,
|
|
475
522
|
* non-consecutive underscores and hyphens. Leading and trailing underscore and hyphens are also not allowed.
|
|
476
523
|
*/
|
|
477
524
|
var ENTRY_POINT_URI_PATH_REGEX = /^[^-_#]([0-9a-z]|[-_](?![-_])){0,62}[^-_#]$/g;
|
|
525
|
+
/**
|
|
526
|
+
* 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.
|
|
527
|
+
*/
|
|
528
|
+
|
|
529
|
+
var PERMISSION_GROUP_NAME_REGEX = /^[^-#]([a-z]|[-](?![-])){0,62}[^-#]$/g;
|
|
478
530
|
var CLOUD_IDENTIFIERS = {
|
|
479
531
|
GCP_AU: 'gcp-au',
|
|
480
532
|
GCP_EU: 'gcp-eu',
|
|
@@ -528,7 +580,7 @@ var validateConfig = function validateConfig(config) {
|
|
|
528
580
|
};
|
|
529
581
|
var validateEntryPointUriPath = function validateEntryPointUriPath(config) {
|
|
530
582
|
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
|
|
583
|
+
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
584
|
}
|
|
533
585
|
};
|
|
534
586
|
var validateSubmenuLinks = function validateSubmenuLinks(config) {
|
|
@@ -546,6 +598,28 @@ var validateSubmenuLinks = function validateSubmenuLinks(config) {
|
|
|
546
598
|
uriPathSet.add(uriPath);
|
|
547
599
|
});
|
|
548
600
|
};
|
|
601
|
+
var validateAdditionalOAuthScopes = function validateAdditionalOAuthScopes(config) {
|
|
602
|
+
var _config$additionalOAu;
|
|
603
|
+
|
|
604
|
+
var additionalPermissionNames = new _Set__default["default"]();
|
|
605
|
+
(_config$additionalOAu = config.additionalOAuthScopes) === null || _config$additionalOAu === void 0 ? void 0 : _forEachInstanceProperty__default["default"](_config$additionalOAu).call(_config$additionalOAu, function (_ref2) {
|
|
606
|
+
var name = _ref2.name,
|
|
607
|
+
view = _ref2.view,
|
|
608
|
+
manage = _ref2.manage;
|
|
609
|
+
|
|
610
|
+
if ((_Array$isArray__default["default"](view) && view.length === 0 || !view) && (_Array$isArray__default["default"](manage) && manage.length === 0 || !manage)) {
|
|
611
|
+
throw new Error("At least one OAuth Scope for permission group name \"".concat(name, "\" is required"));
|
|
612
|
+
} else if (additionalPermissionNames.has(name)) {
|
|
613
|
+
throw new Error("Duplicate additional permission group name \"".concat(name, "\". Every additional permission must have a unique name"));
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
if (!name.match(PERMISSION_GROUP_NAME_REGEX)) {
|
|
617
|
+
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"));
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
additionalPermissionNames.add(name);
|
|
621
|
+
});
|
|
622
|
+
};
|
|
549
623
|
|
|
550
624
|
/**
|
|
551
625
|
* NOTE:
|
|
@@ -724,7 +798,7 @@ var getOrThrow = function getOrThrow(fn, errorMessage) {
|
|
|
724
798
|
|
|
725
799
|
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
800
|
|
|
727
|
-
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var
|
|
801
|
+
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
802
|
// to the `entryPointUriPath`. Computing the full path is done internally to keep
|
|
729
803
|
// the configuration simple.
|
|
730
804
|
|
|
@@ -742,28 +816,57 @@ var computeUriPath = function computeUriPath(uriPath, entryPointUriPath) {
|
|
|
742
816
|
return _concatInstanceProperty__default["default"](_context = "".concat(entryPointUriPath, "/")).call(_context, uriPath);
|
|
743
817
|
};
|
|
744
818
|
|
|
819
|
+
var getPermissions = function getPermissions(appConfig) {
|
|
820
|
+
var _context2, _appConfig$additional, _context3, _context4;
|
|
821
|
+
|
|
822
|
+
var additionalResourceAccessKeyToOauthScopeMap = _reduceInstanceProperty__default["default"](_context2 = appConfig.additionalOAuthScopes || []).call(_context2, function (previousOauthScope, _ref) {
|
|
823
|
+
var _objectSpread2;
|
|
824
|
+
|
|
825
|
+
var name = _ref.name,
|
|
826
|
+
view = _ref.view,
|
|
827
|
+
manage = _ref.manage;
|
|
828
|
+
var formattedResourceKey = formatters.formatEntryPointUriPathToResourceAccessKey(name);
|
|
829
|
+
return _objectSpread$1(_objectSpread$1({}, previousOauthScope), {}, (_objectSpread2 = {}, _defineProperty(_objectSpread2, "view".concat(formattedResourceKey), view), _defineProperty(_objectSpread2, "manage".concat(formattedResourceKey), manage), _objectSpread2));
|
|
830
|
+
}, {});
|
|
831
|
+
|
|
832
|
+
var additionalPermissionNames = ((_appConfig$additional = appConfig.additionalOAuthScopes) === null || _appConfig$additional === void 0 ? void 0 : _mapInstanceProperty__default["default"](_appConfig$additional).call(_appConfig$additional, function (_ref2) {
|
|
833
|
+
var name = _ref2.name;
|
|
834
|
+
return name;
|
|
835
|
+
})) || [];
|
|
836
|
+
var permissionKeys = formatters.entryPointUriPathToResourceAccesses(appConfig.entryPointUriPath, additionalPermissionNames);
|
|
837
|
+
|
|
838
|
+
var additionalPermissions = _mapInstanceProperty__default["default"](_context3 = _Object$keys__default["default"](additionalResourceAccessKeyToOauthScopeMap)).call(_context3, function (additionalResourceAccessKey) {
|
|
839
|
+
return {
|
|
840
|
+
name: permissionKeys[additionalResourceAccessKey],
|
|
841
|
+
oAuthScopes: additionalResourceAccessKeyToOauthScopeMap[additionalResourceAccessKey]
|
|
842
|
+
};
|
|
843
|
+
});
|
|
844
|
+
|
|
845
|
+
return _concatInstanceProperty__default["default"](_context4 = [{
|
|
846
|
+
name: permissionKeys.view,
|
|
847
|
+
oAuthScopes: appConfig.oAuthScopes.view
|
|
848
|
+
}, {
|
|
849
|
+
name: permissionKeys.manage,
|
|
850
|
+
oAuthScopes: appConfig.oAuthScopes.manage
|
|
851
|
+
}]).call(_context4, _toConsumableArray(additionalPermissions));
|
|
852
|
+
};
|
|
853
|
+
|
|
745
854
|
function transformCustomApplicationConfigToData(appConfig) {
|
|
746
|
-
var
|
|
855
|
+
var _context5;
|
|
747
856
|
|
|
748
857
|
validateEntryPointUriPath(appConfig);
|
|
749
858
|
validateSubmenuLinks(appConfig);
|
|
750
|
-
|
|
859
|
+
validateAdditionalOAuthScopes(appConfig);
|
|
751
860
|
return {
|
|
752
861
|
id: appConfig.env.production.applicationId,
|
|
753
862
|
name: appConfig.name,
|
|
754
863
|
description: appConfig.description,
|
|
755
864
|
entryPointUriPath: appConfig.entryPointUriPath,
|
|
756
865
|
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
|
-
}],
|
|
866
|
+
permissions: getPermissions(appConfig),
|
|
764
867
|
icon: appConfig.icon,
|
|
765
868
|
mainMenuLink: appConfig.mainMenuLink,
|
|
766
|
-
submenuLinks: _mapInstanceProperty__default["default"](
|
|
869
|
+
submenuLinks: _mapInstanceProperty__default["default"](_context5 = appConfig.submenuLinks).call(_context5, function (submenuLink) {
|
|
767
870
|
return _objectSpread$1(_objectSpread$1({}, submenuLink), {}, {
|
|
768
871
|
uriPath: computeUriPath(submenuLink.uriPath, appConfig.entryPointUriPath)
|
|
769
872
|
});
|
|
@@ -842,7 +945,8 @@ var processConfig = function processConfig() {
|
|
|
842
945
|
initialProjectKey: // For the `account` application, we should unset the projectKey.
|
|
843
946
|
customApplicationData.entryPointUriPath === 'account' ? undefined : appConfig.env.development.initialProjectKey,
|
|
844
947
|
teamId: (_appConfig$env$develo = appConfig.env.development) === null || _appConfig$env$develo === void 0 ? void 0 : _appConfig$env$develo.teamId,
|
|
845
|
-
oAuthScopes: appConfig.oAuthScopes
|
|
948
|
+
oAuthScopes: appConfig.oAuthScopes,
|
|
949
|
+
additionalOAuthScopes: appConfig === null || appConfig === void 0 ? void 0 : appConfig.additionalOAuthScopes
|
|
846
950
|
}),
|
|
847
951
|
menuLinks: _objectSpread(_objectSpread({
|
|
848
952
|
icon: customApplicationData.icon
|
|
@@ -904,6 +1008,7 @@ exports.CLOUD_IDENTIFIERS = CLOUD_IDENTIFIERS;
|
|
|
904
1008
|
exports.ENTRY_POINT_URI_PATH_REGEX = ENTRY_POINT_URI_PATH_REGEX;
|
|
905
1009
|
exports.MC_API_URLS = MC_API_URLS;
|
|
906
1010
|
exports.MissingOrInvalidConfigError = MissingOrInvalidConfigError;
|
|
1011
|
+
exports.PERMISSION_GROUP_NAME_REGEX = PERMISSION_GROUP_NAME_REGEX;
|
|
907
1012
|
exports.getConfigPath = getConfigPath;
|
|
908
1013
|
exports.processConfig = processConfig;
|
|
909
1014
|
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",
|
|
@@ -471,10 +518,15 @@ var schemaJson = {
|
|
|
471
518
|
};
|
|
472
519
|
|
|
473
520
|
/**
|
|
474
|
-
* The entryPointUriPath may be between 2 and 64 characters and only contain
|
|
521
|
+
* The entryPointUriPath may be between 2 and 64 characters and only contain alphabetic lowercase characters,
|
|
475
522
|
* non-consecutive underscores and hyphens. Leading and trailing underscore and hyphens are also not allowed.
|
|
476
523
|
*/
|
|
477
524
|
var ENTRY_POINT_URI_PATH_REGEX = /^[^-_#]([0-9a-z]|[-_](?![-_])){0,62}[^-_#]$/g;
|
|
525
|
+
/**
|
|
526
|
+
* 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.
|
|
527
|
+
*/
|
|
528
|
+
|
|
529
|
+
var PERMISSION_GROUP_NAME_REGEX = /^[^-#]([a-z]|[-](?![-])){0,62}[^-#]$/g;
|
|
478
530
|
var CLOUD_IDENTIFIERS = {
|
|
479
531
|
GCP_AU: 'gcp-au',
|
|
480
532
|
GCP_EU: 'gcp-eu',
|
|
@@ -528,7 +580,7 @@ var validateConfig = function validateConfig(config) {
|
|
|
528
580
|
};
|
|
529
581
|
var validateEntryPointUriPath = function validateEntryPointUriPath(config) {
|
|
530
582
|
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
|
|
583
|
+
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
584
|
}
|
|
533
585
|
};
|
|
534
586
|
var validateSubmenuLinks = function validateSubmenuLinks(config) {
|
|
@@ -546,6 +598,28 @@ var validateSubmenuLinks = function validateSubmenuLinks(config) {
|
|
|
546
598
|
uriPathSet.add(uriPath);
|
|
547
599
|
});
|
|
548
600
|
};
|
|
601
|
+
var validateAdditionalOAuthScopes = function validateAdditionalOAuthScopes(config) {
|
|
602
|
+
var _config$additionalOAu;
|
|
603
|
+
|
|
604
|
+
var additionalPermissionNames = new _Set__default["default"]();
|
|
605
|
+
(_config$additionalOAu = config.additionalOAuthScopes) === null || _config$additionalOAu === void 0 ? void 0 : _forEachInstanceProperty__default["default"](_config$additionalOAu).call(_config$additionalOAu, function (_ref2) {
|
|
606
|
+
var name = _ref2.name,
|
|
607
|
+
view = _ref2.view,
|
|
608
|
+
manage = _ref2.manage;
|
|
609
|
+
|
|
610
|
+
if ((_Array$isArray__default["default"](view) && view.length === 0 || !view) && (_Array$isArray__default["default"](manage) && manage.length === 0 || !manage)) {
|
|
611
|
+
throw new Error("At least one OAuth Scope for permission group name \"".concat(name, "\" is required"));
|
|
612
|
+
} else if (additionalPermissionNames.has(name)) {
|
|
613
|
+
throw new Error("Duplicate additional permission group name \"".concat(name, "\". Every additional permission must have a unique name"));
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
if (!name.match(PERMISSION_GROUP_NAME_REGEX)) {
|
|
617
|
+
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"));
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
additionalPermissionNames.add(name);
|
|
621
|
+
});
|
|
622
|
+
};
|
|
549
623
|
|
|
550
624
|
/**
|
|
551
625
|
* NOTE:
|
|
@@ -724,7 +798,7 @@ var getOrThrow = function getOrThrow(fn, errorMessage) {
|
|
|
724
798
|
|
|
725
799
|
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
800
|
|
|
727
|
-
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var
|
|
801
|
+
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
802
|
// to the `entryPointUriPath`. Computing the full path is done internally to keep
|
|
729
803
|
// the configuration simple.
|
|
730
804
|
|
|
@@ -742,28 +816,57 @@ var computeUriPath = function computeUriPath(uriPath, entryPointUriPath) {
|
|
|
742
816
|
return _concatInstanceProperty__default["default"](_context = "".concat(entryPointUriPath, "/")).call(_context, uriPath);
|
|
743
817
|
};
|
|
744
818
|
|
|
819
|
+
var getPermissions = function getPermissions(appConfig) {
|
|
820
|
+
var _context2, _appConfig$additional, _context3, _context4;
|
|
821
|
+
|
|
822
|
+
var additionalResourceAccessKeyToOauthScopeMap = _reduceInstanceProperty__default["default"](_context2 = appConfig.additionalOAuthScopes || []).call(_context2, function (previousOauthScope, _ref) {
|
|
823
|
+
var _objectSpread2;
|
|
824
|
+
|
|
825
|
+
var name = _ref.name,
|
|
826
|
+
view = _ref.view,
|
|
827
|
+
manage = _ref.manage;
|
|
828
|
+
var formattedResourceKey = formatters.formatEntryPointUriPathToResourceAccessKey(name);
|
|
829
|
+
return _objectSpread$1(_objectSpread$1({}, previousOauthScope), {}, (_objectSpread2 = {}, _defineProperty(_objectSpread2, "view".concat(formattedResourceKey), view), _defineProperty(_objectSpread2, "manage".concat(formattedResourceKey), manage), _objectSpread2));
|
|
830
|
+
}, {});
|
|
831
|
+
|
|
832
|
+
var additionalPermissionNames = ((_appConfig$additional = appConfig.additionalOAuthScopes) === null || _appConfig$additional === void 0 ? void 0 : _mapInstanceProperty__default["default"](_appConfig$additional).call(_appConfig$additional, function (_ref2) {
|
|
833
|
+
var name = _ref2.name;
|
|
834
|
+
return name;
|
|
835
|
+
})) || [];
|
|
836
|
+
var permissionKeys = formatters.entryPointUriPathToResourceAccesses(appConfig.entryPointUriPath, additionalPermissionNames);
|
|
837
|
+
|
|
838
|
+
var additionalPermissions = _mapInstanceProperty__default["default"](_context3 = _Object$keys__default["default"](additionalResourceAccessKeyToOauthScopeMap)).call(_context3, function (additionalResourceAccessKey) {
|
|
839
|
+
return {
|
|
840
|
+
name: permissionKeys[additionalResourceAccessKey],
|
|
841
|
+
oAuthScopes: additionalResourceAccessKeyToOauthScopeMap[additionalResourceAccessKey]
|
|
842
|
+
};
|
|
843
|
+
});
|
|
844
|
+
|
|
845
|
+
return _concatInstanceProperty__default["default"](_context4 = [{
|
|
846
|
+
name: permissionKeys.view,
|
|
847
|
+
oAuthScopes: appConfig.oAuthScopes.view
|
|
848
|
+
}, {
|
|
849
|
+
name: permissionKeys.manage,
|
|
850
|
+
oAuthScopes: appConfig.oAuthScopes.manage
|
|
851
|
+
}]).call(_context4, _toConsumableArray(additionalPermissions));
|
|
852
|
+
};
|
|
853
|
+
|
|
745
854
|
function transformCustomApplicationConfigToData(appConfig) {
|
|
746
|
-
var
|
|
855
|
+
var _context5;
|
|
747
856
|
|
|
748
857
|
validateEntryPointUriPath(appConfig);
|
|
749
858
|
validateSubmenuLinks(appConfig);
|
|
750
|
-
|
|
859
|
+
validateAdditionalOAuthScopes(appConfig);
|
|
751
860
|
return {
|
|
752
861
|
id: appConfig.env.production.applicationId,
|
|
753
862
|
name: appConfig.name,
|
|
754
863
|
description: appConfig.description,
|
|
755
864
|
entryPointUriPath: appConfig.entryPointUriPath,
|
|
756
865
|
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
|
-
}],
|
|
866
|
+
permissions: getPermissions(appConfig),
|
|
764
867
|
icon: appConfig.icon,
|
|
765
868
|
mainMenuLink: appConfig.mainMenuLink,
|
|
766
|
-
submenuLinks: _mapInstanceProperty__default["default"](
|
|
869
|
+
submenuLinks: _mapInstanceProperty__default["default"](_context5 = appConfig.submenuLinks).call(_context5, function (submenuLink) {
|
|
767
870
|
return _objectSpread$1(_objectSpread$1({}, submenuLink), {}, {
|
|
768
871
|
uriPath: computeUriPath(submenuLink.uriPath, appConfig.entryPointUriPath)
|
|
769
872
|
});
|
|
@@ -842,7 +945,8 @@ var processConfig = function processConfig() {
|
|
|
842
945
|
initialProjectKey: // For the `account` application, we should unset the projectKey.
|
|
843
946
|
customApplicationData.entryPointUriPath === 'account' ? undefined : appConfig.env.development.initialProjectKey,
|
|
844
947
|
teamId: (_appConfig$env$develo = appConfig.env.development) === null || _appConfig$env$develo === void 0 ? void 0 : _appConfig$env$develo.teamId,
|
|
845
|
-
oAuthScopes: appConfig.oAuthScopes
|
|
948
|
+
oAuthScopes: appConfig.oAuthScopes,
|
|
949
|
+
additionalOAuthScopes: appConfig === null || appConfig === void 0 ? void 0 : appConfig.additionalOAuthScopes
|
|
846
950
|
}),
|
|
847
951
|
menuLinks: _objectSpread(_objectSpread({
|
|
848
952
|
icon: customApplicationData.icon
|
|
@@ -904,6 +1008,7 @@ exports.CLOUD_IDENTIFIERS = CLOUD_IDENTIFIERS;
|
|
|
904
1008
|
exports.ENTRY_POINT_URI_PATH_REGEX = ENTRY_POINT_URI_PATH_REGEX;
|
|
905
1009
|
exports.MC_API_URLS = MC_API_URLS;
|
|
906
1010
|
exports.MissingOrInvalidConfigError = MissingOrInvalidConfigError;
|
|
1011
|
+
exports.PERMISSION_GROUP_NAME_REGEX = PERMISSION_GROUP_NAME_REGEX;
|
|
907
1012
|
exports.getConfigPath = getConfigPath;
|
|
908
1013
|
exports.processConfig = processConfig;
|
|
909
1014
|
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",
|
|
@@ -440,10 +485,15 @@ var schemaJson = {
|
|
|
440
485
|
};
|
|
441
486
|
|
|
442
487
|
/**
|
|
443
|
-
* The entryPointUriPath may be between 2 and 64 characters and only contain
|
|
488
|
+
* The entryPointUriPath may be between 2 and 64 characters and only contain alphabetic lowercase characters,
|
|
444
489
|
* non-consecutive underscores and hyphens. Leading and trailing underscore and hyphens are also not allowed.
|
|
445
490
|
*/
|
|
446
491
|
var ENTRY_POINT_URI_PATH_REGEX = /^[^-_#]([0-9a-z]|[-_](?![-_])){0,62}[^-_#]$/g;
|
|
492
|
+
/**
|
|
493
|
+
* 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.
|
|
494
|
+
*/
|
|
495
|
+
|
|
496
|
+
var PERMISSION_GROUP_NAME_REGEX = /^[^-#]([a-z]|[-](?![-])){0,62}[^-#]$/g;
|
|
447
497
|
var CLOUD_IDENTIFIERS = {
|
|
448
498
|
GCP_AU: 'gcp-au',
|
|
449
499
|
GCP_EU: 'gcp-eu',
|
|
@@ -497,7 +547,7 @@ var validateConfig = function validateConfig(config) {
|
|
|
497
547
|
};
|
|
498
548
|
var validateEntryPointUriPath = function validateEntryPointUriPath(config) {
|
|
499
549
|
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
|
|
550
|
+
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
551
|
}
|
|
502
552
|
};
|
|
503
553
|
var validateSubmenuLinks = function validateSubmenuLinks(config) {
|
|
@@ -515,6 +565,28 @@ var validateSubmenuLinks = function validateSubmenuLinks(config) {
|
|
|
515
565
|
uriPathSet.add(uriPath);
|
|
516
566
|
});
|
|
517
567
|
};
|
|
568
|
+
var validateAdditionalOAuthScopes = function validateAdditionalOAuthScopes(config) {
|
|
569
|
+
var _config$additionalOAu;
|
|
570
|
+
|
|
571
|
+
var additionalPermissionNames = new _Set();
|
|
572
|
+
(_config$additionalOAu = config.additionalOAuthScopes) === null || _config$additionalOAu === void 0 ? void 0 : _forEachInstanceProperty(_config$additionalOAu).call(_config$additionalOAu, function (_ref2) {
|
|
573
|
+
var name = _ref2.name,
|
|
574
|
+
view = _ref2.view,
|
|
575
|
+
manage = _ref2.manage;
|
|
576
|
+
|
|
577
|
+
if ((_Array$isArray(view) && view.length === 0 || !view) && (_Array$isArray(manage) && manage.length === 0 || !manage)) {
|
|
578
|
+
throw new Error("At least one OAuth Scope for permission group name \"".concat(name, "\" is required"));
|
|
579
|
+
} else if (additionalPermissionNames.has(name)) {
|
|
580
|
+
throw new Error("Duplicate additional permission group name \"".concat(name, "\". Every additional permission must have a unique name"));
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
if (!name.match(PERMISSION_GROUP_NAME_REGEX)) {
|
|
584
|
+
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"));
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
additionalPermissionNames.add(name);
|
|
588
|
+
});
|
|
589
|
+
};
|
|
518
590
|
|
|
519
591
|
/**
|
|
520
592
|
* NOTE:
|
|
@@ -693,7 +765,7 @@ var getOrThrow = function getOrThrow(fn, errorMessage) {
|
|
|
693
765
|
|
|
694
766
|
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
767
|
|
|
696
|
-
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var
|
|
768
|
+
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
769
|
// to the `entryPointUriPath`. Computing the full path is done internally to keep
|
|
698
770
|
// the configuration simple.
|
|
699
771
|
|
|
@@ -711,28 +783,57 @@ var computeUriPath = function computeUriPath(uriPath, entryPointUriPath) {
|
|
|
711
783
|
return _concatInstanceProperty(_context = "".concat(entryPointUriPath, "/")).call(_context, uriPath);
|
|
712
784
|
};
|
|
713
785
|
|
|
786
|
+
var getPermissions = function getPermissions(appConfig) {
|
|
787
|
+
var _context2, _appConfig$additional, _context3, _context4;
|
|
788
|
+
|
|
789
|
+
var additionalResourceAccessKeyToOauthScopeMap = _reduceInstanceProperty(_context2 = appConfig.additionalOAuthScopes || []).call(_context2, function (previousOauthScope, _ref) {
|
|
790
|
+
var _objectSpread2;
|
|
791
|
+
|
|
792
|
+
var name = _ref.name,
|
|
793
|
+
view = _ref.view,
|
|
794
|
+
manage = _ref.manage;
|
|
795
|
+
var formattedResourceKey = formatEntryPointUriPathToResourceAccessKey(name);
|
|
796
|
+
return _objectSpread$1(_objectSpread$1({}, previousOauthScope), {}, (_objectSpread2 = {}, _defineProperty(_objectSpread2, "view".concat(formattedResourceKey), view), _defineProperty(_objectSpread2, "manage".concat(formattedResourceKey), manage), _objectSpread2));
|
|
797
|
+
}, {});
|
|
798
|
+
|
|
799
|
+
var additionalPermissionNames = ((_appConfig$additional = appConfig.additionalOAuthScopes) === null || _appConfig$additional === void 0 ? void 0 : _mapInstanceProperty(_appConfig$additional).call(_appConfig$additional, function (_ref2) {
|
|
800
|
+
var name = _ref2.name;
|
|
801
|
+
return name;
|
|
802
|
+
})) || [];
|
|
803
|
+
var permissionKeys = entryPointUriPathToResourceAccesses(appConfig.entryPointUriPath, additionalPermissionNames);
|
|
804
|
+
|
|
805
|
+
var additionalPermissions = _mapInstanceProperty(_context3 = _Object$keys(additionalResourceAccessKeyToOauthScopeMap)).call(_context3, function (additionalResourceAccessKey) {
|
|
806
|
+
return {
|
|
807
|
+
name: permissionKeys[additionalResourceAccessKey],
|
|
808
|
+
oAuthScopes: additionalResourceAccessKeyToOauthScopeMap[additionalResourceAccessKey]
|
|
809
|
+
};
|
|
810
|
+
});
|
|
811
|
+
|
|
812
|
+
return _concatInstanceProperty(_context4 = [{
|
|
813
|
+
name: permissionKeys.view,
|
|
814
|
+
oAuthScopes: appConfig.oAuthScopes.view
|
|
815
|
+
}, {
|
|
816
|
+
name: permissionKeys.manage,
|
|
817
|
+
oAuthScopes: appConfig.oAuthScopes.manage
|
|
818
|
+
}]).call(_context4, _toConsumableArray(additionalPermissions));
|
|
819
|
+
};
|
|
820
|
+
|
|
714
821
|
function transformCustomApplicationConfigToData(appConfig) {
|
|
715
|
-
var
|
|
822
|
+
var _context5;
|
|
716
823
|
|
|
717
824
|
validateEntryPointUriPath(appConfig);
|
|
718
825
|
validateSubmenuLinks(appConfig);
|
|
719
|
-
|
|
826
|
+
validateAdditionalOAuthScopes(appConfig);
|
|
720
827
|
return {
|
|
721
828
|
id: appConfig.env.production.applicationId,
|
|
722
829
|
name: appConfig.name,
|
|
723
830
|
description: appConfig.description,
|
|
724
831
|
entryPointUriPath: appConfig.entryPointUriPath,
|
|
725
832
|
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
|
-
}],
|
|
833
|
+
permissions: getPermissions(appConfig),
|
|
733
834
|
icon: appConfig.icon,
|
|
734
835
|
mainMenuLink: appConfig.mainMenuLink,
|
|
735
|
-
submenuLinks: _mapInstanceProperty(
|
|
836
|
+
submenuLinks: _mapInstanceProperty(_context5 = appConfig.submenuLinks).call(_context5, function (submenuLink) {
|
|
736
837
|
return _objectSpread$1(_objectSpread$1({}, submenuLink), {}, {
|
|
737
838
|
uriPath: computeUriPath(submenuLink.uriPath, appConfig.entryPointUriPath)
|
|
738
839
|
});
|
|
@@ -811,7 +912,8 @@ var processConfig = function processConfig() {
|
|
|
811
912
|
initialProjectKey: // For the `account` application, we should unset the projectKey.
|
|
812
913
|
customApplicationData.entryPointUriPath === 'account' ? undefined : appConfig.env.development.initialProjectKey,
|
|
813
914
|
teamId: (_appConfig$env$develo = appConfig.env.development) === null || _appConfig$env$develo === void 0 ? void 0 : _appConfig$env$develo.teamId,
|
|
814
|
-
oAuthScopes: appConfig.oAuthScopes
|
|
915
|
+
oAuthScopes: appConfig.oAuthScopes,
|
|
916
|
+
additionalOAuthScopes: appConfig === null || appConfig === void 0 ? void 0 : appConfig.additionalOAuthScopes
|
|
815
917
|
}),
|
|
816
918
|
menuLinks: _objectSpread(_objectSpread({
|
|
817
919
|
icon: customApplicationData.icon
|
|
@@ -869,4 +971,4 @@ function sanitizeSvg(data) {
|
|
|
869
971
|
}).innerHTML;
|
|
870
972
|
}
|
|
871
973
|
|
|
872
|
-
export { CLOUD_IDENTIFIERS, ENTRY_POINT_URI_PATH_REGEX, MC_API_URLS, MissingOrInvalidConfigError, getConfigPath, processConfig, sanitizeSvg };
|
|
974
|
+
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;
|
|
@@ -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.0",
|
|
4
4
|
"description": "Configuration utilities for building Custom Applications",
|
|
5
5
|
"bugs": "https://github.com/commercetools/merchant-center-application-kit/issues",
|
|
6
6
|
"repository": {
|
|
@@ -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": "21.
|
|
40
|
+
"@commercetools-frontend/babel-preset-mc-app": "21.21.0",
|
|
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",
|
|
@@ -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';
|