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

jj-npm-ocapi

v1.4.0

Published

NPM package to facilitate info retrieval from the Open Commerce DMW API

Downloads

3

Readme

jj-npm-ocapi

Simple product info retrieval via OCAPI

Installation

For Node / Browserify

$ npm install jj-npm-ocapi

API

getInfo (clientID, language, styles, [wantImages: false, wantPrices: false, wantLinks: false])

Returns a promise. When resolved, it's data will consist of an object containing the information parsed from an OCAPI request, modeled as in the example below.

  • clientID (String) OCAPI public key for the chosen instance, with appropriate access to /shop/products endpoints
  • language (String) Code of country to ping against (relevant when requesting prices)
  • styles (String[]) Array of style IDs or style option IDs
  • wantImages (Boolean) Optional. Whether or not you want to retrieve image links. Defaults to false
  • wantPrices (Boolean) Optional. Wether or not you want to retrieve prices formatted dor the chosen language. Defaults to false
  • wantLinks (Boolean) Optional. Wether or not you want to retrieve links for all markets, or just the generic one. Defaults to false

getOcapiUrl (clientID, language, stylesString, [wantImages: false, wantPrices: false])

Returns a String (the OCAPI URL to request, if you plan on doing yourself more advanced parsing of the response).

  • clientID (String) OCAPI public key for the chosen instance, with appropriate access to /shop/products endpoints
  • language (String) Code of country to ping against (relevant when requesting prices)
  • styles (String) Array of style IDs or style option IDs
  • wantImages (Boolean) Optional. Whether or not you want to retrieve image links. Defaults to false
  • wantPrices (Boolean) Optional. Wether or not you want to retrieve prices formatted dor the chosen language. Defaults to false

Example: Requesting images and prices of a style

var ocapi = require('jj-npm-ocapi');

ocapi.getInfo(
	clientID,
	'DK',								                // locale
	['12103726_Anthracite',12109802,'TSD10066863'],	    // array of style IDs/style option IDs
	true,								                // images
	true								                // prices
).then( function(json) {
	// execute once info is retrieved
	console.log(json)
})

Example of the return object (TSD10066863 is an invalid/out of stock style)

{
    '12109802': {
    	name: 'MONOKROM SWEATSHIRT',
        link: 'http://jackjones.com/12109802.html?',
        price: 179.95,
        formattedPrice: '179,95 DKK',
        images: {
            '12109802_Black_519727': 'http://shop.bestseller.com/on/demandware.static/-/Sites-pim-catalog/default/dw9be8265e/pim-static/large/12109802_Black_519727_001_ProductLarge.jpg',
            '12109802_ForestNight_519727': 'http://shop.bestseller.com/on/demandware.static/-/Sites-pim-catalog/default/dw9be8265e/pim-static/large/12109802_ForestNight_519727_001_ProductLarge.jpg'
        }
    },
    '12103726_Anthracite': {
    	name: 'LET SNEAKERS',
        link: 'http://jackjones.com/12103726.html?dwvar_colorPattern=12103726_Anthracite',
        price: 499.95,
        formattedPrice: '499,95 DKK',
        images: {
            '12103726_Anthracite': 'http://shop.bestseller.com/on/demandware.static/-/Sites-pim-catalog/default/dw9be8265e/pim-static/large/12103726_Anthracite_001_ProductLarge.jpg'
        }
    },
    TSD10066863: false
}

Example: Requesting just the OCAPI URL

var ocapi = require('jj-npm-ocapi');

console.log(
	ocapi.getOcapiUrl(
		clientID,
		'DK',								                // locale
		['12103726_Anthracite',12109802,'TSD10066863'],		// array of style IDs/style option IDs
		true,								                // images
		true								                // prices
	)
)
http://shop.bestseller.com/s/BSE-DK/dw/shop/v15_4/products/(12103726,12109802)?client_id=xxxxxxxxxxxxxxxxxxx&expand=images,prices&currency=DKK

Notes

  • Out of stock styles are not retrievable. Querying them will return a false, like in the example above.
  • If you request a style ID, images for all of its varaitions will be returned, indexed by style option ID.
  • For clientside scripting, install the package via npm install jj-npm-ocapi, require it in your scripts as in the examples above, bundle it among all other dependencies with eg. browserify main.js -o bundle.js

License

MIT

Repo changelog

1.4.0

  • Bingified module

1.3.6

  • Added product links to returned object

1.3.5

  • Turned into isomorphic package

1.2.X

  • We don't speak of 1.2.X

1.2.1

  • Styles not found / out of stock return a false

1.2.0

  • Added product name to return obj