ok
This commit is contained in:
@@ -12,9 +12,12 @@ import type {
|
||||
ApiDebugInfo,
|
||||
} from '../types/index.js'
|
||||
|
||||
function loggedClient(prefixUrl: string) {
|
||||
// Статусы КМ, при которых код считается действительным (в обороте)
|
||||
const VALID_STATUSES = ['INTRODUCED', 'APPLIED', 'EMITTED']
|
||||
|
||||
function loggedClient(prefixUrl?: string) {
|
||||
return got.extend({
|
||||
prefixUrl,
|
||||
...(prefixUrl ? { prefixUrl } : {}),
|
||||
responseType: 'json',
|
||||
hooks: {
|
||||
beforeRequest: [
|
||||
@@ -59,15 +62,19 @@ export async function checkCodesPublic(env: TrueApiEnv, body: CheckCodesRequest)
|
||||
while (queue.length > 0) {
|
||||
const code = queue.shift()!
|
||||
try {
|
||||
const { body: response } = await loggedClient(envUrls[env].publicCheckUrl).get<PublicCheckResponse>(
|
||||
`?code=${encodeURIComponent(code)}`,
|
||||
{ timeout: { request: 10000 } }
|
||||
// Полный URL передаём как input (без prefixUrl) + searchParams,
|
||||
// иначе got добавляет лишний слэш (.../check/?code=) → 404.
|
||||
const { body: response } = await loggedClient().get<PublicCheckResponse>(
|
||||
envUrls[env].publicCheckUrl,
|
||||
{ searchParams: { code }, timeout: { request: 10000 } }
|
||||
)
|
||||
const status = response.outerStatus || response.status || 'UNKNOWN'
|
||||
results.push({
|
||||
code: response.code,
|
||||
found: response.found,
|
||||
valid: response.valid,
|
||||
status: response.status,
|
||||
code: response.code || code,
|
||||
found: response.codeFounded ?? response.codeResolveData?.found ?? false,
|
||||
valid: VALID_STATUSES.includes(status),
|
||||
status,
|
||||
productName: response.productName,
|
||||
})
|
||||
} catch {
|
||||
results.push({
|
||||
@@ -259,7 +266,7 @@ async function retryOnError(
|
||||
results.push({
|
||||
code: ci.requestedCis,
|
||||
found: !!ci.cis && !item.errorCode,
|
||||
valid: ci.status === 'INTRODUCED' || ci.status === 'APPLIED' || ci.status === 'EMITTED',
|
||||
valid: VALID_STATUSES.includes(ci.status || ''),
|
||||
status: item.errorCode || ci.status || 'UNKNOWN',
|
||||
gtin: ci.gtin,
|
||||
productName: ci.productName,
|
||||
|
||||
@@ -38,9 +38,17 @@ export interface CisInfoResponseItem {
|
||||
|
||||
export interface PublicCheckResponse {
|
||||
code: string
|
||||
found: boolean
|
||||
valid: boolean
|
||||
status: string
|
||||
// Схема ответа mobile.api.crpt.ru/mobile/check (эндпоинт мобильного приложения)
|
||||
codeFounded?: boolean
|
||||
checkResult?: boolean
|
||||
status?: string
|
||||
outerStatus?: string
|
||||
productName?: string
|
||||
codeResolveData?: {
|
||||
valid?: boolean
|
||||
found?: boolean
|
||||
verified?: boolean
|
||||
}
|
||||
}
|
||||
|
||||
export interface CheckCodesRequest {
|
||||
|
||||
@@ -1 +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/services/cadesplugin.ts","./src/types/index.ts"],"version":"5.9.3"}
|
||||
{"root":["./src/app.tsx","./src/main.tsx","./src/components/resultstable.tsx","./src/pages/authpage.tsx","./src/pages/checkcodespage.tsx","./src/pages/planspage.tsx","./src/pages/uploadupdpage.tsx","./src/services/api.ts","./src/services/cadesplugin.ts","./src/types/index.ts"],"version":"5.9.3"}
|
||||
Reference in New Issue
Block a user