@tsocial/trustvision-sdk
TypeScript icon, indicating that this package has built-in type declarations

2.11.2 • Public • Published

Trust Vision JavaScript SDK

The JavaScript SDK of Trust Vision API

Using script tag

<script src="https://unpkg.com/@tsocial/trustvision-sdk@2.5.0/dist/trustvision-sdk.umd.js"></script>
<script>
  // create and instance of API client with provided access key, secret key and environment
  // environment values should be testing, staging, production or the API URL
  const apiClient = new trustvisionSdk.default(
    'access key', // access key
    'secret key', // secret key
    'testing', // environment (testing, staging, production) or API URL
  );

  // start using services
  apiClient
    .clientSettings()
    .then((result) => {
        // result contains information about card types and other settings
    })
    .catch((error) => {

    });

</script>

Using NPM

// import API Client class
import TrustVisionAPI from '@tsocial/trustvision-sdk';


// create and instance of API client with provided access key, secret key and environment
// environment values should be testing, staging, production or the API URL
const apiClient = new TrustVisionAPI(
  'access key', // access key
  'secret key', // secret key
  'testing', // environment (testing, staging, production) or API URL
);

// start using services
apiClient
  .clientSettings()
  .then((result) => {
      // result contains information about card types and other settings
  })
  .catch((error) => {

  });

Services

Client settings

apiClient
  .clientSettings()
  .then((result) => {
      // please refer to API document for response's format
  })
  .catch((error) => {

  });

Upload image

API document

apiClient
  .uploadImage({
    file: imageFile, // file object
    imageLabel: 'portrait', // image label
  })
  .then((result) => {
      // please refer to API document for response's format
  })
  .catch((error) => {

  });

Compare faces

API document

apiClient
  .compareFaces({
    image1: {
      id: '', //ID of the image in DB
      base64: '', //Base64 encoded text of image1 data
      label: '', //label of the image as described at Upload Image API
      metadata: {}, //any key-value metadata to save with the image, both key and value should be string
    },
    image2: {
      id: '', //ID of the image in DB
      base64: '', //Base64 encoded text of image1 data
      label: '', //label of the image as described at Upload Image API
      metadata: {}, //any key-value metadata to save with the image, both key and value should be string
    }
  })
  .then((result) => {
      // please refer to API document for response's format
  })
  .catch((error) => {

  });

Verify face liveness

API document

apiClient
  .verifyFaceLiveness({
    images: [{
      id: '', //ID of the image in DB
      base64: '', //Base64 encoded text of image1 data
      label: '', //label of the image as described at Upload Image API
      metadata: {}, //any key-value metadata to save with the image, both key and value should be string
    }, {
      id: '', //ID of the image in DB
      base64: '', //Base64 encoded text of image1 data
      label: '', //label of the image as described at Upload Image API
      metadata: {}, //any key-value metadata to save with the image, both key and value should be string
    }],
    gestures: ['<image 1 gesture>', '<image 1 gesture>'], //array of expected gestures of the face in each image, optional
  })
  .then((result) => {
      // please refer to API document for response's format
  })
  .catch((error) => {

  });

Read ID card

API document

apiClient
  .readIDCard({
    card_type: 'card type', // card type of image
    image1: {
      id: '', //ID of the image in DB
      base64: '', //Base64 encoded text of image1 data
      label: '', //label of the image as described at Upload Image API
      metadata: {}, //any key-value metadata to save with the image, both key and value should be string
    },
    image2: {
      id: '', //ID of the image in DB
      base64: '', //Base64 encoded text of image1 data
      label: '', //label of the image as described at Upload Image API
      metadata: {}, //any key-value metadata to save with the image, both key and value should be string
    }, // optional
    qr1_images: [{
      id: '', //ID of the image in DB
      base64: '', //Base64 encoded text of image1 data
      label: '', //label of the image as described at Upload Image API
      metadata: {}, //any key-value metadata to save with the image, both key and value should be string
    }], // array of uploaded back qr code, optional
    qr2_images: [{
      id: '', //ID of the image in DB
      base64: '', //Base64 encoded text of image1 data
      label: '', //label of the image as described at Upload Image API
      metadata: {}, //any key-value metadata to save with the image, both key and value should be string
    }], // array of uploaded front qr code, optional
  })
  .then((result) => {
      // please refer to API document for response's format
  })
  .catch((error) => {

  });

Request verify ID card

API document

apiClient
  .requestVerifyIDCard({
    card_type: 'card type', // card type of image
    image1: {
      id: '', //ID of the image in DB
      base64: '', //Base64 encoded text of image1 data
      label: '', //label of the image as described at Upload Image API
      metadata: {}, //any key-value metadata to save with the image, both key and value should be string
    },
    image2: {
      id: '', //ID of the image in DB
      base64: '', //Base64 encoded text of image1 data
      label: '', //label of the image as described at Upload Image API
      metadata: {}, //any key-value metadata to save with the image, both key and value should be string
    }
  })
  .then((result) => {
      // please refer to API document for response's format
  })
  .catch((error) => {

  });

Request verify portrait

API document

apiClient
  .requestVerifyPortrait({
    image: {
      id: '', //ID of the image in DB
      base64: '', //Base64 encoded text of image1 data
      label: '', //label of the image as described at Upload Image API
      metadata: {}, //any key-value metadata to save with the image, both key and value should be string
    }
  })
  .then((result) => {
      // please refer to API document for response's format
  })
  .catch((error) => {

  });

Search faces (Faces retrieval)

API document

apiClient
  .searchFaces({
    image: {
      id: '', //ID of the image in DB
      base64: '', //Base64 encoded text of image1 data
      label: '', //label of the image as described at Upload Image API
      metadata: {}, //any key-value metadata to save with the image, both key and value should be string
    },
    collection: "", // index faces to this collection, optional
  })
  .then((result) => {
      // please refer to API document for response's format
  })
  .catch((error) => {

  });

Download image

API document

Example: Download an image and display it on a img HTML tag

const $img = document.getElementById('result'); // select an image tag with id result <img id="result" />
const imageId = 'd70b3fd3-253d-4e35-b2f7-fad564a36443';
apiClient.downloadImage(imageId)
  .then((dataURL) => $img.setAttribute('src', result));

Index faces

API document

apiClient
  .indexFaces({
    image: {
      id: '', //ID of the image in DB
      base64: '', //Base64 encoded text of image1 data
      label: '', //label of the image as described at Upload Image API
      metadata: {}, //any key-value metadata to save with the image, both key and value should be string
    },
    collection: "", // index faces to this collection, optional
  })
  .then((result) => {
      // please refer to API document for response's format
  })
  .catch((error) => {

  });

Update metadata

API document

apiClient
  .updateMetadata({
    "metadata": {} // any key-value metadata to save with the image, both key and value should be string,
    "label": '', //label of the image
    "override":  true, // boolean flag to allow override old metadata or not,
})
  .then((result) => {
      // please refer to API document for response's format
  })
  .catch((error) => {

  });

Readme

Keywords

none

Package Sidebar

Install

npm i @tsocial/trustvision-sdk

Weekly Downloads

156

Version

2.11.2

License

MIT

Unpacked Size

3.63 MB

Total Files

229

Last publish

Collaborators

  • toan-trieu-ts
  • thu.tran
  • khai.truong