From 6674d97a269cef24e0424cdff90c8fb3b3626f28 Mon Sep 17 00:00:00 2001 From: Ben Chypak Date: Wed, 20 Jun 2018 14:43:24 -0700 Subject: [PATCH 1/5] Fix usage to attachCookies and saveCookies to use their updated method name --- CHANGELOG.md | 3 +++ src/ApiClient.js | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 515b7be..0c34ab1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## To be released +- Fix attaching/saving cookies to superagent + ## v0.1.3 (May 9, 2018) - Ensure we are shipping ES5 everywhere. diff --git a/src/ApiClient.js b/src/ApiClient.js index b670753..0ec6ab7 100644 --- a/src/ApiClient.js +++ b/src/ApiClient.js @@ -470,7 +470,7 @@ export default class ApiClient { // Attach previously saved cookies, if enabled if (this.enableCookies) { if (typeof window === 'undefined') { - this.agent.attachCookies(request) + this.agent._attachCookies(request) } else { request.withCredentials() } @@ -493,7 +493,7 @@ export default class ApiClient { try { const data = this.deserialize(response, returnType) if (this.enableCookies && typeof window === 'undefined') { - this.agent.saveCookies(response) + this.agent._saveCookies(response) } resolve({ From d785b1e039b53feb347677f282ffe8bfa495aa8f Mon Sep 17 00:00:00 2001 From: Ben Chypak Date: Wed, 20 Jun 2018 14:49:45 -0700 Subject: [PATCH 2/5] Update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c34ab1..ca1c555 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ ## To be released -- Fix attaching/saving cookies to superagent +- Fix superagent `attachCookies` and `saveCookies` usage ## v0.1.3 (May 9, 2018) - Ensure we are shipping ES5 everywhere. From d67e682788b8b6054c99911b4068261923c1b62a Mon Sep 17 00:00:00 2001 From: Ben Chypak Date: Wed, 20 Jun 2018 15:12:50 -0700 Subject: [PATCH 3/5] Update docs --- docs/ApiClient.js.html | 4 +- docs/index.html | 98 ++++++++++++++++++++++++++---------------- 2 files changed, 63 insertions(+), 39 deletions(-) diff --git a/docs/ApiClient.js.html b/docs/ApiClient.js.html index b5f0b5c..935e180 100644 --- a/docs/ApiClient.js.html +++ b/docs/ApiClient.js.html @@ -498,7 +498,7 @@

Source: ApiClient.js

// Attach previously saved cookies, if enabled if (this.enableCookies) { if (typeof window === 'undefined') { - this.agent.attachCookies(request) + this.agent._attachCookies(request) } else { request.withCredentials() } @@ -521,7 +521,7 @@

Source: ApiClient.js

try { const data = this.deserialize(response, returnType) if (this.enableCookies && typeof window === 'undefined') { - this.agent.saveCookies(response) + this.agent._saveCookies(response) } resolve({ diff --git a/docs/index.html b/docs/index.html index 76a4650..d527085 100644 --- a/docs/index.html +++ b/docs/index.html @@ -52,22 +52,12 @@

/ /

NPM

CircleCI

-

Introduction

ShopApi - JavaScript client for Salesforce Commerce Cloud OCAPI Shop API.

+

🙌 Introduction

Salesforce Commerce Cloud Open Commerce API (OCAPI) for Node and browsers.

  • API version: 17.8
-

Installation

For Node.js

npm

To publish the library as a npm, -please follow the procedure in "Publishing npm packages".

-

Then install it via:

-
npm install commercecloud-ocapi-client --save

git

# -If the library is hosted at a git repository, e.g. -https://github.com/GIT_USER_ID/GIT_REPO_ID -then install it via:

-
    npm install GIT_USER_ID/GIT_REPO_ID --save

For browser

The library also works in the browser environment via npm and browserify. After following -the above steps with Node.js and installing browserify with npm install -g browserify, -perform the following (assuming main.js is your entry file):

-
browserify main.js > bundle.js

Then include bundle.js in the HTML pages.

-

Webpack Configuration

Using Webpack you may encounter the following error: "Module not found: Error: +

⚒ Installation

This library is distributed on npm, in order to add it as a dependency, run the following command:

+
npm install commercecloud-ocapi-client --save

🔦 Webpack Configuration

Using Webpack you may encounter the following error: "Module not found: Error: Cannot resolve module", most certainly you should disable AMD loader. Add/merge the following section to your webpack config:

module: {
@@ -78,41 +68,75 @@ 

Webpack Configuration

Using Webpack you may encounter the following e } } ] -}

Getting Started

Please follow the installation instruction and execute the following JS code:

+}

👨🏻‍💻 Getting Started

💡 Usage

Please follow the installation instruction and execute the following JS code:

import ShopApi from 'commercecloud-ocapi-client'
 
-ShopApi.ApiClient.instance = new ShopApi.ApiClient({
-    clientUsername: 'YOUR USERNAME', // Configure HTTP basic authorization: customers_auth
-    clientPassword: 'YOUR PASSWORD', // Configure HTTP basic authorization: customers_auth
-    oAuthAccessToken: '' // Configure OAuth2 access token for authorization: oauth2_application
-})
+ShopApi.ApiClient.instance = new ShopApi.ApiClient()
 
-const api = new ShopApi.BasketsApi()
+const api = new ShopApi.CategoriesApi()
 
-const basketId = "basketId_example" // {String} the id of the basket to be retrieved
-
-api.deleteBasketsByID(basketId)
+api.getCategoriesByIDs(['mens', 'newarrivals'])
     .then(() {
         console.log('API called successfully.')
     })
     .catch((fault) => {
         console.error(fault)
-    })

Documentation for API Endpoints

-

Documentation for Authorization

client_id

    -
  • Type: API key
  • -
  • API key parameter name: x-dw-client-id
  • -
  • Location: HTTP header
  • + })

    🔌 Configuration

    The API client accepts an configuration object, example:

    +
    import ShopApi from 'commercecloud-ocapi-client'
    +
    +const config = {
    +  basePath: 'https://localhost/s/siteId/dw/shop/v17_8',
    +  defaultHeaders: {}, // HTTP header for all requests
    +  timeout: 60000, // Request timeout in milliseconds
    +  cache: true, // If set to false an additional timestamp parameter is added to all API GET calls to prevent browser caching
    +  enableCookies: false, //If set to true, the client will save the cookies from each server response, and return them in the next request.
    +}
    +
    +ShopApi.ApiClient.instance = new ShopApi.ApiClient(config)

    🔐 Authorization

    To access secure end points, you can pass the username, password in the configuration, example:

    +
    import ShopApi from 'commercecloud-ocapi-client'
    +
    +const config = {
    +  clientUsername: 'username',
    +  clientPassword: 'password',
    +}
    +
    +ShopApi.ApiClient.instance = new ShopApi.ApiClient(config)

    Or to use oAuth token:

    +
    import ShopApi from 'commercecloud-ocapi-client'
    +
    +const config = {
    +  oauth2AccessToken: 'token'
    +}
    +
    +ShopApi.ApiClient.instance = new ShopApi.ApiClient(config)

    ✅ Testing

    Because Salesforce OCAPI is not publicly available, you need to have a running instance that you can test against. In the test folder, there is a file config.json that has the example configuration for your environment. Simply update the file with your instance information

    +

    Example:

    +
    {
    +  "clientId": "5640cc6b-f5e9-466e-9134-9853e9f9db93",
    +  "baseUrl": "https://localhost/s/siteId/dw/shop/v17_8"
    +}

    Then run the following command:

    +
    npm test

    ♻️ Continuous Integration

    We use Circle CI to protect the develop and master branch to make sure the builds follows the code style and passes all tests. For every pull request, it is required to pass ALL checks including the following tests:

    +
      +
    • Linting: npm run lint
    • +
    • Unit Tests: npm run test
    -

    customers_auth

      -
    • Type: HTTP basic authentication
    • +

      📦 Build and Deployment

      At Mobify, we practice several branching strategies, Release Deployment is a strategy for projects where feature gets bundled into a release periodically. master contains the code for current version, develop has the features that is under development and waiting to be released. For new features and bug fixes, please propose pull requests to merge into develop.

      +

      This package is distributed on npm, on every release, we run scripts to automatically merge develop into master, test the build in Circle CI as well as publish the package on NPM.

      +

      Changelog

      To understand the change between versions, please read CHANGELOG.md. Note that it is required to have a # To be released section filled out if you are planning to make pull requests that include new features or bug fixes.

      +

      Example:

      +
      ## To be released
      +- Update npm package to ship with three builds: `UMD`, `CommonJS` and `ES2015` [#4](https://github.com/mobify/commercecloud-ocapi-client/pull/4)
      +
      +## v0.1.1 (November 7, 2017)
      +- Update Rollup output format to 'es'
      +
      +...

      📖 Documentation

      -

      oauth2_application

        -
      • Type: OAuth
      • -
      • Flow: application
      • -
      • Authorization URL:
      • -
      • Scopes: N/A
      • +

        👥 Owner

        This project is open sourced and actively maintained by Mobify. +We will make an effort to support the library, but we reserve the right to make incompatible changes when necessary.

        +

        🏅 Contributors

        From 6f5f8c70a4e9ce41c7e1929d35aac89ed2da8b49 Mon Sep 17 00:00:00 2001 From: John Boxall Date: Thu, 21 Jun 2018 11:20:23 -0700 Subject: [PATCH 4/5] Updating package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 22b2d10..1a85703 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "commercecloud-ocapi-client", - "version": "0.1.3", + "version": "0.1.4", "description": "An ES6 JavaScript Client for Salesforce Open Commerce API", "license": "SEE LICENSE IN LICENSE", "main": "dist/commercecloud-ocapi-client.cjs.js", From f1e3378897df7253c49aa5a2cd71c2484e6da072 Mon Sep 17 00:00:00 2001 From: John Boxall Date: Thu, 21 Jun 2018 11:20:27 -0700 Subject: [PATCH 5/5] Updating CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca1c555..cd3eea1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## To be released +## v0.1.4 (June 21, 2018) - Fix superagent `attachCookies` and `saveCookies` usage ## v0.1.3 (May 9, 2018)