Skip to content

Commit 1c729a9

Browse files
authored
Release v4.2.0
Release version 4.2.0
2 parents 77b66d2 + ac9af30 commit 1c729a9

File tree

7 files changed

+224
-54
lines changed

7 files changed

+224
-54
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## CHANGELOG
22

33

4-
## v4.2.0 - future release
4+
## v4.2.0
55

66
### Enchancements
77
- Allow custom params for 'loginGuestUser' and custom body for 'loginRegisteredUserB2C' function [#415](https://github.com/SalesforceCommerceCloud/commerce-sdk/pull/415)

docs/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
## CHANGELOG
22

3+
4+
## v4.2.0
5+
6+
### Enchancements
7+
- Allow custom params for 'loginGuestUser' and custom body for 'loginRegisteredUserB2C' function [#415](https://github.com/SalesforceCommerceCloud/commerce-sdk/pull/415)
8+
- Add helper to encode special SCAPI characters [#416](https://github.com/SalesforceCommerceCloud/commerce-sdk/pull/416)
9+
310
## v4.1.0
411

512
### Enchancements

docs/assets/js/search.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/index.html

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ <h3>Shopper Login (SLAS)</h3>
8383
<p>SLAS will soon require new tenants to pass <code>channel_id</code> as an argument for retrieving guest access tokens. You can read more about the planned change <a href="https://developer.salesforce.com/docs/commerce/commerce-api/guide/slas.html#guest-tokens">here</a>.</p>
8484
<p>Please be aware that existing tenants are on a temporary allow list and will see no immediate disruption to service. We do ask that all users seek to adhere to the <code>channel_id</code> requirement before the end of August to enhance your security posture before the holiday peak season.</p>
8585
<p>In practice, we recommend that customers using the SLAS helper functions upgrade to <code>v4.0.0</code> of the <code>commerce-sdk</code>.</p>
86+
<a href="#warning-planned-sdk-changes-warning" id="warning-planned-sdk-changes-warning" style="color: inherit; text-decoration: none;">
87+
<h2>:warning: Planned SDK Changes :warning:</h2>
88+
</a>
89+
<a href="#encoding-path-parameters" id="encoding-path-parameters" style="color: inherit; text-decoration: none;">
90+
<h3>Encoding path parameters</h3>
91+
</a>
92+
<p>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 <a href="#encoding-special-characters">Encoding special characters</a> section for more details.</p>
8693
<a href="#prerequisites" id="prerequisites" style="color: inherit; text-decoration: none;">
8794
<h2>Prerequisites</h2>
8895
</a>
@@ -378,6 +385,63 @@ <h3>Custom APIs</h3>
378385

379386
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">&#x27;get response: &#x27;</span>, getResponse)
380387
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">&#x27;post response: &#x27;</span>, postResponse)</code></pre>
388+
<a href="#encoding-special-characters" id="encoding-special-characters" style="color: inherit; text-decoration: none;">
389+
<h3>Encoding special characters</h3>
390+
</a>
391+
<p>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.</p>
392+
<p>Additionally, SCAPI has special characters that should be double encoded, specifically <code>%</code> and <code>,</code>:</p>
393+
<ul>
394+
<li><code>%</code> should always be double encoded</li>
395+
<li><code>,</code> should be double encoded when used as part of an ID/parameter string, and single encoded when used to differentiate items in a list </li>
396+
</ul>
397+
<p>There is a helper function called <code>encodeSCAPISpecialCharacters</code> that can be utilized to single encode the SCAPI special characters and no other special characters.</p>
398+
<p>Here&#39;s an example where the <code>getCategory/getCategories</code> endpoints are called with a <code>categoryID</code> with special characters:</p>
399+
<pre><code class="language-javascript"><span class="hljs-keyword">import</span> * <span class="hljs-keyword">as</span> CommerceSdk <span class="hljs-keyword">from</span> <span class="hljs-string">&quot;commerce-sdk&quot;</span>;
400+
<span class="hljs-keyword">const</span> { helpers, Product } = CommerceSdk;
401+
402+
<span class="hljs-keyword">const</span> clientConfig = {
403+
<span class="hljs-attr">parameters</span>: {
404+
<span class="hljs-attr">clientId</span>: <span class="hljs-string">&quot;&lt;your-client-id&gt;&quot;</span>,
405+
<span class="hljs-attr">organizationId</span>: <span class="hljs-string">&quot;&lt;your-org-id&gt;&quot;</span>,
406+
<span class="hljs-attr">shortCode</span>: <span class="hljs-string">&quot;&lt;your-short-code&gt;&quot;</span>,
407+
<span class="hljs-attr">siteId</span>: <span class="hljs-string">&quot;&lt;your-site-id&gt;&quot;</span>,
408+
}
409+
};
410+
411+
<span class="hljs-keyword">const</span> shopperProducts = <span class="hljs-keyword">new</span> Product.ShopperProducts({
412+
...clientConfig,
413+
<span class="hljs-attr">headers</span>: {<span class="hljs-attr">authorization</span>: <span class="hljs-string">`Bearer &lt;insert_access_token&gt;`</span>}
414+
});
415+
416+
<span class="hljs-keyword">const</span> categoryId = <span class="hljs-string">&quot;SpecialCharacter,%$^@&amp;$;()!123Category&quot;</span>;
417+
<span class="hljs-comment">// &quot;SpecialCharacter%2C%25$^@&amp;$;()!123Category&quot;</span>
418+
<span class="hljs-keyword">const</span> scapiSpecialEncodedId = helpers.encodeSCAPISpecialCharacters(categoryId);
419+
420+
421+
<span class="hljs-comment">// id is a path parameter for API call:</span>
422+
<span class="hljs-comment">// &lt;base-url&gt;/product/shopper-products/v1/organizations/{organizationId}/categories/{id}</span>
423+
<span class="hljs-keyword">const</span> categoryResult = <span class="hljs-keyword">await</span> shopperProducts.getCategory({
424+
<span class="hljs-attr">parameters</span>: {
425+
<span class="hljs-comment">// Path parameters are NOT encoded by the SDK, so we have to single encode special characters</span>
426+
<span class="hljs-comment">// and the SCAPI special characters will end up double encoded</span>
427+
<span class="hljs-attr">id</span>: <span class="hljs-built_in">encodeURIComponent</span>(scapiSpecialEncodedId),
428+
}
429+
});
430+
431+
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;categoryResult: &quot;</span>, categoryResult);
432+
433+
<span class="hljs-comment">// `ids` are a query parameter and comma delimited to separate category IDs</span>
434+
<span class="hljs-keyword">const</span> categoriesResult = <span class="hljs-keyword">await</span> shopperProducts.getCategories({
435+
<span class="hljs-attr">parameters</span>: {
436+
<span class="hljs-comment">// No need to use `encodeURIComponent` as query parameters are single encoded by the SDK</span>
437+
<span class="hljs-comment">// So the SCAPI special characters will end up double encoded as well</span>
438+
<span class="hljs-comment">// Commas that separate items in a list will end up single encoded</span>
439+
<span class="hljs-attr">ids</span>: <span class="hljs-string">`<span class="hljs-subst">${scapiSpecialEncodedId}</span>,<span class="hljs-subst">${scapiSpecialEncodedId}</span>`</span>,
440+
}
441+
});
442+
443+
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;categoriesResult: &quot;</span>, categoriesResult);</code></pre>
444+
<p><strong>NOTE: In the next major version release, path parameters will be single encoded by default</strong></p>
381445
<a href="#caching" id="caching" style="color: inherit; text-decoration: none;">
382446
<h2>Caching</h2>
383447
</a>
@@ -528,7 +592,7 @@ <h2>Security</h2>
528592
<p>For more information about security considerations related to developing headless commerce applications, see
529593
<a href="https://developer.salesforce.com/docs/commerce/commerce-api/guide/security-considerations-for-headless-commerce.html">Security Considerations for Headless Commerce</a> on the
530594
<a href="https://developer.salesforce.com/developer-centers/commerce-cloud">Commerce Cloud Developer Center</a>.</p>
531-
<p>If you discover any potential security issues, please report them to <a href="mailto:&#115;&#101;&#x63;&#117;&#114;&#x69;&#x74;&#121;&#x40;&#x73;&#x61;&#108;&#101;&#x73;&#102;&#x6f;&#114;&#99;&#x65;&#x2e;&#99;&#111;&#x6d;">&#115;&#101;&#x63;&#117;&#114;&#x69;&#x74;&#121;&#x40;&#x73;&#x61;&#108;&#101;&#x73;&#102;&#x6f;&#114;&#99;&#x65;&#x2e;&#99;&#111;&#x6d;</a> as soon as possible.</p>
595+
<p>If you discover any potential security issues, please report them to <a href="mailto:&#x73;&#x65;&#99;&#x75;&#x72;&#x69;&#x74;&#x79;&#x40;&#x73;&#97;&#108;&#101;&#x73;&#x66;&#111;&#x72;&#x63;&#101;&#46;&#x63;&#111;&#109;">&#x73;&#x65;&#99;&#x75;&#x72;&#x69;&#x74;&#x79;&#x40;&#x73;&#97;&#108;&#101;&#x73;&#x66;&#111;&#x72;&#x63;&#101;&#46;&#x63;&#111;&#109;</a> as soon as possible.</p>
532596
<a href="#additional-documentation" id="additional-documentation" style="color: inherit; text-decoration: none;">
533597
<h2>Additional Documentation</h2>
534598
</a>

docs/interfaces/helpers.islasclient.html

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,13 @@ <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">Promise</
375375
<li class=" tsd-kind-type-alias tsd-parent-kind-module">
376376
<a href="../modules/helpers.html#customapiparameters" class="tsd-kind-icon">Custom<wbr>Api<wbr>Parameters</a>
377377
</li>
378-
<li class=" tsd-kind-type-alias tsd-parent-kind-module tsd-is-not-exported">
378+
<li class=" tsd-kind-type-alias tsd-parent-kind-module">
379+
<a href="../modules/helpers.html#customqueryparameters" class="tsd-kind-icon">Custom<wbr>Query<wbr>Parameters</a>
380+
</li>
381+
<li class=" tsd-kind-type-alias tsd-parent-kind-module">
382+
<a href="../modules/helpers.html#customrequestbody" class="tsd-kind-icon">Custom<wbr>Request<wbr>Body</a>
383+
</li>
384+
<li class=" tsd-kind-type-alias tsd-parent-kind-module">
379385
<a href="../modules/helpers.html#loginrequest" class="tsd-kind-icon">Login<wbr>Request</a>
380386
</li>
381387
<li class=" tsd-kind-type-alias tsd-parent-kind-module">
@@ -399,6 +405,9 @@ <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">Promise</
399405
<li class=" tsd-kind-function tsd-parent-kind-module">
400406
<a href="../modules/helpers.html#createcodeverifier" class="tsd-kind-icon">create<wbr>Code<wbr>Verifier</a>
401407
</li>
408+
<li class=" tsd-kind-function tsd-parent-kind-module">
409+
<a href="../modules/helpers.html#encodescapispecialcharacters" class="tsd-kind-icon">encodeSCAPISpecial<wbr>Characters</a>
410+
</li>
402411
<li class=" tsd-kind-function tsd-parent-kind-module">
403412
<a href="../modules/helpers.html#generatecodechallenge" class="tsd-kind-icon">generate<wbr>Code<wbr>Challenge</a>
404413
</li>

0 commit comments

Comments
 (0)