@webiny/app-security 5.24.0 → 5.25.0-beta.2
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/Security.d.ts +2 -2
- package/Security.js +7 -1
- package/Security.js.map +1 -0
- package/components/HasPermission.d.ts +1 -1
- package/components/HasPermission.js.map +1 -0
- package/components/SecureRoute.d.ts +5 -4
- package/components/SecureRoute.js +3 -2
- package/components/SecureRoute.js.map +1 -0
- package/components/SecureView.d.ts +2 -2
- package/components/SecureView.js +3 -3
- package/components/SecureView.js.map +1 -0
- package/components/index.js.map +1 -0
- package/contexts/Security.d.ts +2 -2
- package/contexts/Security.js +9 -1
- package/contexts/Security.js.map +1 -0
- package/hooks/usePermission.d.ts +1 -1
- package/hooks/usePermission.js.map +1 -0
- package/hooks/useSecurity.js.map +1 -0
- package/index.js.map +1 -0
- package/package.json +9 -9
- package/types.d.ts +19 -2
- package/types.js.map +1 -0
package/Security.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const Security:
|
|
1
|
+
import React from "react";
|
|
2
|
+
export declare const Security: React.FC;
|
package/Security.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Importing from `app-admin-core` and NOT from `app-admin`, to avoid circular dependency.
|
|
2
2
|
// This can be resolved in a different way, by changing the location of `AppInstaller` component (currently in `app-admin`).
|
|
3
3
|
// But this is a faster solution, as I'm really short on time :)
|
|
4
|
-
import { Provider } from "@webiny/app-admin-core";
|
|
5
4
|
import React from "react";
|
|
5
|
+
import { Provider } from "@webiny/app-admin-core";
|
|
6
6
|
import { SecurityProvider as ContextProvider } from "./contexts/Security";
|
|
7
7
|
|
|
8
8
|
var SecurityProviderHOC = function SecurityProviderHOC(Component) {
|
|
@@ -13,6 +13,12 @@ var SecurityProviderHOC = function SecurityProviderHOC(Component) {
|
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
export var Security = function Security() {
|
|
16
|
+
/**
|
|
17
|
+
* TODO @ts-refactor somewhere down the line in Provider.
|
|
18
|
+
* Provider expects ComponentType and we are giving it the React.FC.
|
|
19
|
+
* It works, just the types are wrong.
|
|
20
|
+
*/
|
|
21
|
+
// @ts-ignore
|
|
16
22
|
return /*#__PURE__*/React.createElement(Provider, {
|
|
17
23
|
hoc: SecurityProviderHOC
|
|
18
24
|
});
|
package/Security.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["Security.tsx"],"names":["React","Provider","SecurityProvider","ContextProvider","SecurityProviderHOC","Component","children","Security"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,KAAP,MAAkB,OAAlB;AACA,SAASC,QAAT,QAAyB,wBAAzB;AACA,SAASC,gBAAgB,IAAIC,eAA7B;;AAEA,IAAMC,mBAAmB,GAAG,SAAtBA,mBAAsB,CAACC,SAAD,EAA6C;AACrE,SAAO,SAASH,gBAAT,OAAwC;AAAA,QAAZI,QAAY,QAAZA,QAAY;AAC3C,wBACI,oBAAC,eAAD,qBACI,oBAAC,SAAD,QAAYA,QAAZ,CADJ,CADJ;AAKH,GAND;AAOH,CARD;;AAUA,OAAO,IAAMC,QAAkB,GAAG,SAArBA,QAAqB,GAAM;AACpC;AACJ;AACA;AACA;AACA;AACI;AACA,sBAAO,oBAAC,QAAD;AAAU,IAAA,GAAG,EAAEH;AAAf,IAAP;AACH,CARM","sourcesContent":["// Importing from `app-admin-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-admin-core\";\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 /**\n * TODO @ts-refactor somewhere down the line in Provider.\n * Provider expects ComponentType and we are giving it the React.FC.\n * It works, just the types are wrong.\n */\n // @ts-ignore\n return <Provider hoc={SecurityProviderHOC} />;\n};\n"]}
|
|
@@ -5,5 +5,5 @@ interface HasPermissionProps {
|
|
|
5
5
|
name?: string;
|
|
6
6
|
children: React.ReactNode;
|
|
7
7
|
}
|
|
8
|
-
export declare const HasPermission: ({ children, ...props }: HasPermissionProps) => JSX.Element;
|
|
8
|
+
export declare const HasPermission: ({ children, ...props }: HasPermissionProps) => JSX.Element | null;
|
|
9
9
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["HasPermission.tsx"],"names":["React","Fragment","useSecurity","HasPermission","children","props","getPermission","any","all","Error","name","permissions","map","hasPermission","some","p","Boolean","every"],"mappings":";;;AAAA,OAAOA,KAAP,IAAgBC,QAAhB,QAAgC,OAAhC;AACA,SAASC,WAAT;AASA,OAAO,IAAMC,aAAa,GAAG,SAAhBA,aAAgB,OAAgD;AAAA,MAA7CC,QAA6C,QAA7CA,QAA6C;AAAA,MAAhCC,KAAgC;;AACzE,qBAA0BH,WAAW,EAArC;AAAA,MAAQI,aAAR,gBAAQA,aAAR;;AAEA,MAAID,KAAK,CAACE,GAAN,IAAaF,KAAK,CAACG,GAAvB,EAA4B;AACxB,UAAM,IAAIC,KAAJ,yEAAN;AACH;;AAED,MAAIJ,KAAK,CAACK,IAAV,EAAgB;AACZ,WAAOJ,aAAa,CAACD,KAAK,CAACK,IAAP,CAAb,gBAA4B,oBAAC,QAAD,QAAWN,QAAX,CAA5B,GAA8D,IAArE;AACH;;AAED,MAAMO,WAAW,GAAG,6BAAKN,KAAK,CAACE,GAAN,IAAa,EAAlB,sBAA2BF,KAAK,CAACG,GAAN,IAAa,EAAxC,GAA6CI,GAA7C,CAAiD,UAAAF,IAAI;AAAA,WACrEJ,aAAa,CAACI,IAAD,CADwD;AAAA,GAArD,CAApB;AAIA,MAAMG,aAAa,GAAGR,KAAK,CAACE,GAAN,GAChBI,WAAW,CAACG,IAAZ,CAAiB,UAAAC,CAAC;AAAA,WAAIC,OAAO,CAACD,CAAD,CAAX;AAAA,GAAlB,CADgB,GAEhBJ,WAAW,CAACM,KAAZ,CAAkB,UAAAF,CAAC;AAAA,WAAIC,OAAO,CAACD,CAAD,CAAX;AAAA,GAAnB,CAFN;AAIA,SAAOF,aAAa,gBAAG,oBAAC,QAAD,QAAWT,QAAX,CAAH,GAAqC,IAAzD;AACH,CApBM","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"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
children:
|
|
1
|
+
import React from "react";
|
|
2
|
+
interface SecureRouteProps {
|
|
3
|
+
children: React.ReactNode;
|
|
4
4
|
permission?: string;
|
|
5
|
-
}
|
|
5
|
+
}
|
|
6
|
+
declare const _default: ({ children, permission }: SecureRouteProps) => React.ReactElement | null;
|
|
6
7
|
export default _default;
|
|
@@ -9,7 +9,8 @@ export default (function (_ref) {
|
|
|
9
9
|
return null;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
var identity = security.identity
|
|
12
|
+
var identity = security.identity,
|
|
13
|
+
getPermission = security.getPermission;
|
|
13
14
|
|
|
14
15
|
if (!identity) {
|
|
15
16
|
return null;
|
|
@@ -18,7 +19,7 @@ export default (function (_ref) {
|
|
|
18
19
|
var hasPermission = false;
|
|
19
20
|
|
|
20
21
|
if (identity) {
|
|
21
|
-
hasPermission = permission ? Boolean(
|
|
22
|
+
hasPermission = permission ? Boolean(getPermission(permission)) : true;
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
if (hasPermission) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["SecureRoute.tsx"],"names":["useSecurity","plugins","children","permission","security","identity","getPermission","hasPermission","Boolean","plugin","byName","render"],"mappings":"AACA,SAASA,WAAT;AAEA,SAASC,OAAT,QAAwB,iBAAxB;AAMA,gBAAe,gBAA2E;AAAA,MAAxEC,QAAwE,QAAxEA,QAAwE;AAAA,MAA9DC,UAA8D,QAA9DA,UAA8D;AACtF,MAAMC,QAAQ,GAAGJ,WAAW,EAA5B;;AAEA,MAAI,CAACI,QAAL,EAAe;AACX,WAAO,IAAP;AACH;;AAED,MAAQC,QAAR,GAAoCD,QAApC,CAAQC,QAAR;AAAA,MAAkBC,aAAlB,GAAoCF,QAApC,CAAkBE,aAAlB;;AAEA,MAAI,CAACD,QAAL,EAAe;AACX,WAAO,IAAP;AACH;;AAED,MAAIE,aAAa,GAAG,KAApB;;AACA,MAAIF,QAAJ,EAAc;AACVE,IAAAA,aAAa,GAAGJ,UAAU,GAAGK,OAAO,CAACF,aAAa,CAACH,UAAD,CAAd,CAAV,GAAwC,IAAlE;AACH;;AAED,MAAII,aAAJ,EAAmB;AACf,WAAOL,QAAP;AACH;;AAED,MAAMO,MAAM,GAAGR,OAAO,CAACS,MAAR,CAAuC,oBAAvC,CAAf;;AACA,MAAI,CAACD,MAAL,EAAa;AACT,WAAO,IAAP;AACH;;AAED,SAAOA,MAAM,CAACE,MAAP,EAAP;AACH,CA5BD","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"]}
|
|
@@ -2,11 +2,11 @@ import * as React from "react";
|
|
|
2
2
|
import { SecurityPermission } from "../types";
|
|
3
3
|
interface ChildrenRenderFunctionArgs<T extends SecurityPermission> {
|
|
4
4
|
hasPermission: boolean;
|
|
5
|
-
permission: T;
|
|
5
|
+
permission: T | null;
|
|
6
6
|
}
|
|
7
7
|
interface Props<T extends SecurityPermission> {
|
|
8
8
|
children: ((args: ChildrenRenderFunctionArgs<T>) => React.ReactElement) | React.ReactElement;
|
|
9
9
|
permission?: string;
|
|
10
10
|
}
|
|
11
|
-
declare function SecureView<T extends SecurityPermission>({ children, permission }: Props<T>): React.ReactElement;
|
|
11
|
+
declare function SecureView<T extends SecurityPermission>({ children, permission }: Props<T>): React.ReactElement | null;
|
|
12
12
|
export default SecureView;
|
package/components/SecureView.js
CHANGED
|
@@ -5,13 +5,13 @@ function SecureView(_ref) {
|
|
|
5
5
|
permission = _ref.permission;
|
|
6
6
|
|
|
7
7
|
var _useSecurity = useSecurity(),
|
|
8
|
-
|
|
8
|
+
getPermission = _useSecurity.getPermission;
|
|
9
9
|
|
|
10
10
|
var hasPermission = false;
|
|
11
11
|
var matchedPermission = null;
|
|
12
12
|
|
|
13
|
-
if (
|
|
14
|
-
matchedPermission =
|
|
13
|
+
if (permission) {
|
|
14
|
+
matchedPermission = getPermission(permission);
|
|
15
15
|
hasPermission = Boolean(matchedPermission);
|
|
16
16
|
}
|
|
17
17
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["SecureView.tsx"],"names":["useSecurity","SecureView","children","permission","getPermission","hasPermission","matchedPermission","Boolean"],"mappings":"AACA,SAASA,WAAT;;AAaA,SAASC,UAAT,OAGwC;AAAA,MAFpCC,QAEoC,QAFpCA,QAEoC;AAAA,MADpCC,UACoC,QADpCA,UACoC;;AACpC,qBAA0BH,WAAW,EAArC;AAAA,MAAQI,aAAR,gBAAQA,aAAR;;AAEA,MAAIC,aAAa,GAAG,KAApB;AACA,MAAIC,iBAA2B,GAAG,IAAlC;;AACA,MAAIH,UAAJ,EAAgB;AACZG,IAAAA,iBAAiB,GAAGF,aAAa,CAAID,UAAJ,CAAjC;AACAE,IAAAA,aAAa,GAAGE,OAAO,CAACD,iBAAD,CAAvB;AACH;;AAED,MAAI,OAAOJ,QAAP,KAAoB,UAAxB,EAAoC;AAChC,WAAOA,QAAQ,CAAC;AACZG,MAAAA,aAAa,EAAbA,aADY;AAEZF,MAAAA,UAAU,EAAEG;AAFA,KAAD,CAAf;AAIH;;AAED,SAAOD,aAAa,GAAGH,QAAH,GAAc,IAAlC;AACH;;AAED,eAAeD,UAAf","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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":["default","SecureView","SecureRoute","HasPermission"],"mappings":"AAAA,SAASA,OAAO,IAAIC,UAApB;AACA,SAASD,OAAO,IAAIE,WAApB;AACA,SAASC,aAAT","sourcesContent":["export { default as SecureView } from \"./SecureView\";\nexport { default as SecureRoute } from \"./SecureRoute\";\nexport { HasPermission } from \"./HasPermission\";\n"]}
|
package/contexts/Security.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import React, { Dispatch, SetStateAction } from "react";
|
|
|
2
2
|
import { SecurityIdentity, SecurityPermission } from "../types";
|
|
3
3
|
export interface SecurityContext {
|
|
4
4
|
identity: SecurityIdentity | null;
|
|
5
|
-
setIdentity: Dispatch<SetStateAction<SecurityIdentity>>;
|
|
6
|
-
getPermission<T extends SecurityPermission = SecurityPermission>(name: string): T;
|
|
5
|
+
setIdentity: Dispatch<SetStateAction<SecurityIdentity | null>>;
|
|
6
|
+
getPermission<T extends SecurityPermission = SecurityPermission>(name: string): T | null;
|
|
7
7
|
}
|
|
8
8
|
export declare const SecurityContext: React.Context<SecurityContext>;
|
|
9
9
|
export declare const SecurityProvider: React.FC;
|
package/contexts/Security.js
CHANGED
|
@@ -2,7 +2,15 @@ import _objectSpread from "@babel/runtime/helpers/objectSpread2";
|
|
|
2
2
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
3
|
import minimatch from "minimatch";
|
|
4
4
|
import React, { useState, useMemo, useCallback } from "react";
|
|
5
|
-
export var SecurityContext = /*#__PURE__*/React.createContext(
|
|
5
|
+
export var SecurityContext = /*#__PURE__*/React.createContext({
|
|
6
|
+
identity: null,
|
|
7
|
+
setIdentity: function setIdentity() {
|
|
8
|
+
return void 0;
|
|
9
|
+
},
|
|
10
|
+
getPermission: function getPermission() {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
6
14
|
export var SecurityProvider = function SecurityProvider(props) {
|
|
7
15
|
var _useState = useState(null),
|
|
8
16
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["Security.tsx"],"names":["minimatch","React","useState","useMemo","useCallback","SecurityContext","createContext","identity","setIdentity","getPermission","SecurityProvider","props","name","perms","permissions","exactMatch","find","p","value","children"],"mappings":";;AAAA,OAAOA,SAAP,MAAsB,WAAtB;AACA,OAAOC,KAAP,IAAgBC,QAAhB,EAA0BC,OAA1B,EAA6DC,WAA7D,QAAgF,OAAhF;AASA,OAAO,IAAMC,eAAe,gBAAGJ,KAAK,CAACK,aAAN,CAAqC;AAChEC,EAAAA,QAAQ,EAAE,IADsD;AAEhEC,EAAAA,WAAW,EAAE,uBAAM;AACf,WAAO,KAAK,CAAZ;AACH,GAJ+D;AAKhEC,EAAAA,aAAa,EAAE,yBAAM;AACjB,WAAO,IAAP;AACH;AAP+D,CAArC,CAAxB;AAUP,OAAO,IAAMC,gBAA0B,GAAG,SAA7BA,gBAA6B,CAAAC,KAAK,EAAI;AAC/C,kBAAgCT,QAAQ,CAA0B,IAA1B,CAAxC;AAAA;AAAA,MAAOK,QAAP;AAAA,MAAiBC,WAAjB;;AAEA,MAAMC,aAAa,GAAGL,WAAW,CAC7B,UAAoDQ,IAApD,EAA+E;AAC3E,QAAI,CAACL,QAAL,EAAe;AACX,aAAO,IAAP;AACH;;AAED,QAAMM,KAAK,GAAGN,QAAQ,CAACO,WAAT,IAAwB,EAAtC;AACA,QAAMC,UAAU,GAAGF,KAAK,CAACG,IAAN,CAAW,UAAAC,CAAC;AAAA,aAAIA,CAAC,CAACL,IAAF,KAAWA,IAAf;AAAA,KAAZ,CAAnB;;AACA,QAAIG,UAAJ,EAAgB;AACZ,aAAOA,UAAP;AACH,KAT0E,CAW3E;;;AACA,WAAOF,KAAK,CAACG,IAAN,CAAW,UAAAC,CAAC;AAAA,aAAIjB,SAAS,CAACY,IAAD,EAAOK,CAAC,CAACL,IAAT,CAAb;AAAA,KAAZ,CAAP;AACH,GAd4B,EAe7B,CAACL,QAAD,CAf6B,CAAjC;AAkBA,MAAMW,KAAK,GAAGf,OAAO,CAAC,YAAM;AACxB,WAAO;AACHI,MAAAA,QAAQ,EAAEA,QAAQ,mCAELA,QAFK;AAGR;AACAE,QAAAA,aAAa,EAAbA;AAJQ,WAMZ,IAPH;AAQHD,MAAAA,WAAW,EAAXA,WARG;AASHC,MAAAA,aAAa,EAAbA;AATG,KAAP;AAWH,GAZoB,EAYlB,CAACF,QAAD,CAZkB,CAArB;AAcA,sBAAO,oBAAC,eAAD,CAAiB,QAAjB;AAA0B,IAAA,KAAK,EAAEW;AAAjC,KAAyCP,KAAK,CAACQ,QAA/C,CAAP;AACH,CApCM","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"]}
|
package/hooks/usePermission.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { SecurityPermission } from "../types";
|
|
2
|
-
export declare function usePermission<T extends SecurityPermission = SecurityPermission>(name: string): T;
|
|
2
|
+
export declare function usePermission<T extends SecurityPermission = SecurityPermission>(name: string): T | null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["usePermission.ts"],"names":["useSecurity","usePermission","name","getPermission"],"mappings":"AAAA,SAASA,WAAT;AAGA,OAAO,SAASC,aAAT,CAA0EC,IAA1E,EAAwF;AAC3F,qBAA0BF,WAAW,EAArC;AAAA,MAAQG,aAAR,gBAAQA,aAAR;;AACA,SAAOA,aAAa,CAAID,IAAJ,CAApB;AACH","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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["useSecurity.ts"],"names":["useContext","SecurityContext","useSecurity"],"mappings":"AAAA,SAASA,UAAT,QAA2B,OAA3B;AACA,SAASC,eAAT;AAEA,OAAO,SAASC,WAAT,GAAuB;AAC1B,SAAOF,UAAU,CAACC,eAAD,CAAjB;AACH","sourcesContent":["import { useContext } from \"react\";\nimport { SecurityContext } from \"~/contexts/Security\";\n\nexport function useSecurity() {\n return useContext(SecurityContext);\n}\n"]}
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":["SecurityContext"],"mappings":"AAAA;AACA;AACA,SAASA,eAAT;AACA;AACA;AACA","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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/app-security",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.25.0-beta.2",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
],
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@webiny/app": "5.
|
|
17
|
-
"@webiny/app-admin-core": "5.
|
|
18
|
-
"@webiny/plugins": "5.
|
|
19
|
-
"minimatch": "3.
|
|
16
|
+
"@webiny/app": "5.25.0-beta.2",
|
|
17
|
+
"@webiny/app-admin-core": "5.25.0-beta.2",
|
|
18
|
+
"@webiny/plugins": "5.25.0-beta.2",
|
|
19
|
+
"minimatch": "3.1.2",
|
|
20
20
|
"react": "16.14.0",
|
|
21
21
|
"react-dom": "16.14.0"
|
|
22
22
|
},
|
|
@@ -27,13 +27,13 @@
|
|
|
27
27
|
"@babel/preset-env": "^7.16.4",
|
|
28
28
|
"@babel/preset-react": "^7.16.0",
|
|
29
29
|
"@babel/preset-typescript": "^7.16.0",
|
|
30
|
-
"@webiny/cli": "^5.
|
|
31
|
-
"@webiny/project-utils": "^5.
|
|
30
|
+
"@webiny/cli": "^5.25.0-beta.2",
|
|
31
|
+
"@webiny/project-utils": "^5.25.0-beta.2",
|
|
32
32
|
"babel-plugin-emotion": "^9.2.8",
|
|
33
33
|
"babel-plugin-lodash": "^3.3.4",
|
|
34
34
|
"rimraf": "^3.0.2",
|
|
35
35
|
"ttypescript": "^1.5.12",
|
|
36
|
-
"typescript": "
|
|
36
|
+
"typescript": "4.5.5"
|
|
37
37
|
},
|
|
38
38
|
"publishConfig": {
|
|
39
39
|
"access": "public",
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
]
|
|
51
51
|
}
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "ed2f22976af47aea0b6b5d638f8afdc39951b014"
|
|
54
54
|
}
|
package/types.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { Plugin } from "@webiny/app/types";
|
|
3
2
|
export declare type SecureRouteErrorPlugin = Plugin & {
|
|
4
3
|
render(): React.ReactElement;
|
|
@@ -15,7 +14,25 @@ export interface SecurityIdentity {
|
|
|
15
14
|
type: string;
|
|
16
15
|
displayName: string;
|
|
17
16
|
permissions?: SecurityPermission[];
|
|
17
|
+
/**
|
|
18
|
+
* TODO @ts-refactor @pavel
|
|
19
|
+
* Verify that login can be present in here.
|
|
20
|
+
*/
|
|
21
|
+
login?: string;
|
|
22
|
+
/**
|
|
23
|
+
* TODO @ts-refactor @pavel
|
|
24
|
+
* Verify that profile can be present in here.
|
|
25
|
+
*/
|
|
26
|
+
profile?: {
|
|
27
|
+
email?: string;
|
|
28
|
+
firstName?: string;
|
|
29
|
+
lastName?: string;
|
|
30
|
+
avatar?: {
|
|
31
|
+
src?: string;
|
|
32
|
+
};
|
|
33
|
+
gravatar?: string;
|
|
34
|
+
};
|
|
18
35
|
logout(): void;
|
|
19
|
-
getPermission?<T extends SecurityPermission = SecurityPermission>(name: string): T;
|
|
36
|
+
getPermission?<T extends SecurityPermission = SecurityPermission>(name: string): T | null;
|
|
20
37
|
[key: string]: any;
|
|
21
38
|
}
|
package/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|