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