@akinon/next 1.48.0-rc.4 → 1.48.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 (65) hide show
  1. package/CHANGELOG.md +1 -444
  2. package/api/client.ts +17 -50
  3. package/assets/styles/index.scss +26 -50
  4. package/bin/pz-prebuild.js +0 -1
  5. package/bin/pz-predev.js +0 -1
  6. package/components/index.ts +0 -1
  7. package/components/input.tsx +7 -21
  8. package/components/link.tsx +13 -17
  9. package/components/pagination.tsx +2 -1
  10. package/components/price.tsx +4 -11
  11. package/components/pz-root.tsx +3 -15
  12. package/components/selected-payment-option-view.tsx +38 -26
  13. package/data/client/account.ts +9 -10
  14. package/data/client/address.ts +8 -32
  15. package/data/client/api.ts +2 -2
  16. package/data/client/b2b.ts +2 -35
  17. package/data/client/basket.ts +5 -6
  18. package/data/client/checkout.ts +4 -47
  19. package/data/client/user.ts +2 -3
  20. package/data/server/category.ts +19 -43
  21. package/data/server/flatpage.ts +7 -29
  22. package/data/server/form.ts +11 -29
  23. package/data/server/landingpage.ts +7 -26
  24. package/data/server/list.ts +6 -16
  25. package/data/server/menu.ts +2 -15
  26. package/data/server/product.ts +21 -46
  27. package/data/server/seo.ts +24 -17
  28. package/data/server/special-page.ts +5 -15
  29. package/data/server/widget.ts +7 -14
  30. package/data/urls.ts +2 -9
  31. package/hocs/server/with-segment-defaults.tsx +1 -4
  32. package/hooks/index.ts +1 -2
  33. package/hooks/use-pagination.ts +2 -2
  34. package/hooks/use-payment-options.ts +1 -2
  35. package/lib/cache.ts +6 -8
  36. package/middlewares/default.ts +8 -91
  37. package/middlewares/pretty-url.ts +1 -11
  38. package/middlewares/url-redirection.ts +0 -4
  39. package/package.json +4 -5
  40. package/plugins.d.ts +0 -1
  41. package/redux/middlewares/checkout.ts +11 -70
  42. package/redux/reducers/checkout.ts +5 -24
  43. package/redux/reducers/config.ts +0 -2
  44. package/types/commerce/account.ts +0 -1
  45. package/types/commerce/address.ts +1 -1
  46. package/types/commerce/b2b.ts +2 -12
  47. package/types/commerce/checkout.ts +0 -30
  48. package/types/commerce/misc.ts +0 -2
  49. package/types/commerce/order.ts +0 -12
  50. package/types/index.ts +3 -37
  51. package/utils/app-fetch.ts +10 -21
  52. package/utils/generate-commerce-search-params.ts +1 -3
  53. package/utils/index.ts +6 -27
  54. package/utils/menu-generator.ts +2 -2
  55. package/utils/server-translation.ts +1 -11
  56. package/utils/server-variables.ts +1 -2
  57. package/with-pz-config.js +2 -13
  58. package/assets/styles/index.css +0 -49
  59. package/assets/styles/index.css.map +0 -1
  60. package/bin/pz-generate-translations.js +0 -41
  61. package/components/file-input.tsx +0 -8
  62. package/hooks/use-message-listener.ts +0 -24
  63. package/lib/cache-handler.mjs +0 -33
  64. package/routes/pretty-url.tsx +0 -192
  65. package/utils/redirection-iframe.ts +0 -85
@@ -33,23 +33,6 @@ export interface ShippingOption {
33
33
  slug: string;
34
34
  }
35
35
 
36
- export interface DataSource {
37
- pk: number;
38
- name: string;
39
- data_source_shipping_options: DataSourceShippingOption[];
40
- }
41
-
42
- export interface DataSourceShippingOption {
43
- pk: number;
44
- shipping_amount: string;
45
- shipping_option_name: string;
46
- shipping_option_logo: string | null;
47
- data_source: {
48
- pk: number;
49
- title: string | null;
50
- };
51
- }
52
-
53
36
  export interface CheckoutAddressType {
54
37
  label: string;
55
38
  text: string;
@@ -95,8 +78,6 @@ export interface PreOrder {
95
78
  retail_store?: RetailStore;
96
79
  gift_box?: GiftBox;
97
80
  credit_payment_option?: CheckoutCreditPaymentOption;
98
- data_source_shipping_options: any;
99
- attribute_based_shipping_options?: AttributeBasedShippingOption[];
100
81
  }
101
82
 
102
83
  export interface GuestLoginFormParams {
@@ -136,7 +117,6 @@ export interface CheckoutContext {
136
117
  redirect_url?: string;
137
118
  context_data?: any;
138
119
  balance?: string;
139
- attribute_based_shipping_options?: AttributeBasedShippingOption[];
140
120
  [key: string]: any;
141
121
  };
142
122
  }
@@ -162,13 +142,3 @@ export interface BankAccount {
162
142
  pk: number;
163
143
  sort_order: number;
164
144
  }
165
-
166
- export interface AttributeBasedShippingOption {
167
- pk: number;
168
- shipping_amount: string | null;
169
- shipping_option_name: string | null;
170
- shipping_option_logo: string | null;
171
- attribute_value: string | null;
172
- attribute_key: string;
173
- [key: string]: any;
174
- }
@@ -2,8 +2,6 @@ import { District } from './address';
2
2
  export interface Config {
3
3
  user_phone_regex: string;
4
4
  user_phone_format: string;
5
- user_post_code_regex: string;
6
- user_post_code_format: string;
7
5
  country: {
8
6
  pk: number;
9
7
  name: string;
@@ -52,10 +52,6 @@ export interface OrderItem {
52
52
  quantity: string;
53
53
  unit_price: string;
54
54
  total_amount: string;
55
- attributes: {
56
- gift_note: string;
57
- [key: string]: any;
58
- };
59
55
  }
60
56
 
61
57
  export interface Order {
@@ -109,14 +105,6 @@ export interface Order {
109
105
  shipping_option: number;
110
106
  tracking_number: string;
111
107
  tracking_url: string;
112
- [key: string]: any;
113
- bank: {
114
- pk: number;
115
- name: string;
116
- slug: string;
117
- logo: string;
118
- [key: string]: any;
119
- };
120
108
  }
121
109
 
122
110
  export interface Quotations {
package/types/index.ts CHANGED
@@ -2,7 +2,7 @@ import { LocaleUrlStrategy } from '../localization';
2
2
  import { PzNextRequest } from '../middlewares';
3
3
  import { Control, FieldError } from 'react-hook-form';
4
4
  import { ReactNode } from 'react';
5
- import { UsePaginationType } from '../hooks/use-pagination';
5
+
6
6
  declare global {
7
7
  interface Window {
8
8
  // we did it like this because declare types needs to be identical, if not it will fail
@@ -68,17 +68,9 @@ 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;
78
71
  }
79
72
 
80
73
  export interface Settings {
81
- usePrettyUrlRoute?: boolean;
82
74
  commerceUrl: string;
83
75
  redis: {
84
76
  defaultExpirationTime: number;
@@ -191,9 +183,7 @@ export interface Settings {
191
183
  masterpassJsUrl?: string;
192
184
  };
193
185
  customNotFoundEnabled: boolean;
194
- useOptimizedTranslations?: boolean;
195
186
  plugins?: Record<string, Record<string, any>>;
196
- includedProxyHeaders?: string[];
197
187
  }
198
188
 
199
189
  export interface CacheOptions {
@@ -225,7 +215,7 @@ export type ImageOptions = CDNOptions & {
225
215
  export type Translations = { [key: string]: object };
226
216
 
227
217
  export interface PageProps<T = any> {
228
- params: T & { locale: string; currency: string };
218
+ params: T;
229
219
  searchParams: URLSearchParams;
230
220
  }
231
221
 
@@ -234,11 +224,7 @@ export interface LayoutProps<T = any> extends PageProps<T> {
234
224
  }
235
225
 
236
226
  export interface RootLayoutProps<
237
- T = {
238
- commerce: string;
239
- locale: string;
240
- currency: string;
241
- }
227
+ T = { commerce: string; locale: string; currency: string }
242
228
  > extends LayoutProps<T> {
243
229
  translations: Translations;
244
230
  locale: Locale & {
@@ -264,8 +250,6 @@ export interface ButtonProps
264
250
  appearance?: 'filled' | 'outlined' | 'ghost';
265
251
  }
266
252
 
267
- export type FileInputProps = React.HTMLProps<HTMLInputElement>;
268
-
269
253
  export interface PriceProps {
270
254
  currencyCode?: string;
271
255
  useCurrencySymbol?: boolean;
@@ -299,21 +283,3 @@ export interface AccordionProps {
299
283
  export interface PluginModuleComponentProps {
300
284
  settings?: Record<string, any>;
301
285
  }
302
-
303
- export interface PaginationProps {
304
- total: number | undefined;
305
- limit?: number | undefined;
306
- currentPage: number | undefined;
307
- numberOfPages?: number | undefined;
308
- containerClassName?: string;
309
- moreButtonClassName?: string;
310
- prevClassName?: string;
311
- nextClassName?: string;
312
- pageClassName?: string;
313
- threshold?: number | undefined;
314
- delta?: number | undefined;
315
- render?: (pagination: UsePaginationType) => ReactNode;
316
- type?: 'infinite' | 'list' | 'more';
317
- onPageChange?: (page: number) => void;
318
- direction?: 'next' | 'prev';
319
- }
@@ -1,38 +1,29 @@
1
1
  import Settings from 'settings';
2
- import logger from '../utils/log';
3
- import { headers, cookies } from 'next/headers';
4
2
  import { ServerVariables } from './server-variables';
3
+ import logger from '../utils/log';
4
+ import { headers } from 'next/headers';
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
- locale,
14
- currency,
15
- init = {},
11
+ const appFetch = async <T>(
12
+ url: RequestInfo,
13
+ init: RequestInit = {},
16
14
  responseType = FetchResponseType.JSON
17
- }: {
18
- url: RequestInfo;
19
- locale: string;
20
- currency: string;
21
- init?: RequestInit;
22
- responseType?: FetchResponseType;
23
- }): Promise<T> => {
15
+ ): Promise<T> => {
24
16
  let response: T;
25
17
  let status: number;
26
18
  let ip = '';
27
19
 
28
20
  try {
29
21
  const nextHeaders = headers();
30
- const nextCookies = cookies();
31
22
  ip = nextHeaders.get('x-forwarded-for') ?? '';
32
23
 
33
24
  const commerceUrl = Settings.commerceUrl;
34
25
  const currentLocale = Settings.localization.locales.find(
35
- (l) => l.value === locale
26
+ (locale) => locale.value === ServerVariables.locale
36
27
  );
37
28
 
38
29
  if (commerceUrl === 'default') {
@@ -44,15 +35,13 @@ const appFetch = async <T>({
44
35
 
45
36
  init.headers = {
46
37
  ...(init.headers ?? {}),
47
- ...(ServerVariables.globalHeaders ?? {}),
48
38
  'Accept-Language': currentLocale.apiValue,
49
- 'x-currency': currency,
50
- 'x-forwarded-for': ip,
51
- cookie: nextCookies.toString()
39
+ 'x-currency': ServerVariables.currency,
40
+ 'x-forwarded-for': ip
52
41
  };
53
42
 
54
43
  init.next = {
55
- revalidate: Settings.usePrettyUrlRoute ? 0 : 60
44
+ revalidate: 60
56
45
  };
57
46
 
58
47
  logger.debug(`FETCH START ${url}`, { requestURL, init, ip });
@@ -1,8 +1,6 @@
1
1
  import logger from './log';
2
2
 
3
- export const generateCommerceSearchParams = (
4
- searchParams?: URLSearchParams
5
- ) => {
3
+ export const generateCommerceSearchParams = (searchParams?: URLSearchParams) => {
6
4
  if (!searchParams) {
7
5
  return null;
8
6
  }
package/utils/index.ts CHANGED
@@ -63,33 +63,18 @@ export function getTranslateFn(path: string, translations: any) {
63
63
 
64
64
  export function buildClientRequestUrl(
65
65
  path: string,
66
- options?: ClientRequestOptions & { cache?: boolean }
66
+ options?: ClientRequestOptions
67
67
  ) {
68
68
  let url = `/api/client${path}`;
69
69
 
70
- let hasQuery = url.includes('?');
71
-
72
70
  if (options) {
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))}`;
71
+ if (url.includes('?')) {
72
+ url += '&';
73
+ } else {
74
+ url += '?';
83
75
  }
84
76
 
85
- if (cache === false) {
86
- if (hasQuery) {
87
- url += '&';
88
- } else {
89
- url += '?';
90
- }
91
- url += `t=${Date.now()}`;
92
- }
77
+ url += `options=${encodeURIComponent(JSON.stringify(options))}`;
93
78
  }
94
79
 
95
80
  return url;
@@ -117,12 +102,6 @@ export function buildCDNUrl(url: string, config?: CDNOptions) {
117
102
  ''
118
103
  );
119
104
 
120
- const noOptionFileExtension = url?.split('.').pop()?.toLowerCase() ?? '';
121
-
122
- if (noOptionFileExtension === 'svg' || noOptionFileExtension === 'gif') {
123
- return url;
124
- }
125
-
126
105
  let options = '';
127
106
 
128
107
  if (config) {
@@ -13,8 +13,8 @@ export const menuGenerator = (arr: MenuItemType[]) => {
13
13
  });
14
14
 
15
15
  Object.values(data).forEach((item) => {
16
- if (item.parent_pk) {
17
- data[item.parent_pk].children.push(item);
16
+ if (item.parent) {
17
+ data[item.parent.pk].children.push(item);
18
18
  } else {
19
19
  tree.push(item);
20
20
  }
@@ -8,6 +8,7 @@ import logger from './log';
8
8
 
9
9
  export const translations: Translations = {};
10
10
 
11
+ // TODO: Read translations from cache
11
12
  export async function getTranslations(locale_: string) {
12
13
  try {
13
14
  const locale = settings.localization.locales.find(
@@ -54,14 +55,3 @@ export async function getTranslations(locale_: string) {
54
55
  export function t(path: string) {
55
56
  return getTranslateFn(path, translations);
56
57
  }
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
- }
@@ -5,6 +5,5 @@ const { locales, defaultLocaleValue, defaultCurrencyCode } =
5
5
 
6
6
  export const ServerVariables = {
7
7
  locale: locales.find((l) => l.value === defaultLocaleValue)?.value ?? '',
8
- currency: defaultCurrencyCode,
9
- globalHeaders: {}
8
+ currency: defaultCurrencyCode
10
9
  };
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
  },
@@ -57,8 +56,7 @@ const defaultConfig = {
57
56
  ...pzPlugins.reduce((acc, plugin) => {
58
57
  acc[`@akinon/${plugin}`] = false;
59
58
  return acc;
60
- }, {}),
61
- translations: false
59
+ }, {})
62
60
  };
63
61
  return config;
64
62
  },
@@ -67,12 +65,7 @@ const defaultConfig = {
67
65
  }
68
66
  };
69
67
 
70
- const withPzConfig = (
71
- myNextConfig = {},
72
- options = {
73
- useCacheHandler: false
74
- }
75
- ) => {
68
+ const withPzConfig = (myNextConfig = {}) => {
76
69
  let extendedConfig = deepMerge({}, defaultConfig, myNextConfig);
77
70
 
78
71
  const originalPzHeadersFunction = defaultConfig.headers;
@@ -98,10 +91,6 @@ const withPzConfig = (
98
91
  return [...pzRewrites, ...myRewrites];
99
92
  };
100
93
 
101
- if (options.useCacheHandler && process.env.CACHE_HOST) {
102
- extendedConfig.cacheHandler = require.resolve('./lib/cache-handler.mjs');
103
- }
104
-
105
94
  return extendedConfig;
106
95
  };
107
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,41 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const fs = require('fs');
4
- const path = require('path');
5
- const localesPath = path.resolve(`public/locales/`);
6
-
7
- async function generateTranslationIndex(locale_) {
8
- let translations = {};
9
-
10
- try {
11
- const localeDirPath = path.resolve(`public/locales/${locale_}`);
12
- const fileNames = fs.readdirSync(localeDirPath);
13
-
14
- for await (const fileName of fileNames) {
15
- if (fileName === 'index.json') {
16
- continue;
17
- }
18
-
19
- const data = fs.readFileSync(
20
- path.join(localeDirPath, `/${fileName}`),
21
- 'utf-8'
22
- );
23
-
24
- translations[fileName.substring(0, fileName.lastIndexOf('.'))] =
25
- JSON.parse(data);
26
- }
27
-
28
- fs.writeFileSync(
29
- path.resolve(`public/locales/${locale_}/index.json`),
30
- JSON.stringify(translations)
31
- );
32
- } catch (error) {
33
- console.error(error);
34
- }
35
- }
36
-
37
- const localePaths = fs.readdirSync(localesPath);
38
-
39
- localePaths.forEach((localePath) => {
40
- generateTranslationIndex(localePath);
41
- });
@@ -1,8 +0,0 @@
1
- import { forwardRef } from 'react';
2
- import { FileInputProps } from '../types/index';
3
-
4
- export const FileInput = forwardRef<HTMLInputElement, FileInputProps>(
5
- function fileInput(props, ref) {
6
- return <input type="file" {...props} ref={ref} />;
7
- }
8
- );
@@ -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;