@akinon/next 2.0.102-rc.0 → 2.0.103-beta.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/CHANGELOG.md +10 -28
- package/api/auth.ts +116 -90
- package/bin/pz-generate-routes.js +1 -4
- package/components/plugin-module.tsx +1 -0
- package/data/client/checkout.ts +1 -0
- package/data/client/wishlist.ts +0 -22
- package/data/server/category.ts +2 -14
- package/data/server/list.ts +1 -13
- package/data/server/product.ts +0 -10
- package/data/server/special-page.ts +1 -14
- package/data/server/widget.ts +0 -10
- package/data/urls.ts +4 -13
- package/hooks/index.ts +0 -1
- package/hooks/use-captcha.tsx +1 -1
- package/middlewares/default.ts +247 -254
- package/middlewares/pretty-url.ts +1 -3
- 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/with-pz-config.js +1 -6
- package/api/client-env.ts +0 -78
- package/hooks/use-client-env.ts +0 -265
- package/utils/payload-optimizer.ts +0 -481
package/CHANGELOG.md
CHANGED
|
@@ -1,36 +1,18 @@
|
|
|
1
1
|
# @akinon/next
|
|
2
2
|
|
|
3
|
-
## 2.0.
|
|
3
|
+
## 2.0.103-beta.0
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
- 7889b08fe: ZERO-4276: Enhance route generation by adding .env loading and custom skip segments support
|
|
17
|
-
- 9f8cd3bc5: ZERO-3449: AI Search Active Filters & Crop Style changes have been implemented
|
|
18
|
-
- bfafa3f49: ZERO-4160: Refactor oauth-login middleware to use fetchCommerce for API calls and improve cookie handling
|
|
19
|
-
- 57d7eb305: ZERO-4276: Refactor route generation logic by removing environment loading and simplifying skip segments handling
|
|
20
|
-
- d99a6a7d5: ZERO-3457_1: Fixed the settings prop and made sure everything is customizable.
|
|
21
|
-
- 9db81a714: ZERO-4365: Remove brand `@theme/*` alias imports from library packages
|
|
22
|
-
- 591e345e1: ZERO-3855: Enhance credit card payment handling in checkout middlewares
|
|
23
|
-
- 4de5303c5: ZERO-2504: add cookie filter to api client request
|
|
24
|
-
- 95b139dc1: ZERO-3795: Remove duplicate entry for SavedCard in PluginComponents map
|
|
25
|
-
- 1d00f2d06: BRDG-16664: Set secure flag for CSRF token cookies in useCaptcha and default middleware
|
|
26
|
-
- 4ac7b2a1e: ZERO-4219: fix masterpass-rest callback route format and double-encoded error cookie
|
|
27
|
-
- e9598c71d: ZERO-4622: Images remotePatterns for improved readability
|
|
28
|
-
- 4998a9631: ZERO-4168: Add server-side payload optimization
|
|
29
|
-
- 804d2bd6c: ZERO-4536: Add akinon.net domain to CSP frame-ancestors directive
|
|
30
|
-
- 3909d3224: Edit the duplicate Plugin.SimilarProducts in the plugin-module.
|
|
31
|
-
- 6a3d8a631: ZERO-4541: Fix URL query string formatting in getOrders and getOldOrders functions
|
|
32
|
-
- e18836b20: ZERO-4160: Restore scope in Sentry addon configuration in akinon.json
|
|
33
|
-
- b1111d7b: ZERO-4841: Guard `withPrettyUrl` against calling `String.prototype.replace` with an `undefined` locale prefix on projects without a URL locale prefix (e.g. `HideDefaultLocale`) — previously this coerced to the literal string `"undefined"` and silently stripped a trailing `/undefined` segment from the path before the pretty-url lookup, causing bogus URLs like `/{product-slug}/undefined` to resolve and rewrite to the real product page (200) instead of 404
|
|
7
|
+
- cbbbfd757: ZERO-4376: Bootstrap beta cycle (next-main pre-release motor)
|
|
8
|
+
|
|
9
|
+
## 2.0.102
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 52a5928: ZERO-5041: Keep the anonymous session on login so the guest basket merges
|
|
14
|
+
|
|
15
|
+
The login flow cleared the anonymous osessionid whenever getCurrentUser returned no pk, but the commerce currentUser endpoint returns 401 for a valid anonymous session too, so every guest's session (and its basket) was discarded before the login request reached the backend. Forward the anonymous session instead, and recover from a genuinely stale cookie by retrying the login once without it (ZERO-4247), scoped to password login and skipping OTP challenges (ZERO-4550) and throttled responses.
|
|
34
16
|
|
|
35
17
|
## 2.0.101
|
|
36
18
|
|
package/api/auth.ts
CHANGED
|
@@ -203,60 +203,73 @@ const getDefaultAuthConfig = () => {
|
|
|
203
203
|
if (sessionCookie) {
|
|
204
204
|
reqHeaders.set('cookie', sessionCookie);
|
|
205
205
|
}
|
|
206
|
-
} else if (credentials.formType === 'login') {
|
|
207
|
-
// Stale session cookie — only clear it before a fresh password
|
|
208
|
-
// login (ZERO-4247). Register and OTP flows are still anonymous at
|
|
209
|
-
// this point (no pk yet), but their session carries the pending OTP
|
|
210
|
-
// challenge; clearing it here makes the backend lose the challenge
|
|
211
|
-
// and re-issue the code on every verify (ZERO-4550).
|
|
212
|
-
// remove from headers and clear in browser
|
|
213
|
-
const currentCookies = reqHeaders.get('cookie') || '';
|
|
214
|
-
const cleanedCookies = currentCookies
|
|
215
|
-
.split(';')
|
|
216
|
-
.filter((c) => !c.trim().startsWith('osessionid='))
|
|
217
|
-
.join(';')
|
|
218
|
-
.trim();
|
|
219
|
-
reqHeaders.set('cookie', cleanedCookies);
|
|
220
|
-
|
|
221
|
-
const { localeUrlStrategy } = Settings.localization;
|
|
222
|
-
const fallbackHost =
|
|
223
|
-
headerStore.get('x-forwarded-host') ||
|
|
224
|
-
headerStore.get('host');
|
|
225
|
-
const hostname =
|
|
226
|
-
process.env.NEXT_PUBLIC_URL || `https://${fallbackHost}`;
|
|
227
|
-
const rootHostname =
|
|
228
|
-
localeUrlStrategy === LocaleUrlStrategy.Subdomain
|
|
229
|
-
? getRootHostname(hostname)
|
|
230
|
-
: null;
|
|
231
|
-
const expireOptions = {
|
|
232
|
-
path: '/',
|
|
233
|
-
maxAge: 0,
|
|
234
|
-
...(rootHostname ? { domain: rootHostname } : {})
|
|
235
|
-
};
|
|
236
|
-
cookieStore.set('osessionid', '', expireOptions);
|
|
237
|
-
cookieStore.set('sessionid', '', expireOptions);
|
|
238
206
|
}
|
|
207
|
+
// A guest's anonymous session (no pk yet) is deliberately NOT
|
|
208
|
+
// stripped here. It must be forwarded on the login request so the
|
|
209
|
+
// backend can merge the guest basket into the account on sign-in
|
|
210
|
+
// (ZERO-5041). getCurrentUser cannot tell a valid anonymous session
|
|
211
|
+
// apart from a truly stale one — the commerce currentUser endpoint
|
|
212
|
+
// returns 401 for both — so pre-emptively clearing on "no pk" also
|
|
213
|
+
// discarded every legitimate guest session. The ZERO-4247
|
|
214
|
+
// stale-cookie recovery is handled below instead, as a one-time
|
|
215
|
+
// retry without the session cookie after a login actually fails.
|
|
239
216
|
}
|
|
240
217
|
|
|
241
|
-
const
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
218
|
+
const performAuthRequest = async (headers: HeadersInit) => {
|
|
219
|
+
const request = await fetch(
|
|
220
|
+
`${Settings.commerceUrl}${user[credentials.formType]}`,
|
|
221
|
+
{
|
|
222
|
+
method: 'POST',
|
|
223
|
+
headers,
|
|
224
|
+
body: JSON.stringify(credentials)
|
|
225
|
+
}
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
const body = (await request.json()) as {
|
|
229
|
+
key: string;
|
|
230
|
+
non_field_errors: string[];
|
|
231
|
+
redirect_url: string;
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
return { request, body };
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
let { request: apiRequest, body: response } =
|
|
238
|
+
await performAuthRequest(reqHeaders);
|
|
239
|
+
|
|
240
|
+
// ZERO-4247 recovery: the anonymous session was forwarded so the guest
|
|
241
|
+
// basket can merge (ZERO-5041). If a session cookie was present and the
|
|
242
|
+
// login still failed, the session may be genuinely stale, so retry once
|
|
243
|
+
// without it. Scoped to password login; OTP challenges (202,
|
|
244
|
+
// ZERO-4550) and throttled requests (429) are left untouched. On a
|
|
245
|
+
// successful retry the sessionId block below overwrites the browser
|
|
246
|
+
// cookies with the freshly issued session.
|
|
247
|
+
if (
|
|
248
|
+
!response.key &&
|
|
249
|
+
credentials.formType === 'login' &&
|
|
250
|
+
existingSessionId &&
|
|
251
|
+
apiRequest.status !== 202 &&
|
|
252
|
+
apiRequest.status !== 429
|
|
253
|
+
) {
|
|
254
|
+
const retryHeaders = new Headers(reqHeaders);
|
|
255
|
+
const cleanedCookies = (retryHeaders.get('cookie') || '')
|
|
256
|
+
.split(';')
|
|
257
|
+
.filter((c) => !c.trim().startsWith('osessionid='))
|
|
258
|
+
.join(';')
|
|
259
|
+
.trim();
|
|
260
|
+
retryHeaders.set('cookie', cleanedCookies);
|
|
261
|
+
|
|
262
|
+
const retry = await performAuthRequest(retryHeaders);
|
|
263
|
+
if (retry.body.key) {
|
|
264
|
+
apiRequest = retry.request;
|
|
265
|
+
response = retry.body;
|
|
247
266
|
}
|
|
248
|
-
|
|
267
|
+
}
|
|
249
268
|
|
|
250
269
|
logger.info(`Login/Register request result: ${apiRequest.status}`, {
|
|
251
270
|
userIp
|
|
252
271
|
});
|
|
253
272
|
|
|
254
|
-
const response = (await apiRequest.json()) as {
|
|
255
|
-
key: string;
|
|
256
|
-
non_field_errors: string[];
|
|
257
|
-
redirect_url: string;
|
|
258
|
-
};
|
|
259
|
-
|
|
260
273
|
logger.debug(`Login/Register response: ${JSON.stringify(response)}`);
|
|
261
274
|
|
|
262
275
|
let sessionId = '';
|
|
@@ -496,60 +509,73 @@ const defaultNextAuthOptionsV4 = (req: any, res: any) => {
|
|
|
496
509
|
if (sessionCookie) {
|
|
497
510
|
reqHeaders.set('cookie', sessionCookie);
|
|
498
511
|
}
|
|
499
|
-
} else if (credentials.formType === 'login') {
|
|
500
|
-
// Stale session cookie — only clear it before a fresh password
|
|
501
|
-
// login (ZERO-4247). Register and OTP flows are still anonymous at
|
|
502
|
-
// this point (no pk yet), but their session carries the pending OTP
|
|
503
|
-
// challenge; clearing it here makes the backend lose the challenge
|
|
504
|
-
// and re-issue the code on every verify (ZERO-4550).
|
|
505
|
-
// remove from headers and clear in browser
|
|
506
|
-
const currentCookies = reqHeaders.get('cookie') || '';
|
|
507
|
-
const cleanedCookies = currentCookies
|
|
508
|
-
.split(';')
|
|
509
|
-
.filter((c) => !c.trim().startsWith('osessionid='))
|
|
510
|
-
.join(';')
|
|
511
|
-
.trim();
|
|
512
|
-
reqHeaders.set('cookie', cleanedCookies);
|
|
513
|
-
|
|
514
|
-
const { localeUrlStrategy } = Settings.localization;
|
|
515
|
-
const fallbackHost =
|
|
516
|
-
req.headers['x-forwarded-host']?.toString() ||
|
|
517
|
-
req.headers.host?.toString();
|
|
518
|
-
const hostname =
|
|
519
|
-
process.env.NEXT_PUBLIC_URL || `https://${fallbackHost}`;
|
|
520
|
-
const rootHostname =
|
|
521
|
-
localeUrlStrategy === LocaleUrlStrategy.Subdomain
|
|
522
|
-
? getRootHostname(hostname)
|
|
523
|
-
: null;
|
|
524
|
-
const domainOption = rootHostname
|
|
525
|
-
? ` Domain=${rootHostname};`
|
|
526
|
-
: '';
|
|
527
|
-
res.setHeader('Set-Cookie', [
|
|
528
|
-
`osessionid=; Path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT;${domainOption}`,
|
|
529
|
-
`sessionid=; Path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT;${domainOption}`
|
|
530
|
-
]);
|
|
531
512
|
}
|
|
513
|
+
// A guest's anonymous session (no pk yet) is deliberately NOT
|
|
514
|
+
// stripped here. It must be forwarded on the login request so the
|
|
515
|
+
// backend can merge the guest basket into the account on sign-in
|
|
516
|
+
// (ZERO-5041). getCurrentUser cannot tell a valid anonymous session
|
|
517
|
+
// apart from a truly stale one — the commerce currentUser endpoint
|
|
518
|
+
// returns 401 for both — so pre-emptively clearing on "no pk" also
|
|
519
|
+
// discarded every legitimate guest session. The ZERO-4247
|
|
520
|
+
// stale-cookie recovery is handled below instead, as a one-time
|
|
521
|
+
// retry without the session cookie after a login actually fails.
|
|
532
522
|
}
|
|
533
523
|
|
|
534
|
-
const
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
524
|
+
const performAuthRequest = async (headers: HeadersInit) => {
|
|
525
|
+
const request = await fetch(
|
|
526
|
+
`${Settings.commerceUrl}${user[credentials.formType]}`,
|
|
527
|
+
{
|
|
528
|
+
method: 'POST',
|
|
529
|
+
headers,
|
|
530
|
+
body: JSON.stringify(credentials)
|
|
531
|
+
}
|
|
532
|
+
);
|
|
533
|
+
|
|
534
|
+
const body = (await request.json()) as {
|
|
535
|
+
key: string;
|
|
536
|
+
non_field_errors: string[];
|
|
537
|
+
redirect_url: string;
|
|
538
|
+
};
|
|
539
|
+
|
|
540
|
+
return { request, body };
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
let { request: apiRequest, body: response } =
|
|
544
|
+
await performAuthRequest(reqHeaders);
|
|
545
|
+
|
|
546
|
+
// ZERO-4247 recovery: the anonymous session was forwarded so the guest
|
|
547
|
+
// basket can merge (ZERO-5041). If a session cookie was present and the
|
|
548
|
+
// login still failed, the session may be genuinely stale, so retry once
|
|
549
|
+
// without it. Scoped to password login; OTP challenges (202,
|
|
550
|
+
// ZERO-4550) and throttled requests (429) are left untouched. On a
|
|
551
|
+
// successful retry the sessionId block below overwrites the browser
|
|
552
|
+
// cookies with the freshly issued session.
|
|
553
|
+
if (
|
|
554
|
+
!response.key &&
|
|
555
|
+
credentials.formType === 'login' &&
|
|
556
|
+
req.cookies['osessionid'] &&
|
|
557
|
+
apiRequest.status !== 202 &&
|
|
558
|
+
apiRequest.status !== 429
|
|
559
|
+
) {
|
|
560
|
+
const retryHeaders = new Headers(reqHeaders);
|
|
561
|
+
const cleanedCookies = (retryHeaders.get('cookie') || '')
|
|
562
|
+
.split(';')
|
|
563
|
+
.filter((c) => !c.trim().startsWith('osessionid='))
|
|
564
|
+
.join(';')
|
|
565
|
+
.trim();
|
|
566
|
+
retryHeaders.set('cookie', cleanedCookies);
|
|
567
|
+
|
|
568
|
+
const retry = await performAuthRequest(retryHeaders);
|
|
569
|
+
if (retry.body.key) {
|
|
570
|
+
apiRequest = retry.request;
|
|
571
|
+
response = retry.body;
|
|
540
572
|
}
|
|
541
|
-
|
|
573
|
+
}
|
|
542
574
|
|
|
543
575
|
logger.info(`Login/Register request result: ${apiRequest.status}`, {
|
|
544
576
|
userIp
|
|
545
577
|
});
|
|
546
578
|
|
|
547
|
-
const response = (await apiRequest.json()) as {
|
|
548
|
-
key: string;
|
|
549
|
-
non_field_errors: string[];
|
|
550
|
-
redirect_url: string;
|
|
551
|
-
};
|
|
552
|
-
|
|
553
579
|
logger.debug(`Login/Register response: ${JSON.stringify(response)}`);
|
|
554
580
|
|
|
555
581
|
let sessionId = '';
|
|
@@ -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
|
@@ -718,6 +718,7 @@ export const checkoutApi = api.injectEndpoints({
|
|
|
718
718
|
},
|
|
719
719
|
async onQueryStarted(arg, { dispatch, queryFulfilled }) {
|
|
720
720
|
dispatch(setPaymentStepBusy(true));
|
|
721
|
+
dispatch(setCardType(arg));
|
|
721
722
|
await queryFulfilled;
|
|
722
723
|
dispatch(setPaymentStepBusy(false));
|
|
723
724
|
}
|
package/data/client/wishlist.ts
CHANGED
|
@@ -26,19 +26,6 @@ interface GetFavoritesResponse {
|
|
|
26
26
|
results: FavoriteItem[];
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
export interface FavouriteProductIdItem {
|
|
30
|
-
product_id: number;
|
|
31
|
-
favourite_id: number;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface GetFavouriteProductIdsResponse {
|
|
35
|
-
favourite_products: FavouriteProductIdItem[];
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
interface GetFavouriteProductIdsParams {
|
|
39
|
-
productIds: Array<number | string>;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
29
|
interface AddFavoriteResponse {
|
|
43
30
|
pk: number;
|
|
44
31
|
product: number;
|
|
@@ -96,14 +83,6 @@ export const wishlistApi = api.injectEndpoints({
|
|
|
96
83
|
buildClientRequestUrl(wishlist.getFavorites({ page, limit })),
|
|
97
84
|
providesTags: ['Favorite']
|
|
98
85
|
}),
|
|
99
|
-
getFavouriteProductIds: build.query<
|
|
100
|
-
GetFavouriteProductIdsResponse,
|
|
101
|
-
GetFavouriteProductIdsParams
|
|
102
|
-
>({
|
|
103
|
-
query: ({ productIds }) =>
|
|
104
|
-
buildClientRequestUrl(wishlist.getFavouriteProductIds(productIds)),
|
|
105
|
-
providesTags: ['Favorite']
|
|
106
|
-
}),
|
|
107
86
|
addFavorite: build.mutation<AddFavoriteResponse, number>({
|
|
108
87
|
query: (productPk: number) => ({
|
|
109
88
|
url: buildClientRequestUrl(wishlist.addFavorite, {
|
|
@@ -217,7 +196,6 @@ export const wishlistApi = api.injectEndpoints({
|
|
|
217
196
|
|
|
218
197
|
export const {
|
|
219
198
|
useGetFavoritesQuery,
|
|
220
|
-
useGetFavouriteProductIdsQuery,
|
|
221
199
|
useAddFavoriteMutation,
|
|
222
200
|
useRemoveFavoriteMutation,
|
|
223
201
|
useAddStockAlertMutation,
|
package/data/server/category.ts
CHANGED
|
@@ -8,8 +8,6 @@ import { parse } from 'lossless-json';
|
|
|
8
8
|
import logger from '../../utils/log';
|
|
9
9
|
import { headers as nHeaders } from 'next/headers';
|
|
10
10
|
import { ServerVariables } from '../../utils/server-variables';
|
|
11
|
-
import { optimizeCategoryResponse } from '../../utils/payload-optimizer';
|
|
12
|
-
import settings from 'settings';
|
|
13
11
|
|
|
14
12
|
function getCategoryDataHandler(
|
|
15
13
|
pk: number,
|
|
@@ -83,7 +81,7 @@ function getCategoryDataHandler(
|
|
|
83
81
|
};
|
|
84
82
|
}
|
|
85
83
|
|
|
86
|
-
export const getCategoryData =
|
|
84
|
+
export const getCategoryData = ({
|
|
87
85
|
pk,
|
|
88
86
|
searchParams,
|
|
89
87
|
headers,
|
|
@@ -98,7 +96,7 @@ export const getCategoryData = async ({
|
|
|
98
96
|
}) => {
|
|
99
97
|
searchParams = normalizeSearchParams(searchParams);
|
|
100
98
|
|
|
101
|
-
|
|
99
|
+
return Cache.wrap(
|
|
102
100
|
CacheKey.Category(pk, searchParams, headers),
|
|
103
101
|
locale,
|
|
104
102
|
getCategoryDataHandler(pk, locale, currency, searchParams, headers),
|
|
@@ -107,16 +105,6 @@ export const getCategoryData = async ({
|
|
|
107
105
|
compressed: true
|
|
108
106
|
}
|
|
109
107
|
);
|
|
110
|
-
|
|
111
|
-
if (settings.payloadOptimization?.enabled && result?.data) {
|
|
112
|
-
try {
|
|
113
|
-
return { ...result, data: optimizeCategoryResponse(result.data, settings.payloadOptimization) };
|
|
114
|
-
} catch (e) {
|
|
115
|
-
logger.error('Payload optimization failed for category', { pk, error: (e as Error).message });
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return result;
|
|
120
108
|
};
|
|
121
109
|
|
|
122
110
|
function getCategoryBySlugDataHandler(
|
package/data/server/list.ts
CHANGED
|
@@ -7,8 +7,6 @@ import appFetch, { FetchResponseType } from '../../utils/app-fetch';
|
|
|
7
7
|
import { parse } from 'lossless-json';
|
|
8
8
|
import logger from '../../utils/log';
|
|
9
9
|
import { ServerVariables } from '../../utils/server-variables';
|
|
10
|
-
import { optimizeCategoryResponse } from '../../utils/payload-optimizer';
|
|
11
|
-
import settings from 'settings';
|
|
12
10
|
|
|
13
11
|
const getListDataHandler = (
|
|
14
12
|
locale,
|
|
@@ -71,7 +69,7 @@ export const getListData = async ({
|
|
|
71
69
|
}) => {
|
|
72
70
|
searchParams = normalizeSearchParams(searchParams);
|
|
73
71
|
|
|
74
|
-
|
|
72
|
+
return Cache.wrap(
|
|
75
73
|
CacheKey.List(searchParams, headers),
|
|
76
74
|
locale,
|
|
77
75
|
getListDataHandler(locale, currency, searchParams, headers),
|
|
@@ -80,14 +78,4 @@ export const getListData = async ({
|
|
|
80
78
|
compressed: true
|
|
81
79
|
}
|
|
82
80
|
);
|
|
83
|
-
|
|
84
|
-
if (settings.payloadOptimization?.enabled && result) {
|
|
85
|
-
try {
|
|
86
|
-
return optimizeCategoryResponse(result, settings.payloadOptimization);
|
|
87
|
-
} catch (e) {
|
|
88
|
-
logger.error('Payload optimization failed for list', { error: (e as Error).message });
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return result;
|
|
93
81
|
};
|
package/data/server/product.ts
CHANGED
|
@@ -5,8 +5,6 @@ import appFetch from '../../utils/app-fetch';
|
|
|
5
5
|
import { normalizeSearchParams } from '../../utils/normalize-search-params';
|
|
6
6
|
import { ServerVariables } from '../../utils/server-variables';
|
|
7
7
|
import logger from '../../utils/log';
|
|
8
|
-
import { optimizeProductResponse } from '../../utils/payload-optimizer';
|
|
9
|
-
import settings from 'settings';
|
|
10
8
|
|
|
11
9
|
type GetProduct = {
|
|
12
10
|
pk: number | string;
|
|
@@ -168,13 +166,5 @@ export const getProductData = async ({
|
|
|
168
166
|
throw error;
|
|
169
167
|
}
|
|
170
168
|
|
|
171
|
-
if (settings.payloadOptimization?.enabled && result?.data) {
|
|
172
|
-
try {
|
|
173
|
-
return { ...result, data: optimizeProductResponse(result.data, settings.payloadOptimization) };
|
|
174
|
-
} catch (e) {
|
|
175
|
-
logger.error('Payload optimization failed for product', { pk, error: (e as Error).message });
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
169
|
return result;
|
|
180
170
|
};
|
|
@@ -5,9 +5,6 @@ import { generateCommerceSearchParams } from '../../utils';
|
|
|
5
5
|
import { normalizeSearchParams } from '../../utils/normalize-search-params';
|
|
6
6
|
import appFetch from '../../utils/app-fetch';
|
|
7
7
|
import { ServerVariables } from '../../utils/server-variables';
|
|
8
|
-
import { optimizeCategoryResponse } from '../../utils/payload-optimizer';
|
|
9
|
-
import logger from '../../utils/log';
|
|
10
|
-
import settings from 'settings';
|
|
11
8
|
|
|
12
9
|
const getSpecialPageDataHandler = (
|
|
13
10
|
pk: number,
|
|
@@ -51,7 +48,7 @@ export const getSpecialPageData = async ({
|
|
|
51
48
|
}) => {
|
|
52
49
|
searchParams = normalizeSearchParams(searchParams);
|
|
53
50
|
|
|
54
|
-
|
|
51
|
+
return Cache.wrap(
|
|
55
52
|
CacheKey.SpecialPage(pk, searchParams, headers),
|
|
56
53
|
locale,
|
|
57
54
|
getSpecialPageDataHandler(pk, locale, currency, searchParams, headers),
|
|
@@ -60,14 +57,4 @@ export const getSpecialPageData = async ({
|
|
|
60
57
|
compressed: true
|
|
61
58
|
}
|
|
62
59
|
);
|
|
63
|
-
|
|
64
|
-
if (settings.payloadOptimization?.enabled && result) {
|
|
65
|
-
try {
|
|
66
|
-
return optimizeCategoryResponse(result, settings.payloadOptimization);
|
|
67
|
-
} catch (e) {
|
|
68
|
-
logger.error('Payload optimization failed for special-page', { pk, error: (e as Error).message });
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return result;
|
|
73
60
|
};
|
package/data/server/widget.ts
CHANGED
|
@@ -286,16 +286,6 @@ export const getWidgetData = async <T>({
|
|
|
286
286
|
...cacheOptions
|
|
287
287
|
}
|
|
288
288
|
);
|
|
289
|
-
|
|
290
|
-
if (settings.payloadOptimization?.enabled && result) {
|
|
291
|
-
try {
|
|
292
|
-
return optimizeWidgetResponse(result, settings.payloadOptimization) as WidgetResultType<T>;
|
|
293
|
-
} catch (e) {
|
|
294
|
-
logger.error('Payload optimization failed for widget', { slug, error: (e as Error).message });
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
return result as WidgetResultType<T>;
|
|
299
289
|
};
|
|
300
290
|
|
|
301
291
|
const getCollectionWidgetDataHandler =
|
package/data/urls.ts
CHANGED
|
@@ -40,11 +40,10 @@ export const account = {
|
|
|
40
40
|
shipping_option_slug
|
|
41
41
|
? `&shipping_option_slug${shipping_option_operator}${shipping_option_slug}`
|
|
42
42
|
: ''
|
|
43
|
-
}${currency ? `¤cy=${currency}` : ''}
|
|
44
|
-
|
|
45
|
-
}`,
|
|
43
|
+
}${currency ? `¤cy=${currency}` : ''}
|
|
44
|
+
${filterType && filterValue ? `&${filterType}=${filterValue}` : ''}`,
|
|
46
45
|
getOldOrders: ({ page, limit }: { page?: number; limit?: number }) =>
|
|
47
|
-
`/users/old-orders/?page=${page || 1}&limit=${limit || 12}`,
|
|
46
|
+
`/users/old-orders/?page=${page || 1}&limit=${limit || 12}}`,
|
|
48
47
|
getQuotations: (page?: number, status?: string, limit?: number) =>
|
|
49
48
|
`/b2b/my-quotations/?page=${page || 1}` +
|
|
50
49
|
(status ? `&status=${status}` : '') +
|
|
@@ -184,20 +183,12 @@ export const product = {
|
|
|
184
183
|
breadcrumbUrl: (menuitemmodel: string) =>
|
|
185
184
|
`/menus/generate_breadcrumb/?item=${menuitemmodel}&generator_name=menu_item`,
|
|
186
185
|
bundleProduct: (productPk: string, queryString: string) =>
|
|
187
|
-
`/bundle-product/${productPk}/?${queryString}
|
|
188
|
-
similarProducts: (params?: string) =>
|
|
189
|
-
`/similar-products${params ? `?${params}` : ''}`,
|
|
190
|
-
similarProductsList: (params?: string) =>
|
|
191
|
-
`/similar-product-list${params ? `?${params}` : ''}`
|
|
186
|
+
`/bundle-product/${productPk}/?${queryString}`
|
|
192
187
|
};
|
|
193
188
|
|
|
194
189
|
export const wishlist = {
|
|
195
190
|
getFavorites: ({ page, limit }: { page?: number; limit?: number }) =>
|
|
196
191
|
`/wishlists/favourite-products/?limit=${limit || 12}&page=${page || 1}`,
|
|
197
|
-
getFavouriteProductIds: (productIds: Array<number | string>) =>
|
|
198
|
-
`/wishlists/favourite-product-ids/?${productIds
|
|
199
|
-
.map((id) => `product_id=${id}`)
|
|
200
|
-
.join('&')}`,
|
|
201
192
|
addFavorite: '/wishlists/favourite-products/',
|
|
202
193
|
removeFavorite: (favPk: number) => `/wishlists/favourite-products/${favPk}/`,
|
|
203
194
|
addStockAlert: '/wishlists/product-alerts/',
|
package/hooks/index.ts
CHANGED
package/hooks/use-captcha.tsx
CHANGED