<!-- # React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:

- Configure the top-level `parserOptions` property like this:

```js
   parserOptions: {
    ecmaVersion: 'latest',
    sourceType: 'module',
    project: ['./tsconfig.json', './tsconfig.node.json'],
    tsconfigRootDir: __dirname,
   },
```

- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list

 -->

<center> 

<h1> Curator WEB SDK </h1>

[![version](https://img.shields.io/npm/v/curator-bb?style=flat)](https://www.npmjs.com/package/curator-bb)
[![npm package minimized gzipped size (select exports)](https://img.shields.io/bundlejs/size/curator-bb)](https://www.npmjs.com/package/curator-bb)
[![downloads](https://img.shields.io/npm/dm/curator-bb?style=flat)](https://www.npmjs.com/package/curator-bb)
[![jsdelivr](https://data.jsdelivr.com/v1/package/npm/curator-bb/badge)](https://www.jsdelivr.com/package/npm/curator-bb)
[![NPM](https://img.shields.io/npm/l/curator-bb)](https://www.jsdelivr.com/package/npm/curator-bb)

</center>

## Description :-

> _**curator-bb**_ - _used to validate users at any web form. It is made up of React, TypeScript & Vite._

#### i). Overview

- The Curator Web SDK serves the primary purpose of validating preregistered users to enhance client app privacy and protect against potential security threats.
- The package exposes two key APIs: 'initialize' and 'curate'.
- The 'initialize' API facilitates the registration of users on the client app by making a request to the Axiom Protect server. This request includes parameters such as serverURL, operatorId, appId, and password.
- Users are required to define their form key name fields for inclusion in the Axiom policy under the pre-registration tab.
- Upon submitting the form, the 'curate' API is invoked, sending a request to the server, which responds with either 'true' or 'false' based on user validation. This information determines whether the user can proceed with the registration process in the client app.

<!-- #### ii). Third party API's/Packages for getting device details

- `fingerprintjs` package is using to get the device id.
- `react-device-detect` package is using to get the device details like browserName, browserVersion deviceType, engineName, engineVersion, fullBrowserVersion, mobileModel, mobileVendor, osName, osVersion etc.
- Using `https://api64.ipify.org?format=json` this third party API to get the IpAddress of the device.
- Using `https://api.bigdatacloud.net/data/reverse-geocode-client` this third party API to get the country name of the device.
- Using browsers navigator for getting the location of the device (lat & long). -->

---

## Installation :-

#### i). Install at HTML pages

- **Step 1:** Be ready with HTML form and import the package

```html
<script type="module">
   // import curator package
   import curatorBB from 'https://cdn.jsdelivr.net/npm/curator-bb@0.1.1/+esm'
</script>
```

- **Step 2:** Initially, call `initialize` function to get the curator service
```js
   // initialize curator operator
   curatorBB.initialize({
      serverURL: string,
      operatorId: string,
      appId:string,
      password: string,
      onMessage: (arg) => { }
   });
```

**Note:** It is recommended to call `initialize` function before calling user validator.

| Key | Required | value | Description | 
| ----------- | :-----------: | :-----------: | :----------- |
| **serverURL** | `true` | string | *It is used call the back office server base URL.* | 
| **operatorId** | `true` | string | *It is used to identify the operator/developer, who created account at back office.* | 
| **appId** | `true` | string | *It is used to uniquely identify the application.* | 
| **password** | `true` | string | *It is used to validate the operator/developer.* | 
| **onMessage** | `false` | function | *It is used get the response with more details (Optional).* |


- **Step 3:** Call `curate` function to get the curator service
```js
   // form submission with curator for validating user
   curatorBB.curate({
      userDetails: object, 
      onMessage: (arg) => { }
   });
```

**Note:** It is recommended to call `curate` function after initializing the operator/developer. And make sure you prevent default. 

Example :-
```js
document.addEventListener("DOMContentLoaded", function () {
   document.getElementById("myForm").addEventListener("submit", function (event) {
      // Prevent the default form submission behavior
      event.preventDefault();
      ...
      // call curate
      curatorBB.curate({
         ...
      });
   }
}
```

| Key | Required | value | Description | 
| ----------- | :-----------: | :-----------: | :----------- |
| **userDetails** | `true` | object | *It is used to get the user details, given in the form.* |  
| **onMessage** | `false` | function | *It is used get the response with more details (Optional).* |


_You can get the return response or can use **`onMessage`** to know more about the return response. Use with one argument and check for **`arg.code`**_

- 0 - failed message
- 1 - success message
- 2 - info message
- -1 - error message 

---

## Authors

- [@Shankaresh](https://github.com/shankareshBB)
- [@Suresh](https://github.com/suresh-khairnar)