@akinon/next 1.31.0-rc.2 → 1.31.1

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,28 +1,18 @@
1
1
  # @akinon/next
2
2
 
3
- ## 1.31.0-rc.2
3
+ ## 1.31.1
4
4
 
5
- ### Minor Changes
6
-
7
- - 6d4aadb: ZERO-2476: Auto install recommendenent extension
8
- - f0c23bc: ZERO-2135: add custom not found page
9
- - 495d155: ZERO-2505: findBaseDir function is united and move on to the utils
10
- - 40ad73e: ZERO-2504: add cookie filter to api client request
11
- - 495d155: ZERO-2524: Zero-cli dist checks for changes and renders it to the terminal.
12
- - 6b2972b: ZERO-2514: Fix handling of status 204 and return Commerce status code in client proxy API.
5
+ ## 1.31.0
13
6
 
14
- ## 1.31.0-rc.1
7
+ ### Minor Changes
15
8
 
16
- ## 1.31.0-rc.0
9
+ - 65ddd70: ZERO-2592: Fix regex pattern in buildCDNUrl function
10
+ - c215985: ZERO-2513:Replace the src in the incoming searchParams
11
+ - 21a0ddb: ZERO-2593: Remove body overflow in case of unmount
17
12
 
18
- ### Minor Changes
13
+ ## 1.30.2
19
14
 
20
- - 6d4aadb: ZERO-2476: Auto install recommendenent extension
21
- - f0c23bc: ZERO-2135: add custom not found page
22
- - 495d155: ZERO-2505: findBaseDir function is united and move on to the utils
23
- - 40ad73e: ZERO-2504: add cookie filter to api client request
24
- - 495d155: ZERO-2524: Zero-cli dist checks for changes and renders it to the terminal.
25
- - 6b2972b: ZERO-2514: Fix handling of status 204 and return Commerce status code in client proxy API.
15
+ ## 1.30.1
26
16
 
27
17
  ## 1.30.0
28
18
 
package/api/client.ts CHANGED
@@ -2,8 +2,6 @@ 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';
7
5
 
8
6
  interface RouteParams {
9
7
  params: {
@@ -115,14 +113,6 @@ async function proxyRequest(...args) {
115
113
 
116
114
  try {
117
115
  const request = await fetch(url, fetchOptions);
118
-
119
- // Using NextResponse.json with status 204 will cause an error
120
- if (request.status === 204) {
121
- return new Response(null, {
122
- status: 204
123
- });
124
- }
125
-
126
116
  let response = {} as any;
127
117
 
128
118
  try {
@@ -141,26 +131,20 @@ async function proxyRequest(...args) {
141
131
  );
142
132
  }
143
133
 
144
- const setCookieHeaders = req.headers.getSetCookie();
145
- const exceptCookieKeys = ['pz-locale', 'pz-currency'];
146
-
147
- const isExcludedCookie = (name: string) => exceptCookieKeys.includes(name);
148
-
149
- const filteredCookies = cookieParser
150
- .parse(setCookieHeaders)
151
- .filter((cookie) => !isExcludedCookie(cookie.name));
152
-
134
+ const setCookieHeader = request.headers.get('set-cookie');
153
135
  const responseHeaders: any = {};
154
136
 
155
- if (filteredCookies.length > 0) {
156
- responseHeaders['set-cookie'] = filteredCookies
157
- .map(formatCookieString)
158
- .join(', ');
137
+ if (setCookieHeader) {
138
+ responseHeaders['set-cookie'] = setCookieHeader;
159
139
  }
160
140
 
141
+ const statusCode = new RegExp(/^20./).test(request.status.toString())
142
+ ? 200
143
+ : request.status;
144
+
161
145
  return NextResponse.json(
162
146
  options.responseType === 'text' ? { result: response } : response,
163
- { status: request.status, headers: responseHeaders }
147
+ { status: statusCode, headers: responseHeaders }
164
148
  );
165
149
  } catch (error) {
166
150
  logger.error('Client proxy request failed', error);
@@ -1,7 +1,13 @@
1
1
  const fs = require('fs');
2
2
  const path = require('path');
3
3
  const { execSync } = require('child_process');
4
- const findBaseDir = require('../utils/find-base-dir');
4
+
5
+ function findBaseDir() {
6
+ const insideNodeModules = __dirname.includes('node_modules');
7
+ return insideNodeModules
8
+ ? process.cwd()
9
+ : path.resolve(__dirname, '../../../apps/projectzeronext');
10
+ }
5
11
 
6
12
  const BASE_DIR = findBaseDir();
7
13
  const getFullPath = (relativePath) => path.join(BASE_DIR, relativePath);
@@ -3,7 +3,16 @@
3
3
  const fs = require('fs');
4
4
  const path = require('path');
5
5
  const spawn = require('cross-spawn');
6
- const findBaseDir = require('../utils/find-base-dir');
6
+
7
+ function findBaseDir() {
8
+ const insideNodeModules = __dirname.includes('node_modules');
9
+
10
+ if (insideNodeModules) {
11
+ return path.resolve(__dirname, '../../../../');
12
+ } else {
13
+ return path.resolve(__dirname, '../../../apps/projectzeronext');
14
+ }
15
+ }
7
16
 
8
17
  const BASE_DIR = findBaseDir();
9
18
 
@@ -1,6 +1,4 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  const runScript = require('./run-script');
4
-
5
4
  runScript('pz-install-theme.js');
6
- runScript('pz-pre-check-dist.js');
package/bin/pz-predev.js CHANGED
@@ -1,7 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  const runScript = require('./run-script');
4
-
5
- runScript('pz-install-extensions.js');
6
4
  runScript('pz-check-env.js');
7
5
  runScript('pz-install-theme.js');
@@ -1,5 +1,6 @@
1
1
  'use client';
2
2
 
3
+ import React from 'react';
3
4
  import { CDNOptions } from '../types';
4
5
  import NextImage, { ImageProps as NextImageProps } from 'next/image';
5
6
  import { twMerge } from 'tailwind-merge';
@@ -99,6 +100,17 @@ export const Image = (props: ImageProps) => {
99
100
  ...restImage
100
101
  } = props;
101
102
 
103
+ const optimizeImageURL = ({ src, width }) => {
104
+ return ImageLoader({
105
+ src,
106
+ width,
107
+ quality: parseInt(String(quality), DEFAULT_QUALITY),
108
+ crop,
109
+ fill,
110
+ aspectRatio
111
+ });
112
+ };
113
+
102
114
  const hasGif = typeof src === 'string' && src.includes('.gif');
103
115
 
104
116
  if (fill && !aspectRatio) {
@@ -119,19 +131,10 @@ export const Image = (props: ImageProps) => {
119
131
  <NextImage
120
132
  {...restImage}
121
133
  width={width}
122
- src={src}
134
+ src={optimizeImageURL({ src, width })}
123
135
  sizes={sizes}
124
136
  fill={fill}
125
- loader={({ src, width }) => {
126
- return ImageLoader({
127
- src,
128
- width,
129
- quality: parseInt(String(quality), DEFAULT_QUALITY),
130
- crop,
131
- fill,
132
- aspectRatio
133
- });
134
- }}
137
+ loader={({ src, width }) => optimizeImageURL({ src, width })}
135
138
  className={imageClassName}
136
139
  {...(hasGif && { unoptimized: true })}
137
140
  {...(draggable !== undefined && { draggable })}
@@ -1,10 +1,10 @@
1
1
  'use client';
2
2
 
3
3
  import { ReactPortal } from './react-portal';
4
-
5
4
  import { Icon } from './icon';
6
5
  import { twMerge } from 'tailwind-merge';
7
6
  import { useEffect } from 'react';
7
+
8
8
  export interface ModalProps {
9
9
  portalId: string;
10
10
  children?: React.ReactNode;
@@ -27,11 +27,11 @@ export const Modal = (props: ModalProps) => {
27
27
  } = props;
28
28
 
29
29
  useEffect(() => {
30
- if (open) {
31
- document.body.style.overflow = 'hidden';
32
- } else {
30
+ document.body.style.overflow = open ? 'hidden' : 'auto';
31
+
32
+ return () => {
33
33
  document.body.style.overflow = 'auto';
34
- }
34
+ };
35
35
  }, [open]);
36
36
 
37
37
  if (!open) return null;
@@ -153,7 +153,6 @@ const withPzDefault =
153
153
 
154
154
  req.middlewareParams = {
155
155
  commerceUrl,
156
- found: true,
157
156
  rewrites: {}
158
157
  };
159
158
 
@@ -187,19 +186,6 @@ const withPzDefault =
187
186
  locale.length ? `${locale}/` : ''
188
187
  }${currency}${prettyUrl ?? pathnameWithoutLocale}`;
189
188
 
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
-
203
189
  Settings.rewrites.forEach((rewrite) => {
204
190
  url.pathname = url.pathname.replace(
205
191
  rewrite.source,
@@ -26,7 +26,6 @@ export {
26
26
  export interface PzNextRequest extends NextRequest {
27
27
  middlewareParams: {
28
28
  commerceUrl: string;
29
- found: boolean;
30
29
  rewrites: {
31
30
  locale?: string;
32
31
  prettyUrl?: string;
@@ -98,8 +98,6 @@ const withPrettyUrl =
98
98
  return middleware(req, event);
99
99
  }
100
100
 
101
- req.middlewareParams.found = false;
102
-
103
101
  return middleware(req, event);
104
102
  };
105
103
 
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.31.0-rc.2",
4
+ "version": "1.31.1",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "bin": {
@@ -25,16 +25,14 @@
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",
29
- "set-cookie-parser": "2.6.0"
28
+ "semver": "7.5.4"
30
29
  },
31
30
  "devDependencies": {
32
31
  "@types/react-redux": "7.1.30",
33
- "@types/set-cookie-parser": "2.4.7",
34
32
  "@typescript-eslint/eslint-plugin": "6.7.4",
35
33
  "@typescript-eslint/parser": "6.7.4",
36
34
  "eslint": "^8.14.0",
37
- "@akinon/eslint-plugin-projectzero": "1.31.0-rc.2",
35
+ "@akinon/eslint-plugin-projectzero": "1.31.1",
38
36
  "eslint-config-prettier": "8.5.0"
39
37
  }
40
38
  }
package/types/index.ts CHANGED
@@ -181,7 +181,6 @@ export interface Settings {
181
181
  extraPaymentTypes?: string[];
182
182
  masterpassJsUrl?: string;
183
183
  };
184
- customNotFoundEnabled: boolean;
185
184
  }
186
185
 
187
186
  export interface CacheOptions {
package/utils/index.ts CHANGED
@@ -97,6 +97,10 @@ function splitUrlByFileExtension(path: string) {
97
97
 
98
98
  export function buildCDNUrl(url: string, config?: CDNOptions) {
99
99
  const [root, fileExtension] = splitUrlByFileExtension(url);
100
+ const rootWithoutOptions = root.replace(
101
+ /_size\d+(x\d+)?|_quality\d*|_crop\w*|_upscale\d*/g,
102
+ ''
103
+ );
100
104
 
101
105
  let options = '';
102
106
 
@@ -124,7 +128,7 @@ export function buildCDNUrl(url: string, config?: CDNOptions) {
124
128
  }
125
129
  }
126
130
 
127
- return `${root}${options}${fileExtension}`;
131
+ return `${rootWithoutOptions}${options}${fileExtension}`;
128
132
  }
129
133
 
130
134
  export const urlLocaleMatcherRegex = new RegExp(
@@ -1,43 +0,0 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const projectZeroNextDir = path.join(
4
- __dirname,
5
- '../../../apps/projectzeronext'
6
- );
7
-
8
- const templatesDir = path.join(
9
- __dirname,
10
- '../../../packages/projectzero-cli/app-template'
11
- );
12
-
13
- if (fs.existsSync(templatesDir)) {
14
- fs.rmdirSync(templatesDir, { recursive: true });
15
- }
16
-
17
- function copyRecursively(src, dest) {
18
- if (path.basename(src) === 'node_modules') {
19
- return;
20
- }
21
-
22
- if (fs.existsSync(src) && fs.statSync(src).isDirectory()) {
23
- fs.mkdirSync(dest, { recursive: true });
24
- fs.readdirSync(src).forEach((childItemName) => {
25
- const childSrcPath = path.join(src, childItemName);
26
- const childDestPath = path.join(dest, childItemName);
27
- copyRecursively(childSrcPath, childDestPath);
28
- });
29
- } else {
30
- fs.copyFileSync(src, dest);
31
- }
32
- }
33
-
34
- if (!fs.existsSync(templatesDir)) {
35
- fs.mkdirSync(templatesDir, { recursive: true });
36
- }
37
-
38
- copyRecursively(projectZeroNextDir, templatesDir);
39
-
40
- console.log(
41
- '\x1b[33m%s\x1b[0m',
42
- 'projectzeronext content has been copied to templates.'
43
- );
@@ -1,27 +0,0 @@
1
- const { execSync } = require('child_process');
2
- const fs = require('fs');
3
- const path = require('path');
4
-
5
- function findBaseDir() {
6
- let currentDir = __dirname;
7
- while (currentDir !== path.resolve(currentDir, '..')) {
8
- if (fs.existsSync(path.join(currentDir, 'turbo.json'))) {
9
- return currentDir;
10
- }
11
- currentDir = path.resolve(currentDir, '..');
12
- }
13
- return null;
14
- }
15
-
16
- const BASE_DIR = findBaseDir();
17
-
18
- if (BASE_DIR) {
19
- const extensions = ['bilal-akinon.pznext'];
20
- extensions.forEach((extension) => {
21
- try {
22
- execSync(`code --install-extension ${extension}`, { stdio: 'inherit' });
23
- } catch (error) {
24
- console.error(`Error installing ${extension}:`);
25
- }
26
- });
27
- }
@@ -1,14 +0,0 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const hashDirectory = require('../utils/hash-directory');
4
-
5
- const packageDistPath = path.join(
6
- __dirname,
7
- '../../../packages/projectzero-cli/dist/commands'
8
- );
9
-
10
- const hash = hashDirectory(packageDistPath);
11
- fs.writeFileSync(
12
- path.join(__dirname, '../../../packages/projectzero-cli/dist/dist-hash.txt'),
13
- hash
14
- );
@@ -1,13 +0,0 @@
1
- const path = require('path');
2
-
3
- function findBaseDir() {
4
- const insideNodeModules = __dirname.includes('node_modules');
5
-
6
- if (insideNodeModules) {
7
- return path.resolve(__dirname, '../../../../');
8
- } else {
9
- return path.resolve(__dirname, '../../../apps/projectzeronext');
10
- }
11
- }
12
-
13
- module.exports = findBaseDir;
@@ -1,27 +0,0 @@
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
- }
@@ -1,18 +0,0 @@
1
- const { createHash } = require('crypto');
2
- const fs = require('fs');
3
- const path = require('path');
4
-
5
- function hashDirectory(directory) {
6
- const files = fs.readdirSync(directory).sort();
7
- const hash = createHash('sha256');
8
- files.forEach((file) => {
9
- const filePath = path.join(directory, file);
10
- if (fs.statSync(filePath).isFile()) {
11
- const fileBuffer = fs.readFileSync(filePath);
12
- hash.update(fileBuffer);
13
- }
14
- });
15
- return hash.digest('hex');
16
- }
17
-
18
- module.exports = hashDirectory;