CSV State Parser
Convert commercetools states CSV data to JSON. See example below for CSV format, sample response and usage.
Usage
npm install @commercetools/csv-parser-state --global
CLI
Info on flags
The
--projectKey
is only required if states have atransitions
field containing one or more states that need to be resolved, otherwise it can be omitted. More info in the Examples belowThe
--input
flag specifies the path to the states CSV file. If this flag is omitted, the module will attempt to read the data from thestandard input
.The
--output
flag specifies where to output/save the parsed states as JSON file. Several notes on this flag:If the file specified already exists, it will be overwritten.
If no output path is specified, the parsed states will be written to the standard output. As a result, status reports will be logged to a
csv-parser-state.log
file in the current directory.
The
--delimiter
flag specifies the delimiter used in the input file. Defaults to','
if omitted.The
--multiValueDelimiter
flag specifies the delimiter for multiValue cells in CSV. Note that only thetransitions
androles
fields if present should contain multiple values. Defaults to';'
if omitted.The
--continueOnProblems
flag specifies if the module should continue parsing states if it encounters an error. Defaults tofalse
if omitted.If the module should continue on error, all errors are logged to the logging location (see above).
If the module should not continue on error, the failing error is written to the
stderr
, regardless of the output and logging locations
JS
For more direct usage, it is possible to use this module directly:
The constructor takes in 2 optional parameters
A configuration object containing any/all of the following values:
apiConfig
(Object):AuthMiddleware
options for authentication on the commercetools platform. (only required if states have atransitions
field containing one or more states that need to be resolved. See here)csvConfig
(Object): A configuration object for describing the CSV file:delimiter
(String): Used delimiter in the CSV (Default:','
)multiValueDelimiter
(String): Used delimiter in multiValue fields in the CSV (Default:';'
)
accessToken
(String): Access token to be used to authenticate requests to API. Requires scope of [view_orders
]continueOnProblems
(Boolean): Option if module should continue on errors (Default:false
)
A logger object having four functions (
info
,warn
,error
anddebug
)
CSV Notes
The CSV transitions in the CSV file should contain the list of state keys that can be transitioned to. This keys should be separated by the supplied multiValueDelimiter
. A valid CSV file with valid transitions using the default multiValueDelimiter
(;
) is given below:
Examples
If we want to parse 3 states from CSV to JSON; with the following as input:
Using the CLI, we could run the following command:
And the following would be written to the JSON file
Last updated