@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.
- package/.eslintrc.js +12 -0
- package/CHANGELOG.md +400 -7
- package/__tests__/next-config.test.ts +83 -0
- package/__tests__/tsconfig.json +23 -0
- package/api/auth.ts +381 -60
- package/api/barcode-search.ts +59 -0
- package/api/cache.ts +41 -5
- package/api/client.ts +21 -4
- package/api/form.ts +85 -0
- package/api/image-proxy.ts +75 -0
- package/api/product-categories.ts +53 -0
- package/api/similar-product-list.ts +63 -0
- package/api/similar-products.ts +111 -0
- package/api/virtual-try-on.ts +382 -0
- package/assets/styles/index.scss +84 -0
- package/babel.config.js +6 -0
- package/bin/pz-generate-routes.js +115 -0
- package/bin/pz-install-plugins.js +1 -1
- package/bin/pz-prebuild.js +1 -0
- package/bin/pz-predev.js +1 -0
- package/bin/pz-run-tests.js +99 -0
- package/bin/run-prebuild-tests.js +46 -0
- package/components/accordion.tsx +20 -5
- package/components/button.tsx +51 -36
- package/components/client-root.tsx +138 -2
- package/components/file-input.tsx +65 -3
- package/components/index.ts +1 -0
- package/components/input.tsx +1 -1
- package/components/link.tsx +46 -16
- package/components/logger-popup.tsx +213 -0
- package/components/modal.tsx +32 -16
- package/components/plugin-module.tsx +62 -3
- package/components/price.tsx +2 -2
- package/components/select.tsx +1 -1
- package/components/selected-payment-option-view.tsx +21 -0
- package/data/client/account.ts +17 -2
- package/data/client/api.ts +2 -0
- package/data/client/basket.ts +66 -5
- package/data/client/checkout.ts +391 -99
- package/data/client/misc.ts +38 -2
- package/data/client/product.ts +19 -2
- package/data/client/user.ts +16 -8
- package/data/server/category.ts +11 -9
- package/data/server/flatpage.ts +11 -4
- package/data/server/form.ts +15 -4
- package/data/server/landingpage.ts +11 -4
- package/data/server/list.ts +5 -4
- package/data/server/menu.ts +11 -3
- package/data/server/product.ts +111 -55
- package/data/server/seo.ts +14 -4
- package/data/server/special-page.ts +5 -4
- package/data/server/widget.ts +90 -5
- package/data/urls.ts +16 -5
- package/hocs/client/with-segment-defaults.tsx +2 -2
- package/hocs/server/with-segment-defaults.tsx +65 -20
- package/hooks/index.ts +4 -0
- package/hooks/use-localization.ts +24 -10
- package/hooks/use-logger-context.tsx +114 -0
- package/hooks/use-logger.ts +92 -0
- package/hooks/use-loyalty-availability.ts +21 -0
- package/hooks/use-payment-options.ts +2 -1
- package/hooks/use-pz-params.ts +37 -0
- package/hooks/use-router.ts +51 -14
- package/hooks/use-sentry-uncaught-errors.ts +24 -0
- package/instrumentation/index.ts +10 -1
- package/instrumentation/node.ts +2 -20
- package/jest.config.js +25 -0
- package/lib/cache-handler.mjs +534 -16
- package/lib/cache.ts +272 -37
- package/localization/index.ts +2 -1
- package/localization/provider.tsx +2 -5
- package/middlewares/bfcache-headers.ts +18 -0
- package/middlewares/checkout-provider.ts +1 -1
- package/middlewares/complete-gpay.ts +32 -26
- package/middlewares/complete-masterpass.ts +33 -26
- package/middlewares/complete-wallet.ts +182 -0
- package/middlewares/default.ts +360 -215
- package/middlewares/index.ts +10 -2
- package/middlewares/locale.ts +34 -11
- package/middlewares/masterpass-rest-callback.ts +230 -0
- package/middlewares/oauth-login.ts +200 -57
- package/middlewares/pretty-url.ts +21 -8
- package/middlewares/redirection-payment.ts +32 -26
- package/middlewares/saved-card-redirection.ts +33 -26
- package/middlewares/three-d-redirection.ts +32 -26
- package/middlewares/url-redirection.ts +11 -1
- package/middlewares/wallet-complete-redirection.ts +206 -0
- package/package.json +24 -9
- package/plugins.d.ts +19 -4
- package/plugins.js +10 -1
- package/redux/actions.ts +47 -0
- package/redux/middlewares/checkout.ts +63 -138
- package/redux/middlewares/index.ts +14 -10
- package/redux/middlewares/pre-order/address.ts +7 -2
- package/redux/middlewares/pre-order/attribute-based-shipping-option.ts +7 -1
- package/redux/middlewares/pre-order/data-source-shipping-option.ts +7 -1
- package/redux/middlewares/pre-order/delivery-option.ts +7 -1
- package/redux/middlewares/pre-order/index.ts +16 -10
- package/redux/middlewares/pre-order/installment-option.ts +8 -1
- package/redux/middlewares/pre-order/payment-option-reset.ts +37 -0
- package/redux/middlewares/pre-order/payment-option.ts +7 -1
- package/redux/middlewares/pre-order/pre-order-validation.ts +8 -3
- package/redux/middlewares/pre-order/redirection.ts +8 -2
- package/redux/middlewares/pre-order/set-pre-order.ts +6 -2
- package/redux/middlewares/pre-order/shipping-option.ts +7 -1
- package/redux/middlewares/pre-order/shipping-step.ts +5 -1
- package/redux/reducers/checkout.ts +23 -3
- package/redux/reducers/index.ts +11 -3
- package/redux/reducers/root.ts +7 -2
- package/redux/reducers/widget.ts +80 -0
- package/sentry/index.ts +69 -13
- package/tailwind/content.js +16 -0
- package/types/commerce/account.ts +5 -1
- package/types/commerce/checkout.ts +35 -1
- package/types/commerce/widget.ts +33 -0
- package/types/index.ts +114 -6
- package/types/next-auth.d.ts +2 -2
- package/types/widget.ts +80 -0
- package/utils/app-fetch.ts +7 -2
- package/utils/generate-commerce-search-params.ts +3 -2
- package/utils/get-checkout-path.ts +3 -0
- package/utils/get-root-hostname.ts +28 -0
- package/utils/index.ts +64 -10
- package/utils/localization.ts +4 -0
- package/utils/mobile-3d-iframe.ts +8 -2
- package/utils/override-middleware.ts +7 -12
- package/utils/pz-segments.ts +92 -0
- package/utils/redirect-ignore.ts +35 -0
- package/utils/redirect.ts +9 -3
- package/utils/redirection-iframe.ts +8 -2
- package/utils/widget-styles.ts +107 -0
- package/views/error-page.tsx +93 -0
- package/with-pz-config.js +21 -7
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
import Settings from 'settings';
|
|
3
|
+
|
|
4
|
+
const VIRTUAL_TRY_ON_API_URL = process.env.NEXT_PUBLIC_VIRTUAL_TRY_ON_API_URL;
|
|
5
|
+
|
|
6
|
+
let limitedCategoriesCache: {
|
|
7
|
+
data: any;
|
|
8
|
+
timestamp: number;
|
|
9
|
+
} | null = null;
|
|
10
|
+
|
|
11
|
+
const CACHE_TTL = 3600000;
|
|
12
|
+
|
|
13
|
+
function getClientIP(request: NextRequest): string | null {
|
|
14
|
+
const forwardedFor = request.headers.get('x-forwarded-for');
|
|
15
|
+
if (forwardedFor) {
|
|
16
|
+
const ip = forwardedFor.split(',')[0].trim();
|
|
17
|
+
if (ip === '::1' || ip === '::ffff:127.0.0.1') {
|
|
18
|
+
return '127.0.0.1';
|
|
19
|
+
}
|
|
20
|
+
return ip;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const realIP = request.headers.get('x-real-ip');
|
|
24
|
+
if (realIP) {
|
|
25
|
+
if (realIP === '::1' || realIP === '::ffff:127.0.0.1') {
|
|
26
|
+
return '127.0.0.1';
|
|
27
|
+
}
|
|
28
|
+
return realIP;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (process.env.NODE_ENV === 'development') {
|
|
32
|
+
return '127.0.0.1';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function getLocaleFromRequest(request: NextRequest): string | null {
|
|
39
|
+
const cookieLocale = request.cookies.get('pz-locale')?.value;
|
|
40
|
+
|
|
41
|
+
if (cookieLocale) {
|
|
42
|
+
const currentLocale = Settings.localization.locales.find(
|
|
43
|
+
(l) => l.value === cookieLocale
|
|
44
|
+
);
|
|
45
|
+
return currentLocale?.apiValue || null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export async function GET(request: NextRequest) {
|
|
52
|
+
try {
|
|
53
|
+
const { searchParams } = new URL(request.url);
|
|
54
|
+
const endpoint = searchParams.get('endpoint');
|
|
55
|
+
|
|
56
|
+
if (endpoint === 'limited-categories') {
|
|
57
|
+
const now = Date.now();
|
|
58
|
+
|
|
59
|
+
if (
|
|
60
|
+
limitedCategoriesCache &&
|
|
61
|
+
now - limitedCategoriesCache.timestamp < CACHE_TTL
|
|
62
|
+
) {
|
|
63
|
+
return NextResponse.json(limitedCategoriesCache.data, {
|
|
64
|
+
status: 200,
|
|
65
|
+
headers: {
|
|
66
|
+
'Access-Control-Allow-Origin': '*',
|
|
67
|
+
'Access-Control-Allow-Methods': 'GET, POST, PUT, OPTIONS',
|
|
68
|
+
'Access-Control-Allow-Headers':
|
|
69
|
+
'Content-Type, Accept, Authorization',
|
|
70
|
+
'Cache-Control':
|
|
71
|
+
'public, s-maxage=3600, stale-while-revalidate=7200',
|
|
72
|
+
'X-Virtual-Try-On-Cache-Status': 'HIT'
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const externalUrl = `${VIRTUAL_TRY_ON_API_URL}/api/v1/limited-categories`;
|
|
78
|
+
const clientIP = getClientIP(request);
|
|
79
|
+
const locale = getLocaleFromRequest(request);
|
|
80
|
+
|
|
81
|
+
const headersToSend = {
|
|
82
|
+
Accept: 'application/json',
|
|
83
|
+
...(locale && { 'Accept-Language': locale }),
|
|
84
|
+
...(request.headers.get('authorization') && {
|
|
85
|
+
Authorization: request.headers.get('authorization')!
|
|
86
|
+
}),
|
|
87
|
+
...(clientIP && {
|
|
88
|
+
'X-Forwarded-For': clientIP
|
|
89
|
+
})
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const response = await fetch(externalUrl, {
|
|
93
|
+
method: 'GET',
|
|
94
|
+
headers: headersToSend
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
let responseData: any;
|
|
98
|
+
const responseText = await response.text();
|
|
99
|
+
|
|
100
|
+
try {
|
|
101
|
+
responseData = responseText ? JSON.parse(responseText) : {};
|
|
102
|
+
} catch (parseError) {
|
|
103
|
+
responseData = { category_ids: [] };
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (!response.ok) {
|
|
107
|
+
responseData = { category_ids: [] };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
limitedCategoriesCache = {
|
|
111
|
+
data: responseData,
|
|
112
|
+
timestamp: Date.now()
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
return NextResponse.json(responseData, {
|
|
116
|
+
status: response.ok ? response.status : 200,
|
|
117
|
+
headers: {
|
|
118
|
+
'Access-Control-Allow-Origin': '*',
|
|
119
|
+
'Access-Control-Allow-Methods': 'GET, POST, PUT, OPTIONS',
|
|
120
|
+
'Access-Control-Allow-Headers': 'Content-Type, Accept, Authorization',
|
|
121
|
+
'Cache-Control': 'public, s-maxage=3600, stale-while-revalidate=7200',
|
|
122
|
+
'X-Virtual-Try-On-Cache-Status': 'MISS'
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
} else if (endpoint === 'job-status') {
|
|
126
|
+
const referenceUrl = searchParams.get('reference_url');
|
|
127
|
+
if (!referenceUrl) {
|
|
128
|
+
return NextResponse.json(
|
|
129
|
+
{ error: 'reference_url is required' },
|
|
130
|
+
{ status: 400 }
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const externalUrl = `${VIRTUAL_TRY_ON_API_URL}/api/async/v1/job-status?reference_url=${encodeURIComponent(
|
|
135
|
+
referenceUrl
|
|
136
|
+
)}`;
|
|
137
|
+
const clientIP = getClientIP(request);
|
|
138
|
+
const locale = getLocaleFromRequest(request);
|
|
139
|
+
|
|
140
|
+
const headersToSend = {
|
|
141
|
+
Accept: 'application/json',
|
|
142
|
+
...(locale && { 'Accept-Language': locale }),
|
|
143
|
+
...(request.headers.get('authorization') && {
|
|
144
|
+
Authorization: request.headers.get('authorization')!
|
|
145
|
+
}),
|
|
146
|
+
...(clientIP && {
|
|
147
|
+
'X-Forwarded-For': clientIP
|
|
148
|
+
})
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
const response = await fetch(externalUrl, {
|
|
152
|
+
method: 'GET',
|
|
153
|
+
headers: headersToSend
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
let responseData: any;
|
|
157
|
+
const responseText = await response.text();
|
|
158
|
+
|
|
159
|
+
try {
|
|
160
|
+
responseData = responseText ? JSON.parse(responseText) : {};
|
|
161
|
+
} catch (parseError) {
|
|
162
|
+
return NextResponse.json(
|
|
163
|
+
{ error: 'Invalid JSON response from job status API' },
|
|
164
|
+
{ status: 500 }
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return NextResponse.json(responseData, {
|
|
169
|
+
status: response.status,
|
|
170
|
+
headers: {
|
|
171
|
+
'Access-Control-Allow-Origin': '*',
|
|
172
|
+
'Access-Control-Allow-Methods': 'GET, POST, PUT, OPTIONS',
|
|
173
|
+
'Access-Control-Allow-Headers': 'Content-Type, Accept, Authorization'
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return NextResponse.json(
|
|
179
|
+
{ error: 'Invalid endpoint for GET method' },
|
|
180
|
+
{ status: 400 }
|
|
181
|
+
);
|
|
182
|
+
} catch (error) {
|
|
183
|
+
return NextResponse.json({ category_ids: [] }, { status: 200 });
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export async function POST(request: NextRequest) {
|
|
188
|
+
try {
|
|
189
|
+
const { searchParams } = new URL(request.url);
|
|
190
|
+
const endpoint = searchParams.get('endpoint');
|
|
191
|
+
|
|
192
|
+
const body = await request.json();
|
|
193
|
+
|
|
194
|
+
let externalUrl: string;
|
|
195
|
+
let httpMethod = 'POST';
|
|
196
|
+
|
|
197
|
+
if (endpoint === 'feedback') {
|
|
198
|
+
if (!body.url || typeof body.url !== 'string' || !body.url.trim()) {
|
|
199
|
+
return NextResponse.json(
|
|
200
|
+
{ status: 'error', message: 'URL is required for feedback' },
|
|
201
|
+
{ status: 400 }
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
if (typeof body.feedback !== 'boolean') {
|
|
205
|
+
return NextResponse.json(
|
|
206
|
+
{ status: 'error', message: 'Feedback must be a boolean value' },
|
|
207
|
+
{ status: 400 }
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
externalUrl = `${VIRTUAL_TRY_ON_API_URL}/api/v1/feedback`;
|
|
211
|
+
httpMethod = 'PUT';
|
|
212
|
+
} else if (endpoint === 'async-multiple-try-on') {
|
|
213
|
+
externalUrl = `${VIRTUAL_TRY_ON_API_URL}/api/async/v1/multiple-virtual-try-on`;
|
|
214
|
+
} else {
|
|
215
|
+
return NextResponse.json(
|
|
216
|
+
{ error: 'Invalid endpoint specified' },
|
|
217
|
+
{ status: 400 }
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const clientIP = getClientIP(request);
|
|
222
|
+
const locale = getLocaleFromRequest(request);
|
|
223
|
+
|
|
224
|
+
const headersToSend = {
|
|
225
|
+
'Content-Type': 'application/json',
|
|
226
|
+
...(locale && { 'Accept-Language': locale }),
|
|
227
|
+
...(httpMethod === 'POST' && { Accept: 'application/json' }),
|
|
228
|
+
...(request.headers.get('authorization') && {
|
|
229
|
+
Authorization: request.headers.get('authorization')!
|
|
230
|
+
}),
|
|
231
|
+
...(clientIP && {
|
|
232
|
+
'X-Forwarded-For': clientIP
|
|
233
|
+
})
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
const fetchOptions: RequestInit = {
|
|
237
|
+
method: httpMethod,
|
|
238
|
+
headers: headersToSend
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
if (httpMethod !== 'GET') {
|
|
242
|
+
fetchOptions.body = JSON.stringify(body);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const response = await fetch(externalUrl, fetchOptions);
|
|
246
|
+
|
|
247
|
+
let responseData: Record<string, any>;
|
|
248
|
+
const responseText = await response.text();
|
|
249
|
+
|
|
250
|
+
if (endpoint === 'feedback') {
|
|
251
|
+
try {
|
|
252
|
+
responseData = responseText ? JSON.parse(responseText) : {};
|
|
253
|
+
} catch (parseError) {
|
|
254
|
+
responseData = { error: 'Invalid JSON response from feedback API' };
|
|
255
|
+
}
|
|
256
|
+
} else {
|
|
257
|
+
try {
|
|
258
|
+
responseData = responseText ? JSON.parse(responseText) : {};
|
|
259
|
+
} catch (parseError) {
|
|
260
|
+
responseData = { error: 'Invalid JSON response' };
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (!response.ok && responseData.error) {
|
|
265
|
+
let userFriendlyMessage = responseData.error;
|
|
266
|
+
|
|
267
|
+
if (
|
|
268
|
+
typeof responseData.error === 'string' &&
|
|
269
|
+
(responseData.error.includes('duplicate key value') ||
|
|
270
|
+
responseData.error.includes('image_pk'))
|
|
271
|
+
) {
|
|
272
|
+
userFriendlyMessage =
|
|
273
|
+
'This image has already been processed. Please try with a different image.';
|
|
274
|
+
} else if (responseData.error.includes('bulk insert images')) {
|
|
275
|
+
userFriendlyMessage =
|
|
276
|
+
'There was an issue processing your image. Please try again with a different image.';
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return NextResponse.json(
|
|
280
|
+
{
|
|
281
|
+
...responseData,
|
|
282
|
+
message: userFriendlyMessage
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
status: response.status,
|
|
286
|
+
headers: {
|
|
287
|
+
'Access-Control-Allow-Origin': '*',
|
|
288
|
+
'Access-Control-Allow-Methods': 'POST, OPTIONS',
|
|
289
|
+
'Access-Control-Allow-Headers':
|
|
290
|
+
'Content-Type, Accept, Authorization'
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
return NextResponse.json(responseData, {
|
|
297
|
+
status: response.status,
|
|
298
|
+
headers: {
|
|
299
|
+
'Access-Control-Allow-Origin': '*',
|
|
300
|
+
'Access-Control-Allow-Methods': 'POST, OPTIONS',
|
|
301
|
+
'Access-Control-Allow-Headers': 'Content-Type, Accept, Authorization'
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
} catch (error) {
|
|
305
|
+
return NextResponse.json(
|
|
306
|
+
{
|
|
307
|
+
status: 'error',
|
|
308
|
+
message:
|
|
309
|
+
'Internal server error occurred during virtual try-on processing'
|
|
310
|
+
},
|
|
311
|
+
{ status: 500 }
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export async function PUT(request: NextRequest) {
|
|
317
|
+
try {
|
|
318
|
+
const { searchParams } = new URL(request.url);
|
|
319
|
+
const endpoint = searchParams.get('endpoint');
|
|
320
|
+
|
|
321
|
+
if (endpoint !== 'feedback') {
|
|
322
|
+
return NextResponse.json(
|
|
323
|
+
{ error: 'PUT method only supports feedback endpoint' },
|
|
324
|
+
{ status: 400 }
|
|
325
|
+
);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
const body = await request.json();
|
|
329
|
+
|
|
330
|
+
const externalUrl = `${VIRTUAL_TRY_ON_API_URL}/api/v1/feedback`;
|
|
331
|
+
const clientIP = getClientIP(request);
|
|
332
|
+
const locale = getLocaleFromRequest(request);
|
|
333
|
+
|
|
334
|
+
const headersToSend = {
|
|
335
|
+
'Content-Type': 'application/json',
|
|
336
|
+
...(locale && { 'Accept-Language': locale }),
|
|
337
|
+
...(request.headers.get('authorization') && {
|
|
338
|
+
Authorization: request.headers.get('authorization')!
|
|
339
|
+
}),
|
|
340
|
+
...(clientIP && {
|
|
341
|
+
'X-Forwarded-For': clientIP
|
|
342
|
+
})
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
const response = await fetch(externalUrl, {
|
|
346
|
+
method: 'PUT',
|
|
347
|
+
headers: headersToSend,
|
|
348
|
+
body: JSON.stringify(body)
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
const responseData = response?.json() || {};
|
|
352
|
+
|
|
353
|
+
return NextResponse.json(responseData, {
|
|
354
|
+
status: response.status,
|
|
355
|
+
headers: {
|
|
356
|
+
'Access-Control-Allow-Origin': '*',
|
|
357
|
+
'Access-Control-Allow-Methods': 'GET, POST, PUT, OPTIONS',
|
|
358
|
+
'Access-Control-Allow-Headers': 'Content-Type, Accept, Authorization'
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
} catch (error) {
|
|
362
|
+
return NextResponse.json(
|
|
363
|
+
{
|
|
364
|
+
status: 'error',
|
|
365
|
+
message: 'Internal server error occurred during feedback submission',
|
|
366
|
+
error: (error as Error).message
|
|
367
|
+
},
|
|
368
|
+
{ status: 500 }
|
|
369
|
+
);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
export async function OPTIONS() {
|
|
374
|
+
return new NextResponse(null, {
|
|
375
|
+
status: 200,
|
|
376
|
+
headers: {
|
|
377
|
+
'Access-Control-Allow-Origin': '*',
|
|
378
|
+
'Access-Control-Allow-Methods': 'GET, POST, PUT, OPTIONS',
|
|
379
|
+
'Access-Control-Allow-Headers': 'Content-Type, Accept, Authorization'
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
}
|
package/assets/styles/index.scss
CHANGED
|
@@ -51,3 +51,87 @@
|
|
|
51
51
|
z-index: 1001;
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
+
|
|
55
|
+
.container-droppable {
|
|
56
|
+
outline: 2px dashed #4482ff !important;
|
|
57
|
+
outline-offset: -2px;
|
|
58
|
+
background-color: rgba(96, 165, 250, 0.1) !important;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.container-dragover {
|
|
62
|
+
background-color: rgba(59, 130, 246, 0.1);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.container-dragover::after {
|
|
66
|
+
content: '';
|
|
67
|
+
position: absolute;
|
|
68
|
+
top: 0;
|
|
69
|
+
left: 0;
|
|
70
|
+
right: 0;
|
|
71
|
+
bottom: 0;
|
|
72
|
+
border: 2px solid #4482ff;
|
|
73
|
+
pointer-events: none;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.dragging * {
|
|
77
|
+
cursor: default !important;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.dragging [data-component='true'] {
|
|
81
|
+
cursor: grabbing !important;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.dragging .drop-target {
|
|
85
|
+
cursor: grab !important;
|
|
86
|
+
outline: 2px dashed #4482ff !important;
|
|
87
|
+
outline-offset: -2px;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.dragging .no-drop-target {
|
|
91
|
+
cursor: no-drop !important;
|
|
92
|
+
outline: 2px dashed #e63946 !important;
|
|
93
|
+
outline-offset: -2px;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
[data-component='true'] {
|
|
97
|
+
cursor: pointer;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.carousel-container {
|
|
101
|
+
li[aria-hidden='false'] {
|
|
102
|
+
div {
|
|
103
|
+
display: block;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.posts-slider-carousel {
|
|
109
|
+
width: 100%;
|
|
110
|
+
|
|
111
|
+
.react-multi-carousel-track {
|
|
112
|
+
align-items: stretch;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.posts-slider-dots {
|
|
117
|
+
position: relative;
|
|
118
|
+
display: flex;
|
|
119
|
+
justify-content: center;
|
|
120
|
+
gap: 8px;
|
|
121
|
+
margin-top: 16px;
|
|
122
|
+
padding: 0;
|
|
123
|
+
list-style: none;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.posts-slider-dots li button {
|
|
127
|
+
width: 8px;
|
|
128
|
+
height: 8px;
|
|
129
|
+
border-radius: 9999px;
|
|
130
|
+
border: none;
|
|
131
|
+
background: rgba(0, 0, 0, 0.25);
|
|
132
|
+
cursor: pointer;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.posts-slider-dots li.react-multi-carousel-dot--active button {
|
|
136
|
+
background: rgba(0, 0, 0, 0.6);
|
|
137
|
+
}
|
package/babel.config.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const findBaseDir = require('../utils/find-base-dir');
|
|
6
|
+
|
|
7
|
+
const generateRoutes = () => {
|
|
8
|
+
const baseDir = findBaseDir();
|
|
9
|
+
const srcDir = path.join(baseDir, 'src');
|
|
10
|
+
const appDir = path.join(srcDir, 'app');
|
|
11
|
+
|
|
12
|
+
const routesDir = path.join(srcDir, 'routes');
|
|
13
|
+
const jsOutputPath = path.join(routesDir, 'generated-routes.js');
|
|
14
|
+
|
|
15
|
+
if (!fs.existsSync(routesDir)) {
|
|
16
|
+
fs.mkdirSync(routesDir, { recursive: true });
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (!fs.existsSync(appDir)) {
|
|
20
|
+
console.error(`Error: app directory not found at ${appDir}`);
|
|
21
|
+
console.error('Make sure you have an app directory in your project');
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const routes = [];
|
|
26
|
+
const excludedDirs = ['api', 'pz-not-found'];
|
|
27
|
+
|
|
28
|
+
const skipSegments = [
|
|
29
|
+
'[pz]',
|
|
30
|
+
'[commerce]',
|
|
31
|
+
'[locale]',
|
|
32
|
+
'[currency]',
|
|
33
|
+
'[session]',
|
|
34
|
+
'[segment]',
|
|
35
|
+
'[url]',
|
|
36
|
+
'[theme]',
|
|
37
|
+
'[member_type]'
|
|
38
|
+
];
|
|
39
|
+
const skipCatchAllRoutes = ['[...prettyurl]', '[...not_found]'];
|
|
40
|
+
|
|
41
|
+
const walkDirectory = (dir, basePath = '') => {
|
|
42
|
+
const files = fs.readdirSync(dir);
|
|
43
|
+
|
|
44
|
+
files.forEach((file) => {
|
|
45
|
+
const filePath = path.join(dir, file);
|
|
46
|
+
const stat = fs.statSync(filePath);
|
|
47
|
+
|
|
48
|
+
if (stat.isDirectory()) {
|
|
49
|
+
if (excludedDirs.includes(file)) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (skipCatchAllRoutes.includes(file.toLowerCase())) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
let routePath = basePath;
|
|
58
|
+
if (skipSegments.includes(file.toLowerCase())) {
|
|
59
|
+
routePath = basePath;
|
|
60
|
+
} else if (file.startsWith('[') && file.endsWith(']')) {
|
|
61
|
+
if (file.startsWith('[...')) {
|
|
62
|
+
routePath = `${basePath}/.+`;
|
|
63
|
+
} else {
|
|
64
|
+
routePath = `${basePath}/[^/]+`;
|
|
65
|
+
}
|
|
66
|
+
} else if (file.startsWith('(') && file.endsWith(')')) {
|
|
67
|
+
routePath = basePath;
|
|
68
|
+
} else {
|
|
69
|
+
routePath = `${basePath}/${file}`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const pageFiles = ['page.tsx'];
|
|
73
|
+
const hasPage = pageFiles.some((pageFile) =>
|
|
74
|
+
fs.existsSync(path.join(filePath, pageFile))
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
if (hasPage && routePath) {
|
|
78
|
+
routes.push(routePath === '' ? '/' : routePath);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
walkDirectory(filePath, routePath);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
walkDirectory(appDir);
|
|
87
|
+
|
|
88
|
+
routes.push('/');
|
|
89
|
+
|
|
90
|
+
const cleanedRoutes = routes
|
|
91
|
+
.map((route) => {
|
|
92
|
+
return route.replace(/\/+/g, '/');
|
|
93
|
+
})
|
|
94
|
+
.filter((route, index, self) => {
|
|
95
|
+
return self.indexOf(route) === index;
|
|
96
|
+
})
|
|
97
|
+
.sort();
|
|
98
|
+
|
|
99
|
+
const jsContent = `// Generated by pz-generate-routes script
|
|
100
|
+
// Do not edit manually
|
|
101
|
+
module.exports = ${JSON.stringify(cleanedRoutes, null, 2)};`;
|
|
102
|
+
|
|
103
|
+
fs.writeFileSync(jsOutputPath, jsContent);
|
|
104
|
+
|
|
105
|
+
console.info(
|
|
106
|
+
`Routes generated successfully. (Found ${cleanedRoutes.length} routes)`
|
|
107
|
+
);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
try {
|
|
111
|
+
generateRoutes();
|
|
112
|
+
} catch (error) {
|
|
113
|
+
console.error('Error generating routes:', error);
|
|
114
|
+
process.exit(1);
|
|
115
|
+
}
|
package/bin/pz-prebuild.js
CHANGED
package/bin/pz-predev.js
CHANGED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { spawn } = require('child_process');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const glob = require('glob');
|
|
7
|
+
const findBaseDir = require('../utils/find-base-dir');
|
|
8
|
+
const checkMonorepo = require('../utils/check-monorepo');
|
|
9
|
+
|
|
10
|
+
const IS_MONOREPO = checkMonorepo() !== null;
|
|
11
|
+
const BASE_DIR = findBaseDir();
|
|
12
|
+
const PLUGINS = require(path.join(BASE_DIR, 'src', 'plugins.js'));
|
|
13
|
+
|
|
14
|
+
function findPluginTestFiles(akinonNextPackagePath) {
|
|
15
|
+
const pluginsRootPath = path.join(
|
|
16
|
+
akinonNextPackagePath,
|
|
17
|
+
'..',
|
|
18
|
+
'..',
|
|
19
|
+
IS_MONOREPO ? 'packages' : '@akinon'
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
if (!fs.existsSync(pluginsRootPath)) {
|
|
23
|
+
console.log('Plugins directory not found:', pluginsRootPath);
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return PLUGINS.reduce((testFiles, pluginName) => {
|
|
28
|
+
const pluginDirectoryPath = path.join(pluginsRootPath, pluginName);
|
|
29
|
+
if (fs.existsSync(pluginDirectoryPath)) {
|
|
30
|
+
const pluginTestFiles = glob.sync('**/*.test.ts', {
|
|
31
|
+
cwd: pluginDirectoryPath,
|
|
32
|
+
absolute: true
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
return testFiles.concat(pluginTestFiles);
|
|
36
|
+
} else {
|
|
37
|
+
console.log(`Plugin directory not found: ${pluginName}`);
|
|
38
|
+
}
|
|
39
|
+
return testFiles;
|
|
40
|
+
}, []);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function isJestInstalled() {
|
|
44
|
+
try {
|
|
45
|
+
const jestExecutablePath = path.join(
|
|
46
|
+
BASE_DIR,
|
|
47
|
+
'node_modules',
|
|
48
|
+
'.bin',
|
|
49
|
+
'jest'
|
|
50
|
+
);
|
|
51
|
+
return fs.existsSync(jestExecutablePath);
|
|
52
|
+
} catch (error) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function getAkinonNextPackagePath() {
|
|
58
|
+
if (!IS_MONOREPO) {
|
|
59
|
+
return path.resolve(__dirname, '..');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return path.resolve(__dirname, '../../../packages/akinon-next');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (!isJestInstalled()) {
|
|
66
|
+
console.error('\x1b[31mError: Jest is not installed in the project!\x1b[0m');
|
|
67
|
+
console.error(
|
|
68
|
+
'Please install all dependencies by running one of the following commands:'
|
|
69
|
+
);
|
|
70
|
+
console.error(' npm install');
|
|
71
|
+
console.error(' yarn install');
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const jestExecutablePath = path.join(BASE_DIR, 'node_modules', '.bin', 'jest');
|
|
76
|
+
const akinonNextPackagePath = getAkinonNextPackagePath();
|
|
77
|
+
|
|
78
|
+
const testFiles = [
|
|
79
|
+
...glob.sync('__tests__/**/*.test.ts', {
|
|
80
|
+
cwd: akinonNextPackagePath,
|
|
81
|
+
absolute: true
|
|
82
|
+
}),
|
|
83
|
+
...findPluginTestFiles(akinonNextPackagePath)
|
|
84
|
+
];
|
|
85
|
+
|
|
86
|
+
console.log(`Found ${testFiles.length} test files to run`);
|
|
87
|
+
|
|
88
|
+
const jestArguments = [
|
|
89
|
+
...testFiles,
|
|
90
|
+
`--config ${path.join(akinonNextPackagePath, 'jest.config.js')}`,
|
|
91
|
+
'--runTestsByPath',
|
|
92
|
+
'--passWithNoTests'
|
|
93
|
+
];
|
|
94
|
+
|
|
95
|
+
spawn(jestExecutablePath, jestArguments, {
|
|
96
|
+
cwd: akinonNextPackagePath,
|
|
97
|
+
stdio: 'inherit',
|
|
98
|
+
shell: true
|
|
99
|
+
});
|