@akinon/next 1.103.0-snapshot-ZERO-3648-20251002084215 → 1.103.0-snapshot-ZERO-3648-20251002182439

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,6 +1,6 @@
1
1
  # @akinon/next
2
2
 
3
- ## 1.103.0-snapshot-ZERO-3648-20251002084215
3
+ ## 1.103.0-snapshot-ZERO-3648-20251002182439
4
4
 
5
5
  ### Minor Changes
6
6
 
@@ -9,6 +9,41 @@ let limitedCategoriesCache: {
9
9
 
10
10
  const CACHE_TTL = 3600000;
11
11
 
12
+ function getClientIP(request: NextRequest): string | null {
13
+ const forwardedFor = request.headers.get('x-forwarded-for');
14
+ if (forwardedFor) {
15
+ const ip = forwardedFor.split(',')[0].trim();
16
+ if (ip === '::1' || ip === '::ffff:127.0.0.1') {
17
+ return '127.0.0.1';
18
+ }
19
+ return ip;
20
+ }
21
+
22
+ const realIP = request.headers.get('x-real-ip');
23
+ if (realIP) {
24
+ if (realIP === '::1' || realIP === '::ffff:127.0.0.1') {
25
+ return '127.0.0.1';
26
+ }
27
+ return realIP;
28
+ }
29
+
30
+ if (process.env.NODE_ENV === 'development') {
31
+ return '127.0.0.1';
32
+ }
33
+
34
+ return null;
35
+ }
36
+
37
+ function getLocaleFromRequest(request: NextRequest): string {
38
+ const referer = request.headers.get('referer') || '';
39
+ const localeMatch = referer.match(/\/(\w{2})[-/]/);
40
+ return localeMatch ? localeMatch[1] : 'en';
41
+ }
42
+
43
+ function getAcceptLanguageHeader(locale: string): string {
44
+ return `${locale}-${locale.toUpperCase()},${locale};q=0.9`;
45
+ }
46
+
12
47
  export async function GET(request: NextRequest) {
13
48
  try {
14
49
  const { searchParams } = new URL(request.url);
@@ -36,18 +71,24 @@ export async function GET(request: NextRequest) {
36
71
  }
37
72
 
38
73
  const externalUrl = `${VIRTUAL_TRY_ON_API_URL}/api/v1/limited-categories`;
74
+ const clientIP = getClientIP(request);
75
+ const locale = getLocaleFromRequest(request);
76
+ const acceptLanguage = getAcceptLanguageHeader(locale);
77
+
78
+ const headersToSend = {
79
+ Accept: 'application/json',
80
+ 'Accept-Language': acceptLanguage,
81
+ ...(request.headers.get('authorization') && {
82
+ Authorization: request.headers.get('authorization')!
83
+ }),
84
+ ...(clientIP && {
85
+ 'X-Forwarded-For': clientIP
86
+ })
87
+ };
39
88
 
40
89
  const response = await fetch(externalUrl, {
41
90
  method: 'GET',
42
- headers: {
43
- Accept: 'application/json',
44
- ...(request.headers.get('authorization') && {
45
- Authorization: request.headers.get('authorization')!
46
- }),
47
- ...(request.headers.get('x-forwarded-for') && {
48
- 'X-Forwarded-For': request.headers.get('x-forwarded-for')!
49
- })
50
- }
91
+ headers: headersToSend
51
92
  });
52
93
 
53
94
  let responseData: any;
@@ -104,21 +145,25 @@ export async function POST(request: NextRequest) {
104
145
  }
105
146
 
106
147
  const httpMethod = endpoint === 'feedback' ? 'PUT' : 'POST';
107
-
108
- const forwardedFor = request.headers.get('x-forwarded-for');
148
+ const clientIP = getClientIP(request);
149
+ const locale = getLocaleFromRequest(request);
150
+ const acceptLanguage = getAcceptLanguageHeader(locale);
151
+
152
+ const headersToSend = {
153
+ 'Content-Type': 'application/json',
154
+ 'Accept-Language': acceptLanguage,
155
+ ...(httpMethod === 'POST' && { Accept: 'application/json' }),
156
+ ...(request.headers.get('authorization') && {
157
+ Authorization: request.headers.get('authorization')!
158
+ }),
159
+ ...(clientIP && {
160
+ 'X-Forwarded-For': clientIP
161
+ })
162
+ };
109
163
 
110
164
  const response = await fetch(externalUrl, {
111
165
  method: httpMethod,
112
- headers: {
113
- 'Content-Type': 'application/json',
114
- ...(httpMethod === 'POST' && { Accept: 'application/json' }),
115
- ...(request.headers.get('authorization') && {
116
- Authorization: request.headers.get('authorization')!
117
- }),
118
- ...(request.headers.get('x-forwarded-for') && {
119
- 'X-Forwarded-For': request.headers.get('x-forwarded-for')!
120
- })
121
- },
166
+ headers: headersToSend,
122
167
  body: JSON.stringify(body)
123
168
  });
124
169
 
@@ -206,18 +251,24 @@ export async function PUT(request: NextRequest) {
206
251
  const body = await request.json();
207
252
 
208
253
  const externalUrl = `${VIRTUAL_TRY_ON_API_URL}/api/v1/feedback`;
254
+ const clientIP = getClientIP(request);
255
+ const locale = getLocaleFromRequest(request);
256
+ const acceptLanguage = getAcceptLanguageHeader(locale);
257
+
258
+ const headersToSend = {
259
+ 'Content-Type': 'application/json',
260
+ 'Accept-Language': acceptLanguage,
261
+ ...(request.headers.get('authorization') && {
262
+ Authorization: request.headers.get('authorization')!
263
+ }),
264
+ ...(clientIP && {
265
+ 'X-Forwarded-For': clientIP
266
+ })
267
+ };
209
268
 
210
269
  const response = await fetch(externalUrl, {
211
270
  method: 'PUT',
212
- headers: {
213
- 'Content-Type': 'application/json',
214
- ...(request.headers.get('authorization') && {
215
- Authorization: request.headers.get('authorization')!
216
- }),
217
- ...(request.headers.get('x-forwarded-for') && {
218
- 'X-Forwarded-For': request.headers.get('x-forwarded-for')!
219
- })
220
- },
271
+ headers: headersToSend,
221
272
  body: JSON.stringify(body)
222
273
  });
223
274
 
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-snapshot-ZERO-3648-20251002084215",
4
+ "version": "1.103.0-snapshot-ZERO-3648-20251002182439",
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-snapshot-ZERO-3648-20251002084215",
38
+ "@akinon/eslint-plugin-projectzero": "1.103.0-snapshot-ZERO-3648-20251002182439",
39
39
  "@babel/core": "7.26.10",
40
40
  "@babel/preset-env": "7.26.9",
41
41
  "@babel/preset-typescript": "7.27.0",