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

Commit 40e9dfb

Browse files
authored
Merge release-v0.1.5 into master
2 parents 68a8c5c + e88ee4b commit 40e9dfb

File tree

5 files changed

+29
-7
lines changed

5 files changed

+29
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## v0.1.5 (October 16, 2018)
2+
- Add `overrideHttpPut` option for handling environments not allowing http put.
3+
14
## v0.1.4 (June 21, 2018)
25
- Fix superagent `attachCookies` and `saveCookies` usage
36

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,13 @@ const config = {
8383
timeout: 60000, // Request timeout in milliseconds
8484
cache: true, // If set to false an additional timestamp parameter is added to all API GET calls to prevent browser caching
8585
enableCookies: false, //If set to true, the client will save the cookies from each server response, and return them in the next request.
86+
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'.
8687
}
8788

8889
ShopApi.ApiClient.instance = new ShopApi.ApiClient(config)
8990
```
9091

91-
92+
9293

9394
### 🔐 Authorization
9495

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

122123
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
123124

124-
Example:
125+
Example:
125126
```json
126127
{
127128
"clientId": "5640cc6b-f5e9-466e-9134-9853e9f9db93",

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "commercecloud-ocapi-client",
3-
"version": "0.1.4",
3+
"version": "0.1.5",
44
"description": "An ES6 JavaScript Client for Salesforce Open Commerce API",
55
"license": "SEE LICENSE IN LICENSE",
66
"main": "dist/commercecloud-ocapi-client.cjs.js",

src/ApiClient.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ import Fault from './models/Fault'
2626

2727
const defaultConfig = {
2828
basePath: 'https://localhost/s/siteId/dw/shop/v17_8',
29-
defaultHeaders: {},
30-
timeout: 60000,
3129
cache: true,
30+
defaultHeaders: {},
3231
enableCookies: false,
32+
overrideHttpPut: true,
33+
timeout: 60000,
3334
}
3435

3536
/**
@@ -50,7 +51,8 @@ export default class ApiClient {
5051
enableCookies,
5152
clientUsername,
5253
clientPassword,
53-
oauth2AccessToken
54+
oauth2AccessToken,
55+
overrideHttpPut
5456
} = Object.assign(defaultConfig, config)
5557

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

99+
/**
100+
* If set to true, endpoints that normally use HTTP `PUT` will
101+
* be sent using `POST` with an aditional header (x-dw-http-method-override: `PUT`).
102+
* Please refer to the following Salesforce documentation {@link https://documentation.demandware.com/DOC1/topic/com.demandware.dochelp/OCAPI/18.8/usage/HttpMethods.html}
103+
* for more information.
104+
* @type {Boolean}
105+
* @default true
106+
*/
107+
this.overrideHttpPut = overrideHttpPut
108+
97109
/**
98110
* The default HTTP headers to be included for all API calls.
99111
* @type {Array.<String>}
@@ -420,6 +432,12 @@ export default class ApiClient {
420432
queryParams._ = new Date().getTime()
421433
}
422434

435+
// emulate PUT method because they are not allowed on staging and production environments
436+
if (this.overrideHttpPut && httpMethod.toUpperCase() === 'PUT') {
437+
httpMethod = 'POST'
438+
headerParams = Object.assign(headerParams || {}, {'x-dw-http-method-override': 'PUT'})
439+
}
440+
423441
request.query(this.normalizeParams(queryParams))
424442

425443
// set header parameters

0 commit comments

Comments
 (0)