@akinon/next 2.0.23-rc.0 → 2.0.23
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/CHANGELOG.md +11 -23
- package/bin/pz-generate-routes.js +1 -4
- package/components/plugin-module.tsx +1 -0
- package/data/client/checkout.ts +1 -0
- package/data/server/category.ts +5 -14
- package/data/server/list.ts +4 -13
- package/data/server/product.ts +4 -11
- package/data/server/special-page.ts +4 -14
- package/data/server/widget.ts +1 -14
- package/data/urls.ts +1 -5
- package/hooks/use-captcha.tsx +1 -1
- package/middlewares/default.ts +249 -254
- package/middlewares/masterpass-rest-callback.ts +202 -89
- package/package.json +2 -2
- package/plugins.d.ts +0 -10
- package/plugins.js +0 -1
- package/redux/middlewares/checkout.ts +3 -45
- package/redux/middlewares/pre-order/installment-option.ts +1 -9
- package/types/index.ts +9 -20
- package/utils/csrf.ts +1 -1
- package/utils/index.ts +1 -0
- package/utils/normalize-search-params.ts +42 -0
- package/with-pz-config.js +1 -2
- package/utils/payload-optimizer.ts +0 -481
package/CHANGELOG.md
CHANGED
|
@@ -1,31 +1,19 @@
|
|
|
1
1
|
# @akinon/next
|
|
2
2
|
|
|
3
|
-
## 2.0.23
|
|
3
|
+
## 2.0.23
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
|
|
14
|
-
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
- bfafa3f4: ZERO-4160: Refactor oauth-login middleware to use fetchCommerce for API calls and improve cookie handling
|
|
18
|
-
- 57d7eb30: ZERO-4276: Refactor route generation logic by removing environment loading and simplifying skip segments handling
|
|
19
|
-
- d99a6a7d5: ZERO-3457_1: Fixed the settings prop and made sure everything is customizable.
|
|
20
|
-
- 9db81a71: ZERO-4365: Remove brand `@theme/*` alias imports from library packages
|
|
21
|
-
- 591e345e: ZERO-3855: Enhance credit card payment handling in checkout middlewares
|
|
22
|
-
- 4de5303c5: ZERO-2504: add cookie filter to api client request
|
|
23
|
-
- 95b139dc1: ZERO-3795: Remove duplicate entry for SavedCard in PluginComponents map
|
|
24
|
-
- 1d00f2d0: BRDG-16664: Set secure flag for CSRF token cookies in useCaptcha and default middleware
|
|
25
|
-
- 4ac7b2a1: ZERO-4219: fix masterpass-rest callback route format and double-encoded error cookie
|
|
26
|
-
- 4998a963: ZERO-4168: Add server-side payload optimization
|
|
27
|
-
- 3909d322: Edit the duplicate Plugin.SimilarProducts in the plugin-module.
|
|
28
|
-
- e18836b2: ZERO-4160: Restore scope in Sentry addon configuration in akinon.json
|
|
7
|
+
- 079fc67: ZERO-4522: Normalize searchParams at the entry of server data functions so v2 brand SSR no longer drops query params and no longer collides on a single Redis cache entry.
|
|
8
|
+
|
|
9
|
+
`withSegmentDefaults` converts Next 16's plain searchParams into a `URLSearchParams` instance for v1 brand compatibility. The instance then flowed into `getProductData` / `getCategoryData` / `getListData` / `getSpecialPageData` and broke two things:
|
|
10
|
+
|
|
11
|
+
- `JSON.stringify(new URLSearchParams(...))` returns `"{}"`, so every cache key for the same `pk` collapsed onto one Redis entry. The first user's filtered/variant response was served to every subsequent visitor.
|
|
12
|
+
- `getProductData`'s outbound URL builder used `Object.keys(searchParams).map(...)`, which returns `[]` for `URLSearchParams`. The backend product fetch silently dropped every query param — variant/attribute selections on the PDP never reached the commerce backend, and the add-to-cart button stayed stuck in its loading state.
|
|
13
|
+
|
|
14
|
+
Add `normalizeSearchParams` (`packages/akinon-next/utils/normalize-search-params.ts`) and call it once at the entry of each public data function. Multi-value URLSearchParams keys (`?color=red&color=blue`) collapse to `string[]` so multi-select filters survive. v1 brand pages keep receiving `URLSearchParams` from the HOC — only the internal data layer canonicalizes. No public signature change.
|
|
15
|
+
|
|
16
|
+
Side note: v1 brand PDP requests will now actually forward `?` params to the commerce backend instead of silently dropping them. Any v1 brand that relied on PDP requests ignoring query strings should smoke-test variant fetches.
|
|
29
17
|
|
|
30
18
|
## 2.0.22
|
|
31
19
|
|
|
@@ -6,7 +6,6 @@ const findBaseDir = require('../utils/find-base-dir');
|
|
|
6
6
|
|
|
7
7
|
const generateRoutes = () => {
|
|
8
8
|
const baseDir = findBaseDir();
|
|
9
|
-
|
|
10
9
|
const srcDir = path.join(baseDir, 'src');
|
|
11
10
|
const appDir = path.join(srcDir, 'app');
|
|
12
11
|
|
|
@@ -35,10 +34,8 @@ const generateRoutes = () => {
|
|
|
35
34
|
'[segment]',
|
|
36
35
|
'[url]',
|
|
37
36
|
'[theme]',
|
|
38
|
-
'[member_type]'
|
|
39
|
-
'[clienttype]'
|
|
37
|
+
'[member_type]'
|
|
40
38
|
];
|
|
41
|
-
|
|
42
39
|
const skipCatchAllRoutes = ['[...prettyurl]', '[...not_found]'];
|
|
43
40
|
|
|
44
41
|
const walkDirectory = (dir, basePath = '') => {
|
package/data/client/checkout.ts
CHANGED
|
@@ -738,6 +738,7 @@ export const checkoutApi = api.injectEndpoints({
|
|
|
738
738
|
},
|
|
739
739
|
async onQueryStarted(arg, { dispatch, queryFulfilled }) {
|
|
740
740
|
dispatch(setPaymentStepBusy(true));
|
|
741
|
+
dispatch(setCardType(arg));
|
|
741
742
|
await queryFulfilled;
|
|
742
743
|
dispatch(setPaymentStepBusy(false));
|
|
743
744
|
}
|
package/data/server/category.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { GetCategoryResponse, SearchParams } from '../../types';
|
|
2
2
|
import { generateCommerceSearchParams } from '../../utils';
|
|
3
|
+
import { normalizeSearchParams } from '../../utils/normalize-search-params';
|
|
3
4
|
import appFetch, { FetchResponseType } from '../../utils/app-fetch';
|
|
4
5
|
import { category, product } from '../urls';
|
|
5
6
|
import { Cache, CacheKey } from '../../lib/cache';
|
|
@@ -7,8 +8,6 @@ import { parse } from 'lossless-json';
|
|
|
7
8
|
import logger from '../../utils/log';
|
|
8
9
|
import { headers as nHeaders } from 'next/headers';
|
|
9
10
|
import { ServerVariables } from '../../utils/server-variables';
|
|
10
|
-
import { optimizeCategoryResponse } from '../../utils/payload-optimizer';
|
|
11
|
-
import settings from 'settings';
|
|
12
11
|
|
|
13
12
|
function getCategoryDataHandler(
|
|
14
13
|
pk: number,
|
|
@@ -82,7 +81,7 @@ function getCategoryDataHandler(
|
|
|
82
81
|
};
|
|
83
82
|
}
|
|
84
83
|
|
|
85
|
-
export const getCategoryData =
|
|
84
|
+
export const getCategoryData = ({
|
|
86
85
|
pk,
|
|
87
86
|
searchParams,
|
|
88
87
|
headers,
|
|
@@ -95,7 +94,9 @@ export const getCategoryData = async ({
|
|
|
95
94
|
searchParams?: SearchParams;
|
|
96
95
|
headers?: Record<string, string>;
|
|
97
96
|
}) => {
|
|
98
|
-
|
|
97
|
+
searchParams = normalizeSearchParams(searchParams);
|
|
98
|
+
|
|
99
|
+
return Cache.wrap(
|
|
99
100
|
CacheKey.Category(pk, searchParams, headers),
|
|
100
101
|
locale,
|
|
101
102
|
getCategoryDataHandler(pk, locale, currency, searchParams, headers),
|
|
@@ -104,16 +105,6 @@ export const getCategoryData = async ({
|
|
|
104
105
|
compressed: true
|
|
105
106
|
}
|
|
106
107
|
);
|
|
107
|
-
|
|
108
|
-
if (settings.payloadOptimization?.enabled && result?.data) {
|
|
109
|
-
try {
|
|
110
|
-
return { ...result, data: optimizeCategoryResponse(result.data, settings.payloadOptimization) };
|
|
111
|
-
} catch (e) {
|
|
112
|
-
logger.error('Payload optimization failed for category', { pk, error: (e as Error).message });
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return result;
|
|
117
108
|
};
|
|
118
109
|
|
|
119
110
|
function getCategoryBySlugDataHandler(
|
package/data/server/list.ts
CHANGED
|
@@ -2,12 +2,11 @@ import { Cache, CacheKey } from '../../lib/cache';
|
|
|
2
2
|
import { category } from '../urls';
|
|
3
3
|
import { GetCategoryResponse, SearchParams } from '../../types';
|
|
4
4
|
import { generateCommerceSearchParams } from '../../utils';
|
|
5
|
+
import { normalizeSearchParams } from '../../utils/normalize-search-params';
|
|
5
6
|
import appFetch, { FetchResponseType } from '../../utils/app-fetch';
|
|
6
7
|
import { parse } from 'lossless-json';
|
|
7
8
|
import logger from '../../utils/log';
|
|
8
9
|
import { ServerVariables } from '../../utils/server-variables';
|
|
9
|
-
import { optimizeCategoryResponse } from '../../utils/payload-optimizer';
|
|
10
|
-
import settings from 'settings';
|
|
11
10
|
|
|
12
11
|
const getListDataHandler = (
|
|
13
12
|
locale,
|
|
@@ -68,7 +67,9 @@ export const getListData = async ({
|
|
|
68
67
|
searchParams: SearchParams;
|
|
69
68
|
headers?: Record<string, string>;
|
|
70
69
|
}) => {
|
|
71
|
-
|
|
70
|
+
searchParams = normalizeSearchParams(searchParams);
|
|
71
|
+
|
|
72
|
+
return Cache.wrap(
|
|
72
73
|
CacheKey.List(searchParams, headers),
|
|
73
74
|
locale,
|
|
74
75
|
getListDataHandler(locale, currency, searchParams, headers),
|
|
@@ -77,14 +78,4 @@ export const getListData = async ({
|
|
|
77
78
|
compressed: true
|
|
78
79
|
}
|
|
79
80
|
);
|
|
80
|
-
|
|
81
|
-
if (settings.payloadOptimization?.enabled && result) {
|
|
82
|
-
try {
|
|
83
|
-
return optimizeCategoryResponse(result, settings.payloadOptimization);
|
|
84
|
-
} catch (e) {
|
|
85
|
-
logger.error('Payload optimization failed for list', { error: (e as Error).message });
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return result;
|
|
90
81
|
};
|
package/data/server/product.ts
CHANGED
|
@@ -2,10 +2,9 @@ import { Cache, CacheKey } from '../../lib/cache';
|
|
|
2
2
|
import { product } from '../urls';
|
|
3
3
|
import { ProductCategoryResult, ProductResult, SearchParams } from '../../types';
|
|
4
4
|
import appFetch from '../../utils/app-fetch';
|
|
5
|
+
import { normalizeSearchParams } from '../../utils/normalize-search-params';
|
|
5
6
|
import { ServerVariables } from '../../utils/server-variables';
|
|
6
7
|
import logger from '../../utils/log';
|
|
7
|
-
import { optimizeProductResponse } from '../../utils/payload-optimizer';
|
|
8
|
-
import settings from 'settings';
|
|
9
8
|
|
|
10
9
|
type GetProduct = {
|
|
11
10
|
pk: number | string;
|
|
@@ -135,13 +134,15 @@ export const getProductData = async ({
|
|
|
135
134
|
groupProduct,
|
|
136
135
|
headers
|
|
137
136
|
}: GetProduct) => {
|
|
137
|
+
searchParams = normalizeSearchParams(searchParams);
|
|
138
|
+
|
|
138
139
|
// Convert pk to number for cache key if it's a string
|
|
139
140
|
const numericPkForCache = typeof pk === 'string' ? parseInt(pk, 10) : pk;
|
|
140
141
|
|
|
141
142
|
const result = await Cache.wrap(
|
|
142
143
|
CacheKey[groupProduct ? 'GroupProduct' : 'Product'](
|
|
143
144
|
numericPkForCache,
|
|
144
|
-
searchParams ??
|
|
145
|
+
searchParams ?? {}
|
|
145
146
|
),
|
|
146
147
|
locale,
|
|
147
148
|
getProductDataHandler({
|
|
@@ -165,13 +166,5 @@ export const getProductData = async ({
|
|
|
165
166
|
throw error;
|
|
166
167
|
}
|
|
167
168
|
|
|
168
|
-
if (settings.payloadOptimization?.enabled && result?.data) {
|
|
169
|
-
try {
|
|
170
|
-
return { ...result, data: optimizeProductResponse(result.data, settings.payloadOptimization) };
|
|
171
|
-
} catch (e) {
|
|
172
|
-
logger.error('Payload optimization failed for product', { pk, error: (e as Error).message });
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
169
|
return result;
|
|
177
170
|
};
|
|
@@ -2,11 +2,9 @@ import { Cache, CacheKey } from '../../lib/cache';
|
|
|
2
2
|
import { category } from '../urls';
|
|
3
3
|
import { GetCategoryResponse, SearchParams } from '../../types';
|
|
4
4
|
import { generateCommerceSearchParams } from '../../utils';
|
|
5
|
+
import { normalizeSearchParams } from '../../utils/normalize-search-params';
|
|
5
6
|
import appFetch from '../../utils/app-fetch';
|
|
6
7
|
import { ServerVariables } from '../../utils/server-variables';
|
|
7
|
-
import { optimizeCategoryResponse } from '../../utils/payload-optimizer';
|
|
8
|
-
import logger from '../../utils/log';
|
|
9
|
-
import settings from 'settings';
|
|
10
8
|
|
|
11
9
|
const getSpecialPageDataHandler = (
|
|
12
10
|
pk: number,
|
|
@@ -48,7 +46,9 @@ export const getSpecialPageData = async ({
|
|
|
48
46
|
searchParams: SearchParams;
|
|
49
47
|
headers?: Record<string, string>;
|
|
50
48
|
}) => {
|
|
51
|
-
|
|
49
|
+
searchParams = normalizeSearchParams(searchParams);
|
|
50
|
+
|
|
51
|
+
return Cache.wrap(
|
|
52
52
|
CacheKey.SpecialPage(pk, searchParams, headers),
|
|
53
53
|
locale,
|
|
54
54
|
getSpecialPageDataHandler(pk, locale, currency, searchParams, headers),
|
|
@@ -57,14 +57,4 @@ export const getSpecialPageData = async ({
|
|
|
57
57
|
compressed: true
|
|
58
58
|
}
|
|
59
59
|
);
|
|
60
|
-
|
|
61
|
-
if (settings.payloadOptimization?.enabled && result) {
|
|
62
|
-
try {
|
|
63
|
-
return optimizeCategoryResponse(result, settings.payloadOptimization);
|
|
64
|
-
} catch (e) {
|
|
65
|
-
logger.error('Payload optimization failed for special-page', { pk, error: (e as Error).message });
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return result;
|
|
70
60
|
};
|
package/data/server/widget.ts
CHANGED
|
@@ -4,9 +4,6 @@ import { CacheOptions, WidgetResultType, WidgetSchemaType } from '../../types';
|
|
|
4
4
|
import appFetch from '../../utils/app-fetch';
|
|
5
5
|
import { widgets } from '../urls';
|
|
6
6
|
import { ServerVariables } from '../../utils/server-variables';
|
|
7
|
-
import { optimizeWidgetResponse } from '../../utils/payload-optimizer';
|
|
8
|
-
import logger from '../../utils/log';
|
|
9
|
-
import settings from 'settings';
|
|
10
7
|
|
|
11
8
|
const getWidgetDataHandler =
|
|
12
9
|
(
|
|
@@ -56,7 +53,7 @@ export const getWidgetData = async <T>({
|
|
|
56
53
|
cacheOptions?: CacheOptions;
|
|
57
54
|
headers?: Record<string, string>;
|
|
58
55
|
}): Promise<WidgetResultType<T>> => {
|
|
59
|
-
|
|
56
|
+
return Cache.wrap(
|
|
60
57
|
CacheKey.Widget(slug),
|
|
61
58
|
locale,
|
|
62
59
|
getWidgetDataHandler(slug, locale, currency, headers),
|
|
@@ -65,16 +62,6 @@ export const getWidgetData = async <T>({
|
|
|
65
62
|
...cacheOptions
|
|
66
63
|
}
|
|
67
64
|
);
|
|
68
|
-
|
|
69
|
-
if (settings.payloadOptimization?.enabled && result) {
|
|
70
|
-
try {
|
|
71
|
-
return optimizeWidgetResponse(result, settings.payloadOptimization) as WidgetResultType<T>;
|
|
72
|
-
} catch (e) {
|
|
73
|
-
logger.error('Payload optimization failed for widget', { slug, error: (e as Error).message });
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return result as WidgetResultType<T>;
|
|
78
65
|
};
|
|
79
66
|
|
|
80
67
|
const getCollectionWidgetDataHandler =
|
package/data/urls.ts
CHANGED
|
@@ -183,11 +183,7 @@ export const product = {
|
|
|
183
183
|
breadcrumbUrl: (menuitemmodel: string) =>
|
|
184
184
|
`/menus/generate_breadcrumb/?item=${menuitemmodel}&generator_name=menu_item`,
|
|
185
185
|
bundleProduct: (productPk: string, queryString: string) =>
|
|
186
|
-
`/bundle-product/${productPk}/?${queryString}
|
|
187
|
-
similarProducts: (params?: string) =>
|
|
188
|
-
`/similar-products${params ? `?${params}` : ''}`,
|
|
189
|
-
similarProductsList: (params?: string) =>
|
|
190
|
-
`/similar-product-list${params ? `?${params}` : ''}`
|
|
186
|
+
`/bundle-product/${productPk}/?${queryString}`
|
|
191
187
|
};
|
|
192
188
|
|
|
193
189
|
export const wishlist = {
|
package/hooks/use-captcha.tsx
CHANGED