npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@glair/vision

v0.0.1-beta.9

Published

GLAIR Vision Node.js SDK

Downloads

268

Readme

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);