@akinon/next 1.26.0-rc.1 → 1.26.0-rc.10

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,96 @@
1
1
  # @akinon/next
2
2
 
3
+ ## 1.26.0-rc.10
4
+
5
+ ### Patch Changes
6
+
7
+ - @akinon/eslint-plugin-projectzero@1.26.0-rc.10
8
+
9
+ ## 1.26.0-rc.9
10
+
11
+ ### Minor Changes
12
+
13
+ - 6d4aadb: ZERO-2476: Auto install recommendenent extension
14
+ - a7e432f: ZERO-2534: Fix for recapthca regex for replacing the special chars.
15
+ - 02fa342: ZERO-2507: Add web vitals endpoint
16
+ - 7e41bdc: BRDG-9158: Remove redirect-three-d page endpoint
17
+ - f0c23bc: ZERO-2135: add custom not found page
18
+ - 1289982: ZERO-2521: Add x-forwarded-for header to requests
19
+ - 3690d3b: ZERO-2485: Check ESLint peerDependency version
20
+ - 40ad73e: ZERO-2504: add cookie filter to api client request
21
+ - b4452e9: ZERO-2463: Refactor Sentry initialization and add Sentry DSN option to settings
22
+ - b2da5e4: Revert ZERO-2435
23
+ - f76f079: ZERO-2493: Add redirect util function
24
+ - d6d2533: ZERO-2560: Add installment count to masterpass payment forms
25
+ - ff89630: ZERO-2498: Add script for env control
26
+
27
+ ### Patch Changes
28
+
29
+ - da1e501: ZERO-2296: Fix ROUTES import
30
+ - 073fbd2: ZERO-2503: Add check changeset control script
31
+ - 2e44646: ZERO-2434: Fix category URL in getCategoryDataHandler function
32
+ - 183674f: BRDG-9158: Handle locale prefix
33
+ - 8c7f5bc: ZERO-2440: Pipeline test
34
+ - Updated dependencies [073fbd2]
35
+ - @akinon/eslint-plugin-projectzero@1.26.0-rc.9
36
+
37
+ ## 1.26.0-rc.8
38
+
39
+ ### Minor Changes
40
+
41
+ - f0c23bc: ZERO-2135: add custom not found page
42
+
43
+ ### Patch Changes
44
+
45
+ - @akinon/eslint-plugin-projectzero@1.26.0-rc.8
46
+
47
+ ## 1.26.0-rc.7
48
+
49
+ ### Patch Changes
50
+
51
+ - @akinon/eslint-plugin-projectzero@1.26.0-rc.7
52
+
53
+ ## 1.26.0-rc.6
54
+
55
+ ### Minor Changes
56
+
57
+ - 40ad73e: ZERO-2504: add cookie filter to api client request
58
+
59
+ ### Patch Changes
60
+
61
+ - @akinon/eslint-plugin-projectzero@1.26.0-rc.6
62
+
63
+ ## 1.26.0-rc.5
64
+
65
+ ### Patch Changes
66
+
67
+ - @akinon/eslint-plugin-projectzero@1.26.0-rc.5
68
+
69
+ ## 1.26.0-rc.4
70
+
71
+ ### Patch Changes
72
+
73
+ - @akinon/eslint-plugin-projectzero@1.26.0-rc.4
74
+
75
+ ## 1.26.0-rc.3
76
+
77
+ ### Minor Changes
78
+
79
+ - d6d2533: ZERO-2560: Add installment count to masterpass payment forms
80
+ - ff89630: ZERO-2498: Add script for env control
81
+
82
+ ### Patch Changes
83
+
84
+ - 073fbd2: ZERO-2503: Add check changeset control script
85
+ - Updated dependencies [073fbd2]
86
+ - @akinon/eslint-plugin-projectzero@1.26.0-rc.3
87
+
88
+ ## 1.26.0-rc.2
89
+
90
+ ### Patch Changes
91
+
92
+ - @akinon/eslint-plugin-projectzero@1.26.0-rc.2
93
+
3
94
  ## 1.26.0-rc.1
4
95
 
5
96
  ### Minor Changes
package/api/client.ts CHANGED
@@ -2,6 +2,8 @@ import { ClientRequestOptions } from '../types';
2
2
  import { NextResponse } from 'next/server';
3
3
  import settings from 'settings';
4
4
  import logger from '../utils/log';
5
+ import formatCookieString from '../utils/format-cookie-string';
6
+ import cookieParser from 'set-cookie-parser';
5
7
 
6
8
  interface RouteParams {
7
9
  params: {
@@ -131,11 +133,21 @@ async function proxyRequest(...args) {
131
133
  );
132
134
  }
133
135
 
134
- const setCookieHeader = request.headers.get('set-cookie');
136
+ const setCookieHeaders = req.headers.getSetCookie();
137
+ const exceptCookieKeys = ['pz-locale', 'pz-currency'];
138
+
139
+ const isExcludedCookie = (name: string) => exceptCookieKeys.includes(name);
140
+
141
+ const filteredCookies = cookieParser
142
+ .parse(setCookieHeaders)
143
+ .filter((cookie) => !isExcludedCookie(cookie.name));
144
+
135
145
  const responseHeaders: any = {};
136
146
 
137
- if (setCookieHeader) {
138
- responseHeaders['set-cookie'] = setCookieHeader;
147
+ if (filteredCookies.length > 0) {
148
+ responseHeaders['set-cookie'] = filteredCookies
149
+ .map(formatCookieString)
150
+ .join(', ');
139
151
  }
140
152
 
141
153
  const statusCode = new RegExp(/^20./).test(request.status.toString())
@@ -0,0 +1,15 @@
1
+ import { NextResponse } from 'next/server';
2
+ import { trace, context } from '@opentelemetry/api';
3
+
4
+ export async function POST(req: Request) {
5
+ const { name, value, rating, page, pathname } = await req.json();
6
+ const span = trace.getSpan(context.active());
7
+
8
+ span?.setAttribute('page', page);
9
+ span?.setAttribute(name, value);
10
+ span?.setAttribute('rating', rating);
11
+ span?.setAttribute('pathname', pathname);
12
+ span?.end();
13
+
14
+ return NextResponse.json({ success: true });
15
+ }
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('fs');
4
+
5
+ const invalidEnvList = [
6
+ { key: 'NEXT_TELEMETRY_DISABLED', value: 1 },
7
+ { key: 'OTEL_SDK_DISABLED', value: true }
8
+ ];
9
+
10
+ function checkEnv(invalidEnvList) {
11
+ if (!fs.existsSync('.env')) {
12
+ return false;
13
+ }
14
+
15
+ const envContent = fs.readFileSync('.env', 'utf8');
16
+
17
+ invalidEnvList.forEach(({ key, value }) => {
18
+ const env = `${key}=${value}`;
19
+
20
+ if (envContent.includes(env)) {
21
+ console.error(`Remove the ${key} environment variable`);
22
+ process.exit(1);
23
+ }
24
+ });
25
+ }
26
+
27
+ checkEnv(invalidEnvList);
package/bin/pz-predev.js CHANGED
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  const runScript = require('./run-script');
4
-
5
- runScript('pz-install-extensions.js');
4
+ runScript('pz-check-env.js');
6
5
  runScript('pz-install-theme.js');
@@ -2,6 +2,7 @@ import 'server-only';
2
2
  import ClientRoot from './client-root';
3
3
  import { cookies } from 'next/headers';
4
4
  import PzProviders from './pz-providers';
5
+ import { WebVitals } from './web-vitals';
5
6
 
6
7
  export default function PzRoot({
7
8
  translations,
@@ -15,6 +16,7 @@ export default function PzRoot({
15
16
 
16
17
  return (
17
18
  <PzProviders translations={translations}>
19
+ <WebVitals />
18
20
  <ClientRoot sessionId={sessionid}>{children}</ClientRoot>
19
21
  </PzProviders>
20
22
  );
@@ -0,0 +1,33 @@
1
+ 'use client';
2
+
3
+ import { useReportWebVitals } from 'next/web-vitals';
4
+ import { useSelectedLayoutSegment } from 'next/navigation';
5
+ import { usePathname } from 'next/navigation';
6
+
7
+ export function WebVitals() {
8
+ let layoutSegment = useSelectedLayoutSegment();
9
+ const pathname = usePathname();
10
+
11
+ if (pathname === '/' && layoutSegment === null) {
12
+ layoutSegment = 'home';
13
+ }
14
+
15
+ useReportWebVitals((metric) => {
16
+ if (process.env.NODE_ENV !== 'development') {
17
+ return;
18
+ }
19
+
20
+ const { name, value, rating } = metric;
21
+ const page = layoutSegment || 'unknown';
22
+
23
+ fetch(`${process.env.NEXT_PUBLIC_URL}/api/web-vitals`, {
24
+ method: 'POST',
25
+ headers: {
26
+ 'Content-Type': 'application/json'
27
+ },
28
+ body: JSON.stringify({ name, value, rating, page, pathname })
29
+ });
30
+ });
31
+
32
+ return null;
33
+ }
@@ -103,7 +103,8 @@ const completeMasterpassPayment = async (
103
103
  merchantId: credentials?.merchant_id ?? null,
104
104
  msisdn,
105
105
  amount: preOrder?.unpaid_amount?.replace('.', '') ?? '',
106
- additionalParams: additionalParams ?? extras?.additionalParams
106
+ additionalParams: additionalParams ?? extras?.additionalParams,
107
+ installmentCount: preOrder?.installment?.installment_count ?? 1
107
108
  };
108
109
 
109
110
  const form = isDirectPurchase
@@ -153,6 +153,7 @@ const withPzDefault =
153
153
 
154
154
  req.middlewareParams = {
155
155
  commerceUrl,
156
+ found: true,
156
157
  rewrites: {}
157
158
  };
158
159
 
@@ -186,6 +187,19 @@ const withPzDefault =
186
187
  locale.length ? `${locale}/` : ''
187
188
  }${currency}${prettyUrl ?? pathnameWithoutLocale}`;
188
189
 
190
+ if (
191
+ !req.middlewareParams.found &&
192
+ Settings.customNotFoundEnabled
193
+ ) {
194
+ let pathname = url.pathname
195
+ .replace(/\/+$/, '')
196
+ .split('/');
197
+ url.pathname = url.pathname.replace(
198
+ pathname.pop(),
199
+ 'pz-not-found'
200
+ );
201
+ }
202
+
189
203
  Settings.rewrites.forEach((rewrite) => {
190
204
  url.pathname = url.pathname.replace(
191
205
  rewrite.source,
@@ -26,6 +26,7 @@ export {
26
26
  export interface PzNextRequest extends NextRequest {
27
27
  middlewareParams: {
28
28
  commerceUrl: string;
29
+ found: boolean;
29
30
  rewrites: {
30
31
  locale?: string;
31
32
  prettyUrl?: string;
@@ -98,6 +98,8 @@ const withPrettyUrl =
98
98
  return middleware(req, event);
99
99
  }
100
100
 
101
+ req.middlewareParams.found = false;
102
+
101
103
  return middleware(req, event);
102
104
  };
103
105
 
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.26.0-rc.1",
4
+ "version": "1.26.0-rc.10",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "bin": {
@@ -25,14 +25,16 @@
25
25
  "react-redux": "8.1.3",
26
26
  "react-string-replace": "1.1.1",
27
27
  "redis": "4.5.1",
28
- "semver": "7.5.4"
28
+ "semver": "7.5.4",
29
+ "set-cookie-parser": "2.6.0"
29
30
  },
30
31
  "devDependencies": {
32
+ "@akinon/eslint-plugin-projectzero": "1.24.0",
31
33
  "@types/react-redux": "7.1.30",
34
+ "@types/set-cookie-parser": "2.4.7",
32
35
  "@typescript-eslint/eslint-plugin": "6.7.4",
33
36
  "@typescript-eslint/parser": "6.7.4",
34
37
  "eslint": "^8.14.0",
35
- "@akinon/eslint-plugin-projectzero": "1.24.0",
36
38
  "eslint-config-prettier": "8.5.0"
37
39
  },
38
40
  "peerDependencies": {
package/types/index.ts CHANGED
@@ -187,6 +187,7 @@ export interface Settings {
187
187
  extraPaymentTypes?: string[];
188
188
  masterpassJsUrl?: string;
189
189
  };
190
+ customNotFoundEnabled: boolean;
190
191
  }
191
192
 
192
193
  export interface CacheOptions {
@@ -0,0 +1,27 @@
1
+ export default function formatCookieString(cookieObj: Record<string, any>) {
2
+ const cookieParts = [`${cookieObj.name}=${cookieObj.value}`];
3
+
4
+ if (cookieObj.expires) {
5
+ cookieParts.push(`Expires=${cookieObj.expires.toUTCString()}`);
6
+ }
7
+ if (cookieObj.maxAge) {
8
+ cookieParts.push(`Max-Age=${cookieObj.maxAge}`);
9
+ }
10
+ if (cookieObj.path) {
11
+ cookieParts.push(`Path=${cookieObj.path}`);
12
+ }
13
+ if (cookieObj.domain) {
14
+ cookieParts.push(`Domain=${cookieObj.domain}`);
15
+ }
16
+ if (cookieObj.secure) {
17
+ cookieParts.push('Secure');
18
+ }
19
+ if (cookieObj.httpOnly) {
20
+ cookieParts.push('HttpOnly');
21
+ }
22
+ if (cookieObj.sameSite) {
23
+ cookieParts.push(`SameSite=${cookieObj.sameSite}`);
24
+ }
25
+
26
+ return cookieParts.join('; ');
27
+ }