UNPKG

@gohcltech/bitbucket-mcp

Version:

Bitbucket integration for Claude via Model Context Protocol

829 lines 24.4 kB
/** * @fileoverview Zod validation schemas for Bitbucket branch operations. * * This module provides comprehensive validation schemas for branch-related * operations using Zod for runtime type checking and validation. These schemas * ensure that data conforms to Bitbucket API v2.0 specifications and provide * type-safe validation for MCP tool inputs and API responses. * * Key features: * - Runtime validation of branch API responses * - Branching model and Git Flow configuration validation * - Branch protection and permissions schema validation * - Default reviewer assignment rule validation * - Input parameter validation for branch management tools * - Type-safe schema definitions matching TypeScript interfaces */ import { z } from 'zod'; /** * Zod schema for validating Bitbucket branch API responses. * * This schema validates the structure of branch objects returned by * Bitbucket's REST API v2.0. It ensures that all required fields are present * and correctly typed, including commit metadata and navigation links. * * The schema uses `satisfies z.ZodType<Branch>` to guarantee that the * validation schema matches the TypeScript interface exactly. * * @example * ```typescript * const apiResponse = await fetch('/2.0/repositories/gohcl/bitbucket-mcp/refs/branches/feature/auth'); * const rawData = await apiResponse.json(); * const branch = BranchSchema.parse(rawData); * ``` */ export declare const BranchSchema: z.ZodObject<{ /** * Branch name following git naming conventions. * Must be a non-empty string with valid git branch name format. */ name: z.ZodString; /** * Target commit information that this branch points to. * Contains comprehensive metadata about the HEAD commit. */ target: z.ZodObject<{ /** * SHA-1 hash of the target commit. * Must be a 40-character hexadecimal string. */ hash: z.ZodString; /** * ISO 8601 timestamp when the commit was created. * Must be a valid datetime string with timezone information. */ date: z.ZodString; /** * Commit author information. * May contain user details if author is a registered Bitbucket user. */ author: z.ZodObject<{ /** * Optional Bitbucket user information for the commit author. * Present only if author email matches a registered user. */ user: z.ZodOptional<z.ZodObject<{ /** Display name of the commit author */ display_name: z.ZodString; /** Unique UUID for the author's user account */ uuid: z.ZodString; }, "strip", z.ZodTypeAny, { uuid: string; display_name: string; }, { uuid: string; display_name: string; }>>; }, "strip", z.ZodTypeAny, { user?: { uuid: string; display_name: string; } | undefined; }, { user?: { uuid: string; display_name: string; } | undefined; }>; /** * Commit message describing the changes. * Contains the full commit message including title and body. */ message: z.ZodString; }, "strip", z.ZodTypeAny, { message: string; date: string; hash: string; author: { user?: { uuid: string; display_name: string; } | undefined; }; }, { message: string; date: string; hash: string; author: { user?: { uuid: string; display_name: string; } | undefined; }; }>; /** * Collection of related URLs for the branch. * Provides navigation links to commits and web interface. */ links: z.ZodObject<{ /** * API endpoint for commits on this branch. * Links to the filtered commits API for this branch. */ commits: z.ZodObject<{ /** Full URL to the branch's commits API endpoint */ href: z.ZodString; }, "strip", z.ZodTypeAny, { href: string; }, { href: string; }>; /** * Web interface link to the branch page. * Opens the branch view in Bitbucket's web interface. */ html: z.ZodObject<{ /** Full URL to the branch page in Bitbucket */ href: z.ZodString; }, "strip", z.ZodTypeAny, { href: string; }, { href: string; }>; }, "strip", z.ZodTypeAny, { html: { href: string; }; commits: { href: string; }; }, { html: { href: string; }; commits: { href: string; }; }>; }, "strip", z.ZodTypeAny, { name: string; links: { html: { href: string; }; commits: { href: string; }; }; target: { message: string; date: string; hash: string; author: { user?: { uuid: string; display_name: string; } | undefined; }; }; }, { name: string; links: { html: { href: string; }; commits: { href: string; }; }; target: { message: string; date: string; hash: string; author: { user?: { uuid: string; display_name: string; } | undefined; }; }; }>; /** * Zod schema for validating Bitbucket branching model API responses. * * This schema validates the structure of branching model configurations that * define Git Flow, GitHub Flow, or custom branching strategies. It includes * validation for development/production branch settings and branch type * configurations with their naming prefixes. * * The schema accommodates the flexible nature of branching models where * most fields are optional depending on the strategy type. * * @example * ```typescript * const apiResponse = await fetch('/2.0/repositories/gohcl/bitbucket-mcp/branching-model'); * const rawData = await apiResponse.json(); * const model = BranchingModelSchema.parse(rawData); * ``` */ export declare const BranchingModelSchema: z.ZodObject<{ /** * Type of branching workflow strategy. * Defines the overall branching strategy used by the repository. */ type: z.ZodOptional<z.ZodEnum<["git_flow", "github_flow", "custom"]>>; /** * Development branch configuration. * Defines the primary development branch for ongoing work. */ development: z.ZodOptional<z.ZodObject<{ /** * Name of the development branch. * Must be a valid git branch name. */ name: z.ZodString; /** * Whether this branch is the repository's main branch. * Determines if development happens on the main branch. */ use_mainbranch: z.ZodBoolean; }, "strip", z.ZodTypeAny, { name: string; use_mainbranch: boolean; }, { name: string; use_mainbranch: boolean; }>>; /** * Production/stable branch configuration. * Defines the branch containing production-ready code. */ production: z.ZodOptional<z.ZodObject<{ /** * Name of the production branch. * Must be a valid git branch name. */ name: z.ZodString; /** * Whether this branch is the repository's main branch. * Usually true for production branches. */ use_mainbranch: z.ZodBoolean; }, "strip", z.ZodTypeAny, { name: string; use_mainbranch: boolean; }, { name: string; use_mainbranch: boolean; }>>; /** * Array of branch type configurations. * Defines naming patterns and behavior for different branch categories. */ branch_types: z.ZodOptional<z.ZodArray<z.ZodObject<{ /** * Category of branch defining its purpose. * Must be one of the predefined branch types. */ kind: z.ZodEnum<["feature", "bugfix", "release", "hotfix", "custom"]>; /** * Naming prefix for branches of this type. * Should end with a separator like '/' or '-'. */ prefix: z.ZodString; /** * Whether branches of this type are currently enabled. * Controls whether new branches of this type can be created. */ enabled: z.ZodBoolean; }, "strip", z.ZodTypeAny, { kind: "custom" | "feature" | "bugfix" | "release" | "hotfix"; prefix: string; enabled: boolean; }, { kind: "custom" | "feature" | "bugfix" | "release" | "hotfix"; prefix: string; enabled: boolean; }>, "many">>; /** * Collection of related URLs for the branching model. * Provides API endpoints for managing branching model settings. */ links: z.ZodOptional<z.ZodObject<{ /** * Self-referential link to this branching model configuration. */ self: z.ZodObject<{ /** API endpoint URL for this branching model */ href: z.ZodString; }, "strip", z.ZodTypeAny, { href: string; }, { href: string; }>; }, "strip", z.ZodTypeAny, { self: { href: string; }; }, { self: { href: string; }; }>>; }, "strip", z.ZodTypeAny, { type?: "custom" | "git_flow" | "github_flow" | undefined; development?: { name: string; use_mainbranch: boolean; } | undefined; production?: { name: string; use_mainbranch: boolean; } | undefined; links?: { self: { href: string; }; } | undefined; branch_types?: { kind: "custom" | "feature" | "bugfix" | "release" | "hotfix"; prefix: string; enabled: boolean; }[] | undefined; }, { type?: "custom" | "git_flow" | "github_flow" | undefined; development?: { name: string; use_mainbranch: boolean; } | undefined; production?: { name: string; use_mainbranch: boolean; } | undefined; links?: { self: { href: string; }; } | undefined; branch_types?: { kind: "custom" | "feature" | "bugfix" | "release" | "hotfix"; prefix: string; enabled: boolean; }[] | undefined; }>; /** * Zod schema for validating Bitbucket branch permissions API responses. * * This schema validates the structure of branch protection rules and restrictions * that control access to specific branches. It includes validation for various * restriction types, user/group exemptions, and pagination metadata. * * @example * ```typescript * const apiResponse = await fetch('/2.0/repositories/gohcl/bitbucket-mcp/branch-restrictions'); * const rawData = await apiResponse.json(); * const permissions = BranchPermissionsSchema.parse(rawData); * ``` */ export declare const BranchPermissionsSchema: z.ZodObject<{ /** Array of branch restrictions */ values: z.ZodArray<z.ZodObject<{ /** Unique restriction ID */ id: z.ZodNumber; /** Restriction type */ kind: z.ZodEnum<["push", "force", "delete", "restrict_merges", "enforce_merge_checks"]>; /** Branch name pattern this restriction applies to */ pattern: z.ZodString; /** Users affected by this restriction */ users: z.ZodOptional<z.ZodArray<z.ZodObject<{ display_name: z.ZodString; uuid: z.ZodString; }, "strip", z.ZodTypeAny, { uuid: string; display_name: string; }, { uuid: string; display_name: string; }>, "many">>; /** Groups affected by this restriction */ groups: z.ZodOptional<z.ZodArray<z.ZodObject<{ name: z.ZodString; slug: z.ZodString; }, "strip", z.ZodTypeAny, { name: string; slug: string; }, { name: string; slug: string; }>, "many">>; /** Restriction value/configuration */ value: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean]>>; /** Related links */ links: z.ZodOptional<z.ZodObject<{ self: z.ZodObject<{ href: z.ZodString; }, "strip", z.ZodTypeAny, { href: string; }, { href: string; }>; }, "strip", z.ZodTypeAny, { self: { href: string; }; }, { self: { href: string; }; }>>; }, "strip", z.ZodTypeAny, { kind: "push" | "delete" | "force" | "restrict_merges" | "enforce_merge_checks"; id: number; pattern: string; value?: string | number | boolean | undefined; links?: { self: { href: string; }; } | undefined; users?: { uuid: string; display_name: string; }[] | undefined; groups?: { name: string; slug: string; }[] | undefined; }, { kind: "push" | "delete" | "force" | "restrict_merges" | "enforce_merge_checks"; id: number; pattern: string; value?: string | number | boolean | undefined; links?: { self: { href: string; }; } | undefined; users?: { uuid: string; display_name: string; }[] | undefined; groups?: { name: string; slug: string; }[] | undefined; }>, "many">; /** Pagination information */ page: z.ZodOptional<z.ZodNumber>; pagelen: z.ZodOptional<z.ZodNumber>; size: z.ZodOptional<z.ZodNumber>; next: z.ZodOptional<z.ZodString>; }, "strip", z.ZodTypeAny, { values: { kind: "push" | "delete" | "force" | "restrict_merges" | "enforce_merge_checks"; id: number; pattern: string; value?: string | number | boolean | undefined; links?: { self: { href: string; }; } | undefined; users?: { uuid: string; display_name: string; }[] | undefined; groups?: { name: string; slug: string; }[] | undefined; }[]; page?: number | undefined; size?: number | undefined; pagelen?: number | undefined; next?: string | undefined; }, { values: { kind: "push" | "delete" | "force" | "restrict_merges" | "enforce_merge_checks"; id: number; pattern: string; value?: string | number | boolean | undefined; links?: { self: { href: string; }; } | undefined; users?: { uuid: string; display_name: string; }[] | undefined; groups?: { name: string; slug: string; }[] | undefined; }[]; page?: number | undefined; size?: number | undefined; pagelen?: number | undefined; next?: string | undefined; }>; /** * Zod schema for validating Bitbucket default reviewers API responses. * * This schema validates the structure of automatic reviewer assignment rules * that determine which users should be added as reviewers for pull requests * based on branch patterns. It includes comprehensive user information and * repository context. * * @example * ```typescript * const apiResponse = await fetch('/2.0/repositories/gohcl/bitbucket-mcp/default-reviewers'); * const rawData = await apiResponse.json(); * const reviewers = DefaultReviewersSchema.parse(rawData); * ``` */ export declare const DefaultReviewersSchema: z.ZodObject<{ /** Array of default reviewer configurations */ values: z.ZodArray<z.ZodObject<{ /** Default reviewer user information */ user: z.ZodObject<{ display_name: z.ZodString; uuid: z.ZodString; account_id: z.ZodString; links: z.ZodObject<{ avatar: z.ZodObject<{ href: z.ZodString; }, "strip", z.ZodTypeAny, { href: string; }, { href: string; }>; html: z.ZodObject<{ href: z.ZodString; }, "strip", z.ZodTypeAny, { href: string; }, { href: string; }>; }, "strip", z.ZodTypeAny, { html: { href: string; }; avatar: { href: string; }; }, { html: { href: string; }; avatar: { href: string; }; }>; }, "strip", z.ZodTypeAny, { uuid: string; links: { html: { href: string; }; avatar: { href: string; }; }; display_name: string; account_id: string; }, { uuid: string; links: { html: { href: string; }; avatar: { href: string; }; }; display_name: string; account_id: string; }>; /** Branch name pattern this reviewer applies to */ pattern: z.ZodOptional<z.ZodString>; /** Repository information */ repository: z.ZodOptional<z.ZodObject<{ name: z.ZodString; full_name: z.ZodString; uuid: z.ZodString; }, "strip", z.ZodTypeAny, { name: string; uuid: string; full_name: string; }, { name: string; uuid: string; full_name: string; }>>; }, "strip", z.ZodTypeAny, { user: { uuid: string; links: { html: { href: string; }; avatar: { href: string; }; }; display_name: string; account_id: string; }; repository?: { name: string; uuid: string; full_name: string; } | undefined; pattern?: string | undefined; }, { user: { uuid: string; links: { html: { href: string; }; avatar: { href: string; }; }; display_name: string; account_id: string; }; repository?: { name: string; uuid: string; full_name: string; } | undefined; pattern?: string | undefined; }>, "many">; /** Pagination information */ page: z.ZodOptional<z.ZodNumber>; pagelen: z.ZodOptional<z.ZodNumber>; size: z.ZodOptional<z.ZodNumber>; next: z.ZodOptional<z.ZodString>; }, "strip", z.ZodTypeAny, { values: { user: { uuid: string; links: { html: { href: string; }; avatar: { href: string; }; }; display_name: string; account_id: string; }; repository?: { name: string; uuid: string; full_name: string; } | undefined; pattern?: string | undefined; }[]; page?: number | undefined; size?: number | undefined; pagelen?: number | undefined; next?: string | undefined; }, { values: { user: { uuid: string; links: { html: { href: string; }; avatar: { href: string; }; }; display_name: string; account_id: string; }; repository?: { name: string; uuid: string; full_name: string; } | undefined; pattern?: string | undefined; }[]; page?: number | undefined; size?: number | undefined; pagelen?: number | undefined; next?: string | undefined; }>; /** * Input validation schema for branch-related MCP tool parameters. * * This schema validates the basic parameters required by branch-related tools, * extending the repository base schema with branch-specific validation. * It ensures proper formatting of workspace, repository, and branch identifiers. * * Used by tools that operate on existing branches like get_branch, delete_branch. * * @example * ```typescript * const input = { * workspace: 'gohcl', * repo_slug: 'bitbucket-mcp', * branch_name: 'feature/authentication' * }; * const validatedInput = BranchInputSchema.parse(input); * ``` */ export declare const BranchInputSchema: z.ZodObject<{ workspace: z.ZodString; } & { repo_slug: z.ZodString; } & { /** * Branch name following git naming conventions. * Must be a valid git branch name without path separators. */ branch_name: z.ZodString; }, "strip", z.ZodTypeAny, { workspace: string; repo_slug: string; branch_name: string; }, { workspace: string; repo_slug: string; branch_name: string; }>; /** * Input validation schema for the create_branch MCP tool. * * This schema validates parameters for creating new branches, including * the branch name and target commit hash. It ensures that branch names * follow git conventions and target commits are properly specified. * * @example * ```typescript * const input = { * workspace: 'gohcl', * repo_slug: 'bitbucket-mcp', * name: 'feature/oauth-integration', * target: { * hash: 'a1b2c3d4e5f6789012345678901234567890abcd' * } * }; * const validatedInput = CreateBranchInputSchema.parse(input); * ``` */ export declare const CreateBranchInputSchema: z.ZodObject<{ workspace: z.ZodString; } & { repo_slug: z.ZodString; } & { /** * Name for the new branch. * Must follow git branch naming conventions and be unique within the repository. */ name: z.ZodString; /** * Target commit information for the new branch. * Specifies which commit the new branch should point to. */ target: z.ZodObject<{ /** * SHA-1 hash of the target commit. * Must be a valid 40-character hexadecimal commit hash. */ hash: z.ZodString; }, "strip", z.ZodTypeAny, { hash: string; }, { hash: string; }>; }, "strip", z.ZodTypeAny, { workspace: string; name: string; repo_slug: string; target: { hash: string; }; }, { workspace: string; name: string; repo_slug: string; target: { hash: string; }; }>; /** * Type guard function for branch input validation. * * Checks if the provided input matches the branch input schema structure, * providing runtime type safety for branch-related operations. * * @param input - Unknown input to validate * @returns True if input matches BranchInputSchema, false otherwise * * @example * ```typescript * if (isBranchInput(userInput)) { * // userInput is now typed as { workspace: string; repo_slug: string; branch_name: string } * console.log(`Branch: ${userInput.branch_name}`); * } * ``` */ export declare function isBranchInput(input: unknown): input is z.infer<typeof BranchInputSchema>; //# sourceMappingURL=schemas.d.ts.map