@backstage/plugin-permission-react 0.4.36-next.0 → 0.4.37-next.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/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @backstage/plugin-permission-react
2
2
 
3
+ ## 0.4.37-next.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+ - @backstage/config@1.3.4-next.0
9
+ - @backstage/core-plugin-api@1.11.1-next.0
10
+ - @backstage/plugin-permission-common@0.9.2-next.0
11
+
12
+ ## 0.4.36
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies
17
+ - @backstage/config@1.3.3
18
+ - @backstage/plugin-permission-common@0.9.1
19
+ - @backstage/core-plugin-api@1.10.9
20
+
3
21
  ## 0.4.36-next.0
4
22
 
5
23
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"IdentityPermissionApi.esm.js","sources":["../../src/apis/IdentityPermissionApi.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { DiscoveryApi, IdentityApi } from '@backstage/core-plugin-api';\nimport { PermissionApi } from './PermissionApi';\nimport {\n AuthorizePermissionRequest,\n AuthorizePermissionResponse,\n PermissionClient,\n} from '@backstage/plugin-permission-common';\nimport { Config } from '@backstage/config';\n\n/**\n * The default implementation of the PermissionApi, which simply calls the authorize method of the given\n * {@link @backstage/plugin-permission-common#PermissionClient}.\n * @public\n */\nexport class IdentityPermissionApi implements PermissionApi {\n private constructor(\n private readonly permissionClient: PermissionClient,\n private readonly identityApi: IdentityApi,\n ) {}\n\n static create(options: {\n config: Config;\n discovery: DiscoveryApi;\n identity: IdentityApi;\n }) {\n const { config, discovery, identity } = options;\n const permissionClient = new PermissionClient({ discovery, config });\n return new IdentityPermissionApi(permissionClient, identity);\n }\n\n async authorize(\n request: AuthorizePermissionRequest,\n ): Promise<AuthorizePermissionResponse> {\n const response = await this.permissionClient.authorize(\n [request],\n await this.identityApi.getCredentials(),\n );\n return response[0];\n }\n}\n"],"names":[],"mappings":";;AA8BO,MAAM,qBAA+C,CAAA;AAAA,EAClD,WAAA,CACW,kBACA,WACjB,EAAA;AAFiB,IAAA,IAAA,CAAA,gBAAA,GAAA,gBAAA;AACA,IAAA,IAAA,CAAA,WAAA,GAAA,WAAA;AAAA;AAChB,EAEH,OAAO,OAAO,OAIX,EAAA;AACD,IAAA,MAAM,EAAE,MAAA,EAAQ,SAAW,EAAA,QAAA,EAAa,GAAA,OAAA;AACxC,IAAA,MAAM,mBAAmB,IAAI,gBAAA,CAAiB,EAAE,SAAA,EAAW,QAAQ,CAAA;AACnE,IAAO,OAAA,IAAI,qBAAsB,CAAA,gBAAA,EAAkB,QAAQ,CAAA;AAAA;AAC7D,EAEA,MAAM,UACJ,OACsC,EAAA;AACtC,IAAM,MAAA,QAAA,GAAW,MAAM,IAAA,CAAK,gBAAiB,CAAA,SAAA;AAAA,MAC3C,CAAC,OAAO,CAAA;AAAA,MACR,MAAM,IAAK,CAAA,WAAA,CAAY,cAAe;AAAA,KACxC;AACA,IAAA,OAAO,SAAS,CAAC,CAAA;AAAA;AAErB;;;;"}
1
+ {"version":3,"file":"IdentityPermissionApi.esm.js","sources":["../../src/apis/IdentityPermissionApi.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { DiscoveryApi, IdentityApi } from '@backstage/core-plugin-api';\nimport { PermissionApi } from './PermissionApi';\nimport {\n AuthorizePermissionRequest,\n AuthorizePermissionResponse,\n PermissionClient,\n} from '@backstage/plugin-permission-common';\nimport { Config } from '@backstage/config';\n\n/**\n * The default implementation of the PermissionApi, which simply calls the authorize method of the given\n * {@link @backstage/plugin-permission-common#PermissionClient}.\n * @public\n */\nexport class IdentityPermissionApi implements PermissionApi {\n private constructor(\n private readonly permissionClient: PermissionClient,\n private readonly identityApi: IdentityApi,\n ) {}\n\n static create(options: {\n config: Config;\n discovery: DiscoveryApi;\n identity: IdentityApi;\n }) {\n const { config, discovery, identity } = options;\n const permissionClient = new PermissionClient({ discovery, config });\n return new IdentityPermissionApi(permissionClient, identity);\n }\n\n async authorize(\n request: AuthorizePermissionRequest,\n ): Promise<AuthorizePermissionResponse> {\n const response = await this.permissionClient.authorize(\n [request],\n await this.identityApi.getCredentials(),\n );\n return response[0];\n }\n}\n"],"names":[],"mappings":";;AA8BO,MAAM,qBAAA,CAA+C;AAAA,EAClD,WAAA,CACW,kBACA,WAAA,EACjB;AAFiB,IAAA,IAAA,CAAA,gBAAA,GAAA,gBAAA;AACA,IAAA,IAAA,CAAA,WAAA,GAAA,WAAA;AAAA,EAChB;AAAA,EAEH,OAAO,OAAO,OAAA,EAIX;AACD,IAAA,MAAM,EAAE,MAAA,EAAQ,SAAA,EAAW,QAAA,EAAS,GAAI,OAAA;AACxC,IAAA,MAAM,mBAAmB,IAAI,gBAAA,CAAiB,EAAE,SAAA,EAAW,QAAQ,CAAA;AACnE,IAAA,OAAO,IAAI,qBAAA,CAAsB,gBAAA,EAAkB,QAAQ,CAAA;AAAA,EAC7D;AAAA,EAEA,MAAM,UACJ,OAAA,EACsC;AACtC,IAAA,MAAM,QAAA,GAAW,MAAM,IAAA,CAAK,gBAAA,CAAiB,SAAA;AAAA,MAC3C,CAAC,OAAO,CAAA;AAAA,MACR,MAAM,IAAA,CAAK,WAAA,CAAY,cAAA;AAAe,KACxC;AACA,IAAA,OAAO,SAAS,CAAC,CAAA;AAAA,EACnB;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"PermissionApi.esm.js","sources":["../../src/apis/PermissionApi.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n EvaluatePermissionRequest,\n EvaluatePermissionResponse,\n} from '@backstage/plugin-permission-common';\nimport { ApiRef, createApiRef } from '@backstage/core-plugin-api';\n\n/**\n * This API is used by various frontend utilities that allow developers to implement authorization within their frontend\n * plugins. A plugin developer will likely not have to interact with this API or its implementations directly, but\n * rather with the aforementioned utility components/hooks.\n * @public\n */\nexport type PermissionApi = {\n authorize(\n request: EvaluatePermissionRequest,\n ): Promise<EvaluatePermissionResponse>;\n};\n\n/**\n * A Backstage ApiRef for the Permission API. See https://backstage.io/docs/api/utility-apis for more information on\n * Backstage ApiRefs.\n * @public\n */\nexport const permissionApiRef: ApiRef<PermissionApi> = createApiRef({\n id: 'plugin.permission.api',\n});\n"],"names":[],"mappings":";;AAuCO,MAAM,mBAA0C,YAAa,CAAA;AAAA,EAClE,EAAI,EAAA;AACN,CAAC;;;;"}
1
+ {"version":3,"file":"PermissionApi.esm.js","sources":["../../src/apis/PermissionApi.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n EvaluatePermissionRequest,\n EvaluatePermissionResponse,\n} from '@backstage/plugin-permission-common';\nimport { ApiRef, createApiRef } from '@backstage/core-plugin-api';\n\n/**\n * This API is used by various frontend utilities that allow developers to implement authorization within their frontend\n * plugins. A plugin developer will likely not have to interact with this API or its implementations directly, but\n * rather with the aforementioned utility components/hooks.\n * @public\n */\nexport type PermissionApi = {\n authorize(\n request: EvaluatePermissionRequest,\n ): Promise<EvaluatePermissionResponse>;\n};\n\n/**\n * A Backstage ApiRef for the Permission API. See https://backstage.io/docs/api/utility-apis for more information on\n * Backstage ApiRefs.\n * @public\n */\nexport const permissionApiRef: ApiRef<PermissionApi> = createApiRef({\n id: 'plugin.permission.api',\n});\n"],"names":[],"mappings":";;AAuCO,MAAM,mBAA0C,YAAA,CAAa;AAAA,EAClE,EAAA,EAAI;AACN,CAAC;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"PermissionedRoute.esm.js","sources":["../../src/components/PermissionedRoute.tsx"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ReactElement, ReactNode } from 'react';\nimport { Route } from 'react-router-dom';\nimport { useApp } from '@backstage/core-plugin-api';\nimport { usePermission } from '../hooks';\nimport {\n isResourcePermission,\n Permission,\n ResourcePermission,\n} from '@backstage/plugin-permission-common';\n\n/**\n * Returns a React Router Route which only renders the element when authorized. If unauthorized, the Route will render a\n * NotFoundErrorPage (see {@link @backstage/core-app-api#AppComponents}).\n *\n * @public\n * @deprecated This component no longer works with the most recent version of `@backstage/core-app-api` and react-router v6, use {@link RequirePermission} instead.\n */\nexport const PermissionedRoute = (\n props: {\n caseSensitive?: boolean;\n children?: ReactNode;\n element?: ReactElement | null;\n path?: string;\n errorComponent?: ReactElement | null;\n } & (\n | {\n permission: Exclude<Permission, ResourcePermission>;\n resourceRef?: never;\n }\n | {\n permission: ResourcePermission;\n resourceRef: string | undefined;\n }\n ),\n) => {\n const { permission, resourceRef, errorComponent, ...otherProps } = props;\n\n const permissionResult = usePermission(\n isResourcePermission(permission)\n ? { permission, resourceRef }\n : { permission },\n );\n const app = useApp();\n const { NotFoundErrorPage } = app.getComponents();\n\n let shownElement: ReactElement | null | undefined =\n errorComponent === undefined ? <NotFoundErrorPage /> : errorComponent;\n\n if (permissionResult.loading) {\n shownElement = null;\n } else if (permissionResult.allowed) {\n shownElement = props.element;\n }\n\n return <Route {...otherProps} element={shownElement} />;\n};\n"],"names":[],"mappings":";;;;;;AAiCa,MAAA,iBAAA,GAAoB,CAC/B,KAgBG,KAAA;AACH,EAAA,MAAM,EAAE,UAAY,EAAA,WAAA,EAAa,cAAgB,EAAA,GAAG,YAAe,GAAA,KAAA;AAEnE,EAAA,MAAM,gBAAmB,GAAA,aAAA;AAAA,IACvB,oBAAA,CAAqB,UAAU,CAC3B,GAAA,EAAE,YAAY,WAAY,EAAA,GAC1B,EAAE,UAAW;AAAA,GACnB;AACA,EAAA,MAAM,MAAM,MAAO,EAAA;AACnB,EAAA,MAAM,EAAE,iBAAA,EAAsB,GAAA,GAAA,CAAI,aAAc,EAAA;AAEhD,EAAA,IAAI,YACF,GAAA,cAAA,KAAmB,KAAY,CAAA,mBAAA,GAAA,CAAC,qBAAkB,CAAK,GAAA,cAAA;AAEzD,EAAA,IAAI,iBAAiB,OAAS,EAAA;AAC5B,IAAe,YAAA,GAAA,IAAA;AAAA,GACjB,MAAA,IAAW,iBAAiB,OAAS,EAAA;AACnC,IAAA,YAAA,GAAe,KAAM,CAAA,OAAA;AAAA;AAGvB,EAAA,uBAAQ,GAAA,CAAA,KAAA,EAAA,EAAO,GAAG,UAAA,EAAY,SAAS,YAAc,EAAA,CAAA;AACvD;;;;"}
1
+ {"version":3,"file":"PermissionedRoute.esm.js","sources":["../../src/components/PermissionedRoute.tsx"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ReactElement, ReactNode } from 'react';\nimport { Route } from 'react-router-dom';\nimport { useApp } from '@backstage/core-plugin-api';\nimport { usePermission } from '../hooks';\nimport {\n isResourcePermission,\n Permission,\n ResourcePermission,\n} from '@backstage/plugin-permission-common';\n\n/**\n * Returns a React Router Route which only renders the element when authorized. If unauthorized, the Route will render a\n * NotFoundErrorPage (see {@link @backstage/core-app-api#AppComponents}).\n *\n * @public\n * @deprecated This component no longer works with the most recent version of `@backstage/core-app-api` and react-router v6, use {@link RequirePermission} instead.\n */\nexport const PermissionedRoute = (\n props: {\n caseSensitive?: boolean;\n children?: ReactNode;\n element?: ReactElement | null;\n path?: string;\n errorComponent?: ReactElement | null;\n } & (\n | {\n permission: Exclude<Permission, ResourcePermission>;\n resourceRef?: never;\n }\n | {\n permission: ResourcePermission;\n resourceRef: string | undefined;\n }\n ),\n) => {\n const { permission, resourceRef, errorComponent, ...otherProps } = props;\n\n const permissionResult = usePermission(\n isResourcePermission(permission)\n ? { permission, resourceRef }\n : { permission },\n );\n const app = useApp();\n const { NotFoundErrorPage } = app.getComponents();\n\n let shownElement: ReactElement | null | undefined =\n errorComponent === undefined ? <NotFoundErrorPage /> : errorComponent;\n\n if (permissionResult.loading) {\n shownElement = null;\n } else if (permissionResult.allowed) {\n shownElement = props.element;\n }\n\n return <Route {...otherProps} element={shownElement} />;\n};\n"],"names":[],"mappings":";;;;;;AAiCO,MAAM,iBAAA,GAAoB,CAC/B,KAAA,KAgBG;AACH,EAAA,MAAM,EAAE,UAAA,EAAY,WAAA,EAAa,cAAA,EAAgB,GAAG,YAAW,GAAI,KAAA;AAEnE,EAAA,MAAM,gBAAA,GAAmB,aAAA;AAAA,IACvB,oBAAA,CAAqB,UAAU,CAAA,GAC3B,EAAE,YAAY,WAAA,EAAY,GAC1B,EAAE,UAAA;AAAW,GACnB;AACA,EAAA,MAAM,MAAM,MAAA,EAAO;AACnB,EAAA,MAAM,EAAE,iBAAA,EAAkB,GAAI,GAAA,CAAI,aAAA,EAAc;AAEhD,EAAA,IAAI,YAAA,GACF,cAAA,KAAmB,MAAA,mBAAY,GAAA,CAAC,qBAAkB,CAAA,GAAK,cAAA;AAEzD,EAAA,IAAI,iBAAiB,OAAA,EAAS;AAC5B,IAAA,YAAA,GAAe,IAAA;AAAA,EACjB,CAAA,MAAA,IAAW,iBAAiB,OAAA,EAAS;AACnC,IAAA,YAAA,GAAe,KAAA,CAAM,OAAA;AAAA,EACvB;AAEA,EAAA,uBAAO,GAAA,CAAC,KAAA,EAAA,EAAO,GAAG,UAAA,EAAY,SAAS,YAAA,EAAc,CAAA;AACvD;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"RequirePermission.esm.js","sources":["../../src/components/RequirePermission.tsx"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ReactNode } from 'react';\nimport { useApp } from '@backstage/core-plugin-api';\nimport { usePermission } from '../hooks';\nimport {\n isResourcePermission,\n Permission,\n ResourcePermission,\n} from '@backstage/plugin-permission-common';\n\n/**\n * Properties for {@link RequirePermission}\n *\n * @public\n */\nexport type RequirePermissionProps = (\n | {\n permission: Exclude<Permission, ResourcePermission>;\n resourceRef?: never;\n }\n | {\n permission: ResourcePermission;\n resourceRef: string | undefined;\n }\n) & {\n /**\n * The error page to be displayed if the user is not allowed access.\n *\n * Defaults to the `NotFoundErrorPage` app component.\n */\n errorPage?: ReactNode;\n children: ReactNode;\n};\n\n/**\n * A boundary that only renders its child elements if the user has the specified permission.\n *\n * While loading, nothing will be rendered. If the user does not have\n * permission, the `errorPage` element will be rendered, falling back\n * to the `NotFoundErrorPage` app component if no `errorPage` is provider.\n *\n * @public\n */\nexport function RequirePermission(\n props: RequirePermissionProps,\n): JSX.Element | null {\n const { permission, resourceRef } = props;\n const permissionResult = usePermission(\n isResourcePermission(permission)\n ? { permission, resourceRef }\n : { permission },\n );\n const app = useApp();\n\n if (permissionResult.loading) {\n return null;\n } else if (permissionResult.allowed) {\n return <>{props.children}</>;\n }\n\n if (props.errorPage) {\n return <>{props.errorPage}</>;\n }\n // If no explicit error element is provided, the not found page is used as fallback.\n const { NotFoundErrorPage } = app.getComponents();\n return <NotFoundErrorPage />;\n}\n"],"names":[],"mappings":";;;;;AA0DO,SAAS,kBACd,KACoB,EAAA;AACpB,EAAM,MAAA,EAAE,UAAY,EAAA,WAAA,EAAgB,GAAA,KAAA;AACpC,EAAA,MAAM,gBAAmB,GAAA,aAAA;AAAA,IACvB,oBAAA,CAAqB,UAAU,CAC3B,GAAA,EAAE,YAAY,WAAY,EAAA,GAC1B,EAAE,UAAW;AAAA,GACnB;AACA,EAAA,MAAM,MAAM,MAAO,EAAA;AAEnB,EAAA,IAAI,iBAAiB,OAAS,EAAA;AAC5B,IAAO,OAAA,IAAA;AAAA,GACT,MAAA,IAAW,iBAAiB,OAAS,EAAA;AACnC,IAAO,uBAAA,GAAA,CAAA,QAAA,EAAA,EAAG,gBAAM,QAAS,EAAA,CAAA;AAAA;AAG3B,EAAA,IAAI,MAAM,SAAW,EAAA;AACnB,IAAO,uBAAA,GAAA,CAAA,QAAA,EAAA,EAAG,gBAAM,SAAU,EAAA,CAAA;AAAA;AAG5B,EAAA,MAAM,EAAE,iBAAA,EAAsB,GAAA,GAAA,CAAI,aAAc,EAAA;AAChD,EAAA,2BAAQ,iBAAkB,EAAA,EAAA,CAAA;AAC5B;;;;"}
1
+ {"version":3,"file":"RequirePermission.esm.js","sources":["../../src/components/RequirePermission.tsx"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ReactNode } from 'react';\nimport { useApp } from '@backstage/core-plugin-api';\nimport { usePermission } from '../hooks';\nimport {\n isResourcePermission,\n Permission,\n ResourcePermission,\n} from '@backstage/plugin-permission-common';\n\n/**\n * Properties for {@link RequirePermission}\n *\n * @public\n */\nexport type RequirePermissionProps = (\n | {\n permission: Exclude<Permission, ResourcePermission>;\n resourceRef?: never;\n }\n | {\n permission: ResourcePermission;\n resourceRef: string | undefined;\n }\n) & {\n /**\n * The error page to be displayed if the user is not allowed access.\n *\n * Defaults to the `NotFoundErrorPage` app component.\n */\n errorPage?: ReactNode;\n children: ReactNode;\n};\n\n/**\n * A boundary that only renders its child elements if the user has the specified permission.\n *\n * While loading, nothing will be rendered. If the user does not have\n * permission, the `errorPage` element will be rendered, falling back\n * to the `NotFoundErrorPage` app component if no `errorPage` is provider.\n *\n * @public\n */\nexport function RequirePermission(\n props: RequirePermissionProps,\n): JSX.Element | null {\n const { permission, resourceRef } = props;\n const permissionResult = usePermission(\n isResourcePermission(permission)\n ? { permission, resourceRef }\n : { permission },\n );\n const app = useApp();\n\n if (permissionResult.loading) {\n return null;\n } else if (permissionResult.allowed) {\n return <>{props.children}</>;\n }\n\n if (props.errorPage) {\n return <>{props.errorPage}</>;\n }\n // If no explicit error element is provided, the not found page is used as fallback.\n const { NotFoundErrorPage } = app.getComponents();\n return <NotFoundErrorPage />;\n}\n"],"names":[],"mappings":";;;;;AA0DO,SAAS,kBACd,KAAA,EACoB;AACpB,EAAA,MAAM,EAAE,UAAA,EAAY,WAAA,EAAY,GAAI,KAAA;AACpC,EAAA,MAAM,gBAAA,GAAmB,aAAA;AAAA,IACvB,oBAAA,CAAqB,UAAU,CAAA,GAC3B,EAAE,YAAY,WAAA,EAAY,GAC1B,EAAE,UAAA;AAAW,GACnB;AACA,EAAA,MAAM,MAAM,MAAA,EAAO;AAEnB,EAAA,IAAI,iBAAiB,OAAA,EAAS;AAC5B,IAAA,OAAO,IAAA;AAAA,EACT,CAAA,MAAA,IAAW,iBAAiB,OAAA,EAAS;AACnC,IAAA,uBAAO,GAAA,CAAA,QAAA,EAAA,EAAG,gBAAM,QAAA,EAAS,CAAA;AAAA,EAC3B;AAEA,EAAA,IAAI,MAAM,SAAA,EAAW;AACnB,IAAA,uBAAO,GAAA,CAAA,QAAA,EAAA,EAAG,gBAAM,SAAA,EAAU,CAAA;AAAA,EAC5B;AAEA,EAAA,MAAM,EAAE,iBAAA,EAAkB,GAAI,GAAA,CAAI,aAAA,EAAc;AAChD,EAAA,2BAAQ,iBAAA,EAAA,EAAkB,CAAA;AAC5B;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"usePermission.esm.js","sources":["../../src/hooks/usePermission.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useApi } from '@backstage/core-plugin-api';\nimport { permissionApiRef } from '../apis';\nimport {\n AuthorizeResult,\n isResourcePermission,\n Permission,\n ResourcePermission,\n} from '@backstage/plugin-permission-common';\nimport useSWR from 'swr';\n\n/** @public */\nexport type AsyncPermissionResult = {\n loading: boolean;\n allowed: boolean;\n error?: Error;\n};\n\n/**\n * React hook utility for authorization. Given either a non-resource\n * {@link @backstage/plugin-permission-common#Permission} or a\n * {@link @backstage/plugin-permission-common#ResourcePermission} and an\n * optional resourceRef, it will return whether or not access is allowed (for\n * the given resource, if resourceRef is provided). See\n * {@link @backstage/plugin-permission-common/PermissionClient#authorize} for\n * more details.\n *\n * The resourceRef field is optional to allow calling this hook with an\n * entity that might be loading asynchronously, but when resourceRef is not\n * supplied, the value of `allowed` will always be false.\n *\n * Note: This hook uses stale-while-revalidate to help avoid flicker in UI\n * elements that would be conditionally rendered based on the `allowed` result\n * of this hook.\n * @public\n */\nexport function usePermission(\n input:\n | {\n permission: Exclude<Permission, ResourcePermission>;\n resourceRef?: never;\n }\n | {\n permission: ResourcePermission;\n resourceRef: string | undefined;\n },\n): AsyncPermissionResult {\n const permissionApi = useApi(permissionApiRef);\n const { data, error } = useSWR(input, async (args: typeof input) => {\n // We could make the resourceRef parameter required to avoid this check, but\n // it would make using this hook difficult in situations where the entity\n // must be asynchronously loaded, so instead we short-circuit to a deny when\n // no resourceRef is supplied, on the assumption that the resourceRef is\n // still loading outside the hook.\n if (isResourcePermission(args.permission) && !args.resourceRef) {\n return AuthorizeResult.DENY;\n }\n\n const { result } = await permissionApi.authorize(args);\n return result;\n });\n\n if (error) {\n return { error, loading: false, allowed: false };\n }\n if (data === undefined) {\n return { loading: true, allowed: false };\n }\n return { loading: false, allowed: data === AuthorizeResult.ALLOW };\n}\n"],"names":[],"mappings":";;;;;AAmDO,SAAS,cACd,KASuB,EAAA;AACvB,EAAM,MAAA,aAAA,GAAgB,OAAO,gBAAgB,CAAA;AAC7C,EAAA,MAAM,EAAE,IAAM,EAAA,KAAA,KAAU,MAAO,CAAA,KAAA,EAAO,OAAO,IAAuB,KAAA;AAMlE,IAAA,IAAI,qBAAqB,IAAK,CAAA,UAAU,CAAK,IAAA,CAAC,KAAK,WAAa,EAAA;AAC9D,MAAA,OAAO,eAAgB,CAAA,IAAA;AAAA;AAGzB,IAAA,MAAM,EAAE,MAAO,EAAA,GAAI,MAAM,aAAA,CAAc,UAAU,IAAI,CAAA;AACrD,IAAO,OAAA,MAAA;AAAA,GACR,CAAA;AAED,EAAA,IAAI,KAAO,EAAA;AACT,IAAA,OAAO,EAAE,KAAA,EAAO,OAAS,EAAA,KAAA,EAAO,SAAS,KAAM,EAAA;AAAA;AAEjD,EAAA,IAAI,SAAS,KAAW,CAAA,EAAA;AACtB,IAAA,OAAO,EAAE,OAAA,EAAS,IAAM,EAAA,OAAA,EAAS,KAAM,EAAA;AAAA;AAEzC,EAAA,OAAO,EAAE,OAAS,EAAA,KAAA,EAAO,OAAS,EAAA,IAAA,KAAS,gBAAgB,KAAM,EAAA;AACnE;;;;"}
1
+ {"version":3,"file":"usePermission.esm.js","sources":["../../src/hooks/usePermission.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useApi } from '@backstage/core-plugin-api';\nimport { permissionApiRef } from '../apis';\nimport {\n AuthorizeResult,\n isResourcePermission,\n Permission,\n ResourcePermission,\n} from '@backstage/plugin-permission-common';\nimport useSWR from 'swr';\n\n/** @public */\nexport type AsyncPermissionResult = {\n loading: boolean;\n allowed: boolean;\n error?: Error;\n};\n\n/**\n * React hook utility for authorization. Given either a non-resource\n * {@link @backstage/plugin-permission-common#Permission} or a\n * {@link @backstage/plugin-permission-common#ResourcePermission} and an\n * optional resourceRef, it will return whether or not access is allowed (for\n * the given resource, if resourceRef is provided). See\n * {@link @backstage/plugin-permission-common/PermissionClient#authorize} for\n * more details.\n *\n * The resourceRef field is optional to allow calling this hook with an\n * entity that might be loading asynchronously, but when resourceRef is not\n * supplied, the value of `allowed` will always be false.\n *\n * Note: This hook uses stale-while-revalidate to help avoid flicker in UI\n * elements that would be conditionally rendered based on the `allowed` result\n * of this hook.\n * @public\n */\nexport function usePermission(\n input:\n | {\n permission: Exclude<Permission, ResourcePermission>;\n resourceRef?: never;\n }\n | {\n permission: ResourcePermission;\n resourceRef: string | undefined;\n },\n): AsyncPermissionResult {\n const permissionApi = useApi(permissionApiRef);\n const { data, error } = useSWR(input, async (args: typeof input) => {\n // We could make the resourceRef parameter required to avoid this check, but\n // it would make using this hook difficult in situations where the entity\n // must be asynchronously loaded, so instead we short-circuit to a deny when\n // no resourceRef is supplied, on the assumption that the resourceRef is\n // still loading outside the hook.\n if (isResourcePermission(args.permission) && !args.resourceRef) {\n return AuthorizeResult.DENY;\n }\n\n const { result } = await permissionApi.authorize(args);\n return result;\n });\n\n if (error) {\n return { error, loading: false, allowed: false };\n }\n if (data === undefined) {\n return { loading: true, allowed: false };\n }\n return { loading: false, allowed: data === AuthorizeResult.ALLOW };\n}\n"],"names":[],"mappings":";;;;;AAmDO,SAAS,cACd,KAAA,EASuB;AACvB,EAAA,MAAM,aAAA,GAAgB,OAAO,gBAAgB,CAAA;AAC7C,EAAA,MAAM,EAAE,IAAA,EAAM,KAAA,KAAU,MAAA,CAAO,KAAA,EAAO,OAAO,IAAA,KAAuB;AAMlE,IAAA,IAAI,qBAAqB,IAAA,CAAK,UAAU,CAAA,IAAK,CAAC,KAAK,WAAA,EAAa;AAC9D,MAAA,OAAO,eAAA,CAAgB,IAAA;AAAA,IACzB;AAEA,IAAA,MAAM,EAAE,MAAA,EAAO,GAAI,MAAM,aAAA,CAAc,UAAU,IAAI,CAAA;AACrD,IAAA,OAAO,MAAA;AAAA,EACT,CAAC,CAAA;AAED,EAAA,IAAI,KAAA,EAAO;AACT,IAAA,OAAO,EAAE,KAAA,EAAO,OAAA,EAAS,KAAA,EAAO,SAAS,KAAA,EAAM;AAAA,EACjD;AACA,EAAA,IAAI,SAAS,MAAA,EAAW;AACtB,IAAA,OAAO,EAAE,OAAA,EAAS,IAAA,EAAM,OAAA,EAAS,KAAA,EAAM;AAAA,EACzC;AACA,EAAA,OAAO,EAAE,OAAA,EAAS,KAAA,EAAO,OAAA,EAAS,IAAA,KAAS,gBAAgB,KAAA,EAAM;AACnE;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-permission-react",
3
- "version": "0.4.36-next.0",
3
+ "version": "0.4.37-next.0",
4
4
  "backstage": {
5
5
  "role": "web-library",
6
6
  "pluginId": "permission",
@@ -42,14 +42,14 @@
42
42
  "test": "backstage-cli package test"
43
43
  },
44
44
  "dependencies": {
45
- "@backstage/config": "1.3.3-next.0",
46
- "@backstage/core-plugin-api": "1.10.9-next.0",
47
- "@backstage/plugin-permission-common": "0.9.1-next.0",
45
+ "@backstage/config": "1.3.4-next.0",
46
+ "@backstage/core-plugin-api": "1.11.1-next.0",
47
+ "@backstage/plugin-permission-common": "0.9.2-next.0",
48
48
  "swr": "^2.0.0"
49
49
  },
50
50
  "devDependencies": {
51
- "@backstage/cli": "0.33.1-next.1",
52
- "@backstage/test-utils": "1.7.10-next.1",
51
+ "@backstage/cli": "0.34.4-next.1",
52
+ "@backstage/test-utils": "1.7.12-next.0",
53
53
  "@testing-library/jest-dom": "^6.0.0",
54
54
  "@testing-library/react": "^16.0.0",
55
55
  "@types/react": "^18.0.0",