Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
Merge release-v0.1.5 into master
Browse files Browse the repository at this point in the history
  • Loading branch information
johnboxall authored Oct 16, 2018
2 parents 68a8c5c + e88ee4b commit 40e9dfb
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v0.1.5 (October 16, 2018)
- Add `overrideHttpPut` option for handling environments not allowing http put.

## v0.1.4 (June 21, 2018)
- Fix superagent `attachCookies` and `saveCookies` usage

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,13 @@ const config = {
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.
overrideHttpPut: true // If set to true, any methods specified as using http PUT will be sent using POST along the header value 'x-dw-http-method-override' set to 'PUT'.
}

ShopApi.ApiClient.instance = new ShopApi.ApiClient(config)
```



### 🔐 Authorization

Expand Down Expand Up @@ -121,7 +122,7 @@ ShopApi.ApiClient.instance = new ShopApi.ApiClient(config)

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:
Example:
```json
{
"clientId": "5640cc6b-f5e9-466e-9134-9853e9f9db93",
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "commercecloud-ocapi-client",
"version": "0.1.4",
"version": "0.1.5",
"description": "An ES6 JavaScript Client for Salesforce Open Commerce API",
"license": "SEE LICENSE IN LICENSE",
"main": "dist/commercecloud-ocapi-client.cjs.js",
Expand Down
24 changes: 21 additions & 3 deletions src/ApiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ import Fault from './models/Fault'

const defaultConfig = {
basePath: 'https://localhost/s/siteId/dw/shop/v17_8',
defaultHeaders: {},
timeout: 60000,
cache: true,
defaultHeaders: {},
enableCookies: false,
overrideHttpPut: true,
timeout: 60000,
}

/**
Expand All @@ -50,7 +51,8 @@ export default class ApiClient {
enableCookies,
clientUsername,
clientPassword,
oauth2AccessToken
oauth2AccessToken,
overrideHttpPut
} = Object.assign(defaultConfig, config)

// verify the required parameter 'basepath' is set
Expand Down Expand Up @@ -94,6 +96,16 @@ export default class ApiClient {
customers_auth.password = clientPassword
}

/**
* If set to true, endpoints that normally use HTTP `PUT` will
* be sent using `POST` with an aditional header (x-dw-http-method-override: `PUT`).
* Please refer to the following Salesforce documentation {@link https://documentation.demandware.com/DOC1/topic/com.demandware.dochelp/OCAPI/18.8/usage/HttpMethods.html}
* for more information.
* @type {Boolean}
* @default true
*/
this.overrideHttpPut = overrideHttpPut

/**
* The default HTTP headers to be included for all API calls.
* @type {Array.<String>}
Expand Down Expand Up @@ -420,6 +432,12 @@ export default class ApiClient {
queryParams._ = new Date().getTime()
}

// emulate PUT method because they are not allowed on staging and production environments
if (this.overrideHttpPut && httpMethod.toUpperCase() === 'PUT') {
httpMethod = 'POST'
headerParams = Object.assign(headerParams || {}, {'x-dw-http-method-override': 'PUT'})
}

request.query(this.normalizeParams(queryParams))

// set header parameters
Expand Down

0 comments on commit 40e9dfb

Please sign in to comment.