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

imgix-management-js

v1.3.1

Published

A Javascript library that wraps the imgix management API

Downloads

5,623

Readme

⚠️ This library is currently marked as experimental. We plan to eventually integrate it as its own module in @imgix/js-core.

imgix logo

imgix-management-js is a JavaScript client library for making requests against the imgix Management API.

NPM Version Build Status Monthly Downloads Minified Size License styled with prettier FOSSA Status


Installation

npm install imgix-management-js

imgix-management-js exposes a class ImgixAPI:

CommonJS

const ImgixAPI = require("imgix-management-js");

const imgix = new ImgixAPI({
    apiKey: `${yourApiKey}`
});

Configuration

The following options can be used when creating an instance of ImgixAPI:

  • apiKey: String, required. The token used to authenticate API requests.
  • version: Integer. The version of the API that will be requested against. Defaults to 1.

API

ImgixAPI.request(path, options)

  • path: String, required. A partial path representing the relative URL endpoint to request. This will typically require a sourceId.
  • options: Object. Any custom HTTP(S) settings to be applied to a request.
    • method: String, required. The request method, defaults to 'GET'.
    • headers: Object. Additional information included with a request.
    • body: Object, String, or Buffer. A resource, such as binary data or a file, included with the request.

Makes a request against the specified imgix Management API endpoint.

Returns: Promise<[Response]>

The supplied path should be a relative URL, such as assets/{sourceId}. Using this path, the full API URL will be constructed at the time that the request is made, saving users the need to provide the full URL themselves each time.

ImgixAPI will intelligently populate any necessary headers prior to completing the request. This includes fields such as Content-Type and Authorization. Outside of that, the options argument can be used to override certain defaults, such as the HTTP request method, or provide a file for uploading.

Usage Examples

The following sections demonstrate how to use this library to make API requests for common use cases. For a full list of endpoints and operations, see the management API docs.

Retrieve a list of images

imgix.request(`assets/${sourceId}`)
.then(response => console.log(JSON.stringify(response, null, 2)));

Retrieve all details for a single image

imgix.request(`assets/${sourceId}/${originPath}`)
.then(response => console.log(JSON.stringify(response, null, 2)));

Retrieve custom fields for a single image

var customFields;

imgix.request(`assets/${sourceId}/uploads/pecanpie.jpg`)
.then(response => {
    customFields = response.data.attributes.customFields;
    console.log(customFields);
});

Update custom fields for a single image

var document = {
    'data': {
        'id': `${sourceId}/pecanpie.jpg`,
        'type': 'assets',
        'attributes': {}
    }
};

imgix.request(`sources/${sourceId}/assets/pecanpie.jpg`)
.then(response => {
    /*
    ** Populate `document` with all pre-existing fields
    ** so as to not overwrite them when sending a PATCH request
    */
    document.data.attributes.custom_fields = response.data.attributes.custom_fields;
    document.data.attributes.custom_fields.type = 'dessert';

    // PATCH request to write in new custom field
    imgix.request(`sources/${sourceId}/assets/pecanpie.jpg`, {
        method: 'PATCH',
        body: document
    })
    .then(response => console.log(response.data.attributes))
})

Upload an image

const data = fs.readFileSync('./src/monstera.jpg');

imgix.request(`sources/upload/${sourceId}/monstera.jpg`, {
    method: 'POST',
    body: data
})
.then(response => console.log(JSON.stringify(response, null, 2)));

Retrieve all sources

imgix.request(`sources`)
.then(response => console.log(JSON.stringify(response, null, 2)));

Specify the fields returned

// To request a deeply-nested field, use dot notation

imgix.request(`sources/${sourceId}?fields[sources]=name,deployment_status,deployment.default_params`)
.then(resp => console.log(resp));

Paging by page number and size

imgix.request(`assets/${sourceId}?page[number]=0&page[size]=1`)
.then(resp => console.log(resp))

Sorting lists of objects

// To sort a field in descending order, prepend a dash “-” to the field name.

imgix.request('sources?sort=name&fields[sources]=name')
.then(resp => console.log(resp))

Filtering lists of objects

imgix.request('sources?filter[name]=staging&filter[deployment.type]=s3')
.then(resp => console.log(resp))

Create an object

var data = {
  "data": {
    "attributes": {
      "name": "New Web Folder Source",
      "deployment": {
        "type": "webfolder",
        "webfolder_base_url": "https://my-domain.com/images/",
        "imgix_subdomains": [
          "my-unique-imgix-subdomain"
        ]
      }
    },
    "type": "sources"
  },
  "jsonapi": {
    "version": "1.0"
  }
}

imgix.request(`sources`, {
    method: 'POST',
    body: data
})
.then(response => console.log(JSON.stringify(response, null, 2)));

License

FOSSA Status