@akinon/next 2.0.79-rc.0 → 2.0.79

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 CHANGED
@@ -1,36 +1,6 @@
1
1
  # @akinon/next
2
2
 
3
- ## 2.0.79-rc.0
4
-
5
- ### Patch Changes
6
-
7
- - 86187b1c: ZERO-4879: Repair sync-merge corruption in default middleware and server data loaders — remove a duplicated block that left an unbalanced brace, and restore the awaited `result` binding the payload optimization reads
8
- - 0cf9ea239: BRDG-16491: Prevent redirect when iframe payment is active
9
- - 324f97d55: ZERO-4219: replace masterpass-rest-complete with masterpass-rest-callback
10
- - 51ea06888: ZERO-4377: Fix checkout card type state being cleared after valid bin number responses.
11
- - ZERO-4160: Enhance oauth-login middleware with improved request handling and logging
12
- - 2fea4143: ZERO-4620: Add runtime access to `NEXT_PUBLIC_*` environment variables from Client Components
13
- - b55acb768: ZERO-2577: Fix pagination bug and update usePagination hook and ensure pagination controls rendering correctly
14
- - 760258c1c: ZERO-4160: Enhance oauth-login middleware to handle fetch errors and improve response handling
15
- - 143be2b9d: ZERO-3457: Crop styles are customizable and logic improved for rendering similar products modal
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
- - e9598c71: 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
3
+ ## 2.0.79
34
4
 
35
5
  ## 2.0.78
36
6
 
@@ -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 = '') => {
@@ -116,6 +116,7 @@ const PluginComponents = new Map([
116
116
  ]
117
117
  ],
118
118
  [Plugin.SavedCard, [Component.SavedCard, Component.IyzicoSavedCard]],
119
+ [Plugin.SavedCard, [Component.SavedCard]],
119
120
  [Plugin.FlowPayment, [Component.FlowPayment]],
120
121
  [
121
122
  Plugin.VirtualTryOn,
@@ -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
  }
@@ -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,
@@ -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 = async ({
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
- const result = await Cache.wrap(
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(
@@ -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
- const result = await Cache.wrap(
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
  };
@@ -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
- const result = await Cache.wrap(
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
  };
@@ -1,19 +1,192 @@
1
1
  import { Cache, CacheKey } from '../../lib/cache';
2
2
  import 'server-only';
3
+ import { draftMode } from 'next/headers';
3
4
  import { CacheOptions, WidgetResultType, WidgetSchemaType } from '../../types';
4
5
  import appFetch from '../../utils/app-fetch';
5
6
  import { widgets } from '../urls';
6
7
  import { ServerVariables } from '../../utils/server-variables';
7
- import { optimizeWidgetResponse } from '../../utils/payload-optimizer';
8
- import logger from '../../utils/log';
9
- import settings from 'settings';
8
+ import {
9
+ isPreviewCopySlug,
10
+ isValidPreviewId,
11
+ previewSlug
12
+ } from '../../utils/preview';
13
+
14
+ /**
15
+ * Widget preview (draft mode): the theme editor keeps any number of NAMED
16
+ * previews, each storing its pages under `<slug>-preview-<previewId>`. With
17
+ * draft mode on (entered via /api/preview, toggled by `?preview` on any page
18
+ * url) and a preview id on the request, every widget fetch first tries that
19
+ * preview's copy and falls back to the live slug when none exists — a
20
+ * preview renders as "live + that preview's overlay". Preview fetches bypass
21
+ * Redis and the fetch data cache so the editor's latest save is visible.
22
+ *
23
+ * BOTH signals are required: draft mode alone renders live (no id ⇒ no
24
+ * preview slug to try), and an id alone does nothing without draft mode.
25
+ */
26
+ const PREVIEW_SNAPSHOT_ATTRIBUTE = 'preview_snapshot';
27
+
28
+ const PREVIEW_NO_STORE = { revalidate: 0 };
29
+
30
+ // The snapshot blob owns theme settings/data sources in preview, so the
31
+ // theme-config widget itself is never slug-transformed; a slug that is
32
+ // already this preview's copy is never transformed twice. Checked against
33
+ // the CURRENT id, not a shape — a live slug may legitimately end in
34
+ // `-preview-<something>` (a custom page named `summer-preview-2026`).
35
+ const isPreviewTransformableSlug = (slug: string, previewId: string): boolean =>
36
+ slug !== 'theme-config' && !isPreviewCopySlug(slug, previewId);
37
+
38
+ /**
39
+ * The editor's directory of previews that exist (`theme-previews` widget,
40
+ * `theme_previews` attribute). Deleting a preview removes it here first and
41
+ * clears only the pages the editor had loaded — so this is what makes a
42
+ * deleted preview stop rendering, even for a browser that still carries its
43
+ * cookie. Read uncached, remembered briefly across requests: a deleted
44
+ * preview may linger for at most REGISTRY_TTL_MS. An unreadable registry
45
+ * fails OPEN (behaves as before the check existed) rather than blanking
46
+ * every preview on a transient backend error.
47
+ */
48
+ const PREVIEW_REGISTRY_SLUG = 'theme-previews';
49
+ const PREVIEW_REGISTRY_ATTRIBUTE = 'theme_previews';
50
+ const REGISTRY_TTL_MS = 5_000;
51
+
52
+ let registryMemo: { ids: Set<string> | null; expires: number } = {
53
+ ids: null,
54
+ expires: 0
55
+ };
56
+
57
+ const unwrapAttribute = (raw: unknown): unknown =>
58
+ typeof raw === 'object' && raw !== null && 'value' in raw
59
+ ? (raw as { value?: unknown }).value
60
+ : raw;
61
+
62
+ const registryKnowsPreview = async (
63
+ previewId: string,
64
+ locale: string,
65
+ currency: string
66
+ ): Promise<boolean> => {
67
+ const now = Date.now();
68
+ if (registryMemo.expires <= now) {
69
+ let ids: Set<string> | null = null;
70
+ try {
71
+ const widget = await getWidgetDataHandler(
72
+ PREVIEW_REGISTRY_SLUG,
73
+ locale,
74
+ currency,
75
+ undefined,
76
+ PREVIEW_NO_STORE
77
+ )();
78
+ const raw = unwrapAttribute(
79
+ (widget as { attributes?: Record<string, unknown> } | null)
80
+ ?.attributes?.[PREVIEW_REGISTRY_ATTRIBUTE]
81
+ );
82
+ if (typeof raw === 'string' && raw) {
83
+ const parsed = JSON.parse(raw);
84
+ if (Array.isArray(parsed?.previews)) {
85
+ ids = new Set(
86
+ (parsed.previews as Array<{ id?: unknown }>)
87
+ .map((entry) => entry?.id)
88
+ .filter((id): id is string => typeof id === 'string')
89
+ );
90
+ }
91
+ }
92
+ } catch {
93
+ ids = null;
94
+ }
95
+ registryMemo = { ids, expires: now + REGISTRY_TTL_MS };
96
+ }
97
+ return registryMemo.ids ? registryMemo.ids.has(previewId) : true;
98
+ };
99
+
100
+ /**
101
+ * The named preview this render belongs to, or '' when the request is not a
102
+ * preview at all. The id is decoded from the pz route segment (see
103
+ * utils/preview.ts) and re-validated here — it originates from a cookie.
104
+ */
105
+ const previewIdForRequest = async (
106
+ locale: string = ServerVariables.locale,
107
+ currency: string = ServerVariables.currency
108
+ ): Promise<string> => {
109
+ try {
110
+ if (!(await draftMode()).isEnabled) return '';
111
+ } catch {
112
+ // No request scope (e.g. build-time prerender) — never a preview.
113
+ return '';
114
+ }
115
+ const previewId = ServerVariables.previewId;
116
+ if (!isValidPreviewId(previewId)) return '';
117
+ return (await registryKnowsPreview(previewId, locale, currency))
118
+ ? previewId
119
+ : '';
120
+ };
121
+
122
+ /**
123
+ * Whole-placeholder preview snapshot written by the theme editor into the
124
+ * `preview_snapshot` attribute of `<placeholderSlug>-preview-<previewId>`.
125
+ * When present (draft mode only), the placeholder renders straight from this
126
+ * blob — no per-section fetches.
127
+ */
128
+ export type PreviewSnapshot = {
129
+ version: number;
130
+ savedAt?: string;
131
+ themeSettings?: Record<string, unknown> | null;
132
+ dataSources?: unknown[];
133
+ sections: unknown[];
134
+ };
135
+
136
+ export const getPreviewSnapshot = async ({
137
+ slug,
138
+ locale = ServerVariables.locale,
139
+ currency = ServerVariables.currency
140
+ }: {
141
+ slug: string;
142
+ locale?: string;
143
+ currency?: string;
144
+ }): Promise<PreviewSnapshot | null> => {
145
+ const previewId = slug ? await previewIdForRequest(locale, currency) : '';
146
+ if (!previewId) {
147
+ return null;
148
+ }
149
+
150
+ const widget = await getWidgetDataHandler(
151
+ previewSlug(slug, previewId),
152
+ locale,
153
+ currency,
154
+ undefined,
155
+ PREVIEW_NO_STORE
156
+ )();
157
+
158
+ const rawAttribute = (
159
+ widget as { attributes?: Record<string, unknown> } | null
160
+ )?.attributes?.[PREVIEW_SNAPSHOT_ATTRIBUTE];
161
+ const rawValue =
162
+ typeof rawAttribute === 'object' &&
163
+ rawAttribute !== null &&
164
+ 'value' in rawAttribute
165
+ ? (rawAttribute as { value?: unknown }).value
166
+ : rawAttribute;
167
+
168
+ if (typeof rawValue !== 'string' || !rawValue) {
169
+ return null;
170
+ }
171
+
172
+ try {
173
+ const parsed = JSON.parse(rawValue);
174
+ if (parsed?.version === 1 && Array.isArray(parsed.sections)) {
175
+ return parsed as PreviewSnapshot;
176
+ }
177
+ } catch {
178
+ // Malformed snapshot — fall back to the live render path.
179
+ }
180
+ return null;
181
+ };
10
182
 
11
183
  const getWidgetDataHandler =
12
184
  (
13
185
  slug: string,
14
186
  locale: string,
15
187
  currency: string,
16
- headers?: Record<string, string>
188
+ headers?: Record<string, string>,
189
+ next?: { revalidate: number }
17
190
  ) =>
18
191
  async () => {
19
192
  if (!slug) {
@@ -25,13 +198,20 @@ const getWidgetDataHandler =
25
198
  locale,
26
199
  currency,
27
200
  init: {
28
- headers
201
+ headers,
202
+ ...(next ? { next } : {})
29
203
  }
30
204
  });
31
205
  };
32
206
 
33
207
  const getWidgetSchemaDataHandler =
34
- (widgetSlug: string, locale: string, currency: string) => async () => {
208
+ (
209
+ widgetSlug: string,
210
+ locale: string,
211
+ currency: string,
212
+ next?: { revalidate: number }
213
+ ) =>
214
+ async () => {
35
215
  if (!widgetSlug) {
36
216
  return null;
37
217
  }
@@ -39,7 +219,8 @@ const getWidgetSchemaDataHandler =
39
219
  return await appFetch({
40
220
  url: widgets.getWidgetSchema(widgetSlug),
41
221
  locale,
42
- currency
222
+ currency,
223
+ init: next ? { next } : {}
43
224
  });
44
225
  };
45
226
 
@@ -56,7 +237,36 @@ export const getWidgetData = async <T>({
56
237
  cacheOptions?: CacheOptions;
57
238
  headers?: Record<string, string>;
58
239
  }): Promise<WidgetResultType<T>> => {
59
- const result = await Cache.wrap(
240
+ const requestPreviewId =
241
+ slug === 'theme-config' ? '' : await previewIdForRequest(locale, currency);
242
+ const previewId = isPreviewTransformableSlug(slug, requestPreviewId)
243
+ ? requestPreviewId
244
+ : '';
245
+ if (previewId) {
246
+ const previewData = await getWidgetDataHandler(
247
+ previewSlug(slug, previewId),
248
+ locale,
249
+ currency,
250
+ headers,
251
+ PREVIEW_NO_STORE
252
+ )();
253
+
254
+ // A snapshot HOLDER (placeholder blob carrier, consumed exclusively via
255
+ // getPreviewSnapshot) is not a per-widget preview copy — returning it
256
+ // here would shadow the live widget with an attribute-less shell when
257
+ // its blob is malformed and the caller fell back to the live path.
258
+ const previewAttributes = (
259
+ previewData as { attributes?: Record<string, unknown> } | null
260
+ )?.attributes;
261
+ if (
262
+ previewAttributes &&
263
+ previewAttributes[PREVIEW_SNAPSHOT_ATTRIBUTE] === undefined
264
+ ) {
265
+ return previewData as WidgetResultType<T>;
266
+ }
267
+ }
268
+
269
+ return Cache.wrap(
60
270
  CacheKey.Widget(slug),
61
271
  locale,
62
272
  getWidgetDataHandler(slug, locale, currency, headers),
@@ -65,20 +275,16 @@ export const getWidgetData = async <T>({
65
275
  ...cacheOptions
66
276
  }
67
277
  );
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
278
  };
79
279
 
80
280
  const getCollectionWidgetDataHandler =
81
- (slug: string, locale: string, currency: string) => async () => {
281
+ (
282
+ slug: string,
283
+ locale: string,
284
+ currency: string,
285
+ next?: { revalidate: number }
286
+ ) =>
287
+ async () => {
82
288
  if (!slug) {
83
289
  return null;
84
290
  }
@@ -86,7 +292,8 @@ const getCollectionWidgetDataHandler =
86
292
  return await appFetch({
87
293
  url: widgets.getCollectionWidget(slug),
88
294
  locale,
89
- currency
295
+ currency,
296
+ init: next ? { next } : {}
90
297
  });
91
298
  };
92
299
 
@@ -101,6 +308,24 @@ export const getCollectionWidgetData = async <T>({
101
308
  currency?: string;
102
309
  cacheOptions?: CacheOptions;
103
310
  }): Promise<WidgetResultType<T>> => {
311
+ const requestPreviewId =
312
+ slug === 'theme-config' ? '' : await previewIdForRequest(locale, currency);
313
+ const previewId = isPreviewTransformableSlug(slug, requestPreviewId)
314
+ ? requestPreviewId
315
+ : '';
316
+ if (previewId) {
317
+ const previewData = await getCollectionWidgetDataHandler(
318
+ previewSlug(slug, previewId),
319
+ locale,
320
+ currency,
321
+ PREVIEW_NO_STORE
322
+ )();
323
+
324
+ if ((previewData as { attributes?: unknown } | null)?.attributes) {
325
+ return previewData as WidgetResultType<T>;
326
+ }
327
+ }
328
+
104
329
  return Cache.wrap(
105
330
  CacheKey.Widget(`collection:${slug}`),
106
331
  locale,
@@ -123,6 +348,26 @@ export const getWidgetSchemaData = async <T>({
123
348
  currency?: string;
124
349
  cacheOptions?: CacheOptions;
125
350
  }): Promise<WidgetSchemaType<T>> => {
351
+ const requestPreviewId =
352
+ widgetSlug === 'theme-config'
353
+ ? ''
354
+ : await previewIdForRequest(locale, currency);
355
+ const previewId = isPreviewTransformableSlug(widgetSlug, requestPreviewId)
356
+ ? requestPreviewId
357
+ : '';
358
+ if (previewId) {
359
+ const previewData = await getWidgetSchemaDataHandler(
360
+ previewSlug(widgetSlug, previewId),
361
+ locale,
362
+ currency,
363
+ PREVIEW_NO_STORE
364
+ )();
365
+
366
+ if ((previewData as { schema?: unknown } | null)?.schema) {
367
+ return previewData as WidgetSchemaType<T>;
368
+ }
369
+ }
370
+
126
371
  return Cache.wrap(
127
372
  CacheKey.WidgetSchema(widgetSlug),
128
373
  locale,
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 ? `&currency=${currency}` : ''}${
44
- filterType && filterValue ? `&${filterType}=${filterValue}` : ''
45
- }`,
43
+ }${currency ? `&currency=${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/',
@@ -15,6 +15,7 @@ import {
15
15
  getBuiltInSegments,
16
16
  isLegacyMode
17
17
  } from '../../utils/pz-segments';
18
+ import { isValidPreviewId, PREVIEW_PZ_SEGMENT } from '../../utils/preview';
18
19
 
19
20
  type SegmentType = 'root-layout' | 'layout' | 'page';
20
21
 
@@ -60,6 +61,9 @@ export const withSegmentDefaults =
60
61
 
61
62
  let localeValue: string;
62
63
  let currencyValue: string;
64
+ // Which named widget preview this render belongs to, if any — see
65
+ // utils/preview.ts for why it travels in the route rather than a cookie.
66
+ let previewValue = '';
63
67
 
64
68
  if (isLegacyMode(settings)) {
65
69
  localeValue = resolvedParams.locale;
@@ -70,6 +74,10 @@ export const withSegmentDefaults =
70
74
  const builtIn = getBuiltInSegments(parsed, settings);
71
75
  localeValue = builtIn.locale;
72
76
  currencyValue = builtIn.currency;
77
+ // Cookie-derived, so re-validated here rather than trusted.
78
+ previewValue = isValidPreviewId(parsed[PREVIEW_PZ_SEGMENT])
79
+ ? parsed[PREVIEW_PZ_SEGMENT]
80
+ : '';
73
81
  }
74
82
 
75
83
  if (options.segmentType === 'root-layout') {
@@ -83,6 +91,7 @@ export const withSegmentDefaults =
83
91
 
84
92
  ServerVariables.locale = localeValue;
85
93
  ServerVariables.currency = currencyValue;
94
+ ServerVariables.previewId = previewValue;
86
95
 
87
96
  return await (
88
97
  <>
package/hooks/index.ts CHANGED
@@ -15,4 +15,3 @@ export * from './use-logger-context';
15
15
  export * from './use-sentry-uncaught-errors';
16
16
  export * from './use-pz-params';
17
17
  export * from './use-toast';
18
- export * from './use-client-env';