@backstage/plugin-permission-react 0.0.0-nightly-20260919022921 → 0.0.0-nightly-20260920023043
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,13 +1,13 @@
|
|
|
1
1
|
# @backstage/plugin-permission-react
|
|
2
2
|
|
|
3
|
-
## 0.0.0-nightly-
|
|
3
|
+
## 0.0.0-nightly-20260920023043
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
7
|
- Updated dependencies
|
|
8
|
-
- @backstage/config@0.0.0-nightly-
|
|
9
|
-
- @backstage/core-plugin-api@0.0.0-nightly-
|
|
10
|
-
- @backstage/plugin-permission-common@0.0.0-nightly-
|
|
8
|
+
- @backstage/config@0.0.0-nightly-20260920023043
|
|
9
|
+
- @backstage/core-plugin-api@0.0.0-nightly-20260920023043
|
|
10
|
+
- @backstage/plugin-permission-common@0.0.0-nightly-20260920023043
|
|
11
11
|
|
|
12
12
|
## 0.5.5
|
|
13
13
|
|
|
@@ -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 DataLoader from 'dataloader';\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 batches calls to\n * {@link @backstage/plugin-permission-common#PermissionClient} that are made\n * within the same microtask into a single HTTP request.\n * @public\n */\nexport class IdentityPermissionApi implements PermissionApi {\n private readonly loader: DataLoader<\n AuthorizePermissionRequest,\n AuthorizePermissionResponse\n >;\n\n private constructor(\n permissionClient: PermissionClient,\n identityApi: IdentityApi,\n ) {\n this.loader = new DataLoader(\n async (requests: readonly AuthorizePermissionRequest[]) => {\n const credentials = await identityApi.getCredentials();\n return permissionClient.authorize([...requests], credentials);\n },\n {\n cache: false,\n },\n );\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 async authorize(\n request: AuthorizePermissionRequest,\n ): Promise<AuthorizePermissionResponse> {\n return await this.loader.load(request);\n }\n}\n"],"names":[],"mappings":";;;AAgCO,MAAM,qBAAA,CAA+C;AAAA,EACzC,MAAA;AAAA,EAKT,WAAA,CACN,kBACA,WAAA,EACA;AACA,IAAA,IAAA,CAAK,SAAS,IAAI,UAAA;AAAA,MAChB,OAAO,QAAA,KAAoD;AACzD,QAAA,MAAM,WAAA,GAAc,MAAM,WAAA,CAAY,cAAA,EAAe;AACrD,QAAA,OAAO,iBAAiB,SAAA,CAAU,CAAC,GAAG,QAAQ,GAAG,WAAW,CAAA;AAAA,MAC9D,CAAA;AAAA,MACA;AAAA,QACE,KAAA,EAAO;AAAA;AACT,KACF;AAAA,EACF;AAAA,EAEA,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,EAKA,MAAM,UACJ,OAAA,EACsC;AACtC,IAAA,OAAO,MAAM,IAAA,CAAK,MAAA,CAAO,IAAA,CAAK,OAAO,CAAA;AAAA,EACvC;AACF
|
|
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 DataLoader from 'dataloader';\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 batches calls to\n * {@link @backstage/plugin-permission-common#PermissionClient} that are made\n * within the same microtask into a single HTTP request.\n * @public\n */\nexport class IdentityPermissionApi implements PermissionApi {\n private readonly loader: DataLoader<\n AuthorizePermissionRequest,\n AuthorizePermissionResponse\n >;\n\n private constructor(\n permissionClient: PermissionClient,\n identityApi: IdentityApi,\n ) {\n this.loader = new DataLoader(\n async (requests: readonly AuthorizePermissionRequest[]) => {\n const credentials = await identityApi.getCredentials();\n return permissionClient.authorize([...requests], credentials);\n },\n {\n cache: false,\n },\n );\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 async authorize(\n request: AuthorizePermissionRequest,\n ): Promise<AuthorizePermissionResponse> {\n return await this.loader.load(request);\n }\n}\n"],"names":[],"mappings":";;;AAgCO,MAAM,qBAAA,CAA+C;AAAA,EACzC,MAAA;AAAA,EAKT,WAAA,CACN,kBACA,WAAA,EACA;AACA,IAAA,IAAA,CAAK,SAAS,IAAI,UAAA;AAAA,MAChB,OAAO,QAAA,KAAoD;AACzD,QAAA,MAAM,WAAA,GAAc,MAAM,WAAA,CAAY,cAAA,EAAe;AACrD,QAAA,OAAO,iBAAiB,SAAA,CAAU,CAAC,GAAG,QAAQ,GAAG,WAAW,CAAA;AAAA,MAC9D,CAAA;AAAA,MACA;AAAA,QACE,KAAA,EAAO;AAAA;AACT,KACF;AAAA,EACF;AAAA,EAEA,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,EAKA,MAAM,UACJ,OAAA,EACsC;AACtC,IAAA,OAAO,MAAM,IAAA,CAAK,MAAA,CAAO,IAAA,CAAK,OAAO,CAAA;AAAA,EACvC;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,EAAA,EAAI;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":"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
|
+
{"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,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
|
|
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.0.0-nightly-
|
|
3
|
+
"version": "0.0.0-nightly-20260920023043",
|
|
4
4
|
"backstage": {
|
|
5
5
|
"role": "web-library",
|
|
6
6
|
"pluginId": "permission",
|
|
@@ -42,15 +42,15 @@
|
|
|
42
42
|
"test": "backstage-cli package test"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@backstage/config": "0.0.0-nightly-
|
|
46
|
-
"@backstage/core-plugin-api": "0.0.0-nightly-
|
|
47
|
-
"@backstage/plugin-permission-common": "0.0.0-nightly-
|
|
45
|
+
"@backstage/config": "0.0.0-nightly-20260920023043",
|
|
46
|
+
"@backstage/core-plugin-api": "0.0.0-nightly-20260920023043",
|
|
47
|
+
"@backstage/plugin-permission-common": "0.0.0-nightly-20260920023043",
|
|
48
48
|
"dataloader": "^2.0.0",
|
|
49
49
|
"swr": "^2.0.0"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@backstage/cli": "0.0.0-nightly-
|
|
53
|
-
"@backstage/test-utils": "0.0.0-nightly-
|
|
52
|
+
"@backstage/cli": "0.0.0-nightly-20260920023043",
|
|
53
|
+
"@backstage/test-utils": "0.0.0-nightly-20260920023043",
|
|
54
54
|
"@testing-library/dom": "^10.0.0",
|
|
55
55
|
"@testing-library/jest-dom": "^6.0.0",
|
|
56
56
|
"@testing-library/react": "^16.0.0",
|