@akinon/next 1.42.0-rc.8 → 1.42.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.
Files changed (47) hide show
  1. package/CHANGELOG.md +2 -53
  2. package/api/client.ts +9 -18
  3. package/assets/styles/index.scss +26 -50
  4. package/components/input.tsx +7 -20
  5. package/components/link.tsx +13 -17
  6. package/components/pagination.tsx +2 -1
  7. package/components/plugin-module.tsx +8 -3
  8. package/components/price.tsx +4 -10
  9. package/components/selected-payment-option-view.tsx +38 -26
  10. package/data/client/account.ts +9 -10
  11. package/data/client/api.ts +2 -1
  12. package/data/client/basket.ts +42 -0
  13. package/data/client/checkout.ts +3 -26
  14. package/data/server/category.ts +2 -2
  15. package/data/server/list.ts +2 -2
  16. package/data/server/product.ts +13 -15
  17. package/data/server/special-page.ts +2 -2
  18. package/data/urls.ts +5 -3
  19. package/hocs/server/with-segment-defaults.tsx +2 -2
  20. package/hooks/index.ts +1 -2
  21. package/hooks/use-payment-options.ts +1 -2
  22. package/lib/cache.ts +6 -18
  23. package/middlewares/default.ts +0 -9
  24. package/middlewares/pretty-url.ts +0 -4
  25. package/package.json +4 -5
  26. package/plugins.d.ts +0 -1
  27. package/redux/middlewares/checkout.ts +9 -40
  28. package/redux/reducers/checkout.ts +3 -9
  29. package/redux/reducers/config.ts +0 -2
  30. package/types/commerce/account.ts +0 -1
  31. package/types/commerce/address.ts +1 -1
  32. package/types/commerce/basket.ts +1 -0
  33. package/types/commerce/checkout.ts +0 -18
  34. package/types/commerce/misc.ts +0 -2
  35. package/types/commerce/order.ts +0 -7
  36. package/types/index.ts +2 -28
  37. package/utils/app-fetch.ts +1 -1
  38. package/utils/generate-commerce-search-params.ts +2 -6
  39. package/utils/index.ts +6 -27
  40. package/utils/server-translation.ts +1 -5
  41. package/with-pz-config.js +1 -11
  42. package/assets/styles/index.css +0 -49
  43. package/assets/styles/index.css.map +0 -1
  44. package/hooks/use-message-listener.ts +0 -24
  45. package/lib/cache-handler.mjs +0 -33
  46. package/routes/pretty-url.tsx +0 -194
  47. package/utils/redirection-iframe.ts +0 -85
@@ -5,10 +5,10 @@ import { getTranslateFn } from '../utils';
5
5
  import { Translations } from '../types';
6
6
  import settings from 'settings';
7
7
  import logger from './log';
8
- import { unstable_cache } from 'next/cache';
9
8
 
10
9
  export const translations: Translations = {};
11
10
 
11
+ // TODO: Read translations from cache
12
12
  export async function getTranslations(locale_: string) {
13
13
  try {
14
14
  const locale = settings.localization.locales.find(
@@ -52,10 +52,6 @@ export async function getTranslations(locale_: string) {
52
52
  return translations;
53
53
  }
54
54
 
55
- export const getCachedTranslations = unstable_cache(async (locale: string) =>
56
- getTranslations(locale)
57
- );
58
-
59
55
  export function t(path: string) {
60
56
  return getTranslateFn(path, translations);
61
57
  }
package/with-pz-config.js CHANGED
@@ -8,7 +8,6 @@ const defaultConfig = {
8
8
  transpilePackages: ['@akinon/next', ...pzPlugins.map((p) => `@akinon/${p}`)],
9
9
  skipTrailingSlashRedirect: true,
10
10
  poweredByHeader: false,
11
- cacheMaxMemorySize: 0,
12
11
  env: {
13
12
  NEXT_PUBLIC_SENTRY_DSN: process.env.SENTRY_DSN
14
13
  },
@@ -66,12 +65,7 @@ const defaultConfig = {
66
65
  }
67
66
  };
68
67
 
69
- const withPzConfig = (
70
- myNextConfig = {},
71
- options = {
72
- useCacheHandler: false
73
- }
74
- ) => {
68
+ const withPzConfig = (myNextConfig = {}) => {
75
69
  let extendedConfig = deepMerge({}, defaultConfig, myNextConfig);
76
70
 
77
71
  const originalPzHeadersFunction = defaultConfig.headers;
@@ -97,10 +91,6 @@ const withPzConfig = (
97
91
  return [...pzRewrites, ...myRewrites];
98
92
  };
99
93
 
100
- if (options.useCacheHandler) {
101
- extendedConfig.cacheHandler = require.resolve('./lib/cache-handler.mjs');
102
- }
103
-
104
94
  return extendedConfig;
105
95
  };
106
96
 
@@ -1,49 +0,0 @@
1
- .checkout-payment-iframe-wrapper {
2
- position: fixed;
3
- top: 0;
4
- left: 0;
5
- width: 100%;
6
- height: 100%;
7
- border: none;
8
- z-index: 1000;
9
- background-color: white;
10
- }
11
- .checkout-payment-iframe-wrapper iframe {
12
- width: 100%;
13
- height: 100%;
14
- border: none;
15
- background-color: white;
16
- }
17
- .checkout-payment-iframe-wrapper .close-button {
18
- position: fixed;
19
- top: 16px;
20
- right: 16px;
21
- width: 32px;
22
- height: 32px;
23
- display: flex;
24
- align-items: center;
25
- justify-content: center;
26
- z-index: 1001;
27
- }
28
-
29
- .checkout-payment-redirection-iframe-wrapper {
30
- width: 100%;
31
- position: relative;
32
- }
33
- .checkout-payment-redirection-iframe-wrapper iframe {
34
- width: 100%;
35
- height: 100%;
36
- border: none;
37
- background-color: white;
38
- }
39
- .checkout-payment-redirection-iframe-wrapper .close-button {
40
- position: absolute;
41
- top: 16px;
42
- right: 16px;
43
- width: 32px;
44
- height: 32px;
45
- display: flex;
46
- align-items: center;
47
- justify-content: center;
48
- z-index: 1001;
49
- }/*# sourceMappingURL=index.css.map */
@@ -1 +0,0 @@
1
- {"version":3,"sources":["index.scss","index.css"],"names":[],"mappings":"AAAA;EACE,eAAA;EACA,MAAA;EACA,OAAA;EACA,WAAA;EACA,YAAA;EACA,YAAA;EACA,aAAA;EACA,uBAAA;ACCF;ADCE;EACE,WAAA;EACA,YAAA;EACA,YAAA;EACA,uBAAA;ACCJ;ADEE;EACE,eAAA;EACA,SAAA;EACA,WAAA;EACA,WAAA;EACA,YAAA;EACA,aAAA;EACA,mBAAA;EACA,uBAAA;EACA,aAAA;ACAJ;;ADIA;EACE,WAAA;EACA,kBAAA;ACDF;ADGE;EACE,WAAA;EACA,YAAA;EACA,YAAA;EACA,uBAAA;ACDJ;ADIE;EACE,kBAAA;EACA,SAAA;EACA,WAAA;EACA,WAAA;EACA,YAAA;EACA,aAAA;EACA,mBAAA;EACA,uBAAA;EACA,aAAA;ACFJ","file":"index.css"}
@@ -1,24 +0,0 @@
1
- import { useEffect } from 'react';
2
-
3
- export const useMessageListener = () => {
4
- useEffect(() => {
5
- const handleMessage = (event: MessageEvent) => {
6
- if (event.origin !== window.location.origin) {
7
- return;
8
- }
9
-
10
- if (event.data && typeof event.data === 'string') {
11
- const messageData = JSON.parse(event.data);
12
- if (messageData?.url) {
13
- window.location.href = messageData.url;
14
- }
15
- }
16
- };
17
-
18
- window.addEventListener('message', handleMessage);
19
-
20
- return () => {
21
- window.removeEventListener('message', handleMessage);
22
- };
23
- }, []);
24
- };
@@ -1,33 +0,0 @@
1
- import { CacheHandler } from '@neshca/cache-handler';
2
- import createLruHandler from '@neshca/cache-handler/local-lru';
3
- import createRedisHandler from '@neshca/cache-handler/redis-stack';
4
- import { createClient } from 'redis';
5
-
6
- CacheHandler.onCreation(async () => {
7
- const redisUrl = `redis://${process.env.CACHE_HOST}:${
8
- process.env.CACHE_PORT
9
- }/${process.env.CACHE_BUCKET ?? '0'}`;
10
-
11
- const client = createClient({
12
- url: redisUrl
13
- });
14
-
15
- client.on('error', (error) => {
16
- console.error('Redis client error', { redisUrl, error });
17
- });
18
-
19
- await client.connect();
20
-
21
- const redisHandler = await createRedisHandler({
22
- client,
23
- timeoutMs: 5000
24
- });
25
-
26
- const localHandler = createLruHandler();
27
-
28
- return {
29
- handlers: [redisHandler, localHandler]
30
- };
31
- });
32
-
33
- export default CacheHandler;
@@ -1,194 +0,0 @@
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 = Object.fromEntries(
67
- new URLSearchParams(
68
- decodeURIComponent(
69
- prettyurl
70
- .find((x) => x.startsWith('searchparams'))
71
- ?.replace('searchparams%7C', '')
72
- ) ?? {}
73
- ).entries()
74
- );
75
-
76
- const prettyUrlResult = await resolvePrettyUrlHandler(pageSlug, null)();
77
-
78
- if (!prettyUrlResult.matched) {
79
- return notFound();
80
- }
81
-
82
- const commonProps = {
83
- params: {
84
- ...params,
85
- pk: prettyUrlResult.pk
86
- },
87
- searchParams
88
- };
89
-
90
- try {
91
- if (prettyUrlResult.path.startsWith('/product/')) {
92
- await import('@product/[pk]/page').then(async (module) => {
93
- result = await module['generateMetadata']?.(commonProps);
94
- });
95
- }
96
-
97
- if (prettyUrlResult.path.startsWith('/group-product/')) {
98
- await import('@group-product/[pk]/page').then(async (module) => {
99
- result = await module['generateMetadata']?.(commonProps);
100
- });
101
- }
102
-
103
- if (prettyUrlResult.path.startsWith('/category/')) {
104
- await import('@category/[pk]/page').then(async (module) => {
105
- result = await module['generateMetadata']?.(commonProps);
106
- });
107
- }
108
-
109
- if (prettyUrlResult.path.startsWith('/special-page/')) {
110
- await import('@special-page/[pk]/page').then(async (module) => {
111
- result = await module['generateMetadata']?.(commonProps);
112
- });
113
- }
114
-
115
- if (prettyUrlResult.path.startsWith('/flat-page/')) {
116
- await import('@flat-page/[pk]/page').then(async (module) => {
117
- result = await module['generateMetadata']?.(commonProps);
118
- });
119
- }
120
- // eslint-disable-next-line no-empty
121
- } catch (error) {}
122
-
123
- return result;
124
- }
125
-
126
- export const dynamic = 'force-static';
127
- export const revalidate = 300;
128
-
129
- export default async function Page({ params }) {
130
- const { prettyurl } = params;
131
- const pageSlug = prettyurl
132
- .filter((x) => !x.startsWith('searchparams'))
133
- .join('/');
134
-
135
- const urlSearchParams = new URLSearchParams(
136
- decodeURIComponent(
137
- prettyurl
138
- .find((x) => x.startsWith('searchparams'))
139
- ?.replace('searchparams%7C', '')
140
- ) ?? {}
141
- );
142
-
143
- const searchParams = {};
144
-
145
- for (const [key, value] of urlSearchParams.entries() as unknown as Array<
146
- [string, string]
147
- >) {
148
- if (!searchParams[key]) {
149
- searchParams[key] = [];
150
- }
151
- searchParams[key].push(value);
152
- }
153
-
154
- const result = await resolvePrettyUrlHandler(pageSlug, null)();
155
-
156
- if (!result.matched) {
157
- return notFound();
158
- }
159
-
160
- const commonProps = {
161
- params: {
162
- ...params,
163
- pk: result.pk
164
- },
165
- searchParams
166
- };
167
-
168
- if (result.path.startsWith('/category/')) {
169
- const CategoryPage = (await import('@category/[pk]/page')).default;
170
- return <CategoryPage {...commonProps} />;
171
- }
172
-
173
- if (result.path.startsWith('/product/')) {
174
- const ProductPage = (await import('@product/[pk]/page')).default;
175
- return <ProductPage {...commonProps} />;
176
- }
177
-
178
- if (result.path.startsWith('/group-product/')) {
179
- const GroupProduct = (await import('@group-product/[pk]/page')).default;
180
- return <GroupProduct {...commonProps} />;
181
- }
182
-
183
- if (result.path.startsWith('/special-page/')) {
184
- const SpecialPage = (await import('@special-page/[pk]/page')).default;
185
- return <SpecialPage {...commonProps} />;
186
- }
187
-
188
- if (result.path.startsWith('/flat-page/')) {
189
- const FlatPage = (await import('@flat-page/[pk]/page')).default;
190
- return <FlatPage {...commonProps} />;
191
- }
192
-
193
- return null;
194
- }
@@ -1,85 +0,0 @@
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 = '&#x2715';
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
- };