@webiny/app-security 0.0.0-mt-2 → 0.0.0-unstable.085ff6572f
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.d.ts +2 -0
- package/Security.js +26 -0
- package/Security.js.map +1 -0
- package/components/HasPermission.d.ts +9 -0
- package/components/HasPermission.js +43 -0
- package/components/HasPermission.js.map +1 -0
- package/components/SecureRoute.d.ts +5 -4
- package/components/SecureRoute.js +23 -16
- package/components/SecureRoute.js.map +1 -0
- package/components/SecureView.d.ts +2 -2
- package/components/SecureView.js +13 -13
- package/components/SecureView.js.map +1 -0
- package/components/index.d.ts +1 -0
- package/components/index.js +27 -2
- package/components/index.js.map +1 -0
- package/contexts/Security.d.ts +7 -5
- package/contexts/Security.js +67 -21
- package/contexts/Security.js.map +1 -0
- package/hooks/usePermission.d.ts +2 -0
- package/hooks/usePermission.js +12 -0
- package/hooks/usePermission.js.map +1 -0
- package/hooks/useSecurity.d.ts +2 -2
- package/hooks/useSecurity.js +10 -4
- package/hooks/useSecurity.js.map +1 -0
- package/index.d.ts +3 -0
- package/index.js +74 -3
- package/index.js.map +1 -0
- package/package.json +20 -26
- package/types.d.ts +19 -1
- package/types.js +5 -1
- package/types.js.map +1 -0
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.d.ts
ADDED
package/Security.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.Security = void 0;
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _app = require("@webiny/app");
|
|
10
|
+
var _Security = require("./contexts/Security");
|
|
11
|
+
// Importing from `app-core` and NOT from `app-admin`, to avoid circular dependency.
|
|
12
|
+
// This can be resolved in a different way, by changing the location of `AppInstaller` component (currently in `app-admin`).
|
|
13
|
+
// But this is a faster solution, as I'm really short on time :)
|
|
14
|
+
|
|
15
|
+
var SecurityProviderHOC = function SecurityProviderHOC(Component) {
|
|
16
|
+
return function SecurityProvider(_ref) {
|
|
17
|
+
var children = _ref.children;
|
|
18
|
+
return /*#__PURE__*/_react.default.createElement(_Security.SecurityProvider, null, /*#__PURE__*/_react.default.createElement(Component, null, children));
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
var Security = function Security() {
|
|
22
|
+
return /*#__PURE__*/_react.default.createElement(_app.Provider, {
|
|
23
|
+
hoc: SecurityProviderHOC
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
exports.Security = Security;
|
package/Security.js.map
ADDED
|
@@ -0,0 +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":";;;;;;;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"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
interface HasPermissionProps {
|
|
3
|
+
any?: string[];
|
|
4
|
+
all?: string[];
|
|
5
|
+
name?: string;
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
}
|
|
8
|
+
export declare const HasPermission: ({ children, ...props }: HasPermissionProps) => JSX.Element | null;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.HasPermission = void 0;
|
|
9
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
10
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
11
|
+
var _useSecurity2 = require("../hooks/useSecurity");
|
|
12
|
+
var _excluded = ["children"];
|
|
13
|
+
var HasPermission = function HasPermission(_ref) {
|
|
14
|
+
var children = _ref.children,
|
|
15
|
+
props = (0, _objectWithoutProperties2.default)(_ref, _excluded);
|
|
16
|
+
var _useSecurity = (0, _useSecurity2.useSecurity)(),
|
|
17
|
+
getPermissions = _useSecurity.getPermissions;
|
|
18
|
+
if (props.name) {
|
|
19
|
+
var _permissionsCollections = getPermissions(props.name);
|
|
20
|
+
var _hasPermission = _permissionsCollections.length > 0;
|
|
21
|
+
if (_hasPermission) {
|
|
22
|
+
return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, children);
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
if (props.any && props.all) {
|
|
27
|
+
throw new Error("You can use either \"any\" or \"all\", but not both at the same time.");
|
|
28
|
+
}
|
|
29
|
+
var anyAllPermissions = props.any || props.all || [];
|
|
30
|
+
var permissionsCollections = anyAllPermissions.map(function (name) {
|
|
31
|
+
return getPermissions(name);
|
|
32
|
+
});
|
|
33
|
+
var hasPermission = props.any ? permissionsCollections.some(function (collection) {
|
|
34
|
+
return collection.length > 0;
|
|
35
|
+
}) : permissionsCollections.every(function (collection) {
|
|
36
|
+
return collection.length > 0;
|
|
37
|
+
});
|
|
38
|
+
if (hasPermission) {
|
|
39
|
+
return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, children);
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
};
|
|
43
|
+
exports.HasPermission = HasPermission;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["HasPermission","children","props","useSecurity","getPermissions","name","permissionsCollections","hasPermission","length","any","all","Error","anyAllPermissions","map","some","collection","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 { getPermissions } = useSecurity();\n\n if (props.name) {\n const permissionsCollections = getPermissions(props.name);\n const hasPermission = permissionsCollections.length > 0;\n if (hasPermission) {\n return <Fragment>{children}</Fragment>;\n }\n\n return null;\n }\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 const anyAllPermissions = props.any || props.all || [];\n\n const permissionsCollections = anyAllPermissions.map(name => getPermissions(name));\n\n const hasPermission = props.any\n ? permissionsCollections.some(collection => collection.length > 0)\n : permissionsCollections.every(collection => collection.length > 0);\n\n if (hasPermission) {\n return <Fragment>{children}</Fragment>;\n }\n\n return null;\n};\n"],"mappings":";;;;;;;;;AAAA;AACA;AAAkD;AAS3C,IAAMA,aAAa,GAAG,SAAhBA,aAAa,OAAmD;EAAA,IAA7CC,QAAQ,QAARA,QAAQ;IAAKC,KAAK;EAC9C,mBAA2B,IAAAC,yBAAW,GAAE;IAAhCC,cAAc,gBAAdA,cAAc;EAEtB,IAAIF,KAAK,CAACG,IAAI,EAAE;IACZ,IAAMC,uBAAsB,GAAGF,cAAc,CAACF,KAAK,CAACG,IAAI,CAAC;IACzD,IAAME,cAAa,GAAGD,uBAAsB,CAACE,MAAM,GAAG,CAAC;IACvD,IAAID,cAAa,EAAE;MACf,oBAAO,6BAAC,eAAQ,QAAEN,QAAQ,CAAY;IAC1C;IAEA,OAAO,IAAI;EACf;EAEA,IAAIC,KAAK,CAACO,GAAG,IAAIP,KAAK,CAACQ,GAAG,EAAE;IACxB,MAAM,IAAIC,KAAK,yEAAqE;EACxF;EAEA,IAAMC,iBAAiB,GAAGV,KAAK,CAACO,GAAG,IAAIP,KAAK,CAACQ,GAAG,IAAI,EAAE;EAEtD,IAAMJ,sBAAsB,GAAGM,iBAAiB,CAACC,GAAG,CAAC,UAAAR,IAAI;IAAA,OAAID,cAAc,CAACC,IAAI,CAAC;EAAA,EAAC;EAElF,IAAME,aAAa,GAAGL,KAAK,CAACO,GAAG,GACzBH,sBAAsB,CAACQ,IAAI,CAAC,UAAAC,UAAU;IAAA,OAAIA,UAAU,CAACP,MAAM,GAAG,CAAC;EAAA,EAAC,GAChEF,sBAAsB,CAACU,KAAK,CAAC,UAAAD,UAAU;IAAA,OAAIA,UAAU,CAACP,MAAM,GAAG,CAAC;EAAA,EAAC;EAEvE,IAAID,aAAa,EAAE;IACf,oBAAO,6BAAC,eAAQ,QAAEN,QAAQ,CAAY;EAC1C;EAEA,OAAO,IAAI;AACf,CAAC;AAAC"}
|
|
@@ -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;
|
|
@@ -1,27 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
import { plugins } from "@webiny/plugins";
|
|
3
|
-
export default (function (_ref) {
|
|
4
|
-
var children = _ref.children,
|
|
5
|
-
permission = _ref.permission;
|
|
6
|
-
|
|
7
|
-
var _useSecurity = useSecurity(),
|
|
8
|
-
identity = _useSecurity.identity;
|
|
1
|
+
"use strict";
|
|
9
2
|
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _useSecurity = require("../hooks/useSecurity");
|
|
8
|
+
var _plugins = require("@webiny/plugins");
|
|
9
|
+
var _default = function _default(_ref) {
|
|
10
|
+
var children = _ref.children,
|
|
11
|
+
permission = _ref.permission;
|
|
12
|
+
var security = (0, _useSecurity.useSecurity)();
|
|
13
|
+
if (!security) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
var identity = security.identity,
|
|
17
|
+
getPermission = security.getPermission;
|
|
18
|
+
if (!identity) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
10
21
|
var hasPermission = false;
|
|
11
|
-
|
|
12
22
|
if (identity) {
|
|
13
|
-
hasPermission = permission ? Boolean(
|
|
23
|
+
hasPermission = permission ? Boolean(getPermission(permission)) : true;
|
|
14
24
|
}
|
|
15
|
-
|
|
16
25
|
if (hasPermission) {
|
|
17
26
|
return children;
|
|
18
27
|
}
|
|
19
|
-
|
|
20
|
-
var plugin = plugins.byName("secure-route-error");
|
|
21
|
-
|
|
28
|
+
var plugin = _plugins.plugins.byName("secure-route-error");
|
|
22
29
|
if (!plugin) {
|
|
23
30
|
return null;
|
|
24
31
|
}
|
|
25
|
-
|
|
26
32
|
return plugin.render();
|
|
27
|
-
}
|
|
33
|
+
};
|
|
34
|
+
exports.default = _default;
|
|
@@ -0,0 +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":";;;;;;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"}
|
|
@@ -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
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _useSecurity2 = require("../hooks/useSecurity");
|
|
3
8
|
function SecureView(_ref) {
|
|
4
9
|
var children = _ref.children,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
identity = _useSecurity.identity;
|
|
9
|
-
|
|
10
|
+
permission = _ref.permission;
|
|
11
|
+
var _useSecurity = (0, _useSecurity2.useSecurity)(),
|
|
12
|
+
getPermission = _useSecurity.getPermission;
|
|
10
13
|
var hasPermission = false;
|
|
11
14
|
var matchedPermission = null;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
matchedPermission = identity.getPermission(permission);
|
|
15
|
+
if (permission) {
|
|
16
|
+
matchedPermission = getPermission(permission);
|
|
15
17
|
hasPermission = Boolean(matchedPermission);
|
|
16
18
|
}
|
|
17
|
-
|
|
18
19
|
if (typeof children === "function") {
|
|
19
20
|
return children({
|
|
20
21
|
hasPermission: hasPermission,
|
|
21
22
|
permission: matchedPermission
|
|
22
23
|
});
|
|
23
24
|
}
|
|
24
|
-
|
|
25
25
|
return hasPermission ? children : null;
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
var _default = SecureView;
|
|
28
|
+
exports.default = _default;
|
|
@@ -0,0 +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":";;;;;;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.d.ts
CHANGED
package/components/index.js
CHANGED
|
@@ -1,2 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
Object.defineProperty(exports, "HasPermission", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function get() {
|
|
10
|
+
return _HasPermission.HasPermission;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(exports, "SecureRoute", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function get() {
|
|
16
|
+
return _SecureRoute.default;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports, "SecureView", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function get() {
|
|
22
|
+
return _SecureView.default;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
var _SecureView = _interopRequireDefault(require("./SecureView"));
|
|
26
|
+
var _SecureRoute = _interopRequireDefault(require("./SecureRoute"));
|
|
27
|
+
var _HasPermission = require("./HasPermission");
|
|
@@ -0,0 +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":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA"}
|
package/contexts/Security.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import React, { Dispatch, SetStateAction } from "react";
|
|
2
2
|
import { SecurityIdentity, SecurityPermission } from "../types";
|
|
3
|
-
export
|
|
4
|
-
export interface SecurityContextValue {
|
|
3
|
+
export interface SecurityContext {
|
|
5
4
|
identity: SecurityIdentity | null;
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
getIdentityId: () => string | null;
|
|
6
|
+
setIdentity: Dispatch<SetStateAction<SecurityIdentity | null>>;
|
|
7
|
+
getPermission<T extends SecurityPermission = SecurityPermission>(name: string, exact?: boolean): T | null;
|
|
8
|
+
getPermissions<T extends SecurityPermission = SecurityPermission>(name: string): T[];
|
|
8
9
|
}
|
|
9
|
-
export declare const
|
|
10
|
+
export declare const SecurityContext: React.Context<SecurityContext>;
|
|
11
|
+
export declare const SecurityProvider: React.FC;
|
package/contexts/Security.js
CHANGED
|
@@ -1,44 +1,90 @@
|
|
|
1
|
-
|
|
2
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
-
import minimatch from "minimatch";
|
|
4
|
-
import React, { useState, useMemo, useCallback } from "react";
|
|
5
|
-
export var SecurityContext = /*#__PURE__*/React.createContext(null);
|
|
6
|
-
export var SecurityProvider = function SecurityProvider(props) {
|
|
7
|
-
var _useState = useState(null),
|
|
8
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
9
|
-
identity = _useState2[0],
|
|
10
|
-
setIdentity = _useState2[1];
|
|
1
|
+
"use strict";
|
|
11
2
|
|
|
12
|
-
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.SecurityProvider = exports.SecurityContext = void 0;
|
|
9
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
10
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
|
+
var _minimatch = _interopRequireDefault(require("minimatch"));
|
|
12
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
13
|
+
var SecurityContext = /*#__PURE__*/_react.default.createContext({
|
|
14
|
+
identity: null,
|
|
15
|
+
getIdentityId: function getIdentityId() {
|
|
16
|
+
return null;
|
|
17
|
+
},
|
|
18
|
+
setIdentity: function setIdentity() {
|
|
19
|
+
return void 0;
|
|
20
|
+
},
|
|
21
|
+
getPermission: function getPermission() {
|
|
22
|
+
return null;
|
|
23
|
+
},
|
|
24
|
+
getPermissions: function getPermissions() {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
exports.SecurityContext = SecurityContext;
|
|
29
|
+
var SecurityProvider = function SecurityProvider(props) {
|
|
30
|
+
var _useState = (0, _react.useState)(null),
|
|
31
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
32
|
+
identity = _useState2[0],
|
|
33
|
+
setIdentity = _useState2[1];
|
|
34
|
+
var getPermission = (0, _react.useCallback)(function (name, exact) {
|
|
13
35
|
if (!identity) {
|
|
14
36
|
return null;
|
|
15
37
|
}
|
|
16
|
-
|
|
17
38
|
var perms = identity.permissions || [];
|
|
18
39
|
var exactMatch = perms.find(function (p) {
|
|
19
40
|
return p.name === name;
|
|
20
41
|
});
|
|
21
|
-
|
|
22
42
|
if (exactMatch) {
|
|
23
43
|
return exactMatch;
|
|
24
|
-
}
|
|
25
|
-
|
|
44
|
+
} else if (exact) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
26
47
|
|
|
48
|
+
// Try matching using patterns
|
|
27
49
|
return perms.find(function (p) {
|
|
28
|
-
return
|
|
50
|
+
return (0, _minimatch.default)(name, p.name);
|
|
51
|
+
});
|
|
52
|
+
}, [identity]);
|
|
53
|
+
var getPermissions = (0, _react.useCallback)(function (name) {
|
|
54
|
+
if (!identity) {
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
57
|
+
var permissions = identity.permissions || [];
|
|
58
|
+
return permissions.filter(function (current) {
|
|
59
|
+
var exactMatch = current.name === name;
|
|
60
|
+
if (exactMatch) {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Try matching using patterns.
|
|
65
|
+
return (0, _minimatch.default)(name, current.name);
|
|
29
66
|
});
|
|
30
67
|
}, [identity]);
|
|
31
|
-
var
|
|
68
|
+
var getIdentityId = (0, _react.useCallback)(function () {
|
|
69
|
+
if (!identity) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
return identity.id || identity.login || null;
|
|
73
|
+
}, [identity]);
|
|
74
|
+
var value = (0, _react.useMemo)(function () {
|
|
32
75
|
return {
|
|
33
|
-
identity: identity ?
|
|
76
|
+
identity: identity ? (0, _objectSpread2.default)((0, _objectSpread2.default)({}, identity), {}, {
|
|
34
77
|
// For backwards compatibility, expose the `getPermission` method on the `identity` object.
|
|
35
78
|
getPermission: getPermission
|
|
36
79
|
}) : null,
|
|
80
|
+
getIdentityId: getIdentityId,
|
|
37
81
|
setIdentity: setIdentity,
|
|
38
|
-
getPermission: getPermission
|
|
82
|
+
getPermission: getPermission,
|
|
83
|
+
getPermissions: getPermissions
|
|
39
84
|
};
|
|
40
85
|
}, [identity]);
|
|
41
|
-
return /*#__PURE__*/
|
|
86
|
+
return /*#__PURE__*/_react.default.createElement(SecurityContext.Provider, {
|
|
42
87
|
value: value
|
|
43
88
|
}, props.children);
|
|
44
|
-
};
|
|
89
|
+
};
|
|
90
|
+
exports.SecurityProvider = SecurityProvider;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["SecurityContext","React","createContext","identity","getIdentityId","setIdentity","getPermission","getPermissions","SecurityProvider","props","useState","useCallback","name","exact","perms","permissions","exactMatch","find","p","minimatch","filter","current","id","login","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 getIdentityId: () => string | null;\n\n setIdentity: Dispatch<SetStateAction<SecurityIdentity | null>>;\n\n getPermission<T extends SecurityPermission = SecurityPermission>(\n name: string,\n exact?: boolean\n ): T | null;\n\n getPermissions<T extends SecurityPermission = SecurityPermission>(name: string): T[];\n}\n\nexport const SecurityContext = React.createContext<SecurityContext>({\n identity: null,\n getIdentityId: () => null,\n setIdentity: () => {\n return void 0;\n },\n getPermission: () => {\n return null;\n },\n getPermissions: () => {\n return [];\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>(\n name: string,\n exact?: boolean\n ): 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 } else if (exact) {\n return null;\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 getPermissions = useCallback(\n <T extends SecurityPermission = SecurityPermission>(name: string): Array<T> => {\n if (!identity) {\n return [];\n }\n\n const permissions = identity.permissions || [];\n\n return permissions.filter(current => {\n const exactMatch = current.name === name;\n if (exactMatch) {\n return true;\n }\n\n // Try matching using patterns.\n return minimatch(name, current.name);\n }) as T[];\n },\n [identity]\n );\n\n const getIdentityId = useCallback(() => {\n if (!identity) {\n return null;\n }\n return identity.id || identity.login || null;\n }, [identity]);\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 getIdentityId,\n setIdentity,\n getPermission,\n getPermissions\n };\n }, [identity]);\n\n return <SecurityContext.Provider value={value}>{props.children}</SecurityContext.Provider>;\n};\n"],"mappings":";;;;;;;;;;AAAA;AACA;AAiBO,IAAMA,eAAe,gBAAGC,cAAK,CAACC,aAAa,CAAkB;EAChEC,QAAQ,EAAE,IAAI;EACdC,aAAa,EAAE;IAAA,OAAM,IAAI;EAAA;EACzBC,WAAW,EAAE,uBAAM;IACf,OAAO,KAAK,CAAC;EACjB,CAAC;EACDC,aAAa,EAAE,yBAAM;IACjB,OAAO,IAAI;EACf,CAAC;EACDC,cAAc,EAAE,0BAAM;IAClB,OAAO,EAAE;EACb;AACJ,CAAC,CAAC;AAAC;AAEI,IAAMC,gBAA0B,GAAG,SAA7BA,gBAA0B,CAAGC,KAAK,EAAI;EAC/C,gBAAgC,IAAAC,eAAQ,EAA0B,IAAI,CAAC;IAAA;IAAhEP,QAAQ;IAAEE,WAAW;EAE5B,IAAMC,aAAa,GAAG,IAAAK,kBAAW,EAC7B,UACIC,IAAY,EACZC,KAAe,EACJ;IACX,IAAI,CAACV,QAAQ,EAAE;MACX,OAAO,IAAI;IACf;IAEA,IAAMW,KAAK,GAAGX,QAAQ,CAACY,WAAW,IAAI,EAAE;IACxC,IAAMC,UAAU,GAAGF,KAAK,CAACG,IAAI,CAAC,UAAAC,CAAC;MAAA,OAAIA,CAAC,CAACN,IAAI,KAAKA,IAAI;IAAA,EAAC;IACnD,IAAII,UAAU,EAAE;MACZ,OAAOA,UAAU;IACrB,CAAC,MAAM,IAAIH,KAAK,EAAE;MACd,OAAO,IAAI;IACf;;IAEA;IACA,OAAOC,KAAK,CAACG,IAAI,CAAC,UAAAC,CAAC;MAAA,OAAI,IAAAC,kBAAS,EAACP,IAAI,EAAEM,CAAC,CAACN,IAAI,CAAC;IAAA,EAAC;EACnD,CAAC,EACD,CAACT,QAAQ,CAAC,CACb;EAED,IAAMI,cAAc,GAAG,IAAAI,kBAAW,EAC9B,UAAoDC,IAAY,EAAe;IAC3E,IAAI,CAACT,QAAQ,EAAE;MACX,OAAO,EAAE;IACb;IAEA,IAAMY,WAAW,GAAGZ,QAAQ,CAACY,WAAW,IAAI,EAAE;IAE9C,OAAOA,WAAW,CAACK,MAAM,CAAC,UAAAC,OAAO,EAAI;MACjC,IAAML,UAAU,GAAGK,OAAO,CAACT,IAAI,KAAKA,IAAI;MACxC,IAAII,UAAU,EAAE;QACZ,OAAO,IAAI;MACf;;MAEA;MACA,OAAO,IAAAG,kBAAS,EAACP,IAAI,EAAES,OAAO,CAACT,IAAI,CAAC;IACxC,CAAC,CAAC;EACN,CAAC,EACD,CAACT,QAAQ,CAAC,CACb;EAED,IAAMC,aAAa,GAAG,IAAAO,kBAAW,EAAC,YAAM;IACpC,IAAI,CAACR,QAAQ,EAAE;MACX,OAAO,IAAI;IACf;IACA,OAAOA,QAAQ,CAACmB,EAAE,IAAInB,QAAQ,CAACoB,KAAK,IAAI,IAAI;EAChD,CAAC,EAAE,CAACpB,QAAQ,CAAC,CAAC;EAEd,IAAMqB,KAAK,GAAG,IAAAC,cAAO,EAAC,YAAM;IACxB,OAAO;MACHtB,QAAQ,EAAEA,QAAQ,+DAELA,QAAQ;QACX;QACAG,aAAa,EAAbA;MAAa,KAEjB,IAAI;MACVF,aAAa,EAAbA,aAAa;MACbC,WAAW,EAAXA,WAAW;MACXC,aAAa,EAAbA,aAAa;MACbC,cAAc,EAAdA;IACJ,CAAC;EACL,CAAC,EAAE,CAACJ,QAAQ,CAAC,CAAC;EAEd,oBAAO,6BAAC,eAAe,CAAC,QAAQ;IAAC,KAAK,EAAEqB;EAAM,GAAEf,KAAK,CAACiB,QAAQ,CAA4B;AAC9F,CAAC;AAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.usePermission = usePermission;
|
|
7
|
+
var _useSecurity2 = require("./useSecurity");
|
|
8
|
+
function usePermission(name) {
|
|
9
|
+
var _useSecurity = (0, _useSecurity2.useSecurity)(),
|
|
10
|
+
getPermission = _useSecurity.getPermission;
|
|
11
|
+
return getPermission(name);
|
|
12
|
+
}
|
|
@@ -0,0 +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":";;;;;;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.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function useSecurity():
|
|
1
|
+
import { SecurityContext } from "../contexts/Security";
|
|
2
|
+
export declare function useSecurity(): SecurityContext;
|
package/hooks/useSecurity.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useSecurity = useSecurity;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _Security = require("../contexts/Security");
|
|
9
|
+
function useSecurity() {
|
|
10
|
+
return (0, _react.useContext)(_Security.SecurityContext);
|
|
5
11
|
}
|
|
@@ -0,0 +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":";;;;;;AAAA;AACA;AAEO,SAASA,WAAW,GAAG;EAC1B,OAAO,IAAAC,iBAAU,EAACC,yBAAe,CAAC;AACtC"}
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1,3 +1,74 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
SecurityContext: true
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "SecurityContext", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function get() {
|
|
12
|
+
return _Security.SecurityContext;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
var _components = require("./components");
|
|
16
|
+
Object.keys(_components).forEach(function (key) {
|
|
17
|
+
if (key === "default" || key === "__esModule") return;
|
|
18
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
19
|
+
if (key in exports && exports[key] === _components[key]) return;
|
|
20
|
+
Object.defineProperty(exports, key, {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function get() {
|
|
23
|
+
return _components[key];
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
var _Security = require("./contexts/Security");
|
|
28
|
+
Object.keys(_Security).forEach(function (key) {
|
|
29
|
+
if (key === "default" || key === "__esModule") return;
|
|
30
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
31
|
+
if (key in exports && exports[key] === _Security[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function get() {
|
|
35
|
+
return _Security[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
var _useSecurity = require("./hooks/useSecurity");
|
|
40
|
+
Object.keys(_useSecurity).forEach(function (key) {
|
|
41
|
+
if (key === "default" || key === "__esModule") return;
|
|
42
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
43
|
+
if (key in exports && exports[key] === _useSecurity[key]) return;
|
|
44
|
+
Object.defineProperty(exports, key, {
|
|
45
|
+
enumerable: true,
|
|
46
|
+
get: function get() {
|
|
47
|
+
return _useSecurity[key];
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
var _usePermission = require("./hooks/usePermission");
|
|
52
|
+
Object.keys(_usePermission).forEach(function (key) {
|
|
53
|
+
if (key === "default" || key === "__esModule") return;
|
|
54
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
55
|
+
if (key in exports && exports[key] === _usePermission[key]) return;
|
|
56
|
+
Object.defineProperty(exports, key, {
|
|
57
|
+
enumerable: true,
|
|
58
|
+
get: function get() {
|
|
59
|
+
return _usePermission[key];
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
var _Security2 = require("./Security");
|
|
64
|
+
Object.keys(_Security2).forEach(function (key) {
|
|
65
|
+
if (key === "default" || key === "__esModule") return;
|
|
66
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
67
|
+
if (key in exports && exports[key] === _Security2[key]) return;
|
|
68
|
+
Object.defineProperty(exports, key, {
|
|
69
|
+
enumerable: true,
|
|
70
|
+
get: function get() {
|
|
71
|
+
return _Security2[key];
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
});
|
package/index.js.map
ADDED
|
@@ -0,0 +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":";;;;;;;;;;;;;;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": "0.0.0-
|
|
3
|
+
"version": "0.0.0-unstable.085ff6572f",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -13,27 +13,26 @@
|
|
|
13
13
|
],
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@webiny/app": "0.0.0-
|
|
17
|
-
"@webiny/plugins": "0.0.0-
|
|
18
|
-
"minimatch": "
|
|
19
|
-
"react": "
|
|
20
|
-
"react-dom": "
|
|
16
|
+
"@webiny/app": "0.0.0-unstable.085ff6572f",
|
|
17
|
+
"@webiny/plugins": "0.0.0-unstable.085ff6572f",
|
|
18
|
+
"minimatch": "5.1.6",
|
|
19
|
+
"react": "17.0.2",
|
|
20
|
+
"react-dom": "17.0.2"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@babel/cli": "
|
|
24
|
-
"@babel/core": "
|
|
25
|
-
"@babel/plugin-proposal-class-properties": "
|
|
26
|
-
"@babel/preset-env": "
|
|
27
|
-
"@babel/preset-react": "
|
|
28
|
-
"@babel/preset-typescript": "
|
|
29
|
-
"@webiny/cli": "
|
|
30
|
-
"@webiny/project-utils": "
|
|
31
|
-
"babel-plugin-emotion": "
|
|
32
|
-
"babel-plugin-lodash": "
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"typescript": "^4.1.3"
|
|
23
|
+
"@babel/cli": "7.20.7",
|
|
24
|
+
"@babel/core": "7.20.12",
|
|
25
|
+
"@babel/plugin-proposal-class-properties": "7.18.6",
|
|
26
|
+
"@babel/preset-env": "7.20.2",
|
|
27
|
+
"@babel/preset-react": "7.18.6",
|
|
28
|
+
"@babel/preset-typescript": "7.18.6",
|
|
29
|
+
"@webiny/cli": "0.0.0-unstable.085ff6572f",
|
|
30
|
+
"@webiny/project-utils": "0.0.0-unstable.085ff6572f",
|
|
31
|
+
"babel-plugin-emotion": "9.2.11",
|
|
32
|
+
"babel-plugin-lodash": "3.3.4",
|
|
33
|
+
"rimraf": "3.0.2",
|
|
34
|
+
"ttypescript": "1.5.15",
|
|
35
|
+
"typescript": "4.7.4"
|
|
37
36
|
},
|
|
38
37
|
"publishConfig": {
|
|
39
38
|
"access": "public",
|
|
@@ -43,11 +42,6 @@
|
|
|
43
42
|
"build": "yarn webiny run build",
|
|
44
43
|
"watch": "yarn webiny run watch"
|
|
45
44
|
},
|
|
46
|
-
"svgo": {
|
|
47
|
-
"plugins": {
|
|
48
|
-
"removeViewBox": false
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
45
|
"adio": {
|
|
52
46
|
"ignore": {
|
|
53
47
|
"peerDependencies": [
|
|
@@ -55,5 +49,5 @@
|
|
|
55
49
|
]
|
|
56
50
|
}
|
|
57
51
|
},
|
|
58
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "085ff6572f6bb6a76d218088b06d9f4ef92bbea7"
|
|
59
53
|
}
|
package/types.d.ts
CHANGED
|
@@ -15,7 +15,25 @@ export interface SecurityIdentity {
|
|
|
15
15
|
type: string;
|
|
16
16
|
displayName: string;
|
|
17
17
|
permissions?: SecurityPermission[];
|
|
18
|
+
/**
|
|
19
|
+
* TODO @ts-refactor @pavel
|
|
20
|
+
* Verify that login can be present in here.
|
|
21
|
+
*/
|
|
22
|
+
login?: string;
|
|
23
|
+
/**
|
|
24
|
+
* TODO @ts-refactor @pavel
|
|
25
|
+
* Verify that profile can be present in here.
|
|
26
|
+
*/
|
|
27
|
+
profile?: {
|
|
28
|
+
email?: string;
|
|
29
|
+
firstName?: string;
|
|
30
|
+
lastName?: string;
|
|
31
|
+
avatar?: {
|
|
32
|
+
src?: string;
|
|
33
|
+
};
|
|
34
|
+
gravatar?: string;
|
|
35
|
+
};
|
|
18
36
|
logout(): void;
|
|
19
|
-
getPermission?<T extends SecurityPermission = SecurityPermission>(name: string): T;
|
|
37
|
+
getPermission?<T extends SecurityPermission = SecurityPermission>(name: string): T | null;
|
|
20
38
|
[key: string]: any;
|
|
21
39
|
}
|
package/types.js
CHANGED
package/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import { Plugin } from \"@webiny/app/types\";\n\nexport type SecureRouteErrorPlugin = Plugin & {\n render(): React.ReactElement;\n};\n\nexport interface FullAccessPermission {\n name: \"*\";\n}\n\nexport interface SecurityPermission {\n name: string;\n [key: string]: any;\n}\n\nexport interface SecurityIdentity {\n id: string;\n type: string;\n displayName: string;\n permissions?: SecurityPermission[];\n /**\n * TODO @ts-refactor @pavel\n * Verify that login can be present in here.\n */\n login?: string;\n /**\n * TODO @ts-refactor @pavel\n * Verify that profile can be present in here.\n */\n profile?: {\n email?: string;\n firstName?: string;\n lastName?: string;\n avatar?: {\n src?: string;\n };\n gravatar?: string;\n };\n logout(): void;\n // For backwards compatibility, expose the `getPermission` method on the `identity` object.\n getPermission?<T extends SecurityPermission = SecurityPermission>(name: string): T | null;\n [key: string]: any;\n}\n"],"mappings":""}
|