Skip to content
Node.js library to manage deploy Serverless Functions
TypeScript JavaScript Shell
Branch: master
Clone or download
butuzov and dkundel docs(readme): update (absolute) link to CONTRIBUTING.md (#17)
link to contributing.md changed to absolute 

Reason for this - is website https://serverless-api.twilio-labs.com/  that generated by this readme
doesn't actually have CONTRIBUTING.md
Latest commit c490844 Oct 4, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.vscode feat(environments): make naming of environments predictable Jul 24, 2019
hooks build(npm): setup git hooks and linters Jul 10, 2019
src fix(build): reject promise on failed build Sep 25, 2019
.all-contributorsrc docs: add @dkundel as a contributor Jul 2, 2019
.gitignore add docs to ignore file May 1, 2019
.npmrc disable lock file May 1, 2019
.nvmrc add nvmrc to pin Node 8.10 Apr 26, 2019
.prettierrc build(npm): setup git hooks and linters Jul 10, 2019
CHANGELOG.md chore(release): 1.0.3 Sep 25, 2019
CODE_OF_CONDUCT.md 🎉 Initial commit Apr 9, 2019
CONTRIBUTING.md docs(contributing): add release steps Jul 10, 2019
LICENSE chore(license): update copyright notice Sep 25, 2019
README.md docs(readme): update (absolute) link to CONTRIBUTING.md (#17) Oct 3, 2019
commitlint.config.js build(npm): setup git hooks and linters Jul 10, 2019
jest.config.js
npm-shrinkwrap.json chore(shrinkwrap): update shrinkwrap file Sep 25, 2019
package.json chore(release): 1.0.3 Sep 25, 2019
tsconfig.json Add initial version of API Apr 9, 2019
typedoc.json change docs config May 2, 2019

README.md

@twilio-labs/serverless-api

A module to interact with the Twilio Serverless API. For example to deploy projects. Part of the Serverless Toolkit.
Full reference documentation at serverless-api.twilio-labs.com

npm (scoped) npm GitHub All Contributors Code of Conduct PRs Welcome


Installation

npm install @twilio-labs/serverless-api

Example

If you want to deploy a local project you can do this using:

const TwilioServerlessApiClient = require('@twilio-labs/serverless-api');

const client = new TwilioServerlessApiClient({
  accountSid: '...',
  authToken: '...',
});

client.on('status-update', evt => {
  console.log(evt.message);
});

const result = await client.deployLocalProject({
  cwd: '...',
  envPath: '...',
  accountSid: '...',
  authToken: '...',
  env: {},
  pkgJson: {},
  serviceName: 'serverless-example',
  functionsEnv: 'dev',
  assetsFolderName: 'static',
  functionsFolderName: 'src',
});

API

You can find the full reference documentation of everything at: https://serverless-api.twilio-labs.com

Some functions you might want to check out is:

client.activateBuild(activateConfig: ActivateConfig): Promise<ActivateResult>

"Activates" a build by taking a specified build SID or a "source environment" and activating the same build in the specified environment.

More in the Docs

client.deployLocalProject(deployConfig: DeployLocalProjectConfig): 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.

More in the Docs

client.deployProject(deployConfig: DeployProjectConfig): Promise<DeployResult>

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.

const result = await client.deployProject({
  env: {},
  pkgJson: {},
  serviceName: 'serverless-example',
  functionsEnv: 'dev',
  functions: [
    {
      name: 'hello-world',
      path: '/hello-world-path',
      content: await readFile(path.join(__dirname, 'some-dir', 'handler.js')),
      access: 'public',
    },
  ],
  assets: [
    {
      name: 'image',
      path: '/foo/image.jpg',
      access: 'public',
      content: await readFile(path.join(__dirname, 'another-dir', 'image.jpg')),
    },
  ]
});

More in the Docs

client.getClient(): GotClient

Returns the internally used GotClient instance used to make API requests

More in the Docs

client.list(listConfig: ListConfig): Promise<ListResult>

Returns an object containing lists of services, environments, variables functions or assets, depending on which have beeen requested in listConfig

More in the Docs

api and fsHelpers

There's also a variety of small helper libraries that you can find more details on https://serverless-api.twilio-labs.com.

You can consume them in two ways:

const { fsHelpers, api, utils } = require('@twilio-labs/serverless-api');
// or
const fsHelpers = require('@twilio-labs/serverless-api/dist/utils/fs');
const api = require('@twilio-labs/serverless-api/dist/api');
const utils = require('@twilio-labs/serverless-api/dist/utils');

Contributing

This project welcomes contributions from the community. Please see the CONTRIBUTING.md file for more details.

Code of Conduct

Please be aware that this project has a Code of Conduct. The tldr; is to just be excellent to each other ❤️

Contributors

Thanks goes to these wonderful people (emoji key):

Dominik Kundel
Dominik Kundel

💻 📖 🤔

This project follows the all-contributors specification. Contributions of any kind welcome!

License

MIT

You can’t perform that action at this time.