@akinon/next 1.92.0-rc.9 → 1.92.0-snapshot-ZERO-3449-20250618101111

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 (42) hide show
  1. package/CHANGELOG.md +33 -1180
  2. package/api/similar-product-list.ts +63 -0
  3. package/api/similar-products.ts +109 -0
  4. package/components/accordion.tsx +5 -20
  5. package/components/file-input.tsx +3 -65
  6. package/components/input.tsx +0 -2
  7. package/components/link.tsx +12 -16
  8. package/components/modal.tsx +16 -32
  9. package/components/plugin-module.tsx +3 -13
  10. package/components/selected-payment-option-view.tsx +0 -11
  11. package/data/client/similar-products.ts +122 -0
  12. package/data/urls.ts +5 -1
  13. package/hocs/server/with-segment-defaults.tsx +2 -5
  14. package/hooks/index.ts +2 -0
  15. package/hooks/use-image-cropper.ts +160 -0
  16. package/hooks/use-similar-products.ts +720 -0
  17. package/instrumentation/node.ts +13 -15
  18. package/lib/cache.ts +0 -2
  19. package/middlewares/complete-gpay.ts +1 -2
  20. package/middlewares/complete-masterpass.ts +1 -2
  21. package/middlewares/default.ts +184 -196
  22. package/middlewares/index.ts +1 -3
  23. package/middlewares/redirection-payment.ts +1 -2
  24. package/middlewares/saved-card-redirection.ts +1 -2
  25. package/middlewares/three-d-redirection.ts +1 -2
  26. package/middlewares/url-redirection.ts +14 -8
  27. package/package.json +3 -3
  28. package/plugins.d.ts +0 -2
  29. package/plugins.js +1 -3
  30. package/redux/middlewares/checkout.ts +2 -15
  31. package/redux/reducers/checkout.ts +1 -9
  32. package/sentry/index.ts +17 -54
  33. package/types/commerce/order.ts +0 -1
  34. package/types/index.ts +73 -26
  35. package/utils/app-fetch.ts +2 -2
  36. package/utils/image-validation.ts +303 -0
  37. package/utils/redirect.ts +3 -5
  38. package/with-pz-config.js +5 -1
  39. package/data/server/basket.ts +0 -72
  40. package/hooks/use-loyalty-availability.ts +0 -21
  41. package/middlewares/wallet-complete-redirection.ts +0 -179
  42. package/utils/redirect-ignore.ts +0 -35
@@ -0,0 +1,160 @@
1
+ import { useState, useRef } from 'react';
2
+ import 'react-image-crop/dist/ReactCrop.css';
3
+
4
+ type CropType = {
5
+ unit: 'px' | '%';
6
+ x: number;
7
+ y: number;
8
+ width: number;
9
+ height: number;
10
+ };
11
+
12
+ export function useImageCropper(
13
+ setIsLoading: (loading: boolean) => void,
14
+ processImage: (base64: string) => void
15
+ ) {
16
+ const [isCropping, setIsCropping] = useState(false);
17
+ const [crop, setCrop] = useState<CropType>({
18
+ unit: 'px',
19
+ x: 0,
20
+ y: 0,
21
+ width: 100,
22
+ height: 100
23
+ });
24
+ const [completedCrop, setCompletedCrop] = useState<CropType | null>(null);
25
+
26
+ const imageRef = useRef<HTMLImageElement>(null);
27
+ const fileInputRef = useRef<HTMLInputElement>(null);
28
+
29
+ const handleCropComplete = (c) => {
30
+ setCompletedCrop(c);
31
+ };
32
+
33
+ const toggleCropMode = () => {
34
+ const newCroppingState = !isCropping;
35
+ setIsCropping(newCroppingState);
36
+
37
+ if (newCroppingState) {
38
+ if (completedCrop?.width && completedCrop?.height) {
39
+ setCrop(completedCrop);
40
+ } else {
41
+ const centeredCrop: CropType = {
42
+ unit: '%',
43
+ x: 25,
44
+ y: 25,
45
+ width: 50,
46
+ height: 50
47
+ };
48
+ setCrop(centeredCrop);
49
+ }
50
+ }
51
+ };
52
+
53
+ const processCompletedCrop = (crop) => {
54
+ if (!imageRef.current || !crop?.width || !crop?.height) {
55
+ setIsLoading(false);
56
+ return;
57
+ }
58
+
59
+ try {
60
+ const canvas = document.createElement('canvas');
61
+ const image = imageRef.current;
62
+
63
+ const scaleX = image.naturalWidth / image.width;
64
+ const scaleY = image.naturalHeight / image.height;
65
+
66
+ canvas.width = crop.width * scaleX;
67
+ canvas.height = crop.height * scaleY;
68
+
69
+ const ctx = canvas.getContext('2d');
70
+
71
+ if (!ctx) {
72
+ setIsLoading(false);
73
+ throw new Error('No 2d context');
74
+ }
75
+
76
+ try {
77
+ ctx.drawImage(
78
+ image,
79
+ crop.x * scaleX,
80
+ crop.y * scaleY,
81
+ crop.width * scaleX,
82
+ crop.height * scaleY,
83
+ 0,
84
+ 0,
85
+ crop.width * scaleX,
86
+ crop.height * scaleY
87
+ );
88
+
89
+ const base64Image = canvas.toDataURL('image/jpeg');
90
+ processImage(base64Image);
91
+ } catch (canvasError) {
92
+ const corsFixedImg = new window.Image();
93
+ corsFixedImg.crossOrigin = 'anonymous';
94
+
95
+ corsFixedImg.onload = () => {
96
+ try {
97
+ canvas.width = crop.width * scaleX;
98
+ canvas.height = crop.height * scaleY;
99
+
100
+ ctx.drawImage(
101
+ corsFixedImg,
102
+ crop.x * scaleX,
103
+ crop.y * scaleY,
104
+ crop.width * scaleX,
105
+ crop.height * scaleY,
106
+ 0,
107
+ 0,
108
+ crop.width * scaleX,
109
+ crop.height * scaleY
110
+ );
111
+
112
+ const base64Image = canvas.toDataURL('image/jpeg');
113
+ processImage(base64Image);
114
+ } catch (retryError) {
115
+ setIsLoading(false);
116
+ }
117
+ };
118
+
119
+ corsFixedImg.onerror = () => {
120
+ setIsLoading(false);
121
+ };
122
+
123
+ const cacheBuster = Date.now();
124
+ const imageUrl = image.src.includes('?')
125
+ ? `${image.src}&cors_fix=${cacheBuster}`
126
+ : `${image.src}?cors_fix=${cacheBuster}`;
127
+
128
+ corsFixedImg.src = imageUrl;
129
+ }
130
+ } catch (error) {
131
+ setIsLoading(false);
132
+ }
133
+ };
134
+
135
+ const resetCrop = () => {
136
+ setIsCropping(false);
137
+ setCompletedCrop(null);
138
+ setCrop({
139
+ unit: 'px',
140
+ x: 0,
141
+ y: 0,
142
+ width: 100,
143
+ height: 100
144
+ });
145
+ };
146
+
147
+ return {
148
+ isCropping,
149
+ crop,
150
+ setCrop,
151
+ completedCrop,
152
+ setCompletedCrop,
153
+ imageRef,
154
+ fileInputRef,
155
+ handleCropComplete,
156
+ toggleCropMode,
157
+ processCompletedCrop,
158
+ resetCrop
159
+ };
160
+ }