/** * Request-body validation for the authorization routes, reported the way production's * class-validator pipe reports it: a 422 "Validation failed" carrying one entry per failing * field, whose `code` is the message of the first constraint that failed. Unknown properties * come first (the pipe whitelists before it validates), then the DTO's fields in declaration * order. Production decorates each DTO property bottom-up, so a field's constraints run in * the reverse of the decorator stack in the monorepo; the rule sets below list them in that * run order. */ /** Returns the constraint's message when `value` fails it. */ export type Constraint = (value: unknown, field: string) => string | undefined; export interface FieldRule { /** * When the field is checked: `always` for a required field (checked even when absent), * `defined` for one checked whenever it is sent, null included (class-validator's * `ValidateIf(v => v !== undefined)`), `present` for one skipped when absent or null * (`IsOptional`). */ when: 'always' | 'defined' | 'present'; constraints: readonly Constraint[]; } export interface BodyRules { fields: Record; /** Reject properties the DTO does not declare, as `forbidNonWhitelisted` does. */ forbidUnknown: boolean; } export declare const notEmpty: Constraint; export declare const isString: Constraint; /** * class-validator's MaxLength counts a surrogate pair as one character (validator.js * `isLength`), so an astral character such as an emoji counts once, as it does in production. */ export declare const maxLength: (max: number) => Constraint; export declare const matches: (pattern: RegExp, message: string) => Constraint; export declare const ascii: Constraint; export declare const isArray: Constraint; /** `IsString({ each: true })`: class-validator only inspects the elements of an array. */ export declare const eachString: Constraint; export declare const arrayMinSize: (min: number) => Constraint; /** `IsNotEmpty` + `IsString` + the rest: a field production marks required. */ export declare const required: (...constraints: Constraint[]) => FieldRule; /** `IsOptional` + `IsString` + the rest: absent or null passes untouched. */ export declare const optional: (...constraints: Constraint[]) => FieldRule; /** `IsOptional` + `IsNotEmpty` + `IsString`: absent or null passes, an empty string does not. */ export declare const optionalNonEmpty: (...constraints: Constraint[]) => FieldRule; export declare function validateBody(body: Record, rules: BodyRules): void; export declare const MAX_SLUG_LENGTH = 48; export declare const MAX_NAME_LENGTH = 48; export declare const MAX_DESCRIPTION_LENGTH = 150; export declare const MAX_RESOURCE_EXTERNAL_ID_LENGTH = 128; export declare const SLUG_PATTERN: RegExp; export declare const ORGANIZATION_ROLE_SLUG_PATTERN: RegExp; export declare const PERMISSION_SLUG_PATTERN: RegExp; export declare const SLUG_MESSAGE = "Slug must contain only lowercase letters, numbers, hyphens and underscores, and cannot have leading, trailing, or consecutive separators."; export declare const ORGANIZATION_ROLE_SLUG_MESSAGE = "Slug must be prefixed with 'org-', contain only lowercase letters, numbers, hyphens and underscores, and cannot have leading, trailing, or consecutive separators."; export declare const PERMISSION_SLUG_MESSAGE = "Slug must contain only lowercase letters, numbers, hyphens, underscores, colons, periods, and asterisks, and cannot have leading, trailing, or consecutive separators."; export declare const ROLE_CREATE_RULES: BodyRules; /** * An organization role's slug is optional (one is generated from the name when omitted) * but must carry the `org-` prefix when given; the create route runs a plain * `ValidationPipe()` with no whitelist, so unknown properties are ignored, not refused. */ export declare const ORGANIZATION_ROLE_CREATE_RULES: BodyRules; /** Shared by environment and organization roles: only name and description are updatable. */ export declare const ROLE_UPDATE_RULES: BodyRules; /** `PUT .../permissions`: set-role-permissions.dto.ts. */ export declare const ROLE_PERMISSIONS_SET_RULES: BodyRules; /** `POST .../permissions`: add-role-permission.dto.ts. */ export declare const ROLE_PERMISSION_ADD_RULES: BodyRules; /** `PUT .../roles/priority`: update-organization-role-priority-order.dto.ts, no whitelist. */ export declare const ROLE_PRIORITY_ORDER_RULES: BodyRules; export declare const PERMISSION_CREATE_RULES: BodyRules; export declare const PERMISSION_UPDATE_RULES: BodyRules; export declare const RESOURCE_CREATE_RULES: BodyRules; export declare const RESOURCE_UPDATE_RULES: BodyRules; /** The query of the memberships-for-resource routes: list-organization-memberships-for-resource.dto.ts. */ export declare const RESOURCE_MEMBERSHIPS_QUERY_RULES: BodyRules;