Skip to content

Commit 87d3e44

Browse files
authored
Deprecate default export (#371)
2 parents 95b121a + d96e470 commit 87d3e44

8 files changed

Lines changed: 62 additions & 14 deletions

File tree

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
## [8.0.0-beta.8](https://github.com/commercelayer/commercelayer-sdk/compare/v8.0.0-beta.7...v8.0.0-beta.8) (2026-07-02)
2+
3+
### Features
4+
5+
* add `@since` JSDoc annotations — counterpart to `@deprecated`. ([c1ff52b](https://github.com/commercelayer/commercelayer-sdk/commit/c1ff52b1213df610fb4d3d45e15e5542594da6bc))
6+
* add SDK version to request headers ([0d66f57](https://github.com/commercelayer/commercelayer-sdk/commit/0d66f574fbc7b3770ddde86bfb8fd2fdab58f3cb))
7+
* add support for `versions` attribute in schema ([a54ba3d](https://github.com/commercelayer/commercelayer-sdk/commit/a54ba3d623a907c62ab5b237e20b8076ffc723fc))
8+
* isolate client config between multiple instances ([39ee08a](https://github.com/commercelayer/commercelayer-sdk/commit/39ee08a33d3251c3c4a37e49a0b95983378559e2))
9+
* use `bundle` mode as default. Default one will become the `single-client` version ([788655d](https://github.com/commercelayer/commercelayer-sdk/commit/788655d2faf8a0710e75bb36ab7b2c567be5bf2c))
10+
* use children type for payment settings, promotions, ([7dc99ed](https://github.com/commercelayer/commercelayer-sdk/commit/7dc99edd823924d967d63a556923e0c40d622a0f))
11+
112
## [8.0.0-beta.7](https://github.com/commercelayer/commercelayer-sdk/compare/v8.0.0-beta.6...v8.0.0-beta.7) (2026-06-25)
213

314
### ⚠ BREAKING CHANGES

README.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ All requests to Commerce Layer API must be authenticated with an [OAuth2](https:
5858
5959
### Import
6060

61-
The SDK supports two import approaches. **Use the bundled client by default**, the selective import pattern is available for specific use cases but comes with important caveats described below.
61+
The SDK offers two import styles. **The default entry is the bundled client** — use it unless you have a specific reason not to. The selective (tree-shakeable) style lives on a separate subpath and carries an important caveat described below.
6262

63-
#### Bundled client import
63+
#### Bundled client (default)
6464

6565
```javascript
66-
import { CommerceLayer } from '@commercelayer/sdk/bundle'
66+
import { CommerceLayer } from '@commercelayer/sdk'
6767

6868
const cl = CommerceLayer({
6969
accessToken: 'your-access-token'
@@ -73,12 +73,22 @@ const orderList = await cl.orders.list()
7373
const skuList = await cl.skus.list()
7474
```
7575

76-
All resource accessors are available directly on the client object. This increases your final bundle size but keeps all resource calls scoped to a specific client instance.
76+
All resource accessors are available directly on the client object. This increases your final bundle size, but every call is scoped to that specific client instance — so you can safely create and use **multiple clients with different access tokens at the same time** (multi-tenant apps, serverless with connection reuse, etc.):
7777

78-
#### Selective resource imports
78+
```javascript
79+
const clUS = CommerceLayer({ accessToken: usToken })
80+
const clEU = CommerceLayer({ accessToken: euToken })
81+
82+
const [usOrders, euOrders] = await Promise.all([
83+
clUS.orders.list(),
84+
clEU.orders.list()
85+
]) // each request uses its own token
86+
```
87+
88+
#### Selective resource imports (`/single-client`)
7989

8090
```javascript
81-
import CommerceLayer, { orders, skus } from '@commercelayer/sdk'
91+
import { CommerceLayer, orders, skus } from '@commercelayer/sdk/single-client'
8292

8393
const cl = CommerceLayer({
8494
accessToken: 'your-access-token'
@@ -88,9 +98,9 @@ const orderList = await orders.list()
8898
const skuList = await skus.list()
8999
```
90100

91-
Only the imported resources are included in your bundle. However, imported resources share a single global SDK configuration. If two requests are in-flight simultaneously with different access tokens (common in serverless environments with connection reuse, or in any multi-tenant context), they may silently use the wrong token.
101+
Only the imported resources are included in your bundle, so it produces the smallest output. The trade-off: imported resources share **a single global SDK configuration**. If two requests are in-flight simultaneously with different access tokens, they may silently use the wrong token — so this style supports only **one active token at a time**.
92102

93-
It is a good fit for edge/serverless functions or webhook handlers that use only a few resources and a single token active at a time.
103+
It is a good fit for edge/serverless functions or webhook handlers that use only a few resources and a single token. When you need multiple concurrent tokens, use the bundled client above.
94104

95105
### Options
96106

@@ -129,6 +139,8 @@ The JavaScript SDK is a wrapper around Commerce Layer API which means you would
129139

130140
To show you how things work, we will use the [SKUs](https://docs.commercelayer.io/core/v/api-reference/skus) and [Shipping Categories](https://docs.commercelayer.io/core/v/api-reference/shipping_categories) resource in the following examples. The code snippets below show how to use the SDK when performing the standard CRUD operations provided by our REST API. Kindly check our [API reference](https://docs.commercelayer.io/core/v/api-reference) for the complete list of available **resources** and their **attributes**.
131141

142+
> The examples below use the selective style (`skus.create(...)`, imported from `@commercelayer/sdk/single-client`) for brevity. With the default **bundled client**, call the same methods through the client instance instead — e.g. `cl.skus.create(...)`, `cl.shipping_categories.list(...)`.
143+
132144
### Create
133145

134146
<details>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@commercelayer/sdk",
3-
"version": "8.0.0-beta.7",
3+
"version": "8.0.0-beta.8",
44
"main": "lib/index.cjs",
55
"types": "lib/index.d.ts",
66
"module": "lib/index.js",

specs/bundle-smoke.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, test } from 'vitest'
2-
import CommerceLayer from '../src' // default entry === the bundle client
2+
import { CommerceLayer } from '../src' // default entry === the bundle client
33
import { handleError, interceptRequest } from '../test/common'
44

55
// Smoke coverage for the DEFAULT entry (the bundle). The exhaustive

src/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,19 @@
22
// isolated per client). For the lightweight, tree-shakeable single-client
33
// model (direct resource imports, one global token) use
44
// `@commercelayer/sdk/single-client`.
5-
export { CommerceLayer, type CommerceLayerBundle, default } from './bundle'
5+
import { CommerceLayer, type CommerceLayerBundle } from './bundle'
6+
67
export { SDK_VERSION } from './commercelayer'
8+
// Preferred: the named export. Clean, and the form we're standardising on.
9+
export { CommerceLayer, type CommerceLayerBundle }
10+
11+
/**
12+
* @deprecated Use the named import instead:
13+
* `import { CommerceLayer } from '@commercelayer/sdk'`. The default export is
14+
* kept for backwards compatibility and will be removed in a future major.
15+
*/
16+
const CommerceLayerDefault = CommerceLayer
17+
export default CommerceLayerDefault
718

819
// Commerce Layer static functions
920
export { CommerceLayerStatic } from './static'

src/single-client.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
// Resource adapters
22
export * from './api'
3+
34
// SDK
4-
export { CommerceLayer, default, SDK_VERSION } from './commercelayer'
5+
import { CommerceLayer } from './commercelayer'
6+
7+
// Preferred: the named export. Clean, and the form we're standardising on.
8+
export { CommerceLayer, SDK_VERSION } from './commercelayer'
9+
10+
/**
11+
* @deprecated Use the named import instead:
12+
* `import { CommerceLayer } from '@commercelayer/sdk/single-client'`. The
13+
* default export is kept for backwards compatibility and will be removed in
14+
* a future major.
15+
*/
16+
const CommerceLayerDefault = CommerceLayer
17+
export default CommerceLayerDefault
518

619
// Commerce Layer static functions
720
export { CommerceLayerStatic } from './static'

test/common.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { inspect, isDeepStrictEqual } from 'node:util'
22
import dotenv from 'dotenv'
33
import { API_SCHEMA_VERSION } from '../src/commercelayer'
4-
import CommerceLayer, {
4+
import {
5+
CommerceLayer,
56
type CommerceLayerClient,
67
type CommerceLayerConfig,
78
type QueryParamsList,

test/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { inspect } from 'node:util'
2-
import CommerceLayer, { type CommerceLayerClient, type CommerceLayerInitConfig, CommerceLayerStatic } from '../src'
2+
import { CommerceLayer, type CommerceLayerClient, type CommerceLayerInitConfig, CommerceLayerStatic } from '../src'
33
import getToken, { type AccessToken } from './token'
44

55
export const getAccessToken = async (env?: string): Promise<AccessToken> => {

0 commit comments

Comments
 (0)