@commercengine/storefront-sdk 0.14.0 → 0.14.2
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/MIGRATION.md +3 -0
- package/README.md +41 -6
- package/dist/index.d.mts +27 -17
- package/dist/index.iife.js +45 -25
- package/dist/index.iife.js.map +1 -1
- package/dist/index.mjs +45 -25
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/MIGRATION.md
CHANGED
|
@@ -40,6 +40,9 @@ const publicSdk = storefront.public();
|
|
|
40
40
|
const sessionSdk = storefront.session();
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
+
The factory owns one cached public SDK and one cached default session SDK, so
|
|
44
|
+
most applications only need a single shared `storefront` export.
|
|
45
|
+
|
|
43
46
|
## Before / After
|
|
44
47
|
|
|
45
48
|
### Managed session SDK
|
package/README.md
CHANGED
|
@@ -5,6 +5,11 @@ A powerful, type-safe TypeScript SDK for the CommerceEngine Storefront API. Buil
|
|
|
5
5
|
Breaking changes from the previous SDK surface are documented in
|
|
6
6
|
[MIGRATION.md](./MIGRATION.md).
|
|
7
7
|
|
|
8
|
+
If you are building an application on an official framework wrapper such as
|
|
9
|
+
Next.js, prefer [`@commercengine/storefront`](../storefront/README.md). This
|
|
10
|
+
package is the standalone isomorphic core SDK for SPA usage, advanced custom
|
|
11
|
+
integrations, and framework bindings.
|
|
12
|
+
|
|
8
13
|
**✨ Key Features:**
|
|
9
14
|
- **100% Type Safe**: Every API endpoint is fully typed with TypeScript
|
|
10
15
|
- **Automatic Token Management**: Built-in refresh token logic for seamless authentication
|
|
@@ -51,6 +56,11 @@ const { data: products } = await storefront.public().catalog.listProducts();
|
|
|
51
56
|
const { data: wishlist } = await storefront.session().cart.getWishlist();
|
|
52
57
|
```
|
|
53
58
|
|
|
59
|
+
`createStorefront()` returns one cached public SDK and one cached default
|
|
60
|
+
session SDK for that factory instance. Use `storefront.session(overrides)` only
|
|
61
|
+
for one-off, token-seeded/stateless cases that should not reuse the default
|
|
62
|
+
session client.
|
|
63
|
+
|
|
54
64
|
## Configuration Options
|
|
55
65
|
|
|
56
66
|
The SDK supports extensive configuration to fit your needs:
|
|
@@ -121,6 +131,18 @@ const sdk = new SessionStorefrontSDK({
|
|
|
121
131
|
});
|
|
122
132
|
```
|
|
123
133
|
|
|
134
|
+
If you need the raw public transport classes directly, the advanced exports are
|
|
135
|
+
also available:
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
import {
|
|
139
|
+
PublicStorefrontAPIClient,
|
|
140
|
+
PublicStorefrontSDK,
|
|
141
|
+
SessionStorefrontAPIClient,
|
|
142
|
+
SessionStorefrontSDK,
|
|
143
|
+
} from "@commercengine/storefront-sdk";
|
|
144
|
+
```
|
|
145
|
+
|
|
124
146
|
## Token Management
|
|
125
147
|
|
|
126
148
|
The SDK supports three primary access patterns:
|
|
@@ -210,7 +232,7 @@ import { BrowserTokenStorage } from "@commercengine/storefront-sdk";
|
|
|
210
232
|
const tokenStorage = new BrowserTokenStorage("myapp_"); // Optional prefix
|
|
211
233
|
```
|
|
212
234
|
|
|
213
|
-
####
|
|
235
|
+
#### Browser cookies (for browser persistence or cross-tab sync)
|
|
214
236
|
```typescript
|
|
215
237
|
import { CookieTokenStorage } from "@commercengine/storefront-sdk";
|
|
216
238
|
|
|
@@ -222,6 +244,12 @@ const tokenStorage = new CookieTokenStorage({
|
|
|
222
244
|
});
|
|
223
245
|
```
|
|
224
246
|
|
|
247
|
+
`CookieTokenStorage` uses `document.cookie` and is browser-only. It is useful
|
|
248
|
+
for browser cookie persistence and cross-tab visibility, but it is **not**
|
|
249
|
+
request-aware SSR storage. For framework server/client continuity, use an
|
|
250
|
+
official wrapper from `@commercengine/storefront` or a request-aware storage
|
|
251
|
+
adapter from `@commercengine/ssr-utils`.
|
|
252
|
+
|
|
225
253
|
#### Memory (for server-side or temporary storage)
|
|
226
254
|
```typescript
|
|
227
255
|
import { MemoryTokenStorage } from "@commercengine/storefront-sdk";
|
|
@@ -246,7 +274,14 @@ class CustomTokenStorage implements TokenStorage {
|
|
|
246
274
|
|
|
247
275
|
## Authentication
|
|
248
276
|
|
|
249
|
-
If you use managed sessions (`tokenStorage`), you usually do not need to call
|
|
277
|
+
If you use managed sessions (`tokenStorage`), you usually do not need to call
|
|
278
|
+
anonymous auth manually. The SDK can bootstrap anonymous sessions
|
|
279
|
+
automatically on token-required requests.
|
|
280
|
+
|
|
281
|
+
That lazy bootstrap is a core SDK capability, not necessarily the primary app
|
|
282
|
+
pattern for every framework. For official framework wrappers, the recommended
|
|
283
|
+
pattern is still to bootstrap explicitly in app code when later server-side
|
|
284
|
+
session reads depend on established cookie continuity.
|
|
250
285
|
|
|
251
286
|
### Anonymous Authentication
|
|
252
287
|
```typescript
|
|
@@ -467,10 +502,10 @@ The SDK works seamlessly across all JavaScript environments:
|
|
|
467
502
|
- **Background jobs**: Reliable token management for long-running processes
|
|
468
503
|
|
|
469
504
|
### Hybrid Rendering (SSR/SSG)
|
|
470
|
-
- **
|
|
471
|
-
- **
|
|
472
|
-
- **
|
|
473
|
-
- **Hydration-safe**:
|
|
505
|
+
- **Official framework wrappers**: Prefer `@commercengine/storefront`
|
|
506
|
+
- **Custom SSR integrations**: Use request-aware storage from `@commercengine/ssr-utils`
|
|
507
|
+
- **CookieTokenStorage**: Browser-only cookie persistence, not server request storage
|
|
508
|
+
- **Hydration-safe setups**: depend on framework-aware request storage, not `document.cookie`
|
|
474
509
|
|
|
475
510
|
## Best Practices Built-In
|
|
476
511
|
|
package/dist/index.d.mts
CHANGED
|
@@ -12582,7 +12582,7 @@ type StorefrontClientBaseConfig = BaseSDKOptions<SupportedDefaultHeaders> & {
|
|
|
12582
12582
|
* decisions to the public and session-specific subclasses.
|
|
12583
12583
|
*/
|
|
12584
12584
|
declare class StorefrontAPIClientBase extends BaseAPIClient<paths, SupportedDefaultHeaders> {
|
|
12585
|
-
|
|
12585
|
+
apiKey?: string;
|
|
12586
12586
|
constructor(config: StorefrontClientBaseConfig);
|
|
12587
12587
|
setApiKey(apiKey: string): void;
|
|
12588
12588
|
clearApiKey(): void;
|
|
@@ -12595,7 +12595,11 @@ type SessionStorefrontClientConfig = StorefrontClientBaseConfig & SessionStorefr
|
|
|
12595
12595
|
};
|
|
12596
12596
|
/**
|
|
12597
12597
|
* Storefront API client that extends the generic BaseAPIClient
|
|
12598
|
-
* Adds Commerce Engine specific authentication and token management
|
|
12598
|
+
* Adds Commerce Engine specific authentication and token management.
|
|
12599
|
+
*
|
|
12600
|
+
* Session-only domain clients can extend this directly. Shared public/session
|
|
12601
|
+
* read clients may instead extend a shared base class and call
|
|
12602
|
+
* `attachSessionAuth()` explicitly in their concrete session wrapper.
|
|
12599
12603
|
*/
|
|
12600
12604
|
declare class SessionStorefrontAPIClient extends StorefrontAPIClientBase {
|
|
12601
12605
|
protected config: SessionStorefrontClientConfig;
|
|
@@ -13972,11 +13976,25 @@ declare class BaseCatalogClient extends StorefrontAPIClientBase {
|
|
|
13972
13976
|
listSimilarProducts(options?: ListSimilarProductsQuery, headers?: ListSimilarProductsHeaderParams): Promise<ApiResult<ListSimilarProductsContent>>;
|
|
13973
13977
|
}
|
|
13974
13978
|
//#endregion
|
|
13979
|
+
//#region src/lib/public/client.d.ts
|
|
13980
|
+
/**
|
|
13981
|
+
* Storefront API client that always authenticates with `X-Api-Key`.
|
|
13982
|
+
*
|
|
13983
|
+
* This class is kept as the advanced public transport client. Concrete public
|
|
13984
|
+
* domain clients can either extend this directly or extend a shared base class
|
|
13985
|
+
* and attach the same auth behavior via `attachPublicAuth()`.
|
|
13986
|
+
*/
|
|
13987
|
+
declare class PublicStorefrontAPIClient extends StorefrontAPIClientBase {
|
|
13988
|
+
constructor(config: StorefrontClientBaseConfig);
|
|
13989
|
+
}
|
|
13990
|
+
//#endregion
|
|
13975
13991
|
//#region src/lib/public/catalog.d.ts
|
|
13976
13992
|
/**
|
|
13977
13993
|
* Client for interacting with catalog endpoints
|
|
13978
13994
|
*/
|
|
13979
|
-
declare class PublicCatalogClient extends BaseCatalogClient {
|
|
13995
|
+
declare class PublicCatalogClient extends BaseCatalogClient {
|
|
13996
|
+
constructor(config: ConstructorParameters<typeof PublicStorefrontAPIClient>[0]);
|
|
13997
|
+
}
|
|
13980
13998
|
//#endregion
|
|
13981
13999
|
//#region src/lib/catalog.d.ts
|
|
13982
14000
|
/**
|
|
@@ -15916,7 +15934,9 @@ declare class BaseHelpersClient extends StorefrontAPIClientBase {
|
|
|
15916
15934
|
/**
|
|
15917
15935
|
* Client for interacting with helper endpoints
|
|
15918
15936
|
*/
|
|
15919
|
-
declare class PublicHelpersClient extends BaseHelpersClient {
|
|
15937
|
+
declare class PublicHelpersClient extends BaseHelpersClient {
|
|
15938
|
+
constructor(config: ConstructorParameters<typeof PublicStorefrontAPIClient>[0]);
|
|
15939
|
+
}
|
|
15920
15940
|
//#endregion
|
|
15921
15941
|
//#region src/lib/helper.d.ts
|
|
15922
15942
|
/**
|
|
@@ -16276,7 +16296,9 @@ declare class BaseStoreConfigClient extends StorefrontAPIClientBase {
|
|
|
16276
16296
|
/**
|
|
16277
16297
|
* Client for interacting with store config endpoints
|
|
16278
16298
|
*/
|
|
16279
|
-
declare class PublicStoreConfigClient extends BaseStoreConfigClient {
|
|
16299
|
+
declare class PublicStoreConfigClient extends BaseStoreConfigClient {
|
|
16300
|
+
constructor(config: ConstructorParameters<typeof PublicStorefrontAPIClient>[0]);
|
|
16301
|
+
}
|
|
16280
16302
|
//#endregion
|
|
16281
16303
|
//#region src/lib/store-config.d.ts
|
|
16282
16304
|
/**
|
|
@@ -16286,18 +16308,6 @@ declare class StoreConfigClient extends BaseStoreConfigClient {
|
|
|
16286
16308
|
constructor(config: ConstructorParameters<typeof SessionStorefrontAPIClient>[0]);
|
|
16287
16309
|
}
|
|
16288
16310
|
//#endregion
|
|
16289
|
-
//#region src/lib/public/client.d.ts
|
|
16290
|
-
/**
|
|
16291
|
-
* Storefront API client that always authenticates with `X-Api-Key`.
|
|
16292
|
-
*
|
|
16293
|
-
* This client is used by the public storefront surface where no session or
|
|
16294
|
-
* token lifecycle should be involved.
|
|
16295
|
-
*/
|
|
16296
|
-
declare class PublicStorefrontAPIClient extends StorefrontAPIClientBase {
|
|
16297
|
-
constructor(config: StorefrontClientBaseConfig);
|
|
16298
|
-
private setupPublicAuth;
|
|
16299
|
-
}
|
|
16300
|
-
//#endregion
|
|
16301
16311
|
//#region src/index.d.ts
|
|
16302
16312
|
/**
|
|
16303
16313
|
* Public SDK class for the Storefront API.
|
package/dist/index.iife.js
CHANGED
|
@@ -886,7 +886,11 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
886
886
|
}
|
|
887
887
|
/**
|
|
888
888
|
* Storefront API client that extends the generic BaseAPIClient
|
|
889
|
-
* Adds Commerce Engine specific authentication and token management
|
|
889
|
+
* Adds Commerce Engine specific authentication and token management.
|
|
890
|
+
*
|
|
891
|
+
* Session-only domain clients can extend this directly. Shared public/session
|
|
892
|
+
* read clients may instead extend a shared base class and call
|
|
893
|
+
* `attachSessionAuth()` explicitly in their concrete session wrapper.
|
|
890
894
|
*/
|
|
891
895
|
var SessionStorefrontAPIClient = class extends StorefrontAPIClientBase {
|
|
892
896
|
config;
|
|
@@ -1582,12 +1586,39 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1582
1586
|
}
|
|
1583
1587
|
};
|
|
1584
1588
|
|
|
1589
|
+
//#endregion
|
|
1590
|
+
//#region src/lib/public/client.ts
|
|
1591
|
+
/**
|
|
1592
|
+
* Storefront API client that always authenticates with `X-Api-Key`.
|
|
1593
|
+
*
|
|
1594
|
+
* This class is kept as the advanced public transport client. Concrete public
|
|
1595
|
+
* domain clients can either extend this directly or extend a shared base class
|
|
1596
|
+
* and attach the same auth behavior via `attachPublicAuth()`.
|
|
1597
|
+
*/
|
|
1598
|
+
var PublicStorefrontAPIClient = class extends StorefrontAPIClientBase {
|
|
1599
|
+
constructor(config) {
|
|
1600
|
+
super(config);
|
|
1601
|
+
attachPublicAuth(this);
|
|
1602
|
+
}
|
|
1603
|
+
};
|
|
1604
|
+
function attachPublicAuth(client) {
|
|
1605
|
+
client.useMiddleware({ onRequest: async ({ request }) => {
|
|
1606
|
+
if (client.apiKey) request.headers.set("X-Api-Key", client.apiKey);
|
|
1607
|
+
return request;
|
|
1608
|
+
} });
|
|
1609
|
+
}
|
|
1610
|
+
|
|
1585
1611
|
//#endregion
|
|
1586
1612
|
//#region src/lib/public/catalog.ts
|
|
1587
1613
|
/**
|
|
1588
1614
|
* Client for interacting with catalog endpoints
|
|
1589
1615
|
*/
|
|
1590
|
-
var PublicCatalogClient = class extends BaseCatalogClient {
|
|
1616
|
+
var PublicCatalogClient = class extends BaseCatalogClient {
|
|
1617
|
+
constructor(config) {
|
|
1618
|
+
super(config);
|
|
1619
|
+
attachPublicAuth(this);
|
|
1620
|
+
}
|
|
1621
|
+
};
|
|
1591
1622
|
|
|
1592
1623
|
//#endregion
|
|
1593
1624
|
//#region src/lib/catalog.ts
|
|
@@ -3617,7 +3648,12 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
3617
3648
|
/**
|
|
3618
3649
|
* Client for interacting with helper endpoints
|
|
3619
3650
|
*/
|
|
3620
|
-
var PublicHelpersClient = class extends BaseHelpersClient {
|
|
3651
|
+
var PublicHelpersClient = class extends BaseHelpersClient {
|
|
3652
|
+
constructor(config) {
|
|
3653
|
+
super(config);
|
|
3654
|
+
attachPublicAuth(this);
|
|
3655
|
+
}
|
|
3656
|
+
};
|
|
3621
3657
|
|
|
3622
3658
|
//#endregion
|
|
3623
3659
|
//#region src/lib/helper.ts
|
|
@@ -3761,7 +3797,12 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
3761
3797
|
/**
|
|
3762
3798
|
* Client for interacting with store config endpoints
|
|
3763
3799
|
*/
|
|
3764
|
-
var PublicStoreConfigClient = class extends BaseStoreConfigClient {
|
|
3800
|
+
var PublicStoreConfigClient = class extends BaseStoreConfigClient {
|
|
3801
|
+
constructor(config) {
|
|
3802
|
+
super(config);
|
|
3803
|
+
attachPublicAuth(this);
|
|
3804
|
+
}
|
|
3805
|
+
};
|
|
3765
3806
|
|
|
3766
3807
|
//#endregion
|
|
3767
3808
|
//#region src/lib/store-config.ts
|
|
@@ -4493,27 +4534,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
4493
4534
|
}
|
|
4494
4535
|
};
|
|
4495
4536
|
|
|
4496
|
-
//#endregion
|
|
4497
|
-
//#region src/lib/public/client.ts
|
|
4498
|
-
/**
|
|
4499
|
-
* Storefront API client that always authenticates with `X-Api-Key`.
|
|
4500
|
-
*
|
|
4501
|
-
* This client is used by the public storefront surface where no session or
|
|
4502
|
-
* token lifecycle should be involved.
|
|
4503
|
-
*/
|
|
4504
|
-
var PublicStorefrontAPIClient = class extends StorefrontAPIClientBase {
|
|
4505
|
-
constructor(config) {
|
|
4506
|
-
super(config);
|
|
4507
|
-
this.setupPublicAuth();
|
|
4508
|
-
}
|
|
4509
|
-
setupPublicAuth() {
|
|
4510
|
-
this.client.use({ onRequest: async ({ request }) => {
|
|
4511
|
-
if (this.apiKey) request.headers.set("X-Api-Key", this.apiKey);
|
|
4512
|
-
return request;
|
|
4513
|
-
} });
|
|
4514
|
-
}
|
|
4515
|
-
};
|
|
4516
|
-
|
|
4517
4537
|
//#endregion
|
|
4518
4538
|
//#region src/index.ts
|
|
4519
4539
|
/**
|