# finnotech-client-sdk

> Implementing a client sdk to request our services and show the results to user

Latest version **1.1.2** (published 2023-06-07) · ISC license · 0 weekly downloads

## Install

```sh
npm install finnotech-client-sdk
pnpm add finnotech-client-sdk
yarn add finnotech-client-sdk
bun add finnotech-client-sdk
```

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2023-06-07 |
| First published | 2023-06-02 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 7 |
| Unpacked size | 53.9 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Ali Moradzade |
| Maintainers | ali-moradzade |

## Links

- npm: https://www.npmjs.com/package/finnotech-client-sdk
- Repository: https://github.com/https-github-com-ali-moradzade/client-sdk
- Homepage: https://github.com/https-github-com-ali-moradzade/client-sdk#readme
- Issues: https://github.com/https-github-com-ali-moradzade/client-sdk/issues
- npm.io page: https://npm.io/package/finnotech-client-sdk

## Dependencies (7)

- [uuid](https://npm.io/package/uuid.md) ^9.0.0
- [axios](https://npm.io/package/axios.md) ^1.4.0
- [redis](https://npm.io/package/redis.md) ^4.5.1
- [bunyan](https://npm.io/package/bunyan.md) ^1.8.15
- [dotenv](https://npm.io/package/dotenv.md) ^16.0.3
- [js-yaml](https://npm.io/package/js-yaml.md) ^4.1.0
- [concurrently](https://npm.io/package/concurrently.md) ^7.6.0

## Recent versions

- 1.1.2 (latest) — 2023-06-07
- 1.1.1 — 2023-06-06
- 1.0.9 — 2023-06-06
- 1.0.8 — 2023-06-06
- 1.0.7 — 2023-06-06
- 1.0.6 — 2023-06-03
- 1.0.5 — 2023-06-03
- 1.0.4 — 2023-06-03
- 1.0.3 — 2023-06-03
- 1.0.2 — 2023-06-02
- 1.0.1 — 2023-06-02
- 1.0.0 — 2023-06-02

## README

# Client SDK

This is a wrapper to call the apis from [Finnotech](https://finnotech.ir/doc/), note that this client only works
with `Client_Credential` type services.

## Installation

You can install this package with the following command:

```bash
npm i finnotech-client-sdk
```

### Create a new client

You can create a new client with the following code:

```typescript
import {ClientSDK} from "./ClientSDK";

const clientSDK = new ClientSDK(); // to use staging url: new ClientSDK(true);
```

You should configure .env file before using client:

```dotenv
# Client Configuration
CLIENT_NID=""
CLIENT_ID=""
CLIENT_PASSWORD=""

# Redis Configuration
REDIS_HOST="localhost"
REDIS_PORT="6379"

# Logger Configuration
LOG_PATH="/var/tmp/ClientSDK.log"
```

`CLIENT_ID` is the client id which you get from [Finnotech](https://console.finnotech.ir/reportLogin), in applications section.  
`CLIENT_PASSWORD` is the client password which you get from [Finnotech](https://console.finnotech.ir/reportLogin), in applications
section.  
`CLIENT_NID` is the client nid

### Call a service

You can call a service with `callService` method:

```typescript
const response = await clientSDK.callService(serviceName, payload);
```

`serviceName` is the name of the service which you want to call, and it should be in `config.yaml` file.  
`payload` is the payload which you want to send to the service.

Note: `callService` method returns a promise, so you should use `await` keyword.

## Run

To automatically compile and run the project, you can put your codes inside `src/index.ts` file and run the following
command:

```bash
npm run start
```

## Docker

To run the project in docker, you can use the following command:

```bash
docker-compose up --build
```

This command will build the images and run your index.ts file and all the tests.

For stopping the docker, you can use the following command:

```bash
docker-compose down
```

## Example

```typescript
import {ClientSDK} from "./ClientSDK";
import {v4 as uuid} from 'uuid';

// Create a new client, use redis from localhost
const clientSDK = new ClientSDK();

const result = await clientSDK.callService('billingInquiry', {
    trackId: uuid(),
    type: "Tel",
    parameter: "021xxxxxxx1",
    secondParameter: "MCI"
})

console.log(result);
```

Resulting output should look like:

```javascript
{
    responseCode: 'FN-BGVH-20000000000',
    trackId: 'de8d92dd-e6fd-4dee-b61b-1a80d1a771dd',
    result: {
        Amount: '1195000',
        BillId: '89xxxxxxx48',
        PayId: '1xxxxxxx9',
        Date: ''
    } ,
    status: 'DONE'
}
```

## Testing

To test the client, you can use following command:

```bash
npm run test
```

Client sdk tests are in `ClientSDK.spec.ts` file.

Note: If you did not pass `redisUrl` to the client, Be sure that you have `redis` installed and running on `redis://localhost:6379`.

## Logging

Configure log path: `LOG_PATH` in `.env` file.

```dotenv
# Logger Configuration
LOG_PATH="/var/tmp/ClientSDK.log"
```

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