@akinon/next 1.99.0-rc.69 → 1.99.0-rc.70
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 +6 -0
- package/api/form.ts +84 -0
- package/data/urls.ts +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
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
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.99.0-rc.
|
|
4
|
+
"version": "1.99.0-rc.70",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"bin": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"set-cookie-parser": "2.6.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@akinon/eslint-plugin-projectzero": "1.99.0-rc.
|
|
37
|
+
"@akinon/eslint-plugin-projectzero": "1.99.0-rc.70",
|
|
38
38
|
"@babel/core": "7.26.10",
|
|
39
39
|
"@babel/preset-env": "7.26.9",
|
|
40
40
|
"@babel/preset-typescript": "7.27.0",
|