UNPKG

@unito/integration-debugger

Version:

The Unito Integration Debugger

89 lines (88 loc) 4.07 kB
import { FieldSchema, RelationSchema } from '@unito/integration-api'; import * as Crawler from './crawler'; import * as Generator from './generator'; export type Operation = Crawler.Operation; export declare const Operation: typeof Crawler.Operation; export type Step = Crawler.Step; export type StepExecutionResult = Crawler.StepExecutionResult; export type ProxyCallResponse = Crawler.ProxyCallResponse; export type Context = { name: string; }; export type PreparedStep = Omit<Step, 'context'> & { context?: Context; }; export interface StepCheck { label: string; prepareOnPreparedSteps: boolean; validateOnError: boolean; activatedByDefault: boolean; prepare: (stepResult: StepExecutionResult, crawlerDriver: Instance) => Promise<PreparedStep[]>; validate?: (step: Step, crawlerDriver: Instance) => void; } export interface CrawlerDriverOptions { readOnly: boolean; [Operation.GetCollection]: { /** * Number of items to crawl, per page, when crawling collections. * Should be a positive integer. Any negative value is equal to Number.MAX_SAFE_INTEGER. */ itemsPerPage?: number; /** * Whether to follow the next page when crawling collections. */ followNextPage?: boolean; }; /** * Whether to include a timeout in the headers of the steps. */ timeout?: number; } export declare class Instance { crawler: Crawler.Instance; generator: Generator.Instance; private stepChecks; private visitedSteps; private options; /** * Depending on the context (createWithProxyCrawler, createWithDirectCrawler, ...), we * produce HTTP headers for the step, stored in "headersIn". */ private prepareHeaders; constructor(crawler: Crawler.Instance, generator: Generator.Instance, prepareHeaders: (step: Step) => void, options?: CrawlerDriverOptions); startFrom(step: Step): void; remaining(): readonly Readonly<Step>[]; getRelationSchema(schemaPath: string): RelationSchema | undefined; getFieldSchemas(schemaPath: string): readonly Readonly<FieldSchema>[] | undefined; set stepCheckKeys(keys: string[] | undefined); next(): Promise<Step | undefined>; /** * When we discover a step, we always crawl it to perform basic checks (defined in @unito/integration-api). * This could be considered a check like the others but it feels wrong. * The crawling of an integration is too core to be considered a simple check that can be toggled on/off. * If allowed to be toggled off, it could be a surprising behavior for the developer * (ex: why is the crawl stopping now?). * * Configuration options can be used to change the default behavior and reduce the quantity of steps crawled. * @see {@link CrawlerDriverOptions} */ private addDiscoveredSteps; /** * Determines if a discovered step can be crawled * * A step with a request schema cannot be crawled automatically without a check (see checks/requestSchema). * * @param step * @returns true if a discovered step can be crawled */ private canCrawl; /** * Returns a sanitized version of the step, where sensitive data is blurred. * @param step * @returns sanitized step */ private sanitizeStep; } export declare function createWithProxyCrawler(credentialId: number, options?: CrawlerDriverOptions): Promise<Instance>; export declare function createWithDirectCrawler(integrationUrl: string, graphUrl: string, credentialAccountUrl: string, webhookParsingUrl: string | undefined, webhookSubscriptionsUrl: string | undefined, webhookAcknowledgeRelativeUrl: string | undefined, credentialPayload: Record<string, unknown>, secretsPayload: Record<string, unknown>, options?: CrawlerDriverOptions): Promise<Instance>; export declare function createWithDummyCrawler(proxyCall: (step: Step) => Promise<ProxyCallResponse>, generatorOptions?: Generator.GeneratorOptions, options?: CrawlerDriverOptions): Promise<Instance>;