UNPKG

@omlet/cli

Version:

Omlet (https://omlet.dev) is a component analytics tool that uses a CLI to scan your codebase to detect components and their usage. Get real usage insights from customizable charts to measure adoption across all projects and identify opportunities to impr

126 lines (125 loc) 3.92 kB
import { type Response } from "node-fetch"; import { type AnalyzeResult } from "./analyzer"; import { CliError } from "./error"; declare type APIResponse<TData, TMeta = never> = { data: TData; meta: TMeta; }; export declare enum ErrorResponseCode { UNAUTHORIZED = "unauthorized", BAD_REQUEST = "bad-request", REQUEST_TOO_LONG = "request-too-long", CLI_NOT_SUPPORTED = "cli-not-supported", USER_NOT_SUBSCRIBED = "user-not-subscribed", WORKSPACE_NOT_FOUND = "workspace-not-found", WORKSPACE_SLUG_NOT_AVAILABLE = "workspace-slug-not-available", WORKSPACE_ALREADY_SETUP = "workspace-already-setup", USER_NOT_HAVE_WORKSPACE = "user-not-have-workspace", USER_ALREADY_HAS_WORKSPACE = "user-already-has-workspace", USER_ALREADY_MEMBER = "user-already-member", TAG_NOT_FOUND = "tag-not-found", SAVED_CHARTS_FEATURE_DISABLED = "saved-charts-feature-disabled", SAVED_CHART_NOT_FOUND = "saved-chart-not-found", SAVED_CHART_LIMIT_REACHED = "saved-chart-limit-reached", LOCKED = "locked", UNSUPPORTED_MEDIA_TYPE = "unsupported-media-type" } export interface ErrorResponse { code?: ErrorResponseCode; title: string; detail: string; meta?: unknown; } interface ApiErrorContext extends Record<string, unknown> { url: string; method: string; requestHeaders: Record<string, string>; cli_version: string; node_version: string; device_info: { os: string; arch: string; version: string; }; duration: number; responseStatus?: number; responseHeaders?: Record<string, string>; responseBody?: string; } export declare class ApiError<T extends ApiErrorContext = ApiErrorContext> extends CliError<T> { readonly context: T; protected _errorInfo: ErrorResponse; constructor(message: string, { context }: { context: T; }); get errorInfo(): ErrorResponse; } export declare class LoginRequiredError extends ApiError { constructor({ context }: { context: ApiErrorContext; }); } export declare class RequestFailedError extends ApiError { readonly statusCode: number; constructor(statusCode: number, { context }: { context: ApiErrorContext; }); } export declare class UnknownRequestError extends ApiError { constructor(reason: Error, { context }: { context: ApiErrorContext; }); } export declare class RequestTimeoutError extends ApiError { constructor(message: string, { context }: { context: ApiErrorContext; }); } export interface User { id: string; email: string; fullName?: string; lastSeen?: Date; } export declare function getMe(): Promise<User>; export interface Workspace { id: string; name: string; slug: string; projects: { slug: string; packageName: string; name: string; }[]; hasReachedAnalysisLimit: boolean; subscription: { features: { analysisLimit: number; }; }; } export declare function getDefaultWorkspace(): Promise<Workspace>; export declare function getWorkspace(slug: string): Promise<Workspace>; export interface Analysis { id: string; createdAt: Date; numOfComponents: number; } declare type PostAnalysisResponse = APIResponse<Analysis, { dataIssueCount: number; }>; export declare function postAnalysis(workspace: Workspace, analysisData: AnalyzeResult): Promise<PostAnalysisResponse>; export declare function initWorkspace(workspace: Workspace, analyses: AnalyzeResult[]): Promise<Workspace>; export interface TrackerEventProps { deviceId: string; cliVersion: string; command: string; workspaceId?: string; workspaceSlug?: string; [key: string]: string | number | undefined; } export declare function trackEvent(eventName: string, props?: TrackerEventProps): Promise<{ data: unknown; response: Response; }>; export {};