Commerce Layer Seeder
A Node JS library that lets you import predefines seed data into a Commerce Layer organization.
What is Commerce Layer?
Commerce Layer is a headless platform that lets you easily build enterprise-grade ecommerce into any website, by using the language, CMS, and tools you already master and love.
Table of contents
How it works
This seeder is the easiest way to bulk import a set of products, the related prices, and inventory — based on one of the available business models — into your organization and start using Commerce Layer right away.
This seeder is built for Node.js and doesn't run in the browser.
Getting Started
To be ready to use the Commerce Layer Seeder, you need to install it and then get the credentials that will allow you to manage your organization in Commerce Layer.
Installation
Commerce Layer Seeder is available as an npm package:
// npm
npm install @commercelayer/commercelayer-seeder
// yarn
yarn add @commercelayer/commercelayer-seeder
Import
You can use the ES6 default import as follows:
import seeder from '@commercelayer/commercelayer-seeder'
Usage
The seeder function
The seeder
function returns a promise and you need to pass to it as a parameter an object containing:
-
clientId: string
— your Commerce Layer application client ID (required) -
clientSecret: string
— your Commerce Layer application client secret (required) -
endpoint: string
— your Commerce Layer organization endpoint (required) -
businessModel: string
— the kind of business model you want to import (required / choose among this list) -
maxItems: number
— the maximum number of SKUs that will be imported (optional / default: all) -
resourcesUrl: string
— the resources URL or local path (optional / default: our seeds directory) -
infoLog: boolean
- view the information log during the process (optional / default: true)
// default import — all the products, with related prices and inventory
seeder({
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
endpoint: 'https://yourdomain.commercelayer.io',
businessModel: 'multi_market'
}).then((result) => {
console.log(result)
})
// custom import — 50 SKUs, local path, with related prices and inventory
seeder({
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
endpoint: 'https://yourdomain.commercelayer.io',
businessModel: 'custom',
resourcesUrl: 'your-local-resources-directory'
maxItems: 50,
}).then((result) => {
console.log(result)
})
The returned object
The promise returned by the seeder
function is an array of objects, containing the full list the items imported, by ID:
[
{'address_1': 'byPVuGvQAW'},
// ...
{ merchant_1: 'eMBwVHdKmn' },
// ...
{ stock_location_1: 'gnWomumDNn' },
{ stock_location_2: 'vMQwjuwrbG' },
// ...
{ inventory_model_1: 'KaozeSXKdZ' },
{ inventory_model_2: 'kLpovSAjMW' },
// ...
{ inventory_stock_location_1: 'VWRmvInEve' },
{ inventory_stock_location_2: 'lkVMVIlXbW' },
// ...
{ price_list_1: 'zBMxECjbOL' },
{ price_list_2: 'AkebyCEWRl' },
// ...
{ market_1: 'wjvKBhQGag' },
{ market_2: 'YoPmehRpdj' },
{ market_3: 'EjDkXhMZao' },
// ...
{ shipping_category_1: 'ywpRoFraeK' },
// ...
{ shipping_zone_1: 'BOEwrtpzwv' },
// ...
{ shipping_method_1: 'XVzWbFkkrE' },
{ shipping_method_2: 'qOWbjFLnZE' },
// ...
{'SKUCODE0001XXXX': 'zBMxECjbOL'},
{'SKUCODE0002XXXX': 'cBKdCEgObJ'},
{'SKUCODE0003XXXX': 'rVDxESjeKG'},
// ...
{ price_1: 'BqkxSEzLDZ' },
{ price_2: 'WGDMSkgaAB' },
{ price_3: 'BwpOSbaKAn' },
// ...
{ stock_item_1: 'nOpOSvyGgZ' },
{ stock_item_2: 'nzPQSGebpW' },
{ stock_item_3: 'ZrxeSRlqbB' },
// ...
]
Available business models
Commerce Layer provides a set of predefined business models so that you can choose and import your stater one based on your needs and business requirements. These are the business models available at the moment (more to come):
-
Multi-market —
businessModel: 'multi_market'
- Custom —
businessModel: 'custom'
License
This repository is published under the MIT license.