@akinon/next 1.101.0-snapshot-ZERO-3648-20250926111417 → 1.102.0-rc.77

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 (45) hide show
  1. package/CHANGELOG.md +1326 -48
  2. package/__tests__/next-config.test.ts +1 -10
  3. package/__tests__/redirect.test.ts +319 -0
  4. package/api/form.ts +84 -0
  5. package/api/image-proxy.ts +75 -0
  6. package/api/similar-product-list.ts +84 -0
  7. package/api/similar-products.ts +120 -0
  8. package/bin/pz-prebuild.js +1 -0
  9. package/components/accordion.tsx +20 -5
  10. package/components/file-input.tsx +65 -3
  11. package/components/input.tsx +2 -0
  12. package/components/link.tsx +16 -12
  13. package/components/modal.tsx +32 -16
  14. package/components/plugin-module.tsx +29 -6
  15. package/data/client/checkout.ts +4 -2
  16. package/data/server/basket.ts +72 -0
  17. package/data/server/category.ts +44 -24
  18. package/data/server/flatpage.ts +16 -12
  19. package/data/server/landingpage.ts +16 -12
  20. package/data/server/list.ts +23 -13
  21. package/data/server/product.ts +66 -39
  22. package/data/server/special-page.ts +16 -12
  23. package/data/urls.ts +6 -2
  24. package/hocs/server/with-segment-defaults.tsx +5 -2
  25. package/hooks/use-localization.ts +2 -3
  26. package/middlewares/complete-gpay.ts +2 -1
  27. package/middlewares/complete-masterpass.ts +2 -1
  28. package/middlewares/default.ts +50 -13
  29. package/middlewares/locale.ts +9 -1
  30. package/middlewares/redirection-payment.ts +2 -1
  31. package/middlewares/saved-card-redirection.ts +2 -1
  32. package/middlewares/three-d-redirection.ts +2 -2
  33. package/middlewares/url-redirection.ts +8 -14
  34. package/package.json +2 -2
  35. package/plugins.d.ts +8 -5
  36. package/plugins.js +2 -1
  37. package/redux/middlewares/checkout.ts +6 -2
  38. package/redux/middlewares/pre-order/payment-option-reset.ts +3 -1
  39. package/types/commerce/order.ts +1 -0
  40. package/types/index.ts +34 -1
  41. package/utils/app-fetch.ts +7 -2
  42. package/utils/redirect-ignore.ts +35 -0
  43. package/utils/redirect.ts +22 -3
  44. package/with-pz-config.js +1 -5
  45. package/api/virtual-try-on.ts +0 -209
package/utils/redirect.ts CHANGED
@@ -1,20 +1,39 @@
1
1
  import { redirect as nextRedirect, RedirectType } from 'next/navigation';
2
2
  import Settings from 'settings';
3
- import { headers } from 'next/headers';
4
- import { ServerVariables } from '@akinon/next/utils/server-variables';
3
+ import { headers, cookies } from 'next/headers';
5
4
  import { getUrlPathWithLocale } from '@akinon/next/utils/localization';
6
5
  import { urlLocaleMatcherRegex } from '@akinon/next/utils';
7
6
 
8
7
  export const redirect = (path: string, type?: RedirectType) => {
9
8
  const nextHeaders = headers();
9
+ const nextCookies = cookies();
10
10
  const pageUrl = new URL(
11
11
  nextHeaders.get('pz-url') ?? process.env.NEXT_PUBLIC_URL ?? ''
12
12
  );
13
13
 
14
+ let currentLocaleValue = Settings.localization.defaultLocaleValue;
15
+ const urlLocaleMatch = pageUrl.pathname.match(urlLocaleMatcherRegex);
16
+
17
+ if (urlLocaleMatch && urlLocaleMatch[0]) {
18
+ currentLocaleValue = urlLocaleMatch[0].replace('/', '');
19
+ } else {
20
+ const cookieLocale = nextCookies.get('pz-locale')?.value;
21
+ if (
22
+ cookieLocale &&
23
+ Settings.localization.locales.find((l) => l.value === cookieLocale)
24
+ ) {
25
+ currentLocaleValue = cookieLocale;
26
+ }
27
+ }
28
+
14
29
  const currentLocale = Settings.localization.locales.find(
15
- (locale) => locale.value === ServerVariables.locale
30
+ (locale) => locale.value === currentLocaleValue
16
31
  );
17
32
 
33
+ if (!currentLocale) {
34
+ currentLocaleValue = Settings.localization.defaultLocaleValue;
35
+ }
36
+
18
37
  const searchParams = new URLSearchParams(pageUrl.search);
19
38
 
20
39
  const callbackUrl =
package/with-pz-config.js CHANGED
@@ -16,12 +16,8 @@ const defaultConfig = {
16
16
  remotePatterns: [
17
17
  {
18
18
  protocol: 'https',
19
- hostname: '**.akinoncloud.com'
19
+ hostname: '**'
20
20
  },
21
- {
22
- protocol: 'https',
23
- hostname: '**.akinoncdn.com'
24
- }
25
21
  ]
26
22
  },
27
23
  modularizeImports: {
@@ -1,209 +0,0 @@
1
- import { NextRequest, NextResponse } from 'next/server';
2
-
3
- const VIRTUAL_TRY_ON_API_URL = process.env.NEXT_PUBLIC_VIRTUAL_TRY_ON_API_URL;
4
-
5
- export async function GET(request: NextRequest) {
6
- try {
7
- const { searchParams } = new URL(request.url);
8
- const endpoint = searchParams.get('endpoint');
9
-
10
- if (endpoint === 'limited-categories') {
11
- const externalUrl = `${VIRTUAL_TRY_ON_API_URL}/api/v1/limited-categories`;
12
-
13
- const response = await fetch(externalUrl, {
14
- method: 'GET',
15
- headers: {
16
- Accept: 'application/json',
17
- ...(request.headers.get('authorization') && {
18
- Authorization: request.headers.get('authorization')!
19
- })
20
- }
21
- });
22
-
23
- let responseData: any;
24
- const responseText = await response.text();
25
-
26
- try {
27
- responseData = responseText ? JSON.parse(responseText) : {};
28
- } catch (parseError) {
29
- responseData = { category_ids: [] };
30
- }
31
-
32
- if (!response.ok) {
33
- responseData = { category_ids: [] };
34
- }
35
-
36
- return NextResponse.json(responseData, {
37
- status: response.ok ? response.status : 200,
38
- headers: {
39
- 'Access-Control-Allow-Origin': '*',
40
- 'Access-Control-Allow-Methods': 'GET, POST, PUT, OPTIONS',
41
- 'Access-Control-Allow-Headers': 'Content-Type, Accept, Authorization'
42
- }
43
- });
44
- }
45
-
46
- return NextResponse.json(
47
- { error: 'Invalid endpoint for GET method' },
48
- { status: 400 }
49
- );
50
- } catch (error) {
51
- return NextResponse.json({ category_ids: [] }, { status: 200 });
52
- }
53
- }
54
-
55
- export async function POST(request: NextRequest) {
56
- try {
57
- const { searchParams } = new URL(request.url);
58
- const endpoint = searchParams.get('endpoint');
59
-
60
- const body = await request.json();
61
-
62
- let externalUrl: string;
63
- if (endpoint === 'feedback') {
64
- externalUrl = `${VIRTUAL_TRY_ON_API_URL}/api/v1/feedback`;
65
- } else {
66
- externalUrl = `${VIRTUAL_TRY_ON_API_URL}/api/v1/virtual-try-on`;
67
- }
68
-
69
- const httpMethod = endpoint === 'feedback' ? 'PUT' : 'POST';
70
-
71
- const response = await fetch(externalUrl, {
72
- method: httpMethod,
73
- headers: {
74
- 'Content-Type': 'application/json',
75
- ...(httpMethod === 'POST' && { Accept: 'application/json' }),
76
- ...(request.headers.get('authorization') && {
77
- Authorization: request.headers.get('authorization')!
78
- })
79
- },
80
- body: JSON.stringify(body)
81
- });
82
-
83
- let responseData: any;
84
- const responseText = await response.text();
85
-
86
- if (endpoint === 'feedback') {
87
- try {
88
- responseData = responseText ? JSON.parse(responseText) : {};
89
- } catch (parseError) {
90
- responseData = { error: 'Invalid JSON response from feedback API' };
91
- }
92
- } else {
93
- try {
94
- responseData = responseText ? JSON.parse(responseText) : {};
95
- } catch (parseError) {
96
- responseData = { error: 'Invalid JSON response' };
97
- }
98
- }
99
-
100
- if (!response.ok && responseData.error) {
101
- let userFriendlyMessage = responseData.error;
102
-
103
- if (
104
- typeof responseData.error === 'string' &&
105
- (responseData.error.includes('duplicate key value') ||
106
- responseData.error.includes('image_pk'))
107
- ) {
108
- userFriendlyMessage =
109
- 'This image has already been processed. Please try with a different image.';
110
- } else if (responseData.error.includes('bulk insert images')) {
111
- userFriendlyMessage =
112
- 'There was an issue processing your image. Please try again with a different image.';
113
- }
114
-
115
- return NextResponse.json(
116
- {
117
- ...responseData,
118
- message: userFriendlyMessage
119
- },
120
- {
121
- status: response.status,
122
- headers: {
123
- 'Access-Control-Allow-Origin': '*',
124
- 'Access-Control-Allow-Methods': 'POST, OPTIONS',
125
- 'Access-Control-Allow-Headers':
126
- 'Content-Type, Accept, Authorization'
127
- }
128
- }
129
- );
130
- }
131
-
132
- return NextResponse.json(responseData, {
133
- status: response.status,
134
- headers: {
135
- 'Access-Control-Allow-Origin': '*',
136
- 'Access-Control-Allow-Methods': 'POST, OPTIONS',
137
- 'Access-Control-Allow-Headers': 'Content-Type, Accept, Authorization'
138
- }
139
- });
140
- } catch (error) {
141
- return NextResponse.json(
142
- {
143
- status: 'error',
144
- message:
145
- 'Internal server error occurred during virtual try-on processing'
146
- },
147
- { status: 500 }
148
- );
149
- }
150
- }
151
-
152
- export async function PUT(request: NextRequest) {
153
- try {
154
- const { searchParams } = new URL(request.url);
155
- const endpoint = searchParams.get('endpoint');
156
-
157
- if (endpoint !== 'feedback') {
158
- return NextResponse.json(
159
- { error: 'PUT method only supports feedback endpoint' },
160
- { status: 400 }
161
- );
162
- }
163
-
164
- const body = await request.json();
165
-
166
- const externalUrl = `${VIRTUAL_TRY_ON_API_URL}/api/v1/feedback`;
167
-
168
- const response = await fetch(externalUrl, {
169
- method: 'PUT',
170
- headers: {
171
- 'Content-Type': 'application/json',
172
- ...(request.headers.get('authorization') && {
173
- Authorization: request.headers.get('authorization')!
174
- })
175
- },
176
- body: JSON.stringify(body)
177
- });
178
-
179
- const responseData = await response.json();
180
-
181
- return NextResponse.json(responseData, {
182
- status: response.status,
183
- headers: {
184
- 'Access-Control-Allow-Origin': '*',
185
- 'Access-Control-Allow-Methods': 'GET, POST, PUT, OPTIONS',
186
- 'Access-Control-Allow-Headers': 'Content-Type, Accept, Authorization'
187
- }
188
- });
189
- } catch (error) {
190
- return NextResponse.json(
191
- {
192
- status: 'error',
193
- message: 'Internal server error occurred during feedback submission'
194
- },
195
- { status: 500 }
196
- );
197
- }
198
- }
199
-
200
- export async function OPTIONS() {
201
- return new NextResponse(null, {
202
- status: 200,
203
- headers: {
204
- 'Access-Control-Allow-Origin': '*',
205
- 'Access-Control-Allow-Methods': 'GET, POST, PUT, OPTIONS',
206
- 'Access-Control-Allow-Headers': 'Content-Type, Accept, Authorization'
207
- }
208
- });
209
- }