npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@twilio-labs/serverless-api

v5.6.0

Published

API-wrapper for the Twilio Serverless API

Downloads

58,576

Readme

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"
});

HTTP Client Configuration

When deploying lots of Functions and Assets it is possible to run up against the enforced concurrency limits of the Twilio API. You can limit the concurrency and set how many times the library retries API requests either in the constructor for TwilioServerlessApiClient or using environment variables (useful when this is part of a CLI tool like twilio-run).

The default concurrency is 50 and the default number of retries is 10. You can change this in the config, the following would set concurrency to 1, only 1 live request at a time, and retries to 0, so if it fails it won't retry.

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

You can also set these values with the following environment variables:

export TWILIO_SERVERLESS_API_CONCURRENCY=1
export TWILIO_SERVERLESS_API_RETRY_LIMIT=0

Usage with proxy

  • HTTP_PROXY: If deploying behind a proxy, set the URL of the proxy in an environment variable called HTTP_PROXY.

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):

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

License

MIT