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

banjo-kentico-cloud-delivery-js-sdk

v0.1.0

Published

Fork of Unofficial SDK for the Kentico Cloud Delivery API.

Downloads

2

Readme

Delivery SDK for Javascript

Build status

Notification

This is an unofficial SDK for the Kentico Cloud Delivery API. The SDK is currently under development, it is not fully tested and might change without guarantee of backward compatibility.

About

The purpose of this SDK is to:

  • Deliver complete content for a current view from the Kentico Cloud storage with ease.
  • Simplify the output in order to make it operable for rendering.

All of this happens in a single Promise chain in 3 steps:

  1. Get complete content by calling the getContent method that is able to make multiple requests and return a single response.
  2. Simplify the delivered content by getting only values from the complex response with use of the getValues method.
  3. Process selected raw values to get them ready to be rendered in a view:
    • resolveModularContentInRichText Rich text elements might contain modular content. This method resolves specified modular content item in specified rich text element according to provided template.

Installation

npm install kentico-cloud-delivery-js-sdk

Start

var Delivery = require('kentico-cloud-delivery-js-sdk');

// Initialize SDK with Project ID and Preview API Key
var project = new Delivery('28f9fefa0...88bcda2cbd13', 'ew0KICAiYW...iwNCiAgInR5');

// Step 1: Request multiple Kentico Cloud endpoints in one step and get responses categorized by keys of the passing object
project.getContent({
  home: '?system.type=homepage',
  nav: '?system.type=navigation'
})
// Step 2: Get only values from the response and join modular_content values with appropriate data items
.then(project.getValues)
// Step 3: Process values to get them ready to be rendered in a view  
.then(function (data) {
  data = project.resolveModularContentInRichText(data, 'home', 'name_of_rich_text_field', 'codename_of_modular_item', '<div class="template">{elements.label}</div><span>{system.id}</span>');
  return data;
})
// View results
.then(console.log);

API

Delivery

Initilizes object with its Project ID and Preview API Key that represents a Kentico Cloud project.

Parameters

Examples

var project = new Delivery('82594550-e25c-8219-aee9-677f600bad53', 'ew0KICAiYWxnIjo...QvV8puicXQ');

getContent

Returns promise with data from Kentico Cloud storage specified by params.

Parameters

  • params (object | array) Object or array that contains filtering url parameters that are used for requesting Kentico Cloud storage. Object properties are names for categories. In case array is passed the response must be processed with use of the categorizeContent method. See details about filtering url parameters: https://developer.kenticocloud.com/v1/reference#delivery-api
  • isPreview boolean Flag that controls whether only published or all items should be requested.

Examples

// returns
// {
//   home: {items: [...]},
//   nav: {items: [...]}
// }
project.getContent({
  home: '?system.type=homepage',
  nav: '?system.type=navigation'
}, true)

Returns promise with object of responses for each passed parameter from the Kentico Cloud storage.

categorizeContent

Returns object where each content item is assigned to one category according to their position in given arrays. Number of content items and categories must match.

Parameters

  • content array Content items returned from the "getContent" method.
  • categories array Names of categories.

Examples

// returns {navigation: {items: [...]}, homepage: {items: [...]}}
project.getContent(['?system.type=navigation', '?system.type=homepage'], false)
.then((data) => {
  return project.categorizeContent(data, ['navigation', 'homepage']);
})

Returns object where content items are property values and categories are property names ordered by their position in given arrays.

getValues

Returns values from content items. Covers content types: Text, Rich text, Number, Multiple choice, Date & time, Asset, Modular content, URL slug, Taxonomy and supports localization. For Rich text elements the method covers: Modular content, images and links with value added as "Web URL". For links added as "Content item" the method returns a <a> tag with empty "href" attribute as it is not possible to identify full url from the Kentico Cloud response. Data of a Modular content which is part of a Rich text element is returned as a <script> tag with data in the JSON format inside. The <script> tag is inserted after the <object> tag which represents position of the Modular content in the default Kentico Cloud response.

Parameters

  • content object Categorized content items returned from the "categorizeContent" method.
  • config object Optional. Model that describes values you need to get from the data provided through content parameter. If the config parameter is not present the returned object contains the "system" object for each item and values for each property. It is recommeneded not to use the "config" parameter in most scenarions.

Examples

// Returns
// {
//   homepage: {
//     items: [{
//       system: {
//         id: '...',
//         name: '...'
//       },
//       elements: {
//         page_title: '...',
//         header: '...',
//         logos: [{
//           system: {
//             codename: '...'
//           },
//           elements: {
//             image: ['...'],
//             url: '...'
//           }
//         }]
//       }
//     }
//   }],
//   blog: {
//     items: [{
//       system: {
//         id: '...',
//         name: '...'
//       },
//       elements: {
//         page_title: '...',
//         publish_date: '...',
//         header_image: ['...', '...']
//       }
//     },{
//       system: {
//         id: '...',
//         name: '...'
//       },
//       elements: {
//         page_title: '...',
//         publish_date: '...',
//         header_image: ['...', '...']
//       }
//    }],
//    pagination: {
//      skip: ...,
//      limit: ...,
//      count: ...,
//      next_page: '...'
//    }
// }
project.getContent({
  home: '?system.type=homepage',
  blog: '?system.type=blog_post'
})
.then((data) => {
  return project.getValues(data, {
    home: {
      system: ['id', 'name'],
      elements: ['page_title', 'header', {
        name: 'logos',
        system: ['codename'],
        elements: ['image', 'url']
      }]
    },
    blog: {
      system: ['id', 'name'],
      elements: ['page_title', 'publish_date', 'header_image'],
      pagination: true
    }
  });
});

Returns object with structured content items values.

resolveModularContentInRichText

Returns data containing resolved specified Modular content in specified Rich text element.

Parameters

  • content object Data from the Kentico Cloud storage processed by the getValues methods.
  • categoryName string Name of a category that has been passed the getContent of categorizeContent methods.
  • elementName string Name of field that represents the Rich text element.
  • modularContentCodeName string Code name of a modular item that is inside of the Rich text element.
  • template string Template that gets rendered in the Rich text element. You can render data from the passed content with use of the macros wrapped in { }.

Examples

project.getContent({
  home: '?system.type=homepage',
  blog: '?system.type=blog_post'
})
.then(project.getValues)
.then((data) => {
  data = project.resolveModularContentInRichText(data, 'home', 'rich_content_with_modular_content', 'myCodeName', '<div class="foo">{elements.label}</div><span>{system.id}</span>');
  return data;
});

Returns object content with processed Rich text element.