@akinon/next 2.0.0-beta.9 → 2.0.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 +434 -23
- package/__tests__/next-config.test.ts +83 -0
- package/__tests__/tsconfig.json +23 -0
- package/api/auth.ts +367 -63
- package/api/barcode-search.ts +59 -0
- package/api/cache.ts +41 -5
- package/api/client.ts +21 -4
- package/api/form.ts +85 -0
- package/api/image-proxy.ts +75 -0
- package/api/product-categories.ts +53 -0
- package/api/similar-product-list.ts +63 -0
- package/api/similar-products.ts +111 -0
- package/api/virtual-try-on.ts +382 -0
- package/assets/styles/index.scss +84 -0
- package/babel.config.js +6 -0
- package/bin/pz-generate-routes.js +115 -0
- package/bin/pz-install-plugins.js +1 -1
- package/bin/pz-prebuild.js +1 -0
- package/bin/pz-predev.js +1 -0
- package/bin/pz-run-tests.js +99 -0
- package/components/accordion.tsx +21 -6
- package/components/client-root.tsx +119 -3
- package/components/file-input.tsx +65 -3
- package/components/index.ts +1 -0
- package/components/input.tsx +2 -2
- package/components/link.tsx +46 -16
- package/components/logger-popup.tsx +213 -0
- package/components/modal.tsx +32 -16
- package/components/plugin-module.tsx +62 -3
- package/components/price.tsx +2 -2
- package/components/select.tsx +3 -3
- package/components/selected-payment-option-view.tsx +21 -0
- package/data/client/account.ts +17 -2
- package/data/client/basket.ts +39 -0
- package/data/client/checkout.ts +336 -99
- package/data/client/misc.ts +13 -1
- package/data/server/category.ts +11 -9
- package/data/server/flatpage.ts +4 -1
- package/data/server/form.ts +4 -1
- package/data/server/landingpage.ts +4 -1
- package/data/server/list.ts +5 -4
- package/data/server/menu.ts +4 -1
- package/data/server/product.ts +97 -52
- package/data/server/seo.ts +4 -1
- package/data/server/special-page.ts +5 -4
- package/data/server/widget.ts +71 -1
- package/data/urls.ts +6 -3
- package/hocs/client/with-segment-defaults.tsx +2 -2
- package/hocs/server/with-segment-defaults.tsx +81 -20
- package/hooks/index.ts +3 -0
- package/hooks/use-localization.ts +24 -10
- package/hooks/use-logger-context.tsx +114 -0
- package/hooks/use-logger.ts +92 -0
- package/hooks/use-loyalty-availability.ts +21 -0
- package/hooks/use-payment-options.ts +2 -1
- package/hooks/use-pz-params.ts +37 -0
- package/hooks/use-router.ts +53 -19
- package/instrumentation/index.ts +0 -1
- package/instrumentation/node.ts +2 -20
- package/jest.config.js +25 -0
- package/lib/cache-handler.mjs +534 -16
- package/lib/cache.ts +269 -34
- package/localization/provider.tsx +2 -5
- package/middlewares/bfcache-headers.ts +18 -0
- package/middlewares/checkout-provider.ts +1 -1
- package/middlewares/complete-gpay.ts +32 -26
- package/middlewares/complete-masterpass.ts +33 -26
- package/middlewares/complete-wallet.ts +182 -0
- package/middlewares/default.ts +357 -203
- package/middlewares/index.ts +10 -2
- package/middlewares/locale.ts +5 -3
- package/middlewares/masterpass-rest-callback.ts +230 -0
- package/middlewares/oauth-login.ts +200 -57
- package/middlewares/pretty-url.ts +21 -8
- package/middlewares/redirection-payment.ts +32 -26
- package/middlewares/saved-card-redirection.ts +33 -26
- package/middlewares/three-d-redirection.ts +32 -26
- package/middlewares/url-redirection.ts +9 -15
- package/middlewares/wallet-complete-redirection.ts +206 -0
- package/package.json +24 -10
- package/plugins.d.ts +19 -4
- package/plugins.js +9 -1
- package/redux/actions.ts +47 -0
- package/redux/middlewares/checkout.ts +61 -8
- package/redux/middlewares/index.ts +14 -10
- package/redux/middlewares/pre-order/address.ts +1 -1
- package/redux/middlewares/pre-order/attribute-based-shipping-option.ts +1 -1
- package/redux/middlewares/pre-order/data-source-shipping-option.ts +1 -1
- package/redux/middlewares/pre-order/delivery-option.ts +1 -1
- package/redux/middlewares/pre-order/index.ts +3 -1
- package/redux/middlewares/pre-order/installment-option.ts +2 -1
- package/redux/middlewares/pre-order/payment-option-reset.ts +37 -0
- package/redux/middlewares/pre-order/payment-option.ts +1 -1
- package/redux/middlewares/pre-order/pre-order-validation.ts +4 -3
- package/redux/middlewares/pre-order/redirection.ts +2 -2
- package/redux/middlewares/pre-order/set-pre-order.ts +2 -2
- package/redux/middlewares/pre-order/shipping-option.ts +1 -1
- package/redux/middlewares/pre-order/shipping-step.ts +1 -1
- package/redux/reducers/checkout.ts +15 -1
- package/redux/reducers/index.ts +7 -1
- package/redux/reducers/widget.ts +80 -0
- package/sentry/index.ts +54 -17
- package/tailwind/content.js +16 -0
- package/types/commerce/checkout.ts +26 -1
- package/types/commerce/widget.ts +33 -0
- package/types/index.ts +114 -5
- package/types/next-auth.d.ts +2 -2
- package/types/widget.ts +80 -0
- package/utils/app-fetch.ts +7 -2
- package/utils/generate-commerce-search-params.ts +3 -2
- package/utils/get-checkout-path.ts +3 -0
- package/utils/get-root-hostname.ts +28 -0
- package/utils/index.ts +69 -18
- package/utils/mobile-3d-iframe.ts +8 -2
- package/utils/override-middleware.ts +1 -0
- package/utils/pz-segments.ts +92 -0
- package/utils/redirect-ignore.ts +35 -0
- package/utils/redirect.ts +9 -3
- package/utils/redirection-iframe.ts +8 -2
- package/utils/widget-styles.ts +107 -0
- package/with-pz-config.js +20 -7
package/data/client/misc.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
EmailSubscriptionType,
|
|
3
3
|
MenuItemType,
|
|
4
|
-
WidgetResultType
|
|
4
|
+
WidgetResultType,
|
|
5
|
+
WidgetSchemaType,
|
|
6
|
+
DynamicWidgetResultType
|
|
5
7
|
} from '../../types';
|
|
6
8
|
import { buildClientRequestUrl } from '../../utils';
|
|
7
9
|
import { misc, widgets } from '../urls';
|
|
@@ -80,11 +82,20 @@ export const miscApi = api.injectEndpoints({
|
|
|
80
82
|
};
|
|
81
83
|
}
|
|
82
84
|
}),
|
|
85
|
+
// change any type
|
|
83
86
|
getWidget: builder.query<WidgetResultType<any>, string>({
|
|
84
87
|
query: (slug: string) => ({
|
|
85
88
|
url: buildClientRequestUrl(widgets.getWidget(slug))
|
|
86
89
|
})
|
|
87
90
|
}),
|
|
91
|
+
getWidgetSchema: builder.query<
|
|
92
|
+
WidgetSchemaType<DynamicWidgetResultType>,
|
|
93
|
+
string
|
|
94
|
+
>({
|
|
95
|
+
query: (widgetSlug: string) => ({
|
|
96
|
+
url: buildClientRequestUrl(widgets.getWidgetSchema(widgetSlug))
|
|
97
|
+
})
|
|
98
|
+
}),
|
|
88
99
|
getMenu: builder.query<MenuItemType[], GetMenuParams>({
|
|
89
100
|
query: ({ depth, parent }) => ({
|
|
90
101
|
url: buildClientRequestUrl(misc.menus(depth, parent))
|
|
@@ -125,6 +136,7 @@ export const {
|
|
|
125
136
|
useEmailSubscriptionMutation,
|
|
126
137
|
useSetLanguageMutation,
|
|
127
138
|
useGetWidgetQuery,
|
|
139
|
+
useGetWidgetSchemaQuery,
|
|
128
140
|
useGetMenuQuery,
|
|
129
141
|
useGetBukalemunImageUrlQuery
|
|
130
142
|
} = miscApi;
|
package/data/server/category.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GetCategoryResponse } from '../../types';
|
|
1
|
+
import { GetCategoryResponse, SearchParams } from '../../types';
|
|
2
2
|
import { generateCommerceSearchParams } from '../../utils';
|
|
3
3
|
import appFetch, { FetchResponseType } from '../../utils/app-fetch';
|
|
4
4
|
import { category, product } from '../urls';
|
|
@@ -12,7 +12,7 @@ function getCategoryDataHandler(
|
|
|
12
12
|
pk: number,
|
|
13
13
|
locale: string,
|
|
14
14
|
currency: string,
|
|
15
|
-
searchParams?:
|
|
15
|
+
searchParams?: SearchParams,
|
|
16
16
|
headers?: Record<string, string>
|
|
17
17
|
) {
|
|
18
18
|
return async function () {
|
|
@@ -48,8 +48,8 @@ function getCategoryDataHandler(
|
|
|
48
48
|
logger.fatal('Error while parsing category data', {
|
|
49
49
|
handler: 'getCategoryDataHandler',
|
|
50
50
|
error,
|
|
51
|
-
rawData: rawData
|
|
52
|
-
? `${rawData
|
|
51
|
+
rawData: rawData?.startsWith?.('<!DOCTYPE html>')
|
|
52
|
+
? `${rawData?.substring(0, 50)}...`
|
|
53
53
|
: rawData
|
|
54
54
|
});
|
|
55
55
|
}
|
|
@@ -90,7 +90,7 @@ export const getCategoryData = ({
|
|
|
90
90
|
pk: number;
|
|
91
91
|
locale?: string;
|
|
92
92
|
currency?: string;
|
|
93
|
-
searchParams?:
|
|
93
|
+
searchParams?: SearchParams;
|
|
94
94
|
headers?: Record<string, string>;
|
|
95
95
|
}) => {
|
|
96
96
|
return Cache.wrap(
|
|
@@ -98,7 +98,8 @@ export const getCategoryData = ({
|
|
|
98
98
|
locale,
|
|
99
99
|
getCategoryDataHandler(pk, locale, currency, searchParams, headers),
|
|
100
100
|
{
|
|
101
|
-
expire: 300
|
|
101
|
+
expire: 300,
|
|
102
|
+
compressed: true
|
|
102
103
|
}
|
|
103
104
|
);
|
|
104
105
|
};
|
|
@@ -138,8 +139,8 @@ function getCategoryBySlugDataHandler(
|
|
|
138
139
|
logger.fatal('Error while parsing category data', {
|
|
139
140
|
handler: 'getCategoryBySlugDataHandler',
|
|
140
141
|
error,
|
|
141
|
-
rawData: rawData
|
|
142
|
-
? `${rawData
|
|
142
|
+
rawData: rawData?.startsWith?.('<!DOCTYPE html>')
|
|
143
|
+
? `${rawData?.substring(0, 50)}...`
|
|
143
144
|
: rawData
|
|
144
145
|
});
|
|
145
146
|
}
|
|
@@ -158,7 +159,8 @@ export const getCategoryBySlugData = async ({
|
|
|
158
159
|
locale,
|
|
159
160
|
getCategoryBySlugDataHandler(slug, locale, currency),
|
|
160
161
|
{
|
|
161
|
-
expire: 300
|
|
162
|
+
expire: 300,
|
|
163
|
+
compressed: true
|
|
162
164
|
}
|
|
163
165
|
);
|
|
164
166
|
};
|
package/data/server/flatpage.ts
CHANGED
package/data/server/form.ts
CHANGED
package/data/server/list.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Cache, CacheKey } from '../../lib/cache';
|
|
2
2
|
import { category } from '../urls';
|
|
3
|
-
import { GetCategoryResponse } from '../../types';
|
|
3
|
+
import { GetCategoryResponse, SearchParams } from '../../types';
|
|
4
4
|
import { generateCommerceSearchParams } from '../../utils';
|
|
5
5
|
import appFetch, { FetchResponseType } from '../../utils/app-fetch';
|
|
6
6
|
import { parse } from 'lossless-json';
|
|
@@ -10,7 +10,7 @@ import { ServerVariables } from '../../utils/server-variables';
|
|
|
10
10
|
const getListDataHandler = (
|
|
11
11
|
locale,
|
|
12
12
|
currency,
|
|
13
|
-
searchParams:
|
|
13
|
+
searchParams: SearchParams,
|
|
14
14
|
headers?: Record<string, string>
|
|
15
15
|
) => {
|
|
16
16
|
return async function () {
|
|
@@ -63,7 +63,7 @@ export const getListData = async ({
|
|
|
63
63
|
}: {
|
|
64
64
|
locale?: string;
|
|
65
65
|
currency?: string;
|
|
66
|
-
searchParams:
|
|
66
|
+
searchParams: SearchParams;
|
|
67
67
|
headers?: Record<string, string>;
|
|
68
68
|
}) => {
|
|
69
69
|
return Cache.wrap(
|
|
@@ -71,7 +71,8 @@ export const getListData = async ({
|
|
|
71
71
|
locale,
|
|
72
72
|
getListDataHandler(locale, currency, searchParams, headers),
|
|
73
73
|
{
|
|
74
|
-
expire: 300
|
|
74
|
+
expire: 300,
|
|
75
|
+
compressed: true
|
|
75
76
|
}
|
|
76
77
|
);
|
|
77
78
|
};
|
package/data/server/menu.ts
CHANGED
|
@@ -48,6 +48,9 @@ export const getMenu = async (params?: MenuHandlerParams) => {
|
|
|
48
48
|
return Cache.wrap(
|
|
49
49
|
CacheKey.Menu(params?.depth ?? DEFAULT_DEPTH, params?.parent),
|
|
50
50
|
params?.locale ?? ServerVariables.locale,
|
|
51
|
-
getMenuHandler(params)
|
|
51
|
+
getMenuHandler(params),
|
|
52
|
+
{
|
|
53
|
+
compressed: true
|
|
54
|
+
}
|
|
52
55
|
);
|
|
53
56
|
};
|
package/data/server/product.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { Cache, CacheKey } from '../../lib/cache';
|
|
2
2
|
import { product } from '../urls';
|
|
3
|
-
import { ProductCategoryResult, ProductResult } from '../../types';
|
|
3
|
+
import { ProductCategoryResult, ProductResult, SearchParams } from '../../types';
|
|
4
4
|
import appFetch from '../../utils/app-fetch';
|
|
5
5
|
import { ServerVariables } from '../../utils/server-variables';
|
|
6
6
|
import logger from '../../utils/log';
|
|
7
7
|
|
|
8
8
|
type GetProduct = {
|
|
9
|
-
pk: number;
|
|
9
|
+
pk: number | string;
|
|
10
10
|
locale?: string;
|
|
11
11
|
currency?: string;
|
|
12
|
-
searchParams?:
|
|
12
|
+
searchParams?: SearchParams;
|
|
13
13
|
groupProduct?: boolean;
|
|
14
14
|
headers?: Record<string, string>;
|
|
15
15
|
};
|
|
@@ -23,9 +23,21 @@ const getProductDataHandler = ({
|
|
|
23
23
|
headers
|
|
24
24
|
}: GetProduct) => {
|
|
25
25
|
return async function () {
|
|
26
|
+
// Convert pk to number if it's a string and validate
|
|
27
|
+
const numericPk = typeof pk === 'string' ? parseInt(pk, 10) : pk;
|
|
28
|
+
|
|
29
|
+
if (isNaN(numericPk)) {
|
|
30
|
+
logger.warn('Invalid product pk provided', {
|
|
31
|
+
handler: 'getProductDataHandler',
|
|
32
|
+
pk,
|
|
33
|
+
numericPk
|
|
34
|
+
});
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
|
|
26
38
|
let url = groupProduct
|
|
27
|
-
? product.getGroupProductByPk(
|
|
28
|
-
: product.getProductByPk(
|
|
39
|
+
? product.getGroupProductByPk(numericPk)
|
|
40
|
+
: product.getProductByPk(numericPk);
|
|
29
41
|
|
|
30
42
|
if (searchParams) {
|
|
31
43
|
url +=
|
|
@@ -35,61 +47,81 @@ const getProductDataHandler = ({
|
|
|
35
47
|
.join('&');
|
|
36
48
|
}
|
|
37
49
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
50
|
+
try {
|
|
51
|
+
const data = await appFetch<ProductResult>({
|
|
52
|
+
url,
|
|
53
|
+
locale,
|
|
54
|
+
currency,
|
|
55
|
+
init: {
|
|
56
|
+
headers: {
|
|
57
|
+
Accept: 'application/json',
|
|
58
|
+
'Content-Type': 'application/json',
|
|
59
|
+
...(headers ?? {})
|
|
60
|
+
}
|
|
47
61
|
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// If product data is not found, return null to trigger 404
|
|
65
|
+
if (!data?.product?.pk) {
|
|
66
|
+
logger.warn('Product not found', {
|
|
67
|
+
handler: 'getProductDataHandler',
|
|
68
|
+
pk: numericPk,
|
|
69
|
+
hasData: !!data,
|
|
70
|
+
hasProduct: !!data?.product
|
|
71
|
+
});
|
|
72
|
+
return null;
|
|
48
73
|
}
|
|
49
|
-
});
|
|
50
74
|
|
|
51
|
-
|
|
75
|
+
const categoryUrl = product.categoryUrl(data.product.pk);
|
|
52
76
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
77
|
+
const productCategoryData = await appFetch<ProductCategoryResult>({
|
|
78
|
+
url: categoryUrl,
|
|
79
|
+
locale,
|
|
80
|
+
currency,
|
|
81
|
+
init: {
|
|
82
|
+
headers: {
|
|
83
|
+
Accept: 'application/json',
|
|
84
|
+
'Content-Type': 'application/json'
|
|
85
|
+
}
|
|
61
86
|
}
|
|
62
|
-
}
|
|
63
|
-
});
|
|
87
|
+
});
|
|
64
88
|
|
|
65
|
-
|
|
89
|
+
const menuItemModel = productCategoryData?.results[0]?.menuitemmodel;
|
|
66
90
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
91
|
+
if (!menuItemModel) {
|
|
92
|
+
logger.warn('menuItemModel is undefined, skipping breadcrumbData fetch', {
|
|
93
|
+
handler: 'getProductDataHandler',
|
|
94
|
+
pk: numericPk
|
|
95
|
+
});
|
|
96
|
+
return { data, breadcrumbData: undefined };
|
|
97
|
+
}
|
|
74
98
|
|
|
75
|
-
|
|
99
|
+
const breadcrumbUrl = product.breadcrumbUrl(menuItemModel);
|
|
76
100
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
101
|
+
const breadcrumbData = await appFetch<any>({
|
|
102
|
+
url: breadcrumbUrl,
|
|
103
|
+
locale,
|
|
104
|
+
currency,
|
|
105
|
+
init: {
|
|
106
|
+
headers: {
|
|
107
|
+
Accept: 'application/json',
|
|
108
|
+
'Content-Type': 'application/json'
|
|
109
|
+
}
|
|
85
110
|
}
|
|
86
|
-
}
|
|
87
|
-
});
|
|
111
|
+
});
|
|
88
112
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
113
|
+
return {
|
|
114
|
+
data,
|
|
115
|
+
breadcrumbData: breadcrumbData?.menu
|
|
116
|
+
};
|
|
117
|
+
} catch (error) {
|
|
118
|
+
logger.error('Error in getProductDataHandler', {
|
|
119
|
+
handler: 'getProductDataHandler',
|
|
120
|
+
pk: numericPk,
|
|
121
|
+
error: error.message
|
|
122
|
+
});
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
93
125
|
};
|
|
94
126
|
};
|
|
95
127
|
|
|
@@ -101,9 +133,12 @@ export const getProductData = async ({
|
|
|
101
133
|
groupProduct,
|
|
102
134
|
headers
|
|
103
135
|
}: GetProduct) => {
|
|
104
|
-
|
|
136
|
+
// Convert pk to number for cache key if it's a string
|
|
137
|
+
const numericPkForCache = typeof pk === 'string' ? parseInt(pk, 10) : pk;
|
|
138
|
+
|
|
139
|
+
const result = await Cache.wrap(
|
|
105
140
|
CacheKey[groupProduct ? 'GroupProduct' : 'Product'](
|
|
106
|
-
|
|
141
|
+
numericPkForCache,
|
|
107
142
|
searchParams ?? new URLSearchParams()
|
|
108
143
|
),
|
|
109
144
|
locale,
|
|
@@ -116,7 +151,17 @@ export const getProductData = async ({
|
|
|
116
151
|
headers
|
|
117
152
|
}),
|
|
118
153
|
{
|
|
119
|
-
expire: 300
|
|
154
|
+
expire: 300,
|
|
155
|
+
compressed: true
|
|
120
156
|
}
|
|
121
157
|
);
|
|
158
|
+
|
|
159
|
+
// If product data is not found, throw 404 error
|
|
160
|
+
if (!result) {
|
|
161
|
+
const error = new Error('Product not found') as Error & { status: number };
|
|
162
|
+
error.status = 404;
|
|
163
|
+
throw error;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return result;
|
|
122
167
|
};
|
package/data/server/seo.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Cache, CacheKey } from '../../lib/cache';
|
|
2
2
|
import { category } from '../urls';
|
|
3
|
-
import { GetCategoryResponse } from '../../types';
|
|
3
|
+
import { GetCategoryResponse, SearchParams } from '../../types';
|
|
4
4
|
import { generateCommerceSearchParams } from '../../utils';
|
|
5
5
|
import appFetch from '../../utils/app-fetch';
|
|
6
6
|
import { ServerVariables } from '../../utils/server-variables';
|
|
@@ -9,7 +9,7 @@ const getSpecialPageDataHandler = (
|
|
|
9
9
|
pk: number,
|
|
10
10
|
locale: string,
|
|
11
11
|
currency: string,
|
|
12
|
-
searchParams:
|
|
12
|
+
searchParams: SearchParams,
|
|
13
13
|
headers?: Record<string, string>
|
|
14
14
|
) => {
|
|
15
15
|
return async function () {
|
|
@@ -42,7 +42,7 @@ export const getSpecialPageData = async ({
|
|
|
42
42
|
pk: number;
|
|
43
43
|
locale?: string;
|
|
44
44
|
currency?: string;
|
|
45
|
-
searchParams:
|
|
45
|
+
searchParams: SearchParams;
|
|
46
46
|
headers?: Record<string, string>;
|
|
47
47
|
}) => {
|
|
48
48
|
return Cache.wrap(
|
|
@@ -50,7 +50,8 @@ export const getSpecialPageData = async ({
|
|
|
50
50
|
locale,
|
|
51
51
|
getSpecialPageDataHandler(pk, locale, currency, searchParams, headers),
|
|
52
52
|
{
|
|
53
|
-
expire: 300
|
|
53
|
+
expire: 300,
|
|
54
|
+
compressed: true
|
|
54
55
|
}
|
|
55
56
|
);
|
|
56
57
|
};
|
package/data/server/widget.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Cache, CacheKey } from '../../lib/cache';
|
|
2
2
|
import 'server-only';
|
|
3
|
-
import { CacheOptions, WidgetResultType } from '../../types';
|
|
3
|
+
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';
|
|
@@ -27,6 +27,19 @@ const getWidgetDataHandler =
|
|
|
27
27
|
});
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
+
const getWidgetSchemaDataHandler =
|
|
31
|
+
(widgetSlug: string, locale: string, currency: string) => async () => {
|
|
32
|
+
if (!widgetSlug) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return await appFetch({
|
|
37
|
+
url: widgets.getWidgetSchema(widgetSlug),
|
|
38
|
+
locale,
|
|
39
|
+
currency
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
|
|
30
43
|
export const getWidgetData = async <T>({
|
|
31
44
|
slug,
|
|
32
45
|
locale = ServerVariables.locale,
|
|
@@ -44,6 +57,63 @@ export const getWidgetData = async <T>({
|
|
|
44
57
|
CacheKey.Widget(slug),
|
|
45
58
|
locale,
|
|
46
59
|
getWidgetDataHandler(slug, locale, currency, headers),
|
|
60
|
+
{
|
|
61
|
+
compressed: true,
|
|
62
|
+
...cacheOptions
|
|
63
|
+
}
|
|
64
|
+
);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const getCollectionWidgetDataHandler =
|
|
68
|
+
(slug: string, locale: string, currency: string) => async () => {
|
|
69
|
+
if (!slug) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return await appFetch({
|
|
74
|
+
url: widgets.getCollectionWidget(slug),
|
|
75
|
+
locale,
|
|
76
|
+
currency
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export const getCollectionWidgetData = async <T>({
|
|
81
|
+
slug,
|
|
82
|
+
locale = ServerVariables.locale,
|
|
83
|
+
currency = ServerVariables.currency,
|
|
84
|
+
cacheOptions
|
|
85
|
+
}: {
|
|
86
|
+
slug: string;
|
|
87
|
+
locale?: string;
|
|
88
|
+
currency?: string;
|
|
89
|
+
cacheOptions?: CacheOptions;
|
|
90
|
+
}): Promise<WidgetResultType<T>> => {
|
|
91
|
+
return Cache.wrap(
|
|
92
|
+
CacheKey.Widget(`collection:${slug}`),
|
|
93
|
+
locale,
|
|
94
|
+
getCollectionWidgetDataHandler(slug, locale, currency),
|
|
95
|
+
{
|
|
96
|
+
compressed: true,
|
|
97
|
+
...cacheOptions
|
|
98
|
+
}
|
|
99
|
+
);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export const getWidgetSchemaData = async <T>({
|
|
103
|
+
widgetSlug,
|
|
104
|
+
locale = ServerVariables.locale,
|
|
105
|
+
currency = ServerVariables.currency,
|
|
106
|
+
cacheOptions
|
|
107
|
+
}: {
|
|
108
|
+
widgetSlug: string;
|
|
109
|
+
locale?: string;
|
|
110
|
+
currency?: string;
|
|
111
|
+
cacheOptions?: CacheOptions;
|
|
112
|
+
}): Promise<WidgetSchemaType<T>> => {
|
|
113
|
+
return Cache.wrap(
|
|
114
|
+
CacheKey.WidgetSchema(widgetSlug),
|
|
115
|
+
locale,
|
|
116
|
+
getWidgetSchemaDataHandler(widgetSlug, locale, currency),
|
|
47
117
|
cacheOptions
|
|
48
118
|
);
|
|
49
119
|
};
|
package/data/urls.ts
CHANGED
|
@@ -142,7 +142,8 @@ export const checkout = {
|
|
|
142
142
|
setOrderSelectionPage: '/orders/checkout/?page=OrderSelectionPage',
|
|
143
143
|
loyaltyCardPage: '/orders/checkout/?page=LoyaltyCardPage',
|
|
144
144
|
sendSmsPage: '/orders/checkout/?page=SendSmsPage',
|
|
145
|
-
verifySmsPage: '/orders/checkout/?page=VerifySmsPage'
|
|
145
|
+
verifySmsPage: '/orders/checkout/?page=VerifySmsPage',
|
|
146
|
+
saveSampleProducts: '/orders/checkout/?page=SampleProductPage'
|
|
146
147
|
};
|
|
147
148
|
|
|
148
149
|
export const flatpage = {
|
|
@@ -242,11 +243,13 @@ export const b2b = {
|
|
|
242
243
|
};
|
|
243
244
|
|
|
244
245
|
export const widgets = {
|
|
245
|
-
getWidget: (slug: string) => `/widgets/${slug}
|
|
246
|
+
getWidget: (slug: string) => `/widgets/${slug}/`,
|
|
247
|
+
getWidgetSchema: (widgetSlug: string) => `/widgets/${widgetSlug}/schema/`,
|
|
248
|
+
getCollectionWidget: (slug: string) => `/product_collection_widgets/${slug}/`
|
|
246
249
|
};
|
|
247
250
|
|
|
248
251
|
export const form = {
|
|
249
|
-
getForm: (pk: number) => `/forms/${pk}/generate
|
|
252
|
+
getForm: (pk: number) => `/forms/${pk}/generate`
|
|
250
253
|
};
|
|
251
254
|
|
|
252
255
|
const URLS = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ResolvedLayoutProps, ResolvedPageProps, ResolvedRootLayoutProps } from '../../types';
|
|
2
2
|
import React, { JSX } from 'react';
|
|
3
3
|
|
|
4
4
|
type SegmentType = 'client-root' | 'layout' | 'page';
|
|
@@ -8,7 +8,7 @@ interface SegmentDefaultsOptions {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export const withSegmentDefaults =
|
|
11
|
-
<T extends
|
|
11
|
+
<T extends ResolvedPageProps | ResolvedLayoutProps | ResolvedRootLayoutProps>(
|
|
12
12
|
Component: (
|
|
13
13
|
props?: T
|
|
14
14
|
) => null | JSX.Element | Promise<JSX.Element> | Promise<JSX.Element[]>,
|