@northflank/js-client
Version:
Node.js client for the Northflank platform based on the Northflank public API.
1,439 lines (1,420 loc) • 1.57 MB
TypeScript
import { EventEmitter } from 'events';
import * as stream from 'node:stream';
import { Stream } from 'node:stream';
type Optional<T, K extends keyof T> = Omit<T, K> & Partial<T>;
declare abstract class ApiClientContextProvider {
private contextWrapper;
constructor();
protected loadContext(): void;
getInfo(): string;
storeContext(contextWrapper: ApiClientContextWrapper): Promise<void>;
addContext(context: Optional<ApiClientContext, 'host'>, override?: boolean): Promise<void>;
removeContext(name: string): Promise<void>;
protected abstract writeContext(context: ApiClientContextWrapper): Promise<void>;
abstract loadContextWrapper(): ApiClientContextWrapper;
getCurrentContext(): ApiClientContext | undefined;
private findContext;
getCurrentBaseUrl(throwIfNotPresent?: boolean): string | undefined;
getCurrentProjectName(): string | undefined;
getCurrentName(): string | undefined;
getCurrentToken(): string | undefined;
getCurrentServiceName(): string | undefined;
getCurrentJobName(): string | undefined;
getCurrentPlanId(): string | undefined;
getCurrentRegion(): string | undefined;
useContext(name: string): Promise<void>;
updateToken(token: string, name?: string): Promise<void>;
useProjectId(id: string): Promise<void>;
useServiceId(id: string): Promise<void>;
useJobId(id: string): Promise<void>;
usePlanId(id: string): Promise<void>;
useRegion(region: string): Promise<void>;
getLastUpdateCheck(): Date;
setLastUpdateCheck(check: Date): Promise<any>;
}
interface ApiClientContextWrapper {
current?: string;
contexts: ApiClientContext[];
lastUpdateCheck?: Date;
}
interface ApiClientContext {
name: string;
token: string;
host: string;
project?: string;
service?: string;
job?: string;
plan?: string;
region?: string;
}
type PortForwardingInfo = {
type: 'addon' | 'service';
projectId: string;
id: string;
address: string;
port: number;
portName?: string;
protocol?: 'HTTP' | 'TCP' | 'UDP';
hostnames: string[];
ipOnly: boolean;
};
interface PortTunnel extends EventEmitter {
readonly bindTo?: {
address: string;
port: number;
};
readonly protocol: 'TCP' | 'UDP';
on(event: 'tunnel-open', listener: (h: {
address: string;
port: number;
}) => any): any;
on(event: 'tunnel-close', listener: () => any): any;
on(event: 'connection-accept', listener: () => any): any;
on(event: 'connection-close', listener: () => any): any;
on(event: 'connection-error', listener: (error: any) => any): any;
open(): Promise<{
address: string;
port: number;
}>;
close(): Promise<void>;
}
declare class ApiClientFileContextProvider extends ApiClientContextProvider {
configPath: string;
configFile: string;
constructor(configPath?: string);
loadContextWrapper(): ApiClientContextWrapper;
protected writeContext(context: ApiClientContextWrapper): Promise<void>;
assertDir: (path: string) => Promise<void>;
assertConfigDir(): Promise<void>;
getInfo(): string;
}
declare class ApiClientInMemoryContextProvider extends ApiClientContextProvider {
private inMemoryContextWrapper;
loadContextWrapper(): ApiClientContextWrapper;
protected writeContext(context: ApiClientContextWrapper): Promise<void>;
}
declare class NorthflankApiCallError extends Error implements ApiCallError {
id?: any;
details?: any;
status: number;
constructor(callError: ApiCallError);
}
interface ApiCallError {
/** Http status response code */
status: number;
/** Error message */
message: string;
/** Northflank error id */
id?: string;
/** Error details */
details?: any;
}
type ApiClientOpts = {
throwErrorOnHttpErrorCode?: boolean;
customUserAgent?: string;
agent?: any;
};
interface ApiCallResponse<R> {
data: R;
rawResponse: Response;
request: {
url: string;
method: string;
headers: any;
body: any;
};
error?: ApiCallError;
pagination?: {
/** Is there another page of results available? */
'hasNextPage': boolean;
/** The cursor to access the next page of results. */
'cursor'?: string;
/** The number of results returned by this request. Example: 1 */
'count': number;
getNextPage: () => Promise<ApiCallResponse<R>>;
};
}
interface ApiEndpoint<T, R> {
requiredPermissions?: string | undefined;
}
declare abstract class ApiEndpoint<T, R> {
protected readonly opts: ApiClientOpts;
protected contextProvider: ApiClientContextProvider;
abstract description: string;
abstract method: string;
abstract body(opts: T): any;
abstract endpointUrl(opts: T): string;
abstract withAuth: boolean;
constructor(contextProvider: ApiClientContextProvider, opts: ApiClientOpts);
private getDefaultHeaders;
call: (opts: T) => Promise<ApiCallResponse<R>>;
protected executeCall(opts: T): Promise<ApiCallResponse<R>>;
}
declare abstract class GetApiEndpoint<T, R> extends ApiEndpoint<T, R> {
method: string;
body: () => undefined;
abstract endpointUrl(opts: T): string;
abstract withAuth: boolean;
}
declare abstract class GetApiEndpointPaginated<T, R> extends GetApiEndpoint<T, R> {
all: (opts: T) => Promise<ApiCallResponse<R>>;
call: (opts: T) => Promise<ApiCallResponse<R>>;
}
declare abstract class PostApiEndpoint<T, R> extends ApiEndpoint<T, R> {
method: string;
abstract body(opts: T): any;
abstract endpointUrl(opts: T): string;
abstract withAuth: boolean;
}
declare abstract class DeleteApiEndpoint<T, R> extends ApiEndpoint<T, R> {
method: string;
body: () => undefined;
abstract endpointUrl(opts: T): string;
abstract withAuth: boolean;
}
declare abstract class PutApiEndpoint<T, R> extends ApiEndpoint<T, R> {
method: string;
abstract body(opts: T): any;
abstract endpointUrl(opts: T): string;
abstract withAuth: boolean;
}
declare abstract class PatchApiEndpoint<T, R> extends ApiEndpoint<T, R> {
method: string;
abstract body(opts: T): any;
abstract endpointUrl(opts: T): string;
abstract withAuth: boolean;
}
type ListServicesResult = {
/** An array of services. */
'services': {
/** Identifier for the service Example: "example-service" */
'id': string;
/** Full identifier used for service deployment Example: "/example-user/default-project/example-service" */
'appId': string;
/** ID of the project the service belongs to. Example: "default-project" */
'projectId': string;
/** Service name Example: "Example Service" */
'name': string;
/** An array of previously defined tags to help identify and group the resource. */
'tags': string[];
/** A short description of the service Example: "This is the service description" */
'description'?: string;
/** Type of the service (combined, build or deployment) Example: "combined" */
'serviceType': 'combined' | 'build' | 'deployment';
/** Whether Continuous Integration is disabled */
'disabledCI': boolean;
/** Whether Continuous Deployment is disabled */
'disabledCD': boolean;
/** Details about the current service status. */
'status': {
/** Details about the status of the most recent build. */
'build'?: {
/** The current status of the build. Example: "SUCCESS" */
'status': 'QUEUED' | 'PENDING' | 'UNSCHEDULABLE' | 'STARTING' | 'CLONING' | 'BUILDING' | 'UPLOADING' | 'ABORTED' | 'FAILURE' | 'SUBMISSION_FAILURE' | 'SUCCESS' | 'CRASHED' | 'IN_PROGRESS';
/** The timestamp of when the build reached this status. Example: "2021-11-29T11:47:16.624Z" */
'lastTransitionTime'?: string;
};
/** Details about the current deployment status. */
'deployment'?: {
/** The current status of the deployment. Example: "COMPLETED" */
'status': 'PENDING' | 'IN_PROGRESS' | 'COMPLETED' | 'FAILED';
/** The reason the current deployment was started. Example: "DEPLOYING" */
'reason': 'SCALING' | 'DEPLOYING';
/** The timestamp of when the deployment reached this status. Example: "2021-11-29T11:47:16.624Z" */
'lastTransitionTime'?: string;
};
};
}[];
};
type ListServicesCall = ((opts: ListServicesRequest) => Promise<ApiCallResponse<ListServicesResult>>) & {
all: (opts: ListServicesRequest) => Promise<ApiCallResponse<ListServicesResult>>;
};
type ListServicesRequest = {
parameters: ListServicesParameters;
options?: ListServicesOptions;
};
type ListServicesParameters = {
/** ID of the project */ 'projectId': string;
};
type ListServicesOptions = {
/** The number of results to display per request. Maximum of 100 results per page. */
'per_page'?: number;
/** The page number to access. */
'page'?: number;
/** The cursor returned from the previous page of results, used to request the next page. */
'cursor'?: string;
};
/** Gets a list of services belonging to the project */
declare class ListServicesEndpoint extends GetApiEndpointPaginated<ListServicesRequest, ListServicesResult> {
description: string;
withAuth: boolean;
requiredPermissions: string;
endpointUrl: (opts: ListServicesRequest) => string;
body: () => undefined;
}
type ListAddonsResult = {
/** An array of addons. */
'addons': {
/** Identifier for the addon. Example: "example-addon" */
'id': string;
/** Addon name. Example: "Example Addon" */
'name': string;
/** Full identifier for the addon. Example: "/example-user/default-project/example-job" */
'appId': string;
/** An array of previously defined tags to help identify and group the resource. */
'tags': string[];
/** A short description of the addon. Example: "This is the addon description" */
'description'?: string;
/** Details about the addon's specifications. */
'spec': {
/** The type of the addon Example: "mongodb" */
'type': string;
};
/** The current state of the addon. Example: "running" */
'status': 'preDeployment' | 'triggerAllocation' | 'allocating' | 'postDeployment' | 'running' | 'paused' | 'scaling' | 'upgrading' | 'resetting' | 'backup' | 'restore' | 'failed' | 'error' | 'errorAllocating' | 'deleting' | 'deleted';
}[];
};
type ListAddonsCall = ((opts: ListAddonsRequest) => Promise<ApiCallResponse<ListAddonsResult>>) & {
all: (opts: ListAddonsRequest) => Promise<ApiCallResponse<ListAddonsResult>>;
};
type ListAddonsRequest = {
parameters: ListAddonsParameters;
options?: ListAddonsOptions;
};
type ListAddonsParameters = {
/** ID of the project */ 'projectId': string;
};
type ListAddonsOptions = {
/** The number of results to display per request. Maximum of 100 results per page. */
'per_page'?: number;
/** The page number to access. */
'page'?: number;
/** The cursor returned from the previous page of results, used to request the next page. */
'cursor'?: string;
};
/** Gets a list of addons belonging to the project */
declare class ListAddonsEndpoint extends GetApiEndpointPaginated<ListAddonsRequest, ListAddonsResult> {
description: string;
withAuth: boolean;
requiredPermissions: string;
endpointUrl: (opts: ListAddonsRequest) => string;
body: () => undefined;
}
type PortForwardingResult = {
data: PortForwardingInfo;
error?: never;
} | {
data?: never;
error: {
message: string;
};
};
interface NorthflankPortForwarder {
on(event: 'connection-accept', listener: (tunnel: PortTunnel) => any): any;
on(event: 'connection-close', listener: (tunnel: PortTunnel) => any): any;
on(event: 'connection-error', listener: (tunnel: PortTunnel, data: PortForwardingInfo, error: any) => any): any;
on(event: 'tunnel-open', listener: (tunnel: PortTunnel, data: PortForwardingInfo) => any): any;
on(event: 'tunnel-close', listener: (tunnel: PortTunnel, data: PortForwardingInfo) => any): any;
}
declare class NorthflankPortForwarder extends EventEmitter {
private readonly contextProvider;
private readonly listServices;
private readonly listAddons;
private readonly agent?;
private nextIpAddress?;
private connections;
private proxyApiClient;
private hostsFileMutex;
private ipAllocationMutex;
constructor(contextProvider: ApiClientContextProvider, listServices: ListServicesEndpoint, listAddons: ListAddonsEndpoint, agent?: any | undefined);
withProjectForwarding<T = any>(parameters: {
projectId: string;
}, func: (p: {
services: PortForwardingResult[][];
addons: PortForwardingResult[][];
}) => Promise<T>, ipOnly?: boolean): Promise<T>;
forwardProject(parameters: {
projectId: string;
}, ipOnly?: boolean): Promise<{
services: PortForwardingResult[][];
addons: PortForwardingResult[][];
}>;
withServiceForwarding<T = any>(parameters: {
projectId: string;
serviceId: string;
}, func: (p: PortForwardingResult[]) => Promise<T>, ipOnly?: boolean): Promise<T>;
forwardService(parameters: {
projectId: string;
serviceId: string;
}, ipOnly?: boolean): Promise<PortForwardingResult[]>;
withAddonForwarding<T = any>(parameters: {
projectId: string;
addonId: string;
}, func: (p: PortForwardingResult[]) => Promise<T>, ipOnly?: boolean): Promise<T>;
forwardAddon(parameters: {
projectId: string;
addonId: string;
}, ipOnly?: boolean): Promise<PortForwardingResult[]>;
private allocateIpAddress;
private forwardPort;
private determineSocketAddress;
private registerHostnames;
private unregisterHostnames;
private modifyHostsFile;
stopProjectForwarding(opts: {
projectId: string;
}): Promise<void>;
stopServiceForwarding(opts: {
projectId: string;
serviceId: string;
}): Promise<void>;
stopAddonForwarding(opts: {
projectId: string;
addonId: string;
}): Promise<void>;
private stopForwarding;
stop(): Promise<void>;
canExecuteWithHostnames: () => {
error: boolean;
message?: string;
type?: "windows-admin" | "unix-admin";
};
private assertStartedWithNodejs;
}
interface ExecCommand extends EventEmitter {
on(event: 'auth-success', listener: () => any): any;
on(event: 'command-started', listener: () => any): any;
on(event: 'command-completed', listener: () => any): any;
on(event: 'command-result', listener: (result: {
code: number;
message: string;
}) => any): any;
on(event: 'error', listener: (error: any) => any): any;
on(event: 'std-out-data', listener: (data: any) => any): any;
on(event: 'std-err-data', listener: (data: any) => any): any;
}
type ExecConfig = {
projectId: string;
entityType: 'service' | 'job' | 'addon' | 'build';
entityId: string;
instanceName?: string;
containerName?: string;
command?: string | string[];
shell?: string;
user?: string | number;
group?: string | number;
encoding?: string;
tty?: boolean;
ttyRows?: number;
ttyColumns?: number;
};
declare class ExecCommandStandard extends EventEmitter implements ExecCommand {
private readonly baseUrl;
readonly execConfig: ExecConfig;
private readonly token;
private readonly agent;
readonly stdOut: stream.PassThrough;
readonly stdErr: stream.PassThrough;
readonly stdIn: stream.PassThrough;
private remote;
private currentCommand;
private duplex;
constructor(baseUrl: string, execConfig: ExecConfig, token: string, // readonly timeout: number = 120 // Timeout in seconds
agent: any, stdOut?: stream.PassThrough, stdErr?: stream.PassThrough, stdIn?: stream.PassThrough);
private get execEndpoint();
waitForCommandResult: () => Promise<CommandResult>;
sendInputToCurrentCommand: (input: string) => Promise<void>;
resizeTerminal: (size: {
rows?: number;
columns?: number;
}) => Promise<void>;
start(): Promise<CommandResult>;
private constructPayloadPacket;
private stdInEndPacket;
private initialAuth;
private reset;
}
type CommandResult = {
exitCode: number;
status: 'Success' | 'Failure' | 'Unknown';
message?: string;
};
type ExecCommandData = {
command: string | string[];
instanceName?: string;
containerName?: string;
shell?: string;
user?: string | number;
group?: string | number;
};
type ExecCommandDataAddon = ExecCommandData & {
instanceName: string;
containerName?: string;
};
type ExecSessionData = Omit<ExecCommandData, 'command'> & {
command?: string | string[];
encoding?: string;
tty?: boolean;
ttyRows?: number;
ttyColumns?: number;
};
type CommandInfo = {
instanceName: string;
containerName: string;
};
declare class NorthflankExecCommand {
private readonly contextProvider;
private readonly agent?;
constructor(contextProvider: ApiClientContextProvider, agent?: any | undefined);
/**
* Runs command on a Northflank service and waits for completion returning command result and
* standard output and standard error emitted during commmand execution.
*/
execServiceCommand(parameters: {
projectId: string;
serviceId: string;
}, data: ExecCommandData): Promise<{
commandResult: CommandResult;
stdOut: string;
stdErr: string;
}>;
/**
* Starts a session on a Northflank service. This is usually a longer-running command. The returned object allows to listen to events as well
* as consume streams for standard output (stdOut) and standard error (stdErr). Input can be sent using the standard input (stdIn)
* writable stream.
*/
execServiceSession(parameters: {
projectId: string;
serviceId: string;
}, data?: ExecSessionData, commandInitCompletedCallback?: (commandInfo: CommandInfo) => void): Promise<ExecCommandStandard>;
/**
* Runs command on a Northflank job and waits for completion returning command result and
* standard output and standard error emitted during commmand execution.
*/
execJobCommand(parameters: {
projectId: string;
jobId: string;
}, data: ExecCommandData): Promise<{
commandResult: CommandResult;
stdOut: string;
stdErr: string;
}>;
/**
* Starts a session on a Northflank job. This is usually a longer-running command. The returned object allows to listen to events as well
* as consume streams for standard output (stdOut) and standard error (stdErr). Input can be sent using the standard input (stdIn)
* writable stream.
*/
execJobSession(parameters: {
projectId: string;
jobId: string;
}, data?: ExecSessionData, commandInitCompletedCallback?: (commandInfo: CommandInfo) => void): Promise<ExecCommandStandard>;
/**
* Runs command on a Northflank job and waits for completion returning command result and
* standard output and standard error emitted during commmand execution.
*/
execAddonCommand(parameters: {
projectId: string;
addonId: string;
}, data: ExecCommandDataAddon): Promise<{
commandResult: CommandResult;
stdOut: string;
stdErr: string;
}>;
/**
* Starts a session on a Northflank job. This is usually a longer-running command. The returned object allows to listen to events as well
* as consume streams for standard output (stdOut) and standard error (stdErr). Input can be sent using the standard input (stdIn)
* writable stream.
*/
execAddonSession(parameters: {
projectId: string;
addonId: string;
}, data?: ExecSessionData, commandInitCompletedCallback?: (commandInfo: CommandInfo) => void): Promise<ExecCommandStandard>;
private execCommand;
private shellSession;
private getCommandRunner;
private assertStartedWithNodejs;
}
declare enum CopyType {
DIRECTORY_UPLOAD = "directory-upload",
FILE_UPLOAD = "file-upload",
DIRECTORY_DOWNLOAD = "directory-download",
FILE_DOWNLOAD = "file-download"
}
type DownloadOptions = {
localPath: string;
remotePath?: string;
containerName?: string;
ignoreList?: string[];
};
type UploadOptions = {
localPath: string;
remotePath?: string;
containerName?: string;
ignoreList?: string[];
};
declare class NorthflankFileCopy {
private readonly exec;
private stdIgnoreList;
constructor(exec: NorthflankExecCommand, stdIgnoreListOverride?: string[]);
downloadServiceFiles(parameters: {
projectId: string;
serviceId: string;
}, options: DownloadOptions): Promise<{
type: CopyType;
sourceDirectory: string;
sourceFile?: string;
targetDirectory: string;
targetFile?: string;
}>;
downloadServiceFileStream(parameters: {
projectId: string;
serviceId: string;
}, options: {
remotePath: string;
containerName?: string;
}): Promise<{
fileStream: Stream.PassThrough;
completionPromise: Promise<boolean>;
}>;
uploadServiceFiles(parameters: {
projectId: string;
serviceId: string;
}, options: UploadOptions): Promise<{
type: CopyType;
sourceDirectory: string;
sourceFile?: string;
targetDirectory: string;
targetFile?: string;
}>;
uploadServiceFileStream(parameters: {
projectId: string;
serviceId: string;
}, options: {
source: string | Buffer | Stream;
remotePath: string;
containerName?: string;
}): Promise<void>;
downloadJobFiles(parameters: {
projectId: string;
jobId: string;
}, options: DownloadOptions): Promise<{
type: CopyType;
sourceDirectory: string;
sourceFile?: string;
targetDirectory: string;
targetFile?: string;
}>;
downloadJobFileStream(parameters: {
projectId: string;
jobId: string;
}, options: {
remotePath: string;
containerName?: string;
}): Promise<{
fileStream: Stream.PassThrough;
completionPromise: Promise<boolean>;
}>;
uploadJobFiles(parameters: {
projectId: string;
jobId: string;
}, options: UploadOptions): Promise<{
type: CopyType;
sourceDirectory: string;
sourceFile?: string;
targetDirectory: string;
targetFile?: string;
}>;
uploadJobFileStream(parameters: {
projectId: string;
jobId: string;
}, options: {
source: string | Buffer | Stream;
remotePath: string;
containerName?: string;
}): Promise<void>;
private copy;
}
declare enum LogType {
CDN = "cdn",
Mesh = "mesh",
Ingress = "ingress",
Runtime = "runtime"
}
type LogsRequestCommon = LogRequestTextFilters & {
lineLimit?: number;
startTime?: Date;
deploymentId?: string;
};
type JobLogsRangeRequestData = LogsRequestCommon & {
direction?: 'forward' | 'backward';
endTime?: Date;
duration?: number;
types?: LogType[];
containerName?: string | 'all';
runId?: undefined | string;
buildId?: never;
backupId?: never;
restoreId?: never;
isBuild?: false;
};
type AddonBackupLogsRangeRequestData = LogsRequestCommon & {
direction?: never;
endTime?: never;
duration?: never;
types?: never;
containerName?: never;
runId?: never;
buildId?: never;
backupId?: string;
restoreId?: never;
isBuild?: false;
};
type AddonRestoresLogsRangeRequestData = LogsRequestCommon & {
direction?: never;
endTime?: never;
duration?: never;
types?: never;
containerName?: never;
runId?: never;
buildId?: never;
backupId?: string;
restoreId?: string;
isBuild?: false;
};
type LogsRangeRequestData = JobLogsRangeRequestData & {
runId?: undefined;
};
type BuildLogsRangeRequestData = LogsRequestCommon & {
direction?: 'forward' | 'backward';
endTime?: Date;
duration?: number;
types?: never;
containerName?: never;
runId?: never;
buildId?: string;
backupId?: never;
restoreId?: never;
isBuild?: true;
};
type JobLogsTailRequestData = LogsRequestCommon & {
direction?: never;
endTime?: never;
duration?: never;
types?: LogType[];
containerName?: string | 'all';
runId?: undefined | string;
buildId?: never;
backupId?: never;
restoreId?: never;
isBuild?: false;
};
type AddonBackupLogsTailRequestData = LogsRequestCommon & {
direction?: never;
endTime?: never;
duration?: never;
types?: never;
containerName?: never;
runId?: never;
buildId?: never;
backupId?: string;
restoreId?: never;
isBuild?: false;
};
type AddonRestoresLogsTailRequestData = LogsRequestCommon & {
direction?: never;
endTime?: never;
duration?: never;
types?: never;
containerName?: never;
runId?: never;
buildId?: never;
backupId?: string;
restoreId?: string;
isBuild?: false;
};
type LogsTailRequestData = JobLogsTailRequestData & {
runId?: undefined;
};
type BuildLogsTailRequestData = LogsRequestCommon & {
direction?: never;
endTime?: never;
duration?: never;
types?: never;
containerName?: never;
runId?: never;
buildId?: string;
backupId?: never;
restoreId?: never;
isBuild?: true;
};
type LogsRequestDataTextIncl = {
textIncludes?: string;
textNotIncludes?: never;
regexIncludes?: never;
regexNotIncludes?: never;
};
type LogsRequestDataTextExcl = {
textIncludes?: never;
textNotIncludes?: string;
regexIncludes?: never;
regexNotIncludes?: never;
};
type LogsRequestDataRegexIncl = {
textIncludes?: never;
textNotIncludes?: never;
regexIncludes?: string;
regexNotIncludes?: never;
};
type LogsRequestDataRegexExcl = {
textIncludes?: never;
textNotIncludes?: never;
regexIncludes?: never;
regexNotIncludes?: string;
};
type LogRequestTextFilters = LogsRequestDataTextIncl | LogsRequestDataTextExcl | LogsRequestDataRegexIncl | LogsRequestDataRegexExcl;
type LogsConfigCommon = {
projectId: string;
entityType: 'service' | 'job' | 'addon' | 'build' | 'addonBackup' | 'addonRestore';
entityId: string;
};
type LogsRangeConfig = LogsConfigCommon & {
queryType: 'range';
} & (LogsRangeRequestData | BuildLogsRangeRequestData | JobLogsRangeRequestData | AddonBackupLogsRangeRequestData | AddonRestoresLogsRangeRequestData);
type LogsTailConfig = LogsConfigCommon & {
queryType: 'tail';
} & (LogsTailRequestData | BuildLogsTailRequestData | JobLogsTailRequestData | AddonBackupLogsTailRequestData | AddonRestoresLogsTailRequestData);
type LogLine = {
containerId: string;
log: any;
ts: Date;
};
interface LogsClient extends EventEmitter {
on(event: 'logs-received', listener: (logLines: LogLine[]) => any): any;
on(event: 'error', listener: (error: any) => any): any;
on(event: 'open', listener: () => any): any;
on(event: 'close', listener: () => any): any;
}
declare class LogsClient extends EventEmitter {
private readonly baseUrl;
readonly logsConfig: LogsTailConfig;
private readonly token;
private readonly agent?;
private remote;
private logSession;
constructor(baseUrl: string, logsConfig: LogsTailConfig, token: string, // readonly timeout: number = 120 // Timeout in seconds
agent?: any | undefined);
static getLogsEndpoint(config: LogsTailConfig | LogsRangeConfig): string;
private get logsEndpoint();
stop: () => Promise<any>;
start(): Promise<void>;
private initialAuth;
private reset;
}
type ApiCallLogRangeResponse = ApiCallResponse<LogLine[]>;
type GetServiceLogsCall = (opts: {
parameters: {
projectId: string;
serviceId: string;
};
options?: LogsRangeRequestData;
}) => Promise<ApiCallLogRangeResponse>;
type TailServiceLogsCall = (opts: {
parameters: {
projectId: string;
serviceId: string;
};
options?: LogsTailRequestData;
}) => Promise<LogsClient>;
type GetServiceBuildlogsCall = (opts: {
parameters: {
projectId: string;
serviceId: string;
};
options?: BuildLogsRangeRequestData;
}) => Promise<ApiCallLogRangeResponse>;
type TailServiceBuildlogsCall = (opts: {
parameters: {
projectId: string;
serviceId: string;
};
options?: BuildLogsTailRequestData;
}) => Promise<LogsClient>;
type GetJobLogsCall = (opts: {
parameters: {
projectId: string;
jobId: string;
};
options?: JobLogsRangeRequestData;
}) => Promise<ApiCallLogRangeResponse>;
type TailJobLogsCall = (opts: {
parameters: {
projectId: string;
jobId: string;
};
options?: JobLogsTailRequestData;
}) => Promise<LogsClient>;
type GetJobBuildlogsCall = (opts: {
parameters: {
projectId: string;
jobId: string;
};
options?: BuildLogsRangeRequestData;
}) => Promise<ApiCallLogRangeResponse>;
type TailJobBuildlogsCall = (opts: {
parameters: {
projectId: string;
jobId: string;
};
options?: BuildLogsTailRequestData;
}) => Promise<LogsClient>;
type GetAddonLogsCall = (opts: {
parameters: {
projectId: string;
addonId: string;
};
options?: LogsRangeRequestData;
}) => Promise<ApiCallLogRangeResponse>;
type TailAddonLogsCall = (opts: {
parameters: {
projectId: string;
addonId: string;
};
options?: LogsTailRequestData;
}) => Promise<LogsClient>;
type GetAddonBackupLogsCall = (opts: {
parameters: {
projectId: string;
addonId: string;
backupId: string;
};
options?: LogsRangeRequestData;
}) => Promise<ApiCallLogRangeResponse>;
type TailAddonBackupLogsCall = (opts: {
parameters: {
projectId: string;
addonId: string;
backupId: string;
};
options?: LogsTailRequestData;
}) => Promise<LogsClient>;
type GetAddonRestoresLogsCall = (opts: {
parameters: {
projectId: string;
addonId: string;
backupId: string;
restoreId: string;
};
options?: LogsRangeRequestData;
}) => Promise<ApiCallLogRangeResponse>;
type TailAddonRestoresLogsCall = (opts: {
parameters: {
projectId: string;
addonId: string;
backupId: string;
restoreId: string;
};
options?: LogsTailRequestData;
}) => Promise<LogsClient>;
declare class NorthflankLogFetch {
private readonly contextProvider;
private readonly clientOpts;
constructor(contextProvider: ApiClientContextProvider, clientOpts?: ApiClientOpts);
/** Fetches service container logs over a specific time span applying optional filters. */
getServiceLogs: (opts: {
parameters: {
projectId: string;
serviceId: string;
};
options?: LogsRangeRequestData;
}) => Promise<ApiCallLogRangeResponse>;
/** Fetches service build container logs over a specific time span applying optional filters. */
getServiceBuildLogs: (opts: {
parameters: {
projectId: string;
serviceId: string;
};
options?: BuildLogsTailRequestData;
}) => Promise<ApiCallLogRangeResponse>;
/** Fetches job container logs over a specific time span applying optional filters. */
getJobLogs: (opts: {
parameters: {
projectId: string;
jobId: string;
};
options?: JobLogsRangeRequestData;
}) => Promise<ApiCallLogRangeResponse>;
/** Fetches job build container logs over a specific time span applying optional filters. */
getJobBuildLogs: (opts: {
parameters: {
projectId: string;
jobId: string;
};
options?: BuildLogsRangeRequestData;
}) => Promise<ApiCallLogRangeResponse>;
/** Fetches addon container logs over a specific time span applying optional filters. */
getAddonLogs: (opts: {
parameters: {
projectId: string;
addonId: string;
};
options?: LogsRangeRequestData;
}) => Promise<ApiCallLogRangeResponse>;
/** Fetches addon backup logs */
getAddonBackupLogs: (opts: {
parameters: {
projectId: string;
addonId: string;
backupId: string;
};
options?: Omit<AddonBackupLogsRangeRequestData, "backupId">;
}) => Promise<ApiCallLogRangeResponse>;
/** Fetches addon restore logs */
getAddonRestoresLogs: (opts: {
parameters: {
projectId: string;
addonId: string;
backupId: string;
restoreId: string;
};
options?: Omit<AddonRestoresLogsRangeRequestData, "backupId" | "restoreId">;
}) => Promise<ApiCallLogRangeResponse>;
logRange: (parameters: {
projectId: string;
entityId: string;
}, data: LogsRangeRequestData | BuildLogsRangeRequestData | JobLogsRangeRequestData | AddonBackupLogsRangeRequestData | AddonRestoresLogsRangeRequestData, entityType: LogsConfigCommon["entityType"]) => Promise<ApiCallLogRangeResponse>;
tailServiceLogs: (opts: {
parameters: {
projectId: string;
serviceId: string;
};
options?: LogsTailRequestData;
}) => Promise<LogsClient>;
/** Starts a log tail on a service build container. */
tailServiceBuildLogs: (opts: {
parameters: {
projectId: string;
serviceId: string;
};
options?: BuildLogsTailRequestData;
}) => Promise<LogsClient>;
/** Starts a log tail on a job container. */
tailJobLogs: (opts: {
parameters: {
projectId: string;
jobId: string;
};
options?: JobLogsTailRequestData;
}) => Promise<LogsClient>;
/** Starts a log tail on a job build container. */
tailJobBuildLogs: (opts: {
parameters: {
projectId: string;
jobId: string;
};
options?: BuildLogsTailRequestData;
}) => Promise<LogsClient>;
/** Starts a log tail on an addon container. */
tailAddonLogs: (opts: {
parameters: {
projectId: string;
addonId: string;
};
options?: LogsTailRequestData;
}) => Promise<LogsClient>;
/** Starts a log tail on an addon backup. */
tailAddonBackupLogs: (opts: {
parameters: {
projectId: string;
addonId: string;
backupId: string;
};
options?: Omit<AddonBackupLogsTailRequestData, "backupId">;
}) => Promise<LogsClient>;
/** Starts a log tail on an addon restore. */
tailAddonRestoresLogs: (opts: {
parameters: {
projectId: string;
addonId: string;
backupId: string;
restoreId: string;
};
options?: Omit<AddonRestoresLogsTailRequestData, "backupId" | "restoreId">;
}) => Promise<LogsClient>;
/** Starts a log tail. */
logTail: (parameters: {
projectId: string;
entityId: string;
}, data: LogsTailRequestData | BuildLogsTailRequestData | JobLogsTailRequestData | AddonBackupLogsTailRequestData | AddonRestoresLogsTailRequestData, entityType: LogsConfigCommon["entityType"]) => Promise<LogsClient>;
private assertStartedWithNodejs;
}
type ApiCallMetricsResponse = ApiCallResponse<Record<MetricType, MetricsEntry>>;
declare enum MetricType {
Cpu = "cpu",
Memory = "memory",
NetworkIngress = "networkIngress",
NetworkEgress = "networkEgress",
TcpConnectionOpen = "tcpConnectionsOpen",
PvcUsage = "diskUsage",
Requests = "requests",
Http4xxResponses = "http4xxResponses",
Http5xxResponses = "http5xxResponses",
Bandwidth = "bandwidth",
BandwidthVolume = "bandwidthVolume"
}
type MetricUnit = 'pct' | 'vCPU' | 'mb' | 'kbps' | 'rps' | 'count';
type MetricValue = {
metadata: {
containerId: string;
volumeId?: string;
};
data: {
value: string | number;
ts: Date;
}[];
};
type MetricsEntry = {
metricInfo: {
metricId: MetricType;
metricUnit: MetricUnit;
metricResolution?: number;
};
values: MetricValue[];
};
type MetricsRequestCommon = {
metricTypes?: MetricType[];
deploymentId?: string;
};
type JobMetricsRangeRequestData = MetricsRequestCommon & {
startTime?: Date;
endTime?: Date;
timestamp?: never;
duration?: number;
containerName?: string | 'all';
runId?: undefined | string;
buildId?: never;
isBuild?: false;
};
type MetricsRangeRequestData = JobMetricsRangeRequestData & {
runId?: undefined;
};
type MetricsRangeBuildRequestData = MetricsRequestCommon & {
startTime?: Date;
endTime?: Date;
timestamp?: never;
duration?: number;
containerName?: never;
runId?: never;
buildId?: string;
isBuild?: true;
};
type JobMetricsSingleRequestData = MetricsRequestCommon & {
timestamp?: Date;
startTime?: never;
endTime?: never;
duration?: never;
containerName?: string | 'all';
runId?: undefined | string;
buildId?: never;
isBuild?: false;
};
type MetricsSingleRequestData = JobMetricsSingleRequestData & {
runId?: undefined;
};
type MetricsSingleBuildRequestData = MetricsRequestCommon & {
timestamp?: Date;
startTime?: never;
endTime?: never;
duration?: never;
containerName?: never;
runId?: never;
buildId?: string;
isBuild?: true;
};
type GetServiceMetricsCall = (opts: {
parameters: {
projectId: string;
serviceId: string;
};
options?: MetricsSingleRequestData;
}) => Promise<ApiCallMetricsResponse>;
type GetServiceMetricsRangeCall = (opts: {
parameters: {
projectId: string;
serviceId: string;
};
options?: MetricsRangeRequestData;
}) => Promise<ApiCallMetricsResponse>;
type GetServiceBuildMetricsCall = (opts: {
parameters: {
projectId: string;
serviceId: string;
};
options?: MetricsSingleBuildRequestData;
}) => Promise<ApiCallMetricsResponse>;
type GetServiceBuildMetricsRangeCall = (opts: {
parameters: {
projectId: string;
serviceId: string;
};
options?: MetricsRangeBuildRequestData;
}) => Promise<ApiCallMetricsResponse>;
type GetJobMetricsCall = (opts: {
parameters: {
projectId: string;
jobId: string;
};
options?: JobMetricsSingleRequestData;
}) => Promise<ApiCallMetricsResponse>;
type GetJobMetricsRangeCall = (opts: {
parameters: {
projectId: string;
jobId: string;
};
options?: JobMetricsRangeRequestData;
}) => Promise<ApiCallMetricsResponse>;
type GetJobBuildMetricsCall = (opts: {
parameters: {
projectId: string;
jobId: string;
};
options?: MetricsSingleBuildRequestData;
}) => Promise<ApiCallMetricsResponse>;
type GetJobBuildMetricsRangeCall = (opts: {
parameters: {
projectId: string;
jobId: string;
};
options?: MetricsRangeBuildRequestData;
}) => Promise<ApiCallMetricsResponse>;
type GetAddonMetricsCall = (opts: {
parameters: {
projectId: string;
addonId: string;
};
options?: MetricsSingleRequestData;
}) => Promise<ApiCallMetricsResponse>;
type GetAddonMetricsRangeCall = (opts: {
parameters: {
projectId: string;
addonId: string;
};
options?: MetricsRangeRequestData;
}) => Promise<ApiCallMetricsResponse>;
declare class NorthflankMetricFetch {
private readonly contextProvider;
constructor(contextProvider: ApiClientContextProvider);
/** Fetches service container metrics over a specific time span applying optional filters. */
getServiceMetrics: (opts: {
parameters: {
projectId: string;
serviceId: string;
};
options?: MetricsSingleRequestData;
}) => Promise<ApiCallMetricsResponse>;
/** Fetches service build container metrics over a specific time span applying optional filters. */
getServiceBuildMetrics: (opts: {
parameters: {
projectId: string;
serviceId: string;
};
options?: MetricsSingleBuildRequestData;
}) => Promise<ApiCallMetricsResponse>;
/** Fetches job container metrics over a specific time span applying optional filters. */
getJobMetrics: (opts: {
parameters: {
projectId: string;
jobId: string;
};
options?: JobMetricsSingleRequestData;
}) => Promise<ApiCallMetricsResponse>;
/** Fetches job build container metrics over a specific time span applying optional filters. */
getJobBuildMetrics: (opts: {
parameters: {
projectId: string;
jobId: string;
};
options?: MetricsSingleBuildRequestData;
}) => Promise<ApiCallMetricsResponse>;
/** Fetches addon container metrics over a specific time span applying optional filters. */
getAddonMetrics: (opts: {
parameters: {
projectId: string;
addonId: string;
};
options?: MetricsSingleRequestData;
}) => Promise<ApiCallMetricsResponse>;
metricsSingle: (parameters: {
projectId: string;
entityId: string;
}, data: MetricsSingleRequestData | MetricsSingleBuildRequestData | JobMetricsSingleRequestData, entityType: "service" | "job" | "addon") => Promise<ApiCallMetricsResponse>;
getServiceMetricsRange: (opts: {
parameters: {
projectId: string;
serviceId: string;
};
options?: MetricsRangeRequestData;
}) => Promise<ApiCallMetricsResponse>;
/** Get metrics range for a service build container. */
getServiceBuildMetricsRange: (opts: {
parameters: {
projectId: string;
serviceId: string;
};
options?: MetricsRangeBuildRequestData;
}) => Promise<ApiCallMetricsResponse>;
/** Get metrics range for a job container. */
getJobMetricsRange: (opts: {
parameters: {
projectId: string;
jobId: string;
};
options?: JobMetricsRangeRequestData;
}) => Promise<ApiCallMetricsResponse>;
/** Get metrics range for a job build container. */
getJobBuildMetricsRange: (opts: {
parameters: {
projectId: string;
jobId: string;
};
options?: MetricsRangeBuildRequestData;
}) => Promise<ApiCallMetricsResponse>;
/** Get metrics range for an addon container. */
getAddonMetricsRange: (opts: {
parameters: {
projectId: string;
addonId: string;
};
options?: MetricsRangeRequestData;
}) => Promise<ApiCallMetricsResponse>;
/** Fetches a series of metrics over a timerange. */
metricsRange: (parameters: {
projectId: string;
entityId: string;
}, data: MetricsRangeRequestData | MetricsRangeBuildRequestData | JobMetricsRangeRequestData, entityType: "service" | "job" | "addon") => Promise<ApiCallMetricsResponse>;
private getMetrics;
}
type GetAddonTypesResult = {
/** A list of available addon types. */
'addonTypes': {
/** The identifier for the addon type. Example: "redis" */
'type': string;
/** The name of the addon type. Example: "Redis" */
'name': string;
/** A description of the addon. Example: "Redis implements a distributed, in-memory key-value database with optional durability." */
'description': string;
/** Features supported by this addon type. */
'features'?: {
/** Whether this addon supports native (dump) backups */
'backupsDump': boolean;
/** Whether this addon supports customising the database name. */
'customDBName': boolean;
/** Whether this addon supports addon forking - creating a new addon from an existing addon backup. */
'forkAddon': boolean;
/** Whether this addon supports importing from an external backup. */
'importDump': boolean;
/** Whether this addon supports importing from an existing live database. */
'importLive': boolean;
/** Whether this addon supports replica scaling. */
'scaleReplicas': boolean;
/** Whether this addon supports connection via TLS. Example: true */
'tls': boolean;
/** Whether this addon supports external connection. Example: true */
'externalAccess': boolean;
};
/** A list of available versions of the addon type. */
'versions': string[];
/** A list of available major versions of the addon type. */
'major': string[];
/** Details about resource options for the addon type. */
'resources': {
/** Details about storage size options for this addon. */
'storage': {
/** Available options for storage size for this addon, in MB. */
'options': number[];
/** The default storage value for this addon. Example: 1024 */
'default': number;
};
/** Details about replica count options for this addon. */
'replicas': {
/** Available options for replica counts for this addon. */
'options': number[];
/** The default replica count for this addon. Example: 1 */
'default': number;
};
};
}[] | {
/** The identifier for the addon type. Example: "redis" */
'type': string;
/** The name of the addon type. Example: "Redis" */
'name': string;
/** A description of the addon. Example: "Redis implements a distributed, in-memory key-value database with optional durability." */
'description': string;
/** Features supported by this addon type. */
'features'?: {
/** Whether this addon supports native (dump) backups */
'backupsDump': boolean;
/** Whether this addon supports customising the database name. */
'customDBName': boolean;
/** Whether this addon supports addon forking - creating a new addon from an existing addon backup. */
'forkAddon': boolean;
/** Whether this addon supports importing from an external backup. */
'importDump': boolean;
/** Whether this addon supports importing from an existing live database. */
'importLive': boolean;
/** Whether this addon supports replica scaling. */
'scaleReplicas': boolean;
/** Whether this addon supports connection via TLS. Example: true */
'tls': boolean;
/** Whether this addon supports external connection. Example: true */
'externalAccess': boolean;
};
'config': {
/** Allow addon user to view values provided to templating engine. */
'showTemplateValues'?: boolean;
/** Allow addon user to edit values provided to templating engine. */
'enableTemplateValuesModification'?: boolean;
/** Allow addon user to view and resolve potential errors occuring with templating engine run. */
'enableErrorRecovery'?: boolean;
/** Install CRDs provided in resource bundle. */
'installCrds'?: boolean;
/** Apply Northflank secret injection instead of using Kubernetes secrets. */
'useNfSecretInjection'?: boolean;
/** Inject Northflank-specific Kubernetes imagePullSecret to Pod resources. */
'useNfImagePullSecret'?: boolean;
};
/** If the addon deploys any k8s resources which are not namespace/project-scoped, it's a cluster scoped addon */
'scope': 'project' | 'cluster';
}[];
};
type GetAddonTypesCall = (opts: GetAddonTypesRequest) => Promise<ApiCallResponse<GetAddonTypesResult>>;
type GetAddonTypesRequest = {};
/** Gets information about the available addon types */
declare class GetAddonTypesEndpoint extends GetApiEndpoint<GetAddonTypesRequest, GetAddonTypesResult> {
description: string;
withAuth: boolean;
requiredPermissions: string;
endpointUrl: (opts: GetAddonTypesRequest) => string;
body: () => undefined;
}
type ListBackupdestinationsResult = {
/** List of backup destinations. */
'backupDestinations': {
/** The name of the backup destination. Example: "Example Backup Destination" */
'name': string;
'description'?: string;
/** Type of the backup destination. */
'type': 's3';
/** A prefix path to add to the bucket objects if not writing to / */
'prefix': string;
/** Credentials used for the backup destination. */
'credentials': {
'accessKey': string;
'secretKey': string;
'bucketName': string;
'region': string;
/** S3 destination including region, fe s3.us-west-2.amazonaws.com */
'endpoint': string;
};
}[];
};
type ListBackupdestinationsCall = ((opts: ListBackupdestinationsRequest) => Promise<ApiCallResponse<List