Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@chec/commercerays-plugin

Package Overview
Dependencies
Maintainers
6
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@chec/commercerays-plugin

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

  • 0.0.11
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-90%
Maintainers
6
Weekly downloads
 
Created
Source

CommerceRays plugin

An SDK for interfacing with the Commerce Ray dashboard to create rays that can be live edited and deployed with custom configuration

Version Downloads/week License
commercejs.com | @commercejs | Slack

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

FAQs

Package last updated on 04 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc