# humanapi-connect-client

> [![NPM](https://nodei.co/npm/humanapi-connect-client.png)](https://nodei.co/npm/humanapi-connect-client/)

Latest version **2.4.5** (published 2026-01-27) · 0 weekly downloads

## Install

```sh
npm install humanapi-connect-client
pnpm add humanapi-connect-client
yarn add humanapi-connect-client
bun add humanapi-connect-client
```

## Health

**Score 45/100 (D)** — status: stable.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 2.4.5 |
| Published | 2026-01-27 |
| First published | 2018-07-26 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 121.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | human-api, hapideploy, hapi-deploy, pjpastrana, brian_hapi, sagar_hapi, pankaj_hapi, huichops_hapi, arunkadari_hapi, gus_hapi, rafasalazarzx, hapi-joonhyuk-kang, hapi_juan_perez, dianaglzrico, joaquintrevino, hidalgo_fernandez, danielrosales, ivan_parada, vaibhav_hapi, davidbeach, abdelhumanapi, felipehapi, k.hansen1987, hapi-pratik2, itamadmin, puneet_isarka, bdarosa, ajp-sourceship, herve.tcheukado, huan.mai, marco.murakami.hapi, isaackuriln, andres.mg, diego.robmen, nick.pashkov.humanapi, rubenoalvarado, raul.rodriguez.hapi, nirmalchoudhari, talapanv, keshavgarg4995, neha_hapi |

## Links

- npm: https://www.npmjs.com/package/humanapi-connect-client
- npm.io page: https://npm.io/package/humanapi-connect-client

## Dependencies (3)

- [core-js](https://npm.io/package/core-js.md) ^3.6.5
- [focus-trap](https://npm.io/package/focus-trap.md) ^6.2.3
- [@babel/runtime-corejs3](https://npm.io/package/@babel/runtime-corejs3.md) ^7.9.6

## Recent versions

- 2.4.5 (latest) — 2026-01-27
- 2.4.5-beta.4 (beta) — 2025-12-22
- 2.4.0-alpha.0 (alpha) — 2021-06-10
- 2.0.0-rc.3 (rc) — 2020-02-10
- 2.4.5-beta.3 — 2025-12-22
- 2.4.5-beta.2 — 2025-12-22
- 2.4.5-beta.1 — 2025-12-17
- 2.4.4 — 2024-10-03
- 2.4.4-beta.3 — 2024-09-11
- 2.4.4-beta.2 — 2024-09-11
- 2.4.4-beta.1 — 2024-09-10
- 2.4.4-beta.0 — 2024-09-10
- 2.4.3 — 2022-05-18
- 2.4.3-beta.0 — 2022-05-17
- 2.4.2 — 2022-05-06
- … 61 more at https://npm.io/package/humanapi-connect-client/versions

## README

# Human API Connect Client
[![NPM](https://nodei.co/npm/humanapi-connect-client.png)](https://nodei.co/npm/humanapi-connect-client/)

## Table of contents

- [Description](#description)
- [Installation](#installation)
- [Lifecycle Hooks](#lifecycle-hooks)
- [Upgrade from 1.x.x](#upgrade-from-1xx)

## Looking for `1.x` documentation?

The documentation below is for `humanapi-connect-client@2`. We have recently released a new Connect integration client version that replaces the old 1.x.x version that has been deprecated.

It is recommended that you use this new client version which is backwards compatible to make the transition easier.

[Click here](https://github.com/humanapi/connect-client/tree/4e5ab9ff1c41946f5320fbe3e457ce0e4b117caf) for `humanapi-connect-client@1.x` documentation.

---

## Description

Connect is the authentication widget for your application to allow users to share their health data. After a user has successfully granted you access to their health data using Connect, you'll be able to query their disparate data directly from Human API. 

Please refer to the [connect guide](http://myhealthdata.co/connect-guide) for full instructions on how to use the Connect client.

## Installation

This module can be used by loading the script from our CDN or by installing the npm module.

### CDN
To use the library via our CDN you can include the following script source:

```html
<script src="https://cdn.humanapi.co/humanapi-connect-client@latest.js">
```

### NPM module
To install the npm module and use it with e.g. React:

```sh
npm install --save humanapi-connect-client
```

## Usage

To use this library regardless of the method used, you first need to acquire a session token and set it as the data-attribute `data-hapi-token` of an element that supports the `onclick` event (e.g. a button). Then, you need to add the class `hapi__token-container` to the parent of the element that has the token value, e.g.: 

```html
<div class="hapi__token-container">
    <button data-hapi-token="<your session token>">Open Connect</button>
</div>
```

**Note:** Make sure that the element containing the class `hapi__token-container` is rendered on page load.

The library will then automatically configure all elements with the `data-hapi-token` attribute under that parent, to allow them to open the Connect window.

### Lifecycle hooks

`humanapi-connect-client` can be configured to respond to the following lifecycle hooks:
 
 - `connect`: This event will be fired after a source has been successfully connected
 - `disconnect`: This event will be fired after a source has been disconnected
 - `close`: This event will be fired after the Connect window is closed, regardless of whether sources were connected or not
 - `error`: This event fires in case theres an error with the library e.g. a token container element is not found
 
 To add a lifecycle hook to a particular event you have to use the `on(eventName, eventListener)` method, e.g.:
 
 ```javascript
HumanConnect.on("close", (response) => {console.log("close", response)});
HumanConnect.on("connect", (response) => {console.log("connect", response)});
HumanConnect.on("disconnect", (response) => {console.log("disconnect", response)});
HumanConnect.on("error", (response) => {console.error("error", response)});
```
 
 Any function listening for lifecycle events defined by Connect will receive a payload with the following schema:
  
  ```javascript
   {
       sessionResults: {
           // List of sources the user connected during this session
           connectedSources: [
               {
                   name: "Starfleet Pharmacy",
                   id: "5b1daf3f079c652eaf41fd23"
               }
           ],
           // List of sources the user disconnected during this session
           disconnectedSources: [],
           // List of sources the user requested during this session
           requestedSources: [
               {
                   address: "742 Evergreen Terrace, OH",
                   healthSystem: "N/A",
                   location: {
                       latitude: 41.3289,
                       longitude: -105.6928
                   },
                   physician: "Dr. John Smith",
                   website: "drjohnsmith.example.com"
               }
           ]
       },
       // List of sources the user currently has connected with your app
       currentConnections: [
           {
               name: "Starfleet Pharmacy",
               id: "5b1daf3f079c652eaf41fd23"
           }
       ],
       // List of sources the user has requested
       requestedProviders: [
               {
                   address: "742 Evergreen Terrace, OH",
                   healthSystem: "N/A",
                   location: {
                       latitude: 41.3289,
                       longitude: -105.6928
                   },
                   physician: "Dr. John Smith",
                   website: "drjohnsmith.example.com"
               }
       ]
   }
   ```

## Upgrade from 1.x.x

### CDN
- If you are using the script via the CDN and the source location is `src=https://cdn.humanapi.co/humanapi-connect-client@latest.js` you will be upgraded automatically. The new version is backwards compatible so there is no other change needed for the time being.

- If you are using a specific version of the library, e.g. `src=https://cdn.humanapi.co/humanapi-connect-client@1.2.4.js` you can just use `humanapi-connect-client@latest.js` or specify a 2.x.x version, e.g. `humanapi-connect-client@2.0.4.js`

### npm
- Install the latest package with `npm install humanapi-connect-client`

## Contributing

**Note:** This project uses Node 14.

### Generate a prerelease version

To generate a new pre-release version, you can run the following command:

```sh
npm version prerelease --preid=beta
```

This will bump the version to the next pre-release version, e.g. from `2.0.0` to `2.0.1-beta.0`. After that you can publish the new version with:

```sh
npm publish --tag beta
```
And then push the new tag to the repository:

```sh
# Example
git push origin v2.0.1-beta.0
```

### Generate a new version

To generate a new version, you can run the following command:

```sh
npm version patch
```

After that you can publish the new version with:

```sh
npm publish
```

And then push the new tag to the repository:

```sh
# Example
git push origin v2.0.1
```

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