commerce-sdk-isomorphic 1.4.0 → 1.5.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,41 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## v1.5.1
4
+
5
+ #### Documentation
6
+
7
+ * Replaced links to the [Commerce Cloud Developer Center](https://developer.commercecloud.com/s/salesforce-developer-center) with links to the new [Salesforce Developer Portal](https://developer.salesforce.com/docs/commerce/commerce-api).
8
+
9
+ #### Bug Fixes
10
+
11
+ * SLAS Login Helper no longer requests `redirect_uri` when running server-side
12
+
13
+ ## v1.5.0
14
+
15
+ #### New Features
16
+
17
+ * SLAS helper functions have been added.
18
+ * New client configuration setting `throwOnBadResponse`. When set to true, responses other than `2xx` and `304` will throw an error.
19
+
20
+ #### New APIs
21
+
22
+ * *Shopper Context* has been added to the SDK.
23
+
24
+ #### API Changes
25
+
26
+ *Shopper Login*
27
+
28
+ * New Endpoints
29
+
30
+ | **Endpoint Name** | **Description** |
31
+ | ------------- |-------------|
32
+ | authorizePasswordlessCustomer | Logs a customer in using Core with their customer profiles loaded in ECOM. Allows the user to authenticate when their identity provider (Core) is down. |
33
+ | getPasswordLessAccessToken | Evaluate the `pwdless_token` and issue the shopper token (JWT). |
34
+
35
+ #### Bug Fixes
36
+
37
+ * Added support for `application/x-www-form-urlencoded` request bodies.
38
+ - SLAS endpoints now work out of the box
3
39
  ## v1.4.0
4
40
 
5
41
  #### New Features
package/README.md CHANGED
@@ -2,102 +2,119 @@
2
2
 
3
3
  [![CircleCI][circleci-image]][circleci-url]
4
4
 
5
- The Salesforce Commerce SDK Isomorphic allows easy interaction with the Salesforce B2C Commerce platform Shopper APIs through a lightweight SDK that works both on browsers and nodejs applications. For a more robust SDK, which includes our B2C Data APIS and Shopper APIs, see [our Node.js Commerce SDK](https://github.com/SalesforceCommerceCloud/commerce-sdk).
5
+ The Salesforce Commerce SDK Isomorphic allows easy interaction with the Salesforce B2C Commerce platform Shopper APIs through a lightweight SDK that works both on browsers and NodeJS applications. For a more robust SDK, which includes our B2C Data APIS and Shopper APIs, see [our Node.js Commerce SDK](https://github.com/SalesforceCommerceCloud/commerce-sdk).
6
6
 
7
- ## Building
7
+ ## Getting Started
8
8
 
9
- To create the SDK package:
9
+ ### Requirements
10
10
 
11
- ```
12
- # Install dependencies needed to run generation
13
- $ yarn install
14
-
15
- # Parse API files, render templates to src/lib folder and copy static files to src/lib
16
- $ yarn run renderTemplates
11
+ - Node `^12.x`, `^14.x`, or `^16.x`
17
12
 
18
- # Launch sample application
19
- $ yarn start
13
+ ### Installation
20
14
 
21
- # Transpile and minify
22
- $ yarn build:lib
23
-
24
- # Run tests
25
- $ yarn test
15
+ ```bash
16
+ npm install commerce-sdk-isomorphic
26
17
  ```
27
18
 
28
- ## Usage
29
-
30
- An example React App is available at `./src/environment/App` directory. To use the sample application, configure these parameters in `./src/environment/config.js` file.
19
+ ### Usage
31
20
 
32
21
  > **Note:** These are required parameters.
33
22
 
34
- | Parameter | Description |
35
- | -------------- | :-------------------------------------------------------------------------------------------------------------------------------------- |
36
- | clientId | ID of the client account created with Salesforce Commerce. |
37
- | organizationId | The unique identifier for your Salesforce identity. |
38
- | shortCode | Region specific merchant ID. |
39
- | siteId | A unique site ID (for example, RefArch or SiteGenesis). |
23
+ | Parameter | Description |
24
+ | -------------- | :------------------------------------------------------------------------- |
25
+ | clientId | ID of the client account created with Salesforce Commerce. |
26
+ | organizationId | The unique identifier for your Salesforce identity. |
27
+ | shortCode | Region-specific merchant ID. |
28
+ | siteId | Name of the site to access data from, for example, RefArch or SiteGenesis. |
40
29
 
41
30
  ```javascript
42
31
  /**
43
32
  * Configure required parameters
44
- *
45
- * To learn more about the parameters please refer to https://developer.commercecloud.com/s/article/CommerceAPI-Get-Started
33
+ *
34
+ * To learn more about the parameters please refer to https://developer.salesforce.com/docs/commerce/commerce-api/guide/get-started.html
46
35
  */
36
+ import {helpers, ShopperLogin, ShopperSearch} from 'commerce-sdk-isomorphic';
37
+
47
38
  // Create a configuration to use when creating API clients
48
39
  const config = {
49
- proxy: 'https://localhost:3000',
50
- headers: {},
51
- parameters: {
52
- clientId: '<your-client-id>',
53
- organizationId: '<your-org-id>',
54
- shortCode: '<your-short-code>',
55
- siteId: '<your-site-id>'
56
- }
57
- }
40
+ proxy: 'https://localhost:3000', // Routes API calls through a proxy when set
41
+ headers: {},
42
+ parameters: {
43
+ clientId: '<your-client-id>',
44
+ organizationId: '<your-org-id>',
45
+ shortCode: '<your-short-code>',
46
+ siteId: '<your-site-id>',
47
+ },
48
+ throwOnBadResponse: true,
49
+ };
50
+
51
+ const shopperLogin = new ShopperLogin(config);
52
+ // Execute Public Client OAuth with PKCE to acquire guest tokens
53
+ const {access_token, refresh_token} = await helpers.loginGuestUser(
54
+ shopperLogin,
55
+ {redirectURI: `${config.proxy}/callback`} // Callback URL must be configured in SLAS Admin
56
+ );
57
+
58
+ const shopperSearch = new ShopperSearch({
59
+ ...config,
60
+ headers: {authorization: `Bearer ${access_token}`},
61
+ });
62
+
63
+ const searchResult = await shopperSearch.productSearch({
64
+ parameters: {q: 'shirt'},
65
+ });
58
66
  ```
59
- Launch the sample application using `yarn start`. Access the sample application using a new browser window at this url `localhost:3000`.
60
67
 
61
68
  ### Advanced options
62
69
 
63
- Commerce SDK Isomorphic supports advanced [Fetch API options](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) by a simple configuration.
64
- This sample code shows how to configure HTTP timeout and agent options in `./src/environment/config.js` file
70
+ Commerce SDK Isomorphic supports Fetch API options for [node-fetch](https://github.com/node-fetch/node-fetch/1#api) on server and [whatwg-fetch](https://github.github.io/fetch/) on browser with a simple configuration.
71
+ This sample code shows how to configure HTTP timeout and agent options.
65
72
 
66
73
  ```javascript
67
- /**
68
- * Configure advanced timeout and agent parameters
69
- *
70
- * To learn more about the parameters please refer to https://developer.commercecloud.com/s/article/CommerceAPI-Get-Started
71
- */
72
- // Create a configuration to use when creating API clients
73
- const https = require("https");
74
+ /**
75
+ * Configure advanced timeout and agent parameters
76
+ *
77
+ * To learn more about the parameters please refer to the [Salesforce Developer Center](https://developer.salesforce.com/docs/commerce/commerce-api).
78
+ */
79
+ // Create a configuration to use when creating API clients
80
+ const https = require('https');
74
81
 
75
82
  const config = {
76
- proxy: 'https://localhost:3000',
77
- headers: {},
78
- parameters: {
79
- clientId: '<your-client-id>',
80
- organizationId: '<your-org-id>',
81
- shortCode: '<your-short-code>',
82
- siteId: '<your-site-id>'
83
- },
84
- fetchOptions: {
85
- timeout: 2000, //request times out after 2 seconds
86
- agent: new https.agent({ // a custom http agent
87
- keepAlive: true
88
- })
89
- }
90
- }
91
- ```
92
-
93
- ## Testing
94
-
95
- Two types of tests occur when running `yarn test`. First, unit tests are executed with jest including an enforced coverage level. This is all tests not contained within the sample app path of `src/environment`. If that passes, tests within the sample app path are executed using the `react-scripts` configuration. These allow for testing of the SDK within a sample React application.
83
+ proxy: 'https://localhost:3000',
84
+ headers: {},
85
+ parameters: {
86
+ clientId: '<your-client-id>',
87
+ organizationId: '<your-org-id>',
88
+ shortCode: '<your-short-code>',
89
+ siteId: '<your-site-id>',
90
+ },
91
+ fetchOptions: {
92
+ timeout: 2000, //request times out after 2 seconds
93
+ agent: new https.agent({
94
+ // a custom http agent
95
+ keepAlive: true,
96
+ }),
97
+ },
98
+ };
99
+ ```
100
+
101
+ ### Additional Config Settings
102
+
103
+ _headers:_ A collection of key/value string pairs representing additional headers to include with API requests.
104
+
105
+ _throwOnBadResponse:_ Default value is false. When set to true, the SDK throws an Error on responses with statuses that are not 2xx or 304.
106
+
107
+ ### Public Client Shopper Login helpers
108
+
109
+ A collection of helper functions are available in this SDK to simplify [Public
110
+ Client Shopper Login OAuth
111
+ flows](https://developer.salesforce.com/docs/commerce/commerce-api/references?meta=shopper-login:Summary). See sample code above for guest login.
96
112
 
97
113
  ## License Information
98
114
 
99
115
  The Commerce SDK Isomorphic is licensed under BSD-3-Clause license. See the [license](./LICENSE.txt) for details.
100
116
 
101
117
  <!-- Markdown link & img dfn's -->
118
+
102
119
  [circleci-image]: https://circleci.com/gh/SalesforceCommerceCloud/commerce-sdk-isomorphic.svg?style=svg&circle-token=379eaa6f00e0840e10dd80585b2b045d02a8f3b7
103
120
  [circleci-url]: https://circleci.com/gh/SalesforceCommerceCloud/commerce-sdk-isomorphic