@tsocial/trustvision-sdk
v2.11.2
Published
A SDK to interact with Trust Vision BE API
Downloads
849
Readme
Trust Vision JavaScript SDK
The JavaScript SDK of Trust Vision API
Using script tag
<script src="https://unpkg.com/@tsocial/[email protected]/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
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
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
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
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
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
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)
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
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
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
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) => {
});