diff --git a/packages/@n8n/api-types/src/dto/index.ts b/packages/@n8n/api-types/src/dto/index.ts index fbc7d78103c..ecf0d38bc2a 100644 --- a/packages/@n8n/api-types/src/dto/index.ts +++ b/packages/@n8n/api-types/src/dto/index.ts @@ -236,6 +236,27 @@ export { } from './log-streaming/public-destination.dto'; export { PaginationDto, MAX_ITEMS_PER_PAGE } from './pagination/pagination.dto'; + +export type { + NonDelegatingPolicyAction, + NonDelegatingPolicyRule, + PolicyAction, + PolicyRule, + PolicySelector, +} from './node-type-policies/policy-rule.types'; +export { policySelectorSchema } from './node-type-policies/policy-selector.schema'; +export { + nonDelegatingPolicyActionSchema, + nonDelegatingPolicyRuleListSchema, + policyActionSchema, + policyRuleListSchema, + policyRuleSchema, +} from './node-type-policies/policy-rule.schema'; +export { PutInstancePolicyDto } from './node-type-policies/put-instance-policy.dto'; +export { PutProjectPolicyDto } from './node-type-policies/put-project-policy.dto'; +export { CreatePolicyDocumentDto } from './node-type-policies/create-policy-document.dto'; +export { UpdatePolicyDocumentDto } from './node-type-policies/update-policy-document.dto'; +export { ReplaceAttachmentsDto } from './node-type-policies/replace-attachments.dto'; export { UsersListFilterDto, type UsersListSortOptions, diff --git a/packages/cli/src/modules/type-availability-policies/dto/__tests__/policy-rule.schema.test.ts b/packages/@n8n/api-types/src/dto/node-type-policies/__tests__/policy-rule.schema.test.ts similarity index 100% rename from packages/cli/src/modules/type-availability-policies/dto/__tests__/policy-rule.schema.test.ts rename to packages/@n8n/api-types/src/dto/node-type-policies/__tests__/policy-rule.schema.test.ts diff --git a/packages/cli/src/modules/type-availability-policies/dto/__tests__/policy-selector.schema.test.ts b/packages/@n8n/api-types/src/dto/node-type-policies/__tests__/policy-selector.schema.test.ts similarity index 100% rename from packages/cli/src/modules/type-availability-policies/dto/__tests__/policy-selector.schema.test.ts rename to packages/@n8n/api-types/src/dto/node-type-policies/__tests__/policy-selector.schema.test.ts diff --git a/packages/cli/src/modules/type-availability-policies/dto/__tests__/replace-attachments.dto.test.ts b/packages/@n8n/api-types/src/dto/node-type-policies/__tests__/replace-attachments.dto.test.ts similarity index 100% rename from packages/cli/src/modules/type-availability-policies/dto/__tests__/replace-attachments.dto.test.ts rename to packages/@n8n/api-types/src/dto/node-type-policies/__tests__/replace-attachments.dto.test.ts diff --git a/packages/cli/src/modules/type-availability-policies/dto/create-policy-document.dto.ts b/packages/@n8n/api-types/src/dto/node-type-policies/create-policy-document.dto.ts similarity index 84% rename from packages/cli/src/modules/type-availability-policies/dto/create-policy-document.dto.ts rename to packages/@n8n/api-types/src/dto/node-type-policies/create-policy-document.dto.ts index 2f1cf6129d0..58a6e5cc676 100644 --- a/packages/cli/src/modules/type-availability-policies/dto/create-policy-document.dto.ts +++ b/packages/@n8n/api-types/src/dto/node-type-policies/create-policy-document.dto.ts @@ -1,6 +1,5 @@ -import { Z } from '@n8n/api-types'; - import { policyRuleListSchema } from './policy-rule.schema'; +import { Z } from '../../zod-class'; /** Request body for creating a policy document. */ export class CreatePolicyDocumentDto extends Z.class({ diff --git a/packages/cli/src/modules/type-availability-policies/dto/policy-rule.schema.ts b/packages/@n8n/api-types/src/dto/node-type-policies/policy-rule.schema.ts similarity index 89% rename from packages/cli/src/modules/type-availability-policies/dto/policy-rule.schema.ts rename to packages/@n8n/api-types/src/dto/node-type-policies/policy-rule.schema.ts index caa70b6df5c..ede3d876357 100644 --- a/packages/cli/src/modules/type-availability-policies/dto/policy-rule.schema.ts +++ b/packages/@n8n/api-types/src/dto/node-type-policies/policy-rule.schema.ts @@ -5,11 +5,11 @@ import type { NonDelegatingPolicyRule, PolicyAction, PolicyRule, -} from '../policy-rule.types'; +} from './policy-rule.types'; import { policySelectorSchema } from './policy-selector.schema'; /** - * Zod counterpart of `PolicyAction` in `../policy-rule.types.ts`. The `satisfies` check + * Zod counterpart of `PolicyAction` in `./policy-rule.types.ts`. The `satisfies` check * keeps this schema honest against that type. */ export const policyActionSchema = z.enum([ @@ -19,7 +19,7 @@ export const policyActionSchema = z.enum([ ]) satisfies z.ZodType; /** - * Zod counterpart of `PolicyRule` in `../policy-rule.types.ts`. The `satisfies` check + * Zod counterpart of `PolicyRule` in `./policy-rule.types.ts`. The `satisfies` check * keeps this schema honest against that type. */ export const policyRuleSchema = z.object({ diff --git a/packages/@n8n/api-types/src/dto/node-type-policies/policy-rule.types.ts b/packages/@n8n/api-types/src/dto/node-type-policies/policy-rule.types.ts new file mode 100644 index 00000000000..645b19fb0e6 --- /dev/null +++ b/packages/@n8n/api-types/src/dto/node-type-policies/policy-rule.types.ts @@ -0,0 +1,29 @@ +/** + * Domain types for node type availability policies, shared by the internal and public API + * request DTOs and by the backend evaluator. + */ + +/** Matches a node type by its exact full name, or by its package segment. */ +export type PolicySelector = + | { readonly kind: 'name'; readonly value: string } + | { readonly kind: 'package'; readonly value: string }; + +export type PolicyAction = 'allow' | 'deny' | 'delegate'; + +/** One first-match rule within a policy document, in document order. */ +export type PolicyRule = { + readonly id: string; + readonly action: PolicyAction; + readonly selector: PolicySelector; +}; + +/** + * The actions a project scope accepts. `delegate` defers to a narrower scope, and none exists + * below project, so project-scope writes never accept it. + */ +export type NonDelegatingPolicyAction = Exclude; + +/** A `PolicyRule` as a project scope accepts it. */ +export type NonDelegatingPolicyRule = Omit & { + readonly action: NonDelegatingPolicyAction; +}; diff --git a/packages/cli/src/modules/type-availability-policies/dto/policy-selector.schema.ts b/packages/@n8n/api-types/src/dto/node-type-policies/policy-selector.schema.ts similarity index 73% rename from packages/cli/src/modules/type-availability-policies/dto/policy-selector.schema.ts rename to packages/@n8n/api-types/src/dto/node-type-policies/policy-selector.schema.ts index 93803850791..dbcc0e3d6f9 100644 --- a/packages/cli/src/modules/type-availability-policies/dto/policy-selector.schema.ts +++ b/packages/@n8n/api-types/src/dto/node-type-policies/policy-selector.schema.ts @@ -1,9 +1,9 @@ import { z } from 'zod'; -import type { PolicySelector } from '../policy-rule.types'; +import type { PolicySelector } from './policy-rule.types'; /** - * Zod counterpart of `PolicySelector` in `../policy-rule.types.ts`. The `satisfies` check + * Zod counterpart of `PolicySelector` in `./policy-rule.types.ts`. The `satisfies` check * keeps this schema honest against that type — it fails to compile if this schema ever * accepts a shape `PolicySelector` doesn't. */ diff --git a/packages/cli/src/modules/type-availability-policies/dto/put-instance-policy.dto.ts b/packages/@n8n/api-types/src/dto/node-type-policies/put-instance-policy.dto.ts similarity index 92% rename from packages/cli/src/modules/type-availability-policies/dto/put-instance-policy.dto.ts rename to packages/@n8n/api-types/src/dto/node-type-policies/put-instance-policy.dto.ts index 6e6568d383f..a8fb51996d0 100644 --- a/packages/cli/src/modules/type-availability-policies/dto/put-instance-policy.dto.ts +++ b/packages/@n8n/api-types/src/dto/node-type-policies/put-instance-policy.dto.ts @@ -1,7 +1,7 @@ -import { Z } from '@n8n/api-types'; import { z } from 'zod'; import { policyActionSchema, policyRuleListSchema } from './policy-rule.schema'; +import { Z } from '../../zod-class'; /** Request body for setting the composed instance policy. */ export class PutInstancePolicyDto extends Z.class({ diff --git a/packages/cli/src/modules/type-availability-policies/dto/put-project-policy.dto.ts b/packages/@n8n/api-types/src/dto/node-type-policies/put-project-policy.dto.ts similarity index 94% rename from packages/cli/src/modules/type-availability-policies/dto/put-project-policy.dto.ts rename to packages/@n8n/api-types/src/dto/node-type-policies/put-project-policy.dto.ts index 20c26b2f2c1..9bf2e27fc2a 100644 --- a/packages/cli/src/modules/type-availability-policies/dto/put-project-policy.dto.ts +++ b/packages/@n8n/api-types/src/dto/node-type-policies/put-project-policy.dto.ts @@ -1,10 +1,10 @@ -import { Z } from '@n8n/api-types'; import { z } from 'zod'; import { nonDelegatingPolicyActionSchema, nonDelegatingPolicyRuleListSchema, } from './policy-rule.schema'; +import { Z } from '../../zod-class'; /** * Request body for setting a project's composed policy. Same shape as diff --git a/packages/cli/src/modules/type-availability-policies/dto/replace-attachments.dto.ts b/packages/@n8n/api-types/src/dto/node-type-policies/replace-attachments.dto.ts similarity index 97% rename from packages/cli/src/modules/type-availability-policies/dto/replace-attachments.dto.ts rename to packages/@n8n/api-types/src/dto/node-type-policies/replace-attachments.dto.ts index ddb8b2f839c..47642331a36 100644 --- a/packages/cli/src/modules/type-availability-policies/dto/replace-attachments.dto.ts +++ b/packages/@n8n/api-types/src/dto/node-type-policies/replace-attachments.dto.ts @@ -1,6 +1,7 @@ -import { Z } from '@n8n/api-types'; import { z } from 'zod'; +import { Z } from '../../zod-class'; + const policyAttachmentInputSchema = z.object({ policyId: z.string().min(1), priority: z.number().int(), diff --git a/packages/cli/src/modules/type-availability-policies/dto/update-policy-document.dto.ts b/packages/@n8n/api-types/src/dto/node-type-policies/update-policy-document.dto.ts similarity index 91% rename from packages/cli/src/modules/type-availability-policies/dto/update-policy-document.dto.ts rename to packages/@n8n/api-types/src/dto/node-type-policies/update-policy-document.dto.ts index d3a3edebf45..8225fe0e2e1 100644 --- a/packages/cli/src/modules/type-availability-policies/dto/update-policy-document.dto.ts +++ b/packages/@n8n/api-types/src/dto/node-type-policies/update-policy-document.dto.ts @@ -1,7 +1,7 @@ -import { Z } from '@n8n/api-types'; import { z } from 'zod'; import { policyRuleListSchema } from './policy-rule.schema'; +import { Z } from '../../zod-class'; /** Request body for replacing a policy document's rules. */ export class UpdatePolicyDocumentDto extends Z.class({ diff --git a/packages/cli/src/modules/type-availability-policies/policy-rule.types.ts b/packages/cli/src/modules/type-availability-policies/policy-rule.types.ts index 353f877a39e..98f87776c65 100644 --- a/packages/cli/src/modules/type-availability-policies/policy-rule.types.ts +++ b/packages/cli/src/modules/type-availability-policies/policy-rule.types.ts @@ -1,35 +1,24 @@ /** * Domain types for node type availability policies. * + * The rule/selector/action shapes live in `@n8n/api-types` so the public and internal request + * DTOs share them; they are re-exported here so the module keeps one import path. The types + * below are backend-only. + * * Deliberately independent of the `policy`/`policy_scope`/`policy_attachment` TypeORM - * entities (not yet built) — the repository layer will map DB rows into these shapes so - * the evaluator never depends on the persistence layer. + * entities — the repository layer maps DB rows into these shapes so the evaluator never + * depends on the persistence layer. */ -/** Matches a node type by its exact full name, or by its package segment. */ -export type PolicySelector = - | { readonly kind: 'name'; readonly value: string } - | { readonly kind: 'package'; readonly value: string }; +import type { PolicyAction, PolicyRule } from '@n8n/api-types'; -export type PolicyAction = 'allow' | 'deny' | 'delegate'; - -/** One first-match rule within a policy document, in document order. */ -export type PolicyRule = { - readonly id: string; - readonly action: PolicyAction; - readonly selector: PolicySelector; -}; - -/** - * The actions a project scope accepts. `delegate` defers to a narrower scope, and none exists - * below project, so project-scope writes never accept it. - */ -export type NonDelegatingPolicyAction = Exclude; - -/** A `PolicyRule` as a project scope accepts it. */ -export type NonDelegatingPolicyRule = Omit & { - readonly action: NonDelegatingPolicyAction; -}; +export type { + NonDelegatingPolicyAction, + NonDelegatingPolicyRule, + PolicyAction, + PolicyRule, + PolicySelector, +} from '@n8n/api-types'; /** One policy document as attached to a scope, with its evaluation-order metadata. */ export type PolicyAttachment = { diff --git a/packages/cli/src/modules/type-availability-policies/type-availability-policy-instance.controller.ts b/packages/cli/src/modules/type-availability-policies/type-availability-policy-instance.controller.ts index 881f703b03a..3c76586afad 100644 --- a/packages/cli/src/modules/type-availability-policies/type-availability-policy-instance.controller.ts +++ b/packages/cli/src/modules/type-availability-policies/type-availability-policy-instance.controller.ts @@ -1,3 +1,9 @@ +import { + CreatePolicyDocumentDto, + PutInstancePolicyDto, + ReplaceAttachmentsDto, + UpdatePolicyDocumentDto, +} from '@n8n/api-types'; import { LICENSE_FEATURES } from '@n8n/constants'; import { AuthenticatedRequest } from '@n8n/db'; import { @@ -17,10 +23,6 @@ import type { Response } from 'express'; import { NotFoundError } from '@/errors/response-errors/not-found.error'; import { NODE_TYPES_KIND } from './constants'; -import { CreatePolicyDocumentDto } from './dto/create-policy-document.dto'; -import { PutInstancePolicyDto } from './dto/put-instance-policy.dto'; -import { ReplaceAttachmentsDto } from './dto/replace-attachments.dto'; -import { UpdatePolicyDocumentDto } from './dto/update-policy-document.dto'; import { TypeAvailabilityPolicyService } from './type-availability-policy.service'; /** diff --git a/packages/cli/src/modules/type-availability-policies/type-availability-policy-project.controller.ts b/packages/cli/src/modules/type-availability-policies/type-availability-policy-project.controller.ts index 02badfca410..68b4ebb90ab 100644 --- a/packages/cli/src/modules/type-availability-policies/type-availability-policy-project.controller.ts +++ b/packages/cli/src/modules/type-availability-policies/type-availability-policy-project.controller.ts @@ -1,10 +1,10 @@ +import { PutProjectPolicyDto } from '@n8n/api-types'; import { LICENSE_FEATURES } from '@n8n/constants'; import { AuthenticatedRequest } from '@n8n/db'; import { Body, Get, Licensed, ProjectScope, Put, RestController } from '@n8n/decorators'; import type { Response } from 'express'; import { NODE_TYPES_KIND } from './constants'; -import { PutProjectPolicyDto } from './dto/put-project-policy.dto'; import { TypeAvailabilityPolicyService } from './type-availability-policy.service'; /**