@akinon/next 1.94.0 → 1.95.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 +8 -0
- package/middlewares/checkout-provider.ts +1 -1
- package/middlewares/url-redirection.ts +1 -1
- package/package.json +2 -2
- package/sentry/index.ts +54 -17
- package/types/index.ts +8 -0
- package/utils/index.ts +34 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @akinon/next
|
|
2
2
|
|
|
3
|
+
## 1.95.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 35dfb8f: ZERO-3363: Refactor URL handling in checkout and redirection middlewares to use url.origin instead of process.env.NEXT_PUBLIC_URL
|
|
8
|
+
- 99b6e7b: ZERO-3421: Enhance Sentry error handling by adding network error detection logic and refining initialization options
|
|
9
|
+
- cbdb5c1: ZERO-3448: fix set cookie domain handling for subdomain locale strategy
|
|
10
|
+
|
|
3
11
|
## 1.94.0
|
|
4
12
|
|
|
5
13
|
### Minor Changes
|
|
@@ -64,7 +64,7 @@ const withCheckoutProvider =
|
|
|
64
64
|
const location = request.headers.get('location');
|
|
65
65
|
const redirectUrl = new URL(
|
|
66
66
|
request.headers.get('location'),
|
|
67
|
-
location.startsWith('http') ? '' :
|
|
67
|
+
location.startsWith('http') ? '' : url.origin
|
|
68
68
|
);
|
|
69
69
|
|
|
70
70
|
redirectUrl.pathname = getUrlPathWithLocale(
|
|
@@ -50,7 +50,7 @@ const withUrlRedirection =
|
|
|
50
50
|
const location = request.headers.get('location');
|
|
51
51
|
const redirectUrl = new URL(
|
|
52
52
|
request.headers.get('location'),
|
|
53
|
-
location.startsWith('http') ? '' :
|
|
53
|
+
location.startsWith('http') ? '' : url.origin
|
|
54
54
|
);
|
|
55
55
|
|
|
56
56
|
redirectUrl.pathname = getUrlPathWithLocale(
|
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.
|
|
4
|
+
"version": "1.95.0",
|
|
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.
|
|
37
|
+
"@akinon/eslint-plugin-projectzero": "1.95.0",
|
|
38
38
|
"@babel/core": "7.26.10",
|
|
39
39
|
"@babel/preset-env": "7.26.9",
|
|
40
40
|
"@babel/preset-typescript": "7.27.0",
|
package/sentry/index.ts
CHANGED
|
@@ -13,36 +13,73 @@ const ALLOWED_CLIENT_LOG_TYPES: ClientLogType[] = [
|
|
|
13
13
|
ClientLogType.CHECKOUT
|
|
14
14
|
];
|
|
15
15
|
|
|
16
|
+
const isNetworkError = (exception: unknown): boolean => {
|
|
17
|
+
if (!(exception instanceof Error)) return false;
|
|
18
|
+
|
|
19
|
+
const networkErrorPatterns = [
|
|
20
|
+
'networkerror',
|
|
21
|
+
'failed to fetch',
|
|
22
|
+
'network request failed',
|
|
23
|
+
'network error',
|
|
24
|
+
'loading chunk',
|
|
25
|
+
'chunk load failed'
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
if (exception.name === 'NetworkError') return true;
|
|
29
|
+
|
|
30
|
+
if (exception.name === 'TypeError') {
|
|
31
|
+
return networkErrorPatterns.some((pattern) =>
|
|
32
|
+
exception.message.toLowerCase().includes(pattern)
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return networkErrorPatterns.some((pattern) =>
|
|
37
|
+
exception.message.toLowerCase().includes(pattern)
|
|
38
|
+
);
|
|
39
|
+
};
|
|
40
|
+
|
|
16
41
|
export const initSentry = (
|
|
17
42
|
type: 'Server' | 'Client' | 'Edge',
|
|
18
43
|
options: Sentry.BrowserOptions | Sentry.NodeOptions | Sentry.EdgeOptions = {}
|
|
19
44
|
) => {
|
|
20
|
-
// TODO:
|
|
45
|
+
// TODO: Remove Zero Project DSN
|
|
21
46
|
|
|
22
|
-
|
|
47
|
+
const baseConfig = {
|
|
23
48
|
dsn:
|
|
24
|
-
options.dsn ||
|
|
25
49
|
SENTRY_DSN ||
|
|
50
|
+
options.dsn ||
|
|
26
51
|
'https://d8558ef8997543deacf376c7d8d7cf4b@o64293.ingest.sentry.io/4504338423742464',
|
|
27
52
|
initialScope: {
|
|
28
53
|
tags: {
|
|
29
54
|
APP_TYPE: 'ProjectZeroNext',
|
|
30
|
-
TYPE: type
|
|
55
|
+
TYPE: type,
|
|
56
|
+
...((options.initialScope as any)?.tags || {})
|
|
31
57
|
}
|
|
32
58
|
},
|
|
33
59
|
tracesSampleRate: 0,
|
|
34
|
-
integrations: []
|
|
35
|
-
|
|
36
|
-
if (
|
|
37
|
-
type === 'Client' &&
|
|
38
|
-
!ALLOWED_CLIENT_LOG_TYPES.includes(
|
|
39
|
-
event.tags?.LOG_TYPE as ClientLogType
|
|
40
|
-
)
|
|
41
|
-
) {
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
60
|
+
integrations: []
|
|
61
|
+
};
|
|
44
62
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
})
|
|
63
|
+
if (type === 'Server' || type === 'Edge') {
|
|
64
|
+
Sentry.init(baseConfig);
|
|
65
|
+
} else if (type === 'Client') {
|
|
66
|
+
Sentry.init({
|
|
67
|
+
...baseConfig,
|
|
68
|
+
beforeSend: (event, hint) => {
|
|
69
|
+
if (
|
|
70
|
+
!ALLOWED_CLIENT_LOG_TYPES.includes(
|
|
71
|
+
event.tags?.LOG_TYPE as ClientLogType
|
|
72
|
+
)
|
|
73
|
+
) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (isNetworkError(hint?.originalException)) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return event;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
48
85
|
};
|
package/types/index.ts
CHANGED
|
@@ -218,6 +218,14 @@ export interface CacheOptions {
|
|
|
218
218
|
useProxy?: boolean;
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
+
export interface SetCookieOptions {
|
|
222
|
+
expires?: number; // days
|
|
223
|
+
path?: string;
|
|
224
|
+
domain?: string;
|
|
225
|
+
secure?: boolean;
|
|
226
|
+
sameSite?: 'strict' | 'lax' | 'none';
|
|
227
|
+
}
|
|
228
|
+
|
|
221
229
|
export interface ClientRequestOptions {
|
|
222
230
|
useTrailingSlash?: boolean;
|
|
223
231
|
useFormData?: boolean;
|
package/utils/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import settings from 'settings';
|
|
2
2
|
import { LocaleUrlStrategy } from '../localization';
|
|
3
|
-
import { CDNOptions, ClientRequestOptions } from '../types';
|
|
3
|
+
import { CDNOptions, ClientRequestOptions, SetCookieOptions } from '../types';
|
|
4
|
+
import getRootHostname from './get-root-hostname';
|
|
4
5
|
|
|
5
6
|
export * from './get-currency';
|
|
6
7
|
export * from './menu-generator';
|
|
@@ -20,14 +21,40 @@ export function getCookie(name: string) {
|
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
export function setCookie(
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
export function setCookie(
|
|
25
|
+
name: string,
|
|
26
|
+
value: string,
|
|
27
|
+
options: SetCookieOptions = {}
|
|
28
|
+
) {
|
|
29
|
+
const cookieParts = [`${name}=${value}`];
|
|
30
|
+
|
|
31
|
+
if (options.expires) {
|
|
32
|
+
const date = new Date();
|
|
33
|
+
date.setTime(date.getTime() + options.expires * 24 * 60 * 60 * 1000);
|
|
34
|
+
cookieParts.push(`expires=${date.toUTCString()}`);
|
|
35
|
+
}
|
|
26
36
|
|
|
27
|
-
|
|
37
|
+
cookieParts.push(`path=${options.path ?? '/'}`);
|
|
28
38
|
|
|
29
|
-
|
|
30
|
-
|
|
39
|
+
if (options.secure) {
|
|
40
|
+
cookieParts.push('secure');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (options.sameSite) {
|
|
44
|
+
cookieParts.push(`sameSite=${options.sameSite}`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const domain =
|
|
48
|
+
options.domain ??
|
|
49
|
+
(settings.localization.localeUrlStrategy === LocaleUrlStrategy.Subdomain
|
|
50
|
+
? getRootHostname(document.location.href)
|
|
51
|
+
: null);
|
|
52
|
+
|
|
53
|
+
if (domain) {
|
|
54
|
+
cookieParts.push(`domain=${domain}`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
document.cookie = cookieParts.join('; ');
|
|
31
58
|
}
|
|
32
59
|
|
|
33
60
|
export function removeCookie(name: string) {
|
|
@@ -152,9 +179,6 @@ export function buildCDNUrl(url: string, config?: CDNOptions) {
|
|
|
152
179
|
return `${rootWithoutOptions}${options}${fileExtension}`;
|
|
153
180
|
}
|
|
154
181
|
|
|
155
|
-
const { locales, localeUrlStrategy, defaultLocaleValue } =
|
|
156
|
-
settings.localization;
|
|
157
|
-
|
|
158
182
|
export const urlLocaleMatcherRegex = new RegExp(
|
|
159
183
|
`^/(${settings.localization.locales
|
|
160
184
|
.filter((l) =>
|