@akinon/next 1.55.0 → 1.56.0-rc.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 +482 -0
- package/api/client.ts +50 -17
- package/assets/styles/index.css +49 -0
- package/assets/styles/index.css.map +1 -0
- package/assets/styles/index.scss +50 -26
- package/bin/pz-generate-translations.js +41 -0
- package/bin/pz-prebuild.js +1 -0
- package/bin/pz-predev.js +1 -0
- package/components/file-input.tsx +8 -0
- package/components/index.ts +1 -0
- package/components/input.tsx +21 -7
- package/components/link.tsx +17 -13
- package/components/price.tsx +11 -4
- package/components/pz-root.tsx +15 -3
- package/components/selected-payment-option-view.tsx +26 -38
- package/data/client/account.ts +10 -9
- package/data/client/api.ts +1 -1
- package/data/client/b2b.ts +35 -2
- package/data/client/basket.ts +6 -5
- package/data/client/checkout.ts +38 -1
- package/data/client/user.ts +3 -2
- package/data/server/category.ts +43 -19
- package/data/server/flatpage.ts +29 -7
- package/data/server/form.ts +29 -11
- package/data/server/landingpage.ts +26 -7
- package/data/server/list.ts +16 -6
- package/data/server/menu.ts +15 -2
- package/data/server/product.ts +33 -13
- package/data/server/seo.ts +17 -24
- package/data/server/special-page.ts +15 -5
- package/data/server/widget.ts +14 -7
- package/data/urls.ts +8 -1
- package/hocs/server/with-segment-defaults.tsx +4 -1
- package/hooks/index.ts +2 -1
- package/hooks/use-message-listener.ts +24 -0
- package/hooks/use-pagination.ts +2 -2
- package/hooks/use-payment-options.ts +2 -1
- package/lib/cache-handler.mjs +33 -0
- package/lib/cache.ts +8 -6
- package/middlewares/default.ts +87 -8
- package/middlewares/pretty-url.ts +11 -1
- package/middlewares/url-redirection.ts +4 -0
- package/package.json +4 -3
- package/redux/middlewares/checkout.ts +69 -10
- package/redux/reducers/checkout.ts +23 -3
- package/routes/pretty-url.tsx +192 -0
- package/types/commerce/account.ts +1 -0
- package/types/commerce/address.ts +1 -1
- package/types/commerce/b2b.ts +12 -2
- package/types/commerce/checkout.ts +30 -0
- package/types/commerce/order.ts +1 -0
- package/types/index.ts +18 -2
- package/utils/app-fetch.ts +17 -8
- package/utils/generate-commerce-search-params.ts +3 -1
- package/utils/index.ts +27 -6
- package/utils/redirection-iframe.ts +85 -0
- package/utils/server-translation.ts +11 -1
- package/utils/server-variables.ts +2 -1
- package/with-pz-config.js +13 -2
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { URLS } from '@akinon/next/data/urls';
|
|
2
|
+
import { Metadata, PageProps } from '@akinon/next/types';
|
|
3
|
+
import logger from '@akinon/next/utils/log';
|
|
4
|
+
import { notFound } from 'next/navigation';
|
|
5
|
+
|
|
6
|
+
type PrettyUrlResult = {
|
|
7
|
+
matched: boolean;
|
|
8
|
+
path?: string;
|
|
9
|
+
pk?: number;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const resolvePrettyUrlHandler =
|
|
13
|
+
(pathname: string, ip: string | null) => async () => {
|
|
14
|
+
let results = [] as { old_path: string }[];
|
|
15
|
+
let prettyUrlResult: PrettyUrlResult = {
|
|
16
|
+
matched: false
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
const requestUrl = URLS.misc.prettyUrls(`/${pathname}/`);
|
|
21
|
+
|
|
22
|
+
logger.debug(`Resolving pretty url`, { pathname, requestUrl, ip });
|
|
23
|
+
|
|
24
|
+
const start = Date.now();
|
|
25
|
+
const apiResponse = await fetch(requestUrl, {
|
|
26
|
+
next: {
|
|
27
|
+
revalidate: 0
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
const data = await apiResponse.json();
|
|
31
|
+
({ results } = data);
|
|
32
|
+
const end = Date.now();
|
|
33
|
+
console.warn('Pretty url response time', end - start, requestUrl);
|
|
34
|
+
|
|
35
|
+
const matched = results.length > 0;
|
|
36
|
+
const [{ old_path: path } = { old_path: '' }] = results;
|
|
37
|
+
let pk;
|
|
38
|
+
|
|
39
|
+
if (matched) {
|
|
40
|
+
const pkRegex = /\/(\d+)\/$/;
|
|
41
|
+
const match = path.match(pkRegex);
|
|
42
|
+
pk = match ? parseInt(match[1]) : undefined;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
prettyUrlResult = {
|
|
46
|
+
matched,
|
|
47
|
+
path,
|
|
48
|
+
pk
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
logger.trace('Pretty url result', { prettyUrlResult, ip });
|
|
52
|
+
} catch (error) {
|
|
53
|
+
logger.error('Error resolving pretty url', { error, pathname, ip });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return prettyUrlResult;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export async function generateMetadata({ params }: PageProps) {
|
|
60
|
+
let result: Metadata = {};
|
|
61
|
+
const { prettyurl } = params;
|
|
62
|
+
const pageSlug = prettyurl
|
|
63
|
+
.filter((x) => !x.startsWith('searchparams'))
|
|
64
|
+
.join('/');
|
|
65
|
+
|
|
66
|
+
const searchParams = new URLSearchParams(
|
|
67
|
+
decodeURIComponent(
|
|
68
|
+
prettyurl
|
|
69
|
+
.find((x) => x.startsWith('searchparams'))
|
|
70
|
+
?.replace('searchparams%7C', '')
|
|
71
|
+
) ?? {}
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
const prettyUrlResult = await resolvePrettyUrlHandler(pageSlug, null)();
|
|
75
|
+
|
|
76
|
+
if (!prettyUrlResult.matched) {
|
|
77
|
+
return notFound();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const commonProps = {
|
|
81
|
+
params: {
|
|
82
|
+
...params,
|
|
83
|
+
pk: prettyUrlResult.pk
|
|
84
|
+
},
|
|
85
|
+
searchParams
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
try {
|
|
89
|
+
if (prettyUrlResult.path.startsWith('/product/')) {
|
|
90
|
+
await import('@product/[pk]/page').then(async (module) => {
|
|
91
|
+
result = await module['generateMetadata']?.(commonProps);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (prettyUrlResult.path.startsWith('/group-product/')) {
|
|
96
|
+
await import('@group-product/[pk]/page').then(async (module) => {
|
|
97
|
+
result = await module['generateMetadata']?.(commonProps);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (prettyUrlResult.path.startsWith('/category/')) {
|
|
102
|
+
await import('@category/[pk]/page').then(async (module) => {
|
|
103
|
+
result = await module['generateMetadata']?.(commonProps);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (prettyUrlResult.path.startsWith('/special-page/')) {
|
|
108
|
+
await import('@special-page/[pk]/page').then(async (module) => {
|
|
109
|
+
result = await module['generateMetadata']?.(commonProps);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (prettyUrlResult.path.startsWith('/flat-page/')) {
|
|
114
|
+
await import('@flat-page/[pk]/page').then(async (module) => {
|
|
115
|
+
result = await module['generateMetadata']?.(commonProps);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
// eslint-disable-next-line no-empty
|
|
119
|
+
} catch (error) {}
|
|
120
|
+
|
|
121
|
+
return result;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export const dynamic = 'force-static';
|
|
125
|
+
export const revalidate = 300;
|
|
126
|
+
|
|
127
|
+
export default async function Page({ params }) {
|
|
128
|
+
const { prettyurl } = params;
|
|
129
|
+
const pageSlug = prettyurl
|
|
130
|
+
.filter((x) => !x.startsWith('searchparams'))
|
|
131
|
+
.join('/');
|
|
132
|
+
|
|
133
|
+
const urlSearchParams = new URLSearchParams(
|
|
134
|
+
decodeURIComponent(
|
|
135
|
+
prettyurl
|
|
136
|
+
.find((x) => x.startsWith('searchparams'))
|
|
137
|
+
?.replace('searchparams%7C', '')
|
|
138
|
+
) ?? {}
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
const searchParams = {};
|
|
142
|
+
|
|
143
|
+
for (const [key, value] of urlSearchParams.entries() as unknown as Array<
|
|
144
|
+
[string, string]
|
|
145
|
+
>) {
|
|
146
|
+
if (!searchParams[key]) {
|
|
147
|
+
searchParams[key] = [];
|
|
148
|
+
}
|
|
149
|
+
searchParams[key].push(value);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const result = await resolvePrettyUrlHandler(pageSlug, null)();
|
|
153
|
+
|
|
154
|
+
if (!result.matched) {
|
|
155
|
+
return notFound();
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const commonProps = {
|
|
159
|
+
params: {
|
|
160
|
+
...params,
|
|
161
|
+
pk: result.pk
|
|
162
|
+
},
|
|
163
|
+
searchParams: new URLSearchParams(searchParams)
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
if (result.path.startsWith('/category/')) {
|
|
167
|
+
const CategoryPage = (await import('@category/[pk]/page')).default;
|
|
168
|
+
return <CategoryPage {...commonProps} />;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (result.path.startsWith('/product/')) {
|
|
172
|
+
const ProductPage = (await import('@product/[pk]/page')).default;
|
|
173
|
+
return <ProductPage {...commonProps} />;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (result.path.startsWith('/group-product/')) {
|
|
177
|
+
const GroupProduct = (await import('@group-product/[pk]/page')).default;
|
|
178
|
+
return <GroupProduct {...commonProps} />;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (result.path.startsWith('/special-page/')) {
|
|
182
|
+
const SpecialPage = (await import('@special-page/[pk]/page')).default;
|
|
183
|
+
return <SpecialPage {...commonProps} />;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (result.path.startsWith('/flat-page/')) {
|
|
187
|
+
const FlatPage = (await import('@flat-page/[pk]/page')).default;
|
|
188
|
+
return <FlatPage {...commonProps} />;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return null;
|
|
192
|
+
}
|
package/types/commerce/b2b.ts
CHANGED
|
@@ -72,7 +72,7 @@ export type BasketItemType = {
|
|
|
72
72
|
divisions: BasketItemDivision[];
|
|
73
73
|
product: ProductB2b;
|
|
74
74
|
product_remote_id: number;
|
|
75
|
-
}
|
|
75
|
+
};
|
|
76
76
|
|
|
77
77
|
export type BasketParams = {
|
|
78
78
|
division: string;
|
|
@@ -91,7 +91,7 @@ export type CreateQuotationParams = {
|
|
|
91
91
|
export type UpdateProductParams = {
|
|
92
92
|
product_remote_id: number;
|
|
93
93
|
division: number;
|
|
94
|
-
quantity: number
|
|
94
|
+
quantity: number;
|
|
95
95
|
};
|
|
96
96
|
|
|
97
97
|
export type DeleteProductParams = {
|
|
@@ -115,3 +115,13 @@ export type DraftResponse = {
|
|
|
115
115
|
total_amount: number;
|
|
116
116
|
total_quantity: number;
|
|
117
117
|
};
|
|
118
|
+
|
|
119
|
+
export type BasketStatusResponse = {
|
|
120
|
+
is_ready: boolean;
|
|
121
|
+
status: string;
|
|
122
|
+
url: string;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export type ExportBasketResponse = {
|
|
126
|
+
cache_key: string;
|
|
127
|
+
};
|
|
@@ -34,6 +34,23 @@ export interface ShippingOption {
|
|
|
34
34
|
slug: string;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
export interface DataSource {
|
|
38
|
+
pk: number;
|
|
39
|
+
name: string;
|
|
40
|
+
data_source_shipping_options: DataSourceShippingOption[];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface DataSourceShippingOption {
|
|
44
|
+
pk: number;
|
|
45
|
+
shipping_amount: string;
|
|
46
|
+
shipping_option_name: string;
|
|
47
|
+
shipping_option_logo: string | null;
|
|
48
|
+
data_source: {
|
|
49
|
+
pk: number;
|
|
50
|
+
title: string | null;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
37
54
|
export interface CheckoutAddressType {
|
|
38
55
|
label: string;
|
|
39
56
|
text: string;
|
|
@@ -79,6 +96,8 @@ export interface PreOrder {
|
|
|
79
96
|
retail_store?: RetailStore;
|
|
80
97
|
gift_box?: GiftBox;
|
|
81
98
|
credit_payment_option?: CheckoutCreditPaymentOption;
|
|
99
|
+
data_source_shipping_options: any;
|
|
100
|
+
attribute_based_shipping_options?: AttributeBasedShippingOption[];
|
|
82
101
|
bags?: Product[];
|
|
83
102
|
bags_fee?: string;
|
|
84
103
|
}
|
|
@@ -120,6 +139,7 @@ export interface CheckoutContext {
|
|
|
120
139
|
redirect_url?: string;
|
|
121
140
|
context_data?: any;
|
|
122
141
|
balance?: string;
|
|
142
|
+
attribute_based_shipping_options?: AttributeBasedShippingOption[];
|
|
123
143
|
[key: string]: any;
|
|
124
144
|
};
|
|
125
145
|
}
|
|
@@ -145,3 +165,13 @@ export interface BankAccount {
|
|
|
145
165
|
pk: number;
|
|
146
166
|
sort_order: number;
|
|
147
167
|
}
|
|
168
|
+
|
|
169
|
+
export interface AttributeBasedShippingOption {
|
|
170
|
+
pk: number;
|
|
171
|
+
shipping_amount: string | null;
|
|
172
|
+
shipping_option_name: string | null;
|
|
173
|
+
shipping_option_logo: string | null;
|
|
174
|
+
attribute_value: string | null;
|
|
175
|
+
attribute_key: string;
|
|
176
|
+
[key: string]: any;
|
|
177
|
+
}
|
package/types/commerce/order.ts
CHANGED
package/types/index.ts
CHANGED
|
@@ -68,9 +68,17 @@ export interface Currency {
|
|
|
68
68
|
* @see https://en.wikipedia.org/wiki/ISO_4217
|
|
69
69
|
*/
|
|
70
70
|
code: string;
|
|
71
|
+
/**
|
|
72
|
+
* Number of decimal places to display.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* decimalScale: 3
|
|
76
|
+
*/
|
|
77
|
+
decimalScale?: number;
|
|
71
78
|
}
|
|
72
79
|
|
|
73
80
|
export interface Settings {
|
|
81
|
+
usePrettyUrlRoute?: boolean;
|
|
74
82
|
commerceUrl: string;
|
|
75
83
|
redis: {
|
|
76
84
|
defaultExpirationTime: number;
|
|
@@ -183,7 +191,9 @@ export interface Settings {
|
|
|
183
191
|
masterpassJsUrl?: string;
|
|
184
192
|
};
|
|
185
193
|
customNotFoundEnabled: boolean;
|
|
194
|
+
useOptimizedTranslations?: boolean;
|
|
186
195
|
plugins?: Record<string, Record<string, any>>;
|
|
196
|
+
includedProxyHeaders?: string[];
|
|
187
197
|
}
|
|
188
198
|
|
|
189
199
|
export interface CacheOptions {
|
|
@@ -215,7 +225,7 @@ export type ImageOptions = CDNOptions & {
|
|
|
215
225
|
export type Translations = { [key: string]: object };
|
|
216
226
|
|
|
217
227
|
export interface PageProps<T = any> {
|
|
218
|
-
params: T;
|
|
228
|
+
params: T & { locale: string; currency: string };
|
|
219
229
|
searchParams: URLSearchParams;
|
|
220
230
|
}
|
|
221
231
|
|
|
@@ -224,7 +234,11 @@ export interface LayoutProps<T = any> extends PageProps<T> {
|
|
|
224
234
|
}
|
|
225
235
|
|
|
226
236
|
export interface RootLayoutProps<
|
|
227
|
-
T = {
|
|
237
|
+
T = {
|
|
238
|
+
commerce: string;
|
|
239
|
+
locale: string;
|
|
240
|
+
currency: string;
|
|
241
|
+
}
|
|
228
242
|
> extends LayoutProps<T> {
|
|
229
243
|
translations: Translations;
|
|
230
244
|
locale: Locale & {
|
|
@@ -250,6 +264,8 @@ export interface ButtonProps
|
|
|
250
264
|
appearance?: 'filled' | 'outlined' | 'ghost';
|
|
251
265
|
}
|
|
252
266
|
|
|
267
|
+
export type FileInputProps = React.HTMLProps<HTMLInputElement>;
|
|
268
|
+
|
|
253
269
|
export interface PriceProps {
|
|
254
270
|
currencyCode?: string;
|
|
255
271
|
useCurrencySymbol?: boolean;
|
package/utils/app-fetch.ts
CHANGED
|
@@ -1,18 +1,26 @@
|
|
|
1
1
|
import Settings from 'settings';
|
|
2
|
-
import { ServerVariables } from './server-variables';
|
|
3
2
|
import logger from '../utils/log';
|
|
4
3
|
import { headers, cookies } from 'next/headers';
|
|
4
|
+
import { ServerVariables } from './server-variables';
|
|
5
5
|
|
|
6
6
|
export enum FetchResponseType {
|
|
7
7
|
JSON = 'json',
|
|
8
8
|
TEXT = 'text'
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
const appFetch = async <T>(
|
|
12
|
-
url
|
|
13
|
-
|
|
11
|
+
const appFetch = async <T>({
|
|
12
|
+
url,
|
|
13
|
+
locale,
|
|
14
|
+
currency,
|
|
15
|
+
init = {},
|
|
14
16
|
responseType = FetchResponseType.JSON
|
|
15
|
-
|
|
17
|
+
}: {
|
|
18
|
+
url: RequestInfo;
|
|
19
|
+
locale: string;
|
|
20
|
+
currency: string;
|
|
21
|
+
init?: RequestInit;
|
|
22
|
+
responseType?: FetchResponseType;
|
|
23
|
+
}): Promise<T> => {
|
|
16
24
|
let response: T;
|
|
17
25
|
let status: number;
|
|
18
26
|
let ip = '';
|
|
@@ -24,7 +32,7 @@ const appFetch = async <T>(
|
|
|
24
32
|
|
|
25
33
|
const commerceUrl = Settings.commerceUrl;
|
|
26
34
|
const currentLocale = Settings.localization.locales.find(
|
|
27
|
-
(
|
|
35
|
+
(l) => l.value === locale
|
|
28
36
|
);
|
|
29
37
|
|
|
30
38
|
if (commerceUrl === 'default') {
|
|
@@ -36,14 +44,15 @@ const appFetch = async <T>(
|
|
|
36
44
|
|
|
37
45
|
init.headers = {
|
|
38
46
|
...(init.headers ?? {}),
|
|
47
|
+
...(ServerVariables.globalHeaders ?? {}),
|
|
39
48
|
'Accept-Language': currentLocale.apiValue,
|
|
40
|
-
'x-currency':
|
|
49
|
+
'x-currency': currency,
|
|
41
50
|
'x-forwarded-for': ip,
|
|
42
51
|
cookie: nextCookies.toString()
|
|
43
52
|
};
|
|
44
53
|
|
|
45
54
|
init.next = {
|
|
46
|
-
revalidate: 60
|
|
55
|
+
revalidate: Settings.usePrettyUrlRoute ? 0 : 60
|
|
47
56
|
};
|
|
48
57
|
|
|
49
58
|
logger.debug(`FETCH START ${url}`, { requestURL, init, ip });
|
package/utils/index.ts
CHANGED
|
@@ -63,18 +63,33 @@ export function getTranslateFn(path: string, translations: any) {
|
|
|
63
63
|
|
|
64
64
|
export function buildClientRequestUrl(
|
|
65
65
|
path: string,
|
|
66
|
-
options?: ClientRequestOptions
|
|
66
|
+
options?: ClientRequestOptions & { cache?: boolean }
|
|
67
67
|
) {
|
|
68
68
|
let url = `/api/client${path}`;
|
|
69
69
|
|
|
70
|
+
let hasQuery = url.includes('?');
|
|
71
|
+
|
|
70
72
|
if (options) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
const { cache, ...otherOptions } = options;
|
|
74
|
+
|
|
75
|
+
if (Object.keys(otherOptions).length > 0) {
|
|
76
|
+
if (hasQuery) {
|
|
77
|
+
url += '&';
|
|
78
|
+
} else {
|
|
79
|
+
url += '?';
|
|
80
|
+
hasQuery = true;
|
|
81
|
+
}
|
|
82
|
+
url += `options=${encodeURIComponent(JSON.stringify(otherOptions))}`;
|
|
75
83
|
}
|
|
76
84
|
|
|
77
|
-
|
|
85
|
+
if (cache === false) {
|
|
86
|
+
if (hasQuery) {
|
|
87
|
+
url += '&';
|
|
88
|
+
} else {
|
|
89
|
+
url += '?';
|
|
90
|
+
}
|
|
91
|
+
url += `t=${Date.now()}`;
|
|
92
|
+
}
|
|
78
93
|
}
|
|
79
94
|
|
|
80
95
|
return url;
|
|
@@ -102,6 +117,12 @@ export function buildCDNUrl(url: string, config?: CDNOptions) {
|
|
|
102
117
|
''
|
|
103
118
|
);
|
|
104
119
|
|
|
120
|
+
const noOptionFileExtension = url?.split('.').pop()?.toLowerCase() ?? '';
|
|
121
|
+
|
|
122
|
+
if (noOptionFileExtension === 'svg' || noOptionFileExtension === 'gif') {
|
|
123
|
+
return url;
|
|
124
|
+
}
|
|
125
|
+
|
|
105
126
|
let options = '';
|
|
106
127
|
|
|
107
128
|
if (config) {
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
const iframeURLChange = (iframe, callback) => {
|
|
2
|
+
iframe.addEventListener('load', () => {
|
|
3
|
+
setTimeout(() => {
|
|
4
|
+
if (iframe?.contentWindow?.location) {
|
|
5
|
+
callback(iframe.contentWindow.location);
|
|
6
|
+
}
|
|
7
|
+
}, 0);
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const removeIframe = async () => {
|
|
12
|
+
const iframeSelector = document.querySelector(
|
|
13
|
+
'.checkout-payment-redirection-iframe-wrapper'
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
const redirectionPaymentWrapper = document.querySelector(
|
|
17
|
+
'.checkout-redirection-payment-wrapper'
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
const form = redirectionPaymentWrapper.querySelector('form') as HTMLElement;
|
|
21
|
+
|
|
22
|
+
if (!iframeSelector) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
iframeSelector.remove();
|
|
27
|
+
|
|
28
|
+
if (form) {
|
|
29
|
+
form.style.display = 'block';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
location.reload();
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const showRedirectionIframe = (redirectUrl: string) => {
|
|
36
|
+
const iframeWrapper = document.createElement('div');
|
|
37
|
+
const iframe = document.createElement('iframe');
|
|
38
|
+
const closeButton = document.createElement('div');
|
|
39
|
+
const redirectionPaymentWrapper = document.querySelector(
|
|
40
|
+
'.checkout-redirection-payment-wrapper'
|
|
41
|
+
);
|
|
42
|
+
const form = redirectionPaymentWrapper.querySelector('form') as HTMLElement;
|
|
43
|
+
|
|
44
|
+
iframeWrapper.className = 'checkout-payment-redirection-iframe-wrapper';
|
|
45
|
+
closeButton.className = 'close-button';
|
|
46
|
+
|
|
47
|
+
iframe.setAttribute('src', redirectUrl);
|
|
48
|
+
closeButton.innerHTML = '✕';
|
|
49
|
+
closeButton.addEventListener('click', removeIframe);
|
|
50
|
+
|
|
51
|
+
iframeWrapper.append(iframe, closeButton);
|
|
52
|
+
|
|
53
|
+
if (form) {
|
|
54
|
+
form.style.display = 'none';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
redirectionPaymentWrapper.appendChild(iframeWrapper);
|
|
58
|
+
|
|
59
|
+
iframeURLChange(iframe, (location) => {
|
|
60
|
+
if (location.origin !== window.location.origin) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const searchParams = new URLSearchParams(location.search);
|
|
65
|
+
const isOrderCompleted = location.href.includes('/orders/completed');
|
|
66
|
+
|
|
67
|
+
if (isOrderCompleted) {
|
|
68
|
+
(window.parent as any)?.postMessage?.(
|
|
69
|
+
JSON.stringify({
|
|
70
|
+
url: location.pathname
|
|
71
|
+
})
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (
|
|
76
|
+
searchParams.has('success') ||
|
|
77
|
+
isOrderCompleted ||
|
|
78
|
+
location.href.includes('/orders/checkout')
|
|
79
|
+
) {
|
|
80
|
+
setTimeout(() => {
|
|
81
|
+
removeIframe();
|
|
82
|
+
}, 0);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
};
|
|
@@ -8,7 +8,6 @@ import logger from './log';
|
|
|
8
8
|
|
|
9
9
|
export const translations: Translations = {};
|
|
10
10
|
|
|
11
|
-
// TODO: Read translations from cache
|
|
12
11
|
export async function getTranslations(locale_: string) {
|
|
13
12
|
try {
|
|
14
13
|
const locale = settings.localization.locales.find(
|
|
@@ -55,3 +54,14 @@ export async function getTranslations(locale_: string) {
|
|
|
55
54
|
export function t(path: string) {
|
|
56
55
|
return getTranslateFn(path, translations);
|
|
57
56
|
}
|
|
57
|
+
|
|
58
|
+
export async function t_(path: string, locale?: string) {
|
|
59
|
+
let translations_ = translations;
|
|
60
|
+
|
|
61
|
+
if (settings.useOptimizedTranslations && locale) {
|
|
62
|
+
const { getTranslations } = require('translations');
|
|
63
|
+
translations_ = await getTranslations(locale);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return getTranslateFn(path, translations_);
|
|
67
|
+
}
|
package/with-pz-config.js
CHANGED
|
@@ -8,6 +8,7 @@ const defaultConfig = {
|
|
|
8
8
|
transpilePackages: ['@akinon/next', ...pzPlugins.map((p) => `@akinon/${p}`)],
|
|
9
9
|
skipTrailingSlashRedirect: true,
|
|
10
10
|
poweredByHeader: false,
|
|
11
|
+
cacheMaxMemorySize: 0,
|
|
11
12
|
env: {
|
|
12
13
|
NEXT_PUBLIC_SENTRY_DSN: process.env.SENTRY_DSN
|
|
13
14
|
},
|
|
@@ -56,7 +57,8 @@ const defaultConfig = {
|
|
|
56
57
|
...pzPlugins.reduce((acc, plugin) => {
|
|
57
58
|
acc[`@akinon/${plugin}`] = false;
|
|
58
59
|
return acc;
|
|
59
|
-
}, {})
|
|
60
|
+
}, {}),
|
|
61
|
+
translations: false
|
|
60
62
|
};
|
|
61
63
|
return config;
|
|
62
64
|
},
|
|
@@ -65,7 +67,12 @@ const defaultConfig = {
|
|
|
65
67
|
}
|
|
66
68
|
};
|
|
67
69
|
|
|
68
|
-
const withPzConfig = (
|
|
70
|
+
const withPzConfig = (
|
|
71
|
+
myNextConfig = {},
|
|
72
|
+
options = {
|
|
73
|
+
useCacheHandler: false
|
|
74
|
+
}
|
|
75
|
+
) => {
|
|
69
76
|
let extendedConfig = deepMerge({}, defaultConfig, myNextConfig);
|
|
70
77
|
|
|
71
78
|
const originalPzHeadersFunction = defaultConfig.headers;
|
|
@@ -91,6 +98,10 @@ const withPzConfig = (myNextConfig = {}) => {
|
|
|
91
98
|
return [...pzRewrites, ...myRewrites];
|
|
92
99
|
};
|
|
93
100
|
|
|
101
|
+
if (options.useCacheHandler && process.env.CACHE_HOST) {
|
|
102
|
+
extendedConfig.cacheHandler = require.resolve('./lib/cache-handler.mjs');
|
|
103
|
+
}
|
|
104
|
+
|
|
94
105
|
return extendedConfig;
|
|
95
106
|
};
|
|
96
107
|
|