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 +36 -0
- package/README.md +69 -117
- package/lib/index.cjs.d.ts +623 -179
- package/lib/index.cjs.js +1 -1
- package/lib/index.esm.d.ts +623 -179
- package/lib/index.esm.js +1 -1
- package/package.json +3 -3
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
|
-
|
|
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`
|
|
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
|
-
|
|
44
|
-
|
|
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
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
####
|
|
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
|
-
|
|
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
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
|
|
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
|
-
|
|
87
|
+
#### Additional Config Settings
|
|
123
88
|
|
|
124
|
-
|
|
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
|
-
|
|
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
|
|
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 [
|
|
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
|
|
112
|
+
import pkg from "commerce-sdk-isomorphic";
|
|
152
113
|
const { helpers } = pkg;
|
|
153
114
|
|
|
154
|
-
const
|
|
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
|
|
171
|
-
apiName:
|
|
172
|
-
apiVersion:
|
|
173
|
-
endpointPath:
|
|
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 =
|
|
137
|
+
const accessToken = "<INSERT ACCESS TOKEN HERE>";
|
|
177
138
|
|
|
178
|
-
|
|
139
|
+
await helpers.callCustomEndpoint({
|
|
179
140
|
options: {
|
|
180
|
-
method:
|
|
141
|
+
method: "GET",
|
|
181
142
|
parameters: {
|
|
182
|
-
queryParameter:
|
|
143
|
+
queryParameter: "queryParameter1",
|
|
183
144
|
},
|
|
184
145
|
headers: {
|
|
185
146
|
// Content-Type is defaulted to application/json if not provided
|
|
186
|
-
|
|
187
|
-
authorization: `Bearer ${
|
|
147
|
+
"Content-Type": "application/json",
|
|
148
|
+
authorization: `Bearer ${accessToken}`,
|
|
188
149
|
},
|
|
189
|
-
customApiPathParameters
|
|
190
|
-
},
|
|
191
|
-
clientConfig
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
let postResponse = await helpers.callCustomEndpoint({
|
|
150
|
+
customApiPathParameters,
|
|
151
|
+
},
|
|
152
|
+
clientConfig,
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
await helpers.callCustomEndpoint({
|
|
197
156
|
options: {
|
|
198
|
-
method:
|
|
157
|
+
method: "POST",
|
|
199
158
|
parameters: {
|
|
200
|
-
queryParameter:
|
|
159
|
+
queryParameter: "queryParameter1",
|
|
201
160
|
},
|
|
202
161
|
headers: {
|
|
203
|
-
authorization: `Bearer ${
|
|
162
|
+
authorization: `Bearer ${accessToken}`,
|
|
204
163
|
},
|
|
205
|
-
customApiPathParameters
|
|
206
|
-
body: JSON.stringify({ data:
|
|
207
|
-
},
|
|
208
|
-
clientConfig
|
|
209
|
-
|
|
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.
|