@twilio-labs/serverless-api
Version:
API-wrapper for the Twilio Serverless API
122 lines (121 loc) • 6 kB
TypeScript
/** @module @twilio-labs/serverless-api */
/// <reference types="node" />
import events from 'events';
import { HTTPAlias, OptionsOfJSONResponseBody, OptionsOfTextResponseBody, Response } from 'got/dist/source';
import { LogsStream } from './streams/logs';
import { ActivateConfig, ActivateResult, ClientConfig, DeployLocalProjectConfig, DeployProjectConfig, DeployResult, GotClient, ListConfig, ListResult, LogApiResource, LogsConfig } from './types';
import { GetEnvironmentVariablesConfig, GetEnvironmentVariablesResult, RemoveEnvironmentVariablesConfig, RemoveEnvironmentVariablesResult, SetEnvironmentVariablesConfig, SetEnvironmentVariablesResult } from './types/env';
export declare function createGotClient(config: ClientConfig): GotClient;
export declare class TwilioServerlessApiClient extends events.EventEmitter {
/**
* Contains the client config used to do API requests
*
* @private
* @type {ClientConfig}
* @memberof TwilioServerlessApiClient
*/
private config;
/**
* The `got` client that is used to make all the API requests
*
* @private
* @type {GotClient}
* @memberof TwilioServerlessApiClient
*/
private client;
/**
*
* @private
* @type {Limit}
* @memberof TwilioServerlessApiClient
*/
private limit;
constructor(config: ClientConfig);
/**
* Returns the internally used GotClient instance used to make API requests
* @returns {GotClient} A client instance with set-up credentials
*/
getClient(): GotClient;
/**
* Sets a set of environment variables for a given Twilio Serverless environment
* If append is false it will remove all existing environment variables.
*
* @param {SetEnvironmentVariablesConfig} config
* @returns {Promise<SetEnvironmentVariablesResult>}
* @memberof TwilioServerlessApiClient
*/
setEnvironmentVariables(config: SetEnvironmentVariablesConfig): Promise<SetEnvironmentVariablesResult>;
/**
* Retrieves a list of environment variables for a given Twilio Serverless environment.
* If config.getValues is false (default) the values will be all set to undefined.
*
* @param {GetEnvironmentVariablesConfig} config
* @returns {Promise<GetEnvironmentVariablesResult>}
* @memberof TwilioServerlessApiClient
*/
getEnvironmentVariables(config: GetEnvironmentVariablesConfig): Promise<GetEnvironmentVariablesResult>;
/**
* Deletes a list of environment variables (by key) for a given Twilio Serverless environment.
*
* @param {RemoveEnvironmentVariablesConfig} config
* @returns {Promise<RemoveEnvironmentVariablesResult>}
* @memberof TwilioServerlessApiClient
*/
removeEnvironmentVariables(config: RemoveEnvironmentVariablesConfig): Promise<RemoveEnvironmentVariablesResult>;
/**
* Returns an object containing lists of services, environments, variables
* functions or assets, depending on which have beeen requested in `listConfig`
* @param {ListConfig} listConfig Specifies info around which things should be listed
* @returns Promise<ListResult> Object containing the different lists.
*/
list(listConfig: ListConfig): Promise<ListResult>;
getLogsStream(logsConfig: LogsConfig): Promise<LogsStream>;
getLogs(logsConfig: LogsConfig): Promise<LogApiResource[]>;
/**
* "Activates" a build by taking a specified build SID or a "source environment"
* and activating the same build in the specified `environment`.
*
* Can optionally create the new environment when called with `activateConfig.createEnvironment`
* @param {ActivateConfig} activateConfig Config to specify which build to activate in which environment
* @returns Promise<ActivateResult> Object containing meta information around deployment
*/
activateBuild(activateConfig: ActivateConfig): Promise<ActivateResult>;
/**
* Deploys a set of functions, assets, variables and dependencies specified
* in `deployConfig`. Functions & assets can either be paths to the local
* filesystem or `Buffer` instances allowing you to dynamically upload
* even without a file system.
*
* Unless a `deployConfig. serviceSid` is specified, it will try to create one. If a service
* with the name `deployConfig.serviceName` already exists, it will throw
* an error. You can make it use the existing service by setting `overrideExistingService` to
* true.
*
* Updates to the deployment will be emitted as events to `status-update`. Example:
*
* ```js
* client.on('status-update', ({ status, message }) => {
* console.log('[%s]: %s', status, message);
* })
* ```
* @param {DeployProjectConfig} deployConfig Config containing all details for deployment
* @returns Promise<DeployResult> Object containing meta information around deployment
*/
deployProject(deployConfig: DeployProjectConfig): Promise<DeployResult>;
/**
* Deploys a local project by reading existing functions and assets
* from `deployConfig.cwd` and calling `this.deployProject` with it.
*
* Functions have to be placed in a `functions` or `src` directory to be found.
* Assets have to be placed into an `assets` or `static` directory.
*
* Nested folder structures will result in nested routes.
* @param {DeployLocalProjectConfig} deployConfig
* @returns Promise<DeployResult> Object containing meta information around deployment
*/
deployLocalProject(deployConfig: DeployLocalProjectConfig): Promise<DeployResult>;
request(method: HTTPAlias, path: string): Promise<Response<unknown>>;
request(method: HTTPAlias, path: string, options: OptionsOfJSONResponseBody): Promise<Response<unknown>>;
request(method: HTTPAlias, path: string, options: OptionsOfTextResponseBody): Promise<Response<string>>;
}
export default TwilioServerlessApiClient;