Code Monkey home page Code Monkey logo

sphere-node-sdk's Introduction

⛔ [Deprecated]

This repo has been deprecated and the code migrated to this repo.

For migration, please follow this guide.

commercetools logo

Node.js SDK

NPM

NPM version Build Status Coverage Status Dependency Status

commercetools is a cloud-based commerce platform.

Officially supported Node.js SDK library for working with the commercetools platform HTTP API, with OAuth2 support.

Getting Started

Install the module with npm install sphere-node-sdk

Documentation

Check out the JSDoc.

The module exposes some libraries which can be either used alone or together

  • SphereClient - a high-level (promise-based) client to connect to the SPHERE.IO HTTP APIs
  • Rest - a low-level (callback-based) client to connect to the SPHERE.IO HTTP APIs
  • *Sync - a collection of utils to build update actions

License

Licensed under the MIT license.

sphere-node-sdk's People

Contributors

adnasa avatar ahmetoz avatar babanila avatar butenkor avatar daern91 avatar emmenko avatar hajoeichler avatar hisabimbola avatar junajan avatar lojzatran avatar mmoelli avatar philippspo avatar renovate-bot avatar renovate[bot] avatar siilwyn avatar svenmueller avatar wizzy25 avatar yanns avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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

sphere-node-sdk's Issues

Redesign request API

  • truncate Rest from OAuth
  • first-level support for streams (both request + response)
  • rethink mechanisms to fetch all pages (e.g.: let promises take care of that?)
  • tiny wrapper around request module

byId(...) call triggers GET request with parameter limit=100

Moin

i'm using the client the get a channel by id client.channels.byId('OrderXmlFileExport'). The result GET request looks like that

https://api.sphere.io/kokon-staging-1/channels/OrderXmlFileExport?limit=100

why do we need a parameter limit when asking for a single resource using byId(...)?

Process function doesn't take care of reducing total results

At the moment the process function just recursively goes through the pages by incrementing the offset on each iteration, assuming the total is fixed.

There are cases though when the processed function changes the data model and influences the total results of the current query.
Some examples:

  • when deleting the resource on each recursion
  • when querying for published products and unpublishing the product on each iteration

To fix that, the process method should always check for changes of total and increment the offset only if the total is the same as before.

page(0) returns the same as page(1)

When fetching something from SPHERE.IO and use page(0) I get the same results as page(1).
Yes, the documentation defines 1 as the default.
It would be very developer friendly when we could throw an exceptions here as most of us start thinking from 0 ;)

Nice query for lastModifiedAt

In many situations it is helpful to get only the changed resource within a specific time frame.
What about this API:

client.customers.last('7d').fetch()
client.inventoryEntries.last('2h').fetch()
client.messages.last('30s').fetch()
  • s for seconds
  • h for hours
  • d for days

We could also add m for month and a for year.

Use logging framework to able to trace/debug client

Would be nice to use a logging fromework where you can change the log configuration to another log level like trace/debug for debugging. This would really help when working with the client to see whats going on (like target url, request/response header, response body etc.).

Timouts when using byId() method for channel resource

I'm trying get get a channel resource using method byId() but the promise is never fullfilled, instead a timeout occurs. The only logged message is "start", so then(), fail(result) or fin() are never called. Any idea why this happens?

console.log "start"
@client.channels.byId(channelId).fetch()
.then(channel) ->
  console.log "then"
.fail(result) ->
  console.log "fail"
.fin ->
  console.log "finally"

i also can see that the underlying request seems to return with status code 404 (might be ok if the channel doesn't exist yet) but the proper fail(result) method is not triggered though (i would expect that).

{
  "name": "sphere-node-client",
  "hostname": "Miami-2.local",
  "pid": 10946,
  "widget_type": "sphere-node-connect",
  "level": 20,
  "request": {
    "type": "REQUEST",
    "uri": {
      "protocol": "https:",
      "slashes": true,
      "auth": null,
      "host": "api.sphere.io",
      "port": 443,
      "hostname": "api.sphere.io",
      "hash": null,
      "search": "?limit=100",
      "query": "limit=100",
      "pathname": "\/kokon-staging-1\/channels\/OrderXmlFileExport",
      "path": "\/kokon-staging-1\/channels\/OrderXmlFileExport?limit=100",
      "href": "https:\/\/api.sphere.io\/kokon-staging-1\/channels\/OrderXmlFileExport?limit=100"
    },
    "method": "GET",
    "headers": {
      "User-Agent": "sphere-node-connect",
      "Authorization": "Bearer ADRjkM3XFtNmp70uAcMXQQcFXYrzjmqf",
      "accept": "application\/json"
    }
  },
  "response": {
    "type": "RESPONSE",
    "status": 404,
    "headers": {
      "server": "nginx",
      "date": "Wed, 02 Apr 2014 13:52:18 GMT",
      "transfer-encoding": "chunked",
      "connection": "keep-alive",
      "x-served-by": "app1.sphere.prod.commercetools.de",
      "x-served-config": "sphere-projects-ws-1.0",
      "access-control-allow-origin": "*",
      "access-control-allow-headers": "Accept, Authorization, Content-Type, Origin",
      "access-control-allow-methods": "GET, POST, DELETE, OPTIONS"
    }
  },
  "msg": "Rest response",
  "time": "2014-04-02T13:52:21.384Z",
  "v": 0
}

Refactor logging + debug

  • use debug module
  • make it "logger-unaware", meaning there are no logger deps (e.g. bunyan, winston) but a logger object is assumed to be given and used like logger.info {foo: 'bar'}, 'This is foo bar' and let the application decide what logger to use

Allow to process in batches

When you have a lot of thousands of resources to process, it's not a good idea to first fetch all elements as it would consume a lot or memory.
Thus, it would be nice to pass a process function that is called for each page resp each element of each page.
What about passing a function into fetch?

Rewrite classes to use composition with mixins

Currently some services don't support all methods inherited from BaseService (e.g.: the messages endpoint is a read-only endpoint).

A service class should be composed by only the pieces it needs and not inherits everything.

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.