commerce-sdk-isomorphic 1.1.2 → 1.5.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/CHANGELOG.md CHANGED
@@ -1,20 +1,97 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## v1.5.0
4
+
5
+ #### New Features
6
+
7
+ * SLAS helper functions have been added.
8
+ #### New APIs
9
+
10
+ * *Shopper Context* has been added to the SDK.
11
+
12
+ #### API Changes
13
+
14
+ *Shopper Login*
15
+
16
+ * New Endpoints
17
+
18
+ | **Endpoint Name** | **Description** |
19
+ | ------------- |-------------|
20
+ | 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. |
21
+ | getPasswordLessAccessToken | Evaluate the `pwdless_token` and issue the shopper token (JWT). |
22
+
23
+ ## v1.4.0
24
+
25
+ #### New Features
26
+
27
+ * TypeScript type definitions are now exported! :tada:
28
+ * Any parameter for any method can now be specified in the client configuration.
29
+ * Parameters not used by an endpoint will now be ignored, rather than included.
30
+ * A custom user agent is now sent with requests (node.js only)
31
+
32
+ #### API Changes
33
+
34
+ *Shopper Baskets*
35
+
36
+ * New endpoints
37
+
38
+ | **Endpoint Name** | **Description** |
39
+ | ------------- |-------------|
40
+ | transferBasket | Transfer the previous shopper's basket to the current shopper by updating the basket's owner. No other values change. You must obtain the shopper authorization token via SLAS, and it must contain both the previous and current shopper IDs. |
41
+ | mergeBasket | Merge data from the previous shopper's basket into the current shopper's active basket and delete the previous shopper's basket. This endpoint doesn't merge Personally Identifiable Information (PII). You must obtain the shopper authorization token via SLAS, and it must contain both the previous and current shopper IDs. After the merge, all basket amounts are recalculated and totaled, including lookups for prices, taxes, shipping, and promotions. |
42
+ | updatePaymentInstrumentInBasket | Success, the response body contains the basket with the updated payment instrument. |
43
+
44
+ *Shopper Login*
45
+
46
+ * New endpoints
47
+
48
+ | **Endpoint Name** | **Description** |
49
+ | ------------- |-------------|
50
+ | retrieveCredQualityUserInfo | Retrieve credential quality statistics for a user. |
51
+
52
+ ## v1.3.0
53
+
54
+ #### New APIs
55
+
56
+ * *Shopper Discovery Search* has been added to the SDK.
57
+
58
+ #### API Changes
59
+
60
+ *Shopper Login*
61
+
62
+ * New operation: `getTrustedSystemAccessToken`
63
+
64
+ ## v1.2.0
65
+
66
+ #### API Changes
67
+
68
+ *Shopper Customers*
69
+
70
+ * New operations
71
+ * registerExternalProfile
72
+ * getExternalProfile
73
+
3
74
  ## v1.1.2
75
+
4
76
  * Fixed issue causing endpoints that accept array values to not properly set `Content-Type` header to `application/json`.
5
77
 
6
78
  ## v1.1.1
79
+
7
80
  * Fixed issue causing `shortCode` to not be properly set
8
81
 
9
82
  ## v1.1.0
83
+
10
84
  #### **API Changes**
85
+
11
86
  *Shopper Baskets API*
12
- * Endpoint Added
13
- * organizations/{organizationId}/baskets/{basketId}/price-books
87
+
88
+ * Endpoint Added
89
+ * organizations/{organizationId}/baskets/{basketId}/price-books
14
90
 
15
91
  *Shopper Login API*
92
+
16
93
  * Endpoint Added
17
- * organizations/{organizationId}/oauth2/logout
94
+ * organizations/{organizationId}/oauth2/logout
18
95
  * customer_id and enc_user_id were added to the TokenResponse type
19
96
  * LoginRequest type was added
20
97
  * Query param uuid for /organizations/{organizationId}/oauth2/authorize was renamed to usid
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
- *
33
+ *
45
34
  * To learn more about the parameters please refer to https://developer.commercecloud.com/s/article/CommerceAPI-Get-Started
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.commercecloud.com/s/api-details/a003k00000VWfNDAA1/commerce-cloud-developer-centershopperloginandapiaccessservice#public-client-use-cases). 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