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

contensis-delivery-api

v1.5.0

Published

Client for retrieving content using the read-only Contensis Delivery API

Downloads

4,774

Readme

Contensis contensis-delivery-api TypeScript NPM version

JavaScript TypeScript Node.js

Angular Electron Express.js React React Native Vue.js

Contensis Contensis Slack

Create a Contensis client that allows you to query and retrieve entries, site view nodes, content types and projects. It can be used in all your JavaScript / TypeScript projects, whether it runs in a browser, Node.js app, or both.

Explore the docs on contensis.com and the contensis-delivery-api-examples repository containing Express.js, React and Angular test applications, as well as an extended example using nodes api in a Node.js project.

Use with Contensis version 12.0 and above. For Contensis 11.3 support use this version | npm. This library requires Node.js 14 or above.

Installation

Install the package to your project dependencies using npm, or your preferred Node.js package manager.

npm install --save contensis-delivery-api

Usage

Follow the examples with the preferred coding style that best suits your project

Create a client

All of the delivery methods are available under the client instance returned by Client.create(...)

Use the provided intellisense to guide you where it is available

// Using TypeScript, or ES Module syntax

import { Client } from "contensis-delivery-api";

const client = Client.create({
  rootUrl: "https://my-cms.com",
  accessToken: "DELIVERY_API_ACCESS_TOKEN",
  projectId: "website",
  language: "en-GB",
  versionStatus: "published",
});
// Using Common JS syntax

const Client = require("contensis-delivery-api").Client;

const client = Client.create({
  rootUrl: "https://my-cms.com",
  accessToken: "DELIVERY_API_ACCESS_TOKEN",
  projectId: "website",
  language: "en-GB",
  versionStatus: "published",
});

Get a list of entries

Reusing the client instance we created above

// Using TypeScript, or ES Module syntax

const loadMovies = async () => {
  const movieList = await client.entries.list({
    contentTypeId: "movie",
    pageOptions: { pageIndex: 0, pageSize: 10 },
    order: ["-releaseDate"],
  });
  for (const movie of movieList.items) {
    console.log(movie);
  }
};

loadMovies();

Create a client config and get a list of entries

Keep a common client configuration and create the delivery client when you need it

// Using async / await syntax (avoiding callbacks)

// Import the additional "Config" type when using TypeScript
import { Client, Config } from "contensis-delivery-api";

// Remove ": Config" annotation when NOT using TypeScript
const contensisConfig: Config = {
  rootUrl: "https://my-cms.com",
  accessToken: "DELIVERY_API_ACCESS_TOKEN",
  projectId: "website",
  language: "en-GB",
  versionStatus: "published",
};

const loadMovies = async () => {
  const client = Client.create(contensisConfig);
  const movieList = await client.entries.list({
    contentTypeId: "movie",
    pageOptions: { pageIndex: 0, pageSize: 10 },
    order: ["-releaseDate"],
  });
  for (const movie of movieList.items) {
    console.log(movie);
  }
};

loadMovies();
// Using Promises and callbacks

import { Client } from "contensis-delivery-api";

const contensisConfig = {
  rootUrl: "https://my-cms.com",
  accessToken: "DELIVERY_API_ACCESS_TOKEN",
  projectId: "website",
  language: "en-GB",
  versionStatus: "published",
};

function loadMovies() {
  const client = Client.create(contensisConfig);
  client.entries
    .list({
      contentTypeId: "movie",
      pageOptions: { pageIndex: 0, pageSize: 10 },
      order: ["-releaseDate"],
    })
    .then((movieList) => {
      console.log(movieList.items);
    });
}

loadMovies();

For more examples refer to our documentation on contensis.com

Fetch API

This library uses the fetch API and relies on it being available at runtime.

Browser support

In modern browsers fetch is available natively, a polyfill is provided for older browsers.

The build of the library that targets browsers can be found in the bundle folder.

Node.js support

When using this library in Node.js the fetch API is already polyfilled with cross-fetch package (which uses node-fetch when used with a Node.js runtime).

Node.js version 16 introduced experimental support for a native global fetch API and shipped as standard with Node.js versions 18 and 20. The global fetch support in Node.js version 21 and greater is marked as stable.

Use your own fetch

You can override the built-in fetch API by providing your own fetchFn method when creating the Client.

Method calls that require fetch invoked from this client instance will be made using your chosen API.

import { Client } from "contensis-delivery-api";
import enterpriseFetch from "enterprise-fetch";

const client = Client.create({
  rootUrl: "https://my-cms.com",
  accessToken: "DELIVERY_API_ACCESS_TOKEN",
  projectId: "website",
  language: "en-GB",
  versionStatus: "published",
  fetchFn: enterpriseFetch,
});