@commercetools-frontend/permissions 22.30.2 → 22.31.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.
|
@@ -53,7 +53,7 @@ var _Object$entries__default = /*#__PURE__*/_interopDefault(_Object$entries);
|
|
|
53
53
|
var upperFirst__default = /*#__PURE__*/_interopDefault(upperFirst);
|
|
54
54
|
|
|
55
55
|
// NOTE: This string will be replaced on build time with the package version.
|
|
56
|
-
var version = "22.
|
|
56
|
+
var version = "22.31.0";
|
|
57
57
|
|
|
58
58
|
// Permissions
|
|
59
59
|
|
|
@@ -64,7 +64,7 @@ var version = "22.30.2";
|
|
|
64
64
|
// Potentially a union type.
|
|
65
65
|
|
|
66
66
|
// Build the permission key from the definition to match it to the format coming from the API.
|
|
67
|
-
const toCanCase = permissionName =>
|
|
67
|
+
const toCanCase = permissionName => `can${permissionName}`;
|
|
68
68
|
const getIsViewPermission = demandedPermission => _startsWithInstanceProperty__default["default"](demandedPermission).call(demandedPermission, 'View');
|
|
69
69
|
const toManageCase = permissionName => permissionName.replace('View', 'Manage');
|
|
70
70
|
|
|
@@ -163,7 +163,7 @@ const getHasDemandedDataFence = options => {
|
|
|
163
163
|
actualDataFenceValues: _valuesInstanceProperty__default["default"](options.actualDataFence.dataFenceValue)
|
|
164
164
|
});
|
|
165
165
|
if (!selectedDataFenceData) {
|
|
166
|
-
sentry.reportErrorToSentry(new Error(
|
|
166
|
+
sentry.reportErrorToSentry(new Error(`missing mapper for type "${options.demandedDataFence.type}"`), {
|
|
167
167
|
extra: options.demandedDataFence.type
|
|
168
168
|
});
|
|
169
169
|
return false;
|
|
@@ -204,7 +204,7 @@ const getIsPermissionOverwritingDataFence = (actualPermissions, demandedDataFenc
|
|
|
204
204
|
* Given the user _does not_ have manage access on the data fence's group
|
|
205
205
|
* Then the data fence itself takes precedence
|
|
206
206
|
*/
|
|
207
|
-
const demandedPermissionByDataFence =
|
|
207
|
+
const demandedPermissionByDataFence = `Manage${upperFirst__default["default"](demandedDataFence.group)}`;
|
|
208
208
|
if (hasExactPermission(demandedPermissionByDataFence, actualPermissions)) return true;
|
|
209
209
|
return false;
|
|
210
210
|
};
|
|
@@ -276,29 +276,20 @@ const useIsAuthorized = _ref => {
|
|
|
276
276
|
shouldMatchSomePermissions = _ref$shouldMatchSomeP === void 0 ? false : _ref$shouldMatchSomeP,
|
|
277
277
|
projectPermissions = _ref.projectPermissions;
|
|
278
278
|
const impliedPermissions = getImpliedPermissions(demandedPermissions);
|
|
279
|
-
useWarning(!demandedActionRights || demandedActionRights.length === 1,
|
|
280
|
-
useWarning(!demandedPermissions || demandedPermissions.length === 1,
|
|
281
|
-
useWarning(shouldMatchSomePermissions === false,
|
|
282
|
-
useWarning(!impliedPermissions || impliedPermissions.length === 0,
|
|
283
|
-
const actualPermissions = applicationShellConnectors.useApplicationContext(applicationContext =>
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
});
|
|
287
|
-
const actualActionRights = applicationShellConnectors.useApplicationContext(applicationContext => {
|
|
288
|
-
var _projectPermissions$a;
|
|
289
|
-
return (_projectPermissions$a = projectPermissions === null || projectPermissions === void 0 ? void 0 : projectPermissions.actionRights) !== null && _projectPermissions$a !== void 0 ? _projectPermissions$a : applicationContext.actionRights;
|
|
290
|
-
});
|
|
291
|
-
const actualDataFences = applicationShellConnectors.useApplicationContext(applicationContext => {
|
|
292
|
-
var _projectPermissions$d;
|
|
293
|
-
return (_projectPermissions$d = projectPermissions === null || projectPermissions === void 0 ? void 0 : projectPermissions.dataFences) !== null && _projectPermissions$d !== void 0 ? _projectPermissions$d : applicationContext.dataFences;
|
|
294
|
-
});
|
|
279
|
+
useWarning(!demandedActionRights || demandedActionRights.length === 1, `@commercetools-frontend/permissions: It is recommended to pass a single demanded action right while using the hook, HoC or component multiple times.`);
|
|
280
|
+
useWarning(!demandedPermissions || demandedPermissions.length === 1, `@commercetools-frontend/permissions: It is recommended to pass a single demanded permission while using the hook, HoC or component multiple times.`);
|
|
281
|
+
useWarning(shouldMatchSomePermissions === false, `@commercetools-frontend/permissions: It is recommended not to use 'shouldMatchSomePermissions' but instead use the hook, HoC or component multiple times.`);
|
|
282
|
+
useWarning(!impliedPermissions || impliedPermissions.length === 0, `@commercetools-frontend/permissions: Demanded permissions contain implied permissions. These are implied: ${impliedPermissions.join(', ')}.`);
|
|
283
|
+
const actualPermissions = applicationShellConnectors.useApplicationContext(applicationContext => projectPermissions?.permissions ?? applicationContext.permissions);
|
|
284
|
+
const actualActionRights = applicationShellConnectors.useApplicationContext(applicationContext => projectPermissions?.actionRights ?? applicationContext.actionRights);
|
|
285
|
+
const actualDataFences = applicationShellConnectors.useApplicationContext(applicationContext => projectPermissions?.dataFences ?? applicationContext.dataFences);
|
|
295
286
|
|
|
296
287
|
// if the user has no permissions and no dataFences assigned to them, they are not authorized
|
|
297
288
|
if (!actualPermissions && !actualDataFences) return false;
|
|
298
289
|
let hasDemandedDataFences = false;
|
|
299
290
|
if (demandedDataFences && demandedDataFences.length > 0) {
|
|
300
291
|
if (!selectDataFenceData) {
|
|
301
|
-
sentry.reportErrorToSentry(new Error(
|
|
292
|
+
sentry.reportErrorToSentry(new Error(`@commercetools-frontend/permissions/Authorized: Missing data fences selector "selectDataFenceData".`));
|
|
302
293
|
}
|
|
303
294
|
hasDemandedDataFences = hasSomeDataFence({
|
|
304
295
|
actualPermissions,
|
|
@@ -377,7 +368,7 @@ const injectAuthorized = function (demandedPermissions) {
|
|
|
377
368
|
[propName]: isAuthorized
|
|
378
369
|
}))
|
|
379
370
|
});
|
|
380
|
-
WrappedComponent.displayName =
|
|
371
|
+
WrappedComponent.displayName = `withUserPermissions(${getDisplayName(Component)})`;
|
|
381
372
|
return WrappedComponent;
|
|
382
373
|
};
|
|
383
374
|
};
|
|
@@ -464,7 +455,7 @@ const branchOnPermissions = function (demandedPermissions, FallbackComponent) {
|
|
|
464
455
|
return jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
465
456
|
}
|
|
466
457
|
});
|
|
467
|
-
WrappedComponent.displayName =
|
|
458
|
+
WrappedComponent.displayName = `branchOnPermissions(${getDisplayName(Component)})`;
|
|
468
459
|
return WrappedComponent;
|
|
469
460
|
};
|
|
470
461
|
};
|
|
@@ -52,7 +52,7 @@ var _Object$entries__default = /*#__PURE__*/_interopDefault(_Object$entries);
|
|
|
52
52
|
var upperFirst__default = /*#__PURE__*/_interopDefault(upperFirst);
|
|
53
53
|
|
|
54
54
|
// NOTE: This string will be replaced on build time with the package version.
|
|
55
|
-
var version = "22.
|
|
55
|
+
var version = "22.31.0";
|
|
56
56
|
|
|
57
57
|
// Permissions
|
|
58
58
|
|
|
@@ -63,7 +63,7 @@ var version = "22.30.2";
|
|
|
63
63
|
// Potentially a union type.
|
|
64
64
|
|
|
65
65
|
// Build the permission key from the definition to match it to the format coming from the API.
|
|
66
|
-
const toCanCase = permissionName =>
|
|
66
|
+
const toCanCase = permissionName => `can${permissionName}`;
|
|
67
67
|
const getIsViewPermission = demandedPermission => _startsWithInstanceProperty__default["default"](demandedPermission).call(demandedPermission, 'View');
|
|
68
68
|
const toManageCase = permissionName => permissionName.replace('View', 'Manage');
|
|
69
69
|
|
|
@@ -162,7 +162,7 @@ const getHasDemandedDataFence = options => {
|
|
|
162
162
|
actualDataFenceValues: _valuesInstanceProperty__default["default"](options.actualDataFence.dataFenceValue)
|
|
163
163
|
});
|
|
164
164
|
if (!selectedDataFenceData) {
|
|
165
|
-
sentry.reportErrorToSentry(new Error(
|
|
165
|
+
sentry.reportErrorToSentry(new Error(`missing mapper for type "${options.demandedDataFence.type}"`), {
|
|
166
166
|
extra: options.demandedDataFence.type
|
|
167
167
|
});
|
|
168
168
|
return false;
|
|
@@ -203,7 +203,7 @@ const getIsPermissionOverwritingDataFence = (actualPermissions, demandedDataFenc
|
|
|
203
203
|
* Given the user _does not_ have manage access on the data fence's group
|
|
204
204
|
* Then the data fence itself takes precedence
|
|
205
205
|
*/
|
|
206
|
-
const demandedPermissionByDataFence =
|
|
206
|
+
const demandedPermissionByDataFence = `Manage${upperFirst__default["default"](demandedDataFence.group)}`;
|
|
207
207
|
if (hasExactPermission(demandedPermissionByDataFence, actualPermissions)) return true;
|
|
208
208
|
return false;
|
|
209
209
|
};
|
|
@@ -277,26 +277,17 @@ const useIsAuthorized = _ref => {
|
|
|
277
277
|
useWarning(!demandedActionRights || demandedActionRights.length === 1);
|
|
278
278
|
useWarning(!demandedPermissions || demandedPermissions.length === 1);
|
|
279
279
|
useWarning();
|
|
280
|
-
useWarning(!impliedPermissions || impliedPermissions.length === 0,
|
|
281
|
-
const actualPermissions = applicationShellConnectors.useApplicationContext(applicationContext =>
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
});
|
|
285
|
-
const actualActionRights = applicationShellConnectors.useApplicationContext(applicationContext => {
|
|
286
|
-
var _projectPermissions$a;
|
|
287
|
-
return (_projectPermissions$a = projectPermissions === null || projectPermissions === void 0 ? void 0 : projectPermissions.actionRights) !== null && _projectPermissions$a !== void 0 ? _projectPermissions$a : applicationContext.actionRights;
|
|
288
|
-
});
|
|
289
|
-
const actualDataFences = applicationShellConnectors.useApplicationContext(applicationContext => {
|
|
290
|
-
var _projectPermissions$d;
|
|
291
|
-
return (_projectPermissions$d = projectPermissions === null || projectPermissions === void 0 ? void 0 : projectPermissions.dataFences) !== null && _projectPermissions$d !== void 0 ? _projectPermissions$d : applicationContext.dataFences;
|
|
292
|
-
});
|
|
280
|
+
useWarning(!impliedPermissions || impliedPermissions.length === 0, `@commercetools-frontend/permissions: Demanded permissions contain implied permissions. These are implied: ${impliedPermissions.join(', ')}.`);
|
|
281
|
+
const actualPermissions = applicationShellConnectors.useApplicationContext(applicationContext => projectPermissions?.permissions ?? applicationContext.permissions);
|
|
282
|
+
const actualActionRights = applicationShellConnectors.useApplicationContext(applicationContext => projectPermissions?.actionRights ?? applicationContext.actionRights);
|
|
283
|
+
const actualDataFences = applicationShellConnectors.useApplicationContext(applicationContext => projectPermissions?.dataFences ?? applicationContext.dataFences);
|
|
293
284
|
|
|
294
285
|
// if the user has no permissions and no dataFences assigned to them, they are not authorized
|
|
295
286
|
if (!actualPermissions && !actualDataFences) return false;
|
|
296
287
|
let hasDemandedDataFences = false;
|
|
297
288
|
if (demandedDataFences && demandedDataFences.length > 0) {
|
|
298
289
|
if (!selectDataFenceData) {
|
|
299
|
-
sentry.reportErrorToSentry(new Error(
|
|
290
|
+
sentry.reportErrorToSentry(new Error(`@commercetools-frontend/permissions/Authorized: Missing data fences selector "selectDataFenceData".`));
|
|
300
291
|
}
|
|
301
292
|
hasDemandedDataFences = hasSomeDataFence({
|
|
302
293
|
actualPermissions,
|
|
@@ -375,7 +366,7 @@ const injectAuthorized = function (demandedPermissions) {
|
|
|
375
366
|
[propName]: isAuthorized
|
|
376
367
|
}))
|
|
377
368
|
});
|
|
378
|
-
WrappedComponent.displayName =
|
|
369
|
+
WrappedComponent.displayName = `withUserPermissions(${getDisplayName(Component)})`;
|
|
379
370
|
return WrappedComponent;
|
|
380
371
|
};
|
|
381
372
|
};
|
|
@@ -441,7 +432,7 @@ const branchOnPermissions = function (demandedPermissions, FallbackComponent) {
|
|
|
441
432
|
return jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
442
433
|
}
|
|
443
434
|
});
|
|
444
|
-
WrappedComponent.displayName =
|
|
435
|
+
WrappedComponent.displayName = `branchOnPermissions(${getDisplayName(Component)})`;
|
|
445
436
|
return WrappedComponent;
|
|
446
437
|
};
|
|
447
438
|
};
|
|
@@ -26,7 +26,7 @@ import upperFirst from 'lodash/upperFirst';
|
|
|
26
26
|
import { jsx, Fragment } from '@emotion/react/jsx-runtime';
|
|
27
27
|
|
|
28
28
|
// NOTE: This string will be replaced on build time with the package version.
|
|
29
|
-
var version = "22.
|
|
29
|
+
var version = "22.31.0";
|
|
30
30
|
|
|
31
31
|
// Permissions
|
|
32
32
|
|
|
@@ -37,7 +37,7 @@ var version = "22.30.2";
|
|
|
37
37
|
// Potentially a union type.
|
|
38
38
|
|
|
39
39
|
// Build the permission key from the definition to match it to the format coming from the API.
|
|
40
|
-
const toCanCase = permissionName =>
|
|
40
|
+
const toCanCase = permissionName => `can${permissionName}`;
|
|
41
41
|
const getIsViewPermission = demandedPermission => _startsWithInstanceProperty(demandedPermission).call(demandedPermission, 'View');
|
|
42
42
|
const toManageCase = permissionName => permissionName.replace('View', 'Manage');
|
|
43
43
|
|
|
@@ -136,7 +136,7 @@ const getHasDemandedDataFence = options => {
|
|
|
136
136
|
actualDataFenceValues: _valuesInstanceProperty(options.actualDataFence.dataFenceValue)
|
|
137
137
|
});
|
|
138
138
|
if (!selectedDataFenceData) {
|
|
139
|
-
reportErrorToSentry(new Error(
|
|
139
|
+
reportErrorToSentry(new Error(`missing mapper for type "${options.demandedDataFence.type}"`), {
|
|
140
140
|
extra: options.demandedDataFence.type
|
|
141
141
|
});
|
|
142
142
|
return false;
|
|
@@ -177,7 +177,7 @@ const getIsPermissionOverwritingDataFence = (actualPermissions, demandedDataFenc
|
|
|
177
177
|
* Given the user _does not_ have manage access on the data fence's group
|
|
178
178
|
* Then the data fence itself takes precedence
|
|
179
179
|
*/
|
|
180
|
-
const demandedPermissionByDataFence =
|
|
180
|
+
const demandedPermissionByDataFence = `Manage${upperFirst(demandedDataFence.group)}`;
|
|
181
181
|
if (hasExactPermission(demandedPermissionByDataFence, actualPermissions)) return true;
|
|
182
182
|
return false;
|
|
183
183
|
};
|
|
@@ -249,29 +249,20 @@ const useIsAuthorized = _ref => {
|
|
|
249
249
|
shouldMatchSomePermissions = _ref$shouldMatchSomeP === void 0 ? false : _ref$shouldMatchSomeP,
|
|
250
250
|
projectPermissions = _ref.projectPermissions;
|
|
251
251
|
const impliedPermissions = getImpliedPermissions(demandedPermissions);
|
|
252
|
-
useWarning(!demandedActionRights || demandedActionRights.length === 1,
|
|
253
|
-
useWarning(!demandedPermissions || demandedPermissions.length === 1,
|
|
254
|
-
useWarning(shouldMatchSomePermissions === false,
|
|
255
|
-
useWarning(!impliedPermissions || impliedPermissions.length === 0,
|
|
256
|
-
const actualPermissions = useApplicationContext(applicationContext =>
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
});
|
|
260
|
-
const actualActionRights = useApplicationContext(applicationContext => {
|
|
261
|
-
var _projectPermissions$a;
|
|
262
|
-
return (_projectPermissions$a = projectPermissions === null || projectPermissions === void 0 ? void 0 : projectPermissions.actionRights) !== null && _projectPermissions$a !== void 0 ? _projectPermissions$a : applicationContext.actionRights;
|
|
263
|
-
});
|
|
264
|
-
const actualDataFences = useApplicationContext(applicationContext => {
|
|
265
|
-
var _projectPermissions$d;
|
|
266
|
-
return (_projectPermissions$d = projectPermissions === null || projectPermissions === void 0 ? void 0 : projectPermissions.dataFences) !== null && _projectPermissions$d !== void 0 ? _projectPermissions$d : applicationContext.dataFences;
|
|
267
|
-
});
|
|
252
|
+
useWarning(!demandedActionRights || demandedActionRights.length === 1, `@commercetools-frontend/permissions: It is recommended to pass a single demanded action right while using the hook, HoC or component multiple times.`);
|
|
253
|
+
useWarning(!demandedPermissions || demandedPermissions.length === 1, `@commercetools-frontend/permissions: It is recommended to pass a single demanded permission while using the hook, HoC or component multiple times.`);
|
|
254
|
+
useWarning(shouldMatchSomePermissions === false, `@commercetools-frontend/permissions: It is recommended not to use 'shouldMatchSomePermissions' but instead use the hook, HoC or component multiple times.`);
|
|
255
|
+
useWarning(!impliedPermissions || impliedPermissions.length === 0, `@commercetools-frontend/permissions: Demanded permissions contain implied permissions. These are implied: ${impliedPermissions.join(', ')}.`);
|
|
256
|
+
const actualPermissions = useApplicationContext(applicationContext => projectPermissions?.permissions ?? applicationContext.permissions);
|
|
257
|
+
const actualActionRights = useApplicationContext(applicationContext => projectPermissions?.actionRights ?? applicationContext.actionRights);
|
|
258
|
+
const actualDataFences = useApplicationContext(applicationContext => projectPermissions?.dataFences ?? applicationContext.dataFences);
|
|
268
259
|
|
|
269
260
|
// if the user has no permissions and no dataFences assigned to them, they are not authorized
|
|
270
261
|
if (!actualPermissions && !actualDataFences) return false;
|
|
271
262
|
let hasDemandedDataFences = false;
|
|
272
263
|
if (demandedDataFences && demandedDataFences.length > 0) {
|
|
273
264
|
if (!selectDataFenceData) {
|
|
274
|
-
reportErrorToSentry(new Error(
|
|
265
|
+
reportErrorToSentry(new Error(`@commercetools-frontend/permissions/Authorized: Missing data fences selector "selectDataFenceData".`));
|
|
275
266
|
}
|
|
276
267
|
hasDemandedDataFences = hasSomeDataFence({
|
|
277
268
|
actualPermissions,
|
|
@@ -350,7 +341,7 @@ const injectAuthorized = function (demandedPermissions) {
|
|
|
350
341
|
[propName]: isAuthorized
|
|
351
342
|
}))
|
|
352
343
|
});
|
|
353
|
-
WrappedComponent.displayName =
|
|
344
|
+
WrappedComponent.displayName = `withUserPermissions(${getDisplayName(Component)})`;
|
|
354
345
|
return WrappedComponent;
|
|
355
346
|
};
|
|
356
347
|
};
|
|
@@ -437,7 +428,7 @@ const branchOnPermissions = function (demandedPermissions, FallbackComponent) {
|
|
|
437
428
|
return jsx(Fragment, {});
|
|
438
429
|
}
|
|
439
430
|
});
|
|
440
|
-
WrappedComponent.displayName =
|
|
431
|
+
WrappedComponent.displayName = `branchOnPermissions(${getDisplayName(Component)})`;
|
|
441
432
|
return WrappedComponent;
|
|
442
433
|
};
|
|
443
434
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools-frontend/permissions",
|
|
3
|
-
"version": "22.
|
|
3
|
+
"version": "22.31.0",
|
|
4
4
|
"description": "React components to declaratively handle MC permissions",
|
|
5
5
|
"bugs": "https://github.com/commercetools/merchant-center-application-kit/issues",
|
|
6
6
|
"repository": {
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@babel/runtime": "^7.22.15",
|
|
32
32
|
"@babel/runtime-corejs3": "^7.22.15",
|
|
33
|
-
"@commercetools-frontend/application-shell-connectors": "22.
|
|
34
|
-
"@commercetools-frontend/sentry": "22.
|
|
33
|
+
"@commercetools-frontend/application-shell-connectors": "22.31.0",
|
|
34
|
+
"@commercetools-frontend/sentry": "22.31.0",
|
|
35
35
|
"@emotion/react": "^11.11.4",
|
|
36
36
|
"@types/lodash": "^4.14.198",
|
|
37
37
|
"@types/prop-types": "^15.7.5",
|