@commercetools-frontend/permissions 25.0.0 → 25.2.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.
|
@@ -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 = "25.
|
|
55
|
+
var version = "25.2.0";
|
|
56
56
|
|
|
57
57
|
// Permissions
|
|
58
58
|
|
|
@@ -63,7 +63,7 @@ var version = "25.0.0";
|
|
|
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
|
};
|
|
@@ -275,29 +275,20 @@ const useIsAuthorized = _ref => {
|
|
|
275
275
|
shouldMatchSomePermissions = _ref$shouldMatchSomeP === void 0 ? false : _ref$shouldMatchSomeP,
|
|
276
276
|
projectPermissions = _ref.projectPermissions;
|
|
277
277
|
const impliedPermissions = getImpliedPermissions(demandedPermissions);
|
|
278
|
-
useWarning(!demandedActionRights || demandedActionRights.length === 1,
|
|
279
|
-
useWarning(!demandedPermissions || demandedPermissions.length === 1,
|
|
280
|
-
useWarning(shouldMatchSomePermissions === false,
|
|
281
|
-
useWarning(!impliedPermissions || impliedPermissions.length === 0,
|
|
282
|
-
const actualPermissions = applicationShellConnectors.useApplicationContext(applicationContext =>
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
});
|
|
286
|
-
const actualActionRights = applicationShellConnectors.useApplicationContext(applicationContext => {
|
|
287
|
-
var _projectPermissions$a;
|
|
288
|
-
return (_projectPermissions$a = projectPermissions === null || projectPermissions === void 0 ? void 0 : projectPermissions.actionRights) !== null && _projectPermissions$a !== void 0 ? _projectPermissions$a : applicationContext.actionRights;
|
|
289
|
-
});
|
|
290
|
-
const actualDataFences = applicationShellConnectors.useApplicationContext(applicationContext => {
|
|
291
|
-
var _projectPermissions$d;
|
|
292
|
-
return (_projectPermissions$d = projectPermissions === null || projectPermissions === void 0 ? void 0 : projectPermissions.dataFences) !== null && _projectPermissions$d !== void 0 ? _projectPermissions$d : applicationContext.dataFences;
|
|
293
|
-
});
|
|
278
|
+
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.`);
|
|
279
|
+
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.`);
|
|
280
|
+
useWarning(shouldMatchSomePermissions === false, `@commercetools-frontend/permissions: It is recommended not to use 'shouldMatchSomePermissions' but instead use the hook, HoC or component multiple times.`);
|
|
281
|
+
useWarning(!impliedPermissions || impliedPermissions.length === 0, `@commercetools-frontend/permissions: Demanded permissions contain implied permissions. These are implied: ${impliedPermissions.join(', ')}.`);
|
|
282
|
+
const actualPermissions = applicationShellConnectors.useApplicationContext(applicationContext => projectPermissions?.permissions ?? applicationContext.permissions);
|
|
283
|
+
const actualActionRights = applicationShellConnectors.useApplicationContext(applicationContext => projectPermissions?.actionRights ?? applicationContext.actionRights);
|
|
284
|
+
const actualDataFences = applicationShellConnectors.useApplicationContext(applicationContext => projectPermissions?.dataFences ?? applicationContext.dataFences);
|
|
294
285
|
|
|
295
286
|
// if the user has no permissions and no dataFences assigned to them, they are not authorized
|
|
296
287
|
if (!actualPermissions && !actualDataFences) return false;
|
|
297
288
|
let hasDemandedDataFences = false;
|
|
298
289
|
if (demandedDataFences && demandedDataFences.length > 0) {
|
|
299
290
|
if (!selectDataFenceData) {
|
|
300
|
-
sentry.reportErrorToSentry(new Error(
|
|
291
|
+
sentry.reportErrorToSentry(new Error(`@commercetools-frontend/permissions/Authorized: Missing data fences selector "selectDataFenceData".`));
|
|
301
292
|
}
|
|
302
293
|
hasDemandedDataFences = hasSomeDataFence({
|
|
303
294
|
actualPermissions,
|
|
@@ -358,7 +349,7 @@ const injectAuthorized = function (demandedPermissions) {
|
|
|
358
349
|
[propName]: isAuthorized
|
|
359
350
|
}))
|
|
360
351
|
});
|
|
361
|
-
WrappedComponent.displayName =
|
|
352
|
+
WrappedComponent.displayName = `withUserPermissions(${getDisplayName(Component)})`;
|
|
362
353
|
return WrappedComponent;
|
|
363
354
|
};
|
|
364
355
|
};
|
|
@@ -424,7 +415,7 @@ const branchOnPermissions = function (demandedPermissions, FallbackComponent) {
|
|
|
424
415
|
return jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
425
416
|
}
|
|
426
417
|
});
|
|
427
|
-
WrappedComponent.displayName =
|
|
418
|
+
WrappedComponent.displayName = `branchOnPermissions(${getDisplayName(Component)})`;
|
|
428
419
|
return WrappedComponent;
|
|
429
420
|
};
|
|
430
421
|
};
|
|
@@ -51,7 +51,7 @@ var _Object$entries__default = /*#__PURE__*/_interopDefault(_Object$entries);
|
|
|
51
51
|
var upperFirst__default = /*#__PURE__*/_interopDefault(upperFirst);
|
|
52
52
|
|
|
53
53
|
// NOTE: This string will be replaced on build time with the package version.
|
|
54
|
-
var version = "25.
|
|
54
|
+
var version = "25.2.0";
|
|
55
55
|
|
|
56
56
|
// Permissions
|
|
57
57
|
|
|
@@ -62,7 +62,7 @@ var version = "25.0.0";
|
|
|
62
62
|
// Potentially a union type.
|
|
63
63
|
|
|
64
64
|
// Build the permission key from the definition to match it to the format coming from the API.
|
|
65
|
-
const toCanCase = permissionName =>
|
|
65
|
+
const toCanCase = permissionName => `can${permissionName}`;
|
|
66
66
|
const getIsViewPermission = demandedPermission => _startsWithInstanceProperty__default["default"](demandedPermission).call(demandedPermission, 'View');
|
|
67
67
|
const toManageCase = permissionName => permissionName.replace('View', 'Manage');
|
|
68
68
|
|
|
@@ -161,7 +161,7 @@ const getHasDemandedDataFence = options => {
|
|
|
161
161
|
actualDataFenceValues: _valuesInstanceProperty__default["default"](options.actualDataFence.dataFenceValue)
|
|
162
162
|
});
|
|
163
163
|
if (!selectedDataFenceData) {
|
|
164
|
-
sentry.reportErrorToSentry(new Error(
|
|
164
|
+
sentry.reportErrorToSentry(new Error(`missing mapper for type "${options.demandedDataFence.type}"`), {
|
|
165
165
|
extra: options.demandedDataFence.type
|
|
166
166
|
});
|
|
167
167
|
return false;
|
|
@@ -202,7 +202,7 @@ const getIsPermissionOverwritingDataFence = (actualPermissions, demandedDataFenc
|
|
|
202
202
|
* Given the user _does not_ have manage access on the data fence's group
|
|
203
203
|
* Then the data fence itself takes precedence
|
|
204
204
|
*/
|
|
205
|
-
const demandedPermissionByDataFence =
|
|
205
|
+
const demandedPermissionByDataFence = `Manage${upperFirst__default["default"](demandedDataFence.group)}`;
|
|
206
206
|
if (hasExactPermission(demandedPermissionByDataFence, actualPermissions)) return true;
|
|
207
207
|
return false;
|
|
208
208
|
};
|
|
@@ -276,26 +276,17 @@ const useIsAuthorized = _ref => {
|
|
|
276
276
|
useWarning(!demandedActionRights || demandedActionRights.length === 1);
|
|
277
277
|
useWarning(!demandedPermissions || demandedPermissions.length === 1);
|
|
278
278
|
useWarning();
|
|
279
|
-
useWarning(!impliedPermissions || impliedPermissions.length === 0,
|
|
280
|
-
const actualPermissions = applicationShellConnectors.useApplicationContext(applicationContext =>
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
});
|
|
284
|
-
const actualActionRights = applicationShellConnectors.useApplicationContext(applicationContext => {
|
|
285
|
-
var _projectPermissions$a;
|
|
286
|
-
return (_projectPermissions$a = projectPermissions === null || projectPermissions === void 0 ? void 0 : projectPermissions.actionRights) !== null && _projectPermissions$a !== void 0 ? _projectPermissions$a : applicationContext.actionRights;
|
|
287
|
-
});
|
|
288
|
-
const actualDataFences = applicationShellConnectors.useApplicationContext(applicationContext => {
|
|
289
|
-
var _projectPermissions$d;
|
|
290
|
-
return (_projectPermissions$d = projectPermissions === null || projectPermissions === void 0 ? void 0 : projectPermissions.dataFences) !== null && _projectPermissions$d !== void 0 ? _projectPermissions$d : applicationContext.dataFences;
|
|
291
|
-
});
|
|
279
|
+
useWarning(!impliedPermissions || impliedPermissions.length === 0, `@commercetools-frontend/permissions: Demanded permissions contain implied permissions. These are implied: ${impliedPermissions.join(', ')}.`);
|
|
280
|
+
const actualPermissions = applicationShellConnectors.useApplicationContext(applicationContext => projectPermissions?.permissions ?? applicationContext.permissions);
|
|
281
|
+
const actualActionRights = applicationShellConnectors.useApplicationContext(applicationContext => projectPermissions?.actionRights ?? applicationContext.actionRights);
|
|
282
|
+
const actualDataFences = applicationShellConnectors.useApplicationContext(applicationContext => projectPermissions?.dataFences ?? applicationContext.dataFences);
|
|
292
283
|
|
|
293
284
|
// if the user has no permissions and no dataFences assigned to them, they are not authorized
|
|
294
285
|
if (!actualPermissions && !actualDataFences) return false;
|
|
295
286
|
let hasDemandedDataFences = false;
|
|
296
287
|
if (demandedDataFences && demandedDataFences.length > 0) {
|
|
297
288
|
if (!selectDataFenceData) {
|
|
298
|
-
sentry.reportErrorToSentry(new Error(
|
|
289
|
+
sentry.reportErrorToSentry(new Error(`@commercetools-frontend/permissions/Authorized: Missing data fences selector "selectDataFenceData".`));
|
|
299
290
|
}
|
|
300
291
|
hasDemandedDataFences = hasSomeDataFence({
|
|
301
292
|
actualPermissions,
|
|
@@ -356,7 +347,7 @@ const injectAuthorized = function (demandedPermissions) {
|
|
|
356
347
|
[propName]: isAuthorized
|
|
357
348
|
}))
|
|
358
349
|
});
|
|
359
|
-
WrappedComponent.displayName =
|
|
350
|
+
WrappedComponent.displayName = `withUserPermissions(${getDisplayName(Component)})`;
|
|
360
351
|
return WrappedComponent;
|
|
361
352
|
};
|
|
362
353
|
};
|
|
@@ -422,7 +413,7 @@ const branchOnPermissions = function (demandedPermissions, FallbackComponent) {
|
|
|
422
413
|
return jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
423
414
|
}
|
|
424
415
|
});
|
|
425
|
-
WrappedComponent.displayName =
|
|
416
|
+
WrappedComponent.displayName = `branchOnPermissions(${getDisplayName(Component)})`;
|
|
426
417
|
return WrappedComponent;
|
|
427
418
|
};
|
|
428
419
|
};
|
|
@@ -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 = "25.
|
|
29
|
+
var version = "25.2.0";
|
|
30
30
|
|
|
31
31
|
// Permissions
|
|
32
32
|
|
|
@@ -37,7 +37,7 @@ var version = "25.0.0";
|
|
|
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,
|
|
@@ -332,7 +323,7 @@ const injectAuthorized = function (demandedPermissions) {
|
|
|
332
323
|
[propName]: isAuthorized
|
|
333
324
|
}))
|
|
334
325
|
});
|
|
335
|
-
WrappedComponent.displayName =
|
|
326
|
+
WrappedComponent.displayName = `withUserPermissions(${getDisplayName(Component)})`;
|
|
336
327
|
return WrappedComponent;
|
|
337
328
|
};
|
|
338
329
|
};
|
|
@@ -398,7 +389,7 @@ const branchOnPermissions = function (demandedPermissions, FallbackComponent) {
|
|
|
398
389
|
return jsx(Fragment, {});
|
|
399
390
|
}
|
|
400
391
|
});
|
|
401
|
-
WrappedComponent.displayName =
|
|
392
|
+
WrappedComponent.displayName = `branchOnPermissions(${getDisplayName(Component)})`;
|
|
402
393
|
return WrappedComponent;
|
|
403
394
|
};
|
|
404
395
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools-frontend/permissions",
|
|
3
|
-
"version": "25.
|
|
3
|
+
"version": "25.2.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,13 +30,13 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@babel/runtime": "^7.22.15",
|
|
32
32
|
"@babel/runtime-corejs3": "^7.22.15",
|
|
33
|
-
"@commercetools-frontend/application-shell-connectors": "25.
|
|
34
|
-
"@commercetools-frontend/sentry": "25.
|
|
33
|
+
"@commercetools-frontend/application-shell-connectors": "25.2.0",
|
|
34
|
+
"@commercetools-frontend/sentry": "25.2.0",
|
|
35
35
|
"@emotion/react": "^11.14.0",
|
|
36
36
|
"@types/lodash": "^4.14.198",
|
|
37
37
|
"@types/prop-types": "^15.7.5",
|
|
38
38
|
"@types/react": "^19.0.3",
|
|
39
|
-
"lodash": "4.17.
|
|
39
|
+
"lodash": "4.17.23",
|
|
40
40
|
"prop-types": "15.8.1",
|
|
41
41
|
"tiny-invariant": "1.3.3",
|
|
42
42
|
"tiny-warning": "1.0.3"
|