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

@contentchef/contentchef-node

v6.0.0

Published

JavaScript and TypeScript SDK for Content Chef

Downloads

185

Readme

Content Chef Typescript SDK

Content Chef's polymorphic typescript SDK for your web and node.js applications.

Requirements

In order to use this SDK, you will need

  • An active ContentChef account
  • Node.js (v >= 8)

An IDE/TextEditor with support for TypeScript is highly recommended.

Installation

# install it using npm
npm i --save @contentchef/contentchef-node

# or if you use yarn
yarn add @contentchef/contentchef-node

API

ContentChef

ContentChef is the default exported function. It is used to configure the SDK with your data.

example

import ContentChef from '@contentchef/contentchef-node';

const cf = ContentChef({
  spaceId: 'your-space-id'
}, targetDateResolver);

Configuration implements this interface

export default interface ISDKConfiguration {
  /**
   * Content Chef SpaceId to use
   * @type {string}
   * @memberof IContentChefConfiguration
   */
  spaceId: string;  
  /**
   * Content Chef API Endpoint
   * @type {string}
   * @memberof IContentChefConfiguration
   */
  host?: string;
  /**
   * Sets a pending request timeout
   * @type {number}
   * @memberof IContentChefConfiguration
   */
  timeout?: number;
}

targetDateResolver is used to retrieve contents in the preview channel in a specific dare different from the current date a valid targetDateResolver must return a valid date expressed using the ISO format like 2019-08-16T12:22:232Z

if defined must be a string or a TargetDateResolver interface defined as follow:

    export interface ITargetDateResolver {
      getTargetDate(): Promise<string | undefined>;
    }

Bear in mind that apiKey and host are required

Channels

A channel is a collector of contents.

The SDK returns two channels: onlineChannel and a previewChannel.

With the onlineChannel you can retrieve contents which are in live state and which are actually visible, while with the previewChannel you can retrieve contents which are in in both stage and live state and even contents that are not visible in the current date

Both the onlineChannel and the previewChannel returns two methods which are content and search

You can use the content methods to collect a specific content by it's own publicId, to retrieve, for example to retrieve a single post from your blog, a single image from a gallery or a set of articles from your featured articles list. Otherwise you can use the search methods to find content with multiple matching criteria, like content definition name, publishing dates and more.

Example:

import ContentChef, { PublishingStatus } from '@contentchef/contentchef-node'; 

const cf = ContentChef({
  spaceId: 'your-space-id'
}, undefined | 'a target date' | ITargetDateResolver);

// This could be the representation of your data
interface IArticle {
  main_image: {
    transformations: string;
    publicId: string;
  };
  sections: Array<{
    name: string;
    value: {
      body: string;
    };
  }>;
  title: string;
}

// opens for example your website channel, will query only published contents in live state in the current date
const websiteOnlineChannel = cf.onlineChannel('onlineApiKey', 'website');

// will retrieve from the channel website a single content
websiteOnlineChannel.content<IArticle>({ publicId: 'your-content-id' }).then(response => /* handles response */);

// will retrieve the first 10 contents from the channel website with a specific contentDefinition
websiteOnlineChannel.search<IArticle>({
  contentDefinition: 'featured-articles',
  skip: 0,
  take: 10,
}).then(response => /* handles response */);

// opens your website channel and queries only the published content with a staging state
const websitePreviewChannel = cf.previewChannel('previewApiKey', 'website', PublishingStatus.Staging);

// admitted params for content function

interface IGetContentConfig {
  legacyMetadata?: boolean;
  publicId: string;
}


// retrieves a single published content from the channel website with the current date
websitePreviewChannel.content<IArticle>({ publicId: 'your-content-id' }).then(response => /* handles response */);

// admitted params for search function

interface ISearchConfig {
  skip: number;
  take: number;
  publicId?: string[] | string;
  contentDefinition?: string[] | string;
  repositories?: string[];
  legacyMetadata?: boolean;
  tags?: string[] | string;
  propFilters?: IPropFilter;
  sorting?: ISortingField[] | string;
}

// retrieves the first 10 contents from the channel website with a specific contentDefinition in another date
websitePreviewChannel.search<IArticle>({
  contentDefinition: 'featured-articles',
  skip: 0,
  take: 10,
}).then(response => /* handles response */);

// retrieves the first 10 contents with a specific contentDefinition from the channel website for a desired date as specified in the targetDate param
websitePreviewChannel.search<IArticle>({
  contentDefinition: 'featured-articles',
  skip: 0,
  take: 10,
  targetDate: 'a_date_different_from_now',
}).then(response => /* handles response */);

// retrieve the first 10 contents with ascending ordering for publicId
websitePreviewChannel.search<IArticle>({
  skip: 0,
  take: 10,
  sorting: '+publicId',
}).then(response => /* handles response */);

// retrieve the first 10 contents with descending ordering for publicId and ascending ordering for onlineDate, 
websitePreviewChannel.search<IArticle>({
  skip: 0,
  take: 10,
  sorting: '-publicId, +onlineDate',
}).then(response => /* handles response */);