UNPKG

@unito/integration-debugger

Version:

The Unito Integration Debugger

68 lines (67 loc) 2.33 kB
import { FieldSchema, Item, ItemSummary } from '@unito/integration-api'; export interface ValidateItemOptions { schemaPath?: string; fields?: FieldSchema[]; partial?: boolean; requiredFields?: string[]; detailedMessage?: string; } export interface ValidationResult { errors: ValidationDetail[]; warnings: ValidationDetail[]; } export interface ValidationDetail { keyword: string; instancePath: string; schemaPath: string; message: string | undefined; detailedMessage?: string; params?: Record<string, unknown>; } /** * This error is raised when a payload is not compliant with the Integration API specification. */ export declare class ValidationFailed extends Error { payload: unknown; details: ValidationDetail[] | null | undefined; constructor(payload: unknown, details: ValidationDetail[]); } export declare function create(): Promise<Instance>; /** * The Integration API specification validator. * * Part of the specification define types that payloads must comply to. * Those types are available in our @unito/integration-api NPM package. */ export declare class Instance { private spec; schemas: Record<string, unknown>[]; constructor(schemas: Record<string, unknown>[]); /** * Validate the shape of the payload. * * For example, if the payload is supposed to be an "Item", * we validate that it complies to our "Item" JSON Schema type. */ validateShape(payload: unknown, schema: string): ValidationResult; /** * Validate the content of an Item. * * The content of an Item is specific to an integration. * * For example, if the item is supposed to be a "task", * which is a specific "item" of some integration, * we validate that it complies to the provided "task" schema. */ validateItem(item: Item | ItemSummary, options: ValidateItemOptions): ValidationResult; toJsonFields(fields: FieldSchema[], partial: boolean): Record<string, Record<string, unknown>>; /** * Populate the validation result with errors, warnings, a message and the validity of the payload */ private performValidation; private validateRange; /** * Validate Unito specific requirements of an item's fields. */ private validateForUnito; }