@commercengine/storefront-sdk-nextjs 0.2.10 → 0.3.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/MIGRATION.md +89 -0
- package/README.md +180 -440
- package/dist/client.d.mts +4 -4
- package/dist/client.mjs +9 -9
- package/dist/index.d.mts +23 -24
- package/dist/index.mjs +13 -35
- package/dist/manager.d.mts +18 -13
- package/dist/manager.mjs +67 -50
- package/dist/server.d.mts +3 -3
- package/dist/server.mjs +3 -3
- package/package.json +5 -4
package/MIGRATION.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# Storefront SDK Next.js Migration Guide
|
|
2
|
+
|
|
3
|
+
This guide covers the breaking API changes in
|
|
4
|
+
`@commercengine/storefront-sdk-nextjs`.
|
|
5
|
+
|
|
6
|
+
## Summary
|
|
7
|
+
|
|
8
|
+
- `storefront()` was replaced by explicit `storefront.public()` and
|
|
9
|
+
`storefront.session(...)`
|
|
10
|
+
- `isRootLayout` was removed
|
|
11
|
+
- root layouts and public server reads now use `storefront.public()`
|
|
12
|
+
- server-side session usage now always uses `storefront.session(await cookies())`
|
|
13
|
+
- client-side session usage uses `storefront.session()`
|
|
14
|
+
|
|
15
|
+
## Before / After
|
|
16
|
+
|
|
17
|
+
### Public server reads
|
|
18
|
+
|
|
19
|
+
Before:
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
const sdk = storefront({ isRootLayout: true });
|
|
23
|
+
const { data } = await sdk.catalog.listProducts();
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
After:
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
const sdk = storefront.public();
|
|
30
|
+
const { data } = await sdk.catalog.listProducts();
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Server components, server actions, and route handlers
|
|
34
|
+
|
|
35
|
+
Before:
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
const sdk = storefront(await cookies());
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
After:
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
const sdk = storefront.session(await cookies());
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Client components
|
|
48
|
+
|
|
49
|
+
Before:
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
const sdk = storefront();
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
After:
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
const sdk = storefront.session();
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## New Mental Model
|
|
62
|
+
|
|
63
|
+
Use `storefront.public()` for:
|
|
64
|
+
|
|
65
|
+
- root layouts
|
|
66
|
+
- static generation
|
|
67
|
+
- ISR pages
|
|
68
|
+
- public server-rendered catalog or helper reads
|
|
69
|
+
|
|
70
|
+
Use `storefront.session()` / `storefront.session(await cookies())` for:
|
|
71
|
+
|
|
72
|
+
- auth flows
|
|
73
|
+
- cart reads and mutations
|
|
74
|
+
- customer reads and mutations
|
|
75
|
+
- order and payment flows
|
|
76
|
+
- any request that should participate in anonymous or authenticated session
|
|
77
|
+
continuity
|
|
78
|
+
|
|
79
|
+
## Root Layouts
|
|
80
|
+
|
|
81
|
+
There is no special root-layout escape hatch anymore.
|
|
82
|
+
|
|
83
|
+
Root layouts should:
|
|
84
|
+
|
|
85
|
+
- use `storefront.public()` for public reads
|
|
86
|
+
- mount `StorefrontSDKInitializer` to eagerly bootstrap the browser session
|
|
87
|
+
|
|
88
|
+
If a server component needs request-bound session continuity, move that call to a
|
|
89
|
+
request-aware boundary and use `storefront.session(await cookies())`.
|