sonic-widget 2.7.21 → 2.7.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,391 +1,399 @@
1
- # SONIC WIDGET
2
-
3
- [![version](https://img.shields.io/npm/v/sonic-widget?style=flat)](https://www.npmjs.com/package/sonic-widget)
4
- [![downloads](https://img.shields.io/npm/dm/sonic-widget?style=flat)](https://www.npmjs.com/package/sonic-widget)
5
- [![jsdelivr](https://data.jsdelivr.com/v1/package/npm/sonic-widget/badge)](https://www.jsdelivr.com/package/npm/sonic-widget)
6
- [![NPM](https://img.shields.io/npm/l/sonic-widget)](https://www.jsdelivr.com/package/npm/sonic-widget)
7
-
8
- ## Installation:
9
-
10
- **Sonic Widget** - _used to show the onboard kyc at your web page itself._
11
-
12
- Use this script tag to get access to the widget:
13
-
14
- ```html
15
- <script src="https://cdn.jsdelivr.net/npm/sonic-widget@2.7.21/dist/index.min.js"></script>
16
- ```
17
-
18
- or
19
-
20
- in **Angular** can be used by installing package from npm
21
-
22
- ```shell
23
- npm install sonic-widget
24
- ```
25
-
26
- and adding path in `angular.json`
27
-
28
- ```json
29
- "scripts": [ "node_modules/sonic-widget/dist/index.js" ]
30
- ```
31
-
32
-
33
- ## Implementation Details for Angular TypeScript:
34
-
35
- **Steps:-**
36
-
37
- 1. Create or open an angular TS project.
38
-
39
- 2. Use this script tag to get access to the widget at initial html page:
40
-
41
- ```html
42
- <script src="https://cdn.jsdelivr.net/npm/sonic-widget@2.7.21/dist/index.min.js"></script>
43
- ```
44
-
45
- or
46
-
47
- it can be added in `angular.json` by installing the npm package
48
-
49
- ```json
50
- "scripts": [ "node_modules/sonic-widget/dist/index.js" ]
51
- ```
52
-
53
- 3. At `app.component.html`, Add a button with the id **`xxxx`**. It is used to call the widget by on click event.
54
-
55
- ```html
56
- <button id="xxxx">Open</button>
57
- ```
58
-
59
- 4. 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.
60
-
61
- ```html
62
- <div id="sonic-web-widget"></div>
63
- ```
64
-
65
- 5. Add a declaration for var *sonic* at TS file `app.component.ts`.
66
-
67
- ```ts
68
- declare var sonic: any;
69
- ```
70
-
71
- 6. Next, add the functionality to call widget in the base of onInit.
72
-
73
- ```ts
74
- ngOnInit(): void {
75
-
76
- const config = {
77
- baseurl: string, // the base url of the backend server
78
- docModelPath: string, // the doc model url of the document recognition process
79
- maskModelPath: string, // the mask model url of the mask detect process
80
- faceModelUrl: string, // the face model url of the face recognition process
81
- handModelUrl: string, // the hand model url of the hand recognition process
82
- objectModelUrl: string, // the object model url of the object recognition process
83
- ipInfoKey: string,
84
- googleMapKey: string,
85
- showPage: boolean, // used to show the page or not
86
- speedCheckURL: string, // public URL of the internet speed check
87
- videoURL: string, // url of video to do (e.g: demo doing kyc) (Optional)
88
- appId: string, // application policy identifier
89
- accountId: string, // account can be taken from operator axiom account
90
- appName: string, // representing name of the application (Optional)
91
- userName: string, // user prospective data
92
- userId: string, // user document number to identity
93
- email: string, // user prospective data
94
- phone: string, // user prospective data
95
- applicationNo: string, // user prospective data
96
- isMalay: boolean, //used to change the default language english to malay
97
- branchId: string, //used to identify the bank branch
98
- sendLogsEmail: boolean, //used to send logs through email
99
- blinkThreshold: number, // used for blink threshold
100
- eyeOpenThreshold: number, // used for eye open threshold
101
- disableUploadDocs: boolean, // used to show/hide the upload docs option.
102
- objectPersonThreshold: number, // used for object Person score threshold
103
- objectPhoneThreshold: number, // used for object Phone score threshold
104
- grayscalePercentageThreshold: number, // used for black&white percentage score threshold
105
- onMessage: function (data) {}, // callback function, when api response message or error or any other actions
106
- };
107
-
108
- // get the element used in the action button
109
- var container = document.getElementById('xxxx');
110
- // on click of element widget works
111
- container?.addEventListener('click', function () {
112
- sonic?.SonicWidget(config);
113
- });
114
- }
115
- ```
116
-
117
- 7. 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.
118
-
119
- ```javascript
120
- const CACHE_NAME = 'demo-app-ai-tensorflow-models-cache-v1';
121
- const urlsToCache = [
122
- // coco ssd - tensorflow model
123
- // document model - teachable machine drive link or folder path
124
- // mask model - teachable machine drive link or folder path
125
- // face landmark model - mediapipe tasks-vision
126
- // hand landmark model - mediapipe tasks-vision
127
- // Add more model files if necessary
128
- ]
129
-
130
- self.addEventListener('install', function(event) {
131
- // Perform install steps
132
- event.waitUntil(
133
- caches.open(CACHE_NAME)
134
- .then(function(cache) {
135
- return cache.addAll(urlsToCache);
136
- })
137
- );
138
- });
139
-
140
- self.addEventListener('fetch', function(event) {
141
- const request = event.request;
142
-
143
- // Skip caching for requests from browser extensions
144
- if (request.url.startsWith('chrome-extension://')) {
145
- return;
146
- }
147
-
148
- event.respondWith(
149
- caches.match(request)
150
- .then(function(response) {
151
- // Cache hit - return response
152
- if (response) {
153
- return response;
154
- }
155
-
156
- // Clone the request
157
- const fetchRequest = request.clone();
158
-
159
- return fetch(fetchRequest).then(
160
- function(response) {
161
- // Check if we received a valid response
162
- if(!response || response.status !== 200 || response.type !== 'basic') {
163
- return response;
164
- }
165
-
166
- // Clone the response
167
- const responseToCache = response.clone();
168
- // Save the response for future matching
169
- caches.open(CACHE_NAME)
170
- .then(function(cache) {
171
- cache.put(request, responseToCache);
172
- });
173
-
174
- return response;
175
- }
176
- );
177
- })
178
- );
179
- });
180
- ```
181
- 8. Use this script tag to get access to the service worker at initial html page:
182
-
183
- ```html
184
- <script src="src/assets/service-worker.js"></script>
185
- ```
186
-
187
- or
188
-
189
- it can be added in `angular.json` by installing the npm package
190
-
191
- ```json
192
- "scripts": [ ..., "src/assets/service-worker.js" ]
193
- ```
194
-
195
- 9. Register the service worker at your required place:
196
- ```ts
197
- ngAfterViewInit(): void {
198
- if ('serviceWorker' in navigator) {
199
- window.addEventListener('load', () => {
200
- navigator.serviceWorker.register('/demo-app/assets/service-worker.js').then(
201
- (registration) => {
202
- console.log(
203
- 'ServiceWorker registered with scope: ',
204
- registration.scope
205
- );
206
- },
207
- (err) => {
208
- console.error('ServiceWorker registration failed: ', err);
209
- }
210
- );
211
- });
212
- }
213
- }
214
- ```
215
-
216
- &nbsp;
217
-
218
- ## Implementation Details for Vanilla JavaScript:
219
-
220
- **Steps:-**
221
-
222
- 1. Create or open an html file.
223
-
224
- 2. Add a button with the id **`xxxx`**. It is used to call the widget by on click event.
225
-
226
- ```html
227
- <button id="xxxx">Open</button>
228
- ```
229
-
230
- 3. 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.
231
-
232
- ```html
233
- <div id="sonic-web-widget"></div>
234
- ```
235
-
236
- 4. Add a Script tag to the head tag or body tag. And use the latest version.
237
-
238
- ```html
239
- <script src="https://cdn.jsdelivr.net/npm/sonic-widget@2.7.21/dist/index.min.js"></script>
240
- ```
241
-
242
- 5. Next, add the script tag at a necessary place. But add below the widget script.
243
-
244
- ```html
245
- <script>
246
- const config = {
247
- baseurl: string, // the base url of the backend server
248
- docModelPath: string, // the doc model url of the document recognition process
249
- maskModelPath: string, // the mask model url of the mask detect process
250
- faceModelUrl: string, // the face model url of the face recognition process
251
- handModelUrl: string, // the hand model url of the hand recognition process
252
- objectModelUrl: string, // the object model url of the object recognition process
253
- ipInfoKey: string,
254
- googleMapKey: string,
255
- showPage: boolean, // used to show the page or not
256
- speedCheckURL: string, // public URL of the internet speed check
257
- videoURL: string, // url of video to do (e.g: demo doing kyc) (Optional)
258
- appId: string, // application policy identifier
259
- appName: string, // representing name of the application (Optional)
260
- accountId: string, // account can be taken from operator axiom account
261
- userName: string, // user prospective data
262
- userId: string, // user document number to identity
263
- email: string, // user prospective data
264
- phone: string, // user prospective data
265
- applicationNo: string, // user prospective data
266
- isMalay: boolean, //used to change the default language english to malay
267
- branchId: string, // branch id to identify the branch of the bank
268
- sendLogsEmail: boolean, //used to send logs through email
269
- blinkThreshold: number, // threshold used to calculate the user's eye blinked or not, with range limit 0-1(default value is 0.35)
270
- eyeOpenThreshold: number, // threshold used to calculate the user's eye open or not, with range limit 0-1(default value is 0.2)
271
- disableUploadDocs: boolean, // used to pass a boolean value. It is used to disable the upload option the document process
272
- objectPersonThreshold: number, // used for object Person score threshold with range limit 0-1(default value is 0.925)
273
- objectPhoneThreshold: number, // used for object Phone score threshold with range limit 0-1(default value is 0.5)
274
- grayscalePercentageThreshold: number, // used for black&white percentage score threshold with range limit 0-100(default value is 80)
275
- onMessage: function (data) {}, // callback function, when api response message or error or any other actions
276
- };
277
- // get the element used in the action button
278
- var container = document.getElementById('xxxx');
279
- // on click of element widget works
280
- container.addEventListener('click', function () {
281
- sonic.SonicWidget(config);
282
- });
283
- </script>
284
- ```
285
-
286
- _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.
287
- **`sonic.SonicWidget(config)`**_
288
-
289
- _You can get the logs with **`onMessage`** for all actions and stages.
290
- Check with **`data.code`**_
291
-
292
- ```
293
- 0 - info message from application
294
- 1 - success api call
295
- -1 - failed api call
296
- -2 - error message from application
297
- -3 - configuration error message
298
- 2 - on close application
299
- ```
300
-
301
- **Note:-**
302
-
303
- <!-- - _**`serviceWorkerPath`** should pass as a string value. It is used as the service worker path and its default path is **`/demo-app/assets/service-worker.js`** and Cache name should be different to fix conflict._ -->
304
- - _**`baseurl`** should pass as a string value. It is used as the base URL for API calls._
305
- - _**`docModelPath`** should pass as a string value. It is used as the base URL for document model._
306
- - _**`maskModelPath`** should pass as a string value. It is used as the base URL for mask model._
307
- - _**`faceModelUrl`** should pass as a string value. It is used as the base URL for task vision face model._
308
- - _**`handModelUrl`** should pass as a string value. It is used as the base URL for task vision hand model._
309
- - _**`objectModelUrl`** should pass as a string value. It is used as the base URL for coco-ssd object model._
310
- - _**`showPage`** is used to pass a boolean value ( **`true`** or **`false`** ). To toggle the widget page open or close._
311
- - _**`speedCheckURL`** should pass as a string value. It is used to detect internet speed and intimate the user._
312
- - _**`videoURL`** should pass as a string value as url. It is used to show the video onboard sonic kyc and it is optional._
313
- - _**`accountId`** should pass as a string value. It is used to get the JWT token and proceed with the operator account._
314
- - _**`isMalay`** is used to pass a boolean value ( **`true`** or **`false`** ). To toggle the widget default language english or malay._
315
- - _**`branchId`** should pass as a string value. It is used to find bank branch available for operator account for onboard sonic kyc._
316
- - _**`appId`** should pass as a string value. It is used to find an application policy for onboard sonic kyc._
317
- - _**`appName`** should pass as a string value. It is used for onboard kyc application name. it is optional and default **`Sonic`** ._
318
- - _**`userName`** should pass as a string value. It is used to create an application for onboard sonic kyc._
319
- - _**`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._
320
- - _**`email`** should pass as a string value. It is used to create an application for onboard sonic kyc._
321
- - _**`phone`** should pass as a string value. It is used to create an application for onboard sonic kyc._
322
- - _**`applicationNo`** should pass as a string value. It is used to create an application for onboard sonic kyc._
323
- - _**`sendLogsEmail`** is used to pass a boolean value. It is used to send logs to client email address._
324
- - _**`blinkThreshold`** is used to pass a numerical value. It is used to check the user blinking (range 0-1 and default 0.35). Above the threshold consider to be blinking or eye closed._
325
- - _**`disableUploadDocs`** is used to pass a boolean value. It is used to disable the upload option the document process._
326
- - _**`eyeOpenThreshold`** is used to pass a numerical value. It is used to check the user eyes are open (range 0-1 and default 0.2). Below the threshold consider to be eyes are open._
327
- - _**`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)._
328
- - _**`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)._
329
- - _**`grayscalePercentageThreshold`** is used to pass a numerical value for percentage. It is used to check the image color as black&white found with required percentage as threshold (range 0-100 and default 80)._
330
- - _**`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._
331
-
332
-
333
- <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DEVELOPER info ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
334
-
335
- <!-- use node 18 and install packages using yarn and do yarn dev -->
336
-
337
- <!-- env -->
338
-
339
- <!--
340
- VITE_APP_DOCUMENT_DETECT_PATH=""
341
- VITE_APP_MASK_DETECT_PATH=""
342
- VITE_APP_COCO_SSD_OBJECT_URL="https://storage.googleapis.com/tfjs-models/savedmodel/ssdlite_mobilenet_v2/model.json"
343
- VITE_APP_TASK_VISION_WASM_PATH="https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision/wasm"
344
- VITE_APP_TASK_VISION_FACE_URL="https://storage.googleapis.com/mediapipe-models/face_landmarker/face_landmarker/float16/1/face_landmarker.task"
345
- VITE_APP_TASK_VISION_HAND_URL="https://storage.googleapis.com/mediapipe-models/hand_landmarker/hand_landmarker/float16/1/hand_landmarker.task"
346
-
347
- VITE_APP_THIRD_PARTY_GET_IP_URL="https://ipv4.icanhazip.com"
348
- -->
349
-
350
- <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GrayScale info ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
351
-
352
- <!-- GrayScale Suggestions
353
-
354
- 1. RGB Difference Threshold for Grayscale Detection:
355
-
356
- Low Threshold: A low threshold (e.g., 5-10) is good if you want to consider any slight variation in color as an indication that the image is colored. This is more sensitive to minor color differences.
357
-
358
- Moderate Threshold: A threshold of around 10-20 is a more balanced approach. It allows for small variations due to noise or minor imperfections in grayscale images but still classifies them as black and white.
359
-
360
- High Threshold: A higher threshold (e.g., 20-50) will classify images as grayscale even if there are noticeable color variations, which might be acceptable for images that are predominantly black and white but have some color noise or artifacts.
361
-
362
- 2. Percentage of Grayscale Pixels:
363
-
364
- After detecting grayscale pixels, you need to determine the percentage of grayscale pixels required to classify the image as black and white.
365
-
366
- 80-90% Grayscale Pixels: This threshold means that if 80-90% of the pixels are grayscale, the image will be classified as black and white. This works well for documents and images that are mostly grayscale but may have some minor color elements (e.g., stamps, logos).
367
-
368
- 90-100% Grayscale Pixels: This is a stricter threshold, ensuring that the image is classified as black and white only if nearly all pixels are grayscale. -->
369
-
370
- <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Selfie info ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
371
-
372
- <!--
373
- 1.blinkThreshold: number
374
-
375
- Description : The blinkThreshold is used to determine whether the user's eye is considered blinked. It represents the sensitivity to eye closure during a blink.
376
- Range : 0-1 (default: 0.35)
377
- Functionality :
378
- * If either of the user's eyes exceeds the specified threshold (i.e., the eye closure ratio is greater than the blinkThreshold), the eye is detected as "blinked."
379
- * This helps identify blinks during facial detection or tracking processes.
380
-
381
- 2.eyeOpenThreshold: number
382
-
383
- Description : The eyeOpenThreshold is used to detect whether the user's eyes are open or not. It determines the sensitivity to eye openness by checking the openness ratio.
384
- Range : 0-1 (default: 0.25)
385
- Functionality :
386
- * If both eyes fall below the defined threshold, the system interprets that the eyes are open.
387
- * This value helps differentiate between an open eye and a partially closed
388
-
389
- Both thresholds work together to archive ekyc selfie process.
390
- -->
391
-
1
+ # SONIC WIDGET
2
+
3
+ [![version](https://img.shields.io/npm/v/sonic-widget?style=flat)](https://www.npmjs.com/package/sonic-widget)
4
+ [![downloads](https://img.shields.io/npm/dm/sonic-widget?style=flat)](https://www.npmjs.com/package/sonic-widget)
5
+ [![jsdelivr](https://data.jsdelivr.com/v1/package/npm/sonic-widget/badge)](https://www.jsdelivr.com/package/npm/sonic-widget)
6
+ [![NPM](https://img.shields.io/npm/l/sonic-widget)](https://www.jsdelivr.com/package/npm/sonic-widget)
7
+
8
+ ## Installation:
9
+
10
+ **Sonic Widget** - _used to show the onboard kyc at your web page itself._
11
+
12
+ Use this script tag to get access to the widget:
13
+
14
+ ```html
15
+ <script src="https://cdn.jsdelivr.net/npm/sonic-widget@2.7.52/dist/index.min.js"></script>
16
+ ```
17
+
18
+ or
19
+
20
+ in **Angular** can be used by installing package from npm
21
+
22
+ ```shell
23
+ npm install sonic-widget
24
+ ```
25
+
26
+ and adding path in `angular.json`
27
+
28
+ ```json
29
+ "scripts": [ "node_modules/sonic-widget/dist/index.js" ]
30
+ ```
31
+
32
+
33
+ ## Implementation Details for Angular TypeScript:
34
+
35
+ **Steps:-**
36
+
37
+ 1. Create or open an angular TS project.
38
+
39
+ 2. Use this script tag to get access to the widget at initial html page:
40
+
41
+ ```html
42
+ <script src="https://cdn.jsdelivr.net/npm/sonic-widget@2.7.52/dist/index.min.js"></script>
43
+ ```
44
+
45
+ or
46
+
47
+ it can be added in `angular.json` by installing the npm package
48
+
49
+ ```json
50
+ "scripts": [ "node_modules/sonic-widget/dist/index.js" ]
51
+ ```
52
+
53
+ 3. At `app.component.html`, Add a button with the id **`xxxx`**. It is used to call the widget by on click event.
54
+
55
+ ```html
56
+ <button id="xxxx">Open</button>
57
+ ```
58
+
59
+ 4. 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.
60
+
61
+ ```html
62
+ <div id="sonic-web-widget"></div>
63
+ ```
64
+
65
+ 5. Add a declaration for var *sonic* at TS file `app.component.ts`.
66
+
67
+ ```ts
68
+ declare var sonic: any;
69
+ ```
70
+
71
+ 6. Next, add the functionality to call widget in the base of onInit.
72
+
73
+ ```ts
74
+ ngOnInit(): void {
75
+
76
+ const config = {
77
+ baseurl: string, // the base url of the backend server
78
+ docModelPath: string, // the doc model url of the document recognition process
79
+ maskModelPath: string, // the mask model url of the mask detect process
80
+ faceModelUrl: string, // the face model url of the face recognition process
81
+ handModelUrl: string, // the hand model url of the hand recognition process
82
+ objectModelUrl: string, // the object model url of the object recognition process
83
+ ipInfoKey: string, // the ip info key
84
+ googleMapKey: string, // the google map key
85
+ googleCaptchaKey: string, // the google reCAPTCHA site key
86
+ passphrase: string, // the encryption key
87
+ showPage: boolean, // used to show the page or not
88
+ speedCheckURL: string, // public URL of the internet speed check
89
+ videoURL: string, // url of video to do (e.g: demo doing kyc) (Optional)
90
+ appId: string, // application policy identifier
91
+ accountId: string, // account can be taken from operator axiom account
92
+ appName: string, // representing name of the application (Optional)
93
+ userName: string, // user prospective data
94
+ userId: string, // user document number to identity
95
+ email: string, // user prospective data
96
+ phone: string, // user prospective data
97
+ applicationNo: string, // user prospective data
98
+ isMalay: boolean, //used to change the default language english to malay
99
+ branchId: string, //used to identify the bank branch
100
+ sendLogsEmail: boolean, //used to send logs through email
101
+ blinkThreshold: number, // used for blink threshold
102
+ eyeOpenThreshold: number, // used for eye open threshold
103
+ disableUploadDocs: boolean, // used to show/hide the upload docs option.
104
+ objectPersonThreshold: number, // used for object Person score threshold
105
+ objectPhoneThreshold: number, // used for object Phone score threshold
106
+ grayscalePercentageThreshold: number, // used for black&white percentage score threshold
107
+ onMessage: function (data) {}, // callback function, when api response message or error or any other actions
108
+ };
109
+
110
+ // get the element used in the action button
111
+ var container = document.getElementById('xxxx');
112
+ // on click of element widget works
113
+ container?.addEventListener('click', function () {
114
+ sonic?.SonicWidget(config);
115
+ });
116
+ }
117
+ ```
118
+
119
+ 7. 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.
120
+
121
+ ```javascript
122
+ const CACHE_NAME = 'demo-app-ai-tensorflow-models-cache-v1';
123
+ const urlsToCache = [
124
+ // coco ssd - tensorflow model
125
+ // document model - teachable machine drive link or folder path
126
+ // mask model - teachable machine drive link or folder path
127
+ // face landmark model - mediapipe tasks-vision
128
+ // hand landmark model - mediapipe tasks-vision
129
+ // Add more model files if necessary
130
+ ]
131
+
132
+ self.addEventListener('install', function(event) {
133
+ // Perform install steps
134
+ event.waitUntil(
135
+ caches.open(CACHE_NAME)
136
+ .then(function(cache) {
137
+ return cache.addAll(urlsToCache);
138
+ })
139
+ );
140
+ });
141
+
142
+ self.addEventListener('fetch', function(event) {
143
+ const request = event.request;
144
+
145
+ // Skip caching for requests from browser extensions
146
+ if (request.url.startsWith('chrome-extension://')) {
147
+ return;
148
+ }
149
+
150
+ event.respondWith(
151
+ caches.match(request)
152
+ .then(function(response) {
153
+ // Cache hit - return response
154
+ if (response) {
155
+ return response;
156
+ }
157
+
158
+ // Clone the request
159
+ const fetchRequest = request.clone();
160
+
161
+ return fetch(fetchRequest).then(
162
+ function(response) {
163
+ // Check if we received a valid response
164
+ if(!response || response.status !== 200 || response.type !== 'basic') {
165
+ return response;
166
+ }
167
+
168
+ // Clone the response
169
+ const responseToCache = response.clone();
170
+ // Save the response for future matching
171
+ caches.open(CACHE_NAME)
172
+ .then(function(cache) {
173
+ cache.put(request, responseToCache);
174
+ });
175
+
176
+ return response;
177
+ }
178
+ );
179
+ })
180
+ );
181
+ });
182
+ ```
183
+ 8. Use this script tag to get access to the service worker at initial html page:
184
+
185
+ ```html
186
+ <script src="src/assets/service-worker.js"></script>
187
+ ```
188
+
189
+ or
190
+
191
+ it can be added in `angular.json` by installing the npm package
192
+
193
+ ```json
194
+ "scripts": [ ..., "src/assets/service-worker.js" ]
195
+ ```
196
+
197
+ 9. Register the service worker at your required place:
198
+ ```ts
199
+ ngAfterViewInit(): void {
200
+ if ('serviceWorker' in navigator) {
201
+ window.addEventListener('load', () => {
202
+ navigator.serviceWorker.register('/demo-app/assets/service-worker.js').then(
203
+ (registration) => {
204
+ console.log(
205
+ 'ServiceWorker registered with scope: ',
206
+ registration.scope
207
+ );
208
+ },
209
+ (err) => {
210
+ console.error('ServiceWorker registration failed: ', err);
211
+ }
212
+ );
213
+ });
214
+ }
215
+ }
216
+ ```
217
+
218
+ &nbsp;
219
+
220
+ ## Implementation Details for Vanilla JavaScript:
221
+
222
+ **Steps:-**
223
+
224
+ 1. Create or open an html file.
225
+
226
+ 2. Add a button with the id **`xxxx`**. It is used to call the widget by on click event.
227
+
228
+ ```html
229
+ <button id="xxxx">Open</button>
230
+ ```
231
+
232
+ 3. 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.
233
+
234
+ ```html
235
+ <div id="sonic-web-widget"></div>
236
+ ```
237
+
238
+ 4. Add a Script tag to the head tag or body tag. And use the latest version.
239
+
240
+ ```html
241
+ <script src="https://cdn.jsdelivr.net/npm/sonic-widget@2.7.52/dist/index.min.js"></script>
242
+ ```
243
+
244
+ 5. Next, add the script tag at a necessary place. But add below the widget script.
245
+
246
+ ```html
247
+ <script>
248
+ const config = {
249
+ baseurl: string, // the base url of the backend server
250
+ docModelPath: string, // the doc model url of the document recognition process
251
+ maskModelPath: string, // the mask model url of the mask detect process
252
+ faceModelUrl: string, // the face model url of the face recognition process
253
+ handModelUrl: string, // the hand model url of the hand recognition process
254
+ objectModelUrl: string, // the object model url of the object recognition process
255
+ ipInfoKey: string, // the ip info key
256
+ googleMapKey: string, // the google map key
257
+ googleCaptchaKey: string, // the google reCAPTCHA site key
258
+ passphrase: string, // the encryption key
259
+ showPage: boolean, // used to show the page or not
260
+ speedCheckURL: string, // public URL of the internet speed check
261
+ videoURL: string, // url of video to do (e.g: demo doing kyc) (Optional)
262
+ appId: string, // application policy identifier
263
+ appName: string, // representing name of the application (Optional)
264
+ accountId: string, // account can be taken from operator axiom account
265
+ userName: string, // user prospective data
266
+ userId: string, // user document number to identity
267
+ email: string, // user prospective data
268
+ phone: string, // user prospective data
269
+ applicationNo: string, // user prospective data
270
+ isMalay: boolean, //used to change the default language english to malay
271
+ branchId: string, // branch id to identify the branch of the bank
272
+ sendLogsEmail: boolean, //used to send logs through email
273
+ blinkThreshold: number, // threshold used to calculate the user's eye blinked or not, with range limit 0-1(default value is 0.35)
274
+ eyeOpenThreshold: number, // threshold used to calculate the user's eye open or not, with range limit 0-1(default value is 0.2)
275
+ disableUploadDocs: boolean, // used to pass a boolean value. It is used to disable the upload option the document process
276
+ objectPersonThreshold: number, // used for object Person score threshold with range limit 0-1(default value is 0.925)
277
+ objectPhoneThreshold: number, // used for object Phone score threshold with range limit 0-1(default value is 0.5)
278
+ grayscalePercentageThreshold: number, // used for black&white percentage score threshold with range limit 0-100(default value is 80)
279
+ onMessage: function (data) {}, // callback function, when api response message or error or any other actions
280
+ };
281
+ // get the element used in the action button
282
+ var container = document.getElementById('xxxx');
283
+ // on click of element widget works
284
+ container.addEventListener('click', function () {
285
+ sonic.SonicWidget(config);
286
+ });
287
+ </script>
288
+ ```
289
+
290
+ _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.
291
+ **`sonic.SonicWidget(config)`**_
292
+
293
+ _You can get the logs with **`onMessage`** for all actions and stages.
294
+ Check with **`data.code`**_
295
+
296
+ ```
297
+ 0 - info message from application
298
+ 1 - success api call
299
+ -1 - failed api call
300
+ -2 - error message from application
301
+ -3 - configuration error message
302
+ 2 - on close application
303
+ ```
304
+
305
+ **Note:-**
306
+
307
+ <!-- - _**`serviceWorkerPath`** should pass as a string value. It is used as the service worker path and its default path is **`/demo-app/assets/service-worker.js`** and Cache name should be different to fix conflict._ -->
308
+ - _**`baseurl`** should pass as a string value. It is used as the base URL for API calls._
309
+ - _**`docModelPath`** should pass as a string value. It is used as the base URL for document model._
310
+ - _**`maskModelPath`** should pass as a string value. It is used as the base URL for mask model._
311
+ - _**`faceModelUrl`** should pass as a string value. It is used as the base URL for task vision face model._
312
+ - _**`handModelUrl`** should pass as a string value. It is used as the base URL for task vision hand model._
313
+ - _**`objectModelUrl`** should pass as a string value. It is used as the base URL for coco-ssd object model._
314
+ - _**`showPage`** is used to pass a boolean value ( **`true`** or **`false`** ). To toggle the widget page open or close._
315
+ - _**`speedCheckURL`** should pass as a string value. It is used to detect internet speed and intimate the user._
316
+ - _**`videoURL`** should pass as a string value as url. It is used to show the video onboard sonic kyc and it is optional._
317
+ - _**`accountId`** should pass as a string value. It is used to get the JWT token and proceed with the operator account._
318
+ - _**`isMalay`** is used to pass a boolean value ( **`true`** or **`false`** ). To toggle the widget default language english or malay._
319
+ - _**`branchId`** should pass as a string value. It is used to find bank branch available for operator account for onboard sonic kyc._
320
+ - _**`appId`** should pass as a string value. It is used to find an application policy for onboard sonic kyc._
321
+ - _**`appName`** should pass as a string value. It is used for onboard kyc application name. it is optional and default **`Sonic`** ._
322
+ - _**`ipInfoKey`** should pass as a string value. It is used for location details and paid api key for VPN restriction. For more details visit **`https://ipinfo.io/`**._
323
+ - _**`googleMapKey`** should pass as a string value. It is used for location details and geo fence. For more details visit **`https://developers.google.com/maps`**._
324
+ - _**`googleCaptchaKey`** should pass as a string value. It is used for spam/bot attack. For more details visit **`https://developers.google.com/recaptcha`**._
325
+ - _**`passphrase`** should pass as a string value. It is used for encrypting the string with this special key and same key need to be used at backend also for decrypting the data._
326
+ - _**`userName`** should pass as a string value. It is used to create an application for onboard sonic kyc._
327
+ - _**`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._
328
+ - _**`email`** should pass as a string value. It is used to create an application for onboard sonic kyc._
329
+ - _**`phone`** should pass as a string value. It is used to create an application for onboard sonic kyc._
330
+ - _**`applicationNo`** should pass as a string value. It is used to create an application for onboard sonic kyc._
331
+ - _**`sendLogsEmail`** is used to pass a boolean value. It is used to send logs to client email address._
332
+ - _**`blinkThreshold`** is used to pass a numerical value. It is used to check the user blinking (range 0-1 and default 0.35). Above the threshold consider to be blinking or eye closed._
333
+ - _**`disableUploadDocs`** is used to pass a boolean value. It is used to disable the upload option the document process._
334
+ - _**`eyeOpenThreshold`** is used to pass a numerical value. It is used to check the user eyes are open (range 0-1 and default 0.2). Below the threshold consider to be eyes are open._
335
+ - _**`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)._
336
+ - _**`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)._
337
+ - _**`grayscalePercentageThreshold`** is used to pass a numerical value for percentage. It is used to check the image color as black&white found with required percentage as threshold (range 0-100 and default 80)._
338
+ - _**`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._
339
+
340
+
341
+ <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DEVELOPER info ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
342
+
343
+ <!-- use node 18 and install packages using yarn and do yarn dev -->
344
+
345
+ <!-- env -->
346
+
347
+ <!--
348
+ VITE_APP_DOCUMENT_DETECT_PATH=""
349
+ VITE_APP_MASK_DETECT_PATH=""
350
+ VITE_APP_COCO_SSD_OBJECT_URL="https://storage.googleapis.com/tfjs-models/savedmodel/ssdlite_mobilenet_v2/model.json"
351
+ VITE_APP_TASK_VISION_WASM_PATH="https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision/wasm"
352
+ VITE_APP_TASK_VISION_FACE_URL="https://storage.googleapis.com/mediapipe-models/face_landmarker/face_landmarker/float16/1/face_landmarker.task"
353
+ VITE_APP_TASK_VISION_HAND_URL="https://storage.googleapis.com/mediapipe-models/hand_landmarker/hand_landmarker/float16/1/hand_landmarker.task"
354
+ VITE_APP_DEFAULT_PASS_PHRASE=""
355
+ VITE_APP_THIRD_PARTY_GET_IP_URL="https://ipv4.icanhazip.com"
356
+ -->
357
+
358
+ <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GrayScale info ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
359
+
360
+ <!-- GrayScale Suggestions
361
+
362
+ 1. RGB Difference Threshold for Grayscale Detection:
363
+
364
+ Low Threshold: A low threshold (e.g., 5-10) is good if you want to consider any slight variation in color as an indication that the image is colored. This is more sensitive to minor color differences.
365
+
366
+ Moderate Threshold: A threshold of around 10-20 is a more balanced approach. It allows for small variations due to noise or minor imperfections in grayscale images but still classifies them as black and white.
367
+
368
+ High Threshold: A higher threshold (e.g., 20-50) will classify images as grayscale even if there are noticeable color variations, which might be acceptable for images that are predominantly black and white but have some color noise or artifacts.
369
+
370
+ 2. Percentage of Grayscale Pixels:
371
+
372
+ After detecting grayscale pixels, you need to determine the percentage of grayscale pixels required to classify the image as black and white.
373
+
374
+ 80-90% Grayscale Pixels: This threshold means that if 80-90% of the pixels are grayscale, the image will be classified as black and white. This works well for documents and images that are mostly grayscale but may have some minor color elements (e.g., stamps, logos).
375
+
376
+ 90-100% Grayscale Pixels: This is a stricter threshold, ensuring that the image is classified as black and white only if nearly all pixels are grayscale. -->
377
+
378
+ <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Selfie info ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
379
+
380
+ <!--
381
+ 1.blinkThreshold: number
382
+
383
+ Description : The blinkThreshold is used to determine whether the user's eye is considered blinked. It represents the sensitivity to eye closure during a blink.
384
+ Range : 0-1 (default: 0.35)
385
+ Functionality :
386
+ * If either of the user's eyes exceeds the specified threshold (i.e., the eye closure ratio is greater than the blinkThreshold), the eye is detected as "blinked."
387
+ * This helps identify blinks during facial detection or tracking processes.
388
+
389
+ 2.eyeOpenThreshold: number
390
+
391
+ Description : The eyeOpenThreshold is used to detect whether the user's eyes are open or not. It determines the sensitivity to eye openness by checking the openness ratio.
392
+ Range : 0-1 (default: 0.25)
393
+ Functionality :
394
+ * If both eyes fall below the defined threshold, the system interprets that the eyes are open.
395
+ * This value helps differentiate between an open eye and a partially closed
396
+
397
+ Both thresholds work together to archive ekyc selfie process.
398
+ -->
399
+