@webiny/app-security 5.34.8-beta.1 → 5.35.0-beta.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/README.md +1 -1
- package/Security.js +1 -7
- package/Security.js.map +1 -1
- package/components/HasPermission.js +2 -15
- package/components/HasPermission.js.map +1 -1
- package/components/SecureRoute.js +2 -15
- package/components/SecureRoute.js.map +1 -1
- package/components/SecureView.js +2 -10
- package/components/SecureView.js.map +1 -1
- package/components/index.js +0 -4
- package/components/index.js.map +1 -1
- package/contexts/Security.js +5 -18
- package/contexts/Security.js.map +1 -1
- package/hooks/usePermission.js +1 -4
- package/hooks/usePermission.js.map +1 -1
- package/hooks/useSecurity.js +0 -3
- package/hooks/useSecurity.js.map +1 -1
- package/index.js +0 -10
- package/index.js.map +1 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -51,7 +51,7 @@ A simple `Authenticator` React component (uses Amazon Cognito and AWS Amplify's
|
|
|
51
51
|
|
|
52
52
|
```tsx
|
|
53
53
|
import React, { useEffect } from "react";
|
|
54
|
-
import Auth from "@aws-amplify/auth";
|
|
54
|
+
import { Auth } from "@aws-amplify/auth";
|
|
55
55
|
import { useSecurity, SecurityIdentity } from "@webiny/app-security";
|
|
56
56
|
|
|
57
57
|
// Apart from the React component, we also configure the Auth class here.
|
package/Security.js
CHANGED
|
@@ -1,32 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.Security = void 0;
|
|
9
|
-
|
|
10
8
|
var _react = _interopRequireDefault(require("react"));
|
|
11
|
-
|
|
12
9
|
var _app = require("@webiny/app");
|
|
13
|
-
|
|
14
10
|
var _Security = require("./contexts/Security");
|
|
15
|
-
|
|
16
11
|
// Importing from `app-core` and NOT from `app-admin`, to avoid circular dependency.
|
|
17
12
|
// This can be resolved in a different way, by changing the location of `AppInstaller` component (currently in `app-admin`).
|
|
18
13
|
// But this is a faster solution, as I'm really short on time :)
|
|
14
|
+
|
|
19
15
|
var SecurityProviderHOC = function SecurityProviderHOC(Component) {
|
|
20
16
|
return function SecurityProvider(_ref) {
|
|
21
17
|
var children = _ref.children;
|
|
22
18
|
return /*#__PURE__*/_react.default.createElement(_Security.SecurityProvider, null, /*#__PURE__*/_react.default.createElement(Component, null, children));
|
|
23
19
|
};
|
|
24
20
|
};
|
|
25
|
-
|
|
26
21
|
var Security = function Security() {
|
|
27
22
|
return /*#__PURE__*/_react.default.createElement(_app.Provider, {
|
|
28
23
|
hoc: SecurityProviderHOC
|
|
29
24
|
});
|
|
30
25
|
};
|
|
31
|
-
|
|
32
26
|
exports.Security = Security;
|
package/Security.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["SecurityProviderHOC","Component","SecurityProvider","children","Security"],"sources":["Security.tsx"],"sourcesContent":["// Importing from `app-core` and NOT from `app-admin`, to avoid circular dependency.\n// This can be resolved in a different way, by changing the location of `AppInstaller` component (currently in `app-admin`).\n// But this is a faster solution, as I'm really short on time :)\nimport React from \"react\";\nimport { Provider } from \"@webiny/app\";\nimport { SecurityProvider as ContextProvider } from \"./contexts/Security\";\n\nconst SecurityProviderHOC = (Component: React.FC<any>): React.FC<any> => {\n return function SecurityProvider({ children }) {\n return (\n <ContextProvider>\n <Component>{children}</Component>\n </ContextProvider>\n );\n };\n};\n\nexport const Security: React.FC = () => {\n return <Provider hoc={SecurityProviderHOC} />;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["SecurityProviderHOC","Component","SecurityProvider","children","Security"],"sources":["Security.tsx"],"sourcesContent":["// Importing from `app-core` and NOT from `app-admin`, to avoid circular dependency.\n// This can be resolved in a different way, by changing the location of `AppInstaller` component (currently in `app-admin`).\n// But this is a faster solution, as I'm really short on time :)\nimport React from \"react\";\nimport { Provider } from \"@webiny/app\";\nimport { SecurityProvider as ContextProvider } from \"./contexts/Security\";\n\nconst SecurityProviderHOC = (Component: React.FC<any>): React.FC<any> => {\n return function SecurityProvider({ children }) {\n return (\n <ContextProvider>\n <Component>{children}</Component>\n </ContextProvider>\n );\n };\n};\n\nexport const Security: React.FC = () => {\n return <Provider hoc={SecurityProviderHOC} />;\n};\n"],"mappings":";;;;;;;AAGA;AACA;AACA;AALA;AACA;AACA;;AAKA,IAAMA,mBAAmB,GAAG,SAAtBA,mBAAmB,CAAIC,SAAwB,EAAoB;EACrE,OAAO,SAASC,gBAAgB,OAAe;IAAA,IAAZC,QAAQ,QAARA,QAAQ;IACvC,oBACI,6BAAC,0BAAe,qBACZ,6BAAC,SAAS,QAAEA,QAAQ,CAAa,CACnB;EAE1B,CAAC;AACL,CAAC;AAEM,IAAMC,QAAkB,GAAG,SAArBA,QAAkB,GAAS;EACpC,oBAAO,6BAAC,aAAQ;IAAC,GAAG,EAAEJ;EAAoB,EAAG;AACjD,CAAC;AAAC"}
|
|
@@ -1,39 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
6
|
-
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
8
|
exports.HasPermission = void 0;
|
|
11
|
-
|
|
12
9
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
13
|
-
|
|
14
10
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
15
|
-
|
|
16
11
|
var _react = _interopRequireWildcard(require("react"));
|
|
17
|
-
|
|
18
12
|
var _useSecurity2 = require("../hooks/useSecurity");
|
|
19
|
-
|
|
20
13
|
var _excluded = ["children"];
|
|
21
|
-
|
|
22
14
|
var HasPermission = function HasPermission(_ref) {
|
|
23
15
|
var children = _ref.children,
|
|
24
|
-
|
|
25
|
-
|
|
16
|
+
props = (0, _objectWithoutProperties2.default)(_ref, _excluded);
|
|
26
17
|
var _useSecurity = (0, _useSecurity2.useSecurity)(),
|
|
27
|
-
|
|
28
|
-
|
|
18
|
+
getPermission = _useSecurity.getPermission;
|
|
29
19
|
if (props.any && props.all) {
|
|
30
20
|
throw new Error("You can use either \"any\" or \"all\", but not both at the same time.");
|
|
31
21
|
}
|
|
32
|
-
|
|
33
22
|
if (props.name) {
|
|
34
23
|
return getPermission(props.name) ? /*#__PURE__*/_react.default.createElement(_react.Fragment, null, children) : null;
|
|
35
24
|
}
|
|
36
|
-
|
|
37
25
|
var permissions = [].concat((0, _toConsumableArray2.default)(props.any || []), (0, _toConsumableArray2.default)(props.all || [])).map(function (name) {
|
|
38
26
|
return getPermission(name);
|
|
39
27
|
});
|
|
@@ -44,5 +32,4 @@ var HasPermission = function HasPermission(_ref) {
|
|
|
44
32
|
});
|
|
45
33
|
return hasPermission ? /*#__PURE__*/_react.default.createElement(_react.Fragment, null, children) : null;
|
|
46
34
|
};
|
|
47
|
-
|
|
48
35
|
exports.HasPermission = HasPermission;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["HasPermission","children","props","useSecurity","getPermission","any","all","Error","name","permissions","map","hasPermission","some","p","Boolean","every"],"sources":["HasPermission.tsx"],"sourcesContent":["import React, { Fragment } from \"react\";\nimport { useSecurity } from \"~/hooks/useSecurity\";\n\ninterface HasPermissionProps {\n any?: string[];\n all?: string[];\n name?: string;\n children: React.ReactNode;\n}\n\nexport const HasPermission = ({ children, ...props }: HasPermissionProps) => {\n const { getPermission } = useSecurity();\n\n if (props.any && props.all) {\n throw new Error(`You can use either \"any\" or \"all\", but not both at the same time.`);\n }\n\n if (props.name) {\n return getPermission(props.name) ? <Fragment>{children}</Fragment> : null;\n }\n\n const permissions = [...(props.any || []), ...(props.all || [])].map(name =>\n getPermission(name)\n );\n\n const hasPermission = props.any\n ? permissions.some(p => Boolean(p))\n : permissions.every(p => Boolean(p));\n\n return hasPermission ? <Fragment>{children}</Fragment> : null;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["HasPermission","children","props","useSecurity","getPermission","any","all","Error","name","permissions","map","hasPermission","some","p","Boolean","every"],"sources":["HasPermission.tsx"],"sourcesContent":["import React, { Fragment } from \"react\";\nimport { useSecurity } from \"~/hooks/useSecurity\";\n\ninterface HasPermissionProps {\n any?: string[];\n all?: string[];\n name?: string;\n children: React.ReactNode;\n}\n\nexport const HasPermission = ({ children, ...props }: HasPermissionProps) => {\n const { getPermission } = useSecurity();\n\n if (props.any && props.all) {\n throw new Error(`You can use either \"any\" or \"all\", but not both at the same time.`);\n }\n\n if (props.name) {\n return getPermission(props.name) ? <Fragment>{children}</Fragment> : null;\n }\n\n const permissions = [...(props.any || []), ...(props.all || [])].map(name =>\n getPermission(name)\n );\n\n const hasPermission = props.any\n ? permissions.some(p => Boolean(p))\n : permissions.every(p => Boolean(p));\n\n return hasPermission ? <Fragment>{children}</Fragment> : null;\n};\n"],"mappings":";;;;;;;;;;AAAA;AACA;AAAkD;AAS3C,IAAMA,aAAa,GAAG,SAAhBA,aAAa,OAAmD;EAAA,IAA7CC,QAAQ,QAARA,QAAQ;IAAKC,KAAK;EAC9C,mBAA0B,IAAAC,yBAAW,GAAE;IAA/BC,aAAa,gBAAbA,aAAa;EAErB,IAAIF,KAAK,CAACG,GAAG,IAAIH,KAAK,CAACI,GAAG,EAAE;IACxB,MAAM,IAAIC,KAAK,yEAAqE;EACxF;EAEA,IAAIL,KAAK,CAACM,IAAI,EAAE;IACZ,OAAOJ,aAAa,CAACF,KAAK,CAACM,IAAI,CAAC,gBAAG,6BAAC,eAAQ,QAAEP,QAAQ,CAAY,GAAG,IAAI;EAC7E;EAEA,IAAMQ,WAAW,GAAG,2CAAKP,KAAK,CAACG,GAAG,IAAI,EAAE,oCAAOH,KAAK,CAACI,GAAG,IAAI,EAAE,GAAGI,GAAG,CAAC,UAAAF,IAAI;IAAA,OACrEJ,aAAa,CAACI,IAAI,CAAC;EAAA,EACtB;EAED,IAAMG,aAAa,GAAGT,KAAK,CAACG,GAAG,GACzBI,WAAW,CAACG,IAAI,CAAC,UAAAC,CAAC;IAAA,OAAIC,OAAO,CAACD,CAAC,CAAC;EAAA,EAAC,GACjCJ,WAAW,CAACM,KAAK,CAAC,UAAAF,CAAC;IAAA,OAAIC,OAAO,CAACD,CAAC,CAAC;EAAA,EAAC;EAExC,OAAOF,aAAa,gBAAG,6BAAC,eAAQ,QAAEV,QAAQ,CAAY,GAAG,IAAI;AACjE,CAAC;AAAC"}
|
|
@@ -4,44 +4,31 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _useSecurity = require("../hooks/useSecurity");
|
|
9
|
-
|
|
10
8
|
var _plugins = require("@webiny/plugins");
|
|
11
|
-
|
|
12
9
|
var _default = function _default(_ref) {
|
|
13
10
|
var children = _ref.children,
|
|
14
|
-
|
|
11
|
+
permission = _ref.permission;
|
|
15
12
|
var security = (0, _useSecurity.useSecurity)();
|
|
16
|
-
|
|
17
13
|
if (!security) {
|
|
18
14
|
return null;
|
|
19
15
|
}
|
|
20
|
-
|
|
21
16
|
var identity = security.identity,
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
getPermission = security.getPermission;
|
|
24
18
|
if (!identity) {
|
|
25
19
|
return null;
|
|
26
20
|
}
|
|
27
|
-
|
|
28
21
|
var hasPermission = false;
|
|
29
|
-
|
|
30
22
|
if (identity) {
|
|
31
23
|
hasPermission = permission ? Boolean(getPermission(permission)) : true;
|
|
32
24
|
}
|
|
33
|
-
|
|
34
25
|
if (hasPermission) {
|
|
35
26
|
return children;
|
|
36
27
|
}
|
|
37
|
-
|
|
38
28
|
var plugin = _plugins.plugins.byName("secure-route-error");
|
|
39
|
-
|
|
40
29
|
if (!plugin) {
|
|
41
30
|
return null;
|
|
42
31
|
}
|
|
43
|
-
|
|
44
32
|
return plugin.render();
|
|
45
33
|
};
|
|
46
|
-
|
|
47
34
|
exports.default = _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["children","permission","security","useSecurity","identity","getPermission","hasPermission","Boolean","plugin","plugins","byName","render"],"sources":["SecureRoute.tsx"],"sourcesContent":["import React from \"react\";\nimport { useSecurity } from \"~/hooks/useSecurity\";\nimport { SecureRouteErrorPlugin } from \"~/types\";\nimport { plugins } from \"@webiny/plugins\";\n\ninterface SecureRouteProps {\n children: React.ReactNode;\n permission?: string;\n}\nexport default ({ children, permission }: SecureRouteProps): React.ReactElement | null => {\n const security = useSecurity();\n\n if (!security) {\n return null;\n }\n\n const { identity, getPermission } = security;\n\n if (!identity) {\n return null;\n }\n\n let hasPermission = false;\n if (identity) {\n hasPermission = permission ? Boolean(getPermission(permission)) : true;\n }\n\n if (hasPermission) {\n return children as unknown as React.ReactElement;\n }\n\n const plugin = plugins.byName<SecureRouteErrorPlugin>(\"secure-route-error\");\n if (!plugin) {\n return null;\n }\n\n return plugin.render();\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["children","permission","security","useSecurity","identity","getPermission","hasPermission","Boolean","plugin","plugins","byName","render"],"sources":["SecureRoute.tsx"],"sourcesContent":["import React from \"react\";\nimport { useSecurity } from \"~/hooks/useSecurity\";\nimport { SecureRouteErrorPlugin } from \"~/types\";\nimport { plugins } from \"@webiny/plugins\";\n\ninterface SecureRouteProps {\n children: React.ReactNode;\n permission?: string;\n}\nexport default ({ children, permission }: SecureRouteProps): React.ReactElement | null => {\n const security = useSecurity();\n\n if (!security) {\n return null;\n }\n\n const { identity, getPermission } = security;\n\n if (!identity) {\n return null;\n }\n\n let hasPermission = false;\n if (identity) {\n hasPermission = permission ? Boolean(getPermission(permission)) : true;\n }\n\n if (hasPermission) {\n return children as unknown as React.ReactElement;\n }\n\n const plugin = plugins.byName<SecureRouteErrorPlugin>(\"secure-route-error\");\n if (!plugin) {\n return null;\n }\n\n return plugin.render();\n};\n"],"mappings":";;;;;;AACA;AAEA;AAA0C,eAM3B,wBAA2E;EAAA,IAAxEA,QAAQ,QAARA,QAAQ;IAAEC,UAAU,QAAVA,UAAU;EAClC,IAAMC,QAAQ,GAAG,IAAAC,wBAAW,GAAE;EAE9B,IAAI,CAACD,QAAQ,EAAE;IACX,OAAO,IAAI;EACf;EAEA,IAAQE,QAAQ,GAAoBF,QAAQ,CAApCE,QAAQ;IAAEC,aAAa,GAAKH,QAAQ,CAA1BG,aAAa;EAE/B,IAAI,CAACD,QAAQ,EAAE;IACX,OAAO,IAAI;EACf;EAEA,IAAIE,aAAa,GAAG,KAAK;EACzB,IAAIF,QAAQ,EAAE;IACVE,aAAa,GAAGL,UAAU,GAAGM,OAAO,CAACF,aAAa,CAACJ,UAAU,CAAC,CAAC,GAAG,IAAI;EAC1E;EAEA,IAAIK,aAAa,EAAE;IACf,OAAON,QAAQ;EACnB;EAEA,IAAMQ,MAAM,GAAGC,gBAAO,CAACC,MAAM,CAAyB,oBAAoB,CAAC;EAC3E,IAAI,CAACF,MAAM,EAAE;IACT,OAAO,IAAI;EACf;EAEA,OAAOA,MAAM,CAACG,MAAM,EAAE;AAC1B,CAAC;AAAA"}
|
package/components/SecureView.js
CHANGED
|
@@ -4,33 +4,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _useSecurity2 = require("../hooks/useSecurity");
|
|
9
|
-
|
|
10
8
|
function SecureView(_ref) {
|
|
11
9
|
var children = _ref.children,
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
permission = _ref.permission;
|
|
14
11
|
var _useSecurity = (0, _useSecurity2.useSecurity)(),
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
getPermission = _useSecurity.getPermission;
|
|
17
13
|
var hasPermission = false;
|
|
18
14
|
var matchedPermission = null;
|
|
19
|
-
|
|
20
15
|
if (permission) {
|
|
21
16
|
matchedPermission = getPermission(permission);
|
|
22
17
|
hasPermission = Boolean(matchedPermission);
|
|
23
18
|
}
|
|
24
|
-
|
|
25
19
|
if (typeof children === "function") {
|
|
26
20
|
return children({
|
|
27
21
|
hasPermission: hasPermission,
|
|
28
22
|
permission: matchedPermission
|
|
29
23
|
});
|
|
30
24
|
}
|
|
31
|
-
|
|
32
25
|
return hasPermission ? children : null;
|
|
33
26
|
}
|
|
34
|
-
|
|
35
27
|
var _default = SecureView;
|
|
36
28
|
exports.default = _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["SecureView","children","permission","useSecurity","getPermission","hasPermission","matchedPermission","Boolean"],"sources":["SecureView.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { useSecurity } from \"~/hooks/useSecurity\";\nimport { SecurityPermission } from \"~/types\";\n\ninterface ChildrenRenderFunctionArgs<T extends SecurityPermission> {\n hasPermission: boolean;\n permission: T | null;\n}\n\ninterface Props<T extends SecurityPermission> {\n children: ((args: ChildrenRenderFunctionArgs<T>) => React.ReactElement) | React.ReactElement;\n permission?: string;\n}\n\nfunction SecureView<T extends SecurityPermission>({\n children,\n permission\n}: Props<T>): React.ReactElement | null {\n const { getPermission } = useSecurity();\n\n let hasPermission = false;\n let matchedPermission: T | null = null;\n if (permission) {\n matchedPermission = getPermission<T>(permission);\n hasPermission = Boolean(matchedPermission);\n }\n\n if (typeof children === \"function\") {\n return children({\n hasPermission,\n permission: matchedPermission\n });\n }\n\n return hasPermission ? children : null;\n}\n\nexport default SecureView;\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["SecureView","children","permission","useSecurity","getPermission","hasPermission","matchedPermission","Boolean"],"sources":["SecureView.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { useSecurity } from \"~/hooks/useSecurity\";\nimport { SecurityPermission } from \"~/types\";\n\ninterface ChildrenRenderFunctionArgs<T extends SecurityPermission> {\n hasPermission: boolean;\n permission: T | null;\n}\n\ninterface Props<T extends SecurityPermission> {\n children: ((args: ChildrenRenderFunctionArgs<T>) => React.ReactElement) | React.ReactElement;\n permission?: string;\n}\n\nfunction SecureView<T extends SecurityPermission>({\n children,\n permission\n}: Props<T>): React.ReactElement | null {\n const { getPermission } = useSecurity();\n\n let hasPermission = false;\n let matchedPermission: T | null = null;\n if (permission) {\n matchedPermission = getPermission<T>(permission);\n hasPermission = Boolean(matchedPermission);\n }\n\n if (typeof children === \"function\") {\n return children({\n hasPermission,\n permission: matchedPermission\n });\n }\n\n return hasPermission ? children : null;\n}\n\nexport default SecureView;\n"],"mappings":";;;;;;AACA;AAaA,SAASA,UAAU,OAGqB;EAAA,IAFpCC,QAAQ,QAARA,QAAQ;IACRC,UAAU,QAAVA,UAAU;EAEV,mBAA0B,IAAAC,yBAAW,GAAE;IAA/BC,aAAa,gBAAbA,aAAa;EAErB,IAAIC,aAAa,GAAG,KAAK;EACzB,IAAIC,iBAA2B,GAAG,IAAI;EACtC,IAAIJ,UAAU,EAAE;IACZI,iBAAiB,GAAGF,aAAa,CAAIF,UAAU,CAAC;IAChDG,aAAa,GAAGE,OAAO,CAACD,iBAAiB,CAAC;EAC9C;EAEA,IAAI,OAAOL,QAAQ,KAAK,UAAU,EAAE;IAChC,OAAOA,QAAQ,CAAC;MACZI,aAAa,EAAbA,aAAa;MACbH,UAAU,EAAEI;IAChB,CAAC,CAAC;EACN;EAEA,OAAOD,aAAa,GAAGJ,QAAQ,GAAG,IAAI;AAC1C;AAAC,eAEcD,UAAU;AAAA"}
|
package/components/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
@@ -23,9 +22,6 @@ Object.defineProperty(exports, "SecureView", {
|
|
|
23
22
|
return _SecureView.default;
|
|
24
23
|
}
|
|
25
24
|
});
|
|
26
|
-
|
|
27
25
|
var _SecureView = _interopRequireDefault(require("./SecureView"));
|
|
28
|
-
|
|
29
26
|
var _SecureRoute = _interopRequireDefault(require("./SecureRoute"));
|
|
30
|
-
|
|
31
27
|
var _HasPermission = require("./HasPermission");
|
package/components/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { default as SecureView } from \"./SecureView\";\nexport { default as SecureRoute } from \"./SecureRoute\";\nexport { HasPermission } from \"./HasPermission\";\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { default as SecureView } from \"./SecureView\";\nexport { default as SecureRoute } from \"./SecureRoute\";\nexport { HasPermission } from \"./HasPermission\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA"}
|
package/contexts/Security.js
CHANGED
|
@@ -1,22 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
-
|
|
5
4
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
6
|
-
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
8
|
exports.SecurityProvider = exports.SecurityContext = void 0;
|
|
11
|
-
|
|
12
9
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
13
|
-
|
|
14
10
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
15
|
-
|
|
16
11
|
var _minimatch = _interopRequireDefault(require("minimatch"));
|
|
17
|
-
|
|
18
12
|
var _react = _interopRequireWildcard(require("react"));
|
|
19
|
-
|
|
20
13
|
var SecurityContext = /*#__PURE__*/_react.default.createContext({
|
|
21
14
|
identity: null,
|
|
22
15
|
setIdentity: function setIdentity() {
|
|
@@ -26,30 +19,25 @@ var SecurityContext = /*#__PURE__*/_react.default.createContext({
|
|
|
26
19
|
return null;
|
|
27
20
|
}
|
|
28
21
|
});
|
|
29
|
-
|
|
30
22
|
exports.SecurityContext = SecurityContext;
|
|
31
|
-
|
|
32
23
|
var SecurityProvider = function SecurityProvider(props) {
|
|
33
24
|
var _useState = (0, _react.useState)(null),
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
25
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
26
|
+
identity = _useState2[0],
|
|
27
|
+
setIdentity = _useState2[1];
|
|
38
28
|
var getPermission = (0, _react.useCallback)(function (name) {
|
|
39
29
|
if (!identity) {
|
|
40
30
|
return null;
|
|
41
31
|
}
|
|
42
|
-
|
|
43
32
|
var perms = identity.permissions || [];
|
|
44
33
|
var exactMatch = perms.find(function (p) {
|
|
45
34
|
return p.name === name;
|
|
46
35
|
});
|
|
47
|
-
|
|
48
36
|
if (exactMatch) {
|
|
49
37
|
return exactMatch;
|
|
50
|
-
}
|
|
51
|
-
|
|
38
|
+
}
|
|
52
39
|
|
|
40
|
+
// Try matching using patterns
|
|
53
41
|
return perms.find(function (p) {
|
|
54
42
|
return (0, _minimatch.default)(name, p.name);
|
|
55
43
|
});
|
|
@@ -68,5 +56,4 @@ var SecurityProvider = function SecurityProvider(props) {
|
|
|
68
56
|
value: value
|
|
69
57
|
}, props.children);
|
|
70
58
|
};
|
|
71
|
-
|
|
72
59
|
exports.SecurityProvider = SecurityProvider;
|
package/contexts/Security.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["SecurityContext","React","createContext","identity","setIdentity","getPermission","SecurityProvider","props","useState","useCallback","name","perms","permissions","exactMatch","find","p","minimatch","value","useMemo","children"],"sources":["Security.tsx"],"sourcesContent":["import minimatch from \"minimatch\";\nimport React, { useState, useMemo, Dispatch, SetStateAction, useCallback } from \"react\";\nimport { SecurityIdentity, SecurityPermission } from \"~/types\";\n\nexport interface SecurityContext {\n identity: SecurityIdentity | null;\n setIdentity: Dispatch<SetStateAction<SecurityIdentity | null>>;\n getPermission<T extends SecurityPermission = SecurityPermission>(name: string): T | null;\n}\n\nexport const SecurityContext = React.createContext<SecurityContext>({\n identity: null,\n setIdentity: () => {\n return void 0;\n },\n getPermission: () => {\n return null;\n }\n});\n\nexport const SecurityProvider: React.FC = props => {\n const [identity, setIdentity] = useState<SecurityIdentity | null>(null);\n\n const getPermission = useCallback(\n <T extends SecurityPermission = SecurityPermission>(name: string): T | null => {\n if (!identity) {\n return null;\n }\n\n const perms = identity.permissions || [];\n const exactMatch = perms.find(p => p.name === name);\n if (exactMatch) {\n return exactMatch as T;\n }\n\n // Try matching using patterns\n return perms.find(p => minimatch(name, p.name)) as any;\n },\n [identity]\n );\n\n const value = useMemo(() => {\n return {\n identity: identity\n ? {\n ...identity,\n // For backwards compatibility, expose the `getPermission` method on the `identity` object.\n getPermission\n }\n : null,\n setIdentity,\n getPermission\n };\n }, [identity]);\n\n return <SecurityContext.Provider value={value}>{props.children}</SecurityContext.Provider>;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["SecurityContext","React","createContext","identity","setIdentity","getPermission","SecurityProvider","props","useState","useCallback","name","perms","permissions","exactMatch","find","p","minimatch","value","useMemo","children"],"sources":["Security.tsx"],"sourcesContent":["import minimatch from \"minimatch\";\nimport React, { useState, useMemo, Dispatch, SetStateAction, useCallback } from \"react\";\nimport { SecurityIdentity, SecurityPermission } from \"~/types\";\n\nexport interface SecurityContext {\n identity: SecurityIdentity | null;\n setIdentity: Dispatch<SetStateAction<SecurityIdentity | null>>;\n getPermission<T extends SecurityPermission = SecurityPermission>(name: string): T | null;\n}\n\nexport const SecurityContext = React.createContext<SecurityContext>({\n identity: null,\n setIdentity: () => {\n return void 0;\n },\n getPermission: () => {\n return null;\n }\n});\n\nexport const SecurityProvider: React.FC = props => {\n const [identity, setIdentity] = useState<SecurityIdentity | null>(null);\n\n const getPermission = useCallback(\n <T extends SecurityPermission = SecurityPermission>(name: string): T | null => {\n if (!identity) {\n return null;\n }\n\n const perms = identity.permissions || [];\n const exactMatch = perms.find(p => p.name === name);\n if (exactMatch) {\n return exactMatch as T;\n }\n\n // Try matching using patterns\n return perms.find(p => minimatch(name, p.name)) as any;\n },\n [identity]\n );\n\n const value = useMemo(() => {\n return {\n identity: identity\n ? {\n ...identity,\n // For backwards compatibility, expose the `getPermission` method on the `identity` object.\n getPermission\n }\n : null,\n setIdentity,\n getPermission\n };\n }, [identity]);\n\n return <SecurityContext.Provider value={value}>{props.children}</SecurityContext.Provider>;\n};\n"],"mappings":";;;;;;;;;;AAAA;AACA;AASO,IAAMA,eAAe,gBAAGC,cAAK,CAACC,aAAa,CAAkB;EAChEC,QAAQ,EAAE,IAAI;EACdC,WAAW,EAAE,uBAAM;IACf,OAAO,KAAK,CAAC;EACjB,CAAC;EACDC,aAAa,EAAE,yBAAM;IACjB,OAAO,IAAI;EACf;AACJ,CAAC,CAAC;AAAC;AAEI,IAAMC,gBAA0B,GAAG,SAA7BA,gBAA0B,CAAGC,KAAK,EAAI;EAC/C,gBAAgC,IAAAC,eAAQ,EAA0B,IAAI,CAAC;IAAA;IAAhEL,QAAQ;IAAEC,WAAW;EAE5B,IAAMC,aAAa,GAAG,IAAAI,kBAAW,EAC7B,UAAoDC,IAAY,EAAe;IAC3E,IAAI,CAACP,QAAQ,EAAE;MACX,OAAO,IAAI;IACf;IAEA,IAAMQ,KAAK,GAAGR,QAAQ,CAACS,WAAW,IAAI,EAAE;IACxC,IAAMC,UAAU,GAAGF,KAAK,CAACG,IAAI,CAAC,UAAAC,CAAC;MAAA,OAAIA,CAAC,CAACL,IAAI,KAAKA,IAAI;IAAA,EAAC;IACnD,IAAIG,UAAU,EAAE;MACZ,OAAOA,UAAU;IACrB;;IAEA;IACA,OAAOF,KAAK,CAACG,IAAI,CAAC,UAAAC,CAAC;MAAA,OAAI,IAAAC,kBAAS,EAACN,IAAI,EAAEK,CAAC,CAACL,IAAI,CAAC;IAAA,EAAC;EACnD,CAAC,EACD,CAACP,QAAQ,CAAC,CACb;EAED,IAAMc,KAAK,GAAG,IAAAC,cAAO,EAAC,YAAM;IACxB,OAAO;MACHf,QAAQ,EAAEA,QAAQ,+DAELA,QAAQ;QACX;QACAE,aAAa,EAAbA;MAAa,KAEjB,IAAI;MACVD,WAAW,EAAXA,WAAW;MACXC,aAAa,EAAbA;IACJ,CAAC;EACL,CAAC,EAAE,CAACF,QAAQ,CAAC,CAAC;EAEd,oBAAO,6BAAC,eAAe,CAAC,QAAQ;IAAC,KAAK,EAAEc;EAAM,GAAEV,KAAK,CAACY,QAAQ,CAA4B;AAC9F,CAAC;AAAC"}
|
package/hooks/usePermission.js
CHANGED
|
@@ -4,12 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.usePermission = usePermission;
|
|
7
|
-
|
|
8
7
|
var _useSecurity2 = require("./useSecurity");
|
|
9
|
-
|
|
10
8
|
function usePermission(name) {
|
|
11
9
|
var _useSecurity = (0, _useSecurity2.useSecurity)(),
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
getPermission = _useSecurity.getPermission;
|
|
14
11
|
return getPermission(name);
|
|
15
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["usePermission","name","useSecurity","getPermission"],"sources":["usePermission.ts"],"sourcesContent":["import { useSecurity } from \"~/hooks/useSecurity\";\nimport { SecurityPermission } from \"~/types\";\n\nexport function usePermission<T extends SecurityPermission = SecurityPermission>(name: string) {\n const { getPermission } = useSecurity();\n return getPermission<T>(name);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["usePermission","name","useSecurity","getPermission"],"sources":["usePermission.ts"],"sourcesContent":["import { useSecurity } from \"~/hooks/useSecurity\";\nimport { SecurityPermission } from \"~/types\";\n\nexport function usePermission<T extends SecurityPermission = SecurityPermission>(name: string) {\n const { getPermission } = useSecurity();\n return getPermission<T>(name);\n}\n"],"mappings":";;;;;;AAAA;AAGO,SAASA,aAAa,CAAoDC,IAAY,EAAE;EAC3F,mBAA0B,IAAAC,yBAAW,GAAE;IAA/BC,aAAa,gBAAbA,aAAa;EACrB,OAAOA,aAAa,CAAIF,IAAI,CAAC;AACjC"}
|
package/hooks/useSecurity.js
CHANGED
|
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.useSecurity = useSecurity;
|
|
7
|
-
|
|
8
7
|
var _react = require("react");
|
|
9
|
-
|
|
10
8
|
var _Security = require("../contexts/Security");
|
|
11
|
-
|
|
12
9
|
function useSecurity() {
|
|
13
10
|
return (0, _react.useContext)(_Security.SecurityContext);
|
|
14
11
|
}
|
package/hooks/useSecurity.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useSecurity","useContext","SecurityContext"],"sources":["useSecurity.ts"],"sourcesContent":["import { useContext } from \"react\";\nimport { SecurityContext } from \"~/contexts/Security\";\n\nexport function useSecurity() {\n return useContext(SecurityContext);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["useSecurity","useContext","SecurityContext"],"sources":["useSecurity.ts"],"sourcesContent":["import { useContext } from \"react\";\nimport { SecurityContext } from \"~/contexts/Security\";\n\nexport function useSecurity() {\n return useContext(SecurityContext);\n}\n"],"mappings":";;;;;;AAAA;AACA;AAEO,SAASA,WAAW,GAAG;EAC1B,OAAO,IAAAC,iBAAU,EAACC,yBAAe,CAAC;AACtC"}
|
package/index.js
CHANGED
|
@@ -12,9 +12,7 @@ Object.defineProperty(exports, "SecurityContext", {
|
|
|
12
12
|
return _Security.SecurityContext;
|
|
13
13
|
}
|
|
14
14
|
});
|
|
15
|
-
|
|
16
15
|
var _components = require("./components");
|
|
17
|
-
|
|
18
16
|
Object.keys(_components).forEach(function (key) {
|
|
19
17
|
if (key === "default" || key === "__esModule") return;
|
|
20
18
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -26,9 +24,7 @@ Object.keys(_components).forEach(function (key) {
|
|
|
26
24
|
}
|
|
27
25
|
});
|
|
28
26
|
});
|
|
29
|
-
|
|
30
27
|
var _Security = require("./contexts/Security");
|
|
31
|
-
|
|
32
28
|
Object.keys(_Security).forEach(function (key) {
|
|
33
29
|
if (key === "default" || key === "__esModule") return;
|
|
34
30
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -40,9 +36,7 @@ Object.keys(_Security).forEach(function (key) {
|
|
|
40
36
|
}
|
|
41
37
|
});
|
|
42
38
|
});
|
|
43
|
-
|
|
44
39
|
var _useSecurity = require("./hooks/useSecurity");
|
|
45
|
-
|
|
46
40
|
Object.keys(_useSecurity).forEach(function (key) {
|
|
47
41
|
if (key === "default" || key === "__esModule") return;
|
|
48
42
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -54,9 +48,7 @@ Object.keys(_useSecurity).forEach(function (key) {
|
|
|
54
48
|
}
|
|
55
49
|
});
|
|
56
50
|
});
|
|
57
|
-
|
|
58
51
|
var _usePermission = require("./hooks/usePermission");
|
|
59
|
-
|
|
60
52
|
Object.keys(_usePermission).forEach(function (key) {
|
|
61
53
|
if (key === "default" || key === "__esModule") return;
|
|
62
54
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -68,9 +60,7 @@ Object.keys(_usePermission).forEach(function (key) {
|
|
|
68
60
|
}
|
|
69
61
|
});
|
|
70
62
|
});
|
|
71
|
-
|
|
72
63
|
var _Security2 = require("./Security");
|
|
73
|
-
|
|
74
64
|
Object.keys(_Security2).forEach(function (key) {
|
|
75
65
|
if (key === "default" || key === "__esModule") return;
|
|
76
66
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./components\";\nexport * from \"./contexts/Security\";\nexport { SecurityContext } from \"./contexts/Security\";\nexport * from \"./hooks/useSecurity\";\nexport * from \"./hooks/usePermission\";\nexport * from \"./Security\";\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./components\";\nexport * from \"./contexts/Security\";\nexport { SecurityContext } from \"./contexts/Security\";\nexport * from \"./hooks/useSecurity\";\nexport * from \"./hooks/usePermission\";\nexport * from \"./Security\";\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AAEA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/app-security",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.35.0-beta.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
],
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@webiny/app": "5.
|
|
17
|
-
"@webiny/plugins": "5.
|
|
18
|
-
"minimatch": "5.1.
|
|
16
|
+
"@webiny/app": "5.35.0-beta.0",
|
|
17
|
+
"@webiny/plugins": "5.35.0-beta.0",
|
|
18
|
+
"minimatch": "5.1.6",
|
|
19
19
|
"react": "17.0.2",
|
|
20
20
|
"react-dom": "17.0.2"
|
|
21
21
|
},
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"@babel/preset-env": "^7.19.4",
|
|
27
27
|
"@babel/preset-react": "^7.16.0",
|
|
28
28
|
"@babel/preset-typescript": "^7.18.6",
|
|
29
|
-
"@webiny/cli": "^5.
|
|
30
|
-
"@webiny/project-utils": "^5.
|
|
29
|
+
"@webiny/cli": "^5.35.0-beta.0",
|
|
30
|
+
"@webiny/project-utils": "^5.35.0-beta.0",
|
|
31
31
|
"babel-plugin-emotion": "^9.2.8",
|
|
32
32
|
"babel-plugin-lodash": "^3.3.4",
|
|
33
33
|
"rimraf": "^3.0.2",
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
]
|
|
50
50
|
}
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "8acc9e8892842cabb3980ce0b6432fde55968d5b"
|
|
53
53
|
}
|