0.1.5 • Published 5 years ago

zeit-api-client v0.1.5

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

zeit-api-client

NPM

API client for ZEIT Now and ZEIT Integrations

Related Links

Install

npm install --save zeit-api-client
# or 
yarn add zeit-api-client

Usage

Basic

const ZeitApiClient = require("zeit-api-client")
// import ZeitApiClient from "zeit-api-client"

const zeitApi = new ZeitApiClient({token:process.env.ZEIT_TOKEN})
const latestDeployments = await zeitApi.getDeployments({limit:5})
console.log(latestDeployments[0])

Within an integration

const { withUiHook, htm } = require("@zeit/integration-utils");
const ZeitApiClient  = require("zeit-api-client")
module.exports = withUiHook(async ({ payload, zeitClient }) => {
  const zeitApi = new ZeitApiClient({token:payload.token})
  const latestDeployments = await zeitApi.getDeployments()
  return htm`
    <Page>
      <H1>Latest Deployments</H1>
      <Code>
        ${JSON.stringify(latestDeployments, null, 2)}
      </Code>
    </Page>
  `;
});

Documentation

View Documentation

ZeitApiClient

Parameters

Examples

const ZeitApiClient = require("zeit-api-client")
const ZEIT_TOKEN = "your_zeit_now_token" // process.env.ZEIT_TOKEN
const zeitApi = new ZeitApiClient({token:ZEIT_TOKEN})

getUser

Get the authenticated user

Official Documentation: https://zeit.co/docs/api#endpoints/user

Examples

const user = zeitApi.getUser()

createDeployment

Create a new deployment with all the required and intended data.

Official Documentation: https://zeit.co/docs/api#endpoints/deployments/list-deployments

Parameters

  • data Object
    • data.name String A string with the project name used in the deployment URL. The name string has a max length of 52 characters.
    • data.files Array A list of objects with the files to be deployed.
    • data.version Number The version of Now Platform to use. Must have the value of 2.
    • data.meta Object An object containing the deployment's metadata. Multiple key-value pairs can be attached to a deployment. For example, { "foo": "bar" }.
    • data.env Object An object containing the deployment's environment variable names and values. Secrets can be referenced by prefixing the value with @.
    • data.builds Array A list of Build objects used to build sources in a deployment. For example, {{ "src": "*.php", "use": "@now/php" }}.
    • data.routes Array A list of routes objects used to rewrite paths to point towards other internal or external paths. For example; { "src": "/docs", "dest": "https://docs.zeit.co" }.
    • data.regions Array An array of the regions the deployment should be deployed to. For example, "sfo", "bru".
    • data.public Boolean Whether a deployment's source and logs are available publicly.
    • data.target String Either not defined, staging or production. If staging, a staging alias in the format ..now.sh will be assigned. If production, any aliases defined in alias will be assigned.
    • data.alias Array Aliases that will get assigned when the deployment is READY and the target is production. The client needs to make a GET request to this API to ensure the assignment.

Examples

const deploymentData = {
  "name": "my-instant-deployment",
  "version": 2,
  "files": [
    {
      "file": "index.html",
      "data": "<!doctype html>\n<html>\n  <head>\n    <title>A simple deployment with the Now API!</title>\n  </head>\n  <body>\n    <h1>Welcome to a simple static file</h1>\n    <p>Deployed with <a href=\"https://zeit.co/docs/api\">ZEIT&apos;s Now API</a>!</p>\n    </body>\n</html>"
    }
  ]
}
const newDeployment = zeitApi.createDeployment(deploymentData)

uploadFile

Uploads a file and returns its size and sha if successful (currently only works in node). Returned object can be used with createDeployment() files section

Official Documentation: https://zeit.co/docs/api#endpoints/deployments/upload-deployment-files

Parameters

  • options Object
    • options.filePath String Path pf file to upload

Returns Object fileData

Returns String fileData.sha sha1 hash of uploaded file

Returns String fileData.size size in bytes of uploaded file

getDeployments

Fetch all deployments

Official Documentation: https://zeit.co/docs/api#endpoints/deployments/list-deployments

Parameters

  • options Object
    • options.limit Number Maximum number of deployments to list from a request. (default: 5, max: 100)
    • options.from Timestamp Get the deployment created after this Date timestamp. (default: current time)
    • options.projectId String Filter deployments from the given projectId
    • options.meta-null String KEY Filter deployments by the given meta key value pairs. e.g., meta-githubDeployment=1

getDeployment

Fetch single deployment by id

Official Documentation: https://zeit.co/docs/api#endpoints/deployments/get-a-single-deployment

Parameters

  • deploymentId String deployment id

getDeploymentFiles

Fetch a list of deployments files

Official Documentation: https://zeit.co/docs/api#endpoints/deployments/list-deployment-files

Parameters

  • deploymentId String deployment id

getDeploymentFile

Fetch a single file by deployment and file id

Official Documentation: https://zeit.co/docs/api#endpoints/deployments/list-deployment-files

Parameters

  • deploymentId String deployment id
  • fileId

deleteDeployment

Delete a single deployment by id

Official Documentation: https://zeit.co/docs/api#endpoints/deployments/delete-a-deployment

Parameters

  • deploymentId String deployment id

getLogs

Get the logs of a deployment by its ID.

Official Documentation: https://zeit.co/docs/api#endpoints/logs

Parameters

  • deploymentId String deployment id

getAliases

Fetch all aliases

Official Documentation: https://zeit.co/docs/api#endpoints/aliases/list-all-the-aliases

Parameters

  • options Object
    • options.limit Number Maximum number of aliases to list from a request. (default: 5, max: 100)
    • options.from Timestamp Get the aliases created after this Date timestamp. (default: current time)
    • options.projectId String Filter aliases from the given projectId

getDeploymentAliases

Fetch a deployment's aliases

Official Documentation: https://zeit.co/docs/api#endpoints/aliases/list-aliases-by-deployment

Parameters

  • deploymentId String Id of deployment to fetch aliases from

getSecrets

Fetch all secrets

Official Documentation: https://zeit.co/docs/api#endpoints/secrets/list-all-the-secrets

getTeams

Fetch all teams

Official Documentation: https://zeit.co/docs/api#endpoints/teams/list-all-your-teams

getProjects

Fetch all projects

Official Documentation: https://zeit.co/docs/api#endpoints/projects/get-all-projects

Parameters

  • options Object
    • options.limit Number Limit the number of projects returned
    • options.from Timestamp The updatedAt point where the list should start.
    • options.search String Search projects by the name field.

getDomains

Fetch all domains

Official Documentation: https://zeit.co/docs/api#endpoints/domains/list-all-the-domains

Parameters

  • options

getCertificates

Fetch all certificates

Official Documentation: https://zeit.co/docs/api#endpoints/certificates/list-all-the-certificates

Parameters

  • options

getWebhooks

Fetch all webhooks

Official Documentation: https://zeit.co/docs/api#endpoints/webhooks/list-all-webhooks

License

MIT © Luka Kakia

0.1.5

5 years ago

0.1.4

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago

0.0.0

5 years ago