How to use @twilio-labs/serverless-api - 7 common examples

To help you get started, we’ve selected a few @twilio-labs/serverless-api examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github twilio-labs / twilio-run / src / commands / deploy.ts View on Github external
if (!config) {
    logError('Internal Error');
    process.exit(1);
    return;
  }

  debug('Deploy Config %P', config);

  checkConfigForCredentials(config);

  printConfigInfo(config);

  const spinner = getOraSpinner('Deploying Function').start();
  try {
    const client = new TwilioServerlessApiClient(config);
    client.on('status-update', evt => {
      spinner.text = evt.message + '\n';
    });
    const result = await client.deployLocalProject(config);
    spinner.text = 'Serverless project successfully deployed\n';
    spinner.succeed();
    printDeployedResources(config, result);
    const { serviceSid, buildSid } = result;
    await saveLatestDeploymentData(
      config.cwd,
      serviceSid,
      buildSid,
      config.accountSid.startsWith('AC')
        ? config.accountSid
        : externalCliOptions && externalCliOptions.accountSid
    );
github twilio-labs / twilio-run / src / commands / activate.ts View on Github external
process.exit(1);
    return;
  }

  checkConfigForCredentials(config);

  printActivateConfig(config);

  const details = config.buildSid
    ? `(${config.buildSid})`
    : `from ${config.sourceEnvironment}`;
  const spinner = getOraSpinner(
    `Activating build ${details} to ${config.targetEnvironment || 'production'}`
  ).start();
  try {
    const client = new TwilioServerlessApiClient(config);
    const result = await client.activateBuild(config);
    spinner.succeed(
      `Activated new build ${details} on ${config.targetEnvironment ||
        'production'}`
    );
    printActivateResult(result);
  } catch (err) {
    handleError(err, spinner);
  }
}
github twilio-labs / twilio-run / src / commands / list.ts View on Github external
if (!config) {
    logError('Internal Error');
    process.exit(1);
    return;
  }

  checkConfigForCredentials(config);

  if (config.types !== 'services' && config.types[0] !== 'services') {
    const command = getFullCommand(flags);
    checkForValidServiceSid(command, config.serviceSid);
  }

  try {
    const client = new TwilioServerlessApiClient(config);
    const result = await client.list({ ...config });
    printListResult(result, config);
  } catch (err) {
    handleError(err);
  }
}
github twilio-labs / twilio-run / src / checks / project-structure.ts View on Github external
export async function doesAnyDirectoryExist(
  basePath: string,
  directories: string[]
): Promise {
  let foundDirectories: string | undefined;
  try {
    foundDirectories = fsHelpers.getFirstMatchingDirectory(
      basePath,
      directories
    );
  } catch {
    foundDirectories = undefined;
  }

  if (typeof foundDirectories !== 'undefined') {
    return true;
  }

  return false;
}
github twilio-labs / twilio-run / src / templating / filesystem.ts View on Github external
export async function writeFiles(
  files: TemplateFileInfo[],
  targetDir: string,
  namespace: string
): Promise {
  const functionsDir = fsHelpers.getFirstMatchingDirectory(targetDir, [
    'functions',
    'src',
  ]);
  const assetsDir = fsHelpers.getFirstMatchingDirectory(targetDir, [
    'assets',
    'static',
  ]);
  const functionsTargetDir = path.join(functionsDir, namespace);
  const assetsTargetDir = path.join(assetsDir, namespace);

  if (functionsTargetDir !== functionsDir) {
    if (hasFilesOfType(files, 'functions')) {
      try {
        await mkdir(functionsTargetDir);
      } catch (err) {
        debug(err);
github twilio-labs / twilio-run / src / templating / filesystem.ts View on Github external
export async function writeFiles(
  files: TemplateFileInfo[],
  targetDir: string,
  namespace: string
): Promise {
  const functionsDir = fsHelpers.getFirstMatchingDirectory(targetDir, [
    'functions',
    'src',
  ]);
  const assetsDir = fsHelpers.getFirstMatchingDirectory(targetDir, [
    'assets',
    'static',
  ]);
  const functionsTargetDir = path.join(functionsDir, namespace);
  const assetsTargetDir = path.join(assetsDir, namespace);

  if (functionsTargetDir !== functionsDir) {
    if (hasFilesOfType(files, 'functions')) {
      try {
        await mkdir(functionsTargetDir);
      } catch (err) {
        debug(err);
        throw new Error(
          `Template with name "${namespace}" already exists in "${functionsDir}"`
        );
      }
github twilio-labs / twilio-run / src / runtime / internal / runtime-paths.ts View on Github external
export async function getFunctionsAndAssets(
  baseDir: string
): Promise {
  let { functions, assets } = await fsHelpers.getListOfFunctionsAndAssets(
    baseDir
  );
  return { functions, assets };
}

@twilio-labs/serverless-api

API-wrapper for the Twilio Serverless API

MIT
Latest version published 6 days ago

Package Health Score

83 / 100
Full package analysis