npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

heydoctor-js

v3.7.2

Published

Javascript library for the HeyDoctor Telehealth API.

Downloads

16

Readme

HeyDoctor Javascript SDK

The HeyDoctor Javascript library provides convenient access to the HeyDoctor API for applications written in JavaScript.

Documentation

Check out our auto-generated docs using TypeDoc.

Installation

You can install heydoctor-js using your favorite package manager.

$ yarn add heydoctor-js
# or
$ npm install --save heydoctor-js

Usage

You'll first need to create a new client resource. If using the HeyDoctor SaaS platform, you'll need to provide the API key located in the EMR. The client contains the http module that will communicate with the HeyDoctor API, so we'll pass this client to the other resources you'll need.

Creating the client

import { Client, Environments, Visits, OAuth } from 'heydoctor-js';

// The client will hold all configuration options and the http module
// that communicates to our server
const client = new Client({
  env: Environments.SANDBOX | Environments.PRODUCTION, // determines the API and OAuth endpoints
});

// Create two resources passing both the client we've just created
// ** Some resources also take an optional options object as a second argument
const visits = new Visits(client;
const oauth = new OAuth(client, {
  clientId: 'your-provided-client-id',
  scope: '*',
});

Subscribing to HTTP events

The HeyDoctor client also doubles as an event emitter. The client extends from Mitt and complies with standard EventEmitter events.

interface HttpCallback {
  statusCode: number;
  data: any;
}

const client = new Client();

client.on('http:success', (data: HttpCallback) => void);
client.on('http:error', (data: HttpCallback) => void);

Authorizing via OAuth

Partnering clients will use the HeyDoctor JS SDK to create or link a HeyDoctor account. HeyDoctor conforms to the existing OAuth2 protocol. In the case that HeyDoctor already has the provided email on file, the SDK will open a dialog box, akin to Facebook or Google login, prompting the user to confirm their existing password. In all successful cases, an access token and refresh token will be returned. The resulting payload is outlined below.

We recommend to store the longstanding refresh token in a persisted data store. You’ll use this token, along with your unique client id and secret key to regenerate short lived access tokens used to authenticate requests to the HeyDoctor API. For security measures, the access token has a one hour TTL, after which the token will expire and new access token will need to be generated.

Upon successful authorization, all subsequent SDK calls will be authenticated using the access token. The access token can also be utilized server-side to call our API directly.

Example

import { Client, OAuth } from 'heydoctor-js';

const client = new Client({
  env: 'production',
});

const oauth = new OAuth(client, {
  clientId: 'your-provided-client-id',
});

// First attempt to create a new HeyDoctor user silently. The method will throw an error in the case that the email already exists,
// in which case you have the opportunity to present an unobtrusive dialog for the user to confirm their existing HeyDoctor password.
try {
  const { accessToken, refreshToken } = await oauth.createUser({
    email: '[email protected]',
    firstName: 'Frank',
    lastName: 'Sinatra',
    dob: '1915-12-12',
    gender: 'male',
    addressLine1: '123 Somewhere Street',
    city: 'Hoboken',
    state: 'NJ',
    zip: '07030',
  });
} catch (error) {
  if (error.code === 'account_exists') {
    const { accessToken, refreshToken } = await oauth.launchWebAuthFlow('[email protected]');
  }
}

// Now that the client has been authorized, we can call call other methods available in the SDK
const visit = await visits.create({
  code: 'hair-loss',
});

// Excellent, we've just created our first visit. Now, we can upload photos to that visit.
await visit.uploadPhoto('photoId1234', 'base64photostring');