@glair/vision
TypeScript icon, indicating that this package has built-in type declarations

0.0.1-beta.9 • Public • Published

GLAIR

GLAIR Vision Node.js SDK

Latest Release License

Requirement

You need Node version 18 or higher. For local development, we recommend to use Node Version Manager (NVM).

Installation

Install

npm install @glair/vision

Usage

The package needs to be configured with your credentials, see here for more details.

import { Vision } from "@glair/vision";

const vision = new Vision({
  apiKey: "api-key",
  username: "username",
  password: "password",
});

Afterwards, you can use the provided functions to access GLAIR Vision API:

  1. OCR
  2. Face Biometric
  3. Session
  4. Identity

Configuration

The SDK can be initialized with several options:

import { Settings } from "@glair/vision/lib/api/config";

const visionConfig: Settings = {
  baseUrl: "https://api.vision.glair.ai",
  apiVersion: "v1",
  apiKey: "default-api-key",
  username: "default-username",
  password: "default-password",
};
Option Default Description
baseUrl https://api.vision.glair.ai Base URL for the API
apiVersion v1 GLAIR Vision API version to be used
apiKey default-api-key Your API Key
username default-username Your username
password default-password Your password

Override Configuration

You can override the configuration values for one-time only:

const resp = await vision.ocr
  .ktp(
    { image: "/path/to/image.jpg" },
    { apiKey: "xxx", username: "yyy", password: "passwd" }
  )
  .catch((err) => console.error(err));
console.log(resp);

The second parameter is Partial<Settings> (same as Settings but all optional). It will be merged with the original Settings you set when instantiating the Vision instance.

Usage with TypeScript

GLAIR Vision Node.js SDK is packaged with TypeScript declarations. You don't need to install another package.

Usage with Frameworks

NextJS

Instantiate a Vision instance in a file and export it.

// util/vision.ts
import { Vision } from "@glair/vision";

const vision = new Vision({
  apiKey: "api-key",
  username: "username",
  password: "password",
});

Then you can use the vision object in server-side NextJS.

// api/ktp.ts
import { vision } from "../util/vision";
import type { NextApiRequest, NextApiResponse } from "next";

export default async function handler(
  req: NextApiRequest,
  res: NextApiResponse
) {
  const resp = await vision.ocr.ktp({
    image: "/path/to/image.jpg",
  });
  res.status(200).json(resp);
}

FAQ

  1. I got ReferenceError: FormData is not defined error. What should I do?
    • Make sure you use Node version 18 or higher.

OCR

KTP

const resp = await vision.ocr
  .ktp({ image: "/path/to/image.jpg", qualities_detector: true }) // qualities_detector is false by default
  .catch((err) => console.error(err));
console.log(resp);

NPWP

const resp = await vision.ocr
  .npwp({ image: "/path/to/image.jpg" })
  .catch((err) => console.error(err));
console.log(resp);

KK

const resp = await vision
  .kk({ image: "/path/to/image.jpg" })
  .catch((err) => console.error(err));
console.log(resp);

STNK

const resp = await vision.ocr
  .stnk({ image: "/path/to/image.jpg" })
  .catch((err) => console.error(err));
console.log(resp);

BPKB

const resp = await vision.ocr
  .bpkb({ image: "/path/to/image.jpg" })
  .catch((err) => console.error(err));
console.log(resp);

Passport

const resp = await vision.ocr
  .passport({ image: "/path/to/image.jpg" })
  .catch((err) => console.error(err));
console.log(resp);

License Plate

const resp = await vision.ocr
  .licensePlate({ image: "/path/to/image.jpg" })
  .catch((err) => console.error(err));
console.log(resp);

General Document

const resp = await vision.ocr
  .generalDocument({ image: "/path/to/image.jpg" })
  .catch((err) => console.error(err));
console.log(resp);

Invoice

const resp = await vision.ocr
  .invoice({ image: "/path/to/image.jpg" })
  .catch((err) => console.error(err));
console.log(resp);

Receipt

const resp = await vision.ocr
  .receipt({ image: "/path/to/image.jpg" })
  .catch((err) => console.error(err));
console.log(resp);

Face Biometric

Face Matching

const resp = await vision.faceBio
  .match({
    captured: "/path/to/captured.jpg",
    stored: "/path/to/stored.jpg",
  })
  .catch((err) => console.error(err));
console.log(resp);

Passive Liveness

const resp = await vision.faceBio
  .passiveLiveness({
    image: "/path/to/image.jpg",
  })
  .catch((err) => console.error(err));
console.log(resp);

Active Liveness

const resp = await vision.faceBio
  .activeLiveness({
    image: "/path/to/image.jpg",
    gestureCode: "gesture-code",
  })
  .catch((err) => console.error(err));
console.log(resp);

Session

Passive Liveness Sessions

Create session

const resp = await vision.faceBio.passiveLivenessSessions
  .create({
    success_url: "https://docs.glair.ai?success=true",
    cancel_url: "https://docs.glair.ai?success=false",
  })
  .catch((err) => console.error(err));
console.log(resp);

Retrieve Session

const resp = await vision.faceBio.passiveLivenessSessions
  .retrieve({ sid: "session-id" })
  .catch((err) => console.error(err));
console.log(resp);

Active Liveness Sessions

Create session

const resp = await vision.faceBio.activeLivenessSessions
  .create({
    success_url: "https://docs.glair.ai?success=true",
    cancel_url: "https://docs.glair.ai?success=false",
    number_of_gesture: 3,
  })
  .catch((err) => console.error(err));
console.log(resp);

Retrieve Session

const resp = await vision.faceBio.activeLivenessSessions
  .retrieve({ sid: "session-id" })
  .catch((err) => console.error(err));
console.log(resp);

KTP Sessions

Create session

const resp = await vision.ocr.ktpSessions
  .create({
    success_url: "https://docs.glair.ai?success=true",
    cancel_url: "https://docs.glair.ai?success=false",
  })
  .catch((err) => console.error(err));
console.log(resp);

Retrieve Session

const resp = await vision.ocr.ktpSessions
  .retrieve({ sid: "session-id" })
  .catch((err) => console.error(err));
console.log(resp);

NPWP Sessions

Create session

const resp = await vision.ocr.npwpSessions
  .create({
    success_url: "https://docs.glair.ai?success=true",
    cancel_url: "https://docs.glair.ai?success=false",
  })
  .catch((err) => console.error(err));
console.log(resp);

Retrieve Session

const resp = await vision.ocr.npwpSessions
  .retrieve({ sid: "session-id" })
  .catch((err) => console.error(err));
console.log(resp);

Identity

Basic Verification

const resp = await vision.identity
  .verification({
    nik: "1234567890123456",
    name: "John Doe",
    date_of_birth: "01-01-2000",
  })
  .catch((err) => console.error(err));
console.log(resp);

Face Verification

const resp = await vision.identity
  .faceVerification({
    nik: "1234567890123456",
    name: "John Doe",
    date_of_birth: "01-01-2000",
    face_image: "/path/to/image.jpg",
  })
  .catch((err) => console.error(err));
console.log(resp);

Package Sidebar

Install

npm i @glair/vision

Weekly Downloads

315

Version

0.0.1-beta.9

License

MIT

Unpacked Size

55.7 kB

Total Files

34

Last publish

Collaborators

  • teguh.s.santoso
  • sahatnicholas-gdp
  • timotiusnc
  • glair-admin