diff --git a/plugins/permission-node/src/integration/createConditionExports.test.ts b/plugins/permission-node/src/integration/createConditionExports.test.ts index 424b3c3c24..dad57e2b8b 100644 --- a/plugins/permission-node/src/integration/createConditionExports.test.ts +++ b/plugins/permission-node/src/integration/createConditionExports.test.ts @@ -46,7 +46,7 @@ const testIntegration = () => description: 'Test rule 2', resourceType: 'test-resource', paramsSchema: z.object({ - foo: z.string(), + foo: z.string().optional(), }), apply: (_resource: any) => false, toQuery: params => ({ @@ -76,12 +76,10 @@ describe('createConditionExports', () => { }, }); - expect(conditions.testRule2({ foo: 'baz' })).toEqual({ + expect(conditions.testRule2({})).toEqual({ rule: 'testRule2', resourceType: 'test-resource', - params: { - foo: 'baz', - }, + params: {}, }); }); }); diff --git a/plugins/permission-node/src/types.ts b/plugins/permission-node/src/types.ts index 6b15df407e..36e30714f6 100644 --- a/plugins/permission-node/src/types.ts +++ b/plugins/permission-node/src/types.ts @@ -21,22 +21,6 @@ import type { import { z } from 'zod'; import { NoInfer } from './integration/util'; -/** - * A ZodSchema that reflects the structure of the parameters that are passed to - * into a {@link PermissionRule}. - * - * @public - */ -export type PermissionRuleSchema = z.ZodObject<{ - // Parameters can be optional, however we we want to make sure that the - // parameters are always present in the schema, even if they are undefined. - // We remove the optional flag from the schema, and then add it back in - // with an optional zod type. - [P in keyof TParams]-?: TParams[P] extends undefined - ? z.ZodOptionalType> - : z.ZodType; -}>; - /** * A conditional rule that can be provided in an * {@link @backstage/permission-common#AuthorizeDecision} response to an authorization request. @@ -66,24 +50,19 @@ export type PermissionRule< /** * A ZodSchema that reflects the structure of the parameters that are passed to */ - paramsSchema?: PermissionRuleSchema; + paramsSchema?: z.ZodSchema; /** * Apply this rule to a resource already loaded from a backing data source. The params are * arguments supplied for the rule; for example, a rule could be `isOwner` with entityRefs as the * params. */ - apply( - resource: TResource, - params: NoInfer>>, - ): boolean; + apply(resource: TResource, params: NoInfer): boolean; /** * Translate this rule to criteria suitable for use in querying a backing data store. The criteria * can be used for loading a collection of resources efficiently with conditional criteria already * applied. */ - toQuery( - params: NoInfer>>, - ): PermissionCriteria; + toQuery(params: NoInfer): PermissionCriteria; };