@commercetools-frontend/permissions 24.11.0 → 24.12.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 = "24.
|
|
55
|
+
var version = "24.12.0";
|
|
56
56
|
|
|
57
57
|
// Permissions
|
|
58
58
|
|
|
@@ -63,7 +63,7 @@ var version = "24.11.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".concat(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 \"".concat(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".concat(upperFirst__default["default"](demandedDataFence.group));
|
|
207
207
|
if (hasExactPermission(demandedPermissionByDataFence, actualPermissions)) return true;
|
|
208
208
|
return false;
|
|
209
209
|
};
|
|
@@ -275,20 +275,29 @@ 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
|
-
|
|
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: ".concat(impliedPermissions.join(', '), "."));
|
|
282
|
+
const actualPermissions = applicationShellConnectors.useApplicationContext(applicationContext => {
|
|
283
|
+
var _projectPermissions$p;
|
|
284
|
+
return (_projectPermissions$p = projectPermissions === null || projectPermissions === void 0 ? void 0 : projectPermissions.permissions) !== null && _projectPermissions$p !== void 0 ? _projectPermissions$p : applicationContext.permissions;
|
|
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
|
+
});
|
|
285
294
|
|
|
286
295
|
// if the user has no permissions and no dataFences assigned to them, they are not authorized
|
|
287
296
|
if (!actualPermissions && !actualDataFences) return false;
|
|
288
297
|
let hasDemandedDataFences = false;
|
|
289
298
|
if (demandedDataFences && demandedDataFences.length > 0) {
|
|
290
299
|
if (!selectDataFenceData) {
|
|
291
|
-
sentry.reportErrorToSentry(new Error(
|
|
300
|
+
sentry.reportErrorToSentry(new Error("@commercetools-frontend/permissions/Authorized: Missing data fences selector \"selectDataFenceData\"."));
|
|
292
301
|
}
|
|
293
302
|
hasDemandedDataFences = hasSomeDataFence({
|
|
294
303
|
actualPermissions,
|
|
@@ -349,7 +358,7 @@ const injectAuthorized = function (demandedPermissions) {
|
|
|
349
358
|
[propName]: isAuthorized
|
|
350
359
|
}))
|
|
351
360
|
});
|
|
352
|
-
WrappedComponent.displayName =
|
|
361
|
+
WrappedComponent.displayName = "withUserPermissions(".concat(getDisplayName(Component), ")");
|
|
353
362
|
return WrappedComponent;
|
|
354
363
|
};
|
|
355
364
|
};
|
|
@@ -415,7 +424,7 @@ const branchOnPermissions = function (demandedPermissions, FallbackComponent) {
|
|
|
415
424
|
return jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
416
425
|
}
|
|
417
426
|
});
|
|
418
|
-
WrappedComponent.displayName =
|
|
427
|
+
WrappedComponent.displayName = "branchOnPermissions(".concat(getDisplayName(Component), ")");
|
|
419
428
|
return WrappedComponent;
|
|
420
429
|
};
|
|
421
430
|
};
|
|
@@ -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 = "24.
|
|
54
|
+
var version = "24.12.0";
|
|
55
55
|
|
|
56
56
|
// Permissions
|
|
57
57
|
|
|
@@ -62,7 +62,7 @@ var version = "24.11.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".concat(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 \"".concat(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".concat(upperFirst__default["default"](demandedDataFence.group));
|
|
206
206
|
if (hasExactPermission(demandedPermissionByDataFence, actualPermissions)) return true;
|
|
207
207
|
return false;
|
|
208
208
|
};
|
|
@@ -276,17 +276,26 @@ 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
|
-
|
|
279
|
+
useWarning(!impliedPermissions || impliedPermissions.length === 0, "@commercetools-frontend/permissions: Demanded permissions contain implied permissions. These are implied: ".concat(impliedPermissions.join(', '), "."));
|
|
280
|
+
const actualPermissions = applicationShellConnectors.useApplicationContext(applicationContext => {
|
|
281
|
+
var _projectPermissions$p;
|
|
282
|
+
return (_projectPermissions$p = projectPermissions === null || projectPermissions === void 0 ? void 0 : projectPermissions.permissions) !== null && _projectPermissions$p !== void 0 ? _projectPermissions$p : applicationContext.permissions;
|
|
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
|
+
});
|
|
283
292
|
|
|
284
293
|
// if the user has no permissions and no dataFences assigned to them, they are not authorized
|
|
285
294
|
if (!actualPermissions && !actualDataFences) return false;
|
|
286
295
|
let hasDemandedDataFences = false;
|
|
287
296
|
if (demandedDataFences && demandedDataFences.length > 0) {
|
|
288
297
|
if (!selectDataFenceData) {
|
|
289
|
-
sentry.reportErrorToSentry(new Error(
|
|
298
|
+
sentry.reportErrorToSentry(new Error("@commercetools-frontend/permissions/Authorized: Missing data fences selector \"selectDataFenceData\"."));
|
|
290
299
|
}
|
|
291
300
|
hasDemandedDataFences = hasSomeDataFence({
|
|
292
301
|
actualPermissions,
|
|
@@ -347,7 +356,7 @@ const injectAuthorized = function (demandedPermissions) {
|
|
|
347
356
|
[propName]: isAuthorized
|
|
348
357
|
}))
|
|
349
358
|
});
|
|
350
|
-
WrappedComponent.displayName =
|
|
359
|
+
WrappedComponent.displayName = "withUserPermissions(".concat(getDisplayName(Component), ")");
|
|
351
360
|
return WrappedComponent;
|
|
352
361
|
};
|
|
353
362
|
};
|
|
@@ -413,7 +422,7 @@ const branchOnPermissions = function (demandedPermissions, FallbackComponent) {
|
|
|
413
422
|
return jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
414
423
|
}
|
|
415
424
|
});
|
|
416
|
-
WrappedComponent.displayName =
|
|
425
|
+
WrappedComponent.displayName = "branchOnPermissions(".concat(getDisplayName(Component), ")");
|
|
417
426
|
return WrappedComponent;
|
|
418
427
|
};
|
|
419
428
|
};
|
|
@@ -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 = "24.
|
|
29
|
+
var version = "24.12.0";
|
|
30
30
|
|
|
31
31
|
// Permissions
|
|
32
32
|
|
|
@@ -37,7 +37,7 @@ var version = "24.11.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".concat(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 \"".concat(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".concat(upperFirst(demandedDataFence.group));
|
|
181
181
|
if (hasExactPermission(demandedPermissionByDataFence, actualPermissions)) return true;
|
|
182
182
|
return false;
|
|
183
183
|
};
|
|
@@ -249,20 +249,29 @@ 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
|
-
|
|
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: ".concat(impliedPermissions.join(', '), "."));
|
|
256
|
+
const actualPermissions = useApplicationContext(applicationContext => {
|
|
257
|
+
var _projectPermissions$p;
|
|
258
|
+
return (_projectPermissions$p = projectPermissions === null || projectPermissions === void 0 ? void 0 : projectPermissions.permissions) !== null && _projectPermissions$p !== void 0 ? _projectPermissions$p : applicationContext.permissions;
|
|
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
|
+
});
|
|
259
268
|
|
|
260
269
|
// if the user has no permissions and no dataFences assigned to them, they are not authorized
|
|
261
270
|
if (!actualPermissions && !actualDataFences) return false;
|
|
262
271
|
let hasDemandedDataFences = false;
|
|
263
272
|
if (demandedDataFences && demandedDataFences.length > 0) {
|
|
264
273
|
if (!selectDataFenceData) {
|
|
265
|
-
reportErrorToSentry(new Error(
|
|
274
|
+
reportErrorToSentry(new Error("@commercetools-frontend/permissions/Authorized: Missing data fences selector \"selectDataFenceData\"."));
|
|
266
275
|
}
|
|
267
276
|
hasDemandedDataFences = hasSomeDataFence({
|
|
268
277
|
actualPermissions,
|
|
@@ -323,7 +332,7 @@ const injectAuthorized = function (demandedPermissions) {
|
|
|
323
332
|
[propName]: isAuthorized
|
|
324
333
|
}))
|
|
325
334
|
});
|
|
326
|
-
WrappedComponent.displayName =
|
|
335
|
+
WrappedComponent.displayName = "withUserPermissions(".concat(getDisplayName(Component), ")");
|
|
327
336
|
return WrappedComponent;
|
|
328
337
|
};
|
|
329
338
|
};
|
|
@@ -389,7 +398,7 @@ const branchOnPermissions = function (demandedPermissions, FallbackComponent) {
|
|
|
389
398
|
return jsx(Fragment, {});
|
|
390
399
|
}
|
|
391
400
|
});
|
|
392
|
-
WrappedComponent.displayName =
|
|
401
|
+
WrappedComponent.displayName = "branchOnPermissions(".concat(getDisplayName(Component), ")");
|
|
393
402
|
return WrappedComponent;
|
|
394
403
|
};
|
|
395
404
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools-frontend/permissions",
|
|
3
|
-
"version": "24.
|
|
3
|
+
"version": "24.12.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": "24.
|
|
34
|
-
"@commercetools-frontend/sentry": "24.
|
|
33
|
+
"@commercetools-frontend/application-shell-connectors": "24.12.0",
|
|
34
|
+
"@commercetools-frontend/sentry": "24.12.0",
|
|
35
35
|
"@emotion/react": "^11.14.0",
|
|
36
36
|
"@types/lodash": "^4.14.198",
|
|
37
37
|
"@types/prop-types": "^15.7.5",
|