# @lenra/client

> Create your JavaScript application with a Lenra backend.

Latest version **1.4.1** (published 2024-02-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install @lenra/client
pnpm add @lenra/client
yarn add @lenra/client
bun add @lenra/client
```

## 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.4.1 |
| Published | 2024-02-08 |
| First published | 2023-09-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 112 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Lenra |
| Maintainers | flavien_lenra, taorepoara |
| Keywords | Lenra, app, application, lib, client |

## Links

- npm: https://www.npmjs.com/package/@lenra/client
- Repository: https://github.com/lenra-io/client-lib-js
- Homepage: https://github.com/lenra-io/client-lib-js.git#readme
- Issues: https://github.com/lenra-io/client-lib-js/issues
- npm.io page: https://npm.io/package/@lenra/client

## Dependencies (3)

- [phoenix](https://npm.io/package/phoenix.md) ^1.7.7
- [fast-json-patch](https://npm.io/package/fast-json-patch.md) ^3.1.1
- [@badgateway/oauth2-client](https://npm.io/package/@badgateway/oauth2-client.md) ^2.2.3

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 1.4.1 (latest) — 2024-02-08
- 1.4.0 — 2024-02-07
- 1.3.0 — 2024-01-25
- 1.2.0 — 2024-01-18
- 1.1.2 — 2023-10-31
- 1.1.1 — 2023-10-31
- 1.1.0 — 2023-10-24
- 1.1.0-beta.1 — 2023-10-24
- 1.0.0 — 2023-09-29
- 1.0.0-beta.4 — 2023-09-29
- 1.0.0-beta.3 — 2023-09-20
- 1.0.0-beta.2 — 2023-09-13
- 1.0.0-beta.1 — 2023-09-13

## README

<div id="top"></div>
<!--
*** This README was created with https://github.com/othneildrew/Best-README-Template
-->



<!-- PROJECT SHIELDS -->
[![Contributors][contributors-shield]][contributors-url]
[![Forks][forks-shield]][forks-url]
[![Stargazers][stars-shield]][stars-url]
[![Issues][issues-shield]][issues-url]
[![MIT License][license-shield]][license-url]



<!-- PROJECT LOGO -->
<br />
<div align="center">

<h3 align="center">Lenra's JavaScript client lib</h3>

  <p align="center">
    Let you create your JavaScript application with Lenra backend.
    <br />
    <br />
    <a href="https://github.com/lenra-io/client-lib-js/issues">Report Bug</a>
    ·
    <a href="https://github.com/lenra-io/client-lib-js/issues">Request Feature</a>
  </p>
</div>




<!-- GETTING STARTED -->

## Prerequisites

Add the dependency to your project:

```console
npm i @lenra/client
```

<p align="right">(<a href="#top">back to top</a>)</p>


<!-- USAGE EXAMPLES -->
## Usage

Create a `LenraApp` in your :

```javascript
import { LenraApp } from '@lenra/client';

const app = new LenraApp({
    appName: "Example Client",
    clientId: "XXX-XXX-XXX",
});
```

Authenticate the user and open the websocket connection:

```javascript
app.connect();
```

You also can manage them separatly:
  
```javascript
const token = app.authenticate();
app.openSocket(token);
```

Or just open the websocket connection without authentication:

```javascript
app.openSocket();
```

This while automatically start the authentication flow.

You can then connect to a Lenra route to use it data:

```javascript
const route = app.route(`/${counter.id}`, (data) => {
    // Handle data
});
```

You can also call a listener given by the route:

```javascript
// calling directly the listener
button1.onclick = () => {
  data.increment().then(() => {
      // When the listener is finished
  });
};
// or from the route
button2.onclick = () => {
  route.callListener(data.decrement).then(() => {
      // When the listener is finished
  });
};
```

This [the full example](./example/src/index.js) for more informations.


For the web target, you also have to add the following JavaScript to a redirect file (default to `redirect.html`) to handle OAuth2 redirection (see the [example](./example/redirect.html)):

```javascript
window.onload = function() {
  window.opener.postMessage(window.location.href, `${window.location.protocol}//${window.location.host}`);
}
```

<p align="right">(<a href="#top">back to top</a>)</p>


<!-- CONTRIBUTING -->
## Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.

If you have a suggestion that would make this better, please open an issue with the tag "enhancement".
Don't forget to give the project a star if you liked it! Thanks again!

<p align="right">(<a href="#top">back to top</a>)</p>



<!-- LICENSE -->
## License

Distributed under the **MIT** License. See [LICENSE](./LICENSE) for more information.

<p align="right">(<a href="#top">back to top</a>)</p>



<!-- CONTACT -->
## Contact

Lenra - [@lenra_dev](https://twitter.com/lenra_dev) - contact@lenra.io

Project Link: [https://github.com/lenra-io/client-lib-js](https://github.com/lenra-io/client-lib-js)

<p align="right">(<a href="#top">back to top</a>)</p>


<!-- MARKDOWN LINKS & IMAGES -->
<!-- https://www.markdownguide.org/basic-syntax/#reference-style-links -->
[contributors-shield]: https://img.shields.io/github/contributors/lenra-io/client-lib-js.svg?style=for-the-badge
[contributors-url]: https://github.com/lenra-io/client-lib-js/graphs/contributors
[forks-shield]: https://img.shields.io/github/forks/lenra-io/client-lib-js.svg?style=for-the-badge
[forks-url]: https://github.com/lenra-io/client-lib-js/network/members
[stars-shield]: https://img.shields.io/github/stars/lenra-io/client-lib-js.svg?style=for-the-badge
[stars-url]: https://github.com/lenra-io/client-lib-js/stargazers
[issues-shield]: https://img.shields.io/github/issues/lenra-io/client-lib-js.svg?style=for-the-badge
[issues-url]: https://github.com/lenra-io/client-lib-js/issues
[license-shield]: https://img.shields.io/github/license/lenra-io/client-lib-js.svg?style=for-the-badge
[license-url]: https://github.com/lenra-io/client-lib-js/blob/master/LICENSE

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