Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
# CHANGELOG

## v4.1.0

### Enhancements

- Allow developers to pass in custom fetch implementation via `clientConfig` [#246](https://github.com/SalesforceCommerceCloud/commerce-sdk-isomorphic/pull/246)
- Support subpath imports for individual APIs and named imports [#219](https://github.com/SalesforceCommerceCloud/commerce-sdk-isomorphic/pull/219)
## v4.0.1

### Bug Fixes

- Fix incorrect encoding of multi-segment endpoint paths in `callCustomEndpoint` [#246](https://github.com/SalesforceCommerceCloud/commerce-sdk-isomorphic/pull/246)

## v4.0.0
Expand Down
115 changes: 1 addition & 114 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,7 @@ yarn install commerce-sdk-isomorphic
### Usage

```javascript
import ocapi from 'commerce-sdk-isomorphic';
const { helpers, ShopperLogin, ShopperSearch } = ocapi;

// Named imports also work
// import {helpers, ShopperLogin, ShopperSearch} from 'commerce-sdk-isomorphic';

// Alternatively, you can use subpath imports to import a single API at a time instead of the entire SDK
// Useful for when you want a slimmer bundle size and only need a single API
// import * as helpers from 'commerce-sdk-isomorphic/helpers'
// import { ShopperProducts } from 'commerce-sdk-isomorphic/shopperProducts';
// import { ShopperSearch } from 'commerce-sdk-isomorphic/shopperSearch';
import {helpers, ShopperLogin, ShopperSearch} from 'commerce-sdk-isomorphic';

const config = {
// SCAPI does not support CORS, so client side requests must use a reverse proxy.
Expand Down Expand Up @@ -103,91 +93,6 @@ const searchResult = await shopperSearch.productSearch({
});
```

#### Import Strategies

The SDK supports multiple import patterns to accommodate different use cases:

**Default Import (Full SDK)**
```javascript
import ocapi from 'commerce-sdk-isomorphic';
const { helpers, ShopperLogin, ShopperSearch } = ocapi;
```

**Named Imports (Full SDK)**
```javascript
import { helpers, ShopperLogin, ShopperSearch } from 'commerce-sdk-isomorphic';
```

**Subpath Imports (Individual APIs and Common dependencies)**

*ESM (ES Modules):*
```javascript
import { ShopperLogin } from 'commerce-sdk-isomorphic/shopperLogin';
import * as helpers from 'commerce-sdk-isomorphic/helpers';
```

*CommonJS:*
```javascript
const { ShopperLogin } = require('commerce-sdk-isomorphic/shopperLogin');
const helpers = require('commerce-sdk-isomorphic/helpers');
```

#### Choosing the Right Import Strategy

**Use Default/Named Imports when:**
- You need multiple APIs from the SDK
- You want the smallest overall bundle size for comprehensive usage
- The entire SDK is optimized and maximally compressed as a single bundle

**Note:** Default and named imports load the entire SDK, including all APIs, helpers, and dependencies.

**Use Subpath Imports when:**
- You only need specific APIs
- You want to minimize initial bundle size
- You're implementing dynamic loading for better page performance
- You need granular control over which APIs are loaded

**Note:** While subpath imports reduce initial bundle size, using them for all APIs will result in a larger total bundle size due to duplicated dependencies required for standalone operation.

#### Custom Fetch function

You can provide your own custom fetch function to intercept, log, or modify all SDK requests. This is useful for:
- **Request/Response Logging**: Track all API calls for debugging and monitoring
- **Request Interception**: Add custom headers, modify request URLs, or implement custom retry logic
- **Error Handling**: Add custom error processing or transformation before responses reach your application
- **Performance Monitoring**: Measure request/response times and track API performance metrics

**Example with Logging:**
```javascript
// Custom fetch function with detailed logging
const customFetch = async (url, options) => {
console.log(`[SDK Request] ${options?.method || 'GET'} ${url}`);
console.log('[SDK Request Headers]', options?.headers);
if (options?.body) {
console.log('[SDK Request Body]', options.body);
}

const startTime = Date.now();
const response = await fetch(url, options);
const duration = Date.now() - startTime;

console.log(`[SDK Response] ${response.status} ${response.statusText} (${duration}ms)`);
console.log('[SDK Response Headers]', Object.fromEntries(response.headers.entries()));

return response;
};

const config = {
parameters: {
clientId: '<your-client-id>',
organizationId: '<your-org-id>',
shortCode: '<your-short-code>',
siteId: '<your-site-id>',
},
fetch: customFetch,
};
```

#### Fetch Options

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.
Expand Down Expand Up @@ -379,24 +284,6 @@ console.log("categoriesResult: ", categoriesResult);

**NOTE: In the next major version release, path parameters will be single encoded by default**

## Unstable Releases

**⚠️ Important: Unstable/preview releases are experimental and not officially supported.**

Preview releases (e.g., preview, unstable, or pre-release versions) are provided for experimental purposes and early testing of upcoming features. These releases:

- **Are not intended for production use** - Do not use unstable releases in production environments
- **May contain breaking changes** - API signatures, behavior, and structure may change without notice
- **Are not officially supported** - No support, bug fixes, or security patches are guaranteed
- **May have incomplete features** - Functionality may be partially implemented or subject to change

**Use stable releases for production applications.** Only use unstable releases for:
- Testing upcoming features in development environments
- Providing feedback on new functionality before official release
- Experimental integrations that are not mission-critical

For production deployments, always use the latest stable release version available on npm.

## License Information

The Commerce SDK Isomorphic is licensed under BSD-3-Clause license. See the [license](./LICENSE.txt) for details.
2 changes: 1 addition & 1 deletion docs/assets/js/search.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/modules/version.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ <h3><span class="tsd-flag ts-flagConst">Const</span> USER_<wbr>AGENT_<wbr>HEADER
<section class="tsd-panel tsd-member tsd-kind-variable tsd-parent-kind-module">
<a name="user_agent_value" class="tsd-anchor"></a>
<h3><span class="tsd-flag ts-flagConst">Const</span> USER_<wbr>AGENT_<wbr>VALUE</h3>
<div class="tsd-signature tsd-kind-icon">USER_<wbr>AGENT_<wbr>VALUE<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">"commerce-sdk-isomorphic@4.1.0"</span><span class="tsd-signature-symbol"> = &quot;commerce-sdk-isomorphic@4.1.0&quot;</span></div>
<div class="tsd-signature tsd-kind-icon">USER_<wbr>AGENT_<wbr>VALUE<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">"commerce-sdk-isomorphic@4.0.1"</span><span class="tsd-signature-symbol"> = &quot;commerce-sdk-isomorphic@4.0.1&quot;</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in src/lib/version.ts:8</li>
Expand Down
2 changes: 0 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ module.exports = {
'src/static/**/*.{js,jsx,ts,tsx}',
'scripts/**/*.{js,jsx,ts,tsx}',
'!scripts/generate.ts',
'!scripts/generateFileList.ts',
'!scripts/updateApis.ts',
'!scripts/generateVersionTable.ts',
'!scripts/fileList.ts',
'!<rootDir>/node_modules/',
],
coverageReporters: ['text'],
Expand Down
115 changes: 24 additions & 91 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "commerce-sdk-isomorphic",
"version": "4.1.0",
"version": "4.0.1",
"private": false,
"description": "Salesforce Commerce SDK Isomorphic",
"bugs": {
Expand All @@ -11,94 +11,6 @@
"url": "git+https://github.com/SalesforceCommerceCloud/commerce-sdk-isomorphic.git"
},
"license": "BSD-3-Clause",
"sideEffects": false,
"exports": {
".": {
"import": "./lib/index.esm.js",
"require": "./lib/index.cjs.js"
},
"./shopperBaskets": {
"import": "./lib/shopperBaskets.js",
"require": "./lib/shopperBaskets.cjs.js"
},
"./shopperBasketsv2": {
"import": "./lib/shopperBasketsv2.js",
"require": "./lib/shopperBasketsv2.cjs.js"
},
"./shopperConsents": {
"import": "./lib/shopperConsents.js",
"require": "./lib/shopperConsents.cjs.js"
},
"./shopperContext": {
"import": "./lib/shopperContext.js",
"require": "./lib/shopperContext.cjs.js"
},
"./shopperCustomers": {
"import": "./lib/shopperCustomers.js",
"require": "./lib/shopperCustomers.cjs.js"
},
"./shopperExperience": {
"import": "./lib/shopperExperience.js",
"require": "./lib/shopperExperience.cjs.js"
},
"./shopperGiftCertificates": {
"import": "./lib/shopperGiftCertificates.js",
"require": "./lib/shopperGiftCertificates.cjs.js"
},
"./shopperLogin": {
"import": "./lib/shopperLogin.js",
"require": "./lib/shopperLogin.cjs.js"
},
"./shopperOrders": {
"import": "./lib/shopperOrders.js",
"require": "./lib/shopperOrders.cjs.js"
},
"./shopperProducts": {
"import": "./lib/shopperProducts.js",
"require": "./lib/shopperProducts.cjs.js"
},
"./shopperPromotions": {
"import": "./lib/shopperPromotions.js",
"require": "./lib/shopperPromotions.cjs.js"
},
"./shopperSearch": {
"import": "./lib/shopperSearch.js",
"require": "./lib/shopperSearch.cjs.js"
},
"./shopperSeo": {
"import": "./lib/shopperSeo.js",
"require": "./lib/shopperSeo.cjs.js"
},
"./shopperStores": {
"import": "./lib/shopperStores.js",
"require": "./lib/shopperStores.cjs.js"
},
"./helpers": {
"import": "./lib/helpers.js",
"require": "./lib/helpers.cjs.js"
},
"./clientConfig": {
"import": "./lib/clientConfig.js",
"require": "./lib/clientConfig.cjs.js"
},
"./config": {
"import": "./lib/config.js",
"require": "./lib/config.cjs.js"
},
"./responseError": {
"import": "./lib/responseError.js",
"require": "./lib/responseError.cjs.js"
},
"./templateUrl": {
"import": "./lib/templateUrl.js",
"require": "./lib/templateUrl.cjs.js"
},
"./version": {
"import": "./lib/version.js",
"require": "./lib/version.cjs.js"
},
"./package.json": "./package.json"
},
"main": "lib/index.cjs.js",
"module": "lib/index.esm.js",
"style": "lib/default.css",
Expand All @@ -109,7 +21,7 @@
],
"scripts": {
"build": "react-scripts build",
"build:lib": "ts-node --compiler-options '{\"module\": \"commonjs\", \"target\": \"ES6\" }' ./scripts/generateFileList.ts && rollup -c",
"build:lib": "rollup -c",
"check:size": "npm-pack-all --output commerce-sdk-isomorphic-with-deps.tgz && bundlesize",
"check:types": "tsc --noEmit",
"ci": "rm -rf node_modules && yarn install",
Expand All @@ -129,7 +41,7 @@
"start": "HTTPS=true react-scripts start",
"pretest": "yarn run lint && yarn run lint:style && depcheck && yarn run check:size",
"test": "yarn run check:types && yarn run test:unit && CI=true yarn run test:react",
"test:react": "react-scripts test --env=jest-environment-jsdom-sixteen src/environment --setupFilesAfterEnv ./src/test/setupTests.ts",
"test:react": "react-scripts test --env=jest-environment-jsdom-sixteen src/environment",
"test:unit": "jest --coverage --testPathIgnorePatterns node_modules src/environment --silent",
"updateApis": "ts-node --compiler-options '{\"module\": \"commonjs\", \"target\": \"ES6\" }' ./scripts/updateApis.ts && yarn diffApis"
},
Expand Down Expand Up @@ -157,6 +69,27 @@
"last 1 safari version"
]
},
"jest": {
"collectCoverageFrom": [
"src/static/**/*.{js,jsx,ts,tsx}",
"scripts/**/*.{js,jsx,ts,tsx}",
"!scripts/generate.ts",
"!scripts/updateApis.ts",
"!scripts/generateVersionTable.ts",
"!<rootDir>/node_modules/"
],
"coverageReporters": [
"text"
],
"coverageThreshold": {
"global": {
"branches": 90,
"functions": 90,
"lines": 90,
"statements": 90
}
}
},
"resolutions": {
"**/@npmcli/fs": "<1.1.0",
"**/@oclif/command": "<=1.8.3",
Expand Down
Loading
Loading