TypeScript SDK

Detectant

Detectant TypeScript SDK

Detectant is a malware scanning API with support for TypeScript

Scan files for malware from Node.js and TypeScript.

Install

$npm install @detectant-api/sdk

Set your API key in the environment:

$export DETECTANT_API_KEY="your-api-key"

Create a client

1import { Detectant } from "@detectant-api/sdk";
2
3const detectant = new Detectant({
4 apiKey: process.env.DETECTANT_API_KEY,
5});

Scan one file

The simplest Node.js option is a file path:

1const result = await detectant.scan({ path: "./invoice.pdf" });
2
3console.log(result.verdict, result.detections);

The call completes after the file has been analyzed and returns its scan result.

Supported file inputs

Choose the input that already fits your application:

1import { createReadStream, readFileSync } from "node:fs";
2
3// A path — recommended when the file is on disk
4await detectant.scan({ path: "./invoice.pdf" });
5
6// A Node.js readable stream
7await detectant.scan(createReadStream("./invoice.pdf"));
8
9// A Buffer or Uint8Array already in memory
10await detectant.scan(readFileSync("./invoice.pdf"));
11await detectant.scan(new Uint8Array([/* file bytes */]));
12
13// A browser File, such as one selected with <input type="file">
14await detectant.scan(fileInput.files![0]);
15
16// A Blob
17await detectant.scan(new Blob([fileBytes], { type: "application/pdf" }));

For in-memory data, add a filename and content type when they are known:

1await detectant.scan({
2 data: fileBuffer,
3 filename: "invoice.pdf",
4 contentType: "application/pdf",
5});

The SDK accepts file paths, Node.js streams, web ReadableStreams, Buffers, Uint8Arrays, ArrayBuffers, Blobs, and Files.

Scan a batch

Upload between 1 and 20 files. Results are returned in the same order as the inputs.

1const batch = await detectant.scanBatch([
2 { path: "./invoice.pdf" },
3 { path: "./archive.zip" },
4]);
5
6for (const item of batch.results) {
7 if (item.scan) {
8 console.log(item.filename, item.scan.verdict);
9 } else {
10 console.error(item.filename, item.error);
11 }
12}

One file can fail without preventing the other files in the batch from being scanned. Check each item’s scan and error values.

Configuration

Increase the timeout for large files when needed:

1const detectant = new Detectant({
2 apiKey: process.env.DETECTANT_API_KEY,
3 timeoutInSeconds: 120,
4});