@djangocfg/layouts 2.1.666 → 2.1.668
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/package.json +14 -14
- package/src/components/errors/ErrorsTracker/providers/ErrorTrackingProvider.test.tsx +51 -0
- package/src/components/errors/ErrorsTracker/providers/ErrorTrackingProvider.tsx +1 -1
- package/src/components/errors/ErrorsTracker/types.ts +2 -0
- package/src/components/errors/ErrorsTracker/utils/formatters.ts +6 -0
- package/src/layouts/AppLayout/BaseApp.tsx +5 -1
- package/src/layouts/AuthLayout/components/steps/OTPStep.test.tsx +83 -0
- package/src/layouts/AuthLayout/components/steps/OTPStep.tsx +0 -6
- package/src/layouts/AuthLayout/shells/AuthShell.tsx +1 -1
- package/src/layouts/AuthLayout/styles/auth.css +0 -15
- package/src/utils/config.ts +1 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@djangocfg/layouts",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.668",
|
|
4
4
|
"description": "Simple, straightforward layout components for Next.js - import and use with props",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"layouts",
|
|
@@ -91,12 +91,12 @@
|
|
|
91
91
|
"test": "vitest run"
|
|
92
92
|
},
|
|
93
93
|
"peerDependencies": {
|
|
94
|
-
"@djangocfg/analytics": "^2.1.
|
|
95
|
-
"@djangocfg/api": "^2.1.
|
|
96
|
-
"@djangocfg/devtools": "^2.1.
|
|
97
|
-
"@djangocfg/i18n": "^2.1.
|
|
98
|
-
"@djangocfg/realtime": "^2.1.
|
|
99
|
-
"@djangocfg/ui-core": "^2.1.
|
|
94
|
+
"@djangocfg/analytics": "^2.1.668",
|
|
95
|
+
"@djangocfg/api": "^2.1.668",
|
|
96
|
+
"@djangocfg/devtools": "^2.1.668",
|
|
97
|
+
"@djangocfg/i18n": "^2.1.668",
|
|
98
|
+
"@djangocfg/realtime": "^2.1.668",
|
|
99
|
+
"@djangocfg/ui-core": "^2.1.668",
|
|
100
100
|
"@hookform/resolvers": "^5.2.2 || ^7.0.2",
|
|
101
101
|
"@tanstack/react-query": "^5.108.2",
|
|
102
102
|
"consola": "^3.4.2",
|
|
@@ -123,13 +123,13 @@
|
|
|
123
123
|
"qrcode.react": "^4.2.0"
|
|
124
124
|
},
|
|
125
125
|
"devDependencies": {
|
|
126
|
-
"@djangocfg/analytics": "^2.1.
|
|
127
|
-
"@djangocfg/api": "^2.1.
|
|
128
|
-
"@djangocfg/devtools": "^2.1.
|
|
129
|
-
"@djangocfg/i18n": "^2.1.
|
|
130
|
-
"@djangocfg/realtime": "^2.1.
|
|
131
|
-
"@djangocfg/typescript-config": "^2.1.
|
|
132
|
-
"@djangocfg/ui-core": "^2.1.
|
|
126
|
+
"@djangocfg/analytics": "^2.1.668",
|
|
127
|
+
"@djangocfg/api": "^2.1.668",
|
|
128
|
+
"@djangocfg/devtools": "^2.1.668",
|
|
129
|
+
"@djangocfg/i18n": "^2.1.668",
|
|
130
|
+
"@djangocfg/realtime": "^2.1.668",
|
|
131
|
+
"@djangocfg/typescript-config": "^2.1.668",
|
|
132
|
+
"@djangocfg/ui-core": "^2.1.668",
|
|
133
133
|
"@storybook/react-vite": "^10.6.5",
|
|
134
134
|
"@tanstack/react-query": "5.108.2",
|
|
135
135
|
"@types/node": "^25.9.5",
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import React, { act } from 'react';
|
|
3
|
+
import { createRoot } from 'react-dom/client';
|
|
4
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
5
|
+
|
|
6
|
+
const { showError } = vi.hoisted(() => ({ showError: vi.fn() }));
|
|
7
|
+
vi.mock('@djangocfg/ui-core/hooks', () => ({ toast: { error: showError } }));
|
|
8
|
+
vi.mock('@djangocfg/devtools', () => ({
|
|
9
|
+
useDebugMode: () => false,
|
|
10
|
+
isProduction: true,
|
|
11
|
+
EventType: { ERROR: 'error', NETWORK_ERROR: 'network_error', JS_ERROR: 'js_error' },
|
|
12
|
+
EventLevel: { WARNING: 'warning', ERROR: 'error' },
|
|
13
|
+
}));
|
|
14
|
+
vi.mock('../components/ErrorToast', () => ({ createErrorToast: vi.fn() }));
|
|
15
|
+
|
|
16
|
+
import { ErrorTrackingProvider } from './ErrorTrackingProvider';
|
|
17
|
+
|
|
18
|
+
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
|
19
|
+
|
|
20
|
+
describe('production diagnostic references', () => {
|
|
21
|
+
afterEach(() => showError.mockClear());
|
|
22
|
+
|
|
23
|
+
it('uses the exact runtime reference in the safe validation and network toasts', () => {
|
|
24
|
+
const host = document.createElement('div');
|
|
25
|
+
const root = createRoot(host);
|
|
26
|
+
act(() => root.render(<ErrorTrackingProvider><div /></ErrorTrackingProvider>));
|
|
27
|
+
try {
|
|
28
|
+
act(() => window.dispatchEvent(new CustomEvent('zod-validation-error', {
|
|
29
|
+
detail: {
|
|
30
|
+
operation: 'GET /test/', method: 'GET', path: '/test/',
|
|
31
|
+
reference: 'ERR-VALIDATION', error: { issues: [{ code: 'invalid_type', path: ['ok'], message: 'private' }] },
|
|
32
|
+
response: { ok: 'private' }, timestamp: new Date(),
|
|
33
|
+
},
|
|
34
|
+
})));
|
|
35
|
+
expect(showError).toHaveBeenCalledWith('Invalid data received', expect.objectContaining({
|
|
36
|
+
description: 'Please try again. Reference: ERR-VALIDATION',
|
|
37
|
+
}));
|
|
38
|
+
|
|
39
|
+
act(() => window.dispatchEvent(new CustomEvent('network-error', {
|
|
40
|
+
detail: { method: 'POST', url: '/test/', reference: 'ERR-NETWORK',
|
|
41
|
+
statusCode: 503, error: 'HTTP 503', timestamp: new Date() },
|
|
42
|
+
})));
|
|
43
|
+
expect(showError).toHaveBeenCalledWith('Server error', expect.objectContaining({
|
|
44
|
+
description: "We're working on it. Reference: ERR-NETWORK",
|
|
45
|
+
}));
|
|
46
|
+
expect(showError).toHaveBeenCalledTimes(2);
|
|
47
|
+
} finally {
|
|
48
|
+
act(() => root.unmount());
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -173,7 +173,7 @@ export function ErrorTrackingProvider({
|
|
|
173
173
|
duration: toastOptions.duration,
|
|
174
174
|
});
|
|
175
175
|
} else if (!shouldThrottleProdToast(detail.type)) {
|
|
176
|
-
const errorId = generateShortErrorId();
|
|
176
|
+
const errorId = detail.reference || generateShortErrorId();
|
|
177
177
|
const { title, description } = getProductionToast(detail, errorId);
|
|
178
178
|
toast.error(title, { description, duration: config.duration });
|
|
179
179
|
}
|
|
@@ -197,6 +197,12 @@ export function getProductionToast(detail: ErrorDetail, errorId: string): { titl
|
|
|
197
197
|
};
|
|
198
198
|
case 'network': {
|
|
199
199
|
const status = detail.statusCode;
|
|
200
|
+
if (status && status >= 200 && status < 300) {
|
|
201
|
+
return {
|
|
202
|
+
title: 'Invalid server response',
|
|
203
|
+
description: `Please try again. Reference: ${errorId}`,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
200
206
|
if (status && status >= 500) {
|
|
201
207
|
return {
|
|
202
208
|
title: 'Server error',
|
|
@@ -205,7 +205,11 @@ export function BaseApp({
|
|
|
205
205
|
cors={errorTracking?.cors}
|
|
206
206
|
network={errorTracking?.network}
|
|
207
207
|
onError={errorTracking?.onError}
|
|
208
|
-
onMonitorCapture={(d) =>
|
|
208
|
+
onMonitorCapture={(d) => {
|
|
209
|
+
// Devtools owns the generated-client validation and network events.
|
|
210
|
+
// Do not create a second monitoring row.
|
|
211
|
+
if (d.type !== 'validation' && d.type !== 'network') devtools.capture(errorDetailToDevtoolsEvent(d));
|
|
212
|
+
}}
|
|
209
213
|
>
|
|
210
214
|
<ScrollToTop />
|
|
211
215
|
<Devtools {...devtoolsProps} />
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import React, { act } from 'react';
|
|
3
|
+
import { createRoot } from 'react-dom/client';
|
|
4
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
5
|
+
|
|
6
|
+
import { OTPStep } from './OTPStep';
|
|
7
|
+
|
|
8
|
+
const form = vi.hoisted(() => ({
|
|
9
|
+
identifier: 'fixture@example.com',
|
|
10
|
+
otp: '1234',
|
|
11
|
+
isLoading: false,
|
|
12
|
+
error: 'Invalid verification code',
|
|
13
|
+
isRateLimited: false,
|
|
14
|
+
rateLimitLabel: '',
|
|
15
|
+
resendSeconds: 0,
|
|
16
|
+
resendLabel: '',
|
|
17
|
+
webmail: null,
|
|
18
|
+
setOtp: vi.fn(),
|
|
19
|
+
handleOTPSubmit: vi.fn(async (event: React.FormEvent) => event.preventDefault()),
|
|
20
|
+
handleResendOTP: vi.fn(),
|
|
21
|
+
handleBackToIdentifier: vi.fn(),
|
|
22
|
+
isAutoSubmittingFromUrl: { current: false },
|
|
23
|
+
}));
|
|
24
|
+
|
|
25
|
+
vi.mock('../../context', () => ({ useAuthFormContext: () => form }));
|
|
26
|
+
vi.mock('../../../../utils', () => ({ config: { isDevelopment: true } }));
|
|
27
|
+
vi.mock('@djangocfg/api/auth', () => ({
|
|
28
|
+
AUTH_CONSTANTS: { EMAIL_OTP_LENGTH: 4, TOTP_LENGTH: 6, BACKUP_CODE_MAX_LENGTH: 12 },
|
|
29
|
+
}));
|
|
30
|
+
vi.mock('@djangocfg/i18n', () => ({
|
|
31
|
+
useAppT: () => (key: string) => key === 'layouts.auth.dev.anyCodeWorks'
|
|
32
|
+
? 'Dev Mode: Any code works'
|
|
33
|
+
: key,
|
|
34
|
+
}));
|
|
35
|
+
vi.mock('@djangocfg/ui-core/components', () => ({
|
|
36
|
+
Link: ({ children }: { children: React.ReactNode }) => <a href="/">{children}</a>,
|
|
37
|
+
OTPInput: ({ value, onChange }: { value: string; onChange: (value: string) => void }) =>
|
|
38
|
+
<input aria-label="Verification code" value={value} onChange={e => onChange(e.target.value)} />,
|
|
39
|
+
}));
|
|
40
|
+
vi.mock('../shared', async () => ({
|
|
41
|
+
...(await import('../shared/AuthContainer')),
|
|
42
|
+
...(await import('../shared/AuthHeader')),
|
|
43
|
+
...(await import('../shared/AuthButton')),
|
|
44
|
+
...(await import('../shared/AuthLink')),
|
|
45
|
+
...(await import('../shared/AuthError')),
|
|
46
|
+
...(await import('../shared/AuthOTPInput')),
|
|
47
|
+
WebmailIcon: () => null,
|
|
48
|
+
}));
|
|
49
|
+
|
|
50
|
+
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
|
51
|
+
|
|
52
|
+
let cleanup: (() => void) | undefined;
|
|
53
|
+
afterEach(() => {
|
|
54
|
+
cleanup?.();
|
|
55
|
+
cleanup = undefined;
|
|
56
|
+
form.handleOTPSubmit.mockClear();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
function render() {
|
|
60
|
+
const host = document.createElement('div');
|
|
61
|
+
document.body.append(host);
|
|
62
|
+
const root = createRoot(host);
|
|
63
|
+
act(() => root.render(<OTPStep />));
|
|
64
|
+
cleanup = () => { act(() => root.unmount()); host.remove(); };
|
|
65
|
+
return host;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
describe('OTPStep server-owned verification', () => {
|
|
69
|
+
it('does not claim a development frontend can bypass OTP verification', () => {
|
|
70
|
+
const host = render();
|
|
71
|
+
expect(host.querySelector('.auth-dev-notice')).toBeNull();
|
|
72
|
+
expect(host.textContent).not.toContain('Any code works');
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('keeps the backend error and verification action visible', () => {
|
|
76
|
+
const host = render();
|
|
77
|
+
expect(host.querySelector('[role="alert"]')?.textContent).toContain(form.error);
|
|
78
|
+
const submit = host.querySelector<HTMLButtonElement>('button[type="submit"]')!;
|
|
79
|
+
expect(submit.disabled).toBe(false);
|
|
80
|
+
act(() => submit.click());
|
|
81
|
+
expect(form.handleOTPSubmit).toHaveBeenCalledOnce();
|
|
82
|
+
});
|
|
83
|
+
});
|
|
@@ -4,7 +4,6 @@ import React, { memo, useCallback, useEffect, useMemo, useRef, useState } from '
|
|
|
4
4
|
|
|
5
5
|
import { useAppT } from '@djangocfg/i18n';
|
|
6
6
|
|
|
7
|
-
import { config } from '../../../../utils';
|
|
8
7
|
import { AUTH } from '../../constants';
|
|
9
8
|
import { useAuthFormContext } from '../../context';
|
|
10
9
|
import {
|
|
@@ -59,7 +58,6 @@ function OTPStepRaw() {
|
|
|
59
58
|
button: t('layouts.auth.otp.button'),
|
|
60
59
|
resend: t('layouts.auth.otp.resend'),
|
|
61
60
|
changeEmail: t('layouts.auth.otp.changeEmail'),
|
|
62
|
-
devMode: t('layouts.auth.dev.anyCodeWorks'),
|
|
63
61
|
}), [t]);
|
|
64
62
|
|
|
65
63
|
// "Open Gmail / Outlook / …" — jumps straight to a search for our email.
|
|
@@ -134,10 +132,6 @@ function OTPStepRaw() {
|
|
|
134
132
|
size="lg"
|
|
135
133
|
/>
|
|
136
134
|
|
|
137
|
-
{config.isDevelopment && (
|
|
138
|
-
<div className="auth-dev-notice">{content.devMode}</div>
|
|
139
|
-
)}
|
|
140
|
-
|
|
141
135
|
{webmail && (
|
|
142
136
|
<AuthButton
|
|
143
137
|
type="button"
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import React, { memo, useMemo } from 'react';
|
|
4
4
|
|
|
5
|
-
import { useImageLoader } from '@djangocfg/ui-core/hooks';
|
|
5
|
+
import { useImageLoader } from '@djangocfg/ui-core/hooks/image-loader';
|
|
6
6
|
|
|
7
7
|
import { AuthShellProvider } from './context';
|
|
8
8
|
import { CenteredShell } from './CenteredShell';
|
|
@@ -707,21 +707,6 @@ a.auth-logo:focus-visible {
|
|
|
707
707
|
color: var(--auth-muted);
|
|
708
708
|
}
|
|
709
709
|
|
|
710
|
-
/* ===== DEV NOTICE ===== */
|
|
711
|
-
|
|
712
|
-
/* Uses the shared warning surface tokens (defined for both themes) instead of
|
|
713
|
-
hardcoded amber — keeps the dev banner consistent with the rest of the
|
|
714
|
-
system and drops the manual `.dark` override. */
|
|
715
|
-
.auth-dev-notice {
|
|
716
|
-
padding: 0.5rem 0.75rem;
|
|
717
|
-
font-size: 0.75rem;
|
|
718
|
-
text-align: center;
|
|
719
|
-
color: var(--warning-foreground);
|
|
720
|
-
background: var(--warning-background);
|
|
721
|
-
border-radius: var(--auth-radius-xs);
|
|
722
|
-
border: 1px solid var(--warning-border);
|
|
723
|
-
}
|
|
724
|
-
|
|
725
710
|
/* ===== INSTRUCTION ===== */
|
|
726
711
|
|
|
727
712
|
/* ===== RESPONSIVE ===== */
|
package/src/utils/config.ts
CHANGED
|
@@ -5,8 +5,7 @@ import { isDev, isProd } from '@djangocfg/ui-core/lib';
|
|
|
5
5
|
|
|
6
6
|
export const config = {
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
* In development mode, any OTP code is accepted for authentication
|
|
8
|
+
* Frontend build mode only; the server owns authentication policy.
|
|
10
9
|
*/
|
|
11
10
|
isDevelopment: isDev,
|
|
12
11
|
isProduction: isProd,
|