bootstrap
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
FROM node:20-alpine AS builder
|
||||
WORKDIR /app
|
||||
COPY package.json tsconfig.json vite.config.ts index.html ./
|
||||
RUN npm ci
|
||||
COPY src/ ./src/
|
||||
RUN npm run build
|
||||
|
||||
FROM nginx:alpine AS runner
|
||||
COPY --from=builder /app/dist /usr/share/nginx/html
|
||||
EXPOSE 80
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
@@ -0,0 +1,12 @@
|
||||
<!doctype html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Проверка кодов маркировки — Честный знак</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,32 @@
|
||||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
location /api/ {
|
||||
proxy_pass http://backend:3001;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
}
|
||||
|
||||
location /auth/ {
|
||||
proxy_pass http://backend:3001;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
}
|
||||
|
||||
location /health {
|
||||
proxy_pass http://backend:3001;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
}
|
||||
}
|
||||
Generated
+2914
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "chestny-znak-api-frontend",
|
||||
"private": true,
|
||||
"version": "1.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc -b && vite build",
|
||||
"preview": "vite preview",
|
||||
"lint": "tsc --noEmit",
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"react": "^19.0.0",
|
||||
"react-dom": "^19.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "^19.0.0",
|
||||
"@types/react-dom": "^19.0.0",
|
||||
"@vitejs/plugin-react": "^4.3.4",
|
||||
"typescript": "^5.7.3",
|
||||
"vite": "^6.1.0",
|
||||
"eslint": "^9.19.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
import { useState } from 'react'
|
||||
import { AuthPage } from './pages/AuthPage'
|
||||
import { CheckCodesPage } from './pages/CheckCodesPage'
|
||||
import { UploadUpdPage } from './pages/UploadUpdPage'
|
||||
|
||||
type Page = 'auth' | 'check' | 'upload'
|
||||
|
||||
export default function App() {
|
||||
const [page, setPage] = useState<Page>('auth')
|
||||
const [authenticated, setAuthenticated] = useState(false)
|
||||
|
||||
return (
|
||||
<div style={{ minHeight: '100vh', background: '#f5f5f5' }}>
|
||||
<header style={{
|
||||
background: '#1a237e',
|
||||
color: 'white',
|
||||
padding: '12px 24px',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
gap: 24,
|
||||
}}>
|
||||
<h1 style={{ fontSize: 18, margin: 0 }}>Честный знак — Проверка КМ</h1>
|
||||
<nav style={{ display: 'flex', gap: 12 }}>
|
||||
<button onClick={() => setPage('auth')}
|
||||
style={navBtnStyle(page === 'auth')}>
|
||||
Авторизация
|
||||
</button>
|
||||
<button onClick={() => setPage('check')}
|
||||
style={navBtnStyle(page === 'check')}>
|
||||
Проверка кода
|
||||
</button>
|
||||
<button onClick={() => setPage('upload')}
|
||||
style={navBtnStyle(page === 'upload')}>
|
||||
Загрузка УПД
|
||||
</button>
|
||||
</nav>
|
||||
<div style={{ marginLeft: 'auto', fontSize: 13 }}>
|
||||
{authenticated ? '✅ Авторизован' : '❌ Не авторизован'}
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main style={{ padding: 24, maxWidth: 960, margin: '0 auto' }}>
|
||||
{page === 'auth' && <AuthPage onAuth={() => setAuthenticated(true)} />}
|
||||
{page === 'check' && <CheckCodesPage />}
|
||||
{page === 'upload' && <UploadUpdPage />}
|
||||
</main>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function navBtnStyle(active: boolean): React.CSSProperties {
|
||||
return {
|
||||
background: active ? 'rgba(255,255,255,0.2)' : 'transparent',
|
||||
color: 'white',
|
||||
border: active ? '1px solid rgba(255,255,255,0.4)' : '1px solid transparent',
|
||||
borderRadius: 4,
|
||||
padding: '6px 14px',
|
||||
cursor: 'pointer',
|
||||
fontSize: 14,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
import type { CodeResult } from '../types'
|
||||
|
||||
interface Props {
|
||||
results: CodeResult[]
|
||||
}
|
||||
|
||||
export function ResultsTable({ results }: Props) {
|
||||
if (results.length === 0) return null
|
||||
|
||||
return (
|
||||
<div style={{ overflowX: 'auto' }}>
|
||||
<table style={{
|
||||
width: '100%',
|
||||
borderCollapse: 'collapse',
|
||||
fontSize: 13,
|
||||
}}>
|
||||
<thead>
|
||||
<tr style={{ background: '#1a237e', color: 'white' }}>
|
||||
<th style={thStyle}>Код маркировки</th>
|
||||
<th style={thStyle}>GTIN</th>
|
||||
<th style={thStyle}>Наименование</th>
|
||||
<th style={thStyle}>Статус</th>
|
||||
<th style={thStyle}>Производитель</th>
|
||||
<th style={thStyle}>Владелец</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{results.map((r, i) => (
|
||||
<tr key={i} style={{
|
||||
background: i % 2 === 0 ? '#fff' : '#f5f5f5',
|
||||
borderBottom: '1px solid #e0e0e0',
|
||||
}}>
|
||||
<td style={tdStyle}>
|
||||
<span style={{ fontSize: 11, wordBreak: 'break-all' }}>{r.code}</span>
|
||||
</td>
|
||||
<td style={tdStyle}>{r.gtin || '—'}</td>
|
||||
<td style={tdStyle}>{r.productName || '—'}</td>
|
||||
<td style={tdStyle}>
|
||||
<StatusBadge status={r.status} valid={r.valid} error={r.error} />
|
||||
</td>
|
||||
<td style={tdStyle}>{r.producerName || '—'}</td>
|
||||
<td style={tdStyle}>{r.ownerName || '—'}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function StatusBadge({ status, valid, error }: { status: string; valid: boolean; error?: string }) {
|
||||
if (error) {
|
||||
return <span style={{ ...badgeBase, background: '#ffebee', color: '#c62828' }}>⚠️ {error}</span>
|
||||
}
|
||||
|
||||
const colorMap: Record<string, string> = {
|
||||
INTRODUCED: '#e8f5e9',
|
||||
EMITTED: '#fff8e1',
|
||||
APPLIED: '#fff8e1',
|
||||
RETIRED: '#ffebee',
|
||||
WRITTEN_OFF: '#ffebee',
|
||||
DISAGGREGATION: '#fff3e0',
|
||||
CANCELLED: '#ffebee',
|
||||
}
|
||||
|
||||
const labelMap: Record<string, string> = {
|
||||
INTRODUCED: '✅ В обороте',
|
||||
EMITTED: '🟡 Эмитирован',
|
||||
APPLIED: '🟡 Нанесён',
|
||||
RETIRED: '❌ Выбыл',
|
||||
WRITTEN_OFF: '❌ Списан',
|
||||
DISAGGREGATION: '🟠 Расформирован',
|
||||
CANCELLED: '❌ Аннулирован',
|
||||
}
|
||||
|
||||
return (
|
||||
<span style={{
|
||||
...badgeBase,
|
||||
background: colorMap[status] || '#f5f5f5',
|
||||
color: valid ? '#2e7d32' : '#c62828',
|
||||
}}>
|
||||
{labelMap[status] || status}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
const badgeBase: React.CSSProperties = {
|
||||
display: 'inline-block',
|
||||
padding: '2px 8px',
|
||||
borderRadius: 4,
|
||||
fontSize: 12,
|
||||
fontWeight: 500,
|
||||
whiteSpace: 'nowrap',
|
||||
}
|
||||
|
||||
const thStyle: React.CSSProperties = {
|
||||
padding: '8px 12px',
|
||||
textAlign: 'left',
|
||||
fontWeight: 600,
|
||||
fontSize: 12,
|
||||
textTransform: 'uppercase',
|
||||
}
|
||||
|
||||
const tdStyle: React.CSSProperties = {
|
||||
padding: '8px 12px',
|
||||
verticalAlign: 'top',
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { StrictMode } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import App from './App'
|
||||
|
||||
createRoot(document.getElementById('root')!).render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
</StrictMode>,
|
||||
)
|
||||
@@ -0,0 +1,135 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { getAuthStatus, getAuthKey, signIn } from '../services/api'
|
||||
|
||||
interface Props {
|
||||
onAuth: () => void
|
||||
}
|
||||
|
||||
export function AuthPage({ onAuth }: Props) {
|
||||
const [status, setStatus] = useState<{ authenticated: boolean; tokenExpiresAt: string | null } | null>(null)
|
||||
const [uuid, setUuid] = useState('')
|
||||
const [dataToSign, setDataToSign] = useState('')
|
||||
const [signature, setSignature] = useState('')
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [error, setError] = useState('')
|
||||
|
||||
useEffect(() => {
|
||||
getAuthStatus().then(setStatus).catch(() => {})
|
||||
}, [])
|
||||
|
||||
async function handleGetKey() {
|
||||
setLoading(true)
|
||||
setError('')
|
||||
try {
|
||||
const { uuid, data } = await getAuthKey()
|
||||
setUuid(uuid)
|
||||
setDataToSign(data)
|
||||
} catch (err) {
|
||||
setError(String(err))
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
async function handleSignIn() {
|
||||
setLoading(true)
|
||||
setError('')
|
||||
try {
|
||||
await signIn(uuid, signature)
|
||||
const s = await getAuthStatus()
|
||||
setStatus(s)
|
||||
if (s.authenticated) onAuth()
|
||||
} catch (err) {
|
||||
setError(String(err))
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h2>Авторизация в True API</h2>
|
||||
|
||||
{status && (
|
||||
<div style={{
|
||||
padding: 12,
|
||||
background: status.authenticated ? '#e8f5e9' : '#fff3e0',
|
||||
borderRadius: 6,
|
||||
marginBottom: 16,
|
||||
}}>
|
||||
<strong>Статус:</strong>{' '}
|
||||
{status.authenticated ? '✅ Авторизован' : '❌ Не авторизован'}
|
||||
{status.tokenExpiresAt && (
|
||||
<div style={{ fontSize: 13, marginTop: 4 }}>
|
||||
Токен истекает: {new Date(status.tokenExpiresAt).toLocaleString()}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 12, maxWidth: 500 }}>
|
||||
<button onClick={handleGetKey} disabled={loading}
|
||||
style={btnStyle}>
|
||||
{loading ? 'Загрузка...' : '1. Получить ключ авторизации'}
|
||||
</button>
|
||||
|
||||
{dataToSign && (
|
||||
<div style={{ background: '#f5f5f5', padding: 8, borderRadius: 4, fontSize: 12, wordBreak: 'break-all' }}>
|
||||
<strong>Данные для подписи:</strong><br />
|
||||
{dataToSign}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{uuid && (
|
||||
<>
|
||||
<textarea
|
||||
placeholder="Вставьте подпись (base64) из КриптоПро..."
|
||||
value={signature}
|
||||
onChange={e => setSignature(e.target.value)}
|
||||
rows={4}
|
||||
style={inputStyle}
|
||||
/>
|
||||
|
||||
<button onClick={handleSignIn} disabled={loading || !signature}
|
||||
style={btnStyle}>
|
||||
{loading ? 'Подписание...' : '2. Отправить подпись'}
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
|
||||
{error && (
|
||||
<div style={{ color: '#c62828', fontSize: 14 }}>Ошибка: {error}</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div style={{ marginTop: 24, fontSize: 13, color: '#666' }}>
|
||||
<h4>Инструкция:</h4>
|
||||
<ol>
|
||||
<li>Нажмите «Получить ключ авторизации» — система получит UUID и случайные данные для подписи</li>
|
||||
<li>Подпишите полученные данные в КриптоПро (CAdES-BES, присоединённая подпись, base64)</li>
|
||||
<li>Вставьте подпись в поле выше и нажмите «Отправить подпись»</li>
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const btnStyle: React.CSSProperties = {
|
||||
background: '#1a237e',
|
||||
color: 'white',
|
||||
border: 'none',
|
||||
borderRadius: 6,
|
||||
padding: '10px 20px',
|
||||
cursor: 'pointer',
|
||||
fontSize: 14,
|
||||
}
|
||||
|
||||
const inputStyle: React.CSSProperties = {
|
||||
padding: 8,
|
||||
border: '1px solid #ccc',
|
||||
borderRadius: 4,
|
||||
fontSize: 13,
|
||||
fontFamily: 'monospace',
|
||||
width: '100%',
|
||||
boxSizing: 'border-box',
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
import { useState } from 'react'
|
||||
import { checkCodesPublic, checkCodesAuth } from '../services/api'
|
||||
import { ResultsTable } from '../components/ResultsTable'
|
||||
import type { CodeResult } from '../types'
|
||||
|
||||
export function CheckCodesPage() {
|
||||
const [codesInput, setCodesInput] = useState('')
|
||||
const [results, setResults] = useState<CodeResult[] | null>(null)
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [error, setError] = useState('')
|
||||
|
||||
async function handleCheck(mode: 'public' | 'auth') {
|
||||
const codes = codesInput
|
||||
.split(/[\n,;]+/)
|
||||
.map(c => c.trim())
|
||||
.filter(Boolean)
|
||||
|
||||
if (codes.length === 0) {
|
||||
setError('Введите хотя бы один код маркировки')
|
||||
return
|
||||
}
|
||||
|
||||
setLoading(true)
|
||||
setError('')
|
||||
try {
|
||||
const fn = mode === 'public' ? checkCodesPublic : checkCodesAuth
|
||||
const response = await fn(codes)
|
||||
setResults(response.results)
|
||||
} catch (err) {
|
||||
setError(String(err))
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h2>Проверка кодов маркировки (КМ)</h2>
|
||||
|
||||
<textarea
|
||||
placeholder="Введите коды маркировки (каждый с новой строки, через запятую или точку с запятой)"
|
||||
value={codesInput}
|
||||
onChange={e => setCodesInput(e.target.value)}
|
||||
rows={6}
|
||||
style={{
|
||||
padding: 8,
|
||||
border: '1px solid #ccc',
|
||||
borderRadius: 4,
|
||||
fontSize: 13,
|
||||
fontFamily: 'monospace',
|
||||
width: '100%',
|
||||
boxSizing: 'border-box',
|
||||
marginBottom: 12,
|
||||
}}
|
||||
/>
|
||||
|
||||
<div style={{ display: 'flex', gap: 12, marginBottom: 16 }}>
|
||||
<button onClick={() => handleCheck('public')} disabled={loading}
|
||||
style={btnStyle}>
|
||||
{loading ? 'Проверка...' : '🔓 Проверить без авторизации'}
|
||||
</button>
|
||||
<button onClick={() => handleCheck('auth')} disabled={loading}
|
||||
style={{ ...btnStyle, background: '#2e7d32' }}>
|
||||
{loading ? 'Проверка...' : '🔐 Проверить с авторизацией'}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
<div style={{ color: '#c62828', marginBottom: 12 }}>Ошибка: {error}</div>
|
||||
)}
|
||||
|
||||
{results && (
|
||||
<div>
|
||||
<div style={{ marginBottom: 12, fontSize: 14 }}>
|
||||
Всего: {results.length} |
|
||||
✅ Актуальных: {results.filter(r => r.valid).length} |
|
||||
❌ Неактуальных: {results.filter(r => !r.valid && !r.error).length} |
|
||||
⚠️ Ошибок: {results.filter(r => !!r.error).length}
|
||||
</div>
|
||||
<ResultsTable results={results} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const btnStyle: React.CSSProperties = {
|
||||
background: '#1565c0',
|
||||
color: 'white',
|
||||
border: 'none',
|
||||
borderRadius: 6,
|
||||
padding: '10px 20px',
|
||||
cursor: 'pointer',
|
||||
fontSize: 14,
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
import { useState, useRef } from 'react'
|
||||
import { uploadUpd } from '../services/api'
|
||||
import { ResultsTable } from '../components/ResultsTable'
|
||||
import type { UpdUploadResponse } from '../types'
|
||||
|
||||
export function UploadUpdPage() {
|
||||
const [file, setFile] = useState<File | null>(null)
|
||||
const [response, setResponse] = useState<UpdUploadResponse | null>(null)
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [error, setError] = useState('')
|
||||
const [dragging, setDragging] = useState(false)
|
||||
const inputRef = useRef<HTMLInputElement>(null)
|
||||
|
||||
async function handleUpload() {
|
||||
if (!file) return
|
||||
setLoading(true)
|
||||
setError('')
|
||||
try {
|
||||
const result = await uploadUpd(file)
|
||||
setResponse(result)
|
||||
} catch (err) {
|
||||
setError(String(err))
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
function handleDrop(e: React.DragEvent) {
|
||||
e.preventDefault()
|
||||
setDragging(false)
|
||||
const f = e.dataTransfer.files[0]
|
||||
if (f) setFile(f)
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h2>Загрузка УПД (формат Приказа №970 ФНС)</h2>
|
||||
|
||||
<div
|
||||
onDragOver={e => { e.preventDefault(); setDragging(true) }}
|
||||
onDragLeave={() => setDragging(false)}
|
||||
onDrop={handleDrop}
|
||||
onClick={() => inputRef.current?.click()}
|
||||
style={{
|
||||
border: `2px dashed ${dragging ? '#1a237e' : '#ccc'}`,
|
||||
borderRadius: 8,
|
||||
padding: 40,
|
||||
textAlign: 'center',
|
||||
cursor: 'pointer',
|
||||
background: dragging ? '#e8eaf6' : '#fafafa',
|
||||
marginBottom: 16,
|
||||
}}
|
||||
>
|
||||
{file ? (
|
||||
<div>
|
||||
<strong>{file.name}</strong> ({(file.size / 1024).toFixed(1)} KB)
|
||||
<br />
|
||||
<button onClick={e => { e.stopPropagation(); setFile(null) }}
|
||||
style={{ marginTop: 8, ...smallBtnStyle }}>
|
||||
Удалить
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<div>
|
||||
<div style={{ fontSize: 32, marginBottom: 8 }}>📄</div>
|
||||
<div>Перетащите XML-файл УПД сюда или нажмите для выбора</div>
|
||||
</div>
|
||||
)}
|
||||
<input
|
||||
ref={inputRef}
|
||||
type="file"
|
||||
accept=".xml"
|
||||
hidden
|
||||
onChange={e => setFile(e.target.files?.[0] || null)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<button onClick={handleUpload} disabled={loading || !file}
|
||||
style={btnStyle}>
|
||||
{loading ? 'Загрузка и проверка...' : 'Отправить и проверить коды'}
|
||||
</button>
|
||||
|
||||
{error && (
|
||||
<div style={{ color: '#c62828', marginTop: 12 }}>Ошибка: {error}</div>
|
||||
)}
|
||||
|
||||
{response && (
|
||||
<div style={{ marginTop: 16 }}>
|
||||
<div style={{
|
||||
padding: 12,
|
||||
background: '#e3f2fd',
|
||||
borderRadius: 6,
|
||||
marginBottom: 12,
|
||||
fontSize: 14,
|
||||
}}>
|
||||
<strong>Документ:</strong>{' '}
|
||||
{response.document.number || '—'} от {response.document.date || '—'}
|
||||
<br />
|
||||
<strong>Продавец:</strong> {response.document.seller || '—'}
|
||||
<br />
|
||||
<strong>Покупатель:</strong> {response.document.buyer || '—'}
|
||||
<br />
|
||||
<strong>Найдено кодов:</strong> {response.codesFound}
|
||||
<br />
|
||||
<strong>Результаты:</strong> всего {response.results.total},
|
||||
✅ {response.results.validCount},
|
||||
❌ {response.results.invalidCount},
|
||||
⚠️ {response.results.errorCount}
|
||||
</div>
|
||||
|
||||
<ResultsTable results={response.results.results} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const btnStyle: React.CSSProperties = {
|
||||
background: '#1565c0',
|
||||
color: 'white',
|
||||
border: 'none',
|
||||
borderRadius: 6,
|
||||
padding: '10px 20px',
|
||||
cursor: 'pointer',
|
||||
fontSize: 14,
|
||||
}
|
||||
|
||||
const smallBtnStyle: React.CSSProperties = {
|
||||
background: '#e53935',
|
||||
color: 'white',
|
||||
border: 'none',
|
||||
borderRadius: 4,
|
||||
padding: '4px 12px',
|
||||
cursor: 'pointer',
|
||||
fontSize: 12,
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
import type { AuthStatus, CheckCodesResponse, UpdUploadResponse } from '../types'
|
||||
|
||||
const BASE_URL = ''
|
||||
|
||||
async function request<T>(url: string, options?: RequestInit): Promise<T> {
|
||||
const res = await fetch(`${BASE_URL}${url}`, {
|
||||
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
||||
...options,
|
||||
})
|
||||
if (!res.ok) {
|
||||
const err = await res.json().catch(() => ({ error: res.statusText }))
|
||||
throw new Error(err.error || `HTTP ${res.status}`)
|
||||
}
|
||||
return res.json()
|
||||
}
|
||||
|
||||
export async function getAuthKey(): Promise<{ uuid: string; data: string }> {
|
||||
return request('/auth/key')
|
||||
}
|
||||
|
||||
export async function signIn(uuid: string, data: string): Promise<{ token: string }> {
|
||||
return request('/auth/signin', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ uuid, data }),
|
||||
})
|
||||
}
|
||||
|
||||
export async function getAuthStatus(): Promise<AuthStatus> {
|
||||
return request('/auth/status')
|
||||
}
|
||||
|
||||
export async function checkCodesPublic(codes: string[]): Promise<CheckCodesResponse> {
|
||||
return request('/api/check-codes/public', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ codes }),
|
||||
})
|
||||
}
|
||||
|
||||
export async function checkCodesAuth(codes: string[]): Promise<CheckCodesResponse> {
|
||||
return request('/api/check-codes/auth', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ codes }),
|
||||
})
|
||||
}
|
||||
|
||||
export async function uploadUpd(file: File): Promise<UpdUploadResponse> {
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
|
||||
const res = await fetch(`${BASE_URL}/api/upload-upd`, {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
})
|
||||
|
||||
if (!res.ok) {
|
||||
const err = await res.json().catch(() => ({ error: res.statusText }))
|
||||
throw new Error(err.error || `HTTP ${res.status}`)
|
||||
}
|
||||
|
||||
return res.json()
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
export interface AuthStatus {
|
||||
authenticated: boolean
|
||||
tokenExpiresAt: string | null
|
||||
}
|
||||
|
||||
export interface CodeResult {
|
||||
code: string
|
||||
found: boolean
|
||||
valid: boolean
|
||||
status: string
|
||||
gtin?: string
|
||||
productName?: string
|
||||
producerName?: string
|
||||
ownerName?: string
|
||||
error?: string
|
||||
}
|
||||
|
||||
export interface CheckCodesResponse {
|
||||
results: CodeResult[]
|
||||
total: number
|
||||
validCount: number
|
||||
invalidCount: number
|
||||
errorCount: number
|
||||
}
|
||||
|
||||
export interface UpdDocument {
|
||||
number: string | undefined
|
||||
date: string | undefined
|
||||
seller: string | undefined
|
||||
buyer: string | undefined
|
||||
fileName: string
|
||||
}
|
||||
|
||||
export interface UpdUploadResponse {
|
||||
document: UpdDocument
|
||||
codesFound: number
|
||||
results: CheckCodesResponse
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2020",
|
||||
"useDefineForClassFields": true,
|
||||
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
||||
"module": "ESNext",
|
||||
"skipLibCheck": true,
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"isolatedModules": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx",
|
||||
"strict": true,
|
||||
"noUnusedLocals": false,
|
||||
"noUnusedParameters": false,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{"root":["./src/app.tsx","./src/main.tsx","./src/components/resultstable.tsx","./src/pages/authpage.tsx","./src/pages/checkcodespage.tsx","./src/pages/uploadupdpage.tsx","./src/services/api.ts","./src/types/index.ts"],"version":"5.9.3"}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
server: {
|
||||
port: 5173,
|
||||
proxy: {
|
||||
'/api': 'http://backend:3001',
|
||||
'/auth': 'http://backend:3001',
|
||||
'/health': 'http://backend:3001',
|
||||
},
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user