Code Monkey home page Code Monkey logo

sphere-node-cli's Introduction

commercetools logo

Node.js CLI

npm Travis Build Status Codecov Coverage Status David Dependencies Status David devDependencies Status

The next generation Command-Line-Interface for SPHERE.IO.

Table of Contents

Features

  • import of stock, product, price, category, discount, order, customer, productType, discountCode, state, customObject
  • Docker support
  • Custom plugin

Requirements

Make sure you have installed all of the following prerequisites on your development machine:

  • Git - Download & Install Git. MacOS and Linux machines typically have this already installed.
  • Node.js - Download & Install Node.js and the npm package manager. Make sure to get the latest active LTS version. You could also use a Node.js version manager such as n or nvm.

If you were using the old ruby CLI make sure to uninstall it first.

Usage

$ npm install -g sphere-node-cli

# show general help
$ sphere -h

# show help for a command (e.g.: import)
$ sphere help <cmd>

The CLI is still under development but already provides a bunch of commands.
The idea behind it is to operate as a proxy for the different libraries that are used underneath. For example the import command will stream chunks from a given JSON file and pass them to the related library that will handled the rest.

Credentials

The CLI has a lookup mechanism to load SPHERE.IO project credentials.
If you specify a -p, --project option, the CLI will try to load the credentials for that project from the following locations:

./.sphere-project-credentials
./.sphere-project-credentials.json
~/.sphere-project-credentials
~/.sphere-project-credentials.json
/etc/sphere-project-credentials
/etc/sphere-project-credentials.json

There are 2 supported formats: csv and json.

  • csv: project_key:client_id:client_secret
  • json: { "project_key": { "client_id": "", "client_secret": "" } }

If no -p, --project option is provided, the CLI tries to read the credentials from ENV variables:

export SPHERE_PROJECT_KEY=""
export SPHERE_CLIENT_ID=""
export SPHERE_CLIENT_SECRET=""

Docker

Docker build

You need to have a working docker client! The Docker Toolbox is an installer to quickly and easily install and setup a Docker environment on your computer. Available for both Windows and Mac, the Toolbox installs Docker Client, Machine, Compose, Kitematic and VirtualBox.

Examples

Show help

docker run \
sphereio/sphere-node-cli -h

Import a product (host folder /sample_dir/ mounted as docker volume)

docker run \
-e SPHERE_PROJECT_KEY=<KEY>
-e SPHERE_CLIENT_ID=<ID>
-e SPHERE_CLIENT_SECRET=<SECRET>
-v /sample_dir/:/sample_dir/ \
sphereio/sphere-node-cli
import -p my-project-key -t product -f /sample_dir/products.json'

You can also set an alias for repeated calls:

alias sphere='docker run \
-v /etc/sphere-project-credentials.json:/etc/sphere-project-credentials.json \
sphereio/sphere-node-cli'

Commands

The CLI has git-like sub-commands which can be invoked as sphere <cmd>.

Current available commands:

  • import (stock, product, price, category, discount, order, customer, productType, discountCode, state, customObject)

Commands expects at least a -t, --type option which may vary for each command.

sphere-import

Imports a resource type by streaming the input JSON file.

$ sphere import -p my-project-key -t product \
  -f sample_dir/products.json \
  -c '{"errorDir": "./productErrors"}'

The input must be a valid JSON following a specific schema (import-type-key is the plural form of the type option, e.g.: products, stocks, etc.).

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "title": "SPHERE.IO CLI import schema",
  "type": "object",
  "properties": {
    "<import-type-key>": {
      "type": "array",
      "items": {
        "$ref": "https://github.com/sphereio/sphere-json-schemas/tree/master/schema"
      }
    }
  },
  "additionalProperties": false,
  "required": ["<import-type-key>"]
}

If you don't provide a file to read from, the CLI listens from stdin so you can i.e. pipe in something.

Each import type might have / expect some extra specific configuration. In that case you have to refer to the related documentation.

Contributing

See Contribution guidelines

sphere-node-cli's People

Contributors

ct-szilvia avatar daern91 avatar emmenko avatar hajoeichler avatar hisabimbola avatar junajan avatar philippspo avatar renovate-bot avatar renovate[bot] avatar siilwyn avatar stremlenye avatar svenmueller avatar wizzy25 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sphere-node-cli's Issues

Module does not work

Description

The module does not work again. Getting error when trying to run the tool.

Expected Behavior

Should work flawlessly

Current Behavior

running sphere throw this error

TypeError: cmd is not a constructor

Context

Possible Solution

Most likely issue is with the way Babel exports module. Using module.export should fix it.

product update fails if product is in a category

If I try to import a json file to update a product which is already in a category I get following error message:

error: Skipping product due to error message: Cannot add to category '7bcad580-c785-4b29-9f72-960436ccc186' because the product 'LocalizedString(Map(en -> Vest))' is already in that category.

I try to update simple fields like name, description etc... informations which will be transformed from csv to a json by the product transformer.
We are not updating categories, so it can't be a problem.

So not sure why it can't import products which has already categories.

If you need more informations, please let me know.
Many thanks & regards,
Szilvia

.error: Skipping product due to error message: New product name must not be empty or equal to the old name.

Hi,

well... ive got 5 data sources to build the json for a product import actually and it does not look like its getting less.

So I just tried to update my aggregated product import json with a new product title as the customer has new titles in another database I have to use. So i connected it, updated my json with the new field and... hoped I could just import my new json by this CLI.

its not using the update action actually, isn't it? Do I have to write my own update-process for updating product titles actually or is there a way with this CLI?

Thanks for Feedback.

BR
Emtii

CLI should accept CTP host url

Description

The CLI currently doesn't accept host url, meaning that all usage will default to sphere.io in each module.
This is not good for other regions

Expected Behavior

Should accept a host url param

Current Behavior

Context

Possible Solution

node SDK should hand down 414 errors

right now the Node SDK produces a 500 error if server returns a 414 - request URL too long. It should produce a better error message or hand down the 414

payload -t stock

Hi,

currently I face some issues with the payload for stock. This is what I generate:

{
    "stocks": [
        {
            "sku": "4001513102164",
            "quantity": 85
        },
        {
            "sku": "4001513102423",
            "quantity": 28
        }
    ]
}

What is wrong with that? Getting:

.Unhandled rejection BadRequest: Request body does not contain valid JSON.

Simple implementation of stock export

$ sphere export --type stock --to out.json

# without a target, it will print to stdout, allowing to pipe it
$ sphere export --type stock > out.json

Allow CLI to accepts accessToken

Description

The CLI only accepts credentials but it should accept accessTokens also if available

Expected Behavior

Should accepts either tokens or credentials

Current Behavior

Does not accept API access tokens

Context

Blocking for an issue on impex

Possible Solution

Add another parameter in the CLI to accept accessTokens and pass it to the SDK

rebrand before it has wide adoption

Hi,

as this new CLI is not yet widely used outside the company that is a chance to change the SPHERE branding. Once it's in wide use we're stuck again. Now that commercetools is getting more consitent, the remaining sphere monikers are really starting to create confusion with users. I start to get asked, what the "sphere" thing is more and more since ca. one month.

we bit the bullet in the PHP SDK and it turned out to be not as bad as expected once we took the heart to really and fully do it.

provide example payload for product creation

Could you please provide an example payload for using sphere-import to create new products? Including nested attributes, please.

Additionally, could you please extend your manpage with available types to choose from for import?

-t, --type type of import

Fetch command

  • specify resource via --type option
  • specify query params via --query option (either JSON string or file)
{
  "where": "id = \"foo\"",
  "sort": "id asc"
}

Remove github vulneribility warnings

Remove github vulneribility warnings

current direct dependencies has some github vulnerability because of the Transitive dependencies. So we need to update below packages.

  • codecov update to 3.6.5
  • acorn update to 6.4.1
  • csv-parse update to 4.4.6
  • minimist update to 0.2.1
  • https-proxy-agent update to 2.2.3

sphere-import doesn't exit with code 1 when it fails

Description

sphere-import -t order -p $SPHERE_PROJECT_KEY -f $jsonFile

Expected Behavior

exit with code 1 (or any non-zero) as the order does not exist!

Current Behavior

info:    {
  "errors": [
    {
      "order": {
        "orderNumber": "B-258-254-111",
        "lineItems": [
          {
            "id": "da9e02c4-7937-49c6-afbb-6da2601e43dd",
            "state": [
              {
                "quantity": 1,
                "fromState": "exported",
                "toState": "open"
              }
            ]
          }
        ]
      },
      "error": {
        "code": "ENOENT",
        "name": "Error",
        "message": "Order with orderNumber B-258-254-111 not found.",
        "stack": "Error: Order with orderNumber B-258-254-111 not found.\n    at /usr/local/lib/node_modules/sphere-node-cli/node_modules/@commercetools/orders-update/dist/orders-update.js:166:45\n    at tryCatcher (/usr/local/lib/node_modules/sphere-node-cli/node_modules/bluebird/js/release/util.js:16:23)\n    at Promise._settlePromiseFromHandler (/usr/local/lib/node_modules/sphere-node-cli/node_modules/bluebird/js/release/promise.js:510:31)\n    at Promise._settlePromise (/usr/local/lib/node_modules/sphere-node-cli/node_modules/bluebird/js/release/promise.js:567:18)\n    at Promise._settlePromise0 (/usr/local/lib/node_modules/sphere-node-cli/node_modules/bluebird/js/release/promise.js:612:10)\n    at Promise._settlePromises (/usr/local/lib/node_modules/sphere-node-cli/node_modules/bluebird/js/release/promise.js:691:18)\n    at Async._drainQueue (/usr/local/lib/node_modules/sphere-node-cli/node_modules/bluebird/js/release/async.js:133:16)\n    at Async._drainQueues (/usr/local/lib/node_modules/sphere-node-cli/node_modules/bluebird/js/release/async.js:143:10)\n    at Immediate.Async.drainQueues (/usr/local/lib/node_modules/sphere-node-cli/node_modules/bluebird/js/release/async.js:17:14)\n    at runCallback (timers.js:649:20)\n    at tryOnImmediate (timers.js:622:5)\n    at processImmediate [as _immediateCallback] (timers.js:594:5)"
      }
    }
  ],
  "inserted": [],
  "successfullImports": 0
}

RETURN CODE: 0

Context

There is no way to find if the command succeeded or failed!

Possible Solution

The main module should exit with a non-zero code when a sub-module fails.

bulk delete for product types

Hi,

when modeling product data within product types and adding A LOT of types to dev projects I would love to be able to delete types easily when we are in development process.

BR
Emtii

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.