@akinon/next 1.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/.prettierrc +13 -0
- package/api/auth.ts +217 -0
- package/api/cache.ts +44 -0
- package/api/client.ts +157 -0
- package/api/logout.ts +42 -0
- package/assets/styles/index.scss +24 -0
- package/bin/pz-install-plugins.js +33 -0
- package/components/client-root.tsx +69 -0
- package/components/image.tsx +133 -0
- package/components/mobile-app-toggler.tsx +15 -0
- package/components/oauth-login.tsx +24 -0
- package/components/plugin-module.tsx +78 -0
- package/components/pz-providers.tsx +24 -0
- package/components/pz-root.tsx +21 -0
- package/components/redirect-three-d/content/index.tsx +64 -0
- package/components/redirect-three-d/index.tsx +17 -0
- package/components/selected-payment-option-view.tsx +66 -0
- package/components/trans.tsx +39 -0
- package/data/client/account.ts +188 -0
- package/data/client/address.ts +107 -0
- package/data/client/api.ts +42 -0
- package/data/client/basket.ts +85 -0
- package/data/client/checkout.ts +477 -0
- package/data/client/misc.ts +101 -0
- package/data/client/product.ts +90 -0
- package/data/client/user.ts +83 -0
- package/data/client/wishlist.ts +79 -0
- package/data/server/category.ts +121 -0
- package/data/server/flatpage.ts +21 -0
- package/data/server/index.ts +8 -0
- package/data/server/list.ts +56 -0
- package/data/server/menu.ts +35 -0
- package/data/server/product.ts +86 -0
- package/data/server/seo.ts +48 -0
- package/data/server/special-page.ts +42 -0
- package/data/server/widget.ts +27 -0
- package/data/urls.ts +184 -0
- package/hocs/client/index.ts +1 -0
- package/hocs/client/with-segment-defaults.tsx +26 -0
- package/hocs/server/index.ts +1 -0
- package/hocs/server/with-segment-defaults.tsx +83 -0
- package/hooks/index.ts +8 -0
- package/hooks/use-captcha.tsx +76 -0
- package/hooks/use-common-product-attributes.ts +36 -0
- package/hooks/use-debounce.ts +20 -0
- package/hooks/use-localization.ts +63 -0
- package/hooks/use-media-query.ts +36 -0
- package/hooks/use-on-click-outside.tsx +28 -0
- package/hooks/use-router.ts +45 -0
- package/hooks/use-translation.ts +14 -0
- package/lib/cache.ts +185 -0
- package/localization/index.ts +5 -0
- package/localization/provider.tsx +58 -0
- package/middlewares/currency.ts +55 -0
- package/middlewares/default.ts +224 -0
- package/middlewares/index.ts +29 -0
- package/middlewares/locale.ts +61 -0
- package/middlewares/oauth-login.ts +78 -0
- package/middlewares/pretty-url.ts +94 -0
- package/middlewares/redirection-payment.ts +117 -0
- package/middlewares/three-d-redirection.ts +122 -0
- package/middlewares/url-redirection.ts +61 -0
- package/package.json +20 -0
- package/plugins.js +7 -0
- package/redux/hooks.ts +7 -0
- package/redux/middlewares/checkout.ts +231 -0
- package/redux/middlewares/index.ts +50 -0
- package/redux/reducers/checkout.ts +164 -0
- package/redux/reducers/config.ts +28 -0
- package/redux/reducers/header.ts +59 -0
- package/redux/reducers/index.ts +15 -0
- package/redux/reducers/root.ts +61 -0
- package/tailwind/rtl.js +137 -0
- package/types/commerce/account.ts +68 -0
- package/types/commerce/address.ts +94 -0
- package/types/commerce/basket.ts +43 -0
- package/types/commerce/category.ts +114 -0
- package/types/commerce/checkout.ts +132 -0
- package/types/commerce/flatpage.ts +7 -0
- package/types/commerce/index.ts +10 -0
- package/types/commerce/misc.ts +127 -0
- package/types/commerce/order.ts +108 -0
- package/types/commerce/product.ts +110 -0
- package/types/commerce/widget.ts +28 -0
- package/types/gtm.ts +16 -0
- package/types/index.ts +207 -0
- package/types/next-auth.d.ts +24 -0
- package/utils/app-fetch.ts +62 -0
- package/utils/generate-commerce-search-params.ts +22 -0
- package/utils/get-currency.ts +29 -0
- package/utils/image-loader.ts +31 -0
- package/utils/index.ts +132 -0
- package/utils/localization.ts +29 -0
- package/utils/log.ts +138 -0
- package/utils/menu-generator.ts +27 -0
- package/utils/mobile-3d-iframe.ts +58 -0
- package/utils/server-translation.ts +57 -0
- package/utils/server-variables.ts +9 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import getSymbolFromCurrency from 'currency-symbol-map';
|
|
4
|
+
|
|
5
|
+
type GetCurrencyType = {
|
|
6
|
+
currencyCode: string;
|
|
7
|
+
useCurrencySymbol?: boolean;
|
|
8
|
+
useCurrencyAfterPrice?: boolean;
|
|
9
|
+
useCurrencySpace?: boolean;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const getCurrency = (args: GetCurrencyType) => {
|
|
13
|
+
const {
|
|
14
|
+
currencyCode,
|
|
15
|
+
useCurrencySymbol = true,
|
|
16
|
+
useCurrencyAfterPrice = true,
|
|
17
|
+
useCurrencySpace = true
|
|
18
|
+
} = args;
|
|
19
|
+
|
|
20
|
+
const currencySpace = useCurrencySpace ? ' ' : '';
|
|
21
|
+
const currency = useCurrencySymbol
|
|
22
|
+
? `${getSymbolFromCurrency(currencyCode)}`
|
|
23
|
+
: currencyCode;
|
|
24
|
+
const currencyAfterPrice = useCurrencyAfterPrice
|
|
25
|
+
? `${currencySpace}${currency}`
|
|
26
|
+
: `${currency}${currencySpace}`;
|
|
27
|
+
|
|
28
|
+
return currencyAfterPrice;
|
|
29
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { buildCDNUrl } from '.';
|
|
2
|
+
import { CDNOptions } from '../types';
|
|
3
|
+
|
|
4
|
+
export interface ImageLoaderParams {
|
|
5
|
+
src: string;
|
|
6
|
+
width: number;
|
|
7
|
+
quality: number;
|
|
8
|
+
crop: CDNOptions['crop'];
|
|
9
|
+
fill?: boolean;
|
|
10
|
+
aspectRatio?: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const ImageLoader = ({
|
|
14
|
+
src,
|
|
15
|
+
width,
|
|
16
|
+
quality,
|
|
17
|
+
crop,
|
|
18
|
+
fill,
|
|
19
|
+
aspectRatio
|
|
20
|
+
}: ImageLoaderParams) => {
|
|
21
|
+
if (src.match(/akinoncdn|akinoncloud|b-cdn\.net/)) {
|
|
22
|
+
return buildCDNUrl(src, {
|
|
23
|
+
width,
|
|
24
|
+
height: fill ? parseInt(String(Number(width) / aspectRatio)) : undefined,
|
|
25
|
+
quality,
|
|
26
|
+
crop
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return src;
|
|
31
|
+
};
|
package/utils/index.ts
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import settings from 'settings';
|
|
2
|
+
import { LocaleUrlStrategy } from '../localization';
|
|
3
|
+
import { CDNOptions, ClientRequestOptions } from '../types';
|
|
4
|
+
|
|
5
|
+
export * from './get-currency';
|
|
6
|
+
export * from './menu-generator';
|
|
7
|
+
export * from './generate-commerce-search-params';
|
|
8
|
+
|
|
9
|
+
export function getCookie(name: string) {
|
|
10
|
+
if (typeof document === 'undefined') {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const value = `; ${document.cookie}`;
|
|
15
|
+
const parts = value.split(`; ${name}=`);
|
|
16
|
+
|
|
17
|
+
if (parts.length === 2) {
|
|
18
|
+
return parts.pop().split(';').shift();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function setCookie(name: string, val: string) {
|
|
23
|
+
const date = new Date();
|
|
24
|
+
const value = val;
|
|
25
|
+
|
|
26
|
+
date.setTime(date.getTime() + 7 * 24 * 60 * 60 * 1000);
|
|
27
|
+
|
|
28
|
+
document.cookie =
|
|
29
|
+
name + '=' + value + '; expires=' + date.toUTCString() + '; path=/';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function removeCookie(name: string) {
|
|
33
|
+
const date = 'Thu, 01 Jan 1970 00:00:00 UTC';
|
|
34
|
+
|
|
35
|
+
document.cookie = name + '=' + '; expires=' + date + '; path=/';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function setCurrency(currency: string) {
|
|
39
|
+
setCookie('pz-currency', currency);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function getTranslateFn(path: string, translations: any) {
|
|
43
|
+
const get = (parts_: Array<string>, tObj: any) => {
|
|
44
|
+
const currentPart = parts_[0];
|
|
45
|
+
|
|
46
|
+
if (parts_.length === 1) {
|
|
47
|
+
return tObj?.[currentPart] ?? path;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return get(parts_.slice(1), tObj?.[currentPart]);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
return get(path.split('.'), translations);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function buildClientRequestUrl(
|
|
57
|
+
path: string,
|
|
58
|
+
options?: ClientRequestOptions
|
|
59
|
+
) {
|
|
60
|
+
let url = `/api/client${path}`;
|
|
61
|
+
|
|
62
|
+
if (options) {
|
|
63
|
+
if (url.includes('?')) {
|
|
64
|
+
url += '&';
|
|
65
|
+
} else {
|
|
66
|
+
url += '?';
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
url += `options=${encodeURIComponent(JSON.stringify(options))}`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return url;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function capitalize(str: string) {
|
|
76
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function asTypedObject<E>() {
|
|
80
|
+
return function <T>(et: { [K in keyof T]: E }) {
|
|
81
|
+
return et;
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function splitUrlByFileExtension(path: string) {
|
|
86
|
+
const lastDotIndex = path.lastIndexOf('.');
|
|
87
|
+
return [path.slice(0, lastDotIndex), path.slice(lastDotIndex)] as const;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function buildCDNUrl(url: string, config?: CDNOptions) {
|
|
91
|
+
const [root, fileExtension] = splitUrlByFileExtension(url);
|
|
92
|
+
|
|
93
|
+
let options = '';
|
|
94
|
+
|
|
95
|
+
if (config) {
|
|
96
|
+
const { width, height, quality, crop, upscale } = config;
|
|
97
|
+
|
|
98
|
+
if (width && height) {
|
|
99
|
+
options += `_size${width}x${height}`;
|
|
100
|
+
} else if (height) {
|
|
101
|
+
options += `_sizex${height}`;
|
|
102
|
+
} else if (width) {
|
|
103
|
+
options += `_size${width}`;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (quality) {
|
|
107
|
+
options += `_quality${quality}`;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (crop) {
|
|
111
|
+
options += `_crop${capitalize(crop)}`;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (upscale) {
|
|
115
|
+
options += `_upscale${upscale.toString()}`;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return `${root}${options}${fileExtension}`;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export const urlLocaleMatcherRegex = new RegExp(
|
|
123
|
+
`^/(${settings.localization.locales
|
|
124
|
+
.filter((l) =>
|
|
125
|
+
settings.localization.localeUrlStrategy !==
|
|
126
|
+
LocaleUrlStrategy.ShowAllLocales
|
|
127
|
+
? l.value !== settings.localization.defaultLocaleValue
|
|
128
|
+
: l
|
|
129
|
+
)
|
|
130
|
+
.map((l) => l.value)
|
|
131
|
+
.join('|')})`
|
|
132
|
+
);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import settings from 'settings';
|
|
2
|
+
import { LocaleUrlStrategy } from '../localization';
|
|
3
|
+
|
|
4
|
+
export const getUrlPathWithLocale = (
|
|
5
|
+
pathname: string,
|
|
6
|
+
currentLocale?: string
|
|
7
|
+
) => {
|
|
8
|
+
const { defaultLocaleValue, localeUrlStrategy } = settings.localization;
|
|
9
|
+
|
|
10
|
+
if (!currentLocale) {
|
|
11
|
+
currentLocale = defaultLocaleValue;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (localeUrlStrategy === LocaleUrlStrategy.HideAllLocales) {
|
|
15
|
+
return pathname;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (localeUrlStrategy === LocaleUrlStrategy.HideDefaultLocale) {
|
|
19
|
+
if (currentLocale === defaultLocaleValue) {
|
|
20
|
+
return pathname;
|
|
21
|
+
} else {
|
|
22
|
+
return `/${currentLocale}${pathname}`;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (localeUrlStrategy === LocaleUrlStrategy.ShowAllLocales) {
|
|
27
|
+
return `/${currentLocale}${pathname}`;
|
|
28
|
+
}
|
|
29
|
+
};
|
package/utils/log.ts
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
enum LogLevel {
|
|
2
|
+
TRACE = 'trace',
|
|
3
|
+
DEBUG = 'debug',
|
|
4
|
+
INFO = 'info',
|
|
5
|
+
WARN = 'warn',
|
|
6
|
+
ERROR = 'error',
|
|
7
|
+
FATAL = 'fatal',
|
|
8
|
+
SILENT = 'silent'
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const LOG_LEVELS = new Map([
|
|
12
|
+
['trace', 10],
|
|
13
|
+
['debug', 20],
|
|
14
|
+
['info', 30],
|
|
15
|
+
['warn', 40],
|
|
16
|
+
['error', 50],
|
|
17
|
+
['fatal', 60],
|
|
18
|
+
['silent', 1000]
|
|
19
|
+
]);
|
|
20
|
+
|
|
21
|
+
interface LoggerFn {
|
|
22
|
+
(message: string, payload?: any): void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface Message {
|
|
26
|
+
message: string;
|
|
27
|
+
level?: LogLevel;
|
|
28
|
+
payload?: any;
|
|
29
|
+
details?: any;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const LOG_COLORS = new Map([
|
|
33
|
+
[LogLevel.TRACE, '\x1b[45m'],
|
|
34
|
+
[LogLevel.DEBUG, '\x1b[44m'],
|
|
35
|
+
[LogLevel.INFO, '\x1b[42m'],
|
|
36
|
+
[LogLevel.WARN, '\x1b[43m'],
|
|
37
|
+
[LogLevel.ERROR, '\x1b[41m'],
|
|
38
|
+
[LogLevel.FATAL, '\x1b[41m']
|
|
39
|
+
]);
|
|
40
|
+
|
|
41
|
+
let LOG_LEVEL = LOG_LEVELS.get(LogLevel.INFO);
|
|
42
|
+
|
|
43
|
+
if (process.env.NODE_ENV === 'development') {
|
|
44
|
+
LOG_LEVEL = LOG_LEVELS.get(process.env.LOG_LEVEL_DEV ?? LogLevel.INFO);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (process.env.NODE_ENV === 'production') {
|
|
48
|
+
LOG_LEVEL = LOG_LEVELS.get(process.env.LOG_LEVEL ?? LogLevel.INFO);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const writeMsg = ({ level, message, payload }: Message) => {
|
|
52
|
+
if (LOG_LEVELS.get(level) < LOG_LEVEL) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
let log: Message | string = { message };
|
|
57
|
+
|
|
58
|
+
if (payload) {
|
|
59
|
+
log.details = payload;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (process.env.NODE_ENV === 'production') {
|
|
63
|
+
log.level = level;
|
|
64
|
+
log = `PZ LOG ----${level.toUpperCase()}---- ${JSON.stringify(log)}`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (process.env.NODE_ENV === 'development') {
|
|
68
|
+
console.log(
|
|
69
|
+
'\n\n' + LOG_COLORS.get(level),
|
|
70
|
+
`▼ PZ ${level.toUpperCase()}${
|
|
71
|
+
message.length < 250 ? ` ━━ ${message}` : ''
|
|
72
|
+
} \x1b[0m\n`,
|
|
73
|
+
log,
|
|
74
|
+
'\n\n'
|
|
75
|
+
);
|
|
76
|
+
} else {
|
|
77
|
+
console.log(log);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const info: LoggerFn = (message, payload) => {
|
|
82
|
+
writeMsg({
|
|
83
|
+
level: LogLevel.INFO,
|
|
84
|
+
message,
|
|
85
|
+
payload
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const error: LoggerFn = (message, payload) => {
|
|
90
|
+
writeMsg({
|
|
91
|
+
level: LogLevel.ERROR,
|
|
92
|
+
message,
|
|
93
|
+
payload
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const warn: LoggerFn = (message, payload) => {
|
|
98
|
+
writeMsg({
|
|
99
|
+
level: LogLevel.WARN,
|
|
100
|
+
message,
|
|
101
|
+
payload
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const debug: LoggerFn = (message, payload) => {
|
|
106
|
+
writeMsg({
|
|
107
|
+
level: LogLevel.DEBUG,
|
|
108
|
+
message,
|
|
109
|
+
payload
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const trace: LoggerFn = (message, payload) => {
|
|
114
|
+
writeMsg({
|
|
115
|
+
level: LogLevel.TRACE,
|
|
116
|
+
message,
|
|
117
|
+
payload
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const fatal: LoggerFn = (message, payload) => {
|
|
122
|
+
writeMsg({
|
|
123
|
+
level: LogLevel.FATAL,
|
|
124
|
+
message,
|
|
125
|
+
payload
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const logger = {
|
|
130
|
+
trace,
|
|
131
|
+
debug,
|
|
132
|
+
info,
|
|
133
|
+
warn,
|
|
134
|
+
error,
|
|
135
|
+
fatal
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export default logger;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { MenuItemType } from '../types';
|
|
2
|
+
import logger from './log';
|
|
3
|
+
|
|
4
|
+
export const menuGenerator = (arr: MenuItemType[]) => {
|
|
5
|
+
const tree: MenuItemType[] = [];
|
|
6
|
+
|
|
7
|
+
try {
|
|
8
|
+
const data: { [key: string]: MenuItemType } = {};
|
|
9
|
+
|
|
10
|
+
arr.forEach((item) => {
|
|
11
|
+
const newData = { ...item, children: [] };
|
|
12
|
+
data[item.pk] = newData;
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
Object.values(data).forEach((item) => {
|
|
16
|
+
if (item.parent) {
|
|
17
|
+
data[item.parent.pk].children.push(item);
|
|
18
|
+
} else {
|
|
19
|
+
tree.push(item);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
} catch (error) {
|
|
23
|
+
logger.error(error, 'menuGenerator');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return tree;
|
|
27
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
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-iframe-wrapper'
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
if (!iframeSelector) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
iframeSelector.remove();
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const showMobile3dIframe = (redirectUrl: string) => {
|
|
24
|
+
const iframeWrapper = document.createElement('div');
|
|
25
|
+
const iframe = document.createElement('iframe');
|
|
26
|
+
const closeButton = document.createElement('div');
|
|
27
|
+
|
|
28
|
+
iframeWrapper.className = 'checkout-payment-iframe-wrapper';
|
|
29
|
+
closeButton.className = 'close-button';
|
|
30
|
+
iframe.setAttribute('src', redirectUrl);
|
|
31
|
+
closeButton.innerHTML = '✕';
|
|
32
|
+
closeButton.addEventListener('click', removeIframe);
|
|
33
|
+
|
|
34
|
+
iframeWrapper.append(iframe, closeButton);
|
|
35
|
+
document.body.appendChild(iframeWrapper);
|
|
36
|
+
|
|
37
|
+
iframeURLChange(iframe, (location) => {
|
|
38
|
+
if (location.origin !== window.location.origin) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const searchParams = new URLSearchParams(location.search);
|
|
43
|
+
const isOrderCompleted = location.href.includes('/orders/completed');
|
|
44
|
+
const data = {
|
|
45
|
+
url: location.pathname
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
if (searchParams.has('success') || isOrderCompleted) {
|
|
49
|
+
removeIframe();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (isOrderCompleted) {
|
|
53
|
+
(window.parent as any)?.ReactNativeWebView?.postMessage?.(
|
|
54
|
+
JSON.stringify(data)
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import { getTranslateFn } from '../utils';
|
|
5
|
+
import { Translations } from '../types';
|
|
6
|
+
import settings from 'settings';
|
|
7
|
+
import logger from './log';
|
|
8
|
+
|
|
9
|
+
export const translations: Translations = {};
|
|
10
|
+
|
|
11
|
+
// TODO: Read translations from cache
|
|
12
|
+
export async function getTranslations(locale_: string) {
|
|
13
|
+
try {
|
|
14
|
+
const locale = settings.localization.locales.find(
|
|
15
|
+
(locale) => locale.value === locale_
|
|
16
|
+
);
|
|
17
|
+
const localeDirPath = path.resolve(
|
|
18
|
+
`public/locales/${locale.localePath ?? locale.value}`
|
|
19
|
+
);
|
|
20
|
+
const fileNames = fs.readdirSync(localeDirPath);
|
|
21
|
+
|
|
22
|
+
const fileImports = fileNames.map(
|
|
23
|
+
(fileName) =>
|
|
24
|
+
new Promise<string>((resolve, reject) => {
|
|
25
|
+
fs.readFile(
|
|
26
|
+
path.join(localeDirPath, `/${fileName}`),
|
|
27
|
+
'utf-8',
|
|
28
|
+
(error, data) => {
|
|
29
|
+
if (error) {
|
|
30
|
+
console.error(error);
|
|
31
|
+
reject(error.message);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
resolve(data);
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
})
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
let index = 0;
|
|
41
|
+
|
|
42
|
+
for await (const fileImport of fileImports) {
|
|
43
|
+
translations[
|
|
44
|
+
fileNames[index].substring(0, fileNames[index].lastIndexOf('.'))
|
|
45
|
+
] = JSON.parse(fileImport);
|
|
46
|
+
index++;
|
|
47
|
+
}
|
|
48
|
+
} catch (error) {
|
|
49
|
+
logger.error('Failed to read translations', error);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return translations;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function t(path: string) {
|
|
56
|
+
return getTranslateFn(path, translations);
|
|
57
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import settings from 'settings';
|
|
2
|
+
|
|
3
|
+
const { locales, defaultLocaleValue, defaultCurrencyCode } =
|
|
4
|
+
settings.localization;
|
|
5
|
+
|
|
6
|
+
export const ServerVariables = {
|
|
7
|
+
locale: locales.find((l) => l.value === defaultLocaleValue)?.value ?? '',
|
|
8
|
+
currency: defaultCurrencyCode
|
|
9
|
+
};
|