@commercengine/storefront-sdk 0.14.1 → 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 +8 -3
- package/dist/index.iife.js +8 -3
- package/dist/index.iife.js.map +1 -1
- package/dist/index.mjs +8 -3
- 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
|
@@ -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;
|
|
@@ -13976,8 +13980,9 @@ declare class BaseCatalogClient extends StorefrontAPIClientBase {
|
|
|
13976
13980
|
/**
|
|
13977
13981
|
* Storefront API client that always authenticates with `X-Api-Key`.
|
|
13978
13982
|
*
|
|
13979
|
-
* This
|
|
13980
|
-
*
|
|
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()`.
|
|
13981
13986
|
*/
|
|
13982
13987
|
declare class PublicStorefrontAPIClient extends StorefrontAPIClientBase {
|
|
13983
13988
|
constructor(config: StorefrontClientBaseConfig);
|
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;
|
|
@@ -1587,8 +1591,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1587
1591
|
/**
|
|
1588
1592
|
* Storefront API client that always authenticates with `X-Api-Key`.
|
|
1589
1593
|
*
|
|
1590
|
-
* This
|
|
1591
|
-
*
|
|
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()`.
|
|
1592
1597
|
*/
|
|
1593
1598
|
var PublicStorefrontAPIClient = class extends StorefrontAPIClientBase {
|
|
1594
1599
|
constructor(config) {
|