@ztimson/momentum
Version:
Client library for momentum
95 lines • 2.86 kB
TypeScript
import { Api } from './api';
import { Cache, HttpRequestOptions, PathEventEmitter } from '@ztimson/utils';
import { Meta } from './core';
/** Action model */
export type Action = Meta & {
/** Action name */
name: string;
/** Trigger with CRON, CRUD or Event */
trigger: {
type: ActionType;
value: string;
};
/** Run as system or with triggering user permissions */
system?: boolean;
/** Action code */
fn: string;
/** User nodes */
notes?: string;
/** Last execution timestamp */
lastRun?: Date;
/** Last execution duration */
lastRunLength?: number;
/** Next scheduled run time (CRON only) */
nextRun?: Date;
/** Last execution results */
response?: ActionResult;
};
/** Action execution result */
export type ActionResult = {
/** ID of associated action */
action: string;
/** Console output */
stdout: any[];
/** Console errors */
stderr: any[];
/** HTTP Response */
response?: any;
/** Action return value */
return?: any;
};
export declare enum ActionType {
'CRON' = 0,
'EVENT' = 1,
'DELETE' = 2,
'GET' = 3,
'PATCH' = 4,
'POST' = 5,
'PUT' = 6
}
/** Execute custom Javascript on trigger event */
export declare class Actions extends PathEventEmitter {
private readonly api;
cache: Cache<string, Action>;
constructor(api: Api | string);
/**
* All saved actions
* @param {boolean} reload Will use cached response if false
* @return {Promise<Action[]>} List of saved actions
*/
all(reload?: boolean): Promise<Action[]>;
/**
* Manually trigger an actions execution
* @param {string} id Action ID
* @param {HttpRequestOptions} opts Additional arguments
* @return {Promise<ActionResult>} All action output including console logs & return
*/
debug(id: string, opts?: HttpRequestOptions): Promise<ActionResult>;
/**
* Delete an existing action
* @param {string} id Action ID
* @return {Promise<void>} Delete complete
*/
delete(id: string): Promise<void>;
/**
* Fetch action info
* @param {string} id Action ID
* @param {boolean} reload Will use cached response if false
* @return {Promise<Action | null>} Requested action
*/
read(id: string, reload?: boolean): Promise<Action | null>;
/**
* Run an HTTP action
* @param {string} path HTTP path excluding `/api/actions/run`
* @param {HttpRequestOptions} opts HTTP options
* @return {Promise<T>} HTTP response
*/
run<T>(path: string, opts?: HttpRequestOptions): Promise<T>;
/**
* Update an action
* @param {Action} action The new action
* @return {Promise<Action>} Saved action
*/
update(action: Action): Promise<Action>;
}
//# sourceMappingURL=actions.d.ts.map