npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sylius-shop-api-client

v1.0.2

Published

Sylius Shop API JS Client

Downloads

5

Readme

Sylius Shop API Client

npm npm npm

Implement Sylius Shop API Client into your app in just One Step!

  • Easy to configure API client for quick use
  • All API Plugin endpoints are supported!
  • Very simple way to add custom endpoints.
  • Well-Organized and scalable project.
  • All query params, paths and bodies are documented within the code using jsDoc.

Instalation

npm i sylius-shop-api-client - OR - yarn add sylius-shop-api-client

Usage

API_Client

import { API_Client } from "sylius-shop-api-client"

// Configuration

// Initialize API BaseURL ( Required ) Don't forget trailing /
API_Client.baseURL = "https://my.web.site/api/"


// Set / Clear API Cart Identifier (token), used in all cart requests.

// After Picking Cart => Set token
API_Client.cartToken = "xxxxxxxxxxxxxxx"

// After Dropping Cart => Clear token
API_Client.cartToken = ""


// Set API Locale
API_Client.locale = "en_US"


// Set API default pagination limit
API_Client.limit = "10"


// Set API Default Headers ( Optional ), below values are already defaults.
const myDefaultHeaders = {
  "Accept": "application/json",
  "Content-Type": "application/json",
}
API_Client.defaultHeaders = myDefaultHeaders



// Append New Header (name, value) pair, Any where in your code,
API_Client.appendHeader("Authorization", "Bearer xxxxx")

// Remove header from default headers, Any where in your code,
API_Client.removeHeader("Authorization")


// Set onResponseStatus handler,
// to invoke your custom functions in certain response status codes
API_Client.onResponseStatus = (status) => {

  switch(status){

    case 403:
      // Do something, etc Clear UserData, Remove Auth Headers
      break

    case 500:
      // Do something else
      break

    default:
      // Unhandled cases
      console.log("Unhandled case for status ", status)

  }
}

ShopAPI

import { ShopAPI } from "sylius-shop-api-client"


// Async / Await approach
async loadTaxons() {
  
  try {

    const taxons = await ShopAPI.taxons.show_tree()

    // then use taxon constant

  } catch (error) {

    // handle errors

  }

}

// Callbacks approach
ShopAPI.taxons.show_tree().then((response) => {

// handle response

}).catch((error) => {

  // handle errors

})


Cart ShopAPI.cart

|Method|Status| |---|---| |ShopAPI.cart.pick|✅| |ShopAPI.cart.show|✅| |ShopAPI.cart.drop|✅| |ShopAPI.cart.add|✅| |ShopAPI.cart.add_multiple|✅| |ShopAPI.cart.change_quantitiy|✅| |ShopAPI.cart.remove_item|✅| |ShopAPI.cart.shipping_cost|✅| |ShopAPI.cart.add_coupon|✅| |ShopAPI.cart.remove_coupon|✅|

Products ShopAPI.products

|Method|Status| |---|---| |ShopAPI.products.by_slug|✅| |ShopAPI.products.by_code|✅| |ShopAPI.products.by_taxon_slug|✅| |ShopAPI.products.by_taxon_code|✅| |ShopAPI.products.reviews_by_slug|✅| |ShopAPI.products.reviews_by_code|✅| |ShopAPI.products.add_review_by_slug|✅| |ShopAPI.products.add_review_by_code|✅| |ShopAPI.products.latest|✅|

Taxons ShopAPI.taxon

|Method|Status| |---|---| |ShopAPI.taxons.show_tree|✅| |ShopAPI.taxons.show_subtree|✅|

Checkout ShopAPI.checkout

|Method|Status| |---|---| |ShopAPI.checkout.summary|✅| |ShopAPI.checkout.address|✅| |ShopAPI.checkout.get_shipping_methods|✅| |ShopAPI.checkout.set_shipping_method|✅| |ShopAPI.checkout.get_payment_methods|✅| |ShopAPI.checkout.set_payment_method|✅| |ShopAPI.checkout.complete|✅|

Orders ShopAPI.orders

|Method|Status| |---|---| |ShopAPI.orders.list_orders|✅| |ShopAPI.orders.order_details|✅|

User ShopAPI.user

|Method|Status| |---|---| |ShopAPI.user.request_reset_password|✅| |ShopAPI.user.password_reset|✅| |ShopAPI.user.register|✅| |ShopAPI.user.login|✅| |ShopAPI.user.verify_account|✅| |ShopAPI.user.me|✅| |ShopAPI.user.update_me|✅| |ShopAPI.user.change_password|✅|

Addresses ShopAPI.addresses

|Method|Status| |---|---| |ShopAPI.addresses.list|✅| |ShopAPI.addresses.create|✅| |ShopAPI.addresses.update|✅| |ShopAPI.addresses.delete|✅| |ShopAPI.addresses.set_default|✅|


Custom Endpoint Extending

import { ShopAPI, API_Client } from "sylius-shop-api-client"

const MyShopAPI = {

  // Spread defaults endpoints
  ...ShopAPI,


  // Create your own enpoints using API_client.

  // Get Method, without query params
  myEndpoint: () => API_Client.get("endpoint"),

  // Get Method, query params object (will be converted to string)
  myEndpointCallMethod: (params) => API_Client.get("endpoint", params),

  // Get Method, with changable path and params
  myEndpointPathMethod: (path, params) => API_Client.get(`endpoint/${path}`, params),

  // Post Method, body object (will be stringified inside)
  myEndpointPostMethod: (body) => API_Client.post("endpoint", body),

  // And so on, for put, patch and delete 
  
  

}

// Then use it anywhere in your code,

// Async / Await approach
async loadMyData() {
  
  try {

    const data = await MyShopAPI.myEndpoint()

    // then use data constant

  } catch (error) {

    // handle errors

  }

}

// Callbacks approach
MyShopAPI.myEndpoint().then((response) => {

// handle response

}).catch((error) => {

  // handle errors

})