commerce-sdk-isomorphic 2.1.0-dev.0 → 3.0.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,5 +1,41 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## v3.0.0
4
+
5
+ ### :warning: Planned API Changes :warning:
6
+
7
+ #### Shopper Context
8
+
9
+ Starting July 31st 2024, all endpoints in the Shopper context API will require the `siteId` parameter for new customers. This field is marked as optional for backward compatibility and will be changed to mandatory tentatively by January 2025. You can read more about the planned change [here](https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-context?meta=Summary) in the notes section.
10
+
11
+ #### Shopper Login (SLAS)
12
+
13
+ SLAS will soon require new tenants to pass `channel_id` as an argument for retrieving guest access tokens. You can read more about the planned change [here](https://developer.salesforce.com/docs/commerce/commerce-api/guide/slas.html#guest-tokens).
14
+
15
+ 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 `channel_id` requirement before the end of August to enhance your security posture before the holiday peak season.
16
+
17
+ In practice, we recommend:
18
+
19
+ - 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`.
20
+ - For customers using the SLAS helpers with a private client, it is recommended to upgrade to `v3.0.0` of the `commerce-sdk-isomorphic`.
21
+
22
+ ### Enchancements
23
+
24
+ - Update SLAS helper function `loginGuestUserPrivate` to require `channel_id` through `clientConfig.parameters.siteId` [#165](https://github.com/SalesforceCommerceCloud/commerce-sdk-isomorphic/pull/165)
25
+
26
+ ## v2.1.0
27
+
28
+ ### Enhancements
29
+ - Export the parameter keys for each API endpoint [#158](https://github.com/SalesforceCommerceCloud/commerce-sdk-isomorphic/pull/158)
30
+
31
+ ### API Changes
32
+ *Shopper Baskets*
33
+
34
+ | **Endpoint Name** | **Description** |
35
+ | ------------- |-----------------------------------|
36
+ | updateItemsInBasket | Updates multiple items in a basket. |
37
+
38
+
3
39
  ## v2.0.0
4
40
 
5
41
  #### API Changes
package/README.md CHANGED
@@ -1,13 +1,32 @@
1
1
  # commerce-sdk-isomorphic
2
2
 
3
- The Salesforce Commerce SDK (Isomorphic) allows easy interaction with the B2C Commerce platform’s Shopper APIs on the Node.js runtime and works both in browsers and Node applications. For a Node-based SDK that can access the Admin APIs in addition to the Shopper APIs, see the main [Commerce SDK](https://github.com/SalesforceCommerceCloud/commerce-sdk).
3
+ This SDK provides a Browser & Node.js JavaScript client for calling [B2C Commerce Shopper APIs](https://developer.salesforce.com/docs/commerce/commerce-api/overview).
4
+
5
+ _For a Node.js only SDK that can also access Admin APIs checkout [Commerce SDK](https://github.com/SalesforceCommerceCloud/commerce-sdk)._
6
+
7
+ ## :warning: Planned API Changes :warning:
8
+
9
+ ### Shopper Context
10
+
11
+ Starting July 31st 2024, all endpoints in the Shopper context API will require the `siteId` parameter for new customers. This field is marked as optional for backward compatibility and will be changed to mandatory tentatively by January 2025. You can read more about the planned change [here](https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-context?meta=Summary) in the notes section.
12
+
13
+ ### Shopper Login (SLAS)
14
+
15
+ SLAS will soon require new tenants to pass `channel_id` as an argument for retrieving guest access tokens. You can read more about the planned change [here](https://developer.salesforce.com/docs/commerce/commerce-api/guide/slas.html#guest-tokens).
16
+
17
+ 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 `channel_id` requirement before the end of August to enhance your security posture before the holiday peak season.
18
+
19
+ In practice, we recommend:
20
+
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
+ - For customers using the SLAS helpers with a private client, it is recommended to upgrade to `v3.0.0` of the `commerce-sdk-isomorphic`.
4
23
 
5
24
  ## Getting Started
6
25
 
7
26
  ### Requirements
8
27
 
9
- - Node `^12.x`, `^14.x`, `^16.x`, `^18.x` or `^20.x`
10
-
28
+ - Node `^12.x`, `^14.x`, `^16.x`, `^18.x`
29
+ - The SDK requires B2C Commerce API (SCAPI) to be configured. For more info see [Getting started with SCAPI](https://developer.salesforce.com/docs/commerce/commerce-api/guide/get-started.html).
11
30
 
12
31
  ### Installation
13
32
 
@@ -17,55 +36,25 @@ npm install commerce-sdk-isomorphic
17
36
 
18
37
  ### Usage
19
38
 
20
- > **Note:** These are required parameters.
21
-
22
- | Parameter | Description |
23
- | -------------- | :------------------------------------------------------------------------- |
24
- | clientId | ID of the client account created with Salesforce Commerce. |
25
- | organizationId | The unique identifier for your Salesforce identity. |
26
- | shortCode | Region-specific merchant ID. |
27
- | siteId | Name of the site to access data from, for example, RefArch or SiteGenesis. |
28
-
29
-
30
- ### Configure the Isomorphic SDK
31
-
32
-
33
39
  ```javascript
34
- /**
35
- * Configure required parameters
36
- *
37
- * To learn more about the parameters please refer to https://developer.salesforce.com/docs/commerce/commerce-api/guide/get-started.html
38
- */
39
40
  import {helpers, ShopperLogin, ShopperSearch} from 'commerce-sdk-isomorphic';
40
41
 
41
- // Create a configuration to use when creating API clients
42
42
  const config = {
43
- proxy: 'https://localhost:3000', // Routes API calls through a proxy when set
44
- headers: {},
43
+ // SCAPI does not support CORS, so client side requests must use a reverse proxy.
44
+ proxy: 'https://localhost:3000',
45
45
  parameters: {
46
46
  clientId: '<your-client-id>',
47
47
  organizationId: '<your-org-id>',
48
48
  shortCode: '<your-short-code>',
49
49
  siteId: '<your-site-id>',
50
50
  },
51
- throwOnBadResponse: true,
52
51
  };
53
52
 
54
- const shopperLogin = new ShopperLogin(config);
55
- // Execute Public Client OAuth with PKCE to acquire guest tokens
56
- const {access_token, refresh_token} = await helpers.loginGuestUser(
57
- shopperLogin,
58
- {redirectURI: `${config.proxy}/callback`} // Callback URL must be configured in SLAS Admin
53
+ const {access_token} = await helpers.loginGuestUser(
54
+ new ShopperLogin(config),
55
+ {redirectURI: `${config.proxy}/callback`}
59
56
  );
60
57
 
61
- // Execute Private Client OAuth with PKCE to acquire guest tokens
62
- // ***WARNING*** Be cautious about using this function in the browser as you may end up exposing your client secret
63
- // only use it when you know your slas client secret is secured
64
- // const {access_token, refresh_token} = await helpers.loginGuestUserPrivate(
65
- // shopperLogin,
66
- // {}, {clientSecret: '<your-slas-client-secret>'}
67
- // );
68
-
69
58
  const shopperSearch = new ShopperSearch({
70
59
  ...config,
71
60
  headers: {authorization: `Bearer ${access_token}`},
@@ -76,59 +65,33 @@ const searchResult = await shopperSearch.productSearch({
76
65
  });
77
66
  ```
78
67
 
79
- #### CORS
80
-
81
- The Salesforce Commerce API (SCAPI) does not support CORS, so a proxy must be used to be able to use the SDK.
82
-
83
- ### Advanced Options
68
+ #### Fetch Options
84
69
 
85
- 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.
86
- This sample code shows how to configure HTTP timeout and agent options.
70
+ You can configure how the SDK makes requests using the `fetchOptions` parameter. It is passed to [node-fetch](https://github.com/node-fetch/node-fetch/1#api) on the server and [whatwg-fetch](https://github.github.io/fetch/) on browser.
87
71
 
88
72
  ```javascript
89
- /**
90
- * Configure advanced timeout and agent parameters
91
- *
92
- * To learn more about the parameters please refer to the [Salesforce Developer Center](https://developer.salesforce.com/docs/commerce/commerce-api).
93
- */
94
- // Create a configuration to use when creating API clients
95
- const https = require('https');
73
+ const https = require("https");
96
74
 
97
75
  const config = {
98
- proxy: 'https://localhost:3000',
99
- headers: {},
100
- parameters: {
101
- clientId: '<your-client-id>',
102
- organizationId: '<your-org-id>',
103
- shortCode: '<your-short-code>',
104
- siteId: '<your-site-id>',
105
- },
106
76
  fetchOptions: {
107
- timeout: 2000, //request times out after 2 seconds
108
- agent: new https.agent({
109
- // a custom http agent
110
- keepAlive: true,
111
- }),
77
+ // By default, requests made using the SDK do not include cookies.
78
+ credentials: "include",
79
+ timeout: 2000,
80
+ agent: new https.agent({ keepAlive: true }),
112
81
  },
113
82
  };
114
83
  ```
115
84
 
116
- ### Additional Config Settings
117
-
118
- _headers:_ A collection of key/value string pairs representing additional headers to include with API requests.
119
-
120
- _throwOnBadResponse:_ Default value is false. When set to true, the SDK throws an Error on responses with statuses that are not 2xx or 304.
85
+ For more info, refer to the [documentation site](https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/).
121
86
 
122
- ### Public/Private Client Shopper Login (SLAS) helpers
87
+ #### Additional Config Settings
123
88
 
124
- A collection of helper functions are available in this SDK to simplify [Public/Private Client Shopper Login OAuth flows](https://developer.salesforce.com/docs/commerce/commerce-api/references?meta=shopper-login:Summary). See sample code above for guest login.
125
-
126
- **⚠️ WARNING ⚠️**
127
- Users should be extremely cautious about using the SLAS private client helper functions in the browser as it can expose your client secret. Ensure that your client secret is secured before running the function client side.
89
+ * `headers`: Headers to include with API requests.
90
+ * `throwOnBadResponse`: When `true`, the SDK throws an `Error` on responses whose status is not 2xx or 304.
128
91
 
129
92
  ### Custom Query Parameters
130
93
 
131
- With the introduction of [hooks for Commerce APIs](https://developer.salesforce.com/docs/commerce/commerce-api/guide/extensibility_via_hooks.html), customers can pass custom query parameters through the SDK to be used in their custom hook. Custom query parameters must begin with `c_`:
94
+ 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_`:
132
95
 
133
96
  ```javascript
134
97
  const searchResult = await shopperSearch.productSearch({
@@ -139,19 +102,17 @@ const searchResult = await shopperSearch.productSearch({
139
102
  });
140
103
  ```
141
104
 
142
- Invalid query parameters that are not a part of the API and do not follow the `c_` custom query parameter convention will be filtered from the request and a warning will be displayed.
105
+ 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.
143
106
 
144
107
  ### Custom APIs
145
108
 
146
- The SDK supports calling [custom APIs](https://developer.salesforce.com/docs/commerce/commerce-api/guide/custom-apis.html) with a helper function, `callCustomEndpoint`.
147
-
148
- Example usage:
109
+ 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`:
149
110
 
150
111
  ```javascript
151
- import pkg from 'commerce-sdk-isomorphic';
112
+ import pkg from "commerce-sdk-isomorphic";
152
113
  const { helpers } = pkg;
153
114
 
154
- const clientConfigExample = {
115
+ const clientConfig = {
155
116
  parameters: {
156
117
  clientId: "<your-client-id>",
157
118
  organizationId: "<your-org-id>",
@@ -161,63 +122,54 @@ const clientConfigExample = {
161
122
  // If not provided, it'll use the default production URI:
162
123
  // 'https://{shortCode}.api.commercecloud.salesforce.com/custom/{apiName}/{apiVersion}'
163
124
  // path parameters should be wrapped in curly braces like the default production URI
164
- baseUri: "<your-base-uri>"
125
+ baseUri: "<your-base-uri>",
165
126
  };
166
127
 
167
128
  // Required params: apiName, endpointPath, shortCode, organizaitonId
168
129
  // Required path params can be passed into:
169
130
  // options.customApiPathParameters or clientConfig.parameters
170
- const customApiArgs = {
171
- apiName: 'loyalty-info',
172
- apiVersion: 'v1', // defaults to v1 if not provided
173
- endpointPath: 'customers'
174
- }
131
+ const customApiPathParameters = {
132
+ apiName: "loyalty-info",
133
+ apiVersion: "v1", // defaults to v1 if not provided
134
+ endpointPath: "customers",
135
+ };
175
136
 
176
- const accessToken = '<INSERT ACCESS TOKEN HERE>';
137
+ const accessToken = "<INSERT ACCESS TOKEN HERE>";
177
138
 
178
- let getResponse = await helpers.callCustomEndpoint({
139
+ await helpers.callCustomEndpoint({
179
140
  options: {
180
- method: 'GET',
141
+ method: "GET",
181
142
  parameters: {
182
- queryParameter: 'queryParameter1',
143
+ queryParameter: "queryParameter1",
183
144
  },
184
145
  headers: {
185
146
  // Content-Type is defaulted to application/json if not provided
186
- 'Content-Type': 'application/json',
187
- authorization: `Bearer ${access_token}`
147
+ "Content-Type": "application/json",
148
+ authorization: `Bearer ${accessToken}`,
188
149
  },
189
- customApiPathParameters: customApiArgs
190
- },
191
- clientConfig: clientConfigExample,
192
- // Flag to retrieve raw response or data from helper function
193
- rawResponse: false,
194
- })
195
-
196
- let postResponse = await helpers.callCustomEndpoint({
150
+ customApiPathParameters,
151
+ },
152
+ clientConfig,
153
+ });
154
+
155
+ await helpers.callCustomEndpoint({
197
156
  options: {
198
- method: 'POST',
157
+ method: "POST",
199
158
  parameters: {
200
- queryParameter: 'queryParameter1',
159
+ queryParameter: "queryParameter1",
201
160
  },
202
161
  headers: {
203
- authorization: `Bearer ${access_token}`
162
+ authorization: `Bearer ${accessToken}`,
204
163
  },
205
- customApiPathParameters: customApiArgs,
206
- body: JSON.stringify({ data: 'data' })
207
- },
208
- clientConfig: clientConfigExample,
209
- // Flag to retrieve raw response or data from helper function
210
- rawResponse: false,
211
- })
212
-
213
- console.log('get response: ', getResponse)
214
- console.log('post response: ', postResponse)
164
+ customApiPathParameters,
165
+ body: JSON.stringify({ data: "data" }),
166
+ },
167
+ clientConfig,
168
+ });
215
169
  ```
216
170
 
217
171
  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).
218
172
 
219
- For more information about custom APIs, please refer to the [Salesforce Developer Docs](https://developer.salesforce.com/docs/commerce/commerce-api/guide/custom-apis.html)
220
-
221
173
  ## License Information
222
174
 
223
175
  The Commerce SDK Isomorphic is licensed under BSD-3-Clause license. See the [license](./LICENSE.txt) for details.