@akinon/next 1.89.0-snapshot-ZERO-3343-20250508112943 → 1.89.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 +1 -9
- package/api/auth.ts +5 -49
- package/api/client.ts +1 -14
- package/components/price.tsx +2 -2
- package/middlewares/default.ts +2 -19
- package/middlewares/locale.ts +2 -5
- package/package.json +2 -2
- package/utils/get-root-hostname.ts +0 -28
package/CHANGELOG.md
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
# @akinon/next
|
|
2
2
|
|
|
3
|
-
## 1.89.0
|
|
4
|
-
|
|
5
|
-
### Minor Changes
|
|
6
|
-
|
|
7
|
-
- f8e4cac: ZERO-3343: restrict root hostname to only locale subdomains
|
|
8
|
-
- 832bee3: ZERO-3343: add domain to cookie for subdomain locale strategy
|
|
9
|
-
- 8feabe9: ZERO-3343: add custom NextAuth options support
|
|
10
|
-
- 068dc39: ZERO-3343: update get-root-hostname logic
|
|
11
|
-
- b6d5bda: ZERO-3343: update changeset config
|
|
3
|
+
## 1.89.0
|
|
12
4
|
|
|
13
5
|
## 1.88.0
|
|
14
6
|
|
package/api/auth.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NextApiRequest, NextApiResponse } from 'next';
|
|
2
|
-
import NextAuth, { Session
|
|
2
|
+
import NextAuth, { Session } from 'next-auth';
|
|
3
3
|
import CredentialProvider from 'next-auth/providers/credentials';
|
|
4
4
|
import { ROUTES } from 'routes';
|
|
5
5
|
import { URLS, user } from '../data/urls';
|
|
@@ -7,8 +7,6 @@ import Settings from 'settings';
|
|
|
7
7
|
import { urlLocaleMatcherRegex } from '../utils';
|
|
8
8
|
import logger from '@akinon/next/utils/log';
|
|
9
9
|
import { AuthError } from '../types';
|
|
10
|
-
import getRootHostname from '../utils/get-root-hostname';
|
|
11
|
-
import { LocaleUrlStrategy } from '../localization';
|
|
12
10
|
|
|
13
11
|
async function getCurrentUser(sessionId: string, currency = '') {
|
|
14
12
|
const headers = {
|
|
@@ -42,15 +40,7 @@ async function getCurrentUser(sessionId: string, currency = '') {
|
|
|
42
40
|
};
|
|
43
41
|
}
|
|
44
42
|
|
|
45
|
-
|
|
46
|
-
req: NextApiRequest,
|
|
47
|
-
res: NextApiResponse
|
|
48
|
-
) => Partial<NextAuthOptions>;
|
|
49
|
-
|
|
50
|
-
const defaultNextAuthOptions = (
|
|
51
|
-
req: NextApiRequest,
|
|
52
|
-
res: NextApiResponse
|
|
53
|
-
): NextAuthOptions => {
|
|
43
|
+
const nextAuthOptions = (req: NextApiRequest, res: NextApiResponse) => {
|
|
54
44
|
return {
|
|
55
45
|
providers: [
|
|
56
46
|
CredentialProvider({
|
|
@@ -160,13 +150,7 @@ const defaultNextAuthOptions = (
|
|
|
160
150
|
|
|
161
151
|
if (sessionId) {
|
|
162
152
|
const maxAge = 30 * 24 * 60 * 60; // 30 days in seconds
|
|
163
|
-
const
|
|
164
|
-
const rootHostname =
|
|
165
|
-
localeUrlStrategy === LocaleUrlStrategy.Subdomain
|
|
166
|
-
? getRootHostname(process.env.NEXT_PUBLIC_URL)
|
|
167
|
-
: null;
|
|
168
|
-
const domainOption = rootHostname ? `Domain=${rootHostname};` : '';
|
|
169
|
-
const cookieOptions = `Path=/; HttpOnly; Secure; Max-Age=${maxAge}; ${domainOption}`;
|
|
153
|
+
const cookieOptions = `Path=/; HttpOnly; Secure; Max-Age=${maxAge}`;
|
|
170
154
|
|
|
171
155
|
res.setHeader('Set-Cookie', [
|
|
172
156
|
`osessionid=${sessionId}; ${cookieOptions}`,
|
|
@@ -269,36 +253,8 @@ const defaultNextAuthOptions = (
|
|
|
269
253
|
};
|
|
270
254
|
};
|
|
271
255
|
|
|
272
|
-
const Auth = (
|
|
273
|
-
req
|
|
274
|
-
res: NextApiResponse,
|
|
275
|
-
customOptions?: CustomNextAuthOptions
|
|
276
|
-
) => {
|
|
277
|
-
const baseOptions = defaultNextAuthOptions(req, res);
|
|
278
|
-
const customOptionsResult = customOptions ? customOptions(req, res) : {};
|
|
279
|
-
|
|
280
|
-
const mergedOptions = {
|
|
281
|
-
...baseOptions,
|
|
282
|
-
...customOptionsResult,
|
|
283
|
-
providers: [
|
|
284
|
-
...baseOptions.providers,
|
|
285
|
-
...(customOptionsResult.providers || [])
|
|
286
|
-
],
|
|
287
|
-
callbacks: {
|
|
288
|
-
...baseOptions.callbacks,
|
|
289
|
-
...customOptionsResult.callbacks
|
|
290
|
-
},
|
|
291
|
-
events: {
|
|
292
|
-
...baseOptions.events,
|
|
293
|
-
...customOptionsResult.events
|
|
294
|
-
},
|
|
295
|
-
pages: {
|
|
296
|
-
...baseOptions.pages,
|
|
297
|
-
...customOptionsResult.pages
|
|
298
|
-
}
|
|
299
|
-
};
|
|
300
|
-
|
|
301
|
-
return NextAuth(req, res, mergedOptions);
|
|
256
|
+
const Auth = (req, res) => {
|
|
257
|
+
return NextAuth(req, res, nextAuthOptions(req, res));
|
|
302
258
|
};
|
|
303
259
|
|
|
304
260
|
export default Auth;
|
package/api/client.ts
CHANGED
|
@@ -5,8 +5,6 @@ import logger from '../utils/log';
|
|
|
5
5
|
import formatCookieString from '../utils/format-cookie-string';
|
|
6
6
|
import cookieParser from 'set-cookie-parser';
|
|
7
7
|
import { cookies } from 'next/headers';
|
|
8
|
-
import getRootHostname from '../utils/get-root-hostname';
|
|
9
|
-
import { LocaleUrlStrategy } from '../localization';
|
|
10
8
|
|
|
11
9
|
interface RouteParams {
|
|
12
10
|
params: {
|
|
@@ -192,19 +190,8 @@ async function proxyRequest(...args) {
|
|
|
192
190
|
const responseHeaders: any = {};
|
|
193
191
|
|
|
194
192
|
if (filteredCookies.length > 0) {
|
|
195
|
-
const { localeUrlStrategy } = settings.localization;
|
|
196
|
-
const rootHostname =
|
|
197
|
-
localeUrlStrategy === LocaleUrlStrategy.Subdomain
|
|
198
|
-
? getRootHostname(process.env.NEXT_PUBLIC_URL)
|
|
199
|
-
: null;
|
|
200
|
-
|
|
201
193
|
responseHeaders['set-cookie'] = filteredCookies
|
|
202
|
-
.map(
|
|
203
|
-
if (!cookie.domain && rootHostname) {
|
|
204
|
-
cookie.domain = rootHostname;
|
|
205
|
-
}
|
|
206
|
-
return formatCookieString(cookie);
|
|
207
|
-
})
|
|
194
|
+
.map(formatCookieString)
|
|
208
195
|
.join(', ');
|
|
209
196
|
}
|
|
210
197
|
|
package/components/price.tsx
CHANGED
|
@@ -55,8 +55,8 @@ export const Price = (props: NumericFormatProps & PriceProps) => {
|
|
|
55
55
|
: formattedValue;
|
|
56
56
|
|
|
57
57
|
const currentCurrencyDecimalScale = Settings.localization.currencies.find(
|
|
58
|
-
(currency) => currency
|
|
59
|
-
)
|
|
58
|
+
(currency) => currency?.code === currencyCode_
|
|
59
|
+
)?.decimalScale;
|
|
60
60
|
|
|
61
61
|
return (
|
|
62
62
|
<NumericFormat
|
package/middlewares/default.ts
CHANGED
|
@@ -19,8 +19,6 @@ import withLocale from './locale';
|
|
|
19
19
|
import logger from '../utils/log';
|
|
20
20
|
import { user } from '../data/urls';
|
|
21
21
|
import { getUrlPathWithLocale } from '../utils/localization';
|
|
22
|
-
import getRootHostname from '../utils/get-root-hostname';
|
|
23
|
-
import { LocaleUrlStrategy } from '../localization';
|
|
24
22
|
|
|
25
23
|
const withPzDefault =
|
|
26
24
|
(middleware: NextMiddleware) =>
|
|
@@ -298,7 +296,7 @@ const withPzDefault =
|
|
|
298
296
|
!req.middlewareParams.found &&
|
|
299
297
|
Settings.customNotFoundEnabled
|
|
300
298
|
) {
|
|
301
|
-
|
|
299
|
+
let pathname = url.pathname
|
|
302
300
|
.replace(/\/+$/, '')
|
|
303
301
|
.split('/');
|
|
304
302
|
url.pathname = url.pathname.replace(
|
|
@@ -343,15 +341,6 @@ const withPzDefault =
|
|
|
343
341
|
middlewareResult = NextResponse.rewrite(url);
|
|
344
342
|
}
|
|
345
343
|
|
|
346
|
-
const { localeUrlStrategy } =
|
|
347
|
-
Settings.localization;
|
|
348
|
-
|
|
349
|
-
const rootHostname =
|
|
350
|
-
localeUrlStrategy ===
|
|
351
|
-
LocaleUrlStrategy.Subdomain
|
|
352
|
-
? getRootHostname(process.env.NEXT_PUBLIC_URL)
|
|
353
|
-
: null;
|
|
354
|
-
|
|
355
344
|
if (
|
|
356
345
|
!url.pathname.startsWith(`/${currency}/orders`)
|
|
357
346
|
) {
|
|
@@ -361,7 +350,6 @@ const withPzDefault =
|
|
|
361
350
|
? locale
|
|
362
351
|
: defaultLocaleValue,
|
|
363
352
|
{
|
|
364
|
-
domain: rootHostname,
|
|
365
353
|
sameSite: 'none',
|
|
366
354
|
secure: true,
|
|
367
355
|
expires: new Date(
|
|
@@ -370,12 +358,10 @@ const withPzDefault =
|
|
|
370
358
|
}
|
|
371
359
|
);
|
|
372
360
|
}
|
|
373
|
-
|
|
374
361
|
middlewareResult.cookies.set(
|
|
375
362
|
'pz-currency',
|
|
376
363
|
currency,
|
|
377
364
|
{
|
|
378
|
-
domain: rootHostname,
|
|
379
365
|
sameSite: 'none',
|
|
380
366
|
secure: true,
|
|
381
367
|
expires: new Date(
|
|
@@ -424,10 +410,7 @@ const withPzDefault =
|
|
|
424
410
|
).json();
|
|
425
411
|
middlewareResult.cookies.set(
|
|
426
412
|
'csrftoken',
|
|
427
|
-
csrf_token
|
|
428
|
-
{
|
|
429
|
-
domain: rootHostname
|
|
430
|
-
}
|
|
413
|
+
csrf_token
|
|
431
414
|
);
|
|
432
415
|
}
|
|
433
416
|
} catch (error) {
|
package/middlewares/locale.ts
CHANGED
|
@@ -13,8 +13,7 @@ const getMatchedLocale = (pathname: string, req: PzNextRequest) => {
|
|
|
13
13
|
const { localeUrlStrategy, defaultLocaleValue } = settings.localization;
|
|
14
14
|
|
|
15
15
|
if (localeUrlStrategy === LocaleUrlStrategy.Subdomain) {
|
|
16
|
-
const host =
|
|
17
|
-
req.headers.get('x-forwarded-host') || req.headers.get('host') || '';
|
|
16
|
+
const host = req.headers.get('x-forwarded-host');
|
|
18
17
|
|
|
19
18
|
if (host) {
|
|
20
19
|
const subDomain = host.split('.')[0] || '';
|
|
@@ -45,9 +44,7 @@ const withLocale =
|
|
|
45
44
|
try {
|
|
46
45
|
const url = req.nextUrl.clone();
|
|
47
46
|
const matchedLocale = getMatchedLocale(url.pathname, req);
|
|
48
|
-
let { localeUrlStrategy } =
|
|
49
|
-
|
|
50
|
-
const { defaultLocaleValue, redirectToDefaultLocale } =
|
|
47
|
+
let { localeUrlStrategy, defaultLocaleValue, redirectToDefaultLocale } =
|
|
51
48
|
settings.localization;
|
|
52
49
|
|
|
53
50
|
localeUrlStrategy =
|
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.89.0
|
|
4
|
+
"version": "1.89.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"bin": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"set-cookie-parser": "2.6.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@akinon/eslint-plugin-projectzero": "1.89.0
|
|
34
|
+
"@akinon/eslint-plugin-projectzero": "1.89.0",
|
|
35
35
|
"@types/react-redux": "7.1.30",
|
|
36
36
|
"@types/set-cookie-parser": "2.4.7",
|
|
37
37
|
"@typescript-eslint/eslint-plugin": "6.7.4",
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import Settings from 'settings';
|
|
2
|
-
|
|
3
|
-
export default function getRootHostname(
|
|
4
|
-
url: string | undefined
|
|
5
|
-
): string | null {
|
|
6
|
-
if (!url) return null;
|
|
7
|
-
|
|
8
|
-
try {
|
|
9
|
-
const urlObj = new URL(url);
|
|
10
|
-
const hostname = urlObj.hostname;
|
|
11
|
-
const parts = hostname.split('.');
|
|
12
|
-
|
|
13
|
-
const firstPart = parts[0];
|
|
14
|
-
|
|
15
|
-
const isLocale = Settings.localization.locales.some(
|
|
16
|
-
(locale) => locale.value === firstPart
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
if (isLocale) {
|
|
20
|
-
const hostnameAfterLocale = parts.slice(1).join('.');
|
|
21
|
-
return `.${hostnameAfterLocale}`;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return `.${hostname}`;
|
|
25
|
-
} catch {
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
}
|