# sabil-js

> Sabil JS SDK

Latest version **2.6.1** (published 2023-01-10) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install sabil-js
pnpm add sabil-js
yarn add sabil-js
bun add sabil-js
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 2.6.1 |
| Published | 2023-01-10 |
| First published | 2022-07-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 74.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | ahmedsabil |
| Keywords | account sharing prevention, sabil |

## Links

- npm: https://www.npmjs.com/package/sabil-js
- npm.io page: https://npm.io/package/sabil-js

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 2.6.1 (latest) — 2023-01-10
- 2.5.1 — 2022-12-07
- 2.5.0 — 2022-10-31
- 2.4.4 — 2022-10-27
- 2.4.2 — 2022-10-12
- 2.4.1 — 2022-10-11
- 2.4.0 — 2022-09-16
- 2.3.0 — 2022-08-30
- 2.2.0 — 2022-08-29
- 2.1.0 — 2022-08-25
- 2.0.3 — 2022-08-18
- 2.0.2 — 2022-08-18
- 2.0.1 — 2022-08-18
- 2.0.0 — 2022-08-18
- 1.1.1 — 2022-07-30
- … 2 more at https://npm.io/package/sabil-js/versions

## README

# Sabil JavaScript SDK

This is the official Sabil API client for JavaScript.

- [Documentation](https://www.sabil.io/docs/javascript/quick-start)

### Installation

```sh
yarn add sabil-js
```

or if using npm

```sh
npm install --save sabil-js
```

### Import

```js
import Sabil from "sabil-js";
```

_Note_ the common js version can be found in `sabil-js/common.cjs`

### Usage

- Cal the `attach` function to attach the device to the user. You must pass the `client_id` and a `user`.

```js
try {
  const { device_id } = await Sabil.attach({
    client_id: `client_id`,
    user: `user_id`,
    appearance_config: {
      font_family: `Inter, sans-serif`,
    },
  });
} catch (error) {
  console.error(error);
}
```

Ideally, you should call the `attach` function on every page as soon as you have the user id available. Alternatively, you can call it only when the user id becomes available and/or on key entry pages like the dashboard, login, ...etc.

- Detaching a user device

By default, the devices are automatically detached if they are not used for 1 week. You can change this behavior in the [dashboard settings](https://dashboard.sabil.io/settings). But it might be useful to manually detach the devices sometimes. For example, if the user logs out, it's good to detach the device. If you need to manually detach the device, do the following:

```js
try {
  await Sabil.detach({
    client_id: `client_id`,
    user: `user_id`,
    device: `device_id`,
  });
} catch (error) {
  console.error(error);
}
```

The `device` field takes the device ID that is returned in the `attach` function response as `device_id`.

That's it. To learn more, visit the [documentation](https://www.sabil.io/docs/javascript/quick-start)

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