1. Bailigh sa bhrabhsálaí
Is é an lódálaí poiblí an t-aon eisiúint bhrabhsálaí atá fíoraithe faoi láthair. Aschuir sé aitheantóir gléis nó staid earráide; ní fhaigheann sé dintiúr freastalaí riamh.
<script src="https://collect.noxtica.com/collector/noxtica-collector-core.js" data-site-key="pk_example_replace_me" data-extensions="auto" data-auto-init data-auto-check-once async></script>
<script>
document.addEventListener('noxtica:collected', (event) => {
const deviceId = event.detail?.fingerprintId;
document.dispatchEvent(new CustomEvent('app:noxtica-evidence', {
detail: deviceId ? { state: 'received', deviceId } : { state: 'invalid' },
}));
});
document.addEventListener('noxtica:error', () => {
document.dispatchEvent(new CustomEvent('app:noxtica-evidence', {
detail: { state: 'unavailable' },
}));
});
</script>
2. Léigh ar do fhreastalaí
Seol an t-aitheantóir gléis chuig d'inneall cúltaca, ansin glaoigh ar an mbealach v1 fíordheimhnithe le heochair atá coinnithe ar an bhfreastalaí.
export async function lookupDevice({ deviceId, apiKey, fetchImpl = fetch }) {
const response = await fetchImpl(
`https://collect.noxtica.com/v1/device/${encodeURIComponent(deviceId)}`,
{ headers: { Authorization: `Bearer ${apiKey}` } },
);
if (response.status === 404) return { state: 'missing' };
if (response.status === 429) return { state: 'rate_limited' };
if (!response.ok) return { state: 'unavailable' };
return { state: 'received', record: await response.json() };
}
3. Coinnigh staideanna torthaí ar leithligh
Ní théann ach taifead faighte iomlán isteach sa bheartas uimhriúil. Leanann staideanna ar iarraidh, neamhbhailí, srianta de réir ráta agus nach bhfuil ar fáil cúltacaí soiléire custaiméara.
export function classifyLookup(result) {
if (!result || result.state === 'unavailable') return { state: 'unavailable' };
if (result.state === 'rate_limited') return { state: 'rate_limited' };
if (result.state === 'missing') return { state: 'missing' };
const record = result.record;
if (!record || typeof record.score !== 'number' || typeof record.confidence !== 'number') {
return { state: 'invalid' };
}
return {
state: 'received',
score: record.score,
riskLevel: record.riskLevel,
confidence: record.confidence,
};
}