commerce-sdk-isomorphic 3.2.0 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +69 -2
- package/lib/index.cjs.d.ts +296 -10
- package/lib/index.cjs.js +1 -1
- package/lib/index.esm.d.ts +296 -10
- package/lib/index.esm.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -21,6 +21,12 @@ In practice, we recommend:
|
|
|
21
21
|
- For customers using the SLAS helpers with a public client, it is recommended to upgrade to at least `v1.8.0` of the `commerce-sdk-isomorphic`.
|
|
22
22
|
- For customers using the SLAS helpers with a private client, it is recommended to upgrade to `v3.0.0` of the `commerce-sdk-isomorphic`.
|
|
23
23
|
|
|
24
|
+
## :warning: Planned SDK Changes :warning:
|
|
25
|
+
|
|
26
|
+
### Encoding path parameters
|
|
27
|
+
|
|
28
|
+
In the next major version release, the SDK will encode special characters (UTF-8 based on SCAPI guidelines) in path parameters by default. Please see the [Encoding special characters](#encoding-special-characters) section for more details.
|
|
29
|
+
|
|
24
30
|
## Getting Started
|
|
25
31
|
|
|
26
32
|
### Requirements
|
|
@@ -114,7 +120,7 @@ try {
|
|
|
114
120
|
|
|
115
121
|
* `headers`: Headers to include with API requests.
|
|
116
122
|
|
|
117
|
-
|
|
123
|
+
#### Custom Query Parameters
|
|
118
124
|
|
|
119
125
|
You can pass custom query parameters through the SDK to be used in [B2C Commerce API Hooks](https://developer.salesforce.com/docs/commerce/commerce-api/guide/extensibility_via_hooks.html). Custom query parameters must begin with `c_`:
|
|
120
126
|
|
|
@@ -129,7 +135,7 @@ const searchResult = await shopperSearch.productSearch({
|
|
|
129
135
|
|
|
130
136
|
Invalid query parameters that are not a part of the API and do not follow the `c_` custom query parameter convention are filtered from the request with a warning.
|
|
131
137
|
|
|
132
|
-
|
|
138
|
+
#### Custom APIs
|
|
133
139
|
|
|
134
140
|
The SDK supports calling [B2C Commerce Custom APIs](https://developer.salesforce.com/docs/commerce/commerce-api/guide/custom-apis.html) with a helper function, `callCustomEndpoint`:
|
|
135
141
|
|
|
@@ -195,6 +201,67 @@ await helpers.callCustomEndpoint({
|
|
|
195
201
|
|
|
196
202
|
For more documentation about this helper function, please refer to the [commerce-sdk-isomorphic docs](https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/modules/helpers.html).
|
|
197
203
|
|
|
204
|
+
#### Encoding special characters
|
|
205
|
+
|
|
206
|
+
The SDK currently single encodes special characters for query parameters in UTF-8 format based on SCAPI guidelines. However, the SDK does NOT encode path parameters, and will require the developer to encode any path parameters with special characters.
|
|
207
|
+
|
|
208
|
+
Additionally, SCAPI has special characters that should be double encoded, specifically `%` and `,`:
|
|
209
|
+
- `%` should always be double encoded
|
|
210
|
+
- `,` should be double encoded when used as part of an ID/parameter string, and single encoded when used to differentiate items in a list
|
|
211
|
+
|
|
212
|
+
There is a helper function called `encodeSCAPISpecialCharacters` that can be utilized to single encode the SCAPI special characters and no other special characters.
|
|
213
|
+
|
|
214
|
+
Here's an example where the `getCategory/getCategories` endpoints are called with a `categoryID` with special characters:
|
|
215
|
+
```javascript
|
|
216
|
+
import pkg from "commerce-sdk-isomorphic";
|
|
217
|
+
const { helpers, ShopperProducts } = pkg;
|
|
218
|
+
|
|
219
|
+
const clientConfig = {
|
|
220
|
+
parameters: {
|
|
221
|
+
clientId: "<your-client-id>",
|
|
222
|
+
organizationId: "<your-org-id>",
|
|
223
|
+
shortCode: "<your-short-code>",
|
|
224
|
+
siteId: "<your-site-id>",
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
const shopperProducts = new ShopperProducts({
|
|
229
|
+
...clientConfig,
|
|
230
|
+
headers: {authorization: `Bearer <insert_access_token>`}
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
const categoryId = "SpecialCharacter,%$^@&$;()!123Category";
|
|
234
|
+
// "SpecialCharacter%2C%25$^@&$;()!123Category"
|
|
235
|
+
const scapiSpecialEncodedId = helpers.encodeSCAPISpecialCharacters(categoryId);
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
// id is a path parameter for API call:
|
|
239
|
+
// <base-url>/product/shopper-products/v1/organizations/{organizationId}/categories/{id}
|
|
240
|
+
const categoryResult = await shopperProducts.getCategory({
|
|
241
|
+
parameters: {
|
|
242
|
+
// Path parameters are NOT encoded by the SDK, so we have to single encode special characters
|
|
243
|
+
// and the SCAPI special characters will end up double encoded
|
|
244
|
+
id: encodeURIComponent(scapiSpecialEncodedId),
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
console.log("categoryResult: ", categoryResult);
|
|
249
|
+
|
|
250
|
+
// `ids` are a query parameter and comma delimited to separate category IDs
|
|
251
|
+
const categoriesResult = await shopperProducts.getCategories({
|
|
252
|
+
parameters: {
|
|
253
|
+
// No need to use `encodeURIComponent` as query parameters are single encoded by the SDK
|
|
254
|
+
// So the SCAPI special characters will end up double encoded as well
|
|
255
|
+
// Commas that separate items in a list will end up single encoded
|
|
256
|
+
ids: `${scapiSpecialEncodedId},${scapiSpecialEncodedId}`,
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
console.log("categoriesResult: ", categoriesResult);
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
**NOTE: In the next major version release, path parameters will be single encoded by default**
|
|
264
|
+
|
|
198
265
|
## License Information
|
|
199
266
|
|
|
200
267
|
The Commerce SDK Isomorphic is licensed under BSD-3-Clause license. See the [license](./LICENSE.txt) for details.
|