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

@chec/commercerays-plugin

v0.0.11

Published

Integrate directly with an editor within the Chec Dashboard - allowing customisation of your project by the merchant

Downloads

12

Readme

Project status

This plugin is currently a work in progress. This code has been made open source as we intend to allow custom themes to be contributed to Commerce Rays, although this is not currently possible. As CommerceRays evolves, this plugin is likely to change significantly

Installation

Use your favourite package manager:

yarn add @chec/commercerays-plugin
# OR
npm install --save @chec/commercerays-plugin

Core concept

CommerceRays are websites that have custom theme configuration provided by an API. This theme configuration is defined by a schema, and can be edited from within the Chec Dashboard (the "editor"). Projects that use this plugin are referred to as "themes", and deployed websites that combine a user-edited configuration and your theme are referred to as "rays". Many different types of configuration are supported by the editor, and are detailed in the Writing your schema section below.

Usage

Currently, NextJS is the only natively supported JS framework.

NextJS

Hooking into getStaticProps

The NextJS integration provided by this plugin is intended for use with NextJS pages. The plugin will hook into getStaticProps and ensures that relevant data is fetched on the server side. You may either use createGetStaticProps to generate a getStaticProps function, or use the provided augmentStaticProps function

pages/index.js:

import { createGetStaticProps } from '@chec/commercerays-plugin/nextjs';
import schema from './schema.json';

const getStaticProps = createGetStaticProps(schema);
export getStaticProps;

or

import { augmentStaticProps } from '@chec/commercerays-plugin/nextjs';
import schema from './schema.json';

export function getStaticProps() {
  // Custom code...
  
  return augmentStaticProps(schema)({
    // Usual return value of getStaticProps goes here
  })
}

Applying the CommerceRay context

Next, you need to apply the CommerceRays React context to your page component. This is provided as a HOC as it relies on props provided by getStaticProps:

pages/index.js:

import { withCommerceRays } from '@chec/commercerays-plugin/nextjs';

// Imported theme schema and theme defaults
import schema from './schema.json';
import defaultConfig from './defaults.json';

function IndexPage() {
  return (
    <>
      <Head>
        <title>My page</title>
      </Head>
      Hello world
    </>
  );
}

// You may also provide any default values for your schema here 
export default withCommerceRays(schema, defaultConfig)(IndexPage);

Accessing configuration values

As the user chooses values for your theme configuration (or the defaults should be used as a fallback) you will need to access them to alter the look of the page. A React hook is provided for this, which can be used in any React component that is a child of the page that you applied the withCommerceRays HOC to:

import { useCommerceRay } from '@chec/commercerays-plugin/nextjs'

export function MyComponent() {
  const { myConfigurationProperty } = useCommerceRay();
  
  // ...
}

Writing your schema

// TODO