@akinon/next 2.0.0-beta.2 → 2.0.0-beta.21

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 (133) hide show
  1. package/.eslintrc.js +12 -0
  2. package/CHANGELOG.md +400 -7
  3. package/__tests__/next-config.test.ts +83 -0
  4. package/__tests__/tsconfig.json +23 -0
  5. package/api/auth.ts +381 -60
  6. package/api/barcode-search.ts +59 -0
  7. package/api/cache.ts +41 -5
  8. package/api/client.ts +21 -4
  9. package/api/form.ts +85 -0
  10. package/api/image-proxy.ts +75 -0
  11. package/api/product-categories.ts +53 -0
  12. package/api/similar-product-list.ts +63 -0
  13. package/api/similar-products.ts +111 -0
  14. package/api/virtual-try-on.ts +382 -0
  15. package/assets/styles/index.scss +84 -0
  16. package/babel.config.js +6 -0
  17. package/bin/pz-generate-routes.js +115 -0
  18. package/bin/pz-install-plugins.js +1 -1
  19. package/bin/pz-prebuild.js +1 -0
  20. package/bin/pz-predev.js +1 -0
  21. package/bin/pz-run-tests.js +99 -0
  22. package/bin/run-prebuild-tests.js +46 -0
  23. package/components/accordion.tsx +20 -5
  24. package/components/button.tsx +51 -36
  25. package/components/client-root.tsx +138 -2
  26. package/components/file-input.tsx +65 -3
  27. package/components/index.ts +1 -0
  28. package/components/input.tsx +1 -1
  29. package/components/link.tsx +46 -16
  30. package/components/logger-popup.tsx +213 -0
  31. package/components/modal.tsx +32 -16
  32. package/components/plugin-module.tsx +62 -3
  33. package/components/price.tsx +2 -2
  34. package/components/select.tsx +1 -1
  35. package/components/selected-payment-option-view.tsx +21 -0
  36. package/data/client/account.ts +17 -2
  37. package/data/client/api.ts +2 -0
  38. package/data/client/basket.ts +66 -5
  39. package/data/client/checkout.ts +391 -99
  40. package/data/client/misc.ts +38 -2
  41. package/data/client/product.ts +19 -2
  42. package/data/client/user.ts +16 -8
  43. package/data/server/category.ts +11 -9
  44. package/data/server/flatpage.ts +11 -4
  45. package/data/server/form.ts +15 -4
  46. package/data/server/landingpage.ts +11 -4
  47. package/data/server/list.ts +5 -4
  48. package/data/server/menu.ts +11 -3
  49. package/data/server/product.ts +111 -55
  50. package/data/server/seo.ts +14 -4
  51. package/data/server/special-page.ts +5 -4
  52. package/data/server/widget.ts +90 -5
  53. package/data/urls.ts +16 -5
  54. package/hocs/client/with-segment-defaults.tsx +2 -2
  55. package/hocs/server/with-segment-defaults.tsx +65 -20
  56. package/hooks/index.ts +4 -0
  57. package/hooks/use-localization.ts +24 -10
  58. package/hooks/use-logger-context.tsx +114 -0
  59. package/hooks/use-logger.ts +92 -0
  60. package/hooks/use-loyalty-availability.ts +21 -0
  61. package/hooks/use-payment-options.ts +2 -1
  62. package/hooks/use-pz-params.ts +37 -0
  63. package/hooks/use-router.ts +51 -14
  64. package/hooks/use-sentry-uncaught-errors.ts +24 -0
  65. package/instrumentation/index.ts +10 -1
  66. package/instrumentation/node.ts +2 -20
  67. package/jest.config.js +25 -0
  68. package/lib/cache-handler.mjs +534 -16
  69. package/lib/cache.ts +272 -37
  70. package/localization/index.ts +2 -1
  71. package/localization/provider.tsx +2 -5
  72. package/middlewares/bfcache-headers.ts +18 -0
  73. package/middlewares/checkout-provider.ts +1 -1
  74. package/middlewares/complete-gpay.ts +32 -26
  75. package/middlewares/complete-masterpass.ts +33 -26
  76. package/middlewares/complete-wallet.ts +182 -0
  77. package/middlewares/default.ts +360 -215
  78. package/middlewares/index.ts +10 -2
  79. package/middlewares/locale.ts +34 -11
  80. package/middlewares/masterpass-rest-callback.ts +230 -0
  81. package/middlewares/oauth-login.ts +200 -57
  82. package/middlewares/pretty-url.ts +21 -8
  83. package/middlewares/redirection-payment.ts +32 -26
  84. package/middlewares/saved-card-redirection.ts +33 -26
  85. package/middlewares/three-d-redirection.ts +32 -26
  86. package/middlewares/url-redirection.ts +11 -1
  87. package/middlewares/wallet-complete-redirection.ts +206 -0
  88. package/package.json +24 -9
  89. package/plugins.d.ts +19 -4
  90. package/plugins.js +10 -1
  91. package/redux/actions.ts +47 -0
  92. package/redux/middlewares/checkout.ts +63 -138
  93. package/redux/middlewares/index.ts +14 -10
  94. package/redux/middlewares/pre-order/address.ts +7 -2
  95. package/redux/middlewares/pre-order/attribute-based-shipping-option.ts +7 -1
  96. package/redux/middlewares/pre-order/data-source-shipping-option.ts +7 -1
  97. package/redux/middlewares/pre-order/delivery-option.ts +7 -1
  98. package/redux/middlewares/pre-order/index.ts +16 -10
  99. package/redux/middlewares/pre-order/installment-option.ts +8 -1
  100. package/redux/middlewares/pre-order/payment-option-reset.ts +37 -0
  101. package/redux/middlewares/pre-order/payment-option.ts +7 -1
  102. package/redux/middlewares/pre-order/pre-order-validation.ts +8 -3
  103. package/redux/middlewares/pre-order/redirection.ts +8 -2
  104. package/redux/middlewares/pre-order/set-pre-order.ts +6 -2
  105. package/redux/middlewares/pre-order/shipping-option.ts +7 -1
  106. package/redux/middlewares/pre-order/shipping-step.ts +5 -1
  107. package/redux/reducers/checkout.ts +23 -3
  108. package/redux/reducers/index.ts +11 -3
  109. package/redux/reducers/root.ts +7 -2
  110. package/redux/reducers/widget.ts +80 -0
  111. package/sentry/index.ts +69 -13
  112. package/tailwind/content.js +16 -0
  113. package/types/commerce/account.ts +5 -1
  114. package/types/commerce/checkout.ts +35 -1
  115. package/types/commerce/widget.ts +33 -0
  116. package/types/index.ts +114 -6
  117. package/types/next-auth.d.ts +2 -2
  118. package/types/widget.ts +80 -0
  119. package/utils/app-fetch.ts +7 -2
  120. package/utils/generate-commerce-search-params.ts +3 -2
  121. package/utils/get-checkout-path.ts +3 -0
  122. package/utils/get-root-hostname.ts +28 -0
  123. package/utils/index.ts +64 -10
  124. package/utils/localization.ts +4 -0
  125. package/utils/mobile-3d-iframe.ts +8 -2
  126. package/utils/override-middleware.ts +7 -12
  127. package/utils/pz-segments.ts +92 -0
  128. package/utils/redirect-ignore.ts +35 -0
  129. package/utils/redirect.ts +9 -3
  130. package/utils/redirection-iframe.ts +8 -2
  131. package/utils/widget-styles.ts +107 -0
  132. package/views/error-page.tsx +93 -0
  133. package/with-pz-config.js +21 -7
@@ -0,0 +1,37 @@
1
+ 'use client';
2
+
3
+ import { useParams } from 'next/navigation';
4
+ import settings from 'settings';
5
+ import {
6
+ decodePzValue,
7
+ getPzSegmentsConfig,
8
+ getBuiltInSegments,
9
+ isLegacyMode
10
+ } from '../utils/pz-segments';
11
+
12
+ export function usePzParams(): {
13
+ locale: string;
14
+ currency: string;
15
+ [key: string]: string;
16
+ } {
17
+ const params = useParams() as Record<string, string>;
18
+
19
+ if (isLegacyMode(settings)) {
20
+ return {
21
+ locale:
22
+ params.locale ?? settings.localization.defaultLocaleValue,
23
+ currency:
24
+ params.currency ?? settings.localization.defaultCurrencyCode
25
+ };
26
+ }
27
+
28
+ const pzValue = params.pz ?? '';
29
+ const config = getPzSegmentsConfig(settings);
30
+ const parsed = decodePzValue(pzValue, config);
31
+ const builtIn = getBuiltInSegments(parsed, settings);
32
+
33
+ return {
34
+ ...parsed,
35
+ ...builtIn
36
+ };
37
+ }
@@ -5,6 +5,24 @@ import { urlLocaleMatcherRegex } from '../utils';
5
5
  import { useLocalization } from './use-localization';
6
6
  import { LocaleUrlStrategy } from '../localization';
7
7
 
8
+ const isNavigableHref = (href: string) => {
9
+ if (!href || typeof href !== 'string') return false;
10
+
11
+ const trimmedHref = href.trim();
12
+ if (!trimmedHref) return false;
13
+ if (trimmedHref === '#') return true;
14
+ if (trimmedHref.startsWith('mailto:') || trimmedHref.startsWith('tel:')) {
15
+ return true;
16
+ }
17
+
18
+ try {
19
+ new URL(trimmedHref, 'http://localhost');
20
+ return true;
21
+ } catch {
22
+ return false;
23
+ }
24
+ };
25
+
8
26
  export const useRouter = () => {
9
27
  const { locale, locales, localeUrlStrategy, defaultLocaleValue } =
10
28
  useLocalization();
@@ -16,24 +34,43 @@ export const useRouter = () => {
16
34
  href: string,
17
35
  options?
18
36
  ) => {
19
- if (href.startsWith('http')) {
20
- return fn(href, options);
37
+ if (!isNavigableHref(href)) {
38
+ return fn('#', options);
21
39
  }
22
40
 
23
- const url = new URL(href, window.location.origin);
24
- const pathnameWithoutLocale = url.pathname.replace(
25
- urlLocaleMatcherRegex,
26
- ''
27
- );
41
+ const trimmedHref = href.trim();
28
42
 
29
- url.pathname = `${
30
- locale === defaultLocale?.value &&
31
- localeUrlStrategy === LocaleUrlStrategy.HideDefaultLocale
32
- ? ''
33
- : `/${locale}`
34
- }${pathnameWithoutLocale}`;
43
+ if (
44
+ trimmedHref.startsWith('http') ||
45
+ trimmedHref.startsWith('//') ||
46
+ trimmedHref.startsWith('mailto:') ||
47
+ trimmedHref.startsWith('tel:') ||
48
+ trimmedHref.startsWith('#')
49
+ ) {
50
+ return fn(trimmedHref, options);
51
+ }
52
+
53
+ try {
54
+ const url = new URL(trimmedHref, window.location.origin);
55
+ const pathnameWithoutLocale = url.pathname.replace(
56
+ urlLocaleMatcherRegex,
57
+ ''
58
+ );
35
59
 
36
- return fn(url.href, options);
60
+ url.pathname = `${
61
+ localeUrlStrategy === LocaleUrlStrategy.Subdomain ||
62
+ (locale === defaultLocale?.value &&
63
+ [LocaleUrlStrategy.HideDefaultLocale].includes(
64
+ localeUrlStrategy as LocaleUrlStrategy
65
+ ))
66
+ ? ''
67
+ : `/${locale}`
68
+ }${pathnameWithoutLocale}`;
69
+
70
+ return fn(url.href, options);
71
+ } catch {
72
+ return fn('#', options);
73
+ }
37
74
  };
38
75
 
39
76
  return {
@@ -0,0 +1,24 @@
1
+ import { useEffect } from 'react';
2
+ import * as Sentry from '@sentry/nextjs';
3
+ import { ClientLogType } from '@akinon/next/sentry';
4
+
5
+ export const useSentryUncaughtErrors = (error: Error & { digest?: string }) => {
6
+ useEffect(() => {
7
+ Sentry.withScope(function (scope) {
8
+ scope.setLevel('fatal');
9
+ scope.setTags({
10
+ APP_TYPE: 'ProjectZeroNext',
11
+ TYPE: 'Client',
12
+ LOG_TYPE: ClientLogType.UNCAUGHT_ERROR_PAGE
13
+ });
14
+ scope.setExtra('error', error);
15
+
16
+ const error_ = new Error('FATAL: Uncaught client error');
17
+ error_.name = 'UNCAUGHT_ERROR_PAGE';
18
+
19
+ Sentry.captureException(error_, {
20
+ fingerprint: ['UNCAUGHT_ERROR_PAGE', error.digest]
21
+ });
22
+ });
23
+ }, [error]);
24
+ };
@@ -1,5 +1,14 @@
1
+ import { initSentry } from '../sentry';
2
+ import * as Sentry from '@sentry/nextjs';
3
+
1
4
  export async function register() {
2
5
  if (process.env.NEXT_RUNTIME === 'nodejs') {
3
- await import('./node');
6
+ initSentry('Server');
7
+ }
8
+
9
+ if (process.env.NEXT_RUNTIME === 'edge') {
10
+ initSentry('Edge');
4
11
  }
5
12
  }
13
+
14
+ export const onRequestError = Sentry.captureRequestError;
@@ -1,20 +1,2 @@
1
- import { NodeSDK } from '@opentelemetry/sdk-node';
2
- import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
3
- import { Resource } from '@opentelemetry/resources';
4
- import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
5
- import { SimpleSpanProcessor } from '@opentelemetry/sdk-trace-node';
6
-
7
- const sdk = new NodeSDK({
8
- resource: new Resource({
9
- [SemanticResourceAttributes.SERVICE_NAME]: 'pz-next-app'
10
- }),
11
- spanProcessor: new SimpleSpanProcessor(
12
- new OTLPTraceExporter({
13
- url: `${
14
- process.env.PZ_DASHBOARD_URL ?? 'http://localhost:3005'
15
- }/api/traces`
16
- })
17
- )
18
- });
19
-
20
- sdk.start();
1
+ // OpenTelemetry tracing is handled by Sentry.
2
+ // Custom NodeSDK setup removed due to version incompatibility with Sentry 10's OpenTelemetry v2.x requirements.
package/jest.config.js ADDED
@@ -0,0 +1,25 @@
1
+ const path = require('path');
2
+ const findBaseDir = require('./utils/find-base-dir');
3
+
4
+ const baseDir = findBaseDir();
5
+
6
+ module.exports = {
7
+ preset: 'ts-jest',
8
+ testEnvironment: 'node',
9
+ rootDir: path.resolve(__dirname),
10
+ testMatch: ['**/*.test.ts'],
11
+ testPathIgnorePatterns: [],
12
+ roots: [path.resolve(__dirname)],
13
+ transformIgnorePatterns: [],
14
+ moduleNameMapper: {
15
+ '^settings$': path.resolve(baseDir, 'src/settings.js')
16
+ },
17
+ transform: {
18
+ '^.+\\.(tsx?|jsx?|mjs?)$': [
19
+ 'ts-jest',
20
+ {
21
+ tsconfig: path.resolve(__dirname, '__tests__/tsconfig.json')
22
+ }
23
+ ]
24
+ }
25
+ };