Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

customer-js-sdk

Package Overview
Dependencies
Maintainers
1
Versions
98
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

customer-js-sdk

Customer JS SDK main repo.

  • 1.73.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

customer-js-sdk

The customer-js-sdk is a Front-End layer of abstraction for communicating with Back-End services.

Install

npm install --save customer-js-sdk

Import

import { v0 as sdk } from 'customer-js-sdk';

BaseUrl

  • Setting the baseUrl
sdk.baseUrl.set('http://custom.api/');

Headers

  • Setting a header
sdk.headers.append('Content-Type', 'application/json');
  • Retrieving all headers
sdk.headers.get();
  • Removing a header
sdk.headers.remove('Content-Type');

Usage Examples

  • GET request without parameters
sdk.merchants.partners.get();
  • GET request with URL parameter
sdk.merchants.addresses.get({
  urlParam: '123456789'
});
  • POST request with body
sdk.merchants.contacts.post({}, {
  body: '123456789'
});
  • POST request with URL parameter and body
sdk.merchants.contacts.post({
  urlParam: '123456789'
}, {
  body: '123456789'
});
  • Passing a custom baseUrl to overide the default in a specific request
sdk.merchants.partners.get('https://custom.api/');

sdk.merchants.addresses.get('https://custom.api/', {
  urlParam: '123456789'
});

sdk.merchants.contacts.post('https://custom.api/', {
  urlParam: '123456789'
}, {
  body: '123456789'
});

Using Middlewares

Middlewares run before and after every request in the same order that they were declared. Every middleware must call either proceed or quit in order to work.

sdk.middleware.use({
  beforeRequest({ proceed, quit }) {
    if (conditionMet) {
      proceed();
    } else {
      quit();
    }
  },
  afterRequest({ proceed }) {
    logSomething();
    proceed();
  }
});

sdk.middleware.use({
  async beforeRequest({ proceed }) {
    await doSomethingAsync();
    proceed();
  }
});

See more information on our Wiki page.

FAQs

Package last updated on 01 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc