Code Monkey home page Code Monkey logo

cli's Introduction

Calibre’s Node.js API and Command Line Client (CLI)

NPM package Node version support License

This repository contains Calibre’s APIs you can use to fetch and manage your monitoring data. The Command Line Client (CLI) is designed for simple tasks right from your terminal. We recommend using the Node.js API for more complex tasks and automation.

ℹ️ Please note: Using the APIs requires an active Calibre account (in trial or on a paid plan).

🖇 Table of Contents

  1. Installation
  2. Authentication
  3. Features
  4. Usage
  5. Package Exports
  6. Script Examples
  7. Contributing
  8. Resources
  9. License

📥 Installation

To install the latest version globally, run this command:

npm install -g calibre

or save it directly to your project:

npm install calibre --save

The calibre package is built to support all current Node.js LTS releases.

🔐 Authentication

To authenticate to Calibre and use the APIs, you will need to create or use an existing API Token. Learn about the types of API Tokens and how to create them here.

Once you have an API Token, you can store it locally:

calibre token set <your token>

Or alternately, set CALIBRE_API_TOKEN environment variable.

💡 Features

  • Manage performance with a single command. Retrieve all speed data and manage the test environment and settings.
  • Run Single Page Tests. Create one-off tests privately or share them with your team.
  • Monitor speed across your release process. Track performance between deploys and mark them on your charts.
  • Use Calibre within CI/CD. Every command has a --json flag for machine-readable output.
  • Script any action. We export all API methods to the Calibre npm package..

🛠 Usage

To see a full list of available commands, subcommands and options run:

$ calibre --help
$ calibre <command> --help

or see all commands in this repository or Calibre’s documentation.

In Node, you can use the either ES Modules or CommonJS versions accordingly:

// ES Modules
import { Site } from 'calibre'
await Site.list()
// CommonJS
const { Site } = require('calibre')
await Site.list()

📤 Package exports

In addition to the named default exports shown above, the calibre package also exports CLI related metadata, which is used to generate CLI documentation.

CLI Commands

Each CLI command is a Node module that exports command, describe, handler and builder. You can import all CLI commands from calibre/cli-commands (see src/cli.js for reference).

import Commands from 'calibre/cli-commands'

CLI Metadata

You can import command metadata (used to generate CLI documentation) from the calibre/cli-metadata export:

import { getCommandMetaData } from 'calibre/cli-metadata'
console.log(JSON.stringify(getCommandMetaData(), null, 2))

🙌🏻 Contributing

Happy to hear you’re interested in contributing to Calibre’s APIs! Please find our contribution guidelines here.

🖥 Script Examples

We prepared a handful of examples for common actions you might want to perform:

📚 Resources

Find code examples and more information for the CLI and Node.js API in our documentation.

💼 License

This project is MIT licensed.

cli's People

Contributors

bassettsj avatar benschwarz avatar colby-swandale avatar dependabot-preview[bot] avatar dependabot[bot] avatar ethitter avatar gnujoow avatar jonogillettt avatar mikedijkstra avatar tapsboy avatar thefoxis avatar trieloff avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

cli's Issues

process.env.CALIBRE_HOST isn't set for node.js API approach

Node API Issue

What you expected to happen

CALIBRE_HOST env variable should be set before the code reaches

What happened

While try to use the ad-hoc "Test" API using the node.js API approach, CALIBRE_HOST isn't set as an env variable

Error: TypeError: Cannot read property 'error' of undefined at Object.create (/Users/tapanshah/aenetworks/aetn.watch.perftrigger/node_modules/calibre/src/api/test.js:75:20) at at runMicrotasksCallback (internal/process/next_tick.js:121:5) at _combinedTickCallback (internal/process/next_tick.js:131:7) at process._tickCallback (internal/process/next_tick.js:180:9) at Function.Module.runMain (module.js:686:11) at startup (bootstrap_node.js:187:16) at bootstrap_node.js:608:3

Steps to Reproduce (for bugs)

const { Test } = require('calibre');
const urlToTest = 'https://www.yahoo.com';

const payload = {
  url: urlToTest,
  location: 'NorthVirginia',
  device: 'iPhone8',
  connection: 'good3G'
};

Test.create(payload)
  .then(r => console.log(r))
  .catch(e => console.error(e));

command not found?

I keep getting calibre: command not found when trying to run in terminal (mac). Installation and setup with API seemed to go through successfully and pretty straightforward. Am I missing something basic? :)

'calibre site pages' should return slug of the page

When I list my sites via CLI, apart from the name that is displayed in the calibre ui I also get site's slug:

calibre site list --json

[
  {
    "name": "FirstSite Name",
    "slug": "firstsite-name",
    "createdAt": "2015-05-19T07:23:39Z"
  },
  {
    "name": "SecondSite (Something)",
    "slug": "secondsite-something",
    "createdAt": "2015-10-05T09:42:53Z"
  }
]

But when I'm fetching list of pages for the site I'm getting only original name of the page and its uuid:

calibre site pages --site=firstsite-name --json

[
  {
    "uuid": "uuid1",
    "name": "Name Of The Page With Spaces",
    "url": "https://legiturl.com/",
    "canonical": true
  },
  {
    "uuid": "uuid2",
    "name": "Weird (N)a me",
    "url": "https://legiturl.com/2",
    "canonical": false
  }
]

If I want to get pulse metrics for particular page I have to guess its slug, because I can't use uuid there.

Shouldn't calibre site pages return also page's slug? 🤔

Error: [object Object] returned from CLI in terminal and node script

CLI Installation method

  • NPM / NPX
  • Binary

Output of calibre --version

1.2.4

Operating system

  • Mac
  • Windows
  • Linux

What you expected to happen

From both the terminal interface (calibre test create [url] --[location]) and from a node script (using the example provided) I expect to run a test and after some time results returned or any errors handled gracefully.

What happened

Error from Node Script: (node:2085) UnhandledPromiseRejectionWarning: Error: [object Object] at Object.waitForTest (/Users/allen/traffic/node_modules/calibre/src/api/test.js:107:69) at processTicksAndRejections (internal/process/task_queues.js:86:5) (node:2085) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:2085) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Error from terminal CLI:

(in Red text): Error: [object Object]

Steps to Reproduce (for bugs)

  1. From the CLI Terminal, run tests on a sample site.

After 3-4 tests the test will run for an extended period of time and this unhandled exception error will return: UnhandledPromiseRejectionWarning: Error: [object Object]

The number of tests before this error is returned has not been consistent. I was able to duplicate in both the example node script provided with the CLI and in the terminal using the CLI commands.

I've been unable to get any more information about the error other than the [object Object] portion.

--device and --connection parameters get ignored

CLI Installation method

  • NPM
  • Binary

Operating system

  • Mac
  • Windows
  • Linux

What you expected to happen

I've been running this command:

$ ./node_modules/.bin/calibre test create http://$CIRCLE_BRANCH.$MYURL --location=SaoPaulo --device=iPhone8 --connection=good3G

According to the documentation, specifying iPhone8 and good3G as the device and connection parameters.

I expected a test to be run with these conditions.

What happened

http://$CIRCLE_BRANCH.$MYURL on Chrome Desktop

The --device and --connection parameters have been ignored without any error message.

How to improve

either:

  • add a device-list and connection-list subcommand similar to location-list
  • document the correct parameters and their possible values
  • report an error for unknown devices and connection properties
  • all of the above

2.0.0 changes

Using this issue to track changes coming into CLI for 2.0.0 release.

There's been a few things we've wanted to do but didn't because we didn't want to risk changing CLI flags etc.

  • Add adblocking to single page tests. Add ability to turn it on or off for a test profile (#48)
  • Tidy up command line flags so that they're all --dash-separated rather than --camelCase (#48)
  • Rename flags used to turn JavaScript on / off (#48)
  • Remove GIF artifact download (#50)
  • Move get-pulse-metrics to use the top level timeseries query method
  • Add / Remove deploy markers (#52)
  • Change snapshots to use snapshotsList for pagination (#52)
  • Return completed, errored and timeout tests with runtimeError (#53)
  • Change the metrics chart for single page tests to swap out FMP for FCP (#54)
  • Match Lighthouse grade colours to app (#54)

calibre does not exit with an error code when appropriate

CLI Installation method

  • NPM
  • Binary

Operating system

  • Mac
  • Windows
  • Linux

What you expected to happen

When an error occurs, calibre should exit with a non-zero error-code.

What happened

When an error is encountered, calibre exits with a 0 code.

Steps to Reproduce (for bugs)

  1. npm install --save calibre
  2. npx calibre site create-snapshot --site=INCORRECT_SITE_NAME --json
  3. echo $?

Retrieving Agent settings

At the moment the Node AgentSettings API allows for settings to be updated for a given site, however there is no method to easily retrieve the current settings. They are also not returned via the Site.list function.

We'll need to add an AgentSettings.get function to make this more ergonomic.

Manage budgets via API

This issue is to track the process of having support for managing budgets.

At the moment we do not have the capacity to mange (view, create, update, delete) metric budgets for a site. Add that.

get-all-pulse-metrics.js -> Variables

I've successfully run + output the 7-days and (30 days) script to JSON. Fiddling around with it, it would be good to be able to adjust variables:
$sites
$pages
$duration
$metrics retrieved

For example:

    // Iterate through each page, returning a promise for the metrics being fetched
    return Promise.all(pages.map(async page => {
      const pulse = await SnapshotMetrics.pulse({
        site: site.slug,
        page: page.uuid,
        durationInDays: 30,
        metrics: ['consistently-interactive']
      })

      // Update the allPulseMetrics hash with metrics for this page
      allPulseMetrics[site.slug][page.uuid] = {
        page: page,
        pulse: pulse
      }

When I modified metrics: ['consistently-interactive'] to metrics: ['consistently-interactive','meaningful-paint'], I got back (node:84764) UnhandledPromiseRejectionWarning: [object Array] and when I tried other variations, I got back other similar errors. I also did not know which variables to put into metrics, because they are not named 1:1 with the desktop UI labels.

Changing Setting for Test Profiles

There are times that we will need to update our test profiles for cookies to provide required authentication information for example. Would it be possible to add this to the CLI?

Thanks :-)

Release 2.2.0

Using this issue to track changes coming into CLI for 2.2.0 release.

  • Add Integrations to the Node.JS API (#79)
  • Add Metric Budgets to the Node.JS API (#78, #81)
  • Add Agent Settings to the Node.JS API (#83)

Retrieving snapshot metrics for invalid snapshot throws error

Command:

calibre site get-snapshot-metrics --site=calibre --snapshot=1000000

Returns:

 TypeError: e.map is not a function

Command:

calibre site get-snapshot-metrics --site=calibre --snapshot=1000000 --json

Returns:

TypeError: Cannot read property 'tests' of null
    at Object.main [as handler] (/Users/micdijkstra/.asdf/installs/nodejs/11.6.0/.npm/lib/node_modules/calibre/src/cli/site/get-snapshot-metrics.js:68:27)
    at process.internalTickCallback (internal/process/next_tick.js:77:7)

It should return a more helpful error message.

Error when running Node API examples (Cannot find module './src/api/test_profile')

CLI Installation method

  • NPM / NPX
  • Binary

Output of calibre --version

1.0.8

Operating system

  • Mac
  • Windows
  • Linux

What you expected to happen

Following instructions in docs to be able to run the sample JS files which use the API.

What happened

Every example script I run results in the same error:

Error: Cannot find module './src/api/test_profile' Error: Cannot find module './src/api/test_profile' at Function.Module._resolveFilename (module.js:547:15) at Function.Module._load (module.js:474:25) at Module.require (module.js:596:17) at require (internal/module.js:11:18) at Object. (/Users/henry/git/calibre-cli/examples/nodejs/node_modules/calibre/index.js:16:21) at Module._compile (module.js:652:30) at Object.Module._extensions..js (module.js:663:10) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12) at Function.Module._load (module.js:497:3)

Steps to Reproduce (for bugs)

$ git clone [email protected]:calibreapp/cli.git calibre-cli
$ cd calibre-cli/examples/nodejs/
$ npm install
npm WARN [email protected] No repository field.

added 160 packages in 7.08s
$ CALIBRE_API_TOKEN=blah ./list-agent-locations.js
module.js:549
    throw err;
    ^

Error: Cannot find module './src/api/test_profile'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/henry/git/calibre-cli/examples/nodejs/node_modules/calibre/index.js:16:21)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)

$ node --version
v8.11.3

Not able to install Calibre CLI in Ubuntu machine

CLI Installation method

  • NPM / NPX
  • Binary

Output of calibre --version

root@ip-*****:/home/delops# calibre --version
Traceback (most recent call last):
File "/usr/bin/calibre", line 19, in
from calibre.gui2.main import main
File "/usr/lib/calibre/calibre/gui2/init.py", line 21, in
from calibre.utils.date import UNDEFINED_DATE
File "/usr/lib/calibre/calibre/utils/date.py", line 13, in
from dateutil.tz import tzlocal, tzutc, EPOCHORDINAL
File "/usr/local/lib/python2.7/dist-packages/dateutil/tz/init.py", line 2, in
from .tz import *
File "/usr/local/lib/python2.7/dist-packages/dateutil/tz/tz.py", line 21, in
from six.moves import _thread

Operating system

  • Mac
  • Windows
  • Linux

What you expected to happen

Clean installation of calibre CLI without any issue

What happened

I performed "npm install calibre -g ", but got the below error. I am not able to install calibre CLI in my Ubuntu machine.

1842 verbose linkStuff '/usr/local/lib/node_modules/calibre/node_modules' ]
1843 info linkStuff [email protected]
1844 silly gunzTarPerm extractEntry index.js
1845 silly gunzTarPerm extractEntry readme.md
1846 silly addNameRange number 2 { name: 'samverschueren/stream-to-observable',
1846 silly addNameRange range: '>=0.3.0-0 <0.4.0-0',
1846 silly addNameRange hasData: true }
1847 silly addNameRange versions [ undefined, [] ]
1848 error TypeError: Cannot read property 'latest' of undefined
1848 error at next (/usr/share/npm/lib/cache.js:687:35)
1848 error at /usr/share/npm/lib/cache.js:675:5
1848 error at saved (/usr/share/npm/node_modules/npm-registry-client/lib/get.js:142:7)
1848 error at /usr/lib/nodejs/graceful-fs/polyfills.js:133:7
1848 error at Object.oncomplete (fs.js:107:15)
1849 error If you need help, you may report this log at:
1849 error http://github.com/isaacs/npm/issues
1849 error or email it to:
1849 error [email protected]
1850 error System Linux 3.13.0-43-generic
1851 error command "/usr/bin/nodejs" "/usr/bin/npm" "install" "calibre" "-g"
1852 error cwd /root
1853 error node -v v0.10.25
1854 error npm -v 1.3.10
1855 error type non_object_property_load
1856 verbose exit [ 1, true ]

Steps to Reproduce (for bugs)

npm install calibre -g

Thanks in advance,
Rahul

Field 'createSnapshot' doesn't accept argument 'ref'

CLI Installation method

  • NPM
  • Binary

Operating system

  • Mac
  • Windows
  • Linux

What you expected to happen

I expected npx calibre site create-snapshot --site=SITENAME to create a snapshot without an error.

What happened

When attempting to create a snapshot, I received an error: Field 'createSnapshot' doesn't accept argument 'ref'

I was attempting to pass in a reference id with --ref but this error is occurring whether or not I specify a ref.

Error: [ { message: 'Field \'createSnapshot\' doesn\'t accept argument \'ref\'', locations: [ [Object] ], fields: [ 'mutation CreateSnapshot', 'createSnapshot', 'ref' ] }, { message: 'Variable $ref is declared by CreateSnapshot but not used', locations: [ [Object] ], fields: [ 'mutation CreateSnapshot' ] } ]

Steps to Reproduce (for bugs)

  1. npm install --save calibre
  2. npx calibre site create-snapshot --site=SITENAME

ChainAlert: npm package release (5.0.0) has no matching tag in this repo

Dear calibre maintainers,
Thank you for your contribution to the open-source community.

This issue was automatically created to inform you a new version (5.0.0) of calibre was published without a matching tag in this repo.

As part of our efforts to fight software supply chain attacks, we would like to verify this release is known and intended, and not a result of an unauthorized activity.

If you find this behavior legitimate, kindly close and ignore this issue. Read more

badge

3.0 Release

  • Update version
  • Update minimum node version
  • Update CHANGELOG
  • Update docs
    • Create site with agent settings

Allow calling api from the client-side

Can we enable calling the api from the client-side?

My first approach was to try to use the node api as graphql-request works for both node and js. This didn't work as it expected a CALIBRE_API_TOKEN. The entire api takes input as environment variables.

If the node api could be refactored to allow passing those values it would make for a cleaner and more flexible api. If that's not feasible, can the graphql api be tweaked such that it works for cross origin requests?
I tried calling the graphql api directly but currently when I call the api from the client-side, the network request fails as newer browsers makes a pre-flight OPTIONS request which throws a 404.

Test Create Only Passes the First Cookie

CLI Installation method

  • NPM / NPX
  • Binary

Output of calibre --version

1.0.9

Operating system

  • Mac
  • Windows
  • Linux

What you expected to happen

I expect that calibre test create --cookie-jar= to allow multiple cookies be passed to it.

What happened

Only the first cookie is used.

Error:

Show Speed Index in metrics list

CLI Installation method

  • NPM / NPX
  • Binary

Output of calibre --version

Operating system

  • Mac
  • Windows
  • Linux

What you expected to happen

Expecting Speed Index to be included in the metrics list

What happened

N/A

Steps to Reproduce

calibre site get-pulse-metrics --site=site-name --page=page-slug --metrics

Latest release of calibre broken in node 8 (v8.15.0), works in node 10

CLI Installation method

  • NPM / NPX
  • Binary

Output of calibre --version

Operating system

  • Mac
  • Windows
  • Linux

What you expected to happen

npx calibre site create-snapshot --site abc

What happened

it crashes

Error: npx: installed 205 in 11.696s /Users/anthonymittaz/.npm/_npx/59370/lib/node_modules/calibre/src/cli/site/download-snapshot-artifacts.js:53 for await (const page of response.pages) { ^^^^^

SyntaxError: Unexpected reserved word
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:617:28)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)
at Object.require (internal/module.js:11:18)
at /Users/anthonymittaz/.npm/_npx/59370/lib/node_modules/calibre/node_modules/require-directory/index.js:76:17
error Command failed with exit code 1.

Steps to Reproduce (for bugs)

  1. Use node 8, and latest calibre version: 1.2.0
  2. npx calibre site create-snapshot --site abc
  3. crash boom

SnapshotMetrics.pulse() fails with GraphQL error: Field 'hasCompletedSnapshots' doesn't exist on type 'Site'

CLI Installation method

  • NPM / NPX
  • Binary

Output of calibre --version

1.1.1

Operating system

  • Mac
  • Windows
  • Linux

What you expected to happen

I'm using a script based on the get-all-pulse-metrics.js which has been working fine. Today the script failed with a GraphQL error.

What happened

The following GraphQL error is breaking the SnapshotMetrics.pulse call

[ { message: 'Field \'hasCompletedSnapshots\' doesn\'t exist on type \'Site\'',
    locations: [ [Object] ],
    fields:
     [ 'query GetPulsePageData',
       'organisation',
       'site',
       'hasCompletedSnapshots' ] } ]

Removing hasCompletedSnapshots field from the query (

hasCompletedSnapshots
) seemed to fix the issue.

Steps to Reproduce (for bugs)

Run the get-all-pulse-metrics.js example with valid API token

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.