@infactory/infactory-ts
Version:
Infactory TypeScript SDK for use with Infactory Workshop, MCP Server and API
1,602 lines (1,592 loc) • 133 kB
text/typescript
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | (string & {});
type AuthType = 'None' | 'Basic Auth' | 'Bearer Token' | 'API Key';
/**
* Parameters for Fivetran webhook handling
*/
interface FivetranWebhookParams {
payload: Record<string, any>;
signatureHeader: string;
}
/**
* Parameters for chat completion request
*/
interface ChatCompletionRequest {
model: string;
messages: Array<Record<string, any>>;
tools?: Array<Record<string, any>>;
tool_choice?: string | Record<string, any>;
temperature?: number;
top_p?: number;
n?: number;
max_tokens?: number;
[key: string]: any;
}
/**
* Parameters for calling a chat tool function
*/
interface CallToolFunctionParams {
projectId: string;
toolName: string;
params: Record<string, any>;
}
/**
* Configuration for a parameter
*/
type ParameterConfig$1 = string | {
value: string;
required: boolean;
};
/**
* Group of parameters
*/
interface ParameterGroup$1 {
required: boolean;
parameters: Array<{
key: string;
value: string;
}>;
}
/**
* Configuration for HTTP request body
*/
interface HttpBodyConfig$1 {
type: string;
contentType?: string;
content?: string;
parameters?: Record<string, string>;
}
/**
* Configuration for HTTP authentication
*/
interface HttpAuthConfig {
apiKey?: {
name: string;
value: string;
location: string;
};
bearerToken?: string;
basicAuth?: {
username: string;
password: string;
};
}
/**
* Request parameters for testing an HTTP connection
*/
interface TestHttpConnectionRequest {
url: string;
method: HttpMethod;
headers?: Record<string, string>;
parameters?: Record<string, ParameterConfig$1>;
parameterGroups?: ParameterGroup$1[];
authType?: AuthType;
auth?: HttpAuthConfig;
/**
* @deprecated Use `auth` instead. Kept for backwards compatibility with examples.
*/
authConfig?: HttpAuthConfig;
body?: HttpBodyConfig$1;
responsePathExtractor?: string;
}
/**
* Response from testing an HTTP connection
*/
interface TestHttpConnectionResponse {
success: boolean;
status: number;
responseTime: number;
contentType: string;
size: number;
data: any;
headers?: Record<string, string>;
}
/**
* Request parameters for executing an HTTP request
*/
interface ExecuteHttpRequestRequest extends TestHttpConnectionRequest {
projectId: string;
datasourceId: string;
connectSpec?: Record<string, any>;
}
/**
* Response from executing an HTTP request
*/
interface ExecuteHttpRequestResponse {
jobs: I7YPendingJob[];
}
/**
* Client for managing integrations in the Infactory API
*/
declare class IntegrationsClient {
private readonly httpClient;
/**
* Creates a new IntegrationsClient instance
* @param httpClient - The HTTP client to use for API requests
*/
constructor(httpClient: HttpClient);
/**
* Handle Fivetran webhook notifications
* @param params - The webhook payload and signature header
* @returns A promise that resolves to an API response
*/
fivetranWebhook(params: FivetranWebhookParams): Promise<ApiResponse<any>>;
/**
* Gets available chat models for a specific project
* @param projectId - The ID of the project
* @returns A promise that resolves to an API response containing available chat models
*/
getChatModels(projectId: string): Promise<ApiResponse<any>>;
/**
* Gets OpenAI chat completions compatible tools for a specific project
* @param projectId - The ID of the project
* @returns A promise that resolves to an API response containing tools compatible with OpenAI chat completions API
*/
getChatTools(projectId: string): Promise<ApiResponse<ToolNameSpace>>;
/**
* Gets Python code for Open WebUI tools integration
* @param projectId - The ID of the project
* @returns A promise that resolves to an API response containing Python code for tools integration
*/
getChatToolsCode(projectId: string): Promise<ApiResponse<string>>;
/**
* Gets Open WebUI tools configuration for a specific project
* @param projectId - The ID of the project
* @returns A promise that resolves to an API response containing Open WebUI tools configuration
*/
getOpenWebUITools(projectId: string): Promise<ApiResponse<any[]>>;
/**
* Gets chat tool schema for a specific project
* @param projectId - The ID of the project
* @returns A promise that resolves to an API response containing the schema for chat tools
*/
getChatToolSchema(projectId: string): Promise<ApiResponse<any>>;
/**
* Call a specific tool function for a chat integration
* @param params - Parameters for calling the tool function
* @returns A promise that resolves to an API response containing the result of the tool call
*/
callChatToolFunction(params: CallToolFunctionParams): Promise<ApiResponse<any>>;
/**
* Create a chat completion using project APIs as tools
* @param projectId - The ID of the project
* @param requestBody - The chat completion request payload
* @returns A promise that resolves to an API response containing the chat completion
*/
createChatCompletion(projectId: string, requestBody: any): Promise<ApiResponse<any>>;
/**
* Test an HTTP API connection by making a request and returning the response
* @param requestConfig - The configuration for the HTTP request
* @returns A promise that resolves to an API response containing the test results with status, content type, and data
*/
testHttpConnection(requestConfig: TestHttpConnectionRequest): Promise<ApiResponse<TestHttpConnectionResponse>>;
/**
* Execute an HTTP API request using the Endpoint class from infactory.sources
* This function uses the Endpoint.from_connect_spec to directly get a DataFrame from an API,
* similar to how sample_containers works in Cosmos DB
* @param requestConfig - The configuration for the HTTP request
* @returns A promise that resolves to an API response containing the execution jobs
*/
executeHttpRequest(requestConfig: ExecuteHttpRequestRequest): Promise<ApiResponse<ExecuteHttpRequestResponse>>;
}
/**
* Error classes for the Infactory SDK
*/
/**
* Base error class for all Infactory API errors
*/
declare class InfactoryAPIError extends Error {
status: number;
code: string;
requestId?: string | undefined;
details?: any | undefined;
constructor(status: number, code: string, message: string, requestId?: string | undefined, details?: any | undefined);
/**
* Convert error to a plain object for serialization
*/
toJSON(): {
name: string;
status: number;
code: string;
message: string;
requestId: string | undefined;
details: any;
};
}
/**
* Error thrown when authentication fails
*/
declare class AuthenticationError extends InfactoryAPIError {
constructor(message: string, requestId?: string, details?: any);
}
/**
* Error thrown when the user doesn't have permission to perform an action
*/
declare class PermissionError extends InfactoryAPIError {
constructor(message: string, requestId?: string, details?: any);
}
/**
* Error thrown when a resource is not found
*/
declare class NotFoundError extends InfactoryAPIError {
constructor(message: string, requestId?: string, details?: any);
}
/**
* Error thrown when a request is invalid
*/
declare class ValidationError extends InfactoryAPIError {
constructor(message: string, requestId?: string, details?: any);
}
/**
* Error thrown when a request conflicts with the current state
*/
declare class ConflictError extends InfactoryAPIError {
constructor(message: string, requestId?: string, details?: any);
}
/**
* Error thrown when the API rate limit is exceeded
*/
declare class RateLimitError extends InfactoryAPIError {
constructor(message: string, requestId?: string, details?: any);
}
/**
* Error thrown when there is a server error
*/
declare class ServerError extends InfactoryAPIError {
constructor(message: string, requestId?: string, details?: any);
}
/**
* Error thrown when the service is unavailable
*/
declare class ServiceUnavailableError extends InfactoryAPIError {
constructor(message: string, requestId?: string, details?: any);
}
/**
* Error thrown when a network error occurs
*/
declare class NetworkError extends InfactoryAPIError {
constructor(message: string, details?: any);
}
/**
* Create an appropriate error instance based on the HTTP status code
*/
declare function createErrorFromStatus(status: number, code: string | undefined, message: string, requestId?: string, details?: any): InfactoryAPIError;
/**
* Ensure this aligns with the schema components of openapi schema and infactory database schemas
*/
/**
* Standard API response format
* Either contains data on success or an error on failure
*/
interface ApiResponse<T> {
data?: T;
error?: InfactoryAPIError;
}
interface ApiKeyResponse<TData = any> {
success: boolean;
data?: TData;
error?: InfactoryAPIError;
}
interface BaseEntity {
id: string;
createdAt: string;
updatedAt: string;
deletedAt?: string | null;
}
interface Platform {
id: string;
name: string;
description?: string;
createdAt: string;
updatedAt: string;
deletedAt?: string | null;
metadata?: Record<string, any>;
}
interface Organization {
id: string;
createdAt: string;
updatedAt: string;
deletedAt?: string | null;
name: string;
description?: string;
platformId: string;
clerkOrgId?: string;
teams: Team[];
}
/**
* Team object as returned by the API
*/
interface Team {
id: string;
name: string;
organizationId: string;
createdAt: string;
updatedAt: string;
deletedAt?: string | null;
credentials?: any;
projects?: any;
rbac?: any;
secrets?: any;
organizations?: any;
userTeams?: any;
}
/**
* Team Membership object as returned by the API
*/
interface TeamMembership {
userId: string;
teamId: string;
role: TeamMembershipRole;
createdAt: string;
updatedAt: string;
deletedAt?: string | null;
}
/**
* Valid roles for team memberships
*/
declare enum TeamMembershipRole {
ADMIN = "admin",
MEMBER = "member",
VIEWER = "viewer"
}
/**
* Project object as returned by the API
*/
interface Project {
id: string;
name: string;
description?: string;
teamId?: string;
createdAt: string;
updatedAt: string;
deletedAt?: string | null;
datasources?: any[];
events?: any[];
teams?: any[];
datalines?: any[];
api?: any[];
jobs?: any[];
conversations?: any[];
queryprograms?: any[];
ontologies?: any[];
apiLogs?: any[];
}
interface CreateProjectParams$1 {
name: string;
description?: string;
teamId: string;
}
interface Infrastructure extends BaseEntity {
name: string;
organizationId: string;
type: string;
config: Record<string, any>;
}
interface CreateInfrastructureParams {
name: string;
organizationId: string;
type: string;
config: Record<string, any>;
}
interface Dataline extends BaseEntity {
name: string;
projectId: string;
dataobjectId?: string;
schemaCode?: string;
dataModel?: Record<string, any>;
dataobjects?: any;
projects?: any;
queryprograms?: any;
}
declare enum DatasourceStatus {
WORKING = "working",
READY = "ready",
FAILED = "failed",
/**
* Newly created datasource that has not started any processing yet
*/
CREATED = "created"
}
declare enum DatasourcePhase {
UPLOAD_STARTED = "upload_started",
UPLOAD_IN_PROGRESS = "upload_in_progress",
UPLOAD_COMPLETED = "upload_completed",
SYNC_STARTED = "sync_started",
SYNC_IN_PROGRESS = "sync_in_progress",
SYNC_COMPLETED = "sync_completed",
CONVERT_STARTED = "convert_started",
CONVERT_IN_PROGRESS = "convert_in_progress",
CONVERT_COMPLETED = "convert_completed",
SCHEMA_GENERATION_STARTED = "generate_schema_started",
SCHEMA_GENERATION_IN_PROGRESS = "generate_schema_in_progress",
SCHEMA_GENERATION_COMPLETED = "generate_schema_completed",
TRANSFORMATION_STARTED = "transformation_started",
TRANSFORMATION_IN_PROGRESS = "transformation_in_progress",
TRANSFORMATION_COMPLETED = "transformation_completed",
STARTED = "started",
IN_PROGRESS = "in_progress",
COMPLETED = "completed"
}
type DatasourceStatusType = 'working' | 'ready' | 'failed';
type DatasourcePhaseType = 'upload_started' | 'upload_in_progress' | 'upload_completed' | 'sync_started' | 'sync_in_progress' | 'sync_completed' | 'convert_started' | 'convert_in_progress' | 'convert_completed' | 'generate_schema_started' | 'generate_schema_in_progress' | 'generate_schema_completed' | 'transformation_started' | 'transformation_in_progress' | 'transformation_completed' | 'started' | 'in_progress' | 'completed';
interface DatasourceWithDatalines extends BaseEntity {
name: string | null;
type: string | null;
uri: string | null;
projectId: string;
credentials: any;
status: DatasourceStatus | null;
phase: DatasourcePhase | null;
/** Optional JSON schema for the datasource */
schema?: Record<string, any>;
/** Array of datalines (rows preview / sample) */
datalines?: Dataline[];
dataobjects: DataObject[];
projects: any;
}
interface DataObject {
id: string;
bucket: string;
key: string;
fileType: string;
fileSize: number;
etag: string;
mimeType: string;
metadata: any;
datasourceId: string;
downstreamLineage: Lineage[] | null;
upstreamLineage: any;
datalines: Dataline[];
datasources: any;
queryprograms: any;
createdAt: string;
updatedAt: string;
deletedAt: string | null;
}
interface Lineage extends BaseEntity {
upstreamId: string | null;
downstreamId: string;
transformation: string;
metadata: any;
downstream: any;
upstream: any;
}
interface CreateDatalineParams {
name: string;
projectId: string;
dataobjectId?: string;
schemaCode?: string;
dataModel?: Record<string, any>;
}
interface Datasource extends BaseEntity {
name: string;
projectId: string;
type: string;
uri?: string;
status?: DatasourceStatusType;
deletedAt?: string | null;
}
interface CreateDatasourceParams {
/** Parent project ID */
projectId: string;
/** Human-friendly datasource name */
name?: string;
/** Type, e.g. `csv`, `http`, `database`, … */
type?: string;
/** Optional source URI */
uri?: string;
/** Processing status */
status?: DatasourceStatus;
/** Processing phase */
phase?: DatasourcePhase;
/** Optional status / error message */
message?: string;
/** Optional detailed description */
description?: string;
/**
* Rich configuration object used by HTTP / database sources in the UI.
* This is intentionally loose-typed because each connector stores different keys.
*/
dataSourceConfig?: Record<string, any>;
}
interface Credential extends BaseEntity {
name: string;
type: string;
organizationId: string;
config: Record<string, any>;
}
interface CreateCredentialParams {
name: string | ((id: string) => string);
type: string;
description?: string;
metadata?: Record<string, any>;
datasourceId?: string;
teamId?: string;
organizationId: string;
infrastructureId?: string;
config: Record<string, any>;
}
interface Secret extends BaseEntity {
name: string;
teamId: string;
type?: string;
value: string;
credentialsId?: string;
}
interface CreateSecretParams {
name: string | ((id: string) => string);
teamId: string;
type?: string;
value: string;
credentialsId?: string;
}
interface QueryProgram extends BaseEntity {
name?: string | null;
cue?: string | null;
code?: string | null;
steps?: string | null;
slots?: string | null;
stores?: string | null;
published?: boolean | null;
reason?: string | null;
projectId: string;
ontologyId?: string | null;
}
interface CreateQueryProgramParams {
cue?: string;
code?: string;
steps?: string;
slots?: string;
stores?: string;
published?: boolean;
reason?: string;
projectId: string;
/** Allow additional dynamic properties */
[key: string]: any;
}
/**
* Response from executing a query program
* Aligns with the OpenAPI schema definition
*/
interface QueryResponse {
result: any;
metadata?: Record<string, any>;
success?: boolean;
error?: string;
status?: string;
executionTime?: number;
}
interface User extends BaseEntity {
email: string;
name?: string;
clerkUserId: string;
organizationId?: string;
}
interface User extends BaseEntity {
email: string;
name?: string;
clerkUserId: string;
organizationId?: string;
}
interface UserTeam {
userId: string;
teamId: string;
createdAt: string;
updatedAt: string;
deletedAt: string | null;
}
interface UserWithTeamsAndOrganization extends User {
userTeams: UserTeam[];
organization: Organization;
apiKeys: any;
apiLogs: any;
}
interface RBACRole extends BaseEntity {
name: string;
description?: string;
permissions: string[];
}
interface RBACRole extends BaseEntity {
name: string;
description?: string;
permissions: string[];
}
interface Task extends BaseEntity {
name: string;
status: string;
projectId: string;
type: string;
metadata?: Record<string, any>;
}
interface CreateTaskParams {
name: string;
projectId: string;
type: string;
metadata?: Record<string, any>;
}
interface Event extends BaseEntity {
name: string;
projectId: string;
type: string;
status: string;
metadata?: Record<string, any>;
}
interface CreateEventParams {
name: string;
projectId: string;
type: string;
status: string;
metadata?: Record<string, any>;
}
interface API extends BaseEntity {
name: string;
description?: string;
projectId: string;
slug: string;
version: string;
tags?: string[];
status: 'draft' | 'published' | 'deprecated';
specification?: Record<string, any>;
}
interface CreateAPIParams {
/** API friendly display name */
name?: string;
projectId: string;
slug: string;
version: string;
description?: string;
servers?: string[];
security?: SecurityRequirement[];
tags?: string;
}
interface EndpointTypes {
GET: 'GET';
POST: 'POST';
PUT: 'PUT';
DELETE: 'DELETE';
PATCH: 'PATCH';
}
interface APIEndpoint extends BaseEntity {
name: string;
description?: string;
apiId: string;
path: string;
tags?: string;
httpMethod: EndpointTypes[keyof EndpointTypes];
requestSchema?: Record<string, any>;
responseSchema?: Record<string, any>;
implementation?: string;
queryprogramId?: string;
}
interface CreateAPIEndpointParams {
apiId: string;
endpointName: string;
httpMethod: EndpointTypes[keyof EndpointTypes];
path: string;
queryprogramId: string;
description?: string;
operationId?: string;
tags?: string;
parameters?: string;
requestBody?: string;
responses?: string;
security?: SecurityRequirement[];
}
interface PaginationParams {
page?: number;
limit?: number;
offset?: number;
sort?: string;
order?: 'asc' | 'desc';
}
declare enum ConversationMode {
build = "build",
explore = "explore"
}
interface ParameterSchema {
type: string;
description: string;
format?: string;
default?: any;
enum?: string[];
}
interface ListParameterSchema {
type: 'array';
description: string;
items: ParameterSchema;
}
interface FunctionParameters {
type: 'object';
properties: Record<string, ParameterSchema | ListParameterSchema>;
required: string[];
additionalProperties: boolean;
}
interface FunctionDefinition {
name: string;
description: string;
strict: boolean;
parameters: FunctionParameters;
}
interface ToolNameSpace {
name: string;
functions: FunctionDefinition[];
fnMapping: Record<string, string>;
}
interface ContextInfo {
location?: string;
date?: string;
}
interface FunctionMessageReference {
requestId?: string;
conversationId: string;
/** Original function message ID (optional – back-compat) */
messageId?: string;
authorUserId?: string;
projectId?: string;
nodeId?: string;
channel?: string;
}
interface Graph {
nodes: Node[];
edges: Edge[];
}
interface Node {
id: string;
type: string;
data: {
label: string;
nodeType: string;
[key: string]: any;
};
}
interface Edge {
id: string;
source: string;
target: string;
type: string;
data?: any;
}
/** Security requirement in OpenAPI spec */
interface SecurityRequirement {
[scheme: string]: string[];
}
/** Security scheme object in OpenAPI components */
interface SecurityScheme {
type: 'http' | 'apiKey' | 'oauth2' | 'openIdConnect';
description?: string;
name?: string;
in?: 'query' | 'header' | 'cookie';
scheme?: string;
bearerFormat?: string;
flows?: Record<string, any>;
openIdConnectUrl?: string;
}
/**
* Coverage status for query programs
*/
interface CoverageStatus {
slots_count: number;
columns_count: number;
columns: string[];
}
/**
* Coverage by publish status
*/
interface CoverageByStatus {
published: CoverageStatus;
unpublished: CoverageStatus;
}
/**
* Response for the coverage endpoint
*/
interface GetCoverageResponse {
total_columns: number;
used_columns_count: number;
coverage_percentage: number;
all_columns: string[];
used_columns: string[];
coverage_by_status: CoverageByStatus;
}
/**
* HTTP API Authentication Configuration
*/
interface HttpAPIAuthConfig {
apiKey?: Record<string, any>;
bearerToken?: string;
basicAuth?: Record<string, any>;
}
/**
* Parameter Configuration
*/
interface ParameterConfig {
value: string;
required?: boolean;
}
/**
* Parameter Group
*/
interface ParameterGroup {
required?: boolean;
parameters: Array<Record<string, string>>;
}
/**
* HTTP Body Configuration
*/
interface HttpBodyConfig {
type: string;
contentType?: string;
content?: string;
parameters?: Record<string, string>;
}
/**
* Test HTTP API Request
*/
interface TestHttpAPIRequest {
url: string;
method?: string;
headers?: Record<string, string>;
parameters?: Record<string, ParameterConfig>;
parameterGroups?: ParameterGroup[];
authType?: string;
auth?: HttpAPIAuthConfig;
body?: HttpBodyConfig;
responsePathExtractor?: string;
}
/**
* Database connection test request
*/
interface TestConnectionRequest {
connectionString: string;
}
/**
* Validate SQL syntax request
*/
interface ValidateSqlSyntaxRequest {
connectionString: string;
sqlQuery: string;
}
interface TableInfo {
name: string;
estimatedRows: number;
estimatedSize: string;
columnCount: number;
}
interface TestConnectionResponse {
success: boolean;
tables: TableInfo[];
}
/**
* Sample tables request
*/
interface SampleTablesRequest {
connectionString: string;
tableNames: string[];
projectId: string;
datasourceId: string;
name: string;
}
interface SampleTablesRequest {
connectionString: string;
tableNames: string[];
projectId: string;
datasourceId: string;
name: string;
}
interface I7YPendingJob {
jobType: string;
projectId: string;
userId: string | null;
parentJobId: string | null;
metadata: any;
payload: Record<string, any>;
}
interface SampleTablesResponse {
dataObjects: Record<string, string>;
jobs: I7YPendingJob[];
}
/**
* Execute custom SQL request
*/
interface ExecuteCustomSqlRequest {
connectionString: string;
sqlQuery: string;
samplingSqlQuery: string;
projectId: string;
datasourceId: string;
name: string;
}
interface ExecuteCustomSqlRequest {
connectionString: string;
sqlQuery: string;
samplingSqlQuery: string;
projectId: string;
datasourceId: string;
name: string;
}
interface ExecuteCustomSqlResponse {
jobs: I7YPendingJob[];
}
/**
* Validate SQL query request
*/
interface ValidateSqlQueryRequest {
connectionString: string;
sqlQuery: string;
maxRows?: number;
}
interface ValidateSqlQueryRequest {
connectionString: string;
sqlQuery: string;
}
interface ValidateSqlQueryResponse {
rowCount: number;
valid: boolean;
message?: string;
}
interface SqlParameter {
type: string;
field: string;
operator: string;
value: string;
displayName: string;
}
/**
* Extract SQL parameters request
*/
interface ExtractSqlParametersRequest {
sqlQuery: string;
}
interface ExtractSqlParametersRequest {
sqlQuery: string;
}
interface ExtractSqlParametersResponse {
parameters: SqlParameter[];
parsedQuery: string;
}
interface DatabaseCapabilitiesListResponse {
capabilities: string[];
}
interface DatabaseConnectionParams {
connectionString: string;
}
interface ValidateQueryRequest {
connectionString: string;
query: string;
}
/**
* Options for connecting to an HTTP API
*/
interface ConnectOptions {
url: string;
method: HttpMethod;
projectId: string;
connectionName: string;
organizationId?: string;
teamId?: string;
headers?: Record<string, string>;
parameters?: Record<string, any>;
responsePathExtractor?: string;
authType?: AuthType;
authConfig?: Record<string, any>;
}
/**
* Result of an HTTP connection operation
*/
interface HttpConnectionResult {
success: boolean;
stepsCompleted: string[];
datasourceId?: string;
dataObjectId?: string;
jobIds: string[];
errors: Array<{
step: string;
error: string;
}>;
testResult?: TestConnectionResponse | TestHttpConnectionResponse;
datasource?: Datasource;
credentials?: any;
jobs?: any[];
}
/**
* Parameters for the unified 'connect' method in DatasourcesClient
*/
interface ConnectDatasourceParams {
projectId: string;
name: string;
type: string;
uri?: string;
status?: string;
config?: {
url?: string;
method?: string;
headers?: Record<string, string>;
parameters?: Record<string, any>;
parameterGroups?: any[];
authType?: string;
auth?: Record<string, any>;
body?: any;
responsePathExtractor?: string;
teamId?: string;
organizationId?: string;
};
credentialsId?: string;
filePath?: string;
sampleTables?: string[];
}
/**
* A modern HTTP client implementation with interceptors and automatic serialization/deserialization.
* This client serves as the foundation for all API requests in the Infactory SDK.
*/
/**
* Represents a request interceptor function.
* @template T - The type of the request data.
*/
type RequestInterceptor = (request: HttpRequest) => HttpRequest | Promise<HttpRequest>;
/**
* Represents a response interceptor function.
*/
type ResponseInterceptor = (response: Response, request: HttpRequest) => Response | Promise<Response>;
/**
* Configuration options for the HTTP client.
*/
interface HttpClientOptions {
/** Base URL for API requests */
baseUrl: string;
/** API key for authentication */
apiKey?: string;
/** Custom fetch implementation */
fetch?: typeof globalThis.fetch;
/** Default request headers */
defaultHeaders?: Record<string, string>;
/** Authentication location: header (Bearer), query (nf_api_key), or cookie-based */
authIn?: 'header' | 'query' | 'cookie';
/** Whether this client is running on the server side */
isServer?: boolean;
}
/**
* Represents an HTTP request object.
*/
interface HttpRequest extends RequestInit {
/** The URL for the request */
url: string;
/** Query parameters to append to the URL */
params?: Record<string, any>;
/** The JSON body of the request (will be serialized) */
jsonBody?: any;
}
/**
* A modern HTTP client with interceptors and automatic serialization/deserialization.
*/
declare class HttpClient {
private baseUrl;
private apiKey?;
private fetchImpl;
private defaultHeaders;
private authIn;
private isServer;
private requestInterceptors;
private responseInterceptors;
/**
* Gets the configured API key.
* @returns The API key or empty string if not set.
*/
getApiKey(): string;
/**
* Gets the configured base URL.
* @returns The base URL.
*/
getBaseUrl(): string;
getIsServer(): boolean;
/**
* Creates a new HTTP client instance.
* @param options - Configuration options for the client.
*/
constructor(options: HttpClientOptions);
/**
* Adds a request interceptor to the chain.
* @param interceptor - The request interceptor function.
* @returns This HTTP client instance for chaining.
*/
addRequestInterceptor(interceptor: RequestInterceptor): HttpClient;
/**
* Adds a response interceptor to the chain.
* @param interceptor - The response interceptor function.
* @returns This HTTP client instance for chaining.
*/
addResponseInterceptor(interceptor: ResponseInterceptor): HttpClient;
/**
* Executes an HTTP request with the configured settings and interceptors.
* @param request - The HTTP request configuration.
* @returns A promise resolving to the response with data of type T.
*/
request<T>(request: HttpRequest): Promise<ApiResponse<T>>;
/**
* Executes an HTTP GET request.
* @param endpoint - The API endpoint path.
* @param params - Optional query parameters.
* @param options - Optional fetch options.
* @returns A promise resolving to the response with data of type T.
*/
get<T>(endpoint: string, params?: Record<string, any>, options?: RequestInit): Promise<ApiResponse<T>>;
/**
* Executes an HTTP POST request.
* @param endpoint - The API endpoint path.
* @param body - Optional request body (will be JSON serialized).
* @param params - Optional query parameters.
* @param options - Optional fetch options.
* @returns A promise resolving to the response with data of type T.
*/
post<T, U = any>(endpoint: string, body?: U, options?: RequestInit): Promise<ApiResponse<T>>;
/**
* Executes an HTTP PUT request.
* @param endpoint - The API endpoint path.
* @param body - Optional request body (will be JSON serialized).
* @param params - Optional query parameters.
* @param options - Optional fetch options.
* @returns A promise resolving to the response with data of type T.
*/
put<T, U = any>(endpoint: string, body?: U, params?: Record<string, any>, options?: RequestInit): Promise<ApiResponse<T>>;
/**
* Executes an HTTP PATCH request.
* @param endpoint - The API endpoint path.
* @param body - Optional request body (will be JSON serialized).
* @param params - Optional query parameters.
* @param options - Optional fetch options.
* @returns A promise resolving to the response with data of type T.
*/
patch<T, U = any>(endpoint: string, body?: U, options?: RequestInit): Promise<ApiResponse<T>>;
/**
* Executes an HTTP DELETE request.
* @param endpoint - The API endpoint path.
* @param params - Optional query parameters.
* @param options - Optional fetch options.
* @returns A promise resolving to the response with data of type T.
*/
delete<T>(endpoint: string, params?: Record<string, any>, options?: RequestInit): Promise<ApiResponse<T>>;
/**
* Uploads a file to the API endpoint.
* @param endpoint - The API endpoint path.
* @param file - The file to upload.
* @param formFields - Additional form fields to include.
* @param params - Optional query parameters.
* @param options - Optional fetch options.
* @returns A promise resolving to the response with data of type T.
*/
uploadFile<T>(endpoint: string, file: File, formFields?: Record<string, any>, params?: Record<string, any>, options?: RequestInit): Promise<ApiResponse<T>>;
/**
* Downloads a file from the API endpoint.
* @param endpoint - The API endpoint path.
* @param params - Optional query parameters.
* @param defaultFilename - The default filename to use if not specified in headers.
* @returns A promise resolving to the response with download info of type T.
*/
downloadFile<T>(endpoint: string, params?: Record<string, any>, defaultFilename?: string, options?: RequestInit): Promise<ApiResponse<T>>;
/**
* Creates a streaming request to the API endpoint.
* @param endpoint - The API endpoint path.
* @param options - The fetch options for the request.
* @param signal - Optional abort signal for cancellation.
* @returns A promise resolving to a readable stream.
*/
createStream(endpoint: string, options: HttpRequest, signal?: AbortSignal): Promise<ReadableStream>;
/**
* Prepares the request URL and options.
* @param request - The HTTP request configuration.
* @returns The prepared URL and fetch options.
*/
private prepareRequest;
/**
* Processes an HTTP response.
* @param response - The fetch response object.
* @returns A promise resolving to the processed API response.
*/
private processResponse;
/**
* Handles errors that occur during the request.
* @param error - The error that occurred.
* @returns An API response containing the error.
*/
private handleRequestError;
/**
* Builds a URL with query parameters.
* @param endpoint - The API endpoint path.
* @param params - The query parameters to append.
* @returns The complete URL string.
*/
private buildUrl;
}
type CreatePlatformParams = Pick<Platform, 'name' | 'description' | 'metadata'>;
type UpdatePlatformParams = Pick<Platform, 'name' | 'description' | 'metadata'>;
/**
* Client for managing platforms in the Infactory API
*/
declare class PlatformsClient {
private readonly httpClient;
/**
* Creates a new PlatformsClient instance
* @param httpClient - The HTTP client to use for API requests
*/
constructor(httpClient: HttpClient);
/**
* Get a list of all platforms
* @returns A promise that resolves to an API response containing an array of platforms
*/
list(): Promise<ApiResponse<Platform[]>>;
/**
* Get a platform by ID
* @param id - The ID of the platform to retrieve
* @returns A promise that resolves to an API response containing the platform
*/
get(id: string): Promise<ApiResponse<Platform>>;
/**
* Create a new platform
* @param params - The parameters for creating the platform
* @returns A promise that resolves to an API response containing the created platform
*/
create(params: CreatePlatformParams): Promise<ApiResponse<Platform>>;
/**
* Update a platform
* @param id - The ID of the platform to update
* @param params - The parameters for updating the platform
* @returns A promise that resolves to an API response containing the updated platform
*/
update(id: string, params: UpdatePlatformParams): Promise<ApiResponse<Platform>>;
/**
* Delete a platform
* @param id - The ID of the platform to delete
* @returns A promise that resolves to an API response containing the deleted platform
*/
delete(id: string): Promise<ApiResponse<Platform>>;
}
type CreateOrganizationParams = Pick<Organization, 'name' | 'description' | 'clerkOrgId'> & {
platformId?: string;
};
/**
* Client for managing organizations in the Infactory API
*/
declare class OrganizationsClient {
private readonly httpClient;
/**
* Creates a new OrganizationsClient instance
* @param httpClient - The HTTP client to use for API requests
*/
constructor(httpClient: HttpClient);
/**
* Get a list of all organizations
* @returns A promise that resolves to an API response containing an array of organizations
*/
list(): Promise<ApiResponse<Organization[]>>;
/**
* Get an organization by ID
* @param id - The ID of the organization to retrieve
* @returns A promise that resolves to an API response containing the organization
*/
get(id: string): Promise<ApiResponse<Organization>>;
/**
* Get an organization by Clerk ID
* @param clerkOrgId - The Clerk ID of the organization to retrieve
* @returns A promise that resolves to an API response containing the organization
*/
getByClerkId(clerkOrgId: string): Promise<ApiResponse<Organization>>;
/**
* Create a new organization
* @param params - The parameters for creating the organization
* @returns A promise that resolves to an API response containing the created organization
*/
create(params: CreateOrganizationParams): Promise<ApiResponse<Organization>>;
/**
* Update an organization
* @param id - The ID of the organization to update
* @param params - The parameters for updating the organization
* @returns A promise that resolves to an API response containing the updated organization
*/
update(id: string, params: Partial<CreateOrganizationParams>): Promise<ApiResponse<Organization>>;
/**
* Delete an organization
* @param id - The ID of the organization to delete
* @returns A promise that resolves to an API response containing the deleted organization
*/
delete(id: string): Promise<ApiResponse<Organization>>;
/**
* Move an organization to a new platform
* @param id - The ID of the organization to move
* @param newPlatformId - The ID of the platform to move the organization to
* @returns A promise that resolves to an API response containing the moved organization
*/
move(id: string, newPlatformId: string): Promise<ApiResponse<Organization>>;
}
/**
* Parameters for creating a team
*/
type CreateTeamParams = Pick<Team, 'name' | 'organizationId'>;
/**
* Parameters for updating a team
*/
type UpdateTeamParams = Pick<Team, 'name'>;
/**
* Client for managing teams in the Infactory API
*/
declare class TeamsClient {
private readonly httpClient;
/**
* Creates a new TeamsClient instance
* @param httpClient - The HTTP client to use for API requests
*/
constructor(httpClient: HttpClient);
/**
* Get a list of all teams for an organization
* @param organizationId - The ID of the organization to get teams for
* @returns A promise that resolves to an API response containing an array of teams
*/
getTeams(organizationId: string): Promise<ApiResponse<Team[]>>;
/**
* Get a team by ID
* @param id - The ID of the team to retrieve
* @returns A promise that resolves to an API response containing the team
*/
getTeam(id: string): Promise<ApiResponse<Team>>;
/**
* Create a new team
* @param params - The parameters for creating the team
* @returns A promise that resolves to an API response containing the created team
*/
createTeam(params: CreateTeamParams): Promise<ApiResponse<Team>>;
/**
* Update a team
* @param id - The ID of the team to update
* @param params - The parameters for updating the team
* @returns A promise that resolves to an API response containing the updated team
*/
updateTeam(id: string, params: UpdateTeamParams): Promise<ApiResponse<Team>>;
/**
* Delete a team
* @param id - The ID of the team to delete
* @returns A promise that resolves to an API response
*/
deleteTeam(id: string): Promise<ApiResponse<void>>;
/**
* Move a team to a new organization
* @param id - The ID of the team to move
* @param newOrganizationId - The ID of the organization to move the team to
* @returns A promise that resolves to an API response containing the moved team
*/
moveTeam(id: string, newOrganizationId: string): Promise<ApiResponse<Team>>;
/**
* Get all memberships for a team
* @param teamId - The ID of the team to get memberships for
* @returns A promise that resolves to an API response containing an array of team memberships
*/
getTeamMemberships(teamId: string): Promise<ApiResponse<TeamMembership[]>>;
/**
* Create a team membership
* @param teamId - The ID of the team
* @param userId - The ID of the user
* @param role - The role for the membership
* @returns A promise that resolves to an API response containing the created team membership
*/
createTeamMembership(teamId: string, userId: string, role: TeamMembershipRole): Promise<ApiResponse<TeamMembership>>;
/**
* Update a team membership
* @param teamId - The ID of the team
* @param userId - The ID of the user
* @param role - The new role for the membership
* @returns A promise that resolves to an API response containing the updated team membership
*/
updateTeamMembership(teamId: string, userId: string, role: TeamMembershipRole): Promise<ApiResponse<TeamMembership>>;
/**
* Delete a team membership
* @param teamId - The ID of the team
* @param userId - The ID of the user
* @param permanent - Whether to permanently delete the membership
* @returns A promise that resolves to an API response
*/
deleteTeamMembership(teamId: string, userId: string, permanent?: boolean): Promise<ApiResponse<TeamMembership>>;
}
/**
* Parameters for creating a project
*/
type CreateProjectParams = Pick<Project, 'name' | 'description'> & {
teamId?: string;
};
/**
* Parameters for updating a project
*/
type UpdateProjectParams = Partial<Pick<Project, 'name' | 'description'>> & {
deletedAt?: string | null;
};
/**
* Response from a project import operation
*/
interface ProjectImportResponse {
project?: Project;
importLog?: any;
success?: boolean;
message?: string;
project_id?: string;
project_name?: string;
}
/**
* Client for managing projects in the Infactory API
*/
declare class ProjectsClient {
private readonly httpClient;
/**
* Creates a new ProjectsClient instance
* @param httpClient - The HTTP client to use for API requests
*/
constructor(httpClient: HttpClient);
/**
* Get a list of all projects
* @param teamId - Optional team ID to filter projects by
* @param includeDeleted - Whether to include deleted projects
* @returns A promise that resolves to an API response containing an array of projects
*/
getProjects(teamId?: string, includeDeleted?: boolean): Promise<ApiResponse<Project[]>>;
/**
* Get projects for a specific team
* @param teamId - The ID of the team to get projects for
* @param includeDeleted - Whether to include deleted projects
* @returns A promise that resolves to an API response containing an array of projects
*/
getTeamProjects(teamId: string, includeDeleted?: boolean): Promise<ApiResponse<Project[]>>;
/**
* Get a project by ID
* @param projectId - The ID of the project to retrieve
* @param teamId - Optional team ID for access control
* @returns A promise that resolves to an API response containing the project
*/
getProject(projectId: string, teamId?: string): Promise<ApiResponse<Project>>;
/**
* Create a new project
* @param params - The parameters for creating the project
* @returns A promise that resolves to an API response containing the created project
*/
createProject(params: CreateProjectParams): Promise<ApiResponse<Project>>;
/**
* Update a project
* @param projectId - The ID of the project to update
* @param params - The parameters for updating the project
* @returns A promise that resolves to an API response containing the updated project
*/
updateProject(projectId: string, params: UpdateProjectParams): Promise<ApiResponse<Project>>;
/**
* Delete a project
* @param projectId - The ID of the project to delete
* @param permanent - Whether to permanently delete the project
* @returns A promise that resolves to an API response
*/
deleteProject(projectId: string, permanent?: boolean): Promise<ApiResponse<void>>;
/**
* Move a project to a new team
* @param projectId - The ID of the project to move
* @param newTeamId - The ID of the team to move the project to
* @returns A promise that resolves to an API response containing the moved project
*/
moveProject(projectId: string, newTeamId: string): Promise<ApiResponse<Project>>;
/**
* Export a project
* @param projectId - The ID of the project to export
* @param teamId - The ID of the team the project belongs to
* @returns A promise that resolves to an API response containing the export data
*/
exportProject(projectId: string, teamId: string): Promise<ApiResponse<any>>;
/**
* Import a project
* @param teamId - The ID of the team to import the project into
* @param file - The project configuration file to import
* @param conflictStrategy - Strategy for handling naming conflicts
* @param renameSuffix - Custom suffix to use for renaming projects (when conflict_strategy is 'rename')
* @returns A promise that resolves to an API response containing the imported project
*/
/**
* Import a project from a JSON file.
* @param teamId - The ID of the team to import the project into
* @param fileOrFilePath - Either a File object (browser) or a file path string (Node.js)
* @param options - Optional: { conflictStrategy, renameSuffix }
* @returns A promise that resolves to an API response containing the imported project
*/
importProject(teamId: string, fileOrFilePath: File | string, options?: {
conflictStrategy?: 'rename' | 'overwrite' | 'skip';
renameSuffix?: string;
}): Promise<ApiResponse<ProjectImportResponse>>;
/**
* Validate a project import file without importing it
* @param file - The project configuration file to validate
* @returns A promise that resolves to an API response containing validation info
*/
validateImport(file: File): Promise<ApiResponse<any>>;
/**
* Get coverage information for a project's query programs
* @param projectId - The ID of the project
* @returns A promise that resolves to an API response containing coverage information
*/
getCoverage(projectId: string): Promise<ApiResponse<GetCoverageResponse>>;
}
interface GetOrCreateUserTeamOrganizationRequest {
clerkUserId: string;
clerkOrgId: string;
platformId: string;
}
/**
* Client for managing users in the Infactory API
*/
declare class UsersClient {
private readonly httpClient;
/**
* Creates a new UsersClient instance
* @param httpClient - The HTTP client to use for API requests
*/
constructor(httpClient: HttpClient);
/**
* Get a list of all users
* @param organizationId - Optional organization ID to filter users
* @returns A promise that resolves to an API response containing an array of users
*/
getUsers(organizationId?: string): Promise<ApiResponse<User[]>>;
/**
* Get a user by ID
* @param userId - The ID of the user to retrieve
* @returns A promise that resolves to an API response containing the user
*/
getUser(userId: string): Promise<ApiResponse<User>>;
/**
* Get the current authenticated user
* @returns A promise that resolves to an API response containing the current user with teams and organization
*/
getCurrentUser(): Promise<ApiResponse<UserWithTeamsAndOrganization>>;
/**
* Create a new user
* @param params - Parameters for creating the user
* @returns A promise that resolves to an API response containing the created user
*/
createUser(params: {
email?: string;
name?: string;
organizationId?: string;
role?: string;
}): Promise<ApiResponse<User>>;
/**
* Update a user
* @param userId - The ID of the user to update
* @param params - Parameters for updating the user
* @returns A promise that resolves to an API response containing the updated user
*/
updateUser(userId: string, params: {
email?: string;
name?: string;
role?: string;
}): Promise<ApiResponse<User>>;
/**
* Delete a user
* @param userId - The ID of the user to delete
* @returns A promise that resolves to an API response containing the deleted user
*/
deleteUser(userId: string): Promise<ApiResponse<User>>;
/**
* Move a user to a new organization
* @param userId - The ID of the user to move
* @param newOrganizationId - The ID of the organization to move the user to
* @returns A promise that resolves to an API response containing the moved user
*/
moveUser(userId: string, newOrganizationId: string): Promise<ApiResponse<User>>;
/**
* Get or create a user, team, and organization based on Clerk ID