2.5.0 • Published 9 days ago

sonic-widget v2.5.0

Weekly downloads
-
License
MIT
Repository
-
Last release
9 days ago

version downloads jsdelivr NPM

Installation:

Sonic Widget - used to show the onboard kyc at your web page itself.

Use this script tag to get access to the widget:

<script src="https://cdn.jsdelivr.net/npm/sonic-widget@2.5.0/dist/index.min.js"></script>

or

in Angular can be used by installing package from npm

npm install sonic-widget

and adding path in angular.json

"scripts": [ "node_modules/sonic-widget/dist/index.js" ]

Implementation Details for Angular TypeScript:

Steps:-

  1. Create or open an angular TS project.

  2. Use this script tag to get access to the widget at initial html page:

<script src="https://cdn.jsdelivr.net/npm/sonic-widget@2.5.0/dist/index.min.js"></script>

or

it can be added in angular.json by installing the npm package

"scripts": [ "node_modules/sonic-widget/dist/index.js" ]
  1. At app.component.html, Add a button with the id xxxx. It is used to call the widget by on click event.
<button id="xxxx">Open</button>
  1. Add a div tag with the id sonic-web-widget at the specific place. It is used to display the sonic module with the help of this id.
<div id="sonic-web-widget"></div>
  1. Add a declaration for var sonic at TS file app.component.ts.
declare var sonic: any;
  1. Next, add the functionality to call widget in the base of onInit.
ngOnInit(): void {
	
	const config = {
		baseurl: string, // the base url of the backend server
		docModelUrl: string, // the doc model url of the document recognition process 
		maskModelUrl: string, // the mask model url of the mask detect process
		showPage: boolean, // used to show the page or not
		ipInfoKey: string, // api key to detect vpn used or not from "ipInfo.io" (Optional)
		videoURL: string, // url of video to do (e.g: demo doing kyc) (Optional)
		appId: string, // application policy identifier
		accountId: string, // account can be taken from operator axiom account
		appName: string, // representing name of the application (Optional)
		userName: string, // user prospective data
		userId: string, // user document number to identity
		email: string, // user prospective data
		phone: string, // user prospective data
		applicationNo: string, // user prospective data
		isMalay: boolean, //used to change the default language english to malay
		branchId: string, //used to identify the bank branch
		sendLogsEmail: boolean, //used to send logs through email
		blinkThreshold: number, // used for blink threshold
		objectPersonThreshold: number, // used for object Person score threshold
		objectPhoneThreshold: number, // used for object Phone score threshold
		onMessage: function (data) {}, // callback function, when api response message or error or any other actions
	};

	// get the element used in the action button 
	var container = document.getElementById('xxxx');
	// on click of element widget works
	container?.addEventListener('click', function () {
		sonic?.SonicWidget(config);
	});
}
  1. Add service worker for widget to protect the multiple calls for tensorflow. So, it will have cache to reuse it. Here, I'm adding service-worker.js file at src/assets folder. So, below steps will be based on this file path.
const CACHE_NAME = 'demo-app-ai-tensorflow-models-cache-v1';
const urlsToCache = [
    // coco ssd - tensorflow model
    // document model - teachable machine drive link or folder path 
    // mask model - teachable machine drive link or folder path 
    // face landmark model - mediapipe tasks-vision
    // hand landmark model - mediapipe tasks-vision
    // Add more model files if necessary
  ]

self.addEventListener('install', function(event) {
  // Perform install steps
  event.waitUntil(
    caches.open(CACHE_NAME)
      .then(function(cache) {
        return cache.addAll(urlsToCache);
      })
  );
});

self.addEventListener('fetch', function(event) {
    const request = event.request;
  
    // Skip caching for requests from browser extensions
    if (request.url.startsWith('chrome-extension://')) {
      return;
    }
  
    event.respondWith(
      caches.match(request)
        .then(function(response) {
          // Cache hit - return response
          if (response) {
            return response;
          }
  
          // Clone the request
          const fetchRequest = request.clone();
  
          return fetch(fetchRequest).then(
            function(response) {
              // Check if we received a valid response
              if(!response || response.status !== 200 || response.type !== 'basic') {
                return response;
              }
  
              // Clone the response
              const responseToCache = response.clone();
              // Save the response for future matching
              caches.open(CACHE_NAME)
                .then(function(cache) {
                  cache.put(request, responseToCache);
                });
  
              return response;
            }
          );
        })
    );
});
  1. Use this script tag to get access to the service worker at initial html page:
<script src="src/assets/service-worker.js"></script>

or

it can be added in angular.json by installing the npm package

"scripts": [ ..., "src/assets/service-worker.js" ]
  1. Register the service worker at your required place:
	ngAfterViewInit(): void {
		if ('serviceWorker' in navigator) {
			window.addEventListener('load', () => {
				navigator.serviceWorker.register('/demo-app/assets/service-worker.js').then(
					(registration) => {
						console.log(
							'ServiceWorker registered with scope: ',
							registration.scope
						);
					},
					(err) => {
						console.error('ServiceWorker registration failed: ', err);
					}
				);
			});
		}
	}

 

Implementation Details for Vanilla JavaScript:

Steps:-

  1. Create or open an html file.

  2. Add a button with the id xxxx. It is used to call the widget by on click event.

<button id="xxxx">Open</button>
  1. Add a div tag with the id sonic-web-widget at the last or beginning of the body tag. It is used to display the sonic module with the help of this id.
<div id="sonic-web-widget"></div>
  1. Add a Script tag to the head tag or body tag. And use the latest version.
<script src="https://cdn.jsdelivr.net/npm/sonic-widget@2.5.0/dist/index.min.js"></script>
  1. Next, add the script tag at a necessary place. But add below the widget script.
<script>
	const config = {
		baseurl: string, // the base url of the backend server
		docModelUrl: string, // the doc model url of the document recognition process
		maskModelUrl: string, // the mask model url of the mask detect process
		showPage: boolean, // used to show the page or not
		ipInfoKey: string, // api key to detect vpn used or not from "ipInfo.io" (Optional)
		videoURL: string, // url of video to do (e.g: demo doing kyc) (Optional)
		appId: string, // application policy identifier
		appName: string, // representing name of the application (Optional)
		accountId: string, // account can be taken from operator axiom account
		userName: string, // user prospective data
		userId: string, // user document number to identity
		email: string, // user prospective data
		phone: string, // user prospective data
		applicationNo: string, // user prospective data
		isMalay: boolean, //used to change the default language english to malay
		branchId: string, // branch id to identify the branch of the bank
		sendLogsEmail: boolean, //used to send logs through email
		blinkThreshold: number, // threshold used to calculate the user blinked or not, with range limit 0-1(default value is 0.35)
		objectPersonThreshold: number, // used for object Person score threshold with range limit 0-1(default value is 0.35)
		objectPhoneThreshold: number, // used for object Phone score threshold with range limit 0-1(default value is 0.35)
		onMessage: function (data) {}, // callback function, when api response message or error or any other actions
	};
	// get the element used in the action button 
	var container = document.getElementById('xxxx');
	// on click of element widget works
	container.addEventListener('click', function () {
		sonic.SonicWidget(config);
	});
</script>

Here, the config variable is used to pass the data. And the container variable is to get the dom element of the id xxxx button and add it to the event listener. It checks if the button is clicked and sends the config object data to the sonic module. sonic.SonicWidget(config)

You can get the logs with onMessage for all actions and stages. Check with data.code

0 - info message from application 
1 - success api call
-1 - failed api call
-2 - error message from application 
-3 - configuration error message 
2 - on close application

Note:-

  • baseurl should pass as a string value. It is used as the base URL for API calls.
  • docModelUrl should pass as a string value. It is used as the base URL for document model.
  • maskModelUrl should pass as a string value. It is used as the base URL for mask model.
  • showPage is used to pass a boolean value ( true or false ). To toggle the widget page open or close.
  • ipInfoKey should pass as a string value. It is used to detect whether vpn is used or not from "ipInfo.io" with this api key and it is optional.
  • videoURL should pass as a string value as url. It is used to show the video onboard sonic kyc and it is optional.
  • accountId should pass as a string value. It is used to get the JWT token and proceed with the operator account.
  • isMalay is used to pass a boolean value ( true or false ). To toggle the widget default language english or malay.
  • branchId should pass as a string value. It is used to find bank branch available for operator account for onboard sonic kyc.
  • appId should pass as a string value. It is used to find an application policy for onboard sonic kyc.
  • appName should pass as a string value. It is used for onboard kyc application name. it is optional and default Sonic .
  • userName should pass as a string value. It is used to create an application for onboard sonic kyc.
  • userId should pass as a string value. It is used to create an application for onboard sonic kyc and to compare your identity with the document.
  • email should pass as a string value. It is used to create an application for onboard sonic kyc.
  • phone should pass as a string value. It is used to create an application for onboard sonic kyc.
  • applicationNo should pass as a string value. It is used to create an application for onboard sonic kyc.
  • sendLogsEmail is used to pass a boolean value. It is used to send logs to client email address.
  • blinkThreshold is used to pass a numerical value. It is used to check the user blinks (range 0-1 and default 0.5).
  • objectPersonThreshold is used to pass a numerical value. It is used to check the image person as object found with required score as threshold (range 0-1 and default 0.925).
  • objectPhoneThreshold is used to pass a numerical value. It is used to check the image phone/laptop as object found with required score as threshold (range 0-1 and default 0.5).
  • onMessage is a callback function. It is getting called when the API gives a message or at any configuration error. Return data is an object with its API endpoint and result.
2.5.0

9 days ago

2.4.7

10 days ago

2.4.8

10 days ago

2.4.5

16 days ago

2.4.6

15 days ago

2.4.3

17 days ago

2.4.1

22 days ago

2.4.0

22 days ago

2.4.2

22 days ago

2.3.5

23 days ago

2.3.0

28 days ago

2.3.2

28 days ago

2.3.1

28 days ago

2.3.4

27 days ago

2.3.3

27 days ago

2.2.7

2 months ago

2.2.6

2 months ago

2.2.8

2 months ago

2.2.5

2 months ago

2.2.3

3 months ago

2.2.2

3 months ago

2.2.4

3 months ago

2.1.9

3 months ago

2.2.1

3 months ago

2.2.0

3 months ago

2.1.4

3 months ago

2.1.6

3 months ago

2.1.5

3 months ago

2.1.8

3 months ago

2.1.7

3 months ago

2.1.2

3 months ago

2.1.1

3 months ago

2.1.3

3 months ago

2.1.0

3 months ago

2.0.3

3 months ago

2.0.2

3 months ago

2.0.5

3 months ago

2.0.4

3 months ago

2.0.6

3 months ago

2.0.1

3 months ago

2.0.0

3 months ago

1.71.0

3 months ago

1.70.0

3 months ago

1.66.0-dev

3 months ago

1.66.2-dev

3 months ago

1.66.1-dev

3 months ago

1.65.1

3 months ago

1.64.0

3 months ago

1.65.0

3 months ago

1.63.0

3 months ago

1.60.0

3 months ago

1.61.0

3 months ago

1.62.0

3 months ago

1.53.70

3 months ago

1.53.71

3 months ago

1.53.72

3 months ago

1.53.73

3 months ago

1.53.67

3 months ago

1.53.68

3 months ago

1.53.69

3 months ago

1.53.66

3 months ago

1.53.65

3 months ago

1.53.6

3 months ago

1.53.51

4 months ago

1.53.55

4 months ago

1.53.4

4 months ago

1.53.3

4 months ago

1.53.5

4 months ago

1.53.2

4 months ago

1.53.1

4 months ago

1.52.9

4 months ago

1.53.0

4 months ago

1.52.8-dev

5 months ago

1.52.5

6 months ago

1.52.4

6 months ago

1.52.7

5 months ago

1.52.6

5 months ago

1.51.0

7 months ago

1.51.2

7 months ago

1.51.1

7 months ago

1.51.4

6 months ago

1.51.3

6 months ago

1.51.5

6 months ago

1.50.1

7 months ago

1.50.0

7 months ago

1.52.1

6 months ago

1.50.3

7 months ago

1.52.0

6 months ago

1.50.2

7 months ago

1.52.3

6 months ago

1.52.2

6 months ago

1.46.0

7 months ago

1.48.0

7 months ago

1.45.0

7 months ago

1.47.0

7 months ago

1.49.0

7 months ago

1.37.0

8 months ago

1.14.0

10 months ago

1.35.0

8 months ago

1.12.0

10 months ago

1.18.0

9 months ago

1.39.0

8 months ago

1.16.0

10 months ago

1.0.9

11 months ago

1.8.0

10 months ago

1.0.8

11 months ago

1.0.7

12 months ago

1.6.0

10 months ago

1.0.6

12 months ago

1.0.5

12 months ago

1.40.0

8 months ago

1.42.0

8 months ago

1.21.0

9 months ago

1.44.0

8 months ago

1.25.0

9 months ago

1.23.0

9 months ago

1.29.0

9 months ago

1.27.0

9 months ago

1.32.0

8 months ago

1.11.0

10 months ago

1.30.0

8 months ago

1.36.0

8 months ago

1.34.2

8 months ago

1.15.0

10 months ago

1.1.0

11 months ago

1.34.0

8 months ago

1.13.0

10 months ago

1.34.1

8 months ago

1.19.0

9 months ago

1.38.0

8 months ago

1.17.0

10 months ago

1.9.0

10 months ago

1.7.0

10 months ago

1.5.0

10 months ago

1.41.1

8 months ago

1.41.0

8 months ago

1.22.0

9 months ago

1.43.0

8 months ago

1.20.0

9 months ago

1.26.0

9 months ago

1.24.0

9 months ago

1.28.0

9 months ago

1.33.0

8 months ago

1.10.0

10 months ago

1.31.0

8 months ago

1.0.3

12 months ago

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago