Giter Club home page Giter Club logo

cocart-js-lib's Introduction

CoCart - JavaScript Library

CoCart

๐Ÿด Forked from WooCommerce JavaScript Library and modified to support CoCart REST API instead. Authentication is optional.

JavaScript library for CoCart, supports CommonJS (CJS) and ECMAScript Modules (ESM).

Requests are made with Axios library with support to promises.

build status npm version

โš ๏ธThis library will NOT support the LEGACY API of CoCart.

Installation

npm install --save @cocart/cocart-rest-api

Getting started

Check out the CoCart API endpoints and data that can be manipulated in https://docs.cocart.xyz/.

Setup

ESM example

import CoCartAPI from "@cocart/cocart-rest-api";

const CoCart = new CoCartAPI({
  url: "https://example.com",
});

CJS example

const CoCartAPI = require("@cocart/cocart-rest-api").default;

const CoCart = new CoCartAPI({
  url: "https://example.com",
});

Options

Option Type Required Description
url String yes Your Store URL, example: https://example.com/
consumerKey String no Your API consumer key, username or email address.
consumerSecret String no Your API consumer secret or password.
wpAPIPrefix String no Custom WP REST API URL prefix, used to support custom prefixes created with the rest_url_prefix filter.
version String no API version, default is cocart/v2
encoding String no Encoding, default is 'utf-8'
queryStringAuth Bool no When true and using under HTTPS force Basic Authentication as query string, default is false
port string no Provide support for URLs with ports, eg: 8080
oauth Bool no When true authorize via OAuth 1.0a, default is false
timeout Integer no Define the request timeout
axiosConfig Object no Define the custom Axios config, also override this library options.

Methods

GET

  • .get(endpoint)
  • .get(endpoint, params)
Params Type Description
endpoint String CoCart API endpoint, example: cart or products/32
params Object Query strings params, example: { per_page: 20 }

POST

  • .post(endpoint, data)
  • .post(endpoint, data, params)
Params Type Description
endpoint String CoCart API endpoint, example: cart/add-item or cart/item
data Object JS object to be converted into JSON and sent in the request
params Object Query strings params

PUT

  • .put(endpoint, data)
  • .putt(endpoint, data, params)
Params Type Description
endpoint String CoCart API endpoint, example: cart/item/<item_key>
data Object JS object to be converted into JSON and sent in the request
params Object Query strings params

DELETE

  • .delete(endpoint)
  • .delete(endpoint, params)
Params Type Description
endpoint String CoCart API endpoint, example: cart/item or coupon
params Object Query strings params, example: { force: true }

Bug Reporting

If you think you have found a bug in the library, please open a new issue and I will do my best to help you out.

CoCart Channels

We have different channels at your disposal where you can find information about the CoCart project, discuss it and get involved:

Twitter: cart_co CoCart JS Lib Github Stars

  • ๐Ÿ“– Docs: this is the place to learn how to build amazing sites with CoCart. Get started!
  • ๐Ÿ‘ช Community: use our Slack chat room to share any doubts, feedback and meet great people. This is your place too to share how are you planning to use CoCart!
  • ๐Ÿž GitHub: we use GitHub for bugs and pull requests, doubts are solved with the community.
  • ๐Ÿฆ Social media: a more informal place to interact with CoCart users, reach out to us on Twitter.
  • ๐Ÿ’Œ Newsletter: do you want to receive the latest plugin updates and news? Subscribe here.

I'm not seeing X-COCART-API header returning

If you want this header to return then you need to enable CORS. Simply install CoCart CORS plugin for quick activation.

Changelog

See changelog for details

Credits

CoCart is developed and maintained by Sรฉbastien Dumont.


sebastiendumont.com ย ยทย  GitHub @seb86 ย ยทย  Twitter @sebd86

cocart-js-lib's People

Contributors

renovate-bot avatar seb86 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

cocart-js-lib's Issues

Incorrect request method when Authorizing or not Authorizing

Since updating to 3.0.3 (from 2.x) I can no longer add to cart via a react component (using the @cocart/cocart-rest-api library). I'm suddenly getting a 401 error from the server.

Response is:
{"code":"woocommerce_rest_authentication_missing_parameter","message":"Missing OAuth parameter oauth_consumer_key","data":{"status":401}}

Any ideas? I thought at first it was due to be operating on a local dev server (not https), but the same issue occurs over https as well.

Request (cURL) is along the lines of:

curl 'https://mysite.foo/wp-json/cocart/v2/add-item?oauth_consumer_key=&oauth_nonce=H8zvy7kyYv6Czv395G4ck87ASnwHRnc0&oauth_signature_method=HMAC-SHA256&oauth_timestamp=1621259305&oauth_version=1.0&oauth_signature=Id5SYwKgg8FWXwREMoqsse7ev5N5mZjRbIvzKGqjrJ0%3D' \
  -H 'Connection: keep-alive' \
  -H 'Pragma: no-cache' \
  -H 'Cache-Control: no-cache' \
  -H 'sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="90", "Google Chrome";v="90"' \
  -H 'Accept: application/json' \
  -H 'DNT: 1' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36' \
  -H 'Content-Type: application/json;charset=UTF-8' \
  -H 'Origin: https://mysite.foo' \
  -H 'Sec-Fetch-Site: same-origin' \
  -H 'Sec-Fetch-Mode: cors' \
  -H 'Sec-Fetch-Dest: empty' \
  -H 'Referer: https://mysite.foo/product/teamwear/socks-teamwear/full-length-socks/' \
  -H 'Accept-Language: en-GB,en-US;q=0.9,en;q=0.8' \
  -H 'Cookie: _ga=GA1.3.968707277.1591347534; cookielawinfo-checkbox-non-necessary=yes; cookielawinfo-checkbox-necessary=yes; viewed_cookie_policy=yes; CookieLawInfoConsent=eyJuZWNlc3NhcnkiOnRydWUsIm5vbi1uZWNlc3NhcnkiOnRydWV9; wp-settings-1=libraryContent%3Dbrowse; _fbp=fb.2.1610448280180.1841253780; wp-settings-time-1=1620288912; _gcl_au=1.1.1712335327.1620838761; woocommerce_items_in_cart=1; woocommerce_cart_hash=7cb4c4f4bc7decf39ec9d45b450c50c0; wp_cocart_session_e166e212aa264c65fd64411d789d41b0=1%7C%7C1621861183%7C%7C1621774783%7C%7Ced37fc15784116f6f331d3a1fba9be8a; wordpress_test_cookie=WP+Cookie+check; wordpress_logged_in_e166e212aa264c65fd64411d789d41b0=britweb-mdhtw%7C1621429306%7CIpEHRXRpWT3AWskl7GezkwfbjOBlgjzn1NmDY7i3Z9g%7Cacc2705fd4154f40165ae969ccc2be075bb688bef5f604bd536650863c96c0e9; tk_ai=woo%3ARTLZgaY3TlPi%2Fog01f1y%2FxrV' \
  --data-raw '{"key":"cartkosnw871","product_id":"100593","quantity":"1","variation_id":100608,"variation":{"size":"X-Small"},"cart_item_data":{"order_part_key":"kosnxi6f","addons":[],"playerData":[{"size":"X-Small","values":{}}],"variant_price":13,"variant_size":"X-Small"}}' \
  --compressed

Dependency Dashboard

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

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • Update dependency eslint-plugin-import to v2.27.5
  • Update dependency eslint-plugin-prettier to v4.2.1
  • Update dependency prettier to v2.8.8
  • Update dependency axios to v1
  • Update dependency del-cli to v5
  • Update dependency eslint-plugin-jest to v27
  • Update dependency lint-staged to v13
  • ๐Ÿ” Create all rate-limited PRs at once ๐Ÿ”

Edited/Blocked

These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

npm
package.json
  • axios ^0.26.0
  • create-hmac ^1.1.7
  • oauth-1.0a ^2.2.6
  • url-parse ^1.4.7
  • @babel/cli 7.17.6
  • @babel/core 7.17.9
  • @babel/plugin-transform-modules-commonjs 7.17.9
  • @babel/preset-env 7.16.11
  • babel-jest 27.5.1
  • del-cli 4.0.1
  • eslint 8.14.0
  • eslint-config-prettier 8.3.0
  • eslint-config-standard 16.0.3
  • eslint-plugin-import 2.26.0
  • eslint-plugin-jest 25.2.4
  • eslint-plugin-node 11.1.0
  • eslint-plugin-prettier 4.0.0
  • eslint-plugin-promise 5.2.0
  • eslint-plugin-standard 5.0.0
  • husky 7.0.4
  • jest 27.5.1
  • lint-staged 11.2.6
  • nock 13.2.4
  • prettier 2.6.2
  • node >=8.0.0
travis
.travis.yml
  • node 10
  • node 11
  • node 12
  • node 13
  • node 14
  • node 15

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

ISBAT to use via form data

It has been reported that the JS library does not support making requests via form data. Need to run tests and enhance JS lib.

Prerequisites

  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • I have attempted to find the simplest possible steps to reproduce the issue.
  • I have included a failing test as a pull request (Optional)
  • I have installed the requirements to run this library.

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.

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.