liveperson-functions-cli
Version:
LivePerson Functions CLI
202 lines (201 loc) • 7.78 kB
TypeScript
import { Got } from 'got';
import { LoginController } from '../controller/login.controller';
import { ILambda, IRuntime, ISchedule, IDomain } from '../types';
import { IScheduleConfig } from '../controller/create.controller';
import { CsdsClient } from './csds.service';
export declare type HttpMethods = 'POST' | 'GET' | 'DELETE' | 'PUT';
export interface IPayload {
headers: string[];
payload: any;
}
export interface IInvokeResponse {
result: any;
logs: {
level: string;
message: any;
extras: any[];
timestamp: number;
}[];
}
export interface IDeploymentResponse {
/**
* Deployment message from the LivePerson functions platform
* @type {string}
* @memberof IDeploymentResponse
*/
message: string;
/**
* UUID of the lambda that was deployed (optional)
* @type {string}
* @memberof IDeploymentResponse
*/
uuid?: string;
}
export interface IFaaSService {
/**
* Runs the initial setup for the faas service.
* Checks if a valid temp file is available and will use this for authentication.
* If not, the user will have to enter his accountId, username and password.
* Have to be called before all other functions.
* @returns {Promise<FaasService>}
* @memberof IFaaSService
*/
setup(): Promise<FaasService>;
/**
* Undeploys a function on the LivePerson functions platform. Setup before is necessary.
* The correct LivePerson url will be fetched by the accountId.
* @param {string} uuid - lambda uuid
* @returns {Promise<IDeploymentResponse>}
* @memberof IFaaSService
*/
undeploy(uuid: string): Promise<IDeploymentResponse>;
/**
* Deploys a function on the LivePerson functions platform. Setup before is necessary.
* The correct LivePerson url will be fetched by the accountId.
* @param {string} uuid - lambda uuid
* @returns {Promise<IDeploymentResponse>}
* @memberof IFaaSService
*/
deploy(uuid: string): Promise<IDeploymentResponse>;
/**
* Gather all information from the LivePerson functions platform by lambda names. Setup before is necessary.
* The correct LivePerson url will be fetched by the accountId.
* @param {string[]} lambdaNames - lambda names which should be collected
* @returns {Promise<ILambda[]>}
* @memberof IFaaSService
*/
getLambdasByNames(lambdaNames: string[]): Promise<(ILambda | {
name: string;
})[]>;
/**
* Gather all information from the LivePerson functions platform. Setup before is necessary.
* The correct LivePerson url will be fetched by the accountId.
* @returns {Promise<ILambda[]>}
* @memberof IFaaSService
*/
getAllLambdas(): Promise<ILambda[]>;
/**
* Gather the information from one lambda by uuid. Setup before is necessary.
* The correct LivePerson url will be fetched by the accountId.
* @param {string} uuid - lambda uuid
* @returns {Promise<ILambda>}
* @memberof IFaaSService
*/
getLambdaByUUID(uuid: string): Promise<ILambda>;
/**
* Push a local lambda to the LP-Functions platform. Either creates
* a new lambda or overwrites an existing one.
* @param {Object} input - Object containing all the other inputs
* @param {HttpMethods} input.method - The HTTP Method that will be used for the push request.
* @param {ILambda} input.body - The HTTP body that will be used for the push request.
* @param {string} input.uuid - Uuid that identifies a lambda to overwrite on the LP-Functions platform.
* Only needed if the function already exists.
* @returns {Promise<void>}
* @memberof IFaaSService
*/
push(input: {
method: HttpMethods;
body: ILambda;
uuid?: string;
}): void;
/**
* Return the current runtime of the LivePerson functions platform
* The correct LivePerson url will be fetched by the accountId.
* @returns {Promise<IRuntime>}
* @memberof IFaaSService
*/
getRuntime(): Promise<IRuntime>;
/**
* Invokes a function on the LivePerson functions platform with a provided payload
* The correct LivePerson url will be fetched by the accountId.
* @param {string} uuid
* @param {IPayload} payload
* @returns {Promise<IInvokeResponse>}
* @memberof IFaaSService
*/
invoke(uuid: string, payload: IPayload): Promise<IInvokeResponse>;
/**
* Creates a schedule in an account based on a cron expression and the lambda uuid. Every function can only be scheduled once and must be deployed.
* @param uuid uuid of lambda for which a schedule will be created
* @param cronExpression string which is in the cron expression format
*/
createSchedule(schedule: {
uuid: string;
cronExpression: string;
}): Promise<ISchedule>;
/**
* Creates a schedule in an account based on a cron expression and the lambda uuid. Every function can only be scheduled once and must be deployed.
* @param uuid uuid of lambda for which a schedule will be created
* @param cronExpression string which is in the cron expression format
*/
addDomain(domain: string): Promise<IDomain>;
/**
* Get logs from the LivePerson functions platform by lambda names. Setup before is necessary.
* The correct LivePerson url will be fetched by the accountId.
* @param {string} uuid uuid of lambda for which logs should be fetched
* @param {number} start start timestamp for logs
* @param {number} end end timestamp for logs
* @param {string[]} levels which is in the cron expression format
* @returns {Promise<void>}
* @memberof IFaaSService
*/
getLogs(options: {
uuid: string;
start?: string;
end?: string;
levels?: string[];
removeHeader?: boolean;
}): Promise<void>;
}
interface IFaasServiceConfig {
username?: string;
loginController?: LoginController;
csdsClient?: CsdsClient;
gotDefault?: Got;
}
export declare class FaasService implements IFaaSService {
username: string;
accountId: string | undefined;
userId: string | undefined;
token: string | undefined;
private readonly loginController;
private readonly csdsClient;
private readonly got;
constructor({ username, loginController, csdsClient, gotDefault, }?: IFaasServiceConfig);
undeploy(uuid: string): Promise<IDeploymentResponse>;
deploy(uuid: string): Promise<IDeploymentResponse>;
getLambdasByNames(lambdaNames: string[], collectNonExistingLambas?: boolean): Promise<(ILambda | {
name: string;
})[]>;
getRuntime(): Promise<IRuntime>;
getAllLambdas(): Promise<ILambda[]>;
createSchedule(schedule: IScheduleConfig): Promise<ISchedule>;
addDomain(domain: string): Promise<IDomain>;
getLambdaInvocationMetrics({ uuid, startTimestamp, endTimestamp, bucketSize, }: {
uuid: string;
startTimestamp: number;
endTimestamp: number;
bucketSize: any;
}): Promise<any>;
getAccountStatistic(): Promise<any>;
push({ method, body, uuid, }: {
method: HttpMethods;
body: ILambda;
uuid?: string;
}): Promise<boolean>;
getLambdaByUUID(uuid: string): Promise<ILambda>;
invoke(uuid: string, payload: IPayload): Promise<IInvokeResponse>;
getEvents(): Promise<any[]>;
getLogs({ uuid, start, end, levels, removeHeader, }: {
uuid: string;
start?: string;
end?: string;
levels?: string[];
removeHeader?: boolean;
}): Promise<void>;
setup(): Promise<FaasService>;
private getCsdsEntry;
private getStream;
private doFetch;
}
export {};