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

fastly-domains

v0.2.0

Published

Client to list all the domains for a particular Fastly account

Downloads

5

Readme

fastly-domains

Client to list all the domains for a particular Fastly account

travis build codecov coverage npm version npm downloads npm license

NPM

Table of Contents

Problem

The Fastly API doesn't provide an endpoint to fetch all the domains associated with an account. It only provides an endpoint which lists all the domains for a particular service and version and another one which lists all the domains for the active version of a service.

Solution

The solution is to perform a request to GET /service first in order to fetch all services of a Fastly account before you send a request for each service to GET /service/service_id/version/version/domain in order to fetch all of the domains of a service.

That's exactly what the fastly-domains library does. Let's say you have 10 services then it needs to perform eleven requests (1 + 10) to the Fastly API in order to fetch all domains associated with an account.

The library doesn't provide an option to specify a particular version of a service since it fetches the domains of all serivces. Instead it uses the active version for each request to GET /service/service_id/version/version/domain.

Security

You'll need a Fastly API Token in order to use the fastly-domains library. Your token must have at least global:read access. The token is necessary for every single invocation and won't be saved by the library!

Install

This is a Node.js module available through the npm registry. The fastly-domains library can be used locally in your scripts or globally in your Terminal or Command Prompt. Installation is done using the npm install command:

Globally

$ npm install --global fastly-domains

Locally

$ npm install --save fastly-domains

Usage

Globally

fastly-domains [command] [option]

| Commands | Options | Alias | Type | Required | Description | |----------|-----------|-------|---------|----------|----------------------------------------------| | read | | | | | List all the domains in the terminal | | | --help | -h | boolean | false | Show help | | | --version | -v | boolean | false | Show version number | | | --token | -t | string | true | Fastly API token | | create | | | | | Write all the domains to fastly-domains.json | | | --help | -h | boolean | false | Show help | | | --version | -v | boolean | false | Show version number | | | --token | -t | string | true | Fastly API token |

Locally

Promises

const fastlyDomains = require('fastly-domains');

function handler() {
  fastlyDomains('<your_fastly_api_token>')
    .then(res => {
      res.domains.forEach(domain => console.log(domain.name));
    })
    .catch(err => {
      console.log(err.message);
    });
}

Async/Await

const fastlyDomains = require('fastly-domains');

async function handler() {
  try {
    const res = await fastlyDomains('<your_fastly_api_token>');
    res.domains.forEach(domain => console.log(domain.name));
  } catch (err) {
    console.log(err.message);
  }
}

Response Schema

{
  // a list of all domains associated with a fastly account
  domains: [
    {
      version: 2,
      name: 'fastly-domains.com',
      service_id: '20Esr3c2mP2IO4661htKVo'
    },
    {
      version: 2,
      name: 'www.fastly-domains.com',
      service_id: '20Esr3c2mP2IO4661htKVo'
    }
  ],

  // the total number of all domains associated to a fastly account
  number_of_domains: 2,

  // the total number of all services associated to a fastly account
  number_of_services: 1
}

Tests

To run the test suite, first install the dependencies, then run the npm test command:

$ npm install
$ npm test

Contribute

PRs accepted. I am open to suggestions in improving this library. Commit by:

$ npm run commit

License

Licensed under the MIT License © 2017 Philipp Schulte