# will-lib

> Library classes

Latest version **1.0.22** (published 2023-10-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install will-lib
pnpm add will-lib
yarn add will-lib
bun add will-lib
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.22 |
| Published | 2023-10-04 |
| First published | 2022-11-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=15 |
| Dependencies | 14 |
| Unpacked size | 122.3 KB |
| Known vulnerabilities | 0 (+12 in 1 direct dependencies) |
| Install scripts | no |
| Author | tassun_oro@hotmail.com |
| Maintainers | tassun_oro |
| Keywords | PasswordLibrary, MailLibrary, BasicLibrary, AuthenLibrary, ActiveLibrary, CaptchaLibrary |

## Links

- npm: https://www.npmjs.com/package/will-lib
- Repository: https://github.com/tassun/will-lib
- Homepage: https://github.com/tassun/will-lib#readme
- Issues: https://github.com/tassun/will-lib/issues
- npm.io page: https://npm.io/package/will-lib

## Dependencies (14)

- [path](https://npm.io/package/path.md) ^0.12.7
- [axios](https://npm.io/package/axios.md) ^1.1.3
- [bcrypt](https://npm.io/package/bcrypt.md) ^5.1.0
- [canvas](https://npm.io/package/canvas.md) ^2.10.2
- [config](https://npm.io/package/config.md) ^3.3.8
- [uuidv4](https://npm.io/package/uuidv4.md) ^6.2.13
- [node-rsa](https://npm.io/package/node-rsa.md) ^1.1.1
- [will-sql](https://npm.io/package/will-sql.md) ^1.0.23
- [random-js](https://npm.io/package/random-js.md) ^2.1.0
- [will-util](https://npm.io/package/will-util.md) ^1.0.6
- [nodemailer](https://npm.io/package/nodemailer.md) ^6.8.0
- [randomcolor](https://npm.io/package/randomcolor.md) ^0.6.2
- [jsonwebtoken](https://npm.io/package/jsonwebtoken.md) ^9.0.2
- [activedirectory](https://npm.io/package/activedirectory.md) ^0.7.2

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 1.0.22 (latest) — 2023-10-04
- 1.0.21 — 2023-09-23
- 1.0.20 — 2023-09-13
- 1.0.19 — 2023-08-23
- 1.0.18 — 2023-08-19
- 1.0.17 — 2023-08-18
- 1.0.16 — 2023-08-11
- 1.0.15 — 2023-08-08
- 1.0.14 — 2023-08-08
- 1.0.13 — 2023-08-07
- 1.0.12 — 2023-08-05
- 1.0.11 — 2023-08-05
- 1.0.10 — 2023-08-04
- 1.0.9 — 2023-08-02
- 1.0.8 — 2023-01-18
- … 8 more at https://npm.io/package/will-lib/versions

## README

# will-lib

Library classes

## Installation

    npm install will-lib

### Configuration

This module require configuration ([config](https://www.npmjs.com/package/config)) setting by config/default.json under project and [will-sql](https://www.npmjs.com/package/will-sql), [will-util](https://www.npmjs.com/package/will-util)

    npm install config

config/default.json

```json
{
    "MYSQL" : { "alias": "mysql", "dialect": "mysql", "url": "mysql://user:password@localhost:3306/testdb?charset=utf8&connectionLimit=10", "user": "user", "password": "password" },
    "ODBC" : { "alias": "odbc", "dialect": "mysql", "url": "DRIVER={MySQL ODBC 5.3 Unicode Driver};SERVER=localhost;DATABASE=testdb;HOST=localhost;PORT=3306;UID=user;PWD=password;", "user": "user", "password": "password" },
    "MSSQL": { "alias": "mssql", "dialect": "mssql", "url": "Server=localhost,1433;Database=testdb;User Id=user;Password=password;Encrypt=false;Trusted_Connection=Yes;", "user": "user", "password": "password" },
    "ORACLE": { "alias": "oracle", "dialect": "oracle", "url": "localhost:1521/ORCLCDB.localdomain", "user": "user", "password": "password" },
    "POSTGRES": { "alias": "postgres", "dialect": "postgres", "url": "postgresql://user:password@localhost:5432/testdb", "user": "user", "password": "password" },
    "INFORMIX": { "alias": "odbc", "dialect": "informix", "url": "DRIVER={IBM INFORMIX ODBC DRIVER (64-bit)};SERVER=online_localhost;DATABASE=refdb;HOST=localhost;SERVICE=9088;UID=user;PWD=password;CLIENT_LOCALE=th_th.thai620;DB_LOCALE=th_th.thai620;", "user": "user", "password":"password" }
}
```

    npm install will-sql
    npm install will-util

#### PasswordLibrary
PasswordLibrary handle for user password maintainance 

#### Usage

```typescript
import { PasswordLibrary } from "will-lib";
import { DBConnections } from "will-sql";
import { Arguments } from "will-util";

let args = process.argv.slice(2);
console.log("args = "+args);
let section = Arguments.getString(args,"MYSQL","-ms");

let plib : PasswordLibrary = new PasswordLibrary();
let ranpwd = PasswordLibrary.randomPassword();
console.log(ranpwd);
console.log("alphabets",PasswordLibrary.getAlphabets(ranpwd));
console.log("digits",PasswordLibrary.getDigits(ranpwd));
console.log("indexOfAlphabet",PasswordLibrary.indexOfAlphabets(ranpwd));
console.log("newpwd",PasswordLibrary.createNewPassword());
let newpwd = plib.createPassword();
console.log("pass",newpwd);
let epwd = plib.encryptPassword(newpwd);
console.log("encpwd",epwd);
console.log(ranpwd,PasswordLibrary.checkNumberOnly(ranpwd));
let num = "12345678";
console.log(num,PasswordLibrary.checkNumberOnly(num));
console.log("checkAlphainpwd",plib.checkAlphainpwd(ranpwd));

async function doCheckPassword() {
    try {
        let plib : PasswordLibrary = new PasswordLibrary();
        let conn = DBConnections.getDBConnector(section);
        let valid = await plib.verifyPassword(conn,site,userid,pwd);
        console.log("verifyPassword",valid);
    } catch(ex) {
        console.error(ex);
    }
}

async function doChangePassword() {
    try {
        let conn = DBConnections.getDBConnector(section);
        await conn.beginWork();
        try {
            let plib : PasswordLibrary = new PasswordLibrary();
            let verify = await plib.changePassword(conn,site,userid,pwd,newpwd,date);
            console.log("verify",verify);
            await conn.commitWork();    
        } catch(er) {
            console.error(er);
            conn.rollbackWork();
            console.log("roll back work");
        }
    } catch(ex) {
        console.error(ex);
    }
}

```

#### MailLibrary

MailLibrary handle for send mail with custom configuration from database table `tconfig` with schema
    
    CREATE TABLE tconfig (
	    category VARCHAR(50) NOT NULL,
	    colname VARCHAR(50) NOT NULL,
	    colvalue VARCHAR(250) NULL DEFAULT NULL,
	    seqno INT NULL DEFAULT '0',
	    remarks TEXT NULL,
	    PRIMARY KEY (category, colname)
    )

configuration table data 

| category | colname | colvalue | remarks |
| -------- | ---- | ------- | ----------- |
| CONFIGMAIL | MAIL_FROM | **required** | Sender email |
| CONFIGMAIL | MAIL_USER | **required** | Sender user |
| CONFIGMAIL | MAIL_PASSWORD | **required** | Sender password |
| CONFIGMAIL | MAIL_SERVER | **required** | Mail server address |
| CONFIGMAIL | MAIL_PORT | **required** | Mail server port |
| CONFIGMAIL | MAIL_TITLE | optional | Mail title |


```typescript
import { Arguments } from "will-util";
import { DBConnections } from "will-sql";
import { MailInfo, MailLibrary } from "will-lib";

let args = process.argv.slice(2);
console.log("args = "+args);
let section = Arguments.getString(args,"MYSQL","-ms");
let mail_to = Arguments.getString(args,'email@mail.com','-t');
let mail_subject = Arguments.getString(args,'Testing','-s');
let mail_message = Arguments.getString(args,'Hello Test','-m');

async function testMail() {
    let info : MailInfo = {
        email: mail_to as string,
        subject: mail_subject as string,
        message: mail_message as string
    };
    console.log("send mail",info);
    let conn = DBConnections.getDBConnector(section);
    let res = await MailLibrary.sendMail(info, conn);
}

testMail();
```

#### BasicLibrary

BasicLibrary handle for basic authentication and basic authenticate with RSA from table `ttenant` setting with schema

    CREATE TABLE `ttenant` (
        `tenantid` VARCHAR(50) NOT NULL,
        `tenantname` VARCHAR(100) NOT NULL,
        `applicationid` VARCHAR(50) NOT NULL,
        `inactive` VARCHAR(1) NOT NULL DEFAULT '0' COMMENT '1=Inactive',
        `privatekeys` TEXT NOT NULL,
        `publickeys` TEXT NOT NULL,
        PRIMARY KEY (`tenantid`),
        INDEX `applicationid` (`applicationid`)
    )

```typescript
import { Arguments } from "will-util";
import { DBConnections } from "will-sql";
import { BasicLibrary } from "will-lib";

let args = process.argv.slice(2);
console.log("args = "+args);
let section = Arguments.getString(args,"MYSQL","-ms");
let clientid = Arguments.getString(args,"","-cid","-client");
let plaintext = Arguments.getString(args,"","-txt");
let ciphertext = Arguments.getString(args,"","-ctxt");

async function doBasic() {
    try {
        let conn = DBConnections.getDBConnector(section);
        try {
            let blib : BasicLibrary = new BasicLibrary();
            if(clientid) {
                let info = await blib.getTenantInfo(conn,clientid as string);
                console.log("tenant",info);    
                if(plaintext) {
                    let txt = await blib.encrypt(plaintext, clientid, conn);
                    console.log("encrypt",txt);
                }
                if(ciphertext) {
                    let txt = await blib.decrypt(ciphertext, clientid, conn);
                    console.log("decrypt",txt);
                }
            } else {
                if(plaintext) {
                    let txt = await blib.encrypt(plaintext);
                    console.log("encrypt",txt);
                }
                if(ciphertext) {
                    let txt = await blib.decrypt(ciphertext);
                    console.log("decrypt",txt);
                }
            }
        } catch(er) {
            console.error(er);
        }
    } catch(ex) {
        console.error(ex);
    }
}

testBasic();
```

---
_Source: https://npm.io/package/will-lib · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
