@webiny/app-security 5.17.4-beta.1 → 5.18.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.
@@ -24,5 +24,4 @@ export default (function (_ref) {
24
24
  }
25
25
 
26
26
  return plugin.render();
27
- });
28
- //# sourceMappingURL=SecureRoute.js.map
27
+ });
@@ -25,5 +25,4 @@ function SecureView(_ref) {
25
25
  return hasPermission ? children : null;
26
26
  }
27
27
 
28
- export default SecureView;
29
- //# sourceMappingURL=SecureView.js.map
28
+ export default SecureView;
@@ -1,3 +1,2 @@
1
1
  export { default as SecureView } from "./SecureView";
2
- export { default as SecureRoute } from "./SecureRoute";
3
- //# sourceMappingURL=index.js.map
2
+ export { default as SecureRoute } from "./SecureRoute";
@@ -41,5 +41,4 @@ export var SecurityProvider = function SecurityProvider(props) {
41
41
  return /*#__PURE__*/React.createElement(SecurityContext.Provider, {
42
42
  value: value
43
43
  }, props.children);
44
- };
45
- //# sourceMappingURL=Security.js.map
44
+ };
@@ -2,5 +2,4 @@ import { useContext } from "react";
2
2
  import { SecurityContext } from "../contexts/Security";
3
3
  export function useSecurity() {
4
4
  return useContext(SecurityContext);
5
- }
6
- //# sourceMappingURL=useSecurity.js.map
5
+ }
package/index.js CHANGED
@@ -1,4 +1,3 @@
1
1
  export * from "./components";
2
2
  export * from "./contexts/Security";
3
- export * from "./hooks/useSecurity";
4
- //# sourceMappingURL=index.js.map
3
+ export * from "./hooks/useSecurity";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/app-security",
3
- "version": "5.17.4-beta.1",
3
+ "version": "5.18.0-beta.2",
4
4
  "main": "index.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -13,8 +13,8 @@
13
13
  ],
14
14
  "license": "MIT",
15
15
  "dependencies": {
16
- "@webiny/app": "5.17.4-beta.1",
17
- "@webiny/plugins": "5.17.4-beta.1",
16
+ "@webiny/app": "5.18.0-beta.2",
17
+ "@webiny/plugins": "5.18.0-beta.2",
18
18
  "minimatch": "3.0.4",
19
19
  "react": "16.14.0",
20
20
  "react-dom": "16.14.0"
@@ -26,8 +26,8 @@
26
26
  "@babel/preset-env": "^7.5.5",
27
27
  "@babel/preset-react": "^7.0.0",
28
28
  "@babel/preset-typescript": "^7.8.3",
29
- "@webiny/cli": "^5.17.4-beta.1",
30
- "@webiny/project-utils": "^5.17.4-beta.1",
29
+ "@webiny/cli": "^5.18.0-beta.2",
30
+ "@webiny/project-utils": "^5.18.0-beta.2",
31
31
  "babel-plugin-emotion": "^9.2.8",
32
32
  "babel-plugin-lodash": "^3.3.4",
33
33
  "babel-plugin-named-asset-import": "^1.0.0-next.3e165448",
@@ -55,5 +55,5 @@
55
55
  ]
56
56
  }
57
57
  },
58
- "gitHead": "42a79226fee87b18750a72c9d8399f3b32625a9a"
58
+ "gitHead": "02bb6242be1f61cbc204aea458fbc9e7c6000fc8"
59
59
  }
package/types.js CHANGED
@@ -1,2 +1 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
1
+ export {};
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/components/SecureRoute.tsx"],"names":["useSecurity","plugins","children","permission","identity","hasPermission","Boolean","getPermission","plugin","byName","render"],"mappings":"AACA,SAASA,WAAT,QAA4B,IAA5B;AAEA,SAASC,OAAT,QAAwB,iBAAxB;AAEA,gBAAe,gBAMW;AAAA,MALtBC,QAKsB,QALtBA,QAKsB;AAAA,MAJtBC,UAIsB,QAJtBA,UAIsB;;AACtB,qBAAqBH,WAAW,EAAhC;AAAA,MAAQI,QAAR,gBAAQA,QAAR;;AAEA,MAAIC,aAAa,GAAG,KAApB;;AACA,MAAID,QAAJ,EAAc;AACVC,IAAAA,aAAa,GAAGF,UAAU,GAAGG,OAAO,CAACF,QAAQ,CAACG,aAAT,CAAuBJ,UAAvB,CAAD,CAAV,GAAiD,IAA3E;AACH;;AAED,MAAIE,aAAJ,EAAmB;AACf,WAAOH,QAAP;AACH;;AAED,MAAMM,MAAM,GAAGP,OAAO,CAACQ,MAAR,CAAuC,oBAAvC,CAAf;;AACA,MAAI,CAACD,MAAL,EAAa;AACT,WAAO,IAAP;AACH;;AAED,SAAOA,MAAM,CAACE,MAAP,EAAP;AACH,CAxBD","sourcesContent":["import * as React from \"react\";\nimport { useSecurity } from \"..\";\nimport { SecureRouteErrorPlugin } from \"~/types\";\nimport { plugins } from \"@webiny/plugins\";\n\nexport default ({\n children,\n permission\n}: {\n children: any;\n permission?: string;\n}): React.ReactElement => {\n const { identity } = useSecurity();\n\n let hasPermission = false;\n if (identity) {\n hasPermission = permission ? Boolean(identity.getPermission(permission)) : true;\n }\n\n if (hasPermission) {\n return children;\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"],"file":"SecureRoute.js"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/components/SecureView.tsx"],"names":["useSecurity","SecureView","children","permission","identity","hasPermission","matchedPermission","getPermission","Boolean"],"mappings":"AACA,SAASA,WAAT,QAA4B,IAA5B;;AAaA,SAASC,UAAT,OAGiC;AAAA,MAF7BC,QAE6B,QAF7BA,QAE6B;AAAA,MAD7BC,UAC6B,QAD7BA,UAC6B;;AAC7B,qBAAqBH,WAAW,EAAhC;AAAA,MAAQI,QAAR,gBAAQA,QAAR;;AAEA,MAAIC,aAAa,GAAG,KAApB;AACA,MAAIC,iBAAoB,GAAG,IAA3B;;AACA,MAAIF,QAAJ,EAAc;AACVE,IAAAA,iBAAiB,GAAGF,QAAQ,CAACG,aAAT,CAA0BJ,UAA1B,CAApB;AACAE,IAAAA,aAAa,GAAGG,OAAO,CAACF,iBAAD,CAAvB;AACH;;AAED,MAAI,OAAOJ,QAAP,KAAoB,UAAxB,EAAoC;AAChC,WAAOA,QAAQ,CAAC;AAAEG,MAAAA,aAAa,EAAbA,aAAF;AAAiBF,MAAAA,UAAU,EAAEG;AAA7B,KAAD,CAAf;AACH;;AAED,SAAOD,aAAa,GAAGH,QAAH,GAAc,IAAlC;AACH;;AAED,eAAeD,UAAf","sourcesContent":["import * as React from \"react\";\nimport { useSecurity } from \"..\";\nimport { SecurityPermission } from \"~/types\";\n\ninterface ChildrenRenderFunctionArgs<T extends SecurityPermission> {\n hasPermission: boolean;\n permission: T;\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 {\n const { identity } = useSecurity();\n\n let hasPermission = false;\n let matchedPermission: T = null;\n if (identity) {\n matchedPermission = identity.getPermission<T>(permission);\n hasPermission = Boolean(matchedPermission);\n }\n\n if (typeof children === \"function\") {\n return children({ hasPermission, permission: matchedPermission });\n }\n\n return hasPermission ? children : null;\n}\n\nexport default SecureView;\n"],"file":"SecureView.js"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/components/index.ts"],"names":["default","SecureView","SecureRoute"],"mappings":"AAAA,SAASA,OAAO,IAAIC,UAApB;AACA,SAASD,OAAO,IAAIE,WAApB","sourcesContent":["export { default as SecureView } from \"./SecureView\";\nexport { default as SecureRoute } from \"./SecureRoute\";\n"],"file":"index.js"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/contexts/Security.tsx"],"names":["minimatch","React","useState","useMemo","useCallback","SecurityContext","createContext","SecurityProvider","props","identity","setIdentity","getPermission","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;AAGA,OAAO,IAAMC,eAAe,gBAAGJ,KAAK,CAACK,aAAN,CAA0C,IAA1C,CAAxB;AAQP,OAAO,IAAMC,gBAAgB,GAAG,SAAnBA,gBAAmB,CAAAC,KAAK,EAAI;AACrC,kBAAgCN,QAAQ,CAAmB,IAAnB,CAAxC;AAAA;AAAA,MAAOO,QAAP;AAAA,MAAiBC,WAAjB;;AAEA,MAAMC,aAAa,GAAGP,WAAW,CAC7B,UAAoDQ,IAApD,EAAwE;AACpE,QAAI,CAACH,QAAL,EAAe;AACX,aAAO,IAAP;AACH;;AAED,QAAMI,KAAK,GAAGJ,QAAQ,CAACK,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,KATmE,CAWpE;;;AACA,WAAOF,KAAK,CAACG,IAAN,CAAW,UAAAC,CAAC;AAAA,aAAIjB,SAAS,CAACY,IAAD,EAAOK,CAAC,CAACL,IAAT,CAAb;AAAA,KAAZ,CAAP;AACH,GAd4B,EAe7B,CAACH,QAAD,CAf6B,CAAjC;AAkBA,MAAMS,KAAK,GAAGf,OAAO,CACjB;AAAA,WAAO;AACHM,MAAAA,QAAQ,EAAEA,QAAQ,mCAELA,QAFK;AAGR;AACAE,QAAAA,aAAa,EAAEA;AAJP,WAMZ,IAPH;AAQHD,MAAAA,WAAW,EAAXA,WARG;AASHC,MAAAA,aAAa,EAAbA;AATG,KAAP;AAAA,GADiB,EAYjB,CAACF,QAAD,CAZiB,CAArB;AAeA,sBAAO,oBAAC,eAAD,CAAiB,QAAjB;AAA0B,IAAA,KAAK,EAAES;AAAjC,KAAyCV,KAAK,CAACW,QAA/C,CAAP;AACH,CArCM","sourcesContent":["import minimatch from \"minimatch\";\nimport React, { useState, useMemo, Dispatch, SetStateAction, useCallback } from \"react\";\nimport { SecurityIdentity, SecurityPermission } from \"~/types\";\n\nexport const SecurityContext = React.createContext<SecurityContextValue>(null);\n\nexport interface SecurityContextValue {\n identity: SecurityIdentity | null;\n setIdentity: Dispatch<SetStateAction<SecurityIdentity>>;\n getPermission<T extends SecurityPermission = SecurityPermission>(name: string): T;\n}\n\nexport const SecurityProvider = props => {\n const [identity, setIdentity] = useState<SecurityIdentity>(null);\n\n const getPermission = useCallback(\n <T extends SecurityPermission = SecurityPermission>(name: string): T => {\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 () => ({\n identity: identity\n ? {\n ...identity,\n // For backwards compatibility, expose the `getPermission` method on the `identity` object.\n getPermission: getPermission as any\n }\n : null,\n setIdentity,\n getPermission\n }),\n [identity]\n );\n\n return <SecurityContext.Provider value={value}>{props.children}</SecurityContext.Provider>;\n};\n"],"file":"Security.js"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/hooks/useSecurity.ts"],"names":["useContext","SecurityContext","useSecurity"],"mappings":"AAAA,SAASA,UAAT,QAA2B,OAA3B;AACA,SAASC,eAAT;AAIA,OAAO,SAASC,WAAT,GAAuB;AAC1B,SAAOF,UAAU,CAACC,eAAD,CAAjB;AACH","sourcesContent":["import { useContext } from \"react\";\nimport { SecurityContext } from \"~/contexts/Security\";\n\nexport type UseSecurity = ReturnType<typeof useSecurity>;\n\nexport function useSecurity() {\n return useContext(SecurityContext);\n}\n"],"file":"useSecurity.js"}
package/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"AAAA;AACA;AACA","sourcesContent":["export * from \"./components\";\nexport * from \"./contexts/Security\";\nexport * from \"./hooks/useSecurity\";\n"],"file":"index.js"}
package/types.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"types.js"}