# bfastjs

> javascript client sdk for bfast::cloud project

Latest version **4.5.3** (published 2021-08-17) · ISC license · 0 weekly downloads

## Install

```sh
npm install bfastjs
pnpm add bfastjs
yarn add bfastjs
bun add bfastjs
```

## 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 | 4.5.3 |
| Published | 2021-08-17 |
| First published | 2019-08-30 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 349.9 KB |
| Known vulnerabilities | 0 (+23 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Fahamu Tech |
| Maintainers | fahamutech |

## Links

- npm: https://www.npmjs.com/package/bfastjs
- Repository: https://github.com/fahamutech/bfast-js
- Homepage: https://github.com/fahamutech/bfast-js#readme
- Issues: https://github.com/fahamutech/bfast-js/issues
- npm.io page: https://npm.io/package/bfastjs

## Dependencies (7)

- [axios](https://npm.io/package/axios.md) ~0.21.1
- [form-data](https://npm.io/package/form-data.md) ~4.0.0
- [bufferutil](https://npm.io/package/bufferutil.md) ~4.0.3
- [localforage](https://npm.io/package/localforage.md) ~1.9.0
- [utf-8-validate](https://npm.io/package/utf-8-validate.md) ~5.0.5
- [browser-or-node](https://npm.io/package/browser-or-node.md) ^1.3.0
- [socket.io-client](https://npm.io/package/socket.io-client.md) ~4.1.3

## Recent versions

- 4.5.3 (latest) — 2021-08-17
- 4.5.2 — 2021-07-28
- 4.5.1-alpha.3 — 2021-07-16
- 4.5.1-alpha.2 — 2021-07-16
- 4.5.1-alpha.0 — 2021-07-16
- 4.5.0 — 2021-07-14
- 4.4.0 — 2021-07-09
- 4.3.0 — 2021-07-07
- 4.2.9 — 2021-05-28
- 4.2.8 — 2021-05-28
- 4.2.7 — 2021-05-28
- 4.2.6 — 2021-05-28
- 4.2.5 — 2021-04-21
- 4.2.4 — 2021-04-14
- 4.2.3 — 2021-04-13
- … 106 more at https://npm.io/package/bfastjs/versions

## README

# BFast::Cloud | JS Client SDK

Sdk library to be used in a client-side web like (Angular, React) and NodeJs env.

## Get Started

*Web*

You can use `https://www.unpkg.com/bfastjs` to add it as a `<script src="https://www.unpkg.com/bfastjs"></script>` direct to your
html file. Or you can install it direct from npm.
```shell script
john@pc:~$ npm install --save bfastjs
```

*NodeJs*
```shell script
john@pc:~$ npm install --save bfastnode
```

***Note***
For bfastjs < 3.x.x work with bfast-daas < 1.x.x and bfast-faas < 1.x.x

## SetUp

Before you call any API you need to initialize your SDK

```javascript
const {bfast} = require('bfastjs');

BFast.init({
    applicationId: 'your-bfast-project-applicationId', // required if you connect to bfast cloud project [ optional if you have a bfast cloud project]
    projectId: 'your-bfast-project-projectId', // required if you connect to bfast cloud project [ optional if you have a bfast cloud project]
    appPassword: 'your-bfast-project-password', // this is the master-key to override any authorization from bfast cloud, you get it from from bfast cloud project [ optional if you have a bfast cloud project]
    functionsURL: 'a url to your FaaS engine', // if you have a faas engine served in your servers other that bfast cloud
    databaseURL: 'a url to your DaaS engine', // if you have a daas engine served in your servers other than bfast cloud
    cache: {
        collection: 'any name',
        ttlCollection: 'any name',
        enable: false // default is false
    } // this is optional if you need to override a default cache configuration
}, 'your-app-name');
```

if you don't supply app name DEFAULT_APP name will be used. That all you need to set up a bfast sdk.
You will only call this once in your app just before you use any api this sdk.

## React | NextJS Support

Create useBFast.js file:

```javascript
import { useRef, useState, useEffect } from "react";

export default function useBFast() {
  const dbRef = useRef();
  const [isDBLoaded, setIsDBLoaded] = useState(false);
  const { BFast } = dbRef.current || {};

  useEffect(() => {
    dbRef.current = {
      BFast: require("bfastjs").BFast,
    };

    setIsDBLoaded(true);
  }, []);

  return Object.freeze({
    isDBLoaded,
    BFast,
  });
}
```

Use in app as:

```javascript
import useBFast from "../PATH_TO/useBFast";

export default function MyComponent(props) {
  const { isDBLoaded, BFast } = useBFast();
  
  useEffect(() => {
    if (isDBLoaded) {
      console.log(BFast);
      // use BFast
      BFast.BFast.init({
        applicationId: "",
        projectId: "",
      });
    }
  }, [isDBLoaded]);

  return (
    <>
      <div>
        BFast App!
      </div>
    </>
  );
}
```

## Database

You can manipulate a database instance from bfast cloud project or the instance you deploy in your own infrastructure.

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