From 137fa342b4bf43c91e91d3b0b947b8d37c9e233e Mon Sep 17 00:00:00 2001 From: MT Lewis Date: Sun, 28 Jul 2024 14:00:10 +0100 Subject: [PATCH] permission-common: add MetadataResponseSerializedRule from permission-node Signed-off-by: MT Lewis --- .changeset/nine-seahorses-relate.md | 5 ++++ plugins/permission-common/api-report.md | 9 ++++++ plugins/permission-common/package.json | 3 +- plugins/permission-common/src/types/index.ts | 1 + .../src/types/integration.ts | 30 +++++++++++++++++++ yarn.lock | 1 + 6 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 .changeset/nine-seahorses-relate.md create mode 100644 plugins/permission-common/src/types/integration.ts diff --git a/.changeset/nine-seahorses-relate.md b/.changeset/nine-seahorses-relate.md new file mode 100644 index 0000000000..9a5bb43823 --- /dev/null +++ b/.changeset/nine-seahorses-relate.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-permission-common': patch +--- + +Add the MetadataResponseSerializedRule type from @backstage/plugin-permission-node, since this type might be used in frontend code. diff --git a/plugins/permission-common/api-report.md b/plugins/permission-common/api-report.md index e9935c612d..12dd49d090 100644 --- a/plugins/permission-common/api-report.md +++ b/plugins/permission-common/api-report.md @@ -5,6 +5,7 @@ ```ts import { Config } from '@backstage/config'; import { JsonPrimitive } from '@backstage/types'; +import zodToJsonSchema from 'zod-to-json-schema'; // @public export type AllOfCriteria = { @@ -125,6 +126,14 @@ export function isResourcePermission( // @public export function isUpdatePermission(permission: Permission): boolean; +// @public +export type MetadataResponseSerializedRule = { + name: string; + description: string; + resourceType: string; + paramsSchema?: ReturnType; +}; + // @public export type NotCriteria = { not: PermissionCriteria; diff --git a/plugins/permission-common/package.json b/plugins/permission-common/package.json index 8d6f54fac0..585fc00531 100644 --- a/plugins/permission-common/package.json +++ b/plugins/permission-common/package.json @@ -53,7 +53,8 @@ "@backstage/types": "workspace:^", "cross-fetch": "^4.0.0", "uuid": "^9.0.0", - "zod": "^3.22.4" + "zod": "^3.22.4", + "zod-to-json-schema": "^3.20.4" }, "devDependencies": { "@backstage/cli": "workspace:^", diff --git a/plugins/permission-common/src/types/index.ts b/plugins/permission-common/src/types/index.ts index 5702f47c1c..1d2243447f 100644 --- a/plugins/permission-common/src/types/index.ts +++ b/plugins/permission-common/src/types/index.ts @@ -40,6 +40,7 @@ export type { NotCriteria, } from './api'; export type { DiscoveryApi } from './discovery'; +export type { MetadataResponseSerializedRule } from './integration'; export type { BasicPermission, PermissionAttributes, diff --git a/plugins/permission-common/src/types/integration.ts b/plugins/permission-common/src/types/integration.ts new file mode 100644 index 0000000000..6c208bb775 --- /dev/null +++ b/plugins/permission-common/src/types/integration.ts @@ -0,0 +1,30 @@ +/* + * Copyright 2024 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import zodToJsonSchema from 'zod-to-json-schema'; + +/** + * Serialized permission rules, with the paramsSchema + * converted from a ZodSchema to a JsonSchema. + * + * @public + */ +export type MetadataResponseSerializedRule = { + name: string; + description: string; + resourceType: string; + paramsSchema?: ReturnType; +}; diff --git a/yarn.lock b/yarn.lock index ad55a72897..794f848f55 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6723,6 +6723,7 @@ __metadata: msw: ^1.0.0 uuid: ^9.0.0 zod: ^3.22.4 + zod-to-json-schema: ^3.20.4 languageName: unknown linkType: soft