@akinon/next 2.0.10-rc.0 → 2.0.11-beta.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 -22
- package/bin/pz-generate-routes.js +1 -4
- package/components/plugin-module.tsx +1 -0
- package/data/client/checkout.ts +1 -0
- package/data/server/category.ts +2 -14
- package/data/server/list.ts +1 -13
- package/data/server/product.ts +0 -10
- package/data/server/special-page.ts +1 -14
- package/data/server/widget.ts +1 -14
- package/data/urls.ts +1 -5
- package/hooks/use-captcha.tsx +1 -1
- package/middlewares/default.ts +1 -2
- package/middlewares/masterpass-rest-callback.ts +147 -34
- package/package.json +3 -4
- package/plugins.d.ts +0 -10
- package/plugins.js +0 -1
- package/redux/middlewares/checkout.ts +3 -45
- package/redux/middlewares/pre-order/installment-option.ts +1 -9
- package/types/index.ts +0 -7
- package/with-pz-config.js +1 -2
- package/bin/pz-migrate-eslint.js +0 -6
- package/codemods/migrate-eslint-flat.js +0 -247
- package/utils/payload-optimizer.ts +0 -481
|
@@ -26,28 +26,13 @@ import {
|
|
|
26
26
|
} from '../../redux/reducers/checkout';
|
|
27
27
|
import { RootState, TypedDispatch } from 'redux/store';
|
|
28
28
|
import { checkoutApi } from '../../data/client/checkout';
|
|
29
|
-
import { CheckoutContext,
|
|
29
|
+
import { CheckoutContext, PreOrder } from '../../types';
|
|
30
30
|
import { getCookie } from '../../utils';
|
|
31
31
|
import settings from 'settings';
|
|
32
32
|
import { LocaleUrlStrategy } from '../../localization';
|
|
33
33
|
import { showMobile3dIframe } from '../../utils/mobile-3d-iframe';
|
|
34
34
|
import { showRedirectionIframe } from '../../utils/redirection-iframe';
|
|
35
35
|
|
|
36
|
-
const IFRAME_REDIRECTION_KEY = 'pz-iframe-redirection-active';
|
|
37
|
-
|
|
38
|
-
const isIframeRedirectionActive = () =>
|
|
39
|
-
typeof window !== 'undefined' &&
|
|
40
|
-
sessionStorage.getItem(IFRAME_REDIRECTION_KEY) === 'true';
|
|
41
|
-
|
|
42
|
-
const setIframeRedirectionActive = (active: boolean) => {
|
|
43
|
-
if (typeof window === 'undefined') return;
|
|
44
|
-
if (active) {
|
|
45
|
-
sessionStorage.setItem(IFRAME_REDIRECTION_KEY, 'true');
|
|
46
|
-
} else {
|
|
47
|
-
sessionStorage.removeItem(IFRAME_REDIRECTION_KEY);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
|
|
51
36
|
interface CheckoutResult {
|
|
52
37
|
payload: {
|
|
53
38
|
errors?: Record<string, string[]>;
|
|
@@ -84,7 +69,7 @@ export const redirectUrlMiddleware: Middleware = () => {
|
|
|
84
69
|
const result = next(action) as CheckoutResult;
|
|
85
70
|
const redirectUrl = result?.payload?.redirect_url;
|
|
86
71
|
|
|
87
|
-
if (redirectUrl
|
|
72
|
+
if (redirectUrl) {
|
|
88
73
|
const currentLocale = getCookie('pz-locale');
|
|
89
74
|
|
|
90
75
|
let url = redirectUrl;
|
|
@@ -114,15 +99,8 @@ export const contextListMiddleware: Middleware = ({
|
|
|
114
99
|
const { isMobileApp, userPhoneNumber } = getState().root;
|
|
115
100
|
const result = next(action) as CheckoutResult;
|
|
116
101
|
const preOrder = result?.payload?.pre_order;
|
|
117
|
-
const act = action as MiddlewareAction;
|
|
118
102
|
|
|
119
103
|
if (result?.payload?.context_list) {
|
|
120
|
-
const endpointName = act.meta?.arg?.endpointName;
|
|
121
|
-
const isBinNumberResponse = endpointName === 'setBinNumber';
|
|
122
|
-
const hasCardTypeInContextList = result.payload.context_list.some(
|
|
123
|
-
(ctx) => ctx.page_context.card_type
|
|
124
|
-
);
|
|
125
|
-
|
|
126
104
|
result.payload.context_list.forEach((context) => {
|
|
127
105
|
const redirectUrl = context.page_context.redirect_url;
|
|
128
106
|
const isIframe = context.page_context.is_iframe ?? false;
|
|
@@ -156,7 +134,6 @@ export const contextListMiddleware: Middleware = ({
|
|
|
156
134
|
if (isMobileDevice && isIframePaymentOptionIncluded) {
|
|
157
135
|
showMobile3dIframe(urlObj.toString());
|
|
158
136
|
} else if (isIframe) {
|
|
159
|
-
setIframeRedirectionActive(true);
|
|
160
137
|
showRedirectionIframe(urlObj.toString());
|
|
161
138
|
} else {
|
|
162
139
|
window.location.href = urlObj.toString();
|
|
@@ -232,34 +209,15 @@ export const contextListMiddleware: Middleware = ({
|
|
|
232
209
|
(ctx) => ctx.page_name === 'DeliveryOptionSelectionPage'
|
|
233
210
|
)
|
|
234
211
|
) {
|
|
235
|
-
const isCreditCardPayment =
|
|
236
|
-
preOrder?.payment_option?.payment_type === 'credit_card' ||
|
|
237
|
-
preOrder?.payment_option?.payment_type === 'masterpass';
|
|
238
|
-
|
|
239
212
|
if (context.page_context.card_type) {
|
|
240
213
|
dispatch(setCardType(context.page_context.card_type));
|
|
241
|
-
} else if (
|
|
242
|
-
isCreditCardPayment &&
|
|
243
|
-
isBinNumberResponse &&
|
|
244
|
-
!hasCardTypeInContextList
|
|
245
|
-
) {
|
|
246
|
-
dispatch(setCardType(null));
|
|
247
|
-
dispatch(setInstallmentOptions([]));
|
|
248
214
|
}
|
|
249
215
|
|
|
250
216
|
if (
|
|
251
217
|
context.page_context.installments &&
|
|
252
218
|
preOrder?.payment_option?.payment_type !== 'masterpass_rest'
|
|
253
219
|
) {
|
|
254
|
-
|
|
255
|
-
!isCreditCardPayment ||
|
|
256
|
-
context.page_context.card_type ||
|
|
257
|
-
hasCardTypeInContextList
|
|
258
|
-
) {
|
|
259
|
-
dispatch(
|
|
260
|
-
setInstallmentOptions(context.page_context.installments)
|
|
261
|
-
);
|
|
262
|
-
}
|
|
220
|
+
dispatch(setInstallmentOptions(context.page_context.installments));
|
|
263
221
|
}
|
|
264
222
|
}
|
|
265
223
|
|
|
@@ -14,17 +14,9 @@ export const installmentOptionMiddleware: Middleware = ({
|
|
|
14
14
|
return result;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
const { installmentOptions
|
|
17
|
+
const { installmentOptions } = getState().checkout;
|
|
18
18
|
const { endpoints: apiEndpoints } = checkoutApi;
|
|
19
19
|
|
|
20
|
-
const isCreditCardPayment =
|
|
21
|
-
preOrder?.payment_option?.payment_type === 'credit_card' ||
|
|
22
|
-
preOrder?.payment_option?.payment_type === 'masterpass';
|
|
23
|
-
|
|
24
|
-
if (isCreditCardPayment && !cardType) {
|
|
25
|
-
return result;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
20
|
if (
|
|
29
21
|
!preOrder?.installment &&
|
|
30
22
|
preOrder?.payment_option?.payment_type !== 'saved_card' &&
|
package/types/index.ts
CHANGED
|
@@ -85,12 +85,6 @@ export interface Settings {
|
|
|
85
85
|
};
|
|
86
86
|
usePrettyUrlRoute?: boolean;
|
|
87
87
|
commerceUrl: string;
|
|
88
|
-
/**
|
|
89
|
-
* This option allows you to track Sentry events on the client side, in addition to server and edge environments.
|
|
90
|
-
*
|
|
91
|
-
* It overrides process.env.NEXT_PUBLIC_SENTRY_DSN and process.env.SENTRY_DSN.
|
|
92
|
-
*/
|
|
93
|
-
sentryDsn?: string;
|
|
94
88
|
redis: {
|
|
95
89
|
defaultExpirationTime: number;
|
|
96
90
|
};
|
|
@@ -223,7 +217,6 @@ export interface Settings {
|
|
|
223
217
|
separator?: string;
|
|
224
218
|
segments: PzSegmentDefinition[];
|
|
225
219
|
};
|
|
226
|
-
payloadOptimization?: import('../utils/payload-optimizer').PayloadOptimizationConfig;
|
|
227
220
|
}
|
|
228
221
|
|
|
229
222
|
export interface CacheOptions {
|
package/with-pz-config.js
CHANGED
|
@@ -69,8 +69,7 @@ const defaultConfig = {
|
|
|
69
69
|
acc[`@akinon/${plugin}`] = false;
|
|
70
70
|
return acc;
|
|
71
71
|
}, {}),
|
|
72
|
-
translations: false
|
|
73
|
-
'@opentelemetry/exporter-jaeger': false
|
|
72
|
+
translations: false
|
|
74
73
|
};
|
|
75
74
|
// Ensure webpack can resolve deps from the app's node_modules when
|
|
76
75
|
// compiling transpiled packages (e.g. @akinon/next) whose imports
|
package/bin/pz-migrate-eslint.js
DELETED
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ESLint flat config migration codemod.
|
|
3
|
-
*
|
|
4
|
-
* Converts a brand project from legacy `.eslintrc.js` to ESLint v9 flat config
|
|
5
|
-
* (`eslint.config.mjs`), consuming the shared base from
|
|
6
|
-
* `@akinon/next/eslint.config.base.mjs`.
|
|
7
|
-
*
|
|
8
|
-
* Idempotent: re-running on an already migrated project is a no-op for
|
|
9
|
-
* already-applied steps.
|
|
10
|
-
*
|
|
11
|
-
* Steps:
|
|
12
|
-
* 1. Read .eslintrc.js (if present) to detect brand-specific settings
|
|
13
|
-
* (settings.next.rootDir, custom rules).
|
|
14
|
-
* 2. Read .eslintignore (if present) to collect ignore patterns.
|
|
15
|
-
* 3. Write eslint.config.mjs (skipped if already exists).
|
|
16
|
-
* 4. Delete .eslintrc.js and .eslintignore.
|
|
17
|
-
* 5. Rewrite .lintstagedrc.js to use `eslint --fix` instead of `next lint`.
|
|
18
|
-
* 6. Patch package.json:
|
|
19
|
-
* - scripts.lint: "next lint" -> "eslint ."
|
|
20
|
-
* - eslint: ^8.x -> ^9.39.4
|
|
21
|
-
* - eslint-config-prettier: ^8.x -> ^10.1.1
|
|
22
|
-
* - remove @typescript-eslint/eslint-plugin and @typescript-eslint/parser
|
|
23
|
-
* (now provided by eslint-config-next/typescript).
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
'use strict';
|
|
27
|
-
|
|
28
|
-
const fs = require('fs');
|
|
29
|
-
const path = require('path');
|
|
30
|
-
|
|
31
|
-
const ESLINT_TARGET = '9.39.4';
|
|
32
|
-
const ESLINT_CONFIG_PRETTIER_TARGET = '10.1.1';
|
|
33
|
-
const TYPESCRIPT_ESLINT_DROP = [
|
|
34
|
-
'@typescript-eslint/eslint-plugin',
|
|
35
|
-
'@typescript-eslint/parser'
|
|
36
|
-
];
|
|
37
|
-
|
|
38
|
-
function buildFlatConfig({ rootDir, ignores, customRules }) {
|
|
39
|
-
const lines = [
|
|
40
|
-
"import { defineConfig, globalIgnores } from 'eslint/config';",
|
|
41
|
-
"import baseConfig from '@akinon/next/eslint.config.base.mjs';",
|
|
42
|
-
'',
|
|
43
|
-
'export default defineConfig([',
|
|
44
|
-
' ...baseConfig'
|
|
45
|
-
];
|
|
46
|
-
|
|
47
|
-
if (rootDir) {
|
|
48
|
-
lines[lines.length - 1] += ',';
|
|
49
|
-
lines.push(
|
|
50
|
-
' {',
|
|
51
|
-
' settings: {',
|
|
52
|
-
' next: {',
|
|
53
|
-
` rootDir: ${JSON.stringify(rootDir)}`,
|
|
54
|
-
' }',
|
|
55
|
-
' }',
|
|
56
|
-
' }'
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (customRules) {
|
|
61
|
-
lines[lines.length - 1] += ',';
|
|
62
|
-
const indented = JSON.stringify(customRules, null, 2)
|
|
63
|
-
.split('\n')
|
|
64
|
-
.map((l, i) => (i === 0 ? ' rules: ' + l : ' ' + l))
|
|
65
|
-
.join('\n');
|
|
66
|
-
lines.push(' {', indented, ' }');
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (ignores && ignores.length) {
|
|
70
|
-
lines[lines.length - 1] += ',';
|
|
71
|
-
lines.push(` globalIgnores(${JSON.stringify(ignores)})`);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
lines.push(']);', '');
|
|
75
|
-
|
|
76
|
-
return lines.join('\n');
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const LINT_STAGED_TEMPLATE = `const path = require('path');
|
|
80
|
-
|
|
81
|
-
const buildEslintCommand = (filenames) =>
|
|
82
|
-
\`eslint --fix \${filenames
|
|
83
|
-
.map((f) => \`"\${path.relative(process.cwd(), f)}"\`)
|
|
84
|
-
.join(' ')}\`;
|
|
85
|
-
|
|
86
|
-
module.exports = {
|
|
87
|
-
'**/*.(ts|tsx)': () => 'yarn tsc --noEmit',
|
|
88
|
-
'*.{js,jsx,ts,tsx}': [buildEslintCommand, 'prettier --write'],
|
|
89
|
-
'*.{css,scss}': [
|
|
90
|
-
'stylelint --fix --allow-empty-input',
|
|
91
|
-
'prettier --write',
|
|
92
|
-
'stylelint --allow-empty-input'
|
|
93
|
-
]
|
|
94
|
-
};
|
|
95
|
-
`;
|
|
96
|
-
|
|
97
|
-
function loadLegacyConfig(eslintrcPath) {
|
|
98
|
-
try {
|
|
99
|
-
delete require.cache[require.resolve(eslintrcPath)];
|
|
100
|
-
return require(eslintrcPath);
|
|
101
|
-
} catch (err) {
|
|
102
|
-
return { __parseError: err.message };
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function readIgnoreFile(eslintignorePath) {
|
|
107
|
-
if (!fs.existsSync(eslintignorePath)) return [];
|
|
108
|
-
const raw = fs.readFileSync(eslintignorePath, 'utf8');
|
|
109
|
-
return raw
|
|
110
|
-
.split(/\r?\n/)
|
|
111
|
-
.map((line) => line.trim())
|
|
112
|
-
.filter((line) => line && !line.startsWith('#'))
|
|
113
|
-
.map((pattern) => (pattern.endsWith('/**') ? pattern : pattern + '/**'));
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function patchPackageJson(pkgPath) {
|
|
117
|
-
const raw = fs.readFileSync(pkgPath, 'utf8');
|
|
118
|
-
const pkg = JSON.parse(raw);
|
|
119
|
-
const changes = [];
|
|
120
|
-
|
|
121
|
-
if (pkg.scripts && typeof pkg.scripts.lint === 'string') {
|
|
122
|
-
if (/^next\s+lint\b/.test(pkg.scripts.lint.trim())) {
|
|
123
|
-
pkg.scripts.lint = 'eslint .';
|
|
124
|
-
changes.push('scripts.lint -> "eslint ."');
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const bumpDev = (name, target) => {
|
|
129
|
-
if (!pkg.devDependencies || !pkg.devDependencies[name]) return;
|
|
130
|
-
const current = pkg.devDependencies[name].replace(/^\^|^~/, '');
|
|
131
|
-
if (current === target) return;
|
|
132
|
-
pkg.devDependencies[name] = target;
|
|
133
|
-
changes.push(`devDependencies.${name} ${current} -> ${target}`);
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
bumpDev('eslint', ESLINT_TARGET);
|
|
137
|
-
bumpDev('eslint-config-prettier', ESLINT_CONFIG_PRETTIER_TARGET);
|
|
138
|
-
|
|
139
|
-
for (const dep of TYPESCRIPT_ESLINT_DROP) {
|
|
140
|
-
if (pkg.devDependencies && pkg.devDependencies[dep]) {
|
|
141
|
-
delete pkg.devDependencies[dep];
|
|
142
|
-
changes.push(`removed devDependencies.${dep}`);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
if (changes.length === 0) return { changed: false, changes };
|
|
147
|
-
|
|
148
|
-
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n', 'utf8');
|
|
149
|
-
return { changed: true, changes };
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function migrate(projectRoot) {
|
|
153
|
-
const root = path.resolve(projectRoot || process.cwd());
|
|
154
|
-
const eslintrcPath = path.join(root, '.eslintrc.js');
|
|
155
|
-
const eslintignorePath = path.join(root, '.eslintignore');
|
|
156
|
-
const flatConfigPath = path.join(root, 'eslint.config.mjs');
|
|
157
|
-
const lintStagedPath = path.join(root, '.lintstagedrc.js');
|
|
158
|
-
const packageJsonPath = path.join(root, 'package.json');
|
|
159
|
-
|
|
160
|
-
if (!fs.existsSync(packageJsonPath)) {
|
|
161
|
-
console.error(`[migrate-eslint-flat] No package.json found in ${root}`);
|
|
162
|
-
process.exit(1);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
console.log(`[migrate-eslint-flat] Project root: ${root}`);
|
|
166
|
-
const summary = [];
|
|
167
|
-
|
|
168
|
-
const legacyConfig = fs.existsSync(eslintrcPath)
|
|
169
|
-
? loadLegacyConfig(eslintrcPath)
|
|
170
|
-
: null;
|
|
171
|
-
|
|
172
|
-
if (legacyConfig && legacyConfig.__parseError) {
|
|
173
|
-
console.warn(
|
|
174
|
-
`[migrate-eslint-flat] Could not parse .eslintrc.js: ${legacyConfig.__parseError}`
|
|
175
|
-
);
|
|
176
|
-
console.warn('Continuing with default brand-template settings.');
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
const rootDir = legacyConfig?.settings?.next?.rootDir;
|
|
180
|
-
const customRules =
|
|
181
|
-
legacyConfig && legacyConfig.rules && Object.keys(legacyConfig.rules).length
|
|
182
|
-
? legacyConfig.rules
|
|
183
|
-
: null;
|
|
184
|
-
|
|
185
|
-
let ignores = readIgnoreFile(eslintignorePath);
|
|
186
|
-
if (ignores.length === 0) ignores = ['public/**'];
|
|
187
|
-
|
|
188
|
-
if (!fs.existsSync(flatConfigPath)) {
|
|
189
|
-
fs.writeFileSync(
|
|
190
|
-
flatConfigPath,
|
|
191
|
-
buildFlatConfig({ rootDir, ignores, customRules }),
|
|
192
|
-
'utf8'
|
|
193
|
-
);
|
|
194
|
-
summary.push('created eslint.config.mjs');
|
|
195
|
-
} else {
|
|
196
|
-
summary.push('eslint.config.mjs already exists (skipped)');
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
if (fs.existsSync(eslintrcPath)) {
|
|
200
|
-
fs.unlinkSync(eslintrcPath);
|
|
201
|
-
summary.push('removed .eslintrc.js');
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
if (fs.existsSync(eslintignorePath)) {
|
|
205
|
-
fs.unlinkSync(eslintignorePath);
|
|
206
|
-
summary.push('removed .eslintignore');
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
if (fs.existsSync(lintStagedPath)) {
|
|
210
|
-
const before = fs.readFileSync(lintStagedPath, 'utf8');
|
|
211
|
-
if (before !== LINT_STAGED_TEMPLATE) {
|
|
212
|
-
fs.writeFileSync(lintStagedPath, LINT_STAGED_TEMPLATE, 'utf8');
|
|
213
|
-
summary.push('rewrote .lintstagedrc.js');
|
|
214
|
-
} else {
|
|
215
|
-
summary.push('.lintstagedrc.js already up to date (skipped)');
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
const pkgResult = patchPackageJson(packageJsonPath);
|
|
220
|
-
if (pkgResult.changed) {
|
|
221
|
-
summary.push(`patched package.json (${pkgResult.changes.join(', ')})`);
|
|
222
|
-
} else {
|
|
223
|
-
summary.push('package.json already up to date (skipped)');
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
console.log('\nESLint flat config migration summary:');
|
|
227
|
-
for (const line of summary) console.log(` - ${line}`);
|
|
228
|
-
|
|
229
|
-
if (customRules) {
|
|
230
|
-
console.log(
|
|
231
|
-
`\nNote: ${Object.keys(customRules).length} custom rule(s) from the old ` +
|
|
232
|
-
'.eslintrc.js were carried over into eslint.config.mjs.\nReview if ' +
|
|
233
|
-
'they are still needed (some may already be covered by the base config).'
|
|
234
|
-
);
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
console.log('\nNext steps:');
|
|
238
|
-
console.log(' 1. yarn install');
|
|
239
|
-
console.log(' 2. yarn lint # expect 0 errors (warnings ok)');
|
|
240
|
-
console.log(' 3. yarn build # smoke test');
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
if (require.main === module) {
|
|
244
|
-
migrate(process.argv[2]);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
module.exports = { migrate };
|