@akinon/next 1.103.0 → 1.104.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @akinon/next
2
2
 
3
+ ## 1.104.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 63774a6: ZERO-3351: Add commerce redirection ignore list functionality and related utility
8
+ - a2fbee6: ZERO-3651: Fix correct is Iframe property in contextListMiddleware
9
+ - 0de5573: ZERO-3418: Update remotePatterns hostname to allow all subdomains
10
+ - 5ad87ff: ZERO-3646: Refactor form submission API to handle form data and improve error responses
11
+
3
12
  ## 1.103.0
4
13
 
5
14
  ## 1.102.0
package/api/form.ts ADDED
@@ -0,0 +1,84 @@
1
+ import { NextRequest, NextResponse } from 'next/server';
2
+ import { getFormData } from '@akinon/next/data/server';
3
+
4
+ interface FormRouteParams {
5
+ params: {
6
+ id: string[];
7
+ };
8
+ }
9
+
10
+ interface FormConfig {
11
+ pk: number;
12
+ is_active: boolean;
13
+ }
14
+
15
+ type SubmissionData = Record<string, string | File>;
16
+
17
+ export async function POST(request: NextRequest, { params }: FormRouteParams) {
18
+ try {
19
+ const formId = params.id?.[0];
20
+
21
+ if (!formId || isNaN(Number(formId))) {
22
+ return NextResponse.json(
23
+ { error: 'Valid form ID is required' },
24
+ { status: 400 }
25
+ );
26
+ }
27
+
28
+ const formConfig: FormConfig | null = await getFormData({
29
+ pk: Number(formId)
30
+ });
31
+
32
+ if (!formConfig || !formConfig.is_active) {
33
+ return NextResponse.json(
34
+ { error: 'Form not found or inactive' },
35
+ { status: 404 }
36
+ );
37
+ }
38
+
39
+ const formData = await request.formData();
40
+ const submissionData: SubmissionData = Object.fromEntries(
41
+ formData.entries()
42
+ );
43
+
44
+ return await processFormSubmission(formConfig, submissionData);
45
+ } catch (error) {
46
+ console.error('Form submission error:', error);
47
+
48
+ return NextResponse.json(
49
+ { error: 'Internal server error' },
50
+ { status: 500 }
51
+ );
52
+ }
53
+ }
54
+
55
+ async function processFormSubmission(
56
+ formConfig: FormConfig,
57
+ data: SubmissionData
58
+ ) {
59
+ const backendUrl = process.env.SERVICE_BACKEND_URL;
60
+ if (!backendUrl) {
61
+ throw new Error('SERVICE_BACKEND_URL is not defined');
62
+ }
63
+
64
+ const url = `${backendUrl}/forms/${formConfig.pk}/generate`;
65
+
66
+ const submissionPayload = {
67
+ ...data
68
+ };
69
+
70
+ const response = await fetch(url, {
71
+ method: 'POST',
72
+ headers: { 'Content-Type': 'application/json' },
73
+ body: JSON.stringify(submissionPayload)
74
+ });
75
+
76
+ const body = await response.text();
77
+
78
+ return new NextResponse(body, {
79
+ status: response.status,
80
+ headers: {
81
+ 'Content-Type': response.headers.get('content-type') ?? 'application/json'
82
+ }
83
+ });
84
+ }
package/data/urls.ts CHANGED
@@ -247,7 +247,7 @@ export const widgets = {
247
247
  };
248
248
 
249
249
  export const form = {
250
- getForm: (pk: number) => `/forms/${pk}/generate/`
250
+ getForm: (pk: number) => `/forms/${pk}/generate`
251
251
  };
252
252
 
253
253
  const URLS = {
@@ -4,6 +4,7 @@ import { PzNextRequest } from '.';
4
4
  import logger from '../utils/log';
5
5
  import { urlLocaleMatcherRegex } from '../utils';
6
6
  import { getUrlPathWithLocale } from '../utils/localization';
7
+ import { shouldIgnoreRedirect } from '../utils/redirect-ignore';
7
8
  import { ROUTES } from 'routes';
8
9
 
9
10
  // This middleware is used to handle url redirections set in Omnitron
@@ -60,20 +61,13 @@ const withUrlRedirection =
60
61
 
61
62
  const setCookies = request.headers.getSetCookie();
62
63
 
63
- if (settings.commerceRedirectionIgnoreList) {
64
- const shouldIgnoreRedirect =
65
- settings.commerceRedirectionIgnoreList.some((ignorePath) =>
66
- redirectUrl.pathname.startsWith(
67
- getUrlPathWithLocale(
68
- ignorePath,
69
- req.middlewareParams.rewrites.locale
70
- )
71
- )
72
- );
73
-
74
- if (shouldIgnoreRedirect) {
75
- return middleware(req, event);
76
- }
64
+ if (
65
+ shouldIgnoreRedirect(
66
+ url.pathname,
67
+ req.middlewareParams.rewrites.locale
68
+ )
69
+ ) {
70
+ return middleware(req, event);
77
71
  }
78
72
 
79
73
  const response = NextResponse.redirect(redirectUrl.toString(), {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@akinon/next",
3
3
  "description": "Core package for Project Zero Next",
4
- "version": "1.103.0",
4
+ "version": "1.104.0",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "bin": {
@@ -35,7 +35,7 @@
35
35
  "set-cookie-parser": "2.6.0"
36
36
  },
37
37
  "devDependencies": {
38
- "@akinon/eslint-plugin-projectzero": "1.103.0",
38
+ "@akinon/eslint-plugin-projectzero": "1.104.0",
39
39
  "@babel/core": "7.26.10",
40
40
  "@babel/preset-env": "7.26.9",
41
41
  "@babel/preset-typescript": "7.27.0",
@@ -98,7 +98,7 @@ export const contextListMiddleware: Middleware = ({
98
98
  if (result?.payload?.context_list) {
99
99
  result.payload.context_list.forEach((context) => {
100
100
  const redirectUrl = context.page_context.redirect_url;
101
- const isIframe = context.page_context.is_frame ?? false;
101
+ const isIframe = context.page_context.is_iframe ?? false;
102
102
 
103
103
  if (redirectUrl) {
104
104
  const currentLocale = getCookie('pz-locale');
@@ -0,0 +1,35 @@
1
+ import settings from 'settings';
2
+ import { getUrlPathWithLocale } from './localization';
3
+
4
+ type IgnorePath = string | RegExp;
5
+
6
+ const defaultIgnoreList: string[] = [];
7
+
8
+ const extraIgnores: IgnorePath[] = Array.isArray(
9
+ settings.commerceRedirectionIgnoreList
10
+ )
11
+ ? settings.commerceRedirectionIgnoreList.map((path) => {
12
+ if (path === '/users/reset') {
13
+ return /^\/users\/reset\/[^/]+\/[^/]+\/$/;
14
+ }
15
+ return path;
16
+ })
17
+ : [];
18
+
19
+ export function shouldIgnoreRedirect(
20
+ pathname: string,
21
+ locale: string
22
+ ): boolean {
23
+ if (!pathname) return false;
24
+
25
+ const rawIgnoreList: IgnorePath[] = [...defaultIgnoreList, ...extraIgnores];
26
+
27
+ return rawIgnoreList.some((ignorePath) => {
28
+ if (ignorePath instanceof RegExp) {
29
+ return ignorePath.test(pathname);
30
+ }
31
+
32
+ const localized = getUrlPathWithLocale(ignorePath, locale);
33
+ return localized === pathname;
34
+ });
35
+ }
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: {