This commit is contained in:
Your Name
2026-07-13 09:23:24 +00:00
parent 51e3f3776a
commit 5c8a0c8abb
11 changed files with 405 additions and 115 deletions
+81 -2
View File
@@ -1,5 +1,5 @@
import { useState, useEffect } from 'react'
import { getAuthStatus, getAuthKey, signIn } from '../services/api'
import { getAuthStatus, getAuthKey, signIn, setTokenManually } from '../services/api'
import type { RequestError } from '../services/api'
import { isCadesPluginAvailable, listCertificates, signWithCadesPlugin } from '../services/cadesplugin'
import type { CertInfo } from '../services/cadesplugin'
@@ -13,10 +13,13 @@ export function AuthPage({ onAuth }: Props) {
const [hasPlugin, setHasPlugin] = useState<boolean | null>(null)
const [certs, setCerts] = useState<CertInfo[]>([])
const [selectedThumbprint, setSelectedThumbprint] = useState('')
const [inn, setInn] = useState('')
const [loading, setLoading] = useState(false)
const [error, setError] = useState('')
const [errorDebug, setErrorDebug] = useState<string | null>(null)
const [debugExpanded, setDebugExpanded] = useState(false)
const [manualToken, setManualToken] = useState('')
const [manualLoading, setManualLoading] = useState(false)
useEffect(() => {
getAuthStatus().then(setStatus).catch(() => {})
@@ -34,6 +37,27 @@ export function AuthPage({ onAuth }: Props) {
}
}
async function handleSetToken() {
setManualLoading(true)
setError('')
setErrorDebug(null)
setDebugExpanded(false)
try {
await setTokenManually(manualToken)
const s = await getAuthStatus()
setStatus(s)
if (s.authenticated) onAuth()
} catch (err) {
const re = err as RequestError
setError(re.message)
if (re.debugInfo) {
setErrorDebug(JSON.stringify(re.debugInfo, null, 2))
}
} finally {
setManualLoading(false)
}
}
async function handleSignIn() {
setLoading(true)
setError('')
@@ -42,7 +66,7 @@ export function AuthPage({ onAuth }: Props) {
try {
const { uuid, data } = await getAuthKey()
const signature = await signWithCadesPlugin(data, selectedThumbprint || undefined)
await signIn(uuid, signature)
await signIn(uuid, signature, inn || undefined)
const s = await getAuthStatus()
setStatus(s)
if (s.authenticated) onAuth()
@@ -92,6 +116,19 @@ export function AuthPage({ onAuth }: Props) {
)}
<div style={{ display: 'flex', flexDirection: 'column', gap: 12, maxWidth: 500 }}>
<div>
<label style={{ fontSize: 13, color: '#666', display: 'block', marginBottom: 4 }}>
ИНН организации:
</label>
<input
type="text"
value={inn}
onChange={e => setInn(e.target.value)}
placeholder="Введите ИНН для однозначной авторизации"
style={inputStyle}
/>
</div>
{hasPlugin && certs.length > 0 && (
<div>
<label style={{ fontSize: 13, color: '#666', display: 'block', marginBottom: 4 }}>
@@ -126,6 +163,39 @@ export function AuthPage({ onAuth }: Props) {
{loading ? 'Подписание...' : 'Подписать и войти'}
</button>
<div style={{
borderTop: '1px solid #e0e0e0',
margin: '12px 0',
paddingTop: 16,
}}>
<label style={{ fontSize: 13, color: '#666', display: 'block', marginBottom: 4 }}>
Или введите готовый токен:
</label>
<textarea
value={manualToken}
onChange={e => setManualToken(e.target.value)}
placeholder="Вставьте токен доступа к True API"
rows={3}
style={{
...inputStyle,
fontFamily: 'monospace',
fontSize: 12,
resize: 'vertical',
}}
/>
<button
onClick={handleSetToken}
disabled={manualLoading || !manualToken.trim()}
style={{
...btnStyle,
background: '#1565c0',
marginTop: 8,
}}
>
{manualLoading ? 'Сохранение...' : 'Сохранить токен'}
</button>
</div>
{error && (
<div style={{ color: '#c62828', fontSize: 14, marginTop: 8 }}>Ошибка: {error}</div>
)}
@@ -197,3 +267,12 @@ const selectStyle: React.CSSProperties = {
width: '100%',
boxSizing: 'border-box',
}
const inputStyle: React.CSSProperties = {
padding: 8,
border: '1px solid #ccc',
borderRadius: 4,
fontSize: 13,
width: '100%',
boxSizing: 'border-box',
}
+7 -4
View File
@@ -2,7 +2,7 @@ import { useState } from 'react'
import { checkCodesPublic, checkCodesAuth } from '../services/api'
import type { RequestError } from '../services/api'
import { ResultsTable } from '../components/ResultsTable'
import type { CodeResult } from '../types'
import type { CodeResult, CheckCodesResponse } from '../types'
export function CheckCodesPage() {
const [codesInput, setCodesInput] = useState('')
@@ -14,7 +14,7 @@ export function CheckCodesPage() {
async function handleCheck(mode: 'public' | 'auth') {
const codes = codesInput
.split(/[\n,;]+/)
.split('\n')
.map(c => c.trim())
.filter(Boolean)
@@ -29,8 +29,11 @@ export function CheckCodesPage() {
setDebugExpanded(false)
try {
const fn = mode === 'public' ? checkCodesPublic : checkCodesAuth
const response = await fn(codes)
const response: CheckCodesResponse = await fn(codes)
setResults(response.results)
if (response.debugInfo) {
setErrorDebug(JSON.stringify(response.debugInfo, null, 2))
}
} catch (err) {
const re = err as RequestError
setError(re.message)
@@ -47,7 +50,7 @@ export function CheckCodesPage() {
<h2>Проверка кодов маркировки (КМ)</h2>
<textarea
placeholder="Введите коды маркировки (каждый с новой строки, через запятую или точку с запятой)"
placeholder="Введите коды маркировки (каждый с новой строки)"
value={codesInput}
onChange={e => setCodesInput(e.target.value)}
rows={6}
+11 -3
View File
@@ -38,7 +38,7 @@ async function handleError(res: Response, env: ApiEnv): Promise<never> {
async function request<T>(url: string, options?: RequestInit & { env?: ApiEnv }): Promise<T> {
const reqEnv = options?.env || currentEnv
const headers: Record<string, string> = {}
if (!(options?.body instanceof FormData)) {
if (!(options?.body instanceof FormData) && options?.body) {
headers['Content-Type'] = 'application/json'
}
if (options?.headers) {
@@ -59,10 +59,10 @@ export async function getAuthKey(env?: ApiEnv): Promise<{ uuid: string; data: st
return request('/auth/key', { env })
}
export async function signIn(uuid: string, data: string, env?: ApiEnv): Promise<{ token: string }> {
export async function signIn(uuid: string, data: string, inn?: string, env?: ApiEnv): Promise<{ token: string }> {
return request('/auth/simpleSignIn', {
method: 'POST',
body: JSON.stringify({ uuid, data }),
body: JSON.stringify({ uuid, data, inn }),
env,
})
}
@@ -97,6 +97,14 @@ export async function uploadUpd(file: File, env?: ApiEnv): Promise<UpdUploadResp
return request('/api/upload-upd', { method: 'POST', body: formData, env })
}
export async function setTokenManually(token: string, env?: ApiEnv): Promise<void> {
await request('/auth/setToken', {
method: 'POST',
body: JSON.stringify({ token }),
env,
})
}
export async function getPlansList(): Promise<{ name: string; path: string; size: number }[]> {
return request('/api/plans')
}
+5 -2
View File
@@ -23,6 +23,7 @@ export interface CheckCodesResponse {
validCount: number
invalidCount: number
errorCount: number
debugInfo?: ApiDebugInfo
}
export interface UpdDocument {
@@ -33,7 +34,7 @@ export interface UpdDocument {
fileName: string
}
export interface ApiErrorLog {
export interface ApiDebugInfo {
request: {
method: string
url: string
@@ -44,12 +45,14 @@ export interface ApiErrorLog {
statusCode: number
headers: Record<string, string>
body: unknown
errorCode?: string
errorMessage?: string
}
}
export interface ApiErrorResponse {
error: string
debugInfo?: ApiErrorLog
debugInfo?: ApiDebugInfo
}
export interface UpdUploadResponse {