Code Monkey home page Code Monkey logo

client's Introduction

E-Com Plus Client

Publish CodeFactor npm version License MIT

JS client for E-Com Plus REST APIs

CHANGELOG

Usage

TL;DR: We have methods to run requests for almost all E-Com Plus APIs, but you're probably searching for Store API.

The @ecomplus/client package provides a list of methods, each one is a function to request a specific E-Com Plus REST API, using axios HTTP client and returning a Promise.

It's available for both Node.js and browser environments.

Store API request example

import { store } from '@ecomplus/client'

const authenticationId = 'myAuthenticationId'
const accessToken = 'myAccessToken'

ecomClient.store({
  url: '/products.json',
  authenticationId,
  accessToken,
  method: 'post',
  data: { sku: '123', name: 'Sample Prduct 123' }
})
  .then(({ data, status }) => console.log(status, data))
  .catch(error => console.error(error))

Dependencies

It requires and may not include core-js, axios and @ecomplus/utils.

Node.js

npm i --save @ecomplus/utils @ecomplus/client

Webpack

npm i --save core-js @ecomplus/utils @ecomplus/client

CDN

<script src="https://cdn.jsdelivr.net/npm/@ecomplus/client/dist/ecom-client.polyfill.min.js"></script>

axios and ecomUtils libraries must be included separately and available on window scope.

Development

Fork/clone this repository and install dependencies normally:

git clone https://github.com/ecomplus/client
cd client
npm i

Then you can edit source files and test locally with npm run serve.

Contributing

Please read the contribution guidelines.

Deploy

Take a look on package.json scripts:

  • npm run doc - Update jsdoc/docdash generated documentation;
  • npm run release - Generate changelog and new version;

client's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar joao-colen avatar leomp12 avatar renovate[bot] avatar talissonf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

client's Issues

Complete docs examples and unit tests

We haven't jsdoc examples for many methods, all marked with // TODO.
Actually, these examples are intended not only for documentation but also unit tests, so we need them to release v1.

[RFC] Instâncias e emissão de eventos

Proposta

Emitir eventos após cada requisição, retornando o objeto response:

  1. Os eventos de sucesso (resolved) serão emitidos para cada combinação método (cada API) e resource (${api}.${resource});
  2. O nome do evento será equivalente ao método HTTP (lowercase);
  3. Eventos de erro (reject) serão emitidos diretamente no método com o nome error;

Exemplos de uso:

ecomClient.store.products.on('get', ({ data }) => {
  console.log(data.sku) // "S123"
})
ecomClient.store.on('error', response => {
  console.log(response.status) // 400
})

Motivação

  • Facilitar manipulação de dados assíncronos em múltiplos componentes/widgets no storefront;

    • Ex.: um produto carrega, um widget escuta e trata o evento e um adiciona as estrelinhas de review, substituiria o tratamento atual via IntersectionObserver, acredito que seria mais fácil de implementar e mais flexível (todo o body do produto recebido como objeto).
  • Centralizar manipulação de erros e data (um state global ?) no admin;

  • Centralizar com facilidade o debug de requisições com erro server side (Node.js);

O que as instâncias têm a ver com isto?

Segurança: a intenção seria adicionar a possibilidade de criar intâncias de forma parecida com o axios para executar requisições autenticadas, neste caso os eventos são emitidos dentro da própria instância, que deverá ser um objeto privado, fora do escopo global.

Não emitir eventos na instância padrão caso a requisição seja autenticada ?

Outra opção

Uma implementação parecida, com a mesma solução mas talvez mais possibilidades pode ser utilizar RxJS e fornecer observadores em vez de métodos retornando promises. 🤔

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • chore(deps): update all non-major dependencies (@babel/core, @babel/preset-env, core-js)

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

github-actions
.github/workflows/create-release.yml
  • actions/checkout v4
  • actions/create-release v1
.github/workflows/publish.yml
  • actions/checkout v4
  • actions/setup-node v4
  • actions/cache v4
npm
package.json
  • axios ^0.27.2 || ^1.1.2
  • @babel/core ^7.24.0
  • @babel/preset-env ^7.24.0
  • @commitlint/cli ^17.8.1
  • @commitlint/config-conventional ^17.8.1
  • @ecomplus/utils ^1.4.1
  • babel-loader ^8.3.0
  • core-js ^3.36.0
  • docdash ^2.0.2
  • husky ^8.0.3
  • jsdoc ^4.0.2
  • standard ^17.1.0
  • standard-version ^9.3.2
  • webpack ^4.47.0
  • webpack-cli ^3.3.12
  • webpack-dev-server ^3.11.3
  • core-js 3.x
  • @ecomplus/utils 1.x

  • Check this box to trigger a request for Renovate to run again on this repository

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

keep alive on Node env

To improve SSR performance, on Node we should create axios instance by default with options:

httpAgent: new http.Agent({ keepAlive: true }),
httpsAgent: new https.Agent({ keepAlive: true }),

It may be optionally disabled with a new env var.

use https://undici.nodejs.org/#/ ? 🤔

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.