GB Elements Logic SDK for integrating GroupBy's APIs into a front-end e-commerce application.
To clone this repo with submodules run:
git clone --recursive https://github.com/groupby/elements-logic
or if the repo is already cloned and you want to install submodules only, run:
git submodule update --init
Run the ./scripts/setup.sh script to build all of the Elements-Logic packages.
./scripts/setup.shThe following commands are run in the context of an individual package contained within the Elements-Logic monorepo. The individual packages can be found within the packages/@groupby directory.
To build an individual package, run the following command:
yarn buildTo build an individual package in response to changes within the src directory, run the following command:
yarn devTests are run with Mocha, Chai, and Sinon in Node. Alternatively, browser based testing is also supported and uses the Karma test runner. The following browsers are tested:
- Chrome
To run tests for a specific plugin package, navigate to its directory and use the following commands based on the desired testing flow:
- To run the tests for a specific package once:
yarn test- To run the tests for a specific package and watch the
srcandtestdirectories to rerun the tests after any changes:
yarn tdd- To run the tests in a browser environment once:
yarn test:browser- To run the tests in a browser environment while watching the
srcandtestdirectories for any changes:
yarn tdd:browserTest coverage is also provided using Istanbul.
This project ships with ESLint configuration to enforce a consistent code style across *.ts files.
The following commands are run in the context of an individual package contained within the Elements-Logic monorepo. The individual packages can be found within the packages/@groupby directory.
To lint files for an individual package, navigate to its directory and use one of the following commands.
- To lint the files under the
srcdirectory for an individual package:
yarn lint:scripts- To lint the files under the
testdirectory for an individual package:
yarn lint:testTo run the automated lint fixes for an individual package, navigate to its directory and use one of the following commands.
- To run automated lint fixes on the files under the
srcdirectory for an individual package:
yarn lint:scripts:fix- To run automated lint fixes on the files under the
testdirectory for an individual package:
yarn lint:tests:fixTo lint all the Elements-Logic packages at once, run the following commands at the root of the monorepo:
- To lint all files within each package's
srcdirectory:
yarn lint:scripts- To lint all files within each package's
testdirectory:
yarn lint:tests- To run automated lint fixes on all files within each package's
srcdirectory:
yarn lint:scripts:fix- To run automated lint fixes on all files within each package's
testdirectory:
yarn lint:tests:fixThe following command will generate documentation for each module in the packages directory. It uses TypeDoc and outputs to the docs directory.
yarn docsTo bundle the Elements-Logic packages, run the following command at the root of the monorepo:
yarn bundleThe resulting bundles can be found within the dist directory at the root of the repo.
To use elements-logic in the browser, point to a bundle with a script tag:
<script src="your-elements-logic-bundle"></script>You can now instantiate Core and the plugins. For example:
const core = new GbElementsCore.Core();
const domEventsPlugin = new GbElementsPlugins.DomEventsPlugin()
const saytPlugin = new GbElementsPlugins.SaytPlugin({ subdomain: 'apparel' });
const saytDriverPlugin = new GbElementsPlugins.SaytDriverPlugin();
const searchPlugin = new GbElementsPlugins.SearchPlugin({ customerId: 'apparel' });
const searchDriverPlugin = new GbElementsPlugins.SearchDriverPlugin();
// register all plugins with core
core.register([saytPlugin, saytDriverPlugin, domEventsPlugin, searchPlugin, searchDriverPlugin]);If you are additionally using elements-view, or require the search data to be transformed to be ready for your own views, you should define a productTransformer function that accepts a Record (a product as it is returned from a search), returns a Product (a product in the format needed for elements-view or your own views) and pass it to the saytDriverPlugin and searchDriverPlugin:
function productTransformer(record) {
// ...transform a record/product in some way and return it
return newProduct;
}
const core = new GbElementsCore.Core();
// ...instantiate other plugins
const saytDriverPlugin = new GbElementsPlugins.SaytDriverPlugin({ productTransformer });
const searchDriverPlugin = new GbElementsPlugins.SearchDriverPlugin({ productTransformer });