2.5.2 • Published 7 days ago

@cboyke/demotools v2.5.2

Weekly downloads
7
License
ISC
Repository
github
Last release
7 days ago

demotools

Tools to aid in the process of building demos, scripts, etc. for commercetools.
The Primary focus is on transforming product catalog data and importing into the commercetools platform for standing up demos quickly

Components

commercetools.js

Encapsulation of the "standard" apiRoot

Place the commercetools connection parameters in a file named .env in a folder adjacent to your calling script.

getAll -- Issue a query that will potentially return large amounts of data

Pass: endpoint, queryArgs Return: an array of results.


transform.js

Data mapping / transformation utils. The heart of this module is the mapFields function, which takes an array of mappers as an argument. A mapper describes mapping of one source field to one (or more) destination fields.

A Mapper has (up to) four fields:

  • src: The name of the field in the source object
  • dest: The name of the field in the destination object
  • convert: (optional) - a conversion operation to perform. One of: slug, category, price, number, boolean, image, list, newline-list

  • type: (optional) - the data type of the destination field. One of: attr, array

Examples:

{
  src: 'ProductID',
  dest: 'key',
}

The field ProductID in the source object will be mapped to the field key in the destination object -- no transformations performed (straight copy)

Price

Convert a Price:

{
  src: 'SalePrice',
  dest: 'prices',
  convert: 'price'
}

Localized Fields:

{
  src: 'ProductName',
  dest: 'name',
  locale: 'en-US'
}

In this case, ProductName in the source will map to a localized field name in the destination, in a structure used by commercetools localized fields.

Attributes

{
  src: 'Department',
  dest: 'department',
  type: 'attr'
}

The source field Department will be copied to an attribute called department in an attributes array of the destination object

Category (reference by key)

Use both a 'convert' (to convert to a reference to a category), and a 'type' (array)

{
  src: 'CategoryID',
  dest: 'categories',
  convert: 'category',
  type: 'array'
}

Images

Convert to an (external) image format

{
  src: 'MainImageURL',
  dest: 'images',
  convert: 'image',
  type: 'array'
}

files.js

readCSV, writeCSV, readJSON, writeJSON, inspect

TODO: document these


Linking locally

If developing locally, do 'yarn link' in this directory, then 'yarn link @cboyke/demotools' in the dependent folder.

2.5.2

7 days ago

2.5.1

19 days ago

2.5.0

22 days ago

2.4.1

5 months ago

2.4.0

5 months ago

2.4.2

5 months ago

2.3.2

10 months ago

2.3.3

9 months ago

2.3.0

1 year ago

2.3.1

1 year ago

2.2.1

1 year ago

2.2.0

2 years ago

2.2.3

1 year ago

2.2.2

1 year ago

2.1.2

2 years ago

2.1.1

2 years ago

2.1.0

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.1.6

2 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago